aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/linux/linux-2.6.38/ts72xx/0021-TS-72XX-LCD-console-driver.patch
blob: d5cf0c56142f0b7fd5adc9b42f617a48e5f7a42c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
From 6cc9932f888449862cc9364d799fc84e9ea7b007 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20=C5=A0tetiar?= <ynezz@true.cz>
Date: Sun, 13 Mar 2011 21:15:10 +0100
Subject: [PATCH 21/24] TS-72XX LCD console driver
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Petr Štetiar <ynezz@true.cz>
---
 arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h |    4 +
 drivers/video/console/Kconfig                   |   21 +
 drivers/video/console/Makefile                  |    2 +
 drivers/video/console/ts72xx_con.c              |  442 +++++++++++++++++++++++
 4 files changed, 469 insertions(+), 0 deletions(-)
 create mode 100644 drivers/video/console/ts72xx_con.c

diff --git a/arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h b/arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h
index 87a5bfe..39e5b5a 100644
--- a/arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h
+++ b/arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h
@@ -111,6 +111,10 @@
 #define EP93XX_GPIO_B_INT_DEBOUNCE	EP93XX_GPIO_REG(0xc4)
 #define EP93XX_GPIO_EEDRIVE		EP93XX_GPIO_REG(0xc8)
 
+/* ts72xx lcd console driver quick "hack" */
+#define EP93XX_GPIO_A_DATA		EP93XX_GPIO_REG(0x00)
+#define EP93XX_GPIO_A_DIRECTION		EP93XX_GPIO_REG(0x10)
+
 #define EP93XX_AAC_PHYS_BASE		EP93XX_APB_PHYS(0x00080000)
 #define EP93XX_AAC_BASE			EP93XX_APB_IOMEM(0x00080000)
 
diff --git a/drivers/video/console/Kconfig b/drivers/video/console/Kconfig
index 2209e35..8afef58 100644
--- a/drivers/video/console/Kconfig
+++ b/drivers/video/console/Kconfig
@@ -89,6 +89,27 @@ config DUMMY_CONSOLE_ROWS
           The default value is 64, which should fit a 1280x1024 monitor.
           Select 25 if you use a 640x480 resolution by default.
 
+config TS72XX_CONSOLE
+	tristate "TS-72xx text LCD console"
+	depends on ARCH_EP93XX && MACH_TS72XX
+	help
+	  Say Y to build a console driver for TS-72xx LCD (2x7) header.
+	  LCD display must be compatible with HD44780 controller.
+
+config TS72XX_CONSOLE_COLUMNS
+        int "Initial number of console screen columns"
+        depends on TS72XX_CONSOLE
+        default "20"
+        help
+          Dependant to your text LCD, 16 or 20 are legacy values.
+
+config TS72XX_CONSOLE_ROWS
+        int "Initial number of console screen rows"
+        depends on TS72XX_CONSOLE
+        default "4"
+        help
+          Dependant to your text LCD, 2 or 4 are legacy values.
+
 config FRAMEBUFFER_CONSOLE
 	tristate "Framebuffer Console support"
 	depends on FB
diff --git a/drivers/video/console/Makefile b/drivers/video/console/Makefile
index a862e91..e0f9269 100644
--- a/drivers/video/console/Makefile
+++ b/drivers/video/console/Makefile
@@ -25,6 +25,8 @@ obj-$(CONFIG_SGI_NEWPORT_CONSOLE) += newport_con.o font.o
 obj-$(CONFIG_STI_CONSOLE)         += sticon.o sticore.o font.o
 obj-$(CONFIG_VGA_CONSOLE)         += vgacon.o
 obj-$(CONFIG_MDA_CONSOLE)         += mdacon.o
+obj-$(CONFIG_TS72XX_CONSOLE)      += ts72xx_con.o
+
 obj-$(CONFIG_FRAMEBUFFER_CONSOLE) += fbcon.o bitblit.o font.o softcursor.o
 ifeq ($(CONFIG_FB_TILEBLITTING),y)
 obj-$(CONFIG_FRAMEBUFFER_CONSOLE)     += tileblit.o
