Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / drivers / staging / fbtft / fb_ili9481.c
1 /*
2  * FB driver for the ILI9481 LCD Controller
3  *
4  * Copyright (c) 2014 Petr Olivka
5  * Copyright (c) 2013 Noralf Tronnes
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21
22 #include <linux/module.h>
23 #include <linux/kernel.h>
24 #include <linux/init.h>
25 #include <linux/delay.h>
26
27 #include "fbtft.h"
28
29 #define DRVNAME "fb_ili9481"
30 #define WIDTH           320
31 #define HEIGHT          480
32
33 static int default_init_sequence[] = {
34
35         /* SLP_OUT - Sleep out */
36         -1, 0x11,
37         -2, 50,
38         /* Power setting */
39         -1, 0xD0, 0x07, 0x42, 0x18,
40         /* VCOM */
41         -1, 0xD1, 0x00, 0x07, 0x10,
42         /* Power setting for norm. mode */
43         -1, 0xD2, 0x01, 0x02,
44         /* Panel driving setting */
45         -1, 0xC0, 0x10, 0x3B, 0x00, 0x02, 0x11,
46         /* Frame rate & inv. */
47         -1, 0xC5, 0x03,
48         /* Pixel format */
49         -1, 0x3A, 0x55,
50         /* Gamma */
51         -1, 0xC8, 0x00, 0x32, 0x36, 0x45, 0x06, 0x16,
52                   0x37, 0x75, 0x77, 0x54, 0x0C, 0x00,
53         /* DISP_ON */
54         -1, 0x29,
55         -3
56 };
57
58 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
59 {
60         fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
61                 "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
62
63         /* column address */
64         write_reg(par, 0x2a, xs >> 8, xs & 0xff, xe >> 8, xe & 0xff);
65
66         /* Row address */
67         write_reg(par, 0x2b, ys >> 8, ys & 0xff, ye >> 8, ye & 0xff);
68
69         /* memory write */
70         write_reg(par, 0x2c);
71 }
72
73 #define HFLIP 0x01
74 #define VFLIP 0x02
75 #define ROWxCOL 0x20
76 static int set_var(struct fbtft_par *par)
77 {
78         fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
79
80         switch (par->info->var.rotate) {
81         case 270:
82                 write_reg(par, 0x36, ROWxCOL | HFLIP | VFLIP | (par->bgr << 3));
83                 break;
84         case 180:
85                 write_reg(par, 0x36, VFLIP | (par->bgr << 3));
86                 break;
87         case 90:
88                 write_reg(par, 0x36, ROWxCOL | (par->bgr << 3));
89                 break;
90         default:
91                 write_reg(par, 0x36, HFLIP | (par->bgr << 3));
92                 break;
93         }
94
95         return 0;
96 }
97
98 static struct fbtft_display display = {
99         .regwidth = 8,
100         .width = WIDTH,
101         .height = HEIGHT,
102         .init_sequence = default_init_sequence,
103         .fbtftops = {
104                 .set_addr_win = set_addr_win,
105                 .set_var = set_var,
106         },
107 };
108 FBTFT_REGISTER_DRIVER(DRVNAME, "ilitek,ili9481", &display);
109
110 MODULE_ALIAS("spi:" DRVNAME);
111 MODULE_ALIAS("platform:" DRVNAME);
112 MODULE_ALIAS("spi:ili9481");
113 MODULE_ALIAS("platform:ili9481");
114
115 MODULE_DESCRIPTION("FB driver for the ILI9481 LCD Controller");
116 MODULE_AUTHOR("Petr Olivka");
117 MODULE_LICENSE("GPL");