This source file includes following definitions.
- long_sleep
- charlcd_backlight
- charlcd_bl_off
- charlcd_poke
- charlcd_gotoxy
- charlcd_home
- charlcd_print
- charlcd_clear_fast
- charlcd_clear_display
- charlcd_init_display
- parse_n
- parse_xy
- handle_lcd_special_code
- charlcd_write_char
- charlcd_write
- charlcd_open
- charlcd_release
- charlcd_puts
- charlcd_init
- charlcd_alloc
- charlcd_free
- panel_notify_sys
- charlcd_register
- charlcd_unregister
1
2
3
4
5
6
7
8
9 #include <linux/atomic.h>
10 #include <linux/ctype.h>
11 #include <linux/delay.h>
12 #include <linux/fs.h>
13 #include <linux/miscdevice.h>
14 #include <linux/module.h>
15 #include <linux/notifier.h>
16 #include <linux/reboot.h>
17 #include <linux/slab.h>
18 #include <linux/uaccess.h>
19 #include <linux/workqueue.h>
20
21 #include <generated/utsrelease.h>
22
23 #include "charlcd.h"
24
25 #define LCD_MINOR 156
26
27 #define DEFAULT_LCD_BWIDTH 40
28 #define DEFAULT_LCD_HWIDTH 64
29
30
31 #define LCD_BL_TEMPO_PERIOD 4
32
33 #define LCD_FLAG_B 0x0004
34 #define LCD_FLAG_C 0x0008
35 #define LCD_FLAG_D 0x0010
36 #define LCD_FLAG_F 0x0020
37 #define LCD_FLAG_N 0x0040
38 #define LCD_FLAG_L 0x0080
39
40
41 #define LCD_CMD_DISPLAY_CLEAR 0x01
42
43 #define LCD_CMD_ENTRY_MODE 0x04
44 #define LCD_CMD_CURSOR_INC 0x02
45
46 #define LCD_CMD_DISPLAY_CTRL 0x08
47 #define LCD_CMD_DISPLAY_ON 0x04
48 #define LCD_CMD_CURSOR_ON 0x02
49 #define LCD_CMD_BLINK_ON 0x01
50
51 #define LCD_CMD_SHIFT 0x10
52 #define LCD_CMD_DISPLAY_SHIFT 0x08
53 #define LCD_CMD_SHIFT_RIGHT 0x04
54
55 #define LCD_CMD_FUNCTION_SET 0x20
56 #define LCD_CMD_DATA_LEN_8BITS 0x10
57 #define LCD_CMD_TWO_LINES 0x08
58 #define LCD_CMD_FONT_5X10_DOTS 0x04
59
60 #define LCD_CMD_SET_CGRAM_ADDR 0x40
61
62 #define LCD_CMD_SET_DDRAM_ADDR 0x80
63
64 #define LCD_ESCAPE_LEN 24
65 #define LCD_ESCAPE_CHAR 27
66
67 struct charlcd_priv {
68 struct charlcd lcd;
69
70 struct delayed_work bl_work;
71 struct mutex bl_tempo_lock;
72 bool bl_tempo;
73
74 bool must_clear;
75
76
77 unsigned long int flags;
78
79
80 struct {
81 unsigned long int x;
82 unsigned long int y;
83 } addr;
84
85
86 struct {
87 char buf[LCD_ESCAPE_LEN + 1];
88 int len;
89 } esc_seq;
90
91 unsigned long long drvdata[0];
92 };
93
94 #define charlcd_to_priv(p) container_of(p, struct charlcd_priv, lcd)
95
96
97 static atomic_t charlcd_available = ATOMIC_INIT(1);
98
99
100 static void long_sleep(int ms)
101 {
102 schedule_timeout_interruptible(msecs_to_jiffies(ms));
103 }
104
105
106 static void charlcd_backlight(struct charlcd *lcd, int on)
107 {
108 struct charlcd_priv *priv = charlcd_to_priv(lcd);
109
110 if (!lcd->ops->backlight)
111 return;
112
113 mutex_lock(&priv->bl_tempo_lock);
114 if (!priv->bl_tempo)
115 lcd->ops->backlight(lcd, on);
116 mutex_unlock(&priv->bl_tempo_lock);
117 }
118
119 static void charlcd_bl_off(struct work_struct *work)
120 {
121 struct delayed_work *dwork = to_delayed_work(work);
122 struct charlcd_priv *priv =
123 container_of(dwork, struct charlcd_priv, bl_work);
124
125 mutex_lock(&priv->bl_tempo_lock);
126 if (priv->bl_tempo) {
127 priv->bl_tempo = false;
128 if (!(priv->flags & LCD_FLAG_L))
129 priv->lcd.ops->backlight(&priv->lcd, 0);
130 }
131 mutex_unlock(&priv->bl_tempo_lock);
132 }
133
134
135 void charlcd_poke(struct charlcd *lcd)
136 {
137 struct charlcd_priv *priv = charlcd_to_priv(lcd);
138
139 if (!lcd->ops->backlight)
140 return;
141
142 cancel_delayed_work_sync(&priv->bl_work);
143
144 mutex_lock(&priv->bl_tempo_lock);
145 if (!priv->bl_tempo && !(priv->flags & LCD_FLAG_L))
146 lcd->ops->backlight(lcd, 1);
147 priv->bl_tempo = true;
148 schedule_delayed_work(&priv->bl_work, LCD_BL_TEMPO_PERIOD * HZ);
149 mutex_unlock(&priv->bl_tempo_lock);
150 }
151 EXPORT_SYMBOL_GPL(charlcd_poke);
152
153 static void charlcd_gotoxy(struct charlcd *lcd)
154 {
155 struct charlcd_priv *priv = charlcd_to_priv(lcd);
156 unsigned int addr;
157
158
159
160
161
162 addr = priv->addr.x < lcd->bwidth ? priv->addr.x & (lcd->hwidth - 1)
163 : lcd->bwidth - 1;
164 if (priv->addr.y & 1)
165 addr += lcd->hwidth;
166 if (priv->addr.y & 2)
167 addr += lcd->bwidth;
168 lcd->ops->write_cmd(lcd, LCD_CMD_SET_DDRAM_ADDR | addr);
169 }
170
171 static void charlcd_home(struct charlcd *lcd)
172 {
173 struct charlcd_priv *priv = charlcd_to_priv(lcd);
174
175 priv->addr.x = 0;
176 priv->addr.y = 0;
177 charlcd_gotoxy(lcd);
178 }
179
180 static void charlcd_print(struct charlcd *lcd, char c)
181 {
182 struct charlcd_priv *priv = charlcd_to_priv(lcd);
183
184 if (priv->addr.x < lcd->bwidth) {
185 if (lcd->char_conv)
186 c = lcd->char_conv[(unsigned char)c];
187 lcd->ops->write_data(lcd, c);
188 priv->addr.x++;
189
190
191 if (priv->addr.x == lcd->bwidth)
192 charlcd_gotoxy(lcd);
193 }
194 }
195
196 static void charlcd_clear_fast(struct charlcd *lcd)
197 {
198 int pos;
199
200 charlcd_home(lcd);
201
202 if (lcd->ops->clear_fast)
203 lcd->ops->clear_fast(lcd);
204 else
205 for (pos = 0; pos < min(2, lcd->height) * lcd->hwidth; pos++)
206 lcd->ops->write_data(lcd, ' ');
207
208 charlcd_home(lcd);
209 }
210
211
212 static void charlcd_clear_display(struct charlcd *lcd)
213 {
214 struct charlcd_priv *priv = charlcd_to_priv(lcd);
215
216 lcd->ops->write_cmd(lcd, LCD_CMD_DISPLAY_CLEAR);
217 priv->addr.x = 0;
218 priv->addr.y = 0;
219
220 long_sleep(15);
221 }
222
223 static int charlcd_init_display(struct charlcd *lcd)
224 {
225 void (*write_cmd_raw)(struct charlcd *lcd, int cmd);
226 struct charlcd_priv *priv = charlcd_to_priv(lcd);
227 u8 init;
228
229 if (lcd->ifwidth != 4 && lcd->ifwidth != 8)
230 return -EINVAL;
231
232 priv->flags = ((lcd->height > 1) ? LCD_FLAG_N : 0) | LCD_FLAG_D |
233 LCD_FLAG_C | LCD_FLAG_B;
234
235 long_sleep(20);
236
237
238
239
240
241 init = LCD_CMD_FUNCTION_SET | LCD_CMD_DATA_LEN_8BITS;
242 if (lcd->ifwidth == 4) {
243 init >>= 4;
244 write_cmd_raw = lcd->ops->write_cmd_raw4;
245 } else {
246 write_cmd_raw = lcd->ops->write_cmd;
247 }
248 write_cmd_raw(lcd, init);
249 long_sleep(10);
250 write_cmd_raw(lcd, init);
251 long_sleep(10);
252 write_cmd_raw(lcd, init);
253 long_sleep(10);
254
255 if (lcd->ifwidth == 4) {
256
257 lcd->ops->write_cmd_raw4(lcd, LCD_CMD_FUNCTION_SET >> 4);
258 long_sleep(10);
259 }
260
261
262 lcd->ops->write_cmd(lcd,
263 LCD_CMD_FUNCTION_SET |
264 ((lcd->ifwidth == 8) ? LCD_CMD_DATA_LEN_8BITS : 0) |
265 ((priv->flags & LCD_FLAG_F) ? LCD_CMD_FONT_5X10_DOTS : 0) |
266 ((priv->flags & LCD_FLAG_N) ? LCD_CMD_TWO_LINES : 0));
267 long_sleep(10);
268
269
270 lcd->ops->write_cmd(lcd, LCD_CMD_DISPLAY_CTRL);
271 long_sleep(10);
272
273 lcd->ops->write_cmd(lcd,
274 LCD_CMD_DISPLAY_CTRL |
275 ((priv->flags & LCD_FLAG_D) ? LCD_CMD_DISPLAY_ON : 0) |
276 ((priv->flags & LCD_FLAG_C) ? LCD_CMD_CURSOR_ON : 0) |
277 ((priv->flags & LCD_FLAG_B) ? LCD_CMD_BLINK_ON : 0));
278
279 charlcd_backlight(lcd, (priv->flags & LCD_FLAG_L) ? 1 : 0);
280
281 long_sleep(10);
282
283
284 lcd->ops->write_cmd(lcd, LCD_CMD_ENTRY_MODE | LCD_CMD_CURSOR_INC);
285
286 charlcd_clear_display(lcd);
287 return 0;
288 }
289
290
291
292
293
294
295
296
297
298
299
300 static bool parse_n(const char *s, unsigned long *res, const char **next_s)
301 {
302 if (!isdigit(*s))
303 return false;
304
305 *res = 0;
306 while (isdigit(*s)) {
307 *res = *res * 10 + (*s - '0');
308 ++s;
309 }
310
311 *next_s = s;
312 return true;
313 }
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335 static bool parse_xy(const char *s, unsigned long *x, unsigned long *y)
336 {
337 unsigned long new_x = *x;
338 unsigned long new_y = *y;
339
340 for (;;) {
341 if (!*s)
342 return false;
343
344 if (*s == ';')
345 break;
346
347 if (*s == 'x') {
348 if (!parse_n(s + 1, &new_x, &s))
349 return false;
350 } else if (*s == 'y') {
351 if (!parse_n(s + 1, &new_y, &s))
352 return false;
353 } else {
354 return false;
355 }
356 }
357
358 *x = new_x;
359 *y = new_y;
360 return true;
361 }
362
363
364
365
366
367
368
369
370 static inline int handle_lcd_special_code(struct charlcd *lcd)
371 {
372 struct charlcd_priv *priv = charlcd_to_priv(lcd);
373
374
375
376 int processed = 0;
377
378 char *esc = priv->esc_seq.buf + 2;
379 int oldflags = priv->flags;
380
381
382 switch (*esc) {
383 case 'D':
384 priv->flags |= LCD_FLAG_D;
385 processed = 1;
386 break;
387 case 'd':
388 priv->flags &= ~LCD_FLAG_D;
389 processed = 1;
390 break;
391 case 'C':
392 priv->flags |= LCD_FLAG_C;
393 processed = 1;
394 break;
395 case 'c':
396 priv->flags &= ~LCD_FLAG_C;
397 processed = 1;
398 break;
399 case 'B':
400 priv->flags |= LCD_FLAG_B;
401 processed = 1;
402 break;
403 case 'b':
404 priv->flags &= ~LCD_FLAG_B;
405 processed = 1;
406 break;
407 case '+':
408 priv->flags |= LCD_FLAG_L;
409 processed = 1;
410 break;
411 case '-':
412 priv->flags &= ~LCD_FLAG_L;
413 processed = 1;
414 break;
415 case '*':
416 charlcd_poke(lcd);
417 processed = 1;
418 break;
419 case 'f':
420 priv->flags &= ~LCD_FLAG_F;
421 processed = 1;
422 break;
423 case 'F':
424 priv->flags |= LCD_FLAG_F;
425 processed = 1;
426 break;
427 case 'n':
428 priv->flags &= ~LCD_FLAG_N;
429 processed = 1;
430 break;
431 case 'N':
432 priv->flags |= LCD_FLAG_N;
433 processed = 1;
434 break;
435 case 'l':
436 if (priv->addr.x > 0) {
437
438 if (priv->addr.x < lcd->bwidth)
439 lcd->ops->write_cmd(lcd, LCD_CMD_SHIFT);
440 priv->addr.x--;
441 }
442 processed = 1;
443 break;
444 case 'r':
445 if (priv->addr.x < lcd->width) {
446
447 if (priv->addr.x < (lcd->bwidth - 1))
448 lcd->ops->write_cmd(lcd,
449 LCD_CMD_SHIFT | LCD_CMD_SHIFT_RIGHT);
450 priv->addr.x++;
451 }
452 processed = 1;
453 break;
454 case 'L':
455 lcd->ops->write_cmd(lcd, LCD_CMD_SHIFT | LCD_CMD_DISPLAY_SHIFT);
456 processed = 1;
457 break;
458 case 'R':
459 lcd->ops->write_cmd(lcd,
460 LCD_CMD_SHIFT | LCD_CMD_DISPLAY_SHIFT |
461 LCD_CMD_SHIFT_RIGHT);
462 processed = 1;
463 break;
464 case 'k': {
465 int x;
466
467 for (x = priv->addr.x; x < lcd->bwidth; x++)
468 lcd->ops->write_data(lcd, ' ');
469
470
471 charlcd_gotoxy(lcd);
472 processed = 1;
473 break;
474 }
475 case 'I':
476 charlcd_init_display(lcd);
477 processed = 1;
478 break;
479 case 'G': {
480
481
482
483
484
485
486
487
488 unsigned char cgbytes[8];
489 unsigned char cgaddr;
490 int cgoffset;
491 int shift;
492 char value;
493 int addr;
494
495 if (!strchr(esc, ';'))
496 break;
497
498 esc++;
499
500 cgaddr = *(esc++) - '0';
501 if (cgaddr > 7) {
502 processed = 1;
503 break;
504 }
505
506 cgoffset = 0;
507 shift = 0;
508 value = 0;
509 while (*esc && cgoffset < 8) {
510 shift ^= 4;
511 if (*esc >= '0' && *esc <= '9') {
512 value |= (*esc - '0') << shift;
513 } else if (*esc >= 'A' && *esc <= 'F') {
514 value |= (*esc - 'A' + 10) << shift;
515 } else if (*esc >= 'a' && *esc <= 'f') {
516 value |= (*esc - 'a' + 10) << shift;
517 } else {
518 esc++;
519 continue;
520 }
521
522 if (shift == 0) {
523 cgbytes[cgoffset++] = value;
524 value = 0;
525 }
526
527 esc++;
528 }
529
530 lcd->ops->write_cmd(lcd, LCD_CMD_SET_CGRAM_ADDR | (cgaddr * 8));
531 for (addr = 0; addr < cgoffset; addr++)
532 lcd->ops->write_data(lcd, cgbytes[addr]);
533
534
535 charlcd_gotoxy(lcd);
536 processed = 1;
537 break;
538 }
539 case 'x':
540 case 'y':
541 if (priv->esc_seq.buf[priv->esc_seq.len - 1] != ';')
542 break;
543
544
545 if (parse_xy(esc, &priv->addr.x, &priv->addr.y))
546 charlcd_gotoxy(lcd);
547
548
549 processed = 1;
550 break;
551 }
552
553
554
555 if (oldflags == priv->flags)
556 return processed;
557
558
559 if ((oldflags ^ priv->flags) &
560 (LCD_FLAG_B | LCD_FLAG_C | LCD_FLAG_D))
561
562 lcd->ops->write_cmd(lcd,
563 LCD_CMD_DISPLAY_CTRL |
564 ((priv->flags & LCD_FLAG_D) ? LCD_CMD_DISPLAY_ON : 0) |
565 ((priv->flags & LCD_FLAG_C) ? LCD_CMD_CURSOR_ON : 0) |
566 ((priv->flags & LCD_FLAG_B) ? LCD_CMD_BLINK_ON : 0));
567
568 else if ((oldflags ^ priv->flags) & (LCD_FLAG_F | LCD_FLAG_N))
569 lcd->ops->write_cmd(lcd,
570 LCD_CMD_FUNCTION_SET |
571 ((lcd->ifwidth == 8) ? LCD_CMD_DATA_LEN_8BITS : 0) |
572 ((priv->flags & LCD_FLAG_F) ? LCD_CMD_FONT_5X10_DOTS : 0) |
573 ((priv->flags & LCD_FLAG_N) ? LCD_CMD_TWO_LINES : 0));
574
575 else if ((oldflags ^ priv->flags) & LCD_FLAG_L)
576 charlcd_backlight(lcd, !!(priv->flags & LCD_FLAG_L));
577
578 return processed;
579 }
580
581 static void charlcd_write_char(struct charlcd *lcd, char c)
582 {
583 struct charlcd_priv *priv = charlcd_to_priv(lcd);
584
585
586 if ((c != '\n') && priv->esc_seq.len >= 0) {
587
588 priv->esc_seq.buf[priv->esc_seq.len++] = c;
589 priv->esc_seq.buf[priv->esc_seq.len] = '\0';
590 } else {
591
592 priv->esc_seq.len = -1;
593
594 switch (c) {
595 case LCD_ESCAPE_CHAR:
596
597 priv->esc_seq.len = 0;
598 priv->esc_seq.buf[priv->esc_seq.len] = '\0';
599 break;
600 case '\b':
601
602 if (priv->addr.x > 0) {
603
604
605
606
607 if (priv->addr.x < lcd->bwidth)
608
609 lcd->ops->write_cmd(lcd, LCD_CMD_SHIFT);
610 priv->addr.x--;
611 }
612
613 lcd->ops->write_data(lcd, ' ');
614
615 lcd->ops->write_cmd(lcd, LCD_CMD_SHIFT);
616 break;
617 case '\f':
618
619 charlcd_clear_fast(lcd);
620 break;
621 case '\n':
622
623
624
625
626 for (; priv->addr.x < lcd->bwidth; priv->addr.x++)
627 lcd->ops->write_data(lcd, ' ');
628 priv->addr.x = 0;
629 priv->addr.y = (priv->addr.y + 1) % lcd->height;
630 charlcd_gotoxy(lcd);
631 break;
632 case '\r':
633
634 priv->addr.x = 0;
635 charlcd_gotoxy(lcd);
636 break;
637 case '\t':
638
639 charlcd_print(lcd, ' ');
640 break;
641 default:
642
643 charlcd_print(lcd, c);
644 break;
645 }
646 }
647
648
649
650
651
652 if (priv->esc_seq.len >= 2) {
653 int processed = 0;
654
655 if (!strcmp(priv->esc_seq.buf, "[2J")) {
656
657 charlcd_clear_fast(lcd);
658 processed = 1;
659 } else if (!strcmp(priv->esc_seq.buf, "[H")) {
660
661 charlcd_home(lcd);
662 processed = 1;
663 }
664
665 else if ((priv->esc_seq.len >= 3) &&
666 (priv->esc_seq.buf[0] == '[') &&
667 (priv->esc_seq.buf[1] == 'L')) {
668 processed = handle_lcd_special_code(lcd);
669 }
670
671
672
673
674
675
676 if (processed || (priv->esc_seq.len >= LCD_ESCAPE_LEN))
677 priv->esc_seq.len = -1;
678 }
679 }
680
681 static struct charlcd *the_charlcd;
682
683 static ssize_t charlcd_write(struct file *file, const char __user *buf,
684 size_t count, loff_t *ppos)
685 {
686 const char __user *tmp = buf;
687 char c;
688
689 for (; count-- > 0; (*ppos)++, tmp++) {
690 if (!in_interrupt() && (((count + 1) & 0x1f) == 0))
691
692
693
694
695 schedule();
696
697 if (get_user(c, tmp))
698 return -EFAULT;
699
700 charlcd_write_char(the_charlcd, c);
701 }
702
703 return tmp - buf;
704 }
705
706 static int charlcd_open(struct inode *inode, struct file *file)
707 {
708 struct charlcd_priv *priv = charlcd_to_priv(the_charlcd);
709 int ret;
710
711 ret = -EBUSY;
712 if (!atomic_dec_and_test(&charlcd_available))
713 goto fail;
714
715 ret = -EPERM;
716 if (file->f_mode & FMODE_READ)
717 goto fail;
718
719 if (priv->must_clear) {
720 charlcd_clear_display(&priv->lcd);
721 priv->must_clear = false;
722 }
723 return nonseekable_open(inode, file);
724
725 fail:
726 atomic_inc(&charlcd_available);
727 return ret;
728 }
729
730 static int charlcd_release(struct inode *inode, struct file *file)
731 {
732 atomic_inc(&charlcd_available);
733 return 0;
734 }
735
736 static const struct file_operations charlcd_fops = {
737 .write = charlcd_write,
738 .open = charlcd_open,
739 .release = charlcd_release,
740 .llseek = no_llseek,
741 };
742
743 static struct miscdevice charlcd_dev = {
744 .minor = LCD_MINOR,
745 .name = "lcd",
746 .fops = &charlcd_fops,
747 };
748
749 static void charlcd_puts(struct charlcd *lcd, const char *s)
750 {
751 const char *tmp = s;
752 int count = strlen(s);
753
754 for (; count-- > 0; tmp++) {
755 if (!in_interrupt() && (((count + 1) & 0x1f) == 0))
756
757
758
759
760 schedule();
761
762 charlcd_write_char(lcd, *tmp);
763 }
764 }
765
766 #ifdef CONFIG_PANEL_BOOT_MESSAGE
767 #define LCD_INIT_TEXT CONFIG_PANEL_BOOT_MESSAGE
768 #else
769 #define LCD_INIT_TEXT "Linux-" UTS_RELEASE "\n"
770 #endif
771
772 #ifdef CONFIG_CHARLCD_BL_ON
773 #define LCD_INIT_BL "\x1b[L+"
774 #elif defined(CONFIG_CHARLCD_BL_FLASH)
775 #define LCD_INIT_BL "\x1b[L*"
776 #else
777 #define LCD_INIT_BL "\x1b[L-"
778 #endif
779
780
781 static int charlcd_init(struct charlcd *lcd)
782 {
783 struct charlcd_priv *priv = charlcd_to_priv(lcd);
784 int ret;
785
786 if (lcd->ops->backlight) {
787 mutex_init(&priv->bl_tempo_lock);
788 INIT_DELAYED_WORK(&priv->bl_work, charlcd_bl_off);
789 }
790
791
792
793
794
795
796 ret = charlcd_init_display(lcd);
797 if (ret)
798 return ret;
799
800
801 charlcd_puts(lcd, "\x1b[Lc\x1b[Lb" LCD_INIT_BL LCD_INIT_TEXT);
802
803
804 priv->must_clear = true;
805 charlcd_home(lcd);
806 return 0;
807 }
808
809 struct charlcd *charlcd_alloc(unsigned int drvdata_size)
810 {
811 struct charlcd_priv *priv;
812 struct charlcd *lcd;
813
814 priv = kzalloc(sizeof(*priv) + drvdata_size, GFP_KERNEL);
815 if (!priv)
816 return NULL;
817
818 priv->esc_seq.len = -1;
819
820 lcd = &priv->lcd;
821 lcd->ifwidth = 8;
822 lcd->bwidth = DEFAULT_LCD_BWIDTH;
823 lcd->hwidth = DEFAULT_LCD_HWIDTH;
824 lcd->drvdata = priv->drvdata;
825
826 return lcd;
827 }
828 EXPORT_SYMBOL_GPL(charlcd_alloc);
829
830 void charlcd_free(struct charlcd *lcd)
831 {
832 kfree(charlcd_to_priv(lcd));
833 }
834 EXPORT_SYMBOL_GPL(charlcd_free);
835
836 static int panel_notify_sys(struct notifier_block *this, unsigned long code,
837 void *unused)
838 {
839 struct charlcd *lcd = the_charlcd;
840
841 switch (code) {
842 case SYS_DOWN:
843 charlcd_puts(lcd,
844 "\x0cReloading\nSystem...\x1b[Lc\x1b[Lb\x1b[L+");
845 break;
846 case SYS_HALT:
847 charlcd_puts(lcd, "\x0cSystem Halted.\x1b[Lc\x1b[Lb\x1b[L+");
848 break;
849 case SYS_POWER_OFF:
850 charlcd_puts(lcd, "\x0cPower off.\x1b[Lc\x1b[Lb\x1b[L+");
851 break;
852 default:
853 break;
854 }
855 return NOTIFY_DONE;
856 }
857
858 static struct notifier_block panel_notifier = {
859 panel_notify_sys,
860 NULL,
861 0
862 };
863
864 int charlcd_register(struct charlcd *lcd)
865 {
866 int ret;
867
868 ret = charlcd_init(lcd);
869 if (ret)
870 return ret;
871
872 ret = misc_register(&charlcd_dev);
873 if (ret)
874 return ret;
875
876 the_charlcd = lcd;
877 register_reboot_notifier(&panel_notifier);
878 return 0;
879 }
880 EXPORT_SYMBOL_GPL(charlcd_register);
881
882 int charlcd_unregister(struct charlcd *lcd)
883 {
884 struct charlcd_priv *priv = charlcd_to_priv(lcd);
885
886 unregister_reboot_notifier(&panel_notifier);
887 charlcd_puts(lcd, "\x0cLCD driver unloaded.\x1b[Lc\x1b[Lb\x1b[L-");
888 misc_deregister(&charlcd_dev);
889 the_charlcd = NULL;
890 if (lcd->ops->backlight) {
891 cancel_delayed_work_sync(&priv->bl_work);
892 priv->lcd.ops->backlight(&priv->lcd, 0);
893 }
894
895 return 0;
896 }
897 EXPORT_SYMBOL_GPL(charlcd_unregister);
898
899 MODULE_LICENSE("GPL");