diff --git a/drivers/video/console/ts72xx_con.c b/drivers/video/console/ts72xx_con.c
new file mode 100644
index 0000000..a6ac61d
--- /dev/null
+++ b/drivers/video/console/ts72xx_con.c
@@ -0,0 +1,442 @@
+/*
+ *  TS-72XX lcd console driver for Technologic Systems boards.
+ *
+ * (c) Copyright 2008  Matthieu Crapet <mcrapet@gmail.com>
+ * Based on linux/drivers/video/console/dummycon.c
+ * Thanks to Jim Jackson (lcdd-0.2beta)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ * Note: Port H (LCD_EN, LCD_RS, LCD_WR) uses the new generic GPIO API.
+ *       Port A is used manually used. To fix in future.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/console.h>
+#include <linux/vt_kern.h>
+#include <linux/delay.h>
+#include <mach/hardware.h>
+#include <mach/gpio.h>
+#include <asm/io.h>
+
+#define DRV_VERSION "0.3"
+#define PFX "ts72xx_con: "
+
+#define LCD_COLUMNS  CONFIG_TS72XX_CONSOLE_COLUMNS
+#define LCD_ROWS     CONFIG_TS72XX_CONSOLE_ROWS
+
+/* HD44780 instruction set */
+#define CMD_CLEAR                                        (0x01)
+#define CMD_CURSOR_HOME                                  (0x02)
+#define CMD_ENTRY_MODE(cursor_dir, display_shift)        (0x04|(2*cursor_dir)|display_shift)
+#define CMD_DISPLAY_ONOFF(dis_on, cur_on, cur_blink_on)  (0x08|(4*dis_on)|(2*cur_on)|cur_blink_on)
+#define CMD_FUNCTION_SET(intf_8bit, n, f)                (0x20|(16*intf_8bit)|(8*n)|(4*f))
+#define CMD_DDRAM_ADDR(a)                                (0x80|(a))
+
+/* Port H, bit 3:5 */
+#define LCD_EN   EP93XX_GPIO_LINE_H(3)
+#define LCD_RS   EP93XX_GPIO_LINE_H(4)
+#define LCD_WR   EP93XX_GPIO_LINE_H(5)
+
+static struct gpio lcd_gpios[] = {
+	{ LCD_EN, GPIOF_OUT_INIT_LOW, "LCD enable" },
+	{ LCD_RS, GPIOF_OUT_INIT_LOW, "LCD data" },
+	{ LCD_WR, GPIOF_OUT_INIT_LOW, "LCD r/w" },
+};
+
+/* Timings */
+#define SETUP_TIME   200
+#define ENABLE_TIME  800
+#define HOLD_TIME    200
+
+void hd44780_delay(int i)
+{
+	ndelay(i);
+}
+
+/* Prototypes */
+static void hd44780_wait(void);
+static void hd44780_send_data(unsigned char data);
+static void hd44780_send_command(unsigned char command);
+static void hd44780_init(void);
+static void hd44780_deinit(void);
+static int hd44780_gotoxy(int x, int y);
+
+
+/* HD44780 controller */
+
+static void hd44780_wait(void)
+{
+  int i;
+  int b = 0;
+  unsigned char c;
+
+  __raw_writeb(0x00, EP93XX_GPIO_A_DIRECTION);   // bus input
+  gpio_set_value(LCD_RS, 0);                     // low for control registers
+  gpio_set_value(LCD_WR, 1);                     // read command
+
+  do {
+    i = SETUP_TIME;
+    hd44780_delay(i);
+
+    gpio_set_value(LCD_EN, 1);
+
+    i = ENABLE_TIME;
+    hd44780_delay(i);
+
+    c = __raw_readb(EP93XX_GPIO_A_DATA);
+    gpio_set_value(LCD_EN, 0);
+
+    b++;
+  } while (c & 0x80); // busy flag
+
+  i = HOLD_TIME;
+  hd44780_delay(i);
+}
+
+
+static void hd44780_send_data(unsigned char data)
+{
+  int i;
+
+  __raw_writeb(0xFF, EP93XX_GPIO_A_DIRECTION);   // bus output
+  gpio_set_value(LCD_RS, 1);                     // high for data
+  gpio_set_value(LCD_WR, 0);                     // write data
+
+  i = SETUP_TIME;
+  hd44780_delay(i);
+
+  __raw_writeb(data, EP93XX_GPIO_A_DATA);
+  gpio_set_value(LCD_EN, 1);
+
+  i = ENABLE_TIME;
+  hd44780_delay(i);
+
+  gpio_set_value(LCD_EN, 0);
+
+  i = HOLD_TIME;
+  hd44780_delay(i);
+}
+
+
+static void hd44780_send_command(unsigned char command)
+{
+  int i;
+
+  __raw_writeb(0xFF, EP93XX_GPIO_A_DIRECTION);   // bus output
+  gpio_set_value(LCD_RS, 0);                     // low for control registers
+  gpio_set_value(LCD_WR, 0);                     // write command
+
+  i = SETUP_TIME;
+  hd44780_delay(i);
+
+  __raw_writeb(command, EP93XX_GPIO_A_DATA);
+  gpio_set_value(LCD_EN, 1);
+
+  i = ENABLE_TIME;
+  hd44780_delay(i);
+
+  gpio_set_value(LCD_EN, 0);
+
+  i = HOLD_TIME;
+  hd44780_delay(i);
+}
+
+static void hd44780_deinit()
+{
+	gpio_free_array(lcd_gpios, ARRAY_SIZE(lcd_gpios));
+}
+
+static void hd44780_init(void)
+{
+	int i;
+	int err;
+
+	err = gpio_request_array(lcd_gpios, ARRAY_SIZE(lcd_gpios));
+  	if (err) {
+		printk(KERN_ERR PFX "error while requesting GPIO pins\n");
+		return;
+	}
+
+	/* Port A (8 bits) is data bus */
+	__raw_writeb(0x00, EP93XX_GPIO_A_DATA);
+	__raw_writeb(0x00, EP93XX_GPIO_A_DIRECTION);
+
+	/* 8-bit mode, double line, 5x7 dot character format */
+	hd44780_send_command(CMD_FUNCTION_SET(1,1,1));
+	i = 5000;
+	hd44780_delay(i);
+
+	/* Display on and blink cursor on */
+	hd44780_send_command(CMD_DISPLAY_ONOFF(1,1,1));
+	hd44780_wait();
+
+	/* Cursor in increment position and shift is invisible */
+	hd44780_send_command(CMD_ENTRY_MODE(0,0));
+	hd44780_wait();
+
+	/* Clean display and return cursor to home position */
+	hd44780_send_command(CMD_CLEAR);
+	hd44780_wait();
+}
+
+
+static int hd44780_gotoxy(int x, int y)
+{
+  const unsigned char lines[4] = { 0x00, 0x40, 0x14, 0x54 };
+
+  if ((x == 0) && (y == 0)) {
+    hd44780_send_command(CMD_CURSOR_HOME);
+    hd44780_wait();
+  } else if (y < 4) {
+    hd44780_send_command(CMD_DDRAM_ADDR(lines[y]+x));
+    hd44780_wait();
+  }
+
+  return 0;
+}
+
+
+/* Console operation functions */
+
+static const char *lcdcon_startup(void)
+{
+  return "ts72xx lcd console";
+}
+
+
+static void lcdcon_init(struct vc_data *vc, int init)
+{
+  hd44780_init();
+
+  vc->vc_can_do_color = 0;
+  vc->vc_video_erase_char = 0x20;
+
+  if (init) {
+    vc->vc_cols = LCD_COLUMNS;
+    vc->vc_rows = LCD_ROWS;
+  } else
+    vc_resize(vc, LCD_COLUMNS, LCD_ROWS);
+
+}
+
+
+static void lcdcon_deinit(struct vc_data *vc)
+{
+	hd44780_deinit();
+}
+
+
+static void lcdcon_clear(struct vc_data *vc, int sy, int sx,
+    int height, int width)
+{
+  int i, j;
+
+  if (!height || !width)
+    return;
+
+  for (i = 0; i < height; i++) {
+    hd44780_gotoxy(sx, sy + i);
+    for (j = 0; j < width; j++) {
+      hd44780_send_data((unsigned char)vc->vc_video_erase_char);
+      hd44780_wait();
+    }
+  }
+
+}
+
+
+static int lcdcon_blank(struct vc_data *vc, int blank, int mode_switch)
+{
+  unsigned char c;
+
+  if (blank == 0) {
+    c = CMD_DISPLAY_ONOFF(1,1,1);    /* Display on */
+  } else {
+    c = CMD_DISPLAY_ONOFF(0,1,1);    /* Display off */
+  }
+
+  hd44780_send_command(c);
+  hd44780_wait();
+
+  return 1;
+}
+
+
+static int lcdcon_set_palette(struct vc_data *vc, unsigned char *table)
+{
+  return -EINVAL;
+}
+
+
+static void lcdcon_putc(struct vc_data *vc, int c, int y, int x)
+{
+  if (vc->vc_mode != KD_TEXT)
+    return;
+
+  hd44780_gotoxy(x, y);
+  hd44780_send_data((unsigned char)c);
+  hd44780_wait();
+}
+
+
+static void lcdcon_putcs(struct vc_data *vc, const unsigned short *s,
+    int count, int y, int x)
+{
+  if (vc->vc_mode != KD_TEXT)
+    return;
+
+  hd44780_gotoxy(x, y);
+  while (count--) {
+    hd44780_send_data((unsigned char)(*s));
+    hd44780_wait();
+    s++;
+  }
+
+}
+
+
+static void lcdcon_cursor(struct vc_data *vc, int mode)
+{
+  hd44780_gotoxy(vc->vc_x, vc->vc_y);
+
+  switch (mode) {
+    case CM_ERASE:
+      hd44780_send_command(CMD_DISPLAY_ONOFF(1,0,0)); // Cursor off
+      hd44780_wait();
+      break;
+
+    case CM_DRAW:
+      hd44780_send_command(CMD_DISPLAY_ONOFF(1,1,1)); // Cursor on, Blinking on
+      hd44780_wait();
+      break;
+
+    case CM_MOVE:
+      printk(KERN_NOTICE PFX "lcdcon_cursor CM_MOVE not implemented\n");
+      break;
+  }
+
+}
+
+
+static int lcdcon_scroll(struct vc_data *vc, int t, int b, int dir, int count)
+{
+  int i;
+
+  if (!count)
+    return 0;
+
+  /* Special case */
+  //if (t || b != vc->vc_rows)
+  // scroll area
+
+  switch (dir) {
+    case SM_UP:
+      if (count > vc->vc_rows)
+        count = vc->vc_rows;
+
+      for (i = 0; i < (vc->vc_rows - count); i++) {
+        lcdcon_putcs(vc, vc->vc_screenbuf + (vc->vc_y - i)*vc->vc_cols,
+            vc->vc_cols, vc->vc_y - i -1, 0);
+      }
+
+      /* Clear last line */
+      hd44780_gotoxy(0, vc->vc_y);
+      for (i = 0; i < vc->vc_cols; i++) {
+        hd44780_send_data((unsigned char)vc->vc_video_erase_char);
+        hd44780_wait();
+      }
+      break;
+
+    case SM_DOWN:
+      printk(KERN_NOTICE PFX "lcdcon_scroll DOWN (t=%d b=%d count=%d) not implemtented\n", t,b,count);
+      break;
+  }
+
+  return 0;
+}
+
+
+static void lcdcon_bmove(struct vc_data *vc, int sy, int sx,
+    int dy, int dx, int height, int width)
+{
+  int i, j;
+
+  if (!height || !width)
+    return;
+
+  for (i = 0; i < height; i++) {
+    hd44780_gotoxy(dx, dy + i);
+    for (j = 0; j < width; j++) {
+      hd44780_send_data((unsigned char)(*(vc->vc_screenbuf +
+              (sy+i)*vc->vc_cols + (sx+j) )));
+      hd44780_wait();
+    }
+  }
+}
+
+
+static int lcdcon_dummy(void)
+{
+  return 0;
+}
+
+#define DUMMY (void *)lcdcon_dummy
+
+
+/* Main structure */
+const struct consw ts72xx_lcd_con = {
+  .owner =    THIS_MODULE,
+  .con_startup = lcdcon_startup,
+  .con_init    = lcdcon_init,
+  .con_deinit  = lcdcon_deinit,
+  .con_clear   = lcdcon_clear,
+  .con_putc    = lcdcon_putc,
+  .con_putcs   = lcdcon_putcs,
+  .con_cursor  = lcdcon_cursor,
+  .con_scroll  = lcdcon_scroll,
+  .con_bmove   = lcdcon_bmove,
+  .con_switch  = DUMMY,
+  .con_blank   = lcdcon_blank,
+
+  /* We cannot change color, fonts on character LCD */
+  .con_font_set     = DUMMY,
+  .con_font_get     = DUMMY,
+  .con_font_default = DUMMY,
+  .con_font_copy    = DUMMY,
+  .con_set_palette  = lcdcon_set_palette,
+
+  //.con_scrolldelta   = lcdcon_scrolldelta,
+  //.con_set_origin    = DUMMY,
+  //.con_save_screen   = lcdcon_save_screen,
+  //.con_build_attr    = lcdcon_build_attr,
+  //.con_invert_region = lcdcon_invert_region,
+  //.con_screen_pos    = lcdcon_screen_pos,
+  //.con_getxy         = lcdcon_getxy,
+};
+
+/* Module functions */
+
+static int __init ts72xx_lcd_init(void)
+{
+  printk(KERN_NOTICE "TS-72xx lcd console driver v" DRV_VERSION " loaded\n");
+  return take_over_console(&ts72xx_lcd_con, 0, MAX_NR_CONSOLES-1, 1);
+}
+
+static void __exit ts72xx_lcd_exit(void)
+{
+  printk(KERN_NOTICE "TS-72xx lcd console driver v" DRV_VERSION " unloaded\n");
+  unregister_con_driver(&ts72xx_lcd_con);
+}
+
+MODULE_AUTHOR("Matthieu Crapet <mcrapet@gmail.com>");
+MODULE_DESCRIPTION("TS-72xx lcd console driver");
+MODULE_LICENSE("GPL");
+MODULE_VERSION(DRV_VERSION);
+
+module_init(ts72xx_lcd_init);
+module_exit(ts72xx_lcd_exit);
-- 
1.7.1