drivers/i2c/tpm/cr50: Rename i2c read/write functions

Rename the low-level functions from iic_tpm_read/write to
cr50_i2c_read/write to better match the driver name, and pass in the
tpm_chip structure to the low-level read/write functions as it will
be needed in future changes.

BUG=chrome-os-partner:53336

Change-Id: I826a7f024f8d137453af86ba920e0a3a734f7349
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://review.coreboot.org/16666
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
This commit is contained in:
Duncan Laurie 2016-09-19 17:05:45 -07:00 committed by Patrick Georgi
parent 1dc036ce48
commit 510cb6a144
1 changed files with 31 additions and 23 deletions

View File

@ -56,8 +56,9 @@ struct tpm_inf_dev {
static struct tpm_inf_dev g_tpm_dev CAR_GLOBAL; static struct tpm_inf_dev g_tpm_dev CAR_GLOBAL;
/* /*
* iic_tpm_read() - read from TPM register * cr50_i2c_read() - read from TPM register
* *
* @chip: TPM chip information
* @addr: register address to read from * @addr: register address to read from
* @buffer: provided by caller * @buffer: provided by caller
* @len: number of bytes to read * @len: number of bytes to read
@ -68,7 +69,8 @@ static struct tpm_inf_dev g_tpm_dev CAR_GLOBAL;
* *
* Return -1 on error, 0 on success. * Return -1 on error, 0 on success.
*/ */
static int iic_tpm_read(uint8_t addr, uint8_t *buffer, size_t len) static int cr50_i2c_read(struct tpm_chip *chip, uint8_t addr,
uint8_t *buffer, size_t len)
{ {
struct tpm_inf_dev *tpm_dev = car_get_var_ptr(&g_tpm_dev); struct tpm_inf_dev *tpm_dev = car_get_var_ptr(&g_tpm_dev);
@ -94,8 +96,9 @@ static int iic_tpm_read(uint8_t addr, uint8_t *buffer, size_t len)
} }
/* /*
* iic_tpm_write() - write to TPM register * cr50_i2c_write() - write to TPM register
* *
* @chip: TPM chip information
* @addr: register address to write to * @addr: register address to write to
* @buffer: data to write * @buffer: data to write
* @len: number of bytes to write * @len: number of bytes to write
@ -106,7 +109,8 @@ static int iic_tpm_read(uint8_t addr, uint8_t *buffer, size_t len)
* *
* Returns -1 on error, 0 on success. * Returns -1 on error, 0 on success.
*/ */
static int iic_tpm_write(uint8_t addr, uint8_t *buffer, size_t len) static int cr50_i2c_write(struct tpm_chip *chip,
uint8_t addr, uint8_t *buffer, size_t len)
{ {
struct tpm_inf_dev *tpm_dev = car_get_var_ptr(&g_tpm_dev); struct tpm_inf_dev *tpm_dev = car_get_var_ptr(&g_tpm_dev);
@ -135,7 +139,7 @@ static int check_locality(struct tpm_chip *chip, int loc)
{ {
uint8_t buf; uint8_t buf;
if (iic_tpm_read(TPM_ACCESS(loc), &buf, 1) < 0) if (cr50_i2c_read(chip, TPM_ACCESS(loc), &buf, 1) < 0)
return -1; return -1;
if ((buf & (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) == if ((buf & (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) ==
@ -150,13 +154,14 @@ static int check_locality(struct tpm_chip *chip, int loc)
static void release_locality(struct tpm_chip *chip, int loc, int force) static void release_locality(struct tpm_chip *chip, int loc, int force)
{ {
uint8_t buf; uint8_t buf;
if (iic_tpm_read(TPM_ACCESS(loc), &buf, 1) < 0)
if (cr50_i2c_read(chip, TPM_ACCESS(loc), &buf, 1) < 0)
return; return;
if (force || (buf & (TPM_ACCESS_REQUEST_PENDING | TPM_ACCESS_VALID)) == if (force || (buf & (TPM_ACCESS_REQUEST_PENDING | TPM_ACCESS_VALID)) ==
(TPM_ACCESS_REQUEST_PENDING | TPM_ACCESS_VALID)) { (TPM_ACCESS_REQUEST_PENDING | TPM_ACCESS_VALID)) {
buf = TPM_ACCESS_ACTIVE_LOCALITY; buf = TPM_ACCESS_ACTIVE_LOCALITY;
iic_tpm_write(TPM_ACCESS(loc), &buf, 1); cr50_i2c_write(chip, TPM_ACCESS(loc), &buf, 1);
} }
} }
@ -167,7 +172,8 @@ static int request_locality(struct tpm_chip *chip, int loc)
if (check_locality(chip, loc) >= 0) if (check_locality(chip, loc) >= 0)
return loc; /* we already have the locality */ return loc; /* we already have the locality */
iic_tpm_write(TPM_ACCESS(loc), &buf, 1); if (cr50_i2c_write(chip, TPM_ACCESS(loc), &buf, 1) < 0)
return -1;
/* wait for burstcount */ /* wait for burstcount */
int timeout = 2 * 1000; /* 2s timeout */ int timeout = 2 * 1000; /* 2s timeout */
@ -185,7 +191,7 @@ static int request_locality(struct tpm_chip *chip, int loc)
static uint8_t cr50_tis_i2c_status(struct tpm_chip *chip) static uint8_t cr50_tis_i2c_status(struct tpm_chip *chip)
{ {
uint8_t buf[4]; uint8_t buf[4];
if (iic_tpm_read(TPM_STS(chip->vendor.locality), if (cr50_i2c_read(chip, TPM_STS(chip->vendor.locality),
buf, sizeof(buf)) < 0) { buf, sizeof(buf)) < 0) {
printk(BIOS_ERR, "%s: Failed to read status\n", __func__); printk(BIOS_ERR, "%s: Failed to read status\n", __func__);
return 0; return 0;
@ -197,7 +203,7 @@ static uint8_t cr50_tis_i2c_status(struct tpm_chip *chip)
static void cr50_tis_i2c_ready(struct tpm_chip *chip) static void cr50_tis_i2c_ready(struct tpm_chip *chip)
{ {
uint8_t buf[4] = { TPM_STS_COMMAND_READY }; uint8_t buf[4] = { TPM_STS_COMMAND_READY };
iic_tpm_write(TPM_STS(chip->vendor.locality), buf, sizeof(buf)); cr50_i2c_write(chip, TPM_STS(chip->vendor.locality), buf, sizeof(buf));
mdelay(CR50_TIMEOUT_SHORT_MS); mdelay(CR50_TIMEOUT_SHORT_MS);
} }
@ -212,9 +218,8 @@ static int cr50_wait_burst_status(struct tpm_chip *chip, uint8_t mask,
stopwatch_init_msecs_expire(&sw, CR50_TIMEOUT_LONG_MS); stopwatch_init_msecs_expire(&sw, CR50_TIMEOUT_LONG_MS);
while (!stopwatch_expired(&sw)) { while (!stopwatch_expired(&sw)) {
if (iic_tpm_read(TPM_STS(chip->vendor.locality), if (cr50_i2c_read(chip, TPM_STS(chip->vendor.locality),
buf, sizeof(buf)) != 0) { buf, sizeof(buf)) != 0) {
printk(BIOS_WARNING, "%s: Read failed\n", __func__);
mdelay(CR50_TIMEOUT_SHORT_MS); mdelay(CR50_TIMEOUT_SHORT_MS);
continue; continue;
} }
@ -253,7 +258,7 @@ static int cr50_tis_i2c_recv(struct tpm_chip *chip, uint8_t *buf,
} }
/* Read first chunk of burstcnt bytes */ /* Read first chunk of burstcnt bytes */
if (iic_tpm_read(addr, buf, burstcnt) != 0) { if (cr50_i2c_read(chip, addr, buf, burstcnt) != 0) {
printk(BIOS_ERR, "%s: Read failed\n", __func__); printk(BIOS_ERR, "%s: Read failed\n", __func__);
goto out; goto out;
} }
@ -279,7 +284,7 @@ static int cr50_tis_i2c_recv(struct tpm_chip *chip, uint8_t *buf,
} }
len = min(burstcnt, expected - current); len = min(burstcnt, expected - current);
if (iic_tpm_read(addr, buf + current, len) != 0) { if (cr50_i2c_read(chip, addr, buf + current, len) != 0) {
printk(BIOS_ERR, "%s: Read failed\n", __func__); printk(BIOS_ERR, "%s: Read failed\n", __func__);
goto out; goto out;
} }
@ -332,9 +337,9 @@ static int cr50_tis_i2c_send(struct tpm_chip *chip, uint8_t *buf, size_t len)
} }
/* Use burstcnt - 1 to account for the address byte /* Use burstcnt - 1 to account for the address byte
* that is inserted by iic_tpm_write() */ * that is inserted by cr50_i2c_write() */
limit = min(burstcnt - 1, len); limit = min(burstcnt - 1, len);
if (iic_tpm_write(TPM_DATA_FIFO(chip->vendor.locality), if (cr50_i2c_write(chip, TPM_DATA_FIFO(chip->vendor.locality),
&buf[sent], limit) != 0) { &buf[sent], limit) != 0) {
printk(BIOS_ERR, "%s: Write failed\n", __func__); printk(BIOS_ERR, "%s: Write failed\n", __func__);
goto out; goto out;
@ -353,7 +358,7 @@ static int cr50_tis_i2c_send(struct tpm_chip *chip, uint8_t *buf, size_t len)
} }
/* Start the TPM command */ /* Start the TPM command */
if (iic_tpm_write(TPM_STS(chip->vendor.locality), tpm_go, if (cr50_i2c_write(chip, TPM_STS(chip->vendor.locality), tpm_go,
sizeof(tpm_go)) < 0) { sizeof(tpm_go)) < 0) {
printk(BIOS_ERR, "%s: Start command failed\n", __func__); printk(BIOS_ERR, "%s: Start command failed\n", __func__);
goto out; goto out;
@ -382,6 +387,7 @@ static void cr50_vendor_init(struct tpm_chip *chip)
int tpm_vendor_probe(unsigned bus, uint32_t addr) int tpm_vendor_probe(unsigned bus, uint32_t addr)
{ {
struct tpm_inf_dev *tpm_dev = car_get_var_ptr(&g_tpm_dev); struct tpm_inf_dev *tpm_dev = car_get_var_ptr(&g_tpm_dev);
struct tpm_chip probe_chip;
struct stopwatch sw; struct stopwatch sw;
uint8_t buf = 0; uint8_t buf = 0;
int ret; int ret;
@ -390,10 +396,12 @@ int tpm_vendor_probe(unsigned bus, uint32_t addr)
tpm_dev->bus = bus; tpm_dev->bus = bus;
tpm_dev->addr = addr; tpm_dev->addr = addr;
cr50_vendor_init(&probe_chip);
/* Wait for TPM_ACCESS register ValidSts bit to be set */ /* Wait for TPM_ACCESS register ValidSts bit to be set */
stopwatch_init_msecs_expire(&sw, sw_run_duration); stopwatch_init_msecs_expire(&sw, sw_run_duration);
do { do {
ret = iic_tpm_read(TPM_ACCESS(0), &buf, 1); ret = cr50_i2c_read(&probe_chip, TPM_ACCESS(0), &buf, 1);
if (!ret && (buf & TPM_STS_VALID)) { if (!ret && (buf & TPM_STS_VALID)) {
sw_run_duration = stopwatch_duration_msecs(&sw); sw_run_duration = stopwatch_duration_msecs(&sw);
break; break;
@ -435,7 +443,7 @@ int tpm_vendor_init(struct tpm_chip *chip, unsigned bus, uint32_t dev_addr)
return -1; return -1;
/* Read four bytes from DID_VID register */ /* Read four bytes from DID_VID register */
if (iic_tpm_read(TPM_DID_VID(0), (uint8_t *)&vendor, 4) < 0) if (cr50_i2c_read(chip, TPM_DID_VID(0), (uint8_t *)&vendor, 4) < 0)
goto out_err; goto out_err;
if (vendor != CR50_DID_VID) { if (vendor != CR50_DID_VID) {