Skip to contentSkip to conversation

pwm: airoha: Add support for EN7581 SoC

PATCH Superseded Christian Marangi 2 participants 4 messages Jul 5, 2025 PWM

v21 of 24 Superseded Latest is v24 →

lore
Share & tools
lore
#0 lore raw

PATCH v21 1/1 pwm: airoha: Add support for EN7581 SoC

From: Benjamin Larsson <[email protected]>

Introduce driver for PWM module available on EN7581 SoC.

---
Changes v21:
- Revert offset to u64 in airoha_pwm_apply_bucket_config (do_div require u64)

Changes v20:
- Add Review tag
- Drop duty normalization
- Drop mutex usage
- Use non-atomic bit OPs
- Use unsigned int for offset and bucket in airoha_pwm_apply_bucket_config

Changes v19:
- Fix copyright update
- Drop use of refcount and use mutex + simple counter

Changes v18:
- Fix not inizialized period_ns
- Update copyright name
- Improve define and comments
- Add array_size.h
- Better handle refcount in airoha_pwm_consume_generator

Changes v17:
- Drop math64.h patch
- Move to rounddown()
- Use u32 for period_ns (after clamp)
- Use ticks in inner function and for buckets

Changes v16:
- Always check regmap return
- Add missing header
- Use bitmask APIs
- Use refcount instead of raw u64
- Fix spelling mistake and improve text
- Drop OF dependency
- Drop redundant always true if condition
- Add myself as Author

Changes v15:
- Fix compilation error for 64bit division on 32bit (patch 01)
- Add prefer async probe

Changes v14:
- Fix logic for bucket recycle
(was tested by not releasing the bucket and observing
the best one gets used)
- Assign bucket period and duty only if not used
- Skip bucket period/duty calculation if already used
- Permit disable also if inversed polarity is asked
- Normalize duty similar to period

Changes v13:
- Reorder include
- Split ticks_from_ns function
- Add additional comments for shift register chip clock
- Address suggested minor optimization (Uwe)

Changes v12:
- Make shift function more readable
- Use unsigned int where possible
- Better comment some SIPO strangeness
- Move SIPO init after flash map config
- Retrun real values in get_state instead of the one saved in bucket
- Improve period_ns parsing so we can better share generators

Changes v11:
- Fix wrong calculation of period and duty
- Use AIROHA_PWM prefix for each define
- Drop set/get special define in favour of BITS and GENMASK
- Correctly use dev_err_probe
- Init bucket with initial values
- Rework define to make use of FIELD_PREP and FIELD_GET

Changes in v10:
- repost just patch 6/6 (pwm driver) since patches {1/6-5/6} have been already applied in linux-pinctrl tree
- pwm: introduce AIROHA_PWM_FIELD_GET and AIROHA_PWM_FIELD_SET macros to get/set field with non-const mask
- pwm: simplify airoha_pwm_get_generator() to report unused generator
and remove double lookup
- pwm: remove device_node pointer in airoha_pwm struct since this is write-only field
- pwm: cosmetics
- Link to v9: https://lore.kernel.org/r/[email protected]

Changes in v9:
- pwm: remove unused properties
- Link to v8: https://lore.kernel.org/r/[email protected]

Changes in v8:
- pwm: add missing properties documentation
- Link to v7: https://lore.kernel.org/r/[email protected]

Changes in v7:
- pinctrl: cosmetics
- pinctrl: fix compilation warning
- Link to v6: https://lore.kernel.org/r/[email protected]

Changes in v6:
- pwm: rely on regmap APIs
- pwm: introduce compatible string
- pinctrl: introduce compatible string
- remove airoha-mfd driver
- add airoha,en7581-pinctrl binding
- add airoha,en7581-pwm binding
- update airoha,en7581-gpio-sysctl binding
- Link to v5: https://lore.kernel.org/r/[email protected]

