1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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>
30
31#include "fbtft.h"
32
33#define DRVNAME "fb_pcd8544"
34#define WIDTH 84
35#define HEIGHT 48
36#define TXBUFLEN (84*6)
37#define DEFAULT_GAMMA "40"
38
39static unsigned tc;
40module_param(tc, uint, 0);
41MODULE_PARM_DESC(tc, "TC[1:0] Temperature coefficient: 0-3 (default: 0)");
42
43static unsigned bs = 4;
44module_param(bs, uint, 0);
45MODULE_PARM_DESC(bs, "BS[2:0] Bias voltage level: 0-7 (default: 4)");
46
47
48static int init_display(struct fbtft_par *par)
49{
50 fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
51
52 par->fbtftops.reset(par);
53
54
55
56
57
58
59
60
61 write_reg(par, 0x21);
62
63
64
65
66
67
68
69 write_reg(par, 0x04 | (tc & 0x3));
70
71
72
73
74
75
76
77
78
79 write_reg(par, 0x10 | (bs & 0x7));
80
81
82
83
84
85
86
87
88 write_reg(par, 0x22);
89
90
91
92
93
94
95
96
97 write_reg(par, 0x08 | 4);
98
99 return 0;
100}
101
102static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
103{
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);
106
107
108
109
110
111
112 write_reg(par, 0x80);
113
114
115
116
117
118
119
120 write_reg(par, 0x40);
121}
122
123static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
124{
125 u16 *vmem16 = (u16 *)par->info->screen_base;
126 u8 *buf = par->txbuf.buf;
127 int x, y, i;
128 int ret = 0;
129
130 fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s()\n", __func__);
131
132 for (x = 0; x < 84; x++) {
133 for (y = 0; y < 6; y++) {
134 *buf = 0x00;
135 for (i = 0; i < 8; i++)
136 *buf |= (vmem16[(y*8+i)*84+x] ? 1 : 0) << i;
137 buf++;
138 }
139 }
140
141
142 gpio_set_value(par->gpio.dc, 1);
143 ret = par->fbtftops.write(par, par->txbuf.buf, 6*84);
144 if (ret < 0)
145 dev_err(par->info->device, "write failed and returned: %d\n",
146 ret);
147
148 return ret;
149}
150
151static int set_gamma(struct fbtft_par *par, unsigned long *curves)
152{
153 fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
154
155
156 curves[0] &= 0x7F;
157
158 write_reg(par, 0x23);
159 write_reg(par, 0x80 | curves[0]);
160 write_reg(par, 0x22);
161
162 return 0;
163}
164
165
166static struct fbtft_display display = {
167 .regwidth = 8,
168 .width = WIDTH,
169 .height = HEIGHT,
170 .txbuflen = TXBUFLEN,
171 .gamma_num = 1,
172 .gamma_len = 1,
173 .gamma = DEFAULT_GAMMA,
174 .fbtftops = {
175 .init_display = init_display,
176 .set_addr_win = set_addr_win,
177 .write_vmem = write_vmem,
178 .set_gamma = set_gamma,
179 },
180 .backlight = 1,
181};
182FBTFT_REGISTER_DRIVER(DRVNAME, "philips,pdc8544", &display);
183
184MODULE_ALIAS("spi:" DRVNAME);
185MODULE_ALIAS("spi:pdc8544");
186
187MODULE_DESCRIPTION("FB driver for the PCD8544 LCD Controller");
188MODULE_AUTHOR("Noralf Tronnes");
189MODULE_LICENSE("GPL");
190