Skip to contentSkip to conversation

mfd: tqmx86: new hardware and GPIO/I2C IRQ improvements/additions

PATCH Superseded Matthias Schiffer 2 participants 12 messages Oct 7, 2024 – Oct 16, 2024

Subsystems (2)

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v4 cover mfd: tqmx86: new hardware and GPIO/I2C IRQ improvements/additions

Patch 1 adds support for 3 new TQMx86 COMs. GPIO support on SMARC modules is currently limited (not all GPIOs can be controlled, pins use incorrect default directions, IRQ configuration is handled incorrectly), however this is a preexisting issue also effecting the TQMxE39S and TQMxE40S, not only the new TQMxE41S. This will be addressed by a future patch series involving both the TQMx86 MFD and GPIO drivers.

Patches 2-5 improve module parameter description and error handling of GPIO IRQ configuration and add support for configuring an IRQ for the TQMx86's OpenCores I2C controller in the same way.

Changelog:

v2: improve module parameter description (new patch 2, adjusted patch 5)
v3: replace IRQ 0 resource entries with empty placeholders to simplify
error handling (patches 4 and 5)
v4: remove tqmx86_irq_to_irq_cfg() function (patch 3)

Gregor Herburger (1):
mfd: tqmx86: add I2C IRQ support

Matthias Schiffer (4):
mfd: tqmx86: add board definitions for TQMx120UC, TQMx130UC and
TQMxE41S
mfd: tqmx86: improve gpio_irq module parameter description
mfd: tqmx86: refactor GPIO IRQ setup
mfd: tqmx86: make IRQ setup errors non-fatal

 drivers/mfd/tqmx86.c | 109 +++++++++++++++++++++++++++++--------------
 1 file changed, 75 insertions(+), 34 deletions(-)
Signature · 4 lines
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
https://www.tq-group.com/
#1 lore raw

PATCH v4 1/5 mfd: tqmx86: add board definitions for TQMx120UC, TQMx130UC and TQMxE41S

This adds support for 3 new TQMx86 COMs:

- TQMx120UC/TQMx130UC: COM Express Compact Type 6 modules with 12th and 13th Generation Intel Core CPUs ([1, 2])
- TQMxE41S: SMARC 2.1 module with Intel Atom x7000E and compatible CPUs [3]

[1] https://www.tq-group.com/en/products/tq-embedded/x86-architecture/tqmx120uc/
[2] https://www.tq-group.com/en/products/tq-embedded/x86-architecture/tqmx130uc/
[3] https://www.tq-group.com/en/products/tq-embedded/x86-architecture/tqmxe41s/

---

v2: no changes
v3: no changes
v4: no changes

 drivers/mfd/tqmx86.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/mfd/tqmx86.c +12 -0
index fac02875fe7d9..e15b9be98c2db 100644
@@ -35,11 +35,14 @@
 #define TQMX86_REG_BOARD_ID_E39C2	7
 #define TQMX86_REG_BOARD_ID_70EB	8
 #define TQMX86_REG_BOARD_ID_80UC	9
+#define TQMX86_REG_BOARD_ID_120UC	10
 #define TQMX86_REG_BOARD_ID_110EB	11
 #define TQMX86_REG_BOARD_ID_E40M	12
 #define TQMX86_REG_BOARD_ID_E40S	13
 #define TQMX86_REG_BOARD_ID_E40C1	14
 #define TQMX86_REG_BOARD_ID_E40C2	15
+#define TQMX86_REG_BOARD_ID_130UC	16
+#define TQMX86_REG_BOARD_ID_E41S	19
 #define TQMX86_REG_BOARD_REV	0x01
 #define TQMX86_REG_IO_EXT_INT	0x06
 #define TQMX86_REG_IO_EXT_INT_NONE		0
@@ -132,6 +135,8 @@ static const char *tqmx86_board_id_to_name(u8 board_id, u8 sauc)
 		return "TQMx70EB";
 	case TQMX86_REG_BOARD_ID_80UC:
 		return "TQMx80UC";
+	case TQMX86_REG_BOARD_ID_120UC:
+		return "TQMx120UC";
 	case TQMX86_REG_BOARD_ID_110EB:
 		return "TQMx110EB";
 	case TQMX86_REG_BOARD_ID_E40M:
@@ -142,6 +147,10 @@ static const char *tqmx86_board_id_to_name(u8 board_id, u8 sauc)
 		return "TQMxE40C1";
 	case TQMX86_REG_BOARD_ID_E40C2:
 		return "TQMxE40C2";
+	case TQMX86_REG_BOARD_ID_130UC:
+		return "TQMx130UC";
+	case TQMX86_REG_BOARD_ID_E41S:
+		return "TQMxE41S";
 	default:
 		return "Unknown";
 	}
@@ -154,11 +163,14 @@ static int tqmx86_board_id_to_clk_rate(struct device *dev, u8 board_id)
 	case TQMX86_REG_BOARD_ID_60EB:
 	case TQMX86_REG_BOARD_ID_70EB:
 	case TQMX86_REG_BOARD_ID_80UC:
+	case TQMX86_REG_BOARD_ID_120UC:
 	case TQMX86_REG_BOARD_ID_110EB:
 	case TQMX86_REG_BOARD_ID_E40M:
 	case TQMX86_REG_BOARD_ID_E40S:
 	case TQMX86_REG_BOARD_ID_E40C1:
 	case TQMX86_REG_BOARD_ID_E40C2:
