Angel Pons | 8a3453f | 2020-04-02 23:48:19 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Duncan Laurie | 4721f43 | 2018-05-07 15:24:10 -0700 | [diff] [blame] | 3 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame^] | 4 | #include <acpi/acpi_device.h> |
| 5 | #include <acpi/acpi_pld.h> |
| 6 | #include <acpi/acpigen.h> |
Duncan Laurie | 4721f43 | 2018-05-07 15:24:10 -0700 | [diff] [blame] | 7 | #include <console/console.h> |
| 8 | #include <device/device.h> |
| 9 | #include <device/path.h> |
| 10 | #include <stdint.h> |
Duncan Laurie | 4721f43 | 2018-05-07 15:24:10 -0700 | [diff] [blame] | 11 | #include "chip.h" |
| 12 | |
Nick Vaccaro | 0a495eb | 2018-11-12 19:43:35 -0800 | [diff] [blame] | 13 | static bool usb_acpi_add_gpios_to_crs(struct drivers_usb_acpi_config *cfg) |
| 14 | { |
| 15 | /* |
| 16 | * Return false if reset GPIO is not provided. |
| 17 | */ |
| 18 | if (cfg->reset_gpio.pin_count == 0) |
| 19 | return false; |
| 20 | |
| 21 | return true; |
| 22 | } |
| 23 | |
Furquan Shaikh | 7536a39 | 2020-04-24 21:59:21 -0700 | [diff] [blame] | 24 | static void usb_acpi_fill_ssdt_generator(const struct device *dev) |
Duncan Laurie | 4721f43 | 2018-05-07 15:24:10 -0700 | [diff] [blame] | 25 | { |
| 26 | struct drivers_usb_acpi_config *config = dev->chip_info; |
| 27 | const char *path = acpi_device_path(dev); |
| 28 | |
| 29 | if (!dev->enabled || !path || !config) |
| 30 | return; |
| 31 | |
| 32 | /* Don't generate output for hubs, only ports */ |
| 33 | if (config->type == UPC_TYPE_HUB) |
| 34 | return; |
| 35 | |
| 36 | acpigen_write_scope(path); |
| 37 | if (config->desc) |
| 38 | acpigen_write_name_string("_DDN", config->desc); |
| 39 | acpigen_write_upc(config->type); |
| 40 | |
| 41 | if (config->use_custom_pld) { |
| 42 | /* Use board defined PLD */ |
| 43 | acpigen_write_pld(&config->custom_pld); |
| 44 | } else { |
| 45 | /* Fill PLD strucutre based on port type */ |
| 46 | struct acpi_pld pld; |
Duncan Laurie | e1eca1d | 2018-12-01 17:14:35 -0800 | [diff] [blame] | 47 | acpi_pld_fill_usb(&pld, config->type, &config->group); |
Duncan Laurie | 4721f43 | 2018-05-07 15:24:10 -0700 | [diff] [blame] | 48 | acpigen_write_pld(&pld); |
| 49 | } |
| 50 | |
Nick Vaccaro | 0a495eb | 2018-11-12 19:43:35 -0800 | [diff] [blame] | 51 | /* Resources */ |
| 52 | if (usb_acpi_add_gpios_to_crs(config) == true) { |
| 53 | struct acpi_dp *dsd; |
| 54 | |
| 55 | acpigen_write_name("_CRS"); |
| 56 | acpigen_write_resourcetemplate_header(); |
| 57 | acpi_device_write_gpio(&config->reset_gpio); |
| 58 | acpigen_write_resourcetemplate_footer(); |
| 59 | |
| 60 | dsd = acpi_dp_new_table("_DSD"); |
| 61 | acpi_dp_add_gpio(dsd, "reset-gpio", path, 0, 0, |
| 62 | config->reset_gpio.polarity); |
| 63 | acpi_dp_write(dsd); |
| 64 | } |
| 65 | |
Duncan Laurie | 4721f43 | 2018-05-07 15:24:10 -0700 | [diff] [blame] | 66 | acpigen_pop_len(); |
| 67 | |
| 68 | printk(BIOS_INFO, "%s: %s at %s\n", path, |
| 69 | config->desc ? : dev->chip_ops->name, dev_path(dev)); |
| 70 | } |
| 71 | |
| 72 | static struct device_operations usb_acpi_ops = { |
Nico Huber | 2f8ba69 | 2020-04-05 14:05:24 +0200 | [diff] [blame] | 73 | .read_resources = noop_read_resources, |
| 74 | .set_resources = noop_set_resources, |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 75 | .scan_bus = scan_static_bus, |
| 76 | .acpi_fill_ssdt = usb_acpi_fill_ssdt_generator, |
Duncan Laurie | 4721f43 | 2018-05-07 15:24:10 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | static void usb_acpi_enable(struct device *dev) |
| 80 | { |
| 81 | dev->ops = &usb_acpi_ops; |
| 82 | } |
| 83 | |
| 84 | struct chip_operations drivers_usb_acpi_ops = { |
| 85 | CHIP_NAME("USB ACPI Device") |
Elyes HAOUAS | 2aa3b16 | 2018-11-27 17:02:10 +0100 | [diff] [blame] | 86 | .enable_dev = usb_acpi_enable |
Duncan Laurie | 4721f43 | 2018-05-07 15:24:10 -0700 | [diff] [blame] | 87 | }; |