1 /*
2 * FB driver for the S6D02A1 LCD Controller
3 *
4 * Based on fb_st7735r.c by Noralf Tronnes
5 * Init code from UTFT library by Henning Karlsen
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
22 #include "fbtft.h"
23
24 #define DRVNAME "fb_s6d02a1"
25
26 static int default_init_sequence[] = {
27
28 -1, 0xf0, 0x5a, 0x5a,
29
30 -1, 0xfc, 0x5a, 0x5a,
31
32 -1, 0xfa, 0x02, 0x1f, 0x00, 0x10, 0x22, 0x30, 0x38, 0x3A, 0x3A, 0x3A, 0x3A, 0x3A, 0x3d, 0x02, 0x01,
33
34 -1, 0xfb, 0x21, 0x00, 0x02, 0x04, 0x07, 0x0a, 0x0b, 0x0c, 0x0c, 0x16, 0x1e, 0x30, 0x3f, 0x01, 0x02,
35
36 /* power setting sequence */
37 -1, 0xfd, 0x00, 0x00, 0x00, 0x17, 0x10, 0x00, 0x01, 0x01, 0x00, 0x1f, 0x1f,
38
39 -1, 0xf4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x3f, 0x07, 0x00, 0x3C, 0x36, 0x00, 0x3C, 0x36, 0x00,
40
41 -1, 0xf5, 0x00, 0x70, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6d, 0x66, 0x06,
42
43 -1, 0xf6, 0x02, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x02, 0x00, 0x06, 0x01, 0x00,
44
45 -1, 0xf2, 0x00, 0x01, 0x03, 0x08, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x04, 0x08, 0x08,
46
47 -1, 0xf8, 0x11,
48
49 -1, 0xf7, 0xc8, 0x20, 0x00, 0x00,
50
51 -1, 0xf3, 0x00, 0x00,
52
53 -1, 0x11,
54 -2, 50,
55
56 -1, 0xf3, 0x00, 0x01,
57 -2, 50,
58 -1, 0xf3, 0x00, 0x03,
59 -2, 50,
60 -1, 0xf3, 0x00, 0x07,
61 -2, 50,
62 -1, 0xf3, 0x00, 0x0f,
63 -2, 50,
64
65 -1, 0xf4, 0x00, 0x04, 0x00, 0x00, 0x00, 0x3f, 0x3f, 0x07, 0x00, 0x3C, 0x36, 0x00, 0x3C, 0x36, 0x00,
66 -2, 50,
67
68 -1, 0xf3, 0x00, 0x1f,
69 -2, 50,
70 -1, 0xf3, 0x00, 0x7f,
71 -2, 50,
72
73 -1, 0xf3, 0x00, 0xff,
74 -2, 50,
75
76 -1, 0xfd, 0x00, 0x00, 0x00, 0x17, 0x10, 0x00, 0x00, 0x01, 0x00, 0x16, 0x16,
77
78 -1, 0xf4, 0x00, 0x09, 0x00, 0x00, 0x00, 0x3f, 0x3f, 0x07, 0x00, 0x3C, 0x36, 0x00, 0x3C, 0x36, 0x00,
79
80 /* initializing sequence */
81
82 -1, 0x36, 0x08,
83
84 -1, 0x35, 0x00,
85
86 -1, 0x3a, 0x05,
87
88 /* gamma setting sequence */
89 -1, 0x26, 0x01, /* preset gamma curves, possible values 0x01, 0x02, 0x04, 0x08 */
90
91 -2, 150,
92 -1, 0x29,
93 -1, 0x2c,
94 /* end marker */
95 -3
96
97 };
98
set_addr_win(struct fbtft_par * par,int xs,int ys,int xe,int ye)99 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
100 {
101 /* Column address */
102 write_reg(par, 0x2A, xs >> 8, xs & 0xFF, xe >> 8, xe & 0xFF);
103
104 /* Row address */
105 write_reg(par, 0x2B, ys >> 8, ys & 0xFF, ye >> 8, ye & 0xFF);
106
107 /* Memory write */
108 write_reg(par, 0x2C);
109 }
110
111 #define MY BIT(7)
112 #define MX BIT(6)
113 #define MV BIT(5)
set_var(struct fbtft_par * par)114 static int set_var(struct fbtft_par *par)
115 {
116 /* MADCTL - Memory data access control
117 RGB/BGR:
118 1. Mode selection pin SRGB
119 RGB H/W pin for color filter setting: 0=RGB, 1=BGR
120 2. MADCTL RGB bit
121 RGB-BGR ORDER color filter panel: 0=RGB, 1=BGR */
122 switch (par->info->var.rotate) {
123 case 0:
124 write_reg(par, 0x36, MX | MY | (par->bgr << 3));
125 break;
126 case 270:
127 write_reg(par, 0x36, MY | MV | (par->bgr << 3));
128 break;
129 case 180:
130 write_reg(par, 0x36, par->bgr << 3);
131 break;
132 case 90:
133 write_reg(par, 0x36, MX | MV | (par->bgr << 3));
134 break;
135 }
136
137 return 0;
138 }
139
140 static struct fbtft_display display = {
141 .regwidth = 8,
142 .width = 128,
143 .height = 160,
144 .init_sequence = default_init_sequence,
145 .fbtftops = {
146 .set_addr_win = set_addr_win,
147 .set_var = set_var,
148 },
149 };
150
151 FBTFT_REGISTER_DRIVER(DRVNAME, "samsung,s6d02a1", &display);
152
153 MODULE_ALIAS("spi:" DRVNAME);
154 MODULE_ALIAS("platform:" DRVNAME);
155 MODULE_ALIAS("spi:s6d02a1");
156 MODULE_ALIAS("platform:s6d02a1");
157
158 MODULE_DESCRIPTION("FB driver for the S6D02A1 LCD Controller");
159 MODULE_AUTHOR("WOLFGANG BUENING");
160 MODULE_LICENSE("GPL");
161