From nobody Sat Apr 18 19:10:14 2026 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 8F723C43334 for ; Mon, 11 Jul 2022 13:43:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230345AbiGKNna (ORCPT ); Mon, 11 Jul 2022 09:43:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230008AbiGKNnV (ORCPT ); Mon, 11 Jul 2022 09:43:21 -0400 Received: from maillog.nuvoton.com (maillog.nuvoton.com [202.39.227.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 74D794D82A; Mon, 11 Jul 2022 06:43:20 -0700 (PDT) Received: from NTHCCAS01.nuvoton.com (NTHCCAS01.nuvoton.com [10.1.8.28]) by maillog.nuvoton.com (Postfix) with ESMTP id 615111C80987; Mon, 11 Jul 2022 21:43:19 +0800 (CST) Received: from NTHCML01A.nuvoton.com (10.1.8.177) by NTHCCAS01.nuvoton.com (10.1.8.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Mon, 11 Jul 2022 21:43:19 +0800 Received: from NTHCCAS01.nuvoton.com (10.1.8.28) by NTHCML01A.nuvoton.com (10.1.8.177) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 11 Jul 2022 21:43:18 +0800 Received: from taln60.nuvoton.co.il (10.191.1.180) by NTHCCAS01.nuvoton.com (10.1.12.25) with Microsoft SMTP Server id 15.1.2375.7 via Frontend Transport; Mon, 11 Jul 2022 21:43:18 +0800 Received: by taln60.nuvoton.co.il (Postfix, from userid 10070) id 0884363A23; Mon, 11 Jul 2022 16:43:18 +0300 (IDT) From: Tomer Maimon To: , , , , , , , , , , , CC: , , , , Tomer Maimon Subject: [PATCH v1 1/2] dt-bindings: iio: adc: npcm: Add npcm845 compatible string Date: Mon, 11 Jul 2022 16:43:10 +0300 Message-ID: <20220711134312.234268-2-tmaimon77@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220711134312.234268-1-tmaimon77@gmail.com> References: <20220711134312.234268-1-tmaimon77@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add a compatible string for Nuvoton BMC NPCM845 ADC. Signed-off-by: Tomer Maimon --- .../devicetree/bindings/iio/adc/nuvoton,npcm750-adc.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/iio/adc/nuvoton,npcm750-adc.= yaml b/Documentation/devicetree/bindings/iio/adc/nuvoton,npcm750-adc.yaml index 001cf263b7d5..c9e9c5bf5e5b 100644 --- a/Documentation/devicetree/bindings/iio/adc/nuvoton,npcm750-adc.yaml +++ b/Documentation/devicetree/bindings/iio/adc/nuvoton,npcm750-adc.yaml @@ -14,7 +14,10 @@ description: =20 properties: compatible: - const: nuvoton,npcm750-adc + oneOf: + - items: + - const: nuvoton,npcm750-adc + - const: nuvoton,npcm845-adc =20 reg: maxItems: 1 --=20 2.33.0 From nobody Sat Apr 18 19:10:14 2026 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 94425C433EF for ; Mon, 11 Jul 2022 13:43:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230375AbiGKNnd (ORCPT ); Mon, 11 Jul 2022 09:43:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230286AbiGKNnW (ORCPT ); Mon, 11 Jul 2022 09:43:22 -0400 Received: from maillog.nuvoton.com (maillog.nuvoton.com [202.39.227.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A60684D809; Mon, 11 Jul 2022 06:43:21 -0700 (PDT) Received: from NTHCCAS01.nuvoton.com (NTHCCAS01.nuvoton.com [10.1.8.28]) by maillog.nuvoton.com (Postfix) with ESMTP id E21CC1C80CA9; Mon, 11 Jul 2022 21:43:20 +0800 (CST) Received: from NTHCCAS01.nuvoton.com (10.1.8.28) by NTHCCAS01.nuvoton.com (10.1.8.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Mon, 11 Jul 2022 21:43:20 +0800 Received: from taln60.nuvoton.co.il (10.191.1.180) by NTHCCAS01.nuvoton.com (10.1.12.25) with Microsoft SMTP Server id 15.1.2375.7 via Frontend Transport; Mon, 11 Jul 2022 21:43:20 +0800 Received: by taln60.nuvoton.co.il (Postfix, from userid 10070) id 81BDA63A23; Mon, 11 Jul 2022 16:43:19 +0300 (IDT) From: Tomer Maimon To: , , , , , , , , , , , CC: , , , , Tomer Maimon Subject: [PATCH v1 2/2] iio: adc: npcm: Add NPCM8XX support Date: Mon, 11 Jul 2022 16:43:11 +0300 Message-ID: <20220711134312.234268-3-tmaimon77@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220711134312.234268-1-tmaimon77@gmail.com> References: <20220711134312.234268-1-tmaimon77@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Adding ADC NPCM8XX support to NPCM ADC driver. ADC NPCM8XX uses a different resolution and voltage reference. As part of adding NPCM8XX support: - Add NPCM8XX specific compatible string. - Add data to handle architecture-specific ADC parameters. Signed-off-by: Tomer Maimon --- drivers/iio/adc/npcm_adc.c | 39 ++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/drivers/iio/adc/npcm_adc.c b/drivers/iio/adc/npcm_adc.c index f7bc0bb7f112..efacba256056 100644 --- a/drivers/iio/adc/npcm_adc.c +++ b/drivers/iio/adc/npcm_adc.c @@ -16,6 +16,12 @@ #include #include =20 +struct npcm_adc_info { + u32 data_mask; + u32 internal_vref; + u32 res_bits; +}; + struct npcm_adc { bool int_status; u32 adc_sample_hz; @@ -34,6 +40,7 @@ struct npcm_adc { * has finished. */ struct mutex lock; + struct npcm_adc_info *data; }; =20 /* ADC registers */ @@ -52,13 +59,21 @@ struct npcm_adc { #define NPCM_ADCCON_CH(x) ((x) << 24) #define NPCM_ADCCON_DIV_SHIFT 1 #define NPCM_ADCCON_DIV_MASK GENMASK(8, 1) -#define NPCM_ADC_DATA_MASK(x) ((x) & GENMASK(9, 0)) =20 #define NPCM_ADC_ENABLE (NPCM_ADCCON_ADC_EN | NPCM_ADCCON_ADC_INT_EN) =20 /* ADC General Definition */ -#define NPCM_RESOLUTION_BITS 10 -#define NPCM_INT_VREF_MV 2000 +static const struct npcm_adc_info npxm7xx_adc_info =3D { + .data_mask =3D GENMASK(9, 0), + .internal_vref =3D 2048, + .res_bits =3D 10, +}; + +static const struct npcm_adc_info npxm8xx_adc_info =3D { + .data_mask =3D GENMASK(11, 0), + .internal_vref =3D 1229, + .res_bits =3D 12, +}; =20 #define NPCM_ADC_CHAN(ch) { \ .type =3D IIO_VOLTAGE, \ @@ -129,7 +144,8 @@ static int npcm_adc_read(struct npcm_adc *info, int *va= l, u8 channel) if (ret < 0) return ret; =20 - *val =3D NPCM_ADC_DATA_MASK(ioread32(info->regs + NPCM_ADCDATA)); + *val =3D ioread32(info->regs + NPCM_ADCDATA); + *val &=3D info->data->data_mask; =20 return 0; } @@ -157,9 +173,9 @@ static int npcm_adc_read_raw(struct iio_dev *indio_dev, vref_uv =3D regulator_get_voltage(info->vref); *val =3D vref_uv / 1000; } else { - *val =3D NPCM_INT_VREF_MV; + *val =3D info->data->internal_vref; } - *val2 =3D NPCM_RESOLUTION_BITS; + *val2 =3D info->data->res_bits; return IIO_VAL_FRACTIONAL_LOG2; case IIO_CHAN_INFO_SAMP_FREQ: *val =3D info->adc_sample_hz; @@ -176,7 +192,8 @@ static const struct iio_info npcm_adc_iio_info =3D { }; =20 static const struct of_device_id npcm_adc_match[] =3D { - { .compatible =3D "nuvoton,npcm750-adc", }, + { .compatible =3D "nuvoton,npcm750-adc", .data =3D &npxm7xx_adc_info}, + { .compatible =3D "nuvoton,npcm845-adc", .data =3D &npxm8xx_adc_info}, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, npcm_adc_match); @@ -190,14 +207,20 @@ static int npcm_adc_probe(struct platform_device *pde= v) struct npcm_adc *info; struct iio_dev *indio_dev; struct device *dev =3D &pdev->dev; + const struct of_device_id *match; =20 indio_dev =3D devm_iio_device_alloc(&pdev->dev, sizeof(*info)); if (!indio_dev) return -ENOMEM; info =3D iio_priv(indio_dev); =20 - mutex_init(&info->lock); + match =3D of_match_node(npcm_adc_match, pdev->dev.of_node); + if (!match || !match->data) { + dev_err(dev, "Failed getting npcm_adc_data\n"); + return -ENODEV; + } =20 + info->data =3D (struct npcm_adc_info *)match->data; info->dev =3D &pdev->dev; =20 info->regs =3D devm_platform_ioremap_resource(pdev, 0); --=20 2.33.0