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