Skip to content

Commit 663a4b2

Browse files
committed
Merge pull request raspberrypi#50 from asmecher/master
Add support for SSD1331
2 parents e207c4e + e4f01a8 commit 663a4b2

File tree

4 files changed

+227
-0
lines changed

4 files changed

+227
-0
lines changed

Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ config FB_TFT_SSD1289
5050
help
5151
Framebuffer support for SSD1289
5252

53+
config FB_TFT_SSD1331
54+
tristate "FB driver for the SSD1331 LCD Controller"
55+
depends on FB_TFT
56+
help
57+
Framebuffer support for SSD1331
58+
5359
config FB_TFT_SSD1351
5460
tristate "FB driver for the SSD1351 LCD Controller"
5561
depends on FB_TFT

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ obj-$(CONFIG_FB_TFT_ILI9325) += fb_ili9325.o
1010
obj-$(CONFIG_FB_TFT_ILI9341) += fb_ili9341.o
1111
obj-$(CONFIG_FB_TFT_PCD8544) += fb_pcd8544.o
1212
obj-$(CONFIG_FB_TFT_SSD1289) += fb_ssd1289.o
13+
obj-$(CONFIG_FB_TFT_SSD1331) += fb_ssd1331.o
1314
obj-$(CONFIG_FB_TFT_SSD1351) += fb_ssd1351.o
1415
obj-$(CONFIG_FB_TFT_ST7735R) += fb_st7735r.o
1516
obj-$(CONFIG_FB_TFT_WATTEROTT) += fb_watterott.o

