Tim Wawrzynczak | e184e39 | 2020-05-14 10:23:19 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | |
| 3 | #include <acpi/acpigen.h> |
Nick Vaccaro | 15066ba | 2021-10-01 13:15:26 -0700 | [diff] [blame] | 4 | #include <boot/coreboot_tables.h> |
Nick Vaccaro | d4c5535 | 2021-10-01 16:17:42 -0700 | [diff] [blame] | 5 | #include <cbmem.h> |
Tim Wawrzynczak | e184e39 | 2020-05-14 10:23:19 -0600 | [diff] [blame] | 6 | #include <console/console.h> |
| 7 | #include <intelblocks/acpi.h> |
Nick Vaccaro | 15066ba | 2021-10-01 13:15:26 -0700 | [diff] [blame] | 8 | |
Tim Wawrzynczak | e184e39 | 2020-05-14 10:23:19 -0600 | [diff] [blame] | 9 | #include "chip.h" |
| 10 | |
Nick Vaccaro | d4c5535 | 2021-10-01 16:17:42 -0700 | [diff] [blame] | 11 | /* Number of registered connectors */ |
| 12 | static size_t total_conn_count; |
| 13 | |
| 14 | static void conn_init(struct device *dev) |
| 15 | { |
| 16 | total_conn_count++; |
| 17 | } |
| 18 | |
Reka Norman | d448f8c | 2021-12-09 12:09:27 +1100 | [diff] [blame] | 19 | static unsigned int get_usb_port_number(const struct device *usb_port) |
| 20 | { |
| 21 | return usb_port->path.usb.port_id + 1; |
| 22 | } |
| 23 | |
Nick Vaccaro | d4c5535 | 2021-10-01 16:17:42 -0700 | [diff] [blame] | 24 | static struct type_c_info *conn_get_cbmem_buffer(void) |
| 25 | { |
| 26 | struct type_c_info *info; |
| 27 | size_t size; |
| 28 | |
| 29 | info = cbmem_find(CBMEM_ID_TYPE_C_INFO); |
| 30 | if (info) |
| 31 | return info; |
| 32 | |
| 33 | size = sizeof(struct type_c_info) + total_conn_count * sizeof(struct type_c_port_info); |
| 34 | info = cbmem_add(CBMEM_ID_TYPE_C_INFO, size); |
| 35 | |
| 36 | if (!info) |
| 37 | return NULL; |
| 38 | |
| 39 | memset(info, 0, size); |
| 40 | return info; |
| 41 | } |
| 42 | |
| 43 | static void conn_write_cbmem_entry(struct device *dev) |
| 44 | { |
| 45 | const struct drivers_intel_pmc_mux_conn_config *config = dev->chip_info; |
| 46 | struct type_c_port_info *port_info; |
| 47 | struct type_c_info *info; |
| 48 | size_t count; |
| 49 | |
| 50 | /* |
| 51 | * Do not re-run this code on resume as the cbmem data is populated on boot-up |
| 52 | * (non-S3 path) and stays intact across S3 suspend/resume. |
| 53 | */ |
| 54 | if (acpi_is_wakeup_s3()) |
| 55 | return; |
| 56 | |
| 57 | info = conn_get_cbmem_buffer(); |
| 58 | if (!info || (info->port_count >= total_conn_count)) { |
| 59 | printk(BIOS_ERR, "ERROR: No space for Type-C port info!\n"); |
| 60 | return; |
| 61 | } |
| 62 | |
| 63 | count = info->port_count; |
| 64 | port_info = &info->port_info[count]; |
Reka Norman | d448f8c | 2021-12-09 12:09:27 +1100 | [diff] [blame] | 65 | port_info->usb2_port_number = get_usb_port_number(config->usb2_port); |
| 66 | port_info->usb3_port_number = get_usb_port_number(config->usb3_port); |
Nick Vaccaro | d4c5535 | 2021-10-01 16:17:42 -0700 | [diff] [blame] | 67 | port_info->sbu_orientation = config->sbu_orientation; |
| 68 | port_info->data_orientation = config->hsl_orientation; |
| 69 | |
| 70 | printk(BIOS_INFO, "added type-c port%ld info to cbmem: usb2:%d usb3:%d sbu:%d data:%d\n", |
| 71 | count, port_info->usb2_port_number, port_info->usb3_port_number, |
| 72 | port_info->sbu_orientation, port_info->data_orientation); |
| 73 | |
| 74 | info->port_count++; |
| 75 | } |
| 76 | |
Tim Wawrzynczak | e414ce4 | 2020-07-03 09:36:11 -0600 | [diff] [blame] | 77 | static const char *conn_acpi_name(const struct device *dev) |
Tim Wawrzynczak | e184e39 | 2020-05-14 10:23:19 -0600 | [diff] [blame] | 78 | { |
| 79 | static char name[5]; |
| 80 | snprintf(name, sizeof(name), "CON%1X", dev->path.generic.id); |
| 81 | return name; |
| 82 | } |
| 83 | |
Nick Vaccaro | 15066ba | 2021-10-01 13:15:26 -0700 | [diff] [blame] | 84 | static const char *orientation_to_str(enum type_c_orientation ori) |
Tim Wawrzynczak | e184e39 | 2020-05-14 10:23:19 -0600 | [diff] [blame] | 85 | { |
| 86 | switch (ori) { |
| 87 | case TYPEC_ORIENTATION_NORMAL: |
| 88 | return "normal"; |
| 89 | case TYPEC_ORIENTATION_REVERSE: |
| 90 | return "reverse"; |
Nick Vaccaro | 15066ba | 2021-10-01 13:15:26 -0700 | [diff] [blame] | 91 | case TYPEC_ORIENTATION_NONE: /* Intentional fallthrough */ |
Tim Wawrzynczak | e184e39 | 2020-05-14 10:23:19 -0600 | [diff] [blame] | 92 | default: |
| 93 | return ""; |
| 94 | } |
| 95 | } |
| 96 | |
Tim Wawrzynczak | e414ce4 | 2020-07-03 09:36:11 -0600 | [diff] [blame] | 97 | static void conn_fill_ssdt(const struct device *dev) |
Tim Wawrzynczak | e184e39 | 2020-05-14 10:23:19 -0600 | [diff] [blame] | 98 | { |
Tim Wawrzynczak | e414ce4 | 2020-07-03 09:36:11 -0600 | [diff] [blame] | 99 | struct drivers_intel_pmc_mux_conn_config *config = dev->chip_info; |
Tim Wawrzynczak | e184e39 | 2020-05-14 10:23:19 -0600 | [diff] [blame] | 100 | struct acpi_dp *dsd; |
John Zhao | ff4ead0 | 2020-06-26 08:53:54 -0700 | [diff] [blame] | 101 | const char *scope; |
| 102 | const char *name; |
Tim Wawrzynczak | e184e39 | 2020-05-14 10:23:19 -0600 | [diff] [blame] | 103 | |
Tim Wawrzynczak | e184e39 | 2020-05-14 10:23:19 -0600 | [diff] [blame] | 104 | /* Reference the existing scope and write CONx device */ |
John Zhao | ff4ead0 | 2020-06-26 08:53:54 -0700 | [diff] [blame] | 105 | scope = acpi_device_scope(dev); |
| 106 | name = acpi_device_name(dev); |
| 107 | if (!scope || !name) |
| 108 | return; |
| 109 | |
| 110 | acpigen_write_scope(scope); |
| 111 | acpigen_write_device(name); |
Tim Wawrzynczak | e184e39 | 2020-05-14 10:23:19 -0600 | [diff] [blame] | 112 | |
| 113 | acpigen_write_name_integer("_ADR", dev->path.generic.id); |
| 114 | |
| 115 | /* _DSD, Device-Specific Data */ |
| 116 | dsd = acpi_dp_new_table("_DSD"); |
Reka Norman | d448f8c | 2021-12-09 12:09:27 +1100 | [diff] [blame] | 117 | acpi_dp_add_integer(dsd, "usb2-port-number", get_usb_port_number(config->usb2_port)); |
| 118 | acpi_dp_add_integer(dsd, "usb3-port-number", get_usb_port_number(config->usb3_port)); |
Tim Wawrzynczak | e184e39 | 2020-05-14 10:23:19 -0600 | [diff] [blame] | 119 | |
| 120 | /* |
| 121 | * The kernel assumes that these Type-C signals (SBUs and HSLs) follow the CC lines, |
| 122 | * unless they are explicitly called out otherwise. |
| 123 | */ |
Nick Vaccaro | 15066ba | 2021-10-01 13:15:26 -0700 | [diff] [blame] | 124 | if (config->sbu_orientation != TYPEC_ORIENTATION_NONE) |
Tim Wawrzynczak | e184e39 | 2020-05-14 10:23:19 -0600 | [diff] [blame] | 125 | acpi_dp_add_string(dsd, "sbu-orientation", |
| 126 | orientation_to_str(config->sbu_orientation)); |
| 127 | |
Nick Vaccaro | 15066ba | 2021-10-01 13:15:26 -0700 | [diff] [blame] | 128 | if (config->hsl_orientation != TYPEC_ORIENTATION_NONE) |
Tim Wawrzynczak | e184e39 | 2020-05-14 10:23:19 -0600 | [diff] [blame] | 129 | acpi_dp_add_string(dsd, "hsl-orientation", |
| 130 | orientation_to_str(config->hsl_orientation)); |
| 131 | |
| 132 | acpi_dp_write(dsd); |
| 133 | |
| 134 | acpigen_pop_len(); /* CONx Device */ |
| 135 | acpigen_pop_len(); /* Scope */ |
| 136 | |
| 137 | printk(BIOS_INFO, "%s: %s at %s\n", acpi_device_path(dev), dev->chip_ops->name, |
| 138 | dev_path(dev)); |
| 139 | } |
| 140 | |
Tim Wawrzynczak | e414ce4 | 2020-07-03 09:36:11 -0600 | [diff] [blame] | 141 | static struct device_operations conn_dev_ops = { |
Tim Wawrzynczak | e184e39 | 2020-05-14 10:23:19 -0600 | [diff] [blame] | 142 | .read_resources = noop_read_resources, |
| 143 | .set_resources = noop_set_resources, |
Tim Wawrzynczak | e414ce4 | 2020-07-03 09:36:11 -0600 | [diff] [blame] | 144 | .acpi_name = conn_acpi_name, |
| 145 | .acpi_fill_ssdt = conn_fill_ssdt, |
Nick Vaccaro | d4c5535 | 2021-10-01 16:17:42 -0700 | [diff] [blame] | 146 | .init = conn_init, |
| 147 | .final = conn_write_cbmem_entry, |
Tim Wawrzynczak | e184e39 | 2020-05-14 10:23:19 -0600 | [diff] [blame] | 148 | }; |
| 149 | |
Tim Wawrzynczak | e414ce4 | 2020-07-03 09:36:11 -0600 | [diff] [blame] | 150 | static void conn_enable(struct device *dev) |
Tim Wawrzynczak | e184e39 | 2020-05-14 10:23:19 -0600 | [diff] [blame] | 151 | { |
Tim Wawrzynczak | e414ce4 | 2020-07-03 09:36:11 -0600 | [diff] [blame] | 152 | dev->ops = &conn_dev_ops; |
Tim Wawrzynczak | e184e39 | 2020-05-14 10:23:19 -0600 | [diff] [blame] | 153 | } |
| 154 | |
Tim Wawrzynczak | e414ce4 | 2020-07-03 09:36:11 -0600 | [diff] [blame] | 155 | struct chip_operations drivers_intel_pmc_mux_conn_ops = { |
| 156 | CHIP_NAME("Intel PMC MUX CONN Driver") |
| 157 | .enable_dev = conn_enable, |
Tim Wawrzynczak | e184e39 | 2020-05-14 10:23:19 -0600 | [diff] [blame] | 158 | }; |
Deepti Deshatty | c146daf | 2021-05-20 21:01:52 +0530 | [diff] [blame] | 159 | |
| 160 | bool intel_pmc_mux_conn_get_ports(const struct device *conn, unsigned int *usb2_port, |
| 161 | unsigned int *usb3_port) |
| 162 | { |
| 163 | const struct drivers_intel_pmc_mux_conn_config *mux_config; |
| 164 | |
| 165 | if (!conn->chip_info || conn->chip_ops != &drivers_intel_pmc_mux_conn_ops) |
| 166 | return false; |
| 167 | |
| 168 | mux_config = conn->chip_info; |
Reka Norman | d448f8c | 2021-12-09 12:09:27 +1100 | [diff] [blame] | 169 | *usb2_port = get_usb_port_number(mux_config->usb2_port); |
| 170 | *usb3_port = get_usb_port_number(mux_config->usb3_port); |
Deepti Deshatty | c146daf | 2021-05-20 21:01:52 +0530 | [diff] [blame] | 171 | |
| 172 | return true; |
| 173 | }; |