Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 1 | /* |
| 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 Huber | 0f2dd1e | 2017-08-01 14:02:40 +0200 | [diff] [blame] | 19 | #include <device/i2c_simple.h> |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 20 | #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 | |
| 27 | static 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 TerAvest | ec91dd8 | 2018-01-29 19:14:19 -0700 | [diff] [blame^] | 58 | 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 Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 63 | 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 Durbin | aa090cb | 2017-09-13 16:01:52 -0600 | [diff] [blame] | 72 | static const char *i2c_tpm_acpi_name(const struct device *dev) |
Duncan Laurie | 6eb8e1d | 2016-09-01 15:56:44 -0700 | [diff] [blame] | 73 | { |
| 74 | return "TPMI"; |
| 75 | } |
| 76 | |
| 77 | static 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 | |
| 85 | static void i2c_tpm_enable(struct device *dev) |
| 86 | { |
| 87 | dev->ops = &i2c_tpm_ops; |
| 88 | } |
| 89 | |
| 90 | struct chip_operations drivers_i2c_tpm_ops = { |
| 91 | CHIP_NAME("I2C TPM") |
| 92 | .enable_dev = &i2c_tpm_enable |
| 93 | }; |