Lines Matching +full:signal +full:- +full:id
1 // SPDX-License-Identifier: GPL-2.0
3 * STM32 Low-Power Timer Encoder and Counter driver
9 * Inspired by 104-quad-8 and stm32-timer-trigger drivers.
15 #include <linux/mfd/stm32-lptimer.h>
37 ret = regmap_read(priv->regmap, STM32_LPTIM_CR, &val); in stm32_lptim_is_enabled()
51 ret = regmap_write(priv->regmap, STM32_LPTIM_CR, val); in stm32_lptim_set_enable_state()
56 clk_disable(priv->clk); in stm32_lptim_set_enable_state()
57 priv->enabled = false; in stm32_lptim_set_enable_state()
62 ret = regmap_write(priv->regmap, STM32_LPTIM_ARR, priv->ceiling); in stm32_lptim_set_enable_state()
66 ret = regmap_write(priv->regmap, STM32_LPTIM_CMP, 0); in stm32_lptim_set_enable_state()
71 ret = regmap_read_poll_timeout(priv->regmap, STM32_LPTIM_ISR, val, in stm32_lptim_set_enable_state()
77 ret = regmap_write(priv->regmap, STM32_LPTIM_ICR, in stm32_lptim_set_enable_state()
82 ret = clk_enable(priv->clk); in stm32_lptim_set_enable_state()
84 regmap_write(priv->regmap, STM32_LPTIM_CR, 0); in stm32_lptim_set_enable_state()
87 priv->enabled = true; in stm32_lptim_set_enable_state()
90 return regmap_update_bits(priv->regmap, STM32_LPTIM_CR, in stm32_lptim_set_enable_state()
101 if (priv->quadrature_mode) in stm32_lptim_setup()
105 val |= FIELD_PREP(STM32_LPTIM_CKPOL, enable ? priv->polarity : 0); in stm32_lptim_setup()
107 return regmap_update_bits(priv->regmap, STM32_LPTIM_CFGR, mask, val); in stm32_lptim_setup()
111 * enum stm32_lptim_cnt_function - enumerates LPTimer counter & encoder modes
115 * In non-quadrature mode, device counts up on active edge.
117 * +---------+----------+--------------------+--------------------+
118 * | Active | Level on | IN1 signal | IN2 signal |
119 * | edge | opposite +----------+---------+----------+---------+
120 * | | signal | Rising | Falling | Rising | Falling |
121 * +---------+----------+----------+---------+----------+---------+
122 * | Rising | High -> | Down | - | Up | - |
123 * | edge | Low -> | Up | - | Down | - |
124 * +---------+----------+----------+---------+----------+---------+
125 * | Falling | High -> | - | Up | - | Down |
126 * | edge | Low -> | - | Down | - | Up |
127 * +---------+----------+----------+---------+----------+---------+
128 * | Both | High -> | Down | Up | Up | Down |
129 * | edges | Low -> | Up | Down | Down | Up |
130 * +---------+----------+----------+---------+----------+---------+
150 /* Index must match with stm32_lptim_cnt_polarity[] (priv->polarity) */
160 struct stm32_lptim_cnt *const priv = counter->priv; in stm32_lptim_cnt_read()
164 ret = regmap_read(priv->regmap, STM32_LPTIM_CNT, &cnt); in stm32_lptim_cnt_read()
177 struct stm32_lptim_cnt *const priv = counter->priv; in stm32_lptim_cnt_function_get()
179 if (!priv->quadrature_mode) { in stm32_lptim_cnt_function_get()
184 if (priv->polarity == STM32_LPTIM_SYNAPSE_ACTION_BOTH_EDGES) { in stm32_lptim_cnt_function_get()
189 return -EINVAL; in stm32_lptim_cnt_function_get()
196 struct stm32_lptim_cnt *const priv = counter->priv; in stm32_lptim_cnt_function_set()
199 return -EBUSY; in stm32_lptim_cnt_function_set()
203 priv->quadrature_mode = 0; in stm32_lptim_cnt_function_set()
206 priv->quadrature_mode = 1; in stm32_lptim_cnt_function_set()
207 priv->polarity = STM32_LPTIM_SYNAPSE_ACTION_BOTH_EDGES; in stm32_lptim_cnt_function_set()
211 return -EINVAL; in stm32_lptim_cnt_function_set()
219 struct stm32_lptim_cnt *const priv = counter->priv; in stm32_lptim_cnt_enable_read()
234 struct stm32_lptim_cnt *const priv = counter->priv; in stm32_lptim_cnt_enable_write()
247 return -EBUSY; in stm32_lptim_cnt_enable_write()
264 struct stm32_lptim_cnt *const priv = counter->priv; in stm32_lptim_cnt_ceiling_read()
266 return snprintf(buf, PAGE_SIZE, "%u\n", priv->ceiling); in stm32_lptim_cnt_ceiling_read()
274 struct stm32_lptim_cnt *const priv = counter->priv; in stm32_lptim_cnt_ceiling_write()
279 return -EBUSY; in stm32_lptim_cnt_ceiling_write()
286 return -ERANGE; in stm32_lptim_cnt_ceiling_write()
288 priv->ceiling = ceiling; in stm32_lptim_cnt_ceiling_write()
311 struct stm32_lptim_cnt *const priv = counter->priv; in stm32_lptim_cnt_action_get()
321 /* LP Timer acts as up-counter on input 1 */ in stm32_lptim_cnt_action_get()
322 if (synapse->signal->id == count->synapses[0].signal->id) in stm32_lptim_cnt_action_get()
323 *action = priv->polarity; in stm32_lptim_cnt_action_get()
328 *action = priv->polarity; in stm32_lptim_cnt_action_get()
332 return -EINVAL; in stm32_lptim_cnt_action_get()
341 struct stm32_lptim_cnt *const priv = counter->priv; in stm32_lptim_cnt_action_set()
346 return -EBUSY; in stm32_lptim_cnt_action_set()
354 && synapse->signal->id == count->synapses[0].signal->id) { in stm32_lptim_cnt_action_set()
359 priv->polarity = action; in stm32_lptim_cnt_action_set()
364 return -EINVAL; in stm32_lptim_cnt_action_set()
377 .id = 0,
381 .id = 1,
390 .signal = &stm32_lptim_cnt_signals[0]
395 .signal = &stm32_lptim_cnt_signals[1]
401 .id = 0,
413 .id = 0,
425 struct stm32_lptimer *ddata = dev_get_drvdata(pdev->dev.parent); in stm32_lptim_cnt_probe()
429 return -EINVAL; in stm32_lptim_cnt_probe()
431 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); in stm32_lptim_cnt_probe()
433 return -ENOMEM; in stm32_lptim_cnt_probe()
435 priv->dev = &pdev->dev; in stm32_lptim_cnt_probe()
436 priv->regmap = ddata->regmap; in stm32_lptim_cnt_probe()
437 priv->clk = ddata->clk; in stm32_lptim_cnt_probe()
438 priv->ceiling = STM32_LPTIM_MAX_ARR; in stm32_lptim_cnt_probe()
441 priv->counter.name = dev_name(&pdev->dev); in stm32_lptim_cnt_probe()
442 priv->counter.parent = &pdev->dev; in stm32_lptim_cnt_probe()
443 priv->counter.ops = &stm32_lptim_cnt_ops; in stm32_lptim_cnt_probe()
444 if (ddata->has_encoder) { in stm32_lptim_cnt_probe()
445 priv->counter.counts = &stm32_lptim_enc_counts; in stm32_lptim_cnt_probe()
446 priv->counter.num_signals = ARRAY_SIZE(stm32_lptim_cnt_signals); in stm32_lptim_cnt_probe()
448 priv->counter.counts = &stm32_lptim_in1_counts; in stm32_lptim_cnt_probe()
449 priv->counter.num_signals = 1; in stm32_lptim_cnt_probe()
451 priv->counter.num_counts = 1; in stm32_lptim_cnt_probe()
452 priv->counter.signals = stm32_lptim_cnt_signals; in stm32_lptim_cnt_probe()
453 priv->counter.priv = priv; in stm32_lptim_cnt_probe()
457 return devm_counter_register(&pdev->dev, &priv->counter); in stm32_lptim_cnt_probe()
467 if (priv->enabled) { in stm32_lptim_cnt_suspend()
477 priv->enabled = true; in stm32_lptim_cnt_suspend()
492 if (priv->enabled) { in stm32_lptim_cnt_resume()
493 priv->enabled = false; in stm32_lptim_cnt_resume()
511 { .compatible = "st,stm32-lptimer-counter", },
519 .name = "stm32-lptimer-counter",
527 MODULE_ALIAS("platform:stm32-lptimer-counter");