12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds * LASI Device Driver
41da177e4SLinus Torvalds *
51da177e4SLinus Torvalds * (c) Copyright 1999 Red Hat Software
61da177e4SLinus Torvalds * Portions (c) Copyright 1999 The Puffin Group Inc.
71da177e4SLinus Torvalds * Portions (c) Copyright 1999 Hewlett-Packard
81da177e4SLinus Torvalds *
91da177e4SLinus Torvalds * by Alan Cox <alan@redhat.com> and
101da177e4SLinus Torvalds * Alex deVries <alex@onefishtwo.ca>
111da177e4SLinus Torvalds */
121da177e4SLinus Torvalds
131da177e4SLinus Torvalds #include <linux/errno.h>
141da177e4SLinus Torvalds #include <linux/init.h>
151da177e4SLinus Torvalds #include <linux/interrupt.h>
161da177e4SLinus Torvalds #include <linux/slab.h>
171da177e4SLinus Torvalds #include <linux/module.h>
181da177e4SLinus Torvalds #include <linux/pm.h>
191da177e4SLinus Torvalds #include <linux/types.h>
20e71d47dcSHelge Deller #include <linux/reboot.h>
211da177e4SLinus Torvalds
221da177e4SLinus Torvalds #include <asm/io.h>
231da177e4SLinus Torvalds #include <asm/hardware.h>
241da177e4SLinus Torvalds #include <asm/led.h>
251da177e4SLinus Torvalds
261da177e4SLinus Torvalds #include "gsc.h"
271da177e4SLinus Torvalds
281da177e4SLinus Torvalds
291da177e4SLinus Torvalds #define LASI_VER 0xC008 /* LASI Version */
301da177e4SLinus Torvalds
311da177e4SLinus Torvalds #define LASI_IO_CONF 0x7FFFE /* LASI primary configuration register */
321da177e4SLinus Torvalds #define LASI_IO_CONF2 0x7FFFF /* LASI secondary configuration register */
331da177e4SLinus Torvalds
lasi_choose_irq(struct parisc_device * dev,void * ctrl)341da177e4SLinus Torvalds static void lasi_choose_irq(struct parisc_device *dev, void *ctrl)
351da177e4SLinus Torvalds {
361da177e4SLinus Torvalds int irq;
371da177e4SLinus Torvalds
381da177e4SLinus Torvalds switch (dev->id.sversion) {
391da177e4SLinus Torvalds case 0x74: irq = 7; break; /* Centronics */
401da177e4SLinus Torvalds case 0x7B: irq = 13; break; /* Audio */
411da177e4SLinus Torvalds case 0x81: irq = 14; break; /* Lasi itself */
421da177e4SLinus Torvalds case 0x82: irq = 9; break; /* SCSI */
431da177e4SLinus Torvalds case 0x83: irq = 20; break; /* Floppy */
441da177e4SLinus Torvalds case 0x84: irq = 26; break; /* PS/2 Keyboard */
451da177e4SLinus Torvalds case 0x87: irq = 18; break; /* ISDN */
461da177e4SLinus Torvalds case 0x8A: irq = 8; break; /* LAN */
471da177e4SLinus Torvalds case 0x8C: irq = 5; break; /* RS232 */
481da177e4SLinus Torvalds case 0x8D: irq = (dev->hw_path == 13) ? 16 : 17; break;
491da177e4SLinus Torvalds /* Telephone */
501da177e4SLinus Torvalds default: return; /* unknown */
511da177e4SLinus Torvalds }
521da177e4SLinus Torvalds
531da177e4SLinus Torvalds gsc_asic_assign_irq(ctrl, irq, &dev->irq);
541da177e4SLinus Torvalds }
551da177e4SLinus Torvalds
561da177e4SLinus Torvalds static void __init
lasi_init_irq(struct gsc_asic * this_lasi)571da177e4SLinus Torvalds lasi_init_irq(struct gsc_asic *this_lasi)
581da177e4SLinus Torvalds {
591da177e4SLinus Torvalds unsigned long lasi_base = this_lasi->hpa;
601da177e4SLinus Torvalds
611da177e4SLinus Torvalds /* Stop LASI barking for a bit */
621da177e4SLinus Torvalds gsc_writel(0x00000000, lasi_base+OFFSET_IMR);
631da177e4SLinus Torvalds
641da177e4SLinus Torvalds /* clear pending interrupts */
651da177e4SLinus Torvalds gsc_readl(lasi_base+OFFSET_IRR);
661da177e4SLinus Torvalds
671da177e4SLinus Torvalds /* We're not really convinced we want to reset the onboard
681da177e4SLinus Torvalds * devices. Firmware does it for us...
691da177e4SLinus Torvalds */
701da177e4SLinus Torvalds
711da177e4SLinus Torvalds /* Resets */
721da177e4SLinus Torvalds /* gsc_writel(0xFFFFFFFF, lasi_base+0x2000);*/ /* Parallel */
731da177e4SLinus Torvalds if(pdc_add_valid(lasi_base+0x4004) == PDC_OK)
741da177e4SLinus Torvalds gsc_writel(0xFFFFFFFF, lasi_base+0x4004); /* Audio */
751da177e4SLinus Torvalds /* gsc_writel(0xFFFFFFFF, lasi_base+0x5000);*/ /* Serial */
761da177e4SLinus Torvalds /* gsc_writel(0xFFFFFFFF, lasi_base+0x6000);*/ /* SCSI */
771da177e4SLinus Torvalds gsc_writel(0xFFFFFFFF, lasi_base+0x7000); /* LAN */
781da177e4SLinus Torvalds gsc_writel(0xFFFFFFFF, lasi_base+0x8000); /* Keyboard */
791da177e4SLinus Torvalds gsc_writel(0xFFFFFFFF, lasi_base+0xA000); /* FDC */
801da177e4SLinus Torvalds
811da177e4SLinus Torvalds /* Ok we hit it on the head with a hammer, our Dog is now
821da177e4SLinus Torvalds ** comatose and muzzled. Devices will now unmask LASI
831da177e4SLinus Torvalds ** interrupts as they are registered as irq's in the LASI range.
841da177e4SLinus Torvalds */
851da177e4SLinus Torvalds /* XXX: I thought it was `awks that got `it on the `ead with an
861da177e4SLinus Torvalds * `ammer. -- willy
871da177e4SLinus Torvalds */
881da177e4SLinus Torvalds }
891da177e4SLinus Torvalds
901da177e4SLinus Torvalds
911da177e4SLinus Torvalds /*
921da177e4SLinus Torvalds ** lasi_led_init()
931da177e4SLinus Torvalds **
941da177e4SLinus Torvalds ** lasi_led_init() initializes the LED controller on the LASI.
951da177e4SLinus Torvalds **
961da177e4SLinus Torvalds ** Since Mirage and Electra machines use a different LED
971da177e4SLinus Torvalds ** address register, we need to check for these machines
981da177e4SLinus Torvalds ** explicitly.
991da177e4SLinus Torvalds */
1001da177e4SLinus Torvalds
1011da177e4SLinus Torvalds #ifndef CONFIG_CHASSIS_LCD_LED
1021da177e4SLinus Torvalds
1031da177e4SLinus Torvalds #define lasi_led_init(x) /* nothing */
1041da177e4SLinus Torvalds
1051da177e4SLinus Torvalds #else
1061da177e4SLinus Torvalds
lasi_led_init(unsigned long lasi_hpa)107df8e5bc6SAdrian Bunk static void __init lasi_led_init(unsigned long lasi_hpa)
1081da177e4SLinus Torvalds {
1091da177e4SLinus Torvalds unsigned long datareg;
1101da177e4SLinus Torvalds
1111da177e4SLinus Torvalds switch (CPU_HVERSION) {
1121da177e4SLinus Torvalds /* Gecko machines have only one single LED, which can be permanently
1131da177e4SLinus Torvalds turned on by writing a zero into the power control register. */
1141da177e4SLinus Torvalds case 0x600: /* Gecko (712/60) */
1151da177e4SLinus Torvalds case 0x601: /* Gecko (712/80) */
1161da177e4SLinus Torvalds case 0x602: /* Gecko (712/100) */
1171da177e4SLinus Torvalds case 0x603: /* Anole 64 (743/64) */
1181da177e4SLinus Torvalds case 0x604: /* Anole 100 (743/100) */
1191da177e4SLinus Torvalds case 0x605: /* Gecko (712/120) */
1201da177e4SLinus Torvalds datareg = lasi_hpa + 0x0000C000;
1211da177e4SLinus Torvalds gsc_writeb(0, datareg);
1221da177e4SLinus Torvalds return; /* no need to register the LED interrupt-function */
1231da177e4SLinus Torvalds
1241da177e4SLinus Torvalds /* Mirage and Electra machines need special offsets */
1251da177e4SLinus Torvalds case 0x60A: /* Mirage Jr (715/64) */
1261da177e4SLinus Torvalds case 0x60B: /* Mirage 100 */
1271da177e4SLinus Torvalds case 0x60C: /* Mirage 100+ */
1281da177e4SLinus Torvalds case 0x60D: /* Electra 100 */
1291da177e4SLinus Torvalds case 0x60E: /* Electra 120 */
1301da177e4SLinus Torvalds datareg = lasi_hpa - 0x00020000;
1311da177e4SLinus Torvalds break;
1321da177e4SLinus Torvalds
1331da177e4SLinus Torvalds default:
1341da177e4SLinus Torvalds datareg = lasi_hpa + 0x0000C000;
1351da177e4SLinus Torvalds break;
1361da177e4SLinus Torvalds }
1371da177e4SLinus Torvalds
1381da177e4SLinus Torvalds register_led_driver(DISPLAY_MODEL_LASI, LED_CMD_REG_NONE, datareg);
1391da177e4SLinus Torvalds }
1401da177e4SLinus Torvalds #endif
1411da177e4SLinus Torvalds
1421da177e4SLinus Torvalds /*
1431da177e4SLinus Torvalds * lasi_power_off
1441da177e4SLinus Torvalds *
1451da177e4SLinus Torvalds * Function for lasi to turn off the power. This is accomplished by setting a
1461da177e4SLinus Torvalds * 1 to PWR_ON_L in the Power Control Register
1471da177e4SLinus Torvalds *
1481da177e4SLinus Torvalds */
lasi_power_off(struct sys_off_data * data)149e71d47dcSHelge Deller static int lasi_power_off(struct sys_off_data *data)
1501da177e4SLinus Torvalds {
151e71d47dcSHelge Deller struct gsc_asic *lasi = data->cb_data;
1521da177e4SLinus Torvalds
153e71d47dcSHelge Deller /* Power down the machine via Power Control Register */
154e71d47dcSHelge Deller gsc_writel(0x02, lasi->hpa + 0x0000C000);
1551da177e4SLinus Torvalds
156e71d47dcSHelge Deller /* might not be reached: */
157e71d47dcSHelge Deller return NOTIFY_DONE;
1581da177e4SLinus Torvalds }
1591da177e4SLinus Torvalds
lasi_init_chip(struct parisc_device * dev)160df8e5bc6SAdrian Bunk static int __init lasi_init_chip(struct parisc_device *dev)
1611da177e4SLinus Torvalds {
1621da177e4SLinus Torvalds struct gsc_asic *lasi;
1631da177e4SLinus Torvalds int ret;
1641da177e4SLinus Torvalds
165cb6fc18eSHelge Deller lasi = kzalloc(sizeof(*lasi), GFP_KERNEL);
1661da177e4SLinus Torvalds if (!lasi)
1671da177e4SLinus Torvalds return -ENOMEM;
1681da177e4SLinus Torvalds
1691da177e4SLinus Torvalds lasi->name = "Lasi";
17053f01bbaSMatthew Wilcox lasi->hpa = dev->hpa.start;
1711da177e4SLinus Torvalds
1721da177e4SLinus Torvalds /* Check the 4-bit (yes, only 4) version register */
1731da177e4SLinus Torvalds lasi->version = gsc_readl(lasi->hpa + LASI_VER) & 0xf;
1741da177e4SLinus Torvalds printk(KERN_INFO "%s version %d at 0x%lx found.\n",
1751da177e4SLinus Torvalds lasi->name, lasi->version, lasi->hpa);
1761da177e4SLinus Torvalds
1771da177e4SLinus Torvalds /* initialize the chassis LEDs really early */
1781da177e4SLinus Torvalds lasi_led_init(lasi->hpa);
1791da177e4SLinus Torvalds
1801da177e4SLinus Torvalds /* Stop LASI barking for a bit */
1811da177e4SLinus Torvalds lasi_init_irq(lasi);
1821da177e4SLinus Torvalds
1831da177e4SLinus Torvalds /* the IRQ lasi should use */
184939fc856SHelge Deller dev->irq = gsc_alloc_irq(&lasi->gsc_irq);
1851da177e4SLinus Torvalds if (dev->irq < 0) {
1861da177e4SLinus Torvalds printk(KERN_ERR "%s(): cannot get GSC irq\n",
187a8043ecbSHarvey Harrison __func__);
1881da177e4SLinus Torvalds kfree(lasi);
1891da177e4SLinus Torvalds return -EBUSY;
1901da177e4SLinus Torvalds }
1911da177e4SLinus Torvalds
192939fc856SHelge Deller lasi->eim = ((u32) lasi->gsc_irq.txn_addr) | lasi->gsc_irq.txn_data;
1931da177e4SLinus Torvalds
194939fc856SHelge Deller ret = request_irq(lasi->gsc_irq.irq, gsc_asic_intr, 0, "lasi", lasi);
1951da177e4SLinus Torvalds if (ret < 0) {
1961da177e4SLinus Torvalds kfree(lasi);
1971da177e4SLinus Torvalds return ret;
1981da177e4SLinus Torvalds }
1991da177e4SLinus Torvalds
2001da177e4SLinus Torvalds /* enable IRQ's for devices below LASI */
2011da177e4SLinus Torvalds gsc_writel(lasi->eim, lasi->hpa + OFFSET_IAR);
2021da177e4SLinus Torvalds
2031da177e4SLinus Torvalds /* Done init'ing, register this driver */
2041da177e4SLinus Torvalds ret = gsc_common_setup(dev, lasi);
2051da177e4SLinus Torvalds if (ret) {
2061da177e4SLinus Torvalds kfree(lasi);
2071da177e4SLinus Torvalds return ret;
2081da177e4SLinus Torvalds }
2091da177e4SLinus Torvalds
2101da177e4SLinus Torvalds gsc_fixup_irqs(dev, lasi, lasi_choose_irq);
2111da177e4SLinus Torvalds
212e71d47dcSHelge Deller /* register the LASI power off function */
213e71d47dcSHelge Deller register_sys_off_handler(SYS_OFF_MODE_POWER_OFF,
214e71d47dcSHelge Deller SYS_OFF_PRIO_DEFAULT, lasi_power_off, lasi);
2151da177e4SLinus Torvalds
2161da177e4SLinus Torvalds return ret;
2171da177e4SLinus Torvalds }
2181da177e4SLinus Torvalds
219cfe4fbfbSHelge Deller static struct parisc_device_id lasi_tbl[] __initdata = {
2201da177e4SLinus Torvalds { HPHW_BA, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00081 },
2211da177e4SLinus Torvalds { 0, }
2221da177e4SLinus Torvalds };
223*d75ef599SHelge Deller MODULE_DEVICE_TABLE(parisc, lasi_tbl);
2241da177e4SLinus Torvalds
225*d75ef599SHelge Deller static struct parisc_driver lasi_driver __refdata = {
226bdad1f83SMatthew Wilcox .name = "lasi",
2271da177e4SLinus Torvalds .id_table = lasi_tbl,
2281da177e4SLinus Torvalds .probe = lasi_init_chip,
2291da177e4SLinus Torvalds };
230*d75ef599SHelge Deller
lasi_init(void)231*d75ef599SHelge Deller static int __init lasi_init(void)
232*d75ef599SHelge Deller {
233*d75ef599SHelge Deller return register_parisc_driver(&lasi_driver);
234*d75ef599SHelge Deller }
235*d75ef599SHelge Deller arch_initcall(lasi_init);
236