1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2015, Google, Inc
14 #include <acpi/acpigen.h>
15 #include <acpi/acpi_device.h>
16 #include <acpi/acpi_dp.h>
17 #include <asm-generic/gpio.h>
21 struct mmc_config cfg;
26 struct sdhci_host host;
28 struct gpio_desc cd_gpio;
31 static int pci_mmc_probe(struct udevice *dev)
33 struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
34 struct pci_mmc_plat *plat = dev_get_plat(dev);
35 struct pci_mmc_priv *priv = dev_get_priv(dev);
36 struct sdhci_host *host = &priv->host;
39 host->ioaddr = (void *)dm_pci_map_bar(dev, PCI_BASE_ADDRESS_0,
41 host->name = dev->name;
42 host->mmc = &plat->mmc;
44 ret = sdhci_setup_cfg(&plat->cfg, host, 0, 0);
47 host->mmc->priv = &priv->host;
48 upriv->mmc = host->mmc;
50 return sdhci_probe(dev);
53 static int pci_mmc_of_to_plat(struct udevice *dev)
55 struct pci_mmc_priv *priv = dev_get_priv(dev);
57 gpio_request_by_name(dev, "cd-gpios", 0, &priv->cd_gpio, GPIOD_IS_IN);
62 static int pci_mmc_bind(struct udevice *dev)
64 struct pci_mmc_plat *plat = dev_get_plat(dev);
66 return sdhci_bind(dev, &plat->mmc, &plat->cfg);
69 static int pci_mmc_acpi_fill_ssdt(const struct udevice *dev,
72 struct pci_mmc_priv *priv = dev_get_priv(dev);
73 char path[ACPI_PATH_MAX];
74 struct acpi_gpio gpio;
78 if (!dev_has_ofnode(dev))
81 ret = gpio_get_acpi(&priv->cd_gpio, &gpio);
83 return log_msg_ret("gpio", ret);
84 gpio.type = ACPI_GPIO_TYPE_INTERRUPT;
85 gpio.pull = ACPI_GPIO_PULL_NONE;
86 gpio.irq.mode = ACPI_IRQ_EDGE_TRIGGERED;
87 gpio.irq.polarity = ACPI_IRQ_ACTIVE_BOTH;
88 gpio.irq.shared = ACPI_IRQ_SHARED;
89 gpio.irq.wake = ACPI_IRQ_WAKE;
90 gpio.interrupt_debounce_timeout = 10000; /* 100ms */
92 /* Use device path as the Scope for the SSDT */
93 ret = acpi_device_path(dev, path, sizeof(path));
95 return log_msg_ret("path", ret);
96 acpigen_write_scope(ctx, path);
97 acpigen_write_name(ctx, "_CRS");
99 /* Write GpioInt() as default (if set) or custom from devicetree */
100 acpigen_write_resourcetemplate_header(ctx);
101 acpi_device_write_gpio(ctx, &gpio);
102 acpigen_write_resourcetemplate_footer(ctx);
104 /* Bind the cd-gpio name to the GpioInt() resource */
105 dp = acpi_dp_new_table("_DSD");
108 acpi_dp_add_gpio(dp, "cd-gpio", path, 0, 0, 1);
109 ret = acpi_dp_write(ctx, dp);
111 return log_msg_ret("cd", ret);
113 acpigen_pop_len(ctx);
118 struct acpi_ops pci_mmc_acpi_ops = {
119 .fill_ssdt = pci_mmc_acpi_fill_ssdt,
122 static const struct udevice_id pci_mmc_match[] = {
123 { .compatible = "intel,apl-sd" },
127 U_BOOT_DRIVER(pci_mmc) = {
130 .of_match = pci_mmc_match,
131 .bind = pci_mmc_bind,
132 .of_to_plat = pci_mmc_of_to_plat,
133 .probe = pci_mmc_probe,
135 .priv_auto = sizeof(struct pci_mmc_priv),
136 .plat_auto = sizeof(struct pci_mmc_plat),
137 ACPI_OPS_PTR(&pci_mmc_acpi_ops)
140 static struct pci_device_id mmc_supported[] = {
141 { PCI_DEVICE_CLASS(PCI_CLASS_SYSTEM_SDHCI << 8, 0xffff00) },
145 U_BOOT_PCI_DEVICE(pci_mmc, mmc_supported);