Lines Matching +full:rng +full:- +full:gpios
1 // SPDX-License-Identifier: GPL-2.0+
23 #include <linux/dma-mapping.h>
61 /* Use device name ttyAT, major 204 and minor 154-169. This is necessary if we
70 /* Use device name ttyS, major 4, minor 64-68. This is the usual serial port
143 struct mctrl_gpios *gpios; member
162 bool hd_start_rx; /* can start RX during half-duplex operation */
194 { .compatible = "atmel,at91rm9200-usart-serial" },
207 return __raw_readl(port->membase + reg); in atmel_uart_readl()
212 __raw_writel(value, port->membase + reg); in atmel_uart_writel()
217 return __raw_readb(port->membase + ATMEL_US_RHR); in atmel_uart_read_char()
222 __raw_writeb(value, port->membase + ATMEL_US_THR); in atmel_uart_write_char()
227 return ((port->rs485.flags & SER_RS485_ENABLED) && in atmel_uart_is_half_duplex()
228 !(port->rs485.flags & SER_RS485_RX_DURING_TX)) || in atmel_uart_is_half_duplex()
229 (port->iso7816.flags & SER_ISO7816_ENABLED); in atmel_uart_is_half_duplex()
237 return atmel_port->use_pdc_rx; in atmel_use_pdc_rx()
244 return atmel_port->use_pdc_tx; in atmel_use_pdc_tx()
262 return atmel_port->use_dma_tx; in atmel_use_dma_tx()
269 return atmel_port->use_dma_rx; in atmel_use_dma_rx()
276 return atmel_port->fifo_size; in atmel_use_fifo()
282 if (!atomic_read(&atmel_port->tasklet_shutdown)) in atmel_tasklet_schedule()
294 atmel_uart_writel(port, ATMEL_US_IDR, atmel_port->tx_done_mask); in atmel_config_rs485()
301 port->rs485 = *rs485conf; in atmel_config_rs485()
303 if (rs485conf->flags & SER_RS485_ENABLED) { in atmel_config_rs485()
304 dev_dbg(port->dev, "Setting UART to RS485\n"); in atmel_config_rs485()
305 if (port->rs485.flags & SER_RS485_RX_DURING_TX) in atmel_config_rs485()
306 atmel_port->tx_done_mask = ATMEL_US_TXRDY; in atmel_config_rs485()
308 atmel_port->tx_done_mask = ATMEL_US_TXEMPTY; in atmel_config_rs485()
311 rs485conf->delay_rts_after_send); in atmel_config_rs485()
314 dev_dbg(port->dev, "Setting UART to RS232\n"); in atmel_config_rs485()
316 atmel_port->tx_done_mask = ATMEL_US_ENDTX | in atmel_config_rs485()
319 atmel_port->tx_done_mask = ATMEL_US_TXRDY; in atmel_config_rs485()
324 atmel_uart_writel(port, ATMEL_US_IER, atmel_port->tx_done_mask); in atmel_config_rs485()
336 mck_rate = (u64)clk_get_rate(atmel_port->clk); in atmel_calc_cd()
337 do_div(mck_rate, iso7816conf->clk); in atmel_calc_cd()
347 if (iso7816conf->sc_fi && iso7816conf->sc_di) { in atmel_calc_fidi()
348 fidi = (u64)iso7816conf->sc_fi; in atmel_calc_fidi()
349 do_div(fidi, iso7816conf->sc_di); in atmel_calc_fidi()
365 atmel_uart_writel(port, ATMEL_US_IDR, atmel_port->tx_done_mask); in atmel_config_iso7816()
369 if (iso7816conf->flags & SER_ISO7816_ENABLED) { in atmel_config_iso7816()
372 if (iso7816conf->tg > 255) { in atmel_config_iso7816()
373 dev_err(port->dev, "ISO7816: Timeguard exceeding 255\n"); in atmel_config_iso7816()
375 ret = -EINVAL; in atmel_config_iso7816()
379 if ((iso7816conf->flags & SER_ISO7816_T_PARAM) in atmel_config_iso7816()
382 } else if ((iso7816conf->flags & SER_ISO7816_T_PARAM) in atmel_config_iso7816()
386 dev_err(port->dev, "ISO7816: Type not supported\n"); in atmel_config_iso7816()
388 ret = -EINVAL; in atmel_config_iso7816()
402 dev_warn(port->dev, "ISO7816 fidi = 0, Generator generates no signal\n"); in atmel_config_iso7816()
403 } else if (fidi < atmel_port->fidi_min in atmel_config_iso7816()
404 || fidi > atmel_port->fidi_max) { in atmel_config_iso7816()
405 dev_err(port->dev, "ISO7816 fidi = %u, value not supported\n", fidi); in atmel_config_iso7816()
407 ret = -EINVAL; in atmel_config_iso7816()
411 if (!(port->iso7816.flags & SER_ISO7816_ENABLED)) { in atmel_config_iso7816()
413 atmel_port->backup_mode = atmel_uart_readl(port, ATMEL_US_MR); in atmel_config_iso7816()
414 atmel_port->backup_brgr = atmel_uart_readl(port, ATMEL_US_BRGR); in atmel_config_iso7816()
417 atmel_uart_writel(port, ATMEL_US_TTGR, iso7816conf->tg); in atmel_config_iso7816()
422 atmel_port->tx_done_mask = ATMEL_US_TXEMPTY | ATMEL_US_NACK | ATMEL_US_ITERATION; in atmel_config_iso7816()
424 dev_dbg(port->dev, "Setting UART back to RS232\n"); in atmel_config_iso7816()
426 mode = atmel_port->backup_mode; in atmel_config_iso7816()
429 atmel_uart_writel(port, ATMEL_US_BRGR, atmel_port->backup_brgr); in atmel_config_iso7816()
433 atmel_port->tx_done_mask = ATMEL_US_ENDTX | in atmel_config_iso7816()
436 atmel_port->tx_done_mask = ATMEL_US_TXRDY; in atmel_config_iso7816()
439 port->iso7816 = *iso7816conf; in atmel_config_iso7816()
445 atmel_uart_writel(port, ATMEL_US_IER, atmel_port->tx_done_mask); in atmel_config_iso7816()
457 if (atmel_port->tx_stopped) in atmel_tx_empty()
475 if (port->rs485.flags & SER_RS485_ENABLED) { in atmel_set_mctrl()
477 port->rs485.delay_rts_after_send); in atmel_set_mctrl()
509 mctrl_gpio_set(atmel_port->gpios, mctrl); in atmel_set_mctrl()
543 return mctrl_gpio_get(atmel_port->gpios, &ret); in atmel_get_mctrl()
564 atmel_port->tx_stopped = true; in atmel_stop_tx()
567 atmel_uart_writel(port, ATMEL_US_IDR, atmel_port->tx_done_mask); in atmel_stop_tx()
570 if (!atomic_read(&atmel_port->tasklet_shutdown)) in atmel_stop_tx()
593 /* re-enable PDC transmit */ in atmel_start_tx()
597 atmel_uart_writel(port, ATMEL_US_IER, atmel_port->tx_done_mask); in atmel_start_tx()
599 /* re-enable the transmitter */ in atmel_start_tx()
601 atmel_port->tx_stopped = false; in atmel_start_tx()
605 * start receiving - port is in process of being opened.
618 port->read_status_mask); in atmel_start_rx()
626 * Stop receiving - port is in process of being closed.
637 port->read_status_mask); in atmel_stop_rx()
654 if (atmel_port->ms_irq_enabled) in atmel_enable_ms()
657 atmel_port->ms_irq_enabled = true; in atmel_enable_ms()
659 if (!mctrl_gpio_to_gpiod(atmel_port->gpios, UART_GPIO_CTS)) in atmel_enable_ms()
662 if (!mctrl_gpio_to_gpiod(atmel_port->gpios, UART_GPIO_DSR)) in atmel_enable_ms()
665 if (!mctrl_gpio_to_gpiod(atmel_port->gpios, UART_GPIO_RI)) in atmel_enable_ms()
668 if (!mctrl_gpio_to_gpiod(atmel_port->gpios, UART_GPIO_DCD)) in atmel_enable_ms()
673 mctrl_gpio_enable_ms(atmel_port->gpios); in atmel_enable_ms()
687 if (!atmel_port->ms_irq_enabled) in atmel_disable_ms()
690 atmel_port->ms_irq_enabled = false; in atmel_disable_ms()
692 mctrl_gpio_disable_ms(atmel_port->gpios); in atmel_disable_ms()
694 if (!mctrl_gpio_to_gpiod(atmel_port->gpios, UART_GPIO_CTS)) in atmel_disable_ms()
697 if (!mctrl_gpio_to_gpiod(atmel_port->gpios, UART_GPIO_DSR)) in atmel_disable_ms()
700 if (!mctrl_gpio_to_gpiod(atmel_port->gpios, UART_GPIO_RI)) in atmel_disable_ms()
703 if (!mctrl_gpio_to_gpiod(atmel_port->gpios, UART_GPIO_DCD)) in atmel_disable_ms()
730 struct circ_buf *ring = &atmel_port->rx_ring; in atmel_buffer_rx_char()
733 if (!CIRC_SPACE(ring->head, ring->tail, ATMEL_SERIAL_RINGSIZE)) in atmel_buffer_rx_char()
737 c = &((struct atmel_uart_char *)ring->buf)[ring->head]; in atmel_buffer_rx_char()
738 c->status = status; in atmel_buffer_rx_char()
739 c->ch = ch; in atmel_buffer_rx_char()
744 ring->head = (ring->head + 1) & (ATMEL_SERIAL_RINGSIZE - 1); in atmel_buffer_rx_char()
756 /* ignore side-effect */ in atmel_pdc_rxerr()
758 port->icount.brk++; in atmel_pdc_rxerr()
761 port->icount.parity++; in atmel_pdc_rxerr()
763 port->icount.frame++; in atmel_pdc_rxerr()
765 port->icount.overrun++; in atmel_pdc_rxerr()
786 || atmel_port->break_active)) { in atmel_rx_chars()
792 && !atmel_port->break_active) { in atmel_rx_chars()
793 atmel_port->break_active = 1; in atmel_rx_chars()
798 * This is either the end-of-break in atmel_rx_chars()
802 * RXBRK will indicate start-of-break. in atmel_rx_chars()
807 atmel_port->break_active = 0; in atmel_rx_chars()
815 atmel_tasklet_schedule(atmel_port, &atmel_port->tasklet_rx); in atmel_rx_chars()
824 struct circ_buf *xmit = &port->state->xmit; in atmel_tx_chars()
827 if (port->x_char && in atmel_tx_chars()
829 atmel_uart_write_char(port, port->x_char); in atmel_tx_chars()
830 port->icount.tx++; in atmel_tx_chars()
831 port->x_char = 0; in atmel_tx_chars()
837 atmel_uart_write_char(port, xmit->buf[xmit->tail]); in atmel_tx_chars()
838 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); in atmel_tx_chars()
839 port->icount.tx++; in atmel_tx_chars()
852 atmel_port->tx_done_mask |= ATMEL_US_TXRDY; in atmel_tx_chars()
856 atmel_port->tx_done_mask); in atmel_tx_chars()
859 atmel_port->tx_done_mask &= ~ATMEL_US_TXRDY; in atmel_tx_chars()
866 struct uart_port *port = &atmel_port->uart; in atmel_complete_tx_dma()
867 struct circ_buf *xmit = &port->state->xmit; in atmel_complete_tx_dma()
868 struct dma_chan *chan = atmel_port->chan_tx; in atmel_complete_tx_dma()
871 spin_lock_irqsave(&port->lock, flags); in atmel_complete_tx_dma()
875 xmit->tail += atmel_port->tx_len; in atmel_complete_tx_dma()
876 xmit->tail &= UART_XMIT_SIZE - 1; in atmel_complete_tx_dma()
878 port->icount.tx += atmel_port->tx_len; in atmel_complete_tx_dma()
880 spin_lock_irq(&atmel_port->lock_tx); in atmel_complete_tx_dma()
881 async_tx_ack(atmel_port->desc_tx); in atmel_complete_tx_dma()
882 atmel_port->cookie_tx = -EINVAL; in atmel_complete_tx_dma()
883 atmel_port->desc_tx = NULL; in atmel_complete_tx_dma()
884 spin_unlock_irq(&atmel_port->lock_tx); in atmel_complete_tx_dma()
891 * xmit->tail to the end of xmit->buf, now we have to transmit the in atmel_complete_tx_dma()
892 * remaining data from the beginning of xmit->buf to xmit->head. in atmel_complete_tx_dma()
895 atmel_tasklet_schedule(atmel_port, &atmel_port->tasklet_tx); in atmel_complete_tx_dma()
898 * DMA done, re-enable TXEMPTY and signal that we can stop in atmel_complete_tx_dma()
901 atmel_port->hd_start_rx = true; in atmel_complete_tx_dma()
903 atmel_port->tx_done_mask); in atmel_complete_tx_dma()
906 spin_unlock_irqrestore(&port->lock, flags); in atmel_complete_tx_dma()
912 struct dma_chan *chan = atmel_port->chan_tx; in atmel_release_tx_dma()
917 dma_unmap_sg(port->dev, &atmel_port->sg_tx, 1, in atmel_release_tx_dma()
921 atmel_port->desc_tx = NULL; in atmel_release_tx_dma()
922 atmel_port->chan_tx = NULL; in atmel_release_tx_dma()
923 atmel_port->cookie_tx = -EINVAL; in atmel_release_tx_dma()
932 struct circ_buf *xmit = &port->state->xmit; in atmel_tx_dma()
933 struct dma_chan *chan = atmel_port->chan_tx; in atmel_tx_dma()
935 struct scatterlist sgl[2], *sg, *sg_tx = &atmel_port->sg_tx; in atmel_tx_dma()
940 if (atmel_port->desc_tx != NULL) in atmel_tx_dma()
953 tx_len = CIRC_CNT_TO_END(xmit->head, in atmel_tx_dma()
954 xmit->tail, in atmel_tx_dma()
957 if (atmel_port->fifo_size) { in atmel_tx_dma()
969 phys_addr = sg_dma_address(sg_tx) + xmit->tail; in atmel_tx_dma()
986 * xmit->tail correctly in atmel_tx_dma()
988 atmel_port->tx_len = tx_len; in atmel_tx_dma()
997 dev_err(port->dev, "Failed to send via dma!\n"); in atmel_tx_dma()
1001 dma_sync_sg_for_device(port->dev, sg_tx, 1, DMA_TO_DEVICE); in atmel_tx_dma()
1003 atmel_port->desc_tx = desc; in atmel_tx_dma()
1004 desc->callback = atmel_complete_tx_dma; in atmel_tx_dma()
1005 desc->callback_param = atmel_port; in atmel_tx_dma()
1006 atmel_port->cookie_tx = dmaengine_submit(desc); in atmel_tx_dma()
1016 struct device *mfd_dev = port->dev->parent; in atmel_prepare_tx_dma()
1024 atmel_port->chan_tx = dma_request_slave_channel(mfd_dev, "tx"); in atmel_prepare_tx_dma()
1025 if (atmel_port->chan_tx == NULL) in atmel_prepare_tx_dma()
1027 dev_info(port->dev, "using %s for tx DMA transfers\n", in atmel_prepare_tx_dma()
1028 dma_chan_name(atmel_port->chan_tx)); in atmel_prepare_tx_dma()
1030 spin_lock_init(&atmel_port->lock_tx); in atmel_prepare_tx_dma()
1031 sg_init_table(&atmel_port->sg_tx, 1); in atmel_prepare_tx_dma()
1033 BUG_ON(!PAGE_ALIGNED(port->state->xmit.buf)); in atmel_prepare_tx_dma()
1034 sg_set_page(&atmel_port->sg_tx, in atmel_prepare_tx_dma()
1035 virt_to_page(port->state->xmit.buf), in atmel_prepare_tx_dma()
1037 offset_in_page(port->state->xmit.buf)); in atmel_prepare_tx_dma()
1038 nent = dma_map_sg(port->dev, in atmel_prepare_tx_dma()
1039 &atmel_port->sg_tx, in atmel_prepare_tx_dma()
1044 dev_dbg(port->dev, "need to release resource of dma\n"); in atmel_prepare_tx_dma()
1047 dev_dbg(port->dev, "%s: mapped %d@%p to %pad\n", __func__, in atmel_prepare_tx_dma()
1048 sg_dma_len(&atmel_port->sg_tx), in atmel_prepare_tx_dma()
1049 port->state->xmit.buf, in atmel_prepare_tx_dma()
1050 &sg_dma_address(&atmel_port->sg_tx)); in atmel_prepare_tx_dma()
1056 config.dst_addr_width = (atmel_port->fifo_size) ? in atmel_prepare_tx_dma()
1059 config.dst_addr = port->mapbase + ATMEL_US_THR; in atmel_prepare_tx_dma()
1062 ret = dmaengine_slave_config(atmel_port->chan_tx, in atmel_prepare_tx_dma()
1065 dev_err(port->dev, "DMA tx slave configuration failed\n"); in atmel_prepare_tx_dma()
1072 dev_err(port->dev, "TX channel not available, switch to pio\n"); in atmel_prepare_tx_dma()
1073 atmel_port->use_dma_tx = false; in atmel_prepare_tx_dma()
1074 if (atmel_port->chan_tx) in atmel_prepare_tx_dma()
1076 return -EINVAL; in atmel_prepare_tx_dma()
1084 atmel_tasklet_schedule(atmel_port, &atmel_port->tasklet_rx); in atmel_complete_rx_dma()
1090 struct dma_chan *chan = atmel_port->chan_rx; in atmel_release_rx_dma()
1095 dma_unmap_sg(port->dev, &atmel_port->sg_rx, 1, in atmel_release_rx_dma()
1099 atmel_port->desc_rx = NULL; in atmel_release_rx_dma()
1100 atmel_port->chan_rx = NULL; in atmel_release_rx_dma()
1101 atmel_port->cookie_rx = -EINVAL; in atmel_release_rx_dma()
1107 struct tty_port *tport = &port->state->port; in atmel_rx_from_dma()
1108 struct circ_buf *ring = &atmel_port->rx_ring; in atmel_rx_from_dma()
1109 struct dma_chan *chan = atmel_port->chan_rx; in atmel_rx_from_dma()
1118 atmel_port->cookie_rx, in atmel_rx_from_dma()
1122 dev_dbg(port->dev, "Get residue error, restart tasklet\n"); in atmel_rx_from_dma()
1124 atmel_tasklet_schedule(atmel_port, &atmel_port->tasklet_rx); in atmel_rx_from_dma()
1129 dma_sync_sg_for_cpu(port->dev, in atmel_rx_from_dma()
1130 &atmel_port->sg_rx, in atmel_rx_from_dma()
1135 * ring->head points to the end of data already written by the DMA. in atmel_rx_from_dma()
1136 * ring->tail points to the beginning of data to be read by the in atmel_rx_from_dma()
1141 ring->head = sg_dma_len(&atmel_port->sg_rx) - state.residue; in atmel_rx_from_dma()
1142 BUG_ON(ring->head > sg_dma_len(&atmel_port->sg_rx)); in atmel_rx_from_dma()
1144 * At this point ring->head may point to the first byte right after the in atmel_rx_from_dma()
1146 * 0 <= ring->head <= sg_dma_len(&atmel_port->sg_rx) in atmel_rx_from_dma()
1148 * However ring->tail must always points inside the dma buffer: in atmel_rx_from_dma()
1149 * 0 <= ring->tail <= sg_dma_len(&atmel_port->sg_rx) - 1 in atmel_rx_from_dma()
1155 if (ring->head < ring->tail) { in atmel_rx_from_dma()
1156 count = sg_dma_len(&atmel_port->sg_rx) - ring->tail; in atmel_rx_from_dma()
1158 tty_insert_flip_string(tport, ring->buf + ring->tail, count); in atmel_rx_from_dma()
1159 ring->tail = 0; in atmel_rx_from_dma()
1160 port->icount.rx += count; in atmel_rx_from_dma()
1164 if (ring->tail < ring->head) { in atmel_rx_from_dma()
1165 count = ring->head - ring->tail; in atmel_rx_from_dma()
1167 tty_insert_flip_string(tport, ring->buf + ring->tail, count); in atmel_rx_from_dma()
1168 /* Wrap ring->head if needed */ in atmel_rx_from_dma()
1169 if (ring->head >= sg_dma_len(&atmel_port->sg_rx)) in atmel_rx_from_dma()
1170 ring->head = 0; in atmel_rx_from_dma()
1171 ring->tail = ring->head; in atmel_rx_from_dma()
1172 port->icount.rx += count; in atmel_rx_from_dma()
1176 dma_sync_sg_for_device(port->dev, in atmel_rx_from_dma()
1177 &atmel_port->sg_rx, in atmel_rx_from_dma()
1185 spin_unlock(&port->lock); in atmel_rx_from_dma()
1187 spin_lock(&port->lock); in atmel_rx_from_dma()
1195 struct device *mfd_dev = port->dev->parent; in atmel_prepare_rx_dma()
1202 ring = &atmel_port->rx_ring; in atmel_prepare_rx_dma()
1207 atmel_port->chan_rx = dma_request_slave_channel(mfd_dev, "rx"); in atmel_prepare_rx_dma()
1208 if (atmel_port->chan_rx == NULL) in atmel_prepare_rx_dma()
1210 dev_info(port->dev, "using %s for rx DMA transfers\n", in atmel_prepare_rx_dma()
1211 dma_chan_name(atmel_port->chan_rx)); in atmel_prepare_rx_dma()
1213 spin_lock_init(&atmel_port->lock_rx); in atmel_prepare_rx_dma()
1214 sg_init_table(&atmel_port->sg_rx, 1); in atmel_prepare_rx_dma()
1216 BUG_ON(!PAGE_ALIGNED(ring->buf)); in atmel_prepare_rx_dma()
1217 sg_set_page(&atmel_port->sg_rx, in atmel_prepare_rx_dma()
1218 virt_to_page(ring->buf), in atmel_prepare_rx_dma()
1220 offset_in_page(ring->buf)); in atmel_prepare_rx_dma()
1221 nent = dma_map_sg(port->dev, in atmel_prepare_rx_dma()
1222 &atmel_port->sg_rx, in atmel_prepare_rx_dma()
1227 dev_dbg(port->dev, "need to release resource of dma\n"); in atmel_prepare_rx_dma()
1230 dev_dbg(port->dev, "%s: mapped %d@%p to %pad\n", __func__, in atmel_prepare_rx_dma()
1231 sg_dma_len(&atmel_port->sg_rx), in atmel_prepare_rx_dma()
1232 ring->buf, in atmel_prepare_rx_dma()
1233 &sg_dma_address(&atmel_port->sg_rx)); in atmel_prepare_rx_dma()
1240 config.src_addr = port->mapbase + ATMEL_US_RHR; in atmel_prepare_rx_dma()
1243 ret = dmaengine_slave_config(atmel_port->chan_rx, in atmel_prepare_rx_dma()
1246 dev_err(port->dev, "DMA rx slave configuration failed\n"); in atmel_prepare_rx_dma()
1253 desc = dmaengine_prep_dma_cyclic(atmel_port->chan_rx, in atmel_prepare_rx_dma()
1254 sg_dma_address(&atmel_port->sg_rx), in atmel_prepare_rx_dma()
1255 sg_dma_len(&atmel_port->sg_rx), in atmel_prepare_rx_dma()
1256 sg_dma_len(&atmel_port->sg_rx)/2, in atmel_prepare_rx_dma()
1260 dev_err(port->dev, "Preparing DMA cyclic failed\n"); in atmel_prepare_rx_dma()
1263 desc->callback = atmel_complete_rx_dma; in atmel_prepare_rx_dma()
1264 desc->callback_param = port; in atmel_prepare_rx_dma()
1265 atmel_port->desc_rx = desc; in atmel_prepare_rx_dma()
1266 atmel_port->cookie_rx = dmaengine_submit(desc); in atmel_prepare_rx_dma()
1271 dev_err(port->dev, "RX channel not available, switch to pio\n"); in atmel_prepare_rx_dma()
1272 atmel_port->use_dma_rx = false; in atmel_prepare_rx_dma()
1273 if (atmel_port->chan_rx) in atmel_prepare_rx_dma()
1275 return -EINVAL; in atmel_prepare_rx_dma()
1282 struct uart_port *port = &atmel_port->uart; in atmel_uart_timer_callback()
1284 if (!atomic_read(&atmel_port->tasklet_shutdown)) { in atmel_uart_timer_callback()
1285 tasklet_schedule(&atmel_port->tasklet_rx); in atmel_uart_timer_callback()
1286 mod_timer(&atmel_port->uart_timer, in atmel_uart_timer_callback()
1311 &atmel_port->tasklet_rx); in atmel_handle_receive()
1324 &atmel_port->tasklet_rx); in atmel_handle_receive()
1338 atmel_port->break_active = 0; in atmel_handle_receive()
1350 if (pending & atmel_port->tx_done_mask) { in atmel_handle_transmit()
1352 atmel_port->tx_done_mask); in atmel_handle_transmit()
1355 if (atmel_port->hd_start_rx) { in atmel_handle_transmit()
1358 dev_warn(port->dev, "Should start RX, but TX fifo is not empty\n"); in atmel_handle_transmit()
1360 atmel_port->hd_start_rx = false; in atmel_handle_transmit()
1364 atmel_tasklet_schedule(atmel_port, &atmel_port->tasklet_tx); in atmel_handle_transmit()
1380 status_change = status ^ atmel_port->irq_status_prev; in atmel_handle_status()
1381 atmel_port->irq_status_prev = status; in atmel_handle_status()
1387 port->icount.rng++; in atmel_handle_status()
1389 port->icount.dsr++; in atmel_handle_status()
1395 wake_up_interruptible(&port->state->port.delta_msr_wait); in atmel_handle_status()
1400 dev_dbg(port->dev, "ISO7816 ERROR (0x%08x)\n", pending); in atmel_handle_status()
1412 spin_lock(&atmel_port->lock_suspended); in atmel_interrupt()
1421 if (atmel_port->suspended) { in atmel_interrupt()
1422 atmel_port->pending |= pending; in atmel_interrupt()
1423 atmel_port->pending_status = status; in atmel_interrupt()
1434 spin_unlock(&atmel_port->lock_suspended); in atmel_interrupt()
1442 struct atmel_dma_buffer *pdc = &atmel_port->pdc_tx; in atmel_release_tx_pdc()
1444 dma_unmap_single(port->dev, in atmel_release_tx_pdc()
1445 pdc->dma_addr, in atmel_release_tx_pdc()
1446 pdc->dma_size, in atmel_release_tx_pdc()
1456 struct circ_buf *xmit = &port->state->xmit; in atmel_tx_pdc()
1457 struct atmel_dma_buffer *pdc = &atmel_port->pdc_tx; in atmel_tx_pdc()
1464 xmit->tail += pdc->ofs; in atmel_tx_pdc()
1465 xmit->tail &= UART_XMIT_SIZE - 1; in atmel_tx_pdc()
1467 port->icount.tx += pdc->ofs; in atmel_tx_pdc()
1468 pdc->ofs = 0; in atmel_tx_pdc()
1470 /* more to transmit - setup next transfer */ in atmel_tx_pdc()
1476 dma_sync_single_for_device(port->dev, in atmel_tx_pdc()
1477 pdc->dma_addr, in atmel_tx_pdc()
1478 pdc->dma_size, in atmel_tx_pdc()
1481 count = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE); in atmel_tx_pdc()
1482 pdc->ofs = count; in atmel_tx_pdc()
1485 pdc->dma_addr + xmit->tail); in atmel_tx_pdc()
1487 /* re-enable PDC transmit */ in atmel_tx_pdc()
1491 atmel_port->tx_done_mask); in atmel_tx_pdc()
1506 struct atmel_dma_buffer *pdc = &atmel_port->pdc_tx; in atmel_prepare_tx_pdc()
1507 struct circ_buf *xmit = &port->state->xmit; in atmel_prepare_tx_pdc()
1509 pdc->buf = xmit->buf; in atmel_prepare_tx_pdc()
1510 pdc->dma_addr = dma_map_single(port->dev, in atmel_prepare_tx_pdc()
1511 pdc->buf, in atmel_prepare_tx_pdc()
1514 pdc->dma_size = UART_XMIT_SIZE; in atmel_prepare_tx_pdc()
1515 pdc->ofs = 0; in atmel_prepare_tx_pdc()
1523 struct circ_buf *ring = &atmel_port->rx_ring; in atmel_rx_from_ring()
1527 while (ring->head != ring->tail) { in atmel_rx_from_ring()
1533 c = ((struct atmel_uart_char *)ring->buf)[ring->tail]; in atmel_rx_from_ring()
1535 ring->tail = (ring->tail + 1) & (ATMEL_SERIAL_RINGSIZE - 1); in atmel_rx_from_ring()
1537 port->icount.rx++; in atmel_rx_from_ring()
1548 /* ignore side-effect */ in atmel_rx_from_ring()
1551 port->icount.brk++; in atmel_rx_from_ring()
1556 port->icount.parity++; in atmel_rx_from_ring()
1558 port->icount.frame++; in atmel_rx_from_ring()
1560 port->icount.overrun++; in atmel_rx_from_ring()
1562 status &= port->read_status_mask; in atmel_rx_from_ring()
1583 spin_unlock(&port->lock); in atmel_rx_from_ring()
1584 tty_flip_buffer_push(&port->state->port); in atmel_rx_from_ring()
1585 spin_lock(&port->lock); in atmel_rx_from_ring()
1594 struct atmel_dma_buffer *pdc = &atmel_port->pdc_rx[i]; in atmel_release_rx_pdc()
1596 dma_unmap_single(port->dev, in atmel_release_rx_pdc()
1597 pdc->dma_addr, in atmel_release_rx_pdc()
1598 pdc->dma_size, in atmel_release_rx_pdc()
1600 kfree(pdc->buf); in atmel_release_rx_pdc()
1607 struct tty_port *tport = &port->state->port; in atmel_rx_from_pdc()
1609 int rx_idx = atmel_port->pdc_rx_idx; in atmel_rx_from_pdc()
1618 pdc = &atmel_port->pdc_rx[rx_idx]; in atmel_rx_from_pdc()
1619 head = atmel_uart_readl(port, ATMEL_PDC_RPR) - pdc->dma_addr; in atmel_rx_from_pdc()
1620 tail = pdc->ofs; in atmel_rx_from_pdc()
1624 * is unsigned, we just need a one-way comparison to in atmel_rx_from_pdc()
1629 * ENDRX bit as well, so that we can safely re-enable in atmel_rx_from_pdc()
1632 head = min(head, pdc->dma_size); in atmel_rx_from_pdc()
1635 dma_sync_single_for_cpu(port->dev, pdc->dma_addr, in atmel_rx_from_pdc()
1636 pdc->dma_size, DMA_FROM_DEVICE); in atmel_rx_from_pdc()
1644 count = head - tail; in atmel_rx_from_pdc()
1646 tty_insert_flip_string(tport, pdc->buf + pdc->ofs, in atmel_rx_from_pdc()
1649 dma_sync_single_for_device(port->dev, pdc->dma_addr, in atmel_rx_from_pdc()
1650 pdc->dma_size, DMA_FROM_DEVICE); in atmel_rx_from_pdc()
1652 port->icount.rx += count; in atmel_rx_from_pdc()
1653 pdc->ofs = head; in atmel_rx_from_pdc()
1660 if (head >= pdc->dma_size) { in atmel_rx_from_pdc()
1661 pdc->ofs = 0; in atmel_rx_from_pdc()
1662 atmel_uart_writel(port, ATMEL_PDC_RNPR, pdc->dma_addr); in atmel_rx_from_pdc()
1663 atmel_uart_writel(port, ATMEL_PDC_RNCR, pdc->dma_size); in atmel_rx_from_pdc()
1666 atmel_port->pdc_rx_idx = rx_idx; in atmel_rx_from_pdc()
1668 } while (head >= pdc->dma_size); in atmel_rx_from_pdc()
1674 spin_unlock(&port->lock); in atmel_rx_from_pdc()
1676 spin_lock(&port->lock); in atmel_rx_from_pdc()
1688 struct atmel_dma_buffer *pdc = &atmel_port->pdc_rx[i]; in atmel_prepare_rx_pdc()
1690 pdc->buf = kmalloc(PDC_BUFFER_SIZE, GFP_KERNEL); in atmel_prepare_rx_pdc()
1691 if (pdc->buf == NULL) { in atmel_prepare_rx_pdc()
1693 dma_unmap_single(port->dev, in atmel_prepare_rx_pdc()
1694 atmel_port->pdc_rx[0].dma_addr, in atmel_prepare_rx_pdc()
1697 kfree(atmel_port->pdc_rx[0].buf); in atmel_prepare_rx_pdc()
1699 atmel_port->use_pdc_rx = false; in atmel_prepare_rx_pdc()
1700 return -ENOMEM; in atmel_prepare_rx_pdc()
1702 pdc->dma_addr = dma_map_single(port->dev, in atmel_prepare_rx_pdc()
1703 pdc->buf, in atmel_prepare_rx_pdc()
1706 pdc->dma_size = PDC_BUFFER_SIZE; in atmel_prepare_rx_pdc()
1707 pdc->ofs = 0; in atmel_prepare_rx_pdc()
1710 atmel_port->pdc_rx_idx = 0; in atmel_prepare_rx_pdc()
1712 atmel_uart_writel(port, ATMEL_PDC_RPR, atmel_port->pdc_rx[0].dma_addr); in atmel_prepare_rx_pdc()
1716 atmel_port->pdc_rx[1].dma_addr); in atmel_prepare_rx_pdc()
1729 struct uart_port *port = &atmel_port->uart; in atmel_tasklet_rx_func()
1732 spin_lock(&port->lock); in atmel_tasklet_rx_func()
1733 atmel_port->schedule_rx(port); in atmel_tasklet_rx_func()
1734 spin_unlock(&port->lock); in atmel_tasklet_rx_func()
1741 struct uart_port *port = &atmel_port->uart; in atmel_tasklet_tx_func()
1744 spin_lock(&port->lock); in atmel_tasklet_tx_func()
1745 atmel_port->schedule_tx(port); in atmel_tasklet_tx_func()
1746 spin_unlock(&port->lock); in atmel_tasklet_tx_func()
1752 struct device_node *np = pdev->dev.of_node; in atmel_init_property()
1755 if (of_property_read_bool(np, "atmel,use-dma-rx")) { in atmel_init_property()
1757 atmel_port->use_dma_rx = true; in atmel_init_property()
1758 atmel_port->use_pdc_rx = false; in atmel_init_property()
1760 atmel_port->use_dma_rx = false; in atmel_init_property()
1761 atmel_port->use_pdc_rx = true; in atmel_init_property()
1764 atmel_port->use_dma_rx = false; in atmel_init_property()
1765 atmel_port->use_pdc_rx = false; in atmel_init_property()
1768 if (of_property_read_bool(np, "atmel,use-dma-tx")) { in atmel_init_property()
1770 atmel_port->use_dma_tx = true; in atmel_init_property()
1771 atmel_port->use_pdc_tx = false; in atmel_init_property()
1773 atmel_port->use_dma_tx = false; in atmel_init_property()
1774 atmel_port->use_pdc_tx = true; in atmel_init_property()
1777 atmel_port->use_dma_tx = false; in atmel_init_property()
1778 atmel_port->use_pdc_tx = false; in atmel_init_property()
1787 atmel_port->prepare_rx = &atmel_prepare_rx_dma; in atmel_set_ops()
1788 atmel_port->schedule_rx = &atmel_rx_from_dma; in atmel_set_ops()
1789 atmel_port->release_rx = &atmel_release_rx_dma; in atmel_set_ops()
1791 atmel_port->prepare_rx = &atmel_prepare_rx_pdc; in atmel_set_ops()
1792 atmel_port->schedule_rx = &atmel_rx_from_pdc; in atmel_set_ops()
1793 atmel_port->release_rx = &atmel_release_rx_pdc; in atmel_set_ops()
1795 atmel_port->prepare_rx = NULL; in atmel_set_ops()
1796 atmel_port->schedule_rx = &atmel_rx_from_ring; in atmel_set_ops()
1797 atmel_port->release_rx = NULL; in atmel_set_ops()
1801 atmel_port->prepare_tx = &atmel_prepare_tx_dma; in atmel_set_ops()
1802 atmel_port->schedule_tx = &atmel_tx_dma; in atmel_set_ops()
1803 atmel_port->release_tx = &atmel_release_tx_dma; in atmel_set_ops()
1805 atmel_port->prepare_tx = &atmel_prepare_tx_pdc; in atmel_set_ops()
1806 atmel_port->schedule_tx = &atmel_tx_pdc; in atmel_set_ops()
1807 atmel_port->release_tx = &atmel_release_tx_pdc; in atmel_set_ops()
1809 atmel_port->prepare_tx = NULL; in atmel_set_ops()
1810 atmel_port->schedule_tx = &atmel_tx_chars; in atmel_set_ops()
1811 atmel_port->release_tx = NULL; in atmel_set_ops()
1835 atmel_port->has_frac_baudrate = false; in atmel_get_ip_name()
1836 atmel_port->has_hw_timer = false; in atmel_get_ip_name()
1839 dev_dbg(port->dev, "Uart with hw timer"); in atmel_get_ip_name()
1840 atmel_port->has_hw_timer = true; in atmel_get_ip_name()
1841 atmel_port->rtor = ATMEL_UA_RTOR; in atmel_get_ip_name()
1843 dev_dbg(port->dev, "Usart\n"); in atmel_get_ip_name()
1844 atmel_port->has_frac_baudrate = true; in atmel_get_ip_name()
1845 atmel_port->has_hw_timer = true; in atmel_get_ip_name()
1846 atmel_port->rtor = ATMEL_US_RTOR; in atmel_get_ip_name()
1852 atmel_port->fidi_min = 3; in atmel_get_ip_name()
1853 atmel_port->fidi_max = 65535; in atmel_get_ip_name()
1856 atmel_port->fidi_min = 3; in atmel_get_ip_name()
1857 atmel_port->fidi_max = 2047; in atmel_get_ip_name()
1860 atmel_port->fidi_min = 1; in atmel_get_ip_name()
1861 atmel_port->fidi_max = 2047; in atmel_get_ip_name()
1864 dev_dbg(port->dev, "Dbgu or uart without hw timer\n"); in atmel_get_ip_name()
1872 dev_dbg(port->dev, "This version is usart\n"); in atmel_get_ip_name()
1873 atmel_port->has_frac_baudrate = true; in atmel_get_ip_name()
1874 atmel_port->has_hw_timer = true; in atmel_get_ip_name()
1875 atmel_port->rtor = ATMEL_US_RTOR; in atmel_get_ip_name()
1879 dev_dbg(port->dev, "This version is uart\n"); in atmel_get_ip_name()
1882 dev_err(port->dev, "Not supported ip name nor version, set to uart\n"); in atmel_get_ip_name()
1892 struct platform_device *pdev = to_platform_device(port->dev); in atmel_startup()
1901 atmel_uart_writel(port, ATMEL_US_IDR, -1); in atmel_startup()
1902 atmel_port->ms_irq_enabled = false; in atmel_startup()
1907 retval = request_irq(port->irq, atmel_interrupt, in atmel_startup()
1909 dev_name(&pdev->dev), port); in atmel_startup()
1911 dev_err(port->dev, "atmel_startup - Can't get irq\n"); in atmel_startup()
1915 atomic_set(&atmel_port->tasklet_shutdown, 0); in atmel_startup()
1916 tasklet_setup(&atmel_port->tasklet_rx, atmel_tasklet_rx_func); in atmel_startup()
1917 tasklet_setup(&atmel_port->tasklet_tx, atmel_tasklet_tx_func); in atmel_startup()
1925 if (atmel_port->prepare_rx) { in atmel_startup()
1926 retval = atmel_port->prepare_rx(port); in atmel_startup()
1931 if (atmel_port->prepare_tx) { in atmel_startup()
1932 retval = atmel_port->prepare_tx(port); in atmel_startup()
1940 if (atmel_port->fifo_size) { in atmel_startup()
1954 if (atmel_port->rts_high && in atmel_startup()
1955 atmel_port->rts_low) in atmel_startup()
1957 ATMEL_US_RXFTHRES(atmel_port->rts_high) | in atmel_startup()
1958 ATMEL_US_RXFTHRES2(atmel_port->rts_low); in atmel_startup()
1964 atmel_port->irq_status_prev = atmel_uart_readl(port, ATMEL_US_CSR); in atmel_startup()
1972 atmel_port->tx_stopped = false; in atmel_startup()
1974 timer_setup(&atmel_port->uart_timer, atmel_uart_timer_callback, 0); in atmel_startup()
1978 if (!atmel_port->has_hw_timer) { in atmel_startup()
1979 mod_timer(&atmel_port->uart_timer, in atmel_startup()
1983 atmel_uart_writel(port, atmel_port->rtor, in atmel_startup()
1994 if (!atmel_port->has_hw_timer) { in atmel_startup()
1995 mod_timer(&atmel_port->uart_timer, in atmel_startup()
1999 atmel_uart_writel(port, atmel_port->rtor, in atmel_startup()
2024 atmel_port->pdc_tx.ofs = 0; in atmel_flush_buffer()
2030 atmel_port->tx_len = 0; in atmel_flush_buffer()
2044 atmel_uart_writel(port, ATMEL_US_IDR, -1); in atmel_shutdown()
2047 atomic_inc(&atmel_port->tasklet_shutdown); in atmel_shutdown()
2053 del_timer_sync(&atmel_port->uart_timer); in atmel_shutdown()
2056 synchronize_irq(port->irq); in atmel_shutdown()
2062 tasklet_kill(&atmel_port->tasklet_rx); in atmel_shutdown()
2063 tasklet_kill(&atmel_port->tasklet_tx); in atmel_shutdown()
2075 * Shut-down the DMA. in atmel_shutdown()
2077 if (atmel_port->release_rx) in atmel_shutdown()
2078 atmel_port->release_rx(port); in atmel_shutdown()
2079 if (atmel_port->release_tx) in atmel_shutdown()
2080 atmel_port->release_tx(port); in atmel_shutdown()
2085 atmel_port->rx_ring.head = 0; in atmel_shutdown()
2086 atmel_port->rx_ring.tail = 0; in atmel_shutdown()
2091 free_irq(port->irq, port); in atmel_shutdown()
2110 clk_prepare_enable(atmel_port->clk); in atmel_serial_pm()
2112 /* re-enable interrupts if we disabled some on suspend */ in atmel_serial_pm()
2113 atmel_uart_writel(port, ATMEL_US_IER, atmel_port->backup_imr); in atmel_serial_pm()
2117 atmel_port->backup_imr = atmel_uart_readl(port, ATMEL_US_IMR); in atmel_serial_pm()
2118 atmel_uart_writel(port, ATMEL_US_IDR, -1); in atmel_serial_pm()
2124 clk_disable_unprepare(atmel_port->clk); in atmel_serial_pm()
2127 dev_err(port->dev, "atmel_serial: unknown pm %d\n", state); in atmel_serial_pm()
2148 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16); in atmel_set_termios()
2151 switch (termios->c_cflag & CSIZE) { in atmel_set_termios()
2167 if (termios->c_cflag & CSTOPB) in atmel_set_termios()
2171 if (termios->c_cflag & PARENB) { in atmel_set_termios()
2173 if (termios->c_cflag & CMSPAR) { in atmel_set_termios()
2174 if (termios->c_cflag & PARODD) in atmel_set_termios()
2178 } else if (termios->c_cflag & PARODD) in atmel_set_termios()
2185 spin_lock_irqsave(&port->lock, flags); in atmel_set_termios()
2187 port->read_status_mask = ATMEL_US_OVRE; in atmel_set_termios()
2188 if (termios->c_iflag & INPCK) in atmel_set_termios()
2189 port->read_status_mask |= (ATMEL_US_FRAME | ATMEL_US_PARE); in atmel_set_termios()
2190 if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK)) in atmel_set_termios()
2191 port->read_status_mask |= ATMEL_US_RXBRK; in atmel_set_termios()
2195 atmel_uart_writel(port, ATMEL_US_IER, port->read_status_mask); in atmel_set_termios()
2200 port->ignore_status_mask = 0; in atmel_set_termios()
2201 if (termios->c_iflag & IGNPAR) in atmel_set_termios()
2202 port->ignore_status_mask |= (ATMEL_US_FRAME | ATMEL_US_PARE); in atmel_set_termios()
2203 if (termios->c_iflag & IGNBRK) { in atmel_set_termios()
2204 port->ignore_status_mask |= ATMEL_US_RXBRK; in atmel_set_termios()
2209 if (termios->c_iflag & IGNPAR) in atmel_set_termios()
2210 port->ignore_status_mask |= ATMEL_US_OVRE; in atmel_set_termios()
2214 /* update the per-port timeout */ in atmel_set_termios()
2215 uart_update_timeout(port, termios->c_cflag, baud); in atmel_set_termios()
2223 atmel_uart_writel(port, ATMEL_US_IDR, -1); in atmel_set_termios()
2227 atmel_port->tx_stopped = true; in atmel_set_termios()
2230 if (port->rs485.flags & SER_RS485_ENABLED) { in atmel_set_termios()
2232 port->rs485.delay_rts_after_send); in atmel_set_termios()
2234 } else if (port->iso7816.flags & SER_ISO7816_ENABLED) { in atmel_set_termios()
2235 atmel_uart_writel(port, ATMEL_US_TTGR, port->iso7816.tg); in atmel_set_termios()
2240 if ((port->iso7816.flags & SER_ISO7816_T_PARAM) in atmel_set_termios()
2245 } else if (termios->c_cflag & CRTSCTS) { in atmel_set_termios()
2248 !mctrl_gpio_to_gpiod(atmel_port->gpios, UART_GPIO_CTS)) { in atmel_set_termios()
2257 * disabled (there must be an internal pull-up in atmel_set_termios()
2280 * baudrate = selected clock / (8 * (2 - OVER) * (CD + FP / 8)) in atmel_set_termios()
2286 if (atmel_port->has_frac_baudrate) { in atmel_set_termios()
2287 div = DIV_ROUND_CLOSEST(port->uartclk, baud * 2); in atmel_set_termios()
2294 if (cd > 65535) { /* BRGR is 16-bit, so switch to slower clock */ in atmel_set_termios()
2300 if (!(port->iso7816.flags & SER_ISO7816_ENABLED)) in atmel_set_termios()
2326 atmel_port->tx_stopped = false; in atmel_set_termios()
2331 /* CTS flow-control and modem-status interrupts */ in atmel_set_termios()
2332 if (UART_ENABLE_MS(port, termios->c_cflag)) in atmel_set_termios()
2337 spin_unlock_irqrestore(&port->lock, flags); in atmel_set_termios()
2342 if (termios->c_line == N_PPS) { in atmel_set_ldisc()
2343 port->flags |= UPF_HARDPPS_CD; in atmel_set_ldisc()
2344 spin_lock_irq(&port->lock); in atmel_set_ldisc()
2346 spin_unlock_irq(&port->lock); in atmel_set_ldisc()
2348 port->flags &= ~UPF_HARDPPS_CD; in atmel_set_ldisc()
2349 if (!UART_ENABLE_MS(port, termios->c_cflag)) { in atmel_set_ldisc()
2350 spin_lock_irq(&port->lock); in atmel_set_ldisc()
2352 spin_unlock_irq(&port->lock); in atmel_set_ldisc()
2362 return (port->type == PORT_ATMEL) ? "ATMEL_SERIAL" : NULL; in atmel_type()
2370 struct platform_device *mpdev = to_platform_device(port->dev->parent); in atmel_release_port()
2371 int size = resource_size(mpdev->resource); in atmel_release_port()
2373 release_mem_region(port->mapbase, size); in atmel_release_port()
2375 if (port->flags & UPF_IOREMAP) { in atmel_release_port()
2376 iounmap(port->membase); in atmel_release_port()
2377 port->membase = NULL; in atmel_release_port()
2386 struct platform_device *mpdev = to_platform_device(port->dev->parent); in atmel_request_port()
2387 int size = resource_size(mpdev->resource); in atmel_request_port()
2389 if (!request_mem_region(port->mapbase, size, "atmel_serial")) in atmel_request_port()
2390 return -EBUSY; in atmel_request_port()
2392 if (port->flags & UPF_IOREMAP) { in atmel_request_port()
2393 port->membase = ioremap(port->mapbase, size); in atmel_request_port()
2394 if (port->membase == NULL) { in atmel_request_port()
2395 release_mem_region(port->mapbase, size); in atmel_request_port()
2396 return -ENOMEM; in atmel_request_port()
2409 port->type = PORT_ATMEL; in atmel_config_port()
2420 if (ser->type != PORT_UNKNOWN && ser->type != PORT_ATMEL) in atmel_verify_port()
2421 ret = -EINVAL; in atmel_verify_port()
2422 if (port->irq != ser->irq) in atmel_verify_port()
2423 ret = -EINVAL; in atmel_verify_port()
2424 if (ser->io_type != SERIAL_IO_MEM) in atmel_verify_port()
2425 ret = -EINVAL; in atmel_verify_port()
2426 if (port->uartclk / 16 != ser->baud_base) in atmel_verify_port()
2427 ret = -EINVAL; in atmel_verify_port()
2428 if (port->mapbase != (unsigned long)ser->iomem_base) in atmel_verify_port()
2429 ret = -EINVAL; in atmel_verify_port()
2430 if (port->iobase != ser->port) in atmel_verify_port()
2431 ret = -EINVAL; in atmel_verify_port()
2432 if (ser->hub6 != 0) in atmel_verify_port()
2433 ret = -EINVAL; in atmel_verify_port()
2488 struct uart_port *port = &atmel_port->uart; in atmel_init_port()
2489 struct platform_device *mpdev = to_platform_device(pdev->dev.parent); in atmel_init_port()
2494 port->iotype = UPIO_MEM; in atmel_init_port()
2495 port->flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP; in atmel_init_port()
2496 port->ops = &atmel_pops; in atmel_init_port()
2497 port->fifosize = 1; in atmel_init_port()
2498 port->dev = &pdev->dev; in atmel_init_port()
2499 port->mapbase = mpdev->resource[0].start; in atmel_init_port()
2500 port->irq = mpdev->resource[1].start; in atmel_init_port()
2501 port->rs485_config = atmel_config_rs485; in atmel_init_port()
2502 port->iso7816_config = atmel_config_iso7816; in atmel_init_port()
2503 port->membase = NULL; in atmel_init_port()
2505 memset(&atmel_port->rx_ring, 0, sizeof(atmel_port->rx_ring)); in atmel_init_port()
2512 if (!atmel_port->clk) { in atmel_init_port()
2513 atmel_port->clk = clk_get(&mpdev->dev, "usart"); in atmel_init_port()
2514 if (IS_ERR(atmel_port->clk)) { in atmel_init_port()
2515 ret = PTR_ERR(atmel_port->clk); in atmel_init_port()
2516 atmel_port->clk = NULL; in atmel_init_port()
2519 ret = clk_prepare_enable(atmel_port->clk); in atmel_init_port()
2521 clk_put(atmel_port->clk); in atmel_init_port()
2522 atmel_port->clk = NULL; in atmel_init_port()
2525 port->uartclk = clk_get_rate(atmel_port->clk); in atmel_init_port()
2526 clk_disable_unprepare(atmel_port->clk); in atmel_init_port()
2535 atmel_port->tx_done_mask = ATMEL_US_TXEMPTY; in atmel_init_port()
2537 port->fifosize = PDC_BUFFER_SIZE; in atmel_init_port()
2538 atmel_port->tx_done_mask = ATMEL_US_ENDTX | ATMEL_US_TXBUFE; in atmel_init_port()
2540 atmel_port->tx_done_mask = ATMEL_US_TXRDY; in atmel_init_port()
2559 struct uart_port *port = &atmel_ports[co->index].uart; in atmel_console_write()
2569 ATMEL_US_RXRDY | atmel_port->tx_done_mask); in atmel_console_write()
2577 atmel_port->tx_stopped = false; in atmel_console_write()
2632 *baud = port->uartclk / (16 * (quot - 1)); in atmel_console_get_options()
2638 struct uart_port *port = &atmel_ports[co->index].uart; in atmel_console_setup()
2645 if (port->membase == NULL) { in atmel_console_setup()
2646 /* Port not initialized yet - delay setup */ in atmel_console_setup()
2647 return -ENODEV; in atmel_console_setup()
2650 ret = clk_prepare_enable(atmel_ports[co->index].clk); in atmel_console_setup()
2654 atmel_uart_writel(port, ATMEL_US_IDR, -1); in atmel_console_setup()
2657 atmel_port->tx_stopped = false; in atmel_console_setup()
2675 .index = -1,
2722 atmel_port->cache.mr = atmel_uart_readl(port, ATMEL_US_MR); in atmel_serial_suspend()
2723 atmel_port->cache.imr = atmel_uart_readl(port, ATMEL_US_IMR); in atmel_serial_suspend()
2724 atmel_port->cache.brgr = atmel_uart_readl(port, ATMEL_US_BRGR); in atmel_serial_suspend()
2725 atmel_port->cache.rtor = atmel_uart_readl(port, in atmel_serial_suspend()
2726 atmel_port->rtor); in atmel_serial_suspend()
2727 atmel_port->cache.ttgr = atmel_uart_readl(port, ATMEL_US_TTGR); in atmel_serial_suspend()
2728 atmel_port->cache.fmr = atmel_uart_readl(port, ATMEL_US_FMR); in atmel_serial_suspend()
2729 atmel_port->cache.fimr = atmel_uart_readl(port, ATMEL_US_FIMR); in atmel_serial_suspend()
2733 atmel_port->may_wakeup = device_may_wakeup(&pdev->dev); in atmel_serial_suspend()
2737 spin_lock_irqsave(&atmel_port->lock_suspended, flags); in atmel_serial_suspend()
2738 atmel_port->suspended = true; in atmel_serial_suspend()
2739 spin_unlock_irqrestore(&atmel_port->lock_suspended, flags); in atmel_serial_suspend()
2740 device_set_wakeup_enable(&pdev->dev, 0); in atmel_serial_suspend()
2755 atmel_uart_writel(port, ATMEL_US_MR, atmel_port->cache.mr); in atmel_serial_resume()
2756 atmel_uart_writel(port, ATMEL_US_IER, atmel_port->cache.imr); in atmel_serial_resume()
2757 atmel_uart_writel(port, ATMEL_US_BRGR, atmel_port->cache.brgr); in atmel_serial_resume()
2758 atmel_uart_writel(port, atmel_port->rtor, in atmel_serial_resume()
2759 atmel_port->cache.rtor); in atmel_serial_resume()
2760 atmel_uart_writel(port, ATMEL_US_TTGR, atmel_port->cache.ttgr); in atmel_serial_resume()
2762 if (atmel_port->fifo_size) { in atmel_serial_resume()
2766 atmel_port->cache.fmr); in atmel_serial_resume()
2768 atmel_port->cache.fimr); in atmel_serial_resume()
2773 spin_lock_irqsave(&atmel_port->lock_suspended, flags); in atmel_serial_resume()
2774 if (atmel_port->pending) { in atmel_serial_resume()
2775 atmel_handle_receive(port, atmel_port->pending); in atmel_serial_resume()
2776 atmel_handle_status(port, atmel_port->pending, in atmel_serial_resume()
2777 atmel_port->pending_status); in atmel_serial_resume()
2778 atmel_handle_transmit(port, atmel_port->pending); in atmel_serial_resume()
2779 atmel_port->pending = 0; in atmel_serial_resume()
2781 atmel_port->suspended = false; in atmel_serial_resume()
2782 spin_unlock_irqrestore(&atmel_port->lock_suspended, flags); in atmel_serial_resume()
2785 device_set_wakeup_enable(&pdev->dev, atmel_port->may_wakeup); in atmel_serial_resume()
2797 atmel_port->fifo_size = 0; in atmel_serial_probe_fifos()
2798 atmel_port->rts_low = 0; in atmel_serial_probe_fifos()
2799 atmel_port->rts_high = 0; in atmel_serial_probe_fifos()
2801 if (of_property_read_u32(pdev->dev.of_node, in atmel_serial_probe_fifos()
2802 "atmel,fifo-size", in atmel_serial_probe_fifos()
2803 &atmel_port->fifo_size)) in atmel_serial_probe_fifos()
2806 if (!atmel_port->fifo_size) in atmel_serial_probe_fifos()
2809 if (atmel_port->fifo_size < ATMEL_MIN_FIFO_SIZE) { in atmel_serial_probe_fifos()
2810 atmel_port->fifo_size = 0; in atmel_serial_probe_fifos()
2811 dev_err(&pdev->dev, "Invalid FIFO size\n"); in atmel_serial_probe_fifos()
2823 atmel_port->rts_high = max_t(int, atmel_port->fifo_size >> 1, in atmel_serial_probe_fifos()
2824 atmel_port->fifo_size - ATMEL_RTS_HIGH_OFFSET); in atmel_serial_probe_fifos()
2825 atmel_port->rts_low = max_t(int, atmel_port->fifo_size >> 2, in atmel_serial_probe_fifos()
2826 atmel_port->fifo_size - ATMEL_RTS_LOW_OFFSET); in atmel_serial_probe_fifos()
2828 dev_info(&pdev->dev, "Using FIFO (%u data)\n", in atmel_serial_probe_fifos()
2829 atmel_port->fifo_size); in atmel_serial_probe_fifos()
2830 dev_dbg(&pdev->dev, "RTS High Threshold : %2u data\n", in atmel_serial_probe_fifos()
2831 atmel_port->rts_high); in atmel_serial_probe_fifos()
2832 dev_dbg(&pdev->dev, "RTS Low Threshold : %2u data\n", in atmel_serial_probe_fifos()
2833 atmel_port->rts_low); in atmel_serial_probe_fifos()
2839 struct device_node *np = pdev->dev.parent->of_node; in atmel_serial_probe()
2844 BUILD_BUG_ON(ATMEL_SERIAL_RINGSIZE & (ATMEL_SERIAL_RINGSIZE - 1)); in atmel_serial_probe()
2847 * In device tree there is no node with "atmel,at91rm9200-usart-serial" in atmel_serial_probe()
2848 * as compatible string. This driver is probed by at91-usart mfd driver in atmel_serial_probe()
2850 * spi-at91-usart driver. All attributes needed by this driver are in atmel_serial_probe()
2853 pdev->dev.of_node = np; in atmel_serial_probe()
2857 /* port id not found in platform data nor device-tree aliases: in atmel_serial_probe()
2858 * auto-enumerate it */ in atmel_serial_probe()
2862 ret = -ENODEV; in atmel_serial_probe()
2868 ret = -EBUSY; in atmel_serial_probe()
2873 atmel_port->backup_imr = 0; in atmel_serial_probe()
2874 atmel_port->uart.line = ret; in atmel_serial_probe()
2875 atmel_port->uart.has_sysrq = IS_ENABLED(CONFIG_SERIAL_ATMEL_CONSOLE); in atmel_serial_probe()
2878 atomic_set(&atmel_port->tasklet_shutdown, 0); in atmel_serial_probe()
2879 spin_lock_init(&atmel_port->lock_suspended); in atmel_serial_probe()
2885 atmel_port->gpios = mctrl_gpio_init(&atmel_port->uart, 0); in atmel_serial_probe()
2886 if (IS_ERR(atmel_port->gpios)) { in atmel_serial_probe()
2887 ret = PTR_ERR(atmel_port->gpios); in atmel_serial_probe()
2891 if (!atmel_use_pdc_rx(&atmel_port->uart)) { in atmel_serial_probe()
2892 ret = -ENOMEM; in atmel_serial_probe()
2898 atmel_port->rx_ring.buf = data; in atmel_serial_probe()
2901 rs485_enabled = atmel_port->uart.rs485.flags & SER_RS485_ENABLED; in atmel_serial_probe()
2903 ret = uart_add_one_port(&atmel_uart, &atmel_port->uart); in atmel_serial_probe()
2908 if (uart_console(&atmel_port->uart) in atmel_serial_probe()
2909 && ATMEL_CONSOLE_DEVICE->flags & CON_ENABLED) { in atmel_serial_probe()
2914 clk_disable_unprepare(atmel_port->clk); in atmel_serial_probe()
2918 device_init_wakeup(&pdev->dev, 1); in atmel_serial_probe()
2925 clk_prepare_enable(atmel_port->clk); in atmel_serial_probe()
2928 atmel_uart_writel(&atmel_port->uart, ATMEL_US_MR, in atmel_serial_probe()
2930 atmel_uart_writel(&atmel_port->uart, ATMEL_US_CR, in atmel_serial_probe()
2937 atmel_get_ip_name(&atmel_port->uart); in atmel_serial_probe()
2943 clk_disable_unprepare(atmel_port->clk); in atmel_serial_probe()
2948 kfree(atmel_port->rx_ring.buf); in atmel_serial_probe()
2949 atmel_port->rx_ring.buf = NULL; in atmel_serial_probe()
2951 if (!uart_console(&atmel_port->uart)) { in atmel_serial_probe()
2952 clk_put(atmel_port->clk); in atmel_serial_probe()
2953 atmel_port->clk = NULL; in atmel_serial_probe()
2956 clear_bit(atmel_port->uart.line, atmel_ports_in_use); in atmel_serial_probe()
2976 tasklet_kill(&atmel_port->tasklet_rx); in atmel_serial_remove()
2977 tasklet_kill(&atmel_port->tasklet_tx); in atmel_serial_remove()
2979 device_init_wakeup(&pdev->dev, 0); in atmel_serial_remove()
2983 kfree(atmel_port->rx_ring.buf); in atmel_serial_remove()
2987 clear_bit(port->line, atmel_ports_in_use); in atmel_serial_remove()
2989 clk_put(atmel_port->clk); in atmel_serial_remove()
2990 atmel_port->clk = NULL; in atmel_serial_remove()
2991 pdev->dev.of_node = NULL; in atmel_serial_remove()