Add PWM support for MT8183 EVB
Subsystems (3)
cover Add PWM support for MT8183 EVB
This patch series adds PWM to MT8183 EVB. MT8183 has 4 PWM channels.
Fabien Parent (5):
dt-bindings: pwm: pwm-mediatek: Add documentation for MT8183 SoC
pwm: pwm-mediatek: always use bus clock
pwm: pwm-mediatek: Add MT8183 SoC support
arm64: dts: mediatek: mt8183: add pwm node
arm64: dts: mediatek: mt8183-evb: add PWM support
.../devicetree/bindings/pwm/pwm-mediatek.txt | 1 + arch/arm64/boot/dts/mediatek/mt8183-evb.dts | 12 ++++++++++++ arch/arm64/boot/dts/mediatek/mt8183.dtsi | 14 ++++++++++++++ drivers/pwm/pwm-mediatek.c | 19 +++++++++++++++++++ 4 files changed, 46 insertions(+)
Signature · 1 line
2.28.0
PATCH 1/5 dt-bindings: pwm: pwm-mediatek: Add documentation for MT8183 SoC
Add binding documentation for the MT8183 SoC.
--- Documentation/devicetree/bindings/pwm/pwm-mediatek.txt | 1 + 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/pwm/pwm-mediatek.txt +1 -0
@@ -7,6 +7,7 @@ Required properties: - "mediatek,mt7623-pwm": found on mt7623 SoC. - "mediatek,mt7628-pwm": found on mt7628 SoC. - "mediatek,mt7629-pwm": found on mt7629 SoC. + - "mediatek,mt8183-pwm": found on mt8183 SoC. - "mediatek,mt8516-pwm": found on mt8516 SoC. - reg: physical base address and length of the controller's registers. - #pwm-cells: must be 2. See pwm.yaml in this directory for a description of
Signature · 1 line
2.28.0
Re: [PATCH 1/5] dt-bindings: pwm: pwm-mediatek: Add documentation for MT8183 SoC
Quoted 3 lines · Fabien Parent
Add binding documentation for the MT8183 SoC.
Signed-off-by Fabien Parent <[email protected]>
Quoted 17 lines
--- Documentation/devicetree/bindings/pwm/pwm-mediatek.txt | 1 + 1 file changed, 1 insertion(+)Documentation/devicetree/bindings/pwm/pwm-mediatek.txt +1
-0@@ -7,6 +7,7 @@ Required properties: - "mediatek,mt7623-pwm": found on mt7623 SoC. - "mediatek,mt7628-pwm": found on mt7628 SoC. - "mediatek,mt7629-pwm": found on mt7629 SoC. + - "mediatek,mt8183-pwm": found on mt8183 SoC. - "mediatek,mt8516-pwm": found on mt8516 SoC. - reg: physical base address and length of the controller's registers. - #pwm-cells: must be 2. See pwm.yaml in this directory for a description of
Re: [PATCH 1/5] dt-bindings: pwm: pwm-mediatek: Add documentation for MT8183 SoC
In reply to Fabien ParentQuoted 7 lines · Fabien Parent
Add binding documentation for the MT8183 SoC.
Signed-off-by Fabien Parent <[email protected]>--- Documentation/devicetree/bindings/pwm/pwm-mediatek.txt | 1 + 1 file changed, 1 insertion(+)
PATCH 2/5 pwm: pwm-mediatek: always use bus clock
In reply to Fabien ParentThe MediaTek PWM IP can sometimes use the 26MHz source clock to generate the PWM signal, but the driver currently assumes that we always use the PWM bus clock to generate the PWM signal.
This commit modifies the PWM driver in order to force the PWM IP to always use the bus clock as source clock.
I do not have the datasheet of all the MediaTek SoC, so I don't know if the register to choose the source clk is present in all the SoCs or only in subset. As a consequence I made this change optional by using a platform data paremeter to says whether this register is supported or not. On all the SoC I don't have the datasheet (MT2712, MT7622, MT7623, MT7628, MT7629) I kept the behavior to be the same as before this change.
--- drivers/pwm/pwm-mediatek.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/pwm/pwm-mediatek.c +12 -0
@@ -30,12 +30,14 @@#define PWM45DWIDTH_FIXUP 0x30#define PWMTHRES 0x30#define PWM45THRES_FIXUP 0x34 +#define PWM_CK_26M_SEL 0x210#define PWM_CLK_DIV_MAX 7struct pwm_mediatek_of_data {unsigned int num_pwms;bool pwm45_fixup; +bool has_ck_26m_sel; };/**
@@ -132,6 +134,10 @@ static int pwm_mediatek_config(struct pwm_chip *chip, struct pwm_device *pwm,if (ret <0 )return ret; +/* Make sure we use the bus clock and not the 26MHz clock */ +if (pc->soc->has_ck_26m_sel) +writel (0 , pc->regs +PWM_CK_26M_SEL ); +/* Using resolution in picosecond gets accuracy higher */ resolution = (u64 )NSEC_PER_SEC *1000 ;do_div (resolution,clk_get_rate (pc->clk_pwms[pwm->hwpwm]));
@@ -281,31 +287,37 @@ static int pwm_mediatek_remove(struct platform_device *pdev)static const struct pwm_mediatek_of_data mt2712_pwm_data = { .num_pwms =8 , .pwm45_fixup = false, + .has_ck_26m_sel = false, };static const struct pwm_mediatek_of_data mt7622_pwm_data = { .num_pwms =6 , .pwm45_fixup = false, + .has_ck_26m_sel = false, };static const struct pwm_mediatek_of_data mt7623_pwm_data = { .num_pwms =5 , .pwm45_fixup = true, + .has_ck_26m_sel = false, };static const struct pwm_mediatek_of_data mt7628_pwm_data = { .num_pwms =4 , .pwm45_fixup = true, + .has_ck_26m_sel = false, };static const struct pwm_mediatek_of_data mt7629_pwm_data = { .num_pwms =1 , .pwm45_fixup = false, + .has_ck_26m_sel = false, };static const struct pwm_mediatek_of_data mt8516_pwm_data = { .num_pwms =5 , .pwm45_fixup = false, + .has_ck_26m_sel = true, };static const struct of_device_id pwm_mediatek_of_match[] = {
Signature · 1 line
2.28.0
Re: [PATCH 2/5] pwm: pwm-mediatek: always use bus clock
Quoted 15 lines · Fabien Parent
The MediaTek PWM IP can sometimes use the 26MHz source clock to generate the PWM signal, but the driver currently assumes that we always use the PWM bus clock to generate the PWM signal.
This commit modifies the PWM driver in order to force the PWM IP to always use the bus clock as source clock.
I do not have the datasheet of all the MediaTek SoC, so I don't know if the register to choose the source clk is present in all the SoCs or only in subset. As a consequence I made this change optional by using a platform data paremeter to says whether this register is supported or not. On all the SoC I don't have the datasheet (MT2712, MT7622, MT7623, MT7628, MT7629) I kept the behavior to be the same as before this change.
Quoted 1 line
Signed-off-by Fabien Parent <[email protected]>
Quoted 73 lines
--- drivers/pwm/pwm-mediatek.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)drivers/pwm/pwm-mediatek.c +12
-0@@ -30,12 +30,14 @@#define PWM45DWIDTH_FIXUP 0x30#define PWMTHRES 0x30#define PWM45THRES_FIXUP 0x34 +#define PWM_CK_26M_SEL 0x210#define PWM_CLK_DIV_MAX 7struct pwm_mediatek_of_data {unsigned int num_pwms;bool pwm45_fixup; +bool has_ck_26m_sel; };/** @@ -132,6 +134,10 @@ static int pwm_mediatek_config(struct pwm_chip *chip, struct pwm_device *pwm,if (ret <0 )return ret; +/* Make sure we use the bus clock and not the 26MHz clock */ +if (pc->soc->has_ck_26m_sel) +writel (0 , pc->regs +PWM_CK_26M_SEL ); +/* Using resolution in picosecond gets accuracy higher */ resolution = (u64 )NSEC_PER_SEC *1000 ;do_div (resolution,clk_get_rate (pc->clk_pwms[pwm->hwpwm]));@@ -281,31 +287,37 @@ static int pwm_mediatek_remove(struct platform_device *pdev)static const struct pwm_mediatek_of_data mt2712_pwm_data = { .num_pwms =8 , .pwm45_fixup = false, + .has_ck_26m_sel = false, };static const struct pwm_mediatek_of_data mt7622_pwm_data = { .num_pwms =6 , .pwm45_fixup = false, + .has_ck_26m_sel = false, };static const struct pwm_mediatek_of_data mt7623_pwm_data = { .num_pwms =5 , .pwm45_fixup = true, + .has_ck_26m_sel = false, };static const struct pwm_mediatek_of_data mt7628_pwm_data = { .num_pwms =4 , .pwm45_fixup = true, + .has_ck_26m_sel = false, };static const struct pwm_mediatek_of_data mt7629_pwm_data = { .num_pwms =1 , .pwm45_fixup = false, + .has_ck_26m_sel = false, };static const struct pwm_mediatek_of_data mt8516_pwm_data = { .num_pwms =5 , .pwm45_fixup = false, + .has_ck_26m_sel = true, };static const struct of_device_id pwm_mediatek_of_match[] = {
PATCH 3/5 pwm: pwm-mediatek: Add MT8183 SoC support
In reply to Fabien ParentAdd PWM support for the MT8183 SoC
--- drivers/pwm/pwm-mediatek.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/pwm/pwm-mediatek.c +7 -0
@@ -314,6 +314,12 @@ static const struct pwm_mediatek_of_data mt7629_pwm_data = { .has_ck_26m_sel = false, }; +static const struct pwm_mediatek_of_data mt8183_pwm_data = { + .num_pwms =4 , + .pwm45_fixup = false, + .has_ck_26m_sel = true, +}; +static const struct pwm_mediatek_of_data mt8516_pwm_data = { .num_pwms =5 , .pwm45_fixup = false,
@@ -326,6 +332,7 @@ static const struct of_device_id pwm_mediatek_of_match[] = { { .compatible = "mediatek,mt7623-pwm", .data = &mt7623_pwm_data }, { .compatible = "mediatek,mt7628-pwm", .data = &mt7628_pwm_data }, { .compatible = "mediatek,mt7629-pwm", .data = &mt7629_pwm_data }, + { .compatible = "mediatek,mt8183-pwm", .data = &mt8183_pwm_data }, { .compatible = "mediatek,mt8516-pwm", .data = &mt8516_pwm_data }, { }, };
Signature · 1 line
2.28.0
Re: [PATCH 3/5] pwm: pwm-mediatek: Add MT8183 SoC support
Quoted 3 lines · Fabien Parent
Add PWM support for the MT8183 SoC
Signed-off-by Fabien Parent <[email protected]>
Quoted 30 lines
--- drivers/pwm/pwm-mediatek.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/pwm/pwm-mediatek.c +7
-0@@ -314,6 +314,12 @@ static const struct pwm_mediatek_of_data mt7629_pwm_data = { .has_ck_26m_sel = false, }; +static const struct pwm_mediatek_of_data mt8183_pwm_data = { + .num_pwms =4 , + .pwm45_fixup = false, + .has_ck_26m_sel = true, +}; +static const struct pwm_mediatek_of_data mt8516_pwm_data = { .num_pwms =5 , .pwm45_fixup = false,@@ -326,6 +332,7 @@ static const struct of_device_id pwm_mediatek_of_match[] = { { .compatible = "mediatek,mt7623-pwm", .data = &mt7623_pwm_data }, { .compatible = "mediatek,mt7628-pwm", .data = &mt7628_pwm_data }, { .compatible = "mediatek,mt7629-pwm", .data = &mt7629_pwm_data }, + { .compatible = "mediatek,mt8183-pwm", .data = &mt8183_pwm_data }, { .compatible = "mediatek,mt8516-pwm", .data = &mt8516_pwm_data }, { }, };
PATCH 4/5 arm64: dts: mediatek: mt8183: add pwm node
In reply to Fabien ParentMT8183 SoC has 4 PWMs. Add the pwm node in order to support them.
--- arch/arm64/boot/dts/mediatek/mt8183.dtsi | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
arch/arm64/boot/dts/mediatek/mt8183.dtsi +14 -0
@@ -709,6 +709,20 @@ mmc1: mmc@11240000 { status = "disabled"; }; + pwm0: pwm@11006000 { + compatible = "mediatek,mt8183-pwm"; + reg = <0 0x11006000 0 0x1000>; + #pwm-cells = <2>; + clocks = <&infracfg CLK_INFRA_PWM>, + <&infracfg CLK_INFRA_PWM_HCLK>, + <&infracfg CLK_INFRA_PWM1>, + <&infracfg CLK_INFRA_PWM2>, + <&infracfg CLK_INFRA_PWM3>, + <&infracfg CLK_INFRA_PWM4>; + clock-names = "top", "main", "pwm1", "pwm2", "pwm3", + "pwm4"; + }; + efuse: efuse@11f10000 { compatible = "mediatek,mt8183-efuse", "mediatek,efuse";
Signature · 1 line
2.28.0
PATCH 5/5 arm64: dts: mediatek: mt8183-evb: add PWM support
In reply to Fabien ParentEnable the pwm driver and set the pinctrl for PWM A line.
--- arch/arm64/boot/dts/mediatek/mt8183-evb.dts | 12 ++++++++++++ 1 file changed, 12 insertions(+)
arch/arm64/boot/dts/mediatek/mt8183-evb.dts +12 -0
@@ -333,6 +333,12 @@ pins_spi{ bias-disable; }; }; + + pwm0_pin_default: pwm0 { + pwm { + pinmux = <PINMUX_GPIO90__FUNC_PWM_A>; + }; + }; }; &spi0 {
@@ -381,3 +387,9 @@ &spi5 { &uart0 { status = "okay"; }; + +&pwm0 { + status = "okay"; + pinctrl-0 = <&pwm0_pin_default>; + pinctrl-names = "default"; +};
Signature · 1 line
2.28.0
Thierry Reding
AppliedQuoted 6 lines · Fabien Parent
This patch series adds PWM to MT8183 EVB. MT8183 has 4 PWM channels.
Fabien Parent (5):
dt-bindings: pwm: pwm-mediatek: Add documentation for MT8183 SoC
pwm: pwm-mediatek: always use bus clock
pwm: pwm-mediatek: Add MT8183 SoC support
Applied these three patches, thanks.
Thierry