Skip to contentSkip to conversation

mfd: ntxec: Support for EC in Tolino Shine 2 HD

PATCH Superseded Andreas Kemnade 3 participants 5 messages Mar 13, 2021 – Mar 15, 2021

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 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.

---
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(-)
drivers/mfd/ntxec.c +52 -3
index 957de2b03529..ab6860ef3e9a 100644
@@ -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);
 
include/linux/mfd/ntxec.h +1 -0
index 361204d125f1..26ab3b8eb612 100644
@@ -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
Signature · 1 line
2.29.2
#1 lore raw
Quoted 12 lines · Andreas Kemnade

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.

---

[...]

drivers/mfd/ntxec.c static const struct regmap_config regmap_config = { · line 146

Quoted 3 lines
drivers/mfd/ntxec.c +3 -0
+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.

drivers/mfd/ntxec.c static int ntxec_probe(struct i2c_client *client) · line 234

Quoted 5 lines
drivers/mfd/ntxec.c +3 -2
-	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

#2 lore raw
In reply to Andreas Kemnade
Quoted 78 lines · Andreas Kemnade

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.

---
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(-)
drivers/mfd/ntxec.c +34 -1
index 957de2b03529..ab6860ef3e9a 100644
@@ -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[] = {

drivers/mfd/ntxec.c static const struct regmap_config regmap_config = { · line 154

Quoted 10 lines
drivers/mfd/ntxec.c +5 -0
+	{ .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.

Quoted 42 lines
drivers/mfd/ntxec.c +13 -2
 	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);
 
include/linux/mfd/ntxec.h +1 -0
index 361204d125f1..26ab3b8eb612 100644
@@ -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
Signature · 4 lines
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog
#3 lore raw

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

[...]

Quoted 10 lines

drivers/mfd/ntxec.c static const struct regmap_config regmap_config = { · line 154

Quoted 7 lines

static int ntxec_probe(struct i2c_client *client) {

drivers/mfd/ntxec.c +2 -0
 	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.

Quoted 3 lines

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

#4 lore raw
Quoted 14 lines · Andreas Kemnade

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

[...]

Quoted 10 lines

drivers/mfd/ntxec.c static const struct regmap_config regmap_config = { · line 154

Quoted 7 lines

static int ntxec_probe(struct i2c_client *client) {

drivers/mfd/ntxec.c +2 -0
 	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.

Quoted 7 lines
Quoted 3 lines

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.

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