dt-bindings: pinctrl: k3: Synchronize with v5.14 kernel
[platform/kernel/u-boot.git] / drivers / misc / irq_sandbox.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Sandbox driver for interrupts
4  *
5  * Copyright 2019 Google LLC
6  */
7
8 #include <common.h>
9 #include <dm.h>
10 #include <irq.h>
11 #include <acpi/acpi_device.h>
12 #include <asm/irq.h>
13 #include <asm/test.h>
14
15 static int sandbox_set_polarity(struct udevice *dev, uint irq, bool active_low)
16 {
17         if (irq > 10)
18                 return -EINVAL;
19
20         return 0;
21 }
22
23 static int sandbox_route_pmc_gpio_gpe(struct udevice *dev, uint pmc_gpe_num)
24 {
25         if (pmc_gpe_num > 10)
26                 return -ENOENT;
27
28         return pmc_gpe_num + 1;
29 }
30
31 static int sandbox_snapshot_polarities(struct udevice *dev)
32 {
33         return 0;
34 }
35
36 static int sandbox_restore_polarities(struct udevice *dev)
37 {
38         return 0;
39 }
40
41 static int sandbox_irq_read_and_clear(struct irq *irq)
42 {
43         struct sandbox_irq_priv *priv = dev_get_priv(irq->dev);
44
45         if (irq->id != SANDBOX_IRQN_PEND)
46                 return -EINVAL;
47         priv->count++;
48         if (priv->pending) {
49                 priv->pending = false;
50                 return 1;
51         }
52
53         if (!(priv->count % 3))
54                 priv->pending = true;
55
56         return 0;
57 }
58
59 static int sandbox_irq_of_xlate(struct irq *irq,
60                                 struct ofnode_phandle_args *args)
61 {
62         irq->id = args->args[0];
63
64         return 0;
65 }
66
67 static __maybe_unused int sandbox_get_acpi(const struct irq *irq,
68                                            struct acpi_irq *acpi_irq)
69 {
70         acpi_irq->pin = irq->id;
71         acpi_irq->mode = ACPI_IRQ_LEVEL_TRIGGERED;
72         acpi_irq->polarity = ACPI_IRQ_ACTIVE_HIGH;
73         acpi_irq->shared = ACPI_IRQ_SHARED;
74         acpi_irq->wake = ACPI_IRQ_WAKE;
75
76         return 0;
77 }
78
79 static const struct irq_ops sandbox_irq_ops = {
80         .route_pmc_gpio_gpe     = sandbox_route_pmc_gpio_gpe,
81         .set_polarity           = sandbox_set_polarity,
82         .snapshot_polarities    = sandbox_snapshot_polarities,
83         .restore_polarities     = sandbox_restore_polarities,
84         .read_and_clear         = sandbox_irq_read_and_clear,
85         .of_xlate               = sandbox_irq_of_xlate,
86 #if CONFIG_IS_ENABLED(ACPIGEN)
87         .get_acpi               = sandbox_get_acpi,
88 #endif
89 };
90
91 static const struct udevice_id sandbox_irq_ids[] = {
92         { .compatible = "sandbox,irq", SANDBOX_IRQT_BASE },
93         { }
94 };
95
96 U_BOOT_DRIVER(sandbox_irq) = {
97         .name           = "sandbox_irq",
98         .id             = UCLASS_IRQ,
99         .of_match       = sandbox_irq_ids,
100         .ops            = &sandbox_irq_ops,
101         .priv_auto      = sizeof(struct sandbox_irq_priv),
102         DM_HEADER(<asm/irq.h>)
103 };