Skip to contentSkip to conversation

Add support for Kontron sl28cpld

PATCH Superseded Michael Walle 10 participants 63 messages Apr 23, 2020 – Jun 8, 2020

Subsystems (11)

v3 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v3 cover Add support for Kontron sl28cpld

The Kontron sl28cpld is a board management chip providing gpio, pwm, fan monitoring and an interrupt controller. For now this controller is used on the Kontron SMARC-sAL28 board. But because of its flexible nature, it might also be used on other boards in the future. The individual blocks (like gpio, pwm, etc) are kept intentionally small. The MFD core driver then instantiates different (or multiple of the same) blocks. It also provides the register layout so it might be updated in the future without a device tree change; and support other boards with a different layout or functionalities.

See also [1] for more information.

This is my first take of a MFD driver. I don't know whether the subsystem maintainers should only be CCed on the patches which affect the subsystem or on all patches for this series. I've chosen the latter so you can get a more complete picture.

[1] https://lore.kernel.org/linux-devicetree/[email protected]/

Changes since v2:
As suggested by Guenter Roeck:
- added sl28cpld.rst to index.rst
- removed sl28cpld_wdt_status()
- reverse christmas tree local variable ordering
- assign device_property_read_bool() retval directly
- introduce WDT_DEFAULT_TIMEOUT and use it if the hardware reports 0 as timeout.
- set WDOG_HW_RUNNING if applicable
- remove platform_set_drvdata() leftover

As suggested by Bartosz Golaszewski:
- don't export gpio_regmap_simple_xlate()
- combine local variable declaration of the same type
- drop the "struct gpio_regmap_addr", instead use -1 to force an address offset of zero
- fix typo
- use "struct gpio_regmap_config" pattern, keep "struct gpio_regmap" private. this also means we need a getter/setter for the driver_data element.

As suggested by Linus Walleij:
- don't store irq_domain in gpio-regmap. drop to_irq() altogether for now. Instead there is now a new patch which lets us set the irqdomain of the gpiochip_irqchip and use its .to_irq() function. This way we don't have to expose the gpio_chip inside the gpio-regmap to the user.

Changes since v1:
- use of_match_table in all drivers, needed for automatic module loading, when using OF_MFD_CELL()
- add new gpio-regmap.c which adds a generic regmap gpio_chip implementation
- new patch for reqmap_irq, so we can reuse its implementation
- remove almost any code from gpio-sl28cpld.c, instead use gpio-regmap and regmap-irq
- change the handling of the mfd core vs device tree nodes; add a new property "of_reg" to the mfd_cell struct which, when set, is matched to the unit-address of the device tree nodes.
- fix sl28cpld watchdog when it is not initialized by the bootloader. Explicitly set the operation mode.
- also add support for kontron,assert-wdt-timeout-pin in sl28cpld-wdt.

As suggested by Bartosz Golaszewski:
- define registers as hex
- make gpio enum uppercase
- move parent regmap check before memory allocation
- use device_property_read_bool() instead of the of_ version
- mention the gpio flavors in the bindings documentation

As suggested by Guenter Roeck:
- cleanup #includes and sort them
- use devm_watchdog_register_device()
- use watchdog_stop_on_reboot()
- provide a Documentation/hwmon/sl28cpld.rst
- cleaned up the weird tristate->bool and I2C=y issue. Instead mention that the MFD driver is bool because of the following intc patch
- removed the SL28CPLD_IRQ typo

As suggested by Rob Herring:
- combine all dt bindings docs into one patch
- change the node name for all gpio flavors to "gpio"
- removed the interrupts-extended rule
- cleaned up the unit-address space, see above

Michael Walle (16):
include/linux/ioport.h: add helper to define REG resource constructs
mfd: mfd-core: Don't overwrite the dma_mask of the child device
mfd: mfd-core: match device tree node against reg property
dt-bindings: mfd: Add bindings for sl28cpld
mfd: Add support for Kontron sl28cpld management controller
irqchip: add sl28cpld interrupt controller support
watchdog: add support for sl28cpld watchdog
pwm: add support for sl28cpld PWM controller
gpiolib: Introduce gpiochip_irqchip_add_domain()
gpio: add a reusable generic gpio_chip using regmap
gpio: add support for the sl28cpld GPIO controller
hwmon: add support for the sl28cpld hardware monitoring controller
arm64: dts: freescale: sl28: enable sl28cpld
arm64: dts: freescale: sl28: map GPIOs to input events
arm64: dts: freescale: sl28: enable LED support
arm64: dts: freescale: sl28: enable fan support

 .../bindings/gpio/kontron,sl28cpld-gpio.yaml  |  51 +++
 .../hwmon/kontron,sl28cpld-hwmon.yaml         |  27 ++
 .../bindings/mfd/kontron,sl28cpld.yaml        | 162 ++++++++
 .../bindings/pwm/kontron,sl28cpld-pwm.yaml    |  35 ++
 .../watchdog/kontron,sl28cpld-wdt.yaml        |  35 ++
 Documentation/hwmon/index.rst                 |   1 +
 Documentation/hwmon/sl28cpld.rst              |  36 ++
 .../fsl-ls1028a-kontron-kbox-a-230-ls.dts     |  14 +
 .../fsl-ls1028a-kontron-sl28-var3-ads2.dts    |   9 +
 .../freescale/fsl-ls1028a-kontron-sl28.dts    | 124 +++++++
 drivers/gpio/Kconfig                          |  15 +
 drivers/gpio/Makefile                         |   2 +
 drivers/gpio/gpio-regmap.c                    | 348 ++++++++++++++++++
 drivers/gpio/gpio-sl28cpld.c                  | 184 +++++++++
 drivers/gpio/gpiolib.c                        |  20 +
 drivers/hwmon/Kconfig                         |  10 +
 drivers/hwmon/Makefile                        |   1 +
 drivers/hwmon/sl28cpld-hwmon.c                | 151 ++++++++
 drivers/irqchip/Kconfig                       |   3 +
 drivers/irqchip/Makefile                      |   1 +
 drivers/irqchip/irq-sl28cpld.c                |  97 +++++
 drivers/mfd/Kconfig                           |  21 ++
 drivers/mfd/Makefile                          |   2 +
 drivers/mfd/mfd-core.c                        |  31 +-
 drivers/mfd/sl28cpld.c                        | 153 ++++++++
 drivers/pwm/Kconfig                           |  10 +
 drivers/pwm/Makefile                          |   1 +
 drivers/pwm/pwm-sl28cpld.c                    | 203 ++++++++++
 drivers/watchdog/Kconfig                      |  11 +
 drivers/watchdog/Makefile                     |   1 +
 drivers/watchdog/sl28cpld_wdt.c               | 233 ++++++++++++
 include/linux/gpio-regmap.h                   |  69 ++++
 include/linux/gpio/driver.h                   |   3 +
 include/linux/ioport.h                        |   5 +
 include/linux/mfd/core.h                      |  26 +-
 35 files changed, 2079 insertions(+), 16 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/gpio/kontron,sl28cpld-gpio.yaml
 create mode 100644 Documentation/devicetree/bindings/hwmon/kontron,sl28cpld-hwmon.yaml
 create mode 100644 Documentation/devicetree/bindings/mfd/kontron,sl28cpld.yaml
 create mode 100644 Documentation/devicetree/bindings/pwm/kontron,sl28cpld-pwm.yaml
 create mode 100644 Documentation/devicetree/bindings/watchdog/kontron,sl28cpld-wdt.yaml
 create mode 100644 Documentation/hwmon/sl28cpld.rst
 create mode 100644 drivers/gpio/gpio-regmap.c
 create mode 100644 drivers/gpio/gpio-sl28cpld.c
 create mode 100644 drivers/hwmon/sl28cpld-hwmon.c
 create mode 100644 drivers/irqchip/irq-sl28cpld.c
 create mode 100644 drivers/mfd/sl28cpld.c
 create mode 100644 drivers/pwm/pwm-sl28cpld.c
 create mode 100644 drivers/watchdog/sl28cpld_wdt.c
 create mode 100644 include/linux/gpio-regmap.h
Signature · 1 line
2.20.1
#1 lore raw

PATCH v3 1/16 include/linux/ioport.h: add helper to define REG resource constructs

Similar to the existing helpers, add one for IORESOURCE_REG which comes in handy for most common resource declarations.

---
 include/linux/ioport.h | 5 +++++
 1 file changed, 5 insertions(+)
include/linux/ioport.h +5 -0
index a9b9170b5dd2..cdcceeec0f86 100644
@@ -165,6 +165,11 @@ enum {
 #define DEFINE_RES_MEM(_start, _size)					\
 	DEFINE_RES_MEM_NAMED((_start), (_size), NULL)
 
+#define DEFINE_RES_REG_NAMED(_start, _size, _name)			\
+	DEFINE_RES_NAMED((_start), (_size), (_name), IORESOURCE_REG)
+#define DEFINE_RES_REG(_start, _size)					\
+	DEFINE_RES_REG_NAMED((_start), (_size), NULL)
+
 #define DEFINE_RES_IRQ_NAMED(_irq, _name)				\
 	DEFINE_RES_NAMED((_irq), 1, (_name), IORESOURCE_IRQ)
 #define DEFINE_RES_IRQ(_irq)						\
Signature · 1 line
2.20.1
#2 lore raw

PATCH v3 2/16 mfd: mfd-core: Don't overwrite the dma_mask of the child device

In reply to Michael Walle

Commit cdfee5623290 ("driver core: initialize a default DMA mask for platform device") initialize the DMA of a platform device. But if the parent doesn't have a dma_mask set, for example if it's an I2C device, the dma_mask of the child platform device will be set to zero again. Which leads to many "DMA mask not set" warnings, if the MFD cell has the of_compatible property set.

[    1.877937] sl28cpld-pwm sl28cpld-pwm: DMA mask not set
[    1.883282] sl28cpld-pwm sl28cpld-pwm.0: DMA mask not set
[    1.888795] sl28cpld-gpio sl28cpld-gpio: DMA mask not set

Thus don't overwrite the dma_mask of the children. Instead set the dma_mask of the platform device.

---
 drivers/mfd/mfd-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mfd/mfd-core.c +1 -1
index f5a73af60dd4..e735565969b3 100644
@@ -138,7 +138,7 @@ static int mfd_add_device(struct device *parent, int id,
 
 	pdev->dev.parent = parent;
 	pdev->dev.type = &mfd_dev_type;
-	pdev->dev.dma_mask = parent->dma_mask;
+	pdev->platform_dma_mask = parent->dma_mask ? *parent->dma_mask : 0;
 	pdev->dev.dma_parms = parent->dma_parms;
 	pdev->dev.coherent_dma_mask = parent->coherent_dma_mask;
 
Signature · 1 line
2.20.1
#3 lore raw

Re: [PATCH v3 02/16] mfd: mfd-core: Don't overwrite the dma_mask of the child device

Quoted 6 lines · Michael Walle

Commit cdfee5623290 ("driver core: initialize a default DMA mask for platform device") initialize the DMA of a platform device. But if the parent doesn't have a dma_mask set, for example if it's an I2C device, the dma_mask of the child platform device will be set to zero again. Which leads to many "DMA mask not set" warnings, if the MFD cell has the of_compatible property set.

I'm wondering why parent doesn't have it.
I remember we have explicit patches in the past for buses such as PCI and AMBA to set default DMA mask for all physical devices on the respective bus, of course they can individually override it later.

So, this seems to me a paper over the real issue (absence of default DMA mask where it's needed) and devices should explicitly define it if they disagree with default.

If I'm wrong, you really need elaborate commit message much better.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw

Re: [PATCH v3 02/16] mfd: mfd-core: Don't overwrite the dma_mask of the child device

Quoted 9 lines · Andy Shevchenko
Quoted 6 lines · Michael Walle

Commit cdfee5623290 ("driver core: initialize a default DMA mask for platform device") initialize the DMA of a platform device. But if the parent doesn't have a dma_mask set, for example if it's an I2C device, the dma_mask of the child platform device will be set to zero again. Which leads to many "DMA mask not set" warnings, if the MFD cell has the of_compatible property set.

I'm wondering why parent doesn't have it.

Because the parent isn't on a DMA-capable bus, and thus really shouldn't have a valid DMA configuration ever.

Quoted 9 lines

I remember we have explicit patches in the past for buses such as PCI and AMBA to set default DMA mask for all physical devices on the respective bus, of course they can individually override it later.

So, this seems to me a paper over the real issue (absence of default DMA mask where it's needed) and devices should explicitly define it if they disagree with default.

If I'm wrong, you really need elaborate commit message much better.

The problem here is that MFD children are created as platform devices (regardless of what their parent is) and assigned an of_node, at which point they look pretty much indistinguishable from SoC devices created by the of_platform code, that *do* have to be assumed to be DMA-capable to prevent ~90% of existing devicetrees from breaking.

Of course the real fundamental issue is the platform bus itself, but it's way too late to fix that :(

Robin.

#5 lore raw

Re: [PATCH v3 02/16] mfd: mfd-core: Don't overwrite the dma_mask of the child device

Quoted 9 lines · Robin Murphy
Quoted 8 lines · Andy Shevchenko
Quoted 6 lines · Michael Walle

Commit cdfee5623290 ("driver core: initialize a default DMA mask for platform device") initialize the DMA of a platform device. But if the parent doesn't have a dma_mask set, for example if it's an I2C device, the dma_mask of the child platform device will be set to zero again. Which leads to many "DMA mask not set" warnings, if the MFD cell has the of_compatible property set.

Quoted 4 lines
Quoted 1 line

I'm wondering why parent doesn't have it.

Because the parent isn't on a DMA-capable bus, and thus really shouldn't have a valid DMA configuration ever.

Then how come a child is DMA capable? MFD takes a physical device node as a parent and creates one of several children with that device as a parent. DMA mask is a property of the device which *does DMA*. Obviously a child is not correct device for that.

Where am I mistaken?

Quoted 10 lines
Quoted 9 lines

I remember we have explicit patches in the past for buses such as PCI and AMBA to set default DMA mask for all physical devices on the respective bus, of course they can individually override it later.

So, this seems to me a paper over the real issue (absence of default DMA mask where it's needed) and devices should explicitly define it if they disagree with default.

If I'm wrong, you really need elaborate commit message much better.

Quoted 8 lines

The problem here is that MFD children are created as platform devices (regardless of what their parent is) and assigned an of_node, at which point they look pretty much indistinguishable from SoC devices created by the of_platform code, that *do* have to be assumed to be DMA-capable to prevent ~90% of existing devicetrees from breaking.

Of course the real fundamental issue is the platform bus itself, but it's way too late to fix that :(

I don't think it's an issue, rather in model you are describing. Or I miss something not so obvious.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#6 lore raw

Re: [PATCH v3 02/16] mfd: mfd-core: Don't overwrite the dma_mask of the child device

Quoted 10 lines · Andy Shevchenko
Quoted 9 lines · Robin Murphy
Quoted 8 lines · Andy Shevchenko
Quoted 6 lines · Michael Walle

Commit cdfee5623290 ("driver core: initialize a default DMA mask for platform device") initialize the DMA of a platform device. But if the parent doesn't have a dma_mask set, for example if it's an I2C device, the dma_mask of the child platform device will be set to zero again. Which leads to many "DMA mask not set" warnings, if the MFD cell has the of_compatible property set.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

I'm wondering why parent doesn't have it.

Because the parent isn't on a DMA-capable bus, and thus really shouldn't have a valid DMA configuration ever.

Then how come a child is DMA capable?

Because it's a platform device, and thanks to decades of legacy we have to assume that any platform devices *is* DMA capable.

Quoted 6 lines

MFD takes a physical device node as a
parent and creates one of several children with that device as a parent. DMA mask is a property of the device which *does DMA*. Obviously a child is not correct device for that.

Where am I mistaken?

In theory you're not, however in practice the driver model doesn't really give us a nice way to express the necessary subtle distinctions between this and other similar-looking but fundamentally different parent-child relationships - if it did, we probably wouldn't need the whole MFD layer in the first place. The logical ideal would be to create the children on the same bus as the parent, but as it is doing that would likely lead to the I2C/SPI/whatever bus code assuming they are first-class devices and open up a whole new world of problems.

For better or worse, the platform bus is the dumping ground for random crap, so we just have to deal with all the abstraction breakage that leaks out of that.

Robin.

Quoted 22 lines
Quoted 10 lines
Quoted 9 lines

I remember we have explicit patches in the past for buses such as PCI and AMBA to set default DMA mask for all physical devices on the respective bus, of course they can individually override it later.

So, this seems to me a paper over the real issue (absence of default DMA mask where it's needed) and devices should explicitly define it if they disagree with default.

If I'm wrong, you really need elaborate commit message much better.

Quoted 8 lines

The problem here is that MFD children are created as platform devices (regardless of what their parent is) and assigned an of_node, at which point they look pretty much indistinguishable from SoC devices created by the of_platform code, that *do* have to be assumed to be DMA-capable to prevent ~90% of existing devicetrees from breaking.

Of course the real fundamental issue is the platform bus itself, but it's way too late to fix that :(

I don't think it's an issue, rather in model you are describing. Or I miss something not so obvious.

#7 lore raw

Re: [PATCH v3 02/16] mfd: mfd-core: Don't overwrite the dma_mask of the child device

Quoted 3 lines · Robin Murphy

For better or worse, the platform bus is the dumping ground for random crap, so we just have to deal with all the abstraction breakage that leaks out of that.

The reason we're using the platform bus for this is that historically people were creating buses which were essentially carbon copies of the platform bus with the name changed and it was felt that rather than duplicate code it was better to just use platform devices with no MMIO ranges defined. If there's some assumptions about DMA for platform devices floating about somewhere it might be reasonable to revisit this and create a non-DMA variant of platform devices since there is a meaningful difference.

#8 lore raw

Re: [PATCH v3 02/16] mfd: mfd-core: Don't overwrite the dma_mask of the child device

Am 2020-04-28 17:25, schrieb Mark Brown:

Quoted 6 lines · Robin Murphy
Quoted 4 lines

For better or worse, the platform bus is the dumping ground for random crap, so we just have to deal with all the abstraction breakage that leaks out of that.

Quoted 8 lines

The reason we're using the platform bus for this is that historically people were creating buses which were essentially carbon copies of the platform bus with the name changed and it was felt that rather than duplicate code it was better to just use platform devices with no MMIO ranges defined. If there's some assumptions about DMA for platform devices floating about somewhere it might be reasonable to revisit this and create a non-DMA variant of platform devices since there is a meaningful difference.

Was there any conclusion? Should I keep or drop this patch in the next version of this series?

Signature · 1 line
-michael
#9 lore raw

PATCH v3 3/16 mfd: mfd-core: match device tree node against reg property

In reply to Michael Walle

There might be multiple children with the device tree compatible, for example if a MFD has multiple instances of the same function. In this case only the first is matched and the other children get a wrong of_node reference.
Add a new option to match also against the unit address of the child node. Additonally, a new helper OF_MFD_CELL_REG is added.

---
 drivers/mfd/mfd-core.c   | 29 ++++++++++++++++++++---------
 include/linux/mfd/core.h | 26 ++++++++++++++++++++------
 2 files changed, 40 insertions(+), 15 deletions(-)
drivers/mfd/mfd-core.c +20 -9
index e735565969b3..4ecb376338f7 100644
@@ -117,6 +117,7 @@ static int mfd_add_device(struct device *parent, int id,
 	struct device_node *np = NULL;
 	int ret = -ENOMEM;
 	int platform_id;
+	u32 of_reg;
 	int r;
 
 	if (id == PLATFORM_DEVID_AUTO)
@@ -151,16 +152,26 @@ static int mfd_add_device(struct device *parent, int id,
 
 	if (parent->of_node && cell->of_compatible) {
 		for_each_child_of_node(parent->of_node, np) {
-			if (of_device_is_compatible(np, cell->of_compatible)) {
-				if (!of_device_is_available(np)) {
-					/* Ignore disabled devices error free */
-					ret = 0;
-					goto fail_alias;
-				}
-				pdev->dev.of_node = np;
-				pdev->dev.fwnode = &np->fwnode;
-				break;
+			if (!of_device_is_compatible(np, cell->of_compatible))
+				continue;
+
+			/* also match the unit address if set */
+			if (cell->of_reg & MFD_OF_REG_VALID) {
+				if (of_property_read_u32(np, "reg", &of_reg))
+					continue;
+				if ((cell->of_reg & MFD_OF_REG_MASK) != of_reg)
+					continue;
 			}
+
+			if (!of_device_is_available(np)) {
+				/* Ignore disabled devices error free */
+				ret = 0;
+				goto fail_alias;
+			}
+
+			pdev->dev.of_node = np;
+			pdev->dev.fwnode = &np->fwnode;
+			break;
 		}
 	}
 
include/linux/mfd/core.h +20 -6
index d01d1299e49d..c2c0ad6b14f3 100644
@@ -13,8 +13,11 @@
 #include <linux/platform_device.h>
 
 #define MFD_RES_SIZE(arr) (sizeof(arr) / sizeof(struct resource))
+#define MFD_OF_REG_VALID	BIT(31)
+#define MFD_OF_REG_MASK		GENMASK(30, 0)
 
-#define MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, _match)\
+#define MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat,	\
+		     _of_reg, _match)					\
 	{								\
 		.name = (_name),					\
 		.resources = (_res),					\
@@ -22,24 +25,32 @@
 		.platform_data = (_pdata),				\
 		.pdata_size = (_pdsize),				\
 		.of_compatible = (_compat),				\
+		.of_reg = (_of_reg),					\
 		.acpi_match = (_match),					\
 		.id = (_id),						\
 	}
 
+#define OF_MFD_CELL_REG(_name, _res, _pdata, _pdsize, _id, _compat,	\
+			_of_reg)					\
+	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat,	\
+		     ((_of_reg) | MFD_OF_REG_VALID), NULL)		\
+
 #define OF_MFD_CELL(_name, _res, _pdata, _pdsize,_id, _compat)		\
-	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, NULL)	\
+	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat,	\
+		     0, NULL)						\
 
 #define ACPI_MFD_CELL(_name, _res, _pdata, _pdsize, _id, _match)	\
-	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, _match)	\
+	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, 0,	\
+		     _match)						\
 
 #define MFD_CELL_BASIC(_name, _res, _pdata, _pdsize, _id)		\
-	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, NULL)	\
+	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, 0, NULL) \
 
 #define MFD_CELL_RES(_name, _res)					\
-	MFD_CELL_ALL(_name, _res, NULL, 0, 0, NULL, NULL)		\
+	MFD_CELL_ALL(_name, _res, NULL, 0, 0, NULL, 0, NULL)		\
 
 #define MFD_CELL_NAME(_name)						\
-	MFD_CELL_ALL(_name, NULL, NULL, 0, 0, NULL, NULL)		\
+	MFD_CELL_ALL(_name, NULL, NULL, 0, 0, NULL, 0, NULL)		\
 
 struct irq_domain;
 struct property_entry;
