From patchwork Thu Apr 6 14:58:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 670952 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B0B9C77B70 for ; Thu, 6 Apr 2023 14:59:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239128AbjDFO7A (ORCPT ); Thu, 6 Apr 2023 10:59:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239084AbjDFO67 (ORCPT ); Thu, 6 Apr 2023 10:58:59 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5CE18A7E for ; Thu, 6 Apr 2023 07:58:55 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id d17so39790605wrb.11 for ; Thu, 06 Apr 2023 07:58:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680793134; x=1683385134; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zNY1WgFE5W0+EDCsEQWZ33KMDgDEFiFDJkuxdC14U6c=; b=lsMZ/tmQGh0+Gqb95YSagOXlgovDFj8+1loUBZniBPTntn/h5IVkYuQn7ILSUiUVYq aYG9W1n2NKs2RptvcozWQPSf7ZiDwxLfvfzk9UiJw/4tHPRk21e260kkMA/jnzZBPjfN Gr1plOLPrjpPSR0yFk6Z9QNGTRVpkWqLhnZ5Vm0GN/LuZ6WsYtGrUpFFzHamAhcbP87e 3RvCX7bxDIB/qxO3F1sgfYMCRb/6l9ygjdBvhYUwzHTy9HYG0+SS4BsOfB+47W4hrlhQ yOTzP4LrDo7vULF8GRQ+uS04+C8AOlUZ5dpWBOexEQRaejsNhuHOFUDwU6oQEmdmu5xY z0AA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680793134; x=1683385134; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zNY1WgFE5W0+EDCsEQWZ33KMDgDEFiFDJkuxdC14U6c=; b=7pUmLnmzzdSDjeTWtRrU/6YKoWLO4Kv5m/i4/gdHixKpvTE3E42j3iOCeLWZjUUOlT JBoPXUgTNuUlf1xzl6oU4AGUWbuQD+ttjrF28gYToiUAmkONZTPyZP6+QqKJUeq2TlLT utrfItQ3qSrz1j5uDRFs40zH1QrUkXRJSBRLL7PZFvGYEVo68i8VU9vBVhHmaKdOb7PH 6KEWyL+Lge+9k1kcgRLhHKE3okvivjfCXR1PoLjQW4C9WoexufcE5dYoz6nv2JI8aLgN Ue+jIgnjq+v47V3sqqxcw9jnojKPvsrB6GlsX5DaVpcaBnTXlImDDwNhpuraygczE6gi 8Vbg== X-Gm-Message-State: AAQBX9d7oKweW8Rsf/rPQkbgwDYtv5q0lUZISurLN1uG7KKMhqaMl+Fd 7ijs+z0YxmJb0m+9XS5fXE/S4A== X-Google-Smtp-Source: AKy350Y5/8nzIFtA5GLno7AkNOE83NgVqaQKljVOSMfIXaK0nWcT0TmjC4AnNwjBHz1+YX5CvUKlMw== X-Received: by 2002:a5d:440d:0:b0:2d8:cacd:797e with SMTP id z13-20020a5d440d000000b002d8cacd797emr7051511wrq.10.1680793133951; Thu, 06 Apr 2023 07:58:53 -0700 (PDT) Received: from sagittarius-a.chello.ie (188-141-3-169.dynamic.upc.ie. [188.141.3.169]) by smtp.gmail.com with ESMTPSA id d10-20020a1c730a000000b003f0373d077csm1768160wmb.47.2023.04.06.07.58.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Apr 2023 07:58:53 -0700 (PDT) From: Bryan O'Donoghue To: amitk@kernel.org, thara.gopinath@gmail.com, agross@kernel.org, andersson@kernel.org, konrad.dybcio@linaro.org, rafael@kernel.org, daniel.lezcano@linaro.org, rui.zhang@intel.com, dmitry.baryshkov@linaro.org Cc: linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Bryan O'Donoghue Subject: [PATCH 1/3] thermal/drivers/tsens: Add error/debug prints to calibration read Date: Thu, 6 Apr 2023 15:58:48 +0100 Message-Id: <20230406145850.357296-2-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230406145850.357296-1-bryan.odonoghue@linaro.org> References: <20230406145850.357296-1-bryan.odonoghue@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Add in some dev_dbg() to aid in viewing of raw calibration data extracted. Signed-off-by: Bryan O'Donoghue --- drivers/thermal/qcom/tsens.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c index d3218127e617d..7165b0bfe8b9f 100644 --- a/drivers/thermal/qcom/tsens.c +++ b/drivers/thermal/qcom/tsens.c @@ -115,8 +115,12 @@ int tsens_read_calibration(struct tsens_priv *priv, int shift, u32 *p1, u32 *p2, return ret; ret = nvmem_cell_read_variable_le_u32(priv->dev, name, &p1[i]); - if (ret) + if (ret) { + dev_err(priv->dev, "Failed to read %s\n", name); return ret; + } + + dev_dbg(priv->dev, "%s 0x%x\n", name, p1[i]); ret = snprintf(name, sizeof(name), "s%d_p2%s", priv->sensor[i].hw_id, backup ? "_backup" : ""); @@ -124,8 +128,12 @@ int tsens_read_calibration(struct tsens_priv *priv, int shift, u32 *p1, u32 *p2, return ret; ret = nvmem_cell_read_variable_le_u32(priv->dev, name, &p2[i]); - if (ret) + if (ret) { + dev_err(priv->dev, "Failed to read %s\n", name); return ret; + } + + dev_dbg(priv->dev, "%s 0x%x\n", name, p2[i]); } switch (mode) { From patchwork Thu Apr 6 14:58:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 671386 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4AFA7C76196 for ; Thu, 6 Apr 2023 14:59:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239084AbjDFO7B (ORCPT ); Thu, 6 Apr 2023 10:59:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239162AbjDFO67 (ORCPT ); Thu, 6 Apr 2023 10:58:59 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 006F893E5 for ; Thu, 6 Apr 2023 07:58:56 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id l15-20020a05600c4f0f00b003ef6d684102so20385992wmq.3 for ; Thu, 06 Apr 2023 07:58:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680793135; x=1683385135; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hFQJ0JSK2AI42Y7WQ2NOgsYWULbFZSsr1UBIiIbTSbY=; b=mao3Fw3VDnEGFw2m5aPPM0jnpVyXLIIOXCZCPPqksXA3xVdYRwc5rtmp5MAwj1SPFY A1H2t/65LOh8htqlnLl6+kS667EED9ByiQOkx+gH4wGur6TRCmvobXOjFqck8fIcjg2p nvFQEHsrqMI2Ii7wRJGPXs21aZo/7cED3OSIb7gQHNGcJL8QNIU7Uw4SM+2vWmt4tqfe EnT1Qhume1y0LxuMvIZuGARn97d67nFUE3+AF7MG4u5vjXaTlv4M7OH5EZ5ZgnHks39V He2ZbgRgAtITuKdL5OTehehciTFlxISD8lGeWmvO6qLC6+1dBlDh0+6lny5X18eNjbjP 3Btw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680793135; x=1683385135; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hFQJ0JSK2AI42Y7WQ2NOgsYWULbFZSsr1UBIiIbTSbY=; b=gdj+8Foh86PduhgunnSTYhgm84uhtfk2Q4/9RqNnt0R3+RSyjnRtsC9Vrgk6vUIMZE eM65MxRkzy4zA5lVaRo202jdapKgQPT7D8SWD9KXn7KY0/kt97SIRQq0voo85jbE850D 9wejsUdsyd5D02SSYHoBPHlNH1xgSWYAMG96+cDUS6hN1HZ9/OwvavrrLyTJJ/XfrJpM a1vV0XKZUgnv/GlGEGCUooIVUkU5X0FXTTUJozaa/wegiMcCyxKEmj/QlYeq63SP3Hor h5DQXlHLKX5JdUXxZUIWHYg6EP24FOP543QxofgcfQgGnPiBZfDw83yhotPHCJLz+MRy R6Bg== X-Gm-Message-State: AAQBX9e11CVrHtChqoSCybb1BmPG2Ev2T4oiouR/x5HA/xQv0/P5xUJd 0UUS3cQEr0iERwDdLa3TBjWIew== X-Google-Smtp-Source: AKy350aMZIoUs7COMqn5CuqRo8MtaiTTlCouRN+4YP84oA+m0wsNCdeJzzbU6AoWpEoJOGonlay7FQ== X-Received: by 2002:a05:600c:ace:b0:3ed:ea48:cd92 with SMTP id c14-20020a05600c0ace00b003edea48cd92mr8064920wmr.15.1680793135280; Thu, 06 Apr 2023 07:58:55 -0700 (PDT) Received: from sagittarius-a.chello.ie (188-141-3-169.dynamic.upc.ie. [188.141.3.169]) by smtp.gmail.com with ESMTPSA id d10-20020a1c730a000000b003f0373d077csm1768160wmb.47.2023.04.06.07.58.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Apr 2023 07:58:54 -0700 (PDT) From: Bryan O'Donoghue To: amitk@kernel.org, thara.gopinath@gmail.com, agross@kernel.org, andersson@kernel.org, konrad.dybcio@linaro.org, rafael@kernel.org, daniel.lezcano@linaro.org, rui.zhang@intel.com, dmitry.baryshkov@linaro.org Cc: linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Bryan O'Donoghue Subject: [PATCH 2/3] thermal/drivers/tsens: Describe sensor registers via a structure Date: Thu, 6 Apr 2023 15:58:49 +0100 Message-Id: <20230406145850.357296-3-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230406145850.357296-1-bryan.odonoghue@linaro.org> References: <20230406145850.357296-1-bryan.odonoghue@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Define sensor identifiers and optional shifts in a single data-structure. This facilitates extraction of calibration data from non-contiguous addresses. Signed-off-by: Bryan O'Donoghue --- drivers/thermal/qcom/tsens-v0_1.c | 56 +++++++++++++++++++++++++++++-- drivers/thermal/qcom/tsens.c | 5 +-- drivers/thermal/qcom/tsens.h | 16 ++++++++- 3 files changed, 72 insertions(+), 5 deletions(-) diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c index e89c6f39a3aea..c20c002d98650 100644 --- a/drivers/thermal/qcom/tsens-v0_1.c +++ b/drivers/thermal/qcom/tsens-v0_1.c @@ -319,10 +319,31 @@ static const struct tsens_ops ops_8916 = { .get_temp = get_temp_common, }; +struct tsens_reg_data reg_8916[] = { + { + .id = 0, + }, + { + .id = 1, + }, + { + .id = 2, + }, + { + .id = 3, + }, + { + .id = 4, + }, + { + .id = 5, + }, +}; + struct tsens_plat_data data_8916 = { .num_sensors = 5, .ops = &ops_8916, - .hw_ids = (unsigned int []){0, 1, 2, 4, 5 }, + .reg = reg_8916, .feat = &tsens_v0_1_feat, .fields = tsens_v0_1_regfields, @@ -334,10 +355,41 @@ static const struct tsens_ops ops_8939 = { .get_temp = get_temp_common, }; +struct tsens_reg_data reg_8939[] = { + { + .id = 0, + }, + { + .id = 1, + }, + { + .id = 2, + }, + { + .id = 3, + }, + { + .id = 5, + }, + { + .id = 6, + }, + { + .id = 7, + }, + { + .id = 8, + }, + { + .id = 9, + .p2_shift = 8, + }, +}; + struct tsens_plat_data data_8939 = { .num_sensors = 9, .ops = &ops_8939, - .hw_ids = (unsigned int []){ 0, 1, 2, 3, 5, 6, 7, 8, 9, /* 10 */ }, + .reg = reg_8939, .feat = &tsens_v0_1_feat, .fields = tsens_v0_1_regfields, diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c index 7165b0bfe8b9f..a260f563b4889 100644 --- a/drivers/thermal/qcom/tsens.c +++ b/drivers/thermal/qcom/tsens.c @@ -1274,13 +1274,14 @@ static int tsens_probe(struct platform_device *pdev) priv->num_sensors = num_sensors; priv->ops = data->ops; for (i = 0; i < priv->num_sensors; i++) { - if (data->hw_ids) - priv->sensor[i].hw_id = data->hw_ids[i]; + if (data->reg) + priv->sensor[i].hw_id = data->reg[i].id; else priv->sensor[i].hw_id = i; } priv->feat = data->feat; priv->fields = data->fields; + priv->reg = data->reg; platform_set_drvdata(pdev, priv); diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h index dba9cd38f637c..31f67da03bce6 100644 --- a/drivers/thermal/qcom/tsens.h +++ b/drivers/thermal/qcom/tsens.h @@ -517,18 +517,31 @@ struct tsens_features { int trip_max_temp; }; +/** + * struct tsens_reg_data - describes register data retrieved non-contiguously + * @id: thermal sensor identifier + * @p1_shift: When non-zero is the # of bits to right shift p1 MSB by + * @p2_shift: When non-zero is the # of bits to right shift p2 MSB by + */ +struct tsens_reg_data { + unsigned int id; + unsigned int p1_shift; + unsigned int p2_shift; +}; + /** * struct tsens_plat_data - tsens compile-time platform data * @num_sensors: Number of sensors supported by platform * @ops: operations the tsens instance supports * @hw_ids: Subset of sensors ids supported by platform, if not the first n + * @reg: Describe sensor id and calibration shifts * @feat: features of the IP * @fields: bitfield locations */ struct tsens_plat_data { const u32 num_sensors; const struct tsens_ops *ops; - unsigned int *hw_ids; + struct tsens_reg_data *reg; struct tsens_features *feat; const struct reg_field *fields; }; @@ -575,6 +588,7 @@ struct tsens_priv { struct regmap_field *rf[MAX_REGFIELDS]; struct tsens_context ctx; struct tsens_features *feat; + struct tsens_reg_data *reg; const struct reg_field *fields; const struct tsens_ops *ops; From patchwork Thu Apr 6 14:58:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 670951 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49ECFC7618D for ; Thu, 6 Apr 2023 14:59:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239192AbjDFO7D (ORCPT ); Thu, 6 Apr 2023 10:59:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239209AbjDFO67 (ORCPT ); Thu, 6 Apr 2023 10:58:59 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21E511BCB for ; Thu, 6 Apr 2023 07:58:58 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id v1so39810712wrv.1 for ; Thu, 06 Apr 2023 07:58:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680793136; x=1683385136; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RYyNPnzqae4khg3KV2Lt1ECRlr8f32FnQfafbs3QB5I=; b=vtPP+7phDU/ux5+X1AMnqZmBs1GAc2PM6+xWc18/6ktYNlGaOycSjJMMyF1BBXC+nu 4QZDU9v9WinnH1FsOEkpH4dmI5ellAVQizYtvNkBWHZFWaYZaZboK1o65kSN/SeLRIaX Mc1eGzGQBy9IOVt2PAdVYiujotTNItSEkduNACho30kG6upWUZ0lrSRT61tPUh/3f0n7 qxnxt4EZgiDFO/6sSBUmmG/CiRcw1mtKZGIDPbZ3k1i+ZEonu9CtMIGyfolTacyKP4O8 3/1dkQ0GqFz2waoLRBVnZiAL0B9aHM715lDxWSH6vZnD/GKwTBzx5eejjgRH/DV1TzpG owRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680793136; x=1683385136; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RYyNPnzqae4khg3KV2Lt1ECRlr8f32FnQfafbs3QB5I=; b=LWwS+kV5kkXDIjHDzRS/FA3NAU4Yg7QU0IOVZ0G1N3RMe3VXO2bNIss6QbRNONoLSt KPdCekvhclN5w1e5cFp+8omKdeqEZuVnplTmohDd1TO3B/WHyaEDKMIn2oCYmEaO7B1w 0xhESYVyHX0Qvs1/t3wXlop5SWn21CnH1Ys8XXiMTMfSLME0LvCbpPIFsRjjsAe86d0F Oc9OhU8u2ImwdSyeMf2iHw4uSdYInl+HwFX8HRWM6NgrsqgQG5w+KtnGhGUyWD3lC9Db r2tIf0VEQzmIx6BQDyyyhGVevKi7btHsM7YQgZPaSYssLZeHFawUuaGH6BccuqMz/+Oa UYwg== X-Gm-Message-State: AAQBX9eowj9SPjWWWvwIRsS2ZP6VeJa9FrM+T4VEFMjXTtjFS5+nz8RP 65L6Ui6VK+FiMo70rctgxJTJnw== X-Google-Smtp-Source: AKy350YVmezFAiNqfMgn8vCKeCz1co1VaJgEQqfzy5k/qQyVn240yKSvpXq066F1GHjVmN8wzocQ6A== X-Received: by 2002:adf:ce0a:0:b0:2c8:9cfe:9e29 with SMTP id p10-20020adfce0a000000b002c89cfe9e29mr6532039wrn.38.1680793136560; Thu, 06 Apr 2023 07:58:56 -0700 (PDT) Received: from sagittarius-a.chello.ie (188-141-3-169.dynamic.upc.ie. [188.141.3.169]) by smtp.gmail.com with ESMTPSA id d10-20020a1c730a000000b003f0373d077csm1768160wmb.47.2023.04.06.07.58.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Apr 2023 07:58:56 -0700 (PDT) From: Bryan O'Donoghue To: amitk@kernel.org, thara.gopinath@gmail.com, agross@kernel.org, andersson@kernel.org, konrad.dybcio@linaro.org, rafael@kernel.org, daniel.lezcano@linaro.org, rui.zhang@intel.com, dmitry.baryshkov@linaro.org Cc: linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Bryan O'Donoghue Subject: [PATCH 3/3] thermal/drivers/tsens: Extract and shift-in optional MSB Date: Thu, 6 Apr 2023 15:58:50 +0100 Message-Id: <20230406145850.357296-4-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230406145850.357296-1-bryan.odonoghue@linaro.org> References: <20230406145850.357296-1-bryan.odonoghue@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org In msm8939 some of the sensor calibration data traverses byte boundaries. Two examples of this are thermal sensor 2 point 1 and sensor 9 point 2. For sensor 2 point 1 we can get away with a simple read traversing byte boundaries as the calibration most significant bits are adjacent to the least significant across the byte boundary. In this case a read starting at the end of the first byte for nine bits will deliver up the data we want. In the case of sensor 9 point 2 however, the most significant bits are not adjacent and so therefore we need to perform two reads and or the bits together. If reg.p1_shift or reg.p2_shift is set then automatically search for pX_sY_msb in the dts applying pX_shift as a right shift or into the pX_sY value. Signed-off-by: Bryan O'Donoghue --- drivers/thermal/qcom/tsens.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c index a260f563b4889..eff2c8671c343 100644 --- a/drivers/thermal/qcom/tsens.c +++ b/drivers/thermal/qcom/tsens.c @@ -74,6 +74,7 @@ int tsens_read_calibration(struct tsens_priv *priv, int shift, u32 *p1, u32 *p2, { u32 mode; u32 base1, base2; + u32 msb; char name[] = "sXX_pY_backup"; /* s10_p1_backup */ int i, ret; @@ -122,6 +123,22 @@ int tsens_read_calibration(struct tsens_priv *priv, int shift, u32 *p1, u32 *p2, dev_dbg(priv->dev, "%s 0x%x\n", name, p1[i]); + if (priv->reg && priv->reg[i].p1_shift) { + ret = snprintf(name, sizeof(name), "s%d_p1_msb", + priv->sensor[i].hw_id); + if (ret < 0) + return ret; + + ret = nvmem_cell_read_variable_le_u32(priv->dev, name, &msb); + if (ret) { + dev_err(priv->dev, "Failed to read %s\n", name); + return ret; + } + + dev_dbg(priv->dev, "%s 0x%x\n", name, msb); + p1[i] |= msb >> priv->reg[i].p1_shift; + } + ret = snprintf(name, sizeof(name), "s%d_p2%s", priv->sensor[i].hw_id, backup ? "_backup" : ""); if (ret < 0) @@ -134,6 +151,22 @@ int tsens_read_calibration(struct tsens_priv *priv, int shift, u32 *p1, u32 *p2, } dev_dbg(priv->dev, "%s 0x%x\n", name, p2[i]); + + if (priv->reg && priv->reg[i].p2_shift) { + ret = snprintf(name, sizeof(name), "s%d_p2_msb", + priv->sensor[i].hw_id); + if (ret < 0) + return ret; + + ret = nvmem_cell_read_variable_le_u32(priv->dev, name, &msb); + if (ret) { + dev_err(priv->dev, "Failed to read %s\n", name); + return ret; + } + + dev_dbg(priv->dev, "%s 0x%x\n", name, msb); + p2[i] |= msb >> priv->reg[i].p2_shift; + } } switch (mode) {