1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2019 Google, LLC
4 * Written by Simon Glass <sjg@chromium.org>
7 #define LOG_CATEGORY UCLASS_IRQ
11 #include <dt-structs.h>
13 #include <dm/device-internal.h>
15 int irq_route_pmc_gpio_gpe(struct udevice *dev, uint pmc_gpe_num)
17 const struct irq_ops *ops = irq_get_ops(dev);
19 if (!ops->route_pmc_gpio_gpe)
22 return ops->route_pmc_gpio_gpe(dev, pmc_gpe_num);
25 int irq_set_polarity(struct udevice *dev, uint irq, bool active_low)
27 const struct irq_ops *ops = irq_get_ops(dev);
29 if (!ops->set_polarity)
32 return ops->set_polarity(dev, irq, active_low);
35 int irq_snapshot_polarities(struct udevice *dev)
37 const struct irq_ops *ops = irq_get_ops(dev);
39 if (!ops->snapshot_polarities)
42 return ops->snapshot_polarities(dev);
45 int irq_restore_polarities(struct udevice *dev)
47 const struct irq_ops *ops = irq_get_ops(dev);
49 if (!ops->restore_polarities)
52 return ops->restore_polarities(dev);
55 int irq_read_and_clear(struct irq *irq)
57 const struct irq_ops *ops = irq_get_ops(irq->dev);
59 if (!ops->read_and_clear)
62 return ops->read_and_clear(irq);
65 #if CONFIG_IS_ENABLED(OF_PLATDATA)
66 int irq_get_by_index_platdata(struct udevice *dev, int index,
67 struct phandle_1_arg *cells, struct irq *irq)
73 ret = uclass_get_device(UCLASS_IRQ, 0, &irq->dev);
76 irq->id = cells[0].arg[0];
81 static int irq_of_xlate_default(struct irq *irq,
82 struct ofnode_phandle_args *args)
84 log_debug("(irq=%p)\n", irq);
86 if (args->args_count > 1) {
87 log_debug("Invaild args_count: %d\n", args->args_count);
92 irq->id = args->args[0];
99 static int irq_get_by_index_tail(int ret, ofnode node,
100 struct ofnode_phandle_args *args,
101 const char *list_name, int index,
104 struct udevice *dev_irq;
105 const struct irq_ops *ops;
112 ret = uclass_get_device_by_ofnode(UCLASS_IRQ, args->node, &dev_irq);
114 log_debug("uclass_get_device_by_ofnode failed: err=%d\n", ret);
120 ops = irq_get_ops(dev_irq);
123 ret = ops->of_xlate(irq, args);
125 ret = irq_of_xlate_default(irq, args);
127 log_debug("of_xlate() failed: %d\n", ret);
131 return irq_request(dev_irq, irq);
133 log_debug("Node '%s', property '%s', failed to request IRQ index %d: %d\n",
134 ofnode_get_name(node), list_name, index, ret);
138 int irq_get_by_index(struct udevice *dev, int index, struct irq *irq)
140 struct ofnode_phandle_args args;
143 ret = dev_read_phandle_with_args(dev, "interrupts-extended",
144 "#interrupt-cells", 0, index, &args);
146 return irq_get_by_index_tail(ret, dev_ofnode(dev), &args,
147 "interrupts-extended", index > 0, irq);
149 #endif /* OF_PLATDATA */
151 int irq_request(struct udevice *dev, struct irq *irq)
153 const struct irq_ops *ops;
155 log_debug("(dev=%p, irq=%p)\n", dev, irq);
158 ops = irq_get_ops(dev);
165 return ops->request(irq);
168 int irq_first_device_type(enum irq_dev_t type, struct udevice **devp)
172 ret = uclass_first_device_drvdata(UCLASS_IRQ, type, devp);
174 return log_msg_ret("find", ret);
179 UCLASS_DRIVER(irq) = {