@@ -78,6 +89,9 @@ struct mfd_cell {
 	 */
 	const char		*of_compatible;
 
+	/* matching the reg property if set */
+	unsigned int		of_reg;
+
 	/* Matches ACPI */
 	const struct mfd_cell_acpi_match	*acpi_match;
 
Signature · 1 line
2.20.1
#10 lore raw

Re: [PATCH v3 03/16] mfd: mfd-core: match device tree node against reg property

Hi Lee,

Am 2020-04-23 19:45, schrieb Michael Walle:

Quoted 6 lines

There might be multiple children with the device tree compatible, for example if a MFD has multiple instances of the same function. In this case only the first is matched and the other children get a wrong of_node reference.
Add a new option to match also against the unit address of the child node. Additonally, a new helper OF_MFD_CELL_REG is added.

Do you think this is feasible? I guess this is the biggest uncertainty for me at the moment in this patch series.

-michael

Quoted 122 lines
---
 drivers/mfd/mfd-core.c   | 29 ++++++++++++++++++++---------
 include/linux/mfd/core.h | 26 ++++++++++++++++++++------
 2 files changed, 40 insertions(+), 15 deletions(-)
drivers/mfd/mfd-core.c +1 -0
index e735565969b3..4ecb376338f7 100644
@@ -117,6 +117,7 @@ static int mfd_add_device(struct device *parent, 
 int id,
 	struct device_node *np = NULL;
 	int ret = -ENOMEM;
 	int platform_id;
+	u32 of_reg;
 	int r;
 
drivers/mfd/mfd-core.c +19 -9
 	if (id == PLATFORM_DEVID_AUTO)
@@ -151,16 +152,26 @@ static int mfd_add_device(struct device *parent, 
 int id,
 
 	if (parent->of_node && cell->of_compatible) {
 		for_each_child_of_node(parent->of_node, np) {
-			if (of_device_is_compatible(np, cell->of_compatible)) {
-				if (!of_device_is_available(np)) {
-					/* Ignore disabled devices error free */
-					ret = 0;
-					goto fail_alias;
-				}
-				pdev->dev.of_node = np;
-				pdev->dev.fwnode = &np->fwnode;
-				break;
+			if (!of_device_is_compatible(np, cell->of_compatible))
+				continue;
+
+			/* also match the unit address if set */
+			if (cell->of_reg & MFD_OF_REG_VALID) {
+				if (of_property_read_u32(np, "reg", &of_reg))
+					continue;
+				if ((cell->of_reg & MFD_OF_REG_MASK) != of_reg)
+					continue;
 			}
+
+			if (!of_device_is_available(np)) {
+				/* Ignore disabled devices error free */
+				ret = 0;
+				goto fail_alias;
+			}
+
+			pdev->dev.of_node = np;
+			pdev->dev.fwnode = &np->fwnode;
+			break;
 		}
 	}
include/linux/mfd/core.h +4 -1
index d01d1299e49d..c2c0ad6b14f3 100644
@@ -13,8 +13,11 @@
 #include <linux/platform_device.h>
 
 #define MFD_RES_SIZE(arr) (sizeof(arr) / sizeof(struct resource))
+#define MFD_OF_REG_VALID	BIT(31)
+#define MFD_OF_REG_MASK		GENMASK(30, 0)
 
-#define MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, 
 _match)\
+#define MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat,	\
+		     _of_reg, _match)					\
 	{								\
 		.name = (_name),					\
include/linux/mfd/core.h +16 -5
 		.resources = (_res),					\
@@ -22,24 +25,32 @@
 		.platform_data = (_pdata),				\
 		.pdata_size = (_pdsize),				\
 		.of_compatible = (_compat),				\
+		.of_reg = (_of_reg),					\
 		.acpi_match = (_match),					\
 		.id = (_id),						\
 	}
 
+#define OF_MFD_CELL_REG(_name, _res, _pdata, _pdsize, _id, _compat,	\
+			_of_reg)					\
+	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat,	\
+		     ((_of_reg) | MFD_OF_REG_VALID), NULL)		\
+
 #define OF_MFD_CELL(_name, _res, _pdata, _pdsize,_id, _compat)		\
-	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, NULL)	\
+	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat,	\
+		     0, NULL)						\
 
 #define ACPI_MFD_CELL(_name, _res, _pdata, _pdsize, _id, _match)	\
-	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, _match)	\
+	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, 0,	\
+		     _match)						\
 
 #define MFD_CELL_BASIC(_name, _res, _pdata, _pdsize, _id)		\
-	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, NULL)	\
+	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, 0, NULL) \
 
 #define MFD_CELL_RES(_name, _res)					\
-	MFD_CELL_ALL(_name, _res, NULL, 0, 0, NULL, NULL)		\
+	MFD_CELL_ALL(_name, _res, NULL, 0, 0, NULL, 0, NULL)		\
 
 #define MFD_CELL_NAME(_name)						\
-	MFD_CELL_ALL(_name, NULL, NULL, 0, 0, NULL, NULL)		\
+	MFD_CELL_ALL(_name, NULL, NULL, 0, 0, NULL, 0, NULL)		\
 
 struct irq_domain;
 struct property_entry;
@@ -78,6 +89,9 @@ struct mfd_cell {
 	 */
 	const char		*of_compatible;
 
+	/* matching the reg property if set */
+	unsigned int		of_reg;
+
 	/* Matches ACPI */
 	const struct mfd_cell_acpi_match	*acpi_match;
#11 lore raw

Re: [PATCH v3 03/16] mfd: mfd-core: match device tree node against reg property

Quoted 11 lines · Michael Walle

Hi Lee,

Am 2020-04-23 19:45, schrieb Michael Walle:

Quoted 6 lines

There might be multiple children with the device tree compatible, for example if a MFD has multiple instances of the same function. In this case only the first is matched and the other children get a wrong of_node reference.
Add a new option to match also against the unit address of the child node. Additonally, a new helper OF_MFD_CELL_REG is added.

Quoted 2 lines

Do you think this is feasible? I guess this is the biggest uncertainty for me at the moment in this patch series.

I think it sounds fine in principle. So long as it doesn't change the existing behaviour when of_reg isn't set.

Quoted 22 lines
Quoted 22 lines
---
 drivers/mfd/mfd-core.c   | 29 ++++++++++++++++++++---------
 include/linux/mfd/core.h | 26 ++++++++++++++++++++------
 2 files changed, 40 insertions(+), 15 deletions(-)
drivers/mfd/mfd-core.c +1 -0
index e735565969b3..4ecb376338f7 100644
@@ -117,6 +117,7 @@ static int mfd_add_device(struct device *parent, int
 id,
 	struct device_node *np = NULL;
 	int ret = -ENOMEM;
 	int platform_id;
+	u32 of_reg;
 	int r;
 
drivers/mfd/mfd-core.c +0 -0
 	if (id == PLATFORM_DEVID_AUTO)
@@ -151,16 +152,26 @@ static int mfd_add_device(struct device *parent,
 int id,
 
Quoted 15 lines
Quoted 5 lines
drivers/mfd/mfd-core.c +0 -3
 	if (parent->of_node && cell->of_compatible) {
 		for_each_child_of_node(parent->of_node, np) {
-			if (of_device_is_compatible(np, cell->of_compatible)) {
-				if (!of_device_is_available(np)) {
-					/* Ignore disabled devices error free */

drivers/mfd/mfd-core.c static int mfd_add_device(struct device *parent, int id, · line 158

Quoted 10 lines
drivers/mfd/mfd-core.c +4 -6
-					ret = 0;
-					goto fail_alias;
-				}
-				pdev->dev.of_node = np;
-				pdev->dev.fwnode = &np->fwnode;
-				break;
+			if (!of_device_is_compatible(np, cell->of_compatible))
+				continue;
+
+			/* also match the unit address if set */

Please use correct grammar in comments (leaving off the full-stop).

Quoted 26 lines
Quoted 26 lines
drivers/mfd/mfd-core.c +15 -0
+			if (cell->of_reg & MFD_OF_REG_VALID) {
+				if (of_property_read_u32(np, "reg", &of_reg))
+					continue;
+				if ((cell->of_reg & MFD_OF_REG_MASK) != of_reg)
+					continue;
 			}
+
+			if (!of_device_is_available(np)) {
+				/* Ignore disabled devices error free */
+				ret = 0;
+				goto fail_alias;
+			}
+
+			pdev->dev.of_node = np;
+			pdev->dev.fwnode = &np->fwnode;
+			break;
 		}
 	}
include/linux/mfd/core.h +0 -0
index d01d1299e49d..c2c0ad6b14f3 100644
@@ -13,8 +13,11 @@
 #include <linux/platform_device.h>
 
Quoted 2 lines

include/linux/mfd/core.h line 16

Quoted 2 lines
include/linux/mfd/core.h +1 -0
 #define MFD_RES_SIZE(arr) (sizeof(arr) / sizeof(struct resource))
+#define MFD_OF_REG_VALID	BIT(31)

What about 64bit platforms?

Quoted 45 lines
Quoted 45 lines
include/linux/mfd/core.h +3 -1
+#define MFD_OF_REG_MASK		GENMASK(30, 0)
 
-#define MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat,
 _match)\
+#define MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat,	\
+		     _of_reg, _match)					\
 	{								\
 		.name = (_name),					\
include/linux/mfd/core.h +13 -5
 		.resources = (_res),					\
@@ -22,24 +25,32 @@
 		.platform_data = (_pdata),				\
 		.pdata_size = (_pdsize),				\
 		.of_compatible = (_compat),				\
+		.of_reg = (_of_reg),					\
 		.acpi_match = (_match),					\
 		.id = (_id),						\
 	}
 
+#define OF_MFD_CELL_REG(_name, _res, _pdata, _pdsize, _id, _compat,	\
+			_of_reg)					\
+	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat,	\
+		     ((_of_reg) | MFD_OF_REG_VALID), NULL)		\
+
 #define OF_MFD_CELL(_name, _res, _pdata, _pdsize,_id, _compat)		\
-	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, NULL)	\
+	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat,	\
+		     0, NULL)						\
 
 #define ACPI_MFD_CELL(_name, _res, _pdata, _pdsize, _id, _match)	\
-	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, _match)	\
+	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, 0,	\
+		     _match)						\
 
 #define MFD_CELL_BASIC(_name, _res, _pdata, _pdsize, _id)		\
-	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, NULL)	\
+	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, 0, NULL) \
 
 #define MFD_CELL_RES(_name, _res)					\
-	MFD_CELL_ALL(_name, _res, NULL, 0, 0, NULL, NULL)		\
+	MFD_CELL_ALL(_name, _res, NULL, 0, 0, NULL, 0, NULL)		\
 
 #define MFD_CELL_NAME(_name)						\
-	MFD_CELL_ALL(_name, NULL, NULL, 0, 0, NULL, NULL)		\
+	MFD_CELL_ALL(_name, NULL, NULL, 0, 0, NULL, 0, NULL)		\
 
Quoted 7 lines

include/linux/mfd/core.h struct mfd_cell { · line 92

Quoted 7 lines
include/linux/mfd/core.h +1 -0
 struct irq_domain;
 struct property_entry;
@@ -78,6 +89,9 @@ struct mfd_cell {
 	 */
 	const char		*of_compatible;
 
+	/* matching the reg property if set */

Proper grammar please.

"OF unit address for device matching"

Quoted 4 lines
Quoted 4 lines
include/linux/mfd/core.h +2 -0
+	unsigned int		of_reg;
+
 	/* Matches ACPI */
 	const struct mfd_cell_acpi_match	*acpi_match;
Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#12 lore raw

Re: [PATCH v3 03/16] mfd: mfd-core: match device tree node against reg property

Am 2020-05-15 12:28, schrieb Lee Jones:

Quoted 85 lines · Michael Walle
Quoted 12 lines

Hi Lee,

Am 2020-04-23 19:45, schrieb Michael Walle:

Quoted 6 lines

There might be multiple children with the device tree compatible, for example if a MFD has multiple instances of the same function. In this case only the first is matched and the other children get a wrong of_node reference.
Add a new option to match also against the unit address of the child node. Additonally, a new helper OF_MFD_CELL_REG is added.

Quoted 2 lines

Do you think this is feasible? I guess this is the biggest uncertainty for me at the moment in this patch series.

I think it sounds fine in principle. So long as it doesn't change the existing behaviour when of_reg isn't set.

Quoted 22 lines
Quoted 22 lines
---
 drivers/mfd/mfd-core.c   | 29 ++++++++++++++++++++---------
 include/linux/mfd/core.h | 26 ++++++++++++++++++++------
 2 files changed, 40 insertions(+), 15 deletions(-)
drivers/mfd/mfd-core.c +1 -0
index e735565969b3..4ecb376338f7 100644
@@ -117,6 +117,7 @@ static int mfd_add_device(struct device *parent, int
 id,
 	struct device_node *np = NULL;
 	int ret = -ENOMEM;
 	int platform_id;
+	u32 of_reg;
 	int r;
 
drivers/mfd/mfd-core.c +0 -0
 	if (id == PLATFORM_DEVID_AUTO)
@@ -151,16 +152,26 @@ static int mfd_add_device(struct device *parent,
 int id,
 
Quoted 15 lines
Quoted 5 lines
drivers/mfd/mfd-core.c +0 -3
 	if (parent->of_node && cell->of_compatible) {
 		for_each_child_of_node(parent->of_node, np) {
-			if (of_device_is_compatible(np, cell->of_compatible)) {
-				if (!of_device_is_available(np)) {
-					/* Ignore disabled devices error free */

drivers/mfd/mfd-core.c static int mfd_add_device(struct device *parent, int id, · line 158

Quoted 10 lines
drivers/mfd/mfd-core.c +4 -6
-					ret = 0;
-					goto fail_alias;
-				}
-				pdev->dev.of_node = np;
-				pdev->dev.fwnode = &np->fwnode;
-				break;
+			if (!of_device_is_compatible(np, cell->of_compatible))
+				continue;
+
+			/* also match the unit address if set */

Please use correct grammar in comments (leaving off the full-stop).

Quoted 26 lines
Quoted 26 lines
drivers/mfd/mfd-core.c +15 -0
+			if (cell->of_reg & MFD_OF_REG_VALID) {
+				if (of_property_read_u32(np, "reg", &of_reg))
+					continue;
+				if ((cell->of_reg & MFD_OF_REG_MASK) != of_reg)
+					continue;
 			}
+
+			if (!of_device_is_available(np)) {
+				/* Ignore disabled devices error free */
+				ret = 0;
+				goto fail_alias;
+			}
+
+			pdev->dev.of_node = np;
+			pdev->dev.fwnode = &np->fwnode;
+			break;
 		}
 	}
include/linux/mfd/core.h +0 -0
index d01d1299e49d..c2c0ad6b14f3 100644
@@ -13,8 +13,11 @@
 #include <linux/platform_device.h>
 
Quoted 4 lines
Quoted 2 lines

include/linux/mfd/core.h line 16

Quoted 2 lines
include/linux/mfd/core.h +1 -0
 #define MFD_RES_SIZE(arr) (sizeof(arr) / sizeof(struct resource))
+#define MFD_OF_REG_VALID	BIT(31)

What about 64bit platforms?

The idea was to have this as a logical number. I.e. for now you may only have one subdevice per unique compatible string. In fact, if you have a look at the ab8500.c, there are multiple "stericsson,ab8500-pwm" subdevices. But there is only one DT node for all three of it. I guess this works as long as you don't use phandles to reference the pwm node in the device tree. Or you don't want to use device tree properties per subdevice (for example the "timeout-sec" of a watchdog device).

So to circumvent this, I thought of having the unit-address (and thus the "reg" property) to differentiate between multiple subdevices. Now there is one special case for me: this board management controller might be upgradable and it might change internally. Thus I came up with that logical numbering of subdevices. Rob doesn't seem to be a fan of that, though. Therefore, having bit 31 as a valid indicator leaves you with 2^31 logical devices, which should be enough ;)

Rob proposed to have the internal offset as the unit-address. But in that case I can also use devm_of_platform_populate() and don't need the OF_MFD_CELL_REG; I'd just parse the reg offset in each individual subdevice driver. But like I said, I wanted to keep the internal offsets out of the device tree.

-michael

Quoted 62 lines
Quoted 46 lines
Quoted 46 lines
include/linux/mfd/core.h +3 -1
+#define MFD_OF_REG_MASK		GENMASK(30, 0)
 
-#define MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat,
 _match)\
+#define MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat,	\
+		     _of_reg, _match)					\
 	{								\
 		.name = (_name),					\
include/linux/mfd/core.h +13 -5
 		.resources = (_res),					\
@@ -22,24 +25,32 @@
 		.platform_data = (_pdata),				\
 		.pdata_size = (_pdsize),				\
 		.of_compatible = (_compat),				\
+		.of_reg = (_of_reg),					\
 		.acpi_match = (_match),					\
 		.id = (_id),						\
 	}
 
+#define OF_MFD_CELL_REG(_name, _res, _pdata, _pdsize, _id, _compat,	\
+			_of_reg)					\
+	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat,	\
+		     ((_of_reg) | MFD_OF_REG_VALID), NULL)		\
+
 #define OF_MFD_CELL(_name, _res, _pdata, _pdsize,_id, _compat)		\
-	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, NULL)	\
+	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat,	\
+		     0, NULL)						\
 
 #define ACPI_MFD_CELL(_name, _res, _pdata, _pdsize, _id, _match)	\
-	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, _match)	\
+	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, 0,	\
+		     _match)						\
 
 #define MFD_CELL_BASIC(_name, _res, _pdata, _pdsize, _id)		\
-	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, NULL)	\
+	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, 0, NULL) \
 
 #define MFD_CELL_RES(_name, _res)					\
-	MFD_CELL_ALL(_name, _res, NULL, 0, 0, NULL, NULL)		\
+	MFD_CELL_ALL(_name, _res, NULL, 0, 0, NULL, 0, NULL)		\
 
 #define MFD_CELL_NAME(_name)						\
-	MFD_CELL_ALL(_name, NULL, NULL, 0, 0, NULL, NULL)		\
+	MFD_CELL_ALL(_name, NULL, NULL, 0, 0, NULL, 0, NULL)		\
 
Quoted 7 lines

