Lines Matching +full:am62 +full:- +full:ecap +full:- +full:capture
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * ECAP Capture driver
21 #define ECAP_DRV_NAME "ecap"
23 /* ECAP event IDs */
66 /* ECAP signals */
78 * struct ecap_cnt_dev - device private data structure
83 * @nb_ovf: number of overflows since capture start
105 pm_runtime_get_sync(counter->parent); in ecap_cnt_capture_get_evmode()
106 regmap_read(ecap_dev->regmap, ECAP_ECCTL_REG, ®val); in ecap_cnt_capture_get_evmode()
107 pm_runtime_put_sync(counter->parent); in ecap_cnt_capture_get_evmode()
116 pm_runtime_get_sync(counter->parent); in ecap_cnt_capture_set_evmode()
117 regmap_update_bits(ecap_dev->regmap, ECAP_ECCTL_REG, ECAP_EV_MODE_MASK, ev_mode); in ecap_cnt_capture_set_evmode()
118 pm_runtime_put_sync(counter->parent); in ecap_cnt_capture_set_evmode()
125 pm_runtime_get_sync(counter->parent); in ecap_cnt_capture_enable()
128 regmap_update_bits(ecap_dev->regmap, ECAP_ECINT_EN_FLG_REG, in ecap_cnt_capture_enable()
132 regmap_update_bits(ecap_dev->regmap, ECAP_ECCTL_REG, ECAP_ECCTL_CFG_MASK, in ecap_cnt_capture_enable()
141 regmap_update_bits(ecap_dev->regmap, ECAP_ECCTL_REG, ECAP_ECCTL_EN_MASK, 0); in ecap_cnt_capture_disable()
144 regmap_update_bits(ecap_dev->regmap, ECAP_ECINT_EN_FLG_REG, ECAP_EVT_EN_MASK, 0); in ecap_cnt_capture_disable()
146 pm_runtime_put_sync(counter->parent); in ecap_cnt_capture_disable()
154 pm_runtime_get_sync(counter->parent); in ecap_cnt_count_get_val()
155 regmap_read(ecap_dev->regmap, reg, ®val); in ecap_cnt_count_get_val()
156 pm_runtime_put_sync(counter->parent); in ecap_cnt_count_get_val()
165 pm_runtime_get_sync(counter->parent); in ecap_cnt_count_set_val()
166 regmap_write(ecap_dev->regmap, reg, val); in ecap_cnt_count_set_val()
167 pm_runtime_put_sync(counter->parent); in ecap_cnt_count_set_val()
182 return -ERANGE; in ecap_cnt_count_write()
203 *action = (synapse->signal->id == ECAP_CLOCK_SIG) ? in ecap_cnt_action_read()
213 if (watch->channel > ECAP_CEVT_LAST) in ecap_cnt_watch_validate()
214 return -EINVAL; in ecap_cnt_watch_validate()
216 switch (watch->event) { in ecap_cnt_watch_validate()
221 return -EINVAL; in ecap_cnt_watch_validate()
230 *freq = clk_get_rate(ecap_dev->clk); in ecap_cnt_clk_get_freq()
242 pm_runtime_get_sync(counter->parent); in ecap_cnt_pol_read()
243 bitval = regmap_test_bits(ecap_dev->regmap, ECAP_ECCTL_REG, ECAP_CAPPOL_BIT(idx)); in ecap_cnt_pol_read()
244 pm_runtime_put_sync(counter->parent); in ecap_cnt_pol_read()
257 pm_runtime_get_sync(counter->parent); in ecap_cnt_pol_write()
259 regmap_set_bits(ecap_dev->regmap, ECAP_ECCTL_REG, ECAP_CAPPOL_BIT(idx)); in ecap_cnt_pol_write()
261 regmap_clear_bits(ecap_dev->regmap, ECAP_ECCTL_REG, ECAP_CAPPOL_BIT(idx)); in ecap_cnt_pol_write()
262 pm_runtime_put_sync(counter->parent); in ecap_cnt_pol_write()
281 return -ERANGE; in ecap_cnt_cap_write()
293 *val = atomic_read(&ecap_dev->nb_ovf); in ecap_cnt_nb_ovf_read()
304 return -ERANGE; in ecap_cnt_nb_ovf_write()
306 atomic_set(&ecap_dev->nb_ovf, val); in ecap_cnt_nb_ovf_write()
324 *enable = ecap_dev->enabled; in ecap_cnt_enable_read()
334 mutex_lock(&ecap_dev->lock); in ecap_cnt_enable_write()
336 if (enable == ecap_dev->enabled) in ecap_cnt_enable_write()
343 ecap_dev->enabled = enable; in ecap_cnt_enable_write()
346 mutex_unlock(&ecap_dev->lock); in ecap_cnt_enable_write()
444 regmap_read(ecap_dev->regmap, ECAP_ECINT_EN_FLG_REG, &flg); in ecap_cnt_isr()
446 /* Check capture events */ in ecap_cnt_isr()
456 atomic_inc(&ecap_dev->nb_ovf); in ecap_cnt_isr()
463 regmap_update_bits(ecap_dev->regmap, ECAP_ECINT_CLR_FRC_REG, ECAP_EVT_CLR_MASK, clr); in ecap_cnt_isr()
475 struct device *dev = &pdev->dev; in ecap_cnt_probe()
484 return -ENOMEM; in ecap_cnt_probe()
486 counter_dev->name = ECAP_DRV_NAME; in ecap_cnt_probe()
487 counter_dev->parent = dev; in ecap_cnt_probe()
488 counter_dev->ops = &ecap_cnt_ops; in ecap_cnt_probe()
489 counter_dev->signals = ecap_cnt_signals; in ecap_cnt_probe()
490 counter_dev->num_signals = ARRAY_SIZE(ecap_cnt_signals); in ecap_cnt_probe()
491 counter_dev->counts = ecap_cnt_counts; in ecap_cnt_probe()
492 counter_dev->num_counts = ARRAY_SIZE(ecap_cnt_counts); in ecap_cnt_probe()
496 mutex_init(&ecap_dev->lock); in ecap_cnt_probe()
498 ecap_dev->clk = devm_clk_get_enabled(dev, "fck"); in ecap_cnt_probe()
499 if (IS_ERR(ecap_dev->clk)) in ecap_cnt_probe()
500 return dev_err_probe(dev, PTR_ERR(ecap_dev->clk), "failed to get clock\n"); in ecap_cnt_probe()
502 clk_rate = clk_get_rate(ecap_dev->clk); in ecap_cnt_probe()
505 return -EINVAL; in ecap_cnt_probe()
512 ecap_dev->regmap = devm_regmap_init_mmio(dev, mmio_base, &ecap_cnt_regmap_config); in ecap_cnt_probe()
513 if (IS_ERR(ecap_dev->regmap)) in ecap_cnt_probe()
514 return dev_err_probe(dev, PTR_ERR(ecap_dev->regmap), "failed to init regmap\n"); in ecap_cnt_probe()
520 ret = devm_request_irq(dev, ret, ecap_cnt_isr, 0, pdev->name, counter_dev); in ecap_cnt_probe()
545 if (ecap_dev->enabled) in ecap_cnt_remove()
554 /* If eCAP is running, stop capture then save timestamp counter */ in ecap_cnt_suspend()
555 if (ecap_dev->enabled) { in ecap_cnt_suspend()
557 * Disabling capture has the following effects: in ecap_cnt_suspend()
558 * - interrupts are disabled in ecap_cnt_suspend()
559 * - loading of capture registers is disabled in ecap_cnt_suspend()
560 * - timebase counter is stopped in ecap_cnt_suspend()
563 ecap_dev->pm_ctx.time_cntr = ecap_cnt_count_get_val(counter_dev, ECAP_TSCNT_REG); in ecap_cnt_suspend()
566 ecap_dev->pm_ctx.ev_mode = ecap_cnt_capture_get_evmode(counter_dev); in ecap_cnt_suspend()
568 clk_disable(ecap_dev->clk); in ecap_cnt_suspend()
578 clk_enable(ecap_dev->clk); in ecap_cnt_resume()
580 ecap_cnt_capture_set_evmode(counter_dev, ecap_dev->pm_ctx.ev_mode); in ecap_cnt_resume()
582 /* If eCAP was running, restore timestamp counter then run capture */ in ecap_cnt_resume()
583 if (ecap_dev->enabled) { in ecap_cnt_resume()
584 ecap_cnt_count_set_val(counter_dev, ECAP_TSCNT_REG, ecap_dev->pm_ctx.time_cntr); in ecap_cnt_resume()
594 { .compatible = "ti,am62-ecap-capture" },
603 .name = "ecap-capture",
610 MODULE_DESCRIPTION("ECAP Capture driver");