Lines Matching +full:lcd +full:- +full:backlight
1 // SPDX-License-Identifier: GPL-2.0+
3 * Character LCD driver for Linux
5 * Copyright (C) 2000-2008, Willy Tarreau <w@1wt.eu>
6 * Copyright (C) 2016-2017 Glider bvba
26 /* Keep the backlight on this many seconds for each flash */
29 #define LCD_ESCAPE_LEN 24 /* Max chars for LCD escape command */
33 struct charlcd lcd; member
41 /* contains the LCD config state */
44 /* Current escape sequence and it's length or -1 if outside */
53 #define charlcd_to_priv(p) container_of(p, struct charlcd_priv, lcd)
55 /* Device single-open policy control */
58 /* turn the backlight on or off */
59 void charlcd_backlight(struct charlcd *lcd, enum charlcd_onoff on) in charlcd_backlight() argument
61 struct charlcd_priv *priv = charlcd_to_priv(lcd); in charlcd_backlight()
63 if (!lcd->ops->backlight) in charlcd_backlight()
66 mutex_lock(&priv->bl_tempo_lock); in charlcd_backlight()
67 if (!priv->bl_tempo) in charlcd_backlight()
68 lcd->ops->backlight(lcd, on); in charlcd_backlight()
69 mutex_unlock(&priv->bl_tempo_lock); in charlcd_backlight()
79 mutex_lock(&priv->bl_tempo_lock); in charlcd_bl_off()
80 if (priv->bl_tempo) { in charlcd_bl_off()
81 priv->bl_tempo = false; in charlcd_bl_off()
82 if (!(priv->flags & LCD_FLAG_L)) in charlcd_bl_off()
83 priv->lcd.ops->backlight(&priv->lcd, CHARLCD_OFF); in charlcd_bl_off()
85 mutex_unlock(&priv->bl_tempo_lock); in charlcd_bl_off()
88 /* turn the backlight on for a little while */
89 void charlcd_poke(struct charlcd *lcd) in charlcd_poke() argument
91 struct charlcd_priv *priv = charlcd_to_priv(lcd); in charlcd_poke()
93 if (!lcd->ops->backlight) in charlcd_poke()
96 cancel_delayed_work_sync(&priv->bl_work); in charlcd_poke()
98 mutex_lock(&priv->bl_tempo_lock); in charlcd_poke()
99 if (!priv->bl_tempo && !(priv->flags & LCD_FLAG_L)) in charlcd_poke()
100 lcd->ops->backlight(lcd, CHARLCD_ON); in charlcd_poke()
101 priv->bl_tempo = true; in charlcd_poke()
102 schedule_delayed_work(&priv->bl_work, LCD_BL_TEMPO_PERIOD * HZ); in charlcd_poke()
103 mutex_unlock(&priv->bl_tempo_lock); in charlcd_poke()
107 static void charlcd_home(struct charlcd *lcd) in charlcd_home() argument
109 lcd->addr.x = 0; in charlcd_home()
110 lcd->addr.y = 0; in charlcd_home()
111 lcd->ops->home(lcd); in charlcd_home()
114 static void charlcd_print(struct charlcd *lcd, char c) in charlcd_print() argument
116 if (lcd->addr.x >= lcd->width) in charlcd_print()
119 if (lcd->char_conv) in charlcd_print()
120 c = lcd->char_conv[(unsigned char)c]; in charlcd_print()
122 if (!lcd->ops->print(lcd, c)) in charlcd_print()
123 lcd->addr.x++; in charlcd_print()
126 if (lcd->addr.x == lcd->width) in charlcd_print()
127 lcd->ops->gotoxy(lcd, lcd->addr.x - 1, lcd->addr.y); in charlcd_print()
130 static void charlcd_clear_display(struct charlcd *lcd) in charlcd_clear_display() argument
132 lcd->ops->clear_display(lcd); in charlcd_clear_display()
133 lcd->addr.x = 0; in charlcd_clear_display()
134 lcd->addr.y = 0; in charlcd_clear_display()
139 * any number of subcommands of the form "(x|y)[0-9]+".
145 * - ";" returns (<original x>, <original y>).
146 * - "x1;" returns (1, <original y>).
147 * - "y2x1;" returns (1, 2).
148 * - "x12y34x56;" returns (56, 34).
149 * - "" fails.
150 * - "x" fails.
151 * - "x;" fails.
152 * - "x1" fails.
153 * - "xy12;" fails.
154 * - "x12yy12;" fails.
155 * - "xx" fails.
191 * These are the file operation function for user access to /dev/lcd
197 static inline int handle_lcd_special_code(struct charlcd *lcd) in handle_lcd_special_code() argument
199 struct charlcd_priv *priv = charlcd_to_priv(lcd); in handle_lcd_special_code()
201 /* LCD special codes */ in handle_lcd_special_code()
205 char *esc = priv->esc_seq.buf + 2; in handle_lcd_special_code()
206 int oldflags = priv->flags; in handle_lcd_special_code()
211 priv->flags |= LCD_FLAG_D; in handle_lcd_special_code()
212 if (priv->flags != oldflags) in handle_lcd_special_code()
213 lcd->ops->display(lcd, CHARLCD_ON); in handle_lcd_special_code()
218 priv->flags &= ~LCD_FLAG_D; in handle_lcd_special_code()
219 if (priv->flags != oldflags) in handle_lcd_special_code()
220 lcd->ops->display(lcd, CHARLCD_OFF); in handle_lcd_special_code()
225 priv->flags |= LCD_FLAG_C; in handle_lcd_special_code()
226 if (priv->flags != oldflags) in handle_lcd_special_code()
227 lcd->ops->cursor(lcd, CHARLCD_ON); in handle_lcd_special_code()
232 priv->flags &= ~LCD_FLAG_C; in handle_lcd_special_code()
233 if (priv->flags != oldflags) in handle_lcd_special_code()
234 lcd->ops->cursor(lcd, CHARLCD_OFF); in handle_lcd_special_code()
239 priv->flags |= LCD_FLAG_B; in handle_lcd_special_code()
240 if (priv->flags != oldflags) in handle_lcd_special_code()
241 lcd->ops->blink(lcd, CHARLCD_ON); in handle_lcd_special_code()
246 priv->flags &= ~LCD_FLAG_B; in handle_lcd_special_code()
247 if (priv->flags != oldflags) in handle_lcd_special_code()
248 lcd->ops->blink(lcd, CHARLCD_OFF); in handle_lcd_special_code()
253 priv->flags |= LCD_FLAG_L; in handle_lcd_special_code()
254 if (priv->flags != oldflags) in handle_lcd_special_code()
255 charlcd_backlight(lcd, CHARLCD_ON); in handle_lcd_special_code()
259 case '-': /* Back light OFF */ in handle_lcd_special_code()
260 priv->flags &= ~LCD_FLAG_L; in handle_lcd_special_code()
261 if (priv->flags != oldflags) in handle_lcd_special_code()
262 charlcd_backlight(lcd, CHARLCD_OFF); in handle_lcd_special_code()
267 charlcd_poke(lcd); in handle_lcd_special_code()
271 priv->flags &= ~LCD_FLAG_F; in handle_lcd_special_code()
272 if (priv->flags != oldflags) in handle_lcd_special_code()
273 lcd->ops->fontsize(lcd, CHARLCD_FONTSIZE_SMALL); in handle_lcd_special_code()
278 priv->flags |= LCD_FLAG_F; in handle_lcd_special_code()
279 if (priv->flags != oldflags) in handle_lcd_special_code()
280 lcd->ops->fontsize(lcd, CHARLCD_FONTSIZE_LARGE); in handle_lcd_special_code()
285 priv->flags &= ~LCD_FLAG_N; in handle_lcd_special_code()
286 if (priv->flags != oldflags) in handle_lcd_special_code()
287 lcd->ops->lines(lcd, CHARLCD_LINES_1); in handle_lcd_special_code()
292 priv->flags |= LCD_FLAG_N; in handle_lcd_special_code()
293 if (priv->flags != oldflags) in handle_lcd_special_code()
294 lcd->ops->lines(lcd, CHARLCD_LINES_2); in handle_lcd_special_code()
299 if (lcd->addr.x > 0) { in handle_lcd_special_code()
300 if (!lcd->ops->shift_cursor(lcd, CHARLCD_SHIFT_LEFT)) in handle_lcd_special_code()
301 lcd->addr.x--; in handle_lcd_special_code()
307 if (lcd->addr.x < lcd->width) { in handle_lcd_special_code()
308 if (!lcd->ops->shift_cursor(lcd, CHARLCD_SHIFT_RIGHT)) in handle_lcd_special_code()
309 lcd->addr.x++; in handle_lcd_special_code()
315 lcd->ops->shift_display(lcd, CHARLCD_SHIFT_LEFT); in handle_lcd_special_code()
319 lcd->ops->shift_display(lcd, CHARLCD_SHIFT_RIGHT); in handle_lcd_special_code()
325 xs = lcd->addr.x; in handle_lcd_special_code()
326 ys = lcd->addr.y; in handle_lcd_special_code()
327 for (x = lcd->addr.x; x < lcd->width; x++) in handle_lcd_special_code()
328 lcd->ops->print(lcd, ' '); in handle_lcd_special_code()
331 lcd->addr.x = xs; in handle_lcd_special_code()
332 lcd->addr.y = ys; in handle_lcd_special_code()
333 lcd->ops->gotoxy(lcd, lcd->addr.x, lcd->addr.y); in handle_lcd_special_code()
338 lcd->ops->init_display(lcd); in handle_lcd_special_code()
339 priv->flags = ((lcd->height > 1) ? LCD_FLAG_N : 0) | LCD_FLAG_D | in handle_lcd_special_code()
344 if (lcd->ops->redefine_char) in handle_lcd_special_code()
345 processed = lcd->ops->redefine_char(lcd, esc); in handle_lcd_special_code()
352 if (priv->esc_seq.buf[priv->esc_seq.len - 1] != ';') in handle_lcd_special_code()
356 if (parse_xy(esc, &lcd->addr.x, &lcd->addr.y)) in handle_lcd_special_code()
357 lcd->ops->gotoxy(lcd, lcd->addr.x, lcd->addr.y); in handle_lcd_special_code()
367 static void charlcd_write_char(struct charlcd *lcd, char c) in charlcd_write_char() argument
369 struct charlcd_priv *priv = charlcd_to_priv(lcd); in charlcd_write_char()
372 if ((c != '\n') && priv->esc_seq.len >= 0) { in charlcd_write_char()
374 priv->esc_seq.buf[priv->esc_seq.len++] = c; in charlcd_write_char()
375 priv->esc_seq.buf[priv->esc_seq.len] = '\0'; in charlcd_write_char()
378 priv->esc_seq.len = -1; in charlcd_write_char()
383 priv->esc_seq.len = 0; in charlcd_write_char()
384 priv->esc_seq.buf[priv->esc_seq.len] = '\0'; in charlcd_write_char()
388 if (lcd->addr.x > 0) { in charlcd_write_char()
390 if (!lcd->ops->shift_cursor(lcd, in charlcd_write_char()
392 lcd->addr.x--; in charlcd_write_char()
395 charlcd_print(lcd, ' '); in charlcd_write_char()
397 if (!lcd->ops->shift_cursor(lcd, CHARLCD_SHIFT_LEFT)) in charlcd_write_char()
398 lcd->addr.x--; in charlcd_write_char()
403 charlcd_clear_display(lcd); in charlcd_write_char()
410 for (; lcd->addr.x < lcd->width; lcd->addr.x++) in charlcd_write_char()
411 lcd->ops->print(lcd, ' '); in charlcd_write_char()
413 lcd->addr.x = 0; in charlcd_write_char()
414 lcd->addr.y = (lcd->addr.y + 1) % lcd->height; in charlcd_write_char()
415 lcd->ops->gotoxy(lcd, lcd->addr.x, lcd->addr.y); in charlcd_write_char()
419 lcd->addr.x = 0; in charlcd_write_char()
420 lcd->ops->gotoxy(lcd, lcd->addr.x, lcd->addr.y); in charlcd_write_char()
424 charlcd_print(lcd, ' '); in charlcd_write_char()
428 charlcd_print(lcd, c); in charlcd_write_char()
437 if (priv->esc_seq.len >= 2) { in charlcd_write_char()
440 if (!strcmp(priv->esc_seq.buf, "[2J")) { in charlcd_write_char()
442 charlcd_clear_display(lcd); in charlcd_write_char()
444 } else if (!strcmp(priv->esc_seq.buf, "[H")) { in charlcd_write_char()
446 charlcd_home(lcd); in charlcd_write_char()
450 else if ((priv->esc_seq.len >= 3) && in charlcd_write_char()
451 (priv->esc_seq.buf[0] == '[') && in charlcd_write_char()
452 (priv->esc_seq.buf[1] == 'L')) { in charlcd_write_char()
453 processed = handle_lcd_special_code(lcd); in charlcd_write_char()
456 /* LCD special escape codes */ in charlcd_write_char()
461 if (processed || (priv->esc_seq.len >= LCD_ESCAPE_LEN)) in charlcd_write_char()
462 priv->esc_seq.len = -1; in charlcd_write_char()
474 for (; count-- > 0; (*ppos)++, tmp++) { in charlcd_write()
477 * charlcd_write() is invoked as a VFS->write() callback in charlcd_write()
485 return -EFAULT; in charlcd_write()
490 return tmp - buf; in charlcd_write()
498 ret = -EBUSY; in charlcd_open()
502 ret = -EPERM; in charlcd_open()
503 if (file->f_mode & FMODE_READ) /* device is write-only */ in charlcd_open()
506 if (priv->must_clear) { in charlcd_open()
507 priv->lcd.ops->clear_display(&priv->lcd); in charlcd_open()
508 priv->must_clear = false; in charlcd_open()
509 priv->lcd.addr.x = 0; in charlcd_open()
510 priv->lcd.addr.y = 0; in charlcd_open()
533 .name = "lcd",
537 static void charlcd_puts(struct charlcd *lcd, const char *s) in charlcd_puts() argument
542 for (; count-- > 0; tmp++) { in charlcd_puts()
546 charlcd_write_char(lcd, *tmp); in charlcd_puts()
553 #define LCD_INIT_TEXT "Linux-" UTS_RELEASE "\n"
561 #define LCD_INIT_BL "\x1b[L-"
564 /* initialize the LCD driver */
565 static int charlcd_init(struct charlcd *lcd) in charlcd_init() argument
567 struct charlcd_priv *priv = charlcd_to_priv(lcd); in charlcd_init()
570 priv->flags = ((lcd->height > 1) ? LCD_FLAG_N : 0) | LCD_FLAG_D | in charlcd_init()
572 if (lcd->ops->backlight) { in charlcd_init()
573 mutex_init(&priv->bl_tempo_lock); in charlcd_init()
574 INIT_DELAYED_WORK(&priv->bl_work, charlcd_bl_off); in charlcd_init()
580 * enable mark the LCD initialized just before. in charlcd_init()
582 if (WARN_ON(!lcd->ops->init_display)) in charlcd_init()
583 return -EINVAL; in charlcd_init()
585 ret = lcd->ops->init_display(lcd); in charlcd_init()
590 charlcd_puts(lcd, "\x1b[Lc\x1b[Lb" LCD_INIT_BL LCD_INIT_TEXT); in charlcd_init()
593 priv->must_clear = true; in charlcd_init()
594 charlcd_home(lcd); in charlcd_init()
601 struct charlcd *lcd; in charlcd_alloc() local
607 priv->esc_seq.len = -1; in charlcd_alloc()
609 lcd = &priv->lcd; in charlcd_alloc()
611 return lcd; in charlcd_alloc()
615 void charlcd_free(struct charlcd *lcd) in charlcd_free() argument
617 kfree(charlcd_to_priv(lcd)); in charlcd_free()
624 struct charlcd *lcd = the_charlcd; in panel_notify_sys() local
628 charlcd_puts(lcd, in panel_notify_sys()
632 charlcd_puts(lcd, "\x0cSystem Halted.\x1b[Lc\x1b[Lb\x1b[L+"); in panel_notify_sys()
635 charlcd_puts(lcd, "\x0cPower off.\x1b[Lc\x1b[Lb\x1b[L+"); in panel_notify_sys()
647 int charlcd_register(struct charlcd *lcd) in charlcd_register() argument
651 ret = charlcd_init(lcd); in charlcd_register()
659 the_charlcd = lcd; in charlcd_register()
665 int charlcd_unregister(struct charlcd *lcd) in charlcd_unregister() argument
667 struct charlcd_priv *priv = charlcd_to_priv(lcd); in charlcd_unregister()
670 charlcd_puts(lcd, "\x0cLCD driver unloaded.\x1b[Lc\x1b[Lb\x1b[L-"); in charlcd_unregister()
673 if (lcd->ops->backlight) { in charlcd_unregister()
674 cancel_delayed_work_sync(&priv->bl_work); in charlcd_unregister()
675 priv->lcd.ops->backlight(&priv->lcd, CHARLCD_OFF); in charlcd_unregister()
682 MODULE_DESCRIPTION("Character LCD core support");