]> Git Repo - J-u-boot.git/blob - drivers/misc/irq_sandbox.c
Merge branch 'next-clk-sync' of https://source.denx.de/u-boot/custodians/u-boot-sh
[J-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 <dm.h>
9 #include <irq.h>
10 #include <acpi/acpi_device.h>
11 #include <asm/irq.h>
12 #include <asm/test.h>
13
14 static int sandbox_set_polarity(struct udevice *dev, uint irq, bool active_low)
15 {
16         if (irq > 10)
17                 return -EINVAL;
18
19         return 0;
20 }
21
22 static int sandbox_route_pmc_gpio_gpe(struct udevice *dev, uint pmc_gpe_num)
23 {
24         if (pmc_gpe_num > 10)
25                 return -ENOENT;
26
27         return pmc_gpe_num + 1;
28 }
29
30 static int sandbox_snapshot_polarities(struct udevice *dev)
31 {
32         return 0;
33 }
34
35 static int sandbox_restore_polarities(struct udevice *dev)
36 {
37         return 0;
38 }
39
40 static int sandbox_irq_read_and_clear(struct irq *irq)
41 {
42         struct sandbox_irq_priv *priv = dev_get_priv(irq->dev);
43
44         if (irq->id != SANDBOX_IRQN_PEND)
45                 return -EINVAL;
46         priv->count++;
47         if (priv->pending) {
48                 priv->pending = false;
49                 return 1;
50         }
51
52         if (!(priv->count % 3))
53                 priv->pending = true;
54
55         return 0;
56 }
57
58 static int sandbox_irq_of_xlate(struct irq *irq,
59                                 struct ofnode_phandle_args *args)
60 {
61         irq->id = args->args[0];
62
63         return 0;
64 }
65
66 static __maybe_unused int sandbox_get_acpi(const struct irq *irq,
67                                            struct acpi_irq *acpi_irq)
68 {
69         acpi_irq->pin = irq->id;
70         acpi_irq->mode = ACPI_IRQ_LEVEL_TRIGGERED;
71         acpi_irq->polarity = ACPI_IRQ_ACTIVE_HIGH;
72         acpi_irq->shared = ACPI_IRQ_SHARED;
73         acpi_irq->wake = ACPI_IRQ_WAKE;
74
75         return 0;
76 }
77
78 static const struct irq_ops sandbox_irq_ops = {
79         .route_pmc_gpio_gpe     = sandbox_route_pmc_gpio_gpe,
80         .set_polarity           = sandbox_set_polarity,
81         .snapshot_polarities    = sandbox_snapshot_polarities,
82         .restore_polarities     = sandbox_restore_polarities,
83         .read_and_clear         = sandbox_irq_read_and_clear,
84         .of_xlate               = sandbox_irq_of_xlate,
85 #if CONFIG_IS_ENABLED(ACPIGEN)
86         .get_acpi               = sandbox_get_acpi,
87 #endif
88 };
89
90 static const struct udevice_id sandbox_irq_ids[] = {
91         { .compatible = "sandbox,irq", SANDBOX_IRQT_BASE },
92         { }
93 };
94
95 U_BOOT_DRIVER(sandbox_irq) = {
96         .name           = "sandbox_irq",
97         .id             = UCLASS_IRQ,
98         .of_match       = sandbox_irq_ids,
99         .ops            = &sandbox_irq_ops,
100         .priv_auto      = sizeof(struct sandbox_irq_priv),
101         DM_HEADER(<asm/irq.h>)
102 };
This page took 0.031074 seconds and 4 git commands to generate.