Designware PWM driver updates for OF
Subsystems (2)
v6 cover Designware PWM driver updates for OF
This is an updated version of the Designware PWM driver updates for OF support, which now splits the driver into PCI and OF parts as well as tries to sort out the review comments.
Hopefully this can now be queued for the next kernel version.
v6:
- fix removal ordering of DWC_PERIOD_NS
v5:
- fixed kconfig string error
- merged pwm-nr into main of code
- split of code from pci code
- updated pwm-nr capping
- fix duplicate error reporting in of-code
- fix return in of-probe
- remove unecessary remove function as devm_ functions sort this
- fixed ordering of properties
- added missing reg item
- fixed missing split of the two clock sources.
- get bus clock in of code
v4:
- split pci and of into new modules
- fixup review comments
- fix typos in dt-bindings
v3:
- change the compatible name
- squash down pwm count patch
- fixup patch naming
v2:
- fix #pwm-cells count to be 3
- fix indetation
- merge the two clock patches
- add HAS_IOMEM as a config dependency
Ben Dooks (10):
dt-bindings: pwm: Document Synopsys DesignWare
snps,pwm-dw-apb-timers-pwm2
pwm: dwc: allow driver to be built with COMPILE_TEST
pwm: dwc: change &pci->dev to dev in probe
pwm: dwc: move memory alloc to own function
pwm: dwc: use devm_pwmchip_add
pwm: dwc: split pci out of core driver
pwm: dwc: make timer clock configurable
pwm: dwc: add of/platform support
pwm: dwc: add PWM bit unset in get_state call
pwm: dwc: use clock rate in hz to avoid rounding issues
.../bindings/pwm/snps,dw-apb-timers-pwm2.yaml | 68 ++++++ drivers/pwm/Kconfig | 24 +- drivers/pwm/Makefile | 2 + drivers/pwm/pwm-dwc-of.c | 76 +++++++ drivers/pwm/pwm-dwc-pci.c | 134 +++++++++++ drivers/pwm/pwm-dwc.c | 210 ++++-------------- drivers/pwm/pwm-dwc.h | 59 +++++ 7 files changed, 402 insertions(+), 171 deletions(-) create mode 100644 Documentation/devicetree/bindings/pwm/snps,dw-apb-timers-pwm2.yaml create mode 100644 drivers/pwm/pwm-dwc-of.c create mode 100644 drivers/pwm/pwm-dwc-pci.c create mode 100644 drivers/pwm/pwm-dwc.h
Signature · 1 line
2.35.1
PATCH v6 1/10 dt-bindings: pwm: Document Synopsys DesignWare snps,pwm-dw-apb-timers-pwm2
Add documentation for the bindings for Synopsys' DesignWare PWM block as we will be adding DT/platform support to the Linux driver soon.
---
v5:
- fixed order of properties
- corrected clock to two items
v4:
- fixed typos, added reg
v3:
- add description and example
- merge the snps,pwm-number into this patch
- rename snps,pwm to snps,dw-apb-timers-pwm2
v2:
- fix #pwm-cells to be 3
- fix indentation and ordering issues
--- .../bindings/pwm/snps,dw-apb-timers-pwm2.yaml | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Documentation/devicetree/bindings/pwm/snps,dw-apb-timers-pwm2.yaml
Documentation/devicetree/bindings/pwm/snps,dw-apb-timers-pwm2.yaml new file +68 -0
@@ -0,0 +1,68 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +# Copyright (C) 2022 SiFive, Inc. +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/pwm/snps,dw-apb-timers-pwm2.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Synopsys DW-APB timers PWM controller + +maintainers: + - Ben Dooks <[email protected]> + +description: + This describes the DesignWare APB timers module when used in the PWM + mode. The IP core can be generated with various options which can + control the functionality, the number of PWMs available and other + internal controls the designer requires. + + The IP block has a version register so this can be used for detection + instead of having to encode the IP version number in the device tree + comaptible. + +allOf: + - $ref: pwm.yaml# + +properties: + compatible: + const: snps,dw-apb-timers-pwm2 + + reg: + maxItems: 1 + + "#pwm-cells": + const: 3 + + clocks: + items: + - description: Interface bus clock + - description: PWM reference clock + + clock-names: + items: + - const: bus + - const: timer + + snps,pwm-number: + $ref: /schemas/types.yaml#/definitions/uint32 + description: The number of PWM channels configured for this instance + enum: [1, 2, 3, 4, 5, 6, 7, 8] + +required: + - compatible + - reg + - "#pwm-cells" + - clocks + - clock-names + +additionalProperties: false + +examples: + - | + pwm: pwm@180000 { + compatible = "snps,dw-apb-timers-pwm2"; + reg = <0x180000 0x200>; + #pwm-cells = <3>; + clocks = <&bus>, <&timer>; + clock-names = "bus", "timer"; + };
Signature · 1 line
2.35.1
Re: [PATCH v6 01/10] dt-bindings: pwm: Document Synopsys DesignWare snps,pwm-dw-apb-timers-pwm2
Quoted 8 lines · Ben Dooks
Add documentation for the bindings for Synopsys' DesignWare PWM block as we will be adding DT/platform support to the Linux driver soon.
Signed-off-by Ben Dooks <[email protected]>---
v5:
- fixed order of properties
- corrected clock to two items
This is a friendly reminder during the review process.
It looks like you received a tag and forgot to add it.
If you do not know the process, here is a short explanation:
Please add Acked-by/Reviewed-by/Tested-by tags when posting new versions. However,
there's no need to repost patches *only* to add the tags. The upstream maintainer will do that for acks received on the version they apply.
https://elixir.bootlin.com/linux/v5.17/source/Documentation/process/submitting-patches.rst#L540
If a tag was not added on purpose, please state why and what changed.
Best regards,
Krzysztof
Re: [PATCH v6 01/10] dt-bindings: pwm: Document Synopsys DesignWare snps,pwm-dw-apb-timers-pwm2
Quoted 20 lines · Krzysztof Kozlowski
Quoted 8 lines · Ben Dooks
Add documentation for the bindings for Synopsys' DesignWare PWM block as we will be adding DT/platform support to the Linux driver soon.
Signed-off-by Ben Dooks <[email protected]>---
v5:
- fixed order of properties
- corrected clock to two itemsThis is a friendly reminder during the review process.
It looks like you received a tag and forgot to add it.
If you do not know the process, here is a short explanation:
Please add Acked-by/Reviewed-by/Tested-by tags when posting new versions. However,
there's no need to repost patches *only* to add the tags. The upstream maintainer will do that for acks received on the version they apply.
Quoted 5 lines
https://elixir.bootlin.com/linux/v5.17/source/Documentation/process/submitting-patches.rst#L540
If a tag was not added on purpose, please state why and what changed.
Reviewed-by Krzysztof Kozlowski <[email protected]>
Given the number of updates I should probably post a v7 of this series with all the tags updated.
Signature · 1 line
Ben
Re: [PATCH v6 01/10] dt-bindings: pwm: Document Synopsys DesignWare snps,pwm-dw-apb-timers-pwm2
In reply to Ben DooksHello Ben,
Quoted 4 lines · Ben Dooks
Add documentation for the bindings for Synopsys' DesignWare PWM block as we will be adding DT/platform support to the Linux driver soon.
Signed-off-by Ben Dooks <[email protected]>
you would make life a bit easier if you added the tags you got for the previous rounds (iff the patch didn't change). Here that would be:
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |
Re: [PATCH v6 01/10] dt-bindings: pwm: Document Synopsys DesignWare snps,pwm-dw-apb-timers-pwm2
In reply to Ben DooksQuoted 4 lines · Ben Dooks
Add documentation for the bindings for Synopsys' DesignWare PWM block as we will be adding DT/platform support to the Linux driver soon.
Signed-off-by Ben Dooks <[email protected]>
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |
PATCH v6 2/10 pwm: dwc: allow driver to be built with COMPILE_TEST
In reply to Ben DooksAllow dwc driver to be built with COMPILE_TEST should allow better coverage when build testing.
---
v4:
- moved to earlier in the series
v3:
- add HAS_IOMEM depdency for compile testing
--- drivers/pwm/Kconfig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/pwm/Kconfig +2 -1
@@ -176,7 +176,8 @@ config PWM_CROS_EC config PWM_DWC tristate "DesignWare PWM Controller" - depends on PCI + depends on PCI || COMPILE_TEST + depends on HAS_IOMEM help PWM driver for Synopsys DWC PWM Controller attached to a PCI bus.
Signature · 1 line
2.35.1
Re: [PATCH v6 02/10] pwm: dwc: allow driver to be built with COMPILE_TEST
Quoted 4 lines · Ben Dooks
Allow dwc driver to be built with
COMPILE_TESTshould allow better coverage when build testing.Signed-off-by Ben Dooks <[email protected]>
(forwarded from v4)
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |
PATCH v6 3/10 pwm: dwc: change &pci->dev to dev in probe
In reply to Ben DooksThe dwc_pwm_probe() assignes dev to be &pci->dev but then uses &pci->dev throughout the function. Change these all to the be 'dev' variable to make lines shorter.
--- drivers/pwm/pwm-dwc.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/pwm/pwm-dwc.c +4 -6
@@ -202,14 +202,13 @@ static int dwc_pwm_probe(struct pci_dev *pci, const struct pci_device_id *id)struct dwc_pwm *dwc;int ret; - dwc =devm_kzalloc (&pci->dev,sizeof (*dwc),GFP_KERNEL ); + dwc =devm_kzalloc (dev,sizeof (*dwc),GFP_KERNEL );if (!dwc)return -ENOMEM ; ret =pcim_enable_device (pci);if (ret) { -dev_err (&pci->dev, -"Failed to enable device (%pe)\n" ,ERR_PTR (ret)); +dev_err (dev,"Failed to enable device (%pe)\n" ,ERR_PTR (ret));return ret; }
@@ -217,14 +216,13 @@ static int dwc_pwm_probe(struct pci_dev *pci, const struct pci_device_id *id) ret =pcim_iomap_regions (pci,BIT (0 ),pci_name (pci));if (ret) { -dev_err (&pci->dev, -"Failed to iomap PCI BAR (%pe)\n" ,ERR_PTR (ret)); +dev_err (dev,"Failed to iomap PCI BAR (%pe)\n" ,ERR_PTR (ret));return ret; } dwc->base =pcim_iomap_table (pci)[0 ];if (!dwc->base) { -dev_err (&pci->dev,"Base address missing\n" ); +dev_err (dev,"Base address missing\n" );return -ENOMEM ; }
Signature · 1 line
2.35.1
PATCH v6 4/10 pwm: dwc: move memory alloc to own function
In reply to Ben DooksIn preparation for adding other bus support, move the allocation of the pwm struct out of the main driver code.
--- drivers/pwm/pwm-dwc.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)
drivers/pwm/pwm-dwc.c +17 -7
@@ -196,13 +196,29 @@ static const struct pwm_ops dwc_pwm_ops = { .owner = THIS_MODULE, }; +static struct dwc_pwm *dwc_pwm_alloc (struct device *dev) +{ +struct dwc_pwm *dwc; + + dwc =devm_kzalloc (dev,sizeof (*dwc),GFP_KERNEL ); +if (!dwc) +return NULL ; + + dwc->chip.dev = dev; + dwc->chip.ops = &dwc_pwm_ops; + dwc->chip.npwm =DWC_TIMERS_TOTAL ; + +dev_set_drvdata (dev, dwc); +return dwc; +} +static int dwc_pwm_probe (struct pci_dev *pci,const struct pci_device_id *id) {struct device *dev = &pci->dev;struct dwc_pwm *dwc;int ret; - dwc =devm_kzalloc (dev,sizeof (*dwc),GFP_KERNEL ); + dwc =dwc_pwm_alloc (dev);if (!dwc)return -ENOMEM ;
@@ -226,12 +242,6 @@ static int dwc_pwm_probe(struct pci_dev *pci, const struct pci_device_id *id)return -ENOMEM ; } -pci_set_drvdata (pci, dwc); - - dwc->chip.dev = dev; - dwc->chip.ops = &dwc_pwm_ops; - dwc->chip.npwm =DWC_TIMERS_TOTAL ; - ret =pwmchip_add (&dwc->chip);if (ret)return ret;
Signature · 1 line
2.35.1
Re: [PATCH v6 04/10] pwm: dwc: move memory alloc to own function
Hello,
Quoted 19 lines · Ben Dooks
In preparation for adding other bus support, move the allocation of the pwm struct out of the main driver code.
Signed-off-by Ben Dooks <[email protected]>--- drivers/pwm/pwm-dwc.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)drivers/pwm/pwm-dwc.c +3
-0@@ -196,13 +196,29 @@ static const struct pwm_ops dwc_pwm_ops = { .owner = THIS_MODULE, }; +static struct dwc_pwm *dwc_pwm_alloc (struct device *dev) +{ +struct dwc_pwm *dwc;
drivers/pwm/pwm-dwc.c static const struct pwm_ops dwc_pwm_ops = { · line 211
Quoted 10 lines
drivers/pwm/pwm-dwc.c +10
-0+ + dwc =devm_kzalloc (dev,sizeof (*dwc),GFP_KERNEL ); +if (!dwc) +return NULL ; + + dwc->chip.dev = dev; + dwc->chip.ops = &dwc_pwm_ops; + dwc->chip.npwm =DWC_TIMERS_TOTAL ; + +dev_set_drvdata (dev, dwc);
This was a pci_set_drvdata before. While it's common knowledge (and implicitly used in several code parts) that pci_set_drvdata(pdev, data) is just the same as dev_set_drvdata(&pdev->dev, data), it would be nice if the driver only used either dev_[sg]et_drvdata or pci_[sg]et_drvdata.
Using the former in dwc_pwm_resume and dwc_pwm_suspend is even a tad shorter.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |
PATCH v6 5/10 pwm: dwc: use devm_pwmchip_add
In reply to Ben DooksUse devm_pwmchip_add() to add the pwm chip to avoid having to manually remove it (useful for the next patch which adds the platform-device support).
--- drivers/pwm/pwm-dwc.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/pwm/pwm-dwc.c +1 -5
@@ -242,7 +242,7 @@ static int dwc_pwm_probe(struct pci_dev *pci, const struct pci_device_id *id)return -ENOMEM ; } - ret =pwmchip_add (&dwc->chip); + ret =devm_pwmchip_add (dev, &dwc->chip);if (ret)return ret;
@@ -254,12 +254,8 @@ static int dwc_pwm_probe(struct pci_dev *pci, const struct pci_device_id *id)static void dwc_pwm_remove (struct pci_dev *pci) { -struct dwc_pwm *dwc =pci_get_drvdata (pci); -pm_runtime_forbid (&pci->dev);pm_runtime_get_noresume (&pci->dev); - -pwmchip_remove (&dwc->chip); }#ifdef CONFIG_PM_SLEEP
Signature · 1 line
2.35.1
Re: [PATCH v6 05/10] pwm: dwc: use devm_pwmchip_add
Quoted 5 lines · Ben Dooks
Use
devm_pwmchip_add()to add the pwm chip to avoid having to manually remove it (useful for the next patch which adds the platform-device support).Signed-off-by Ben Dooks <[email protected]>
Thanks
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |
PATCH v6 6/10 pwm: dwc: split pci out of core driver
In reply to Ben DooksMoving towards adding non-pci support for the driver, move the pci parts out of the core into their own module. This is partly due to the module_driver() code only being allowed once in a module and also to avoid a number of #ifdef if we build a single file in a system without pci support.
---
v6:
- put DWC_PERIOD_NS back to avoid bisect issues
v4:
- removed DWC_PERIOD_NS as not needed
--- drivers/pwm/Kconfig | 14 +++- drivers/pwm/Makefile | 1 + drivers/pwm/pwm-dwc-pci.c | 133 ++++++++++++++++++++++++++++++++ drivers/pwm/pwm-dwc.c | 158 +------------------------------------- drivers/pwm/pwm-dwc.h | 58 ++++++++++++++ 5 files changed, 207 insertions(+), 157 deletions(-) create mode 100644 drivers/pwm/pwm-dwc-pci.c create mode 100644 drivers/pwm/pwm-dwc.h
drivers/pwm/Kconfig +11 -3
@@ -175,15 +175,23 @@ config PWM_CROS_EC Controller. config PWM_DWC - tristate "DesignWare PWM Controller" - depends on PCI || COMPILE_TEST + tristate "DesignWare PWM Controller core" depends on HAS_IOMEM help - PWM driver for Synopsys DWC PWM Controller attached to a PCI bus. + PWM driver for Synopsys DWC PWM Controller. To compile this driver as a module, choose M here: the module will be called pwm-dwc. +config PWM_DWC_PCI + tristate "DesignWare PWM Controller core" + depends on PWM_DWC && HAS_IOMEM && 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-pci. + config PWM_EP93XX tristate "Cirrus Logic EP93xx PWM support" depends on ARCH_EP93XX || COMPILE_TEST
drivers/pwm/Makefile +1 -0
@@ -15,6 +15,7 @@ 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_DWC_PCI) += pwm-dwc-pci.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-pci.c new file +133 -0
133 lines not on this page · raw message
drivers/pwm/pwm-dwc.c +4 -154
187 lines not on this page · raw message
drivers/pwm/pwm-dwc.h new file +58 -0
58 lines not on this page · raw message
Signature · 1 line
2.35.1
Re: [PATCH v6 06/10] pwm: dwc: split pci out of core driver
Quoted 27 lines · Ben Dooks
Moving towards adding non-pci support for the driver, move the pci parts out of the core into their own module. This is partly due to the
module_driver()code only being allowed once in a module and also to avoid a number of #ifdef if we build a single file in a system without pci support.Signed-off-by Ben Dooks <[email protected]>---
v6:
- putDWC_PERIOD_NSback to avoid bisect issues
v4:
- removedDWC_PERIOD_NSas not needed--- drivers/pwm/Kconfig | 14 +++- drivers/pwm/Makefile | 1 + drivers/pwm/pwm-dwc-pci.c | 133 ++++++++++++++++++++++++++++++++ drivers/pwm/pwm-dwc.c | 158 +------------------------------------- drivers/pwm/pwm-dwc.h | 58 ++++++++++++++ 5 files changed, 207 insertions(+), 157 deletions(-) create mode 100644 drivers/pwm/pwm-dwc-pci.c create mode 100644 drivers/pwm/pwm-dwc.hdrivers/pwm/Kconfig +0
-0
drivers/pwm/Kconfig config PWM_CROS_EC · line 181
Quoted 10 lines
drivers/pwm/Kconfig +2
-3@@ -175,15 +175,23 @@ config PWM_CROS_EC Controller. config PWM_DWC - tristate "DesignWare PWM Controller" - depends on PCI || COMPILE_TEST + tristate "DesignWare PWM Controller core" depends on HAS_IOMEM help - PWM driver for Synopsys DWC PWM Controller attached to a PCI bus. + PWM driver for Synopsys DWC PWM Controller.
Currently pwm-dwc doesn't contain a driver but is only a library used by pwm-dwc-pci (and later the of driver). As such it doesn't make sense to be user-selectible, does it?
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |
Re: [PATCH v6 06/10] pwm: dwc: split pci out of core driver
Quoted 30 lines · Uwe Kleine-König
Quoted 29 lines · Ben Dooks
Moving towards adding non-pci support for the driver, move the pci parts out of the core into their own module. This is partly due to the
module_driver()code only being allowed once in a module and also to avoid a number of #ifdef if we build a single file in a system without pci support.Signed-off-by Ben Dooks <[email protected]>---
v6:
- putDWC_PERIOD_NSback to avoid bisect issues
v4:
- removedDWC_PERIOD_NSas not needed--- drivers/pwm/Kconfig | 14 +++- drivers/pwm/Makefile | 1 + drivers/pwm/pwm-dwc-pci.c | 133 ++++++++++++++++++++++++++++++++ drivers/pwm/pwm-dwc.c | 158 +------------------------------------- drivers/pwm/pwm-dwc.h | 58 ++++++++++++++ 5 files changed, 207 insertions(+), 157 deletions(-)create mode 100644
drivers/pwm/pwm-dwc-pci.c
create mode 100644drivers/pwm/pwm-dwc.hdrivers/pwm/Kconfig +0
-0@@ -175,15 +175,23 @@ config PWM_CROS_EC Controller.
Quoted 12 lines
drivers/pwm/Kconfig config PWM_CROS_EC · line 181
Quoted 8 lines
drivers/pwm/Kconfig +2
-3config PWM_DWC - tristate "DesignWare PWM Controller" - depends on PCI || COMPILE_TEST + tristate "DesignWare PWM Controller core" depends on HAS_IOMEM help - PWM driver for Synopsys DWC PWM Controller attached to a PCI bus. + PWM driver for Synopsys DWC PWM Controller.Currently pwm-dwc doesn't contain a driver but is only a library used by pwm-dwc-pci (and later the of driver). As such it doesn't make sense to be user-selectible, does it?
I suppose the PWM_DWC should select the original driver an a new PWM_DW_CORE should build the actual core driver.
Signature · 1 line
Ben
Re: [PATCH v6 06/10] pwm: dwc: split pci out of core driver
Hello,
Quoted 43 lines · Ben Dooks
Quoted 33 lines · Uwe Kleine-König
Quoted 32 lines · Ben Dooks
Moving towards adding non-pci support for the driver, move the pci parts out of the core into their own module. This is partly due to the
module_driver()code only being allowed once in a module and also to avoid a number of #ifdef if we build a single file in a system without pci support.Signed-off-by Ben Dooks <[email protected]>---
v6:
- putDWC_PERIOD_NSback to avoid bisect issues
v4:
- removedDWC_PERIOD_NSas not needed--- drivers/pwm/Kconfig | 14 +++- drivers/pwm/Makefile | 1 + drivers/pwm/pwm-dwc-pci.c | 133 ++++++++++++++++++++++++++++++++ drivers/pwm/pwm-dwc.c | 158 +------------------------------------- drivers/pwm/pwm-dwc.h | 58 ++++++++++++++ 5 files changed, 207 insertions(+), 157 deletions(-)create mode 100644
drivers/pwm/pwm-dwc-pci.c
create mode 100644drivers/pwm/pwm-dwc.hdrivers/pwm/Kconfig +1
-2@@ -175,15 +175,23 @@ config PWM_CROS_EC Controller. config PWM_DWC - tristate "DesignWare PWM Controller" - depends on PCI || COMPILE_TEST + tristate "DesignWare PWM Controller core"Quoted 8 lines
drivers/pwm/Kconfig config PWM_CROS_EC · line 181
Quoted 4 lines
drivers/pwm/Kconfig +1
-1depends on HAS_IOMEM help - PWM driver for Synopsys DWC PWM Controller attached to a PCI bus. + PWM driver for Synopsys DWC PWM Controller.Currently pwm-dwc doesn't contain a driver but is only a library used by pwm-dwc-pci (and later the of driver). As such it doesn't make sense to be user-selectible, does it?
Quoted 2 lines
I suppose the
PWM_DWCshould select the original driver an a newPWM_DW_COREshould build the actual core driver.
Sounds about right.
I will discard the complete v6 series from the PWM patchwork in the expectation that you will send a new round with all patches.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |
PATCH v6 7/10 pwm: dwc: make timer clock configurable
In reply to Ben DooksAdd a configurable clock base rate for the pwm as when being built for non-PCI the block may be sourced from an internal clock.
---
v6:
- removed DWC_CLK_PERIOD_NS as it is now not needed
v4:
- moved earlier before the of changes to make the of changes one patch
v2:
- removed the ifdef and merged the other clock patch in here
--- drivers/pwm/pwm-dwc-pci.c | 1 + drivers/pwm/pwm-dwc.c | 10 ++++++---- drivers/pwm/pwm-dwc.h | 3 ++- 3 files changed, 9 insertions(+), 5 deletions(-)
drivers/pwm/pwm-dwc-pci.c +1 -0
@@ -20,6 +20,7 @@#include <linux/pci.h> #include <linux/pm_runtime.h> #include <linux/pwm.h> +#include <linux/clk.h> #include "pwm-dwc.h"
drivers/pwm/pwm-dwc.c +6 -4
@@ -14,6 +14,7 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/pci.h> +#include <linux/clk.h> #include <linux/pm_runtime.h> #include <linux/pwm.h>
@@ -47,13 +48,13 @@ static int __dwc_pwm_configure_timer(struct dwc_pwm *dwc,* periods and check are the result within HW limits between 1 and * 2^32 periods. */ - tmp =DIV_ROUND_CLOSEST_ULL (state->duty_cycle,DWC_CLK_PERIOD_NS ); + tmp =DIV_ROUND_CLOSEST_ULL (state->duty_cycle, dwc->clk_ns);if (tmp <1 || tmp > (1ULL <<32 ))return -ERANGE ; low = tmp -1 ; tmp =DIV_ROUND_CLOSEST_ULL (state->period - state->duty_cycle, -DWC_CLK_PERIOD_NS ); + dwc->clk_ns);if (tmp <1 || tmp > (1ULL <<32 ))return -ERANGE ; high = tmp -1 ;
@@ -128,12 +129,12 @@ static void dwc_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, duty =dwc_pwm_readl (dwc,DWC_TIM_LD_CNT (pwm->hwpwm)); duty +=1 ; - duty *=DWC_CLK_PERIOD_NS ; + duty *= dwc->clk_ns; state->duty_cycle = duty; period =dwc_pwm_readl (dwc,DWC_TIM_LD_CNT2 (pwm->hwpwm)); period +=1 ; - period *=DWC_CLK_PERIOD_NS ; + period *= dwc->clk_ns; period += duty; state->period = period;
@@ -156,6 +157,7 @@ struct dwc_pwm *dwc_pwm_alloc(struct device *dev)if (!dwc)return NULL ; + dwc->clk_ns =10 ; dwc->chip.dev = dev; dwc->chip.ops = &dwc_pwm_ops; dwc->chip.npwm =DWC_TIMERS_TOTAL ;
drivers/pwm/pwm-dwc.h +2 -1
@@ -22,7 +22,6 @@#define DWC_TIMERS_COMP_VERSION 0xac#define DWC_TIMERS_TOTAL 8 -#define DWC_CLK_PERIOD_NS 10/* Timer Control Register */ #define DWC_TIM_CTRL_EN BIT(0)
@@ -41,6 +40,8 @@ struct dwc_pwm_ctx {struct dwc_pwm {struct pwm_chip chip;void __iomem *base; +struct clk *clk; +unsigned int clk_ns;struct dwc_pwm_ctx ctx[DWC_TIMERS_TOTAL ]; };#define to_dwc_pwm (p) (container_of((p), struct dwc_pwm, chip))
Signature · 1 line
2.35.1
Re: [PATCH v6 07/10] pwm: dwc: make timer clock configurable
Hello,
Quoted 22 lines · Ben Dooks
Add a configurable clock base rate for the pwm as when being built for non-PCI the block may be sourced from an internal clock.
Signed-off-by Ben Dooks <[email protected]>---
v6:
- removedDWC_CLK_PERIOD_NSas it is now not needed
v4:
- moved earlier before the of changes to make the of changes one patch
v2:
- removed the ifdef and merged the other clock patch in here--- drivers/pwm/pwm-dwc-pci.c | 1 + drivers/pwm/pwm-dwc.c | 10 ++++++---- drivers/pwm/pwm-dwc.h | 3 ++- 3 files changed, 9 insertions(+), 5 deletions(-)drivers/pwm/pwm-dwc-pci.c +0
-0
drivers/pwm/pwm-dwc-pci.c line 26
Quoted 7 lines
drivers/pwm/pwm-dwc-pci.c +1
-0@@ -20,6 +20,7 @@#include <linux/pci.h> #include <linux/pm_runtime.h> #include <linux/pwm.h> +#include <linux/clk.h> #include "pwm-dwc.h"
I assume this is only needed because pwm-dwc.h now uses struct clk. Maybe just add
struct clk;
to the pwm-dwc.h instead of this hunk?
Quoted 14 lines
[...]
drivers/pwm/pwm-dwc.h +0
-1@@ -22,7 +22,6 @@#define DWC_TIMERS_COMP_VERSION 0xac#define DWC_TIMERS_TOTAL 8 -#define DWC_CLK_PERIOD_NS 10/* Timer Control Register */ #define DWC_TIM_CTRL_EN BIT(0)
drivers/pwm/pwm-dwc.h struct dwc_pwm_ctx { · line 43
Quoted 4 lines
drivers/pwm/pwm-dwc.h +1
-0@@ -41,6 +40,8 @@ struct dwc_pwm_ctx {struct dwc_pwm {struct pwm_chip chip;void __iomem *base; +struct clk *clk;
This is unsed, please add it in the patch that makes use of it.
drivers/pwm/pwm-dwc.h struct dwc_pwm_ctx { · line 47
Quoted 4 lines
drivers/pwm/pwm-dwc.h +1
-0+unsigned int clk_ns;struct dwc_pwm_ctx ctx[DWC_TIMERS_TOTAL ]; };#define to_dwc_pwm (p) (container_of((p), struct dwc_pwm, chip))
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |
PATCH v6 8/10 pwm: dwc: add of/platform support
In reply to Ben DooksThe dwc pwm controller can be used in non-PCI systems, so allow either platform or OF based probing.
---
v5:
- fix missing " in kconfig
- remove .remove method, devm already sorts this.
- merge pwm-number code
- split the of code out of the core
- get bus clock
v4:
- moved the compile test code earlier
- fixed review comments
- used NS_PER_SEC
- use devm_clk_get_enabled
- ensure we get the bus clock
v3:
- changed compatible name
fixup add pwm/Kconfig
--- drivers/pwm/Kconfig | 9 +++++ drivers/pwm/Makefile | 1 + drivers/pwm/pwm-dwc-of.c | 76 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 drivers/pwm/pwm-dwc-of.c
drivers/pwm/Kconfig +9 -0
@@ -192,6 +192,15 @@ config PWM_DWC_PCI To compile this driver as a module, choose M here: the module will be called pwm-dwc-pci. +config PWM_DWC_OF + tristate "DesignWare PWM Controller (OF bus)" + depends on PWM_DWC && OF + help + PWM driver for Synopsys DWC PWM Controller on an OF bus. + + To compile this driver as a module, choose M here: the module + will be called pwm-dwc-of. + config PWM_EP93XX tristate "Cirrus Logic EP93xx PWM support" depends on ARCH_EP93XX || COMPILE_TEST
drivers/pwm/Makefile +1 -0
@@ -15,6 +15,7 @@ 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_DWC_OF) += pwm-dwc-of.o obj-$(CONFIG_PWM_DWC_PCI) += pwm-dwc-pci.o obj-$(CONFIG_PWM_EP93XX) += pwm-ep93xx.o obj-$(CONFIG_PWM_FSL_FTM) += pwm-fsl-ftm.o
drivers/pwm/pwm-dwc-of.c new file +76 -0
76 lines not on this page · raw message
Signature · 1 line
2.35.1
PATCH v6 9/10 pwm: dwc: add PWM bit unset in get_state call
In reply to Ben DooksIf we are not in PWM mode, then the output is technically a 50% output based on a single timer instead of the high-low based on the two counters. Add a check for the PWM mode in dwc_pwm_get_state() and if DWC_TIM_CTRL_PWM is not set, then return a 50% cycle.
This may only be an issue on initialisation, as the rest of the code currently assumes we're always going to have the extended PWM mode using two counters.
---
v4:
- fixed review comment on mulit-line calculations
--- drivers/pwm/pwm-dwc.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-)
drivers/pwm/pwm-dwc.c +18 -11
@@ -121,23 +121,30 @@ static void dwc_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, {struct dwc_pwm *dwc =to_dwc_pwm (chip);u64 duty, period; +u32 ctrl, ld, ld2;pm_runtime_get_sync (chip->dev); - state->enabled = !!(dwc_pwm_readl (dwc, -DWC_TIM_CTRL (pwm->hwpwm)) &DWC_TIM_CTRL_EN ); + ctrl =dwc_pwm_readl (dwc,DWC_TIM_CTRL (pwm->hwpwm)); + ld =dwc_pwm_readl (dwc,DWC_TIM_LD_CNT (pwm->hwpwm)); + ld2 =dwc_pwm_readl (dwc,DWC_TIM_LD_CNT2 (pwm->hwpwm)); - duty =dwc_pwm_readl (dwc,DWC_TIM_LD_CNT (pwm->hwpwm)); - duty +=1 ; - duty *= dwc->clk_ns; - state->duty_cycle = duty; + state->enabled = !!(ctrl &DWC_TIM_CTRL_EN ); - period =dwc_pwm_readl (dwc,DWC_TIM_LD_CNT2 (pwm->hwpwm)); - period +=1 ; - period *= dwc->clk_ns; - period += duty; - state->period = period; +/* If we're not in PWM, technically the output is a 50-50 +* based on the timer load-count only. +*/ +if (ctrl &DWC_TIM_CTRL_PWM ) { + duty = (ld +1 ) * dwc->clk_ns; + period = (ld2 +1 ) * dwc->clk_ns; + period += duty; + }else { + duty = (ld +1 ) * dwc->clk_ns; + period = duty *2 ; + } + state->period = period; + state->duty_cycle = duty; state->polarity =PWM_POLARITY_INVERSED ;pm_runtime_put_sync (chip->dev);
Signature · 1 line
2.35.1
PATCH v6 10/10 pwm: dwc: use clock rate in hz to avoid rounding issues
In reply to Ben DooksAs noted, the clock-rate when not a nice multiple of ns is probably going to end up with inacurate caculations, as well as on a non pci system the rate may change (although we've not put a clock rate change notifier in this code yet) so we also add some quick checks of the rate when we do any calculations with it.
Signed-off-by; Ben Dooks <[email protected]>
--- drivers/pwm/pwm-dwc-of.c | 2 +- drivers/pwm/pwm-dwc.c | 29 ++++++++++++++++++++--------- drivers/pwm/pwm-dwc.h | 2 +- 3 files changed, 22 insertions(+), 11 deletions(-)
drivers/pwm/pwm-dwc-of.c +1 -1
@@ -50,7 +50,7 @@ static int dwc_pwm_plat_probe(struct platform_device *pdev)return dev_err_probe (dev,PTR_ERR (dwc->clk),"failed to get timer clock\n" ); - dwc->clk_ns =NSEC_PER_SEC /clk_get_rate (dwc->clk); + dwc->clk_rate =clk_get_rate (dwc->clk);return devm_pwmchip_add (dev, &dwc->chip); }
drivers/pwm/pwm-dwc.c +20 -9
@@ -43,18 +43,22 @@ static int __dwc_pwm_configure_timer(struct dwc_pwm *dwc,u32 high;u32 low; +if (dwc->clk) + dwc->clk_rate =clk_get_rate (dwc->clk); +/* * Calculate width of low and high period in terms of input clock * periods and check are the result within HW limits between 1 and * 2^32 periods. */ - tmp =DIV_ROUND_CLOSEST_ULL (state->duty_cycle, dwc->clk_ns); + tmp = state->duty_cycle * dwc->clk_rate; + tmp =DIV_ROUND_CLOSEST_ULL (tmp,NSEC_PER_SEC );if (tmp <1 || tmp > (1ULL <<32 ))return -ERANGE ; low = tmp -1 ; - tmp =DIV_ROUND_CLOSEST_ULL (state->period - state->duty_cycle, - dwc->clk_ns); + tmp = (state->period - state->duty_cycle) * dwc->clk_rate; + tmp =DIV_ROUND_CLOSEST_ULL (tmp,NSEC_PER_SEC );if (tmp <1 || tmp > (1ULL <<32 ))return -ERANGE ; high = tmp -1 ;
@@ -120,6 +124,7 @@ static void dwc_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, struct pwm_state *state) {struct dwc_pwm *dwc =to_dwc_pwm (chip); +unsigned long clk_rate;u64 duty, period;u32 ctrl, ld, ld2;
@@ -129,22 +134,28 @@ static void dwc_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, ld =dwc_pwm_readl (dwc,DWC_TIM_LD_CNT (pwm->hwpwm)); ld2 =dwc_pwm_readl (dwc,DWC_TIM_LD_CNT2 (pwm->hwpwm)); +if (dwc->clk) + dwc->clk_rate =clk_get_rate (dwc->clk); + + clk_rate = dwc->clk_rate; state->enabled = !!(ctrl &DWC_TIM_CTRL_EN );/* If we're not in PWM, technically the output is a 50-50 * based on the timer load-count only. */ if (ctrl &DWC_TIM_CTRL_PWM ) { - duty = (ld +1 ) * dwc->clk_ns; - period = (ld2 +1 ) * dwc->clk_ns; + duty = ld +1 ; + period = ld2 +1 ; period += duty; }else { - duty = (ld +1 ) * dwc->clk_ns; + duty = ld +1 ; period = duty *2 ; } - state->period = period; - state->duty_cycle = duty; + duty *=NSEC_PER_SEC ; + period *=NSEC_PER_SEC ; + state->period =DIV_ROUND_CLOSEST_ULL (period, clk_rate); + state->duty_cycle =DIV_ROUND_CLOSEST_ULL (duty, clk_rate); state->polarity =PWM_POLARITY_INVERSED ;pm_runtime_put_sync (chip->dev);
@@ -164,7 +175,7 @@ struct dwc_pwm *dwc_pwm_alloc(struct device *dev)if (!dwc)return NULL ; - dwc->clk_ns =10 ; + dwc->clk_rate =NSEC_PER_SEC /10 ; dwc->chip.dev = dev; dwc->chip.ops = &dwc_pwm_ops; dwc->chip.npwm =DWC_TIMERS_TOTAL ;
drivers/pwm/pwm-dwc.h +1 -1
@@ -41,7 +41,7 @@ struct dwc_pwm {struct pwm_chip chip;void __iomem *base;struct clk *clk; -unsigned int clk_ns; +unsigned long clk_rate;struct dwc_pwm_ctx ctx[DWC_TIMERS_TOTAL ]; };#define to_dwc_pwm (p) (container_of((p), struct dwc_pwm, chip))
Signature · 1 line
2.35.1
Re: [PATCH v6 10/10] pwm: dwc: use clock rate in hz to avoid rounding issues
Hello Ben,
Quoted 19 lines · Ben Dooks
As noted, the clock-rate when not a nice multiple of ns is probably going to end up with inacurate caculations, as well as on a non pci system the rate may change (although we've not put a clock rate change notifier in this code yet) so we also add some quick checks of the rate when we do any calculations with it.
Signed-off-by; Ben Dooks <[email protected]>
Reported-by Uwe Kleine-König <[email protected]>--- drivers/pwm/pwm-dwc-of.c | 2 +- drivers/pwm/pwm-dwc.c | 29 ++++++++++++++++++++--------- drivers/pwm/pwm-dwc.h | 2 +- 3 files changed, 22 insertions(+), 11 deletions(-)drivers/pwm/pwm-dwc-of.c +0
-0
drivers/pwm/pwm-dwc-of.c static int dwc_pwm_plat_probe(struct platform_device *pdev) · line 53
Quoted 5 lines
drivers/pwm/pwm-dwc-of.c +1
-1@@ -50,7 +50,7 @@ static int dwc_pwm_plat_probe(struct platform_device *pdev)return dev_err_probe (dev,PTR_ERR (dwc->clk),"failed to get timer clock\n" ); - dwc->clk_ns =NSEC_PER_SEC /clk_get_rate (dwc->clk); + dwc->clk_rate =clk_get_rate (dwc->clk);
Given that clk_ns is introduced only in this series, I suggest to make it right from the start.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |
Re: [PATCH v6 10/10] pwm: dwc: use clock rate in hz to avoid rounding issues
Quoted 25 lines · Uwe Kleine-König
Hello Ben,
Quoted 22 lines · Ben Dooks
As noted, the clock-rate when not a nice multiple of ns is probably going to end up with inacurate caculations, as well as on a non pci system the rate may change (although we've not put a clock rate change notifier in this code yet) so we also add some quick checks of the rate when we do any calculations with it.
Signed-off-by; Ben Dooks <[email protected]>
Reported-by Uwe Kleine-König <[email protected]>--- drivers/pwm/pwm-dwc-of.c | 2 +- drivers/pwm/pwm-dwc.c | 29 ++++++++++++++++++++--------- drivers/pwm/pwm-dwc.h | 2 +- 3 files changed, 22 insertions(+), 11 deletions(-)drivers/pwm/pwm-dwc-of.c +0
-0@@ -50,7 +50,7 @@ static int dwc_pwm_plat_probe(struct platform_device *pdev)return dev_err_probe (dev,PTR_ERR (dwc->clk),"failed to get timer clock\n" );
Quoted 5 lines
drivers/pwm/pwm-dwc-of.c static int dwc_pwm_plat_probe(struct platform_device *pdev) · line 53
Quoted 2 lines
drivers/pwm/pwm-dwc-of.c +1
-1- dwc->clk_ns =NSEC_PER_SEC /clk_get_rate (dwc->clk); + dwc->clk_rate =clk_get_rate (dwc->clk);Given that
clk_nsis introduced only in this series, I suggest to make it right from the start.
I was trying to keep the splitting of the driver and the clock changes separate to make any possible bisection easier.
Signature · 1 line
Ben
Hi
Quoted 8 lines · Ben Dooks
This is an updated version of the Designware PWM driver updates for OF support, which now splits the driver into PCI and OF parts as well as tries to sort out the review comments.
Hopefully this can now be queued for the next kernel version.
v6:
- fix removal ordering ofDWC_PERIOD_NS
I did a quick test on our HW and PWM was counting as before.
Quoted 7 lines · Jarkko Nikula
Hi
Quoted 4 lines · Ben Dooks
This is an updated version of the Designware PWM driver updates for OF support, which now splits the driver into PCI and OF parts as well as tries to sort out the review comments.
Quoted 8 lines
Quoted 4 lines
Hopefully this can now be queued for the next kernel version.
v6:
- fix removal ordering ofDWC_PERIOD_NSI did a quick test on our HW and PWM was counting as before.
Tested-by Jarkko Nikula <[email protected]>
Ok, great to hear, thank you.
I guess I should sort out putting a v7 out this week with all the updated comments.
Quoted 7 lines · Jarkko Nikula
Hi
Quoted 4 lines · Ben Dooks
This is an updated version of the Designware PWM driver updates for OF support, which now splits the driver into PCI and OF parts as well as tries to sort out the review comments.
Quoted 8 lines
Quoted 4 lines
Hopefully this can now be queued for the next kernel version.
v6:
- fix removal ordering ofDWC_PERIOD_NSI did a quick test on our HW and PWM was counting as before.
Tested-by Jarkko Nikula <[email protected]>
Just to follow up on this, should I post a v7 of this (given I think it is all just updates for review/tested) ?
Signature · 1 line
Ben
Quoted 13 lines · Ben Dooks
Quoted 12 lines · Jarkko Nikula
Hi
Quoted 8 lines · Ben Dooks
This is an updated version of the Designware PWM driver updates for OF support, which now splits the driver into PCI and OF parts as well as tries to sort out the review comments.
Hopefully this can now be queued for the next kernel version.
v6:
- fix removal ordering ofDWC_PERIOD_NS
Quoted 6 lines
Quoted 3 lines
I did a quick test on our HW and PWM was counting as before.
Tested-by Jarkko Nikula <[email protected]>Just to follow up on this, should I post a v7 of this (given I think it is all just updates for review/tested) ?
Just to add the tags doesn't justify a resend.
Reviewing this is in my todo list, I hope to come to it later this week.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |