Skip to content

Commit fbb18a2

Browse files
Russell KingRussell King
authored andcommitted
[SERIAL] amba-pl010: allow platforms to specify modem control method
The amba-pl010 hardware does not provide RTS and DTR control lines; it is expected that these will be implemented using GPIO. Allow platforms to supply a function to implement manipulation of modem control lines. Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
1 parent 335bd9d commit fbb18a2

3 files changed

Lines changed: 119 additions & 93 deletions

File tree

‎arch/arm/mach-integrator/core.c‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
#include <linux/interrupt.h>
1616
#include <linux/sched.h>
1717
#include <linux/smp.h>
18+
#include <linux/termios.h>
1819
#include <linux/amba/bus.h>
20+
#include <linux/amba/serial.h>
1921

2022
#include <asm/hardware.h>
2123
#include <asm/irq.h>
@@ -28,6 +30,8 @@
2830

2931
#include "common.h"
3032

33+
static struct amba_pl010_data integrator_uart_data;
34+
3135
static struct amba_device rtc_device = {
3236
.dev = {
3337
.bus_id = "mb:15",
@@ -44,6 +48,7 @@ static struct amba_device rtc_device = {
4448
static struct amba_device uart0_device = {
4549
.dev = {
4650
.bus_id = "mb:16",
51+
.platform_data = &integrator_uart_data,
4752
},
4853
.res = {
4954
.start = INTEGRATOR_UART0_BASE,
@@ -57,6 +62,7 @@ static struct amba_device uart0_device = {
5762
static struct amba_device uart1_device = {
5863
.dev = {
5964
.bus_id = "mb:17",
65+
.platform_data = &integrator_uart_data,
6066
},
6167
.res = {
6268
.start = INTEGRATOR_UART1_BASE,
@@ -115,6 +121,46 @@ static int __init integrator_init(void)
115121

116122
arch_initcall(integrator_init);
117123

124+
/*
125+
* On the Integrator platform, the port RTS and DTR are provided by
126+
* bits in the following SC_CTRLS register bits:
127+
* RTS DTR
128+
* UART0 7 6
129+
* UART1 5 4
130+
*/
131+
#define SC_CTRLC (IO_ADDRESS(INTEGRATOR_SC_BASE) + INTEGRATOR_SC_CTRLC_OFFSET)
132+
#define SC_CTRLS (IO_ADDRESS(INTEGRATOR_SC_BASE) + INTEGRATOR_SC_CTRLS_OFFSET)
133+
134+
static void integrator_uart_set_mctrl(struct amba_device *dev, void __iomem *base, unsigned int mctrl)
135+
{
136+
unsigned int ctrls = 0, ctrlc = 0, rts_mask, dtr_mask;
137+
138+
if (dev == &uart0_device) {
139+
rts_mask = 1 << 4;
140+
dtr_mask = 1 << 5;
141+
} else {
142+
rts_mask = 1 << 6;
143+
dtr_mask = 1 << 7;
144+
}
145+
146+
if (mctrl & TIOCM_RTS)
147+
ctrlc |= rts_mask;
148+
else
149+
ctrls |= rts_mask;
150+
151+
if (mctrl & TIOCM_DTR)
152+
ctrlc |= dtr_mask;
153+
else
154+
ctrls |= dtr_mask;
155+
156+
__raw_writel(ctrls, SC_CTRLS);
157+
__raw_writel(ctrlc, SC_CTRLC);
158+
}
159+
160+
static struct amba_pl010_data integrator_uart_data = {
161+
.set_mctrl = integrator_uart_set_mctrl,
162+
};
163+
118164
#define CM_CTRL IO_ADDRESS(INTEGRATOR_HDR_BASE) + INTEGRATOR_HDR_CTRL_OFFSET
119165

120166
static DEFINE_SPINLOCK(cm_lock);

‎drivers/serial/amba-pl010.c‎

Lines changed: 67 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@
5151
#include <linux/amba/serial.h>
5252

5353
#include <asm/io.h>
54-
#include <asm/irq.h>
55-
#include <asm/hardware.h>
5654

5755
#define UART_NR 2
5856

@@ -65,26 +63,16 @@
6563
#define UART_RX_DATA(s) (((s) & UART01x_FR_RXFE) == 0)
6664
#define UART_TX_READY(s) (((s) & UART01x_FR_TXFF) == 0)
6765

68-
#define UART_DUMMY_RSR_RX /*256*/0
66+
#define UART_DUMMY_RSR_RX 256
6967
#define UART_PORT_SIZE 64
7068

71-
/*
72-
* On the Integrator platform, the port RTS and DTR are provided by
73-
* bits in the following SC_CTRLS register bits:
74-
* RTS DTR
75-
* UART0 7 6
76-
* UART1 5 4
77-
*/
78-
#define SC_CTRLC (IO_ADDRESS(INTEGRATOR_SC_BASE) + INTEGRATOR_SC_CTRLC_OFFSET)
79-
#define SC_CTRLS (IO_ADDRESS(INTEGRATOR_SC_BASE) + INTEGRATOR_SC_CTRLS_OFFSET)
80-
8169
/*
8270
* We wrap our port structure around the generic uart_port.
8371
*/
8472
struct uart_amba_port {
8573
struct uart_port port;
86-
unsigned int dtr_mask;
87-
unsigned int rts_mask;
74+
struct amba_device *dev;
75+
struct amba_pl010_data *data;
8876
unsigned int old_status;
8977
};
9078

@@ -300,20 +288,9 @@ static unsigned int pl010_get_mctrl(struct uart_port *port)
300288
static void pl010_set_mctrl(struct uart_port *port, unsigned int mctrl)
301289
{
302290
struct uart_amba_port *uap = (struct uart_amba_port *)port;
303-
unsigned int ctrls = 0, ctrlc = 0;
304-
305-
if (mctrl & TIOCM_RTS)
306-
ctrlc |= uap->rts_mask;
307-
else
308-
ctrls |= uap->rts_mask;
309291

310-
if (mctrl & TIOCM_DTR)
311-
ctrlc |= uap->dtr_mask;
312-
else
313-
ctrls |= uap->dtr_mask;
314-
315-
__raw_writel(ctrls, SC_CTRLS);
316-
__raw_writel(ctrlc, SC_CTRLC);
292+
if (uap->data)
293+
uap->data->set_mctrl(uap->dev, uap->port.membase, mctrl);
317294
}
318295

319296
static void pl010_break_ctl(struct uart_port *port, int break_state)
@@ -539,38 +516,7 @@ static struct uart_ops amba_pl010_pops = {
539516
.verify_port = pl010_verify_port,
540517
};
541518

542-
static struct uart_amba_port amba_ports[UART_NR] = {
543-
{
544-
.port = {
545-
.membase = (void *)IO_ADDRESS(INTEGRATOR_UART0_BASE),
546-
.mapbase = INTEGRATOR_UART0_BASE,
547-
.iotype = UPIO_MEM,
548-
.irq = IRQ_UARTINT0,
549-
.uartclk = 14745600,
550-
.fifosize = 16,
551-
.ops = &amba_pl010_pops,
552-
.flags = UPF_BOOT_AUTOCONF,
553-
.line = 0,
554-
},
555-
.dtr_mask = 1 << 5,
556-
.rts_mask = 1 << 4,
557-
},
558-
{
559-
.port = {
560-
.membase = (void *)IO_ADDRESS(INTEGRATOR_UART1_BASE),
561-
.mapbase = INTEGRATOR_UART1_BASE,
562-
.iotype = UPIO_MEM,
563-
.irq = IRQ_UARTINT1,
564-
.uartclk = 14745600,
565-
.fifosize = 16,
566-
.ops = &amba_pl010_pops,
567-
.flags = UPF_BOOT_AUTOCONF,
568-
.line = 1,
569-
},
570-
.dtr_mask = 1 << 7,
571-
.rts_mask = 1 << 6,
572-
}
573-
};
519+
static struct uart_amba_port *amba_ports[UART_NR];
574520

575521
#ifdef CONFIG_SERIAL_AMBA_PL010_CONSOLE
576522

@@ -588,7 +534,7 @@ static void pl010_console_putchar(struct uart_port *port, int ch)
588534
static void
589535
pl010_console_write(struct console *co, const char *s, unsigned int count)
590536
{
591-
struct uart_port *port = &amba_ports[co->index].port;
537+
struct uart_port *port = &amba_ports[co->index]->port;
592538
unsigned int status, old_cr;
593539

594540
/*
@@ -651,7 +597,7 @@ static int __init pl010_console_setup(struct console *co, char *options)
651597
*/
652598
if (co->index >= UART_NR)
653599
co->index = 0;
654-
port = &amba_ports[co->index].port;
600+
port = &amba_ports[co->index]->port;
655601

656602
if (options)
657603
uart_parse_options(options, &baud, &parity, &bits, &flow);
@@ -672,24 +618,6 @@ static struct console amba_console = {
672618
.data = &amba_reg,
673619
};
674620

675-
static int __init amba_console_init(void)
676-
{
677-
/*
678-
* All port initializations are done statically
679-
*/
680-
register_console(&amba_console);
681-
return 0;
682-
}
683-
console_initcall(amba_console_init);
684-
685-
static int __init amba_late_console_init(void)
686-
{
687-
if (!(amba_console.flags & CON_ENABLED))
688-
register_console(&amba_console);
689-
return 0;
690-
}
691-
late_initcall(amba_late_console_init);
692-
693621
#define AMBA_CONSOLE &amba_console
694622
#else
695623
#define AMBA_CONSOLE NULL
@@ -707,30 +635,76 @@ static struct uart_driver amba_reg = {
707635

708636
static int pl010_probe(struct amba_device *dev, void *id)
709637
{
710-
int i;
638+
struct uart_amba_port *port;
639+
void __iomem *base;
640+
int i, ret;
711641

712-
for (i = 0; i < UART_NR; i++) {
713-
if (amba_ports[i].port.mapbase != dev->res.start)
714-
continue;
642+
for (i = 0; i < ARRAY_SIZE(amba_ports); i++)
643+
if (amba_ports[i] == NULL)
644+
break;
715645

716-
amba_ports[i].port.dev = &dev->dev;
717-
uart_add_one_port(&amba_reg, &amba_ports[i].port);
718-
amba_set_drvdata(dev, &amba_ports[i]);
719-
break;
646+
if (i == ARRAY_SIZE(amba_ports)) {
647+
ret = -EBUSY;
648+
goto out;
720649
}
721650

722-
return 0;
651+
port = kzalloc(sizeof(struct uart_amba_port), GFP_KERNEL);
652+
if (!port) {
653+
ret = -ENOMEM;
654+
goto out;
655+
}
656+
657+
base = ioremap(dev->res.start, PAGE_SIZE);
658+
if (!base) {
659+
ret = -ENOMEM;
660+
goto free;
661+
}
662+
663+
port->port.dev = &dev->dev;
664+
port->port.mapbase = dev->res.start;
665+
port->port.membase = base;
666+
port->port.iotype = UPIO_MEM;
667+
port->port.irq = dev->irq[0];
668+
port->port.uartclk = 14745600;
669+
port->port.fifosize = 16;
670+
port->port.ops = &amba_pl010_pops;
671+
port->port.flags = UPF_BOOT_AUTOCONF;
672+
port->port.line = i;
673+
port->dev = dev;
674+
port->data = dev->dev.platform_data;
675+
676+
amba_ports[i] = port;
677+
678+
amba_set_drvdata(dev, port);
679+
ret = uart_add_one_port(&amba_reg, &port->port);
680+
if (ret) {
681+
amba_set_drvdata(dev, NULL);
682+
amba_ports[i] = NULL;
683+
iounmap(base);
684+
free:
685+
kfree(port);
686+
}
687+
688+
out:
689+
return ret;
723690
}
724691

725692
static int pl010_remove(struct amba_device *dev)
726693
{
727-
struct uart_amba_port *uap = amba_get_drvdata(dev);
728-
729-
if (uap)
730-
uart_remove_one_port(&amba_reg, &uap->port);
694+
struct uart_amba_port *port = amba_get_drvdata(dev);
695+
int i;
731696

732697
amba_set_drvdata(dev, NULL);
733698

699+
uart_remove_one_port(&amba_reg, &port->port);
700+
701+
for (i = 0; i < ARRAY_SIZE(amba_ports); i++)
702+
if (amba_ports[i] == port)
703+
amba_ports[i] = NULL;
704+
705+
iounmap(port->port.membase);
706+
kfree(port);
707+
734708
return 0;
735709
}
736710

‎include/linux/amba/serial.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,10 @@
158158
#define UART01x_RSR_ANY (UART01x_RSR_OE|UART01x_RSR_BE|UART01x_RSR_PE|UART01x_RSR_FE)
159159
#define UART01x_FR_MODEM_ANY (UART01x_FR_DCD|UART01x_FR_DSR|UART01x_FR_CTS)
160160

161+
#ifndef __ASSEMBLY__
162+
struct amba_pl010_data {
163+
void (*set_mctrl)(struct amba_device *dev, void __iomem *base, unsigned int mctrl);
164+
};
165+
#endif
166+
161167
#endif

0 commit comments

Comments
 (0)