]> err.no Git - linux-2.6/blobdiff - drivers/serial/cpm_uart/cpm_uart_core.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6
[linux-2.6] / drivers / serial / cpm_uart / cpm_uart_core.c
index 1ff80de177db21be26be01ffa35831854821e97d..25efca5a7a1ffe423b0757f2a89f660390537e20 100644 (file)
@@ -43,6 +43,9 @@
 #include <linux/dma-mapping.h>
 #include <linux/fs_uart_pd.h>
 #include <linux/of_platform.h>
+#include <linux/gpio.h>
+#include <linux/of_gpio.h>
+#include <linux/clk.h>
 
 #include <asm/io.h>
 #include <asm/irq.h>
@@ -96,13 +99,41 @@ static unsigned int cpm_uart_tx_empty(struct uart_port *port)
 
 static void cpm_uart_set_mctrl(struct uart_port *port, unsigned int mctrl)
 {
-       /* Whee. Do nothing. */
+       struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
+
+       if (pinfo->gpios[GPIO_RTS] >= 0)
+               gpio_set_value(pinfo->gpios[GPIO_RTS], !(mctrl & TIOCM_RTS));
+
+       if (pinfo->gpios[GPIO_DTR] >= 0)
+               gpio_set_value(pinfo->gpios[GPIO_DTR], !(mctrl & TIOCM_DTR));
 }
 
 static unsigned int cpm_uart_get_mctrl(struct uart_port *port)
 {
-       /* Whee. Do nothing. */
-       return TIOCM_CAR | TIOCM_DSR | TIOCM_CTS;
+       struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
+       unsigned int mctrl = TIOCM_CTS | TIOCM_DSR | TIOCM_CAR;
+
+       if (pinfo->gpios[GPIO_CTS] >= 0) {
+               if (gpio_get_value(pinfo->gpios[GPIO_CTS]))
+                       mctrl &= ~TIOCM_CTS;
+       }
+
+       if (pinfo->gpios[GPIO_DSR] >= 0) {
+               if (gpio_get_value(pinfo->gpios[GPIO_DSR]))
+                       mctrl &= ~TIOCM_DSR;
+       }
+
+       if (pinfo->gpios[GPIO_DCD] >= 0) {
+               if (gpio_get_value(pinfo->gpios[GPIO_DCD]))
+                       mctrl &= ~TIOCM_CAR;
+       }
+
+       if (pinfo->gpios[GPIO_RI] >= 0) {
+               if (!gpio_get_value(pinfo->gpios[GPIO_RI]))
+                       mctrl |= TIOCM_RNG;
+       }
+
+       return mctrl;
 }
 
 /*
@@ -435,10 +466,13 @@ static void cpm_uart_shutdown(struct uart_port *port)
                }
 
                /* Shut them really down and reinit buffer descriptors */
-               if (IS_SMC(pinfo))
+               if (IS_SMC(pinfo)) {
+                       out_be16(&pinfo->smcup->smc_brkcr, 0);
                        cpm_line_cr_cmd(pinfo, CPM_CR_STOP_TX);
-               else
+               } else {
+                       out_be16(&pinfo->sccup->scc_brkcr, 0);
                        cpm_line_cr_cmd(pinfo, CPM_CR_GRA_STOP_TX);
+               }
 
                cpm_uart_initbd(pinfo);
        }
@@ -554,14 +588,19 @@ static void cpm_uart_set_termios(struct uart_port *port,
                 * enables, because we want to put them back if they were
                 * present.
                 */
-               prev_mode = in_be16(&smcp->smc_smcmr);
-               out_be16(&smcp->smc_smcmr, smcr_mk_clen(bits) | cval | SMCMR_SM_UART);
-               setbits16(&smcp->smc_smcmr, (prev_mode & (SMCMR_REN | SMCMR_TEN)));
+               prev_mode = in_be16(&smcp->smc_smcmr) & (SMCMR_REN | SMCMR_TEN);
+               /* Output in *one* operation, so we don't interrupt RX/TX if they
+                * were already enabled. */
+               out_be16(&smcp->smc_smcmr, smcr_mk_clen(bits) | cval |
+                   SMCMR_SM_UART | prev_mode);
        } else {
                out_be16(&sccp->scc_psmr, (sbits << 12) | scval);
        }
 
-       cpm_set_brg(pinfo->brg - 1, baud);
+       if (pinfo->clk)
+               clk_set_rate(pinfo->clk, baud);
+       else
+               cpm_set_brg(pinfo->brg - 1, baud);
        spin_unlock_irqrestore(&port->lock, flags);
 }
 
@@ -986,14 +1025,23 @@ static int cpm_uart_init_port(struct device_node *np,
        void __iomem *mem, *pram;
        int len;
        int ret;
+       int i;
 
-       data = of_get_property(np, "fsl,cpm-brg", &len);
-       if (!data || len != 4) {
-               printk(KERN_ERR "CPM UART %s has no/invalid "
-                               "fsl,cpm-brg property.\n", np->name);
-               return -EINVAL;
+       data = of_get_property(np, "clock", NULL);
+       if (data) {
+               struct clk *clk = clk_get(NULL, (const char*)data);
+               if (!IS_ERR(clk))
+                       pinfo->clk = clk;
+       }
+       if (!pinfo->clk) {
+               data = of_get_property(np, "fsl,cpm-brg", &len);
+               if (!data || len != 4) {
+                       printk(KERN_ERR "CPM UART %s has no/invalid "
+                                       "fsl,cpm-brg property.\n", np->name);
+                       return -EINVAL;
+               }
+               pinfo->brg = *data;
        }
-       pinfo->brg = *data;
 
        data = of_get_property(np, "fsl,cpm-command", &len);
        if (!data || len != 4) {
@@ -1045,6 +1093,9 @@ static int cpm_uart_init_port(struct device_node *np,
                goto out_pram;
        }
 
+       for (i = 0; i < NUM_GPIOS; i++)
+               pinfo->gpios[i] = of_get_gpio(np, i);
+
        return cpm_uart_request_port(&pinfo->port);
 
 out_pram:
@@ -1198,12 +1249,14 @@ static int __init cpm_uart_console_setup(struct console *co, char *options)
        udbg_putc = NULL;
 #endif
 
-       cpm_line_cr_cmd(pinfo, CPM_CR_STOP_TX);
-
        if (IS_SMC(pinfo)) {
+               out_be16(&pinfo->smcup->smc_brkcr, 0);
+               cpm_line_cr_cmd(pinfo, CPM_CR_STOP_TX);
                clrbits8(&pinfo->smcp->smc_smcm, SMCM_RX | SMCM_TX);
                clrbits16(&pinfo->smcp->smc_smcmr, SMCMR_REN | SMCMR_TEN);
        } else {
+               out_be16(&pinfo->sccup->scc_brkcr, 0);
+               cpm_line_cr_cmd(pinfo, CPM_CR_GRA_STOP_TX);
                clrbits16(&pinfo->sccp->scc_sccm, UART_SCCM_TX | UART_SCCM_RX);
                clrbits32(&pinfo->sccp->scc_gsmrl, SCC_GSMRL_ENR | SCC_GSMRL_ENT);
        }