summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/clk/at91/clk-h32mx.c2
-rw-r--r--drivers/i2c/Makefile2
-rw-r--r--drivers/i2c/sh_sh7734_i2c.c376
-rw-r--r--drivers/i2c/tsi108_i2c.c275
-rw-r--r--drivers/misc/Kconfig9
-rw-r--r--drivers/misc/Makefile1
-rw-r--r--drivers/misc/stm32mp_fuse.c116
-rw-r--r--drivers/mmc/Kconfig7
-rw-r--r--drivers/mmc/bcm2835_sdhost.c265
-rw-r--r--drivers/mmc/stm32_sdmmc2.c4
-rw-r--r--drivers/net/Makefile1
-rw-r--r--drivers/net/tsi108_eth.c1015
-rw-r--r--drivers/pci/pci-uclass.c7
-rw-r--r--drivers/pci/pci_auto.c6
-rw-r--r--drivers/pci/pci_auto_common.c11
-rw-r--r--drivers/pci/pci_auto_old.c5
-rw-r--r--drivers/ram/stm32_sdram.c37
-rw-r--r--drivers/serial/Kconfig25
-rw-r--r--drivers/serial/serial_arc.c26
-rw-r--r--drivers/serial/serial_msm.c32
-rw-r--r--drivers/serial/serial_stm32.c158
-rw-r--r--drivers/serial/serial_stm32.h16
-rw-r--r--drivers/tpm/Kconfig69
-rw-r--r--drivers/tpm/Makefile3
-rw-r--r--drivers/tpm/tpm-uclass.c6
-rw-r--r--drivers/tpm/tpm2_tis_sandbox.c625
-rw-r--r--drivers/tpm/tpm2_tis_spi.c679
-rw-r--r--drivers/tpm/tpm_atmel_twi.c2
-rw-r--r--drivers/tpm/tpm_tis.h1
-rw-r--r--drivers/tpm/tpm_tis_infineon.c2
-rw-r--r--drivers/tpm/tpm_tis_lpc.c2
-rw-r--r--drivers/tpm/tpm_tis_sandbox.c2
-rw-r--r--drivers/tpm/tpm_tis_st33zp24_i2c.c2
-rw-r--r--drivers/tpm/tpm_tis_st33zp24_spi.c2
34 files changed, 1824 insertions, 1967 deletions
diff --git a/drivers/clk/at91/clk-h32mx.c b/drivers/clk/at91/clk-h32mx.c
index 485a023bfd..8f02d73d8d 100644
--- a/drivers/clk/at91/clk-h32mx.c
+++ b/drivers/clk/at91/clk-h32mx.c
@@ -26,7 +26,7 @@ static ulong sama5d4_h32mx_clk_get_rate(struct clk *clk)
rate /= 2;
if (rate > H32MX_MAX_FREQ)
- dm_warn("H32MX clock is too fast\n");
+ dev_dbg(clk->dev, "H32MX clock is too fast\n");
return rate;
}
diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
index 8bb3c18b57..da368cc02a 100644
--- a/drivers/i2c/Makefile
+++ b/drivers/i2c/Makefile
@@ -9,8 +9,6 @@ obj-$(CONFIG_$(SPL_)I2C_CROS_EC_TUNNEL) += cros_ec_tunnel.o
obj-$(CONFIG_$(SPL_)I2C_CROS_EC_LDO) += cros_ec_ldo.o
obj-$(CONFIG_I2C_MV) += mv_i2c.o
-obj-$(CONFIG_TSI108_I2C) += tsi108_i2c.o
-obj-$(CONFIG_SH_SH7734_I2C) += sh_sh7734_i2c.o
obj-$(CONFIG_SYS_I2C) += i2c_core.o
obj-$(CONFIG_SYS_I2C_ASPEED) += ast_i2c.o
obj-$(CONFIG_SYS_I2C_AT91) += at91_i2c.o
diff --git a/drivers/i2c/sh_sh7734_i2c.c b/drivers/i2c/sh_sh7734_i2c.c
deleted file mode 100644
index 6fe356baca..0000000000
--- a/drivers/i2c/sh_sh7734_i2c.c
+++ /dev/null
@@ -1,376 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * Copyright (C) 2012 Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com>
- * Copyright (C) 2012 Renesas Solutions Corp.
- *
- * NOTE: This driver should be converted to driver model before June 2017.
- * Please see doc/driver-model/i2c-howto.txt for instructions.
- */
-
-#include <common.h>
-#include <i2c.h>
-#include <asm/io.h>
-
-struct sh_i2c {
- u8 iccr1;
- u8 iccr2;
- u8 icmr;
- u8 icier;
- u8 icsr;
- u8 sar;
- u8 icdrt;
- u8 icdrr;
- u8 nf2cyc;
- u8 __pad0;
- u8 __pad1;
-};
-
-static struct sh_i2c *base;
-static u8 iccr1_cks, nf2cyc;
-
-/* ICCR1 */
-#define SH_I2C_ICCR1_ICE (1 << 7)
-#define SH_I2C_ICCR1_RCVD (1 << 6)
-#define SH_I2C_ICCR1_MST (1 << 5)
-#define SH_I2C_ICCR1_TRS (1 << 4)
-#define SH_I2C_ICCR1_MTRS \
- (SH_I2C_ICCR1_MST | SH_I2C_ICCR1_TRS)
-
-/* ICCR1 */
-#define SH_I2C_ICCR2_BBSY (1 << 7)
-#define SH_I2C_ICCR2_SCP (1 << 6)
-#define SH_I2C_ICCR2_SDAO (1 << 5)
-#define SH_I2C_ICCR2_SDAOP (1 << 4)
-#define SH_I2C_ICCR2_SCLO (1 << 3)
-#define SH_I2C_ICCR2_IICRST (1 << 1)
-
-#define SH_I2C_ICIER_TIE (1 << 7)
-#define SH_I2C_ICIER_TEIE (1 << 6)
-#define SH_I2C_ICIER_RIE (1 << 5)
-#define SH_I2C_ICIER_NAKIE (1 << 4)
-#define SH_I2C_ICIER_STIE (1 << 3)
-#define SH_I2C_ICIER_ACKE (1 << 2)
-#define SH_I2C_ICIER_ACKBR (1 << 1)
-#define SH_I2C_ICIER_ACKBT (1 << 0)
-
-#define SH_I2C_ICSR_TDRE (1 << 7)
-#define SH_I2C_ICSR_TEND (1 << 6)
-#define SH_I2C_ICSR_RDRF (1 << 5)
-#define SH_I2C_ICSR_NACKF (1 << 4)
-#define SH_I2C_ICSR_STOP (1 << 3)
-#define SH_I2C_ICSR_ALOVE (1 << 2)
-#define SH_I2C_ICSR_AAS (1 << 1)
-#define SH_I2C_ICSR_ADZ (1 << 0)
-
-#define IRQ_WAIT 1000
-
-static void sh_i2c_send_stop(struct sh_i2c *base)
-{
- clrbits_8(&base->iccr2, SH_I2C_ICCR2_BBSY | SH_I2C_ICCR2_SCP);
-}
-
-static int check_icsr_bits(struct sh_i2c *base, u8 bits)
-{
- int i;
-
- for (i = 0; i < IRQ_WAIT; i++) {
- if (bits & readb(&base->icsr))
- return 0;
- udelay(10);
- }
-
- return 1;
-}
-
-static int check_stop(struct sh_i2c *base)
-{
- int ret = check_icsr_bits(base, SH_I2C_ICSR_STOP);
- clrbits_8(&base->icsr, SH_I2C_ICSR_STOP);
-
- return ret;
-}
-
-static int check_tend(struct sh_i2c *base, int stop)
-{
- int ret = check_icsr_bits(base, SH_I2C_ICSR_TEND);
-
- if (stop) {
- clrbits_8(&base->icsr, SH_I2C_ICSR_STOP);
- sh_i2c_send_stop(base);
- }
-
- clrbits_8(&base->icsr, SH_I2C_ICSR_TEND);
- return ret;
-}
-
-static int check_tdre(struct sh_i2c *base)
-{
- return check_icsr_bits(base, SH_I2C_ICSR_TDRE);
-}
-
-static int check_rdrf(struct sh_i2c *base)
-{
- return check_icsr_bits(base, SH_I2C_ICSR_RDRF);
-}
-
-static int check_bbsy(struct sh_i2c *base)
-{
- int i;
-
- for (i = 0 ; i < IRQ_WAIT ; i++) {
- if (!(SH_I2C_ICCR2_BBSY & readb(&base->iccr2)))
- return 0;
- udelay(10);
- }
- return 1;
-}
-
-static int check_ackbr(struct sh_i2c *base)
-{
- int i;
-
- for (i = 0 ; i < IRQ_WAIT ; i++) {
- if (!(SH_I2C_ICIER_ACKBR & readb(&base->icier)))
- return 0;
- udelay(10);
- }
-
- return 1;
-}
-
-static void sh_i2c_reset(struct sh_i2c *base)
-{
- setbits_8(&base->iccr2, SH_I2C_ICCR2_IICRST);
-
- udelay(100);
-
- clrbits_8(&base->iccr2, SH_I2C_ICCR2_IICRST);
-}
-
-static int i2c_set_addr(struct sh_i2c *base, u8 id, u8 reg)
-{
- if (check_bbsy(base)) {
- puts("i2c bus busy\n");
- goto fail;
- }
-
- setbits_8(&base->iccr1, SH_I2C_ICCR1_MTRS);
- clrsetbits_8(&base->iccr2, SH_I2C_ICCR2_SCP, SH_I2C_ICCR2_BBSY);
-
- writeb((id << 1), &base->icdrt);
-
- if (check_tend(base, 0)) {
- puts("TEND check fail...\n");
- goto fail;
- }
-
- if (check_ackbr(base)) {
- check_tend(base, 0);
- sh_i2c_send_stop(base);
- goto fail;
- }
-
- writeb(reg, &base->icdrt);
-
- if (check_tdre(base)) {
- puts("TDRE check fail...\n");
- goto fail;
- }
-
- if (check_tend(base, 0)) {
- puts("TEND check fail...\n");
- goto fail;
- }
-
- return 0;
-fail:
-
- return 1;
-}
-
-static int
-i2c_raw_write(struct sh_i2c *base, u8 id, u8 reg, u8 *val, int size)
-{
- int i;
-
- if (i2c_set_addr(base, id, reg)) {
- puts("Fail set slave address\n");
- return 1;
- }
-
- for (i = 0; i < size; i++) {
- writeb(val[i], &base->icdrt);
- check_tdre(base);
- }
-
- check_tend(base, 1);
- check_stop(base);
-
- udelay(100);
-
- clrbits_8(&base->iccr1, SH_I2C_ICCR1_MTRS);
- clrbits_8(&base->icsr, SH_I2C_ICSR_TDRE);
- sh_i2c_reset(base);
-
- return 0;
-}
-
-static u8 i2c_raw_read(struct sh_i2c *base, u8 id, u8 reg)
-{
- u8 ret = 0;
-
- if (i2c_set_addr(base, id, reg)) {
- puts("Fail set slave address\n");
- goto fail;
- }
-
- clrsetbits_8(&base->iccr2, SH_I2C_ICCR2_SCP, SH_I2C_ICCR2_BBSY);
- writeb((id << 1) | 1, &base->icdrt);
-
- if (check_tend(base, 0))
- puts("TDRE check fail...\n");
-
- clrsetbits_8(&base->iccr1, SH_I2C_ICCR1_TRS, SH_I2C_ICCR1_MST);
- clrbits_8(&base->icsr, SH_I2C_ICSR_TDRE);
- setbits_8(&base->icier, SH_I2C_ICIER_ACKBT);
- setbits_8(&base->iccr1, SH_I2C_ICCR1_RCVD);
-
- /* read data (dummy) */
- ret = readb(&base->icdrr);
-
- if (check_rdrf(base)) {
- puts("check RDRF error\n");
- goto fail;
- }
-
- clrbits_8(&base->icsr, SH_I2C_ICSR_STOP);
- udelay(1000);
-
- sh_i2c_send_stop(base);
-
- if (check_stop(base)) {
- puts("check STOP error\n");
- goto fail;
- }
-
- clrbits_8(&base->iccr1, SH_I2C_ICCR1_MTRS);
- clrbits_8(&base->icsr, SH_I2C_ICSR_TDRE);
-
- /* data read */
- ret = readb(&base->icdrr);
-
-fail:
- clrbits_8(&base->iccr1, SH_I2C_ICCR1_RCVD);
-
- return ret;
-}
-
-#ifdef CONFIG_I2C_MULTI_BUS
-static unsigned int current_bus;
-
-/**
- * i2c_set_bus_num - change active I2C bus
- * @bus: bus index, zero based
- * @returns: 0 on success, non-0 on failure
- */
-int i2c_set_bus_num(unsigned int bus)
-{
- switch (bus) {
- case 0:
- base = (void *)CONFIG_SH_I2C_BASE0;
- break;
- case 1:
- base = (void *)CONFIG_SH_I2C_BASE1;
- break;
- default:
- printf("Bad bus: %d\n", bus);
- return -1;
- }
-
- current_bus = bus;
-
- return 0;
-}
-
-/**
- * i2c_get_bus_num - returns index of active I2C bus
- */
-unsigned int i2c_get_bus_num(void)
-{
- return current_bus;
-}
-#endif
-
-void i2c_init(int speed, int slaveaddr)
-{
-#ifdef CONFIG_I2C_MULTI_BUS
- current_bus = 0;
-#endif
- base = (struct sh_i2c *)CONFIG_SH_I2C_BASE0;
-
- if (speed == 400000)
- iccr1_cks = 0x07;
- else
- iccr1_cks = 0x0F;
-
- nf2cyc = 1;
-
- /* Reset */
- sh_i2c_reset(base);
-
- /* ICE enable and set clock */
- writeb(SH_I2C_ICCR1_ICE | iccr1_cks, &base->iccr1);
- writeb(nf2cyc, &base->nf2cyc);
-}
-
-/*
- * i2c_read: - Read multiple bytes from an i2c device
- *
- * The higher level routines take into account that this function is only
- * called with len < page length of the device (see configuration file)
- *
- * @chip: address of the chip which is to be read
- * @addr: i2c data address within the chip
- * @alen: length of the i2c data address (1..2 bytes)
- * @buffer: where to write the data
- * @len: how much byte do we want to read
- * @return: 0 in case of success
- */
-int i2c_read(u8 chip, u32 addr, int alen, u8 *buffer, int len)
-{
- int i = 0;
- for (i = 0; i < len; i++)
- buffer[i] = i2c_raw_read(base, chip, addr + i);
-
- return 0;
-}
-
-/*
- * i2c_write: - Write multiple bytes to an i2c device
- *
- * The higher level routines take into account that this function is only
- * called with len < page length of the device (see configuration file)
- *
- * @chip: address of the chip which is to be written
- * @addr: i2c data address within the chip
- * @alen: length of the i2c data address (1..2 bytes)
- * @buffer: where to find the data to be written
- * @len: how much byte do we want to read
- * @return: 0 in case of success
- */
-int i2c_write(u8 chip, u32 addr, int alen, u8 *buffer, int len)
-{
- return i2c_raw_write(base, chip, addr, buffer, len);
-}
-
-/*
- * i2c_probe: - Test if a chip answers for a given i2c address
- *
- * @chip: address of the chip which is searched for
- * @return: 0 if a chip was found, -1 otherwhise
- */
-int i2c_probe(u8 chip)
-{
- u8 byte;
- return i2c_read(chip, 0, 0, &byte, 1);
-}
diff --git a/drivers/i2c/tsi108_i2c.c b/drivers/i2c/tsi108_i2c.c
deleted file mode 100644
index 208c0900ef..0000000000
--- a/drivers/i2c/tsi108_i2c.c
+++ /dev/null
@@ -1,275 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * (C) Copyright 2004 Tundra Semiconductor Corp.
- * Author: Alex Bounine
- *
- * NOTE: This driver should be converted to driver model before June 2017.
- * Please see doc/driver-model/i2c-howto.txt for instructions.
- */
-
-#include <config.h>
-#include <common.h>
-
-#include <tsi108.h>
-
-#if defined(CONFIG_CMD_I2C)
-
-#define I2C_DELAY 100000
-#undef DEBUG_I2C
-
-#ifdef DEBUG_I2C
-#define DPRINT(x) printf (x)
-#else
-#define DPRINT(x)
-#endif
-
-/* All functions assume that Tsi108 I2C block is the only master on the bus */
-/* I2C read helper function */
-
-void i2c_init(int speed, int slaveaddr)
-{
- /*
- * The TSI108 has a fixed I2C clock rate and doesn't support slave
- * operation. This function only exists as a stub to fit into the
- * U-Boot I2C API.
- */
-}
-
-static int i2c_read_byte (
- uint i2c_chan, /* I2C channel number: 0 - main, 1 - SDC SPD */
- uchar chip_addr,/* I2C device address on the bus */
- uint byte_addr, /* Byte address within I2C device */
- uchar * buffer /* pointer to data buffer */
- )
-{
- u32 temp;
- u32 to_count = I2C_DELAY;
- u32 op_status = TSI108_I2C_TIMEOUT_ERR;
- u32 chan_offset = TSI108_I2C_OFFSET;
-
- DPRINT (("I2C read_byte() %d 0x%02x 0x%02x\n",
- i2c_chan, chip_addr, byte_addr));
-
- if (0 != i2c_chan)
- chan_offset = TSI108_I2C_SDRAM_OFFSET;
-
- /* Check if I2C operation is in progress */
- temp = *(u32 *) (CONFIG_SYS_TSI108_CSR_BASE + chan_offset + I2C_CNTRL2);
-
- if (0 == (temp & (I2C_CNTRL2_RD_STATUS | I2C_CNTRL2_WR_STATUS |
- I2C_CNTRL2_START))) {
- /* Set device address and operation (read = 0) */
- temp = (byte_addr << 16) | ((chip_addr & 0x07) << 8) |
- ((chip_addr >> 3) & 0x0F);
- *(u32 *) (CONFIG_SYS_TSI108_CSR_BASE + chan_offset + I2C_CNTRL1) =
- temp;
-
- /* Issue the read command
- * (at this moment all other parameters are 0
- * (size = 1 byte, lane = 0)
- */
-
- *(u32 *) (CONFIG_SYS_TSI108_CSR_BASE + chan_offset + I2C_CNTRL2) =
- (I2C_CNTRL2_START);
-
- /* Wait until operation completed */
- do {
- /* Read I2C operation status */
- temp = *(u32 *) (CONFIG_SYS_TSI108_CSR_BASE + chan_offset + I2C_CNTRL2);
-
- if (0 == (temp & (I2C_CNTRL2_RD_STATUS | I2C_CNTRL2_START))) {
- if (0 == (temp &
- (I2C_CNTRL2_I2C_CFGERR |
- I2C_CNTRL2_I2C_TO_ERR))
- ) {
- op_status = TSI108_I2C_SUCCESS;
-
- temp = *(u32 *) (CONFIG_SYS_TSI108_CSR_BASE +
- chan_offset +
- I2C_RD_DATA);
-
- *buffer = (u8) (temp & 0xFF);
- } else {
- /* report HW error */
- op_status = TSI108_I2C_IF_ERROR;
-
- DPRINT (("I2C HW error reported: 0x%02x\n", temp));
- }
-
- break;
- }
- } while (to_count--);
- } else {
- op_status = TSI108_I2C_IF_BUSY;
-
- DPRINT (("I2C Transaction start failed: 0x%02x\n", temp));
- }
-
- DPRINT (("I2C read_byte() status: 0x%02x\n", op_status));
- return op_status;
-}
-
-/*
- * I2C Read interface as defined in "include/i2c.h" :
- * chip_addr: I2C chip address, range 0..127
- * (to read from SPD channel EEPROM use (0xD0 ... 0xD7)
- * NOTE: The bit 7 in the chip_addr serves as a channel select.
- * This hack is for enabling "i2c sdram" command on Tsi108 boards
- * without changes to common code. Used for I2C reads only.
- * byte_addr: Memory or register address within the chip
- * alen: Number of bytes to use for addr (typically 1, 2 for larger
- * memories, 0 for register type devices with only one
- * register)
- * buffer: Pointer to destination buffer for data to be read
- * len: How many bytes to read
- *
- * Returns: 0 on success, not 0 on failure
- */
-
-int i2c_read (uchar chip_addr, uint byte_addr, int alen,
- uchar * buffer, int len)
-{
- u32 op_status = TSI108_I2C_PARAM_ERR;
- u32 i2c_if = 0;
-
- /* Hack to support second (SPD) I2C controller (SPD EEPROM read only).*/
- if (0xD0 == (chip_addr & ~0x07)) {
- i2c_if = 1;
- chip_addr &= 0x7F;
- }
- /* Check for valid I2C address */
- if (chip_addr <= 0x7F && (byte_addr + len) <= (0x01 << (alen * 8))) {
- while (len--) {
- op_status = i2c_read_byte(i2c_if, chip_addr, byte_addr++, buffer++);
-
- if (TSI108_I2C_SUCCESS != op_status) {
- DPRINT (("I2C read_byte() failed: 0x%02x (%d left)\n", op_status, len));
-
- break;
- }
- }
- }
-
- DPRINT (("I2C read() status: 0x%02x\n", op_status));
- return op_status;
-}
-
-/* I2C write helper function */
-
-static int i2c_write_byte (uchar chip_addr,/* I2C device address on the bus */
- uint byte_addr, /* Byte address within I2C device */
- uchar * buffer /* pointer to data buffer */
- )
-{
- u32 temp;
- u32 to_count = I2C_DELAY;
- u32 op_status = TSI108_I2C_TIMEOUT_ERR;
-
- /* Check if I2C operation is in progress */
- temp = *(u32 *) (CONFIG_SYS_TSI108_CSR_BASE + TSI108_I2C_OFFSET + I2C_CNTRL2);
-
- if (0 == (temp & (I2C_CNTRL2_RD_STATUS | I2C_CNTRL2_WR_STATUS | I2C_CNTRL2_START))) {
- /* Place data into the I2C Tx Register */
- *(u32 *) (CONFIG_SYS_TSI108_CSR_BASE + TSI108_I2C_OFFSET +
- I2C_TX_DATA) = (u32) * buffer;
-
- /* Set device address and operation */
- temp =
- I2C_CNTRL1_I2CWRITE | (byte_addr << 16) |
- ((chip_addr & 0x07) << 8) | ((chip_addr >> 3) & 0x0F);
- *(u32 *) (CONFIG_SYS_TSI108_CSR_BASE + TSI108_I2C_OFFSET +
- I2C_CNTRL1) = temp;
-
- /* Issue the write command (at this moment all other parameters
- * are 0 (size = 1 byte, lane = 0)
- */
-
- *(u32 *) (CONFIG_SYS_TSI108_CSR_BASE + TSI108_I2C_OFFSET +
- I2C_CNTRL2) = (I2C_CNTRL2_START);
-
- op_status = TSI108_I2C_TIMEOUT_ERR;
-
- /* Wait until operation completed */
- do {
- /* Read I2C operation status */
- temp = *(u32 *) (CONFIG_SYS_TSI108_CSR_BASE + TSI108_I2C_OFFSET + I2C_CNTRL2);
-
- if (0 == (temp & (I2C_CNTRL2_WR_STATUS | I2C_CNTRL2_START))) {
- if (0 == (temp &
- (I2C_CNTRL2_I2C_CFGERR |
- I2C_CNTRL2_I2C_TO_ERR))) {
- op_status = TSI108_I2C_SUCCESS;
- } else {
- /* report detected HW error */
- op_status = TSI108_I2C_IF_ERROR;
-
- DPRINT (("I2C HW error reported: 0x%02x\n", temp));
- }
-
- break;
- }
-
- } while (to_count--);
- } else {
- op_status = TSI108_I2C_IF_BUSY;
-
- DPRINT (("I2C Transaction start failed: 0x%02x\n", temp));
- }
-
- return op_status;
-}
-
-/*
- * I2C Write interface as defined in "include/i2c.h" :
- * chip_addr: I2C chip address, range 0..127
- * byte_addr: Memory or register address within the chip
- * alen: Number of bytes to use for addr (typically 1, 2 for larger
- * memories, 0 for register type devices with only one
- * register)
- * buffer: Pointer to data to be written
- * len: How many bytes to write
- *
- * Returns: 0 on success, not 0 on failure
- */
-
-int i2c_write (uchar chip_addr, uint byte_addr, int alen, uchar * buffer,
- int len)
-{
- u32 op_status = TSI108_I2C_PARAM_ERR;
-
- /* Check for valid I2C address */
- if (chip_addr <= 0x7F && (byte_addr + len) <= (0x01 << (alen * 8))) {
- while (len--) {
- op_status =
- i2c_write_byte (chip_addr, byte_addr++, buffer++);
-
- if (TSI108_I2C_SUCCESS != op_status) {
- DPRINT (("I2C write_byte() failed: 0x%02x (%d left)\n", op_status, len));
-
- break;
- }
- }
- }
-
- return op_status;
-}
-
-/*
- * I2C interface function as defined in "include/i2c.h".
- * Probe the given I2C chip address by reading single byte from offset 0.
- * Returns 0 if a chip responded, not 0 on failure.
- */
-
-int i2c_probe (uchar chip)
-{
- u32 tmp;
-
- /*
- * Try to read the first location of the chip.
- * The Tsi108 HW doesn't support sending just the chip address
- * and checkong for an <ACK> back.
- */
- return i2c_read (chip, 0, 1, (uchar *)&tmp, 1);
-}
-
-#endif
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index be900cf4d6..17b3a805a2 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -158,6 +158,15 @@ config PCA9551_I2C_ADDR
help
The I2C address of the PCA9551 LED controller.
+config STM32MP_FUSE
+ bool "Enable STM32MP fuse wrapper providing the fuse API"
+ depends on ARCH_STM32MP && MISC
+ default y if CMD_FUSE
+ help
+ If you say Y here, you will get support for the fuse API (OTP)
+ for STM32MP architecture.
+ This API is needed for CMD_FUSE.
+
config STM32_RCC
bool "Enable RCC driver for the STM32 SoC's family"
depends on STM32 && MISC
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index e362609d62..4ce9d213f0 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -51,5 +51,6 @@ obj-$(CONFIG_WINBOND_W83627) += winbond_w83627.o
obj-$(CONFIG_QFW) += qfw.o
obj-$(CONFIG_ROCKCHIP_EFUSE) += rockchip-efuse.o
obj-$(CONFIG_STM32_RCC) += stm32_rcc.o
+obj-$(CONFIG_STM32MP_FUSE) += stm32mp_fuse.o
obj-$(CONFIG_SYS_DPAA_QBMAN) += fsl_portals.o
obj-$(CONFIG_GDSYS_RXAUI_CTRL) += gdsys_rxaui_ctrl.o
diff --git a/drivers/misc/stm32mp_fuse.c b/drivers/misc/stm32mp_fuse.c
new file mode 100644
index 0000000000..2d661351a1
--- /dev/null
+++ b/drivers/misc/stm32mp_fuse.c
@@ -0,0 +1,116 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
+ */
+
+#include <common.h>
+#include <command.h>
+#include <misc.h>
+#include <errno.h>
+#include <dm/device.h>
+#include <dm/uclass.h>
+
+#define STM32MP_OTP_BANK 0
+
+/*
+ * The 'fuse' command API
+ */
+int fuse_read(u32 bank, u32 word, u32 *val)
+{
+ int ret = 0;
+ struct udevice *dev;
+
+ switch (bank) {
+ case STM32MP_OTP_BANK:
+ ret = uclass_get_device_by_driver(UCLASS_MISC,
+ DM_GET_DRIVER(stm32mp_bsec),
+ &dev);
+ if (ret)
+ return ret;
+ ret = misc_read(dev, word * 4 + STM32_BSEC_SHADOW_OFFSET,
+ val, 4);
+ break;
+
+ default:
+ printf("stm32mp %s: wrong value for bank %i\n", __func__, bank);
+ ret = -EINVAL;
+ break;
+ }
+
+ return ret;
+}
+
+int fuse_prog(u32 bank, u32 word, u32 val)
+{
+ struct udevice *dev;
+ int ret;
+
+ switch (bank) {
+ case STM32MP_OTP_BANK:
+ ret = uclass_get_device_by_driver(UCLASS_MISC,
+ DM_GET_DRIVER(stm32mp_bsec),
+ &dev);
+ if (ret)
+ return ret;
+ ret = misc_write(dev, word * 4 + STM32_BSEC_OTP_OFFSET,
+ &val, 4);
+ break;
+
+ default:
+ printf("stm32mp %s: wrong value for bank %i\n", __func__, bank);
+ ret = -EINVAL;
+ break;
+ }
+
+ return ret;
+}
+
+int fuse_sense(u32 bank, u32 word, u32 *val)
+{
+ struct udevice *dev;
+ int ret;
+
+ switch (bank) {
+ case STM32MP_OTP_BANK:
+ ret = uclass_get_device_by_driver(UCLASS_MISC,
+ DM_GET_DRIVER(stm32mp_bsec),
+ &dev);
+ if (ret)
+ return ret;
+ ret = misc_read(dev, word * 4 + STM32_BSEC_OTP_OFFSET, val, 4);
+ break;
+
+ default:
+ printf("stm32mp %s: wrong value for bank %i\n", __func__, bank);
+ ret = -EINVAL;
+ break;
+ }
+
+ return ret;
+}
+
+int fuse_override(u32 bank, u32 word, u32 val)
+{
+ struct udevice *dev;
+ int ret;
+
+ switch (bank) {
+ case STM32MP_OTP_BANK:
+ ret = uclass_get_device_by_driver(UCLASS_MISC,
+ DM_GET_DRIVER(stm32mp_bsec),
+ &dev);
+ if (ret)
+ return ret;
+ ret = misc_write(dev, word * 4 + STM32_BSEC_SHADOW_OFFSET,
+ &val, 4);
+ break;
+
+ default:
+ printf("stm32mp %s: wrong value for bank %i\n",
+ __func__, bank);
+ ret = -EINVAL;
+ break;
+ }
+
+ return ret;
+}
diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig
index 3f15f85efd..693b3ceaf0 100644
--- a/drivers/mmc/Kconfig
+++ b/drivers/mmc/Kconfig
@@ -71,6 +71,13 @@ config MMC_HW_PARTITIONING
This adds a command and an API to do hardware partitioning on eMMC
devices.
+config SUPPORT_EMMC_RPMB
+ bool "Support eMMC replay protected memory block (RPMB)"
+ imply CMD_MMC_RPMB
+ help
+ Enable support for reading, writing and programming the
+ key for the Replay Protection Memory Block partition in eMMC.
+
config MMC_IO_VOLTAGE
bool "Support IO voltage configuration"
help
diff --git a/drivers/mmc/bcm2835_sdhost.c b/drivers/mmc/bcm2835_sdhost.c
index 96428333b0..1ce019af57 100644
--- a/drivers/mmc/bcm2835_sdhost.c
+++ b/drivers/mmc/bcm2835_sdhost.c
@@ -163,7 +163,6 @@ struct bcm2835_host {
int clock; /* Current clock speed */
unsigned int max_clk; /* Max possible freq */
unsigned int blocks; /* remaining PIO blocks */
- int irq; /* Device IRQ */
u32 ns_per_fifo_word;
@@ -173,14 +172,7 @@ struct bcm2835_host {
struct mmc_cmd *cmd; /* Current command */
struct mmc_data *data; /* Current data request */
- bool data_complete:1;/* Data finished before cmd */
bool use_busy:1; /* Wait for busy interrupt */
- bool wait_data_complete:1; /* Wait for data */
-
- /* for threaded irq handler */
- bool irq_block;
- bool irq_busy;
- bool irq_data;
struct udevice *dev;
struct mmc *mmc;
@@ -240,17 +232,9 @@ static void bcm2835_reset_internal(struct bcm2835_host *host)
writel(host->cdiv, host->ioaddr + SDCDIV);
}
-static int bcm2835_finish_command(struct bcm2835_host *host);
-
-static void bcm2835_wait_transfer_complete(struct bcm2835_host *host)
+static int bcm2835_wait_transfer_complete(struct bcm2835_host *host)
{
- int timediff;
- u32 alternate_idle;
-
- alternate_idle = (host->data->flags & MMC_DATA_READ) ?
- SDEDM_FSM_READWAIT : SDEDM_FSM_WRITESTART1;
-
- timediff = 0;
+ int timediff = 0;
while (1) {
u32 edm, fsm;
@@ -261,7 +245,10 @@ static void bcm2835_wait_transfer_complete(struct bcm2835_host *host)
if ((fsm == SDEDM_FSM_IDENTMODE) ||
(fsm == SDEDM_FSM_DATAMODE))
break;
- if (fsm == alternate_idle) {
+
+ if ((fsm == SDEDM_FSM_READWAIT) ||
+ (fsm == SDEDM_FSM_WRITESTART1) ||
+ (fsm == SDEDM_FSM_READDATA)) {
writel(edm | SDEDM_FORCE_DATA_MODE,
host->ioaddr + SDEDM);
break;
@@ -273,9 +260,11 @@ static void bcm2835_wait_transfer_complete(struct bcm2835_host *host)
"wait_transfer_complete - still waiting after %d retries\n",
timediff);
bcm2835_dumpregs(host);
- return;
+ return -ETIMEDOUT;
}
}
+
+ return 0;
}
static int bcm2835_transfer_block_pio(struct bcm2835_host *host, bool is_read)
@@ -322,6 +311,9 @@ static int bcm2835_transfer_block_pio(struct bcm2835_host *host, bool is_read)
fsm_state != SDEDM_FSM_READCRC)) ||
(!is_read &&
(fsm_state != SDEDM_FSM_WRITEDATA &&
+ fsm_state != SDEDM_FSM_WRITEWAIT1 &&
+ fsm_state != SDEDM_FSM_WRITEWAIT2 &&
+ fsm_state != SDEDM_FSM_WRITECRC &&
fsm_state != SDEDM_FSM_WRITESTART1 &&
fsm_state != SDEDM_FSM_WRITESTART2))) {
hsts = readl(host->ioaddr + SDHSTS);
@@ -358,9 +350,8 @@ static int bcm2835_transfer_pio(struct bcm2835_host *host)
is_read = (host->data->flags & MMC_DATA_READ) != 0;
ret = bcm2835_transfer_block_pio(host, is_read);
-
- if (host->wait_data_complete)
- bcm2835_wait_transfer_complete(host);
+ if (ret)
+ return ret;
sdhsts = readl(host->ioaddr + SDHSTS);
if (sdhsts & (SDHSTS_CRC16_ERROR |
@@ -379,21 +370,8 @@ static int bcm2835_transfer_pio(struct bcm2835_host *host)
return ret;
}
-static void bcm2835_set_transfer_irqs(struct bcm2835_host *host)
-{
- u32 all_irqs = SDHCFG_DATA_IRPT_EN | SDHCFG_BLOCK_IRPT_EN |
- SDHCFG_BUSY_IRPT_EN;
-
- host->hcfg = (host->hcfg & ~all_irqs) |
- SDHCFG_DATA_IRPT_EN |
- SDHCFG_BUSY_IRPT_EN;
-
- writel(host->hcfg, host->ioaddr + SDHCFG);
-}
-
-static
-void bcm2835_prepare_data(struct bcm2835_host *host, struct mmc_cmd *cmd,
- struct mmc_data *data)
+static void bcm2835_prepare_data(struct bcm2835_host *host, struct mmc_cmd *cmd,
+ struct mmc_data *data)
{
WARN_ON(host->data);
@@ -401,14 +379,9 @@ void bcm2835_prepare_data(struct bcm2835_host *host, struct mmc_cmd *cmd,
if (!data)
return;
- host->wait_data_complete = cmd->cmdidx != MMC_CMD_READ_MULTIPLE_BLOCK;
- host->data_complete = false;
-
/* Use PIO */
host->blocks = data->blocks;
- bcm2835_set_transfer_irqs(host);
-
writel(data->blocksize, host->ioaddr + SDHBCT);
writel(data->blocks, host->ioaddr + SDHBLC);
}
@@ -483,36 +456,6 @@ static int bcm2835_send_command(struct bcm2835_host *host, struct mmc_cmd *cmd,
return 0;
}
-static int bcm2835_transfer_complete(struct bcm2835_host *host)
-{
- int ret = 0;
-
- WARN_ON(!host->data_complete);
-
- host->data = NULL;
-
- return ret;
-}
-
-static void bcm2835_finish_data(struct bcm2835_host *host)
-{
- host->hcfg &= ~(SDHCFG_DATA_IRPT_EN | SDHCFG_BLOCK_IRPT_EN);
- writel(host->hcfg, host->ioaddr + SDHCFG);
-
- host->data_complete = true;
-
- if (host->cmd) {
- /* Data managed to finish before the
- * command completed. Make sure we do
- * things in the proper order.
- */
- dev_dbg(dev, "Finished early - HSTS %08x\n",
- readl(host->ioaddr + SDHSTS));
- } else {
- bcm2835_transfer_complete(host);
- }
-}
-
static int bcm2835_finish_command(struct bcm2835_host *host)
{
struct mmc_cmd *cmd = host->cmd;
@@ -562,8 +505,6 @@ static int bcm2835_finish_command(struct bcm2835_host *host)
/* Processed actual command. */
host->cmd = NULL;
- if (host->data && host->data_complete)
- ret = bcm2835_transfer_complete(host);
return ret;
}
@@ -608,159 +549,44 @@ static int bcm2835_check_data_error(struct bcm2835_host *host, u32 intmask)
return ret;
}
-static void bcm2835_busy_irq(struct bcm2835_host *host)
-{
- if (WARN_ON(!host->cmd)) {
- bcm2835_dumpregs(host);
- return;
- }
-
- if (WARN_ON(!host->use_busy)) {
- bcm2835_dumpregs(host);
- return;
- }
- host->use_busy = false;
-
- bcm2835_finish_command(host);
-}
-
-static void bcm2835_data_irq(struct bcm2835_host *host, u32 intmask)
+static int bcm2835_transmit(struct bcm2835_host *host)
{
+ u32 intmask = readl(host->ioaddr + SDHSTS);
int ret;
- /*
- * There are no dedicated data/space available interrupt
- * status bits, so it is necessary to use the single shared
- * data/space available FIFO status bits. It is therefore not
- * an error to get here when there is no data transfer in
- * progress.
- */
- if (!host->data)
- return;
-
+ /* Check for errors */
ret = bcm2835_check_data_error(host, intmask);
if (ret)
- goto finished;
-
- if (host->data->flags & MMC_DATA_WRITE) {
- /* Use the block interrupt for writes after the first block */
- host->hcfg &= ~(SDHCFG_DATA_IRPT_EN);
- host->hcfg |= SDHCFG_BLOCK_IRPT_EN;
- writel(host->hcfg, host->ioaddr + SDHCFG);
- bcm2835_transfer_pio(host);
- } else {
- bcm2835_transfer_pio(host);
- host->blocks--;
- if ((host->blocks == 0))
- goto finished;
- }
- return;
+ return ret;
-finished:
- host->hcfg &= ~(SDHCFG_DATA_IRPT_EN | SDHCFG_BLOCK_IRPT_EN);
- writel(host->hcfg, host->ioaddr + SDHCFG);
-}
-
-static void bcm2835_data_threaded_irq(struct bcm2835_host *host)
-{
- if (!host->data)
- return;
- if ((host->blocks == 0))
- bcm2835_finish_data(host);
-}
-
-static void bcm2835_block_irq(struct bcm2835_host *host)
-{
- if (WARN_ON(!host->data)) {
- bcm2835_dumpregs(host);
- return;
- }
-
- WARN_ON(!host->blocks);
- if ((--host->blocks == 0))
- bcm2835_finish_data(host);
- else
- bcm2835_transfer_pio(host);
-}
+ ret = bcm2835_check_cmd_error(host, intmask);
+ if (ret)
+ return ret;
-static irqreturn_t bcm2835_irq(int irq, void *dev_id)
-{
- irqreturn_t result = IRQ_NONE;
- struct bcm2835_host *host = dev_id;
- u32 intmask;
-
- intmask = readl(host->ioaddr + SDHSTS);
-
- writel(SDHSTS_BUSY_IRPT |
- SDHSTS_BLOCK_IRPT |
- SDHSTS_SDIO_IRPT |
- SDHSTS_DATA_FLAG,
- host->ioaddr + SDHSTS);
-
- if (intmask & SDHSTS_BLOCK_IRPT) {
- bcm2835_check_data_error(host, intmask);
- host->irq_block = true;
- result = IRQ_WAKE_THREAD;
+ /* Handle wait for busy end */
+ if (host->use_busy && (intmask & SDHSTS_BUSY_IRPT)) {
+ writel(SDHSTS_BUSY_IRPT, host->ioaddr + SDHSTS);
+ host->use_busy = false;
+ bcm2835_finish_command(host);
}
- if (intmask & SDHSTS_BUSY_IRPT) {
- if (!bcm2835_check_cmd_error(host, intmask)) {
- host->irq_busy = true;
- result = IRQ_WAKE_THREAD;
- } else {
- result = IRQ_HANDLED;
+ /* Handle PIO data transfer */
+ if (host->data) {
+ ret = bcm2835_transfer_pio(host);
+ if (ret)
+ return ret;
+ host->blocks--;
+ if (host->blocks == 0) {
+ /* Wait for command to complete for real */
+ ret = bcm2835_wait_transfer_complete(host);
+ if (ret)
+ return ret;
+ /* Transfer complete */
+ host->data = NULL;
}
}
- /* There is no true data interrupt status bit, so it is
- * necessary to qualify the data flag with the interrupt
- * enable bit.
- */
- if ((intmask & SDHSTS_DATA_FLAG) &&
- (host->hcfg & SDHCFG_DATA_IRPT_EN)) {
- bcm2835_data_irq(host, intmask);
- host->irq_data = true;
- result = IRQ_WAKE_THREAD;
- }
-
- return result;
-}
-
-static irqreturn_t bcm2835_threaded_irq(int irq, void *dev_id)
-{
- struct bcm2835_host *host = dev_id;
-
- if (host->irq_block) {
- host->irq_block = false;
- bcm2835_block_irq(host);
- }
-
- if (host->irq_busy) {
- host->irq_busy = false;
- bcm2835_busy_irq(host);
- }
-
- if (host->irq_data) {
- host->irq_data = false;
- bcm2835_data_threaded_irq(host);
- }
-
- return IRQ_HANDLED;
-}
-
-static void bcm2835_irq_poll(struct bcm2835_host *host)
-{
- u32 intmask;
-
- while (1) {
- intmask = readl(host->ioaddr + SDHSTS);
- if (intmask & (SDHSTS_BUSY_IRPT | SDHSTS_BLOCK_IRPT |
- SDHSTS_SDIO_IRPT | SDHSTS_DATA_FLAG)) {
- bcm2835_irq(0, host);
- bcm2835_threaded_irq(0, host);
- return;
- }
- }
+ return 0;
}
static void bcm2835_set_clock(struct bcm2835_host *host, unsigned int clock)
@@ -864,8 +690,11 @@ static int bcm2835_send_cmd(struct udevice *dev, struct mmc_cmd *cmd,
}
/* Wait for completion of busy signal or data transfer */
- while (host->use_busy || host->data)
- bcm2835_irq_poll(host);
+ while (host->use_busy || host->data) {
+ ret = bcm2835_transmit(host);
+ if (ret)
+ break;
+ }
return ret;
}
diff --git a/drivers/mmc/stm32_sdmmc2.c b/drivers/mmc/stm32_sdmmc2.c
index 11cc438ce6..e8292c438d 100644
--- a/drivers/mmc/stm32_sdmmc2.c
+++ b/drivers/mmc/stm32_sdmmc2.c
@@ -235,8 +235,8 @@ static void stm32_sdmmc2_start_data(struct stm32_sdmmc2_priv *priv,
static void stm32_sdmmc2_start_cmd(struct stm32_sdmmc2_priv *priv,
struct mmc_cmd *cmd, u32 cmd_param)
{
- if (readl(priv->base + SDMMC_ARG) & SDMMC_CMD_CPSMEN)
- writel(0, priv->base + SDMMC_ARG);
+ if (readl(priv->base + SDMMC_CMD) & SDMMC_CMD_CPSMEN)
+ writel(0, priv->base + SDMMC_CMD);
cmd_param |= cmd->cmdidx | SDMMC_CMD_CPSMEN;
if (cmd->resp_type & MMC_RSP_PRESENT) {
diff --git a/drivers/net/Makefile b/drivers/net/Makefile
index 851f82fb01..584bfdf2f9 100644
--- a/drivers/net/Makefile
+++ b/drivers/net/Makefile
@@ -58,7 +58,6 @@ obj-$(CONFIG_DRIVER_TI_EMAC) += davinci_emac.o
obj-$(CONFIG_TSEC_ENET) += tsec.o fsl_mdio.o
obj-$(CONFIG_DRIVER_TI_CPSW) += cpsw.o cpsw-common.o
obj-$(CONFIG_FMAN_ENET) += fsl_mdio.o
-obj-$(CONFIG_TSI108_ETH) += tsi108_eth.o
obj-$(CONFIG_ULI526X) += uli526x.o
obj-$(CONFIG_VSC7385_ENET) += vsc7385.o
obj-$(CONFIG_XILINX_AXIEMAC) += xilinx_axi_emac.o
diff --git a/drivers/net/tsi108_eth.c b/drivers/net/tsi108_eth.c
deleted file mode 100644
index 108cf61647..0000000000
--- a/drivers/net/tsi108_eth.c
+++ /dev/null
@@ -1,1015 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/***********************************************************************
- *
- * Copyright (c) 2005 Freescale Semiconductor, Inc.
- *
- * Description:
- * Ethernet interface for Tundra TSI108 bridge chip
- *
- ***********************************************************************/
-
-#include <config.h>
-
-#if !defined(CONFIG_TSI108_ETH_NUM_PORTS) || (CONFIG_TSI108_ETH_NUM_PORTS > 2)
-#error "CONFIG_TSI108_ETH_NUM_PORTS must be defined as 1 or 2"
-#endif
-
-#include <common.h>
-#include <malloc.h>
-#include <net.h>
-#include <netdev.h>
-#include <asm/cache.h>
-
-#ifdef DEBUG
-#define TSI108_ETH_DEBUG 7
-#else
-#define TSI108_ETH_DEBUG 0
-#endif
-
-#if TSI108_ETH_DEBUG > 0
-#define debug_lev(lev, fmt, args...) \
-if (lev <= TSI108_ETH_DEBUG) \
-printf ("%s %d: " fmt, __FUNCTION__, __LINE__, ##args)
-#else
-#define debug_lev(lev, fmt, args...) do{}while(0)
-#endif
-
-#define RX_PRINT_ERRORS
-#define TX_PRINT_ERRORS
-
-#define ETH_BASE (CONFIG_SYS_TSI108_CSR_BASE + 0x6000)
-
-#define ETH_PORT_OFFSET 0x400
-
-#define __REG32(base, offset) (*((volatile u32 *)((char *)(base) + (offset))))
-
-#define reg_MAC_CONFIG_1(base) __REG32(base, 0x00000000)
-#define MAC_CONFIG_1_TX_ENABLE (0x00000001)
-#define MAC_CONFIG_1_SYNC_TX_ENABLE (0x00000002)
-#define MAC_CONFIG_1_RX_ENABLE (0x00000004)
-#define MAC_CONFIG_1_SYNC_RX_ENABLE (0x00000008)
-#define MAC_CONFIG_1_TX_FLOW_CONTROL (0x00000010)
-#define MAC_CONFIG_1_RX_FLOW_CONTROL (0x00000020)
-#define MAC_CONFIG_1_LOOP_BACK (0x00000100)
-#define MAC_CONFIG_1_RESET_TX_FUNCTION (0x00010000)
-#define MAC_CONFIG_1_RESET_RX_FUNCTION (0x00020000)
-#define MAC_CONFIG_1_RESET_TX_MAC (0x00040000)
-#define MAC_CONFIG_1_RESET_RX_MAC (0x00080000)
-#define MAC_CONFIG_1_SIM_RESET (0x40000000)
-#define MAC_CONFIG_1_SOFT_RESET (0x80000000)
-
-#define reg_MAC_CONFIG_2(base) __REG32(base, 0x00000004)
-#define MAC_CONFIG_2_FULL_DUPLEX (0x00000001)
-#define MAC_CONFIG_2_CRC_ENABLE (0x00000002)
-#define MAC_CONFIG_2_PAD_CRC (0x00000004)
-#define MAC_CONFIG_2_LENGTH_CHECK (0x00000010)
-#define MAC_CONFIG_2_HUGE_FRAME (0x00000020)
-#define MAC_CONFIG_2_INTERFACE_MODE(val) (((val) & 0x3) << 8)
-#define MAC_CONFIG_2_PREAMBLE_LENGTH(val) (((val) & 0xf) << 12)
-#define INTERFACE_MODE_NIBBLE 1 /* 10/100 Mb/s MII) */
-#define INTERFACE_MODE_BYTE 2 /* 1000 Mb/s GMII/TBI */
-
-#define reg_MAXIMUM_FRAME_LENGTH(base) __REG32(base, 0x00000010)
-
-#define reg_MII_MGMT_CONFIG(base) __REG32(base, 0x00000020)
-#define MII_MGMT_CONFIG_MGMT_CLOCK_SELECT(val) ((val) & 0x7)
-#define MII_MGMT_CONFIG_NO_PREAMBLE (0x00000010)
-#define MII_MGMT_CONFIG_SCAN_INCREMENT (0x00000020)
-#define MII_MGMT_CONFIG_RESET_MGMT (0x80000000)
-
-#define reg_MII_MGMT_COMMAND(base) __REG32(base, 0x00000024)
-#define MII_MGMT_COMMAND_READ_CYCLE (0x00000001)
-#define MII_MGMT_COMMAND_SCAN_CYCLE (0x00000002)
-
-#define reg_MII_MGMT_ADDRESS(base) __REG32(base, 0x00000028)
-#define reg_MII_MGMT_CONTROL(base) __REG32(base, 0x0000002c)
-#define reg_MII_MGMT_STATUS(base) __REG32(base, 0x00000030)
-
-#define reg_MII_MGMT_INDICATORS(base) __REG32(base, 0x00000034)
-#define MII_MGMT_INDICATORS_BUSY (0x00000001)
-#define MII_MGMT_INDICATORS_SCAN (0x00000002)
-#define MII_MGMT_INDICATORS_NOT_VALID (0x00000004)
-
-#define reg_INTERFACE_STATUS(base) __REG32(base, 0x0000003c)
-#define INTERFACE_STATUS_LINK_FAIL (0x00000008)
-#define INTERFACE_STATUS_EXCESS_DEFER (0x00000200)
-
-#define reg_STATION_ADDRESS_1(base) __REG32(base, 0x00000040)
-#define reg_STATION_ADDRESS_2(base) __REG32(base, 0x00000044)
-
-#define reg_PORT_CONTROL(base) __REG32(base, 0x00000200)
-#define PORT_CONTROL_PRI (0x00000001)
-#define PORT_CONTROL_BPT (0x00010000)
-#define PORT_CONTROL_SPD (0x00040000)
-#define PORT_CONTROL_RBC (0x00080000)
-#define PORT_CONTROL_PRB (0x00200000)
-#define PORT_CONTROL_DIS (0x00400000)
-#define PORT_CONTROL_TBI (0x00800000)
-#define PORT_CONTROL_STE (0x10000000)
-#define PORT_CONTROL_ZOR (0x20000000)
-#define PORT_CONTROL_CLR (0x40000000)
-#define PORT_CONTROL_SRT (0x80000000)
-
-#define reg_TX_CONFIG(base) __REG32(base, 0x00000220)
-#define TX_CONFIG_START_Q (0x00000003)
-#define TX_CONFIG_EHP (0x00400000)
-#define TX_CONFIG_CHP (0x00800000)
-#define TX_CONFIG_RST (0x80000000)
-
-#define reg_TX_CONTROL(base) __REG32(base, 0x00000224)
-#define TX_CONTROL_GO (0x00008000)
-#define TX_CONTROL_MP (0x01000000)
-#define TX_CONTROL_EAI (0x20000000)
-#define TX_CONTROL_ABT (0x40000000)
-#define TX_CONTROL_EII (0x80000000)
-
-#define reg_TX_STATUS(base) __REG32(base, 0x00000228)
-#define TX_STATUS_QUEUE_USABLE (0x0000000f)
-#define TX_STATUS_CURR_Q (0x00000300)
-#define TX_STATUS_ACT (0x00008000)
-#define TX_STATUS_QUEUE_IDLE (0x000f0000)
-#define TX_STATUS_EOQ_PENDING (0x0f000000)
-
-#define reg_TX_EXTENDED_STATUS(base) __REG32(base, 0x0000022c)
-#define TX_EXTENDED_STATUS_END_OF_QUEUE_CONDITION (0x0000000f)
-#define TX_EXTENDED_STATUS_END_OF_FRAME_CONDITION (0x00000f00)
-#define TX_EXTENDED_STATUS_DESCRIPTOR_INTERRUPT_CONDITION (0x000f0000)
-#define TX_EXTENDED_STATUS_ERROR_FLAG (0x0f000000)
-
-#define reg_TX_THRESHOLDS(base) __REG32(base, 0x00000230)
-
-#define reg_TX_DIAGNOSTIC_ADDR(base) __REG32(base, 0x00000270)
-#define TX_DIAGNOSTIC_ADDR_INDEX (0x0000007f)
-#define TX_DIAGNOSTIC_ADDR_DFR (0x40000000)
-#define TX_DIAGNOSTIC_ADDR_AI (0x80000000)
-
-#define reg_TX_DIAGNOSTIC_DATA(base) __REG32(base, 0x00000274)
-
-#define reg_TX_ERROR_STATUS(base) __REG32(base, 0x00000278)
-#define TX_ERROR_STATUS (0x00000278)
-#define TX_ERROR_STATUS_QUEUE_0_ERROR_RESPONSE (0x0000000f)
-#define TX_ERROR_STATUS_TEA_ON_QUEUE_0 (0x00000010)
-#define TX_ERROR_STATUS_RER_ON_QUEUE_0 (0x00000020)
-#define TX_ERROR_STATUS_TER_ON_QUEUE_0 (0x00000040)
-#define TX_ERROR_STATUS_DER_ON_QUEUE_0 (0x00000080)
-#define TX_ERROR_STATUS_QUEUE_1_ERROR_RESPONSE (0x00000f00)
-#define TX_ERROR_STATUS_TEA_ON_QUEUE_1 (0x00001000)
-#define TX_ERROR_STATUS_RER_ON_QUEUE_1 (0x00002000)
-#define TX_ERROR_STATUS_TER_ON_QUEUE_1 (0x00004000)
-#define TX_ERROR_STATUS_DER_ON_QUEUE_1 (0x00008000)
-#define TX_ERROR_STATUS_QUEUE_2_ERROR_RESPONSE (0x000f0000)
-#define TX_ERROR_STATUS_TEA_ON_QUEUE_2 (0x00100000)
-#define TX_ERROR_STATUS_RER_ON_QUEUE_2 (0x00200000)
-#define TX_ERROR_STATUS_TER_ON_QUEUE_2 (0x00400000)
-#define TX_ERROR_STATUS_DER_ON_QUEUE_2 (0x00800000)
-#define TX_ERROR_STATUS_QUEUE_3_ERROR_RESPONSE (0x0f000000)
-#define TX_ERROR_STATUS_TEA_ON_QUEUE_3 (0x10000000)
-#define TX_ERROR_STATUS_RER_ON_QUEUE_3 (0x20000000)
-#define TX_ERROR_STATUS_TER_ON_QUEUE_3 (0x40000000)
-#define TX_ERROR_STATUS_DER_ON_QUEUE_3 (0x80000000)
-
-#define reg_TX_QUEUE_0_CONFIG(base) __REG32(base, 0x00000280)
-#define TX_QUEUE_0_CONFIG_OCN_PORT (0x0000003f)
-#define TX_QUEUE_0_CONFIG_BSWP (0x00000400)
-#define TX_QUEUE_0_CONFIG_WSWP (0x00000800)
-#define TX_QUEUE_0_CONFIG_AM (0x00004000)
-#define TX_QUEUE_0_CONFIG_GVI (0x00008000)
-#define TX_QUEUE_0_CONFIG_EEI (0x00010000)
-#define TX_QUEUE_0_CONFIG_ELI (0x00020000)
-#define TX_QUEUE_0_CONFIG_ENI (0x00040000)
-#define TX_QUEUE_0_CONFIG_ESI (0x00080000)
-#define TX_QUEUE_0_CONFIG_EDI (0x00100000)
-
-#define reg_TX_QUEUE_0_BUF_CONFIG(base) __REG32(base, 0x00000284)
-#define TX_QUEUE_0_BUF_CONFIG_OCN_PORT (0x0000003f)
-#define TX_QUEUE_0_BUF_CONFIG_BURST (0x00000300)
-#define TX_QUEUE_0_BUF_CONFIG_BSWP (0x00000400)
-#define TX_QUEUE_0_BUF_CONFIG_WSWP (0x00000800)
-
-#define OCN_PORT_HLP 0 /* HLP Interface */
-#define OCN_PORT_PCI_X 1 /* PCI-X Interface */
-#define OCN_PORT_PROCESSOR_MASTER 2 /* Processor Interface (master) */
-#define OCN_PORT_PROCESSOR_SLAVE 3 /* Processor Interface (slave) */
-#define OCN_PORT_MEMORY 4 /* Memory Controller */
-#define OCN_PORT_DMA 5 /* DMA Controller */
-#define OCN_PORT_ETHERNET 6 /* Ethernet Controller */
-#define OCN_PORT_PRINT 7 /* Print Engine Interface */
-
-#define reg_TX_QUEUE_0_PTR_LOW(base) __REG32(base, 0x00000288)
-
-#define reg_TX_QUEUE_0_PTR_HIGH(base) __REG32(base, 0x0000028c)
-#define TX_QUEUE_0_PTR_HIGH_VALID (0x80000000)
-
-#define reg_RX_CONFIG(base) __REG32(base, 0x00000320)
-#define RX_CONFIG_DEF_Q (0x00000003)
-#define RX_CONFIG_EMF (0x00000100)
-#define RX_CONFIG_EUF (0x00000200)
-#define RX_CONFIG_BFE (0x00000400)
-#define RX_CONFIG_MFE (0x00000800)
-#define RX_CONFIG_UFE (0x00001000)
-#define RX_CONFIG_SE (0x00002000)
-#define RX_CONFIG_ABF (0x00200000)
-#define RX_CONFIG_APE (0x00400000)
-#define RX_CONFIG_CHP (0x00800000)
-#define RX_CONFIG_RST (0x80000000)
-
-#define reg_RX_CONTROL(base) __REG32(base, 0x00000324)
-#define GE_E0_RX_CONTROL_QUEUE_ENABLES (0x0000000f)
-#define GE_E0_RX_CONTROL_GO (0x00008000)
-#define GE_E0_RX_CONTROL_EAI (0x20000000)
-#define GE_E0_RX_CONTROL_ABT (0x40000000)
-#define GE_E0_RX_CONTROL_EII (0x80000000)
-
-#define reg_RX_EXTENDED_STATUS(base) __REG32(base, 0x0000032c)
-#define RX_EXTENDED_STATUS (0x0000032c)
-#define RX_EXTENDED_STATUS_EOQ (0x0000000f)
-#define RX_EXTENDED_STATUS_EOQ_0 (0x00000001)
-#define RX_EXTENDED_STATUS_EOF (0x00000f00)
-#define RX_EXTENDED_STATUS_DESCRIPTOR_INTERRUPT_CONDITION (0x000f0000)
-#define RX_EXTENDED_STATUS_ERROR_FLAG (0x0f000000)
-
-#define reg_RX_THRESHOLDS(base) __REG32(base, 0x00000330)
-
-#define reg_RX_DIAGNOSTIC_ADDR(base) __REG32(base, 0x00000370)
-#define RX_DIAGNOSTIC_ADDR_INDEX (0x0000007f)
-#define RX_DIAGNOSTIC_ADDR_DFR (0x40000000)
-#define RX_DIAGNOSTIC_ADDR_AI (0x80000000)
-
-#define reg_RX_DIAGNOSTIC_DATA(base) __REG32(base, 0x00000374)
-
-#define reg_RX_QUEUE_0_CONFIG(base) __REG32(base, 0x00000380)
-#define RX_QUEUE_0_CONFIG_OCN_PORT (0x0000003f)
-#define RX_QUEUE_0_CONFIG_BSWP (0x00000400)
-#define RX_QUEUE_0_CONFIG_WSWP (0x00000800)
-#define RX_QUEUE_0_CONFIG_AM (0x00004000)
-#define RX_QUEUE_0_CONFIG_EEI (0x00010000)
-#define RX_QUEUE_0_CONFIG_ELI (0x00020000)
-#define RX_QUEUE_0_CONFIG_ENI (0x00040000)
-#define RX_QUEUE_0_CONFIG_ESI (0x00080000)
-#define RX_QUEUE_0_CONFIG_EDI (0x00100000)
-
-#define reg_RX_QUEUE_0_BUF_CONFIG(base) __REG32(base, 0x00000384)
-#define RX_QUEUE_0_BUF_CONFIG_OCN_PORT (0x0000003f)
-#define RX_QUEUE_0_BUF_CONFIG_BURST (0x00000300)
-#define RX_QUEUE_0_BUF_CONFIG_BSWP (0x00000400)
-#define RX_QUEUE_0_BUF_CONFIG_WSWP (0x00000800)
-
-#define reg_RX_QUEUE_0_PTR_LOW(base) __REG32(base, 0x00000388)
-
-#define reg_RX_QUEUE_0_PTR_HIGH(base) __REG32(base, 0x0000038c)
-#define RX_QUEUE_0_PTR_HIGH_VALID (0x80000000)
-
-/*
- * PHY register definitions
- */
-/* the first 15 PHY registers are standard. */
-#define PHY_CTRL_REG 0 /* Control Register */
-#define PHY_STATUS_REG 1 /* Status Regiser */
-#define PHY_ID1_REG 2 /* Phy Id Reg (word 1) */
-#define PHY_ID2_REG 3 /* Phy Id Reg (word 2) */
-#define PHY_AN_ADV_REG 4 /* Autoneg Advertisement */
-#define PHY_LP_ABILITY_REG 5 /* Link Partner Ability (Base Page) */
-#define PHY_AUTONEG_EXP_REG 6 /* Autoneg Expansion Reg */
-#define PHY_NEXT_PAGE_TX_REG 7 /* Next Page TX */
-#define PHY_LP_NEXT_PAGE_REG 8 /* Link Partner Next Page */
-#define PHY_1000T_CTRL_REG 9 /* 1000Base-T Control Reg */
-#define PHY_1000T_STATUS_REG 10 /* 1000Base-T Status Reg */
-#define PHY_EXT_STATUS_REG 11 /* Extended Status Reg */
-
-/*
- * PHY Register bit masks.
- */
-#define PHY_CTRL_RESET (1 << 15)
-#define PHY_CTRL_LOOPBACK (1 << 14)
-#define PHY_CTRL_SPEED0 (1 << 13)
-#define PHY_CTRL_AN_EN (1 << 12)
-#define PHY_CTRL_PWR_DN (1 << 11)
-#define PHY_CTRL_ISOLATE (1 << 10)
-#define PHY_CTRL_RESTART_AN (1 << 9)
-#define PHY_CTRL_FULL_DUPLEX (1 << 8)
-#define PHY_CTRL_CT_EN (1 << 7)
-#define PHY_CTRL_SPEED1 (1 << 6)
-
-#define PHY_STAT_100BASE_T4 (1 << 15)
-#define PHY_STAT_100BASE_X_FD (1 << 14)
-#define PHY_STAT_100BASE_X_HD (1 << 13)
-#define PHY_STAT_10BASE_T_FD (1 << 12)
-#define PHY_STAT_10BASE_T_HD (1 << 11)
-#define PHY_STAT_100BASE_T2_FD (1 << 10)
-#define PHY_STAT_100BASE_T2_HD (1 << 9)
-#define PHY_STAT_EXT_STAT (1 << 8)
-#define PHY_STAT_RESERVED (1 << 7)
-#define PHY_STAT_MFPS (1 << 6) /* Management Frames Preamble Suppression */
-#define PHY_STAT_AN_COMPLETE (1 << 5)
-#define PHY_STAT_REM_FAULT (1 << 4)
-#define PHY_STAT_AN_CAP (1 << 3)
-#define PHY_STAT_LINK_UP (1 << 2)
-#define PHY_STAT_JABBER (1 << 1)
-#define PHY_STAT_EXT_CAP (1 << 0)
-
-#define TBI_CONTROL_2 0x11
-#define TBI_CONTROL_2_ENABLE_COMMA_DETECT 0x0001
-#define TBI_CONTROL_2_ENABLE_WRAP 0x0002
-#define TBI_CONTROL_2_G_MII_MODE 0x0010
-#define TBI_CONTROL_2_RECEIVE_CLOCK_SELECT 0x0020
-#define TBI_CONTROL_2_AUTO_NEGOTIATION_SENSE 0x0100
-#define TBI_CONTROL_2_DISABLE_TRANSMIT_RUNNING_DISPARITY 0x1000
-#define TBI_CONTROL_2_DISABLE_RECEIVE_RUNNING_DISPARITY 0x2000
-#define TBI_CONTROL_2_SHORTCUT_LINK_TIMER 0x4000
-#define TBI_CONTROL_2_SOFT_RESET 0x8000
-
-/* marvel specific */
-#define MV1111_EXT_CTRL1_REG 16 /* PHY Specific Control Reg */
-#define MV1111_SPEC_STAT_REG 17 /* PHY Specific Status Reg */
-#define MV1111_EXT_CTRL2_REG 20 /* Extended PHY Specific Control Reg */
-
-/*
- * MARVELL 88E1111 PHY register bit masks
- */
-/* PHY Specific Status Register (MV1111_EXT_CTRL1_REG) */
-
-#define SPEC_STAT_SPEED_MASK (3 << 14)
-#define SPEC_STAT_FULL_DUP (1 << 13)
-#define SPEC_STAT_PAGE_RCVD (1 << 12)
-#define SPEC_STAT_RESOLVED (1 << 11) /* Speed and Duplex Resolved */
-#define SPEC_STAT_LINK_UP (1 << 10)
-#define SPEC_STAT_CABLE_LEN_MASK (7 << 7)/* Cable Length (100/1000 modes only) */
-#define SPEC_STAT_MDIX (1 << 6)
-#define SPEC_STAT_POLARITY (1 << 1)
-#define SPEC_STAT_JABBER (1 << 0)
-
-#define SPEED_1000 (2 << 14)
-#define SPEED_100 (1 << 14)
-#define SPEED_10 (0 << 14)
-
-#define TBI_ADDR 0x1E /* Ten Bit Interface address */
-
-/* negotiated link parameters */
-#define LINK_SPEED_UNKNOWN 0
-#define LINK_SPEED_10 1
-#define LINK_SPEED_100 2
-#define LINK_SPEED_1000 3
-
-#define LINK_DUPLEX_UNKNOWN 0
-#define LINK_DUPLEX_HALF 1
-#define LINK_DUPLEX_FULL 2
-
-static unsigned int phy_address[] = { 8, 9 };
-
-#define vuint32 volatile u32
-
-/* TX/RX buffer descriptors. MUST be cache line aligned in memory. (32 byte)
- * This structure is accessed by the ethernet DMA engine which means it
- * MUST be in LITTLE ENDIAN format */
-struct dma_descriptor {
- vuint32 start_addr0; /* buffer address, least significant bytes. */
- vuint32 start_addr1; /* buffer address, most significant bytes. */
- vuint32 next_descr_addr0;/* next descriptor address, least significant bytes. Must be 64-bit aligned. */
- vuint32 next_descr_addr1;/* next descriptor address, most significant bytes. */
- vuint32 vlan_byte_count;/* VLAN tag(top 2 bytes) and byte countt (bottom 2 bytes). */
- vuint32 config_status; /* Configuration/Status. */
- vuint32 reserved1; /* reserved to make the descriptor cache line aligned. */
- vuint32 reserved2; /* reserved to make the descriptor cache line aligned. */
-};
-
-/* last next descriptor address flag */
-#define DMA_DESCR_LAST (1 << 31)
-
-/* TX DMA descriptor config status bits */
-#define DMA_DESCR_TX_EOF (1 << 0) /* end of frame */
-#define DMA_DESCR_TX_SOF (1 << 1) /* start of frame */
-#define DMA_DESCR_TX_PFVLAN (1 << 2)
-#define DMA_DESCR_TX_HUGE (1 << 3)
-#define DMA_DESCR_TX_PAD (1 << 4)
-#define DMA_DESCR_TX_CRC (1 << 5)
-#define DMA_DESCR_TX_DESCR_INT (1 << 14)
-#define DMA_DESCR_TX_RETRY_COUNT 0x000F0000
-#define DMA_DESCR_TX_ONE_COLLISION (1 << 20)
-#define DMA_DESCR_TX_LATE_COLLISION (1 << 24)
-#define DMA_DESCR_TX_UNDERRUN (1 << 25)
-#define DMA_DESCR_TX_RETRY_LIMIT (1 << 26)
-#define DMA_DESCR_TX_OK (1 << 30)
-#define DMA_DESCR_TX_OWNER (1 << 31)
-
-/* RX DMA descriptor status bits */
-#define DMA_DESCR_RX_EOF (1 << 0)
-#define DMA_DESCR_RX_SOF (1 << 1)
-#define DMA_DESCR_RX_VTF (1 << 2)
-#define DMA_DESCR_RX_FRAME_IS_TYPE (1 << 3)
-#define DMA_DESCR_RX_SHORT_FRAME (1 << 4)
-#define DMA_DESCR_RX_HASH_MATCH (1 << 7)
-#define DMA_DESCR_RX_BAD_FRAME (1 << 8)
-#define DMA_DESCR_RX_OVERRUN (1 << 9)
-#define DMA_DESCR_RX_MAX_FRAME_LEN (1 << 11)
-#define DMA_DESCR_RX_CRC_ERROR (1 << 12)
-#define DMA_DESCR_RX_DESCR_INT (1 << 13)
-#define DMA_DESCR_RX_OWNER (1 << 15)
-
-#define RX_BUFFER_SIZE PKTSIZE
-#define NUM_RX_DESC PKTBUFSRX
-
-static struct dma_descriptor tx_descriptor __attribute__ ((aligned(32)));
-
-static struct dma_descriptor rx_descr_array[NUM_RX_DESC]
- __attribute__ ((aligned(32)));
-
-static struct dma_descriptor *rx_descr_current;
-
-static int tsi108_eth_probe (struct eth_device *dev, bd_t * bis);
-static int tsi108_eth_send(struct eth_device *dev, void *packet, int length);
-static int tsi108_eth_recv (struct eth_device *dev);
-static void tsi108_eth_halt (struct eth_device *dev);
-static unsigned int read_phy (unsigned int base,
- unsigned int phy_addr, unsigned int phy_reg);
-static void write_phy (unsigned int base,
- unsigned int phy_addr,
- unsigned int phy_reg, unsigned int phy_data);
-
-#if TSI108_ETH_DEBUG > 100
-/*
- * print phy debug infomation
- */
-static void dump_phy_regs (unsigned int phy_addr)
-{
- int i;
-
- printf ("PHY %d registers\n", phy_addr);
- for (i = 0; i <= 30; i++) {
- printf ("%2d 0x%04x\n", i, read_phy (ETH_BASE, phy_addr, i));
- }
- printf ("\n");
-
-}
-#else
-#define dump_phy_regs(base) do{}while(0)
-#endif
-
-#if TSI108_ETH_DEBUG > 100
-/*
- * print debug infomation
- */
-static void tx_diag_regs (unsigned int base)
-{
- int i;
- unsigned long dummy;
-
- printf ("TX diagnostics registers\n");
- reg_TX_DIAGNOSTIC_ADDR(base) = 0x00 | TX_DIAGNOSTIC_ADDR_AI;
- udelay (1000);
- dummy = reg_TX_DIAGNOSTIC_DATA(base);
- for (i = 0x00; i <= 0x05; i++) {
- udelay (1000);
- printf ("0x%02x 0x%08x\n", i, reg_TX_DIAGNOSTIC_DATA(base));
- }
- reg_TX_DIAGNOSTIC_ADDR(base) = 0x40 | TX_DIAGNOSTIC_ADDR_AI;
- udelay (1000);
- dummy = reg_TX_DIAGNOSTIC_DATA(base);
- for (i = 0x40; i <= 0x47; i++) {
- udelay (1000);
- printf ("0x%02x 0x%08x\n", i, reg_TX_DIAGNOSTIC_DATA(base));
- }
- printf ("\n");
-
-}
-#else
-#define tx_diag_regs(base) do{}while(0)
-#endif
-
-#if TSI108_ETH_DEBUG > 100
-/*
- * print debug infomation
- */
-static void rx_diag_regs (unsigned int base)
-{
- int i;
- unsigned long dummy;
-
- printf ("RX diagnostics registers\n");
- reg_RX_DIAGNOSTIC_ADDR(base) = 0x00 | RX_DIAGNOSTIC_ADDR_AI;
- udelay (1000);
- dummy = reg_RX_DIAGNOSTIC_DATA(base);
- for (i = 0x00; i <= 0x05; i++) {
- udelay (1000);
- printf ("0x%02x 0x%08x\n", i, reg_RX_DIAGNOSTIC_DATA(base));
- }
- reg_RX_DIAGNOSTIC_ADDR(base) = 0x40 | RX_DIAGNOSTIC_ADDR_AI;
- udelay (1000);
- dummy = reg_RX_DIAGNOSTIC_DATA(base);
- for (i = 0x08; i <= 0x0a; i++) {
- udelay (1000);
- printf ("0x%02x 0x%08x\n", i, reg_RX_DIAGNOSTIC_DATA(base));
- }
- printf ("\n");
-
-}
-#else
-#define rx_diag_regs(base) do{}while(0)
-#endif
-
-#if TSI108_ETH_DEBUG > 100
-/*
- * print debug infomation
- */
-static void debug_mii_regs (unsigned int base)
-{
- printf ("MII_MGMT_CONFIG 0x%08x\n", reg_MII_MGMT_CONFIG(base));
- printf ("MII_MGMT_COMMAND 0x%08x\n", reg_MII_MGMT_COMMAND(base));
- printf ("MII_MGMT_ADDRESS 0x%08x\n", reg_MII_MGMT_ADDRESS(base));
- printf ("MII_MGMT_CONTROL 0x%08x\n", reg_MII_MGMT_CONTROL(base));
- printf ("MII_MGMT_STATUS 0x%08x\n", reg_MII_MGMT_STATUS(base));
- printf ("MII_MGMT_INDICATORS 0x%08x\n", reg_MII_MGMT_INDICATORS(base));
- printf ("\n");
-
-}
-#else
-#define debug_mii_regs(base) do{}while(0)
-#endif
-
-/*
- * Wait until the phy bus is non-busy
- */
-static void phy_wait (unsigned int base, unsigned int condition)
-{
- int timeout;
-
- timeout = 0;
- while (reg_MII_MGMT_INDICATORS(base) & condition) {
- udelay (10);
- if (++timeout > 10000) {
- printf ("ERROR: timeout waiting for phy bus (%d)\n",
- condition);
- break;
- }
- }
-}
-
-/*
- * read phy register
- */
-static unsigned int read_phy (unsigned int base,
- unsigned int phy_addr, unsigned int phy_reg)
-{
- unsigned int value;
-
- phy_wait (base, MII_MGMT_INDICATORS_BUSY);
-
- reg_MII_MGMT_ADDRESS(base) = (phy_addr << 8) | phy_reg;
-
- /* Ensure that the Read Cycle bit is cleared prior to next read cycle */
- reg_MII_MGMT_COMMAND(base) = 0;
-
- /* start the read */
- reg_MII_MGMT_COMMAND(base) = MII_MGMT_COMMAND_READ_CYCLE;
-
- /* wait for the read to complete */
- phy_wait (base,
- MII_MGMT_INDICATORS_NOT_VALID | MII_MGMT_INDICATORS_BUSY);
-
- value = reg_MII_MGMT_STATUS(base);
-
- reg_MII_MGMT_COMMAND(base) = 0;
-
- return value;
-}
-
-/*
- * write phy register
- */
-static void write_phy (unsigned int base,
- unsigned int phy_addr,
- unsigned int phy_reg, unsigned int phy_data)
-{
- phy_wait (base, MII_MGMT_INDICATORS_BUSY);
-
- reg_MII_MGMT_ADDRESS(base) = (phy_addr << 8) | phy_reg;
-
- /* Ensure that the Read Cycle bit is cleared prior to next cycle */
- reg_MII_MGMT_COMMAND(base) = 0;
-
- /* start the write */
- reg_MII_MGMT_CONTROL(base) = phy_data;
-}
-
-/*
- * configure the marvell 88e1111 phy
- */
-static int marvell_88e_phy_config (struct eth_device *dev, int *speed,
- int *duplex)
-{
- unsigned long base;
- unsigned long phy_addr;
- unsigned int phy_status;
- unsigned int phy_spec_status;
- int timeout;
- int phy_speed;
- int phy_duplex;
- unsigned int value;
-
- phy_speed = LINK_SPEED_UNKNOWN;
- phy_duplex = LINK_DUPLEX_UNKNOWN;
-
- base = dev->iobase;
- phy_addr = (unsigned long)dev->priv;
-
- /* Take the PHY out of reset. */
- write_phy (ETH_BASE, phy_addr, PHY_CTRL_REG, PHY_CTRL_RESET);
-
- /* Wait for the reset process to complete. */
- udelay (10);
- timeout = 0;
- while ((phy_status =
- read_phy (ETH_BASE, phy_addr, PHY_CTRL_REG)) & PHY_CTRL_RESET) {
- udelay (10);
- if (++timeout > 10000) {
- printf ("ERROR: timeout waiting for phy reset\n");
- break;
- }
- }
-
- /* TBI Configuration. */
- write_phy (base, TBI_ADDR, TBI_CONTROL_2, TBI_CONTROL_2_G_MII_MODE |
- TBI_CONTROL_2_RECEIVE_CLOCK_SELECT);
- /* Wait for the link to be established. */
- timeout = 0;
- do {
- udelay (20000);
- phy_status = read_phy (ETH_BASE, phy_addr, PHY_STATUS_REG);
- if (++timeout > 100) {
- debug_lev(1, "ERROR: unable to establish link!!!\n");
- break;
- }
- } while ((phy_status & PHY_STAT_LINK_UP) == 0);
-
- if ((phy_status & PHY_STAT_LINK_UP) == 0)
- return 0;
-
- value = 0;
- phy_spec_status = read_phy (ETH_BASE, phy_addr, MV1111_SPEC_STAT_REG);
- if (phy_spec_status & SPEC_STAT_RESOLVED) {
- switch (phy_spec_status & SPEC_STAT_SPEED_MASK) {
- case SPEED_1000:
- phy_speed = LINK_SPEED_1000;
- value |= PHY_CTRL_SPEED1;
- break;
- case SPEED_100:
- phy_speed = LINK_SPEED_100;
- value |= PHY_CTRL_SPEED0;
- break;
- case SPEED_10:
- phy_speed = LINK_SPEED_10;
- break;
- }
- if (phy_spec_status & SPEC_STAT_FULL_DUP) {
- phy_duplex = LINK_DUPLEX_FULL;
- value |= PHY_CTRL_FULL_DUPLEX;
- } else
- phy_duplex = LINK_DUPLEX_HALF;
- }
- /* set TBI speed */
- write_phy (base, TBI_ADDR, PHY_CTRL_REG, value);
- write_phy (base, TBI_ADDR, PHY_AN_ADV_REG, 0x0060);
-
-#if TSI108_ETH_DEBUG > 0
- printf ("%s link is up", dev->name);
- phy_spec_status = read_phy (ETH_BASE, phy_addr, MV1111_SPEC_STAT_REG);
- if (phy_spec_status & SPEC_STAT_RESOLVED) {
- switch (phy_speed) {
- case LINK_SPEED_1000:
- printf (", 1000 Mbps");
- break;
- case LINK_SPEED_100:
- printf (", 100 Mbps");
- break;
- case LINK_SPEED_10:
- printf (", 10 Mbps");
- break;
- }
- if (phy_duplex == LINK_DUPLEX_FULL)
- printf (", Full duplex");
- else
- printf (", Half duplex");
- }
- printf ("\n");
-#endif
-
- dump_phy_regs (TBI_ADDR);
- if (speed)
- *speed = phy_speed;
- if (duplex)
- *duplex = phy_duplex;
-
- return 1;
-}
-
-/*
- * External interface
- *
- * register the tsi108 ethernet controllers with the multi-ethernet system
- */
-int tsi108_eth_initialize (bd_t * bis)
-{
- struct eth_device *dev;
- int index;
-
- for (index = 0; index < CONFIG_TSI108_ETH_NUM_PORTS; index++) {
- dev = (struct eth_device *)malloc(sizeof(struct eth_device));
- if (!dev) {
- printf("tsi108: Can not allocate memory\n");
- break;
- }
- memset(dev, 0, sizeof(*dev));
- sprintf (dev->name, "TSI108_eth%d", index);
-
- dev->iobase = ETH_BASE + (index * ETH_PORT_OFFSET);
- dev->priv = (void *)(phy_address[index]);
- dev->init = tsi108_eth_probe;
- dev->halt = tsi108_eth_halt;
- dev->send = tsi108_eth_send;
- dev->recv = tsi108_eth_recv;
-
- eth_register(dev);
- }
- return index;
-}
-
-/*
- * probe for and initialize a single ethernet interface
- */
-static int tsi108_eth_probe (struct eth_device *dev, bd_t * bis)
-{
- unsigned long base;
- unsigned long value;
- int index;
- struct dma_descriptor *tx_descr;
- struct dma_descriptor *rx_descr;
- int speed;
- int duplex;
-
- base = dev->iobase;
-
- reg_PORT_CONTROL(base) = PORT_CONTROL_STE | PORT_CONTROL_BPT;
-
- /* Bring DMA/FIFO out of reset. */
- reg_TX_CONFIG(base) = 0x00000000;
- reg_RX_CONFIG(base) = 0x00000000;
-
- reg_TX_THRESHOLDS(base) = (192 << 16) | 192;
- reg_RX_THRESHOLDS(base) = (192 << 16) | 112;
-
- /* Bring MAC out of reset. */
- reg_MAC_CONFIG_1(base) = 0x00000000;
-
- /* DMA MAC configuration. */
- reg_MAC_CONFIG_1(base) =
- MAC_CONFIG_1_RX_ENABLE | MAC_CONFIG_1_TX_ENABLE;
-
- reg_MII_MGMT_CONFIG(base) = MII_MGMT_CONFIG_NO_PREAMBLE;
- reg_MAXIMUM_FRAME_LENGTH(base) = RX_BUFFER_SIZE;
-
- /* Note: Early tsi108 manual did not have correct byte order
- * for the station address.*/
- reg_STATION_ADDRESS_1(base) = (dev->enetaddr[5] << 24) |
- (dev->enetaddr[4] << 16) |
- (dev->enetaddr[3] << 8) | (dev->enetaddr[2] << 0);
-
- reg_STATION_ADDRESS_2(base) = (dev->enetaddr[1] << 24) |
- (dev->enetaddr[0] << 16);
-
- if (marvell_88e_phy_config(dev, &speed, &duplex) == 0)
- return -1;
-
- value =
- MAC_CONFIG_2_PREAMBLE_LENGTH(7) | MAC_CONFIG_2_PAD_CRC |
- MAC_CONFIG_2_CRC_ENABLE;
- if (speed == LINK_SPEED_1000)
- value |= MAC_CONFIG_2_INTERFACE_MODE(INTERFACE_MODE_BYTE);
- else {
- value |= MAC_CONFIG_2_INTERFACE_MODE(INTERFACE_MODE_NIBBLE);
- reg_PORT_CONTROL(base) |= PORT_CONTROL_SPD;
- }
- if (duplex == LINK_DUPLEX_FULL) {
- value |= MAC_CONFIG_2_FULL_DUPLEX;
- reg_PORT_CONTROL(base) &= ~PORT_CONTROL_BPT;
- } else
- reg_PORT_CONTROL(base) |= PORT_CONTROL_BPT;
- reg_MAC_CONFIG_2(base) = value;
-
- reg_RX_CONFIG(base) = RX_CONFIG_SE;
- reg_RX_QUEUE_0_CONFIG(base) = OCN_PORT_MEMORY;
- reg_RX_QUEUE_0_BUF_CONFIG(base) = OCN_PORT_MEMORY;
-
- /* initialize the RX DMA descriptors */
- rx_descr = &rx_descr_array[0];
- rx_descr_current = rx_descr;
- for (index = 0; index < NUM_RX_DESC; index++) {
- /* make sure the receive buffers are not in cache */
- invalidate_dcache_range((unsigned long)net_rx_packets[index],
- (unsigned long)net_rx_packets[index] +
- RX_BUFFER_SIZE);
- rx_descr->start_addr0 =
- cpu_to_le32((vuint32) net_rx_packets[index]);
- rx_descr->start_addr1 = 0;
- rx_descr->next_descr_addr0 =
- cpu_to_le32((vuint32) (rx_descr + 1));
- rx_descr->next_descr_addr1 = 0;
- rx_descr->vlan_byte_count = 0;
- rx_descr->config_status = cpu_to_le32((RX_BUFFER_SIZE << 16) |
- DMA_DESCR_RX_OWNER);
- rx_descr++;
- }
- rx_descr--;
- rx_descr->next_descr_addr0 = 0;
- rx_descr->next_descr_addr1 = cpu_to_le32(DMA_DESCR_LAST);
- /* Push the descriptors to RAM so the ethernet DMA can see them */
- invalidate_dcache_range((unsigned long)rx_descr_array,
- (unsigned long)rx_descr_array +
- sizeof(rx_descr_array));
-
- /* enable RX queue */
- reg_RX_CONTROL(base) = TX_CONTROL_GO | 0x01;
- reg_RX_QUEUE_0_PTR_LOW(base) = (u32) rx_descr_current;
- /* enable receive DMA */
- reg_RX_QUEUE_0_PTR_HIGH(base) = RX_QUEUE_0_PTR_HIGH_VALID;
-
- reg_TX_QUEUE_0_CONFIG(base) = OCN_PORT_MEMORY;
- reg_TX_QUEUE_0_BUF_CONFIG(base) = OCN_PORT_MEMORY;
-
- /* initialize the TX DMA descriptor */
- tx_descr = &tx_descriptor;
-
- tx_descr->start_addr0 = 0;
- tx_descr->start_addr1 = 0;
- tx_descr->next_descr_addr0 = 0;
- tx_descr->next_descr_addr1 = cpu_to_le32(DMA_DESCR_LAST);
- tx_descr->vlan_byte_count = 0;
- tx_descr->config_status = cpu_to_le32(DMA_DESCR_TX_OK |
- DMA_DESCR_TX_SOF |
- DMA_DESCR_TX_EOF);
- /* enable TX queue */
- reg_TX_CONTROL(base) = TX_CONTROL_GO | 0x01;
-
- return 0;
-}
-
-/*
- * send a packet
- */
-static int tsi108_eth_send(struct eth_device *dev, void *packet, int length)
-{
- unsigned long base;
- int timeout;
- struct dma_descriptor *tx_descr;
- unsigned long status;
-
- base = dev->iobase;
- tx_descr = &tx_descriptor;
-
- /* Wait until the last packet has been transmitted. */
- timeout = 0;
- do {
- /* make sure we see the changes made by the DMA engine */
- invalidate_dcache_range((unsigned long)tx_descr,
- (unsigned long)tx_descr +
- sizeof(struct dma_descriptor));
-
- if (timeout != 0)
- udelay (15);
- if (++timeout > 10000) {
- tx_diag_regs(base);
- debug_lev(1,
- "ERROR: timeout waiting for last transmit packet to be sent\n");
- return 0;
- }
- } while (tx_descr->config_status & cpu_to_le32(DMA_DESCR_TX_OWNER));
-
- status = le32_to_cpu(tx_descr->config_status);
- if ((status & DMA_DESCR_TX_OK) == 0) {
-#ifdef TX_PRINT_ERRORS
- printf ("TX packet error: 0x%08lx\n %s%s%s%s\n", status,
- status & DMA_DESCR_TX_OK ? "tx error, " : "",
- status & DMA_DESCR_TX_RETRY_LIMIT ?
- "retry limit reached, " : "",
- status & DMA_DESCR_TX_UNDERRUN ? "underrun, " : "",
- status & DMA_DESCR_TX_LATE_COLLISION ? "late collision, "
- : "");
-#endif
- }
-
- debug_lev (9, "sending packet %d\n", length);
- tx_descr->start_addr0 = cpu_to_le32((vuint32) packet);
- tx_descr->start_addr1 = 0;
- tx_descr->next_descr_addr0 = 0;
- tx_descr->next_descr_addr1 = cpu_to_le32(DMA_DESCR_LAST);
- tx_descr->vlan_byte_count = cpu_to_le32(length);
- tx_descr->config_status = cpu_to_le32(DMA_DESCR_TX_OWNER |
- DMA_DESCR_TX_CRC |
- DMA_DESCR_TX_PAD |
- DMA_DESCR_TX_SOF |
- DMA_DESCR_TX_EOF);
-
- invalidate_dcache_range((unsigned long)tx_descr,
- (unsigned long)tx_descr +
- sizeof(struct dma_descriptor));
-
- invalidate_dcache_range((unsigned long)packet,
- (unsigned long)packet + length);
-
- reg_TX_QUEUE_0_PTR_LOW(base) = (u32) tx_descr;
- reg_TX_QUEUE_0_PTR_HIGH(base) = TX_QUEUE_0_PTR_HIGH_VALID;
-
- return length;
-}
-
-/*
- * Check for received packets and send them up the protocal stack
- */
-static int tsi108_eth_recv (struct eth_device *dev)
-{
- struct dma_descriptor *rx_descr;
- unsigned long base;
- int length = 0;
- unsigned long status;
- uchar *buffer;
-
- base = dev->iobase;
-
- /* make sure we see the changes made by the DMA engine */
- invalidate_dcache_range ((unsigned long)rx_descr_array,
- (unsigned long)rx_descr_array +
- sizeof(rx_descr_array));
-
- /* process all of the received packets */
- rx_descr = rx_descr_current;
- while ((rx_descr->config_status & cpu_to_le32(DMA_DESCR_RX_OWNER)) == 0) {
- /* check for error */
- status = le32_to_cpu(rx_descr->config_status);
- if (status & DMA_DESCR_RX_BAD_FRAME) {
-#ifdef RX_PRINT_ERRORS
- printf ("RX packet error: 0x%08lx\n %s%s%s%s%s%s\n",
- status,
- status & DMA_DESCR_RX_FRAME_IS_TYPE ? "too big, "
- : "",
- status & DMA_DESCR_RX_SHORT_FRAME ? "too short, "
- : "",
- status & DMA_DESCR_RX_BAD_FRAME ? "bad frame, " :
- "",
- status & DMA_DESCR_RX_OVERRUN ? "overrun, " : "",
- status & DMA_DESCR_RX_MAX_FRAME_LEN ?
- "max length, " : "",
- status & DMA_DESCR_RX_CRC_ERROR ? "CRC error, " :
- "");
-#endif
- } else {
- length =
- le32_to_cpu(rx_descr->vlan_byte_count) & 0xFFFF;
-
- /*** process packet ***/
- buffer = (uchar *)(le32_to_cpu(rx_descr->start_addr0));
- net_process_received_packet(buffer, length);
-
- invalidate_dcache_range ((unsigned long)buffer,
- (unsigned long)buffer +
- RX_BUFFER_SIZE);
- }
- /* Give this buffer back to the DMA engine */
- rx_descr->vlan_byte_count = 0;
- rx_descr->config_status = cpu_to_le32 ((RX_BUFFER_SIZE << 16) |
- DMA_DESCR_RX_OWNER);
- /* move descriptor pointer forward */
- rx_descr =
- (struct dma_descriptor
- *)(le32_to_cpu (rx_descr->next_descr_addr0));
- if (rx_descr == 0)
- rx_descr = &rx_descr_array[0];
- }
- /* remember where we are for next time */
- rx_descr_current = rx_descr;
-
- /* If the DMA engine has reached the end of the queue
- * start over at the begining */
- if (reg_RX_EXTENDED_STATUS(base) & RX_EXTENDED_STATUS_EOQ_0) {
-
- reg_RX_EXTENDED_STATUS(base) = RX_EXTENDED_STATUS_EOQ_0;
- reg_RX_QUEUE_0_PTR_LOW(base) = (u32) & rx_descr_array[0];
- reg_RX_QUEUE_0_PTR_HIGH(base) = RX_QUEUE_0_PTR_HIGH_VALID;
- }
-
- return length;
-}
-
-/*
- * disable an ethernet interface
- */
-static void tsi108_eth_halt (struct eth_device *dev)
-{
- unsigned long base;
-
- base = dev->iobase;
-
- /* Put DMA/FIFO into reset state. */
- reg_TX_CONFIG(base) = TX_CONFIG_RST;
- reg_RX_CONFIG(base) = RX_CONFIG_RST;
-
- /* Put MAC into reset state. */
- reg_MAC_CONFIG_1(base) = MAC_CONFIG_1_SOFT_RESET;
-}
diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
index 49be1ebdd7..1cd1e409e3 100644
--- a/drivers/pci/pci-uclass.c
+++ b/drivers/pci/pci-uclass.c
@@ -860,6 +860,13 @@ static int decode_regions(struct pci_controller *hose, ofnode parent_node,
} else {
continue;
}
+
+ if (!IS_ENABLED(CONFIG_SYS_PCI_64BIT) &&
+ type == PCI_REGION_MEM && upper_32_bits(pci_addr)) {
+ debug(" - beyond the 32-bit boundary, ignoring\n");
+ continue;
+ }
+
pos = -1;
for (i = 0; i < hose->region_count; i++) {
if (hose->regions[i].flags == type)
diff --git a/drivers/pci/pci_auto.c b/drivers/pci/pci_auto.c
index d1feb503a0..d7237f6eee 100644
--- a/drivers/pci/pci_auto.c
+++ b/drivers/pci/pci_auto.c
@@ -98,7 +98,8 @@ void dm_pciauto_setup_device(struct udevice *dev, int bars_num,
}
if (!enum_only && pciauto_region_allocate(bar_res, bar_size,
- &bar_value) == 0) {
+ &bar_value,
+ found_mem64) == 0) {
/* Write it out and update our limit */
dm_pci_write_config32(dev, bar, (u32)bar_value);
@@ -140,7 +141,8 @@ void dm_pciauto_setup_device(struct udevice *dev, int bars_num,
debug("PCI Autoconfig: ROM, size=%#x, ",
(unsigned int)bar_size);
if (pciauto_region_allocate(mem, bar_size,
- &bar_value) == 0) {
+ &bar_value,
+ false) == 0) {
dm_pci_write_config32(dev, rom_addr,
bar_value);
}
diff --git a/drivers/pci/pci_auto_common.c b/drivers/pci/pci_auto_common.c
index 1d202ae2ef..183787333e 100644
--- a/drivers/pci/pci_auto_common.c
+++ b/drivers/pci/pci_auto_common.c
@@ -32,12 +32,12 @@ void pciauto_region_align(struct pci_region *res, pci_size_t size)
}
int pciauto_region_allocate(struct pci_region *res, pci_size_t size,
- pci_addr_t *bar)
+ pci_addr_t *bar, bool supports_64bit)
{
pci_addr_t addr;
if (!res) {
- debug("No resource");
+ debug("No resource\n");
goto error;
}
@@ -48,9 +48,14 @@ int pciauto_region_allocate(struct pci_region *res, pci_size_t size,
goto error;
}
+ if (upper_32_bits(addr) && !supports_64bit) {
+ debug("Cannot assign 64-bit address to 32-bit-only resource\n");
+ goto error;
+ }
+
res->bus_lower = addr + size;
- debug("address=0x%llx bus_lower=0x%llx", (unsigned long long)addr,
+ debug("address=0x%llx bus_lower=0x%llx\n", (unsigned long long)addr,
(unsigned long long)res->bus_lower);
*bar = addr;
diff --git a/drivers/pci/pci_auto_old.c b/drivers/pci/pci_auto_old.c
index bc119fba87..e705a3072e 100644
--- a/drivers/pci/pci_auto_old.c
+++ b/drivers/pci/pci_auto_old.c
@@ -108,7 +108,8 @@ void pciauto_setup_device(struct pci_controller *hose,
}
#ifndef CONFIG_PCI_ENUM_ONLY
- if (pciauto_region_allocate(bar_res, bar_size, &bar_value) == 0) {
+ if (pciauto_region_allocate(bar_res, bar_size,
+ &bar_value, found_mem64) == 0) {
/* Write it out and update our limit */
pci_hose_write_config_dword(hose, dev, bar, (u32)bar_value);
@@ -150,7 +151,7 @@ void pciauto_setup_device(struct pci_controller *hose,
debug("PCI Autoconfig: ROM, size=%#x, ",
(unsigned int)bar_size);
if (pciauto_region_allocate(mem, bar_size,
- &bar_value) == 0) {
+ &bar_value, false) == 0) {
pci_hose_write_config_dword(hose, dev, rom_addr,
bar_value);
}
diff --git a/drivers/ram/stm32_sdram.c b/drivers/ram/stm32_sdram.c
index dc39f33d16..f6cac8eb90 100644
--- a/drivers/ram/stm32_sdram.c
+++ b/drivers/ram/stm32_sdram.c
@@ -11,6 +11,8 @@
#include <asm/io.h>
#define MEM_MODE_MASK GENMASK(2, 0)
+#define SWP_FMC_OFFSET 10
+#define SWP_FMC_MASK GENMASK(SWP_FMC_OFFSET+1, SWP_FMC_OFFSET)
#define NOT_FOUND 0xff
struct stm32_fmc_regs {
@@ -256,27 +258,36 @@ static int stm32_fmc_ofdata_to_platdata(struct udevice *dev)
struct ofnode_phandle_args args;
u32 *syscfg_base;
u32 mem_remap;
+ u32 swp_fmc;
ofnode bank_node;
char *bank_name;
u8 bank = 0;
int ret;
- mem_remap = dev_read_u32_default(dev, "st,mem_remap", NOT_FOUND);
- if (mem_remap != NOT_FOUND) {
- ret = dev_read_phandle_with_args(dev, "st,syscfg", NULL, 0, 0,
+ ret = dev_read_phandle_with_args(dev, "st,syscfg", NULL, 0, 0,
&args);
- if (ret) {
- debug("%s: can't find syscon device (%d)\n", __func__,
- ret);
- return ret;
- }
-
+ if (ret) {
+ dev_dbg(dev, "%s: can't find syscon device (%d)\n", __func__, ret);
+ } else {
syscfg_base = (u32 *)ofnode_get_addr(args.node);
- /* set memory mapping selection */
- clrsetbits_le32(syscfg_base, MEM_MODE_MASK, mem_remap);
- } else {
- debug("%s: cannot find st,mem_remap property\n", __func__);
+ mem_remap = dev_read_u32_default(dev, "st,mem_remap", NOT_FOUND);
+ if (mem_remap != NOT_FOUND) {
+ /* set memory mapping selection */
+ clrsetbits_le32(syscfg_base, MEM_MODE_MASK, mem_remap);
+ } else {
+ dev_dbg(dev, "%s: cannot find st,mem_remap property\n", __func__);
+ }
+
+ swp_fmc = dev_read_u32_default(dev, "st,swp_fmc", NOT_FOUND);
+ if (swp_fmc != NOT_FOUND) {
+ /* set fmc swapping selection */
+ clrsetbits_le32(syscfg_base, SWP_FMC_MASK, swp_fmc << SWP_FMC_OFFSET);
+ } else {
+ dev_dbg(dev, "%s: cannot find st,swp_fmc property\n", __func__);
+ }
+
+ dev_dbg(dev, "syscfg %x = %x\n", (u32)syscfg_base, *syscfg_base);
}
dev_for_each_subnode(bank_node, dev) {
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 5937910e5b..2940bd05dc 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -197,6 +197,15 @@ config DEBUG_UART_AR933X
driver will be available until the real driver model serial is
running.
+config DEBUG_ARC_SERIAL
+ bool "ARC UART"
+ depends on ARC_SERIAL
+ help
+ Select this to enable a debug UART using the ARC UART driver.
+ You will need to provide parameters to make this work. The
+ driver will be available until the real driver model serial is
+ running.
+
config DEBUG_UART_ATMEL
bool "Atmel USART"
help
@@ -315,6 +324,15 @@ config DEBUG_UART_MXC
will need to provide parameters to make this work. The driver will
be available until the real driver model serial is running.
+config DEBUG_UART_STM32
+ bool "STMicroelectronics STM32"
+ depends on STM32_SERIAL
+ help
+ Select this to enable a debug UART using the serial_stm32 driver
+ You will need to provide parameters to make this work.
+ The driver will be available until the real driver model
+ serial is running.
+
config DEBUG_UART_UNIPHIER
bool "UniPhier on-chip UART"
depends on ARCH_UNIPHIER
@@ -425,6 +443,13 @@ config AR933X_UART
tree binding to operate, please refer to the document at
doc/device-tree-bindings/serial/qca,ar9330-uart.txt.
+config ARC_SERIAL
+ bool "ARC UART support"
+ depends on DM_SERIAL
+ help
+ Select this to enable support for ARC UART now typically
+ only used in Synopsys DesignWare ARC simulators like nSIM.
+
config ATMEL_USART
bool "Atmel USART support"
help
diff --git a/drivers/serial/serial_arc.c b/drivers/serial/serial_arc.c
index da4a07ab2f..925f0c2555 100644
--- a/drivers/serial/serial_arc.c
+++ b/drivers/serial/serial_arc.c
@@ -130,3 +130,29 @@ U_BOOT_DRIVER(serial_arc) = {
.ops = &arc_serial_ops,
.flags = DM_FLAG_PRE_RELOC,
};
+
+#ifdef CONFIG_DEBUG_ARC_SERIAL
+#include <debug_uart.h>
+
+static inline void _debug_uart_init(void)
+{
+ struct arc_serial_regs *regs = (struct arc_serial_regs *)CONFIG_DEBUG_UART_BASE;
+ int arc_console_baud = CONFIG_DEBUG_UART_CLOCK / (CONFIG_BAUDRATE * 4) - 1;
+
+ writeb(arc_console_baud & 0xff, &regs->baudl);
+ writeb((arc_console_baud & 0xff00) >> 8, &regs->baudh);
+}
+
+static inline void _debug_uart_putc(int c)
+{
+ struct arc_serial_regs *regs = (struct arc_serial_regs *)CONFIG_DEBUG_UART_BASE;
+
+ while (!(readb(&regs->status) & UART_TXEMPTY))
+ ;
+
+ writeb(c, &regs->data);
+}
+
+DEBUG_UART_FUNCS
+
+#endif
diff --git a/drivers/serial/serial_msm.c b/drivers/serial/serial_msm.c
index 119e6b9846..c462394dbd 100644
--- a/drivers/serial/serial_msm.c
+++ b/drivers/serial/serial_msm.c
@@ -16,6 +16,7 @@
#include <watchdog.h>
#include <asm/io.h>
#include <linux/compiler.h>
+#include <dm/pinctrl.h>
/* Serial registers - this driver works in uartdm mode*/
@@ -25,6 +26,9 @@
#define UARTDM_RXFS 0x50 /* RX channel status register */
#define UARTDM_RXFS_BUF_SHIFT 0x7 /* Number of bytes in the packing buffer */
#define UARTDM_RXFS_BUF_MASK 0x7
+#define UARTDM_MR1 0x00
+#define UARTDM_MR2 0x04
+#define UARTDM_CSR 0xA0
#define UARTDM_SR 0xA4 /* Status register */
#define UARTDM_SR_RX_READY (1 << 0) /* Word is the receiver FIFO */
@@ -45,6 +49,10 @@
#define UARTDM_TF 0x100 /* UART Transmit FIFO register */
#define UARTDM_RF 0x140 /* UART Receive FIFO register */
+#define UART_DM_CLK_RX_TX_BIT_RATE 0xCC
+#define MSM_BOOT_UART_DM_8_N_1_MODE 0x34
+#define MSM_BOOT_UART_DM_CMD_RESET_RX 0x10
+#define MSM_BOOT_UART_DM_CMD_RESET_TX 0x20
DECLARE_GLOBAL_DATA_PTR;
@@ -179,19 +187,29 @@ static int msm_uart_clk_init(struct udevice *dev)
return 0;
}
+static void uart_dm_init(struct msm_serial_data *priv)
+{
+ writel(UART_DM_CLK_RX_TX_BIT_RATE, priv->base + UARTDM_CSR);
+ writel(0x0, priv->base + UARTDM_MR1);
+ writel(MSM_BOOT_UART_DM_8_N_1_MODE, priv->base + UARTDM_MR2);
+ writel(MSM_BOOT_UART_DM_CMD_RESET_RX, priv->base + UARTDM_CR);
+ writel(MSM_BOOT_UART_DM_CMD_RESET_TX, priv->base + UARTDM_CR);
+}
static int msm_serial_probe(struct udevice *dev)
{
+ int ret;
struct msm_serial_data *priv = dev_get_priv(dev);
- msm_uart_clk_init(dev); /* Ignore return value and hope clock was
- properly initialized by earlier loaders */
+ /* No need to reinitialize the UART after relocation */
+ if (gd->flags & GD_FLG_RELOC)
+ return 0;
- if (readl(priv->base + UARTDM_SR) & UARTDM_SR_UART_OVERRUN)
- writel(UARTDM_CR_CMD_RESET_ERR, priv->base + UARTDM_CR);
+ ret = msm_uart_clk_init(dev);
+ if (ret)
+ return ret;
- writel(0, priv->base + UARTDM_IMR);
- writel(UARTDM_CR_CMD_STALE_EVENT_DISABLE, priv->base + UARTDM_CR);
- msm_serial_fetch(dev);
+ pinctrl_select_state(dev, "uart");
+ uart_dm_init(priv);
return 0;
}
diff --git a/drivers/serial/serial_stm32.c b/drivers/serial/serial_stm32.c
index 6717ffaaa5..f26234549c 100644
--- a/drivers/serial/serial_stm32.c
+++ b/drivers/serial/serial_stm32.c
@@ -7,19 +7,21 @@
#include <common.h>
#include <clk.h>
#include <dm.h>
-#include <asm/io.h>
#include <serial.h>
+#include <watchdog.h>
+#include <asm/io.h>
#include <asm/arch/stm32.h>
#include "serial_stm32.h"
-static int stm32_serial_setbrg(struct udevice *dev, int baudrate)
+static void _stm32_serial_setbrg(fdt_addr_t base,
+ struct stm32_uart_info *uart_info,
+ u32 clock_rate,
+ int baudrate)
{
- struct stm32x7_serial_platdata *plat = dev_get_platdata(dev);
- bool stm32f4 = plat->uart_info->stm32f4;
- fdt_addr_t base = plat->base;
+ bool stm32f4 = uart_info->stm32f4;
u32 int_div, mantissa, fraction, oversampling;
- int_div = DIV_ROUND_CLOSEST(plat->clock_rate, baudrate);
+ int_div = DIV_ROUND_CLOSEST(clock_rate, baudrate);
if (int_div < 16) {
oversampling = 8;
@@ -33,6 +35,53 @@ static int stm32_serial_setbrg(struct udevice *dev, int baudrate)
fraction = int_div % oversampling;
writel(mantissa | fraction, base + BRR_OFFSET(stm32f4));
+}
+
+static int stm32_serial_setbrg(struct udevice *dev, int baudrate)
+{
+ struct stm32x7_serial_platdata *plat = dev_get_platdata(dev);
+
+ _stm32_serial_setbrg(plat->base, plat->uart_info,
+ plat->clock_rate, baudrate);
+
+ return 0;
+}
+
+static int stm32_serial_setparity(struct udevice *dev, enum serial_par parity)
+{
+ struct stm32x7_serial_platdata *plat = dev_get_platdata(dev);
+ bool stm32f4 = plat->uart_info->stm32f4;
+ u8 uart_enable_bit = plat->uart_info->uart_enable_bit;
+ u32 cr1 = plat->base + CR1_OFFSET(stm32f4);
+ u32 config = 0;
+
+ if (stm32f4)
+ return -EINVAL; /* not supported in driver*/
+
+ clrbits_le32(cr1, USART_CR1_RE | USART_CR1_TE | BIT(uart_enable_bit));
+ /* update usart configuration (uart need to be disable)
+ * PCE: parity check control
+ * PS : '0' : Even / '1' : Odd
+ * M[1:0] = '00' : 8 Data bits
+ * M[1:0] = '01' : 9 Data bits with parity
+ */
+ switch (parity) {
+ default:
+ case SERIAL_PAR_NONE:
+ config = 0;
+ break;
+ case SERIAL_PAR_ODD:
+ config = USART_CR1_PCE | USART_CR1_PS | USART_CR1_M0;
+ break;
+ case SERIAL_PAR_EVEN:
+ config = USART_CR1_PCE | USART_CR1_M0;
+ break;
+ }
+ clrsetbits_le32(cr1,
+ USART_CR1_PCE | USART_CR1_PS | USART_CR1_M1 |
+ USART_CR1_M0,
+ config);
+ setbits_le32(cr1, USART_CR1_RE | USART_CR1_TE | BIT(uart_enable_bit));
return 0;
}
@@ -44,12 +93,13 @@ static int stm32_serial_getc(struct udevice *dev)
fdt_addr_t base = plat->base;
u32 isr = readl(base + ISR_OFFSET(stm32f4));
- if ((isr & USART_ISR_FLAG_RXNE) == 0)
+ if ((isr & USART_ISR_RXNE) == 0)
return -EAGAIN;
- if (isr & USART_ISR_FLAG_ORE) {
+ if (isr & (USART_ISR_PE | USART_ISR_ORE)) {
if (!stm32f4)
- setbits_le32(base + ICR_OFFSET, USART_ICR_OREF);
+ setbits_le32(base + ICR_OFFSET,
+ USART_ICR_PCECF | USART_ICR_ORECF);
else
readl(base + RDR_OFFSET(stm32f4));
return -EIO;
@@ -58,13 +108,13 @@ static int stm32_serial_getc(struct udevice *dev)
return readl(base + RDR_OFFSET(stm32f4));
}
-static int stm32_serial_putc(struct udevice *dev, const char c)
+static int _stm32_serial_putc(fdt_addr_t base,
+ struct stm32_uart_info *uart_info,
+ const char c)
{
- struct stm32x7_serial_platdata *plat = dev_get_platdata(dev);
- bool stm32f4 = plat->uart_info->stm32f4;
- fdt_addr_t base = plat->base;
+ bool stm32f4 = uart_info->stm32f4;
- if ((readl(base + ISR_OFFSET(stm32f4)) & USART_ISR_FLAG_TXE) == 0)
+ if ((readl(base + ISR_OFFSET(stm32f4)) & USART_ISR_TXE) == 0)
return -EAGAIN;
writel(c, base + TDR_OFFSET(stm32f4));
@@ -72,6 +122,13 @@ static int stm32_serial_putc(struct udevice *dev, const char c)
return 0;
}
+static int stm32_serial_putc(struct udevice *dev, const char c)
+{
+ struct stm32x7_serial_platdata *plat = dev_get_platdata(dev);
+
+ return _stm32_serial_putc(plat->base, plat->uart_info, c);
+}
+
static int stm32_serial_pending(struct udevice *dev, bool input)
{
struct stm32x7_serial_platdata *plat = dev_get_platdata(dev);
@@ -80,24 +137,34 @@ static int stm32_serial_pending(struct udevice *dev, bool input)
if (input)
return readl(base + ISR_OFFSET(stm32f4)) &
- USART_ISR_FLAG_RXNE ? 1 : 0;
+ USART_ISR_RXNE ? 1 : 0;
else
return readl(base + ISR_OFFSET(stm32f4)) &
- USART_ISR_FLAG_TXE ? 0 : 1;
+ USART_ISR_TXE ? 0 : 1;
+}
+
+static void _stm32_serial_init(fdt_addr_t base,
+ struct stm32_uart_info *uart_info)
+{
+ bool stm32f4 = uart_info->stm32f4;
+ u8 uart_enable_bit = uart_info->uart_enable_bit;
+
+ /* Disable uart-> enable fifo -> enable uart */
+ clrbits_le32(base + CR1_OFFSET(stm32f4), USART_CR1_RE | USART_CR1_TE |
+ BIT(uart_enable_bit));
+ if (uart_info->has_fifo)
+ setbits_le32(base + CR1_OFFSET(stm32f4), USART_CR1_FIFOEN);
+ setbits_le32(base + CR1_OFFSET(stm32f4), USART_CR1_RE | USART_CR1_TE |
+ BIT(uart_enable_bit));
}
static int stm32_serial_probe(struct udevice *dev)
{
struct stm32x7_serial_platdata *plat = dev_get_platdata(dev);
struct clk clk;
- fdt_addr_t base = plat->base;
int ret;
- bool stm32f4;
- u8 uart_enable_bit;
plat->uart_info = (struct stm32_uart_info *)dev_get_driver_data(dev);
- stm32f4 = plat->uart_info->stm32f4;
- uart_enable_bit = plat->uart_info->uart_enable_bit;
ret = clk_get_by_index(dev, 0, &clk);
if (ret < 0)
@@ -115,13 +182,7 @@ static int stm32_serial_probe(struct udevice *dev)
return plat->clock_rate;
};
- /* Disable uart-> enable fifo-> enable uart */
- clrbits_le32(base + CR1_OFFSET(stm32f4), USART_CR1_RE | USART_CR1_TE |
- BIT(uart_enable_bit));
- if (plat->uart_info->has_fifo)
- setbits_le32(base + CR1_OFFSET(stm32f4), USART_CR1_FIFOEN);
- setbits_le32(base + CR1_OFFSET(stm32f4), USART_CR1_RE | USART_CR1_TE |
- BIT(uart_enable_bit));
+ _stm32_serial_init(plat->base, plat->uart_info);
return 0;
}
@@ -149,6 +210,7 @@ static const struct dm_serial_ops stm32_serial_ops = {
.pending = stm32_serial_pending,
.getc = stm32_serial_getc,
.setbrg = stm32_serial_setbrg,
+ .setparity = stm32_serial_setparity
};
U_BOOT_DRIVER(serial_stm32) = {
@@ -161,3 +223,43 @@ U_BOOT_DRIVER(serial_stm32) = {
.probe = stm32_serial_probe,
.flags = DM_FLAG_PRE_RELOC,
};
+
+#ifdef CONFIG_DEBUG_UART_STM32
+#include <debug_uart.h>
+static inline struct stm32_uart_info *_debug_uart_info(void)
+{
+ struct stm32_uart_info *uart_info;
+
+#if defined(CONFIG_STM32F4)
+ uart_info = &stm32f4_info;
+#elif defined(CONFIG_STM32F7)
+ uart_info = &stm32f7_info;
+#else
+ uart_info = &stm32h7_info;
+#endif
+ return uart_info;
+}
+
+static inline void _debug_uart_init(void)
+{
+ fdt_addr_t base = CONFIG_DEBUG_UART_BASE;
+ struct stm32_uart_info *uart_info = _debug_uart_info();
+
+ _stm32_serial_init(base, uart_info);
+ _stm32_serial_setbrg(base, uart_info,
+ CONFIG_DEBUG_UART_CLOCK,
+ CONFIG_BAUDRATE);
+ printf("DEBUG done\n");
+}
+
+static inline void _debug_uart_putc(int c)
+{
+ fdt_addr_t base = CONFIG_DEBUG_UART_BASE;
+ struct stm32_uart_info *uart_info = _debug_uart_info();
+
+ while (_stm32_serial_putc(base, uart_info, c) == -EAGAIN)
+ WATCHDOG_RESET();
+}
+
+DEBUG_UART_FUNCS
+#endif
diff --git a/drivers/serial/serial_stm32.h b/drivers/serial/serial_stm32.h
index 8a1a24fda8..ccafa31219 100644
--- a/drivers/serial/serial_stm32.h
+++ b/drivers/serial/serial_stm32.h
@@ -13,6 +13,7 @@
#define ISR_OFFSET(x) (x ? 0x00 : 0x1c)
#define ICR_OFFSET 0x20
+
/*
* STM32F4 has one Data Register (DR) for received or transmitted
* data, so map Receive Data Register (RDR) and Transmit Data
@@ -53,19 +54,26 @@ struct stm32x7_serial_platdata {
};
#define USART_CR1_FIFOEN BIT(29)
+#define USART_CR1_M1 BIT(28)
#define USART_CR1_OVER8 BIT(15)
+#define USART_CR1_M0 BIT(12)
+#define USART_CR1_PCE BIT(10)
+#define USART_CR1_PS BIT(9)
#define USART_CR1_TE BIT(3)
#define USART_CR1_RE BIT(2)
#define USART_CR3_OVRDIS BIT(12)
-#define USART_ISR_FLAG_ORE BIT(3)
-#define USART_ISR_FLAG_RXNE BIT(5)
-#define USART_ISR_FLAG_TXE BIT(7)
+#define USART_ISR_TXE BIT(7)
+#define USART_ISR_RXNE BIT(5)
+#define USART_ISR_ORE BIT(3)
+#define USART_ISR_PE BIT(0)
#define USART_BRR_F_MASK GENMASK(7, 0)
#define USART_BRR_M_SHIFT 4
#define USART_BRR_M_MASK GENMASK(15, 4)
-#define USART_ICR_OREF BIT(3)
+#define USART_ICR_ORECF BIT(3)
+#define USART_ICR_PCECF BIT(0)
+
#endif
diff --git a/drivers/tpm/Kconfig b/drivers/tpm/Kconfig
index 2a64bc49c3..93264ddd34 100644
--- a/drivers/tpm/Kconfig
+++ b/drivers/tpm/Kconfig
@@ -4,18 +4,31 @@
menu "TPM support"
+comment "Please select only one TPM revision"
+ depends on TPM_V1 && TPM_V2
+
+config TPM_V1
+ bool "TPMv1.x support"
+ depends on TPM
+ default y
+ help
+ Major TPM versions are not compatible at all, choose either
+ one or the other. This option enables TPMv1.x drivers/commands.
+
+if TPM_V1 && !TPM_V2
+
config TPM_TIS_SANDBOX
bool "Enable sandbox TPM driver"
- depends on SANDBOX
+ depends on TPM_V1 && SANDBOX
help
- This driver emulates a TPM, providing access to base functions
+ This driver emulates a TPMv1.x, providing access to base functions
such as reading and writing TPM private data. This is enough to
support Chrome OS verified boot. Extend functionality is not
implemented.
config TPM_ATMEL_TWI
bool "Enable Atmel TWI TPM device driver"
- depends on TPM
+ depends on TPM_V1
help
This driver supports an Atmel TPM device connected on the I2C bus.
The usual tpm operations and the 'tpm' command can be used to talk
@@ -24,7 +37,7 @@ config TPM_ATMEL_TWI
config TPM_TIS_INFINEON
bool "Enable support for Infineon SLB9635/45 TPMs on I2C"
- depends on TPM && DM_I2C
+ depends on TPM_V1 && DM_I2C
help
This driver supports Infineon TPM devices connected on the I2C bus.
The usual tpm operations and the 'tpm' command can be used to talk
@@ -48,7 +61,8 @@ config TPM_TIS_I2C_BURST_LIMITATION_LEN
config TPM_TIS_LPC
bool "Enable support for Infineon SLB9635/45 TPMs on LPC"
- depends on TPM && X86
+ depends on TPM_V1 && X86
+ select TPM_DRIVER_SELECTED
help
This driver supports Infineon TPM devices connected on the LPC bus.
The usual tpm operations and the 'tpm' command can be used to talk
@@ -57,7 +71,7 @@ config TPM_TIS_LPC
config TPM_AUTH_SESSIONS
bool "Enable TPM authentication session support"
- depends on TPM
+ depends on TPM_V1
help
Enable support for authorised (AUTH1) commands as specified in the
TCG Main Specification 1.2. OIAP-authorised versions of the commands
@@ -66,7 +80,7 @@ config TPM_AUTH_SESSIONS
config TPM_ST33ZP24_I2C
bool "STMicroelectronics ST33ZP24 I2C TPM"
- depends on TPM && DM_I2C
+ depends on TPM_V1 && DM_I2C
---help---
This driver supports STMicroelectronics TPM devices connected on the I2C bus.
The usual tpm operations and the 'tpm' command can be used to talk
@@ -75,7 +89,7 @@ config TPM_ST33ZP24_I2C
config TPM_ST33ZP24_SPI
bool "STMicroelectronics ST33ZP24 SPI TPM"
- depends on TPM && DM_SPI
+ depends on TPM_V1 && DM_SPI
---help---
This driver supports STMicroelectronics TPM devices connected on the SPI bus.
The usual tpm operations and the 'tpm' command can be used to talk
@@ -84,14 +98,14 @@ config TPM_ST33ZP24_SPI
config TPM_FLUSH_RESOURCES
bool "Enable TPM resource flushing support"
- depends on TPM
+ depends on TPM_V1
help
Enable support to flush specific resources (e.g. keys) from the TPM.
The functionality is available via the 'tpm' command as well.
config TPM_LOAD_KEY_BY_SHA1
bool "Enable TPM key loading by SHA1 support"
- depends on TPM
+ depends on TPM_V1
help
Enable support to load keys into the TPM by identifying
their parent via the public key's SHA1 hash.
@@ -99,8 +113,41 @@ config TPM_LOAD_KEY_BY_SHA1
config TPM_LIST_RESOURCES
bool "Enable TPM resource listing support"
- depends on TPM
+ depends on TPM_V1
help
Enable support to list specific resources (e.g. keys) within the TPM.
The functionality is available via the 'tpm' command as well.
+
+endif # TPM_V1
+
+config TPM_V2
+ bool "TPMv2.x support"
+ depends on TPM
+ help
+ Major TPM versions are not compatible at all, choose either
+ one or the other. This option enables TPMv2.x drivers/commands.
+
+if TPM_V2 && !TPM_V1
+
+config TPM2_TIS_SANDBOX
+ bool "Enable sandbox TPMv2.x driver"
+ depends on TPM_V2 && SANDBOX
+ select TPM_DRIVER_SELECTED
+ help
+ This driver emulates a TPMv2.x, providing access to base functions
+ such as basic configuration, PCR extension and PCR read. Extended
+ functionalities are not implemented.
+
+config TPM2_TIS_SPI
+ bool "Enable support for TPMv2.x SPI chips"
+ depends on TPM_V2 && DM_SPI
+ select TPM_DRIVER_SELECTED
+ help
+ This driver supports TPMv2.x devices connected on the SPI bus.
+ The usual TPM operations and the 'tpm' command can be used to talk
+ to the device using the standard TPM Interface Specification (TIS)
+ protocol.
+
+endif # TPM_V2
+
endmenu
diff --git a/drivers/tpm/Makefile b/drivers/tpm/Makefile
index e5fc86ff95..af473ef662 100644
--- a/drivers/tpm/Makefile
+++ b/drivers/tpm/Makefile
@@ -9,3 +9,6 @@ obj-$(CONFIG_TPM_TIS_LPC) += tpm_tis_lpc.o
obj-$(CONFIG_TPM_TIS_SANDBOX) += tpm_tis_sandbox.o
obj-$(CONFIG_TPM_ST33ZP24_I2C) += tpm_tis_st33zp24_i2c.o
obj-$(CONFIG_TPM_ST33ZP24_SPI) += tpm_tis_st33zp24_spi.o
+
+obj-$(CONFIG_TPM2_TIS_SANDBOX) += tpm2_tis_sandbox.o
+obj-$(CONFIG_TPM2_TIS_SPI) += tpm2_tis_spi.o
diff --git a/drivers/tpm/tpm-uclass.c b/drivers/tpm/tpm-uclass.c
index e71545235c..412697eedc 100644
--- a/drivers/tpm/tpm-uclass.c
+++ b/drivers/tpm/tpm-uclass.c
@@ -6,8 +6,12 @@
#include <common.h>
#include <dm.h>
-#include <tpm.h>
#include <linux/unaligned/be_byteshift.h>
+#if defined(CONFIG_TPM_V1)
+#include <tpm-v1.h>
+#elif defined(CONFIG_TPM_V2)
+#include <tpm-v2.h>
+#endif
#include "tpm_internal.h"
int tpm_open(struct udevice *dev)
diff --git a/drivers/tpm/tpm2_tis_sandbox.c b/drivers/tpm/tpm2_tis_sandbox.c
new file mode 100644
index 0000000000..3240cc5dba
--- /dev/null
+++ b/drivers/tpm/tpm2_tis_sandbox.c
@@ -0,0 +1,625 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2018, Bootlin
+ * Author: Miquel Raynal <miquel.raynal@bootlin.com>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <tpm-v2.h>
+#include <asm/state.h>
+#include <asm/unaligned.h>
+#include <linux/crc8.h>
+
+/* Hierarchies */
+enum tpm2_hierarchy {
+ TPM2_HIERARCHY_LOCKOUT = 0,
+ TPM2_HIERARCHY_ENDORSEMENT,
+ TPM2_HIERARCHY_PLATFORM,
+ TPM2_HIERARCHY_NB,
+};
+
+/* Subset of supported capabilities */
+enum tpm2_capability {
+ TPM_CAP_TPM_PROPERTIES = 0x6,
+};
+
+/* Subset of supported properties */
+#define TPM2_PROPERTIES_OFFSET 0x0000020E
+
+enum tpm2_cap_tpm_property {
+ TPM2_FAIL_COUNTER = 0,
+ TPM2_PROP_MAX_TRIES,
+ TPM2_RECOVERY_TIME,
+ TPM2_LOCKOUT_RECOVERY,
+ TPM2_PROPERTY_NB,
+};
+
+#define SANDBOX_TPM_PCR_NB 1
+
+static const u8 sandbox_extended_once_pcr[] = {
+ 0xf5, 0xa5, 0xfd, 0x42, 0xd1, 0x6a, 0x20, 0x30,
+ 0x27, 0x98, 0xef, 0x6e, 0xd3, 0x09, 0x97, 0x9b,
+ 0x43, 0x00, 0x3d, 0x23, 0x20, 0xd9, 0xf0, 0xe8,
+ 0xea, 0x98, 0x31, 0xa9, 0x27, 0x59, 0xfb, 0x4b,
+};
+
+struct sandbox_tpm2 {
+ /* TPM internal states */
+ bool init_done;
+ bool startup_done;
+ bool tests_done;
+ /* TPM password per hierarchy */
+ char pw[TPM2_HIERARCHY_NB][TPM2_DIGEST_LEN + 1];
+ int pw_sz[TPM2_HIERARCHY_NB];
+ /* TPM properties */
+ u32 properties[TPM2_PROPERTY_NB];
+ /* TPM PCRs */
+ u8 pcr[SANDBOX_TPM_PCR_NB][TPM2_DIGEST_LEN];
+ /* TPM PCR extensions */
+ u32 pcr_extensions[SANDBOX_TPM_PCR_NB];
+};
+
+/*
+ * Check the tag validity depending on the command (authentication required or
+ * not). If authentication is required, check it is valid. Update the auth
+ * pointer to point to the next chunk of data to process if needed.
+ */
+static int sandbox_tpm2_check_session(struct udevice *dev, u32 command, u16 tag,
+ const u8 **auth,
+ enum tpm2_hierarchy *hierarchy)
+{
+ struct sandbox_tpm2 *tpm = dev_get_priv(dev);
+ u32 handle, auth_sz, session_handle;
+ u16 nonce_sz, pw_sz;
+ const char *pw;
+
+ switch (command) {
+ case TPM2_CC_STARTUP:
+ case TPM2_CC_SELF_TEST:
+ case TPM2_CC_GET_CAPABILITY:
+ case TPM2_CC_PCR_READ:
+ if (tag != TPM2_ST_NO_SESSIONS) {
+ printf("No session required for command 0x%x\n",
+ command);
+ return TPM2_RC_BAD_TAG;
+ }
+
+ return 0;
+
+ case TPM2_CC_CLEAR:
+ case TPM2_CC_HIERCHANGEAUTH:
+ case TPM2_CC_DAM_RESET:
+ case TPM2_CC_DAM_PARAMETERS:
+ case TPM2_CC_PCR_EXTEND:
+ if (tag != TPM2_ST_SESSIONS) {
+ printf("Session required for command 0x%x\n", command);
+ return TPM2_RC_AUTH_CONTEXT;
+ }
+
+ handle = get_unaligned_be32(*auth);
+ *auth += sizeof(handle);
+
+ /*
+ * PCR_Extend had a different protection mechanism and does not
+ * use the same standards as other commands.
+ */
+ if (command == TPM2_CC_PCR_EXTEND)
+ break;
+
+ switch (handle) {
+ case TPM2_RH_LOCKOUT:
+ *hierarchy = TPM2_HIERARCHY_LOCKOUT;
+ break;
+ case TPM2_RH_ENDORSEMENT:
+ if (command == TPM2_CC_CLEAR) {
+ printf("Endorsement hierarchy unsupported\n");
+ return TPM2_RC_AUTH_MISSING;
+ }
+ *hierarchy = TPM2_HIERARCHY_ENDORSEMENT;
+ break;
+ case TPM2_RH_PLATFORM:
+ *hierarchy = TPM2_HIERARCHY_PLATFORM;
+ break;
+ default:
+ printf("Wrong handle 0x%x\n", handle);
+ return TPM2_RC_VALUE;
+ }
+
+ break;
+
+ default:
+ printf("Command code not recognized: 0x%x\n", command);
+ return TPM2_RC_COMMAND_CODE;
+ }
+
+ auth_sz = get_unaligned_be32(*auth);
+ *auth += sizeof(auth_sz);
+
+ session_handle = get_unaligned_be32(*auth);
+ *auth += sizeof(session_handle);
+ if (session_handle != TPM2_RS_PW) {
+ printf("Wrong session handle 0x%x\n", session_handle);
+ return TPM2_RC_VALUE;
+ }
+
+ nonce_sz = get_unaligned_be16(*auth);
+ *auth += sizeof(nonce_sz);
+ if (nonce_sz) {
+ printf("Nonces not supported in Sandbox, aborting\n");
+ return TPM2_RC_HANDLE;
+ }
+
+ /* Ignore attributes */
+ *auth += sizeof(u8);
+
+ pw_sz = get_unaligned_be16(*auth);
+ *auth += sizeof(pw_sz);
+ if (auth_sz != (9 + nonce_sz + pw_sz)) {
+ printf("Authentication size (%d) do not match %d\n",
+ auth_sz, 9 + nonce_sz + pw_sz);
+ return TPM2_RC_SIZE;
+ }
+
+ /* No passwork is acceptable */
+ if (!pw_sz && !tpm->pw_sz[*hierarchy])
+ return TPM2_RC_SUCCESS;
+
+ /* Password is too long */
+ if (pw_sz > TPM2_DIGEST_LEN) {
+ printf("Password should not be more than %dB\n",
+ TPM2_DIGEST_LEN);
+ return TPM2_RC_AUTHSIZE;
+ }
+
+ pw = (const char *)*auth;
+ *auth += pw_sz;
+
+ /* Password is wrong */
+ if (pw_sz != tpm->pw_sz[*hierarchy] ||
+ strncmp(pw, tpm->pw[*hierarchy], tpm->pw_sz[*hierarchy])) {
+ printf("Authentication failed: wrong password.\n");
+ return TPM2_RC_BAD_AUTH;
+ }
+
+ return TPM2_RC_SUCCESS;
+}
+
+static int sandbox_tpm2_check_readyness(struct udevice *dev, int command)
+{
+ struct sandbox_tpm2 *tpm = dev_get_priv(dev);
+
+ switch (command) {
+ case TPM2_CC_STARTUP:
+ if (!tpm->init_done || tpm->startup_done)
+ return TPM2_RC_INITIALIZE;
+
+ break;
+ case TPM2_CC_GET_CAPABILITY:
+ if (!tpm->init_done || !tpm->startup_done)
+ return TPM2_RC_INITIALIZE;
+
+ break;
+ case TPM2_CC_SELF_TEST:
+ if (!tpm->startup_done)
+ return TPM2_RC_INITIALIZE;
+
+ break;
+ default:
+ if (!tpm->tests_done)
+ return TPM2_RC_NEEDS_TEST;
+
+ break;
+ }
+
+ return 0;
+}
+
+static int sandbox_tpm2_fill_buf(u8 **recv, size_t *recv_len, u16 tag, u32 rc)
+{
+ *recv_len = sizeof(tag) + sizeof(u32) + sizeof(rc);
+
+ /* Write tag */
+ put_unaligned_be16(tag, *recv);
+ *recv += sizeof(tag);
+
+ /* Write length */
+ put_unaligned_be32(*recv_len, *recv);
+ *recv += sizeof(u32);
+
+ /* Write return code */
+ put_unaligned_be32(rc, *recv);
+ *recv += sizeof(rc);
+
+ /* Add trailing \0 */
+ *recv = '\0';
+
+ return 0;
+}
+
+static int sandbox_tpm2_extend(struct udevice *dev, int pcr_index,
+ const u8 *extension)
+{
+ struct sandbox_tpm2 *tpm = dev_get_priv(dev);
+ int i;
+
+ /* Only simulate the first extensions from all '0' with only '0' */
+ for (i = 0; i < TPM2_DIGEST_LEN; i++)
+ if (tpm->pcr[pcr_index][i] || extension[i])
+ return TPM2_RC_FAILURE;
+
+ memcpy(tpm->pcr[pcr_index], sandbox_extended_once_pcr,
+ TPM2_DIGEST_LEN);
+ tpm->pcr_extensions[pcr_index]++;
+
+ return 0;
+};
+
+static int sandbox_tpm2_xfer(struct udevice *dev, const u8 *sendbuf,
+ size_t send_size, u8 *recvbuf,
+ size_t *recv_len)
+{
+ struct sandbox_tpm2 *tpm = dev_get_priv(dev);
+ enum tpm2_hierarchy hierarchy = 0;
+ const u8 *sent = sendbuf;
+ u8 *recv = recvbuf;
+ u32 length, command, rc = 0;
+ u16 tag, mode, new_pw_sz;
+ u8 yes_no;
+ int i, j;
+
+ /* TPM2_GetProperty */
+ u32 capability, property, property_count;
+
+ /* TPM2_PCR_Read/Extend variables */
+ int pcr_index;
+ u64 pcr_map = 0;
+ u32 selections, pcr_nb;
+ u16 alg;
+ u8 pcr_array_sz;
+
+ tag = get_unaligned_be16(sent);
+ sent += sizeof(tag);
+
+ length = get_unaligned_be32(sent);
+ sent += sizeof(length);
+ if (length != send_size) {
+ printf("TPM2: Unmatching length, received: %ld, expected: %d\n",
+ send_size, length);
+ rc = TPM2_RC_SIZE;
+ sandbox_tpm2_fill_buf(&recv, recv_len, tag, rc);
+ return 0;
+ }
+
+ command = get_unaligned_be32(sent);
+ sent += sizeof(command);
+ rc = sandbox_tpm2_check_readyness(dev, command);
+ if (rc) {
+ sandbox_tpm2_fill_buf(&recv, recv_len, tag, rc);
+ return 0;
+ }
+
+ rc = sandbox_tpm2_check_session(dev, command, tag, &sent, &hierarchy);
+ if (rc) {
+ sandbox_tpm2_fill_buf(&recv, recv_len, tag, rc);
+ return 0;
+ }
+
+ switch (command) {
+ case TPM2_CC_STARTUP:
+ mode = get_unaligned_be16(sent);
+ sent += sizeof(mode);
+ switch (mode) {
+ case TPM2_SU_CLEAR:
+ case TPM2_SU_STATE:
+ break;
+ default:
+ rc = TPM2_RC_VALUE;
+ }
+
+ tpm->startup_done = true;
+
+ sandbox_tpm2_fill_buf(&recv, recv_len, tag, rc);
+ break;
+
+ case TPM2_CC_SELF_TEST:
+ yes_no = *sent;
+ sent += sizeof(yes_no);
+ switch (yes_no) {
+ case TPMI_YES:
+ case TPMI_NO:
+ break;
+ default:
+ rc = TPM2_RC_VALUE;
+ }
+
+ tpm->tests_done = true;
+
+ sandbox_tpm2_fill_buf(&recv, recv_len, tag, rc);
+ break;
+
+ case TPM2_CC_CLEAR:
+ /* Reset this hierarchy password */
+ tpm->pw_sz[hierarchy] = 0;
+
+ /* Reset all password if thisis the PLATFORM hierarchy */
+ if (hierarchy == TPM2_HIERARCHY_PLATFORM)
+ for (i = 0; i < TPM2_HIERARCHY_NB; i++)
+ tpm->pw_sz[i] = 0;
+
+ /* Reset the properties */
+ for (i = 0; i < TPM2_PROPERTY_NB; i++)
+ tpm->properties[i] = 0;
+
+ /* Reset the PCRs and their number of extensions */
+ for (i = 0; i < SANDBOX_TPM_PCR_NB; i++) {
+ tpm->pcr_extensions[i] = 0;
+ for (j = 0; j < TPM2_DIGEST_LEN; j++)
+ tpm->pcr[i][j] = 0;
+ }
+
+ sandbox_tpm2_fill_buf(&recv, recv_len, tag, rc);
+ break;
+
+ case TPM2_CC_HIERCHANGEAUTH:
+ new_pw_sz = get_unaligned_be16(sent);
+ sent += sizeof(new_pw_sz);
+ if (new_pw_sz > TPM2_DIGEST_LEN) {
+ rc = TPM2_RC_SIZE;
+ } else if (new_pw_sz) {
+ tpm->pw_sz[hierarchy] = new_pw_sz;
+ memcpy(tpm->pw[hierarchy], sent, new_pw_sz);
+ sent += new_pw_sz;
+ }
+
+ sandbox_tpm2_fill_buf(&recv, recv_len, tag, rc);
+ break;
+
+ case TPM2_CC_GET_CAPABILITY:
+ capability = get_unaligned_be32(sent);
+ sent += sizeof(capability);
+ if (capability != TPM_CAP_TPM_PROPERTIES) {
+ printf("Sandbox TPM only support TPM_CAPABILITIES\n");
+ return TPM2_RC_HANDLE;
+ }
+
+ property = get_unaligned_be32(sent);
+ sent += sizeof(property);
+ property -= TPM2_PROPERTIES_OFFSET;
+
+ property_count = get_unaligned_be32(sent);
+ sent += sizeof(property_count);
+ if (!property_count ||
+ property + property_count > TPM2_PROPERTY_NB) {
+ rc = TPM2_RC_HANDLE;
+ return sandbox_tpm2_fill_buf(&recv, recv_len, tag, rc);
+ }
+
+ /* Write tag */
+ put_unaligned_be16(tag, recv);
+ recv += sizeof(tag);
+
+ /* Ignore length for now */
+ recv += sizeof(u32);
+
+ /* Write return code */
+ put_unaligned_be32(rc, recv);
+ recv += sizeof(rc);
+
+ /* Tell there is more data to read */
+ *recv = TPMI_YES;
+ recv += sizeof(yes_no);
+
+ /* Repeat the capability */
+ put_unaligned_be32(capability, recv);
+ recv += sizeof(capability);
+
+ /* Give the number of properties that follow */
+ put_unaligned_be32(property_count, recv);
+ recv += sizeof(property_count);
+
+ /* Fill with the properties */
+ for (i = 0; i < property_count; i++) {
+ put_unaligned_be32(TPM2_PROPERTIES_OFFSET + property +
+ i, recv);
+ recv += sizeof(property);
+ put_unaligned_be32(tpm->properties[property + i],
+ recv);
+ recv += sizeof(property);
+ }
+
+ /* Add trailing \0 */
+ *recv = '\0';
+
+ /* Write response length */
+ *recv_len = recv - recvbuf;
+ put_unaligned_be32(*recv_len, recvbuf + sizeof(tag));
+
+ break;
+
+ case TPM2_CC_DAM_PARAMETERS:
+ tpm->properties[TPM2_PROP_MAX_TRIES] = get_unaligned_be32(sent);
+ sent += sizeof(*tpm->properties);
+ tpm->properties[TPM2_RECOVERY_TIME] = get_unaligned_be32(sent);
+ sent += sizeof(*tpm->properties);
+ tpm->properties[TPM2_LOCKOUT_RECOVERY] = get_unaligned_be32(sent);
+ sent += sizeof(*tpm->properties);
+
+ sandbox_tpm2_fill_buf(&recv, recv_len, tag, rc);
+ break;
+
+ case TPM2_CC_PCR_READ:
+ selections = get_unaligned_be32(sent);
+ sent += sizeof(selections);
+ if (selections != 1) {
+ printf("Sandbox cannot handle more than one PCR\n");
+ rc = TPM2_RC_VALUE;
+ return sandbox_tpm2_fill_buf(&recv, recv_len, tag, rc);
+ }
+
+ alg = get_unaligned_be16(sent);
+ sent += sizeof(alg);
+ if (alg != TPM2_ALG_SHA256) {
+ printf("Sandbox TPM only handle SHA256 algorithm\n");
+ rc = TPM2_RC_VALUE;
+ return sandbox_tpm2_fill_buf(&recv, recv_len, tag, rc);
+ }
+
+ pcr_array_sz = *sent;
+ sent += sizeof(pcr_array_sz);
+ if (!pcr_array_sz || pcr_array_sz > 8) {
+ printf("Sandbox TPM cannot handle so much PCRs\n");
+ rc = TPM2_RC_VALUE;
+ return sandbox_tpm2_fill_buf(&recv, recv_len, tag, rc);
+ }
+
+ for (i = 0; i < pcr_array_sz; i++)
+ pcr_map += (u64)sent[i] << (i * 8);
+
+ if (pcr_map >> SANDBOX_TPM_PCR_NB) {
+ printf("Sandbox TPM handles up to %d PCR(s)\n",
+ SANDBOX_TPM_PCR_NB);
+ rc = TPM2_RC_VALUE;
+ return sandbox_tpm2_fill_buf(&recv, recv_len, tag, rc);
+ }
+
+ if (pcr_map >> SANDBOX_TPM_PCR_NB) {
+ printf("Wrong PCR map.\n");
+ rc = TPM2_RC_VALUE;
+ return sandbox_tpm2_fill_buf(&recv, recv_len, tag, rc);
+ }
+
+ for (i = 0; i < SANDBOX_TPM_PCR_NB; i++)
+ if (pcr_map & BIT(i))
+ pcr_index = i;
+
+ /* Write tag */
+ put_unaligned_be16(tag, recv);
+ recv += sizeof(tag);
+
+ /* Ignore length for now */
+ recv += sizeof(u32);
+
+ /* Write return code */
+ put_unaligned_be32(rc, recv);
+ recv += sizeof(rc);
+
+ /* Number of extensions */
+ put_unaligned_be32(tpm->pcr_extensions[pcr_index], recv);
+ recv += sizeof(u32);
+
+ /* Copy the PCR */
+ memcpy(recv, tpm->pcr[pcr_index], TPM2_DIGEST_LEN);
+ recv += TPM2_DIGEST_LEN;
+
+ /* Add trailing \0 */
+ *recv = '\0';
+
+ /* Write response length */
+ *recv_len = recv - recvbuf;
+ put_unaligned_be32(*recv_len, recvbuf + sizeof(tag));
+
+ break;
+
+ case TPM2_CC_PCR_EXTEND:
+ /* Get the PCR index */
+ pcr_index = get_unaligned_be32(sendbuf + sizeof(tag) +
+ sizeof(length) +
+ sizeof(command));
+ if (pcr_index > SANDBOX_TPM_PCR_NB) {
+ printf("Sandbox TPM handles up to %d PCR(s)\n",
+ SANDBOX_TPM_PCR_NB);
+ rc = TPM2_RC_VALUE;
+ }
+
+ /* Check the number of hashes */
+ pcr_nb = get_unaligned_be32(sent);
+ sent += sizeof(pcr_nb);
+ if (pcr_nb != 1) {
+ printf("Sandbox cannot handle more than one PCR\n");
+ rc = TPM2_RC_VALUE;
+ return sandbox_tpm2_fill_buf(&recv, recv_len, tag, rc);
+ }
+
+ /* Check the hash algorithm */
+ alg = get_unaligned_be16(sent);
+ sent += sizeof(alg);
+ if (alg != TPM2_ALG_SHA256) {
+ printf("Sandbox TPM only handle SHA256 algorithm\n");
+ rc = TPM2_RC_VALUE;
+ return sandbox_tpm2_fill_buf(&recv, recv_len, tag, rc);
+ }
+
+ /* Extend the PCR */
+ rc = sandbox_tpm2_extend(dev, pcr_index, sent);
+
+ sandbox_tpm2_fill_buf(&recv, recv_len, tag, rc);
+ break;
+
+ default:
+ printf("TPM2 command %02x unknown in Sandbox\n", command);
+ rc = TPM2_RC_COMMAND_CODE;
+ sandbox_tpm2_fill_buf(&recv, recv_len, tag, rc);
+ }
+
+ return 0;
+}
+
+static int sandbox_tpm2_get_desc(struct udevice *dev, char *buf, int size)
+{
+ if (size < 15)
+ return -ENOSPC;
+
+ return snprintf(buf, size, "Sandbox TPM2.x");
+}
+
+static int sandbox_tpm2_open(struct udevice *dev)
+{
+ struct sandbox_tpm2 *tpm = dev_get_priv(dev);
+
+ if (tpm->init_done)
+ return -EIO;
+
+ tpm->init_done = true;
+
+ return 0;
+}
+
+static int sandbox_tpm2_probe(struct udevice *dev)
+{
+ struct sandbox_tpm2 *tpm = dev_get_priv(dev);
+ struct tpm_chip_priv *priv = dev_get_uclass_priv(dev);
+
+ memset(tpm, 0, sizeof(*tpm));
+
+ priv->pcr_count = 32;
+ priv->pcr_select_min = 2;
+
+ return 0;
+}
+
+static int sandbox_tpm2_close(struct udevice *dev)
+{
+ return 0;
+}
+
+static const struct tpm_ops sandbox_tpm2_ops = {
+ .open = sandbox_tpm2_open,
+ .close = sandbox_tpm2_close,
+ .get_desc = sandbox_tpm2_get_desc,
+ .xfer = sandbox_tpm2_xfer,
+};
+
+static const struct udevice_id sandbox_tpm2_ids[] = {
+ { .compatible = "sandbox,tpm2" },
+ { }
+};
+
+U_BOOT_DRIVER(sandbox_tpm2) = {
+ .name = "sandbox_tpm2",
+ .id = UCLASS_TPM,
+ .of_match = sandbox_tpm2_ids,
+ .ops = &sandbox_tpm2_ops,
+ .probe = sandbox_tpm2_probe,
+ .priv_auto_alloc_size = sizeof(struct sandbox_tpm2),
+};
diff --git a/drivers/tpm/tpm2_tis_spi.c b/drivers/tpm/tpm2_tis_spi.c
new file mode 100644
index 0000000000..c5d17a679d
--- /dev/null
+++ b/drivers/tpm/tpm2_tis_spi.c
@@ -0,0 +1,679 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Author:
+ * Miquel Raynal <miquel.raynal@bootlin.com>
+ *
+ * Description:
+ * SPI-level driver for TCG/TIS TPM (trusted platform module).
+ * Specifications at www.trustedcomputinggroup.org
+ *
+ * This device driver implements the TPM interface as defined in
+ * the TCG SPI protocol stack version 2.0.
+ *
+ * It is based on the U-Boot driver tpm_tis_infineon_i2c.c.
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <fdtdec.h>
+#include <log.h>
+#include <spi.h>
+#include <tpm-v2.h>
+#include <linux/errno.h>
+#include <linux/compiler.h>
+#include <linux/types.h>
+#include <linux/unaligned/be_byteshift.h>
+#include <asm-generic/gpio.h>
+
+#include "tpm_tis.h"
+#include "tpm_internal.h"
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#define TPM_ACCESS(l) (0x0000 | ((l) << 12))
+#define TPM_INT_ENABLE(l) (0x0008 | ((l) << 12))
+#define TPM_STS(l) (0x0018 | ((l) << 12))
+#define TPM_DATA_FIFO(l) (0x0024 | ((l) << 12))
+#define TPM_DID_VID(l) (0x0F00 | ((l) << 12))
+#define TPM_RID(l) (0x0F04 | ((l) << 12))
+
+#define MAX_SPI_FRAMESIZE 64
+
+/* Number of wait states to wait for */
+#define TPM_WAIT_STATES 100
+
+/**
+ * struct tpm_tis_chip_data - Non-discoverable TPM information
+ *
+ * @pcr_count: Number of PCR per bank
+ * @pcr_select_min: Size in octets of the pcrSelect array
+ */
+struct tpm_tis_chip_data {
+ unsigned int pcr_count;
+ unsigned int pcr_select_min;
+ unsigned int time_before_first_cmd_ms;
+};
+
+/**
+ * tpm_tis_spi_read() - Read from TPM register
+ *
+ * @addr: register address to read from
+ * @buffer: provided by caller
+ * @len: number of bytes to read
+ *
+ * Read len bytes from TPM register and put them into
+ * buffer (little-endian format, i.e. first byte is put into buffer[0]).
+ *
+ * NOTE: TPM is big-endian for multi-byte values. Multi-byte
+ * values have to be swapped.
+ *
+ * @return -EIO on error, 0 on success.
+ */
+static int tpm_tis_spi_xfer(struct udevice *dev, u32 addr, const u8 *out,
+ u8 *in, u16 len)
+{
+ struct spi_slave *slave = dev_get_parent_priv(dev);
+ int transfer_len, ret;
+ u8 tx_buf[MAX_SPI_FRAMESIZE];
+ u8 rx_buf[MAX_SPI_FRAMESIZE];
+
+ if (in && out) {
+ log(LOGC_NONE, LOGL_ERR, "%s: can't do full duplex\n",
+ __func__);
+ return -EINVAL;
+ }
+
+ ret = spi_claim_bus(slave);
+ if (ret < 0) {
+ log(LOGC_NONE, LOGL_ERR, "%s: could not claim bus\n", __func__);
+ return ret;
+ }
+
+ while (len) {
+ /* Request */
+ transfer_len = min_t(u16, len, MAX_SPI_FRAMESIZE);
+ tx_buf[0] = (in ? BIT(7) : 0) | (transfer_len - 1);
+ tx_buf[1] = 0xD4;
+ tx_buf[2] = addr >> 8;
+ tx_buf[3] = addr;
+
+ ret = spi_xfer(slave, 4 * 8, tx_buf, rx_buf, SPI_XFER_BEGIN);
+ if (ret < 0) {
+ log(LOGC_NONE, LOGL_ERR,
+ "%s: spi request transfer failed (err: %d)\n",
+ __func__, ret);
+ goto release_bus;
+ }
+
+ /* Wait state */
+ if (!(rx_buf[3] & 0x1)) {
+ int i;
+
+ for (i = 0; i < TPM_WAIT_STATES; i++) {
+ ret = spi_xfer(slave, 1 * 8, NULL, rx_buf, 0);
+ if (ret) {
+ log(LOGC_NONE, LOGL_ERR,
+ "%s: wait state failed: %d\n",
+ __func__, ret);
+ goto release_bus;
+ }
+
+ if (rx_buf[0] & 0x1)
+ break;
+ }
+
+ if (i == TPM_WAIT_STATES) {
+ log(LOGC_NONE, LOGL_ERR,
+ "%s: timeout on wait state\n", __func__);
+ ret = -ETIMEDOUT;
+ goto release_bus;
+ }
+ }
+
+ /* Read/Write */
+ if (out) {
+ memcpy(tx_buf, out, transfer_len);
+ out += transfer_len;
+ }
+
+ ret = spi_xfer(slave, transfer_len * 8,
+ out ? tx_buf : NULL,
+ in ? rx_buf : NULL,
+ SPI_XFER_END);
+ if (ret) {
+ log(LOGC_NONE, LOGL_ERR,
+ "%s: spi read transfer failed (err: %d)\n",
+ __func__, ret);
+ goto release_bus;
+ }
+
+ if (in) {
+ memcpy(in, rx_buf, transfer_len);
+ in += transfer_len;
+ }
+
+ len -= transfer_len;
+ }
+
+release_bus:
+ /* If an error occurred, release the chip by deasserting the CS */
+ if (ret < 0)
+ spi_xfer(slave, 0, NULL, NULL, SPI_XFER_END);
+
+ spi_release_bus(slave);
+
+ return ret;
+}
+
+static int tpm_tis_spi_read(struct udevice *dev, u16 addr, u8 *in, u16 len)
+{
+ return tpm_tis_spi_xfer(dev, addr, NULL, in, len);
+}
+
+static int tpm_tis_spi_read32(struct udevice *dev, u32 addr, u32 *result)
+{
+ __le32 result_le;
+ int ret;
+
+ ret = tpm_tis_spi_read(dev, addr, (u8 *)&result_le, sizeof(u32));
+ if (!ret)
+ *result = le32_to_cpu(result_le);
+
+ return ret;
+}
+
+static int tpm_tis_spi_write(struct udevice *dev, u16 addr, const u8 *out,
+ u16 len)
+{
+ return tpm_tis_spi_xfer(dev, addr, out, NULL, len);
+}
+
+static int tpm_tis_spi_check_locality(struct udevice *dev, int loc)
+{
+ const u8 mask = TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID;
+ struct tpm_chip *chip = dev_get_priv(dev);
+ u8 buf;
+ int ret;
+
+ ret = tpm_tis_spi_read(dev, TPM_ACCESS(loc), &buf, 1);
+ if (ret)
+ return ret;
+
+ if ((buf & mask) == mask) {
+ chip->locality = loc;
+ return 0;
+ }
+
+ return -ENOENT;
+}
+
+static void tpm_tis_spi_release_locality(struct udevice *dev, int loc,
+ bool force)
+{
+ const u8 mask = TPM_ACCESS_REQUEST_PENDING | TPM_ACCESS_VALID;
+ u8 buf;
+
+ if (tpm_tis_spi_read(dev, TPM_ACCESS(loc), &buf, 1) < 0)
+ return;
+
+ if (force || (buf & mask) == mask) {
+ buf = TPM_ACCESS_ACTIVE_LOCALITY;
+ tpm_tis_spi_write(dev, TPM_ACCESS(loc), &buf, 1);
+ }
+}
+
+static int tpm_tis_spi_request_locality(struct udevice *dev, int loc)
+{
+ struct tpm_chip *chip = dev_get_priv(dev);
+ unsigned long start, stop;
+ u8 buf = TPM_ACCESS_REQUEST_USE;
+ int ret;
+
+ ret = tpm_tis_spi_check_locality(dev, loc);
+ if (!ret)
+ return 0;
+
+ if (ret != -ENOENT) {
+ log(LOGC_NONE, LOGL_ERR, "%s: Failed to get locality: %d\n",
+ __func__, ret);
+ return ret;
+ }
+
+ ret = tpm_tis_spi_write(dev, TPM_ACCESS(loc), &buf, 1);
+ if (ret) {
+ log(LOGC_NONE, LOGL_ERR, "%s: Failed to write to TPM: %d\n",
+ __func__, ret);
+ return ret;
+ }
+
+ start = get_timer(0);
+ stop = chip->timeout_a;
+ do {
+ ret = tpm_tis_spi_check_locality(dev, loc);
+ if (!ret)
+ return 0;
+
+ if (ret != -ENOENT) {
+ log(LOGC_NONE, LOGL_ERR,
+ "%s: Failed to get locality: %d\n", __func__, ret);
+ return ret;
+ }
+
+ mdelay(TPM_TIMEOUT_MS);
+ } while (get_timer(start) < stop);
+
+ log(LOGC_NONE, LOGL_ERR, "%s: Timeout getting locality: %d\n", __func__,
+ ret);
+
+ return ret;
+}
+
+static u8 tpm_tis_spi_status(struct udevice *dev, u8 *status)
+{
+ struct tpm_chip *chip = dev_get_priv(dev);
+
+ return tpm_tis_spi_read(dev, TPM_STS(chip->locality), status, 1);
+}
+
+static int tpm_tis_spi_wait_for_stat(struct udevice *dev, u8 mask,
+ unsigned long timeout, u8 *status)
+{
+ unsigned long start = get_timer(0);
+ unsigned long stop = timeout;
+ int ret;
+
+ do {
+ mdelay(TPM_TIMEOUT_MS);
+ ret = tpm_tis_spi_status(dev, status);
+ if (ret)
+ return ret;
+
+ if ((*status & mask) == mask)
+ return 0;
+ } while (get_timer(start) < stop);
+
+ return -ETIMEDOUT;
+}
+
+static int tpm_tis_spi_get_burstcount(struct udevice *dev)
+{
+ struct tpm_chip *chip = dev_get_priv(dev);
+ unsigned long start, stop;
+ u32 burstcount, ret;
+
+ /* wait for burstcount */
+ start = get_timer(0);
+ stop = chip->timeout_d;
+ do {
+ ret = tpm_tis_spi_read32(dev, TPM_STS(chip->locality),
+ &burstcount);
+ if (ret)
+ return -EBUSY;
+
+ burstcount = (burstcount >> 8) & 0xFFFF;
+ if (burstcount)
+ return burstcount;
+
+ mdelay(TPM_TIMEOUT_MS);
+ } while (get_timer(start) < stop);
+
+ return -EBUSY;
+}
+
+static int tpm_tis_spi_cancel(struct udevice *dev)
+{
+ struct tpm_chip *chip = dev_get_priv(dev);
+ u8 data = TPM_STS_COMMAND_READY;
+
+ return tpm_tis_spi_write(dev, TPM_STS(chip->locality), &data, 1);
+}
+
+static int tpm_tis_spi_recv_data(struct udevice *dev, u8 *buf, size_t count)
+{
+ struct tpm_chip *chip = dev_get_priv(dev);
+ int size = 0, burstcnt, len, ret;
+ u8 status;
+
+ while (size < count &&
+ tpm_tis_spi_wait_for_stat(dev,
+ TPM_STS_DATA_AVAIL | TPM_STS_VALID,
+ chip->timeout_c, &status) == 0) {
+ burstcnt = tpm_tis_spi_get_burstcount(dev);
+ if (burstcnt < 0)
+ return burstcnt;
+
+ len = min_t(int, burstcnt, count - size);
+ ret = tpm_tis_spi_read(dev, TPM_DATA_FIFO(chip->locality),
+ buf + size, len);
+ if (ret < 0)
+ return ret;
+
+ size += len;
+ }
+
+ return size;
+}
+
+static int tpm_tis_spi_recv(struct udevice *dev, u8 *buf, size_t count)
+{
+ struct tpm_chip *chip = dev_get_priv(dev);
+ int size, expected;
+
+ if (!chip)
+ return -ENODEV;
+
+ if (count < TPM_HEADER_SIZE) {
+ size = -EIO;
+ goto out;
+ }
+
+ size = tpm_tis_spi_recv_data(dev, buf, TPM_HEADER_SIZE);
+ if (size < TPM_HEADER_SIZE) {
+ log(LOGC_NONE, LOGL_ERR, "TPM error, unable to read header\n");
+ goto out;
+ }
+
+ expected = get_unaligned_be32(buf + 2);
+ if (expected > count) {
+ size = -EIO;
+ goto out;
+ }
+
+ size += tpm_tis_spi_recv_data(dev, &buf[TPM_HEADER_SIZE],
+ expected - TPM_HEADER_SIZE);
+ if (size < expected) {
+ log(LOGC_NONE, LOGL_ERR,
+ "TPM error, unable to read remaining bytes of result\n");
+ size = -EIO;
+ goto out;
+ }
+
+out:
+ tpm_tis_spi_cancel(dev);
+ tpm_tis_spi_release_locality(dev, chip->locality, false);
+
+ return size;
+}
+
+static int tpm_tis_spi_send(struct udevice *dev, const u8 *buf, size_t len)
+{
+ struct tpm_chip *chip = dev_get_priv(dev);
+ u32 i, size;
+ u8 status;
+ int burstcnt, ret;
+ u8 data;
+
+ if (!chip)
+ return -ENODEV;
+
+ if (len > TPM_DEV_BUFSIZE)
+ return -E2BIG; /* Command is too long for our tpm, sorry */
+
+ ret = tpm_tis_spi_request_locality(dev, 0);
+ if (ret < 0)
+ return -EBUSY;
+
+ /*
+ * Check if the TPM is ready. If not, if not, cancel the pending command
+ * and poll on the status to be finally ready.
+ */
+ ret = tpm_tis_spi_status(dev, &status);
+ if (ret)
+ return ret;
+
+ if (!(status & TPM_STS_COMMAND_READY)) {
+ /* Force the transition, usually this will be done at startup */
+ ret = tpm_tis_spi_cancel(dev);
+ if (ret) {
+ log(LOGC_NONE, LOGL_ERR,
+ "%s: Could not cancel previous operation\n",
+ __func__);
+ goto out_err;
+ }
+
+ ret = tpm_tis_spi_wait_for_stat(dev, TPM_STS_COMMAND_READY,
+ chip->timeout_b, &status);
+ if (ret < 0 || !(status & TPM_STS_COMMAND_READY)) {
+ log(LOGC_NONE, LOGL_ERR,
+ "status %d after wait for stat returned %d\n",
+ status, ret);
+ goto out_err;
+ }
+ }
+
+ for (i = 0; i < len - 1;) {
+ burstcnt = tpm_tis_spi_get_burstcount(dev);
+ if (burstcnt < 0)
+ return burstcnt;
+
+ size = min_t(int, len - i - 1, burstcnt);
+ ret = tpm_tis_spi_write(dev, TPM_DATA_FIFO(chip->locality),
+ buf + i, size);
+ if (ret < 0)
+ goto out_err;
+
+ i += size;
+ }
+
+ ret = tpm_tis_spi_status(dev, &status);
+ if (ret)
+ goto out_err;
+
+ if ((status & TPM_STS_DATA_EXPECT) == 0) {
+ ret = -EIO;
+ goto out_err;
+ }
+
+ ret = tpm_tis_spi_write(dev, TPM_DATA_FIFO(chip->locality),
+ buf + len - 1, 1);
+ if (ret)
+ goto out_err;
+
+ ret = tpm_tis_spi_status(dev, &status);
+ if (ret)
+ goto out_err;
+
+ if ((status & TPM_STS_DATA_EXPECT) != 0) {
+ ret = -EIO;
+ goto out_err;
+ }
+
+ data = TPM_STS_GO;
+ ret = tpm_tis_spi_write(dev, TPM_STS(chip->locality), &data, 1);
+ if (ret)
+ goto out_err;
+
+ return len;
+
+out_err:
+ tpm_tis_spi_cancel(dev);
+ tpm_tis_spi_release_locality(dev, chip->locality, false);
+
+ return ret;
+}
+
+static int tpm_tis_spi_cleanup(struct udevice *dev)
+{
+ struct tpm_chip *chip = dev_get_priv(dev);
+
+ tpm_tis_spi_cancel(dev);
+ /*
+ * The TPM needs some time to clean up here,
+ * so we sleep rather than keeping the bus busy
+ */
+ mdelay(2);
+ tpm_tis_spi_release_locality(dev, chip->locality, false);
+
+ return 0;
+}
+
+static int tpm_tis_spi_open(struct udevice *dev)
+{
+ struct tpm_chip *chip = dev_get_priv(dev);
+
+ if (chip->is_open)
+ return -EBUSY;
+
+ chip->is_open = 1;
+
+ return 0;
+}
+
+static int tpm_tis_spi_close(struct udevice *dev)
+{
+ struct tpm_chip *chip = dev_get_priv(dev);
+
+ if (chip->is_open) {
+ tpm_tis_spi_release_locality(dev, chip->locality, true);
+ chip->is_open = 0;
+ }
+
+ return 0;
+}
+
+static int tpm_tis_get_desc(struct udevice *dev, char *buf, int size)
+{
+ struct tpm_chip *chip = dev_get_priv(dev);
+
+ if (size < 80)
+ return -ENOSPC;
+
+ return snprintf(buf, size,
+ "%s v2.0: VendorID 0x%04x, DeviceID 0x%04x, RevisionID 0x%02x [%s]",
+ dev->name, chip->vend_dev & 0xFFFF,
+ chip->vend_dev >> 16, chip->rid,
+ (chip->is_open ? "open" : "closed"));
+}
+
+static int tpm_tis_wait_init(struct udevice *dev, int loc)
+{
+ struct tpm_chip *chip = dev_get_priv(dev);
+ unsigned long start, stop;
+ u8 status;
+ int ret;
+
+ start = get_timer(0);
+ stop = chip->timeout_b;
+ do {
+ mdelay(TPM_TIMEOUT_MS);
+
+ ret = tpm_tis_spi_read(dev, TPM_ACCESS(loc), &status, 1);
+ if (ret)
+ break;
+
+ if (status & TPM_ACCESS_VALID)
+ return 0;
+ } while (get_timer(start) < stop);
+
+ return -EIO;
+}
+
+static int tpm_tis_spi_probe(struct udevice *dev)
+{
+ struct tpm_tis_chip_data *drv_data = (void *)dev_get_driver_data(dev);
+ struct tpm_chip_priv *priv = dev_get_uclass_priv(dev);
+ struct tpm_chip *chip = dev_get_priv(dev);
+ int ret;
+
+ if (IS_ENABLED(CONFIG_DM_GPIO)) {
+ struct gpio_desc reset_gpio;
+
+ ret = gpio_request_by_name(dev, "gpio-reset", 0,
+ &reset_gpio, GPIOD_IS_OUT);
+ if (ret) {
+ log(LOGC_NONE, LOGL_NOTICE, "%s: missing reset GPIO\n",
+ __func__);
+ } else {
+ dm_gpio_set_value(&reset_gpio, 0);
+ mdelay(1);
+ dm_gpio_set_value(&reset_gpio, 1);
+ }
+ }
+
+ /* Ensure a minimum amount of time elapsed since reset of the TPM */
+ mdelay(drv_data->time_before_first_cmd_ms);
+
+ chip->locality = 0;
+ chip->timeout_a = TIS_SHORT_TIMEOUT_MS;
+ chip->timeout_b = TIS_LONG_TIMEOUT_MS;
+ chip->timeout_c = TIS_SHORT_TIMEOUT_MS;
+ chip->timeout_d = TIS_SHORT_TIMEOUT_MS;
+ priv->pcr_count = drv_data->pcr_count;
+ priv->pcr_select_min = drv_data->pcr_select_min;
+
+ ret = tpm_tis_wait_init(dev, chip->locality);
+ if (ret) {
+ log(LOGC_DM, LOGL_ERR, "%s: no device found\n", __func__);
+ return ret;
+ }
+
+ ret = tpm_tis_spi_request_locality(dev, chip->locality);
+ if (ret) {
+ log(LOGC_NONE, LOGL_ERR, "%s: could not request locality %d\n",
+ __func__, chip->locality);
+ return ret;
+ }
+
+ ret = tpm_tis_spi_read32(dev, TPM_DID_VID(chip->locality),
+ &chip->vend_dev);
+ if (ret) {
+ log(LOGC_NONE, LOGL_ERR,
+ "%s: could not retrieve VendorID/DeviceID\n", __func__);
+ return ret;
+ }
+
+ ret = tpm_tis_spi_read(dev, TPM_RID(chip->locality), &chip->rid, 1);
+ if (ret) {
+ log(LOGC_NONE, LOGL_ERR, "%s: could not retrieve RevisionID\n",
+ __func__);
+ return ret;
+ }
+
+ log(LOGC_NONE, LOGL_ERR,
+ "SPI TPMv2.0 found (vid:%04x, did:%04x, rid:%02x)\n",
+ chip->vend_dev & 0xFFFF, chip->vend_dev >> 16, chip->rid);
+
+ return 0;
+}
+
+static int tpm_tis_spi_remove(struct udevice *dev)
+{
+ struct tpm_chip *chip = dev_get_priv(dev);
+
+ tpm_tis_spi_release_locality(dev, chip->locality, true);
+
+ return 0;
+}
+
+static const struct tpm_ops tpm_tis_spi_ops = {
+ .open = tpm_tis_spi_open,
+ .close = tpm_tis_spi_close,
+ .get_desc = tpm_tis_get_desc,
+ .send = tpm_tis_spi_send,
+ .recv = tpm_tis_spi_recv,
+ .cleanup = tpm_tis_spi_cleanup,
+};
+
+static const struct tpm_tis_chip_data tpm_tis_std_chip_data = {
+ .pcr_count = 24,
+ .pcr_select_min = 3,
+ .time_before_first_cmd_ms = 30,
+};
+
+static const struct udevice_id tpm_tis_spi_ids[] = {
+ {
+ .compatible = "tis,tpm2-spi",
+ .data = (ulong)&tpm_tis_std_chip_data,
+ },
+ { }
+};
+
+U_BOOT_DRIVER(tpm_tis_spi) = {
+ .name = "tpm_tis_spi",
+ .id = UCLASS_TPM,
+ .of_match = tpm_tis_spi_ids,
+ .ops = &tpm_tis_spi_ops,
+ .probe = tpm_tis_spi_probe,
+ .remove = tpm_tis_spi_remove,
+ .priv_auto_alloc_size = sizeof(struct tpm_chip),
+};
diff --git a/drivers/tpm/tpm_atmel_twi.c b/drivers/tpm/tpm_atmel_twi.c
index 8547580c24..2079ea913e 100644
--- a/drivers/tpm/tpm_atmel_twi.c
+++ b/drivers/tpm/tpm_atmel_twi.c
@@ -7,7 +7,7 @@
#include <common.h>
#include <dm.h>
-#include <tpm.h>
+#include <tpm-v1.h>
#include <i2c.h>
#include <asm/unaligned.h>
diff --git a/drivers/tpm/tpm_tis.h b/drivers/tpm/tpm_tis.h
index a899bc0b46..947585f8e3 100644
--- a/drivers/tpm/tpm_tis.h
+++ b/drivers/tpm/tpm_tis.h
@@ -40,6 +40,7 @@ struct tpm_chip {
int is_open;
int locality;
u32 vend_dev;
+ u8 rid;
unsigned long timeout_a, timeout_b, timeout_c, timeout_d; /* msec */
ulong chip_type;
};
diff --git a/drivers/tpm/tpm_tis_infineon.c b/drivers/tpm/tpm_tis_infineon.c
index 9b2a0250e1..b5fe43ee50 100644
--- a/drivers/tpm/tpm_tis_infineon.c
+++ b/drivers/tpm/tpm_tis_infineon.c
@@ -23,7 +23,7 @@
#include <dm.h>
#include <fdtdec.h>
#include <i2c.h>
-#include <tpm.h>
+#include <tpm-v1.h>
#include <linux/errno.h>
#include <linux/compiler.h>
#include <linux/types.h>
diff --git a/drivers/tpm/tpm_tis_lpc.c b/drivers/tpm/tpm_tis_lpc.c
index 572926382e..7664bb1a60 100644
--- a/drivers/tpm/tpm_tis_lpc.c
+++ b/drivers/tpm/tpm_tis_lpc.c
@@ -15,7 +15,7 @@
#include <common.h>
#include <dm.h>
#include <mapmem.h>
-#include <tpm.h>
+#include <tpm-v1.h>
#include <asm/io.h>
#define PREFIX "lpc_tpm: "
diff --git a/drivers/tpm/tpm_tis_sandbox.c b/drivers/tpm/tpm_tis_sandbox.c
index 44157542a1..8816d55759 100644
--- a/drivers/tpm/tpm_tis_sandbox.c
+++ b/drivers/tpm/tpm_tis_sandbox.c
@@ -5,7 +5,7 @@
#include <common.h>
#include <dm.h>
-#include <tpm.h>
+#include <tpm-v1.h>
#include <asm/state.h>
#include <asm/unaligned.h>
#include <linux/crc8.h>
diff --git a/drivers/tpm/tpm_tis_st33zp24_i2c.c b/drivers/tpm/tpm_tis_st33zp24_i2c.c
index 9cf302caff..0d380375eb 100644
--- a/drivers/tpm/tpm_tis_st33zp24_i2c.c
+++ b/drivers/tpm/tpm_tis_st33zp24_i2c.c
@@ -16,7 +16,7 @@
#include <dm.h>
#include <fdtdec.h>
#include <i2c.h>
-#include <tpm.h>
+#include <tpm-v1.h>
#include <errno.h>
#include <linux/types.h>
#include <asm/unaligned.h>
diff --git a/drivers/tpm/tpm_tis_st33zp24_spi.c b/drivers/tpm/tpm_tis_st33zp24_spi.c
index d5fde11a83..f6087e7633 100644
--- a/drivers/tpm/tpm_tis_st33zp24_spi.c
+++ b/drivers/tpm/tpm_tis_st33zp24_spi.c
@@ -16,7 +16,7 @@
#include <dm.h>
#include <fdtdec.h>
#include <spi.h>
-#include <tpm.h>
+#include <tpm-v1.h>
#include <errno.h>
#include <linux/types.h>
#include <asm/unaligned.h>