xref: /linux/drivers/tty/serial/8250/8250_parisc.c (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
19e4e2ce1SHelge Deller // SPDX-License-Identifier: GPL-2.0+
29e4e2ce1SHelge Deller /*
39e4e2ce1SHelge Deller  *	Serial Device Initialisation for Lasi/Asp/Wax/Dino
49e4e2ce1SHelge Deller  *
59e4e2ce1SHelge Deller  *	(c) Copyright Matthew Wilcox <willy@debian.org> 2001-2002
69e4e2ce1SHelge Deller  */
79e4e2ce1SHelge Deller 
89e4e2ce1SHelge Deller #include <linux/errno.h>
99e4e2ce1SHelge Deller #include <linux/init.h>
109e4e2ce1SHelge Deller #include <linux/interrupt.h>
119e4e2ce1SHelge Deller #include <linux/ioport.h>
129e4e2ce1SHelge Deller #include <linux/module.h>
139e4e2ce1SHelge Deller #include <linux/serial_core.h>
149e4e2ce1SHelge Deller #include <linux/signal.h>
159e4e2ce1SHelge Deller #include <linux/types.h>
169e4e2ce1SHelge Deller 
179e4e2ce1SHelge Deller #include <asm/hardware.h>
189e4e2ce1SHelge Deller #include <asm/parisc-device.h>
199e4e2ce1SHelge Deller #include <asm/io.h>
209e4e2ce1SHelge Deller 
219e4e2ce1SHelge Deller #include "8250.h"
229e4e2ce1SHelge Deller 
serial_init_chip(struct parisc_device * dev)239e4e2ce1SHelge Deller static int __init serial_init_chip(struct parisc_device *dev)
249e4e2ce1SHelge Deller {
259e4e2ce1SHelge Deller 	struct uart_8250_port uart;
269e4e2ce1SHelge Deller 	unsigned long address;
279e4e2ce1SHelge Deller 	int err;
289e4e2ce1SHelge Deller 
299e4e2ce1SHelge Deller #if defined(CONFIG_64BIT) && defined(CONFIG_IOSAPIC)
309e4e2ce1SHelge Deller 	if (!dev->irq && (dev->id.sversion == 0xad))
319e4e2ce1SHelge Deller 		dev->irq = iosapic_serial_irq(dev);
329e4e2ce1SHelge Deller #endif
339e4e2ce1SHelge Deller 
349e4e2ce1SHelge Deller 	if (!dev->irq) {
359e4e2ce1SHelge Deller 		/* We find some unattached serial ports by walking native
369e4e2ce1SHelge Deller 		 * busses.  These should be silently ignored.  Otherwise,
379e4e2ce1SHelge Deller 		 * what we have here is a missing parent device, so tell
389e4e2ce1SHelge Deller 		 * the user what they're missing.
399e4e2ce1SHelge Deller 		 */
409e4e2ce1SHelge Deller 		if (parisc_parent(dev)->id.hw_type != HPHW_IOA)
419e4e2ce1SHelge Deller 			dev_info(&dev->dev,
429e4e2ce1SHelge Deller 				"Serial: device 0x%llx not configured.\n"
439e4e2ce1SHelge Deller 				"Enable support for Wax, Lasi, Asp or Dino.\n",
449e4e2ce1SHelge Deller 				(unsigned long long)dev->hpa.start);
459e4e2ce1SHelge Deller 		return -ENODEV;
469e4e2ce1SHelge Deller 	}
479e4e2ce1SHelge Deller 
489e4e2ce1SHelge Deller 	address = dev->hpa.start;
499e4e2ce1SHelge Deller 	if (dev->id.sversion != 0x8d)
509e4e2ce1SHelge Deller 		address += 0x800;
519e4e2ce1SHelge Deller 
529e4e2ce1SHelge Deller 	memset(&uart, 0, sizeof(uart));
539e4e2ce1SHelge Deller 	uart.port.iotype	= UPIO_MEM;
549e4e2ce1SHelge Deller 	/* 7.272727MHz on Lasi.  Assumed the same for Dino, Wax and Timi. */
559e4e2ce1SHelge Deller 	uart.port.uartclk	= (dev->id.sversion != 0xad) ?
569e4e2ce1SHelge Deller 					7272727 : 1843200;
579e4e2ce1SHelge Deller 	uart.port.mapbase	= address;
589e4e2ce1SHelge Deller 	uart.port.membase	= ioremap(address, 16);
599e4e2ce1SHelge Deller 	if (!uart.port.membase) {
609e4e2ce1SHelge Deller 		dev_warn(&dev->dev, "Failed to map memory\n");
619e4e2ce1SHelge Deller 		return -ENOMEM;
629e4e2ce1SHelge Deller 	}
639e4e2ce1SHelge Deller 	uart.port.irq	= dev->irq;
649e4e2ce1SHelge Deller 	uart.port.flags	= UPF_BOOT_AUTOCONF;
659e4e2ce1SHelge Deller 	uart.port.dev	= &dev->dev;
669e4e2ce1SHelge Deller 
679e4e2ce1SHelge Deller 	err = serial8250_register_8250_port(&uart);
689e4e2ce1SHelge Deller 	if (err < 0) {
699e4e2ce1SHelge Deller 		dev_warn(&dev->dev,
709e4e2ce1SHelge Deller 			"serial8250_register_8250_port returned error %d\n",
719e4e2ce1SHelge Deller 			err);
729e4e2ce1SHelge Deller 		iounmap(uart.port.membase);
739e4e2ce1SHelge Deller 		return err;
749e4e2ce1SHelge Deller 	}
759e4e2ce1SHelge Deller 
769e4e2ce1SHelge Deller 	return 0;
779e4e2ce1SHelge Deller }
789e4e2ce1SHelge Deller 
799e4e2ce1SHelge Deller static const struct parisc_device_id serial_tbl[] __initconst = {
809e4e2ce1SHelge Deller 	{ HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00075 },
819e4e2ce1SHelge Deller 	{ HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0008c },
829e4e2ce1SHelge Deller 	{ HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0008d },
839e4e2ce1SHelge Deller 	{ HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x000ad },
849e4e2ce1SHelge Deller 	{ 0 }
859e4e2ce1SHelge Deller };
869e4e2ce1SHelge Deller 
879e4e2ce1SHelge Deller /* Hack.  Some machines have SERIAL_0 attached to Lasi and SERIAL_1
889e4e2ce1SHelge Deller  * attached to Dino.  Unfortunately, Dino appears before Lasi in the device
899e4e2ce1SHelge Deller  * tree.  To ensure that ttyS0 == SERIAL_0, we register two drivers; one
909e4e2ce1SHelge Deller  * which only knows about Lasi and then a second which will find all the
919e4e2ce1SHelge Deller  * other serial ports.  HPUX ignores this problem.
929e4e2ce1SHelge Deller  */
939e4e2ce1SHelge Deller static const struct parisc_device_id lasi_tbl[] __initconst = {
949e4e2ce1SHelge Deller 	{ HPHW_FIO, HVERSION_REV_ANY_ID, 0x03B, 0x0008C }, /* C1xx/C1xxL */
959e4e2ce1SHelge Deller 	{ HPHW_FIO, HVERSION_REV_ANY_ID, 0x03C, 0x0008C }, /* B132L */
969e4e2ce1SHelge Deller 	{ HPHW_FIO, HVERSION_REV_ANY_ID, 0x03D, 0x0008C }, /* B160L */
979e4e2ce1SHelge Deller 	{ HPHW_FIO, HVERSION_REV_ANY_ID, 0x03E, 0x0008C }, /* B132L+ */
989e4e2ce1SHelge Deller 	{ HPHW_FIO, HVERSION_REV_ANY_ID, 0x03F, 0x0008C }, /* B180L+ */
999e4e2ce1SHelge Deller 	{ HPHW_FIO, HVERSION_REV_ANY_ID, 0x046, 0x0008C }, /* Rocky2 120 */
1009e4e2ce1SHelge Deller 	{ HPHW_FIO, HVERSION_REV_ANY_ID, 0x047, 0x0008C }, /* Rocky2 150 */
1019e4e2ce1SHelge Deller 	{ HPHW_FIO, HVERSION_REV_ANY_ID, 0x04E, 0x0008C }, /* Kiji L2 132 */
1029e4e2ce1SHelge Deller 	{ HPHW_FIO, HVERSION_REV_ANY_ID, 0x056, 0x0008C }, /* Raven+ */
1039e4e2ce1SHelge Deller 	{ 0 }
1049e4e2ce1SHelge Deller };
1059e4e2ce1SHelge Deller 
1069e4e2ce1SHelge Deller 
1079e4e2ce1SHelge Deller MODULE_DEVICE_TABLE(parisc, serial_tbl);
1089e4e2ce1SHelge Deller 
1099e4e2ce1SHelge Deller static struct parisc_driver lasi_driver __refdata = {
1109e4e2ce1SHelge Deller 	.name		= "serial_1",
1119e4e2ce1SHelge Deller 	.id_table	= lasi_tbl,
1129e4e2ce1SHelge Deller 	.probe		= serial_init_chip,
1139e4e2ce1SHelge Deller };
1149e4e2ce1SHelge Deller 
1159e4e2ce1SHelge Deller static struct parisc_driver serial_driver __refdata = {
1169e4e2ce1SHelge Deller 	.name		= "serial",
1179e4e2ce1SHelge Deller 	.id_table	= serial_tbl,
1189e4e2ce1SHelge Deller 	.probe		= serial_init_chip,
1199e4e2ce1SHelge Deller };
1209e4e2ce1SHelge Deller 
probe_serial_gsc(void)1219e4e2ce1SHelge Deller static int __init probe_serial_gsc(void)
1229e4e2ce1SHelge Deller {
1239e4e2ce1SHelge Deller 	register_parisc_driver(&lasi_driver);
1249e4e2ce1SHelge Deller 	register_parisc_driver(&serial_driver);
1259e4e2ce1SHelge Deller 	return 0;
1269e4e2ce1SHelge Deller }
1279e4e2ce1SHelge Deller 
1289e4e2ce1SHelge Deller module_init(probe_serial_gsc);
1299e4e2ce1SHelge Deller 
130*f0a17485SJeff Johnson MODULE_DESCRIPTION("Serial Device Initialisation for Lasi/Asp/Wax/Dino");
1319e4e2ce1SHelge Deller MODULE_LICENSE("GPL");
132