pwm-mediatek.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * MediaTek Pulse Width Modulator driver
  4. *
  5. * Copyright (C) 2015 John Crispin <blogic@openwrt.org>
  6. * Copyright (C) 2017 Zhi Mao <zhi.mao@mediatek.com>
  7. *
  8. */
  9. #include <linux/bitfield.h>
  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>
  17. #include <linux/platform_device.h>
  18. #include <linux/pwm.h>
  19. #include <linux/slab.h>
  20. #include <linux/types.h>
  21. /* PWM registers and bits definitions */
  22. #define PWMCON 0x00
  23. #define PWMCON_CLKDIV GENMASK(2, 0)
  24. #define PWMHDUR 0x04
  25. #define PWMLDUR 0x08
  26. #define PWMGDUR 0x0c
  27. #define PWMWAVENUM 0x28
  28. #define PWMDWIDTH 0x2c
  29. #define PWMDWIDTH_PERIOD GENMASK(12, 0)
  30. #define PWM45DWIDTH_FIXUP 0x30
  31. #define PWMTHRES 0x30
  32. #define PWMTHRES_DUTY GENMASK(12, 0)
  33. #define PWM45THRES_FIXUP 0x34
  34. #define PWM_CK_26M_SEL_V3 0x74
  35. #define PWM_CK_26M_SEL 0x210
  36. struct pwm_mediatek_of_data {
  37. unsigned int num_pwms;
  38. bool pwm45_fixup;
  39. u16 pwm_ck_26m_sel_reg;
  40. unsigned int chanreg_base;
  41. unsigned int chanreg_width;
  42. };
  43. /**
  44. * struct pwm_mediatek_chip - struct representing PWM chip
  45. * @regs: base address of PWM chip
  46. * @clk_top: the top clock generator
  47. * @clk_main: the clock used by PWM core
  48. * @soc: pointer to chip's platform data
  49. * @clk_pwms: the clock and clkrate used by each PWM channel
  50. */
  51. struct pwm_mediatek_chip {
  52. void __iomem *regs;
  53. struct clk *clk_top;
  54. struct clk *clk_main;
  55. const struct pwm_mediatek_of_data *soc;
  56. struct {
  57. struct clk *clk;
  58. unsigned long rate;
  59. } clk_pwms[];
  60. };
  61. static inline struct pwm_mediatek_chip *
  62. to_pwm_mediatek_chip(struct pwm_chip *chip)
  63. {
  64. return pwmchip_get_drvdata(chip);
  65. }
  66. static int pwm_mediatek_clk_enable(struct pwm_mediatek_chip *pc,
  67. unsigned int hwpwm)
  68. {
  69. int ret;
  70. ret = clk_prepare_enable(pc->clk_top);
  71. if (ret < 0)
  72. return ret;
  73. ret = clk_prepare_enable(pc->clk_main);
  74. if (ret < 0)
  75. goto disable_clk_top;
  76. ret = clk_prepare_enable(pc->clk_pwms[hwpwm].clk);
  77. if (ret < 0)
  78. goto disable_clk_main;
  79. if (!pc->clk_pwms[hwpwm].rate) {
  80. pc->clk_pwms[hwpwm].rate = clk_get_rate(pc->clk_pwms[hwpwm].clk);
  81. /*
  82. * With the clk running with not more than 1 GHz the
  83. * calculations in .apply() won't overflow.
  84. */
  85. if (!pc->clk_pwms[hwpwm].rate ||
  86. pc->clk_pwms[hwpwm].rate > 1000000000) {
  87. ret = -EINVAL;
  88. goto disable_clk_hwpwm;
  89. }
  90. }
  91. return 0;
  92. disable_clk_hwpwm:
  93. clk_disable_unprepare(pc->clk_pwms[hwpwm].clk);
  94. disable_clk_main:
  95. clk_disable_unprepare(pc->clk_main);
  96. disable_clk_top:
  97. clk_disable_unprepare(pc->clk_top);
  98. return ret;
  99. }
  100. static void pwm_mediatek_clk_disable(struct pwm_mediatek_chip *pc,
  101. unsigned int hwpwm)
  102. {
  103. clk_disable_unprepare(pc->clk_pwms[hwpwm].clk);
  104. clk_disable_unprepare(pc->clk_main);
  105. clk_disable_unprepare(pc->clk_top);
  106. }
  107. static inline void pwm_mediatek_writel(struct pwm_mediatek_chip *chip,
  108. unsigned int num, unsigned int offset,
  109. u32 value)
  110. {
  111. writel(value, chip->regs + chip->soc->chanreg_base +
  112. num * chip->soc->chanreg_width + offset);
  113. }
  114. static inline u32 pwm_mediatek_readl(struct pwm_mediatek_chip *chip,
  115. unsigned int num, unsigned int offset)
  116. {
  117. return readl(chip->regs + chip->soc->chanreg_base +
  118. num * chip->soc->chanreg_width + offset);
  119. }
  120. struct pwm_mediatek_waveform {
  121. u32 enable;
  122. u32 con;
  123. u32 width;
  124. u32 thres;
  125. };
  126. static int pwm_mediatek_round_waveform_tohw(struct pwm_chip *chip, struct pwm_device *pwm,
  127. const struct pwm_waveform *wf, void *_wfhw)
  128. {
  129. struct pwm_mediatek_waveform *wfhw = _wfhw;
  130. struct pwm_mediatek_chip *pc = to_pwm_mediatek_chip(chip);
  131. u32 clkdiv, enable;
  132. u64 cnt_period, cnt_duty;
  133. unsigned long clk_rate;
  134. int ret = 0;
  135. if (wf->period_length_ns == 0) {
  136. *wfhw = (typeof(*wfhw)){
  137. .enable = 0,
  138. };
  139. return 0;
  140. }
  141. if (!pc->clk_pwms[pwm->hwpwm].rate) {
  142. struct clk *clk = pc->clk_pwms[pwm->hwpwm].clk;
  143. ret = clk_prepare_enable(clk);
  144. if (ret)
  145. return ret;
  146. pc->clk_pwms[pwm->hwpwm].rate = clk_get_rate(clk);
  147. clk_disable_unprepare(clk);
  148. }
  149. clk_rate = pc->clk_pwms[pwm->hwpwm].rate;
  150. if (clk_rate == 0 || clk_rate > 1000000000)
  151. return -EINVAL;
  152. cnt_period = mul_u64_u64_div_u64(wf->period_length_ns, clk_rate, NSEC_PER_SEC);
  153. if (cnt_period == 0) {
  154. cnt_period = 1;
  155. ret = 1;
  156. }
  157. if (cnt_period > FIELD_MAX(PWMDWIDTH_PERIOD) + 1) {
  158. if (cnt_period >= ((FIELD_MAX(PWMDWIDTH_PERIOD) + 1) << FIELD_MAX(PWMCON_CLKDIV))) {
  159. clkdiv = FIELD_MAX(PWMCON_CLKDIV);
  160. cnt_period = FIELD_MAX(PWMDWIDTH_PERIOD) + 1;
  161. } else {
  162. clkdiv = ilog2(cnt_period) - ilog2(FIELD_MAX(PWMDWIDTH_PERIOD));
  163. cnt_period >>= clkdiv;
  164. }
  165. } else {
  166. clkdiv = 0;
  167. }
  168. cnt_duty = mul_u64_u64_div_u64(wf->duty_length_ns, clk_rate, NSEC_PER_SEC) >> clkdiv;
  169. if (cnt_duty > cnt_period)
  170. cnt_duty = cnt_period;
  171. if (cnt_duty) {
  172. cnt_duty -= 1;
  173. enable = BIT(pwm->hwpwm);
  174. } else {
  175. enable = 0;
  176. }
  177. cnt_period -= 1;
  178. dev_dbg(&chip->dev, "pwm#%u: %lld/%lld @%lu -> ENABLE: %x, CON: %x, PERIOD: %llx, DUTY: %llx\n",
  179. pwm->hwpwm, wf->duty_length_ns, wf->period_length_ns, clk_rate,
  180. enable, clkdiv, cnt_period, cnt_duty);
  181. *wfhw = (typeof(*wfhw)){
  182. .enable = enable,
  183. .con = clkdiv,
  184. .width = cnt_period,
  185. .thres = cnt_duty,
  186. };
  187. return ret;
  188. }
  189. static int pwm_mediatek_round_waveform_fromhw(struct pwm_chip *chip, struct pwm_device *pwm,
  190. const void *_wfhw, struct pwm_waveform *wf)
  191. {
  192. const struct pwm_mediatek_waveform *wfhw = _wfhw;
  193. struct pwm_mediatek_chip *pc = to_pwm_mediatek_chip(chip);
  194. u32 clkdiv, cnt_period, cnt_duty;
  195. unsigned long clk_rate;
  196. /*
  197. * When _wfhw was populated, the clock was on, so .rate is
  198. * already set appropriately.
  199. */
  200. clk_rate = pc->clk_pwms[pwm->hwpwm].rate;
  201. if (wfhw->enable) {
  202. clkdiv = FIELD_GET(PWMCON_CLKDIV, wfhw->con);
  203. cnt_period = FIELD_GET(PWMDWIDTH_PERIOD, wfhw->width);
  204. cnt_duty = FIELD_GET(PWMTHRES_DUTY, wfhw->thres);
  205. /*
  206. * cnt_period is a 13 bit value, NSEC_PER_SEC is 30 bits wide
  207. * and clkdiv is less than 8, so the multiplication doesn't
  208. * overflow an u64.
  209. */
  210. *wf = (typeof(*wf)){
  211. .period_length_ns =
  212. DIV_ROUND_UP_ULL((u64)(cnt_period + 1) * NSEC_PER_SEC << clkdiv, clk_rate),
  213. .duty_length_ns =
  214. DIV_ROUND_UP_ULL((u64)(cnt_duty + 1) * NSEC_PER_SEC << clkdiv, clk_rate),
  215. };
  216. } else {
  217. clkdiv = 0;
  218. cnt_period = 0;
  219. cnt_duty = 0;
  220. /*
  221. * .enable = 0 is also used for too small duty_cycle values, so
  222. * report the HW as being enabled to communicate the minimal
  223. * period.
  224. */
  225. *wf = (typeof(*wf)){
  226. .period_length_ns =
  227. DIV_ROUND_UP_ULL(NSEC_PER_SEC, clk_rate),
  228. .duty_length_ns = 0,
  229. };
  230. }
  231. dev_dbg(&chip->dev, "pwm#%u: ENABLE: %x, CLKDIV: %x, PERIOD: %x, DUTY: %x @%lu -> %lld/%lld\n",
  232. pwm->hwpwm, wfhw->enable, clkdiv, cnt_period, cnt_duty, clk_rate,
  233. wf->duty_length_ns, wf->period_length_ns);
  234. return 0;
  235. }
  236. static int pwm_mediatek_read_waveform(struct pwm_chip *chip,
  237. struct pwm_device *pwm, void *_wfhw)
  238. {
  239. struct pwm_mediatek_waveform *wfhw = _wfhw;
  240. struct pwm_mediatek_chip *pc = to_pwm_mediatek_chip(chip);
  241. u32 enable, clkdiv, cnt_period, cnt_duty;
  242. u32 reg_width = PWMDWIDTH, reg_thres = PWMTHRES;
  243. int ret;
  244. ret = pwm_mediatek_clk_enable(pc, pwm->hwpwm);
  245. if (ret < 0)
  246. return ret;
  247. enable = readl(pc->regs) & BIT(pwm->hwpwm);
  248. if (enable) {
  249. if (pc->soc->pwm45_fixup && pwm->hwpwm > 2) {
  250. /*
  251. * PWM[4,5] has distinct offset for PWMDWIDTH and PWMTHRES
  252. * from the other PWMs on MT7623.
  253. */
  254. reg_width = PWM45DWIDTH_FIXUP;
  255. reg_thres = PWM45THRES_FIXUP;
  256. }
  257. clkdiv = FIELD_GET(PWMCON_CLKDIV, pwm_mediatek_readl(pc, pwm->hwpwm, PWMCON));
  258. cnt_period = FIELD_GET(PWMDWIDTH_PERIOD, pwm_mediatek_readl(pc, pwm->hwpwm, reg_width));
  259. cnt_duty = FIELD_GET(PWMTHRES_DUTY, pwm_mediatek_readl(pc, pwm->hwpwm, reg_thres));
  260. *wfhw = (typeof(*wfhw)){
  261. .enable = enable,
  262. .con = BIT(15) | clkdiv,
  263. .width = cnt_period,
  264. .thres = cnt_duty,
  265. };
  266. } else {
  267. *wfhw = (typeof(*wfhw)){
  268. .enable = 0,
  269. };
  270. }
  271. pwm_mediatek_clk_disable(pc, pwm->hwpwm);
  272. return ret;
  273. }
  274. static int pwm_mediatek_write_waveform(struct pwm_chip *chip,
  275. struct pwm_device *pwm, const void *_wfhw)
  276. {
  277. const struct pwm_mediatek_waveform *wfhw = _wfhw;
  278. struct pwm_mediatek_chip *pc = to_pwm_mediatek_chip(chip);
  279. u32 ctrl;
  280. int ret;
  281. ret = pwm_mediatek_clk_enable(pc, pwm->hwpwm);
  282. if (ret < 0)
  283. return ret;
  284. ctrl = readl(pc->regs);
  285. if (wfhw->enable) {
  286. u32 reg_width = PWMDWIDTH, reg_thres = PWMTHRES;
  287. if (pc->soc->pwm45_fixup && pwm->hwpwm > 2) {
  288. /*
  289. * PWM[4,5] has distinct offset for PWMDWIDTH and PWMTHRES
  290. * from the other PWMs on MT7623.
  291. */
  292. reg_width = PWM45DWIDTH_FIXUP;
  293. reg_thres = PWM45THRES_FIXUP;
  294. }
  295. if (!(ctrl & BIT(pwm->hwpwm))) {
  296. /*
  297. * The clks are already on, just increasing the usage
  298. * counter doesn't fail.
  299. */
  300. ret = pwm_mediatek_clk_enable(pc, pwm->hwpwm);
  301. if (unlikely(ret < 0))
  302. goto out;
  303. ctrl |= BIT(pwm->hwpwm);
  304. writel(ctrl, pc->regs);
  305. }
  306. /* Make sure we use the bus clock and not the 26MHz clock */
  307. if (pc->soc->pwm_ck_26m_sel_reg)
  308. writel(0, pc->regs + pc->soc->pwm_ck_26m_sel_reg);
  309. pwm_mediatek_writel(pc, pwm->hwpwm, PWMCON, BIT(15) | wfhw->con);
  310. pwm_mediatek_writel(pc, pwm->hwpwm, reg_width, wfhw->width);
  311. pwm_mediatek_writel(pc, pwm->hwpwm, reg_thres, wfhw->thres);
  312. } else {
  313. if (ctrl & BIT(pwm->hwpwm)) {
  314. ctrl &= ~BIT(pwm->hwpwm);
  315. writel(ctrl, pc->regs);
  316. pwm_mediatek_clk_disable(pc, pwm->hwpwm);
  317. }
  318. }
  319. out:
  320. pwm_mediatek_clk_disable(pc, pwm->hwpwm);
  321. return ret;
  322. }
  323. static const struct pwm_ops pwm_mediatek_ops = {
  324. .sizeof_wfhw = sizeof(struct pwm_mediatek_waveform),
  325. .round_waveform_tohw = pwm_mediatek_round_waveform_tohw,
  326. .round_waveform_fromhw = pwm_mediatek_round_waveform_fromhw,
  327. .read_waveform = pwm_mediatek_read_waveform,
  328. .write_waveform = pwm_mediatek_write_waveform,
  329. };
  330. static int pwm_mediatek_init_used_clks(struct pwm_mediatek_chip *pc)
  331. {
  332. const struct pwm_mediatek_of_data *soc = pc->soc;
  333. unsigned int hwpwm;
  334. u32 enabled, handled = 0;
  335. int ret;
  336. ret = clk_prepare_enable(pc->clk_top);
  337. if (ret)
  338. return ret;
  339. ret = clk_prepare_enable(pc->clk_main);
  340. if (ret)
  341. goto err_enable_main;
  342. enabled = readl(pc->regs) & GENMASK(soc->num_pwms - 1, 0);
  343. while (enabled & ~handled) {
  344. hwpwm = ilog2(enabled & ~handled);
  345. ret = pwm_mediatek_clk_enable(pc, hwpwm);
  346. if (ret) {
  347. while (handled) {
  348. hwpwm = ilog2(handled);
  349. pwm_mediatek_clk_disable(pc, hwpwm);
  350. handled &= ~BIT(hwpwm);
  351. }
  352. break;
  353. }
  354. handled |= BIT(hwpwm);
  355. }
  356. clk_disable_unprepare(pc->clk_main);
  357. err_enable_main:
  358. clk_disable_unprepare(pc->clk_top);
  359. return ret;
  360. }
  361. static int pwm_mediatek_probe(struct platform_device *pdev)
  362. {
  363. struct pwm_chip *chip;
  364. struct pwm_mediatek_chip *pc;
  365. const struct pwm_mediatek_of_data *soc;
  366. unsigned int i;
  367. int ret;
  368. soc = of_device_get_match_data(&pdev->dev);
  369. chip = devm_pwmchip_alloc(&pdev->dev, soc->num_pwms,
  370. struct_size(pc, clk_pwms, soc->num_pwms));
  371. if (IS_ERR(chip))
  372. return PTR_ERR(chip);
  373. pc = to_pwm_mediatek_chip(chip);
  374. pc->soc = soc;
  375. pc->regs = devm_platform_ioremap_resource(pdev, 0);
  376. if (IS_ERR(pc->regs))
  377. return PTR_ERR(pc->regs);
  378. pc->clk_top = devm_clk_get(&pdev->dev, "top");
  379. if (IS_ERR(pc->clk_top))
  380. return dev_err_probe(&pdev->dev, PTR_ERR(pc->clk_top),
  381. "Failed to get top clock\n");
  382. pc->clk_main = devm_clk_get(&pdev->dev, "main");
  383. if (IS_ERR(pc->clk_main))
  384. return dev_err_probe(&pdev->dev, PTR_ERR(pc->clk_main),
  385. "Failed to get main clock\n");
  386. for (i = 0; i < soc->num_pwms; i++) {
  387. char name[8];
  388. snprintf(name, sizeof(name), "pwm%d", i + 1);
  389. pc->clk_pwms[i].clk = devm_clk_get(&pdev->dev, name);
  390. if (IS_ERR(pc->clk_pwms[i].clk))
  391. return dev_err_probe(&pdev->dev, PTR_ERR(pc->clk_pwms[i].clk),
  392. "Failed to get %s clock\n", name);
  393. ret = devm_clk_rate_exclusive_get(&pdev->dev, pc->clk_pwms[i].clk);
  394. if (ret)
  395. return dev_err_probe(&pdev->dev, ret,
  396. "Failed to lock clock rate for %s\n", name);
  397. }
  398. ret = pwm_mediatek_init_used_clks(pc);
  399. if (ret)
  400. return dev_err_probe(&pdev->dev, ret, "Failed to initialize used clocks\n");
  401. chip->ops = &pwm_mediatek_ops;
  402. ret = devm_pwmchip_add(&pdev->dev, chip);
  403. if (ret < 0)
  404. return dev_err_probe(&pdev->dev, ret, "pwmchip_add() failed\n");
  405. return 0;
  406. }
  407. static const struct pwm_mediatek_of_data mt2712_pwm_data = {
  408. .num_pwms = 8,
  409. .pwm45_fixup = false,
  410. .chanreg_base = 0x10,
  411. .chanreg_width = 0x40,
  412. };
  413. static const struct pwm_mediatek_of_data mt6795_pwm_data = {
  414. .num_pwms = 7,
  415. .pwm45_fixup = false,
  416. .chanreg_base = 0x10,
  417. .chanreg_width = 0x40,
  418. };
  419. static const struct pwm_mediatek_of_data mt7622_pwm_data = {
  420. .num_pwms = 6,
  421. .pwm45_fixup = false,
  422. .pwm_ck_26m_sel_reg = PWM_CK_26M_SEL,
  423. .chanreg_base = 0x10,
  424. .chanreg_width = 0x40,
  425. };
  426. static const struct pwm_mediatek_of_data mt7623_pwm_data = {
  427. .num_pwms = 5,
  428. .pwm45_fixup = true,
  429. .chanreg_base = 0x10,
  430. .chanreg_width = 0x40,
  431. };
  432. static const struct pwm_mediatek_of_data mt7628_pwm_data = {
  433. .num_pwms = 4,
  434. .pwm45_fixup = true,
  435. .chanreg_base = 0x10,
  436. .chanreg_width = 0x40,
  437. };
  438. static const struct pwm_mediatek_of_data mt7629_pwm_data = {
  439. .num_pwms = 1,
  440. .pwm45_fixup = false,
  441. .chanreg_base = 0x10,
  442. .chanreg_width = 0x40,
  443. };
  444. static const struct pwm_mediatek_of_data mt7981_pwm_data = {
  445. .num_pwms = 3,
  446. .pwm45_fixup = false,
  447. .pwm_ck_26m_sel_reg = PWM_CK_26M_SEL,
  448. .chanreg_base = 0x80,
  449. .chanreg_width = 0x40,
  450. };
  451. static const struct pwm_mediatek_of_data mt7986_pwm_data = {
  452. .num_pwms = 2,
  453. .pwm45_fixup = false,
  454. .pwm_ck_26m_sel_reg = PWM_CK_26M_SEL,
  455. .chanreg_base = 0x10,
  456. .chanreg_width = 0x40,
  457. };
  458. static const struct pwm_mediatek_of_data mt7988_pwm_data = {
  459. .num_pwms = 8,
  460. .pwm45_fixup = false,
  461. .chanreg_base = 0x80,
  462. .chanreg_width = 0x40,
  463. };
  464. static const struct pwm_mediatek_of_data mt8183_pwm_data = {
  465. .num_pwms = 4,
  466. .pwm45_fixup = false,
  467. .pwm_ck_26m_sel_reg = PWM_CK_26M_SEL,
  468. .chanreg_base = 0x10,
  469. .chanreg_width = 0x40,
  470. };
  471. static const struct pwm_mediatek_of_data mt8365_pwm_data = {
  472. .num_pwms = 3,
  473. .pwm45_fixup = false,
  474. .pwm_ck_26m_sel_reg = PWM_CK_26M_SEL,
  475. .chanreg_base = 0x10,
  476. .chanreg_width = 0x40,
  477. };
  478. static const struct pwm_mediatek_of_data mt8516_pwm_data = {
  479. .num_pwms = 5,
  480. .pwm45_fixup = false,
  481. .pwm_ck_26m_sel_reg = PWM_CK_26M_SEL,
  482. .chanreg_base = 0x10,
  483. .chanreg_width = 0x40,
  484. };
  485. static const struct pwm_mediatek_of_data mt6991_pwm_data = {
  486. .num_pwms = 4,
  487. .pwm45_fixup = false,
  488. .pwm_ck_26m_sel_reg = PWM_CK_26M_SEL_V3,
  489. .chanreg_base = 0x100,
  490. .chanreg_width = 0x100,
  491. };
  492. static const struct of_device_id pwm_mediatek_of_match[] = {
  493. { .compatible = "mediatek,mt2712-pwm", .data = &mt2712_pwm_data },
  494. { .compatible = "mediatek,mt6795-pwm", .data = &mt6795_pwm_data },
  495. { .compatible = "mediatek,mt6991-pwm", .data = &mt6991_pwm_data },
  496. { .compatible = "mediatek,mt7622-pwm", .data = &mt7622_pwm_data },
  497. { .compatible = "mediatek,mt7623-pwm", .data = &mt7623_pwm_data },
  498. { .compatible = "mediatek,mt7628-pwm", .data = &mt7628_pwm_data },
  499. { .compatible = "mediatek,mt7629-pwm", .data = &mt7629_pwm_data },
  500. { .compatible = "mediatek,mt7981-pwm", .data = &mt7981_pwm_data },
  501. { .compatible = "mediatek,mt7986-pwm", .data = &mt7986_pwm_data },
  502. { .compatible = "mediatek,mt7988-pwm", .data = &mt7988_pwm_data },
  503. { .compatible = "mediatek,mt8183-pwm", .data = &mt8183_pwm_data },
  504. { .compatible = "mediatek,mt8365-pwm", .data = &mt8365_pwm_data },
  505. { .compatible = "mediatek,mt8516-pwm", .data = &mt8516_pwm_data },
  506. { },
  507. };
  508. MODULE_DEVICE_TABLE(of, pwm_mediatek_of_match);
  509. static struct platform_driver pwm_mediatek_driver = {
  510. .driver = {
  511. .name = "pwm-mediatek",
  512. .of_match_table = pwm_mediatek_of_match,
  513. },
  514. .probe = pwm_mediatek_probe,
  515. };
  516. module_platform_driver(pwm_mediatek_driver);
  517. MODULE_AUTHOR("John Crispin <blogic@openwrt.org>");
  518. MODULE_DESCRIPTION("MediaTek general purpose Pulse Width Modulator driver");
  519. MODULE_LICENSE("GPL v2");