tpm/tpm_i2c_stm_st33: Add new tpm_stm_dev structure and remove tpm_i2c_buffer[0], [1] buffer.
In order to clean big buffers in st33zp24_platform_data structure, replace with tpm_stm_dev for driver internal usage. As only one buffer is really necessary replace with buf field. In the mean time move tpm_i2c_stm_st33.h to include/linux/platform_data. Reviewed-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com> Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com> Signed-off-by: Peter Huewe <peterhuewe@gmx.de>
This commit is contained in:
parent
2dbca7508f
commit
b9626f3287
|
@ -40,7 +40,6 @@
|
||||||
#include <linux/wait.h>
|
#include <linux/wait.h>
|
||||||
#include <linux/string.h>
|
#include <linux/string.h>
|
||||||
#include <linux/interrupt.h>
|
#include <linux/interrupt.h>
|
||||||
#include <linux/spinlock.h>
|
|
||||||
#include <linux/sysfs.h>
|
#include <linux/sysfs.h>
|
||||||
#include <linux/gpio.h>
|
#include <linux/gpio.h>
|
||||||
#include <linux/sched.h>
|
#include <linux/sched.h>
|
||||||
|
@ -48,6 +47,7 @@
|
||||||
#include <linux/io.h>
|
#include <linux/io.h>
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
|
|
||||||
|
#include <linux/platform_data/tpm_i2c_stm_st33.h>
|
||||||
#include "tpm.h"
|
#include "tpm.h"
|
||||||
|
|
||||||
#define TPM_ACCESS 0x0
|
#define TPM_ACCESS 0x0
|
||||||
|
@ -66,7 +66,7 @@
|
||||||
#define TPM_BUFSIZE 2048
|
#define TPM_BUFSIZE 2048
|
||||||
|
|
||||||
#define LOCALITY0 0
|
#define LOCALITY0 0
|
||||||
#include "tpm_i2c_stm_st33.h"
|
|
||||||
|
|
||||||
enum stm33zp24_access {
|
enum stm33zp24_access {
|
||||||
TPM_ACCESS_VALID = 0x80,
|
TPM_ACCESS_VALID = 0x80,
|
||||||
|
@ -98,6 +98,15 @@ enum tis_defaults {
|
||||||
TIS_LONG_TIMEOUT = 2000,
|
TIS_LONG_TIMEOUT = 2000,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct tpm_stm_dev {
|
||||||
|
struct i2c_client *client;
|
||||||
|
struct completion irq_detection;
|
||||||
|
struct tpm_chip *chip;
|
||||||
|
u8 buf[TPM_BUFSIZE + 1];
|
||||||
|
int io_serirq;
|
||||||
|
int io_lpcpd;
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* write8_reg
|
* write8_reg
|
||||||
* Send byte to the TIS register according to the ST33ZP24 I2C protocol.
|
* Send byte to the TIS register according to the ST33ZP24 I2C protocol.
|
||||||
|
@ -106,17 +115,12 @@ enum tis_defaults {
|
||||||
* @param: tpm_size, The length of the data
|
* @param: tpm_size, The length of the data
|
||||||
* @return: Returns negative errno, or else the number of bytes written.
|
* @return: Returns negative errno, or else the number of bytes written.
|
||||||
*/
|
*/
|
||||||
static int write8_reg(struct i2c_client *client, u8 tpm_register,
|
static int write8_reg(struct tpm_stm_dev *tpm_dev, u8 tpm_register,
|
||||||
u8 *tpm_data, u16 tpm_size)
|
u8 *tpm_data, u16 tpm_size)
|
||||||
{
|
{
|
||||||
struct st33zp24_platform_data *pin_infos;
|
tpm_dev->buf[0] = tpm_register;
|
||||||
|
memcpy(tpm_dev->buf + 1, tpm_data, tpm_size);
|
||||||
pin_infos = client->dev.platform_data;
|
return i2c_master_send(tpm_dev->client, tpm_dev->buf, tpm_size + 1);
|
||||||
|
|
||||||
pin_infos->tpm_i2c_buffer[0][0] = tpm_register;
|
|
||||||
memcpy(&pin_infos->tpm_i2c_buffer[0][1], tpm_data, tpm_size);
|
|
||||||
return i2c_master_send(client, pin_infos->tpm_i2c_buffer[0],
|
|
||||||
tpm_size + 1);
|
|
||||||
} /* write8_reg() */
|
} /* write8_reg() */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -127,56 +131,56 @@ static int write8_reg(struct i2c_client *client, u8 tpm_register,
|
||||||
* @param: tpm_size, tpm TPM response size to read.
|
* @param: tpm_size, tpm TPM response size to read.
|
||||||
* @return: number of byte read successfully: should be one if success.
|
* @return: number of byte read successfully: should be one if success.
|
||||||
*/
|
*/
|
||||||
static int read8_reg(struct i2c_client *client, u8 tpm_register,
|
static int read8_reg(struct tpm_stm_dev *tpm_dev, u8 tpm_register,
|
||||||
u8 *tpm_data, int tpm_size)
|
u8 *tpm_data, int tpm_size)
|
||||||
{
|
{
|
||||||
u8 status = 0;
|
u8 status = 0;
|
||||||
u8 data;
|
u8 data;
|
||||||
|
|
||||||
data = TPM_DUMMY_BYTE;
|
data = TPM_DUMMY_BYTE;
|
||||||
status = write8_reg(client, tpm_register, &data, 1);
|
status = write8_reg(tpm_dev, tpm_register, &data, 1);
|
||||||
if (status == 2)
|
if (status == 2)
|
||||||
status = i2c_master_recv(client, tpm_data, tpm_size);
|
status = i2c_master_recv(tpm_dev->client, tpm_data, tpm_size);
|
||||||
return status;
|
return status;
|
||||||
} /* read8_reg() */
|
} /* read8_reg() */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* I2C_WRITE_DATA
|
* I2C_WRITE_DATA
|
||||||
* Send byte to the TIS register according to the ST33ZP24 I2C protocol.
|
* Send byte to the TIS register according to the ST33ZP24 I2C protocol.
|
||||||
* @param: client, the chip description
|
* @param: tpm_dev, the chip description
|
||||||
* @param: tpm_register, the tpm tis register where the data should be written
|
* @param: tpm_register, the tpm tis register where the data should be written
|
||||||
* @param: tpm_data, the tpm_data to write inside the tpm_register
|
* @param: tpm_data, the tpm_data to write inside the tpm_register
|
||||||
* @param: tpm_size, The length of the data
|
* @param: tpm_size, The length of the data
|
||||||
* @return: number of byte written successfully: should be one if success.
|
* @return: number of byte written successfully: should be one if success.
|
||||||
*/
|
*/
|
||||||
#define I2C_WRITE_DATA(client, tpm_register, tpm_data, tpm_size) \
|
#define I2C_WRITE_DATA(tpm_dev, tpm_register, tpm_data, tpm_size) \
|
||||||
(write8_reg(client, tpm_register | \
|
(write8_reg(tpm_dev, tpm_register | \
|
||||||
TPM_WRITE_DIRECTION, tpm_data, tpm_size))
|
TPM_WRITE_DIRECTION, tpm_data, tpm_size))
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* I2C_READ_DATA
|
* I2C_READ_DATA
|
||||||
* Recv byte from the TIS register according to the ST33ZP24 I2C protocol.
|
* Recv byte from the TIS register according to the ST33ZP24 I2C protocol.
|
||||||
* @param: tpm, the chip description
|
* @param: tpm_dev, the chip description
|
||||||
* @param: tpm_register, the tpm tis register where the data should be read
|
* @param: tpm_register, the tpm tis register where the data should be read
|
||||||
* @param: tpm_data, the TPM response
|
* @param: tpm_data, the TPM response
|
||||||
* @param: tpm_size, tpm TPM response size to read.
|
* @param: tpm_size, tpm TPM response size to read.
|
||||||
* @return: number of byte read successfully: should be one if success.
|
* @return: number of byte read successfully: should be one if success.
|
||||||
*/
|
*/
|
||||||
#define I2C_READ_DATA(client, tpm_register, tpm_data, tpm_size) \
|
#define I2C_READ_DATA(tpm_dev, tpm_register, tpm_data, tpm_size) \
|
||||||
(read8_reg(client, tpm_register, tpm_data, tpm_size))
|
(read8_reg(tpm_dev, tpm_register, tpm_data, tpm_size))
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* clear_interruption
|
* clear_interruption
|
||||||
* clear the TPM interrupt register.
|
* clear the TPM interrupt register.
|
||||||
* @param: tpm, the chip description
|
* @param: tpm, the chip description
|
||||||
*/
|
*/
|
||||||
static void clear_interruption(struct i2c_client *client)
|
static void clear_interruption(struct tpm_stm_dev *tpm_dev)
|
||||||
{
|
{
|
||||||
u8 interrupt;
|
u8 interrupt;
|
||||||
|
|
||||||
I2C_READ_DATA(client, TPM_INT_STATUS, &interrupt, 1);
|
I2C_READ_DATA(tpm_dev, TPM_INT_STATUS, &interrupt, 1);
|
||||||
I2C_WRITE_DATA(client, TPM_INT_STATUS, &interrupt, 1);
|
I2C_WRITE_DATA(tpm_dev, TPM_INT_STATUS, &interrupt, 1);
|
||||||
I2C_READ_DATA(client, TPM_INT_STATUS, &interrupt, 1);
|
I2C_READ_DATA(tpm_dev, TPM_INT_STATUS, &interrupt, 1);
|
||||||
} /* clear_interruption() */
|
} /* clear_interruption() */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -190,17 +194,16 @@ static long _wait_for_interrupt_serirq_timeout(struct tpm_chip *chip,
|
||||||
{
|
{
|
||||||
long status;
|
long status;
|
||||||
struct i2c_client *client;
|
struct i2c_client *client;
|
||||||
struct st33zp24_platform_data *pin_infos;
|
struct tpm_stm_dev *tpm_dev;
|
||||||
|
|
||||||
client = (struct i2c_client *)TPM_VPRIV(chip);
|
tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip);
|
||||||
pin_infos = client->dev.platform_data;
|
client = tpm_dev->client;
|
||||||
|
|
||||||
status = wait_for_completion_interruptible_timeout(
|
status = wait_for_completion_interruptible_timeout(
|
||||||
&pin_infos->irq_detection,
|
&tpm_dev->irq_detection,
|
||||||
timeout);
|
timeout);
|
||||||
if (status > 0)
|
if (status > 0)
|
||||||
enable_irq(gpio_to_irq(pin_infos->io_serirq));
|
enable_irq(client->irq);
|
||||||
gpio_direction_input(pin_infos->io_serirq);
|
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
} /* wait_for_interrupt_serirq_timeout() */
|
} /* wait_for_interrupt_serirq_timeout() */
|
||||||
|
@ -209,15 +212,15 @@ static int wait_for_serirq_timeout(struct tpm_chip *chip, bool condition,
|
||||||
unsigned long timeout)
|
unsigned long timeout)
|
||||||
{
|
{
|
||||||
int status = 2;
|
int status = 2;
|
||||||
struct i2c_client *client;
|
struct tpm_stm_dev *tpm_dev;
|
||||||
|
|
||||||
client = (struct i2c_client *)TPM_VPRIV(chip);
|
tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip);
|
||||||
|
|
||||||
status = _wait_for_interrupt_serirq_timeout(chip, timeout);
|
status = _wait_for_interrupt_serirq_timeout(chip, timeout);
|
||||||
if (!status) {
|
if (!status) {
|
||||||
status = -EBUSY;
|
status = -EBUSY;
|
||||||
} else {
|
} else {
|
||||||
clear_interruption(client);
|
clear_interruption(tpm_dev);
|
||||||
if (condition)
|
if (condition)
|
||||||
status = 1;
|
status = 1;
|
||||||
}
|
}
|
||||||
|
@ -230,13 +233,13 @@ static int wait_for_serirq_timeout(struct tpm_chip *chip, bool condition,
|
||||||
*/
|
*/
|
||||||
static void tpm_stm_i2c_cancel(struct tpm_chip *chip)
|
static void tpm_stm_i2c_cancel(struct tpm_chip *chip)
|
||||||
{
|
{
|
||||||
struct i2c_client *client;
|
struct tpm_stm_dev *tpm_dev;
|
||||||
u8 data;
|
u8 data;
|
||||||
|
|
||||||
client = (struct i2c_client *)TPM_VPRIV(chip);
|
tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip);
|
||||||
|
|
||||||
data = TPM_STS_COMMAND_READY;
|
data = TPM_STS_COMMAND_READY;
|
||||||
I2C_WRITE_DATA(client, TPM_STS, &data, 1);
|
I2C_WRITE_DATA(tpm_dev, TPM_STS, &data, 1);
|
||||||
if (chip->vendor.irq)
|
if (chip->vendor.irq)
|
||||||
wait_for_serirq_timeout(chip, 1, chip->vendor.timeout_a);
|
wait_for_serirq_timeout(chip, 1, chip->vendor.timeout_a);
|
||||||
} /* tpm_stm_i2c_cancel() */
|
} /* tpm_stm_i2c_cancel() */
|
||||||
|
@ -248,12 +251,12 @@ static void tpm_stm_i2c_cancel(struct tpm_chip *chip)
|
||||||
*/
|
*/
|
||||||
static u8 tpm_stm_i2c_status(struct tpm_chip *chip)
|
static u8 tpm_stm_i2c_status(struct tpm_chip *chip)
|
||||||
{
|
{
|
||||||
struct i2c_client *client;
|
struct tpm_stm_dev *tpm_dev;
|
||||||
u8 data;
|
u8 data;
|
||||||
|
|
||||||
client = (struct i2c_client *)TPM_VPRIV(chip);
|
tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip);
|
||||||
|
|
||||||
I2C_READ_DATA(client, TPM_STS, &data, 1);
|
I2C_READ_DATA(tpm_dev, TPM_STS, &data, 1);
|
||||||
return data;
|
return data;
|
||||||
} /* tpm_stm_i2c_status() */
|
} /* tpm_stm_i2c_status() */
|
||||||
|
|
||||||
|
@ -265,13 +268,13 @@ static u8 tpm_stm_i2c_status(struct tpm_chip *chip)
|
||||||
*/
|
*/
|
||||||
static int check_locality(struct tpm_chip *chip)
|
static int check_locality(struct tpm_chip *chip)
|
||||||
{
|
{
|
||||||
struct i2c_client *client;
|
struct tpm_stm_dev *tpm_dev;
|
||||||
u8 data;
|
u8 data;
|
||||||
u8 status;
|
u8 status;
|
||||||
|
|
||||||
client = (struct i2c_client *)TPM_VPRIV(chip);
|
tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip);
|
||||||
|
|
||||||
status = I2C_READ_DATA(client, TPM_ACCESS, &data, 1);
|
status = I2C_READ_DATA(tpm_dev, TPM_ACCESS, &data, 1);
|
||||||
if (status && (data &
|
if (status && (data &
|
||||||
(TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) ==
|
(TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) ==
|
||||||
(TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID))
|
(TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID))
|
||||||
|
@ -290,16 +293,16 @@ static int request_locality(struct tpm_chip *chip)
|
||||||
{
|
{
|
||||||
unsigned long stop;
|
unsigned long stop;
|
||||||
long rc;
|
long rc;
|
||||||
struct i2c_client *client;
|
struct tpm_stm_dev *tpm_dev;
|
||||||
u8 data;
|
u8 data;
|
||||||
|
|
||||||
client = (struct i2c_client *)TPM_VPRIV(chip);
|
tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip);
|
||||||
|
|
||||||
if (check_locality(chip) == chip->vendor.locality)
|
if (check_locality(chip) == chip->vendor.locality)
|
||||||
return chip->vendor.locality;
|
return chip->vendor.locality;
|
||||||
|
|
||||||
data = TPM_ACCESS_REQUEST_USE;
|
data = TPM_ACCESS_REQUEST_USE;
|
||||||
rc = I2C_WRITE_DATA(client, TPM_ACCESS, &data, 1);
|
rc = I2C_WRITE_DATA(tpm_dev, TPM_ACCESS, &data, 1);
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
|
@ -328,13 +331,13 @@ end:
|
||||||
*/
|
*/
|
||||||
static void release_locality(struct tpm_chip *chip)
|
static void release_locality(struct tpm_chip *chip)
|
||||||
{
|
{
|
||||||
struct i2c_client *client;
|
struct tpm_stm_dev *tpm_dev;
|
||||||
u8 data;
|
u8 data;
|
||||||
|
|
||||||
client = (struct i2c_client *)TPM_VPRIV(chip);
|
tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip);
|
||||||
data = TPM_ACCESS_ACTIVE_LOCALITY;
|
data = TPM_ACCESS_ACTIVE_LOCALITY;
|
||||||
|
|
||||||
I2C_WRITE_DATA(client, TPM_ACCESS, &data, 1);
|
I2C_WRITE_DATA(tpm_dev, TPM_ACCESS, &data, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -347,19 +350,20 @@ static int get_burstcount(struct tpm_chip *chip)
|
||||||
unsigned long stop;
|
unsigned long stop;
|
||||||
int burstcnt, status;
|
int burstcnt, status;
|
||||||
u8 tpm_reg, temp;
|
u8 tpm_reg, temp;
|
||||||
|
struct tpm_stm_dev *tpm_dev;
|
||||||
|
|
||||||
struct i2c_client *client = (struct i2c_client *)TPM_VPRIV(chip);
|
tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip);
|
||||||
|
|
||||||
stop = jiffies + chip->vendor.timeout_d;
|
stop = jiffies + chip->vendor.timeout_d;
|
||||||
do {
|
do {
|
||||||
tpm_reg = TPM_STS + 1;
|
tpm_reg = TPM_STS + 1;
|
||||||
status = I2C_READ_DATA(client, tpm_reg, &temp, 1);
|
status = I2C_READ_DATA(tpm_dev, tpm_reg, &temp, 1);
|
||||||
if (status < 0)
|
if (status < 0)
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
tpm_reg = tpm_reg + 1;
|
tpm_reg = tpm_reg + 1;
|
||||||
burstcnt = temp;
|
burstcnt = temp;
|
||||||
status = I2C_READ_DATA(client, tpm_reg, &temp, 1);
|
status = I2C_READ_DATA(tpm_dev, tpm_reg, &temp, 1);
|
||||||
if (status < 0)
|
if (status < 0)
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
|
@ -416,9 +420,9 @@ static int wait_for_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
|
||||||
static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count)
|
static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count)
|
||||||
{
|
{
|
||||||
int size = 0, burstcnt, len;
|
int size = 0, burstcnt, len;
|
||||||
struct i2c_client *client;
|
struct tpm_stm_dev *tpm_dev;
|
||||||
|
|
||||||
client = (struct i2c_client *)TPM_VPRIV(chip);
|
tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip);
|
||||||
|
|
||||||
while (size < count &&
|
while (size < count &&
|
||||||
wait_for_stat(chip,
|
wait_for_stat(chip,
|
||||||
|
@ -430,7 +434,7 @@ static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count)
|
||||||
if (burstcnt < 0)
|
if (burstcnt < 0)
|
||||||
return burstcnt;
|
return burstcnt;
|
||||||
len = min_t(int, burstcnt, count - size);
|
len = min_t(int, burstcnt, count - size);
|
||||||
I2C_READ_DATA(client, TPM_DATA_FIFO, buf + size, len);
|
I2C_READ_DATA(tpm_dev, TPM_DATA_FIFO, buf + size, len);
|
||||||
size += len;
|
size += len;
|
||||||
}
|
}
|
||||||
return size;
|
return size;
|
||||||
|
@ -446,14 +450,14 @@ static irqreturn_t tpm_ioserirq_handler(int irq, void *dev_id)
|
||||||
{
|
{
|
||||||
struct tpm_chip *chip = dev_id;
|
struct tpm_chip *chip = dev_id;
|
||||||
struct i2c_client *client;
|
struct i2c_client *client;
|
||||||
struct st33zp24_platform_data *pin_infos;
|
struct tpm_stm_dev *tpm_dev;
|
||||||
|
|
||||||
disable_irq_nosync(irq);
|
disable_irq_nosync(irq);
|
||||||
|
|
||||||
client = (struct i2c_client *)TPM_VPRIV(chip);
|
tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip);
|
||||||
pin_infos = client->dev.platform_data;
|
client = tpm_dev->client;
|
||||||
|
|
||||||
complete(&pin_infos->irq_detection);
|
complete(&tpm_dev->irq_detection);
|
||||||
return IRQ_HANDLED;
|
return IRQ_HANDLED;
|
||||||
} /* tpm_ioserirq_handler() */
|
} /* tpm_ioserirq_handler() */
|
||||||
|
|
||||||
|
@ -475,13 +479,15 @@ static int tpm_stm_i2c_send(struct tpm_chip *chip, unsigned char *buf,
|
||||||
int ret;
|
int ret;
|
||||||
u8 data;
|
u8 data;
|
||||||
struct i2c_client *client;
|
struct i2c_client *client;
|
||||||
|
struct tpm_stm_dev *tpm_dev;
|
||||||
|
|
||||||
if (chip == NULL)
|
if (chip == NULL)
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
if (len < TPM_HEADER_SIZE)
|
if (len < TPM_HEADER_SIZE)
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
|
|
||||||
client = (struct i2c_client *)TPM_VPRIV(chip);
|
tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip);
|
||||||
|
client = tpm_dev->client;
|
||||||
|
|
||||||
client->flags = 0;
|
client->flags = 0;
|
||||||
|
|
||||||
|
@ -505,7 +511,7 @@ static int tpm_stm_i2c_send(struct tpm_chip *chip, unsigned char *buf,
|
||||||
if (burstcnt < 0)
|
if (burstcnt < 0)
|
||||||
return burstcnt;
|
return burstcnt;
|
||||||
size = min_t(int, len - i - 1, burstcnt);
|
size = min_t(int, len - i - 1, burstcnt);
|
||||||
ret = I2C_WRITE_DATA(client, TPM_DATA_FIFO, buf + i, size);
|
ret = I2C_WRITE_DATA(tpm_dev, TPM_DATA_FIFO, buf + i, size);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto out_err;
|
goto out_err;
|
||||||
|
|
||||||
|
@ -518,7 +524,7 @@ static int tpm_stm_i2c_send(struct tpm_chip *chip, unsigned char *buf,
|
||||||
goto out_err;
|
goto out_err;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = I2C_WRITE_DATA(client, TPM_DATA_FIFO, buf + len - 1, 1);
|
ret = I2C_WRITE_DATA(tpm_dev, TPM_DATA_FIFO, buf + len - 1, 1);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto out_err;
|
goto out_err;
|
||||||
|
|
||||||
|
@ -529,7 +535,7 @@ static int tpm_stm_i2c_send(struct tpm_chip *chip, unsigned char *buf,
|
||||||
}
|
}
|
||||||
|
|
||||||
data = TPM_STS_GO;
|
data = TPM_STS_GO;
|
||||||
I2C_WRITE_DATA(client, TPM_STS, &data, 1);
|
I2C_WRITE_DATA(tpm_dev, TPM_STS, &data, 1);
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
out_err:
|
out_err:
|
||||||
|
@ -623,6 +629,7 @@ tpm_st33_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
|
||||||
u8 intmask;
|
u8 intmask;
|
||||||
struct tpm_chip *chip;
|
struct tpm_chip *chip;
|
||||||
struct st33zp24_platform_data *platform_data;
|
struct st33zp24_platform_data *platform_data;
|
||||||
|
struct tpm_stm_dev *tpm_dev;
|
||||||
|
|
||||||
if (client == NULL) {
|
if (client == NULL) {
|
||||||
pr_info("%s: i2c client is NULL. Device not accessible.\n",
|
pr_info("%s: i2c client is NULL. Device not accessible.\n",
|
||||||
|
@ -637,11 +644,11 @@ tpm_st33_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
chip = tpm_register_hardware(&client->dev, &st_i2c_tpm);
|
tpm_dev = devm_kzalloc(&client->dev, sizeof(struct tpm_stm_dev),
|
||||||
if (!chip) {
|
GFP_KERNEL);
|
||||||
dev_info(&client->dev, "fail chip\n");
|
if (!tpm_dev) {
|
||||||
err = -ENODEV;
|
err = -ENOMEM;
|
||||||
goto end;
|
goto _tpm_clean_answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
platform_data = client->dev.platform_data;
|
platform_data = client->dev.platform_data;
|
||||||
|
@ -652,20 +659,14 @@ tpm_st33_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
|
||||||
goto _tpm_clean_answer;
|
goto _tpm_clean_answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
platform_data->tpm_i2c_buffer[0] =
|
chip = tpm_register_hardware(&client->dev, &st_i2c_tpm);
|
||||||
kmalloc(TPM_BUFSIZE, GFP_KERNEL);
|
if (!chip) {
|
||||||
if (platform_data->tpm_i2c_buffer[0] == NULL) {
|
dev_info(&client->dev, "fail chip\n");
|
||||||
err = -ENOMEM;
|
return -ENODEV;
|
||||||
goto _tpm_clean_answer;
|
|
||||||
}
|
|
||||||
platform_data->tpm_i2c_buffer[1] =
|
|
||||||
kmalloc(TPM_BUFSIZE, GFP_KERNEL);
|
|
||||||
if (platform_data->tpm_i2c_buffer[1] == NULL) {
|
|
||||||
err = -ENOMEM;
|
|
||||||
goto _tpm_clean_response1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TPM_VPRIV(chip) = client;
|
TPM_VPRIV(chip) = tpm_dev;
|
||||||
|
tpm_dev->client = client;
|
||||||
|
|
||||||
chip->vendor.timeout_a = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
|
chip->vendor.timeout_a = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
|
||||||
chip->vendor.timeout_b = msecs_to_jiffies(TIS_LONG_TIMEOUT);
|
chip->vendor.timeout_b = msecs_to_jiffies(TIS_LONG_TIMEOUT);
|
||||||
|
@ -682,16 +683,16 @@ tpm_st33_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (interrupts) {
|
if (interrupts) {
|
||||||
init_completion(&platform_data->irq_detection);
|
init_completion(&tpm_dev->irq_detection);
|
||||||
if (request_locality(chip) != LOCALITY0) {
|
if (request_locality(chip) != LOCALITY0) {
|
||||||
err = -ENODEV;
|
err = -ENODEV;
|
||||||
goto _tpm_clean_response2;
|
goto _tpm_clean_answer;
|
||||||
}
|
}
|
||||||
err = gpio_request(platform_data->io_serirq, "TPM IO_SERIRQ");
|
err = gpio_request(platform_data->io_serirq, "TPM IO_SERIRQ");
|
||||||
if (err)
|
if (err)
|
||||||
goto _gpio_init2;
|
goto _gpio_init2;
|
||||||
|
|
||||||
clear_interruption(client);
|
clear_interruption(tpm_dev);
|
||||||
err = request_irq(gpio_to_irq(platform_data->io_serirq),
|
err = request_irq(gpio_to_irq(platform_data->io_serirq),
|
||||||
&tpm_ioserirq_handler,
|
&tpm_ioserirq_handler,
|
||||||
IRQF_TRIGGER_HIGH,
|
IRQF_TRIGGER_HIGH,
|
||||||
|
@ -702,7 +703,7 @@ tpm_st33_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
|
||||||
goto _irq_set;
|
goto _irq_set;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = I2C_READ_DATA(client, TPM_INT_ENABLE, &intmask, 1);
|
err = I2C_READ_DATA(tpm_dev, TPM_INT_ENABLE, &intmask, 1);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto _irq_set;
|
goto _irq_set;
|
||||||
|
|
||||||
|
@ -713,16 +714,17 @@ tpm_st33_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
|
||||||
| TPM_INTF_STS_VALID_INT
|
| TPM_INTF_STS_VALID_INT
|
||||||
| TPM_INTF_DATA_AVAIL_INT;
|
| TPM_INTF_DATA_AVAIL_INT;
|
||||||
|
|
||||||
err = I2C_WRITE_DATA(client, TPM_INT_ENABLE, &intmask, 1);
|
err = I2C_WRITE_DATA(tpm_dev, TPM_INT_ENABLE, &intmask, 1);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto _irq_set;
|
goto _irq_set;
|
||||||
|
|
||||||
intmask = TPM_GLOBAL_INT_ENABLE;
|
intmask = TPM_GLOBAL_INT_ENABLE;
|
||||||
err = I2C_WRITE_DATA(client, (TPM_INT_ENABLE + 3), &intmask, 1);
|
err = I2C_WRITE_DATA(tpm_dev, (TPM_INT_ENABLE + 3),
|
||||||
|
&intmask, 1);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto _irq_set;
|
goto _irq_set;
|
||||||
|
|
||||||
err = I2C_READ_DATA(client, TPM_INT_STATUS, &intmask, 1);
|
err = I2C_READ_DATA(tpm_dev, TPM_INT_STATUS, &intmask, 1);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto _irq_set;
|
goto _irq_set;
|
||||||
|
|
||||||
|
@ -744,12 +746,6 @@ _gpio_init2:
|
||||||
_gpio_init1:
|
_gpio_init1:
|
||||||
if (power_mgt)
|
if (power_mgt)
|
||||||
gpio_free(platform_data->io_lpcpd);
|
gpio_free(platform_data->io_lpcpd);
|
||||||
_tpm_clean_response2:
|
|
||||||
kzfree(platform_data->tpm_i2c_buffer[1]);
|
|
||||||
platform_data->tpm_i2c_buffer[1] = NULL;
|
|
||||||
_tpm_clean_response1:
|
|
||||||
kzfree(platform_data->tpm_i2c_buffer[0]);
|
|
||||||
platform_data->tpm_i2c_buffer[0] = NULL;
|
|
||||||
_tpm_clean_answer:
|
_tpm_clean_answer:
|
||||||
tpm_remove_hardware(chip->dev);
|
tpm_remove_hardware(chip->dev);
|
||||||
end:
|
end:
|
||||||
|
@ -765,28 +761,12 @@ end:
|
||||||
*/
|
*/
|
||||||
static int tpm_st33_i2c_remove(struct i2c_client *client)
|
static int tpm_st33_i2c_remove(struct i2c_client *client)
|
||||||
{
|
{
|
||||||
struct tpm_chip *chip = (struct tpm_chip *)i2c_get_clientdata(client);
|
struct tpm_chip *chip =
|
||||||
struct st33zp24_platform_data *pin_infos =
|
(struct tpm_chip *) i2c_get_clientdata(client);
|
||||||
((struct i2c_client *)TPM_VPRIV(chip))->dev.platform_data;
|
|
||||||
|
|
||||||
if (pin_infos != NULL) {
|
|
||||||
free_irq(pin_infos->io_serirq, chip);
|
|
||||||
|
|
||||||
gpio_free(pin_infos->io_serirq);
|
|
||||||
gpio_free(pin_infos->io_lpcpd);
|
|
||||||
|
|
||||||
|
if (chip)
|
||||||
tpm_remove_hardware(chip->dev);
|
tpm_remove_hardware(chip->dev);
|
||||||
|
|
||||||
if (pin_infos->tpm_i2c_buffer[1] != NULL) {
|
|
||||||
kzfree(pin_infos->tpm_i2c_buffer[1]);
|
|
||||||
pin_infos->tpm_i2c_buffer[1] = NULL;
|
|
||||||
}
|
|
||||||
if (pin_infos->tpm_i2c_buffer[0] != NULL) {
|
|
||||||
kzfree(pin_infos->tpm_i2c_buffer[0]);
|
|
||||||
pin_infos->tpm_i2c_buffer[0] = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,9 +12,8 @@
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License along
|
* You should have received a copy of the GNU General Public License
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*
|
*
|
||||||
* STMicroelectronics version 1.2.0, Copyright (C) 2010
|
* STMicroelectronics version 1.2.0, Copyright (C) 2010
|
||||||
* STMicroelectronics comes with ABSOLUTELY NO WARRANTY.
|
* STMicroelectronics comes with ABSOLUTELY NO WARRANTY.
|
||||||
|
@ -30,15 +29,12 @@
|
||||||
#ifndef __STM_ST33_TPM_I2C_MAIN_H__
|
#ifndef __STM_ST33_TPM_I2C_MAIN_H__
|
||||||
#define __STM_ST33_TPM_I2C_MAIN_H__
|
#define __STM_ST33_TPM_I2C_MAIN_H__
|
||||||
|
|
||||||
|
|
||||||
#define TPM_ST33_I2C "st33zp24_i2c"
|
#define TPM_ST33_I2C "st33zp24_i2c"
|
||||||
|
|
||||||
struct st33zp24_platform_data {
|
struct st33zp24_platform_data {
|
||||||
int io_serirq;
|
int io_serirq;
|
||||||
int io_lpcpd;
|
int io_lpcpd;
|
||||||
struct i2c_client *client;
|
|
||||||
u8 *tpm_i2c_buffer[2]; /* 0 Request 1 Response */
|
|
||||||
struct completion irq_detection;
|
|
||||||
struct mutex lock;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* __STM_ST33_TPM_I2C_MAIN_H__ */
|
#endif /* __STM_ST33_TPM_I2C_MAIN_H__ */
|
Loading…
Reference in New Issue