led.c 20 KB

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