From patchwork Mon Mar 28 19:47:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 12794154 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 436D8C433F5 for ; Mon, 28 Mar 2022 19:49:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343700AbiC1Tvf (ORCPT ); Mon, 28 Mar 2022 15:51:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345653AbiC1TuE (ORCPT ); Mon, 28 Mar 2022 15:50:04 -0400 Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEB95B65; Mon, 28 Mar 2022 12:47:45 -0700 (PDT) Received: from tr.lan (ip-89-176-112-137.net.upcbroadband.cz [89.176.112.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 0F64383F7D; Mon, 28 Mar 2022 21:47:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1648496862; bh=eNaPFGNFNc1sKelaNjDEWR3YYyLoKTdtvyHaR1Eu4vY=; h=From:To:Cc:Subject:Date:From; b=e097iEkQY49L1NxFV/bgDU3Y+lM6afUEmME3HphNfYHbS2JUn8vNrZY4RQx6VT0+5 ywqsJWRSIad8mOzVKXydEmXBI1ugz+p99p4fnSeJug/tYPhPlhv0JGIrr9IwXZVB2Z +cCuThvQRJBPBzOT/yzWv3Non9zIPvG/rbtET+9KyyGN76smtcmnIdzSbwLEAa8DLz PV7bPIorTIDdFLXr+uSmT/MCUS3mT+sNlLgXN3V20dGRP+gLxGVD676OL+J66P99pz 8rLZ8NOhIDruodi5ClO2k+GfRE8iJg8xg0LFfKfnCG8VqZBfhUa7H0EEbOjzoHunyT BI0QFc+SKYJTw== From: Marek Vasut To: linux-iio@vger.kernel.org Cc: Marek Vasut , Krzysztof Kozlowski , Andy Shevchenko , Daniel Baluta , Jonathan Cameron , Rob Herring , devicetree@vger.kernel.org Subject: [PATCH v5 01/10] dt-bindings: iio: adc: ti,ads1015: Add missing ADS1115 compatible string Date: Mon, 28 Mar 2022 21:47:16 +0200 Message-Id: <20220328194725.149150-1-marex@denx.de> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add missing ti,ads1115 compatible string. This compatible string is supported by the Linux kernel driver and the ads1015 is a 12bit ADC while ads1115 is 16bit ADC. Add the missing compatible string. Acked-by: Krzysztof Kozlowski Signed-off-by: Marek Vasut Cc: Andy Shevchenko Cc: Daniel Baluta Cc: Jonathan Cameron Cc: Rob Herring Cc: devicetree@vger.kernel.org --- V2: Add AB from Krzysztof V3: No change V4: No change V5: No change --- Documentation/devicetree/bindings/iio/adc/ti,ads1015.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/iio/adc/ti,ads1015.yaml b/Documentation/devicetree/bindings/iio/adc/ti,ads1015.yaml index 2c2d01bbc296d..c31c80989cc9a 100644 --- a/Documentation/devicetree/bindings/iio/adc/ti,ads1015.yaml +++ b/Documentation/devicetree/bindings/iio/adc/ti,ads1015.yaml @@ -4,7 +4,7 @@ $id: http://devicetree.org/schemas/iio/adc/ti,ads1015.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: TI ADS1015 4 channel I2C analog to digital converter +title: TI ADS1015/ADS1115 4 channel I2C analog to digital converter maintainers: - Daniel Baluta @@ -15,7 +15,9 @@ description: | properties: compatible: - const: ti,ads1015 + enum: + - ti,ads1015 + - ti,ads1115 reg: maxItems: 1 From patchwork Mon Mar 28 19:47:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 12794145 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 C8171C433FE for ; Mon, 28 Mar 2022 19:49:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344124AbiC1TvZ (ORCPT ); Mon, 28 Mar 2022 15:51:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345649AbiC1TuC (ORCPT ); Mon, 28 Mar 2022 15:50:02 -0400 Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A205DB13; Mon, 28 Mar 2022 12:47:45 -0700 (PDT) Received: from tr.lan (ip-89-176-112-137.net.upcbroadband.cz [89.176.112.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 84FAD83F7E; Mon, 28 Mar 2022 21:47:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1648496862; bh=Cjl9mSicvUiED0u0YTBFHqN+vdDBzVXFMydlI4w/oTI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JZV8+nHqD4JMDUBF/Yv2Rh/vXeYOeZmiYm7aWhEuw9/qZzvB8v1dX0hl9W4eAnMb5 zuOH6UUXNXlQso7UvOzcs7vbr782EkbDTMa6wgrk1JSy66HFy+gCCciTw0lySmhAN3 nNtmlhT4yAoGylbqfmaOxvJtJ4eV0JevQ8DDIRG0nuhqfqa5WRdhfm+jpx2SxMHCYH RJnDdcliCnZdctL1pnl5ffiRPfEzA/+uCwPLbGX0wtAr8hJqU0HETBZEoJq7n0QL+Z iLQNxaoZay75xZVjRAzvMdKQGdXibS6efmxKOv0ffD7Wmf1di7VscDlhTDudFCdHcs mOzO7B3uWkg2g== From: Marek Vasut To: linux-iio@vger.kernel.org Cc: Marek Vasut , Krzysztof Kozlowski , Andy Shevchenko , Daniel Baluta , Jonathan Cameron , Rob Herring , devicetree@vger.kernel.org Subject: [PATCH v5 02/10] dt-bindings: iio: adc: ti,ads1015: Add TLA2024 compatible string Date: Mon, 28 Mar 2022 21:47:17 +0200 Message-Id: <20220328194725.149150-2-marex@denx.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220328194725.149150-1-marex@denx.de> References: <20220328194725.149150-1-marex@denx.de> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add ti,tla2024 compatible string. This device is compatible with ADS1015 except it has no on-chip comparator. Acked-by: Krzysztof Kozlowski Signed-off-by: Marek Vasut Cc: Andy Shevchenko Cc: Daniel Baluta Cc: Jonathan Cameron Cc: Rob Herring Cc: devicetree@vger.kernel.org --- V2: Add AB from Krzysztof V3: No change V4: No change V5: No change --- Documentation/devicetree/bindings/iio/adc/ti,ads1015.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/iio/adc/ti,ads1015.yaml b/Documentation/devicetree/bindings/iio/adc/ti,ads1015.yaml index c31c80989cc9a..a3b79438a13a5 100644 --- a/Documentation/devicetree/bindings/iio/adc/ti,ads1015.yaml +++ b/Documentation/devicetree/bindings/iio/adc/ti,ads1015.yaml @@ -18,6 +18,7 @@ properties: enum: - ti,ads1015 - ti,ads1115 + - ti,tla2024 reg: maxItems: 1 From patchwork Mon Mar 28 19:47:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 12794148 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 C0ACDC433EF for ; Mon, 28 Mar 2022 19:49:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344128AbiC1Tv2 (ORCPT ); Mon, 28 Mar 2022 15:51:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345650AbiC1TuE (ORCPT ); Mon, 28 Mar 2022 15:50:04 -0400 Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B437AB81 for ; Mon, 28 Mar 2022 12:47:45 -0700 (PDT) Received: from tr.lan (ip-89-176-112-137.net.upcbroadband.cz [89.176.112.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 0662A83F80; Mon, 28 Mar 2022 21:47:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1648496863; bh=7tY0ha+1QWNAevFoHt4t0iGCtqJfuL+5IsRyro8fOA8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LsrSBDELwMg3ZN0O4ZuXKum+ZeXEt4gDqmuBecNyNkegXpxhKZXh8Vc/e39YJdFAJ rLeYK5dyYWuj9dmglsb5A3rfETrdT0nBrehNXVE8YH1125d24F0RfFIPC4Je3MDBiT GOhV2gn47q8NUUraul0YGTOiIF7Cg7nVralo1azgeh8DTQs4NMWkP4PlbeIN9mwz0N 12ILb16qbFQjeAcDte8uEyQ2gjXsK6pXHs6V1/WcpgnBMqMx5uVGKIv0GrHMk3xHvo q5AKO2B0uzLuxsTmQ7h60QqNV9S5W7RMrGsHwILTuZ/HC4X58GT01AmFieSmGvxoFi a3g8tqAftSDvQ== From: Marek Vasut To: linux-iio@vger.kernel.org Cc: Marek Vasut , Andy Shevchenko , Daniel Baluta , Jonathan Cameron Subject: [PATCH v5 03/10] iio: adc: ti-ads1015: Switch to static const writeable ranges table Date: Mon, 28 Mar 2022 21:47:18 +0200 Message-Id: <20220328194725.149150-3-marex@denx.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220328194725.149150-1-marex@denx.de> References: <20220328194725.149150-1-marex@denx.de> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Switch the driver from code implementing test whether a regmap register is writeable to static const tables describing the test. No functional change. Signed-off-by: Marek Vasut Cc: Andy Shevchenko Cc: Daniel Baluta Cc: Jonathan Cameron --- V2: No change V3: No change V4: No change V5: No change --- drivers/iio/adc/ti-ads1015.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c index 068efbce17103..85932b9dc166a 100644 --- a/drivers/iio/adc/ti-ads1015.c +++ b/drivers/iio/adc/ti-ads1015.c @@ -273,23 +273,20 @@ static void ads1015_event_channel_disable(struct ads1015_data *data, int chan) data->event_channel = ADS1015_CHANNELS; } -static bool ads1015_is_writeable_reg(struct device *dev, unsigned int reg) -{ - switch (reg) { - case ADS1015_CFG_REG: - case ADS1015_LO_THRESH_REG: - case ADS1015_HI_THRESH_REG: - return true; - default: - return false; - } -} +static const struct regmap_range ads1015_writeable_ranges[] = { + regmap_reg_range(ADS1015_CFG_REG, ADS1015_HI_THRESH_REG), +}; + +static const struct regmap_access_table ads1015_writeable_table = { + .yes_ranges = ads1015_writeable_ranges, + .n_yes_ranges = ARRAY_SIZE(ads1015_writeable_ranges), +}; static const struct regmap_config ads1015_regmap_config = { .reg_bits = 8, .val_bits = 16, .max_register = ADS1015_HI_THRESH_REG, - .writeable_reg = ads1015_is_writeable_reg, + .wr_table = &ads1015_writeable_table, }; static const struct iio_chan_spec ads1015_channels[] = { From patchwork Mon Mar 28 19:47:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 12794149 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 A2EACC4321E for ; Mon, 28 Mar 2022 19:49:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343752AbiC1Tv3 (ORCPT ); Mon, 28 Mar 2022 15:51:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345654AbiC1TuE (ORCPT ); Mon, 28 Mar 2022 15:50:04 -0400 Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BDA4E4C for ; Mon, 28 Mar 2022 12:47:45 -0700 (PDT) Received: from tr.lan (ip-89-176-112-137.net.upcbroadband.cz [89.176.112.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 652BE83F82; Mon, 28 Mar 2022 21:47:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1648496863; bh=il55/u4kxeEILu8145m6itGhDW1Uqi7r8X705osdAgk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rCF2UIC54JIVFwAI+g8LgWewTGa8rwbh9lpiPGT7ab8DcYe/tqpwwqYILLGCzigxt B7W56hBPY350ANALMF5eKea9IMQy3/6hir895T0cwOACje0z0ahqt0mP1Rk7zal0d4 WXpzo2nS5khlOkgFbt7IB0DIO++zU+qPw4SNzasq3iFzreYsIsjhm1dNKQQPPchXmB /jcHJIt+M3ehcNLx55E+rjd4FWiAJZ65rIih8kmnObVNqedb3izDpGt9+xYtFJny5O kEqyEVENmJAYEnWtuKVa93oEb9Em9e0TBOHI4CMvpPR2XFwNPr+SNMNoXLEIm7fS8T aQQGFO5AqxgOA== From: Marek Vasut To: linux-iio@vger.kernel.org Cc: Marek Vasut , Andy Shevchenko , Daniel Baluta , Jonathan Cameron Subject: [PATCH v5 04/10] iio: adc: ti-ads1015: Deduplicate channel macros Date: Mon, 28 Mar 2022 21:47:19 +0200 Message-Id: <20220328194725.149150-4-marex@denx.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220328194725.149150-1-marex@denx.de> References: <20220328194725.149150-1-marex@denx.de> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org These macros differ only in the number of valid bits of each ADC sample and the shift of those bits, i.e. ADS1015 is 12bit ADC shifted by 4 left, ADS1115 is 16bit ADC shifted by 0. No functional change. Signed-off-by: Marek Vasut Cc: Andy Shevchenko Cc: Daniel Baluta Cc: Jonathan Cameron --- V2: No change V3: No change V4: No change V5: No change --- drivers/iio/adc/ti-ads1015.c | 86 +++++++++--------------------------- 1 file changed, 22 insertions(+), 64 deletions(-) diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c index 85932b9dc166a..fc3381ff34710 100644 --- a/drivers/iio/adc/ti-ads1015.c +++ b/drivers/iio/adc/ti-ads1015.c @@ -134,7 +134,7 @@ static const struct iio_event_spec ads1015_events[] = { }, }; -#define ADS1015_V_CHAN(_chan, _addr) { \ +#define ADS1015_V_CHAN(_chan, _addr, _realbits, _shift) { \ .type = IIO_VOLTAGE, \ .indexed = 1, \ .address = _addr, \ @@ -145,9 +145,9 @@ static const struct iio_event_spec ads1015_events[] = { .scan_index = _addr, \ .scan_type = { \ .sign = 's', \ - .realbits = 12, \ + .realbits = (_realbits), \ .storagebits = 16, \ - .shift = 4, \ + .shift = (_shift), \ .endianness = IIO_CPU, \ }, \ .event_spec = ads1015_events, \ @@ -155,7 +155,7 @@ static const struct iio_event_spec ads1015_events[] = { .datasheet_name = "AIN"#_chan, \ } -#define ADS1015_V_DIFF_CHAN(_chan, _chan2, _addr) { \ +#define ADS1015_V_DIFF_CHAN(_chan, _chan2, _addr, _realbits, _shift) { \ .type = IIO_VOLTAGE, \ .differential = 1, \ .indexed = 1, \ @@ -168,51 +168,9 @@ static const struct iio_event_spec ads1015_events[] = { .scan_index = _addr, \ .scan_type = { \ .sign = 's', \ - .realbits = 12, \ - .storagebits = 16, \ - .shift = 4, \ - .endianness = IIO_CPU, \ - }, \ - .event_spec = ads1015_events, \ - .num_event_specs = ARRAY_SIZE(ads1015_events), \ - .datasheet_name = "AIN"#_chan"-AIN"#_chan2, \ -} - -#define ADS1115_V_CHAN(_chan, _addr) { \ - .type = IIO_VOLTAGE, \ - .indexed = 1, \ - .address = _addr, \ - .channel = _chan, \ - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ - BIT(IIO_CHAN_INFO_SCALE) | \ - BIT(IIO_CHAN_INFO_SAMP_FREQ), \ - .scan_index = _addr, \ - .scan_type = { \ - .sign = 's', \ - .realbits = 16, \ - .storagebits = 16, \ - .endianness = IIO_CPU, \ - }, \ - .event_spec = ads1015_events, \ - .num_event_specs = ARRAY_SIZE(ads1015_events), \ - .datasheet_name = "AIN"#_chan, \ -} - -#define ADS1115_V_DIFF_CHAN(_chan, _chan2, _addr) { \ - .type = IIO_VOLTAGE, \ - .differential = 1, \ - .indexed = 1, \ - .address = _addr, \ - .channel = _chan, \ - .channel2 = _chan2, \ - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ - BIT(IIO_CHAN_INFO_SCALE) | \ - BIT(IIO_CHAN_INFO_SAMP_FREQ), \ - .scan_index = _addr, \ - .scan_type = { \ - .sign = 's', \ - .realbits = 16, \ + .realbits = (_realbits), \ .storagebits = 16, \ + .shift = (_shift), \ .endianness = IIO_CPU, \ }, \ .event_spec = ads1015_events, \ @@ -290,26 +248,26 @@ static const struct regmap_config ads1015_regmap_config = { }; static const struct iio_chan_spec ads1015_channels[] = { - ADS1015_V_DIFF_CHAN(0, 1, ADS1015_AIN0_AIN1), - ADS1015_V_DIFF_CHAN(0, 3, ADS1015_AIN0_AIN3), - ADS1015_V_DIFF_CHAN(1, 3, ADS1015_AIN1_AIN3), - ADS1015_V_DIFF_CHAN(2, 3, ADS1015_AIN2_AIN3), - ADS1015_V_CHAN(0, ADS1015_AIN0), - ADS1015_V_CHAN(1, ADS1015_AIN1), - ADS1015_V_CHAN(2, ADS1015_AIN2), - ADS1015_V_CHAN(3, ADS1015_AIN3), + ADS1015_V_DIFF_CHAN(0, 1, ADS1015_AIN0_AIN1, 12, 4), + ADS1015_V_DIFF_CHAN(0, 3, ADS1015_AIN0_AIN3, 12, 4), + ADS1015_V_DIFF_CHAN(1, 3, ADS1015_AIN1_AIN3, 12, 4), + ADS1015_V_DIFF_CHAN(2, 3, ADS1015_AIN2_AIN3, 12, 4), + ADS1015_V_CHAN(0, ADS1015_AIN0, 12, 4), + ADS1015_V_CHAN(1, ADS1015_AIN1, 12, 4), + ADS1015_V_CHAN(2, ADS1015_AIN2, 12, 4), + ADS1015_V_CHAN(3, ADS1015_AIN3, 12, 4), IIO_CHAN_SOFT_TIMESTAMP(ADS1015_TIMESTAMP), }; static const struct iio_chan_spec ads1115_channels[] = { - ADS1115_V_DIFF_CHAN(0, 1, ADS1015_AIN0_AIN1), - ADS1115_V_DIFF_CHAN(0, 3, ADS1015_AIN0_AIN3), - ADS1115_V_DIFF_CHAN(1, 3, ADS1015_AIN1_AIN3), - ADS1115_V_DIFF_CHAN(2, 3, ADS1015_AIN2_AIN3), - ADS1115_V_CHAN(0, ADS1015_AIN0), - ADS1115_V_CHAN(1, ADS1015_AIN1), - ADS1115_V_CHAN(2, ADS1015_AIN2), - ADS1115_V_CHAN(3, ADS1015_AIN3), + ADS1015_V_DIFF_CHAN(0, 1, ADS1015_AIN0_AIN1, 16, 0), + ADS1015_V_DIFF_CHAN(0, 3, ADS1015_AIN0_AIN3, 16, 0), + ADS1015_V_DIFF_CHAN(1, 3, ADS1015_AIN1_AIN3, 16, 0), + ADS1015_V_DIFF_CHAN(2, 3, ADS1015_AIN2_AIN3, 16, 0), + ADS1015_V_CHAN(0, ADS1015_AIN0, 16, 0), + ADS1015_V_CHAN(1, ADS1015_AIN1, 16, 0), + ADS1015_V_CHAN(2, ADS1015_AIN2, 16, 0), + ADS1015_V_CHAN(3, ADS1015_AIN3, 16, 0), IIO_CHAN_SOFT_TIMESTAMP(ADS1015_TIMESTAMP), }; From patchwork Mon Mar 28 19:47:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 12794152 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 B8B3AC433F5 for ; Mon, 28 Mar 2022 19:49:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344145AbiC1Tvb (ORCPT ); Mon, 28 Mar 2022 15:51:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345656AbiC1TuE (ORCPT ); Mon, 28 Mar 2022 15:50:04 -0400 Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09DCFC19 for ; Mon, 28 Mar 2022 12:47:45 -0700 (PDT) Received: from tr.lan (ip-89-176-112-137.net.upcbroadband.cz [89.176.112.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id C700083F84; Mon, 28 Mar 2022 21:47:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1648496864; bh=FDRhEvSejfdDdAU9jt9jON60Y9IvJkPgAeLL4qVKqZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OSuKEEi01XgpCT+R1ezE8iXf5uYksH4lffEG04My/KspoAgb1YHuPek5K5xLkTT0R oRnYyW0lmNpx/6FApUOvgFI8Z/3nwxCK1tmDBWh1K+L8kPMe2xGx/O8/kCghx3aErf bNhVVzkD+PMPYvH9yMn9otSjcSG8toD56SeAbNZhRZkCqW+KqT+J27dlig3Q3bVcRx X5TY0UhELGcre6eGLxP+o5YpJNnDIGEGC2TxMTovfiRI1sS1yDRDuKfHfAMXk6Gp18 wHCoKzOvace/JJC9xR1Po3tLEnU+MEaE+uig37jQlxsNlyJ6j9p+ravdlVl6dhB7dK dxYA9wLCZSCDQ== From: Marek Vasut To: linux-iio@vger.kernel.org Cc: Marek Vasut , Andy Shevchenko , Daniel Baluta , Jonathan Cameron Subject: [PATCH v5 05/10] iio: adc: ti-ads1015: Make channel event_spec optional Date: Mon, 28 Mar 2022 21:47:20 +0200 Message-Id: <20220328194725.149150-5-marex@denx.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220328194725.149150-1-marex@denx.de> References: <20220328194725.149150-1-marex@denx.de> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Pass event_spec and num_event_specs to ADS1015_V_CHAN and ADS1015_V_DIFF_CHAN macros, to make it possible to pass no event_spec at all for chips which have no comparator and thus no events. No functional change. Signed-off-by: Marek Vasut Cc: Andy Shevchenko Cc: Daniel Baluta Cc: Jonathan Cameron --- V2: No change V3: No change V4: No change V5: No change --- drivers/iio/adc/ti-ads1015.c | 60 +++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c index fc3381ff34710..7d0c0552f425c 100644 --- a/drivers/iio/adc/ti-ads1015.c +++ b/drivers/iio/adc/ti-ads1015.c @@ -134,7 +134,7 @@ static const struct iio_event_spec ads1015_events[] = { }, }; -#define ADS1015_V_CHAN(_chan, _addr, _realbits, _shift) { \ +#define ADS1015_V_CHAN(_chan, _addr, _realbits, _shift, _event_spec, _num_event_specs) { \ .type = IIO_VOLTAGE, \ .indexed = 1, \ .address = _addr, \ @@ -150,12 +150,12 @@ static const struct iio_event_spec ads1015_events[] = { .shift = (_shift), \ .endianness = IIO_CPU, \ }, \ - .event_spec = ads1015_events, \ - .num_event_specs = ARRAY_SIZE(ads1015_events), \ + .event_spec = (_event_spec), \ + .num_event_specs = (_num_event_specs), \ .datasheet_name = "AIN"#_chan, \ } -#define ADS1015_V_DIFF_CHAN(_chan, _chan2, _addr, _realbits, _shift) { \ +#define ADS1015_V_DIFF_CHAN(_chan, _chan2, _addr, _realbits, _shift, _event_spec, _num_event_specs) { \ .type = IIO_VOLTAGE, \ .differential = 1, \ .indexed = 1, \ @@ -173,8 +173,8 @@ static const struct iio_event_spec ads1015_events[] = { .shift = (_shift), \ .endianness = IIO_CPU, \ }, \ - .event_spec = ads1015_events, \ - .num_event_specs = ARRAY_SIZE(ads1015_events), \ + .event_spec = (_event_spec), \ + .num_event_specs = (_num_event_specs), \ .datasheet_name = "AIN"#_chan"-AIN"#_chan2, \ } @@ -248,26 +248,42 @@ static const struct regmap_config ads1015_regmap_config = { }; static const struct iio_chan_spec ads1015_channels[] = { - ADS1015_V_DIFF_CHAN(0, 1, ADS1015_AIN0_AIN1, 12, 4), - ADS1015_V_DIFF_CHAN(0, 3, ADS1015_AIN0_AIN3, 12, 4), - ADS1015_V_DIFF_CHAN(1, 3, ADS1015_AIN1_AIN3, 12, 4), - ADS1015_V_DIFF_CHAN(2, 3, ADS1015_AIN2_AIN3, 12, 4), - ADS1015_V_CHAN(0, ADS1015_AIN0, 12, 4), - ADS1015_V_CHAN(1, ADS1015_AIN1, 12, 4), - ADS1015_V_CHAN(2, ADS1015_AIN2, 12, 4), - ADS1015_V_CHAN(3, ADS1015_AIN3, 12, 4), + ADS1015_V_DIFF_CHAN(0, 1, ADS1015_AIN0_AIN1, 12, 4, + ads1015_events, ARRAY_SIZE(ads1015_events)), + ADS1015_V_DIFF_CHAN(0, 3, ADS1015_AIN0_AIN3, 12, 4, + ads1015_events, ARRAY_SIZE(ads1015_events)), + ADS1015_V_DIFF_CHAN(1, 3, ADS1015_AIN1_AIN3, 12, 4, + ads1015_events, ARRAY_SIZE(ads1015_events)), + ADS1015_V_DIFF_CHAN(2, 3, ADS1015_AIN2_AIN3, 12, 4, + ads1015_events, ARRAY_SIZE(ads1015_events)), + ADS1015_V_CHAN(0, ADS1015_AIN0, 12, 4, + ads1015_events, ARRAY_SIZE(ads1015_events)), + ADS1015_V_CHAN(1, ADS1015_AIN1, 12, 4, + ads1015_events, ARRAY_SIZE(ads1015_events)), + ADS1015_V_CHAN(2, ADS1015_AIN2, 12, 4, + ads1015_events, ARRAY_SIZE(ads1015_events)), + ADS1015_V_CHAN(3, ADS1015_AIN3, 12, 4, + ads1015_events, ARRAY_SIZE(ads1015_events)), IIO_CHAN_SOFT_TIMESTAMP(ADS1015_TIMESTAMP), }; static const struct iio_chan_spec ads1115_channels[] = { - ADS1015_V_DIFF_CHAN(0, 1, ADS1015_AIN0_AIN1, 16, 0), - ADS1015_V_DIFF_CHAN(0, 3, ADS1015_AIN0_AIN3, 16, 0), - ADS1015_V_DIFF_CHAN(1, 3, ADS1015_AIN1_AIN3, 16, 0), - ADS1015_V_DIFF_CHAN(2, 3, ADS1015_AIN2_AIN3, 16, 0), - ADS1015_V_CHAN(0, ADS1015_AIN0, 16, 0), - ADS1015_V_CHAN(1, ADS1015_AIN1, 16, 0), - ADS1015_V_CHAN(2, ADS1015_AIN2, 16, 0), - ADS1015_V_CHAN(3, ADS1015_AIN3, 16, 0), + ADS1015_V_DIFF_CHAN(0, 1, ADS1015_AIN0_AIN1, 16, 0, + ads1015_events, ARRAY_SIZE(ads1015_events)), + ADS1015_V_DIFF_CHAN(0, 3, ADS1015_AIN0_AIN3, 16, 0, + ads1015_events, ARRAY_SIZE(ads1015_events)), + ADS1015_V_DIFF_CHAN(1, 3, ADS1015_AIN1_AIN3, 16, 0, + ads1015_events, ARRAY_SIZE(ads1015_events)), + ADS1015_V_DIFF_CHAN(2, 3, ADS1015_AIN2_AIN3, 16, 0, + ads1015_events, ARRAY_SIZE(ads1015_events)), + ADS1015_V_CHAN(0, ADS1015_AIN0, 16, 0, + ads1015_events, ARRAY_SIZE(ads1015_events)), + ADS1015_V_CHAN(1, ADS1015_AIN1, 16, 0, + ads1015_events, ARRAY_SIZE(ads1015_events)), + ADS1015_V_CHAN(2, ADS1015_AIN2, 16, 0, + ads1015_events, ARRAY_SIZE(ads1015_events)), + ADS1015_V_CHAN(3, ADS1015_AIN3, 16, 0, + ads1015_events, ARRAY_SIZE(ads1015_events)), IIO_CHAN_SOFT_TIMESTAMP(ADS1015_TIMESTAMP), }; From patchwork Mon Mar 28 19:47:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 12794153 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 69583C433FE for ; Mon, 28 Mar 2022 19:49:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343666AbiC1Tvc (ORCPT ); Mon, 28 Mar 2022 15:51:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345657AbiC1TuE (ORCPT ); Mon, 28 Mar 2022 15:50:04 -0400 Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8353F32 for ; Mon, 28 Mar 2022 12:47:48 -0700 (PDT) Received: from tr.lan (ip-89-176-112-137.net.upcbroadband.cz [89.176.112.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 319EE83F86; Mon, 28 Mar 2022 21:47:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1648496864; bh=q1X6U3VCDDyB/wPfGUcvD6st0PApeUw32zo1bMpICVU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dyeTkCam4nQCd9c2E0kbc1uvDwZwIiCw5eLr6fDbB06tz5NPLFPwqMsTPfe6OmWN2 B+XzjlO2FkrFae30qCLcjTHcQlUvjubdKEPr38i1lsVvYNT9Sq1eHGme8KyK+HTi4x 00zR+vGsZAnFmkm+mdGu7j+mH6dPzQFDHUBvatt7u/nwzcqSEr3UXU/4yNf2yfD85A pSoYuqA7iaOg7hpxdlGiVmPgxH9ehG/iOJLYRUD0mbETJXe8Dvg7FVm1k4zWot6C2m ddspP4rKEjHNnjXyn5fAMcFYDAPtdSTDUNVPqcyuJU60ksyhej3qTeb9UXPpO7YvLb o59awNfeOksHA== From: Marek Vasut To: linux-iio@vger.kernel.org Cc: Marek Vasut , Andy Shevchenko , Daniel Baluta , Jonathan Cameron Subject: [PATCH v5 06/10] iio: adc: ti-ads1015: Add TLA2024 support Date: Mon, 28 Mar 2022 21:47:21 +0200 Message-Id: <20220328194725.149150-6-marex@denx.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220328194725.149150-1-marex@denx.de> References: <20220328194725.149150-1-marex@denx.de> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add support for TI TLA2024 ADC. This chip is compatible with ADS1015 except it has no comparator in it, hence the comparator configuration bits are missing in Configuration Register and the Hi_Thresh/Lo_Thresh registers are missing as well and so is event support. Signed-off-by: Marek Vasut Cc: Andy Shevchenko Cc: Daniel Baluta Cc: Jonathan Cameron --- V2: No change V3: Use ADS1015 attr group, that's the correct one for this part V4: No change V5: No change --- drivers/iio/adc/ti-ads1015.c | 53 ++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c index 7d0c0552f425c..51ab8bb3d9f1d 100644 --- a/drivers/iio/adc/ti-ads1015.c +++ b/drivers/iio/adc/ti-ads1015.c @@ -80,6 +80,7 @@ enum chip_ids { ADSXXXX = 0, ADS1015, ADS1115, + TLA2024, }; enum ads1015_channels { @@ -247,6 +248,22 @@ static const struct regmap_config ads1015_regmap_config = { .wr_table = &ads1015_writeable_table, }; +static const struct regmap_range tla2024_writeable_ranges[] = { + regmap_reg_range(ADS1015_CFG_REG, ADS1015_CFG_REG), +}; + +static const struct regmap_access_table tla2024_writeable_table = { + .yes_ranges = tla2024_writeable_ranges, + .n_yes_ranges = ARRAY_SIZE(tla2024_writeable_ranges), +}; + +static const struct regmap_config tla2024_regmap_config = { + .reg_bits = 8, + .val_bits = 16, + .max_register = ADS1015_CFG_REG, + .wr_table = &tla2024_writeable_table, +}; + static const struct iio_chan_spec ads1015_channels[] = { ADS1015_V_DIFF_CHAN(0, 1, ADS1015_AIN0_AIN1, 12, 4, ads1015_events, ARRAY_SIZE(ads1015_events)), @@ -287,6 +304,19 @@ static const struct iio_chan_spec ads1115_channels[] = { IIO_CHAN_SOFT_TIMESTAMP(ADS1015_TIMESTAMP), }; +static const struct iio_chan_spec tla2024_channels[] = { + ADS1015_V_DIFF_CHAN(0, 1, ADS1015_AIN0_AIN1, 12, 4, NULL, 0), + ADS1015_V_DIFF_CHAN(0, 3, ADS1015_AIN0_AIN3, 12, 4, NULL, 0), + ADS1015_V_DIFF_CHAN(1, 3, ADS1015_AIN1_AIN3, 12, 4, NULL, 0), + ADS1015_V_DIFF_CHAN(2, 3, ADS1015_AIN2_AIN3, 12, 4, NULL, 0), + ADS1015_V_CHAN(0, ADS1015_AIN0, 12, 4, NULL, 0), + ADS1015_V_CHAN(1, ADS1015_AIN1, 12, 4, NULL, 0), + ADS1015_V_CHAN(2, ADS1015_AIN2, 12, 4, NULL, 0), + ADS1015_V_CHAN(3, ADS1015_AIN3, 12, 4, NULL, 0), + IIO_CHAN_SOFT_TIMESTAMP(ADS1015_TIMESTAMP), +}; + + #ifdef CONFIG_PM static int ads1015_set_power_state(struct ads1015_data *data, bool on) { @@ -823,6 +853,12 @@ static const struct iio_info ads1115_info = { .attrs = &ads1115_attribute_group, }; +static const struct iio_info tla2024_info = { + .read_raw = ads1015_read_raw, + .write_raw = ads1015_write_raw, + .attrs = &ads1015_attribute_group, +}; + static int ads1015_client_get_channels_config(struct i2c_client *client) { struct iio_dev *indio_dev = i2c_get_clientdata(client); @@ -937,6 +973,12 @@ static int ads1015_probe(struct i2c_client *client, indio_dev->info = &ads1115_info; data->data_rate = (unsigned int *) &ads1115_data_rate; break; + case TLA2024: + indio_dev->channels = tla2024_channels; + indio_dev->num_channels = ARRAY_SIZE(tla2024_channels); + indio_dev->info = &tla2024_info; + data->data_rate = (unsigned int *) &ads1015_data_rate; + break; default: dev_err(&client->dev, "Unknown chip %d\n", chip); return -EINVAL; @@ -957,7 +999,9 @@ static int ads1015_probe(struct i2c_client *client, /* we need to keep this ABI the same as used by hwmon ADS1015 driver */ ads1015_get_channels_config(client); - data->regmap = devm_regmap_init_i2c(client, &ads1015_regmap_config); + data->regmap = devm_regmap_init_i2c(client, (chip == TLA2024) ? + &tla2024_regmap_config : + &ads1015_regmap_config); if (IS_ERR(data->regmap)) { dev_err(&client->dev, "Failed to allocate register map\n"); return PTR_ERR(data->regmap); @@ -971,7 +1015,7 @@ static int ads1015_probe(struct i2c_client *client, return ret; } - if (client->irq) { + if (client->irq && chip != TLA2024) { unsigned long irq_trig = irqd_get_trigger_type(irq_get_irq_data(client->irq)); unsigned int cfg_comp_mask = ADS1015_CFG_COMP_QUE_MASK | @@ -1073,6 +1117,7 @@ static const struct dev_pm_ops ads1015_pm_ops = { static const struct i2c_device_id ads1015_id[] = { {"ads1015", ADS1015}, {"ads1115", ADS1115}, + {"tla2024", TLA2024}, {} }; MODULE_DEVICE_TABLE(i2c, ads1015_id); @@ -1086,6 +1131,10 @@ static const struct of_device_id ads1015_of_match[] = { .compatible = "ti,ads1115", .data = (void *)ADS1115 }, + { + .compatible = "ti,tla2024", + .data = (void *)TLA2024 + }, {} }; MODULE_DEVICE_TABLE(of, ads1015_of_match); From patchwork Mon Mar 28 19:47:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 12794151 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 14197C433EF for ; Mon, 28 Mar 2022 19:49:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343944AbiC1Tvb (ORCPT ); Mon, 28 Mar 2022 15:51:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345658AbiC1TuF (ORCPT ); Mon, 28 Mar 2022 15:50:05 -0400 Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8A73101D for ; Mon, 28 Mar 2022 12:47:48 -0700 (PDT) Received: from tr.lan (ip-89-176-112-137.net.upcbroadband.cz [89.176.112.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 9681C83F87; Mon, 28 Mar 2022 21:47:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1648496864; bh=qBlhfEDCZn0VaQh6qpjFOnqnhMUDO61UR74V97fFc9A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xkLRQXWm6w3+HcRFl3rFD37SI/0CPkAsmc9SGzqpAfGx75LADasRvm1KQPE0I3xpf y00dLz6kJTZj6DzdsQfxDZCvPT9oQVW27fWsLQNulf+gl2jANE1BPP7T8/2uRdDJaK 4uXZ9/1g38b7gkvOIhqsci0THzz/M3JQ6h6nZdTEAOSULuMdpCxgM2hgYUpYbj+Ora 232hjnPaOLp0q9vRNNW4goKgMqY4LnkBRuo829j0yQHWY6LNUWkLCVBpO0a9qtyWdK 0MBrz45WrAIjy4sv80FD5Ux9foUCmX+ZsYM1DqmZFb2WTBtpBeILnkj313VEmweECa nKpSwZwAMMe8g== From: Marek Vasut To: linux-iio@vger.kernel.org Cc: Marek Vasut , Andy Shevchenko , Daniel Baluta , Jonathan Cameron Subject: [PATCH v5 07/10] iio: adc: ti-ads1015: Add static assert to test if shifted realbits fit into storagebits Date: Mon, 28 Mar 2022 21:47:22 +0200 Message-Id: <20220328194725.149150-7-marex@denx.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220328194725.149150-1-marex@denx.de> References: <20220328194725.149150-1-marex@denx.de> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add compile-time static_assert wrapper to verify that shifted realbits fit into storagebits. The macro is implemented in a more generic way so it can be used to verify other values if required. Signed-off-by: Marek Vasut Cc: Andy Shevchenko Cc: Daniel Baluta Cc: Jonathan Cameron --- V2: New patch V3: No change V4: No change V5: No change --- drivers/iio/adc/ti-ads1015.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c index 51ab8bb3d9f1d..73d848804a12d 100644 --- a/drivers/iio/adc/ti-ads1015.c +++ b/drivers/iio/adc/ti-ads1015.c @@ -135,6 +135,28 @@ static const struct iio_event_spec ads1015_events[] = { }, }; +/* + * Compile-time check whether _fitbits can accommodate up to _testbits + * bits. Returns _fitbits on success, fails to compile otherwise. + * + * The test works such that it multiplies constant _fitbits by constant + * double-negation of size of a non-empty structure, i.e. it multiplies + * constant _fitbits by constant 1 in each successful compilation case. + * The non-empty structure may contain C11 _Static_assert(), make use of + * this and place the kernel variant of static assert in there, so that + * it performs the compile-time check for _testbits <= _fitbits. Note + * that it is not possible to directly use static_assert in compound + * statements, hence this convoluted construct. + */ +#define FIT_CHECK(_testbits, _fitbits) \ + ( \ + (_fitbits) * \ + !!sizeof(struct { \ + static_assert((_testbits) <= (_fitbits)); \ + int pad; \ + }) \ + ) + #define ADS1015_V_CHAN(_chan, _addr, _realbits, _shift, _event_spec, _num_event_specs) { \ .type = IIO_VOLTAGE, \ .indexed = 1, \ @@ -147,7 +169,7 @@ static const struct iio_event_spec ads1015_events[] = { .scan_type = { \ .sign = 's', \ .realbits = (_realbits), \ - .storagebits = 16, \ + .storagebits = FIT_CHECK((_realbits) + (_shift), 16), \ .shift = (_shift), \ .endianness = IIO_CPU, \ }, \ @@ -170,7 +192,7 @@ static const struct iio_event_spec ads1015_events[] = { .scan_type = { \ .sign = 's', \ .realbits = (_realbits), \ - .storagebits = 16, \ + .storagebits = FIT_CHECK((_realbits) + (_shift), 16), \ .shift = (_shift), \ .endianness = IIO_CPU, \ }, \ From patchwork Mon Mar 28 19:47:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 12794146 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 2BFE5C43217 for ; Mon, 28 Mar 2022 19:49:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344130AbiC1Tv1 (ORCPT ); Mon, 28 Mar 2022 15:51:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345662AbiC1TuF (ORCPT ); Mon, 28 Mar 2022 15:50:05 -0400 Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8DAE10D7 for ; Mon, 28 Mar 2022 12:47:48 -0700 (PDT) Received: from tr.lan (ip-89-176-112-137.net.upcbroadband.cz [89.176.112.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id F08B883F88; Mon, 28 Mar 2022 21:47:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1648496865; bh=9jrh664qfiw72bIrsrVmq1NXWPiBuKVRN/VQgTvmpak=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HQM84J8QGWjLbgK76dePzdPsBrLJZgEmY2QQDPRssXSj8xNb0PrraWZEiXqWgaSTi 7hPKahMv/CsiQRjslLyunT1VjcK55a9fYsW+Fs7FPyYtZpWYeepWbv0lfq/jCRUJbP s5qC/ULlXyJb7Ei2DvhEWhkXfTYyfSDemghPHXfxkLZtGq/oCZaz+uLMu7EXjd+ml7 NrgI+u95zz8OI3uWuflo8VNDJbmoWBPe8476dl8qBWnTLoaoR7HrOjU5PVG/hVAJEE k295Cvhzs5U7BqLGdyZaRujsDEWgtTHVu3BuYbnA9hXcEFaR0Njnsulfj840ErTwDW xBCgsBO9mKuEw== From: Marek Vasut To: linux-iio@vger.kernel.org Cc: Marek Vasut , Andy Shevchenko , Daniel Baluta , Jonathan Cameron Subject: [PATCH v5 08/10] iio: adc: ti-ads1015: Convert to OF match data Date: Mon, 28 Mar 2022 21:47:23 +0200 Message-Id: <20220328194725.149150-8-marex@denx.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220328194725.149150-1-marex@denx.de> References: <20220328194725.149150-1-marex@denx.de> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Replace chip type enumeration in match data with pointer to static constant structure which contains all the different chip properties in one place, and then replace handling of chip type in probe() with simple copy of fields in the new match data structure into struct iio_dev. This reduces code and increases static data. Signed-off-by: Marek Vasut Cc: Andy Shevchenko Cc: Daniel Baluta Cc: Jonathan Cameron --- V3: New patch V4: - Fix contains typo in commit message - Drop redundant cast of device_get_match_data() - Return dev_err_probe() if no valid chip data found V5: Switch data_rate to signed int --- drivers/iio/adc/ti-ads1015.c | 110 +++++++++++++++++------------------ 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c index 73d848804a12d..5d9e9cdfe1c34 100644 --- a/drivers/iio/adc/ti-ads1015.c +++ b/drivers/iio/adc/ti-ads1015.c @@ -76,11 +76,12 @@ #define ADS1015_DEFAULT_DATA_RATE 4 #define ADS1015_DEFAULT_CHAN 0 -enum chip_ids { - ADSXXXX = 0, - ADS1015, - ADS1115, - TLA2024, +struct ads1015_chip_data { + struct iio_chan_spec const *channels; + int num_channels; + const struct iio_info *info; + const int *data_rate; + bool has_comparator; }; enum ads1015_channels { @@ -95,11 +96,11 @@ enum ads1015_channels { ADS1015_TIMESTAMP, }; -static const unsigned int ads1015_data_rate[] = { +static const int ads1015_data_rate[] = { 128, 250, 490, 920, 1600, 2400, 3300, 3300 }; -static const unsigned int ads1115_data_rate[] = { +static const int ads1115_data_rate[] = { 8, 16, 32, 64, 128, 250, 475, 860 }; @@ -226,7 +227,7 @@ struct ads1015_data { unsigned int comp_mode; struct ads1015_thresh_data thresh_data[ADS1015_CHANNELS]; - unsigned int *data_rate; + const int *data_rate; /* * Set to true when the ADC is switched to the continuous-conversion * mode and exits from a power-down state. This flag is used to avoid @@ -961,12 +962,18 @@ static int ads1015_set_conv_mode(struct ads1015_data *data, int mode) static int ads1015_probe(struct i2c_client *client, const struct i2c_device_id *id) { + const struct ads1015_chip_data *chip; struct iio_dev *indio_dev; struct ads1015_data *data; int ret; - enum chip_ids chip; int i; + chip = device_get_match_data(&client->dev); + if (!chip) + chip = (const struct ads1015_chip_data *)id->driver_data; + if (!chip) + return dev_err_probe(&client->dev, -EINVAL, "Unknown chip\n"); + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); if (!indio_dev) return -ENOMEM; @@ -979,34 +986,12 @@ static int ads1015_probe(struct i2c_client *client, indio_dev->name = ADS1015_DRV_NAME; indio_dev->modes = INDIO_DIRECT_MODE; - chip = (uintptr_t)device_get_match_data(&client->dev); - if (chip == ADSXXXX) - chip = id->driver_data; - switch (chip) { - case ADS1015: - indio_dev->channels = ads1015_channels; - indio_dev->num_channels = ARRAY_SIZE(ads1015_channels); - indio_dev->info = &ads1015_info; - data->data_rate = (unsigned int *) &ads1015_data_rate; - break; - case ADS1115: - indio_dev->channels = ads1115_channels; - indio_dev->num_channels = ARRAY_SIZE(ads1115_channels); - indio_dev->info = &ads1115_info; - data->data_rate = (unsigned int *) &ads1115_data_rate; - break; - case TLA2024: - indio_dev->channels = tla2024_channels; - indio_dev->num_channels = ARRAY_SIZE(tla2024_channels); - indio_dev->info = &tla2024_info; - data->data_rate = (unsigned int *) &ads1015_data_rate; - break; - default: - dev_err(&client->dev, "Unknown chip %d\n", chip); - return -EINVAL; - } - + indio_dev->channels = chip->channels; + indio_dev->num_channels = chip->num_channels; + indio_dev->info = chip->info; + data->data_rate = chip->data_rate; data->event_channel = ADS1015_CHANNELS; + /* * Set default lower and upper threshold to min and max value * respectively. @@ -1021,9 +1006,9 @@ static int ads1015_probe(struct i2c_client *client, /* we need to keep this ABI the same as used by hwmon ADS1015 driver */ ads1015_get_channels_config(client); - data->regmap = devm_regmap_init_i2c(client, (chip == TLA2024) ? - &tla2024_regmap_config : - &ads1015_regmap_config); + data->regmap = devm_regmap_init_i2c(client, chip->has_comparator ? + &ads1015_regmap_config : + &tla2024_regmap_config); if (IS_ERR(data->regmap)) { dev_err(&client->dev, "Failed to allocate register map\n"); return PTR_ERR(data->regmap); @@ -1037,7 +1022,7 @@ static int ads1015_probe(struct i2c_client *client, return ret; } - if (client->irq && chip != TLA2024) { + if (client->irq && chip->has_comparator) { unsigned long irq_trig = irqd_get_trigger_type(irq_get_irq_data(client->irq)); unsigned int cfg_comp_mask = ADS1015_CFG_COMP_QUE_MASK | @@ -1136,27 +1121,42 @@ static const struct dev_pm_ops ads1015_pm_ops = { ads1015_runtime_resume, NULL) }; +static const struct ads1015_chip_data ads1015_data = { + .channels = ads1015_channels, + .num_channels = ARRAY_SIZE(ads1015_channels), + .info = &ads1015_info, + .data_rate = ads1015_data_rate, + .has_comparator = true, +}; + +static const struct ads1015_chip_data ads1115_data = { + .channels = ads1115_channels, + .num_channels = ARRAY_SIZE(ads1115_channels), + .info = &ads1115_info, + .data_rate = ads1115_data_rate, + .has_comparator = true, +}; + +static const struct ads1015_chip_data tla2024_data = { + .channels = tla2024_channels, + .num_channels = ARRAY_SIZE(tla2024_channels), + .info = &tla2024_info, + .data_rate = ads1015_data_rate, + .has_comparator = false, +}; + static const struct i2c_device_id ads1015_id[] = { - {"ads1015", ADS1015}, - {"ads1115", ADS1115}, - {"tla2024", TLA2024}, + { "ads1015", (kernel_ulong_t)&ads1015_data }, + { "ads1115", (kernel_ulong_t)&ads1115_data }, + { "tla2024", (kernel_ulong_t)&tla2024_data }, {} }; MODULE_DEVICE_TABLE(i2c, ads1015_id); static const struct of_device_id ads1015_of_match[] = { - { - .compatible = "ti,ads1015", - .data = (void *)ADS1015 - }, - { - .compatible = "ti,ads1115", - .data = (void *)ADS1115 - }, - { - .compatible = "ti,tla2024", - .data = (void *)TLA2024 - }, + { .compatible = "ti,ads1015", .data = &ads1015_data }, + { .compatible = "ti,ads1115", .data = &ads1115_data }, + { .compatible = "ti,tla2024", .data = &tla2024_data }, {} }; MODULE_DEVICE_TABLE(of, ads1015_of_match); From patchwork Mon Mar 28 19:47:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 12794150 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 148D0C4167D for ; Mon, 28 Mar 2022 19:49:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344137AbiC1Tva (ORCPT ); Mon, 28 Mar 2022 15:51:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345659AbiC1TuF (ORCPT ); Mon, 28 Mar 2022 15:50:05 -0400 Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8677F5A for ; Mon, 28 Mar 2022 12:47:48 -0700 (PDT) Received: from tr.lan (ip-89-176-112-137.net.upcbroadband.cz [89.176.112.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 6889F83F8C; Mon, 28 Mar 2022 21:47:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1648496865; bh=IgdJzATzCXDqDTXwkuG3Kbo+wc8P1qCiuiaOPuLM1b0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LxpsnVdjwueHfS7D1NOTpKfcSPpZ9geX+w6wzII/9XpgLFVvJJzB8d9Br1FhV/Bix 3YJeQsJrEYZBSXom1G/5idA9ZxaZO1iYHRnvvIWzaUWPbXmkTc8u3HT7hhNoFT2X3o FkgGUVxrYvqN6Au5vs0+EI0kVK2WM3CPpUEawGm+NoZ06VSxUiyBfi12i1kE1M5tOx WgNuI6OJwIggz0XY0iR2hEQ9Qfy6FgfyMKVqKH+IEKdfkuG0LDLLjAm+h+RARjRq07 pjsNXKE47X/eBN6vvs2yiT1yx1M7lwRUZ6sMlPh76qhdNjsqAosbxVpKwVNADq5TZw frn+jlpQ1gYAQ== From: Marek Vasut To: linux-iio@vger.kernel.org Cc: Marek Vasut , Andy Shevchenko , Daniel Baluta , Jonathan Cameron Subject: [PATCH v5 09/10] iio: adc: ti-ads1015: Replace data_rate with chip data struct ads1015_data Date: Mon, 28 Mar 2022 21:47:24 +0200 Message-Id: <20220328194725.149150-9-marex@denx.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220328194725.149150-1-marex@denx.de> References: <20220328194725.149150-1-marex@denx.de> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Instead of storing only data_rate in private data, store pointer to the whole chip data and use the data_rate from chip data throughout the driver. No functional change. This is done in preparation for switching to read_avail(). Signed-off-by: Marek Vasut Cc: Andy Shevchenko Cc: Daniel Baluta Cc: Jonathan Cameron --- V3: New patch V4: Use switching in commit message V5: Switch data_rate to signed int --- drivers/iio/adc/ti-ads1015.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c index 5d9e9cdfe1c34..42ec4e5c2516e 100644 --- a/drivers/iio/adc/ti-ads1015.c +++ b/drivers/iio/adc/ti-ads1015.c @@ -227,7 +227,7 @@ struct ads1015_data { unsigned int comp_mode; struct ads1015_thresh_data thresh_data[ADS1015_CHANNELS]; - const int *data_rate; + const struct ads1015_chip_data *chip; /* * Set to true when the ADC is switched to the continuous-conversion * mode and exits from a power-down state. This flag is used to avoid @@ -368,6 +368,7 @@ static int ads1015_set_power_state(struct ads1015_data *data, bool on) static int ads1015_get_adc_result(struct ads1015_data *data, int chan, int *val) { + const int *data_rate = data->chip->data_rate; int ret, pga, dr, dr_old, conv_time; unsigned int old, mask, cfg; @@ -402,8 +403,8 @@ int ads1015_get_adc_result(struct ads1015_data *data, int chan, int *val) } if (data->conv_invalid) { dr_old = (old & ADS1015_CFG_DR_MASK) >> ADS1015_CFG_DR_SHIFT; - conv_time = DIV_ROUND_UP(USEC_PER_SEC, data->data_rate[dr_old]); - conv_time += DIV_ROUND_UP(USEC_PER_SEC, data->data_rate[dr]); + conv_time = DIV_ROUND_UP(USEC_PER_SEC, data_rate[dr_old]); + conv_time += DIV_ROUND_UP(USEC_PER_SEC, data_rate[dr]); conv_time += conv_time / 10; /* 10% internal clock inaccuracy */ usleep_range(conv_time, conv_time + 1); data->conv_invalid = false; @@ -470,7 +471,7 @@ static int ads1015_set_data_rate(struct ads1015_data *data, int chan, int rate) int i; for (i = 0; i < ARRAY_SIZE(ads1015_data_rate); i++) { - if (data->data_rate[i] == rate) { + if (data->chip->data_rate[i] == rate) { data->channel_data[chan].data_rate = i; return 0; } @@ -528,7 +529,7 @@ static int ads1015_read_raw(struct iio_dev *indio_dev, break; case IIO_CHAN_INFO_SAMP_FREQ: idx = data->channel_data[chan->address].data_rate; - *val = data->data_rate[idx]; + *val = data->chip->data_rate[idx]; ret = IIO_VAL_INT; break; default: @@ -588,7 +589,7 @@ static int ads1015_read_event(struct iio_dev *indio_dev, dr = data->channel_data[chan->address].data_rate; comp_queue = data->thresh_data[chan->address].comp_queue; period = ads1015_comp_queue[comp_queue] * - USEC_PER_SEC / data->data_rate[dr]; + USEC_PER_SEC / data->chip->data_rate[dr]; *val = period / USEC_PER_SEC; *val2 = period % USEC_PER_SEC; @@ -610,6 +611,7 @@ static int ads1015_write_event(struct iio_dev *indio_dev, int val2) { struct ads1015_data *data = iio_priv(indio_dev); + const int *data_rate = data->chip->data_rate; int realbits = chan->scan_type.realbits; int ret = 0; long long period; @@ -635,7 +637,7 @@ static int ads1015_write_event(struct iio_dev *indio_dev, for (i = 0; i < ARRAY_SIZE(ads1015_comp_queue) - 1; i++) { if (period <= ads1015_comp_queue[i] * - USEC_PER_SEC / data->data_rate[dr]) + USEC_PER_SEC / data_rate[dr]) break; } data->thresh_data[chan->address].comp_queue = i; @@ -989,7 +991,7 @@ static int ads1015_probe(struct i2c_client *client, indio_dev->channels = chip->channels; indio_dev->num_channels = chip->num_channels; indio_dev->info = chip->info; - data->data_rate = chip->data_rate; + data->chip = chip; data->event_channel = ADS1015_CHANNELS; /* From patchwork Mon Mar 28 19:47:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 12794147 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 107C6C433F5 for ; Mon, 28 Mar 2022 19:49:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344100AbiC1Tv0 (ORCPT ); Mon, 28 Mar 2022 15:51:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345661AbiC1TuF (ORCPT ); Mon, 28 Mar 2022 15:50:05 -0400 Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB2B010D9 for ; Mon, 28 Mar 2022 12:47:48 -0700 (PDT) Received: from tr.lan (ip-89-176-112-137.net.upcbroadband.cz [89.176.112.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id D5F8783F8D; Mon, 28 Mar 2022 21:47:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1648496866; bh=owVMwrQ74rQ4ceNaU7cW6L7SJ0tId3IEdIz83QiA1nc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HouvAC0pG3O4nd6LmC1oOWdKrj0XPTEnJiL+H/hx5GtCZCp4l6Jy8+FquCXjM0wx2 yCSllHIJiUDkrdMcT57xX5CBPy2PwhBJXRSQ0jHd0d4thcq3PblvdAmvMUbsCC/2P+ F9/yoo4M6ohw6gc9y0Bbfz5My28o52TjCghr/1RidMJJ4gCMs30EBQa87g9eKrS+1i zlNjWZA9TxQTMf8Rir9XE3vUAl8a0wg41EKp8PWc0ycif3io55CvAxwu64trDCAHLe 0eXlydWZTjMcTK39m85SqEvbFMPKAay4pXHRdRRW9Lr3p9kVM30iFVkWWaOLw2MM8Q JyJ8eJnhgO/yw== From: Marek Vasut To: linux-iio@vger.kernel.org Cc: Marek Vasut , Andy Shevchenko , Daniel Baluta , Jonathan Cameron Subject: [PATCH v5 10/10] iio: adc: ti-ads1015: Switch to read_avail Date: Mon, 28 Mar 2022 21:47:25 +0200 Message-Id: <20220328194725.149150-10-marex@denx.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220328194725.149150-1-marex@denx.de> References: <20220328194725.149150-1-marex@denx.de> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Replace sysfs attributes with read_avail() callback. This also permits removal of ads1115_info, since the scale attribute tables are now part of chip data. Signed-off-by: Marek Vasut Cc: Andy Shevchenko Cc: Daniel Baluta Cc: Jonathan Cameron Reviewed-by: Andy Shevchenko --- V3: New patch V4: - Reformat ads1x15 scale ranges pairwise - Turn the scale ranges into unsigned int V5: Switch scale to signed int --- drivers/iio/adc/ti-ads1015.c | 112 +++++++++++++++++++++-------------- 1 file changed, 67 insertions(+), 45 deletions(-) diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c index 42ec4e5c2516e..5544da80b6369 100644 --- a/drivers/iio/adc/ti-ads1015.c +++ b/drivers/iio/adc/ti-ads1015.c @@ -81,6 +81,9 @@ struct ads1015_chip_data { int num_channels; const struct iio_info *info; const int *data_rate; + const int data_rate_len; + const int *scale; + const int scale_len; bool has_comparator; }; @@ -108,10 +111,28 @@ static const int ads1115_data_rate[] = { * Translation from PGA bits to full-scale positive and negative input voltage * range in mV */ -static int ads1015_fullscale_range[] = { +static const int ads1015_fullscale_range[] = { 6144, 4096, 2048, 1024, 512, 256, 256, 256 }; +static const int ads1015_scale[] = { /* 12bit ADC */ + 256, 11, + 512, 11, + 1024, 11, + 2048, 11, + 4096, 11, + 6144, 11 +}; + +static const int ads1115_scale[] = { /* 16bit ADC */ + 256, 15, + 512, 15, + 1024, 15, + 2048, 15, + 4096, 15, + 6144, 15 +}; + /* * Translation from COMP_QUE field value to the number of successive readings * exceed the threshold values before an interrupt is generated @@ -166,6 +187,9 @@ static const struct iio_event_spec ads1015_events[] = { .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ BIT(IIO_CHAN_INFO_SCALE) | \ BIT(IIO_CHAN_INFO_SAMP_FREQ), \ + .info_mask_shared_by_all_available = \ + BIT(IIO_CHAN_INFO_SCALE) | \ + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ .scan_index = _addr, \ .scan_type = { \ .sign = 's', \ @@ -189,6 +213,9 @@ static const struct iio_event_spec ads1015_events[] = { .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ BIT(IIO_CHAN_INFO_SCALE) | \ BIT(IIO_CHAN_INFO_SAMP_FREQ), \ + .info_mask_shared_by_all_available = \ + BIT(IIO_CHAN_INFO_SCALE) | \ + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ .scan_index = _addr, \ .scan_type = { \ .sign = 's', \ @@ -470,7 +497,7 @@ static int ads1015_set_data_rate(struct ads1015_data *data, int chan, int rate) { int i; - for (i = 0; i < ARRAY_SIZE(ads1015_data_rate); i++) { + for (i = 0; i < data->chip->data_rate_len; i++) { if (data->chip->data_rate[i] == rate) { data->channel_data[chan].data_rate = i; return 0; @@ -480,6 +507,32 @@ static int ads1015_set_data_rate(struct ads1015_data *data, int chan, int rate) return -EINVAL; } +static int ads1015_read_avail(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + const int **vals, int *type, int *length, + long mask) +{ + struct ads1015_data *data = iio_priv(indio_dev); + + if (chan->type != IIO_VOLTAGE) + return -EINVAL; + + switch (mask) { + case IIO_CHAN_INFO_SCALE: + *type = IIO_VAL_FRACTIONAL_LOG2; + *vals = data->chip->scale; + *length = data->chip->scale_len; + return IIO_AVAIL_LIST; + case IIO_CHAN_INFO_SAMP_FREQ: + *type = IIO_VAL_INT; + *vals = data->chip->data_rate; + *length = data->chip->data_rate_len; + return IIO_AVAIL_LIST; + default: + return -EINVAL; + } +} + static int ads1015_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) @@ -828,60 +881,20 @@ static const struct iio_buffer_setup_ops ads1015_buffer_setup_ops = { .validate_scan_mask = &iio_validate_scan_mask_onehot, }; -static IIO_CONST_ATTR_NAMED(ads1015_scale_available, scale_available, - "3 2 1 0.5 0.25 0.125"); -static IIO_CONST_ATTR_NAMED(ads1115_scale_available, scale_available, - "0.1875 0.125 0.0625 0.03125 0.015625 0.007813"); - -static IIO_CONST_ATTR_NAMED(ads1015_sampling_frequency_available, - sampling_frequency_available, "128 250 490 920 1600 2400 3300"); -static IIO_CONST_ATTR_NAMED(ads1115_sampling_frequency_available, - sampling_frequency_available, "8 16 32 64 128 250 475 860"); - -static struct attribute *ads1015_attributes[] = { - &iio_const_attr_ads1015_scale_available.dev_attr.attr, - &iio_const_attr_ads1015_sampling_frequency_available.dev_attr.attr, - NULL, -}; - -static const struct attribute_group ads1015_attribute_group = { - .attrs = ads1015_attributes, -}; - -static struct attribute *ads1115_attributes[] = { - &iio_const_attr_ads1115_scale_available.dev_attr.attr, - &iio_const_attr_ads1115_sampling_frequency_available.dev_attr.attr, - NULL, -}; - -static const struct attribute_group ads1115_attribute_group = { - .attrs = ads1115_attributes, -}; - static const struct iio_info ads1015_info = { + .read_avail = ads1015_read_avail, .read_raw = ads1015_read_raw, .write_raw = ads1015_write_raw, .read_event_value = ads1015_read_event, .write_event_value = ads1015_write_event, .read_event_config = ads1015_read_event_config, .write_event_config = ads1015_write_event_config, - .attrs = &ads1015_attribute_group, -}; - -static const struct iio_info ads1115_info = { - .read_raw = ads1015_read_raw, - .write_raw = ads1015_write_raw, - .read_event_value = ads1015_read_event, - .write_event_value = ads1015_write_event, - .read_event_config = ads1015_read_event_config, - .write_event_config = ads1015_write_event_config, - .attrs = &ads1115_attribute_group, }; static const struct iio_info tla2024_info = { + .read_avail = ads1015_read_avail, .read_raw = ads1015_read_raw, .write_raw = ads1015_write_raw, - .attrs = &ads1015_attribute_group, }; static int ads1015_client_get_channels_config(struct i2c_client *client) @@ -1128,14 +1141,20 @@ static const struct ads1015_chip_data ads1015_data = { .num_channels = ARRAY_SIZE(ads1015_channels), .info = &ads1015_info, .data_rate = ads1015_data_rate, + .data_rate_len = ARRAY_SIZE(ads1015_data_rate), + .scale = ads1015_scale, + .scale_len = ARRAY_SIZE(ads1015_scale), .has_comparator = true, }; static const struct ads1015_chip_data ads1115_data = { .channels = ads1115_channels, .num_channels = ARRAY_SIZE(ads1115_channels), - .info = &ads1115_info, + .info = &ads1015_info, .data_rate = ads1115_data_rate, + .data_rate_len = ARRAY_SIZE(ads1115_data_rate), + .scale = ads1115_scale, + .scale_len = ARRAY_SIZE(ads1115_scale), .has_comparator = true, }; @@ -1144,6 +1163,9 @@ static const struct ads1015_chip_data tla2024_data = { .num_channels = ARRAY_SIZE(tla2024_channels), .info = &tla2024_info, .data_rate = ads1015_data_rate, + .data_rate_len = ARRAY_SIZE(ads1015_data_rate), + .scale = ads1015_scale, + .scale_len = ARRAY_SIZE(ads1015_scale), .has_comparator = false, };