2021-03-13 10:53:46

by Andreas Kemnade

[permalink] [raw]
Subject: [PATCH v3] mfd: ntxec: Support for EC in Tolino Shine 2 HD

Add the version of the EC in the Tolino Shine 2 HD
to the supported versions. It seems not to have an RTC
and does not ack data written to it.
The vendor kernel happily ignores write errors, using
I2C via userspace i2c-set also shows the error.
So add a quirk to ignore that error.

PWM can be successfully configured despite of that error.

Signed-off-by: Andreas Kemnade <[email protected]>
Reviewed-by: Jonathan Neuschäfer <[email protected]>
---
Changes in v3:
- remove have_rtc variable
- rename subdevices again

Changes in v2:
- more comments about stacking regmap construction
- fix accidential line removal
- better naming for subdevices
drivers/mfd/ntxec.c | 55 ++++++++++++++++++++++++++++++++++++---
include/linux/mfd/ntxec.h | 1 +
2 files changed, 53 insertions(+), 3 deletions(-)

diff --git a/drivers/mfd/ntxec.c b/drivers/mfd/ntxec.c
index 957de2b03529..ab6860ef3e9a 100644
--- a/drivers/mfd/ntxec.c
+++ b/drivers/mfd/ntxec.c
@@ -96,6 +96,38 @@ static struct notifier_block ntxec_restart_handler = {
.priority = 128,
};