+	case TQMX86_REG_BOARD_ID_130UC:
+	case TQMX86_REG_BOARD_ID_E41S:
 		return 24000;
 	case TQMX86_REG_BOARD_ID_E39MS:
 	case TQMX86_REG_BOARD_ID_E39C1:
Signature · 4 lines
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
https://www.tq-group.com/
#2 lore raw

PATCH v4 2/5 mfd: tqmx86: improve gpio_irq module parameter description

In reply to Matthias Schiffer

Clarify that "7, 9, 12" refers to the valid arguments that can be passed as gpio_irq.

---

v2: new patch
v3: no changes
v4: no changes

 drivers/mfd/tqmx86.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mfd/tqmx86.c +1 -1
index e15b9be98c2db..7b2f9490a9af5 100644
@@ -58,7 +58,7 @@
 
 static uint gpio_irq;
 module_param(gpio_irq, uint, 0);
-MODULE_PARM_DESC(gpio_irq, "GPIO IRQ number (7, 9, 12)");
+MODULE_PARM_DESC(gpio_irq, "GPIO IRQ number (valid parameters: 7, 9, 12)");
 
 static const struct resource tqmx_i2c_soft_resources[] = {
 	DEFINE_RES_IO(TQMX86_IOBASE_I2C, TQMX86_IOSIZE_I2C),
Signature · 4 lines
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
https://www.tq-group.com/
#3 lore raw

PATCH v4 3/5 mfd: tqmx86: refactor GPIO IRQ setup

In reply to Matthias Schiffer

Move IRQ setup into a helper function. The string "GPIO" for error messages is replaced with a label argument to prepare for reusing the function for the I2C IRQ.

No functional change intended.

---

v2: no changes (was patch 2/4)
v3: no changes
v4: drop tqmx86_irq_to_irq_cfg() function, handle IRQ-to-register-value
mapping in tqmx86_setup_irq() instead

 drivers/mfd/tqmx86.c | 59 +++++++++++++++++++++++++++-----------------
 1 file changed, 37 insertions(+), 22 deletions(-)
drivers/mfd/tqmx86.c +37 -22
index 7b2f9490a9af5..8aa448a67c9a5 100644
@@ -186,33 +186,52 @@ static int tqmx86_board_id_to_clk_rate(struct device *dev, u8 board_id)
 	}
 }
 
