picvue.c 4.3 KB

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