u-boot-brain/drivers/misc/irq_sandbox.c
Simon Glass ba87607971 dm: irq: Add support for interrupt controller types
There can be different types of interrupt controllers in a system and some
drivers may need to distinguish between these. In general this can be
handled using the device tree by adding the interrupt information to
device nodes.

However on x86 devices we have interrupt controllers which are not tied
to any particular device and not really used in U-Boot. These still need
to be inited, so a convenient method is to give each controller a type
and allow a particular controller type to be probed.

Add support for this in sandbox along with a test.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
[bmeng: remove the new bland line at EOF of test/dm/irq.c]
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
2020-02-07 22:44:59 +08:00

56 lines
1.1 KiB
C

// SPDX-License-Identifier: GPL-2.0
/*
* Sandbox driver for interrupts
*
* Copyright 2019 Google LLC
*/
#include <common.h>
#include <dm.h>
#include <irq.h>
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;
}
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,
};
static const struct udevice_id sandbox_irq_ids[] = {
{ .compatible = "sandbox,irq", SANDBOX_IRQT_BASE },
{ }
};
U_BOOT_DRIVER(sandbox_irq_drv) = {
.name = "sandbox_irq",
.id = UCLASS_IRQ,
.of_match = sandbox_irq_ids,
.ops = &sandbox_irq_ops,
};