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