blob: b6bf3714714375256d5b4855e64d04692df96d80 [file] [log] [blame]
Tim Wawrzynczake184e392020-05-14 10:23:19 -06001/* SPDX-License-Identifier: GPL-2.0-or-later */
2
3#include <acpi/acpigen.h>
4#include <console/console.h>
5#include <intelblocks/acpi.h>
6#include "chip.h"
7
Tim Wawrzynczake414ce42020-07-03 09:36:11 -06008static const char *conn_acpi_name(const struct device *dev)
Tim Wawrzynczake184e392020-05-14 10:23:19 -06009{
10 static char name[5];
11 snprintf(name, sizeof(name), "CON%1X", dev->path.generic.id);
12 return name;
13}
14
15static const char *orientation_to_str(enum typec_orientation ori)
16{
17 switch (ori) {
18 case TYPEC_ORIENTATION_NORMAL:
19 return "normal";
20 case TYPEC_ORIENTATION_REVERSE:
21 return "reverse";
22 case TYPEC_ORIENTATION_FOLLOW_CC: /* Intentional fallthrough */
23 default:
24 return "";
25 }
26}
27
Tim Wawrzynczake414ce42020-07-03 09:36:11 -060028static void conn_fill_ssdt(const struct device *dev)
Tim Wawrzynczake184e392020-05-14 10:23:19 -060029{
Tim Wawrzynczake414ce42020-07-03 09:36:11 -060030 struct drivers_intel_pmc_mux_conn_config *config = dev->chip_info;
Tim Wawrzynczake184e392020-05-14 10:23:19 -060031 struct acpi_dp *dsd;
John Zhaoff4ead02020-06-26 08:53:54 -070032 const char *scope;
33 const char *name;
Tim Wawrzynczake184e392020-05-14 10:23:19 -060034
Tim Wawrzynczake184e392020-05-14 10:23:19 -060035 /* Reference the existing scope and write CONx device */
John Zhaoff4ead02020-06-26 08:53:54 -070036 scope = acpi_device_scope(dev);
37 name = acpi_device_name(dev);
38 if (!scope || !name)
39 return;
40
41 acpigen_write_scope(scope);
42 acpigen_write_device(name);
Tim Wawrzynczake184e392020-05-14 10:23:19 -060043
44 acpigen_write_name_integer("_ADR", dev->path.generic.id);
45
46 /* _DSD, Device-Specific Data */
47 dsd = acpi_dp_new_table("_DSD");
48 acpi_dp_add_integer(dsd, "usb2-port-number", config->usb2_port_number);
49 acpi_dp_add_integer(dsd, "usb3-port-number", config->usb3_port_number);
50
51 /*
52 * The kernel assumes that these Type-C signals (SBUs and HSLs) follow the CC lines,
53 * unless they are explicitly called out otherwise.
54 */
55 if (config->sbu_orientation != TYPEC_ORIENTATION_FOLLOW_CC)
56 acpi_dp_add_string(dsd, "sbu-orientation",
57 orientation_to_str(config->sbu_orientation));
58
59 if (config->hsl_orientation != TYPEC_ORIENTATION_FOLLOW_CC)
60 acpi_dp_add_string(dsd, "hsl-orientation",
61 orientation_to_str(config->hsl_orientation));
62
63 acpi_dp_write(dsd);
64
65 acpigen_pop_len(); /* CONx Device */
66 acpigen_pop_len(); /* Scope */
67
68 printk(BIOS_INFO, "%s: %s at %s\n", acpi_device_path(dev), dev->chip_ops->name,
69 dev_path(dev));
70}
71
Tim Wawrzynczake414ce42020-07-03 09:36:11 -060072static struct device_operations conn_dev_ops = {
Tim Wawrzynczake184e392020-05-14 10:23:19 -060073 .read_resources = noop_read_resources,
74 .set_resources = noop_set_resources,
Tim Wawrzynczake414ce42020-07-03 09:36:11 -060075 .acpi_name = conn_acpi_name,
76 .acpi_fill_ssdt = conn_fill_ssdt,
Tim Wawrzynczake184e392020-05-14 10:23:19 -060077};
78
Tim Wawrzynczake414ce42020-07-03 09:36:11 -060079static void conn_enable(struct device *dev)
Tim Wawrzynczake184e392020-05-14 10:23:19 -060080{
Tim Wawrzynczake414ce42020-07-03 09:36:11 -060081 dev->ops = &conn_dev_ops;
Tim Wawrzynczake184e392020-05-14 10:23:19 -060082}
83
Tim Wawrzynczake414ce42020-07-03 09:36:11 -060084struct chip_operations drivers_intel_pmc_mux_conn_ops = {
85 CHIP_NAME("Intel PMC MUX CONN Driver")
86 .enable_dev = conn_enable,
Tim Wawrzynczake184e392020-05-14 10:23:19 -060087};
Deepti Deshattyc146daf2021-05-20 21:01:52 +053088
89bool intel_pmc_mux_conn_get_ports(const struct device *conn, unsigned int *usb2_port,
90 unsigned int *usb3_port)
91{
92 const struct drivers_intel_pmc_mux_conn_config *mux_config;
93
94 if (!conn->chip_info || conn->chip_ops != &drivers_intel_pmc_mux_conn_ops)
95 return false;
96
97 mux_config = conn->chip_info;
98 *usb2_port = mux_config->usb2_port_number;
99 *usb3_port = mux_config->usb3_port_number;
100
101 return true;
102};