Lines Matching +full:irq +full:- +full:signals

1 // SPDX-License-Identifier: GPL-2.0
9 #include <linux/irq.h>
15 #define INTERRUPT_CNT_NAME "interrupt-cnt"
20 int irq; member
22 struct counter_signal signals; member
27 static irqreturn_t interrupt_cnt_isr(int irq, void *dev_id) in interrupt_cnt_isr() argument
32 atomic_inc(&priv->count); in interrupt_cnt_isr()
44 *enable = priv->enabled; in interrupt_cnt_enable_read()
54 if (priv->enabled == enable) in interrupt_cnt_enable_write()
58 priv->enabled = true; in interrupt_cnt_enable_write()
59 enable_irq(priv->irq); in interrupt_cnt_enable_write()
61 disable_irq(priv->irq); in interrupt_cnt_enable_write()
62 priv->enabled = false; in interrupt_cnt_enable_write()
92 *val = atomic_read(&priv->count); in interrupt_cnt_read()
102 if (val != (typeof(priv->count.counter))val) in interrupt_cnt_write()
103 return -ERANGE; in interrupt_cnt_write()
105 atomic_set(&priv->count, val); in interrupt_cnt_write()
130 if (!priv->gpio) in interrupt_cnt_signal_read()
131 return -EINVAL; in interrupt_cnt_signal_read()
133 ret = gpiod_get_value(priv->gpio); in interrupt_cnt_signal_read()
145 if (watch->channel != 0 || in interrupt_cnt_watch_validate()
146 watch->event != COUNTER_EVENT_CHANGE_OF_STATE) in interrupt_cnt_watch_validate()
147 return -EINVAL; in interrupt_cnt_watch_validate()
163 struct device *dev = &pdev->dev; in interrupt_cnt_probe()
170 return -ENOMEM; in interrupt_cnt_probe()
173 priv->irq = platform_get_irq_optional(pdev, 0); in interrupt_cnt_probe()
174 if (priv->irq == -ENXIO) in interrupt_cnt_probe()
175 priv->irq = 0; in interrupt_cnt_probe()
176 else if (priv->irq < 0) in interrupt_cnt_probe()
177 return dev_err_probe(dev, priv->irq, "failed to get IRQ\n"); in interrupt_cnt_probe()
179 priv->gpio = devm_gpiod_get_optional(dev, NULL, GPIOD_IN); in interrupt_cnt_probe()
180 if (IS_ERR(priv->gpio)) in interrupt_cnt_probe()
181 return dev_err_probe(dev, PTR_ERR(priv->gpio), "failed to get GPIO\n"); in interrupt_cnt_probe()
183 if (!priv->irq && !priv->gpio) { in interrupt_cnt_probe()
184 dev_err(dev, "IRQ and GPIO are not found. At least one source should be provided\n"); in interrupt_cnt_probe()
185 return -ENODEV; in interrupt_cnt_probe()
188 if (!priv->irq) { in interrupt_cnt_probe()
189 int irq = gpiod_to_irq(priv->gpio); in interrupt_cnt_probe() local
191 if (irq < 0) in interrupt_cnt_probe()
192 return dev_err_probe(dev, irq, "failed to get IRQ from GPIO\n"); in interrupt_cnt_probe()
194 priv->irq = irq; in interrupt_cnt_probe()
197 priv->signals.name = devm_kasprintf(dev, GFP_KERNEL, "IRQ %d", in interrupt_cnt_probe()
198 priv->irq); in interrupt_cnt_probe()
199 if (!priv->signals.name) in interrupt_cnt_probe()
200 return -ENOMEM; in interrupt_cnt_probe()
202 counter->signals = &priv->signals; in interrupt_cnt_probe()
203 counter->num_signals = 1; in interrupt_cnt_probe()
205 priv->synapses.actions_list = interrupt_cnt_synapse_actions; in interrupt_cnt_probe()
206 priv->synapses.num_actions = ARRAY_SIZE(interrupt_cnt_synapse_actions); in interrupt_cnt_probe()
207 priv->synapses.signal = &priv->signals; in interrupt_cnt_probe()
209 priv->cnts.name = "Channel 0 Count"; in interrupt_cnt_probe()
210 priv->cnts.functions_list = interrupt_cnt_functions; in interrupt_cnt_probe()
211 priv->cnts.num_functions = ARRAY_SIZE(interrupt_cnt_functions); in interrupt_cnt_probe()
212 priv->cnts.synapses = &priv->synapses; in interrupt_cnt_probe()
213 priv->cnts.num_synapses = 1; in interrupt_cnt_probe()
214 priv->cnts.ext = interrupt_cnt_ext; in interrupt_cnt_probe()
215 priv->cnts.num_ext = ARRAY_SIZE(interrupt_cnt_ext); in interrupt_cnt_probe()
217 counter->name = dev_name(dev); in interrupt_cnt_probe()
218 counter->parent = dev; in interrupt_cnt_probe()
219 counter->ops = &interrupt_cnt_ops; in interrupt_cnt_probe()
220 counter->counts = &priv->cnts; in interrupt_cnt_probe()
221 counter->num_counts = 1; in interrupt_cnt_probe()
223 irq_set_status_flags(priv->irq, IRQ_NOAUTOEN); in interrupt_cnt_probe()
224 ret = devm_request_irq(dev, priv->irq, interrupt_cnt_isr, in interrupt_cnt_probe()
238 { .compatible = "interrupt-counter", },
252 MODULE_ALIAS("platform:interrupt-counter");