blob: d36e4c2932b7fcfb208402aa138e0be5902a3786 [file] [log] [blame]
Duncan Laurie6eb8e1d2016-09-01 15:56:44 -07001/*
2 * This file is part of the coreboot project.
3 *
Duncan Laurie6eb8e1d2016-09-01 15:56:44 -07004 * 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 Huber0f2dd1e2017-08-01 14:02:40 +020017#include <device/i2c_simple.h>
Duncan Laurie6eb8e1d2016-09-01 15:56:44 -070018#include <device/device.h>
19#include <device/path.h>
20#include <stdint.h>
Duncan Laurie6eb8e1d2016-09-01 15:56:44 -070021#include "tpm.h"
22#include "chip.h"
23
24static 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 Linb4be50c2018-09-10 10:55:49 +080049 acpigen_write_STA(acpi_device_status(dev));
Duncan Laurie6eb8e1d2016-09-01 15:56:44 -070050
51 /* Resources */
52 acpigen_write_name("_CRS");
53 acpigen_write_resourcetemplate_header();
54 acpi_device_write_i2c(&i2c);
Justin TerAvestec91dd82018-01-29 19:14:19 -070055 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 Laurie6eb8e1d2016-09-01 15:56:44 -070060 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 Durbinaa090cb2017-09-13 16:01:52 -060069static const char *i2c_tpm_acpi_name(const struct device *dev)
Duncan Laurie6eb8e1d2016-09-01 15:56:44 -070070{
71 return "TPMI";
72}
73
74static struct device_operations i2c_tpm_ops = {
Nico Huber68680dd2020-03-31 17:34:52 +020075 .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 Laurie6eb8e1d2016-09-01 15:56:44 -070080};
81
82static void i2c_tpm_enable(struct device *dev)
83{
Naresh G Solanki69e9e712018-06-04 17:45:19 +053084 struct drivers_i2c_tpm_config *config = dev->chip_info;
85
Duncan Laurie6eb8e1d2016-09-01 15:56:44 -070086 dev->ops = &i2c_tpm_ops;
Naresh G Solanki69e9e712018-06-04 17:45:19 +053087
88 if (config && config->desc) {
89 dev->name = config->desc;
90 }
Duncan Laurie6eb8e1d2016-09-01 15:56:44 -070091}
92
93struct chip_operations drivers_i2c_tpm_ops = {
94 CHIP_NAME("I2C TPM")
Elyes HAOUAS2aa3b162018-11-27 17:02:10 +010095 .enable_dev = i2c_tpm_enable
Duncan Laurie6eb8e1d2016-09-01 15:56:44 -070096};