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.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, see <http://www.gnu.org/licenses/>.
24 #include <linux/module.h>
25 #include <linux/kernel.h>
26 #include <linux/init.h>
27 #include <linux/delay.h>
30 #include "fb_hx8357d.h"
32 #define DRVNAME "fb_hx8357d"
37 static int init_display(struct fbtft_par *par)
39 fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
41 par->fbtftops.reset(par);
43 /* Reset things like Gamma */
44 write_reg(par, HX8357B_SWRESET);
45 usleep_range(5000, 7000);
48 write_reg(par, HX8357D_SETC, 0xFF, 0x83, 0x57);
51 /* setRGB which also enables SDO */
52 write_reg(par, HX8357_SETRGB, 0x00, 0x00, 0x06, 0x06);
55 write_reg(par, HX8357D_SETCOM, 0x25);
57 /* Normal mode 70Hz, Idle mode 55 Hz */
58 write_reg(par, HX8357_SETOSC, 0x68);
60 /* Set Panel - BGR, Gate direction swapped */
61 write_reg(par, HX8357_SETPANEL, 0x05);
63 write_reg(par, HX8357_SETPWR1,
64 0x00, /* Not deep standby */
71 write_reg(par, HX8357D_SETSTBA,
72 0x50, /* OPON normal */
79 write_reg(par, HX8357D_SETCYC,
88 write_reg(par, HX8357D_SETGAMMA,
125 write_reg(par, HX8357_COLMOD, 0x55);
127 write_reg(par, HX8357_MADCTL, 0xC0);
130 write_reg(par, HX8357_TEON, 0x00);
133 write_reg(par, HX8357_TEARLINE, 0x00, 0x02);
136 write_reg(par, HX8357_SLPOUT);
140 write_reg(par, HX8357_DISPON);
141 usleep_range(5000, 7000);
146 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
148 fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
149 "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
151 /* Column addr set */
152 write_reg(par, HX8357_CASET,
153 xs >> 8, xs & 0xff, /* XSTART */
154 xe >> 8, xe & 0xff); /* XEND */
157 write_reg(par, HX8357_PASET,
158 ys >> 8, ys & 0xff, /* YSTART */
159 ye >> 8, ye & 0xff); /* YEND */
162 write_reg(par, HX8357_RAMWR);
165 #define HX8357D_MADCTL_MY 0x80
166 #define HX8357D_MADCTL_MX 0x40
167 #define HX8357D_MADCTL_MV 0x20
168 #define HX8357D_MADCTL_ML 0x10
169 #define HX8357D_MADCTL_RGB 0x00
170 #define HX8357D_MADCTL_BGR 0x08
171 #define HX8357D_MADCTL_MH 0x04
172 static int set_var(struct fbtft_par *par)
176 fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
178 switch (par->info->var.rotate) {
180 val = HX8357D_MADCTL_MV | HX8357D_MADCTL_MX;
186 val = HX8357D_MADCTL_MV | HX8357D_MADCTL_MY;
189 val = HX8357D_MADCTL_MX | HX8357D_MADCTL_MY;
193 val |= (par->bgr ? HX8357D_MADCTL_RGB : HX8357D_MADCTL_BGR);
195 /* Memory Access Control */
196 write_reg(par, HX8357_MADCTL, val);
201 static struct fbtft_display display = {
208 .init_display = init_display,
209 .set_addr_win = set_addr_win,
213 FBTFT_REGISTER_DRIVER(DRVNAME, "himax,hx8357d", &display);
215 MODULE_ALIAS("spi:" DRVNAME);
216 MODULE_ALIAS("platform:" DRVNAME);
217 MODULE_ALIAS("spi:hx8357d");
218 MODULE_ALIAS("platform:hx8357d");
220 MODULE_DESCRIPTION("FB driver for the HX8357D LCD Controller");
221 MODULE_AUTHOR("Sean Cross <xobs@kosagi.com>");
222 MODULE_LICENSE("GPL");