openbmc.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 0/2] iio: adc: npcm: add Arbel NPCM8XX support
@ 2022-07-11 13:43 Tomer Maimon
  2022-07-11 13:43 ` [PATCH v1 1/2] dt-bindings: iio: adc: npcm: Add npcm845 compatible string Tomer Maimon
  2022-07-11 13:43 ` [PATCH v1 2/2] iio: adc: npcm: Add NPCM8XX support Tomer Maimon
  0 siblings, 2 replies; 9+ messages in thread
From: Tomer Maimon @ 2022-07-11 13:43 UTC (permalink / raw)
  To: avifishman70, tali.perry1, joel, venture, yuenn, benjaminfair,
	jic23, lars, robh+dt, krzysztof.kozlowski+dt, j.neuschaefer,
	zhengbin13
  Cc: linux-iio, devicetree, openbmc, linux-kernel, Tomer Maimon

This patch set adds Arbel NPCM8XX Analog-to-Digital Converter (ADC) support 
to ADC NPCM driver.

The NPCM8XX ADC is a 12-bit converter for eight channel inputs.

The NPCM ADC driver tested on NPCM845 evaluation board.
Tomer Maimon (2):
  dt-bindings: iio: adc: npcm: Add npcm845 compatible string
  iio: adc: npcm: Add NPCM8XX support

 .../bindings/iio/adc/nuvoton,npcm750-adc.yaml |  5 ++-
 drivers/iio/adc/npcm_adc.c                    | 39 +++++++++++++++----
 2 files changed, 35 insertions(+), 9 deletions(-)

-- 
2.33.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v1 1/2] dt-bindings: iio: adc: npcm: Add npcm845 compatible string
  2022-07-11 13:43 [PATCH v1 0/2] iio: adc: npcm: add Arbel NPCM8XX support Tomer Maimon
@ 2022-07-11 13:43 ` Tomer Maimon
  2022-07-11 17:55   ` Rob Herring
       [not found]   ` <154dd9ef-cb8c-d8d7-ae62-a73bac160089@linaro.org>
  2022-07-11 13:43 ` [PATCH v1 2/2] iio: adc: npcm: Add NPCM8XX support Tomer Maimon
  1 sibling, 2 replies; 9+ messages in thread
From: Tomer Maimon @ 2022-07-11 13:43 UTC (permalink / raw)
  To: avifishman70, tali.perry1, joel, venture, yuenn, benjaminfair,
	jic23, lars, robh+dt, krzysztof.kozlowski+dt, j.neuschaefer,
	zhengbin13
  Cc: linux-iio, devicetree, openbmc, linux-kernel, Tomer Maimon

Add a compatible string for Nuvoton BMC NPCM845 ADC.

Signed-off-by: Tomer Maimon <tmaimon77@gmail.com>
---
 .../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:
 
 properties:
   compatible:
