blob: 344f5f42e56ff8df29d29e4a2b46e03d5ba52233 [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 Wawrzynczak93d7bcb2020-05-29 15:44:25 -060010#include <ec/google/common/dptf.h>
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -070011
12#include "chip.h"
13#include "ec.h"
14#include "ec_commands.h"
15
Karthikeyan Ramasubramaniana95907b2020-04-13 18:03:29 -060016#define GOOGLE_CHROMEEC_USBC_DEVICE_HID "GOOG0014"
17#define GOOGLE_CHROMEEC_USBC_DEVICE_NAME "USBC"
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -070018
19const char *google_chromeec_acpi_name(const struct device *dev)
20{
Furquan Shaikheec30f72020-04-20 16:38:21 -070021 /*
22 * Chrome EC device (CREC - GOOG0004) is really a child of EC device (EC - PNP0C09) in
23 * ACPI tables. However, in coreboot device tree, there is no separate chip/device for
24 * EC0. Thus, Chrome EC device needs to return "EC0.CREC" as the ACPI name so that the
25 * callers can get the correct acpi device path/scope for this device.
26 *
27 * If we ever enable a separate driver for generating AML for EC0 device, then this
28 * function needs to be updated to return "CREC".
29 */
30 return "EC0.CREC";
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -070031}
32
Tim Wawrzynczak6da82132020-05-19 12:46:04 -060033/*
34 * Helper for fill_ssdt_generator. This adds references to the USB
35 * port objects so that the consumer of this information can know
36 * whether the port supports USB2 and/or USB3.
37 */
38static void get_usb_port_references(int port_number, struct device **usb2_port,
39 struct device **usb3_port, struct device **usb4_port)
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -070040{
Tim Wawrzynczak6da82132020-05-19 12:46:04 -060041 struct drivers_usb_acpi_config *config;
42 struct device *port = NULL;
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -070043
Tim Wawrzynczak6da82132020-05-19 12:46:04 -060044 /* Search through the devicetree for matching USB Type-C ports */
45 while ((port = dev_find_path(port, DEVICE_PATH_USB)) != NULL) {
46 if (!port->enabled || port->path.type != DEVICE_PATH_USB)
47 continue;
48
49 config = port->chip_info;
50
51 /* Look at only USB Type-C ports */
52 if ((config->type != UPC_TYPE_C_USB2_ONLY) &&
53 (config->type != UPC_TYPE_C_USB2_SS_SWITCH) &&
54 (config->type != UPC_TYPE_C_USB2_SS))
55 continue;
56
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -070057 /*
Tim Wawrzynczak6da82132020-05-19 12:46:04 -060058 * Check for a matching port number (the 'token' field in 'group'). Note that
59 * 'port_number' is 0-based, whereas the 'token' field is 1-based.
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -070060 */
Tim Wawrzynczak6da82132020-05-19 12:46:04 -060061 if (config->group.token != (port_number + 1))
62 continue;
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -070063
Tim Wawrzynczak6da82132020-05-19 12:46:04 -060064 switch (port->path.usb.port_type) {
65 case 2:
66 *usb2_port = port;
67 break;
68 case 3:
69 *usb3_port = port;
70 break;
71 case 4:
72 *usb4_port = port;
73 break;
74 default:
75 break;
76 }
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -070077 }
78}
79
80/*
81 * Apparently these are supposed to be uppercase, in contrast to the other
82 * lowercase fields.
83 */
84static const char *port_location_to_str(enum ec_pd_port_location port_location)
85{
86 switch (port_location) {
87 case EC_PD_PORT_LOCATION_LEFT:
88 return "LEFT";
89 case EC_PD_PORT_LOCATION_RIGHT:
90 return "RIGHT";
91 case EC_PD_PORT_LOCATION_BACK:
92 return "BACK";
93 case EC_PD_PORT_LOCATION_FRONT:
94 return "FRONT";
95 case EC_PD_PORT_LOCATION_LEFT_FRONT:
96 return "LEFT_FRONT";
97 case EC_PD_PORT_LOCATION_LEFT_BACK:
98 return "LEFT_BACK";
99 case EC_PD_PORT_LOCATION_RIGHT_FRONT:
100 return "RIGHT_FRONT";
101 case EC_PD_PORT_LOCATION_RIGHT_BACK:
102 return "RIGHT_BACK";
103 case EC_PD_PORT_LOCATION_BACK_LEFT:
104 return "BACK_LEFT";
105 case EC_PD_PORT_LOCATION_BACK_RIGHT:
106 return "BACK_RIGHT";
107 case EC_PD_PORT_LOCATION_UNKNOWN: /* intentional fallthrough */
108 default:
109 return "UNKNOWN";
110 }
111}
112
Tim Wawrzynczak6da82132020-05-19 12:46:04 -0600113static struct usb_pd_port_caps port_caps;
114static void add_port_location(struct acpi_dp *dsd, int port_number)
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700115{
Tim Wawrzynczake7881ed2020-09-30 13:12:26 -0600116 acpi_dp_add_string(dsd, "port-location", port_location_to_str(port_caps.port_location));
Tim Wawrzynczak16ef59e2020-06-01 20:07:45 -0600117}
118
Furquan Shaikh7536a392020-04-24 21:59:21 -0700119static void fill_ssdt_typec_device(const struct device *dev)
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700120{
Tim Wawrzynczake7881ed2020-09-30 13:12:26 -0600121 struct ec_google_chromeec_config *config = dev->chip_info;
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700122 int rv;
Divya Sasidharan49d74de2019-10-22 13:41:15 -0700123 int i;
124 unsigned int num_ports;
Tim Wawrzynczak6da82132020-05-19 12:46:04 -0600125 struct device *usb2_port;
126 struct device *usb3_port;
127 struct device *usb4_port;
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700128
Rajat Jain962c7882020-04-01 17:24:28 -0700129 if (google_chromeec_get_num_pd_ports(&num_ports))
130 return;
131
Furquan Shaikheec30f72020-04-20 16:38:21 -0700132 acpigen_write_scope(acpi_device_path(dev));
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700133 acpigen_write_device(GOOGLE_CHROMEEC_USBC_DEVICE_NAME);
134 acpigen_write_name_string("_HID", GOOGLE_CHROMEEC_USBC_DEVICE_HID);
135 acpigen_write_name_string("_DDN", "ChromeOS EC Embedded Controller "
136 "USB Type-C Control");
137
138 for (i = 0; i < num_ports; ++i) {
139 rv = google_chromeec_get_pd_port_caps(i, &port_caps);
140 if (rv)
141 continue;
142
Tim Wawrzynczake7881ed2020-09-30 13:12:26 -0600143 if (!config->mux_conn[i])
144 printk(BIOS_ERR, "ERROR: Mux connector info missing for Type-C port "
145 "#%d\n", i);
Tim Wawrzynczak16ef59e2020-06-01 20:07:45 -0600146
Tim Wawrzynczak6da82132020-05-19 12:46:04 -0600147 usb2_port = NULL;
148 usb3_port = NULL;
149 usb4_port = NULL;
150 get_usb_port_references(i, &usb2_port, &usb3_port, &usb4_port);
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700151
Tim Wawrzynczake7881ed2020-09-30 13:12:26 -0600152 struct typec_connector_class_config typec_config = {
Tim Wawrzynczak6da82132020-05-19 12:46:04 -0600153 .power_role = port_caps.power_role_cap,
154 .try_power_role = port_caps.try_power_role_cap,
155 .data_role = port_caps.data_role_cap,
156 .usb2_port = usb2_port,
157 .usb3_port = usb3_port,
158 .usb4_port = usb4_port,
Tim Wawrzynczake7881ed2020-09-30 13:12:26 -0600159 .orientation_switch = config->mux_conn[i],
160 .usb_role_switch = config->mux_conn[i],
161 .mode_switch = config->mux_conn[i],
Tim Wawrzynczak6da82132020-05-19 12:46:04 -0600162 };
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700163
Tim Wawrzynczake7881ed2020-09-30 13:12:26 -0600164 acpigen_write_typec_connector(&typec_config, i, add_port_location);
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700165 }
166
167 acpigen_pop_len(); /* Device GOOGLE_CHROMEEC_USBC_DEVICE_NAME */
Rajat Jain962c7882020-04-01 17:24:28 -0700168 acpigen_pop_len(); /* Scope */
169}
170
171static const enum ps2_action_key ps2_enum_val[] = {
172 [TK_ABSENT] = PS2_KEY_ABSENT,
173 [TK_BACK] = PS2_KEY_BACK,
174 [TK_FORWARD] = PS2_KEY_FORWARD,
175 [TK_REFRESH] = PS2_KEY_REFRESH,
176 [TK_FULLSCREEN] = PS2_KEY_FULLSCREEN,
177 [TK_OVERVIEW] = PS2_KEY_OVERVIEW,
178 [TK_BRIGHTNESS_DOWN] = PS2_KEY_BRIGHTNESS_DOWN,
179 [TK_BRIGHTNESS_UP] = PS2_KEY_BRIGHTNESS_UP,
180 [TK_VOL_MUTE] = PS2_KEY_VOL_MUTE,
181 [TK_VOL_DOWN] = PS2_KEY_VOL_DOWN,
182 [TK_VOL_UP] = PS2_KEY_VOL_UP,
183 [TK_SNAPSHOT] = PS2_KEY_SNAPSHOT,
184 [TK_PRIVACY_SCRN_TOGGLE] = PS2_KEY_PRIVACY_SCRN_TOGGLE,
185 [TK_KBD_BKLIGHT_DOWN] = PS2_KEY_KBD_BKLIGHT_DOWN,
186 [TK_KBD_BKLIGHT_UP] = PS2_KEY_KBD_BKLIGHT_UP,
187 [TK_PLAY_PAUSE] = PS2_KEY_PLAY_PAUSE,
188 [TK_NEXT_TRACK] = PS2_KEY_NEXT_TRACK,
189 [TK_PREV_TRACK] = PS2_KEY_PREV_TRACK,
190};
191
Furquan Shaikh7536a392020-04-24 21:59:21 -0700192static void fill_ssdt_ps2_keyboard(const struct device *dev)
Rajat Jain962c7882020-04-01 17:24:28 -0700193{
194 uint8_t i;
195 struct ec_response_keybd_config keybd = {};
196 enum ps2_action_key ps2_action_keys[MAX_TOP_ROW_KEYS] = {};
197
198 if (google_chromeec_get_keybd_config(&keybd) ||
199 !keybd.num_top_row_keys ||
200 keybd.num_top_row_keys > MAX_TOP_ROW_KEYS) {
201 printk(BIOS_ERR, "PS2K: Bad resp from EC. Vivaldi disabled!\n");
202 return;
203 }
204
205 /* Convert enum action_key values to enum ps2_action_key values */
206 for (i = 0; i < keybd.num_top_row_keys; i++)
207 ps2_action_keys[i] = ps2_enum_val[keybd.action_keys[i]];
208
209 acpigen_ps2_keyboard_dsd("_SB.PCI0.PS2K", keybd.num_top_row_keys,
210 ps2_action_keys,
211 !!(keybd.capabilities & KEYBD_CAP_FUNCTION_KEYS),
212 !!(keybd.capabilities & KEYBD_CAP_NUMERIC_KEYPAD),
213 !!(keybd.capabilities & KEYBD_CAP_SCRNLOCK_KEY));
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700214}
215
Tim Wawrzynczak93d7bcb2020-05-29 15:44:25 -0600216static const char *ec_acpi_name(const struct device *dev)
217{
218 return "EC0";
219}
220
221static struct device_operations ec_ops = {
222 .acpi_name = ec_acpi_name,
223};
224
Furquan Shaikh7536a392020-04-24 21:59:21 -0700225void google_chromeec_fill_ssdt_generator(const struct device *dev)
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700226{
Tim Wawrzynczak93d7bcb2020-05-29 15:44:25 -0600227 struct device_path path;
228 struct device *ec;
229
Rajat Jain962c7882020-04-01 17:24:28 -0700230 if (!dev->enabled)
Matt DeVillier70ea3b92020-03-18 23:45:32 -0500231 return;
232
Tim Wawrzynczak93d7bcb2020-05-29 15:44:25 -0600233 /* Set up a minimal EC0 device to pass to the DPTF helpers */
234 path.type = DEVICE_PATH_GENERIC;
235 path.generic.id = 0;
236 ec = alloc_find_dev(dev->bus, &path);
237 ec->ops = &ec_ops;
238
239 if (CONFIG(DRIVERS_INTEL_DPTF))
240 ec_fill_dptf_helpers(ec);
241
Rajat Jain962c7882020-04-01 17:24:28 -0700242 fill_ssdt_typec_device(dev);
243 fill_ssdt_ps2_keyboard(dev);
Tim Wawrzynczakeb3cd852020-01-22 16:52:13 -0700244}