blob: a9469becf6bd3e6fcfa79b3099fb0fb91c863cf4 [file] [log] [blame]
Duncan Laurieb25a45c2016-05-10 15:56:16 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2016 Google Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#include <arch/acpi_device.h>
17#include <arch/acpigen.h>
18#include <device/device.h>
19#include <device/pci.h>
20#include <device/pci_ids.h>
21#include <gpio.h>
22#include <soc/ramstage.h>
23#include "chip.h"
24
25#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
26static void sd_fill_ssdt(struct device *dev)
27{
28 config_t *config = dev->chip_info;
29 const char *path;
30 struct acpi_gpio default_gpio = {
31 .type = ACPI_GPIO_TYPE_INTERRUPT,
32 .pull = ACPI_GPIO_PULL_NONE,
Furquan Shaikh5b9b5932017-02-21 13:16:30 -080033 .irq.mode = ACPI_IRQ_EDGE_TRIGGERED,
34 .irq.polarity = ACPI_IRQ_ACTIVE_BOTH,
35 .irq.shared = ACPI_IRQ_SHARED,
36 .irq.wake = ACPI_IRQ_WAKE,
Duncan Laurieb25a45c2016-05-10 15:56:16 -070037 .interrupt_debounce_timeout = 10000, /* 100ms */
38 .pin_count = 1,
39 .pins = { config->sdcard_cd_gpio_default }
40 };
Duncan Laurieffc99902016-07-02 19:56:06 -070041 struct acpi_dp *dp;
Duncan Laurieb25a45c2016-05-10 15:56:16 -070042
43 if (!dev->enabled)
44 return;
45
46 /* Nothing to write if GPIO is not set in devicetree */
47 if (!config->sdcard_cd_gpio_default && !config->sdcard_cd_gpio.pins[0])
48 return;
49
50 /* Use device path as the Scope for the SSDT */
51 path = acpi_device_path(dev);
52 if (!path)
53 return;
54 acpigen_write_scope(path);
55 acpigen_write_name("_CRS");
56
57 /* Write GpioInt() as default (if set) or custom from devicetree */
58 acpigen_write_resourcetemplate_header();
59 if (config->sdcard_cd_gpio_default)
60 acpi_device_write_gpio(&default_gpio);
61 else
62 acpi_device_write_gpio(&config->sdcard_cd_gpio);
63 acpigen_write_resourcetemplate_footer();
64
65 /* Bind the cd-gpio name to the GpioInt() resource */
Duncan Laurieffc99902016-07-02 19:56:06 -070066 dp = acpi_dp_new_table("_DSD");
67 acpi_dp_add_gpio(dp, "cd-gpio", path, 0, 0, 1);
68 acpi_dp_write(dp);
Duncan Laurieb25a45c2016-05-10 15:56:16 -070069
70 acpigen_pop_len();
71}
72#endif
73
74static struct device_operations dev_ops = {
75 .read_resources = &pci_dev_read_resources,
76 .set_resources = &pci_dev_set_resources,
77 .enable_resources = &pci_dev_enable_resources,
78 .ops_pci = &soc_pci_ops,
79#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
80 .acpi_fill_ssdt_generator = &sd_fill_ssdt,
81#endif
82};
83
84static const struct pci_driver pch_sd __pci_driver = {
85 .ops = &dev_ops,
86 .vendor = PCI_VENDOR_ID_INTEL,
87 .device = 0x9d2d
88};