Add support for Kontron sl28cpld
Subsystems (10)
v7 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 for v4 and above are tracked in the patches, suggested by Lee.
Changes since v3:
- use of_platform_populate() to populate internal devices using the internal register offsets as unit-addresses
- because we don't use mfd_cells anymore, we cannot use IORESOURCE_REG, but instead parse the reg property in each individual driver
- dropped the following patches because they were already merged:
gpiolib: Introduce gpiochip_irqchip_add_domain()
gpio: add a reusable generic gpio_chip using regmap
- dropped the following patches because they are no longer needed:
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
- rephrase commit messages, as suggested by Thomas Gleixner
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 (13):
mfd: add simple regmap based I2C driver
dt-bindings: mfd: Add bindings for sl28cpld
mfd: simple-mfd-i2c: add sl28cpld support
irqchip: add sl28cpld interrupt controller support
watchdog: add support for sl28cpld watchdog
pwm: add support for sl28cpld PWM controller
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
arm64: defconfig: enable the sl28cpld board management controller
.../bindings/gpio/kontron,sl28cpld-gpio.yaml | 54 ++++ .../hwmon/kontron,sl28cpld-hwmon.yaml | 27 ++ .../kontron,sl28cpld-intc.yaml | 54 ++++ .../bindings/mfd/kontron,sl28cpld.yaml | 153 ++++++++++++ .../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 | 134 ++++++++++ arch/arm64/configs/defconfig | 5 + drivers/gpio/Kconfig | 12 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-sl28cpld.c | 161 ++++++++++++ drivers/hwmon/Kconfig | 10 + drivers/hwmon/Makefile | 1 + drivers/hwmon/sl28cpld-hwmon.c | 142 +++++++++++ drivers/irqchip/Kconfig | 8 + drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-sl28cpld.c | 96 +++++++ drivers/mfd/Kconfig | 12 + drivers/mfd/Makefile | 1 + drivers/mfd/simple-mfd-i2c.c | 57 +++++ drivers/pwm/Kconfig | 10 + drivers/pwm/Makefile | 1 + drivers/pwm/pwm-sl28cpld.c | 235 ++++++++++++++++++ drivers/watchdog/Kconfig | 11 + drivers/watchdog/Makefile | 1 + drivers/watchdog/sl28cpld_wdt.c | 229 +++++++++++++++++ 30 files changed, 1546 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/interrupt-controller/kontron,sl28cpld-intc.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-sl28cpld.c create mode 100644 drivers/hwmon/sl28cpld-hwmon.c create mode 100644 drivers/irqchip/irq-sl28cpld.c create mode 100644 drivers/mfd/simple-mfd-i2c.c create mode 100644 drivers/pwm/pwm-sl28cpld.c create mode 100644 drivers/watchdog/sl28cpld_wdt.c
Signature · 1 line
2.20.1
PATCH v7 1/13 mfd: add simple regmap based I2C driver
There are I2C devices which contain several different functions but doesn't require any special access functions. For these kind of drivers an I2C regmap should be enough.
Create an I2C driver which creates an I2C regmap and enumerates its children. If a device wants to use this as its MFD core driver, it has to add an individual compatible string. It may provide its own regmap configuration.
Subdevices can use dev_get_regmap() on the parent to get their regmap instance.
---
Changes since v6:
- added SIMPLE_MFD_I2C help text
- revised description in module header
Changes since v5:
- removed "select MFD_CORE" in Kconfig
- removed help text in Kconfig, we assume that the users of this driver will have a "select MFD_SIMPLE_MFD_I2C". Instead added a small description to the driver itself.
- removed "struct simple_mfd_i2c_config" and use regmap_config directly
- changed builtin_i2c_driver() to module_i2c_driver(), added MODULE_ boilerplate
- cleaned up the included files
Changes since v4:
- new patch. Lee, please bear with me. I didn't want to delay the new version (where a lot of remarks on the other patches were addressed) even more, just because we haven't figured out how to deal with the MFD part. So for now, I've included this one.
drivers/mfd/Kconfig | 12 ++++++++ drivers/mfd/Makefile | 1 + drivers/mfd/simple-mfd-i2c.c | 56 ++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 drivers/mfd/simple-mfd-i2c.c
drivers/mfd/Kconfig +12 -0
@@ -1162,6 +1162,18 @@ config MFD_SI476X_CORE To compile this driver as a module, choose M here: the module will be called si476x-core. +config MFD_SIMPLE_MFD_I2C + tristate + depends on I2C + select REGMAP_I2C + help + This driver creates a single register map with the intention for it + to be shared by all sub-devices. + + Once the register map has been successfully initialised, any + sub-devices represented by child nodes in Device Tree will be + subsequently registered. + config MFD_SM501 tristate "Silicon Motion SM501" depends on HAS_DMA
drivers/mfd/Makefile +1 -0
@@ -264,3 +264,4 @@ obj-$(CONFIG_MFD_STMFX) += stmfx.o obj-$(CONFIG_MFD_KHADAS_MCU) += khadas-mcu.o obj-$(CONFIG_SGI_MFD_IOC3) += ioc3.o +obj-$(CONFIG_MFD_SIMPLE_MFD_I2C) += simple-mfd-i2c.o
drivers/mfd/simple-mfd-i2c.c new file +56 -0
56 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v7 2/13 dt-bindings: mfd: Add bindings for sl28cpld
In reply to Michael WalleAdd a device tree bindings for the board management controller found on the Kontron SMARC-sAL28 board.
---
Changes since v6:
- renamed "sl28cpld-r1" to "sl28cpld"
- made paths relative
- moved "reg" and "compatible" to the top of a node
Changes since v5:
- none
Changes since v4:
- fix the regex of the unit-address
Changes since v3:
- see cover letter
.../bindings/gpio/kontron,sl28cpld-gpio.yaml | 54 +++++++ .../hwmon/kontron,sl28cpld-hwmon.yaml | 27 ++++ .../kontron,sl28cpld-intc.yaml | 54 +++++++ .../bindings/mfd/kontron,sl28cpld.yaml | 153 ++++++++++++++++++ .../bindings/pwm/kontron,sl28cpld-pwm.yaml | 35 ++++ .../watchdog/kontron,sl28cpld-wdt.yaml | 35 ++++ 6 files changed, 358 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/interrupt-controller/kontron,sl28cpld-intc.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 +54 -0
@@ -0,0 +1,54 @@ +# 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 ../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 + + interrupts: + 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
@@ -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 ../mfd/kontron,sl28cpld.yaml. + +properties: + compatible: + enum: + - kontron,sl28cpld-fan + + reg: + maxItems: 1 + +required: + - compatible + +additionalProperties: false
Documentation/devicetree/bindings/interrupt-controller/kontron,sl28cpld-intc.yaml new file +54 -0
54 lines not on this page · raw message
Documentation/devicetree/bindings/mfd/kontron,sl28cpld.yaml new file +153 -0
153 lines not on this page · raw message
Documentation/devicetree/bindings/pwm/kontron,sl28cpld-pwm.yaml new file +35 -0
@@ -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 ../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
@@ -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 ../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
PATCH v7 3/13 mfd: simple-mfd-i2c: add sl28cpld support
In reply to Michael WalleAdd the core support for the board management controller found on the SMARC-sAL28 board.
At the moment, this controller is used on the Kontron SMARC-sAL28 board.
---
Changes since v6:
- renamed "sl28cpld-r1" to "sl28cpld"
Changes since v5:
- none
Changes since v4:
- new patch
drivers/mfd/simple-mfd-i2c.c | 1 + 1 file changed, 1 insertion(+)
drivers/mfd/simple-mfd-i2c.c +1 -0
@@ -38,6 +38,7 @@ static int simple_mfd_i2c_probe(struct i2c_client *i2c) }static const struct of_device_id simple_mfd_i2c_of_match[] = { + { .compatible ="kontron,sl28cpld" }, {} };MODULE_DEVICE_TABLE (of, simple_mfd_i2c_of_match);
Signature · 1 line
2.20.1
PATCH v7 4/13 irqchip: add sl28cpld interrupt controller support
In reply to Michael WalleAdd support for the interrupt controller inside the sl28 CPLD management controller.
The interrupt controller can handle at most 8 interrupts and is really simplistic and consists only of an interrupt mask and an interrupt pending register.
---
Changes since v6:
- none
Changes since v5:
- none
Changes since v4:
- update copyright year
- don't use "int irq" instead of "unsigne int irq", because platform_get_irq() might return a negative error code. Found by "kernel test robot <[email protected]>
- remove comma in terminator line of the compatible strings list, suggested by Andy
- use newer devm_regmap_add_irq_chip_fwnode()
- don't use KBUID_MODNAME, suggested by Andy
- remove the platform device table
Changes since v3:
- see cover letter
drivers/irqchip/Kconfig | 8 +++ drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-sl28cpld.c | 96 ++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 drivers/irqchip/irq-sl28cpld.c
drivers/irqchip/Kconfig +8 -0
@@ -246,6 +246,14 @@ 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 "Kontron sl28cpld IRQ controller" + select MFD_SIMPLE_MFD_I2C + select REGMAP_IRQ + help + Interrupt controller driver for the board management controller + found on the Kontron sl28 CPLD. + config ST_IRQCHIP bool select REGMAP
drivers/irqchip/Makefile +1 -0
@@ -111,3 +111,4 @@ obj-$(CONFIG_LOONGSON_HTPIC) += irq-loongson-htpic.o obj-$(CONFIG_LOONGSON_HTVEC) += irq-loongson-htvec.o obj-$(CONFIG_LOONGSON_PCH_PIC) += irq-loongson-pch-pic.o obj-$(CONFIG_LOONGSON_PCH_MSI) += irq-loongson-pch-msi.o +obj-$(CONFIG_SL28CPLD_INTC) += irq-sl28cpld.o
drivers/irqchip/irq-sl28cpld.c new file +96 -0
96 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v7 5/13 watchdog: add support for sl28cpld watchdog
In reply to Michael WalleAdd support for the watchdog of the sl28cpld board management controller. This is part of a multi-function device driver.
---
Changes since v6:
- none
Changes since v5:
- none
Changes since v4:
- update copyright year
- remove #include <linux/of_device.h>, suggested by Andy.
- slightly reworked the error code handling (only style), suggested by Andy.
- Don't use "if (ret < 0)", but only "if (ret)", suggested by Andy.
- remove comma in terminator line of the compatible strings list
- don't use KBUID_MODNAME
- remove the platform device table
Changes since v3:
- see cover letter
drivers/watchdog/Kconfig | 11 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/sl28cpld_wdt.c | 229 ++++++++++++++++++++++++++++++++ 3 files changed, 241 insertions(+) create mode 100644 drivers/watchdog/sl28cpld_wdt.c
drivers/watchdog/Kconfig +11 -0
@@ -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 sl28cpld Watchdog" + select MFD_SIMPLE_MFD_I2C + 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
@@ -225,3 +225,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 +229 -0
229 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v7 6/13 pwm: add support for sl28cpld PWM controller
In reply to Michael WalleAdd support for the PWM controller of the sl28cpld board management controller. This is part of a multi-function device driver.
The controller has one PWM channel and can just generate four distinct frequencies.
---
Changes since v6:
- added new row "period length"
- fixed parenthesis mistake in the description of a calculation
- added sl28cpld_pwm_{read/write}()
- added more error messages
Changes since v5:
- added brief description of the PWM hardware implementation
- added hardware limitations
- dropped the frequency mode table, instead calculate the prescaler value on the fly.
- round the requested parameters instead of support just distinct periods.
- prefix the macros by SL28CPLD_ to make them less generic
- set polarity to PWM_POLARITY_NORMAL and reject inverted polarity requests.
- apply the workaround just for prescaler value of 0.
- make errors during probing more verbose
Changes since v4:
- update copyright year
- remove #include <linux/of_device.h>, suggested by Andy.
- make the pwm mode table look nicer, suggested by Lee.
- use dev_get_drvdata(chip->dev) instead of container_of(), suggested by Lee.
- use whole sentence in comments, suggested by Lee.
- renamed the local "struct sl28cpld_pwm" variable to "priv" everywhere, suggested by Lee.
- use pwm_{get,set}_relative_duty_cycle(), suggested by Andy.
- make the comment about the 250Hz hardware limitation clearer
- don't use "if (ret < 0)", but only "if (ret)", suggested by Andy.
- don't use KBUID_MODNAME
- remove comma in terminator line of the compatible strings list
- remove the platform device table
Changes since v3:
- see cover letter
drivers/pwm/Kconfig | 10 ++ drivers/pwm/Makefile | 1 + drivers/pwm/pwm-sl28cpld.c | 235 +++++++++++++++++++++++++++++++++++++ 3 files changed, 246 insertions(+) create mode 100644 drivers/pwm/pwm-sl28cpld.c
drivers/pwm/Kconfig +10 -0
@@ -428,6 +428,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 sl28cpld PWM support" + select MFD_SIMPLE_MFD_I2C + 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
@@ -40,6 +40,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 +235 -0
235 lines not on this page · raw message
Signature · 1 line
2.20.1
Re: [PATCH v7 06/13] pwm: add support for sl28cpld PWM controller
Hello Michael,
I'm nearly happy now; see below.
drivers/pwm/Kconfig config PWM_SIFIVE · line 433
Quoted 11 lines · Michael Walle
drivers/pwm/Kconfig +3
-0@@ -428,6 +428,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 sl28cpld PWM support" + select MFD_SIMPLE_MFD_I2C
Is it sensible to present this option to everyone? Maybe
depends on SOME_SYMBOL_ONLY_TRUE_ON_SL28CPLD || COMPILE_TEST
.
Quoted 51 lines
drivers/pwm/Kconfig +7
-0+ 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_TESTdrivers/pwm/Makefile +1
-0@@ -40,6 +40,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.odrivers/pwm/pwm-sl28cpld.c new file +23
-0@@ -0,0 +1,235 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* sl28cpld PWM driver +* +* Copyright (c) 2020 Michael Walle <[email protected]> +* +* There is no public datasheet available for this PWM core. But it is easy +* enough to be briefly explained. It consists of one 8-bit counter. The PWM +* supports four distinct frequencies by selecting when to reset the counter. +* With the prescaler setting you can select which bit of the counter is used +* to reset it. This implies that the higher the frequency the less remaining +* bits are available for the actual counter. +* +* Let cnt[7:0] be the counter, clocked at 32kHz: +* +-----------+--------+--------------+-----------+---------------+ +* | prescaler | reset | counter bits | frequency | period length | +* +-----------+--------+--------------+-----------+---------------+ +* | 0 | cnt[7] | cnt[6:0] | 250 Hz | 4000000 ns | +* | 1 | cnt[6] | cnt[5:0] | 500 Hz | 2000000 ns | +* | 2 | cnt[5] | cnt[4:0] | 1 kHz | 1000000 ns | +* | 3 | cnt[4] | cnt[3:0] | 2 kHz | 500000 ns | +* +-----------+--------+--------------+-----------+---------------+ +*
drivers/pwm/pwm-sl28cpld.c line 33
Quoted 10 lines
drivers/pwm/pwm-sl28cpld.c new file +10
-0+* Limitations: +* - The hardware cannot generate a 100% duty cycle if the prescaler is 0. +* - The hardware cannot atomically set the prescaler and the counter value, +* which might lead to glitches and inconsistent states if a write fails. +* - The counter is not reset if you switch the prescaler which leads +* to glitches, too. +* - The duty cycle will switch immediately and not after a complete cycle. +* - Depending on the actual implementation, disabling the PWM might have +* side effects. For example, if the output pin is shared with a GPIO pin +* it will automatically switch back to GPIO mode.
Very nice.
Quoted 26 lines
drivers/pwm/pwm-sl28cpld.c new file +26
-0+*/ + +#include <linux/bitfield.h> +#include <linux/kernel.h> +#include <linux/mod_devicetable.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/pwm.h> +#include <linux/regmap.h> + +/* +* PWM timer block registers. +*/ +#define SL28CPLD_PWM_CTRL 0x00 +#define SL28CPLD_PWM_CTRL_ENABLE BIT(7) +#define SL28CPLD_PWM_CTRL_PRESCALER_MASK GENMASK(1, 0) +#define SL28CPLD_PWM_CYCLE 0x01 +#define SL28CPLD_PWM_CYCLE_MAX GENMASK(6, 0) + +#define SL28CPLD_PWM_CLK 32000/* 32 kHz */ +#define SL28CPLD_PWM_MAX_DUTY_CYCLE (prescaler) (1 << (7 - (prescaler))) +#define SL28CPLD_PWM_PERIOD (prescaler) \ + (NSEC_PER_SEC / SL28CPLD_PWM_CLK * SL28CPLD_PWM_MAX_DUTY_CYCLE(prescaler)) + +/* +* We calculate the duty cycle like this:
drivers/pwm/pwm-sl28cpld.c line 69
Quoted 10 lines
drivers/pwm/pwm-sl28cpld.c new file +10
-0+* duty_cycle_ns = pwm_cycle_reg * max_period_ns / max_duty_cycle +* +* With +* max_period_ns = 1 << (7 - prescaler) / pwm_clk * NSEC_PER_SEC +* max_duty_cycle = 1 << (7 - prescaler) +* this then simplifies to: +* duty_cycle_ns = pwm_cycle_reg / pwm_clk * NSEC_PER_SEC +* +* NSEC_PER_SEC and SL28CPLD_PWM_CLK is integer here, so we're not losing +* precision by doing the divison first.
Apart from the grammatical issue (s/is/are/) this is not the relevant fact. The relevant thing is that NSEC_PER_SEC / SL28CPLD_PWM_CLK is integer.
(In case this is not clear, assume SL28CPLD_PWM_CLK to be 30000 and reg 0x12345.
Then we have:
NSEC_PER_SEC / SL28CPLD_PWM_CLK * (reg) -> 0x94255749 NSEC_PER_SEC * (reg) / SL28CPLD_PWM_CLK -> 0x9425b860
.)
Quoted 24 lines
drivers/pwm/pwm-sl28cpld.c new file +24
-0+*/ +#define SL28CPLD_PWM_TO_DUTY_CYCLE (reg) \ + (NSEC_PER_SEC / SL28CPLD_PWM_CLK * (reg)) +#define SL28CPLD_PWM_FROM_DUTY_CYCLE (duty_cycle) \ + (DIV_ROUND_DOWN_ULL((duty_cycle), NSEC_PER_SEC / SL28CPLD_PWM_CLK)) + +#define sl28cpld_pwm_read (priv, reg, val) \ + regmap_read((priv)->regmap, (priv)->offset + (reg), (val)) +#define sl28cpld_pwm_write (priv, reg, val) \ + regmap_write((priv)->regmap, (priv)->offset + (reg), (val)) + +struct sl28cpld_pwm { +struct pwm_chip pwm_chip; +struct regmap *regmap; +u32 offset; +}; + +static void sl28cpld_pwm_get_state (struct pwm_chip *chip, +struct pwm_device *pwm, +struct pwm_state *state) +{ +struct sl28cpld_pwm *priv =dev_get_drvdata (chip->dev); +unsigned int reg; +int prescaler;
drivers/pwm/pwm-sl28cpld.c line 103
Quoted 10 lines
drivers/pwm/pwm-sl28cpld.c new file +10
-0+ +sl28cpld_pwm_read (priv,SL28CPLD_PWM_CTRL , ®); + + state->enabled = reg &SL28CPLD_PWM_CTRL_ENABLE ; + + prescaler =FIELD_GET (SL28CPLD_PWM_CTRL_PRESCALER_MASK , reg); + state->period =SL28CPLD_PWM_PERIOD (prescaler); + +sl28cpld_pwm_read (priv,SL28CPLD_PWM_CYCLE , ®); + state->duty_cycle =SL28CPLD_PWM_TO_DUTY_CYCLE (reg);
Should reg be masked to SL28CPLD_PWM_CYCLE_MAX, or is it guaranteed that the upper bits are zero?
drivers/pwm/pwm-sl28cpld.c line 105
Quoted 2 lines
drivers/pwm/pwm-sl28cpld.c new file +2
-0+ state->polarity =PWM_POLARITY_NORMAL ; +}
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |
Re: [PATCH v7 06/13] pwm: add support for sl28cpld PWM controller
Hi Uwe, Hi Lee,
Am 2020-08-06 10:40, schrieb Uwe Kleine-König:
Quoted 9 lines · Michael Walle
Quoted 8 lines
drivers/pwm/Kconfig +0
-0@@ -428,6 +428,16 @@ config PWM_SIFIVE To compile this driver as a module, choose M here: the module will be called pwm-sifive.
Quoted 7 lines
drivers/pwm/Kconfig config PWM_SIFIVE · line 433
Quoted 3 lines
drivers/pwm/Kconfig +3
-0+config PWM_SL28CPLD + tristate "Kontron sl28cpld PWM support" + select MFD_SIMPLE_MFD_I2CIs it sensible to present this option to everyone? Maybe
depends on SOME_SYMBOL_ONLY_TRUE_ON_SL28CPLD || COMPILE_TEST
Because there is now no real MFD driver anymore, there is also no symbol for that. The closest would be ARCH_ARM64 but I don't think that is a good idea.
Lee, what do you think about adding a symbol to the MFD, which selects MFD_SIMPLE_MFD_I2C but doesn't enable any C modules?
I.e.
config MFD_SL28CPLD
tristate "Kontron sl28cpld"
select MFD_SIMPLE_MFD_I2C
help
Say yes here to add support for the Kontron sl28cpld board management controller.
Then all the other device driver could depend on the MFD_SL28CPLD symbol.
[..]
Quoted 12 lines
Quoted 12 lines
drivers/pwm/Kconfig +12
-0+static void sl28cpld_pwm_get_state(struct pwm_chip *chip, + struct pwm_device *pwm, + struct pwm_state *state) +{ + struct sl28cpld_pwm *priv = dev_get_drvdata(chip->dev); + unsigned int reg; + int prescaler; + + sl28cpld_pwm_read(priv, SL28CPLD_PWM_CTRL, ®); + + state->enabled = reg & SL28CPLD_PWM_CTRL_ENABLE; +
Quoted 8 lines
drivers/pwm/Kconfig
Quoted 5 lines
drivers/pwm/Kconfig +5
-0+ prescaler = FIELD_GET(SL28CPLD_PWM_CTRL_PRESCALER_MASK, reg); + state->period = SL28CPLD_PWM_PERIOD(prescaler); + + sl28cpld_pwm_read(priv, SL28CPLD_PWM_CYCLE, ®); + state->duty_cycle = SL28CPLD_PWM_TO_DUTY_CYCLE(reg);Should reg be masked to
SL28CPLD_PWM_CYCLE_MAX, or is it guaranteed that the upper bits are zero?
Mh, the hardware guarantees that bit7 is zero. So masking with SL28CPLD_PWM_CYCLE_MAX won't buy us much. But what I could think could go wrong is this: someone set the prescaler to != 0 and the duty cycle to a value greater than the max value for this particular prescaler mode. For the above calculations this would result in a duty_cycle greater than the period, if I'm not mistaken.
The behavior of the hardware is undefined in that case (at the moment it will be always on, I guess). So this isn't a valid setting. Nevertheless it might happen. So what about the following:
state->duty_cycle = min(state->duty_cycle, state->period);
-michael
Re: [PATCH v7 06/13] pwm: add support for sl28cpld PWM controller
Quoted 68 lines · Michael Walle
Hi Uwe, Hi Lee,
Am 2020-08-06 10:40, schrieb Uwe Kleine-König:
Quoted 9 lines · Michael Walle
Quoted 8 lines
drivers/pwm/Kconfig +0
-0@@ -428,6 +428,16 @@ config PWM_SIFIVE To compile this driver as a module, choose M here: the module will be called pwm-sifive.Quoted 7 lines
drivers/pwm/Kconfig config PWM_SIFIVE · line 433
Quoted 3 lines
drivers/pwm/Kconfig +3
-0+config PWM_SL28CPLD + tristate "Kontron sl28cpld PWM support" + select MFD_SIMPLE_MFD_I2CIs it sensible to present this option to everyone? Maybe
depends on SOME_SYMBOL_ONLY_TRUE_ON_SL28CPLD || COMPILE_TESTBecause there is now no real MFD driver anymore, there is also no symbol for that. The closest would be
ARCH_ARM64but I don't think that is a good idea.Lee, what do you think about adding a symbol to the MFD, which selects
MFD_SIMPLE_MFD_I2Cbut doesn't enable any C modules?I.e.
configMFD_SL28CPLD
tristate "Kontron sl28cpld"
selectMFD_SIMPLE_MFD_I2C
help
Say yes here to add support for the Kontron sl28cpld board management controller.Then all the other device driver could depend on the
MFD_SL28CPLDsymbol.[..]
Quoted 12 lines
Quoted 12 lines
drivers/pwm/Kconfig +12
-0+static void sl28cpld_pwm_get_state(struct pwm_chip *chip, + struct pwm_device *pwm, + struct pwm_state *state) +{ + struct sl28cpld_pwm *priv = dev_get_drvdata(chip->dev); + unsigned int reg; + int prescaler; + + sl28cpld_pwm_read(priv, SL28CPLD_PWM_CTRL, ®); + + state->enabled = reg & SL28CPLD_PWM_CTRL_ENABLE; +Quoted 8 lines
drivers/pwm/Kconfig
Quoted 5 lines
drivers/pwm/Kconfig +5
-0+ prescaler = FIELD_GET(SL28CPLD_PWM_CTRL_PRESCALER_MASK, reg); + state->period = SL28CPLD_PWM_PERIOD(prescaler); + + sl28cpld_pwm_read(priv, SL28CPLD_PWM_CYCLE, ®); + state->duty_cycle = SL28CPLD_PWM_TO_DUTY_CYCLE(reg);Should reg be masked to
SL28CPLD_PWM_CYCLE_MAX, or is it guaranteed that the upper bits are zero?Mh, the hardware guarantees that bit7 is zero. So masking with
SL28CPLD_PWM_CYCLE_MAXwon't buy us much. But what I could think could go wrong is this: someone set the prescaler to != 0 and the duty cycle to a value greater than the max value for this particular prescaler mode. For the above calculations this would result in aduty_cyclegreater than the period, if I'm not mistaken.
Quoted 5 lines
The behavior of the hardware is undefined in that case (at the moment it will be always on, I guess). So this isn't a valid setting. Nevertheless it might happen. So what about the following:
state->duty_cycle=min(state->duty_cycle, state->period);
If you care about this: This can also happen (at least shortly) in sl28cpld_pwm_apply() as you write SL28CPLD_PWM_CTRL before SL28CPLD_PWM_CYCLE there.
I wonder if we want to sanitize the values returned from driver's .get_state in the core; or scream loud (maybe only if PWM_DEBUG is on).
Something like:
if (state->enabled && state->duty_cycle > state->period) {
if (IS_ENABLED(CONFIG_PWM_DEBUG))
dev_warn(chip->dev, ".get_state() returned invalid setting.\n");
state->duty_cycle = state->period;
}Do we want to catch state->period = 0, too? Do we interpret this as disabled?
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |
Re: [PATCH v7 06/13] pwm: add support for sl28cpld PWM controller
Am 2020-08-07 09:45, schrieb Uwe Kleine-König:
Quoted 73 lines · Michael Walle
Quoted 72 lines
Hi Uwe, Hi Lee,
Am 2020-08-06 10:40, schrieb Uwe Kleine-König:
Quoted 9 lines · Michael Walle
Quoted 8 lines
drivers/pwm/Kconfig +0
-0@@ -428,6 +428,16 @@ config PWM_SIFIVE To compile this driver as a module, choose M here: the module will be called pwm-sifive.Quoted 7 lines
drivers/pwm/Kconfig config PWM_SIFIVE · line 433
Quoted 3 lines
drivers/pwm/Kconfig +3
-0+config PWM_SL28CPLD + tristate "Kontron sl28cpld PWM support" + select MFD_SIMPLE_MFD_I2CIs it sensible to present this option to everyone? Maybe
depends on SOME_SYMBOL_ONLY_TRUE_ON_SL28CPLD || COMPILE_TESTBecause there is now no real MFD driver anymore, there is also no symbol for that. The closest would be
ARCH_ARM64but I don't think that is a good idea.Lee, what do you think about adding a symbol to the MFD, which selects
MFD_SIMPLE_MFD_I2Cbut doesn't enable any C modules?I.e.
configMFD_SL28CPLD
tristate "Kontron sl28cpld"
selectMFD_SIMPLE_MFD_I2C
help
Say yes here to add support for the Kontron sl28cpld board management controller.Then all the other device driver could depend on the
MFD_SL28CPLDsymbol.[..]
Quoted 12 lines
Quoted 12 lines
drivers/pwm/Kconfig +12
-0+static void sl28cpld_pwm_get_state(struct pwm_chip *chip, + struct pwm_device *pwm, + struct pwm_state *state) +{ + struct sl28cpld_pwm *priv = dev_get_drvdata(chip->dev); + unsigned int reg; + int prescaler; + + sl28cpld_pwm_read(priv, SL28CPLD_PWM_CTRL, ®); + + state->enabled = reg & SL28CPLD_PWM_CTRL_ENABLE; +Quoted 8 lines
drivers/pwm/Kconfig
Quoted 5 lines
drivers/pwm/Kconfig +5
-0+ prescaler = FIELD_GET(SL28CPLD_PWM_CTRL_PRESCALER_MASK, reg); + state->period = SL28CPLD_PWM_PERIOD(prescaler); + + sl28cpld_pwm_read(priv, SL28CPLD_PWM_CYCLE, ®); + state->duty_cycle = SL28CPLD_PWM_TO_DUTY_CYCLE(reg);Should reg be masked to
SL28CPLD_PWM_CYCLE_MAX, or is it guaranteed that the upper bits are zero?Mh, the hardware guarantees that bit7 is zero. So masking with
SL28CPLD_PWM_CYCLE_MAXwon't buy us much. But what I could think could go wrong is this: someone set the prescaler to != 0 and the duty cycle to a value greater than the max value for this particular prescaler mode. For the above calculations this would result in aduty_cyclegreater than the period, if I'm not mistaken.The behavior of the hardware is undefined in that case (at the moment it will be always on, I guess). So this isn't a valid setting. Nevertheless it might happen. So what about the following:
Quoted 5 lines
Quoted 1 line
state->duty_cycle=min(state->duty_cycle, state->period);If you care about this: This can also happen (at least shortly) in
sl28cpld_pwm_apply()as you writeSL28CPLD_PWM_CTRLbeforeSL28CPLD_PWM_CYCLEthere.
It could also happen if it was the other way around, couldn't it? Changing modes might glitch.
I care more about returning valid values to the PWM core ;)
-michael
Re: [PATCH v7 06/13] pwm: add support for sl28cpld PWM controller
Hi Michael,
Quoted 36 lines · Michael Walle
Am 2020-08-07 09:45, schrieb Uwe Kleine-König:
Quoted 35 lines · Michael Walle
Quoted 34 lines
Am 2020-08-06 10:40, schrieb Uwe Kleine-König:
Quoted 13 lines · Michael Walle
Quoted 12 lines
drivers/pwm/pwm-sl28cpld.c new file +12
-0+static void sl28cpld_pwm_get_state (struct pwm_chip *chip, +struct pwm_device *pwm, +struct pwm_state *state) +{ +struct sl28cpld_pwm *priv =dev_get_drvdata (chip->dev); +unsigned int reg; +int prescaler; + +sl28cpld_pwm_read (priv,SL28CPLD_PWM_CTRL , ®); + + state->enabled = reg &SL28CPLD_PWM_CTRL_ENABLE ; +Quoted 8 lines
drivers/pwm/pwm-sl28cpld.c line 103
Quoted 5 lines
drivers/pwm/pwm-sl28cpld.c new file +5
-0+ prescaler =FIELD_GET (SL28CPLD_PWM_CTRL_PRESCALER_MASK , reg); + state->period =SL28CPLD_PWM_PERIOD (prescaler); + +sl28cpld_pwm_read (priv,SL28CPLD_PWM_CYCLE , ®); + state->duty_cycle =SL28CPLD_PWM_TO_DUTY_CYCLE (reg);Should reg be masked to
SL28CPLD_PWM_CYCLE_MAX, or is it guaranteed that the upper bits are zero?Mh, the hardware guarantees that bit7 is zero. So masking with
SL28CPLD_PWM_CYCLE_MAXwon't buy us much. But what I could think could go wrong is this: someone set the prescaler to != 0 and the duty cycle to a value greater than the max value for this particular prescaler mode. For the above calculations this would result in aduty_cyclegreater than the period, if I'm not mistaken.The behavior of the hardware is undefined in that case (at the moment it will be always on, I guess). So this isn't a valid setting. Nevertheless it might happen. So what about the following:
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
state->duty_cycle=min(state->duty_cycle, state->period);If you care about this: This can also happen (at least shortly) in
sl28cpld_pwm_apply()as you writeSL28CPLD_PWM_CTRLbeforeSL28CPLD_PWM_CYCLEthere.It could also happen if it was the other way around, couldn't it? Changing modes might glitch.
If you want to prevent this, you have to order the writes depending on prescaler increasing or decreasing.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |
Re: [PATCH v7 06/13] pwm: add support for sl28cpld PWM controller
In reply to Michael WalleQuoted 35 lines · Michael Walle
Hi Uwe, Hi Lee,
Am 2020-08-06 10:40, schrieb Uwe Kleine-König:
Quoted 9 lines · Michael Walle
Quoted 8 lines
drivers/pwm/Kconfig +0
-0@@ -428,6 +428,16 @@ config PWM_SIFIVE To compile this driver as a module, choose M here: the module will be called pwm-sifive.Quoted 7 lines
drivers/pwm/Kconfig config PWM_SIFIVE · line 433
Quoted 3 lines
drivers/pwm/Kconfig +3
-0+config PWM_SL28CPLD + tristate "Kontron sl28cpld PWM support" + select MFD_SIMPLE_MFD_I2CIs it sensible to present this option to everyone? Maybe
depends on SOME_SYMBOL_ONLY_TRUE_ON_SL28CPLD || COMPILE_TESTBecause there is now no real MFD driver anymore, there is also no symbol for that. The closest would be
ARCH_ARM64but I don't think that is a good idea.Lee, what do you think about adding a symbol to the MFD, which selects
MFD_SIMPLE_MFD_I2Cbut doesn't enable any C modules?I.e.
configMFD_SL28CPLD
tristate "Kontron sl28cpld"
selectMFD_SIMPLE_MFD_I2C
help
Say yes here to add support for the Kontron sl28cpld board management controller.
Quoted 2 lines
Then all the other device driver could depend on the
MFD_SL28CPLDsymbol.
You want to add a virtual symbol to prevent having to present a real one? How is that a reasonable solution?
Signature · 4 lines
Lee Jones [李琼斯] Senior Technical Lead - Developer Services Linaro.org │ Open source software for Arm SoCs Follow Linaro: Facebook | Twitter | Blog
Re: [PATCH v7 06/13] pwm: add support for sl28cpld PWM controller
Am 2020-08-10 09:13, schrieb Lee Jones:
Quoted 37 lines · Michael Walle
Quoted 36 lines
Hi Uwe, Hi Lee,
Am 2020-08-06 10:40, schrieb Uwe Kleine-König:
Quoted 9 lines · Michael Walle
Quoted 8 lines
drivers/pwm/Kconfig +0
-0@@ -428,6 +428,16 @@ config PWM_SIFIVE To compile this driver as a module, choose M here: the module will be called pwm-sifive.Quoted 7 lines
drivers/pwm/Kconfig config PWM_SIFIVE · line 433
Quoted 3 lines
drivers/pwm/Kconfig +3
-0+config PWM_SL28CPLD + tristate "Kontron sl28cpld PWM support" + select MFD_SIMPLE_MFD_I2CIs it sensible to present this option to everyone? Maybe
depends on SOME_SYMBOL_ONLY_TRUE_ON_SL28CPLD || COMPILE_TESTBecause there is now no real MFD driver anymore, there is also no symbol for that. The closest would be
ARCH_ARM64but I don't think that is a good idea.Lee, what do you think about adding a symbol to the MFD, which selects
MFD_SIMPLE_MFD_I2Cbut doesn't enable any C modules?I.e.
configMFD_SL28CPLD
tristate "Kontron sl28cpld"
selectMFD_SIMPLE_MFD_I2C
help
Say yes here to add support for the Kontron sl28cpld board management controller.
Quoted 5 lines
Quoted 2 lines
Then all the other device driver could depend on the
MFD_SL28CPLDsymbol.You want to add a virtual symbol to prevent having to present a real one? How is that a reasonable solution?
(1) Its a symbol on which all sl28cpld will depend on. Thus they will all be hidden if that is not set.
(2) the drivers itself wouldn't need to depend on MFD_SIMPLE_MFD_I2C, which is more correct, because they don't have anything to do with i2c.
-michael
Re: [PATCH v7 06/13] pwm: add support for sl28cpld PWM controller
Am 2020-08-10 09:31, schrieb Michael Walle:
Quoted 41 lines
Am 2020-08-10 09:13, schrieb Lee Jones:
Quoted 40 lines · Michael Walle
Quoted 38 lines
Hi Uwe, Hi Lee,
Am 2020-08-06 10:40, schrieb Uwe Kleine-König:
Quoted 9 lines · Michael Walle
Quoted 8 lines
drivers/pwm/Kconfig +0
-0@@ -428,6 +428,16 @@ config PWM_SIFIVE To compile this driver as a module, choose M here: the module will be called pwm-sifive.Quoted 7 lines
drivers/pwm/Kconfig config PWM_SIFIVE · line 433
Quoted 3 lines
drivers/pwm/Kconfig +3
-0+config PWM_SL28CPLD + tristate "Kontron sl28cpld PWM support" + select MFD_SIMPLE_MFD_I2CIs it sensible to present this option to everyone? Maybe
depends on SOME_SYMBOL_ONLY_TRUE_ON_SL28CPLD || COMPILE_TESTBecause there is now no real MFD driver anymore, there is also no symbol for that. The closest would be
ARCH_ARM64but I don't think that is a good idea.Lee, what do you think about adding a symbol to the MFD, which selects
MFD_SIMPLE_MFD_I2Cbut doesn't enable any C modules?I.e.
configMFD_SL28CPLD
tristate "Kontron sl28cpld"
selectMFD_SIMPLE_MFD_I2C
help
Say yes here to add support for the Kontron sl28cpld board management controller.Then all the other device driver could depend on the
MFD_SL28CPLDsymbol.
Quoted 8 lines
Quoted 2 lines
You want to add a virtual symbol to prevent having to present a real one? How is that a reasonable solution?
(1) Its a symbol on which all sl28cpld will depend on. Thus they will all be hidden if that is not set.
(2) the drivers itself wouldn't need to depend onMFD_SIMPLE_MFD_I2C, which is more correct, because they don't have anything to do with i2c.
Lee, would you accept such a symbol? Otherwise, I'd leave it as is.
-michael
Re: [PATCH v7 06/13] pwm: add support for sl28cpld PWM controller
In reply to Michael WalleQuoted 41 lines · Michael Walle
Am 2020-08-10 09:13, schrieb Lee Jones:
Quoted 40 lines · Michael Walle
Quoted 38 lines
Hi Uwe, Hi Lee,
Am 2020-08-06 10:40, schrieb Uwe Kleine-König:
Quoted 9 lines · Michael Walle
Quoted 8 lines
drivers/pwm/Kconfig +0
-0@@ -428,6 +428,16 @@ config PWM_SIFIVE To compile this driver as a module, choose M here: the module will be called pwm-sifive.Quoted 7 lines
drivers/pwm/Kconfig config PWM_SIFIVE · line 433
Quoted 3 lines
drivers/pwm/Kconfig +3
-0+config PWM_SL28CPLD + tristate "Kontron sl28cpld PWM support" + select MFD_SIMPLE_MFD_I2CIs it sensible to present this option to everyone? Maybe
depends on SOME_SYMBOL_ONLY_TRUE_ON_SL28CPLD || COMPILE_TESTBecause there is now no real MFD driver anymore, there is also no symbol for that. The closest would be
ARCH_ARM64but I don't think that is a good idea.Lee, what do you think about adding a symbol to the MFD, which selects
MFD_SIMPLE_MFD_I2Cbut doesn't enable any C modules?I.e.
configMFD_SL28CPLD
tristate "Kontron sl28cpld"
selectMFD_SIMPLE_MFD_I2C
help
Say yes here to add support for the Kontron sl28cpld board management controller.Then all the other device driver could depend on the
MFD_SL28CPLDsymbol.
Quoted 8 lines
Quoted 2 lines
You want to add a virtual symbol to prevent having to present a real one? How is that a reasonable solution?
(1) Its a symbol on which all sl28cpld will depend on. Thus they will all be hidden if that is not set.
(2) the drivers itself wouldn't need to depend onMFD_SIMPLE_MFD_I2C, which is more correct, because they don't have anything to do with i2c.
Yes, okay.
Signature · 4 lines
Lee Jones [李琼斯] Senior Technical Lead - Developer Services Linaro.org │ Open source software for Arm SoCs Follow Linaro: Facebook | Twitter | Blog
PATCH v7 7/13 gpio: add support for the sl28cpld GPIO controller
In reply to Michael WalleAdd support for the GPIO controller of the sl28 board management controller. This driver is part of a multi-function device.
A controller has 8 lines. There are three different flavors:
full-featured GPIO with interrupt support, input-only and output-only.
---
Changes since v6:
- none
Changes since v5:
- added "select REGMAP_IRQ"
Changes since v4:
- update copyright year
- remove #include <linux/of_device.h>, suggested by Andy.
- use device_get_match_data(), suggested by Andy.
- drop the irq_support variable, instead call _init_irq() directly, suggested by Andy.
- also move the irq code a bit around to make it look nicer
- drop "struct sl28cpld_gpio". We don't need to actually store the irq_chip and irq_chip_data, everything is device resource managed.
- use 100 chars line limit, suggested by Andy.
- remove the platform device table
- don't use KBUID_MODNAME
Changes since v3:
- see cover letter
drivers/gpio/Kconfig | 12 +++ drivers/gpio/Makefile | 1 + drivers/gpio/gpio-sl28cpld.c | 161 +++++++++++++++++++++++++++++++++++ 3 files changed, 174 insertions(+) create mode 100644 drivers/gpio/gpio-sl28cpld.c
drivers/gpio/Kconfig +12 -0
@@ -1223,6 +1223,18 @@ 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 sl28cpld GPIO support" + select MFD_SIMPLE_MFD_I2C + select GPIO_REGMAP + select GPIOLIB_IRQCHIP + select REGMAP_IRQ + 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
@@ -132,6 +132,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 +161 -0
161 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v7 8/13 hwmon: add support for the sl28cpld hardware monitoring controller
In reply to Michael WalleAdd support for the hardware monitoring controller of the sl28cpld board management controller. This driver is part of a multi-function device.
---
Changes since v6:
- none
Changes since v5:
- none
Changes since v4:
- update copyright year
- remove #include <linux/of_device.h>, suggested by Andy.
- use PTR_ERR_OR_ZERO(), suggested by Andy.
- remove the platform device table
- don't use KBUID_MODNAME
Changes since v3:
- see cover letter
Documentation/hwmon/index.rst | 1 + Documentation/hwmon/sl28cpld.rst | 36 ++++++++ drivers/hwmon/Kconfig | 10 +++ drivers/hwmon/Makefile | 1 + drivers/hwmon/sl28cpld-hwmon.c | 142 +++++++++++++++++++++++++++++++ 5 files changed, 190 insertions(+) create mode 100644 Documentation/hwmon/sl28cpld.rst create mode 100644 drivers/hwmon/sl28cpld-hwmon.c
Documentation/hwmon/index.rst +1 -0
@@ -154,6 +154,7 @@ Hardware Monitoring Kernel Drivers sht3x shtc1 sis5595 + sl28cpld smm665 smsc47b397 smsc47m192
Documentation/hwmon/sl28cpld.rst new file +36 -0
@@ -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
@@ -1479,6 +1479,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 sl28cpld hardware monitoring driver" + select MFD_SIMPLE_MFD_I2C + 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
@@ -159,6 +159,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 +142 -0
142 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v7 9/13 arm64: dts: freescale: sl28: enable sl28cpld
In reply to Michael WalleAdd the board management controller node.
---
Changes since v6:
- renamed "sl28cpld-r1" to "sl28cpld"
- moved "reg" and "compatible" properties to the top of a node
Changes since v5:
- none
Changes since v4:
- none
Changes since v3:
- see cover letter
.../freescale/fsl-ls1028a-kontron-sl28.dts | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+)
arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28.dts +102 -0
@@ -8,6 +8,7 @@ /dts-v1/; #include "fsl-ls1028a.dtsi" +#include <dt-bindings/interrupt-controller/irq.h> / { model = "Kontron SMARC-sAL28";
@@ -170,6 +171,107 @@ reg = <0x32>; }; + sl28cpld@4a { + compatible = "kontron,sl28cpld"; + reg = <0x4a>; + #address-cells = <1>; + #size-cells = <0>; + + watchdog@4 { + compatible = "kontron,sl28cpld-wdt"; + reg = <0x4>; + kontron,assert-wdt-timeout-pin; + }; + + hwmon@b { + compatible = "kontron,sl28cpld-fan"; + reg = <0xb>; + }; + + sl28cpld_pwm0: pwm@c { + compatible = "kontron,sl28cpld-pwm"; + reg = <0xc>; + #pwm-cells = <2>; + }; + + sl28cpld_pwm1: pwm@e { + compatible = "kontron,sl28cpld-pwm"; + reg = <0xe>; + #pwm-cells = <2>; + }; + + sl28cpld_gpio0: gpio@10 { + compatible = "kontron,sl28cpld-gpio"; + reg = <0x10>; + interrupts-extended = <&gpio2 6 + IRQ_TYPE_EDGE_FALLING>; + + 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@15 { + compatible = "kontron,sl28cpld-gpio"; + reg = <0x15>; + interrupts-extended = <&gpio2 6 + IRQ_TYPE_EDGE_FALLING>; + + gpio-controller; + #gpio-cells = <2>; + gpio-line-names = + "GPIO8", "GPIO9", "GPIO10", "GPIO11", + "", "", "", ""; + + interrupt-controller; + #interrupt-cells = <2>; + }; + + sl28cpld_gpio2: gpio@1a { + compatible = "kontron,sl28cpld-gpo"; + reg = <0x1a>; + + 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@1b { + compatible = "kontron,sl28cpld-gpi"; + reg = <0x1b>; + + gpio-controller; + #gpio-cells = <2>; + gpio-line-names = + "Power button", "Force recovery", "Sleep", + "Battery low", "Lid state", "Charging", + "Charger present", ""; + }; + + sl28cpld_intc: interrupt-controller@1c { + compatible = "kontron,sl28cpld-intc"; + reg = <0x1c>; + interrupts-extended = <&gpio2 6 + IRQ_TYPE_EDGE_FALLING>; + + interrupt-controller; + #interrupt-cells = <2>; + }; + }; + eeprom@50 { compatible = "atmel,24c32"; reg = <0x50>;
Signature · 1 line
2.20.1
PATCH v7 10/13 arm64: dts: freescale: sl28: map GPIOs to input events
In reply to Michael WalleNow 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.
---
Changes since v6:
- none
Changes since v5:
- none
Changes since v4:
- none
Changes since v3:
- see cover letter
.../freescale/fsl-ls1028a-kontron-sl28.dts | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+)
arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28.dts +32 -0
@@ -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_intc + 4 IRQ_TYPE_EDGE_BOTH>; + linux,code = <KEY_POWER>; + label = "Power"; + }; + + sleep-button { + interrupts-extended = <&sl28cpld_intc + 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
PATCH v7 11/13 arm64: dts: freescale: sl28: enable LED support
In reply to Michael WalleNow 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".
---
Changes since v6:
- none
Changes since v5:
- changed the label, suggested by Pavel Machek
Changes since v4:
- none
Changes since v3:
- see cover letter
.../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
@@ -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"; + + alarm-led { + label = "yellow:alarm"; + gpios = <&sl28cpld_gpio0 0 0>; + }; + + power-led { + label = "green:power"; + gpios = <&sl28cpld_gpio1 3 0>; + }; + }; }; &enetc_mdio_pf3 {
Signature · 1 line
2.20.1
PATCH v7 12/13 arm64: dts: freescale: sl28: enable fan support
In reply to Michael WalleAdd a pwm-fan mapped to the PWM channel 0 which is connected to the fan connector of the carrier.
---
Changes since v6:
- none
Changes since v5:
- none
Changes since v4:
- none
Changes since v3:
- see cover letter
.../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
@@ -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
PATCH v7 13/13 arm64: defconfig: enable the sl28cpld board management controller
In reply to Michael WalleEnable the kernel modules for the board management controller "sl28cpld" which is used on the SMARC-sAL28 board.
---
Changes since v6:
- none
Changes since v5:
- new patch
arch/arm64/configs/defconfig | 5 +++++ 1 file changed, 5 insertions(+)
arch/arm64/configs/defconfig +5 -0
@@ -500,6 +500,7 @@ CONFIG_GPIO_PCA953X=y CONFIG_GPIO_PCA953X_IRQ=y CONFIG_GPIO_BD9571MWV=m CONFIG_GPIO_MAX77620=y +CONFIG_GPIO_SL28CPLD=m CONFIG_POWER_AVS=y CONFIG_QCOM_CPR=y CONFIG_ROCKCHIP_IODOMAIN=y
@@ -513,6 +514,7 @@ CONFIG_SENSORS_ARM_SCPI=y CONFIG_SENSORS_LM90=m CONFIG_SENSORS_PWM_FAN=m CONFIG_SENSORS_RASPBERRYPI_HWMON=m +CONFIG_SENSORS_SL28CPLD=m CONFIG_SENSORS_INA2XX=m CONFIG_SENSORS_INA3221=m CONFIG_THERMAL_GOV_POWER_ALLOCATOR=y
@@ -535,6 +537,7 @@ CONFIG_QCOM_TSENS=y CONFIG_QCOM_SPMI_TEMP_ALARM=m CONFIG_UNIPHIER_THERMAL=y CONFIG_WATCHDOG=y +CONFIG_SL28CPLD_WATCHDOG=m CONFIG_ARM_SP805_WATCHDOG=y CONFIG_ARM_SBSA_WATCHDOG=y CONFIG_ARM_SMC_WATCHDOG=y
@@ -935,8 +938,10 @@ CONFIG_PWM_MESON=m CONFIG_PWM_RCAR=m CONFIG_PWM_ROCKCHIP=y CONFIG_PWM_SAMSUNG=y +CONFIG_PWM_SL28CPLD=m CONFIG_PWM_SUN4I=m CONFIG_PWM_TEGRA=m +CONFIG_SL28CPLD_INTC=y CONFIG_QCOM_PDC=y CONFIG_RESET_QCOM_AOSS=y CONFIG_RESET_QCOM_PDC=m
Signature · 1 line
2.20.1