-static int tqmx86_probe(struct platform_device *pdev)
+static int tqmx86_setup_irq(struct device *dev, const char *label, u8 irq,
+			    void __iomem *io_base, u8 reg_shift)
 {
-	u8 board_id, sauc, rev, i2c_det, io_ext_int_val;
-	struct device *dev = &pdev->dev;
-	u8 gpio_irq_cfg, readback;
-	const char *board_name;
-	void __iomem *io_base;
-	int err;
+	u8 val, readback;
+	int irq_cfg;
 
-	switch (gpio_irq) {
+	switch (irq) {
 	case 0:
-		gpio_irq_cfg = TQMX86_REG_IO_EXT_INT_NONE;
+		irq_cfg = TQMX86_REG_IO_EXT_INT_NONE;
 		break;
 	case 7:
-		gpio_irq_cfg = TQMX86_REG_IO_EXT_INT_7;
+		irq_cfg = TQMX86_REG_IO_EXT_INT_7;
 		break;
 	case 9:
-		gpio_irq_cfg = TQMX86_REG_IO_EXT_INT_9;
+		irq_cfg = TQMX86_REG_IO_EXT_INT_9;
 		break;
 	case 12:
-		gpio_irq_cfg = TQMX86_REG_IO_EXT_INT_12;
+		irq_cfg = TQMX86_REG_IO_EXT_INT_12;
 		break;
 	default:
-		pr_err("tqmx86: Invalid GPIO IRQ (%d)\n", gpio_irq);
+		dev_err(dev, "invalid %s IRQ (%d)\n", label, irq);
 		return -EINVAL;
 	}
 
+	val = ioread8(io_base + TQMX86_REG_IO_EXT_INT);
+	val &= ~(TQMX86_REG_IO_EXT_INT_MASK << reg_shift);
+	val |= (irq_cfg & TQMX86_REG_IO_EXT_INT_MASK) << reg_shift;
+
+	iowrite8(val, io_base + TQMX86_REG_IO_EXT_INT);
+	readback = ioread8(io_base + TQMX86_REG_IO_EXT_INT);
+	if (readback != val) {
+		dev_warn(dev, "%s interrupts not supported\n", label);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int tqmx86_probe(struct platform_device *pdev)
+{
+	u8 board_id, sauc, rev, i2c_det;
+	struct device *dev = &pdev->dev;
+	const char *board_name;
+	void __iomem *io_base;
+	int err;
+
 	io_base = devm_ioport_map(dev, TQMX86_IOBASE, TQMX86_IOSIZE);
 	if (!io_base)
 		return -ENOMEM;
@@ -233,15 +252,11 @@ static int tqmx86_probe(struct platform_device *pdev)
 	 */
 	i2c_det = inb(TQMX86_REG_I2C_DETECT);
 
-	if (gpio_irq_cfg) {
-		io_ext_int_val =
-			gpio_irq_cfg << TQMX86_REG_IO_EXT_INT_GPIO_SHIFT;
-		iowrite8(io_ext_int_val, io_base + TQMX86_REG_IO_EXT_INT);
-		readback = ioread8(io_base + TQMX86_REG_IO_EXT_INT);
-		if (readback != io_ext_int_val) {
-			dev_warn(dev, "GPIO interrupts not supported.\n");
-			return -EINVAL;
-		}
+	if (gpio_irq) {
+		err = tqmx86_setup_irq(dev, "GPIO", gpio_irq, io_base,
+				       TQMX86_REG_IO_EXT_INT_GPIO_SHIFT);
+		if (err)
+			return err;
 
 		/* Assumes the IRQ resource is first. */
 		tqmx_gpio_resources[0].start = gpio_irq;
Signature · 4 lines
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
https://www.tq-group.com/
#4 lore raw

PATCH v4 4/5 mfd: tqmx86: make IRQ setup errors non-fatal

In reply to Matthias Schiffer

GPIO IRQ setup can fail either because an invalid IRQ was passed as a parameter, or because the GPIO controller does not support interrupts. Neither is severe enough to stop the whole probe; simply disable IRQ support in the GPIO resource when setup fails.

---

v2: no changes (was patch 3/4)
v3: replace IRQ 0 resource with an empty placeholder to simplify error handling
v4: no changes

 drivers/mfd/tqmx86.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)
drivers/mfd/tqmx86.c +8 -12
index 8aa448a67c9a5..e444fcd2a3e9d 100644
@@ -68,12 +68,12 @@ static const struct resource tqmx_watchdog_resources[] = {
 	DEFINE_RES_IO(TQMX86_IOBASE_WATCHDOG, TQMX86_IOSIZE_WATCHDOG),
 };
 
-/*
- * The IRQ resource must be first, since it is updated with the
- * configured IRQ in the probe function.
- */
 static struct resource tqmx_gpio_resources[] = {
-	DEFINE_RES_IRQ(0),
+	/*
+	 * Placeholder for IRQ resource - must come first to be filled in by the
+	 * probe function.
+	 */
+	{},
 	DEFINE_RES_IO(TQMX86_IOBASE_GPIO, TQMX86_IOSIZE_GPIO),
 };
 
@@ -255,13 +255,9 @@ static int tqmx86_probe(struct platform_device *pdev)
 	if (gpio_irq) {
 		err = tqmx86_setup_irq(dev, "GPIO", gpio_irq, io_base,
 				       TQMX86_REG_IO_EXT_INT_GPIO_SHIFT);
-		if (err)
-			return err;
-
-		/* Assumes the IRQ resource is first. */
-		tqmx_gpio_resources[0].start = gpio_irq;
-	} else {
-		tqmx_gpio_resources[0].flags = 0;
+		if (!err)
+			/* Assumes the IRQ resource placeholder is first */
+			tqmx_gpio_resources[0] = DEFINE_RES_IRQ(gpio_irq);
 	}
 
 	ocores_platform_data.clock_khz = tqmx86_board_id_to_clk_rate(dev, board_id);
Signature · 4 lines
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
https://www.tq-group.com/
#5 lore raw

PATCH v4 5/5 mfd: tqmx86: add I2C IRQ support

In reply to Matthias Schiffer

From: Gregor Herburger <[email protected]>

The i2c-ocores controller can run in interrupt mode on tqmx86 modules. Add module parameter to allow configuring the IRQ number, similar to the handling of the GPIO IRQ.

---

v2: improve module parameter description (was patch 4/4)
v3: replace IRQ 0 resource with an empty placeholder to simplify error handling
v4: no changes

 drivers/mfd/tqmx86.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/mfd/tqmx86.c +19 -1
index e444fcd2a3e9d..057d035b71d33 100644
@@ -50,6 +50,7 @@
 #define TQMX86_REG_IO_EXT_INT_9			2
 #define TQMX86_REG_IO_EXT_INT_12		3
 #define TQMX86_REG_IO_EXT_INT_MASK		0x3
+#define TQMX86_REG_IO_EXT_INT_I2C_SHIFT		0
 #define TQMX86_REG_IO_EXT_INT_GPIO_SHIFT	4
 #define TQMX86_REG_SAUC		0x17
 
@@ -60,7 +61,16 @@ static uint gpio_irq;
 module_param(gpio_irq, uint, 0);
 MODULE_PARM_DESC(gpio_irq, "GPIO IRQ number (valid parameters: 7, 9, 12)");
 
-static const struct resource tqmx_i2c_soft_resources[] = {
+static uint i2c_irq;
+module_param(i2c_irq, uint, 0);
+MODULE_PARM_DESC(i2c_irq, "I2C IRQ number (valid parameters: 7, 9, 12)");
+
+static struct resource tqmx_i2c_soft_resources[] = {
+	/*
+	 * Placeholder for IRQ resource - must come first to be filled in by the
+	 * probe function.
+	 */
+	{},
 	DEFINE_RES_IO(TQMX86_IOBASE_I2C, TQMX86_IOSIZE_I2C),
 };
 
@@ -263,6 +273,14 @@ static int tqmx86_probe(struct platform_device *pdev)
 	ocores_platform_data.clock_khz = tqmx86_board_id_to_clk_rate(dev, board_id);
 
 	if (i2c_det == TQMX86_REG_I2C_DETECT_SOFT) {
+		if (i2c_irq) {
+			err = tqmx86_setup_irq(dev, "I2C", i2c_irq, io_base,
+					       TQMX86_REG_IO_EXT_INT_I2C_SHIFT);
+			if (!err)
+				/* Assumes the IRQ resource placeholder is first */
+				tqmx_i2c_soft_resources[0] = DEFINE_RES_IRQ(i2c_irq);
+		}
+
 		err = devm_mfd_add_devices(dev, PLATFORM_DEVID_NONE,
 					   tqmx86_i2c_soft_dev,
 					   ARRAY_SIZE(tqmx86_i2c_soft_dev),
Signature · 4 lines
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
https://www.tq-group.com/
maintainer
#6 lore raw

Re: [PATCH v4 5/5] mfd: tqmx86: add I2C IRQ support

Quoted 34 lines · Matthias Schiffer

From: Gregor Herburger <[email protected]>

The i2c-ocores controller can run in interrupt mode on tqmx86 modules. Add module parameter to allow configuring the IRQ number, similar to the handling of the GPIO IRQ.

---

v2: improve module parameter description (was patch 4/4)
v3: replace IRQ 0 resource with an empty placeholder to simplify error handling
v4: no changes

 drivers/mfd/tqmx86.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/mfd/tqmx86.c +1 -1
index e444fcd2a3e9d..057d035b71d33 100644
@@ -50,6 +50,7 @@
 #define TQMX86_REG_IO_EXT_INT_9			2
 #define TQMX86_REG_IO_EXT_INT_12		3
 #define TQMX86_REG_IO_EXT_INT_MASK		0x3
+#define TQMX86_REG_IO_EXT_INT_I2C_SHIFT		0
 #define TQMX86_REG_IO_EXT_INT_GPIO_SHIFT	4
 #define TQMX86_REG_SAUC		0x17
 
@@ -60,7 +61,16 @@ static uint gpio_irq;
 module_param(gpio_irq, uint, 0);
 MODULE_PARM_DESC(gpio_irq, "GPIO IRQ number (valid parameters: 7, 9, 12)");
 
-static const struct resource tqmx_i2c_soft_resources[] = {

drivers/mfd/tqmx86.c static uint gpio_irq; · line 73

Quoted 10 lines
drivers/mfd/tqmx86.c +10 -0
+static uint i2c_irq;
+module_param(i2c_irq, uint, 0);
+MODULE_PARM_DESC(i2c_irq, "I2C IRQ number (valid parameters: 7, 9, 12)");
+
+static struct resource tqmx_i2c_soft_resources[] = {
+	/*
+	 * Placeholder for IRQ resource - must come first to be filled in by the
+	 * probe function.
+	 */
+	{},

Having a NULLed entry in the first slot doesn't sit well with me at all.

In order for us to avoid wasting memory, it would be better to place the entry at the end of the array with a blank entry:

DEFINE_RES_IRQ(0),

Later comes the matching code which updates the 0 value to something sane.

Before you call to the add the devices, check to see if the value has changed. If it hasn't, deprecate num_resources, effectively masking the last entry in the array. Then when platform_device_add_resources() comes to duplicate the array, it will only copy the relevant entries.

Quoted 24 lines
drivers/mfd/tqmx86.c +8 -0
 	DEFINE_RES_IO(TQMX86_IOBASE_I2C, TQMX86_IOSIZE_I2C),
 };
 
@@ -263,6 +273,14 @@ static int tqmx86_probe(struct platform_device *pdev)
 	ocores_platform_data.clock_khz = tqmx86_board_id_to_clk_rate(dev, board_id);
 
 	if (i2c_det == TQMX86_REG_I2C_DETECT_SOFT) {
+		if (i2c_irq) {
+			err = tqmx86_setup_irq(dev, "I2C", i2c_irq, io_base,
+					       TQMX86_REG_IO_EXT_INT_I2C_SHIFT);
+			if (!err)
+				/* Assumes the IRQ resource placeholder is first */
+				tqmx_i2c_soft_resources[0] = DEFINE_RES_IRQ(i2c_irq);
+		}
+
 		err = devm_mfd_add_devices(dev, PLATFORM_DEVID_NONE,
 					   tqmx86_i2c_soft_dev,
 					   ARRAY_SIZE(tqmx86_i2c_soft_dev),
Signature · 4 lines
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
https://www.tq-group.com/
Signature · 1 line
Lee Jones [李琼斯]
#7 lore raw

Re: [PATCH v4 5/5] mfd: tqmx86: add I2C IRQ support

Quoted 53 lines · Lee Jones
Quoted 34 lines · Matthias Schiffer

From: Gregor Herburger <[email protected]>

The i2c-ocores controller can run in interrupt mode on tqmx86 modules. Add module parameter to allow configuring the IRQ number, similar to the handling of the GPIO IRQ.

---

v2: improve module parameter description (was patch 4/4)
v3: replace IRQ 0 resource with an empty placeholder to simplify error handling
v4: no changes

 drivers/mfd/tqmx86.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/mfd/tqmx86.c +1 -1
index e444fcd2a3e9d..057d035b71d33 100644
@@ -50,6 +50,7 @@
 #define TQMX86_REG_IO_EXT_INT_9			2
 #define TQMX86_REG_IO_EXT_INT_12		3
 #define TQMX86_REG_IO_EXT_INT_MASK		0x3
+#define TQMX86_REG_IO_EXT_INT_I2C_SHIFT		0
 #define TQMX86_REG_IO_EXT_INT_GPIO_SHIFT	4
 #define TQMX86_REG_SAUC		0x17
 
@@ -60,7 +61,16 @@ static uint gpio_irq;
 module_param(gpio_irq, uint, 0);
 MODULE_PARM_DESC(gpio_irq, "GPIO IRQ number (valid parameters: 7, 9, 12)");
 
-static const struct resource tqmx_i2c_soft_resources[] = {

drivers/mfd/tqmx86.c static uint gpio_irq; · line 73

Quoted 10 lines
drivers/mfd/tqmx86.c +10 -0
+static uint i2c_irq;
+module_param(i2c_irq, uint, 0);
+MODULE_PARM_DESC(i2c_irq, "I2C IRQ number (valid parameters: 7, 9, 12)");
+
+static struct resource tqmx_i2c_soft_resources[] = {
+	/*
+	 * Placeholder for IRQ resource - must come first to be filled in by the
+	 * probe function.
+	 */
+	{},

Having a NULLed entry in the first slot doesn't sit well with me at all.

In order for us to avoid wasting memory, it would be better to place the entry at the end of the array with a blank entry:

Quoted 8 lines

DEFINE_RES_IRQ(0),

Later comes the matching code which updates the 0 value to something sane.

Before you call to the add the devices, check to see if the value has changed. If it hasn't, deprecate num_resources, effectively masking the last entry in the array. Then when platform_device_add_resources() comes to duplicate the array, it will only copy the relevant entries.

I chose my current solution because it resulted in more simple and maintainable code:

- No dynamic array access, the IRQ resource is always written to index 0
- No surprises regarding num_resources, it is always equal to ARRAY_SIZE(resources)

It also allowed to make all mfd_cell const; to make num_resources modifyable, either the const would need to be removed, or each mfd_cell would need to be copied to a stack variable in the probe function.

In my opinion, these benefits outweigh the 2*64 bytes saved for the additional resources allocated by platform_device_add_resources() - and 128 bytes doesn't seem significant at all, in particular considering that this driver is used on x86_64 only.

Best,
Matthias

Quoted 26 lines
Quoted 25 lines
drivers/mfd/tqmx86.c +8 -0
 	DEFINE_RES_IO(TQMX86_IOBASE_I2C, TQMX86_IOSIZE_I2C),
 };
 
@@ -263,6 +273,14 @@ static int tqmx86_probe(struct platform_device *pdev)
 	ocores_platform_data.clock_khz = tqmx86_board_id_to_clk_rate(dev, board_id);
 
 	if (i2c_det == TQMX86_REG_I2C_DETECT_SOFT) {
+		if (i2c_irq) {
+			err = tqmx86_setup_irq(dev, "I2C", i2c_irq, io_base,
+					       TQMX86_REG_IO_EXT_INT_I2C_SHIFT);
+			if (!err)
+				/* Assumes the IRQ resource placeholder is first */
+				tqmx_i2c_soft_resources[0] = DEFINE_RES_IRQ(i2c_irq);
+		}
+
 		err = devm_mfd_add_devices(dev, PLATFORM_DEVID_NONE,
 					   tqmx86_i2c_soft_dev,
 					   ARRAY_SIZE(tqmx86_i2c_soft_dev),
Signature · 4 lines
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
https://www.tq-group.com/
Signature · 4 lines
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
https://www.tq-group.com/
maintainer
#8 lore raw

Re: [PATCH v4 5/5] mfd: tqmx86: add I2C IRQ support

Quoted 58 lines · Matthias Schiffer
Quoted 57 lines · Lee Jones
Quoted 34 lines · Matthias Schiffer

From: Gregor Herburger <[email protected]>

The i2c-ocores controller can run in interrupt mode on tqmx86 modules. Add module parameter to allow configuring the IRQ number, similar to the handling of the GPIO IRQ.

---

v2: improve module parameter description (was patch 4/4)
v3: replace IRQ 0 resource with an empty placeholder to simplify error handling
v4: no changes

 drivers/mfd/tqmx86.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/mfd/tqmx86.c +1 -1
index e444fcd2a3e9d..057d035b71d33 100644
@@ -50,6 +50,7 @@
 #define TQMX86_REG_IO_EXT_INT_9			2
 #define TQMX86_REG_IO_EXT_INT_12		3
 #define TQMX86_REG_IO_EXT_INT_MASK		0x3
+#define TQMX86_REG_IO_EXT_INT_I2C_SHIFT		0
 #define TQMX86_REG_IO_EXT_INT_GPIO_SHIFT	4
 #define TQMX86_REG_SAUC		0x17
 
@@ -60,7 +61,16 @@ static uint gpio_irq;
 module_param(gpio_irq, uint, 0);
 MODULE_PARM_DESC(gpio_irq, "GPIO IRQ number (valid parameters: 7, 9, 12)");
 
-static const struct resource tqmx_i2c_soft_resources[] = {

drivers/mfd/tqmx86.c static uint gpio_irq; · line 73

Quoted 10 lines
drivers/mfd/tqmx86.c +10 -0
+static uint i2c_irq;
+module_param(i2c_irq, uint, 0);
+MODULE_PARM_DESC(i2c_irq, "I2C IRQ number (valid parameters: 7, 9, 12)");
+
+static struct resource tqmx_i2c_soft_resources[] = {
+	/*
+	 * Placeholder for IRQ resource - must come first to be filled in by the
+	 * probe function.
+	 */
+	{},

Having a NULLed entry in the first slot doesn't sit well with me at all.

In order for us to avoid wasting memory, it would be better to place the entry at the end of the array with a blank entry:

DEFINE_RES_IRQ(0),

Later comes the matching code which updates the 0 value to something sane.

Quoted 8 lines
Quoted 4 lines

Before you call to the add the devices, check to see if the value has changed. If it hasn't, deprecate num_resources, effectively masking the last entry in the array. Then when platform_device_add_resources() comes to duplicate the array, it will only copy the relevant entries.

I chose my current solution because it resulted in more simple and maintainable code:

- No dynamic array access, the IRQ resource is always written to index 0

Which is fragile (even with the comment). If you're going to directly index array elements, please do so with a unique identifier rather than relying on it happening to reside in the first.

Quoted 1 line

- No surprises regarding num_resources, it is always equal to ARRAY_SIZE(resources)

No surprises, but sometimes it's incorrect.

Quoted 7 lines

It also allowed to make all mfd_cell const; to make num_resources modifyable, either the const would need to be removed, or each mfd_cell would need to be copied to a stack variable in the probe function.

In my opinion, these benefits outweigh the 2*64 bytes saved for the additional resources allocated by platform_device_add_resources() - and 128 bytes doesn't seem significant at all, in particular considering that this driver is used on x86_64 only.

But doesn't outweigh my disliking for placing a NULL element at the start of the array. If you _must_ do something like this, please place it at the end of the array.

Quoted 32 lines
Quoted 26 lines
Quoted 25 lines
drivers/mfd/tqmx86.c +8 -0
 	DEFINE_RES_IO(TQMX86_IOBASE_I2C, TQMX86_IOSIZE_I2C),
 };
 
@@ -263,6 +273,14 @@ static int tqmx86_probe(struct platform_device *pdev)
 	ocores_platform_data.clock_khz = tqmx86_board_id_to_clk_rate(dev, board_id);
 
 	if (i2c_det == TQMX86_REG_I2C_DETECT_SOFT) {
+		if (i2c_irq) {
+			err = tqmx86_setup_irq(dev, "I2C", i2c_irq, io_base,
+					       TQMX86_REG_IO_EXT_INT_I2C_SHIFT);
+			if (!err)
+				/* Assumes the IRQ resource placeholder is first */
+				tqmx_i2c_soft_resources[0] = DEFINE_RES_IRQ(i2c_irq);
+		}
+
 		err = devm_mfd_add_devices(dev, PLATFORM_DEVID_NONE,
 					   tqmx86_i2c_soft_dev,
 					   ARRAY_SIZE(tqmx86_i2c_soft_dev),
Signature · 4 lines
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
https://www.tq-group.com/
Signature · 4 lines
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
https://www.tq-group.com/
Signature · 1 line
Lee Jones [李琼斯]
#9 lore raw

Re: [PATCH v4 5/5] mfd: tqmx86: add I2C IRQ support

Quoted 82 lines · Lee Jones
Quoted 58 lines · Matthias Schiffer
Quoted 57 lines · Lee Jones
Quoted 34 lines · Matthias Schiffer

From: Gregor Herburger <[email protected]>

The i2c-ocores controller can run in interrupt mode on tqmx86 modules. Add module parameter to allow configuring the IRQ number, similar to the handling of the GPIO IRQ.

---

v2: improve module parameter description (was patch 4/4)
v3: replace IRQ 0 resource with an empty placeholder to simplify error handling
v4: no changes

 drivers/mfd/tqmx86.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/mfd/tqmx86.c +1 -1
index e444fcd2a3e9d..057d035b71d33 100644
@@ -50,6 +50,7 @@
 #define TQMX86_REG_IO_EXT_INT_9			2
 #define TQMX86_REG_IO_EXT_INT_12		3
 #define TQMX86_REG_IO_EXT_INT_MASK		0x3
+#define TQMX86_REG_IO_EXT_INT_I2C_SHIFT		0
 #define TQMX86_REG_IO_EXT_INT_GPIO_SHIFT	4
 #define TQMX86_REG_SAUC		0x17
 
@@ -60,7 +61,16 @@ static uint gpio_irq;
 module_param(gpio_irq, uint, 0);
 MODULE_PARM_DESC(gpio_irq, "GPIO IRQ number (valid parameters: 7, 9, 12)");
 
-static const struct resource tqmx_i2c_soft_resources[] = {

drivers/mfd/tqmx86.c static uint gpio_irq; · line 73

Quoted 10 lines
drivers/mfd/tqmx86.c +10 -0
+static uint i2c_irq;
+module_param(i2c_irq, uint, 0);
+MODULE_PARM_DESC(i2c_irq, "I2C IRQ number (valid parameters: 7, 9, 12)");
+
+static struct resource tqmx_i2c_soft_resources[] = {
+	/*
+	 * Placeholder for IRQ resource - must come first to be filled in by the
+	 * probe function.
+	 */
+	{},

Having a NULLed entry in the first slot doesn't sit well with me at all.

In order for us to avoid wasting memory, it would be better to place the entry at the end of the array with a blank entry:

DEFINE_RES_IRQ(0),

Later comes the matching code which updates the 0 value to something sane.

Quoted 8 lines
Quoted 4 lines

Before you call to the add the devices, check to see if the value has changed. If it hasn't, deprecate num_resources, effectively masking the last entry in the array. Then when platform_device_add_resources() comes to duplicate the array, it will only copy the relevant entries.

I chose my current solution because it resulted in more simple and maintainable code:

- No dynamic array access, the IRQ resource is always written to index 0

Which is fragile (even with the comment). If you're going to directly index array elements, please do so with a unique identifier rather than relying on it happening to reside in the first.

Quoted 1 line

- No surprises regarding num_resources, it is always equal to ARRAY_SIZE(resources)

No surprises, but sometimes it's incorrect.

Quoted 4 lines

It also allowed to make all mfd_cell const; to make num_resources modifyable, either the const would need to be removed, or each mfd_cell would need to be copied to a stack variable in the probe function.

Quoted 8 lines
Quoted 3 lines

In my opinion, these benefits outweigh the 2*64 bytes saved for the additional resources allocated by platform_device_add_resources() - and 128 bytes doesn't seem significant at all, in particular considering that this driver is used on x86_64 only.

But doesn't outweigh my disliking for placing a NULL element at the start of the array. If you _must_ do something like this, please place it at the end of the array.

Ok, will move the placeholder to the end, and access it using a defined index instead of 0. I would still prefer to keep num_resources constant instead of adjusting it. Does this sound acceptable to you?

Best,
Matthias

Quoted 33 lines
Quoted 32 lines
Quoted 26 lines
Quoted 25 lines
drivers/mfd/tqmx86.c +8 -0
 	DEFINE_RES_IO(TQMX86_IOBASE_I2C, TQMX86_IOSIZE_I2C),
 };
 
@@ -263,6 +273,14 @@ static int tqmx86_probe(struct platform_device *pdev)
 	ocores_platform_data.clock_khz = tqmx86_board_id_to_clk_rate(dev, board_id);
 
 	if (i2c_det == TQMX86_REG_I2C_DETECT_SOFT) {
+		if (i2c_irq) {
+			err = tqmx86_setup_irq(dev, "I2C", i2c_irq, io_base,
+					       TQMX86_REG_IO_EXT_INT_I2C_SHIFT);
+			if (!err)
+				/* Assumes the IRQ resource placeholder is first */
+				tqmx_i2c_soft_resources[0] = DEFINE_RES_IRQ(i2c_irq);
+		}
+
 		err = devm_mfd_add_devices(dev, PLATFORM_DEVID_NONE,
 					   tqmx86_i2c_soft_dev,
 					   ARRAY_SIZE(tqmx86_i2c_soft_dev),
Signature · 4 lines
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
https://www.tq-group.com/
Signature · 4 lines
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
https://www.tq-group.com/
Signature · 4 lines
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
https://www.tq-group.com/
maintainer
#10 lore raw

Re: [PATCH v4 5/5] mfd: tqmx86: add I2C IRQ support

Quoted 87 lines · Matthias Schiffer
Quoted 86 lines · Lee Jones
Quoted 58 lines · Matthias Schiffer
Quoted 57 lines · Lee Jones
Quoted 34 lines · Matthias Schiffer

From: Gregor Herburger <[email protected]>

The i2c-ocores controller can run in interrupt mode on tqmx86 modules. Add module parameter to allow configuring the IRQ number, similar to the handling of the GPIO IRQ.

---

v2: improve module parameter description (was patch 4/4)
v3: replace IRQ 0 resource with an empty placeholder to simplify error handling
v4: no changes

 drivers/mfd/tqmx86.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/mfd/tqmx86.c +1 -1
index e444fcd2a3e9d..057d035b71d33 100644
@@ -50,6 +50,7 @@
 #define TQMX86_REG_IO_EXT_INT_9			2
 #define TQMX86_REG_IO_EXT_INT_12		3
 #define TQMX86_REG_IO_EXT_INT_MASK		0x3
+#define TQMX86_REG_IO_EXT_INT_I2C_SHIFT		0
 #define TQMX86_REG_IO_EXT_INT_GPIO_SHIFT	4
 #define TQMX86_REG_SAUC		0x17
 
@@ -60,7 +61,16 @@ static uint gpio_irq;
 module_param(gpio_irq, uint, 0);
 MODULE_PARM_DESC(gpio_irq, "GPIO IRQ number (valid parameters: 7, 9, 12)");
 
-static const struct resource tqmx_i2c_soft_resources[] = {

drivers/mfd/tqmx86.c static uint gpio_irq; · line 73

Quoted 10 lines
drivers/mfd/tqmx86.c +10 -0
+static uint i2c_irq;
+module_param(i2c_irq, uint, 0);
+MODULE_PARM_DESC(i2c_irq, "I2C IRQ number (valid parameters: 7, 9, 12)");
+
+static struct resource tqmx_i2c_soft_resources[] = {
+	/*
+	 * Placeholder for IRQ resource - must come first to be filled in by the
+	 * probe function.
+	 */
+	{},

Having a NULLed entry in the first slot doesn't sit well with me at all.

In order for us to avoid wasting memory, it would be better to place the entry at the end of the array with a blank entry:

DEFINE_RES_IRQ(0),

Later comes the matching code which updates the 0 value to something sane.

Quoted 8 lines
Quoted 4 lines

Before you call to the add the devices, check to see if the value has changed. If it hasn't, deprecate num_resources, effectively masking the last entry in the array. Then when platform_device_add_resources() comes to duplicate the array, it will only copy the relevant entries.

I chose my current solution because it resulted in more simple and maintainable code:

- No dynamic array access, the IRQ resource is always written to index 0

Which is fragile (even with the comment). If you're going to directly index array elements, please do so with a unique identifier rather than relying on it happening to reside in the first.

Quoted 1 line

- No surprises regarding num_resources, it is always equal to ARRAY_SIZE(resources)

No surprises, but sometimes it's incorrect.

Quoted 7 lines

It also allowed to make all mfd_cell const; to make num_resources modifyable, either the const would need to be removed, or each mfd_cell would need to be copied to a stack variable in the probe function.

In my opinion, these benefits outweigh the 2*64 bytes saved for the additional resources allocated by platform_device_add_resources() - and 128 bytes doesn't seem significant at all, in particular considering that this driver is used on x86_64 only.

Quoted 8 lines
Quoted 4 lines

But doesn't outweigh my disliking for placing a NULL element at the start of the array. If you _must_ do something like this, please place it at the end of the array.

Ok, will move the placeholder to the end, and access it using a defined index instead of 0. I would still prefer to keep num_resources constant instead of adjusting it. Does this sound acceptable to you?

It would allow me to sleep at night, yes. :)

Signature · 1 line
Lee Jones [李琼斯]
maintainer
#11 lore raw

Re: [PATCH v4 5/5] mfd: tqmx86: add I2C IRQ support

Quoted 94 lines · Lee Jones
Quoted 92 lines · Matthias Schiffer
Quoted 90 lines · Lee Jones
Quoted 58 lines · Matthias Schiffer
Quoted 57 lines · Lee Jones
Quoted 34 lines · Matthias Schiffer

From: Gregor Herburger <[email protected]>

The i2c-ocores controller can run in interrupt mode on tqmx86 modules. Add module parameter to allow configuring the IRQ number, similar to the handling of the GPIO IRQ.

---

v2: improve module parameter description (was patch 4/4)
v3: replace IRQ 0 resource with an empty placeholder to simplify error handling
v4: no changes

 drivers/mfd/tqmx86.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/mfd/tqmx86.c +1 -1
index e444fcd2a3e9d..057d035b71d33 100644
@@ -50,6 +50,7 @@
 #define TQMX86_REG_IO_EXT_INT_9			2
 #define TQMX86_REG_IO_EXT_INT_12		3
 #define TQMX86_REG_IO_EXT_INT_MASK		0x3
+#define TQMX86_REG_IO_EXT_INT_I2C_SHIFT		0
 #define TQMX86_REG_IO_EXT_INT_GPIO_SHIFT	4
 #define TQMX86_REG_SAUC		0x17
 
@@ -60,7 +61,16 @@ static uint gpio_irq;
 module_param(gpio_irq, uint, 0);
 MODULE_PARM_DESC(gpio_irq, "GPIO IRQ number (valid parameters: 7, 9, 12)");
 
-static const struct resource tqmx_i2c_soft_resources[] = {

drivers/mfd/tqmx86.c static uint gpio_irq; · line 73

Quoted 10 lines
drivers/mfd/tqmx86.c +10 -0
+static uint i2c_irq;
+module_param(i2c_irq, uint, 0);
+MODULE_PARM_DESC(i2c_irq, "I2C IRQ number (valid parameters: 7, 9, 12)");
+
+static struct resource tqmx_i2c_soft_resources[] = {
+	/*
+	 * Placeholder for IRQ resource - must come first to be filled in by the
+	 * probe function.
+	 */
+	{},

Having a NULLed entry in the first slot doesn't sit well with me at all.

In order for us to avoid wasting memory, it would be better to place the entry at the end of the array with a blank entry:

DEFINE_RES_IRQ(0),

Later comes the matching code which updates the 0 value to something sane.

Quoted 8 lines
Quoted 4 lines

Before you call to the add the devices, check to see if the value has changed. If it hasn't, deprecate num_resources, effectively masking the last entry in the array. Then when platform_device_add_resources() comes to duplicate the array, it will only copy the relevant entries.

I chose my current solution because it resulted in more simple and maintainable code:

- No dynamic array access, the IRQ resource is always written to index 0

Which is fragile (even with the comment). If you're going to directly index array elements, please do so with a unique identifier rather than relying on it happening to reside in the first.

Quoted 1 line

- No surprises regarding num_resources, it is always equal to ARRAY_SIZE(resources)

No surprises, but sometimes it's incorrect.

Quoted 7 lines

It also allowed to make all mfd_cell const; to make num_resources modifyable, either the const would need to be removed, or each mfd_cell would need to be copied to a stack variable in the probe function.

In my opinion, these benefits outweigh the 2*64 bytes saved for the additional resources allocated by platform_device_add_resources() - and 128 bytes doesn't seem significant at all, in particular considering that this driver is used on x86_64 only.

But doesn't outweigh my disliking for placing a NULL element at the start of the array. If you _must_ do something like this, please place it at the end of the array.

Quoted 5 lines
Quoted 3 lines

Ok, will move the placeholder to the end, and access it using a defined index instead of 0. I would still prefer to keep num_resources constant instead of adjusting it. Does this sound acceptable to you?

It would allow me to sleep at night, yes. :)

Place a neat, succinct single line comment on the same line please.

For example - not verbatim:

	[IRQ] = {}, /* Placeholder */
Signature · 1 line
Lee Jones [李琼斯]