-    const: nuvoton,npcm750-adc
+    oneOf:
+      - items:
+          - const: nuvoton,npcm750-adc
+          - const: nuvoton,npcm845-adc
 
   reg:
     maxItems: 1
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v1 2/2] iio: adc: npcm: Add NPCM8XX support
  2022-07-11 13:43 [PATCH v1 0/2] iio: adc: npcm: add Arbel NPCM8XX support Tomer Maimon
  2022-07-11 13:43 ` [PATCH v1 1/2] dt-bindings: iio: adc: npcm: Add npcm845 compatible string Tomer Maimon
@ 2022-07-11 13:43 ` Tomer Maimon
  2022-07-11 14:14   ` Andy Shevchenko
  1 sibling, 1 reply; 9+ messages in thread
From: Tomer Maimon @ 2022-07-11 13:43 UTC (permalink / raw)
  To: avifishman70, tali.perry1, joel, venture, yuenn, benjaminfair,
	jic23, lars, robh+dt, krzysztof.kozlowski+dt, j.neuschaefer,
	zhengbin13
  Cc: linux-iio, devicetree, openbmc, linux-kernel, Tomer Maimon

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 <tmaimon77@gmail.com>
---
 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 <linux/uaccess.h>
 #include <linux/reset.h>
 
+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;
 };
 
 /* 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))
 
 #define NPCM_ADC_ENABLE		(NPCM_ADCCON_ADC_EN | NPCM_ADCCON_ADC_INT_EN)
 
 /* ADC General Definition */
-#define NPCM_RESOLUTION_BITS		10
-#define NPCM_INT_VREF_MV		2000
+static const struct npcm_adc_info npxm7xx_adc_info = {
+	.data_mask = GENMASK(9, 0),
+	.internal_vref = 2048,
+	.res_bits = 10,
+};
+
+static const struct npcm_adc_info npxm8xx_adc_info = {
+	.data_mask = GENMASK(11, 0),
+	.internal_vref = 1229,
+	.res_bits = 12,
+};
 
 #define NPCM_ADC_CHAN(ch) {					\
 	.type = IIO_VOLTAGE,					\
@@ -129,7 +144,8 @@ static int npcm_adc_read(struct npcm_adc *info, int *val, u8 channel)
 	if (ret < 0)
 		return ret;
 
-	*val = NPCM_ADC_DATA_MASK(ioread32(info->regs + NPCM_ADCDATA));
+	*val = ioread32(info->regs + NPCM_ADCDATA);
+	*val &= info->data->data_mask;
 
 	return 0;
 }
@@ -157,9 +173,9 @@ static int npcm_adc_read_raw(struct iio_dev *indio_dev,
 			vref_uv = regulator_get_voltage(info->vref);
 			*val = vref_uv / 1000;
 		} else {
-			*val = NPCM_INT_VREF_MV;
+			*val = info->data->internal_vref;
 		}
-		*val2 = NPCM_RESOLUTION_BITS;
+		*val2 = info->data->res_bits;
 		return IIO_VAL_FRACTIONAL_LOG2;
 	case IIO_CHAN_INFO_SAMP_FREQ:
 		*val = info->adc_sample_hz;
@@ -176,7 +192,8 @@ static const struct iio_info npcm_adc_iio_info = {
 };
 
 static const struct of_device_id npcm_adc_match[] = {
-	{ .compatible = "nuvoton,npcm750-adc", },
+	{ .compatible = "nuvoton,npcm750-adc", .data = &npxm7xx_adc_info},
+	{ .compatible = "nuvoton,npcm845-adc", .data = &npxm8xx_adc_info},
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, npcm_adc_match);
@@ -190,14 +207,20 @@ static int npcm_adc_probe(struct platform_device *pdev)
 	struct npcm_adc *info;
 	struct iio_dev *indio_dev;
 	struct device *dev = &pdev->dev;
+	const struct of_device_id *match;
 
 	indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*info));
 	if (!indio_dev)
 		return -ENOMEM;
 	info = iio_priv(indio_dev);
 
-	mutex_init(&info->lock);
+	match = 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;
+	}
 
+	info->data = (struct npcm_adc_info *)match->data;
 	info->dev = &pdev->dev;
 
 	info->regs = devm_platform_ioremap_resource(pdev, 0);
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 2/2] iio: adc: npcm: Add NPCM8XX support
  2022-07-11 13:43 ` [PATCH v1 2/2] iio: adc: npcm: Add NPCM8XX support Tomer Maimon
@ 2022-07-11 14:14   ` Andy Shevchenko
  2022-07-11 14:16     ` Andy Shevchenko
  0 siblings, 1 reply; 9+ messages in thread
From: Andy Shevchenko @ 2022-07-11 14:14 UTC (permalink / raw)
  To: Tomer Maimon
  Cc: devicetree, Lars-Peter Clausen, Linux Kernel Mailing List,
	Benjamin Fair, Avi Fishman, Patrick Venture, OpenBMC Maillist,
	Jonathan Neuschäfer, linux-iio, Tali Perry, zhengbin13,
	Rob Herring, Joel Stanley, Krzysztof Kozlowski, Jonathan Cameron

On Mon, Jul 11, 2022 at 3:59 PM Tomer Maimon <tmaimon77@gmail.com> wrote:
>
> 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.

Good patch, but one change can make it even better!

...

>         struct device *dev = &pdev->dev;
> +       const struct of_device_id *match;
>
>         indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*info));
>         if (!indio_dev)
>                 return -ENOMEM;
>         info = iio_priv(indio_dev);
>
> -       mutex_init(&info->lock);
> +       match = 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;
> +       }
>
> +       info->data = (struct npcm_adc_info *)match->data;

