2 * FB driver for the SSD1305 OLED Controller
4 * based on SSD1306 driver by Noralf Tronnes
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
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>
25 #define DRVNAME "fb_ssd1305"
33 * This doesn't work because D/C has to be LOW for both values:
34 * write_reg(par, val1, val2);
37 * write_reg(par, val1);
38 * write_reg(par, val2);
41 /* Init sequence taken from the Adafruit SSD1306 Arduino library */
42 static int init_display(struct fbtft_par *par)
44 par->fbtftops.reset(par);
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;
51 par->gamma.curves[0] = 0x8F;
52 mutex_unlock(&par->gamma.lock);
58 /* Set Display Clock Divide Ratio/ Oscillator Frequency */
62 /* Set Multiplex Ratio */
64 if (par->info->var.yres == 64)
69 /* Set Display Offset */
73 /* Set Display Start Line */
74 write_reg(par, 0x40 | 0x0);
76 /* Charge Pump Setting */
78 /* A[2] = 1b, Enable charge pump during display on */
81 /* Set Memory Addressing Mode */
83 /* Vertical addressing mode */
88 * column address 127 is mapped to SEG0
90 write_reg(par, 0xA0 | ((par->info->var.rotate == 180) ? 0x0 : 0x1));
93 * Set COM Output Scan Direction
94 * remapped mode. Scan from COM[N-1] to COM0
96 write_reg(par, ((par->info->var.rotate == 180) ? 0xC8 : 0xC0));
98 /* Set COM Pins Hardware Configuration */
100 if (par->info->var.yres == 64) {
101 /* A[4]=1b, Alternative COM pin configuration */
102 write_reg(par, 0x12);
104 /* A[4]=0b, Sequential COM pin configuration */
105 write_reg(par, 0x02);
108 /* Set Pre-charge Period */
109 write_reg(par, 0xD9);
110 write_reg(par, 0xF1);
114 * Resume to RAM content display. Output follows RAM content
116 write_reg(par, 0xA4);
120 * 0 in RAM: OFF in display panel
121 * 1 in RAM: ON in display panel
123 write_reg(par, 0xA6);
126 write_reg(par, 0xAF);
131 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
133 /* Set Lower Column Start Address for Page Addressing Mode */
134 write_reg(par, 0x00 | ((par->info->var.rotate == 180) ? 0x0 : 0x4));
135 /* Set Higher Column Start Address for Page Addressing Mode */
136 write_reg(par, 0x10 | 0x0);
137 /* Set Display Start Line */
138 write_reg(par, 0x40 | 0x0);
141 static int blank(struct fbtft_par *par, bool on)
144 write_reg(par, 0xAE);
146 write_reg(par, 0xAF);
150 /* Gamma is used to control Contrast */
151 static int set_gamma(struct fbtft_par *par, u32 *curves)
154 /* Set Contrast Control for BANK0 */
155 write_reg(par, 0x81);
156 write_reg(par, curves[0]);
161 static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
163 u16 *vmem16 = (u16 *)par->info->screen_buffer;
164 u8 *buf = par->txbuf.buf;
168 for (x = 0; x < par->info->var.xres; x++) {
169 for (y = 0; y < par->info->var.yres / 8; y++) {
171 for (i = 0; i < 8; i++)
172 *buf |= (vmem16[(y * 8 + i) *
173 par->info->var.xres + x] ?
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 /
185 dev_err(par->info->device, "write failed and returned: %d\n",
190 static struct fbtft_display display = {
194 .txbuflen = WIDTH * HEIGHT / 8,
199 .write_vmem = write_vmem,
200 .init_display = init_display,
201 .set_addr_win = set_addr_win,
203 .set_gamma = set_gamma,
207 FBTFT_REGISTER_DRIVER(DRVNAME, "solomon,ssd1305", &display);
209 MODULE_ALIAS("spi:" DRVNAME);
210 MODULE_ALIAS("platform:" DRVNAME);
211 MODULE_ALIAS("spi:ssd1305");
212 MODULE_ALIAS("platform:ssd1305");
214 MODULE_DESCRIPTION("SSD1305 OLED Driver");
215 MODULE_AUTHOR("Alexey Mednyy");
216 MODULE_LICENSE("GPL");