Miguel Ojeda | 351f683b | 2018-02-17 20:33:13 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Character LCD driver for Linux |
| 4 | * |
| 5 | * Copyright (C) 2000-2008, Willy Tarreau <w@1wt.eu> |
| 6 | * Copyright (C) 2016-2017 Glider bvba |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <linux/atomic.h> |
Miguel Ojeda | b34050f | 2018-02-27 23:09:52 +0100 | [diff] [blame] | 10 | #include <linux/ctype.h> |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 11 | #include <linux/fs.h> |
| 12 | #include <linux/miscdevice.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/notifier.h> |
| 15 | #include <linux/reboot.h> |
| 16 | #include <linux/slab.h> |
| 17 | #include <linux/uaccess.h> |
| 18 | #include <linux/workqueue.h> |
| 19 | |
| 20 | #include <generated/utsrelease.h> |
| 21 | |
Masahiro Yamada | 7535428 | 2019-08-06 16:14:44 +0900 | [diff] [blame] | 22 | #include "charlcd.h" |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 23 | |
| 24 | /* Keep the backlight on this many seconds for each flash */ |
| 25 | #define LCD_BL_TEMPO_PERIOD 4 |
| 26 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 27 | #define LCD_ESCAPE_LEN 24 /* Max chars for LCD escape command */ |
| 28 | #define LCD_ESCAPE_CHAR 27 /* Use char 27 for escape command */ |
| 29 | |
| 30 | struct charlcd_priv { |
| 31 | struct charlcd lcd; |
| 32 | |
| 33 | struct delayed_work bl_work; |
| 34 | struct mutex bl_tempo_lock; /* Protects access to bl_tempo */ |
| 35 | bool bl_tempo; |
| 36 | |
| 37 | bool must_clear; |
| 38 | |
| 39 | /* contains the LCD config state */ |
| 40 | unsigned long int flags; |
| 41 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 42 | /* Current escape sequence and it's length or -1 if outside */ |
| 43 | struct { |
| 44 | char buf[LCD_ESCAPE_LEN + 1]; |
| 45 | int len; |
| 46 | } esc_seq; |
| 47 | |
Gustavo A. R. Silva | 2f920c0 | 2020-02-12 13:52:31 -0600 | [diff] [blame] | 48 | unsigned long long drvdata[]; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 49 | }; |
| 50 | |
Andy Shevchenko | b658a21 | 2019-03-12 16:44:29 +0200 | [diff] [blame] | 51 | #define charlcd_to_priv(p) container_of(p, struct charlcd_priv, lcd) |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 52 | |
| 53 | /* Device single-open policy control */ |
| 54 | static atomic_t charlcd_available = ATOMIC_INIT(1); |
| 55 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 56 | /* turn the backlight on or off */ |
Lars Poeschel | 2bf82b5 | 2020-11-03 10:58:15 +0100 | [diff] [blame] | 57 | void charlcd_backlight(struct charlcd *lcd, enum charlcd_onoff on) |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 58 | { |
Andy Shevchenko | b658a21 | 2019-03-12 16:44:29 +0200 | [diff] [blame] | 59 | struct charlcd_priv *priv = charlcd_to_priv(lcd); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 60 | |
| 61 | if (!lcd->ops->backlight) |
| 62 | return; |
| 63 | |
| 64 | mutex_lock(&priv->bl_tempo_lock); |
| 65 | if (!priv->bl_tempo) |
| 66 | lcd->ops->backlight(lcd, on); |
| 67 | mutex_unlock(&priv->bl_tempo_lock); |
| 68 | } |
Lars Poeschel | 2bf82b5 | 2020-11-03 10:58:15 +0100 | [diff] [blame] | 69 | EXPORT_SYMBOL_GPL(charlcd_backlight); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 70 | |
| 71 | static void charlcd_bl_off(struct work_struct *work) |
| 72 | { |
| 73 | struct delayed_work *dwork = to_delayed_work(work); |
| 74 | struct charlcd_priv *priv = |
| 75 | container_of(dwork, struct charlcd_priv, bl_work); |
| 76 | |
| 77 | mutex_lock(&priv->bl_tempo_lock); |
| 78 | if (priv->bl_tempo) { |
| 79 | priv->bl_tempo = false; |
| 80 | if (!(priv->flags & LCD_FLAG_L)) |
Lars Poeschel | bd26b18 | 2020-11-03 10:58:16 +0100 | [diff] [blame] | 81 | priv->lcd.ops->backlight(&priv->lcd, CHARLCD_OFF); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 82 | } |
| 83 | mutex_unlock(&priv->bl_tempo_lock); |
| 84 | } |
| 85 | |
| 86 | /* turn the backlight on for a little while */ |
| 87 | void charlcd_poke(struct charlcd *lcd) |
| 88 | { |
Andy Shevchenko | b658a21 | 2019-03-12 16:44:29 +0200 | [diff] [blame] | 89 | struct charlcd_priv *priv = charlcd_to_priv(lcd); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 90 | |
| 91 | if (!lcd->ops->backlight) |
| 92 | return; |
| 93 | |
| 94 | cancel_delayed_work_sync(&priv->bl_work); |
| 95 | |
| 96 | mutex_lock(&priv->bl_tempo_lock); |
| 97 | if (!priv->bl_tempo && !(priv->flags & LCD_FLAG_L)) |
Lars Poeschel | bd26b18 | 2020-11-03 10:58:16 +0100 | [diff] [blame] | 98 | lcd->ops->backlight(lcd, CHARLCD_ON); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 99 | priv->bl_tempo = true; |
| 100 | schedule_delayed_work(&priv->bl_work, LCD_BL_TEMPO_PERIOD * HZ); |
| 101 | mutex_unlock(&priv->bl_tempo_lock); |
| 102 | } |
| 103 | EXPORT_SYMBOL_GPL(charlcd_poke); |
| 104 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 105 | static void charlcd_home(struct charlcd *lcd) |
| 106 | { |
Lars Poeschel | 11588b5 | 2020-11-03 10:58:10 +0100 | [diff] [blame] | 107 | lcd->addr.x = 0; |
| 108 | lcd->addr.y = 0; |
Lars Poeschel | 88645a8 | 2020-11-03 10:58:13 +0100 | [diff] [blame] | 109 | lcd->ops->home(lcd); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | static void charlcd_print(struct charlcd *lcd, char c) |
| 113 | { |
Lars Poeschel | af9470b | 2020-11-03 10:58:26 +0100 | [diff] [blame] | 114 | if (lcd->addr.x >= lcd->width) |
| 115 | return; |
| 116 | |
Lars Poeschel | b26deab | 2020-11-03 10:58:11 +0100 | [diff] [blame] | 117 | if (lcd->char_conv) |
| 118 | c = lcd->char_conv[(unsigned char)c]; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 119 | |
Lars Poeschel | b26deab | 2020-11-03 10:58:11 +0100 | [diff] [blame] | 120 | if (!lcd->ops->print(lcd, c)) |
Lars Poeschel | 11588b5 | 2020-11-03 10:58:10 +0100 | [diff] [blame] | 121 | lcd->addr.x++; |
Sean Young | 54bc937f | 2018-01-15 09:43:48 +0000 | [diff] [blame] | 122 | |
Lars Poeschel | b26deab | 2020-11-03 10:58:11 +0100 | [diff] [blame] | 123 | /* prevents the cursor from wrapping onto the next line */ |
Lars Poeschel | 6e49eea | 2020-11-03 10:58:24 +0100 | [diff] [blame] | 124 | if (lcd->addr.x == lcd->width) |
Lars Poeschel | 40c2b72 | 2020-11-03 10:58:25 +0100 | [diff] [blame] | 125 | lcd->ops->gotoxy(lcd, lcd->addr.x - 1, lcd->addr.y); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 126 | } |
| 127 | |
Lars Poeschel | 377cf2c | 2020-11-03 10:58:23 +0100 | [diff] [blame] | 128 | static void charlcd_clear_display(struct charlcd *lcd) |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 129 | { |
Lars Poeschel | 377cf2c | 2020-11-03 10:58:23 +0100 | [diff] [blame] | 130 | lcd->ops->clear_display(lcd); |
| 131 | lcd->addr.x = 0; |
| 132 | lcd->addr.y = 0; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 133 | } |
| 134 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 135 | /* |
Miguel Ojeda | b34050f | 2018-02-27 23:09:52 +0100 | [diff] [blame] | 136 | * Parses a movement command of the form "(.*);", where the group can be |
| 137 | * any number of subcommands of the form "(x|y)[0-9]+". |
| 138 | * |
| 139 | * Returns whether the command is valid. The position arguments are |
| 140 | * only written if the parsing was successful. |
| 141 | * |
| 142 | * For instance: |
| 143 | * - ";" returns (<original x>, <original y>). |
| 144 | * - "x1;" returns (1, <original y>). |
| 145 | * - "y2x1;" returns (1, 2). |
| 146 | * - "x12y34x56;" returns (56, 34). |
| 147 | * - "" fails. |
| 148 | * - "x" fails. |
| 149 | * - "x;" fails. |
| 150 | * - "x1" fails. |
| 151 | * - "xy12;" fails. |
| 152 | * - "x12yy12;" fails. |
| 153 | * - "xx" fails. |
| 154 | */ |
| 155 | static bool parse_xy(const char *s, unsigned long *x, unsigned long *y) |
| 156 | { |
| 157 | unsigned long new_x = *x; |
| 158 | unsigned long new_y = *y; |
Andy Shevchenko | d717e7d | 2019-12-04 16:50:36 -0800 | [diff] [blame] | 159 | char *p; |
Miguel Ojeda | b34050f | 2018-02-27 23:09:52 +0100 | [diff] [blame] | 160 | |
| 161 | for (;;) { |
| 162 | if (!*s) |
| 163 | return false; |
| 164 | |
| 165 | if (*s == ';') |
| 166 | break; |
| 167 | |
| 168 | if (*s == 'x') { |
Andy Shevchenko | d717e7d | 2019-12-04 16:50:36 -0800 | [diff] [blame] | 169 | new_x = simple_strtoul(s + 1, &p, 10); |
| 170 | if (p == s + 1) |
Miguel Ojeda | b34050f | 2018-02-27 23:09:52 +0100 | [diff] [blame] | 171 | return false; |
Andy Shevchenko | d717e7d | 2019-12-04 16:50:36 -0800 | [diff] [blame] | 172 | s = p; |
Miguel Ojeda | b34050f | 2018-02-27 23:09:52 +0100 | [diff] [blame] | 173 | } else if (*s == 'y') { |
Andy Shevchenko | d717e7d | 2019-12-04 16:50:36 -0800 | [diff] [blame] | 174 | new_y = simple_strtoul(s + 1, &p, 10); |
| 175 | if (p == s + 1) |
Miguel Ojeda | b34050f | 2018-02-27 23:09:52 +0100 | [diff] [blame] | 176 | return false; |
Andy Shevchenko | d717e7d | 2019-12-04 16:50:36 -0800 | [diff] [blame] | 177 | s = p; |
Miguel Ojeda | b34050f | 2018-02-27 23:09:52 +0100 | [diff] [blame] | 178 | } else { |
| 179 | return false; |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | *x = new_x; |
| 184 | *y = new_y; |
| 185 | return true; |
| 186 | } |
| 187 | |
| 188 | /* |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 189 | * These are the file operation function for user access to /dev/lcd |
| 190 | * This function can also be called from inside the kernel, by |
| 191 | * setting file and ppos to NULL. |
| 192 | * |
| 193 | */ |
| 194 | |
| 195 | static inline int handle_lcd_special_code(struct charlcd *lcd) |
| 196 | { |
Andy Shevchenko | b658a21 | 2019-03-12 16:44:29 +0200 | [diff] [blame] | 197 | struct charlcd_priv *priv = charlcd_to_priv(lcd); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 198 | |
| 199 | /* LCD special codes */ |
| 200 | |
| 201 | int processed = 0; |
| 202 | |
| 203 | char *esc = priv->esc_seq.buf + 2; |
| 204 | int oldflags = priv->flags; |
| 205 | |
| 206 | /* check for display mode flags */ |
| 207 | switch (*esc) { |
| 208 | case 'D': /* Display ON */ |
| 209 | priv->flags |= LCD_FLAG_D; |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 210 | if (priv->flags != oldflags) |
| 211 | lcd->ops->display(lcd, CHARLCD_ON); |
| 212 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 213 | processed = 1; |
| 214 | break; |
| 215 | case 'd': /* Display OFF */ |
| 216 | priv->flags &= ~LCD_FLAG_D; |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 217 | if (priv->flags != oldflags) |
| 218 | lcd->ops->display(lcd, CHARLCD_OFF); |
| 219 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 220 | processed = 1; |
| 221 | break; |
| 222 | case 'C': /* Cursor ON */ |
| 223 | priv->flags |= LCD_FLAG_C; |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 224 | if (priv->flags != oldflags) |
| 225 | lcd->ops->cursor(lcd, CHARLCD_ON); |
| 226 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 227 | processed = 1; |
| 228 | break; |
| 229 | case 'c': /* Cursor OFF */ |
| 230 | priv->flags &= ~LCD_FLAG_C; |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 231 | if (priv->flags != oldflags) |
| 232 | lcd->ops->cursor(lcd, CHARLCD_OFF); |
| 233 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 234 | processed = 1; |
| 235 | break; |
| 236 | case 'B': /* Blink ON */ |
| 237 | priv->flags |= LCD_FLAG_B; |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 238 | if (priv->flags != oldflags) |
| 239 | lcd->ops->blink(lcd, CHARLCD_ON); |
| 240 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 241 | processed = 1; |
| 242 | break; |
| 243 | case 'b': /* Blink OFF */ |
| 244 | priv->flags &= ~LCD_FLAG_B; |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 245 | if (priv->flags != oldflags) |
| 246 | lcd->ops->blink(lcd, CHARLCD_OFF); |
| 247 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 248 | processed = 1; |
| 249 | break; |
| 250 | case '+': /* Back light ON */ |
| 251 | priv->flags |= LCD_FLAG_L; |
Lars Poeschel | a2060f2 | 2020-11-03 10:58:21 +0100 | [diff] [blame] | 252 | if (priv->flags != oldflags) |
| 253 | charlcd_backlight(lcd, CHARLCD_ON); |
| 254 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 255 | processed = 1; |
| 256 | break; |
| 257 | case '-': /* Back light OFF */ |
| 258 | priv->flags &= ~LCD_FLAG_L; |
Lars Poeschel | a2060f2 | 2020-11-03 10:58:21 +0100 | [diff] [blame] | 259 | if (priv->flags != oldflags) |
| 260 | charlcd_backlight(lcd, CHARLCD_OFF); |
| 261 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 262 | processed = 1; |
| 263 | break; |
| 264 | case '*': /* Flash back light */ |
| 265 | charlcd_poke(lcd); |
| 266 | processed = 1; |
| 267 | break; |
| 268 | case 'f': /* Small Font */ |
| 269 | priv->flags &= ~LCD_FLAG_F; |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 270 | if (priv->flags != oldflags) |
| 271 | lcd->ops->fontsize(lcd, CHARLCD_FONTSIZE_SMALL); |
| 272 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 273 | processed = 1; |
| 274 | break; |
| 275 | case 'F': /* Large Font */ |
| 276 | priv->flags |= LCD_FLAG_F; |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 277 | if (priv->flags != oldflags) |
| 278 | lcd->ops->fontsize(lcd, CHARLCD_FONTSIZE_LARGE); |
| 279 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 280 | processed = 1; |
| 281 | break; |
| 282 | case 'n': /* One Line */ |
| 283 | priv->flags &= ~LCD_FLAG_N; |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 284 | if (priv->flags != oldflags) |
| 285 | lcd->ops->lines(lcd, CHARLCD_LINES_1); |
| 286 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 287 | processed = 1; |
| 288 | break; |
| 289 | case 'N': /* Two Lines */ |
| 290 | priv->flags |= LCD_FLAG_N; |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 291 | if (priv->flags != oldflags) |
| 292 | lcd->ops->lines(lcd, CHARLCD_LINES_2); |
| 293 | |
Robert Abel | 99b9b49 | 2018-02-26 00:54:29 +0100 | [diff] [blame] | 294 | processed = 1; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 295 | break; |
| 296 | case 'l': /* Shift Cursor Left */ |
Lars Poeschel | 11588b5 | 2020-11-03 10:58:10 +0100 | [diff] [blame] | 297 | if (lcd->addr.x > 0) { |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 298 | if (!lcd->ops->shift_cursor(lcd, CHARLCD_SHIFT_LEFT)) |
| 299 | lcd->addr.x--; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 300 | } |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 301 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 302 | processed = 1; |
| 303 | break; |
| 304 | case 'r': /* shift cursor right */ |
Lars Poeschel | 11588b5 | 2020-11-03 10:58:10 +0100 | [diff] [blame] | 305 | if (lcd->addr.x < lcd->width) { |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 306 | if (!lcd->ops->shift_cursor(lcd, CHARLCD_SHIFT_RIGHT)) |
| 307 | lcd->addr.x++; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 308 | } |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 309 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 310 | processed = 1; |
| 311 | break; |
| 312 | case 'L': /* shift display left */ |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 313 | lcd->ops->shift_display(lcd, CHARLCD_SHIFT_LEFT); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 314 | processed = 1; |
| 315 | break; |
| 316 | case 'R': /* shift display right */ |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 317 | lcd->ops->shift_display(lcd, CHARLCD_SHIFT_RIGHT); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 318 | processed = 1; |
| 319 | break; |
| 320 | case 'k': { /* kill end of line */ |
Lars Poeschel | b26deab | 2020-11-03 10:58:11 +0100 | [diff] [blame] | 321 | int x, xs, ys; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 322 | |
Lars Poeschel | b26deab | 2020-11-03 10:58:11 +0100 | [diff] [blame] | 323 | xs = lcd->addr.x; |
| 324 | ys = lcd->addr.y; |
Lars Poeschel | 6e49eea | 2020-11-03 10:58:24 +0100 | [diff] [blame] | 325 | for (x = lcd->addr.x; x < lcd->width; x++) |
Lars Poeschel | b26deab | 2020-11-03 10:58:11 +0100 | [diff] [blame] | 326 | lcd->ops->print(lcd, ' '); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 327 | |
| 328 | /* restore cursor position */ |
Lars Poeschel | b26deab | 2020-11-03 10:58:11 +0100 | [diff] [blame] | 329 | lcd->addr.x = xs; |
| 330 | lcd->addr.y = ys; |
Lars Poeschel | 40c2b72 | 2020-11-03 10:58:25 +0100 | [diff] [blame] | 331 | lcd->ops->gotoxy(lcd, lcd->addr.x, lcd->addr.y); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 332 | processed = 1; |
| 333 | break; |
| 334 | } |
| 335 | case 'I': /* reinitialize display */ |
Lars Poeschel | 01ec46d | 2020-11-03 10:58:17 +0100 | [diff] [blame] | 336 | lcd->ops->init_display(lcd); |
| 337 | priv->flags = ((lcd->height > 1) ? LCD_FLAG_N : 0) | LCD_FLAG_D | |
| 338 | LCD_FLAG_C | LCD_FLAG_B; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 339 | processed = 1; |
| 340 | break; |
Lars Poeschel | 339acb0 | 2020-11-03 10:58:20 +0100 | [diff] [blame] | 341 | case 'G': |
| 342 | if (lcd->ops->redefine_char) |
| 343 | processed = lcd->ops->redefine_char(lcd, esc); |
| 344 | else |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 345 | processed = 1; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 346 | break; |
Lars Poeschel | 339acb0 | 2020-11-03 10:58:20 +0100 | [diff] [blame] | 347 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 348 | case 'x': /* gotoxy : LxXXX[yYYY]; */ |
| 349 | case 'y': /* gotoxy : LyYYY[xXXX]; */ |
Mans Rullgard | 9bc30ab | 2018-12-05 13:52:47 +0000 | [diff] [blame] | 350 | if (priv->esc_seq.buf[priv->esc_seq.len - 1] != ';') |
| 351 | break; |
| 352 | |
Miguel Ojeda | b34050f | 2018-02-27 23:09:52 +0100 | [diff] [blame] | 353 | /* If the command is valid, move to the new address */ |
Lars Poeschel | 11588b5 | 2020-11-03 10:58:10 +0100 | [diff] [blame] | 354 | if (parse_xy(esc, &lcd->addr.x, &lcd->addr.y)) |
Lars Poeschel | 40c2b72 | 2020-11-03 10:58:25 +0100 | [diff] [blame] | 355 | lcd->ops->gotoxy(lcd, lcd->addr.x, lcd->addr.y); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 356 | |
Miguel Ojeda | b34050f | 2018-02-27 23:09:52 +0100 | [diff] [blame] | 357 | /* Regardless of its validity, mark as processed */ |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 358 | processed = 1; |
| 359 | break; |
| 360 | } |
| 361 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 362 | return processed; |
| 363 | } |
| 364 | |
| 365 | static void charlcd_write_char(struct charlcd *lcd, char c) |
| 366 | { |
Andy Shevchenko | b658a21 | 2019-03-12 16:44:29 +0200 | [diff] [blame] | 367 | struct charlcd_priv *priv = charlcd_to_priv(lcd); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 368 | |
| 369 | /* first, we'll test if we're in escape mode */ |
| 370 | if ((c != '\n') && priv->esc_seq.len >= 0) { |
| 371 | /* yes, let's add this char to the buffer */ |
| 372 | priv->esc_seq.buf[priv->esc_seq.len++] = c; |
Robert Abel | 8c48375 | 2018-02-10 00:50:11 +0100 | [diff] [blame] | 373 | priv->esc_seq.buf[priv->esc_seq.len] = '\0'; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 374 | } else { |
| 375 | /* aborts any previous escape sequence */ |
| 376 | priv->esc_seq.len = -1; |
| 377 | |
| 378 | switch (c) { |
| 379 | case LCD_ESCAPE_CHAR: |
| 380 | /* start of an escape sequence */ |
| 381 | priv->esc_seq.len = 0; |
Robert Abel | 8c48375 | 2018-02-10 00:50:11 +0100 | [diff] [blame] | 382 | priv->esc_seq.buf[priv->esc_seq.len] = '\0'; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 383 | break; |
| 384 | case '\b': |
| 385 | /* go back one char and clear it */ |
Lars Poeschel | 11588b5 | 2020-11-03 10:58:10 +0100 | [diff] [blame] | 386 | if (lcd->addr.x > 0) { |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 387 | /* back one char */ |
| 388 | if (!lcd->ops->shift_cursor(lcd, |
| 389 | CHARLCD_SHIFT_LEFT)) |
| 390 | lcd->addr.x--; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 391 | } |
| 392 | /* replace with a space */ |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 393 | charlcd_print(lcd, ' '); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 394 | /* back one char again */ |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 395 | if (!lcd->ops->shift_cursor(lcd, CHARLCD_SHIFT_LEFT)) |
| 396 | lcd->addr.x--; |
| 397 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 398 | break; |
Robert Abel | 9629ccc | 2018-02-10 00:50:12 +0100 | [diff] [blame] | 399 | case '\f': |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 400 | /* quickly clear the display */ |
Lars Poeschel | 377cf2c | 2020-11-03 10:58:23 +0100 | [diff] [blame] | 401 | charlcd_clear_display(lcd); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 402 | break; |
| 403 | case '\n': |
| 404 | /* |
| 405 | * flush the remainder of the current line and |
| 406 | * go to the beginning of the next line |
| 407 | */ |
Lars Poeschel | 6e49eea | 2020-11-03 10:58:24 +0100 | [diff] [blame] | 408 | for (; lcd->addr.x < lcd->width; lcd->addr.x++) |
Lars Poeschel | b26deab | 2020-11-03 10:58:11 +0100 | [diff] [blame] | 409 | lcd->ops->print(lcd, ' '); |
| 410 | |
Lars Poeschel | 11588b5 | 2020-11-03 10:58:10 +0100 | [diff] [blame] | 411 | lcd->addr.x = 0; |
| 412 | lcd->addr.y = (lcd->addr.y + 1) % lcd->height; |
Lars Poeschel | 40c2b72 | 2020-11-03 10:58:25 +0100 | [diff] [blame] | 413 | lcd->ops->gotoxy(lcd, lcd->addr.x, lcd->addr.y); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 414 | break; |
| 415 | case '\r': |
| 416 | /* go to the beginning of the same line */ |
Lars Poeschel | 11588b5 | 2020-11-03 10:58:10 +0100 | [diff] [blame] | 417 | lcd->addr.x = 0; |
Lars Poeschel | 40c2b72 | 2020-11-03 10:58:25 +0100 | [diff] [blame] | 418 | lcd->ops->gotoxy(lcd, lcd->addr.x, lcd->addr.y); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 419 | break; |
| 420 | case '\t': |
| 421 | /* print a space instead of the tab */ |
| 422 | charlcd_print(lcd, ' '); |
| 423 | break; |
| 424 | default: |
| 425 | /* simply print this char */ |
| 426 | charlcd_print(lcd, c); |
| 427 | break; |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | /* |
| 432 | * now we'll see if we're in an escape mode and if the current |
| 433 | * escape sequence can be understood. |
| 434 | */ |
| 435 | if (priv->esc_seq.len >= 2) { |
| 436 | int processed = 0; |
| 437 | |
| 438 | if (!strcmp(priv->esc_seq.buf, "[2J")) { |
| 439 | /* clear the display */ |
Lars Poeschel | 377cf2c | 2020-11-03 10:58:23 +0100 | [diff] [blame] | 440 | charlcd_clear_display(lcd); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 441 | processed = 1; |
| 442 | } else if (!strcmp(priv->esc_seq.buf, "[H")) { |
| 443 | /* cursor to home */ |
| 444 | charlcd_home(lcd); |
| 445 | processed = 1; |
| 446 | } |
| 447 | /* codes starting with ^[[L */ |
| 448 | else if ((priv->esc_seq.len >= 3) && |
| 449 | (priv->esc_seq.buf[0] == '[') && |
| 450 | (priv->esc_seq.buf[1] == 'L')) { |
| 451 | processed = handle_lcd_special_code(lcd); |
| 452 | } |
| 453 | |
| 454 | /* LCD special escape codes */ |
| 455 | /* |
| 456 | * flush the escape sequence if it's been processed |
| 457 | * or if it is getting too long. |
| 458 | */ |
| 459 | if (processed || (priv->esc_seq.len >= LCD_ESCAPE_LEN)) |
| 460 | priv->esc_seq.len = -1; |
| 461 | } /* escape codes */ |
| 462 | } |
| 463 | |
| 464 | static struct charlcd *the_charlcd; |
| 465 | |
| 466 | static ssize_t charlcd_write(struct file *file, const char __user *buf, |
| 467 | size_t count, loff_t *ppos) |
| 468 | { |
| 469 | const char __user *tmp = buf; |
| 470 | char c; |
| 471 | |
| 472 | for (; count-- > 0; (*ppos)++, tmp++) { |
Sebastian Andrzej Siewior | 701454b | 2021-02-16 19:27:14 +0100 | [diff] [blame] | 473 | if (((count + 1) & 0x1f) == 0) { |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 474 | /* |
Sebastian Andrzej Siewior | 701454b | 2021-02-16 19:27:14 +0100 | [diff] [blame] | 475 | * charlcd_write() is invoked as a VFS->write() callback |
| 476 | * and as such it is always invoked from preemptible |
| 477 | * context and may sleep. |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 478 | */ |
Sebastian Andrzej Siewior | 701454b | 2021-02-16 19:27:14 +0100 | [diff] [blame] | 479 | cond_resched(); |
| 480 | } |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 481 | |
| 482 | if (get_user(c, tmp)) |
| 483 | return -EFAULT; |
| 484 | |
| 485 | charlcd_write_char(the_charlcd, c); |
| 486 | } |
| 487 | |
| 488 | return tmp - buf; |
| 489 | } |
| 490 | |
| 491 | static int charlcd_open(struct inode *inode, struct file *file) |
| 492 | { |
Andy Shevchenko | b658a21 | 2019-03-12 16:44:29 +0200 | [diff] [blame] | 493 | struct charlcd_priv *priv = charlcd_to_priv(the_charlcd); |
Willy Tarreau | 93dc177 | 2017-09-07 15:37:30 +0200 | [diff] [blame] | 494 | int ret; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 495 | |
Willy Tarreau | 93dc177 | 2017-09-07 15:37:30 +0200 | [diff] [blame] | 496 | ret = -EBUSY; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 497 | if (!atomic_dec_and_test(&charlcd_available)) |
Willy Tarreau | 93dc177 | 2017-09-07 15:37:30 +0200 | [diff] [blame] | 498 | goto fail; /* open only once at a time */ |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 499 | |
Willy Tarreau | 93dc177 | 2017-09-07 15:37:30 +0200 | [diff] [blame] | 500 | ret = -EPERM; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 501 | if (file->f_mode & FMODE_READ) /* device is write-only */ |
Willy Tarreau | 93dc177 | 2017-09-07 15:37:30 +0200 | [diff] [blame] | 502 | goto fail; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 503 | |
| 504 | if (priv->must_clear) { |
Lars Poeschel | 45421ff | 2020-11-03 10:58:14 +0100 | [diff] [blame] | 505 | priv->lcd.ops->clear_display(&priv->lcd); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 506 | priv->must_clear = false; |
Lars Poeschel | 45421ff | 2020-11-03 10:58:14 +0100 | [diff] [blame] | 507 | priv->lcd.addr.x = 0; |
| 508 | priv->lcd.addr.y = 0; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 509 | } |
| 510 | return nonseekable_open(inode, file); |
Willy Tarreau | 93dc177 | 2017-09-07 15:37:30 +0200 | [diff] [blame] | 511 | |
| 512 | fail: |
| 513 | atomic_inc(&charlcd_available); |
| 514 | return ret; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | static int charlcd_release(struct inode *inode, struct file *file) |
| 518 | { |
| 519 | atomic_inc(&charlcd_available); |
| 520 | return 0; |
| 521 | } |
| 522 | |
| 523 | static const struct file_operations charlcd_fops = { |
| 524 | .write = charlcd_write, |
| 525 | .open = charlcd_open, |
| 526 | .release = charlcd_release, |
| 527 | .llseek = no_llseek, |
| 528 | }; |
| 529 | |
| 530 | static struct miscdevice charlcd_dev = { |
| 531 | .minor = LCD_MINOR, |
| 532 | .name = "lcd", |
| 533 | .fops = &charlcd_fops, |
| 534 | }; |
| 535 | |
| 536 | static void charlcd_puts(struct charlcd *lcd, const char *s) |
| 537 | { |
| 538 | const char *tmp = s; |
| 539 | int count = strlen(s); |
| 540 | |
| 541 | for (; count-- > 0; tmp++) { |
Sebastian Andrzej Siewior | 701454b | 2021-02-16 19:27:14 +0100 | [diff] [blame] | 542 | if (((count + 1) & 0x1f) == 0) |
| 543 | cond_resched(); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 544 | |
| 545 | charlcd_write_char(lcd, *tmp); |
| 546 | } |
| 547 | } |
| 548 | |
Mans Rullgard | c917172 | 2019-03-01 18:48:15 +0000 | [diff] [blame] | 549 | #ifdef CONFIG_PANEL_BOOT_MESSAGE |
| 550 | #define LCD_INIT_TEXT CONFIG_PANEL_BOOT_MESSAGE |
| 551 | #else |
| 552 | #define LCD_INIT_TEXT "Linux-" UTS_RELEASE "\n" |
| 553 | #endif |
| 554 | |
Mans Rullgard | cc5d04d | 2019-03-01 18:48:16 +0000 | [diff] [blame] | 555 | #ifdef CONFIG_CHARLCD_BL_ON |
| 556 | #define LCD_INIT_BL "\x1b[L+" |
| 557 | #elif defined(CONFIG_CHARLCD_BL_FLASH) |
| 558 | #define LCD_INIT_BL "\x1b[L*" |
| 559 | #else |
| 560 | #define LCD_INIT_BL "\x1b[L-" |
| 561 | #endif |
| 562 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 563 | /* initialize the LCD driver */ |
| 564 | static int charlcd_init(struct charlcd *lcd) |
| 565 | { |
Andy Shevchenko | b658a21 | 2019-03-12 16:44:29 +0200 | [diff] [blame] | 566 | struct charlcd_priv *priv = charlcd_to_priv(lcd); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 567 | int ret; |
| 568 | |
Lars Poeschel | 01ec46d | 2020-11-03 10:58:17 +0100 | [diff] [blame] | 569 | priv->flags = ((lcd->height > 1) ? LCD_FLAG_N : 0) | LCD_FLAG_D | |
| 570 | LCD_FLAG_C | LCD_FLAG_B; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 571 | if (lcd->ops->backlight) { |
| 572 | mutex_init(&priv->bl_tempo_lock); |
| 573 | INIT_DELAYED_WORK(&priv->bl_work, charlcd_bl_off); |
| 574 | } |
| 575 | |
| 576 | /* |
| 577 | * before this line, we must NOT send anything to the display. |
| 578 | * Since charlcd_init_display() needs to write data, we have to |
| 579 | * enable mark the LCD initialized just before. |
| 580 | */ |
Lars Poeschel | 01ec46d | 2020-11-03 10:58:17 +0100 | [diff] [blame] | 581 | ret = lcd->ops->init_display(lcd); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 582 | if (ret) |
| 583 | return ret; |
| 584 | |
| 585 | /* display a short message */ |
Mans Rullgard | cc5d04d | 2019-03-01 18:48:16 +0000 | [diff] [blame] | 586 | charlcd_puts(lcd, "\x1b[Lc\x1b[Lb" LCD_INIT_BL LCD_INIT_TEXT); |
Mans Rullgard | c917172 | 2019-03-01 18:48:15 +0000 | [diff] [blame] | 587 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 588 | /* clear the display on the next device opening */ |
| 589 | priv->must_clear = true; |
| 590 | charlcd_home(lcd); |
| 591 | return 0; |
| 592 | } |
| 593 | |
Lars Poeschel | 2545c1c | 2020-11-03 10:58:06 +0100 | [diff] [blame] | 594 | struct charlcd *charlcd_alloc(void) |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 595 | { |
| 596 | struct charlcd_priv *priv; |
| 597 | struct charlcd *lcd; |
| 598 | |
Lars Poeschel | 2545c1c | 2020-11-03 10:58:06 +0100 | [diff] [blame] | 599 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 600 | if (!priv) |
| 601 | return NULL; |
| 602 | |
| 603 | priv->esc_seq.len = -1; |
| 604 | |
| 605 | lcd = &priv->lcd; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 606 | |
| 607 | return lcd; |
| 608 | } |
| 609 | EXPORT_SYMBOL_GPL(charlcd_alloc); |
| 610 | |
Andy Shevchenko | 8e44fc8 | 2019-03-12 16:44:30 +0200 | [diff] [blame] | 611 | void charlcd_free(struct charlcd *lcd) |
| 612 | { |
| 613 | kfree(charlcd_to_priv(lcd)); |
| 614 | } |
| 615 | EXPORT_SYMBOL_GPL(charlcd_free); |
| 616 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 617 | static int panel_notify_sys(struct notifier_block *this, unsigned long code, |
| 618 | void *unused) |
| 619 | { |
| 620 | struct charlcd *lcd = the_charlcd; |
| 621 | |
| 622 | switch (code) { |
| 623 | case SYS_DOWN: |
| 624 | charlcd_puts(lcd, |
| 625 | "\x0cReloading\nSystem...\x1b[Lc\x1b[Lb\x1b[L+"); |
| 626 | break; |
| 627 | case SYS_HALT: |
| 628 | charlcd_puts(lcd, "\x0cSystem Halted.\x1b[Lc\x1b[Lb\x1b[L+"); |
| 629 | break; |
| 630 | case SYS_POWER_OFF: |
| 631 | charlcd_puts(lcd, "\x0cPower off.\x1b[Lc\x1b[Lb\x1b[L+"); |
| 632 | break; |
| 633 | default: |
| 634 | break; |
| 635 | } |
| 636 | return NOTIFY_DONE; |
| 637 | } |
| 638 | |
| 639 | static struct notifier_block panel_notifier = { |
Andy Shevchenko | ac8c8fa | 2021-07-15 17:41:52 +0300 | [diff] [blame] | 640 | .notifier_call = panel_notify_sys, |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 641 | }; |
| 642 | |
| 643 | int charlcd_register(struct charlcd *lcd) |
| 644 | { |
| 645 | int ret; |
| 646 | |
| 647 | ret = charlcd_init(lcd); |
| 648 | if (ret) |
| 649 | return ret; |
| 650 | |
| 651 | ret = misc_register(&charlcd_dev); |
| 652 | if (ret) |
| 653 | return ret; |
| 654 | |
| 655 | the_charlcd = lcd; |
| 656 | register_reboot_notifier(&panel_notifier); |
| 657 | return 0; |
| 658 | } |
| 659 | EXPORT_SYMBOL_GPL(charlcd_register); |
| 660 | |
| 661 | int charlcd_unregister(struct charlcd *lcd) |
| 662 | { |
Andy Shevchenko | b658a21 | 2019-03-12 16:44:29 +0200 | [diff] [blame] | 663 | struct charlcd_priv *priv = charlcd_to_priv(lcd); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 664 | |
| 665 | unregister_reboot_notifier(&panel_notifier); |
| 666 | charlcd_puts(lcd, "\x0cLCD driver unloaded.\x1b[Lc\x1b[Lb\x1b[L-"); |
| 667 | misc_deregister(&charlcd_dev); |
| 668 | the_charlcd = NULL; |
| 669 | if (lcd->ops->backlight) { |
| 670 | cancel_delayed_work_sync(&priv->bl_work); |
Lars Poeschel | bd26b18 | 2020-11-03 10:58:16 +0100 | [diff] [blame] | 671 | priv->lcd.ops->backlight(&priv->lcd, CHARLCD_OFF); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | return 0; |
| 675 | } |
| 676 | EXPORT_SYMBOL_GPL(charlcd_unregister); |
| 677 | |
| 678 | MODULE_LICENSE("GPL"); |