blob: 4fcc679d7079123ff019f7711f3005da5cb48605 [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>
Won Chung667471b2021-11-15 21:19:51 +00005#include <acpi/acpi_pld.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -07006#include <acpi/acpigen.h>
7#include <acpi/acpigen_ps2_keybd.h>
Tim Wawrzynczak6da82132020-05-19 12:46:04 -06008#include <acpi/acpigen_usb.h>
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -07009#include <console/console.h>
10#include <drivers/usb/acpi/chip.h>
John Zhaoeec3e3b2021-01-08 22:33:04 -080011#include <drivers/intel/usb4/retimer/retimer.h>
Tim Wawrzynczak93d7bcb2020-05-29 15:44:25 -060012#include <ec/google/common/dptf.h>
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -070013
14#include "chip.h"
15#include "ec.h"
16#include "ec_commands.h"
17
Karthikeyan Ramasubramaniana95907b2020-04-13 18:03:29 -060018#define GOOGLE_CHROMEEC_USBC_DEVICE_HID "GOOG0014"
19#define GOOGLE_CHROMEEC_USBC_DEVICE_NAME "USBC"
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -070020
21const char *google_chromeec_acpi_name(const struct device *dev)
22{
Furquan Shaikheec30f72020-04-20 16:38:21 -070023 /*
24 * Chrome EC device (CREC - GOOG0004) is really a child of EC device (EC - PNP0C09) in
25 * ACPI tables. However, in coreboot device tree, there is no separate chip/device for
26 * EC0. Thus, Chrome EC device needs to return "EC0.CREC" as the ACPI name so that the
27 * callers can get the correct acpi device path/scope for this device.
28 *
29 * If we ever enable a separate driver for generating AML for EC0 device, then this
30 * function needs to be updated to return "CREC".
31 */
32 return "EC0.CREC";
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -070033}
34
Tim Wawrzynczak6da82132020-05-19 12:46:04 -060035/*
36 * Helper for fill_ssdt_generator. This adds references to the USB
37 * port objects so that the consumer of this information can know
38 * whether the port supports USB2 and/or USB3.
39 */
40static void get_usb_port_references(int port_number, struct device **usb2_port,
41 struct device **usb3_port, struct device **usb4_port)
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -070042{
Tim Wawrzynczak6da82132020-05-19 12:46:04 -060043 struct drivers_usb_acpi_config *config;
44 struct device *port = NULL;
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -070045
Tim Wawrzynczak6da82132020-05-19 12:46:04 -060046 /* Search through the devicetree for matching USB Type-C ports */
47 while ((port = dev_find_path(port, DEVICE_PATH_USB)) != NULL) {
48 if (!port->enabled || port->path.type != DEVICE_PATH_USB)
49 continue;
50
51 config = port->chip_info;
52
53 /* Look at only USB Type-C ports */
54 if ((config->type != UPC_TYPE_C_USB2_ONLY) &&
55 (config->type != UPC_TYPE_C_USB2_SS_SWITCH) &&
56 (config->type != UPC_TYPE_C_USB2_SS))
57 continue;
58
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -070059 /*
Tim Wawrzynczak6da82132020-05-19 12:46:04 -060060 * Check for a matching port number (the 'token' field in 'group'). Note that
61 * 'port_number' is 0-based, whereas the 'token' field is 1-based.
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -070062 */
Tim Wawrzynczak6da82132020-05-19 12:46:04 -060063 if (config->group.token != (port_number + 1))
64 continue;
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -070065
Tim Wawrzynczak6da82132020-05-19 12:46:04 -060066 switch (port->path.usb.port_type) {
67 case 2:
68 *usb2_port = port;
69 break;
70 case 3:
71 *usb3_port = port;
72 break;
73 case 4:
74 *usb4_port = port;
75 break;
76 default:
77 break;
78 }
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -070079 }
80}
81
82/*
83 * Apparently these are supposed to be uppercase, in contrast to the other
84 * lowercase fields.
85 */
86static const char *port_location_to_str(enum ec_pd_port_location port_location)
87{
88 switch (port_location) {
89 case EC_PD_PORT_LOCATION_LEFT:
90 return "LEFT";
91 case EC_PD_PORT_LOCATION_RIGHT:
92 return "RIGHT";
93 case EC_PD_PORT_LOCATION_BACK:
94 return "BACK";
95 case EC_PD_PORT_LOCATION_FRONT:
96 return "FRONT";
97 case EC_PD_PORT_LOCATION_LEFT_FRONT:
98 return "LEFT_FRONT";
99 case EC_PD_PORT_LOCATION_LEFT_BACK:
100 return "LEFT_BACK";
101 case EC_PD_PORT_LOCATION_RIGHT_FRONT:
102 return "RIGHT_FRONT";
103 case EC_PD_PORT_LOCATION_RIGHT_BACK:
104 return "RIGHT_BACK";
105 case EC_PD_PORT_LOCATION_BACK_LEFT:
106 return "BACK_LEFT";
107 case EC_PD_PORT_LOCATION_BACK_RIGHT:
108 return "BACK_RIGHT";
109 case EC_PD_PORT_LOCATION_UNKNOWN: /* intentional fallthrough */
110 default:
111 return "UNKNOWN";
112 }
113}
114
Tim Wawrzynczak6da82132020-05-19 12:46:04 -0600115static struct usb_pd_port_caps port_caps;
116static void add_port_location(struct acpi_dp *dsd, int port_number)
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700117{
Tim Wawrzynczake7881ed2020-09-30 13:12:26 -0600118 acpi_dp_add_string(dsd, "port-location", port_location_to_str(port_caps.port_location));
Tim Wawrzynczak16ef59e2020-06-01 20:07:45 -0600119}
120
Won Chung667471b2021-11-15 21:19:51 +0000121static void get_pld_from_usb_ports(struct acpi_pld *pld,
122 struct device *usb2_port, struct device *usb3_port,
123 struct device *usb4_port)
124{
125 struct drivers_usb_acpi_config *config = NULL;
126
127 if (usb4_port)
128 config = usb4_port->chip_info;
129 else if (usb3_port)
130 config = usb3_port->chip_info;
131 else if (usb2_port)
132 config = usb2_port->chip_info;
133
134 if (config) {
135 if (config->use_custom_pld)
136 *pld = config->custom_pld;
137 else
138 acpi_pld_fill_usb(pld, config->type, &config->group);
139 }
140}
141
Furquan Shaikh7536a392020-04-24 21:59:21 -0700142static void fill_ssdt_typec_device(const struct device *dev)
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700143{
Tim Wawrzynczake7881ed2020-09-30 13:12:26 -0600144 struct ec_google_chromeec_config *config = dev->chip_info;
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700145 int rv;
Divya Sasidharan49d74de2019-10-22 13:41:15 -0700146 int i;
147 unsigned int num_ports;
Tim Wawrzynczak6da82132020-05-19 12:46:04 -0600148 struct device *usb2_port;
149 struct device *usb3_port;
150 struct device *usb4_port;
Won Chung667471b2021-11-15 21:19:51 +0000151 struct acpi_pld pld = {0};
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700152
Rajat Jain962c7882020-04-01 17:24:28 -0700153 if (google_chromeec_get_num_pd_ports(&num_ports))
154 return;
155
Furquan Shaikheec30f72020-04-20 16:38:21 -0700156 acpigen_write_scope(acpi_device_path(dev));
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700157 acpigen_write_device(GOOGLE_CHROMEEC_USBC_DEVICE_NAME);
158 acpigen_write_name_string("_HID", GOOGLE_CHROMEEC_USBC_DEVICE_HID);
159 acpigen_write_name_string("_DDN", "ChromeOS EC Embedded Controller "
160 "USB Type-C Control");
161
162 for (i = 0; i < num_ports; ++i) {
163 rv = google_chromeec_get_pd_port_caps(i, &port_caps);
164 if (rv)
165 continue;
166
Tim Wawrzynczak6da82132020-05-19 12:46:04 -0600167 usb2_port = NULL;
168 usb3_port = NULL;
169 usb4_port = NULL;
170 get_usb_port_references(i, &usb2_port, &usb3_port, &usb4_port);
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700171
Won Chung667471b2021-11-15 21:19:51 +0000172 get_pld_from_usb_ports(&pld, usb2_port, usb3_port, usb4_port);
173
Tim Wawrzynczake7881ed2020-09-30 13:12:26 -0600174 struct typec_connector_class_config typec_config = {
Tim Wawrzynczak6da82132020-05-19 12:46:04 -0600175 .power_role = port_caps.power_role_cap,
176 .try_power_role = port_caps.try_power_role_cap,
177 .data_role = port_caps.data_role_cap,
178 .usb2_port = usb2_port,
179 .usb3_port = usb3_port,
180 .usb4_port = usb4_port,
Tim Wawrzynczake7881ed2020-09-30 13:12:26 -0600181 .orientation_switch = config->mux_conn[i],
182 .usb_role_switch = config->mux_conn[i],
183 .mode_switch = config->mux_conn[i],
Won Chung667471b2021-11-15 21:19:51 +0000184 .pld = &pld,
Tim Wawrzynczak6da82132020-05-19 12:46:04 -0600185 };
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700186
Tim Wawrzynczake7881ed2020-09-30 13:12:26 -0600187 acpigen_write_typec_connector(&typec_config, i, add_port_location);
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700188 }
189
190 acpigen_pop_len(); /* Device GOOGLE_CHROMEEC_USBC_DEVICE_NAME */
Rajat Jain962c7882020-04-01 17:24:28 -0700191 acpigen_pop_len(); /* Scope */
192}
193
194static const enum ps2_action_key ps2_enum_val[] = {
195 [TK_ABSENT] = PS2_KEY_ABSENT,
196 [TK_BACK] = PS2_KEY_BACK,
197 [TK_FORWARD] = PS2_KEY_FORWARD,
198 [TK_REFRESH] = PS2_KEY_REFRESH,
199 [TK_FULLSCREEN] = PS2_KEY_FULLSCREEN,
200 [TK_OVERVIEW] = PS2_KEY_OVERVIEW,
201 [TK_BRIGHTNESS_DOWN] = PS2_KEY_BRIGHTNESS_DOWN,
202 [TK_BRIGHTNESS_UP] = PS2_KEY_BRIGHTNESS_UP,
203 [TK_VOL_MUTE] = PS2_KEY_VOL_MUTE,
204 [TK_VOL_DOWN] = PS2_KEY_VOL_DOWN,
205 [TK_VOL_UP] = PS2_KEY_VOL_UP,
206 [TK_SNAPSHOT] = PS2_KEY_SNAPSHOT,
207 [TK_PRIVACY_SCRN_TOGGLE] = PS2_KEY_PRIVACY_SCRN_TOGGLE,
208 [TK_KBD_BKLIGHT_DOWN] = PS2_KEY_KBD_BKLIGHT_DOWN,
209 [TK_KBD_BKLIGHT_UP] = PS2_KEY_KBD_BKLIGHT_UP,
210 [TK_PLAY_PAUSE] = PS2_KEY_PLAY_PAUSE,
211 [TK_NEXT_TRACK] = PS2_KEY_NEXT_TRACK,
212 [TK_PREV_TRACK] = PS2_KEY_PREV_TRACK,
Scott Chao18141d8c2021-07-30 10:40:57 +0800213 [TK_KBD_BKLIGHT_TOGGLE] = PS2_KEY_KBD_BKLIGHT_TOGGLE,
214 [TK_MICMUTE] = PS2_KEY_MICMUTE,
Rajat Jain962c7882020-04-01 17:24:28 -0700215};
216
Furquan Shaikh7536a392020-04-24 21:59:21 -0700217static void fill_ssdt_ps2_keyboard(const struct device *dev)
Rajat Jain962c7882020-04-01 17:24:28 -0700218{
219 uint8_t i;
220 struct ec_response_keybd_config keybd = {};
221 enum ps2_action_key ps2_action_keys[MAX_TOP_ROW_KEYS] = {};
222
223 if (google_chromeec_get_keybd_config(&keybd) ||
224 !keybd.num_top_row_keys ||
225 keybd.num_top_row_keys > MAX_TOP_ROW_KEYS) {
226 printk(BIOS_ERR, "PS2K: Bad resp from EC. Vivaldi disabled!\n");
227 return;
228 }
229
230 /* Convert enum action_key values to enum ps2_action_key values */
231 for (i = 0; i < keybd.num_top_row_keys; i++)
232 ps2_action_keys[i] = ps2_enum_val[keybd.action_keys[i]];
233
234 acpigen_ps2_keyboard_dsd("_SB.PCI0.PS2K", keybd.num_top_row_keys,
235 ps2_action_keys,
236 !!(keybd.capabilities & KEYBD_CAP_FUNCTION_KEYS),
237 !!(keybd.capabilities & KEYBD_CAP_NUMERIC_KEYPAD),
238 !!(keybd.capabilities & KEYBD_CAP_SCRNLOCK_KEY));
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700239}
240
Tim Wawrzynczak93d7bcb2020-05-29 15:44:25 -0600241static const char *ec_acpi_name(const struct device *dev)
242{
243 return "EC0";
244}
245
246static struct device_operations ec_ops = {
247 .acpi_name = ec_acpi_name,
248};
249
Furquan Shaikh7536a392020-04-24 21:59:21 -0700250void google_chromeec_fill_ssdt_generator(const struct device *dev)
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700251{
Tim Wawrzynczak93d7bcb2020-05-29 15:44:25 -0600252 struct device_path path;
253 struct device *ec;
254
Tim Wawrzynczak93d7bcb2020-05-29 15:44:25 -0600255 /* Set up a minimal EC0 device to pass to the DPTF helpers */
256 path.type = DEVICE_PATH_GENERIC;
257 path.generic.id = 0;
258 ec = alloc_find_dev(dev->bus, &path);
259 ec->ops = &ec_ops;
260
261 if (CONFIG(DRIVERS_INTEL_DPTF))
262 ec_fill_dptf_helpers(ec);
263
Rajat Jain962c7882020-04-01 17:24:28 -0700264 fill_ssdt_typec_device(dev);
265 fill_ssdt_ps2_keyboard(dev);
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700266}
John Zhaoeec3e3b2021-01-08 22:33:04 -0800267
268const char *ec_retimer_fw_update_path(void)
269{
270 return "\\_SB_.PCI0.LPCB.EC0_.RFWU";
271}
John Zhao8bb83a32021-04-27 11:19:41 -0700272
273void ec_retimer_fw_update(uint8_t data)
274{
275 const char *RFWU = ec_retimer_fw_update_path();
276
277 /*
278 * Write the EC RAM for Retimer Upgrade
279 * RFWU = data
280 */
281 acpigen_write_store();
282 acpigen_write_byte(data);
283 acpigen_emit_namestring(RFWU);
284}