2019-12-07 04:41:59 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/*
|
|
|
|
* Sandbox driver for interrupts
|
|
|
|
*
|
|
|
|
* Copyright 2019 Google LLC
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <irq.h>
|
2020-07-07 19:11:41 +00:00
|
|
|
#include <acpi/acpi_device.h>
|
2021-08-07 13:24:11 +00:00
|
|
|
#include <asm/irq.h>
|
2020-02-06 16:55:00 +00:00
|
|
|
#include <asm/test.h>
|
|
|
|
|
2019-12-07 04:41:59 +00:00
|
|
|
static int sandbox_set_polarity(struct udevice *dev, uint irq, bool active_low)
|
|
|
|
{
|
|
|
|
if (irq > 10)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sandbox_route_pmc_gpio_gpe(struct udevice *dev, uint pmc_gpe_num)
|
|
|
|
{
|
|
|
|
if (pmc_gpe_num > 10)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
return pmc_gpe_num + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sandbox_snapshot_polarities(struct udevice *dev)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sandbox_restore_polarities(struct udevice *dev)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-02-06 16:55:00 +00:00
|
|
|
static int sandbox_irq_read_and_clear(struct irq *irq)
|
|
|
|
{
|
|
|
|
struct sandbox_irq_priv *priv = dev_get_priv(irq->dev);
|
|
|
|
|
|
|
|
if (irq->id != SANDBOX_IRQN_PEND)
|
|
|
|
return -EINVAL;
|
|
|
|
priv->count++;
|
|
|
|
if (priv->pending) {
|
|
|
|
priv->pending = false;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(priv->count % 3))
|
|
|
|
priv->pending = true;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sandbox_irq_of_xlate(struct irq *irq,
|
|
|
|
struct ofnode_phandle_args *args)
|
|
|
|
{
|
|
|
|
irq->id = args->args[0];
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-07 19:11:41 +00:00
|
|
|
static __maybe_unused int sandbox_get_acpi(const struct irq *irq,
|
|
|
|
struct acpi_irq *acpi_irq)
|
|
|
|
{
|
|
|
|
acpi_irq->pin = irq->id;
|
|
|
|
acpi_irq->mode = ACPI_IRQ_LEVEL_TRIGGERED;
|
|
|
|
acpi_irq->polarity = ACPI_IRQ_ACTIVE_HIGH;
|
|
|
|
acpi_irq->shared = ACPI_IRQ_SHARED;
|
|
|
|
acpi_irq->wake = ACPI_IRQ_WAKE;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-12-07 04:41:59 +00:00
|
|
|
static const struct irq_ops sandbox_irq_ops = {
|
|
|
|
.route_pmc_gpio_gpe = sandbox_route_pmc_gpio_gpe,
|
|
|
|
.set_polarity = sandbox_set_polarity,
|
|
|
|
.snapshot_polarities = sandbox_snapshot_polarities,
|
|
|
|
.restore_polarities = sandbox_restore_polarities,
|
2020-02-06 16:55:00 +00:00
|
|
|
.read_and_clear = sandbox_irq_read_and_clear,
|
|
|
|
.of_xlate = sandbox_irq_of_xlate,
|
2020-07-07 19:11:41 +00:00
|
|
|
#if CONFIG_IS_ENABLED(ACPIGEN)
|
|
|
|
.get_acpi = sandbox_get_acpi,
|
|
|
|
#endif
|
2019-12-07 04:41:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct udevice_id sandbox_irq_ids[] = {
|
2020-02-06 16:54:57 +00:00
|
|
|
{ .compatible = "sandbox,irq", SANDBOX_IRQT_BASE },
|
2019-12-07 04:41:59 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2021-08-07 13:24:11 +00:00
|
|
|
U_BOOT_DRIVER(sandbox_irq) = {
|
2019-12-07 04:41:59 +00:00
|
|
|
.name = "sandbox_irq",
|
|
|
|
.id = UCLASS_IRQ,
|
|
|
|
.of_match = sandbox_irq_ids,
|
|
|
|
.ops = &sandbox_irq_ops,
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct sandbox_irq_priv),
|
2021-08-07 13:24:11 +00:00
|
|
|
DM_HEADER(<asm/irq.h>)
|
2019-12-07 04:41:59 +00:00
|
|
|
};
|