led.c 20 KB

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