Instead of above

  info->data = device_get_match_data(dev);
  if (!info->data)
    return -ENODEV;

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 2/2] iio: adc: npcm: Add NPCM8XX support
  2022-07-11 14:14   ` Andy Shevchenko
@ 2022-07-11 14:16     ` Andy Shevchenko
  2022-07-12  7:59       ` Tomer Maimon
  0 siblings, 1 reply; 9+ messages in thread
From: Andy Shevchenko @ 2022-07-11 14:16 UTC (permalink / raw)
  To: Tomer Maimon
  Cc: devicetree, Lars-Peter Clausen, Linux Kernel Mailing List,
	Benjamin Fair, Avi Fishman, Patrick Venture, OpenBMC Maillist,
	Jonathan Neuschäfer, linux-iio, Tali Perry, zhengbin13,
	Rob Herring, Joel Stanley, Krzysztof Kozlowski, Jonathan Cameron

On Mon, Jul 11, 2022 at 4:14 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
> On Mon, Jul 11, 2022 at 3:59 PM Tomer Maimon <tmaimon77@gmail.com> wrote:

...

> >         struct device *dev = &pdev->dev;
> > +       const struct of_device_id *match;

> > +       match = 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;
> > +       }
> >
> > +       info->data = (struct npcm_adc_info *)match->data;
>
> Instead of above
>
>   info->data = device_get_match_data(dev);
>   if (!info->data)


>     return -ENODEV;

Or

  return dev_err_probe(dev, -EINVAL, "...\n");

if you want that message to be issued.


-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 1/2] dt-bindings: iio: adc: npcm: Add npcm845 compatible string
  2022-07-11 13:43 ` [PATCH v1 1/2] dt-bindings: iio: adc: npcm: Add npcm845 compatible string Tomer Maimon
@ 2022-07-11 17:55   ` Rob Herring
  2022-07-12  8:03     ` Tomer Maimon
       [not found]   ` <154dd9ef-cb8c-d8d7-ae62-a73bac160089@linaro.org>
  1 sibling, 1 reply; 9+ messages in thread
From: Rob Herring @ 2022-07-11 17:55 UTC (permalink / raw)
  To: Tomer Maimon
  Cc: devicetree, lars, linux-kernel, benjaminfair, avifishman70,
	venture, openbmc, j.neuschaefer, linux-iio, tali.perry1,
	zhengbin13, robh+dt, joel, krzysztof.kozlowski+dt, jic23

On Mon, 11 Jul 2022 16:43:10 +0300, Tomer Maimon wrote:
> Add a compatible string for Nuvoton BMC NPCM845 ADC.
> 
> Signed-off-by: Tomer Maimon <tmaimon77@gmail.com>
> ---
>  .../devicetree/bindings/iio/adc/nuvoton,npcm750-adc.yaml     | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check'
on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/iio/adc/nuvoton,npcm750-adc.example.dtb: adc@f000c000: compatible: 'oneOf' conditional failed, one must be fixed:
	['nuvoton,npcm750-adc'] is too short
	From schema: /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/iio/adc/nuvoton,npcm750-adc.yaml

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/patch/

This check can fail if there are any dependencies. The base for a patch
series is generally the most recent rc1.

If you already ran 'make dt_binding_check' and didn't see the above
error(s), then make sure 'yamllint' is installed and dt-schema is up to
date:

pip3 install dtschema --upgrade

Please check and re-submit.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 2/2] iio: adc: npcm: Add NPCM8XX support
  2022-07-11 14:16     ` Andy Shevchenko
@ 2022-07-12  7:59       ` Tomer Maimon
  0 siblings, 0 replies; 9+ messages in thread
From: Tomer Maimon @ 2022-07-12  7:59 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: devicetree, Lars-Peter Clausen, Linux Kernel Mailing List,
	Benjamin Fair, Avi Fishman, Patrick Venture, OpenBMC Maillist,
	Jonathan Neuschäfer, linux-iio, Tali Perry, zhengbin13,
	Rob Herring, Joel Stanley, Krzysztof Kozlowski, Jonathan Cameron

Hi Andy,

Thanks for your comments, they will be addressed next version.

On Mon, 11 Jul 2022 at 17:16, Andy Shevchenko <andy.shevchenko@gmail.com> wrote:
>
> On Mon, Jul 11, 2022 at 4:14 PM Andy Shevchenko
> <andy.shevchenko@gmail.com> wrote:
> > On Mon, Jul 11, 2022 at 3:59 PM Tomer Maimon <tmaimon77@gmail.com> wrote:
>
> ...
>
> > >         struct device *dev = &pdev->dev;
> > > +       const struct of_device_id *match;
>
> > > +       match = 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;
> > > +       }
> > >
> > > +       info->data = (struct npcm_adc_info *)match->data;
> >
> > Instead of above
> >
> >   info->data = device_get_match_data(dev);
> >   if (!info->data)
>
>
> >     return -ENODEV;
>
> Or
>
>   return dev_err_probe(dev, -EINVAL, "...\n");
>
> if you want that message to be issued.
>
>
> --
> With Best Regards,
> Andy Shevchenko

Best regards,

Tomer

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 1/2] dt-bindings: iio: adc: npcm: Add npcm845 compatible string
  2022-07-11 17:55   ` Rob Herring
