54 #if defined(CONFIG_SERIAL_MPSC_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
58 #include <linux/module.h>
60 #include <linux/tty.h>
66 #include <linux/serial.h>
67 #include <linux/serial_core.h>
69 #include <linux/device.h>
78 #define MPSC_NUM_CTLRS 2
85 #define MPSC_RXR_ENTRIES 32
86 #define MPSC_RXRE_SIZE dma_get_cache_alignment()
87 #define MPSC_RXR_SIZE (MPSC_RXR_ENTRIES * MPSC_RXRE_SIZE)
88 #define MPSC_RXBE_SIZE dma_get_cache_alignment()
89 #define MPSC_RXB_SIZE (MPSC_RXR_ENTRIES * MPSC_RXBE_SIZE)
91 #define MPSC_TXR_ENTRIES 32
92 #define MPSC_TXRE_SIZE dma_get_cache_alignment()
93 #define MPSC_TXR_SIZE (MPSC_TXR_ENTRIES * MPSC_TXRE_SIZE)
94 #define MPSC_TXBE_SIZE dma_get_cache_alignment()
95 #define MPSC_TXB_SIZE (MPSC_TXR_ENTRIES * MPSC_TXBE_SIZE)
97 #define MPSC_DMA_ALLOC_SIZE (MPSC_RXR_SIZE + MPSC_RXB_SIZE + MPSC_TXR_SIZE \
98 + MPSC_TXB_SIZE + dma_get_cache_alignment() )
202 #define MPSC_MMCRL 0x0000
203 #define MPSC_MMCRH 0x0004
204 #define MPSC_MPCR 0x0008
205 #define MPSC_CHR_1 0x000c
206 #define MPSC_CHR_2 0x0010
207 #define MPSC_CHR_3 0x0014
208 #define MPSC_CHR_4 0x0018
209 #define MPSC_CHR_5 0x001c
210 #define MPSC_CHR_6 0x0020
211 #define MPSC_CHR_7 0x0024
212 #define MPSC_CHR_8 0x0028
213 #define MPSC_CHR_9 0x002c
214 #define MPSC_CHR_10 0x0030
215 #define MPSC_CHR_11 0x0034
217 #define MPSC_MPCR_FRZ (1 << 9)
218 #define MPSC_MPCR_CL_5 0
219 #define MPSC_MPCR_CL_6 1
220 #define MPSC_MPCR_CL_7 2
221 #define MPSC_MPCR_CL_8 3
222 #define MPSC_MPCR_SBL_1 0
223 #define MPSC_MPCR_SBL_2 1
225 #define MPSC_CHR_2_TEV (1<<1)
226 #define MPSC_CHR_2_TA (1<<7)
227 #define MPSC_CHR_2_TTCS (1<<9)
228 #define MPSC_CHR_2_REV (1<<17)
229 #define MPSC_CHR_2_RA (1<<23)
230 #define MPSC_CHR_2_CRD (1<<25)
231 #define MPSC_CHR_2_EH (1<<31)
232 #define MPSC_CHR_2_PAR_ODD 0
233 #define MPSC_CHR_2_PAR_SPACE 1
234 #define MPSC_CHR_2_PAR_EVEN 2
235 #define MPSC_CHR_2_PAR_MARK 3
238 #define MPSC_MRR 0x0000
239 #define MPSC_RCRR 0x0004
240 #define MPSC_TCRR 0x0008
243 #define SDMA_SDC 0x0000
244 #define SDMA_SDCM 0x0008
245 #define SDMA_RX_DESC 0x0800
246 #define SDMA_RX_BUF_PTR 0x0808
247 #define SDMA_SCRDP 0x0810
248 #define SDMA_TX_DESC 0x0c00
249 #define SDMA_SCTDP 0x0c10
250 #define SDMA_SFTDP 0x0c14
252 #define SDMA_DESC_CMDSTAT_PE (1<<0)
253 #define SDMA_DESC_CMDSTAT_CDL (1<<1)
254 #define SDMA_DESC_CMDSTAT_FR (1<<3)
255 #define SDMA_DESC_CMDSTAT_OR (1<<6)
256 #define SDMA_DESC_CMDSTAT_BR (1<<9)
257 #define SDMA_DESC_CMDSTAT_MI (1<<10)
258 #define SDMA_DESC_CMDSTAT_A (1<<11)
259 #define SDMA_DESC_CMDSTAT_AM (1<<12)
260 #define SDMA_DESC_CMDSTAT_CT (1<<13)
261 #define SDMA_DESC_CMDSTAT_C (1<<14)
262 #define SDMA_DESC_CMDSTAT_ES (1<<15)
263 #define SDMA_DESC_CMDSTAT_L (1<<16)
264 #define SDMA_DESC_CMDSTAT_F (1<<17)
265 #define SDMA_DESC_CMDSTAT_P (1<<18)
266 #define SDMA_DESC_CMDSTAT_EI (1<<23)
267 #define SDMA_DESC_CMDSTAT_O (1<<31)
269 #define SDMA_DESC_DFLT (SDMA_DESC_CMDSTAT_O \
270 | SDMA_DESC_CMDSTAT_EI)
272 #define SDMA_SDC_RFT (1<<0)
273 #define SDMA_SDC_SFM (1<<1)
274 #define SDMA_SDC_BLMR (1<<6)
275 #define SDMA_SDC_BLMT (1<<7)
276 #define SDMA_SDC_POVR (1<<8)
277 #define SDMA_SDC_RIFB (1<<9)
279 #define SDMA_SDCM_ERD (1<<7)
280 #define SDMA_SDCM_AR (1<<15)
281 #define SDMA_SDCM_STD (1<<16)
282 #define SDMA_SDCM_TXD (1<<23)
283 #define SDMA_SDCM_AT (1<<31)
285 #define SDMA_0_CAUSE_RXBUF (1<<0)
286 #define SDMA_0_CAUSE_RXERR (1<<1)
287 #define SDMA_0_CAUSE_TXBUF (1<<2)
288 #define SDMA_0_CAUSE_TXEND (1<<3)
289 #define SDMA_1_CAUSE_RXBUF (1<<8)
290 #define SDMA_1_CAUSE_RXERR (1<<9)
291 #define SDMA_1_CAUSE_TXBUF (1<<10)
292 #define SDMA_1_CAUSE_TXEND (1<<11)
294 #define SDMA_CAUSE_RX_MASK (SDMA_0_CAUSE_RXBUF | SDMA_0_CAUSE_RXERR \
295 | SDMA_1_CAUSE_RXBUF | SDMA_1_CAUSE_RXERR)
296 #define SDMA_CAUSE_TX_MASK (SDMA_0_CAUSE_TXBUF | SDMA_0_CAUSE_TXEND \
297 | SDMA_1_CAUSE_TXBUF | SDMA_1_CAUSE_TXEND)
300 #define SDMA_INTR_CAUSE 0x0000
301 #define SDMA_INTR_MASK 0x0080
304 #define BRG_BCR 0x0000
305 #define BRG_BTR 0x0004
311 #define MPSC_MAJOR 204
312 #define MPSC_MINOR_START 44
313 #define MPSC_DRIVER_NAME "MPSC"
314 #define MPSC_DEV_NAME "ttyMM"
315 #define MPSC_VERSION "1.00"
336 v = (v & ~(0xf << 18)) | ((clk_src & 0xf) << 18);
384 u32 cdv = (pi->
port.uartclk / (baud << 5)) - 1;
387 mpsc_brg_disable(pi);
389 v = (v & 0xffff0000) | (cdv & 0xffff);
409 pr_debug(
"mpsc_sdma_burstsize[%d]: burst_size: %d\n",
410 pi->
port.line, burst_size);
416 else if (burst_size < 4)
418 else if (burst_size < 8)
429 pr_debug(
"mpsc_sdma_init[%d]: burst_size: %d\n", pi->
port.line,
434 mpsc_sdma_burstsize(pi, burst_size);
441 pr_debug(
"mpsc_sdma_intr_mask[%d]: mask: 0x%x\n", pi->
port.line, mask);
464 pr_debug(
"mpsc_sdma_intr_unmask[%d]: mask: 0x%x\n", pi->
port.line,mask);
481 pr_debug(
"mpsc_sdma_intr_ack[%d]: Acknowledging IRQ\n", pi->
port.line);
492 pr_debug(
"mpsc_sdma_set_rx_ring[%d]: rxre_p: 0x%x\n",
529 if (!mpsc_sdma_tx_active(pi)) {
534 #if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE)
544 mpsc_sdma_set_tx_ring(pi, txre_p);
552 pr_debug(
"mpsc_sdma_stop[%d]: Stopping SDMA\n", pi->
port.line);
555 mpsc_sdma_cmd(pi, 0);
559 mpsc_sdma_set_tx_ring(pi,
NULL);
560 mpsc_sdma_set_rx_ring(pi,
NULL);
563 mpsc_sdma_intr_mask(pi, 0xf);
564 mpsc_sdma_intr_ack(pi);
579 pr_debug(
"mpsc_hw_init[%d]: Initializing hardware\n", pi->
port.line);
589 v = (v & ~0xf0f) | 0x100;
594 v = (v & ~0xf0f) | 0x100;
603 v = (v & ~0xf0f) | 0x100;
607 v = (v & ~0xf0f) | 0x100;
636 pr_debug(
"mpsc_enter_hunt[%d]: Hunting...\n", pi->
port.line);
679 pr_debug(
"mpsc_unfreeze[%d]: Unfrozen\n", pi->
port.line);
686 pr_debug(
"mpsc_set_char_length[%d]: char len: %d\n", pi->
port.line,len);
690 v = (v & ~(0x3 << 12)) | ((len & 0x3) << 12);
701 pr_debug(
"mpsc_set_stop_bit_length[%d]: stop bits: %d\n",
707 v = (v & ~(1 << 14)) | ((len & 0x1) << 14);
718 pr_debug(
"mpsc_set_parity[%d]: parity bits: 0x%x\n", pi->
port.line, p);
724 v = (v & ~0xc000c) | (p << 18) | (p << 2);
741 pr_debug(
"mpsc_init_hw[%d]: Initializing\n", pi->
port.line);
754 pr_debug(
"mpsc_alloc_ring_mem[%d]: Allocating ring mem\n",
775 pr_debug(
"mpsc_free_ring_mem[%d]: Freeing ring mem\n", pi->
port.line);
793 pr_debug(
"mpsc_init_rings[%d]: Initializing rings\n", pi->
port.line);
878 #if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE)
890 pr_debug(
"mpsc_uninit_rings[%d]: Uninitializing rings\n",pi->
port.line);
912 pr_debug(
"mpsc_make_ready[%d]: Making cltr ready\n", pi->
port.line);
916 if ((rc = mpsc_alloc_ring_mem(pi)))
925 #ifdef CONFIG_CONSOLE_POLL
926 static int serial_polled;
946 pr_debug(
"mpsc_rx_intr[%d]: Handling Rx intr\n", pi->
port.line);
952 #if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE)
964 #ifdef CONFIG_CONSOLE_POLL
984 #if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE)
1002 pi->
port.icount.rx++;
1005 pi->
port.icount.brk++;
1007 if (uart_handle_break(&pi->
port))
1010 pi->
port.icount.frame++;
1012 pi->
port.icount.overrun++;
1015 cmdstat &= pi->
port.read_status_mask;
1017 if (cmdstat & SDMA_DESC_CMDSTAT_BR)
1019 else if (cmdstat & SDMA_DESC_CMDSTAT_FR)
1021 else if (cmdstat & SDMA_DESC_CMDSTAT_OR)
1030 #ifdef CONFIG_CONSOLE_POLL
1039 if ((
unlikely(cmdstat & (SDMA_DESC_CMDSTAT_BR
1040 | SDMA_DESC_CMDSTAT_FR
1041 | SDMA_DESC_CMDSTAT_OR)))
1042 && !(cmdstat & pi->
port.ignore_status_mask)) {
1043 tty_insert_flip_char(tty, *bp, flag);
1045 for (i=0; i<bytes_in; i++)
1046 tty_insert_flip_char(tty, *bp++,
TTY_NORMAL);
1048 pi->
port.icount.rx += bytes_in;
1060 #if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE)
1072 #if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE)
1104 #if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE)
1119 < (MPSC_TXR_ENTRIES - 1)) {
1120 if (pi->
port.x_char) {
1130 *bp = pi->
port.x_char;
1131 pi->
port.x_char = 0;
1134 && !uart_tx_stopped(&pi->
port)) {
1151 #if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE)
1154 (
ulong)bp + MPSC_TXBE_SIZE);
1156 mpsc_setup_tx_desc(pi, i, 1);
1167 unsigned long iflags;
1171 if (!mpsc_sdma_tx_active(pi)) {
1177 #if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE)
1196 #if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE)
1203 mpsc_copy_tx_data(pi);
1204 mpsc_sdma_start_tx(pi);
1207 spin_unlock_irqrestore(&pi->
tx_lock, iflags);
1222 pr_debug(
"mpsc_sdma_intr[%d]: SDMA Interrupt Received\n",pi->
port.line);
1225 mpsc_sdma_intr_ack(pi);
1226 if (mpsc_rx_intr(pi))
1228 if (mpsc_tx_intr(pi))
1230 spin_unlock_irqrestore(&pi->
port.lock, iflags);
1232 pr_debug(
"mpsc_sdma_intr[%d]: SDMA Interrupt Handled\n", pi->
port.line);
1251 spin_unlock_irqrestore(&pi->
port.lock, iflags);
1278 static void mpsc_stop_tx(
struct uart_port *port)
1287 static void mpsc_start_tx(
struct uart_port *port)
1290 unsigned long iflags;
1295 mpsc_copy_tx_data(pi);
1296 mpsc_sdma_start_tx(pi);
1298 spin_unlock_irqrestore(&pi->
tx_lock, iflags);
1305 pr_debug(
"mpsc_start_rx[%d]: Starting...\n", pi->
port.line);
1308 mpsc_enter_hunt(pi);
1313 static void mpsc_stop_rx(
struct uart_port *port)
1317 pr_debug(
"mpsc_stop_rx[%d]: Stopping...\n", port->
line);
1335 static void mpsc_enable_ms(
struct uart_port *port)
1339 static void mpsc_break_ctl(
struct uart_port *port,
int ctl)
1345 v = ctl ? 0x00ff0000 : 0;
1351 spin_unlock_irqrestore(&pi->
port.lock, flags);
1354 static int mpsc_startup(
struct uart_port *port)
1360 pr_debug(
"mpsc_startup[%d]: Starting up MPSC, irq: %d\n",
1363 if ((rc = mpsc_make_ready(pi)) == 0) {
1365 mpsc_sdma_intr_ack(pi);
1368 if (mpsc_ports[0].port.
irq == mpsc_ports[1].port.irq)
1376 mpsc_sdma_intr_unmask(pi, 0xf);
1384 static void mpsc_shutdown(
struct uart_port *port)
1388 pr_debug(
"mpsc_shutdown[%d]: Shutting down MPSC\n", port->
line);
1445 mpsc_set_char_length(pi, chr_bits);
1446 mpsc_set_stop_bit_length(pi, stop_bits);
1447 mpsc_set_parity(pi, par);
1448 mpsc_set_baudrate(pi, baud);
1461 pi->
port.ignore_status_mask = 0;
1484 spin_unlock_irqrestore(&pi->
port.lock, flags);
1487 static const char *mpsc_type(
struct uart_port *port)
1493 static int mpsc_request_port(
struct uart_port *port)
1499 static void mpsc_release_port(
struct uart_port *port)
1504 mpsc_uninit_rings(pi);
1505 mpsc_free_ring_mem(pi);
1510 static void mpsc_config_port(
struct uart_port *port,
int flags)
1519 pr_debug(
"mpsc_verify_port[%d]: Verifying port data\n", pi->
port.line);
1523 else if (pi->
port.irq != ser->
irq)
1531 else if (pi->
port.iobase != ser->
port)
1533 else if (ser->
hub6 != 0)
1538 #ifdef CONFIG_CONSOLE_POLL
1543 static char poll_buf[2048];
1544 static int poll_ptr;
1545 static int poll_cnt;
1546 static void mpsc_put_poll_char(
struct uart_port *port,
1549 static int mpsc_get_poll_char(
struct uart_port *port)
1559 pr_debug(
"mpsc_rx_intr[%d]: Handling Rx intr\n", pi->
port.line);
1563 return poll_buf[poll_ptr++];
1568 while (poll_cnt == 0) {
1573 #if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE)
1582 while (poll_cnt == 0 &&
1589 #if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE)
1594 if ((
unlikely(cmdstat & (SDMA_DESC_CMDSTAT_BR |
1595 SDMA_DESC_CMDSTAT_FR | SDMA_DESC_CMDSTAT_OR))) &&
1596 !(cmdstat & pi->
port.ignore_status_mask)) {
1597 poll_buf[poll_cnt] = *bp;
1600 for (i = 0; i < bytes_in; i++) {
1601 poll_buf[poll_cnt] = *bp++;
1604 pi->
port.icount.rx += bytes_in;
1615 #if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE)
1623 (MPSC_RXR_ENTRIES - 1);
1628 #if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE)
1641 return poll_buf[poll_ptr++];
1648 static void mpsc_put_poll_char(
struct uart_port *port,
1666 static struct uart_ops mpsc_pops = {
1667 .tx_empty = mpsc_tx_empty,
1668 .set_mctrl = mpsc_set_mctrl,
1669 .get_mctrl = mpsc_get_mctrl,
1670 .stop_tx = mpsc_stop_tx,
1671 .start_tx = mpsc_start_tx,
1672 .stop_rx = mpsc_stop_rx,
1673 .enable_ms = mpsc_enable_ms,
1674 .break_ctl = mpsc_break_ctl,
1675 .startup = mpsc_startup,
1676 .shutdown = mpsc_shutdown,
1677 .set_termios = mpsc_set_termios,
1679 .release_port = mpsc_release_port,
1680 .request_port = mpsc_request_port,
1681 .config_port = mpsc_config_port,
1682 .verify_port = mpsc_verify_port,
1683 #ifdef CONFIG_CONSOLE_POLL
1684 .poll_get_char = mpsc_get_poll_char,
1685 .poll_put_char = mpsc_put_poll_char,
1697 #ifdef CONFIG_SERIAL_MPSC_CONSOLE
1698 static void mpsc_console_write(
struct console *co,
const char *
s,
uint count)
1701 u8 *bp, *
dp, add_cr = 0;
1703 unsigned long iflags;
1708 while (mpsc_sdma_tx_active(pi))
1710 mpsc_sdma_intr_ack(pi);
1714 while (mpsc_sdma_tx_active(pi))
1730 if (*(s++) ==
'\n') {
1741 #if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE)
1744 (
ulong)bp + MPSC_TXBE_SIZE);
1746 mpsc_setup_tx_desc(pi, i, 0);
1748 mpsc_sdma_start_tx(pi);
1750 while (mpsc_sdma_tx_active(pi))
1756 spin_unlock_irqrestore(&pi->
tx_lock, iflags);
1764 pr_debug(
"mpsc_console_setup[%d]: options: %s\n", co->
index, options);
1769 pi = &mpsc_ports[co->
index];
1787 static struct console mpsc_console = {
1789 .write = mpsc_console_write,
1791 .setup = mpsc_console_setup,
1797 static int __init mpsc_late_console_init(
void)
1799 pr_debug(
"mpsc_late_console_init: Enter\n");
1808 #define MPSC_CONSOLE &mpsc_console
1810 #define MPSC_CONSOLE NULL
1819 static void mpsc_resource_err(
char *s)
1832 "mpsc_routing_regs")) {
1837 mpsc_resource_err(
"MPSC routing base");
1845 "sdma_intr_regs")) {
1853 mpsc_resource_err(
"SDMA intr base");
1860 static void mpsc_shared_unmap_regs(
void)
1886 if (!(rc = mpsc_shared_map_regs(dev))) {
1888 dev->
dev.platform_data;
1910 mpsc_shared_unmap_regs();
1923 .probe = mpsc_shared_drv_probe,
1924 .remove = mpsc_shared_drv_remove,
1958 mpsc_resource_err(
"MPSC base");
1969 mpsc_resource_err(
"SDMA base");
1983 mpsc_resource_err(
"BRG base");
2024 static void mpsc_drv_get_platform_data(
struct mpsc_port_info *pi,
2033 pi->
port.line = num;
2035 pi->
port.fifosize = MPSC_TXBE_SIZE;
2038 pi->
port.ops = &mpsc_pops;
2067 pr_debug(
"mpsc_drv_probe: Adding MPSC %d\n", dev->
id);
2070 pi = &mpsc_ports[dev->
id];
2072 if (!(rc = mpsc_drv_map_regs(pi, dev))) {
2073 mpsc_drv_get_platform_data(pi, dev, dev->
id);
2076 if (!(rc = mpsc_make_ready(pi))) {
2084 mpsc_drv_unmap_regs(pi);
2087 mpsc_drv_unmap_regs(pi);
2097 pr_debug(
"mpsc_drv_exit: Removing MPSC %d\n", dev->
id);
2102 &mpsc_ports[dev->
id].port);
2103 mpsc_drv_unmap_regs(&mpsc_ports[dev->
id]);
2111 .probe = mpsc_drv_probe,
2112 .remove = mpsc_drv_remove,
2119 static int __init mpsc_drv_init(
void)
2125 memset(mpsc_ports, 0,
sizeof(mpsc_ports));
2142 static void __exit mpsc_drv_exit(
void)
2147 memset(mpsc_ports, 0,
sizeof(mpsc_ports));