diff options
Diffstat (limited to 'drivers/staging/panel')
-rw-r--r-- | drivers/staging/panel/panel.c | 104 |
1 files changed, 67 insertions, 37 deletions
diff --git a/drivers/staging/panel/panel.c b/drivers/staging/panel/panel.c index 98325b7b4462..6ed35b6ecf0d 100644 --- a/drivers/staging/panel/panel.c +++ b/drivers/staging/panel/panel.c @@ -130,6 +130,30 @@ #define LCD_FLAG_N 0x0040 /* 2-rows mode */ #define LCD_FLAG_L 0x0080 /* backlight enabled */ +/* LCD commands */ +#define LCD_CMD_DISPLAY_CLEAR 0x01 /* Clear entire display */ + +#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 */ +#define LCD_CMD_BLINK_ON 0x01 /* Set blink on */ + +#define LCD_CMD_SHIFT 0x10 /* Shift cursor/display */ +#define LCD_CMD_DISPLAY_SHIFT 0x08 /* Shift display instead of cursor */ +#define LCD_CMD_SHIFT_RIGHT 0x04 /* Shift display/cursor to the right */ + +#define LCD_CMD_FUNCTION_SET 0x20 /* Set function */ +#define LCD_CMD_DATA_LEN_8BITS 0x10 /* Set data length to 8 bits */ +#define LCD_CMD_TWO_LINES 0x08 /* Set to two display lines */ +#define LCD_CMD_FONT_5X10_DOTS 0x04 /* Set char font to 5x10 dots */ + +#define LCD_CMD_SET_CGRAM_ADDR 0x40 /* Set char generator RAM address */ + +#define LCD_CMD_SET_DDRAM_ADDR 0x80 /* Set display data RAM address */ + #define LCD_ESCAPE_LEN 24 /* max chars for LCD escape command */ #define LCD_ESCAPE_CHAR 27 /* use char 27 for escape command */ @@ -228,9 +252,6 @@ static struct { bool initialized; bool must_clear; - /* TODO: use bool here? */ - char left_shift; - int height; int width; int bwidth; @@ -759,7 +780,7 @@ static void long_sleep(int ms) if (in_interrupt()) { mdelay(ms); } else { - current->state = TASK_INTERRUPTIBLE; + __set_current_state(TASK_INTERRUPTIBLE); schedule_timeout((ms * HZ + 999) / 1000); } } @@ -886,7 +907,7 @@ static void lcd_write_data_tilcd(int data) static void lcd_gotoxy(void) { - lcd_write_cmd(0x80 /* set DDRAM address */ + lcd_write_cmd(LCD_CMD_SET_DDRAM_ADDR | (lcd.addr.y ? lcd.hwidth : 0) /* we force the cursor to stay at the end of the line if it wants to go farther */ @@ -994,7 +1015,7 @@ static void lcd_clear_fast_tilcd(void) /* clears the display and resets X/Y */ static void lcd_clear_display(void) { - lcd_write_cmd(0x01); /* clear display */ + lcd_write_cmd(LCD_CMD_DISPLAY_CLEAR); lcd.addr.x = 0; lcd.addr.y = 0; /* we must wait a few milliseconds (15) */ @@ -1008,26 +1029,29 @@ static void lcd_init_display(void) long_sleep(20); /* wait 20 ms after power-up for the paranoid */ - lcd_write_cmd(0x30); /* 8bits, 1 line, small fonts */ + /* 8bits, 1 line, small fonts; let's do it 3 times */ + lcd_write_cmd(LCD_CMD_FUNCTION_SET | LCD_CMD_DATA_LEN_8BITS); long_sleep(10); - lcd_write_cmd(0x30); /* 8bits, 1 line, small fonts */ + lcd_write_cmd(LCD_CMD_FUNCTION_SET | LCD_CMD_DATA_LEN_8BITS); long_sleep(10); - lcd_write_cmd(0x30); /* 8bits, 1 line, small fonts */ + lcd_write_cmd(LCD_CMD_FUNCTION_SET | LCD_CMD_DATA_LEN_8BITS); long_sleep(10); - lcd_write_cmd(0x30 /* set font height and lines number */ - | ((lcd.flags & LCD_FLAG_F) ? 4 : 0) - | ((lcd.flags & LCD_FLAG_N) ? 8 : 0) + /* set font height and lines number */ + lcd_write_cmd(LCD_CMD_FUNCTION_SET | LCD_CMD_DATA_LEN_8BITS + | ((lcd.flags & LCD_FLAG_F) ? LCD_CMD_FONT_5X10_DOTS : 0) + | ((lcd.flags & LCD_FLAG_N) ? LCD_CMD_TWO_LINES : 0) ); long_sleep(10); - lcd_write_cmd(0x08); /* display off, cursor off, blink off */ + /* display off, cursor off, blink off */ + lcd_write_cmd(LCD_CMD_DISPLAY_CTRL); long_sleep(10); - lcd_write_cmd(0x08 /* set display mode */ - | ((lcd.flags & LCD_FLAG_D) ? 4 : 0) - | ((lcd.flags & LCD_FLAG_C) ? 2 : 0) - | ((lcd.flags & LCD_FLAG_B) ? 1 : 0) + lcd_write_cmd(LCD_CMD_DISPLAY_CTRL /* set display mode */ + | ((lcd.flags & LCD_FLAG_D) ? LCD_CMD_DISPLAY_ON : 0) + | ((lcd.flags & LCD_FLAG_C) ? LCD_CMD_CURSOR_ON : 0) + | ((lcd.flags & LCD_FLAG_B) ? LCD_CMD_BLINK_ON : 0) ); lcd_backlight((lcd.flags & LCD_FLAG_L) ? 1 : 0); @@ -1035,7 +1059,7 @@ static void lcd_init_display(void) long_sleep(10); /* entry mode set : increment, cursor shifting */ - lcd_write_cmd(0x06); + lcd_write_cmd(LCD_CMD_ENTRY_MODE | LCD_CMD_CURSOR_INC); lcd_clear_display(); } @@ -1119,7 +1143,7 @@ static inline int handle_lcd_special_code(void) if (lcd.addr.x > 0) { /* back one char if not at end of line */ if (lcd.addr.x < lcd.bwidth) - lcd_write_cmd(0x10); + lcd_write_cmd(LCD_CMD_SHIFT); lcd.addr.x--; } processed = 1; @@ -1127,21 +1151,20 @@ static inline int handle_lcd_special_code(void) case 'r': /* shift cursor right */ if (lcd.addr.x < lcd.width) { /* allow the cursor to pass the end of the line */ - if (lcd.addr.x < - (lcd.bwidth - 1)) - lcd_write_cmd(0x14); + if (lcd.addr.x < (lcd.bwidth - 1)) + lcd_write_cmd(LCD_CMD_SHIFT | + LCD_CMD_SHIFT_RIGHT); lcd.addr.x++; } processed = 1; break; case 'L': /* shift display left */ - lcd.left_shift++; - lcd_write_cmd(0x18); + lcd_write_cmd(LCD_CMD_SHIFT | LCD_CMD_DISPLAY_SHIFT); processed = 1; break; case 'R': /* shift display right */ - lcd.left_shift--; - lcd_write_cmd(0x1C); + lcd_write_cmd(LCD_CMD_SHIFT | LCD_CMD_DISPLAY_SHIFT | + LCD_CMD_SHIFT_RIGHT); processed = 1; break; case 'k': { /* kill end of line */ @@ -1157,7 +1180,6 @@ static inline int handle_lcd_special_code(void) } case 'I': /* reinitialize display */ lcd_init_display(); - lcd.left_shift = 0; processed = 1; break; case 'G': { @@ -1211,7 +1233,7 @@ static inline int handle_lcd_special_code(void) esc++; } - lcd_write_cmd(0x40 | (cgaddr * 8)); + lcd_write_cmd(LCD_CMD_SET_CGRAM_ADDR | (cgaddr * 8)); for (addr = 0; addr < cgoffset; addr++) lcd_write_data(cgbytes[addr]); @@ -1244,21 +1266,29 @@ static inline int handle_lcd_special_code(void) break; } + /* TODO: This indent party here got ugly, clean it! */ /* Check whether one flag was changed */ if (oldflags != lcd.flags) { /* check whether one of B,C,D flags were changed */ if ((oldflags ^ lcd.flags) & (LCD_FLAG_B | LCD_FLAG_C | LCD_FLAG_D)) /* set display mode */ - lcd_write_cmd(0x08 - | ((lcd.flags & LCD_FLAG_D) ? 4 : 0) - | ((lcd.flags & LCD_FLAG_C) ? 2 : 0) - | ((lcd.flags & LCD_FLAG_B) ? 1 : 0)); + lcd_write_cmd(LCD_CMD_DISPLAY_CTRL + | ((lcd.flags & LCD_FLAG_D) + ? LCD_CMD_DISPLAY_ON : 0) + | ((lcd.flags & LCD_FLAG_C) + ? LCD_CMD_CURSOR_ON : 0) + | ((lcd.flags & LCD_FLAG_B) + ? LCD_CMD_BLINK_ON : 0)); /* check whether one of F,N flags was changed */ else if ((oldflags ^ lcd.flags) & (LCD_FLAG_F | LCD_FLAG_N)) - lcd_write_cmd(0x30 - | ((lcd.flags & LCD_FLAG_F) ? 4 : 0) - | ((lcd.flags & LCD_FLAG_N) ? 8 : 0)); + lcd_write_cmd(LCD_CMD_FUNCTION_SET + | LCD_CMD_DATA_LEN_8BITS + | ((lcd.flags & LCD_FLAG_F) + ? LCD_CMD_TWO_LINES : 0) + | ((lcd.flags & LCD_FLAG_N) + ? LCD_CMD_FONT_5X10_DOTS + : 0)); /* check whether L flag was changed */ else if ((oldflags ^ lcd.flags) & (LCD_FLAG_L)) { if (lcd.flags & (LCD_FLAG_L)) @@ -1297,13 +1327,13 @@ static void lcd_write_char(char c) end of the line */ if (lcd.addr.x < lcd.bwidth) /* back one char */ - lcd_write_cmd(0x10); + lcd_write_cmd(LCD_CMD_SHIFT); lcd.addr.x--; } /* replace with a space */ lcd_write_data(' '); /* back one char again */ - lcd_write_cmd(0x10); + lcd_write_cmd(LCD_CMD_SHIFT); break; case '\014': /* quickly clear the display */ |