@ 2022-07-12  8:03     ` Tomer Maimon
  0 siblings, 0 replies; 9+ messages in thread
From: Tomer Maimon @ 2022-07-12  8:03 UTC (permalink / raw)
  To: Rob Herring
  Cc: devicetree, Lars-Peter Clausen, Linux Kernel Mailing List,
	Benjamin Fair, Avi Fishman, Patrick Venture, OpenBMC Maillist,
	Jonathan Neuschäfer, open list:IIO SUBSYSTEM AND DRIVERS,
	Tali Perry, zhengbin13, Rob Herring, Joel Stanley,
	Krzysztof Kozlowski, Jonathan Cameron

Hi Rob,

Thanks for your comment, it will be addressed next version.

On Mon, 11 Jul 2022 at 20:55, Rob Herring <robh@kernel.org> wrote:
>
> On Mon, 11 Jul 2022 16:43:10 +0300, Tomer Maimon wrote:
> > Add a compatible string for Nuvoton BMC NPCM845 ADC.
> >
> > Signed-off-by: Tomer Maimon <tmaimon77@gmail.com>
> > ---
> >  .../devicetree/bindings/iio/adc/nuvoton,npcm750-adc.yaml     | 5 ++++-
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> >
>
> My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check'
> on your patch (DT_CHECKER_FLAGS is new in v5.13):
>
> yamllint warnings/errors:
>
> dtschema/dtc warnings/errors:
> /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/iio/adc/nuvoton,npcm750-adc.example.dtb: adc@f000c000: compatible: 'oneOf' conditional failed, one must be fixed:
>         ['nuvoton,npcm750-adc'] is too short
>         From schema: /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/iio/adc/nuvoton,npcm750-adc.yaml
>
> doc reference errors (make refcheckdocs):
>
> See https://patchwork.ozlabs.org/patch/
>
> This check can fail if there are any dependencies. The base for a patch
> series is generally the most recent rc1.
>
> If you already ran 'make dt_binding_check' and didn't see the above
> error(s), then make sure 'yamllint' is installed and dt-schema is up to
> date:
>
> pip3 install dtschema --upgrade
>
> Please check and re-submit.
>

Best regards,

Tomer

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 1/2] dt-bindings: iio: adc: npcm: Add npcm845 compatible string
       [not found]   ` <154dd9ef-cb8c-d8d7-ae62-a73bac160089@linaro.org>
@ 2022-07-12  8:19     ` Tomer Maimon
  0 siblings, 0 replies; 9+ messages in thread
From: Tomer Maimon @ 2022-07-12  8:19 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: devicetree, Lars-Peter Clausen, Linux Kernel Mailing List,
	Benjamin Fair, Avi Fishman, Patrick Venture, OpenBMC Maillist,
	Jonathan Neuschäfer, open list:IIO SUBSYSTEM AND DRIVERS,
	Tali Perry, zhengbin13, Rob Herring, Joel Stanley,
	Krzysztof Kozlowski, Jonathan Cameron

Hi Krzysztof,

On Tue, 12 Jul 2022 at 11:15, Krzysztof Kozlowski
<krzysztof.kozlowski@linaro.org> wrote:
>
> On 11/07/2022 15:43, Tomer Maimon wrote:
> > Add a compatible string for Nuvoton BMC NPCM845 ADC.
> >
> > Signed-off-by: Tomer Maimon <tmaimon77@gmail.com>
> > ---
> >  .../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:
> >
> >  properties:
> >    compatible:
> > -    const: nuvoton,npcm750-adc
> > +    oneOf:
> > +      - items:
>
> This does not make sense. oneOf with one item. You also create now list
> breaking all existing users/ABI.
>
> You probably wanted an enum here.
indeed, thanks for your comment.
>
> > +          - const: nuvoton,npcm750-adc
> > +          - const: nuvoton,npcm845-adc
> >
> >    reg:
> >      maxItems: 1
>
>
> Best regards,
> Krzysztof

Best regards,

Tomer

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-07-12  8:20 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-11 13:43 [PATCH v1 0/2] iio: adc: npcm: add Arbel NPCM8XX support Tomer Maimon
2022-07-11 13:43 ` [PATCH v1 1/2] dt-bindings: iio: adc: npcm: Add npcm845 compatible string Tomer Maimon
2022-07-11 17:55   ` Rob Herring
2022-07-12  8:03     ` Tomer Maimon
     [not found]   ` <154dd9ef-cb8c-d8d7-ae62-a73bac160089@linaro.org>
2022-07-12  8:19     ` Tomer Maimon
2022-07-11 13:43 ` [PATCH v1 2/2] iio: adc: npcm: Add NPCM8XX support Tomer Maimon
2022-07-11 14:14   ` Andy Shevchenko
2022-07-11 14:16     ` Andy Shevchenko
2022-07-12  7:59       ` Tomer Maimon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).