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.
20 #include <linux/module.h>
21 #include <linux/kernel.h>
22 #include <linux/init.h>
23 #include <linux/gpio.h>
24 #include <linux/spi/spi.h>
25 #include <linux/delay.h>
29 #define DRVNAME "fb_pcd8544"
32 #define TXBUFLEN (84 * 6)
33 #define DEFAULT_GAMMA "40" /* gamma controls the contrast in this driver */
35 static unsigned int tc;
36 module_param(tc, uint, 0000);
37 MODULE_PARM_DESC(tc, "TC[1:0] Temperature coefficient: 0-3 (default: 0)");
39 static unsigned int bs = 4;
40 module_param(bs, uint, 0000);
41 MODULE_PARM_DESC(bs, "BS[2:0] Bias voltage level: 0-7 (default: 4)");
43 static int init_display(struct fbtft_par *par)
45 par->fbtftops.reset(par);
50 * 2:0 PD - Powerdown control: chip is active
51 * 1:0 V - Entry mode: horizontal addressing
52 * 0:1 H - Extended instruction set control: extended
56 /* H=1 Temperature control
59 * 1:x TC1 - Temperature Coefficient: 0x10
62 write_reg(par, 0x04 | (tc & 0x3));
68 * 2:x BS2 - Bias System
72 write_reg(par, 0x10 | (bs & 0x7));
77 * 2:0 PD - Powerdown control: chip is active
78 * 1:1 V - Entry mode: vertical addressing
79 * 0:0 H - Extended instruction set control: basic
83 /* H=0 Display control
86 * 2:1 D - DE: 10=normal mode
90 write_reg(par, 0x08 | 4);
95 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
97 /* H=0 Set X address of RAM
102 write_reg(par, 0x80);
104 /* H=0 Set Y address of RAM
110 write_reg(par, 0x40);
113 static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
115 u16 *vmem16 = (u16 *)par->info->screen_buffer;
116 u8 *buf = par->txbuf.buf;
120 for (x = 0; x < 84; x++) {
121 for (y = 0; y < 6; y++) {
123 for (i = 0; i < 8; i++)
124 *buf |= (vmem16[(y * 8 + i) * 84 + x] ?
131 gpio_set_value(par->gpio.dc, 1);
132 ret = par->fbtftops.write(par, par->txbuf.buf, 6 * 84);
134 dev_err(par->info->device, "write failed and returned: %d\n",
140 static int set_gamma(struct fbtft_par *par, u32 *curves)
145 write_reg(par, 0x23); /* turn on extended instruction set */
146 write_reg(par, 0x80 | curves[0]);
147 write_reg(par, 0x22); /* turn off extended instruction set */
152 static struct fbtft_display display = {
156 .txbuflen = TXBUFLEN,
159 .gamma = DEFAULT_GAMMA,
161 .init_display = init_display,
162 .set_addr_win = set_addr_win,
163 .write_vmem = write_vmem,
164 .set_gamma = set_gamma,
169 FBTFT_REGISTER_DRIVER(DRVNAME, "philips,pdc8544", &display);
171 MODULE_ALIAS("spi:" DRVNAME);
172 MODULE_ALIAS("spi:pdc8544");
174 MODULE_DESCRIPTION("FB driver for the PCD8544 LCD Controller");
175 MODULE_AUTHOR("Noralf Tronnes");
176 MODULE_LICENSE("GPL");