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