Lines Matching refs:s
468 static inline int is_imx28_auart(struct mxs_auart_port *s) in is_imx28_auart() argument
470 return s->devtype == IMX28_AUART; in is_imx28_auart()
473 static inline int is_asm9260_auart(struct mxs_auart_port *s) in is_asm9260_auart() argument
475 return s->devtype == ASM9260_AUART; in is_asm9260_auart()
478 static inline bool auart_dma_enabled(struct mxs_auart_port *s) in auart_dma_enabled() argument
480 return s->flags & MXS_AUART_DMA_ENABLED; in auart_dma_enabled()
525 static void mxs_auart_tx_chars(struct mxs_auart_port *s);
529 struct mxs_auart_port *s = param; in dma_tx_callback() local
530 struct circ_buf *xmit = &s->port.state->xmit; in dma_tx_callback()
532 dma_unmap_sg(s->dev, &s->tx_sgl, 1, DMA_TO_DEVICE); in dma_tx_callback()
535 clear_bit(MXS_AUART_DMA_TX_SYNC, &s->flags); in dma_tx_callback()
540 uart_write_wakeup(&s->port); in dma_tx_callback()
542 mxs_auart_tx_chars(s); in dma_tx_callback()
545 static int mxs_auart_dma_tx(struct mxs_auart_port *s, int size) in mxs_auart_dma_tx() argument
548 struct scatterlist *sgl = &s->tx_sgl; in mxs_auart_dma_tx()
549 struct dma_chan *channel = s->tx_dma_chan; in mxs_auart_dma_tx()
557 dev_err(s->dev, "step 1 error\n"); in mxs_auart_dma_tx()
562 sg_init_one(sgl, s->tx_dma_buf, size); in mxs_auart_dma_tx()
563 dma_map_sg(s->dev, sgl, 1, DMA_TO_DEVICE); in mxs_auart_dma_tx()
567 dev_err(s->dev, "step 2 error\n"); in mxs_auart_dma_tx()
573 desc->callback_param = s; in mxs_auart_dma_tx()
579 static void mxs_auart_tx_chars(struct mxs_auart_port *s) in mxs_auart_tx_chars() argument
581 struct circ_buf *xmit = &s->port.state->xmit; in mxs_auart_tx_chars()
583 if (auart_dma_enabled(s)) { in mxs_auart_tx_chars()
586 void *buffer = s->tx_dma_buf; in mxs_auart_tx_chars()
588 if (test_and_set_bit(MXS_AUART_DMA_TX_SYNC, &s->flags)) in mxs_auart_tx_chars()
591 while (!uart_circ_empty(xmit) && !uart_tx_stopped(&s->port)) { in mxs_auart_tx_chars()
604 if (uart_tx_stopped(&s->port)) in mxs_auart_tx_chars()
605 mxs_auart_stop_tx(&s->port); in mxs_auart_tx_chars()
608 mxs_auart_dma_tx(s, i); in mxs_auart_tx_chars()
610 clear_bit(MXS_AUART_DMA_TX_SYNC, &s->flags); in mxs_auart_tx_chars()
617 while (!(mxs_read(s, REG_STAT) & AUART_STAT_TXFF)) { in mxs_auart_tx_chars()
618 if (s->port.x_char) { in mxs_auart_tx_chars()
619 s->port.icount.tx++; in mxs_auart_tx_chars()
620 mxs_write(s->port.x_char, s, REG_DATA); in mxs_auart_tx_chars()
621 s->port.x_char = 0; in mxs_auart_tx_chars()
624 if (!uart_circ_empty(xmit) && !uart_tx_stopped(&s->port)) { in mxs_auart_tx_chars()
625 s->port.icount.tx++; in mxs_auart_tx_chars()
626 mxs_write(xmit->buf[xmit->tail], s, REG_DATA); in mxs_auart_tx_chars()
632 uart_write_wakeup(&s->port); in mxs_auart_tx_chars()
634 if (uart_circ_empty(&(s->port.state->xmit))) in mxs_auart_tx_chars()
635 mxs_clr(AUART_INTR_TXIEN, s, REG_INTR); in mxs_auart_tx_chars()
637 mxs_set(AUART_INTR_TXIEN, s, REG_INTR); in mxs_auart_tx_chars()
639 if (uart_tx_stopped(&s->port)) in mxs_auart_tx_chars()
640 mxs_auart_stop_tx(&s->port); in mxs_auart_tx_chars()
643 static void mxs_auart_rx_char(struct mxs_auart_port *s) in mxs_auart_rx_char() argument
649 c = mxs_read(s, REG_DATA); in mxs_auart_rx_char()
650 stat = mxs_read(s, REG_STAT); in mxs_auart_rx_char()
653 s->port.icount.rx++; in mxs_auart_rx_char()
656 s->port.icount.brk++; in mxs_auart_rx_char()
657 if (uart_handle_break(&s->port)) in mxs_auart_rx_char()
660 s->port.icount.parity++; in mxs_auart_rx_char()
662 s->port.icount.frame++; in mxs_auart_rx_char()
668 stat &= s->port.read_status_mask; in mxs_auart_rx_char()
678 s->port.icount.overrun++; in mxs_auart_rx_char()
680 if (uart_handle_sysrq_char(&s->port, c)) in mxs_auart_rx_char()
683 uart_insert_char(&s->port, stat, AUART_STAT_OERR, c, flag); in mxs_auart_rx_char()
685 mxs_write(stat, s, REG_STAT); in mxs_auart_rx_char()
688 static void mxs_auart_rx_chars(struct mxs_auart_port *s) in mxs_auart_rx_chars() argument
693 stat = mxs_read(s, REG_STAT); in mxs_auart_rx_chars()
696 mxs_auart_rx_char(s); in mxs_auart_rx_chars()
699 mxs_write(stat, s, REG_STAT); in mxs_auart_rx_chars()
700 tty_flip_buffer_push(&s->port.state->port); in mxs_auart_rx_chars()
722 struct mxs_auart_port *s = to_auart_port(u); in mxs_auart_type() local
724 return dev_name(s->dev); in mxs_auart_type()
733 struct mxs_auart_port *s = to_auart_port(u); in mxs_auart_set_mctrl() local
735 u32 ctrl = mxs_read(s, REG_CTRL2); in mxs_auart_set_mctrl()
745 mxs_write(ctrl, s, REG_CTRL2); in mxs_auart_set_mctrl()
747 mctrl_gpio_set(s->gpios, mctrl); in mxs_auart_set_mctrl()
751 static u32 mxs_auart_modem_status(struct mxs_auart_port *s, u32 mctrl) in mxs_auart_modem_status() argument
755 mctrl_diff = mctrl ^ s->mctrl_prev; in mxs_auart_modem_status()
756 s->mctrl_prev = mctrl; in mxs_auart_modem_status()
757 if (mctrl_diff & MCTRL_ANY_DELTA && s->ms_irq_enabled && in mxs_auart_modem_status()
758 s->port.state != NULL) { in mxs_auart_modem_status()
760 s->port.icount.rng++; in mxs_auart_modem_status()
762 s->port.icount.dsr++; in mxs_auart_modem_status()
764 uart_handle_dcd_change(&s->port, mctrl & TIOCM_CD); in mxs_auart_modem_status()
766 uart_handle_cts_change(&s->port, mctrl & TIOCM_CTS); in mxs_auart_modem_status()
768 wake_up_interruptible(&s->port.state->port.delta_msr_wait); in mxs_auart_modem_status()
775 struct mxs_auart_port *s = to_auart_port(u); in mxs_auart_get_mctrl() local
776 u32 stat = mxs_read(s, REG_STAT); in mxs_auart_get_mctrl()
782 return mctrl_gpio_get(s->gpios, &mctrl); in mxs_auart_get_mctrl()
790 struct mxs_auart_port *s = to_auart_port(port); in mxs_auart_enable_ms() local
795 if (s->ms_irq_enabled) in mxs_auart_enable_ms()
798 s->ms_irq_enabled = true; in mxs_auart_enable_ms()
800 if (s->gpio_irq[UART_GPIO_CTS] >= 0) in mxs_auart_enable_ms()
801 enable_irq(s->gpio_irq[UART_GPIO_CTS]); in mxs_auart_enable_ms()
804 if (s->gpio_irq[UART_GPIO_DSR] >= 0) in mxs_auart_enable_ms()
805 enable_irq(s->gpio_irq[UART_GPIO_DSR]); in mxs_auart_enable_ms()
807 if (s->gpio_irq[UART_GPIO_RI] >= 0) in mxs_auart_enable_ms()
808 enable_irq(s->gpio_irq[UART_GPIO_RI]); in mxs_auart_enable_ms()
810 if (s->gpio_irq[UART_GPIO_DCD] >= 0) in mxs_auart_enable_ms()
811 enable_irq(s->gpio_irq[UART_GPIO_DCD]); in mxs_auart_enable_ms()
819 struct mxs_auart_port *s = to_auart_port(port); in mxs_auart_disable_ms() local
824 if (!s->ms_irq_enabled) in mxs_auart_disable_ms()
827 s->ms_irq_enabled = false; in mxs_auart_disable_ms()
829 if (s->gpio_irq[UART_GPIO_CTS] >= 0) in mxs_auart_disable_ms()
830 disable_irq(s->gpio_irq[UART_GPIO_CTS]); in mxs_auart_disable_ms()
833 if (s->gpio_irq[UART_GPIO_DSR] >= 0) in mxs_auart_disable_ms()
834 disable_irq(s->gpio_irq[UART_GPIO_DSR]); in mxs_auart_disable_ms()
836 if (s->gpio_irq[UART_GPIO_RI] >= 0) in mxs_auart_disable_ms()
837 disable_irq(s->gpio_irq[UART_GPIO_RI]); in mxs_auart_disable_ms()
839 if (s->gpio_irq[UART_GPIO_DCD] >= 0) in mxs_auart_disable_ms()
840 disable_irq(s->gpio_irq[UART_GPIO_DCD]); in mxs_auart_disable_ms()
843 static int mxs_auart_dma_prep_rx(struct mxs_auart_port *s);
846 struct mxs_auart_port *s = (struct mxs_auart_port *) arg; in dma_rx_callback() local
847 struct tty_port *port = &s->port.state->port; in dma_rx_callback()
851 dma_unmap_sg(s->dev, &s->rx_sgl, 1, DMA_FROM_DEVICE); in dma_rx_callback()
853 stat = mxs_read(s, REG_STAT); in dma_rx_callback()
858 tty_insert_flip_string(port, s->rx_dma_buf, count); in dma_rx_callback()
860 mxs_write(stat, s, REG_STAT); in dma_rx_callback()
864 mxs_auart_dma_prep_rx(s); in dma_rx_callback()
867 static int mxs_auart_dma_prep_rx(struct mxs_auart_port *s) in mxs_auart_dma_prep_rx() argument
870 struct scatterlist *sgl = &s->rx_sgl; in mxs_auart_dma_prep_rx()
871 struct dma_chan *channel = s->rx_dma_chan; in mxs_auart_dma_prep_rx()
881 dev_err(s->dev, "step 1 error\n"); in mxs_auart_dma_prep_rx()
886 sg_init_one(sgl, s->rx_dma_buf, UART_XMIT_SIZE); in mxs_auart_dma_prep_rx()
887 dma_map_sg(s->dev, sgl, 1, DMA_FROM_DEVICE); in mxs_auart_dma_prep_rx()
891 dev_err(s->dev, "step 2 error\n"); in mxs_auart_dma_prep_rx()
897 desc->callback_param = s; in mxs_auart_dma_prep_rx()
903 static void mxs_auart_dma_exit_channel(struct mxs_auart_port *s) in mxs_auart_dma_exit_channel() argument
905 if (s->tx_dma_chan) { in mxs_auart_dma_exit_channel()
906 dma_release_channel(s->tx_dma_chan); in mxs_auart_dma_exit_channel()
907 s->tx_dma_chan = NULL; in mxs_auart_dma_exit_channel()
909 if (s->rx_dma_chan) { in mxs_auart_dma_exit_channel()
910 dma_release_channel(s->rx_dma_chan); in mxs_auart_dma_exit_channel()
911 s->rx_dma_chan = NULL; in mxs_auart_dma_exit_channel()
914 kfree(s->tx_dma_buf); in mxs_auart_dma_exit_channel()
915 kfree(s->rx_dma_buf); in mxs_auart_dma_exit_channel()
916 s->tx_dma_buf = NULL; in mxs_auart_dma_exit_channel()
917 s->rx_dma_buf = NULL; in mxs_auart_dma_exit_channel()
920 static void mxs_auart_dma_exit(struct mxs_auart_port *s) in mxs_auart_dma_exit() argument
924 s, REG_CTRL2); in mxs_auart_dma_exit()
926 mxs_auart_dma_exit_channel(s); in mxs_auart_dma_exit()
927 s->flags &= ~MXS_AUART_DMA_ENABLED; in mxs_auart_dma_exit()
928 clear_bit(MXS_AUART_DMA_TX_SYNC, &s->flags); in mxs_auart_dma_exit()
929 clear_bit(MXS_AUART_DMA_RX_READY, &s->flags); in mxs_auart_dma_exit()
932 static int mxs_auart_dma_init(struct mxs_auart_port *s) in mxs_auart_dma_init() argument
934 if (auart_dma_enabled(s)) in mxs_auart_dma_init()
938 s->rx_dma_chan = dma_request_slave_channel(s->dev, "rx"); in mxs_auart_dma_init()
939 if (!s->rx_dma_chan) in mxs_auart_dma_init()
941 s->rx_dma_buf = kzalloc(UART_XMIT_SIZE, GFP_KERNEL | GFP_DMA); in mxs_auart_dma_init()
942 if (!s->rx_dma_buf) in mxs_auart_dma_init()
946 s->tx_dma_chan = dma_request_slave_channel(s->dev, "tx"); in mxs_auart_dma_init()
947 if (!s->tx_dma_chan) in mxs_auart_dma_init()
949 s->tx_dma_buf = kzalloc(UART_XMIT_SIZE, GFP_KERNEL | GFP_DMA); in mxs_auart_dma_init()
950 if (!s->tx_dma_buf) in mxs_auart_dma_init()
954 s->flags |= MXS_AUART_DMA_ENABLED; in mxs_auart_dma_init()
955 dev_dbg(s->dev, "enabled the DMA support."); in mxs_auart_dma_init()
958 s->port.fifosize = UART_XMIT_SIZE; in mxs_auart_dma_init()
963 mxs_auart_dma_exit_channel(s); in mxs_auart_dma_init()
968 #define RTS_AT_AUART() !mctrl_gpio_to_gpiod(s->gpios, UART_GPIO_RTS)
969 #define CTS_AT_AUART() !mctrl_gpio_to_gpiod(s->gpios, UART_GPIO_CTS)
974 struct mxs_auart_port *s = to_auart_port(u); in mxs_auart_settermios() local
981 ctrl2 = mxs_read(s, REG_CTRL2); in mxs_auart_settermios()
1056 if (is_imx28_auart(s) in mxs_auart_settermios()
1057 && test_bit(MXS_AUART_RTSCTS, &s->flags)) { in mxs_auart_settermios()
1058 if (!mxs_auart_dma_init(s)) in mxs_auart_settermios()
1071 if (is_asm9260_auart(s)) { in mxs_auart_settermios()
1086 mxs_write(ctrl, s, REG_LINECTRL); in mxs_auart_settermios()
1088 mxs_write(ctrl2, s, REG_CTRL2); in mxs_auart_settermios()
1093 if (auart_dma_enabled(s) && in mxs_auart_settermios()
1094 !test_and_set_bit(MXS_AUART_DMA_RX_READY, &s->flags)) { in mxs_auart_settermios()
1095 if (!mxs_auart_dma_prep_rx(s)) { in mxs_auart_settermios()
1098 s, REG_INTR); in mxs_auart_settermios()
1100 mxs_auart_dma_exit(s); in mxs_auart_settermios()
1101 dev_err(s->dev, "We can not start up the DMA.\n"); in mxs_auart_settermios()
1126 struct mxs_auart_port *s = context; in mxs_auart_irq_handle() local
1127 u32 mctrl_temp = s->mctrl_prev; in mxs_auart_irq_handle()
1128 u32 stat = mxs_read(s, REG_STAT); in mxs_auart_irq_handle()
1130 istat = mxs_read(s, REG_INTR); in mxs_auart_irq_handle()
1134 | AUART_INTR_CTSMIS), s, REG_INTR); in mxs_auart_irq_handle()
1139 if (irq == s->gpio_irq[UART_GPIO_CTS] || in mxs_auart_irq_handle()
1140 irq == s->gpio_irq[UART_GPIO_DCD] || in mxs_auart_irq_handle()
1141 irq == s->gpio_irq[UART_GPIO_DSR] || in mxs_auart_irq_handle()
1142 irq == s->gpio_irq[UART_GPIO_RI]) in mxs_auart_irq_handle()
1143 mxs_auart_modem_status(s, in mxs_auart_irq_handle()
1144 mctrl_gpio_get(s->gpios, &mctrl_temp)); in mxs_auart_irq_handle()
1147 if (CTS_AT_AUART() && s->ms_irq_enabled) in mxs_auart_irq_handle()
1148 uart_handle_cts_change(&s->port, in mxs_auart_irq_handle()
1150 mxs_clr(AUART_INTR_CTSMIS, s, REG_INTR); in mxs_auart_irq_handle()
1155 if (!auart_dma_enabled(s)) in mxs_auart_irq_handle()
1156 mxs_auart_rx_chars(s); in mxs_auart_irq_handle()
1161 mxs_auart_tx_chars(s); in mxs_auart_irq_handle()
1168 static void mxs_auart_reset_deassert(struct mxs_auart_port *s) in mxs_auart_reset_deassert() argument
1173 mxs_clr(AUART_CTRL0_SFTRST, s, REG_CTRL0); in mxs_auart_reset_deassert()
1176 reg = mxs_read(s, REG_CTRL0); in mxs_auart_reset_deassert()
1181 mxs_clr(AUART_CTRL0_CLKGATE, s, REG_CTRL0); in mxs_auart_reset_deassert()
1184 static void mxs_auart_reset_assert(struct mxs_auart_port *s) in mxs_auart_reset_assert() argument
1189 reg = mxs_read(s, REG_CTRL0); in mxs_auart_reset_assert()
1194 mxs_clr(AUART_CTRL0_CLKGATE, s, REG_CTRL0); in mxs_auart_reset_assert()
1195 mxs_set(AUART_CTRL0_SFTRST, s, REG_CTRL0); in mxs_auart_reset_assert()
1198 reg = mxs_read(s, REG_CTRL0); in mxs_auart_reset_assert()
1205 dev_err(s->dev, "Failed to reset the unit."); in mxs_auart_reset_assert()
1211 struct mxs_auart_port *s = to_auart_port(u); in mxs_auart_startup() local
1213 ret = clk_prepare_enable(s->clk); in mxs_auart_startup()
1218 mxs_clr(AUART_CTRL0_CLKGATE, s, REG_CTRL0); in mxs_auart_startup()
1221 mxs_auart_reset_assert(s); in mxs_auart_startup()
1222 mxs_auart_reset_deassert(s); in mxs_auart_startup()
1225 mxs_set(AUART_CTRL2_UARTEN, s, REG_CTRL2); in mxs_auart_startup()
1228 s, REG_INTR); in mxs_auart_startup()
1237 mxs_set(AUART_LINECTRL_FEN, s, REG_LINECTRL); in mxs_auart_startup()
1240 mctrl_gpio_get(s->gpios, &s->mctrl_prev); in mxs_auart_startup()
1242 s->ms_irq_enabled = false; in mxs_auart_startup()
1248 struct mxs_auart_port *s = to_auart_port(u); in mxs_auart_shutdown() local
1252 if (auart_dma_enabled(s)) in mxs_auart_shutdown()
1253 mxs_auart_dma_exit(s); in mxs_auart_shutdown()
1256 mxs_clr(AUART_CTRL2_UARTEN, s, REG_CTRL2); in mxs_auart_shutdown()
1259 AUART_INTR_CTSMIEN, s, REG_INTR); in mxs_auart_shutdown()
1260 mxs_set(AUART_CTRL0_CLKGATE, s, REG_CTRL0); in mxs_auart_shutdown()
1262 mxs_auart_reset_assert(s); in mxs_auart_shutdown()
1265 clk_disable_unprepare(s->clk); in mxs_auart_shutdown()
1270 struct mxs_auart_port *s = to_auart_port(u); in mxs_auart_tx_empty() local
1272 if ((mxs_read(s, REG_STAT) & in mxs_auart_tx_empty()
1281 struct mxs_auart_port *s = to_auart_port(u); in mxs_auart_start_tx() local
1284 mxs_set(AUART_CTRL2_TXE, s, REG_CTRL2); in mxs_auart_start_tx()
1286 mxs_auart_tx_chars(s); in mxs_auart_start_tx()
1291 struct mxs_auart_port *s = to_auart_port(u); in mxs_auart_stop_tx() local
1293 mxs_clr(AUART_CTRL2_TXE, s, REG_CTRL2); in mxs_auart_stop_tx()
1298 struct mxs_auart_port *s = to_auart_port(u); in mxs_auart_stop_rx() local
1300 mxs_clr(AUART_CTRL2_RXE, s, REG_CTRL2); in mxs_auart_stop_rx()
1305 struct mxs_auart_port *s = to_auart_port(u); in mxs_auart_break_ctl() local
1308 mxs_set(AUART_LINECTRL_BRK, s, REG_LINECTRL); in mxs_auart_break_ctl()
1310 mxs_clr(AUART_LINECTRL_BRK, s, REG_LINECTRL); in mxs_auart_break_ctl()
1338 struct mxs_auart_port *s = to_auart_port(port); in mxs_auart_console_putchar() local
1341 while (mxs_read(s, REG_STAT) & AUART_STAT_TXFF) { in mxs_auart_console_putchar()
1347 mxs_write(ch, s, REG_DATA); in mxs_auart_console_putchar()
1353 struct mxs_auart_port *s; in auart_console_write() local
1361 s = auart_port[co->index]; in auart_console_write()
1362 port = &s->port; in auart_console_write()
1364 clk_enable(s->clk); in auart_console_write()
1367 old_ctrl2 = mxs_read(s, REG_CTRL2); in auart_console_write()
1368 old_ctrl0 = mxs_read(s, REG_CTRL0); in auart_console_write()
1370 mxs_clr(AUART_CTRL0_CLKGATE, s, REG_CTRL0); in auart_console_write()
1371 mxs_set(AUART_CTRL2_UARTEN | AUART_CTRL2_TXE, s, REG_CTRL2); in auart_console_write()
1376 while (mxs_read(s, REG_STAT) & AUART_STAT_BUSY) { in auart_console_write()
1388 if (!(mxs_read(s, REG_STAT) & AUART_STAT_BUSY)) { in auart_console_write()
1389 mxs_write(old_ctrl0, s, REG_CTRL0); in auart_console_write()
1390 mxs_write(old_ctrl2, s, REG_CTRL2); in auart_console_write()
1393 clk_disable(s->clk); in auart_console_write()
1397 auart_console_get_options(struct mxs_auart_port *s, int *baud, in auart_console_get_options() argument
1400 struct uart_port *port = &s->port; in auart_console_get_options()
1403 if (!(mxs_read(s, REG_CTRL2) & AUART_CTRL2_UARTEN)) in auart_console_get_options()
1406 lcr_h = mxs_read(s, REG_LINECTRL); in auart_console_get_options()
1421 quot = ((mxs_read(s, REG_LINECTRL) & AUART_LINECTRL_BAUD_DIVINT_MASK)) in auart_console_get_options()
1423 quot |= ((mxs_read(s, REG_LINECTRL) & AUART_LINECTRL_BAUD_DIVFRAC_MASK)) in auart_console_get_options()
1434 struct mxs_auart_port *s; in auart_console_setup() local
1448 s = auart_port[co->index]; in auart_console_setup()
1449 if (!s) in auart_console_setup()
1452 ret = clk_prepare_enable(s->clk); in auart_console_setup()
1459 auart_console_get_options(s, &baud, &parity, &bits); in auart_console_setup()
1461 ret = uart_set_options(&s->port, co, baud, parity, bits, flow); in auart_console_setup()
1463 clk_disable_unprepare(s->clk); in auart_console_setup()
1491 static void mxs_init_regs(struct mxs_auart_port *s) in mxs_init_regs() argument
1493 if (is_asm9260_auart(s)) in mxs_init_regs()
1494 s->vendor = &vendor_alphascale_asm9260; in mxs_init_regs()
1496 s->vendor = &vendor_freescale_stmp37xx; in mxs_init_regs()
1499 static int mxs_get_clks(struct mxs_auart_port *s, in mxs_get_clks() argument
1504 if (!is_asm9260_auart(s)) { in mxs_get_clks()
1505 s->clk = devm_clk_get(&pdev->dev, NULL); in mxs_get_clks()
1506 return PTR_ERR_OR_ZERO(s->clk); in mxs_get_clks()
1509 s->clk = devm_clk_get(s->dev, "mod"); in mxs_get_clks()
1510 if (IS_ERR(s->clk)) { in mxs_get_clks()
1511 dev_err(s->dev, "Failed to get \"mod\" clk\n"); in mxs_get_clks()
1512 return PTR_ERR(s->clk); in mxs_get_clks()
1515 s->clk_ahb = devm_clk_get(s->dev, "ahb"); in mxs_get_clks()
1516 if (IS_ERR(s->clk_ahb)) { in mxs_get_clks()
1517 dev_err(s->dev, "Failed to get \"ahb\" clk\n"); in mxs_get_clks()
1518 return PTR_ERR(s->clk_ahb); in mxs_get_clks()
1521 err = clk_prepare_enable(s->clk_ahb); in mxs_get_clks()
1523 dev_err(s->dev, "Failed to enable ahb_clk!\n"); in mxs_get_clks()
1527 err = clk_set_rate(s->clk, clk_get_rate(s->clk_ahb)); in mxs_get_clks()
1529 dev_err(s->dev, "Failed to set rate!\n"); in mxs_get_clks()
1533 err = clk_prepare_enable(s->clk); in mxs_get_clks()
1535 dev_err(s->dev, "Failed to enable clk!\n"); in mxs_get_clks()
1542 clk_disable_unprepare(s->clk_ahb); in mxs_get_clks()
1550 static int serial_mxs_probe_dt(struct mxs_auart_port *s, in serial_mxs_probe_dt() argument
1565 s->port.line = ret; in serial_mxs_probe_dt()
1569 set_bit(MXS_AUART_RTSCTS, &s->flags); in serial_mxs_probe_dt()
1574 static int mxs_auart_init_gpios(struct mxs_auart_port *s, struct device *dev) in mxs_auart_init_gpios() argument
1579 s->gpios = mctrl_gpio_init_noauto(dev, 0); in mxs_auart_init_gpios()
1580 if (IS_ERR(s->gpios)) in mxs_auart_init_gpios()
1581 return PTR_ERR(s->gpios); in mxs_auart_init_gpios()
1585 if (test_bit(MXS_AUART_RTSCTS, &s->flags)) in mxs_auart_init_gpios()
1588 clear_bit(MXS_AUART_RTSCTS, &s->flags); in mxs_auart_init_gpios()
1592 gpiod = mctrl_gpio_to_gpiod(s->gpios, i); in mxs_auart_init_gpios()
1594 s->gpio_irq[i] = gpiod_to_irq(gpiod); in mxs_auart_init_gpios()
1596 s->gpio_irq[i] = -EINVAL; in mxs_auart_init_gpios()
1602 static void mxs_auart_free_gpio_irq(struct mxs_auart_port *s) in mxs_auart_free_gpio_irq() argument
1607 if (s->gpio_irq[i] >= 0) in mxs_auart_free_gpio_irq()
1608 free_irq(s->gpio_irq[i], s); in mxs_auart_free_gpio_irq()
1611 static int mxs_auart_request_gpio_irq(struct mxs_auart_port *s) in mxs_auart_request_gpio_irq() argument
1613 int *irq = s->gpio_irq; in mxs_auart_request_gpio_irq()
1623 IRQ_TYPE_EDGE_BOTH, dev_name(s->dev), s); in mxs_auart_request_gpio_irq()
1625 dev_err(s->dev, "%s - Can't get %d irq\n", in mxs_auart_request_gpio_irq()
1635 free_irq(irq[i], s); in mxs_auart_request_gpio_irq()
1644 struct mxs_auart_port *s; in mxs_auart_probe() local
1649 s = devm_kzalloc(&pdev->dev, sizeof(*s), GFP_KERNEL); in mxs_auart_probe()
1650 if (!s) in mxs_auart_probe()
1653 s->port.dev = &pdev->dev; in mxs_auart_probe()
1654 s->dev = &pdev->dev; in mxs_auart_probe()
1656 ret = serial_mxs_probe_dt(s, pdev); in mxs_auart_probe()
1658 s->port.line = pdev->id < 0 ? 0 : pdev->id; in mxs_auart_probe()
1661 if (s->port.line >= ARRAY_SIZE(auart_port)) { in mxs_auart_probe()
1662 dev_err(&pdev->dev, "serial%d out of range\n", s->port.line); in mxs_auart_probe()
1668 s->devtype = pdev->id_entry->driver_data; in mxs_auart_probe()
1671 ret = mxs_get_clks(s, pdev); in mxs_auart_probe()
1681 s->port.mapbase = r->start; in mxs_auart_probe()
1682 s->port.membase = ioremap(r->start, resource_size(r)); in mxs_auart_probe()
1683 if (!s->port.membase) { in mxs_auart_probe()
1687 s->port.ops = &mxs_auart_ops; in mxs_auart_probe()
1688 s->port.iotype = UPIO_MEM; in mxs_auart_probe()
1689 s->port.fifosize = MXS_AUART_FIFO_SIZE; in mxs_auart_probe()
1690 s->port.uartclk = clk_get_rate(s->clk); in mxs_auart_probe()
1691 s->port.type = PORT_IMX; in mxs_auart_probe()
1692 s->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_MXS_AUART_CONSOLE); in mxs_auart_probe()
1694 mxs_init_regs(s); in mxs_auart_probe()
1696 s->mctrl_prev = 0; in mxs_auart_probe()
1704 s->port.irq = irq; in mxs_auart_probe()
1706 dev_name(&pdev->dev), s); in mxs_auart_probe()
1710 platform_set_drvdata(pdev, s); in mxs_auart_probe()
1712 ret = mxs_auart_init_gpios(s, &pdev->dev); in mxs_auart_probe()
1721 ret = mxs_auart_request_gpio_irq(s); in mxs_auart_probe()
1725 auart_port[s->port.line] = s; in mxs_auart_probe()
1727 mxs_auart_reset_deassert(s); in mxs_auart_probe()
1729 ret = uart_add_one_port(&auart_driver, &s->port); in mxs_auart_probe()
1734 if (is_asm9260_auart(s)) { in mxs_auart_probe()
1737 version = mxs_read(s, REG_VERSION); in mxs_auart_probe()
1746 mxs_auart_free_gpio_irq(s); in mxs_auart_probe()
1750 iounmap(s->port.membase); in mxs_auart_probe()
1753 if (is_asm9260_auart(s)) { in mxs_auart_probe()
1754 clk_disable_unprepare(s->clk); in mxs_auart_probe()
1755 clk_disable_unprepare(s->clk_ahb); in mxs_auart_probe()
1762 struct mxs_auart_port *s = platform_get_drvdata(pdev); in mxs_auart_remove() local
1764 uart_remove_one_port(&auart_driver, &s->port); in mxs_auart_remove()
1766 mxs_auart_free_gpio_irq(s); in mxs_auart_remove()
1767 iounmap(s->port.membase); in mxs_auart_remove()
1768 if (is_asm9260_auart(s)) { in mxs_auart_remove()
1769 clk_disable_unprepare(s->clk); in mxs_auart_remove()
1770 clk_disable_unprepare(s->clk_ahb); in mxs_auart_remove()