1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include <linux/module.h>
22#include <linux/kernel.h>
23#include <linux/init.h>
24#include <linux/delay.h>
25#include <video/mipi_display.h>
26
27#include "fbtft.h"
28#include "fb_hx8357d.h"
29
30#define DRVNAME "fb_hx8357d"
31#define WIDTH 320
32#define HEIGHT 480
33
34static int init_display(struct fbtft_par *par)
35{
36 par->fbtftops.reset(par);
37
38
39 write_reg(par, MIPI_DCS_SOFT_RESET);
40 usleep_range(5000, 7000);
41
42
43 write_reg(par, HX8357D_SETC, 0xFF, 0x83, 0x57);
44 msleep(150);
45
46
47 write_reg(par, HX8357_SETRGB, 0x00, 0x00, 0x06, 0x06);
48
49
50 write_reg(par, HX8357D_SETCOM, 0x25);
51
52
53 write_reg(par, HX8357_SETOSC, 0x68);
54
55
56 write_reg(par, HX8357_SETPANEL, 0x05);
57
58 write_reg(par, HX8357_SETPWR1,
59 0x00,
60 0x15,
61 0x1C,
62 0x1C,
63 0x83,
64 0xAA);
65
66 write_reg(par, HX8357D_SETSTBA,
67 0x50,
68 0x50,
69 0x01,
70 0x3C,
71 0x1E,
72 0x08);
73
74 write_reg(par, HX8357D_SETCYC,
75 0x02,
76 0x40,
77 0x00,
78 0x2A,
79 0x2A,
80 0x0D,
81 0x78);
82
83 write_reg(par, HX8357D_SETGAMMA,
84 0x02,
85 0x0A,
86 0x11,
87 0x1d,
88 0x23,
89 0x35,
90 0x41,
91 0x4b,
92 0x4b,
93 0x42,
94 0x3A,
95 0x27,
96 0x1B,
97 0x08,
98 0x09,
99 0x03,
100 0x02,
101 0x0A,
102 0x11,
103 0x1d,
104 0x23,
105 0x35,
106 0x41,
107 0x4b,
108 0x4b,
109 0x42,
110 0x3A,
111 0x27,
112 0x1B,
113 0x08,
114 0x09,
115 0x03,
116 0x00,
117 0x01);
118
119
120 write_reg(par, MIPI_DCS_SET_PIXEL_FORMAT, 0x55);
121
122 write_reg(par, MIPI_DCS_SET_ADDRESS_MODE, 0xC0);
123
124
125 write_reg(par, MIPI_DCS_SET_TEAR_ON, 0x00);
126
127
128 write_reg(par, MIPI_DCS_SET_TEAR_SCANLINE, 0x00, 0x02);
129
130
131 write_reg(par, MIPI_DCS_EXIT_SLEEP_MODE);
132 msleep(150);
133
134
135 write_reg(par, MIPI_DCS_SET_DISPLAY_ON);
136 usleep_range(5000, 7000);
137
138 return 0;
139}
140
141static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
142{
143 write_reg(par, MIPI_DCS_SET_COLUMN_ADDRESS,
144 xs >> 8, xs & 0xff,
145 xe >> 8, xe & 0xff);
146
147 write_reg(par, MIPI_DCS_SET_PAGE_ADDRESS,
148 ys >> 8, ys & 0xff,
149 ye >> 8, ye & 0xff);
150
151 write_reg(par, MIPI_DCS_WRITE_MEMORY_START);
152}
153
154#define HX8357D_MADCTL_MY 0x80
155#define HX8357D_MADCTL_MX 0x40
156#define HX8357D_MADCTL_MV 0x20
157#define HX8357D_MADCTL_ML 0x10
158#define HX8357D_MADCTL_RGB 0x00
159#define HX8357D_MADCTL_BGR 0x08
160#define HX8357D_MADCTL_MH 0x04
161static int set_var(struct fbtft_par *par)
162{
163 u8 val;
164
165 switch (par->info->var.rotate) {
166 case 270:
167 val = HX8357D_MADCTL_MV | HX8357D_MADCTL_MX;
168 break;
169 case 180:
170 val = 0;
171 break;
172 case 90:
173 val = HX8357D_MADCTL_MV | HX8357D_MADCTL_MY;
174 break;
175 default:
176 val = HX8357D_MADCTL_MX | HX8357D_MADCTL_MY;
177 break;
178 }
179
180 val |= (par->bgr ? HX8357D_MADCTL_RGB : HX8357D_MADCTL_BGR);
181
182
183 write_reg(par, MIPI_DCS_SET_ADDRESS_MODE, val);
184
185 return 0;
186}
187
188static struct fbtft_display display = {
189 .regwidth = 8,
190 .width = WIDTH,
191 .height = HEIGHT,
192 .gamma_num = 2,
193 .gamma_len = 14,
194 .fbtftops = {
195 .init_display = init_display,
196 .set_addr_win = set_addr_win,
197 .set_var = set_var,
198 },
199};
200
201FBTFT_REGISTER_DRIVER(DRVNAME, "himax,hx8357d", &display);
202
203MODULE_ALIAS("spi:" DRVNAME);
204MODULE_ALIAS("platform:" DRVNAME);
205MODULE_ALIAS("spi:hx8357d");
206MODULE_ALIAS("platform:hx8357d");
207
208MODULE_DESCRIPTION("FB driver for the HX8357D LCD Controller");
209MODULE_AUTHOR("Sean Cross <xobs@kosagi.com>");
210MODULE_LICENSE("GPL");
211