picvue.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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 = NULL;
  21. DECLARE_MUTEX(pvc_sem);
  22. static void pvc_reg_write(u32 val)
  23. {
  24. *picvue->reg = val;
  25. }
  26. static u32 pvc_reg_read(void)
  27. {
  28. u32 tmp = *picvue->reg;
  29. return tmp;
  30. }
  31. static void pvc_write_byte(u32 data, u8 byte)
  32. {
  33. data |= picvue->e;
  34. pvc_reg_write(data);
  35. data &= ~picvue->data_mask;
  36. data |= byte << picvue->data_shift;
  37. pvc_reg_write(data);
  38. ndelay(220);
  39. pvc_reg_write(data & ~picvue->e);
  40. ndelay(220);
  41. }
  42. static u8 pvc_read_byte(u32 data)
  43. {
  44. u8 byte;
  45. data |= picvue->e;
  46. pvc_reg_write(data);
  47. ndelay(220);
  48. byte = (pvc_reg_read() & picvue->data_mask) >> picvue->data_shift;
  49. data &= ~picvue->e;
  50. pvc_reg_write(data);
  51. ndelay(220);
  52. return byte;
  53. }
  54. static u8 pvc_read_data(void)
  55. {
  56. u32 data = pvc_reg_read();
  57. u8 byte;
  58. data |= picvue->rw;
  59. data &= ~picvue->rs;
  60. pvc_reg_write(data);
  61. ndelay(40);
  62. byte = pvc_read_byte(data);
  63. data |= picvue->rs;
  64. pvc_reg_write(data);
  65. return byte;
  66. }
  67. #define TIMEOUT 1000
  68. static int pvc_wait(void)
  69. {
  70. int i = TIMEOUT;
  71. int err = 0;
  72. while ((pvc_read_data() & PVC_BUSY) && i)
  73. i--;
  74. if (i == 0)
  75. err = -ETIME;
  76. return err;
  77. }
  78. #define MODE_INST 0
  79. #define MODE_DATA 1
  80. static void pvc_write(u8 byte, int mode)
  81. {
  82. u32 data = pvc_reg_read();
  83. data &= ~picvue->rw;
  84. if (mode == MODE_DATA)
  85. data |= picvue->rs;
  86. else
  87. data &= ~picvue->rs;
  88. pvc_reg_write(data);
  89. ndelay(40);
  90. pvc_write_byte(data, byte);
  91. if (mode == MODE_DATA)
  92. data &= ~picvue->rs;
  93. else
  94. data |= picvue->rs;
  95. pvc_reg_write(data);
  96. pvc_wait();
  97. }
  98. void pvc_write_string(const unsigned char *str, u8 addr, int line)
  99. {
  100. int i = 0;
  101. if (line > 0 && (PVC_NLINES > 1))
  102. addr += 0x40 * line;
  103. pvc_write(0x80 | addr, MODE_INST);
  104. while (*str != 0 && i < PVC_LINELEN) {
  105. pvc_write(*str++, MODE_DATA);
  106. i++;
  107. }
  108. }
  109. void pvc_write_string_centered(const unsigned char *str, int line)
  110. {
  111. int len = strlen(str);
  112. u8 addr;
  113. if (len > PVC_VISIBLE_CHARS)
  114. addr = 0;
  115. else
  116. addr = (PVC_VISIBLE_CHARS - strlen(str))/2;
  117. pvc_write_string(str, addr, line);
  118. }
  119. void pvc_dump_string(const unsigned char *str)
  120. {
  121. int len = strlen(str);
  122. pvc_write_string(str, 0, 0);
  123. if (len > PVC_VISIBLE_CHARS)
  124. pvc_write_string(&str[PVC_VISIBLE_CHARS], 0, 1);
  125. }
  126. #define BM_SIZE 8
  127. #define MAX_PROGRAMMABLE_CHARS 8
  128. int pvc_program_cg(int charnum, u8 bitmap[BM_SIZE])
  129. {
  130. int i;
  131. int addr;
  132. if (charnum > MAX_PROGRAMMABLE_CHARS)
  133. return -ENOENT;
  134. addr = charnum * 8;
  135. pvc_write(0x40 | addr, MODE_INST);
  136. for (i=0; i<BM_SIZE; i++)
  137. pvc_write(bitmap[i], MODE_DATA);
  138. return 0;
  139. }
  140. #define FUNC_SET_CMD 0x20
  141. #define EIGHT_BYTE (1 << 4)
  142. #define FOUR_BYTE 0
  143. #define TWO_LINES (1 << 3)
  144. #define ONE_LINE 0
  145. #define LARGE_FONT (1 << 2)
  146. #define SMALL_FONT 0
  147. static void pvc_funcset(u8 cmd)
  148. {
  149. pvc_write(FUNC_SET_CMD | (cmd & (EIGHT_BYTE|TWO_LINES|LARGE_FONT)), 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)), 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");