led.c 20 KB

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