1 // SPDX-License-Identifier: GPL-2.0-only
3 * Picvue PVC160206 display driver
5 * Brian Murphy <brian@murphy.dk>
8 #include <linux/kernel.h>
9 #include <linux/delay.h>
10 #include <asm/bootinfo.h>
11 #include <asm/lasat/lasat.h>
12 #include <linux/module.h>
13 #include <linux/errno.h>
14 #include <linux/string.h>
20 #define PVC_DISPMEM 80
21 #define PVC_LINELEN PVC_DISPMEM / PVC_NLINES
23 struct pvc_defs
*picvue
;
25 static void pvc_reg_write(u32 val
)
30 static u32
pvc_reg_read(void)
32 u32 tmp
= *picvue
->reg
;
36 static void pvc_write_byte(u32 data
, u8 byte
)
40 data
&= ~picvue
->data_mask
;
41 data
|= byte
<< picvue
->data_shift
;
44 pvc_reg_write(data
& ~picvue
->e
);
48 static u8
pvc_read_byte(u32 data
)
55 byte
= (pvc_reg_read() & picvue
->data_mask
) >> picvue
->data_shift
;
62 static u8
pvc_read_data(void)
64 u32 data
= pvc_reg_read();
70 byte
= pvc_read_byte(data
);
77 static int pvc_wait(void)
82 while ((pvc_read_data() & PVC_BUSY
) && i
)
92 static void pvc_write(u8 byte
, int mode
)
94 u32 data
= pvc_reg_read();
96 if (mode
== MODE_DATA
)
102 pvc_write_byte(data
, byte
);
103 if (mode
== MODE_DATA
)
111 void pvc_write_string(const unsigned char *str
, u8 addr
, int line
)
115 if (line
> 0 && (PVC_NLINES
> 1))
117 pvc_write(0x80 | addr
, MODE_INST
);
119 while (*str
!= 0 && i
< PVC_LINELEN
) {
120 pvc_write(*str
++, MODE_DATA
);
125 void pvc_write_string_centered(const unsigned char *str
, int line
)
127 int len
= strlen(str
);
130 if (len
> PVC_VISIBLE_CHARS
)
133 addr
= (PVC_VISIBLE_CHARS
- strlen(str
))/2;
135 pvc_write_string(str
, addr
, line
);
138 void pvc_dump_string(const unsigned char *str
)
140 int len
= strlen(str
);
142 pvc_write_string(str
, 0, 0);
143 if (len
> PVC_VISIBLE_CHARS
)
144 pvc_write_string(&str
[PVC_VISIBLE_CHARS
], 0, 1);
148 #define MAX_PROGRAMMABLE_CHARS 8
149 int pvc_program_cg(int charnum
, u8 bitmap
[BM_SIZE
])
154 if (charnum
> MAX_PROGRAMMABLE_CHARS
)
158 pvc_write(0x40 | addr
, MODE_INST
);
160 for (i
= 0; i
< BM_SIZE
; i
++)
161 pvc_write(bitmap
[i
], MODE_DATA
);
165 #define FUNC_SET_CMD 0x20
166 #define EIGHT_BYTE (1 << 4)
168 #define TWO_LINES (1 << 3)
170 #define LARGE_FONT (1 << 2)
173 static void pvc_funcset(u8 cmd
)
175 pvc_write(FUNC_SET_CMD
| (cmd
& (EIGHT_BYTE
|TWO_LINES
|LARGE_FONT
)),
179 #define ENTRYMODE_CMD 0x4
180 #define AUTO_INC (1 << 1)
182 #define CURSOR_FOLLOWS_DISP (1 << 0)
184 static void pvc_entrymode(u8 cmd
)
186 pvc_write(ENTRYMODE_CMD
| (cmd
& (AUTO_INC
|CURSOR_FOLLOWS_DISP
)),
190 #define DISP_CNT_CMD 0x08
192 #define DISP_ON (1 << 2)
193 #define CUR_ON (1 << 1)
194 #define CUR_BLINK (1 << 0)
195 void pvc_dispcnt(u8 cmd
)
197 pvc_write(DISP_CNT_CMD
| (cmd
& (DISP_ON
|CUR_ON
|CUR_BLINK
)), MODE_INST
);
200 #define MOVE_CMD 0x10
201 #define DISPLAY (1 << 3)
203 #define RIGHT (1 << 2)
205 void pvc_move(u8 cmd
)
207 pvc_write(MOVE_CMD
| (cmd
& (DISPLAY
|RIGHT
)), MODE_INST
);
210 #define CLEAR_CMD 0x1
213 pvc_write(CLEAR_CMD
, MODE_INST
);
219 pvc_write(HOME_CMD
, MODE_INST
);
227 cmd
|= (SMALL_FONT
|TWO_LINES
);
229 cmd
|= (LARGE_FONT
|ONE_LINE
);
231 pvc_dispcnt(DISP_ON
);
232 pvc_entrymode(AUTO_INC
);
235 pvc_write_string_centered("Display", 0);
236 pvc_write_string_centered("Initialized", 1);
241 module_init(pvc_init
);
242 MODULE_LICENSE("GPL");