fb_ssd1331.c

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
#include <linux/module.h>
2+
#include <linux/kernel.h>
3+
#include <linux/init.h>
4+
#include <linux/gpio.h>
5+
#include <linux/spi/spi.h>
6+
#include <linux/delay.h>
7+
8+
#include "fbtft.h"
9+
10+
#define DRVNAME "fb_ssd1331"
11+
#define WIDTH 96
12+
#define HEIGHT 64
13+
#define GAMMA_NUM 1
14+
#define GAMMA_LEN 63
15+
#define DEFAULT_GAMMA "0 2 2 2 2 2 2 2 " \
16+
"2 2 2 2 2 2 2 2 " \
17+
"2 2 2 2 2 2 2 2 " \
18+
"2 2 2 2 2 2 2 2 " \
19+
"2 2 2 2 2 2 2 2 " \
20+
"2 2 2 2 2 2 2 2 " \
21+
"2 2 2 2 2 2 2 2 " \
22+
"2 2 2 2 2 2 2" \
23+
24+
static int init_display(struct fbtft_par *par)
25+
{
26+
fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
27+
28+
par->fbtftops.reset(par);
29+
30+
write_reg(par, 0xae); /* Display Off */
31+
write_reg(par, 0xa0, 0x70 | (par->bgr << 2)); /* Set Colour Depth */
32+
write_reg(par, 0x72); // RGB colour
33+
write_reg(par, 0xa1, 0x00); /* Set Display Start Line */
34+
write_reg(par, 0xa2, 0x00); /* Set Display Offset */
35+
write_reg(par, 0xa4); /* NORMALDISPLAY */
36+
write_reg(par, 0xa8, 0x3f); // Set multiplex
37+
write_reg(par, 0xad, 0x8e); // Set master
38+
// write_reg(par, 0xb0, 0x0b); // Set power mode
39+
write_reg(par, 0xb1, 0x31); // Precharge
40+
write_reg(par, 0xb3, 0xf0); // Clock div
41+
write_reg(par, 0x8a, 0x64); // Precharge A
42+
write_reg(par, 0x8b, 0x78); // Precharge B
43+
write_reg(par, 0x8c, 0x64); // Precharge C
44+
write_reg(par, 0xbb, 0x3a); // Precharge level
45+
write_reg(par, 0xbe, 0x3e); // vcomh
46+
write_reg(par, 0x87, 0x06); // Master current
47+
write_reg(par, 0x81, 0x91); // Contrast A
48+
write_reg(par, 0x82, 0x50); // Contrast B
49+
write_reg(par, 0x83, 0x7d); // Contrast C
50+
write_reg(par, 0xaf); /* Set Sleep Mode Display On */
51+
52+
return 0;
53+
}
54+
55+
static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
56+
{
57+
fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
58+
"%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
59+
60+
write_reg(par, 0x15, xs, xe);
61+
write_reg(par, 0x75, ys, ye);
62+
}
63+
64+
static void write_reg8_bus8(struct fbtft_par *par, int len, ...)
65+
{
66+
va_list args;
67+
int i, ret;
68+
u8 *buf = (u8 *)par->buf;
69+
70+
if (unlikely(par->debug & DEBUG_WRITE_REGISTER)) {
71+
va_start(args, len);
72+
for (i = 0; i < len; i++) {
73+
buf[i] = (u8)va_arg(args, unsigned int);
74+
}
75+
va_end(args);
76+
fbtft_par_dbg_hex(DEBUG_WRITE_REGISTER, par, par->info->device, u8, buf, len, "%s: ", __func__);
77+
}
78+
79+
va_start(args, len);
80+
81+
*buf = (u8)va_arg(args, unsigned int);
82+
if (par->gpio.dc != -1)
83+
gpio_set_value(par->gpio.dc, 0);
84+
ret = par->fbtftops.write(par, par->buf, sizeof(u8));
85+
if (ret < 0) {
86+
va_end(args);
87+
dev_err(par->info->device, "%s: write() failed and returned %d\n", __func__, ret);
88+
return;
89+
}
90+
len--;
91+
92+
if (len) {
93+
i = len;
94+
while (i--) {
95+
*buf++ = (u8)va_arg(args, unsigned int);
96+
}
97+
ret = par->fbtftops.write(par, par->buf, len * (sizeof(u8)));
98+
if (ret < 0) {
99+
va_end(args);
100+
dev_err(par->info->device, "%s: write() failed and returned %d\n", __func__, ret);
101+
return;
102+
}
103+
}
104+
if (par->gpio.dc != -1)
105+
gpio_set_value(par->gpio.dc, 1);
106+
va_end(args);
107+
}
108+
109+
/*
110+
Grayscale Lookup Table
111+
GS1 - GS63
112+
The driver Gamma curve contains the relative values between the entries
113+
in the Lookup table.
114+
115+
From datasheet:
116+
8.8 Gray Scale Decoder
117+
118+
there are total 180 Gamma Settings (Setting 0 to Setting 180)
119+
available for the Gray Scale table.
120+
121+
The gray scale is defined in incremental way, with reference
122+
to the length of previous table entry:
123+
Setting of GS1 has to be >= 0
124+
Setting of GS2 has to be > Setting of GS1 +1
125+
Setting of GS3 has to be > Setting of GS2 +1
126+
:
127+
Setting of GS63 has to be > Setting of GS62 +1
128+
129+
130+
*/
131+
static int set_gamma(struct fbtft_par *par, unsigned long *curves)
132+
{
133+
unsigned long tmp[GAMMA_NUM * GAMMA_LEN];
134+
int i, acc = 0;
135+
136+
fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
137+
138+
for (i = 0; i < 63; i++) {
139+
if (i > 0 && curves[i] < 2) {
140+
dev_err(par->info->device,
141+
"Illegal value in Grayscale Lookup Table at index %d. " \
142+
"Must be greater than 1\n", i);
143+
return -EINVAL;
144+
}
145+
acc += curves[i];
146+
tmp[i] = acc;
147+
if (acc > 180) {
148+
dev_err(par->info->device,
149+
"Illegal value(s) in Grayscale Lookup Table. " \
150+
"At index=%d, the accumulated value has exceeded 180\n", i);
151+
return -EINVAL;
152+
}
153+
}
154+
155+
write_reg(par, 0xB8,
156+
tmp[0], tmp[1], tmp[2], tmp[3], tmp[4], tmp[5], tmp[6], tmp[7],
157+
tmp[8], tmp[9], tmp[10], tmp[11], tmp[12], tmp[13], tmp[14], tmp[15],
158+
tmp[16], tmp[17], tmp[18], tmp[19], tmp[20], tmp[21], tmp[22], tmp[23],
159+
tmp[24], tmp[25], tmp[26], tmp[27], tmp[28], tmp[29], tmp[30], tmp[31],
160+
tmp[32], tmp[33], tmp[34], tmp[35], tmp[36], tmp[37], tmp[38], tmp[39],
161+
tmp[40], tmp[41], tmp[42], tmp[43], tmp[44], tmp[45], tmp[46], tmp[47],
162+
tmp[48], tmp[49], tmp[50], tmp[51], tmp[52], tmp[53], tmp[54], tmp[55],
163+
tmp[56], tmp[57], tmp[58], tmp[59], tmp[60], tmp[61], tmp[62]);
164+
165+
return 0;
166+
}
167+
168+
static int blank(struct fbtft_par *par, bool on)
169+
{
170+
fbtft_par_dbg(DEBUG_BLANK, par, "%s(blank=%s)\n",
171+
__func__, on ? "true" : "false");
172+
if (on)
173+
write_reg(par, 0xAE);
174+
else
175+
write_reg(par, 0xAF);
176+
return 0;
177+
}
178+
179+
180+
static struct fbtft_display display = {
181+
.regwidth = 8,
182+
.width = WIDTH,
183+
.height = HEIGHT,
184+
.gamma_num = GAMMA_NUM,
185+
.gamma_len = GAMMA_LEN,
186+
.gamma = DEFAULT_GAMMA,
187+
.fbtftops = {
188+
.write_register = write_reg8_bus8,
189+
.init_display = init_display,
190+
.set_addr_win = set_addr_win,
191+
.set_gamma = set_gamma,
192+
.blank = blank,
193+
},
194+
};
195+
196+
FBTFT_REGISTER_DRIVER(DRVNAME, &display);
197+
198+
MODULE_ALIAS("spi:" DRVNAME);
199+
MODULE_ALIAS("platform:" DRVNAME);
200+
201+
MODULE_DESCRIPTION("SSD1331 OLED Driver");
202+
MODULE_AUTHOR("Alec Smecher (adapted from SSD1351 by James Davies)");
203+
MODULE_LICENSE("GPL");

fbtft_device.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,23 @@ static struct fbtft_device_display displays[] = {
260260
},
261261
}
262262
}
263+
}, {
264+
.name = "ssd1331",
265+
.spi = &(struct spi_board_info) {
266+
.modalias = "fb_ssd1331",
267+
.max_speed_hz = 20000000,
268+
.mode = SPI_MODE_3,
269+
.platform_data = &(struct fbtft_platform_data) {
270+
.display = {
271+
.buswidth = 8,
272+
},
273+
.gpios = (const struct fbtft_gpio []) {
274+
{ "reset", 24 },
275+
{ "dc", 25 },
276+
{},
277+
},
278+
}
279+
}
263280
}, {
264281
.name = "hy28a",
265282
.spi = &(struct spi_board_info) {

0 commit comments

Comments
 (0)