Add the Allwinner A31/A31s PWM driver
Subsystems (3)
v3 cover Add the Allwinner A31/A31s PWM driver
From: Siarhei Volkau <[email protected]>
Main goal is to add support of the sun6i PWM variant.
This is the third version of the sun6i PWM patchset. Difference between v2 and v3:
- regmap API used for access to PWM registers.
Thanks to Maxime Ripard for pointing me to the regmap API.
Siarhei Volkau (4):
pwm: sunxi: Code switched to regmap API instead of iomem.
pwm: sunxi: Selectable prescaler table for support sun6i.
pwm: sunxi: Add support the Allwinner A31 PWM.
ARM: dts: sun6i: Add the PWM block to the A31/A31s.
.../devicetree/bindings/pwm/pwm-sun4i.txt | 3 +- arch/arm/boot/dts/sun6i-a31.dtsi | 8 + drivers/pwm/Kconfig | 2 +- drivers/pwm/pwm-sun4i.c | 359 ++++++++++++++++----- 4 files changed, 294 insertions(+), 78 deletions(-)
--
2.4.11
A message that is not in the archive (sent off-list or not yet received): 1487189167-32486-1-git-send-email-lis8215-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
PATCH v3 1/4 pwm: sunxi: Code switched to regmap API instead of iomem.
From: Siarhei Volkau <[email protected]>
sun6i PWM has different register map in comparison to sun4i compatible SoCs. But bit map of the registers and behavior are very similar.
This patch introduces a uniform way to access PWM registers.
--- drivers/pwm/Kconfig | 2 +- drivers/pwm/pwm-sun4i.c | 263 ++++++++++++++++++++++++++++++++++-------------- 2 files changed, 191 insertions(+), 74 deletions(-)
drivers/pwm/Kconfig +1 -1
@@ -416,7 +416,7 @@ config PWM_STMPE config PWM_SUN4I tristate "Allwinner PWM support" depends on ARCH_SUNXI || COMPILE_TEST - depends on HAS_IOMEM && COMMON_CLK + depends on REGMAP_MMIO && COMMON_CLK help Generic PWM framework driver for Allwinner SoCs.
drivers/pwm/pwm-sun4i.c +190 -73
428 lines not on this page · raw message
--
2.4.11
A message that is not in the archive (sent off-list or not yet received): 1487189167-32486-2-git-send-email-lis8215-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Re: [PATCH v3 1/4] pwm: sunxi: Code switched to regmap API instead of iomem.
Hi,
Quoted 8 lines · On Wed, Feb 15, 2017 at 11:06:04PM +0300…
From: Siarhei Volkau <[email protected]>
sun6i PWM has different register map in comparison to sun4i compatible SoCs. But bit map of the registers and behavior are very similar.
This patch introduces a uniform way to access PWM registers.
Signed-off-by Siarhei Volkau <[email protected]>
In order to be easier to review (and bisect if needed), could you split that patch into one to convert to the regmap API, without any change but to replace the sun4i_pwm_readl/sun4i_pwm_writel calls by their regmap equivalent, and then convert to the regmap fields the registers that need to?
Quoted 85 lines
--- drivers/pwm/Kconfig | 2 +- drivers/pwm/pwm-sun4i.c | 263 ++++++++++++++++++++++++++++++++++-------------- 2 files changed, 191 insertions(+), 74 deletions(-)drivers/pwm/Kconfig +1
-1@@ -416,7 +416,7 @@ config PWM_STMPE config PWM_SUN4I tristate "Allwinner PWM support" depends on ARCH_SUNXI || COMPILE_TEST - depends on HAS_IOMEM && COMMON_CLK + depends on REGMAP_MMIO && COMMON_CLK help Generic PWM framework driver for Allwinner SoCs.drivers/pwm/pwm-sun4i.c +32
-11@@ -9,7 +9,7 @@#include <linux/bitops.h> #include <linux/clk.h> #include <linux/err.h> -#include <linux/io.h> +#include <linux/regmap.h> #include <linux/module.h> #include <linux/of.h> #include <linux/of_device.h> @@ -26,25 +26,56 @@#define PWM_CH_PRD (ch) (PWM_CH_PRD_BASE + PWM_CH_PRD_OFFSET * (ch))#define PWMCH_OFFSET 15 -#define PWM_PRESCAL_MASK GENMASK(3, 0) -#define PWM_PRESCAL_OFF 0 -#define PWM_EN BIT(4) -#define PWM_ACT_STATE BIT(5) -#define PWM_CLK_GATING BIT(6) -#define PWM_MODE BIT(7) -#define PWM_PULSE BIT(8) -#define PWM_BYPASS BIT(9) + +#define PWM_PRESCAL_LSB 0 +#define PWM_PRESCAL_MSB 3 +#define PWM_PRESCAL_MASK GENMASK(PWM_PRESCAL_MSB - PWM_PRESCAL_LSB, 0) + +#define PWM_EN_BIT 4 +#define PWM_ACT_STATE_BIT 5 +#define PWM_CLK_GATING_BIT 6 +#define PWM_MODE_BIT 7 +#define PWM_PULSE_BIT 8 +#define PWM_BYPASS_BIT 9#define PWM_RDY_BASE 28#define PWM_RDY_OFFSET 1 -#define PWM_RDY (ch) BIT(PWM_RDY_BASE + PWM_RDY_OFFSET * (ch)) +#define PWM_RDY_BIT (ch) (PWM_RDY_BASE + PWM_RDY_OFFSET * (ch))#define PWM_PRD (prd) (((prd) - 1) << 16)#define PWM_PRD_MASK GENMASK(15, 0)#define PWM_DTY_MASK GENMASK(15, 0) -#define BIT_CH (bit, chan) ((bit) << ((chan) * PWMCH_OFFSET)) +#define BIT_CH (bit, chan) ((bit) + ((chan) * PWMCH_OFFSET)) + +#define FIELD_PRESCALER 0 +#define FIELD_POLARITY 1 +#define FIELD_CLK_GATING 2 +#define FIELD_READY 3 +#define NUM_FIELDS 4 + +#define MAX_CHANNELS 2 + +#define SUN4I_REGMAP_FIELDS (chan) {\ + [FIELD_PRESCALER] = \ + REG_FIELD(PWM_CTRL_REG, \ + BIT_CH(PWM_PRESCAL_LSB, chan), \ + BIT_CH(PWM_PRESCAL_MSB, chan)), \ + [FIELD_POLARITY] = \ + REG_FIELD(PWM_CTRL_REG, \ + BIT_CH(PWM_ACT_STATE_BIT, chan), \ + BIT_CH(PWM_ACT_STATE_BIT, chan)), \
drivers/pwm/pwm-sun4i.c line 78
Quoted 10 lines
drivers/pwm/pwm-sun4i.c +10
-0+ [FIELD_CLK_GATING ] = \ +REG_FIELD (PWM_CTRL_REG , \ +BIT_CH (PWM_CLK_GATING_BIT , chan), \ + BIT_CH(PWM_CLK_GATING_BIT, chan)), \ + [FIELD_READY ] = \ +REG_FIELD (PWM_CTRL_REG , \ +PWM_RDY_BIT (chan), \ + PWM_RDY_BIT(chan)), \ +} +
This is not correct, unfortunately. If someone calls that macro with chan++ or chan--, it will be modified four times instead of one as the caller would expect.
Thanks!
Maxime
Signature · 3 lines
Maxime Ripard, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
Re: [PATCH v3 1/4] pwm: sunxi: Code switched to regmap API instead of iomem.
Hello,
Quoted 5 lines
In order to be easier to review (and bisect if needed), could you split that patch into one to convert to the regmap API, without any change but to replace the sun4i_pwm_readl/sun4i_pwm_writel calls by their regmap equivalent, and then convert to the regmap fields the registers that need to?
Looks reasonable, will be done shortly.
Quoted 15 lines
Quoted 15 lines
drivers/pwm/pwm-sun4i.c +15
-0+#define SUN4I_REGMAP_FIELDS (chan) {\ + [FIELD_PRESCALER] = \ + REG_FIELD(PWM_CTRL_REG, \ + BIT_CH(PWM_PRESCAL_LSB, chan), \ + BIT_CH(PWM_PRESCAL_MSB, chan)), \ + [FIELD_POLARITY] = \ + REG_FIELD(PWM_CTRL_REG, \ + BIT_CH(PWM_ACT_STATE_BIT, chan), \ + BIT_CH(PWM_ACT_STATE_BIT, chan)), \ + [FIELD_CLK_GATING] = \ + REG_FIELD(PWM_CTRL_REG, \ + BIT_CH(PWM_CLK_GATING_BIT, chan), \ + BIT_CH(PWM_CLK_GATING_BIT, chan)), \ + [FIELD_READY] = \ + REG_FIELD(PWM_CTRL_REG, \
Quoted 8 lines
drivers/pwm/pwm-sun4i.c line 78
Quoted 4 lines
drivers/pwm/pwm-sun4i.c +4
-0+ PWM_RDY_BIT(chan), \ + PWM_RDY_BIT(chan)), \ +} +This is not correct, unfortunately. If someone calls that macro with chan++ or chan--, it will be modified four times instead of one as the caller would expect.
Ok, i will refactor that.
I think you should know about existence of unsafe macros (like MIN MAX or ABS) into existing linux kernel tree, this macros can be easily refactored into the inline functions. Please tell me your point of view on that things.
Thanks,
Siarhei.
A message that is not in the archive (sent off-list or not yet received): CAKNVLfa-doz_6oARF5Eg1EbKFuita34Pg2x6Jutjzt9fshUEwQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Re: [PATCH v3 1/4] pwm: sunxi: Code switched to regmap API instead of iomem.
Hi,
Quoted 24 lines · Siarhei Volkau
Quoted 15 lines
Quoted 15 lines
drivers/pwm/pwm-sun4i.c +15
-0+#define SUN4I_REGMAP_FIELDS (chan) {\ + [FIELD_PRESCALER] = \ + REG_FIELD(PWM_CTRL_REG, \ + BIT_CH(PWM_PRESCAL_LSB, chan), \ + BIT_CH(PWM_PRESCAL_MSB, chan)), \ + [FIELD_POLARITY] = \ + REG_FIELD(PWM_CTRL_REG, \ + BIT_CH(PWM_ACT_STATE_BIT, chan), \ + BIT_CH(PWM_ACT_STATE_BIT, chan)), \ + [FIELD_CLK_GATING] = \ + REG_FIELD(PWM_CTRL_REG, \ + BIT_CH(PWM_CLK_GATING_BIT, chan), \ + BIT_CH(PWM_CLK_GATING_BIT, chan)), \ + [FIELD_READY] = \ + REG_FIELD(PWM_CTRL_REG, \Quoted 8 lines
drivers/pwm/pwm-sun4i.c line 78
Quoted 4 lines
drivers/pwm/pwm-sun4i.c +4
-0+ PWM_RDY_BIT(chan), \ + PWM_RDY_BIT(chan)), \ +} +This is not correct, unfortunately. If someone calls that macro with chan++ or chan--, it will be modified four times instead of one as the caller would expect.
Quoted 5 lines
Ok, i will refactor that.
I think you should know about existence of unsafe macros (like MIN MAX or ABS) into existing linux kernel tree, this macros can be easily refactored into the inline functions. Please tell me your point of view on that things.
This might be bad, but we also have functions for those, which should behave properly. Anyway, I don't really expect you to fix the whole kernel before taking that patch in :)
Maxime
Signature · 3 lines
Maxime Ripard, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
PATCH v3 2/4 pwm: sunxi: Selectable prescaler table for support sun6i.
In reply to a message not in the archiveFrom: Siarhei Volkau <[email protected]>
This patch not introduce new features, just prepare code for adding sun6i PWM driver in next commit.
A31 SoC have a different set of prescalers than sun4i compatible ASoCs, but its position and count in the control register are the same.
This patch make the table of prescalers customizable.
--- drivers/pwm/pwm-sun4i.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/pwm/pwm-sun4i.c +8 -1
@@ -77,7 +77,7 @@ } -static const u32 prescaler_table[] = { +static const u32 sun4i_prescaler_table[] = {120 ,180 ,240 ,
@@ -107,6 +107,7 @@ struct sun4i_pwm_data {bool has_prescaler_bypass;bool has_rdy;unsigned int npwm; +const u32 *prescaler_table;const struct sunxi_pwmch_reg_info *chan_info; };
@@ -129,6 +130,7 @@ static int sun4i_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, {struct sun4i_pwm_chip *sun4i_pwm =to_sun4i_pwm_chip (chip);struct regmap_field **chan_fields = sun4i_pwm->fields[pwm->hwpwm]; +const u32 *prescaler_table = sun4i_pwm->data->prescaler_table;u32 prd, dty, busy, clk_gate;u64 clk_rate, div =0 ;unsigned int prescaler =0 ;
@@ -328,6 +330,7 @@ static const struct sun4i_pwm_data sun4i_pwm_data_a10 = { .has_prescaler_bypass = false, .has_rdy = false, .npwm = 2, + .prescaler_table = sun4i_prescaler_table, .chan_info = sun4i_field_info, };
@@ -335,6 +338,7 @@ static const struct sun4i_pwm_data sun4i_pwm_data_a10s = { .has_prescaler_bypass = true, .has_rdy = true, .npwm = 2, + .prescaler_table = sun4i_prescaler_table, .chan_info = sun4i_field_info, };
@@ -342,6 +346,7 @@ static const struct sun4i_pwm_data sun4i_pwm_data_a13 = { .has_prescaler_bypass = true, .has_rdy = true, .npwm = 1, + .prescaler_table = sun4i_prescaler_table, .chan_info = sun4i_field_info, };
@@ -349,6 +354,7 @@ static const struct sun4i_pwm_data sun4i_pwm_data_a20 = { .has_prescaler_bypass = true, .has_rdy = true, .npwm = 2, + .prescaler_table = sun4i_prescaler_table, .chan_info = sun4i_field_info, };
@@ -356,6 +362,7 @@ static const struct sun4i_pwm_data sun4i_pwm_data_h3 = { .has_prescaler_bypass = true, .has_rdy = true, .npwm = 1, + .prescaler_table = sun4i_prescaler_table, .chan_info = sun4i_field_info, };
--
2.4.11
A message that is not in the archive (sent off-list or not yet received): 1487189167-32486-3-git-send-email-lis8215-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Maxime Ripard
Acked-byRe: [PATCH v3 2/4] pwm: sunxi: Selectable prescaler table for support sun6i.
Quoted 5 lines · On Wed, Feb 15, 2017 at 11:06:05PM +0300…
From: Siarhei Volkau <[email protected]>
This patch not introduce new features, just prepare code for adding sun6i PWM driver in next commit.
Quoted 7 lines
A31 SoC have a different set of prescalers than sun4i compatible ASoCs, but its position and count in the control register are the same.
This patch make the table of prescalers customizable.
Signed-off-by Siarhei Volkau <[email protected]>
Thanks,
Maxime
Signature · 3 lines
Maxime Ripard, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
PATCH v3 3/4 pwm: sunxi: Add support the Allwinner A31 PWM.
In reply to a message not in the archiveFrom: Siarhei Volkau <[email protected]>
This patch introduce the sun6i PWM driver itself:
- sun6i channels configuration,
- sun6i prescaler table,
- DT bindings for A31 SoC,
- documentation update,
- module description and author update.
--- .../devicetree/bindings/pwm/pwm-sun4i.txt | 3 +- drivers/pwm/pwm-sun4i.c | 89 +++++++++++++++++++++- 2 files changed, 88 insertions(+), 4 deletions(-)
Documentation/devicetree/bindings/pwm/pwm-sun4i.txt +2 -1
@@ -1,10 +1,11 @@ -Allwinner sun4i and sun7i SoC PWM controller +Allwinner sunxi SoC PWM controller Required properties: - compatible: should be one of: - "allwinner,sun4i-a10-pwm" - "allwinner,sun5i-a10s-pwm" - "allwinner,sun5i-a13-pwm" + - "allwinner,sun6i-a31-pwm" - "allwinner,sun7i-a20-pwm" - "allwinner,sun8i-h3-pwm" - reg: physical base address and length of the controller's registers
drivers/pwm/pwm-sun4i.c +86 -3
141 lines not on this page · raw message
--
2.4.11
PATCH v3 4/4 ARM: dts: sun6i: Add the PWM block to the A31/A31s.
In reply to a message not in the archiveFrom: Siarhei Volkau <[email protected]>
--- arch/arm/boot/dts/sun6i-a31.dtsi | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/arm/boot/dts/sun6i-a31.dtsi +8 -0
@@ -627,6 +627,14 @@ status = "disabled"; }; + pwm: pwm@01c21400 { + compatible = "allwinner,sun6i-a31-pwm"; + reg = <0x01c21400 0x400>; + clocks = <&osc24M>; + #pwm-cells = <3>; + status = "disabled"; + }; + lradc: lradc@01c22800 { compatible = "allwinner,sun4i-a10-lradc-keys"; reg = <0x01c22800 0x100>;
Signature · 1 line
2.4.11