1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2019 Google, LLC
4 * Written by Simon Glass <sjg@chromium.org>
14 * struct acpi_gpe_priv - private driver information
16 * @acpi_base: Base I/O address of ACPI registers
18 struct acpi_gpe_priv {
22 #define GPE0_STS(x) (0x20 + ((x) * 4))
24 static int acpi_gpe_read_and_clear(struct irq *irq)
26 struct acpi_gpe_priv *priv = dev_get_priv(irq->dev);
33 mask = 1 << (irq->id % 32);
35 /* Wait up to 1ms for GPE status to clear */
38 if (get_timer(start) > 1)
41 sts = inl(priv->acpi_base + GPE0_STS(bank));
43 outl(mask, priv->acpi_base + GPE0_STS(bank));
51 static int acpi_gpe_ofdata_to_platdata(struct udevice *dev)
53 struct acpi_gpe_priv *priv = dev_get_priv(dev);
55 priv->acpi_base = dev_read_addr(dev);
56 if (!priv->acpi_base || priv->acpi_base == FDT_ADDR_T_NONE)
57 return log_msg_ret("acpi_base", -EINVAL);
62 static int acpi_gpe_of_xlate(struct irq *irq, struct ofnode_phandle_args *args)
64 irq->id = args->args[0];
69 static const struct irq_ops acpi_gpe_ops = {
70 .read_and_clear = acpi_gpe_read_and_clear,
71 .of_xlate = acpi_gpe_of_xlate,
74 static const struct udevice_id acpi_gpe_ids[] = {
75 { .compatible = "intel,acpi-gpe", .data = X86_IRQT_ACPI_GPE },
79 U_BOOT_DRIVER(acpi_gpe_drv) = {
82 .of_match = acpi_gpe_ids,
84 .ofdata_to_platdata = acpi_gpe_ofdata_to_platdata,
85 .priv_auto_alloc_size = sizeof(struct acpi_gpe_priv),