From patchwork Fri Aug 25 20:53:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Biju Das X-Patchwork-Id: 13366317 X-Patchwork-Delegate: geert@linux-m68k.org 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 2FA7FEE49A0 for ; Fri, 25 Aug 2023 20:54:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230367AbjHYUyI (ORCPT ); Fri, 25 Aug 2023 16:54:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230515AbjHYUx4 (ORCPT ); Fri, 25 Aug 2023 16:53:56 -0400 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B34981FF0; Fri, 25 Aug 2023 13:53:54 -0700 (PDT) X-IronPort-AV: E=Sophos;i="6.02,201,1688396400"; d="scan'208";a="177704970" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie6.idc.renesas.com with ESMTP; 26 Aug 2023 05:53:54 +0900 Received: from localhost.localdomain (unknown [10.226.92.49]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 9957C4001976; Sat, 26 Aug 2023 05:53:51 +0900 (JST) From: Biju Das To: Eric Tremblay , Jean Delvare , Guenter Roeck Cc: Biju Das , linux-hwmon@vger.kernel.org, Geert Uytterhoeven , Andy Shevchenko , Prabhakar Mahadev Lad , linux-renesas-soc@vger.kernel.org Subject: [PATCH v3 1/3] hwmon: tmp513: Add max_channels variable to struct tmp51x_data Date: Fri, 25 Aug 2023 21:53:43 +0100 Message-Id: <20230825205345.632792-2-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230825205345.632792-1-biju.das.jz@bp.renesas.com> References: <20230825205345.632792-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org The tmp512 chip has 3 channels whereas tmp513 has 4 channels. Avoid using tmp51x_ids for this HW difference by replacing OF/ID table data with maximum channels supported by the device. Add max_channels variable to struct tmp51x_data and fix the logic for invalid channel in tmp51x_is_visible(). Signed-off-by: Biju Das --- v3: * New patch split from patch #3 * Avoided Yoda style logic. * Replaced OF/ID data from tmp51x_ids->max_channels --- drivers/hwmon/tmp513.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/drivers/hwmon/tmp513.c b/drivers/hwmon/tmp513.c index 9a180b1030c9..99f66f9d5f19 100644 --- a/drivers/hwmon/tmp513.c +++ b/drivers/hwmon/tmp513.c @@ -113,6 +113,9 @@ #define MAX_TEMP_HYST 127500 +#define TMP512_MAX_CHANNELS 3 +#define TMP513_MAX_CHANNELS 4 + static const u8 TMP51X_TEMP_INPUT[4] = { TMP51X_LOCAL_TEMP_RESULT, TMP51X_REMOTE_TEMP_RESULT_1, @@ -170,6 +173,7 @@ struct tmp51x_data { u32 pwr_lsb_uw; enum tmp51x_ids id; + u8 max_channels; struct regmap *regmap; }; @@ -434,7 +438,7 @@ static umode_t tmp51x_is_visible(const void *_data, switch (type) { case hwmon_temp: - if (data->id == tmp512 && channel == 3) + if (channel >= data->max_channels) return 0; switch (attr) { case hwmon_temp_input: @@ -601,21 +605,15 @@ static int tmp51x_init(struct tmp51x_data *data) } static const struct i2c_device_id tmp51x_id[] = { - { "tmp512", tmp512 }, - { "tmp513", tmp513 }, + { "tmp512", TMP512_MAX_CHANNELS }, + { "tmp513", TMP513_MAX_CHANNELS }, { } }; MODULE_DEVICE_TABLE(i2c, tmp51x_id); static const struct of_device_id tmp51x_of_match[] = { - { - .compatible = "ti,tmp512", - .data = (void *)tmp512 - }, - { - .compatible = "ti,tmp513", - .data = (void *)tmp513 - }, + { .compatible = "ti,tmp512", .data = (void *)TMP512_MAX_CHANNELS }, + { .compatible = "ti,tmp513", .data = (void *)TMP513_MAX_CHANNELS }, { }, }; MODULE_DEVICE_TABLE(of, tmp51x_of_match); @@ -720,7 +718,11 @@ static int tmp51x_probe(struct i2c_client *client) if (!data) return -ENOMEM; - data->id = (uintptr_t)i2c_get_match_data(client); + data->max_channels = (uintptr_t)i2c_get_match_data(client); + if (data->max_channels == TMP513_MAX_CHANNELS) + data->id = tmp513; + else + data->id = tmp512; ret = tmp51x_configure(dev, data); if (ret < 0) { From patchwork Fri Aug 25 20:53:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Biju Das X-Patchwork-Id: 13366318 X-Patchwork-Delegate: geert@linux-m68k.org 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 865CCEE49B3 for ; Fri, 25 Aug 2023 20:54:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231234AbjHYUyI (ORCPT ); Fri, 25 Aug 2023 16:54:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231223AbjHYUyC (ORCPT ); Fri, 25 Aug 2023 16:54:02 -0400 Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A53B71FF0; Fri, 25 Aug 2023 13:53:58 -0700 (PDT) X-IronPort-AV: E=Sophos;i="6.02,201,1688396400"; d="scan'208";a="173998517" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie5.idc.renesas.com with ESMTP; 26 Aug 2023 05:53:57 +0900 Received: from localhost.localdomain (unknown [10.226.92.49]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 0589940031FF; Sat, 26 Aug 2023 05:53:54 +0900 (JST) From: Biju Das To: Eric Tremblay , Jean Delvare , Guenter Roeck Cc: Biju Das , linux-hwmon@vger.kernel.org, Geert Uytterhoeven , Andy Shevchenko , Prabhakar Mahadev Lad , linux-renesas-soc@vger.kernel.org Subject: [PATCH v3 2/3] hwmon: tmp513: Drop enum tmp51x_ids and variable id from struct tmp51x_data Date: Fri, 25 Aug 2023 21:53:44 +0100 Message-Id: <20230825205345.632792-3-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230825205345.632792-1-biju.das.jz@bp.renesas.com> References: <20230825205345.632792-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org Drop variable id from struct tmp51x_data and enum tmp51x_ids as all the hw differences can be handled by max_channels. Signed-off-by: Biju Das --- v2->v3: * Updated the macro TMP51X_TEMP_CONFIG_DEFAULT by adding bit definitions. * Dropped unused macros TMP51{2,3}_TEMP_CONFIG_DEFAULT. --- drivers/hwmon/tmp513.c | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/drivers/hwmon/tmp513.c b/drivers/hwmon/tmp513.c index 99f66f9d5f19..6bbae4735a4b 100644 --- a/drivers/hwmon/tmp513.c +++ b/drivers/hwmon/tmp513.c @@ -19,6 +19,7 @@ * the Free Software Foundation; version 2 of the License. */ +#include #include #include #include @@ -73,9 +74,6 @@ #define TMP51X_PGA_DEFAULT 8 #define TMP51X_MAX_REGISTER_ADDR 0xFF -#define TMP512_TEMP_CONFIG_DEFAULT 0xBF80 -#define TMP513_TEMP_CONFIG_DEFAULT 0xFF80 - // Mask and shift #define CURRENT_SENSE_VOLTAGE_320_MASK 0x1800 #define CURRENT_SENSE_VOLTAGE_160_MASK 0x1000 @@ -116,6 +114,22 @@ #define TMP512_MAX_CHANNELS 3 #define TMP513_MAX_CHANNELS 4 +#define TMP51X_TEMP_CONFIG_GPM_MASK BIT(2) +#define TMP51X_TEMP_CONFIG_RC_MASK BIT(10) +#define TMP51X_TEMP_CONFIG_CONT_MASK BIT(15) + +#define TMP51X_TEMP_CONFIG_GPM FIELD_PREP(GENMASK(1, 0), 0) +#define TMP51X_TEMP_CONFIG_GP FIELD_PREP(TMP51X_TEMP_CONFIG_GPM_MASK, 0) +#define TMP51X_TEMP_CONFIG_CONV_RATE FIELD_PREP(GENMASK(9, 7), 0x7) +#define TMP51X_TEMP_CONFIG_RC FIELD_PREP(TMP51X_TEMP_CONFIG_RC_MASK, 1) +#define TMP51X_TEMP_CHANNEL_MASK(n) FIELD_PREP(GENMASK(14, 11), GENMASK(n, 0) > 1) +#define TMP51X_TEMP_CONFIG_CONT FIELD_PREP(TMP51X_TEMP_CONFIG_CONT_MASK, 1) + +#define TMP51X_TEMP_CONFIG_DEFAULT(n) \ + (TMP51X_TEMP_CONFIG_GPM | TMP51X_TEMP_CONFIG_GP | \ + TMP51X_TEMP_CONFIG_CONV_RATE | TMP51X_TEMP_CONFIG_RC | \ + TMP51X_TEMP_CHANNEL_MASK(n) | TMP51X_TEMP_CONFIG_CONT) + static const u8 TMP51X_TEMP_INPUT[4] = { TMP51X_LOCAL_TEMP_RESULT, TMP51X_REMOTE_TEMP_RESULT_1, @@ -155,10 +169,6 @@ static struct regmap_config tmp51x_regmap_config = { .max_register = TMP51X_MAX_REGISTER_ADDR, }; -enum tmp51x_ids { - tmp512, tmp513 -}; - struct tmp51x_data { u16 shunt_config; u16 pga_gain; @@ -172,7 +182,6 @@ struct tmp51x_data { u32 curr_lsb_ua; u32 pwr_lsb_uw; - enum tmp51x_ids id; u8 max_channels; struct regmap *regmap; }; @@ -589,7 +598,7 @@ static int tmp51x_init(struct tmp51x_data *data) if (ret < 0) return ret; - if (data->id == tmp513) { + if (data->max_channels == TMP513_MAX_CHANNELS) { ret = regmap_write(data->regmap, TMP513_N_FACTOR_3, data->nfactor[2] << 8); if (ret < 0) @@ -672,9 +681,9 @@ static int tmp51x_read_properties(struct device *dev, struct tmp51x_data *data) return ret; ret = device_property_read_u32_array(dev, "ti,nfactor", nfactor, - (data->id == tmp513) ? 3 : 2); + data->max_channels - 1); if (ret >= 0) - memcpy(data->nfactor, nfactor, (data->id == tmp513) ? 3 : 2); + memcpy(data->nfactor, nfactor, data->max_channels - 1); // Check if shunt value is compatible with pga-gain if (data->shunt_uohms > data->pga_gain * 40 * 1000 * 1000) { @@ -696,8 +705,7 @@ static void tmp51x_use_default(struct tmp51x_data *data) static int tmp51x_configure(struct device *dev, struct tmp51x_data *data) { data->shunt_config = TMP51X_SHUNT_CONFIG_DEFAULT; - data->temp_config = (data->id == tmp513) ? - TMP513_TEMP_CONFIG_DEFAULT : TMP512_TEMP_CONFIG_DEFAULT; + data->temp_config = TMP51X_TEMP_CONFIG_DEFAULT(data->max_channels); if (dev->of_node) return tmp51x_read_properties(dev, data); @@ -719,10 +727,6 @@ static int tmp51x_probe(struct i2c_client *client) return -ENOMEM; data->max_channels = (uintptr_t)i2c_get_match_data(client); - if (data->max_channels == TMP513_MAX_CHANNELS) - data->id = tmp513; - else - data->id = tmp512; ret = tmp51x_configure(dev, data); if (ret < 0) { From patchwork Fri Aug 25 20:53:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Biju Das X-Patchwork-Id: 13366320 X-Patchwork-Delegate: geert@linux-m68k.org 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 B49A5EE49B4 for ; Fri, 25 Aug 2023 20:54:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230515AbjHYUyI (ORCPT ); Fri, 25 Aug 2023 16:54:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231234AbjHYUyD (ORCPT ); Fri, 25 Aug 2023 16:54:03 -0400 Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7E4AC2136; Fri, 25 Aug 2023 13:54:01 -0700 (PDT) X-IronPort-AV: E=Sophos;i="6.02,201,1688396400"; d="scan'208";a="173998522" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie5.idc.renesas.com with ESMTP; 26 Aug 2023 05:54:01 +0900 Received: from localhost.localdomain (unknown [10.226.92.49]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 63B144048F0D; Sat, 26 Aug 2023 05:53:58 +0900 (JST) From: Biju Das To: Eric Tremblay , Jean Delvare , Guenter Roeck Cc: Biju Das , linux-hwmon@vger.kernel.org, Geert Uytterhoeven , Andy Shevchenko , Prabhakar Mahadev Lad , linux-renesas-soc@vger.kernel.org Subject: [PATCH v3 3/3] hwmon: tmp513: Simplify tmp51x_read_properties() Date: Fri, 25 Aug 2023 21:53:45 +0100 Message-Id: <20230825205345.632792-4-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230825205345.632792-1-biju.das.jz@bp.renesas.com> References: <20230825205345.632792-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org Simplify tmp51x_read_properties() by replacing 'nfactor' ->'data->nfactor' in device_property_read_u32_array() and drop the local variable as it is unused. Signed-off-by: Biju Das Reviewed-by: Geert Uytterhoeven Reviewed-by: Andy Shevchenko --- v3: * New patch. --- drivers/hwmon/tmp513.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/hwmon/tmp513.c b/drivers/hwmon/tmp513.c index 6bbae4735a4b..a1104833252d 100644 --- a/drivers/hwmon/tmp513.c +++ b/drivers/hwmon/tmp513.c @@ -662,7 +662,6 @@ static int tmp51x_pga_gain_to_reg(struct device *dev, struct tmp51x_data *data) static int tmp51x_read_properties(struct device *dev, struct tmp51x_data *data) { int ret; - u32 nfactor[3]; u32 val; ret = device_property_read_u32(dev, "shunt-resistor-micro-ohms", &val); @@ -680,10 +679,8 @@ static int tmp51x_read_properties(struct device *dev, struct tmp51x_data *data) if (ret < 0) return ret; - ret = device_property_read_u32_array(dev, "ti,nfactor", nfactor, - data->max_channels - 1); - if (ret >= 0) - memcpy(data->nfactor, nfactor, data->max_channels - 1); + device_property_read_u32_array(dev, "ti,nfactor", data->nfactor, + data->max_channels - 1); // Check if shunt value is compatible with pga-gain if (data->shunt_uohms > data->pga_gain * 40 * 1000 * 1000) {