Merge remote-tracking branch 'asoc/topic/tas5270' into asoc-next
[deliverable/linux.git] / drivers / staging / fbtft / fb_ili9340.c
CommitLineData
8f7fdaaf
TP
1/*
2 * FB driver for the ILI9340 LCD Controller
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.
8f7fdaaf
TP
15 */
16
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>
261a984c 22#include <video/mipi_display.h>
8f7fdaaf
TP
23
24#include "fbtft.h"
25
26#define DRVNAME "fb_ili9340"
27#define WIDTH 240
28#define HEIGHT 320
29
8f7fdaaf
TP
30/* Init sequence taken from: Arduino Library for the Adafruit 2.2" display */
31static int init_display(struct fbtft_par *par)
32{
8f7fdaaf
TP
33 par->fbtftops.reset(par);
34
35 write_reg(par, 0xEF, 0x03, 0x80, 0x02);
43da0d92
AM
36 write_reg(par, 0xCF, 0x00, 0XC1, 0X30);
37 write_reg(par, 0xED, 0x64, 0x03, 0X12, 0X81);
38 write_reg(par, 0xE8, 0x85, 0x00, 0x78);
39 write_reg(par, 0xCB, 0x39, 0x2C, 0x00, 0x34, 0x02);
8f7fdaaf 40 write_reg(par, 0xF7, 0x20);
43da0d92 41 write_reg(par, 0xEA, 0x00, 0x00);
8f7fdaaf
TP
42
43 /* Power Control 1 */
44 write_reg(par, 0xC0, 0x23);
45
46 /* Power Control 2 */
47 write_reg(par, 0xC1, 0x10);
48
49 /* VCOM Control 1 */
50 write_reg(par, 0xC5, 0x3e, 0x28);
51
52 /* VCOM Control 2 */
53 write_reg(par, 0xC7, 0x86);
54
55 /* COLMOD: Pixel Format Set */
56 /* 16 bits/pixel */
261a984c 57 write_reg(par, MIPI_DCS_SET_PIXEL_FORMAT, 0x55);
8f7fdaaf
TP
58
59 /* Frame Rate Control */
60 /* Division ratio = fosc, Frame Rate = 79Hz */
61 write_reg(par, 0xB1, 0x00, 0x18);
62
63 /* Display Function Control */
64 write_reg(par, 0xB6, 0x08, 0x82, 0x27);
65
66 /* Gamma Function Disable */
67 write_reg(par, 0xF2, 0x00);
68
261a984c
PL
69 /* Gamma curve selection */
70 write_reg(par, MIPI_DCS_SET_GAMMA_CURVE, 0x01);
8f7fdaaf
TP
71
72 /* Positive Gamma Correction */
73 write_reg(par, 0xE0,
f07e89ce
ERR
74 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1,
75 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00);
8f7fdaaf
TP
76
77 /* Negative Gamma Correction */
78 write_reg(par, 0xE1,
f07e89ce
ERR
79 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1,
80 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F);
8f7fdaaf 81
261a984c 82 write_reg(par, MIPI_DCS_EXIT_SLEEP_MODE);
8f7fdaaf
TP
83
84 mdelay(120);
85
261a984c 86 write_reg(par, MIPI_DCS_SET_DISPLAY_ON);
8f7fdaaf
TP
87
88 return 0;
89}
90
91static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
92{
261a984c
PL
93 write_reg(par, MIPI_DCS_SET_COLUMN_ADDRESS,
94 xs >> 8, xs & 0xFF, xe >> 8, xe & 0xFF);
8f7fdaaf 95
261a984c
PL
96 write_reg(par, MIPI_DCS_SET_PAGE_ADDRESS,
97 ys >> 8, ys & 0xFF, ye >> 8, ye & 0xFF);
8f7fdaaf 98
261a984c 99 write_reg(par, MIPI_DCS_WRITE_MEMORY_START);
8f7fdaaf
TP
100}
101
102#define ILI9340_MADCTL_MV 0x20
103#define ILI9340_MADCTL_MX 0x40
104#define ILI9340_MADCTL_MY 0x80
105static int set_var(struct fbtft_par *par)
106{
107 u8 val;
108
8f7fdaaf
TP
109 switch (par->info->var.rotate) {
110 case 270:
111 val = ILI9340_MADCTL_MV;
112 break;
113 case 180:
114 val = ILI9340_MADCTL_MY;
115 break;
116 case 90:
117 val = ILI9340_MADCTL_MV | ILI9340_MADCTL_MY | ILI9340_MADCTL_MX;
118 break;
119 default:
120 val = ILI9340_MADCTL_MX;
121 break;
122 }
123 /* Memory Access Control */
261a984c 124 write_reg(par, MIPI_DCS_SET_ADDRESS_MODE, val | (par->bgr << 3));
8f7fdaaf
TP
125
126 return 0;
127}
128
8f7fdaaf
TP
129static struct fbtft_display display = {
130 .regwidth = 8,
131 .width = WIDTH,
132 .height = HEIGHT,
133 .fbtftops = {
134 .init_display = init_display,
135 .set_addr_win = set_addr_win,
136 .set_var = set_var,
137 },
138};
1014c2ce 139
8f7fdaaf
TP
140FBTFT_REGISTER_DRIVER(DRVNAME, "ilitek,ili9340", &display);
141
142MODULE_ALIAS("spi:" DRVNAME);
143MODULE_ALIAS("platform:" DRVNAME);
144MODULE_ALIAS("spi:ili9340");
145MODULE_ALIAS("platform:ili9340");
146
147MODULE_DESCRIPTION("FB driver for the ILI9340 LCD Controller");
148MODULE_AUTHOR("Noralf Tronnes");
149MODULE_LICENSE("GPL");
This page took 0.179308 seconds and 5 git commands to generate.