include/linux/mfd/core.h struct mfd_cell { · line 92

Quoted 7 lines
include/linux/mfd/core.h +1 -0
 struct irq_domain;
 struct property_entry;
@@ -78,6 +89,9 @@ struct mfd_cell {
 	 */
 	const char		*of_compatible;
 
+	/* matching the reg property if set */

Proper grammar please.

"OF unit address for device matching"

Quoted 4 lines
Quoted 4 lines
include/linux/mfd/core.h +2 -0
+	unsigned int		of_reg;
+
 	/* Matches ACPI */
 	const struct mfd_cell_acpi_match	*acpi_match;
#13 lore raw

Re: [PATCH v3 03/16] mfd: mfd-core: match device tree node against reg property

Quoted 25 lines · Michael Walle

Am 2020-05-15 12:28, schrieb Lee Jones:

Quoted 24 lines · Michael Walle
Quoted 12 lines

Hi Lee,

Am 2020-04-23 19:45, schrieb Michael Walle:

Quoted 6 lines

There might be multiple children with the device tree compatible, for example if a MFD has multiple instances of the same function. In this case only the first is matched and the other children get a wrong of_node reference.
Add a new option to match also against the unit address of the child node. Additonally, a new helper OF_MFD_CELL_REG is added.

Quoted 2 lines

Do you think this is feasible? I guess this is the biggest uncertainty for me at the moment in this patch series.

I think it sounds fine in principle. So long as it doesn't change the existing behaviour when of_reg isn't set.

Quoted 5 lines
Quoted 5 lines
---
 drivers/mfd/mfd-core.c   | 29 ++++++++++++++++++++---------
 include/linux/mfd/core.h | 26 ++++++++++++++++++++------
 2 files changed, 40 insertions(+), 15 deletions(-)

[...]

Quoted 28 lines
Quoted 11 lines
Quoted 9 lines

include/linux/mfd/core.h line 16

Quoted 9 lines
include/linux/mfd/core.h +1 -0
index d01d1299e49d..c2c0ad6b14f3 100644
@@ -13,8 +13,11 @@
 #include <linux/platform_device.h>
 
 #define MFD_RES_SIZE(arr) (sizeof(arr) / sizeof(struct resource))
+#define MFD_OF_REG_VALID	BIT(31)

What about 64bit platforms?

The idea was to have this as a logical number. I.e. for now you may only have one subdevice per unique compatible string. In fact, if you have a look at the ab8500.c, there are multiple "stericsson,ab8500-pwm" subdevices. But there is only one DT node for all three of it. I guess this works as long as you don't use phandles to reference the pwm node in the device tree. Or you don't want to use device tree properties per subdevice (for example the "timeout-sec" of a watchdog device).

So to circumvent this, I thought of having the unit-address (and thus the "reg" property) to differentiate between multiple subdevices. Now there is one special case for me: this board management controller might be upgradable and it might change internally. Thus I came up with that logical numbering of subdevices. Rob doesn't seem to be a fan of that, though. Therefore, having bit 31 as a valid indicator leaves you with 2^31 logical devices, which should be enough ;)

Quoted 5 lines

Rob proposed to have the internal offset as the unit-address. But in that case I can also use devm_of_platform_populate() and don't need the OF_MFD_CELL_REG; I'd just parse the reg offset in each individual subdevice driver. But like I said, I wanted to keep the internal offsets out of the device tree.

Oh, I see what you're doing.

So you're adding an arbitrary ID to the device's reg property in DT?

How is this not a hack?

Why don't you use the full address for identification?

Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#14 lore raw

Re: [PATCH v3 03/16] mfd: mfd-core: match device tree node against reg property

Am 2020-05-26 09:24, schrieb Lee Jones:

Quoted 64 lines · Michael Walle
Quoted 26 lines

Am 2020-05-15 12:28, schrieb Lee Jones:

Quoted 24 lines · Michael Walle
Quoted 12 lines

Hi Lee,

Am 2020-04-23 19:45, schrieb Michael Walle:

Quoted 6 lines

There might be multiple children with the device tree compatible, for example if a MFD has multiple instances of the same function. In this case only the first is matched and the other children get a wrong of_node reference.
Add a new option to match also against the unit address of the child node. Additonally, a new helper OF_MFD_CELL_REG is added.

Quoted 2 lines

Do you think this is feasible? I guess this is the biggest uncertainty for me at the moment in this patch series.

I think it sounds fine in principle. So long as it doesn't change the existing behaviour when of_reg isn't set.

Quoted 5 lines
Quoted 5 lines
---
 drivers/mfd/mfd-core.c   | 29 ++++++++++++++++++++---------
 include/linux/mfd/core.h | 26 ++++++++++++++++++++------
 2 files changed, 40 insertions(+), 15 deletions(-)

[...]

Quoted 28 lines
Quoted 11 lines
Quoted 9 lines

include/linux/mfd/core.h line 16

Quoted 9 lines
include/linux/mfd/core.h +1 -0
index d01d1299e49d..c2c0ad6b14f3 100644
@@ -13,8 +13,11 @@
 #include <linux/platform_device.h>
 
 #define MFD_RES_SIZE(arr) (sizeof(arr) / sizeof(struct resource))
+#define MFD_OF_REG_VALID	BIT(31)

What about 64bit platforms?

The idea was to have this as a logical number. I.e. for now you may only have one subdevice per unique compatible string. In fact, if you have a look at the ab8500.c, there are multiple "stericsson,ab8500-pwm" subdevices. But there is only one DT node for all three of it. I guess this works as long as you don't use phandles to reference the pwm node in the device tree. Or you don't want to use device tree properties per subdevice (for example the "timeout-sec" of a watchdog device).

So to circumvent this, I thought of having the unit-address (and thus the "reg" property) to differentiate between multiple subdevices. Now there is one special case for me: this board management controller might be upgradable and it might change internally. Thus I came up with that logical numbering of subdevices. Rob doesn't seem to be a fan of that, though. Therefore, having bit 31 as a valid indicator leaves you with 2^31 logical devices, which should be enough ;)

Quoted 5 lines

Rob proposed to have the internal offset as the unit-address. But in that case I can also use devm_of_platform_populate() and don't need the OF_MFD_CELL_REG; I'd just parse the reg offset in each individual subdevice driver. But like I said, I wanted to keep the internal offsets out of the device tree.

Quoted 3 lines

Oh, I see what you're doing.

So you're adding an arbitrary ID to the device's reg property in DT?

Yes.

Quoted 1 line

How is this not a hack?

Well IMHO this is not more or less a hack as the current of_node handling of MFD devices, which happens to work only because there is only one device per compatible string (or it doesn't really work, like in the stericsson,ab8500-pwm case). The of_node is assigned according to the compatible string, just like in my case, only that I have two subdevices with the same compatible string.

Quoted 1 line

Why don't you use the full address for identification?

Like I said, in the long term I would like to have support for different versions of the board management controller without having to change the device tree and have device tree bindings for the subdevices at the same time. But it seems, that this is not possible and I guess I have to bite the bullet and may need to provide another device tree if the controller might be updated.

-michael

#15 lore raw

Re: [PATCH v3 03/16] mfd: mfd-core: match device tree node against reg property

Quoted 1 line · Michael Walle

Am 2020-05-26 09:24, schrieb Lee Jones:

...

Quoted 5 lines

Like I said, in the long term I would like to have support for different versions of the board management controller

without having to change the device tree and have device tree bindings for the subdevices at the same time.

But isn't device tree to describe *very specific platform* rather than *class of platforms*?

Quoted 3 lines

But it seems, that this is not possible
and I guess I have to bite the bullet and may need to provide another device tree if the controller might be updated.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#16 lore raw

Re: [PATCH v3 03/16] mfd: mfd-core: match device tree node against reg property

Quoted 5 lines · Andy Shevchenko
Quoted 1 line · Michael Walle

Am 2020-05-26 09:24, schrieb Lee Jones:

...

Quoted 8 lines
Quoted 5 lines

Like I said, in the long term I would like to have support for different versions of the board management controller

without having to change the device tree and have device tree bindings for the subdevices at the same time.

But isn't device tree to describe *very specific platform* rather than *class of platforms*?

Yes. Device Tree describes the hardware.

If the hardware changes, so must the Device Tree.

Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#17 lore raw

Re: [PATCH v3 03/16] mfd: mfd-core: match device tree node against reg property

In reply to Michael Walle
Quoted 12 lines · Michael Walle

Am 2020-05-15 12:28, schrieb Lee Jones:

Quoted 11 lines · Michael Walle
Quoted 10 lines

Hi Lee,

Am 2020-04-23 19:45, schrieb Michael Walle:

Quoted 6 lines

There might be multiple children with the device tree compatible, for example if a MFD has multiple instances of the same function. In this case only the first is matched and the other children get a wrong of_node reference.
Add a new option to match also against the unit address of the child node. Additonally, a new helper OF_MFD_CELL_REG is added.

[...]

Quoted 12 lines
Quoted 11 lines
Quoted 9 lines

include/linux/mfd/core.h line 16

Quoted 9 lines
include/linux/mfd/core.h +1 -0
index d01d1299e49d..c2c0ad6b14f3 100644
@@ -13,8 +13,11 @@
 #include <linux/platform_device.h>
 
 #define MFD_RES_SIZE(arr) (sizeof(arr) / sizeof(struct resource))
+#define MFD_OF_REG_VALID	BIT(31)

What about 64bit platforms?

Quoted 7 lines

The idea was to have this as a logical number. I.e. for now you may only have one subdevice per unique compatible string. In fact, if you have a look at the ab8500.c, there are multiple "stericsson,ab8500-pwm" subdevices. But there is only one DT node for all three of it. I guess this works as long as you don't use phandles to reference the pwm node in the device tree. Or you don't want to use device tree properties per subdevice (for example the "timeout-sec" of a watchdog device).

This is not a good example, as the "stericsson,ab8500-pwm" is legitimate. Here we are registering 3 potential devices, but only instantiating 1 of them.

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

Re: [PATCH v3 03/16] mfd: mfd-core: match device tree node against reg property

Am 2020-06-08 16:24, schrieb Lee Jones:

Quoted 36 lines · Michael Walle
Quoted 12 lines

Am 2020-05-15 12:28, schrieb Lee Jones:

Quoted 11 lines · Michael Walle
Quoted 10 lines

Hi Lee,

Am 2020-04-23 19:45, schrieb Michael Walle:

Quoted 6 lines

There might be multiple children with the device tree compatible, for example if a MFD has multiple instances of the same function. In this case only the first is matched and the other children get a wrong of_node reference.
Add a new option to match also against the unit address of the child node. Additonally, a new helper OF_MFD_CELL_REG is added.

[...]

Quoted 12 lines
Quoted 11 lines
Quoted 9 lines

include/linux/mfd/core.h line 16

Quoted 9 lines
include/linux/mfd/core.h +1 -0
index d01d1299e49d..c2c0ad6b14f3 100644
@@ -13,8 +13,11 @@
 #include <linux/platform_device.h>
 
 #define MFD_RES_SIZE(arr) (sizeof(arr) / sizeof(struct resource))
+#define MFD_OF_REG_VALID	BIT(31)

What about 64bit platforms?

Quoted 7 lines

The idea was to have this as a logical number. I.e. for now you may only have one subdevice per unique compatible string. In fact, if you have a look at the ab8500.c, there are multiple "stericsson,ab8500-pwm" subdevices. But there is only one DT node for all three of it. I guess this works as long as you don't use phandles to reference the pwm node in the device tree. Or you don't want to use device tree properties per subdevice (for example the "timeout-sec" of a watchdog device).

Quoted 3 lines

This is not a good example, as the "stericsson,ab8500-pwm" is legitimate. Here we are registering 3 potential devices, but only instantiating 1 of them.

Mh?

static const struct mfd_cell ab8500_devs[] = {
..

       OF_MFD_CELL("ab8500-pwm",
                    NULL, NULL, 0, 1, "stericsson,ab8500-pwm"),
        OF_MFD_CELL("ab8500-pwm",
                    NULL, NULL, 0, 2, "stericsson,ab8500-pwm"),
        OF_MFD_CELL("ab8500-pwm",
                    NULL, NULL, 0, 3, "stericsson,ab8500-pwm"),

..
}

And in pwm-ab8500.c there are three offsets based on the pdev->id.

Am I missing something here?

Signature · 1 line
-michael
#19 lore raw

Re: [PATCH v3 03/16] mfd: mfd-core: match device tree node against reg property

Quoted 53 lines · Michael Walle

Am 2020-06-08 16:24, schrieb Lee Jones:

Quoted 38 lines · Michael Walle
Quoted 12 lines

Am 2020-05-15 12:28, schrieb Lee Jones:

Quoted 11 lines · Michael Walle
Quoted 10 lines

Hi Lee,

Am 2020-04-23 19:45, schrieb Michael Walle:

Quoted 6 lines

There might be multiple children with the device tree compatible, for example if a MFD has multiple instances of the same function. In this case only the first is matched and the other children get a wrong of_node reference.
Add a new option to match also against the unit address of the child node. Additonally, a new helper OF_MFD_CELL_REG is added.

[...]

Quoted 12 lines
Quoted 11 lines
Quoted 9 lines

include/linux/mfd/core.h line 16

Quoted 9 lines
include/linux/mfd/core.h +1 -0
index d01d1299e49d..c2c0ad6b14f3 100644
@@ -13,8 +13,11 @@
 #include <linux/plataorm_device.h>
 
 #define MFD_RES_SIZE(arr) (sizeof(arr) / sizeof(struct resource))
+#define MFD_OF_REG_VALID	BIT(31)

What about 64bit platforms?

Quoted 9 lines

The idea was to have this as a logical number. I.e. for now you may only
have one subdevice per unique compatible string. In fact, if you have a
look at the ab8500.c, there are multiple "stericsson,ab8500-pwm" subdevices. But there is only one DT node for all three of it. I guess this works as long as you don't use phandles to reference the pwm node in the device tree. Or you don't want to use device tree properties per subdevice (for example the "timeout-sec" of a watchdog device).

Quoted 3 lines

This is not a good example, as the "stericsson,ab8500-pwm" is legitimate. Here we are registering 3 potential devices, but only instantiating 1 of them.

Mh?

static const struct mfd_cell ab8500_devs[] = {
..

       OF_MFD_CELL("ab8500-pwm",
                    NULL, NULL, 0, 1, "stericsson,ab8500-pwm"),
        OF_MFD_CELL("ab8500-pwm",
                    NULL, NULL, 0, 2, "stericsson,ab8500-pwm"),
        OF_MFD_CELL("ab8500-pwm",
                    NULL, NULL, 0, 3, "stericsson,ab8500-pwm"),
Quoted 6 lines

..
}

And in pwm-ab8500.c there are three offsets based on the pdev->id.

Am I missing something here?

Scrap what I said above.

For some reason I had of_platform_populate() in my head.

This will register and enumerate 3 devices.

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

PATCH v3 4/16 dt-bindings: mfd: Add bindings for sl28cpld

In reply to Michael Walle

This adds device tree bindings for the board management controller found on the Kontron SMARC-sAL28 board.

---
 .../bindings/gpio/kontron,sl28cpld-gpio.yaml  |  51 ++++++
 .../hwmon/kontron,sl28cpld-hwmon.yaml         |  27 +++
 .../bindings/mfd/kontron,sl28cpld.yaml        | 162 ++++++++++++++++++
 .../bindings/pwm/kontron,sl28cpld-pwm.yaml    |  35 ++++
 .../watchdog/kontron,sl28cpld-wdt.yaml        |  35 ++++
 5 files changed, 310 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/gpio/kontron,sl28cpld-gpio.yaml
 create mode 100644 Documentation/devicetree/bindings/hwmon/kontron,sl28cpld-hwmon.yaml
 create mode 100644 Documentation/devicetree/bindings/mfd/kontron,sl28cpld.yaml
 create mode 100644 Documentation/devicetree/bindings/pwm/kontron,sl28cpld-pwm.yaml
 create mode 100644 Documentation/devicetree/bindings/watchdog/kontron,sl28cpld-wdt.yaml
Documentation/devicetree/bindings/gpio/kontron,sl28cpld-gpio.yaml new file +51 -0
new file mode 100644
index 000000000000..291ca116743d
@@ -0,0 +1,51 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/gpio/kontron,sl28cpld-gpio.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: GPIO driver for the sl28cpld board management controller
+
+maintainers:
+  - Michael Walle <[email protected]>
+
+description: |
+  This module is part of the sl28cpld multi-function device. For more
+  details see Documentation/devicetree/bindings/mfd/kontron,sl28cpld.yaml.
+
+  There are three flavors of the GPIO controller, one full featured
+  input/output with interrupt support (kontron,sl28cpld-gpio), one
+  output-only (kontron,sl28-gpo) and one input-only (kontron,sl28-gpi).
+
+  Each controller supports 8 GPIO lines.
+
+properties:
+  compatible:
+    enum:
+      - kontron,sl28cpld-gpio
+      - kontron,sl28cpld-gpi
+      - kontron,sl28cpld-gpo
+
+  reg:
+    maxItems: 1
+
+  "#interrupt-cells":
+    const: 2
+
+  interrupt-controller: true
+
+  "#gpio-cells":
+    const: 2
+
+  gpio-controller: true
+
+  gpio-line-names:
+      minItems: 1
+      maxItems: 8
+
+required:
+  - compatible
+  - "#gpio-cells"
+  - gpio-controller
+
+additionalProperties: false
Documentation/devicetree/bindings/hwmon/kontron,sl28cpld-hwmon.yaml new file +27 -0
new file mode 100644
index 000000000000..1cebd61c6c32
@@ -0,0 +1,27 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/hwmon/kontron,sl28cpld-hwmon.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Hardware monitoring driver for the sl28cpld board management controller
+
+maintainers:
+  - Michael Walle <[email protected]>
+
+description: |
+  This module is part of the sl28cpld multi-function device. For more
+  details see Documentation/devicetree/bindings/mfd/kontron,sl28cpld.yaml.
+
+properties:
+  compatible:
+    enum:
+      - kontron,sl28cpld-fan
+
+  reg:
+    maxItems: 1
+
+required:
+  - compatible
+
+additionalProperties: false
Documentation/devicetree/bindings/mfd/kontron,sl28cpld.yaml new file +162 -0

162 lines not on this page · raw message

Documentation/devicetree/bindings/pwm/kontron,sl28cpld-pwm.yaml new file +35 -0
new file mode 100644
index 000000000000..02fe88c30233
@@ -0,0 +1,35 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/pwm/kontron,sl28cpld-pwm.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: PWM driver for the sl28cpld board management controller
+
+maintainers:
+  - Michael Walle <[email protected]>
+
+description: |
+  This module is part of the sl28cpld multi-function device. For more
+  details see Documentation/devicetree/bindings/mfd/kontron,sl28cpld.yaml.
+
+  The controller supports one PWM channel and supports only four distinct
+  frequencies (250Hz, 500Hz, 1kHz, 2kHz).
+
+allOf:
+  - $ref: pwm.yaml#
+
+properties:
+  compatible:
+    const: kontron,sl28cpld-pwm
+
+  reg:
+    maxItems: 1
+
+  "#pwm-cells":
+    const: 2
+
+required:
+  - compatible
+
+additionalProperties: false
Documentation/devicetree/bindings/watchdog/kontron,sl28cpld-wdt.yaml new file +35 -0
new file mode 100644
index 000000000000..dd6559f2973a
@@ -0,0 +1,35 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/watchdog/kontron,sl28cpld-wdt.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Watchdog driver for the sl28cpld board management controller
+
+maintainers:
+  - Michael Walle <[email protected]>
+
+description: |
+  This module is part of the sl28cpld multi-function device. For more
+  details see Documentation/devicetree/bindings/mfd/kontron,sl28cpld.yaml.
+
+allOf:
+  - $ref: watchdog.yaml#
+
+properties:
+  compatible:
+    const: kontron,sl28cpld-wdt
+
+  reg:
+    maxItems: 1
+
+  kontron,assert-wdt-timeout-pin:
+    description: The SMARC standard defines a WDT_TIME_OUT# pin. If this
+      property is set, this output will be pulsed when the watchdog bites
+      and the system resets.
+    type: boolean
+
+required:
+  - compatible
+
+additionalProperties: false
Signature · 1 line
2.20.1
#21 lore raw

Re: [PATCH v3 04/16] dt-bindings: mfd: Add bindings for sl28cpld

Quoted 2 lines · Michael Walle

This adds device tree bindings for the board management controller found on the Kontron SMARC-sAL28 board.

I think it should be independent patches (same way as you do for drivers).

Quoted 5 lines
 .../bindings/gpio/kontron,sl28cpld-gpio.yaml  |  51 ++++++
 .../hwmon/kontron,sl28cpld-hwmon.yaml         |  27 +++
 .../bindings/mfd/kontron,sl28cpld.yaml        | 162 ++++++++++++++++++
 .../bindings/pwm/kontron,sl28cpld-pwm.yaml    |  35 ++++
 .../watchdog/kontron,sl28cpld-wdt.yaml        |  35 ++++
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#22 lore raw

Re: [PATCH v3 04/16] dt-bindings: mfd: Add bindings for sl28cpld

Am 2020-04-28 14:48, schrieb Andy Shevchenko:

Quoted 5 lines · Michael Walle
Quoted 2 lines

This adds device tree bindings for the board management controller found on the Kontron SMARC-sAL28 board.

I think it should be independent patches (same way as you do for drivers).

It used to be several patches but Rob suggested to put it into one:
https://lore.kernel.org/linux-devicetree/20200330223535.GA31402@bogus/

-michael

Quoted 7 lines
Quoted 7 lines
 .../bindings/gpio/kontron,sl28cpld-gpio.yaml  |  51 ++++++
 .../hwmon/kontron,sl28cpld-hwmon.yaml         |  27 +++
 .../bindings/mfd/kontron,sl28cpld.yaml        | 162 
++++++++++++++++++
 .../bindings/pwm/kontron,sl28cpld-pwm.yaml    |  35 ++++
 .../watchdog/kontron,sl28cpld-wdt.yaml        |  35 ++++
#23 lore raw

Re: [PATCH v3 04/16] dt-bindings: mfd: Add bindings for sl28cpld

Quoted 11 lines · Michael Walle

Am 2020-04-28 14:48, schrieb Andy Shevchenko:

Quoted 7 lines · Michael Walle
Quoted 3 lines

This adds device tree bindings for the board management controller found
on the Kontron SMARC-sAL28 board.

I think it should be independent patches (same way as you do for drivers).

It used to be several patches but Rob suggested to put it into one:
https://lore.kernel.org/linux-devicetree/20200330223535.GA31402@bogus/

Ah, okay.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#24 lore raw

PATCH v3 5/16 mfd: Add support for Kontron sl28cpld management controller

In reply to Michael Walle

This patch adds core support for the board management controller found on the SMARC-sAL28 board. It consists of the following functions:
- watchdog
- GPIO controller
- PWM controller
- fan sensor
- interrupt controller

At the moment, this controller is used on the Kontron SMARC-sAL28 board.

Please note that the MFD driver is defined as bool in the Kconfig because the next patch will add interrupt support.

---
 drivers/mfd/Kconfig    |  19 +++++
 drivers/mfd/Makefile   |   2 +
 drivers/mfd/sl28cpld.c | 153 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 174 insertions(+)
 create mode 100644 drivers/mfd/sl28cpld.c
drivers/mfd/Kconfig +19 -0
index 0a59249198d3..be0c8d93c526 100644
@@ -2060,5 +2060,24 @@ config SGI_MFD_IOC3
 	  If you have an SGI Origin, Octane, or a PCI IOC3 card,
 	  then say Y. Otherwise say N.
 
+config MFD_SL28CPLD
+	bool "Kontron sl28 core driver"
+	depends on I2C=y
+	depends on OF
+	select REGMAP_I2C
+	select MFD_CORE
+	help
+	  This option enables support for the board management controller
+	  found on the Kontron sl28 CPLD. You have to select individual
+	  functions, such as watchdog, GPIO, etc, under the corresponding menus
+	  in order to enable them.
+
+	  Currently supported boards are:
+
+		Kontron SMARC-sAL28
+
+	  To compile this driver as a module, choose M here: the module will be
+	  called sl28cpld.
+
 endmenu
 endif
drivers/mfd/Makefile +2 -0
index f935d10cbf0f..9bc38863b9c7 100644
@@ -259,3 +259,5 @@ obj-$(CONFIG_MFD_ROHM_BD718XX)	+= rohm-bd718x7.o
 obj-$(CONFIG_MFD_STMFX) 	+= stmfx.o
 
 obj-$(CONFIG_SGI_MFD_IOC3)	+= ioc3.o
+
+obj-$(CONFIG_MFD_SL28CPLD)	+= sl28cpld.o
drivers/mfd/sl28cpld.c new file +153 -0

153 lines not on this page · raw message

Signature · 1 line
2.20.1
#25 lore raw

Re: [PATCH v3 05/16] mfd: Add support for Kontron sl28cpld management controller

Quoted 7 lines · Michael Walle

This patch adds core support for the board management controller found on the SMARC-sAL28 board. It consists of the following functions:
- watchdog
- GPIO controller
- PWM controller
- fan sensor
- interrupt controller

...

drivers/mfd/Makefile obj-$(CONFIG_MFD_ROHM_BD718XX) += rohm-bd718x7.o · line 263

Quoted 5 lines

obj-$(CONFIG_MFD_STMFX) += stmfx.o

obj-$(CONFIG_SGI_MFD_IOC3) += ioc3.o

drivers/mfd/Makefile +2 -0
+
+obj-$(CONFIG_MFD_SL28CPLD)	+= sl28cpld.o

Perhaps keep an order?

...

drivers/mfd/sl28cpld.c line 131

Quoted 1 line
drivers/mfd/sl28cpld.c new file +1 -0
+	return devm_mfd_add_devices(dev, -1, sl28cpld_devs,

-1 has its own definition.

Quoted 3 lines
drivers/mfd/sl28cpld.c new file +3 -0
+				    ARRAY_SIZE(sl28cpld_devs), NULL,
+				    i2c->irq, NULL);
+}
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#26 lore raw

Re: [PATCH v3 05/16] mfd: Add support for Kontron sl28cpld management controller

Am 2020-04-28 14:50, schrieb Andy Shevchenko:

Quoted 11 lines · Michael Walle
Quoted 7 lines

This patch adds core support for the board management controller found on the SMARC-sAL28 board. It consists of the following functions:
- watchdog
- GPIO controller
- PWM controller
- fan sensor
- interrupt controller

...

Quoted 7 lines

drivers/mfd/Makefile obj-$(CONFIG_MFD_ROHM_BD718XX) += rohm-bd718x7.o · line 263

Quoted 5 lines

obj-$(CONFIG_MFD_STMFX) += stmfx.o

obj-$(CONFIG_SGI_MFD_IOC3) += ioc3.o

drivers/mfd/Makefile +2 -0
+
+obj-$(CONFIG_MFD_SL28CPLD)	+= sl28cpld.o

Perhaps keep an order?

I don't see any order in that makefile. Looked to me like every new file was added at the end.

Quoted 6 lines

...

drivers/mfd/sl28cpld.c line 131

Quoted 1 line
drivers/mfd/sl28cpld.c new file +1 -0
+	return devm_mfd_add_devices(dev, -1, sl28cpld_devs,

-1 has its own definition.

ok, I'll replace that by PLATFORM_DEVID_NONE.

Thanks,
-michael

Quoted 4 lines
Quoted 4 lines
drivers/mfd/sl28cpld.c new file +3 -0
+				    ARRAY_SIZE(sl28cpld_devs), NULL,
+				    i2c->irq, NULL);
+}
#27 lore raw

Re: [PATCH v3 05/16] mfd: Add support for Kontron sl28cpld management controller

Quoted 14 lines · Michael Walle

Am 2020-04-28 14:50, schrieb Andy Shevchenko:

Quoted 13 lines · Michael Walle
Quoted 7 lines

This patch adds core support for the board management controller found on the SMARC-sAL28 board. It consists of the following functions:
- watchdog
- GPIO controller
- PWM controller
- fan sensor
- interrupt controller

...

Quoted 2 lines

obj-$(CONFIG_MFD_STMFX) += stmfx.o

Quoted 8 lines
Quoted 5 lines

drivers/mfd/Makefile obj-$(CONFIG_MFD_ROHM_BD718XX) += rohm-bd718x7.o · line 263

Quoted 3 lines

obj-$(CONFIG_SGI_MFD_IOC3) += ioc3.o

drivers/mfd/Makefile +2 -0
+
+obj-$(CONFIG_MFD_SL28CPLD)	+= sl28cpld.o

Perhaps keep an order?

I don't see any order in that makefile. Looked to me like every new file was added at the end.

Okay, just didn't note from above context.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#28 lore raw

Re: [PATCH v3 05/16] mfd: Add support for Kontron sl28cpld management controller

Quoted 21 lines · Andy Shevchenko
Quoted 20 lines · Michael Walle

Am 2020-04-28 14:50, schrieb Andy Shevchenko:

Quoted 18 lines · Michael Walle
Quoted 7 lines

This patch adds core support for the board management controller found on the SMARC-sAL28 board. It consists of the following functions:
- watchdog
- GPIO controller
- PWM controller
- fan sensor
- interrupt controller

...

drivers/mfd/Makefile obj-$(CONFIG_MFD_ROHM_BD718XX) += rohm-bd718x7.o · line 263

Quoted 5 lines

obj-$(CONFIG_MFD_STMFX) += stmfx.o

obj-$(CONFIG_SGI_MFD_IOC3) += ioc3.o

drivers/mfd/Makefile +2 -0
+
+obj-$(CONFIG_MFD_SL28CPLD)	+= sl28cpld.o

Perhaps keep an order?

Quoted 4 lines
Quoted 2 lines

I don't see any order in that makefile. Looked to me like every new file was added at the end.

Okay, just didn't note from above context.

Yes, this is historical. I've been meaning to visit this for ~7 years!

Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
maintainer
#29 lore raw

Re: [PATCH v3 05/16] mfd: Add support for Kontron sl28cpld management controller

In reply to Michael Walle
Quoted 81 lines · Michael Walle

This patch adds core support for the board management controller found on the SMARC-sAL28 board. It consists of the following functions:
- watchdog
- GPIO controller
- PWM controller
- fan sensor
- interrupt controller

At the moment, this controller is used on the Kontron SMARC-sAL28 board.

Please note that the MFD driver is defined as bool in the Kconfig because the next patch will add interrupt support.

---
 drivers/mfd/Kconfig    |  19 +++++
 drivers/mfd/Makefile   |   2 +
 drivers/mfd/sl28cpld.c | 153 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 174 insertions(+)
 create mode 100644 drivers/mfd/sl28cpld.c
drivers/mfd/Kconfig +19 -0
index 0a59249198d3..be0c8d93c526 100644
@@ -2060,5 +2060,24 @@ config SGI_MFD_IOC3
 	  If you have an SGI Origin, Octane, or a PCI IOC3 card,
 	  then say Y. Otherwise say N.
 
+config MFD_SL28CPLD
+	bool "Kontron sl28 core driver"
+	depends on I2C=y
+	depends on OF
+	select REGMAP_I2C
+	select MFD_CORE
+	help
+	  This option enables support for the board management controller
+	  found on the Kontron sl28 CPLD. You have to select individual
+	  functions, such as watchdog, GPIO, etc, under the corresponding menus
+	  in order to enable them.
+
+	  Currently supported boards are:
+
+		Kontron SMARC-sAL28
+
+	  To compile this driver as a module, choose M here: the module will be
+	  called sl28cpld.
+
 endmenu
 endif
drivers/mfd/Makefile +2 -0
index f935d10cbf0f..9bc38863b9c7 100644
@@ -259,3 +259,5 @@ obj-$(CONFIG_MFD_ROHM_BD718XX)	+= rohm-bd718x7.o
 obj-$(CONFIG_MFD_STMFX) 	+= stmfx.o
 
 obj-$(CONFIG_SGI_MFD_IOC3)	+= ioc3.o
+
+obj-$(CONFIG_MFD_SL28CPLD)	+= sl28cpld.o
drivers/mfd/sl28cpld.c new file +15 -0
new file mode 100644
index 000000000000..1e5860cc7ffc
@@ -0,0 +1,153 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * MFD core for the sl28cpld.
+ *
+ * Copyright 2019 Kontron Europe GmbH
+ */
+
+#include <linux/i2c.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/mfd/core.h>
+#include <linux/module.h>
+#include <linux/of_platform.h>
+#include <linux/regmap.h>
+

drivers/mfd/sl28cpld.c line 25

Quoted 10 lines
drivers/mfd/sl28cpld.c new file +10 -0
+#define SL28CPLD_VERSION	0x03
+#define SL28CPLD_WATCHDOG_BASE	0x04
+#define SL28CPLD_HWMON_FAN_BASE	0x0b
+#define SL28CPLD_PWM0_BASE	0x0c
+#define SL28CPLD_PWM1_BASE	0x0e
+#define SL28CPLD_GPIO0_BASE	0x10
+#define SL28CPLD_GPIO1_BASE	0x15
+#define SL28CPLD_GPO_BASE	0x1a
+#define SL28CPLD_GPI_BASE	0x1b
+#define SL28CPLD_INTC_BASE	0x1c

If you want to use 'reg' in the binding, these are the numbers you should be using rather than making up numbering!

However, I still don't think you need any child nodes. All the data in the DT binding is right here in the driver already. There's no advantage to putting child nodes in DT, because this driver still has to be updated if you add more nodes.

Rob

#30 lore raw

Re: [PATCH v3 05/16] mfd: Add support for Kontron sl28cpld management controller

Am 2020-05-11 23:13, schrieb Rob Herring:

Quoted 90 lines · Michael Walle
Quoted 89 lines

This patch adds core support for the board management controller found on the SMARC-sAL28 board. It consists of the following functions:
- watchdog
- GPIO controller
- PWM controller
- fan sensor
- interrupt controller

At the moment, this controller is used on the Kontron SMARC-sAL28 board.

Please note that the MFD driver is defined as bool in the Kconfig because the next patch will add interrupt support.

---
 drivers/mfd/Kconfig    |  19 +++++
 drivers/mfd/Makefile   |   2 +
 drivers/mfd/sl28cpld.c | 153 
+++++++++++++++++++++++++++++++++++++++++
 3 files changed, 174 insertions(+)
 create mode 100644 drivers/mfd/sl28cpld.c
drivers/mfd/Kconfig +10 -0
index 0a59249198d3..be0c8d93c526 100644
@@ -2060,5 +2060,24 @@ config SGI_MFD_IOC3
 	  If you have an SGI Origin, Octane, or a PCI IOC3 card,
 	  then say Y. Otherwise say N.
 
+config MFD_SL28CPLD
+	bool "Kontron sl28 core driver"
+	depends on I2C=y
+	depends on OF
+	select REGMAP_I2C
+	select MFD_CORE
+	help
+	  This option enables support for the board management controller
+	  found on the Kontron sl28 CPLD. You have to select individual
+	  functions, such as watchdog, GPIO, etc, under the corresponding 

menus

drivers/mfd/Kconfig +7 -0
+	  in order to enable them.
+
+	  Currently supported boards are:
+
+		Kontron SMARC-sAL28
+
+	  To compile this driver as a module, choose M here: the module will 

be

drivers/mfd/Kconfig +2 -0
+	  called sl28cpld.
+
 endmenu
 endif
drivers/mfd/Makefile +2 -0
index f935d10cbf0f..9bc38863b9c7 100644
@@ -259,3 +259,5 @@ obj-$(CONFIG_MFD_ROHM_BD718XX)	+= rohm-bd718x7.o
 obj-$(CONFIG_MFD_STMFX) 	+= stmfx.o
 
 obj-$(CONFIG_SGI_MFD_IOC3)	+= ioc3.o
+
+obj-$(CONFIG_MFD_SL28CPLD)	+= sl28cpld.o
drivers/mfd/sl28cpld.c new file +20 -0
new file mode 100644
index 000000000000..1e5860cc7ffc
@@ -0,0 +1,153 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * MFD core for the sl28cpld.
+ *
+ * Copyright 2019 Kontron Europe GmbH
+ */
+
+#include <linux/i2c.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/mfd/core.h>
+#include <linux/module.h>
+#include <linux/of_platform.h>
+#include <linux/regmap.h>
+
+#define SL28CPLD_VERSION	0x03
+#define SL28CPLD_WATCHDOG_BASE	0x04
+#define SL28CPLD_HWMON_FAN_BASE	0x0b
+#define SL28CPLD_PWM0_BASE	0x0c
+#define SL28CPLD_PWM1_BASE	0x0e
Quoted 8 lines

drivers/mfd/sl28cpld.c line 25

Quoted 5 lines
drivers/mfd/sl28cpld.c new file +5 -0
+#define SL28CPLD_GPIO0_BASE	0x10
+#define SL28CPLD_GPIO1_BASE	0x15
+#define SL28CPLD_GPO_BASE	0x1a
+#define SL28CPLD_GPI_BASE	0x1b
+#define SL28CPLD_INTC_BASE	0x1c

If you want to use 'reg' in the binding, these are the numbers you should be using rather than making up numbering!

My motivation is that I don't want to hardcode the internal addresses of the management controller in the device tree. For example if they will move around with a later update of the controller, so a driver can be compatible with both the old and the new version. If they are in the device tree, only one register layout is possible.

Quoted 4 lines

However, I still don't think you need any child nodes. All the data in the DT binding is right here in the driver already. There's no advantage to putting child nodes in DT, because this driver still has to be updated if you add more nodes.

But then any phandle will reference the mfd device. And for example there are two different interrupt controllers, that is the INTC and the GPIO[01], which will then be combined into one device tree node, right?

So the mfd node would be

cpld: sl28cpld@4a {
interrupt-controller;
#interrupt-cells = <2>;
gpio-controller;
#gpio-cells = <2>;
[..]
};

and then depending on the mapping one could use:

interrupts-extended = <&cpld 0 FLAGS>; /* gpio0 line 0 */ interrupts-extended = <&cpld 8 FLAGS>; /* gpio1 line 0 */ interrupts-extended = <&cpld 12 FLAGS>; /* irq0 */

gpios = <&cpld 0> /* gpio0 line 0 */

But there is also offset 12, but then it is the GPI controller:

gpios = <&cpld 12> /* gpi line 0, nothing to do with irq0 */

I don't know if this is good practice, I guess you have to tell me. And is it possible to combine any sub device into the mfd node in that way?

-michael

#31 lore raw

Re: [PATCH v3 05/16] mfd: Add support for Kontron sl28cpld management controller

Am 2020-05-11 23:44, schrieb Michael Walle:

Quoted 131 lines

Am 2020-05-11 23:13, schrieb Rob Herring:

Quoted 90 lines · Michael Walle
Quoted 89 lines

This patch adds core support for the board management controller found on the SMARC-sAL28 board. It consists of the following functions:
- watchdog
- GPIO controller
- PWM controller
- fan sensor
- interrupt controller

At the moment, this controller is used on the Kontron SMARC-sAL28 board.

Please note that the MFD driver is defined as bool in the Kconfig because the next patch will add interrupt support.

---
 drivers/mfd/Kconfig    |  19 +++++
 drivers/mfd/Makefile   |   2 +
 drivers/mfd/sl28cpld.c | 153 
+++++++++++++++++++++++++++++++++++++++++
 3 files changed, 174 insertions(+)
 create mode 100644 drivers/mfd/sl28cpld.c
drivers/mfd/Kconfig +10 -0
index 0a59249198d3..be0c8d93c526 100644
@@ -2060,5 +2060,24 @@ config SGI_MFD_IOC3
 	  If you have an SGI Origin, Octane, or a PCI IOC3 card,
 	  then say Y. Otherwise say N.
 
+config MFD_SL28CPLD
+	bool "Kontron sl28 core driver"
+	depends on I2C=y
+	depends on OF
+	select REGMAP_I2C
+	select MFD_CORE
+	help
+	  This option enables support for the board management controller
+	  found on the Kontron sl28 CPLD. You have to select individual
+	  functions, such as watchdog, GPIO, etc, under the corresponding 

menus

drivers/mfd/Kconfig +7 -0
+	  in order to enable them.
+
+	  Currently supported boards are:
+
+		Kontron SMARC-sAL28
+
+	  To compile this driver as a module, choose M here: the module 

will be

drivers/mfd/Kconfig +2 -0
+	  called sl28cpld.
+
 endmenu
 endif
drivers/mfd/Makefile +2 -0
index f935d10cbf0f..9bc38863b9c7 100644
@@ -259,3 +259,5 @@ obj-$(CONFIG_MFD_ROHM_BD718XX)	+= rohm-bd718x7.o
 obj-$(CONFIG_MFD_STMFX) 	+= stmfx.o
 
 obj-$(CONFIG_SGI_MFD_IOC3)	+= ioc3.o
+
+obj-$(CONFIG_MFD_SL28CPLD)	+= sl28cpld.o
drivers/mfd/sl28cpld.c new file +20 -0
new file mode 100644
index 000000000000..1e5860cc7ffc
@@ -0,0 +1,153 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * MFD core for the sl28cpld.
+ *
+ * Copyright 2019 Kontron Europe GmbH
+ */
+
+#include <linux/i2c.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/mfd/core.h>
+#include <linux/module.h>
+#include <linux/of_platform.h>
+#include <linux/regmap.h>
+
+#define SL28CPLD_VERSION	0x03
+#define SL28CPLD_WATCHDOG_BASE	0x04
+#define SL28CPLD_HWMON_FAN_BASE	0x0b
+#define SL28CPLD_PWM0_BASE	0x0c
+#define SL28CPLD_PWM1_BASE	0x0e
Quoted 8 lines

drivers/mfd/sl28cpld.c line 25

Quoted 5 lines
drivers/mfd/sl28cpld.c new file +5 -0
+#define SL28CPLD_GPIO0_BASE	0x10
+#define SL28CPLD_GPIO1_BASE	0x15
+#define SL28CPLD_GPO_BASE	0x1a
+#define SL28CPLD_GPI_BASE	0x1b
+#define SL28CPLD_INTC_BASE	0x1c

If you want to use 'reg' in the binding, these are the numbers you should be using rather than making up numbering!

My motivation is that I don't want to hardcode the internal addresses of the management controller in the device tree. For example if they will move around with a later update of the controller, so a driver can be compatible with both the old and the new version. If they are in the device tree, only one register layout is possible.

Quoted 4 lines

However, I still don't think you need any child nodes. All the data in the DT binding is right here in the driver already. There's no advantage to putting child nodes in DT, because this driver still has to be updated if you add more nodes.

But then any phandle will reference the mfd device. And for example there are two different interrupt controllers, that is the INTC and the GPIO[01], which will then be combined into one device tree node, right?

So the mfd node would be

cpld: sl28cpld@4a {
interrupt-controller;
#interrupt-cells = <2>;
gpio-controller;
#gpio-cells = <2>;
[..]
};

and then depending on the mapping one could use:

interrupts-extended = <&cpld 0 FLAGS>; /* gpio0 line 0 */ interrupts-extended = <&cpld 8 FLAGS>; /* gpio1 line 0 */ interrupts-extended = <&cpld 12 FLAGS>; /* irq0 */

Quoted 8 lines

gpios = <&cpld 0> /* gpio0 line 0 */

But there is also offset 12, but then it is the GPI controller:

gpios = <&cpld 12> /* gpi line 0, nothing to do with irq0 */

I don't know if this is good practice, I guess you have to tell me. And is it possible to combine any sub device into the mfd node in that way?

Oh I don't think that will work for the watchdog. If you just have one watchdog it just looks odd.

cpld: sl28cpld@4a {
interrupt-controller;
#interrupt-cells = <2>;
gpio-controller;
#gpio-cells = <2>;
timeout-sec = <10>; /* watchdog property */
};

And won't pass the dtbindings check because the nodename is not "watchdog(@[0-9]+)?". But it really falls short if you want to have two watchdogs with different properties.

-michael

maintainer
#32 lore raw

Re: [PATCH v3 05/16] mfd: Add support for Kontron sl28cpld management controller

In reply to Michael Walle
Quoted 102 lines · Michael Walle

Am 2020-05-11 23:13, schrieb Rob Herring:

Quoted 91 lines · Michael Walle
Quoted 90 lines

This patch adds core support for the board management controller found on the SMARC-sAL28 board. It consists of the following functions:
- watchdog
- GPIO controller
- PWM controller
- fan sensor
- interrupt controller

At the moment, this controller is used on the Kontron SMARC-sAL28 board.

Please note that the MFD driver is defined as bool in the Kconfig because the next patch will add interrupt support.

---
 drivers/mfd/Kconfig    |  19 +++++
 drivers/mfd/Makefile   |   2 +
 drivers/mfd/sl28cpld.c | 153
+++++++++++++++++++++++++++++++++++++++++
 3 files changed, 174 insertions(+)
 create mode 100644 drivers/mfd/sl28cpld.c
drivers/mfd/Kconfig +10 -0
index 0a59249198d3..be0c8d93c526 100644
@@ -2060,5 +2060,24 @@ config SGI_MFD_IOC3
       If you have an SGI Origin, Octane, or a PCI IOC3 card,
       then say Y. Otherwise say N.
 
+config MFD_SL28CPLD
+    bool "Kontron sl28 core driver"
+    depends on I2C=y
+    depends on OF
+    select REGMAP_I2C
+    select MFD_CORE
+    help
+      This option enables support for the board management controller
+      found on the Kontron sl28 CPLD. You have to select individual
+      functions, such as watchdog, GPIO, etc, under the corresponding

menus

drivers/mfd/Kconfig +7 -0
+      in order to enable them.
+
+      Currently supported boards are:
+
+            Kontron SMARC-sAL28
+
+      To compile this driver as a module, choose M here: the module will

be

drivers/mfd/Kconfig +2 -0
+      called sl28cpld.
+
 endmenu
 endif
drivers/mfd/Makefile +2 -0
index f935d10cbf0f..9bc38863b9c7 100644
@@ -259,3 +259,5 @@ obj-$(CONFIG_MFD_ROHM_BD718XX)   += rohm-bd718x7.o
 obj-$(CONFIG_MFD_STMFX)     += stmfx.o
 
 obj-$(CONFIG_SGI_MFD_IOC3)  += ioc3.o
+
+obj-$(CONFIG_MFD_SL28CPLD)  += sl28cpld.o
drivers/mfd/sl28cpld.c new file +20 -0
new file mode 100644
index 000000000000..1e5860cc7ffc
@@ -0,0 +1,153 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * MFD core for the sl28cpld.
+ *
+ * Copyright 2019 Kontron Europe GmbH
+ */
+
+#include <linux/i2c.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/mfd/core.h>
+#include <linux/module.h>
+#include <linux/of_platform.h>
+#include <linux/regmap.h>
+
+#define SL28CPLD_VERSION    0x03
+#define SL28CPLD_WATCHDOG_BASE      0x04
+#define SL28CPLD_HWMON_FAN_BASE     0x0b
+#define SL28CPLD_PWM0_BASE  0x0c
+#define SL28CPLD_PWM1_BASE  0x0e
Quoted 8 lines

drivers/mfd/sl28cpld.c line 25

Quoted 5 lines
drivers/mfd/sl28cpld.c new file +5 -0
+#define SL28CPLD_GPIO0_BASE 0x10
+#define SL28CPLD_GPIO1_BASE 0x15
+#define SL28CPLD_GPO_BASE   0x1a
+#define SL28CPLD_GPI_BASE   0x1b
+#define SL28CPLD_INTC_BASE  0x1c

If you want to use 'reg' in the binding, these are the numbers you should be using rather than making up numbering!

Quoted 5 lines

My motivation is that I don't want to hardcode the internal addresses of the management controller in the device tree. For example if they will move around with a later update of the controller, so a driver can be compatible with both the old and the new version. If they are in the device tree, only one register layout is possible.

I don't understand, if the addresses change, then the above defines have to change. So your driver is only compatible with 1 version. If you change the CPLD, then that's a h/w change and your h/w description (DT) should change. That can either be the compatible string changing and updating the driver with new match data such as register offsets or all the differences are in DT and there's no kernel change.

Quoted 11 lines
Quoted 5 lines

However, I still don't think you need any child nodes. All the data in the DT binding is right here in the driver already. There's no advantage
to putting child nodes in DT, because this driver still has to be updated if you add more nodes.

But then any phandle will reference the mfd device. And for example there
are two different interrupt controllers, that is the INTC and the GPIO[01],
which will then be combined into one device tree node, right?

You either have to add a cell for 'bank' or divide the 1st cell into a bank and index. Both have been done before.

To go the other direction, AIUI you shouldn't need OF_MFD_CELL_REG entries if you have the child devices in DT. Pick one way or the other. It's ultimately a judgement call. For a one-off device, sub devices in DT doesn't really buy you anything. If you have sub-blocks showing up multiple devices, then sub devices makes sense. If there's only 2-3 combinations, then it's a toss up.

Rob

#33 lore raw

Re: [PATCH v3 05/16] mfd: Add support for Kontron sl28cpld management controller

Am 2020-05-12 23:59, schrieb Rob Herring:

Quoted 24 lines · Michael Walle
Quoted 17 lines

Am 2020-05-11 23:13, schrieb Rob Herring:

Quoted 6 lines · Michael Walle
Quoted 5 lines
drivers/mfd/sl28cpld.c new file +5 -0
+#define SL28CPLD_VERSION    0x03
+#define SL28CPLD_WATCHDOG_BASE      0x04
+#define SL28CPLD_HWMON_FAN_BASE     0x0b
+#define SL28CPLD_PWM0_BASE  0x0c
+#define SL28CPLD_PWM1_BASE  0x0e
Quoted 8 lines

drivers/mfd/sl28cpld.c line 25

Quoted 5 lines
drivers/mfd/sl28cpld.c new file +5 -0
+#define SL28CPLD_GPIO0_BASE 0x10
+#define SL28CPLD_GPIO1_BASE 0x15
+#define SL28CPLD_GPO_BASE   0x1a
+#define SL28CPLD_GPI_BASE   0x1b
+#define SL28CPLD_INTC_BASE  0x1c

If you want to use 'reg' in the binding, these are the numbers you should be using rather than making up numbering!

Quoted 5 lines

My motivation is that I don't want to hardcode the internal addresses of the management controller in the device tree. For example if they will move around with a later update of the controller, so a driver can be compatible with both the old and the new version. If they are in the device tree, only one register layout is possible.

Quoted 6 lines

I don't understand, if the addresses change, then the above defines have to change. So your driver is only compatible with 1 version. If you change the CPLD, then that's a h/w change and your h/w description (DT) should change. That can either be the compatible string changing and updating the driver with new match data such as register offsets or all the differences are in DT and there's no kernel change.

The CPLD and the board is designed in a way that it is possible to update and/or change its function (or parts of it). It must not be a hardware change, although I admit thats a bit of a grey area wether you treat it as hardware or "firmware". Anyway, yes you'd have to change the register offsets, but as this is code it might support different register offsets. For example you could dynamically add functionality, if there is a newer controller version while still being compatible with older versions.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

However, I still don't think you need any child nodes. All the data in the DT binding is right here in the driver already. There's no advantage
to putting child nodes in DT, because this driver still has to be updated if you add more nodes.

Quoted 8 lines
Quoted 5 lines

But then any phandle will reference the mfd device. And for example there
are two different interrupt controllers, that is the INTC and the GPIO[01],
which will then be combined into one device tree node, right?

You either have to add a cell for 'bank' or divide the 1st cell into a bank and index. Both have been done before.

But this won't work with watchdogs, correct? See
https://lore.kernel.org/linux-devicetree/[email protected]/

Quoted 2 lines

To go the other direction, AIUI you shouldn't need OF_MFD_CELL_REG entries if you have the child devices in DT.

This is a general problem IMHO. There are mfd drivers which have mfd cells and a device tree node associated with each cell. But it just works as long as there is only one sub device per unique compatible string. So you cannot have multiple mfd cells with the same compatible string.

That being said, I can try to reimplement it using of_platform_populate() and its internal offset as its unit address.

Quoted 5 lines

Pick one way or the
other. It's ultimately a judgement call. For a one-off device, sub devices in DT doesn't really buy you anything. If you have sub-blocks showing up multiple devices, then sub devices makes sense. If there's only 2-3 combinations, then it's a toss up.

-michael

#34 lore raw

PATCH v3 6/16 irqchip: add sl28cpld interrupt controller support

In reply to Michael Walle

This patch adds support for the interrupt controller inside the sl28 CPLD management controller.

---
 drivers/irqchip/Kconfig        |  3 ++
 drivers/irqchip/Makefile       |  1 +
 drivers/irqchip/irq-sl28cpld.c | 97 ++++++++++++++++++++++++++++++++++
 drivers/mfd/Kconfig            |  2 +
 4 files changed, 103 insertions(+)
 create mode 100644 drivers/irqchip/irq-sl28cpld.c
drivers/irqchip/Kconfig +3 -0
index a85aada04a64..234db932e7cf 100644
@@ -246,6 +246,9 @@ config RENESAS_RZA1_IRQC
 	  Enable support for the Renesas RZ/A1 Interrupt Controller, to use up
 	  to 8 external interrupts with configurable sense select.
 
+config SL28CPLD_INTC
+	bool
+
 config ST_IRQCHIP
 	bool
 	select REGMAP
drivers/irqchip/Makefile +1 -0
index 37bbe39bf909..e3c6b94f7b0a 100644
@@ -107,3 +107,4 @@ obj-$(CONFIG_TI_SCI_INTR_IRQCHIP)	+= irq-ti-sci-intr.o
 obj-$(CONFIG_TI_SCI_INTA_IRQCHIP)	+= irq-ti-sci-inta.o
 obj-$(CONFIG_LOONGSON_LIOINTC)		+= irq-loongson-liointc.o
 obj-$(CONFIG_LOONGSON_HTPIC)		+= irq-loongson-htpic.o
+obj-$(CONFIG_SL28CPLD_INTC)		+= irq-sl28cpld.o
drivers/irqchip/irq-sl28cpld.c new file +97 -0

97 lines not on this page · raw message

drivers/mfd/Kconfig +2 -0
index be0c8d93c526..9e848a455172 100644
@@ -2065,6 +2065,8 @@ config MFD_SL28CPLD
 	depends on I2C=y
 	depends on OF
 	select REGMAP_I2C
+	select REGMAP_IRQ
+	select SL28CPLD_INTC
 	select MFD_CORE
 	help
 	  This option enables support for the board management controller
Signature · 1 line
2.20.1
#35 lore raw

Re: [PATCH v3 06/16] irqchip: add sl28cpld interrupt controller support

Quoted 1 line · Michael Walle

This patch adds support for the interrupt controller inside the sl28

git grep 'This patch' Documentation/process/

Quoted 29 lines

CPLD management controller.

drivers/irqchip/irq-sl28cpld.c new file +27 -0
+static int sl28cpld_intc_probe(struct platform_device *pdev)
+{
+	struct sl28cpld_intc *irqchip;
+	struct resource *res;
+	unsigned int irq;
+	int ret;
+
+	if (!pdev->dev.parent)
+		return -ENODEV;
+
+	irqchip = devm_kzalloc(&pdev->dev, sizeof(*irqchip), GFP_KERNEL);
+	if (!irqchip)
+		return -ENOMEM;
+
+	irqchip->regmap = dev_get_regmap(pdev->dev.parent, NULL);
+	if (!irqchip->regmap)
+		return -ENODEV;
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0)
+		return irq;
+
+	res = platform_get_resource(pdev, IORESOURCE_REG, 0);
+	if (!res)
+		return -EINVAL;
+
+	irqchip->chip.name = "sl28cpld-intc";

drivers/irqchip/irq-sl28cpld.c line 71

Quoted 10 lines
drivers/irqchip/irq-sl28cpld.c new file +10 -0
+	irqchip->chip.irqs = sl28cpld_irqs;
+	irqchip->chip.num_irqs = ARRAY_SIZE(sl28cpld_irqs);
+	irqchip->chip.num_regs = 1;
+	irqchip->chip.status_base = res->start + INTC_IP;
+	irqchip->chip.mask_base = res->start + INTC_IE;
+	irqchip->chip.mask_invert = true,
+	irqchip->chip.ack_base = res->start + INTC_IP;
+
+	ret = devm_regmap_add_irq_chip(&pdev->dev, irqchip->regmap, irq,
+				       IRQF_SHARED | IRQF_ONESHOT, 0,

What's the point of IRQF_SHARED | IRQF_ONESHOT here?

drivers/irqchip/irq-sl28cpld.c line 72

Quoted 1 line
drivers/irqchip/irq-sl28cpld.c new file +1 -0
+				       &irqchip->chip, &irqchip->irq_data);

Thanks,

tglx

#36 lore raw

Re: [PATCH v3 06/16] irqchip: add sl28cpld interrupt controller support

Hi Thomas,

thanks for the review.

Am 2020-04-27 13:40, schrieb Thomas Gleixner:

Quoted 5 lines
Quoted 1 line · Michael Walle

This patch adds support for the interrupt controller inside the sl28

git grep 'This patch' Documentation/process/

ok.

Quoted 34 lines
Quoted 34 lines

CPLD management controller.

drivers/irqchip/irq-sl28cpld.c new file +31 -0
+static int sl28cpld_intc_probe(struct platform_device *pdev)
+{
+	struct sl28cpld_intc *irqchip;
+	struct resource *res;
+	unsigned int irq;
+	int ret;
+
+	if (!pdev->dev.parent)
+		return -ENODEV;
+
+	irqchip = devm_kzalloc(&pdev->dev, sizeof(*irqchip), GFP_KERNEL);
+	if (!irqchip)
+		return -ENOMEM;
+
+	irqchip->regmap = dev_get_regmap(pdev->dev.parent, NULL);
+	if (!irqchip->regmap)
+		return -ENODEV;
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0)
+		return irq;
+
+	res = platform_get_resource(pdev, IORESOURCE_REG, 0);
+	if (!res)
+		return -EINVAL;
+
+	irqchip->chip.name = "sl28cpld-intc";
+	irqchip->chip.irqs = sl28cpld_irqs;
+	irqchip->chip.num_irqs = ARRAY_SIZE(sl28cpld_irqs);
+	irqchip->chip.num_regs = 1;
+	irqchip->chip.status_base = res->start + INTC_IP;
Quoted 8 lines

drivers/irqchip/irq-sl28cpld.c line 71

Quoted 6 lines
drivers/irqchip/irq-sl28cpld.c new file +6 -0
+	irqchip->chip.mask_base = res->start + INTC_IE;
+	irqchip->chip.mask_invert = true,
+	irqchip->chip.ack_base = res->start + INTC_IP;
+
+	ret = devm_regmap_add_irq_chip(&pdev->dev, irqchip->regmap, irq,
+				       IRQF_SHARED | IRQF_ONESHOT, 0,

What's the point of IRQF_SHARED | IRQF_ONESHOT here?

IRQF_SHARED because this interrupt is shared with all the blocks which can generate interrupts, i.e. the GPIO contollers.

IRQF_ONESHOT, because its is a threaded interrupt with no primary handler. But I just noticed, that regmap-irq will also set the IRQF_ONESHOT. But that the commit 09cadf6e088b ("regmap-irq:
set IRQF_ONESHOT flag to ensure IRQ request") reads like it is just there to be sure. So I don't know if it should also be set here.

-michael

Quoted 6 lines

drivers/irqchip/irq-sl28cpld.c line 72

Quoted 2 lines
drivers/irqchip/irq-sl28cpld.c new file +1 -0
+				       &irqchip->chip, &irqchip->irq_data);

Thanks,

tglx

#37 lore raw

Re: [PATCH v3 06/16] irqchip: add sl28cpld interrupt controller support

Quoted 6 lines · Michael Walle

IRQF_ONESHOT, because its is a threaded interrupt with no primary handler. But I just noticed, that regmap-irq will also set the IRQF_ONESHOT. But that the commit 09cadf6e088b ("regmap-irq:
set IRQF_ONESHOT flag to ensure IRQ request") reads like it is just there to be sure. So I don't know if it should also be set here.

Looking at the changelog there the "we can't be sure" bit is that coccinelle couldn't follow the flags through from the caller to make sure that IRQF_ONESHOT is set so we're just oring it in unconditionally.

#38 lore raw

Re: [PATCH v3 06/16] irqchip: add sl28cpld interrupt controller support

Am 2020-04-27 19:44, schrieb Mark Brown:

Quoted 9 lines · Michael Walle
Quoted 7 lines

IRQF_ONESHOT, because its is a threaded interrupt with no primary handler. But I just noticed, that regmap-irq will also set the IRQF_ONESHOT. But that the commit 09cadf6e088b ("regmap-irq:
set IRQF_ONESHOT flag to ensure IRQ request") reads like it is just there to be sure. So I don't know if it should also be set here.

Quoted 3 lines

Looking at the changelog there the "we can't be sure" bit is that coccinelle couldn't follow the flags through from the caller to make sure that IRQF_ONESHOT is set so we're just oring it in unconditionally.

So it is correct that IRQF_ONESHOT is also set in the driver which is using regmap_add_irq_chip(), right?

-michael

#39 lore raw

Re: [PATCH v3 06/16] irqchip: add sl28cpld interrupt controller support

Quoted 8 lines · Michael Walle

Am 2020-04-27 19:44, schrieb Mark Brown:

Quoted 3 lines

Looking at the changelog there the "we can't be sure" bit is that coccinelle couldn't follow the flags through from the caller to make sure that IRQF_ONESHOT is set so we're just oring it in unconditionally.

So it is correct that IRQF_ONESHOT is also set in the driver which is using regmap_add_irq_chip(), right?

It shouldn't break anything and my instinct is that it's better form.

#40 lore raw

Re: [PATCH v3 06/16] irqchip: add sl28cpld interrupt controller support

In reply to Michael Walle

Michael,

Quoted 9 lines · Michael Walle

Am 2020-04-27 13:40, schrieb Thomas Gleixner:

Quoted 5 lines

drivers/irqchip/irq-sl28cpld.c line 71

Quoted 3 lines
drivers/irqchip/irq-sl28cpld.c new file +3 -0
+
+	ret = devm_regmap_add_irq_chip(&pdev->dev, irqchip->regmap, irq,
+				       IRQF_SHARED | IRQF_ONESHOT, 0,

What's the point of IRQF_SHARED | IRQF_ONESHOT here?

IRQF_SHARED because this interrupt is shared with all the blocks which can generate interrupts, i.e. the GPIO contollers.

Why are people still designing hardware with shared interrupts? Shared interrupts are broken by design and that's well known for decades.

Quoted 6 lines

IRQF_ONESHOT, because its is a threaded interrupt with no primary handler. But I just noticed, that regmap-irq will also set the IRQF_ONESHOT. But that the commit 09cadf6e088b ("regmap-irq:
set IRQF_ONESHOT flag to ensure IRQ request") reads like it is just there to be sure. So I don't know if it should also be set here.

Ok. Wasn't aware of that magic threaded interrupt connection.

Thanks,

tglx

#41 lore raw

PATCH v3 7/16 watchdog: add support for sl28cpld watchdog

In reply to Michael Walle

This adds support for the watchdog of the sl28cpld board management controller. This is part of a multi-function device driver.

---
 drivers/watchdog/Kconfig        |  11 ++
 drivers/watchdog/Makefile       |   1 +
 drivers/watchdog/sl28cpld_wdt.c | 233 ++++++++++++++++++++++++++++++++
 3 files changed, 245 insertions(+)
 create mode 100644 drivers/watchdog/sl28cpld_wdt.c
drivers/watchdog/Kconfig +11 -0
index 0663c604bd64..6c53c1d0f348 100644
@@ -340,6 +340,17 @@ config MLX_WDT
 	  To compile this driver as a module, choose M here: the
 	  module will be called mlx-wdt.
 
+config SL28CPLD_WATCHDOG
+	tristate "Kontron sl28 watchdog"
+	depends on MFD_SL28CPLD
+	select WATCHDOG_CORE
+	help
+	  Say Y here to include support for the watchdog timer
+	  on the Kontron sl28 CPLD.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called sl28cpld_wdt.
+
 # ALPHA Architecture
 
 # ARM Architecture
drivers/watchdog/Makefile +1 -0
index 6de2e4ceef19..b9ecdf2d7347 100644
@@ -224,3 +224,4 @@ obj-$(CONFIG_MENF21BMC_WATCHDOG) += menf21bmc_wdt.o
 obj-$(CONFIG_MENZ069_WATCHDOG) += menz69_wdt.o
 obj-$(CONFIG_RAVE_SP_WATCHDOG) += rave-sp-wdt.o
 obj-$(CONFIG_STPMIC1_WATCHDOG) += stpmic1_wdt.o
+obj-$(CONFIG_SL28CPLD_WATCHDOG) += sl28cpld_wdt.o
drivers/watchdog/sl28cpld_wdt.c new file +233 -0

233 lines not on this page · raw message

Signature · 1 line
2.20.1
maintainer Acked-by on v3 7/16
#42 lore raw

Re: [PATCH v3 07/16] watchdog: add support for sl28cpld watchdog

Quoted 4 lines · Michael Walle

This adds support for the watchdog of the sl28cpld board management controller. This is part of a multi-function device driver.

Quoted 278 lines
---
 drivers/watchdog/Kconfig        |  11 ++
 drivers/watchdog/Makefile       |   1 +
 drivers/watchdog/sl28cpld_wdt.c | 233 ++++++++++++++++++++++++++++++++
 3 files changed, 245 insertions(+)
 create mode 100644 drivers/watchdog/sl28cpld_wdt.c
drivers/watchdog/Kconfig +11 -0
index 0663c604bd64..6c53c1d0f348 100644
@@ -340,6 +340,17 @@ config MLX_WDT
 	  To compile this driver as a module, choose M here: the
 	  module will be called mlx-wdt.
 
+config SL28CPLD_WATCHDOG
+	tristate "Kontron sl28 watchdog"
+	depends on MFD_SL28CPLD
+	select WATCHDOG_CORE
+	help
+	  Say Y here to include support for the watchdog timer
+	  on the Kontron sl28 CPLD.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called sl28cpld_wdt.
+
 # ALPHA Architecture
 
 # ARM Architecture
drivers/watchdog/Makefile +1 -0
index 6de2e4ceef19..b9ecdf2d7347 100644
@@ -224,3 +224,4 @@ obj-$(CONFIG_MENF21BMC_WATCHDOG) += menf21bmc_wdt.o
 obj-$(CONFIG_MENZ069_WATCHDOG) += menz69_wdt.o
 obj-$(CONFIG_RAVE_SP_WATCHDOG) += rave-sp-wdt.o
 obj-$(CONFIG_STPMIC1_WATCHDOG) += stpmic1_wdt.o
+obj-$(CONFIG_SL28CPLD_WATCHDOG) += sl28cpld_wdt.o
drivers/watchdog/sl28cpld_wdt.c new file +233 -0
new file mode 100644
index 000000000000..2640084ace5c
@@ -0,0 +1,233 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * sl28cpld watchdog driver.
+ *
+ * Copyright 2019 Kontron Europe GmbH
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <linux/watchdog.h>
+
+/*
+ * Watchdog timer block registers.
+ */
+#define WDT_CTRL			0x00
+#define  WDT_CTRL_EN			BIT(0)
+#define  WDT_CTRL_LOCK			BIT(2)
+#define  WDT_CTRL_ASSERT_SYS_RESET	BIT(6)
+#define  WDT_CTRL_ASSERT_WDT_TIMEOUT	BIT(7)
+#define WDT_TIMEOUT			0x01
+#define WDT_KICK			0x02
+#define  WDT_KICK_VALUE			0x6b
+#define WDT_COUNT			0x03
+
+#define WDT_DEFAULT_TIMEOUT		10
+
+static bool nowayout = WATCHDOG_NOWAYOUT;
+module_param(nowayout, bool, 0);
+MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
+				__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
+
+static int timeout;
+module_param(timeout, int, 0);
+MODULE_PARM_DESC(timeout, "Initial watchdog timeout in seconds");
+
+struct sl28cpld_wdt {
+	struct watchdog_device wdd;
+	struct regmap *regmap;
+	u32 offset;
+	bool assert_wdt_timeout;
+};
+
+static int sl28cpld_wdt_ping(struct watchdog_device *wdd)
+{
+	struct sl28cpld_wdt *wdt = watchdog_get_drvdata(wdd);
+
+	return regmap_write(wdt->regmap, wdt->offset + WDT_KICK,
+			    WDT_KICK_VALUE);
+}
+
+static int sl28cpld_wdt_start(struct watchdog_device *wdd)
+{
+	struct sl28cpld_wdt *wdt = watchdog_get_drvdata(wdd);
+	unsigned int val;
+
+	val = WDT_CTRL_EN | WDT_CTRL_ASSERT_SYS_RESET;
+	if (wdt->assert_wdt_timeout)
+		val |= WDT_CTRL_ASSERT_WDT_TIMEOUT;
+	if (nowayout)
+		val |= WDT_CTRL_LOCK;
+
+	return regmap_update_bits(wdt->regmap, wdt->offset + WDT_CTRL,
+				  val, val);
+}
+
+static int sl28cpld_wdt_stop(struct watchdog_device *wdd)
+{
+	struct sl28cpld_wdt *wdt = watchdog_get_drvdata(wdd);
+
+	return regmap_update_bits(wdt->regmap, wdt->offset + WDT_CTRL,
+				  WDT_CTRL_EN, 0);
+}
+
+static unsigned int sl28cpld_wdt_get_timeleft(struct watchdog_device *wdd)
+{
+	struct sl28cpld_wdt *wdt = watchdog_get_drvdata(wdd);
+	unsigned int val;
+	int ret;
+
+	ret = regmap_read(wdt->regmap, wdt->offset + WDT_COUNT, &val);
+
+	return (ret < 0) ? 0 : val;
+}
+
+static int sl28cpld_wdt_set_timeout(struct watchdog_device *wdd,
+				    unsigned int timeout)
+{
+	struct sl28cpld_wdt *wdt = watchdog_get_drvdata(wdd);
+	int ret;
+
+	ret = regmap_write(wdt->regmap, wdt->offset + WDT_TIMEOUT, timeout);
+	if (!ret)
+		wdd->timeout = timeout;
+
+	return ret;
+}
+
+static const struct watchdog_info sl28cpld_wdt_info = {
+	.options = WDIOF_MAGICCLOSE | WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
+	.identity = "sl28cpld watchdog",
+};
+
+static struct watchdog_ops sl28cpld_wdt_ops = {
+	.owner = THIS_MODULE,
+	.start = sl28cpld_wdt_start,
+	.stop = sl28cpld_wdt_stop,
+	.ping = sl28cpld_wdt_ping,
+	.set_timeout = sl28cpld_wdt_set_timeout,
+	.get_timeleft = sl28cpld_wdt_get_timeleft,
+};
+
+static int sl28cpld_wdt_probe(struct platform_device *pdev)
+{
+	struct watchdog_device *wdd;
+	struct sl28cpld_wdt *wdt;
+	struct resource *res;
+	unsigned int status;
+	unsigned int val;
+	int ret;
+
+	if (!pdev->dev.parent)
+		return -ENODEV;
+
+	wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL);
+	if (!wdt)
+		return -ENOMEM;
+
+	wdt->regmap = dev_get_regmap(pdev->dev.parent, NULL);
+	if (!wdt->regmap)
+		return -ENODEV;
+
+	res = platform_get_resource(pdev, IORESOURCE_REG, 0);
+	if (!res)
+		return -EINVAL;
+	wdt->offset = res->start;
+
+	wdt->assert_wdt_timeout = device_property_read_bool(&pdev->dev,
+							    "kontron,assert-wdt-timeout-pin");
+
+	/* initialize struct watchdog_device */
+	wdd = &wdt->wdd;
+	wdd->parent = &pdev->dev;
+	wdd->info = &sl28cpld_wdt_info;
+	wdd->ops = &sl28cpld_wdt_ops;
+	wdd->min_timeout = 1;
+	wdd->max_timeout = 255;
+
+	watchdog_set_drvdata(wdd, wdt);
+	watchdog_stop_on_reboot(wdd);
+
+	/*
+	 * Read the status early, in case of an error, we haven't modified the
+	 * hardware.
+	 */
+	ret = regmap_read(wdt->regmap, wdt->offset + WDT_CTRL, &status);
+	if (ret < 0)
+		return ret;
+
+	/*
+	 * Initial timeout value, may be overwritten by device tree or module
+	 * parmeter in watchdog_init_timeout().
+	 *
+	 * Reading a zero here means that either the hardware has a default
+	 * value of zero (which is very unlikely and definitely a hardware
+	 * bug) or the bootloader set it to zero. In any case, we handle
+	 * this case gracefully and set out own timeout.
+	 */
+	ret = regmap_read(wdt->regmap, wdt->offset + WDT_TIMEOUT, &val);
+	if (ret < 0)
+		return ret;
+
+	if (val)
+		wdd->timeout = val;
+	else
+		wdd->timeout = WDT_DEFAULT_TIMEOUT;
+
+	watchdog_init_timeout(wdd, timeout, &pdev->dev);
+	sl28cpld_wdt_set_timeout(wdd, wdd->timeout);
+
+	/* if the watchdog is locked, we set nowayout */
+	if (status & WDT_CTRL_LOCK)
+		nowayout = true;
+	watchdog_set_nowayout(wdd, nowayout);
+
+	/*
+	 * If watchdog is already running, keep it enabled, but make
+	 * sure its mode is set correctly.
+	 */
+	if (status & WDT_CTRL_EN) {
+		sl28cpld_wdt_start(wdd);
+		set_bit(WDOG_HW_RUNNING, &wdd->status);
+	}
+
+	ret = devm_watchdog_register_device(&pdev->dev, wdd);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "failed to register watchdog device\n");
+		return ret;
+	}
+
+	dev_info(&pdev->dev, "initial timeout %d sec%s\n",
+		 wdd->timeout, nowayout ? ", nowayout" : "");
+
+	return 0;
+}
+
+static const struct of_device_id sl28cpld_wdt_of_match[] = {
+	{ .compatible = "kontron,sl28cpld-wdt" },
+	{},
+};
+MODULE_DEVICE_TABLE(of, sl28cpld_wdt_of_match);
+
+static const struct platform_device_id sl28cpld_wdt_id_table[] = {
+	{ "sl28cpld-wdt" },
+	{},
+};
+MODULE_DEVICE_TABLE(platform, sl28cpld_wdt_id_table);
+
+static struct platform_driver sl28cpld_wdt_driver = {
+	.probe = sl28cpld_wdt_probe,
+	.id_table = sl28cpld_wdt_id_table,
+	.driver = {
+		.name = KBUILD_MODNAME,
+		.of_match_table = sl28cpld_wdt_of_match,
+	},
+};
+module_platform_driver(sl28cpld_wdt_driver);
+
+MODULE_DESCRIPTION("sl28cpld Watchdog Driver");
+MODULE_AUTHOR("Michael Walle <[email protected]>");
+MODULE_LICENSE("GPL");
#43 lore raw

PATCH v3 8/16 pwm: add support for sl28cpld PWM controller

In reply to Michael Walle

This adds support for the PWM controller of the sl28cpld board management controller. This is part of a multi-function device driver.

---
 drivers/pwm/Kconfig        |  10 ++
 drivers/pwm/Makefile       |   1 +
 drivers/pwm/pwm-sl28cpld.c | 203 +++++++++++++++++++++++++++++++++++++
 3 files changed, 214 insertions(+)
 create mode 100644 drivers/pwm/pwm-sl28cpld.c
drivers/pwm/Kconfig +10 -0
index c13d146cdde5..45b308482f92 100644
@@ -437,6 +437,16 @@ config PWM_SIFIVE
 	  To compile this driver as a module, choose M here: the module
 	  will be called pwm-sifive.
 
+config PWM_SL28CPLD
+	tristate "Kontron sl28 PWM support"
+	depends on MFD_SL28CPLD
+	help
+	  Generic PWM framework driver for board management controller
+	  found on the Kontron sl28 CPLD.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called pwm-sl28cpld.
+
 config PWM_SPEAR
 	tristate "STMicroelectronics SPEAr PWM support"
 	depends on PLAT_SPEAR || COMPILE_TEST
drivers/pwm/Makefile +1 -0
index a59c710e98c7..c479623724e8 100644
@@ -41,6 +41,7 @@ obj-$(CONFIG_PWM_RENESAS_TPU)	+= pwm-renesas-tpu.o
 obj-$(CONFIG_PWM_ROCKCHIP)	+= pwm-rockchip.o
 obj-$(CONFIG_PWM_SAMSUNG)	+= pwm-samsung.o
 obj-$(CONFIG_PWM_SIFIVE)	+= pwm-sifive.o
+obj-$(CONFIG_PWM_SL28CPLD)	+= pwm-sl28cpld.o
 obj-$(CONFIG_PWM_SPEAR)		+= pwm-spear.o
 obj-$(CONFIG_PWM_SPRD)		+= pwm-sprd.o
 obj-$(CONFIG_PWM_STI)		+= pwm-sti.o
drivers/pwm/pwm-sl28cpld.c new file +203 -0

203 lines not on this page · raw message

Signature · 1 line
2.20.1
maintainer
#44 lore raw

Re: [PATCH v3 08/16] pwm: add support for sl28cpld PWM controller

Quoted 12 lines · Michael Walle

This adds support for the PWM controller of the sl28cpld board management controller. This is part of a multi-function device driver.

---
 drivers/pwm/Kconfig        |  10 ++
 drivers/pwm/Makefile       |   1 +
 drivers/pwm/pwm-sl28cpld.c | 203 +++++++++++++++++++++++++++++++++++++
 3 files changed, 214 insertions(+)
 create mode 100644 drivers/pwm/pwm-sl28cpld.c

drivers/pwm/pwm-sl28cpld.c line 185

Quoted 8 lines
drivers/pwm/pwm-sl28cpld.c new file +8 -0
+static const struct of_device_id sl28cpld_pwm_of_match[] = {
+	{ .compatible = "kontron,sl28cpld-pwm" },
+	{},
+};
+MODULE_DEVICE_TABLE(of, sl28cpld_pwm_of_match);
+
+static const struct platform_device_id sl28cpld_pwm_id_table[] = {
+	{"sl28cpld-gpio"},

copy-n-paste error?

Quoted 21 lines
drivers/pwm/pwm-sl28cpld.c new file +18 -0
+	{},
+};
+MODULE_DEVICE_TABLE(platform, sl28cpld_pwm_id_table);
+
+static struct platform_driver sl28cpld_pwm_driver = {
+	.probe = sl28cpld_pwm_probe,
+	.remove	= sl28cpld_pwm_remove,
+	.id_table = sl28cpld_pwm_id_table,
+	.driver = {
+		.name = KBUILD_MODNAME,
+		.of_match_table = sl28cpld_pwm_of_match,
+	},
+};
+module_platform_driver(sl28cpld_pwm_driver);
+
+MODULE_DESCRIPTION("sl28cpld PWM Driver");
+MODULE_AUTHOR("Michael Walle <[email protected]>");
+MODULE_LICENSE("GPL");
Signature · 1 line
2.20.1
#45 lore raw

PATCH v3 9/16 gpiolib: Introduce gpiochip_irqchip_add_domain()

In reply to Michael Walle

This connects an IRQ domain to a gpiochip and reuses gpiochip_to_irq().

---
 drivers/gpio/gpiolib.c      | 20 ++++++++++++++++++++
 include/linux/gpio/driver.h |  3 +++
 2 files changed, 23 insertions(+)
drivers/gpio/gpiolib.c +20 -0
index 40f2d7f69be2..7b3d7f496b9a 100644
@@ -2722,6 +2722,26 @@ int gpiochip_irqchip_add_key(struct gpio_chip *gc,
 }
 EXPORT_SYMBOL_GPL(gpiochip_irqchip_add_key);
 
+/**
+ * gpiochip_irqchip_add_key() - adds an irqdomain to a gpiochip
+ * @gc: the gpiochip to add the irqchip to
+ * @domain: the irqdomain to add to the gpiochip
+ *
+ * This function adds an IRQ domain to the gpiochip.
+ */
+int gpiochip_irqchip_add_domain(struct gpio_chip *gc,
+				struct irq_domain *domain)
+{
+	if (!domain)
+		return -EINVAL;
+
+	gc->to_irq = gpiochip_to_irq;
+	gc->irq.domain = domain;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(gpiochip_irqchip_add_domain);
+
 #else /* CONFIG_GPIOLIB_IRQCHIP */
 
 static inline int gpiochip_add_irqchip(struct gpio_chip *gc,
include/linux/gpio/driver.h +3 -0
index b8fc92c177eb..dfb1aa0ad4dc 100644
@@ -599,6 +599,9 @@ int gpiochip_irqchip_add_key(struct gpio_chip *gc,
 bool gpiochip_irqchip_irq_valid(const struct gpio_chip *gc,
 				unsigned int offset);
 
+int gpiochip_irqchip_add_domain(struct gpio_chip *gc,
+				struct irq_domain *domain);
+
 #ifdef CONFIG_LOCKDEP
 
 /*
Signature · 1 line
2.20.1
#46 lore raw

Re: [PATCH v3 09/16] gpiolib: Introduce gpiochip_irqchip_add_domain()

Quoted 2 lines · Michael Walle

This connects an IRQ domain to a gpiochip and reuses gpiochip_to_irq().

A little bit more context and explanation why this function is useful would be appreciated.

Quoted 11 lines
---
 drivers/gpio/gpiolib.c      | 20 ++++++++++++++++++++
 include/linux/gpio/driver.h |  3 +++
 2 files changed, 23 insertions(+)
drivers/gpio/gpiolib.c +0 -0
index 40f2d7f69be2..7b3d7f496b9a 100644

drivers/gpio/gpiolib.c int gpiochip_irqchip_add_key(struct gpio_chip *gc, · line 2726

Quoted 5 lines
drivers/gpio/gpiolib.c +2 -0
@@ -2722,6 +2722,26 @@ int gpiochip_irqchip_add_key(struct gpio_chip *gc,
 }
 EXPORT_SYMBOL_GPL(gpiochip_irqchip_add_key);
 
+/**
+ * gpiochip_irqchip_add_key() - adds an irqdomain to a gpiochip

Copy & paste is wonderful

Quoted 6 lines
drivers/gpio/gpiolib.c +6 -0
+ * @gc: the gpiochip to add the irqchip to
+ * @domain: the irqdomain to add to the gpiochip
+ *
+ * This function adds an IRQ domain to the gpiochip.
+ */
+int gpiochip_irqchip_add_domain(struct gpio_chip *gc,

drivers/gpio/gpiolib.c int gpiochip_irqchip_add_key(struct gpio_chip *gc, · line 2742

Quoted 10 lines
drivers/gpio/gpiolib.c +10 -0
+				struct irq_domain *domain)
+{
+	if (!domain)
+		return -EINVAL;
+
+	gc->to_irq = gpiochip_to_irq;
+	gc->irq.domain = domain;
+
+	return 0;
+}

Thanks,

tglx

#47 lore raw

Re: [PATCH v3 09/16] gpiolib: Introduce gpiochip_irqchip_add_domain()

Am 2020-04-27 13:42, schrieb Thomas Gleixner:

Quoted 6 lines
Quoted 2 lines · Michael Walle

This connects an IRQ domain to a gpiochip and reuses gpiochip_to_irq().

A little bit more context and explanation why this function is useful would be appreciated.

Ok I'll try to be a bit more elaborate the in the next version, (if this function is still there).

For now:

gpiochip_irqchip_add_domain() allows to use reqmap-irq, which exports an irqdomain, with gpiolib while reusing gpiochip_to_irq(). Both gpiochip_irqchip_* and regmap_irq partially provides the same functionality. The new function will help to connect just the minimal functionality of the gpiochip_irqchip which is needed to work together with regmap-irq.

Quoted 16 lines
Quoted 16 lines
---
 drivers/gpio/gpiolib.c      | 20 ++++++++++++++++++++
 include/linux/gpio/driver.h |  3 +++
 2 files changed, 23 insertions(+)
drivers/gpio/gpiolib.c +0 -0
index 40f2d7f69be2..7b3d7f496b9a 100644
@@ -2722,6 +2722,26 @@ int gpiochip_irqchip_add_key(struct gpio_chip 
 *gc,
 }
 EXPORT_SYMBOL_GPL(gpiochip_irqchip_add_key);
 
Quoted 4 lines

drivers/gpio/gpiolib.c int gpiochip_irqchip_add_key(struct gpio_chip *gc, · line 2726

Quoted 2 lines
drivers/gpio/gpiolib.c +2 -0
+/**
+ * gpiochip_irqchip_add_key() - adds an irqdomain to a gpiochip

Copy & paste is wonderful

whoops.

-michael

Quoted 21 lines
Quoted 7 lines
drivers/gpio/gpiolib.c +6 -0
+ * @gc: the gpiochip to add the irqchip to
+ * @domain: the irqdomain to add to the gpiochip
+ *
+ * This function adds an IRQ domain to the gpiochip.
+ */
+int gpiochip_irqchip_add_domain(struct gpio_chip *gc,

drivers/gpio/gpiolib.c int gpiochip_irqchip_add_key(struct gpio_chip *gc, · line 2742

Quoted 10 lines
drivers/gpio/gpiolib.c +10 -0
+				struct irq_domain *domain)
+{
+	if (!domain)
+		return -EINVAL;
+
+	gc->to_irq = gpiochip_to_irq;
+	gc->irq.domain = domain;
+
+	return 0;
+}

Thanks,

tglx

#48 lore raw

PATCH v3 10/16 gpio: add a reusable generic gpio_chip using regmap

In reply to Michael Walle

There are quite a lot simple GPIO controller which are using regmap to access the hardware. This driver tries to be a base to unify existing code into one place. This won't cover everything but it should be a good starting point.

It does not implement its own irq_chip because there is already a generic one for regmap based devices. Instead, the irq_chip will be instantiated in the parent driver and its irq domain will be associate to this driver.

For now it consists of the usual registers, like set (and an optional clear) data register, an input register and direction registers. Out-of-the-box, it supports consecutive register mappings and mappings where the registers have gaps between them with a linear mapping between GPIO offset and bit position. For weirder mappings the user can register its own .xlate().

---
 drivers/gpio/Kconfig        |   4 +
 drivers/gpio/Makefile       |   1 +
 drivers/gpio/gpio-regmap.c  | 343 ++++++++++++++++++++++++++++++++++++
 include/linux/gpio-regmap.h |  69 ++++++++
 4 files changed, 417 insertions(+)
 create mode 100644 drivers/gpio/gpio-regmap.c
 create mode 100644 include/linux/gpio-regmap.h
drivers/gpio/Kconfig +4 -0
index 8ef2179fb999..ae3a49a2e970 100644
@@ -73,6 +73,10 @@ config GPIO_GENERIC
 	depends on HAS_IOMEM # Only for IOMEM drivers
 	tristate
 
+config GPIO_REGMAP
+	depends on REGMAP
+	tristate
+
 # put drivers in the right section, in alphabetical order
 
 # This symbol is selected by both I2C and SPI expanders
drivers/gpio/Makefile +1 -0
index b2cfc21a97f3..93e139fdfa57 100644
@@ -12,6 +12,7 @@ obj-$(CONFIG_GPIO_SYSFS)	+= gpiolib-sysfs.o
 obj-$(CONFIG_GPIO_ACPI)		+= gpiolib-acpi.o
 
 # Device drivers. Generally keep list sorted alphabetically
+obj-$(CONFIG_GPIO_REGMAP)	+= gpio-regmap.o
 obj-$(CONFIG_GPIO_GENERIC)	+= gpio-generic.o
 
 # directly supported by gpio-generic
drivers/gpio/gpio-regmap.c new file +343 -0

343 lines not on this page · raw message

include/linux/gpio-regmap.h new file +69 -0

69 lines not on this page · raw message

Signature · 1 line
2.20.1
#49 lore raw

Re: [PATCH v3 10/16] gpio: add a reusable generic gpio_chip using regmap

czw., 23 kwi 2020 o 19:46 Michael Walle <[email protected]> napisał(a):

Quoted 18 lines

There are quite a lot simple GPIO controller which are using regmap to access the hardware. This driver tries to be a base to unify existing code into one place. This won't cover everything but it should be a good starting point.

It does not implement its own irq_chip because there is already a generic one for regmap based devices. Instead, the irq_chip will be instantiated in the parent driver and its irq domain will be associate to this driver.

For now it consists of the usual registers, like set (and an optional clear) data register, an input register and direction registers. Out-of-the-box, it supports consecutive register mappings and mappings where the registers have gaps between them with a linear mapping between GPIO offset and bit position. For weirder mappings the user can register its own .xlate().

Quoted 2 lines

---

This looks good to me. Please see some nits below.

Quoted 303 lines
 drivers/gpio/Kconfig        |   4 +
 drivers/gpio/Makefile       |   1 +
 drivers/gpio/gpio-regmap.c  | 343 ++++++++++++++++++++++++++++++++++++
 include/linux/gpio-regmap.h |  69 ++++++++
 4 files changed, 417 insertions(+)
 create mode 100644 drivers/gpio/gpio-regmap.c
 create mode 100644 include/linux/gpio-regmap.h
drivers/gpio/Kconfig +4 -0
index 8ef2179fb999..ae3a49a2e970 100644
@@ -73,6 +73,10 @@ config GPIO_GENERIC
        depends on HAS_IOMEM # Only for IOMEM drivers
        tristate
 
+config GPIO_REGMAP
+       depends on REGMAP
+       tristate
+
 # put drivers in the right section, in alphabetical order
 
 # This symbol is selected by both I2C and SPI expanders
drivers/gpio/Makefile +1 -0
index b2cfc21a97f3..93e139fdfa57 100644
@@ -12,6 +12,7 @@ obj-$(CONFIG_GPIO_SYSFS)      += gpiolib-sysfs.o
 obj-$(CONFIG_GPIO_ACPI)                += gpiolib-acpi.o
 
 # Device drivers. Generally keep list sorted alphabetically
+obj-$(CONFIG_GPIO_REGMAP)      += gpio-regmap.o
 obj-$(CONFIG_GPIO_GENERIC)     += gpio-generic.o
 
 # directly supported by gpio-generic
drivers/gpio/gpio-regmap.c new file +262 -0
new file mode 100644
index 000000000000..04939c0a22f9
@@ -0,0 +1,343 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * regmap based generic GPIO driver
+ *
+ * Copyright 2019 Michael Walle <[email protected]>
+ */
+
+#include <linux/gpio/driver.h>
+#include <linux/gpio-regmap.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/regmap.h>
+
+struct gpio_regmap {
+       struct device *parent;
+       struct regmap *regmap;
+       struct gpio_chip gpio_chip;
+
+       int reg_stride;
+       int ngpio_per_reg;
+       unsigned int reg_dat_base;
+       unsigned int reg_set_base;
+       unsigned int reg_clr_base;
+       unsigned int reg_dir_in_base;
+       unsigned int reg_dir_out_base;
+
+       int (*reg_mask_xlate)(struct gpio_regmap *gpio, unsigned int base,
+                             unsigned int offset, unsigned int *reg,
+                             unsigned int *mask);
+
+       void *driver_data;
+};
+
+static unsigned int gpio_regmap_addr(unsigned int addr)
+{
+       return (addr == GPIO_REGMAP_ADDR_ZERO) ? 0 : addr;
+}
+
+/**
+ * gpio_regmap_simple_xlate() - translate base/offset to reg/mask
+ *
+ * Use a simple linear mapping to translate the offset to the bitmask.
+ */
+static int gpio_regmap_simple_xlate(struct gpio_regmap *gpio,
+                                   unsigned int base, unsigned int offset,
+                                   unsigned int *reg, unsigned int *mask)
+{
+       unsigned int line = offset % gpio->ngpio_per_reg;
+       unsigned int stride = offset / gpio->ngpio_per_reg;
+
+       *reg = base + stride * gpio->reg_stride;
+       *mask = BIT(line);
+
+       return 0;
+}
+
+static int gpio_regmap_get(struct gpio_chip *chip, unsigned int offset)
+{
+       struct gpio_regmap *gpio = gpiochip_get_data(chip);
+       unsigned int base, val, reg, mask;
+       int ret;
+
+       /* we might not have an output register if we are input only */
+       if (gpio->reg_dat_base)
+               base = gpio_regmap_addr(gpio->reg_dat_base);
+       else
+               base = gpio_regmap_addr(gpio->reg_set_base);
+
+       ret = gpio->reg_mask_xlate(gpio, base, offset, &reg, &mask);
+       if (ret)
+               return ret;
+
+       ret = regmap_read(gpio->regmap, reg, &val);
+       if (ret)
+               return ret;
+
+       return (val & mask) ? 1 : 0;
+}
+
+static void gpio_regmap_set(struct gpio_chip *chip, unsigned int offset,
+                           int val)
+{
+       struct gpio_regmap *gpio = gpiochip_get_data(chip);
+       unsigned int base = gpio_regmap_addr(gpio->reg_set_base);
+       unsigned int reg, mask;
+
+       gpio->reg_mask_xlate(gpio, base, offset, &reg, &mask);
+       if (val)
+               regmap_update_bits(gpio->regmap, reg, mask, mask);
+       else
+               regmap_update_bits(gpio->regmap, reg, mask, 0);
+}
+
+static void gpio_regmap_set_with_clear(struct gpio_chip *chip,
+                                      unsigned int offset, int val)
+{
+       struct gpio_regmap *gpio = gpiochip_get_data(chip);
+       unsigned int base, reg, mask;
+
+       if (val)
+               base = gpio_regmap_addr(gpio->reg_set_base);
+       else
+               base = gpio_regmap_addr(gpio->reg_clr_base);
+
+       gpio->reg_mask_xlate(gpio, base, offset, &reg, &mask);
+       regmap_write(gpio->regmap, reg, mask);
+}
+
+static int gpio_regmap_get_direction(struct gpio_chip *chip,
+                                    unsigned int offset)
+{
+       struct gpio_regmap *gpio = gpiochip_get_data(chip);
+       unsigned int base, val, reg, mask;
+       int invert, ret;
+
+       if (gpio->reg_dir_out_base) {
+               base = gpio_regmap_addr(gpio->reg_dir_out_base);
+               invert = 0;
+       } else if (gpio->reg_dir_in_base) {
+               base = gpio_regmap_addr(gpio->reg_dir_in_base);
+               invert = 1;
+       } else {
+               return GPIO_LINE_DIRECTION_IN;
+       }
+
+       ret = gpio->reg_mask_xlate(gpio, base, offset, &reg, &mask);
+       if (ret)
+               return ret;
+
+       ret = regmap_read(gpio->regmap, reg, &val);
+       if (ret)
+               return ret;
+
+       if (!!(val & mask) ^ invert)
+               return GPIO_LINE_DIRECTION_OUT;
+       else
+               return GPIO_LINE_DIRECTION_IN;
+}
+
+static int gpio_regmap_set_direction(struct gpio_chip *chip,
+                                    unsigned int offset, bool output)
+{
+       struct gpio_regmap *gpio = gpiochip_get_data(chip);
+       unsigned int base, val, reg, mask;
+       int invert, ret;
+
+       if (gpio->reg_dir_out_base) {
+               base = gpio_regmap_addr(gpio->reg_dir_out_base);
+               invert = 0;
+       } else if (gpio->reg_dir_in_base) {
+               base = gpio_regmap_addr(gpio->reg_dir_in_base);
+               invert = 1;
+       } else {
+               return 0;
+       }
+
+       ret = gpio->reg_mask_xlate(gpio, base, offset, &reg, &mask);
+       if (ret)
+               return ret;
+
+       if (!invert)
+               val = (output) ? mask : 0;
+       else
+               val = (output) ? 0 : mask;
+
+       return regmap_update_bits(gpio->regmap, reg, mask, val);
+}
+
+static int gpio_regmap_direction_input(struct gpio_chip *chip,
+                                      unsigned int offset)
+{
+       return gpio_regmap_set_direction(chip, offset, false);
+}
+
+static int gpio_regmap_direction_output(struct gpio_chip *chip,
+                                       unsigned int offset, int value)
+{
+       gpio_regmap_set(chip, offset, value);
+
+       return gpio_regmap_set_direction(chip, offset, true);
+}
+
+void gpio_regmap_set_drvdata(struct gpio_regmap *gpio, void *data)
+{
+       gpio->driver_data = data;
+}
+EXPORT_SYMBOL_GPL(gpio_regmap_set_drvdata);
+
+void *gpio_regmap_get_drvdata(struct gpio_regmap *gpio)
+{
+       return gpio->driver_data;
+}
+EXPORT_SYMBOL_GPL(gpio_regmap_get_drvdata);
+
+/**
+ * gpio_regmap_register() - Register a generic regmap GPIO controller
+ *
+ * @gpio: gpio_regmap device to register
+ *
+ * Returns 0 on success or an errno on failure.
+ */
+struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config)
+{
+       struct gpio_regmap *gpio;
+       struct gpio_chip *chip;
+       int ret;
+
+       if (!config->parent)
+               return ERR_PTR(-EINVAL);
+
+       if (!config->ngpio)
+               return ERR_PTR(-EINVAL);
+
+       /* we need at least one */
+       if (!config->reg_dat_base && !config->reg_set_base)
+               return ERR_PTR(-EINVAL);
+
+       /* we don't support having both registers simulaniously for now */
+       if (config->reg_dir_out_base && config->reg_dir_in_base)
+               return ERR_PTR(-EINVAL);
+
+       gpio = kzalloc(sizeof(*gpio), GFP_KERNEL);
+       if (!gpio)
+               return ERR_PTR(-ENOMEM);
+
+       gpio->parent = config->parent;
+       gpio->regmap = config->regmap;
+       gpio->ngpio_per_reg = config->ngpio_per_reg;
+       gpio->reg_stride = config->reg_stride;
+       gpio->reg_mask_xlate = config->reg_mask_xlate;
+       gpio->reg_set_base = config->reg_set_base;
+       gpio->reg_clr_base = config->reg_clr_base;
+       gpio->reg_dir_in_base = config->reg_dir_in_base;
+       gpio->reg_dir_out_base = config->reg_dir_out_base;
+
+       /* if not set, assume there is only one register */
+       if (!gpio->ngpio_per_reg)
+               gpio->ngpio_per_reg = config->ngpio;
+
+       /* if not set, assume they are consecutive */
+       if (!gpio->reg_stride)
+               gpio->reg_stride = 1;
+
+       if (!gpio->reg_mask_xlate)
+               gpio->reg_mask_xlate = gpio_regmap_simple_xlate;
+
+       chip = &gpio->gpio_chip;
+       chip->parent = config->parent;
+       chip->base = -1;
+       chip->ngpio = config->ngpio;
+       chip->can_sleep = true;
+
+       if (!chip->label)
+               chip->label = dev_name(config->parent);
+       else
+               chip->label = config->label;
+
+       chip->get = gpio_regmap_get;
+       if (gpio->reg_set_base && gpio->reg_clr_base)
+               chip->set = gpio_regmap_set_with_clear;
+       else if (gpio->reg_set_base)
+               chip->set = gpio_regmap_set;

drivers/gpio/gpio-regmap.c line 272

Quoted 10 lines
drivers/gpio/gpio-regmap.c new file +10 -0
+
+       if (gpio->reg_dir_in_base || gpio->reg_dir_out_base) {
+               chip->get_direction = gpio_regmap_get_direction;
+               chip->direction_input = gpio_regmap_direction_input;
+               chip->direction_output = gpio_regmap_direction_output;
+       }
+
+       ret = gpiochip_add_data(chip, gpio);
+       if (ret < 0) {
+               kfree(gpio);

Maybe add a second label at the end of the function?

Quoted 77 lines
drivers/gpio/gpio-regmap.c new file +71 -0
+               return ERR_PTR(ret);
+       }
+
+       if (config->irq_domain) {
+               ret = gpiochip_irqchip_add_domain(chip, config->irq_domain);
+               if (ret < 0)
+                       goto err;
+       }
+
+       return gpio;
+
+err:
+       gpiochip_remove(chip);
+       kfree(gpio);
+       return ERR_PTR(ret);
+}
+EXPORT_SYMBOL_GPL(gpio_regmap_register);
+
+/**
+ * gpio_regmap_unregister() - Unregister a generic regmap GPIO controller
+ *
+ * @gpio: gpio_regmap device to unregister
+ */
+void gpio_regmap_unregister(struct gpio_regmap *gpio)
+{
+       gpiochip_remove(&gpio->gpio_chip);
+       kfree(gpio);
+}
+EXPORT_SYMBOL_GPL(gpio_regmap_unregister);
+
+static void devm_gpio_regmap_unregister(struct device *dev, void *res)
+{
+       gpio_regmap_unregister(*(struct gpio_regmap **)res);
+}
+
+/**
+ * devm_gpio_regmap_register() - resource managed gpio_regmap_register()
+ *
+ * @dev: device that is registering this GPIO device
+ * @gpio: gpio_regmap device to register
+ *
+ * Managed gpio_regmap_register(). For generic regmap GPIO device registered by
+ * this function, gpio_regmap_unregister() is automatically called on driver
+ * detach. See gpio_regmap_register() for more information.
+ */
+struct gpio_regmap *devm_gpio_regmap_register(struct device *dev,
+                                             const struct gpio_regmap_config *config)
+{
+       struct gpio_regmap **ptr, *gpio;
+
+       ptr = devres_alloc(devm_gpio_regmap_unregister, sizeof(*ptr),
+                          GFP_KERNEL);
+       if (!ptr)
+               return ERR_PTR(-ENOMEM);
+
+       gpio = gpio_regmap_register(config);
+
+       if (!IS_ERR(gpio)) {
+               *ptr = gpio;
+               devres_add(dev, ptr);
+       } else {
+               devres_free(ptr);
+       }
+
+       return gpio;
+}
+EXPORT_SYMBOL_GPL(devm_gpio_regmap_register);
+
+MODULE_AUTHOR("Michael Walle <[email protected]>");
+MODULE_DESCRIPTION("GPIO generic regmap driver core");
+MODULE_LICENSE("GPL");
include/linux/gpio-regmap.h new file +0 -0
new file mode 100644
index 000000000000..a868cbcde6e9

include/linux/gpio-regmap.h line 10

Quoted 10 lines
include/linux/gpio-regmap.h new file +10 -0
@@ -0,0 +1,69 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef _LINUX_GPIO_REGMAP_H
+#define _LINUX_GPIO_REGMAP_H
+
+struct gpio_regmap;
+
+#define GPIO_REGMAP_ADDR_ZERO ((unsigned long)(-1))
+#define GPIO_REGMAP_ADDR(addr) ((addr) ? : GPIO_REGMAP_ADDR_ZERO)
+

What if the addr is actually 0? Maybe drop GPIO_REGMAP_ADDR and require users to set unused registers to GPIO_REGMAP_ADDR_ZERO?

Quoted 4 lines
include/linux/gpio-regmap.h new file +4 -0
+/**
+ * struct gpio_regmap_config - Description of a generic regmap gpio_chip.
+ *
+ * @parent:            The parent device

include/linux/gpio-regmap.h line 24

Quoted 10 lines
include/linux/gpio-regmap.h new file +10 -0
+ * @regmap:            The regmap used to access the registers
+ *                     given, the name of the device is used
+ * @label:             (Optional) Descriptive name for GPIO controller.
+ *                     If not given, the name of the device is used.
+ * @ngpio:             Number of GPIOs
+ * @reg_dat_base:      (Optional) (in) register base address
+ * @reg_set_base:      (Optional) set register base address
+ * @reg_clr_base:      (Optional) clear register base address
+ * @reg_dir_in_base:   (Optional) out setting register base address
+ * @reg_dir_out_base:  (Optional) in setting register base address

The two above are inverted I think? Also: why the limitation of only supporting one at a time?

Quoted 48 lines
include/linux/gpio-regmap.h new file +45 -1
+ * @reg_stride:                (Optional) May be set if the registers (of the
+ *                     same type, dat, set, etc) are not consecutive.
+ * @ngpio_per_reg:     Number of GPIOs per register
+ * @irq_domain:                (Optional) IRQ domain if the controller is
+ *                     interrupt-capable
+ * @reg_mask_xlate:     (Optional) Translates base address and GPIO
+ *                     offset to a register/bitmask pair. If not
+ *                     given the default gpio_regmap_simple_xlate()
+ *                     is used.
+ *
+ * The reg_mask_xlate translates a given base address and GPIO offset to
+ * register and mask pair. The base address is one of the given reg_*_base.
+ *
+ * All base addresses may have the special value GPIO_REGMAP_ADDR_ZERO
+ * which forces the address to the value 0.
+ */
+struct gpio_regmap_config {
+       struct device *parent;
+       struct regmap *regmap;
+
+       const char *label;
+       int ngpio;
+
+       unsigned int reg_dat_base;
+       unsigned int reg_set_base;
+       unsigned int reg_clr_base;
+       unsigned int reg_dir_in_base;
+       unsigned int reg_dir_out_base;
+       int reg_stride;
+       int ngpio_per_reg;
+       struct irq_domain *irq_domain;
+
+       int (*reg_mask_xlate)(struct gpio_regmap *gpio, unsigned int base,
+                             unsigned int offset, unsigned int *reg,
+                             unsigned int *mask);
+};
+
+struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config);
+void gpio_regmap_unregister(struct gpio_regmap *gpio);
+struct gpio_regmap *devm_gpio_regmap_register(struct device *dev,
+                                             const struct gpio_regmap_config *config);
+void gpio_regmap_set_drvdata(struct gpio_regmap *gpio, void *data);
+void *gpio_regmap_get_drvdata(struct gpio_regmap *gpio);
+
+#endif /* _LINUX_GPIO_REGMAP_H */
--

2.20.1

#50 lore raw

Re: [PATCH v3 10/16] gpio: add a reusable generic gpio_chip using regmap

Am 2020-05-12 14:48, schrieb Bartosz Golaszewski:

Quoted 342 lines

czw., 23 kwi 2020 o 19:46 Michael Walle <[email protected]> napisał(a):

Quoted 18 lines

There are quite a lot simple GPIO controller which are using regmap to access the hardware. This driver tries to be a base to unify existing code into one place. This won't cover everything but it should be a good starting point.

It does not implement its own irq_chip because there is already a generic one for regmap based devices. Instead, the irq_chip will be instantiated in the parent driver and its irq domain will be associate to this driver.

For now it consists of the usual registers, like set (and an optional clear) data register, an input register and direction registers. Out-of-the-box, it supports consecutive register mappings and mappings where the registers have gaps between them with a linear mapping between GPIO offset and bit position. For weirder mappings the user can register its own .xlate().

Quoted 2 lines

---

This looks good to me. Please see some nits below.

Quoted 318 lines
 drivers/gpio/Kconfig        |   4 +
 drivers/gpio/Makefile       |   1 +
 drivers/gpio/gpio-regmap.c  | 343 
++++++++++++++++++++++++++++++++++++
 include/linux/gpio-regmap.h |  69 ++++++++
 4 files changed, 417 insertions(+)
 create mode 100644 drivers/gpio/gpio-regmap.c
 create mode 100644 include/linux/gpio-regmap.h
drivers/gpio/Kconfig +4 -0
index 8ef2179fb999..ae3a49a2e970 100644
@@ -73,6 +73,10 @@ config GPIO_GENERIC
        depends on HAS_IOMEM # Only for IOMEM drivers
        tristate
 
+config GPIO_REGMAP
+       depends on REGMAP
+       tristate
+
 # put drivers in the right section, in alphabetical order
 
 # This symbol is selected by both I2C and SPI expanders
drivers/gpio/Makefile +1 -0
index b2cfc21a97f3..93e139fdfa57 100644
@@ -12,6 +12,7 @@ obj-$(CONFIG_GPIO_SYSFS)      += gpiolib-sysfs.o
 obj-$(CONFIG_GPIO_ACPI)                += gpiolib-acpi.o
 
 # Device drivers. Generally keep list sorted alphabetically
+obj-$(CONFIG_GPIO_REGMAP)      += gpio-regmap.o
 obj-$(CONFIG_GPIO_GENERIC)     += gpio-generic.o
 
 # directly supported by gpio-generic
drivers/gpio/gpio-regmap.c new file +27 -0
new file mode 100644
index 000000000000..04939c0a22f9
@@ -0,0 +1,343 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * regmap based generic GPIO driver
+ *
+ * Copyright 2019 Michael Walle <[email protected]>
+ */
+
+#include <linux/gpio/driver.h>
+#include <linux/gpio-regmap.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/regmap.h>
+
+struct gpio_regmap {
+       struct device *parent;
+       struct regmap *regmap;
+       struct gpio_chip gpio_chip;
+
+       int reg_stride;
+       int ngpio_per_reg;
+       unsigned int reg_dat_base;
+       unsigned int reg_set_base;
+       unsigned int reg_clr_base;
+       unsigned int reg_dir_in_base;
+       unsigned int reg_dir_out_base;
+
+       int (*reg_mask_xlate)(struct gpio_regmap *gpio, unsigned int 

base,

drivers/gpio/gpio-regmap.c new file +15 -0
+                             unsigned int offset, unsigned int *reg,
+                             unsigned int *mask);
+
+       void *driver_data;
+};
+
+static unsigned int gpio_regmap_addr(unsigned int addr)
+{
+       return (addr == GPIO_REGMAP_ADDR_ZERO) ? 0 : addr;
+}
+
+/**
+ * gpio_regmap_simple_xlate() - translate base/offset to reg/mask
+ *
+ * Use a simple linear mapping to translate the offset to the 

bitmask.
+ */

drivers/gpio/gpio-regmap.c new file +2 -0
+static int gpio_regmap_simple_xlate(struct gpio_regmap *gpio,
+                                   unsigned int base, unsigned int 

offset,
+ unsigned int *reg, unsigned int
*mask)

drivers/gpio/gpio-regmap.c new file +11 -0
+{
+       unsigned int line = offset % gpio->ngpio_per_reg;
+       unsigned int stride = offset / gpio->ngpio_per_reg;
+
+       *reg = base + stride * gpio->reg_stride;
+       *mask = BIT(line);
+
+       return 0;
+}
+
+static int gpio_regmap_get(struct gpio_chip *chip, unsigned int 

offset)

drivers/gpio/gpio-regmap.c new file +6 -0
+{
+       struct gpio_regmap *gpio = gpiochip_get_data(chip);
+       unsigned int base, val, reg, mask;
+       int ret;
+
+       /* we might not have an output register if we are input only 

*/

drivers/gpio/gpio-regmap.c new file +17 -0
+       if (gpio->reg_dat_base)
+               base = gpio_regmap_addr(gpio->reg_dat_base);
+       else
+               base = gpio_regmap_addr(gpio->reg_set_base);
+
+       ret = gpio->reg_mask_xlate(gpio, base, offset, &reg, &mask);
+       if (ret)
+               return ret;
+
+       ret = regmap_read(gpio->regmap, reg, &val);
+       if (ret)
+               return ret;
+
+       return (val & mask) ? 1 : 0;
+}
+
+static void gpio_regmap_set(struct gpio_chip *chip, unsigned int 

offset,

drivers/gpio/gpio-regmap.c new file +96 -0
+                           int val)
+{
+       struct gpio_regmap *gpio = gpiochip_get_data(chip);
+       unsigned int base = gpio_regmap_addr(gpio->reg_set_base);
+       unsigned int reg, mask;
+
+       gpio->reg_mask_xlate(gpio, base, offset, &reg, &mask);
+       if (val)
+               regmap_update_bits(gpio->regmap, reg, mask, mask);
+       else
+               regmap_update_bits(gpio->regmap, reg, mask, 0);
+}
+
+static void gpio_regmap_set_with_clear(struct gpio_chip *chip,
+                                      unsigned int offset, int val)
+{
+       struct gpio_regmap *gpio = gpiochip_get_data(chip);
+       unsigned int base, reg, mask;
+
+       if (val)
+               base = gpio_regmap_addr(gpio->reg_set_base);
+       else
+               base = gpio_regmap_addr(gpio->reg_clr_base);
+
+       gpio->reg_mask_xlate(gpio, base, offset, &reg, &mask);
+       regmap_write(gpio->regmap, reg, mask);
+}
+
+static int gpio_regmap_get_direction(struct gpio_chip *chip,
+                                    unsigned int offset)
+{
+       struct gpio_regmap *gpio = gpiochip_get_data(chip);
+       unsigned int base, val, reg, mask;
+       int invert, ret;
+
+       if (gpio->reg_dir_out_base) {
+               base = gpio_regmap_addr(gpio->reg_dir_out_base);
+               invert = 0;
+       } else if (gpio->reg_dir_in_base) {
+               base = gpio_regmap_addr(gpio->reg_dir_in_base);
+               invert = 1;
+       } else {
+               return GPIO_LINE_DIRECTION_IN;
+       }
+
+       ret = gpio->reg_mask_xlate(gpio, base, offset, &reg, &mask);
+       if (ret)
+               return ret;
+
+       ret = regmap_read(gpio->regmap, reg, &val);
+       if (ret)
+               return ret;
+
+       if (!!(val & mask) ^ invert)
+               return GPIO_LINE_DIRECTION_OUT;
+       else
+               return GPIO_LINE_DIRECTION_IN;
+}
+
+static int gpio_regmap_set_direction(struct gpio_chip *chip,
+                                    unsigned int offset, bool output)
+{
+       struct gpio_regmap *gpio = gpiochip_get_data(chip);
+       unsigned int base, val, reg, mask;
+       int invert, ret;
+
+       if (gpio->reg_dir_out_base) {
+               base = gpio_regmap_addr(gpio->reg_dir_out_base);
+               invert = 0;
+       } else if (gpio->reg_dir_in_base) {
+               base = gpio_regmap_addr(gpio->reg_dir_in_base);
+               invert = 1;
+       } else {
+               return 0;
+       }
+
+       ret = gpio->reg_mask_xlate(gpio, base, offset, &reg, &mask);
+       if (ret)
+               return ret;
+
+       if (!invert)
+               val = (output) ? mask : 0;
+       else
+               val = (output) ? 0 : mask;
+
+       return regmap_update_bits(gpio->regmap, reg, mask, val);
+}
+
+static int gpio_regmap_direction_input(struct gpio_chip *chip,
+                                      unsigned int offset)
+{
+       return gpio_regmap_set_direction(chip, offset, false);
+}
+
+static int gpio_regmap_direction_output(struct gpio_chip *chip,
+                                       unsigned int offset, int 

value)

drivers/gpio/gpio-regmap.c new file +26 -0
+{
+       gpio_regmap_set(chip, offset, value);
+
+       return gpio_regmap_set_direction(chip, offset, true);
+}
+
+void gpio_regmap_set_drvdata(struct gpio_regmap *gpio, void *data)
+{
+       gpio->driver_data = data;
+}
+EXPORT_SYMBOL_GPL(gpio_regmap_set_drvdata);
+
+void *gpio_regmap_get_drvdata(struct gpio_regmap *gpio)
+{
+       return gpio->driver_data;
+}
+EXPORT_SYMBOL_GPL(gpio_regmap_get_drvdata);
+
+/**
+ * gpio_regmap_register() - Register a generic regmap GPIO controller
+ *
+ * @gpio: gpio_regmap device to register
+ *
+ * Returns 0 on success or an errno on failure.
+ */
+struct gpio_regmap *gpio_regmap_register(const struct 

gpio_regmap_config *config)

drivers/gpio/gpio-regmap.c new file +16 -0
+{
+       struct gpio_regmap *gpio;
+       struct gpio_chip *chip;
+       int ret;
+
+       if (!config->parent)
+               return ERR_PTR(-EINVAL);
+
+       if (!config->ngpio)
+               return ERR_PTR(-EINVAL);
+
+       /* we need at least one */
+       if (!config->reg_dat_base && !config->reg_set_base)
+               return ERR_PTR(-EINVAL);
+
+       /* we don't support having both registers simulaniously for 

now */

drivers/gpio/gpio-regmap.c new file +48 -0
+       if (config->reg_dir_out_base && config->reg_dir_in_base)
+               return ERR_PTR(-EINVAL);
+
+       gpio = kzalloc(sizeof(*gpio), GFP_KERNEL);
+       if (!gpio)
+               return ERR_PTR(-ENOMEM);
+
+       gpio->parent = config->parent;
+       gpio->regmap = config->regmap;
+       gpio->ngpio_per_reg = config->ngpio_per_reg;
+       gpio->reg_stride = config->reg_stride;
+       gpio->reg_mask_xlate = config->reg_mask_xlate;
+       gpio->reg_set_base = config->reg_set_base;
+       gpio->reg_clr_base = config->reg_clr_base;
+       gpio->reg_dir_in_base = config->reg_dir_in_base;
+       gpio->reg_dir_out_base = config->reg_dir_out_base;
+
+       /* if not set, assume there is only one register */
+       if (!gpio->ngpio_per_reg)
+               gpio->ngpio_per_reg = config->ngpio;
+
+       /* if not set, assume they are consecutive */
+       if (!gpio->reg_stride)
+               gpio->reg_stride = 1;
+
+       if (!gpio->reg_mask_xlate)
+               gpio->reg_mask_xlate = gpio_regmap_simple_xlate;
+
+       chip = &gpio->gpio_chip;
+       chip->parent = config->parent;
+       chip->base = -1;
+       chip->ngpio = config->ngpio;
+       chip->can_sleep = true;
+
+       if (!chip->label)
+               chip->label = dev_name(config->parent);
+       else
+               chip->label = config->label;
+
+       chip->get = gpio_regmap_get;
+       if (gpio->reg_set_base && gpio->reg_clr_base)
+               chip->set = gpio_regmap_set_with_clear;
+       else if (gpio->reg_set_base)
+               chip->set = gpio_regmap_set;
+
+       if (gpio->reg_dir_in_base || gpio->reg_dir_out_base) {
+               chip->get_direction = gpio_regmap_get_direction;
+               chip->direction_input = gpio_regmap_direction_input;
Quoted 8 lines

drivers/gpio/gpio-regmap.c line 272

Quoted 6 lines
drivers/gpio/gpio-regmap.c new file +6 -0
+               chip->direction_output = gpio_regmap_direction_output;
+       }
+
+       ret = gpiochip_add_data(chip, gpio);
+       if (ret < 0) {
+               kfree(gpio);

Maybe add a second label at the end of the function?

sure

Quoted 88 lines
Quoted 88 lines
drivers/gpio/gpio-regmap.c new file +5 -0
+               return ERR_PTR(ret);
+       }
+
+       if (config->irq_domain) {
+               ret = gpiochip_irqchip_add_domain(chip, 

config->irq_domain);

drivers/gpio/gpio-regmap.c new file +15 -0
+               if (ret < 0)
+                       goto err;
+       }
+
+       return gpio;
+
+err:
+       gpiochip_remove(chip);
+       kfree(gpio);
+       return ERR_PTR(ret);
+}
+EXPORT_SYMBOL_GPL(gpio_regmap_register);
+
+/**
+ * gpio_regmap_unregister() - Unregister a generic regmap GPIO 

controller
+ *
+ * @gpio: gpio_regmap device to unregister
+ */

drivers/gpio/gpio-regmap.c new file +8 -0
+void gpio_regmap_unregister(struct gpio_regmap *gpio)
+{
+       gpiochip_remove(&gpio->gpio_chip);
+       kfree(gpio);
+}
+EXPORT_SYMBOL_GPL(gpio_regmap_unregister);
+
+static void devm_gpio_regmap_unregister(struct device *dev, void 

*res)

drivers/gpio/gpio-regmap.c new file +6 -0
+{
+       gpio_regmap_unregister(*(struct gpio_regmap **)res);
+}
+
+/**
+ * devm_gpio_regmap_register() - resource managed 

gpio_regmap_register()
+ *
+ * @dev: device that is registering this GPIO device
+ * @gpio: gpio_regmap device to register
+ *
+ * Managed gpio_regmap_register(). For generic regmap GPIO device registered by
+ * this function, gpio_regmap_unregister() is automatically called on driver
+ * detach. See gpio_regmap_register() for more information.
+ */

drivers/gpio/gpio-regmap.c new file +2 -0
+struct gpio_regmap *devm_gpio_regmap_register(struct device *dev,
+                                             const struct 

gpio_regmap_config *config)

drivers/gpio/gpio-regmap.c new file +24 -0
+{
+       struct gpio_regmap **ptr, *gpio;
+
+       ptr = devres_alloc(devm_gpio_regmap_unregister, sizeof(*ptr),
+                          GFP_KERNEL);
+       if (!ptr)
+               return ERR_PTR(-ENOMEM);
+
+       gpio = gpio_regmap_register(config);
+
+       if (!IS_ERR(gpio)) {
+               *ptr = gpio;
+               devres_add(dev, ptr);
+       } else {
+               devres_free(ptr);
+       }
+
+       return gpio;
+}
+EXPORT_SYMBOL_GPL(devm_gpio_regmap_register);
+
+MODULE_AUTHOR("Michael Walle <[email protected]>");
+MODULE_DESCRIPTION("GPIO generic regmap driver core");
+MODULE_LICENSE("GPL");
include/linux/gpio-regmap.h new file +4 -0
new file mode 100644
index 000000000000..a868cbcde6e9
@@ -0,0 +1,69 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef _LINUX_GPIO_REGMAP_H
+#define _LINUX_GPIO_REGMAP_H
Quoted 8 lines

include/linux/gpio-regmap.h line 10

Quoted 6 lines
include/linux/gpio-regmap.h new file +6 -0
+
+struct gpio_regmap;
+
+#define GPIO_REGMAP_ADDR_ZERO ((unsigned long)(-1))
+#define GPIO_REGMAP_ADDR(addr) ((addr) ? : GPIO_REGMAP_ADDR_ZERO)
+

What if the addr is actually 0?

Then the driver has to set GPIO_REGMAP_ADDR_ZERO or use the convenience macro GPIO_REGMAP_ADDR.

So you can have

  struct gpio_regmap_config config = { 0 };
  config.reg_dat_base = 0x10;
  config.reg_dir_out_base = 0x20;

or

  config.reg_dat_base = GPIO_REGMAP_ADDR_ZERO;

or if you can't be sure if the RHS value might be zero:

  config.reg_dat_base = GPIO_REGMAP_ADDR(reg);
Quoted 2 lines

Maybe drop GPIO_REGMAP_ADDR and require users to set unused registers to GPIO_REGMAP_ADDR_ZERO?

Thats bad because:
* you'd have to set plenty of unused base registers for a simple driver
* if there will be additional properties in the future, you have to
touch
all other drivers, because they are initialized as 0 (ie. valid reg
0).

Quoted 17 lines
Quoted 4 lines
include/linux/gpio-regmap.h new file +2 -0
+/**
+ * struct gpio_regmap_config - Description of a generic regmap 

gpio_chip.
+ *

Quoted 12 lines
+ * @parent:            The parent device
+ * @regmap:            The regmap used to access the registers
+ *                     given, the name of the device is used
+ * @label:             (Optional) Descriptive name for GPIO 
controller.
+ *                     If not given, the name of the device is used.
+ * @ngpio:             Number of GPIOs
+ * @reg_dat_base:      (Optional) (in) register base address
+ * @reg_set_base:      (Optional) set register base address
+ * @reg_clr_base:      (Optional) clear register base address
+ * @reg_dir_in_base:   (Optional) out setting register base address
+ * @reg_dir_out_base:  (Optional) in setting register base address
Quoted 1 line

The two above are inverted I think?

good catch.

Quoted 1 line

Also: why the limitation of only supporting one at a time?

they should be exclusive, either you have a register where you set the output bits to one, or the input bits. Maybe this need a bit more context above. in gpio-mmio.c you can set both and both are used in set_direction(), but only one is read in get_direction().

That being said, I have no strong opinion wether they should be exclusive or not, besides the symmetry of set_/get_direction().

-michael

Quoted 57 lines
Quoted 57 lines

+ * @reg_stride: (Optional) May be set if the registers
(of the
+ * same type, dat, set, etc) are not consecutive.
+ * @ngpio_per_reg: Number of GPIOs per register
+ * @irq_domain: (Optional) IRQ domain if the
controller is
+ * interrupt-capable
+ * @reg_mask_xlate: (Optional) Translates base address and GPIO

+ *                     offset to a register/bitmask pair. If not
+ *                     given the default gpio_regmap_simple_xlate()
+ *                     is used.

+ *
+ * The reg_mask_xlate translates a given base address and GPIO offset to
+ * register and mask pair. The base address is one of the given reg_*_base.
+ *
+ * All base addresses may have the special value GPIO_REGMAP_ADDR_ZERO
+ * which forces the address to the value 0.
+ */

include/linux/gpio-regmap.h new file +17 -0
+struct gpio_regmap_config {
+       struct device *parent;
+       struct regmap *regmap;
+
+       const char *label;
+       int ngpio;
+
+       unsigned int reg_dat_base;
+       unsigned int reg_set_base;
+       unsigned int reg_clr_base;
+       unsigned int reg_dir_in_base;
+       unsigned int reg_dir_out_base;
+       int reg_stride;
+       int ngpio_per_reg;
+       struct irq_domain *irq_domain;
+
+       int (*reg_mask_xlate)(struct gpio_regmap *gpio, unsigned int 

base,

include/linux/gpio-regmap.h new file +5 -0
+                             unsigned int offset, unsigned int *reg,
+                             unsigned int *mask);
+};
+
+struct gpio_regmap *gpio_regmap_register(const struct 

gpio_regmap_config *config);

include/linux/gpio-regmap.h new file +3 -0
+void gpio_regmap_unregister(struct gpio_regmap *gpio);
+struct gpio_regmap *devm_gpio_regmap_register(struct device *dev,
+                                             const struct 

gpio_regmap_config *config);

include/linux/gpio-regmap.h new file +4 -1
+void gpio_regmap_set_drvdata(struct gpio_regmap *gpio, void *data);
+void *gpio_regmap_get_drvdata(struct gpio_regmap *gpio);
+
+#endif /* _LINUX_GPIO_REGMAP_H */
--

2.20.1

#51 lore raw

Re: [PATCH v3 10/16] gpio: add a reusable generic gpio_chip using regmap

wt., 12 maj 2020 o 16:41 Michael Walle <[email protected]> napisał(a):

Quoted 80 lines
Quoted 15 lines
Quoted 15 lines
drivers/gpio/gpio-regmap.c new file +4 -0
+
+MODULE_AUTHOR("Michael Walle <[email protected]>");
+MODULE_DESCRIPTION("GPIO generic regmap driver core");
+MODULE_LICENSE("GPL");
include/linux/gpio-regmap.h new file +4 -0
new file mode 100644
index 000000000000..a868cbcde6e9
@@ -0,0 +1,69 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef _LINUX_GPIO_REGMAP_H
+#define _LINUX_GPIO_REGMAP_H
Quoted 8 lines

include/linux/gpio-regmap.h line 10

Quoted 6 lines
include/linux/gpio-regmap.h new file +6 -0
+
+struct gpio_regmap;
+
+#define GPIO_REGMAP_ADDR_ZERO ((unsigned long)(-1))
+#define GPIO_REGMAP_ADDR(addr) ((addr) ? : GPIO_REGMAP_ADDR_ZERO)
+

What if the addr is actually 0?

Then the driver has to set GPIO_REGMAP_ADDR_ZERO or use the convenience macro GPIO_REGMAP_ADDR.

So you can have

   struct gpio_regmap_config config = { 0 };
   config.reg_dat_base = 0x10;
   config.reg_dir_out_base = 0x20;

or

   config.reg_dat_base = GPIO_REGMAP_ADDR_ZERO;

or if you can't be sure if the RHS value might be zero:

   config.reg_dat_base = GPIO_REGMAP_ADDR(reg);
Quoted 2 lines

Maybe drop GPIO_REGMAP_ADDR and require users to set unused registers to GPIO_REGMAP_ADDR_ZERO?

Thats bad because:
* you'd have to set plenty of unused base registers for a simple driver
* if there will be additional properties in the future, you have to
touch
all other drivers, because they are initialized as 0 (ie. valid reg
0).

Quoted 17 lines
Quoted 4 lines
include/linux/gpio-regmap.h new file +2 -0
+/**
+ * struct gpio_regmap_config - Description of a generic regmap

gpio_chip.
+ *

Quoted 12 lines
+ * @parent:            The parent device
+ * @regmap:            The regmap used to access the registers
+ *                     given, the name of the device is used
+ * @label:             (Optional) Descriptive name for GPIO
controller.
+ *                     If not given, the name of the device is used.
+ * @ngpio:             Number of GPIOs
+ * @reg_dat_base:      (Optional) (in) register base address
+ * @reg_set_base:      (Optional) set register base address
+ * @reg_clr_base:      (Optional) clear register base address
+ * @reg_dir_in_base:   (Optional) out setting register base address
+ * @reg_dir_out_base:  (Optional) in setting register base address
Quoted 1 line

The two above are inverted I think?

good catch.

Quoted 1 line

Also: why the limitation of only supporting one at a time?

they should be exclusive, either you have a register where you set the output bits to one, or the input bits. Maybe this need a bit more context
above. in gpio-mmio.c you can set both and both are used in set_direction(), but only one is read in get_direction().

Quoted 6 lines

That being said, I have no strong opinion wether they should be exclusive
or not, besides the symmetry of set_/get_direction().

-michael

Sorry for the late response, your comments make sense to me. Are you going to submit a v4 before the v5.8 merge window?

Bart

#52 lore raw

Re: [PATCH v3 10/16] gpio: add a reusable generic gpio_chip using regmap

Am 2020-05-25 11:05, schrieb Bartosz Golaszewski:

Quoted 87 lines

wt., 12 maj 2020 o 16:41 Michael Walle <[email protected]> napisał(a):

Quoted 86 lines
Quoted 15 lines
Quoted 15 lines
drivers/gpio/gpio-regmap.c new file +4 -0
+
+MODULE_AUTHOR("Michael Walle <[email protected]>");
+MODULE_DESCRIPTION("GPIO generic regmap driver core");
+MODULE_LICENSE("GPL");
include/linux/gpio-regmap.h new file +4 -0
new file mode 100644
index 000000000000..a868cbcde6e9
@@ -0,0 +1,69 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef _LINUX_GPIO_REGMAP_H
+#define _LINUX_GPIO_REGMAP_H
Quoted 8 lines

include/linux/gpio-regmap.h line 10

Quoted 6 lines
include/linux/gpio-regmap.h new file +6 -0
+
+struct gpio_regmap;
+
+#define GPIO_REGMAP_ADDR_ZERO ((unsigned long)(-1))
+#define GPIO_REGMAP_ADDR(addr) ((addr) ? : GPIO_REGMAP_ADDR_ZERO)
+

What if the addr is actually 0?

Then the driver has to set GPIO_REGMAP_ADDR_ZERO or use the convenience macro GPIO_REGMAP_ADDR.

So you can have

   struct gpio_regmap_config config = { 0 };
   config.reg_dat_base = 0x10;
   config.reg_dir_out_base = 0x20;

or

   config.reg_dat_base = GPIO_REGMAP_ADDR_ZERO;

or if you can't be sure if the RHS value might be zero:

   config.reg_dat_base = GPIO_REGMAP_ADDR(reg);
Quoted 2 lines

Maybe drop GPIO_REGMAP_ADDR and require users to set unused registers to GPIO_REGMAP_ADDR_ZERO?

Thats bad because:
* you'd have to set plenty of unused base registers for a simple
driver
* if there will be additional properties in the future, you have to
touch
all other drivers, because they are initialized as 0 (ie. valid
reg
0).

Quoted 17 lines
Quoted 4 lines
include/linux/gpio-regmap.h new file +2 -0
+/**
+ * struct gpio_regmap_config - Description of a generic regmap

gpio_chip.
+ *

Quoted 12 lines
+ * @parent:            The parent device
+ * @regmap:            The regmap used to access the registers
+ *                     given, the name of the device is used
+ * @label:             (Optional) Descriptive name for GPIO
controller.
+ *                     If not given, the name of the device is used.
+ * @ngpio:             Number of GPIOs
+ * @reg_dat_base:      (Optional) (in) register base address
+ * @reg_set_base:      (Optional) set register base address
+ * @reg_clr_base:      (Optional) clear register base address
+ * @reg_dir_in_base:   (Optional) out setting register base address
+ * @reg_dir_out_base:  (Optional) in setting register base address
Quoted 1 line

The two above are inverted I think?

good catch.

Quoted 1 line

Also: why the limitation of only supporting one at a time?

they should be exclusive, either you have a register where you set the output bits to one, or the input bits. Maybe this need a bit more context
above. in gpio-mmio.c you can set both and both are used in set_direction(), but only one is read in get_direction().

That being said, I have no strong opinion wether they should be exclusive
or not, besides the symmetry of set_/get_direction().

Quoted 5 lines
Quoted 2 lines

-michael

Sorry for the late response, your comments make sense to me. Are you going to submit a v4 before the v5.8 merge window?

I'm currently stuck with how to handle the MFD part. Ie. Rob doesn't seem to like the logicial device numbering - or at least there wasn't an answer to that one anymore, see patch 5/16.

If you like I could submit this patch on its own. But then there wouldn't be a user for it.

-michael

#53 lore raw

Re: [PATCH v3 10/16] gpio: add a reusable generic gpio_chip using regmap

Quoted 2 lines · Michael Walle

If you like I could submit this patch on its own. But then there wouldn't be a user for it.

I'm pretty much fine with that, we do merge code that has no users if we anticipate they will be around the corner.

Yours,
Linus Walleij

#54 lore raw

Re: [PATCH v3 10/16] gpio: add a reusable generic gpio_chip using regmap

Quoted 7 lines · Linus Walleij
Quoted 2 lines · Michael Walle

If you like I could submit this patch on its own. But then there wouldn't be a user for it.

I'm pretty much fine with that, we do merge code that has no users if we anticipate they will be around the corner.

I remember we discussed with Pierre to use it for his ASoC work. Pierre, does it sound useful for you?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#55 lore raw

PATCH v3 11/16 gpio: add support for the sl28cpld GPIO controller

In reply to Michael Walle

This adds support for the GPIO controller of the sl28 board management controller. This driver is part of a multi-function device.

---
 drivers/gpio/Kconfig         |  11 +++
 drivers/gpio/Makefile        |   1 +
 drivers/gpio/gpio-sl28cpld.c | 184 +++++++++++++++++++++++++++++++++++
 3 files changed, 196 insertions(+)
 create mode 100644 drivers/gpio/gpio-sl28cpld.c
drivers/gpio/Kconfig +11 -0
index ae3a49a2e970..95e2f223b34e 100644
@@ -1215,6 +1215,17 @@ config GPIO_RC5T583
 	  This driver provides the support for driving/reading the gpio pins
 	  of RC5T583 device through standard gpio library.
 
+config GPIO_SL28CPLD
+	tristate "Kontron sl28 GPIO"
+	depends on MFD_SL28CPLD
+	select GPIO_REGMAP
+	select GPIOLIB_IRQCHIP
+	help
+	  This enables support for the GPIOs found on the Kontron sl28 CPLD.
+
+	  This driver can also be built as a module. If so, the module will be
+	  called gpio-sl28cpld.
+
 config GPIO_STMPE
 	bool "STMPE GPIOs"
 	depends on MFD_STMPE
drivers/gpio/Makefile +1 -0
index 93e139fdfa57..f50ccf13f5eb 100644
@@ -129,6 +129,7 @@ obj-$(CONFIG_GPIO_SCH311X)		+= gpio-sch311x.o
 obj-$(CONFIG_GPIO_SCH)			+= gpio-sch.o
 obj-$(CONFIG_GPIO_SIFIVE)		+= gpio-sifive.o
 obj-$(CONFIG_GPIO_SIOX)			+= gpio-siox.o
+obj-$(CONFIG_GPIO_SL28CPLD)		+= gpio-sl28cpld.o
 obj-$(CONFIG_GPIO_SODAVILLE)		+= gpio-sodaville.o
 obj-$(CONFIG_GPIO_SPEAR_SPICS)		+= gpio-spear-spics.o
 obj-$(CONFIG_GPIO_SPRD)			+= gpio-sprd.o
drivers/gpio/gpio-sl28cpld.c new file +184 -0

184 lines not on this page · raw message

Signature · 1 line
2.20.1
#56 lore raw

Re: [PATCH v3 11/16] gpio: add support for the sl28cpld GPIO controller

Quoted 5 lines · Michael Walle
drivers/gpio/gpio-sl28cpld.c new file +5 -0
+struct sl28cpld_gpio {
+	struct regmap_irq_chip irq_chip;
+	struct regmap_irq_chip_data *irq_data;
+};
+

drivers/gpio/gpio-sl28cpld.c line 51

Quoted 10 lines
drivers/gpio/gpio-sl28cpld.c new file +10 -0
+static const struct regmap_irq sl28cpld_gpio_irqs[] = {
+	REGMAP_IRQ_REG_LINE(0, 8),
+	REGMAP_IRQ_REG_LINE(1, 8),
+	REGMAP_IRQ_REG_LINE(2, 8),
+	REGMAP_IRQ_REG_LINE(3, 8),
+	REGMAP_IRQ_REG_LINE(4, 8),
+	REGMAP_IRQ_REG_LINE(5, 8),
+	REGMAP_IRQ_REG_LINE(6, 8),
+	REGMAP_IRQ_REG_LINE(7, 8),
+};

This is exactly the same as the one in the irq chip patch.

Quoted 10 lines
drivers/gpio/gpio-sl28cpld.c new file +10 -0
+static int sl28cpld_gpio_irq_init(struct device *dev,
+				  struct sl28cpld_gpio *gpio,
+				  struct regmap *regmap, unsigned int base,
+				  int irq)
+{
+	struct regmap_irq_chip *irq_chip = &gpio->irq_chip;
+
+	irq_chip->name = "sl28cpld-gpio-irq",
+	irq_chip->irqs = sl28cpld_gpio_irqs;
+	irq_chip->num_irqs = ARRAY_SIZE(sl28cpld_gpio_irqs);

drivers/gpio/gpio-sl28cpld.c line 72

Quoted 10 lines
drivers/gpio/gpio-sl28cpld.c new file +10 -0
+	irq_chip->num_regs = 1;
+	irq_chip->status_base = base + GPIO_REG_IP;
+	irq_chip->mask_base = base + GPIO_REG_IE;
+	irq_chip->mask_invert = true,
+	irq_chip->ack_base = base + GPIO_REG_IP;
+
+	return devm_regmap_add_irq_chip_np(dev, dev_of_node(dev), regmap,
+					   irq, IRQF_SHARED | IRQF_ONESHOT, 0,
+					   irq_chip, &gpio->irq_data);
+}

And this looks pretty familiar as well. What's the point of duplicating that code?

Thanks,

tglx

#57 lore raw

Re: [PATCH v3 11/16] gpio: add support for the sl28cpld GPIO controller

Am 2020-04-27 13:45, schrieb Thomas Gleixner:

Quoted 10 lines
Quoted 9 lines · Michael Walle
drivers/gpio/gpio-sl28cpld.c new file +9 -0
+struct sl28cpld_gpio {
+	struct regmap_irq_chip irq_chip;
+	struct regmap_irq_chip_data *irq_data;
+};
+
+static const struct regmap_irq sl28cpld_gpio_irqs[] = {
+	REGMAP_IRQ_REG_LINE(0, 8),
+	REGMAP_IRQ_REG_LINE(1, 8),
+	REGMAP_IRQ_REG_LINE(2, 8),
Quoted 8 lines

drivers/gpio/gpio-sl28cpld.c line 51

Quoted 6 lines
drivers/gpio/gpio-sl28cpld.c new file +6 -0
+	REGMAP_IRQ_REG_LINE(3, 8),
+	REGMAP_IRQ_REG_LINE(4, 8),
+	REGMAP_IRQ_REG_LINE(5, 8),
+	REGMAP_IRQ_REG_LINE(6, 8),
+	REGMAP_IRQ_REG_LINE(7, 8),
+};

This is exactly the same as the one in the irq chip patch.

To my knowledge this boilerplate is just to describe this irqchip has 8 different IRQs.

Quoted 15 lines
Quoted 15 lines
drivers/gpio/gpio-sl28cpld.c new file +15 -0
+static int sl28cpld_gpio_irq_init(struct device *dev,
+				  struct sl28cpld_gpio *gpio,
+				  struct regmap *regmap, unsigned int base,
+				  int irq)
+{
+	struct regmap_irq_chip *irq_chip = &gpio->irq_chip;
+
+	irq_chip->name = "sl28cpld-gpio-irq",
+	irq_chip->irqs = sl28cpld_gpio_irqs;
+	irq_chip->num_irqs = ARRAY_SIZE(sl28cpld_gpio_irqs);
+	irq_chip->num_regs = 1;
+	irq_chip->status_base = base + GPIO_REG_IP;
+	irq_chip->mask_base = base + GPIO_REG_IE;
+	irq_chip->mask_invert = true,
+	irq_chip->ack_base = base + GPIO_REG_IP;
Quoted 8 lines

drivers/gpio/gpio-sl28cpld.c line 72

Quoted 5 lines
drivers/gpio/gpio-sl28cpld.c new file +5 -0
+
+	return devm_regmap_add_irq_chip_np(dev, dev_of_node(dev), regmap,
+					   irq, IRQF_SHARED | IRQF_ONESHOT, 0,
+					   irq_chip, &gpio->irq_data);
+}

And this looks pretty familiar as well. What's the point of duplicating that code?

this is also just boilerplate to configure the irqchip. But there are two distinct blocks inside the board management controller:
- an interrupt controller (which has 8 interrupts)
- and gpio controllers which also happen to have 8 interrupts and both have some shared semantics for now. But the GPIO building block might be extended to provide interrupt type settings, i.e. falling/ rising/level triggered interrupts.

So yes both look similar, but they are two different blocks, they use different registers and they might drift apart in the future.

-michael

Quoted 4 lines

Thanks,

tglx

#58 lore raw

PATCH v3 12/16 hwmon: add support for the sl28cpld hardware monitoring controller

In reply to Michael Walle

This adds support for the hardware monitoring controller of the sl28cpld board management controller. This driver is part of a multi-function device.

---
 Documentation/hwmon/index.rst    |   1 +
 Documentation/hwmon/sl28cpld.rst |  36 ++++++++
 drivers/hwmon/Kconfig            |  10 ++
 drivers/hwmon/Makefile           |   1 +
 drivers/hwmon/sl28cpld-hwmon.c   | 151 +++++++++++++++++++++++++++++++
 5 files changed, 199 insertions(+)
 create mode 100644 Documentation/hwmon/sl28cpld.rst
 create mode 100644 drivers/hwmon/sl28cpld-hwmon.c
Documentation/hwmon/index.rst +1 -0
index 1f0affb3b6e0..19ad0846736d 100644
@@ -149,6 +149,7 @@ Hardware Monitoring Kernel Drivers
    sht3x
    shtc1
    sis5595
+   sl28cpld
    smm665
    smsc47b397
    smsc47m192
Documentation/hwmon/sl28cpld.rst new file +36 -0
new file mode 100644
index 000000000000..7ed65f78250c
@@ -0,0 +1,36 @@
+.. SPDX-License-Identifier: GPL-2.0-only
+
+Kernel driver sl28cpld
+======================
+
+Supported chips:
+
+   * Kontron sl28cpld
+
+     Prefix: 'sl28cpld'
+
+     Datasheet: not available
+
+Authors: Michael Walle <[email protected]>
+
+Description
+-----------
+
+The sl28cpld is a board management controller which also exposes a hardware
+monitoring controller. At the moment this controller supports a single fan
+supervisor. In the future there might be other flavours and additional
+hardware monitoring might be supported.
+
+The fan supervisor has a 7 bit counter register and a counter period of 1
+second. If the 7 bit counter overflows, the supervisor will automatically
+switch to x8 mode to support a wider input range at the loss of
+granularity.
+
+Sysfs entries
+-------------
+
+The following attributes are supported.
+
+======================= ========================================================
+fan1_input		Fan RPM. Assuming 2 pulses per revolution.
+======================= ========================================================
drivers/hwmon/Kconfig +10 -0
index a08765c80a49..cefa8b1e3af1 100644
@@ -1414,6 +1414,16 @@ config SENSORS_RASPBERRYPI_HWMON
 	  This driver can also be built as a module. If so, the module
 	  will be called raspberrypi-hwmon.
 
+config SENSORS_SL28CPLD
+	tristate "Kontron sl28cpl hardware monitoring driver"
+	depends on MFD_SL28CPLD
+	help
+	  If you say yes here you get support for the fan supervisor of the
+	  sl28cpld board management controller.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called sl28cpld-hwmon.
+
 config SENSORS_SHT15
 	tristate "Sensiron humidity and temperature sensors. SHT15 and compat."
 	depends on GPIOLIB || COMPILE_TEST
drivers/hwmon/Makefile +1 -0
index b0b9c8e57176..dfb0f8cda2dd 100644
@@ -155,6 +155,7 @@ obj-$(CONFIG_SENSORS_S3C)	+= s3c-hwmon.o
 obj-$(CONFIG_SENSORS_SCH56XX_COMMON)+= sch56xx-common.o
 obj-$(CONFIG_SENSORS_SCH5627)	+= sch5627.o
 obj-$(CONFIG_SENSORS_SCH5636)	+= sch5636.o
+obj-$(CONFIG_SENSORS_SL28CPLD)	+= sl28cpld-hwmon.o
 obj-$(CONFIG_SENSORS_SHT15)	+= sht15.o
 obj-$(CONFIG_SENSORS_SHT21)	+= sht21.o
 obj-$(CONFIG_SENSORS_SHT3x)	+= sht3x.o
drivers/hwmon/sl28cpld-hwmon.c new file +151 -0

151 lines not on this page · raw message

Signature · 1 line
2.20.1
#59 lore raw

PATCH v3 13/16 arm64: dts: freescale: sl28: enable sl28cpld

In reply to Michael Walle

Add the board management controller node.

---
 .../freescale/fsl-ls1028a-kontron-sl28.dts    | 92 +++++++++++++++++++
 1 file changed, 92 insertions(+)
arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28.dts +92 -0
index 41ba38adc906..b73794d57db4 100644
@@ -8,6 +8,7 @@
 
 /dts-v1/;
 #include "fsl-ls1028a.dtsi"
+#include <dt-bindings/interrupt-controller/irq.h>
 
 / {
 	model = "Kontron SMARC-sAL28";
@@ -174,6 +175,97 @@
 		reg = <0x32>;
 	};
 
+	sl28cpld: sl28cpld@4a {
+		#address-cells = <1>;
+		#size-cells = <0>;
+		compatible = "kontron,sl28cpld";
+		reg = <0x4a>;
+		interrupts-extended = <&gpio2 6 IRQ_TYPE_EDGE_FALLING>;
+
+		interrupt-controller;
+		#interrupt-cells = <2>;
+
+		watchdog@0 {
+			compatible = "kontron,sl28cpld-wdt";
+			reg = <0>;
+			kontron,assert-wdt-timeout-pin;
+		};
+
+		hwmon@4 {
+			compatible = "kontron,sl28cpld-fan";
+			reg = <1>;
+		};
+
+		sl28cpld_pwm0: pwm@5 {
+			#pwm-cells = <2>;
+			compatible = "kontron,sl28cpld-pwm";
+			reg = <2>;
+		};
+
+		sl28cpld_pwm1: pwm@6 {
+			#pwm-cells = <2>;
+			compatible = "kontron,sl28cpld-pwm";
+			reg = <3>;
+		};
+
+		sl28cpld_gpio0: gpio@0 {
+			compatible = "kontron,sl28cpld-gpio";
+			reg = <4>;
+
+			gpio-controller;
+			#gpio-cells = <2>;
+			gpio-line-names =
+				"GPIO0_CAM0_PWR_N", "GPIO1_CAM1_PWR_N",
+				"GPIO2_CAM0_RST_N", "GPIO3_CAM1_RST_N",
+				"GPIO4_HDA_RST_N", "GPIO5_PWM_OUT",
+				"GPIO6_TACHIN", "GPIO7";
+
+			interrupt-controller;
+			#interrupt-cells = <2>;
+		};
+
+		sl28cpld_gpio1: gpio@1 {
+			compatible = "kontron,sl28cpld-gpio";
+			reg = <5>;
+
+			gpio-controller;
+			#gpio-cells = <2>;
+			gpio-line-names =
+				"GPIO8", "GPIO9", "GPIO10", "GPIO11",
+				"", "", "", "";
+
+			interrupt-controller;
+			#interrupt-cells = <2>;
+		};
+
+		sl28cpld_gpio2: gpio@2 {
+			compatible = "kontron,sl28cpld-gpo";
+			reg = <6>;
+
+			gpio-controller;
+			#gpio-cells = <2>;
+			gpio-line-names =
+				"LCD0 voltage enable",
+				"LCD0 backlight enable",
+				"eMMC reset", "LVDS bridge reset",
+				"LVDS bridge power-down",
+				"SDIO power enable",
+				"", "";
+		};
+
+		sl28cpld_gpio3: gpio@3 {
+			compatible = "kontron,sl28cpld-gpi";
+			reg = <7>;
+
+			gpio-controller;
+			#gpio-cells = <2>;
+			gpio-line-names =
+				"Power button", "Force recovery", "Sleep",
+				"Battery low", "Lid state", "Charging",
+				"Charger present", "";
+		};
+	};
+
 	eeprom@50 {
 		compatible = "atmel,24c32";
 		reg = <0x50>;
Signature · 1 line
2.20.1
#60 lore raw

PATCH v3 14/16 arm64: dts: freescale: sl28: map GPIOs to input events

In reply to Michael Walle

Now that we have support for GPIO lines of the SMARC connector, map the sleep, power and lid switch signals to the corresponding keys using the gpio-keys and gpio-keys-polled drivers. The power and sleep signals have dedicated interrupts, thus we use these ones. The lid switch is just mapped to a GPIO input and needs polling.

---
 .../freescale/fsl-ls1028a-kontron-sl28.dts    | 32 +++++++++++++++++++
 1 file changed, 32 insertions(+)
arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28.dts +32 -0
index b73794d57db4..263ce50b0b79 100644
@@ -9,6 +9,8 @@
 /dts-v1/;
 #include "fsl-ls1028a.dtsi"
 #include <dt-bindings/interrupt-controller/irq.h>
+#include <dt-bindings/gpio/gpio.h>
+#include <dt-bindings/input/input.h>
 
 / {
 	model = "Kontron SMARC-sAL28";
@@ -23,6 +25,36 @@
 		spi1 = &dspi2;
 	};
 
+	buttons0 {
+		compatible = "gpio-keys";
+
+		power-button {
+			interrupts-extended = <&sl28cpld
+					       4 IRQ_TYPE_EDGE_BOTH>;
+			linux,code = <KEY_POWER>;
+			label = "Power";
+		};
+
+		sleep-button {
+			interrupts-extended = <&sl28cpld
+					       5 IRQ_TYPE_EDGE_BOTH>;
+			linux,code = <KEY_SLEEP>;
+			label = "Sleep";
+		};
+	};
+
+	buttons1 {
+		compatible = "gpio-keys-polled";
+		poll-interval = <200>;
+
+		lid-switch {
+			linux,input-type = <EV_SW>;
+			linux,code = <SW_LID>;
+			gpios = <&sl28cpld_gpio3 4 GPIO_ACTIVE_LOW>;
+			label = "Lid";
+		};
+	};
+
 	chosen {
 		stdout-path = "serial0:115200n8";
 	};
Signature · 1 line
2.20.1
#61 lore raw

PATCH v3 15/16 arm64: dts: freescale: sl28: enable LED support

In reply to Michael Walle

Now that we have support for GPIO lines of the SMARC connector, enable LED support on the KBox A-230-LS. There are two LEDs without fixed functions, one is yellow and one is green. Unfortunately, it is just one multi-color LED, thus while it is possible to enable both at the same time it is hard to tell the difference between "yellow only" and "yellow and green".

---
 .../fsl-ls1028a-kontron-kbox-a-230-ls.dts          | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-kbox-a-230-ls.dts +14 -0
index 4b4cc6a1573d..49cf4fe05c80 100644
@@ -16,6 +16,20 @@
 	model = "Kontron KBox A-230-LS";
 	compatible = "kontron,kbox-a-230-ls", "kontron,sl28-var4",
 		     "kontron,sl28", "fsl,ls1028a";
+
+	leds {
+		compatible = "gpio-leds";
+
+		user_yellow {
+			label = "s1914:yellow:user";
+			gpios = <&sl28cpld_gpio0 0 0>;
+		};
+
+		user_green {
+			label = "s1914:green:user";
+			gpios = <&sl28cpld_gpio1 3 0>;
+		};
+	};
 };
 
 &enetc_mdio_pf3 {
Signature · 1 line
2.20.1
#62 lore raw

PATCH v3 16/16 arm64: dts: freescale: sl28: enable fan support

In reply to Michael Walle

Add a pwm-fan mapped to the PWM channel 0 which is connected to the fan connector of the carrier.

---
 .../dts/freescale/fsl-ls1028a-kontron-sl28-var3-ads2.dts | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28-var3-ads2.dts +9 -0
index 0973a6a45217..c45d7b40e374 100644
@@ -15,6 +15,15 @@
 	compatible = "kontron,sl28-var3-ads2", "kontron,sl28-var3",
 		     "kontron,sl28", "fsl,ls1028a";
 
+	pwm-fan {
+		compatible = "pwm-fan";
+		cooling-min-state = <0>;
+		cooling-max-state = <3>;
+		#cooling-cells = <2>;
+		pwms = <&sl28cpld_pwm0 0 4000000>;
+		cooling-levels = <1 128 192 255>;
+	};
+
 	sound {
 		#address-cells = <1>;
 		#size-cells = <0>;
Signature · 1 line
2.20.1