From patchwork Wed Aug 31 09:55:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksij Rempel X-Patchwork-Id: 12960603 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 D035CECAAD1 for ; Wed, 31 Aug 2022 09:56:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229655AbiHaJ4U (ORCPT ); Wed, 31 Aug 2022 05:56:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230036AbiHaJ4U (ORCPT ); Wed, 31 Aug 2022 05:56:20 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76E50C579E for ; Wed, 31 Aug 2022 02:56:19 -0700 (PDT) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oTKS9-0000tg-GI; Wed, 31 Aug 2022 11:56:09 +0200 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1oTKS8-0032Z0-Hg; Wed, 31 Aug 2022 11:56:08 +0200 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1oTKS7-00HRUS-Sg; Wed, 31 Aug 2022 11:56:07 +0200 From: Oleksij Rempel To: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski Cc: Oleksij Rempel , Krzysztof Kozlowski , kernel@pengutronix.de, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v2 1/3] dt-bindings: iio: adc: ti,tsc2046: add vref-supply property Date: Wed, 31 Aug 2022 11:55:59 +0200 Message-Id: <20220831095601.4157195-1-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-iio@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add property for the voltage reference supply. Signed-off-by: Oleksij Rempel Acked-by: Krzysztof Kozlowski --- changes v2 - add Acked-by: Krzysztof Kozlowski --- Documentation/devicetree/bindings/iio/adc/ti,tsc2046.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/adc/ti,tsc2046.yaml b/Documentation/devicetree/bindings/iio/adc/ti,tsc2046.yaml index 601d69971d84a..7faf12b1598b9 100644 --- a/Documentation/devicetree/bindings/iio/adc/ti,tsc2046.yaml +++ b/Documentation/devicetree/bindings/iio/adc/ti,tsc2046.yaml @@ -25,6 +25,9 @@ properties: spi-max-frequency: true + vref-supply: + description: Optional supply of the reference voltage + "#io-channel-cells": const: 1 From patchwork Wed Aug 31 09:56:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksij Rempel X-Patchwork-Id: 12960604 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 0F17CECAAD1 for ; Wed, 31 Aug 2022 09:56:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230313AbiHaJ4V (ORCPT ); Wed, 31 Aug 2022 05:56:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230036AbiHaJ4V (ORCPT ); Wed, 31 Aug 2022 05:56:21 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45D56C59F3 for ; Wed, 31 Aug 2022 02:56:20 -0700 (PDT) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oTKSB-0000w5-QJ; Wed, 31 Aug 2022 11:56:11 +0200 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1oTKSA-0032Z9-Vn; Wed, 31 Aug 2022 11:56:10 +0200 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1oTKS9-00HRUc-QO; Wed, 31 Aug 2022 11:56:09 +0200 From: Oleksij Rempel To: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v2 2/3] iio: adc: tsc2046: add vref support Date: Wed, 31 Aug 2022 11:56:00 +0200 Message-Id: <20220831095601.4157195-2-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220831095601.4157195-1-o.rempel@pengutronix.de> References: <20220831095601.4157195-1-o.rempel@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-iio@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org If VREF pin is attached, we should use external VREF source instead of the internal. Otherwise we will get wrong measurements on some of channel types. Signed-off-by: Oleksij Rempel --- drivers/iio/adc/ti-tsc2046.c | 64 +++++++++++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 9 deletions(-) diff --git a/drivers/iio/adc/ti-tsc2046.c b/drivers/iio/adc/ti-tsc2046.c index 0d9436a69cbfb..bbc8b4137b0b1 100644 --- a/drivers/iio/adc/ti-tsc2046.c +++ b/drivers/iio/adc/ti-tsc2046.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -175,6 +176,9 @@ struct tsc2046_adc_priv { u32 time_per_bit_ns; struct tsc2046_adc_ch_cfg ch_cfg[TI_TSC2046_MAX_CHAN]; + bool use_internal_vref; + unsigned int vref_mv; + struct regulator *vref_reg; }; #define TI_TSC2046_V_CHAN(index, bits, name) \ @@ -252,7 +256,9 @@ static u8 tsc2046_adc_get_cmd(struct tsc2046_adc_priv *priv, int ch_idx, case TI_TSC2046_ADDR_AUX: case TI_TSC2046_ADDR_VBAT: case TI_TSC2046_ADDR_TEMP0: - pd |= TI_TSC2046_SER | TI_TSC2046_PD1_VREF_ON; + pd |= TI_TSC2046_SER; + if (priv->use_internal_vref) + pd |= TI_TSC2046_PD1_VREF_ON; } return TI_TSC2046_START | FIELD_PREP(TI_TSC2046_ADDR, ch_idx) | pd; @@ -468,7 +474,7 @@ static int tsc2046_adc_read_raw(struct iio_dev *indio_dev, * So, it is better to use external voltage-divider driver * instead, which is calculating complete chain. */ - *val = TI_TSC2046_INT_VREF; + *val = priv->vref_mv; *val2 = chan->scan_type.realbits; return IIO_VAL_FRACTIONAL_LOG2; } @@ -781,22 +787,42 @@ static int tsc2046_adc_probe(struct spi_device *spi) indio_dev->num_channels = dcfg->num_channels; indio_dev->info = &tsc2046_adc_info; + priv->vref_reg = devm_regulator_get_optional(&spi->dev, "vref"); + if (!IS_ERR(priv->vref_reg)) { + ret = regulator_enable(priv->vref_reg); + if (ret) + return ret; + + ret = regulator_get_voltage(priv->vref_reg); + if (ret < 0) + goto err_regulator_disable; + + priv->vref_mv = ret / 1000; + priv->use_internal_vref = false; + } else { + /* Use internal reference */ + priv->vref_mv = TI_TSC2046_INT_VREF; + priv->use_internal_vref = true; + } + tsc2046_adc_parse_fwnode(priv); ret = tsc2046_adc_setup_spi_msg(priv); if (ret) - return ret; + goto err_regulator_disable; mutex_init(&priv->slock); ret = devm_request_irq(dev, spi->irq, &tsc2046_adc_irq, IRQF_NO_AUTOEN, indio_dev->name, indio_dev); if (ret) - return ret; + goto err_regulator_disable; trig = devm_iio_trigger_alloc(dev, "touchscreen-%s", indio_dev->name); - if (!trig) - return -ENOMEM; + if (!trig) { + ret = -ENOMEM; + goto err_regulator_disable; + } priv->trig = trig; iio_trigger_set_drvdata(trig, indio_dev); @@ -811,20 +837,39 @@ static int tsc2046_adc_probe(struct spi_device *spi) ret = devm_iio_trigger_register(dev, trig); if (ret) { dev_err(dev, "failed to register trigger\n"); - return ret; + goto err_regulator_disable; } ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL, &tsc2046_adc_trigger_handler, NULL); if (ret) { dev_err(dev, "Failed to setup triggered buffer\n"); - return ret; + goto err_regulator_disable; } /* set default trigger */ indio_dev->trig = iio_trigger_get(priv->trig); - return devm_iio_device_register(dev, indio_dev); + ret = devm_iio_device_register(dev, indio_dev); + if (ret) + goto err_regulator_disable; + + return 0; + +err_regulator_disable: + if (!IS_ERR(priv->vref_reg)) + regulator_disable(priv->vref_reg); + + return ret; +} + +static void tsc2046_adc_remove(struct spi_device *spi) +{ + struct iio_dev *indio_dev = spi_get_drvdata(spi); + struct tsc2046_adc_priv *priv = iio_priv(indio_dev); + + if (!IS_ERR(priv->vref_reg)) + regulator_disable(priv->vref_reg); } static const struct of_device_id ads7950_of_table[] = { @@ -839,6 +884,7 @@ static struct spi_driver tsc2046_adc_driver = { .of_match_table = ads7950_of_table, }, .probe = tsc2046_adc_probe, + .remove = tsc2046_adc_remove, }; module_spi_driver(tsc2046_adc_driver); From patchwork Wed Aug 31 09:56:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksij Rempel X-Patchwork-Id: 12960605 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 07641C0502C for ; Wed, 31 Aug 2022 09:56:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230322AbiHaJ4X (ORCPT ); Wed, 31 Aug 2022 05:56:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230304AbiHaJ4V (ORCPT ); Wed, 31 Aug 2022 05:56:21 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77896C579E for ; Wed, 31 Aug 2022 02:56:20 -0700 (PDT) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oTKSB-0000vx-Ri; Wed, 31 Aug 2022 11:56:11 +0200 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1oTKSA-0032Z6-UO; Wed, 31 Aug 2022 11:56:10 +0200 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1oTKSA-00HRUl-CE; Wed, 31 Aug 2022 11:56:10 +0200 From: Oleksij Rempel To: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v2 3/3] iio: adc: tsc2046: silent spi_device_id warning Date: Wed, 31 Aug 2022 11:56:01 +0200 Message-Id: <20220831095601.4157195-3-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220831095601.4157195-1-o.rempel@pengutronix.de> References: <20220831095601.4157195-1-o.rempel@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-iio@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add spi_device_id to silent following kernel runtime warning: "SPI driver tsc2046 has no spi_device_id for ti,tsc2046e-adc" Signed-off-by: Oleksij Rempel --- changes v2: - attach actual driver_data - use spi_get_device_id fallback --- drivers/iio/adc/ti-tsc2046.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/iio/adc/ti-tsc2046.c b/drivers/iio/adc/ti-tsc2046.c index bbc8b4137b0b1..ef78826241ee8 100644 --- a/drivers/iio/adc/ti-tsc2046.c +++ b/drivers/iio/adc/ti-tsc2046.c @@ -762,6 +762,13 @@ static int tsc2046_adc_probe(struct spi_device *spi) } dcfg = device_get_match_data(dev); + if (!dcfg) { + const struct spi_device_id *id; + + id = spi_get_device_id(spi); + dcfg = (const struct tsc2046_adc_dcfg *)id->driver_data; + } + if (!dcfg) return -EINVAL; @@ -878,11 +885,18 @@ static const struct of_device_id ads7950_of_table[] = { }; MODULE_DEVICE_TABLE(of, ads7950_of_table); +static const struct spi_device_id tsc2046_adc_spi_ids[] = { + { "tsc2046e-adc", (unsigned long)&tsc2046_adc_dcfg_tsc2046e }, + { } +}; +MODULE_DEVICE_TABLE(spi, tsc2046_adc_spi_ids); + static struct spi_driver tsc2046_adc_driver = { .driver = { .name = "tsc2046", .of_match_table = ads7950_of_table, }, + .id_table = tsc2046_adc_spi_ids, .probe = tsc2046_adc_probe, .remove = tsc2046_adc_remove, };