blob: 91d4ebf1df56f962e87d7bf8f1fc61a82c70e1ef [file] [log] [blame]
Karthikeyan Ramasubramaniancbc29a22020-09-30 17:04:15 -06001/* 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>
Karthikeyan Ramasubramaniancbc29a22020-09-30 17:04:15 -06007#include <string.h>
Elyes HAOUAS84bd9dc2021-12-31 18:45:17 +01008
Karthikeyan Ramasubramaniancbc29a22020-09-30 17:04:15 -06009#include "chip.h"
10
11static 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
19static 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
Karthikeyan Ramasubramaniand1c0f952020-11-02 16:26:52 -070029 if (!scope || !path)
Karthikeyan Ramasubramaniancbc29a22020-09-30 17:04:15 -060030 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
62static 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
70static void i2c_gpiomux_mux_enable(struct device *dev)
71{
72 if (!dev)
73 return;
74
75 dev->ops = &i2c_gpiomux_mux_ops;
76}
77
78struct chip_operations drivers_i2c_gpiomux_mux_ops = {
Nicholas Sudsgaardbfb11be2024-01-30 09:53:46 +090079 .name = "I2C GPIO MUX Device",
Karthikeyan Ramasubramaniancbc29a22020-09-30 17:04:15 -060080 .enable_dev = i2c_gpiomux_mux_enable
81};