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 | |
Furquan Shaikh | 7536a39 | 2020-04-24 21:59:21 -0700 | [diff] [blame] | 127 | static void fill_ssdt_typec_device(const struct device *dev) |
Tim Wawrzynczak | eb3cd85 | 2020-01-22 16:52:13 -0700 | [diff] [blame] | 128 | { |
Tim Wawrzynczak | eb3cd85 | 2020-01-22 16:52:13 -0700 | [diff] [blame] | 129 | int rv; |
Rajat Jain | 962c788 | 2020-04-01 17:24:28 -0700 | [diff] [blame] | 130 | int i, num_ports; |
Tim Wawrzynczak | 6da8213 | 2020-05-19 12:46:04 -0600 | [diff] [blame^] | 131 | struct device *usb2_port; |
| 132 | struct device *usb3_port; |
| 133 | struct device *usb4_port; |
| 134 | const struct device *mux; |
Tim Wawrzynczak | eb3cd85 | 2020-01-22 16:52:13 -0700 | [diff] [blame] | 135 | |
Rajat Jain | 962c788 | 2020-04-01 17:24:28 -0700 | [diff] [blame] | 136 | if (google_chromeec_get_num_pd_ports(&num_ports)) |
| 137 | return; |
| 138 | |
Furquan Shaikh | eec30f7 | 2020-04-20 16:38:21 -0700 | [diff] [blame] | 139 | acpigen_write_scope(acpi_device_path(dev)); |
Tim Wawrzynczak | eb3cd85 | 2020-01-22 16:52:13 -0700 | [diff] [blame] | 140 | acpigen_write_device(GOOGLE_CHROMEEC_USBC_DEVICE_NAME); |
| 141 | acpigen_write_name_string("_HID", GOOGLE_CHROMEEC_USBC_DEVICE_HID); |
| 142 | acpigen_write_name_string("_DDN", "ChromeOS EC Embedded Controller " |
| 143 | "USB Type-C Control"); |
| 144 | |
| 145 | for (i = 0; i < num_ports; ++i) { |
| 146 | rv = google_chromeec_get_pd_port_caps(i, &port_caps); |
| 147 | if (rv) |
| 148 | continue; |
| 149 | |
Tim Wawrzynczak | 6da8213 | 2020-05-19 12:46:04 -0600 | [diff] [blame^] | 150 | mux = soc_get_pmc_mux_device(i); |
| 151 | usb2_port = NULL; |
| 152 | usb3_port = NULL; |
| 153 | usb4_port = NULL; |
| 154 | get_usb_port_references(i, &usb2_port, &usb3_port, &usb4_port); |
Tim Wawrzynczak | eb3cd85 | 2020-01-22 16:52:13 -0700 | [diff] [blame] | 155 | |
Tim Wawrzynczak | 6da8213 | 2020-05-19 12:46:04 -0600 | [diff] [blame^] | 156 | struct typec_connector_class_config config = { |
| 157 | .power_role = port_caps.power_role_cap, |
| 158 | .try_power_role = port_caps.try_power_role_cap, |
| 159 | .data_role = port_caps.data_role_cap, |
| 160 | .usb2_port = usb2_port, |
| 161 | .usb3_port = usb3_port, |
| 162 | .usb4_port = usb4_port, |
| 163 | .orientation_switch = mux, |
| 164 | .usb_role_switch = mux, |
| 165 | .mode_switch = mux, |
| 166 | }; |
Tim Wawrzynczak | eb3cd85 | 2020-01-22 16:52:13 -0700 | [diff] [blame] | 167 | |
Tim Wawrzynczak | 6da8213 | 2020-05-19 12:46:04 -0600 | [diff] [blame^] | 168 | acpigen_write_typec_connector(&config, i, add_port_location); |
Tim Wawrzynczak | eb3cd85 | 2020-01-22 16:52:13 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | acpigen_pop_len(); /* Device GOOGLE_CHROMEEC_USBC_DEVICE_NAME */ |
Rajat Jain | 962c788 | 2020-04-01 17:24:28 -0700 | [diff] [blame] | 172 | acpigen_pop_len(); /* Scope */ |
| 173 | } |
| 174 | |
| 175 | static const enum ps2_action_key ps2_enum_val[] = { |
| 176 | [TK_ABSENT] = PS2_KEY_ABSENT, |
| 177 | [TK_BACK] = PS2_KEY_BACK, |
| 178 | [TK_FORWARD] = PS2_KEY_FORWARD, |
| 179 | [TK_REFRESH] = PS2_KEY_REFRESH, |
| 180 | [TK_FULLSCREEN] = PS2_KEY_FULLSCREEN, |
| 181 | [TK_OVERVIEW] = PS2_KEY_OVERVIEW, |
| 182 | [TK_BRIGHTNESS_DOWN] = PS2_KEY_BRIGHTNESS_DOWN, |
| 183 | [TK_BRIGHTNESS_UP] = PS2_KEY_BRIGHTNESS_UP, |
| 184 | [TK_VOL_MUTE] = PS2_KEY_VOL_MUTE, |
| 185 | [TK_VOL_DOWN] = PS2_KEY_VOL_DOWN, |
| 186 | [TK_VOL_UP] = PS2_KEY_VOL_UP, |
| 187 | [TK_SNAPSHOT] = PS2_KEY_SNAPSHOT, |
| 188 | [TK_PRIVACY_SCRN_TOGGLE] = PS2_KEY_PRIVACY_SCRN_TOGGLE, |
| 189 | [TK_KBD_BKLIGHT_DOWN] = PS2_KEY_KBD_BKLIGHT_DOWN, |
| 190 | [TK_KBD_BKLIGHT_UP] = PS2_KEY_KBD_BKLIGHT_UP, |
| 191 | [TK_PLAY_PAUSE] = PS2_KEY_PLAY_PAUSE, |
| 192 | [TK_NEXT_TRACK] = PS2_KEY_NEXT_TRACK, |
| 193 | [TK_PREV_TRACK] = PS2_KEY_PREV_TRACK, |
| 194 | }; |
| 195 | |
Furquan Shaikh | 7536a39 | 2020-04-24 21:59:21 -0700 | [diff] [blame] | 196 | static void fill_ssdt_ps2_keyboard(const struct device *dev) |
Rajat Jain | 962c788 | 2020-04-01 17:24:28 -0700 | [diff] [blame] | 197 | { |
| 198 | uint8_t i; |
| 199 | struct ec_response_keybd_config keybd = {}; |
| 200 | enum ps2_action_key ps2_action_keys[MAX_TOP_ROW_KEYS] = {}; |
| 201 | |
| 202 | if (google_chromeec_get_keybd_config(&keybd) || |
| 203 | !keybd.num_top_row_keys || |
| 204 | keybd.num_top_row_keys > MAX_TOP_ROW_KEYS) { |
| 205 | printk(BIOS_ERR, "PS2K: Bad resp from EC. Vivaldi disabled!\n"); |
| 206 | return; |
| 207 | } |
| 208 | |
| 209 | /* Convert enum action_key values to enum ps2_action_key values */ |
| 210 | for (i = 0; i < keybd.num_top_row_keys; i++) |
| 211 | ps2_action_keys[i] = ps2_enum_val[keybd.action_keys[i]]; |
| 212 | |
| 213 | acpigen_ps2_keyboard_dsd("_SB.PCI0.PS2K", keybd.num_top_row_keys, |
| 214 | ps2_action_keys, |
| 215 | !!(keybd.capabilities & KEYBD_CAP_FUNCTION_KEYS), |
| 216 | !!(keybd.capabilities & KEYBD_CAP_NUMERIC_KEYPAD), |
| 217 | !!(keybd.capabilities & KEYBD_CAP_SCRNLOCK_KEY)); |
Tim Wawrzynczak | eb3cd85 | 2020-01-22 16:52:13 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Furquan Shaikh | 7536a39 | 2020-04-24 21:59:21 -0700 | [diff] [blame] | 220 | void google_chromeec_fill_ssdt_generator(const struct device *dev) |
Tim Wawrzynczak | eb3cd85 | 2020-01-22 16:52:13 -0700 | [diff] [blame] | 221 | { |
Rajat Jain | 962c788 | 2020-04-01 17:24:28 -0700 | [diff] [blame] | 222 | if (!dev->enabled) |
Matt DeVillier | 70ea3b9 | 2020-03-18 23:45:32 -0500 | [diff] [blame] | 223 | return; |
| 224 | |
Rajat Jain | 962c788 | 2020-04-01 17:24:28 -0700 | [diff] [blame] | 225 | fill_ssdt_typec_device(dev); |
| 226 | fill_ssdt_ps2_keyboard(dev); |
Tim Wawrzynczak | eb3cd85 | 2020-01-22 16:52:13 -0700 | [diff] [blame] | 227 | } |