pwm-rz-mtu3.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Renesas RZ/G2L MTU3a PWM Timer driver
  4. *
  5. * Copyright (C) 2023 Renesas Electronics Corporation
  6. *
  7. * Hardware manual for this IP can be found here
  8. * https://www.renesas.com/eu/en/document/mah/rzg2l-group-rzg2lc-group-users-manual-hardware-0?language=en
  9. *
  10. * Limitations:
  11. * - When PWM is disabled, the output is driven to Hi-Z.
  12. * - While the hardware supports both polarities, the driver (for now)
  13. * only handles normal polarity.
  14. * - HW uses one counter and two match components to configure duty_cycle
  15. * and period.
  16. * - Multi-Function Timer Pulse Unit (a.k.a MTU) has 7 HW channels for PWM
  17. * operations. (The channels are MTU{0..4, 6, 7}.)
  18. * - MTU{1, 2} channels have a single IO, whereas all other HW channels have
  19. * 2 IOs.
  20. * - Each IO is modelled as an independent PWM channel.
  21. * - rz_mtu3_channel_io_map table is used to map the PWM channel to the
  22. * corresponding HW channel as there are difference in number of IOs
  23. * between HW channels.
  24. */
  25. #include <linux/bitfield.h>
  26. #include <linux/clk.h>
  27. #include <linux/limits.h>
  28. #include <linux/mfd/rz-mtu3.h>
  29. #include <linux/module.h>
  30. #include <linux/platform_device.h>
  31. #include <linux/pm_runtime.h>
  32. #include <linux/pwm.h>
  33. #include <linux/time.h>
  34. #define RZ_MTU3_MAX_PWM_CHANNELS 12
  35. #define RZ_MTU3_MAX_HW_CHANNELS 7
  36. /**
  37. * struct rz_mtu3_channel_io_map - MTU3 pwm channel map
  38. *
  39. * @base_pwm_number: First PWM of a channel
  40. * @num_channel_ios: number of IOs on the HW channel.
  41. */
  42. struct rz_mtu3_channel_io_map {
  43. u8 base_pwm_number;
  44. u8 num_channel_ios;
  45. };
  46. /**
  47. * struct rz_mtu3_pwm_channel - MTU3 pwm channel data
  48. *
  49. * @mtu: MTU3 channel data
  50. * @map: MTU3 pwm channel map
  51. */
  52. struct rz_mtu3_pwm_channel {
  53. struct rz_mtu3_channel *mtu;
  54. const struct rz_mtu3_channel_io_map *map;
  55. };
  56. /**
  57. * struct rz_mtu3_pwm_chip - MTU3 pwm private data
  58. *
  59. * @clk: MTU3 module clock
  60. * @lock: Lock to prevent concurrent access for usage count
  61. * @rate: MTU3 clock rate
  62. * @user_count: MTU3 usage count
  63. * @enable_count: MTU3 enable count
  64. * @prescale: MTU3 prescale
  65. * @channel_data: MTU3 pwm channel data
  66. */
  67. struct rz_mtu3_pwm_chip {
  68. struct clk *clk;
  69. struct mutex lock;
  70. unsigned long rate;
  71. u32 user_count[RZ_MTU3_MAX_HW_CHANNELS];
  72. u32 enable_count[RZ_MTU3_MAX_HW_CHANNELS];
  73. u8 prescale[RZ_MTU3_MAX_HW_CHANNELS];
  74. struct rz_mtu3_pwm_channel channel_data[RZ_MTU3_MAX_HW_CHANNELS];
  75. };
  76. /*
  77. * The MTU channels are {0..4, 6, 7} and the number of IO on MTU1
  78. * and MTU2 channel is 1 compared to 2 on others.
  79. */
  80. static const struct rz_mtu3_channel_io_map channel_map[] = {
  81. { 0, 2 }, { 2, 1 }, { 3, 1 }, { 4, 2 }, { 6, 2 }, { 8, 2 }, { 10, 2 }
  82. };
  83. static inline struct rz_mtu3_pwm_chip *to_rz_mtu3_pwm_chip(struct pwm_chip *chip)
  84. {
  85. return pwmchip_get_drvdata(chip);
  86. }
  87. static void rz_mtu3_pwm_read_tgr_registers(struct rz_mtu3_pwm_channel *priv,
  88. u16 reg_pv_offset, u16 *pv_val,
  89. u16 reg_dc_offset, u16 *dc_val)
  90. {
  91. *pv_val = rz_mtu3_16bit_ch_read(priv->mtu, reg_pv_offset);
  92. *dc_val = rz_mtu3_16bit_ch_read(priv->mtu, reg_dc_offset);
  93. }
  94. static void rz_mtu3_pwm_write_tgr_registers(struct rz_mtu3_pwm_channel *priv,
  95. u16 reg_pv_offset, u16 pv_val,
  96. u16 reg_dc_offset, u16 dc_val)
  97. {
  98. rz_mtu3_16bit_ch_write(priv->mtu, reg_pv_offset, pv_val);
  99. rz_mtu3_16bit_ch_write(priv->mtu, reg_dc_offset, dc_val);
  100. }
  101. static u8 rz_mtu3_pwm_calculate_prescale(struct rz_mtu3_pwm_chip *rz_mtu3,
  102. u64 period_cycles)
  103. {
  104. u32 prescaled_period_cycles;
  105. u8 prescale;
  106. /*
  107. * Supported prescale values are 1, 4, 16 and 64.
  108. * TODO: Support prescale values 2, 8, 32, 256 and 1024.
  109. */
  110. prescaled_period_cycles = period_cycles >> 16;
  111. if (prescaled_period_cycles >= 16)
  112. prescale = 3;
  113. else
  114. prescale = (fls(prescaled_period_cycles) + 1) / 2;
  115. return prescale;
  116. }
  117. static struct rz_mtu3_pwm_channel *
  118. rz_mtu3_get_channel(struct rz_mtu3_pwm_chip *rz_mtu3_pwm, u32 hwpwm)
  119. {
  120. struct rz_mtu3_pwm_channel *priv = rz_mtu3_pwm->channel_data;
  121. unsigned int ch;
  122. for (ch = 0; ch < RZ_MTU3_MAX_HW_CHANNELS; ch++, priv++) {
  123. if (priv->map->base_pwm_number + priv->map->num_channel_ios > hwpwm)
  124. break;
  125. }
  126. return priv;
  127. }
  128. static bool rz_mtu3_pwm_is_ch_enabled(struct rz_mtu3_pwm_chip *rz_mtu3_pwm,
  129. u32 hwpwm)
  130. {
  131. struct rz_mtu3_pwm_channel *priv;
  132. bool is_channel_en;
  133. u8 val;
  134. priv = rz_mtu3_get_channel(rz_mtu3_pwm, hwpwm);
  135. is_channel_en = rz_mtu3_is_enabled(priv->mtu);
  136. if (!is_channel_en)
  137. return false;
  138. if (priv->map->base_pwm_number == hwpwm)
  139. val = rz_mtu3_8bit_ch_read(priv->mtu, RZ_MTU3_TIORH);
  140. else
  141. val = rz_mtu3_8bit_ch_read(priv->mtu, RZ_MTU3_TIORL);
  142. return val & RZ_MTU3_TIOR_IOA;
  143. }
  144. static int rz_mtu3_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
  145. {
  146. struct rz_mtu3_pwm_chip *rz_mtu3_pwm = to_rz_mtu3_pwm_chip(chip);
  147. struct rz_mtu3_pwm_channel *priv;
  148. bool is_mtu3_channel_available;
  149. u32 ch;
  150. priv = rz_mtu3_get_channel(rz_mtu3_pwm, pwm->hwpwm);
  151. ch = priv - rz_mtu3_pwm->channel_data;
  152. mutex_lock(&rz_mtu3_pwm->lock);
  153. /*
  154. * Each channel must be requested only once, so if the channel
  155. * serves two PWMs and the other is already requested, skip over
  156. * rz_mtu3_request_channel()
  157. */
  158. if (!rz_mtu3_pwm->user_count[ch]) {
  159. is_mtu3_channel_available = rz_mtu3_request_channel(priv->mtu);
  160. if (!is_mtu3_channel_available) {
  161. mutex_unlock(&rz_mtu3_pwm->lock);
  162. return -EBUSY;
  163. }
  164. }
  165. rz_mtu3_pwm->user_count[ch]++;
  166. mutex_unlock(&rz_mtu3_pwm->lock);
  167. return 0;
  168. }
  169. static void rz_mtu3_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
  170. {
  171. struct rz_mtu3_pwm_chip *rz_mtu3_pwm = to_rz_mtu3_pwm_chip(chip);
  172. struct rz_mtu3_pwm_channel *priv;
  173. u32 ch;
  174. priv = rz_mtu3_get_channel(rz_mtu3_pwm, pwm->hwpwm);
  175. ch = priv - rz_mtu3_pwm->channel_data;
  176. mutex_lock(&rz_mtu3_pwm->lock);
  177. rz_mtu3_pwm->user_count[ch]--;
  178. if (!rz_mtu3_pwm->user_count[ch])
  179. rz_mtu3_release_channel(priv->mtu);
  180. mutex_unlock(&rz_mtu3_pwm->lock);
  181. }
  182. static int rz_mtu3_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
  183. {
  184. struct rz_mtu3_pwm_chip *rz_mtu3_pwm = to_rz_mtu3_pwm_chip(chip);
  185. struct rz_mtu3_pwm_channel *priv;
  186. u32 ch;
  187. u8 val;
  188. int rc;
  189. rc = pm_runtime_resume_and_get(pwmchip_parent(chip));
  190. if (rc)
  191. return rc;
  192. priv = rz_mtu3_get_channel(rz_mtu3_pwm, pwm->hwpwm);
  193. ch = priv - rz_mtu3_pwm->channel_data;
  194. val = RZ_MTU3_TIOR_OC_IOB_TOGGLE | RZ_MTU3_TIOR_OC_IOA_H_COMP_MATCH;
  195. rz_mtu3_8bit_ch_write(priv->mtu, RZ_MTU3_TMDR1, RZ_MTU3_TMDR1_MD_PWMMODE1);
  196. if (priv->map->base_pwm_number == pwm->hwpwm)
  197. rz_mtu3_8bit_ch_write(priv->mtu, RZ_MTU3_TIORH, val);
  198. else
  199. rz_mtu3_8bit_ch_write(priv->mtu, RZ_MTU3_TIORL, val);
  200. mutex_lock(&rz_mtu3_pwm->lock);
  201. if (!rz_mtu3_pwm->enable_count[ch])
  202. rz_mtu3_enable(priv->mtu);
  203. rz_mtu3_pwm->enable_count[ch]++;
  204. mutex_unlock(&rz_mtu3_pwm->lock);
  205. return 0;
  206. }
  207. static void rz_mtu3_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
  208. {
  209. struct rz_mtu3_pwm_chip *rz_mtu3_pwm = to_rz_mtu3_pwm_chip(chip);
  210. struct rz_mtu3_pwm_channel *priv;
  211. u32 ch;
  212. priv = rz_mtu3_get_channel(rz_mtu3_pwm, pwm->hwpwm);
  213. ch = priv - rz_mtu3_pwm->channel_data;
  214. /* Disable output pins of MTU3 channel */
  215. if (priv->map->base_pwm_number == pwm->hwpwm)
  216. rz_mtu3_8bit_ch_write(priv->mtu, RZ_MTU3_TIORH, RZ_MTU3_TIOR_OC_RETAIN);
  217. else
  218. rz_mtu3_8bit_ch_write(priv->mtu, RZ_MTU3_TIORL, RZ_MTU3_TIOR_OC_RETAIN);
  219. mutex_lock(&rz_mtu3_pwm->lock);
  220. rz_mtu3_pwm->enable_count[ch]--;
  221. if (!rz_mtu3_pwm->enable_count[ch])
  222. rz_mtu3_disable(priv->mtu);
  223. mutex_unlock(&rz_mtu3_pwm->lock);
  224. pm_runtime_put_sync(pwmchip_parent(chip));
  225. }
  226. static int rz_mtu3_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
  227. struct pwm_state *state)
  228. {
  229. struct rz_mtu3_pwm_chip *rz_mtu3_pwm = to_rz_mtu3_pwm_chip(chip);
  230. int rc;
  231. rc = pm_runtime_resume_and_get(pwmchip_parent(chip));
  232. if (rc)
  233. return rc;
  234. state->enabled = rz_mtu3_pwm_is_ch_enabled(rz_mtu3_pwm, pwm->hwpwm);
  235. if (state->enabled) {
  236. struct rz_mtu3_pwm_channel *priv;
  237. u8 prescale, val;
  238. u16 dc, pv;
  239. u64 tmp;
  240. priv = rz_mtu3_get_channel(rz_mtu3_pwm, pwm->hwpwm);
  241. if (priv->map->base_pwm_number == pwm->hwpwm)
  242. rz_mtu3_pwm_read_tgr_registers(priv, RZ_MTU3_TGRA, &pv,
  243. RZ_MTU3_TGRB, &dc);
  244. else
  245. rz_mtu3_pwm_read_tgr_registers(priv, RZ_MTU3_TGRC, &pv,
  246. RZ_MTU3_TGRD, &dc);
  247. val = rz_mtu3_8bit_ch_read(priv->mtu, RZ_MTU3_TCR);
  248. prescale = FIELD_GET(RZ_MTU3_TCR_TPCS, val);
  249. /* With prescale <= 7 and pv <= 0xffff this doesn't overflow. */
  250. tmp = NSEC_PER_SEC * (u64)pv << (2 * prescale);
  251. state->period = DIV_ROUND_UP_ULL(tmp, rz_mtu3_pwm->rate);
  252. tmp = NSEC_PER_SEC * (u64)dc << (2 * prescale);
  253. state->duty_cycle = DIV_ROUND_UP_ULL(tmp, rz_mtu3_pwm->rate);
  254. if (state->duty_cycle > state->period)
  255. state->duty_cycle = state->period;
  256. }
  257. state->polarity = PWM_POLARITY_NORMAL;
  258. pm_runtime_put(pwmchip_parent(chip));
  259. return 0;
  260. }
  261. static u16 rz_mtu3_pwm_calculate_pv_or_dc(u64 period_or_duty_cycle, u8 prescale)
  262. {
  263. return min(period_or_duty_cycle >> (2 * prescale), (u64)U16_MAX);
  264. }
  265. static int rz_mtu3_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
  266. const struct pwm_state *state)
  267. {
  268. struct rz_mtu3_pwm_chip *rz_mtu3_pwm = to_rz_mtu3_pwm_chip(chip);
  269. struct rz_mtu3_pwm_channel *priv;
  270. u64 period_cycles;
  271. u64 duty_cycles;
  272. u8 prescale;
  273. u16 pv, dc;
  274. u8 val;
  275. u32 ch;
  276. priv = rz_mtu3_get_channel(rz_mtu3_pwm, pwm->hwpwm);
  277. ch = priv - rz_mtu3_pwm->channel_data;
  278. period_cycles = mul_u64_u32_div(state->period, rz_mtu3_pwm->rate,
  279. NSEC_PER_SEC);
  280. prescale = rz_mtu3_pwm_calculate_prescale(rz_mtu3_pwm, period_cycles);
  281. /*
  282. * Prescalar is shared by multiple channels, so prescale can
  283. * NOT be modified when there are multiple channels in use with
  284. * different settings. Modify prescalar if other PWM is off or handle
  285. * it, if current prescale value is less than the one we want to set.
  286. */
  287. if (rz_mtu3_pwm->enable_count[ch] > 1) {
  288. if (rz_mtu3_pwm->prescale[ch] > prescale)
  289. return -EBUSY;
  290. prescale = rz_mtu3_pwm->prescale[ch];
  291. }
  292. pv = rz_mtu3_pwm_calculate_pv_or_dc(period_cycles, prescale);
  293. duty_cycles = mul_u64_u32_div(state->duty_cycle, rz_mtu3_pwm->rate,
  294. NSEC_PER_SEC);
  295. dc = rz_mtu3_pwm_calculate_pv_or_dc(duty_cycles, prescale);
  296. /*
  297. * If the PWM channel is disabled, make sure to turn on the clock
  298. * before writing the register.
  299. */
  300. if (!pwm->state.enabled) {
  301. int rc;
  302. rc = pm_runtime_resume_and_get(pwmchip_parent(chip));
  303. if (rc)
  304. return rc;
  305. }
  306. val = RZ_MTU3_TCR_CKEG_RISING | prescale;
  307. /* Counter must be stopped while updating TCR register */
  308. if (rz_mtu3_pwm->prescale[ch] != prescale && rz_mtu3_pwm->enable_count[ch])
  309. rz_mtu3_disable(priv->mtu);
  310. if (priv->map->base_pwm_number == pwm->hwpwm) {
  311. rz_mtu3_8bit_ch_write(priv->mtu, RZ_MTU3_TCR,
  312. RZ_MTU3_TCR_CCLR_TGRA | val);
  313. rz_mtu3_pwm_write_tgr_registers(priv, RZ_MTU3_TGRA, pv,
  314. RZ_MTU3_TGRB, dc);
  315. } else {
  316. rz_mtu3_8bit_ch_write(priv->mtu, RZ_MTU3_TCR,
  317. RZ_MTU3_TCR_CCLR_TGRC | val);
  318. rz_mtu3_pwm_write_tgr_registers(priv, RZ_MTU3_TGRC, pv,
  319. RZ_MTU3_TGRD, dc);
  320. }
  321. if (rz_mtu3_pwm->prescale[ch] != prescale) {
  322. /*
  323. * Prescalar is shared by multiple channels, we cache the
  324. * prescalar value from first enabled channel and use the same
  325. * value for both channels.
  326. */
  327. rz_mtu3_pwm->prescale[ch] = prescale;
  328. if (rz_mtu3_pwm->enable_count[ch])
  329. rz_mtu3_enable(priv->mtu);
  330. }
  331. /* If the PWM is not enabled, turn the clock off again to save power. */
  332. if (!pwm->state.enabled)
  333. pm_runtime_put(pwmchip_parent(chip));
  334. return 0;
  335. }
  336. static int rz_mtu3_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
  337. const struct pwm_state *state)
  338. {
  339. struct rz_mtu3_pwm_chip *rz_mtu3_pwm = to_rz_mtu3_pwm_chip(chip);
  340. bool enabled = pwm->state.enabled;
  341. int ret;
  342. if (state->polarity != PWM_POLARITY_NORMAL)
  343. return -EINVAL;
  344. if (!state->enabled) {
  345. if (enabled)
  346. rz_mtu3_pwm_disable(chip, pwm);
  347. return 0;
  348. }
  349. mutex_lock(&rz_mtu3_pwm->lock);
  350. ret = rz_mtu3_pwm_config(chip, pwm, state);
  351. mutex_unlock(&rz_mtu3_pwm->lock);
  352. if (ret)
  353. return ret;
  354. if (!enabled)
  355. ret = rz_mtu3_pwm_enable(chip, pwm);
  356. return ret;
  357. }
  358. static const struct pwm_ops rz_mtu3_pwm_ops = {
  359. .request = rz_mtu3_pwm_request,
  360. .free = rz_mtu3_pwm_free,
  361. .get_state = rz_mtu3_pwm_get_state,
  362. .apply = rz_mtu3_pwm_apply,
  363. };
  364. static int rz_mtu3_pwm_pm_runtime_suspend(struct device *dev)
  365. {
  366. struct pwm_chip *chip = dev_get_drvdata(dev);
  367. struct rz_mtu3_pwm_chip *rz_mtu3_pwm = to_rz_mtu3_pwm_chip(chip);
  368. clk_disable_unprepare(rz_mtu3_pwm->clk);
  369. return 0;
  370. }
  371. static int rz_mtu3_pwm_pm_runtime_resume(struct device *dev)
  372. {
  373. struct pwm_chip *chip = dev_get_drvdata(dev);
  374. struct rz_mtu3_pwm_chip *rz_mtu3_pwm = to_rz_mtu3_pwm_chip(chip);
  375. return clk_prepare_enable(rz_mtu3_pwm->clk);
  376. }
  377. static DEFINE_RUNTIME_DEV_PM_OPS(rz_mtu3_pwm_pm_ops,
  378. rz_mtu3_pwm_pm_runtime_suspend,
  379. rz_mtu3_pwm_pm_runtime_resume, NULL);
  380. static void rz_mtu3_pwm_pm_disable(void *data)
  381. {
  382. struct pwm_chip *chip = data;
  383. struct rz_mtu3_pwm_chip *rz_mtu3_pwm = to_rz_mtu3_pwm_chip(chip);
  384. clk_rate_exclusive_put(rz_mtu3_pwm->clk);
  385. pm_runtime_disable(pwmchip_parent(chip));
  386. pm_runtime_set_suspended(pwmchip_parent(chip));
  387. }
  388. static int rz_mtu3_pwm_probe(struct platform_device *pdev)
  389. {
  390. struct rz_mtu3 *parent_ddata = dev_get_drvdata(pdev->dev.parent);
  391. struct rz_mtu3_pwm_chip *rz_mtu3_pwm;
  392. struct pwm_chip *chip;
  393. struct device *dev = &pdev->dev;
  394. unsigned int i, j = 0;
  395. int ret;
  396. chip = devm_pwmchip_alloc(&pdev->dev, RZ_MTU3_MAX_PWM_CHANNELS,
  397. sizeof(*rz_mtu3_pwm));
  398. if (IS_ERR(chip))
  399. return PTR_ERR(chip);
  400. rz_mtu3_pwm = to_rz_mtu3_pwm_chip(chip);
  401. rz_mtu3_pwm->clk = parent_ddata->clk;
  402. for (i = 0; i < RZ_MTU_NUM_CHANNELS; i++) {
  403. if (i == RZ_MTU3_CHAN_5 || i == RZ_MTU3_CHAN_8)
  404. continue;
  405. rz_mtu3_pwm->channel_data[j].mtu = &parent_ddata->channels[i];
  406. rz_mtu3_pwm->channel_data[j].mtu->dev = dev;
  407. rz_mtu3_pwm->channel_data[j].map = &channel_map[j];
  408. j++;
  409. }
  410. mutex_init(&rz_mtu3_pwm->lock);
  411. platform_set_drvdata(pdev, chip);
  412. ret = clk_prepare_enable(rz_mtu3_pwm->clk);
  413. if (ret)
  414. return dev_err_probe(dev, ret, "Clock enable failed\n");
  415. clk_rate_exclusive_get(rz_mtu3_pwm->clk);
  416. rz_mtu3_pwm->rate = clk_get_rate(rz_mtu3_pwm->clk);
  417. /*
  418. * Refuse clk rates > 1 GHz to prevent overflow later for computing
  419. * period and duty cycle.
  420. */
  421. if (rz_mtu3_pwm->rate > NSEC_PER_SEC) {
  422. ret = -EINVAL;
  423. clk_rate_exclusive_put(rz_mtu3_pwm->clk);
  424. goto disable_clock;
  425. }
  426. pm_runtime_set_active(&pdev->dev);
  427. pm_runtime_enable(&pdev->dev);
  428. ret = devm_add_action_or_reset(&pdev->dev, rz_mtu3_pwm_pm_disable,
  429. chip);
  430. if (ret < 0)
  431. return ret;
  432. chip->ops = &rz_mtu3_pwm_ops;
  433. ret = devm_pwmchip_add(&pdev->dev, chip);
  434. if (ret)
  435. return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n");
  436. pm_runtime_idle(&pdev->dev);
  437. return 0;
  438. disable_clock:
  439. clk_disable_unprepare(rz_mtu3_pwm->clk);
  440. return ret;
  441. }
  442. static struct platform_driver rz_mtu3_pwm_driver = {
  443. .driver = {
  444. .name = "pwm-rz-mtu3",
  445. .pm = pm_ptr(&rz_mtu3_pwm_pm_ops),
  446. },
  447. .probe = rz_mtu3_pwm_probe,
  448. };
  449. module_platform_driver(rz_mtu3_pwm_driver);
  450. MODULE_AUTHOR("Biju Das <biju.das.jz@bp.renesas.com>");
  451. MODULE_ALIAS("platform:pwm-rz-mtu3");
  452. MODULE_DESCRIPTION("Renesas RZ/G2L MTU3a PWM Timer Driver");
  453. MODULE_LICENSE("GPL");