Support pwm driver for aspeed ast26xx
Subsystems (5)
Billy Tsai
reviewerv13 cover Support pwm driver for aspeed ast26xx
The legacy driver of aspeed pwm is binding with tach controller and it doesn't follow the pwm framworks usage. In addition, the pwm register usage of the 6th generation of ast26xx has drastic change. So these patch serials add the new aspeed pwm driver to fix up the problem above.
Change since v12:
- pwm-aspeed-ast2600.c
- Fix the comment about the duty cycle and period of the PWM.
- Configured to max period when request period > max period.
- Remove unnecessary curly braces.
Change since v11:
- pwm-aspeed-ast2600.c
- Request reset controller before clock enable.
Change since v10:
- pwm-aspeed-ast2600.c
- Add more comment to explain the feature of PWM
- Fix the naming of some parameters.
- Set pin_enable and clk_enable at the same time.
- Always set fixed divisor to hw register when apply.
Change since v9:
- dt-bindings:
- Change the naming of tach subnode channel setting property to aspeed,tach-ch.
- pwm-aspeed-ast2600.c
- Fix the naming of some parameters.
- Capitalise error messages.
- Handling potentially mult overflow when .apply
Change since v8:
- pwm-aspeed-ast2600.c
- Replace "* _BITULL(div_h)" to "<< div_h"
- Fix duty_cycle precision problem.
- Add the comment about the formula of duty_cycle.
Change since v7:
- pwm-aspeed-g6.c
- Rename the driver: pwm-aspeed-g6.c -> pwm-aspeed-ast2600.c.
- Macro remove "_CH" part of the register name.
- Unroll the aspeed_pwm_get_period and remove it.
- Simplify the formula to get duty_pt
- Reduce the number of writing register. Organize all the fields and write them at once.
Change since v6:
- dt-bindings:
- Add blank line between each DT property.
- Change the sub-node name from fan to tach-ch.
- pwm-aspeed-g6.c
- Merge aspeed_pwm_set_period and aspeed_pwm_set_duty into .apply.
- Convert the factor type to u64 when calculating the period value.
- Using ROUND_UP strategy to calculate div_h for finer resolution.
Change since v5:
- pwm-aspeed-g6.c suggested by Uwe Kleine-K?nig
- Move the divide at the end of the calculation.
- Unified the prefix of the function name.
- Use div64_u64 to calculate the divider of frequency.
Change since v4:
- dt_binding:
- pwm/tach yaml: Replace child-node with additionalProperties
- pwm-tach yaml: Replace child-node with patternProperties
- pwm-aspeed-g6.c suggested by Uwe Kleine-K?nig
- The bit definitions contained the name of the register.
- Remove single caller function and fold it to the caller.
- Avoid to divide by the result of a division.
- Remove unnecessary condition in .apply().
- Use goto for error handling
Changes since v3:
- Add the dt_binding for aspeed,ast2600-tach.
- Describe the pwm/tach as child-node of pwm-tach mfd.
- Complete the properties of pwm node.
Changes since v2:
- Remove the tach node, #address-cells and #size-cells from pwm-tach.yaml
- Add clocks and reset properties to pwm-tach.yaml
- Kconfig/Makfile sorted alphabetically
- pwm-aspeed-g6.c suggested by Uwe Kleine-K?nig
- Add more hardware descriptions at top of the driver.
- Remove unused api request and free
- Move the initialize settings of all pwm channel to probe.
- Change the method of getting the approximate period.
- Read the hardware register values to fill the state for .get_state()
Changes since v1:
- Fix the dt_binding_check fail suggested by Rob Herring
- Add depends to PWM_ASPEED_G6 configure suggested by Uwe Kleine-Konig
- pwm-aspeed-g6.c suggested by Uwe Kleine-K?nig
- Fix license header
- Use bitfiled.h macro to define register fields
- Implement .remove device function
- Implement .get_state pwm api
Billy Tsai (2):
dt-bindings: Add bindings for aspeed pwm-tach.
pwm: Add Aspeed ast2600 PWM support
.../bindings/hwmon/aspeed,ast2600-tach.yaml | 68 ++++ .../bindings/mfd/aspeed,ast2600-pwm-tach.yaml | 76 ++++ .../bindings/pwm/aspeed,ast2600-pwm.yaml | 64 ++++ drivers/pwm/Kconfig | 10 + drivers/pwm/Makefile | 1 + drivers/pwm/pwm-aspeed-ast2600.c | 327 ++++++++++++++++++ 6 files changed, 546 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/aspeed,ast2600-tach.yaml create mode 100644 Documentation/devicetree/bindings/mfd/aspeed,ast2600-pwm-tach.yaml create mode 100644 Documentation/devicetree/bindings/pwm/aspeed,ast2600-pwm.yaml create mode 100644 drivers/pwm/pwm-aspeed-ast2600.c
Signature · 1 line
2.25.1
Billy Tsai
reviewerPATCH v13 1/2 dt-bindings: Add bindings for aspeed pwm-tach.
This patch adds device binding for aspeed pwm-tach device which is a multi-function device include pwm and tach function and pwm/tach device bindings which should be the child-node of pwm-tach device.
--- .../bindings/hwmon/aspeed,ast2600-tach.yaml | 68 +++++++++++++++++ .../bindings/mfd/aspeed,ast2600-pwm-tach.yaml | 76 +++++++++++++++++++ .../bindings/pwm/aspeed,ast2600-pwm.yaml | 64 ++++++++++++++++ 3 files changed, 208 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/aspeed,ast2600-tach.yaml create mode 100644 Documentation/devicetree/bindings/mfd/aspeed,ast2600-pwm-tach.yaml create mode 100644 Documentation/devicetree/bindings/pwm/aspeed,ast2600-pwm.yaml
Documentation/devicetree/bindings/hwmon/aspeed,ast2600-tach.yaml new file +68 -0
@@ -0,0 +1,68 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +# Copyright (C) 2021 Aspeed, Inc. +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/hwmon/aspeed,ast2600-tach.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Aspeed Ast2600 Tach controller + +maintainers: + - Billy Tsai <[email protected]> + +description: | + The Aspeed Tach controller can support upto 16 fan input. + This module is part of the ast2600-pwm-tach multi-function device. For more + details see ../mfd/aspeed,ast2600-pwm-tach.yaml. + +properties: + compatible: + enum: + - aspeed,ast2600-tach + + "#address-cells": + const: 1 + + "#size-cells": + const: 0 + + pinctrl-0: true + + pinctrl-names: + const: default + +required: + - compatible + - "#address-cells" + - "#size-cells" + +additionalProperties: + type: object + properties: + aspeed,tach-ch: + description: + The tach channel used for this node. + maxItems: 1 + + aspeed,min-rpm: + description: + define the minimal revolutions per minute of the measure fan + used to calculate the sample period of tach + default: 1000 + + aspeed,pulse-pr: + description: + Value specifying the number of pulses per revolution of the + monitored FAN. + default: 2 + + aspeed,tach-div: + description: + define the tachometer clock divider as an integer. Formula of + tach clock = clock source / (2^tach-div)^2 + minimum: 0 + maximum: 15 + default: 5 + + required: + - reg
Documentation/devicetree/bindings/mfd/aspeed,ast2600-pwm-tach.yaml new file +76 -0
76 lines not on this page · raw message
Documentation/devicetree/bindings/pwm/aspeed,ast2600-pwm.yaml new file +64 -0
64 lines not on this page · raw message
Signature · 1 line
2.25.1
Billy Tsai
reviewerPATCH v13 2/2 pwm: Add Aspeed ast2600 PWM support
In reply to Billy TsaiThis patch add the support of PWM controller which can be found at aspeed ast2600 soc. The pwm supoorts up to 16 channels and it's part function of multi-function device "pwm-tach controller".
--- drivers/pwm/Kconfig | 10 + drivers/pwm/Makefile | 1 + drivers/pwm/pwm-aspeed-ast2600.c | 327 +++++++++++++++++++++++++++++++ 3 files changed, 338 insertions(+) create mode 100644 drivers/pwm/pwm-aspeed-ast2600.c
drivers/pwm/Kconfig +10 -0
@@ -51,6 +51,16 @@ config PWM_AB8500 To compile this driver as a module, choose M here: the module will be called pwm-ab8500. +config PWM_ASPEED_AST2600 + tristate "Aspeed ast2600 PWM support" + depends on ARCH_ASPEED || COMPILE_TEST + depends on HAVE_CLK && HAS_IOMEM + help + This driver provides support for Aspeed ast2600 PWM controllers. + + To compile this driver as a module, choose M here: the module + will be called pwm-aspeed-ast2600. + config PWM_ATMEL tristate "Atmel PWM support" depends on OF
drivers/pwm/Makefile +1 -0
@@ -2,6 +2,7 @@ obj-$(CONFIG_PWM) += core.o obj-$(CONFIG_PWM_SYSFS) += sysfs.o obj-$(CONFIG_PWM_AB8500) += pwm-ab8500.o +obj-$(CONFIG_PWM_ASPEED_AST2600) += pwm-aspeed-ast2600.o obj-$(CONFIG_PWM_ATMEL) += pwm-atmel.o obj-$(CONFIG_PWM_ATMEL_HLCDC_PWM) += pwm-atmel-hlcdc.o obj-$(CONFIG_PWM_ATMEL_TCB) += pwm-atmel-tcb.o
drivers/pwm/pwm-aspeed-ast2600.c new file +327 -0
327 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [v13 2/2] pwm: Add Aspeed ast2600 PWM support
Hello Billy,
just two minor thing left to criticise:
drivers/pwm/pwm-aspeed-ast2600.c line 138
Quoted 6 lines · Billy Tsai
drivers/pwm/pwm-aspeed-ast2600.c new file +6
-0+if (clk_en && duty_pt) { + dividend = (u64 )NSEC_PER_SEC * (div_l +1 ) * duty_pt + << div_h; + state->duty_cycle =DIV_ROUND_UP_ULL (dividend, rate); + }else + state->duty_cycle = clk_en ? state->period :0 ;
I wonder about checkpatch not criticising this construct. See Documentation/process/coding-style.rst:
Do not unnecessarily use braces where a single statement will do. [...] This does not apply if only one branch of a conditional statement is a single statement; in the latter case use braces in both branches
Quoted 8 lines
[...]
drivers/pwm/pwm-aspeed-ast2600.c new file +7
-0+static int aspeed_pwm_apply (struct pwm_chip *chip,struct pwm_device *pwm, +const struct pwm_state *state) +{ +struct device *dev = chip->dev; +struct aspeed_pwm_data *priv =aspeed_pwm_chip_to_data (chip); +u32 hwpwm = pwm->hwpwm, duty_pt; +unsigned long rate;
drivers/pwm/pwm-aspeed-ast2600.c line 161
Quoted 10 lines
drivers/pwm/pwm-aspeed-ast2600.c new file +10
-0+u64 div_h, div_l, divisor, expect_period; +bool clk_en; + + expect_period = state->period; +dev_dbg (dev,"expect period: %lldns, duty_cycle: %lldns" , expect_period, + state->duty_cycle); + + rate =clk_get_rate (priv->clk); +if (expect_period >div64_u64 (ULLONG_MAX , (u64 )rate)) + expect_period =div64_u64 (ULLONG_MAX , (u64 )rate);
If you write that as
expect_period = min(div64_u64(ULLONG_MAX, (u64)rate), expect_period);
you make sure that the division is only calculated once.
Best regards
Uwe
Signature · 9 lines
Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | https://www.pengutronix.de/ | -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 488 bytes Desc: not available URL: <http://lists.ozlabs.org/pipermail/linux-aspeed/attachments/20211129/4c8503dc/attachment.sig>
Re: [v13 2/2] pwm: Add Aspeed ast2600 PWM support
In reply to Billy TsaiOn Mon, 2021-11-29 at 14:43 +0800, Billy Tsai wrote:
[...]
drivers/pwm/pwm-aspeed-ast2600.c line 275
Quoted 9 lines
drivers/pwm/pwm-aspeed-ast2600.c new file +9
-0+ ret =clk_prepare_enable (priv->clk); +if (ret) +return dev_err_probe (dev, ret,"Couldn't enable clock\n" ); + + ret =reset_control_deassert (priv->reset); +if (ret) { +dev_err_probe (dev, ret,"Couldn't deassert reset control\n" ); + goto err_disable_clk; + }
Is there any reason to keep the clocks running and the controller out of reset while the PWM outputs are disabled?
regards
Philipp
Billy Tsai
reviewerRe: [v13 2/2] pwm: Add Aspeed ast2600 PWM support
Hi Philipp,
On 2021/11/30, 5:52 PM, "Philipp Zabel" <[email protected]> wrote:
On Mon, 2021-11-29 at 14:43 +0800, Billy Tsai wrote:
[...]
> > + ret = clk_prepare_enable(priv->clk);
> > + if (ret)
> > + return dev_err_probe(dev, ret, "Couldn't enable clock\n");
> > +
> > + ret = reset_control_deassert(priv->reset);
> > + if (ret) {
> > + dev_err_probe(dev, ret, "Couldn't deassert reset control\n");
> > + goto err_disable_clk;
> > + }
> Is there any reason to keep the clocks running and the controller out of
> reset while the PWM outputs are disabled?Can you tell me about your concerns with this process?
In my opinion, they are used to provide the clock and de-assert the reset of the PWM engine. If we didn't release them in probe stage the CPU can't and shouldn't read the register of the PWM engine when call the get_state. Assume that we want to adjust them dynamically, the driver needs to add more conditions to check and keep the status of each PWM channel, which is not a good deal for the server platform.
Thanks
Best Regards,
Billy Tsai
Re: [v13 2/2] pwm: Add Aspeed ast2600 PWM support
Hi Billy,
Quoted 16 lines · Billy Tsai
Hi Philipp,
On 2021/11/30, 5:52 PM, "Philipp Zabel" <[email protected]> wrote:
????On Mon, 2021-11-29 at 14:43 +0800, Billy Tsai wrote:
????[...]????> > + ret = clk_prepare_enable(priv->clk); ????> > + if (ret) ????> > + return dev_err_probe(dev, ret, "Couldn't enable clock\n"); ????> > + ????> > + ret = reset_control_deassert(priv->reset); ????> > + if (ret) { ????> > + dev_err_probe(dev, ret, "Couldn't deassert reset control\n"); ????> > + goto err_disable_clk; ????> > + }
Quoted 4 lines
????> Is there any reason to keep the clocks running and the controller out of
????> reset while the PWM outputs are disabled?Can you tell me about your concerns with this process?
No particular concerns, just curiosity.
Quoted 4 lines
In my opinion, they are used to provide the clock and de-assert the reset of the PWM engine. If we didn't release them in probe stage the CPU can't and shouldn't read the register of the PWM engine when call the
get_state. Assume that we want to adjust them dynamically, the driver needs to add more conditions to check and keep the status of each PWM channel, which is not a good deal for the server platform.
Thanks. I don't know the hardware, so I have no idea whether disabling the clocks would even save a measurable (let alone appreciable) amount of power.
I've just seen other PWM drivers use runtime PM or enable/disable clocks dynamically, and wondered why this one doesn't.
regards
Philipp
Billy Tsai
reviewerRe: [v13 2/2] pwm: Add Aspeed ast2600 PWM support
Hi Philipp,
On 2021/12/1, 5:12 PM, "Philipp Zabel" <[email protected]> wrote:
Hi Billy,
On Wed, 2021-12-01 at 03:30 +0000, Billy Tsai wrote:
> > Hi Philipp,
> >
> > On 2021/11/30, 5:52 PM, "Philipp Zabel" <[email protected]> wrote:
> >
> > On Mon, 2021-11-29 at 14:43 +0800, Billy Tsai wrote:
> > [...]
> > > > + ret = clk_prepare_enable(priv->clk);
> > > > + if (ret)
> > > > + return dev_err_probe(dev, ret, "Couldn't enable clock\n");
> > > > +
> > > > + ret = reset_control_deassert(priv->reset);
> > > > + if (ret) {
> > > > + dev_err_probe(dev, ret, "Couldn't deassert reset control\n");
> > > > + goto err_disable_clk;
> > > > + }
> >
> > > Is there any reason to keep the clocks running and the controller out of
> > > reset while the PWM outputs are disabled?
> >
> > Can you tell me about your concerns with this process?
> No particular concerns, just curiosity.
> > In my opinion, they are used to provide the clock and de-assert the reset of the PWM engine. If we didn't release
> > them in probe stage the CPU can't and shouldn't read the register of the PWM engine when call the get_state.
> > Assume that we want to adjust them dynamically, the driver needs to add more conditions to check and keep the status
> > of each PWM channel, which is not a good deal for the server platform.
> Thanks. I don't know the hardware, so I have no idea whether disabling
> the clocks would even save a measurable (let alone appreciable) amount
> of power.
> I've just seen other PWM drivers use runtime PM or enable/disable clocks
> dynamically, and wondered why this one doesn't.Thanks for the heads up, I think that for the usage we don't need to implement that.
Best Regards,
Billy Tsai