blob: c2af071932270e680aaa465709c7e7b401ca3e85 [file] [log] [blame]
Duncan Laurie6eb8e1d2016-09-01 15:56:44 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2016 Google Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#include <arch/acpi_device.h>
17#include <arch/acpigen.h>
18#include <console/console.h>
Nico Huber0f2dd1e2017-08-01 14:02:40 +020019#include <device/i2c_simple.h>
Duncan Laurie6eb8e1d2016-09-01 15:56:44 -070020#include <device/device.h>
21#include <device/path.h>
22#include <stdint.h>
23#include <string.h>
24#include "tpm.h"
25#include "chip.h"
26
27static void i2c_tpm_fill_ssdt(struct device *dev)
28{
29 struct drivers_i2c_tpm_config *config = dev->chip_info;
30 const char *scope = acpi_device_scope(dev);
31 struct acpi_i2c i2c = {
32 .address = dev->path.i2c.device,
33 .mode_10bit = dev->path.i2c.mode_10bit,
34 .speed = config->speed ? : I2C_SPEED_FAST,
35 .resource = scope,
36 };
37
38 if (!dev->enabled || !scope)
39 return;
40
41 if (!config->hid) {
42 printk(BIOS_ERR, "%s: ERROR: HID required\n", dev_path(dev));
43 return;
44 }
45
46 /* Device */
47 acpigen_write_scope(scope);
48 acpigen_write_device(acpi_device_name(dev));
49 acpigen_write_name_string("_HID", config->hid);
50 acpigen_write_name_integer("_UID", config->uid);
51 acpigen_write_name_string("_DDN", dev->chip_ops->name);
52 acpigen_write_STA(ACPI_STATUS_DEVICE_ALL_ON);
53
54 /* Resources */
55 acpigen_write_name("_CRS");
56 acpigen_write_resourcetemplate_header();
57 acpi_device_write_i2c(&i2c);
Justin TerAvestec91dd82018-01-29 19:14:19 -070058 if (config->irq_gpio.pin_count)
59 acpi_device_write_gpio(&config->irq_gpio);
60 else
61 acpi_device_write_interrupt(&config->irq);
62
Duncan Laurie6eb8e1d2016-09-01 15:56:44 -070063 acpigen_write_resourcetemplate_footer();
64
65 acpigen_pop_len(); /* Device */
66 acpigen_pop_len(); /* Scope */
67
68 printk(BIOS_INFO, "%s: %s at %s\n", acpi_device_path(dev),
69 dev->chip_ops->name, dev_path(dev));
70}
71
Aaron Durbinaa090cb2017-09-13 16:01:52 -060072static const char *i2c_tpm_acpi_name(const struct device *dev)
Duncan Laurie6eb8e1d2016-09-01 15:56:44 -070073{
74 return "TPMI";
75}
76
77static struct device_operations i2c_tpm_ops = {
78 .read_resources = DEVICE_NOOP,
79 .set_resources = DEVICE_NOOP,
80 .enable_resources = DEVICE_NOOP,
81 .acpi_name = &i2c_tpm_acpi_name,
82 .acpi_fill_ssdt_generator = &i2c_tpm_fill_ssdt,
83};
84
85static void i2c_tpm_enable(struct device *dev)
86{
Naresh G Solanki69e9e712018-06-04 17:45:19 +053087 struct drivers_i2c_tpm_config *config = dev->chip_info;
88
Duncan Laurie6eb8e1d2016-09-01 15:56:44 -070089 dev->ops = &i2c_tpm_ops;
Naresh G Solanki69e9e712018-06-04 17:45:19 +053090
91 if (config && config->desc) {
92 dev->name = config->desc;
93 }
Duncan Laurie6eb8e1d2016-09-01 15:56:44 -070094}
95
96struct chip_operations drivers_i2c_tpm_ops = {
97 CHIP_NAME("I2C TPM")
98 .enable_dev = &i2c_tpm_enable
99};