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