2021-07-21 11:08:38

by Christophe Branchereau

[permalink] [raw]
Subject: [PATCH] Ingenic: iio/adc: add JZ4760(B) support to the

This is a set of patches to add support for the JZ4760(B) socs
to ingenic-sadc, those socs have 3 aux channels, and the JZ4760B
has an extra register to set the battery divider as internal or
external.



2021-07-21 11:09:01

by Christophe Branchereau

[permalink] [raw]
Subject: [PATCH 6/6] dt-bindings: iio/adc: ingenic: add the JZ4760(B) socs to the sadc Documentation

Signed-off-by: citral23 <[email protected]>
---
.../devicetree/bindings/iio/adc/ingenic,adc.yaml | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/Documentation/devicetree/bindings/iio/adc/ingenic,adc.yaml b/Documentation/devicetree/bindings/iio/adc/ingenic,adc.yaml
index 433a3fb55a2e..1b423adba61d 100644
--- a/Documentation/devicetree/bindings/iio/adc/ingenic,adc.yaml
+++ b/Documentation/devicetree/bindings/iio/adc/ingenic,adc.yaml
@@ -23,6 +23,8 @@ properties:
enum:
- ingenic,jz4725b-adc
- ingenic,jz4740-adc
+ - ingenic,jz4760-adc
+ - ingenic,jz4760b-adc
- ingenic,jz4770-adc

'#io-channel-cells':
@@ -43,6 +45,12 @@ properties:
interrupts:
maxItems: 1

+ ingenic,use-internal-divider:
+ description:
+ This property can be used to set VBAT_SEL in the JZ4760B CFG register
+ to sample the battery voltage from the internal divider. If absent, it
+ will sample the external divider.
+
required:
- compatible
- '#io-channel-cells'
@@ -53,6 +61,7 @@ required:

additionalProperties: false

+
examples:
- |
#include <dt-bindings/clock/jz4740-cgu.h>
--
2.30.2

2021-07-21 11:09:24

by Christophe Branchereau

[permalink] [raw]
Subject: [PATCH 5/6] iio/adc: ingenic: modify

The current code does not allow to set MD to 0 to sample AUX0, fix it for the JZ4760(B).

