1/* 2 * FB driver for the ILI9486 LCD Controller 3 * 4 * Copyright (C) 2014 Noralf Tronnes 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 */ 16 17#include <linux/module.h> 18#include <linux/kernel.h> 19#include <linux/init.h> 20 21#include "fbtft.h" 22 23#define DRVNAME "fb_ili9486" 24#define WIDTH 320 25#define HEIGHT 480 26 27/* this init sequence matches PiScreen */ 28static int default_init_sequence[] = { 29 /* Interface Mode Control */ 30 -1, 0xb0, 0x0, 31 /* Sleep OUT */ 32 -1, 0x11, 33 -2, 250, 34 /* Interface Pixel Format */ 35 -1, 0x3A, 0x55, 36 /* Power Control 3 */ 37 -1, 0xC2, 0x44, 38 /* VCOM Control 1 */ 39 -1, 0xC5, 0x00, 0x00, 0x00, 0x00, 40 /* PGAMCTRL(Positive Gamma Control) */ 41 -1, 0xE0, 0x0F, 0x1F, 0x1C, 0x0C, 0x0F, 0x08, 0x48, 0x98, 42 0x37, 0x0A, 0x13, 0x04, 0x11, 0x0D, 0x00, 43 /* NGAMCTRL(Negative Gamma Control) */ 44 -1, 0xE1, 0x0F, 0x32, 0x2E, 0x0B, 0x0D, 0x05, 0x47, 0x75, 45 0x37, 0x06, 0x10, 0x03, 0x24, 0x20, 0x00, 46 /* Digital Gamma Control 1 */ 47 -1, 0xE2, 0x0F, 0x32, 0x2E, 0x0B, 0x0D, 0x05, 0x47, 0x75, 48 0x37, 0x06, 0x10, 0x03, 0x24, 0x20, 0x00, 49 /* Sleep OUT */ 50 -1, 0x11, 51 /* Display ON */ 52 -1, 0x29, 53 /* end marker */ 54 -3 55}; 56 57static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) 58{ 59 /* Column address */ 60 write_reg(par, 0x2A, xs >> 8, xs & 0xFF, xe >> 8, xe & 0xFF); 61 62 /* Row address */ 63 write_reg(par, 0x2B, ys >> 8, ys & 0xFF, ye >> 8, ye & 0xFF); 64 65 /* Memory write */ 66 write_reg(par, 0x2C); 67} 68 69static int set_var(struct fbtft_par *par) 70{ 71 switch (par->info->var.rotate) { 72 case 0: 73 write_reg(par, 0x36, 0x80 | (par->bgr << 3)); 74 break; 75 case 90: 76 write_reg(par, 0x36, 0x20 | (par->bgr << 3)); 77 break; 78 case 180: 79 write_reg(par, 0x36, 0x40 | (par->bgr << 3)); 80 break; 81 case 270: 82 write_reg(par, 0x36, 0xE0 | (par->bgr << 3)); 83 break; 84 default: 85 break; 86 } 87 88 return 0; 89} 90 91static struct fbtft_display display = { 92 .regwidth = 8, 93 .width = WIDTH, 94 .height = HEIGHT, 95 .init_sequence = default_init_sequence, 96 .fbtftops = { 97 .set_addr_win = set_addr_win, 98 .set_var = set_var, 99 }, 100}; 101 102FBTFT_REGISTER_DRIVER(DRVNAME, "ilitek,ili9486", &display); 103 104MODULE_ALIAS("spi:" DRVNAME); 105MODULE_ALIAS("platform:" DRVNAME); 106MODULE_ALIAS("spi:ili9486"); 107MODULE_ALIAS("platform:ili9486"); 108 109MODULE_DESCRIPTION("FB driver for the ILI9486 LCD Controller"); 110MODULE_AUTHOR("Noralf Tronnes"); 111MODULE_LICENSE("GPL"); 112