Devicetree
 help / color / mirror / Atom feed
* [PATCH v2 0/3] pwm: airoha: add AN7589 support
@ 2026-12-04 19:38 John Crispin
  2026-12-04 19:38 ` [PATCH v2 1/3] dt-bindings: mfd: airoha: add #pwm-cells to AN7589 gpio-sysctl John Crispin
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: John Crispin @ 2026-12-04 19:38 UTC (permalink / raw)
  To: Lorenzo Bianconi, Lee Jones, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Uwe Kleine-König
  Cc: Christian Marangi, devicetree, lei.dong, Linqi.zhang,
	linux-kernel, linux-mediatek, linux-pwm, mfd, Rajeev.kumar,
	upstream, Weifeng.xu, zhengping.zhang

The AN7589 PWM block is the EN7581 one with three differences: the
flash set-id of a channel is 4 bits wide instead of 3, the channel
enable moved into a register of its own with one bit per channel, and
it has the 16 GPIO channels only.

The PWM controller lives in the GPIO system controller next to the pin
controller. It has no resources of its own, so following Conor's
comment on the pinctrl binding [1] it gets no child node and the system
controller node itself carries #pwm-cells.

Patch 1 adds #pwm-cells to the system controller binding. Patch 2 adds
a small MFD driver that registers the PWM controller as a cell, and
patch 3 teaches the PWM driver the AN7589 layout and lets it probe as
that cell.

Based on next-20261201, which has the AN7589 pinctrl series and with it
the GPIO system controller binding.

[1] https://lore.kernel.org/r/20261117-illicitly-translate-2d16b1279df9@spud

Changes in v2:
- Patch 2: drop <linux/mod_devicetable.h> (Uwe).
- Patch 3: describe the enable bits of both SoCs with a register, the
  bit of channel 0 and the distance between two channels, so the
  lookup has no condition (Uwe).
- Patch 3: add EN7581_PWM_NUM_CHANNELS (Uwe).
- Patch 3: say in the commit message why the PWM chip uses the node of
  its parent and what the id_table changes for the name match (Uwe).
- Patch 1 is unchanged.
- Link to v1: https://lore.kernel.org/r/20261201194434.3132187-1-john@phrozen.org

John Crispin (3):
  dt-bindings: mfd: airoha: add #pwm-cells to AN7589 gpio-sysctl
  mfd: add Airoha GPIO system controller driver
  pwm: airoha: add support for AN7589

 .../mfd/airoha,an7589-gpio-sysctl.yaml        |   6 +-
 MAINTAINERS                                   |   1 +
 drivers/mfd/Kconfig                           |  11 ++
 drivers/mfd/Makefile                          |   1 +
 drivers/mfd/airoha-gpio-sysctl.c              |  42 +++++++
 drivers/pwm/pwm-airoha.c                      | 116 +++++++++++++++---
 6 files changed, 162 insertions(+), 15 deletions(-)
 create mode 100644 drivers/mfd/airoha-gpio-sysctl.c


base-commit: d138596e9f822033490b2e577ec2ea64f2aa246c
-- 
2.34.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/3] dt-bindings: mfd: airoha: add #pwm-cells to AN7589 gpio-sysctl
  2026-12-04 19:38 [PATCH v2 0/3] pwm: airoha: add AN7589 support John Crispin
@ 2026-12-04 19:38 ` John Crispin
  2026-12-04 19:45   ` sashiko-bot
  2026-12-04 19:38 ` [PATCH v2 2/3] mfd: add Airoha GPIO system controller driver John Crispin
  2026-12-04 19:38 ` [PATCH v2 3/3] pwm: airoha: add support for AN7589 John Crispin
  2 siblings, 1 reply; 7+ messages in thread
From: John Crispin @ 2026-12-04 19:38 UTC (permalink / raw)
  To: Lorenzo Bianconi, Lee Jones, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Uwe Kleine-König
  Cc: Christian Marangi, devicetree, lei.dong, Linqi.zhang,
	linux-kernel, linux-mediatek, linux-pwm, mfd, Rajeev.kumar,
	upstream, Weifeng.xu, zhengping.zhang

The AN7589 PWM controller sits in the GPIO system controller. It has
no resources of its own, so it gets no child node. The system
controller node is the PWM provider.

Signed-off-by: John Crispin <john@phrozen.org>
---
Changes in v2:
- None.

 .../devicetree/bindings/mfd/airoha,an7589-gpio-sysctl.yaml  | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/mfd/airoha,an7589-gpio-sysctl.yaml b/Documentation/devicetree/bindings/mfd/airoha,an7589-gpio-sysctl.yaml
index 0785b61bdda3..476f7241bb1b 100644
--- a/Documentation/devicetree/bindings/mfd/airoha,an7589-gpio-sysctl.yaml
+++ b/Documentation/devicetree/bindings/mfd/airoha,an7589-gpio-sysctl.yaml
@@ -11,7 +11,7 @@ maintainers:
 
 description:
   Airoha AN7589 SoC GPIO system controller which provides a register map
-  for controlling the GPIO and pins of the SoC.
+  for controlling the GPIO, pins and PWM of the SoC.
 
 properties:
   compatible:
@@ -29,6 +29,9 @@ properties:
     description:
       Child node definition for AN7589 Pin controller
 
+  "#pwm-cells":
+    const: 3
+
 required:
   - compatible
   - reg
@@ -42,6 +45,7 @@ examples:
     system-controller@1fbf0200 {
       compatible = "airoha,an7589-gpio-sysctl", "syscon", "simple-mfd";
       reg = <0x1fbf0200 0x100>;
+      #pwm-cells = <3>;
 
       pinctrl {
         compatible = "airoha,an7589-pinctrl";
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 2/3] mfd: add Airoha GPIO system controller driver
  2026-12-04 19:38 [PATCH v2 0/3] pwm: airoha: add AN7589 support John Crispin
  2026-12-04 19:38 ` [PATCH v2 1/3] dt-bindings: mfd: airoha: add #pwm-cells to AN7589 gpio-sysctl John Crispin
