linux-pwm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Support PWM on MediaTek MT7981
@ 2023-04-19 19:24 Daniel Golle
  2023-04-19 19:24 ` [PATCH 1/2] dt-bindings: pwm: mediatek: Add mediatek,mt7981 compatible Daniel Golle
  2023-04-19 19:25 ` [PATCH 2/2] pwm: mediatek: Add support for MT7981 Daniel Golle
  0 siblings, 2 replies; 6+ messages in thread
From: Daniel Golle @ 2023-04-19 19:24 UTC (permalink / raw)
  To: devicetree, linux-pwm, linux-mediatek, linux-arm-kernel,
	linux-kernel, Rob Herring, Krzysztof Kozlowski, Thierry Reding,
	Uwe Kleine-König, Matthias Brugger,
	AngeloGioacchino Del Regno, John Crispin

Add support for PWM on the MediaTek MT7981 to pwm-mediatek.c as well
as new mediatek,mt7981-pwm compatible string to the existing bindings.

Daniel Golle (2):
  dt-bindings: pwm: mediatek: Add mediatek,mt7981 compatible
  pwm: mediatek: Add support for MT7981

 .../bindings/pwm/mediatek,mt2712-pwm.yaml     |  1 +
 drivers/pwm/pwm-mediatek.c                    | 54 ++++++++++++++++---
 2 files changed, 47 insertions(+), 8 deletions(-)


base-commit: 67d5d9f013d6c3829383c08162939cabff14fccc
-- 
2.40.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] dt-bindings: pwm: mediatek: Add mediatek,mt7981 compatible
  2023-04-19 19:24 [PATCH 0/2] Support PWM on MediaTek MT7981 Daniel Golle
@ 2023-04-19 19:24 ` Daniel Golle
  2023-04-20  7:48   ` AngeloGioacchino Del Regno
  2023-04-20 15:50   ` Krzysztof Kozlowski
  2023-04-19 19:25 ` [PATCH 2/2] pwm: mediatek: Add support for MT7981 Daniel Golle
  1 sibling, 2 replies; 6+ messages in thread
From: Daniel Golle @ 2023-04-19 19:24 UTC (permalink / raw)
  To: devicetree, linux-pwm, linux-mediatek, linux-arm-kernel,
	linux-kernel, Rob Herring, Krzysztof Kozlowski, Thierry Reding,
	Uwe Kleine-König, Matthias Brugger,
	AngeloGioacchino Del Regno, John Crispin

Add compatible string for the PWM unit found of the MediaTek MT7981 SoC.
This is in preparation to adding support in the pwm-mediatek.c driver.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
 Documentation/devicetree/bindings/pwm/mediatek,mt2712-pwm.yaml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/pwm/mediatek,mt2712-pwm.yaml b/Documentation/devicetree/bindings/pwm/mediatek,mt2712-pwm.yaml
index 8e176ba7a525f..0fbe8a6469eb2 100644
--- a/Documentation/devicetree/bindings/pwm/mediatek,mt2712-pwm.yaml
+++ b/Documentation/devicetree/bindings/pwm/mediatek,mt2712-pwm.yaml
@@ -22,6 +22,7 @@ properties:
           - mediatek,mt7623-pwm
           - mediatek,mt7628-pwm
           - mediatek,mt7629-pwm
+          - mediatek,mt7981-pwm
           - mediatek,mt7986-pwm
           - mediatek,mt8183-pwm
           - mediatek,mt8365-pwm
