diff options
author | Russ Gorby <richardx.r.gorby@intel.com> | 2010-10-26 09:13:52 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-11-11 14:35:57 -0500 |
commit | af3b8881f4c9852eefe9c7f1a997b3ecf580561b (patch) | |
tree | 13cf6f7d955dfc395e3bc41940cf4d89b18f4e96 /drivers | |
parent | a7bcf21e60c73cb7f7c13fad928967d7e47c3cac (diff) |
ifx6x60: SPI protocol driver for Infineon 6x60 modem
Prototype driver for the IFX6x60 series of SPI attached modems by Jim
Stanley and Russ Gorby
Signed-off-by: Russ Gorby <richardx.r.gorby@intel.com>
[Some reworking and a major cleanup]
Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/serial/Kconfig | 6 | ||||
-rw-r--r-- | drivers/serial/Makefile | 1 | ||||
-rw-r--r-- | drivers/serial/ifx6x60.c | 1402 | ||||
-rw-r--r-- | drivers/serial/ifx6x60.h | 129 |
4 files changed, 1538 insertions, 0 deletions
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig index aff9dcd051c6..0b9cc17b380b 100644 --- a/drivers/serial/Kconfig +++ b/drivers/serial/Kconfig | |||
@@ -1632,4 +1632,10 @@ config SERIAL_ALTERA_UART_CONSOLE | |||
1632 | help | 1632 | help |
1633 | Enable a Altera UART port to be the system console. | 1633 | Enable a Altera UART port to be the system console. |
1634 | 1634 | ||
1635 | config SERIAL_IFX6X60 | ||
1636 | tristate "SPI protocol driver for Infineon 6x60 modem (EXPERIMENTAL)" | ||
1637 | depends on GPIOLIB && EXPERIMENTAL | ||
1638 | help | ||
1639 | Support for the IFX6x60 modem devices on Intel MID platforms. | ||
1640 | |||
1635 | endmenu | 1641 | endmenu |
diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile index c5705765454f..783638b10698 100644 --- a/drivers/serial/Makefile +++ b/drivers/serial/Makefile | |||
@@ -89,3 +89,4 @@ obj-$(CONFIG_SERIAL_ALTERA_UART) += altera_uart.o | |||
89 | obj-$(CONFIG_SERIAL_MRST_MAX3110) += mrst_max3110.o | 89 | obj-$(CONFIG_SERIAL_MRST_MAX3110) += mrst_max3110.o |
90 | obj-$(CONFIG_SERIAL_MFD_HSU) += mfd.o | 90 | obj-$(CONFIG_SERIAL_MFD_HSU) += mfd.o |
91 | obj-$(CONFIG_SERIAL_OMAP) += omap-serial.o | 91 | obj-$(CONFIG_SERIAL_OMAP) += omap-serial.o |
92 | obj-$(CONFIG_SERIAL_IFX6X60) += ifx6x60.o | ||
diff --git a/drivers/serial/ifx6x60.c b/drivers/serial/ifx6x60.c new file mode 100644 index 000000000000..b9b7e0601961 --- /dev/null +++ b/drivers/serial/ifx6x60.c | |||
@@ -0,0 +1,1402 @@ | |||
1 | /**************************************************************************** | ||
2 | * | ||
3 | * Driver for the IFX 6x60 spi modem. | ||
4 | * | ||
5 | * Copyright (C) 2008 Option International | ||
6 | * Copyright (C) 2008 Filip Aben <f.aben@option.com> | ||
7 | * Denis Joseph Barrow <d.barow@option.com> | ||
8 | * Jan Dumon <j.dumon@option.com> | ||
9 | * | ||
10 | * Copyright (C) 2009, 2010 Intel Corp | ||
11 | * Russ Gorby <richardx.r.gorby@intel.com> | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or modify | ||
14 | * it under the terms of the GNU General Public License version 2 as | ||
15 | * published by the Free Software Foundation. | ||
16 | * | ||
17 | * This program is distributed in the hope that it will be useful, | ||
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
20 | * GNU General Public License for more details. | ||
21 | * | ||
22 | * You should have received a copy of the GNU General Public License | ||
23 | * along with this program; if not, write to the Free Software | ||
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | ||
25 | * USA | ||
26 | * | ||
27 | * Driver modified by Intel from Option gtm501l_spi.c | ||
28 | * | ||
29 | * Notes | ||
30 | * o The driver currently assumes a single device only. If you need to | ||
31 | * change this then look for saved_ifx_dev and add a device lookup | ||
32 | * o The driver is intended to be big-endian safe but has never been | ||
33 | * tested that way (no suitable hardware). There are a couple of FIXME | ||
34 | * notes by areas that may need addressing | ||
35 | * o Some of the GPIO naming/setup assumptions may need revisiting if | ||
36 | * you need to use this driver for another platform. | ||
37 | * | ||
38 | *****************************************************************************/ | ||
39 | #include <linux/module.h> | ||
40 | #include <linux/termios.h> | ||
41 | #include <linux/tty.h> | ||
42 | #include <linux/device.h> | ||
43 | #include <linux/spi/spi.h> | ||
44 | #include <linux/tty.h> | ||
45 | #include <linux/kfifo.h> | ||
46 | #include <linux/tty_flip.h> | ||
47 | #include <linux/timer.h> | ||
48 | #include <linux/serial.h> | ||
49 | #include <linux/interrupt.h> | ||
50 | #include <linux/irq.h> | ||
51 | #include <linux/rfkill.h> | ||
52 | #include <linux/fs.h> | ||
53 | #include <linux/ip.h> | ||
54 | #include <linux/dmapool.h> | ||
55 | #include <linux/gpio.h> | ||
56 | #include <linux/sched.h> | ||
57 | #include <linux/time.h> | ||
58 | #include <linux/wait.h> | ||
59 | #include <linux/tty.h> | ||
60 | #include <linux/pm.h> | ||
61 | #include <linux/pm_runtime.h> | ||
62 | #include <linux/spi/ifx_modem.h> | ||
63 | |||
64 | #include "ifx6x60.h" | ||
65 | |||
66 | #define IFX_SPI_MORE_MASK 0x10 | ||
67 | #define IFX_SPI_MORE_BIT 12 /* bit position in u16 */ | ||
68 | #define IFX_SPI_CTS_BIT 13 /* bit position in u16 */ | ||
69 | #define IFX_SPI_TTY_ID 0 | ||
70 | #define IFX_SPI_TIMEOUT_SEC 2 | ||
71 | #define IFX_SPI_HEADER_0 (-1) | ||
72 | #define IFX_SPI_HEADER_F (-2) | ||
73 | |||
74 | /* forward reference */ | ||
75 | static void ifx_spi_handle_srdy(struct ifx_spi_device *ifx_dev); | ||
76 | |||
77 | /* local variables */ | ||
78 | static int spi_b16 = 1; /* 8 or 16 bit word length */ | ||
79 | static struct tty_driver *tty_drv; | ||
80 | static struct ifx_spi_device *saved_ifx_dev; | ||
81 | static struct lock_class_key ifx_spi_key; | ||
82 | |||
83 | /* GPIO/GPE settings */ | ||
84 | |||
85 | /** | ||
86 | * mrdy_set_high - set MRDY GPIO | ||
87 | * @ifx: device we are controlling | ||
88 | * | ||
89 | */ | ||
90 | static inline void mrdy_set_high(struct ifx_spi_device *ifx) | ||
91 | { | ||
92 | gpio_set_value(ifx->gpio.mrdy, 1); | ||
93 | } | ||
94 | |||
95 | /** | ||
96 | * mrdy_set_low - clear MRDY GPIO | ||
97 | * @ifx: device we are controlling | ||
98 | * | ||
99 | */ | ||
100 | static inline void mrdy_set_low(struct ifx_spi_device *ifx) | ||
101 | { | ||
102 | gpio_set_value(ifx->gpio.mrdy, 0); | ||
103 | } | ||
104 | |||
105 | /** | ||
106 | * ifx_spi_power_state_set | ||
107 | * @ifx_dev: our SPI device | ||
108 | * @val: bits to set | ||
109 | * | ||
110 | * Set bit in power status and signal power system if status becomes non-0 | ||
111 | */ | ||
112 | static void | ||
113 | ifx_spi_power_state_set(struct ifx_spi_device *ifx_dev, unsigned char val) | ||
114 | { | ||
115 | unsigned long flags; | ||
116 | |||
117 | spin_lock_irqsave(&ifx_dev->power_lock, flags); | ||
118 | |||
119 | /* | ||
120 | * if power status is already non-0, just update, else | ||
121 | * tell power system | ||
122 | */ | ||
123 | if (!ifx_dev->power_status) | ||
124 | pm_runtime_get(&ifx_dev->spi_dev->dev); | ||
125 | ifx_dev->power_status |= val; | ||
126 | |||
127 | spin_unlock_irqrestore(&ifx_dev->power_lock, flags); | ||
128 | } | ||
129 | |||
130 | /** | ||
131 | * ifx_spi_power_state_clear - clear power bit | ||
132 | * @ifx_dev: our SPI device | ||
133 | * @val: bits to clear | ||
134 | * | ||
135 | * clear bit in power status and signal power system if status becomes 0 | ||
136 | */ | ||
137 | static void | ||
138 | ifx_spi_power_state_clear(struct ifx_spi_device *ifx_dev, unsigned char val) | ||
139 | { | ||
140 | unsigned long flags; | ||
141 | |||
142 | spin_lock_irqsave(&ifx_dev->power_lock, flags); | ||
143 | |||
144 | if (ifx_dev->power_status) { | ||
145 | ifx_dev->power_status &= ~val; | ||
146 | if (!ifx_dev->power_status) | ||
147 | pm_runtime_put(&ifx_dev->spi_dev->dev); | ||
148 | } | ||
149 | |||
150 | spin_unlock_irqrestore(&ifx_dev->power_lock, flags); | ||
151 | } | ||
152 | |||
153 | /** | ||
154 | * swap_buf | ||
155 | * @buf: our buffer | ||
156 | * @len : number of bytes (not words) in the buffer | ||
157 | * @end: end of buffer | ||
158 | * | ||
159 | * Swap the contents of a buffer into big endian format | ||
160 | */ | ||
161 | static inline void swap_buf(u16 *buf, int len, void *end) | ||
162 | { | ||
163 | int n; | ||
164 | |||
165 | len = ((len + 1) >> 1); | ||
166 | if ((void *)&buf[len] > end) { | ||
167 | pr_err("swap_buf: swap exceeds boundary (%p > %p)!", | ||
168 | &buf[len], end); | ||
169 | return; | ||
170 | } | ||
171 | for (n = 0; n < len; n++) { | ||
172 | *buf = cpu_to_be16(*buf); | ||
173 | buf++; | ||
174 | } | ||
175 | } | ||
176 | |||
177 | /** | ||
178 | * mrdy_assert - assert MRDY line | ||
179 | * @ifx_dev: our SPI device | ||
180 | * | ||
181 | * Assert mrdy and set timer to wait for SRDY interrupt, if SRDY is low | ||
182 | * now. | ||
183 | * | ||
184 | * FIXME: Can SRDY even go high as we are running this code ? | ||
185 | */ | ||
186 | static void mrdy_assert(struct ifx_spi_device *ifx_dev) | ||
187 | { | ||
188 | int val = gpio_get_value(ifx_dev->gpio.srdy); | ||
189 | if (!val) { | ||
190 | if (!test_and_set_bit(IFX_SPI_STATE_TIMER_PENDING, | ||
191 | &ifx_dev->flags)) { | ||
192 | ifx_dev->spi_timer.expires = | ||
193 | jiffies + IFX_SPI_TIMEOUT_SEC*HZ; | ||
194 | add_timer(&ifx_dev->spi_timer); | ||
195 | |||
196 | } | ||
197 | } | ||
198 | ifx_spi_power_state_set(ifx_dev, IFX_SPI_POWER_DATA_PENDING); | ||
199 | mrdy_set_high(ifx_dev); | ||
200 | } | ||
201 | |||
202 | /** | ||
203 | * ifx_spi_hangup - hang up an IFX device | ||
204 | * @ifx_dev: our SPI device | ||
205 | * | ||
206 | * Hang up the tty attached to the IFX device if one is currently | ||
207 | * open. If not take no action | ||
208 | */ | ||
209 | static void ifx_spi_ttyhangup(struct ifx_spi_device *ifx_dev) | ||
210 | { | ||
211 | struct tty_port *pport = &ifx_dev->tty_port; | ||
212 | struct tty_struct *tty = tty_port_tty_get(pport); | ||
213 | if (tty) { | ||
214 | tty_hangup(tty); | ||
215 | tty_kref_put(tty); | ||
216 | } | ||
217 | } | ||
218 | |||
219 | /** | ||
220 | * ifx_spi_timeout - SPI timeout | ||
221 | * @arg: our SPI device | ||
222 | * | ||
223 | * The SPI has timed out: hang up the tty. Users will then see a hangup | ||
224 | * and error events. | ||
225 | */ | ||
226 | static void ifx_spi_timeout(unsigned long arg) | ||
227 | { | ||
228 | struct ifx_spi_device *ifx_dev = (struct ifx_spi_device *)arg; | ||
229 | |||
230 | dev_warn(&ifx_dev->spi_dev->dev, "*** SPI Timeout ***"); | ||
231 | ifx_spi_ttyhangup(ifx_dev); | ||
232 | mrdy_set_low(ifx_dev); | ||
233 | clear_bit(IFX_SPI_STATE_TIMER_PENDING, &ifx_dev->flags); | ||
234 | } | ||
235 | |||
236 | /* char/tty operations */ | ||
237 | |||
238 | /** | ||
239 | * ifx_spi_tiocmget - get modem lines | ||
240 | * @tty: our tty device | ||
241 | * @filp: file handle issuing the request | ||
242 | * | ||
243 | * Map the signal state into Linux modem flags and report the value | ||
244 | * in Linux terms | ||
245 | */ | ||
246 | static int ifx_spi_tiocmget(struct tty_struct *tty, struct file *filp) | ||
247 | { | ||
248 | unsigned int value; | ||
249 | struct ifx_spi_device *ifx_dev = tty->driver_data; | ||
250 | |||
251 | value = | ||
252 | (test_bit(IFX_SPI_RTS, &ifx_dev->signal_state) ? TIOCM_RTS : 0) | | ||
253 | (test_bit(IFX_SPI_DTR, &ifx_dev->signal_state) ? TIOCM_DTR : 0) | | ||
254 | (test_bit(IFX_SPI_CTS, &ifx_dev->signal_state) ? TIOCM_CTS : 0) | | ||
255 | (test_bit(IFX_SPI_DSR, &ifx_dev->signal_state) ? TIOCM_DSR : 0) | | ||
256 | (test_bit(IFX_SPI_DCD, &ifx_dev->signal_state) ? TIOCM_CAR : 0) | | ||
257 | (test_bit(IFX_SPI_RI, &ifx_dev->signal_state) ? TIOCM_RNG : 0); | ||
258 | return value; | ||
259 | } | ||
260 | |||
261 | /** | ||
262 | * ifx_spi_tiocmset - set modem bits | ||
263 | * @tty: the tty structure | ||
264 | * @filp: file handle issuing the request | ||
265 | * @set: bits to set | ||
266 | * @clear: bits to clear | ||
267 | * | ||
268 | * The IFX6x60 only supports DTR and RTS. Set them accordingly | ||
269 | * and flag that an update to the modem is needed. | ||
270 | * | ||
271 | * FIXME: do we need to kick the tranfers when we do this ? | ||
272 | */ | ||
273 | static int ifx_spi_tiocmset(struct tty_struct *tty, struct file *filp, | ||
274 | unsigned int set, unsigned int clear) | ||
275 | { | ||
276 | struct ifx_spi_device *ifx_dev = tty->driver_data; | ||
277 | |||
278 | if (set & TIOCM_RTS) | ||
279 | set_bit(IFX_SPI_RTS, &ifx_dev->signal_state); | ||
280 | if (set & TIOCM_DTR) | ||
281 | set_bit(IFX_SPI_DTR, &ifx_dev->signal_state); | ||
282 | if (clear & TIOCM_RTS) | ||
283 | clear_bit(IFX_SPI_RTS, &ifx_dev->signal_state); | ||
284 | if (clear & TIOCM_DTR) | ||
285 | clear_bit(IFX_SPI_DTR, &ifx_dev->signal_state); | ||
286 | |||
287 | set_bit(IFX_SPI_UPDATE, &ifx_dev->signal_state); | ||
288 | return 0; | ||
289 | } | ||
290 | |||
291 | /** | ||
292 | * ifx_spi_open - called on tty open | ||
293 | * @tty: our tty device | ||
294 | * @filp: file handle being associated with the tty | ||
295 | * | ||
296 | * Open the tty interface. We let the tty_port layer do all the work | ||
297 | * for us. | ||
298 | * | ||
299 | * FIXME: Remove single device assumption and saved_ifx_dev | ||
300 | */ | ||
301 | static int ifx_spi_open(struct tty_struct *tty, struct file *filp) | ||
302 | { | ||
303 | return tty_port_open(&saved_ifx_dev->tty_port, tty, filp); | ||
304 | } | ||
305 | |||
306 | /** | ||
307 | * ifx_spi_close - called when our tty closes | ||
308 | * @tty: the tty being closed | ||
309 | * @filp: the file handle being closed | ||
310 | * | ||
311 | * Perform the close of the tty. We use the tty_port layer to do all | ||
312 | * our hard work. | ||
313 | */ | ||
314 | static void ifx_spi_close(struct tty_struct *tty, struct file *filp) | ||
315 | { | ||
316 | struct ifx_spi_device *ifx_dev = tty->driver_data; | ||
317 | tty_port_close(&ifx_dev->tty_port, tty, filp); | ||
318 | /* FIXME: should we do an ifx_spi_reset here ? */ | ||
319 | } | ||
320 | |||
321 | /** | ||
322 | * ifx_decode_spi_header - decode received header | ||
323 | * @buffer: the received data | ||
324 | * @length: decoded length | ||
325 | * @more: decoded more flag | ||
326 | * @received_cts: status of cts we received | ||
327 | * | ||
328 | * Note how received_cts is handled -- if header is all F it is left | ||
329 | * the same as it was, if header is all 0 it is set to 0 otherwise it is | ||
330 | * taken from the incoming header. | ||
331 | * | ||
332 | * FIXME: endianness | ||
333 | */ | ||
334 | static int ifx_spi_decode_spi_header(unsigned char *buffer, int *length, | ||
335 | unsigned char *more, unsigned char *received_cts) | ||
336 | { | ||
337 | u16 h1; | ||
338 | u16 h2; | ||
339 | u16 *in_buffer = (u16 *)buffer; | ||
340 | |||
341 | h1 = *in_buffer; | ||
342 | h2 = *(in_buffer+1); | ||
343 | |||
344 | if (h1 == 0 && h2 == 0) { | ||
345 | *received_cts = 0; | ||
346 | return IFX_SPI_HEADER_0; | ||
347 | } else if (h1 == 0xffff && h2 == 0xffff) { | ||
348 | /* spi_slave_cts remains as it was */ | ||
349 | return IFX_SPI_HEADER_F; | ||
350 | } | ||
351 | |||
352 | *length = h1 & 0xfff; /* upper bits of byte are flags */ | ||
353 | *more = (buffer[1] >> IFX_SPI_MORE_BIT) & 1; | ||
354 | *received_cts = (buffer[3] >> IFX_SPI_CTS_BIT) & 1; | ||
355 | return 0; | ||
356 | } | ||
357 | |||
358 | /** | ||
359 | * ifx_setup_spi_header - set header fields | ||
360 | * @txbuffer: pointer to start of SPI buffer | ||
361 | * @tx_count: bytes | ||
362 | * @more: indicate if more to follow | ||
363 | * | ||
364 | * Format up an SPI header for a transfer | ||
365 | * | ||
366 | * FIXME: endianness? | ||
367 | */ | ||
368 | static void ifx_spi_setup_spi_header(unsigned char *txbuffer, int tx_count, | ||
369 | unsigned char more) | ||
370 | { | ||
371 | *(u16 *)(txbuffer) = tx_count; | ||
372 | *(u16 *)(txbuffer+2) = IFX_SPI_PAYLOAD_SIZE; | ||
373 | txbuffer[1] |= (more << IFX_SPI_MORE_BIT) & IFX_SPI_MORE_MASK; | ||
374 | } | ||
375 | |||
376 | /** | ||
377 | * ifx_spi_wakeup_serial - SPI space made | ||
378 | * @port_data: our SPI device | ||
379 | * | ||
380 | * We have emptied the FIFO enough that we want to get more data | ||
381 | * queued into it. Poke the line discipline via tty_wakeup so that | ||
382 | * it will feed us more bits | ||
383 | */ | ||
384 | static void ifx_spi_wakeup_serial(struct ifx_spi_device *ifx_dev) | ||
385 | { | ||
386 | struct tty_struct *tty; | ||
387 | |||
388 | tty = tty_port_tty_get(&ifx_dev->tty_port); | ||
389 | if (!tty) | ||
390 | return; | ||
391 | tty_wakeup(tty); | ||
392 | tty_kref_put(tty); | ||
393 | } | ||
394 | |||
395 | /** | ||
396 | * ifx_spi_prepare_tx_buffer - prepare transmit frame | ||
397 | * @ifx_dev: our SPI device | ||
398 | * | ||
399 | * The transmit buffr needs a header and various other bits of | ||
400 | * information followed by as much data as we can pull from the FIFO | ||
401 | * and transfer. This function formats up a suitable buffer in the | ||
402 | * ifx_dev->tx_buffer | ||
403 | * | ||
404 | * FIXME: performance - should we wake the tty when the queue is half | ||
405 | * empty ? | ||
406 | */ | ||
407 | static int ifx_spi_prepare_tx_buffer(struct ifx_spi_device *ifx_dev) | ||
408 | { | ||
409 | int temp_count; | ||
410 | int queue_length; | ||
411 | int tx_count; | ||
412 | unsigned char *tx_buffer; | ||
413 | |||
414 | tx_buffer = ifx_dev->tx_buffer; | ||
415 | memset(tx_buffer, 0, IFX_SPI_TRANSFER_SIZE); | ||
416 | |||
417 | /* make room for required SPI header */ | ||
418 | tx_buffer += IFX_SPI_HEADER_OVERHEAD; | ||
419 | tx_count = IFX_SPI_HEADER_OVERHEAD; | ||
420 | |||
421 | /* clear to signal no more data if this turns out to be the | ||
422 | * last buffer sent in a sequence */ | ||
423 | ifx_dev->spi_more = 0; | ||
424 | |||
425 | /* if modem cts is set, just send empty buffer */ | ||
426 | if (!ifx_dev->spi_slave_cts) { | ||
427 | /* see if there's tx data */ | ||
428 | queue_length = kfifo_len(&ifx_dev->tx_fifo); | ||
429 | if (queue_length != 0) { | ||
430 | /* data to mux -- see if there's room for it */ | ||
431 | temp_count = min(queue_length, IFX_SPI_PAYLOAD_SIZE); | ||
432 | temp_count = kfifo_out_locked(&ifx_dev->tx_fifo, | ||
433 | tx_buffer, temp_count, | ||
434 | &ifx_dev->fifo_lock); | ||
435 | |||
436 | /* update buffer pointer and data count in message */ | ||
437 | tx_buffer += temp_count; | ||
438 | tx_count += temp_count; | ||
439 | if (temp_count == queue_length) | ||
440 | /* poke port to get more data */ | ||
441 | ifx_spi_wakeup_serial(ifx_dev); | ||
442 | else /* more data in port, use next SPI message */ | ||
443 | ifx_dev->spi_more = 1; | ||
444 | } | ||
445 | } | ||
446 | /* have data and info for header -- set up SPI header in buffer */ | ||
447 | /* spi header needs payload size, not entire buffer size */ | ||
448 | ifx_spi_setup_spi_header(ifx_dev->tx_buffer, | ||
449 | tx_count-IFX_SPI_HEADER_OVERHEAD, | ||
450 | ifx_dev->spi_more); | ||
451 | /* swap actual data in the buffer */ | ||
452 | swap_buf((u16 *)(ifx_dev->tx_buffer), tx_count, | ||
453 | &ifx_dev->tx_buffer[IFX_SPI_TRANSFER_SIZE]); | ||
454 | return tx_count; | ||
455 | } | ||
456 | |||
457 | /** | ||
458 | * ifx_spi_write - line discipline write | ||
459 | * @tty: our tty device | ||
460 | * @buf: pointer to buffer to write (kernel space) | ||
461 | * @count: size of buffer | ||
462 | * | ||
463 | * Write the characters we have been given into the FIFO. If the device | ||
464 | * is not active then activate it, when the SRDY line is asserted back | ||
465 | * this will commence I/O | ||
466 | */ | ||
467 | static int ifx_spi_write(struct tty_struct *tty, const unsigned char *buf, | ||
468 | int count) | ||
469 | { | ||
470 | struct ifx_spi_device *ifx_dev = tty->driver_data; | ||
471 | unsigned char *tmp_buf = (unsigned char *)buf; | ||
472 | int tx_count = kfifo_in_locked(&ifx_dev->tx_fifo, tmp_buf, count, | ||
473 | &ifx_dev->fifo_lock); | ||
474 | mrdy_assert(ifx_dev); | ||
475 | return tx_count; | ||
476 | } | ||
477 | |||
478 | /** | ||
479 | * ifx_spi_chars_in_buffer - line discipline helper | ||
480 | * @tty: our tty device | ||
481 | * | ||
482 | * Report how much data we can accept before we drop bytes. As we use | ||
483 | * a simple FIFO this is nice and easy. | ||
484 | */ | ||
485 | static int ifx_spi_write_room(struct tty_struct *tty) | ||
486 | { | ||
487 | struct ifx_spi_device *ifx_dev = tty->driver_data; | ||
488 | return IFX_SPI_FIFO_SIZE - kfifo_len(&ifx_dev->tx_fifo); | ||
489 | } | ||
490 | |||
491 | /** | ||
492 | * ifx_spi_chars_in_buffer - line discipline helper | ||
493 | * @tty: our tty device | ||
494 | * | ||
495 | * Report how many characters we have buffered. In our case this is the | ||
496 | * number of bytes sitting in our transmit FIFO. | ||
497 | */ | ||
498 | static int ifx_spi_chars_in_buffer(struct tty_struct *tty) | ||
499 | { | ||
500 | struct ifx_spi_device *ifx_dev = tty->driver_data; | ||
501 | return kfifo_len(&ifx_dev->tx_fifo); | ||
502 | } | ||
503 | |||
504 | /** | ||
505 | * ifx_port_hangup | ||
506 | * @port: our tty port | ||
507 | * | ||
508 | * tty port hang up. Called when tty_hangup processing is invoked either | ||
509 | * by loss of carrier, or by software (eg vhangup). Serialized against | ||
510 | * activate/shutdown by the tty layer. | ||
511 | */ | ||
512 | static void ifx_spi_hangup(struct tty_struct *tty) | ||
513 | { | ||
514 | struct ifx_spi_device *ifx_dev = tty->driver_data; | ||
515 | tty_port_hangup(&ifx_dev->tty_port); | ||
516 | } | ||
517 | |||
518 | /** | ||
519 | * ifx_port_activate | ||
520 | * @port: our tty port | ||
521 | * | ||
522 | * tty port activate method - called for first open. Serialized | ||
523 | * with hangup and shutdown by the tty layer. | ||
524 | */ | ||
525 | static int ifx_port_activate(struct tty_port *port, struct tty_struct *tty) | ||
526 | { | ||
527 | struct ifx_spi_device *ifx_dev = | ||
528 | container_of(port, struct ifx_spi_device, tty_port); | ||
529 | |||
530 | /* clear any old data; can't do this in 'close' */ | ||
531 | kfifo_reset(&ifx_dev->tx_fifo); | ||
532 | |||
533 | /* put port data into this tty */ | ||
534 | tty->driver_data = ifx_dev; | ||
535 | |||
536 | /* allows flip string push from int context */ | ||
537 | tty->low_latency = 1; | ||
538 | |||
539 | return 0; | ||
540 | } | ||
541 | |||
542 | /** | ||
543 | * ifx_port_shutdown | ||
544 | * @port: our tty port | ||
545 | * | ||
546 | * tty port shutdown method - called for last port close. Serialized | ||
547 | * with hangup and activate by the tty layer. | ||
548 | */ | ||
549 | static void ifx_port_shutdown(struct tty_port *port) | ||
550 | { | ||
551 | struct ifx_spi_device *ifx_dev = | ||
552 | container_of(port, struct ifx_spi_device, tty_port); | ||
553 | |||
554 | mrdy_set_low(ifx_dev); | ||
555 | clear_bit(IFX_SPI_STATE_TIMER_PENDING, &ifx_dev->flags); | ||
556 | tasklet_kill(&ifx_dev->io_work_tasklet); | ||
557 | } | ||
558 | |||
559 | static const struct tty_port_operations ifx_tty_port_ops = { | ||
560 | .activate = ifx_port_activate, | ||
561 | .shutdown = ifx_port_shutdown, | ||
562 | }; | ||
563 | |||
564 | static const struct tty_operations ifx_spi_serial_ops = { | ||
565 | .open = ifx_spi_open, | ||
566 | .close = ifx_spi_close, | ||
567 | .write = ifx_spi_write, | ||
568 | .hangup = ifx_spi_hangup, | ||
569 | .write_room = ifx_spi_write_room, | ||
570 | .chars_in_buffer = ifx_spi_chars_in_buffer, | ||
571 | .tiocmget = ifx_spi_tiocmget, | ||
572 | .tiocmset = ifx_spi_tiocmset, | ||
573 | }; | ||
574 | |||
575 | /** | ||
576 | * ifx_spi_insert_fip_string - queue received data | ||
577 | * @ifx_ser: our SPI device | ||
578 | * @chars: buffer we have received | ||
579 | * @size: number of chars reeived | ||
580 | * | ||
581 | * Queue bytes to the tty assuming the tty side is currently open. If | ||
582 | * not the discard the data. | ||
583 | */ | ||
584 | static void ifx_spi_insert_flip_string(struct ifx_spi_device *ifx_dev, | ||
585 | unsigned char *chars, size_t size) | ||
586 | { | ||
587 | struct tty_struct *tty = tty_port_tty_get(&ifx_dev->tty_port); | ||
588 | if (!tty) | ||
589 | return; | ||
590 | tty_insert_flip_string(tty, chars, size); | ||
591 | tty_flip_buffer_push(tty); | ||
592 | tty_kref_put(tty); | ||
593 | } | ||
594 | |||
595 | /** | ||
596 | * ifx_spi_complete - SPI transfer completed | ||
597 | * @ctx: our SPI device | ||
598 | * | ||
599 | * An SPI transfer has completed. Process any received data and kick off | ||
600 | * any further transmits we can commence. | ||
601 | */ | ||
602 | static void ifx_spi_complete(void *ctx) | ||
603 | { | ||
604 | struct ifx_spi_device *ifx_dev = ctx; | ||
605 | struct tty_struct *tty; | ||
606 | struct tty_ldisc *ldisc = NULL; | ||
607 | int length; | ||
608 | int actual_length; | ||
609 | unsigned char more; | ||
610 | unsigned char cts; | ||
611 | int local_write_pending = 0; | ||
612 | int queue_length; | ||
613 | int srdy; | ||
614 | int decode_result; | ||
615 | |||
616 | mrdy_set_low(ifx_dev); | ||
617 | |||
618 | if (!ifx_dev->spi_msg.status) { | ||
619 | /* check header validity, get comm flags */ | ||
620 | swap_buf((u16 *)ifx_dev->rx_buffer, IFX_SPI_HEADER_OVERHEAD, | ||
621 | &ifx_dev->rx_buffer[IFX_SPI_HEADER_OVERHEAD]); | ||
622 | decode_result = ifx_spi_decode_spi_header(ifx_dev->rx_buffer, | ||
623 | &length, &more, &cts); | ||
624 | if (decode_result == IFX_SPI_HEADER_0) { | ||
625 | dev_dbg(&ifx_dev->spi_dev->dev, | ||
626 | "ignore input: invalid header 0"); | ||
627 | ifx_dev->spi_slave_cts = 0; | ||
628 | goto complete_exit; | ||
629 | } else if (decode_result == IFX_SPI_HEADER_F) { | ||
630 | dev_dbg(&ifx_dev->spi_dev->dev, | ||
631 | "ignore input: invalid header F"); | ||
632 | goto complete_exit; | ||
633 | } | ||
634 | |||
635 | ifx_dev->spi_slave_cts = cts; | ||
636 | |||
637 | actual_length = min((unsigned int)length, | ||
638 | ifx_dev->spi_msg.actual_length); | ||
639 | swap_buf((u16 *)(ifx_dev->rx_buffer + IFX_SPI_HEADER_OVERHEAD), | ||
640 | actual_length, | ||
641 | &ifx_dev->rx_buffer[IFX_SPI_TRANSFER_SIZE]); | ||
642 | ifx_spi_insert_flip_string( | ||
643 | ifx_dev, | ||
644 | ifx_dev->rx_buffer + IFX_SPI_HEADER_OVERHEAD, | ||
645 | (size_t)actual_length); | ||
646 | } else { | ||
647 | dev_dbg(&ifx_dev->spi_dev->dev, "SPI transfer error %d", | ||
648 | ifx_dev->spi_msg.status); | ||
649 | } | ||
650 | |||
651 | complete_exit: | ||
652 | if (ifx_dev->write_pending) { | ||
653 | ifx_dev->write_pending = 0; | ||
654 | local_write_pending = 1; | ||
655 | } | ||
656 | |||
657 | clear_bit(IFX_SPI_STATE_IO_IN_PROGRESS, &(ifx_dev->flags)); | ||
658 | |||
659 | queue_length = kfifo_len(&ifx_dev->tx_fifo); | ||
660 | srdy = gpio_get_value(ifx_dev->gpio.srdy); | ||
661 | if (!srdy) | ||
662 | ifx_spi_power_state_clear(ifx_dev, IFX_SPI_POWER_SRDY); | ||
663 | |||
664 | /* schedule output if there is more to do */ | ||
665 | if (test_and_clear_bit(IFX_SPI_STATE_IO_READY, &ifx_dev->flags)) | ||
666 | tasklet_schedule(&ifx_dev->io_work_tasklet); | ||
667 | else { | ||
668 | if (more || ifx_dev->spi_more || queue_length > 0 || | ||
669 | local_write_pending) { | ||
670 | if (ifx_dev->spi_slave_cts) { | ||
671 | if (more) | ||
672 | mrdy_assert(ifx_dev); | ||
673 | } else | ||
674 | mrdy_assert(ifx_dev); | ||
675 | } else { | ||
676 | /* | ||
677 | * poke line discipline driver if any for more data | ||
678 | * may or may not get more data to write | ||
679 | * for now, say not busy | ||
680 | */ | ||
681 | ifx_spi_power_state_clear(ifx_dev, | ||
682 | IFX_SPI_POWER_DATA_PENDING); | ||
683 | tty = tty_port_tty_get(&ifx_dev->tty_port); | ||
684 | if (tty) { | ||
685 | ldisc = tty_ldisc_ref(tty); | ||
686 | if (ldisc) { | ||
687 | ldisc->ops->write_wakeup(tty); | ||
688 | tty_ldisc_deref(ldisc); | ||
689 | } | ||
690 | tty_kref_put(tty); | ||
691 | } | ||
692 | } | ||
693 | } | ||
694 | } | ||
695 | |||
696 | /** | ||
697 | * ifx_spio_io - I/O tasklet | ||
698 | * @data: our SPI device | ||
699 | * | ||
700 | * Queue data for transmission if possible and then kick off the | ||
701 | * transfer. | ||
702 | */ | ||
703 | static void ifx_spi_io(unsigned long data) | ||
704 | { | ||
705 | int retval; | ||
706 | struct ifx_spi_device *ifx_dev = (struct ifx_spi_device *) data; | ||
707 | |||
708 | if (!test_and_set_bit(IFX_SPI_STATE_IO_IN_PROGRESS, &ifx_dev->flags)) { | ||
709 | if (ifx_dev->gpio.unack_srdy_int_nb > 0) | ||
710 | ifx_dev->gpio.unack_srdy_int_nb--; | ||
711 | |||
712 | ifx_spi_prepare_tx_buffer(ifx_dev); | ||
713 | |||
714 | spi_message_init(&ifx_dev->spi_msg); | ||
715 | INIT_LIST_HEAD(&ifx_dev->spi_msg.queue); | ||
716 | |||
717 | ifx_dev->spi_msg.context = ifx_dev; | ||
718 | ifx_dev->spi_msg.complete = ifx_spi_complete; | ||
719 | |||
720 | /* set up our spi transfer */ | ||
721 | /* note len is BYTES, not transfers */ | ||
722 | ifx_dev->spi_xfer.len = IFX_SPI_TRANSFER_SIZE; | ||
723 | ifx_dev->spi_xfer.cs_change = 0; | ||
724 | ifx_dev->spi_xfer.speed_hz = 12500000; | ||
725 | /* ifx_dev->spi_xfer.speed_hz = 390625; */ | ||
726 | ifx_dev->spi_xfer.bits_per_word = spi_b16 ? 16 : 8; | ||
727 | |||
728 | ifx_dev->spi_xfer.tx_buf = ifx_dev->tx_buffer; | ||
729 | ifx_dev->spi_xfer.rx_buf = ifx_dev->rx_buffer; | ||
730 | |||
731 | /* | ||
732 | * setup dma pointers | ||
733 | */ | ||
734 | if (ifx_dev->is_6160) { | ||
735 | ifx_dev->spi_msg.is_dma_mapped = 1; | ||
736 | ifx_dev->tx_dma = ifx_dev->tx_bus; | ||
737 | ifx_dev->rx_dma = ifx_dev->rx_bus; | ||
738 | ifx_dev->spi_xfer.tx_dma = ifx_dev->tx_dma; | ||
739 | ifx_dev->spi_xfer.rx_dma = ifx_dev->rx_dma; | ||
740 | } else { | ||
741 | ifx_dev->spi_msg.is_dma_mapped = 0; | ||
742 | ifx_dev->tx_dma = (dma_addr_t)0; | ||
743 | ifx_dev->rx_dma = (dma_addr_t)0; | ||
744 | ifx_dev->spi_xfer.tx_dma = (dma_addr_t)0; | ||
745 | ifx_dev->spi_xfer.rx_dma = (dma_addr_t)0; | ||
746 | } | ||
747 | |||
748 | spi_message_add_tail(&ifx_dev->spi_xfer, &ifx_dev->spi_msg); | ||
749 | |||
750 | /* Assert MRDY. This may have already been done by the write | ||
751 | * routine. | ||
752 | */ | ||
753 | mrdy_assert(ifx_dev); | ||
754 | |||
755 | retval = spi_async(ifx_dev->spi_dev, &ifx_dev->spi_msg); | ||
756 | if (retval) { | ||
757 | clear_bit(IFX_SPI_STATE_IO_IN_PROGRESS, | ||
758 | &ifx_dev->flags); | ||
759 | tasklet_schedule(&ifx_dev->io_work_tasklet); | ||
760 | return; | ||
761 | } | ||
762 | } else | ||
763 | ifx_dev->write_pending = 1; | ||
764 | } | ||
765 | |||
766 | /** | ||
767 | * ifx_spi_free_port - free up the tty side | ||
768 | * @ifx_dev: IFX device going away | ||
769 | * | ||
770 | * Unregister and free up a port when the device goes away | ||
771 | */ | ||
772 | static void ifx_spi_free_port(struct ifx_spi_device *ifx_dev) | ||
773 | { | ||
774 | if (ifx_dev->tty_dev) | ||
775 | tty_unregister_device(tty_drv, ifx_dev->minor); | ||
776 | kfifo_free(&ifx_dev->tx_fifo); | ||
777 | } | ||
778 | |||
779 | /** | ||
780 | * ifx_spi_create_port - create a new port | ||
781 | * @ifx_dev: our spi device | ||
782 | * | ||
783 | * Allocate and initialise the tty port that goes with this interface | ||
784 | * and add it to the tty layer so that it can be opened. | ||
785 | */ | ||
786 | static int ifx_spi_create_port(struct ifx_spi_device *ifx_dev) | ||
787 | { | ||
788 | int ret = 0; | ||
789 | struct tty_port *pport = &ifx_dev->tty_port; | ||
790 | |||
791 | spin_lock_init(&ifx_dev->fifo_lock); | ||
792 | lockdep_set_class_and_subclass(&ifx_dev->fifo_lock, | ||
793 | &ifx_spi_key, 0); | ||
794 | |||
795 | if (kfifo_alloc(&ifx_dev->tx_fifo, IFX_SPI_FIFO_SIZE, GFP_KERNEL)) { | ||
796 | ret = -ENOMEM; | ||
797 | goto error_ret; | ||
798 | } | ||
799 | |||
800 | pport->ops = &ifx_tty_port_ops; | ||
801 | tty_port_init(pport); | ||
802 | ifx_dev->minor = IFX_SPI_TTY_ID; | ||
803 | ifx_dev->tty_dev = tty_register_device(tty_drv, ifx_dev->minor, | ||
804 | &ifx_dev->spi_dev->dev); | ||
805 | if (IS_ERR(ifx_dev->tty_dev)) { | ||
806 | dev_dbg(&ifx_dev->spi_dev->dev, | ||
807 | "%s: registering tty device failed", __func__); | ||
808 | ret = PTR_ERR(ifx_dev->tty_dev); | ||
809 | goto error_ret; | ||
810 | } | ||
811 | return 0; | ||
812 | |||
813 | error_ret: | ||
814 | ifx_spi_free_port(ifx_dev); | ||
815 | return ret; | ||
816 | } | ||
817 | |||
818 | /** | ||
819 | * ifx_spi_handle_srdy - handle SRDY | ||
820 | * @ifx_dev: device asserting SRDY | ||
821 | * | ||
822 | * Check our device state and see what we need to kick off when SRDY | ||
823 | * is asserted. This usually means killing the timer and firing off the | ||
824 | * I/O processing. | ||
825 | */ | ||
826 | static void ifx_spi_handle_srdy(struct ifx_spi_device *ifx_dev) | ||
827 | { | ||
828 | if (test_bit(IFX_SPI_STATE_TIMER_PENDING, &ifx_dev->flags)) { | ||
829 | del_timer_sync(&ifx_dev->spi_timer); | ||
830 | clear_bit(IFX_SPI_STATE_TIMER_PENDING, &ifx_dev->flags); | ||
831 | } | ||
832 | |||
833 | ifx_spi_power_state_set(ifx_dev, IFX_SPI_POWER_SRDY); | ||
834 | |||
835 | if (!test_bit(IFX_SPI_STATE_IO_IN_PROGRESS, &ifx_dev->flags)) | ||
836 | tasklet_schedule(&ifx_dev->io_work_tasklet); | ||
837 | else | ||
838 | set_bit(IFX_SPI_STATE_IO_READY, &ifx_dev->flags); | ||
839 | } | ||
840 | |||
841 | /** | ||
842 | * ifx_spi_srdy_interrupt - SRDY asserted | ||
843 | * @irq: our IRQ number | ||
844 | * @dev: our ifx device | ||
845 | * | ||
846 | * The modem asserted SRDY. Handle the srdy event | ||
847 | */ | ||
848 | static irqreturn_t ifx_spi_srdy_interrupt(int irq, void *dev) | ||
849 | { | ||
850 | struct ifx_spi_device *ifx_dev = dev; | ||
851 | ifx_dev->gpio.unack_srdy_int_nb++; | ||
852 | ifx_spi_handle_srdy(ifx_dev); | ||
853 | return IRQ_HANDLED; | ||
854 | } | ||
855 | |||
856 | /** | ||
857 | * ifx_spi_reset_interrupt - Modem has changed reset state | ||
858 | * @irq: interrupt number | ||
859 | * @dev: our device pointer | ||
860 | * | ||
861 | * The modem has either entered or left reset state. Check the GPIO | ||
862 | * line to see which. | ||
863 | * | ||
864 | * FIXME: review locking on MR_INPROGRESS versus | ||
865 | * parallel unsolicited reset/solicited reset | ||
866 | */ | ||
867 | static irqreturn_t ifx_spi_reset_interrupt(int irq, void *dev) | ||
868 | { | ||
869 | struct ifx_spi_device *ifx_dev = dev; | ||
870 | int val = gpio_get_value(ifx_dev->gpio.reset_out); | ||
871 | int solreset = test_bit(MR_START, &ifx_dev->mdm_reset_state); | ||
872 | |||
873 | if (val == 0) { | ||
874 | /* entered reset */ | ||
875 | set_bit(MR_INPROGRESS, &ifx_dev->mdm_reset_state); | ||
876 | if (!solreset) { | ||
877 | /* unsolicited reset */ | ||
878 | ifx_spi_ttyhangup(ifx_dev); | ||
879 | } | ||
880 | } else { | ||
881 | /* exited reset */ | ||
882 | clear_bit(MR_INPROGRESS, &ifx_dev->mdm_reset_state); | ||
883 | if (solreset) { | ||
884 | set_bit(MR_COMPLETE, &ifx_dev->mdm_reset_state); | ||
885 | wake_up(&ifx_dev->mdm_reset_wait); | ||
886 | } | ||
887 | } | ||
888 | return IRQ_HANDLED; | ||
889 | } | ||
890 | |||
891 | /** | ||
892 | * ifx_spi_free_device - free device | ||
893 | * @ifx_dev: device to free | ||
894 | * | ||
895 | * Free the IFX device | ||
896 | */ | ||
897 | static void ifx_spi_free_device(struct ifx_spi_device *ifx_dev) | ||
898 | { | ||
899 | ifx_spi_free_port(ifx_dev); | ||
900 | dma_free_coherent(&ifx_dev->spi_dev->dev, | ||
901 | IFX_SPI_TRANSFER_SIZE, | ||
902 | ifx_dev->tx_buffer, | ||
903 | ifx_dev->tx_bus); | ||
904 | dma_free_coherent(&ifx_dev->spi_dev->dev, | ||
905 | IFX_SPI_TRANSFER_SIZE, | ||
906 | ifx_dev->rx_buffer, | ||
907 | ifx_dev->rx_bus); | ||
908 | } | ||
909 | |||
910 | /** | ||
911 | * ifx_spi_reset - reset modem | ||
912 | * @ifx_dev: modem to reset | ||
913 | * | ||
914 | * Perform a reset on the modem | ||
915 | */ | ||
916 | static int ifx_spi_reset(struct ifx_spi_device *ifx_dev) | ||
917 | { | ||
918 | int ret; | ||
919 | /* | ||
920 | * set up modem power, reset | ||
921 | * | ||
922 | * delays are required on some platforms for the modem | ||
923 | * to reset properly | ||
924 | */ | ||
925 | set_bit(MR_START, &ifx_dev->mdm_reset_state); | ||
926 | gpio_set_value(ifx_dev->gpio.po, 0); | ||
927 | gpio_set_value(ifx_dev->gpio.reset, 0); | ||
928 | msleep(25); | ||
929 | gpio_set_value(ifx_dev->gpio.reset, 1); | ||
930 | msleep(1); | ||
931 | gpio_set_value(ifx_dev->gpio.po, 1); | ||
932 | msleep(1); | ||
933 | gpio_set_value(ifx_dev->gpio.po, 0); | ||
934 | ret = wait_event_timeout(ifx_dev->mdm_reset_wait, | ||
935 | test_bit(MR_COMPLETE, | ||
936 | &ifx_dev->mdm_reset_state), | ||
937 | IFX_RESET_TIMEOUT); | ||
938 | if (!ret) | ||
939 | dev_warn(&ifx_dev->spi_dev->dev, "Modem reset timeout: (state:%lx)", | ||
940 | ifx_dev->mdm_reset_state); | ||
941 | |||
942 | ifx_dev->mdm_reset_state = 0; | ||
943 | return ret; | ||
944 | } | ||
945 | |||
946 | /** | ||
947 | * ifx_spi_spi_probe - probe callback | ||
948 | * @spi: our possible matching SPI device | ||
949 | * | ||
950 | * Probe for a 6x60 modem on SPI bus. Perform any needed device and | ||
951 | * GPIO setup. | ||
952 | * | ||
953 | * FIXME: | ||
954 | * - Support for multiple devices | ||
955 | * - Split out MID specific GPIO handling eventually | ||
956 | */ | ||
957 | |||
958 | static int ifx_spi_spi_probe(struct spi_device *spi) | ||
959 | { | ||
960 | int ret; | ||
961 | int srdy; | ||
962 | struct ifx_modem_platform_data *pl_data = NULL; | ||
963 | struct ifx_spi_device *ifx_dev; | ||
964 | |||
965 | if (saved_ifx_dev) { | ||
966 | dev_dbg(&spi->dev, "ignoring subsequent detection"); | ||
967 | return -ENODEV; | ||
968 | } | ||
969 | |||
970 | /* initialize structure to hold our device variables */ | ||
971 | ifx_dev = kzalloc(sizeof(struct ifx_spi_device), GFP_KERNEL); | ||
972 | if (!ifx_dev) { | ||
973 | dev_err(&spi->dev, "spi device allocation failed"); | ||
974 | return -ENOMEM; | ||
975 | } | ||
976 | saved_ifx_dev = ifx_dev; | ||
977 | ifx_dev->spi_dev = spi; | ||
978 | clear_bit(IFX_SPI_STATE_IO_IN_PROGRESS, &ifx_dev->flags); | ||
979 | spin_lock_init(&ifx_dev->write_lock); | ||
980 | spin_lock_init(&ifx_dev->power_lock); | ||
981 | ifx_dev->power_status = 0; | ||
982 | init_timer(&ifx_dev->spi_timer); | ||
983 | ifx_dev->spi_timer.function = ifx_spi_timeout; | ||
984 | ifx_dev->spi_timer.data = (unsigned long)ifx_dev; | ||
985 | ifx_dev->is_6160 = pl_data->is_6160; | ||
986 | |||
987 | /* ensure SPI protocol flags are initialized to enable transfer */ | ||
988 | ifx_dev->spi_more = 0; | ||
989 | ifx_dev->spi_slave_cts = 0; | ||
990 | |||
991 | /*initialize transfer and dma buffers */ | ||
992 | ifx_dev->tx_buffer = dma_alloc_coherent(&ifx_dev->spi_dev->dev, | ||
993 | IFX_SPI_TRANSFER_SIZE, | ||
994 | &ifx_dev->tx_bus, | ||
995 | GFP_KERNEL); | ||
996 | if (!ifx_dev->tx_buffer) { | ||
997 | dev_err(&spi->dev, "DMA-TX buffer allocation failed"); | ||
998 | ret = -ENOMEM; | ||
999 | goto error_ret; | ||
1000 | } | ||
1001 | ifx_dev->rx_buffer = dma_alloc_coherent(&ifx_dev->spi_dev->dev, | ||
1002 | IFX_SPI_TRANSFER_SIZE, | ||
1003 | &ifx_dev->rx_bus, | ||
1004 | GFP_KERNEL); | ||
1005 | if (!ifx_dev->rx_buffer) { | ||
1006 | dev_err(&spi->dev, "DMA-RX buffer allocation failed"); | ||
1007 | ret = -ENOMEM; | ||
1008 | goto error_ret; | ||
1009 | } | ||
1010 | |||
1011 | /* initialize waitq for modem reset */ | ||
1012 | init_waitqueue_head(&ifx_dev->mdm_reset_wait); | ||
1013 | |||
1014 | spi_set_drvdata(spi, ifx_dev); | ||
1015 | tasklet_init(&ifx_dev->io_work_tasklet, ifx_spi_io, | ||
1016 | (unsigned long)ifx_dev); | ||
1017 | |||
1018 | set_bit(IFX_SPI_STATE_PRESENT, &ifx_dev->flags); | ||
1019 | |||
1020 | /* create our tty port */ | ||
1021 | ret = ifx_spi_create_port(ifx_dev); | ||
1022 | if (ret != 0) { | ||
1023 | dev_err(&spi->dev, "create default tty port failed"); | ||
1024 | goto error_ret; | ||
1025 | } | ||
1026 | |||
1027 | pl_data = (struct ifx_modem_platform_data *)spi->dev.platform_data; | ||
1028 | if (pl_data) { | ||
1029 | ifx_dev->gpio.reset = pl_data->rst_pmu; | ||
1030 | ifx_dev->gpio.po = pl_data->pwr_on; | ||
1031 | ifx_dev->gpio.mrdy = pl_data->mrdy; | ||
1032 | ifx_dev->gpio.srdy = pl_data->srdy; | ||
1033 | ifx_dev->gpio.reset_out = pl_data->rst_out; | ||
1034 | } else { | ||
1035 | dev_err(&spi->dev, "missing platform data!"); | ||
1036 | ret = -ENODEV; | ||
1037 | goto error_ret; | ||
1038 | } | ||
1039 | |||
1040 | dev_info(&spi->dev, "gpios %d, %d, %d, %d, %d", | ||
1041 | ifx_dev->gpio.reset, ifx_dev->gpio.po, ifx_dev->gpio.mrdy, | ||
1042 | ifx_dev->gpio.srdy, ifx_dev->gpio.reset_out); | ||
1043 | |||
1044 | /* Configure gpios */ | ||
1045 | ret = gpio_request(ifx_dev->gpio.reset, "ifxModem"); | ||
1046 | if (ret < 0) { | ||
1047 | dev_err(&spi->dev, "Unable to allocate GPIO%d (RESET)", | ||
1048 | ifx_dev->gpio.reset); | ||
1049 | goto error_ret; | ||
1050 | } | ||
1051 | ret += gpio_direction_output(ifx_dev->gpio.reset, 0); | ||
1052 | ret += gpio_export(ifx_dev->gpio.reset, 1); | ||
1053 | if (ret) { | ||
1054 | dev_err(&spi->dev, "Unable to configure GPIO%d (RESET)", | ||
1055 | ifx_dev->gpio.reset); | ||
1056 | ret = -EBUSY; | ||
1057 | goto error_ret2; | ||
1058 | } | ||
1059 | |||
1060 | ret = gpio_request(ifx_dev->gpio.po, "ifxModem"); | ||
1061 | ret += gpio_direction_output(ifx_dev->gpio.po, 0); | ||
1062 | ret += gpio_export(ifx_dev->gpio.po, 1); | ||
1063 | if (ret) { | ||
1064 | dev_err(&spi->dev, "Unable to configure GPIO%d (ON)", | ||
1065 | ifx_dev->gpio.po); | ||
1066 | ret = -EBUSY; | ||
1067 | goto error_ret3; | ||
1068 | } | ||
1069 | |||
1070 | ret = gpio_request(ifx_dev->gpio.mrdy, "ifxModem"); | ||
1071 | if (ret < 0) { | ||
1072 | dev_err(&spi->dev, "Unable to allocate GPIO%d (MRDY)", | ||
1073 | ifx_dev->gpio.mrdy); | ||
1074 | goto error_ret3; | ||
1075 | } | ||
1076 | ret += gpio_export(ifx_dev->gpio.mrdy, 1); | ||
1077 | ret += gpio_direction_output(ifx_dev->gpio.mrdy, 0); | ||
1078 | if (ret) { | ||
1079 | dev_err(&spi->dev, "Unable to configure GPIO%d (MRDY)", | ||
1080 | ifx_dev->gpio.mrdy); | ||
1081 | ret = -EBUSY; | ||
1082 | goto error_ret4; | ||
1083 | } | ||
1084 | |||
1085 | ret = gpio_request(ifx_dev->gpio.srdy, "ifxModem"); | ||
1086 | if (ret < 0) { | ||
1087 | dev_err(&spi->dev, "Unable to allocate GPIO%d (SRDY)", | ||
1088 | ifx_dev->gpio.srdy); | ||
1089 | ret = -EBUSY; | ||
1090 | goto error_ret4; | ||
1091 | } | ||
1092 | ret += gpio_export(ifx_dev->gpio.srdy, 1); | ||
1093 | ret += gpio_direction_input(ifx_dev->gpio.srdy); | ||
1094 | if (ret) { | ||
1095 | dev_err(&spi->dev, "Unable to configure GPIO%d (SRDY)", | ||
1096 | ifx_dev->gpio.srdy); | ||
1097 | ret = -EBUSY; | ||
1098 | goto error_ret5; | ||
1099 | } | ||
1100 | |||
1101 | ret = gpio_request(ifx_dev->gpio.reset_out, "ifxModem"); | ||
1102 | if (ret < 0) { | ||
1103 | dev_err(&spi->dev, "Unable to allocate GPIO%d (RESET_OUT)", | ||
1104 | ifx_dev->gpio.reset_out); | ||
1105 | goto error_ret5; | ||
1106 | } | ||
1107 | ret += gpio_export(ifx_dev->gpio.reset_out, 1); | ||
1108 | ret += gpio_direction_input(ifx_dev->gpio.reset_out); | ||
1109 | if (ret) { | ||
1110 | dev_err(&spi->dev, "Unable to configure GPIO%d (RESET_OUT)", | ||
1111 | ifx_dev->gpio.reset_out); | ||
1112 | ret = -EBUSY; | ||
1113 | goto error_ret6; | ||
1114 | } | ||
1115 | |||
1116 | ret = request_irq(gpio_to_irq(ifx_dev->gpio.reset_out), | ||
1117 | ifx_spi_reset_interrupt, | ||
1118 | IRQF_TRIGGER_RISING|IRQF_TRIGGER_FALLING, DRVNAME, | ||
1119 | (void *)ifx_dev); | ||
1120 | if (ret) { | ||
1121 | dev_err(&spi->dev, "Unable to get irq %x\n", | ||
1122 | gpio_to_irq(ifx_dev->gpio.reset_out)); | ||
1123 | goto error_ret6; | ||
1124 | } | ||
1125 | |||
1126 | ret = ifx_spi_reset(ifx_dev); | ||
1127 | |||
1128 | ret = request_irq(gpio_to_irq(ifx_dev->gpio.srdy), | ||
1129 | ifx_spi_srdy_interrupt, | ||
1130 | IRQF_TRIGGER_RISING, DRVNAME, | ||
1131 | (void *)ifx_dev); | ||
1132 | if (ret) { | ||
1133 | dev_err(&spi->dev, "Unable to get irq %x", | ||
1134 | gpio_to_irq(ifx_dev->gpio.srdy)); | ||
1135 | goto error_ret6; | ||
1136 | } | ||
1137 | |||
1138 | /* set pm runtime power state and register with power system */ | ||
1139 | pm_runtime_set_active(&spi->dev); | ||
1140 | pm_runtime_enable(&spi->dev); | ||
1141 | |||
1142 | /* handle case that modem is already signaling SRDY */ | ||
1143 | /* no outgoing tty open at this point, this just satisfies the | ||
1144 | * modem's read and should reset communication properly | ||
1145 | */ | ||
1146 | srdy = gpio_get_value(ifx_dev->gpio.srdy); | ||
1147 | |||
1148 | if (srdy) { | ||
1149 | mrdy_assert(ifx_dev); | ||
1150 | ifx_spi_handle_srdy(ifx_dev); | ||
1151 | } else | ||
1152 | mrdy_set_low(ifx_dev); | ||
1153 | return 0; | ||
1154 | |||
1155 | error_ret6: | ||
1156 | gpio_free(ifx_dev->gpio.srdy); | ||
1157 | error_ret5: | ||
1158 | gpio_free(ifx_dev->gpio.mrdy); | ||
1159 | error_ret4: | ||
1160 | gpio_free(ifx_dev->gpio.reset); | ||
1161 | error_ret3: | ||
1162 | gpio_free(ifx_dev->gpio.po); | ||
1163 | error_ret2: | ||
1164 | gpio_free(ifx_dev->gpio.reset_out); | ||
1165 | error_ret: | ||
1166 | ifx_spi_free_device(ifx_dev); | ||
1167 | saved_ifx_dev = NULL; | ||
1168 | return ret; | ||
1169 | } | ||
1170 | |||
1171 | /** | ||
1172 | * ifx_spi_spi_remove - SPI device was removed | ||
1173 | * @spi: SPI device | ||
1174 | * | ||
1175 | * FIXME: We should be shutting the device down here not in | ||
1176 | * the module unload path. | ||
1177 | */ | ||
1178 | |||
1179 | static int ifx_spi_spi_remove(struct spi_device *spi) | ||
1180 | { | ||
1181 | struct ifx_spi_device *ifx_dev = spi_get_drvdata(spi); | ||
1182 | /* stop activity */ | ||
1183 | tasklet_kill(&ifx_dev->io_work_tasklet); | ||
1184 | /* free irq */ | ||
1185 | free_irq(gpio_to_irq(ifx_dev->gpio.reset_out), (void *)ifx_dev); | ||
1186 | free_irq(gpio_to_irq(ifx_dev->gpio.srdy), (void *)ifx_dev); | ||
1187 | |||
1188 | gpio_free(ifx_dev->gpio.srdy); | ||
1189 | gpio_free(ifx_dev->gpio.mrdy); | ||
1190 | gpio_free(ifx_dev->gpio.reset); | ||
1191 | gpio_free(ifx_dev->gpio.po); | ||
1192 | gpio_free(ifx_dev->gpio.reset_out); | ||
1193 | |||
1194 | /* free allocations */ | ||
1195 | ifx_spi_free_device(ifx_dev); | ||
1196 | |||
1197 | saved_ifx_dev = NULL; | ||
1198 | return 0; | ||
1199 | } | ||
1200 | |||
1201 | /** | ||
1202 | * ifx_spi_spi_shutdown - called on SPI shutdown | ||
1203 | * @spi: SPI device | ||
1204 | * | ||
1205 | * No action needs to be taken here | ||
1206 | */ | ||
1207 | |||
1208 | static void ifx_spi_spi_shutdown(struct spi_device *spi) | ||
1209 | { | ||
1210 | } | ||
1211 | |||
1212 | /* | ||
1213 | * various suspends and resumes have nothing to do | ||
1214 | * no hardware to save state for | ||
1215 | */ | ||
1216 | |||
1217 | /** | ||
1218 | * ifx_spi_spi_suspend - suspend SPI on system suspend | ||
1219 | * @dev: device being suspended | ||
1220 | * | ||
1221 | * Suspend the SPI side. No action needed on Intel MID platforms, may | ||
1222 | * need extending for other systems. | ||
1223 | */ | ||
1224 | static int ifx_spi_spi_suspend(struct spi_device *spi, pm_message_t msg) | ||
1225 | { | ||
1226 | return 0; | ||
1227 | } | ||
1228 | |||
1229 | /** | ||
1230 | * ifx_spi_spi_resume - resume SPI side on system resume | ||
1231 | * @dev: device being suspended | ||
1232 | * | ||
1233 | * Suspend the SPI side. No action needed on Intel MID platforms, may | ||
1234 | * need extending for other systems. | ||
1235 | */ | ||
1236 | static int ifx_spi_spi_resume(struct spi_device *spi) | ||
1237 | { | ||
1238 | return 0; | ||
1239 | } | ||
1240 | |||
1241 | /** | ||
1242 | * ifx_spi_pm_suspend - suspend modem on system suspend | ||
1243 | * @dev: device being suspended | ||
1244 | * | ||
1245 | * Suspend the modem. No action needed on Intel MID platforms, may | ||
1246 | * need extending for other systems. | ||
1247 | */ | ||
1248 | static int ifx_spi_pm_suspend(struct device *dev) | ||
1249 | { | ||
1250 | return 0; | ||
1251 | } | ||
1252 | |||
1253 | /** | ||
1254 | * ifx_spi_pm_resume - resume modem on system resume | ||
1255 | * @dev: device being suspended | ||
1256 | * | ||
1257 | * Allow the modem to resume. No action needed. | ||
1258 | * | ||
1259 | * FIXME: do we need to reset anything here ? | ||
1260 | */ | ||
1261 | static int ifx_spi_pm_resume(struct device *dev) | ||
1262 | { | ||
1263 | return 0; | ||
1264 | } | ||
1265 | |||
1266 | /** | ||
1267 | * ifx_spi_pm_runtime_resume - suspend modem | ||
1268 | * @dev: device being suspended | ||
1269 | * | ||
1270 | * Allow the modem to resume. No action needed. | ||
1271 | */ | ||
1272 | static int ifx_spi_pm_runtime_resume(struct device *dev) | ||
1273 | { | ||
1274 | return 0; | ||
1275 | } | ||
1276 | |||
1277 | /** | ||
1278 | * ifx_spi_pm_runtime_suspend - suspend modem | ||
1279 | * @dev: device being suspended | ||
1280 | * | ||
1281 | * Allow the modem to suspend and thus suspend to continue up the | ||
1282 | * device tree. | ||
1283 | */ | ||
1284 | static int ifx_spi_pm_runtime_suspend(struct device *dev) | ||
1285 | { | ||
1286 | return 0; | ||
1287 | } | ||
1288 | |||
1289 | /** | ||
1290 | * ifx_spi_pm_runtime_idle - check if modem idle | ||
1291 | * @dev: our device | ||
1292 | * | ||
1293 | * Check conditions and queue runtime suspend if idle. | ||
1294 | */ | ||
1295 | static int ifx_spi_pm_runtime_idle(struct device *dev) | ||
1296 | { | ||
1297 | struct spi_device *spi = to_spi_device(dev); | ||
1298 | struct ifx_spi_device *ifx_dev = spi_get_drvdata(spi); | ||
1299 | |||
1300 | if (!ifx_dev->power_status) | ||
1301 | pm_runtime_suspend(dev); | ||
1302 | |||
1303 | return 0; | ||
1304 | } | ||
1305 | |||
1306 | static const struct dev_pm_ops ifx_spi_pm = { | ||
1307 | .resume = ifx_spi_pm_resume, | ||
1308 | .suspend = ifx_spi_pm_suspend, | ||
1309 | .runtime_resume = ifx_spi_pm_runtime_resume, | ||
1310 | .runtime_suspend = ifx_spi_pm_runtime_suspend, | ||
1311 | .runtime_idle = ifx_spi_pm_runtime_idle | ||
1312 | }; | ||
1313 | |||
1314 | static const struct spi_device_id ifx_id_table[] = { | ||
1315 | {"ifx6160", 0}, | ||
1316 | {"ifx6260", 0}, | ||
1317 | { } | ||
1318 | }; | ||
1319 | MODULE_DEVICE_TABLE(spi, ifx_id_table); | ||
1320 | |||
1321 | /* spi operations */ | ||
1322 | static const struct spi_driver ifx_spi_driver_6160 = { | ||
1323 | .driver = { | ||
1324 | .name = "ifx6160", | ||
1325 | .bus = &spi_bus_type, | ||
1326 | .pm = &ifx_spi_pm, | ||
1327 | .owner = THIS_MODULE}, | ||
1328 | .probe = ifx_spi_spi_probe, | ||
1329 | .shutdown = ifx_spi_spi_shutdown, | ||
1330 | .remove = __devexit_p(ifx_spi_spi_remove), | ||
1331 | .suspend = ifx_spi_spi_suspend, | ||
1332 | .resume = ifx_spi_spi_resume, | ||
1333 | .id_table = ifx_id_table | ||
1334 | }; | ||
1335 | |||
1336 | /** | ||
1337 | * ifx_spi_exit - module exit | ||
1338 | * | ||
1339 | * Unload the module. | ||
1340 | */ | ||
1341 | |||
1342 | static void __exit ifx_spi_exit(void) | ||
1343 | { | ||
1344 | /* unregister */ | ||
1345 | tty_unregister_driver(tty_drv); | ||
1346 | spi_unregister_driver((void *)&ifx_spi_driver_6160); | ||
1347 | } | ||
1348 | |||
1349 | /** | ||
1350 | * ifx_spi_init - module entry point | ||
1351 | * | ||
1352 | * Initialise the SPI and tty interfaces for the IFX SPI driver | ||
1353 | * We need to initialize upper-edge spi driver after the tty | ||
1354 | * driver because otherwise the spi probe will race | ||
1355 | */ | ||
1356 | |||
1357 | static int __init ifx_spi_init(void) | ||
1358 | { | ||
1359 | int result; | ||
1360 | |||
1361 | tty_drv = alloc_tty_driver(1); | ||
1362 | if (!tty_drv) { | ||
1363 | pr_err("%s: alloc_tty_driver failed", DRVNAME); | ||
1364 | return -ENOMEM; | ||
1365 | } | ||
1366 | |||
1367 | tty_drv->magic = TTY_DRIVER_MAGIC; | ||
1368 | tty_drv->owner = THIS_MODULE; | ||
1369 | tty_drv->driver_name = DRVNAME; | ||
1370 | tty_drv->name = TTYNAME; | ||
1371 | tty_drv->minor_start = IFX_SPI_TTY_ID; | ||
1372 | tty_drv->num = 1; | ||
1373 | tty_drv->type = TTY_DRIVER_TYPE_SERIAL; | ||
1374 | tty_drv->subtype = SERIAL_TYPE_NORMAL; | ||
1375 | tty_drv->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; | ||
1376 | tty_drv->init_termios = tty_std_termios; | ||
1377 | |||
1378 | tty_set_operations(tty_drv, &ifx_spi_serial_ops); | ||
1379 | |||
1380 | result = tty_register_driver(tty_drv); | ||
1381 | if (result) { | ||
1382 | pr_err("%s: tty_register_driver failed(%d)", | ||
1383 | DRVNAME, result); | ||
1384 | return result; | ||
1385 | } | ||
1386 | |||
1387 | result = spi_register_driver((void *)&ifx_spi_driver_6160); | ||
1388 | if (result) { | ||
1389 | pr_err("%s: spi_register_driver failed(%d)", | ||
1390 | DRVNAME, result); | ||
1391 | tty_unregister_driver(tty_drv); | ||
1392 | } | ||
1393 | return result; | ||
1394 | } | ||
1395 | |||
1396 | module_init(ifx_spi_init); | ||
1397 | module_exit(ifx_spi_exit); | ||
1398 | |||
1399 | MODULE_AUTHOR("Intel"); | ||
1400 | MODULE_DESCRIPTION("IFX6x60 spi driver"); | ||
1401 | MODULE_LICENSE("GPL"); | ||
1402 | MODULE_INFO(Version, "0.1-IFX6x60"); | ||
diff --git a/drivers/serial/ifx6x60.h b/drivers/serial/ifx6x60.h new file mode 100644 index 000000000000..deb7b8d977dc --- /dev/null +++ b/drivers/serial/ifx6x60.h | |||
@@ -0,0 +1,129 @@ | |||
1 | /**************************************************************************** | ||
2 | * | ||
3 | * Driver for the IFX spi modem. | ||
4 | * | ||
5 | * Copyright (C) 2009, 2010 Intel Corp | ||
6 | * Jim Stanley <jim.stanley@intel.com> | ||
7 | * | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License version 2 as | ||
11 | * published by the Free Software Foundation. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | ||
21 | * USA | ||
22 | * | ||
23 | * | ||
24 | * | ||
25 | *****************************************************************************/ | ||
26 | #ifndef _IFX6X60_H | ||
27 | #define _IFX6X60_H | ||
28 | |||
29 | #define DRVNAME "ifx6x60" | ||
30 | #define TTYNAME "ttyIFX" | ||
31 | |||
32 | /* #define IFX_THROTTLE_CODE */ | ||
33 | |||
34 | #define IFX_SPI_MAX_MINORS 1 | ||
35 | #define IFX_SPI_TRANSFER_SIZE 2048 | ||
36 | #define IFX_SPI_FIFO_SIZE 4096 | ||
37 | |||
38 | #define IFX_SPI_HEADER_OVERHEAD 4 | ||
39 | #define IFX_RESET_TIMEOUT msecs_to_jiffies(50) | ||
40 | |||
41 | /* device flags bitfield definitions */ | ||
42 | #define IFX_SPI_STATE_PRESENT 0 | ||
43 | #define IFX_SPI_STATE_IO_IN_PROGRESS 1 | ||
44 | #define IFX_SPI_STATE_IO_READY 2 | ||
45 | #define IFX_SPI_STATE_TIMER_PENDING 3 | ||
46 | |||
47 | /* flow control bitfields */ | ||
48 | #define IFX_SPI_DCD 0 | ||
49 | #define IFX_SPI_CTS 1 | ||
50 | #define IFX_SPI_DSR 2 | ||
51 | #define IFX_SPI_RI 3 | ||
52 | #define IFX_SPI_DTR 4 | ||
53 | #define IFX_SPI_RTS 5 | ||
54 | #define IFX_SPI_TX_FC 6 | ||
55 | #define IFX_SPI_RX_FC 7 | ||
56 | #define IFX_SPI_UPDATE 8 | ||
57 | |||
58 | #define IFX_SPI_PAYLOAD_SIZE (IFX_SPI_TRANSFER_SIZE - \ | ||
59 | IFX_SPI_HEADER_OVERHEAD) | ||
60 | |||
61 | #define IFX_SPI_IRQ_TYPE DETECT_EDGE_RISING | ||
62 | #define IFX_SPI_GPIO_TARGET 0 | ||
63 | #define IFX_SPI_GPIO0 0x105 | ||
64 | |||
65 | #define IFX_SPI_STATUS_TIMEOUT (2000*HZ) | ||
66 | |||
67 | /* values for bits in power status byte */ | ||
68 | #define IFX_SPI_POWER_DATA_PENDING 1 | ||
69 | #define IFX_SPI_POWER_SRDY 2 | ||
70 | |||
71 | struct ifx_spi_device { | ||
72 | /* Our SPI device */ | ||
73 | struct spi_device *spi_dev; | ||
74 | |||
75 | /* Port specific data */ | ||
76 | struct kfifo tx_fifo; | ||
77 | spinlock_t fifo_lock; | ||
78 | unsigned long signal_state; | ||
79 | |||
80 | /* TTY Layer logic */ | ||
81 | struct tty_port tty_port; | ||
82 | struct device *tty_dev; | ||
83 | int minor; | ||
84 | |||
85 | /* Low level I/O work */ | ||
86 | struct tasklet_struct io_work_tasklet; | ||
87 | unsigned long flags; | ||
88 | dma_addr_t rx_dma; | ||
89 | dma_addr_t tx_dma; | ||
90 | |||
91 | int is_6160; /* Modem type */ | ||
92 | |||
93 | spinlock_t write_lock; | ||
94 | int write_pending; | ||
95 | spinlock_t power_lock; | ||
96 | unsigned char power_status; | ||
97 | |||
98 | unsigned char *rx_buffer; | ||
99 | unsigned char *tx_buffer; | ||
100 | dma_addr_t rx_bus; | ||
101 | dma_addr_t tx_bus; | ||
102 | unsigned char spi_more; | ||
103 | unsigned char spi_slave_cts; | ||
104 | |||
105 | struct timer_list spi_timer; | ||
106 | |||
107 | struct spi_message spi_msg; | ||
108 | struct spi_transfer spi_xfer; | ||
109 | |||
110 | struct { | ||
111 | /* gpio lines */ | ||
112 | unsigned short srdy; /* slave-ready gpio */ | ||
113 | unsigned short mrdy; /* master-ready gpio */ | ||
114 | unsigned short reset; /* modem-reset gpio */ | ||
115 | unsigned short po; /* modem-on gpio */ | ||
116 | unsigned short reset_out; /* modem-in-reset gpio */ | ||
117 | /* state/stats */ | ||
118 | int unack_srdy_int_nb; | ||
119 | } gpio; | ||
120 | |||
121 | /* modem reset */ | ||
122 | unsigned long mdm_reset_state; | ||
123 | #define MR_START 0 | ||
124 | #define MR_INPROGRESS 1 | ||
125 | #define MR_COMPLETE 2 | ||
126 | wait_queue_head_t mdm_reset_wait; | ||
127 | }; | ||
128 | |||
129 | #endif /* _IFX6X60_H */ | ||