^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Chassis LCD/LED driver for HP-PARISC workstations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * (c) Copyright 2000 Red Hat Software
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * (c) Copyright 2000 Helge Deller <hdeller@redhat.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * (c) Copyright 2001-2009 Helge Deller <deller@gmx.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * (c) Copyright 2001 Randolph Chung <tausq@debian.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * TODO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * - speed-up calculations with inlined assembler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * - interface to write to second row of LCD from /proc (if technically possible)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Changes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * - Audit copy_from_user in led_proc_write.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * Daniele Bellucci <bellucda@tiscali.it>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * - Switch from using a tasklet to a work queue, so the led_LCD_driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * can sleep.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * David Pye <dmp@davidmpye.dyndns.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/stddef.h> /* for offsetof() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/utsname.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/capability.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/inetdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/in.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/kernel_stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <linux/rcupdate.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include <asm/processor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include <asm/hardware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #include <asm/param.h> /* HZ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #include <asm/led.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #include <asm/pdc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) /* The control of the LEDs and LCDs on PARISC-machines have to be done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) completely in software. The necessary calculations are done in a work queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) task which is scheduled regularly, and since the calculations may consume a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) relatively large amount of CPU time, some of the calculations can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) turned off with the following variables (controlled via procfs) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static int led_type __read_mostly = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static unsigned char lastleds; /* LED state from most recent update */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) static unsigned int led_heartbeat __read_mostly = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) static unsigned int led_diskio __read_mostly = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static unsigned int led_lanrxtx __read_mostly = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) static char lcd_text[32] __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static char lcd_text_default[32] __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) static int lcd_no_led_support __read_mostly = 0; /* KittyHawk doesn't support LED on its LCD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) static struct workqueue_struct *led_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static void led_work_func(struct work_struct *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) static DECLARE_DELAYED_WORK(led_task, led_work_func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #define DPRINTK(x) printk x
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #define DPRINTK(x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) struct lcd_block {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) unsigned char command; /* stores the command byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) unsigned char on; /* value for turning LED on */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) unsigned char off; /* value for turning LED off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) /* Structure returned by PDC_RETURN_CHASSIS_INFO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /* NOTE: we use unsigned long:16 two times, since the following member
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) lcd_cmd_reg_addr needs to be 64bit aligned on 64bit PA2.0-machines */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct pdc_chassis_lcd_info_ret_block {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) unsigned long model:16; /* DISPLAY_MODEL_XXXX */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) unsigned long lcd_width:16; /* width of the LCD in chars (DISPLAY_MODEL_LCD only) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) unsigned long lcd_cmd_reg_addr; /* ptr to LCD cmd-register & data ptr for LED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) unsigned long lcd_data_reg_addr; /* ptr to LCD data-register (LCD only) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) unsigned int min_cmd_delay; /* delay in uS after cmd-write (LCD only) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) unsigned char reset_cmd1; /* command #1 for writing LCD string (LCD only) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) unsigned char reset_cmd2; /* command #2 for writing LCD string (LCD only) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) unsigned char act_enable; /* 0 = no activity (LCD only) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct lcd_block heartbeat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct lcd_block disk_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) struct lcd_block lan_rcv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) struct lcd_block lan_tx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) char _pad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) /* LCD_CMD and LCD_DATA for KittyHawk machines */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #define KITTYHAWK_LCD_CMD F_EXTEND(0xf0190000UL) /* 64bit-ready */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #define KITTYHAWK_LCD_DATA (KITTYHAWK_LCD_CMD+1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /* lcd_info is pre-initialized to the values needed to program KittyHawk LCD's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * HP seems to have used Sharp/Hitachi HD44780 LCDs most of the time. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static struct pdc_chassis_lcd_info_ret_block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) lcd_info __attribute__((aligned(8))) __read_mostly =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) .model = DISPLAY_MODEL_LCD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) .lcd_width = 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) .lcd_cmd_reg_addr = KITTYHAWK_LCD_CMD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) .lcd_data_reg_addr = KITTYHAWK_LCD_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) .min_cmd_delay = 80,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) .reset_cmd1 = 0x80,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) .reset_cmd2 = 0xc0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) /* direct access to some of the lcd_info variables */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) #define LCD_CMD_REG lcd_info.lcd_cmd_reg_addr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) #define LCD_DATA_REG lcd_info.lcd_data_reg_addr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) #define LED_DATA_REG lcd_info.lcd_cmd_reg_addr /* LASI & ASP only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) #define LED_HASLCD 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) #define LED_NOLCD 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) /* The workqueue must be created at init-time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static int start_task(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) /* Display the default text now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) if (led_type == LED_HASLCD) lcd_print( lcd_text_default );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) /* KittyHawk has no LED support on its LCD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if (lcd_no_led_support) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) /* Create the work queue and queue the LED task */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) led_wq = create_singlethread_workqueue("led_wq");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) queue_delayed_work(led_wq, &led_task, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) device_initcall(start_task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) /* ptr to LCD/LED-specific function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static void (*led_func_ptr) (unsigned char) __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) #ifdef CONFIG_PROC_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static int led_proc_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) switch ((long)m->private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) case LED_NOLCD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) seq_printf(m, "Heartbeat: %d\n", led_heartbeat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) seq_printf(m, "Disk IO: %d\n", led_diskio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) seq_printf(m, "LAN Rx/Tx: %d\n", led_lanrxtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) case LED_HASLCD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) seq_printf(m, "%s\n", lcd_text);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static int led_proc_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) return single_open(file, led_proc_show, PDE_DATA(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static ssize_t led_proc_write(struct file *file, const char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) size_t count, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) void *data = PDE_DATA(file_inode(file));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) char *cur, lbuf[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) int d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if (!capable(CAP_SYS_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (count >= sizeof(lbuf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) count = sizeof(lbuf)-1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) if (copy_from_user(lbuf, buf, count))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) lbuf[count] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) cur = lbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) switch ((long)data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) case LED_NOLCD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) d = *cur++ - '0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if (d != 0 && d != 1) goto parse_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) led_heartbeat = d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) if (*cur++ != ' ') goto parse_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) d = *cur++ - '0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) if (d != 0 && d != 1) goto parse_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) led_diskio = d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) if (*cur++ != ' ') goto parse_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) d = *cur++ - '0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) if (d != 0 && d != 1) goto parse_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) led_lanrxtx = d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) case LED_HASLCD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) if (*cur && cur[strlen(cur)-1] == '\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) cur[strlen(cur)-1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) if (*cur == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) cur = lcd_text_default;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) lcd_print(cur);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) parse_error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) if ((long)data == LED_NOLCD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) printk(KERN_CRIT "Parse error: expect \"n n n\" (n == 0 or 1) for heartbeat,\ndisk io and lan tx/rx indicators\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) static const struct proc_ops led_proc_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) .proc_open = led_proc_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) .proc_read = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) .proc_lseek = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) .proc_release = single_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) .proc_write = led_proc_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) static int __init led_create_procfs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) struct proc_dir_entry *proc_pdc_root = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) struct proc_dir_entry *ent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) if (led_type == -1) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) proc_pdc_root = proc_mkdir("pdc", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) if (!proc_pdc_root) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) if (!lcd_no_led_support)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) ent = proc_create_data("led", S_IRUGO|S_IWUSR, proc_pdc_root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) &led_proc_ops, (void *)LED_NOLCD); /* LED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (!ent) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) if (led_type == LED_HASLCD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) ent = proc_create_data("lcd", S_IRUGO|S_IWUSR, proc_pdc_root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) &led_proc_ops, (void *)LED_HASLCD); /* LCD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) if (!ent) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) ** led_ASP_driver()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) #define LED_DATA 0x01 /* data to shift (0:on 1:off) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) #define LED_STROBE 0x02 /* strobe to clock data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) static void led_ASP_driver(unsigned char leds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) leds = ~leds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) for (i = 0; i < 8; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) unsigned char value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) value = (leds & 0x80) >> 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) gsc_writeb( value, LED_DATA_REG );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) gsc_writeb( value | LED_STROBE, LED_DATA_REG );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) leds <<= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) ** led_LASI_driver()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) static void led_LASI_driver(unsigned char leds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) leds = ~leds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) gsc_writeb( leds, LED_DATA_REG );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) ** led_LCD_driver()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) static void led_LCD_driver(unsigned char leds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) static int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) static unsigned char mask[4] = { LED_HEARTBEAT, LED_DISK_IO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) LED_LAN_RCV, LED_LAN_TX };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) static struct lcd_block * blockp[4] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) &lcd_info.heartbeat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) &lcd_info.disk_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) &lcd_info.lan_rcv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) &lcd_info.lan_tx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) /* Convert min_cmd_delay to milliseconds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) unsigned int msec_cmd_delay = 1 + (lcd_info.min_cmd_delay / 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) for (i=0; i<4; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) if ((leds & mask[i]) != (lastleds & mask[i]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) gsc_writeb( blockp[i]->command, LCD_CMD_REG );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) msleep(msec_cmd_delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) gsc_writeb( leds & mask[i] ? blockp[i]->on :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) blockp[i]->off, LCD_DATA_REG );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) msleep(msec_cmd_delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) ** led_get_net_activity()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) ** calculate if there was TX- or RX-throughput on the network interfaces
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) ** (analog to dev_get_info() from net/core/dev.c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) static __inline__ int led_get_net_activity(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) #ifndef CONFIG_NET
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) static u64 rx_total_last, tx_total_last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) u64 rx_total, tx_total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) rx_total = tx_total = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) /* we are running as a workqueue task, so we can use an RCU lookup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) for_each_netdev_rcu(&init_net, dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) const struct rtnl_link_stats64 *stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) struct rtnl_link_stats64 temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) struct in_device *in_dev = __in_dev_get_rcu(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) if (!in_dev || !in_dev->ifa_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) if (ipv4_is_loopback(in_dev->ifa_list->ifa_local))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) stats = dev_get_stats(dev, &temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) rx_total += stats->rx_packets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) tx_total += stats->tx_packets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) if (rx_total != rx_total_last) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) rx_total_last = rx_total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) retval |= LED_LAN_RCV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) if (tx_total != tx_total_last) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) tx_total_last = tx_total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) retval |= LED_LAN_TX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) ** led_get_diskio_activity()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) ** calculate if there was disk-io in the system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) static __inline__ int led_get_diskio_activity(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) static unsigned long last_pgpgin, last_pgpgout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) unsigned long events[NR_VM_EVENT_ITEMS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) int changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) all_vm_events(events);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) /* Just use a very simple calculation here. Do not care about overflow,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) since we only want to know if there was activity or not. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) changed = (events[PGPGIN] != last_pgpgin) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) (events[PGPGOUT] != last_pgpgout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) last_pgpgin = events[PGPGIN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) last_pgpgout = events[PGPGOUT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) return (changed ? LED_DISK_IO : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) ** led_work_func()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) ** manages when and which chassis LCD/LED gets updated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) TODO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) - display load average (older machines like 715/64 have 4 "free" LED's for that)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) - optimizations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) #define HEARTBEAT_LEN (HZ*10/100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) #define HEARTBEAT_2ND_RANGE_START (HZ*28/100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) #define HEARTBEAT_2ND_RANGE_END (HEARTBEAT_2ND_RANGE_START + HEARTBEAT_LEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) #define LED_UPDATE_INTERVAL (1 + (HZ*19/1000))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) static void led_work_func (struct work_struct *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) static unsigned long last_jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) static unsigned long count_HZ; /* counter in range 0..HZ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) unsigned char currentleds = 0; /* stores current value of the LEDs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) /* exit if not initialized */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) if (!led_func_ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) /* increment the heartbeat timekeeper */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) count_HZ += jiffies - last_jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) last_jiffies = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) if (count_HZ >= HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) count_HZ = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) if (likely(led_heartbeat))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) /* flash heartbeat-LED like a real heart
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) * (2 x short then a long delay)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) if (count_HZ < HEARTBEAT_LEN ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) (count_HZ >= HEARTBEAT_2ND_RANGE_START &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) count_HZ < HEARTBEAT_2ND_RANGE_END))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) currentleds |= LED_HEARTBEAT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) if (likely(led_lanrxtx)) currentleds |= led_get_net_activity();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) if (likely(led_diskio)) currentleds |= led_get_diskio_activity();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) /* blink LEDs if we got an Oops (HPMC) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) if (unlikely(oops_in_progress)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) if (boot_cpu_data.cpu_type >= pcxl2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) /* newer machines don't have loadavg. LEDs, so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) * let all LEDs blink twice per second instead */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) currentleds = (count_HZ <= (HZ/2)) ? 0 : 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) /* old machines: blink loadavg. LEDs twice per second */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) if (count_HZ <= (HZ/2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) currentleds &= ~(LED4|LED5|LED6|LED7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) currentleds |= (LED4|LED5|LED6|LED7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) if (currentleds != lastleds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) led_func_ptr(currentleds); /* Update the LCD/LEDs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) lastleds = currentleds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) queue_delayed_work(led_wq, &led_task, LED_UPDATE_INTERVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) ** led_halt()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) ** called by the reboot notifier chain at shutdown and stops all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) ** LED/LCD activities.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) static int led_halt(struct notifier_block *, unsigned long, void *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) static struct notifier_block led_notifier = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) .notifier_call = led_halt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) static int notifier_disabled = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) static int led_halt(struct notifier_block *nb, unsigned long event, void *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) char *txt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) if (notifier_disabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) return NOTIFY_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) notifier_disabled = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) case SYS_RESTART: txt = "SYSTEM RESTART";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) case SYS_HALT: txt = "SYSTEM HALT";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) case SYS_POWER_OFF: txt = "SYSTEM POWER OFF";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) default: return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) /* Cancel the work item and delete the queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) if (led_wq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) cancel_delayed_work_sync(&led_task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) destroy_workqueue(led_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) led_wq = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) if (lcd_info.model == DISPLAY_MODEL_LCD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) lcd_print(txt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) if (led_func_ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) led_func_ptr(0xff); /* turn all LEDs ON */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) return NOTIFY_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) ** register_led_driver()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) ** registers an external LED or LCD for usage by this driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) ** currently only LCD-, LASI- and ASP-style LCD/LED's are supported.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) int __init register_led_driver(int model, unsigned long cmd_reg, unsigned long data_reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) static int initialized;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) if (initialized || !data_reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) lcd_info.model = model; /* store the values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) LCD_CMD_REG = (cmd_reg == LED_CMD_REG_NONE) ? 0 : cmd_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) switch (lcd_info.model) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) case DISPLAY_MODEL_LCD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) LCD_DATA_REG = data_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) printk(KERN_INFO "LCD display at %lx,%lx registered\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) LCD_CMD_REG , LCD_DATA_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) led_func_ptr = led_LCD_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) led_type = LED_HASLCD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) case DISPLAY_MODEL_LASI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) /* Skip to register LED in QEMU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) if (running_on_qemu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) LED_DATA_REG = data_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) led_func_ptr = led_LASI_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) printk(KERN_INFO "LED display at %lx registered\n", LED_DATA_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) led_type = LED_NOLCD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) case DISPLAY_MODEL_OLD_ASP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) LED_DATA_REG = data_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) led_func_ptr = led_ASP_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) printk(KERN_INFO "LED (ASP-style) display at %lx registered\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) LED_DATA_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) led_type = LED_NOLCD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) printk(KERN_ERR "%s: Wrong LCD/LED model %d !\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) __func__, lcd_info.model);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) /* mark the LCD/LED driver now as initialized and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) * register to the reboot notifier chain */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) initialized++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) register_reboot_notifier(&led_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) /* Ensure the work is queued */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) if (led_wq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) queue_delayed_work(led_wq, &led_task, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) ** register_led_regions()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) ** register_led_regions() registers the LCD/LED regions for /procfs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) ** At bootup - where the initialisation of the LCD/LED normally happens -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) ** not all internal structures of request_region() are properly set up,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) ** so that we delay the led-registration until after busdevices_init()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) ** has been executed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) void __init register_led_regions(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) switch (lcd_info.model) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) case DISPLAY_MODEL_LCD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) request_mem_region((unsigned long)LCD_CMD_REG, 1, "lcd_cmd");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) request_mem_region((unsigned long)LCD_DATA_REG, 1, "lcd_data");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) case DISPLAY_MODEL_LASI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) case DISPLAY_MODEL_OLD_ASP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) request_mem_region((unsigned long)LED_DATA_REG, 1, "led_data");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) ** lcd_print()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) ** Displays the given string on the LCD-Display of newer machines.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) ** lcd_print() disables/enables the timer-based led work queue to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) ** avoid a race condition while writing the CMD/DATA register pair.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) int lcd_print( const char *str )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) if (!led_func_ptr || lcd_info.model != DISPLAY_MODEL_LCD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) /* temporarily disable the led work task */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) if (led_wq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) cancel_delayed_work_sync(&led_task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) /* copy display string to buffer for procfs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) strlcpy(lcd_text, str, sizeof(lcd_text));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) /* Set LCD Cursor to 1st character */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) gsc_writeb(lcd_info.reset_cmd1, LCD_CMD_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) udelay(lcd_info.min_cmd_delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) /* Print the string */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) for (i=0; i < lcd_info.lcd_width; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) if (str && *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) gsc_writeb(*str++, LCD_DATA_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) gsc_writeb(' ', LCD_DATA_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) udelay(lcd_info.min_cmd_delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) /* re-queue the work */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) if (led_wq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) queue_delayed_work(led_wq, &led_task, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) return lcd_info.lcd_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) ** led_init()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) ** led_init() is called very early in the bootup-process from setup.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) ** and asks the PDC for an usable chassis LCD or LED.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) ** If the PDC doesn't return any info, then the LED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) ** is detected by lasi.c or asp.c and registered with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) ** above functions lasi_led_init() or asp_led_init().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) ** KittyHawk machines have often a buggy PDC, so that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) ** we explicitly check for those machines here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) int __init led_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) struct pdc_chassis_info chassis_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) snprintf(lcd_text_default, sizeof(lcd_text_default),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) "Linux %s", init_utsname()->release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) /* Work around the buggy PDC of KittyHawk-machines */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) switch (CPU_HVERSION) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) case 0x580: /* KittyHawk DC2-100 (K100) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) case 0x581: /* KittyHawk DC3-120 (K210) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) case 0x582: /* KittyHawk DC3 100 (K400) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) case 0x583: /* KittyHawk DC3 120 (K410) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) case 0x58B: /* KittyHawk DC2 100 (K200) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) printk(KERN_INFO "%s: KittyHawk-Machine (hversion 0x%x) found, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) "LED detection skipped.\n", __FILE__, CPU_HVERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) lcd_no_led_support = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) goto found; /* use the preinitialized values of lcd_info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) /* initialize the struct, so that we can check for valid return values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) lcd_info.model = DISPLAY_MODEL_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) chassis_info.actcnt = chassis_info.maxcnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) ret = pdc_chassis_info(&chassis_info, &lcd_info, sizeof(lcd_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) if (ret == PDC_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) DPRINTK((KERN_INFO "%s: chassis info: model=%d (%s), "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) "lcd_width=%d, cmd_delay=%u,\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) "%s: sizecnt=%d, actcnt=%ld, maxcnt=%ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) __FILE__, lcd_info.model,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) (lcd_info.model==DISPLAY_MODEL_LCD) ? "LCD" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) (lcd_info.model==DISPLAY_MODEL_LASI) ? "LED" : "unknown",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) lcd_info.lcd_width, lcd_info.min_cmd_delay,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) __FILE__, sizeof(lcd_info),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) chassis_info.actcnt, chassis_info.maxcnt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) DPRINTK((KERN_INFO "%s: cmd=%p, data=%p, reset1=%x, reset2=%x, act_enable=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) __FILE__, lcd_info.lcd_cmd_reg_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) lcd_info.lcd_data_reg_addr, lcd_info.reset_cmd1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) lcd_info.reset_cmd2, lcd_info.act_enable ));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) /* check the results. Some machines have a buggy PDC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) if (chassis_info.actcnt <= 0 || chassis_info.actcnt != chassis_info.maxcnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) goto not_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) switch (lcd_info.model) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) case DISPLAY_MODEL_LCD: /* LCD display */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) if (chassis_info.actcnt <
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) offsetof(struct pdc_chassis_lcd_info_ret_block, _pad)-1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) goto not_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) if (!lcd_info.act_enable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) DPRINTK((KERN_INFO "PDC prohibited usage of the LCD.\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) goto not_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) case DISPLAY_MODEL_NONE: /* no LED or LCD available */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) printk(KERN_INFO "PDC reported no LCD or LED.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) goto not_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) case DISPLAY_MODEL_LASI: /* Lasi style 8 bit LED display */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) if (chassis_info.actcnt != 8 && chassis_info.actcnt != 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) goto not_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) printk(KERN_WARNING "PDC reported unknown LCD/LED model %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) lcd_info.model);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) goto not_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) } /* switch() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) /* register the LCD/LED driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) register_led_driver(lcd_info.model, LCD_CMD_REG, LCD_DATA_REG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) } else { /* if() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) DPRINTK((KERN_INFO "pdc_chassis_info call failed with retval = %d\n", ret));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) not_found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) lcd_info.model = DISPLAY_MODEL_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) static void __exit led_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) unregister_reboot_notifier(&led_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) #ifdef CONFIG_PROC_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) module_init(led_create_procfs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) #endif