2 * FB driver for the HX8357D LCD Controller
3 * Copyright (C) 2015 Adafruit Industries
5 * Based on the HX8347D FB driver
6 * Copyright (C) 2013 Christian Vogelgsang
8 * Based on driver code found here: https://github.com/watterott/r61505u-Adapter
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
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>
28 #include "fb_hx8357d.h"
30 #define DRVNAME "fb_hx8357d"
34 static int init_display(struct fbtft_par
*par
)
36 par
->fbtftops
.reset(par
);
38 /* Reset things like Gamma */
39 write_reg(par
, MIPI_DCS_SOFT_RESET
);
40 usleep_range(5000, 7000);
43 write_reg(par
, HX8357D_SETC
, 0xFF, 0x83, 0x57);
46 /* setRGB which also enables SDO */
47 write_reg(par
, HX8357_SETRGB
, 0x00, 0x00, 0x06, 0x06);
50 write_reg(par
, HX8357D_SETCOM
, 0x25);
52 /* Normal mode 70Hz, Idle mode 55 Hz */
53 write_reg(par
, HX8357_SETOSC
, 0x68);
55 /* Set Panel - BGR, Gate direction swapped */
56 write_reg(par
, HX8357_SETPANEL
, 0x05);
58 write_reg(par
, HX8357_SETPWR1
,
59 0x00, /* Not deep standby */
66 write_reg(par
, HX8357D_SETSTBA
,
67 0x50, /* OPON normal */
74 write_reg(par
, HX8357D_SETCYC
,
83 write_reg(par
, HX8357D_SETGAMMA
,
120 write_reg(par
, MIPI_DCS_SET_PIXEL_FORMAT
, 0x55);
122 write_reg(par
, MIPI_DCS_SET_ADDRESS_MODE
, 0xC0);
125 write_reg(par
, MIPI_DCS_SET_TEAR_ON
, 0x00);
128 write_reg(par
, MIPI_DCS_SET_TEAR_SCANLINE
, 0x00, 0x02);
131 write_reg(par
, MIPI_DCS_EXIT_SLEEP_MODE
);
135 write_reg(par
, MIPI_DCS_SET_DISPLAY_ON
);
136 usleep_range(5000, 7000);
141 static void set_addr_win(struct fbtft_par
*par
, int xs
, int ys
, int xe
, int ye
)
143 write_reg(par
, MIPI_DCS_SET_COLUMN_ADDRESS
,
144 xs
>> 8, xs
& 0xff, /* XSTART */
145 xe
>> 8, xe
& 0xff); /* XEND */
147 write_reg(par
, MIPI_DCS_SET_PAGE_ADDRESS
,
148 ys
>> 8, ys
& 0xff, /* YSTART */
149 ye
>> 8, ye
& 0xff); /* YEND */
151 write_reg(par
, MIPI_DCS_WRITE_MEMORY_START
);
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
161 static int set_var(struct fbtft_par
*par
)
165 switch (par
->info
->var
.rotate
) {
167 val
= HX8357D_MADCTL_MV
| HX8357D_MADCTL_MX
;
173 val
= HX8357D_MADCTL_MV
| HX8357D_MADCTL_MY
;
176 val
= HX8357D_MADCTL_MX
| HX8357D_MADCTL_MY
;
180 val
|= (par
->bgr
? HX8357D_MADCTL_RGB
: HX8357D_MADCTL_BGR
);
182 /* Memory Access Control */
183 write_reg(par
, MIPI_DCS_SET_ADDRESS_MODE
, val
);
188 static struct fbtft_display display
= {
195 .init_display
= init_display
,
196 .set_addr_win
= set_addr_win
,
201 FBTFT_REGISTER_DRIVER(DRVNAME
, "himax,hx8357d", &display
);
203 MODULE_ALIAS("spi:" DRVNAME
);
204 MODULE_ALIAS("platform:" DRVNAME
);
205 MODULE_ALIAS("spi:hx8357d");
206 MODULE_ALIAS("platform:hx8357d");
208 MODULE_DESCRIPTION("FB driver for the HX8357D LCD Controller");
209 MODULE_AUTHOR("Sean Cross <xobs@kosagi.com>");
210 MODULE_LICENSE("GPL");