@ 2026-12-04 19:38 ` John Crispin
  2026-12-04 19:50   ` sashiko-bot
  2026-12-04 19:38 ` [PATCH v2 3/3] pwm: airoha: add support for AN7589 John Crispin
  2 siblings, 1 reply; 7+ messages in thread
From: John Crispin @ 2026-12-04 19:38 UTC (permalink / raw)
  To: Lorenzo Bianconi, Lee Jones, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Uwe Kleine-König
  Cc: Christian Marangi, devicetree, lei.dong, Linqi.zhang,
	linux-kernel, linux-mediatek, linux-pwm, mfd, Rajeev.kumar,
	upstream, Weifeng.xu, zhengping.zhang

The GPIO system controller of the AN7589 holds the pin controller and
the PWM controller. The pin controller is a child node. The PWM
controller has no node, so register it as an MFD cell.

Signed-off-by: John Crispin <john@phrozen.org>
---
Changes in v2:
- Drop <linux/mod_devicetable.h> (Uwe).

 MAINTAINERS                      |  1 +
 drivers/mfd/Kconfig              | 11 +++++++++
 drivers/mfd/Makefile             |  1 +
 drivers/mfd/airoha-gpio-sysctl.c | 42 ++++++++++++++++++++++++++++++++
 4 files changed, 55 insertions(+)
 create mode 100644 drivers/mfd/airoha-gpio-sysctl.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 857ad039c997..196b0be1ab8b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -22334,6 +22334,7 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/mfd/airoha,an7589-gpio-sysctl.yaml
 F:	Documentation/devicetree/bindings/pinctrl/airoha,an7589-pinctrl.yaml
 F:	Documentation/devicetree/bindings/pinctrl/airoha,en7581-pinctrl.yaml
+F:	drivers/mfd/airoha-gpio-sysctl.c
 F:	drivers/pinctrl/airoha/pinctrl-airoha.c
 F:	drivers/pinctrl/airoha/pinctrl-an7589.c
 
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 81b5cb566996..65afbb32ad16 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -32,6 +32,17 @@ config MFD_ADP5585
 	  the core APIs _only_, you have to select individual components like
 	  the GPIO and PWM functions under the corresponding menus.
 
+config MFD_AIROHA_GPIO_SYSCTL
+	tristate "Airoha GPIO system controller"
+	select MFD_CORE
+	depends on ARCH_AIROHA || COMPILE_TEST
+	depends on OF
+	help
+	  Say yes here to add support for the GPIO system controller of the
+	  Airoha AN7589 SoC. The block holds the pin controller and the PWM
+	  controller. This driver registers the PWM controller, you have to
+	  select the PWM driver under the corresponding menu.
+
 config MFD_ALTERA_A10SR
 	bool "Altera Arria10 DevKit System Resource chip"
 	depends on ARCH_INTEL_SOCFPGA && SPI_MASTER=y && OF
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 0697f8bbb65f..02e01adbc261 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -200,6 +200,7 @@ obj-$(CONFIG_AB8500_CORE)	+= ab8500-core.o ab8500-sysctrl.o
 obj-$(CONFIG_MFD_TIMBERDALE)    += timberdale.o
 obj-$(CONFIG_PMIC_ADP5520)	+= adp5520.o
 obj-$(CONFIG_MFD_ADP5585)	+= adp5585.o
+obj-$(CONFIG_MFD_AIROHA_GPIO_SYSCTL)	+= airoha-gpio-sysctl.o
 obj-$(CONFIG_MFD_KEMPLD)	+= kempld-core.o
 obj-$(CONFIG_MFD_INTEL_QUARK_I2C_GPIO)	+= intel_quark_i2c_gpio.o
 obj-$(CONFIG_LPC_SCH)		+= lpc_sch.o
diff --git a/drivers/mfd/airoha-gpio-sysctl.c b/drivers/mfd/airoha-gpio-sysctl.c
new file mode 100644
index 000000000000..40b3251200f3
--- /dev/null
+++ b/drivers/mfd/airoha-gpio-sysctl.c
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Airoha GPIO system controller
+ *
+ * Copyright (C) 2026 John Crispin <john@phrozen.org>
+ */
+
+#include <linux/array_size.h>
+#include <linux/mfd/core.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+
+static const struct mfd_cell an7589_gpio_sysctl_cells[] = {
+	MFD_CELL_NAME("airoha-an7589-pwm"),
+};
+
+static int airoha_gpio_sysctl_probe(struct platform_device *pdev)
+{
+	return devm_mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE,
+				    an7589_gpio_sysctl_cells,
+				    ARRAY_SIZE(an7589_gpio_sysctl_cells),
+				    NULL, 0, NULL);
+}
+
+static const struct of_device_id airoha_gpio_sysctl_of_match[] = {
+	{ .compatible = "airoha,an7589-gpio-sysctl" },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, airoha_gpio_sysctl_of_match);
+
+static struct platform_driver airoha_gpio_sysctl_driver = {
+	.probe = airoha_gpio_sysctl_probe,
+	.driver = {
+		.name = "airoha-gpio-sysctl",
+		.of_match_table = airoha_gpio_sysctl_of_match,
+	},
+};
+module_platform_driver(airoha_gpio_sysctl_driver);
+
+MODULE_AUTHOR("John Crispin <john@phrozen.org>");
+MODULE_DESCRIPTION("Airoha GPIO system controller driver");
+MODULE_LICENSE("GPL");
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 3/3] pwm: airoha: add support for AN7589
  2026-12-04 19:38 [PATCH v2 0/3] pwm: airoha: add AN7589 support John Crispin
  2026-12-04 19:38 ` [PATCH v2 1/3] dt-bindings: mfd: airoha: add #pwm-cells to AN7589 gpio-sysctl John Crispin
  2026-12-04 19:38 ` [PATCH v2 2/3] mfd: add Airoha GPIO system controller driver John Crispin
@ 2026-12-04 19:38 ` John Crispin
  2026-12-04 19:55   ` sashiko-bot
  2 siblings, 1 reply; 7+ messages in thread
From: John Crispin @ 2026-12-04 19:38 UTC (permalink / raw)
  To: Lorenzo Bianconi, Lee Jones, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Uwe Kleine-König
  Cc: Christian Marangi, devicetree, lei.dong, Linqi.zhang,
	linux-kernel, linux-mediatek, linux-pwm, mfd, Rajeev.kumar,
	upstream, Weifeng.xu, zhengping.zhang

The AN7589 flash map has a 4 bit set-id per channel instead of 3. On
the EN7581 bit 3 of each channel is the enable bit; on the AN7589 the
enable bits are in a register of their own at 0xe0, one bit per
channel.

Describe both layouts in match data: the set-id mask, and for the
enable bits the first register, the bit of channel 0 and the distance
in bits between two channels.

The AN7589 has the 16 GPIO channels of the EN7581 and no SIPO channels:
only the low 16 bits of the enable register and the two GPIO flash map
registers hold a value. So the channel count moves into the match data
as well: 16 for the AN7589, 33 for the EN7581 as before.

The device tree binding of the AN7589 GPIO system controller has no
child node for the PWM controller; the system controller node itself
carries #pwm-cells. The MFD driver of the system controller registers
the PWM controller as a cell. Match the cell by name and take over the
device tree node of the parent, so that consumers find the PWM chip.

With an id_table, the platform bus no longer matches a device by the
driver name "pwm-airoha". Nothing creates a device with that name: the
EN7581 PWM controller binds by its compatible.

Signed-off-by: John Crispin <john@phrozen.org>
---
Changes in v2:
- Describe the enable bits of both SoCs with a register, the bit of
  channel 0 and the distance between two channels, so the lookup has
  no condition (Uwe).
- Add EN7581_PWM_NUM_CHANNELS (Uwe).
- Say in the commit message why the PWM chip uses the node of its
  parent and what the id_table changes for the name match (Uwe).

 drivers/pwm/pwm-airoha.c | 116++++++++++++++++++++++++++++++++++-----
 1 file changed, 102 insertions(+), 14 deletions(-)

diff --git a/drivers/pwm/pwm-airoha.c b/drivers/pwm/pwm-airoha.c
index 0cf6b011520a..85e17a9d69b6 100644
--- a/drivers/pwm/pwm-airoha.c
+++ b/drivers/pwm/pwm-airoha.c
@@ -23,6 +23,7 @@
 #include <linux/mfd/syscon.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
+#include <linux/property.h>
 #include <linux/pwm.h>
 #include <linux/regmap.h>
 #include <linux/types.h>
@@ -53,6 +54,7 @@
 #define AIROHA_PWM_REG_GPIO_FLASH_MAP_SHIFT(_n) (4 * (_n))
 #define AIROHA_PWM_GPIO_FLASH_EN		BIT(3)
 #define AIROHA_PWM_GPIO_FLASH_SET_ID		GENMASK(2, 0)
+#define AIROHA_PWM_GPIO_FLASH_SET_ID_WIDE	GENMASK(3, 0)
 
 /* Register map is equal to GPIO flash map */
 #define AIROHA_PWM_REG_SIPO_FLASH_MAP(_n)	(0x0054 + (4 * (_n)))
@@ -61,6 +63,8 @@
 #define AIROHA_PWM_REG_CYCLE_CFG_SHIFT(_n)	(8 * (_n))
 #define AIROHA_PWM_WAVE_GEN_CYCLE		GENMASK(7, 0)
 
+#define AIROHA_PWM_REG_GPIO_FLASH_EN		0x00e0
+
 /* GPIO/SIPO flash map handles 8 pins in one register */
 #define AIROHA_PWM_PINS_PER_FLASH_MAP		8
 /* Cycle(Period) registers handles 4 generators in one 32-bit register */
@@ -78,6 +82,16 @@
 #define AIROHA_PWM_NUM_GPIO			16
 #define AIROHA_PWM_NUM_SIPO			17
 #define AIROHA_PWM_MAX_CHANNELS			(AIROHA_PWM_NUM_GPIO + AIROHA_PWM_NUM_SIPO)
+#define EN7581_PWM_NUM_CHANNELS			AIROHA_PWM_MAX_CHANNELS
+#define AN7589_PWM_NUM_CHANNELS			AIROHA_PWM_NUM_GPIO
+
+struct airoha_pwm_soc_data {
+	unsigned int npwm;
+	u32 flash_set_id_mask;
+	u32 flash_en_reg;
+	u32 flash_en_mask;
+	u8 flash_en_stride;
+};
 
 struct airoha_pwm_bucket {
 	/* Concurrent access protected by PWM core */
@@ -88,6 +102,7 @@ struct airoha_pwm_bucket {
 
 struct airoha_pwm {
 	struct regmap *regmap;
+	const struct airoha_pwm_soc_data *soc;
 
 	DECLARE_BITMAP(initialized, AIROHA_PWM_MAX_CHANNELS);
 
@@ -417,9 +432,41 @@ static int airoha_pwm_sipo_init(struct airoha_pwm *pc)
 			       AIROHA_PWM_SERIAL_GPIO_FLASH_MODE);
 }
 
+static void airoha_pwm_get_flash_en_addr_and_mask(struct airoha_pwm *pc,
+						  unsigned int hwpwm,
+						  u32 *addr, u32 *mask)
+{
+	const struct airoha_pwm_soc_data *soc = pc->soc;
+	unsigned int bit = __ffs(soc->flash_en_mask) +
+			   hwpwm * soc->flash_en_stride;
+
+	*addr = soc->flash_en_reg + sizeof(u32) * (bit / BITS_PER_TYPE(u32));
+	*mask = BIT(bit % BITS_PER_TYPE(u32));
+}
+
+static int airoha_pwm_flash_enable(struct airoha_pwm *pc, unsigned int hwpwm,
+				   bool enable)
+{
+	u32 addr, mask;
+
+	airoha_pwm_get_flash_en_addr_and_mask(pc, hwpwm, &addr, &mask);
+
+	return regmap_assign_bits(pc->regmap, addr, mask, enable);
+}
+
+static int airoha_pwm_flash_enabled(struct airoha_pwm *pc, unsigned int hwpwm)
+{
+	u32 addr, mask;
+
+	airoha_pwm_get_flash_en_addr_and_mask(pc, hwpwm, &addr, &mask);
+
+	return regmap_test_bits(pc->regmap, addr, mask);
+}
+
 static int airoha_pwm_config_flash_map(struct airoha_pwm *pc,
 				       unsigned int hwpwm, int index)
 {
+	u32 set_id_mask = pc->soc->flash_set_id_mask;
 	unsigned int addr;
 	u32 shift;
 	int ret;
@@ -432,17 +479,15 @@ static int airoha_pwm_config_flash_map(struct airoha_pwm *pc,
 		 * If we need to disable the PWM, we just put low the
 		 * GPIO. No need to setup buckets.
 		 */
-		return regmap_clear_bits(pc->regmap, addr,
-					 AIROHA_PWM_GPIO_FLASH_EN << shift);
+		return airoha_pwm_flash_enable(pc, hwpwm, false);
 	}
 
-	ret = regmap_update_bits(pc->regmap, addr,
-				 AIROHA_PWM_GPIO_FLASH_SET_ID << shift,
-				 FIELD_PREP(AIROHA_PWM_GPIO_FLASH_SET_ID, index) << shift);
+	ret = regmap_update_bits(pc->regmap, addr, set_id_mask << shift,
+				 field_prep(set_id_mask, index) << shift);
 	if (ret)
 		return ret;
 
-	return regmap_set_bits(pc->regmap, addr, AIROHA_PWM_GPIO_FLASH_EN << shift);
+	return airoha_pwm_flash_enable(pc, hwpwm, true);
 }
 
 static int airoha_pwm_config(struct airoha_pwm *pc, struct pwm_device *pwm,
@@ -550,19 +595,23 @@ static int airoha_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
 	u32 addr, shift, val;
 	u8 bucket;
 
+	ret = airoha_pwm_flash_enabled(pc, hwpwm);
+	if (ret < 0)
+		return ret;
+
+	state->enabled = ret;
+	if (!state->enabled)
+		return 0;
+
 	airoha_pwm_get_flash_map_addr_and_shift(hwpwm, &addr, &shift);
 
 	ret = regmap_read(pc->regmap, addr, &val);
 	if (ret)
 		return ret;
 
-	state->enabled = FIELD_GET(AIROHA_PWM_GPIO_FLASH_EN, val >> shift);
-	if (!state->enabled)
-		return 0;
-
 	state->polarity = PWM_POLARITY_NORMAL;
 
-	bucket = FIELD_GET(AIROHA_PWM_GPIO_FLASH_SET_ID, val >> shift);
+	bucket = field_get(pc->soc->flash_set_id_mask, val >> shift);
 	return airoha_pwm_get_bucket(pc, bucket, &state->period,
 				     &state->duty_cycle);
 }
@@ -574,17 +623,30 @@ static const struct pwm_ops airoha_pwm_ops = {
 
 static int airoha_pwm_probe(struct platform_device *pdev)
 {
+	const struct airoha_pwm_soc_data *soc;
+	const struct platform_device_id *id;
 	struct device *dev = &pdev->dev;
 	struct airoha_pwm *pc;
 	struct pwm_chip *chip;
 	int ret;
 
-	chip = devm_pwmchip_alloc(dev, AIROHA_PWM_MAX_CHANNELS, sizeof(*pc));
+	id = platform_get_device_id(pdev);
+	if (id) {
+		soc = (const struct airoha_pwm_soc_data *)id->driver_data;
+		device_set_of_node_from_dev(dev, dev->parent);
+	} else {
+		soc = device_get_match_data(dev);
+	}
+	if (!soc)
+		return -EINVAL;
+
+	chip = devm_pwmchip_alloc(dev, soc->npwm, sizeof(*pc));
 	if (IS_ERR(chip))
 		return PTR_ERR(chip);
 
 	chip->ops = &airoha_pwm_ops;
 	pc = pwmchip_get_drvdata(chip);
+	pc->soc = soc;
 
 	pc->regmap = device_node_to_regmap(dev_of_node(dev->parent));
 	if (IS_ERR(pc->regmap))
@@ -597,12 +659,37 @@ static int airoha_pwm_probe(struct platform_device *pdev)
 	return 0;
 }
 
+static const struct airoha_pwm_soc_data en7581_pwm_soc_data = {
+	.npwm = EN7581_PWM_NUM_CHANNELS,
+	.flash_set_id_mask = AIROHA_PWM_GPIO_FLASH_SET_ID,
+	.flash_en_reg = AIROHA_PWM_REG_GPIO_FLASH_MAP(0),
+	.flash_en_mask = AIROHA_PWM_GPIO_FLASH_EN,
+	.flash_en_stride = AIROHA_PWM_REG_GPIO_FLASH_MAP_SHIFT(1),
+};
+
+static const struct airoha_pwm_soc_data an7589_pwm_soc_data = {
+	.npwm = AN7589_PWM_NUM_CHANNELS,
+	.flash_set_id_mask = AIROHA_PWM_GPIO_FLASH_SET_ID_WIDE,
+	.flash_en_reg = AIROHA_PWM_REG_GPIO_FLASH_EN,
+	.flash_en_mask = BIT(0),
+	.flash_en_stride = 1,
+};
+
 static const struct of_device_id airoha_pwm_of_match[] = {
-	{ .compatible = "airoha,en7581-pwm" },
+	{ .compatible = "airoha,en7581-pwm", .data = &en7581_pwm_soc_data },
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, airoha_pwm_of_match);
 
+static const struct platform_device_id airoha_pwm_id_table[] = {
+	{
+		.name = "airoha-an7589-pwm",
+		.driver_data = (kernel_ulong_t)&an7589_pwm_soc_data,
+	},
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(platform, airoha_pwm_id_table);
+
 static struct platform_driver airoha_pwm_driver = {
 	.driver = {
 		.name = "pwm-airoha",
@@ -610,6 +697,7 @@ static struct platform_driver airoha_pwm_driver = {
 		.of_match_table = airoha_pwm_of_match,
 	},
 	.probe = airoha_pwm_probe,
+	.id_table = airoha_pwm_id_table,
 };
 module_platform_driver(airoha_pwm_driver);
 
@@ -617,5 +705,5 @@ MODULE_AUTHOR("Lorenzo Bianconi <lorenzo@kernel.org>");
 MODULE_AUTHOR("Markus Gothe <markus.gothe@genexis.eu>");
 MODULE_AUTHOR("Benjamin Larsson <benjamin.larsson@genexis.eu>");
 MODULE_AUTHOR("Christian Marangi <ansuelsmth@gmail.com>");
-MODULE_DESCRIPTION("Airoha EN7581 PWM driver");
+MODULE_DESCRIPTION("Airoha PWM driver");
 MODULE_LICENSE("GPL");
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/3] dt-bindings: mfd: airoha: add #pwm-cells to AN7589 gpio-sysctl
  2026-12-04 19:38 ` [PATCH v2 1/3] dt-bindings: mfd: airoha: add #pwm-cells to AN7589 gpio-sysctl John Crispin
