#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/gpio/consumer.h>
#include <linux/delay.h>
#include "fbtft.h"
#define DRVNAME "fb_ssd1305"
#define WIDTH 128
#define HEIGHT 64
static int init_display(struct fbtft_par *par)
{
par->fbtftops.reset(par);
if (par->gamma.curves[0] == 0) {
mutex_lock(&par->gamma.lock);
if (par->info->var.yres == 64)
par->gamma.curves[0] = 0xCF;
else
par->gamma.curves[0] = 0x8F;
mutex_unlock(&par->gamma.lock);
}
write_reg(par, 0xAE);
write_reg(par, 0xD5);
write_reg(par, 0x80);
write_reg(par, 0xA8);
if (par->info->var.yres == 64)
write_reg(par, 0x3F);
else
write_reg(par, 0x1F);
write_reg(par, 0xD3);
write_reg(par, 0x0);
write_reg(par, 0x40 | 0x0);
write_reg(par, 0x8D);
write_reg(par, 0x14);
write_reg(par, 0x20);
write_reg(par, 0x01);
write_reg(par, 0xA0 | ((par->info->var.rotate == 180) ? 0x0 : 0x1));
write_reg(par, ((par->info->var.rotate == 180) ? 0xC8 : 0xC0));
write_reg(par, 0xDA);
if (par->info->var.yres == 64) {
write_reg(par, 0x12);
} else {
write_reg(par, 0x02);
}
write_reg(par, 0xD9);
write_reg(par, 0xF1);
write_reg(par, 0xA4);
write_reg(par, 0xA6);
write_reg(par, 0xAF);
return 0;
}
static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
{
write_reg(par, 0x00 | ((par->info->var.rotate == 180) ? 0x0 : 0x4));
write_reg(par, 0x10 | 0x0);
write_reg(par, 0x40 | 0x0);
}
static int blank(struct fbtft_par *par, bool on)
{
if (on)
write_reg(par, 0xAE);
else
write_reg(par, 0xAF);
return 0;
}
static int set_gamma(struct fbtft_par *par, u32 *curves)
{
curves[0] &= 0xFF;
write_reg(par, 0x81);
write_reg(par, curves[0]);
return 0;
}
static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
{
u16 *vmem16 = (u16 *)par->info->screen_buffer;
u8 *buf = par->txbuf.buf;
int x, y, i;
int ret;
for (x = 0; x < par->info->var.xres; x++) {
for (y = 0; y < par->info->var.yres / 8; y++) {
*buf = 0x00;
for (i = 0; i < 8; i++)
*buf |= (vmem16[(y * 8 + i) *
par->info->var.xres + x] ?
1 : 0) << i;
buf++;
}
}
gpiod_set_value(par->gpio.dc, 1);
ret = par->fbtftops.write(par, par->txbuf.buf,
par->info->var.xres * par->info->var.yres /
8);
if (ret < 0)
dev_err(par->info->device, "write failed and returned: %d\n",
ret);
return ret;
}
static struct fbtft_display display = {
.regwidth = 8,
.width = WIDTH,
.height = HEIGHT,
.txbuflen = WIDTH * HEIGHT / 8,
.gamma_num = 1,
.gamma_len = 1,
.gamma = "00",
.fbtftops = {
.write_vmem = write_vmem,
.init_display = init_display,
.set_addr_win = set_addr_win,
.blank = blank,
.set_gamma = set_gamma,
},
};
FBTFT_REGISTER_DRIVER(DRVNAME, "solomon,ssd1305", &display);
MODULE_ALIAS("spi:" DRVNAME);
MODULE_ALIAS("platform:" DRVNAME);
MODULE_ALIAS("spi:ssd1305");
MODULE_ALIAS("platform:ssd1305");
MODULE_DESCRIPTION("SSD1305 OLED Driver");
MODULE_AUTHOR("Alexey Mednyy");
MODULE_LICENSE("GPL"