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>
14 #include <dm/device-internal.h>
16 int irq_route_pmc_gpio_gpe(struct udevice *dev, uint pmc_gpe_num)
18 const struct irq_ops *ops = irq_get_ops(dev);
20 if (!ops->route_pmc_gpio_gpe)
23 return ops->route_pmc_gpio_gpe(dev, pmc_gpe_num);
26 int irq_set_polarity(struct udevice *dev, uint irq, bool active_low)
28 const struct irq_ops *ops = irq_get_ops(dev);
30 if (!ops->set_polarity)
33 return ops->set_polarity(dev, irq, active_low);
36 int irq_snapshot_polarities(struct udevice *dev)
38 const struct irq_ops *ops = irq_get_ops(dev);
40 if (!ops->snapshot_polarities)
43 return ops->snapshot_polarities(dev);
46 int irq_restore_polarities(struct udevice *dev)
48 const struct irq_ops *ops = irq_get_ops(dev);
50 if (!ops->restore_polarities)
53 return ops->restore_polarities(dev);
56 int irq_read_and_clear(struct irq *irq)
58 const struct irq_ops *ops = irq_get_ops(irq->dev);
60 if (!ops->read_and_clear)
63 return ops->read_and_clear(irq);
66 #if CONFIG_IS_ENABLED(OF_PLATDATA)
67 int irq_get_by_index_platdata(struct udevice *dev, int index,
68 struct phandle_1_arg *cells, struct irq *irq)
74 ret = uclass_get_device(UCLASS_IRQ, 0, &irq->dev);
77 irq->id = cells[0].arg[0];
82 static int irq_of_xlate_default(struct irq *irq,
83 struct ofnode_phandle_args *args)
85 log_debug("(irq=%p)\n", irq);
87 if (args->args_count > 1) {
88 log_debug("Invaild args_count: %d\n", args->args_count);
93 irq->id = args->args[0];
100 static int irq_get_by_index_tail(int ret, ofnode node,
101 struct ofnode_phandle_args *args,
102 const char *list_name, int index,
105 struct udevice *dev_irq;
106 const struct irq_ops *ops;
113 ret = uclass_get_device_by_ofnode(UCLASS_IRQ, args->node, &dev_irq);
115 log_debug("uclass_get_device_by_ofnode failed: err=%d\n", ret);
121 ops = irq_get_ops(dev_irq);
124 ret = ops->of_xlate(irq, args);
126 ret = irq_of_xlate_default(irq, args);
128 log_debug("of_xlate() failed: %d\n", ret);
132 return irq_request(dev_irq, irq);
134 log_debug("Node '%s', property '%s', failed to request IRQ index %d: %d\n",
135 ofnode_get_name(node), list_name, index, ret);
139 int irq_get_by_index(struct udevice *dev, int index, struct irq *irq)
141 struct ofnode_phandle_args args;
144 ret = dev_read_phandle_with_args(dev, "interrupts-extended",
145 "#interrupt-cells", 0, index, &args);
147 return irq_get_by_index_tail(ret, dev_ofnode(dev), &args,
148 "interrupts-extended", index > 0, irq);
150 #endif /* OF_PLATDATA */
152 int irq_request(struct udevice *dev, struct irq *irq)
154 const struct irq_ops *ops;
156 log_debug("(dev=%p, irq=%p)\n", dev, irq);
159 ops = irq_get_ops(dev);
166 return ops->request(irq);
169 int irq_first_device_type(enum irq_dev_t type, struct udevice **devp)
173 ret = uclass_first_device_drvdata(UCLASS_IRQ, type, devp);
175 return log_msg_ret("find", ret);
180 UCLASS_DRIVER(irq) = {