Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 1 | /* |
| 2 | * STMicroelectronics TPM SPI Linux driver for TPM ST33ZP24 |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 3 | * Copyright (C) 2009 - 2015 STMicroelectronics |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 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/spi/spi.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_DATA_FIFO 0x24 |
| 30 | #define TPM_INTF_CAPABILITY 0x14 |
| 31 | |
| 32 | #define TPM_DUMMY_BYTE 0x00 |
| 33 | |
| 34 | #define MAX_SPI_LATENCY 15 |
| 35 | #define LOCALITY0 0 |
| 36 | |
| 37 | #define ST33ZP24_OK 0x5A |
| 38 | #define ST33ZP24_UNDEFINED_ERR 0x80 |
| 39 | #define ST33ZP24_BADLOCALITY 0x81 |
| 40 | #define ST33ZP24_TISREGISTER_UKNOWN 0x82 |
| 41 | #define ST33ZP24_LOCALITY_NOT_ACTIVATED 0x83 |
| 42 | #define ST33ZP24_HASH_END_BEFORE_HASH_START 0x84 |
| 43 | #define ST33ZP24_BAD_COMMAND_ORDER 0x85 |
| 44 | #define ST33ZP24_INCORECT_RECEIVED_LENGTH 0x86 |
| 45 | #define ST33ZP24_TPM_FIFO_OVERFLOW 0x89 |
| 46 | #define ST33ZP24_UNEXPECTED_READ_FIFO 0x8A |
| 47 | #define ST33ZP24_UNEXPECTED_WRITE_FIFO 0x8B |
| 48 | #define ST33ZP24_CMDRDY_SET_WHEN_PROCESSING_HASH_END 0x90 |
| 49 | #define ST33ZP24_DUMMY_BYTES 0x00 |
| 50 | |
| 51 | /* |
| 52 | * TPM command can be up to 2048 byte, A TPM response can be up to |
| 53 | * 1024 byte. |
| 54 | * Between command and response, there are latency byte (up to 15 |
| 55 | * usually on st33zp24 2 are enough). |
| 56 | * |
| 57 | * Overall when sending a command and expecting an answer we need if |
| 58 | * worst case: |
| 59 | * 2048 (for the TPM command) + 1024 (for the TPM answer). We need |
| 60 | * some latency byte before the answer is available (max 15). |
| 61 | * We have 2048 + 1024 + 15. |
| 62 | */ |
| 63 | #define ST33ZP24_SPI_BUFFER_SIZE (TPM_BUFSIZE + (TPM_BUFSIZE / 2) +\ |
| 64 | MAX_SPI_LATENCY) |
| 65 | |
| 66 | |
| 67 | struct st33zp24_spi_phy { |
| 68 | struct spi_device *spi_device; |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 69 | struct spi_transfer spi_xfer; |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 70 | u8 tx_buf[ST33ZP24_SPI_BUFFER_SIZE]; |
| 71 | u8 rx_buf[ST33ZP24_SPI_BUFFER_SIZE]; |
| 72 | |
| 73 | int io_lpcpd; |
| 74 | int latency; |
| 75 | }; |
| 76 | |
| 77 | static int st33zp24_status_to_errno(u8 code) |
| 78 | { |
| 79 | switch (code) { |
| 80 | case ST33ZP24_OK: |
| 81 | return 0; |
| 82 | case ST33ZP24_UNDEFINED_ERR: |
| 83 | case ST33ZP24_BADLOCALITY: |
| 84 | case ST33ZP24_TISREGISTER_UKNOWN: |
| 85 | case ST33ZP24_LOCALITY_NOT_ACTIVATED: |
| 86 | case ST33ZP24_HASH_END_BEFORE_HASH_START: |
| 87 | case ST33ZP24_BAD_COMMAND_ORDER: |
| 88 | case ST33ZP24_UNEXPECTED_READ_FIFO: |
| 89 | case ST33ZP24_UNEXPECTED_WRITE_FIFO: |
| 90 | case ST33ZP24_CMDRDY_SET_WHEN_PROCESSING_HASH_END: |
| 91 | return -EPROTO; |
| 92 | case ST33ZP24_INCORECT_RECEIVED_LENGTH: |
| 93 | case ST33ZP24_TPM_FIFO_OVERFLOW: |
| 94 | return -EMSGSIZE; |
| 95 | case ST33ZP24_DUMMY_BYTES: |
| 96 | return -ENOSYS; |
| 97 | } |
| 98 | return code; |
| 99 | } |
| 100 | |
| 101 | /* |
| 102 | * st33zp24_spi_send |
| 103 | * Send byte to the TIS register according to the ST33ZP24 SPI protocol. |
| 104 | * @param: phy_id, the phy description |
| 105 | * @param: tpm_register, the tpm tis register where the data should be written |
| 106 | * @param: tpm_data, the tpm_data to write inside the tpm_register |
| 107 | * @param: tpm_size, The length of the data |
| 108 | * @return: should be zero if success else a negative error code. |
| 109 | */ |
| 110 | static int st33zp24_spi_send(void *phy_id, u8 tpm_register, u8 *tpm_data, |
| 111 | int tpm_size) |
| 112 | { |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 113 | u8 data = 0; |
Christophe RICARD | 9feaab5 | 2016-02-13 16:15:24 +0100 | [diff] [blame] | 114 | int total_length = 0, ret = 0; |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 115 | struct st33zp24_spi_phy *phy = phy_id; |
| 116 | struct spi_device *dev = phy->spi_device; |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 117 | u8 *tx_buf = (u8 *)phy->spi_xfer.tx_buf; |
| 118 | u8 *rx_buf = phy->spi_xfer.rx_buf; |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 119 | |
| 120 | /* Pre-Header */ |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 121 | data = TPM_WRITE_DIRECTION | LOCALITY0; |
| 122 | memcpy(tx_buf + total_length, &data, sizeof(data)); |
| 123 | total_length++; |
| 124 | data = tpm_register; |
| 125 | memcpy(tx_buf + total_length, &data, sizeof(data)); |
| 126 | total_length++; |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 127 | |
| 128 | if (tpm_size > 0 && tpm_register == TPM_DATA_FIFO) { |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 129 | tx_buf[total_length++] = tpm_size >> 8; |
| 130 | tx_buf[total_length++] = tpm_size; |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 131 | } |
| 132 | |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 133 | memcpy(&tx_buf[total_length], tpm_data, tpm_size); |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 134 | total_length += tpm_size; |
| 135 | |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 136 | memset(&tx_buf[total_length], TPM_DUMMY_BYTE, phy->latency); |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 137 | |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 138 | phy->spi_xfer.len = total_length + phy->latency; |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 139 | |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 140 | ret = spi_sync_transfer(dev, &phy->spi_xfer, 1); |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 141 | if (ret == 0) |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 142 | ret = rx_buf[total_length + phy->latency - 1]; |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 143 | |
| 144 | return st33zp24_status_to_errno(ret); |
| 145 | } /* st33zp24_spi_send() */ |
| 146 | |
| 147 | /* |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 148 | * read8_recv |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 149 | * Recv byte from the TIS register according to the ST33ZP24 SPI protocol. |
| 150 | * @param: phy_id, the phy description |
| 151 | * @param: tpm_register, the tpm tis register where the data should be read |
| 152 | * @param: tpm_data, the TPM response |
| 153 | * @param: tpm_size, tpm TPM response size to read. |
| 154 | * @return: should be zero if success else a negative error code. |
| 155 | */ |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 156 | static int read8_reg(void *phy_id, u8 tpm_register, u8 *tpm_data, int tpm_size) |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 157 | { |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 158 | u8 data = 0; |
Christophe RICARD | 9feaab5 | 2016-02-13 16:15:24 +0100 | [diff] [blame] | 159 | int total_length = 0, ret; |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 160 | struct st33zp24_spi_phy *phy = phy_id; |
| 161 | struct spi_device *dev = phy->spi_device; |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 162 | u8 *tx_buf = (u8 *)phy->spi_xfer.tx_buf; |
| 163 | u8 *rx_buf = phy->spi_xfer.rx_buf; |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 164 | |
| 165 | /* Pre-Header */ |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 166 | data = LOCALITY0; |
| 167 | memcpy(tx_buf + total_length, &data, sizeof(data)); |
| 168 | total_length++; |
| 169 | data = tpm_register; |
| 170 | memcpy(tx_buf + total_length, &data, sizeof(data)); |
| 171 | total_length++; |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 172 | |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 173 | memset(&tx_buf[total_length], TPM_DUMMY_BYTE, |
Christophe RICARD | 9feaab5 | 2016-02-13 16:15:24 +0100 | [diff] [blame] | 174 | phy->latency + tpm_size); |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 175 | |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 176 | phy->spi_xfer.len = total_length + phy->latency + tpm_size; |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 177 | |
| 178 | /* header + status byte + size of the data + status byte */ |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 179 | ret = spi_sync_transfer(dev, &phy->spi_xfer, 1); |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 180 | if (tpm_size > 0 && ret == 0) { |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 181 | ret = rx_buf[total_length + phy->latency - 1]; |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 182 | |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 183 | memcpy(tpm_data, rx_buf + total_length + phy->latency, |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 184 | tpm_size); |
| 185 | } |
| 186 | |
| 187 | return ret; |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 188 | } /* read8_reg() */ |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 189 | |
| 190 | /* |
| 191 | * st33zp24_spi_recv |
| 192 | * Recv byte from the TIS register according to the ST33ZP24 SPI protocol. |
| 193 | * @param: phy_id, the phy description |
| 194 | * @param: tpm_register, the tpm tis register where the data should be read |
| 195 | * @param: tpm_data, the TPM response |
| 196 | * @param: tpm_size, tpm TPM response size to read. |
| 197 | * @return: number of byte read successfully: should be one if success. |
| 198 | */ |
| 199 | static int st33zp24_spi_recv(void *phy_id, u8 tpm_register, u8 *tpm_data, |
| 200 | int tpm_size) |
| 201 | { |
| 202 | int ret; |
| 203 | |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 204 | ret = read8_reg(phy_id, tpm_register, tpm_data, tpm_size); |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 205 | if (!st33zp24_status_to_errno(ret)) |
| 206 | return tpm_size; |
| 207 | return ret; |
| 208 | } /* st33zp24_spi_recv() */ |
| 209 | |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 210 | static int evaluate_latency(void *phy_id) |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 211 | { |
| 212 | struct st33zp24_spi_phy *phy = phy_id; |
| 213 | int latency = 1, status = 0; |
| 214 | u8 data = 0; |
| 215 | |
| 216 | while (!status && latency < MAX_SPI_LATENCY) { |
| 217 | phy->latency = latency; |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 218 | status = read8_reg(phy_id, TPM_INTF_CAPABILITY, &data, 1); |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 219 | latency++; |
| 220 | } |
| 221 | return latency - 1; |
| 222 | } /* evaluate_latency() */ |
| 223 | |
| 224 | static const struct st33zp24_phy_ops spi_phy_ops = { |
| 225 | .send = st33zp24_spi_send, |
| 226 | .recv = st33zp24_spi_recv, |
| 227 | }; |
| 228 | |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 229 | #ifdef CONFIG_OF |
| 230 | static int tpm_stm_spi_of_request_resources(struct st33zp24_spi_phy *phy) |
Christophe RICARD | 160beb4 | 2016-02-23 22:25:49 +0100 | [diff] [blame] | 231 | { |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 232 | struct device_node *pp; |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 233 | struct spi_device *dev = phy->spi_device; |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 234 | int gpio; |
| 235 | int ret; |
| 236 | |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 237 | pp = dev->dev.of_node; |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 238 | if (!pp) { |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 239 | dev_err(&dev->dev, "No platform data\n"); |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 240 | return -ENODEV; |
| 241 | } |
| 242 | |
| 243 | /* Get GPIO from device tree */ |
| 244 | gpio = of_get_named_gpio(pp, "lpcpd-gpios", 0); |
| 245 | if (gpio < 0) { |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 246 | dev_err(&dev->dev, |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 247 | "Failed to retrieve lpcpd-gpios from dts.\n"); |
| 248 | phy->io_lpcpd = -1; |
| 249 | /* |
| 250 | * lpcpd pin is not specified. This is not an issue as |
| 251 | * power management can be also managed by TPM specific |
| 252 | * commands. So leave with a success status code. |
| 253 | */ |
| 254 | return 0; |
| 255 | } |
| 256 | /* GPIO request and configuration */ |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 257 | ret = devm_gpio_request_one(&dev->dev, gpio, |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 258 | GPIOF_OUT_INIT_HIGH, "TPM IO LPCPD"); |
| 259 | if (ret) { |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 260 | dev_err(&dev->dev, "Failed to request lpcpd pin\n"); |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 261 | return -ENODEV; |
| 262 | } |
| 263 | phy->io_lpcpd = gpio; |
| 264 | |
| 265 | return 0; |
| 266 | } |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 267 | #else |
| 268 | static int tpm_stm_spi_of_request_resources(struct st33zp24_spi_phy *phy) |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 269 | { |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 270 | return -ENODEV; |
| 271 | } |
| 272 | #endif |
| 273 | |
| 274 | static int tpm_stm_spi_request_resources(struct spi_device *dev, |
| 275 | struct st33zp24_spi_phy *phy) |
| 276 | { |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 277 | struct st33zp24_platform_data *pdata; |
| 278 | int ret; |
| 279 | |
| 280 | pdata = dev->dev.platform_data; |
| 281 | if (!pdata) { |
| 282 | dev_err(&dev->dev, "No platform data\n"); |
| 283 | return -ENODEV; |
| 284 | } |
| 285 | |
| 286 | /* store for late use */ |
| 287 | phy->io_lpcpd = pdata->io_lpcpd; |
| 288 | |
| 289 | if (gpio_is_valid(pdata->io_lpcpd)) { |
| 290 | ret = devm_gpio_request_one(&dev->dev, |
| 291 | pdata->io_lpcpd, GPIOF_OUT_INIT_HIGH, |
| 292 | "TPM IO_LPCPD"); |
| 293 | if (ret) { |
| 294 | dev_err(&dev->dev, "%s : reset gpio_request failed\n", |
| 295 | __FILE__); |
| 296 | return ret; |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | return 0; |
| 301 | } |
| 302 | |
| 303 | /* |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 304 | * tpm_st33_spi_probe initialize the TPM device |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 305 | * @param: dev, the spi_device drescription (TPM SPI description). |
| 306 | * @return: 0 in case of success. |
| 307 | * or a negative value describing the error. |
| 308 | */ |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 309 | static int |
| 310 | tpm_st33_spi_probe(struct spi_device *dev) |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 311 | { |
| 312 | int ret; |
| 313 | struct st33zp24_platform_data *pdata; |
| 314 | struct st33zp24_spi_phy *phy; |
| 315 | |
| 316 | /* Check SPI platform functionnalities */ |
| 317 | if (!dev) { |
| 318 | pr_info("%s: dev is NULL. Device is not accessible.\n", |
| 319 | __func__); |
| 320 | return -ENODEV; |
| 321 | } |
| 322 | |
| 323 | phy = devm_kzalloc(&dev->dev, sizeof(struct st33zp24_spi_phy), |
| 324 | GFP_KERNEL); |
| 325 | if (!phy) |
| 326 | return -ENOMEM; |
| 327 | |
| 328 | phy->spi_device = dev; |
| 329 | pdata = dev->dev.platform_data; |
| 330 | if (!pdata && dev->dev.of_node) { |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 331 | ret = tpm_stm_spi_of_request_resources(phy); |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 332 | if (ret) |
| 333 | return ret; |
| 334 | } else if (pdata) { |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 335 | ret = tpm_stm_spi_request_resources(dev, phy); |
Christophe RICARD | 160beb4 | 2016-02-23 22:25:49 +0100 | [diff] [blame] | 336 | if (ret) |
| 337 | return ret; |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 338 | } |
| 339 | |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 340 | phy->spi_xfer.tx_buf = phy->tx_buf; |
| 341 | phy->spi_xfer.rx_buf = phy->rx_buf; |
| 342 | |
| 343 | phy->latency = evaluate_latency(phy); |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 344 | if (phy->latency <= 0) |
| 345 | return -ENODEV; |
| 346 | |
| 347 | return st33zp24_probe(phy, &spi_phy_ops, &dev->dev, dev->irq, |
| 348 | phy->io_lpcpd); |
| 349 | } |
| 350 | |
| 351 | /* |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 352 | * tpm_st33_spi_remove remove the TPM device |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 353 | * @param: client, the spi_device drescription (TPM SPI description). |
| 354 | * @return: 0 in case of success. |
| 355 | */ |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 356 | static int tpm_st33_spi_remove(struct spi_device *dev) |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 357 | { |
| 358 | struct tpm_chip *chip = spi_get_drvdata(dev); |
| 359 | |
| 360 | return st33zp24_remove(chip); |
| 361 | } |
| 362 | |
Christophe Ricard | 1018bc2 | 2015-03-23 22:29:58 +0100 | [diff] [blame] | 363 | static const struct spi_device_id st33zp24_spi_id[] = { |
| 364 | {TPM_ST33_SPI, 0}, |
| 365 | {} |
| 366 | }; |
| 367 | MODULE_DEVICE_TABLE(spi, st33zp24_spi_id); |
| 368 | |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 369 | #ifdef CONFIG_OF |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 370 | static const struct of_device_id of_st33zp24_spi_match[] = { |
| 371 | { .compatible = "st,st33zp24-spi", }, |
| 372 | {} |
| 373 | }; |
| 374 | MODULE_DEVICE_TABLE(of, of_st33zp24_spi_match); |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 375 | #endif |
Christophe RICARD | 160beb4 | 2016-02-23 22:25:49 +0100 | [diff] [blame] | 376 | |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 377 | static SIMPLE_DEV_PM_OPS(st33zp24_spi_ops, st33zp24_pm_suspend, |
| 378 | st33zp24_pm_resume); |
| 379 | |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 380 | static struct spi_driver tpm_st33_spi_driver = { |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 381 | .driver = { |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 382 | .name = TPM_ST33_SPI, |
| 383 | .pm = &st33zp24_spi_ops, |
| 384 | .of_match_table = of_match_ptr(of_st33zp24_spi_match), |
| 385 | }, |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 386 | .probe = tpm_st33_spi_probe, |
| 387 | .remove = tpm_st33_spi_remove, |
Christophe Ricard | 1018bc2 | 2015-03-23 22:29:58 +0100 | [diff] [blame] | 388 | .id_table = st33zp24_spi_id, |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 389 | }; |
| 390 | |
Christophe RICARD | 604e578 | 2016-02-13 16:15:24 +0100 | [diff] [blame^] | 391 | module_spi_driver(tpm_st33_spi_driver); |
Christophe Ricard | f042a31 | 2015-03-08 11:17:15 +0100 | [diff] [blame] | 392 | |
| 393 | MODULE_AUTHOR("TPM support (TPMsupport@list.st.com)"); |
| 394 | MODULE_DESCRIPTION("STM TPM 1.2 SPI ST33 Driver"); |
| 395 | MODULE_VERSION("1.3.0"); |
| 396 | MODULE_LICENSE("GPL"); |