Lines Matching +full:spi +full:- +full:gpio
1 // SPDX-License-Identifier: GPL-2.0
4 * Driver for the IFX 6x60 spi modem.
19 * o The driver is intended to be big-endian safe but has never been
22 * o Some of the GPIO naming/setup assumptions may need revisiting if
26 #include <linux/dma-mapping.h>
31 #include <linux/spi/spi.h>
42 #include <linux/gpio.h>
48 #include <linux/spi/ifx_modem.h>
60 #define IFX_SPI_HEADER_0 (-1)
61 #define IFX_SPI_HEADER_F (-2)
101 /* GPIO/GPE settings */
104 * mrdy_set_high - set MRDY GPIO
110 gpio_set_value(ifx->gpio.mrdy, 1); in mrdy_set_high()
114 * mrdy_set_low - clear MRDY GPIO
120 gpio_set_value(ifx->gpio.mrdy, 0); in mrdy_set_low()
125 * @ifx_dev: our SPI device
128 * Set bit in power status and signal power system if status becomes non-0
135 spin_lock_irqsave(&ifx_dev->power_lock, flags); in ifx_spi_power_state_set()
138 * if power status is already non-0, just update, else in ifx_spi_power_state_set()
141 if (!ifx_dev->power_status) in ifx_spi_power_state_set()
142 pm_runtime_get(&ifx_dev->spi_dev->dev); in ifx_spi_power_state_set()
143 ifx_dev->power_status |= val; in ifx_spi_power_state_set()
145 spin_unlock_irqrestore(&ifx_dev->power_lock, flags); in ifx_spi_power_state_set()
149 * ifx_spi_power_state_clear - clear power bit
150 * @ifx_dev: our SPI device
160 spin_lock_irqsave(&ifx_dev->power_lock, flags); in ifx_spi_power_state_clear()
162 if (ifx_dev->power_status) { in ifx_spi_power_state_clear()
163 ifx_dev->power_status &= ~val; in ifx_spi_power_state_clear()
164 if (!ifx_dev->power_status) in ifx_spi_power_state_clear()
165 pm_runtime_put(&ifx_dev->spi_dev->dev); in ifx_spi_power_state_clear()
168 spin_unlock_irqrestore(&ifx_dev->power_lock, flags); in ifx_spi_power_state_clear()
181 /* don't swap buffer if SPI word width is 8 bits */ in swap_buf_8()
237 * mrdy_assert - assert MRDY line
238 * @ifx_dev: our SPI device
247 int val = gpio_get_value(ifx_dev->gpio.srdy); in mrdy_assert()
250 &ifx_dev->flags)) { in mrdy_assert()
251 mod_timer(&ifx_dev->spi_timer,jiffies + IFX_SPI_TIMEOUT_SEC*HZ); in mrdy_assert()
260 * ifx_spi_timeout - SPI timeout
261 * @arg: our SPI device
263 * The SPI has timed out: hang up the tty. Users will then see a hangup
270 dev_warn(&ifx_dev->spi_dev->dev, "*** SPI Timeout ***"); in ifx_spi_timeout()
271 tty_port_tty_hangup(&ifx_dev->tty_port, false); in ifx_spi_timeout()
273 clear_bit(IFX_SPI_STATE_TIMER_PENDING, &ifx_dev->flags); in ifx_spi_timeout()
279 * ifx_spi_tiocmget - get modem lines
289 struct ifx_spi_device *ifx_dev = tty->driver_data; in ifx_spi_tiocmget()
292 (test_bit(IFX_SPI_RTS, &ifx_dev->signal_state) ? TIOCM_RTS : 0) | in ifx_spi_tiocmget()
293 (test_bit(IFX_SPI_DTR, &ifx_dev->signal_state) ? TIOCM_DTR : 0) | in ifx_spi_tiocmget()
294 (test_bit(IFX_SPI_CTS, &ifx_dev->signal_state) ? TIOCM_CTS : 0) | in ifx_spi_tiocmget()
295 (test_bit(IFX_SPI_DSR, &ifx_dev->signal_state) ? TIOCM_DSR : 0) | in ifx_spi_tiocmget()
296 (test_bit(IFX_SPI_DCD, &ifx_dev->signal_state) ? TIOCM_CAR : 0) | in ifx_spi_tiocmget()
297 (test_bit(IFX_SPI_RI, &ifx_dev->signal_state) ? TIOCM_RNG : 0); in ifx_spi_tiocmget()
302 * ifx_spi_tiocmset - set modem bits
315 struct ifx_spi_device *ifx_dev = tty->driver_data; in ifx_spi_tiocmset()
318 set_bit(IFX_SPI_RTS, &ifx_dev->signal_state); in ifx_spi_tiocmset()
320 set_bit(IFX_SPI_DTR, &ifx_dev->signal_state); in ifx_spi_tiocmset()
322 clear_bit(IFX_SPI_RTS, &ifx_dev->signal_state); in ifx_spi_tiocmset()
324 clear_bit(IFX_SPI_DTR, &ifx_dev->signal_state); in ifx_spi_tiocmset()
326 set_bit(IFX_SPI_UPDATE, &ifx_dev->signal_state); in ifx_spi_tiocmset()
331 * ifx_spi_open - called on tty open
342 return tty_port_open(&saved_ifx_dev->tty_port, tty, filp); in ifx_spi_open()
346 * ifx_spi_close - called when our tty closes
355 struct ifx_spi_device *ifx_dev = tty->driver_data; in ifx_spi_close()
356 tty_port_close(&ifx_dev->tty_port, tty, filp); in ifx_spi_close()
361 * ifx_decode_spi_header - decode received header
367 * Note how received_cts is handled -- if header is all F it is left
400 * ifx_setup_spi_header - set header fields
401 * @txbuffer: pointer to start of SPI buffer
405 * Format up an SPI header for a transfer
418 * ifx_spi_prepare_tx_buffer - prepare transmit frame
419 * @ifx_dev: our SPI device
424 * ifx_dev->tx_buffer
426 * FIXME: performance - should we wake the tty when the queue is half
436 tx_buffer = ifx_dev->tx_buffer; in ifx_spi_prepare_tx_buffer()
438 /* make room for required SPI header */ in ifx_spi_prepare_tx_buffer()
444 ifx_dev->spi_more = 0; in ifx_spi_prepare_tx_buffer()
447 if (!ifx_dev->spi_slave_cts) { in ifx_spi_prepare_tx_buffer()
449 queue_length = kfifo_len(&ifx_dev->tx_fifo); in ifx_spi_prepare_tx_buffer()
451 /* data to mux -- see if there's room for it */ in ifx_spi_prepare_tx_buffer()
453 temp_count = kfifo_out_locked(&ifx_dev->tx_fifo, in ifx_spi_prepare_tx_buffer()
455 &ifx_dev->fifo_lock); in ifx_spi_prepare_tx_buffer()
462 tty_port_tty_wakeup(&ifx_dev->tty_port); in ifx_spi_prepare_tx_buffer()
463 else /* more data in port, use next SPI message */ in ifx_spi_prepare_tx_buffer()
464 ifx_dev->spi_more = 1; in ifx_spi_prepare_tx_buffer()
467 /* have data and info for header -- set up SPI header in buffer */ in ifx_spi_prepare_tx_buffer()
468 /* spi header needs payload size, not entire buffer size */ in ifx_spi_prepare_tx_buffer()
469 ifx_spi_setup_spi_header(ifx_dev->tx_buffer, in ifx_spi_prepare_tx_buffer()
470 tx_count-IFX_SPI_HEADER_OVERHEAD, in ifx_spi_prepare_tx_buffer()
471 ifx_dev->spi_more); in ifx_spi_prepare_tx_buffer()
473 ifx_dev->swap_buf((ifx_dev->tx_buffer), tx_count, in ifx_spi_prepare_tx_buffer()
474 &ifx_dev->tx_buffer[IFX_SPI_TRANSFER_SIZE]); in ifx_spi_prepare_tx_buffer()
479 * ifx_spi_write - line discipline write
491 struct ifx_spi_device *ifx_dev = tty->driver_data; in ifx_spi_write()
497 spin_lock_irqsave(&ifx_dev->fifo_lock, flags); in ifx_spi_write()
498 is_fifo_empty = kfifo_is_empty(&ifx_dev->tx_fifo); in ifx_spi_write()
499 tx_count = kfifo_in(&ifx_dev->tx_fifo, tmp_buf, count); in ifx_spi_write()
500 spin_unlock_irqrestore(&ifx_dev->fifo_lock, flags); in ifx_spi_write()
508 * ifx_spi_chars_in_buffer - line discipline helper
516 struct ifx_spi_device *ifx_dev = tty->driver_data; in ifx_spi_write_room()
517 return IFX_SPI_FIFO_SIZE - kfifo_len(&ifx_dev->tx_fifo); in ifx_spi_write_room()
521 * ifx_spi_chars_in_buffer - line discipline helper
529 struct ifx_spi_device *ifx_dev = tty->driver_data; in ifx_spi_chars_in_buffer()
530 return kfifo_len(&ifx_dev->tx_fifo); in ifx_spi_chars_in_buffer()
543 struct ifx_spi_device *ifx_dev = tty->driver_data; in ifx_spi_hangup()
544 tty_port_hangup(&ifx_dev->tty_port); in ifx_spi_hangup()
551 * tty port activate method - called for first open. Serialized
560 kfifo_reset(&ifx_dev->tx_fifo); in ifx_port_activate()
563 clear_bit(IFX_SPI_STATE_IO_IN_PROGRESS, &ifx_dev->flags); in ifx_port_activate()
564 clear_bit(IFX_SPI_STATE_IO_READY, &ifx_dev->flags); in ifx_port_activate()
567 tty->driver_data = ifx_dev; in ifx_port_activate()
570 port->low_latency = 1; in ifx_port_activate()
573 set_bit(IFX_SPI_STATE_IO_AVAILABLE, &ifx_dev->flags); in ifx_port_activate()
582 * tty port shutdown method - called for last port close. Serialized
590 clear_bit(IFX_SPI_STATE_IO_AVAILABLE, &ifx_dev->flags); in ifx_port_shutdown()
592 del_timer(&ifx_dev->spi_timer); in ifx_port_shutdown()
593 clear_bit(IFX_SPI_STATE_TIMER_PENDING, &ifx_dev->flags); in ifx_port_shutdown()
594 tasklet_kill(&ifx_dev->io_work_tasklet); in ifx_port_shutdown()
614 * ifx_spi_insert_fip_string - queue received data
615 * @ifx_ser: our SPI device
625 tty_insert_flip_string(&ifx_dev->tty_port, chars, size); in ifx_spi_insert_flip_string()
626 tty_flip_buffer_push(&ifx_dev->tty_port); in ifx_spi_insert_flip_string()
630 * ifx_spi_complete - SPI transfer completed
631 * @ctx: our SPI device
633 * An SPI transfer has completed. Process any received data and kick off
650 if (!ifx_dev->spi_msg.status) { in ifx_spi_complete()
652 ifx_dev->swap_buf(ifx_dev->rx_buffer, IFX_SPI_HEADER_OVERHEAD, in ifx_spi_complete()
653 &ifx_dev->rx_buffer[IFX_SPI_HEADER_OVERHEAD]); in ifx_spi_complete()
654 decode_result = ifx_spi_decode_spi_header(ifx_dev->rx_buffer, in ifx_spi_complete()
657 dev_dbg(&ifx_dev->spi_dev->dev, in ifx_spi_complete()
659 ifx_dev->spi_slave_cts = 0; in ifx_spi_complete()
662 dev_dbg(&ifx_dev->spi_dev->dev, in ifx_spi_complete()
667 ifx_dev->spi_slave_cts = cts; in ifx_spi_complete()
670 ifx_dev->spi_msg.actual_length); in ifx_spi_complete()
671 ifx_dev->swap_buf( in ifx_spi_complete()
672 (ifx_dev->rx_buffer + IFX_SPI_HEADER_OVERHEAD), in ifx_spi_complete()
674 &ifx_dev->rx_buffer[IFX_SPI_TRANSFER_SIZE]); in ifx_spi_complete()
677 ifx_dev->rx_buffer + IFX_SPI_HEADER_OVERHEAD, in ifx_spi_complete()
681 dev_dbg(&ifx_dev->spi_dev->dev, "SPI transfer error %d", in ifx_spi_complete()
682 ifx_dev->spi_msg.status); in ifx_spi_complete()
686 if (ifx_dev->write_pending) { in ifx_spi_complete()
687 ifx_dev->write_pending = 0; in ifx_spi_complete()
691 clear_bit(IFX_SPI_STATE_IO_IN_PROGRESS, &(ifx_dev->flags)); in ifx_spi_complete()
693 queue_length = kfifo_len(&ifx_dev->tx_fifo); in ifx_spi_complete()
694 srdy = gpio_get_value(ifx_dev->gpio.srdy); in ifx_spi_complete()
699 if (test_and_clear_bit(IFX_SPI_STATE_IO_READY, &ifx_dev->flags)) in ifx_spi_complete()
700 tasklet_schedule(&ifx_dev->io_work_tasklet); in ifx_spi_complete()
702 if (more || ifx_dev->spi_more || queue_length > 0 || in ifx_spi_complete()
704 if (ifx_dev->spi_slave_cts) { in ifx_spi_complete()
717 tty_port_tty_wakeup(&ifx_dev->tty_port); in ifx_spi_complete()
723 * ifx_spio_io - I/O tasklet
724 * @data: our SPI device
734 if (!test_and_set_bit(IFX_SPI_STATE_IO_IN_PROGRESS, &ifx_dev->flags) && in ifx_spi_io()
735 test_bit(IFX_SPI_STATE_IO_AVAILABLE, &ifx_dev->flags)) { in ifx_spi_io()
736 if (ifx_dev->gpio.unack_srdy_int_nb > 0) in ifx_spi_io()
737 ifx_dev->gpio.unack_srdy_int_nb--; in ifx_spi_io()
741 spi_message_init(&ifx_dev->spi_msg); in ifx_spi_io()
742 INIT_LIST_HEAD(&ifx_dev->spi_msg.queue); in ifx_spi_io()
744 ifx_dev->spi_msg.context = ifx_dev; in ifx_spi_io()
745 ifx_dev->spi_msg.complete = ifx_spi_complete; in ifx_spi_io()
747 /* set up our spi transfer */ in ifx_spi_io()
749 ifx_dev->spi_xfer.len = IFX_SPI_TRANSFER_SIZE; in ifx_spi_io()
750 ifx_dev->spi_xfer.cs_change = 0; in ifx_spi_io()
751 ifx_dev->spi_xfer.speed_hz = ifx_dev->spi_dev->max_speed_hz; in ifx_spi_io()
752 /* ifx_dev->spi_xfer.speed_hz = 390625; */ in ifx_spi_io()
753 ifx_dev->spi_xfer.bits_per_word = in ifx_spi_io()
754 ifx_dev->spi_dev->bits_per_word; in ifx_spi_io()
756 ifx_dev->spi_xfer.tx_buf = ifx_dev->tx_buffer; in ifx_spi_io()
757 ifx_dev->spi_xfer.rx_buf = ifx_dev->rx_buffer; in ifx_spi_io()
762 if (ifx_dev->use_dma) { in ifx_spi_io()
763 ifx_dev->spi_msg.is_dma_mapped = 1; in ifx_spi_io()
764 ifx_dev->tx_dma = ifx_dev->tx_bus; in ifx_spi_io()
765 ifx_dev->rx_dma = ifx_dev->rx_bus; in ifx_spi_io()
766 ifx_dev->spi_xfer.tx_dma = ifx_dev->tx_dma; in ifx_spi_io()
767 ifx_dev->spi_xfer.rx_dma = ifx_dev->rx_dma; in ifx_spi_io()
769 ifx_dev->spi_msg.is_dma_mapped = 0; in ifx_spi_io()
770 ifx_dev->tx_dma = (dma_addr_t)0; in ifx_spi_io()
771 ifx_dev->rx_dma = (dma_addr_t)0; in ifx_spi_io()
772 ifx_dev->spi_xfer.tx_dma = (dma_addr_t)0; in ifx_spi_io()
773 ifx_dev->spi_xfer.rx_dma = (dma_addr_t)0; in ifx_spi_io()
776 spi_message_add_tail(&ifx_dev->spi_xfer, &ifx_dev->spi_msg); in ifx_spi_io()
783 retval = spi_async(ifx_dev->spi_dev, &ifx_dev->spi_msg); in ifx_spi_io()
786 &ifx_dev->flags); in ifx_spi_io()
787 tasklet_schedule(&ifx_dev->io_work_tasklet); in ifx_spi_io()
791 ifx_dev->write_pending = 1; in ifx_spi_io()
795 * ifx_spi_free_port - free up the tty side
802 if (ifx_dev->tty_dev) in ifx_spi_free_port()
803 tty_unregister_device(tty_drv, ifx_dev->minor); in ifx_spi_free_port()
804 tty_port_destroy(&ifx_dev->tty_port); in ifx_spi_free_port()
805 kfifo_free(&ifx_dev->tx_fifo); in ifx_spi_free_port()
809 * ifx_spi_create_port - create a new port
810 * @ifx_dev: our spi device
818 struct tty_port *pport = &ifx_dev->tty_port; in ifx_spi_create_port()
820 spin_lock_init(&ifx_dev->fifo_lock); in ifx_spi_create_port()
821 lockdep_set_class_and_subclass(&ifx_dev->fifo_lock, in ifx_spi_create_port()
824 if (kfifo_alloc(&ifx_dev->tx_fifo, IFX_SPI_FIFO_SIZE, GFP_KERNEL)) { in ifx_spi_create_port()
825 ret = -ENOMEM; in ifx_spi_create_port()
830 pport->ops = &ifx_tty_port_ops; in ifx_spi_create_port()
831 ifx_dev->minor = IFX_SPI_TTY_ID; in ifx_spi_create_port()
832 ifx_dev->tty_dev = tty_port_register_device(pport, tty_drv, in ifx_spi_create_port()
833 ifx_dev->minor, &ifx_dev->spi_dev->dev); in ifx_spi_create_port()
834 if (IS_ERR(ifx_dev->tty_dev)) { in ifx_spi_create_port()
835 dev_dbg(&ifx_dev->spi_dev->dev, in ifx_spi_create_port()
837 ret = PTR_ERR(ifx_dev->tty_dev); in ifx_spi_create_port()
850 * ifx_spi_handle_srdy - handle SRDY
859 if (test_bit(IFX_SPI_STATE_TIMER_PENDING, &ifx_dev->flags)) { in ifx_spi_handle_srdy()
860 del_timer(&ifx_dev->spi_timer); in ifx_spi_handle_srdy()
861 clear_bit(IFX_SPI_STATE_TIMER_PENDING, &ifx_dev->flags); in ifx_spi_handle_srdy()
866 if (!test_bit(IFX_SPI_STATE_IO_IN_PROGRESS, &ifx_dev->flags)) in ifx_spi_handle_srdy()
867 tasklet_schedule(&ifx_dev->io_work_tasklet); in ifx_spi_handle_srdy()
869 set_bit(IFX_SPI_STATE_IO_READY, &ifx_dev->flags); in ifx_spi_handle_srdy()
873 * ifx_spi_srdy_interrupt - SRDY asserted
882 ifx_dev->gpio.unack_srdy_int_nb++; in ifx_spi_srdy_interrupt()
888 * ifx_spi_reset_interrupt - Modem has changed reset state
892 * The modem has either entered or left reset state. Check the GPIO
901 int val = gpio_get_value(ifx_dev->gpio.reset_out); in ifx_spi_reset_interrupt()
902 int solreset = test_bit(MR_START, &ifx_dev->mdm_reset_state); in ifx_spi_reset_interrupt()
906 set_bit(MR_INPROGRESS, &ifx_dev->mdm_reset_state); in ifx_spi_reset_interrupt()
909 tty_port_tty_hangup(&ifx_dev->tty_port, false); in ifx_spi_reset_interrupt()
913 clear_bit(MR_INPROGRESS, &ifx_dev->mdm_reset_state); in ifx_spi_reset_interrupt()
915 set_bit(MR_COMPLETE, &ifx_dev->mdm_reset_state); in ifx_spi_reset_interrupt()
916 wake_up(&ifx_dev->mdm_reset_wait); in ifx_spi_reset_interrupt()
923 * ifx_spi_free_device - free device
931 dma_free_coherent(&ifx_dev->spi_dev->dev, in ifx_spi_free_device()
933 ifx_dev->tx_buffer, in ifx_spi_free_device()
934 ifx_dev->tx_bus); in ifx_spi_free_device()
935 dma_free_coherent(&ifx_dev->spi_dev->dev, in ifx_spi_free_device()
937 ifx_dev->rx_buffer, in ifx_spi_free_device()
938 ifx_dev->rx_bus); in ifx_spi_free_device()
942 * ifx_spi_reset - reset modem
956 set_bit(MR_START, &ifx_dev->mdm_reset_state); in ifx_spi_reset()
957 gpio_set_value(ifx_dev->gpio.po, 0); in ifx_spi_reset()
958 gpio_set_value(ifx_dev->gpio.reset, 0); in ifx_spi_reset()
960 gpio_set_value(ifx_dev->gpio.reset, 1); in ifx_spi_reset()
962 gpio_set_value(ifx_dev->gpio.po, 1); in ifx_spi_reset()
964 gpio_set_value(ifx_dev->gpio.po, 0); in ifx_spi_reset()
965 ret = wait_event_timeout(ifx_dev->mdm_reset_wait, in ifx_spi_reset()
967 &ifx_dev->mdm_reset_state), in ifx_spi_reset()
970 dev_warn(&ifx_dev->spi_dev->dev, "Modem reset timeout: (state:%lx)", in ifx_spi_reset()
971 ifx_dev->mdm_reset_state); in ifx_spi_reset()
973 ifx_dev->mdm_reset_state = 0; in ifx_spi_reset()
978 * ifx_spi_spi_probe - probe callback
979 * @spi: our possible matching SPI device
981 * Probe for a 6x60 modem on SPI bus. Perform any needed device and
982 * GPIO setup.
985 * - Support for multiple devices
986 * - Split out MID specific GPIO handling eventually
989 static int ifx_spi_spi_probe(struct spi_device *spi) in ifx_spi_spi_probe() argument
997 dev_dbg(&spi->dev, "ignoring subsequent detection"); in ifx_spi_spi_probe()
998 return -ENODEV; in ifx_spi_spi_probe()
1001 pl_data = dev_get_platdata(&spi->dev); in ifx_spi_spi_probe()
1003 dev_err(&spi->dev, "missing platform data!"); in ifx_spi_spi_probe()
1004 return -ENODEV; in ifx_spi_spi_probe()
1010 dev_err(&spi->dev, "spi device allocation failed"); in ifx_spi_spi_probe()
1011 return -ENOMEM; in ifx_spi_spi_probe()
1014 ifx_dev->spi_dev = spi; in ifx_spi_spi_probe()
1015 clear_bit(IFX_SPI_STATE_IO_IN_PROGRESS, &ifx_dev->flags); in ifx_spi_spi_probe()
1016 spin_lock_init(&ifx_dev->write_lock); in ifx_spi_spi_probe()
1017 spin_lock_init(&ifx_dev->power_lock); in ifx_spi_spi_probe()
1018 ifx_dev->power_status = 0; in ifx_spi_spi_probe()
1019 timer_setup(&ifx_dev->spi_timer, ifx_spi_timeout, 0); in ifx_spi_spi_probe()
1020 ifx_dev->modem = pl_data->modem_type; in ifx_spi_spi_probe()
1021 ifx_dev->use_dma = pl_data->use_dma; in ifx_spi_spi_probe()
1022 ifx_dev->max_hz = pl_data->max_hz; in ifx_spi_spi_probe()
1023 /* initialize spi mode, etc */ in ifx_spi_spi_probe()
1024 spi->max_speed_hz = ifx_dev->max_hz; in ifx_spi_spi_probe()
1025 spi->mode = IFX_SPI_MODE | (SPI_LOOP & spi->mode); in ifx_spi_spi_probe()
1026 spi->bits_per_word = spi_bpw; in ifx_spi_spi_probe()
1027 ret = spi_setup(spi); in ifx_spi_spi_probe()
1029 dev_err(&spi->dev, "SPI setup wasn't successful %d", ret); in ifx_spi_spi_probe()
1031 return -ENODEV; in ifx_spi_spi_probe()
1035 if (spi->bits_per_word == 32) in ifx_spi_spi_probe()
1036 ifx_dev->swap_buf = swap_buf_32; in ifx_spi_spi_probe()
1037 else if (spi->bits_per_word == 16) in ifx_spi_spi_probe()
1038 ifx_dev->swap_buf = swap_buf_16; in ifx_spi_spi_probe()
1040 ifx_dev->swap_buf = swap_buf_8; in ifx_spi_spi_probe()
1042 /* ensure SPI protocol flags are initialized to enable transfer */ in ifx_spi_spi_probe()
1043 ifx_dev->spi_more = 0; in ifx_spi_spi_probe()
1044 ifx_dev->spi_slave_cts = 0; in ifx_spi_spi_probe()
1047 ifx_dev->tx_buffer = dma_alloc_coherent(ifx_dev->spi_dev->dev.parent, in ifx_spi_spi_probe()
1049 &ifx_dev->tx_bus, in ifx_spi_spi_probe()
1051 if (!ifx_dev->tx_buffer) { in ifx_spi_spi_probe()
1052 dev_err(&spi->dev, "DMA-TX buffer allocation failed"); in ifx_spi_spi_probe()
1053 ret = -ENOMEM; in ifx_spi_spi_probe()
1056 ifx_dev->rx_buffer = dma_alloc_coherent(ifx_dev->spi_dev->dev.parent, in ifx_spi_spi_probe()
1058 &ifx_dev->rx_bus, in ifx_spi_spi_probe()
1060 if (!ifx_dev->rx_buffer) { in ifx_spi_spi_probe()
1061 dev_err(&spi->dev, "DMA-RX buffer allocation failed"); in ifx_spi_spi_probe()
1062 ret = -ENOMEM; in ifx_spi_spi_probe()
1067 init_waitqueue_head(&ifx_dev->mdm_reset_wait); in ifx_spi_spi_probe()
1069 spi_set_drvdata(spi, ifx_dev); in ifx_spi_spi_probe()
1070 tasklet_init(&ifx_dev->io_work_tasklet, ifx_spi_io, in ifx_spi_spi_probe()
1073 set_bit(IFX_SPI_STATE_PRESENT, &ifx_dev->flags); in ifx_spi_spi_probe()
1078 dev_err(&spi->dev, "create default tty port failed"); in ifx_spi_spi_probe()
1082 ifx_dev->gpio.reset = pl_data->rst_pmu; in ifx_spi_spi_probe()
1083 ifx_dev->gpio.po = pl_data->pwr_on; in ifx_spi_spi_probe()
1084 ifx_dev->gpio.mrdy = pl_data->mrdy; in ifx_spi_spi_probe()
1085 ifx_dev->gpio.srdy = pl_data->srdy; in ifx_spi_spi_probe()
1086 ifx_dev->gpio.reset_out = pl_data->rst_out; in ifx_spi_spi_probe()
1088 dev_info(&spi->dev, "gpios %d, %d, %d, %d, %d", in ifx_spi_spi_probe()
1089 ifx_dev->gpio.reset, ifx_dev->gpio.po, ifx_dev->gpio.mrdy, in ifx_spi_spi_probe()
1090 ifx_dev->gpio.srdy, ifx_dev->gpio.reset_out); in ifx_spi_spi_probe()
1093 ret = gpio_request(ifx_dev->gpio.reset, "ifxModem"); in ifx_spi_spi_probe()
1095 dev_err(&spi->dev, "Unable to allocate GPIO%d (RESET)", in ifx_spi_spi_probe()
1096 ifx_dev->gpio.reset); in ifx_spi_spi_probe()
1099 ret += gpio_direction_output(ifx_dev->gpio.reset, 0); in ifx_spi_spi_probe()
1100 ret += gpio_export(ifx_dev->gpio.reset, 1); in ifx_spi_spi_probe()
1102 dev_err(&spi->dev, "Unable to configure GPIO%d (RESET)", in ifx_spi_spi_probe()
1103 ifx_dev->gpio.reset); in ifx_spi_spi_probe()
1104 ret = -EBUSY; in ifx_spi_spi_probe()
1108 ret = gpio_request(ifx_dev->gpio.po, "ifxModem"); in ifx_spi_spi_probe()
1109 ret += gpio_direction_output(ifx_dev->gpio.po, 0); in ifx_spi_spi_probe()
1110 ret += gpio_export(ifx_dev->gpio.po, 1); in ifx_spi_spi_probe()
1112 dev_err(&spi->dev, "Unable to configure GPIO%d (ON)", in ifx_spi_spi_probe()
1113 ifx_dev->gpio.po); in ifx_spi_spi_probe()
1114 ret = -EBUSY; in ifx_spi_spi_probe()
1118 ret = gpio_request(ifx_dev->gpio.mrdy, "ifxModem"); in ifx_spi_spi_probe()
1120 dev_err(&spi->dev, "Unable to allocate GPIO%d (MRDY)", in ifx_spi_spi_probe()
1121 ifx_dev->gpio.mrdy); in ifx_spi_spi_probe()
1124 ret += gpio_export(ifx_dev->gpio.mrdy, 1); in ifx_spi_spi_probe()
1125 ret += gpio_direction_output(ifx_dev->gpio.mrdy, 0); in ifx_spi_spi_probe()
1127 dev_err(&spi->dev, "Unable to configure GPIO%d (MRDY)", in ifx_spi_spi_probe()
1128 ifx_dev->gpio.mrdy); in ifx_spi_spi_probe()
1129 ret = -EBUSY; in ifx_spi_spi_probe()
1133 ret = gpio_request(ifx_dev->gpio.srdy, "ifxModem"); in ifx_spi_spi_probe()
1135 dev_err(&spi->dev, "Unable to allocate GPIO%d (SRDY)", in ifx_spi_spi_probe()
1136 ifx_dev->gpio.srdy); in ifx_spi_spi_probe()
1137 ret = -EBUSY; in ifx_spi_spi_probe()
1140 ret += gpio_export(ifx_dev->gpio.srdy, 1); in ifx_spi_spi_probe()
1141 ret += gpio_direction_input(ifx_dev->gpio.srdy); in ifx_spi_spi_probe()
1143 dev_err(&spi->dev, "Unable to configure GPIO%d (SRDY)", in ifx_spi_spi_probe()
1144 ifx_dev->gpio.srdy); in ifx_spi_spi_probe()
1145 ret = -EBUSY; in ifx_spi_spi_probe()
1149 ret = gpio_request(ifx_dev->gpio.reset_out, "ifxModem"); in ifx_spi_spi_probe()
1151 dev_err(&spi->dev, "Unable to allocate GPIO%d (RESET_OUT)", in ifx_spi_spi_probe()
1152 ifx_dev->gpio.reset_out); in ifx_spi_spi_probe()
1155 ret += gpio_export(ifx_dev->gpio.reset_out, 1); in ifx_spi_spi_probe()
1156 ret += gpio_direction_input(ifx_dev->gpio.reset_out); in ifx_spi_spi_probe()
1158 dev_err(&spi->dev, "Unable to configure GPIO%d (RESET_OUT)", in ifx_spi_spi_probe()
1159 ifx_dev->gpio.reset_out); in ifx_spi_spi_probe()
1160 ret = -EBUSY; in ifx_spi_spi_probe()
1164 ret = request_irq(gpio_to_irq(ifx_dev->gpio.reset_out), in ifx_spi_spi_probe()
1169 dev_err(&spi->dev, "Unable to get irq %x\n", in ifx_spi_spi_probe()
1170 gpio_to_irq(ifx_dev->gpio.reset_out)); in ifx_spi_spi_probe()
1176 ret = request_irq(gpio_to_irq(ifx_dev->gpio.srdy), in ifx_spi_spi_probe()
1180 dev_err(&spi->dev, "Unable to get irq %x", in ifx_spi_spi_probe()
1181 gpio_to_irq(ifx_dev->gpio.srdy)); in ifx_spi_spi_probe()
1186 pm_runtime_set_active(&spi->dev); in ifx_spi_spi_probe()
1187 pm_runtime_enable(&spi->dev); in ifx_spi_spi_probe()
1193 srdy = gpio_get_value(ifx_dev->gpio.srdy); in ifx_spi_spi_probe()
1203 free_irq(gpio_to_irq(ifx_dev->gpio.reset_out), ifx_dev); in ifx_spi_spi_probe()
1205 gpio_free(ifx_dev->gpio.srdy); in ifx_spi_spi_probe()
1207 gpio_free(ifx_dev->gpio.mrdy); in ifx_spi_spi_probe()
1209 gpio_free(ifx_dev->gpio.reset); in ifx_spi_spi_probe()
1211 gpio_free(ifx_dev->gpio.po); in ifx_spi_spi_probe()
1213 gpio_free(ifx_dev->gpio.reset_out); in ifx_spi_spi_probe()
1221 * ifx_spi_spi_remove - SPI device was removed
1222 * @spi: SPI device
1228 static int ifx_spi_spi_remove(struct spi_device *spi) in ifx_spi_spi_remove() argument
1230 struct ifx_spi_device *ifx_dev = spi_get_drvdata(spi); in ifx_spi_spi_remove()
1232 tasklet_kill(&ifx_dev->io_work_tasklet); in ifx_spi_spi_remove()
1234 pm_runtime_disable(&spi->dev); in ifx_spi_spi_remove()
1237 free_irq(gpio_to_irq(ifx_dev->gpio.reset_out), ifx_dev); in ifx_spi_spi_remove()
1238 free_irq(gpio_to_irq(ifx_dev->gpio.srdy), ifx_dev); in ifx_spi_spi_remove()
1240 gpio_free(ifx_dev->gpio.srdy); in ifx_spi_spi_remove()
1241 gpio_free(ifx_dev->gpio.mrdy); in ifx_spi_spi_remove()
1242 gpio_free(ifx_dev->gpio.reset); in ifx_spi_spi_remove()
1243 gpio_free(ifx_dev->gpio.po); in ifx_spi_spi_remove()
1244 gpio_free(ifx_dev->gpio.reset_out); in ifx_spi_spi_remove()
1254 * ifx_spi_spi_shutdown - called on SPI shutdown
1255 * @spi: SPI device
1260 static void ifx_spi_spi_shutdown(struct spi_device *spi) in ifx_spi_spi_shutdown() argument
1262 struct ifx_spi_device *ifx_dev = spi_get_drvdata(spi); in ifx_spi_spi_shutdown()
1273 * ifx_spi_pm_suspend - suspend modem on system suspend
1285 * ifx_spi_pm_resume - resume modem on system resume
1298 * ifx_spi_pm_runtime_resume - suspend modem
1309 * ifx_spi_pm_runtime_suspend - suspend modem
1321 * ifx_spi_pm_runtime_idle - check if modem idle
1328 struct spi_device *spi = to_spi_device(dev); in ifx_spi_pm_runtime_idle() local
1329 struct ifx_spi_device *ifx_dev = spi_get_drvdata(spi); in ifx_spi_pm_runtime_idle()
1331 if (!ifx_dev->power_status) in ifx_spi_pm_runtime_idle()
1350 MODULE_DEVICE_TABLE(spi, ifx_id_table);
1352 /* spi operations */
1365 * ifx_spi_exit - module exit
1380 * ifx_spi_init - module entry point
1382 * Initialise the SPI and tty interfaces for the IFX SPI driver
1383 * We need to initialize upper-edge spi driver after the tty
1384 * driver because otherwise the spi probe will race
1394 return -ENOMEM; in ifx_spi_init()
1397 tty_drv->driver_name = DRVNAME; in ifx_spi_init()
1398 tty_drv->name = TTYNAME; in ifx_spi_init()
1399 tty_drv->minor_start = IFX_SPI_TTY_ID; in ifx_spi_init()
1400 tty_drv->type = TTY_DRIVER_TYPE_SERIAL; in ifx_spi_init()
1401 tty_drv->subtype = SERIAL_TYPE_NORMAL; in ifx_spi_init()
1402 tty_drv->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; in ifx_spi_init()
1403 tty_drv->init_termios = tty_std_termios; in ifx_spi_init()
1443 MODULE_DESCRIPTION("IFX6x60 spi driver");
1445 MODULE_INFO(Version, "0.1-IFX6x60");