blob: 059836485f35911235bfec2cbea08c54912a00a6 [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>
John Zhaoeec3e3b2021-01-08 22:33:04 -080010#include <drivers/intel/usb4/retimer/retimer.h>
Tim Wawrzynczak93d7bcb2020-05-29 15:44:25 -060011#include <ec/google/common/dptf.h>
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -070012
13#include "chip.h"
14#include "ec.h"
15#include "ec_commands.h"
16
Karthikeyan Ramasubramaniana95907b2020-04-13 18:03:29 -060017#define GOOGLE_CHROMEEC_USBC_DEVICE_HID "GOOG0014"
18#define GOOGLE_CHROMEEC_USBC_DEVICE_NAME "USBC"
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -070019
20const char *google_chromeec_acpi_name(const struct device *dev)
21{
Furquan Shaikheec30f72020-04-20 16:38:21 -070022 /*
23 * Chrome EC device (CREC - GOOG0004) is really a child of EC device (EC - PNP0C09) in
24 * ACPI tables. However, in coreboot device tree, there is no separate chip/device for
25 * EC0. Thus, Chrome EC device needs to return "EC0.CREC" as the ACPI name so that the
26 * callers can get the correct acpi device path/scope for this device.
27 *
28 * If we ever enable a separate driver for generating AML for EC0 device, then this
29 * function needs to be updated to return "CREC".
30 */
31 return "EC0.CREC";
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -070032}
33
Tim Wawrzynczak6da82132020-05-19 12:46:04 -060034/*
35 * Helper for fill_ssdt_generator. This adds references to the USB
36 * port objects so that the consumer of this information can know
37 * whether the port supports USB2 and/or USB3.
38 */
39static void get_usb_port_references(int port_number, struct device **usb2_port,
40 struct device **usb3_port, struct device **usb4_port)
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -070041{
Tim Wawrzynczak6da82132020-05-19 12:46:04 -060042 struct drivers_usb_acpi_config *config;
43 struct device *port = NULL;
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -070044
Tim Wawrzynczak6da82132020-05-19 12:46:04 -060045 /* Search through the devicetree for matching USB Type-C ports */
46 while ((port = dev_find_path(port, DEVICE_PATH_USB)) != NULL) {
47 if (!port->enabled || port->path.type != DEVICE_PATH_USB)
48 continue;
49
50 config = port->chip_info;
51
52 /* Look at only USB Type-C ports */
53 if ((config->type != UPC_TYPE_C_USB2_ONLY) &&
54 (config->type != UPC_TYPE_C_USB2_SS_SWITCH) &&
55 (config->type != UPC_TYPE_C_USB2_SS))
56 continue;
57
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -070058 /*
Tim Wawrzynczak6da82132020-05-19 12:46:04 -060059 * Check for a matching port number (the 'token' field in 'group'). Note that
60 * 'port_number' is 0-based, whereas the 'token' field is 1-based.
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -070061 */
Tim Wawrzynczak6da82132020-05-19 12:46:04 -060062 if (config->group.token != (port_number + 1))
63 continue;
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -070064
Tim Wawrzynczak6da82132020-05-19 12:46:04 -060065 switch (port->path.usb.port_type) {
66 case 2:
67 *usb2_port = port;
68 break;
69 case 3:
70 *usb3_port = port;
71 break;
72 case 4:
73 *usb4_port = port;
74 break;
75 default:
76 break;
77 }
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -070078 }
79}
80
81/*
82 * Apparently these are supposed to be uppercase, in contrast to the other
83 * lowercase fields.
84 */
85static const char *port_location_to_str(enum ec_pd_port_location port_location)
86{
87 switch (port_location) {
88 case EC_PD_PORT_LOCATION_LEFT:
89 return "LEFT";
90 case EC_PD_PORT_LOCATION_RIGHT:
91 return "RIGHT";
92 case EC_PD_PORT_LOCATION_BACK:
93 return "BACK";
94 case EC_PD_PORT_LOCATION_FRONT:
95 return "FRONT";
96 case EC_PD_PORT_LOCATION_LEFT_FRONT:
97 return "LEFT_FRONT";
98 case EC_PD_PORT_LOCATION_LEFT_BACK:
99 return "LEFT_BACK";
100 case EC_PD_PORT_LOCATION_RIGHT_FRONT:
101 return "RIGHT_FRONT";
102 case EC_PD_PORT_LOCATION_RIGHT_BACK:
103 return "RIGHT_BACK";
104 case EC_PD_PORT_LOCATION_BACK_LEFT:
105 return "BACK_LEFT";
106 case EC_PD_PORT_LOCATION_BACK_RIGHT:
107 return "BACK_RIGHT";
108 case EC_PD_PORT_LOCATION_UNKNOWN: /* intentional fallthrough */
109 default:
110 return "UNKNOWN";
111 }
112}
113
Tim Wawrzynczak6da82132020-05-19 12:46:04 -0600114static struct usb_pd_port_caps port_caps;
115static void add_port_location(struct acpi_dp *dsd, int port_number)
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700116{
Tim Wawrzynczake7881ed2020-09-30 13:12:26 -0600117 acpi_dp_add_string(dsd, "port-location", port_location_to_str(port_caps.port_location));
Tim Wawrzynczak16ef59e2020-06-01 20:07:45 -0600118}
119
Furquan Shaikh7536a392020-04-24 21:59:21 -0700120static void fill_ssdt_typec_device(const struct device *dev)
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700121{
Tim Wawrzynczake7881ed2020-09-30 13:12:26 -0600122 struct ec_google_chromeec_config *config = dev->chip_info;
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700123 int rv;
Divya Sasidharan49d74de2019-10-22 13:41:15 -0700124 int i;
125 unsigned int num_ports;
Tim Wawrzynczak6da82132020-05-19 12:46:04 -0600126 struct device *usb2_port;
127 struct device *usb3_port;
128 struct device *usb4_port;
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700129
Rajat Jain962c7882020-04-01 17:24:28 -0700130 if (google_chromeec_get_num_pd_ports(&num_ports))
131 return;
132
Furquan Shaikheec30f72020-04-20 16:38:21 -0700133 acpigen_write_scope(acpi_device_path(dev));
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700134 acpigen_write_device(GOOGLE_CHROMEEC_USBC_DEVICE_NAME);
135 acpigen_write_name_string("_HID", GOOGLE_CHROMEEC_USBC_DEVICE_HID);
136 acpigen_write_name_string("_DDN", "ChromeOS EC Embedded Controller "
137 "USB Type-C Control");
138
139 for (i = 0; i < num_ports; ++i) {
140 rv = google_chromeec_get_pd_port_caps(i, &port_caps);
141 if (rv)
142 continue;
143
Tim Wawrzynczak6da82132020-05-19 12:46:04 -0600144 usb2_port = NULL;
145 usb3_port = NULL;
146 usb4_port = NULL;
147 get_usb_port_references(i, &usb2_port, &usb3_port, &usb4_port);
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700148
Tim Wawrzynczake7881ed2020-09-30 13:12:26 -0600149 struct typec_connector_class_config typec_config = {
Tim Wawrzynczak6da82132020-05-19 12:46:04 -0600150 .power_role = port_caps.power_role_cap,
151 .try_power_role = port_caps.try_power_role_cap,
152 .data_role = port_caps.data_role_cap,
153 .usb2_port = usb2_port,
154 .usb3_port = usb3_port,
155 .usb4_port = usb4_port,
Tim Wawrzynczake7881ed2020-09-30 13:12:26 -0600156 .orientation_switch = config->mux_conn[i],
157 .usb_role_switch = config->mux_conn[i],
158 .mode_switch = config->mux_conn[i],
Tim Wawrzynczak6da82132020-05-19 12:46:04 -0600159 };
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700160
Tim Wawrzynczake7881ed2020-09-30 13:12:26 -0600161 acpigen_write_typec_connector(&typec_config, i, add_port_location);
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700162 }
163
164 acpigen_pop_len(); /* Device GOOGLE_CHROMEEC_USBC_DEVICE_NAME */
Rajat Jain962c7882020-04-01 17:24:28 -0700165 acpigen_pop_len(); /* Scope */
166}
167
168static const enum ps2_action_key ps2_enum_val[] = {
169 [TK_ABSENT] = PS2_KEY_ABSENT,
170 [TK_BACK] = PS2_KEY_BACK,
171 [TK_FORWARD] = PS2_KEY_FORWARD,
172 [TK_REFRESH] = PS2_KEY_REFRESH,
173 [TK_FULLSCREEN] = PS2_KEY_FULLSCREEN,
174 [TK_OVERVIEW] = PS2_KEY_OVERVIEW,
175 [TK_BRIGHTNESS_DOWN] = PS2_KEY_BRIGHTNESS_DOWN,
176 [TK_BRIGHTNESS_UP] = PS2_KEY_BRIGHTNESS_UP,
177 [TK_VOL_MUTE] = PS2_KEY_VOL_MUTE,
178 [TK_VOL_DOWN] = PS2_KEY_VOL_DOWN,
179 [TK_VOL_UP] = PS2_KEY_VOL_UP,
180 [TK_SNAPSHOT] = PS2_KEY_SNAPSHOT,
181 [TK_PRIVACY_SCRN_TOGGLE] = PS2_KEY_PRIVACY_SCRN_TOGGLE,
182 [TK_KBD_BKLIGHT_DOWN] = PS2_KEY_KBD_BKLIGHT_DOWN,
183 [TK_KBD_BKLIGHT_UP] = PS2_KEY_KBD_BKLIGHT_UP,
184 [TK_PLAY_PAUSE] = PS2_KEY_PLAY_PAUSE,
185 [TK_NEXT_TRACK] = PS2_KEY_NEXT_TRACK,
186 [TK_PREV_TRACK] = PS2_KEY_PREV_TRACK,
Scott Chao18141d8c2021-07-30 10:40:57 +0800187 [TK_KBD_BKLIGHT_TOGGLE] = PS2_KEY_KBD_BKLIGHT_TOGGLE,
188 [TK_MICMUTE] = PS2_KEY_MICMUTE,
Rajat Jain962c7882020-04-01 17:24:28 -0700189};
190
Furquan Shaikh7536a392020-04-24 21:59:21 -0700191static void fill_ssdt_ps2_keyboard(const struct device *dev)
Rajat Jain962c7882020-04-01 17:24:28 -0700192{
193 uint8_t i;
194 struct ec_response_keybd_config keybd = {};
195 enum ps2_action_key ps2_action_keys[MAX_TOP_ROW_KEYS] = {};
196
197 if (google_chromeec_get_keybd_config(&keybd) ||
198 !keybd.num_top_row_keys ||
199 keybd.num_top_row_keys > MAX_TOP_ROW_KEYS) {
200 printk(BIOS_ERR, "PS2K: Bad resp from EC. Vivaldi disabled!\n");
201 return;
202 }
203
204 /* Convert enum action_key values to enum ps2_action_key values */
205 for (i = 0; i < keybd.num_top_row_keys; i++)
206 ps2_action_keys[i] = ps2_enum_val[keybd.action_keys[i]];
207
208 acpigen_ps2_keyboard_dsd("_SB.PCI0.PS2K", keybd.num_top_row_keys,
209 ps2_action_keys,
210 !!(keybd.capabilities & KEYBD_CAP_FUNCTION_KEYS),
211 !!(keybd.capabilities & KEYBD_CAP_NUMERIC_KEYPAD),
212 !!(keybd.capabilities & KEYBD_CAP_SCRNLOCK_KEY));
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700213}
214
Tim Wawrzynczak93d7bcb2020-05-29 15:44:25 -0600215static const char *ec_acpi_name(const struct device *dev)
216{
217 return "EC0";
218}
219
220static struct device_operations ec_ops = {
221 .acpi_name = ec_acpi_name,
222};
223
Furquan Shaikh7536a392020-04-24 21:59:21 -0700224void google_chromeec_fill_ssdt_generator(const struct device *dev)
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700225{
Tim Wawrzynczak93d7bcb2020-05-29 15:44:25 -0600226 struct device_path path;
227 struct device *ec;
228
Tim Wawrzynczak93d7bcb2020-05-29 15:44:25 -0600229 /* Set up a minimal EC0 device to pass to the DPTF helpers */
230 path.type = DEVICE_PATH_GENERIC;
231 path.generic.id = 0;
232 ec = alloc_find_dev(dev->bus, &path);
233 ec->ops = &ec_ops;
234
235 if (CONFIG(DRIVERS_INTEL_DPTF))
236 ec_fill_dptf_helpers(ec);
237
Rajat Jain962c7882020-04-01 17:24:28 -0700238 fill_ssdt_typec_device(dev);
239 fill_ssdt_ps2_keyboard(dev);
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700240}
John Zhaoeec3e3b2021-01-08 22:33:04 -0800241
242const char *ec_retimer_fw_update_path(void)
243{
244 return "\\_SB_.PCI0.LPCB.EC0_.RFWU";
245}
John Zhao8bb83a32021-04-27 11:19:41 -0700246
247void ec_retimer_fw_update(uint8_t data)
248{
249 const char *RFWU = ec_retimer_fw_update_path();
250
251 /*
252 * Write the EC RAM for Retimer Upgrade
253 * RFWU = data
254 */
255 acpigen_write_store();
256 acpigen_write_byte(data);
257 acpigen_emit_namestring(RFWU);
258}