blob: 8b5573fcaddda24ea0d7c93b8a370f7d875c5bad [file] [log] [blame]
Simon Glassfbb0efd2019-12-06 21:41:59 -07001// 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>
Simon Glassf4955132020-07-07 13:11:41 -060011#include <acpi/acpi_device.h>
Simon Glass3e57ad92021-08-07 07:24:11 -060012#include <asm/irq.h>
Simon Glass02554352020-02-06 09:55:00 -070013#include <asm/test.h>
14
Simon Glassfbb0efd2019-12-06 21:41:59 -070015static 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
23static 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
31static int sandbox_snapshot_polarities(struct udevice *dev)
32{
33 return 0;
34}
35
36static int sandbox_restore_polarities(struct udevice *dev)
37{
38 return 0;
39}
40
Simon Glass02554352020-02-06 09:55:00 -070041static 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
59static 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
Simon Glassf4955132020-07-07 13:11:41 -060067static __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
Simon Glassfbb0efd2019-12-06 21:41:59 -070079static 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,
Simon Glass02554352020-02-06 09:55:00 -070084 .read_and_clear = sandbox_irq_read_and_clear,
85 .of_xlate = sandbox_irq_of_xlate,
Simon Glassf4955132020-07-07 13:11:41 -060086#if CONFIG_IS_ENABLED(ACPIGEN)
87 .get_acpi = sandbox_get_acpi,
88#endif
Simon Glassfbb0efd2019-12-06 21:41:59 -070089};
90
91static const struct udevice_id sandbox_irq_ids[] = {
Simon Glassba876072020-02-06 09:54:57 -070092 { .compatible = "sandbox,irq", SANDBOX_IRQT_BASE },
Simon Glassfbb0efd2019-12-06 21:41:59 -070093 { }
94};
95
Simon Glass3e57ad92021-08-07 07:24:11 -060096U_BOOT_DRIVER(sandbox_irq) = {
Simon Glassfbb0efd2019-12-06 21:41:59 -070097 .name = "sandbox_irq",
98 .id = UCLASS_IRQ,
99 .of_match = sandbox_irq_ids,
100 .ops = &sandbox_irq_ops,
Simon Glass41575d82020-12-03 16:55:17 -0700101 .priv_auto = sizeof(struct sandbox_irq_priv),
Simon Glass3e57ad92021-08-07 07:24:11 -0600102 DM_HEADER(<asm/irq.h>)
Simon Glassfbb0efd2019-12-06 21:41:59 -0700103};