Lines Matching +full:spi +full:- +full:tx +full:- +full:delay +full:- +full:us

12  * to use polling for flow control. TX empty IRQ is unusable, since
14 * always asking us for attention.
34 * The initial minor number is 209 in the low-density serial port:
43 #include <linux/delay.h>
49 #include <linux/spi/spi.h>
99 struct spi_device *spi; member
102 int tx_empty; /* last TX empty bit */
107 * (bits 0-7, bits 8-11 are irqs) */
148 if (s->parity & MAX3100_PARITY_ODD) in max3100_do_parity()
153 if (s->parity & MAX3100_7BIT) in max3100_do_parity()
169 if (s->parity & MAX3100_7BIT) in max3100_calc_parity()
174 if (s->parity & MAX3100_PARITY_ON) in max3100_calc_parity()
182 if (!s->force_end_work && !work_pending(&s->work) && in max3100_dowork()
183 !freezing(current) && !s->suspending) in max3100_dowork()
184 queue_work(s->workqueue, &s->work); in max3100_dowork()
191 if (s->port.state) { in max3100_timeout()
193 mod_timer(&s->timer, jiffies + s->poll_time); in max3100_timeout()
197 static int max3100_sr(struct max3100_port *s, u16 tx, u16 *rx) in max3100_sr() argument
208 etx = cpu_to_be16(tx); in max3100_sr()
211 status = spi_sync(s->spi, &message); in max3100_sr()
213 dev_warn(&s->spi->dev, "error while calling spi_sync\n"); in max3100_sr()
214 return -EIO; in max3100_sr()
217 s->tx_empty = (*rx & MAX3100_T) > 0; in max3100_sr()
218 dev_dbg(&s->spi->dev, "%04x - %04x\n", tx, *rx); in max3100_sr()
227 if (rx & MAX3100_R && s->rx_enabled) { in max3100_handlerx()
228 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_handlerx()
229 ch = rx & (s->parity & MAX3100_7BIT ? 0x7f : 0xff); in max3100_handlerx()
231 s->port.icount.frame++; in max3100_handlerx()
235 if (s->parity & MAX3100_PARITY_ON) { in max3100_handlerx()
237 s->port.icount.rx++; in max3100_handlerx()
240 s->port.icount.parity++; in max3100_handlerx()
245 s->port.icount.rx++; in max3100_handlerx()
249 uart_insert_char(&s->port, status, MAX3100_STATUS_OE, ch, flg); in max3100_handlerx()
254 if (s->cts != cts) { in max3100_handlerx()
255 s->cts = cts; in max3100_handlerx()
256 uart_handle_cts_change(&s->port, cts ? TIOCM_CTS : 0); in max3100_handlerx()
266 u16 tx, rx; in max3100_work() local
268 struct circ_buf *xmit = &s->port.state->xmit; in max3100_work()
270 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_work()
274 spin_lock(&s->conf_lock); in max3100_work()
275 conf = s->conf; in max3100_work()
276 cconf = s->conf_commit; in max3100_work()
277 s->conf_commit = 0; in max3100_work()
278 rts = s->rts; in max3100_work()
279 crts = s->rts_commit; in max3100_work()
280 s->rts_commit = 0; in max3100_work()
281 spin_unlock(&s->conf_lock); in max3100_work()
286 (s->rts ? MAX3100_RTS : 0), &rx); in max3100_work()
294 tx = 0xffff; in max3100_work()
295 if (s->port.x_char) { in max3100_work()
296 tx = s->port.x_char; in max3100_work()
297 s->port.icount.tx++; in max3100_work()
298 s->port.x_char = 0; in max3100_work()
300 !uart_tx_stopped(&s->port)) { in max3100_work()
301 tx = xmit->buf[xmit->tail]; in max3100_work()
302 xmit->tail = (xmit->tail + 1) & in max3100_work()
303 (UART_XMIT_SIZE - 1); in max3100_work()
304 s->port.icount.tx++; in max3100_work()
306 if (tx != 0xffff) { in max3100_work()
307 max3100_calc_parity(s, &tx); in max3100_work()
308 tx |= MAX3100_WD | (s->rts ? MAX3100_RTS : 0); in max3100_work()
309 max3100_sr(s, tx, &rx); in max3100_work()
314 if (rxchars > 16 && s->port.state->port.tty != NULL) { in max3100_work()
315 tty_flip_buffer_push(s->port.state->port.tty); in max3100_work()
319 uart_write_wakeup(&s->port); in max3100_work()
321 } while (!s->force_end_work && in max3100_work()
325 !uart_tx_stopped(&s->port)))); in max3100_work()
327 if (rxchars > 0 && s->port.state->port.tty != NULL) in max3100_work()
328 tty_flip_buffer_push(s->port.state->port.tty); in max3100_work()
335 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_irq()
347 if (s->poll_time > 0) in max3100_enable_ms()
348 mod_timer(&s->timer, jiffies); in max3100_enable_ms()
349 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_enable_ms()
358 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_start_tx()
369 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_stop_rx()
371 s->rx_enabled = 0; in max3100_stop_rx()
372 spin_lock(&s->conf_lock); in max3100_stop_rx()
373 s->conf &= ~MAX3100_RM; in max3100_stop_rx()
374 s->conf_commit = 1; in max3100_stop_rx()
375 spin_unlock(&s->conf_lock); in max3100_stop_rx()
385 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_tx_empty()
387 /* may not be truly up-to-date */ in max3100_tx_empty()
389 return s->tx_empty; in max3100_tx_empty()
398 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_get_mctrl()
400 /* may not be truly up-to-date */ in max3100_get_mctrl()
403 return (s->cts ? TIOCM_CTS : 0) | TIOCM_DSR | TIOCM_CAR; in max3100_get_mctrl()
413 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_set_mctrl()
417 spin_lock(&s->conf_lock); in max3100_set_mctrl()
418 if (s->rts != rts) { in max3100_set_mctrl()
419 s->rts = rts; in max3100_set_mctrl()
420 s->rts_commit = 1; in max3100_set_mctrl()
423 spin_unlock(&s->conf_lock); in max3100_set_mctrl()
437 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_set_termios()
439 cflag = termios->c_cflag; in max3100_set_termios()
444 param_new = s->conf & MAX3100_BAUD; in max3100_set_termios()
447 if (s->crystal) in max3100_set_termios()
448 baud = s->baud; in max3100_set_termios()
453 param_new = 14 + s->crystal; in max3100_set_termios()
456 param_new = 13 + s->crystal; in max3100_set_termios()
459 param_new = 12 + s->crystal; in max3100_set_termios()
462 param_new = 11 + s->crystal; in max3100_set_termios()
465 param_new = 10 + s->crystal; in max3100_set_termios()
468 param_new = 9 + s->crystal; in max3100_set_termios()
471 param_new = 8 + s->crystal; in max3100_set_termios()
474 param_new = 1 + s->crystal; in max3100_set_termios()
477 param_new = 0 + s->crystal; in max3100_set_termios()
480 if (s->crystal) in max3100_set_termios()
483 baud = s->baud; in max3100_set_termios()
486 baud = s->baud; in max3100_set_termios()
489 s->baud = baud; in max3100_set_termios()
524 termios->c_cflag = cflag; in max3100_set_termios()
526 s->port.ignore_status_mask = 0; in max3100_set_termios()
527 if (termios->c_iflag & IGNPAR) in max3100_set_termios()
528 s->port.ignore_status_mask |= in max3100_set_termios()
533 s->port.state->port.tty->low_latency = 1; in max3100_set_termios()
535 if (s->poll_time > 0) in max3100_set_termios()
536 del_timer_sync(&s->timer); in max3100_set_termios()
538 uart_update_timeout(port, termios->c_cflag, baud); in max3100_set_termios()
540 spin_lock(&s->conf_lock); in max3100_set_termios()
541 s->conf = (s->conf & ~param_mask) | (param_new & param_mask); in max3100_set_termios()
542 s->conf_commit = 1; in max3100_set_termios()
543 s->parity = parity; in max3100_set_termios()
544 spin_unlock(&s->conf_lock); in max3100_set_termios()
547 if (UART_ENABLE_MS(&s->port, termios->c_cflag)) in max3100_set_termios()
548 max3100_enable_ms(&s->port); in max3100_set_termios()
557 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_shutdown()
559 if (s->suspending) in max3100_shutdown()
562 s->force_end_work = 1; in max3100_shutdown()
564 if (s->poll_time > 0) in max3100_shutdown()
565 del_timer_sync(&s->timer); in max3100_shutdown()
567 if (s->workqueue) { in max3100_shutdown()
568 flush_workqueue(s->workqueue); in max3100_shutdown()
569 destroy_workqueue(s->workqueue); in max3100_shutdown()
570 s->workqueue = NULL; in max3100_shutdown()
572 if (s->irq) in max3100_shutdown()
573 free_irq(s->irq, s); in max3100_shutdown()
576 if (s->max3100_hw_suspend) in max3100_shutdown()
577 s->max3100_hw_suspend(1); in max3100_shutdown()
579 u16 tx, rx; in max3100_shutdown() local
581 tx = MAX3100_WC | MAX3100_SHDN; in max3100_shutdown()
582 max3100_sr(s, tx, &rx); in max3100_shutdown()
593 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_startup()
595 s->conf = MAX3100_RM; in max3100_startup()
596 s->baud = s->crystal ? 230400 : 115200; in max3100_startup()
597 s->rx_enabled = 1; in max3100_startup()
599 if (s->suspending) in max3100_startup()
602 s->force_end_work = 0; in max3100_startup()
603 s->parity = 0; in max3100_startup()
604 s->rts = 0; in max3100_startup()
606 sprintf(b, "max3100-%d", s->minor); in max3100_startup()
607 s->workqueue = create_freezable_workqueue(b); in max3100_startup()
608 if (!s->workqueue) { in max3100_startup()
609 dev_warn(&s->spi->dev, "cannot create workqueue\n"); in max3100_startup()
610 return -EBUSY; in max3100_startup()
612 INIT_WORK(&s->work, max3100_work); in max3100_startup()
614 if (request_irq(s->irq, max3100_irq, in max3100_startup()
616 dev_warn(&s->spi->dev, "cannot allocate irq %d\n", s->irq); in max3100_startup()
617 s->irq = 0; in max3100_startup()
618 destroy_workqueue(s->workqueue); in max3100_startup()
619 s->workqueue = NULL; in max3100_startup()
620 return -EBUSY; in max3100_startup()
623 if (s->loopback) { in max3100_startup()
624 u16 tx, rx; in max3100_startup() local
625 tx = 0x4001; in max3100_startup()
626 max3100_sr(s, tx, &rx); in max3100_startup()
629 if (s->max3100_hw_suspend) in max3100_startup()
630 s->max3100_hw_suspend(0); in max3100_startup()
631 s->conf_commit = 1; in max3100_startup()
636 max3100_enable_ms(&s->port); in max3100_startup()
647 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_type()
649 return s->port.type == PORT_MAX3100 ? "MAX3100" : NULL; in max3100_type()
658 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_release_port()
667 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_config_port()
670 s->port.type = PORT_MAX3100; in max3100_config_port()
679 int ret = -EINVAL; in max3100_verify_port()
681 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_verify_port()
683 if (ser->type == PORT_UNKNOWN || ser->type == PORT_MAX3100) in max3100_verify_port()
694 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_stop_tx()
703 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_request_port()
713 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_break_ctl()
745 static int __devinit max3100_probe(struct spi_device *spi) in max3100_probe() argument
749 u16 tx, rx; in max3100_probe() local
767 dev_warn(&spi->dev, "too many MAX3100 chips\n"); in max3100_probe()
769 return -ENOMEM; in max3100_probe()
774 dev_warn(&spi->dev, in max3100_probe()
777 return -ENOMEM; in max3100_probe()
779 max3100s[i]->spi = spi; in max3100_probe()
780 max3100s[i]->irq = spi->irq; in max3100_probe()
781 spin_lock_init(&max3100s[i]->conf_lock); in max3100_probe()
782 dev_set_drvdata(&spi->dev, max3100s[i]); in max3100_probe()
783 pdata = spi->dev.platform_data; in max3100_probe()
784 max3100s[i]->crystal = pdata->crystal; in max3100_probe()
785 max3100s[i]->loopback = pdata->loopback; in max3100_probe()
786 max3100s[i]->poll_time = pdata->poll_time * HZ / 1000; in max3100_probe()
787 if (pdata->poll_time > 0 && max3100s[i]->poll_time == 0) in max3100_probe()
788 max3100s[i]->poll_time = 1; in max3100_probe()
789 max3100s[i]->max3100_hw_suspend = pdata->max3100_hw_suspend; in max3100_probe()
790 max3100s[i]->minor = i; in max3100_probe()
791 init_timer(&max3100s[i]->timer); in max3100_probe()
792 max3100s[i]->timer.function = max3100_timeout; in max3100_probe()
793 max3100s[i]->timer.data = (unsigned long) max3100s[i]; in max3100_probe()
795 dev_dbg(&spi->dev, "%s: adding port %d\n", __func__, i); in max3100_probe()
796 max3100s[i]->port.irq = max3100s[i]->irq; in max3100_probe()
797 max3100s[i]->port.uartclk = max3100s[i]->crystal ? 3686400 : 1843200; in max3100_probe()
798 max3100s[i]->port.fifosize = 16; in max3100_probe()
799 max3100s[i]->port.ops = &max3100_ops; in max3100_probe()
800 max3100s[i]->port.flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF; in max3100_probe()
801 max3100s[i]->port.line = i; in max3100_probe()
802 max3100s[i]->port.type = PORT_MAX3100; in max3100_probe()
803 max3100s[i]->port.dev = &spi->dev; in max3100_probe()
804 retval = uart_add_one_port(&max3100_uart_driver, &max3100s[i]->port); in max3100_probe()
806 dev_warn(&spi->dev, in max3100_probe()
810 /* set shutdown mode to save power. Will be woken-up on open */ in max3100_probe()
811 if (max3100s[i]->max3100_hw_suspend) in max3100_probe()
812 max3100s[i]->max3100_hw_suspend(1); in max3100_probe()
814 tx = MAX3100_WC | MAX3100_SHDN; in max3100_probe()
815 max3100_sr(max3100s[i], tx, &rx); in max3100_probe()
821 static int __devexit max3100_remove(struct spi_device *spi) in max3100_remove() argument
823 struct max3100_port *s = dev_get_drvdata(&spi->dev); in max3100_remove()
833 dev_dbg(&spi->dev, "%s: removing port %d\n", __func__, i); in max3100_remove()
834 uart_remove_one_port(&max3100_uart_driver, &max3100s[i]->port); in max3100_remove()
853 static int max3100_suspend(struct spi_device *spi, pm_message_t state) in max3100_suspend() argument
855 struct max3100_port *s = dev_get_drvdata(&spi->dev); in max3100_suspend()
857 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_suspend()
859 disable_irq(s->irq); in max3100_suspend()
861 s->suspending = 1; in max3100_suspend()
862 uart_suspend_port(&max3100_uart_driver, &s->port); in max3100_suspend()
864 if (s->max3100_hw_suspend) in max3100_suspend()
865 s->max3100_hw_suspend(1); in max3100_suspend()
868 u16 tx, rx; in max3100_suspend() local
870 tx = MAX3100_WC | MAX3100_SHDN; in max3100_suspend()
871 max3100_sr(s, tx, &rx); in max3100_suspend()
876 static int max3100_resume(struct spi_device *spi) in max3100_resume() argument
878 struct max3100_port *s = dev_get_drvdata(&spi->dev); in max3100_resume()
880 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_resume()
882 if (s->max3100_hw_suspend) in max3100_resume()
883 s->max3100_hw_suspend(0); in max3100_resume()
884 uart_resume_port(&max3100_uart_driver, &s->port); in max3100_resume()
885 s->suspending = 0; in max3100_resume()
887 enable_irq(s->irq); in max3100_resume()
889 s->conf_commit = 1; in max3100_resume()
890 if (s->workqueue) in max3100_resume()
928 MODULE_ALIAS("spi:max3100");