| 1 |
|
| 2 |
|
| 3 |
#include <acpi/acpi_device.h> |
| 4 |
#include <acpi/acpigen.h> |
| 5 |
#include <console/console.h> |
| 6 |
#include <device/i2c_simple.h> |
| 7 |
#include <device/device.h> |
| 8 |
#include "tpm.h" |
| 9 |
#include "chip.h" |
| 10 |
|
| 11 |
static void i2c_tpm_fill_ssdt(const struct device *dev) |
| 12 |
{ |
| 13 |
struct acpi_dp *dsd; |
| 14 |
struct drivers_i2c_tpm_config *config = dev->chip_info; |
| 15 |
const char *scope = acpi_device_scope(dev); |
| 16 |
struct acpi_i2c i2c = { |
| 17 |
.address = dev->path.i2c.device, |
| 18 |
.mode_10bit = dev->path.i2c.mode_10bit, |
| 19 |
.speed = config->speed ? : I2C_SPEED_FAST, |
| 20 |
.resource = scope, |
| 21 |
}; |
| 22 |
|
| 23 |
if (!scope) |
| 24 |
return; |
| 25 |
|
| 26 |
if (!config->hid) { |
| 27 |
printk(BIOS_ERR, "%s: ERROR: HID required\n", dev_path(dev)); |
| 28 |
return; |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
acpigen_write_scope(scope); |
| 33 |
acpigen_write_device(acpi_device_name(dev)); |
| 34 |
acpigen_write_name_string("_HID", config->hid); |
| 35 |
acpigen_write_name_integer("_UID", config->uid); |
| 36 |
acpigen_write_name_string("_DDN", dev->chip_ops->name); |
| 37 |
acpigen_write_STA(acpi_device_status(dev)); |
| 38 |
|
| 39 |
|
| 40 |
acpigen_write_name("_CRS"); |
| 41 |
acpigen_write_resourcetemplate_header(); |
| 42 |
acpi_device_write_i2c(&i2c); |
| 43 |
if (config->irq_gpio.pin_count) |
| 44 |
acpi_device_write_gpio(&config->irq_gpio); |
| 45 |
else |
| 46 |
acpi_device_write_interrupt(&config->irq); |
| 47 |
|
| 48 |
acpigen_write_resourcetemplate_footer(); |
| 49 |
|
| 50 |
|
| 51 |
dsd = acpi_dp_new_table("_DSD"); |
| 52 |
switch (config->power_managed_mode) { |
| 53 |
case TPM_FIRMWARE_POWER_MANAGED: |
| 54 |
acpi_dp_add_integer(dsd, "firmware-power-managed", 1); |
| 55 |
break; |
| 56 |
case TPM_KERNEL_POWER_MANAGED: |
| 57 |
acpi_dp_add_integer(dsd, "firmware-power-managed", 0); |
| 58 |
break; |
| 59 |
case TPM_DEFAULT_POWER_MANAGED: |
| 60 |
default: |
| 61 |
|
| 62 |
break; |
| 63 |
} |
| 64 |
acpi_dp_write(dsd); |
| 65 |
|
| 66 |
acpigen_pop_len(); |
| 67 |
acpigen_pop_len(); |
| 68 |
|
| 69 |
printk(BIOS_INFO, "%s: %s at %s\n", acpi_device_path(dev), |
| 70 |
dev->chip_ops->name, dev_path(dev)); |
| 71 |
} |
| 72 |
|
| 73 |
static const char *i2c_tpm_acpi_name(const struct device *dev) |
| 74 |
{ |
| 75 |
return "TPMI"; |
| 76 |
} |
| 77 |
|
| 78 |
static struct device_operations i2c_tpm_ops = { |
| 79 |
.read_resources = noop_read_resources, |
| 80 |
.set_resources = noop_set_resources, |
| 81 |
.acpi_name = i2c_tpm_acpi_name, |
| 82 |
.acpi_fill_ssdt = i2c_tpm_fill_ssdt, |
| 83 |
}; |
| 84 |
|
| 85 |
static void i2c_tpm_enable(struct device *dev) |
| 86 |
{ |
| 87 |
struct drivers_i2c_tpm_config *config = dev->chip_info; |
| 88 |
|
| 89 |
dev->ops = &i2c_tpm_ops; |
| 90 |
|
| 91 |
if (config && config->desc) { |
| 92 |
dev->name = config->desc; |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
struct chip_operations drivers_i2c_tpm_ops = { |
| 97 |
.name = "I2C TPM", |
| 98 |
.enable_dev = i2c_tpm_enable |
| 99 |
}; |