Simon Glass | fbb0efd | 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 | |
| 8 | #include <common.h> |
| 9 | #include <dm.h> |
| 10 | #include <irq.h> |
Simon Glass | f495513 | 2020-07-07 13:11:41 -0600 | [diff] [blame] | 11 | #include <acpi/acpi_device.h> |
Simon Glass | 3e57ad9 | 2021-08-07 07:24:11 -0600 | [diff] [blame] | 12 | #include <asm/irq.h> |
Simon Glass | 0255435 | 2020-02-06 09:55:00 -0700 | [diff] [blame] | 13 | #include <asm/test.h> |
| 14 | |
Simon Glass | fbb0efd | 2019-12-06 21:41:59 -0700 | [diff] [blame] | 15 | static 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 | |
| 23 | static 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 | |
| 31 | static int sandbox_snapshot_polarities(struct udevice *dev) |
| 32 | { |
| 33 | return 0; |
| 34 | } |
| 35 | |
| 36 | static int sandbox_restore_polarities(struct udevice *dev) |
| 37 | { |
| 38 | return 0; |
| 39 | } |
| 40 | |
Simon Glass | 0255435 | 2020-02-06 09:55:00 -0700 | [diff] [blame] | 41 | static 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 | |
| 59 | static 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 Glass | f495513 | 2020-07-07 13:11:41 -0600 | [diff] [blame] | 67 | static __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 Glass | fbb0efd | 2019-12-06 21:41:59 -0700 | [diff] [blame] | 79 | static 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 Glass | 0255435 | 2020-02-06 09:55:00 -0700 | [diff] [blame] | 84 | .read_and_clear = sandbox_irq_read_and_clear, |
| 85 | .of_xlate = sandbox_irq_of_xlate, |
Simon Glass | f495513 | 2020-07-07 13:11:41 -0600 | [diff] [blame] | 86 | #if CONFIG_IS_ENABLED(ACPIGEN) |
| 87 | .get_acpi = sandbox_get_acpi, |
| 88 | #endif |
Simon Glass | fbb0efd | 2019-12-06 21:41:59 -0700 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | static const struct udevice_id sandbox_irq_ids[] = { |
Simon Glass | ba87607 | 2020-02-06 09:54:57 -0700 | [diff] [blame] | 92 | { .compatible = "sandbox,irq", SANDBOX_IRQT_BASE }, |
Simon Glass | fbb0efd | 2019-12-06 21:41:59 -0700 | [diff] [blame] | 93 | { } |
| 94 | }; |
| 95 | |
Simon Glass | 3e57ad9 | 2021-08-07 07:24:11 -0600 | [diff] [blame] | 96 | U_BOOT_DRIVER(sandbox_irq) = { |
Simon Glass | fbb0efd | 2019-12-06 21:41:59 -0700 | [diff] [blame] | 97 | .name = "sandbox_irq", |
| 98 | .id = UCLASS_IRQ, |
| 99 | .of_match = sandbox_irq_ids, |
| 100 | .ops = &sandbox_irq_ops, |
Simon Glass | 41575d8 | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 101 | .priv_auto = sizeof(struct sandbox_irq_priv), |
Simon Glass | 3e57ad9 | 2021-08-07 07:24:11 -0600 | [diff] [blame] | 102 | DM_HEADER(<asm/irq.h>) |
Simon Glass | fbb0efd | 2019-12-06 21:41:59 -0700 | [diff] [blame] | 103 | }; |