Lines Matching +full:enum +full:- +full:cnt +full:- +full:name
1 // SPDX-License-Identifier: GPL-2.0-only
17 #include <uapi/linux/counter/microchip-tcb-capture.h>
38 static const enum counter_function mchp_tc_count_functions[] = {
43 static const enum counter_synapse_action mchp_tc_synapse_actions[] = {
53 .name = "Channel A",
57 .name = "Channel B",
76 enum counter_function *function) in mchp_tc_count_function_read()
80 if (priv->qdec_mode) in mchp_tc_count_function_read()
90 enum counter_function function) in mchp_tc_count_function_write()
95 regmap_read(priv->regmap, ATMEL_TC_BMR, &bmr); in mchp_tc_count_function_write()
96 regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], CMR), &cmr); in mchp_tc_count_function_write()
103 priv->qdec_mode = 0; in mchp_tc_count_function_write()
106 if (!priv->tc_cfg->has_gclk) in mchp_tc_count_function_write()
115 if (!priv->tc_cfg->has_qdec) in mchp_tc_count_function_write()
116 return -EINVAL; in mchp_tc_count_function_write()
118 if (priv->num_channels < 2 || priv->channel[0] != 0 || in mchp_tc_count_function_write()
119 priv->channel[1] != 1) { in mchp_tc_count_function_write()
121 return -EINVAL; in mchp_tc_count_function_write()
123 priv->qdec_mode = 1; in mchp_tc_count_function_write()
129 return -EINVAL; in mchp_tc_count_function_write()
132 regmap_write(priv->regmap, ATMEL_TC_BMR, bmr); in mchp_tc_count_function_write()
133 regmap_write(priv->regmap, ATMEL_TC_REG(priv->channel[0], CMR), cmr); in mchp_tc_count_function_write()
136 regmap_write(priv->regmap, ATMEL_TC_REG(priv->channel[0], CCR), in mchp_tc_count_function_write()
139 if (priv->qdec_mode) { in mchp_tc_count_function_write()
140 regmap_write(priv->regmap, in mchp_tc_count_function_write()
141 ATMEL_TC_REG(priv->channel[1], CMR), cmr); in mchp_tc_count_function_write()
142 regmap_write(priv->regmap, in mchp_tc_count_function_write()
143 ATMEL_TC_REG(priv->channel[1], CCR), in mchp_tc_count_function_write()
152 enum counter_signal_level *lvl) in mchp_tc_count_signal_read()
158 regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], SR), &sr); in mchp_tc_count_signal_read()
160 if (signal->id == 1) in mchp_tc_count_signal_read()
173 enum counter_synapse_action *action) in mchp_tc_count_action_read()
178 if (priv->qdec_mode) { in mchp_tc_count_action_read()
183 /* Only TIOA signal is evaluated in non-QDEC mode */ in mchp_tc_count_action_read()
184 if (synapse->signal->id != 0) { in mchp_tc_count_action_read()
189 regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], CMR), &cmr); in mchp_tc_count_action_read()
212 enum counter_synapse_action action) in mchp_tc_count_action_write()
217 /* QDEC mode is rising edge only; only TIOA handled in non-QDEC mode */ in mchp_tc_count_action_write()
218 if (priv->qdec_mode || synapse->signal->id != 0) in mchp_tc_count_action_write()
219 return -EINVAL; in mchp_tc_count_action_write()
236 return -EINVAL; in mchp_tc_count_action_write()
239 return regmap_write_bits(priv->regmap, in mchp_tc_count_action_write()
240 ATMEL_TC_REG(priv->channel[0], CMR), in mchp_tc_count_action_write()
248 u32 cnt; in mchp_tc_count_read() local
250 regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], CV), &cnt); in mchp_tc_count_read()
251 *val = cnt; in mchp_tc_count_read()
260 u32 cnt; in mchp_tc_count_cap_read() local
265 ret = regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], RA), &cnt); in mchp_tc_count_cap_read()
268 ret = regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], RB), &cnt); in mchp_tc_count_cap_read()
271 return -EINVAL; in mchp_tc_count_cap_read()
277 *val = cnt; in mchp_tc_count_cap_read()
289 return -ERANGE; in mchp_tc_count_cap_write()
293 ret = regmap_write(priv->regmap, ATMEL_TC_REG(priv->channel[0], RA), val); in mchp_tc_count_cap_write()
296 ret = regmap_write(priv->regmap, ATMEL_TC_REG(priv->channel[0], RB), val); in mchp_tc_count_cap_write()
299 return -EINVAL; in mchp_tc_count_cap_write()
309 u32 cnt; in mchp_tc_count_compare_read() local
312 ret = regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], RC), &cnt); in mchp_tc_count_compare_read()
316 *val = cnt; in mchp_tc_count_compare_read()
327 return -ERANGE; in mchp_tc_count_compare_write()
329 return regmap_write(priv->regmap, ATMEL_TC_REG(priv->channel[0], RC), val); in mchp_tc_count_compare_write()
343 if (watch->channel == COUNTER_MCHP_EVCHN_CV || watch->channel == COUNTER_MCHP_EVCHN_RA) in mchp_tc_watch_validate()
344 switch (watch->event) { in mchp_tc_watch_validate()
350 return -EINVAL; in mchp_tc_watch_validate()
353 if (watch->channel == COUNTER_MCHP_EVCHN_RB && watch->event == COUNTER_EVENT_CAPTURE) in mchp_tc_watch_validate()
356 if (watch->channel == COUNTER_MCHP_EVCHN_RC && watch->event == COUNTER_EVENT_THRESHOLD) in mchp_tc_watch_validate()
359 return -EINVAL; in mchp_tc_watch_validate()
365 .name = "Timer Counter",
405 { .compatible = "atmel,at91rm9200-tcb", .data = &tcb_rm9200_config, },
406 { .compatible = "atmel,at91sam9x5-tcb", .data = &tcb_sam9x5_config, },
407 { .compatible = "atmel,sama5d2-tcb", .data = &tcb_sama5d2_config, },
408 { .compatible = "atmel,sama5d3-tcb", .data = &tcb_sama5d3_config, },
418 regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], SR), &sr); in mchp_tc_isr()
419 regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], IMR), &mask); in mchp_tc_isr()
448 regmap_write(priv->regmap, ATMEL_TC_REG(priv->channel[0], IDR), ATMEL_TC_DEF_IRQS); in mchp_tc_irq_remove()
454 int ret = devm_request_irq(counter->parent, irq, mchp_tc_isr, 0, in mchp_tc_irq_enable()
455 dev_name(counter->parent), counter); in mchp_tc_irq_enable()
460 ret = regmap_write(priv->regmap, ATMEL_TC_REG(priv->channel[0], IER), ATMEL_TC_DEF_IRQS); in mchp_tc_irq_enable()
464 ret = devm_add_action_or_reset(counter->parent, mchp_tc_irq_remove, priv); in mchp_tc_irq_enable()
478 struct device_node *np = pdev->dev.of_node; in mchp_tc_probe()
489 counter = devm_counter_alloc(&pdev->dev, sizeof(*priv)); in mchp_tc_probe()
491 return -ENOMEM; in mchp_tc_probe()
494 match = of_match_node(atmel_tc_of_match, np->parent); in mchp_tc_probe()
495 tcb_config = match->data; in mchp_tc_probe()
497 dev_err(&pdev->dev, "No matching parent node found\n"); in mchp_tc_probe()
498 return -ENODEV; in mchp_tc_probe()
501 regmap = syscon_node_to_regmap(np->parent); in mchp_tc_probe()
506 priv->num_channels = of_property_count_u32_elems(np, "reg"); in mchp_tc_probe()
507 if (priv->num_channels < 0) { in mchp_tc_probe()
508 dev_err(&pdev->dev, "Invalid or missing channel\n"); in mchp_tc_probe()
509 return -EINVAL; in mchp_tc_probe()
513 for (i = 0; i < priv->num_channels; i++) { in mchp_tc_probe()
516 return -ENODEV; in mchp_tc_probe()
518 priv->channel[i] = channel; in mchp_tc_probe()
522 clk[i] = of_clk_get_by_name(np->parent, clk_name); in mchp_tc_probe()
525 clk[i] = of_clk_get_by_name(np->parent, "t0_clk"); in mchp_tc_probe()
534 ret = devm_add_action_or_reset(&pdev->dev, in mchp_tc_probe()
540 dev_dbg(&pdev->dev, in mchp_tc_probe()
551 ret = regmap_update_bits(regmap, ATMEL_TC_REG(priv->channel[0], CMR), in mchp_tc_probe()
559 ret = regmap_write(regmap, ATMEL_TC_REG(priv->channel[0], CCR), in mchp_tc_probe()
564 priv->tc_cfg = tcb_config; in mchp_tc_probe()
565 priv->regmap = regmap; in mchp_tc_probe()
566 counter->name = dev_name(&pdev->dev); in mchp_tc_probe()
567 counter->parent = &pdev->dev; in mchp_tc_probe()
568 counter->ops = &mchp_tc_ops; in mchp_tc_probe()
569 counter->num_counts = ARRAY_SIZE(mchp_tc_counts); in mchp_tc_probe()
570 counter->counts = mchp_tc_counts; in mchp_tc_probe()
571 counter->num_signals = ARRAY_SIZE(mchp_tc_count_signals); in mchp_tc_probe()
572 counter->signals = mchp_tc_count_signals; in mchp_tc_probe()
574 i = of_irq_get(np->parent, 0); in mchp_tc_probe()
575 if (i == -EPROBE_DEFER) in mchp_tc_probe()
576 return -EPROBE_DEFER; in mchp_tc_probe()
580 return dev_err_probe(&pdev->dev, ret, "Failed to set up IRQ"); in mchp_tc_probe()
583 ret = devm_counter_add(&pdev->dev, counter); in mchp_tc_probe()
585 return dev_err_probe(&pdev->dev, ret, "Failed to add counter\n"); in mchp_tc_probe()
591 { .compatible = "microchip,tcb-capture", },
599 .name = "microchip-tcb-capture",