blob: 51375f8f22ed167757719a6f5a6223fd72aea4fb [file] [log] [blame]
Furquan Shaikh38b349c2020-04-19 17:40:22 -07001/* SPDX-License-Identifier: GPL-2.0-or-later */
2/* This file is part of the coreboot project. */
3
4#include <arch/acpi_device.h>
5#include <arch/acpigen.h>
6#include <console/console.h>
7#include <device/device.h>
8#include <device/path.h>
9#include <string.h>
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
15static void crosec_i2c_tunnel_fill_ssdt(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 (!dev->enabled || !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
43static 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
55static 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
63static void crosec_i2c_tunnel_enable(struct device *dev)
64{
65 dev->ops = &crosec_i2c_tunnel_ops;
66}
67
68struct chip_operations ec_google_chromeec_i2c_tunnel_ops = {
69 CHIP_NAME("CrosEC I2C Tunnel Device")
70 .enable_dev = crosec_i2c_tunnel_enable
71};