led.c 20 KB

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