aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char
diff options
context:
space:
mode:
authorKent Yoder <key@linux.vnet.ibm.com>2012-12-05 17:52:43 -0500
committerKent Yoder <key@linux.vnet.ibm.com>2013-02-05 10:38:23 -0500
commit3d7a7bd75d446bd38367c77a723d7a634aba0261 (patch)
tree65bd01faf28aa94fc842f1788126a1bc067858e2 /drivers/char
parent775585e47cd6b5eddf814d53b117b56a1a171553 (diff)
tpm: STM i2c driver fixes
Store the i2c_client struct in the vendor private pointer. Get rid of the unnecessary include/linux/i2c/ header. Moved include files into the driver c file. Fix smatch warnings. Make use of module_i2c_driver(). Removed unused code from the tpm_stm_st33_i2c.h file. Fix return variable signedness in tpm_stm_i2c_send() and tpm_st33_i2c_probe(). Signed-off-by: Kent Yoder <key@linux.vnet.ibm.com>
Diffstat (limited to 'drivers/char')
-rw-r--r--drivers/char/tpm/tpm_stm_st33_i2c.c119
-rw-r--r--drivers/char/tpm/tpm_stm_st33_i2c.h39
2 files changed, 69 insertions, 89 deletions
diff --git a/drivers/char/tpm/tpm_stm_st33_i2c.c b/drivers/char/tpm/tpm_stm_st33_i2c.c
index 32cdd5e92141..f78e532acec5 100644
--- a/drivers/char/tpm/tpm_stm_st33_i2c.c
+++ b/drivers/char/tpm/tpm_stm_st33_i2c.c
@@ -30,8 +30,29 @@
30 lpc is used as model. 30 lpc is used as model.
31 */ 31 */
32 32
33#include <linux/i2c/tpm_stm_st33_i2c.h> 33#include <linux/pci.h>
34 34#include <linux/module.h>
35#include <linux/platform_device.h>
36#include <linux/i2c.h>
37#include <linux/fs.h>
38#include <linux/miscdevice.h>
39#include <linux/module.h>
40#include <linux/kernel.h>
41#include <linux/delay.h>
42#include <linux/init.h>
43#include <linux/wait.h>
44#include <linux/string.h>
45#include <linux/interrupt.h>
46#include <linux/spinlock.h>
47#include <linux/sysfs.h>
48#include <linux/gpio.h>
49#include <linux/sched.h>
50#include <linux/uaccess.h>
51#include <linux/io.h>
52#include <linux/slab.h>
53#include <linux/sched.h>
54
55#include "tpm.h"
35#include "tpm_stm_st33_i2c.h" 56#include "tpm_stm_st33_i2c.h"
36 57
37enum stm33zp24_access { 58enum stm33zp24_access {
@@ -164,7 +185,7 @@ static long _wait_for_interrupt_serirq_timeout(struct tpm_chip *chip,
164 struct i2c_client *client; 185 struct i2c_client *client;
165 struct st33zp24_platform_data *pin_infos; 186 struct st33zp24_platform_data *pin_infos;
166 187
167 client = (struct i2c_client *) chip->vendor.iobase; 188 client = (struct i2c_client *) TPM_VPRIV(chip);
168 pin_infos = client->dev.platform_data; 189 pin_infos = client->dev.platform_data;
169 190
170 status = wait_for_completion_interruptible_timeout( 191 status = wait_for_completion_interruptible_timeout(
@@ -177,14 +198,14 @@ static long _wait_for_interrupt_serirq_timeout(struct tpm_chip *chip,
177 return status; 198 return status;
178} /* wait_for_interrupt_serirq_timeout() */ 199} /* wait_for_interrupt_serirq_timeout() */
179 200
180int wait_for_serirq_timeout(struct tpm_chip *chip, bool condition, 201static int wait_for_serirq_timeout(struct tpm_chip *chip, bool condition,
181 unsigned long timeout) 202 unsigned long timeout)
182{ 203{
183 int status = 2; 204 int status = 2;
184 struct i2c_client *client; 205 struct i2c_client *client;
185 struct st33zp24_platform_data *pin_infos; 206 struct st33zp24_platform_data *pin_infos;
186 207
187 client = (struct i2c_client *) chip->vendor.iobase; 208 client = (struct i2c_client *) TPM_VPRIV(chip);
188 pin_infos = client->dev.platform_data; 209 pin_infos = client->dev.platform_data;
189 210
190 status = _wait_for_interrupt_serirq_timeout(chip, timeout); 211 status = _wait_for_interrupt_serirq_timeout(chip, timeout);
@@ -207,7 +228,7 @@ static void tpm_stm_i2c_cancel(struct tpm_chip *chip)
207 struct i2c_client *client; 228 struct i2c_client *client;
208 u8 data; 229 u8 data;
209 230
210 client = (struct i2c_client *) chip->vendor.iobase; 231 client = (struct i2c_client *) TPM_VPRIV(chip);
211 232
212 data = TPM_STS_COMMAND_READY; 233 data = TPM_STS_COMMAND_READY;
213 I2C_WRITE_DATA(client, TPM_STS, &data, 1); 234 I2C_WRITE_DATA(client, TPM_STS, &data, 1);
@@ -224,7 +245,7 @@ static u8 tpm_stm_i2c_status(struct tpm_chip *chip)
224{ 245{
225 struct i2c_client *client; 246 struct i2c_client *client;
226 u8 data; 247 u8 data;
227 client = (struct i2c_client *) chip->vendor.iobase; 248 client = (struct i2c_client *) TPM_VPRIV(chip);
228 249
229 I2C_READ_DATA(client, TPM_STS, &data, 1); 250 I2C_READ_DATA(client, TPM_STS, &data, 1);
230 return data; 251 return data;
@@ -242,7 +263,7 @@ static int check_locality(struct tpm_chip *chip)
242 u8 data; 263 u8 data;
243 u8 status; 264 u8 status;
244 265
245 client = (struct i2c_client *) chip->vendor.iobase; 266 client = (struct i2c_client *) TPM_VPRIV(chip);
246 267
247 status = I2C_READ_DATA(client, TPM_ACCESS, &data, 1); 268 status = I2C_READ_DATA(client, TPM_ACCESS, &data, 1);
248 if (status && (data & 269 if (status && (data &
@@ -266,7 +287,7 @@ static int request_locality(struct tpm_chip *chip)
266 struct i2c_client *client; 287 struct i2c_client *client;
267 u8 data; 288 u8 data;
268 289
269 client = (struct i2c_client *) chip->vendor.iobase; 290 client = (struct i2c_client *) TPM_VPRIV(chip);
270 291
271 if (check_locality(chip) == chip->vendor.locality) 292 if (check_locality(chip) == chip->vendor.locality)
272 return chip->vendor.locality; 293 return chip->vendor.locality;
@@ -304,7 +325,7 @@ static void release_locality(struct tpm_chip *chip)
304 struct i2c_client *client; 325 struct i2c_client *client;
305 u8 data; 326 u8 data;
306 327
307 client = (struct i2c_client *) chip->vendor.iobase; 328 client = (struct i2c_client *) TPM_VPRIV(chip);
308 data = TPM_ACCESS_ACTIVE_LOCALITY; 329 data = TPM_ACCESS_ACTIVE_LOCALITY;
309 330
310 I2C_WRITE_DATA(client, TPM_ACCESS, &data, 1); 331 I2C_WRITE_DATA(client, TPM_ACCESS, &data, 1);
@@ -321,7 +342,7 @@ static int get_burstcount(struct tpm_chip *chip)
321 int burstcnt, status; 342 int burstcnt, status;
322 u8 tpm_reg, temp; 343 u8 tpm_reg, temp;
323 344
324 struct i2c_client *client = (struct i2c_client *) chip->vendor.iobase; 345 struct i2c_client *client = (struct i2c_client *) TPM_VPRIV(chip);
325 346
326 stop = jiffies + chip->vendor.timeout_d; 347 stop = jiffies + chip->vendor.timeout_d;
327 do { 348 do {
@@ -391,7 +412,7 @@ static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count)
391 int size = 0, burstcnt, len; 412 int size = 0, burstcnt, len;
392 struct i2c_client *client; 413 struct i2c_client *client;
393 414
394 client = (struct i2c_client *) chip->vendor.iobase; 415 client = (struct i2c_client *) TPM_VPRIV(chip);
395 416
396 while (size < count && 417 while (size < count &&
397 wait_for_stat(chip, 418 wait_for_stat(chip,
@@ -421,7 +442,7 @@ static irqreturn_t tpm_ioserirq_handler(int irq, void *dev_id)
421 442
422 disable_irq_nosync(irq); 443 disable_irq_nosync(irq);
423 444
424 client = (struct i2c_client *) chip->vendor.iobase; 445 client = (struct i2c_client *) TPM_VPRIV(chip);
425 pin_infos = client->dev.platform_data; 446 pin_infos = client->dev.platform_data;
426 447
427 complete(&pin_infos->irq_detection); 448 complete(&pin_infos->irq_detection);
@@ -441,9 +462,10 @@ static irqreturn_t tpm_ioserirq_handler(int irq, void *dev_id)
441static int tpm_stm_i2c_send(struct tpm_chip *chip, unsigned char *buf, 462static int tpm_stm_i2c_send(struct tpm_chip *chip, unsigned char *buf,
442 size_t len) 463 size_t len)
443{ 464{
444 u32 ret = 0, ordinal, 465 u32 ordinal,
445 status, 466 status,
446 burstcnt = 0, i, size; 467 burstcnt = 0, i, size;
468 int ret;
447 u8 data; 469 u8 data;
448 struct i2c_client *client; 470 struct i2c_client *client;
449 struct st33zp24_platform_data *pin_infos; 471 struct st33zp24_platform_data *pin_infos;
@@ -453,7 +475,7 @@ static int tpm_stm_i2c_send(struct tpm_chip *chip, unsigned char *buf,
453 if (len < TPM_HEADER_SIZE) 475 if (len < TPM_HEADER_SIZE)
454 return -EBUSY; 476 return -EBUSY;
455 477
456 client = (struct i2c_client *)chip->vendor.iobase; 478 client = (struct i2c_client *)TPM_VPRIV(chip);
457 pin_infos = client->dev.platform_data; 479 pin_infos = client->dev.platform_data;
458 480
459 ordinal = be32_to_cpu(*((__be32 *) (buf + 6))); 481 ordinal = be32_to_cpu(*((__be32 *) (buf + 6)));
@@ -528,13 +550,12 @@ static int tpm_stm_i2c_recv(struct tpm_chip *chip, unsigned char *buf,
528 struct i2c_client *client; 550 struct i2c_client *client;
529 struct st33zp24_platform_data *pin_infos; 551 struct st33zp24_platform_data *pin_infos;
530 552
531 client = (struct i2c_client *)chip->vendor.iobase;
532 pin_infos = client->dev.platform_data;
533
534
535 if (chip == NULL) 553 if (chip == NULL)
536 return -EBUSY; 554 return -EBUSY;
537 555
556 client = (struct i2c_client *)TPM_VPRIV(chip);
557 pin_infos = client->dev.platform_data;
558
538 if (count < TPM_HEADER_SIZE) { 559 if (count < TPM_HEADER_SIZE) {
539 size = -EIO; 560 size = -EIO;
540 goto out; 561 goto out;
@@ -629,7 +650,7 @@ MODULE_PARM_DESC(power_mgt, "Power Management");
629static int 650static int
630tpm_st33_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) 651tpm_st33_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
631{ 652{
632 u32 err; 653 int err;
633 u8 intmask; 654 u8 intmask;
634 struct tpm_chip *chip; 655 struct tpm_chip *chip;
635 struct st33zp24_platform_data *platform_data; 656 struct st33zp24_platform_data *platform_data;
@@ -666,10 +687,10 @@ tpm_st33_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
666 kmalloc(TPM_BUFSIZE * sizeof(u8), GFP_KERNEL); 687 kmalloc(TPM_BUFSIZE * sizeof(u8), GFP_KERNEL);
667 if (platform_data->tpm_i2c_buffer[1] == NULL) { 688 if (platform_data->tpm_i2c_buffer[1] == NULL) {
668 err = -ENOMEM; 689 err = -ENOMEM;
669 goto _tpm_clean_response; 690 goto _tpm_clean_response1;
670 } 691 }
671 692
672 chip->vendor.iobase = client; 693 TPM_VPRIV(chip) = client;
673 694
674 chip->vendor.timeout_a = msecs_to_jiffies(TIS_SHORT_TIMEOUT); 695 chip->vendor.timeout_a = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
675 chip->vendor.timeout_b = msecs_to_jiffies(TIS_LONG_TIMEOUT); 696 chip->vendor.timeout_b = msecs_to_jiffies(TIS_LONG_TIMEOUT);
@@ -689,7 +710,7 @@ tpm_st33_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
689 init_completion(&platform_data->irq_detection); 710 init_completion(&platform_data->irq_detection);
690 if (request_locality(chip) != LOCALITY0) { 711 if (request_locality(chip) != LOCALITY0) {
691 err = -ENODEV; 712 err = -ENODEV;
692 goto _tpm_clean_response; 713 goto _tpm_clean_response2;
693 } 714 }
694 err = gpio_request(platform_data->io_serirq, "TPM IO_SERIRQ"); 715 err = gpio_request(platform_data->io_serirq, "TPM IO_SERIRQ");
695 if (err) 716 if (err)
@@ -745,23 +766,19 @@ tpm_st33_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
745_irq_set: 766_irq_set:
746 free_irq(gpio_to_irq(platform_data->io_serirq), (void *) chip); 767 free_irq(gpio_to_irq(platform_data->io_serirq), (void *) chip);
747_gpio_init2: 768_gpio_init2:
748 if (platform_data && interrupts) 769 if (interrupts)
749 gpio_free(platform_data->io_serirq); 770 gpio_free(platform_data->io_serirq);
750_gpio_init1: 771_gpio_init1:
751 if (platform_data && power_mgt) 772 if (power_mgt)
752 gpio_free(platform_data->io_lpcpd); 773 gpio_free(platform_data->io_lpcpd);
753_tpm_clean_response: 774_tpm_clean_response2:
754 tpm_remove_hardware(chip->dev); 775 kzfree(platform_data->tpm_i2c_buffer[1]);
755 if (platform_data->tpm_i2c_buffer[1] != NULL) { 776 platform_data->tpm_i2c_buffer[1] = NULL;
756 kzfree(platform_data->tpm_i2c_buffer[1]); 777_tpm_clean_response1:
757 platform_data->tpm_i2c_buffer[1] = NULL; 778 kzfree(platform_data->tpm_i2c_buffer[0]);
758 } 779 platform_data->tpm_i2c_buffer[0] = NULL;
759_tpm_clean_answer: 780_tpm_clean_answer:
760 if (platform_data->tpm_i2c_buffer[0] != NULL) { 781 tpm_remove_hardware(chip->dev);
761 kzfree(platform_data->tpm_i2c_buffer[0]);
762 platform_data->tpm_i2c_buffer[0] = NULL;
763 }
764
765 platform_data->bChipF = true; 782 platform_data->bChipF = true;
766end: 783end:
767 pr_info("TPM I2C initialisation fail\n"); 784 pr_info("TPM I2C initialisation fail\n");
@@ -778,7 +795,7 @@ static __devexit int tpm_st33_i2c_remove(struct i2c_client *client)
778{ 795{
779 struct tpm_chip *chip = (struct tpm_chip *)i2c_get_clientdata(client); 796 struct tpm_chip *chip = (struct tpm_chip *)i2c_get_clientdata(client);
780 struct st33zp24_platform_data *pin_infos = 797 struct st33zp24_platform_data *pin_infos =
781 ((struct i2c_client *) chip->vendor.iobase)->dev.platform_data; 798 ((struct i2c_client *) TPM_VPRIV(chip))->dev.platform_data;
782 799
783 if (pin_infos != NULL) { 800 if (pin_infos != NULL) {
784 free_irq(pin_infos->io_serirq, chip); 801 free_irq(pin_infos->io_serirq, chip);
@@ -815,7 +832,7 @@ static int tpm_st33_i2c_pm_suspend(struct i2c_client *client, pm_message_t mesg)
815 struct tpm_chip *chip = 832 struct tpm_chip *chip =
816 (struct tpm_chip *)i2c_get_clientdata(client); 833 (struct tpm_chip *)i2c_get_clientdata(client);
817 struct st33zp24_platform_data *pin_infos = 834 struct st33zp24_platform_data *pin_infos =
818 ((struct i2c_client *)chip->vendor.iobase)->dev.platform_data; 835 ((struct i2c_client *)TPM_VPRIV(chip))->dev.platform_data;
819 int ret = 0; 836 int ret = 0;
820 837
821 if (power_mgt) 838 if (power_mgt)
@@ -838,14 +855,14 @@ static int tpm_st33_i2c_pm_resume(struct i2c_client *client)
838 struct tpm_chip *chip = 855 struct tpm_chip *chip =
839 (struct tpm_chip *)i2c_get_clientdata(client); 856 (struct tpm_chip *)i2c_get_clientdata(client);
840 struct st33zp24_platform_data *pin_infos = 857 struct st33zp24_platform_data *pin_infos =
841 ((struct i2c_client *)chip->vendor.iobase)->dev.platform_data; 858 ((struct i2c_client *)TPM_VPRIV(chip))->dev.platform_data;
842 859
843 int ret = 0; 860 int ret = 0;
844 861
845 if (power_mgt) { 862 if (power_mgt) {
846 gpio_set_value(pin_infos->io_lpcpd, 1); 863 gpio_set_value(pin_infos->io_lpcpd, 1);
847 ret = wait_for_serirq_timeout(chip, 864 ret = wait_for_serirq_timeout(chip,
848 (chip->vendor.status(chip) && 865 (chip->vendor.status(chip) &
849 TPM_STS_VALID) == TPM_STS_VALID, 866 TPM_STS_VALID) == TPM_STS_VALID,
850 chip->vendor.timeout_b); 867 chip->vendor.timeout_b);
851 } else{ 868 } else{
@@ -877,27 +894,9 @@ static struct i2c_driver tpm_st33_i2c_driver = {
877 .id_table = tpm_st33_i2c_id 894 .id_table = tpm_st33_i2c_id
878}; 895};
879 896
880/* 897module_i2c_driver(tpm_st33_i2c_driver);
881 * tpm_st33_i2c_init initialize driver
882 * @return: 0 if successful, else non zero value.
883 */
884static int __init tpm_st33_i2c_init(void)
885{
886 return i2c_add_driver(&tpm_st33_i2c_driver);
887}
888
889/*
890 * tpm_st33_i2c_exit The kernel calls this function during unloading the
891 * module or during shut down process
892 */
893static void __exit tpm_st33_i2c_exit(void)
894{
895 i2c_del_driver(&tpm_st33_i2c_driver);
896}
897
898module_init(tpm_st33_i2c_init);
899module_exit(tpm_st33_i2c_exit);
900 898
901MODULE_AUTHOR("Christophe Ricard (tpmsupport@st.com)"); 899MODULE_AUTHOR("Christophe Ricard (tpmsupport@st.com)");
902MODULE_DESCRIPTION("STM TPM I2C ST33 Driver"); 900MODULE_DESCRIPTION("STM TPM I2C ST33 Driver");
903MODULE_VERSION("1.2.0"); 901MODULE_VERSION("1.2.0");
902MODULE_LICENSE("GPL");
diff --git a/drivers/char/tpm/tpm_stm_st33_i2c.h b/drivers/char/tpm/tpm_stm_st33_i2c.h
index d390542db869..5862d0376bd8 100644
--- a/drivers/char/tpm/tpm_stm_st33_i2c.h
+++ b/drivers/char/tpm/tpm_stm_st33_i2c.h
@@ -30,32 +30,6 @@
30#ifndef __STM_ST33_TPM_I2C_MAIN_H__ 30#ifndef __STM_ST33_TPM_I2C_MAIN_H__
31#define __STM_ST33_TPM_I2C_MAIN_H__ 31#define __STM_ST33_TPM_I2C_MAIN_H__
32 32
33#include <linux/pci.h>
34#include <linux/module.h>
35#include <linux/platform_device.h>
36#include <linux/i2c.h>
37#include <linux/fs.h>
38#include <linux/miscdevice.h>
39#include <linux/module.h>
40#include <linux/kernel.h>
41#include <linux/delay.h>
42#include <linux/init.h>
43#include <linux/wait.h>
44#include <linux/string.h>
45#include <linux/interrupt.h>
46#include <linux/spinlock.h>
47#include <linux/sysfs.h>
48#include <linux/gpio.h>
49#include <linux/sched.h>
50#include <linux/uaccess.h>
51#include <linux/io.h>
52#include <linux/slab.h>
53#include <linux/sched.h>
54
55#include "tpm.h"
56
57#define MINOR_NUM_I2C 224
58
59#define TPM_ACCESS (0x0) 33#define TPM_ACCESS (0x0)
60#define TPM_STS (0x18) 34#define TPM_STS (0x18)
61#define TPM_HASH_END (0x20) 35#define TPM_HASH_END (0x20)
@@ -73,9 +47,16 @@
73 47
74#define LOCALITY0 0 48#define LOCALITY0 0
75 49
76struct st_tpm_hash { 50#define TPM_ST33_I2C "st33zp24_i2c"
77 int size; 51
78 u8 *data; 52struct st33zp24_platform_data {
53 int io_serirq;
54 int io_lpcpd;
55 struct i2c_client *client;
56 bool bChipF;
57 u8 *tpm_i2c_buffer[2]; /* 0 Request 1 Response */
58 struct completion irq_detection;
59 struct mutex lock;
79}; 60};
80 61
81#endif /* __STM_ST33_TPM_I2C_MAIN_H__ */ 62#endif /* __STM_ST33_TPM_I2C_MAIN_H__ */