-- 
2.40.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] pwm: mediatek: Add support for MT7981
  2023-04-19 19:24 [PATCH 0/2] Support PWM on MediaTek MT7981 Daniel Golle
  2023-04-19 19:24 ` [PATCH 1/2] dt-bindings: pwm: mediatek: Add mediatek,mt7981 compatible Daniel Golle
@ 2023-04-19 19:25 ` Daniel Golle
  2023-04-20  7:47   ` AngeloGioacchino Del Regno
  1 sibling, 1 reply; 6+ messages in thread
From: Daniel Golle @ 2023-04-19 19:25 UTC (permalink / raw)
  To: linux-pwm, linux-mediatek, linux-arm-kernel, linux-kernel,
	Thierry Reding, Uwe Kleine-König, Matthias Brugger,
	AngeloGioacchino Del Regno, John Crispin

The PWM unit on MT7981 uses different register offsets than previous
MediaTek PWM units. Add support for these new offsets and add support
for PWM on MT7981 which has 3 PWM channels, one of them is typically
used for a temperature controlled fan.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
 drivers/pwm/pwm-mediatek.c | 54 ++++++++++++++++++++++++++++++++------
 1 file changed, 46 insertions(+), 8 deletions(-)

diff --git a/drivers/pwm/pwm-mediatek.c b/drivers/pwm/pwm-mediatek.c
index 5b5eeaff35da6..2bfb5bedf570b 100644
--- a/drivers/pwm/pwm-mediatek.c
+++ b/drivers/pwm/pwm-mediatek.c
@@ -34,10 +34,14 @@
 
 #define PWM_CLK_DIV_MAX		7
 
+#define REG_V1			1
+#define REG_V2			2
+
 struct pwm_mediatek_of_data {
 	unsigned int num_pwms;
 	bool pwm45_fixup;
 	bool has_ck_26m_sel;
+	u8 reg_ver;
 };
 
 /**
@@ -59,10 +63,14 @@ struct pwm_mediatek_chip {
 	const struct pwm_mediatek_of_data *soc;
 };
 
-static const unsigned int pwm_mediatek_reg_offset[] = {
+static const unsigned int mtk_pwm_reg_offset_v1[] = {
 	0x0010, 0x0050, 0x0090, 0x00d0, 0x0110, 0x0150, 0x0190, 0x0220
 };
 
+static const unsigned int mtk_pwm_reg_offset_v2[] = {
+	0x0080, 0x00c0, 0x0100, 0x0140, 0x0180, 0x1c0, 0x200, 0x0240
+};
+
 static inline struct pwm_mediatek_chip *
 to_pwm_mediatek_chip(struct pwm_chip *chip)
 {
@@ -111,7 +119,19 @@ static inline void pwm_mediatek_writel(struct pwm_mediatek_chip *chip,
 				       unsigned int num, unsigned int offset,
 				       u32 value)
 {
-	writel(value, chip->regs + pwm_mediatek_reg_offset[num] + offset);
+	u32 pwm_offset;
+
+	switch (chip->soc->reg_ver) {
+	case REG_V2:
+		pwm_offset = mtk_pwm_reg_offset_v2[num];
+		break;
+
+	case REG_V1:
+	default:
+		pwm_offset = mtk_pwm_reg_offset_v1[num];
+	}
+
+	writel(value, chip->regs + pwm_offset + offset);
 }
 
 static int pwm_mediatek_config(struct pwm_chip *chip, struct pwm_device *pwm,
@@ -285,60 +305,77 @@ static const struct pwm_mediatek_of_data mt2712_pwm_data = {
 	.num_pwms = 8,
 	.pwm45_fixup = false,
 	.has_ck_26m_sel = false,
+	.reg_ver = REG_V1,
 };
 
 static const struct pwm_mediatek_of_data mt6795_pwm_data = {
 	.num_pwms = 7,
 	.pwm45_fixup = false,
 	.has_ck_26m_sel = false,
+	.reg_ver = REG_V1,
 };
 
 static const struct pwm_mediatek_of_data mt7622_pwm_data = {
 	.num_pwms = 6,
 	.pwm45_fixup = false,
 	.has_ck_26m_sel = true,
+	.reg_ver = REG_V1,
 };
 
 static const struct pwm_mediatek_of_data mt7623_pwm_data = {
 	.num_pwms = 5,
 	.pwm45_fixup = true,
 	.has_ck_26m_sel = false,
+	.reg_ver = REG_V1,
 };
 
 static const struct pwm_mediatek_of_data mt7628_pwm_data = {
 	.num_pwms = 4,
 	.pwm45_fixup = true,
 	.has_ck_26m_sel = false,
+	.reg_ver = REG_V1,
 };
 
 static const struct pwm_mediatek_of_data mt7629_pwm_data = {
 	.num_pwms = 1,
 	.pwm45_fixup = false,
 	.has_ck_26m_sel = false,
+	.reg_ver = REG_V1,
 };
 
-static const struct pwm_mediatek_of_data mt8183_pwm_data = {
-	.num_pwms = 4,
+static const struct pwm_mediatek_of_data mt7981_pwm_data = {
+	.num_pwms = 3,
 	.pwm45_fixup = false,
 	.has_ck_26m_sel = true,
+	.reg_ver = REG_V2,
 };
 
-static const struct pwm_mediatek_of_data mt8365_pwm_data = {
-	.num_pwms = 3,
+static const struct pwm_mediatek_of_data mt7986_pwm_data = {
+	.num_pwms = 2,
 	.pwm45_fixup = false,
 	.has_ck_26m_sel = true,
+	.reg_ver = REG_V1,
 };
 
-static const struct pwm_mediatek_of_data mt7986_pwm_data = {
-	.num_pwms = 2,
+static const struct pwm_mediatek_of_data mt8183_pwm_data = {
+	.num_pwms = 4,
+	.pwm45_fixup = false,
+	.has_ck_26m_sel = true,
+	.reg_ver = REG_V1,
+};
+
+static const struct pwm_mediatek_of_data mt8365_pwm_data = {
+	.num_pwms = 3,
 	.pwm45_fixup = false,
 	.has_ck_26m_sel = true,
+	.reg_ver = REG_V1,
 };
 
 static const struct pwm_mediatek_of_data mt8516_pwm_data = {
 	.num_pwms = 5,
 	.pwm45_fixup = false,
 	.has_ck_26m_sel = true,
+	.reg_ver = REG_V1,
 };
 
 static const struct of_device_id pwm_mediatek_of_match[] = {
@@ -348,6 +385,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,mt7981-pwm", .data = &mt7981_pwm_data },
 	{ .compatible = "mediatek,mt7986-pwm", .data = &mt7986_pwm_data },
 	{ .compatible = "mediatek,mt8183-pwm", .data = &mt8183_pwm_data },
 	{ .compatible = "mediatek,mt8365-pwm", .data = &mt8365_pwm_data },
-- 
2.40.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] pwm: mediatek: Add support for MT7981
  2023-04-19 19:25 ` [PATCH 2/2] pwm: mediatek: Add support for MT7981 Daniel Golle
