pwm-sti.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * PWM device driver for ST SoCs
  4. *
  5. * Copyright (C) 2013-2016 STMicroelectronics (R&D) Limited
  6. *
  7. * Author: Ajit Pal Singh <ajitpal.singh@st.com>
  8. * Lee Jones <lee.jones@linaro.org>
  9. */
  10. #include <linux/clk.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/math64.h>
  13. #include <linux/mfd/syscon.h>
  14. #include <linux/module.h>
  15. #include <linux/of.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/pwm.h>
  18. #include <linux/regmap.h>
  19. #include <linux/sched.h>
  20. #include <linux/slab.h>
  21. #include <linux/time.h>
  22. #include <linux/wait.h>
  23. #define PWM_OUT_VAL(x) (0x00 + (4 * (x))) /* Device's Duty Cycle register */
  24. #define PWM_CPT_VAL(x) (0x10 + (4 * (x))) /* Capture value */
  25. #define PWM_CPT_EDGE(x) (0x30 + (4 * (x))) /* Edge to capture on */
  26. #define STI_PWM_CTRL 0x50 /* Control/Config register */
  27. #define STI_INT_EN 0x54 /* Interrupt Enable/Disable register */
  28. #define STI_INT_STA 0x58 /* Interrupt Status register */
  29. #define PWM_INT_ACK 0x5c
  30. #define PWM_PRESCALE_LOW_MASK 0x0f
  31. #define PWM_PRESCALE_HIGH_MASK 0xf0
  32. #define PWM_CPT_EDGE_MASK 0x03
  33. #define PWM_INT_ACK_MASK 0x1ff
  34. #define STI_MAX_CPT_DEVS 4
  35. #define CPT_DC_MAX 0xff
  36. /* Regfield IDs */
  37. enum {
  38. /* Bits in PWM_CTRL*/
  39. PWMCLK_PRESCALE_LOW,
  40. PWMCLK_PRESCALE_HIGH,
  41. CPTCLK_PRESCALE,
  42. PWM_OUT_EN,
  43. PWM_CPT_EN,
  44. PWM_CPT_INT_EN,
  45. PWM_CPT_INT_STAT,
  46. /* Keep last */
  47. MAX_REGFIELDS
  48. };
  49. /*
  50. * Each capture input can be programmed to detect rising-edge, falling-edge,
  51. * either edge or neither egde.
  52. */
  53. enum sti_cpt_edge {
  54. CPT_EDGE_DISABLED,
  55. CPT_EDGE_RISING,
  56. CPT_EDGE_FALLING,
  57. CPT_EDGE_BOTH,
  58. };
  59. struct sti_cpt_ddata {
  60. u32 snapshot[3];
  61. unsigned int index;
  62. struct mutex lock;
  63. wait_queue_head_t wait;
  64. };
  65. struct sti_pwm_chip {
  66. struct device *dev;
  67. struct clk *pwm_clk;
  68. struct clk *cpt_clk;
  69. struct regmap *regmap;
  70. unsigned int pwm_num_devs;
  71. unsigned int cpt_num_devs;
  72. unsigned int max_pwm_cnt;
  73. unsigned int max_prescale;
  74. struct sti_cpt_ddata *ddata;
  75. struct regmap_field *prescale_low;
  76. struct regmap_field *prescale_high;
  77. struct regmap_field *pwm_out_en;
  78. struct regmap_field *pwm_cpt_en;
  79. struct regmap_field *pwm_cpt_int_en;
  80. struct regmap_field *pwm_cpt_int_stat;
  81. struct pwm_device *cur;
  82. unsigned long configured;
  83. unsigned int en_count;
  84. struct mutex sti_pwm_lock; /* To sync between enable/disable calls */
  85. void __iomem *mmio;
  86. };
  87. static const struct reg_field sti_pwm_regfields[MAX_REGFIELDS] = {
  88. [PWMCLK_PRESCALE_LOW] = REG_FIELD(STI_PWM_CTRL, 0, 3),
  89. [PWMCLK_PRESCALE_HIGH] = REG_FIELD(STI_PWM_CTRL, 11, 14),
  90. [CPTCLK_PRESCALE] = REG_FIELD(STI_PWM_CTRL, 4, 8),
  91. [PWM_OUT_EN] = REG_FIELD(STI_PWM_CTRL, 9, 9),
  92. [PWM_CPT_EN] = REG_FIELD(STI_PWM_CTRL, 10, 10),
  93. [PWM_CPT_INT_EN] = REG_FIELD(STI_INT_EN, 1, 4),
  94. [PWM_CPT_INT_STAT] = REG_FIELD(STI_INT_STA, 1, 4),
  95. };
  96. static inline struct sti_pwm_chip *to_sti_pwmchip(struct pwm_chip *chip)
  97. {
  98. return pwmchip_get_drvdata(chip);
  99. }
  100. /*
  101. * Calculate the prescaler value corresponding to the period.
  102. */
  103. static int sti_pwm_get_prescale(struct sti_pwm_chip *pc, unsigned long period,
  104. unsigned int *prescale)
  105. {
  106. unsigned long clk_rate;
  107. unsigned long value;
  108. unsigned int ps;
  109. clk_rate = clk_get_rate(pc->pwm_clk);
  110. if (!clk_rate) {
  111. dev_err(pc->dev, "failed to get clock rate\n");
  112. return -EINVAL;
  113. }
  114. /*
  115. * prescale = ((period_ns * clk_rate) / (10^9 * (max_pwm_cnt + 1)) - 1
  116. */
  117. value = NSEC_PER_SEC / clk_rate;
  118. value *= pc->max_pwm_cnt + 1;
  119. if (period % value)
  120. return -EINVAL;
  121. ps = period / value - 1;
  122. if (ps > pc->max_prescale)
  123. return -EINVAL;
  124. *prescale = ps;
  125. return 0;
  126. }
  127. /*
  128. * For STiH4xx PWM IP, the PWM period is fixed to 256 local clock cycles. The
  129. * only way to change the period (apart from changing the PWM input clock) is
  130. * to change the PWM clock prescaler.
  131. *
  132. * The prescaler is of 8 bits, so 256 prescaler values and hence 256 possible
  133. * period values are supported (for a particular clock rate). The requested
  134. * period will be applied only if it matches one of these 256 values.
  135. */
  136. static int sti_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
  137. int duty_ns, int period_ns)
  138. {
  139. struct sti_pwm_chip *pc = to_sti_pwmchip(chip);
  140. unsigned int ncfg, value, prescale = 0;
  141. struct pwm_device *cur = pc->cur;
  142. struct device *dev = pc->dev;
  143. bool period_same = false;
  144. int ret;
  145. ncfg = hweight_long(pc->configured);
  146. if (ncfg)
  147. period_same = (period_ns == pwm_get_period(cur));
  148. /*
  149. * Allow configuration changes if one of the following conditions
  150. * satisfy.
  151. * 1. No devices have been configured.
  152. * 2. Only one device has been configured and the new request is for
  153. * the same device.
  154. * 3. Only one device has been configured and the new request is for
  155. * a new device and period of the new device is same as the current
  156. * configured period.
  157. * 4. More than one devices are configured and period of the new
  158. * requestis the same as the current period.
  159. */
  160. if (!ncfg ||
  161. ((ncfg == 1) && (pwm->hwpwm == cur->hwpwm)) ||
  162. ((ncfg == 1) && (pwm->hwpwm != cur->hwpwm) && period_same) ||
  163. ((ncfg > 1) && period_same)) {
  164. /* Enable clock before writing to PWM registers. */
  165. ret = clk_enable(pc->pwm_clk);
  166. if (ret)
  167. return ret;
  168. ret = clk_enable(pc->cpt_clk);
  169. if (ret)
  170. return ret;
  171. if (!period_same) {
  172. ret = sti_pwm_get_prescale(pc, period_ns, &prescale);
  173. if (ret)
  174. goto clk_dis;
  175. value = prescale & PWM_PRESCALE_LOW_MASK;
  176. ret = regmap_field_write(pc->prescale_low, value);
  177. if (ret)
  178. goto clk_dis;
  179. value = (prescale & PWM_PRESCALE_HIGH_MASK) >> 4;
  180. ret = regmap_field_write(pc->prescale_high, value);
  181. if (ret)
  182. goto clk_dis;
  183. }
  184. /*
  185. * When PWMVal == 0, PWM pulse = 1 local clock cycle.
  186. * When PWMVal == max_pwm_count,
  187. * PWM pulse = (max_pwm_count + 1) local cycles,
  188. * that is continuous pulse: signal never goes low.
  189. */
  190. value = pc->max_pwm_cnt * duty_ns / period_ns;
  191. ret = regmap_write(pc->regmap, PWM_OUT_VAL(pwm->hwpwm), value);
  192. if (ret)
  193. goto clk_dis;
  194. ret = regmap_field_write(pc->pwm_cpt_int_en, 0);
  195. set_bit(pwm->hwpwm, &pc->configured);
  196. pc->cur = pwm;
  197. dev_dbg(dev, "prescale:%u, period:%i, duty:%i, value:%u\n",
  198. prescale, period_ns, duty_ns, value);
  199. } else {
  200. return -EINVAL;
  201. }
  202. clk_dis:
  203. clk_disable(pc->pwm_clk);
  204. clk_disable(pc->cpt_clk);
  205. return ret;
  206. }
  207. static int sti_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
  208. {
  209. struct sti_pwm_chip *pc = to_sti_pwmchip(chip);
  210. struct device *dev = pc->dev;
  211. int ret = 0;
  212. /*
  213. * Since we have a common enable for all PWM devices, do not enable if
  214. * already enabled.
  215. */
  216. mutex_lock(&pc->sti_pwm_lock);
  217. if (!pc->en_count) {
  218. ret = clk_enable(pc->pwm_clk);
  219. if (ret)
  220. goto out;
  221. ret = clk_enable(pc->cpt_clk);
  222. if (ret)
  223. goto out;
  224. ret = regmap_field_write(pc->pwm_out_en, 1);
  225. if (ret) {
  226. dev_err(dev, "failed to enable PWM device %u: %d\n",
  227. pwm->hwpwm, ret);
  228. goto out;
  229. }
  230. }
  231. pc->en_count++;
  232. out:
  233. mutex_unlock(&pc->sti_pwm_lock);
  234. return ret;
  235. }
  236. static void sti_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
  237. {
  238. struct sti_pwm_chip *pc = to_sti_pwmchip(chip);
  239. mutex_lock(&pc->sti_pwm_lock);
  240. if (--pc->en_count) {
  241. mutex_unlock(&pc->sti_pwm_lock);
  242. return;
  243. }
  244. regmap_field_write(pc->pwm_out_en, 0);
  245. clk_disable(pc->pwm_clk);
  246. clk_disable(pc->cpt_clk);
  247. mutex_unlock(&pc->sti_pwm_lock);
  248. }
  249. static void sti_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
  250. {
  251. struct sti_pwm_chip *pc = to_sti_pwmchip(chip);
  252. clear_bit(pwm->hwpwm, &pc->configured);
  253. }
  254. static int sti_pwm_capture(struct pwm_chip *chip, struct pwm_device *pwm,
  255. struct pwm_capture *result, unsigned long timeout)
  256. {
  257. struct sti_pwm_chip *pc = to_sti_pwmchip(chip);
  258. struct sti_cpt_ddata *ddata = &pc->ddata[pwm->hwpwm];
  259. struct device *dev = pc->dev;
  260. unsigned int effective_ticks;
  261. unsigned long long high, low;
  262. int ret;
  263. if (pwm->hwpwm >= pc->cpt_num_devs) {
  264. dev_err(dev, "device %u is not valid\n", pwm->hwpwm);
  265. return -EINVAL;
  266. }
  267. mutex_lock(&ddata->lock);
  268. ddata->index = 0;
  269. /* Prepare capture measurement */
  270. regmap_write(pc->regmap, PWM_CPT_EDGE(pwm->hwpwm), CPT_EDGE_RISING);
  271. regmap_field_write(pc->pwm_cpt_int_en, BIT(pwm->hwpwm));
  272. /* Enable capture */
  273. ret = regmap_field_write(pc->pwm_cpt_en, 1);
  274. if (ret) {
  275. dev_err(dev, "failed to enable PWM capture %u: %d\n",
  276. pwm->hwpwm, ret);
  277. goto out;
  278. }
  279. ret = wait_event_interruptible_timeout(ddata->wait, ddata->index > 1,
  280. msecs_to_jiffies(timeout));
  281. regmap_write(pc->regmap, PWM_CPT_EDGE(pwm->hwpwm), CPT_EDGE_DISABLED);
  282. if (ret == -ERESTARTSYS)
  283. goto out;
  284. switch (ddata->index) {
  285. case 0:
  286. case 1:
  287. /*
  288. * Getting here could mean:
  289. * - input signal is constant of less than 1 Hz
  290. * - there is no input signal at all
  291. *
  292. * In such case the frequency is rounded down to 0
  293. */
  294. result->period = 0;
  295. result->duty_cycle = 0;
  296. break;
  297. case 2:
  298. /* We have everying we need */
  299. high = ddata->snapshot[1] - ddata->snapshot[0];
  300. low = ddata->snapshot[2] - ddata->snapshot[1];
  301. effective_ticks = clk_get_rate(pc->cpt_clk);
  302. result->period = (high + low) * NSEC_PER_SEC;
  303. result->period /= effective_ticks;
  304. result->duty_cycle = high * NSEC_PER_SEC;
  305. result->duty_cycle /= effective_ticks;
  306. break;
  307. default:
  308. dev_err(dev, "internal error\n");
  309. break;
  310. }
  311. out:
  312. /* Disable capture */
  313. regmap_field_write(pc->pwm_cpt_en, 0);
  314. mutex_unlock(&ddata->lock);
  315. return ret;
  316. }
  317. static int sti_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
  318. const struct pwm_state *state)
  319. {
  320. struct sti_pwm_chip *pc = to_sti_pwmchip(chip);
  321. struct device *dev = pc->dev;
  322. int err;
  323. if (pwm->hwpwm >= pc->pwm_num_devs) {
  324. dev_err(dev, "device %u is not valid for pwm mode\n",
  325. pwm->hwpwm);
  326. return -EINVAL;
  327. }
  328. if (state->polarity != PWM_POLARITY_NORMAL)
  329. return -EINVAL;
  330. if (!state->enabled) {
  331. if (pwm->state.enabled)
  332. sti_pwm_disable(chip, pwm);
  333. return 0;
  334. }
  335. err = sti_pwm_config(chip, pwm, state->duty_cycle, state->period);
  336. if (err)
  337. return err;
  338. if (!pwm->state.enabled)
  339. err = sti_pwm_enable(chip, pwm);
  340. return err;
  341. }
  342. static const struct pwm_ops sti_pwm_ops = {
  343. .capture = sti_pwm_capture,
  344. .apply = sti_pwm_apply,
  345. .free = sti_pwm_free,
  346. };
  347. static irqreturn_t sti_pwm_interrupt(int irq, void *data)
  348. {
  349. struct sti_pwm_chip *pc = data;
  350. struct device *dev = pc->dev;
  351. struct sti_cpt_ddata *ddata;
  352. int devicenum;
  353. unsigned int cpt_int_stat;
  354. unsigned int reg;
  355. int ret = IRQ_NONE;
  356. ret = regmap_field_read(pc->pwm_cpt_int_stat, &cpt_int_stat);
  357. if (ret)
  358. return ret;
  359. while (cpt_int_stat) {
  360. devicenum = ffs(cpt_int_stat) - 1;
  361. ddata = &pc->ddata[devicenum];
  362. /*
  363. * Capture input:
  364. * _______ _______
  365. * | | | |
  366. * __| |_________________| |________
  367. * ^0 ^1 ^2
  368. *
  369. * Capture start by the first available rising edge. When a
  370. * capture event occurs, capture value (CPT_VALx) is stored,
  371. * index incremented, capture edge changed.
  372. *
  373. * After the capture, if the index > 1, we have collected the
  374. * necessary data so we signal the thread waiting for it and
  375. * disable the capture by setting capture edge to none
  376. */
  377. regmap_read(pc->regmap,
  378. PWM_CPT_VAL(devicenum),
  379. &ddata->snapshot[ddata->index]);
  380. switch (ddata->index) {
  381. case 0:
  382. case 1:
  383. regmap_read(pc->regmap, PWM_CPT_EDGE(devicenum), &reg);
  384. reg ^= PWM_CPT_EDGE_MASK;
  385. regmap_write(pc->regmap, PWM_CPT_EDGE(devicenum), reg);
  386. ddata->index++;
  387. break;
  388. case 2:
  389. regmap_write(pc->regmap,
  390. PWM_CPT_EDGE(devicenum),
  391. CPT_EDGE_DISABLED);
  392. wake_up(&ddata->wait);
  393. break;
  394. default:
  395. dev_err(dev, "Internal error\n");
  396. }
  397. cpt_int_stat &= ~BIT_MASK(devicenum);
  398. ret = IRQ_HANDLED;
  399. }
  400. /* Just ACK everything */
  401. regmap_write(pc->regmap, PWM_INT_ACK, PWM_INT_ACK_MASK);
  402. return ret;
  403. }
  404. static int sti_pwm_probe_regmap(struct sti_pwm_chip *pc)
  405. {
  406. struct device *dev = pc->dev;
  407. pc->prescale_low = devm_regmap_field_alloc(dev, pc->regmap,
  408. sti_pwm_regfields[PWMCLK_PRESCALE_LOW]);
  409. if (IS_ERR(pc->prescale_low))
  410. return PTR_ERR(pc->prescale_low);
  411. pc->prescale_high = devm_regmap_field_alloc(dev, pc->regmap,
  412. sti_pwm_regfields[PWMCLK_PRESCALE_HIGH]);
  413. if (IS_ERR(pc->prescale_high))
  414. return PTR_ERR(pc->prescale_high);
  415. pc->pwm_out_en = devm_regmap_field_alloc(dev, pc->regmap,
  416. sti_pwm_regfields[PWM_OUT_EN]);
  417. if (IS_ERR(pc->pwm_out_en))
  418. return PTR_ERR(pc->pwm_out_en);
  419. pc->pwm_cpt_en = devm_regmap_field_alloc(dev, pc->regmap,
  420. sti_pwm_regfields[PWM_CPT_EN]);
  421. if (IS_ERR(pc->pwm_cpt_en))
  422. return PTR_ERR(pc->pwm_cpt_en);
  423. pc->pwm_cpt_int_en = devm_regmap_field_alloc(dev, pc->regmap,
  424. sti_pwm_regfields[PWM_CPT_INT_EN]);
  425. if (IS_ERR(pc->pwm_cpt_int_en))
  426. return PTR_ERR(pc->pwm_cpt_int_en);
  427. pc->pwm_cpt_int_stat = devm_regmap_field_alloc(dev, pc->regmap,
  428. sti_pwm_regfields[PWM_CPT_INT_STAT]);
  429. if (PTR_ERR_OR_ZERO(pc->pwm_cpt_int_stat))
  430. return PTR_ERR(pc->pwm_cpt_int_stat);
  431. return 0;
  432. }
  433. static const struct regmap_config sti_pwm_regmap_config = {
  434. .reg_bits = 32,
  435. .val_bits = 32,
  436. .reg_stride = 4,
  437. };
  438. static int sti_pwm_probe(struct platform_device *pdev)
  439. {
  440. struct device *dev = &pdev->dev;
  441. struct device_node *np = dev->of_node;
  442. u32 num_devs;
  443. unsigned int pwm_num_devs = 0;
  444. unsigned int cpt_num_devs = 0;
  445. struct pwm_chip *chip;
  446. struct sti_pwm_chip *pc;
  447. unsigned int i;
  448. int irq, ret;
  449. ret = of_property_read_u32(np, "st,pwm-num-chan", &num_devs);
  450. if (!ret)
  451. pwm_num_devs = num_devs;
  452. ret = of_property_read_u32(np, "st,capture-num-chan", &num_devs);
  453. if (!ret)
  454. cpt_num_devs = num_devs;
  455. if (!pwm_num_devs && !cpt_num_devs)
  456. return dev_err_probe(dev, -EINVAL, "No channels configured\n");
  457. chip = devm_pwmchip_alloc(dev, max(pwm_num_devs, cpt_num_devs), sizeof(*pc));
  458. if (IS_ERR(chip))
  459. return PTR_ERR(chip);
  460. pc = to_sti_pwmchip(chip);
  461. pc->mmio = devm_platform_ioremap_resource(pdev, 0);
  462. if (IS_ERR(pc->mmio))
  463. return PTR_ERR(pc->mmio);
  464. pc->regmap = devm_regmap_init_mmio(dev, pc->mmio,
  465. &sti_pwm_regmap_config);
  466. if (IS_ERR(pc->regmap))
  467. return dev_err_probe(dev, PTR_ERR(pc->regmap),
  468. "Failed to initialize regmap\n");
  469. irq = platform_get_irq(pdev, 0);
  470. if (irq < 0)
  471. return irq;
  472. ret = devm_request_irq(&pdev->dev, irq, sti_pwm_interrupt, 0,
  473. pdev->name, pc);
  474. if (ret < 0)
  475. dev_err_probe(&pdev->dev, ret, "Failed to request IRQ\n");
  476. /*
  477. * Setup PWM data with default values: some values could be replaced
  478. * with specific ones provided from Device Tree.
  479. */
  480. pc->max_prescale = 0xff;
  481. pc->max_pwm_cnt = 255;
  482. pc->pwm_num_devs = pwm_num_devs;
  483. pc->cpt_num_devs = cpt_num_devs;
  484. pc->dev = dev;
  485. pc->en_count = 0;
  486. mutex_init(&pc->sti_pwm_lock);
  487. ret = sti_pwm_probe_regmap(pc);
  488. if (ret)
  489. return dev_err_probe(dev, ret, "Failed to initialize regmap fields\n");
  490. if (pwm_num_devs) {
  491. pc->pwm_clk = devm_clk_get_prepared(dev, "pwm");
  492. if (IS_ERR(pc->pwm_clk))
  493. return dev_err_probe(dev, PTR_ERR(pc->pwm_clk),
  494. "failed to get PWM clock\n");
  495. }
  496. if (cpt_num_devs) {
  497. pc->cpt_clk = devm_clk_get_prepared(dev, "capture");
  498. if (IS_ERR(pc->cpt_clk))
  499. return dev_err_probe(dev, PTR_ERR(pc->cpt_clk),
  500. "failed to get PWM capture clock\n");
  501. pc->ddata = devm_kcalloc(dev, cpt_num_devs,
  502. sizeof(*pc->ddata), GFP_KERNEL);
  503. if (!pc->ddata)
  504. return -ENOMEM;
  505. for (i = 0; i < cpt_num_devs; i++) {
  506. struct sti_cpt_ddata *ddata = &pc->ddata[i];
  507. init_waitqueue_head(&ddata->wait);
  508. mutex_init(&ddata->lock);
  509. }
  510. }
  511. chip->ops = &sti_pwm_ops;
  512. ret = devm_pwmchip_add(dev, chip);
  513. if (ret)
  514. return dev_err_probe(dev, ret, "Failed to register pwm chip\n");
  515. return 0;
  516. }
  517. static const struct of_device_id sti_pwm_of_match[] = {
  518. { .compatible = "st,sti-pwm", },
  519. { /* sentinel */ }
  520. };
  521. MODULE_DEVICE_TABLE(of, sti_pwm_of_match);
  522. static struct platform_driver sti_pwm_driver = {
  523. .driver = {
  524. .name = "sti-pwm",
  525. .of_match_table = sti_pwm_of_match,
  526. },
  527. .probe = sti_pwm_probe,
  528. };
  529. module_platform_driver(sti_pwm_driver);
  530. MODULE_AUTHOR("Ajit Pal Singh <ajitpal.singh@st.com>");
  531. MODULE_DESCRIPTION("STMicroelectronics ST PWM driver");
  532. MODULE_LICENSE("GPL");