| 1 |
|
| 2 |
|
| 3 |
#include <acpi/acpi.h> |
| 4 |
#include <acpi/acpi_device.h> |
| 5 |
#include <acpi/acpi_pld.h> |
| 6 |
#include <acpi/acpigen.h> |
| 7 |
#include <acpi/acpigen_ps2_keybd.h> |
| 8 |
#include <acpi/acpigen_usb.h> |
| 9 |
#include <console/console.h> |
| 10 |
#include <drivers/usb/acpi/chip.h> |
| 11 |
#include <drivers/intel/usb4/retimer/retimer.h> |
| 12 |
#include <ec/google/common/dptf.h> |
| 13 |
|
| 14 |
#include "chip.h" |
| 15 |
#include "ec.h" |
| 16 |
#include "ec_commands.h" |
| 17 |
|
| 18 |
#define GOOGLE_CHROMEEC_USBC_DEVICE_HID "GOOG0014" |
| 19 |
#define GOOGLE_CHROMEEC_USBC_DEVICE_NAME "USBC" |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
#define GOOGLE_CHROMEEC_USBC_UCSI_DEVICE_HID "GOOG0021" |
| 26 |
|
| 27 |
const char *google_chromeec_acpi_name(const struct device *dev) |
| 28 |
{ |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
return "EC0.CREC"; |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
static void get_usb_port_references(int port_number, struct device **usb2_port, |
| 47 |
struct device **usb3_port, struct device **usb4_port) |
| 48 |
{ |
| 49 |
struct drivers_usb_acpi_config *config; |
| 50 |
struct device *port = NULL; |
| 51 |
|
| 52 |
|
| 53 |
while ((port = dev_find_path(port, DEVICE_PATH_USB)) != NULL) { |
| 54 |
if (!port->enabled || port->path.type != DEVICE_PATH_USB) |
| 55 |
continue; |
| 56 |
|
| 57 |
config = port->chip_info; |
| 58 |
|
| 59 |
|
| 60 |
if ((config->type != UPC_TYPE_C_USB2_ONLY) && |
| 61 |
(config->type != UPC_TYPE_C_USB2_SS_SWITCH) && |
| 62 |
(config->type != UPC_TYPE_C_USB2_SS)) |
| 63 |
continue; |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
int group_token; |
| 70 |
if (config->use_custom_pld) |
| 71 |
group_token = config->custom_pld.group.token; |
| 72 |
else |
| 73 |
group_token = config->group.token; |
| 74 |
if (group_token != (port_number + 1)) |
| 75 |
continue; |
| 76 |
|
| 77 |
switch (port->path.usb.port_type) { |
| 78 |
case 2: |
| 79 |
*usb2_port = port; |
| 80 |
break; |
| 81 |
case 3: |
| 82 |
*usb3_port = port; |
| 83 |
break; |
| 84 |
case 4: |
| 85 |
*usb4_port = port; |
| 86 |
break; |
| 87 |
default: |
| 88 |
break; |
| 89 |
} |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
static const char *port_location_to_str(enum ec_pd_port_location port_location) |
| 98 |
{ |
| 99 |
switch (port_location) { |
| 100 |
case EC_PD_PORT_LOCATION_LEFT: |
| 101 |
return "LEFT"; |
| 102 |
case EC_PD_PORT_LOCATION_RIGHT: |
| 103 |
return "RIGHT"; |
| 104 |
case EC_PD_PORT_LOCATION_BACK: |
| 105 |
return "BACK"; |
| 106 |
case EC_PD_PORT_LOCATION_FRONT: |
| 107 |
return "FRONT"; |
| 108 |
case EC_PD_PORT_LOCATION_LEFT_FRONT: |
| 109 |
return "LEFT_FRONT"; |
| 110 |
case EC_PD_PORT_LOCATION_LEFT_BACK: |
| 111 |
return "LEFT_BACK"; |
| 112 |
case EC_PD_PORT_LOCATION_RIGHT_FRONT: |
| 113 |
return "RIGHT_FRONT"; |
| 114 |
case EC_PD_PORT_LOCATION_RIGHT_BACK: |
| 115 |
return "RIGHT_BACK"; |
| 116 |
case EC_PD_PORT_LOCATION_BACK_LEFT: |
| 117 |
return "BACK_LEFT"; |
| 118 |
case EC_PD_PORT_LOCATION_BACK_RIGHT: |
| 119 |
return "BACK_RIGHT"; |
| 120 |
case EC_PD_PORT_LOCATION_UNKNOWN: |
| 121 |
__fallthrough; |
| 122 |
default: |
| 123 |
return "UNKNOWN"; |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
static struct usb_pd_port_caps port_caps; |
| 128 |
static void add_port_location(struct acpi_dp *dsd, int port_number) |
| 129 |
{ |
| 130 |
acpi_dp_add_string(dsd, "port-location", port_location_to_str(port_caps.port_location)); |
| 131 |
} |
| 132 |
|
| 133 |
static void get_pld_from_usb_ports(struct acpi_pld *pld, |
| 134 |
struct device *usb2_port, struct device *usb3_port, |
| 135 |
struct device *usb4_port) |
| 136 |
{ |
| 137 |
struct drivers_usb_acpi_config *config = NULL; |
| 138 |
|
| 139 |
if (usb4_port) |
| 140 |
config = usb4_port->chip_info; |
| 141 |
else if (usb3_port) |
| 142 |
config = usb3_port->chip_info; |
| 143 |
else if (usb2_port) |
| 144 |
config = usb2_port->chip_info; |
| 145 |
|
| 146 |
if (config) { |
| 147 |
if (config->use_custom_pld) |
| 148 |
*pld = config->custom_pld; |
| 149 |
else |
| 150 |
acpi_pld_fill_usb(pld, config->type, &config->group); |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
static void fill_ssdt_typec_device(const struct device *dev) |
| 155 |
{ |
| 156 |
struct ec_google_chromeec_config *config = dev->chip_info; |
| 157 |
int rv; |
| 158 |
int i; |
| 159 |
unsigned int num_ports = 0; |
| 160 |
struct device *usb2_port; |
| 161 |
struct device *usb3_port; |
| 162 |
struct device *usb4_port; |
| 163 |
struct acpi_pld pld = {0}; |
| 164 |
uint32_t pcap_mask = 0; |
| 165 |
|
| 166 |
rv = google_chromeec_get_num_pd_ports(&num_ports); |
| 167 |
if (rv || num_ports == 0) |
| 168 |
return; |
| 169 |
|
| 170 |
|
| 171 |
rv = google_chromeec_get_cmd_versions(EC_CMD_GET_PD_PORT_CAPS, &pcap_mask); |
| 172 |
if (rv || pcap_mask == 0) |
| 173 |
return; |
| 174 |
|
| 175 |
acpigen_write_scope(acpi_device_path(dev)); |
| 176 |
acpigen_write_device(GOOGLE_CHROMEEC_USBC_DEVICE_NAME); |
| 177 |
|
| 178 |
bool ucsi_platform = google_chromeec_get_ucsi_enabled(); |
| 179 |
if (ucsi_platform) { |
| 180 |
acpigen_write_name_string("_HID", |
| 181 |
GOOGLE_CHROMEEC_USBC_UCSI_DEVICE_HID); |
| 182 |
acpigen_write_name_string("_DDN", "ChromeOS EC UCSI USB Type-C " |
| 183 |
"Control"); |
| 184 |
} else { |
| 185 |
acpigen_write_name_string("_HID", |
| 186 |
GOOGLE_CHROMEEC_USBC_DEVICE_HID); |
| 187 |
acpigen_write_name_string("_DDN", "ChromeOS EC Embedded " |
| 188 |
"Controller USB Type-C Control"); |
| 189 |
} |
| 190 |
|
| 191 |
for (i = 0; i < num_ports; ++i) { |
| 192 |
rv = google_chromeec_get_pd_port_caps(i, &port_caps); |
| 193 |
if (rv) |
| 194 |
continue; |
| 195 |
|
| 196 |
usb2_port = NULL; |
| 197 |
usb3_port = NULL; |
| 198 |
usb4_port = NULL; |
| 199 |
get_usb_port_references(i, &usb2_port, &usb3_port, &usb4_port); |
| 200 |
|
| 201 |
get_pld_from_usb_ports(&pld, usb2_port, usb3_port, usb4_port); |
| 202 |
|
| 203 |
struct typec_connector_class_config typec_config = { |
| 204 |
.power_role = (enum usb_typec_power_role)port_caps.power_role_cap, |
| 205 |
.try_power_role = |
| 206 |
(enum usb_typec_try_power_role)port_caps.try_power_role_cap, |
| 207 |
.data_role = (enum usb_typec_data_role)port_caps.data_role_cap, |
| 208 |
.usb2_port = usb2_port, |
| 209 |
.usb3_port = usb3_port, |
| 210 |
.usb4_port = usb4_port, |
| 211 |
.orientation_switch = config->mux_conn[i], |
| 212 |
.usb_role_switch = config->mux_conn[i], |
| 213 |
.mode_switch = config->mux_conn[i], |
| 214 |
.retimer_switch = config->retimer_conn[i], |
| 215 |
.pld = &pld, |
| 216 |
}; |
| 217 |
|
| 218 |
acpigen_write_typec_connector(&typec_config, i, add_port_location); |
| 219 |
} |
| 220 |
|
| 221 |
acpigen_pop_len(); |
| 222 |
acpigen_pop_len(); |
| 223 |
} |
| 224 |
|
| 225 |
static const enum ps2_action_key ps2_enum_val[] = { |
| 226 |
[TK_ABSENT] = PS2_KEY_ABSENT, |
| 227 |
[TK_BACK] = PS2_KEY_BACK, |
| 228 |
[TK_FORWARD] = PS2_KEY_FORWARD, |
| 229 |
[TK_REFRESH] = PS2_KEY_REFRESH, |
| 230 |
[TK_FULLSCREEN] = PS2_KEY_FULLSCREEN, |
| 231 |
[TK_OVERVIEW] = PS2_KEY_OVERVIEW, |
| 232 |
[TK_BRIGHTNESS_DOWN] = PS2_KEY_BRIGHTNESS_DOWN, |
| 233 |
[TK_BRIGHTNESS_UP] = PS2_KEY_BRIGHTNESS_UP, |
| 234 |
[TK_VOL_MUTE] = PS2_KEY_VOL_MUTE, |
| 235 |
[TK_VOL_DOWN] = PS2_KEY_VOL_DOWN, |
| 236 |
[TK_VOL_UP] = PS2_KEY_VOL_UP, |
| 237 |
[TK_SNAPSHOT] = PS2_KEY_SNAPSHOT, |
| 238 |
[TK_PRIVACY_SCRN_TOGGLE] = PS2_KEY_PRIVACY_SCRN_TOGGLE, |
| 239 |
[TK_KBD_BKLIGHT_DOWN] = PS2_KEY_KBD_BKLIGHT_DOWN, |
| 240 |
[TK_KBD_BKLIGHT_UP] = PS2_KEY_KBD_BKLIGHT_UP, |
| 241 |
[TK_PLAY_PAUSE] = PS2_KEY_PLAY_PAUSE, |
| 242 |
[TK_NEXT_TRACK] = PS2_KEY_NEXT_TRACK, |
| 243 |
[TK_PREV_TRACK] = PS2_KEY_PREV_TRACK, |
| 244 |
[TK_KBD_BKLIGHT_TOGGLE] = PS2_KEY_KBD_BKLIGHT_TOGGLE, |
| 245 |
[TK_MICMUTE] = PS2_KEY_MICMUTE, |
| 246 |
[TK_MENU] = PS2_KEY_MENU, |
| 247 |
[TK_DICTATE] = PS2_KEY_DICTATE, |
| 248 |
[TK_ACCESSIBILITY] = PS2_KEY_ACCESSIBILITY, |
| 249 |
[TK_DONOTDISTURB] = PS2_KEY_DO_NOT_DISTURB, |
| 250 |
}; |
| 251 |
|
| 252 |
static void fill_ssdt_ps2_keyboard(const struct device *dev) |
| 253 |
{ |
| 254 |
uint8_t i; |
| 255 |
struct ec_response_keybd_config keybd = {}; |
| 256 |
enum ps2_action_key ps2_action_keys[MAX_TOP_ROW_KEYS] = {}; |
| 257 |
|
| 258 |
if (google_chromeec_get_keybd_config(&keybd) || |
| 259 |
!keybd.num_top_row_keys || |
| 260 |
keybd.num_top_row_keys > MAX_TOP_ROW_KEYS) { |
| 261 |
printk(BIOS_INFO, "PS2K: Unsupported or bad resp from EC. Vivaldi disabled!\n"); |
| 262 |
return; |
| 263 |
} |
| 264 |
|
| 265 |
|
| 266 |
for (i = 0; i < keybd.num_top_row_keys; i++) |
| 267 |
ps2_action_keys[i] = ps2_enum_val[keybd.action_keys[i]]; |
| 268 |
|
| 269 |
acpigen_ps2_keyboard_dsd("_SB.PCI0.PS2K", keybd.num_top_row_keys, |
| 270 |
ps2_action_keys, |
| 271 |
!!(keybd.capabilities & KEYBD_CAP_FUNCTION_KEYS), |
| 272 |
!!(keybd.capabilities & KEYBD_CAP_NUMERIC_KEYPAD), |
| 273 |
!!(keybd.capabilities & KEYBD_CAP_SCRNLOCK_KEY), |
| 274 |
!!(keybd.capabilities & KEYBD_CAP_ASSISTANT_KEY), |
| 275 |
true); |
| 276 |
} |
| 277 |
|
| 278 |
static const char *ec_acpi_name(const struct device *dev) |
| 279 |
{ |
| 280 |
return "EC0"; |
| 281 |
} |
| 282 |
|
| 283 |
static struct device_operations ec_ops = { |
| 284 |
.acpi_name = ec_acpi_name, |
| 285 |
}; |
| 286 |
|
| 287 |
void google_chromeec_fill_ssdt_generator(const struct device *dev) |
| 288 |
{ |
| 289 |
struct device_path path; |
| 290 |
struct device *ec; |
| 291 |
|
| 292 |
|
| 293 |
path.type = DEVICE_PATH_GENERIC; |
| 294 |
path.generic.id = 0; |
| 295 |
path.generic.subid = 0; |
| 296 |
ec = alloc_find_dev(dev->upstream, &path); |
| 297 |
ec->ops = &ec_ops; |
| 298 |
|
| 299 |
if (CONFIG(DRIVERS_INTEL_DPTF)) |
| 300 |
ec_fill_dptf_helpers(ec, dev); |
| 301 |
|
| 302 |
fill_ssdt_typec_device(dev); |
| 303 |
fill_ssdt_ps2_keyboard(dev); |
| 304 |
} |
| 305 |
|
| 306 |
const char *ec_retimer_fw_update_path(void) |
| 307 |
{ |
| 308 |
return "\\_SB_.PCI0.LPCB.EC0_.RFWU"; |
| 309 |
} |
| 310 |
|
| 311 |
void ec_retimer_fw_update(uint8_t data) |
| 312 |
{ |
| 313 |
const char *RFWU = ec_retimer_fw_update_path(); |
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
acpigen_write_store(); |
| 320 |
acpigen_write_byte(data); |
| 321 |
acpigen_emit_namestring(RFWU); |
| 322 |
} |