* [PATCH v3 0/2] iio: adc: npcm: add Arbel NPCM8XX support @ 2022-07-13 13:26 Tomer Maimon 2022-07-13 13:26 ` [PATCH v3 1/2] dt-bindings: iio: adc: npcm: Add npcm845 compatible string Tomer Maimon 2022-07-13 13:26 ` [PATCH v3 2/2] iio: adc: npcm: Add NPCM8XX support Tomer Maimon 0 siblings, 2 replies; 5+ messages in thread From: Tomer Maimon @ 2022-07-13 13:26 UTC (permalink / raw) To: avifishman70, tali.perry1, joel, venture, yuenn, benjaminfair, jic23, lars, robh+dt, krzysztof.kozlowski+dt, j.neuschaefer, zhengbin13 Cc: openbmc, linux-iio, linux-kernel, devicetree, 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. Addressed comments from: - Andy Shevchenko : https://www.spinics.net/lists/kernel/msg4436806.html Changes since version 2: - Drop npcm_adc_info casting. Changes since version 1: - Modify dt-binding compatible property. - Use device_get_match_data function instead of_match_node function. 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 | 7 ++-- drivers/iio/adc/npcm_adc.c | 35 +++++++++++++++---- 2 files changed, 33 insertions(+), 9 deletions(-) -- 2.33.0 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v3 1/2] dt-bindings: iio: adc: npcm: Add npcm845 compatible string 2022-07-13 13:26 [PATCH v3 0/2] iio: adc: npcm: add Arbel NPCM8XX support Tomer Maimon @ 2022-07-13 13:26 ` Tomer Maimon 2022-07-13 13:26 ` [PATCH v3 2/2] iio: adc: npcm: Add NPCM8XX support Tomer Maimon 1 sibling, 0 replies; 5+ messages in thread From: Tomer Maimon @ 2022-07-13 13:26 UTC (permalink / raw) To: avifishman70, tali.perry1, joel, venture, yuenn, benjaminfair, jic23, lars, robh+dt, krzysztof.kozlowski+dt, j.neuschaefer, zhengbin13 Cc: openbmc, linux-iio, linux-kernel, devicetree, Tomer Maimon, Krzysztof Kozlowski Add a compatible string for Nuvoton BMC NPCM845 ADC. Signed-off-by: Tomer Maimon <tmaimon77@gmail.com> Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> --- .../devicetree/bindings/iio/adc/nuvoton,npcm750-adc.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/iio/adc/nuvoton,npcm750-adc.yaml b/Documentation/devicetree/bindings/iio/adc/nuvoton,npcm750-adc.yaml index 001cf263b7d5..fede2aa64092 100644 --- a/Documentation/devicetree/bindings/iio/adc/nuvoton,npcm750-adc.yaml +++ b/Documentation/devicetree/bindings/iio/adc/nuvoton,npcm750-adc.yaml @@ -10,11 +10,14 @@ maintainers: - Tomer Maimon <tmaimon77@gmail.com> description: - The NPCM ADC is a 10-bit converter for eight channel inputs. + The NPCM7XX ADC is a 10-bit converter and NPCM8XX ADC is a 12-bit converter, + both have eight channel inputs. properties: compatible: - const: nuvoton,npcm750-adc + enum: + - nuvoton,npcm750-adc + - nuvoton,npcm845-adc reg: maxItems: 1 -- 2.33.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v3 2/2] iio: adc: npcm: Add NPCM8XX support 2022-07-13 13:26 [PATCH v3 0/2] iio: adc: npcm: add Arbel NPCM8XX support Tomer Maimon 2022-07-13 13:26 ` [PATCH v3 1/2] dt-bindings: iio: adc: npcm: Add npcm845 compatible string Tomer Maimon @ 2022-07-13 13:26 ` Tomer Maimon 2022-07-13 16:21 ` Jonathan Cameron 1 sibling, 1 reply; 5+ messages in thread From: Tomer Maimon @ 2022-07-13 13:26 UTC (permalink / raw) To: avifishman70, tali.perry1, joel, venture, yuenn, benjaminfair, jic23, lars, robh+dt, krzysztof.kozlowski+dt, j.neuschaefer, zhengbin13 Cc: openbmc, linux-iio, linux-kernel, devicetree, 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 | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/drivers/iio/adc/npcm_adc.c b/drivers/iio/adc/npcm_adc.c index f7bc0bb7f112..4c7ebcd57b88 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; + const 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); @@ -196,6 +213,10 @@ static int npcm_adc_probe(struct platform_device *pdev) return -ENOMEM; info = iio_priv(indio_dev); + info->data = device_get_match_data(dev); + if (!info->data) + return -EINVAL; + mutex_init(&info->lock); info->dev = &pdev->dev; -- 2.33.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3 2/2] iio: adc: npcm: Add NPCM8XX support 2022-07-13 13:26 ` [PATCH v3 2/2] iio: adc: npcm: Add NPCM8XX support Tomer Maimon @ 2022-07-13 16:21 ` Jonathan Cameron 2022-07-17 15:14 ` Jonathan Cameron 0 siblings, 1 reply; 5+ messages in thread From: Jonathan Cameron @ 2022-07-13 16:21 UTC (permalink / raw) To: Tomer Maimon Cc: avifishman70, tali.perry1, joel, venture, yuenn, benjaminfair, lars, robh+dt, krzysztof.kozlowski+dt, j.neuschaefer, zhengbin13, openbmc, linux-iio, linux-kernel, devicetree On Wed, 13 Jul 2022 16:26:40 +0300 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. > > Signed-off-by: Tomer Maimon <tmaimon77@gmail.com> missing #include <linux/property.h> So in current IIO togreg tree this doesn't build. I could fix it up but given we are very late in cycle and I'd like to give this a little more time on list for Andy to take another look if he wishes, chances are this won't make it in until early next cycle. Thanks, Jonathan > --- > drivers/iio/adc/npcm_adc.c | 35 ++++++++++++++++++++++++++++------- > 1 file changed, 28 insertions(+), 7 deletions(-) > > diff --git a/drivers/iio/adc/npcm_adc.c b/drivers/iio/adc/npcm_adc.c > index f7bc0bb7f112..4c7ebcd57b88 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; > + const 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); > @@ -196,6 +213,10 @@ static int npcm_adc_probe(struct platform_device *pdev) > return -ENOMEM; > info = iio_priv(indio_dev); > > + info->data = device_get_match_data(dev); > + if (!info->data) > + return -EINVAL; > + > mutex_init(&info->lock); > > info->dev = &pdev->dev; ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3 2/2] iio: adc: npcm: Add NPCM8XX support 2022-07-13 16:21 ` Jonathan Cameron @ 2022-07-17 15:14 ` Jonathan Cameron 0 siblings, 0 replies; 5+ messages in thread From: Jonathan Cameron @ 2022-07-17 15:14 UTC (permalink / raw) To: Tomer Maimon Cc: avifishman70, tali.perry1, joel, venture, yuenn, benjaminfair, lars, robh+dt, krzysztof.kozlowski+dt, j.neuschaefer, zhengbin13, openbmc, linux-iio, linux-kernel, devicetree On Wed, 13 Jul 2022 17:21:32 +0100 Jonathan Cameron <jic23@kernel.org> wrote: > On Wed, 13 Jul 2022 16:26:40 +0300 > 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. > > > > Signed-off-by: Tomer Maimon <tmaimon77@gmail.com> > missing > > #include <linux/property.h> > > So in current IIO togreg tree this doesn't build. I could fix it up > but given we are very late in cycle and I'd like to give this a little > more time on list for Andy to take another look if he wishes, chances > are this won't make it in until early next cycle. > Applied to the togreg branch of iio.git and pushed out as testing for now only as I'll be rebaseing on rc1 once available. Thanks, Jonathan > Thanks, > > Jonathan > > > --- > > drivers/iio/adc/npcm_adc.c | 35 ++++++++++++++++++++++++++++------- > > 1 file changed, 28 insertions(+), 7 deletions(-) > > > > diff --git a/drivers/iio/adc/npcm_adc.c b/drivers/iio/adc/npcm_adc.c > > index f7bc0bb7f112..4c7ebcd57b88 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; > > + const 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); > > @@ -196,6 +213,10 @@ static int npcm_adc_probe(struct platform_device *pdev) > > return -ENOMEM; > > info = iio_priv(indio_dev); > > > > + info->data = device_get_match_data(dev); > > + if (!info->data) > > + return -EINVAL; > > + > > mutex_init(&info->lock); > > > > info->dev = &pdev->dev; > ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-07-17 15:04 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-07-13 13:26 [PATCH v3 0/2] iio: adc: npcm: add Arbel NPCM8XX support Tomer Maimon 2022-07-13 13:26 ` [PATCH v3 1/2] dt-bindings: iio: adc: npcm: Add npcm845 compatible string Tomer Maimon 2022-07-13 13:26 ` [PATCH v3 2/2] iio: adc: npcm: Add NPCM8XX support Tomer Maimon 2022-07-13 16:21 ` Jonathan Cameron 2022-07-17 15:14 ` Jonathan Cameron
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).