1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#include <linux/module.h>
21#include <linux/kernel.h>
22#include <linux/init.h>
23#include <linux/gpio.h>
24#include <linux/spi/spi.h>
25#include <linux/delay.h>
26
27#include "fbtft.h"
28
29#define DRVNAME "fb_uc1701"
30#define WIDTH 102
31#define HEIGHT 64
32#define PAGES (HEIGHT / 8)
33
34
35#define LCD_DISPLAY_ENABLE 0xAE
36
37#define LCD_START_LINE 0x40
38
39#define LCD_PAGE_ADDRESS 0xB0
40
41#define LCD_COL_ADDRESS 0x10
42
43#define LCD_BOTTOMVIEW 0xA0
44
45#define LCD_DISPLAY_INVERT 0xA6
46
47#define LCD_ALL_PIXEL 0xA4
48
49#define LCD_BIAS 0xA2
50
51#define LCD_RESET_CMD 0xE2
52
53#define LCD_SCAN_DIR 0xC0
54
55#define LCD_POWER_CONTROL 0x28
56
57#define LCD_VOLTAGE 0x20
58
59#define LCD_VOLUME_MODE 0x81
60
61#define LCD_NO_OP 0xE3
62
63#define LCD_ADV_PROG_CTRL 0xFA
64
65#define LCD_ADV_PROG_CTRL2 0x10
66#define LCD_TEMPCOMP_HIGH 0x80
67
68#define SHIFT_ADDR_NORMAL 0
69
70#define SHIFT_ADDR_TOPVIEW 30
71
72static int init_display(struct fbtft_par *par)
73{
74 par->fbtftops.reset(par);
75
76
77 write_reg(par, LCD_RESET_CMD);
78 mdelay(10);
79
80
81 write_reg(par, LCD_START_LINE);
82
83
84 write_reg(par, LCD_BOTTOMVIEW | 1);
85
86
87 write_reg(par, LCD_SCAN_DIR | 0x00);
88
89
90 write_reg(par, LCD_ALL_PIXEL | 0);
91
92
93 write_reg(par, LCD_DISPLAY_INVERT | 0);
94
95
96 write_reg(par, LCD_BIAS | 0);
97
98
99 write_reg(par, LCD_POWER_CONTROL | 0x07);
100
101
102 write_reg(par, LCD_VOLTAGE | 0x07);
103
104
105 write_reg(par, LCD_VOLUME_MODE);
106 write_reg(par, 0x09);
107 write_reg(par, LCD_NO_OP);
108
109
110 write_reg(par, LCD_ADV_PROG_CTRL);
111 write_reg(par, LCD_ADV_PROG_CTRL2 | LCD_TEMPCOMP_HIGH);
112
113
114 write_reg(par, LCD_DISPLAY_ENABLE | 1);
115
116 return 0;
117}
118
119static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
120{
121
122 write_reg(par, LCD_PAGE_ADDRESS);
123 write_reg(par, 0x00);
124 write_reg(par, LCD_COL_ADDRESS);
125}
126
127static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
128{
129 u16 *vmem16 = (u16 *)par->info->screen_buffer;
130 u8 *buf = par->txbuf.buf;
131 int x, y, i;
132 int ret = 0;
133
134 for (y = 0; y < PAGES; y++) {
135 buf = par->txbuf.buf;
136 for (x = 0; x < WIDTH; x++) {
137 *buf = 0x00;
138 for (i = 0; i < 8; i++)
139 *buf |= (vmem16[((y * 8 * WIDTH) +
140 (i * WIDTH)) + x] ?
141 1 : 0) << i;
142 buf++;
143 }
144
145 write_reg(par, LCD_PAGE_ADDRESS | (u8)y);
146 write_reg(par, 0x00);
147 write_reg(par, LCD_COL_ADDRESS);
148 gpio_set_value(par->gpio.dc, 1);
149 ret = par->fbtftops.write(par, par->txbuf.buf, WIDTH);
150 gpio_set_value(par->gpio.dc, 0);
151 }
152
153 if (ret < 0)
154 dev_err(par->info->device, "write failed and returned: %d\n",
155 ret);
156
157 return ret;
158}
159
160static struct fbtft_display display = {
161 .regwidth = 8,
162 .width = WIDTH,
163 .height = HEIGHT,
164 .fbtftops = {
165 .init_display = init_display,
166 .set_addr_win = set_addr_win,
167 .write_vmem = write_vmem,
168 },
169 .backlight = 1,
170};
171
172FBTFT_REGISTER_DRIVER(DRVNAME, "UltraChip,uc1701", &display);
173
174MODULE_ALIAS("spi:" DRVNAME);
175MODULE_ALIAS("spi:uc1701");
176
177MODULE_DESCRIPTION("FB driver for the UC1701 LCD Controller");
178MODULE_AUTHOR("Juergen Holzmann");
179MODULE_LICENSE("GPL");
180