@ 2023-04-20  7:47   ` AngeloGioacchino Del Regno
  0 siblings, 0 replies; 6+ messages in thread
From: AngeloGioacchino Del Regno @ 2023-04-20  7:47 UTC (permalink / raw)
  To: Daniel Golle, linux-pwm, linux-mediatek, linux-arm-kernel,
	linux-kernel, Thierry Reding, Uwe Kleine-König,
	Matthias Brugger, John Crispin

Il 19/04/23 21:25, Daniel Golle ha scritto:
> The PWM unit on MT7981 uses different register offsets than previous
> MediaTek PWM units. Add support for these new offsets and add support
> for PWM on MT7981 which has 3 PWM channels, one of them is typically
> used for a temperature controlled fan.
> 
> Signed-off-by: Daniel Golle <daniel@makrotopia.org>
> ---
>   drivers/pwm/pwm-mediatek.c | 54 ++++++++++++++++++++++++++++++++------
>   1 file changed, 46 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/pwm/pwm-mediatek.c b/drivers/pwm/pwm-mediatek.c
> index 5b5eeaff35da6..2bfb5bedf570b 100644
> --- a/drivers/pwm/pwm-mediatek.c
> +++ b/drivers/pwm/pwm-mediatek.c
> @@ -34,10 +34,14 @@
>   
>   #define PWM_CLK_DIV_MAX		7
>   
> +#define REG_V1			1
> +#define REG_V2			2
> +
>   struct pwm_mediatek_of_data {
>   	unsigned int num_pwms;
>   	bool pwm45_fixup;
>   	bool has_ck_26m_sel;
> +	u8 reg_ver;

You're overcomplicating this one... checking for a register version and then
deciding at every pwm_mediatek_writel() call what to use...

It's way simpler than that!
Pass a pointer to the register array in pwm_mediatek_of_data and then...

>   };
>   
>   /**
> @@ -59,10 +63,14 @@ struct pwm_mediatek_chip {
>   	const struct pwm_mediatek_of_data *soc;
>   };
>   
> -static const unsigned int pwm_mediatek_reg_offset[] = {
> +static const unsigned int mtk_pwm_reg_offset_v1[] = {
>   	0x0010, 0x0050, 0x0090, 0x00d0, 0x0110, 0x0150, 0x0190, 0x0220
>   };
>   
> +static const unsigned int mtk_pwm_reg_offset_v2[] = {
> +	0x0080, 0x00c0, 0x0100, 0x0140, 0x0180, 0x1c0, 0x200, 0x0240
> +};
> +
>   static inline struct pwm_mediatek_chip *
>   to_pwm_mediatek_chip(struct pwm_chip *chip)
>   {
> @@ -111,7 +119,19 @@ static inline void pwm_mediatek_writel(struct pwm_mediatek_chip *chip,
>   				       unsigned int num, unsigned int offset,
>   				       u32 value)
>   {
> -	writel(value, chip->regs + pwm_mediatek_reg_offset[num] + offset);

...this simply becomes:

writel(value, chip->regs + chip->reg_offset[num] + offset);

> +	u32 pwm_offset;
> +
> +	switch (chip->soc->reg_ver) {
> +	case REG_V2:
> +		pwm_offset = mtk_pwm_reg_offset_v2[num];
> +		break;
> +
> +	case REG_V1:
> +	default:
> +		pwm_offset = mtk_pwm_reg_offset_v1[num];
> +	}
> +
> +	writel(value, chip->regs + pwm_offset + offset);
>   }
>   
>   static int pwm_mediatek_config(struct pwm_chip *chip, struct pwm_device *pwm,
> @@ -285,60 +305,77 @@ static const struct pwm_mediatek_of_data mt2712_pwm_data = {
>   	.num_pwms = 8,
>   	.pwm45_fixup = false,
>   	.has_ck_26m_sel = false,
> +	.reg_ver = REG_V1,

...so instead of assigning that, you'd be assigning

	.reg_offset = mtk_pwm_reg_offset_v1;

Better, right? :-)

Cheers,
Angelo




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] dt-bindings: pwm: mediatek: Add mediatek,mt7981 compatible
  2023-04-19 19:24 ` [PATCH 1/2] dt-bindings: pwm: mediatek: Add mediatek,mt7981 compatible Daniel Golle
