aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Ricard <christophe.ricard@gmail.com>2015-03-08 06:17:14 -0400
committerPeter Huewe <peterhuewe@gmx.de>2015-03-18 17:43:06 -0400
commitbf38b8710892333cec2d8069644eb36ff435fd6f (patch)
tree8319469f65050f72a95ad0ca3e7d231779eac2b7
parentfe7d36859f25cec5029fb4f26e40db2fea623906 (diff)
tpm/tpm_i2c_stm_st33: Split tpm_i2c_tpm_st33 in 2 layers (core + phy)
tpm_i2c_stm_st33 is a TIS 1.2 TPM with a core interface which can be used by different phy such as i2c or spi. The core part is called st33zp24 which is also the main part reference. include/linux/platform_data/tpm_stm_st33.h is renamed consequently. The driver is also split into an i2c phy in charge of sending/receiving data as well as managing platform data or dts configuration. Acked-by: Jarkko Sakkinen <jarkko.sakknen@linux.intel.com> Reviewed-by: Jason Gunthorpe <jason.gunthorpe@obsidianresearch.com> Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com> Signed-off-by: Peter Huewe <peterhuewe@gmx.de>
-rw-r--r--drivers/char/tpm/Kconfig11
-rw-r--r--drivers/char/tpm/Makefile2
-rw-r--r--drivers/char/tpm/st33zp24/Kconfig20
-rw-r--r--drivers/char/tpm/st33zp24/Makefile9
-rw-r--r--drivers/char/tpm/st33zp24/i2c.c278
-rw-r--r--drivers/char/tpm/st33zp24/st33zp24.c688
-rw-r--r--drivers/char/tpm/st33zp24/st33zp24.h34
-rw-r--r--drivers/char/tpm/tpm_i2c_stm_st33.c915
-rw-r--r--include/linux/platform_data/st33zp24.h (renamed from include/linux/platform_data/tpm_stm_st33.h)21
9 files changed, 1036 insertions, 942 deletions
diff --git a/drivers/char/tpm/Kconfig b/drivers/char/tpm/Kconfig
index 9d4e37549eb2..2dc16d3b2336 100644
--- a/drivers/char/tpm/Kconfig
+++ b/drivers/char/tpm/Kconfig
@@ -100,16 +100,6 @@ config TCG_IBMVTPM
100 will be accessible from within Linux. To compile this driver 100 will be accessible from within Linux. To compile this driver
101 as a module, choose M here; the module will be called tpm_ibmvtpm. 101 as a module, choose M here; the module will be called tpm_ibmvtpm.
102 102
103config TCG_TIS_I2C_ST33
104 tristate "TPM Interface Specification 1.2 Interface (I2C - STMicroelectronics)"
105 depends on I2C
106 depends on GPIOLIB
107 ---help---
108 If you have a TPM security chip from STMicroelectronics working with
109 an I2C bus say Yes and it will be accessible from within Linux.
110 To compile this driver as a module, choose M here; the module will be
111 called tpm_i2c_stm_st33.
112
113config TCG_XEN 103config TCG_XEN
114 tristate "XEN TPM Interface" 104 tristate "XEN TPM Interface"
115 depends on TCG_TPM && XEN 105 depends on TCG_TPM && XEN
@@ -131,4 +121,5 @@ config TCG_CRB
131 from within Linux. To compile this driver as a module, choose 121 from within Linux. To compile this driver as a module, choose
132 M here; the module will be called tpm_crb. 122 M here; the module will be called tpm_crb.
133 123
124source "drivers/char/tpm/st33zp24/Kconfig"
134endif # TCG_TPM 125endif # TCG_TPM
diff --git a/drivers/char/tpm/Makefile b/drivers/char/tpm/Makefile
index 990cf183931d..56e8f1f3dc7e 100644
--- a/drivers/char/tpm/Makefile
+++ b/drivers/char/tpm/Makefile
@@ -20,6 +20,6 @@ obj-$(CONFIG_TCG_NSC) += tpm_nsc.o
20obj-$(CONFIG_TCG_ATMEL) += tpm_atmel.o 20obj-$(CONFIG_TCG_ATMEL) += tpm_atmel.o
21obj-$(CONFIG_TCG_INFINEON) += tpm_infineon.o 21obj-$(CONFIG_TCG_INFINEON) += tpm_infineon.o
22obj-$(CONFIG_TCG_IBMVTPM) += tpm_ibmvtpm.o 22obj-$(CONFIG_TCG_IBMVTPM) += tpm_ibmvtpm.o
23obj-$(CONFIG_TCG_TIS_I2C_ST33) += tpm_i2c_stm_st33.o 23obj-$(CONFIG_TCG_TIS_ST33ZP24) += st33zp24/
24obj-$(CONFIG_TCG_XEN) += xen-tpmfront.o 24obj-$(CONFIG_TCG_XEN) += xen-tpmfront.o
25obj-$(CONFIG_TCG_CRB) += tpm_crb.o 25obj-$(CONFIG_TCG_CRB) += tpm_crb.o
diff --git a/drivers/char/tpm/st33zp24/Kconfig b/drivers/char/tpm/st33zp24/Kconfig
new file mode 100644
index 000000000000..51dcef520d3f
--- /dev/null
+++ b/drivers/char/tpm/st33zp24/Kconfig
@@ -0,0 +1,20 @@
1config TCG_TIS_ST33ZP24
2 tristate "STMicroelectronics TPM Interface Specification 1.2 Interface"
3 depends on GPIOLIB
4 ---help---
5 STMicroelectronics ST33ZP24 core driver. It implements the core
6 TPM1.2 logic and hooks into the TPM kernel APIs. Physical layers will
7 register against it.
8
9 To compile this driver as a module, choose m here. The module will be called
10 tpm_st33zp24.
11
12config TCG_TIS_ST33ZP24_I2C
13 tristate "TPM 1.2 ST33ZP24 I2C support"
14 depends on TCG_TIS_ST33ZP24
15 depends on I2C
16 ---help---
17 This module adds support for the STMicroelectronics TPM security chip
18 ST33ZP24 with i2c interface.
19 To compile this driver as a module, choose M here; the module will be
20 called tpm_st33zp24_i2c.
diff --git a/drivers/char/tpm/st33zp24/Makefile b/drivers/char/tpm/st33zp24/Makefile
new file mode 100644
index 000000000000..414497f00e5a
--- /dev/null
+++ b/drivers/char/tpm/st33zp24/Makefile
@@ -0,0 +1,9 @@
1#
2# Makefile for ST33ZP24 TPM 1.2 driver
3#
4
5tpm_st33zp24-objs = st33zp24.o
6obj-$(CONFIG_TCG_TIS_ST33ZP24) += tpm_st33zp24.o
7
8tpm_st33zp24_i2c-objs = i2c.o
9obj-$(CONFIG_TCG_TIS_ST33ZP24_I2C) += tpm_st33zp24_i2c.o
diff --git a/drivers/char/tpm/st33zp24/i2c.c b/drivers/char/tpm/st33zp24/i2c.c
new file mode 100644
index 000000000000..95e3091c4590
--- /dev/null
+++ b/drivers/char/tpm/st33zp24/i2c.c
@@ -0,0 +1,278 @@
1/*
2 * STMicroelectronics TPM I2C Linux driver for TPM ST33ZP24
3 * Copyright (C) 2009 - 2015 STMicroelectronics
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <linux/module.h>
20#include <linux/i2c.h>
21#include <linux/gpio.h>
22#include <linux/of_irq.h>
23#include <linux/of_gpio.h>
24#include <linux/tpm.h>
25#include <linux/platform_data/st33zp24.h>
26
27#include "st33zp24.h"
28
29#define TPM_DUMMY_BYTE 0xAA
30#define TPM_WRITE_DIRECTION 0x80
31#define TPM_BUFSIZE 2048
32
33struct st33zp24_i2c_phy {
34 struct i2c_client *client;
35 u8 buf[TPM_BUFSIZE + 1];
36 int io_lpcpd;
37};
38
39/*
40 * write8_reg
41 * Send byte to the TIS register according to the ST33ZP24 I2C protocol.
42 * @param: tpm_register, the tpm tis register where the data should be written
43 * @param: tpm_data, the tpm_data to write inside the tpm_register
44 * @param: tpm_size, The length of the data
45 * @return: Returns negative errno, or else the number of bytes written.
46 */
47static int write8_reg(void *phy_id, u8 tpm_register, u8 *tpm_data, int tpm_size)
48{
49 struct st33zp24_i2c_phy *phy = phy_id;
50
51 phy->buf[0] = tpm_register;
52 memcpy(phy->buf + 1, tpm_data, tpm_size);
53 return i2c_master_send(phy->client, phy->buf, tpm_size + 1);
54} /* write8_reg() */
55
56/*
57 * read8_reg
58 * Recv byte from the TIS register according to the ST33ZP24 I2C protocol.
59 * @param: tpm_register, the tpm tis register where the data should be read
60 * @param: tpm_data, the TPM response
61 * @param: tpm_size, tpm TPM response size to read.
62 * @return: number of byte read successfully: should be one if success.
63 */
64static int read8_reg(void *phy_id, u8 tpm_register, u8 *tpm_data, int tpm_size)
65{
66 struct st33zp24_i2c_phy *phy = phy_id;
67 u8 status = 0;
68 u8 data;
69
70 data = TPM_DUMMY_BYTE;
71 status = write8_reg(phy, tpm_register, &data, 1);
72 if (status == 2)
73 status = i2c_master_recv(phy->client, tpm_data, tpm_size);
74 return status;
75} /* read8_reg() */
76
77/*
78 * st33zp24_i2c_send
79 * Send byte to the TIS register according to the ST33ZP24 I2C protocol.
80 * @param: phy_id, the phy description
81 * @param: tpm_register, the tpm tis register where the data should be written
82 * @param: tpm_data, the tpm_data to write inside the tpm_register
83 * @param: tpm_size, the length of the data
84 * @return: number of byte written successfully: should be one if success.
85 */
86static int st33zp24_i2c_send(void *phy_id, u8 tpm_register, u8 *tpm_data,
87 int tpm_size)
88{
89 return write8_reg(phy_id, tpm_register | TPM_WRITE_DIRECTION, tpm_data,
90 tpm_size);
91}
92
93/*
94 * st33zp24_i2c_recv
95 * Recv byte from the TIS register according to the ST33ZP24 I2C protocol.
96 * @param: phy_id, the phy description
97 * @param: tpm_register, the tpm tis register where the data should be read
98 * @param: tpm_data, the TPM response
99 * @param: tpm_size, tpm TPM response size to read.
100 * @return: number of byte read successfully: should be one if success.
101 */
102static int st33zp24_i2c_recv(void *phy_id, u8 tpm_register, u8 *tpm_data,
103 int tpm_size)
104{
105 return read8_reg(phy_id, tpm_register, tpm_data, tpm_size);
106}
107
108static const struct st33zp24_phy_ops i2c_phy_ops = {
109 .send = st33zp24_i2c_send,
110 .recv = st33zp24_i2c_recv,
111};
112
113#ifdef CONFIG_OF
114static int st33zp24_i2c_of_request_resources(struct st33zp24_i2c_phy *phy)
115{
116 struct device_node *pp;
117 struct i2c_client *client = phy->client;
118 int gpio;
119 int ret;
120
121 pp = client->dev.of_node;
122 if (!pp) {
123 dev_err(&client->dev, "No platform data\n");
124 return -ENODEV;
125 }
126
127 /* Get GPIO from device tree */
128 gpio = of_get_named_gpio(pp, "lpcpd-gpios", 0);
129 if (gpio < 0) {
130 dev_err(&client->dev,
131 "Failed to retrieve lpcpd-gpios from dts.\n");
132 phy->io_lpcpd = -1;
133 /*
134 * lpcpd pin is not specified. This is not an issue as
135 * power management can be also managed by TPM specific
136 * commands. So leave with a success status code.
137 */
138 return 0;
139 }
140 /* GPIO request and configuration */
141 ret = devm_gpio_request_one(&client->dev, gpio,
142 GPIOF_OUT_INIT_HIGH, "TPM IO LPCPD");
143 if (ret) {
144 dev_err(&client->dev, "Failed to request lpcpd pin\n");
145 return -ENODEV;
146 }
147 phy->io_lpcpd = gpio;
148
149 return 0;
150}
151#else
152static int st33zp24_i2c_of_request_resources(struct st33zp24_i2c_phy *phy)
153{
154 return -ENODEV;
155}
156#endif
157
158static int st33zp24_i2c_request_resources(struct i2c_client *client,
159 struct st33zp24_i2c_phy *phy)
160{
161 struct st33zp24_platform_data *pdata;
162 int ret;
163
164 pdata = client->dev.platform_data;
165 if (!pdata) {
166 dev_err(&client->dev, "No platform data\n");
167 return -ENODEV;
168 }
169
170 /* store for late use */
171 phy->io_lpcpd = pdata->io_lpcpd;
172
173 if (gpio_is_valid(pdata->io_lpcpd)) {
174 ret = devm_gpio_request_one(&client->dev,
175 pdata->io_lpcpd, GPIOF_OUT_INIT_HIGH,
176 "TPM IO_LPCPD");
177 if (ret) {
178 dev_err(&client->dev, "Failed to request lpcpd pin\n");
179 return ret;
180 }
181 }
182
183 return 0;
184}
185
186/*
187 * st33zp24_i2c_probe initialize the TPM device
188 * @param: client, the i2c_client drescription (TPM I2C description).
189 * @param: id, the i2c_device_id struct.
190 * @return: 0 in case of success.
191 * -1 in other case.
192 */
193static int st33zp24_i2c_probe(struct i2c_client *client,
194 const struct i2c_device_id *id)
195{
196 int ret;
197 struct st33zp24_platform_data *pdata;
198 struct st33zp24_i2c_phy *phy;
199
200 if (!client) {
201 pr_info("%s: i2c client is NULL. Device not accessible.\n",
202 __func__);
203 return -ENODEV;
204 }
205
206 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
207 dev_info(&client->dev, "client not i2c capable\n");
208 return -ENODEV;
209 }
210
211 phy = devm_kzalloc(&client->dev, sizeof(struct st33zp24_i2c_phy),
212 GFP_KERNEL);
213 if (!phy)
214 return -ENOMEM;
215
216 phy->client = client;
217 pdata = client->dev.platform_data;
218 if (!pdata && client->dev.of_node) {
219 ret = st33zp24_i2c_of_request_resources(phy);
220 if (ret)
221 return ret;
222 } else if (pdata) {
223 ret = st33zp24_i2c_request_resources(client, phy);
224 if (ret)
225 return ret;
226 }
227
228 return st33zp24_probe(phy, &i2c_phy_ops, &client->dev, client->irq,
229 phy->io_lpcpd);
230}
231
232/*
233 * st33zp24_i2c_remove remove the TPM device
234 * @param: client, the i2c_client description (TPM I2C description).
235 * @return: 0 in case of success.
236 */
237static int st33zp24_i2c_remove(struct i2c_client *client)
238{
239 struct tpm_chip *chip = i2c_get_clientdata(client);
240
241 return st33zp24_remove(chip);
242}
243
244static const struct i2c_device_id st33zp24_i2c_id[] = {
245 {TPM_ST33_I2C, 0},
246 {}
247};
248MODULE_DEVICE_TABLE(i2c, st33zp24_i2c_id);
249
250#ifdef CONFIG_OF
251static const struct of_device_id of_st33zp24_i2c_match[] = {
252 { .compatible = "st,st33zp24-i2c", },
253 {}
254};
255MODULE_DEVICE_TABLE(of, of_st33zp24_i2c_match);
256#endif
257
258static SIMPLE_DEV_PM_OPS(st33zp24_i2c_ops, st33zp24_pm_suspend,
259 st33zp24_pm_resume);
260
261static struct i2c_driver st33zp24_i2c_driver = {
262 .driver = {
263 .owner = THIS_MODULE,
264 .name = TPM_ST33_I2C,
265 .pm = &st33zp24_i2c_ops,
266 .of_match_table = of_match_ptr(of_st33zp24_i2c_match),
267 },
268 .probe = st33zp24_i2c_probe,
269 .remove = st33zp24_i2c_remove,
270 .id_table = st33zp24_i2c_id
271};
272
273module_i2c_driver(st33zp24_i2c_driver);
274
275MODULE_AUTHOR("TPM support (TPMsupport@list.st.com)");
276MODULE_DESCRIPTION("STM TPM 1.2 I2C ST33 Driver");
277MODULE_VERSION("1.3.0");
278MODULE_LICENSE("GPL");
diff --git a/drivers/char/tpm/st33zp24/st33zp24.c b/drivers/char/tpm/st33zp24/st33zp24.c
new file mode 100644
index 000000000000..03f254384585
--- /dev/null
+++ b/drivers/char/tpm/st33zp24/st33zp24.c
@@ -0,0 +1,688 @@
1/*
2 * STMicroelectronics TPM Linux driver for TPM ST33ZP24
3 * Copyright (C) 2009 - 2015 STMicroelectronics
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <linux/module.h>
20#include <linux/fs.h>
21#include <linux/miscdevice.h>
22#include <linux/kernel.h>
23#include <linux/delay.h>
24#include <linux/wait.h>
25#include <linux/freezer.h>
26#include <linux/string.h>
27#include <linux/interrupt.h>
28#include <linux/gpio.h>
29#include <linux/sched.h>
30#include <linux/uaccess.h>
31#include <linux/io.h>
32#include <linux/slab.h>
33
34#include "../tpm.h"
35#include "st33zp24.h"
36
37#define TPM_ACCESS 0x0
38#define TPM_STS 0x18
39#define TPM_DATA_FIFO 0x24
40#define TPM_INTF_CAPABILITY 0x14
41#define TPM_INT_STATUS 0x10
42#define TPM_INT_ENABLE 0x08
43
44#define LOCALITY0 0
45
46enum st33zp24_access {
47 TPM_ACCESS_VALID = 0x80,
48 TPM_ACCESS_ACTIVE_LOCALITY = 0x20,
49 TPM_ACCESS_REQUEST_PENDING = 0x04,
50 TPM_ACCESS_REQUEST_USE = 0x02,
51};
52
53enum st33zp24_status {
54 TPM_STS_VALID = 0x80,
55 TPM_STS_COMMAND_READY = 0x40,
56 TPM_STS_GO = 0x20,
57 TPM_STS_DATA_AVAIL = 0x10,
58 TPM_STS_DATA_EXPECT = 0x08,
59};
60
61enum st33zp24_int_flags {
62 TPM_GLOBAL_INT_ENABLE = 0x80,
63 TPM_INTF_CMD_READY_INT = 0x080,
64 TPM_INTF_FIFO_AVALAIBLE_INT = 0x040,
65 TPM_INTF_WAKE_UP_READY_INT = 0x020,
66 TPM_INTF_LOCALITY_CHANGE_INT = 0x004,
67 TPM_INTF_STS_VALID_INT = 0x002,
68 TPM_INTF_DATA_AVAIL_INT = 0x001,
69};
70
71enum tis_defaults {
72 TIS_SHORT_TIMEOUT = 750,
73 TIS_LONG_TIMEOUT = 2000,
74};
75
76struct st33zp24_dev {
77 struct tpm_chip *chip;
78 void *phy_id;
79 const struct st33zp24_phy_ops *ops;
80 u32 intrs;
81 int io_lpcpd;
82};
83
84/*
85 * clear_interruption clear the pending interrupt.
86 * @param: tpm_dev, the tpm device device.
87 * @return: the interrupt status value.
88 */
89static u8 clear_interruption(struct st33zp24_dev *tpm_dev)
90{
91 u8 interrupt;
92
93 tpm_dev->ops->recv(tpm_dev->phy_id, TPM_INT_STATUS, &interrupt, 1);
94 tpm_dev->ops->send(tpm_dev->phy_id, TPM_INT_STATUS, &interrupt, 1);
95 return interrupt;
96} /* clear_interruption() */
97
98/*
99 * st33zp24_cancel, cancel the current command execution or
100 * set STS to COMMAND READY.
101 * @param: chip, the tpm_chip description as specified in driver/char/tpm/tpm.h
102 */
103static void st33zp24_cancel(struct tpm_chip *chip)
104{
105 struct st33zp24_dev *tpm_dev;
106 u8 data;
107
108 tpm_dev = (struct st33zp24_dev *)TPM_VPRIV(chip);
109
110 data = TPM_STS_COMMAND_READY;
111 tpm_dev->ops->send(tpm_dev->phy_id, TPM_STS, &data, 1);
112} /* st33zp24_cancel() */
113
114/*
115 * st33zp24_status return the TPM_STS register
116 * @param: chip, the tpm chip description
117 * @return: the TPM_STS register value.
118 */
119static u8 st33zp24_status(struct tpm_chip *chip)
120{
121 struct st33zp24_dev *tpm_dev;
122 u8 data;
123
124 tpm_dev = (struct st33zp24_dev *)TPM_VPRIV(chip);
125
126 tpm_dev->ops->recv(tpm_dev->phy_id, TPM_STS, &data, 1);
127 return data;
128} /* st33zp24_status() */
129
130/*
131 * check_locality if the locality is active
132 * @param: chip, the tpm chip description
133 * @return: the active locality or -EACCESS.
134 */
135static int check_locality(struct tpm_chip *chip)
136{
137 struct st33zp24_dev *tpm_dev;
138 u8 data;
139 u8 status;
140
141 tpm_dev = (struct st33zp24_dev *)TPM_VPRIV(chip);
142
143 status = tpm_dev->ops->recv(tpm_dev->phy_id, TPM_ACCESS, &data, 1);
144 if (status && (data &
145 (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) ==
146 (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID))
147 return chip->vendor.locality;
148
149 return -EACCES;
150} /* check_locality() */
151
152/*
153 * request_locality request the TPM locality
154 * @param: chip, the chip description
155 * @return: the active locality or negative value.
156 */
157static int request_locality(struct tpm_chip *chip)
158{
159 unsigned long stop;
160 long ret;
161 struct st33zp24_dev *tpm_dev;
162 u8 data;
163
164 if (check_locality(chip) == chip->vendor.locality)
165 return chip->vendor.locality;
166
167 tpm_dev = (struct st33zp24_dev *)TPM_VPRIV(chip);
168
169 data = TPM_ACCESS_REQUEST_USE;
170 ret = tpm_dev->ops->send(tpm_dev->phy_id, TPM_ACCESS, &data, 1);
171 if (ret < 0)
172 return ret;
173
174 stop = jiffies + chip->vendor.timeout_a;
175
176 /* Request locality is usually effective after the request */
177 do {
178 if (check_locality(chip) >= 0)
179 return chip->vendor.locality;
180 msleep(TPM_TIMEOUT);
181 } while (time_before(jiffies, stop));
182
183 /* could not get locality */
184 return -EACCES;
185} /* request_locality() */
186
187/*
188 * release_locality release the active locality
189 * @param: chip, the tpm chip description.
190 */
191static void release_locality(struct tpm_chip *chip)
192{
193 struct st33zp24_dev *tpm_dev;
194 u8 data;
195
196 tpm_dev = (struct st33zp24_dev *)TPM_VPRIV(chip);
197 data = TPM_ACCESS_ACTIVE_LOCALITY;
198
199 tpm_dev->ops->send(tpm_dev->phy_id, TPM_ACCESS, &data, 1);
200}
201
202/*
203 * get_burstcount return the burstcount value
204 * @param: chip, the chip description
205 * return: the burstcount or negative value.
206 */
207static int get_burstcount(struct tpm_chip *chip)
208{
209 unsigned long stop;
210 int burstcnt, status;
211 u8 tpm_reg, temp;
212 struct st33zp24_dev *tpm_dev;
213
214 tpm_dev = (struct st33zp24_dev *)TPM_VPRIV(chip);
215
216 stop = jiffies + chip->vendor.timeout_d;
217 do {
218 tpm_reg = TPM_STS + 1;
219 status = tpm_dev->ops->recv(tpm_dev->phy_id, tpm_reg, &temp, 1);
220 if (status < 0)
221 return -EBUSY;
222
223 tpm_reg = TPM_STS + 2;
224 burstcnt = temp;
225 status = tpm_dev->ops->recv(tpm_dev->phy_id, tpm_reg, &temp, 1);
226 if (status < 0)
227 return -EBUSY;
228
229 burstcnt |= temp << 8;
230 if (burstcnt)
231 return burstcnt;
232 msleep(TPM_TIMEOUT);
233 } while (time_before(jiffies, stop));
234 return -EBUSY;
235} /* get_burstcount() */
236
237
238/*
239 * wait_for_tpm_stat_cond
240 * @param: chip, chip description
241 * @param: mask, expected mask value
242 * @param: check_cancel, does the command expected to be canceled ?
243 * @param: canceled, did we received a cancel request ?
244 * @return: true if status == mask or if the command is canceled.
245 * false in other cases.
246 */
247static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
248 bool check_cancel, bool *canceled)
249{
250 u8 status = chip->ops->status(chip);
251
252 *canceled = false;
253 if ((status & mask) == mask)
254 return true;
255 if (check_cancel && chip->ops->req_canceled(chip, status)) {
256 *canceled = true;
257 return true;
258 }
259 return false;
260}
261
262/*
263 * wait_for_stat wait for a TPM_STS value
264 * @param: chip, the tpm chip description
265 * @param: mask, the value mask to wait
266 * @param: timeout, the timeout
267 * @param: queue, the wait queue.
268 * @param: check_cancel, does the command can be cancelled ?
269 * @return: the tpm status, 0 if success, -ETIME if timeout is reached.
270 */
271static int wait_for_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
272 wait_queue_head_t *queue, bool check_cancel)
273{
274 unsigned long stop;
275 int ret = 0;
276 bool canceled = false;
277 bool condition;
278 u32 cur_intrs;
279 u8 status;
280 struct st33zp24_dev *tpm_dev;
281
282 tpm_dev = (struct st33zp24_dev *)TPM_VPRIV(chip);
283
284 /* check current status */
285 status = st33zp24_status(chip);
286 if ((status & mask) == mask)
287 return 0;
288
289 stop = jiffies + timeout;
290
291 if (chip->vendor.irq) {
292 cur_intrs = tpm_dev->intrs;
293 clear_interruption(tpm_dev);
294 enable_irq(chip->vendor.irq);
295
296 do {
297 if (ret == -ERESTARTSYS && freezing(current))
298 clear_thread_flag(TIF_SIGPENDING);
299
300 timeout = stop - jiffies;
301 if ((long) timeout <= 0)
302 return -1;
303
304 ret = wait_event_interruptible_timeout(*queue,
305 cur_intrs != tpm_dev->intrs,
306 timeout);
307 clear_interruption(tpm_dev);
308 condition = wait_for_tpm_stat_cond(chip, mask,
309 check_cancel, &canceled);
310 if (ret >= 0 && condition) {
311 if (canceled)
312 return -ECANCELED;
313 return 0;
314 }
315 } while (ret == -ERESTARTSYS && freezing(current));
316
317 disable_irq_nosync(chip->vendor.irq);
318
319 } else {
320 do {
321 msleep(TPM_TIMEOUT);
322 status = chip->ops->status(chip);
323 if ((status & mask) == mask)
324 return 0;
325 } while (time_before(jiffies, stop));
326 }
327
328 return -ETIME;
329} /* wait_for_stat() */
330
331/*
332 * recv_data receive data
333 * @param: chip, the tpm chip description
334 * @param: buf, the buffer where the data are received
335 * @param: count, the number of data to receive
336 * @return: the number of bytes read from TPM FIFO.
337 */
338static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count)
339{
340 int size = 0, burstcnt, len, ret;
341 struct st33zp24_dev *tpm_dev;
342
343 tpm_dev = (struct st33zp24_dev *)TPM_VPRIV(chip);
344
345 while (size < count &&
346 wait_for_stat(chip,
347 TPM_STS_DATA_AVAIL | TPM_STS_VALID,
348 chip->vendor.timeout_c,
349 &chip->vendor.read_queue, true) == 0) {
350 burstcnt = get_burstcount(chip);
351 if (burstcnt < 0)
352 return burstcnt;
353 len = min_t(int, burstcnt, count - size);
354 ret = tpm_dev->ops->recv(tpm_dev->phy_id, TPM_DATA_FIFO,
355 buf + size, len);
356 if (ret < 0)
357 return ret;
358
359 size += len;
360 }
361 return size;
362}
363
364/*
365 * tpm_ioserirq_handler the serirq irq handler
366 * @param: irq, the tpm chip description
367 * @param: dev_id, the description of the chip
368 * @return: the status of the handler.
369 */
370static irqreturn_t tpm_ioserirq_handler(int irq, void *dev_id)
371{
372 struct tpm_chip *chip = dev_id;
373 struct st33zp24_dev *tpm_dev;
374
375 tpm_dev = (struct st33zp24_dev *)TPM_VPRIV(chip);
376
377 tpm_dev->intrs++;
378 wake_up_interruptible(&chip->vendor.read_queue);
379 disable_irq_nosync(chip->vendor.irq);
380
381 return IRQ_HANDLED;
382} /* tpm_ioserirq_handler() */
383
384/*
385 * st33zp24_send send TPM commands through the I2C bus.
386 *
387 * @param: chip, the tpm_chip description as specified in driver/char/tpm/tpm.h
388 * @param: buf, the buffer to send.
389 * @param: count, the number of bytes to send.
390 * @return: In case of success the number of bytes sent.
391 * In other case, a < 0 value describing the issue.
392 */
393static int st33zp24_send(struct tpm_chip *chip, unsigned char *buf,
394 size_t len)
395{
396 u32 status, i, size;
397 int burstcnt = 0;
398 int ret;
399 u8 data;
400 struct st33zp24_dev *tpm_dev;
401
402 if (!chip)
403 return -EBUSY;
404 if (len < TPM_HEADER_SIZE)
405 return -EBUSY;
406
407 tpm_dev = (struct st33zp24_dev *)TPM_VPRIV(chip);
408
409 ret = request_locality(chip);
410 if (ret < 0)
411 return ret;
412
413 status = st33zp24_status(chip);
414 if ((status & TPM_STS_COMMAND_READY) == 0) {
415 st33zp24_cancel(chip);
416 if (wait_for_stat
417 (chip, TPM_STS_COMMAND_READY, chip->vendor.timeout_b,
418 &chip->vendor.read_queue, false) < 0) {
419 ret = -ETIME;
420 goto out_err;
421 }
422 }
423
424 for (i = 0; i < len - 1;) {
425 burstcnt = get_burstcount(chip);
426 if (burstcnt < 0)
427 return burstcnt;
428 size = min_t(int, len - i - 1, burstcnt);
429 ret = tpm_dev->ops->send(tpm_dev->phy_id, TPM_DATA_FIFO,
430 buf + i, size);
431 if (ret < 0)
432 goto out_err;
433
434 i += size;
435 }
436
437 status = st33zp24_status(chip);
438 if ((status & TPM_STS_DATA_EXPECT) == 0) {
439 ret = -EIO;
440 goto out_err;
441 }
442
443 ret = tpm_dev->ops->send(tpm_dev->phy_id, TPM_DATA_FIFO,
444 buf + len - 1, 1);
445 if (ret < 0)
446 goto out_err;
447
448 status = st33zp24_status(chip);
449 if ((status & TPM_STS_DATA_EXPECT) != 0) {
450 ret = -EIO;
451 goto out_err;
452 }
453
454 data = TPM_STS_GO;
455 ret = tpm_dev->ops->send(tpm_dev->phy_id, TPM_STS, &data, 1);
456 if (ret < 0)
457 goto out_err;
458
459 return len;
460out_err:
461 st33zp24_cancel(chip);
462 release_locality(chip);
463 return ret;
464}
465
466/*
467 * st33zp24_recv received TPM response through TPM phy.
468 * @param: chip, the tpm_chip description as specified in driver/char/tpm/tpm.h.
469 * @param: buf, the buffer to store datas.
470 * @param: count, the number of bytes to send.
471 * @return: In case of success the number of bytes received.
472 * In other case, a < 0 value describing the issue.
473 */
474static int st33zp24_recv(struct tpm_chip *chip, unsigned char *buf,
475 size_t count)
476{
477 int size = 0;
478 int expected;
479
480 if (!chip)
481 return -EBUSY;
482
483 if (count < TPM_HEADER_SIZE) {
484 size = -EIO;
485 goto out;
486 }
487
488 size = recv_data(chip, buf, TPM_HEADER_SIZE);
489 if (size < TPM_HEADER_SIZE) {
490 dev_err(&chip->dev, "Unable to read header\n");
491 goto out;
492 }
493
494 expected = be32_to_cpu(*(__be32 *)(buf + 2));
495 if (expected > count) {
496 size = -EIO;
497 goto out;
498 }
499
500 size += recv_data(chip, &buf[TPM_HEADER_SIZE],
501 expected - TPM_HEADER_SIZE);
502 if (size < expected) {
503 dev_err(&chip->dev, "Unable to read remainder of result\n");
504 size = -ETIME;
505 }
506
507out:
508 st33zp24_cancel(chip);
509 release_locality(chip);
510 return size;
511}
512
513/*
514 * st33zp24_req_canceled
515 * @param: chip, the tpm_chip description as specified in driver/char/tpm/tpm.h.
516 * @param: status, the TPM status.
517 * @return: Does TPM ready to compute a new command ? true.
518 */
519static bool st33zp24_req_canceled(struct tpm_chip *chip, u8 status)
520{
521 return (status == TPM_STS_COMMAND_READY);
522}
523
524static const struct tpm_class_ops st33zp24_tpm = {
525 .send = st33zp24_send,
526 .recv = st33zp24_recv,
527 .cancel = st33zp24_cancel,
528 .status = st33zp24_status,
529 .req_complete_mask = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
530 .req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
531 .req_canceled = st33zp24_req_canceled,
532};
533
534/*
535 * st33zp24_probe initialize the TPM device
536 * @param: client, the i2c_client drescription (TPM I2C description).
537 * @param: id, the i2c_device_id struct.
538 * @return: 0 in case of success.
539 * -1 in other case.
540 */
541int st33zp24_probe(void *phy_id, const struct st33zp24_phy_ops *ops,
542 struct device *dev, int irq, int io_lpcpd)
543{
544 int ret;
545 u8 intmask = 0;
546 struct tpm_chip *chip;
547 struct st33zp24_dev *tpm_dev;
548
549 chip = tpmm_chip_alloc(dev, &st33zp24_tpm);
550 if (IS_ERR(chip))
551 return PTR_ERR(chip);
552
553 tpm_dev = devm_kzalloc(dev, sizeof(struct st33zp24_dev),
554 GFP_KERNEL);
555 if (!tpm_dev)
556 return -ENOMEM;
557
558 TPM_VPRIV(chip) = tpm_dev;
559 tpm_dev->phy_id = phy_id;
560 tpm_dev->ops = ops;
561
562 chip->vendor.timeout_a = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
563 chip->vendor.timeout_b = msecs_to_jiffies(TIS_LONG_TIMEOUT);
564 chip->vendor.timeout_c = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
565 chip->vendor.timeout_d = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
566
567 chip->vendor.locality = LOCALITY0;
568
569 if (irq) {
570 /* INTERRUPT Setup */
571 init_waitqueue_head(&chip->vendor.read_queue);
572 tpm_dev->intrs = 0;
573
574 if (request_locality(chip) != LOCALITY0) {
575 ret = -ENODEV;
576 goto _tpm_clean_answer;
577 }
578
579 clear_interruption(tpm_dev);
580 ret = devm_request_irq(dev, irq, tpm_ioserirq_handler,
581 IRQF_TRIGGER_HIGH, "TPM SERIRQ management",
582 chip);
583 if (ret < 0) {
584 dev_err(&chip->dev, "TPM SERIRQ signals %d not available\n",
585 irq);
586 goto _tpm_clean_answer;
587 }
588
589 intmask |= TPM_INTF_CMD_READY_INT
590 | TPM_INTF_STS_VALID_INT
591 | TPM_INTF_DATA_AVAIL_INT;
592
593 ret = tpm_dev->ops->send(tpm_dev->phy_id, TPM_INT_ENABLE,
594 &intmask, 1);
595 if (ret < 0)
596 goto _tpm_clean_answer;
597
598 intmask = TPM_GLOBAL_INT_ENABLE;
599 ret = tpm_dev->ops->send(tpm_dev->phy_id, (TPM_INT_ENABLE + 3),
600 &intmask, 1);
601 if (ret < 0)
602 goto _tpm_clean_answer;
603
604 chip->vendor.irq = irq;
605
606 disable_irq_nosync(chip->vendor.irq);
607
608 tpm_gen_interrupt(chip);
609 }
610
611 tpm_get_timeouts(chip);
612 tpm_do_selftest(chip);
613
614 return tpm_chip_register(chip);
615_tpm_clean_answer:
616 dev_info(&chip->dev, "TPM initialization fail\n");
617 return ret;
618}
619EXPORT_SYMBOL(st33zp24_probe);
620
621/*
622 * st33zp24_remove remove the TPM device
623 * @param: tpm_data, the tpm phy.
624 * @return: 0 in case of success.
625 */
626int st33zp24_remove(struct tpm_chip *chip)
627{
628 tpm_chip_unregister(chip);
629 return 0;
630}
631EXPORT_SYMBOL(st33zp24_remove);
632
633#ifdef CONFIG_PM_SLEEP
634/*
635 * st33zp24_pm_suspend suspend the TPM device
636 * @param: tpm_data, the tpm phy.
637 * @param: mesg, the power management message.
638 * @return: 0 in case of success.
639 */
640int st33zp24_pm_suspend(struct device *dev)
641{
642 struct tpm_chip *chip = dev_get_drvdata(dev);
643 struct st33zp24_dev *tpm_dev;
644 int ret = 0;
645
646 tpm_dev = (struct st33zp24_dev *)TPM_VPRIV(chip);
647
648 if (gpio_is_valid(tpm_dev->io_lpcpd))
649 gpio_set_value(tpm_dev->io_lpcpd, 0);
650 else
651 ret = tpm_pm_suspend(dev);
652
653 return ret;
654} /* st33zp24_pm_suspend() */
655EXPORT_SYMBOL(st33zp24_pm_suspend);
656
657/*
658 * st33zp24_pm_resume resume the TPM device
659 * @param: tpm_data, the tpm phy.
660 * @return: 0 in case of success.
661 */
662int st33zp24_pm_resume(struct device *dev)
663{
664 struct tpm_chip *chip = dev_get_drvdata(dev);
665 struct st33zp24_dev *tpm_dev;
666 int ret = 0;
667
668 tpm_dev = (struct st33zp24_dev *)TPM_VPRIV(chip);
669
670 if (gpio_is_valid(tpm_dev->io_lpcpd)) {
671 gpio_set_value(tpm_dev->io_lpcpd, 1);
672 ret = wait_for_stat(chip,
673 TPM_STS_VALID, chip->vendor.timeout_b,
674 &chip->vendor.read_queue, false);
675 } else {
676 ret = tpm_pm_resume(dev);
677 if (!ret)
678 tpm_do_selftest(chip);
679 }
680 return ret;
681} /* st33zp24_pm_resume() */
682EXPORT_SYMBOL(st33zp24_pm_resume);
683#endif
684
685MODULE_AUTHOR("TPM support (TPMsupport@list.st.com)");
686MODULE_DESCRIPTION("ST33ZP24 TPM 1.2 driver");
687MODULE_VERSION("1.3.0");
688MODULE_LICENSE("GPL");
diff --git a/drivers/char/tpm/st33zp24/st33zp24.h b/drivers/char/tpm/st33zp24/st33zp24.h
new file mode 100644
index 000000000000..43ad39a27f8d
--- /dev/null
+++ b/drivers/char/tpm/st33zp24/st33zp24.h
@@ -0,0 +1,34 @@
1/*
2 * STMicroelectronics TPM Linux driver for TPM ST33ZP24
3 * Copyright (C) 2009 - 2015 STMicroelectronics
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef __LOCAL_ST33ZP24_H__
19#define __LOCAL_ST33ZP24_H__
20
21struct st33zp24_phy_ops {
22 int (*send)(void *phy_id, u8 tpm_register, u8 *tpm_data, int tpm_size);
23 int (*recv)(void *phy_id, u8 tpm_register, u8 *tpm_data, int tpm_size);
24};
25
26#ifdef CONFIG_PM_SLEEP
27int st33zp24_pm_suspend(struct device *dev);
28int st33zp24_pm_resume(struct device *dev);
29#endif
30
31int st33zp24_probe(void *phy_id, const struct st33zp24_phy_ops *ops,
32 struct device *dev, int irq, int io_lpcpd);
33int st33zp24_remove(struct tpm_chip *chip);
34#endif /* __LOCAL_ST33ZP24_H__ */
diff --git a/drivers/char/tpm/tpm_i2c_stm_st33.c b/drivers/char/tpm/tpm_i2c_stm_st33.c
deleted file mode 100644
index 882c60a433fd..000000000000
--- a/drivers/char/tpm/tpm_i2c_stm_st33.c
+++ /dev/null
@@ -1,915 +0,0 @@
1/*
2 * STMicroelectronics TPM I2C Linux driver for TPM ST33ZP24
3 * Copyright (C) 2009, 2010, 2014 STMicroelectronics
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 *
18 * STMicroelectronics version 1.2.1, Copyright (C) 2014
19 * STMicroelectronics comes with ABSOLUTELY NO WARRANTY.
20 * This is free software, and you are welcome to redistribute it
21 * under certain conditions.
22 *
23 * @Author: Christophe RICARD tpmsupport@st.com
24 *
25 * @File: tpm_stm_st33_i2c.c
26 *
27 * @Synopsis:
28 * 09/15/2010: First shot driver tpm_tis driver for
29 * lpc is used as model.
30 */
31
32#include <linux/pci.h>
33#include <linux/module.h>
34#include <linux/platform_device.h>
35#include <linux/i2c.h>
36#include <linux/fs.h>
37#include <linux/miscdevice.h>
38#include <linux/kernel.h>
39#include <linux/delay.h>
40#include <linux/wait.h>
41#include <linux/freezer.h>
42#include <linux/string.h>
43#include <linux/interrupt.h>
44#include <linux/sysfs.h>
45#include <linux/gpio.h>
46#include <linux/sched.h>
47#include <linux/uaccess.h>
48#include <linux/io.h>
49#include <linux/slab.h>
50#include <linux/of_irq.h>
51#include <linux/of_gpio.h>
52
53#include <linux/platform_data/tpm_stm_st33.h>
54#include "tpm.h"
55
56#define TPM_ACCESS 0x0
57#define TPM_STS 0x18
58#define TPM_HASH_END 0x20
59#define TPM_DATA_FIFO 0x24
60#define TPM_HASH_DATA 0x24
61#define TPM_HASH_START 0x28
62#define TPM_INTF_CAPABILITY 0x14
63#define TPM_INT_STATUS 0x10
64#define TPM_INT_ENABLE 0x08
65
66#define TPM_DUMMY_BYTE 0xAA
67#define TPM_WRITE_DIRECTION 0x80
68#define TPM_HEADER_SIZE 10
69#define TPM_BUFSIZE 2048
70
71#define LOCALITY0 0
72
73
74enum stm33zp24_access {
75 TPM_ACCESS_VALID = 0x80,
76 TPM_ACCESS_ACTIVE_LOCALITY = 0x20,
77 TPM_ACCESS_REQUEST_PENDING = 0x04,
78 TPM_ACCESS_REQUEST_USE = 0x02,
79};
80
81enum stm33zp24_status {
82 TPM_STS_VALID = 0x80,
83 TPM_STS_COMMAND_READY = 0x40,
84 TPM_STS_GO = 0x20,
85 TPM_STS_DATA_AVAIL = 0x10,
86 TPM_STS_DATA_EXPECT = 0x08,
87};
88
89enum stm33zp24_int_flags {
90 TPM_GLOBAL_INT_ENABLE = 0x80,
91 TPM_INTF_CMD_READY_INT = 0x080,
92 TPM_INTF_FIFO_AVALAIBLE_INT = 0x040,
93 TPM_INTF_WAKE_UP_READY_INT = 0x020,
94 TPM_INTF_LOCALITY_CHANGE_INT = 0x004,
95 TPM_INTF_STS_VALID_INT = 0x002,
96 TPM_INTF_DATA_AVAIL_INT = 0x001,
97};
98
99enum tis_defaults {
100 TIS_SHORT_TIMEOUT = 750,
101 TIS_LONG_TIMEOUT = 2000,
102};
103
104struct tpm_stm_dev {
105 struct i2c_client *client;
106 struct tpm_chip *chip;
107 u8 buf[TPM_BUFSIZE + 1];
108 u32 intrs;
109 int io_lpcpd;
110};
111
112/*
113 * write8_reg
114 * Send byte to the TIS register according to the ST33ZP24 I2C protocol.
115 * @param: tpm_register, the tpm tis register where the data should be written
116 * @param: tpm_data, the tpm_data to write inside the tpm_register
117 * @param: tpm_size, The length of the data
118 * @return: Returns negative errno, or else the number of bytes written.
119 */
120static int write8_reg(struct tpm_stm_dev *tpm_dev, u8 tpm_register,
121 u8 *tpm_data, u16 tpm_size)
122{
123 tpm_dev->buf[0] = tpm_register;
124 memcpy(tpm_dev->buf + 1, tpm_data, tpm_size);
125 return i2c_master_send(tpm_dev->client, tpm_dev->buf, tpm_size + 1);
126} /* write8_reg() */
127
128/*
129 * read8_reg
130 * Recv byte from the TIS register according to the ST33ZP24 I2C protocol.
131 * @param: tpm_register, the tpm tis register where the data should be read
132 * @param: tpm_data, the TPM response
133 * @param: tpm_size, tpm TPM response size to read.
134 * @return: number of byte read successfully: should be one if success.
135 */
136static int read8_reg(struct tpm_stm_dev *tpm_dev, u8 tpm_register,
137 u8 *tpm_data, int tpm_size)
138{
139 u8 status = 0;
140 u8 data;
141
142 data = TPM_DUMMY_BYTE;
143 status = write8_reg(tpm_dev, tpm_register, &data, 1);
144 if (status == 2)
145 status = i2c_master_recv(tpm_dev->client, tpm_data, tpm_size);
146 return status;
147} /* read8_reg() */
148
149/*
150 * I2C_WRITE_DATA
151 * Send byte to the TIS register according to the ST33ZP24 I2C protocol.
152 * @param: tpm_dev, the chip description
153 * @param: tpm_register, the tpm tis register where the data should be written
154 * @param: tpm_data, the tpm_data to write inside the tpm_register
155 * @param: tpm_size, The length of the data
156 * @return: number of byte written successfully: should be one if success.
157 */
158#define I2C_WRITE_DATA(tpm_dev, tpm_register, tpm_data, tpm_size) \
159 (write8_reg(tpm_dev, tpm_register | \
160 TPM_WRITE_DIRECTION, tpm_data, tpm_size))
161
162/*
163 * I2C_READ_DATA
164 * Recv byte from the TIS register according to the ST33ZP24 I2C protocol.
165 * @param: tpm_dev, the chip description
166 * @param: tpm_register, the tpm tis register where the data should be read
167 * @param: tpm_data, the TPM response
168 * @param: tpm_size, tpm TPM response size to read.
169 * @return: number of byte read successfully: should be one if success.
170 */
171#define I2C_READ_DATA(tpm_dev, tpm_register, tpm_data, tpm_size) \
172 (read8_reg(tpm_dev, tpm_register, tpm_data, tpm_size))
173
174/*
175 * clear_interruption
176 * clear the TPM interrupt register.
177 * @param: tpm, the chip description
178 * @return: the TPM_INT_STATUS value
179 */
180static u8 clear_interruption(struct tpm_stm_dev *tpm_dev)
181{
182 u8 interrupt;
183
184 I2C_READ_DATA(tpm_dev, TPM_INT_STATUS, &interrupt, 1);
185 I2C_WRITE_DATA(tpm_dev, TPM_INT_STATUS, &interrupt, 1);
186 return interrupt;
187} /* clear_interruption() */
188
189/*
190 * tpm_stm_i2c_cancel, cancel is not implemented.
191 * @param: chip, the tpm_chip description as specified in driver/char/tpm/tpm.h
192 */
193static void tpm_stm_i2c_cancel(struct tpm_chip *chip)
194{
195 struct tpm_stm_dev *tpm_dev;
196 u8 data;
197
198 tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip);
199
200 data = TPM_STS_COMMAND_READY;
201 I2C_WRITE_DATA(tpm_dev, TPM_STS, &data, 1);
202} /* tpm_stm_i2c_cancel() */
203
204/*
205 * tpm_stm_spi_status return the TPM_STS register
206 * @param: chip, the tpm chip description
207 * @return: the TPM_STS register value.
208 */
209static u8 tpm_stm_i2c_status(struct tpm_chip *chip)
210{
211 struct tpm_stm_dev *tpm_dev;
212 u8 data;
213
214 tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip);
215
216 I2C_READ_DATA(tpm_dev, TPM_STS, &data, 1);
217 return data;
218} /* tpm_stm_i2c_status() */
219
220
221/*
222 * check_locality if the locality is active
223 * @param: chip, the tpm chip description
224 * @return: the active locality or -EACCESS.
225 */
226static int check_locality(struct tpm_chip *chip)
227{
228 struct tpm_stm_dev *tpm_dev;
229 u8 data;
230 u8 status;
231
232 tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip);
233
234 status = I2C_READ_DATA(tpm_dev, TPM_ACCESS, &data, 1);
235 if (status && (data &
236 (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) ==
237 (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID))
238 return chip->vendor.locality;
239
240 return -EACCES;
241} /* check_locality() */
242
243/*
244 * request_locality request the TPM locality
245 * @param: chip, the chip description
246 * @return: the active locality or EACCESS.
247 */
248static int request_locality(struct tpm_chip *chip)
249{
250 unsigned long stop;
251 long ret;
252 struct tpm_stm_dev *tpm_dev;
253 u8 data;
254
255 if (check_locality(chip) == chip->vendor.locality)
256 return chip->vendor.locality;
257
258 tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip);
259
260 data = TPM_ACCESS_REQUEST_USE;
261 ret = I2C_WRITE_DATA(tpm_dev, TPM_ACCESS, &data, 1);
262 if (ret < 0)
263 goto end;
264
265 stop = jiffies + chip->vendor.timeout_a;
266
267 /* Request locality is usually effective after the request */
268 do {
269 if (check_locality(chip) >= 0)
270 return chip->vendor.locality;
271 msleep(TPM_TIMEOUT);
272 } while (time_before(jiffies, stop));
273 ret = -EACCES;
274end:
275 return ret;
276} /* request_locality() */
277
278/*
279 * release_locality release the active locality
280 * @param: chip, the tpm chip description.
281 */
282static void release_locality(struct tpm_chip *chip)
283{
284 struct tpm_stm_dev *tpm_dev;
285 u8 data;
286
287 tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip);
288 data = TPM_ACCESS_ACTIVE_LOCALITY;
289
290 I2C_WRITE_DATA(tpm_dev, TPM_ACCESS, &data, 1);
291}
292
293/*
294 * get_burstcount return the burstcount address 0x19 0x1A
295 * @param: chip, the chip description
296 * return: the burstcount.
297 */
298static int get_burstcount(struct tpm_chip *chip)
299{
300 unsigned long stop;
301 int burstcnt, status;
302 u8 tpm_reg, temp;
303 struct tpm_stm_dev *tpm_dev;
304
305 tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip);
306
307 stop = jiffies + chip->vendor.timeout_d;
308 do {
309 tpm_reg = TPM_STS + 1;
310 status = I2C_READ_DATA(tpm_dev, tpm_reg, &temp, 1);
311 if (status < 0)
312 goto end;
313
314 tpm_reg = tpm_reg + 1;
315 burstcnt = temp;
316 status = I2C_READ_DATA(tpm_dev, tpm_reg, &temp, 1);
317 if (status < 0)
318 goto end;
319
320 burstcnt |= temp << 8;
321 if (burstcnt)
322 return burstcnt;
323 msleep(TPM_TIMEOUT);
324 } while (time_before(jiffies, stop));
325
326end:
327 return -EBUSY;
328} /* get_burstcount() */
329
330static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
331 bool check_cancel, bool *canceled)
332{
333 u8 status = chip->ops->status(chip);
334
335 *canceled = false;
336 if ((status & mask) == mask)
337 return true;
338 if (check_cancel && chip->ops->req_canceled(chip, status)) {
339 *canceled = true;
340 return true;
341 }
342 return false;
343}
344
345/*
346 * interrupt_to_status
347 * @param: irq_mask, the irq mask value to wait
348 * @return: the corresponding tpm_sts value
349 */
350static u8 interrupt_to_status(u8 irq_mask)
351{
352 u8 status = 0;
353
354 if ((irq_mask & TPM_INTF_STS_VALID_INT) == TPM_INTF_STS_VALID_INT)
355 status |= TPM_STS_VALID;
356 if ((irq_mask & TPM_INTF_DATA_AVAIL_INT) == TPM_INTF_DATA_AVAIL_INT)
357 status |= TPM_STS_DATA_AVAIL;
358 if ((irq_mask & TPM_INTF_CMD_READY_INT) == TPM_INTF_CMD_READY_INT)
359 status |= TPM_STS_COMMAND_READY;
360
361 return status;
362} /* status_to_interrupt() */
363
364/*
365 * wait_for_stat wait for a TPM_STS value
366 * @param: chip, the tpm chip description
367 * @param: mask, the value mask to wait
368 * @param: timeout, the timeout
369 * @param: queue, the wait queue.
370 * @param: check_cancel, does the command can be cancelled ?
371 * @return: the tpm status, 0 if success, -ETIME if timeout is reached.
372 */
373static int wait_for_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
374 wait_queue_head_t *queue, bool check_cancel)
375{
376 unsigned long stop;
377 int ret;
378 bool canceled = false;
379 bool condition;
380 u32 cur_intrs;
381 u8 interrupt, status;
382 struct tpm_stm_dev *tpm_dev;
383
384 tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip);
385
386 /* check current status */
387 status = tpm_stm_i2c_status(chip);
388 if ((status & mask) == mask)
389 return 0;
390
391 stop = jiffies + timeout;
392
393 if (chip->vendor.irq) {
394 cur_intrs = tpm_dev->intrs;
395 interrupt = clear_interruption(tpm_dev);
396 enable_irq(chip->vendor.irq);
397
398again:
399 timeout = stop - jiffies;
400 if ((long) timeout <= 0)
401 return -1;
402
403 ret = wait_event_interruptible_timeout(*queue,
404 cur_intrs != tpm_dev->intrs, timeout);
405
406 interrupt |= clear_interruption(tpm_dev);
407 status = interrupt_to_status(interrupt);
408 condition = wait_for_tpm_stat_cond(chip, mask,
409 check_cancel, &canceled);
410
411 if (ret >= 0 && condition) {
412 if (canceled)
413 return -ECANCELED;
414 return 0;
415 }
416 if (ret == -ERESTARTSYS && freezing(current)) {
417 clear_thread_flag(TIF_SIGPENDING);
418 goto again;
419 }
420 disable_irq_nosync(chip->vendor.irq);
421
422 } else {
423 do {
424 msleep(TPM_TIMEOUT);
425 status = chip->ops->status(chip);
426 if ((status & mask) == mask)
427 return 0;
428 } while (time_before(jiffies, stop));
429 }
430
431 return -ETIME;
432} /* wait_for_stat() */
433
434/*
435 * recv_data receive data
436 * @param: chip, the tpm chip description
437 * @param: buf, the buffer where the data are received
438 * @param: count, the number of data to receive
439 * @return: the number of bytes read from TPM FIFO.
440 */
441static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count)
442{
443 int size = 0, burstcnt, len, ret;
444 struct tpm_stm_dev *tpm_dev;
445
446 tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip);
447
448 while (size < count &&
449 wait_for_stat(chip,
450 TPM_STS_DATA_AVAIL | TPM_STS_VALID,
451 chip->vendor.timeout_c,
452 &chip->vendor.read_queue, true) == 0) {
453 burstcnt = get_burstcount(chip);
454 if (burstcnt < 0)
455 return burstcnt;
456 len = min_t(int, burstcnt, count - size);
457 ret = I2C_READ_DATA(tpm_dev, TPM_DATA_FIFO, buf + size, len);
458 if (ret < 0)
459 return ret;
460
461 size += len;
462 }
463 return size;
464}
465
466/*
467 * tpm_ioserirq_handler the serirq irq handler
468 * @param: irq, the tpm chip description
469 * @param: dev_id, the description of the chip
470 * @return: the status of the handler.
471 */
472static irqreturn_t tpm_ioserirq_handler(int irq, void *dev_id)
473{
474 struct tpm_chip *chip = dev_id;
475 struct tpm_stm_dev *tpm_dev;
476
477 tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip);
478
479 tpm_dev->intrs++;
480 wake_up_interruptible(&chip->vendor.read_queue);
481 disable_irq_nosync(chip->vendor.irq);
482
483 return IRQ_HANDLED;
484} /* tpm_ioserirq_handler() */
485
486
487/*
488 * tpm_stm_i2c_send send TPM commands through the I2C bus.
489 *
490 * @param: chip, the tpm_chip description as specified in driver/char/tpm/tpm.h
491 * @param: buf, the buffer to send.
492 * @param: count, the number of bytes to send.
493 * @return: In case of success the number of bytes sent.
494 * In other case, a < 0 value describing the issue.
495 */
496static int tpm_stm_i2c_send(struct tpm_chip *chip, unsigned char *buf,
497 size_t len)
498{
499 u32 status, i, size;
500 int burstcnt = 0;
501 int ret;
502 u8 data;
503 struct i2c_client *client;
504 struct tpm_stm_dev *tpm_dev;
505
506 if (!chip)
507 return -EBUSY;
508 if (len < TPM_HEADER_SIZE)
509 return -EBUSY;
510
511 tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip);
512 client = tpm_dev->client;
513
514 client->flags = 0;
515
516 ret = request_locality(chip);
517 if (ret < 0)
518 return ret;
519
520 status = tpm_stm_i2c_status(chip);
521 if ((status & TPM_STS_COMMAND_READY) == 0) {
522 tpm_stm_i2c_cancel(chip);
523 if (wait_for_stat
524 (chip, TPM_STS_COMMAND_READY, chip->vendor.timeout_b,
525 &chip->vendor.read_queue, false) < 0) {
526 ret = -ETIME;
527 goto out_err;
528 }
529 }
530
531 for (i = 0; i < len - 1;) {
532 burstcnt = get_burstcount(chip);
533 if (burstcnt < 0)
534 return burstcnt;
535 size = min_t(int, len - i - 1, burstcnt);
536 ret = I2C_WRITE_DATA(tpm_dev, TPM_DATA_FIFO, buf + i, size);
537 if (ret < 0)
538 goto out_err;
539
540 i += size;
541 }
542
543 status = tpm_stm_i2c_status(chip);
544 if ((status & TPM_STS_DATA_EXPECT) == 0) {
545 ret = -EIO;
546 goto out_err;
547 }
548
549 ret = I2C_WRITE_DATA(tpm_dev, TPM_DATA_FIFO, buf + len - 1, 1);
550 if (ret < 0)
551 goto out_err;
552
553 status = tpm_stm_i2c_status(chip);
554 if ((status & TPM_STS_DATA_EXPECT) != 0) {
555 ret = -EIO;
556 goto out_err;
557 }
558
559 data = TPM_STS_GO;
560 I2C_WRITE_DATA(tpm_dev, TPM_STS, &data, 1);
561
562 return len;
563out_err:
564 tpm_stm_i2c_cancel(chip);
565 release_locality(chip);
566 return ret;
567}
568
569/*
570 * tpm_stm_i2c_recv received TPM response through the I2C bus.
571 * @param: chip, the tpm_chip description as specified in driver/char/tpm/tpm.h.
572 * @param: buf, the buffer to store datas.
573 * @param: count, the number of bytes to send.
574 * @return: In case of success the number of bytes received.
575 * In other case, a < 0 value describing the issue.
576 */
577static int tpm_stm_i2c_recv(struct tpm_chip *chip, unsigned char *buf,
578 size_t count)
579{
580 int size = 0;
581 int expected;
582
583 if (!chip)
584 return -EBUSY;
585
586 if (count < TPM_HEADER_SIZE) {
587 size = -EIO;
588 goto out;
589 }
590
591 size = recv_data(chip, buf, TPM_HEADER_SIZE);
592 if (size < TPM_HEADER_SIZE) {
593 dev_err(chip->pdev, "Unable to read header\n");
594 goto out;
595 }
596
597 expected = be32_to_cpu(*(__be32 *)(buf + 2));
598 if (expected > count) {
599 size = -EIO;
600 goto out;
601 }
602
603 size += recv_data(chip, &buf[TPM_HEADER_SIZE],
604 expected - TPM_HEADER_SIZE);
605 if (size < expected) {
606 dev_err(chip->pdev, "Unable to read remainder of result\n");
607 size = -ETIME;
608 goto out;
609 }
610
611out:
612 chip->ops->cancel(chip);
613 release_locality(chip);
614 return size;
615}
616
617static bool tpm_stm_i2c_req_canceled(struct tpm_chip *chip, u8 status)
618{
619 return (status == TPM_STS_COMMAND_READY);
620}
621
622static const struct tpm_class_ops st_i2c_tpm = {
623 .send = tpm_stm_i2c_send,
624 .recv = tpm_stm_i2c_recv,
625 .cancel = tpm_stm_i2c_cancel,
626 .status = tpm_stm_i2c_status,
627 .req_complete_mask = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
628 .req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
629 .req_canceled = tpm_stm_i2c_req_canceled,
630};
631
632#ifdef CONFIG_OF
633static int tpm_stm_i2c_of_request_resources(struct tpm_chip *chip)
634{
635 struct device_node *pp;
636 struct tpm_stm_dev *tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip);
637 struct i2c_client *client = tpm_dev->client;
638 int gpio;
639 int ret;
640
641 pp = client->dev.of_node;
642 if (!pp) {
643 dev_err(chip->pdev, "No platform data\n");
644 return -ENODEV;
645 }
646
647 /* Get GPIO from device tree */
648 gpio = of_get_named_gpio(pp, "lpcpd-gpios", 0);
649 if (gpio < 0) {
650 dev_err(chip->pdev, "Failed to retrieve lpcpd-gpios from dts.\n");
651 tpm_dev->io_lpcpd = -1;
652 /*
653 * lpcpd pin is not specified. This is not an issue as
654 * power management can be also managed by TPM specific
655 * commands. So leave with a success status code.
656 */
657 return 0;
658 }
659 /* GPIO request and configuration */
660 ret = devm_gpio_request_one(&client->dev, gpio,
661 GPIOF_OUT_INIT_HIGH, "TPM IO LPCPD");
662 if (ret) {
663 dev_err(chip->pdev, "Failed to request lpcpd pin\n");
664 return -ENODEV;
665 }
666 tpm_dev->io_lpcpd = gpio;
667
668 return 0;
669}
670#else
671static int tpm_stm_i2c_of_request_resources(struct tpm_chip *chip)
672{
673 return -ENODEV;
674}
675#endif
676
677static int tpm_stm_i2c_request_resources(struct i2c_client *client,
678 struct tpm_chip *chip)
679{
680 struct st33zp24_platform_data *pdata;
681 struct tpm_stm_dev *tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip);
682 int ret;
683
684 pdata = client->dev.platform_data;
685 if (!pdata) {
686 dev_err(chip->pdev, "No platform data\n");
687 return -ENODEV;
688 }
689
690 /* store for late use */
691 tpm_dev->io_lpcpd = pdata->io_lpcpd;
692
693 if (gpio_is_valid(pdata->io_lpcpd)) {
694 ret = devm_gpio_request_one(&client->dev,
695 pdata->io_lpcpd, GPIOF_OUT_INIT_HIGH,
696 "TPM IO_LPCPD");
697 if (ret) {
698 dev_err(chip->pdev, "%s : reset gpio_request failed\n",
699 __FILE__);
700 return ret;
701 }
702 }
703
704 return 0;
705}
706
707/*
708 * tpm_stm_i2c_probe initialize the TPM device
709 * @param: client, the i2c_client drescription (TPM I2C description).
710 * @param: id, the i2c_device_id struct.
711 * @return: 0 in case of success.
712 * -1 in other case.
713 */
714static int
715tpm_stm_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
716{
717 int ret;
718 u8 intmask = 0;
719 struct tpm_chip *chip;
720 struct st33zp24_platform_data *platform_data;
721 struct tpm_stm_dev *tpm_dev;
722
723 if (!client) {
724 pr_info("%s: i2c client is NULL. Device not accessible.\n",
725 __func__);
726 return -ENODEV;
727 }
728
729 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
730 dev_info(&client->dev, "client not i2c capable\n");
731 return -ENODEV;
732 }
733
734 tpm_dev = devm_kzalloc(&client->dev, sizeof(struct tpm_stm_dev),
735 GFP_KERNEL);
736 if (!tpm_dev)
737 return -ENOMEM;
738
739 chip = tpmm_chip_alloc(&client->dev, &st_i2c_tpm);
740 if (IS_ERR(chip))
741 return PTR_ERR(chip);
742
743 TPM_VPRIV(chip) = tpm_dev;
744 tpm_dev->client = client;
745
746 platform_data = client->dev.platform_data;
747 if (!platform_data && client->dev.of_node) {
748 ret = tpm_stm_i2c_of_request_resources(chip);
749 if (ret)
750 goto _tpm_clean_answer;
751 } else if (platform_data) {
752 ret = tpm_stm_i2c_request_resources(client, chip);
753 if (ret)
754 goto _tpm_clean_answer;
755 }
756
757 chip->vendor.timeout_a = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
758 chip->vendor.timeout_b = msecs_to_jiffies(TIS_LONG_TIMEOUT);
759 chip->vendor.timeout_c = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
760 chip->vendor.timeout_d = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
761
762 chip->vendor.locality = LOCALITY0;
763
764 if (client->irq) {
765 /* INTERRUPT Setup */
766 init_waitqueue_head(&chip->vendor.read_queue);
767 tpm_dev->intrs = 0;
768
769 if (request_locality(chip) != LOCALITY0) {
770 ret = -ENODEV;
771 goto _tpm_clean_answer;
772 }
773
774 clear_interruption(tpm_dev);
775 ret = devm_request_irq(&client->dev, client->irq,
776 tpm_ioserirq_handler,
777 IRQF_TRIGGER_HIGH,
778 "TPM SERIRQ management", chip);
779 if (ret < 0) {
780 dev_err(chip->pdev, "TPM SERIRQ signals %d not available\n",
781 client->irq);
782 goto _tpm_clean_answer;
783 }
784
785 intmask |= TPM_INTF_CMD_READY_INT
786 | TPM_INTF_STS_VALID_INT
787 | TPM_INTF_DATA_AVAIL_INT;
788
789 ret = I2C_WRITE_DATA(tpm_dev, TPM_INT_ENABLE, &intmask, 1);
790 if (ret < 0)
791 goto _tpm_clean_answer;
792
793 intmask = TPM_GLOBAL_INT_ENABLE;
794 ret = I2C_WRITE_DATA(tpm_dev, (TPM_INT_ENABLE + 3),
795 &intmask, 1);
796 if (ret < 0)
797 goto _tpm_clean_answer;
798
799 chip->vendor.irq = client->irq;
800
801 disable_irq_nosync(chip->vendor.irq);
802
803 tpm_gen_interrupt(chip);
804 }
805
806 tpm_get_timeouts(chip);
807 tpm_do_selftest(chip);
808
809 return tpm_chip_register(chip);
810_tpm_clean_answer:
811 dev_info(chip->pdev, "TPM I2C initialisation fail\n");
812 return ret;
813}
814
815/*
816 * tpm_stm_i2c_remove remove the TPM device
817 * @param: client, the i2c_client description (TPM I2C description).
818 * @return: 0 in case of success.
819 */
820static int tpm_stm_i2c_remove(struct i2c_client *client)
821{
822 struct tpm_chip *chip =
823 (struct tpm_chip *) i2c_get_clientdata(client);
824
825 if (chip)
826 tpm_chip_unregister(chip);
827
828 return 0;
829}
830
831#ifdef CONFIG_PM_SLEEP
832/*
833 * tpm_stm_i2c_pm_suspend suspend the TPM device
834 * @param: client, the i2c_client drescription (TPM I2C description).
835 * @param: mesg, the power management message.
836 * @return: 0 in case of success.
837 */
838static int tpm_stm_i2c_pm_suspend(struct device *dev)
839{
840 struct tpm_chip *chip = dev_get_drvdata(dev);
841 struct tpm_stm_dev *tpm_dev;
842 int ret = 0;
843
844 tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip);
845
846 if (gpio_is_valid(tpm_dev->io_lpcpd))
847 gpio_set_value(tpm_dev->io_lpcpd, 0);
848 else
849 ret = tpm_pm_suspend(dev);
850
851 return ret;
852} /* tpm_stm_i2c_suspend() */
853
854/*
855 * tpm_stm_i2c_pm_resume resume the TPM device
856 * @param: client, the i2c_client drescription (TPM I2C description).
857 * @return: 0 in case of success.
858 */
859static int tpm_stm_i2c_pm_resume(struct device *dev)
860{
861 struct tpm_chip *chip = dev_get_drvdata(dev);
862 struct tpm_stm_dev *tpm_dev;
863 int ret = 0;
864
865 tpm_dev = (struct tpm_stm_dev *)TPM_VPRIV(chip);
866
867 if (gpio_is_valid(tpm_dev->io_lpcpd)) {
868 gpio_set_value(tpm_dev->io_lpcpd, 1);
869 ret = wait_for_stat(chip,
870 TPM_STS_VALID, chip->vendor.timeout_b,
871 &chip->vendor.read_queue, false);
872 } else {
873 ret = tpm_pm_resume(dev);
874 if (!ret)
875 tpm_do_selftest(chip);
876 }
877 return ret;
878} /* tpm_stm_i2c_pm_resume() */
879#endif
880
881static const struct i2c_device_id tpm_stm_i2c_id[] = {
882 {TPM_ST33_I2C, 0},
883 {}
884};
885MODULE_DEVICE_TABLE(i2c, tpm_stm_i2c_id);
886
887#ifdef CONFIG_OF
888static const struct of_device_id of_st33zp24_i2c_match[] = {
889 { .compatible = "st,st33zp24-i2c", },
890 {}
891};
892MODULE_DEVICE_TABLE(of, of_st33zp24_i2c_match);
893#endif
894
895static SIMPLE_DEV_PM_OPS(tpm_stm_i2c_ops, tpm_stm_i2c_pm_suspend,
896 tpm_stm_i2c_pm_resume);
897
898static struct i2c_driver tpm_stm_i2c_driver = {
899 .driver = {
900 .owner = THIS_MODULE,
901 .name = TPM_ST33_I2C,
902 .pm = &tpm_stm_i2c_ops,
903 .of_match_table = of_match_ptr(of_st33zp24_i2c_match),
904 },
905 .probe = tpm_stm_i2c_probe,
906 .remove = tpm_stm_i2c_remove,
907 .id_table = tpm_stm_i2c_id
908};
909
910module_i2c_driver(tpm_stm_i2c_driver);
911
912MODULE_AUTHOR("Christophe Ricard (tpmsupport@st.com)");
913MODULE_DESCRIPTION("STM TPM I2C ST33 Driver");
914MODULE_VERSION("1.2.1");
915MODULE_LICENSE("GPL");
diff --git a/include/linux/platform_data/tpm_stm_st33.h b/include/linux/platform_data/st33zp24.h
index ff75310c0f47..817dfdb37885 100644
--- a/include/linux/platform_data/tpm_stm_st33.h
+++ b/include/linux/platform_data/st33zp24.h
@@ -1,6 +1,6 @@
1/* 1/*
2 * STMicroelectronics TPM I2C Linux driver for TPM ST33ZP24 2 * STMicroelectronics TPM Linux driver for TPM 1.2 ST33ZP24
3 * Copyright (C) 2009, 2010 STMicroelectronics 3 * Copyright (C) 2009 - 2015 STMicroelectronics
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by 6 * it under the terms of the GNU General Public License as published by
@@ -14,20 +14,9 @@
14 * 14 *
15 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>. 16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 *
18 * STMicroelectronics version 1.2.0, Copyright (C) 2010
19 * STMicroelectronics comes with ABSOLUTELY NO WARRANTY.
20 * This is free software, and you are welcome to redistribute it
21 * under certain conditions.
22 *
23 * @Author: Christophe RICARD tpmsupport@st.com
24 *
25 * @File: stm_st33_tpm.h
26 *
27 * @Date: 09/15/2010
28 */ 17 */
29#ifndef __STM_ST33_TPM_H__ 18#ifndef __ST33ZP24_H__
30#define __STM_ST33_TPM_H__ 19#define __ST33ZP24_H__
31 20
32#define TPM_ST33_I2C "st33zp24-i2c" 21#define TPM_ST33_I2C "st33zp24-i2c"
33#define TPM_ST33_SPI "st33zp24-spi" 22#define TPM_ST33_SPI "st33zp24-spi"
@@ -36,4 +25,4 @@ struct st33zp24_platform_data {
36 int io_lpcpd; 25 int io_lpcpd;
37}; 26};
38 27
39#endif /* __STM_ST33_TPM_H__ */ 28#endif /* __ST33ZP24_H__ */