blob: a6c603a8f12f34e42aa99b761f1980c2cbf02fbb [file] [log] [blame]
Karthikeyan Ramasubramanianbf089d2a2020-10-07 12:42:44 -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>
7#include <device/path.h>
Karthikeyan Ramasubramanianbf089d2a2020-10-07 12:42:44 -06008#include <string.h>
Elyes HAOUAS84bd9dc2021-12-31 18:45:17 +01009
Karthikeyan Ramasubramanianbf089d2a2020-10-07 12:42:44 -060010#include "chip.h"
11
12static const char *i2c_gpiomux_bus_acpi_name(const struct device *dev)
13{
14 static char name[ACPI_NAME_BUFFER_SIZE];
15
16 snprintf(name, ACPI_NAME_BUFFER_SIZE, "MXA%01.1X", dev->path.generic.id);
17 return name;
18}
19
20static void i2c_gpiomux_bus_fill_ssdt(const struct device *dev)
21{
22 const char *scope = acpi_device_scope(dev);
23 const char *path = acpi_device_path(dev);
24
Karthikeyan Ramasubramaniand1c0f952020-11-02 16:26:52 -070025 if (!dev || !scope || !path)
Karthikeyan Ramasubramanianbf089d2a2020-10-07 12:42:44 -060026 return;
27
28 /* Device */
29 acpigen_write_scope(scope);
30 acpigen_write_device(acpi_device_name(dev));
31
32 acpigen_write_STA(acpi_device_status(dev));
33 acpigen_write_ADR(dev->path.generic.id);
34
35 acpigen_pop_len(); /* Device */
36 acpigen_pop_len(); /* Scope */
37
38 printk(BIOS_INFO, "%s: %s at %s\n", path, dev->chip_ops->name, dev_path(dev));
39}
40
41static struct device_operations i2c_gpiomux_bus_ops = {
42 .read_resources = noop_read_resources,
43 .set_resources = noop_set_resources,
44 .scan_bus = scan_static_bus,
45 .acpi_name = i2c_gpiomux_bus_acpi_name,
46 .acpi_fill_ssdt = i2c_gpiomux_bus_fill_ssdt,
47};
48
49static void i2c_gpiomux_bus_enable(struct device *dev)
50{
51 if (!dev)
52 return;
53
54 dev->ops = &i2c_gpiomux_bus_ops;
55}
56
57struct chip_operations drivers_i2c_gpiomux_bus_ops = {
Nicholas Sudsgaardbfb11be2024-01-30 09:53:46 +090058 .name = "I2C GPIO MUX Bus Device",
Karthikeyan Ramasubramanianbf089d2a2020-10-07 12:42:44 -060059 .enable_dev = i2c_gpiomux_bus_enable
60};