blob: 64812d4e8de3f4e0feeed70a559f6f5d699d3fe9 [file] [log] [blame]
Furquan Shaikh38b349c2020-04-19 17:40:22 -07001/* SPDX-License-Identifier: GPL-2.0-or-later */
Furquan Shaikh38b349c2020-04-19 17:40:22 -07002
Furquan Shaikh76cedd22020-05-02 10:24:23 -07003#include <acpi/acpi_device.h>
4#include <acpi/acpigen.h>
Furquan Shaikh38b349c2020-04-19 17:40:22 -07005#include <console/console.h>
6#include <device/device.h>
7#include <device/path.h>
8#include <string.h>
9#include "chip.h"
10
11#define CROS_EC_I2C_TUNNEL_HID "GOOG0012"
12#define CROS_EC_I2C_TUNNEL_DDN "Cros EC I2C Tunnel"
13
Raul E Rangel77f66272020-05-20 14:27:27 -060014static void crosec_i2c_tunnel_fill_ssdt(const struct device *dev)
Furquan Shaikh38b349c2020-04-19 17:40:22 -070015{
16 const char *scope = acpi_device_scope(dev);
17 struct ec_google_chromeec_i2c_tunnel_config *cfg = dev->chip_info;
18 struct acpi_dp *dsd;
19
Karthikeyan Ramasubramaniand1c0f952020-11-02 16:26:52 -070020 if (!scope || !cfg)
Furquan Shaikh38b349c2020-04-19 17:40:22 -070021 return;
22
23 acpigen_write_scope(scope);
24
25 acpigen_write_device(acpi_device_name(dev));
26 acpigen_write_name_string("_HID", CROS_EC_I2C_TUNNEL_HID);
27 acpigen_write_name_integer("_UID", cfg->uid);
28 acpigen_write_name_string("_DDN", CROS_EC_I2C_TUNNEL_DDN);
29 acpigen_write_STA(acpi_device_status(dev));
30
31 dsd = acpi_dp_new_table("_DSD");
32 acpi_dp_add_integer(dsd, "google,remote-bus", cfg->remote_bus);
33 acpi_dp_write(dsd);
34
35 acpigen_pop_len(); /* Device */
36 acpigen_pop_len(); /* Scope */
37
38 printk(BIOS_INFO, "%s: %s at %s\n", acpi_device_path(dev), CROS_EC_I2C_TUNNEL_DDN,
39 dev_path(dev));
40}
41
42static const char *crosec_i2c_tunnel_acpi_name(const struct device *dev)
43{
44 struct ec_google_chromeec_i2c_tunnel_config *cfg = dev->chip_info;
45 static char name[5];
46
47 if (cfg->name)
48 return cfg->name;
49
50 snprintf(name, sizeof(name), "TUN%X", dev->path.generic.id);
51 return name;
52}
53
54static struct device_operations crosec_i2c_tunnel_ops = {
55 .read_resources = noop_read_resources,
56 .set_resources = noop_set_resources,
57 .acpi_name = crosec_i2c_tunnel_acpi_name,
58 .acpi_fill_ssdt = crosec_i2c_tunnel_fill_ssdt,
59 .scan_bus = scan_static_bus,
60};
61
62static void crosec_i2c_tunnel_enable(struct device *dev)
63{
64 dev->ops = &crosec_i2c_tunnel_ops;
65}
66
67struct chip_operations ec_google_chromeec_i2c_tunnel_ops = {
Nicholas Sudsgaardbfb11be2024-01-30 09:53:46 +090068 .name = "CrosEC I2C Tunnel Device",
Furquan Shaikh38b349c2020-04-19 17:40:22 -070069 .enable_dev = crosec_i2c_tunnel_enable
70};