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  * 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 
25 #include "fbtft.h"
26 
27 #define DRVNAME		"fb_ili9486"
28 #define WIDTH		320
29 #define HEIGHT		480
30 
31 
32 /* this init sequence matches PiScreen */
33 static int default_init_sequence[] = {
34 	/* Interface Mode Control */
35 	-1, 0xb0, 0x0,
36 	/* Sleep OUT */
37 	-1, 0x11,
38 	-2, 250,
39 	/* Interface Pixel Format */
40 	-1, 0x3A, 0x55,
41 	/* Power Control 3 */
42 	-1, 0xC2, 0x44,
43 	/* VCOM Control 1 */
44 	-1, 0xC5, 0x00, 0x00, 0x00, 0x00,
45 	/* PGAMCTRL(Positive Gamma Control) */
46 	-1, 0xE0, 0x0F, 0x1F, 0x1C, 0x0C, 0x0F, 0x08, 0x48, 0x98,
47 		  0x37, 0x0A, 0x13, 0x04, 0x11, 0x0D, 0x00,
48 	/* NGAMCTRL(Negative Gamma Control) */
49 	-1, 0xE1, 0x0F, 0x32, 0x2E, 0x0B, 0x0D, 0x05, 0x47, 0x75,
50 		  0x37, 0x06, 0x10, 0x03, 0x24, 0x20, 0x00,
51 	/* Digital Gamma Control 1 */
52 	-1, 0xE2, 0x0F, 0x32, 0x2E, 0x0B, 0x0D, 0x05, 0x47, 0x75,
53 		  0x37, 0x06, 0x10, 0x03, 0x24, 0x20, 0x00,
54 	/* Sleep OUT */
55 	-1, 0x11,
56 	/* Display ON */
57 	-1, 0x29,
58 	/* end marker */
59 	-3
60 };
61 
62 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
63 {
64 	fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
65 		"%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
66 
67 	/* Column address */
68 	write_reg(par, 0x2A, xs >> 8, xs & 0xFF, xe >> 8, xe & 0xFF);
69 
70 	/* Row address */
71 	write_reg(par, 0x2B, ys >> 8, ys & 0xFF, ye >> 8, ye & 0xFF);
72 
73 	/* Memory write */
74 	write_reg(par, 0x2C);
75 }
76 
77 static int set_var(struct fbtft_par *par)
78 {
79 	fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
80 
81 	switch (par->info->var.rotate) {
82 	case 0:
83 		write_reg(par, 0x36, 0x80 | (par->bgr << 3));
84 		break;
85 	case 90:
86 		write_reg(par, 0x36, 0x20 | (par->bgr << 3));
87 		break;
88 	case 180:
89 		write_reg(par, 0x36, 0x40 | (par->bgr << 3));
90 		break;
91 	case 270:
92 		write_reg(par, 0x36, 0xE0 | (par->bgr << 3));
93 		break;
94 	default:
95 		break;
96 	}
97 
98 	return 0;
99 }
100 
101 
102 static struct fbtft_display display = {
103 	.regwidth = 8,
104 	.width = WIDTH,
105 	.height = HEIGHT,
106 	.init_sequence = default_init_sequence,
107 	.fbtftops = {
108 		.set_addr_win = set_addr_win,
109 		.set_var = set_var,
110 	},
111 };
112 FBTFT_REGISTER_DRIVER(DRVNAME, "ilitek,ili9486", &display);
113 
114 MODULE_ALIAS("spi:" DRVNAME);
115 MODULE_ALIAS("platform:" DRVNAME);
116 MODULE_ALIAS("spi:ili9486");
117 MODULE_ALIAS("platform:ili9486");
118 
119 MODULE_DESCRIPTION("FB driver for the ILI9486 LCD Controller");
120 MODULE_AUTHOR("Noralf Tronnes");
121 MODULE_LICENSE("GPL");
122