Angel Pons | 8a3453f | 2020-04-02 23:48:19 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Duncan Laurie | 4721f43 | 2018-05-07 15:24:10 -0700 | [diff] [blame] | 2 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 3 | #include <acpi/acpi_device.h> |
| 4 | #include <acpi/acpi_pld.h> |
| 5 | #include <acpi/acpigen.h> |
Duncan Laurie | 4721f43 | 2018-05-07 15:24:10 -0700 | [diff] [blame] | 6 | #include <console/console.h> |
| 7 | #include <device/device.h> |
| 8 | #include <device/path.h> |
Duncan Laurie | 4721f43 | 2018-05-07 15:24:10 -0700 | [diff] [blame] | 9 | #include "chip.h" |
| 10 | |
Nick Vaccaro | 0a495eb | 2018-11-12 19:43:35 -0800 | [diff] [blame] | 11 | static bool usb_acpi_add_gpios_to_crs(struct drivers_usb_acpi_config *cfg) |
| 12 | { |
Ricardo Ribalda | df79757 | 2020-10-05 12:44:18 +0000 | [diff] [blame^] | 13 | if (cfg->privacy_gpio.pin_count) |
| 14 | return true; |
Nick Vaccaro | 0a495eb | 2018-11-12 19:43:35 -0800 | [diff] [blame] | 15 | |
Ricardo Ribalda | df79757 | 2020-10-05 12:44:18 +0000 | [diff] [blame^] | 16 | if (cfg->reset_gpio.pin_count && !cfg->has_power_resource) |
| 17 | return true; |
| 18 | |
| 19 | return false; |
| 20 | } |
| 21 | |
| 22 | static int usb_acpi_write_gpio(struct acpi_gpio *gpio, int *curr_index) |
| 23 | { |
| 24 | int ret = -1; |
| 25 | |
| 26 | if (gpio->pin_count == 0) |
| 27 | return ret; |
| 28 | |
| 29 | acpi_device_write_gpio(gpio); |
| 30 | ret = *curr_index; |
| 31 | (*curr_index)++; |
| 32 | |
| 33 | return ret; |
Nick Vaccaro | 0a495eb | 2018-11-12 19:43:35 -0800 | [diff] [blame] | 34 | } |
| 35 | |
Furquan Shaikh | 7536a39 | 2020-04-24 21:59:21 -0700 | [diff] [blame] | 36 | static void usb_acpi_fill_ssdt_generator(const struct device *dev) |
Duncan Laurie | 4721f43 | 2018-05-07 15:24:10 -0700 | [diff] [blame] | 37 | { |
| 38 | struct drivers_usb_acpi_config *config = dev->chip_info; |
| 39 | const char *path = acpi_device_path(dev); |
| 40 | |
Karthikeyan Ramasubramanian | d1c0f95 | 2020-11-02 16:26:52 -0700 | [diff] [blame] | 41 | if (!path || !config) |
Duncan Laurie | 4721f43 | 2018-05-07 15:24:10 -0700 | [diff] [blame] | 42 | return; |
| 43 | |
| 44 | /* Don't generate output for hubs, only ports */ |
| 45 | if (config->type == UPC_TYPE_HUB) |
| 46 | return; |
| 47 | |
| 48 | acpigen_write_scope(path); |
| 49 | if (config->desc) |
| 50 | acpigen_write_name_string("_DDN", config->desc); |
| 51 | acpigen_write_upc(config->type); |
| 52 | |
| 53 | if (config->use_custom_pld) { |
| 54 | /* Use board defined PLD */ |
| 55 | acpigen_write_pld(&config->custom_pld); |
| 56 | } else { |
| 57 | /* Fill PLD strucutre based on port type */ |
| 58 | struct acpi_pld pld; |
Duncan Laurie | e1eca1d | 2018-12-01 17:14:35 -0800 | [diff] [blame] | 59 | acpi_pld_fill_usb(&pld, config->type, &config->group); |
Duncan Laurie | 4721f43 | 2018-05-07 15:24:10 -0700 | [diff] [blame] | 60 | acpigen_write_pld(&pld); |
| 61 | } |
| 62 | |
Nick Vaccaro | 0a495eb | 2018-11-12 19:43:35 -0800 | [diff] [blame] | 63 | /* Resources */ |
| 64 | if (usb_acpi_add_gpios_to_crs(config) == true) { |
| 65 | struct acpi_dp *dsd; |
Ricardo Ribalda | df79757 | 2020-10-05 12:44:18 +0000 | [diff] [blame^] | 66 | int idx = 0; |
| 67 | int reset_gpio_index = -1; |
| 68 | int privacy_gpio_index; |
Nick Vaccaro | 0a495eb | 2018-11-12 19:43:35 -0800 | [diff] [blame] | 69 | |
| 70 | acpigen_write_name("_CRS"); |
| 71 | acpigen_write_resourcetemplate_header(); |
Ricardo Ribalda | df79757 | 2020-10-05 12:44:18 +0000 | [diff] [blame^] | 72 | if (!config->has_power_resource) { |
| 73 | reset_gpio_index = usb_acpi_write_gpio( |
| 74 | &config->reset_gpio, &idx); |
| 75 | } |
| 76 | privacy_gpio_index = usb_acpi_write_gpio(&config->privacy_gpio, |
| 77 | &idx); |
Nick Vaccaro | 0a495eb | 2018-11-12 19:43:35 -0800 | [diff] [blame] | 78 | acpigen_write_resourcetemplate_footer(); |
| 79 | |
| 80 | dsd = acpi_dp_new_table("_DSD"); |
Ricardo Ribalda | df79757 | 2020-10-05 12:44:18 +0000 | [diff] [blame^] | 81 | if (reset_gpio_index >= 0) |
| 82 | acpi_dp_add_gpio(dsd, "reset-gpio", path, |
| 83 | reset_gpio_index, 0, |
| 84 | config->reset_gpio.active_low); |
| 85 | if (privacy_gpio_index >= 0) |
| 86 | acpi_dp_add_gpio(dsd, "privacy-gpio", path, |
| 87 | privacy_gpio_index, 0, |
| 88 | config->privacy_gpio.active_low); |
Nick Vaccaro | 0a495eb | 2018-11-12 19:43:35 -0800 | [diff] [blame] | 89 | acpi_dp_write(dsd); |
| 90 | } |
| 91 | |
Karthikeyan Ramasubramanian | 5eac877 | 2020-10-23 15:15:01 -0600 | [diff] [blame] | 92 | if (config->has_power_resource) { |
| 93 | const struct acpi_power_res_params power_res_params = { |
| 94 | &config->reset_gpio, |
| 95 | config->reset_delay_ms, |
| 96 | config->reset_off_delay_ms, |
| 97 | &config->enable_gpio, |
| 98 | config->enable_delay_ms, |
| 99 | config->enable_off_delay_ms, |
| 100 | NULL, |
| 101 | 0, |
| 102 | 0 |
| 103 | }; |
| 104 | acpi_device_add_power_res(&power_res_params); |
| 105 | } |
| 106 | |
Duncan Laurie | 4721f43 | 2018-05-07 15:24:10 -0700 | [diff] [blame] | 107 | acpigen_pop_len(); |
| 108 | |
| 109 | printk(BIOS_INFO, "%s: %s at %s\n", path, |
| 110 | config->desc ? : dev->chip_ops->name, dev_path(dev)); |
| 111 | } |
| 112 | |
| 113 | static struct device_operations usb_acpi_ops = { |
Nico Huber | 2f8ba69 | 2020-04-05 14:05:24 +0200 | [diff] [blame] | 114 | .read_resources = noop_read_resources, |
| 115 | .set_resources = noop_set_resources, |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 116 | .scan_bus = scan_static_bus, |
| 117 | .acpi_fill_ssdt = usb_acpi_fill_ssdt_generator, |
Duncan Laurie | 4721f43 | 2018-05-07 15:24:10 -0700 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | static void usb_acpi_enable(struct device *dev) |
| 121 | { |
| 122 | dev->ops = &usb_acpi_ops; |
| 123 | } |
| 124 | |
| 125 | struct chip_operations drivers_usb_acpi_ops = { |
| 126 | CHIP_NAME("USB ACPI Device") |
Elyes HAOUAS | 2aa3b16 | 2018-11-27 17:02:10 +0100 | [diff] [blame] | 127 | .enable_dev = usb_acpi_enable |
Duncan Laurie | 4721f43 | 2018-05-07 15:24:10 -0700 | [diff] [blame] | 128 | }; |