2 * FB driver for the SSD1325 OLED Controller
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/gpio.h>
19 #include <linux/delay.h>
23 #define DRVNAME "fb_ssd1325"
29 #define DEFAULT_GAMMA "7 1 1 1 1 2 2 3 3 4 4 5 5 6 6"
34 * This doesn't work because D/C has to be LOW for both values:
35 * write_reg(par, val1, val2);
38 * write_reg(par, val1);
39 * write_reg(par, val2);
42 /* Init sequence taken from the Adafruit SSD1306 Arduino library */
43 static int init_display(struct fbtft_par *par)
45 par->fbtftops.reset(par);
47 gpio_set_value(par->gpio.cs, 0);
72 static uint8_t rgb565_to_g16(u16 pixel)
75 u16 g = (pixel & (0x3f << 5)) >> 5;
76 u16 r = (pixel & (0x1f << (5 + 6))) >> (5 + 6);
78 pixel = (299 * r + 587 * g + 114 * b) / 195;
81 return (uint8_t)pixel / 16;
84 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
86 fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
87 "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe,
98 static int blank(struct fbtft_par *par, bool on)
100 fbtft_par_dbg(DEBUG_BLANK, par, "%s(blank=%s)\n",
101 __func__, on ? "true" : "false");
104 write_reg(par, 0xAE);
106 write_reg(par, 0xAF);
111 * Grayscale Lookup Table
113 * The "Gamma curve" contains the relative values between the entries
114 * in the Lookup table.
116 * 0 = Setting of GS1 < Setting of GS2 < Setting of GS3.....<
117 * Setting of GS14 < Setting of GS15
119 static int set_gamma(struct fbtft_par *par, u32 *curves)
123 fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
125 for (i = 0; i < GAMMA_LEN; i++) {
126 if (i > 0 && curves[i] < 1) {
127 dev_err(par->info->device,
128 "Illegal value in Grayscale Lookup Table at index %d.\n"
129 "Must be greater than 0\n", i);
133 dev_err(par->info->device,
134 "Illegal value(s) in Grayscale Lookup Table.\n"
135 "At index=%d, the accumulated value has exceeded 7\n",
140 write_reg(par, 0xB8);
141 for (i = 0; i < 8; i++)
142 write_reg(par, (curves[i] & 0xFF));
146 static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
148 u16 *vmem16 = (u16 *)par->info->screen_buffer;
149 u8 *buf = par->txbuf.buf;
155 for (x = 0; x < par->info->var.xres; x++) {
158 for (y = 0; y < par->info->var.yres; y++) {
159 n1 = rgb565_to_g16(vmem16[y * par->info->var.xres + x]);
160 n2 = rgb565_to_g16(vmem16
161 [y * par->info->var.xres + x + 1]);
162 *buf = (n1 << 4) | n2;
167 gpio_set_value(par->gpio.dc, 1);
170 ret = par->fbtftops.write(par, par->txbuf.buf,
171 par->info->var.xres * par->info->var.yres / 2);
173 dev_err(par->info->device,
174 "%s: write failed and returned: %d\n", __func__, ret);
179 static struct fbtft_display display = {
183 .txbuflen = WIDTH * HEIGHT / 2,
184 .gamma_num = GAMMA_NUM,
185 .gamma_len = GAMMA_LEN,
186 .gamma = DEFAULT_GAMMA,
188 .write_vmem = write_vmem,
189 .init_display = init_display,
190 .set_addr_win = set_addr_win,
192 .set_gamma = set_gamma,
196 FBTFT_REGISTER_DRIVER(DRVNAME, "solomon,ssd1325", &display);
198 MODULE_ALIAS("spi:" DRVNAME);
199 MODULE_ALIAS("platform:" DRVNAME);
200 MODULE_ALIAS("spi:ssd1325");
201 MODULE_ALIAS("platform:ssd1325");
203 MODULE_DESCRIPTION("SSD1325 OLED Driver");
204 MODULE_AUTHOR("Alexey Mednyy");
205 MODULE_LICENSE("GPL");