1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#include <linux/module.h>
18#include <linux/kernel.h>
19#include <linux/init.h>
20#include <linux/gpio.h>
21#include <linux/delay.h>
22
23#include "fbtft.h"
24
25#define DRVNAME "fb_ssd1305"
26
27#define WIDTH 128
28#define HEIGHT 64
29
30
31
32
33
34
35
36
37
38
39
40
41
42static int init_display(struct fbtft_par *par)
43{
44 par->fbtftops.reset(par);
45
46 if (par->gamma.curves[0] == 0) {
47 mutex_lock(&par->gamma.lock);
48 if (par->info->var.yres == 64)
49 par->gamma.curves[0] = 0xCF;
50 else
51 par->gamma.curves[0] = 0x8F;
52 mutex_unlock(&par->gamma.lock);
53 }
54
55
56 write_reg(par, 0xAE);
57
58
59 write_reg(par, 0xD5);
60 write_reg(par, 0x80);
61
62
63 write_reg(par, 0xA8);
64 if (par->info->var.yres == 64)
65 write_reg(par, 0x3F);
66 else
67 write_reg(par, 0x1F);
68
69
70 write_reg(par, 0xD3);
71 write_reg(par, 0x0);
72
73
74 write_reg(par, 0x40 | 0x0);
75
76
77 write_reg(par, 0x8D);
78
79 write_reg(par, 0x14);
80
81
82 write_reg(par, 0x20);
83
84 write_reg(par, 0x01);
85
86
87
88
89
90 write_reg(par, 0xA0 | ((par->info->var.rotate == 180) ? 0x0 : 0x1));
91
92
93
94
95
96 write_reg(par, ((par->info->var.rotate == 180) ? 0xC8 : 0xC0));
97
98
99 write_reg(par, 0xDA);
100 if (par->info->var.yres == 64) {
101
102 write_reg(par, 0x12);
103 } else {
104
105 write_reg(par, 0x02);
106 }
107
108
109 write_reg(par, 0xD9);
110 write_reg(par, 0xF1);
111
112
113
114
115
116 write_reg(par, 0xA4);
117
118
119
120
121
122
123 write_reg(par, 0xA6);
124
125
126 write_reg(par, 0xAF);
127
128 return 0;
129}
130
131static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
132{
133
134 write_reg(par, 0x00 | ((par->info->var.rotate == 180) ? 0x0 : 0x4));
135
136 write_reg(par, 0x10 | 0x0);
137
138 write_reg(par, 0x40 | 0x0);
139}
140
141static int blank(struct fbtft_par *par, bool on)
142{
143 if (on)
144 write_reg(par, 0xAE);
145 else
146 write_reg(par, 0xAF);
147 return 0;
148}
149
150
151static int set_gamma(struct fbtft_par *par, u32 *curves)
152{
153 curves[0] &= 0xFF;
154
155 write_reg(par, 0x81);
156 write_reg(par, curves[0]);
157
158 return 0;
159}
160
161static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
162{
163 u16 *vmem16 = (u16 *)par->info->screen_buffer;
164 u8 *buf = par->txbuf.buf;
165 int x, y, i;
166 int ret;
167
168 for (x = 0; x < par->info->var.xres; x++) {
169 for (y = 0; y < par->info->var.yres / 8; y++) {
170 *buf = 0x00;
171 for (i = 0; i < 8; i++)
172 *buf |= (vmem16[(y * 8 + i) *
173 par->info->var.xres + x] ?
174 1 : 0) << i;
175 buf++;
176 }
177 }
178
179
180 gpio_set_value(par->gpio.dc, 1);
181 ret = par->fbtftops.write(par, par->txbuf.buf,
182 par->info->var.xres * par->info->var.yres /
183 8);
184 if (ret < 0)
185 dev_err(par->info->device, "write failed and returned: %d\n",
186 ret);
187 return ret;
188}
189
190static struct fbtft_display display = {
191 .regwidth = 8,
192 .width = WIDTH,
193 .height = HEIGHT,
194 .txbuflen = WIDTH * HEIGHT / 8,
195 .gamma_num = 1,
196 .gamma_len = 1,
197 .gamma = "00",
198 .fbtftops = {
199 .write_vmem = write_vmem,
200 .init_display = init_display,
201 .set_addr_win = set_addr_win,
202 .blank = blank,
203 .set_gamma = set_gamma,
204 },
205};
206
207FBTFT_REGISTER_DRIVER(DRVNAME, "solomon,ssd1305", &display);
208
209MODULE_ALIAS("spi:" DRVNAME);
210MODULE_ALIAS("platform:" DRVNAME);
211MODULE_ALIAS("spi:ssd1305");
212MODULE_ALIAS("platform:ssd1305");
213
214MODULE_DESCRIPTION("SSD1305 OLED Driver");
215MODULE_AUTHOR("Alexey Mednyy");
216MODULE_LICENSE("GPL");
217