2 * FB driver for the PCD8544 LCD Controller
4 * The display is monochrome and the video memory is RGB565.
5 * Any pixel value except 0 turns the pixel on.
7 * Copyright (C) 2013 Noralf Tronnes
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <linux/module.h>
25 #include <linux/kernel.h>
26 #include <linux/init.h>
27 #include <linux/gpio.h>
28 #include <linux/spi/spi.h>
29 #include <linux/delay.h>
33 #define DRVNAME "fb_pcd8544"
36 #define TXBUFLEN (84*6)
37 #define DEFAULT_GAMMA "40" /* gamma controls the contrast in this driver */
40 module_param(tc, uint, 0);
41 MODULE_PARM_DESC(tc, "TC[1:0] Temperature coefficient: 0-3 (default: 0)");
43 static unsigned bs = 4;
44 module_param(bs, uint, 0);
45 MODULE_PARM_DESC(bs, "BS[2:0] Bias voltage level: 0-7 (default: 4)");
48 static int init_display(struct fbtft_par *par)
50 fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
52 par->fbtftops.reset(par);
57 * 2:0 PD - Powerdown control: chip is active
58 * 1:0 V - Entry mode: horizontal addressing
59 * 0:1 H - Extended instruction set control: extended
63 /* H=1 Temperature control
66 * 1:x TC1 - Temperature Coefficient: 0x10
69 write_reg(par, 0x04 | (tc & 0x3));
75 * 2:x BS2 - Bias System
79 write_reg(par, 0x10 | (bs & 0x7));
84 * 2:0 PD - Powerdown control: chip is active
85 * 1:1 V - Entry mode: vertical addressing
86 * 0:0 H - Extended instruction set control: basic
90 /* H=0 Display control
93 * 2:1 D - DE: 10=normal mode
97 write_reg(par, 0x08 | 4);
102 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
104 fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par, "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n",
105 __func__, xs, ys, xe, ye);
107 /* H=0 Set X address of RAM
112 write_reg(par, 0x80);
114 /* H=0 Set Y address of RAM
120 write_reg(par, 0x40);
123 static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
125 u16 *vmem16 = (u16 *)par->info->screen_base;
126 u8 *buf = par->txbuf.buf;
130 fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s()\n", __func__);
132 for (x = 0; x < 84; x++) {
133 for (y = 0; y < 6; y++) {
135 for (i = 0; i < 8; i++)
136 *buf |= (vmem16[(y*8+i)*84+x] ? 1 : 0) << i;
142 gpio_set_value(par->gpio.dc, 1);
143 ret = par->fbtftops.write(par, par->txbuf.buf, 6*84);
145 dev_err(par->info->device, "write failed and returned: %d\n",
151 static int set_gamma(struct fbtft_par *par, unsigned long *curves)
153 fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
158 write_reg(par, 0x23); /* turn on extended instruction set */
159 write_reg(par, 0x80 | curves[0]);
160 write_reg(par, 0x22); /* turn off extended instruction set */
166 static struct fbtft_display display = {
170 .txbuflen = TXBUFLEN,
173 .gamma = DEFAULT_GAMMA,
175 .init_display = init_display,
176 .set_addr_win = set_addr_win,
177 .write_vmem = write_vmem,
178 .set_gamma = set_gamma,
182 FBTFT_REGISTER_DRIVER(DRVNAME, "philips,pdc8544", &display);
184 MODULE_ALIAS("spi:" DRVNAME);
185 MODULE_ALIAS("spi:pdc8544");
187 MODULE_DESCRIPTION("FB driver for the PCD8544 LCD Controller");
188 MODULE_AUTHOR("Noralf Tronnes");
189 MODULE_LICENSE("GPL");