@ 2026-12-04 19:45   ` sashiko-bot
  0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-12-04 19:45 UTC (permalink / raw)
  To: John Crispin; +Cc: devicetree, mfd, robh, conor+dt, lee

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] dt-bindings: mfd: airoha: #pwm-cells placed after pinctrl child
  node
--

commit f1b243d911de5965e31542d858a6b32f5d703bda
Author: John Crispin <john@phrozen.org>

dt-bindings: mfd: airoha: add #pwm-cells to AN7589 gpio-sysctl

This commit adds the #pwm-cells property to the Airoha AN7589 GPIO system
controller binding and updates its description and example to reflect that
it acts as the PWM provider.

> diff --git a/Documentation/devicetree/bindings/mfd/airoha,an7589-gpio-sysctl.yaml b/Documentation/devicetree/bindings/mfd/airoha,an7589-gpio-sysctl.yaml
> index 0785b61bdda3e..476f7241bb1b7 100644
> --- a/Documentation/devicetree/bindings/mfd/airoha,an7589-gpio-sysctl.yaml
> +++ b/Documentation/devicetree/bindings/mfd/airoha,an7589-gpio-sysctl.yaml

[ ... ]

> @@ -29,6 +29,9 @@ properties:
>      description:
>        Child node definition for AN7589 Pin controller
>
> +  "#pwm-cells":
> +    const: 3
> +
>  required:
>    - compatible
>    - reg

[Severity: Low]
Should "#pwm-cells" be placed before the pinctrl child node definition in
properties, immediately after reg?

Documentation/devicetree/bindings/writing-schema.rst and
dts-coding-style.rst place standard properties before child nodes, which
also matches the order used in the example below.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204193857.3801624-1-john@phrozen.org?part=1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/3] mfd: add Airoha GPIO system controller driver
  2026-12-04 19:38 ` [PATCH v2 2/3] mfd: add Airoha GPIO system controller driver John Crispin
