diff options
author | Lars Poeschel | 2020-11-03 10:58:17 +0100 |
---|---|---|
committer | Miguel Ojeda | 2020-11-04 11:04:04 +0100 |
commit | 01ec46dfa633a52ccfe38d4a194460d6adb2ba00 (patch) | |
tree | 14e67817c60048d0e3c361d498041b6ef64039da /drivers/auxdisplay/charlcd.c | |
parent | bd26b181d14af003a1c9903831f5735f431530f6 (diff) |
auxdisplay: Move init_display to hd44780_common
The init_display function is moved over to hd44780_common. charlcd uses
it via its ops function pointer and drivers initialize the ops with the
common hd44780_common_init_display function.
Reviewed-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Lars Poeschel <poeschel@lemonage.de>
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Diffstat (limited to 'drivers/auxdisplay/charlcd.c')
-rw-r--r-- | drivers/auxdisplay/charlcd.c | 95 |
1 files changed, 6 insertions, 89 deletions
diff --git a/drivers/auxdisplay/charlcd.c b/drivers/auxdisplay/charlcd.c index 9631f70e8128..94f6b0afab13 100644 --- a/drivers/auxdisplay/charlcd.c +++ b/drivers/auxdisplay/charlcd.c @@ -8,7 +8,6 @@ #include <linux/atomic.h> #include <linux/ctype.h> -#include <linux/delay.h> #include <linux/fs.h> #include <linux/miscdevice.h> #include <linux/module.h> @@ -26,17 +25,7 @@ /* Keep the backlight on this many seconds for each flash */ #define LCD_BL_TEMPO_PERIOD 4 -#define LCD_FLAG_B 0x0004 /* Blink on */ -#define LCD_FLAG_C 0x0008 /* Cursor on */ -#define LCD_FLAG_D 0x0010 /* Display on */ -#define LCD_FLAG_F 0x0020 /* Large font mode */ -#define LCD_FLAG_N 0x0040 /* 2-rows mode */ -#define LCD_FLAG_L 0x0080 /* Backlight enabled */ - /* LCD commands */ -#define LCD_CMD_ENTRY_MODE 0x04 /* Set entry mode */ -#define LCD_CMD_CURSOR_INC 0x02 /* Increment cursor */ - #define LCD_CMD_DISPLAY_CTRL 0x08 /* Display control */ #define LCD_CMD_DISPLAY_ON 0x04 /* Set display on */ #define LCD_CMD_CURSOR_ON 0x02 /* Set cursor on */ @@ -84,12 +73,6 @@ struct charlcd_priv { /* Device single-open policy control */ static atomic_t charlcd_available = ATOMIC_INIT(1); -/* sleeps that many milliseconds with a reschedule */ -static void long_sleep(int ms) -{ - schedule_timeout_interruptible(msecs_to_jiffies(ms)); -} - /* turn the backlight on or off */ void charlcd_backlight(struct charlcd *lcd, enum charlcd_onoff on) { @@ -177,76 +160,6 @@ static void charlcd_clear_fast(struct charlcd *lcd) charlcd_home(lcd); } -static int charlcd_init_display(struct charlcd *lcd) -{ - void (*write_cmd_raw)(struct hd44780_common *hdc, int cmd); - struct charlcd_priv *priv = charlcd_to_priv(lcd); - struct hd44780_common *hdc = lcd->drvdata; - u8 init; - - if (hdc->ifwidth != 4 && hdc->ifwidth != 8) - return -EINVAL; - - priv->flags = ((lcd->height > 1) ? LCD_FLAG_N : 0) | LCD_FLAG_D | - LCD_FLAG_C | LCD_FLAG_B; - - long_sleep(20); /* wait 20 ms after power-up for the paranoid */ - - /* - * 8-bit mode, 1 line, small fonts; let's do it 3 times, to make sure - * the LCD is in 8-bit mode afterwards - */ - init = LCD_CMD_FUNCTION_SET | LCD_CMD_DATA_LEN_8BITS; - if (hdc->ifwidth == 4) { - init >>= 4; - write_cmd_raw = hdc->write_cmd_raw4; - } else { - write_cmd_raw = hdc->write_cmd; - } - write_cmd_raw(hdc, init); - long_sleep(10); - write_cmd_raw(hdc, init); - long_sleep(10); - write_cmd_raw(hdc, init); - long_sleep(10); - - if (hdc->ifwidth == 4) { - /* Switch to 4-bit mode, 1 line, small fonts */ - hdc->write_cmd_raw4(hdc, LCD_CMD_FUNCTION_SET >> 4); - long_sleep(10); - } - - /* set font height and lines number */ - hdc->write_cmd(hdc, - LCD_CMD_FUNCTION_SET | - ((hdc->ifwidth == 8) ? LCD_CMD_DATA_LEN_8BITS : 0) | - ((priv->flags & LCD_FLAG_F) ? LCD_CMD_FONT_5X10_DOTS : 0) | - ((priv->flags & LCD_FLAG_N) ? LCD_CMD_TWO_LINES : 0)); - long_sleep(10); - - /* display off, cursor off, blink off */ - hdc->write_cmd(hdc, LCD_CMD_DISPLAY_CTRL); - long_sleep(10); - - hdc->write_cmd(hdc, - LCD_CMD_DISPLAY_CTRL | /* set display mode */ - ((priv->flags & LCD_FLAG_D) ? LCD_CMD_DISPLAY_ON : 0) | - ((priv->flags & LCD_FLAG_C) ? LCD_CMD_CURSOR_ON : 0) | - ((priv->flags & LCD_FLAG_B) ? LCD_CMD_BLINK_ON : 0)); - - charlcd_backlight(lcd, (priv->flags & LCD_FLAG_L) ? 1 : 0); - - long_sleep(10); - - /* entry mode set : increment, cursor shifting */ - hdc->write_cmd(hdc, LCD_CMD_ENTRY_MODE | LCD_CMD_CURSOR_INC); - - lcd->ops->clear_display(lcd); - lcd->addr.x = 0; - lcd->addr.y = 0; - return 0; -} - /* * Parses a movement command of the form "(.*);", where the group can be * any number of subcommands of the form "(x|y)[0-9]+". @@ -418,7 +331,9 @@ static inline int handle_lcd_special_code(struct charlcd *lcd) break; } case 'I': /* reinitialize display */ - charlcd_init_display(lcd); + lcd->ops->init_display(lcd); + priv->flags = ((lcd->height > 1) ? LCD_FLAG_N : 0) | LCD_FLAG_D | + LCD_FLAG_C | LCD_FLAG_B; processed = 1; break; case 'G': { @@ -727,6 +642,8 @@ static int charlcd_init(struct charlcd *lcd) struct charlcd_priv *priv = charlcd_to_priv(lcd); int ret; + priv->flags = ((lcd->height > 1) ? LCD_FLAG_N : 0) | LCD_FLAG_D | + LCD_FLAG_C | LCD_FLAG_B; if (lcd->ops->backlight) { mutex_init(&priv->bl_tempo_lock); INIT_DELAYED_WORK(&priv->bl_work, charlcd_bl_off); @@ -737,7 +654,7 @@ static int charlcd_init(struct charlcd *lcd) * Since charlcd_init_display() needs to write data, we have to * enable mark the LCD initialized just before. */ - ret = charlcd_init_display(lcd); + ret = lcd->ops->init_display(lcd); if (ret) return ret; |