2 * FB driver for the ILI9340 LCD Controller
4 * Copyright (C) 2013 Noralf Tronnes
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.
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.
17 #include <linux/module.h>
18 #include <linux/kernel.h>
19 #include <linux/init.h>
20 #include <linux/gpio.h>
21 #include <linux/delay.h>
25 #define DRVNAME "fb_ili9340"
29 /* Init sequence taken from: Arduino Library for the Adafruit 2.2" display */
30 static int init_display(struct fbtft_par *par)
32 par->fbtftops.reset(par);
34 write_reg(par, 0xEF, 0x03, 0x80, 0x02);
35 write_reg(par, 0xCF, 0x00, 0XC1, 0X30);
36 write_reg(par, 0xED, 0x64, 0x03, 0X12, 0X81);
37 write_reg(par, 0xE8, 0x85, 0x00, 0x78);
38 write_reg(par, 0xCB, 0x39, 0x2C, 0x00, 0x34, 0x02);
39 write_reg(par, 0xF7, 0x20);
40 write_reg(par, 0xEA, 0x00, 0x00);
43 write_reg(par, 0xC0, 0x23);
46 write_reg(par, 0xC1, 0x10);
49 write_reg(par, 0xC5, 0x3e, 0x28);
52 write_reg(par, 0xC7, 0x86);
54 /* COLMOD: Pixel Format Set */
56 write_reg(par, 0x3A, 0x55);
58 /* Frame Rate Control */
59 /* Division ratio = fosc, Frame Rate = 79Hz */
60 write_reg(par, 0xB1, 0x00, 0x18);
62 /* Display Function Control */
63 write_reg(par, 0xB6, 0x08, 0x82, 0x27);
65 /* Gamma Function Disable */
66 write_reg(par, 0xF2, 0x00);
68 /* Gamma curve selected */
69 write_reg(par, 0x26, 0x01);
71 /* Positive Gamma Correction */
73 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1,
74 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00);
76 /* Negative Gamma Correction */
78 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1,
79 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F);
92 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
95 write_reg(par, 0x2A, xs >> 8, xs & 0xFF, xe >> 8, xe & 0xFF);
98 write_reg(par, 0x2B, ys >> 8, ys & 0xFF, ye >> 8, ye & 0xFF);
101 write_reg(par, 0x2C);
104 #define ILI9340_MADCTL_MV 0x20
105 #define ILI9340_MADCTL_MX 0x40
106 #define ILI9340_MADCTL_MY 0x80
107 static int set_var(struct fbtft_par *par)
111 switch (par->info->var.rotate) {
113 val = ILI9340_MADCTL_MV;
116 val = ILI9340_MADCTL_MY;
119 val = ILI9340_MADCTL_MV | ILI9340_MADCTL_MY | ILI9340_MADCTL_MX;
122 val = ILI9340_MADCTL_MX;
125 /* Memory Access Control */
126 write_reg(par, 0x36, val | (par->bgr << 3));
131 static struct fbtft_display display = {
136 .init_display = init_display,
137 .set_addr_win = set_addr_win,
142 FBTFT_REGISTER_DRIVER(DRVNAME, "ilitek,ili9340", &display);
144 MODULE_ALIAS("spi:" DRVNAME);
145 MODULE_ALIAS("platform:" DRVNAME);
146 MODULE_ALIAS("spi:ili9340");
147 MODULE_ALIAS("platform:ili9340");
149 MODULE_DESCRIPTION("FB driver for the ILI9340 LCD Controller");
150 MODULE_AUTHOR("Noralf Tronnes");
151 MODULE_LICENSE("GPL");