Simon Glass | 54028bc | 2019-12-06 21:41:59 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Sandbox driver for interrupts |
| 4 | * |
| 5 | * Copyright 2019 Google LLC |
| 6 | */ |
| 7 | |
Simon Glass | 54028bc | 2019-12-06 21:41:59 -0700 | [diff] [blame] | 8 | #include <dm.h> |
| 9 | #include <irq.h> |
Simon Glass | b24cbf4 | 2020-07-07 13:11:41 -0600 | [diff] [blame] | 10 | #include <acpi/acpi_device.h> |
Simon Glass | e7995f7 | 2021-08-07 07:24:11 -0600 | [diff] [blame] | 11 | #include <asm/irq.h> |
Simon Glass | 515dcff | 2020-02-06 09:55:00 -0700 | [diff] [blame] | 12 | #include <asm/test.h> |
| 13 | |
Simon Glass | 54028bc | 2019-12-06 21:41:59 -0700 | [diff] [blame] | 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 | { |
Simon Glass | 515dcff | 2020-02-06 09:55:00 -0700 | [diff] [blame] | 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 | |
Simon Glass | 54028bc | 2019-12-06 21:41:59 -0700 | [diff] [blame] | 63 | return 0; |
| 64 | } |
| 65 | |
Simon Glass | b24cbf4 | 2020-07-07 13:11:41 -0600 | [diff] [blame] | 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 | |
Simon Glass | 54028bc | 2019-12-06 21:41:59 -0700 | [diff] [blame] | 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, |
Simon Glass | 515dcff | 2020-02-06 09:55:00 -0700 | [diff] [blame] | 83 | .read_and_clear = sandbox_irq_read_and_clear, |
| 84 | .of_xlate = sandbox_irq_of_xlate, |
Simon Glass | b24cbf4 | 2020-07-07 13:11:41 -0600 | [diff] [blame] | 85 | #if CONFIG_IS_ENABLED(ACPIGEN) |
| 86 | .get_acpi = sandbox_get_acpi, |
| 87 | #endif |
Simon Glass | 54028bc | 2019-12-06 21:41:59 -0700 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | static const struct udevice_id sandbox_irq_ids[] = { |
Simon Glass | a847b27 | 2020-02-06 09:54:57 -0700 | [diff] [blame] | 91 | { .compatible = "sandbox,irq", SANDBOX_IRQT_BASE }, |
Simon Glass | 54028bc | 2019-12-06 21:41:59 -0700 | [diff] [blame] | 92 | { } |
| 93 | }; |
| 94 | |
Simon Glass | e7995f7 | 2021-08-07 07:24:11 -0600 | [diff] [blame] | 95 | U_BOOT_DRIVER(sandbox_irq) = { |
Simon Glass | 54028bc | 2019-12-06 21:41:59 -0700 | [diff] [blame] | 96 | .name = "sandbox_irq", |
| 97 | .id = UCLASS_IRQ, |
| 98 | .of_match = sandbox_irq_ids, |
| 99 | .ops = &sandbox_irq_ops, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 100 | .priv_auto = sizeof(struct sandbox_irq_priv), |
Simon Glass | e7995f7 | 2021-08-07 07:24:11 -0600 | [diff] [blame] | 101 | DM_HEADER(<asm/irq.h>) |
Simon Glass | 54028bc | 2019-12-06 21:41:59 -0700 | [diff] [blame] | 102 | }; |