1 // SPDX-License-Identifier: GPL-2.0
3 * Sandbox driver for interrupts
5 * Copyright 2019 Google LLC
11 #include <acpi/acpi_device.h>
15 * struct sandbox_irq_priv - private data for this driver
17 * @count: Counts the number calls to the read_and_clear() method
18 * @pending: true if an interrupt is pending, else false
20 struct sandbox_irq_priv {
25 static int sandbox_set_polarity(struct udevice *dev, uint irq, bool active_low)
33 static int sandbox_route_pmc_gpio_gpe(struct udevice *dev, uint pmc_gpe_num)
38 return pmc_gpe_num + 1;
41 static int sandbox_snapshot_polarities(struct udevice *dev)
46 static int sandbox_restore_polarities(struct udevice *dev)
51 static int sandbox_irq_read_and_clear(struct irq *irq)
53 struct sandbox_irq_priv *priv = dev_get_priv(irq->dev);
55 if (irq->id != SANDBOX_IRQN_PEND)
59 priv->pending = false;
63 if (!(priv->count % 3))
69 static int sandbox_irq_of_xlate(struct irq *irq,
70 struct ofnode_phandle_args *args)
72 irq->id = args->args[0];
77 static __maybe_unused int sandbox_get_acpi(const struct irq *irq,
78 struct acpi_irq *acpi_irq)
80 acpi_irq->pin = irq->id;
81 acpi_irq->mode = ACPI_IRQ_LEVEL_TRIGGERED;
82 acpi_irq->polarity = ACPI_IRQ_ACTIVE_HIGH;
83 acpi_irq->shared = ACPI_IRQ_SHARED;
84 acpi_irq->wake = ACPI_IRQ_WAKE;
89 static const struct irq_ops sandbox_irq_ops = {
90 .route_pmc_gpio_gpe = sandbox_route_pmc_gpio_gpe,
91 .set_polarity = sandbox_set_polarity,
92 .snapshot_polarities = sandbox_snapshot_polarities,
93 .restore_polarities = sandbox_restore_polarities,
94 .read_and_clear = sandbox_irq_read_and_clear,
95 .of_xlate = sandbox_irq_of_xlate,
96 #if CONFIG_IS_ENABLED(ACPIGEN)
97 .get_acpi = sandbox_get_acpi,
101 static const struct udevice_id sandbox_irq_ids[] = {
102 { .compatible = "sandbox,irq", SANDBOX_IRQT_BASE },
106 U_BOOT_DRIVER(sandbox_irq_drv) = {
107 .name = "sandbox_irq",
109 .of_match = sandbox_irq_ids,
110 .ops = &sandbox_irq_ops,
111 .priv_auto_alloc_size = sizeof(struct sandbox_irq_priv),