picvue.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /*
  2. * Picvue PVC160206 display driver
  3. *
  4. * Brian Murphy <brian@murphy.dk>
  5. *
  6. */
  7. #include <linux/kernel.h>
  8. #include <linux/delay.h>
  9. #include <asm/bootinfo.h>
  10. #include <asm/lasat/lasat.h>
  11. #include <linux/module.h>
  12. #include <linux/errno.h>
  13. #include <linux/string.h>
  14. #include "picvue.h"
  15. #define PVC_BUSY 0x80
  16. #define PVC_NLINES 2
  17. #define PVC_DISPMEM 80
  18. #define PVC_LINELEN PVC_DISPMEM / PVC_NLINES
  19. struct pvc_defs *picvue;
  20. static void pvc_reg_write(u32 val)
  21. {
  22. *picvue->reg = val;
  23. }
  24. static u32 pvc_reg_read(void)
  25. {
  26. u32 tmp = *picvue->reg;
  27. return tmp;
  28. }
  29. static void pvc_write_byte(u32 data, u8 byte)
  30. {
  31. data |= picvue->e;
  32. pvc_reg_write(data);
  33. data &= ~picvue->data_mask;
  34. data |= byte << picvue->data_shift;
  35. pvc_reg_write(data);
  36. ndelay(220);
  37. pvc_reg_write(data & ~picvue->e);
  38. ndelay(220);
  39. }
  40. static u8 pvc_read_byte(u32 data)
  41. {
  42. u8 byte;
  43. data |= picvue->e;
  44. pvc_reg_write(data);
  45. ndelay(220);
  46. byte = (pvc_reg_read() & picvue->data_mask) >> picvue->data_shift;
  47. data &= ~picvue->e;
  48. pvc_reg_write(data);
  49. ndelay(220);
  50. return byte;
  51. }
  52. static u8 pvc_read_data(void)
  53. {
  54. u32 data = pvc_reg_read();
  55. u8 byte;
  56. data |= picvue->rw;
  57. data &= ~picvue->rs;
  58. pvc_reg_write(data);
  59. ndelay(40);
  60. byte = pvc_read_byte(data);
  61. data |= picvue->rs;
  62. pvc_reg_write(data);
  63. return byte;
  64. }
  65. #define TIMEOUT 1000
  66. static int pvc_wait(void)
  67. {
  68. int i = TIMEOUT;
  69. int err = 0;
  70. while ((pvc_read_data() & PVC_BUSY) && i)
  71. i--;
  72. if (i == 0)
  73. err = -ETIME;
  74. return err;
  75. }
  76. #define MODE_INST 0
  77. #define MODE_DATA 1
  78. static void pvc_write(u8 byte, int mode)
  79. {
  80. u32 data = pvc_reg_read();
  81. data &= ~picvue->rw;
  82. if (mode == MODE_DATA)
  83. data |= picvue->rs;
  84. else
  85. data &= ~picvue->rs;
  86. pvc_reg_write(data);
  87. ndelay(40);
  88. pvc_write_byte(data, byte);
  89. if (mode == MODE_DATA)
  90. data &= ~picvue->rs;
  91. else
  92. data |= picvue->rs;
  93. pvc_reg_write(data);
  94. pvc_wait();
  95. }
  96. void pvc_write_string(const unsigned char *str, u8 addr, int line)
  97. {
  98. int i = 0;
  99. if (line > 0 && (PVC_NLINES > 1))
  100. addr += 0x40 * line;
  101. pvc_write(0x80 | addr, MODE_INST);
  102. while (*str != 0 && i < PVC_LINELEN) {
  103. pvc_write(*str++, MODE_DATA);
  104. i++;
  105. }
  106. }
  107. void pvc_write_string_centered(const unsigned char *str, int line)
  108. {
  109. int len = strlen(str);
  110. u8 addr;
  111. if (len > PVC_VISIBLE_CHARS)
  112. addr = 0;
  113. else
  114. addr = (PVC_VISIBLE_CHARS - strlen(str))/2;
  115. pvc_write_string(str, addr, line);
  116. }
  117. void pvc_dump_string(const unsigned char *str)
  118. {
  119. int len = strlen(str);
  120. pvc_write_string(str, 0, 0);
  121. if (len > PVC_VISIBLE_CHARS)
  122. pvc_write_string(&str[PVC_VISIBLE_CHARS], 0, 1);
  123. }
  124. #define BM_SIZE 8
  125. #define MAX_PROGRAMMABLE_CHARS 8
  126. int pvc_program_cg(int charnum, u8 bitmap[BM_SIZE])
  127. {
  128. int i;
  129. int addr;
  130. if (charnum > MAX_PROGRAMMABLE_CHARS)
  131. return -ENOENT;
  132. addr = charnum * 8;
  133. pvc_write(0x40 | addr, MODE_INST);
  134. for (i = 0; i < BM_SIZE; i++)
  135. pvc_write(bitmap[i], MODE_DATA);
  136. return 0;
  137. }
  138. #define FUNC_SET_CMD 0x20
  139. #define EIGHT_BYTE (1 << 4)
  140. #define FOUR_BYTE 0
  141. #define TWO_LINES (1 << 3)
  142. #define ONE_LINE 0
  143. #define LARGE_FONT (1 << 2)
  144. #define SMALL_FONT 0
  145. static void pvc_funcset(u8 cmd)
  146. {
  147. pvc_write(FUNC_SET_CMD | (cmd & (EIGHT_BYTE|TWO_LINES|LARGE_FONT)),
  148. MODE_INST);
  149. }
  150. #define ENTRYMODE_CMD 0x4
  151. #define AUTO_INC (1 << 1)
  152. #define AUTO_DEC 0
  153. #define CURSOR_FOLLOWS_DISP (1 << 0)
  154. static void pvc_entrymode(u8 cmd)
  155. {
  156. pvc_write(ENTRYMODE_CMD | (cmd & (AUTO_INC|CURSOR_FOLLOWS_DISP)),
  157. MODE_INST);
  158. }
  159. #define DISP_CNT_CMD 0x08
  160. #define DISP_OFF 0
  161. #define DISP_ON (1 << 2)
  162. #define CUR_ON (1 << 1)
  163. #define CUR_BLINK (1 << 0)
  164. void pvc_dispcnt(u8 cmd)
  165. {
  166. pvc_write(DISP_CNT_CMD | (cmd & (DISP_ON|CUR_ON|CUR_BLINK)), MODE_INST);
  167. }
  168. #define MOVE_CMD 0x10
  169. #define DISPLAY (1 << 3)
  170. #define CURSOR 0
  171. #define RIGHT (1 << 2)
  172. #define LEFT 0
  173. void pvc_move(u8 cmd)
  174. {
  175. pvc_write(MOVE_CMD | (cmd & (DISPLAY|RIGHT)), MODE_INST);
  176. }
  177. #define CLEAR_CMD 0x1
  178. void pvc_clear(void)
  179. {
  180. pvc_write(CLEAR_CMD, MODE_INST);
  181. }
  182. #define HOME_CMD 0x2
  183. void pvc_home(void)
  184. {
  185. pvc_write(HOME_CMD, MODE_INST);
  186. }
  187. int pvc_init(void)
  188. {
  189. u8 cmd = EIGHT_BYTE;
  190. if (PVC_NLINES == 2)
  191. cmd |= (SMALL_FONT|TWO_LINES);
  192. else
  193. cmd |= (LARGE_FONT|ONE_LINE);
  194. pvc_funcset(cmd);
  195. pvc_dispcnt(DISP_ON);
  196. pvc_entrymode(AUTO_INC);
  197. pvc_clear();
  198. pvc_write_string_centered("Display", 0);
  199. pvc_write_string_centered("Initialized", 1);
  200. return 0;
  201. }
  202. module_init(pvc_init);
  203. MODULE_LICENSE("GPL");