Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

serial: ifx6x60: Remove driver for deprecated platform

Intel Moorestown and Medfield are quite old Intel Atom based
32-bit platforms, which were in limited use in some Android phones,
tablets and consumer electronics more than eight years ago.

There are no bugs or problems ever reported outside from Intel
for breaking any of that platforms for years. It seems no real
users exists who run more or less fresh kernel on it. The commit
05f4434bc130 ("ASoC: Intel: remove mfld_machine") also in align
with this theory.

Due to above and to reduce a burden of supporting outdated drivers
we remove the support of outdated platforms completely.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/20210125150238.16980-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Andy Shevchenko and committed by
Greg Kroah-Hartman
e9103f47 0f8b29fa

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