Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 1 | /* |
| 2 | * ChromeOS EC multi-function device (SPI) |
| 3 | * |
| 4 | * Copyright (C) 2012 Google, Inc |
| 5 | * |
| 6 | * This software is licensed under the terms of the GNU General Public |
| 7 | * License version 2, as published by the Free Software Foundation, and |
| 8 | * may be copied, distributed, and modified under those terms. |
| 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 | |
| 16 | #include <linux/delay.h> |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/mfd/cros_ec.h> |
| 20 | #include <linux/mfd/cros_ec_commands.h> |
Rhyland Klein | 01e73c8 | 2013-12-09 12:36:09 +0100 | [diff] [blame] | 21 | #include <linux/of.h> |
Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 22 | #include <linux/platform_device.h> |
| 23 | #include <linux/slab.h> |
| 24 | #include <linux/spi/spi.h> |
| 25 | |
| 26 | |
| 27 | /* The header byte, which follows the preamble */ |
| 28 | #define EC_MSG_HEADER 0xec |
| 29 | |
| 30 | /* |
| 31 | * Number of EC preamble bytes we read at a time. Since it takes |
| 32 | * about 400-500us for the EC to respond there is not a lot of |
| 33 | * point in tuning this. If the EC could respond faster then |
| 34 | * we could increase this so that might expect the preamble and |
| 35 | * message to occur in a single transaction. However, the maximum |
| 36 | * SPI transfer size is 256 bytes, so at 5MHz we need a response |
| 37 | * time of perhaps <320us (200 bytes / 1600 bits). |
| 38 | */ |
| 39 | #define EC_MSG_PREAMBLE_COUNT 32 |
| 40 | |
| 41 | /* |
Doug Anderson | 9c0b54a | 2014-04-30 10:44:07 -0700 | [diff] [blame] | 42 | * Allow for a long time for the EC to respond. We support i2c |
| 43 | * tunneling and support fairly long messages for the tunnel (249 |
| 44 | * bytes long at the moment). If we're talking to a 100 kHz device |
| 45 | * on the other end and need to transfer ~256 bytes, then we need: |
| 46 | * 10 us/bit * ~10 bits/byte * ~256 bytes = ~25ms |
| 47 | * |
| 48 | * We'll wait 4 times that to handle clock stretching and other |
| 49 | * paranoia. |
| 50 | * |
| 51 | * It's pretty unlikely that we'll really see a 249 byte tunnel in |
| 52 | * anything other than testing. If this was more common we might |
| 53 | * consider having slow commands like this require a GET_STATUS |
| 54 | * wait loop. The 'flash write' command would be another candidate |
| 55 | * for this, clocking in at 2-3ms. |
| 56 | */ |
| 57 | #define EC_MSG_DEADLINE_MS 100 |
Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 58 | |
| 59 | /* |
| 60 | * Time between raising the SPI chip select (for the end of a |
| 61 | * transaction) and dropping it again (for the next transaction). |
Derek Basehore | 49f91ac | 2013-11-18 11:30:48 +0100 | [diff] [blame] | 62 | * If we go too fast, the EC will miss the transaction. We know that we |
| 63 | * need at least 70 us with the 16 MHz STM32 EC, so go with 200 us to be |
| 64 | * safe. |
Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 65 | */ |
Derek Basehore | 49f91ac | 2013-11-18 11:30:48 +0100 | [diff] [blame] | 66 | #define EC_SPI_RECOVERY_TIME_NS (200 * 1000) |
Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 67 | |
| 68 | /** |
| 69 | * struct cros_ec_spi - information about a SPI-connected EC |
| 70 | * |
| 71 | * @spi: SPI device we are connected to |
| 72 | * @last_transfer_ns: time that we last finished a transfer, or 0 if there |
| 73 | * if no record |
Rhyland Klein | 01e73c8 | 2013-12-09 12:36:09 +0100 | [diff] [blame] | 74 | * @end_of_msg_delay: used to set the delay_usecs on the spi_transfer that |
| 75 | * is sent when we want to turn off CS at the end of a transaction. |
Doug Anderson | 362196e | 2014-04-30 10:44:05 -0700 | [diff] [blame] | 76 | * @lock: mutex to ensure only one user of cros_ec_command_spi_xfer at a time |
Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 77 | */ |
| 78 | struct cros_ec_spi { |
| 79 | struct spi_device *spi; |
| 80 | s64 last_transfer_ns; |
Rhyland Klein | 01e73c8 | 2013-12-09 12:36:09 +0100 | [diff] [blame] | 81 | unsigned int end_of_msg_delay; |
Doug Anderson | 362196e | 2014-04-30 10:44:05 -0700 | [diff] [blame] | 82 | struct mutex lock; |
Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | static void debug_packet(struct device *dev, const char *name, u8 *ptr, |
| 86 | int len) |
| 87 | { |
| 88 | #ifdef DEBUG |
| 89 | int i; |
| 90 | |
| 91 | dev_dbg(dev, "%s: ", name); |
| 92 | for (i = 0; i < len; i++) |
Thierry Reding | 9e146f4 | 2013-11-18 11:30:49 +0100 | [diff] [blame] | 93 | pr_cont(" %02x", ptr[i]); |
| 94 | |
| 95 | pr_cont("\n"); |
Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 96 | #endif |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * cros_ec_spi_receive_response - Receive a response from the EC. |
| 101 | * |
| 102 | * This function has two phases: reading the preamble bytes (since if we read |
| 103 | * data from the EC before it is ready to send, we just get preamble) and |
| 104 | * reading the actual message. |
| 105 | * |
| 106 | * The received data is placed into ec_dev->din. |
| 107 | * |
| 108 | * @ec_dev: ChromeOS EC device |
| 109 | * @need_len: Number of message bytes we need to read |
| 110 | */ |
| 111 | static int cros_ec_spi_receive_response(struct cros_ec_device *ec_dev, |
| 112 | int need_len) |
| 113 | { |
| 114 | struct cros_ec_spi *ec_spi = ec_dev->priv; |
| 115 | struct spi_transfer trans; |
| 116 | struct spi_message msg; |
| 117 | u8 *ptr, *end; |
| 118 | int ret; |
| 119 | unsigned long deadline; |
| 120 | int todo; |
| 121 | |
| 122 | /* Receive data until we see the header byte */ |
| 123 | deadline = jiffies + msecs_to_jiffies(EC_MSG_DEADLINE_MS); |
Doug Anderson | c9a81d6 | 2014-04-30 10:44:06 -0700 | [diff] [blame] | 124 | while (true) { |
| 125 | unsigned long start_jiffies = jiffies; |
| 126 | |
Thierry Reding | daf93d2 | 2013-12-09 12:36:10 +0100 | [diff] [blame] | 127 | memset(&trans, 0, sizeof(trans)); |
Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 128 | trans.cs_change = 1; |
| 129 | trans.rx_buf = ptr = ec_dev->din; |
| 130 | trans.len = EC_MSG_PREAMBLE_COUNT; |
| 131 | |
| 132 | spi_message_init(&msg); |
| 133 | spi_message_add_tail(&trans, &msg); |
| 134 | ret = spi_sync(ec_spi->spi, &msg); |
| 135 | if (ret < 0) { |
| 136 | dev_err(ec_dev->dev, "spi transfer failed: %d\n", ret); |
| 137 | return ret; |
| 138 | } |
| 139 | |
| 140 | for (end = ptr + EC_MSG_PREAMBLE_COUNT; ptr != end; ptr++) { |
| 141 | if (*ptr == EC_MSG_HEADER) { |
Geert Uytterhoeven | c34924b | 2013-05-08 23:37:45 +0200 | [diff] [blame] | 142 | dev_dbg(ec_dev->dev, "msg found at %zd\n", |
Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 143 | ptr - ec_dev->din); |
| 144 | break; |
| 145 | } |
| 146 | } |
Doug Anderson | c9a81d6 | 2014-04-30 10:44:06 -0700 | [diff] [blame] | 147 | if (ptr != end) |
| 148 | break; |
Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 149 | |
Doug Anderson | c9a81d6 | 2014-04-30 10:44:06 -0700 | [diff] [blame] | 150 | /* |
| 151 | * Use the time at the start of the loop as a timeout. This |
| 152 | * gives us one last shot at getting the transfer and is useful |
| 153 | * in case we got context switched out for a while. |
| 154 | */ |
| 155 | if (time_after(start_jiffies, deadline)) { |
Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 156 | dev_warn(ec_dev->dev, "EC failed to respond in time\n"); |
| 157 | return -ETIMEDOUT; |
| 158 | } |
Doug Anderson | c9a81d6 | 2014-04-30 10:44:06 -0700 | [diff] [blame] | 159 | } |
Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 160 | |
| 161 | /* |
| 162 | * ptr now points to the header byte. Copy any valid data to the |
| 163 | * start of our buffer |
| 164 | */ |
| 165 | todo = end - ++ptr; |
| 166 | BUG_ON(todo < 0 || todo > ec_dev->din_size); |
| 167 | todo = min(todo, need_len); |
| 168 | memmove(ec_dev->din, ptr, todo); |
| 169 | ptr = ec_dev->din + todo; |
| 170 | dev_dbg(ec_dev->dev, "need %d, got %d bytes from preamble\n", |
| 171 | need_len, todo); |
| 172 | need_len -= todo; |
| 173 | |
| 174 | /* Receive data until we have it all */ |
| 175 | while (need_len > 0) { |
| 176 | /* |
| 177 | * We can't support transfers larger than the SPI FIFO size |
| 178 | * unless we have DMA. We don't have DMA on the ISP SPI ports |
| 179 | * for Exynos. We need a way of asking SPI driver for |
| 180 | * maximum-supported transfer size. |
| 181 | */ |
| 182 | todo = min(need_len, 256); |
Geert Uytterhoeven | c34924b | 2013-05-08 23:37:45 +0200 | [diff] [blame] | 183 | dev_dbg(ec_dev->dev, "loop, todo=%d, need_len=%d, ptr=%zd\n", |
Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 184 | todo, need_len, ptr - ec_dev->din); |
| 185 | |
Thierry Reding | daf93d2 | 2013-12-09 12:36:10 +0100 | [diff] [blame] | 186 | memset(&trans, 0, sizeof(trans)); |
Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 187 | trans.cs_change = 1; |
| 188 | trans.rx_buf = ptr; |
| 189 | trans.len = todo; |
| 190 | spi_message_init(&msg); |
| 191 | spi_message_add_tail(&trans, &msg); |
| 192 | |
| 193 | /* send command to EC and read answer */ |
| 194 | BUG_ON((u8 *)trans.rx_buf - ec_dev->din + todo > |
| 195 | ec_dev->din_size); |
| 196 | ret = spi_sync(ec_spi->spi, &msg); |
| 197 | if (ret < 0) { |
| 198 | dev_err(ec_dev->dev, "spi transfer failed: %d\n", ret); |
| 199 | return ret; |
| 200 | } |
| 201 | |
| 202 | debug_packet(ec_dev->dev, "interim", ptr, todo); |
| 203 | ptr += todo; |
| 204 | need_len -= todo; |
| 205 | } |
| 206 | |
Geert Uytterhoeven | c34924b | 2013-05-08 23:37:45 +0200 | [diff] [blame] | 207 | dev_dbg(ec_dev->dev, "loop done, ptr=%zd\n", ptr - ec_dev->din); |
Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 208 | |
| 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * cros_ec_command_spi_xfer - Transfer a message over SPI and receive the reply |
| 214 | * |
| 215 | * @ec_dev: ChromeOS EC device |
| 216 | * @ec_msg: Message to transfer |
| 217 | */ |
| 218 | static int cros_ec_command_spi_xfer(struct cros_ec_device *ec_dev, |
| 219 | struct cros_ec_msg *ec_msg) |
| 220 | { |
| 221 | struct cros_ec_spi *ec_spi = ec_dev->priv; |
| 222 | struct spi_transfer trans; |
| 223 | struct spi_message msg; |
| 224 | int i, len; |
| 225 | u8 *ptr; |
| 226 | int sum; |
| 227 | int ret = 0, final_ret; |
Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 228 | |
Doug Anderson | 362196e | 2014-04-30 10:44:05 -0700 | [diff] [blame] | 229 | /* |
| 230 | * We have the shared ec_dev buffer plus we do lots of separate spi_sync |
| 231 | * calls, so we need to make sure only one person is using this at a |
| 232 | * time. |
| 233 | */ |
| 234 | mutex_lock(&ec_spi->lock); |
| 235 | |
Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 236 | len = cros_ec_prepare_tx(ec_dev, ec_msg); |
| 237 | dev_dbg(ec_dev->dev, "prepared, len=%d\n", len); |
| 238 | |
| 239 | /* If it's too soon to do another transaction, wait */ |
| 240 | if (ec_spi->last_transfer_ns) { |
Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 241 | unsigned long delay; /* The delay completed so far */ |
| 242 | |
Thomas Gleixner | 154adc1 | 2014-07-16 21:04:41 +0000 | [diff] [blame] | 243 | delay = ktime_get_ns() - ec_spi->last_transfer_ns; |
Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 244 | if (delay < EC_SPI_RECOVERY_TIME_NS) |
David Hendricks | 1fe3686 | 2014-04-30 10:44:04 -0700 | [diff] [blame] | 245 | ndelay(EC_SPI_RECOVERY_TIME_NS - delay); |
Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | /* Transmit phase - send our message */ |
| 249 | debug_packet(ec_dev->dev, "out", ec_dev->dout, len); |
Thierry Reding | daf93d2 | 2013-12-09 12:36:10 +0100 | [diff] [blame] | 250 | memset(&trans, 0, sizeof(trans)); |
Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 251 | trans.tx_buf = ec_dev->dout; |
| 252 | trans.len = len; |
| 253 | trans.cs_change = 1; |
| 254 | spi_message_init(&msg); |
| 255 | spi_message_add_tail(&trans, &msg); |
| 256 | ret = spi_sync(ec_spi->spi, &msg); |
| 257 | |
| 258 | /* Get the response */ |
| 259 | if (!ret) { |
| 260 | ret = cros_ec_spi_receive_response(ec_dev, |
| 261 | ec_msg->in_len + EC_MSG_TX_PROTO_BYTES); |
| 262 | } else { |
| 263 | dev_err(ec_dev->dev, "spi transfer failed: %d\n", ret); |
| 264 | } |
| 265 | |
| 266 | /* turn off CS */ |
| 267 | spi_message_init(&msg); |
Rhyland Klein | 01e73c8 | 2013-12-09 12:36:09 +0100 | [diff] [blame] | 268 | |
| 269 | if (ec_spi->end_of_msg_delay) { |
| 270 | /* |
| 271 | * Add delay for last transaction, to ensure the rising edge |
| 272 | * doesn't come too soon after the end of the data. |
| 273 | */ |
| 274 | memset(&trans, 0, sizeof(trans)); |
| 275 | trans.delay_usecs = ec_spi->end_of_msg_delay; |
| 276 | spi_message_add_tail(&trans, &msg); |
| 277 | } |
| 278 | |
Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 279 | final_ret = spi_sync(ec_spi->spi, &msg); |
Thomas Gleixner | 154adc1 | 2014-07-16 21:04:41 +0000 | [diff] [blame] | 280 | ec_spi->last_transfer_ns = ktime_get_ns(); |
Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 281 | if (!ret) |
| 282 | ret = final_ret; |
| 283 | if (ret < 0) { |
| 284 | dev_err(ec_dev->dev, "spi transfer failed: %d\n", ret); |
Doug Anderson | 362196e | 2014-04-30 10:44:05 -0700 | [diff] [blame] | 285 | goto exit; |
Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | /* check response error code */ |
| 289 | ptr = ec_dev->din; |
| 290 | if (ptr[0]) { |
| 291 | dev_warn(ec_dev->dev, "command 0x%02x returned an error %d\n", |
| 292 | ec_msg->cmd, ptr[0]); |
| 293 | debug_packet(ec_dev->dev, "in_err", ptr, len); |
Doug Anderson | 362196e | 2014-04-30 10:44:05 -0700 | [diff] [blame] | 294 | ret = -EINVAL; |
| 295 | goto exit; |
Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 296 | } |
| 297 | len = ptr[1]; |
| 298 | sum = ptr[0] + ptr[1]; |
| 299 | if (len > ec_msg->in_len) { |
| 300 | dev_err(ec_dev->dev, "packet too long (%d bytes, expected %d)", |
| 301 | len, ec_msg->in_len); |
Doug Anderson | 362196e | 2014-04-30 10:44:05 -0700 | [diff] [blame] | 302 | ret = -ENOSPC; |
| 303 | goto exit; |
Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | /* copy response packet payload and compute checksum */ |
| 307 | for (i = 0; i < len; i++) { |
| 308 | sum += ptr[i + 2]; |
| 309 | if (ec_msg->in_len) |
| 310 | ec_msg->in_buf[i] = ptr[i + 2]; |
| 311 | } |
| 312 | sum &= 0xff; |
| 313 | |
| 314 | debug_packet(ec_dev->dev, "in", ptr, len + 3); |
| 315 | |
| 316 | if (sum != ptr[len + 2]) { |
| 317 | dev_err(ec_dev->dev, |
| 318 | "bad packet checksum, expected %02x, got %02x\n", |
| 319 | sum, ptr[len + 2]); |
Doug Anderson | 362196e | 2014-04-30 10:44:05 -0700 | [diff] [blame] | 320 | ret = -EBADMSG; |
| 321 | goto exit; |
Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 322 | } |
| 323 | |
Doug Anderson | 362196e | 2014-04-30 10:44:05 -0700 | [diff] [blame] | 324 | ret = 0; |
| 325 | exit: |
| 326 | mutex_unlock(&ec_spi->lock); |
| 327 | return ret; |
Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 328 | } |
| 329 | |
Rhyland Klein | 01e73c8 | 2013-12-09 12:36:09 +0100 | [diff] [blame] | 330 | static void cros_ec_spi_dt_probe(struct cros_ec_spi *ec_spi, struct device *dev) |
| 331 | { |
| 332 | struct device_node *np = dev->of_node; |
| 333 | u32 val; |
| 334 | int ret; |
| 335 | |
| 336 | ret = of_property_read_u32(np, "google,cros-ec-spi-msg-delay", &val); |
| 337 | if (!ret) |
| 338 | ec_spi->end_of_msg_delay = val; |
| 339 | } |
| 340 | |
Thierry Reding | 9922b41 | 2013-11-25 13:22:30 +0100 | [diff] [blame] | 341 | static int cros_ec_spi_probe(struct spi_device *spi) |
Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 342 | { |
| 343 | struct device *dev = &spi->dev; |
| 344 | struct cros_ec_device *ec_dev; |
| 345 | struct cros_ec_spi *ec_spi; |
| 346 | int err; |
| 347 | |
| 348 | spi->bits_per_word = 8; |
| 349 | spi->mode = SPI_MODE_0; |
| 350 | err = spi_setup(spi); |
| 351 | if (err < 0) |
| 352 | return err; |
| 353 | |
| 354 | ec_spi = devm_kzalloc(dev, sizeof(*ec_spi), GFP_KERNEL); |
| 355 | if (ec_spi == NULL) |
| 356 | return -ENOMEM; |
| 357 | ec_spi->spi = spi; |
Doug Anderson | 362196e | 2014-04-30 10:44:05 -0700 | [diff] [blame] | 358 | mutex_init(&ec_spi->lock); |
Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 359 | ec_dev = devm_kzalloc(dev, sizeof(*ec_dev), GFP_KERNEL); |
| 360 | if (!ec_dev) |
| 361 | return -ENOMEM; |
| 362 | |
Rhyland Klein | 01e73c8 | 2013-12-09 12:36:09 +0100 | [diff] [blame] | 363 | /* Check for any DT properties */ |
| 364 | cros_ec_spi_dt_probe(ec_spi, dev); |
| 365 | |
Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 366 | spi_set_drvdata(spi, ec_dev); |
| 367 | ec_dev->name = "SPI"; |
| 368 | ec_dev->dev = dev; |
| 369 | ec_dev->priv = ec_spi; |
| 370 | ec_dev->irq = spi->irq; |
| 371 | ec_dev->command_xfer = cros_ec_command_spi_xfer; |
| 372 | ec_dev->ec_name = ec_spi->spi->modalias; |
| 373 | ec_dev->phys_name = dev_name(&ec_spi->spi->dev); |
| 374 | ec_dev->parent = &ec_spi->spi->dev; |
| 375 | ec_dev->din_size = EC_MSG_BYTES + EC_MSG_PREAMBLE_COUNT; |
| 376 | ec_dev->dout_size = EC_MSG_BYTES; |
| 377 | |
| 378 | err = cros_ec_register(ec_dev); |
| 379 | if (err) { |
| 380 | dev_err(dev, "cannot register EC\n"); |
| 381 | return err; |
| 382 | } |
| 383 | |
| 384 | return 0; |
| 385 | } |
| 386 | |
Thierry Reding | 9922b41 | 2013-11-25 13:22:30 +0100 | [diff] [blame] | 387 | static int cros_ec_spi_remove(struct spi_device *spi) |
Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 388 | { |
| 389 | struct cros_ec_device *ec_dev; |
| 390 | |
| 391 | ec_dev = spi_get_drvdata(spi); |
| 392 | cros_ec_remove(ec_dev); |
| 393 | |
| 394 | return 0; |
| 395 | } |
| 396 | |
| 397 | #ifdef CONFIG_PM_SLEEP |
| 398 | static int cros_ec_spi_suspend(struct device *dev) |
| 399 | { |
| 400 | struct cros_ec_device *ec_dev = dev_get_drvdata(dev); |
| 401 | |
| 402 | return cros_ec_suspend(ec_dev); |
| 403 | } |
| 404 | |
| 405 | static int cros_ec_spi_resume(struct device *dev) |
| 406 | { |
| 407 | struct cros_ec_device *ec_dev = dev_get_drvdata(dev); |
| 408 | |
| 409 | return cros_ec_resume(ec_dev); |
| 410 | } |
| 411 | #endif |
| 412 | |
| 413 | static SIMPLE_DEV_PM_OPS(cros_ec_spi_pm_ops, cros_ec_spi_suspend, |
| 414 | cros_ec_spi_resume); |
| 415 | |
| 416 | static const struct spi_device_id cros_ec_spi_id[] = { |
| 417 | { "cros-ec-spi", 0 }, |
| 418 | { } |
| 419 | }; |
| 420 | MODULE_DEVICE_TABLE(spi, cros_ec_spi_id); |
| 421 | |
| 422 | static struct spi_driver cros_ec_driver_spi = { |
| 423 | .driver = { |
| 424 | .name = "cros-ec-spi", |
| 425 | .owner = THIS_MODULE, |
| 426 | .pm = &cros_ec_spi_pm_ops, |
| 427 | }, |
Thierry Reding | 9922b41 | 2013-11-25 13:22:30 +0100 | [diff] [blame] | 428 | .probe = cros_ec_spi_probe, |
| 429 | .remove = cros_ec_spi_remove, |
Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 430 | .id_table = cros_ec_spi_id, |
| 431 | }; |
| 432 | |
| 433 | module_spi_driver(cros_ec_driver_spi); |
| 434 | |
Thierry Reding | ea0f8b0 | 2013-12-09 11:05:38 +0100 | [diff] [blame] | 435 | MODULE_LICENSE("GPL v2"); |
Simon Glass | a17d94f | 2013-02-25 14:08:39 -0800 | [diff] [blame] | 436 | MODULE_DESCRIPTION("ChromeOS EC multi function device (SPI)"); |