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