This source file includes following definitions.
- init_display
- set_addr_win
- set_var
- gamma_adj
1
2
3
4
5
6
7
8
9
10
11 #include <linux/module.h>
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/gpio/consumer.h>
15 #include <linux/delay.h>
16 #include <video/mipi_display.h>
17
18 #include "fbtft.h"
19
20 #define DRVNAME "fb_ili9163"
21 #define WIDTH 128
22 #define HEIGHT 128
23 #define BPP 16
24 #define FPS 30
25
26 #ifdef GAMMA_ADJ
27 #define GAMMA_LEN 15
28 #define GAMMA_NUM 1
29 #define DEFAULT_GAMMA "36 29 12 22 1C 15 42 B7 2F 13 12 0A 11 0B 06\n"
30 #endif
31
32
33 #define CMD_FRMCTR1 0xB1
34
35 #define CMD_FRMCTR2 0xB2
36 #define CMD_FRMCTR3 0xB3
37
38 #define CMD_DINVCTR 0xB4
39 #define CMD_RGBBLK 0xB5
40 #define CMD_DFUNCTR 0xB6
41 #define CMD_SDRVDIR 0xB7
42 #define CMD_GDRVDIR 0xB8
43
44 #define CMD_PWCTR1 0xC0
45 #define CMD_PWCTR2 0xC1
46 #define CMD_PWCTR3 0xC2
47 #define CMD_PWCTR4 0xC3
48 #define CMD_PWCTR5 0xC4
49 #define CMD_VCOMCTR1 0xC5
50 #define CMD_VCOMCTR2 0xC6
51 #define CMD_VCOMOFFS 0xC7
52 #define CMD_PGAMMAC 0xE0
53 #define CMD_NGAMMAC 0xE1
54 #define CMD_GAMRSEL 0xF2
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70 #ifdef RED
71 #define __OFFSET 32
72 #else
73 #define __OFFSET 0
74 #endif
75
76 static int init_display(struct fbtft_par *par)
77 {
78 par->fbtftops.reset(par);
79
80 if (par->gpio.cs)
81 gpiod_set_value(par->gpio.cs, 0);
82
83 write_reg(par, MIPI_DCS_SOFT_RESET);
84 mdelay(500);
85 write_reg(par, MIPI_DCS_EXIT_SLEEP_MODE);
86 mdelay(5);
87 write_reg(par, MIPI_DCS_SET_PIXEL_FORMAT, MIPI_DCS_PIXEL_FMT_16BIT);
88
89 write_reg(par, MIPI_DCS_SET_GAMMA_CURVE, 0x02);
90 #ifdef GAMMA_ADJ
91 write_reg(par, CMD_GAMRSEL, 0x01);
92 #endif
93 write_reg(par, MIPI_DCS_ENTER_NORMAL_MODE);
94 write_reg(par, CMD_DFUNCTR, 0xff, 0x06);
95
96 write_reg(par, CMD_FRMCTR1, 0x08, 0x02);
97 write_reg(par, CMD_DINVCTR, 0x07);
98
99 write_reg(par, CMD_PWCTR1, 0x0A, 0x02);
100
101 write_reg(par, CMD_PWCTR2, 0x02);
102
103 write_reg(par, CMD_VCOMCTR1, 0x50, 0x63);
104 write_reg(par, CMD_VCOMOFFS, 0);
105
106 write_reg(par, MIPI_DCS_SET_COLUMN_ADDRESS, 0, 0, 0, WIDTH);
107 write_reg(par, MIPI_DCS_SET_PAGE_ADDRESS, 0, 0, 0, HEIGHT);
108
109 write_reg(par, MIPI_DCS_SET_DISPLAY_ON);
110 write_reg(par, MIPI_DCS_WRITE_MEMORY_START);
111
112 return 0;
113 }
114
115 static void set_addr_win(struct fbtft_par *par, int xs, int ys,
116 int xe, int ye)
117 {
118 switch (par->info->var.rotate) {
119 case 0:
120 write_reg(par, MIPI_DCS_SET_COLUMN_ADDRESS,
121 xs >> 8, xs & 0xff, xe >> 8, xe & 0xff);
122 write_reg(par, MIPI_DCS_SET_PAGE_ADDRESS,
123 (ys + __OFFSET) >> 8, (ys + __OFFSET) & 0xff,
124 (ye + __OFFSET) >> 8, (ye + __OFFSET) & 0xff);
125 break;
126 case 90:
127 write_reg(par, MIPI_DCS_SET_COLUMN_ADDRESS,
128 (xs + __OFFSET) >> 8, (xs + __OFFSET) & 0xff,
129 (xe + __OFFSET) >> 8, (xe + __OFFSET) & 0xff);
130 write_reg(par, MIPI_DCS_SET_PAGE_ADDRESS,
131 ys >> 8, ys & 0xff, ye >> 8, ye & 0xff);
132 break;
133 case 180:
134 case 270:
135 write_reg(par, MIPI_DCS_SET_COLUMN_ADDRESS,
136 xs >> 8, xs & 0xff, xe >> 8, xe & 0xff);
137 write_reg(par, MIPI_DCS_SET_PAGE_ADDRESS,
138 ys >> 8, ys & 0xff, ye >> 8, ye & 0xff);
139 break;
140 default:
141
142 par->info->var.rotate = 0;
143 }
144 write_reg(par, MIPI_DCS_WRITE_MEMORY_START);
145 }
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167 static int set_var(struct fbtft_par *par)
168 {
169 u8 mactrl_data = 0;
170
171 switch (par->info->var.rotate) {
172 case 0:
173 mactrl_data = 0x08;
174 break;
175 case 180:
176 mactrl_data = 0xC8;
177 break;
178 case 270:
179 mactrl_data = 0xA8;
180 break;
181 case 90:
182 mactrl_data = 0x68;
183 break;
184 }
185
186
187 if (par->bgr)
188 mactrl_data |= BIT(2);
189 write_reg(par, MIPI_DCS_SET_ADDRESS_MODE, mactrl_data);
190 write_reg(par, MIPI_DCS_WRITE_MEMORY_START);
191 return 0;
192 }
193
194 #ifdef GAMMA_ADJ
195 #define CURVE(num, idx) curves[(num) * par->gamma.num_values + (idx)]
196 static int gamma_adj(struct fbtft_par *par, u32 *curves)
197 {
198 static const unsigned long mask[] = {
199 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
200 0x1f, 0x3f, 0x0f, 0x0f, 0x7f, 0x1f,
201 0x3F, 0x3F, 0x3F, 0x3F, 0x3F};
202 int i, j;
203
204 for (i = 0; i < GAMMA_NUM; i++)
205 for (j = 0; j < GAMMA_LEN; j++)
206 CURVE(i, j) &= mask[i * par->gamma.num_values + j];
207
208 write_reg(par, CMD_PGAMMAC,
209 CURVE(0, 0),
210 CURVE(0, 1),
211 CURVE(0, 2),
212 CURVE(0, 3),
213 CURVE(0, 4),
214 CURVE(0, 5),
215 CURVE(0, 6),
216 (CURVE(0, 7) << 4) | CURVE(0, 8),
217 CURVE(0, 9),
218 CURVE(0, 10),
219 CURVE(0, 11),
220 CURVE(0, 12),
221 CURVE(0, 13),
222 CURVE(0, 14),
223 CURVE(0, 15));
224
225
226 write_reg(par, MIPI_DCS_WRITE_MEMORY_START);
227
228 return 0;
229 }
230
231 #undef CURVE
232 #endif
233
234 static struct fbtft_display display = {
235 .regwidth = 8,
236 .width = WIDTH,
237 .height = HEIGHT,
238 .bpp = BPP,
239 .fps = FPS,
240 #ifdef GAMMA_ADJ
241 .gamma_num = GAMMA_NUM,
242 .gamma_len = GAMMA_LEN,
243 .gamma = DEFAULT_GAMMA,
244 #endif
245 .fbtftops = {
246 .init_display = init_display,
247 .set_addr_win = set_addr_win,
248 .set_var = set_var,
249 #ifdef GAMMA_ADJ
250 .set_gamma = gamma_adj,
251 #endif
252 },
253 };
254
255 FBTFT_REGISTER_DRIVER(DRVNAME, "ilitek,ili9163", &display);
256
257 MODULE_ALIAS("spi:" DRVNAME);
258 MODULE_ALIAS("platform:" DRVNAME);
259 MODULE_ALIAS("spi:ili9163");
260 MODULE_ALIAS("platform:ili9163");
261
262 MODULE_DESCRIPTION("FB driver for the ILI9163 LCD Controller");
263 MODULE_AUTHOR("Kozhevnikov Anatoly");
264 MODULE_LICENSE("GPL");