led.c 20 KB

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