15dc5e4fbSThomas Petazzoni /* 25dc5e4fbSThomas Petazzoni * FB driver for the SSD1289 LCD Controller 35dc5e4fbSThomas Petazzoni * 45dc5e4fbSThomas Petazzoni * Copyright (C) 2013 Noralf Tronnes 55dc5e4fbSThomas Petazzoni * 65dc5e4fbSThomas Petazzoni * Init sequence taken from ITDB02_Graph16.cpp - (C)2010-2011 Henning Karlsen 75dc5e4fbSThomas Petazzoni * 85dc5e4fbSThomas Petazzoni * This program is free software; you can redistribute it and/or modify 95dc5e4fbSThomas Petazzoni * it under the terms of the GNU General Public License as published by 105dc5e4fbSThomas Petazzoni * the Free Software Foundation; either version 2 of the License, or 115dc5e4fbSThomas Petazzoni * (at your option) any later version. 125dc5e4fbSThomas Petazzoni * 135dc5e4fbSThomas Petazzoni * This program is distributed in the hope that it will be useful, 145dc5e4fbSThomas Petazzoni * but WITHOUT ANY WARRANTY; without even the implied warranty of 155dc5e4fbSThomas Petazzoni * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 165dc5e4fbSThomas Petazzoni * GNU General Public License for more details. 175dc5e4fbSThomas Petazzoni */ 185dc5e4fbSThomas Petazzoni 195dc5e4fbSThomas Petazzoni #include <linux/module.h> 205dc5e4fbSThomas Petazzoni #include <linux/kernel.h> 215dc5e4fbSThomas Petazzoni #include <linux/init.h> 225dc5e4fbSThomas Petazzoni #include <linux/gpio.h> 235dc5e4fbSThomas Petazzoni 245dc5e4fbSThomas Petazzoni #include "fbtft.h" 255dc5e4fbSThomas Petazzoni 265dc5e4fbSThomas Petazzoni #define DRVNAME "fb_ssd1289" 275dc5e4fbSThomas Petazzoni #define WIDTH 240 285dc5e4fbSThomas Petazzoni #define HEIGHT 320 295dc5e4fbSThomas Petazzoni #define DEFAULT_GAMMA "02 03 2 5 7 7 4 2 4 2\n" \ 305dc5e4fbSThomas Petazzoni "02 03 2 5 7 5 4 2 4 2" 315dc5e4fbSThomas Petazzoni 321c41494aSMing Yang static unsigned int reg11 = 0x6040; 335dc5e4fbSThomas Petazzoni module_param(reg11, uint, 0); 345dc5e4fbSThomas Petazzoni MODULE_PARM_DESC(reg11, "Register 11h value"); 355dc5e4fbSThomas Petazzoni 365dc5e4fbSThomas Petazzoni static int init_display(struct fbtft_par *par) 375dc5e4fbSThomas Petazzoni { 385dc5e4fbSThomas Petazzoni par->fbtftops.reset(par); 395dc5e4fbSThomas Petazzoni 405dc5e4fbSThomas Petazzoni if (par->gpio.cs != -1) 415dc5e4fbSThomas Petazzoni gpio_set_value(par->gpio.cs, 0); /* Activate chip */ 425dc5e4fbSThomas Petazzoni 435dc5e4fbSThomas Petazzoni write_reg(par, 0x00, 0x0001); 445dc5e4fbSThomas Petazzoni write_reg(par, 0x03, 0xA8A4); 455dc5e4fbSThomas Petazzoni write_reg(par, 0x0C, 0x0000); 465dc5e4fbSThomas Petazzoni write_reg(par, 0x0D, 0x080C); 475dc5e4fbSThomas Petazzoni write_reg(par, 0x0E, 0x2B00); 485dc5e4fbSThomas Petazzoni write_reg(par, 0x1E, 0x00B7); 495dc5e4fbSThomas Petazzoni write_reg(par, 0x01, 505dc5e4fbSThomas Petazzoni (1 << 13) | (par->bgr << 11) | (1 << 9) | (HEIGHT - 1)); 515dc5e4fbSThomas Petazzoni write_reg(par, 0x02, 0x0600); 525dc5e4fbSThomas Petazzoni write_reg(par, 0x10, 0x0000); 535dc5e4fbSThomas Petazzoni write_reg(par, 0x05, 0x0000); 545dc5e4fbSThomas Petazzoni write_reg(par, 0x06, 0x0000); 555dc5e4fbSThomas Petazzoni write_reg(par, 0x16, 0xEF1C); 565dc5e4fbSThomas Petazzoni write_reg(par, 0x17, 0x0003); 575dc5e4fbSThomas Petazzoni write_reg(par, 0x07, 0x0233); 585dc5e4fbSThomas Petazzoni write_reg(par, 0x0B, 0x0000); 595dc5e4fbSThomas Petazzoni write_reg(par, 0x0F, 0x0000); 605dc5e4fbSThomas Petazzoni write_reg(par, 0x41, 0x0000); 615dc5e4fbSThomas Petazzoni write_reg(par, 0x42, 0x0000); 625dc5e4fbSThomas Petazzoni write_reg(par, 0x48, 0x0000); 635dc5e4fbSThomas Petazzoni write_reg(par, 0x49, 0x013F); 645dc5e4fbSThomas Petazzoni write_reg(par, 0x4A, 0x0000); 655dc5e4fbSThomas Petazzoni write_reg(par, 0x4B, 0x0000); 665dc5e4fbSThomas Petazzoni write_reg(par, 0x44, 0xEF00); 675dc5e4fbSThomas Petazzoni write_reg(par, 0x45, 0x0000); 685dc5e4fbSThomas Petazzoni write_reg(par, 0x46, 0x013F); 695dc5e4fbSThomas Petazzoni write_reg(par, 0x23, 0x0000); 705dc5e4fbSThomas Petazzoni write_reg(par, 0x24, 0x0000); 715dc5e4fbSThomas Petazzoni write_reg(par, 0x25, 0x8000); 725dc5e4fbSThomas Petazzoni write_reg(par, 0x4f, 0x0000); 735dc5e4fbSThomas Petazzoni write_reg(par, 0x4e, 0x0000); 745dc5e4fbSThomas Petazzoni write_reg(par, 0x22); 755dc5e4fbSThomas Petazzoni return 0; 765dc5e4fbSThomas Petazzoni } 775dc5e4fbSThomas Petazzoni 785dc5e4fbSThomas Petazzoni static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) 795dc5e4fbSThomas Petazzoni { 805dc5e4fbSThomas Petazzoni switch (par->info->var.rotate) { 815dc5e4fbSThomas Petazzoni /* R4Eh - Set GDDRAM X address counter */ 825dc5e4fbSThomas Petazzoni /* R4Fh - Set GDDRAM Y address counter */ 835dc5e4fbSThomas Petazzoni case 0: 845dc5e4fbSThomas Petazzoni write_reg(par, 0x4e, xs); 855dc5e4fbSThomas Petazzoni write_reg(par, 0x4f, ys); 865dc5e4fbSThomas Petazzoni break; 875dc5e4fbSThomas Petazzoni case 180: 885dc5e4fbSThomas Petazzoni write_reg(par, 0x4e, par->info->var.xres - 1 - xs); 895dc5e4fbSThomas Petazzoni write_reg(par, 0x4f, par->info->var.yres - 1 - ys); 905dc5e4fbSThomas Petazzoni break; 915dc5e4fbSThomas Petazzoni case 270: 925dc5e4fbSThomas Petazzoni write_reg(par, 0x4e, par->info->var.yres - 1 - ys); 935dc5e4fbSThomas Petazzoni write_reg(par, 0x4f, xs); 945dc5e4fbSThomas Petazzoni break; 955dc5e4fbSThomas Petazzoni case 90: 965dc5e4fbSThomas Petazzoni write_reg(par, 0x4e, ys); 975dc5e4fbSThomas Petazzoni write_reg(par, 0x4f, par->info->var.xres - 1 - xs); 985dc5e4fbSThomas Petazzoni break; 995dc5e4fbSThomas Petazzoni } 1005dc5e4fbSThomas Petazzoni 1015dc5e4fbSThomas Petazzoni /* R22h - RAM data write */ 1025dc5e4fbSThomas Petazzoni write_reg(par, 0x22); 1035dc5e4fbSThomas Petazzoni } 1045dc5e4fbSThomas Petazzoni 1055dc5e4fbSThomas Petazzoni static int set_var(struct fbtft_par *par) 1065dc5e4fbSThomas Petazzoni { 1075dc5e4fbSThomas Petazzoni if (par->fbtftops.init_display != init_display) { 1085dc5e4fbSThomas Petazzoni /* don't risk messing up register 11h */ 1095dc5e4fbSThomas Petazzoni fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, 1105dc5e4fbSThomas Petazzoni "%s: skipping since custom init_display() is used\n", 1115dc5e4fbSThomas Petazzoni __func__); 1125dc5e4fbSThomas Petazzoni return 0; 1135dc5e4fbSThomas Petazzoni } 1145dc5e4fbSThomas Petazzoni 1155dc5e4fbSThomas Petazzoni switch (par->info->var.rotate) { 1165dc5e4fbSThomas Petazzoni case 0: 117153fe946SGeert Uytterhoeven write_reg(par, 0x11, reg11 | 0x30); 1185dc5e4fbSThomas Petazzoni break; 1195dc5e4fbSThomas Petazzoni case 270: 120153fe946SGeert Uytterhoeven write_reg(par, 0x11, reg11 | 0x28); 1215dc5e4fbSThomas Petazzoni break; 1225dc5e4fbSThomas Petazzoni case 180: 123153fe946SGeert Uytterhoeven write_reg(par, 0x11, reg11 | 0x00); 1245dc5e4fbSThomas Petazzoni break; 1255dc5e4fbSThomas Petazzoni case 90: 126153fe946SGeert Uytterhoeven write_reg(par, 0x11, reg11 | 0x18); 1275dc5e4fbSThomas Petazzoni break; 1285dc5e4fbSThomas Petazzoni } 1295dc5e4fbSThomas Petazzoni 1305dc5e4fbSThomas Petazzoni return 0; 1315dc5e4fbSThomas Petazzoni } 1325dc5e4fbSThomas Petazzoni 1335dc5e4fbSThomas Petazzoni /* 134*b2a8bb77SAnson Jacob * Gamma string format: 135*b2a8bb77SAnson Jacob * VRP0 VRP1 PRP0 PRP1 PKP0 PKP1 PKP2 PKP3 PKP4 PKP5 136*b2a8bb77SAnson Jacob * VRN0 VRN1 PRN0 PRN1 PKN0 PKN1 PKN2 PKN3 PKN4 PKN5 1375dc5e4fbSThomas Petazzoni */ 1385dc5e4fbSThomas Petazzoni #define CURVE(num, idx) curves[num * par->gamma.num_values + idx] 1395dc5e4fbSThomas Petazzoni static int set_gamma(struct fbtft_par *par, unsigned long *curves) 1405dc5e4fbSThomas Petazzoni { 1415dc5e4fbSThomas Petazzoni unsigned long mask[] = { 142153fe946SGeert Uytterhoeven 0x1f, 0x1f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 143153fe946SGeert Uytterhoeven 0x1f, 0x1f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 144153fe946SGeert Uytterhoeven }; 1455dc5e4fbSThomas Petazzoni int i, j; 1465dc5e4fbSThomas Petazzoni 1475dc5e4fbSThomas Petazzoni /* apply mask */ 1485dc5e4fbSThomas Petazzoni for (i = 0; i < 2; i++) 1495dc5e4fbSThomas Petazzoni for (j = 0; j < 10; j++) 1505dc5e4fbSThomas Petazzoni CURVE(i, j) &= mask[i * par->gamma.num_values + j]; 1515dc5e4fbSThomas Petazzoni 1525dc5e4fbSThomas Petazzoni write_reg(par, 0x0030, CURVE(0, 5) << 8 | CURVE(0, 4)); 1535dc5e4fbSThomas Petazzoni write_reg(par, 0x0031, CURVE(0, 7) << 8 | CURVE(0, 6)); 1545dc5e4fbSThomas Petazzoni write_reg(par, 0x0032, CURVE(0, 9) << 8 | CURVE(0, 8)); 1555dc5e4fbSThomas Petazzoni write_reg(par, 0x0033, CURVE(0, 3) << 8 | CURVE(0, 2)); 1565dc5e4fbSThomas Petazzoni write_reg(par, 0x0034, CURVE(1, 5) << 8 | CURVE(1, 4)); 1575dc5e4fbSThomas Petazzoni write_reg(par, 0x0035, CURVE(1, 7) << 8 | CURVE(1, 6)); 1585dc5e4fbSThomas Petazzoni write_reg(par, 0x0036, CURVE(1, 9) << 8 | CURVE(1, 8)); 1595dc5e4fbSThomas Petazzoni write_reg(par, 0x0037, CURVE(1, 3) << 8 | CURVE(1, 2)); 1605dc5e4fbSThomas Petazzoni write_reg(par, 0x003A, CURVE(0, 1) << 8 | CURVE(0, 0)); 1615dc5e4fbSThomas Petazzoni write_reg(par, 0x003B, CURVE(1, 1) << 8 | CURVE(1, 0)); 1625dc5e4fbSThomas Petazzoni 1635dc5e4fbSThomas Petazzoni return 0; 1645dc5e4fbSThomas Petazzoni } 1655dc5e4fbSThomas Petazzoni #undef CURVE 1665dc5e4fbSThomas Petazzoni 1675dc5e4fbSThomas Petazzoni static struct fbtft_display display = { 1685dc5e4fbSThomas Petazzoni .regwidth = 16, 1695dc5e4fbSThomas Petazzoni .width = WIDTH, 1705dc5e4fbSThomas Petazzoni .height = HEIGHT, 1715dc5e4fbSThomas Petazzoni .gamma_num = 2, 1725dc5e4fbSThomas Petazzoni .gamma_len = 10, 1735dc5e4fbSThomas Petazzoni .gamma = DEFAULT_GAMMA, 1745dc5e4fbSThomas Petazzoni .fbtftops = { 1755dc5e4fbSThomas Petazzoni .init_display = init_display, 1765dc5e4fbSThomas Petazzoni .set_addr_win = set_addr_win, 1775dc5e4fbSThomas Petazzoni .set_var = set_var, 1785dc5e4fbSThomas Petazzoni .set_gamma = set_gamma, 1795dc5e4fbSThomas Petazzoni }, 1805dc5e4fbSThomas Petazzoni }; 1811014c2ceSAnish Bhatt 1825dc5e4fbSThomas Petazzoni FBTFT_REGISTER_DRIVER(DRVNAME, "solomon,ssd1289", &display); 1835dc5e4fbSThomas Petazzoni 1845dc5e4fbSThomas Petazzoni MODULE_ALIAS("spi:" DRVNAME); 1855dc5e4fbSThomas Petazzoni MODULE_ALIAS("platform:" DRVNAME); 1865dc5e4fbSThomas Petazzoni MODULE_ALIAS("spi:ssd1289"); 1875dc5e4fbSThomas Petazzoni MODULE_ALIAS("platform:ssd1289"); 1885dc5e4fbSThomas Petazzoni 1895dc5e4fbSThomas Petazzoni MODULE_DESCRIPTION("FB driver for the SSD1289 LCD Controller"); 1905dc5e4fbSThomas Petazzoni MODULE_AUTHOR("Noralf Tronnes"); 1915dc5e4fbSThomas Petazzoni MODULE_LICENSE("GPL"); 192