Skip to content

Commit

Permalink
fb_ili9340: add support for ILI9340
Browse files Browse the repository at this point in the history
  • Loading branch information
notro committed Nov 11, 2013
1 parent 663a4b2 commit 5a01afb
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Kconfig
Expand Up @@ -32,6 +32,12 @@ config FB_TFT_ILI9325
help
Generic Framebuffer support for ILI9325

config FB_TFT_ILI9340
tristate "FB driver for the ILI9340 LCD Controller"
depends on FB_TFT
help
Generic Framebuffer support for ILI9340

config FB_TFT_ILI9341
tristate "FB driver for the ILI9341 LCD Controller"
depends on FB_TFT
Expand Down
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -7,6 +7,7 @@ obj-$(CONFIG_FB_TFT_HX8340BN) += fb_hx8340bn.o
obj-$(CONFIG_FB_TFT_HX8347D) += fb_hx8347d.o
obj-$(CONFIG_FB_TFT_ILI9320) += fb_ili9320.o
obj-$(CONFIG_FB_TFT_ILI9325) += fb_ili9325.o
obj-$(CONFIG_FB_TFT_ILI9340) += fb_ili9340.o
obj-$(CONFIG_FB_TFT_ILI9341) += fb_ili9341.o
obj-$(CONFIG_FB_TFT_PCD8544) += fb_pcd8544.o
obj-$(CONFIG_FB_TFT_SSD1289) += fb_ssd1289.o
Expand Down
161 changes: 161 additions & 0 deletions fb_ili9340.c
@@ -0,0 +1,161 @@
/*
* FB driver for the ILI9340 LCD Controller
*
* Copyright (C) 2013 Noralf Tronnes
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/gpio.h>
#include <linux/delay.h>

#include "fbtft.h"

#define DRVNAME "fb_ili9340"
#define WIDTH 240
#define HEIGHT 320


/* Init sequence taken from: Arduino Library for the Adafruit 2.2" display */
static int init_display(struct fbtft_par *par)
{
fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);

par->fbtftops.reset(par);

write_reg(par, 0xEF, 0x03, 0x80, 0x02);
write_reg(par, 0xCF, 0x00 , 0XC1 , 0X30);
write_reg(par, 0xED, 0x64 , 0x03 , 0X12 , 0X81);
write_reg(par, 0xE8, 0x85 , 0x00 , 0x78);
write_reg(par, 0xCB, 0x39 , 0x2C , 0x00 , 0x34 , 0x02);
write_reg(par, 0xF7, 0x20);
write_reg(par, 0xEA, 0x00 , 0x00);

/* Power Control 1 */
write_reg(par, 0xC0, 0x23);

/* Power Control 2 */
write_reg(par, 0xC1, 0x10);

/* VCOM Control 1 */
write_reg(par, 0xC5, 0x3e, 0x28);

/* VCOM Control 2 */
write_reg(par, 0xC7, 0x86);

/* COLMOD: Pixel Format Set */
/* 16 bits/pixel */
write_reg(par, 0x3A, 0x55);

/* Frame Rate Control */
/* Division ratio = fosc, Frame Rate = 79Hz */
write_reg(par, 0xB1, 0x00, 0x18);

/* Display Function Control */
write_reg(par, 0xB6, 0x08, 0x82, 0x27);

/* Gamma Function Disable */
write_reg(par, 0xF2, 0x00);

/* Gamma curve selected */
write_reg(par, 0x26, 0x01);

/* Positive Gamma Correction */
write_reg(par, 0xE0,
0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1,
0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00);

/* Negative Gamma Correction */
write_reg(par, 0xE1,
0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1,
0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F);

/* Sleep OUT */
write_reg(par, 0x11);

mdelay(120);

/* Display ON */
write_reg(par, 0x29);

return 0;
}

static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
{
fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
"%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);

/* Column address */
write_reg(par, 0x2A, xs >> 8, xs & 0xFF, xe >> 8, xe & 0xFF);

/* Row adress */
write_reg(par, 0x2B, ys >> 8, ys & 0xFF, ye >> 8, ye & 0xFF);

/* Memory write */
write_reg(par, 0x2C);
}

#define ILI9340_MADCTL_MV 0x20
#define ILI9340_MADCTL_MX 0x40
#define ILI9340_MADCTL_MY 0x80
static int set_var(struct fbtft_par *par)
{
u8 val;

fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);

switch (par->info->var.rotate) {
case 270:
val = ILI9340_MADCTL_MV;
break;
case 180:
val = ILI9340_MADCTL_MY;
break;
case 90:
val = ILI9340_MADCTL_MV | ILI9340_MADCTL_MY | ILI9340_MADCTL_MX;
break;
default:
val = ILI9340_MADCTL_MX;
break;
}
/* Memory Access Control */
write_reg(par, 0x36, val | (par->bgr << 3));

return 0;
}


static struct fbtft_display display = {
.regwidth = 8,
.width = WIDTH,
.height = HEIGHT,
.fbtftops = {
.init_display = init_display,
.set_addr_win = set_addr_win,
.set_var = set_var,
},
};
FBTFT_REGISTER_DRIVER(DRVNAME, &display);

MODULE_ALIAS("spi:" DRVNAME);
MODULE_ALIAS("platform:" DRVNAME);

MODULE_DESCRIPTION("FB driver for the ILI9340 LCD Controller");
MODULE_AUTHOR("Noralf Tronnes");
MODULE_LICENSE("GPL");
20 changes: 20 additions & 0 deletions fbtft_device.c
Expand Up @@ -200,6 +200,26 @@ static struct fbtft_device_display displays[] = {
},
}
}
}, {
.name = "adafruit22a",
.spi = &(struct spi_board_info) {
.modalias = "fb_ili9340",
.max_speed_hz = 32000000,
.mode = SPI_MODE_0,
.platform_data = &(struct fbtft_platform_data) {
.display = {
.buswidth = 8,
.backlight = 1,
},
.bgr = true,
.gpios = (const struct fbtft_gpio []) {
{ "reset", 25 },
{ "dc", 24 },
{ "led", 18 },
{},
},
}
}
}, {
.name = "flexfb",
.spi = &(struct spi_board_info) {
Expand Down

0 comments on commit 5a01afb

Please sign in to comment.