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