GNU Linux-libre 4.9.315-gnu1
[releases.git] / drivers / staging / fbtft / fb_ili9486.c
1 /*
2  * FB driver for the ILI9486 LCD Controller
3  *
4  * Copyright (C) 2014 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 <video/mipi_display.h>
21
22 #include "fbtft.h"
23
24 #define DRVNAME         "fb_ili9486"
25 #define WIDTH           320
26 #define HEIGHT          480
27
28 /* this init sequence matches PiScreen */
29 static int default_init_sequence[] = {
30         /* Interface Mode Control */
31         -1, 0xb0, 0x0,
32         -1, MIPI_DCS_EXIT_SLEEP_MODE,
33         -2, 250,
34         /* Interface Pixel Format */
35         -1, MIPI_DCS_SET_PIXEL_FORMAT, 0x55,
36         /* Power Control 3 */
37         -1, 0xC2, 0x44,
38         /* VCOM Control 1 */
39         -1, 0xC5, 0x00, 0x00, 0x00, 0x00,
40         /* PGAMCTRL(Positive Gamma Control) */
41         -1, 0xE0, 0x0F, 0x1F, 0x1C, 0x0C, 0x0F, 0x08, 0x48, 0x98,
42                   0x37, 0x0A, 0x13, 0x04, 0x11, 0x0D, 0x00,
43         /* NGAMCTRL(Negative Gamma Control) */
44         -1, 0xE1, 0x0F, 0x32, 0x2E, 0x0B, 0x0D, 0x05, 0x47, 0x75,
45                   0x37, 0x06, 0x10, 0x03, 0x24, 0x20, 0x00,
46         /* Digital Gamma Control 1 */
47         -1, 0xE2, 0x0F, 0x32, 0x2E, 0x0B, 0x0D, 0x05, 0x47, 0x75,
48                   0x37, 0x06, 0x10, 0x03, 0x24, 0x20, 0x00,
49         -1, MIPI_DCS_EXIT_SLEEP_MODE,
50         -1, MIPI_DCS_SET_DISPLAY_ON,
51         /* end marker */
52         -3
53 };
54
55 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
56 {
57         write_reg(par, MIPI_DCS_SET_COLUMN_ADDRESS,
58                   xs >> 8, xs & 0xFF, xe >> 8, xe & 0xFF);
59
60         write_reg(par, MIPI_DCS_SET_PAGE_ADDRESS,
61                   ys >> 8, ys & 0xFF, ye >> 8, ye & 0xFF);
62
63         write_reg(par, MIPI_DCS_WRITE_MEMORY_START);
64 }
65
66 static int set_var(struct fbtft_par *par)
67 {
68         switch (par->info->var.rotate) {
69         case 0:
70                 write_reg(par, MIPI_DCS_SET_ADDRESS_MODE,
71                           0x80 | (par->bgr << 3));
72                 break;
73         case 90:
74                 write_reg(par, MIPI_DCS_SET_ADDRESS_MODE,
75                           0x20 | (par->bgr << 3));
76                 break;
77         case 180:
78                 write_reg(par, MIPI_DCS_SET_ADDRESS_MODE,
79                           0x40 | (par->bgr << 3));
80                 break;
81         case 270:
82                 write_reg(par, MIPI_DCS_SET_ADDRESS_MODE,
83                           0xE0 | (par->bgr << 3));
84                 break;
85         default:
86                 break;
87         }
88
89         return 0;
90 }
91
92 static struct fbtft_display display = {
93         .regwidth = 8,
94         .width = WIDTH,
95         .height = HEIGHT,
96         .init_sequence = default_init_sequence,
97         .fbtftops = {
98                 .set_addr_win = set_addr_win,
99                 .set_var = set_var,
100         },
101 };
102
103 FBTFT_REGISTER_DRIVER(DRVNAME, "ilitek,ili9486", &display);
104
105 MODULE_ALIAS("spi:" DRVNAME);
106 MODULE_ALIAS("platform:" DRVNAME);
107 MODULE_ALIAS("spi:ili9486");
108 MODULE_ALIAS("platform:ili9486");
109
110 MODULE_DESCRIPTION("FB driver for the ILI9486 LCD Controller");
111 MODULE_AUTHOR("Noralf Tronnes");
112 MODULE_LICENSE("GPL");