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" |
Lars Poeschel | 2545c1c | 2020-11-03 10:58:06 +0100 | [diff] [blame] | 23 | #include "hd44780_common.h" |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 24 | |
| 25 | /* Keep the backlight on this many seconds for each flash */ |
| 26 | #define LCD_BL_TEMPO_PERIOD 4 |
| 27 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 28 | #define LCD_ESCAPE_LEN 24 /* Max chars for LCD escape command */ |
| 29 | #define LCD_ESCAPE_CHAR 27 /* Use char 27 for escape command */ |
| 30 | |
| 31 | struct charlcd_priv { |
| 32 | struct charlcd lcd; |
| 33 | |
| 34 | struct delayed_work bl_work; |
| 35 | struct mutex bl_tempo_lock; /* Protects access to bl_tempo */ |
| 36 | bool bl_tempo; |
| 37 | |
| 38 | bool must_clear; |
| 39 | |
| 40 | /* contains the LCD config state */ |
| 41 | unsigned long int flags; |
| 42 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 43 | /* Current escape sequence and it's length or -1 if outside */ |
| 44 | struct { |
| 45 | char buf[LCD_ESCAPE_LEN + 1]; |
| 46 | int len; |
| 47 | } esc_seq; |
| 48 | |
Gustavo A. R. Silva | 2f920c0 | 2020-02-12 13:52:31 -0600 | [diff] [blame] | 49 | unsigned long long drvdata[]; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 50 | }; |
| 51 | |
Andy Shevchenko | b658a21 | 2019-03-12 16:44:29 +0200 | [diff] [blame] | 52 | #define charlcd_to_priv(p) container_of(p, struct charlcd_priv, lcd) |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 53 | |
| 54 | /* Device single-open policy control */ |
| 55 | static atomic_t charlcd_available = ATOMIC_INIT(1); |
| 56 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 57 | /* turn the backlight on or off */ |
Lars Poeschel | 2bf82b5 | 2020-11-03 10:58:15 +0100 | [diff] [blame] | 58 | void charlcd_backlight(struct charlcd *lcd, enum charlcd_onoff on) |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 59 | { |
Andy Shevchenko | b658a21 | 2019-03-12 16:44:29 +0200 | [diff] [blame] | 60 | struct charlcd_priv *priv = charlcd_to_priv(lcd); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 61 | |
| 62 | if (!lcd->ops->backlight) |
| 63 | return; |
| 64 | |
| 65 | mutex_lock(&priv->bl_tempo_lock); |
| 66 | if (!priv->bl_tempo) |
| 67 | lcd->ops->backlight(lcd, on); |
| 68 | mutex_unlock(&priv->bl_tempo_lock); |
| 69 | } |
Lars Poeschel | 2bf82b5 | 2020-11-03 10:58:15 +0100 | [diff] [blame] | 70 | EXPORT_SYMBOL_GPL(charlcd_backlight); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 71 | |
| 72 | static void charlcd_bl_off(struct work_struct *work) |
| 73 | { |
| 74 | struct delayed_work *dwork = to_delayed_work(work); |
| 75 | struct charlcd_priv *priv = |
| 76 | container_of(dwork, struct charlcd_priv, bl_work); |
| 77 | |
| 78 | mutex_lock(&priv->bl_tempo_lock); |
| 79 | if (priv->bl_tempo) { |
| 80 | priv->bl_tempo = false; |
| 81 | if (!(priv->flags & LCD_FLAG_L)) |
Lars Poeschel | bd26b18 | 2020-11-03 10:58:16 +0100 | [diff] [blame] | 82 | priv->lcd.ops->backlight(&priv->lcd, CHARLCD_OFF); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 83 | } |
| 84 | mutex_unlock(&priv->bl_tempo_lock); |
| 85 | } |
| 86 | |
| 87 | /* turn the backlight on for a little while */ |
| 88 | void charlcd_poke(struct charlcd *lcd) |
| 89 | { |
Andy Shevchenko | b658a21 | 2019-03-12 16:44:29 +0200 | [diff] [blame] | 90 | struct charlcd_priv *priv = charlcd_to_priv(lcd); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 91 | |
| 92 | if (!lcd->ops->backlight) |
| 93 | return; |
| 94 | |
| 95 | cancel_delayed_work_sync(&priv->bl_work); |
| 96 | |
| 97 | mutex_lock(&priv->bl_tempo_lock); |
| 98 | if (!priv->bl_tempo && !(priv->flags & LCD_FLAG_L)) |
Lars Poeschel | bd26b18 | 2020-11-03 10:58:16 +0100 | [diff] [blame] | 99 | lcd->ops->backlight(lcd, CHARLCD_ON); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 100 | priv->bl_tempo = true; |
| 101 | schedule_delayed_work(&priv->bl_work, LCD_BL_TEMPO_PERIOD * HZ); |
| 102 | mutex_unlock(&priv->bl_tempo_lock); |
| 103 | } |
| 104 | EXPORT_SYMBOL_GPL(charlcd_poke); |
| 105 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 106 | static void charlcd_home(struct charlcd *lcd) |
| 107 | { |
Lars Poeschel | 11588b5 | 2020-11-03 10:58:10 +0100 | [diff] [blame] | 108 | lcd->addr.x = 0; |
| 109 | lcd->addr.y = 0; |
Lars Poeschel | 88645a8 | 2020-11-03 10:58:13 +0100 | [diff] [blame] | 110 | lcd->ops->home(lcd); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | static void charlcd_print(struct charlcd *lcd, char c) |
| 114 | { |
Lars Poeschel | d3a2fb8 | 2020-11-03 10:58:12 +0100 | [diff] [blame] | 115 | struct hd44780_common *hdc = lcd->drvdata; |
| 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 | d3a2fb8 | 2020-11-03 10:58:12 +0100 | [diff] [blame] | 124 | if (lcd->addr.x == hdc->bwidth) |
| 125 | lcd->ops->gotoxy(lcd); |
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); |
Lars Poeschel | 2545c1c | 2020-11-03 10:58:06 +0100 | [diff] [blame] | 198 | struct hd44780_common *hdc = lcd->drvdata; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 199 | |
| 200 | /* LCD special codes */ |
| 201 | |
| 202 | int processed = 0; |
| 203 | |
| 204 | char *esc = priv->esc_seq.buf + 2; |
| 205 | int oldflags = priv->flags; |
| 206 | |
| 207 | /* check for display mode flags */ |
| 208 | switch (*esc) { |
| 209 | case 'D': /* Display ON */ |
| 210 | priv->flags |= LCD_FLAG_D; |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 211 | if (priv->flags != oldflags) |
| 212 | lcd->ops->display(lcd, CHARLCD_ON); |
| 213 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 214 | processed = 1; |
| 215 | break; |
| 216 | case 'd': /* Display OFF */ |
| 217 | priv->flags &= ~LCD_FLAG_D; |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 218 | if (priv->flags != oldflags) |
| 219 | lcd->ops->display(lcd, CHARLCD_OFF); |
| 220 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 221 | processed = 1; |
| 222 | break; |
| 223 | case 'C': /* Cursor ON */ |
| 224 | priv->flags |= LCD_FLAG_C; |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 225 | if (priv->flags != oldflags) |
| 226 | lcd->ops->cursor(lcd, CHARLCD_ON); |
| 227 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 228 | processed = 1; |
| 229 | break; |
| 230 | case 'c': /* Cursor OFF */ |
| 231 | priv->flags &= ~LCD_FLAG_C; |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 232 | if (priv->flags != oldflags) |
| 233 | lcd->ops->cursor(lcd, CHARLCD_OFF); |
| 234 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 235 | processed = 1; |
| 236 | break; |
| 237 | case 'B': /* Blink ON */ |
| 238 | priv->flags |= LCD_FLAG_B; |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 239 | if (priv->flags != oldflags) |
| 240 | lcd->ops->blink(lcd, CHARLCD_ON); |
| 241 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 242 | processed = 1; |
| 243 | break; |
| 244 | case 'b': /* Blink OFF */ |
| 245 | priv->flags &= ~LCD_FLAG_B; |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 246 | if (priv->flags != oldflags) |
| 247 | lcd->ops->blink(lcd, CHARLCD_OFF); |
| 248 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 249 | processed = 1; |
| 250 | break; |
| 251 | case '+': /* Back light ON */ |
| 252 | priv->flags |= LCD_FLAG_L; |
Lars Poeschel | a2060f2 | 2020-11-03 10:58:21 +0100 | [diff] [blame] | 253 | if (priv->flags != oldflags) |
| 254 | charlcd_backlight(lcd, CHARLCD_ON); |
| 255 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 256 | processed = 1; |
| 257 | break; |
| 258 | case '-': /* Back light OFF */ |
| 259 | priv->flags &= ~LCD_FLAG_L; |
Lars Poeschel | a2060f2 | 2020-11-03 10:58:21 +0100 | [diff] [blame] | 260 | if (priv->flags != oldflags) |
| 261 | charlcd_backlight(lcd, CHARLCD_OFF); |
| 262 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 263 | processed = 1; |
| 264 | break; |
| 265 | case '*': /* Flash back light */ |
| 266 | charlcd_poke(lcd); |
| 267 | processed = 1; |
| 268 | break; |
| 269 | case 'f': /* Small Font */ |
| 270 | priv->flags &= ~LCD_FLAG_F; |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 271 | if (priv->flags != oldflags) |
| 272 | lcd->ops->fontsize(lcd, CHARLCD_FONTSIZE_SMALL); |
| 273 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 274 | processed = 1; |
| 275 | break; |
| 276 | case 'F': /* Large Font */ |
| 277 | priv->flags |= LCD_FLAG_F; |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 278 | if (priv->flags != oldflags) |
| 279 | lcd->ops->fontsize(lcd, CHARLCD_FONTSIZE_LARGE); |
| 280 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 281 | processed = 1; |
| 282 | break; |
| 283 | case 'n': /* One Line */ |
| 284 | priv->flags &= ~LCD_FLAG_N; |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 285 | if (priv->flags != oldflags) |
| 286 | lcd->ops->lines(lcd, CHARLCD_LINES_1); |
| 287 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 288 | processed = 1; |
| 289 | break; |
| 290 | case 'N': /* Two Lines */ |
| 291 | priv->flags |= LCD_FLAG_N; |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 292 | if (priv->flags != oldflags) |
| 293 | lcd->ops->lines(lcd, CHARLCD_LINES_2); |
| 294 | |
Robert Abel | 99b9b49 | 2018-02-26 00:54:29 +0100 | [diff] [blame] | 295 | processed = 1; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 296 | break; |
| 297 | case 'l': /* Shift Cursor Left */ |
Lars Poeschel | 11588b5 | 2020-11-03 10:58:10 +0100 | [diff] [blame] | 298 | if (lcd->addr.x > 0) { |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 299 | if (!lcd->ops->shift_cursor(lcd, CHARLCD_SHIFT_LEFT)) |
| 300 | lcd->addr.x--; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 301 | } |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 302 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 303 | processed = 1; |
| 304 | break; |
| 305 | case 'r': /* shift cursor right */ |
Lars Poeschel | 11588b5 | 2020-11-03 10:58:10 +0100 | [diff] [blame] | 306 | if (lcd->addr.x < lcd->width) { |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 307 | if (!lcd->ops->shift_cursor(lcd, CHARLCD_SHIFT_RIGHT)) |
| 308 | lcd->addr.x++; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 309 | } |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 310 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 311 | processed = 1; |
| 312 | break; |
| 313 | case 'L': /* shift display left */ |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 314 | lcd->ops->shift_display(lcd, CHARLCD_SHIFT_LEFT); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 315 | processed = 1; |
| 316 | break; |
| 317 | case 'R': /* shift display right */ |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 318 | lcd->ops->shift_display(lcd, CHARLCD_SHIFT_RIGHT); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 319 | processed = 1; |
| 320 | break; |
| 321 | case 'k': { /* kill end of line */ |
Lars Poeschel | b26deab | 2020-11-03 10:58:11 +0100 | [diff] [blame] | 322 | int x, xs, ys; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 323 | |
Lars Poeschel | b26deab | 2020-11-03 10:58:11 +0100 | [diff] [blame] | 324 | xs = lcd->addr.x; |
| 325 | ys = lcd->addr.y; |
Lars Poeschel | 11588b5 | 2020-11-03 10:58:10 +0100 | [diff] [blame] | 326 | for (x = lcd->addr.x; x < hdc->bwidth; x++) |
Lars Poeschel | b26deab | 2020-11-03 10:58:11 +0100 | [diff] [blame] | 327 | lcd->ops->print(lcd, ' '); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 328 | |
| 329 | /* restore cursor position */ |
Lars Poeschel | b26deab | 2020-11-03 10:58:11 +0100 | [diff] [blame] | 330 | lcd->addr.x = xs; |
| 331 | lcd->addr.y = ys; |
Lars Poeschel | d3a2fb8 | 2020-11-03 10:58:12 +0100 | [diff] [blame] | 332 | lcd->ops->gotoxy(lcd); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 333 | processed = 1; |
| 334 | break; |
| 335 | } |
| 336 | case 'I': /* reinitialize display */ |
Lars Poeschel | 01ec46d | 2020-11-03 10:58:17 +0100 | [diff] [blame] | 337 | lcd->ops->init_display(lcd); |
| 338 | priv->flags = ((lcd->height > 1) ? LCD_FLAG_N : 0) | LCD_FLAG_D | |
| 339 | LCD_FLAG_C | LCD_FLAG_B; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 340 | processed = 1; |
| 341 | break; |
Lars Poeschel | 339acb0 | 2020-11-03 10:58:20 +0100 | [diff] [blame] | 342 | case 'G': |
| 343 | if (lcd->ops->redefine_char) |
| 344 | processed = lcd->ops->redefine_char(lcd, esc); |
| 345 | else |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 346 | processed = 1; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 347 | break; |
Lars Poeschel | 339acb0 | 2020-11-03 10:58:20 +0100 | [diff] [blame] | 348 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 349 | case 'x': /* gotoxy : LxXXX[yYYY]; */ |
| 350 | case 'y': /* gotoxy : LyYYY[xXXX]; */ |
Mans Rullgard | 9bc30ab | 2018-12-05 13:52:47 +0000 | [diff] [blame] | 351 | if (priv->esc_seq.buf[priv->esc_seq.len - 1] != ';') |
| 352 | break; |
| 353 | |
Miguel Ojeda | b34050f | 2018-02-27 23:09:52 +0100 | [diff] [blame] | 354 | /* If the command is valid, move to the new address */ |
Lars Poeschel | 11588b5 | 2020-11-03 10:58:10 +0100 | [diff] [blame] | 355 | if (parse_xy(esc, &lcd->addr.x, &lcd->addr.y)) |
Lars Poeschel | d3a2fb8 | 2020-11-03 10:58:12 +0100 | [diff] [blame] | 356 | lcd->ops->gotoxy(lcd); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 357 | |
Miguel Ojeda | b34050f | 2018-02-27 23:09:52 +0100 | [diff] [blame] | 358 | /* Regardless of its validity, mark as processed */ |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 359 | processed = 1; |
| 360 | break; |
| 361 | } |
| 362 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 363 | return processed; |
| 364 | } |
| 365 | |
| 366 | static void charlcd_write_char(struct charlcd *lcd, char c) |
| 367 | { |
Andy Shevchenko | b658a21 | 2019-03-12 16:44:29 +0200 | [diff] [blame] | 368 | struct charlcd_priv *priv = charlcd_to_priv(lcd); |
Lars Poeschel | 2545c1c | 2020-11-03 10:58:06 +0100 | [diff] [blame] | 369 | struct hd44780_common *hdc = lcd->drvdata; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 370 | |
| 371 | /* first, we'll test if we're in escape mode */ |
| 372 | if ((c != '\n') && priv->esc_seq.len >= 0) { |
| 373 | /* yes, let's add this char to the buffer */ |
| 374 | priv->esc_seq.buf[priv->esc_seq.len++] = c; |
Robert Abel | 8c48375 | 2018-02-10 00:50:11 +0100 | [diff] [blame] | 375 | priv->esc_seq.buf[priv->esc_seq.len] = '\0'; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 376 | } else { |
| 377 | /* aborts any previous escape sequence */ |
| 378 | priv->esc_seq.len = -1; |
| 379 | |
| 380 | switch (c) { |
| 381 | case LCD_ESCAPE_CHAR: |
| 382 | /* start of an escape sequence */ |
| 383 | priv->esc_seq.len = 0; |
Robert Abel | 8c48375 | 2018-02-10 00:50:11 +0100 | [diff] [blame] | 384 | priv->esc_seq.buf[priv->esc_seq.len] = '\0'; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 385 | break; |
| 386 | case '\b': |
| 387 | /* go back one char and clear it */ |
Lars Poeschel | 11588b5 | 2020-11-03 10:58:10 +0100 | [diff] [blame] | 388 | if (lcd->addr.x > 0) { |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 389 | /* back one char */ |
| 390 | if (!lcd->ops->shift_cursor(lcd, |
| 391 | CHARLCD_SHIFT_LEFT)) |
| 392 | lcd->addr.x--; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 393 | } |
| 394 | /* replace with a space */ |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 395 | charlcd_print(lcd, ' '); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 396 | /* back one char again */ |
Lars Poeschel | d2f2187 | 2020-11-03 10:58:18 +0100 | [diff] [blame] | 397 | if (!lcd->ops->shift_cursor(lcd, CHARLCD_SHIFT_LEFT)) |
| 398 | lcd->addr.x--; |
| 399 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 400 | break; |
Robert Abel | 9629ccc | 2018-02-10 00:50:12 +0100 | [diff] [blame] | 401 | case '\f': |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 402 | /* quickly clear the display */ |
Lars Poeschel | 377cf2c | 2020-11-03 10:58:23 +0100 | [diff] [blame^] | 403 | charlcd_clear_display(lcd); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 404 | break; |
| 405 | case '\n': |
| 406 | /* |
| 407 | * flush the remainder of the current line and |
| 408 | * go to the beginning of the next line |
| 409 | */ |
Lars Poeschel | 11588b5 | 2020-11-03 10:58:10 +0100 | [diff] [blame] | 410 | for (; lcd->addr.x < hdc->bwidth; lcd->addr.x++) |
Lars Poeschel | b26deab | 2020-11-03 10:58:11 +0100 | [diff] [blame] | 411 | lcd->ops->print(lcd, ' '); |
| 412 | |
Lars Poeschel | 11588b5 | 2020-11-03 10:58:10 +0100 | [diff] [blame] | 413 | lcd->addr.x = 0; |
| 414 | lcd->addr.y = (lcd->addr.y + 1) % lcd->height; |
Lars Poeschel | d3a2fb8 | 2020-11-03 10:58:12 +0100 | [diff] [blame] | 415 | lcd->ops->gotoxy(lcd); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 416 | break; |
| 417 | case '\r': |
| 418 | /* go to the beginning of the same line */ |
Lars Poeschel | 11588b5 | 2020-11-03 10:58:10 +0100 | [diff] [blame] | 419 | lcd->addr.x = 0; |
Lars Poeschel | d3a2fb8 | 2020-11-03 10:58:12 +0100 | [diff] [blame] | 420 | lcd->ops->gotoxy(lcd); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 421 | break; |
| 422 | case '\t': |
| 423 | /* print a space instead of the tab */ |
| 424 | charlcd_print(lcd, ' '); |
| 425 | break; |
| 426 | default: |
| 427 | /* simply print this char */ |
| 428 | charlcd_print(lcd, c); |
| 429 | break; |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | /* |
| 434 | * now we'll see if we're in an escape mode and if the current |
| 435 | * escape sequence can be understood. |
| 436 | */ |
| 437 | if (priv->esc_seq.len >= 2) { |
| 438 | int processed = 0; |
| 439 | |
| 440 | if (!strcmp(priv->esc_seq.buf, "[2J")) { |
| 441 | /* clear the display */ |
Lars Poeschel | 377cf2c | 2020-11-03 10:58:23 +0100 | [diff] [blame^] | 442 | charlcd_clear_display(lcd); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 443 | processed = 1; |
| 444 | } else if (!strcmp(priv->esc_seq.buf, "[H")) { |
| 445 | /* cursor to home */ |
| 446 | charlcd_home(lcd); |
| 447 | processed = 1; |
| 448 | } |
| 449 | /* codes starting with ^[[L */ |
| 450 | else if ((priv->esc_seq.len >= 3) && |
| 451 | (priv->esc_seq.buf[0] == '[') && |
| 452 | (priv->esc_seq.buf[1] == 'L')) { |
| 453 | processed = handle_lcd_special_code(lcd); |
| 454 | } |
| 455 | |
| 456 | /* LCD special escape codes */ |
| 457 | /* |
| 458 | * flush the escape sequence if it's been processed |
| 459 | * or if it is getting too long. |
| 460 | */ |
| 461 | if (processed || (priv->esc_seq.len >= LCD_ESCAPE_LEN)) |
| 462 | priv->esc_seq.len = -1; |
| 463 | } /* escape codes */ |
| 464 | } |
| 465 | |
| 466 | static struct charlcd *the_charlcd; |
| 467 | |
| 468 | static ssize_t charlcd_write(struct file *file, const char __user *buf, |
| 469 | size_t count, loff_t *ppos) |
| 470 | { |
| 471 | const char __user *tmp = buf; |
| 472 | char c; |
| 473 | |
| 474 | for (; count-- > 0; (*ppos)++, tmp++) { |
| 475 | if (!in_interrupt() && (((count + 1) & 0x1f) == 0)) |
| 476 | /* |
| 477 | * let's be a little nice with other processes |
| 478 | * that need some CPU |
| 479 | */ |
| 480 | schedule(); |
| 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++) { |
| 542 | if (!in_interrupt() && (((count + 1) & 0x1f) == 0)) |
| 543 | /* |
| 544 | * let's be a little nice with other processes |
| 545 | * that need some CPU |
| 546 | */ |
| 547 | schedule(); |
| 548 | |
| 549 | charlcd_write_char(lcd, *tmp); |
| 550 | } |
| 551 | } |
| 552 | |
Mans Rullgard | c917172 | 2019-03-01 18:48:15 +0000 | [diff] [blame] | 553 | #ifdef CONFIG_PANEL_BOOT_MESSAGE |
| 554 | #define LCD_INIT_TEXT CONFIG_PANEL_BOOT_MESSAGE |
| 555 | #else |
| 556 | #define LCD_INIT_TEXT "Linux-" UTS_RELEASE "\n" |
| 557 | #endif |
| 558 | |
Mans Rullgard | cc5d04d | 2019-03-01 18:48:16 +0000 | [diff] [blame] | 559 | #ifdef CONFIG_CHARLCD_BL_ON |
| 560 | #define LCD_INIT_BL "\x1b[L+" |
| 561 | #elif defined(CONFIG_CHARLCD_BL_FLASH) |
| 562 | #define LCD_INIT_BL "\x1b[L*" |
| 563 | #else |
| 564 | #define LCD_INIT_BL "\x1b[L-" |
| 565 | #endif |
| 566 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 567 | /* initialize the LCD driver */ |
| 568 | static int charlcd_init(struct charlcd *lcd) |
| 569 | { |
Andy Shevchenko | b658a21 | 2019-03-12 16:44:29 +0200 | [diff] [blame] | 570 | struct charlcd_priv *priv = charlcd_to_priv(lcd); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 571 | int ret; |
| 572 | |
Lars Poeschel | 01ec46d | 2020-11-03 10:58:17 +0100 | [diff] [blame] | 573 | priv->flags = ((lcd->height > 1) ? LCD_FLAG_N : 0) | LCD_FLAG_D | |
| 574 | LCD_FLAG_C | LCD_FLAG_B; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 575 | if (lcd->ops->backlight) { |
| 576 | mutex_init(&priv->bl_tempo_lock); |
| 577 | INIT_DELAYED_WORK(&priv->bl_work, charlcd_bl_off); |
| 578 | } |
| 579 | |
| 580 | /* |
| 581 | * before this line, we must NOT send anything to the display. |
| 582 | * Since charlcd_init_display() needs to write data, we have to |
| 583 | * enable mark the LCD initialized just before. |
| 584 | */ |
Lars Poeschel | 01ec46d | 2020-11-03 10:58:17 +0100 | [diff] [blame] | 585 | ret = lcd->ops->init_display(lcd); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 586 | if (ret) |
| 587 | return ret; |
| 588 | |
| 589 | /* display a short message */ |
Mans Rullgard | cc5d04d | 2019-03-01 18:48:16 +0000 | [diff] [blame] | 590 | 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] | 591 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 592 | /* clear the display on the next device opening */ |
| 593 | priv->must_clear = true; |
| 594 | charlcd_home(lcd); |
| 595 | return 0; |
| 596 | } |
| 597 | |
Lars Poeschel | 2545c1c | 2020-11-03 10:58:06 +0100 | [diff] [blame] | 598 | struct charlcd *charlcd_alloc(void) |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 599 | { |
| 600 | struct charlcd_priv *priv; |
| 601 | struct charlcd *lcd; |
| 602 | |
Lars Poeschel | 2545c1c | 2020-11-03 10:58:06 +0100 | [diff] [blame] | 603 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 604 | if (!priv) |
| 605 | return NULL; |
| 606 | |
| 607 | priv->esc_seq.len = -1; |
| 608 | |
| 609 | lcd = &priv->lcd; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 610 | |
| 611 | return lcd; |
| 612 | } |
| 613 | EXPORT_SYMBOL_GPL(charlcd_alloc); |
| 614 | |
Andy Shevchenko | 8e44fc8 | 2019-03-12 16:44:30 +0200 | [diff] [blame] | 615 | void charlcd_free(struct charlcd *lcd) |
| 616 | { |
| 617 | kfree(charlcd_to_priv(lcd)); |
| 618 | } |
| 619 | EXPORT_SYMBOL_GPL(charlcd_free); |
| 620 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 621 | static int panel_notify_sys(struct notifier_block *this, unsigned long code, |
| 622 | void *unused) |
| 623 | { |
| 624 | struct charlcd *lcd = the_charlcd; |
| 625 | |
| 626 | switch (code) { |
| 627 | case SYS_DOWN: |
| 628 | charlcd_puts(lcd, |
| 629 | "\x0cReloading\nSystem...\x1b[Lc\x1b[Lb\x1b[L+"); |
| 630 | break; |
| 631 | case SYS_HALT: |
| 632 | charlcd_puts(lcd, "\x0cSystem Halted.\x1b[Lc\x1b[Lb\x1b[L+"); |
| 633 | break; |
| 634 | case SYS_POWER_OFF: |
| 635 | charlcd_puts(lcd, "\x0cPower off.\x1b[Lc\x1b[Lb\x1b[L+"); |
| 636 | break; |
| 637 | default: |
| 638 | break; |
| 639 | } |
| 640 | return NOTIFY_DONE; |
| 641 | } |
| 642 | |
| 643 | static struct notifier_block panel_notifier = { |
| 644 | panel_notify_sys, |
| 645 | NULL, |
| 646 | 0 |
| 647 | }; |
| 648 | |
| 649 | int charlcd_register(struct charlcd *lcd) |
| 650 | { |
| 651 | int ret; |
| 652 | |
| 653 | ret = charlcd_init(lcd); |
| 654 | if (ret) |
| 655 | return ret; |
| 656 | |
| 657 | ret = misc_register(&charlcd_dev); |
| 658 | if (ret) |
| 659 | return ret; |
| 660 | |
| 661 | the_charlcd = lcd; |
| 662 | register_reboot_notifier(&panel_notifier); |
| 663 | return 0; |
| 664 | } |
| 665 | EXPORT_SYMBOL_GPL(charlcd_register); |
| 666 | |
| 667 | int charlcd_unregister(struct charlcd *lcd) |
| 668 | { |
Andy Shevchenko | b658a21 | 2019-03-12 16:44:29 +0200 | [diff] [blame] | 669 | struct charlcd_priv *priv = charlcd_to_priv(lcd); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 670 | |
| 671 | unregister_reboot_notifier(&panel_notifier); |
| 672 | charlcd_puts(lcd, "\x0cLCD driver unloaded.\x1b[Lc\x1b[Lb\x1b[L-"); |
| 673 | misc_deregister(&charlcd_dev); |
| 674 | the_charlcd = NULL; |
| 675 | if (lcd->ops->backlight) { |
| 676 | cancel_delayed_work_sync(&priv->bl_work); |
Lars Poeschel | bd26b18 | 2020-11-03 10:58:16 +0100 | [diff] [blame] | 677 | priv->lcd.ops->backlight(&priv->lcd, CHARLCD_OFF); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | return 0; |
| 681 | } |
| 682 | EXPORT_SYMBOL_GPL(charlcd_unregister); |
| 683 | |
| 684 | MODULE_LICENSE("GPL"); |