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> |
| 4 | #include <console/console.h> |
| 5 | #include <intelblocks/acpi.h> |
| 6 | #include "chip.h" |
| 7 | |
Tim Wawrzynczak | e414ce4 | 2020-07-03 09:36:11 -0600 | [diff] [blame] | 8 | static const char *conn_acpi_name(const struct device *dev) |
Tim Wawrzynczak | e184e39 | 2020-05-14 10:23:19 -0600 | [diff] [blame] | 9 | { |
| 10 | static char name[5]; |
| 11 | snprintf(name, sizeof(name), "CON%1X", dev->path.generic.id); |
| 12 | return name; |
| 13 | } |
| 14 | |
| 15 | static const char *orientation_to_str(enum typec_orientation ori) |
| 16 | { |
| 17 | switch (ori) { |
| 18 | case TYPEC_ORIENTATION_NORMAL: |
| 19 | return "normal"; |
| 20 | case TYPEC_ORIENTATION_REVERSE: |
| 21 | return "reverse"; |
| 22 | case TYPEC_ORIENTATION_FOLLOW_CC: /* Intentional fallthrough */ |
| 23 | default: |
| 24 | return ""; |
| 25 | } |
| 26 | } |
| 27 | |
Tim Wawrzynczak | e414ce4 | 2020-07-03 09:36:11 -0600 | [diff] [blame] | 28 | static void conn_fill_ssdt(const struct device *dev) |
Tim Wawrzynczak | e184e39 | 2020-05-14 10:23:19 -0600 | [diff] [blame] | 29 | { |
Tim Wawrzynczak | e414ce4 | 2020-07-03 09:36:11 -0600 | [diff] [blame] | 30 | struct drivers_intel_pmc_mux_conn_config *config = dev->chip_info; |
Tim Wawrzynczak | e184e39 | 2020-05-14 10:23:19 -0600 | [diff] [blame] | 31 | struct acpi_dp *dsd; |
John Zhao | ff4ead0 | 2020-06-26 08:53:54 -0700 | [diff] [blame] | 32 | const char *scope; |
| 33 | const char *name; |
Tim Wawrzynczak | e184e39 | 2020-05-14 10:23:19 -0600 | [diff] [blame] | 34 | |
Tim Wawrzynczak | e184e39 | 2020-05-14 10:23:19 -0600 | [diff] [blame] | 35 | /* Reference the existing scope and write CONx device */ |
John Zhao | ff4ead0 | 2020-06-26 08:53:54 -0700 | [diff] [blame] | 36 | scope = acpi_device_scope(dev); |
| 37 | name = acpi_device_name(dev); |
| 38 | if (!scope || !name) |
| 39 | return; |
| 40 | |
| 41 | acpigen_write_scope(scope); |
| 42 | acpigen_write_device(name); |
Tim Wawrzynczak | e184e39 | 2020-05-14 10:23:19 -0600 | [diff] [blame] | 43 | |
| 44 | acpigen_write_name_integer("_ADR", dev->path.generic.id); |
| 45 | |
| 46 | /* _DSD, Device-Specific Data */ |
| 47 | dsd = acpi_dp_new_table("_DSD"); |
| 48 | acpi_dp_add_integer(dsd, "usb2-port-number", config->usb2_port_number); |
| 49 | acpi_dp_add_integer(dsd, "usb3-port-number", config->usb3_port_number); |
| 50 | |
| 51 | /* |
| 52 | * The kernel assumes that these Type-C signals (SBUs and HSLs) follow the CC lines, |
| 53 | * unless they are explicitly called out otherwise. |
| 54 | */ |
| 55 | if (config->sbu_orientation != TYPEC_ORIENTATION_FOLLOW_CC) |
| 56 | acpi_dp_add_string(dsd, "sbu-orientation", |
| 57 | orientation_to_str(config->sbu_orientation)); |
| 58 | |
| 59 | if (config->hsl_orientation != TYPEC_ORIENTATION_FOLLOW_CC) |
| 60 | acpi_dp_add_string(dsd, "hsl-orientation", |
| 61 | orientation_to_str(config->hsl_orientation)); |
| 62 | |
| 63 | acpi_dp_write(dsd); |
| 64 | |
| 65 | acpigen_pop_len(); /* CONx Device */ |
| 66 | acpigen_pop_len(); /* Scope */ |
| 67 | |
| 68 | printk(BIOS_INFO, "%s: %s at %s\n", acpi_device_path(dev), dev->chip_ops->name, |
| 69 | dev_path(dev)); |
| 70 | } |
| 71 | |
Tim Wawrzynczak | e414ce4 | 2020-07-03 09:36:11 -0600 | [diff] [blame] | 72 | static struct device_operations conn_dev_ops = { |
Tim Wawrzynczak | e184e39 | 2020-05-14 10:23:19 -0600 | [diff] [blame] | 73 | .read_resources = noop_read_resources, |
| 74 | .set_resources = noop_set_resources, |
Tim Wawrzynczak | e414ce4 | 2020-07-03 09:36:11 -0600 | [diff] [blame] | 75 | .acpi_name = conn_acpi_name, |
| 76 | .acpi_fill_ssdt = conn_fill_ssdt, |
Tim Wawrzynczak | e184e39 | 2020-05-14 10:23:19 -0600 | [diff] [blame] | 77 | }; |
| 78 | |
Tim Wawrzynczak | e414ce4 | 2020-07-03 09:36:11 -0600 | [diff] [blame] | 79 | static void conn_enable(struct device *dev) |
Tim Wawrzynczak | e184e39 | 2020-05-14 10:23:19 -0600 | [diff] [blame] | 80 | { |
Tim Wawrzynczak | e414ce4 | 2020-07-03 09:36:11 -0600 | [diff] [blame] | 81 | dev->ops = &conn_dev_ops; |
Tim Wawrzynczak | e184e39 | 2020-05-14 10:23:19 -0600 | [diff] [blame] | 82 | } |
| 83 | |
Tim Wawrzynczak | e414ce4 | 2020-07-03 09:36:11 -0600 | [diff] [blame] | 84 | struct chip_operations drivers_intel_pmc_mux_conn_ops = { |
| 85 | CHIP_NAME("Intel PMC MUX CONN Driver") |
| 86 | .enable_dev = conn_enable, |
Tim Wawrzynczak | e184e39 | 2020-05-14 10:23:19 -0600 | [diff] [blame] | 87 | }; |
Deepti Deshatty | c146daf | 2021-05-20 21:01:52 +0530 | [diff] [blame] | 88 | |
| 89 | bool intel_pmc_mux_conn_get_ports(const struct device *conn, unsigned int *usb2_port, |
| 90 | unsigned int *usb3_port) |
| 91 | { |
| 92 | const struct drivers_intel_pmc_mux_conn_config *mux_config; |
| 93 | |
| 94 | if (!conn->chip_info || conn->chip_ops != &drivers_intel_pmc_mux_conn_ops) |
| 95 | return false; |
| 96 | |
| 97 | mux_config = conn->chip_info; |
| 98 | *usb2_port = mux_config->usb2_port_number; |
| 99 | *usb3_port = mux_config->usb3_port_number; |
| 100 | |
| 101 | return true; |
| 102 | }; |