blob: 0dbaa9c4565ccbab5c2cd2e28d9ee33575989d4f [file] [log] [blame]
Tim Wawrzynczak6da82132020-05-19 12:46:04 -06001/* SPDX-License-Identifier: GPL-2.0-or-later */
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -07002
Furquan Shaikh76cedd22020-05-02 10:24:23 -07003#include <acpi/acpi.h>
4#include <acpi/acpi_device.h>
5#include <acpi/acpigen.h>
6#include <acpi/acpigen_ps2_keybd.h>
Tim Wawrzynczak6da82132020-05-19 12:46:04 -06007#include <acpi/acpigen_usb.h>
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -07008#include <console/console.h>
9#include <drivers/usb/acpi/chip.h>
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -070010
11#include "chip.h"
12#include "ec.h"
13#include "ec_commands.h"
14
Karthikeyan Ramasubramaniana95907b2020-04-13 18:03:29 -060015#define GOOGLE_CHROMEEC_USBC_DEVICE_HID "GOOG0014"
16#define GOOGLE_CHROMEEC_USBC_DEVICE_NAME "USBC"
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -070017
Tim Wawrzynczak60467392020-05-18 13:45:43 -060018/* Avoid adding a false dependency on an SoC or intel/common */
19extern 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 Wawrzynczakeb3cd852020-01-22 16:52:13 -070026const char *google_chromeec_acpi_name(const struct device *dev)
27{
Furquan Shaikheec30f72020-04-20 16:38:21 -070028 /*
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 Wawrzynczakeb3cd852020-01-22 16:52:13 -070038}
39
Tim Wawrzynczak6da82132020-05-19 12:46:04 -060040/*
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 */
45static void get_usb_port_references(int port_number, struct device **usb2_port,
46 struct device **usb3_port, struct device **usb4_port)
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -070047{
Tim Wawrzynczak6da82132020-05-19 12:46:04 -060048 struct drivers_usb_acpi_config *config;
49 struct device *port = NULL;
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -070050
Tim Wawrzynczak6da82132020-05-19 12:46:04 -060051 /* 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 Wawrzynczakeb3cd852020-01-22 16:52:13 -070064 /*
Tim Wawrzynczak6da82132020-05-19 12:46:04 -060065 * 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 Wawrzynczakeb3cd852020-01-22 16:52:13 -070067 */
Tim Wawrzynczak6da82132020-05-19 12:46:04 -060068 if (config->group.token != (port_number + 1))
69 continue;
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -070070
Tim Wawrzynczak6da82132020-05-19 12:46:04 -060071 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 Wawrzynczakeb3cd852020-01-22 16:52:13 -070084 }
85}
86
87/*
88 * Apparently these are supposed to be uppercase, in contrast to the other
89 * lowercase fields.
90 */
91static 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 Wawrzynczak6da82132020-05-19 12:46:04 -0600120static struct usb_pd_port_caps port_caps;
121static void add_port_location(struct acpi_dp *dsd, int port_number)
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700122{
Tim Wawrzynczak6da82132020-05-19 12:46:04 -0600123 acpi_dp_add_string(dsd, "port-location",
124 port_location_to_str(port_caps.port_location));
Tim Wawrzynczak60467392020-05-18 13:45:43 -0600125}
126
Furquan Shaikh7536a392020-04-24 21:59:21 -0700127static void fill_ssdt_typec_device(const struct device *dev)
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700128{
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700129 int rv;
Rajat Jain962c7882020-04-01 17:24:28 -0700130 int i, num_ports;
Tim Wawrzynczak6da82132020-05-19 12:46:04 -0600131 struct device *usb2_port;
132 struct device *usb3_port;
133 struct device *usb4_port;
134 const struct device *mux;
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700135
Rajat Jain962c7882020-04-01 17:24:28 -0700136 if (google_chromeec_get_num_pd_ports(&num_ports))
137 return;
138
Furquan Shaikheec30f72020-04-20 16:38:21 -0700139 acpigen_write_scope(acpi_device_path(dev));
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700140 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 Wawrzynczak6da82132020-05-19 12:46:04 -0600150 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 Wawrzynczakeb3cd852020-01-22 16:52:13 -0700155
Tim Wawrzynczak6da82132020-05-19 12:46:04 -0600156 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 Wawrzynczakeb3cd852020-01-22 16:52:13 -0700167
Tim Wawrzynczak6da82132020-05-19 12:46:04 -0600168 acpigen_write_typec_connector(&config, i, add_port_location);
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700169 }
170
171 acpigen_pop_len(); /* Device GOOGLE_CHROMEEC_USBC_DEVICE_NAME */
Rajat Jain962c7882020-04-01 17:24:28 -0700172 acpigen_pop_len(); /* Scope */
173}
174
175static 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 Shaikh7536a392020-04-24 21:59:21 -0700196static void fill_ssdt_ps2_keyboard(const struct device *dev)
Rajat Jain962c7882020-04-01 17:24:28 -0700197{
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 Wawrzynczakeb3cd852020-01-22 16:52:13 -0700218}
219
Furquan Shaikh7536a392020-04-24 21:59:21 -0700220void google_chromeec_fill_ssdt_generator(const struct device *dev)
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700221{
Rajat Jain962c7882020-04-01 17:24:28 -0700222 if (!dev->enabled)
Matt DeVillier70ea3b92020-03-18 23:45:32 -0500223 return;
224
Rajat Jain962c7882020-04-01 17:24:28 -0700225 fill_ssdt_typec_device(dev);
226 fill_ssdt_ps2_keyboard(dev);
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700227}