@ 2023-04-20  7:48   ` AngeloGioacchino Del Regno
  2023-04-20 15:50   ` Krzysztof Kozlowski
  1 sibling, 0 replies; 6+ messages in thread
From: AngeloGioacchino Del Regno @ 2023-04-20  7:48 UTC (permalink / raw)
  To: Daniel Golle, devicetree, linux-pwm, linux-mediatek,
	linux-arm-kernel, linux-kernel, Rob Herring, Krzysztof Kozlowski,
	Thierry Reding, Uwe Kleine-König, Matthias Brugger,
	John Crispin

Il 19/04/23 21:24, Daniel Golle ha scritto:
> Add compatible string for the PWM unit found of the MediaTek MT7981 SoC.
> This is in preparation to adding support in the pwm-mediatek.c driver.
> 
> Signed-off-by: Daniel Golle <daniel@makrotopia.org>

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] dt-bindings: pwm: mediatek: Add mediatek,mt7981 compatible
  2023-04-19 19:24 ` [PATCH 1/2] dt-bindings: pwm: mediatek: Add mediatek,mt7981 compatible Daniel Golle
  2023-04-20  7:48   ` AngeloGioacchino Del Regno
@ 2023-04-20 15:50   ` Krzysztof Kozlowski
  1 sibling, 0 replies; 6+ messages in thread
From: Krzysztof Kozlowski @ 2023-04-20 15:50 UTC (permalink / raw)
  To: Daniel Golle, devicetree, linux-pwm, linux-mediatek,
	linux-arm-kernel, linux-kernel, Rob Herring, Krzysztof Kozlowski,
	Thierry Reding, Uwe Kleine-König, Matthias Brugger,
	AngeloGioacchino Del Regno, John Crispin

On 19/04/2023 21:24, Daniel Golle wrote:
> Add compatible string for the PWM unit found of the MediaTek MT7981 SoC.
> This is in preparation to adding support in the pwm-mediatek.c driver.
> 
> Signed-off-by: Daniel Golle <daniel@makrotopia.org>
> ---
>  Documentation/devicetree/bindings/pwm/mediatek,mt2712-pwm.yaml | 1 +
>  1 file changed, 1 insertion(+)


Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

Best regards,
Krzysztof


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-04-20 15:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-19 19:24 [PATCH 0/2] Support PWM on MediaTek MT7981 Daniel Golle
2023-04-19 19:24 ` [PATCH 1/2] dt-bindings: pwm: mediatek: Add mediatek,mt7981 compatible Daniel Golle
2023-04-20  7:48   ` AngeloGioacchino Del Regno
2023-04-20 15:50   ` Krzysztof Kozlowski
2023-04-19 19:25 ` [PATCH 2/2] pwm: mediatek: Add support for MT7981 Daniel Golle
2023-04-20  7:47   ` AngeloGioacchino Del Regno

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).