+static int regmap_ignore_write(void *context,
+ unsigned int reg, unsigned int val)
+
+{
+ struct regmap *regmap = context;
+
+ regmap_write(regmap, reg, val);
+
+ return 0;
+}
+
+static int regmap_wrap_read(void *context, unsigned int reg,
+ unsigned int *val)
+{
+ struct regmap *regmap = context;
+
+ return regmap_read(regmap, reg, val);
+}
+
+/*
+ * Some firmware versions do not ack written data, add a wrapper. It
+ * is used to stack another regmap on top.
+ */
+static const struct regmap_config regmap_config_noack = {
+ .name = "ntxec_noack",
+ .reg_bits = 8,
+ .val_bits = 16,
+ .cache_type = REGCACHE_NONE,
+ .reg_write = regmap_ignore_write,
+ .reg_read = regmap_wrap_read
+};
+
static const struct regmap_config regmap_config = {
.name = "ntxec",
.reg_bits = 8,
@@ -104,16 +136,22 @@ static const struct regmap_config regmap_config = {
.val_format_endian = REGMAP_ENDIAN_BIG,
};

-static const struct mfd_cell ntxec_subdevices[] = {
+static const struct mfd_cell ntxec_subdev[] = {
{ .name = "ntxec-rtc" },
{ .name = "ntxec-pwm" },
};

+static const struct mfd_cell ntxec_subdev_no_rtc[] = {
+ { .name = "ntxec-pwm" },
+};
+
static int ntxec_probe(struct i2c_client *client)
{
struct ntxec *ec;
unsigned int version;
int res;
+ const struct mfd_cell *subdevs = ntxec_subdev;
+ size_t n_subdevs = ARRAY_SIZE(ntxec_subdev);

ec = devm_kmalloc(&client->dev, sizeof(*ec), GFP_KERNEL);
if (!ec)
@@ -138,6 +176,16 @@ static int ntxec_probe(struct i2c_client *client)
switch (version) {
case NTXEC_VERSION_KOBO_AURA:
break;
+ case NTXEC_VERSION_TOLINO_SHINE2:
+ subdevs = ntxec_subdev_no_rtc;
+ n_subdevs = ARRAY_SIZE(ntxec_subdev_no_rtc);
+ /* Another regmap stacked on top of the other */
+ ec->regmap = devm_regmap_init(ec->dev, NULL,
+ ec->regmap,
+ &regmap_config_noack);
+ if (IS_ERR(ec->regmap))
+ return PTR_ERR(ec->regmap);
+ break;
default:
dev_err(ec->dev,
"Netronix embedded controller version %04x is not supported.\n",
@@ -181,8 +229,9 @@ static int ntxec_probe(struct i2c_client *client)

i2c_set_clientdata(client, ec);

- res = devm_mfd_add_devices(ec->dev, PLATFORM_DEVID_NONE, ntxec_subdevices,
- ARRAY_SIZE(ntxec_subdevices), NULL, 0, NULL);
+ res = devm_mfd_add_devices(ec->dev, PLATFORM_DEVID_NONE,
+ subdevs, n_subdevs,
+ NULL, 0, NULL);
if (res)
dev_err(ec->dev, "Failed to add subdevices: %d\n", res);

diff --git a/include/linux/mfd/ntxec.h b/include/linux/mfd/ntxec.h
index 361204d125f1..26ab3b8eb612 100644
--- a/include/linux/mfd/ntxec.h
+++ b/include/linux/mfd/ntxec.h
@@ -33,5 +33,6 @@ static inline __be16 ntxec_reg8(u8 value)

/* Known firmware versions */
#define NTXEC_VERSION_KOBO_AURA 0xd726 /* found in Kobo Aura */
+#define NTXEC_VERSION_TOLINO_SHINE2 0xf110 /* found in Tolino Shine 2 HD */

#endif
--
2.29.2


2021-03-13 11:31:40

by J. Neuschäfer

[permalink] [raw]
Subject: Re: [PATCH v3] mfd: ntxec: Support for EC in Tolino Shine 2 HD

On Sat, Mar 13, 2021 at 11:42:58AM +0100, Andreas Kemnade wrote:
> Add the version of the EC in the Tolino Shine 2 HD
> to the supported versions. It seems not to have an RTC
> and does not ack data written to it.
> The vendor kernel happily ignores write errors, using
> I2C via userspace i2c-set also shows the error.
> So add a quirk to ignore that error.
>
> PWM can be successfully configured despite of that error.
>
> Signed-off-by: Andreas Kemnade <[email protected]>
> Reviewed-by: Jonathan Neuschäfer <[email protected]>
> ---
[...]
> +static const struct mfd_cell ntxec_subdev_no_rtc[] = {
> + { .name = "ntxec-pwm" },
> +};

I left a comment/question about 'no_rtc' vs. 'pwm' in the other thread.


> - res = devm_mfd_add_devices(ec->dev, PLATFORM_DEVID_NONE, ntxec_subdevices,
> - ARRAY_SIZE(ntxec_subdevices), NULL, 0, NULL);
> + res = devm_mfd_add_devices(ec->dev, PLATFORM_DEVID_NONE,
> + subdevs, n_subdevs,
> + NULL, 0, NULL);

The last two lines might as well be one, width-wise.


This version of the patch looks nice and short :)
Jonathan


Attachments:
(No filename) (1.09 kB)
signature.asc (849.00 B)
Download all attachments

2021-03-15 08:14:06

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH v3] mfd: ntxec: Support for EC in Tolino Shine 2 HD

On Sat, 13 Mar 2021, Andreas Kemnade wrote:

> Add the version of the EC in the Tolino Shine 2 HD
> to the supported versions. It seems not to have an RTC
> and does not ack data written to it.
> The vendor kernel happily ignores write errors, using
> I2C via userspace i2c-set also shows the error.
> So add a quirk to ignore that error.
>
> PWM can be successfully configured despite of that error.
>
> Signed-off-by: Andreas Kemnade <[email protected]>
> Reviewed-by: Jonathan Neuschäfer <[email protected]>
> ---
> Changes in v3:
> - remove have_rtc variable
> - rename subdevices again
>
> Changes in v2:
> - more comments about stacking regmap construction
> - fix accidential line removal
> - better naming for subdevices
> drivers/mfd/ntxec.c | 55 ++++++++++++++++++++++++++++++++++++---
> include/linux/mfd/ntxec.h | 1 +
> 2 files changed, 53 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mfd/ntxec.c b/drivers/mfd/ntxec.c
> index 957de2b03529..ab6860ef3e9a 100644
> --- a/drivers/mfd/ntxec.c
> +++ b/drivers/mfd/ntxec.c
> @@ -96,6 +96,38 @@ static struct notifier_block ntxec_restart_handler = {
> .priority = 128,
> };
>
> +static int regmap_ignore_write(void *context,
> + unsigned int reg, unsigned int val)
> +
> +{
> + struct regmap *regmap = context;
> +
> + regmap_write(regmap, reg, val);
> +
> + return 0;
> +}
> +
> +static int regmap_wrap_read(void *context, unsigned int reg,
> + unsigned int *val)
> +{
> + struct regmap *regmap = context;
> +
> + return regmap_read(regmap, reg, val);
> +}
> +
> +/*
> + * Some firmware versions do not ack written data, add a wrapper. It
> + * is used to stack another regmap on top.
> + */
> +static const struct regmap_config regmap_config_noack = {
> + .name = "ntxec_noack",
> + .reg_bits = 8,
> + .val_bits = 16,
> + .cache_type = REGCACHE_NONE,
> + .reg_write = regmap_ignore_write,
> + .reg_read = regmap_wrap_read
> +};
> +
> static const struct regmap_config regmap_config = {
> .name = "ntxec",
> .reg_bits = 8,
> @@ -104,16 +136,22 @@ static const struct regmap_config regmap_config = {
> .val_format_endian = REGMAP_ENDIAN_BIG,
> };
>
> -static const struct mfd_cell ntxec_subdevices[] = {
> +static const struct mfd_cell ntxec_subdev[] = {
> { .name = "ntxec-rtc" },
> { .name = "ntxec-pwm" },
> };
>
> +static const struct mfd_cell ntxec_subdev_no_rtc[] = {
> + { .name = "ntxec-pwm" },
> +};
> +
> static int ntxec_probe(struct i2c_client *client)
> {
> struct ntxec *ec;
> unsigned int version;
> int res;
> + const struct mfd_cell *subdevs = ntxec_subdev;
> + size_t n_subdevs = ARRAY_SIZE(ntxec_subdev);

This is a little confusing. I had to re-read to figure it out.

In my mind, it would be clearer to explicitly set these in the
switch, rather than have a default which can be over-written.

> ec = devm_kmalloc(&client->dev, sizeof(*ec), GFP_KERNEL);
> if (!ec)
> @@ -138,6 +176,16 @@ static int ntxec_probe(struct i2c_client *client)
> switch (version) {
> case NTXEC_VERSION_KOBO_AURA:
> break;
> + case NTXEC_VERSION_TOLINO_SHINE2:
> + subdevs = ntxec_subdev_no_rtc;
> + n_subdevs = ARRAY_SIZE(ntxec_subdev_no_rtc);
> + /* Another regmap stacked on top of the other */
> + ec->regmap = devm_regmap_init(ec->dev, NULL,
> + ec->regmap,
> + &regmap_config_noack);
> + if (IS_ERR(ec->regmap))
> + return PTR_ERR(ec->regmap);
> + break;
> default:
> dev_err(ec->dev,
> "Netronix embedded controller version %04x is not supported.\n",
> @@ -181,8 +229,9 @@ static int ntxec_probe(struct i2c_client *client)
>
> i2c_set_clientdata(client, ec);
>
> - res = devm_mfd_add_devices(ec->dev, PLATFORM_DEVID_NONE, ntxec_subdevices,
> - ARRAY_SIZE(ntxec_subdevices), NULL, 0, NULL);
> + res = devm_mfd_add_devices(ec->dev, PLATFORM_DEVID_NONE,
> + subdevs, n_subdevs,
> + NULL, 0, NULL);
> if (res)
> dev_err(ec->dev, "Failed to add subdevices: %d\n", res);
>
> diff --git a/include/linux/mfd/ntxec.h b/include/linux/mfd/ntxec.h
> index 361204d125f1..26ab3b8eb612 100644
> --- a/include/linux/mfd/ntxec.h
> +++ b/include/linux/mfd/ntxec.h
> @@ -33,5 +33,6 @@ static inline __be16 ntxec_reg8(u8 value)
>
> /* Known firmware versions */
> #define NTXEC_VERSION_KOBO_AURA 0xd726 /* found in Kobo Aura */
> +#define NTXEC_VERSION_TOLINO_SHINE2 0xf110 /* found in Tolino Shine 2 HD */
>
> #endif

--
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog

2021-03-15 12:30:21

by Andreas Kemnade

[permalink] [raw]
Subject: Re: [PATCH v3] mfd: ntxec: Support for EC in Tolino Shine 2 HD

On Mon, 15 Mar 2021 08:12:31 +0000
Lee Jones <[email protected]> wrote:

[...]
> > static int ntxec_probe(struct i2c_client *client)
> > {
> > struct ntxec *ec;
> > unsigned int version;
> > int res;
> > + const struct mfd_cell *subdevs = ntxec_subdev;
> > + size_t n_subdevs = ARRAY_SIZE(ntxec_subdev);
>
> This is a little confusing. I had to re-read to figure it out.
>
> In my mind, it would be clearer to explicitly set these in the
> switch, rather than have a default which can be over-written.
>
yes, it is clearer. I was just afraid that your compiler cannot
figure it out that things get initialized and getting comments like
"This code has never seen a compiler."
But I will throw it against several ones.

Regards,
Andreas

2021-03-15 18:35:16

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH v3] mfd: ntxec: Support for EC in Tolino Shine 2 HD

On Mon, 15 Mar 2021, Andreas Kemnade wrote:

> On Mon, 15 Mar 2021 08:12:31 +0000
> Lee Jones <[email protected]> wrote:
>
> [...]
> > > static int ntxec_probe(struct i2c_client *client)
> > > {
> > > struct ntxec *ec;
> > > unsigned int version;
> > > int res;
> > > + const struct mfd_cell *subdevs = ntxec_subdev;
> > > + size_t n_subdevs = ARRAY_SIZE(ntxec_subdev);
> >
> > This is a little confusing. I had to re-read to figure it out.
> >
> > In my mind, it would be clearer to explicitly set these in the
> > switch, rather than have a default which can be over-written.
> >
> yes, it is clearer. I was just afraid that your compiler cannot
> figure it out that things get initialized and getting comments like
> "This code has never seen a compiler."
> But I will throw it against several ones.

Don't think so. Just ensure you error out in the default case.

--
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog