18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Serial Device Initialisation for Lasi/Asp/Wax/Dino 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * (c) Copyright Matthew Wilcox <willy@debian.org> 2001-2002 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include <linux/errno.h> 98c2ecf20Sopenharmony_ci#include <linux/init.h> 108c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 118c2ecf20Sopenharmony_ci#include <linux/ioport.h> 128c2ecf20Sopenharmony_ci#include <linux/module.h> 138c2ecf20Sopenharmony_ci#include <linux/serial_core.h> 148c2ecf20Sopenharmony_ci#include <linux/signal.h> 158c2ecf20Sopenharmony_ci#include <linux/types.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#include <asm/hardware.h> 188c2ecf20Sopenharmony_ci#include <asm/parisc-device.h> 198c2ecf20Sopenharmony_ci#include <asm/io.h> 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci#include "8250.h" 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_cistatic int __init serial_init_chip(struct parisc_device *dev) 248c2ecf20Sopenharmony_ci{ 258c2ecf20Sopenharmony_ci struct uart_8250_port uart; 268c2ecf20Sopenharmony_ci unsigned long address; 278c2ecf20Sopenharmony_ci int err; 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci#if defined(CONFIG_64BIT) && defined(CONFIG_IOSAPIC) 308c2ecf20Sopenharmony_ci if (!dev->irq && (dev->id.sversion == 0xad)) 318c2ecf20Sopenharmony_ci dev->irq = iosapic_serial_irq(dev); 328c2ecf20Sopenharmony_ci#endif 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci if (!dev->irq) { 358c2ecf20Sopenharmony_ci /* We find some unattached serial ports by walking native 368c2ecf20Sopenharmony_ci * busses. These should be silently ignored. Otherwise, 378c2ecf20Sopenharmony_ci * what we have here is a missing parent device, so tell 388c2ecf20Sopenharmony_ci * the user what they're missing. 398c2ecf20Sopenharmony_ci */ 408c2ecf20Sopenharmony_ci if (parisc_parent(dev)->id.hw_type != HPHW_IOA) 418c2ecf20Sopenharmony_ci dev_info(&dev->dev, 428c2ecf20Sopenharmony_ci "Serial: device 0x%llx not configured.\n" 438c2ecf20Sopenharmony_ci "Enable support for Wax, Lasi, Asp or Dino.\n", 448c2ecf20Sopenharmony_ci (unsigned long long)dev->hpa.start); 458c2ecf20Sopenharmony_ci return -ENODEV; 468c2ecf20Sopenharmony_ci } 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci address = dev->hpa.start; 498c2ecf20Sopenharmony_ci if (dev->id.sversion != 0x8d) 508c2ecf20Sopenharmony_ci address += 0x800; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci memset(&uart, 0, sizeof(uart)); 538c2ecf20Sopenharmony_ci uart.port.iotype = UPIO_MEM; 548c2ecf20Sopenharmony_ci /* 7.272727MHz on Lasi. Assumed the same for Dino, Wax and Timi. */ 558c2ecf20Sopenharmony_ci uart.port.uartclk = (dev->id.sversion != 0xad) ? 568c2ecf20Sopenharmony_ci 7272727 : 1843200; 578c2ecf20Sopenharmony_ci uart.port.mapbase = address; 588c2ecf20Sopenharmony_ci uart.port.membase = ioremap(address, 16); 598c2ecf20Sopenharmony_ci if (!uart.port.membase) { 608c2ecf20Sopenharmony_ci dev_warn(&dev->dev, "Failed to map memory\n"); 618c2ecf20Sopenharmony_ci return -ENOMEM; 628c2ecf20Sopenharmony_ci } 638c2ecf20Sopenharmony_ci uart.port.irq = dev->irq; 648c2ecf20Sopenharmony_ci uart.port.flags = UPF_BOOT_AUTOCONF; 658c2ecf20Sopenharmony_ci uart.port.dev = &dev->dev; 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci err = serial8250_register_8250_port(&uart); 688c2ecf20Sopenharmony_ci if (err < 0) { 698c2ecf20Sopenharmony_ci dev_warn(&dev->dev, 708c2ecf20Sopenharmony_ci "serial8250_register_8250_port returned error %d\n", 718c2ecf20Sopenharmony_ci err); 728c2ecf20Sopenharmony_ci iounmap(uart.port.membase); 738c2ecf20Sopenharmony_ci return err; 748c2ecf20Sopenharmony_ci } 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci return 0; 778c2ecf20Sopenharmony_ci} 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_cistatic const struct parisc_device_id serial_tbl[] __initconst = { 808c2ecf20Sopenharmony_ci { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00075 }, 818c2ecf20Sopenharmony_ci { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0008c }, 828c2ecf20Sopenharmony_ci { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0008d }, 838c2ecf20Sopenharmony_ci { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x000ad }, 848c2ecf20Sopenharmony_ci { 0 } 858c2ecf20Sopenharmony_ci}; 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci/* Hack. Some machines have SERIAL_0 attached to Lasi and SERIAL_1 888c2ecf20Sopenharmony_ci * attached to Dino. Unfortunately, Dino appears before Lasi in the device 898c2ecf20Sopenharmony_ci * tree. To ensure that ttyS0 == SERIAL_0, we register two drivers; one 908c2ecf20Sopenharmony_ci * which only knows about Lasi and then a second which will find all the 918c2ecf20Sopenharmony_ci * other serial ports. HPUX ignores this problem. 928c2ecf20Sopenharmony_ci */ 938c2ecf20Sopenharmony_cistatic const struct parisc_device_id lasi_tbl[] __initconst = { 948c2ecf20Sopenharmony_ci { HPHW_FIO, HVERSION_REV_ANY_ID, 0x03B, 0x0008C }, /* C1xx/C1xxL */ 958c2ecf20Sopenharmony_ci { HPHW_FIO, HVERSION_REV_ANY_ID, 0x03C, 0x0008C }, /* B132L */ 968c2ecf20Sopenharmony_ci { HPHW_FIO, HVERSION_REV_ANY_ID, 0x03D, 0x0008C }, /* B160L */ 978c2ecf20Sopenharmony_ci { HPHW_FIO, HVERSION_REV_ANY_ID, 0x03E, 0x0008C }, /* B132L+ */ 988c2ecf20Sopenharmony_ci { HPHW_FIO, HVERSION_REV_ANY_ID, 0x03F, 0x0008C }, /* B180L+ */ 998c2ecf20Sopenharmony_ci { HPHW_FIO, HVERSION_REV_ANY_ID, 0x046, 0x0008C }, /* Rocky2 120 */ 1008c2ecf20Sopenharmony_ci { HPHW_FIO, HVERSION_REV_ANY_ID, 0x047, 0x0008C }, /* Rocky2 150 */ 1018c2ecf20Sopenharmony_ci { HPHW_FIO, HVERSION_REV_ANY_ID, 0x04E, 0x0008C }, /* Kiji L2 132 */ 1028c2ecf20Sopenharmony_ci { HPHW_FIO, HVERSION_REV_ANY_ID, 0x056, 0x0008C }, /* Raven+ */ 1038c2ecf20Sopenharmony_ci { 0 } 1048c2ecf20Sopenharmony_ci}; 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(parisc, serial_tbl); 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_cistatic struct parisc_driver lasi_driver __refdata = { 1108c2ecf20Sopenharmony_ci .name = "serial_1", 1118c2ecf20Sopenharmony_ci .id_table = lasi_tbl, 1128c2ecf20Sopenharmony_ci .probe = serial_init_chip, 1138c2ecf20Sopenharmony_ci}; 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_cistatic struct parisc_driver serial_driver __refdata = { 1168c2ecf20Sopenharmony_ci .name = "serial", 1178c2ecf20Sopenharmony_ci .id_table = serial_tbl, 1188c2ecf20Sopenharmony_ci .probe = serial_init_chip, 1198c2ecf20Sopenharmony_ci}; 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_cistatic int __init probe_serial_gsc(void) 1228c2ecf20Sopenharmony_ci{ 1238c2ecf20Sopenharmony_ci register_parisc_driver(&lasi_driver); 1248c2ecf20Sopenharmony_ci register_parisc_driver(&serial_driver); 1258c2ecf20Sopenharmony_ci return 0; 1268c2ecf20Sopenharmony_ci} 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_cimodule_init(probe_serial_gsc); 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 131