Changes in v5:
- use spin_lock in airoha_pinctrl_rmw instead of a mutex since it can run
in interrupt context
- remove unused includes in pinctrl driver
- since the irq_chip is immutable, allocate the gpio_irq_chip struct statically in pinctrl driver
- rely on regmap APIs in pinctrl driver but keep the spin_lock local to the driver
- rely on guard/guard_scope APIs in pinctrl driver
- improve naming convention pinctrl driver
- introduce airoha_pinconf_set_pin_value utility routine
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- add 'Limitation' description in pwm driver
- fix comments in pwm driver
- rely on mfd->base __iomem pointer in pwm driver, modify register
offsets according to it and get rid of sgpio_cfg, flash_cfg and
cycle_cfg pointers
- simplify register utility routines in pwm driver
- use 'generator' instead of 'waveform' suffix for pwm routines
- fix possible overflow calculating duty cycle in pwm driver
- do not modify pwm state in free callback in pwm driver
- cap the maximum period in pwm driver
- do not allow inverse polarity in pwm driver
- do not set of_xlate callback in the pwm driver and allow the stack to
do it
- fix MAINTAINERS file for airoha pinctrl driver
- fix undefined reference to __ffsdi2 in pinctrl driver
- simplify airoha,en7581-gpio-sysctl.yam binding
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- introduce airoha-mfd driver
- add pwm driver to the same series
- model pinctrl and pwm drivers as childs of a parent mfd driver.
- access chip-scu memory region in pinctrl driver via syscon
- introduce a single airoha,en7581-gpio-sysctl.yaml binding and get rid
of dedicated bindings for pinctrl and pwm
- add airoha,en7581-chip-scu.yaml binding do the series
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Fix compilation errors
- Collapse some register mappings for gpio and irq controllers
- update dt-bindings according to new register mapping
- fix some dt-bindings errors
- Link to v1: https://lore.kernel.org/all/[email protected]/

 drivers/pwm/Kconfig      |  10 +
 drivers/pwm/Makefile     |   1 +
 drivers/pwm/pwm-airoha.c | 607 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 618 insertions(+)
 create mode 100644 drivers/pwm/pwm-airoha.c
drivers/pwm/Kconfig +10 -0
index c866ed388da9..4aa7d94cd680 100644
@@ -54,6 +54,16 @@ config PWM_ADP5585
 	  This option enables support for the PWM function found in the Analog
 	  Devices ADP5585.
 
+config PWM_AIROHA
+	tristate "Airoha PWM support"
+	depends on ARCH_AIROHA || COMPILE_TEST
+	select REGMAP_MMIO
+	help
+	  Generic PWM framework driver for Airoha SoC.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called pwm-airoha.
+
 config PWM_APPLE
 	tristate "Apple SoC PWM support"
 	depends on ARCH_APPLE || COMPILE_TEST
drivers/pwm/Makefile +1 -0
index 5c782af8f49b..cd3e6de2e44a 100644
@@ -2,6 +2,7 @@
 obj-$(CONFIG_PWM)		+= core.o
 obj-$(CONFIG_PWM_AB8500)	+= pwm-ab8500.o
 obj-$(CONFIG_PWM_ADP5585)	+= pwm-adp5585.o
+obj-$(CONFIG_PWM_AIROHA)	+= pwm-airoha.o
 obj-$(CONFIG_PWM_APPLE)		+= pwm-apple.o
 obj-$(CONFIG_PWM_ATMEL)		+= pwm-atmel.o
 obj-$(CONFIG_PWM_ATMEL_HLCDC_PWM)	+= pwm-atmel-hlcdc.o
drivers/pwm/pwm-airoha.c new file +607 -0

607 lines not on this page · raw message

Signature · 1 line
2.48.1
#1 lore raw

Hello Christian,

Quoted 3 lines · Christian Marangi

Changes v21:
- Revert offset to u64 in airoha_pwm_apply_bucket_config (do_div require u64)

I didn't look in detail, but I wonder if you considered using a different division function to keep offset not bigger than needed?

Best regards
Uwe

#2 lore raw
Quoted 10 lines · Uwe Kleine-König

Hello Christian,

Quoted 3 lines · Christian Marangi

Changes v21:
- Revert offset to u64 in airoha_pwm_apply_bucket_config (do_div require u64)

I didn't look in detail, but I wonder if you considered using a different division function to keep offset not bigger than needed?

Hi Uwe,

I used do_div since it can calculate both division and remainder in one go.

The kernel warning were present only on 32 bit and are caused because do_div implementation is different on 32 or 64 bit.

On 64 bit it's simply

rem = n % base
div = n / base

but on 32 bit it's much more complex and adds the check n to be an u64.

Also on 64bit n is expected to be u64 but given the simplicity the type is not checked.

I checked if there is some kind of do_div32 but it doesn't exist and also using cast doesn't work give the complexity of the macro define (I tried with (u64)offset.

What do you think should be the best solution here?

Signature · 1 line
	Ansuel
#3 lore raw
Quoted 2 lines · Christian Marangi

I used do_div since it can calculate both division and remainder in one go.

On 32bit archs do_div is definitively more expensive than a 32bit / + a 32bit %. So the latter is the way to go. And given that these operations are native on all archs, there is no do_div32. And I'd expect that the compiler can use the synergies (if any on a given arch) when a division and a modulo operation with the same parameters is done.

Best regards
Uwe