Signed-off-by: citral23 <[email protected]>
---
drivers/iio/adc/ingenic-adc.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/adc/ingenic-adc.c b/drivers/iio/adc/ingenic-adc.c
index 618150475421..1edaae439a32 100644
--- a/drivers/iio/adc/ingenic-adc.c
+++ b/drivers/iio/adc/ingenic-adc.c
@@ -632,7 +632,7 @@ static int ingenic_adc_read_chan_info_raw(struct iio_dev *iio_dev,
struct iio_chan_spec const *chan,
int *val)
{
- int bit, ret, engine = (chan->channel == INGENIC_ADC_BATTERY);
+ int cmd, ret, engine = (chan->channel == INGENIC_ADC_BATTERY);
struct ingenic_adc *adc = iio_priv(iio_dev);

ret = clk_enable(adc->clk);
@@ -642,11 +642,22 @@ static int ingenic_adc_read_chan_info_raw(struct iio_dev *iio_dev,
return ret;
}

- /* We cannot sample AUX/AUX2 in parallel. */
+ /* We cannot sample the aux channels in parallel. */
mutex_lock(&adc->aux_lock);
if (adc->soc_data->has_aux_md && engine == 0) {
- bit = BIT(chan->channel == INGENIC_ADC_AUX2);
- ingenic_adc_set_config(adc, JZ_ADC_REG_CFG_AUX_MD, bit);
+ switch (chan->channel) {
+ case INGENIC_ADC_AUX0:
+ cmd = 0;
+ break;
+ case INGENIC_ADC_AUX:
+ cmd = 1;
+ break;
+ case INGENIC_ADC_AUX2:
+ cmd = 2;
+ break;
+ }
+
+ ingenic_adc_set_config(adc, JZ_ADC_REG_CFG_AUX_MD, cmd);
}

ret = ingenic_adc_capture(adc, engine);
@@ -654,6 +665,7 @@ static int ingenic_adc_read_chan_info_raw(struct iio_dev *iio_dev,
goto out;

switch (chan->channel) {
+ case INGENIC_ADC_AUX0:
case INGENIC_ADC_AUX:
case INGENIC_ADC_AUX2:
*val = readw(adc->base + JZ_ADC_REG_ADSDAT);
--
2.30.2

2021-07-21 11:10:01

by Christophe Branchereau

[permalink] [raw]
Subject: [PATCH 4/6] iio/adc: ingenic: add JZ4760B support to the sadc driver

The JZ4760B variant differs slightly from the JZ4760, in that it has a bit called VBAT_SEL
in the CFG register. In order to correctly sample the battery voltage on existing handhelds
using this SOC, the bit must be cleared.

We leave the possibility to set the bit, by using the "ingenic,use-internal-divider" in the devicetree.

Signed-off-by: citral23 <[email protected]>
---
drivers/iio/adc/ingenic-adc.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/drivers/iio/adc/ingenic-adc.c b/drivers/iio/adc/ingenic-adc.c
index 285e7aa8e37a..618150475421 100644
--- a/drivers/iio/adc/ingenic-adc.c
+++ b/drivers/iio/adc/ingenic-adc.c
@@ -37,6 +37,7 @@
#define JZ_ADC_REG_CFG_SAMPLE_NUM(n) ((n) << 10)
#define JZ_ADC_REG_CFG_PULL_UP(n) ((n) << 16)
#define JZ_ADC_REG_CFG_CMD_SEL BIT(22)
+#define JZ_ADC_REG_CFG_VBAT_SEL BIT(30)
#define JZ_ADC_REG_CFG_TOUCH_OPS_MASK (BIT(31) | GENMASK(23, 10))
#define JZ_ADC_REG_ADCLK_CLKDIV_LSB 0
#define JZ4725B_ADC_REG_ADCLK_CLKDIV10US_LSB 16
@@ -869,6 +870,10 @@ static int ingenic_adc_probe(struct platform_device *pdev)
/* Put hardware in a known passive state. */
writeb(0x00, adc->base + JZ_ADC_REG_ENABLE);
writeb(0xff, adc->base + JZ_ADC_REG_CTRL);
+
+ if (!device_property_present(dev, "ingenic,use-internal-divider")) /* JZ4760B specific */
+ ingenic_adc_set_config(adc, JZ_ADC_REG_CFG_VBAT_SEL, 0);
+
usleep_range(2000, 3000); /* Must wait at least 2ms. */
clk_disable(adc->clk);

@@ -896,6 +901,7 @@ static const struct of_device_id ingenic_adc_of_match[] = {
{ .compatible = "ingenic,jz4725b-adc", .data = &jz4725b_adc_soc_data, },
{ .compatible = "ingenic,jz4740-adc", .data = &jz4740_adc_soc_data, },
{ .compatible = "ingenic,jz4760-adc", .data = &jz4760_adc_soc_data, },
+ { .compatible = "ingenic,jz4760b-adc", .data = &jz4760_adc_soc_data, },
{ .compatible = "ingenic,jz4770-adc", .data = &jz4770_adc_soc_data, },
{ },
};
--
2.30.2

2021-07-21 11:11:25

by Christophe Branchereau

[permalink] [raw]
Subject: [PATCH 2/6] dt-bindings: iio/adc: add an INGENIC_ADC_AUX0 entry

The JZ4760(B) socs have 3 AUX inputs, add an entry to prepare including the one named AUX in the sadc driver.
Leaving the rest untouched as it's ABI.

Signed-off-by: citral23 <[email protected]>
---
include/dt-bindings/iio/adc/ingenic,adc.h | 1 +
1 file changed, 1 insertion(+)

diff --git a/include/dt-bindings/iio/adc/ingenic,adc.h b/include/dt-bindings/iio/adc/ingenic,adc.h
index 4627a00e369e..a6ccc031635b 100644
--- a/include/dt-bindings/iio/adc/ingenic,adc.h
+++ b/include/dt-bindings/iio/adc/ingenic,adc.h
@@ -13,5 +13,6 @@
#define INGENIC_ADC_TOUCH_YN 6
#define INGENIC_ADC_TOUCH_XD 7
#define INGENIC_ADC_TOUCH_YD 8
+#define INGENIC_ADC_AUX0 9

#endif
--
2.30.2

2021-07-21 21:06:03

by Paul Cercueil

[permalink] [raw]
Subject: Re: [PATCH 2/6] dt-bindings: iio/adc: add an INGENIC_ADC_AUX0 entry

Hi Christophe,

Le mer., juil. 21 2021 at 12:53:13 +0200, citral23
<[email protected]> a ?crit :
> The JZ4760(B) socs have 3 AUX inputs, add an entry to prepare
> including the one named AUX in the sadc driver.
> Leaving the rest untouched as it's ABI.
>
> Signed-off-by: citral23 <[email protected]>

Please use your real name when you sign a commit.

Reviewed-by: Paul Cercueil <[email protected]>

Cheers,
-Paul

> ---
> include/dt-bindings/iio/adc/ingenic,adc.h | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/include/dt-bindings/iio/adc/ingenic,adc.h
> b/include/dt-bindings/iio/adc/ingenic,adc.h
> index 4627a00e369e..a6ccc031635b 100644
> --- a/include/dt-bindings/iio/adc/ingenic,adc.h
> +++ b/include/dt-bindings/iio/adc/ingenic,adc.h
> @@ -13,5 +13,6 @@
> #define INGENIC_ADC_TOUCH_YN 6
> #define INGENIC_ADC_TOUCH_XD 7
> #define INGENIC_ADC_TOUCH_YD 8
> +#define INGENIC_ADC_AUX0 9
>
> #endif
> --
> 2.30.2
>


2021-07-21 21:06:15

by Paul Cercueil

[permalink] [raw]
Subject: Re: [PATCH 6/6] dt-bindings: iio/adc: ingenic: add the JZ4760(B) socs to the sadc Documentation

Hi Christophe,

Please always add a short description in your patches, even if all you
do is repeat the patch title.


Le mer., juil. 21 2021 at 12:53:17 +0200, citral23
<[email protected]> a ?crit :
> Signed-off-by: citral23 <[email protected]>
> ---
> .../devicetree/bindings/iio/adc/ingenic,adc.yaml | 9
> +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git
> a/Documentation/devicetree/bindings/iio/adc/ingenic,adc.yaml
> b/Documentation/devicetree/bindings/iio/adc/ingenic,adc.yaml
> index 433a3fb55a2e..1b423adba61d 100644
> --- a/Documentation/devicetree/bindings/iio/adc/ingenic,adc.yaml
> +++ b/Documentation/devicetree/bindings/iio/adc/ingenic,adc.yaml
> @@ -23,6 +23,8 @@ properties:
> enum:
> - ingenic,jz4725b-adc
> - ingenic,jz4740-adc
> + - ingenic,jz4760-adc
> + - ingenic,jz4760b-adc
> - ingenic,jz4770-adc
>
> '#io-channel-cells':
> @@ -43,6 +45,12 @@ properties:
> interrupts:
> maxItems: 1
>
> + ingenic,use-internal-divider:
> + description:
> + This property can be used to set VBAT_SEL in the JZ4760B CFG
> register
> + to sample the battery voltage from the internal divider. If
> absent, it
> + will sample the external divider.

Please remove trailing spaces. And you don't need to describe internal
behaviour; you only need to explain the functionality in a user-facing
perspective. Something like:

"If present, battery voltage is read from the VBAT_IR pin, which has an
internal /4 divider. If absent, it is read through the VBAT_ER pin,
which does not have such divider."

You also don't specify the type of the property, please add "type:
boolean" before the description.

There should also be a way to make sure that this property can only be
used with the JZ4760B SoC. So a dependency for this vendor property on
the "ingenic,jz4760b-adc" compatible string. But I'm honestly not sure
how to express that... Maybe Rob can help.

> +
> required:
> - compatible
> - '#io-channel-cells'
> @@ -53,6 +61,7 @@ required:
>
> additionalProperties: false
>
> +

Remove the extra newline.

Cheers,
-Paul

> examples:
> - |
> #include <dt-bindings/clock/jz4740-cgu.h>
> --
> 2.30.2
>


2021-07-21 21:06:29

by Paul Cercueil

[permalink] [raw]
Subject: Re: [PATCH 5/6] iio/adc: ingenic: modify

Hi Christophe,

Le mer., juil. 21 2021 at 12:53:16 +0200, citral23
<[email protected]> a ?crit :
> The current code does not allow to set MD to 0 to sample AUX0, fix it
> for the JZ4760(B).

Well, then this should be merged with patch 3, because that means
JZ4760 support does not work without it.

Also, concise commit messages are good, but "modify" is a bit too
concise ;)

Cheers,
-Paul

> Signed-off-by: citral23 <[email protected]>
> ---
> drivers/iio/adc/ingenic-adc.c | 20 ++++++++++++++++----
> 1 file changed, 16 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/iio/adc/ingenic-adc.c
> b/drivers/iio/adc/ingenic-adc.c
> index 618150475421..1edaae439a32 100644
> --- a/drivers/iio/adc/ingenic-adc.c
> +++ b/drivers/iio/adc/ingenic-adc.c
> @@ -632,7 +632,7 @@ static int ingenic_adc_read_chan_info_raw(struct
> iio_dev *iio_dev,
> struct iio_chan_spec const *chan,
> int *val)
> {
> - int bit, ret, engine = (chan->channel == INGENIC_ADC_BATTERY);
> + int cmd, ret, engine = (chan->channel == INGENIC_ADC_BATTERY);
> struct ingenic_adc *adc = iio_priv(iio_dev);
>
> ret = clk_enable(adc->clk);
> @@ -642,11 +642,22 @@ static int
> ingenic_adc_read_chan_info_raw(struct iio_dev *iio_dev,
> return ret;
> }
>
> - /* We cannot sample AUX/AUX2 in parallel. */
> + /* We cannot sample the aux channels in parallel. */
> mutex_lock(&adc->aux_lock);
> if (adc->soc_data->has_aux_md && engine == 0) {
> - bit = BIT(chan->channel == INGENIC_ADC_AUX2);
> - ingenic_adc_set_config(adc, JZ_ADC_REG_CFG_AUX_MD, bit);
> + switch (chan->channel) {
> + case INGENIC_ADC_AUX0:
> + cmd = 0;
> + break;
> + case INGENIC_ADC_AUX:
> + cmd = 1;
> + break;
> + case INGENIC_ADC_AUX2:
> + cmd = 2;
> + break;
> + }
> +
> + ingenic_adc_set_config(adc, JZ_ADC_REG_CFG_AUX_MD, cmd);
> }
>
> ret = ingenic_adc_capture(adc, engine);
> @@ -654,6 +665,7 @@ static int ingenic_adc_read_chan_info_raw(struct
> iio_dev *iio_dev,
> goto out;
>
> switch (chan->channel) {
> + case INGENIC_ADC_AUX0:
> case INGENIC_ADC_AUX:
> case INGENIC_ADC_AUX2:
> *val = readw(adc->base + JZ_ADC_REG_ADSDAT);
> --
> 2.30.2
>


2021-07-21 21:13:09

by Paul Cercueil

[permalink] [raw]
Subject: Re: [PATCH 4/6] iio/adc: ingenic: add JZ4760B support to the sadc driver

Hi Christophe,

Le mer., juil. 21 2021 at 12:53:15 +0200, citral23
<[email protected]> a ?crit :
> The JZ4760B variant differs slightly from the JZ4760, in that it has
> a bit called VBAT_SEL
> in the CFG register. In order to correctly sample the battery voltage
> on existing handhelds
> using this SOC, the bit must be cleared.
>
> We leave the possibility to set the bit, by using the
> "ingenic,use-internal-divider" in the devicetree.
>
> Signed-off-by: citral23 <[email protected]>
> ---
> drivers/iio/adc/ingenic-adc.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/drivers/iio/adc/ingenic-adc.c
> b/drivers/iio/adc/ingenic-adc.c
> index 285e7aa8e37a..618150475421 100644
> --- a/drivers/iio/adc/ingenic-adc.c
> +++ b/drivers/iio/adc/ingenic-adc.c
> @@ -37,6 +37,7 @@
> #define JZ_ADC_REG_CFG_SAMPLE_NUM(n) ((n) << 10)
> #define JZ_ADC_REG_CFG_PULL_UP(n) ((n) << 16)
> #define JZ_ADC_REG_CFG_CMD_SEL BIT(22)
> +#define JZ_ADC_REG_CFG_VBAT_SEL BIT(30)
> #define JZ_ADC_REG_CFG_TOUCH_OPS_MASK (BIT(31) | GENMASK(23, 10))
> #define JZ_ADC_REG_ADCLK_CLKDIV_LSB 0
> #define JZ4725B_ADC_REG_ADCLK_CLKDIV10US_LSB 16
> @@ -869,6 +870,10 @@ static int ingenic_adc_probe(struct
> platform_device *pdev)
> /* Put hardware in a known passive state. */
> writeb(0x00, adc->base + JZ_ADC_REG_ENABLE);
> writeb(0xff, adc->base + JZ_ADC_REG_CTRL);
> +
> + if (!device_property_present(dev, "ingenic,use-internal-divider"))
> /* JZ4760B specific */
> + ingenic_adc_set_config(adc, JZ_ADC_REG_CFG_VBAT_SEL, 0);

You miss an "else" part, no? Set the bit if the property is present,
clear it if it is missing? You can't really rely on the reset value,
since (e.g.) the bootloader could have changed it.

Cheers,
-Paul

> +
> usleep_range(2000, 3000); /* Must wait at least 2ms. */
> clk_disable(adc->clk);
>
> @@ -896,6 +901,7 @@ static const struct of_device_id
> ingenic_adc_of_match[] = {
> { .compatible = "ingenic,jz4725b-adc", .data =
> &jz4725b_adc_soc_data, },
> { .compatible = "ingenic,jz4740-adc", .data = &jz4740_adc_soc_data,
> },
> { .compatible = "ingenic,jz4760-adc", .data = &jz4760_adc_soc_data,
> },
> + { .compatible = "ingenic,jz4760b-adc", .data =
> &jz4760_adc_soc_data, },
> { .compatible = "ingenic,jz4770-adc", .data = &jz4770_adc_soc_data,
> },
> { },
> };
> --
> 2.30.2
>


2021-07-22 02:11:56

by Rob Herring (Arm)

[permalink] [raw]
Subject: Re: [PATCH 6/6] dt-bindings: iio/adc: ingenic: add the JZ4760(B) socs to the sadc Documentation

On Wed, 21 Jul 2021 12:53:17 +0200, citral23 wrote:
> Signed-off-by: citral23 <[email protected]>
> ---
> .../devicetree/bindings/iio/adc/ingenic,adc.yaml | 9 +++++++++
> 1 file changed, 9 insertions(+)
>

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/ingenic,adc.yaml: properties:ingenic,use-internal-divider: 'oneOf' conditional failed, one must be fixed:
'type' is a required property
hint: A vendor boolean property can use "type: boolean"
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/iio/adc/ingenic,adc.yaml: properties:ingenic,use-internal-divider: 'oneOf' conditional failed, one must be fixed:
'enum' is a required property
'const' is a required property
hint: A vendor string property with exact values has an implicit type
from schema $id: http://devicetree.org/meta-schemas/vendor-props.yaml#
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/iio/adc/ingenic,adc.yaml: properties:ingenic,use-internal-divider: 'oneOf' conditional failed, one must be fixed:
'$ref' is a required property
'allOf' is a required property
hint: A vendor property needs a $ref to types.yaml
from schema $id: http://devicetree.org/meta-schemas/vendor-props.yaml#
hint: Vendor specific properties must have a type and description unless they have a defined, common suffix.
from schema $id: http://devicetree.org/meta-schemas/vendor-props.yaml#
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/iio/adc/ingenic,adc.yaml: ignoring, error in schema: properties: ingenic,use-internal-divider
warning: no schema found in file: ./Documentation/devicetree/bindings/iio/adc/ingenic,adc.yaml
Documentation/devicetree/bindings/iio/adc/ingenic,adc.example.dt.yaml:0:0: /example-0/adc@10070000: failed to match any schema with compatible: ['ingenic,jz4740-adc']
\ndoc reference errors (make refcheckdocs):

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

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.

2021-07-23 16:13:10

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH 6/6] dt-bindings: iio/adc: ingenic: add the JZ4760(B) socs to the sadc Documentation

On Wed, 21 Jul 2021 20:17:45 +0100
Paul Cercueil <[email protected]> wrote:

> Hi Christophe,
>
> Please always add a short description in your patches, even if all you
> do is repeat the patch title.
>
>
> Le mer., juil. 21 2021 at 12:53:17 +0200, citral23
> <[email protected]> a ?crit :
> > Signed-off-by: citral23 <[email protected]>
> > ---
> > .../devicetree/bindings/iio/adc/ingenic,adc.yaml | 9
> > +++++++++
> > 1 file changed, 9 insertions(+)
> >
> > diff --git
> > a/Documentation/devicetree/bindings/iio/adc/ingenic,adc.yaml
> > b/Documentation/devicetree/bindings/iio/adc/ingenic,adc.yaml
> > index 433a3fb55a2e..1b423adba61d 100644
> > --- a/Documentation/devicetree/bindings/iio/adc/ingenic,adc.yaml
> > +++ b/Documentation/devicetree/bindings/iio/adc/ingenic,adc.yaml
> > @@ -23,6 +23,8 @@ properties:
> > enum:
> > - ingenic,jz4725b-adc
> > - ingenic,jz4740-adc
> > + - ingenic,jz4760-adc
> > + - ingenic,jz4760b-adc
> > - ingenic,jz4770-adc
> >
> > '#io-channel-cells':
> > @@ -43,6 +45,12 @@ properties:
> > interrupts:
> > maxItems: 1
> >
> > + ingenic,use-internal-divider:
> > + description:
> > + This property can be used to set VBAT_SEL in the JZ4760B CFG
> > register
> > + to sample the battery voltage from the internal divider. If
> > absent, it
> > + will sample the external divider.
>
> Please remove trailing spaces. And you don't need to describe internal
> behaviour; you only need to explain the functionality in a user-facing
> perspective. Something like:
>
> "If present, battery voltage is read from the VBAT_IR pin, which has an
> internal /4 divider. If absent, it is read through the VBAT_ER pin,
> which does not have such divider."
>
> You also don't specify the type of the property, please add "type:
> boolean" before the description.
>
> There should also be a way to make sure that this property can only be
> used with the JZ4760B SoC. So a dependency for this vendor property on
> the "ingenic,jz4760b-adc" compatible string. But I'm honestly not sure
> how to express that... Maybe Rob can help.

Lots of examples in tree.
e.g.
https://elixir.bootlin.com/linux/v5.14-rc2/source/Documentation/devicetree/bindings/iio/st,st-sensors.yaml#L153

Basically you have an if block matching the compatible and for non matches
set it to false. That combined with additionaProperties: false enforces
the property can't exist for those other devices.

>
> > +
> > required:
> > - compatible
> > - '#io-channel-cells'
> > @@ -53,6 +61,7 @@ required:
> >
> > additionalProperties: false
> >
> > +
>
> Remove the extra newline.
>
> Cheers,
> -Paul
>
> > examples:
> > - |
> > #include <dt-bindings/clock/jz4740-cgu.h>
> > --
> > 2.30.2
> >
>
>