1
2
3
4
5
6
7
8
9
10#include <linux/module.h>
11#include <linux/kernel.h>
12#include <linux/init.h>
13#include <linux/delay.h>
14
15#include "fbtft.h"
16
17#define DRVNAME "fb_ili9325"
18#define WIDTH 240
19#define HEIGHT 320
20#define BPP 16
21#define FPS 20
22#define DEFAULT_GAMMA "0F 00 7 2 0 0 6 5 4 1\n" \
23 "04 16 2 7 6 3 2 1 7 7"
24
25static unsigned int bt = 6;
26module_param(bt, uint, 0000);
27MODULE_PARM_DESC(bt, "Sets the factor used in the step-up circuits");
28
29static unsigned int vc = 0x03;
30module_param(vc, uint, 0000);
31MODULE_PARM_DESC(vc, "Sets the ratio factor of Vci to generate the reference voltages Vci1");
32
33static unsigned int vrh = 0x0d;
34module_param(vrh, uint, 0000);
35MODULE_PARM_DESC(vrh, "Set the amplifying rate (1.6 ~ 1.9) of Vci applied to output the VREG1OUT");
36
37static unsigned int vdv = 0x12;
38module_param(vdv, uint, 0000);
39MODULE_PARM_DESC(vdv, "Select the factor of VREG1OUT to set the amplitude of Vcom");
40
41static unsigned int vcm = 0x0a;
42module_param(vcm, uint, 0000);
43MODULE_PARM_DESC(vcm, "Set the internal VcomH voltage");
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83static int init_display(struct fbtft_par *par)
84{
85 par->fbtftops.reset(par);
86
87 bt &= 0x07;
88 vc &= 0x07;
89 vrh &= 0x0f;
90 vdv &= 0x1f;
91 vcm &= 0x3f;
92
93
94
95
96 write_reg(par, 0x00E3, 0x3008);
97 write_reg(par, 0x00E7, 0x0012);
98 write_reg(par, 0x00EF, 0x1231);
99 write_reg(par, 0x0001, 0x0100);
100 write_reg(par, 0x0002, 0x0700);
101 write_reg(par, 0x0004, 0x0000);
102 write_reg(par, 0x0008, 0x0207);
103 write_reg(par, 0x0009, 0x0000);
104 write_reg(par, 0x000A, 0x0000);
105 write_reg(par, 0x000C, 0x0000);
106 write_reg(par, 0x000D, 0x0000);
107 write_reg(par, 0x000F, 0x0000);
108
109
110 write_reg(par, 0x0010, 0x0000);
111 write_reg(par, 0x0011, 0x0007);
112 write_reg(par, 0x0012, 0x0000);
113 write_reg(par, 0x0013, 0x0000);
114 mdelay(200);
115 write_reg(par, 0x0010,
116 BIT(12) | (bt << 8) | BIT(7) | BIT(4));
117 write_reg(par, 0x0011, 0x220 | vc);
118 mdelay(50);
119 write_reg(par, 0x0012, vrh);
120 mdelay(50);
121 write_reg(par, 0x0013, vdv << 8);
122 write_reg(par, 0x0029, vcm);
123 write_reg(par, 0x002B, 0x000C);
124 mdelay(50);
125 write_reg(par, 0x0020, 0x0000);
126 write_reg(par, 0x0021, 0x0000);
127
128
129 write_reg(par, 0x0050, 0x0000);
130 write_reg(par, 0x0051, 0x00EF);
131 write_reg(par, 0x0052, 0x0000);
132 write_reg(par, 0x0053, 0x013F);
133 write_reg(par, 0x0060, 0xA700);
134 write_reg(par, 0x0061, 0x0001);
135 write_reg(par, 0x006A, 0x0000);
136
137
138 write_reg(par, 0x0080, 0x0000);
139 write_reg(par, 0x0081, 0x0000);
140 write_reg(par, 0x0082, 0x0000);
141 write_reg(par, 0x0083, 0x0000);
142 write_reg(par, 0x0084, 0x0000);
143 write_reg(par, 0x0085, 0x0000);
144
145
146 write_reg(par, 0x0090, 0x0010);
147 write_reg(par, 0x0092, 0x0600);
148 write_reg(par, 0x0007, 0x0133);
149
150 return 0;
151}
152
153static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
154{
155 switch (par->info->var.rotate) {
156
157
158 case 0:
159 write_reg(par, 0x0020, xs);
160 write_reg(par, 0x0021, ys);
161 break;
162 case 180:
163 write_reg(par, 0x0020, WIDTH - 1 - xs);
164 write_reg(par, 0x0021, HEIGHT - 1 - ys);
165 break;
166 case 270:
167 write_reg(par, 0x0020, WIDTH - 1 - ys);
168 write_reg(par, 0x0021, xs);
169 break;
170 case 90:
171 write_reg(par, 0x0020, ys);
172 write_reg(par, 0x0021, HEIGHT - 1 - xs);
173 break;
174 }
175 write_reg(par, 0x0022);
176}
177
178static int set_var(struct fbtft_par *par)
179{
180 switch (par->info->var.rotate) {
181
182 case 0:
183 write_reg(par, 0x03, 0x0030 | (par->bgr << 12));
184 break;
185 case 180:
186 write_reg(par, 0x03, 0x0000 | (par->bgr << 12));
187 break;
188 case 270:
189 write_reg(par, 0x03, 0x0028 | (par->bgr << 12));
190 break;
191 case 90:
192 write_reg(par, 0x03, 0x0018 | (par->bgr << 12));
193 break;
194 }
195
196 return 0;
197}
198
199
200
201
202
203
204#define CURVE(num, idx) curves[(num) * par->gamma.num_values + (idx)]
205static int set_gamma(struct fbtft_par *par, u32 *curves)
206{
207 static const unsigned long mask[] = {
208 0x1f, 0x1f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
209 0x1f, 0x1f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
210 };
211 int i, j;
212
213
214 for (i = 0; i < 2; i++)
215 for (j = 0; j < 10; j++)
216 CURVE(i, j) &= mask[i * par->gamma.num_values + j];
217
218 write_reg(par, 0x0030, CURVE(0, 5) << 8 | CURVE(0, 4));
219 write_reg(par, 0x0031, CURVE(0, 7) << 8 | CURVE(0, 6));
220 write_reg(par, 0x0032, CURVE(0, 9) << 8 | CURVE(0, 8));
221 write_reg(par, 0x0035, CURVE(0, 3) << 8 | CURVE(0, 2));
222 write_reg(par, 0x0036, CURVE(0, 1) << 8 | CURVE(0, 0));
223
224 write_reg(par, 0x0037, CURVE(1, 5) << 8 | CURVE(1, 4));
225 write_reg(par, 0x0038, CURVE(1, 7) << 8 | CURVE(1, 6));
226 write_reg(par, 0x0039, CURVE(1, 9) << 8 | CURVE(1, 8));
227 write_reg(par, 0x003C, CURVE(1, 3) << 8 | CURVE(1, 2));
228 write_reg(par, 0x003D, CURVE(1, 1) << 8 | CURVE(1, 0));
229
230 return 0;
231}
232
233#undef CURVE
234
235static struct fbtft_display display = {
236 .regwidth = 16,
237 .width = WIDTH,
238 .height = HEIGHT,
239 .bpp = BPP,
240 .fps = FPS,
241 .gamma_num = 2,
242 .gamma_len = 10,
243 .gamma = DEFAULT_GAMMA,
244 .fbtftops = {
245 .init_display = init_display,
246 .set_addr_win = set_addr_win,
247 .set_var = set_var,
248 .set_gamma = set_gamma,
249 },
250};
251
252FBTFT_REGISTER_DRIVER(DRVNAME, "ilitek,ili9325", &display);
253
254MODULE_ALIAS("spi:" DRVNAME);
255MODULE_ALIAS("platform:" DRVNAME);
256MODULE_ALIAS("spi:ili9325");
257MODULE_ALIAS("platform:ili9325");
258
259MODULE_DESCRIPTION("FB driver for the ILI9325 LCD Controller");
260MODULE_AUTHOR("Noralf Tronnes");
261MODULE_LICENSE("GPL");
262