]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/fbtft/fb_ili9481.c
Merge branch 'akpm-current/current'
[karo-tx-linux.git] / 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
18 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/init.h>
21 #include <linux/delay.h>
22 #include <video/mipi_display.h>
23
24 #include "fbtft.h"
25
26 #define DRVNAME "fb_ili9481"
27 #define WIDTH           320
28 #define HEIGHT          480
29
30 static int default_init_sequence[] = {
31
32         /* SLP_OUT - Sleep out */
33         -1, MIPI_DCS_EXIT_SLEEP_MODE,
34         -2, 50,
35         /* Power setting */
36         -1, 0xD0, 0x07, 0x42, 0x18,
37         /* VCOM */
38         -1, 0xD1, 0x00, 0x07, 0x10,
39         /* Power setting for norm. mode */
40         -1, 0xD2, 0x01, 0x02,
41         /* Panel driving setting */
42         -1, 0xC0, 0x10, 0x3B, 0x00, 0x02, 0x11,
43         /* Frame rate & inv. */
44         -1, 0xC5, 0x03,
45         /* Pixel format */
46         -1, MIPI_DCS_SET_PIXEL_FORMAT, 0x55,
47         /* Gamma */
48         -1, 0xC8, 0x00, 0x32, 0x36, 0x45, 0x06, 0x16,
49                   0x37, 0x75, 0x77, 0x54, 0x0C, 0x00,
50         /* DISP_ON */
51         -1, MIPI_DCS_SET_DISPLAY_ON,
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 #define HFLIP 0x01
67 #define VFLIP 0x02
68 #define ROWxCOL 0x20
69 static int set_var(struct fbtft_par *par)
70 {
71         switch (par->info->var.rotate) {
72         case 270:
73                 write_reg(par, MIPI_DCS_SET_ADDRESS_MODE,
74                           ROWxCOL | HFLIP | VFLIP | (par->bgr << 3));
75                 break;
76         case 180:
77                 write_reg(par, MIPI_DCS_SET_ADDRESS_MODE,
78                           VFLIP | (par->bgr << 3));
79                 break;
80         case 90:
81                 write_reg(par, MIPI_DCS_SET_ADDRESS_MODE,
82                           ROWxCOL | (par->bgr << 3));
83                 break;
84         default:
85                 write_reg(par, MIPI_DCS_SET_ADDRESS_MODE,
86                           HFLIP | (par->bgr << 3));
87                 break;
88         }
89
90         return 0;
91 }
92
93 static struct fbtft_display display = {
94         .regwidth = 8,
95         .width = WIDTH,
96         .height = HEIGHT,
97         .init_sequence = default_init_sequence,
98         .fbtftops = {
99                 .set_addr_win = set_addr_win,
100                 .set_var = set_var,
101         },
102 };
103
104 FBTFT_REGISTER_DRIVER(DRVNAME, "ilitek,ili9481", &display);
105
106 MODULE_ALIAS("spi:" DRVNAME);
107 MODULE_ALIAS("platform:" DRVNAME);
108 MODULE_ALIAS("spi:ili9481");
109 MODULE_ALIAS("platform:ili9481");
110
111 MODULE_DESCRIPTION("FB driver for the ILI9481 LCD Controller");
112 MODULE_AUTHOR("Petr Olivka");
113 MODULE_LICENSE("GPL");