blob: 6d5c28a446adbb40a6c4543160299b7d4a94138a [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);
58 acpi_device_write_interrupt(&config->irq);
59 acpigen_write_resourcetemplate_footer();
60
61 acpigen_pop_len(); /* Device */
62 acpigen_pop_len(); /* Scope */
63
64 printk(BIOS_INFO, "%s: %s at %s\n", acpi_device_path(dev),
65 dev->chip_ops->name, dev_path(dev));
66}
67
Aaron Durbinaa090cb2017-09-13 16:01:52 -060068static const char *i2c_tpm_acpi_name(const struct device *dev)
Duncan Laurie6eb8e1d2016-09-01 15:56:44 -070069{
70 return "TPMI";
71}
72
73static struct device_operations i2c_tpm_ops = {
74 .read_resources = DEVICE_NOOP,
75 .set_resources = DEVICE_NOOP,
76 .enable_resources = DEVICE_NOOP,
77 .acpi_name = &i2c_tpm_acpi_name,
78 .acpi_fill_ssdt_generator = &i2c_tpm_fill_ssdt,
79};
80
81static void i2c_tpm_enable(struct device *dev)
82{
83 dev->ops = &i2c_tpm_ops;
84}
85
86struct chip_operations drivers_i2c_tpm_ops = {
87 CHIP_NAME("I2C TPM")
88 .enable_dev = &i2c_tpm_enable
89};