ti-ecap-capture.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * ECAP Capture driver
  4. *
  5. * Copyright (C) 2022 Julien Panis <[email protected]>
  6. */
  7. #include <linux/atomic.h>
  8. #include <linux/clk.h>
  9. #include <linux/counter.h>
  10. #include <linux/err.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/io.h>
  13. #include <linux/module.h>
  14. #include <linux/mod_devicetable.h>
  15. #include <linux/mutex.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/pm_runtime.h>
  18. #include <linux/regmap.h>
  19. #define ECAP_DRV_NAME "ecap"
  20. /* ECAP event IDs */
  21. #define ECAP_CEVT1 0
  22. #define ECAP_CEVT2 1
  23. #define ECAP_CEVT3 2
  24. #define ECAP_CEVT4 3
  25. #define ECAP_CNTOVF 4
  26. #define ECAP_CEVT_LAST ECAP_CEVT4
  27. #define ECAP_NB_CEVT (ECAP_CEVT_LAST + 1)
  28. #define ECAP_EVT_LAST ECAP_CNTOVF
  29. #define ECAP_NB_EVT (ECAP_EVT_LAST + 1)
  30. /* Registers */
  31. #define ECAP_TSCNT_REG 0x00
  32. #define ECAP_CAP_REG(i) (((i) << 2) + 0x08)
  33. #define ECAP_ECCTL_REG 0x28
  34. #define ECAP_CAPPOL_BIT(i) BIT((i) << 1)
  35. #define ECAP_EV_MODE_MASK GENMASK(7, 0)
  36. #define ECAP_CAPLDEN_BIT BIT(8)
  37. #define ECAP_CONT_ONESHT_BIT BIT(16)
  38. #define ECAP_STOPVALUE_MASK GENMASK(18, 17)
  39. #define ECAP_TSCNTSTP_BIT BIT(20)
  40. #define ECAP_SYNCO_DIS_MASK GENMASK(23, 22)
  41. #define ECAP_CAP_APWM_BIT BIT(25)
  42. #define ECAP_ECCTL_EN_MASK (ECAP_CAPLDEN_BIT | ECAP_TSCNTSTP_BIT)
  43. #define ECAP_ECCTL_CFG_MASK (ECAP_SYNCO_DIS_MASK | ECAP_STOPVALUE_MASK \
  44. | ECAP_ECCTL_EN_MASK | ECAP_CAP_APWM_BIT \
  45. | ECAP_CONT_ONESHT_BIT)
  46. #define ECAP_ECINT_EN_FLG_REG 0x2c
  47. #define ECAP_EVT_EN_MASK GENMASK(ECAP_NB_EVT, ECAP_NB_CEVT)
  48. #define ECAP_EVT_FLG_BIT(i) BIT((i) + 17)
  49. #define ECAP_ECINT_CLR_FRC_REG 0x30
  50. #define ECAP_INT_CLR_BIT BIT(0)
  51. #define ECAP_EVT_CLR_BIT(i) BIT((i) + 1)
  52. #define ECAP_EVT_CLR_MASK GENMASK(ECAP_NB_EVT, 0)
  53. #define ECAP_PID_REG 0x5c
  54. /* ECAP signals */
  55. #define ECAP_CLOCK_SIG 0
  56. #define ECAP_INPUT_SIG 1
  57. static const struct regmap_config ecap_cnt_regmap_config = {
  58. .reg_bits = 32,
  59. .reg_stride = 4,
  60. .val_bits = 32,
  61. .max_register = ECAP_PID_REG,
  62. };
  63. /**
  64. * struct ecap_cnt_dev - device private data structure
  65. * @enabled: device state
  66. * @lock: synchronization lock to prevent I/O race conditions
  67. * @clk: device clock
  68. * @regmap: device register map
  69. * @nb_ovf: number of overflows since capture start
  70. * @pm_ctx: device context for PM operations
  71. * @pm_ctx.ev_mode: event mode bits
  72. * @pm_ctx.time_cntr: timestamp counter value
  73. */
  74. struct ecap_cnt_dev {
  75. bool enabled;
  76. struct mutex lock;
  77. struct clk *clk;
  78. struct regmap *regmap;
  79. atomic_t nb_ovf;
  80. struct {
  81. u8 ev_mode;
  82. u32 time_cntr;
  83. } pm_ctx;
  84. };
  85. static u8 ecap_cnt_capture_get_evmode(struct counter_device *counter)
  86. {
  87. struct ecap_cnt_dev *ecap_dev = counter_priv(counter);
  88. unsigned int regval;
  89. pm_runtime_get_sync(counter->parent);
  90. regmap_read(ecap_dev->regmap, ECAP_ECCTL_REG, &regval);
  91. pm_runtime_put_sync(counter->parent);
  92. return regval;
  93. }
  94. static void ecap_cnt_capture_set_evmode(struct counter_device *counter, u8 ev_mode)
  95. {
  96. struct ecap_cnt_dev *ecap_dev = counter_priv(counter);
  97. pm_runtime_get_sync(counter->parent);
  98. regmap_update_bits(ecap_dev->regmap, ECAP_ECCTL_REG, ECAP_EV_MODE_MASK, ev_mode);
  99. pm_runtime_put_sync(counter->parent);
  100. }
  101. static void ecap_cnt_capture_enable(struct counter_device *counter)
  102. {
  103. struct ecap_cnt_dev *ecap_dev = counter_priv(counter);
  104. pm_runtime_get_sync(counter->parent);
  105. /* Enable interrupts on events */
  106. regmap_update_bits(ecap_dev->regmap, ECAP_ECINT_EN_FLG_REG,
  107. ECAP_EVT_EN_MASK, ECAP_EVT_EN_MASK);
  108. /* Run counter */
  109. regmap_update_bits(ecap_dev->regmap, ECAP_ECCTL_REG, ECAP_ECCTL_CFG_MASK,
  110. ECAP_SYNCO_DIS_MASK | ECAP_STOPVALUE_MASK | ECAP_ECCTL_EN_MASK);
  111. }
  112. static void ecap_cnt_capture_disable(struct counter_device *counter)
  113. {
  114. struct ecap_cnt_dev *ecap_dev = counter_priv(counter);
  115. /* Stop counter */
  116. regmap_update_bits(ecap_dev->regmap, ECAP_ECCTL_REG, ECAP_ECCTL_EN_MASK, 0);
  117. /* Disable interrupts on events */
  118. regmap_update_bits(ecap_dev->regmap, ECAP_ECINT_EN_FLG_REG, ECAP_EVT_EN_MASK, 0);
  119. pm_runtime_put_sync(counter->parent);
  120. }
  121. static u32 ecap_cnt_count_get_val(struct counter_device *counter, unsigned int reg)
  122. {
  123. struct ecap_cnt_dev *ecap_dev = counter_priv(counter);
  124. unsigned int regval;
  125. pm_runtime_get_sync(counter->parent);
  126. regmap_read(ecap_dev->regmap, reg, &regval);
  127. pm_runtime_put_sync(counter->parent);
  128. return regval;
  129. }
  130. static void ecap_cnt_count_set_val(struct counter_device *counter, unsigned int reg, u32 val)
  131. {
  132. struct ecap_cnt_dev *ecap_dev = counter_priv(counter);
  133. pm_runtime_get_sync(counter->parent);
  134. regmap_write(ecap_dev->regmap, reg, val);
  135. pm_runtime_put_sync(counter->parent);
  136. }
  137. static int ecap_cnt_count_read(struct counter_device *counter,
  138. struct counter_count *count, u64 *val)
  139. {
  140. *val = ecap_cnt_count_get_val(counter, ECAP_TSCNT_REG);
  141. return 0;
  142. }
  143. static int ecap_cnt_count_write(struct counter_device *counter,
  144. struct counter_count *count, u64 val)
  145. {
  146. if (val > U32_MAX)
  147. return -ERANGE;
  148. ecap_cnt_count_set_val(counter, ECAP_TSCNT_REG, val);
  149. return 0;
  150. }
  151. static int ecap_cnt_function_read(struct counter_device *counter,
  152. struct counter_count *count,
  153. enum counter_function *function)
  154. {
  155. *function = COUNTER_FUNCTION_INCREASE;
  156. return 0;
  157. }
  158. static int ecap_cnt_action_read(struct counter_device *counter,
  159. struct counter_count *count,
  160. struct counter_synapse *synapse,
  161. enum counter_synapse_action *action)
  162. {
  163. *action = (synapse->signal->id == ECAP_CLOCK_SIG) ?
  164. COUNTER_SYNAPSE_ACTION_RISING_EDGE :
  165. COUNTER_SYNAPSE_ACTION_NONE;
  166. return 0;
  167. }
  168. static int ecap_cnt_watch_validate(struct counter_device *counter,
  169. const struct counter_watch *watch)
  170. {
  171. if (watch->channel > ECAP_CEVT_LAST)
  172. return -EINVAL;
  173. switch (watch->event) {
  174. case COUNTER_EVENT_CAPTURE:
  175. case COUNTER_EVENT_OVERFLOW:
  176. return 0;
  177. default:
  178. return -EINVAL;
  179. }
  180. }
  181. static int ecap_cnt_clk_get_freq(struct counter_device *counter,
  182. struct counter_signal *signal, u64 *freq)
  183. {
  184. struct ecap_cnt_dev *ecap_dev = counter_priv(counter);
  185. *freq = clk_get_rate(ecap_dev->clk);
  186. return 0;
  187. }
  188. static int ecap_cnt_pol_read(struct counter_device *counter,
  189. struct counter_signal *signal,
  190. size_t idx, enum counter_signal_polarity *pol)
  191. {
  192. struct ecap_cnt_dev *ecap_dev = counter_priv(counter);
  193. int bitval;
  194. pm_runtime_get_sync(counter->parent);
  195. bitval = regmap_test_bits(ecap_dev->regmap, ECAP_ECCTL_REG, ECAP_CAPPOL_BIT(idx));
  196. pm_runtime_put_sync(counter->parent);
  197. *pol = bitval ? COUNTER_SIGNAL_POLARITY_NEGATIVE : COUNTER_SIGNAL_POLARITY_POSITIVE;
  198. return 0;
  199. }
  200. static int ecap_cnt_pol_write(struct counter_device *counter,
  201. struct counter_signal *signal,
  202. size_t idx, enum counter_signal_polarity pol)
  203. {
  204. struct ecap_cnt_dev *ecap_dev = counter_priv(counter);
  205. pm_runtime_get_sync(counter->parent);
  206. if (pol == COUNTER_SIGNAL_POLARITY_NEGATIVE)
  207. regmap_set_bits(ecap_dev->regmap, ECAP_ECCTL_REG, ECAP_CAPPOL_BIT(idx));
  208. else
  209. regmap_clear_bits(ecap_dev->regmap, ECAP_ECCTL_REG, ECAP_CAPPOL_BIT(idx));
  210. pm_runtime_put_sync(counter->parent);
  211. return 0;
  212. }
  213. static int ecap_cnt_cap_read(struct counter_device *counter,
  214. struct counter_count *count,
  215. size_t idx, u64 *cap)
  216. {
  217. *cap = ecap_cnt_count_get_val(counter, ECAP_CAP_REG(idx));
  218. return 0;
  219. }
  220. static int ecap_cnt_cap_write(struct counter_device *counter,
  221. struct counter_count *count,
  222. size_t idx, u64 cap)
  223. {
  224. if (cap > U32_MAX)
  225. return -ERANGE;
  226. ecap_cnt_count_set_val(counter, ECAP_CAP_REG(idx), cap);
  227. return 0;
  228. }
  229. static int ecap_cnt_nb_ovf_read(struct counter_device *counter,
  230. struct counter_count *count, u64 *val)
  231. {
  232. struct ecap_cnt_dev *ecap_dev = counter_priv(counter);
  233. *val = atomic_read(&ecap_dev->nb_ovf);
  234. return 0;
  235. }
  236. static int ecap_cnt_nb_ovf_write(struct counter_device *counter,
  237. struct counter_count *count, u64 val)
  238. {
  239. struct ecap_cnt_dev *ecap_dev = counter_priv(counter);
  240. if (val > U32_MAX)
  241. return -ERANGE;
  242. atomic_set(&ecap_dev->nb_ovf, val);
  243. return 0;
  244. }
  245. static int ecap_cnt_ceiling_read(struct counter_device *counter,
  246. struct counter_count *count, u64 *val)
  247. {
  248. *val = U32_MAX;
  249. return 0;
  250. }
  251. static int ecap_cnt_enable_read(struct counter_device *counter,
  252. struct counter_count *count, u8 *enable)
  253. {
  254. struct ecap_cnt_dev *ecap_dev = counter_priv(counter);
  255. *enable = ecap_dev->enabled;
  256. return 0;
  257. }
  258. static int ecap_cnt_enable_write(struct counter_device *counter,
  259. struct counter_count *count, u8 enable)
  260. {
  261. struct ecap_cnt_dev *ecap_dev = counter_priv(counter);
  262. mutex_lock(&ecap_dev->lock);
  263. if (enable == ecap_dev->enabled)
  264. goto out;
  265. if (enable)
  266. ecap_cnt_capture_enable(counter);
  267. else
  268. ecap_cnt_capture_disable(counter);
  269. ecap_dev->enabled = enable;
  270. out:
  271. mutex_unlock(&ecap_dev->lock);
  272. return 0;
  273. }
  274. static const struct counter_ops ecap_cnt_ops = {
  275. .count_read = ecap_cnt_count_read,
  276. .count_write = ecap_cnt_count_write,
  277. .function_read = ecap_cnt_function_read,
  278. .action_read = ecap_cnt_action_read,
  279. .watch_validate = ecap_cnt_watch_validate,
  280. };
  281. static const enum counter_function ecap_cnt_functions[] = {
  282. COUNTER_FUNCTION_INCREASE,
  283. };
  284. static const enum counter_synapse_action ecap_cnt_clock_actions[] = {
  285. COUNTER_SYNAPSE_ACTION_RISING_EDGE,
  286. };
  287. static const enum counter_synapse_action ecap_cnt_input_actions[] = {
  288. COUNTER_SYNAPSE_ACTION_NONE,
  289. };
  290. static struct counter_comp ecap_cnt_clock_ext[] = {
  291. COUNTER_COMP_SIGNAL_U64("frequency", ecap_cnt_clk_get_freq, NULL),
  292. };
  293. static const enum counter_signal_polarity ecap_cnt_pol_avail[] = {
  294. COUNTER_SIGNAL_POLARITY_POSITIVE,
  295. COUNTER_SIGNAL_POLARITY_NEGATIVE,
  296. };
  297. static DEFINE_COUNTER_AVAILABLE(ecap_cnt_pol_available, ecap_cnt_pol_avail);
  298. static DEFINE_COUNTER_ARRAY_POLARITY(ecap_cnt_pol_array, ecap_cnt_pol_available, ECAP_NB_CEVT);
  299. static struct counter_comp ecap_cnt_signal_ext[] = {
  300. COUNTER_COMP_ARRAY_POLARITY(ecap_cnt_pol_read, ecap_cnt_pol_write, ecap_cnt_pol_array),
  301. };
  302. static struct counter_signal ecap_cnt_signals[] = {
  303. {
  304. .id = ECAP_CLOCK_SIG,
  305. .name = "Clock Signal",
  306. .ext = ecap_cnt_clock_ext,
  307. .num_ext = ARRAY_SIZE(ecap_cnt_clock_ext),
  308. },
  309. {
  310. .id = ECAP_INPUT_SIG,
  311. .name = "Input Signal",
  312. .ext = ecap_cnt_signal_ext,
  313. .num_ext = ARRAY_SIZE(ecap_cnt_signal_ext),
  314. },
  315. };
  316. static struct counter_synapse ecap_cnt_synapses[] = {
  317. {
  318. .actions_list = ecap_cnt_clock_actions,
  319. .num_actions = ARRAY_SIZE(ecap_cnt_clock_actions),
  320. .signal = &ecap_cnt_signals[ECAP_CLOCK_SIG],
  321. },
  322. {
  323. .actions_list = ecap_cnt_input_actions,
  324. .num_actions = ARRAY_SIZE(ecap_cnt_input_actions),
  325. .signal = &ecap_cnt_signals[ECAP_INPUT_SIG],
  326. },
  327. };
  328. static DEFINE_COUNTER_ARRAY_CAPTURE(ecap_cnt_cap_array, ECAP_NB_CEVT);
  329. static struct counter_comp ecap_cnt_count_ext[] = {
  330. COUNTER_COMP_ARRAY_CAPTURE(ecap_cnt_cap_read, ecap_cnt_cap_write, ecap_cnt_cap_array),
  331. COUNTER_COMP_COUNT_U64("num_overflows", ecap_cnt_nb_ovf_read, ecap_cnt_nb_ovf_write),
  332. COUNTER_COMP_CEILING(ecap_cnt_ceiling_read, NULL),
  333. COUNTER_COMP_ENABLE(ecap_cnt_enable_read, ecap_cnt_enable_write),
  334. };
  335. static struct counter_count ecap_cnt_counts[] = {
  336. {
  337. .name = "Timestamp Counter",
  338. .functions_list = ecap_cnt_functions,
  339. .num_functions = ARRAY_SIZE(ecap_cnt_functions),
  340. .synapses = ecap_cnt_synapses,
  341. .num_synapses = ARRAY_SIZE(ecap_cnt_synapses),
  342. .ext = ecap_cnt_count_ext,
  343. .num_ext = ARRAY_SIZE(ecap_cnt_count_ext),
  344. },
  345. };
  346. static irqreturn_t ecap_cnt_isr(int irq, void *dev_id)
  347. {
  348. struct counter_device *counter_dev = dev_id;
  349. struct ecap_cnt_dev *ecap_dev = counter_priv(counter_dev);
  350. unsigned int clr = 0;
  351. unsigned int flg;
  352. int i;
  353. regmap_read(ecap_dev->regmap, ECAP_ECINT_EN_FLG_REG, &flg);
  354. /* Check capture events */
  355. for (i = 0 ; i < ECAP_NB_CEVT ; i++) {
  356. if (flg & ECAP_EVT_FLG_BIT(i)) {
  357. counter_push_event(counter_dev, COUNTER_EVENT_CAPTURE, i);
  358. clr |= ECAP_EVT_CLR_BIT(i);
  359. }
  360. }
  361. /* Check counter overflow */
  362. if (flg & ECAP_EVT_FLG_BIT(ECAP_CNTOVF)) {
  363. atomic_inc(&ecap_dev->nb_ovf);
  364. for (i = 0 ; i < ECAP_NB_CEVT ; i++)
  365. counter_push_event(counter_dev, COUNTER_EVENT_OVERFLOW, i);
  366. clr |= ECAP_EVT_CLR_BIT(ECAP_CNTOVF);
  367. }
  368. clr |= ECAP_INT_CLR_BIT;
  369. regmap_update_bits(ecap_dev->regmap, ECAP_ECINT_CLR_FRC_REG, ECAP_EVT_CLR_MASK, clr);
  370. return IRQ_HANDLED;
  371. }
  372. static void ecap_cnt_pm_disable(void *dev)
  373. {
  374. pm_runtime_disable(dev);
  375. }
  376. static int ecap_cnt_probe(struct platform_device *pdev)
  377. {
  378. struct device *dev = &pdev->dev;
  379. struct ecap_cnt_dev *ecap_dev;
  380. struct counter_device *counter_dev;
  381. void __iomem *mmio_base;
  382. unsigned long clk_rate;
  383. int ret;
  384. counter_dev = devm_counter_alloc(dev, sizeof(*ecap_dev));
  385. if (!counter_dev)
  386. return -ENOMEM;
  387. counter_dev->name = ECAP_DRV_NAME;
  388. counter_dev->parent = dev;
  389. counter_dev->ops = &ecap_cnt_ops;
  390. counter_dev->signals = ecap_cnt_signals;
  391. counter_dev->num_signals = ARRAY_SIZE(ecap_cnt_signals);
  392. counter_dev->counts = ecap_cnt_counts;
  393. counter_dev->num_counts = ARRAY_SIZE(ecap_cnt_counts);
  394. ecap_dev = counter_priv(counter_dev);
  395. mutex_init(&ecap_dev->lock);
  396. ecap_dev->clk = devm_clk_get_enabled(dev, "fck");
  397. if (IS_ERR(ecap_dev->clk))
  398. return dev_err_probe(dev, PTR_ERR(ecap_dev->clk), "failed to get clock\n");
  399. clk_rate = clk_get_rate(ecap_dev->clk);
  400. if (!clk_rate) {
  401. dev_err(dev, "failed to get clock rate\n");
  402. return -EINVAL;
  403. }
  404. mmio_base = devm_platform_ioremap_resource(pdev, 0);
  405. if (IS_ERR(mmio_base))
  406. return PTR_ERR(mmio_base);
  407. ecap_dev->regmap = devm_regmap_init_mmio(dev, mmio_base, &ecap_cnt_regmap_config);
  408. if (IS_ERR(ecap_dev->regmap))
  409. return dev_err_probe(dev, PTR_ERR(ecap_dev->regmap), "failed to init regmap\n");
  410. ret = platform_get_irq(pdev, 0);
  411. if (ret < 0)
  412. return dev_err_probe(dev, ret, "failed to get irq\n");
  413. ret = devm_request_irq(dev, ret, ecap_cnt_isr, 0, pdev->name, counter_dev);
  414. if (ret)
  415. return dev_err_probe(dev, ret, "failed to request irq\n");
  416. platform_set_drvdata(pdev, counter_dev);
  417. pm_runtime_enable(dev);
  418. /* Register a cleanup callback to care for disabling PM */
  419. ret = devm_add_action_or_reset(dev, ecap_cnt_pm_disable, dev);
  420. if (ret)
  421. return dev_err_probe(dev, ret, "failed to add pm disable action\n");
  422. ret = devm_counter_add(dev, counter_dev);
  423. if (ret)
  424. return dev_err_probe(dev, ret, "failed to add counter\n");
  425. return 0;
  426. }
  427. static int ecap_cnt_remove(struct platform_device *pdev)
  428. {
  429. struct counter_device *counter_dev = platform_get_drvdata(pdev);
  430. struct ecap_cnt_dev *ecap_dev = counter_priv(counter_dev);
  431. if (ecap_dev->enabled)
  432. ecap_cnt_capture_disable(counter_dev);
  433. return 0;
  434. }
  435. static int ecap_cnt_suspend(struct device *dev)
  436. {
  437. struct counter_device *counter_dev = dev_get_drvdata(dev);
  438. struct ecap_cnt_dev *ecap_dev = counter_priv(counter_dev);
  439. /* If eCAP is running, stop capture then save timestamp counter */
  440. if (ecap_dev->enabled) {
  441. /*
  442. * Disabling capture has the following effects:
  443. * - interrupts are disabled
  444. * - loading of capture registers is disabled
  445. * - timebase counter is stopped
  446. */
  447. ecap_cnt_capture_disable(counter_dev);
  448. ecap_dev->pm_ctx.time_cntr = ecap_cnt_count_get_val(counter_dev, ECAP_TSCNT_REG);
  449. }
  450. ecap_dev->pm_ctx.ev_mode = ecap_cnt_capture_get_evmode(counter_dev);
  451. clk_disable(ecap_dev->clk);
  452. return 0;
  453. }
  454. static int ecap_cnt_resume(struct device *dev)
  455. {
  456. struct counter_device *counter_dev = dev_get_drvdata(dev);
  457. struct ecap_cnt_dev *ecap_dev = counter_priv(counter_dev);
  458. clk_enable(ecap_dev->clk);
  459. ecap_cnt_capture_set_evmode(counter_dev, ecap_dev->pm_ctx.ev_mode);
  460. /* If eCAP was running, restore timestamp counter then run capture */
  461. if (ecap_dev->enabled) {
  462. ecap_cnt_count_set_val(counter_dev, ECAP_TSCNT_REG, ecap_dev->pm_ctx.time_cntr);
  463. ecap_cnt_capture_enable(counter_dev);
  464. }
  465. return 0;
  466. }
  467. static DEFINE_SIMPLE_DEV_PM_OPS(ecap_cnt_pm_ops, ecap_cnt_suspend, ecap_cnt_resume);
  468. static const struct of_device_id ecap_cnt_of_match[] = {
  469. { .compatible = "ti,am62-ecap-capture" },
  470. {},
  471. };
  472. MODULE_DEVICE_TABLE(of, ecap_cnt_of_match);
  473. static struct platform_driver ecap_cnt_driver = {
  474. .probe = ecap_cnt_probe,
  475. .remove = ecap_cnt_remove,
  476. .driver = {
  477. .name = "ecap-capture",
  478. .of_match_table = ecap_cnt_of_match,
  479. .pm = pm_sleep_ptr(&ecap_cnt_pm_ops),
  480. },
  481. };
  482. module_platform_driver(ecap_cnt_driver);
  483. MODULE_DESCRIPTION("ECAP Capture driver");
  484. MODULE_AUTHOR("Julien Panis <[email protected]>");
  485. MODULE_LICENSE("GPL");
  486. MODULE_IMPORT_NS(COUNTER);