blob: 5487f6df91c70599a267e6557f04e5f0e8c74f5e [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>
Karthikeyan Ramasubramanianbf089d2a2020-10-07 12:42:44 -06007#include <string.h>
Elyes HAOUAS84bd9dc2021-12-31 18:45:17 +01008
Karthikeyan Ramasubramanianbf089d2a2020-10-07 12:42:44 -06009#include "chip.h"
10
11static 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
19static 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
Karthikeyan Ramasubramaniand1c0f952020-11-02 16:26:52 -070024 if (!dev || !scope || !path)
Karthikeyan Ramasubramanianbf089d2a2020-10-07 12:42:44 -060025 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
40static 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
48static void i2c_gpiomux_bus_enable(struct device *dev)
49{
50 if (!dev)
51 return;
52
53 dev->ops = &i2c_gpiomux_bus_ops;
54}
55
56struct chip_operations drivers_i2c_gpiomux_bus_ops = {
Nicholas Sudsgaardbfb11be2024-01-30 09:53:46 +090057 .name = "I2C GPIO MUX Bus Device",
Karthikeyan Ramasubramanianbf089d2a2020-10-07 12:42:44 -060058 .enable_dev = i2c_gpiomux_bus_enable
59};