Bora Guvendik | 94ee328 | 2017-05-04 13:06:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2017 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/acpigen.h> |
| 17 | #include <device/pci.h> |
| 18 | #include <device/pci_ids.h> |
| 19 | #include <intelblocks/sd.h> |
| 20 | |
| 21 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) |
| 22 | static void sd_fill_ssdt(struct device *dev) |
| 23 | { |
| 24 | const char *path; |
| 25 | struct acpi_gpio default_gpio = { 0 }; |
| 26 | struct acpi_dp *dp; |
| 27 | |
| 28 | if (!dev->enabled) |
| 29 | return; |
| 30 | |
| 31 | if (sd_fill_soc_gpio_info(&default_gpio, dev) != 0) |
| 32 | return; |
| 33 | |
| 34 | /* Use device path as the Scope for the SSDT */ |
| 35 | path = acpi_device_path(dev); |
| 36 | if (!path) |
| 37 | return; |
| 38 | acpigen_write_scope(path); |
| 39 | acpigen_write_name("_CRS"); |
| 40 | |
| 41 | /* Write GpioInt() as default (if set) or custom from devicetree */ |
| 42 | acpigen_write_resourcetemplate_header(); |
| 43 | acpi_device_write_gpio(&default_gpio); |
| 44 | acpigen_write_resourcetemplate_footer(); |
| 45 | |
| 46 | /* Bind the cd-gpio name to the GpioInt() resource */ |
| 47 | dp = acpi_dp_new_table("_DSD"); |
| 48 | if (!dp) |
| 49 | return; |
| 50 | acpi_dp_add_gpio(dp, "cd-gpio", path, 0, 0, 1); |
| 51 | acpi_dp_write(dp); |
| 52 | |
| 53 | acpigen_pop_len(); |
| 54 | } |
| 55 | #endif |
| 56 | |
| 57 | static struct device_operations dev_ops = { |
Subrata Banik | 6bbc91a | 2017-12-07 14:55:51 +0530 | [diff] [blame^] | 58 | .read_resources = &pci_dev_read_resources, |
| 59 | .set_resources = &pci_dev_set_resources, |
| 60 | .enable_resources = &pci_dev_enable_resources, |
Bora Guvendik | 94ee328 | 2017-05-04 13:06:43 -0700 | [diff] [blame] | 61 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) |
| 62 | .acpi_fill_ssdt_generator = &sd_fill_ssdt, |
| 63 | #endif |
Subrata Banik | 6bbc91a | 2017-12-07 14:55:51 +0530 | [diff] [blame^] | 64 | .ops_pci = &pci_dev_ops_pci, |
Bora Guvendik | 94ee328 | 2017-05-04 13:06:43 -0700 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | static const unsigned short pci_device_ids[] = { |
| 68 | PCI_DEVICE_ID_INTEL_APL_SD, |
Lijian Zhao | bbedef9 | 2017-07-29 16:38:38 -0700 | [diff] [blame] | 69 | PCI_DEVICE_ID_INTEL_CNL_SD, |
Bora Guvendik | 94ee328 | 2017-05-04 13:06:43 -0700 | [diff] [blame] | 70 | PCI_DEVICE_ID_INTEL_GLK_SD, |
| 71 | PCI_DEVICE_ID_INTEL_SKL_SD, |
| 72 | 0 |
| 73 | }; |
| 74 | |
| 75 | static const struct pci_driver pch_sd __pci_driver = { |
| 76 | .ops = &dev_ops, |
| 77 | .vendor = PCI_VENDOR_ID_INTEL, |
| 78 | .devices = pci_device_ids |
| 79 | }; |