Angel Pons | 8a3453f | 2020-04-02 23:48:19 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -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> |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 5 | #include <console/console.h> |
Nico Huber | 0f2dd1e | 2017-08-01 14:02:40 +0200 | [diff] [blame] | 6 | #include <device/i2c_simple.h> |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 7 | #include <device/device.h> |
| 8 | #include <device/path.h> |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 9 | #include "tpm.h" |
| 10 | #include "chip.h" |
| 11 | |
Furquan Shaikh | 7536a39 | 2020-04-24 21:59:21 -0700 | [diff] [blame] | 12 | static void i2c_tpm_fill_ssdt(const struct device *dev) |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 13 | { |
Rob Barnes | 5e3c454 | 2021-11-18 14:12:46 -0700 | [diff] [blame^] | 14 | struct acpi_dp *dsd; |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 15 | struct drivers_i2c_tpm_config *config = dev->chip_info; |
| 16 | const char *scope = acpi_device_scope(dev); |
| 17 | struct acpi_i2c i2c = { |
| 18 | .address = dev->path.i2c.device, |
| 19 | .mode_10bit = dev->path.i2c.mode_10bit, |
| 20 | .speed = config->speed ? : I2C_SPEED_FAST, |
| 21 | .resource = scope, |
| 22 | }; |
| 23 | |
Karthikeyan Ramasubramanian | d1c0f95 | 2020-11-02 16:26:52 -0700 | [diff] [blame] | 24 | if (!scope) |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 25 | return; |
| 26 | |
| 27 | if (!config->hid) { |
| 28 | printk(BIOS_ERR, "%s: ERROR: HID required\n", dev_path(dev)); |
| 29 | return; |
| 30 | } |
| 31 | |
| 32 | /* Device */ |
| 33 | acpigen_write_scope(scope); |
| 34 | acpigen_write_device(acpi_device_name(dev)); |
| 35 | acpigen_write_name_string("_HID", config->hid); |
| 36 | acpigen_write_name_integer("_UID", config->uid); |
| 37 | acpigen_write_name_string("_DDN", dev->chip_ops->name); |
Hung-Te Lin | b4be50c | 2018-09-10 10:55:49 +0800 | [diff] [blame] | 38 | acpigen_write_STA(acpi_device_status(dev)); |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 39 | |
| 40 | /* Resources */ |
| 41 | acpigen_write_name("_CRS"); |
| 42 | acpigen_write_resourcetemplate_header(); |
| 43 | acpi_device_write_i2c(&i2c); |
Justin TerAvest | ec91dd8 | 2018-01-29 19:14:19 -0700 | [diff] [blame] | 44 | if (config->irq_gpio.pin_count) |
| 45 | acpi_device_write_gpio(&config->irq_gpio); |
| 46 | else |
| 47 | acpi_device_write_interrupt(&config->irq); |
| 48 | |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 49 | acpigen_write_resourcetemplate_footer(); |
| 50 | |
Rob Barnes | 5e3c454 | 2021-11-18 14:12:46 -0700 | [diff] [blame^] | 51 | /* _DSD, Device-Specific Data */ |
| 52 | dsd = acpi_dp_new_table("_DSD"); |
| 53 | switch (config->power_managed_mode) { |
| 54 | case TPM_FIRMWARE_POWER_MANAGED: |
| 55 | acpi_dp_add_integer(dsd, "firmware-power-managed", 1); |
| 56 | break; |
| 57 | case TPM_KERNEL_POWER_MANAGED: |
| 58 | acpi_dp_add_integer(dsd, "firmware-power-managed", 0); |
| 59 | break; |
| 60 | case TPM_DEFAULT_POWER_MANAGED: |
| 61 | default: |
| 62 | /* Leave firmware-power-managed unset */ |
| 63 | } |
| 64 | acpi_dp_write(dsd); |
| 65 | |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 66 | acpigen_pop_len(); /* Device */ |
| 67 | acpigen_pop_len(); /* Scope */ |
| 68 | |
| 69 | printk(BIOS_INFO, "%s: %s at %s\n", acpi_device_path(dev), |
| 70 | dev->chip_ops->name, dev_path(dev)); |
| 71 | } |
| 72 | |
Aaron Durbin | aa090cb | 2017-09-13 16:01:52 -0600 | [diff] [blame] | 73 | static const char *i2c_tpm_acpi_name(const struct device *dev) |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 74 | { |
| 75 | return "TPMI"; |
| 76 | } |
| 77 | |
| 78 | static struct device_operations i2c_tpm_ops = { |
Nico Huber | 2f8ba69 | 2020-04-05 14:05:24 +0200 | [diff] [blame] | 79 | .read_resources = noop_read_resources, |
| 80 | .set_resources = noop_set_resources, |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 81 | .acpi_name = i2c_tpm_acpi_name, |
| 82 | .acpi_fill_ssdt = i2c_tpm_fill_ssdt, |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | static void i2c_tpm_enable(struct device *dev) |
| 86 | { |
Naresh G Solanki | 69e9e71 | 2018-06-04 17:45:19 +0530 | [diff] [blame] | 87 | struct drivers_i2c_tpm_config *config = dev->chip_info; |
| 88 | |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 89 | dev->ops = &i2c_tpm_ops; |
Naresh G Solanki | 69e9e71 | 2018-06-04 17:45:19 +0530 | [diff] [blame] | 90 | |
| 91 | if (config && config->desc) { |
| 92 | dev->name = config->desc; |
| 93 | } |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | struct chip_operations drivers_i2c_tpm_ops = { |
| 97 | CHIP_NAME("I2C TPM") |
Elyes HAOUAS | 2aa3b16 | 2018-11-27 17:02:10 +0100 | [diff] [blame] | 98 | .enable_dev = i2c_tpm_enable |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 99 | }; |