• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <acpi/acpi_device.h>
4 #include <acpi/acpigen.h>
5 #include <console/console.h>
6 #include <device/device.h>
7 #include <stdio.h>
8 
9 #include "chip.h"
10 
i2c_gpiomux_mux_acpi_name(const struct device * dev)11 static const char *i2c_gpiomux_mux_acpi_name(const struct device *dev)
12 {
13 	static char name[ACPI_NAME_BUFFER_SIZE];
14 
15 	snprintf(name, ACPI_NAME_BUFFER_SIZE, "MUX%01.1X", dev->path.generic.id);
16 	return name;
17 }
18 
i2c_gpiomux_mux_fill_ssdt(const struct device * dev)19 static void i2c_gpiomux_mux_fill_ssdt(const struct device *dev)
20 {
21 	const char *scope = acpi_device_scope(dev);
22 	const char *path = acpi_device_path(dev);
23 	struct drivers_i2c_gpiomux_mux_config *config = config_of(dev);
24 	struct acpi_dp *dsd = NULL;
25 	const char *compat_string = "i2c-mux-gpio";
26 	struct acpi_gpio_res_params param[MAX_NUM_MUX_GPIOS];
27 	int i;
28 
29 	if (!scope || !path)
30 		return;
31 
32 	/* Device */
33 	acpigen_write_scope(scope);
34 	acpigen_write_device(acpi_device_name(dev));
35 	acpigen_write_name_string("_HID", ACPI_DT_NAMESPACE_HID);
36 	acpigen_write_STA(acpi_device_status(dev));
37 
38 	/* Resources */
39 	acpigen_write_name("_CRS");
40 	acpigen_write_resourcetemplate_header();
41 	for (i = 0; i < config->mux_gpio_count; i++) {
42 		acpi_device_write_gpio(&config->mux_gpio[i]);
43 		param[i].ref = path;
44 		param[i].index = i;
45 		param[i].pin = 0;
46 		param[i].active_low = config->mux_gpio[i].active_low;
47 	}
48 	acpigen_write_resourcetemplate_footer();
49 
50 	/* DSD */
51 	dsd = acpi_dp_new_table("_DSD");
52 	acpi_dp_add_string(dsd, "compatible", compat_string);
53 	acpi_dp_add_gpio_array(dsd, "mux-gpios", param, config->mux_gpio_count);
54 	acpi_dp_write(dsd);
55 
56 	acpigen_pop_len(); /* Device */
57 	acpigen_pop_len(); /* Scope */
58 
59 	printk(BIOS_INFO, "%s: %s at %s\n", path, dev->chip_ops->name, dev_path(dev));
60 }
61 
62 static struct device_operations i2c_gpiomux_mux_ops = {
63 	.read_resources		= noop_read_resources,
64 	.set_resources		= noop_set_resources,
65 	.scan_bus		= scan_static_bus,
66 	.acpi_name		= i2c_gpiomux_mux_acpi_name,
67 	.acpi_fill_ssdt		= i2c_gpiomux_mux_fill_ssdt,
68 };
69 
i2c_gpiomux_mux_enable(struct device * dev)70 static void i2c_gpiomux_mux_enable(struct device *dev)
71 {
72 	if (!dev)
73 		return;
74 
75 	dev->ops = &i2c_gpiomux_mux_ops;
76 }
77 
78 struct chip_operations drivers_i2c_gpiomux_mux_ops = {
79 	.name = "I2C GPIO MUX Device",
80 	.enable_dev = i2c_gpiomux_mux_enable
81 };
82