Skip to contentSkip to conversation

pwm: Add DesignWare PWM Controller Driver

PATCH New Jarkko Nikula 1 participant 1 message Aug 31, 2020 PWM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pwm: Add DesignWare PWM Controller Driver

Introduce driver for Synopsys DesignWare PWM Controller used on Intel Elkhart Lake.

Initial implementation is done by Felipe Balbi while he was working at Intel with later changes from Raymond Tan and me.

---
v3. Previous version: https://www.spinics.net/lists/linux-pwm/msg12363.html
Changes:
- I got confirmation specification is not publicly available
- HW is actually fixed inversed polarity by the PWM framework
conventions: HW cycle begins with a low period. Fixed polarity and low/high period calculation accordingly
- Added range check to period and duty_cycle
- Bogus '*' removed from head of the file comment
- struct dwc_pwm * passed to readl/writel wrappers instead of __iomem *
- %pe for error code prints
- clk_period_ns removed from struct dwc_pwm and use DWC_CLK_PERIOD_NS instead
- Device pointer removed from struct dwc_pwm, it's already carried in struct pwm_chip
- Added Limitations paragraph and commenting timer usage flow in code
- duty_cycle and period capping to 32-bit removed from dwc_pwm_get_state() since PWM core has been converted to 64-bit
- s/DIV_ROUND_CLOSEST/DIV_ROUND_CLOSEST_ULL/ to fix a link error on 32-bit ARM and older GCC-9 build. Reported by kernel test robot <[email protected]> on an internal tree
- Random cleanups, empty line removals etc
v2. First version here https://www.spinics.net/lists/linux-pwm/msg12122.html
Thanks to Uwe Kleine-König for good review comments, hopefully I captured them all.
Changes:
- Added Felipe's Signed-of-by. I added (Intel) to his kernel.org address to highlight contribution was done while working at Intel
- Version register read removed as result was unused
- Order of dwc_pwm_writel() arguments changed to match with writel()
- Structure initializers use one space instead of tab alignment
- Error messages added to dwc_pwm_probe()
- MODULE_LICENSE() Updated based on a review comment and commit bf7fbeeae6db ("module: Cure the MODULE_LICENSE "GPL" vs. "GPL v2" bogosity")
- Polarity handled. HW supports only normal polarity and driver errors out in case of wrong polarity in dwc_pwm_apply() and returns fixed normal polarity in dwc_pwm_get_state()
- Running timers are not stopped on probe and remove. Those may be set running by a bootloader and driver should leave them runnning
- pwm_is_enabled() call changed to pwm->state.enabled in wc_pwm_apply()
- Co-authors added to MODULE_AUTHOR() and comment
- mutex removed
- Add struct dwc_pwm_ctx for register save/restore instead of word array
- suspend prevented in case of active PWM consumers. Please note this checks only PWMs enabled by Linux consumers and not the ones enabled by bootloader
- Duplicate linux/pm_runtime.h include removed
- Only once used trivial functions moved to dwc_pwm_get_state()
- struct dwc_pwm_driver_data removed and used hard coded properties instead since currently driver supports single device type
- Driver uses internally 64-bit duty and period calculation and caps them to 32-bit ns max value for PWM core. HW supports 32-bit high and low period counters with 10 ns resolution so HW can do ~42,9 s duty and ~85.9 s period at maximum

---
 drivers/pwm/Kconfig   |   9 ++
 drivers/pwm/Makefile  |   1 +
 drivers/pwm/pwm-dwc.c | 321 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 331 insertions(+)
 create mode 100644 drivers/pwm/pwm-dwc.c
drivers/pwm/Kconfig +9 -0
index 9448e4ca8c73..ab79cb4734f1 100644
@@ -160,6 +160,15 @@ config PWM_CROS_EC
 	  PWM driver for exposing a PWM attached to the ChromeOS Embedded
 	  Controller.
 
+config PWM_DWC
+	tristate "DesignWare PWM Controller"
+	depends on PCI
+	help
+	  PWM driver for Synopsys DWC PWM Controller attached to a PCI bus.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called pwm-dwc.
+
 config PWM_EP93XX
 	tristate "Cirrus Logic EP93xx PWM support"
 	depends on ARCH_EP93XX || COMPILE_TEST
drivers/pwm/Makefile +1 -0
index 2c2ba0a03557..a1b7098fc4b8 100644
@@ -13,6 +13,7 @@ obj-$(CONFIG_PWM_BRCMSTB)	+= pwm-brcmstb.o
 obj-$(CONFIG_PWM_CLPS711X)	+= pwm-clps711x.o
 obj-$(CONFIG_PWM_CRC)		+= pwm-crc.o
 obj-$(CONFIG_PWM_CROS_EC)	+= pwm-cros-ec.o
+obj-$(CONFIG_PWM_DWC)		+= pwm-dwc.o
 obj-$(CONFIG_PWM_EP93XX)	+= pwm-ep93xx.o
 obj-$(CONFIG_PWM_FSL_FTM)	+= pwm-fsl-ftm.o
 obj-$(CONFIG_PWM_HIBVT)		+= pwm-hibvt.o
drivers/pwm/pwm-dwc.c new file +321 -0

321 lines not on this page · raw message

Signature · 1 line
2.28.0