Angel Pons | 8a3453f | 2020-04-02 23:48:19 +0200 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 3 | |
| 4 | #include <arch/acpi_device.h> |
| 5 | #include <arch/acpigen.h> |
| 6 | #include <console/console.h> |
Nico Huber | 0f2dd1e | 2017-08-01 14:02:40 +0200 | [diff] [blame] | 7 | #include <device/i2c_simple.h> |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 8 | #include <device/device.h> |
| 9 | #include <device/path.h> |
| 10 | #include <stdint.h> |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 11 | #include "tpm.h" |
| 12 | #include "chip.h" |
| 13 | |
| 14 | static void i2c_tpm_fill_ssdt(struct device *dev) |
| 15 | { |
| 16 | struct drivers_i2c_tpm_config *config = dev->chip_info; |
| 17 | const char *scope = acpi_device_scope(dev); |
| 18 | struct acpi_i2c i2c = { |
| 19 | .address = dev->path.i2c.device, |
| 20 | .mode_10bit = dev->path.i2c.mode_10bit, |
| 21 | .speed = config->speed ? : I2C_SPEED_FAST, |
| 22 | .resource = scope, |
| 23 | }; |
| 24 | |
| 25 | if (!dev->enabled || !scope) |
| 26 | return; |
| 27 | |
| 28 | if (!config->hid) { |
| 29 | printk(BIOS_ERR, "%s: ERROR: HID required\n", dev_path(dev)); |
| 30 | return; |
| 31 | } |
| 32 | |
| 33 | /* Device */ |
| 34 | acpigen_write_scope(scope); |
| 35 | acpigen_write_device(acpi_device_name(dev)); |
| 36 | acpigen_write_name_string("_HID", config->hid); |
| 37 | acpigen_write_name_integer("_UID", config->uid); |
| 38 | acpigen_write_name_string("_DDN", dev->chip_ops->name); |
Hung-Te Lin | b4be50c | 2018-09-10 10:55:49 +0800 | [diff] [blame] | 39 | acpigen_write_STA(acpi_device_status(dev)); |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 40 | |
| 41 | /* Resources */ |
| 42 | acpigen_write_name("_CRS"); |
| 43 | acpigen_write_resourcetemplate_header(); |
| 44 | acpi_device_write_i2c(&i2c); |
Justin TerAvest | ec91dd8 | 2018-01-29 19:14:19 -0700 | [diff] [blame] | 45 | if (config->irq_gpio.pin_count) |
| 46 | acpi_device_write_gpio(&config->irq_gpio); |
| 47 | else |
| 48 | acpi_device_write_interrupt(&config->irq); |
| 49 | |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 50 | acpigen_write_resourcetemplate_footer(); |
| 51 | |
| 52 | acpigen_pop_len(); /* Device */ |
| 53 | acpigen_pop_len(); /* Scope */ |
| 54 | |
| 55 | printk(BIOS_INFO, "%s: %s at %s\n", acpi_device_path(dev), |
| 56 | dev->chip_ops->name, dev_path(dev)); |
| 57 | } |
| 58 | |
Aaron Durbin | aa090cb | 2017-09-13 16:01:52 -0600 | [diff] [blame] | 59 | static const char *i2c_tpm_acpi_name(const struct device *dev) |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 60 | { |
| 61 | return "TPMI"; |
| 62 | } |
| 63 | |
| 64 | static struct device_operations i2c_tpm_ops = { |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 65 | .read_resources = DEVICE_NOOP, |
| 66 | .set_resources = DEVICE_NOOP, |
| 67 | .enable_resources = DEVICE_NOOP, |
| 68 | .acpi_name = i2c_tpm_acpi_name, |
| 69 | .acpi_fill_ssdt = i2c_tpm_fill_ssdt, |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | static void i2c_tpm_enable(struct device *dev) |
| 73 | { |
Naresh G Solanki | 69e9e71 | 2018-06-04 17:45:19 +0530 | [diff] [blame] | 74 | struct drivers_i2c_tpm_config *config = dev->chip_info; |
| 75 | |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 76 | dev->ops = &i2c_tpm_ops; |
Naresh G Solanki | 69e9e71 | 2018-06-04 17:45:19 +0530 | [diff] [blame] | 77 | |
| 78 | if (config && config->desc) { |
| 79 | dev->name = config->desc; |
| 80 | } |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | struct chip_operations drivers_i2c_tpm_ops = { |
| 84 | CHIP_NAME("I2C TPM") |
Elyes HAOUAS | 2aa3b16 | 2018-11-27 17:02:10 +0100 | [diff] [blame] | 85 | .enable_dev = i2c_tpm_enable |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 86 | }; |