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_bus_acpi_name(const struct device * dev)11 static const char *i2c_gpiomux_bus_acpi_name(const struct device *dev)
12 {
13 static char name[ACPI_NAME_BUFFER_SIZE];
14
15 snprintf(name, ACPI_NAME_BUFFER_SIZE, "MXA%01.1X", dev->path.generic.id);
16 return name;
17 }
18
i2c_gpiomux_bus_fill_ssdt(const struct device * dev)19 static void i2c_gpiomux_bus_fill_ssdt(const struct device *dev)
20 {
21 const char *scope = acpi_device_scope(dev);
22 const char *path = acpi_device_path(dev);
23
24 if (!dev || !scope || !path)
25 return;
26
27 /* Device */
28 acpigen_write_scope(scope);
29 acpigen_write_device(acpi_device_name(dev));
30
31 acpigen_write_STA(acpi_device_status(dev));
32 acpigen_write_ADR(dev->path.generic.id);
33
34 acpigen_pop_len(); /* Device */
35 acpigen_pop_len(); /* Scope */
36
37 printk(BIOS_INFO, "%s: %s at %s\n", path, dev->chip_ops->name, dev_path(dev));
38 }
39
40 static struct device_operations i2c_gpiomux_bus_ops = {
41 .read_resources = noop_read_resources,
42 .set_resources = noop_set_resources,
43 .scan_bus = scan_static_bus,
44 .acpi_name = i2c_gpiomux_bus_acpi_name,
45 .acpi_fill_ssdt = i2c_gpiomux_bus_fill_ssdt,
46 };
47
i2c_gpiomux_bus_enable(struct device * dev)48 static void i2c_gpiomux_bus_enable(struct device *dev)
49 {
50 if (!dev)
51 return;
52
53 dev->ops = &i2c_gpiomux_bus_ops;
54 }
55
56 struct chip_operations drivers_i2c_gpiomux_bus_ops = {
57 .name = "I2C GPIO MUX Bus Device",
58 .enable_dev = i2c_gpiomux_bus_enable
59 };
60