lpc is used as model.
*/
-#include <linux/i2c/tpm_stm_st33_i2c.h>
-
+#include <linux/pci.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/i2c.h>
+#include <linux/fs.h>
+#include <linux/miscdevice.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/delay.h>
+#include <linux/init.h>
+#include <linux/wait.h>
+#include <linux/string.h>
+#include <linux/interrupt.h>
+#include <linux/spinlock.h>
+#include <linux/sysfs.h>
+#include <linux/gpio.h>
+#include <linux/sched.h>
+#include <linux/uaccess.h>
+#include <linux/io.h>
+#include <linux/slab.h>
+#include <linux/sched.h>
+
+#include "tpm.h"
#include "tpm_stm_st33_i2c.h"
enum stm33zp24_access {
struct i2c_client *client;
struct st33zp24_platform_data *pin_infos;
- client = (struct i2c_client *) chip->vendor.iobase;
+ client = (struct i2c_client *) TPM_VPRIV(chip);
pin_infos = client->dev.platform_data;
status = wait_for_completion_interruptible_timeout(
return status;
} /* wait_for_interrupt_serirq_timeout() */
-int wait_for_serirq_timeout(struct tpm_chip *chip, bool condition,
+static int wait_for_serirq_timeout(struct tpm_chip *chip, bool condition,
unsigned long timeout)
{
int status = 2;
struct i2c_client *client;
struct st33zp24_platform_data *pin_infos;
- client = (struct i2c_client *) chip->vendor.iobase;
+ client = (struct i2c_client *) TPM_VPRIV(chip);
pin_infos = client->dev.platform_data;
status = _wait_for_interrupt_serirq_timeout(chip, timeout);
struct i2c_client *client;
u8 data;
- client = (struct i2c_client *) chip->vendor.iobase;
+ client = (struct i2c_client *) TPM_VPRIV(chip);
data = TPM_STS_COMMAND_READY;
I2C_WRITE_DATA(client, TPM_STS, &data, 1);
{
struct i2c_client *client;
u8 data;
- client = (struct i2c_client *) chip->vendor.iobase;
+ client = (struct i2c_client *) TPM_VPRIV(chip);
I2C_READ_DATA(client, TPM_STS, &data, 1);
return data;
u8 data;
u8 status;
- client = (struct i2c_client *) chip->vendor.iobase;
+ client = (struct i2c_client *) TPM_VPRIV(chip);
status = I2C_READ_DATA(client, TPM_ACCESS, &data, 1);
if (status && (data &
struct i2c_client *client;
u8 data;
- client = (struct i2c_client *) chip->vendor.iobase;
+ client = (struct i2c_client *) TPM_VPRIV(chip);
if (check_locality(chip) == chip->vendor.locality)
return chip->vendor.locality;
struct i2c_client *client;
u8 data;
- client = (struct i2c_client *) chip->vendor.iobase;
+ client = (struct i2c_client *) TPM_VPRIV(chip);
data = TPM_ACCESS_ACTIVE_LOCALITY;
I2C_WRITE_DATA(client, TPM_ACCESS, &data, 1);
int burstcnt, status;
u8 tpm_reg, temp;
- struct i2c_client *client = (struct i2c_client *) chip->vendor.iobase;
+ struct i2c_client *client = (struct i2c_client *) TPM_VPRIV(chip);
stop = jiffies + chip->vendor.timeout_d;
do {
int size = 0, burstcnt, len;
struct i2c_client *client;
- client = (struct i2c_client *) chip->vendor.iobase;
+ client = (struct i2c_client *) TPM_VPRIV(chip);
while (size < count &&
wait_for_stat(chip,
disable_irq_nosync(irq);
- client = (struct i2c_client *) chip->vendor.iobase;
+ client = (struct i2c_client *) TPM_VPRIV(chip);
pin_infos = client->dev.platform_data;
complete(&pin_infos->irq_detection);
static int tpm_stm_i2c_send(struct tpm_chip *chip, unsigned char *buf,
size_t len)
{
- u32 ret = 0, ordinal,
+ u32 ordinal,
status,
burstcnt = 0, i, size;
+ int ret;
u8 data;
struct i2c_client *client;
struct st33zp24_platform_data *pin_infos;
if (len < TPM_HEADER_SIZE)
return -EBUSY;
- client = (struct i2c_client *)chip->vendor.iobase;
+ client = (struct i2c_client *)TPM_VPRIV(chip);
pin_infos = client->dev.platform_data;
ordinal = be32_to_cpu(*((__be32 *) (buf + 6)));
struct i2c_client *client;
struct st33zp24_platform_data *pin_infos;
- client = (struct i2c_client *)chip->vendor.iobase;
- pin_infos = client->dev.platform_data;
-
-
if (chip == NULL)
return -EBUSY;
+ client = (struct i2c_client *)TPM_VPRIV(chip);
+ pin_infos = client->dev.platform_data;
+
if (count < TPM_HEADER_SIZE) {
size = -EIO;
goto out;
static int
tpm_st33_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
- u32 err;
+ int err;
u8 intmask;
struct tpm_chip *chip;
struct st33zp24_platform_data *platform_data;
kmalloc(TPM_BUFSIZE * sizeof(u8), GFP_KERNEL);
if (platform_data->tpm_i2c_buffer[1] == NULL) {
err = -ENOMEM;
- goto _tpm_clean_response;
+ goto _tpm_clean_response1;
}
- chip->vendor.iobase = client;
+ TPM_VPRIV(chip) = client;
chip->vendor.timeout_a = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
chip->vendor.timeout_b = msecs_to_jiffies(TIS_LONG_TIMEOUT);
init_completion(&platform_data->irq_detection);
if (request_locality(chip) != LOCALITY0) {
err = -ENODEV;
- goto _tpm_clean_response;
+ goto _tpm_clean_response2;
}
err = gpio_request(platform_data->io_serirq, "TPM IO_SERIRQ");
if (err)
_irq_set:
free_irq(gpio_to_irq(platform_data->io_serirq), (void *) chip);
_gpio_init2:
- if (platform_data && interrupts)
+ if (interrupts)
gpio_free(platform_data->io_serirq);
_gpio_init1:
- if (platform_data && power_mgt)
+ if (power_mgt)
gpio_free(platform_data->io_lpcpd);
-_tpm_clean_response:
- tpm_remove_hardware(chip->dev);
- if (platform_data->tpm_i2c_buffer[1] != NULL) {
- kzfree(platform_data->tpm_i2c_buffer[1]);
- platform_data->tpm_i2c_buffer[1] = NULL;
- }
+_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:
- if (platform_data->tpm_i2c_buffer[0] != NULL) {
- kzfree(platform_data->tpm_i2c_buffer[0]);
- platform_data->tpm_i2c_buffer[0] = NULL;
- }
-
+ tpm_remove_hardware(chip->dev);
platform_data->bChipF = true;
end:
pr_info("TPM I2C initialisation fail\n");
{
struct tpm_chip *chip = (struct tpm_chip *)i2c_get_clientdata(client);
struct st33zp24_platform_data *pin_infos =
- ((struct i2c_client *) chip->vendor.iobase)->dev.platform_data;
+ ((struct i2c_client *) TPM_VPRIV(chip))->dev.platform_data;
if (pin_infos != NULL) {
free_irq(pin_infos->io_serirq, chip);
struct tpm_chip *chip =
(struct tpm_chip *)i2c_get_clientdata(client);
struct st33zp24_platform_data *pin_infos =
- ((struct i2c_client *)chip->vendor.iobase)->dev.platform_data;
+ ((struct i2c_client *)TPM_VPRIV(chip))->dev.platform_data;
int ret = 0;
if (power_mgt)
struct tpm_chip *chip =
(struct tpm_chip *)i2c_get_clientdata(client);
struct st33zp24_platform_data *pin_infos =
- ((struct i2c_client *)chip->vendor.iobase)->dev.platform_data;
+ ((struct i2c_client *)TPM_VPRIV(chip))->dev.platform_data;
int ret = 0;
if (power_mgt) {
gpio_set_value(pin_infos->io_lpcpd, 1);
ret = wait_for_serirq_timeout(chip,
- (chip->vendor.status(chip) &&
+ (chip->vendor.status(chip) &
TPM_STS_VALID) == TPM_STS_VALID,
chip->vendor.timeout_b);
} else{
.id_table = tpm_st33_i2c_id
};
-/*
- * tpm_st33_i2c_init initialize driver
- * @return: 0 if successful, else non zero value.
- */
-static int __init tpm_st33_i2c_init(void)
-{
- return i2c_add_driver(&tpm_st33_i2c_driver);
-}
-
-/*
- * tpm_st33_i2c_exit The kernel calls this function during unloading the
- * module or during shut down process
- */
-static void __exit tpm_st33_i2c_exit(void)
-{
- i2c_del_driver(&tpm_st33_i2c_driver);
-}
-
-module_init(tpm_st33_i2c_init);
-module_exit(tpm_st33_i2c_exit);
+module_i2c_driver(tpm_st33_i2c_driver);
MODULE_AUTHOR("Christophe Ricard (tpmsupport@st.com)");
MODULE_DESCRIPTION("STM TPM I2C ST33 Driver");
MODULE_VERSION("1.2.0");
+MODULE_LICENSE("GPL");
+++ /dev/null
-/*
-* STMicroelectronics TPM I2C Linux driver for TPM ST33ZP24
-* Copyright (C) 2009, 2010 STMicroelectronics
-* Christophe RICARD tpmsupport@st.com
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License along
-* with this program; if not, write to the Free Software Foundation, Inc.,
-* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*
-* STMicroelectronics version 1.2.0, Copyright (C) 2010
-* STMicroelectronics comes with ABSOLUTELY NO WARRANTY.
-* This is free software, and you are welcome to redistribute it
-* under certain conditions.
-*
-* @File: stm_st33_tpm_i2c.h
-*
-* @Date: 06/15/2008
-*/
-#ifndef __STM_ST33_TPM_I2C_H__
-#define __STM_ST33_TPM_I2C_H__
-
-#include <linux/i2c.h>
-
-#define TPM_ST33_I2C "st33zp24_i2c"
-#define TPM_I2C_ST33_ADDR_WR_LOC0 (0x26 >> 1)
-
-
-struct st33zp24_platform_data {
- int io_serirq;
- int io_lpcpd;
- struct i2c_client *client;
- bool bChipF;
- u8 *tpm_i2c_buffer[2]; /* 0 Request 1 Response */
- struct completion irq_detection;
- struct mutex lock;
-};
-
-#endif /* __STM_ST33_TPM_I2C_H__ */