Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/*
2 * Generic FB driver for TFT LCD displays
3 *
4 * Copyright (C) 2013 Noralf Tronnes
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
17#include <linux/module.h>
18#include <linux/kernel.h>
19#include <linux/init.h>
20#include <linux/vmalloc.h>
21#include <linux/gpio.h>
22#include <linux/spi/spi.h>
23#include <linux/delay.h>
24
25#include "fbtft.h"
26
27#define DRVNAME "flexfb"
28
29static char *chip;
30module_param(chip, charp, 0);
31MODULE_PARM_DESC(chip, "LCD controller");
32
33static unsigned int width;
34module_param(width, uint, 0);
35MODULE_PARM_DESC(width, "Display width");
36
37static unsigned int height;
38module_param(height, uint, 0);
39MODULE_PARM_DESC(height, "Display height");
40
41static s16 init[512];
42static int init_num;
43module_param_array(init, short, &init_num, 0);
44MODULE_PARM_DESC(init, "Init sequence");
45
46static unsigned int setaddrwin;
47module_param(setaddrwin, uint, 0);
48MODULE_PARM_DESC(setaddrwin, "Which set_addr_win() implementation to use");
49
50static unsigned int buswidth = 8;
51module_param(buswidth, uint, 0);
52MODULE_PARM_DESC(buswidth, "Width of databus (default: 8)");
53
54static unsigned int regwidth = 8;
55module_param(regwidth, uint, 0);
56MODULE_PARM_DESC(regwidth, "Width of controller register (default: 8)");
57
58static bool nobacklight;
59module_param(nobacklight, bool, 0);
60MODULE_PARM_DESC(nobacklight, "Turn off backlight functionality.");
61
62static bool latched;
63module_param(latched, bool, 0);
64MODULE_PARM_DESC(latched, "Use with latched 16-bit databus");
65
66static s16 *initp;
67static int initp_num;
68
69/* default init sequences */
70static s16 st7735r_init[] = {
71 -1, 0x01,
72 -2, 150,
73 -1, 0x11,
74 -2, 500,
75 -1, 0xB1, 0x01, 0x2C, 0x2D,
76 -1, 0xB2, 0x01, 0x2C, 0x2D,
77 -1, 0xB3, 0x01, 0x2C, 0x2D, 0x01, 0x2C, 0x2D,
78 -1, 0xB4, 0x07,
79 -1, 0xC0, 0xA2, 0x02, 0x84,
80 -1, 0xC1, 0xC5,
81 -1, 0xC2, 0x0A, 0x00,
82 -1, 0xC3, 0x8A, 0x2A,
83 -1, 0xC4, 0x8A, 0xEE,
84 -1, 0xC5, 0x0E,
85 -1, 0x20,
86 -1, 0x36, 0xC0,
87 -1, 0x3A, 0x05,
88 -1, 0xE0, 0x0f, 0x1a, 0x0f, 0x18, 0x2f, 0x28, 0x20, 0x22,
89 0x1f, 0x1b, 0x23, 0x37, 0x00, 0x07, 0x02, 0x10,
90 -1, 0xE1, 0x0f, 0x1b, 0x0f, 0x17, 0x33, 0x2c, 0x29, 0x2e,
91 0x30, 0x30, 0x39, 0x3f, 0x00, 0x07, 0x03, 0x10,
92 -1, 0x29,
93 -2, 100,
94 -1, 0x13,
95 -2, 10,
96 -3
97};
98
99static s16 ssd1289_init[] = {
100 -1, 0x00, 0x0001,
101 -1, 0x03, 0xA8A4,
102 -1, 0x0C, 0x0000,
103 -1, 0x0D, 0x080C,
104 -1, 0x0E, 0x2B00,
105 -1, 0x1E, 0x00B7,
106 -1, 0x01, 0x2B3F,
107 -1, 0x02, 0x0600,
108 -1, 0x10, 0x0000,
109 -1, 0x11, 0x6070,
110 -1, 0x05, 0x0000,
111 -1, 0x06, 0x0000,
112 -1, 0x16, 0xEF1C,
113 -1, 0x17, 0x0003,
114 -1, 0x07, 0x0233,
115 -1, 0x0B, 0x0000,
116 -1, 0x0F, 0x0000,
117 -1, 0x41, 0x0000,
118 -1, 0x42, 0x0000,
119 -1, 0x48, 0x0000,
120 -1, 0x49, 0x013F,
121 -1, 0x4A, 0x0000,
122 -1, 0x4B, 0x0000,
123 -1, 0x44, 0xEF00,
124 -1, 0x45, 0x0000,
125 -1, 0x46, 0x013F,
126 -1, 0x30, 0x0707,
127 -1, 0x31, 0x0204,
128 -1, 0x32, 0x0204,
129 -1, 0x33, 0x0502,
130 -1, 0x34, 0x0507,
131 -1, 0x35, 0x0204,
132 -1, 0x36, 0x0204,
133 -1, 0x37, 0x0502,
134 -1, 0x3A, 0x0302,
135 -1, 0x3B, 0x0302,
136 -1, 0x23, 0x0000,
137 -1, 0x24, 0x0000,
138 -1, 0x25, 0x8000,
139 -1, 0x4f, 0x0000,
140 -1, 0x4e, 0x0000,
141 -1, 0x22,
142 -3
143};
144
145static s16 hx8340bn_init[] = {
146 -1, 0xC1, 0xFF, 0x83, 0x40,
147 -1, 0x11,
148 -2, 150,
149 -1, 0xCA, 0x70, 0x00, 0xD9,
150 -1, 0xB0, 0x01, 0x11,
151 -1, 0xC9, 0x90, 0x49, 0x10, 0x28, 0x28, 0x10, 0x00, 0x06,
152 -2, 20,
153 -1, 0xC2, 0x60, 0x71, 0x01, 0x0E, 0x05, 0x02, 0x09, 0x31, 0x0A,
154 -1, 0xC3, 0x67, 0x30, 0x61, 0x17, 0x48, 0x07, 0x05, 0x33,
155 -2, 10,
156 -1, 0xB5, 0x35, 0x20, 0x45,
157 -1, 0xB4, 0x33, 0x25, 0x4C,
158 -2, 10,
159 -1, 0x3A, 0x05,
160 -1, 0x29,
161 -2, 10,
162 -3
163};
164
165static s16 ili9225_init[] = {
166 -1, 0x0001, 0x011C,
167 -1, 0x0002, 0x0100,
168 -1, 0x0003, 0x1030,
169 -1, 0x0008, 0x0808,
170 -1, 0x000C, 0x0000,
171 -1, 0x000F, 0x0A01,
172 -1, 0x0020, 0x0000,
173 -1, 0x0021, 0x0000,
174 -2, 50,
175 -1, 0x0010, 0x0A00,
176 -1, 0x0011, 0x1038,
177 -2, 50,
178 -1, 0x0012, 0x1121,
179 -1, 0x0013, 0x004E,
180 -1, 0x0014, 0x676F,
181 -1, 0x0030, 0x0000,
182 -1, 0x0031, 0x00DB,
183 -1, 0x0032, 0x0000,
184 -1, 0x0033, 0x0000,
185 -1, 0x0034, 0x00DB,
186 -1, 0x0035, 0x0000,
187 -1, 0x0036, 0x00AF,
188 -1, 0x0037, 0x0000,
189 -1, 0x0038, 0x00DB,
190 -1, 0x0039, 0x0000,
191 -1, 0x0050, 0x0000,
192 -1, 0x0051, 0x060A,
193 -1, 0x0052, 0x0D0A,
194 -1, 0x0053, 0x0303,
195 -1, 0x0054, 0x0A0D,
196 -1, 0x0055, 0x0A06,
197 -1, 0x0056, 0x0000,
198 -1, 0x0057, 0x0303,
199 -1, 0x0058, 0x0000,
200 -1, 0x0059, 0x0000,
201 -2, 50,
202 -1, 0x0007, 0x1017,
203 -2, 50,
204 -3
205};
206
207static s16 ili9320_init[] = {
208 -1, 0x00E5, 0x8000,
209 -1, 0x0000, 0x0001,
210 -1, 0x0001, 0x0100,
211 -1, 0x0002, 0x0700,
212 -1, 0x0003, 0x1030,
213 -1, 0x0004, 0x0000,
214 -1, 0x0008, 0x0202,
215 -1, 0x0009, 0x0000,
216 -1, 0x000A, 0x0000,
217 -1, 0x000C, 0x0000,
218 -1, 0x000D, 0x0000,
219 -1, 0x000F, 0x0000,
220 -1, 0x0010, 0x0000,
221 -1, 0x0011, 0x0007,
222 -1, 0x0012, 0x0000,
223 -1, 0x0013, 0x0000,
224 -2, 200,
225 -1, 0x0010, 0x17B0,
226 -1, 0x0011, 0x0031,
227 -2, 50,
228 -1, 0x0012, 0x0138,
229 -2, 50,
230 -1, 0x0013, 0x1800,
231 -1, 0x0029, 0x0008,
232 -2, 50,
233 -1, 0x0020, 0x0000,
234 -1, 0x0021, 0x0000,
235 -1, 0x0030, 0x0000,
236 -1, 0x0031, 0x0505,
237 -1, 0x0032, 0x0004,
238 -1, 0x0035, 0x0006,
239 -1, 0x0036, 0x0707,
240 -1, 0x0037, 0x0105,
241 -1, 0x0038, 0x0002,
242 -1, 0x0039, 0x0707,
243 -1, 0x003C, 0x0704,
244 -1, 0x003D, 0x0807,
245 -1, 0x0050, 0x0000,
246 -1, 0x0051, 0x00EF,
247 -1, 0x0052, 0x0000,
248 -1, 0x0053, 0x013F,
249 -1, 0x0060, 0x2700,
250 -1, 0x0061, 0x0001,
251 -1, 0x006A, 0x0000,
252 -1, 0x0080, 0x0000,
253 -1, 0x0081, 0x0000,
254 -1, 0x0082, 0x0000,
255 -1, 0x0083, 0x0000,
256 -1, 0x0084, 0x0000,
257 -1, 0x0085, 0x0000,
258 -1, 0x0090, 0x0010,
259 -1, 0x0092, 0x0000,
260 -1, 0x0093, 0x0003,
261 -1, 0x0095, 0x0110,
262 -1, 0x0097, 0x0000,
263 -1, 0x0098, 0x0000,
264 -1, 0x0007, 0x0173,
265 -3
266};
267
268static s16 ili9325_init[] = {
269 -1, 0x00E3, 0x3008,
270 -1, 0x00E7, 0x0012,
271 -1, 0x00EF, 0x1231,
272 -1, 0x0001, 0x0100,
273 -1, 0x0002, 0x0700,
274 -1, 0x0003, 0x1030,
275 -1, 0x0004, 0x0000,
276 -1, 0x0008, 0x0207,
277 -1, 0x0009, 0x0000,
278 -1, 0x000A, 0x0000,
279 -1, 0x000C, 0x0000,
280 -1, 0x000D, 0x0000,
281 -1, 0x000F, 0x0000,
282 -1, 0x0010, 0x0000,
283 -1, 0x0011, 0x0007,
284 -1, 0x0012, 0x0000,
285 -1, 0x0013, 0x0000,
286 -2, 200,
287 -1, 0x0010, 0x1690,
288 -1, 0x0011, 0x0223,
289 -2, 50,
290 -1, 0x0012, 0x000D,
291 -2, 50,
292 -1, 0x0013, 0x1200,
293 -1, 0x0029, 0x000A,
294 -1, 0x002B, 0x000C,
295 -2, 50,
296 -1, 0x0020, 0x0000,
297 -1, 0x0021, 0x0000,
298 -1, 0x0030, 0x0000,
299 -1, 0x0031, 0x0506,
300 -1, 0x0032, 0x0104,
301 -1, 0x0035, 0x0207,
302 -1, 0x0036, 0x000F,
303 -1, 0x0037, 0x0306,
304 -1, 0x0038, 0x0102,
305 -1, 0x0039, 0x0707,
306 -1, 0x003C, 0x0702,
307 -1, 0x003D, 0x1604,
308 -1, 0x0050, 0x0000,
309 -1, 0x0051, 0x00EF,
310 -1, 0x0052, 0x0000,
311 -1, 0x0053, 0x013F,
312 -1, 0x0060, 0xA700,
313 -1, 0x0061, 0x0001,
314 -1, 0x006A, 0x0000,
315 -1, 0x0080, 0x0000,
316 -1, 0x0081, 0x0000,
317 -1, 0x0082, 0x0000,
318 -1, 0x0083, 0x0000,
319 -1, 0x0084, 0x0000,
320 -1, 0x0085, 0x0000,
321 -1, 0x0090, 0x0010,
322 -1, 0x0092, 0x0600,
323 -1, 0x0007, 0x0133,
324 -3
325};
326
327static s16 ili9341_init[] = {
328 -1, 0x28,
329 -2, 20,
330 -1, 0xCF, 0x00, 0x83, 0x30,
331 -1, 0xED, 0x64, 0x03, 0x12, 0x81,
332 -1, 0xE8, 0x85, 0x01, 0x79,
333 -1, 0xCB, 0x39, 0x2c, 0x00, 0x34, 0x02,
334 -1, 0xF7, 0x20,
335 -1, 0xEA, 0x00, 0x00,
336 -1, 0xC0, 0x26,
337 -1, 0xC1, 0x11,
338 -1, 0xC5, 0x35, 0x3E,
339 -1, 0xC7, 0xBE,
340 -1, 0xB1, 0x00, 0x1B,
341 -1, 0xB6, 0x0a, 0x82, 0x27, 0x00,
342 -1, 0xB7, 0x07,
343 -1, 0x3A, 0x55,
344 -1, 0x36, 0x48,
345 -1, 0x11,
346 -2, 120,
347 -1, 0x29,
348 -2, 20,
349 -3
350};
351
352static s16 ssd1351_init[] = {
353 -1, 0xfd, 0x12,
354 -1, 0xfd, 0xb1,
355 -1, 0xae,
356 -1, 0xb3, 0xf1,
357 -1, 0xca, 0x7f,
358 -1, 0xa0, 0x74,
359 -1, 0x15, 0x00, 0x7f,
360 -1, 0x75, 0x00, 0x7f,
361 -1, 0xa1, 0x00,
362 -1, 0xa2, 0x00,
363 -1, 0xb5, 0x00,
364 -1, 0xab, 0x01,
365 -1, 0xb1, 0x32,
366 -1, 0xb4, 0xa0, 0xb5, 0x55,
367 -1, 0xbb, 0x17,
368 -1, 0xbe, 0x05,
369 -1, 0xc1, 0xc8, 0x80, 0xc8,
370 -1, 0xc7, 0x0f,
371 -1, 0xb6, 0x01,
372 -1, 0xa6,
373 -1, 0xaf,
374 -3
375};
376
377/**
378 * struct flexfb_lcd_controller - Describes the LCD controller properties
379 * @name: Model name of the chip
380 * @width: Width of display in pixels
381 * @height: Height of display in pixels
382 * @setaddrwin: Which set_addr_win() implementation to use
383 * @regwidth: LCD Controller Register width in bits
384 * @init_seq: LCD initialization sequence
385 * @init_seq_sz: Size of LCD initialization sequence
386 */
387struct flexfb_lcd_controller {
388 const char *name;
389 unsigned int width;
390 unsigned int height;
391 unsigned int setaddrwin;
392 unsigned int regwidth;
393 s16 *init_seq;
394 int init_seq_sz;
395};
396
397static const struct flexfb_lcd_controller flexfb_chip_table[] = {
398 {
399 .name = "st7735r",
400 .width = 120,
401 .height = 160,
402 .init_seq = st7735r_init,
403 .init_seq_sz = ARRAY_SIZE(st7735r_init),
404 },
405 {
406 .name = "hx8340bn",
407 .width = 176,
408 .height = 220,
409 .init_seq = hx8340bn_init,
410 .init_seq_sz = ARRAY_SIZE(hx8340bn_init),
411 },
412 {
413 .name = "ili9225",
414 .width = 176,
415 .height = 220,
416 .regwidth = 16,
417 .init_seq = ili9225_init,
418 .init_seq_sz = ARRAY_SIZE(ili9225_init),
419 },
420 {
421 .name = "ili9225",
422 .width = 176,
423 .height = 220,
424 .regwidth = 16,
425 .init_seq = ili9225_init,
426 .init_seq_sz = ARRAY_SIZE(ili9225_init),
427 },
428 {
429 .name = "ili9225",
430 .width = 176,
431 .height = 220,
432 .regwidth = 16,
433 .init_seq = ili9225_init,
434 .init_seq_sz = ARRAY_SIZE(ili9225_init),
435 },
436 {
437 .name = "ili9320",
438 .width = 240,
439 .height = 320,
440 .setaddrwin = 1,
441 .regwidth = 16,
442 .init_seq = ili9320_init,
443 .init_seq_sz = ARRAY_SIZE(ili9320_init),
444 },
445 {
446 .name = "ili9325",
447 .width = 240,
448 .height = 320,
449 .setaddrwin = 1,
450 .regwidth = 16,
451 .init_seq = ili9325_init,
452 .init_seq_sz = ARRAY_SIZE(ili9325_init),
453 },
454 {
455 .name = "ili9341",
456 .width = 240,
457 .height = 320,
458 .init_seq = ili9341_init,
459 .init_seq_sz = ARRAY_SIZE(ili9341_init),
460 },
461 {
462 .name = "ssd1289",
463 .width = 240,
464 .height = 320,
465 .setaddrwin = 2,
466 .regwidth = 16,
467 .init_seq = ssd1289_init,
468 .init_seq_sz = ARRAY_SIZE(ssd1289_init),
469 },
470 {
471 .name = "ssd1351",
472 .width = 128,
473 .height = 128,
474 .setaddrwin = 3,
475 .init_seq = ssd1351_init,
476 .init_seq_sz = ARRAY_SIZE(ssd1351_init),
477 },
478};
479
480/* ili9320, ili9325 */
481static void flexfb_set_addr_win_1(struct fbtft_par *par,
482 int xs, int ys, int xe, int ye)
483{
484 switch (par->info->var.rotate) {
485 /* R20h = Horizontal GRAM Start Address */
486 /* R21h = Vertical GRAM Start Address */
487 case 0:
488 write_reg(par, 0x0020, xs);
489 write_reg(par, 0x0021, ys);
490 break;
491 case 180:
492 write_reg(par, 0x0020, width - 1 - xs);
493 write_reg(par, 0x0021, height - 1 - ys);
494 break;
495 case 270:
496 write_reg(par, 0x0020, width - 1 - ys);
497 write_reg(par, 0x0021, xs);
498 break;
499 case 90:
500 write_reg(par, 0x0020, ys);
501 write_reg(par, 0x0021, height - 1 - xs);
502 break;
503 }
504 write_reg(par, 0x0022); /* Write Data to GRAM */
505}
506
507/* ssd1289 */
508static void flexfb_set_addr_win_2(struct fbtft_par *par,
509 int xs, int ys, int xe, int ye)
510{
511 switch (par->info->var.rotate) {
512 /* R4Eh - Set GDDRAM X address counter */
513 /* R4Fh - Set GDDRAM Y address counter */
514 case 0:
515 write_reg(par, 0x4e, xs);
516 write_reg(par, 0x4f, ys);
517 break;
518 case 180:
519 write_reg(par, 0x4e, par->info->var.xres - 1 - xs);
520 write_reg(par, 0x4f, par->info->var.yres - 1 - ys);
521 break;
522 case 270:
523 write_reg(par, 0x4e, par->info->var.yres - 1 - ys);
524 write_reg(par, 0x4f, xs);
525 break;
526 case 90:
527 write_reg(par, 0x4e, ys);
528 write_reg(par, 0x4f, par->info->var.xres - 1 - xs);
529 break;
530 }
531
532 /* R22h - RAM data write */
533 write_reg(par, 0x22, 0);
534}
535
536/* ssd1351 */
537static void set_addr_win_3(struct fbtft_par *par,
538 int xs, int ys, int xe, int ye)
539{
540 write_reg(par, 0x15, xs, xe);
541 write_reg(par, 0x75, ys, ye);
542 write_reg(par, 0x5C);
543}
544
545static int flexfb_verify_gpios_dc(struct fbtft_par *par)
546{
547 fbtft_par_dbg(DEBUG_VERIFY_GPIOS, par, "%s()\n", __func__);
548
549 if (par->gpio.dc < 0) {
550 dev_err(par->info->device,
551 "Missing info about 'dc' gpio. Aborting.\n");
552 return -EINVAL;
553 }
554
555 return 0;
556}
557
558static int flexfb_verify_gpios_db(struct fbtft_par *par)
559{
560 int i;
561 int num_db = buswidth;
562
563 fbtft_par_dbg(DEBUG_VERIFY_GPIOS, par, "%s()\n", __func__);
564
565 if (par->gpio.dc < 0) {
566 dev_err(par->info->device, "Missing info about 'dc' gpio. Aborting.\n");
567 return -EINVAL;
568 }
569 if (par->gpio.wr < 0) {
570 dev_err(par->info->device, "Missing info about 'wr' gpio. Aborting.\n");
571 return -EINVAL;
572 }
573 if (latched && (par->gpio.latch < 0)) {
574 dev_err(par->info->device, "Missing info about 'latch' gpio. Aborting.\n");
575 return -EINVAL;
576 }
577 if (latched)
578 num_db = buswidth / 2;
579 for (i = 0; i < num_db; i++) {
580 if (par->gpio.db[i] < 0) {
581 dev_err(par->info->device,
582 "Missing info about 'db%02d' gpio. Aborting.\n",
583 i);
584 return -EINVAL;
585 }
586 }
587
588 return 0;
589}
590
591static void flexfb_chip_load_param(const struct flexfb_lcd_controller *chip)
592{
593 if (!width)
594 width = chip->width;
595 if (!height)
596 height = chip->height;
597 setaddrwin = chip->setaddrwin;
598 if (chip->regwidth)
599 regwidth = chip->regwidth;
600 if (!init_num) {
601 initp = chip->init_seq;
602 initp_num = chip->init_seq_sz;
603 }
604}
605
606static struct fbtft_display flex_display = { };
607
608static int flexfb_chip_init(const struct device *dev)
609{
610 int i;
611
612 for (i = 0; i < ARRAY_SIZE(flexfb_chip_table); i++)
613 if (!strcmp(chip, flexfb_chip_table[i].name)) {
614 flexfb_chip_load_param(&flexfb_chip_table[i]);
615 return 0;
616 }
617
618 dev_err(dev, "chip=%s is not supported\n", chip);
619
620 return -EINVAL;
621}
622
623static int flexfb_probe_common(struct spi_device *sdev,
624 struct platform_device *pdev)
625{
626 struct device *dev;
627 struct fb_info *info;
628 struct fbtft_par *par;
629 int ret;
630
631 initp = init;
632 initp_num = init_num;
633
634 if (sdev)
635 dev = &sdev->dev;
636 else
637 dev = &pdev->dev;
638
639 fbtft_init_dbg(dev, "%s(%s)\n", __func__,
640 sdev ? "'SPI device'" : "'Platform device'");
641
642 if (chip) {
643 ret = flexfb_chip_init(dev);
644 if (ret)
645 return ret;
646 }
647
648 if (width == 0 || height == 0) {
649 dev_err(dev, "argument(s) missing: width and height has to be set.\n");
650 return -EINVAL;
651 }
652 flex_display.width = width;
653 flex_display.height = height;
654 fbtft_init_dbg(dev, "Display resolution: %dx%d\n", width, height);
655 fbtft_init_dbg(dev, "chip = %s\n", chip ? chip : "not set");
656 fbtft_init_dbg(dev, "setaddrwin = %d\n", setaddrwin);
657 fbtft_init_dbg(dev, "regwidth = %d\n", regwidth);
658 fbtft_init_dbg(dev, "buswidth = %d\n", buswidth);
659
660 info = fbtft_framebuffer_alloc(&flex_display, dev, dev->platform_data);
661 if (!info)
662 return -ENOMEM;
663
664 par = info->par;
665 if (sdev)
666 par->spi = sdev;
667 else
668 par->pdev = pdev;
669 if (!par->init_sequence)
670 par->init_sequence = initp;
671 par->fbtftops.init_display = fbtft_init_display;
672
673 /* registerwrite functions */
674 switch (regwidth) {
675 case 8:
676 par->fbtftops.write_register = fbtft_write_reg8_bus8;
677 break;
678 case 16:
679 par->fbtftops.write_register = fbtft_write_reg16_bus8;
680 break;
681 default:
682 dev_err(dev,
683 "argument 'regwidth': %d is not supported.\n",
684 regwidth);
685 return -EINVAL;
686 }
687
688 /* bus functions */
689 if (sdev) {
690 par->fbtftops.write = fbtft_write_spi;
691 switch (buswidth) {
692 case 8:
693 par->fbtftops.write_vmem = fbtft_write_vmem16_bus8;
694 if (!par->startbyte)
695 par->fbtftops.verify_gpios = flexfb_verify_gpios_dc;
696 break;
697 case 9:
698 if (regwidth == 16) {
699 dev_err(dev, "argument 'regwidth': %d is not supported with buswidth=%d and SPI.\n", regwidth, buswidth);
700 return -EINVAL;
701 }
702 par->fbtftops.write_register = fbtft_write_reg8_bus9;
703 par->fbtftops.write_vmem = fbtft_write_vmem16_bus9;
704 if (par->spi->master->bits_per_word_mask
705 & SPI_BPW_MASK(9)) {
706 par->spi->bits_per_word = 9;
707 } else {
708 dev_warn(dev,
709 "9-bit SPI not available, emulating using 8-bit.\n");
710 /* allocate buffer with room for dc bits */
711 par->extra = devm_kzalloc(par->info->device,
712 par->txbuf.len + (par->txbuf.len / 8) + 8,
713 GFP_KERNEL);
714 if (!par->extra) {
715 ret = -ENOMEM;
716 goto out_release;
717 }
718 par->fbtftops.write = fbtft_write_spi_emulate_9;
719 }
720 break;
721 default:
722 dev_err(dev, "argument 'buswidth': %d is not supported with SPI.\n", buswidth);
723 return -EINVAL;
724 }
725 } else {
726 par->fbtftops.verify_gpios = flexfb_verify_gpios_db;
727 switch (buswidth) {
728 case 8:
729 par->fbtftops.write = fbtft_write_gpio8_wr;
730 par->fbtftops.write_vmem = fbtft_write_vmem16_bus8;
731 break;
732 case 16:
733 par->fbtftops.write_register = fbtft_write_reg16_bus16;
734 if (latched)
735 par->fbtftops.write = fbtft_write_gpio16_wr_latched;
736 else
737 par->fbtftops.write = fbtft_write_gpio16_wr;
738 par->fbtftops.write_vmem = fbtft_write_vmem16_bus16;
739 break;
740 default:
741 dev_err(dev, "argument 'buswidth': %d is not supported with parallel.\n", buswidth);
742 return -EINVAL;
743 }
744 }
745
746 /* set_addr_win function */
747 switch (setaddrwin) {
748 case 0:
749 /* use default */
750 break;
751 case 1:
752 par->fbtftops.set_addr_win = flexfb_set_addr_win_1;
753 break;
754 case 2:
755 par->fbtftops.set_addr_win = flexfb_set_addr_win_2;
756 break;
757 case 3:
758 par->fbtftops.set_addr_win = set_addr_win_3;
759 break;
760 default:
761 dev_err(dev, "argument 'setaddrwin': unknown value %d.\n",
762 setaddrwin);
763 return -EINVAL;
764 }
765
766 if (!nobacklight)
767 par->fbtftops.register_backlight = fbtft_register_backlight;
768
769 ret = fbtft_register_framebuffer(info);
770 if (ret < 0)
771 goto out_release;
772
773 return 0;
774
775out_release:
776 fbtft_framebuffer_release(info);
777
778 return ret;
779}
780
781static int flexfb_remove_common(struct device *dev, struct fb_info *info)
782{
783 struct fbtft_par *par;
784
785 if (!info)
786 return -EINVAL;
787 par = info->par;
788 if (par)
789 fbtft_par_dbg(DEBUG_DRIVER_INIT_FUNCTIONS, par, "%s()\n",
790 __func__);
791 fbtft_unregister_framebuffer(info);
792 fbtft_framebuffer_release(info);
793
794 return 0;
795}
796
797static int flexfb_probe_spi(struct spi_device *spi)
798{
799 return flexfb_probe_common(spi, NULL);
800}
801
802static int flexfb_remove_spi(struct spi_device *spi)
803{
804 struct fb_info *info = spi_get_drvdata(spi);
805
806 return flexfb_remove_common(&spi->dev, info);
807}
808
809static int flexfb_probe_pdev(struct platform_device *pdev)
810{
811 return flexfb_probe_common(NULL, pdev);
812}
813
814static int flexfb_remove_pdev(struct platform_device *pdev)
815{
816 struct fb_info *info = platform_get_drvdata(pdev);
817
818 return flexfb_remove_common(&pdev->dev, info);
819}
820
821static struct spi_driver flexfb_spi_driver = {
822 .driver = {
823 .name = DRVNAME,
824 },
825 .probe = flexfb_probe_spi,
826 .remove = flexfb_remove_spi,
827};
828
829static const struct platform_device_id flexfb_platform_ids[] = {
830 { "flexpfb", 0 },
831 { },
832};
833MODULE_DEVICE_TABLE(platform, flexfb_platform_ids);
834
835static struct platform_driver flexfb_platform_driver = {
836 .driver = {
837 .name = DRVNAME,
838 },
839 .id_table = flexfb_platform_ids,
840 .probe = flexfb_probe_pdev,
841 .remove = flexfb_remove_pdev,
842};
843
844static int __init flexfb_init(void)
845{
846 int ret, ret2;
847
848 ret = spi_register_driver(&flexfb_spi_driver);
849 ret2 = platform_driver_register(&flexfb_platform_driver);
850 if (ret < 0)
851 return ret;
852 return ret2;
853}
854
855static void __exit flexfb_exit(void)
856{
857 spi_unregister_driver(&flexfb_spi_driver);
858 platform_driver_unregister(&flexfb_platform_driver);
859}
860
861/* ------------------------------------------------------------------------- */
862
863module_init(flexfb_init);
864module_exit(flexfb_exit);
865
866MODULE_DESCRIPTION("Generic FB driver for TFT LCD displays");
867MODULE_AUTHOR("Noralf Tronnes");
868MODULE_LICENSE("GPL");