Commit 9922b4129c898223513ff5bee007463182a19b58
Committed by
Lee Jones
1 parent
e553fa6e17
Exists in
master
and in
16 other branches
mfd: cros ec: spi: Use consistent function names
Rename cros_ec_{probe,remove}_spi() to cros_ec_spi_{probe,remove}() for consistency. Signed-off-by: Thierry Reding <treding@nvidia.com> Signed-off-by: Lee Jones <lee.jones@linaro.org>
Showing 1 changed file with 4 additions and 4 deletions Inline Diff
drivers/mfd/cros_ec_spi.c
1 | /* | 1 | /* |
2 | * ChromeOS EC multi-function device (SPI) | 2 | * ChromeOS EC multi-function device (SPI) |
3 | * | 3 | * |
4 | * Copyright (C) 2012 Google, Inc | 4 | * Copyright (C) 2012 Google, Inc |
5 | * | 5 | * |
6 | * This software is licensed under the terms of the GNU General Public | 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 | 7 | * License version 2, as published by the Free Software Foundation, and |
8 | * may be copied, distributed, and modified under those terms. | 8 | * may be copied, distributed, and modified under those terms. |
9 | * | 9 | * |
10 | * This program is distributed in the hope that it will be useful, | 10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. | 13 | * GNU General Public License for more details. |
14 | */ | 14 | */ |
15 | 15 | ||
16 | #include <linux/delay.h> | 16 | #include <linux/delay.h> |
17 | #include <linux/kernel.h> | 17 | #include <linux/kernel.h> |
18 | #include <linux/module.h> | 18 | #include <linux/module.h> |
19 | #include <linux/mfd/cros_ec.h> | 19 | #include <linux/mfd/cros_ec.h> |
20 | #include <linux/mfd/cros_ec_commands.h> | 20 | #include <linux/mfd/cros_ec_commands.h> |
21 | #include <linux/platform_device.h> | 21 | #include <linux/platform_device.h> |
22 | #include <linux/slab.h> | 22 | #include <linux/slab.h> |
23 | #include <linux/spi/spi.h> | 23 | #include <linux/spi/spi.h> |
24 | 24 | ||
25 | 25 | ||
26 | /* The header byte, which follows the preamble */ | 26 | /* The header byte, which follows the preamble */ |
27 | #define EC_MSG_HEADER 0xec | 27 | #define EC_MSG_HEADER 0xec |
28 | 28 | ||
29 | /* | 29 | /* |
30 | * Number of EC preamble bytes we read at a time. Since it takes | 30 | * Number of EC preamble bytes we read at a time. Since it takes |
31 | * about 400-500us for the EC to respond there is not a lot of | 31 | * about 400-500us for the EC to respond there is not a lot of |
32 | * point in tuning this. If the EC could respond faster then | 32 | * point in tuning this. If the EC could respond faster then |
33 | * we could increase this so that might expect the preamble and | 33 | * we could increase this so that might expect the preamble and |
34 | * message to occur in a single transaction. However, the maximum | 34 | * message to occur in a single transaction. However, the maximum |
35 | * SPI transfer size is 256 bytes, so at 5MHz we need a response | 35 | * SPI transfer size is 256 bytes, so at 5MHz we need a response |
36 | * time of perhaps <320us (200 bytes / 1600 bits). | 36 | * time of perhaps <320us (200 bytes / 1600 bits). |
37 | */ | 37 | */ |
38 | #define EC_MSG_PREAMBLE_COUNT 32 | 38 | #define EC_MSG_PREAMBLE_COUNT 32 |
39 | 39 | ||
40 | /* | 40 | /* |
41 | * We must get a response from the EC in 5ms. This is a very long | 41 | * We must get a response from the EC in 5ms. This is a very long |
42 | * time, but the flash write command can take 2-3ms. The EC command | 42 | * time, but the flash write command can take 2-3ms. The EC command |
43 | * processing is currently not very fast (about 500us). We could | 43 | * processing is currently not very fast (about 500us). We could |
44 | * look at speeding this up and making the flash write command a | 44 | * look at speeding this up and making the flash write command a |
45 | * 'slow' command, requiring a GET_STATUS wait loop, like flash | 45 | * 'slow' command, requiring a GET_STATUS wait loop, like flash |
46 | * erase. | 46 | * erase. |
47 | */ | 47 | */ |
48 | #define EC_MSG_DEADLINE_MS 5 | 48 | #define EC_MSG_DEADLINE_MS 5 |
49 | 49 | ||
50 | /* | 50 | /* |
51 | * Time between raising the SPI chip select (for the end of a | 51 | * Time between raising the SPI chip select (for the end of a |
52 | * transaction) and dropping it again (for the next transaction). | 52 | * transaction) and dropping it again (for the next transaction). |
53 | * If we go too fast, the EC will miss the transaction. We know that we | 53 | * If we go too fast, the EC will miss the transaction. We know that we |
54 | * need at least 70 us with the 16 MHz STM32 EC, so go with 200 us to be | 54 | * need at least 70 us with the 16 MHz STM32 EC, so go with 200 us to be |
55 | * safe. | 55 | * safe. |
56 | */ | 56 | */ |
57 | #define EC_SPI_RECOVERY_TIME_NS (200 * 1000) | 57 | #define EC_SPI_RECOVERY_TIME_NS (200 * 1000) |
58 | 58 | ||
59 | /** | 59 | /** |
60 | * struct cros_ec_spi - information about a SPI-connected EC | 60 | * struct cros_ec_spi - information about a SPI-connected EC |
61 | * | 61 | * |
62 | * @spi: SPI device we are connected to | 62 | * @spi: SPI device we are connected to |
63 | * @last_transfer_ns: time that we last finished a transfer, or 0 if there | 63 | * @last_transfer_ns: time that we last finished a transfer, or 0 if there |
64 | * if no record | 64 | * if no record |
65 | */ | 65 | */ |
66 | struct cros_ec_spi { | 66 | struct cros_ec_spi { |
67 | struct spi_device *spi; | 67 | struct spi_device *spi; |
68 | s64 last_transfer_ns; | 68 | s64 last_transfer_ns; |
69 | }; | 69 | }; |
70 | 70 | ||
71 | static void debug_packet(struct device *dev, const char *name, u8 *ptr, | 71 | static void debug_packet(struct device *dev, const char *name, u8 *ptr, |
72 | int len) | 72 | int len) |
73 | { | 73 | { |
74 | #ifdef DEBUG | 74 | #ifdef DEBUG |
75 | int i; | 75 | int i; |
76 | 76 | ||
77 | dev_dbg(dev, "%s: ", name); | 77 | dev_dbg(dev, "%s: ", name); |
78 | for (i = 0; i < len; i++) | 78 | for (i = 0; i < len; i++) |
79 | pr_cont(" %02x", ptr[i]); | 79 | pr_cont(" %02x", ptr[i]); |
80 | 80 | ||
81 | pr_cont("\n"); | 81 | pr_cont("\n"); |
82 | #endif | 82 | #endif |
83 | } | 83 | } |
84 | 84 | ||
85 | /** | 85 | /** |
86 | * cros_ec_spi_receive_response - Receive a response from the EC. | 86 | * cros_ec_spi_receive_response - Receive a response from the EC. |
87 | * | 87 | * |
88 | * This function has two phases: reading the preamble bytes (since if we read | 88 | * This function has two phases: reading the preamble bytes (since if we read |
89 | * data from the EC before it is ready to send, we just get preamble) and | 89 | * data from the EC before it is ready to send, we just get preamble) and |
90 | * reading the actual message. | 90 | * reading the actual message. |
91 | * | 91 | * |
92 | * The received data is placed into ec_dev->din. | 92 | * The received data is placed into ec_dev->din. |
93 | * | 93 | * |
94 | * @ec_dev: ChromeOS EC device | 94 | * @ec_dev: ChromeOS EC device |
95 | * @need_len: Number of message bytes we need to read | 95 | * @need_len: Number of message bytes we need to read |
96 | */ | 96 | */ |
97 | static int cros_ec_spi_receive_response(struct cros_ec_device *ec_dev, | 97 | static int cros_ec_spi_receive_response(struct cros_ec_device *ec_dev, |
98 | int need_len) | 98 | int need_len) |
99 | { | 99 | { |
100 | struct cros_ec_spi *ec_spi = ec_dev->priv; | 100 | struct cros_ec_spi *ec_spi = ec_dev->priv; |
101 | struct spi_transfer trans; | 101 | struct spi_transfer trans; |
102 | struct spi_message msg; | 102 | struct spi_message msg; |
103 | u8 *ptr, *end; | 103 | u8 *ptr, *end; |
104 | int ret; | 104 | int ret; |
105 | unsigned long deadline; | 105 | unsigned long deadline; |
106 | int todo; | 106 | int todo; |
107 | 107 | ||
108 | /* Receive data until we see the header byte */ | 108 | /* Receive data until we see the header byte */ |
109 | deadline = jiffies + msecs_to_jiffies(EC_MSG_DEADLINE_MS); | 109 | deadline = jiffies + msecs_to_jiffies(EC_MSG_DEADLINE_MS); |
110 | do { | 110 | do { |
111 | memset(&trans, '\0', sizeof(trans)); | 111 | memset(&trans, '\0', sizeof(trans)); |
112 | trans.cs_change = 1; | 112 | trans.cs_change = 1; |
113 | trans.rx_buf = ptr = ec_dev->din; | 113 | trans.rx_buf = ptr = ec_dev->din; |
114 | trans.len = EC_MSG_PREAMBLE_COUNT; | 114 | trans.len = EC_MSG_PREAMBLE_COUNT; |
115 | 115 | ||
116 | spi_message_init(&msg); | 116 | spi_message_init(&msg); |
117 | spi_message_add_tail(&trans, &msg); | 117 | spi_message_add_tail(&trans, &msg); |
118 | ret = spi_sync(ec_spi->spi, &msg); | 118 | ret = spi_sync(ec_spi->spi, &msg); |
119 | if (ret < 0) { | 119 | if (ret < 0) { |
120 | dev_err(ec_dev->dev, "spi transfer failed: %d\n", ret); | 120 | dev_err(ec_dev->dev, "spi transfer failed: %d\n", ret); |
121 | return ret; | 121 | return ret; |
122 | } | 122 | } |
123 | 123 | ||
124 | for (end = ptr + EC_MSG_PREAMBLE_COUNT; ptr != end; ptr++) { | 124 | for (end = ptr + EC_MSG_PREAMBLE_COUNT; ptr != end; ptr++) { |
125 | if (*ptr == EC_MSG_HEADER) { | 125 | if (*ptr == EC_MSG_HEADER) { |
126 | dev_dbg(ec_dev->dev, "msg found at %zd\n", | 126 | dev_dbg(ec_dev->dev, "msg found at %zd\n", |
127 | ptr - ec_dev->din); | 127 | ptr - ec_dev->din); |
128 | break; | 128 | break; |
129 | } | 129 | } |
130 | } | 130 | } |
131 | 131 | ||
132 | if (time_after(jiffies, deadline)) { | 132 | if (time_after(jiffies, deadline)) { |
133 | dev_warn(ec_dev->dev, "EC failed to respond in time\n"); | 133 | dev_warn(ec_dev->dev, "EC failed to respond in time\n"); |
134 | return -ETIMEDOUT; | 134 | return -ETIMEDOUT; |
135 | } | 135 | } |
136 | } while (ptr == end); | 136 | } while (ptr == end); |
137 | 137 | ||
138 | /* | 138 | /* |
139 | * ptr now points to the header byte. Copy any valid data to the | 139 | * ptr now points to the header byte. Copy any valid data to the |
140 | * start of our buffer | 140 | * start of our buffer |
141 | */ | 141 | */ |
142 | todo = end - ++ptr; | 142 | todo = end - ++ptr; |
143 | BUG_ON(todo < 0 || todo > ec_dev->din_size); | 143 | BUG_ON(todo < 0 || todo > ec_dev->din_size); |
144 | todo = min(todo, need_len); | 144 | todo = min(todo, need_len); |
145 | memmove(ec_dev->din, ptr, todo); | 145 | memmove(ec_dev->din, ptr, todo); |
146 | ptr = ec_dev->din + todo; | 146 | ptr = ec_dev->din + todo; |
147 | dev_dbg(ec_dev->dev, "need %d, got %d bytes from preamble\n", | 147 | dev_dbg(ec_dev->dev, "need %d, got %d bytes from preamble\n", |
148 | need_len, todo); | 148 | need_len, todo); |
149 | need_len -= todo; | 149 | need_len -= todo; |
150 | 150 | ||
151 | /* Receive data until we have it all */ | 151 | /* Receive data until we have it all */ |
152 | while (need_len > 0) { | 152 | while (need_len > 0) { |
153 | /* | 153 | /* |
154 | * We can't support transfers larger than the SPI FIFO size | 154 | * We can't support transfers larger than the SPI FIFO size |
155 | * unless we have DMA. We don't have DMA on the ISP SPI ports | 155 | * unless we have DMA. We don't have DMA on the ISP SPI ports |
156 | * for Exynos. We need a way of asking SPI driver for | 156 | * for Exynos. We need a way of asking SPI driver for |
157 | * maximum-supported transfer size. | 157 | * maximum-supported transfer size. |
158 | */ | 158 | */ |
159 | todo = min(need_len, 256); | 159 | todo = min(need_len, 256); |
160 | dev_dbg(ec_dev->dev, "loop, todo=%d, need_len=%d, ptr=%zd\n", | 160 | dev_dbg(ec_dev->dev, "loop, todo=%d, need_len=%d, ptr=%zd\n", |
161 | todo, need_len, ptr - ec_dev->din); | 161 | todo, need_len, ptr - ec_dev->din); |
162 | 162 | ||
163 | memset(&trans, '\0', sizeof(trans)); | 163 | memset(&trans, '\0', sizeof(trans)); |
164 | trans.cs_change = 1; | 164 | trans.cs_change = 1; |
165 | trans.rx_buf = ptr; | 165 | trans.rx_buf = ptr; |
166 | trans.len = todo; | 166 | trans.len = todo; |
167 | spi_message_init(&msg); | 167 | spi_message_init(&msg); |
168 | spi_message_add_tail(&trans, &msg); | 168 | spi_message_add_tail(&trans, &msg); |
169 | 169 | ||
170 | /* send command to EC and read answer */ | 170 | /* send command to EC and read answer */ |
171 | BUG_ON((u8 *)trans.rx_buf - ec_dev->din + todo > | 171 | BUG_ON((u8 *)trans.rx_buf - ec_dev->din + todo > |
172 | ec_dev->din_size); | 172 | ec_dev->din_size); |
173 | ret = spi_sync(ec_spi->spi, &msg); | 173 | ret = spi_sync(ec_spi->spi, &msg); |
174 | if (ret < 0) { | 174 | if (ret < 0) { |
175 | dev_err(ec_dev->dev, "spi transfer failed: %d\n", ret); | 175 | dev_err(ec_dev->dev, "spi transfer failed: %d\n", ret); |
176 | return ret; | 176 | return ret; |
177 | } | 177 | } |
178 | 178 | ||
179 | debug_packet(ec_dev->dev, "interim", ptr, todo); | 179 | debug_packet(ec_dev->dev, "interim", ptr, todo); |
180 | ptr += todo; | 180 | ptr += todo; |
181 | need_len -= todo; | 181 | need_len -= todo; |
182 | } | 182 | } |
183 | 183 | ||
184 | dev_dbg(ec_dev->dev, "loop done, ptr=%zd\n", ptr - ec_dev->din); | 184 | dev_dbg(ec_dev->dev, "loop done, ptr=%zd\n", ptr - ec_dev->din); |
185 | 185 | ||
186 | return 0; | 186 | return 0; |
187 | } | 187 | } |
188 | 188 | ||
189 | /** | 189 | /** |
190 | * cros_ec_command_spi_xfer - Transfer a message over SPI and receive the reply | 190 | * cros_ec_command_spi_xfer - Transfer a message over SPI and receive the reply |
191 | * | 191 | * |
192 | * @ec_dev: ChromeOS EC device | 192 | * @ec_dev: ChromeOS EC device |
193 | * @ec_msg: Message to transfer | 193 | * @ec_msg: Message to transfer |
194 | */ | 194 | */ |
195 | static int cros_ec_command_spi_xfer(struct cros_ec_device *ec_dev, | 195 | static int cros_ec_command_spi_xfer(struct cros_ec_device *ec_dev, |
196 | struct cros_ec_msg *ec_msg) | 196 | struct cros_ec_msg *ec_msg) |
197 | { | 197 | { |
198 | struct cros_ec_spi *ec_spi = ec_dev->priv; | 198 | struct cros_ec_spi *ec_spi = ec_dev->priv; |
199 | struct spi_transfer trans; | 199 | struct spi_transfer trans; |
200 | struct spi_message msg; | 200 | struct spi_message msg; |
201 | int i, len; | 201 | int i, len; |
202 | u8 *ptr; | 202 | u8 *ptr; |
203 | int sum; | 203 | int sum; |
204 | int ret = 0, final_ret; | 204 | int ret = 0, final_ret; |
205 | struct timespec ts; | 205 | struct timespec ts; |
206 | 206 | ||
207 | len = cros_ec_prepare_tx(ec_dev, ec_msg); | 207 | len = cros_ec_prepare_tx(ec_dev, ec_msg); |
208 | dev_dbg(ec_dev->dev, "prepared, len=%d\n", len); | 208 | dev_dbg(ec_dev->dev, "prepared, len=%d\n", len); |
209 | 209 | ||
210 | /* If it's too soon to do another transaction, wait */ | 210 | /* If it's too soon to do another transaction, wait */ |
211 | if (ec_spi->last_transfer_ns) { | 211 | if (ec_spi->last_transfer_ns) { |
212 | struct timespec ts; | 212 | struct timespec ts; |
213 | unsigned long delay; /* The delay completed so far */ | 213 | unsigned long delay; /* The delay completed so far */ |
214 | 214 | ||
215 | ktime_get_ts(&ts); | 215 | ktime_get_ts(&ts); |
216 | delay = timespec_to_ns(&ts) - ec_spi->last_transfer_ns; | 216 | delay = timespec_to_ns(&ts) - ec_spi->last_transfer_ns; |
217 | if (delay < EC_SPI_RECOVERY_TIME_NS) | 217 | if (delay < EC_SPI_RECOVERY_TIME_NS) |
218 | ndelay(delay); | 218 | ndelay(delay); |
219 | } | 219 | } |
220 | 220 | ||
221 | /* Transmit phase - send our message */ | 221 | /* Transmit phase - send our message */ |
222 | debug_packet(ec_dev->dev, "out", ec_dev->dout, len); | 222 | debug_packet(ec_dev->dev, "out", ec_dev->dout, len); |
223 | memset(&trans, '\0', sizeof(trans)); | 223 | memset(&trans, '\0', sizeof(trans)); |
224 | trans.tx_buf = ec_dev->dout; | 224 | trans.tx_buf = ec_dev->dout; |
225 | trans.len = len; | 225 | trans.len = len; |
226 | trans.cs_change = 1; | 226 | trans.cs_change = 1; |
227 | spi_message_init(&msg); | 227 | spi_message_init(&msg); |
228 | spi_message_add_tail(&trans, &msg); | 228 | spi_message_add_tail(&trans, &msg); |
229 | ret = spi_sync(ec_spi->spi, &msg); | 229 | ret = spi_sync(ec_spi->spi, &msg); |
230 | 230 | ||
231 | /* Get the response */ | 231 | /* Get the response */ |
232 | if (!ret) { | 232 | if (!ret) { |
233 | ret = cros_ec_spi_receive_response(ec_dev, | 233 | ret = cros_ec_spi_receive_response(ec_dev, |
234 | ec_msg->in_len + EC_MSG_TX_PROTO_BYTES); | 234 | ec_msg->in_len + EC_MSG_TX_PROTO_BYTES); |
235 | } else { | 235 | } else { |
236 | dev_err(ec_dev->dev, "spi transfer failed: %d\n", ret); | 236 | dev_err(ec_dev->dev, "spi transfer failed: %d\n", ret); |
237 | } | 237 | } |
238 | 238 | ||
239 | /* turn off CS */ | 239 | /* turn off CS */ |
240 | spi_message_init(&msg); | 240 | spi_message_init(&msg); |
241 | final_ret = spi_sync(ec_spi->spi, &msg); | 241 | final_ret = spi_sync(ec_spi->spi, &msg); |
242 | ktime_get_ts(&ts); | 242 | ktime_get_ts(&ts); |
243 | ec_spi->last_transfer_ns = timespec_to_ns(&ts); | 243 | ec_spi->last_transfer_ns = timespec_to_ns(&ts); |
244 | if (!ret) | 244 | if (!ret) |
245 | ret = final_ret; | 245 | ret = final_ret; |
246 | if (ret < 0) { | 246 | if (ret < 0) { |
247 | dev_err(ec_dev->dev, "spi transfer failed: %d\n", ret); | 247 | dev_err(ec_dev->dev, "spi transfer failed: %d\n", ret); |
248 | return ret; | 248 | return ret; |
249 | } | 249 | } |
250 | 250 | ||
251 | /* check response error code */ | 251 | /* check response error code */ |
252 | ptr = ec_dev->din; | 252 | ptr = ec_dev->din; |
253 | if (ptr[0]) { | 253 | if (ptr[0]) { |
254 | dev_warn(ec_dev->dev, "command 0x%02x returned an error %d\n", | 254 | dev_warn(ec_dev->dev, "command 0x%02x returned an error %d\n", |
255 | ec_msg->cmd, ptr[0]); | 255 | ec_msg->cmd, ptr[0]); |
256 | debug_packet(ec_dev->dev, "in_err", ptr, len); | 256 | debug_packet(ec_dev->dev, "in_err", ptr, len); |
257 | return -EINVAL; | 257 | return -EINVAL; |
258 | } | 258 | } |
259 | len = ptr[1]; | 259 | len = ptr[1]; |
260 | sum = ptr[0] + ptr[1]; | 260 | sum = ptr[0] + ptr[1]; |
261 | if (len > ec_msg->in_len) { | 261 | if (len > ec_msg->in_len) { |
262 | dev_err(ec_dev->dev, "packet too long (%d bytes, expected %d)", | 262 | dev_err(ec_dev->dev, "packet too long (%d bytes, expected %d)", |
263 | len, ec_msg->in_len); | 263 | len, ec_msg->in_len); |
264 | return -ENOSPC; | 264 | return -ENOSPC; |
265 | } | 265 | } |
266 | 266 | ||
267 | /* copy response packet payload and compute checksum */ | 267 | /* copy response packet payload and compute checksum */ |
268 | for (i = 0; i < len; i++) { | 268 | for (i = 0; i < len; i++) { |
269 | sum += ptr[i + 2]; | 269 | sum += ptr[i + 2]; |
270 | if (ec_msg->in_len) | 270 | if (ec_msg->in_len) |
271 | ec_msg->in_buf[i] = ptr[i + 2]; | 271 | ec_msg->in_buf[i] = ptr[i + 2]; |
272 | } | 272 | } |
273 | sum &= 0xff; | 273 | sum &= 0xff; |
274 | 274 | ||
275 | debug_packet(ec_dev->dev, "in", ptr, len + 3); | 275 | debug_packet(ec_dev->dev, "in", ptr, len + 3); |
276 | 276 | ||
277 | if (sum != ptr[len + 2]) { | 277 | if (sum != ptr[len + 2]) { |
278 | dev_err(ec_dev->dev, | 278 | dev_err(ec_dev->dev, |
279 | "bad packet checksum, expected %02x, got %02x\n", | 279 | "bad packet checksum, expected %02x, got %02x\n", |
280 | sum, ptr[len + 2]); | 280 | sum, ptr[len + 2]); |
281 | return -EBADMSG; | 281 | return -EBADMSG; |
282 | } | 282 | } |
283 | 283 | ||
284 | return 0; | 284 | return 0; |
285 | } | 285 | } |
286 | 286 | ||
287 | static int cros_ec_probe_spi(struct spi_device *spi) | 287 | static int cros_ec_spi_probe(struct spi_device *spi) |
288 | { | 288 | { |
289 | struct device *dev = &spi->dev; | 289 | struct device *dev = &spi->dev; |
290 | struct cros_ec_device *ec_dev; | 290 | struct cros_ec_device *ec_dev; |
291 | struct cros_ec_spi *ec_spi; | 291 | struct cros_ec_spi *ec_spi; |
292 | int err; | 292 | int err; |
293 | 293 | ||
294 | spi->bits_per_word = 8; | 294 | spi->bits_per_word = 8; |
295 | spi->mode = SPI_MODE_0; | 295 | spi->mode = SPI_MODE_0; |
296 | err = spi_setup(spi); | 296 | err = spi_setup(spi); |
297 | if (err < 0) | 297 | if (err < 0) |
298 | return err; | 298 | return err; |
299 | 299 | ||
300 | ec_spi = devm_kzalloc(dev, sizeof(*ec_spi), GFP_KERNEL); | 300 | ec_spi = devm_kzalloc(dev, sizeof(*ec_spi), GFP_KERNEL); |
301 | if (ec_spi == NULL) | 301 | if (ec_spi == NULL) |
302 | return -ENOMEM; | 302 | return -ENOMEM; |
303 | ec_spi->spi = spi; | 303 | ec_spi->spi = spi; |
304 | ec_dev = devm_kzalloc(dev, sizeof(*ec_dev), GFP_KERNEL); | 304 | ec_dev = devm_kzalloc(dev, sizeof(*ec_dev), GFP_KERNEL); |
305 | if (!ec_dev) | 305 | if (!ec_dev) |
306 | return -ENOMEM; | 306 | return -ENOMEM; |
307 | 307 | ||
308 | spi_set_drvdata(spi, ec_dev); | 308 | spi_set_drvdata(spi, ec_dev); |
309 | ec_dev->name = "SPI"; | 309 | ec_dev->name = "SPI"; |
310 | ec_dev->dev = dev; | 310 | ec_dev->dev = dev; |
311 | ec_dev->priv = ec_spi; | 311 | ec_dev->priv = ec_spi; |
312 | ec_dev->irq = spi->irq; | 312 | ec_dev->irq = spi->irq; |
313 | ec_dev->command_xfer = cros_ec_command_spi_xfer; | 313 | ec_dev->command_xfer = cros_ec_command_spi_xfer; |
314 | ec_dev->ec_name = ec_spi->spi->modalias; | 314 | ec_dev->ec_name = ec_spi->spi->modalias; |
315 | ec_dev->phys_name = dev_name(&ec_spi->spi->dev); | 315 | ec_dev->phys_name = dev_name(&ec_spi->spi->dev); |
316 | ec_dev->parent = &ec_spi->spi->dev; | 316 | ec_dev->parent = &ec_spi->spi->dev; |
317 | ec_dev->din_size = EC_MSG_BYTES + EC_MSG_PREAMBLE_COUNT; | 317 | ec_dev->din_size = EC_MSG_BYTES + EC_MSG_PREAMBLE_COUNT; |
318 | ec_dev->dout_size = EC_MSG_BYTES; | 318 | ec_dev->dout_size = EC_MSG_BYTES; |
319 | 319 | ||
320 | err = cros_ec_register(ec_dev); | 320 | err = cros_ec_register(ec_dev); |
321 | if (err) { | 321 | if (err) { |
322 | dev_err(dev, "cannot register EC\n"); | 322 | dev_err(dev, "cannot register EC\n"); |
323 | return err; | 323 | return err; |
324 | } | 324 | } |
325 | 325 | ||
326 | return 0; | 326 | return 0; |
327 | } | 327 | } |
328 | 328 | ||
329 | static int cros_ec_remove_spi(struct spi_device *spi) | 329 | static int cros_ec_spi_remove(struct spi_device *spi) |
330 | { | 330 | { |
331 | struct cros_ec_device *ec_dev; | 331 | struct cros_ec_device *ec_dev; |
332 | 332 | ||
333 | ec_dev = spi_get_drvdata(spi); | 333 | ec_dev = spi_get_drvdata(spi); |
334 | cros_ec_remove(ec_dev); | 334 | cros_ec_remove(ec_dev); |
335 | 335 | ||
336 | return 0; | 336 | return 0; |
337 | } | 337 | } |
338 | 338 | ||
339 | #ifdef CONFIG_PM_SLEEP | 339 | #ifdef CONFIG_PM_SLEEP |
340 | static int cros_ec_spi_suspend(struct device *dev) | 340 | static int cros_ec_spi_suspend(struct device *dev) |
341 | { | 341 | { |
342 | struct cros_ec_device *ec_dev = dev_get_drvdata(dev); | 342 | struct cros_ec_device *ec_dev = dev_get_drvdata(dev); |
343 | 343 | ||
344 | return cros_ec_suspend(ec_dev); | 344 | return cros_ec_suspend(ec_dev); |
345 | } | 345 | } |
346 | 346 | ||
347 | static int cros_ec_spi_resume(struct device *dev) | 347 | static int cros_ec_spi_resume(struct device *dev) |
348 | { | 348 | { |
349 | struct cros_ec_device *ec_dev = dev_get_drvdata(dev); | 349 | struct cros_ec_device *ec_dev = dev_get_drvdata(dev); |
350 | 350 | ||
351 | return cros_ec_resume(ec_dev); | 351 | return cros_ec_resume(ec_dev); |
352 | } | 352 | } |
353 | #endif | 353 | #endif |
354 | 354 | ||
355 | static SIMPLE_DEV_PM_OPS(cros_ec_spi_pm_ops, cros_ec_spi_suspend, | 355 | static SIMPLE_DEV_PM_OPS(cros_ec_spi_pm_ops, cros_ec_spi_suspend, |
356 | cros_ec_spi_resume); | 356 | cros_ec_spi_resume); |
357 | 357 | ||
358 | static const struct spi_device_id cros_ec_spi_id[] = { | 358 | static const struct spi_device_id cros_ec_spi_id[] = { |
359 | { "cros-ec-spi", 0 }, | 359 | { "cros-ec-spi", 0 }, |
360 | { } | 360 | { } |
361 | }; | 361 | }; |
362 | MODULE_DEVICE_TABLE(spi, cros_ec_spi_id); | 362 | MODULE_DEVICE_TABLE(spi, cros_ec_spi_id); |
363 | 363 | ||
364 | static struct spi_driver cros_ec_driver_spi = { | 364 | static struct spi_driver cros_ec_driver_spi = { |
365 | .driver = { | 365 | .driver = { |
366 | .name = "cros-ec-spi", | 366 | .name = "cros-ec-spi", |
367 | .owner = THIS_MODULE, | 367 | .owner = THIS_MODULE, |
368 | .pm = &cros_ec_spi_pm_ops, | 368 | .pm = &cros_ec_spi_pm_ops, |
369 | }, | 369 | }, |
370 | .probe = cros_ec_probe_spi, | 370 | .probe = cros_ec_spi_probe, |
371 | .remove = cros_ec_remove_spi, | 371 | .remove = cros_ec_spi_remove, |
372 | .id_table = cros_ec_spi_id, | 372 | .id_table = cros_ec_spi_id, |
373 | }; | 373 | }; |
374 | 374 | ||
375 | module_spi_driver(cros_ec_driver_spi); | 375 | module_spi_driver(cros_ec_driver_spi); |
376 | 376 | ||
377 | MODULE_LICENSE("GPL"); | 377 | MODULE_LICENSE("GPL"); |
378 | MODULE_DESCRIPTION("ChromeOS EC multi function device (SPI)"); | 378 | MODULE_DESCRIPTION("ChromeOS EC multi function device (SPI)"); |
379 | 379 |