From patchwork Mon Feb 24 23:26:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Franz Forstmayr X-Patchwork-Id: 11402111 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 62F4C1871 for ; Mon, 24 Feb 2020 23:27:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4173021D7E for ; Mon, 24 Feb 2020 23:27:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RsqzdoQe" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728527AbgBXX1F (ORCPT ); Mon, 24 Feb 2020 18:27:05 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:50284 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727976AbgBXX1D (ORCPT ); Mon, 24 Feb 2020 18:27:03 -0500 Received: by mail-wm1-f66.google.com with SMTP id a5so1111953wmb.0; Mon, 24 Feb 2020 15:27:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=8NVlvzE3Tm6P+gLHVWoR+a8t0nwDLWG0p5mfxUKacM8=; b=RsqzdoQe89nHPyKET3qT33aLg5yAxbgQswsmIDvzPvSW7D6bHtfMRpm0nbYYuP4Gtt B9UsEgE7n86ChF4Dm6CIHlaSOhB5/4iMGOzhwM49ofX6YupnwF+7Qvhl4TF4+CiJr4S4 gLAuRlDJS6BS6BWZVUrvXnLV2pIPM2RinXRL5M1SyZqy5zoNxw4qPmPH1IXpoy0Avgcd JMoKZKKULwgWohALQ2Y4RnbO6yAUZ6ozphw0I7QDihAmUW7SiDK56UfXHlbjAOsdsiuF ipYwR+jDXaNnHyRfHBAu5Hs5SLJZaactWOr2h572/bjV0WUAH+P8DGZ6D9Y0pXgz8coa rg6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=8NVlvzE3Tm6P+gLHVWoR+a8t0nwDLWG0p5mfxUKacM8=; b=D5iotJNP3zLFJQ0xnxCNUUm7xYMcO2lssrHNCDQhO1+7gW6DYeSVdIX1Mb7fN+IF9G xIJ9xXeLNUvJkXSe1089NcnaxRPXhE8aVRtkMBTgYvaeDeAQqorB98bmRoN4JVPVDIAO ix5Ty7O0kIejFyiddP+5y4qaZZv+RwAt+v7BxeMPTb/+wjVBNk2R044Et9/2+q4ZTRA4 uX7NEODcmFEfSCEh1+l6VEx9DibUxo1+EHlnK2DiwjGm3VkL2EfJzYjM9Y7/0EFz5+de gSGZKDsSDyZ564H2uAtsZgdsCUwNp8DAx1w/Az150yjRV48TyKzGi+G+3SlfymZ8e0sJ n5yA== X-Gm-Message-State: APjAAAVkd/hCDxzYCr35S+rQ0kEcHpDkhj3ZPHMxU2Pk5FtOTEITfkax JRm99z97G+MXFJwVKAjeeYo= X-Google-Smtp-Source: APXvYqwLkmHUUFun+m9+BvTzVsQnD+kGQ4DuAT8WzcyXQYxIMaZPQS9XVg5KG8cUpMT9brJIkdK1/w== X-Received: by 2002:a1c:a952:: with SMTP id s79mr1369235wme.83.1582586820935; Mon, 24 Feb 2020 15:27:00 -0800 (PST) Received: from buildbot.home (217-149-167-12.nat.highway.telekom.at. [217.149.167.12]) by smtp.googlemail.com with ESMTPSA id g25sm1971099wmh.3.2020.02.24.15.26.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2020 15:27:00 -0800 (PST) From: Franz Forstmayr To: forstmayr.franz@gmail.com Cc: Guenter Roeck , Jean Delvare , Rob Herring , Mark Rutland , Jonathan Corbet , linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH 1/3] dt-bindings: hwmon: Add compatible for ti,ina260 Date: Tue, 25 Feb 2020 00:26:45 +0100 Message-Id: <20200224232647.29213-1-forstmayr.franz@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Add initial support for power/current monitor INA260 Signed-off-by: Franz Forstmayr Acked-by: Rob Herring --- Documentation/devicetree/bindings/hwmon/ina2xx.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/hwmon/ina2xx.txt b/Documentation/devicetree/bindings/hwmon/ina2xx.txt index 02af0d94e921..92983a224109 100644 --- a/Documentation/devicetree/bindings/hwmon/ina2xx.txt +++ b/Documentation/devicetree/bindings/hwmon/ina2xx.txt @@ -8,6 +8,7 @@ Required properties: - "ti,ina226" for ina226 - "ti,ina230" for ina230 - "ti,ina231" for ina231 + - "ti,ina260" for ina260 - reg: I2C address Optional properties: From patchwork Mon Feb 24 23:26:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Franz Forstmayr X-Patchwork-Id: 11402113 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 912721580 for ; Mon, 24 Feb 2020 23:27:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6EA8921D7E for ; Mon, 24 Feb 2020 23:27:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LFWvr7kz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728512AbgBXX1F (ORCPT ); Mon, 24 Feb 2020 18:27:05 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:38875 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727843AbgBXX1E (ORCPT ); Mon, 24 Feb 2020 18:27:04 -0500 Received: by mail-wm1-f68.google.com with SMTP id a9so1184883wmj.3; Mon, 24 Feb 2020 15:27:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=23TD4aokwkLA4YFL/RMSToVR/ZyFznaziCp8vM8V51U=; b=LFWvr7kzjAVeBtnezK13os3rubmVM//bzWCe/YZhk/nB1g+w3D3bnzUzu45G3UeqTZ 65/jXVXYXxYaSlVVlZsWvgkdvzTQj51rUXSBJdzX4YHea4jZ5k9I9YSPG45yvpK7Orug 6pUsDAolp43uT07L9SjIpflDX6SG9HkVRxCl+aWTS3ExQ2X1J+raRPiyyGO5RDIv4oxR xwW/673j3cXzLku45QdQXWMLf0dPBKJNviKrqkYGHqDKvf9eOemvuM4+m45Drsu1CDUt 7EYfIt6u1+PR/mnY+iXYFVrfjYeLYnM95crd0TxrOzRi1zTvMecwIPiqjtth2eo3sj5Z bwIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=23TD4aokwkLA4YFL/RMSToVR/ZyFznaziCp8vM8V51U=; b=VdqpDUzfL3VjADeJ9LZwRn+HhLqnvplLPkcGAKgaMS3g1JraEQfWRj+ntiTrjTgv+2 o49bEFraN7VG/e2a5RtCTh1ZjWqrnZlgJRdhIubjBhY6ZBoAzo5kT43iibvW5n5QHgDw OApLrPN8u8WAKy/ii3Wc+o4FfZgtFruIMxpH2pTnJnQPTX5MFVRO/LjasLfC0WRb8QQh GmXedtNvWgGytHEa/7zbk6iVpBlLUz/gWXdcHEmTrHATECam8XpzqrB3EmkqMT5s6CZ7 dMfAW5xlkr/3fKIMJFVelVF7zWCRA9PNlVc5NHblgGNfRsK8t5ie3Wuxl/SZ8cOIEWsA GYaw== X-Gm-Message-State: APjAAAXHAJhWZk4KjSafMxI4qKmxAcFu8A9g7J1/VOMpmAZmAJbKbYHC bA372jSNo0YNkB6YfGzFD2s= X-Google-Smtp-Source: APXvYqz39UvdMoJ4Twe4n+7DfqpGUdBg03hSNF+vDC/9/q8YLSO8JHEWd3T0uUjWaPGilVQyh+evog== X-Received: by 2002:a1c:7205:: with SMTP id n5mr1390088wmc.9.1582586822341; Mon, 24 Feb 2020 15:27:02 -0800 (PST) Received: from buildbot.home (217-149-167-12.nat.highway.telekom.at. [217.149.167.12]) by smtp.googlemail.com with ESMTPSA id g25sm1971099wmh.3.2020.02.24.15.27.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2020 15:27:01 -0800 (PST) From: Franz Forstmayr To: forstmayr.franz@gmail.com Cc: Guenter Roeck , Jean Delvare , Rob Herring , Mark Rutland , Jonathan Corbet , linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH 2/3] docs: hwmon: Add support for ina2xx Date: Tue, 25 Feb 2020 00:26:46 +0100 Message-Id: <20200224232647.29213-2-forstmayr.franz@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200224232647.29213-1-forstmayr.franz@gmail.com> References: <20200224232647.29213-1-forstmayr.franz@gmail.com> Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Add documentation for INA260, power/current monitor with I2C interface. Signed-off-by: Franz Forstmayr --- Documentation/hwmon/ina2xx.rst | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Documentation/hwmon/ina2xx.rst b/Documentation/hwmon/ina2xx.rst index 94b9a260c518..74267dd433dd 100644 --- a/Documentation/hwmon/ina2xx.rst +++ b/Documentation/hwmon/ina2xx.rst @@ -53,6 +53,16 @@ Supported chips: http://www.ti.com/ + * Texas Instruments INA260 + + Prefix: 'ina260' + + Addresses: I2C 0x40 - 0x4f + + Datasheet: Publicly available at the Texas Instruments website + + http://www.ti.com/ + Author: Lothar Felten Description @@ -72,14 +82,17 @@ INA230 and INA231 are high or low side current shunt and power monitors with an I2C interface. The chips monitor both a shunt voltage drop and bus supply voltage. +INA260 is a high or low side current and power monitor with an integrated +shunt and I2C interface. + The shunt value in micro-ohms can be set via platform data or device tree at compile-time or via the shunt_resistor attribute in sysfs at run-time. Please refer to the Documentation/devicetree/bindings/hwmon/ina2xx.txt for bindings if the device tree is used. -Additionally ina226 supports update_interval attribute as described in -Documentation/hwmon/sysfs-interface.rst. Internally the interval is the sum of -bus and shunt voltage conversion times multiplied by the averaging rate. We +Additionally ina226 and ina260 supports update_interval attribute as described +in Documentation/hwmon/sysfs-interface.rst. Internally the interval is the sum +of bus and shunt voltage conversion times multiplied by the averaging rate. We don't touch the conversion times and only modify the number of averages. The lower limit of the update_interval is 2 ms, the upper limit is 2253 ms. The actual programmed interval may vary from the desired value. From patchwork Mon Feb 24 23:26:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Franz Forstmayr X-Patchwork-Id: 11402109 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 1AA0F1871 for ; Mon, 24 Feb 2020 23:27:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DAB8E2176D for ; Mon, 24 Feb 2020 23:27:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="V0gSEhJb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727976AbgBXX1H (ORCPT ); Mon, 24 Feb 2020 18:27:07 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:38879 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728354AbgBXX1G (ORCPT ); Mon, 24 Feb 2020 18:27:06 -0500 Received: by mail-wm1-f67.google.com with SMTP id a9so1184936wmj.3; Mon, 24 Feb 2020 15:27:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DciDFBtm2KODVam6qaaL1QMin/0mjJzkuCv9v0Jic/o=; b=V0gSEhJbqi1RFQeEGhXRYzvOcqu0nm4PVbi7BsS56ZCKl7zChjfNLBt2+Uij350EWI eD8feBt/awN5SE/QEi2ewZI2m6nqiXqpcrvpS1lJWD5EIq8XS8ezEprNQUVVOE5gafOd KvpBMVyFn/F9+0iLm20o1yBYrCBW6EfawbaIj9Ow8A0kAEtFgYiZO+xjQ/qo672TjcKo LAbH24KKO0+WHBjo2diOzgKOKoRHvWNt+dzhV+IHcA7/ZJO/1eKyCOk/PUEmPPXjafIo r/YNA8ZKT4nqqT+9x6UCcx+q6rDWL5e58VlavzONl+rmqpMY/wEGx7hRZLv2gv8zxwNz YlFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DciDFBtm2KODVam6qaaL1QMin/0mjJzkuCv9v0Jic/o=; b=YYSZpM0MibnCqg8jcn9Lh+luxcdvGAfELP1RoqHblbeqO12H+BoP/Ma1iZN/+n6Bvv Eg2Sv0axlr8d5EOKeZQthIPJrevpZlmzqAB7tOd2pvcX0azNi0cwPQEd50wgR4QutYb3 s5Sd36WW0cTdUVvFjU33G/VTgmx3MD8TcbgX+8wpoIbI9/HP7bmoxMXR0mwdIjX2+dAC jQ6jyLn6uGD16VZwzzRDLFqq3fFWOYz/6QxFVab5C58gIc7qQ6RjKtHjom8Rs+QNWsqj vMjnpNYFAjpp/UqrPq+IqHnV3ekLTdIQkp8HLMD3HKSUYUghc52ibK0tXVPSrZtB/THl zBCA== X-Gm-Message-State: APjAAAVnqalLqpzSBC9By1Qp9ctoggJMeTz3zL5At327VyAKVomwUnDG kTJvTfyDn0dbRBRsLB/WqVM= X-Google-Smtp-Source: APXvYqwSdmb3/b4hBOdmeVP2G1h5ARxbbqQdao65qirurmkLhyshwQlUrps4i4/Ly6xvQ80aAJtgnQ== X-Received: by 2002:a7b:ca49:: with SMTP id m9mr1397173wml.50.1582586823845; Mon, 24 Feb 2020 15:27:03 -0800 (PST) Received: from buildbot.home (217-149-167-12.nat.highway.telekom.at. [217.149.167.12]) by smtp.googlemail.com with ESMTPSA id g25sm1971099wmh.3.2020.02.24.15.27.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2020 15:27:03 -0800 (PST) From: Franz Forstmayr To: forstmayr.franz@gmail.com Cc: Guenter Roeck , Jean Delvare , Rob Herring , Mark Rutland , Jonathan Corbet , linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH 3/3] hwmon: (ina2xx) Add support for ina260 Date: Tue, 25 Feb 2020 00:26:47 +0100 Message-Id: <20200224232647.29213-3-forstmayr.franz@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200224232647.29213-1-forstmayr.franz@gmail.com> References: <20200224232647.29213-1-forstmayr.franz@gmail.com> Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Add initial support for INA260 power monitor with integrated shunt. Registers are different from other INA2xx devices, that's why a small translation table is used. Signed-off-by: Franz Forstmayr --- drivers/hwmon/Kconfig | 5 +- drivers/hwmon/ina2xx.c | 144 ++++++++++++++++++++++++++++++++++------- 2 files changed, 125 insertions(+), 24 deletions(-) diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index 05a30832c6ba..2916a60dd9b1 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -1683,11 +1683,12 @@ config SENSORS_INA2XX select REGMAP_I2C help If you say yes here you get support for INA219, INA220, INA226, - INA230, and INA231 power monitor chips. + INA230, INA231 and INA260 power monitor chips. The INA2xx driver is configured for the default configuration of the part as described in the datasheet. - Default value for Rshunt is 10 mOhms. + Default value for Rshunt is 10 mOhms, except for INA260 which has + an 2 mOhm integrated shunt. This driver can also be built as a module. If so, the module will be called ina2xx. diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c index e9e78c0b7212..bc5bb936bac5 100644 --- a/drivers/hwmon/ina2xx.c +++ b/drivers/hwmon/ina2xx.c @@ -18,6 +18,11 @@ * Bi-directional Current/Power Monitor with I2C Interface * Datasheet: http://www.ti.com/product/ina230 * + * INA260: + * Bi-directional Current/Power Monitor with I2C Interface and integrated + * shunt. + * Datasheet: http://www.ti.com/product/ina260 + * * Copyright (C) 2012 Lothar Felten * Thanks to Jan Volkering */ @@ -50,8 +55,14 @@ /* INA226 register definitions */ #define INA226_MASK_ENABLE 0x06 #define INA226_ALERT_LIMIT 0x07 +#define INA226_MANUFACTURER_ID 0xFE #define INA226_DIE_ID 0xFF +/* INA260 register definitions */ +#define INA260_CURRENT 0x01 +#define INA260_BUS_VOLTAGE 0x02 +#define INA260_POWER 0x03 + /* register count */ #define INA219_REGISTERS 6 #define INA226_REGISTERS 8 @@ -61,12 +72,14 @@ /* settings - depend on use case */ #define INA219_CONFIG_DEFAULT 0x399F /* PGA=8 */ #define INA226_CONFIG_DEFAULT 0x4527 /* averages=16 */ +#define INA260_CONFIG_DEFAULT 0x6127 /* averages=16 */ /* worst case is 68.10 ms (~14.6Hz, ina219) */ #define INA2XX_CONVERSION_RATE 15 #define INA2XX_MAX_DELAY 69 /* worst case delay in ms */ #define INA2XX_RSHUNT_DEFAULT 10000 +#define INA260_RSHUNT_DEFAULT 2000 /* bit mask for reading the averaging setting in the configuration register */ #define INA226_AVG_RD_MASK 0x0E00 @@ -74,8 +87,8 @@ #define INA226_READ_AVG(reg) (((reg) & INA226_AVG_RD_MASK) >> 9) #define INA226_SHIFT_AVG(val) ((val) << 9) -/* common attrs, ina226 attrs and NULL */ -#define INA2XX_MAX_ATTRIBUTE_GROUPS 3 +/* common attrs, shunt/bus voltage attrs, ina226 attrs and NULL */ +#define INA2XX_MAX_ATTRIBUTE_GROUPS 4 /* * Both bus voltage and shunt voltage conversion times for ina226 are set @@ -88,7 +101,15 @@ static struct regmap_config ina2xx_regmap_config = { .val_bits = 16, }; -enum ina2xx_ids { ina219, ina226 }; +enum ina2xx_ids { ina219, ina226, ina260 }; + +/* Translate the ina2xx addresses to ina260 addresses */ +const int ina260_translation[] = { 0, + 0, + INA260_BUS_VOLTAGE, + INA260_POWER, + INA260_CURRENT }; + struct ina2xx_config { u16 config_default; @@ -108,6 +129,7 @@ struct ina2xx_data { long power_lsb_uW; struct mutex config_lock; struct regmap *regmap; + enum ina2xx_ids chip; const struct attribute_group *groups[INA2XX_MAX_ATTRIBUTE_GROUPS]; }; @@ -131,6 +153,15 @@ static const struct ina2xx_config ina2xx_config[] = { .bus_voltage_lsb = 1250, .power_lsb_factor = 25, }, + [ina260] = { + .config_default = INA260_CONFIG_DEFAULT, + .calibration_value = 0, + .registers = INA226_REGISTERS, + .shunt_div = 0, + .bus_voltage_shift = 0, + .bus_voltage_lsb = 1250, + .power_lsb_factor = 10, + }, }; /* @@ -190,7 +221,11 @@ static int ina2xx_init(struct ina2xx_data *data) if (ret < 0) return ret; - return ina2xx_calibrate(data); + /* ina260 has no calibration register */ + if (data->chip != ina260) + return ina2xx_calibrate(data); + else + return 0; } static int ina2xx_read_reg(struct device *dev, int reg, unsigned int *regval) @@ -215,8 +250,9 @@ static int ina2xx_read_reg(struct device *dev, int reg, unsigned int *regval) * register and reinitialize if needed. * We do that extra read of the calibration register if there * is some hint of a chip reset. + * INA260 has an integrated shunt, thus no calibration register */ - if (*regval == 0) { + if (*regval == 0 && data->chip != ina260) { unsigned int cal; ret = regmap_read(data->regmap, INA2XX_CALIBRATION, @@ -287,20 +323,60 @@ static int ina2xx_get_value(struct ina2xx_data *data, u8 reg, return val; } +static int ina260_get_value(struct ina2xx_data *data, u8 reg, + unsigned int regval) +{ + int val; + + switch (reg) { + case INA260_BUS_VOLTAGE: + val = (regval >> data->config->bus_voltage_shift) + * data->config->bus_voltage_lsb; + val = DIV_ROUND_CLOSEST(val, 1000); + break; + case INA260_POWER: + val = regval * data->power_lsb_uW; + break; + case INA260_CURRENT: + /* signed register, result in mA */ + val = (s16)regval * data->current_lsb_uA; + val = DIV_ROUND_CLOSEST(val, 1000); + break; + default: + /* programmer goofed */ + WARN_ON_ONCE(1); + val = 0; + break; + } + return val; +} + static ssize_t ina2xx_value_show(struct device *dev, struct device_attribute *da, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(da); struct ina2xx_data *data = dev_get_drvdata(dev); unsigned int regval; + int err; + + if (data->chip == ina260) { + err = ina2xx_read_reg(dev, + ina260_translation[attr->index], ®val); + + if (err < 0) + return err; - int err = ina2xx_read_reg(dev, attr->index, ®val); + return snprintf(buf, PAGE_SIZE, "%d\n", ina260_get_value(data, + ina260_translation[attr->index], regval)); + } else { + err = ina2xx_read_reg(dev, attr->index, ®val); - if (err < 0) - return err; + if (err < 0) + return err; - return snprintf(buf, PAGE_SIZE, "%d\n", - ina2xx_get_value(data, attr->index, regval)); + return snprintf(buf, PAGE_SIZE, "%d\n", ina2xx_get_value(data, + attr->index, regval)); + } } /* @@ -409,11 +485,19 @@ static SENSOR_DEVICE_ATTR_RW(shunt_resistor, ina2xx_shunt, INA2XX_CALIBRATION); static SENSOR_DEVICE_ATTR_RW(update_interval, ina226_interval, 0); /* pointers to created device attributes */ -static struct attribute *ina2xx_attrs[] = { - &sensor_dev_attr_in0_input.dev_attr.attr, +static struct attribute *ina2xx_common_attrs[] = { &sensor_dev_attr_in1_input.dev_attr.attr, &sensor_dev_attr_curr1_input.dev_attr.attr, &sensor_dev_attr_power1_input.dev_attr.attr, + NULL, +}; + +static const struct attribute_group ina2xx_common_group = { + .attrs = ina2xx_common_attrs, +}; + +static struct attribute *ina2xx_attrs[] = { + &sensor_dev_attr_in0_input.dev_attr.attr, &sensor_dev_attr_shunt_resistor.dev_attr.attr, NULL, }; @@ -451,19 +535,28 @@ static int ina2xx_probe(struct i2c_client *client, return -ENOMEM; /* set the device type */ + data->chip = chip; data->config = &ina2xx_config[chip]; mutex_init(&data->config_lock); - if (of_property_read_u32(dev->of_node, "shunt-resistor", &val) < 0) { - struct ina2xx_platform_data *pdata = dev_get_platdata(dev); + if (chip != ina260) { + if (of_property_read_u32(dev->of_node, + "shunt-resistor", &val) < 0) { - if (pdata) - val = pdata->shunt_uohms; - else - val = INA2XX_RSHUNT_DEFAULT; - } + struct ina2xx_platform_data *pdata = dev_get_platdata(dev); - ina2xx_set_shunt(data, val); + if (pdata) + val = pdata->shunt_uohms; + else + val = INA2XX_RSHUNT_DEFAULT; + } + ina2xx_set_shunt(data, val); + } else { + data->rshunt = INA260_RSHUNT_DEFAULT; + /* ina260 has same LSB value for current and voltage */ + data->current_lsb_uA = data->config->bus_voltage_lsb; + data->power_lsb_uW = data->config->power_lsb_factor; + } ina2xx_regmap_config.max_register = data->config->registers; @@ -479,9 +572,11 @@ static int ina2xx_probe(struct i2c_client *client, return -ENODEV; } - data->groups[group++] = &ina2xx_group; - if (chip == ina226) + data->groups[group++] = &ina2xx_common_group; + if (chip == ina226 || chip == ina260) data->groups[group++] = &ina226_group; + if (chip != ina260) + data->groups[group++] = &ina2xx_group; hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, data, data->groups); @@ -500,6 +595,7 @@ static const struct i2c_device_id ina2xx_id[] = { { "ina226", ina226 }, { "ina230", ina226 }, { "ina231", ina226 }, + { "ina260", ina260 }, { } }; MODULE_DEVICE_TABLE(i2c, ina2xx_id); @@ -525,6 +621,10 @@ static const struct of_device_id __maybe_unused ina2xx_of_match[] = { .compatible = "ti,ina231", .data = (void *)ina226 }, + { + .compatible = "ti,ina260", + .data = (void *)ina260 + }, { }, }; MODULE_DEVICE_TABLE(of, ina2xx_of_match);