Lines Matching +full:rs485 +full:- +full:rts +full:- +full:active +full:- +full:low
1 // SPDX-License-Identifier: GPL-2.0+
18 #include <linux/clk-provider.h>
24 #include <linux/dma-mapping.h>
46 * These two offsets are substracted from the RX FIFO size to define the RTS
47 * high and low thresholds
62 /* Use device name ttyAT, major 204 and minor 154-169. This is necessary if we
71 /* Use device name ttyS, major 4, minor 64-68. This is the usual serial port
167 bool hd_start_rx; /* can start RX during half-duplex operation */
197 { .compatible = "atmel,at91rm9200-usart-serial" },
210 return __raw_readl(port->membase + reg); in atmel_uart_readl()
215 __raw_writel(value, port->membase + reg); in atmel_uart_writel()
220 return __raw_readb(port->membase + ATMEL_US_RHR); in atmel_uart_read_char()
225 __raw_writeb(value, port->membase + ATMEL_US_THR); in atmel_uart_write_char()
230 return ((port->rs485.flags & SER_RS485_ENABLED) && in atmel_uart_is_half_duplex()
231 !(port->rs485.flags & SER_RS485_RX_DURING_TX)) || in atmel_uart_is_half_duplex()
232 (port->iso7816.flags & SER_ISO7816_ENABLED); in atmel_uart_is_half_duplex()
237 return 100 - (desired_value * 100) / actual_value; in atmel_error_rate()
245 return atmel_port->use_pdc_rx; in atmel_use_pdc_rx()
252 return atmel_port->use_pdc_tx; in atmel_use_pdc_tx()
270 return atmel_port->use_dma_tx; in atmel_use_dma_tx()
277 return atmel_port->use_dma_rx; in atmel_use_dma_rx()
284 return atmel_port->fifo_size; in atmel_use_fifo()
290 if (!atomic_read(&atmel_port->tasklet_shutdown)) in atmel_tasklet_schedule()
294 /* Enable or disable the rs485 support */
302 atmel_uart_writel(port, ATMEL_US_IDR, atmel_port->tx_done_mask); in atmel_config_rs485()
306 if (rs485conf->flags & SER_RS485_ENABLED) { in atmel_config_rs485()
307 dev_dbg(port->dev, "Setting UART to RS485\n"); in atmel_config_rs485()
308 if (rs485conf->flags & SER_RS485_RX_DURING_TX) in atmel_config_rs485()
309 atmel_port->tx_done_mask = ATMEL_US_TXRDY; in atmel_config_rs485()
311 atmel_port->tx_done_mask = ATMEL_US_TXEMPTY; in atmel_config_rs485()
314 rs485conf->delay_rts_after_send); in atmel_config_rs485()
318 dev_dbg(port->dev, "Setting UART to RS232\n"); in atmel_config_rs485()
320 atmel_port->tx_done_mask = ATMEL_US_ENDTX | in atmel_config_rs485()
323 atmel_port->tx_done_mask = ATMEL_US_TXRDY; in atmel_config_rs485()
328 atmel_uart_writel(port, ATMEL_US_IER, atmel_port->tx_done_mask); in atmel_config_rs485()
340 mck_rate = (u64)clk_get_rate(atmel_port->clk); in atmel_calc_cd()
341 do_div(mck_rate, iso7816conf->clk); in atmel_calc_cd()
351 if (iso7816conf->sc_fi && iso7816conf->sc_di) { in atmel_calc_fidi()
352 fidi = (u64)iso7816conf->sc_fi; in atmel_calc_fidi()
353 do_div(fidi, iso7816conf->sc_di); in atmel_calc_fidi()
369 atmel_uart_writel(port, ATMEL_US_IDR, atmel_port->tx_done_mask); in atmel_config_iso7816()
373 if (iso7816conf->flags & SER_ISO7816_ENABLED) { in atmel_config_iso7816()
376 if (iso7816conf->tg > 255) { in atmel_config_iso7816()
377 dev_err(port->dev, "ISO7816: Timeguard exceeding 255\n"); in atmel_config_iso7816()
379 ret = -EINVAL; in atmel_config_iso7816()
383 if ((iso7816conf->flags & SER_ISO7816_T_PARAM) in atmel_config_iso7816()
386 } else if ((iso7816conf->flags & SER_ISO7816_T_PARAM) in atmel_config_iso7816()
390 dev_err(port->dev, "ISO7816: Type not supported\n"); in atmel_config_iso7816()
392 ret = -EINVAL; in atmel_config_iso7816()
406 dev_warn(port->dev, "ISO7816 fidi = 0, Generator generates no signal\n"); in atmel_config_iso7816()
407 } else if (fidi < atmel_port->fidi_min in atmel_config_iso7816()
408 || fidi > atmel_port->fidi_max) { in atmel_config_iso7816()
409 dev_err(port->dev, "ISO7816 fidi = %u, value not supported\n", fidi); in atmel_config_iso7816()
411 ret = -EINVAL; in atmel_config_iso7816()
415 if (!(port->iso7816.flags & SER_ISO7816_ENABLED)) { in atmel_config_iso7816()
417 atmel_port->backup_mode = atmel_uart_readl(port, ATMEL_US_MR); in atmel_config_iso7816()
418 atmel_port->backup_brgr = atmel_uart_readl(port, ATMEL_US_BRGR); in atmel_config_iso7816()
421 atmel_uart_writel(port, ATMEL_US_TTGR, iso7816conf->tg); in atmel_config_iso7816()
426 atmel_port->tx_done_mask = ATMEL_US_TXEMPTY | ATMEL_US_NACK | ATMEL_US_ITERATION; in atmel_config_iso7816()
428 dev_dbg(port->dev, "Setting UART back to RS232\n"); in atmel_config_iso7816()
430 mode = atmel_port->backup_mode; in atmel_config_iso7816()
433 atmel_uart_writel(port, ATMEL_US_BRGR, atmel_port->backup_brgr); in atmel_config_iso7816()
437 atmel_port->tx_done_mask = ATMEL_US_ENDTX | in atmel_config_iso7816()
440 atmel_port->tx_done_mask = ATMEL_US_TXRDY; in atmel_config_iso7816()
443 port->iso7816 = *iso7816conf; in atmel_config_iso7816()
449 atmel_uart_writel(port, ATMEL_US_IER, atmel_port->tx_done_mask); in atmel_config_iso7816()
461 if (atmel_port->tx_stopped) in atmel_tx_empty()
478 /* override mode to RS485 if needed, otherwise keep the current mode */ in atmel_set_mctrl()
479 if (port->rs485.flags & SER_RS485_ENABLED) { in atmel_set_mctrl()
481 port->rs485.delay_rts_after_send); in atmel_set_mctrl()
486 /* set the RTS line state according to the mode */ in atmel_set_mctrl()
488 /* force RTS line to high level */ in atmel_set_mctrl()
491 /* give the control of the RTS line back to the hardware */ in atmel_set_mctrl()
494 /* force RTS line to high level */ in atmel_set_mctrl()
497 /* force RTS line to low level */ in atmel_set_mctrl()
513 mctrl_gpio_set(atmel_port->gpios, mctrl); in atmel_set_mctrl()
536 * The control signals are active low. in atmel_get_mctrl()
547 return mctrl_gpio_get(atmel_port->gpios, &ret); in atmel_get_mctrl()
571 atmel_port->tx_stopped = true; in atmel_stop_tx()
575 atmel_uart_writel(port, ATMEL_US_IDR, atmel_port->tx_done_mask); in atmel_stop_tx()
578 if (!atomic_read(&atmel_port->tasklet_shutdown)) in atmel_stop_tx()
601 /* re-enable PDC transmit */ in atmel_start_tx()
606 atmel_uart_writel(port, ATMEL_US_IER, atmel_port->tx_done_mask); in atmel_start_tx()
609 /* re-enable the transmitter */ in atmel_start_tx()
611 atmel_port->tx_stopped = false; in atmel_start_tx()
616 * start receiving - port is in process of being opened.
629 port->read_status_mask); in atmel_start_rx()
637 * Stop receiving - port is in process of being closed.
648 port->read_status_mask); in atmel_stop_rx()
665 if (atmel_port->ms_irq_enabled) in atmel_enable_ms()
668 atmel_port->ms_irq_enabled = true; in atmel_enable_ms()
670 if (!mctrl_gpio_to_gpiod(atmel_port->gpios, UART_GPIO_CTS)) in atmel_enable_ms()
673 if (!mctrl_gpio_to_gpiod(atmel_port->gpios, UART_GPIO_DSR)) in atmel_enable_ms()
676 if (!mctrl_gpio_to_gpiod(atmel_port->gpios, UART_GPIO_RI)) in atmel_enable_ms()
679 if (!mctrl_gpio_to_gpiod(atmel_port->gpios, UART_GPIO_DCD)) in atmel_enable_ms()
684 mctrl_gpio_enable_ms(atmel_port->gpios); in atmel_enable_ms()
698 if (!atmel_port->ms_irq_enabled) in atmel_disable_ms()
701 atmel_port->ms_irq_enabled = false; in atmel_disable_ms()
703 mctrl_gpio_disable_ms(atmel_port->gpios); in atmel_disable_ms()
705 if (!mctrl_gpio_to_gpiod(atmel_port->gpios, UART_GPIO_CTS)) in atmel_disable_ms()
708 if (!mctrl_gpio_to_gpiod(atmel_port->gpios, UART_GPIO_DSR)) in atmel_disable_ms()
711 if (!mctrl_gpio_to_gpiod(atmel_port->gpios, UART_GPIO_RI)) in atmel_disable_ms()
714 if (!mctrl_gpio_to_gpiod(atmel_port->gpios, UART_GPIO_DCD)) in atmel_disable_ms()
741 struct circ_buf *ring = &atmel_port->rx_ring; in atmel_buffer_rx_char()
744 if (!CIRC_SPACE(ring->head, ring->tail, ATMEL_SERIAL_RINGSIZE)) in atmel_buffer_rx_char()
748 c = &((struct atmel_uart_char *)ring->buf)[ring->head]; in atmel_buffer_rx_char()
749 c->status = status; in atmel_buffer_rx_char()
750 c->ch = ch; in atmel_buffer_rx_char()
755 ring->head = (ring->head + 1) & (ATMEL_SERIAL_RINGSIZE - 1); in atmel_buffer_rx_char()
767 /* ignore side-effect */ in atmel_pdc_rxerr()
769 port->icount.brk++; in atmel_pdc_rxerr()
772 port->icount.parity++; in atmel_pdc_rxerr()
774 port->icount.frame++; in atmel_pdc_rxerr()
776 port->icount.overrun++; in atmel_pdc_rxerr()
797 || atmel_port->break_active)) { in atmel_rx_chars()
803 && !atmel_port->break_active) { in atmel_rx_chars()
804 atmel_port->break_active = 1; in atmel_rx_chars()
809 * This is either the end-of-break in atmel_rx_chars()
813 * RXBRK will indicate start-of-break. in atmel_rx_chars()
818 atmel_port->break_active = 0; in atmel_rx_chars()
826 atmel_tasklet_schedule(atmel_port, &atmel_port->tasklet_rx); in atmel_rx_chars()
847 atmel_port->tx_done_mask |= ATMEL_US_TXRDY; in atmel_tx_chars()
851 atmel_port->tx_done_mask); in atmel_tx_chars()
854 atmel_port->tx_done_mask &= ~ATMEL_US_TXRDY; in atmel_tx_chars()
861 struct uart_port *port = &atmel_port->uart; in atmel_complete_tx_dma()
862 struct tty_port *tport = &port->state->port; in atmel_complete_tx_dma()
863 struct dma_chan *chan = atmel_port->chan_tx; in atmel_complete_tx_dma()
870 uart_xmit_advance(port, atmel_port->tx_len); in atmel_complete_tx_dma()
872 spin_lock(&atmel_port->lock_tx); in atmel_complete_tx_dma()
873 async_tx_ack(atmel_port->desc_tx); in atmel_complete_tx_dma()
874 atmel_port->cookie_tx = -EINVAL; in atmel_complete_tx_dma()
875 atmel_port->desc_tx = NULL; in atmel_complete_tx_dma()
876 spin_unlock(&atmel_port->lock_tx); in atmel_complete_tx_dma()
878 if (kfifo_len(&tport->xmit_fifo) < WAKEUP_CHARS) in atmel_complete_tx_dma()
886 if (!kfifo_is_empty(&tport->xmit_fifo)) in atmel_complete_tx_dma()
887 atmel_tasklet_schedule(atmel_port, &atmel_port->tasklet_tx); in atmel_complete_tx_dma()
890 * DMA done, re-enable TXEMPTY and signal that we can stop in atmel_complete_tx_dma()
891 * TX and start RX for RS485 in atmel_complete_tx_dma()
893 atmel_port->hd_start_rx = true; in atmel_complete_tx_dma()
895 atmel_port->tx_done_mask); in atmel_complete_tx_dma()
904 struct dma_chan *chan = atmel_port->chan_tx; in atmel_release_tx_dma()
909 dma_unmap_single(port->dev, atmel_port->tx_phys, in atmel_release_tx_dma()
913 atmel_port->desc_tx = NULL; in atmel_release_tx_dma()
914 atmel_port->chan_tx = NULL; in atmel_release_tx_dma()
915 atmel_port->cookie_tx = -EINVAL; in atmel_release_tx_dma()
924 struct tty_port *tport = &port->state->port; in atmel_tx_dma()
925 struct dma_chan *chan = atmel_port->chan_tx; in atmel_tx_dma()
932 if (atmel_port->desc_tx != NULL) in atmel_tx_dma()
935 if (!kfifo_is_empty(&tport->xmit_fifo) && !uart_tx_stopped(port)) { in atmel_tx_dma()
945 tx_len = kfifo_out_linear(&tport->xmit_fifo, &tail, in atmel_tx_dma()
948 if (atmel_port->fifo_size) { in atmel_tx_dma()
960 phys_addr = atmel_port->tx_phys + tail; in atmel_tx_dma()
979 atmel_port->tx_len = tx_len; in atmel_tx_dma()
988 dev_err(port->dev, "Failed to send via dma!\n"); in atmel_tx_dma()
992 dma_sync_single_for_device(port->dev, atmel_port->tx_phys, in atmel_tx_dma()
995 atmel_port->desc_tx = desc; in atmel_tx_dma()
996 desc->callback = atmel_complete_tx_dma; in atmel_tx_dma()
997 desc->callback_param = atmel_port; in atmel_tx_dma()
998 atmel_port->cookie_tx = dmaengine_submit(desc); in atmel_tx_dma()
999 if (dma_submit_error(atmel_port->cookie_tx)) { in atmel_tx_dma()
1000 dev_err(port->dev, "dma_submit_error %d\n", in atmel_tx_dma()
1001 atmel_port->cookie_tx); in atmel_tx_dma()
1008 if (kfifo_len(&tport->xmit_fifo) < WAKEUP_CHARS) in atmel_tx_dma()
1015 struct tty_port *tport = &port->state->port; in atmel_prepare_tx_dma()
1016 struct device *mfd_dev = port->dev->parent; in atmel_prepare_tx_dma()
1027 atmel_port->chan_tx = NULL; in atmel_prepare_tx_dma()
1030 atmel_port->chan_tx = chan; in atmel_prepare_tx_dma()
1031 dev_info(port->dev, "using %s for tx DMA transfers\n", in atmel_prepare_tx_dma()
1032 dma_chan_name(atmel_port->chan_tx)); in atmel_prepare_tx_dma()
1034 spin_lock_init(&atmel_port->lock_tx); in atmel_prepare_tx_dma()
1036 BUG_ON(!PAGE_ALIGNED(tport->xmit_buf)); in atmel_prepare_tx_dma()
1037 atmel_port->tx_phys = dma_map_single(port->dev, tport->xmit_buf, in atmel_prepare_tx_dma()
1040 if (dma_mapping_error(port->dev, atmel_port->tx_phys)) { in atmel_prepare_tx_dma()
1041 dev_dbg(port->dev, "need to release resource of dma\n"); in atmel_prepare_tx_dma()
1044 dev_dbg(port->dev, "%s: mapped %lu@%p to %pad\n", __func__, in atmel_prepare_tx_dma()
1045 UART_XMIT_SIZE, tport->xmit_buf, in atmel_prepare_tx_dma()
1046 &atmel_port->tx_phys); in atmel_prepare_tx_dma()
1052 config.dst_addr_width = (atmel_port->fifo_size) ? in atmel_prepare_tx_dma()
1055 config.dst_addr = port->mapbase + ATMEL_US_THR; in atmel_prepare_tx_dma()
1058 ret = dmaengine_slave_config(atmel_port->chan_tx, in atmel_prepare_tx_dma()
1061 dev_err(port->dev, "DMA tx slave configuration failed\n"); in atmel_prepare_tx_dma()
1068 dev_err(port->dev, "TX channel not available, switch to pio\n"); in atmel_prepare_tx_dma()
1069 atmel_port->use_dma_tx = false; in atmel_prepare_tx_dma()
1070 if (atmel_port->chan_tx) in atmel_prepare_tx_dma()
1072 return -EINVAL; in atmel_prepare_tx_dma()
1080 atmel_tasklet_schedule(atmel_port, &atmel_port->tasklet_rx); in atmel_complete_rx_dma()
1086 struct dma_chan *chan = atmel_port->chan_rx; in atmel_release_rx_dma()
1091 dma_unmap_single(port->dev, atmel_port->rx_phys, in atmel_release_rx_dma()
1095 atmel_port->desc_rx = NULL; in atmel_release_rx_dma()
1096 atmel_port->chan_rx = NULL; in atmel_release_rx_dma()
1097 atmel_port->cookie_rx = -EINVAL; in atmel_release_rx_dma()
1103 struct tty_port *tport = &port->state->port; in atmel_rx_from_dma()
1104 struct circ_buf *ring = &atmel_port->rx_ring; in atmel_rx_from_dma()
1105 struct dma_chan *chan = atmel_port->chan_rx; in atmel_rx_from_dma()
1114 atmel_port->cookie_rx, in atmel_rx_from_dma()
1118 dev_dbg(port->dev, "Get residue error, restart tasklet\n"); in atmel_rx_from_dma()
1120 atmel_tasklet_schedule(atmel_port, &atmel_port->tasklet_rx); in atmel_rx_from_dma()
1125 dma_sync_single_for_cpu(port->dev, atmel_port->rx_phys, in atmel_rx_from_dma()
1129 * ring->head points to the end of data already written by the DMA. in atmel_rx_from_dma()
1130 * ring->tail points to the beginning of data to be read by the in atmel_rx_from_dma()
1135 ring->head = ATMEL_SERIAL_RX_SIZE - state.residue; in atmel_rx_from_dma()
1136 BUG_ON(ring->head > ATMEL_SERIAL_RX_SIZE); in atmel_rx_from_dma()
1138 * At this point ring->head may point to the first byte right after the in atmel_rx_from_dma()
1140 * 0 <= ring->head <= sg_dma_len(&atmel_port->sg_rx) in atmel_rx_from_dma()
1142 * However ring->tail must always points inside the dma buffer: in atmel_rx_from_dma()
1143 * 0 <= ring->tail <= sg_dma_len(&atmel_port->sg_rx) - 1 in atmel_rx_from_dma()
1149 if (ring->head < ring->tail) { in atmel_rx_from_dma()
1150 count = ATMEL_SERIAL_RX_SIZE - ring->tail; in atmel_rx_from_dma()
1152 tty_insert_flip_string(tport, ring->buf + ring->tail, count); in atmel_rx_from_dma()
1153 ring->tail = 0; in atmel_rx_from_dma()
1154 port->icount.rx += count; in atmel_rx_from_dma()
1158 if (ring->tail < ring->head) { in atmel_rx_from_dma()
1159 count = ring->head - ring->tail; in atmel_rx_from_dma()
1161 tty_insert_flip_string(tport, ring->buf + ring->tail, count); in atmel_rx_from_dma()
1162 /* Wrap ring->head if needed */ in atmel_rx_from_dma()
1163 if (ring->head >= ATMEL_SERIAL_RX_SIZE) in atmel_rx_from_dma()
1164 ring->head = 0; in atmel_rx_from_dma()
1165 ring->tail = ring->head; in atmel_rx_from_dma()
1166 port->icount.rx += count; in atmel_rx_from_dma()
1170 dma_sync_single_for_device(port->dev, atmel_port->rx_phys, in atmel_rx_from_dma()
1181 struct device *mfd_dev = port->dev->parent; in atmel_prepare_rx_dma()
1189 ring = &atmel_port->rx_ring; in atmel_prepare_rx_dma()
1196 atmel_port->chan_rx = NULL; in atmel_prepare_rx_dma()
1199 atmel_port->chan_rx = chan; in atmel_prepare_rx_dma()
1200 dev_info(port->dev, "using %s for rx DMA transfers\n", in atmel_prepare_rx_dma()
1201 dma_chan_name(atmel_port->chan_rx)); in atmel_prepare_rx_dma()
1203 spin_lock_init(&atmel_port->lock_rx); in atmel_prepare_rx_dma()
1205 BUG_ON(!PAGE_ALIGNED(ring->buf)); in atmel_prepare_rx_dma()
1206 atmel_port->rx_phys = dma_map_single(port->dev, ring->buf, in atmel_prepare_rx_dma()
1210 if (dma_mapping_error(port->dev, atmel_port->rx_phys)) { in atmel_prepare_rx_dma()
1211 dev_dbg(port->dev, "need to release resource of dma\n"); in atmel_prepare_rx_dma()
1214 dev_dbg(port->dev, "%s: mapped %zu@%p to %pad\n", __func__, in atmel_prepare_rx_dma()
1215 ATMEL_SERIAL_RX_SIZE, ring->buf, &atmel_port->rx_phys); in atmel_prepare_rx_dma()
1222 config.src_addr = port->mapbase + ATMEL_US_RHR; in atmel_prepare_rx_dma()
1225 ret = dmaengine_slave_config(atmel_port->chan_rx, in atmel_prepare_rx_dma()
1228 dev_err(port->dev, "DMA rx slave configuration failed\n"); in atmel_prepare_rx_dma()
1235 desc = dmaengine_prep_dma_cyclic(atmel_port->chan_rx, in atmel_prepare_rx_dma()
1236 atmel_port->rx_phys, in atmel_prepare_rx_dma()
1242 dev_err(port->dev, "Preparing DMA cyclic failed\n"); in atmel_prepare_rx_dma()
1245 desc->callback = atmel_complete_rx_dma; in atmel_prepare_rx_dma()
1246 desc->callback_param = port; in atmel_prepare_rx_dma()
1247 atmel_port->desc_rx = desc; in atmel_prepare_rx_dma()
1248 atmel_port->cookie_rx = dmaengine_submit(desc); in atmel_prepare_rx_dma()
1249 if (dma_submit_error(atmel_port->cookie_rx)) { in atmel_prepare_rx_dma()
1250 dev_err(port->dev, "dma_submit_error %d\n", in atmel_prepare_rx_dma()
1251 atmel_port->cookie_rx); in atmel_prepare_rx_dma()
1255 dma_async_issue_pending(atmel_port->chan_rx); in atmel_prepare_rx_dma()
1260 dev_err(port->dev, "RX channel not available, switch to pio\n"); in atmel_prepare_rx_dma()
1261 atmel_port->use_dma_rx = false; in atmel_prepare_rx_dma()
1262 if (atmel_port->chan_rx) in atmel_prepare_rx_dma()
1264 return -EINVAL; in atmel_prepare_rx_dma()
1271 struct uart_port *port = &atmel_port->uart; in atmel_uart_timer_callback()
1273 if (!atomic_read(&atmel_port->tasklet_shutdown)) { in atmel_uart_timer_callback()
1274 tasklet_schedule(&atmel_port->tasklet_rx); in atmel_uart_timer_callback()
1275 mod_timer(&atmel_port->uart_timer, in atmel_uart_timer_callback()
1300 &atmel_port->tasklet_rx); in atmel_handle_receive()
1313 &atmel_port->tasklet_rx); in atmel_handle_receive()
1327 atmel_port->break_active = 0; in atmel_handle_receive()
1339 if (pending & atmel_port->tx_done_mask) { in atmel_handle_transmit()
1341 atmel_port->tx_done_mask); in atmel_handle_transmit()
1344 if (atmel_port->hd_start_rx) { in atmel_handle_transmit()
1347 dev_warn(port->dev, "Should start RX, but TX fifo is not empty\n"); in atmel_handle_transmit()
1349 atmel_port->hd_start_rx = false; in atmel_handle_transmit()
1353 atmel_tasklet_schedule(atmel_port, &atmel_port->tasklet_tx); in atmel_handle_transmit()
1369 status_change = status ^ atmel_port->irq_status_prev; in atmel_handle_status()
1370 atmel_port->irq_status_prev = status; in atmel_handle_status()
1376 port->icount.rng++; in atmel_handle_status()
1378 port->icount.dsr++; in atmel_handle_status()
1384 wake_up_interruptible(&port->state->port.delta_msr_wait); in atmel_handle_status()
1389 dev_dbg(port->dev, "ISO7816 ERROR (0x%08x)\n", pending); in atmel_handle_status()
1401 spin_lock(&atmel_port->lock_suspended); in atmel_interrupt()
1410 if (atmel_port->suspended) { in atmel_interrupt()
1411 atmel_port->pending |= pending; in atmel_interrupt()
1412 atmel_port->pending_status = status; in atmel_interrupt()
1423 spin_unlock(&atmel_port->lock_suspended); in atmel_interrupt()
1431 struct atmel_dma_buffer *pdc = &atmel_port->pdc_tx; in atmel_release_tx_pdc()
1433 dma_unmap_single(port->dev, in atmel_release_tx_pdc()
1434 pdc->dma_addr, in atmel_release_tx_pdc()
1435 pdc->dma_size, in atmel_release_tx_pdc()
1445 struct tty_port *tport = &port->state->port; in atmel_tx_pdc()
1446 struct atmel_dma_buffer *pdc = &atmel_port->pdc_tx; in atmel_tx_pdc()
1451 uart_xmit_advance(port, pdc->ofs); in atmel_tx_pdc()
1452 pdc->ofs = 0; in atmel_tx_pdc()
1454 /* more to transmit - setup next transfer */ in atmel_tx_pdc()
1459 if (!kfifo_is_empty(&tport->xmit_fifo) && !uart_tx_stopped(port)) { in atmel_tx_pdc()
1462 dma_sync_single_for_device(port->dev, in atmel_tx_pdc()
1463 pdc->dma_addr, in atmel_tx_pdc()
1464 pdc->dma_size, in atmel_tx_pdc()
1467 count = kfifo_out_linear(&tport->xmit_fifo, &tail, in atmel_tx_pdc()
1469 pdc->ofs = count; in atmel_tx_pdc()
1471 atmel_uart_writel(port, ATMEL_PDC_TPR, pdc->dma_addr + tail); in atmel_tx_pdc()
1473 /* re-enable PDC transmit */ in atmel_tx_pdc()
1477 atmel_port->tx_done_mask); in atmel_tx_pdc()
1480 /* DMA done, stop TX, start RX for RS485 */ in atmel_tx_pdc()
1485 if (kfifo_len(&tport->xmit_fifo) < WAKEUP_CHARS) in atmel_tx_pdc()
1492 struct atmel_dma_buffer *pdc = &atmel_port->pdc_tx; in atmel_prepare_tx_pdc()
1493 struct tty_port *tport = &port->state->port; in atmel_prepare_tx_pdc()
1495 pdc->buf = tport->xmit_buf; in atmel_prepare_tx_pdc()
1496 pdc->dma_addr = dma_map_single(port->dev, in atmel_prepare_tx_pdc()
1497 pdc->buf, in atmel_prepare_tx_pdc()
1500 pdc->dma_size = UART_XMIT_SIZE; in atmel_prepare_tx_pdc()
1501 pdc->ofs = 0; in atmel_prepare_tx_pdc()
1509 struct circ_buf *ring = &atmel_port->rx_ring; in atmel_rx_from_ring()
1513 while (ring->head != ring->tail) { in atmel_rx_from_ring()
1519 c = ((struct atmel_uart_char *)ring->buf)[ring->tail]; in atmel_rx_from_ring()
1521 ring->tail = (ring->tail + 1) & (ATMEL_SERIAL_RINGSIZE - 1); in atmel_rx_from_ring()
1523 port->icount.rx++; in atmel_rx_from_ring()
1534 /* ignore side-effect */ in atmel_rx_from_ring()
1537 port->icount.brk++; in atmel_rx_from_ring()
1542 port->icount.parity++; in atmel_rx_from_ring()
1544 port->icount.frame++; in atmel_rx_from_ring()
1546 port->icount.overrun++; in atmel_rx_from_ring()
1548 status &= port->read_status_mask; in atmel_rx_from_ring()
1565 tty_flip_buffer_push(&port->state->port); in atmel_rx_from_ring()
1574 struct atmel_dma_buffer *pdc = &atmel_port->pdc_rx[i]; in atmel_release_rx_pdc()
1576 dma_unmap_single(port->dev, in atmel_release_rx_pdc()
1577 pdc->dma_addr, in atmel_release_rx_pdc()
1578 pdc->dma_size, in atmel_release_rx_pdc()
1580 kfree(pdc->buf); in atmel_release_rx_pdc()
1587 struct tty_port *tport = &port->state->port; in atmel_rx_from_pdc()
1589 int rx_idx = atmel_port->pdc_rx_idx; in atmel_rx_from_pdc()
1598 pdc = &atmel_port->pdc_rx[rx_idx]; in atmel_rx_from_pdc()
1599 head = atmel_uart_readl(port, ATMEL_PDC_RPR) - pdc->dma_addr; in atmel_rx_from_pdc()
1600 tail = pdc->ofs; in atmel_rx_from_pdc()
1604 * is unsigned, we just need a one-way comparison to in atmel_rx_from_pdc()
1609 * ENDRX bit as well, so that we can safely re-enable in atmel_rx_from_pdc()
1612 head = min(head, pdc->dma_size); in atmel_rx_from_pdc()
1615 dma_sync_single_for_cpu(port->dev, pdc->dma_addr, in atmel_rx_from_pdc()
1616 pdc->dma_size, DMA_FROM_DEVICE); in atmel_rx_from_pdc()
1624 count = head - tail; in atmel_rx_from_pdc()
1626 tty_insert_flip_string(tport, pdc->buf + pdc->ofs, in atmel_rx_from_pdc()
1629 dma_sync_single_for_device(port->dev, pdc->dma_addr, in atmel_rx_from_pdc()
1630 pdc->dma_size, DMA_FROM_DEVICE); in atmel_rx_from_pdc()
1632 port->icount.rx += count; in atmel_rx_from_pdc()
1633 pdc->ofs = head; in atmel_rx_from_pdc()
1640 if (head >= pdc->dma_size) { in atmel_rx_from_pdc()
1641 pdc->ofs = 0; in atmel_rx_from_pdc()
1642 atmel_uart_writel(port, ATMEL_PDC_RNPR, pdc->dma_addr); in atmel_rx_from_pdc()
1643 atmel_uart_writel(port, ATMEL_PDC_RNCR, pdc->dma_size); in atmel_rx_from_pdc()
1646 atmel_port->pdc_rx_idx = rx_idx; in atmel_rx_from_pdc()
1648 } while (head >= pdc->dma_size); in atmel_rx_from_pdc()
1662 struct atmel_dma_buffer *pdc = &atmel_port->pdc_rx[i]; in atmel_prepare_rx_pdc()
1664 pdc->buf = kmalloc(PDC_BUFFER_SIZE, GFP_KERNEL); in atmel_prepare_rx_pdc()
1665 if (pdc->buf == NULL) { in atmel_prepare_rx_pdc()
1667 dma_unmap_single(port->dev, in atmel_prepare_rx_pdc()
1668 atmel_port->pdc_rx[0].dma_addr, in atmel_prepare_rx_pdc()
1671 kfree(atmel_port->pdc_rx[0].buf); in atmel_prepare_rx_pdc()
1673 atmel_port->use_pdc_rx = false; in atmel_prepare_rx_pdc()
1674 return -ENOMEM; in atmel_prepare_rx_pdc()
1676 pdc->dma_addr = dma_map_single(port->dev, in atmel_prepare_rx_pdc()
1677 pdc->buf, in atmel_prepare_rx_pdc()
1680 pdc->dma_size = PDC_BUFFER_SIZE; in atmel_prepare_rx_pdc()
1681 pdc->ofs = 0; in atmel_prepare_rx_pdc()
1684 atmel_port->pdc_rx_idx = 0; in atmel_prepare_rx_pdc()
1686 atmel_uart_writel(port, ATMEL_PDC_RPR, atmel_port->pdc_rx[0].dma_addr); in atmel_prepare_rx_pdc()
1690 atmel_port->pdc_rx[1].dma_addr); in atmel_prepare_rx_pdc()
1703 struct uart_port *port = &atmel_port->uart; in atmel_tasklet_rx_func()
1707 atmel_port->schedule_rx(port); in atmel_tasklet_rx_func()
1715 struct uart_port *port = &atmel_port->uart; in atmel_tasklet_tx_func()
1719 atmel_port->schedule_tx(port); in atmel_tasklet_tx_func()
1726 struct device_node *np = pdev->dev.of_node; in atmel_init_property()
1729 if (of_property_read_bool(np, "atmel,use-dma-rx")) { in atmel_init_property()
1731 atmel_port->use_dma_rx = true; in atmel_init_property()
1732 atmel_port->use_pdc_rx = false; in atmel_init_property()
1734 atmel_port->use_dma_rx = false; in atmel_init_property()
1735 atmel_port->use_pdc_rx = true; in atmel_init_property()
1738 atmel_port->use_dma_rx = false; in atmel_init_property()
1739 atmel_port->use_pdc_rx = false; in atmel_init_property()
1742 if (of_property_read_bool(np, "atmel,use-dma-tx")) { in atmel_init_property()
1744 atmel_port->use_dma_tx = true; in atmel_init_property()
1745 atmel_port->use_pdc_tx = false; in atmel_init_property()
1747 atmel_port->use_dma_tx = false; in atmel_init_property()
1748 atmel_port->use_pdc_tx = true; in atmel_init_property()
1751 atmel_port->use_dma_tx = false; in atmel_init_property()
1752 atmel_port->use_pdc_tx = false; in atmel_init_property()
1761 atmel_port->prepare_rx = &atmel_prepare_rx_dma; in atmel_set_ops()
1762 atmel_port->schedule_rx = &atmel_rx_from_dma; in atmel_set_ops()
1763 atmel_port->release_rx = &atmel_release_rx_dma; in atmel_set_ops()
1765 atmel_port->prepare_rx = &atmel_prepare_rx_pdc; in atmel_set_ops()
1766 atmel_port->schedule_rx = &atmel_rx_from_pdc; in atmel_set_ops()
1767 atmel_port->release_rx = &atmel_release_rx_pdc; in atmel_set_ops()
1769 atmel_port->prepare_rx = NULL; in atmel_set_ops()
1770 atmel_port->schedule_rx = &atmel_rx_from_ring; in atmel_set_ops()
1771 atmel_port->release_rx = NULL; in atmel_set_ops()
1775 atmel_port->prepare_tx = &atmel_prepare_tx_dma; in atmel_set_ops()
1776 atmel_port->schedule_tx = &atmel_tx_dma; in atmel_set_ops()
1777 atmel_port->release_tx = &atmel_release_tx_dma; in atmel_set_ops()
1779 atmel_port->prepare_tx = &atmel_prepare_tx_pdc; in atmel_set_ops()
1780 atmel_port->schedule_tx = &atmel_tx_pdc; in atmel_set_ops()
1781 atmel_port->release_tx = &atmel_release_tx_pdc; in atmel_set_ops()
1783 atmel_port->prepare_tx = NULL; in atmel_set_ops()
1784 atmel_port->schedule_tx = &atmel_tx_chars; in atmel_set_ops()
1785 atmel_port->release_tx = NULL; in atmel_set_ops()
1809 atmel_port->has_frac_baudrate = false; in atmel_get_ip_name()
1810 atmel_port->has_hw_timer = false; in atmel_get_ip_name()
1811 atmel_port->is_usart = false; in atmel_get_ip_name()
1814 dev_dbg(port->dev, "Uart with hw timer"); in atmel_get_ip_name()
1815 atmel_port->has_hw_timer = true; in atmel_get_ip_name()
1816 atmel_port->rtor = ATMEL_UA_RTOR; in atmel_get_ip_name()
1818 dev_dbg(port->dev, "Usart\n"); in atmel_get_ip_name()
1819 atmel_port->has_frac_baudrate = true; in atmel_get_ip_name()
1820 atmel_port->has_hw_timer = true; in atmel_get_ip_name()
1821 atmel_port->is_usart = true; in atmel_get_ip_name()
1822 atmel_port->rtor = ATMEL_US_RTOR; in atmel_get_ip_name()
1828 atmel_port->fidi_min = 3; in atmel_get_ip_name()
1829 atmel_port->fidi_max = 65535; in atmel_get_ip_name()
1832 atmel_port->fidi_min = 3; in atmel_get_ip_name()
1833 atmel_port->fidi_max = 2047; in atmel_get_ip_name()
1836 atmel_port->fidi_min = 1; in atmel_get_ip_name()
1837 atmel_port->fidi_max = 2047; in atmel_get_ip_name()
1840 dev_dbg(port->dev, "Dbgu or uart without hw timer\n"); in atmel_get_ip_name()
1848 dev_dbg(port->dev, "This version is usart\n"); in atmel_get_ip_name()
1849 atmel_port->has_frac_baudrate = true; in atmel_get_ip_name()
1850 atmel_port->has_hw_timer = true; in atmel_get_ip_name()
1851 atmel_port->is_usart = true; in atmel_get_ip_name()
1852 atmel_port->rtor = ATMEL_US_RTOR; in atmel_get_ip_name()
1856 dev_dbg(port->dev, "This version is uart\n"); in atmel_get_ip_name()
1859 dev_err(port->dev, "Not supported ip name nor version, set to uart\n"); in atmel_get_ip_name()
1869 struct platform_device *pdev = to_platform_device(port->dev); in atmel_startup()
1878 atmel_uart_writel(port, ATMEL_US_IDR, -1); in atmel_startup()
1879 atmel_port->ms_irq_enabled = false; in atmel_startup()
1884 retval = request_irq(port->irq, atmel_interrupt, in atmel_startup()
1886 dev_name(&pdev->dev), port); in atmel_startup()
1888 dev_err(port->dev, "atmel_startup - Can't get irq\n"); in atmel_startup()
1892 atomic_set(&atmel_port->tasklet_shutdown, 0); in atmel_startup()
1893 tasklet_setup(&atmel_port->tasklet_rx, atmel_tasklet_rx_func); in atmel_startup()
1894 tasklet_setup(&atmel_port->tasklet_tx, atmel_tasklet_tx_func); in atmel_startup()
1902 if (atmel_port->prepare_rx) { in atmel_startup()
1903 retval = atmel_port->prepare_rx(port); in atmel_startup()
1908 if (atmel_port->prepare_tx) { in atmel_startup()
1909 retval = atmel_port->prepare_tx(port); in atmel_startup()
1917 if (atmel_port->fifo_size) { in atmel_startup()
1931 if (atmel_port->rts_high && in atmel_startup()
1932 atmel_port->rts_low) in atmel_startup()
1934 ATMEL_US_RXFTHRES(atmel_port->rts_high) | in atmel_startup()
1935 ATMEL_US_RXFTHRES2(atmel_port->rts_low); in atmel_startup()
1941 atmel_port->irq_status_prev = atmel_uart_readl(port, ATMEL_US_CSR); in atmel_startup()
1949 atmel_port->tx_stopped = false; in atmel_startup()
1951 timer_setup(&atmel_port->uart_timer, atmel_uart_timer_callback, 0); in atmel_startup()
1955 if (!atmel_port->has_hw_timer) { in atmel_startup()
1956 mod_timer(&atmel_port->uart_timer, in atmel_startup()
1960 atmel_uart_writel(port, atmel_port->rtor, in atmel_startup()
1971 if (!atmel_port->has_hw_timer) { in atmel_startup()
1972 mod_timer(&atmel_port->uart_timer, in atmel_startup()
1976 atmel_uart_writel(port, atmel_port->rtor, in atmel_startup()
2001 atmel_port->pdc_tx.ofs = 0; in atmel_flush_buffer()
2007 atmel_port->tx_len = 0; in atmel_flush_buffer()
2021 atmel_uart_writel(port, ATMEL_US_IDR, -1); in atmel_shutdown()
2024 atomic_inc(&atmel_port->tasklet_shutdown); in atmel_shutdown()
2030 del_timer_sync(&atmel_port->uart_timer); in atmel_shutdown()
2033 synchronize_irq(port->irq); in atmel_shutdown()
2039 tasklet_kill(&atmel_port->tasklet_rx); in atmel_shutdown()
2040 tasklet_kill(&atmel_port->tasklet_tx); in atmel_shutdown()
2052 * Shut-down the DMA. in atmel_shutdown()
2054 if (atmel_port->release_rx) in atmel_shutdown()
2055 atmel_port->release_rx(port); in atmel_shutdown()
2056 if (atmel_port->release_tx) in atmel_shutdown()
2057 atmel_port->release_tx(port); in atmel_shutdown()
2062 atmel_port->rx_ring.head = 0; in atmel_shutdown()
2063 atmel_port->rx_ring.tail = 0; in atmel_shutdown()
2068 free_irq(port->irq, port); in atmel_shutdown()
2087 clk_prepare_enable(atmel_port->clk); in atmel_serial_pm()
2089 /* re-enable interrupts if we disabled some on suspend */ in atmel_serial_pm()
2090 atmel_uart_writel(port, ATMEL_US_IER, atmel_port->backup_imr); in atmel_serial_pm()
2094 atmel_port->backup_imr = atmel_uart_readl(port, ATMEL_US_IMR); in atmel_serial_pm()
2095 atmel_uart_writel(port, ATMEL_US_IDR, -1); in atmel_serial_pm()
2101 clk_disable_unprepare(atmel_port->clk); in atmel_serial_pm()
2102 if (__clk_is_enabled(atmel_port->gclk)) in atmel_serial_pm()
2103 clk_disable_unprepare(atmel_port->gclk); in atmel_serial_pm()
2106 dev_err(port->dev, "atmel_serial: unknown pm %d\n", state); in atmel_serial_pm()
2127 if (atmel_port->is_usart) in atmel_set_termios()
2133 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16); in atmel_set_termios()
2136 switch (termios->c_cflag & CSIZE) { in atmel_set_termios()
2152 if (termios->c_cflag & CSTOPB) in atmel_set_termios()
2156 if (termios->c_cflag & PARENB) { in atmel_set_termios()
2158 if (termios->c_cflag & CMSPAR) { in atmel_set_termios()
2159 if (termios->c_cflag & PARODD) in atmel_set_termios()
2163 } else if (termios->c_cflag & PARODD) in atmel_set_termios()
2172 port->read_status_mask = ATMEL_US_OVRE; in atmel_set_termios()
2173 if (termios->c_iflag & INPCK) in atmel_set_termios()
2174 port->read_status_mask |= (ATMEL_US_FRAME | ATMEL_US_PARE); in atmel_set_termios()
2175 if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK)) in atmel_set_termios()
2176 port->read_status_mask |= ATMEL_US_RXBRK; in atmel_set_termios()
2180 atmel_uart_writel(port, ATMEL_US_IER, port->read_status_mask); in atmel_set_termios()
2185 port->ignore_status_mask = 0; in atmel_set_termios()
2186 if (termios->c_iflag & IGNPAR) in atmel_set_termios()
2187 port->ignore_status_mask |= (ATMEL_US_FRAME | ATMEL_US_PARE); in atmel_set_termios()
2188 if (termios->c_iflag & IGNBRK) { in atmel_set_termios()
2189 port->ignore_status_mask |= ATMEL_US_RXBRK; in atmel_set_termios()
2194 if (termios->c_iflag & IGNPAR) in atmel_set_termios()
2195 port->ignore_status_mask |= ATMEL_US_OVRE; in atmel_set_termios()
2199 /* update the per-port timeout */ in atmel_set_termios()
2200 uart_update_timeout(port, termios->c_cflag, baud); in atmel_set_termios()
2208 atmel_uart_writel(port, ATMEL_US_IDR, -1); in atmel_set_termios()
2212 atmel_port->tx_stopped = true; in atmel_set_termios()
2215 if (port->rs485.flags & SER_RS485_ENABLED) { in atmel_set_termios()
2217 port->rs485.delay_rts_after_send); in atmel_set_termios()
2219 } else if (port->iso7816.flags & SER_ISO7816_ENABLED) { in atmel_set_termios()
2220 atmel_uart_writel(port, ATMEL_US_TTGR, port->iso7816.tg); in atmel_set_termios()
2225 if ((port->iso7816.flags & SER_ISO7816_T_PARAM) in atmel_set_termios()
2230 } else if (termios->c_cflag & CRTSCTS) { in atmel_set_termios()
2231 /* RS232 with hardware handshake (RTS/CTS) */ in atmel_set_termios()
2233 !mctrl_gpio_to_gpiod(atmel_port->gpios, UART_GPIO_CTS)) { in atmel_set_termios()
2236 * be able to drive the RTS pin high/low when the RX in atmel_set_termios()
2242 * disabled (there must be an internal pull-up in atmel_set_termios()
2244 * If the RTS pin is a GPIO, the controller won't be in atmel_set_termios()
2265 * baudrate = selected clock / (8 * (2 - OVER) * (CD + FP / 8)) in atmel_set_termios()
2271 if (atmel_port->has_frac_baudrate) { in atmel_set_termios()
2272 div = DIV_ROUND_CLOSEST(port->uartclk, baud * 2); in atmel_set_termios()
2287 if (atmel_port->is_usart && cd > ATMEL_US_CD) { in atmel_set_termios()
2300 if (!atmel_port->has_frac_baudrate) { in atmel_set_termios()
2301 if (__clk_is_enabled(atmel_port->gclk)) in atmel_set_termios()
2302 clk_disable_unprepare(atmel_port->gclk); in atmel_set_termios()
2303 gclk_rate = clk_round_rate(atmel_port->gclk, 16 * baud); in atmel_set_termios()
2304 actual_baud = clk_get_rate(atmel_port->clk) / (16 * cd); in atmel_set_termios()
2307 clk_set_rate(atmel_port->gclk, 16 * baud); in atmel_set_termios()
2308 ret = clk_prepare_enable(atmel_port->gclk); in atmel_set_termios()
2312 if (atmel_port->is_usart) { in atmel_set_termios()
2335 if (!(port->iso7816.flags & SER_ISO7816_ENABLED)) in atmel_set_termios()
2342 * when switching the mode, set the RTS line state according to the in atmel_set_termios()
2349 /* let the hardware control the RTS line */ in atmel_set_termios()
2352 /* force RTS line to low level */ in atmel_set_termios()
2361 atmel_port->tx_stopped = false; in atmel_set_termios()
2366 /* CTS flow-control and modem-status interrupts */ in atmel_set_termios()
2367 if (UART_ENABLE_MS(port, termios->c_cflag)) in atmel_set_termios()
2377 if (termios->c_line == N_PPS) { in atmel_set_ldisc()
2378 port->flags |= UPF_HARDPPS_CD; in atmel_set_ldisc()
2383 port->flags &= ~UPF_HARDPPS_CD; in atmel_set_ldisc()
2384 if (!UART_ENABLE_MS(port, termios->c_cflag)) { in atmel_set_ldisc()
2397 return (port->type == PORT_ATMEL) ? "ATMEL_SERIAL" : NULL; in atmel_type()
2405 struct platform_device *mpdev = to_platform_device(port->dev->parent); in atmel_release_port()
2406 int size = resource_size(mpdev->resource); in atmel_release_port()
2408 release_mem_region(port->mapbase, size); in atmel_release_port()
2410 if (port->flags & UPF_IOREMAP) { in atmel_release_port()
2411 iounmap(port->membase); in atmel_release_port()
2412 port->membase = NULL; in atmel_release_port()
2421 struct platform_device *mpdev = to_platform_device(port->dev->parent); in atmel_request_port()
2422 int size = resource_size(mpdev->resource); in atmel_request_port()
2424 if (!request_mem_region(port->mapbase, size, "atmel_serial")) in atmel_request_port()
2425 return -EBUSY; in atmel_request_port()
2427 if (port->flags & UPF_IOREMAP) { in atmel_request_port()
2428 port->membase = ioremap(port->mapbase, size); in atmel_request_port()
2429 if (port->membase == NULL) { in atmel_request_port()
2430 release_mem_region(port->mapbase, size); in atmel_request_port()
2431 return -ENOMEM; in atmel_request_port()
2444 port->type = PORT_ATMEL; in atmel_config_port()
2455 if (ser->type != PORT_UNKNOWN && ser->type != PORT_ATMEL) in atmel_verify_port()
2456 ret = -EINVAL; in atmel_verify_port()
2457 if (port->irq != ser->irq) in atmel_verify_port()
2458 ret = -EINVAL; in atmel_verify_port()
2459 if (ser->io_type != SERIAL_IO_MEM) in atmel_verify_port()
2460 ret = -EINVAL; in atmel_verify_port()
2461 if (port->uartclk / 16 != ser->baud_base) in atmel_verify_port()
2462 ret = -EINVAL; in atmel_verify_port()
2463 if (port->mapbase != (unsigned long)ser->iomem_base) in atmel_verify_port()
2464 ret = -EINVAL; in atmel_verify_port()
2465 if (port->iobase != ser->port) in atmel_verify_port()
2466 ret = -EINVAL; in atmel_verify_port()
2467 if (ser->hub6 != 0) in atmel_verify_port()
2468 ret = -EINVAL; in atmel_verify_port()
2529 struct uart_port *port = &atmel_port->uart; in atmel_init_port()
2530 struct platform_device *mpdev = to_platform_device(pdev->dev.parent); in atmel_init_port()
2535 port->iotype = UPIO_MEM; in atmel_init_port()
2536 port->flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP; in atmel_init_port()
2537 port->ops = &atmel_pops; in atmel_init_port()
2538 port->fifosize = 1; in atmel_init_port()
2539 port->dev = &pdev->dev; in atmel_init_port()
2540 port->mapbase = mpdev->resource[0].start; in atmel_init_port()
2541 port->irq = platform_get_irq(mpdev, 0); in atmel_init_port()
2542 port->rs485_config = atmel_config_rs485; in atmel_init_port()
2543 port->rs485_supported = atmel_rs485_supported; in atmel_init_port()
2544 port->iso7816_config = atmel_config_iso7816; in atmel_init_port()
2545 port->membase = NULL; in atmel_init_port()
2547 memset(&atmel_port->rx_ring, 0, sizeof(atmel_port->rx_ring)); in atmel_init_port()
2553 port->uartclk = clk_get_rate(atmel_port->clk); in atmel_init_port()
2556 * Use TXEMPTY for interrupt when rs485 or ISO7816 else TXRDY or in atmel_init_port()
2560 atmel_port->tx_done_mask = ATMEL_US_TXEMPTY; in atmel_init_port()
2562 port->fifosize = PDC_BUFFER_SIZE; in atmel_init_port()
2563 atmel_port->tx_done_mask = ATMEL_US_ENDTX | ATMEL_US_TXBUFE; in atmel_init_port()
2565 atmel_port->tx_done_mask = ATMEL_US_TXRDY; in atmel_init_port()
2584 struct uart_port *port = &atmel_ports[co->index].uart; in atmel_console_write()
2594 ATMEL_US_RXRDY | atmel_port->tx_done_mask); in atmel_console_write()
2602 atmel_port->tx_stopped = false; in atmel_console_write()
2651 *baud = port->uartclk / (16 * quot); in atmel_console_get_options()
2656 struct uart_port *port = &atmel_ports[co->index].uart; in atmel_console_setup()
2663 if (port->membase == NULL) { in atmel_console_setup()
2664 /* Port not initialized yet - delay setup */ in atmel_console_setup()
2665 return -ENODEV; in atmel_console_setup()
2668 atmel_uart_writel(port, ATMEL_US_IDR, -1); in atmel_console_setup()
2671 atmel_port->tx_stopped = false; in atmel_console_setup()
2689 .index = -1,
2696 struct earlycon_device *dev = con->data; in atmel_serial_early_write()
2698 uart_console_write(&dev->port, s, n, atmel_console_putchar); in atmel_serial_early_write()
2704 if (!device->port.membase) in atmel_early_console_setup()
2705 return -ENODEV; in atmel_early_console_setup()
2707 device->con->write = atmel_serial_early_write; in atmel_early_console_setup()
2712 OF_EARLYCON_DECLARE(atmel_serial, "atmel,at91rm9200-usart",
2714 OF_EARLYCON_DECLARE(atmel_serial, "atmel,at91sam9260-usart",
2758 atmel_port->cache.mr = atmel_uart_readl(port, ATMEL_US_MR); in atmel_serial_suspend()
2759 atmel_port->cache.imr = atmel_uart_readl(port, ATMEL_US_IMR); in atmel_serial_suspend()
2760 atmel_port->cache.brgr = atmel_uart_readl(port, ATMEL_US_BRGR); in atmel_serial_suspend()
2761 atmel_port->cache.rtor = atmel_uart_readl(port, in atmel_serial_suspend()
2762 atmel_port->rtor); in atmel_serial_suspend()
2763 atmel_port->cache.ttgr = atmel_uart_readl(port, ATMEL_US_TTGR); in atmel_serial_suspend()
2764 atmel_port->cache.fmr = atmel_uart_readl(port, ATMEL_US_FMR); in atmel_serial_suspend()
2765 atmel_port->cache.fimr = atmel_uart_readl(port, ATMEL_US_FIMR); in atmel_serial_suspend()
2769 atmel_port->may_wakeup = device_may_wakeup(dev); in atmel_serial_suspend()
2773 spin_lock_irqsave(&atmel_port->lock_suspended, flags); in atmel_serial_suspend()
2774 atmel_port->suspended = true; in atmel_serial_suspend()
2775 spin_unlock_irqrestore(&atmel_port->lock_suspended, flags); in atmel_serial_suspend()
2791 atmel_uart_writel(port, ATMEL_US_MR, atmel_port->cache.mr); in atmel_serial_resume()
2792 atmel_uart_writel(port, ATMEL_US_IER, atmel_port->cache.imr); in atmel_serial_resume()
2793 atmel_uart_writel(port, ATMEL_US_BRGR, atmel_port->cache.brgr); in atmel_serial_resume()
2794 atmel_uart_writel(port, atmel_port->rtor, in atmel_serial_resume()
2795 atmel_port->cache.rtor); in atmel_serial_resume()
2796 atmel_uart_writel(port, ATMEL_US_TTGR, atmel_port->cache.ttgr); in atmel_serial_resume()
2798 if (atmel_port->fifo_size) { in atmel_serial_resume()
2802 atmel_port->cache.fmr); in atmel_serial_resume()
2804 atmel_port->cache.fimr); in atmel_serial_resume()
2809 spin_lock_irqsave(&atmel_port->lock_suspended, flags); in atmel_serial_resume()
2810 if (atmel_port->pending) { in atmel_serial_resume()
2811 atmel_handle_receive(port, atmel_port->pending); in atmel_serial_resume()
2812 atmel_handle_status(port, atmel_port->pending, in atmel_serial_resume()
2813 atmel_port->pending_status); in atmel_serial_resume()
2814 atmel_handle_transmit(port, atmel_port->pending); in atmel_serial_resume()
2815 atmel_port->pending = 0; in atmel_serial_resume()
2817 atmel_port->suspended = false; in atmel_serial_resume()
2818 spin_unlock_irqrestore(&atmel_port->lock_suspended, flags); in atmel_serial_resume()
2821 device_set_wakeup_enable(dev, atmel_port->may_wakeup); in atmel_serial_resume()
2829 atmel_port->fifo_size = 0; in atmel_serial_probe_fifos()
2830 atmel_port->rts_low = 0; in atmel_serial_probe_fifos()
2831 atmel_port->rts_high = 0; in atmel_serial_probe_fifos()
2833 if (of_property_read_u32(pdev->dev.of_node, in atmel_serial_probe_fifos()
2834 "atmel,fifo-size", in atmel_serial_probe_fifos()
2835 &atmel_port->fifo_size)) in atmel_serial_probe_fifos()
2838 if (!atmel_port->fifo_size) in atmel_serial_probe_fifos()
2841 if (atmel_port->fifo_size < ATMEL_MIN_FIFO_SIZE) { in atmel_serial_probe_fifos()
2842 atmel_port->fifo_size = 0; in atmel_serial_probe_fifos()
2843 dev_err(&pdev->dev, "Invalid FIFO size\n"); in atmel_serial_probe_fifos()
2851 * actually stopping to send new data. So we try to set the RTS High in atmel_serial_probe_fifos()
2855 atmel_port->rts_high = max_t(int, atmel_port->fifo_size >> 1, in atmel_serial_probe_fifos()
2856 atmel_port->fifo_size - ATMEL_RTS_HIGH_OFFSET); in atmel_serial_probe_fifos()
2857 atmel_port->rts_low = max_t(int, atmel_port->fifo_size >> 2, in atmel_serial_probe_fifos()
2858 atmel_port->fifo_size - ATMEL_RTS_LOW_OFFSET); in atmel_serial_probe_fifos()
2860 dev_info(&pdev->dev, "Using FIFO (%u data)\n", in atmel_serial_probe_fifos()
2861 atmel_port->fifo_size); in atmel_serial_probe_fifos()
2862 dev_dbg(&pdev->dev, "RTS High Threshold : %2u data\n", in atmel_serial_probe_fifos()
2863 atmel_port->rts_high); in atmel_serial_probe_fifos()
2864 dev_dbg(&pdev->dev, "RTS Low Threshold : %2u data\n", in atmel_serial_probe_fifos()
2865 atmel_port->rts_low); in atmel_serial_probe_fifos()
2871 struct device_node *np = pdev->dev.parent->of_node; in atmel_serial_probe()
2876 BUILD_BUG_ON(ATMEL_SERIAL_RINGSIZE & (ATMEL_SERIAL_RINGSIZE - 1)); in atmel_serial_probe()
2879 * In device tree there is no node with "atmel,at91rm9200-usart-serial" in atmel_serial_probe()
2880 * as compatible string. This driver is probed by at91-usart mfd driver in atmel_serial_probe()
2882 * spi-at91-usart driver. All attributes needed by this driver are in atmel_serial_probe()
2885 pdev->dev.of_node = np; in atmel_serial_probe()
2889 /* port id not found in platform data nor device-tree aliases: in atmel_serial_probe()
2890 * auto-enumerate it */ in atmel_serial_probe()
2894 ret = -ENODEV; in atmel_serial_probe()
2900 ret = -EBUSY; in atmel_serial_probe()
2905 atmel_port->backup_imr = 0; in atmel_serial_probe()
2906 atmel_port->uart.line = ret; in atmel_serial_probe()
2907 atmel_port->uart.has_sysrq = IS_ENABLED(CONFIG_SERIAL_ATMEL_CONSOLE); in atmel_serial_probe()
2910 atomic_set(&atmel_port->tasklet_shutdown, 0); in atmel_serial_probe()
2911 spin_lock_init(&atmel_port->lock_suspended); in atmel_serial_probe()
2913 atmel_port->clk = devm_clk_get(&pdev->dev, "usart"); in atmel_serial_probe()
2914 if (IS_ERR(atmel_port->clk)) { in atmel_serial_probe()
2915 ret = PTR_ERR(atmel_port->clk); in atmel_serial_probe()
2918 ret = clk_prepare_enable(atmel_port->clk); in atmel_serial_probe()
2922 atmel_port->gclk = devm_clk_get_optional(&pdev->dev, "gclk"); in atmel_serial_probe()
2923 if (IS_ERR(atmel_port->gclk)) { in atmel_serial_probe()
2924 ret = PTR_ERR(atmel_port->gclk); in atmel_serial_probe()
2932 atmel_port->gpios = mctrl_gpio_init(&atmel_port->uart, 0); in atmel_serial_probe()
2933 if (IS_ERR(atmel_port->gpios)) { in atmel_serial_probe()
2934 ret = PTR_ERR(atmel_port->gpios); in atmel_serial_probe()
2938 if (!atmel_use_pdc_rx(&atmel_port->uart)) { in atmel_serial_probe()
2939 ret = -ENOMEM; in atmel_serial_probe()
2943 atmel_port->rx_ring.buf = data; in atmel_serial_probe()
2946 rs485_enabled = atmel_port->uart.rs485.flags & SER_RS485_ENABLED; in atmel_serial_probe()
2948 ret = uart_add_one_port(&atmel_uart, &atmel_port->uart); in atmel_serial_probe()
2952 device_init_wakeup(&pdev->dev, 1); in atmel_serial_probe()
2956 atmel_uart_writel(&atmel_port->uart, ATMEL_US_MR, in atmel_serial_probe()
2958 atmel_uart_writel(&atmel_port->uart, ATMEL_US_CR, in atmel_serial_probe()
2965 atmel_get_ip_name(&atmel_port->uart); in atmel_serial_probe()
2971 clk_disable_unprepare(atmel_port->clk); in atmel_serial_probe()
2976 kfree(atmel_port->rx_ring.buf); in atmel_serial_probe()
2977 atmel_port->rx_ring.buf = NULL; in atmel_serial_probe()
2979 clk_disable_unprepare(atmel_port->clk); in atmel_serial_probe()
2980 clear_bit(atmel_port->uart.line, atmel_ports_in_use); in atmel_serial_probe()
2999 tasklet_kill(&atmel_port->tasklet_rx); in atmel_serial_remove()
3000 tasklet_kill(&atmel_port->tasklet_tx); in atmel_serial_remove()
3002 device_init_wakeup(&pdev->dev, 0); in atmel_serial_remove()
3006 kfree(atmel_port->rx_ring.buf); in atmel_serial_remove()
3010 clear_bit(port->line, atmel_ports_in_use); in atmel_serial_remove()
3012 pdev->dev.of_node = NULL; in atmel_serial_remove()