Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging: fbtft: Add support for Himax HX8357D controller

The Himax HX8357D is used e.g. by the Adafruit PITFT Plus 3.5".
Adafruit added HX8357D support to an own fork of fbtft and support
Raspbian only (https://github.com/adafruit/adafruit-rpi-fbtft/).
They don't intend to push it upstream but gave me the ok to do so.
Original author: Sean Cross <xobs@kosagi.com>

I just applied small changes to the driver to align it with the other
fbtft drivers.
- add "compatible" argument to FBTFT_REGISTER_DRIVER call
- add missing MODULE_ALIAS declarations

Tested successfully with this display on an RPI2 under Arch Linux ARM
(kernel 3.18.13).

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Heiner Kallweit and committed by
Greg Kroah-Hartman
9cd491e8 5df5910b

+331
+6
drivers/staging/fbtft/Kconfig
··· 38 38 help 39 39 Generic Framebuffer support for HX8353D 40 40 41 + config FB_TFT_HX8357D 42 + tristate "FB driver for the HX8357D LCD Controller" 43 + depends on FB_TFT 44 + help 45 + Generic Framebuffer support for HX8357D 46 + 41 47 config FB_TFT_ILI9163 42 48 tristate "FB driver for the ILI9163 LCD Controller" 43 49 depends on FB_TFT
+1
drivers/staging/fbtft/Makefile
··· 8 8 obj-$(CONFIG_FB_TFT_HX8340BN) += fb_hx8340bn.o 9 9 obj-$(CONFIG_FB_TFT_HX8347D) += fb_hx8347d.o 10 10 obj-$(CONFIG_FB_TFT_HX8353D) += fb_hx8353d.o 11 + obj-$(CONFIG_FB_TFT_HX8357D) += fb_hx8357d.o 11 12 obj-$(CONFIG_FB_TFT_ILI9163) += fb_ili9163.o 12 13 obj-$(CONFIG_FB_TFT_ILI9320) += fb_ili9320.o 13 14 obj-$(CONFIG_FB_TFT_ILI9325) += fb_ili9325.o
+222
drivers/staging/fbtft/fb_hx8357d.c
··· 1 + /* 2 + * FB driver for the HX8357D LCD Controller 3 + * Copyright (C) 2015 Adafruit Industries 4 + * 5 + * Based on the HX8347D FB driver 6 + * Copyright (C) 2013 Christian Vogelgsang 7 + * 8 + * Based on driver code found here: https://github.com/watterott/r61505u-Adapter 9 + * 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. 14 + * 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. 19 + * 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/>. 22 + */ 23 + 24 + #include <linux/module.h> 25 + #include <linux/kernel.h> 26 + #include <linux/init.h> 27 + #include <linux/delay.h> 28 + 29 + #include "fbtft.h" 30 + #include "fb_hx8357d.h" 31 + 32 + #define DRVNAME "fb_hx8357d" 33 + #define WIDTH 320 34 + #define HEIGHT 480 35 + 36 + 37 + static int init_display(struct fbtft_par *par) 38 + { 39 + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); 40 + 41 + par->fbtftops.reset(par); 42 + 43 + /* Reset things like Gamma */ 44 + write_reg(par, HX8357B_SWRESET); 45 + usleep_range(5000, 7000); 46 + 47 + /* setextc */ 48 + write_reg(par, HX8357D_SETC, 0xFF, 0x83, 0x57); 49 + msleep(150); 50 + 51 + /* setRGB which also enables SDO */ 52 + write_reg(par, HX8357_SETRGB, 0x00, 0x00, 0x06, 0x06); 53 + 54 + /* -1.52V */ 55 + write_reg(par, HX8357D_SETCOM, 0x25); 56 + 57 + /* Normal mode 70Hz, Idle mode 55 Hz */ 58 + write_reg(par, HX8357_SETOSC, 0x68); 59 + 60 + /* Set Panel - BGR, Gate direction swapped */ 61 + write_reg(par, HX8357_SETPANEL, 0x05); 62 + 63 + write_reg(par, HX8357_SETPWR1, 64 + 0x00, /* Not deep standby */ 65 + 0x15, /* BT */ 66 + 0x1C, /* VSPR */ 67 + 0x1C, /* VSNR */ 68 + 0x83, /* AP */ 69 + 0xAA); /* FS */ 70 + 71 + write_reg(par, HX8357D_SETSTBA, 72 + 0x50, /* OPON normal */ 73 + 0x50, /* OPON idle */ 74 + 0x01, /* STBA */ 75 + 0x3C, /* STBA */ 76 + 0x1E, /* STBA */ 77 + 0x08); /* GEN */ 78 + 79 + write_reg(par, HX8357D_SETCYC, 80 + 0x02, /* NW 0x02 */ 81 + 0x40, /* RTN */ 82 + 0x00, /* DIV */ 83 + 0x2A, /* DUM */ 84 + 0x2A, /* DUM */ 85 + 0x0D, /* GDON */ 86 + 0x78); /* GDOFF */ 87 + 88 + write_reg(par, HX8357D_SETGAMMA, 89 + 0x02, 90 + 0x0A, 91 + 0x11, 92 + 0x1d, 93 + 0x23, 94 + 0x35, 95 + 0x41, 96 + 0x4b, 97 + 0x4b, 98 + 0x42, 99 + 0x3A, 100 + 0x27, 101 + 0x1B, 102 + 0x08, 103 + 0x09, 104 + 0x03, 105 + 0x02, 106 + 0x0A, 107 + 0x11, 108 + 0x1d, 109 + 0x23, 110 + 0x35, 111 + 0x41, 112 + 0x4b, 113 + 0x4b, 114 + 0x42, 115 + 0x3A, 116 + 0x27, 117 + 0x1B, 118 + 0x08, 119 + 0x09, 120 + 0x03, 121 + 0x00, 122 + 0x01); 123 + 124 + /* 16 bit */ 125 + write_reg(par, HX8357_COLMOD, 0x55); 126 + 127 + write_reg(par, HX8357_MADCTL, 0xC0); 128 + 129 + /* TE off */ 130 + write_reg(par, HX8357_TEON, 0x00); 131 + 132 + /* tear line */ 133 + write_reg(par, HX8357_TEARLINE, 0x00, 0x02); 134 + 135 + /* Exit Sleep */ 136 + write_reg(par, HX8357_SLPOUT); 137 + msleep(150); 138 + 139 + /* display on */ 140 + write_reg(par, HX8357_DISPON); 141 + usleep_range(5000, 7000); 142 + 143 + return 0; 144 + } 145 + 146 + static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) 147 + { 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); 150 + 151 + /* Column addr set */ 152 + write_reg(par, HX8357_CASET, 153 + xs >> 8, xs & 0xff, /* XSTART */ 154 + xe >> 8, xe & 0xff); /* XEND */ 155 + 156 + /* Row addr set */ 157 + write_reg(par, HX8357_PASET, 158 + ys >> 8, ys & 0xff, /* YSTART */ 159 + ye >> 8, ye & 0xff); /* YEND */ 160 + 161 + /* write to RAM */ 162 + write_reg(par, HX8357_RAMWR); 163 + } 164 + 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) 173 + { 174 + u8 val; 175 + 176 + fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__); 177 + 178 + switch (par->info->var.rotate) { 179 + case 270: 180 + val = HX8357D_MADCTL_MV | HX8357D_MADCTL_MX; 181 + break; 182 + case 180: 183 + val = 0; 184 + break; 185 + case 90: 186 + val = HX8357D_MADCTL_MV | HX8357D_MADCTL_MY; 187 + break; 188 + default: 189 + val = HX8357D_MADCTL_MX | HX8357D_MADCTL_MY; 190 + break; 191 + } 192 + 193 + val |= (par->bgr ? HX8357D_MADCTL_RGB : HX8357D_MADCTL_BGR); 194 + 195 + /* Memory Access Control */ 196 + write_reg(par, HX8357_MADCTL, val); 197 + 198 + return 0; 199 + } 200 + 201 + static struct fbtft_display display = { 202 + .regwidth = 8, 203 + .width = WIDTH, 204 + .height = HEIGHT, 205 + .gamma_num = 2, 206 + .gamma_len = 14, 207 + .fbtftops = { 208 + .init_display = init_display, 209 + .set_addr_win = set_addr_win, 210 + .set_var = set_var, 211 + }, 212 + }; 213 + FBTFT_REGISTER_DRIVER(DRVNAME, "himax,hx8357d", &display); 214 + 215 + MODULE_ALIAS("spi:" DRVNAME); 216 + MODULE_ALIAS("platform:" DRVNAME); 217 + MODULE_ALIAS("spi:hx8357d"); 218 + MODULE_ALIAS("platform:hx8357d"); 219 + 220 + MODULE_DESCRIPTION("FB driver for the HX8357D LCD Controller"); 221 + MODULE_AUTHOR("Sean Cross <xobs@kosagi.com>"); 222 + MODULE_LICENSE("GPL");
+102
drivers/staging/fbtft/fb_hx8357d.h
··· 1 + /*************************************************** 2 + This is our library for the Adafruit ILI9341 Breakout and Shield 3 + ----> http://www.adafruit.com/products/1651 4 + 5 + Check out the links above for our tutorials and wiring diagrams 6 + These displays use SPI to communicate, 4 or 5 pins are required to 7 + interface (RST is optional) 8 + Adafruit invests time and resources providing this open source code, 9 + please support Adafruit and open-source hardware by purchasing 10 + products from Adafruit! 11 + 12 + Written by Limor Fried/Ladyada for Adafruit Industries. 13 + MIT license, all text above must be included in any redistribution 14 + ****************************************************/ 15 + 16 + #ifndef __HX8357_H__ 17 + #define __HX8357_H__ 18 + 19 + #define HX8357D 0xD 20 + #define HX8357B 0xB 21 + 22 + #define HX8357_TFTWIDTH 320 23 + #define HX8357_TFTHEIGHT 480 24 + 25 + #define HX8357B_NOP 0x00 26 + #define HX8357B_SWRESET 0x01 27 + #define HX8357B_RDDID 0x04 28 + #define HX8357B_RDDST 0x09 29 + 30 + #define HX8357B_RDPOWMODE 0x0A 31 + #define HX8357B_RDMADCTL 0x0B 32 + #define HX8357B_RDCOLMOD 0x0C 33 + #define HX8357B_RDDIM 0x0D 34 + #define HX8357B_RDDSDR 0x0F 35 + 36 + #define HX8357_SLPIN 0x10 37 + #define HX8357_SLPOUT 0x11 38 + #define HX8357B_PTLON 0x12 39 + #define HX8357B_NORON 0x13 40 + 41 + #define HX8357_INVOFF 0x20 42 + #define HX8357_INVON 0x21 43 + #define HX8357_DISPOFF 0x28 44 + #define HX8357_DISPON 0x29 45 + 46 + #define HX8357_CASET 0x2A 47 + #define HX8357_PASET 0x2B 48 + #define HX8357_RAMWR 0x2C 49 + #define HX8357_RAMRD 0x2E 50 + 51 + #define HX8357B_PTLAR 0x30 52 + #define HX8357_TEON 0x35 53 + #define HX8357_TEARLINE 0x44 54 + #define HX8357_MADCTL 0x36 55 + #define HX8357_COLMOD 0x3A 56 + 57 + #define HX8357_SETOSC 0xB0 58 + #define HX8357_SETPWR1 0xB1 59 + #define HX8357B_SETDISPLAY 0xB2 60 + #define HX8357_SETRGB 0xB3 61 + #define HX8357D_SETCOM 0xB6 62 + 63 + #define HX8357B_SETDISPMODE 0xB4 64 + #define HX8357D_SETCYC 0xB4 65 + #define HX8357B_SETOTP 0xB7 66 + #define HX8357D_SETC 0xB9 67 + 68 + #define HX8357B_SET_PANEL_DRIVING 0xC0 69 + #define HX8357D_SETSTBA 0xC0 70 + #define HX8357B_SETDGC 0xC1 71 + #define HX8357B_SETID 0xC3 72 + #define HX8357B_SETDDB 0xC4 73 + #define HX8357B_SETDISPLAYFRAME 0xC5 74 + #define HX8357B_GAMMASET 0xC8 75 + #define HX8357B_SETCABC 0xC9 76 + #define HX8357_SETPANEL 0xCC 77 + 78 + #define HX8357B_SETPOWER 0xD0 79 + #define HX8357B_SETVCOM 0xD1 80 + #define HX8357B_SETPWRNORMAL 0xD2 81 + 82 + #define HX8357B_RDID1 0xDA 83 + #define HX8357B_RDID2 0xDB 84 + #define HX8357B_RDID3 0xDC 85 + #define HX8357B_RDID4 0xDD 86 + 87 + #define HX8357D_SETGAMMA 0xE0 88 + 89 + #define HX8357B_SETGAMMA 0xC8 90 + #define HX8357B_SETPANELRELATED 0xE9 91 + 92 + /* Color definitions */ 93 + #define HX8357_BLACK 0x0000 94 + #define HX8357_BLUE 0x001F 95 + #define HX8357_RED 0xF800 96 + #define HX8357_GREEN 0x07E0 97 + #define HX8357_CYAN 0x07FF 98 + #define HX8357_MAGENTA 0xF81F 99 + #define HX8357_YELLOW 0xFFE0 100 + #define HX8357_WHITE 0xFFFF 101 + 102 + #endif /* __HX8357_H__ */