12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds * Chassis LCD/LED driver for HP-PARISC workstations
41da177e4SLinus Torvalds *
51da177e4SLinus Torvalds * (c) Copyright 2000 Red Hat Software
61da177e4SLinus Torvalds * (c) Copyright 2000 Helge Deller <hdeller@redhat.com>
71da177e4SLinus Torvalds * (c) Copyright 2001 Randolph Chung <tausq@debian.org>
8*789e527aSHelge Deller * (c) Copyright 2000-2023 Helge Deller <deller@gmx.de>
91da177e4SLinus Torvalds *
10*789e527aSHelge Deller * The control of the LEDs and LCDs on PARISC machines has to be done
11*789e527aSHelge Deller * completely in software.
121da177e4SLinus Torvalds *
13*789e527aSHelge Deller * The LEDs can be configured at runtime in /sys/class/leds/
141da177e4SLinus Torvalds */
151da177e4SLinus Torvalds
161da177e4SLinus Torvalds #include <linux/module.h>
171da177e4SLinus Torvalds #include <linux/init.h>
181da177e4SLinus Torvalds #include <linux/types.h>
191da177e4SLinus Torvalds #include <linux/ioport.h>
201da177e4SLinus Torvalds #include <linux/utsname.h>
21c59ede7bSRandy.Dunlap #include <linux/capability.h>
221da177e4SLinus Torvalds #include <linux/delay.h>
231da177e4SLinus Torvalds #include <linux/reboot.h>
24*789e527aSHelge Deller #include <linux/uaccess.h>
25*789e527aSHelge Deller #include <linux/leds.h>
26*789e527aSHelge Deller #include <linux/platform_device.h>
27*789e527aSHelge Deller
281da177e4SLinus Torvalds #include <asm/io.h>
291da177e4SLinus Torvalds #include <asm/processor.h>
301da177e4SLinus Torvalds #include <asm/hardware.h>
311da177e4SLinus Torvalds #include <asm/param.h> /* HZ */
321da177e4SLinus Torvalds #include <asm/led.h>
331da177e4SLinus Torvalds #include <asm/pdc.h>
341da177e4SLinus Torvalds
35*789e527aSHelge Deller #define LED_HAS_LCD 1
36*789e527aSHelge Deller #define LED_HAS_LED 2
371da177e4SLinus Torvalds
38*789e527aSHelge Deller static unsigned char led_type; /* bitmask of LED_HAS_XXX */
3934994952SGrant Grundler static unsigned char lastleds; /* LED state from most recent update */
40*789e527aSHelge Deller static unsigned char lcd_new_text;
41*789e527aSHelge Deller static unsigned char lcd_text[20];
42*789e527aSHelge Deller static unsigned char lcd_text_default[20];
43*789e527aSHelge Deller static unsigned char lcd_no_led_support; /* KittyHawk doesn't support LED on its LCD */
441da177e4SLinus Torvalds
451da177e4SLinus Torvalds struct lcd_block {
461da177e4SLinus Torvalds unsigned char command; /* stores the command byte */
471da177e4SLinus Torvalds unsigned char on; /* value for turning LED on */
481da177e4SLinus Torvalds unsigned char off; /* value for turning LED off */
491da177e4SLinus Torvalds };
501da177e4SLinus Torvalds
511da177e4SLinus Torvalds /* Structure returned by PDC_RETURN_CHASSIS_INFO */
521da177e4SLinus Torvalds /* NOTE: we use unsigned long:16 two times, since the following member
531da177e4SLinus Torvalds lcd_cmd_reg_addr needs to be 64bit aligned on 64bit PA2.0-machines */
541da177e4SLinus Torvalds struct pdc_chassis_lcd_info_ret_block {
551da177e4SLinus Torvalds unsigned long model:16; /* DISPLAY_MODEL_XXXX */
561da177e4SLinus Torvalds unsigned long lcd_width:16; /* width of the LCD in chars (DISPLAY_MODEL_LCD only) */
571da177e4SLinus Torvalds unsigned long lcd_cmd_reg_addr; /* ptr to LCD cmd-register & data ptr for LED */
581da177e4SLinus Torvalds unsigned long lcd_data_reg_addr; /* ptr to LCD data-register (LCD only) */
591da177e4SLinus Torvalds unsigned int min_cmd_delay; /* delay in uS after cmd-write (LCD only) */
601da177e4SLinus Torvalds unsigned char reset_cmd1; /* command #1 for writing LCD string (LCD only) */
611da177e4SLinus Torvalds unsigned char reset_cmd2; /* command #2 for writing LCD string (LCD only) */
621da177e4SLinus Torvalds unsigned char act_enable; /* 0 = no activity (LCD only) */
631da177e4SLinus Torvalds struct lcd_block heartbeat;
641da177e4SLinus Torvalds struct lcd_block disk_io;
651da177e4SLinus Torvalds struct lcd_block lan_rcv;
661da177e4SLinus Torvalds struct lcd_block lan_tx;
671da177e4SLinus Torvalds char _pad;
681da177e4SLinus Torvalds };
691da177e4SLinus Torvalds
701da177e4SLinus Torvalds
711da177e4SLinus Torvalds /* LCD_CMD and LCD_DATA for KittyHawk machines */
72*789e527aSHelge Deller #define KITTYHAWK_LCD_CMD F_EXTEND(0xf0190000UL)
731da177e4SLinus Torvalds #define KITTYHAWK_LCD_DATA (KITTYHAWK_LCD_CMD + 1)
741da177e4SLinus Torvalds
751da177e4SLinus Torvalds /* lcd_info is pre-initialized to the values needed to program KittyHawk LCD's
761da177e4SLinus Torvalds * HP seems to have used Sharp/Hitachi HD44780 LCDs most of the time. */
771da177e4SLinus Torvalds static struct pdc_chassis_lcd_info_ret_block
78*789e527aSHelge Deller lcd_info __attribute__((aligned(8))) =
791da177e4SLinus Torvalds {
80*789e527aSHelge Deller .model = DISPLAY_MODEL_NONE,
811da177e4SLinus Torvalds .lcd_width = 16,
821da177e4SLinus Torvalds .lcd_cmd_reg_addr = KITTYHAWK_LCD_CMD,
831da177e4SLinus Torvalds .lcd_data_reg_addr = KITTYHAWK_LCD_DATA,
8479a04296SGuy Martin .min_cmd_delay = 80,
851da177e4SLinus Torvalds .reset_cmd1 = 0x80,
861da177e4SLinus Torvalds .reset_cmd2 = 0xc0,
871da177e4SLinus Torvalds };
881da177e4SLinus Torvalds
891da177e4SLinus Torvalds /* direct access to some of the lcd_info variables */
901da177e4SLinus Torvalds #define LCD_CMD_REG lcd_info.lcd_cmd_reg_addr
911da177e4SLinus Torvalds #define LCD_DATA_REG lcd_info.lcd_data_reg_addr
921da177e4SLinus Torvalds #define LED_DATA_REG lcd_info.lcd_cmd_reg_addr /* LASI & ASP only */
931da177e4SLinus Torvalds
941da177e4SLinus Torvalds /* ptr to LCD/LED-specific function */
95*789e527aSHelge Deller static void (*led_func_ptr) (unsigned char);
961da177e4SLinus Torvalds
97*789e527aSHelge Deller
lcd_print_now(void)98*789e527aSHelge Deller static void lcd_print_now(void)
991da177e4SLinus Torvalds {
100*789e527aSHelge Deller int i;
101*789e527aSHelge Deller char *str = lcd_text;
102*789e527aSHelge Deller
103*789e527aSHelge Deller if (lcd_info.model != DISPLAY_MODEL_LCD)
104*789e527aSHelge Deller return;
105*789e527aSHelge Deller
106*789e527aSHelge Deller if (!lcd_new_text)
107*789e527aSHelge Deller return;
108*789e527aSHelge Deller lcd_new_text = 0;
109*789e527aSHelge Deller
110*789e527aSHelge Deller /* Set LCD Cursor to 1st character */
111*789e527aSHelge Deller gsc_writeb(lcd_info.reset_cmd1, LCD_CMD_REG);
112*789e527aSHelge Deller udelay(lcd_info.min_cmd_delay);
113*789e527aSHelge Deller
114*789e527aSHelge Deller /* Print the string */
115*789e527aSHelge Deller for (i = 0; i < lcd_info.lcd_width; i++) {
116*789e527aSHelge Deller gsc_writeb(*str ? *str++ : ' ', LCD_DATA_REG);
117*789e527aSHelge Deller udelay(lcd_info.min_cmd_delay);
118217bfb51SAlexey Dobriyan }
1191da177e4SLinus Torvalds }
1201da177e4SLinus Torvalds
121*789e527aSHelge Deller /**
122*789e527aSHelge Deller * lcd_print()
123*789e527aSHelge Deller *
124*789e527aSHelge Deller * @str: string to show on the LCD. If NULL, print current string again.
125*789e527aSHelge Deller *
126*789e527aSHelge Deller * Displays the given string on the LCD-Display of newer machines.
1271da177e4SLinus Torvalds */
lcd_print(const char * str)128*789e527aSHelge Deller void lcd_print(const char *str)
129*789e527aSHelge Deller {
130*789e527aSHelge Deller /* copy display string to buffer for procfs */
131*789e527aSHelge Deller if (str)
132*789e527aSHelge Deller strscpy(lcd_text, str, sizeof(lcd_text));
133*789e527aSHelge Deller lcd_new_text = 1;
134*789e527aSHelge Deller
135*789e527aSHelge Deller /* print now if LCD without any LEDs */
136*789e527aSHelge Deller if (led_type == LED_HAS_LCD)
137*789e527aSHelge Deller lcd_print_now();
138*789e527aSHelge Deller }
139*789e527aSHelge Deller
1401da177e4SLinus Torvalds #define LED_DATA 0x01 /* data to shift (0:on 1:off) */
1411da177e4SLinus Torvalds #define LED_STROBE 0x02 /* strobe to clock data */
142*789e527aSHelge Deller
143*789e527aSHelge Deller /**
144*789e527aSHelge Deller * led_ASP_driver() - LED driver for the ASP controller chip
145*789e527aSHelge Deller *
146*789e527aSHelge Deller * @leds: bitmap representing the LED status
147*789e527aSHelge Deller */
led_ASP_driver(unsigned char leds)1481da177e4SLinus Torvalds static void led_ASP_driver(unsigned char leds)
1491da177e4SLinus Torvalds {
1501da177e4SLinus Torvalds int i;
1511da177e4SLinus Torvalds
1521da177e4SLinus Torvalds leds = ~leds;
1531da177e4SLinus Torvalds for (i = 0; i < 8; i++) {
1541da177e4SLinus Torvalds unsigned char value;
1551da177e4SLinus Torvalds value = (leds & 0x80) >> 7;
1561da177e4SLinus Torvalds gsc_writeb( value, LED_DATA_REG );
1571da177e4SLinus Torvalds gsc_writeb( value | LED_STROBE, LED_DATA_REG );
1581da177e4SLinus Torvalds leds <<= 1;
1591da177e4SLinus Torvalds }
1601da177e4SLinus Torvalds }
1611da177e4SLinus Torvalds
162*789e527aSHelge Deller /**
163*789e527aSHelge Deller * led_LASI_driver() - LED driver for the LASI controller chip
164*789e527aSHelge Deller *
165*789e527aSHelge Deller * @leds: bitmap representing the LED status
1661da177e4SLinus Torvalds */
led_LASI_driver(unsigned char leds)1671da177e4SLinus Torvalds static void led_LASI_driver(unsigned char leds)
1681da177e4SLinus Torvalds {
1691da177e4SLinus Torvalds leds = ~leds;
1701da177e4SLinus Torvalds gsc_writeb( leds, LED_DATA_REG );
1711da177e4SLinus Torvalds }
1721da177e4SLinus Torvalds
173*789e527aSHelge Deller /**
174*789e527aSHelge Deller * led_LCD_driver() - LED & LCD driver for LCD chips
175*789e527aSHelge Deller *
176*789e527aSHelge Deller * @leds: bitmap representing the LED status
1771da177e4SLinus Torvalds */
led_LCD_driver(unsigned char leds)1781da177e4SLinus Torvalds static void led_LCD_driver(unsigned char leds)
1791da177e4SLinus Torvalds {
180*789e527aSHelge Deller static const unsigned char mask[4] = {
181*789e527aSHelge Deller LED_HEARTBEAT, LED_DISK_IO,
18234994952SGrant Grundler LED_LAN_RCV, LED_LAN_TX };
1831da177e4SLinus Torvalds
184*789e527aSHelge Deller static struct lcd_block * const blockp[4] = {
18534994952SGrant Grundler &lcd_info.heartbeat,
18634994952SGrant Grundler &lcd_info.disk_io,
18734994952SGrant Grundler &lcd_info.lan_rcv,
18834994952SGrant Grundler &lcd_info.lan_tx
18934994952SGrant Grundler };
190*789e527aSHelge Deller static unsigned char latest_leds;
191*789e527aSHelge Deller int i;
19234994952SGrant Grundler
193*789e527aSHelge Deller for (i = 0; i < 4; ++i) {
194*789e527aSHelge Deller if ((leds & mask[i]) == (latest_leds & mask[i]))
195*789e527aSHelge Deller continue;
19634994952SGrant Grundler
19734994952SGrant Grundler gsc_writeb( blockp[i]->command, LCD_CMD_REG );
198*789e527aSHelge Deller udelay(lcd_info.min_cmd_delay);
19934994952SGrant Grundler
20034994952SGrant Grundler gsc_writeb( leds & mask[i] ? blockp[i]->on :
20134994952SGrant Grundler blockp[i]->off, LCD_DATA_REG );
202*789e527aSHelge Deller udelay(lcd_info.min_cmd_delay);
2031da177e4SLinus Torvalds }
204*789e527aSHelge Deller latest_leds = leds;
205*789e527aSHelge Deller
206*789e527aSHelge Deller lcd_print_now();
2071da177e4SLinus Torvalds }
2081da177e4SLinus Torvalds
2091da177e4SLinus Torvalds
210*789e527aSHelge Deller /**
211*789e527aSHelge Deller * lcd_system_halt()
212*789e527aSHelge Deller *
213*789e527aSHelge Deller * @nb: pointer to the notifier_block structure
214*789e527aSHelge Deller * @event: the event (SYS_RESTART, SYS_HALT or SYS_POWER_OFF)
215*789e527aSHelge Deller * @buf: pointer to a buffer (not used)
216*789e527aSHelge Deller *
217*789e527aSHelge Deller * Called by the reboot notifier chain at shutdown. Stops all
218*789e527aSHelge Deller * LED/LCD activities.
2191da177e4SLinus Torvalds */
lcd_system_halt(struct notifier_block * nb,unsigned long event,void * buf)220*789e527aSHelge Deller static int lcd_system_halt(struct notifier_block *nb, unsigned long event, void *buf)
2211da177e4SLinus Torvalds {
222*789e527aSHelge Deller const char *txt;
2231da177e4SLinus Torvalds
2241da177e4SLinus Torvalds switch (event) {
2251da177e4SLinus Torvalds case SYS_RESTART: txt = "SYSTEM RESTART";
2261da177e4SLinus Torvalds break;
2271da177e4SLinus Torvalds case SYS_HALT: txt = "SYSTEM HALT";
2281da177e4SLinus Torvalds break;
2291da177e4SLinus Torvalds case SYS_POWER_OFF: txt = "SYSTEM POWER OFF";
2301da177e4SLinus Torvalds break;
2311da177e4SLinus Torvalds default: return NOTIFY_DONE;
2321da177e4SLinus Torvalds }
2331da177e4SLinus Torvalds
2341da177e4SLinus Torvalds lcd_print(txt);
2351da177e4SLinus Torvalds
2361da177e4SLinus Torvalds return NOTIFY_OK;
2371da177e4SLinus Torvalds }
2381da177e4SLinus Torvalds
239*789e527aSHelge Deller static struct notifier_block lcd_system_halt_notifier = {
240*789e527aSHelge Deller .notifier_call = lcd_system_halt,
241*789e527aSHelge Deller };
2421da177e4SLinus Torvalds
243*789e527aSHelge Deller static void set_led(struct led_classdev *led_cdev, enum led_brightness brightness);
244*789e527aSHelge Deller
245*789e527aSHelge Deller struct hppa_led {
246*789e527aSHelge Deller struct led_classdev led_cdev;
247*789e527aSHelge Deller unsigned char led_bit;
248*789e527aSHelge Deller };
249*789e527aSHelge Deller #define to_hppa_led(d) container_of(d, struct hppa_led, led_cdev)
250*789e527aSHelge Deller
251*789e527aSHelge Deller typedef void (*set_handler)(struct led_classdev *, enum led_brightness);
252*789e527aSHelge Deller struct led_type {
253*789e527aSHelge Deller const char *name;
254*789e527aSHelge Deller set_handler handler;
255*789e527aSHelge Deller const char *default_trigger;
256*789e527aSHelge Deller };
257*789e527aSHelge Deller
258*789e527aSHelge Deller #define NUM_LEDS_PER_BOARD 8
259*789e527aSHelge Deller struct hppa_drvdata {
260*789e527aSHelge Deller struct hppa_led leds[NUM_LEDS_PER_BOARD];
261*789e527aSHelge Deller };
262*789e527aSHelge Deller
set_led(struct led_classdev * led_cdev,enum led_brightness brightness)263*789e527aSHelge Deller static void set_led(struct led_classdev *led_cdev, enum led_brightness brightness)
264*789e527aSHelge Deller {
265*789e527aSHelge Deller struct hppa_led *p = to_hppa_led(led_cdev);
266*789e527aSHelge Deller unsigned char led_bit = p->led_bit;
267*789e527aSHelge Deller
268*789e527aSHelge Deller if (brightness == LED_OFF)
269*789e527aSHelge Deller lastleds &= ~led_bit;
270*789e527aSHelge Deller else
271*789e527aSHelge Deller lastleds |= led_bit;
272*789e527aSHelge Deller
273*789e527aSHelge Deller if (led_func_ptr)
274*789e527aSHelge Deller led_func_ptr(lastleds);
275*789e527aSHelge Deller }
276*789e527aSHelge Deller
277*789e527aSHelge Deller
hppa_led_generic_probe(struct platform_device * pdev,struct led_type * types)278*789e527aSHelge Deller static int hppa_led_generic_probe(struct platform_device *pdev,
279*789e527aSHelge Deller struct led_type *types)
280*789e527aSHelge Deller {
281*789e527aSHelge Deller struct hppa_drvdata *p;
282*789e527aSHelge Deller int i, err;
283*789e527aSHelge Deller
284*789e527aSHelge Deller p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL);
285*789e527aSHelge Deller if (!p)
286*789e527aSHelge Deller return -ENOMEM;
287*789e527aSHelge Deller
288*789e527aSHelge Deller for (i = 0; i < NUM_LEDS_PER_BOARD; i++) {
289*789e527aSHelge Deller struct led_classdev *lp = &p->leds[i].led_cdev;
290*789e527aSHelge Deller
291*789e527aSHelge Deller p->leds[i].led_bit = BIT(i);
292*789e527aSHelge Deller lp->name = types[i].name;
293*789e527aSHelge Deller lp->brightness = LED_FULL;
294*789e527aSHelge Deller lp->brightness_set = types[i].handler;
295*789e527aSHelge Deller lp->default_trigger = types[i].default_trigger;
296*789e527aSHelge Deller err = led_classdev_register(&pdev->dev, lp);
297*789e527aSHelge Deller if (err) {
298*789e527aSHelge Deller dev_err(&pdev->dev, "Could not register %s LED\n",
299*789e527aSHelge Deller lp->name);
300*789e527aSHelge Deller for (i--; i >= 0; i--)
301*789e527aSHelge Deller led_classdev_unregister(&p->leds[i].led_cdev);
302*789e527aSHelge Deller return err;
303*789e527aSHelge Deller }
304*789e527aSHelge Deller }
305*789e527aSHelge Deller
306*789e527aSHelge Deller platform_set_drvdata(pdev, p);
307*789e527aSHelge Deller
308*789e527aSHelge Deller return 0;
309*789e527aSHelge Deller }
310*789e527aSHelge Deller
platform_led_remove(struct platform_device * pdev)311*789e527aSHelge Deller static int platform_led_remove(struct platform_device *pdev)
312*789e527aSHelge Deller {
313*789e527aSHelge Deller struct hppa_drvdata *p = platform_get_drvdata(pdev);
314*789e527aSHelge Deller int i;
315*789e527aSHelge Deller
316*789e527aSHelge Deller for (i = 0; i < NUM_LEDS_PER_BOARD; i++)
317*789e527aSHelge Deller led_classdev_unregister(&p->leds[i].led_cdev);
318*789e527aSHelge Deller
319*789e527aSHelge Deller return 0;
320*789e527aSHelge Deller }
321*789e527aSHelge Deller
322*789e527aSHelge Deller static struct led_type mainboard_led_types[NUM_LEDS_PER_BOARD] = {
323*789e527aSHelge Deller {
324*789e527aSHelge Deller .name = "platform-lan-tx",
325*789e527aSHelge Deller .handler = set_led,
326*789e527aSHelge Deller .default_trigger = "tx",
327*789e527aSHelge Deller },
328*789e527aSHelge Deller {
329*789e527aSHelge Deller .name = "platform-lan-rx",
330*789e527aSHelge Deller .handler = set_led,
331*789e527aSHelge Deller .default_trigger = "rx",
332*789e527aSHelge Deller },
333*789e527aSHelge Deller {
334*789e527aSHelge Deller .name = "platform-disk",
335*789e527aSHelge Deller .handler = set_led,
336*789e527aSHelge Deller .default_trigger = "disk-activity",
337*789e527aSHelge Deller },
338*789e527aSHelge Deller {
339*789e527aSHelge Deller .name = "platform-heartbeat",
340*789e527aSHelge Deller .handler = set_led,
341*789e527aSHelge Deller .default_trigger = "heartbeat",
342*789e527aSHelge Deller },
343*789e527aSHelge Deller {
344*789e527aSHelge Deller .name = "platform-LED4",
345*789e527aSHelge Deller .handler = set_led,
346*789e527aSHelge Deller .default_trigger = "panic",
347*789e527aSHelge Deller },
348*789e527aSHelge Deller {
349*789e527aSHelge Deller .name = "platform-LED5",
350*789e527aSHelge Deller .handler = set_led,
351*789e527aSHelge Deller .default_trigger = "panic",
352*789e527aSHelge Deller },
353*789e527aSHelge Deller {
354*789e527aSHelge Deller .name = "platform-LED6",
355*789e527aSHelge Deller .handler = set_led,
356*789e527aSHelge Deller .default_trigger = "panic",
357*789e527aSHelge Deller },
358*789e527aSHelge Deller {
359*789e527aSHelge Deller .name = "platform-LED7",
360*789e527aSHelge Deller .handler = set_led,
361*789e527aSHelge Deller .default_trigger = "panic",
362*789e527aSHelge Deller },
363*789e527aSHelge Deller };
364*789e527aSHelge Deller
platform_led_probe(struct platform_device * pdev)365*789e527aSHelge Deller static int platform_led_probe(struct platform_device *pdev)
366*789e527aSHelge Deller {
367*789e527aSHelge Deller return hppa_led_generic_probe(pdev, mainboard_led_types);
368*789e527aSHelge Deller }
369*789e527aSHelge Deller
370*789e527aSHelge Deller MODULE_ALIAS("platform:platform-leds");
371*789e527aSHelge Deller
372*789e527aSHelge Deller static struct platform_driver hppa_mainboard_led_driver = {
373*789e527aSHelge Deller .probe = platform_led_probe,
374*789e527aSHelge Deller .remove = platform_led_remove,
375*789e527aSHelge Deller .driver = {
376*789e527aSHelge Deller .name = "platform-leds",
377*789e527aSHelge Deller },
378*789e527aSHelge Deller };
379*789e527aSHelge Deller
380*789e527aSHelge Deller static struct platform_driver * const drivers[] = {
381*789e527aSHelge Deller &hppa_mainboard_led_driver,
382*789e527aSHelge Deller };
383*789e527aSHelge Deller
384*789e527aSHelge Deller static struct platform_device platform_leds = {
385*789e527aSHelge Deller .name = "platform-leds",
386*789e527aSHelge Deller };
387*789e527aSHelge Deller
388*789e527aSHelge Deller /**
389*789e527aSHelge Deller * register_led_driver()
390*789e527aSHelge Deller *
391*789e527aSHelge Deller * @model: model type, one of the DISPLAY_MODEL_XXXX values
392*789e527aSHelge Deller * @cmd_reg: physical address of cmd register for the LED/LCD
393*789e527aSHelge Deller * @data_reg: physical address of data register for the LED/LCD
394*789e527aSHelge Deller *
395*789e527aSHelge Deller * Registers a chassis LED or LCD which should be driven by this driver.
396*789e527aSHelge Deller * Only PDC-based, LASI- or ASP-style LEDs and LCDs are supported.
397*789e527aSHelge Deller */
register_led_driver(int model,unsigned long cmd_reg,unsigned long data_reg)3981da177e4SLinus Torvalds int __init register_led_driver(int model, unsigned long cmd_reg, unsigned long data_reg)
3991da177e4SLinus Torvalds {
400*789e527aSHelge Deller if (led_func_ptr || !data_reg)
401*789e527aSHelge Deller return 1;
4021da177e4SLinus Torvalds
403*789e527aSHelge Deller /* No LEDs when running in QEMU */
404*789e527aSHelge Deller if (running_on_qemu)
4051da177e4SLinus Torvalds return 1;
4061da177e4SLinus Torvalds
4071da177e4SLinus Torvalds lcd_info.model = model; /* store the values */
4081da177e4SLinus Torvalds LCD_CMD_REG = (cmd_reg == LED_CMD_REG_NONE) ? 0 : cmd_reg;
4091da177e4SLinus Torvalds
4101da177e4SLinus Torvalds switch (lcd_info.model) {
4111da177e4SLinus Torvalds case DISPLAY_MODEL_LCD:
4121da177e4SLinus Torvalds LCD_DATA_REG = data_reg;
413*789e527aSHelge Deller pr_info("led: LCD display at %#lx and %#lx\n",
4141da177e4SLinus Torvalds LCD_CMD_REG , LCD_DATA_REG);
4151da177e4SLinus Torvalds led_func_ptr = led_LCD_driver;
416*789e527aSHelge Deller if (lcd_no_led_support)
417*789e527aSHelge Deller led_type = LED_HAS_LCD;
418*789e527aSHelge Deller else
419*789e527aSHelge Deller led_type = LED_HAS_LCD | LED_HAS_LED;
4201da177e4SLinus Torvalds break;
4211da177e4SLinus Torvalds
4221da177e4SLinus Torvalds case DISPLAY_MODEL_LASI:
4231da177e4SLinus Torvalds LED_DATA_REG = data_reg;
4241da177e4SLinus Torvalds led_func_ptr = led_LASI_driver;
425*789e527aSHelge Deller pr_info("led: LED display at %#lx\n", LED_DATA_REG);
426*789e527aSHelge Deller led_type = LED_HAS_LED;
4271da177e4SLinus Torvalds break;
4281da177e4SLinus Torvalds
4291da177e4SLinus Torvalds case DISPLAY_MODEL_OLD_ASP:
4301da177e4SLinus Torvalds LED_DATA_REG = data_reg;
4311da177e4SLinus Torvalds led_func_ptr = led_ASP_driver;
432*789e527aSHelge Deller pr_info("led: LED (ASP-style) display at %#lx\n",
4331da177e4SLinus Torvalds LED_DATA_REG);
434*789e527aSHelge Deller led_type = LED_HAS_LED;
4351da177e4SLinus Torvalds break;
4361da177e4SLinus Torvalds
4371da177e4SLinus Torvalds default:
438*789e527aSHelge Deller pr_err("led: Unknown LCD/LED model type %d\n", lcd_info.model);
4391da177e4SLinus Torvalds return 1;
4401da177e4SLinus Torvalds }
4411da177e4SLinus Torvalds
442*789e527aSHelge Deller platform_register_drivers(drivers, ARRAY_SIZE(drivers));
4431da177e4SLinus Torvalds
444*789e527aSHelge Deller return register_reboot_notifier(&lcd_system_halt_notifier);
44534994952SGrant Grundler }
4461da177e4SLinus Torvalds
447*789e527aSHelge Deller /**
448*789e527aSHelge Deller * early_led_init()
449*789e527aSHelge Deller *
450*789e527aSHelge Deller * early_led_init() is called early in the bootup-process and asks the
451*789e527aSHelge Deller * PDC for an usable chassis LCD or LED. If the PDC doesn't return any
452*789e527aSHelge Deller * info, then a LED might be detected by the LASI or ASP drivers later.
453*789e527aSHelge Deller * KittyHawk machines have often a buggy PDC, so that we explicitly check
454*789e527aSHelge Deller * for those machines here.
4551da177e4SLinus Torvalds */
early_led_init(void)456*789e527aSHelge Deller static int __init early_led_init(void)
4571da177e4SLinus Torvalds {
4581da177e4SLinus Torvalds struct pdc_chassis_info chassis_info;
4591da177e4SLinus Torvalds int ret;
4601da177e4SLinus Torvalds
4611da177e4SLinus Torvalds snprintf(lcd_text_default, sizeof(lcd_text_default),
46296b644bdSSerge E. Hallyn "Linux %s", init_utsname()->release);
463*789e527aSHelge Deller strcpy(lcd_text, lcd_text_default);
464*789e527aSHelge Deller lcd_new_text = 1;
4651da177e4SLinus Torvalds
4661da177e4SLinus Torvalds /* Work around the buggy PDC of KittyHawk-machines */
4671da177e4SLinus Torvalds switch (CPU_HVERSION) {
4681da177e4SLinus Torvalds case 0x580: /* KittyHawk DC2-100 (K100) */
4691da177e4SLinus Torvalds case 0x581: /* KittyHawk DC3-120 (K210) */
4701da177e4SLinus Torvalds case 0x582: /* KittyHawk DC3 100 (K400) */
4711da177e4SLinus Torvalds case 0x583: /* KittyHawk DC3 120 (K410) */
4721da177e4SLinus Torvalds case 0x58B: /* KittyHawk DC2 100 (K200) */
473*789e527aSHelge Deller pr_info("LCD on KittyHawk-Machine found.\n");
474*789e527aSHelge Deller lcd_info.model = DISPLAY_MODEL_LCD;
475*789e527aSHelge Deller /* KittyHawk has no LED support on its LCD, so skip LED detection */
47679a04296SGuy Martin lcd_no_led_support = 1;
4771da177e4SLinus Torvalds goto found; /* use the preinitialized values of lcd_info */
4781da177e4SLinus Torvalds }
4791da177e4SLinus Torvalds
4801da177e4SLinus Torvalds /* initialize the struct, so that we can check for valid return values */
4811da177e4SLinus Torvalds chassis_info.actcnt = chassis_info.maxcnt = 0;
4821da177e4SLinus Torvalds
4831da177e4SLinus Torvalds ret = pdc_chassis_info(&chassis_info, &lcd_info, sizeof(lcd_info));
484*789e527aSHelge Deller if (ret != PDC_OK) {
485*789e527aSHelge Deller not_found:
486*789e527aSHelge Deller lcd_info.model = DISPLAY_MODEL_NONE;
487*789e527aSHelge Deller return 1;
488*789e527aSHelge Deller }
4891da177e4SLinus Torvalds
4901da177e4SLinus Torvalds /* check the results. Some machines have a buggy PDC */
4911da177e4SLinus Torvalds if (chassis_info.actcnt <= 0 || chassis_info.actcnt != chassis_info.maxcnt)
4921da177e4SLinus Torvalds goto not_found;
4931da177e4SLinus Torvalds
4941da177e4SLinus Torvalds switch (lcd_info.model) {
4951da177e4SLinus Torvalds case DISPLAY_MODEL_LCD: /* LCD display */
4961da177e4SLinus Torvalds if (chassis_info.actcnt <
4971da177e4SLinus Torvalds offsetof(struct pdc_chassis_lcd_info_ret_block, _pad)-1)
4981da177e4SLinus Torvalds goto not_found;
4991da177e4SLinus Torvalds if (!lcd_info.act_enable) {
500*789e527aSHelge Deller /* PDC tells LCD should not be used. */
5011da177e4SLinus Torvalds goto not_found;
5021da177e4SLinus Torvalds }
5031da177e4SLinus Torvalds break;
5041da177e4SLinus Torvalds
5051da177e4SLinus Torvalds case DISPLAY_MODEL_NONE: /* no LED or LCD available */
5061da177e4SLinus Torvalds goto not_found;
5071da177e4SLinus Torvalds
5081da177e4SLinus Torvalds case DISPLAY_MODEL_LASI: /* Lasi style 8 bit LED display */
5091da177e4SLinus Torvalds if (chassis_info.actcnt != 8 && chassis_info.actcnt != 32)
5101da177e4SLinus Torvalds goto not_found;
5111da177e4SLinus Torvalds break;
5121da177e4SLinus Torvalds
5131da177e4SLinus Torvalds default:
514*789e527aSHelge Deller pr_warn("PDC reported unknown LCD/LED model %d\n",
5151da177e4SLinus Torvalds lcd_info.model);
5161da177e4SLinus Torvalds goto not_found;
517*789e527aSHelge Deller }
5181da177e4SLinus Torvalds
5191da177e4SLinus Torvalds found:
5201da177e4SLinus Torvalds /* register the LCD/LED driver */
521*789e527aSHelge Deller return register_led_driver(lcd_info.model, LCD_CMD_REG, LCD_DATA_REG);
5221da177e4SLinus Torvalds }
523*789e527aSHelge Deller arch_initcall(early_led_init);
5241da177e4SLinus Torvalds
525*789e527aSHelge Deller /**
526*789e527aSHelge Deller * register_led_regions()
527*789e527aSHelge Deller *
528*789e527aSHelge Deller * Register_led_regions() registers the LCD/LED regions for /procfs.
529*789e527aSHelge Deller * At bootup - where the initialisation of the LCD/LED often happens
530*789e527aSHelge Deller * not all internal structures of request_region() are properly set up,
531*789e527aSHelge Deller * so that we delay the led-registration until after busdevices_init()
532*789e527aSHelge Deller * has been executed.
533*789e527aSHelge Deller */
register_led_regions(void)534*789e527aSHelge Deller static void __init register_led_regions(void)
535e041c683SAlan Stern {
536*789e527aSHelge Deller switch (lcd_info.model) {
537*789e527aSHelge Deller case DISPLAY_MODEL_LCD:
538*789e527aSHelge Deller request_mem_region((unsigned long)LCD_CMD_REG, 1, "lcd_cmd");
539*789e527aSHelge Deller request_mem_region((unsigned long)LCD_DATA_REG, 1, "lcd_data");
540*789e527aSHelge Deller break;
541*789e527aSHelge Deller case DISPLAY_MODEL_LASI:
542*789e527aSHelge Deller case DISPLAY_MODEL_OLD_ASP:
543*789e527aSHelge Deller request_mem_region((unsigned long)LED_DATA_REG, 1, "led_data");
544*789e527aSHelge Deller break;
545*789e527aSHelge Deller }
546e041c683SAlan Stern }
547e041c683SAlan Stern
startup_leds(void)548*789e527aSHelge Deller static int __init startup_leds(void)
549*789e527aSHelge Deller {
550*789e527aSHelge Deller if (platform_device_register(&platform_leds))
551*789e527aSHelge Deller printk(KERN_INFO "LED: failed to register LEDs\n");
552*789e527aSHelge Deller register_led_regions();
553*789e527aSHelge Deller return 0;
554*789e527aSHelge Deller }
555*789e527aSHelge Deller device_initcall(startup_leds);
556