@ 2026-12-04 19:50   ` sashiko-bot
  0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-12-04 19:50 UTC (permalink / raw)
  To: John Crispin; +Cc: devicetree, mfd, robh, conor+dt, lee

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Low] mfd: single-cell MFD wrapper in airoha_gpio_sysctl_probe()
- [Low] mfd: airoha_gpio_sysctl_probe() uses PLATFORM_DEVID_NONE instead
  of AUTO
- [Low] mfd: commit subject omits driver prefix and capitalized
  description
--

commit c0c4caede3d516641ce772c10961adb3a204e79d
Author: John Crispin <john@phrozen.org>

mfd: add Airoha GPIO system controller driver

This commit adds an MFD platform driver for the Airoha AN7589 GPIO system
controller that registers an MFD cell for the PWM controller.

> mfd: add Airoha GPIO system controller driver

[Severity: Low]
MFD commit subjects use the "mfd: <driver>: <Capitalized description>"
format, so this should include the driver prefix and capitalize the
description (e.g. "mfd: airoha-gpio-sysctl: Add Airoha GPIO system
controller driver").

[ ... ]

> diff --git a/drivers/mfd/airoha-gpio-sysctl.c b/drivers/mfd/airoha-gpio-sysctl.c
> new file mode 100644
> index 0000000000000..40b3251200f37
> --- /dev/null
> +++ b/drivers/mfd/airoha-gpio-sysctl.c

[ ... ]

> +static const struct mfd_cell an7589_gpio_sysctl_cells[] = {
> +	MFD_CELL_NAME("airoha-an7589-pwm"),
> +};

[Severity: Low]
Is a dedicated MFD driver needed here when it manages no shared core
resources and registers only a single PWM cell?

In Documentation/devicetree/bindings/mfd/airoha,an7589-gpio-sysctl.yaml,
the node already specifies "syscon" and "simple-mfd" with #pwm-cells = <3>
on the parent node, so simple-mfd populates the pinctrl child and syscon
provides the shared regmap.

MFD is meant for devices registering multiple children across subsystems,
and this wrapper adds a separate MFD_AIROHA_GPIO_SYSCTL Kconfig option
that silently prevents the PWM driver from probing if disabled.  Could the
PWM driver bind directly to airoha,an7589-gpio-sysctl instead?

> +static int airoha_gpio_sysctl_probe(struct platform_device *pdev)
> +{
> +	return devm_mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE,
> +				    an7589_gpio_sysctl_cells,
> +				    ARRAY_SIZE(an7589_gpio_sysctl_cells),
> +				    NULL, 0, NULL);
> +}

[Severity: Low]
Should this pass PLATFORM_DEVID_AUTO instead of PLATFORM_DEVID_NONE?

MFD prefers PLATFORM_DEVID_AUTO unless a subdevice needs explicit
numbering.  PLATFORM_DEVID_NONE assigns a fixed unindexed platform device
name, which would fail with -EEXIST if more than one instance ever probed.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204193857.3801624-1-john@phrozen.org?part=2

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 3/3] pwm: airoha: add support for AN7589
  2026-12-04 19:38 ` [PATCH v2 3/3] pwm: airoha: add support for AN7589 John Crispin
