xref: /aosp_15_r20/external/coreboot/src/ec/google/chromeec/i2c_tunnel/i2c_tunnel.c (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
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>
8 #include <stdio.h>
9 
10 #include "chip.h"
11 
12 #define CROS_EC_I2C_TUNNEL_HID		"GOOG0012"
13 #define CROS_EC_I2C_TUNNEL_DDN		"Cros EC I2C Tunnel"
14 
crosec_i2c_tunnel_fill_ssdt(const struct device * dev)15 static void crosec_i2c_tunnel_fill_ssdt(const struct device *dev)
16 {
17 	const char *scope = acpi_device_scope(dev);
18 	struct ec_google_chromeec_i2c_tunnel_config *cfg = dev->chip_info;
19 	struct acpi_dp *dsd;
20 
21 	if (!scope || !cfg)
22 		return;
23 
24 	acpigen_write_scope(scope);
25 
26 	acpigen_write_device(acpi_device_name(dev));
27 	acpigen_write_name_string("_HID", CROS_EC_I2C_TUNNEL_HID);
28 	acpigen_write_name_integer("_UID", cfg->uid);
29 	acpigen_write_name_string("_DDN", CROS_EC_I2C_TUNNEL_DDN);
30 	acpigen_write_STA(acpi_device_status(dev));
31 
32 	dsd = acpi_dp_new_table("_DSD");
33 	acpi_dp_add_integer(dsd, "google,remote-bus", cfg->remote_bus);
34 	acpi_dp_write(dsd);
35 
36 	acpigen_pop_len(); /* Device */
37 	acpigen_pop_len(); /* Scope */
38 
39 	printk(BIOS_INFO, "%s: %s at %s\n", acpi_device_path(dev), CROS_EC_I2C_TUNNEL_DDN,
40 						dev_path(dev));
41 }
42 
crosec_i2c_tunnel_acpi_name(const struct device * dev)43 static const char *crosec_i2c_tunnel_acpi_name(const struct device *dev)
44 {
45 	struct ec_google_chromeec_i2c_tunnel_config *cfg = dev->chip_info;
46 	static char name[5];
47 
48 	if (cfg->name)
49 		return cfg->name;
50 
51 	snprintf(name, sizeof(name), "TUN%X", dev->path.generic.id);
52 	return name;
53 }
54 
55 static struct device_operations crosec_i2c_tunnel_ops = {
56 	.read_resources		= noop_read_resources,
57 	.set_resources		= noop_set_resources,
58 	.acpi_name		= crosec_i2c_tunnel_acpi_name,
59 	.acpi_fill_ssdt		= crosec_i2c_tunnel_fill_ssdt,
60 	.scan_bus		= scan_static_bus,
61 };
62 
crosec_i2c_tunnel_enable(struct device * dev)63 static void crosec_i2c_tunnel_enable(struct device *dev)
64 {
65 	dev->ops = &crosec_i2c_tunnel_ops;
66 }
67 
68 struct chip_operations ec_google_chromeec_i2c_tunnel_ops = {
69 	.name = "CrosEC I2C Tunnel Device",
70 	.enable_dev = crosec_i2c_tunnel_enable
71 };
72