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