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