blob: ad95905a9f2dd5d069e53ad170287095d2587e85 [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
8static const char *con_acpi_name(const struct device *dev)
9{
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
28static void con_fill_ssdt(const struct device *dev)
29{
30 struct drivers_intel_pmc_mux_con_config *config = dev->chip_info;
31 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
35 if (!dev->enabled)
36 return;
37
38 /* Reference the existing scope and write CONx device */
John Zhaoff4ead02020-06-26 08:53:54 -070039 scope = acpi_device_scope(dev);
40 name = acpi_device_name(dev);
41 if (!scope || !name)
42 return;
43
44 acpigen_write_scope(scope);
45 acpigen_write_device(name);
Tim Wawrzynczake184e392020-05-14 10:23:19 -060046
47 acpigen_write_name_integer("_ADR", dev->path.generic.id);
48
49 /* _DSD, Device-Specific Data */
50 dsd = acpi_dp_new_table("_DSD");
51 acpi_dp_add_integer(dsd, "usb2-port-number", config->usb2_port_number);
52 acpi_dp_add_integer(dsd, "usb3-port-number", config->usb3_port_number);
53
54 /*
55 * The kernel assumes that these Type-C signals (SBUs and HSLs) follow the CC lines,
56 * unless they are explicitly called out otherwise.
57 */
58 if (config->sbu_orientation != TYPEC_ORIENTATION_FOLLOW_CC)
59 acpi_dp_add_string(dsd, "sbu-orientation",
60 orientation_to_str(config->sbu_orientation));
61
62 if (config->hsl_orientation != TYPEC_ORIENTATION_FOLLOW_CC)
63 acpi_dp_add_string(dsd, "hsl-orientation",
64 orientation_to_str(config->hsl_orientation));
65
66 acpi_dp_write(dsd);
67
68 acpigen_pop_len(); /* CONx Device */
69 acpigen_pop_len(); /* Scope */
70
71 printk(BIOS_INFO, "%s: %s at %s\n", acpi_device_path(dev), dev->chip_ops->name,
72 dev_path(dev));
73}
74
75static struct device_operations con_dev_ops = {
76 .read_resources = noop_read_resources,
77 .set_resources = noop_set_resources,
78 .acpi_name = con_acpi_name,
79 .acpi_fill_ssdt = con_fill_ssdt,
80};
81
82static void con_enable(struct device *dev)
83{
84 dev->ops = &con_dev_ops;
85}
86
87struct chip_operations drivers_intel_pmc_mux_con_ops = {
88 CHIP_NAME("Intel PMC MUX CON Driver")
89 .enable_dev = con_enable,
90};