pwm: airoha: Add support for EN7581 SoC
PATCH v14 1/1 pwm: airoha: Add support for EN7581 SoC
From: Benjamin Larsson <[email protected]>
Introduce driver for PWM module available on EN7581 SoC.
---
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 | 11 + drivers/pwm/Makefile | 1 + drivers/pwm/pwm-airoha.c | 569 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 581 insertions(+) create mode 100644 drivers/pwm/pwm-airoha.c
drivers/pwm/Kconfig +11 -0
@@ -54,6 +54,17 @@ 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 + depends on OF + 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
@@ -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 +569 -0
569 lines not on this page · raw message
Signature · 1 line
2.48.1
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Christian,
kernel test robot noticed the following build errors:
[auto build test ERROR on linus/master]
[also build test ERROR on v6.16-rc3 next-20250620]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Christian-Marangi/pwm-airoha-Add-support-for-EN7581-SoC/20250617-042042 base: linus/master patch link: https://lore.kernel.org/r/20250616201532.29047-1-ansuelsmth%40gmail.com patch subject: [PATCH v14] pwm: airoha: Add support for EN7581 SoC config: m68k-randconfig-r072-20250623 (https://download.01.org/0day-ci/archive/20250623/[email protected]/config) compiler: m68k-linux-gcc (GCC) 13.3.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250623/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
m68k-linux-ld: drivers/pwm/pwm-airoha.o: in function `airoha_pwm_apply':
>> pwm-airoha.c:(.text+0x8f8): undefined reference to `__umoddi3'
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Uwe Kleine-König
maintainerHello Christian,
Quoted 15 lines · Christian Marangi
drivers/pwm/pwm-airoha.c new file +15
-0+static int airoha_pwm_apply (struct pwm_chip *chip,struct pwm_device *pwm, +const struct pwm_state *state) +{ +struct airoha_pwm *pc =pwmchip_get_drvdata (chip); +u64 duty_ns = state->duty_cycle; +u64 period_ns = state->period; + +if (!state->enabled) { +airoha_pwm_disable (pc, pwm); +return 0 ; + } + +/* Only normal polarity is supported */ +if (state->polarity ==PWM_POLARITY_INVERSED ) +return -EINVAL ;
drivers/pwm/pwm-airoha.c line 473
Quoted 10 lines
drivers/pwm/pwm-airoha.c new file +10
-0+ +/* Exit early if period is less than minimum supported */ +if (period_ns <AIROHA_PWM_PERIOD_TICK_NS ) +return -EINVAL ; + +/* +* Period goes at 4ns step, normalize it to check if we can +* share a generator. +*/ + period_ns =rounddown (period_ns,AIROHA_PWM_PERIOD_TICK_NS );
I guess this is the one that triggered the exception on m68k (though I couldn't reproduce it). If you do the clamping first, period_ns can be an unsigned int and the issue should be fixed.
Quoted 11 lines
drivers/pwm/pwm-airoha.c new file +11
-0+/* +* Duty goes at 255 step, normalize it to check if we can +* share a generator. +*/ + duty_ns =DIV_U64_ROUND_UP (duty_ns *AIROHA_PWM_DUTY_FULL , +AIROHA_PWM_DUTY_FULL ); + +/* Clamp period to MAX supported value */ +if (period_ns >AIROHA_PWM_PERIOD_MAX_NS ) { + period_ns =AIROHA_PWM_PERIOD_MAX_NS ; +
drivers/pwm/pwm-airoha.c
Quoted 10 lines
drivers/pwm/pwm-airoha.c new file +9
-0+if (duty_ns > period_ns) + duty_ns = period_ns; + } + +return airoha_pwm_config (pc, pwm, duty_ns, period_ns); +} +static struct platform_driver airoha_pwm_driver = { + .driver = { + .name ="pwm-airoha" ,
Given that there must be another revision anyhow, please add
.probe_type = PROBE_PREFER_ASYNCHRONOUS,
here.
drivers/pwm/pwm-airoha.c line 563
Quoted 5 lines
drivers/pwm/pwm-airoha.c new file +5
-0+ .of_match_table = airoha_pwm_of_match, + }, + .probe = airoha_pwm_probe, +}; +module_platform_driver (airoha_pwm_driver);
Best regards
Uwe