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