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