c52c813ff370b702cc631326f5d89028394cce12
[oweals/u-boot.git] / drivers / misc / irq-uclass.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright 2019 Google, LLC
4  * Written by Simon Glass <sjg@chromium.org>
5  */
6
7 #include <common.h>
8 #include <dm.h>
9 #include <irq.h>
10 #include <dm/device-internal.h>
11
12 int irq_route_pmc_gpio_gpe(struct udevice *dev, uint pmc_gpe_num)
13 {
14         const struct irq_ops *ops = irq_get_ops(dev);
15
16         if (!ops->route_pmc_gpio_gpe)
17                 return -ENOSYS;
18
19         return ops->route_pmc_gpio_gpe(dev, pmc_gpe_num);
20 }
21
22 int irq_set_polarity(struct udevice *dev, uint irq, bool active_low)
23 {
24         const struct irq_ops *ops = irq_get_ops(dev);
25
26         if (!ops->set_polarity)
27                 return -ENOSYS;
28
29         return ops->set_polarity(dev, irq, active_low);
30 }
31
32 int irq_snapshot_polarities(struct udevice *dev)
33 {
34         const struct irq_ops *ops = irq_get_ops(dev);
35
36         if (!ops->snapshot_polarities)
37                 return -ENOSYS;
38
39         return ops->snapshot_polarities(dev);
40 }
41
42 int irq_restore_polarities(struct udevice *dev)
43 {
44         const struct irq_ops *ops = irq_get_ops(dev);
45
46         if (!ops->restore_polarities)
47                 return -ENOSYS;
48
49         return ops->restore_polarities(dev);
50 }
51
52 int irq_first_device_type(enum irq_dev_t type, struct udevice **devp)
53 {
54         int ret;
55
56         ret = uclass_first_device_drvdata(UCLASS_IRQ, type, devp);
57         if (ret)
58                 return log_msg_ret("find", ret);
59
60         return 0;
61 }
62
63 UCLASS_DRIVER(irq) = {
64         .id             = UCLASS_IRQ,
65         .name           = "irq",
66 };