Prashant Malani | 688105b | 2022-04-01 20:19:20 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | |
| 3 | #include <acpi/acpigen.h> |
Elyes Haouas | bdd03c2 | 2024-05-27 11:20:07 +0200 | [diff] [blame^] | 4 | #include <stdio.h> |
Prashant Malani | 688105b | 2022-04-01 20:19:20 +0000 | [diff] [blame] | 5 | |
Prashant Malani | 1e0d2e0 | 2022-06-13 21:51:52 +0000 | [diff] [blame] | 6 | #include "chip.h" |
| 7 | |
Prashant Malani | 688105b | 2022-04-01 20:19:20 +0000 | [diff] [blame] | 8 | static const char *conn_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 | |
| 15 | static void conn_fill_ssdt(const struct device *dev) |
| 16 | { |
Prashant Malani | 1e0d2e0 | 2022-06-13 21:51:52 +0000 | [diff] [blame] | 17 | const struct ec_google_chromeec_mux_conn_config *config = dev->chip_info; |
Prashant Malani | 688105b | 2022-04-01 20:19:20 +0000 | [diff] [blame] | 18 | const char *name; |
| 19 | name = acpi_device_name(dev); |
| 20 | if (!name) |
| 21 | return; |
| 22 | |
| 23 | acpigen_write_scope(acpi_device_scope(dev)); |
| 24 | acpigen_write_device(name); |
| 25 | |
| 26 | acpigen_write_name_integer("_ADR", dev->path.generic.id); |
| 27 | |
Prashant Malani | 8c3fa46 | 2022-12-29 18:46:47 +0000 | [diff] [blame] | 28 | if (config) { |
Prashant Malani | 1e0d2e0 | 2022-06-13 21:51:52 +0000 | [diff] [blame] | 29 | struct acpi_dp *dsd = acpi_dp_new_table("_DSD"); |
Prashant Malani | 8c3fa46 | 2022-12-29 18:46:47 +0000 | [diff] [blame] | 30 | |
| 31 | if (config->mode_switch) |
| 32 | acpi_dp_add_integer(dsd, "mode-switch", 1); |
| 33 | if (config->retimer_switch) |
| 34 | acpi_dp_add_integer(dsd, "retimer-switch", 1); |
| 35 | |
Prashant Malani | 1e0d2e0 | 2022-06-13 21:51:52 +0000 | [diff] [blame] | 36 | acpi_dp_write(dsd); |
| 37 | } |
| 38 | |
Prashant Malani | 688105b | 2022-04-01 20:19:20 +0000 | [diff] [blame] | 39 | acpigen_write_device_end(); |
| 40 | acpigen_write_scope_end(); |
| 41 | } |
| 42 | |
| 43 | static struct device_operations conn_dev_ops = { |
| 44 | .read_resources = noop_read_resources, |
| 45 | .set_resources = noop_set_resources, |
| 46 | .acpi_name = conn_acpi_name, |
| 47 | .acpi_fill_ssdt = conn_fill_ssdt, |
| 48 | }; |
| 49 | |
| 50 | static void conn_enable(struct device *dev) |
| 51 | { |
| 52 | dev->ops = &conn_dev_ops; |
| 53 | } |
| 54 | |
| 55 | struct chip_operations ec_google_chromeec_mux_conn_ops = { |
Nicholas Sudsgaard | bfb11be | 2024-01-30 09:53:46 +0900 | [diff] [blame] | 56 | .name = "CrosEC Type C Mux device", |
Prashant Malani | 688105b | 2022-04-01 20:19:20 +0000 | [diff] [blame] | 57 | .enable_dev = conn_enable, |
| 58 | }; |