staging: fbtft: split long strings
[linux-2.6-block.git] / drivers / staging / fbtft / flexfb.c
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  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */
20
21 #include <linux/module.h>
22 #include <linux/kernel.h>
23 #include <linux/init.h>
24 #include <linux/vmalloc.h>
25 #include <linux/gpio.h>
26 #include <linux/spi/spi.h>
27 #include <linux/delay.h>
28
29 #include "fbtft.h"
30
31 #define DRVNAME     "flexfb"
32
33
34 static char *chip;
35 module_param(chip, charp, 0);
36 MODULE_PARM_DESC(chip, "LCD controller");
37
38 static unsigned int width;
39 module_param(width, uint, 0);
40 MODULE_PARM_DESC(width, "Display width");
41
42 static unsigned int height;
43 module_param(height, uint, 0);
44 MODULE_PARM_DESC(height, "Display height");
45
46 static int init[512];
47 static int init_num;
48 module_param_array(init, int, &init_num, 0);
49 MODULE_PARM_DESC(init, "Init sequence");
50
51 static unsigned int setaddrwin;
52 module_param(setaddrwin, uint, 0);
53 MODULE_PARM_DESC(setaddrwin, "Which set_addr_win() implementation to use");
54
55 static unsigned int buswidth = 8;
56 module_param(buswidth, uint, 0);
57 MODULE_PARM_DESC(buswidth, "Width of databus (default: 8)");
58
59 static unsigned int regwidth = 8;
60 module_param(regwidth, uint, 0);
61 MODULE_PARM_DESC(regwidth, "Width of controller register (default: 8)");
62
63 static bool nobacklight;
64 module_param(nobacklight, bool, 0);
65 MODULE_PARM_DESC(nobacklight, "Turn off backlight functionality.");
66
67 static bool latched;
68 module_param(latched, bool, 0);
69 MODULE_PARM_DESC(latched, "Use with latched 16-bit databus");
70
71
72 static int *initp;
73 static int initp_num;
74
75 /* default init sequences */
76 static int st7735r_init[] = { \
77 -1,0x01,-2,150,-1,0x11,-2,500,-1,0xB1,0x01,0x2C,0x2D,-1,0xB2,0x01,0x2C,0x2D,-1,0xB3,0x01,0x2C,0x2D,0x01,0x2C,0x2D, \
78 -1,0xB4,0x07,-1,0xC0,0xA2,0x02,0x84,-1,0xC1,0xC5,-1,0xC2,0x0A,0x00,-1,0xC3,0x8A,0x2A,-1,0xC4,0x8A,0xEE,-1,0xC5,0x0E, \
79 -1,0x20,-1,0x36,0xC0,-1,0x3A,0x05,-1,0xE0,0x0f,0x1a,0x0f,0x18,0x2f,0x28,0x20,0x22,0x1f,0x1b,0x23,0x37,0x00,0x07,0x02,0x10, \
80 -1,0xE1,0x0f,0x1b,0x0f,0x17,0x33,0x2c,0x29,0x2e,0x30,0x30,0x39,0x3f,0x00,0x07,0x03,0x10,-1,0x29,-2,100,-1,0x13,-2,10,-3 };
81
82 static int ssd1289_init[] = { \
83 -1,0x00,0x0001,-1,0x03,0xA8A4,-1,0x0C,0x0000,-1,0x0D,0x080C,-1,0x0E,0x2B00,-1,0x1E,0x00B7,-1,0x01,0x2B3F,-1,0x02,0x0600, \
84 -1,0x10,0x0000,-1,0x11,0x6070,-1,0x05,0x0000,-1,0x06,0x0000,-1,0x16,0xEF1C,-1,0x17,0x0003,-1,0x07,0x0233,-1,0x0B,0x0000, \
85 -1,0x0F,0x0000,-1,0x41,0x0000,-1,0x42,0x0000,-1,0x48,0x0000,-1,0x49,0x013F,-1,0x4A,0x0000,-1,0x4B,0x0000,-1,0x44,0xEF00, \
86 -1,0x45,0x0000,-1,0x46,0x013F,-1,0x30,0x0707,-1,0x31,0x0204,-1,0x32,0x0204,-1,0x33,0x0502,-1,0x34,0x0507,-1,0x35,0x0204, \
87 -1,0x36,0x0204,-1,0x37,0x0502,-1,0x3A,0x0302,-1,0x3B,0x0302,-1,0x23,0x0000,-1,0x24,0x0000,-1,0x25,0x8000,-1,0x4f,0x0000, \
88 -1,0x4e,0x0000,-1,0x22,-3 };
89
90 static int hx8340bn_init[] = { \
91 -1,0xC1,0xFF,0x83,0x40,-1,0x11,-2,150,-1,0xCA,0x70,0x00,0xD9,-1,0xB0,0x01,0x11, \
92 -1,0xC9,0x90,0x49,0x10,0x28,0x28,0x10,0x00,0x06,-2,20,-1,0xC2,0x60,0x71,0x01,0x0E,0x05,0x02,0x09,0x31,0x0A, \
93 -1,0xC3,0x67,0x30,0x61,0x17,0x48,0x07,0x05,0x33,-2,10,-1,0xB5,0x35,0x20,0x45,-1,0xB4,0x33,0x25,0x4C,-2,10, \
94 -1,0x3A,0x05,-1,0x29,-2,10,-3 };
95
96 static int ili9225_init[] = { \
97 -1,0x0001,0x011C,-1,0x0002,0x0100,-1,0x0003,0x1030,-1,0x0008,0x0808,-1,0x000C,0x0000,-1,0x000F,0x0A01,-1,0x0020,0x0000, \
98 -1,0x0021,0x0000,-2,50,-1,0x0010,0x0A00,-1,0x0011,0x1038,-2,50,-1,0x0012,0x1121,-1,0x0013,0x004E,-1,0x0014,0x676F, \
99 -1,0x0030,0x0000,-1,0x0031,0x00DB,-1,0x0032,0x0000,-1,0x0033,0x0000,-1,0x0034,0x00DB,-1,0x0035,0x0000,-1,0x0036,0x00AF, \
100 -1,0x0037,0x0000,-1,0x0038,0x00DB,-1,0x0039,0x0000,-1,0x0050,0x0000,-1,0x0051,0x060A,-1,0x0052,0x0D0A,-1,0x0053,0x0303, \
101 -1,0x0054,0x0A0D,-1,0x0055,0x0A06,-1,0x0056,0x0000,-1,0x0057,0x0303,-1,0x0058,0x0000,-1,0x0059,0x0000,-2,50, \
102 -1,0x0007,0x1017,-2,50,-3 };
103
104 static int ili9320_init[] = { \
105 -1,0x00E5,0x8000,-1,0x0000,0x0001,-1,0x0001,0x0100,-1,0x0002,0x0700,-1,0x0003,0x1030,-1,0x0004,0x0000,-1,0x0008,0x0202, \
106 -1,0x0009,0x0000,-1,0x000A,0x0000,-1,0x000C,0x0000,-1,0x000D,0x0000,-1,0x000F,0x0000,-1,0x0010,0x0000,-1,0x0011,0x0007, \
107 -1,0x0012,0x0000,-1,0x0013,0x0000,-2,200,-1,0x0010,0x17B0,-1,0x0011,0x0031,-2,50,-1,0x0012,0x0138,-2,50,-1,0x0013,0x1800, \
108 -1,0x0029,0x0008,-2,50,-1,0x0020,0x0000,-1,0x0021,0x0000,-1,0x0030,0x0000,-1,0x0031,0x0505,-1,0x0032,0x0004, \
109 -1,0x0035,0x0006,-1,0x0036,0x0707,-1,0x0037,0x0105,-1,0x0038,0x0002,-1,0x0039,0x0707,-1,0x003C,0x0704,-1,0x003D,0x0807, \
110 -1,0x0050,0x0000,-1,0x0051,0x00EF,-1,0x0052,0x0000,-1,0x0053,0x013F,-1,0x0060,0x2700,-1,0x0061,0x0001,-1,0x006A,0x0000, \
111 -1,0x0080,0x0000,-1,0x0081,0x0000,-1,0x0082,0x0000,-1,0x0083,0x0000,-1,0x0084,0x0000,-1,0x0085,0x0000,-1,0x0090,0x0010, \
112 -1,0x0092,0x0000,-1,0x0093,0x0003,-1,0x0095,0x0110,-1,0x0097,0x0000,-1,0x0098,0x0000,-1,0x0007,0x0173,-3 };
113
114 static int ili9325_init[] = { \
115 -1,0x00E3,0x3008,-1,0x00E7,0x0012,-1,0x00EF,0x1231,-1,0x0001,0x0100,-1,0x0002,0x0700,-1,0x0003,0x1030,-1,0x0004,0x0000, \
116 -1,0x0008,0x0207,-1,0x0009,0x0000,-1,0x000A,0x0000,-1,0x000C,0x0000,-1,0x000D,0x0000,-1,0x000F,0x0000,-1,0x0010,0x0000, \
117 -1,0x0011,0x0007,-1,0x0012,0x0000,-1,0x0013,0x0000,-2,200,-1,0x0010,0x1690,-1,0x0011,0x0223,-2,50,-1,0x0012,0x000D,-2,50, \
118 -1,0x0013,0x1200,-1,0x0029,0x000A,-1,0x002B,0x000C,-2,50,-1,0x0020,0x0000,-1,0x0021,0x0000,-1,0x0030,0x0000, \
119 -1,0x0031,0x0506,-1,0x0032,0x0104,-1,0x0035,0x0207,-1,0x0036,0x000F,-1,0x0037,0x0306,-1,0x0038,0x0102,-1,0x0039,0x0707, \
120 -1,0x003C,0x0702,-1,0x003D,0x1604,-1,0x0050,0x0000,-1,0x0051,0x00EF,-1,0x0052,0x0000,-1,0x0053,0x013F,-1,0x0060,0xA700, \
121 -1,0x0061,0x0001,-1,0x006A,0x0000,-1,0x0080,0x0000,-1,0x0081,0x0000,-1,0x0082,0x0000,-1,0x0083,0x0000,-1,0x0084,0x0000, \
122 -1,0x0085,0x0000,-1,0x0090,0x0010,-1,0x0092,0x0600,-1,0x0007,0x0133,-3 };
123
124 static int ili9341_init[] = { \
125 -1,0x28,-2,20,-1,0xCF,0x00,0x83,0x30,-1,0xED,0x64,0x03,0x12,0x81,-1,0xE8,0x85,0x01,0x79, \
126 -1,0xCB,0x39,0x2c,0x00,0x34,0x02,-1,0xF7,0x20,-1,0xEA,0x00,0x00,-1,0xC0,0x26,-1,0xC1,0x11, \
127 -1,0xC5,0x35,0x3E,-1,0xC7,0xBE,-1,0xB1,0x00,0x1B,-1,0xB6,0x0a,0x82,0x27,0x00,-1,0xB7,0x07, \
128 -1,0x3A,0x55,-1,0x36,0x48,-1,0x11,-2,120,-1,0x29,-2,20,-3 };
129
130 static int ssd1351_init[] = { -1,0xfd,0x12,-1,0xfd,0xb1,-1,0xae,-1,0xb3,0xf1,-1,0xca,0x7f,-1,0xa0,0x74, \
131                               -1,0x15,0x00,0x7f,-1,0x75,0x00,0x7f,-1,0xa1,0x00,-1,0xa2,0x00,-1,0xb5,0x00, \
132                               -1,0xab,0x01,-1,0xb1,0x32,-1,0xb4,0xa0,0xb5,0x55,-1,0xbb,0x17,-1,0xbe,0x05, \
133                               -1,0xc1,0xc8,0x80,0xc8,-1,0xc7,0x0f,-1,0xb6,0x01,-1,0xa6,-1,0xaf,-3 };
134
135
136 /* ili9320, ili9325 */
137 static void flexfb_set_addr_win_1(struct fbtft_par *par,
138                                   int xs, int ys, int xe, int ye)
139 {
140         fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
141                      "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n",
142                      __func__, xs, ys, xe, ye);
143         switch (par->info->var.rotate) {
144         /* R20h = Horizontal GRAM Start Address */
145         /* R21h = Vertical GRAM Start Address */
146         case 0:
147                 write_reg(par, 0x0020, xs);
148                 write_reg(par, 0x0021, ys);
149                 break;
150         case 180:
151                 write_reg(par, 0x0020, width - 1 - xs);
152                 write_reg(par, 0x0021, height - 1 - ys);
153                 break;
154         case 270:
155                 write_reg(par, 0x0020, width - 1 - ys);
156                 write_reg(par, 0x0021, xs);
157                 break;
158         case 90:
159                 write_reg(par, 0x0020, ys);
160                 write_reg(par, 0x0021, height - 1 - xs);
161                 break;
162         }
163         write_reg(par, 0x0022); /* Write Data to GRAM */
164 }
165
166 /* ssd1289 */
167 static void flexfb_set_addr_win_2(struct fbtft_par *par,
168                                   int xs, int ys, int xe, int ye)
169 {
170         fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
171                       "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n",
172                       __func__, xs, ys, xe, ye);
173
174         switch (par->info->var.rotate) {
175         /* R4Eh - Set GDDRAM X address counter */
176         /* R4Fh - Set GDDRAM Y address counter */
177         case 0:
178                 write_reg(par, 0x4e, xs);
179                 write_reg(par, 0x4f, ys);
180                 break;
181         case 180:
182                 write_reg(par, 0x4e, par->info->var.xres - 1 - xs);
183                 write_reg(par, 0x4f, par->info->var.yres - 1 - ys);
184                 break;
185         case 270:
186                 write_reg(par, 0x4e, par->info->var.yres - 1 - ys);
187                 write_reg(par, 0x4f, xs);
188                 break;
189         case 90:
190                 write_reg(par, 0x4e, ys);
191                 write_reg(par, 0x4f, par->info->var.xres - 1 - xs);
192                 break;
193         }
194
195         /* R22h - RAM data write */
196         write_reg(par, 0x22, 0);
197 }
198
199 /* ssd1351 */
200 static void set_addr_win_3(struct fbtft_par *par,
201                            int xs, int ys, int xe, int ye)
202 {
203         fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
204                       "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__,
205                       xs, ys, xe, ye);
206
207         write_reg(par, 0x15, xs, xe);
208         write_reg(par, 0x75, ys, ye);
209         write_reg(par, 0x5C);
210 }
211
212 static int flexfb_verify_gpios_dc(struct fbtft_par *par)
213 {
214         fbtft_par_dbg(DEBUG_VERIFY_GPIOS, par, "%s()\n", __func__);
215
216         if (par->gpio.dc < 0) {
217                 dev_err(par->info->device,
218                         "Missing info about 'dc' gpio. Aborting.\n");
219                 return -EINVAL;
220         }
221
222         return 0;
223 }
224
225 static int flexfb_verify_gpios_db(struct fbtft_par *par)
226 {
227         int i;
228         int num_db = buswidth;
229
230         fbtft_par_dbg(DEBUG_VERIFY_GPIOS, par, "%s()\n", __func__);
231
232         if (par->gpio.dc < 0) {
233                 dev_err(par->info->device, "Missing info about 'dc' gpio. Aborting.\n");
234                 return -EINVAL;
235         }
236         if (par->gpio.wr < 0) {
237                 dev_err(par->info->device, "Missing info about 'wr' gpio. Aborting.\n");
238                 return -EINVAL;
239         }
240         if (latched && (par->gpio.latch < 0)) {
241                 dev_err(par->info->device, "Missing info about 'latch' gpio. Aborting.\n");
242                 return -EINVAL;
243         }
244         if (latched)
245                 num_db=buswidth/2;
246         for (i=0;i < num_db;i++) {
247                 if (par->gpio.db[i] < 0) {
248                         dev_err(par->info->device,
249                                 "Missing info about 'db%02d' gpio. Aborting.\n",
250                                 i);
251                         return -EINVAL;
252                 }
253         }
254
255         return 0;
256 }
257
258 static struct fbtft_display flex_display = { };
259
260 static int flexfb_probe_common(struct spi_device *sdev,
261                                struct platform_device *pdev)
262 {
263         struct device *dev;
264         struct fb_info *info;
265         struct fbtft_par *par;
266         int ret;
267
268         initp = init;
269         initp_num = init_num;
270
271         if (sdev)
272                 dev = &sdev->dev;
273         else
274                 dev = &pdev->dev;
275
276         fbtft_init_dbg(dev, "%s(%s)\n", __func__,
277                        sdev ? "'SPI device'" : "'Platform device'");
278
279         if (chip) {
280
281                 if (!strcmp(chip, "st7735r")) {
282                         if (!width)
283                                 width = 128;
284                         if (!height)
285                                 height = 160;
286                         if (init_num == 0) {
287                                 initp = st7735r_init;
288                                 initp_num = ARRAY_SIZE(st7735r_init);
289                         }
290
291
292                 } else if (!strcmp(chip, "hx8340bn")) {
293                         if (!width)
294                                 width = 176;
295                         if (!height)
296                                 height = 220;
297                         setaddrwin = 0;
298                         if (init_num == 0) {
299                                 initp = hx8340bn_init;
300                                 initp_num = ARRAY_SIZE(hx8340bn_init);
301                         }
302
303
304                 } else if (!strcmp(chip, "ili9225")) {
305                         if (!width)
306                                 width = 176;
307                         if (!height)
308                                 height = 220;
309                         setaddrwin = 0;
310                         regwidth = 16;
311                         if (init_num == 0) {
312                                 initp = ili9225_init;
313                                 initp_num = ARRAY_SIZE(ili9225_init);
314                         }
315
316
317
318                 } else if (!strcmp(chip, "ili9320")) {
319                         if (!width)
320                                 width = 240;
321                         if (!height)
322                                 height = 320;
323                         setaddrwin = 1;
324                         regwidth = 16;
325                         if (init_num == 0) {
326                                 initp = ili9320_init;
327                                 initp_num = ARRAY_SIZE(ili9320_init);
328                         }
329
330
331                 } else if (!strcmp(chip, "ili9325")) {
332                         if (!width)
333                                 width = 240;
334                         if (!height)
335                                 height = 320;
336                         setaddrwin = 1;
337                         regwidth = 16;
338                         if (init_num == 0) {
339                                 initp = ili9325_init;
340                                 initp_num = ARRAY_SIZE(ili9325_init);
341                         }
342
343                 } else if (!strcmp(chip, "ili9341")) {
344                         if (!width)
345                                 width = 240;
346                         if (!height)
347                                 height = 320;
348                         setaddrwin = 0;
349                         regwidth = 8;
350                         if (init_num == 0) {
351                                 initp = ili9341_init;
352                                 initp_num = ARRAY_SIZE(ili9341_init);
353                         }
354
355
356                 } else if (!strcmp(chip, "ssd1289")) {
357                         if (!width)
358                                 width = 240;
359                         if (!height)
360                                 height = 320;
361                         setaddrwin = 2;
362                         regwidth = 16;
363                         if (init_num == 0) {
364                                 initp = ssd1289_init;
365                                 initp_num = ARRAY_SIZE(ssd1289_init);
366                         }
367
368
369
370                 } else if (!strcmp(chip, "ssd1351")) {
371                         if (!width)
372                                 width = 128;
373                         if (!height)
374                                 height = 128;
375                         setaddrwin = 3;
376                         if (init_num == 0) {
377                                 initp = ssd1351_init;
378                                 initp_num = ARRAY_SIZE(ssd1351_init);
379                         }
380                 } else {
381                         dev_err(dev, "chip=%s is not supported\n", chip);
382                         return -EINVAL;
383                 }
384         }
385
386         if (width == 0 || height == 0) {
387                 dev_err(dev, "argument(s) missing: width and height has to be set.\n");
388                 return -EINVAL;
389         }
390         flex_display.width = width;
391         flex_display.height = height;
392         fbtft_init_dbg(dev, "Display resolution: %dx%d\n", width, height);
393         fbtft_init_dbg(dev, "chip = %s\n", chip ? chip : "not set");
394         fbtft_init_dbg(dev, "setaddrwin = %d\n", setaddrwin);
395         fbtft_init_dbg(dev, "regwidth = %d\n", regwidth);
396         fbtft_init_dbg(dev, "buswidth = %d\n", buswidth);
397
398         info = fbtft_framebuffer_alloc(&flex_display, dev);
399         if (!info)
400                 return -ENOMEM;
401
402         par = info->par;
403         if (sdev)
404                 par->spi = sdev;
405         else
406                 par->pdev = pdev;
407         if (!par->init_sequence)
408                 par->init_sequence = initp;
409         par->fbtftops.init_display = fbtft_init_display;
410
411         /* registerwrite functions */
412         switch (regwidth) {
413         case 8:
414                 par->fbtftops.write_register = fbtft_write_reg8_bus8;
415                 break;
416         case 16:
417                 par->fbtftops.write_register = fbtft_write_reg16_bus8;
418                 break;
419         default:
420                 dev_err(dev,
421                         "argument 'regwidth': %d is not supported.\n",
422                         regwidth);
423                 return -EINVAL;
424         }
425
426         /* bus functions */
427         if (sdev) {
428                 par->fbtftops.write = fbtft_write_spi;
429                 switch (buswidth) {
430                 case 8:
431                         par->fbtftops.write_vmem = fbtft_write_vmem16_bus8;
432                         if (!par->startbyte)
433                                 par->fbtftops.verify_gpios = flexfb_verify_gpios_dc;
434                         break;
435                 case 9:
436                         if (regwidth == 16) {
437                                 dev_err(dev, "argument 'regwidth': %d is not supported with buswidth=%d and SPI.\n", regwidth, buswidth);
438                                 return -EINVAL;
439                         }
440                         par->fbtftops.write_register = fbtft_write_reg8_bus9;
441                         par->fbtftops.write_vmem = fbtft_write_vmem16_bus9;
442                         sdev->bits_per_word = 9;
443                         ret = sdev->master->setup(sdev);
444                         if (ret) {
445                                 dev_warn(dev,
446                                         "9-bit SPI not available, emulating using 8-bit.\n");
447                                 sdev->bits_per_word = 8;
448                                 ret = sdev->master->setup(sdev);
449                                 if (ret)
450                                         goto out_release;
451                                 /* allocate buffer with room for dc bits */
452                                 par->extra = devm_kzalloc(par->info->device,
453                                                 par->txbuf.len + (par->txbuf.len / 8) + 8,
454                                                 GFP_KERNEL);
455                                 if (!par->extra) {
456                                         ret = -ENOMEM;
457                                         goto out_release;
458                                 }
459                                 par->fbtftops.write = fbtft_write_spi_emulate_9;
460                         }
461                         break;
462                 default:
463                         dev_err(dev, "argument 'buswidth': %d is not supported with SPI.\n", buswidth);
464                         return -EINVAL;
465                 }
466         } else {
467                 par->fbtftops.verify_gpios = flexfb_verify_gpios_db;
468                 switch (buswidth) {
469                 case 8:
470                         par->fbtftops.write = fbtft_write_gpio8_wr;
471                         par->fbtftops.write_vmem = fbtft_write_vmem16_bus8;
472                         break;
473                 case 16:
474                         par->fbtftops.write_register = fbtft_write_reg16_bus16;
475                         if (latched)
476                                 par->fbtftops.write = fbtft_write_gpio16_wr_latched;
477                         else
478                                 par->fbtftops.write = fbtft_write_gpio16_wr;
479                         par->fbtftops.write_vmem = fbtft_write_vmem16_bus16;
480                         break;
481                 default:
482                         dev_err(dev, "argument 'buswidth': %d is not supported with parallel.\n", buswidth);
483                         return -EINVAL;
484                 }
485         }
486
487         /* set_addr_win function */
488         switch (setaddrwin) {
489         case 0:
490                 /* use default */
491                 break;
492         case 1:
493                 par->fbtftops.set_addr_win = flexfb_set_addr_win_1;
494                 break;
495         case 2:
496                 par->fbtftops.set_addr_win = flexfb_set_addr_win_2;
497                 break;
498         case 3:
499                 par->fbtftops.set_addr_win = set_addr_win_3;
500                 break;
501         default:
502                 dev_err(dev, "argument 'setaddrwin': unknown value %d.\n",
503                         setaddrwin);
504                 return -EINVAL;
505         }
506
507         if (!nobacklight)
508                 par->fbtftops.register_backlight = fbtft_register_backlight;
509
510         ret = fbtft_register_framebuffer(info);
511         if (ret < 0)
512                 goto out_release;
513
514         return 0;
515
516 out_release:
517         fbtft_framebuffer_release(info);
518
519         return ret;
520 }
521
522 static int flexfb_remove_common(struct device *dev, struct fb_info *info)
523 {
524         struct fbtft_par *par;
525
526         if (!info)
527                 return -EINVAL;
528         par = info->par;
529         if (par)
530                 fbtft_par_dbg(DEBUG_DRIVER_INIT_FUNCTIONS, par,
531                         "%s()\n", __func__);
532         fbtft_unregister_framebuffer(info);
533         fbtft_framebuffer_release(info);
534
535         return 0;
536 }
537
538 static int flexfb_probe_spi(struct spi_device *spi)
539 {
540         return flexfb_probe_common(spi, NULL);
541 }
542
543 static int flexfb_remove_spi(struct spi_device *spi)
544 {
545         struct fb_info *info = spi_get_drvdata(spi);
546
547         return flexfb_remove_common(&spi->dev, info);
548 }
549
550 static int flexfb_probe_pdev(struct platform_device *pdev)
551 {
552         return flexfb_probe_common(NULL, pdev);
553 }
554
555 static int flexfb_remove_pdev(struct platform_device *pdev)
556 {
557         struct fb_info *info = platform_get_drvdata(pdev);
558
559         return flexfb_remove_common(&pdev->dev, info);
560 }
561
562 static struct spi_driver flexfb_spi_driver = {
563         .driver = {
564                 .name   = DRVNAME,
565                 .owner  = THIS_MODULE,
566         },
567         .probe  = flexfb_probe_spi,
568         .remove = flexfb_remove_spi,
569 };
570
571 static const struct platform_device_id flexfb_platform_ids[] = {
572         { "flexpfb", 0 },
573         { },
574 };
575
576 static struct platform_driver flexfb_platform_driver = {
577         .driver = {
578                 .name   = DRVNAME,
579         },
580         .id_table = flexfb_platform_ids,
581         .probe  = flexfb_probe_pdev,
582         .remove = flexfb_remove_pdev,
583 };
584
585 static int __init flexfb_init(void)
586 {
587         int ret, ret2;
588
589         ret = spi_register_driver(&flexfb_spi_driver);
590         ret2 = platform_driver_register(&flexfb_platform_driver);
591         if (ret < 0)
592                 return ret;
593         return ret2;
594 }
595
596 static void __exit flexfb_exit(void)
597 {
598         spi_unregister_driver(&flexfb_spi_driver);
599         platform_driver_unregister(&flexfb_platform_driver);
600 }
601
602 /* ------------------------------------------------------------------------- */
603
604 module_init(flexfb_init);
605 module_exit(flexfb_exit);
606
607 MODULE_DESCRIPTION("Generic FB driver for TFT LCD displays");
608 MODULE_AUTHOR("Noralf Tronnes");
609 MODULE_LICENSE("GPL");