1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#include <linux/module.h>
20#include <linux/kernel.h>
21#include <linux/init.h>
22#include <linux/gpio.h>
23
24#include "fbtft.h"
25
26#define DRVNAME "fb_ssd1289"
27#define WIDTH 240
28#define HEIGHT 320
29#define DEFAULT_GAMMA "02 03 2 5 7 7 4 2 4 2\n" \
30 "02 03 2 5 7 5 4 2 4 2"
31
32static unsigned int reg11 = 0x6040;
33module_param(reg11, uint, 0000);
34MODULE_PARM_DESC(reg11, "Register 11h value");
35
36static int init_display(struct fbtft_par *par)
37{
38 par->fbtftops.reset(par);
39
40 if (par->gpio.cs != -1)
41 gpio_set_value(par->gpio.cs, 0);
42
43 write_reg(par, 0x00, 0x0001);
44 write_reg(par, 0x03, 0xA8A4);
45 write_reg(par, 0x0C, 0x0000);
46 write_reg(par, 0x0D, 0x080C);
47 write_reg(par, 0x0E, 0x2B00);
48 write_reg(par, 0x1E, 0x00B7);
49 write_reg(par, 0x01,
50 (1 << 13) | (par->bgr << 11) | (1 << 9) | (HEIGHT - 1));
51 write_reg(par, 0x02, 0x0600);
52 write_reg(par, 0x10, 0x0000);
53 write_reg(par, 0x05, 0x0000);
54 write_reg(par, 0x06, 0x0000);
55 write_reg(par, 0x16, 0xEF1C);
56 write_reg(par, 0x17, 0x0003);
57 write_reg(par, 0x07, 0x0233);
58 write_reg(par, 0x0B, 0x0000);
59 write_reg(par, 0x0F, 0x0000);
60 write_reg(par, 0x41, 0x0000);
61 write_reg(par, 0x42, 0x0000);
62 write_reg(par, 0x48, 0x0000);
63 write_reg(par, 0x49, 0x013F);
64 write_reg(par, 0x4A, 0x0000);
65 write_reg(par, 0x4B, 0x0000);
66 write_reg(par, 0x44, 0xEF00);
67 write_reg(par, 0x45, 0x0000);
68 write_reg(par, 0x46, 0x013F);
69 write_reg(par, 0x23, 0x0000);
70 write_reg(par, 0x24, 0x0000);
71 write_reg(par, 0x25, 0x8000);
72 write_reg(par, 0x4f, 0x0000);
73 write_reg(par, 0x4e, 0x0000);
74 write_reg(par, 0x22);
75 return 0;
76}
77
78static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
79{
80 switch (par->info->var.rotate) {
81
82
83 case 0:
84 write_reg(par, 0x4e, xs);
85 write_reg(par, 0x4f, ys);
86 break;
87 case 180:
88 write_reg(par, 0x4e, par->info->var.xres - 1 - xs);
89 write_reg(par, 0x4f, par->info->var.yres - 1 - ys);
90 break;
91 case 270:
92 write_reg(par, 0x4e, par->info->var.yres - 1 - ys);
93 write_reg(par, 0x4f, xs);
94 break;
95 case 90:
96 write_reg(par, 0x4e, ys);
97 write_reg(par, 0x4f, par->info->var.xres - 1 - xs);
98 break;
99 }
100
101
102 write_reg(par, 0x22);
103}
104
105static int set_var(struct fbtft_par *par)
106{
107 if (par->fbtftops.init_display != init_display) {
108
109 fbtft_par_dbg(DEBUG_INIT_DISPLAY, par,
110 "%s: skipping since custom init_display() is used\n",
111 __func__);
112 return 0;
113 }
114
115 switch (par->info->var.rotate) {
116 case 0:
117 write_reg(par, 0x11, reg11 | 0x30);
118 break;
119 case 270:
120 write_reg(par, 0x11, reg11 | 0x28);
121 break;
122 case 180:
123 write_reg(par, 0x11, reg11 | 0x00);
124 break;
125 case 90:
126 write_reg(par, 0x11, reg11 | 0x18);
127 break;
128 }
129
130 return 0;
131}
132
133
134
135
136
137
138#define CURVE(num, idx) curves[num * par->gamma.num_values + idx]
139static int set_gamma(struct fbtft_par *par, u32 *curves)
140{
141 unsigned long mask[] = {
142 0x1f, 0x1f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
143 0x1f, 0x1f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
144 };
145 int i, j;
146
147
148 for (i = 0; i < 2; i++)
149 for (j = 0; j < 10; j++)
150 CURVE(i, j) &= mask[i * par->gamma.num_values + j];
151
152 write_reg(par, 0x0030, CURVE(0, 5) << 8 | CURVE(0, 4));
153 write_reg(par, 0x0031, CURVE(0, 7) << 8 | CURVE(0, 6));
154 write_reg(par, 0x0032, CURVE(0, 9) << 8 | CURVE(0, 8));
155 write_reg(par, 0x0033, CURVE(0, 3) << 8 | CURVE(0, 2));
156 write_reg(par, 0x0034, CURVE(1, 5) << 8 | CURVE(1, 4));
157 write_reg(par, 0x0035, CURVE(1, 7) << 8 | CURVE(1, 6));
158 write_reg(par, 0x0036, CURVE(1, 9) << 8 | CURVE(1, 8));
159 write_reg(par, 0x0037, CURVE(1, 3) << 8 | CURVE(1, 2));
160 write_reg(par, 0x003A, CURVE(0, 1) << 8 | CURVE(0, 0));
161 write_reg(par, 0x003B, CURVE(1, 1) << 8 | CURVE(1, 0));
162
163 return 0;
164}
165#undef CURVE
166
167static struct fbtft_display display = {
168 .regwidth = 16,
169 .width = WIDTH,
170 .height = HEIGHT,
171 .gamma_num = 2,
172 .gamma_len = 10,
173 .gamma = DEFAULT_GAMMA,
174 .fbtftops = {
175 .init_display = init_display,
176 .set_addr_win = set_addr_win,
177 .set_var = set_var,
178 .set_gamma = set_gamma,
179 },
180};
181
182FBTFT_REGISTER_DRIVER(DRVNAME, "solomon,ssd1289", &display);
183
184MODULE_ALIAS("spi:" DRVNAME);
185MODULE_ALIAS("platform:" DRVNAME);
186MODULE_ALIAS("spi:ssd1289");
187MODULE_ALIAS("platform:ssd1289");
188
189MODULE_DESCRIPTION("FB driver for the SSD1289 LCD Controller");
190MODULE_AUTHOR("Noralf Tronnes");
191MODULE_LICENSE("GPL");
192