@ 2026-12-04 19:55   ` sashiko-bot
  0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-12-04 19:55 UTC (permalink / raw)
  To: John Crispin; +Cc: devicetree, mfd, robh, conor+dt, lee

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] pwm: airoha_pwm_disable() unconditionally clears SIPO
  register on AN7589
- [Medium] pwm: unchecked 4-bit bucket index in airoha_pwm_get_state()
  on AN7589
--

commit 9e34a67908ec87aef2e6fb0c34ba57a33ee1533c
Author: John Crispin <john@phrozen.org>

pwm: airoha: add support for AN7589

This commit adds SoC match data and a platform ID table to pwm-airoha to
support the 16-channel AN7589 PWM controller with a 4-bit set-id and a
separate flash enable register.

> diff --git a/drivers/pwm/pwm-airoha.c b/drivers/pwm/pwm-airoha.c
> index 0cf6b011520a2..85e17a9d69b6f 100644
> --- a/drivers/pwm/pwm-airoha.c
> +++ b/drivers/pwm/pwm-airoha.c

[ ... ]

> @@ -550,19 +595,23 @@ static int airoha_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
>  	u32 addr, shift, val;
>  	u8 bucket;
>  
> +	ret = airoha_pwm_flash_enabled(pc, hwpwm);
> +	if (ret < 0)
> +		return ret;
> +
> +	state->enabled = ret;
> +	if (!state->enabled)
> +		return 0;
> +
>  	airoha_pwm_get_flash_map_addr_and_shift(hwpwm, &addr, &shift);
>  
>  	ret = regmap_read(pc->regmap, addr, &val);
>  	if (ret)
>  		return ret;
>  
> -	state->enabled = FIELD_GET(AIROHA_PWM_GPIO_FLASH_EN, val >> shift);
> -	if (!state->enabled)
> -		return 0;
> -
>  	state->polarity = PWM_POLARITY_NORMAL;
>  
> -	bucket = FIELD_GET(AIROHA_PWM_GPIO_FLASH_SET_ID, val >> shift);
> +	bucket = field_get(pc->soc->flash_set_id_mask, val >> shift);
>  	return airoha_pwm_get_bucket(pc, bucket, &state->period,
>  				     &state->duty_cycle);
>  }

[Severity: Medium]
Can bucket be >= AIROHA_PWM_NUM_BUCKETS (8) on AN7589 here?

With flash_set_id_mask widened to GENMASK(3, 0), field_get() can return
values 8..15 if firmware or hardware leaves an enabled channel programmed
with bit 3 set.  airoha_pwm_get_bucket() then reads past the 8 generator
registers (0x004c..0x0058 and 0x00a0..0x00a4) and reports bogus state.

Validating bucket < AIROHA_PWM_NUM_BUCKETS before calling
airoha_pwm_get_bucket() would prevent out-of-range register reads.

[ ... ]

> @@ -597,12 +659,37 @@ static int airoha_pwm_probe(struct platform_device *pdev)
>  	return 0;
>  }
>  
> +static const struct airoha_pwm_soc_data en7581_pwm_soc_data = {
> +	.npwm = EN7581_PWM_NUM_CHANNELS,
> +	.flash_set_id_mask = AIROHA_PWM_GPIO_FLASH_SET_ID,
> +	.flash_en_reg = AIROHA_PWM_REG_GPIO_FLASH_MAP(0),
> +	.flash_en_mask = AIROHA_PWM_GPIO_FLASH_EN,
> +	.flash_en_stride = AIROHA_PWM_REG_GPIO_FLASH_MAP_SHIFT(1),
> +};
> +
> +static const struct airoha_pwm_soc_data an7589_pwm_soc_data = {
> +	.npwm = AN7589_PWM_NUM_CHANNELS,
> +	.flash_set_id_mask = AIROHA_PWM_GPIO_FLASH_SET_ID_WIDE,
> +	.flash_en_reg = AIROHA_PWM_REG_GPIO_FLASH_EN,
> +	.flash_en_mask = BIT(0),
> +	.flash_en_stride = 1,
> +};

[Severity: Medium]
Will disabling a PWM channel on AN7589 still clear
AIROHA_PWM_REG_SIPO_FLASH_MODE_CFG even though AN7589 has no SIPO
channels?

drivers/pwm/pwm-airoha.c:airoha_pwm_disable() {
    ...
	/* If no SIPO is used, disable the shift register chip */
	if (!bitmap_read(pc->initialized,
			 AIROHA_PWM_NUM_GPIO, AIROHA_PWM_NUM_SIPO))
		regmap_clear_bits(pc->regmap, AIROHA_PWM_REG_SIPO_FLASH_MODE_CFG,
				  AIROHA_PWM_SERIAL_GPIO_FLASH_MODE);
}

Because the SIPO bits of pc->initialized are never set on AN7589, this
condition is always true and every disable clears BIT(1) at offset 0x0030
in the shared GPIO syscon regmap, risking corruption of unrelated register
state.

Guarding this clear on pc->soc->npwm > AIROHA_PWM_NUM_GPIO would avoid
touching that register on AN7589.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204193857.3801624-1-john@phrozen.org?part=3

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-12-04 19:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 19:38 [PATCH v2 0/3] pwm: airoha: add AN7589 support John Crispin
2026-12-04 19:38 ` [PATCH v2 1/3] dt-bindings: mfd: airoha: add #pwm-cells to AN7589 gpio-sysctl John Crispin
2026-12-04 19:45   ` sashiko-bot
2026-12-04 19:38 ` [PATCH v2 2/3] mfd: add Airoha GPIO system controller driver John Crispin
2026-12-04 19:50   ` sashiko-bot
2026-12-04 19:38 ` [PATCH v2 3/3] pwm: airoha: add support for AN7589 John Crispin
2026-12-04 19:55   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox