aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/configs/controlcenterd.h7
-rw-r--r--include/configs/efi-x86.h2
-rw-r--r--include/configs/exynos5-common.h7
-rw-r--r--include/configs/x86-common.h2
-rw-r--r--include/dm/device-internal.h4
-rw-r--r--include/dm/lists.h4
-rw-r--r--include/dm/pinctrl.h227
-rw-r--r--include/dm/uclass-id.h3
-rw-r--r--include/dm/uclass.h9
-rw-r--r--include/fdtdec.h2
-rw-r--r--include/tis.h3
-rw-r--r--include/tpm.h243
12 files changed, 481 insertions, 32 deletions
diff --git a/include/configs/controlcenterd.h b/include/configs/controlcenterd.h
index 8f829eddb1..9a1f6d0782 100644
--- a/include/configs/controlcenterd.h
+++ b/include/configs/controlcenterd.h
@@ -226,14 +226,7 @@
#define CONFIG_SF_DEFAULT_MODE 0
#endif
-/*
- * TPM
- */
-#define CONFIG_TPM_ATMEL_TWI
-#define CONFIG_TPM
-#define CONFIG_TPM_AUTH_SESSIONS
#define CONFIG_SHA1
-#define CONFIG_CMD_TPM
/*
* MMC
diff --git a/include/configs/efi-x86.h b/include/configs/efi-x86.h
index 5779cfdb66..1c955d9e37 100644
--- a/include/configs/efi-x86.h
+++ b/include/configs/efi-x86.h
@@ -11,8 +11,6 @@
#undef CONFIG_CMD_SF_TEST
-#undef CONFIG_TPM
-#undef CONFIG_TPM_TIS_LPC
#undef CONFIG_TPM_TIS_BASE_ADDRESS
#undef CONFIG_CMD_IMLS
diff --git a/include/configs/exynos5-common.h b/include/configs/exynos5-common.h
index e710f41f79..4866836d55 100644
--- a/include/configs/exynos5-common.h
+++ b/include/configs/exynos5-common.h
@@ -54,13 +54,6 @@
#define CONFIG_CMD_DTT
#define CONFIG_TMU_CMD_DTT
-/* TPM */
-#define CONFIG_TPM
-#define CONFIG_CMD_TPM
-#define CONFIG_TPM_TIS_I2C
-#define CONFIG_TPM_TIS_I2C_BUS_NUMBER 3
-#define CONFIG_TPM_TIS_I2C_SLAVE_ADDR 0x20
-
/* MMC SPL */
#define COPY_BL2_FNPTR_ADDR 0x02020030
#define CONFIG_SUPPORT_EMMC_BOOT
diff --git a/include/configs/x86-common.h b/include/configs/x86-common.h
index 217312e5b7..3f153f24ae 100644
--- a/include/configs/x86-common.h
+++ b/include/configs/x86-common.h
@@ -47,8 +47,6 @@
#endif
/* Generic TPM interfaced through LPC bus */
-#define CONFIG_TPM
-#define CONFIG_TPM_TIS_LPC
#define CONFIG_TPM_TIS_BASE_ADDRESS 0xfed40000
/*-----------------------------------------------------------------------
diff --git a/include/dm/device-internal.h b/include/dm/device-internal.h
index 04884f1805..322d35a478 100644
--- a/include/dm/device-internal.h
+++ b/include/dm/device-internal.h
@@ -31,7 +31,7 @@ struct udevice;
* devices which use device tree.
* @of_offset: Offset of device tree node for this device. This is -1 for
* devices which don't use device tree.
- * @devp: Returns a pointer to the bound device
+ * @devp: if non-NULL, returns a pointer to the bound device
* @return 0 if OK, -ve on error
*/
int device_bind(struct udevice *parent, const struct driver *drv,
@@ -48,7 +48,7 @@ int device_bind(struct udevice *parent, const struct driver *drv,
* @pre_reloc_only: If true, bind the driver only if its DM_INIT_F flag is set.
* If false bind the driver always.
* @info: Name and platdata for this device
- * @devp: Returns a pointer to the bound device
+ * @devp: if non-NULL, returns a pointer to the bound device
* @return 0 if OK, -ve on error
*/
int device_bind_by_name(struct udevice *parent, bool pre_reloc_only,
diff --git a/include/dm/lists.h b/include/dm/lists.h
index 61610e69aa..4513d6a311 100644
--- a/include/dm/lists.h
+++ b/include/dm/lists.h
@@ -68,7 +68,7 @@ int lists_bind_fdt(struct udevice *parent, const void *blob, int offset,
* @parent: Parent device
* @drv_name: Name of driver to attach to this parent
* @dev_name: Name of the new device thus created
- * @devp: Returns the newly bound device
+ * @devp: If non-NULL, returns the newly bound device
*/
int device_bind_driver(struct udevice *parent, const char *drv_name,
const char *dev_name, struct udevice **devp);
@@ -83,7 +83,7 @@ int device_bind_driver(struct udevice *parent, const char *drv_name,
* @drv_name: Name of driver to attach to this parent
* @dev_name: Name of the new device thus created
* @node: Device tree node
- * @devp: Returns the newly bound device
+ * @devp: If non-NULL, returns the newly bound device
*/
int device_bind_driver_to_node(struct udevice *parent, const char *drv_name,
const char *dev_name, int node,
diff --git a/include/dm/pinctrl.h b/include/dm/pinctrl.h
new file mode 100644
index 0000000000..bc6fdb4a1f
--- /dev/null
+++ b/include/dm/pinctrl.h
@@ -0,0 +1,227 @@
+/*
+ * Copyright (C) 2015 Masahiro Yamada <yamada.masahiro@socionext.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef __PINCTRL_H
+#define __PINCTRL_H
+
+/**
+ * struct pinconf_param - pin config parameters
+ *
+ * @property: property name in DT nodes
+ * @param: ID for this config parameter
+ * @default_value: default value for this config parameter used in case
+ * no value is specified in DT nodes
+ */
+struct pinconf_param {
+ const char * const property;
+ unsigned int param;
+ u32 default_value;
+};
+
+/**
+ * struct pinctrl_ops - pin control operations, to be implemented by
+ * pin controller drivers.
+ *
+ * The @set_state is the only mandatory operation. You can implement your
+ * pinctrl driver with its own @set_state. In this case, the other callbacks
+ * are not required. Otherwise, generic pinctrl framework is also available;
+ * use pinctrl_generic_set_state for @set_state, and implement other operations
+ * depending on your necessity.
+ *
+ * @get_pins_count: return number of selectable named pins available
+ * in this driver. (necessary to parse "pins" property in DTS)
+ * @get_pin_name: return the pin name of the pin selector,
+ * called by the core to figure out which pin it shall do
+ * operations to. (necessary to parse "pins" property in DTS)
+ * @get_groups_count: return number of selectable named groups available
+ * in this driver. (necessary to parse "groups" property in DTS)
+ * @get_group_name: return the group name of the group selector,
+ * called by the core to figure out which pin group it shall do
+ * operations to. (necessary to parse "groups" property in DTS)
+ * @get_functions_count: return number of selectable named functions available
+ * in this driver. (necessary for pin-muxing)
+ * @get_function_name: return the function name of the muxing selector,
+ * called by the core to figure out which mux setting it shall map a
+ * certain device to. (necessary for pin-muxing)
+ * @pinmux_set: enable a certain muxing function with a certain pin.
+ * The @func_selector selects a certain function whereas @pin_selector
+ * selects a certain pin to be used. On simple controllers one of them
+ * may be ignored. (necessary for pin-muxing against a single pin)
+ * @pinmux_group_set: enable a certain muxing function with a certain pin
+ * group. The @func_selector selects a certain function whereas
+ * @group_selector selects a certain set of pins to be used. On simple
+ * controllers one of them may be ignored.
+ * (necessary for pin-muxing against a pin group)
+ * @pinconf_num_params: number of driver-specific parameters to be parsed
+ * from device trees (necessary for pin-configuration)
+ * @pinconf_params: list of driver_specific parameters to be parsed from
+ * device trees (necessary for pin-configuration)
+ * @pinconf_set: configure an individual pin with a given parameter.
+ * (necessary for pin-configuration against a single pin)
+ * @pinconf_group_set: configure all pins in a group with a given parameter.
+ * (necessary for pin-configuration against a pin group)
+ * @set_state: do pinctrl operations specified by @config, a pseudo device
+ * pointing a config node. (necessary for pinctrl_full)
+ * @set_state_simple: do needed pinctrl operations for a peripherl @periph.
+ * (necessary for pinctrl_simple)
+ */
+struct pinctrl_ops {
+ int (*get_pins_count)(struct udevice *dev);
+ const char *(*get_pin_name)(struct udevice *dev, unsigned selector);
+ int (*get_groups_count)(struct udevice *dev);
+ const char *(*get_group_name)(struct udevice *dev, unsigned selector);
+ int (*get_functions_count)(struct udevice *dev);
+ const char *(*get_function_name)(struct udevice *dev,
+ unsigned selector);
+ int (*pinmux_set)(struct udevice *dev, unsigned pin_selector,
+ unsigned func_selector);
+ int (*pinmux_group_set)(struct udevice *dev, unsigned group_selector,
+ unsigned func_selector);
+ unsigned int pinconf_num_params;
+ const struct pinconf_param *pinconf_params;
+ int (*pinconf_set)(struct udevice *dev, unsigned pin_selector,
+ unsigned param, unsigned argument);
+ int (*pinconf_group_set)(struct udevice *dev, unsigned group_selector,
+ unsigned param, unsigned argument);
+ int (*set_state)(struct udevice *dev, struct udevice *config);
+ int (*set_state_simple)(struct udevice *dev, struct udevice *periph);
+};
+
+#define pinctrl_get_ops(dev) ((struct pinctrl_ops *)(dev)->driver->ops)
+
+/**
+ * Generic pin configuration paramters
+ *
+ * @PIN_CONFIG_BIAS_DISABLE: disable any pin bias on the pin, a
+ * transition from say pull-up to pull-down implies that you disable
+ * pull-up in the process, this setting disables all biasing.
+ * @PIN_CONFIG_BIAS_HIGH_IMPEDANCE: the pin will be set to a high impedance
+ * mode, also know as "third-state" (tristate) or "high-Z" or "floating".
+ * On output pins this effectively disconnects the pin, which is useful
+ * if for example some other pin is going to drive the signal connected
+ * to it for a while. Pins used for input are usually always high
+ * impedance.
+ * @PIN_CONFIG_BIAS_BUS_HOLD: the pin will be set to weakly latch so that it
+ * weakly drives the last value on a tristate bus, also known as a "bus
+ * holder", "bus keeper" or "repeater". This allows another device on the
+ * bus to change the value by driving the bus high or low and switching to
+ * tristate. The argument is ignored.
+ * @PIN_CONFIG_BIAS_PULL_UP: the pin will be pulled up (usually with high
+ * impedance to VDD). If the argument is != 0 pull-up is enabled,
+ * if it is 0, pull-up is total, i.e. the pin is connected to VDD.
+ * @PIN_CONFIG_BIAS_PULL_DOWN: the pin will be pulled down (usually with high
+ * impedance to GROUND). If the argument is != 0 pull-down is enabled,
+ * if it is 0, pull-down is total, i.e. the pin is connected to GROUND.
+ * @PIN_CONFIG_BIAS_PULL_PIN_DEFAULT: the pin will be pulled up or down based
+ * on embedded knowledge of the controller hardware, like current mux
+ * function. The pull direction and possibly strength too will normally
+ * be decided completely inside the hardware block and not be readable
+ * from the kernel side.
+ * If the argument is != 0 pull up/down is enabled, if it is 0, the
+ * configuration is ignored. The proper way to disable it is to use
+ * @PIN_CONFIG_BIAS_DISABLE.
+ * @PIN_CONFIG_DRIVE_PUSH_PULL: the pin will be driven actively high and
+ * low, this is the most typical case and is typically achieved with two
+ * active transistors on the output. Setting this config will enable
+ * push-pull mode, the argument is ignored.
+ * @PIN_CONFIG_DRIVE_OPEN_DRAIN: the pin will be driven with open drain (open
+ * collector) which means it is usually wired with other output ports
+ * which are then pulled up with an external resistor. Setting this
+ * config will enable open drain mode, the argument is ignored.
+ * @PIN_CONFIG_DRIVE_OPEN_SOURCE: the pin will be driven with open source
+ * (open emitter). Setting this config will enable open source mode, the
+ * argument is ignored.
+ * @PIN_CONFIG_DRIVE_STRENGTH: the pin will sink or source at most the current
+ * passed as argument. The argument is in mA.
+ * @PIN_CONFIG_INPUT_ENABLE: enable the pin's input. Note that this does not
+ * affect the pin's ability to drive output. 1 enables input, 0 disables
+ * input.
+ * @PIN_CONFIG_INPUT_SCHMITT_ENABLE: control schmitt-trigger mode on the pin.
+ * If the argument != 0, schmitt-trigger mode is enabled. If it's 0,
+ * schmitt-trigger mode is disabled.
+ * @PIN_CONFIG_INPUT_SCHMITT: this will configure an input pin to run in
+ * schmitt-trigger mode. If the schmitt-trigger has adjustable hysteresis,
+ * the threshold value is given on a custom format as argument when
+ * setting pins to this mode.
+ * @PIN_CONFIG_INPUT_DEBOUNCE: this will configure the pin to debounce mode,
+ * which means it will wait for signals to settle when reading inputs. The
+ * argument gives the debounce time in usecs. Setting the
+ * argument to zero turns debouncing off.
+ * @PIN_CONFIG_POWER_SOURCE: if the pin can select between different power
+ * supplies, the argument to this parameter (on a custom format) tells
+ * the driver which alternative power source to use.
+ * @PIN_CONFIG_SLEW_RATE: if the pin can select slew rate, the argument to
+ * this parameter (on a custom format) tells the driver which alternative
+ * slew rate to use.
+ * @PIN_CONFIG_LOW_POWER_MODE: this will configure the pin for low power
+ * operation, if several modes of operation are supported these can be
+ * passed in the argument on a custom form, else just use argument 1
+ * to indicate low power mode, argument 0 turns low power mode off.
+ * @PIN_CONFIG_OUTPUT: this will configure the pin as an output. Use argument
+ * 1 to indicate high level, argument 0 to indicate low level. (Please
+ * see Documentation/pinctrl.txt, section "GPIO mode pitfalls" for a
+ * discussion around this parameter.)
+ * @PIN_CONFIG_END: this is the last enumerator for pin configurations, if
+ * you need to pass in custom configurations to the pin controller, use
+ * PIN_CONFIG_END+1 as the base offset.
+ */
+#define PIN_CONFIG_BIAS_DISABLE 0
+#define PIN_CONFIG_BIAS_HIGH_IMPEDANCE 1
+#define PIN_CONFIG_BIAS_BUS_HOLD 2
+#define PIN_CONFIG_BIAS_PULL_UP 3
+#define PIN_CONFIG_BIAS_PULL_DOWN 4
+#define PIN_CONFIG_BIAS_PULL_PIN_DEFAULT 5
+#define PIN_CONFIG_DRIVE_PUSH_PULL 6
+#define PIN_CONFIG_DRIVE_OPEN_DRAIN 7
+#define PIN_CONFIG_DRIVE_OPEN_SOURCE 8
+#define PIN_CONFIG_DRIVE_STRENGTH 9
+#define PIN_CONFIG_INPUT_ENABLE 10
+#define PIN_CONFIG_INPUT_SCHMITT_ENABLE 11
+#define PIN_CONFIG_INPUT_SCHMITT 12
+#define PIN_CONFIG_INPUT_DEBOUNCE 13
+#define PIN_CONFIG_POWER_SOURCE 14
+#define PIN_CONFIG_SLEW_RATE 15
+#define PIN_CONFIG_LOW_POWER_MODE 16
+#define PIN_CONFIG_OUTPUT 17
+#define PIN_CONFIG_END 0x7FFF
+
+#if CONFIG_IS_ENABLED(PINCTRL_GENERIC)
+/**
+ * pinctrl_generic_set_state() - generic set_state operation
+ * Parse the DT node of @config and its children and handle generic properties
+ * such as "pins", "groups", "functions", and pin configuration parameters.
+ *
+ * @pctldev: pinctrl device
+ * @config: config device (pseudo device), pointing a config node in DTS
+ * @return: 0 on success, or negative error code on failure
+ */
+int pinctrl_generic_set_state(struct udevice *pctldev, struct udevice *config);
+#else
+static inline int pinctrl_generic_set_state(struct udevice *pctldev,
+ struct udevice *config)
+{
+ return -EINVAL;
+}
+#endif
+
+#if CONFIG_IS_ENABLED(PINCTRL)
+/**
+ * pinctrl_select_state() - set a device to a given state
+ *
+ * @dev: peripheral device
+ * @statename: state name, like "default"
+ * @return: 0 on success, or negative error code on failure
+ */
+int pinctrl_select_state(struct udevice *dev, const char *statename);
+#else
+static inline int pinctrl_select_state(struct udevice *dev,
+ const char *statename)
+{
+ return -EINVAL;
+}
+#endif
+
+#endif /* __PINCTRL_H */
diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
index c744044bb8..1eeec74964 100644
--- a/include/dm/uclass-id.h
+++ b/include/dm/uclass-id.h
@@ -44,6 +44,8 @@ enum uclass_id {
UCLASS_PCH, /* x86 platform controller hub */
UCLASS_PCI, /* PCI bus */
UCLASS_PCI_GENERIC, /* Generic PCI bus device */
+ UCLASS_PINCTRL, /* Pinctrl (pin muxing/configuration) device */
+ UCLASS_PINCONFIG, /* Pin configuration node device */
UCLASS_PMIC, /* PMIC I/O device */
UCLASS_REGULATOR, /* Regulator device */
UCLASS_RESET, /* Reset device */
@@ -54,6 +56,7 @@ enum uclass_id {
UCLASS_SPI_GENERIC, /* Generic SPI flash target */
UCLASS_SYSCON, /* System configuration device */
UCLASS_THERMAL, /* Thermal sensor */
+ UCLASS_TPM, /* Trusted Platform Module TIS interface */
UCLASS_USB, /* USB bus */
UCLASS_USB_DEV_GENERIC, /* USB generic device */
UCLASS_USB_HUB, /* USB hub */
diff --git a/include/dm/uclass.h b/include/dm/uclass.h
index d56877c898..d214b88734 100644
--- a/include/dm/uclass.h
+++ b/include/dm/uclass.h
@@ -240,12 +240,7 @@ int uclass_resolve_seq(struct udevice *dev);
* are no more devices.
* @uc: uclass to scan
*/
-#define uclass_foreach_dev(pos, uc) \
- for (pos = list_entry((&(uc)->dev_head)->next, typeof(*pos), \
- uclass_node); \
- prefetch(pos->uclass_node.next), \
- &pos->uclass_node != (&(uc)->dev_head); \
- pos = list_entry(pos->uclass_node.next, typeof(*pos), \
- uclass_node))
+#define uclass_foreach_dev(pos, uc) \
+ list_for_each_entry(pos, &uc->dev_head, uclass_node)
#endif
diff --git a/include/fdtdec.h b/include/fdtdec.h
index 0cb6fa0075..3e237312a7 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -154,8 +154,6 @@ enum fdt_compat_id {
COMPAT_MAXIM_MAX77686_PMIC, /* MAX77686 PMIC */
COMPAT_GENERIC_SPI_FLASH, /* Generic SPI Flash chip */
COMPAT_MAXIM_98095_CODEC, /* MAX98095 Codec */
- COMPAT_INFINEON_SLB9635_TPM, /* Infineon SLB9635 TPM */
- COMPAT_INFINEON_SLB9645_TPM, /* Infineon SLB9645 TPM */
COMPAT_SAMSUNG_EXYNOS5_I2C, /* Exynos5 High Speed I2C Controller */
COMPAT_SANDBOX_LCD_SDL, /* Sandbox LCD emulation with SDL */
COMPAT_SAMSUNG_EXYNOS_SYSMMU, /* Exynos sysmmu */
diff --git a/include/tis.h b/include/tis.h
index 40a1f86762..1985d9e60e 100644
--- a/include/tis.h
+++ b/include/tis.h
@@ -7,6 +7,8 @@
#ifndef __TIS_H
#define __TIS_H
+#ifndef CONFIG_DM_TPM
+
#include <common.h>
/* Low-level interface to access TPM */
@@ -53,5 +55,6 @@ int tis_close(void);
*/
int tis_sendrecv(const uint8_t *sendbuf, size_t send_size, uint8_t *recvbuf,
size_t *recv_len);
+#endif
#endif /* __TIS_H */
diff --git a/include/tpm.h b/include/tpm.h
index 88aeba28e3..086b672718 100644
--- a/include/tpm.h
+++ b/include/tpm.h
@@ -15,6 +15,17 @@
* Specification for definitions of TPM commands.
*/
+#define TPM_HEADER_SIZE 10
+
+enum tpm_duration {
+ TPM_SHORT = 0,
+ TPM_MEDIUM = 1,
+ TPM_LONG = 2,
+ TPM_UNDEFINED,
+
+ TPM_DURATION_COUNT,
+};
+
enum tpm_startup_type {
TPM_ST_CLEAR = 0x0001,
TPM_ST_STATE = 0x0002,
@@ -38,6 +49,15 @@ enum tpm_nv_index {
TPM_NV_INDEX_DIR = 0x10000001,
};
+#define TPM_NV_PER_GLOBALLOCK (1U << 15)
+#define TPM_NV_PER_PPWRITE (1U << 0)
+#define TPM_NV_PER_READ_STCLEAR (1U << 31)
+#define TPM_NV_PER_WRITE_STCLEAR (1U << 14)
+
+enum {
+ TPM_PUBEK_SIZE = 256,
+};
+
/**
* TPM return codes as defined in the TCG Main specification
* (TPM Main Part 2 Structures; Specification version 1.2)
@@ -152,12 +172,217 @@ enum tpm_return_code {
TPM_DEFEND_LOCK_RUNNING = TPM_BASE + TPM_NON_FATAL + 3,
};
+struct tpm_permanent_flags {
+ __be16 tag;
+ u8 disable;
+ u8 ownership;
+ u8 deactivated;
+ u8 read_pubek;
+ u8 disable_owner_clear;
+ u8 allow_maintenance;
+ u8 physical_presence_lifetime_lock;
+ u8 physical_presence_hw_enable;
+ u8 physical_presence_cmd_enable;
+ u8 cekp_used;
+ u8 tpm_post;
+ u8 tpm_post_lock;
+ u8 fips;
+ u8 operator;
+ u8 enable_revoke_ek;
+ u8 nv_locked;
+ u8 read_srk_pub;
+ u8 tpm_established;
+ u8 maintenance_done;
+ u8 disable_full_da_logic_info;
+} __packed;
+
+#ifdef CONFIG_DM_TPM
+
+/* Max buffer size supported by our tpm */
+#define TPM_DEV_BUFSIZE 1260
+
+/**
+ * struct tpm_chip_priv - Information about a TPM, stored by the uclass
+ *
+ * These values must be set up by the device's probe() method before
+ * communcation is attempted. If the device has an xfer() method, this is
+ * not needed. There is no need to set up @buf.
+ *
+ * @duration_ms: Length of each duration type in milliseconds
+ * @retry_time_ms: Time to wait before retrying receive
+ */
+struct tpm_chip_priv {
+ uint duration_ms[TPM_DURATION_COUNT];
+ uint retry_time_ms;
+ u8 buf[TPM_DEV_BUFSIZE + sizeof(u8)]; /* Max buffer size + addr */
+};
+
+/**
+ * struct tpm_ops - low-level TPM operations
+ *
+ * These are designed to avoid loops and delays in the driver itself. These
+ * should be handled in the uclass.
+ *
+ * In gneral you should implement everything except xfer(). Where you need
+ * complete control of the transfer, then xfer() can be provided and will
+ * override the other methods.
+ *
+ * This interface is for low-level TPM access. It does not understand the
+ * concept of localities or the various TPM messages. That interface is
+ * defined in the functions later on in this file, but they all translate
+ * to bytes which are sent and received.
+ */
+struct tpm_ops {
+ /**
+ * open() - Request access to locality 0 for the caller
+ *
+ * After all commands have been completed the caller should call
+ * close().
+ *
+ * @dev: Device to close
+ * @return 0 ok OK, -ve on error
+ */
+ int (*open)(struct udevice *dev);
+
+ /**
+ * close() - Close the current session
+ *
+ * Releasing the locked locality. Returns 0 on success, -ve 1 on
+ * failure (in case lock removal did not succeed).
+ *
+ * @dev: Device to close
+ * @return 0 ok OK, -ve on error
+ */
+ int (*close)(struct udevice *dev);
+
+ /**
+ * get_desc() - Get a text description of the TPM
+ *
+ * @dev: Device to check
+ * @buf: Buffer to put the string
+ * @size: Maximum size of buffer
+ * @return length of string, or -ENOSPC it no space
+ */
+ int (*get_desc)(struct udevice *dev, char *buf, int size);
+
+ /**
+ * send() - send data to the TPM
+ *
+ * @dev: Device to talk to
+ * @sendbuf: Buffer of the data to send
+ * @send_size: Size of the data to send
+ *
+ * Returns 0 on success or -ve on failure.
+ */
+ int (*send)(struct udevice *dev, const uint8_t *sendbuf,
+ size_t send_size);
+
+ /**
+ * recv() - receive a response from the TPM
+ *
+ * @dev: Device to talk to
+ * @recvbuf: Buffer to save the response to
+ * @max_size: Maximum number of bytes to receive
+ *
+ * Returns number of bytes received on success, -EAGAIN if the TPM
+ * response is not ready, -EINTR if cancelled, or other -ve value on
+ * failure.
+ */
+ int (*recv)(struct udevice *dev, uint8_t *recvbuf, size_t max_size);
+
+ /**
+ * cleanup() - clean up after an operation in progress
+ *
+ * This is called if receiving times out. The TPM may need to abort
+ * the current transaction if it did not complete, and make itself
+ * ready for another.
+ *
+ * @dev: Device to talk to
+ */
+ int (*cleanup)(struct udevice *dev);
+
+ /**
+ * xfer() - send data to the TPM and get response
+ *
+ * This method is optional. If it exists it is used in preference
+ * to send(), recv() and cleanup(). It should handle all aspects of
+ * TPM communication for a single transfer.
+ *
+ * @dev: Device to talk to
+ * @sendbuf: Buffer of the data to send
+ * @send_size: Size of the data to send
+ * @recvbuf: Buffer to save the response to
+ * @recv_size: Pointer to the size of the response buffer
+ *
+ * Returns 0 on success (and places the number of response bytes at
+ * recv_size) or -ve on failure.
+ */
+ int (*xfer)(struct udevice *dev, const uint8_t *sendbuf,
+ size_t send_size, uint8_t *recvbuf, size_t *recv_size);
+};
+
+#define tpm_get_ops(dev) ((struct tpm_ops *)device_get_ops(dev))
+
+/**
+ * tpm_open() - Request access to locality 0 for the caller
+ *
+ * After all commands have been completed the caller is supposed to
+ * call tpm_close().
+ *
+ * Returns 0 on success, -ve on failure.
+ */
+int tpm_open(struct udevice *dev);
+
+/**
+ * tpm_close() - Close the current session
+ *
+ * Releasing the locked locality. Returns 0 on success, -ve 1 on
+ * failure (in case lock removal did not succeed).
+ */
+int tpm_close(struct udevice *dev);
+
+/**
+ * tpm_get_desc() - Get a text description of the TPM
+ *
+ * @dev: Device to check
+ * @buf: Buffer to put the string
+ * @size: Maximum size of buffer
+ * @return length of string, or -ENOSPC it no space
+ */
+int tpm_get_desc(struct udevice *dev, char *buf, int size);
+
+/**
+ * tpm_xfer() - send data to the TPM and get response
+ *
+ * This first uses the device's send() method to send the bytes. Then it calls
+ * recv() to get the reply. If recv() returns -EAGAIN then it will delay a
+ * short time and then call recv() again.
+ *
+ * Regardless of whether recv() completes successfully, it will then call
+ * cleanup() to finish the transaction.
+ *
+ * Note that the outgoing data is inspected to determine command type
+ * (ordinal) and a timeout is used for that command type.
+ *
+ * @sendbuf - buffer of the data to send
+ * @send_size size of the data to send
+ * @recvbuf - memory to save the response to
+ * @recv_len - pointer to the size of the response buffer
+ *
+ * Returns 0 on success (and places the number of response bytes at
+ * recv_len) or -ve on failure.
+ */
+int tpm_xfer(struct udevice *dev, const uint8_t *sendbuf, size_t send_size,
+ uint8_t *recvbuf, size_t *recv_size);
+
+#endif /* CONFIG_DM_TPM */
+
/**
* Initialize TPM device. It must be called before any TPM commands.
*
* @return 0 on success, non-0 on error.
*/
-uint32_t tpm_init(void);
+int tpm_init(void);
/**
* Issue a TPM_Startup command.
@@ -359,4 +584,20 @@ uint32_t tpm_load_key2_oiap(uint32_t parent_handle,
uint32_t tpm_get_pub_key_oiap(uint32_t key_handle, const void *usage_auth,
void *pubkey, size_t *pubkey_len);
+/**
+ * Get the TPM permanent flags value
+ *
+ * @param pflags Place to put permanent flags
+ * @return return code of the operation
+ */
+uint32_t tpm_get_permanent_flags(struct tpm_permanent_flags *pflags);
+
+/**
+ * Get the TPM permissions
+ *
+ * @param perm Returns permissions value
+ * @return return code of the operation
+ */
+uint32_t tpm_get_permissions(uint32_t index, uint32_t *perm);
+
#endif /* __TPM_H */