blob: b81b0d17c8e109c9f9204586148eab2da8819215 [file] [log] [blame]
Angel Pons8a3453f2020-04-02 23:48:19 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Duncan Laurie6eb8e1d2016-09-01 15:56:44 -07003
4#include <arch/acpi_device.h>
5#include <arch/acpigen.h>
6#include <console/console.h>
Nico Huber0f2dd1e2017-08-01 14:02:40 +02007#include <device/i2c_simple.h>
Duncan Laurie6eb8e1d2016-09-01 15:56:44 -07008#include <device/device.h>
9#include <device/path.h>
10#include <stdint.h>
Duncan Laurie6eb8e1d2016-09-01 15:56:44 -070011#include "tpm.h"
12#include "chip.h"
13
14static 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 Linb4be50c2018-09-10 10:55:49 +080039 acpigen_write_STA(acpi_device_status(dev));
Duncan Laurie6eb8e1d2016-09-01 15:56:44 -070040
41 /* Resources */
42 acpigen_write_name("_CRS");
43 acpigen_write_resourcetemplate_header();
44 acpi_device_write_i2c(&i2c);
Justin TerAvestec91dd82018-01-29 19:14:19 -070045 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 Laurie6eb8e1d2016-09-01 15:56:44 -070050 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 Durbinaa090cb2017-09-13 16:01:52 -060059static const char *i2c_tpm_acpi_name(const struct device *dev)
Duncan Laurie6eb8e1d2016-09-01 15:56:44 -070060{
61 return "TPMI";
62}
63
64static struct device_operations i2c_tpm_ops = {
Nico Huber2f8ba692020-04-05 14:05:24 +020065 .read_resources = noop_read_resources,
66 .set_resources = noop_set_resources,
Nico Huber68680dd2020-03-31 17:34:52 +020067 .acpi_name = i2c_tpm_acpi_name,
68 .acpi_fill_ssdt = i2c_tpm_fill_ssdt,
Duncan Laurie6eb8e1d2016-09-01 15:56:44 -070069};
70
71static void i2c_tpm_enable(struct device *dev)
72{
Naresh G Solanki69e9e712018-06-04 17:45:19 +053073 struct drivers_i2c_tpm_config *config = dev->chip_info;
74
Duncan Laurie6eb8e1d2016-09-01 15:56:44 -070075 dev->ops = &i2c_tpm_ops;
Naresh G Solanki69e9e712018-06-04 17:45:19 +053076
77 if (config && config->desc) {
78 dev->name = config->desc;
79 }
Duncan Laurie6eb8e1d2016-09-01 15:56:44 -070080}
81
82struct chip_operations drivers_i2c_tpm_ops = {
83 CHIP_NAME("I2C TPM")
Elyes HAOUAS2aa3b162018-11-27 17:02:10 +010084 .enable_dev = i2c_tpm_enable
Duncan Laurie6eb8e1d2016-09-01 15:56:44 -070085};