hd44780_common.c (d2f2187e8f27cd884150acdce7ec96135260413b) hd44780_common.c (339acb082987a6b0aa7c67a5a77b29f6c81962f6)
1// SPDX-License-Identifier: GPL-2.0-or-later
2#include <linux/module.h>
3#include <linux/sched.h>
4#include <linux/slab.h>
5
6#include "charlcd.h"
7#include "hd44780_common.h"
8

--- 12 unchanged lines hidden (view full) ---

21#define LCD_CMD_DISPLAY_SHIFT 0x08 /* Shift display instead of cursor */
22#define LCD_CMD_SHIFT_RIGHT 0x04 /* Shift display/cursor to the right */
23
24#define LCD_CMD_FUNCTION_SET 0x20 /* Set function */
25#define LCD_CMD_DATA_LEN_8BITS 0x10 /* Set data length to 8 bits */
26#define LCD_CMD_TWO_LINES 0x08 /* Set to two display lines */
27#define LCD_CMD_FONT_5X10_DOTS 0x04 /* Set char font to 5x10 dots */
28
1// SPDX-License-Identifier: GPL-2.0-or-later
2#include <linux/module.h>
3#include <linux/sched.h>
4#include <linux/slab.h>
5
6#include "charlcd.h"
7#include "hd44780_common.h"
8

--- 12 unchanged lines hidden (view full) ---

21#define LCD_CMD_DISPLAY_SHIFT 0x08 /* Shift display instead of cursor */
22#define LCD_CMD_SHIFT_RIGHT 0x04 /* Shift display/cursor to the right */
23
24#define LCD_CMD_FUNCTION_SET 0x20 /* Set function */
25#define LCD_CMD_DATA_LEN_8BITS 0x10 /* Set data length to 8 bits */
26#define LCD_CMD_TWO_LINES 0x08 /* Set to two display lines */
27#define LCD_CMD_FONT_5X10_DOTS 0x04 /* Set char font to 5x10 dots */
28
29#define LCD_CMD_SET_CGRAM_ADDR 0x40 /* Set char generator RAM address */
30
29#define LCD_CMD_SET_DDRAM_ADDR 0x80 /* Set display data RAM address */
30
31/* sleeps that many milliseconds with a reschedule */
32static void long_sleep(int ms)
33{
34 schedule_timeout_interruptible(msecs_to_jiffies(ms));
35}
36

--- 247 unchanged lines hidden (view full) ---

284 else
285 hdc->hd44780_common_flags &= ~LCD_FLAG_N;
286
287 hd44780_common_set_function(hdc);
288 return 0;
289}
290EXPORT_SYMBOL_GPL(hd44780_common_lines);
291
31#define LCD_CMD_SET_DDRAM_ADDR 0x80 /* Set display data RAM address */
32
33/* sleeps that many milliseconds with a reschedule */
34static void long_sleep(int ms)
35{
36 schedule_timeout_interruptible(msecs_to_jiffies(ms));
37}
38

--- 247 unchanged lines hidden (view full) ---

286 else
287 hdc->hd44780_common_flags &= ~LCD_FLAG_N;
288
289 hd44780_common_set_function(hdc);
290 return 0;
291}
292EXPORT_SYMBOL_GPL(hd44780_common_lines);
293
294int hd44780_common_redefine_char(struct charlcd *lcd, char *esc)
295{
296 /* Generator : LGcxxxxx...xx; must have <c> between '0'
297 * and '7', representing the numerical ASCII code of the
298 * redefined character, and <xx...xx> a sequence of 16
299 * hex digits representing 8 bytes for each character.
300 * Most LCDs will only use 5 lower bits of the 7 first
301 * bytes.
302 */
303
304 struct hd44780_common *hdc = lcd->drvdata;
305 unsigned char cgbytes[8];
306 unsigned char cgaddr;
307 int cgoffset;
308 int shift;
309 char value;
310 int addr;
311
312 if (!strchr(esc, ';'))
313 return 0;
314
315 esc++;
316
317 cgaddr = *(esc++) - '0';
318 if (cgaddr > 7)
319 return 1;
320
321 cgoffset = 0;
322 shift = 0;
323 value = 0;
324 while (*esc && cgoffset < 8) {
325 int half;
326
327 shift ^= 4;
328 half = hex_to_bin(*esc++);
329 if (half < 0)
330 continue;
331
332 value |= half << shift;
333 if (shift == 0) {
334 cgbytes[cgoffset++] = value;
335 value = 0;
336 }
337 }
338
339 hdc->write_cmd(hdc, LCD_CMD_SET_CGRAM_ADDR | (cgaddr * 8));
340 for (addr = 0; addr < cgoffset; addr++)
341 hdc->write_data(hdc, cgbytes[addr]);
342
343 /* ensures that we stop writing to CGRAM */
344 lcd->ops->gotoxy(lcd);
345 return 1;
346}
347EXPORT_SYMBOL_GPL(hd44780_common_redefine_char);
348
292struct hd44780_common *hd44780_common_alloc(void)
293{
294 struct hd44780_common *hd;
295
296 hd = kzalloc(sizeof(*hd), GFP_KERNEL);
297 if (!hd)
298 return NULL;
299
300 hd->ifwidth = 8;
301 hd->bwidth = DEFAULT_LCD_BWIDTH;
302 hd->hwidth = DEFAULT_LCD_HWIDTH;
303 return hd;
304}
305EXPORT_SYMBOL_GPL(hd44780_common_alloc);
306
307MODULE_LICENSE("GPL");
349struct hd44780_common *hd44780_common_alloc(void)
350{
351 struct hd44780_common *hd;
352
353 hd = kzalloc(sizeof(*hd), GFP_KERNEL);
354 if (!hd)
355 return NULL;
356
357 hd->ifwidth = 8;
358 hd->bwidth = DEFAULT_LCD_BWIDTH;
359 hd->hwidth = DEFAULT_LCD_HWIDTH;
360 return hd;
361}
362EXPORT_SYMBOL_GPL(hd44780_common_alloc);
363
364MODULE_LICENSE("GPL");