blob: 55005455c09144ea572e23b417124185b88924b2 [file] [log] [blame]
Simon Glasse85cbe82020-02-06 09:55:01 -07001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2019 Google, LLC
4 * Written by Simon Glass <sjg@chromium.org>
5 */
6
7#include <common.h>
8#include <dm.h>
9#include <irq.h>
10#include <asm/io.h>
11
12/**
13 * struct acpi_gpe_priv - private driver information
14 *
15 * @acpi_base: Base I/O address of ACPI registers
16 */
17struct acpi_gpe_priv {
18 ulong acpi_base;
19};
20
21#define GPE0_STS(x) (0x20 + ((x) * 4))
22
23static int acpi_gpe_read_and_clear(struct irq *irq)
24{
25 struct acpi_gpe_priv *priv = dev_get_priv(irq->dev);
26 u32 mask, sts;
27 ulong start;
28 int ret = 0;
29 int bank;
30
31 bank = irq->id / 32;
32 mask = 1 << (irq->id % 32);
33
34 /* Wait up to 1ms for GPE status to clear */
35 start = get_timer(0);
36 do {
37 if (get_timer(start) > 1)
38 return ret;
39
40 sts = inl(priv->acpi_base + GPE0_STS(bank));
41 if (sts & mask) {
42 outl(mask, priv->acpi_base + GPE0_STS(bank));
43 ret = 1;
44 }
45 } while (sts & mask);
46
47 return ret;
48}
49
50static int acpi_gpe_ofdata_to_platdata(struct udevice *dev)
51{
52 struct acpi_gpe_priv *priv = dev_get_priv(dev);
53
54 priv->acpi_base = dev_read_addr(dev);
55 if (!priv->acpi_base || priv->acpi_base == FDT_ADDR_T_NONE)
56 return log_msg_ret("acpi_base", -EINVAL);
57
58 return 0;
59}
60
61static int acpi_gpe_of_xlate(struct irq *irq, struct ofnode_phandle_args *args)
62{
63 irq->id = args->args[0];
64
65 return 0;
66}
67
68static const struct irq_ops acpi_gpe_ops = {
69 .read_and_clear = acpi_gpe_read_and_clear,
70 .of_xlate = acpi_gpe_of_xlate,
71};
72
73static const struct udevice_id acpi_gpe_ids[] = {
74 { .compatible = "intel,acpi-gpe", .data = X86_IRQT_ACPI_GPE },
75 { }
76};
77
78U_BOOT_DRIVER(acpi_gpe_drv) = {
79 .name = "acpi_gpe",
80 .id = UCLASS_IRQ,
81 .of_match = acpi_gpe_ids,
82 .ops = &acpi_gpe_ops,
83 .ofdata_to_platdata = acpi_gpe_ofdata_to_platdata,
84 .priv_auto_alloc_size = sizeof(struct acpi_gpe_priv),
85};