developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 1 | From c6dc9128df3673041cade417331ad2579e669520 Mon Sep 17 00:00:00 2001 |
| 2 | From: Sam Shih <sam.shih@mediatek.com> |
| 3 | Date: Fri, 2 Jun 2023 13:06:07 +0800 |
| 4 | Subject: [PATCH] [slow-speed-io][999-2131-pwm-add-mt7981-support.patch] |
| 5 | |
| 6 | --- |
| 7 | drivers/pwm/pwm-mediatek.c | 51 +++++++++++++++++++++++++++++++++++--- |
| 8 | 1 file changed, 48 insertions(+), 3 deletions(-) |
| 9 | |
developer | 705722e | 2021-12-14 17:47:28 +0800 | [diff] [blame] | 10 | diff --git a/drivers/pwm/pwm-mediatek.c b/drivers/pwm/pwm-mediatek.c |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 11 | index 35a0db2ff..f4393bd46 100644 |
developer | 705722e | 2021-12-14 17:47:28 +0800 | [diff] [blame] | 12 | --- a/drivers/pwm/pwm-mediatek.c |
| 13 | +++ b/drivers/pwm/pwm-mediatek.c |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 14 | @@ -32,10 +32,13 @@ |
developer | 32e626c | 2021-12-14 11:01:32 +0800 | [diff] [blame] | 15 | #define PWM45THRES_FIXUP 0x34 |
| 16 | |
| 17 | #define PWM_CLK_DIV_MAX 7 |
| 18 | +#define REG_V1 1 |
| 19 | +#define REG_V2 2 |
| 20 | |
| 21 | struct pwm_mediatek_of_data { |
| 22 | unsigned int num_pwms; |
| 23 | bool pwm45_fixup; |
| 24 | + int reg_ver; |
| 25 | }; |
| 26 | |
| 27 | /** |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 28 | @@ -56,10 +59,14 @@ struct pwm_mediatek_chip { |
developer | 32e626c | 2021-12-14 11:01:32 +0800 | [diff] [blame] | 29 | const struct pwm_mediatek_of_data *soc; |
| 30 | }; |
| 31 | |
| 32 | -static const unsigned int pwm_mediatek_reg_offset[] = { |
| 33 | +static const unsigned int mtk_pwm_reg_offset_v1[] = { |
| 34 | 0x0010, 0x0050, 0x0090, 0x00d0, 0x0110, 0x0150, 0x0190, 0x0220 |
| 35 | }; |
| 36 | |
| 37 | +static const unsigned int mtk_pwm_reg_offset_v2[] = { |
| 38 | + 0x0080, 0x00c0, 0x0100, 0x0140, 0x0180, 0x1c0, 0x200, 0x0240 |
| 39 | +}; |
| 40 | + |
| 41 | static inline struct pwm_mediatek_chip * |
| 42 | to_pwm_mediatek_chip(struct pwm_chip *chip) |
| 43 | { |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 44 | @@ -107,14 +114,38 @@ static void pwm_mediatek_clk_disable(struct pwm_chip *chip, |
developer | 32e626c | 2021-12-14 11:01:32 +0800 | [diff] [blame] | 45 | static inline u32 pwm_mediatek_readl(struct pwm_mediatek_chip *chip, |
| 46 | unsigned int num, unsigned int offset) |
| 47 | { |
| 48 | - return readl(chip->regs + pwm_mediatek_reg_offset[num] + offset); |
| 49 | + u32 pwm_offset; |
| 50 | + |
| 51 | + switch (chip->soc->reg_ver) { |
| 52 | + case REG_V2: |
| 53 | + pwm_offset = mtk_pwm_reg_offset_v2[num]; |
| 54 | + break; |
| 55 | + |
| 56 | + case REG_V1: |
| 57 | + default: |
| 58 | + pwm_offset = mtk_pwm_reg_offset_v1[num]; |
| 59 | + } |
| 60 | + |
| 61 | + return readl(chip->regs + pwm_offset + offset); |
| 62 | } |
| 63 | |
| 64 | static inline void pwm_mediatek_writel(struct pwm_mediatek_chip *chip, |
| 65 | unsigned int num, unsigned int offset, |
| 66 | u32 value) |
| 67 | { |
| 68 | - writel(value, chip->regs + pwm_mediatek_reg_offset[num] + offset); |
| 69 | + u32 pwm_offset; |
| 70 | + |
| 71 | + switch (chip->soc->reg_ver) { |
| 72 | + case REG_V2: |
| 73 | + pwm_offset = mtk_pwm_reg_offset_v2[num]; |
| 74 | + break; |
| 75 | + |
| 76 | + case REG_V1: |
| 77 | + default: |
| 78 | + pwm_offset = mtk_pwm_reg_offset_v1[num]; |
| 79 | + } |
| 80 | + |
| 81 | + writel(value, chip->regs + pwm_offset + offset); |
| 82 | } |
| 83 | |
| 84 | static int pwm_mediatek_config(struct pwm_chip *chip, struct pwm_device *pwm, |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 85 | @@ -280,36 +311,49 @@ static int pwm_mediatek_remove(struct platform_device *pdev) |
developer | 32e626c | 2021-12-14 11:01:32 +0800 | [diff] [blame] | 86 | static const struct pwm_mediatek_of_data mt2712_pwm_data = { |
| 87 | .num_pwms = 8, |
| 88 | .pwm45_fixup = false, |
| 89 | + .reg_ver = REG_V1, |
| 90 | }; |
| 91 | |
| 92 | static const struct pwm_mediatek_of_data mt7622_pwm_data = { |
| 93 | .num_pwms = 6, |
| 94 | .pwm45_fixup = false, |
| 95 | + .reg_ver = REG_V1, |
| 96 | }; |
| 97 | |
| 98 | static const struct pwm_mediatek_of_data mt7623_pwm_data = { |
| 99 | .num_pwms = 5, |
| 100 | .pwm45_fixup = true, |
| 101 | + .reg_ver = REG_V1, |
| 102 | }; |
| 103 | |
| 104 | static const struct pwm_mediatek_of_data mt7628_pwm_data = { |
| 105 | .num_pwms = 4, |
| 106 | .pwm45_fixup = true, |
| 107 | + .reg_ver = REG_V1, |
| 108 | }; |
| 109 | |
| 110 | static const struct pwm_mediatek_of_data mt7629_pwm_data = { |
| 111 | .num_pwms = 1, |
| 112 | .pwm45_fixup = false, |
| 113 | + .reg_ver = REG_V1, |
| 114 | +}; |
| 115 | + |
| 116 | +static const struct pwm_mediatek_of_data mt7981_pwm_data = { |
| 117 | + .num_pwms = 3, |
| 118 | + .pwm45_fixup = false, |
| 119 | + .reg_ver = REG_V2, |
| 120 | }; |
| 121 | |
| 122 | static const struct pwm_mediatek_of_data mt7986_pwm_data = { |
| 123 | .num_pwms = 2, |
| 124 | .pwm45_fixup = false, |
developer | 0a5b02c | 2022-05-24 18:33:11 +0800 | [diff] [blame] | 125 | + .reg_ver = REG_V1, |
developer | 32e626c | 2021-12-14 11:01:32 +0800 | [diff] [blame] | 126 | }; |
| 127 | |
| 128 | static const struct pwm_mediatek_of_data mt8516_pwm_data = { |
| 129 | .num_pwms = 5, |
| 130 | .pwm45_fixup = false, |
| 131 | + .reg_ver = REG_V1, |
| 132 | }; |
| 133 | |
| 134 | static const struct of_device_id pwm_mediatek_of_match[] = { |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 135 | @@ -318,6 +362,7 @@ static const struct of_device_id pwm_mediatek_of_match[] = { |
developer | 32e626c | 2021-12-14 11:01:32 +0800 | [diff] [blame] | 136 | { .compatible = "mediatek,mt7623-pwm", .data = &mt7623_pwm_data }, |
| 137 | { .compatible = "mediatek,mt7628-pwm", .data = &mt7628_pwm_data }, |
| 138 | { .compatible = "mediatek,mt7629-pwm", .data = &mt7629_pwm_data }, |
| 139 | + { .compatible = "mediatek,mt7981-pwm", .data = &mt7981_pwm_data }, |
| 140 | { .compatible = "mediatek,mt7986-pwm", .data = &mt7986_pwm_data }, |
| 141 | { .compatible = "mediatek,mt8516-pwm", .data = &mt8516_pwm_data }, |
| 142 | { }, |
developer | 5d148cb | 2023-06-02 13:08:11 +0800 | [diff] [blame] | 143 | -- |
| 144 | 2.34.1 |
| 145 | |