John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Mediatek Pulse Width Modulator driver |
| 3 | * |
| 4 | * Copyright (C) 2015 John Crispin <blogic@openwrt.org> |
Zhi Mao | e7c197e | 2017-06-30 14:05:18 +0800 | [diff] [blame] | 5 | * Copyright (C) 2017 Zhi Mao <zhi.mao@mediatek.com> |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 6 | * |
| 7 | * This file is licensed under the terms of the GNU General Public |
| 8 | * License version 2. This program is licensed "as is" without any |
| 9 | * warranty of any kind, whether express or implied. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/err.h> |
| 13 | #include <linux/io.h> |
| 14 | #include <linux/ioport.h> |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/clk.h> |
| 18 | #include <linux/of.h> |
Zhi Mao | 424268c | 2017-10-25 18:11:01 +0800 | [diff] [blame] | 19 | #include <linux/of_device.h> |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 20 | #include <linux/platform_device.h> |
| 21 | #include <linux/pwm.h> |
| 22 | #include <linux/slab.h> |
| 23 | #include <linux/types.h> |
| 24 | |
| 25 | /* PWM registers and bits definitions */ |
| 26 | #define PWMCON 0x00 |
| 27 | #define PWMHDUR 0x04 |
| 28 | #define PWMLDUR 0x08 |
| 29 | #define PWMGDUR 0x0c |
| 30 | #define PWMWAVENUM 0x28 |
| 31 | #define PWMDWIDTH 0x2c |
Sean Wang | 360cc03 | 2018-03-01 16:19:12 +0800 | [diff] [blame] | 32 | #define PWM45DWIDTH_FIXUP 0x30 |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 33 | #define PWMTHRES 0x30 |
Sean Wang | 360cc03 | 2018-03-01 16:19:12 +0800 | [diff] [blame] | 34 | #define PWM45THRES_FIXUP 0x34 |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 35 | |
Zhi Mao | 8bdb65d | 2017-06-30 14:05:20 +0800 | [diff] [blame] | 36 | #define PWM_CLK_DIV_MAX 7 |
| 37 | |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 38 | struct pwm_mediatek_of_data { |
Zhi Mao | 424268c | 2017-10-25 18:11:01 +0800 | [diff] [blame] | 39 | unsigned int num_pwms; |
Sean Wang | 360cc03 | 2018-03-01 16:19:12 +0800 | [diff] [blame] | 40 | bool pwm45_fixup; |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | /** |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 44 | * struct pwm_mediatek_chip - struct representing PWM chip |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 45 | * @chip: linux PWM chip representation |
| 46 | * @regs: base address of PWM chip |
Sam Shih | efecdeb | 2019-09-20 06:49:04 +0800 | [diff] [blame] | 47 | * @clk_top: the top clock generator |
| 48 | * @clk_main: the clock used by PWM core |
| 49 | * @clk_pwms: the clock used by each PWM channel |
| 50 | * @clk_freq: the fix clock frequency of legacy MIPS SoC |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 51 | */ |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 52 | struct pwm_mediatek_chip { |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 53 | struct pwm_chip chip; |
| 54 | void __iomem *regs; |
Sam Shih | efecdeb | 2019-09-20 06:49:04 +0800 | [diff] [blame] | 55 | struct clk *clk_top; |
| 56 | struct clk *clk_main; |
| 57 | struct clk **clk_pwms; |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 58 | const struct pwm_mediatek_of_data *soc; |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 59 | }; |
| 60 | |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 61 | static const unsigned int pwm_mediatek_reg_offset[] = { |
Zhi Mao | 424268c | 2017-10-25 18:11:01 +0800 | [diff] [blame] | 62 | 0x0010, 0x0050, 0x0090, 0x00d0, 0x0110, 0x0150, 0x0190, 0x0220 |
| 63 | }; |
| 64 | |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 65 | static inline struct pwm_mediatek_chip * |
| 66 | to_pwm_mediatek_chip(struct pwm_chip *chip) |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 67 | { |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 68 | return container_of(chip, struct pwm_mediatek_chip, chip); |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 69 | } |
| 70 | |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 71 | static int pwm_mediatek_clk_enable(struct pwm_chip *chip, |
| 72 | struct pwm_device *pwm) |
Zhi Mao | e7c197e | 2017-06-30 14:05:18 +0800 | [diff] [blame] | 73 | { |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 74 | struct pwm_mediatek_chip *pc = to_pwm_mediatek_chip(chip); |
Zhi Mao | e7c197e | 2017-06-30 14:05:18 +0800 | [diff] [blame] | 75 | int ret; |
| 76 | |
Sam Shih | efecdeb | 2019-09-20 06:49:04 +0800 | [diff] [blame] | 77 | ret = clk_prepare_enable(pc->clk_top); |
Zhi Mao | e7c197e | 2017-06-30 14:05:18 +0800 | [diff] [blame] | 78 | if (ret < 0) |
| 79 | return ret; |
| 80 | |
Sam Shih | efecdeb | 2019-09-20 06:49:04 +0800 | [diff] [blame] | 81 | ret = clk_prepare_enable(pc->clk_main); |
Zhi Mao | e7c197e | 2017-06-30 14:05:18 +0800 | [diff] [blame] | 82 | if (ret < 0) |
| 83 | goto disable_clk_top; |
| 84 | |
Sam Shih | efecdeb | 2019-09-20 06:49:04 +0800 | [diff] [blame] | 85 | ret = clk_prepare_enable(pc->clk_pwms[pwm->hwpwm]); |
Zhi Mao | e7c197e | 2017-06-30 14:05:18 +0800 | [diff] [blame] | 86 | if (ret < 0) |
| 87 | goto disable_clk_main; |
| 88 | |
| 89 | return 0; |
| 90 | |
| 91 | disable_clk_main: |
Sam Shih | efecdeb | 2019-09-20 06:49:04 +0800 | [diff] [blame] | 92 | clk_disable_unprepare(pc->clk_main); |
Zhi Mao | e7c197e | 2017-06-30 14:05:18 +0800 | [diff] [blame] | 93 | disable_clk_top: |
Sam Shih | efecdeb | 2019-09-20 06:49:04 +0800 | [diff] [blame] | 94 | clk_disable_unprepare(pc->clk_top); |
Zhi Mao | e7c197e | 2017-06-30 14:05:18 +0800 | [diff] [blame] | 95 | |
| 96 | return ret; |
| 97 | } |
| 98 | |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 99 | static void pwm_mediatek_clk_disable(struct pwm_chip *chip, |
| 100 | struct pwm_device *pwm) |
Zhi Mao | e7c197e | 2017-06-30 14:05:18 +0800 | [diff] [blame] | 101 | { |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 102 | struct pwm_mediatek_chip *pc = to_pwm_mediatek_chip(chip); |
Zhi Mao | e7c197e | 2017-06-30 14:05:18 +0800 | [diff] [blame] | 103 | |
Sam Shih | efecdeb | 2019-09-20 06:49:04 +0800 | [diff] [blame] | 104 | clk_disable_unprepare(pc->clk_pwms[pwm->hwpwm]); |
| 105 | clk_disable_unprepare(pc->clk_main); |
| 106 | clk_disable_unprepare(pc->clk_top); |
Zhi Mao | e7c197e | 2017-06-30 14:05:18 +0800 | [diff] [blame] | 107 | } |
| 108 | |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 109 | static inline u32 pwm_mediatek_readl(struct pwm_mediatek_chip *chip, |
| 110 | unsigned int num, unsigned int offset) |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 111 | { |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 112 | return readl(chip->regs + pwm_mediatek_reg_offset[num] + offset); |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 113 | } |
| 114 | |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 115 | static inline void pwm_mediatek_writel(struct pwm_mediatek_chip *chip, |
| 116 | unsigned int num, unsigned int offset, |
| 117 | u32 value) |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 118 | { |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 119 | writel(value, chip->regs + pwm_mediatek_reg_offset[num] + offset); |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 120 | } |
| 121 | |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 122 | static int pwm_mediatek_config(struct pwm_chip *chip, struct pwm_device *pwm, |
| 123 | int duty_ns, int period_ns) |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 124 | { |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 125 | struct pwm_mediatek_chip *pc = to_pwm_mediatek_chip(chip); |
Sean Wang | 04c0a4e | 2018-03-02 16:49:14 +0800 | [diff] [blame] | 126 | u32 clkdiv = 0, cnt_period, cnt_duty, reg_width = PWMDWIDTH, |
Sean Wang | 360cc03 | 2018-03-01 16:19:12 +0800 | [diff] [blame] | 127 | reg_thres = PWMTHRES; |
Sean Wang | 04c0a4e | 2018-03-02 16:49:14 +0800 | [diff] [blame] | 128 | u64 resolution; |
Zhi Mao | e7c197e | 2017-06-30 14:05:18 +0800 | [diff] [blame] | 129 | int ret; |
| 130 | |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 131 | ret = pwm_mediatek_clk_enable(chip, pwm); |
| 132 | |
Zhi Mao | e7c197e | 2017-06-30 14:05:18 +0800 | [diff] [blame] | 133 | if (ret < 0) |
| 134 | return ret; |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 135 | |
Sean Wang | 04c0a4e | 2018-03-02 16:49:14 +0800 | [diff] [blame] | 136 | /* Using resolution in picosecond gets accuracy higher */ |
| 137 | resolution = (u64)NSEC_PER_SEC * 1000; |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 138 | do_div(resolution, clk_get_rate(pc->clk_pwms[pwm->hwpwm])); |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 139 | |
Sean Wang | 04c0a4e | 2018-03-02 16:49:14 +0800 | [diff] [blame] | 140 | cnt_period = DIV_ROUND_CLOSEST_ULL((u64)period_ns * 1000, resolution); |
| 141 | while (cnt_period > 8191) { |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 142 | resolution *= 2; |
| 143 | clkdiv++; |
Sean Wang | 04c0a4e | 2018-03-02 16:49:14 +0800 | [diff] [blame] | 144 | cnt_period = DIV_ROUND_CLOSEST_ULL((u64)period_ns * 1000, |
| 145 | resolution); |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 146 | } |
| 147 | |
Zhi Mao | 8bdb65d | 2017-06-30 14:05:20 +0800 | [diff] [blame] | 148 | if (clkdiv > PWM_CLK_DIV_MAX) { |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 149 | pwm_mediatek_clk_disable(chip, pwm); |
Zhi Mao | 8bdb65d | 2017-06-30 14:05:20 +0800 | [diff] [blame] | 150 | dev_err(chip->dev, "period %d not supported\n", period_ns); |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 151 | return -EINVAL; |
Zhi Mao | 8bdb65d | 2017-06-30 14:05:20 +0800 | [diff] [blame] | 152 | } |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 153 | |
Sean Wang | 360cc03 | 2018-03-01 16:19:12 +0800 | [diff] [blame] | 154 | if (pc->soc->pwm45_fixup && pwm->hwpwm > 2) { |
| 155 | /* |
| 156 | * PWM[4,5] has distinct offset for PWMDWIDTH and PWMTHRES |
| 157 | * from the other PWMs on MT7623. |
| 158 | */ |
| 159 | reg_width = PWM45DWIDTH_FIXUP; |
| 160 | reg_thres = PWM45THRES_FIXUP; |
| 161 | } |
| 162 | |
Sean Wang | 04c0a4e | 2018-03-02 16:49:14 +0800 | [diff] [blame] | 163 | cnt_duty = DIV_ROUND_CLOSEST_ULL((u64)duty_ns * 1000, resolution); |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 164 | pwm_mediatek_writel(pc, pwm->hwpwm, PWMCON, BIT(15) | clkdiv); |
| 165 | pwm_mediatek_writel(pc, pwm->hwpwm, reg_width, cnt_period); |
| 166 | pwm_mediatek_writel(pc, pwm->hwpwm, reg_thres, cnt_duty); |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 167 | |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 168 | pwm_mediatek_clk_disable(chip, pwm); |
Zhi Mao | e7c197e | 2017-06-30 14:05:18 +0800 | [diff] [blame] | 169 | |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 170 | return 0; |
| 171 | } |
| 172 | |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 173 | static int pwm_mediatek_enable(struct pwm_chip *chip, struct pwm_device *pwm) |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 174 | { |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 175 | struct pwm_mediatek_chip *pc = to_pwm_mediatek_chip(chip); |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 176 | u32 value; |
| 177 | int ret; |
| 178 | |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 179 | ret = pwm_mediatek_clk_enable(chip, pwm); |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 180 | if (ret < 0) |
| 181 | return ret; |
| 182 | |
| 183 | value = readl(pc->regs); |
| 184 | value |= BIT(pwm->hwpwm); |
| 185 | writel(value, pc->regs); |
| 186 | |
| 187 | return 0; |
| 188 | } |
| 189 | |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 190 | static void pwm_mediatek_disable(struct pwm_chip *chip, struct pwm_device *pwm) |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 191 | { |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 192 | struct pwm_mediatek_chip *pc = to_pwm_mediatek_chip(chip); |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 193 | u32 value; |
| 194 | |
| 195 | value = readl(pc->regs); |
| 196 | value &= ~BIT(pwm->hwpwm); |
| 197 | writel(value, pc->regs); |
| 198 | |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 199 | pwm_mediatek_clk_disable(chip, pwm); |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 200 | } |
| 201 | |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 202 | static const struct pwm_ops pwm_mediatek_ops = { |
| 203 | .config = pwm_mediatek_config, |
| 204 | .enable = pwm_mediatek_enable, |
| 205 | .disable = pwm_mediatek_disable, |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 206 | .owner = THIS_MODULE, |
| 207 | }; |
| 208 | |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 209 | static int pwm_mediatek_probe(struct platform_device *pdev) |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 210 | { |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 211 | struct pwm_mediatek_chip *pc; |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 212 | struct resource *res; |
| 213 | unsigned int i; |
| 214 | int ret; |
| 215 | |
| 216 | pc = devm_kzalloc(&pdev->dev, sizeof(*pc), GFP_KERNEL); |
| 217 | if (!pc) |
| 218 | return -ENOMEM; |
| 219 | |
Sam Shih | e6c7c25 | 2019-09-20 06:49:02 +0800 | [diff] [blame] | 220 | pc->soc = of_device_get_match_data(&pdev->dev); |
Zhi Mao | 424268c | 2017-10-25 18:11:01 +0800 | [diff] [blame] | 221 | |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 222 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 223 | pc->regs = devm_ioremap_resource(&pdev->dev, res); |
| 224 | if (IS_ERR(pc->regs)) |
| 225 | return PTR_ERR(pc->regs); |
| 226 | |
Sam Shih | efecdeb | 2019-09-20 06:49:04 +0800 | [diff] [blame] | 227 | pc->clk_pwms = devm_kcalloc(&pdev->dev, pc->soc->num_pwms, |
| 228 | sizeof(*pc->clk_pwms), GFP_KERNEL); |
| 229 | if (!pc->clk_pwms) |
| 230 | return -ENOMEM; |
| 231 | |
| 232 | pc->clk_top = devm_clk_get(&pdev->dev, "top"); |
| 233 | if (IS_ERR(pc->clk_top)) { |
| 234 | dev_err(&pdev->dev, "clock: top fail: %ld\n", |
| 235 | PTR_ERR(pc->clk_top)); |
| 236 | return PTR_ERR(pc->clk_top); |
| 237 | } |
| 238 | |
| 239 | pc->clk_main = devm_clk_get(&pdev->dev, "main"); |
| 240 | if (IS_ERR(pc->clk_main)) { |
| 241 | dev_err(&pdev->dev, "clock: main fail: %ld\n", |
| 242 | PTR_ERR(pc->clk_main)); |
| 243 | return PTR_ERR(pc->clk_main); |
| 244 | } |
| 245 | |
| 246 | for (i = 0; i < pc->soc->num_pwms; i++) { |
| 247 | char name[8]; |
| 248 | |
| 249 | snprintf(name, sizeof(name), "pwm%d", i + 1); |
| 250 | |
| 251 | pc->clk_pwms[i] = devm_clk_get(&pdev->dev, name); |
| 252 | if (IS_ERR(pc->clk_pwms[i])) { |
Zhi Mao | 424268c | 2017-10-25 18:11:01 +0800 | [diff] [blame] | 253 | dev_err(&pdev->dev, "clock: %s fail: %ld\n", |
Sam Shih | efecdeb | 2019-09-20 06:49:04 +0800 | [diff] [blame] | 254 | name, PTR_ERR(pc->clk_pwms[i])); |
| 255 | return PTR_ERR(pc->clk_pwms[i]); |
Zhi Mao | 424268c | 2017-10-25 18:11:01 +0800 | [diff] [blame] | 256 | } |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 257 | } |
| 258 | |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 259 | platform_set_drvdata(pdev, pc); |
| 260 | |
| 261 | pc->chip.dev = &pdev->dev; |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 262 | pc->chip.ops = &pwm_mediatek_ops; |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 263 | pc->chip.base = -1; |
Sam Shih | e6c7c25 | 2019-09-20 06:49:02 +0800 | [diff] [blame] | 264 | pc->chip.npwm = pc->soc->num_pwms; |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 265 | |
| 266 | ret = pwmchip_add(&pc->chip); |
| 267 | if (ret < 0) { |
| 268 | dev_err(&pdev->dev, "pwmchip_add() failed: %d\n", ret); |
Zhi Mao | e7c197e | 2017-06-30 14:05:18 +0800 | [diff] [blame] | 269 | return ret; |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | return 0; |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 273 | } |
| 274 | |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 275 | static int pwm_mediatek_remove(struct platform_device *pdev) |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 276 | { |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 277 | struct pwm_mediatek_chip *pc = platform_get_drvdata(pdev); |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 278 | |
| 279 | return pwmchip_remove(&pc->chip); |
| 280 | } |
| 281 | |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 282 | static const struct pwm_mediatek_of_data mt2712_pwm_data = { |
Zhi Mao | 424268c | 2017-10-25 18:11:01 +0800 | [diff] [blame] | 283 | .num_pwms = 8, |
Sean Wang | 360cc03 | 2018-03-01 16:19:12 +0800 | [diff] [blame] | 284 | .pwm45_fixup = false, |
Zhi Mao | 424268c | 2017-10-25 18:11:01 +0800 | [diff] [blame] | 285 | }; |
| 286 | |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 287 | static const struct pwm_mediatek_of_data mt7622_pwm_data = { |
Zhi Mao | 424268c | 2017-10-25 18:11:01 +0800 | [diff] [blame] | 288 | .num_pwms = 6, |
Sean Wang | 360cc03 | 2018-03-01 16:19:12 +0800 | [diff] [blame] | 289 | .pwm45_fixup = false, |
Zhi Mao | 424268c | 2017-10-25 18:11:01 +0800 | [diff] [blame] | 290 | }; |
| 291 | |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 292 | static const struct pwm_mediatek_of_data mt7623_pwm_data = { |
Zhi Mao | 424268c | 2017-10-25 18:11:01 +0800 | [diff] [blame] | 293 | .num_pwms = 5, |
Sean Wang | 360cc03 | 2018-03-01 16:19:12 +0800 | [diff] [blame] | 294 | .pwm45_fixup = true, |
John Crispin | 8cdc43a | 2018-07-25 11:52:09 +0200 | [diff] [blame] | 295 | }; |
| 296 | |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 297 | static const struct pwm_mediatek_of_data mt7628_pwm_data = { |
John Crispin | 8cdc43a | 2018-07-25 11:52:09 +0200 | [diff] [blame] | 298 | .num_pwms = 4, |
| 299 | .pwm45_fixup = true, |
Zhi Mao | 424268c | 2017-10-25 18:11:01 +0800 | [diff] [blame] | 300 | }; |
| 301 | |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 302 | static const struct pwm_mediatek_of_data mt8516_pwm_data = { |
Fabien Parent | 8d19072 | 2019-08-05 14:58:48 +0200 | [diff] [blame] | 303 | .num_pwms = 5, |
| 304 | .pwm45_fixup = false, |
Fabien Parent | 8d19072 | 2019-08-05 14:58:48 +0200 | [diff] [blame] | 305 | }; |
| 306 | |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 307 | static const struct of_device_id pwm_mediatek_of_match[] = { |
Zhi Mao | 424268c | 2017-10-25 18:11:01 +0800 | [diff] [blame] | 308 | { .compatible = "mediatek,mt2712-pwm", .data = &mt2712_pwm_data }, |
| 309 | { .compatible = "mediatek,mt7622-pwm", .data = &mt7622_pwm_data }, |
| 310 | { .compatible = "mediatek,mt7623-pwm", .data = &mt7623_pwm_data }, |
John Crispin | 8cdc43a | 2018-07-25 11:52:09 +0200 | [diff] [blame] | 311 | { .compatible = "mediatek,mt7628-pwm", .data = &mt7628_pwm_data }, |
Fabien Parent | 8d19072 | 2019-08-05 14:58:48 +0200 | [diff] [blame] | 312 | { .compatible = "mediatek,mt8516-pwm", .data = &mt8516_pwm_data }, |
Zhi Mao | 424268c | 2017-10-25 18:11:01 +0800 | [diff] [blame] | 313 | { }, |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 314 | }; |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 315 | MODULE_DEVICE_TABLE(of, pwm_mediatek_of_match); |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 316 | |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 317 | static struct platform_driver pwm_mediatek_driver = { |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 318 | .driver = { |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 319 | .name = "pwm-mediatek", |
| 320 | .of_match_table = pwm_mediatek_of_match, |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 321 | }, |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 322 | .probe = pwm_mediatek_probe, |
| 323 | .remove = pwm_mediatek_remove, |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 324 | }; |
Sam Shih | 2503781 | 2019-09-20 06:49:05 +0800 | [diff] [blame^] | 325 | module_platform_driver(pwm_mediatek_driver); |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 326 | |
| 327 | MODULE_AUTHOR("John Crispin <blogic@openwrt.org>"); |
John Crispin | caf065f | 2017-01-23 19:34:37 +0100 | [diff] [blame] | 328 | MODULE_LICENSE("GPL"); |