1
2
3
4
5
6
7
8
9
10
11
12#include <linux/module.h>
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <linux/delay.h>
16
17#include "fbtft.h"
18
19#define DRVNAME "fb_upd161704"
20#define WIDTH 240
21#define HEIGHT 320
22#define BPP 16
23
24static int init_display(struct fbtft_par *par)
25{
26 par->fbtftops.reset(par);
27
28
29
30
31 write_reg(par, 0x0003, 0x0001);
32
33
34 write_reg(par, 0x003A, 0x0001);
35 udelay(100);
36
37
38 write_reg(par, 0x0024, 0x007B);
39 udelay(10);
40 write_reg(par, 0x0025, 0x003B);
41 write_reg(par, 0x0026, 0x0034);
42 udelay(10);
43 write_reg(par, 0x0027, 0x0004);
44 write_reg(par, 0x0052, 0x0025);
45 udelay(10);
46 write_reg(par, 0x0053, 0x0033);
47 write_reg(par, 0x0061, 0x001C);
48 udelay(10);
49 write_reg(par, 0x0062, 0x002C);
50 write_reg(par, 0x0063, 0x0022);
51 udelay(10);
52 write_reg(par, 0x0064, 0x0027);
53 udelay(10);
54 write_reg(par, 0x0065, 0x0014);
55 udelay(10);
56 write_reg(par, 0x0066, 0x0010);
57
58
59 write_reg(par, 0x002E, 0x002D);
60
61
62 write_reg(par, 0x0019, 0x0000);
63 udelay(200);
64 write_reg(par, 0x001A, 0x1000);
65 write_reg(par, 0x001B, 0x0023);
66 write_reg(par, 0x001C, 0x0C01);
67 write_reg(par, 0x001D, 0x0000);
68 write_reg(par, 0x001E, 0x0009);
69 write_reg(par, 0x001F, 0x0035);
70 write_reg(par, 0x0020, 0x0015);
71 write_reg(par, 0x0018, 0x1E7B);
72
73
74 write_reg(par, 0x0008, 0x0000);
75 write_reg(par, 0x0009, 0x00EF);
76 write_reg(par, 0x000a, 0x0000);
77 write_reg(par, 0x000b, 0x013F);
78
79
80 write_reg(par, 0x0029, 0x0000);
81 write_reg(par, 0x002A, 0x0000);
82 write_reg(par, 0x002B, 0x00EF);
83 write_reg(par, 0x002C, 0x013F);
84
85
86 write_reg(par, 0x0032, 0x0002);
87
88
89 write_reg(par, 0x0033, 0x0000);
90
91
92 write_reg(par, 0x0037, 0x0000);
93
94
95 write_reg(par, 0x003B, 0x0001);
96
97
98
99 write_reg(par, 0x0004, 0x0000);
100
101
102 write_reg(par, 0x0005, 0x0000);
103
104
105 write_reg(par, 0x0001, 0x0000);
106
107
108 write_reg(par, 0x0000, 0x0000);
109
110 return 0;
111}
112
113static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
114{
115 switch (par->info->var.rotate) {
116
117
118 case 0:
119 write_reg(par, 0x0006, xs);
120 write_reg(par, 0x0007, ys);
121 break;
122 case 180:
123 write_reg(par, 0x0006, WIDTH - 1 - xs);
124 write_reg(par, 0x0007, HEIGHT - 1 - ys);
125 break;
126 case 270:
127 write_reg(par, 0x0006, WIDTH - 1 - ys);
128 write_reg(par, 0x0007, xs);
129 break;
130 case 90:
131 write_reg(par, 0x0006, ys);
132 write_reg(par, 0x0007, HEIGHT - 1 - xs);
133 break;
134 }
135
136 write_reg(par, 0x0e);
137}
138
139static int set_var(struct fbtft_par *par)
140{
141 switch (par->info->var.rotate) {
142
143 case 0:
144 write_reg(par, 0x01, 0x0000);
145 write_reg(par, 0x05, 0x0000);
146 break;
147 case 180:
148 write_reg(par, 0x01, 0x00C0);
149 write_reg(par, 0x05, 0x0000);
150 break;
151 case 270:
152 write_reg(par, 0x01, 0x0080);
153 write_reg(par, 0x05, 0x0001);
154 break;
155 case 90:
156 write_reg(par, 0x01, 0x0040);
157 write_reg(par, 0x05, 0x0001);
158 break;
159 }
160
161 return 0;
162}
163
164static struct fbtft_display display = {
165 .regwidth = 16,
166 .width = WIDTH,
167 .height = HEIGHT,
168 .fbtftops = {
169 .init_display = init_display,
170 .set_addr_win = set_addr_win,
171 .set_var = set_var,
172 },
173};
174
175FBTFT_REGISTER_DRIVER(DRVNAME, "nec,upd161704", &display);
176
177MODULE_ALIAS("spi:" DRVNAME);
178MODULE_ALIAS("platform:" DRVNAME);
179MODULE_ALIAS("spi:upd161704");
180MODULE_ALIAS("platform:upd161704");
181
182MODULE_DESCRIPTION("FB driver for the uPD161704 LCD Controller");
183MODULE_AUTHOR("Seong-Woo Kim");
184MODULE_LICENSE("GPL");
185