From patchwork Wed Nov 11 09:12:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 11896995 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AF87D1668 for ; Wed, 11 Nov 2020 09:09:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8B2B2206F1 for ; Wed, 11 Nov 2020 09:09:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726553AbgKKJI0 (ORCPT ); Wed, 11 Nov 2020 04:08:26 -0500 Received: from mx0a-00128a01.pphosted.com ([148.163.135.77]:9616 "EHLO mx0a-00128a01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726300AbgKKJIZ (ORCPT ); Wed, 11 Nov 2020 04:08:25 -0500 Received: from pps.filterd (m0167089.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0AB97fWt014144; Wed, 11 Nov 2020 04:08:08 -0500 Received: from nwd2mta4.analog.com ([137.71.173.58]) by mx0a-00128a01.pphosted.com with ESMTP id 34nsc94j4p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Nov 2020 04:08:08 -0500 Received: from ASHBMBX9.ad.analog.com (ashbmbx9.ad.analog.com [10.64.17.10]) by nwd2mta4.analog.com (8.14.7/8.14.7) with ESMTP id 0AB987Bc040535 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=FAIL); Wed, 11 Nov 2020 04:08:07 -0500 Received: from ASHBMBX8.ad.analog.com (10.64.17.5) by ASHBMBX9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1779.2; Wed, 11 Nov 2020 04:08:06 -0500 Received: from zeus.spd.analog.com (10.66.68.11) by ASHBMBX8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server id 15.1.1779.2 via Frontend Transport; Wed, 11 Nov 2020 04:08:06 -0500 Received: from localhost.localdomain ([10.48.65.12]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 0AB981gF023509; Wed, 11 Nov 2020 04:08:03 -0500 From: Alexandru Ardelean To: , , CC: , , , , , Alexandru Ardelean Subject: [PATCH v2 1/4] hwmon: (ltc2945): wrap regmap into an ltc2945_state struct Date: Wed, 11 Nov 2020 11:12:56 +0200 Message-ID: <20201111091259.46773-2-alexandru.ardelean@analog.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201111091259.46773-1-alexandru.ardelean@analog.com> References: <20201111091259.46773-1-alexandru.ardelean@analog.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312,18.0.737 definitions=2020-11-11_02:2020-11-10,2020-11-11 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 priorityscore=1501 bulkscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 phishscore=0 mlxlogscore=999 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011110050 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org The intent is to add pass the value of the sense resistor in the driver. This change wraps a 'struct ltc2945_state', and moves the regmap reference on that object. Then we can add the value of the sense resistor, or other information that would be useful for the driver. Signed-off-by: Alexandru Ardelean --- drivers/hwmon/ltc2945.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/drivers/hwmon/ltc2945.c b/drivers/hwmon/ltc2945.c index ba9c868a8641..1cea710df668 100644 --- a/drivers/hwmon/ltc2945.c +++ b/drivers/hwmon/ltc2945.c @@ -58,6 +58,14 @@ #define CONTROL_MULT_SELECT (1 << 0) #define CONTROL_TEST_MODE (1 << 4) +/** + * struct ltc2945_state - driver instance specific data + * @regmap regmap object to access device registers + */ +struct ltc2945_state { + struct regmap *regmap; +}; + static inline bool is_power_reg(u8 reg) { return reg < LTC2945_SENSE_H; @@ -66,7 +74,8 @@ static inline bool is_power_reg(u8 reg) /* Return the value from the given register in uW, mV, or mA */ static long long ltc2945_reg_to_val(struct device *dev, u8 reg) { - struct regmap *regmap = dev_get_drvdata(dev); + struct ltc2945_state *st = dev_get_drvdata(dev); + struct regmap *regmap = st->regmap; unsigned int control; u8 buf[3]; long long val; @@ -148,7 +157,8 @@ static long long ltc2945_reg_to_val(struct device *dev, u8 reg) static int ltc2945_val_to_reg(struct device *dev, u8 reg, unsigned long val) { - struct regmap *regmap = dev_get_drvdata(dev); + struct ltc2945_state *st = dev_get_drvdata(dev); + struct regmap *regmap = st->regmap; unsigned int control; int ret; @@ -234,7 +244,8 @@ static ssize_t ltc2945_value_store(struct device *dev, const char *buf, size_t count) { struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct regmap *regmap = dev_get_drvdata(dev); + struct ltc2945_state *st = dev_get_drvdata(dev); + struct regmap *regmap = st->regmap; u8 reg = attr->index; unsigned long val; u8 regbuf[3]; @@ -269,7 +280,8 @@ static ssize_t ltc2945_history_store(struct device *dev, const char *buf, size_t count) { struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct regmap *regmap = dev_get_drvdata(dev); + struct ltc2945_state *st = dev_get_drvdata(dev); + struct regmap *regmap = st->regmap; u8 reg = attr->index; int num_regs = is_power_reg(reg) ? 3 : 2; u8 buf_min[3] = { 0xff, 0xff, 0xff }; @@ -321,7 +333,8 @@ static ssize_t ltc2945_bool_show(struct device *dev, struct device_attribute *da, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct regmap *regmap = dev_get_drvdata(dev); + struct ltc2945_state *st = dev_get_drvdata(dev); + struct regmap *regmap = st->regmap; unsigned int fault; int ret; @@ -448,15 +461,22 @@ static const struct regmap_config ltc2945_regmap_config = { static int ltc2945_probe(struct i2c_client *client) { struct device *dev = &client->dev; + struct ltc2945_state *st; struct device *hwmon_dev; struct regmap *regmap; + st = devm_kzalloc(dev, sizeof(*st), GFP_KERNEL); + if (!st) + return -ENOMEM; + regmap = devm_regmap_init_i2c(client, <c2945_regmap_config); if (IS_ERR(regmap)) { dev_err(dev, "failed to allocate register map\n"); return PTR_ERR(regmap); } + st->regmap = regmap; + /* Clear faults */ regmap_write(regmap, LTC2945_FAULT, 0x00); From patchwork Wed Nov 11 09:12:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 11897113 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3F7CE138B for ; Wed, 11 Nov 2020 09:12:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2A77A2072C for ; Wed, 11 Nov 2020 09:12:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726334AbgKKJJI (ORCPT ); Wed, 11 Nov 2020 04:09:08 -0500 Received: from mx0a-00128a01.pphosted.com ([148.163.135.77]:11924 "EHLO mx0a-00128a01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726584AbgKKJI1 (ORCPT ); Wed, 11 Nov 2020 04:08:27 -0500 Received: from pps.filterd (m0167089.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0AB97h40014160; Wed, 11 Nov 2020 04:08:11 -0500 Received: from nwd2mta4.analog.com ([137.71.173.58]) by mx0a-00128a01.pphosted.com with ESMTP id 34nsc94j4s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Nov 2020 04:08:10 -0500 Received: from ASHBMBX9.ad.analog.com (ashbmbx9.ad.analog.com [10.64.17.10]) by nwd2mta4.analog.com (8.14.7/8.14.7) with ESMTP id 0AB9892P040540 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=FAIL); Wed, 11 Nov 2020 04:08:09 -0500 Received: from ASHBMBX8.ad.analog.com (10.64.17.5) by ASHBMBX9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1779.2; Wed, 11 Nov 2020 04:08:08 -0500 Received: from zeus.spd.analog.com (10.66.68.11) by ASHBMBX8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server id 15.1.1779.2 via Frontend Transport; Wed, 11 Nov 2020 04:08:08 -0500 Received: from localhost.localdomain ([10.48.65.12]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 0AB981gG023509; Wed, 11 Nov 2020 04:08:05 -0500 From: Alexandru Ardelean To: , , CC: , , , , , Alexandru Ardelean Subject: [PATCH v2 2/4] docs: hwmon: (ltc2945): change type of val to ULL in ltc2945_val_to_reg() Date: Wed, 11 Nov 2020 11:12:57 +0200 Message-ID: <20201111091259.46773-3-alexandru.ardelean@analog.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201111091259.46773-1-alexandru.ardelean@analog.com> References: <20201111091259.46773-1-alexandru.ardelean@analog.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312,18.0.737 definitions=2020-11-11_02:2020-11-10,2020-11-11 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 priorityscore=1501 bulkscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 phishscore=0 mlxlogscore=999 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011110050 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org In order to account for any potential overflows that could occur. Signed-off-by: Alexandru Ardelean Reported-by: kernel test robot --- drivers/hwmon/ltc2945.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/hwmon/ltc2945.c b/drivers/hwmon/ltc2945.c index 1cea710df668..6d4569a25471 100644 --- a/drivers/hwmon/ltc2945.c +++ b/drivers/hwmon/ltc2945.c @@ -155,7 +155,7 @@ static long long ltc2945_reg_to_val(struct device *dev, u8 reg) } static int ltc2945_val_to_reg(struct device *dev, u8 reg, - unsigned long val) + unsigned long long val) { struct ltc2945_state *st = dev_get_drvdata(dev); struct regmap *regmap = st->regmap; @@ -181,14 +181,14 @@ static int ltc2945_val_to_reg(struct device *dev, u8 reg, return ret; if (control & CONTROL_MULT_SELECT) { /* 25 mV * 25 uV = 0.625 uV resolution. */ - val = DIV_ROUND_CLOSEST(val, 625); + val = DIV_ROUND_CLOSEST_ULL(val, 625); } else { /* * 0.5 mV * 25 uV = 0.0125 uV resolution. * Divide first to avoid overflow; * accept loss of accuracy. */ - val = DIV_ROUND_CLOSEST(val, 25) * 2; + val = DIV_ROUND_CLOSEST_ULL(val, 25) * 2; } break; case LTC2945_VIN_H: @@ -197,7 +197,7 @@ static int ltc2945_val_to_reg(struct device *dev, u8 reg, case LTC2945_MAX_VIN_THRES_H: case LTC2945_MIN_VIN_THRES_H: /* 25 mV resolution. */ - val /= 25; + val = div_u64(val, 25); break; case LTC2945_ADIN_H: case LTC2945_MAX_ADIN_H: @@ -219,7 +219,7 @@ static int ltc2945_val_to_reg(struct device *dev, u8 reg, * dividing the reported current by the sense resistor value * in mOhm. */ - val = DIV_ROUND_CLOSEST(val, 25); + val = DIV_ROUND_CLOSEST_ULL(val, 25); break; default: return -EINVAL; @@ -247,7 +247,7 @@ static ssize_t ltc2945_value_store(struct device *dev, struct ltc2945_state *st = dev_get_drvdata(dev); struct regmap *regmap = st->regmap; u8 reg = attr->index; - unsigned long val; + unsigned long long val; u8 regbuf[3]; int num_regs; int regval; From patchwork Wed Nov 11 09:12:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 11896991 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5E47C1391 for ; Wed, 11 Nov 2020 09:08:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4511120797 for ; Wed, 11 Nov 2020 09:08:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726628AbgKKJIj (ORCPT ); Wed, 11 Nov 2020 04:08:39 -0500 Received: from mx0a-00128a01.pphosted.com ([148.163.135.77]:14368 "EHLO mx0a-00128a01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726605AbgKKJI3 (ORCPT ); Wed, 11 Nov 2020 04:08:29 -0500 Received: from pps.filterd (m0167088.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0AB95FuE017182; Wed, 11 Nov 2020 04:08:12 -0500 Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0a-00128a01.pphosted.com with ESMTP id 34npaavs8p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Nov 2020 04:08:12 -0500 Received: from SCSQMBX11.ad.analog.com (SCSQMBX11.ad.analog.com [10.77.17.10]) by nwd2mta3.analog.com (8.14.7/8.14.7) with ESMTP id 0AB98Avl059536 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=FAIL); Wed, 11 Nov 2020 04:08:11 -0500 Received: from SCSQMBX11.ad.analog.com (10.77.17.10) by SCSQMBX11.ad.analog.com (10.77.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1779.2; Wed, 11 Nov 2020 01:08:09 -0800 Received: from zeus.spd.analog.com (10.66.68.11) by SCSQMBX11.ad.analog.com (10.77.17.10) with Microsoft SMTP Server id 15.1.1779.2 via Frontend Transport; Wed, 11 Nov 2020 01:08:09 -0800 Received: from localhost.localdomain ([10.48.65.12]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 0AB981gH023509; Wed, 11 Nov 2020 04:08:07 -0500 From: Alexandru Ardelean To: , , CC: , , , , , Alexandru Ardelean Subject: [PATCH v2 3/4] hwmon: (ltc2945): add support for sense resistor Date: Wed, 11 Nov 2020 11:12:58 +0200 Message-ID: <20201111091259.46773-4-alexandru.ardelean@analog.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201111091259.46773-1-alexandru.ardelean@analog.com> References: <20201111091259.46773-1-alexandru.ardelean@analog.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312,18.0.737 definitions=2020-11-11_02:2020-11-10,2020-11-11 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 priorityscore=1501 mlxlogscore=999 clxscore=1015 lowpriorityscore=0 suspectscore=0 bulkscore=0 impostorscore=0 adultscore=0 spamscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011110050 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org The sense resistor is a parameter of the board. It should be configured in the driver via a device-tree / ACPI property, so that the proper current measurements can be done in the driver. It shouldn't be necessary that userspace need to know about the value of the resistor. It makes things a bit harder to make the application code portable from one board to another. This change implements support for the sense resistor to be configured from DT/ACPI and used in current calculations. Signed-off-by: Alexandru Ardelean --- drivers/hwmon/ltc2945.c | 53 ++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/drivers/hwmon/ltc2945.c b/drivers/hwmon/ltc2945.c index 6d4569a25471..909dd92a7a20 100644 --- a/drivers/hwmon/ltc2945.c +++ b/drivers/hwmon/ltc2945.c @@ -61,9 +61,11 @@ /** * struct ltc2945_state - driver instance specific data * @regmap regmap object to access device registers + * @r_sense_uohm current sense resistor value */ struct ltc2945_state { struct regmap *regmap; + u32 r_sense_uohm; }; static inline bool is_power_reg(u8 reg) @@ -101,9 +103,8 @@ static long long ltc2945_reg_to_val(struct device *dev, u8 reg) case LTC2945_MAX_POWER_THRES_H: case LTC2945_MIN_POWER_THRES_H: /* - * Convert to uW by assuming current is measured with - * an 1mOhm sense resistor, similar to current - * measurements. + * Convert to uW by and scale it with the configured + * sense resistor, similar to current measurements. * Control register bit 0 selects if voltage at SENSE+/VDD * or voltage at ADIN is used to measure power. */ @@ -112,10 +113,10 @@ static long long ltc2945_reg_to_val(struct device *dev, u8 reg) return ret; if (control & CONTROL_MULT_SELECT) { /* 25 mV * 25 uV = 0.625 uV resolution. */ - val *= 625LL; + val = DIV_ROUND_CLOSEST_ULL(val * 625LL * 1000, st->r_sense_uohm); } else { /* 0.5 mV * 25 uV = 0.0125 uV resolution. */ - val = (val * 25LL) >> 1; + val = DIV_ROUND_CLOSEST_ULL(val * 25LL * 1000, st->r_sense_uohm) >> 1; } break; case LTC2945_VIN_H: @@ -140,13 +141,10 @@ static long long ltc2945_reg_to_val(struct device *dev, u8 reg) case LTC2945_MAX_SENSE_THRES_H: case LTC2945_MIN_SENSE_THRES_H: /* - * 25 uV resolution. Convert to current as measured with - * an 1 mOhm sense resistor, in mA. If a different sense - * resistor is installed, calculate the actual current by - * dividing the reported current by the sense resistor value - * in mOhm. + * 25 uV resolution. Convert to current and scale it + * with the value of the sense resistor. */ - val *= 25; + val = DIV_ROUND_CLOSEST_ULL(val * 25 * 1000, st->r_sense_uohm); break; default: return -EINVAL; @@ -169,9 +167,8 @@ static int ltc2945_val_to_reg(struct device *dev, u8 reg, case LTC2945_MAX_POWER_THRES_H: case LTC2945_MIN_POWER_THRES_H: /* - * Convert to register value by assuming current is measured - * with an 1mOhm sense resistor, similar to current - * measurements. + * Convert to register value, scale it with the configured sense + * resistor value, similar to current measurements. * Control register bit 0 selects if voltage at SENSE+/VDD * or voltage at ADIN is used to measure power, which in turn * determines register calculations. @@ -181,14 +178,10 @@ static int ltc2945_val_to_reg(struct device *dev, u8 reg, return ret; if (control & CONTROL_MULT_SELECT) { /* 25 mV * 25 uV = 0.625 uV resolution. */ - val = DIV_ROUND_CLOSEST_ULL(val, 625); + val = DIV_ROUND_CLOSEST_ULL(val * 1000, 625 * st->r_sense_uohm); } else { - /* - * 0.5 mV * 25 uV = 0.0125 uV resolution. - * Divide first to avoid overflow; - * accept loss of accuracy. - */ - val = DIV_ROUND_CLOSEST_ULL(val, 25) * 2; + /* 0.5 mV * 25 uV = 0.0125 uV resolution. */ + val = DIV_ROUND_CLOSEST_ULL(val * 2 * 1000, 25 * st->r_sense_uohm); } break; case LTC2945_VIN_H: @@ -213,13 +206,10 @@ static int ltc2945_val_to_reg(struct device *dev, u8 reg, case LTC2945_MAX_SENSE_THRES_H: case LTC2945_MIN_SENSE_THRES_H: /* - * 25 uV resolution. Convert to current as measured with - * an 1 mOhm sense resistor, in mA. If a different sense - * resistor is installed, calculate the actual current by - * dividing the reported current by the sense resistor value - * in mOhm. + * 25 uV resolution. Convert to current and scale it + * with the value of the sense resistor, in mA. */ - val = DIV_ROUND_CLOSEST_ULL(val, 25); + val = DIV_ROUND_CLOSEST_ULL(val * 1000, 25 * st->r_sense_uohm); break; default: return -EINVAL; @@ -475,6 +465,15 @@ static int ltc2945_probe(struct i2c_client *client) return PTR_ERR(regmap); } + if (device_property_read_u32(dev, "shunt-resistor-micro-ohms", + &st->r_sense_uohm)) + st->r_sense_uohm = 1000; + + if (st->r_sense_uohm == 0) { + dev_err(dev, "Zero value provided for sense resistor in DT"); + return -EINVAL; + } + st->regmap = regmap; /* Clear faults */ From patchwork Wed Nov 11 09:12:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 11896993 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A6D6B1668 for ; Wed, 11 Nov 2020 09:09:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8C2DE206F1 for ; Wed, 11 Nov 2020 09:09:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726384AbgKKJIh (ORCPT ); Wed, 11 Nov 2020 04:08:37 -0500 Received: from mx0a-00128a01.pphosted.com ([148.163.135.77]:16014 "EHLO mx0a-00128a01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726606AbgKKJIc (ORCPT ); Wed, 11 Nov 2020 04:08:32 -0500 Received: from pps.filterd (m0167089.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0AB983qE014222; Wed, 11 Nov 2020 04:08:14 -0500 Received: from nwd2mta4.analog.com ([137.71.173.58]) by mx0a-00128a01.pphosted.com with ESMTP id 34nsc94j4y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Nov 2020 04:08:14 -0500 Received: from ASHBMBX9.ad.analog.com (ashbmbx9.ad.analog.com [10.64.17.10]) by nwd2mta4.analog.com (8.14.7/8.14.7) with ESMTP id 0AB98DFU040546 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=FAIL); Wed, 11 Nov 2020 04:08:13 -0500 Received: from ASHBCASHYB5.ad.analog.com (10.64.17.133) by ASHBMBX9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1779.2; Wed, 11 Nov 2020 04:08:12 -0500 Received: from ASHBMBX9.ad.analog.com (10.64.17.10) by ASHBCASHYB5.ad.analog.com (10.64.17.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1779.2; Wed, 11 Nov 2020 04:08:11 -0500 Received: from zeus.spd.analog.com (10.66.68.11) by ASHBMBX9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server id 15.1.1779.2 via Frontend Transport; Wed, 11 Nov 2020 04:08:11 -0500 Received: from localhost.localdomain ([10.48.65.12]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 0AB981gI023509; Wed, 11 Nov 2020 04:08:09 -0500 From: Alexandru Ardelean To: , , CC: , , , , , Alexandru Ardelean Subject: [PATCH v2 4/4] dt-bindings: hwmon: ltc2945: add device tree doc for ltc2945 Date: Wed, 11 Nov 2020 11:12:59 +0200 Message-ID: <20201111091259.46773-5-alexandru.ardelean@analog.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201111091259.46773-1-alexandru.ardelean@analog.com> References: <20201111091259.46773-1-alexandru.ardelean@analog.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312,18.0.737 definitions=2020-11-11_02:2020-11-10,2020-11-11 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 priorityscore=1501 bulkscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 phishscore=0 mlxlogscore=999 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011110050 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org This change adds a device-tree binding documentation for the Linear Technology (now Analog Devices) LTC2945 Wide Range I2C Power Monitor. Signed-off-by: Alexandru Ardelean Reviewed-by: Rob Herring --- .../bindings/hwmon/adi,ltc2945.yaml | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/adi,ltc2945.yaml diff --git a/Documentation/devicetree/bindings/hwmon/adi,ltc2945.yaml b/Documentation/devicetree/bindings/hwmon/adi,ltc2945.yaml new file mode 100644 index 000000000000..e49d7da09f74 --- /dev/null +++ b/Documentation/devicetree/bindings/hwmon/adi,ltc2945.yaml @@ -0,0 +1,49 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/hwmon/adi,ltc2945.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Linear Technology LTC2945 Wide Range I2C Power Monitor + +maintainers: + - Guenter Roeck + +description: | + The LTC2945 is a rail-to-rail system monitor that measures current, voltage, + and power consumption. + +properties: + compatible: + enum: + - adi,ltc2945 + + reg: + maxItems: 1 + + shunt-resistor-micro-ohms: + description: + The value of curent sense resistor in microohms. If not provided, + a default value of 1000 microohms is used. + default: 1000 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + ltc2945_i2c: ltc2945@6f { + compatible = "adi,ltc2945"; + reg = <0x6f>; + + shunt-resistor-micro-ohms = <20000>; + }; + }; +...