1 // SPDX-License-Identifier: GPL-2.0+
3 * FB driver for the PCD8544 LCD Controller
5 * The display is monochrome and the video memory is RGB565.
6 * Any pixel value except 0 turns the pixel on.
8 * Copyright (C) 2013 Noralf Tronnes
11 #include <linux/module.h>
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/gpio/consumer.h>
15 #include <linux/spi/spi.h>
16 #include <linux/delay.h>
20 #define DRVNAME "fb_pcd8544"
23 #define TXBUFLEN (84 * 6)
24 #define DEFAULT_GAMMA "40" /* gamma controls the contrast in this driver */
26 static unsigned int tc;
27 module_param(tc, uint, 0000);
28 MODULE_PARM_DESC(tc, "TC[1:0] Temperature coefficient: 0-3 (default: 0)");
30 static unsigned int bs = 4;
31 module_param(bs, uint, 0000);
32 MODULE_PARM_DESC(bs, "BS[2:0] Bias voltage level: 0-7 (default: 4)");
34 static int init_display(struct fbtft_par *par)
36 par->fbtftops.reset(par);
41 * 2:0 PD - Powerdown control: chip is active
42 * 1:0 V - Entry mode: horizontal addressing
43 * 0:1 H - Extended instruction set control: extended
47 /* H=1 Temperature control
50 * 1:x TC1 - Temperature Coefficient: 0x10
53 write_reg(par, 0x04 | (tc & 0x3));
59 * 2:x BS2 - Bias System
63 write_reg(par, 0x10 | (bs & 0x7));
68 * 2:0 PD - Powerdown control: chip is active
69 * 1:1 V - Entry mode: vertical addressing
70 * 0:0 H - Extended instruction set control: basic
74 /* H=0 Display control
77 * 2:1 D - DE: 10=normal mode
81 write_reg(par, 0x08 | 4);
86 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
88 /* H=0 Set X address of RAM
95 /* H=0 Set Y address of RAM
101 write_reg(par, 0x40);
104 static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
106 u16 *vmem16 = (u16 *)par->info->screen_buffer;
107 u8 *buf = par->txbuf.buf;
111 for (x = 0; x < 84; x++) {
112 for (y = 0; y < 6; y++) {
114 for (i = 0; i < 8; i++)
115 *buf |= (vmem16[(y * 8 + i) * 84 + x] ?
122 gpiod_set_value(par->gpio.dc, 1);
123 ret = par->fbtftops.write(par, par->txbuf.buf, 6 * 84);
125 dev_err(par->info->device, "write failed and returned: %d\n",
131 static int set_gamma(struct fbtft_par *par, u32 *curves)
136 write_reg(par, 0x23); /* turn on extended instruction set */
137 write_reg(par, 0x80 | curves[0]);
138 write_reg(par, 0x22); /* turn off extended instruction set */
143 static struct fbtft_display display = {
147 .txbuflen = TXBUFLEN,
150 .gamma = DEFAULT_GAMMA,
152 .init_display = init_display,
153 .set_addr_win = set_addr_win,
154 .write_vmem = write_vmem,
155 .set_gamma = set_gamma,
160 FBTFT_REGISTER_DRIVER(DRVNAME, "philips,pcd8544", &display);
162 MODULE_ALIAS("spi:" DRVNAME);
163 MODULE_ALIAS("spi:pcd8544");
165 MODULE_DESCRIPTION("FB driver for the PCD8544 LCD Controller");
166 MODULE_AUTHOR("Noralf Tronnes");
167 MODULE_LICENSE("GPL");