Tim Wawrzynczak | 6da8213 | 2020-05-19 12:46:04 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Tim Wawrzynczak | eb3cd85 | 2020-01-22 16:52:13 -0700 | [diff] [blame] | 2 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 3 | #include <acpi/acpi.h> |
| 4 | #include <acpi/acpi_device.h> |
| 5 | #include <acpi/acpigen.h> |
| 6 | #include <acpi/acpigen_ps2_keybd.h> |
Tim Wawrzynczak | 6da8213 | 2020-05-19 12:46:04 -0600 | [diff] [blame] | 7 | #include <acpi/acpigen_usb.h> |
Tim Wawrzynczak | eb3cd85 | 2020-01-22 16:52:13 -0700 | [diff] [blame] | 8 | #include <console/console.h> |
| 9 | #include <drivers/usb/acpi/chip.h> |
Tim Wawrzynczak | eb3cd85 | 2020-01-22 16:52:13 -0700 | [diff] [blame] | 10 | |
| 11 | #include "chip.h" |
| 12 | #include "ec.h" |
| 13 | #include "ec_commands.h" |
| 14 | |
Karthikeyan Ramasubramanian | a95907b | 2020-04-13 18:03:29 -0600 | [diff] [blame] | 15 | #define GOOGLE_CHROMEEC_USBC_DEVICE_HID "GOOG0014" |
| 16 | #define GOOGLE_CHROMEEC_USBC_DEVICE_NAME "USBC" |
Tim Wawrzynczak | eb3cd85 | 2020-01-22 16:52:13 -0700 | [diff] [blame] | 17 | |
Tim Wawrzynczak | 6046739 | 2020-05-18 13:45:43 -0600 | [diff] [blame] | 18 | /* Avoid adding a false dependency on an SoC or intel/common */ |
| 19 | extern const struct device *soc_get_pmc_mux_device(int port_number); |
| 20 | |
| 21 | __weak const struct device *soc_get_pmc_mux_device(int port_number) |
| 22 | { |
| 23 | return NULL; |
| 24 | } |
| 25 | |
Tim Wawrzynczak | eb3cd85 | 2020-01-22 16:52:13 -0700 | [diff] [blame] | 26 | const char *google_chromeec_acpi_name(const struct device *dev) |
| 27 | { |
Furquan Shaikh | eec30f7 | 2020-04-20 16:38:21 -0700 | [diff] [blame] | 28 | /* |
| 29 | * Chrome EC device (CREC - GOOG0004) is really a child of EC device (EC - PNP0C09) in |
| 30 | * ACPI tables. However, in coreboot device tree, there is no separate chip/device for |
| 31 | * EC0. Thus, Chrome EC device needs to return "EC0.CREC" as the ACPI name so that the |
| 32 | * callers can get the correct acpi device path/scope for this device. |
| 33 | * |
| 34 | * If we ever enable a separate driver for generating AML for EC0 device, then this |
| 35 | * function needs to be updated to return "CREC". |
| 36 | */ |
| 37 | return "EC0.CREC"; |
Tim Wawrzynczak | eb3cd85 | 2020-01-22 16:52:13 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Tim Wawrzynczak | 6da8213 | 2020-05-19 12:46:04 -0600 | [diff] [blame] | 40 | /* |
| 41 | * Helper for fill_ssdt_generator. This adds references to the USB |
| 42 | * port objects so that the consumer of this information can know |
| 43 | * whether the port supports USB2 and/or USB3. |
| 44 | */ |
| 45 | static void get_usb_port_references(int port_number, struct device **usb2_port, |
| 46 | struct device **usb3_port, struct device **usb4_port) |
Tim Wawrzynczak | eb3cd85 | 2020-01-22 16:52:13 -0700 | [diff] [blame] | 47 | { |
Tim Wawrzynczak | 6da8213 | 2020-05-19 12:46:04 -0600 | [diff] [blame] | 48 | struct drivers_usb_acpi_config *config; |
| 49 | struct device *port = NULL; |
Tim Wawrzynczak | eb3cd85 | 2020-01-22 16:52:13 -0700 | [diff] [blame] | 50 | |
Tim Wawrzynczak | 6da8213 | 2020-05-19 12:46:04 -0600 | [diff] [blame] | 51 | /* Search through the devicetree for matching USB Type-C ports */ |
| 52 | while ((port = dev_find_path(port, DEVICE_PATH_USB)) != NULL) { |
| 53 | if (!port->enabled || port->path.type != DEVICE_PATH_USB) |
| 54 | continue; |
| 55 | |
| 56 | config = port->chip_info; |
| 57 | |
| 58 | /* Look at only USB Type-C ports */ |
| 59 | if ((config->type != UPC_TYPE_C_USB2_ONLY) && |
| 60 | (config->type != UPC_TYPE_C_USB2_SS_SWITCH) && |
| 61 | (config->type != UPC_TYPE_C_USB2_SS)) |
| 62 | continue; |
| 63 | |
Tim Wawrzynczak | eb3cd85 | 2020-01-22 16:52:13 -0700 | [diff] [blame] | 64 | /* |
Tim Wawrzynczak | 6da8213 | 2020-05-19 12:46:04 -0600 | [diff] [blame] | 65 | * Check for a matching port number (the 'token' field in 'group'). Note that |
| 66 | * 'port_number' is 0-based, whereas the 'token' field is 1-based. |
Tim Wawrzynczak | eb3cd85 | 2020-01-22 16:52:13 -0700 | [diff] [blame] | 67 | */ |
Tim Wawrzynczak | 6da8213 | 2020-05-19 12:46:04 -0600 | [diff] [blame] | 68 | if (config->group.token != (port_number + 1)) |
| 69 | continue; |
Tim Wawrzynczak | eb3cd85 | 2020-01-22 16:52:13 -0700 | [diff] [blame] | 70 | |
Tim Wawrzynczak | 6da8213 | 2020-05-19 12:46:04 -0600 | [diff] [blame] | 71 | switch (port->path.usb.port_type) { |
| 72 | case 2: |
| 73 | *usb2_port = port; |
| 74 | break; |
| 75 | case 3: |
| 76 | *usb3_port = port; |
| 77 | break; |
| 78 | case 4: |
| 79 | *usb4_port = port; |
| 80 | break; |
| 81 | default: |
| 82 | break; |
| 83 | } |
Tim Wawrzynczak | eb3cd85 | 2020-01-22 16:52:13 -0700 | [diff] [blame] | 84 | } |
| 85 | } |
| 86 | |
| 87 | /* |
| 88 | * Apparently these are supposed to be uppercase, in contrast to the other |
| 89 | * lowercase fields. |
| 90 | */ |
| 91 | static const char *port_location_to_str(enum ec_pd_port_location port_location) |
| 92 | { |
| 93 | switch (port_location) { |
| 94 | case EC_PD_PORT_LOCATION_LEFT: |
| 95 | return "LEFT"; |
| 96 | case EC_PD_PORT_LOCATION_RIGHT: |
| 97 | return "RIGHT"; |
| 98 | case EC_PD_PORT_LOCATION_BACK: |
| 99 | return "BACK"; |
| 100 | case EC_PD_PORT_LOCATION_FRONT: |
| 101 | return "FRONT"; |
| 102 | case EC_PD_PORT_LOCATION_LEFT_FRONT: |
| 103 | return "LEFT_FRONT"; |
| 104 | case EC_PD_PORT_LOCATION_LEFT_BACK: |
| 105 | return "LEFT_BACK"; |
| 106 | case EC_PD_PORT_LOCATION_RIGHT_FRONT: |
| 107 | return "RIGHT_FRONT"; |
| 108 | case EC_PD_PORT_LOCATION_RIGHT_BACK: |
| 109 | return "RIGHT_BACK"; |
| 110 | case EC_PD_PORT_LOCATION_BACK_LEFT: |
| 111 | return "BACK_LEFT"; |
| 112 | case EC_PD_PORT_LOCATION_BACK_RIGHT: |
| 113 | return "BACK_RIGHT"; |
| 114 | case EC_PD_PORT_LOCATION_UNKNOWN: /* intentional fallthrough */ |
| 115 | default: |
| 116 | return "UNKNOWN"; |
| 117 | } |
| 118 | } |
| 119 | |
Tim Wawrzynczak | 6da8213 | 2020-05-19 12:46:04 -0600 | [diff] [blame] | 120 | static struct usb_pd_port_caps port_caps; |
| 121 | static void add_port_location(struct acpi_dp *dsd, int port_number) |
Tim Wawrzynczak | eb3cd85 | 2020-01-22 16:52:13 -0700 | [diff] [blame] | 122 | { |
Tim Wawrzynczak | 6da8213 | 2020-05-19 12:46:04 -0600 | [diff] [blame] | 123 | acpi_dp_add_string(dsd, "port-location", |
| 124 | port_location_to_str(port_caps.port_location)); |
Tim Wawrzynczak | 6046739 | 2020-05-18 13:45:43 -0600 | [diff] [blame] | 125 | } |
| 126 | |
Tim Wawrzynczak | e414ce4 | 2020-07-03 09:36:11 -0600 | [diff] [blame^] | 127 | static int conn_id_to_match; |
Tim Wawrzynczak | 16ef59e | 2020-06-01 20:07:45 -0600 | [diff] [blame] | 128 | |
| 129 | /* A callback to match a port's connector for dev_find_matching_device_on_bus */ |
| 130 | static bool match_connector(DEVTREE_CONST struct device *dev) |
| 131 | { |
| 132 | if (CONFIG(DRIVERS_INTEL_PMC)) { |
Tim Wawrzynczak | e414ce4 | 2020-07-03 09:36:11 -0600 | [diff] [blame^] | 133 | extern struct chip_operations drivers_intel_pmc_mux_conn_ops; |
Tim Wawrzynczak | 16ef59e | 2020-06-01 20:07:45 -0600 | [diff] [blame] | 134 | |
Tim Wawrzynczak | e414ce4 | 2020-07-03 09:36:11 -0600 | [diff] [blame^] | 135 | return (dev->chip_ops == &drivers_intel_pmc_mux_conn_ops && |
Tim Wawrzynczak | 16ef59e | 2020-06-01 20:07:45 -0600 | [diff] [blame] | 136 | dev->path.type == DEVICE_PATH_GENERIC && |
Tim Wawrzynczak | e414ce4 | 2020-07-03 09:36:11 -0600 | [diff] [blame^] | 137 | dev->path.generic.id == conn_id_to_match); |
Tim Wawrzynczak | 16ef59e | 2020-06-01 20:07:45 -0600 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | return false; |
| 141 | } |
| 142 | |
Furquan Shaikh | 7536a39 | 2020-04-24 21:59:21 -0700 | [diff] [blame] | 143 | static void fill_ssdt_typec_device(const struct device *dev) |
Tim Wawrzynczak | eb3cd85 | 2020-01-22 16:52:13 -0700 | [diff] [blame] | 144 | { |
Tim Wawrzynczak | eb3cd85 | 2020-01-22 16:52:13 -0700 | [diff] [blame] | 145 | int rv; |
Rajat Jain | 962c788 | 2020-04-01 17:24:28 -0700 | [diff] [blame] | 146 | int i, num_ports; |
Tim Wawrzynczak | 6da8213 | 2020-05-19 12:46:04 -0600 | [diff] [blame] | 147 | struct device *usb2_port; |
| 148 | struct device *usb3_port; |
| 149 | struct device *usb4_port; |
| 150 | const struct device *mux; |
Tim Wawrzynczak | e414ce4 | 2020-07-03 09:36:11 -0600 | [diff] [blame^] | 151 | const struct device *conn; |
Tim Wawrzynczak | eb3cd85 | 2020-01-22 16:52:13 -0700 | [diff] [blame] | 152 | |
Rajat Jain | 962c788 | 2020-04-01 17:24:28 -0700 | [diff] [blame] | 153 | if (google_chromeec_get_num_pd_ports(&num_ports)) |
| 154 | return; |
| 155 | |
Furquan Shaikh | eec30f7 | 2020-04-20 16:38:21 -0700 | [diff] [blame] | 156 | acpigen_write_scope(acpi_device_path(dev)); |
Tim Wawrzynczak | eb3cd85 | 2020-01-22 16:52:13 -0700 | [diff] [blame] | 157 | acpigen_write_device(GOOGLE_CHROMEEC_USBC_DEVICE_NAME); |
| 158 | acpigen_write_name_string("_HID", GOOGLE_CHROMEEC_USBC_DEVICE_HID); |
| 159 | acpigen_write_name_string("_DDN", "ChromeOS EC Embedded Controller " |
| 160 | "USB Type-C Control"); |
| 161 | |
| 162 | for (i = 0; i < num_ports; ++i) { |
| 163 | rv = google_chromeec_get_pd_port_caps(i, &port_caps); |
| 164 | if (rv) |
| 165 | continue; |
| 166 | |
Tim Wawrzynczak | 16ef59e | 2020-06-01 20:07:45 -0600 | [diff] [blame] | 167 | /* Get the MUX device, and find the matching connector on its bus */ |
Tim Wawrzynczak | e414ce4 | 2020-07-03 09:36:11 -0600 | [diff] [blame^] | 168 | conn = NULL; |
Tim Wawrzynczak | 6da8213 | 2020-05-19 12:46:04 -0600 | [diff] [blame] | 169 | mux = soc_get_pmc_mux_device(i); |
Tim Wawrzynczak | 16ef59e | 2020-06-01 20:07:45 -0600 | [diff] [blame] | 170 | if (mux) { |
Tim Wawrzynczak | e414ce4 | 2020-07-03 09:36:11 -0600 | [diff] [blame^] | 171 | conn_id_to_match = i; |
| 172 | conn = dev_find_matching_device_on_bus(mux->link_list, match_connector); |
Tim Wawrzynczak | 16ef59e | 2020-06-01 20:07:45 -0600 | [diff] [blame] | 173 | } |
| 174 | |
Tim Wawrzynczak | 6da8213 | 2020-05-19 12:46:04 -0600 | [diff] [blame] | 175 | usb2_port = NULL; |
| 176 | usb3_port = NULL; |
| 177 | usb4_port = NULL; |
| 178 | get_usb_port_references(i, &usb2_port, &usb3_port, &usb4_port); |
Tim Wawrzynczak | eb3cd85 | 2020-01-22 16:52:13 -0700 | [diff] [blame] | 179 | |
Tim Wawrzynczak | 6da8213 | 2020-05-19 12:46:04 -0600 | [diff] [blame] | 180 | struct typec_connector_class_config config = { |
| 181 | .power_role = port_caps.power_role_cap, |
| 182 | .try_power_role = port_caps.try_power_role_cap, |
| 183 | .data_role = port_caps.data_role_cap, |
| 184 | .usb2_port = usb2_port, |
| 185 | .usb3_port = usb3_port, |
| 186 | .usb4_port = usb4_port, |
Tim Wawrzynczak | e414ce4 | 2020-07-03 09:36:11 -0600 | [diff] [blame^] | 187 | .orientation_switch = conn, |
| 188 | .usb_role_switch = conn, |
| 189 | .mode_switch = conn, |
Tim Wawrzynczak | 6da8213 | 2020-05-19 12:46:04 -0600 | [diff] [blame] | 190 | }; |
Tim Wawrzynczak | eb3cd85 | 2020-01-22 16:52:13 -0700 | [diff] [blame] | 191 | |
Tim Wawrzynczak | 6da8213 | 2020-05-19 12:46:04 -0600 | [diff] [blame] | 192 | acpigen_write_typec_connector(&config, i, add_port_location); |
Tim Wawrzynczak | eb3cd85 | 2020-01-22 16:52:13 -0700 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | acpigen_pop_len(); /* Device GOOGLE_CHROMEEC_USBC_DEVICE_NAME */ |
Rajat Jain | 962c788 | 2020-04-01 17:24:28 -0700 | [diff] [blame] | 196 | acpigen_pop_len(); /* Scope */ |
| 197 | } |
| 198 | |
| 199 | static const enum ps2_action_key ps2_enum_val[] = { |
| 200 | [TK_ABSENT] = PS2_KEY_ABSENT, |
| 201 | [TK_BACK] = PS2_KEY_BACK, |
| 202 | [TK_FORWARD] = PS2_KEY_FORWARD, |
| 203 | [TK_REFRESH] = PS2_KEY_REFRESH, |
| 204 | [TK_FULLSCREEN] = PS2_KEY_FULLSCREEN, |
| 205 | [TK_OVERVIEW] = PS2_KEY_OVERVIEW, |
| 206 | [TK_BRIGHTNESS_DOWN] = PS2_KEY_BRIGHTNESS_DOWN, |
| 207 | [TK_BRIGHTNESS_UP] = PS2_KEY_BRIGHTNESS_UP, |
| 208 | [TK_VOL_MUTE] = PS2_KEY_VOL_MUTE, |
| 209 | [TK_VOL_DOWN] = PS2_KEY_VOL_DOWN, |
| 210 | [TK_VOL_UP] = PS2_KEY_VOL_UP, |
| 211 | [TK_SNAPSHOT] = PS2_KEY_SNAPSHOT, |
| 212 | [TK_PRIVACY_SCRN_TOGGLE] = PS2_KEY_PRIVACY_SCRN_TOGGLE, |
| 213 | [TK_KBD_BKLIGHT_DOWN] = PS2_KEY_KBD_BKLIGHT_DOWN, |
| 214 | [TK_KBD_BKLIGHT_UP] = PS2_KEY_KBD_BKLIGHT_UP, |
| 215 | [TK_PLAY_PAUSE] = PS2_KEY_PLAY_PAUSE, |
| 216 | [TK_NEXT_TRACK] = PS2_KEY_NEXT_TRACK, |
| 217 | [TK_PREV_TRACK] = PS2_KEY_PREV_TRACK, |
| 218 | }; |
| 219 | |
Furquan Shaikh | 7536a39 | 2020-04-24 21:59:21 -0700 | [diff] [blame] | 220 | static void fill_ssdt_ps2_keyboard(const struct device *dev) |
Rajat Jain | 962c788 | 2020-04-01 17:24:28 -0700 | [diff] [blame] | 221 | { |
| 222 | uint8_t i; |
| 223 | struct ec_response_keybd_config keybd = {}; |
| 224 | enum ps2_action_key ps2_action_keys[MAX_TOP_ROW_KEYS] = {}; |
| 225 | |
| 226 | if (google_chromeec_get_keybd_config(&keybd) || |
| 227 | !keybd.num_top_row_keys || |
| 228 | keybd.num_top_row_keys > MAX_TOP_ROW_KEYS) { |
| 229 | printk(BIOS_ERR, "PS2K: Bad resp from EC. Vivaldi disabled!\n"); |
| 230 | return; |
| 231 | } |
| 232 | |
| 233 | /* Convert enum action_key values to enum ps2_action_key values */ |
| 234 | for (i = 0; i < keybd.num_top_row_keys; i++) |
| 235 | ps2_action_keys[i] = ps2_enum_val[keybd.action_keys[i]]; |
| 236 | |
| 237 | acpigen_ps2_keyboard_dsd("_SB.PCI0.PS2K", keybd.num_top_row_keys, |
| 238 | ps2_action_keys, |
| 239 | !!(keybd.capabilities & KEYBD_CAP_FUNCTION_KEYS), |
| 240 | !!(keybd.capabilities & KEYBD_CAP_NUMERIC_KEYPAD), |
| 241 | !!(keybd.capabilities & KEYBD_CAP_SCRNLOCK_KEY)); |
Tim Wawrzynczak | eb3cd85 | 2020-01-22 16:52:13 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Furquan Shaikh | 7536a39 | 2020-04-24 21:59:21 -0700 | [diff] [blame] | 244 | void google_chromeec_fill_ssdt_generator(const struct device *dev) |
Tim Wawrzynczak | eb3cd85 | 2020-01-22 16:52:13 -0700 | [diff] [blame] | 245 | { |
Rajat Jain | 962c788 | 2020-04-01 17:24:28 -0700 | [diff] [blame] | 246 | if (!dev->enabled) |
Matt DeVillier | 70ea3b9 | 2020-03-18 23:45:32 -0500 | [diff] [blame] | 247 | return; |
| 248 | |
Rajat Jain | 962c788 | 2020-04-01 17:24:28 -0700 | [diff] [blame] | 249 | fill_ssdt_typec_device(dev); |
| 250 | fill_ssdt_ps2_keyboard(dev); |
Tim Wawrzynczak | eb3cd85 | 2020-01-22 16:52:13 -0700 | [diff] [blame] | 251 | } |