diff options
author | Duncan Laurie <dlaurie@chromium.org> | 2016-09-19 17:05:45 -0700 |
---|---|---|
committer | Duncan Laurie <dlaurie@chromium.org> | 2016-09-19 17:52:47 -0700 |
commit | 6f5ceb26b9b3e1455ebbd6192e1d2c832bddc77e (patch) | |
tree | ff39425fb1f2819fd130677e042d7db2e20846df /src/drivers/i2c/tpm | |
parent | 93c778688f0bf2f90334505a3082a2cd4ce1623a (diff) | |
download | coreboot-6f5ceb26b9b3e1455ebbd6192e1d2c832bddc77e.tar.xz |
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: Ib4a68ce1b3a83ea7c4bcefb9c6f002f6dd4aac1f
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Diffstat (limited to 'src/drivers/i2c/tpm')
-rw-r--r-- | src/drivers/i2c/tpm/cr50.c | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/src/drivers/i2c/tpm/cr50.c b/src/drivers/i2c/tpm/cr50.c index 66278519b3..fbc3ece09b 100644 --- a/src/drivers/i2c/tpm/cr50.c +++ b/src/drivers/i2c/tpm/cr50.c @@ -56,8 +56,9 @@ struct tpm_inf_dev { 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 * @buffer: provided by caller * @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. */ -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); @@ -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 * @buffer: data 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. */ -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); @@ -135,7 +139,7 @@ static int check_locality(struct tpm_chip *chip, int loc) { 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; 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) { 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; if (force || (buf & (TPM_ACCESS_REQUEST_PENDING | TPM_ACCESS_VALID)) == (TPM_ACCESS_REQUEST_PENDING | TPM_ACCESS_VALID)) { 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) 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 */ int timeout = 2 * 1000; /* 2s timeout */ @@ -185,8 +191,8 @@ static int request_locality(struct tpm_chip *chip, int loc) static uint8_t cr50_tis_i2c_status(struct tpm_chip *chip) { uint8_t buf[4]; - if (iic_tpm_read(TPM_STS(chip->vendor.locality), - buf, sizeof(buf)) < 0) { + if (cr50_i2c_read(chip, TPM_STS(chip->vendor.locality), + buf, sizeof(buf)) < 0) { printk(BIOS_ERR, "%s: Failed to read status\n", __func__); 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) { 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); } @@ -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); while (!stopwatch_expired(&sw)) { - if (iic_tpm_read(TPM_STS(chip->vendor.locality), - buf, sizeof(buf)) != 0) { - printk(BIOS_WARNING, "%s: Read failed\n", __func__); + if (cr50_i2c_read(chip, TPM_STS(chip->vendor.locality), + buf, sizeof(buf)) != 0) { mdelay(CR50_TIMEOUT_SHORT_MS); continue; } @@ -253,7 +258,7 @@ static int cr50_tis_i2c_recv(struct tpm_chip *chip, uint8_t *buf, } /* 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__); goto out; } @@ -279,7 +284,7 @@ static int cr50_tis_i2c_recv(struct tpm_chip *chip, uint8_t *buf, } 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__); goto out; } @@ -332,10 +337,10 @@ 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 - * that is inserted by iic_tpm_write() */ + * that is inserted by cr50_i2c_write() */ limit = min(burstcnt - 1, len); - if (iic_tpm_write(TPM_DATA_FIFO(chip->vendor.locality), - &buf[sent], limit) != 0) { + if (cr50_i2c_write(chip, TPM_DATA_FIFO(chip->vendor.locality), + &buf[sent], limit) != 0) { printk(BIOS_ERR, "%s: Write failed\n", __func__); goto out; } @@ -353,8 +358,8 @@ static int cr50_tis_i2c_send(struct tpm_chip *chip, uint8_t *buf, size_t len) } /* Start the TPM command */ - if (iic_tpm_write(TPM_STS(chip->vendor.locality), tpm_go, - sizeof(tpm_go)) < 0) { + if (cr50_i2c_write(chip, TPM_STS(chip->vendor.locality), tpm_go, + sizeof(tpm_go)) < 0) { printk(BIOS_ERR, "%s: Start command failed\n", __func__); goto out; } @@ -382,6 +387,7 @@ static void cr50_vendor_init(struct tpm_chip *chip) int tpm_vendor_probe(unsigned bus, uint32_t addr) { struct tpm_inf_dev *tpm_dev = car_get_var_ptr(&g_tpm_dev); + struct tpm_chip probe_chip; struct stopwatch sw; uint8_t buf = 0; int ret; @@ -390,10 +396,12 @@ int tpm_vendor_probe(unsigned bus, uint32_t addr) tpm_dev->bus = bus; tpm_dev->addr = addr; + cr50_vendor_init(&probe_chip); + /* Wait for TPM_ACCESS register ValidSts bit to be set */ stopwatch_init_msecs_expire(&sw, sw_run_duration); 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)) { sw_run_duration = stopwatch_duration_msecs(&sw); break; @@ -435,7 +443,7 @@ int tpm_vendor_init(struct tpm_chip *chip, unsigned bus, uint32_t dev_addr) return -1; /* 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; if (vendor != CR50_DID_VID) { |