summaryrefslogtreecommitdiff
path: root/drivers/serial
diff options
context:
space:
mode:
authorKyle McMartin <kyle@parisc-linux.org>2007-02-17 08:18:23 +0300
committerKyle McMartin <kyle@parisc-linux.org>2007-02-17 08:18:23 +0300
commite7b3ca08549caccf5d6e1cf066780bf4f0ae77a7 (patch)
tree7e5745bea06675cfce60d6813ee3b4d5e19cbb56 /drivers/serial
parent62d0cfcb27cf755cebdc93ca95dabc83608007cd (diff)
parentcb6efb39163bfb6bb6475fa7c8a5e08e44dbf14a (diff)
downloadlinux-e7b3ca08549caccf5d6e1cf066780bf4f0ae77a7.tar.xz
Merge branch 'parisc' from /home/kyle/repos/parisc-2.6.git
Conflicts: arch/parisc/hpux/sys_hpux.c arch/parisc/mm/ioremap.c
Diffstat (limited to 'drivers/serial')
-rw-r--r--drivers/serial/mux.c167
1 files changed, 132 insertions, 35 deletions
diff --git a/drivers/serial/mux.c b/drivers/serial/mux.c
index ccb8fa1800a5..83211013deb8 100644
--- a/drivers/serial/mux.c
+++ b/drivers/serial/mux.c
@@ -51,7 +51,11 @@
#define MUX_NR 256
static unsigned int port_cnt __read_mostly;
-static struct uart_port mux_ports[MUX_NR];
+struct mux_port {
+ struct uart_port port;
+ int enabled;
+};
+static struct mux_port mux_ports[MUX_NR];
static struct uart_driver mux_driver = {
.owner = THIS_MODULE,
@@ -66,7 +70,36 @@ static struct timer_list mux_timer;
#define UART_PUT_CHAR(p, c) __raw_writel((c), (p)->membase + IO_DATA_REG_OFFSET)
#define UART_GET_FIFO_CNT(p) __raw_readl((p)->membase + IO_DCOUNT_REG_OFFSET)
-#define GET_MUX_PORTS(iodc_data) ((((iodc_data)[4] & 0xf0) >> 4) * 8) + 8
+
+/**
+ * get_mux_port_count - Get the number of available ports on the Mux.
+ * @dev: The parisc device.
+ *
+ * This function is used to determine the number of ports the Mux
+ * supports. The IODC data reports the number of ports the Mux
+ * can support, but there are cases where not all the Mux ports
+ * are connected. This function can override the IODC and
+ * return the true port count.
+ */
+static int __init get_mux_port_count(struct parisc_device *dev)
+{
+ int status;
+ u8 iodc_data[32];
+ unsigned long bytecnt;
+
+ /* If this is the built-in Mux for the K-Class (Eole CAP/MUX),
+ * we only need to allocate resources for 1 port since the
+ * other 7 ports are not connected.
+ */
+ if(dev->id.hversion == 0x15)
+ return 1;
+
+ status = pdc_iodc_read(&bytecnt, dev->hpa.start, 0, iodc_data, 32);
+ BUG_ON(status != PDC_OK);
+
+ /* Return the number of ports specified in the iodc data. */
+ return ((((iodc_data)[4] & 0xf0) >> 4) * 8) + 8;
+}
/**
* mux_tx_empty - Check if the transmitter fifo is empty.
@@ -250,7 +283,7 @@ static void mux_read(struct uart_port *port)
*/
static int mux_startup(struct uart_port *port)
{
- mod_timer(&mux_timer, jiffies + MUX_POLL_DELAY);
+ mux_ports[port->line].enabled = 1;
return 0;
}
@@ -262,6 +295,7 @@ static int mux_startup(struct uart_port *port)
*/
static void mux_shutdown(struct uart_port *port)
{
+ mux_ports[port->line].enabled = 0;
}
/**
@@ -319,7 +353,7 @@ static int mux_request_port(struct uart_port *port)
* @port: Ptr to the uart_port.
* @type: Bitmask of required configurations.
*
- * Perform any autoconfiguration steps for the port. This functino is
+ * Perform any autoconfiguration steps for the port. This function is
* called if the UPF_BOOT_AUTOCONF flag is specified for the port.
* [Note: This is required for now because of a bug in the Serial core.
* rmk has already submitted a patch to linus, should be available for
@@ -357,11 +391,11 @@ static void mux_poll(unsigned long unused)
int i;
for(i = 0; i < port_cnt; ++i) {
- if(!mux_ports[i].info)
+ if(!mux_ports[i].enabled)
continue;
- mux_read(&mux_ports[i]);
- mux_write(&mux_ports[i]);
+ mux_read(&mux_ports[i].port);
+ mux_write(&mux_ports[i].port);
}
mod_timer(&mux_timer, jiffies + MUX_POLL_DELAY);
@@ -371,8 +405,17 @@ static void mux_poll(unsigned long unused)
#ifdef CONFIG_SERIAL_MUX_CONSOLE
static void mux_console_write(struct console *co, const char *s, unsigned count)
{
- while(count--)
- pdc_iodc_putc(*s++);
+ /* Wait until the FIFO drains. */
+ while(UART_GET_FIFO_CNT(&mux_ports[0].port))
+ udelay(1);
+
+ while(count--) {
+ if(*s == '\n') {
+ UART_PUT_CHAR(&mux_ports[0].port, '\r');
+ }
+ UART_PUT_CHAR(&mux_ports[0].port, *s++);
+ }
+
}
static int mux_console_setup(struct console *co, char *options)
@@ -428,19 +471,14 @@ static struct uart_ops mux_pops = {
*/
static int __init mux_probe(struct parisc_device *dev)
{
- int i, status, ports;
- u8 iodc_data[32];
- unsigned long bytecnt;
- struct uart_port *port;
+ int i, status;
- status = pdc_iodc_read(&bytecnt, dev->hpa.start, 0, iodc_data, 32);
- if(status != PDC_OK) {
- printk(KERN_ERR "Serial mux: Unable to read IODC.\n");
- return 1;
- }
+ int port_count = get_mux_port_count(dev);
+ printk(KERN_INFO "Serial mux driver (%d ports) Revision: 0.6\n", port_count);
- ports = GET_MUX_PORTS(iodc_data);
- printk(KERN_INFO "Serial mux driver (%d ports) Revision: 0.3\n", ports);
+ dev_set_drvdata(&dev->dev, (void *)(long)port_count);
+ request_mem_region(dev->hpa.start + MUX_OFFSET,
+ port_count * MUX_LINE_OFFSET, "Mux");
if(!port_cnt) {
mux_driver.cons = MUX_CONSOLE;
@@ -450,13 +488,10 @@ static int __init mux_probe(struct parisc_device *dev)
printk(KERN_ERR "Serial mux: Unable to register driver.\n");
return 1;
}
-
- init_timer(&mux_timer);
- mux_timer.function = mux_poll;
}
- for(i = 0; i < ports; ++i, ++port_cnt) {
- port = &mux_ports[port_cnt];
+ for(i = 0; i < port_count; ++i, ++port_cnt) {
+ struct uart_port *port = &mux_ports[port_cnt].port;
port->iobase = 0;
port->mapbase = dev->hpa.start + MUX_OFFSET +
(i * MUX_LINE_OFFSET);
@@ -477,27 +512,73 @@ static int __init mux_probe(struct parisc_device *dev)
*/
port->timeout = HZ / 50;
spin_lock_init(&port->lock);
+
status = uart_add_one_port(&mux_driver, port);
BUG_ON(status);
}
-#ifdef CONFIG_SERIAL_MUX_CONSOLE
- register_console(&mux_console);
-#endif
return 0;
}
+static int __devexit mux_remove(struct parisc_device *dev)
+{
+ int i, j;
+ int port_count = (long)dev_get_drvdata(&dev->dev);
+
+ /* Find Port 0 for this card in the mux_ports list. */
+ for(i = 0; i < port_cnt; ++i) {
+ if(mux_ports[i].port.mapbase == dev->hpa.start + MUX_OFFSET)
+ break;
+ }
+ BUG_ON(i + port_count > port_cnt);
+
+ /* Release the resources associated with each port on the device. */
+ for(j = 0; j < port_count; ++j, ++i) {
+ struct uart_port *port = &mux_ports[i].port;
+
+ uart_remove_one_port(&mux_driver, port);
+ if(port->membase)
+ iounmap(port->membase);
+ }
+
+ release_mem_region(dev->hpa.start + MUX_OFFSET, port_count * MUX_LINE_OFFSET);
+ return 0;
+}
+
+/* Hack. This idea was taken from the 8250_gsc.c on how to properly order
+ * the serial port detection in the proper order. The idea is we always
+ * want the builtin mux to be detected before addin mux cards, so we
+ * specifically probe for the builtin mux cards first.
+ *
+ * This table only contains the parisc_device_id of known builtin mux
+ * devices. All other mux cards will be detected by the generic mux_tbl.
+ */
+static struct parisc_device_id builtin_mux_tbl[] = {
+ { HPHW_A_DIRECT, HVERSION_REV_ANY_ID, 0x15, 0x0000D }, /* All K-class */
+ { HPHW_A_DIRECT, HVERSION_REV_ANY_ID, 0x44, 0x0000D }, /* E35, E45, and E55 */
+ { 0, }
+};
+
static struct parisc_device_id mux_tbl[] = {
{ HPHW_A_DIRECT, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0000D },
{ 0, }
};
+MODULE_DEVICE_TABLE(parisc, builtin_mux_tbl);
MODULE_DEVICE_TABLE(parisc, mux_tbl);
+static struct parisc_driver builtin_serial_mux_driver = {
+ .name = "builtin_serial_mux",
+ .id_table = builtin_mux_tbl,
+ .probe = mux_probe,
+ .remove = __devexit_p(mux_remove),
+};
+
static struct parisc_driver serial_mux_driver = {
.name = "serial_mux",
.id_table = mux_tbl,
.probe = mux_probe,
+ .remove = __devexit_p(mux_remove),
};
/**
@@ -507,7 +588,21 @@ static struct parisc_driver serial_mux_driver = {
*/
static int __init mux_init(void)
{
- return register_parisc_driver(&serial_mux_driver);
+ register_parisc_driver(&builtin_serial_mux_driver);
+ register_parisc_driver(&serial_mux_driver);
+
+ if(port_cnt > 0) {
+ /* Start the Mux timer */
+ init_timer(&mux_timer);
+ mux_timer.function = mux_poll;
+ mod_timer(&mux_timer, jiffies + MUX_POLL_DELAY);
+
+#ifdef CONFIG_SERIAL_MUX_CONSOLE
+ register_console(&mux_console);
+#endif
+ }
+
+ return 0;
}
/**
@@ -517,14 +612,16 @@ static int __init mux_init(void)
*/
static void __exit mux_exit(void)
{
- int i;
-
- for (i = 0; i < port_cnt; i++) {
- uart_remove_one_port(&mux_driver, &mux_ports[i]);
- if (mux_ports[i].membase)
- iounmap(mux_ports[i].membase);
+ /* Delete the Mux timer. */
+ if(port_cnt > 0) {
+ del_timer(&mux_timer);
+#ifdef CONFIG_SERIAL_MUX_CONSOLE
+ unregister_console(&mux_console);
+#endif
}
+ unregister_parisc_driver(&builtin_serial_mux_driver);
+ unregister_parisc_driver(&serial_mux_driver);
uart_unregister_driver(&mux_driver);
}