Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; version 2 of the License. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
| 14 | #include <arch/acpi_device.h> |
| 15 | #include <arch/acpigen.h> |
| 16 | #include <console/console.h> |
Nico Huber | 0f2dd1e | 2017-08-01 14:02:40 +0200 | [diff] [blame] | 17 | #include <device/i2c_simple.h> |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 18 | #include <device/device.h> |
| 19 | #include <device/path.h> |
| 20 | #include <stdint.h> |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 21 | #include "tpm.h" |
| 22 | #include "chip.h" |
| 23 | |
| 24 | static void i2c_tpm_fill_ssdt(struct device *dev) |
| 25 | { |
| 26 | struct drivers_i2c_tpm_config *config = dev->chip_info; |
| 27 | const char *scope = acpi_device_scope(dev); |
| 28 | struct acpi_i2c i2c = { |
| 29 | .address = dev->path.i2c.device, |
| 30 | .mode_10bit = dev->path.i2c.mode_10bit, |
| 31 | .speed = config->speed ? : I2C_SPEED_FAST, |
| 32 | .resource = scope, |
| 33 | }; |
| 34 | |
| 35 | if (!dev->enabled || !scope) |
| 36 | return; |
| 37 | |
| 38 | if (!config->hid) { |
| 39 | printk(BIOS_ERR, "%s: ERROR: HID required\n", dev_path(dev)); |
| 40 | return; |
| 41 | } |
| 42 | |
| 43 | /* Device */ |
| 44 | acpigen_write_scope(scope); |
| 45 | acpigen_write_device(acpi_device_name(dev)); |
| 46 | acpigen_write_name_string("_HID", config->hid); |
| 47 | acpigen_write_name_integer("_UID", config->uid); |
| 48 | acpigen_write_name_string("_DDN", dev->chip_ops->name); |
Hung-Te Lin | b4be50c | 2018-09-10 10:55:49 +0800 | [diff] [blame] | 49 | acpigen_write_STA(acpi_device_status(dev)); |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 50 | |
| 51 | /* Resources */ |
| 52 | acpigen_write_name("_CRS"); |
| 53 | acpigen_write_resourcetemplate_header(); |
| 54 | acpi_device_write_i2c(&i2c); |
Justin TerAvest | ec91dd8 | 2018-01-29 19:14:19 -0700 | [diff] [blame] | 55 | if (config->irq_gpio.pin_count) |
| 56 | acpi_device_write_gpio(&config->irq_gpio); |
| 57 | else |
| 58 | acpi_device_write_interrupt(&config->irq); |
| 59 | |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 60 | acpigen_write_resourcetemplate_footer(); |
| 61 | |
| 62 | acpigen_pop_len(); /* Device */ |
| 63 | acpigen_pop_len(); /* Scope */ |
| 64 | |
| 65 | printk(BIOS_INFO, "%s: %s at %s\n", acpi_device_path(dev), |
| 66 | dev->chip_ops->name, dev_path(dev)); |
| 67 | } |
| 68 | |
Aaron Durbin | aa090cb | 2017-09-13 16:01:52 -0600 | [diff] [blame] | 69 | static const char *i2c_tpm_acpi_name(const struct device *dev) |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 70 | { |
| 71 | return "TPMI"; |
| 72 | } |
| 73 | |
| 74 | static struct device_operations i2c_tpm_ops = { |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame^] | 75 | .read_resources = DEVICE_NOOP, |
| 76 | .set_resources = DEVICE_NOOP, |
| 77 | .enable_resources = DEVICE_NOOP, |
| 78 | .acpi_name = i2c_tpm_acpi_name, |
| 79 | .acpi_fill_ssdt = i2c_tpm_fill_ssdt, |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | static void i2c_tpm_enable(struct device *dev) |
| 83 | { |
Naresh G Solanki | 69e9e71 | 2018-06-04 17:45:19 +0530 | [diff] [blame] | 84 | struct drivers_i2c_tpm_config *config = dev->chip_info; |
| 85 | |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 86 | dev->ops = &i2c_tpm_ops; |
Naresh G Solanki | 69e9e71 | 2018-06-04 17:45:19 +0530 | [diff] [blame] | 87 | |
| 88 | if (config && config->desc) { |
| 89 | dev->name = config->desc; |
| 90 | } |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | struct chip_operations drivers_i2c_tpm_ops = { |
| 94 | CHIP_NAME("I2C TPM") |
Elyes HAOUAS | 2aa3b16 | 2018-11-27 17:02:10 +0100 | [diff] [blame] | 95 | .enable_dev = i2c_tpm_enable |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 96 | }; |