blob: 5d176f63b5cfa7d465d7ced56d4b007a8a640854 [file] [log] [blame]
Simon Glass54028bc2019-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
Simon Glass54028bc2019-12-06 21:41:59 -07008#include <dm.h>
9#include <irq.h>
Simon Glassb24cbf42020-07-07 13:11:41 -060010#include <acpi/acpi_device.h>
Simon Glasse7995f72021-08-07 07:24:11 -060011#include <asm/irq.h>
Simon Glass515dcff2020-02-06 09:55:00 -070012#include <asm/test.h>
13
Simon Glass54028bc2019-12-06 21:41:59 -070014static 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
22static 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
30static int sandbox_snapshot_polarities(struct udevice *dev)
31{
32 return 0;
33}
34
35static int sandbox_restore_polarities(struct udevice *dev)
36{
Simon Glass515dcff2020-02-06 09:55:00 -070037 return 0;
38}
39
40static 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
58static int sandbox_irq_of_xlate(struct irq *irq,
59 struct ofnode_phandle_args *args)
60{
61 irq->id = args->args[0];
62
Simon Glass54028bc2019-12-06 21:41:59 -070063 return 0;
64}
65
Simon Glassb24cbf42020-07-07 13:11:41 -060066static __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
Simon Glass54028bc2019-12-06 21:41:59 -070078static 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,
Simon Glass515dcff2020-02-06 09:55:00 -070083 .read_and_clear = sandbox_irq_read_and_clear,
84 .of_xlate = sandbox_irq_of_xlate,
Simon Glassb24cbf42020-07-07 13:11:41 -060085#if CONFIG_IS_ENABLED(ACPIGEN)
86 .get_acpi = sandbox_get_acpi,
87#endif
Simon Glass54028bc2019-12-06 21:41:59 -070088};
89
90static const struct udevice_id sandbox_irq_ids[] = {
Simon Glassa847b272020-02-06 09:54:57 -070091 { .compatible = "sandbox,irq", SANDBOX_IRQT_BASE },
Simon Glass54028bc2019-12-06 21:41:59 -070092 { }
93};
94
Simon Glasse7995f72021-08-07 07:24:11 -060095U_BOOT_DRIVER(sandbox_irq) = {
Simon Glass54028bc2019-12-06 21:41:59 -070096 .name = "sandbox_irq",
97 .id = UCLASS_IRQ,
98 .of_match = sandbox_irq_ids,
99 .ops = &sandbox_irq_ops,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700100 .priv_auto = sizeof(struct sandbox_irq_priv),
Simon Glasse7995f72021-08-07 07:24:11 -0600101 DM_HEADER(<asm/irq.h>)
Simon Glass54028bc2019-12-06 21:41:59 -0700102};