Furquan Shaikh | 38b349c | 2020-04-19 17:40:22 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Furquan Shaikh | 38b349c | 2020-04-19 17:40:22 -0700 | [diff] [blame] | 2 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 3 | #include <acpi/acpi_device.h> |
| 4 | #include <acpi/acpigen.h> |
Furquan Shaikh | 38b349c | 2020-04-19 17:40:22 -0700 | [diff] [blame] | 5 | #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 Rangel | 77f6627 | 2020-05-20 14:27:27 -0600 | [diff] [blame] | 14 | static void crosec_i2c_tunnel_fill_ssdt(const struct device *dev) |
Furquan Shaikh | 38b349c | 2020-04-19 17:40:22 -0700 | [diff] [blame] | 15 | { |
| 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 | |
| 20 | if (!dev->enabled || !scope || !cfg) |
| 21 | 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 | |
| 42 | static 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 | |
| 54 | static 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 | |
| 62 | static void crosec_i2c_tunnel_enable(struct device *dev) |
| 63 | { |
| 64 | dev->ops = &crosec_i2c_tunnel_ops; |
| 65 | } |
| 66 | |
| 67 | struct chip_operations ec_google_chromeec_i2c_tunnel_ops = { |
| 68 | CHIP_NAME("CrosEC I2C Tunnel Device") |
| 69 | .enable_dev = crosec_i2c_tunnel_enable |
| 70 | }; |