29 #include <linux/module.h>
31 #include <linux/serial.h>
32 #include <linux/serial_core.h>
33 #include <linux/tty.h>
35 #include <linux/slab.h>
41 #include <linux/kernel.h>
48 #include <linux/wait.h>
54 #include <mach/hardware.h>
59 #define UARTDM_MR1_ADDR 0x0
60 #define UARTDM_MR2_ADDR 0x4
63 #define RSLT_FIFO_CNTR_BMSK (0xE << 28)
64 #define RSLT_VLD BIT(1)
67 #define UARTDM_CSR_ADDR 0x8
68 #define UARTDM_CSR_115200 0xFF
69 #define UARTDM_CSR_57600 0xEE
70 #define UARTDM_CSR_38400 0xDD
71 #define UARTDM_CSR_28800 0xCC
72 #define UARTDM_CSR_19200 0xBB
73 #define UARTDM_CSR_14400 0xAA
74 #define UARTDM_CSR_9600 0x99
75 #define UARTDM_CSR_7200 0x88
76 #define UARTDM_CSR_4800 0x77
77 #define UARTDM_CSR_3600 0x66
78 #define UARTDM_CSR_2400 0x55
79 #define UARTDM_CSR_1200 0x44
80 #define UARTDM_CSR_600 0x33
81 #define UARTDM_CSR_300 0x22
82 #define UARTDM_CSR_150 0x11
83 #define UARTDM_CSR_75 0x00
86 #define UARTDM_TF_ADDR 0x70
87 #define UARTDM_TF2_ADDR 0x74
88 #define UARTDM_TF3_ADDR 0x78
89 #define UARTDM_TF4_ADDR 0x7C
92 #define UARTDM_CR_ADDR 0x10
93 #define UARTDM_IMR_ADDR 0x14
95 #define UARTDM_IPR_ADDR 0x18
96 #define UARTDM_TFWR_ADDR 0x1c
97 #define UARTDM_RFWR_ADDR 0x20
98 #define UARTDM_HCR_ADDR 0x24
99 #define UARTDM_DMRX_ADDR 0x34
100 #define UARTDM_IRDA_ADDR 0x38
101 #define UARTDM_DMEN_ADDR 0x3c
104 #define UARTDM_NCF_TX_ADDR 0x40
106 #define UARTDM_BADR_ADDR 0x44
108 #define UARTDM_SIM_CFG_ADDR 0x80
110 #define UARTDM_SR_ADDR 0x8
113 #define UARTDM_RF_ADDR 0x70
114 #define UARTDM_RF2_ADDR 0x74
115 #define UARTDM_RF3_ADDR 0x78
116 #define UARTDM_RF4_ADDR 0x7C
119 #define UARTDM_MISR_ADDR 0x10
122 #define UARTDM_ISR_ADDR 0x14
123 #define UARTDM_RX_TOTAL_SNAP_ADDR 0x38
125 #define UARTDM_RXFS_ADDR 0x50
128 #define UARTDM_SR_PAR_FRAME_BMSK BIT(5)
129 #define UARTDM_SR_OVERRUN_BMSK BIT(4)
130 #define UARTDM_SR_TXEMT_BMSK BIT(3)
131 #define UARTDM_SR_TXRDY_BMSK BIT(2)
132 #define UARTDM_SR_RXRDY_BMSK BIT(0)
134 #define UARTDM_CR_TX_DISABLE_BMSK BIT(3)
135 #define UARTDM_CR_RX_DISABLE_BMSK BIT(1)
136 #define UARTDM_CR_TX_EN_BMSK BIT(2)
137 #define UARTDM_CR_RX_EN_BMSK BIT(0)
140 #define RESET_RX 0x10
141 #define RESET_TX 0x20
142 #define RESET_ERROR_STATUS 0x30
143 #define RESET_BREAK_INT 0x40
144 #define START_BREAK 0x50
145 #define STOP_BREAK 0x60
146 #define RESET_CTS 0x70
147 #define RESET_STALE_INT 0x80
149 #define RFR_HIGH 0xE0
150 #define CR_PROTECTION_EN 0x100
151 #define STALE_EVENT_ENABLE 0x500
152 #define STALE_EVENT_DISABLE 0x600
153 #define FORCE_STALE_EVENT 0x400
154 #define CLEAR_TX_READY 0x300
155 #define RESET_TX_ERROR 0x800
156 #define RESET_TX_DONE 0x810
158 #define UARTDM_MR1_AUTO_RFR_LEVEL1_BMSK 0xffffff00
159 #define UARTDM_MR1_AUTO_RFR_LEVEL0_BMSK 0x3f
160 #define UARTDM_MR1_CTS_CTL_BMSK 0x40
161 #define UARTDM_MR1_RX_RDY_CTL_BMSK 0x80
163 #define UARTDM_MR2_ERROR_MODE_BMSK 0x40
164 #define UARTDM_MR2_BITS_PER_CHAR_BMSK 0x30
167 #define FIVE_BPC (0 << 4)
168 #define SIX_BPC (1 << 4)
169 #define SEVEN_BPC (2 << 4)
170 #define EIGHT_BPC (3 << 4)
172 #define UARTDM_MR2_STOP_BIT_LEN_BMSK 0xc
173 #define STOP_BIT_ONE (1 << 2)
174 #define STOP_BIT_TWO (3 << 2)
176 #define UARTDM_MR2_PARITY_MODE_BMSK 0x3
179 #define NO_PARITY 0x0
180 #define EVEN_PARITY 0x1
181 #define ODD_PARITY 0x2
182 #define SPACE_PARITY 0x3
184 #define UARTDM_IPR_STALE_TIMEOUT_MSB_BMSK 0xffffff80
185 #define UARTDM_IPR_STALE_LSB_BMSK 0x1f
188 #define UARTDM_ISR_TX_READY_BMSK BIT(7)
189 #define UARTDM_ISR_CURRENT_CTS_BMSK BIT(6)
190 #define UARTDM_ISR_DELTA_CTS_BMSK BIT(5)
191 #define UARTDM_ISR_RXLEV_BMSK BIT(4)
192 #define UARTDM_ISR_RXSTALE_BMSK BIT(3)
193 #define UARTDM_ISR_RXBREAK_BMSK BIT(2)
194 #define UARTDM_ISR_RXHUNT_BMSK BIT(1)
195 #define UARTDM_ISR_TXLEV_BMSK BIT(0)
198 #define UARTDM_TX_DM_EN_BMSK 0x1
199 #define UARTDM_RX_DM_EN_BMSK 0x2
201 #define UART_FIFOSIZE 64
202 #define UARTCLK 7372800
355 #define MSM_UARTDM_BURST_SIZE 16
356 #define UARTDM_TX_BUF_SIZE UART_XMIT_SIZE
357 #define UARTDM_RX_BUF_SIZE 512
367 #define UARTDM_TO_MSM(uart_port) \
368 container_of((uart_port), struct msm_hs_port, uport)
370 static unsigned int use_low_power_rx_wakeup(
struct msm_hs_port
376 static unsigned int msm_hs_read(
struct uart_port *uport,
415 msm_uport = &q_uart_port[pdev->
id];
416 dev = msm_uport->
uport.dev;
421 msm_uport->
rx.rbuffer);
435 kfree(msm_uport->
tx.command_ptr);
436 kfree(msm_uport->
tx.command_ptr_ptr);
439 kfree(msm_uport->
rx.command_ptr);
440 kfree(msm_uport->
rx.command_ptr_ptr);
447 static int msm_hs_init_clk_locked(
struct uart_port *uport)
471 static void msm_hs_pm(
struct uart_port *uport,
unsigned int state,
472 unsigned int oldstate)
476 if (use_low_power_rx_wakeup(msm_uport) ||
489 dev_err(uport->
dev,
"msm_serial: Unknown PM state %d\n",
503 static void msm_hs_set_bps_locked(
struct uart_port *uport,
506 unsigned long rxstale;
613 static void msm_hs_set_termios(
struct uart_port *uport,
620 unsigned int c_cflag = termios->
c_cflag;
633 msm_hs_set_bps_locked(uport, bps);
650 switch (c_cflag &
CSIZE) {
707 spin_unlock_irqrestore(&uport->
lock, flags);
714 static unsigned int msm_hs_tx_empty(
struct uart_port *uport)
717 unsigned int ret = 0;
736 static void msm_hs_stop_tx_locked(
struct uart_port *uport)
740 msm_uport->
tx.tx_ready_int_en = 0;
751 static void msm_hs_stop_rx_locked(
struct uart_port *uport)
774 static void msm_hs_submit_tx_locked(
struct uart_port *uport)
784 msm_hs_stop_tx_locked(uport);
805 ((tx_count + 15) >> 4);
827 static void msm_hs_start_rx_locked(
struct uart_port *uport)
846 static void msm_hs_start_tx_locked(
struct uart_port *uport)
855 if (msm_uport->
tx.tx_ready_int_en == 0) {
856 msm_uport->
tx.tx_ready_int_en = 1;
857 msm_hs_submit_tx_locked(uport);
870 static void msm_hs_dmov_tx_callback(
struct msm_dmov_cmd *cmd_ptr,
890 spin_unlock_irqrestore(&msm_uport->
uport.lock, flags);
900 static void msm_hs_dmov_rx_callback(
struct msm_dmov_cmd *cmd_ptr,
907 unsigned int error_f = 0;
915 uport = &msm_uport->
uport;
920 tty = uport->
state->port.tty;
930 uport->
icount.buf_overrun++;
951 flush = msm_uport->
rx.flush;
953 msm_hs_start_rx_locked(uport);
962 retval = tty_insert_flip_string(tty, msm_uport->
rx.buffer,
964 BUG_ON(retval != rx_count);
967 msm_hs_start_rx_locked(uport);
972 spin_unlock_irqrestore(&uport->
lock, flags);
1000 static unsigned int msm_hs_get_mctrl_locked(
struct uart_port *uport)
1010 static void set_rfr_locked(
struct uart_port *uport,
int auto_rfr)
1032 static void msm_hs_set_mctrl_locked(
struct uart_port *uport,
1035 unsigned int auto_rfr;
1041 set_rfr_locked(uport, auto_rfr);
1047 static void msm_hs_enable_ms_locked(
struct uart_port *uport)
1067 static void msm_hs_break_ctl(
struct uart_port *uport,
int ctl)
1076 static void msm_hs_config_port(
struct uart_port *uport,
int cfg_flags)
1078 unsigned long flags;
1083 msm_hs_request_port(uport);
1085 spin_unlock_irqrestore(&uport->
lock, flags);
1089 static void msm_hs_handle_delta_cts_locked(
struct uart_port *uport)
1110 static int msm_hs_check_clock_off_locked(
struct uart_port *uport)
1112 unsigned long sr_status;
1145 msm_hs_stop_rx_locked(uport);
1153 if (use_low_power_rx_wakeup(msm_uport)) {
1162 unsigned long flags;
1170 if (!msm_hs_check_clock_off_locked(uport)) {
1175 spin_unlock_irqrestore(&uport->
lock, flags);
1182 unsigned long flags;
1183 unsigned long isr_status;
1196 msm_uport->
imr_reg &= ~UARTDM_ISR_RXLEV_BMSK;
1230 msm_hs_submit_tx_locked(uport);
1237 msm_uport->
imr_reg &= ~UARTDM_ISR_TXLEV_BMSK;
1239 if (!msm_hs_check_clock_off_locked(uport))
1247 msm_hs_handle_delta_cts_locked(uport);
1249 spin_unlock_irqrestore(&uport->
lock, flags);
1261 if (!use_low_power_rx_wakeup(msm_uport))
1262 set_rfr_locked(uport, 0);
1282 unsigned long flags;
1286 spin_unlock_irqrestore(&uport->
lock, flags);
1309 msm_hs_start_rx_locked(uport);
1310 if (!use_low_power_rx_wakeup(msm_uport))
1311 set_rfr_locked(uport, 1);
1334 unsigned long flags;
1338 spin_unlock_irqrestore(&uport->
lock, flags);
1341 static irqreturn_t msm_hs_rx_wakeup_isr(
int irq,
void *dev)
1343 unsigned int wakeup = 0;
1344 unsigned long flags;
1364 tty = uport->
state->port.tty;
1365 tty_insert_flip_char(tty,
1372 spin_unlock_irqrestore(&uport->
lock, flags);
1377 static const char *msm_hs_type(
struct uart_port *port)
1383 static int msm_hs_startup(
struct uart_port *uport)
1387 unsigned long flags;
1403 uport->
state->port.tty->low_latency = 1;
1406 ret = msm_hs_init_clk_locked(uport);
1409 goto err_msm_hs_init_clk;
1449 tx->
xfer.complete_func = msm_hs_dmov_tx_callback;
1465 rx->
xfer.complete_func = msm_hs_dmov_rx_callback;
1485 "msm_hs_uart", msm_uport);
1488 goto err_request_irq;
1490 if (use_low_power_rx_wakeup(msm_uport)) {
1492 msm_hs_rx_wakeup_isr,
1494 "msm_hs_rx_wakeup", msm_uport);
1498 goto err_request_irq;
1506 msm_hs_start_rx_locked(uport);
1508 spin_unlock_irqrestore(&uport->
lock, flags);
1509 ret = pm_runtime_set_active(uport->
dev);
1511 dev_err(uport->
dev,
"set active error:%d\n", ret);
1517 err_msm_hs_init_clk:
1539 goto err_tx_command_ptr_ptr;
1554 pr_err(
"%s(): cannot allocate rx_buffer_pool", __func__);
1556 goto err_dma_pool_create;
1561 pr_err(
"%s(): cannot allocate rx->buffer", __func__);
1563 goto err_dma_pool_alloc;
1569 pr_err(
"%s(): cannot allocate rx->command_ptr", __func__);
1571 goto err_rx_command_ptr;
1576 pr_err(
"%s(): cannot allocate rx->command_ptr_ptr", __func__);
1578 goto err_rx_command_ptr_ptr;
1599 err_rx_command_ptr_ptr:
1603 msm_uport->
rx.rbuffer);
1606 err_dma_pool_create:
1611 kfree(msm_uport->
tx.command_ptr_ptr);
1612 err_tx_command_ptr_ptr:
1613 kfree(msm_uport->
tx.command_ptr);
1624 pdev->
dev.platform_data;
1631 msm_uport = &q_uart_port[pdev->
id];
1632 uport = &msm_uport->
uport;
1686 uport->
ops = &msm_hs_ops;
1691 if (IS_ERR(msm_uport->
clk))
1692 return PTR_ERR(msm_uport->
clk);
1694 ret = uartdm_init_port(uport);
1708 static int __init msm_serial_hs_init(
void)
1723 goto err_uart_register_driver;
1729 goto err_platform_driver_register;
1734 err_platform_driver_register:
1736 err_uart_register_driver:
1747 static void msm_hs_shutdown(
struct uart_port *uport)
1749 unsigned long flags;
1762 pm_runtime_disable(uport->
dev);
1763 pm_runtime_set_suspended(uport->
dev);
1767 if (use_low_power_rx_wakeup(msm_uport))
1783 spin_unlock_irqrestore(&uport->
lock, flags);
1786 msm_hs_tty_flip_buffer_work(&msm_uport->
rx.tty_work);
1789 static void __exit msm_serial_hs_exit(
void)
1798 #ifdef CONFIG_PM_RUNTIME
1828 #define msm_hs_runtime_idle NULL
1829 #define msm_hs_runtime_resume NULL
1830 #define msm_hs_runtime_suspend NULL
1833 static const struct dev_pm_ops msm_hs_dev_pm_ops = {
1840 .probe = msm_hs_probe,
1843 .name =
"msm_serial_hs",
1845 .pm = &msm_hs_dev_pm_ops,
1851 .driver_name =
"msm_serial_hs",
1852 .dev_name =
"ttyHS",
1857 static struct uart_ops msm_hs_ops = {
1858 .tx_empty = msm_hs_tx_empty,
1859 .set_mctrl = msm_hs_set_mctrl_locked,
1860 .get_mctrl = msm_hs_get_mctrl_locked,
1861 .stop_tx = msm_hs_stop_tx_locked,
1862 .start_tx = msm_hs_start_tx_locked,
1863 .stop_rx = msm_hs_stop_rx_locked,
1864 .enable_ms = msm_hs_enable_ms_locked,
1865 .break_ctl = msm_hs_break_ctl,
1866 .startup = msm_hs_startup,
1867 .shutdown = msm_hs_shutdown,
1868 .set_termios = msm_hs_set_termios,
1870 .type = msm_hs_type,
1871 .config_port = msm_hs_config_port,
1872 .release_port = msm_hs_release_port,
1873 .request_port = msm_hs_request_port,