staging: fbtft: core support
This commit adds the core fbtft framework from https://github.com/notro/fbtft. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> Signed-off-by: Noralf Tronnes <notro@tronnes.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Родитель
ab666bb2dc
Коммит
c296d5f995
|
@ -106,4 +106,6 @@ source "drivers/staging/unisys/Kconfig"
|
|||
|
||||
source "drivers/staging/clocking-wizard/Kconfig"
|
||||
|
||||
source "drivers/staging/fbtft/Kconfig"
|
||||
|
||||
endif # STAGING
|
||||
|
|
|
@ -45,3 +45,4 @@ obj-$(CONFIG_GS_FPGABOOT) += gs_fpgaboot/
|
|||
obj-$(CONFIG_CRYPTO_SKEIN) += skein/
|
||||
obj-$(CONFIG_UNISYSSPAR) += unisys/
|
||||
obj-$(CONFIG_COMMON_CLK_XLNX_CLKWZRD) += clocking-wizard/
|
||||
obj-$(CONFIG_FB_TFT) += fbtft/
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
menuconfig FB_TFT
|
||||
tristate "Support for small TFT LCD display modules"
|
||||
depends on FB && SPI && GPIOLIB
|
||||
select FB_SYS_FILLRECT
|
||||
select FB_SYS_COPYAREA
|
||||
select FB_SYS_IMAGEBLIT
|
||||
select FB_SYS_FOPS
|
||||
select FB_DEFERRED_IO
|
||||
select FB_BACKLIGHT
|
|
@ -0,0 +1,3 @@
|
|||
# Core module
|
||||
obj-$(CONFIG_FB_TFT) += fbtft.o
|
||||
fbtft-y += fbtft-core.o fbtft-sysfs.o fbtft-bus.o fbtft-io.o
|
|
@ -0,0 +1,32 @@
|
|||
FBTFT
|
||||
=========
|
||||
|
||||
Linux Framebuffer drivers for small TFT LCD display modules.
|
||||
The module 'fbtft' makes writing drivers for some of these displays very easy.
|
||||
|
||||
Development is done on a Raspberry Pi running the Raspbian "wheezy" distribution.
|
||||
|
||||
INSTALLATION
|
||||
Download kernel sources
|
||||
|
||||
From Linux 3.15
|
||||
cd drivers/video/fbdev/fbtft
|
||||
git clone https://github.com/notro/fbtft.git
|
||||
|
||||
Add to drivers/video/fbdev/Kconfig: source "drivers/video/fbdev/fbtft/Kconfig"
|
||||
Add to drivers/video/fbdev/Makefile: obj-y += fbtft/
|
||||
|
||||
Before Linux 3.15
|
||||
cd drivers/video
|
||||
git clone https://github.com/notro/fbtft.git
|
||||
|
||||
Add to drivers/video/Kconfig: source "drivers/video/fbtft/Kconfig"
|
||||
Add to drivers/video/Makefile: obj-y += fbtft/
|
||||
|
||||
Enable driver(s) in menuconfig and build the kernel
|
||||
|
||||
|
||||
See wiki for more information: https://github.com/notro/fbtft/wiki
|
||||
|
||||
|
||||
Source: https://github.com/notro/fbtft/
|
|
@ -0,0 +1,256 @@
|
|||
#include <linux/export.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/gpio.h>
|
||||
#include <linux/spi/spi.h>
|
||||
#include "fbtft.h"
|
||||
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* void (*write_reg)(struct fbtft_par *par, int len, ...);
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#define define_fbtft_write_reg(func, type, modifier) \
|
||||
void func(struct fbtft_par *par, int len, ...) \
|
||||
{ \
|
||||
va_list args; \
|
||||
int i, ret; \
|
||||
int offset = 0; \
|
||||
type *buf = (type *)par->buf; \
|
||||
\
|
||||
if (unlikely(par->debug & DEBUG_WRITE_REGISTER)) { \
|
||||
va_start(args, len); \
|
||||
for (i = 0; i < len; i++) { \
|
||||
buf[i] = (type)va_arg(args, unsigned int); \
|
||||
} \
|
||||
va_end(args); \
|
||||
fbtft_par_dbg_hex(DEBUG_WRITE_REGISTER, par, par->info->device, type, buf, len, "%s: ", __func__); \
|
||||
} \
|
||||
\
|
||||
va_start(args, len); \
|
||||
\
|
||||
if (par->startbyte) { \
|
||||
*(u8 *)par->buf = par->startbyte; \
|
||||
buf = (type *)(par->buf + 1); \
|
||||
offset = 1; \
|
||||
} \
|
||||
\
|
||||
*buf = modifier((type)va_arg(args, unsigned int)); \
|
||||
if (par->gpio.dc != -1) \
|
||||
gpio_set_value(par->gpio.dc, 0); \
|
||||
ret = par->fbtftops.write(par, par->buf, sizeof(type)+offset); \
|
||||
if (ret < 0) { \
|
||||
va_end(args); \
|
||||
dev_err(par->info->device, "%s: write() failed and returned %d\n", __func__, ret); \
|
||||
return; \
|
||||
} \
|
||||
len--; \
|
||||
\
|
||||
if (par->startbyte) \
|
||||
*(u8 *)par->buf = par->startbyte | 0x2; \
|
||||
\
|
||||
if (len) { \
|
||||
i = len; \
|
||||
while (i--) { \
|
||||
*buf++ = modifier((type)va_arg(args, unsigned int)); \
|
||||
} \
|
||||
if (par->gpio.dc != -1) \
|
||||
gpio_set_value(par->gpio.dc, 1); \
|
||||
ret = par->fbtftops.write(par, par->buf, len * (sizeof(type)+offset)); \
|
||||
if (ret < 0) { \
|
||||
va_end(args); \
|
||||
dev_err(par->info->device, "%s: write() failed and returned %d\n", __func__, ret); \
|
||||
return; \
|
||||
} \
|
||||
} \
|
||||
va_end(args); \
|
||||
} \
|
||||
EXPORT_SYMBOL(func);
|
||||
|
||||
define_fbtft_write_reg(fbtft_write_reg8_bus8, u8, )
|
||||
define_fbtft_write_reg(fbtft_write_reg16_bus8, u16, cpu_to_be16)
|
||||
define_fbtft_write_reg(fbtft_write_reg16_bus16, u16, )
|
||||
|
||||
void fbtft_write_reg8_bus9(struct fbtft_par *par, int len, ...)
|
||||
{
|
||||
va_list args;
|
||||
int i, ret;
|
||||
int pad = 0;
|
||||
u16 *buf = (u16 *)par->buf;
|
||||
|
||||
if (unlikely(par->debug & DEBUG_WRITE_REGISTER)) {
|
||||
va_start(args, len);
|
||||
for (i = 0; i < len; i++)
|
||||
*(((u8 *)buf) + i) = (u8)va_arg(args, unsigned int);
|
||||
va_end(args);
|
||||
fbtft_par_dbg_hex(DEBUG_WRITE_REGISTER, par,
|
||||
par->info->device, u8, buf, len, "%s: ", __func__);
|
||||
}
|
||||
if (len <= 0)
|
||||
return;
|
||||
|
||||
if (par->spi && (par->spi->bits_per_word == 8)) {
|
||||
/* we're emulating 9-bit, pad start of buffer with no-ops
|
||||
(assuming here that zero is a no-op) */
|
||||
pad = (len % 4) ? 4 - (len % 4) : 0;
|
||||
for (i = 0; i < pad; i++)
|
||||
*buf++ = 0x000;
|
||||
}
|
||||
|
||||
va_start(args, len);
|
||||
*buf++ = (u8)va_arg(args, unsigned int);
|
||||
i = len - 1;
|
||||
while (i--) {
|
||||
*buf = (u8)va_arg(args, unsigned int);
|
||||
*buf++ |= 0x100; /* dc=1 */
|
||||
}
|
||||
va_end(args);
|
||||
ret = par->fbtftops.write(par, par->buf, (len + pad) * sizeof(u16));
|
||||
if (ret < 0) {
|
||||
dev_err(par->info->device,
|
||||
"%s: write() failed and returned %d\n", __func__, ret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
EXPORT_SYMBOL(fbtft_write_reg8_bus9);
|
||||
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* int (*write_vmem)(struct fbtft_par *par);
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
/* 16 bit pixel over 8-bit databus */
|
||||
int fbtft_write_vmem16_bus8(struct fbtft_par *par, size_t offset, size_t len)
|
||||
{
|
||||
u16 *vmem16;
|
||||
u16 *txbuf16 = (u16 *)par->txbuf.buf;
|
||||
size_t remain;
|
||||
size_t to_copy;
|
||||
size_t tx_array_size;
|
||||
int i;
|
||||
int ret = 0;
|
||||
size_t startbyte_size = 0;
|
||||
|
||||
fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s(offset=%zu, len=%zu)\n",
|
||||
__func__, offset, len);
|
||||
|
||||
remain = len / 2;
|
||||
vmem16 = (u16 *)(par->info->screen_base + offset);
|
||||
|
||||
if (par->gpio.dc != -1)
|
||||
gpio_set_value(par->gpio.dc, 1);
|
||||
|
||||
/* non buffered write */
|
||||
if (!par->txbuf.buf)
|
||||
return par->fbtftops.write(par, vmem16, len);
|
||||
|
||||
/* buffered write */
|
||||
tx_array_size = par->txbuf.len / 2;
|
||||
|
||||
if (par->startbyte) {
|
||||
txbuf16 = (u16 *)(par->txbuf.buf + 1);
|
||||
tx_array_size -= 2;
|
||||
*(u8 *)(par->txbuf.buf) = par->startbyte | 0x2;
|
||||
startbyte_size = 1;
|
||||
}
|
||||
|
||||
while (remain) {
|
||||
to_copy = remain > tx_array_size ? tx_array_size : remain;
|
||||
dev_dbg(par->info->device, " to_copy=%zu, remain=%zu\n",
|
||||
to_copy, remain - to_copy);
|
||||
|
||||
for (i = 0; i < to_copy; i++)
|
||||
txbuf16[i] = cpu_to_be16(vmem16[i]);
|
||||
|
||||
vmem16 = vmem16 + to_copy;
|
||||
ret = par->fbtftops.write(par, par->txbuf.buf,
|
||||
startbyte_size + to_copy * 2);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
remain -= to_copy;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(fbtft_write_vmem16_bus8);
|
||||
|
||||
/* 16 bit pixel over 9-bit SPI bus: dc + high byte, dc + low byte */
|
||||
int fbtft_write_vmem16_bus9(struct fbtft_par *par, size_t offset, size_t len)
|
||||
{
|
||||
u8 *vmem8;
|
||||
u16 *txbuf16 = par->txbuf.buf;
|
||||
size_t remain;
|
||||
size_t to_copy;
|
||||
size_t tx_array_size;
|
||||
int i;
|
||||
int ret = 0;
|
||||
|
||||
fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s(offset=%zu, len=%zu)\n",
|
||||
__func__, offset, len);
|
||||
|
||||
if (!par->txbuf.buf) {
|
||||
dev_err(par->info->device, "%s: txbuf.buf is NULL\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
remain = len;
|
||||
vmem8 = par->info->screen_base + offset;
|
||||
|
||||
tx_array_size = par->txbuf.len / 2;
|
||||
|
||||
while (remain) {
|
||||
to_copy = remain > tx_array_size ? tx_array_size : remain;
|
||||
dev_dbg(par->info->device, " to_copy=%zu, remain=%zu\n",
|
||||
to_copy, remain - to_copy);
|
||||
|
||||
#ifdef __LITTLE_ENDIAN
|
||||
for (i = 0; i < to_copy; i += 2) {
|
||||
txbuf16[i] = 0x0100 | vmem8[i+1];
|
||||
txbuf16[i+1] = 0x0100 | vmem8[i];
|
||||
}
|
||||
#else
|
||||
for (i = 0; i < to_copy; i++)
|
||||
txbuf16[i] = 0x0100 | vmem8[i];
|
||||
#endif
|
||||
vmem8 = vmem8 + to_copy;
|
||||
ret = par->fbtftops.write(par, par->txbuf.buf, to_copy*2);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
remain -= to_copy;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(fbtft_write_vmem16_bus9);
|
||||
|
||||
int fbtft_write_vmem8_bus8(struct fbtft_par *par, size_t offset, size_t len)
|
||||
{
|
||||
dev_err(par->info->device, "%s: function not implemented\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
EXPORT_SYMBOL(fbtft_write_vmem8_bus8);
|
||||
|
||||
/* 16 bit pixel over 16-bit databus */
|
||||
int fbtft_write_vmem16_bus16(struct fbtft_par *par, size_t offset, size_t len)
|
||||
{
|
||||
u16 *vmem16;
|
||||
|
||||
fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s(offset=%zu, len=%zu)\n",
|
||||
__func__, offset, len);
|
||||
|
||||
vmem16 = (u16 *)(par->info->screen_base + offset);
|
||||
|
||||
if (par->gpio.dc != -1)
|
||||
gpio_set_value(par->gpio.dc, 1);
|
||||
|
||||
/* no need for buffered write with 16-bit bus */
|
||||
return par->fbtftops.write(par, vmem16, len);
|
||||
}
|
||||
EXPORT_SYMBOL(fbtft_write_vmem16_bus16);
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,409 @@
|
|||
#include <linux/export.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/gpio.h>
|
||||
#include <linux/spi/spi.h>
|
||||
#ifdef CONFIG_ARCH_BCM2708
|
||||
#include <mach/platform.h>
|
||||
#endif
|
||||
#include "fbtft.h"
|
||||
|
||||
int fbtft_write_spi(struct fbtft_par *par, void *buf, size_t len)
|
||||
{
|
||||
struct spi_transfer t = {
|
||||
.tx_buf = buf,
|
||||
.len = len,
|
||||
};
|
||||
struct spi_message m;
|
||||
|
||||
fbtft_par_dbg_hex(DEBUG_WRITE, par, par->info->device, u8, buf, len,
|
||||
"%s(len=%d): ", __func__, len);
|
||||
|
||||
if (!par->spi) {
|
||||
dev_err(par->info->device,
|
||||
"%s: par->spi is unexpectedly NULL\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
spi_message_init(&m);
|
||||
if (par->txbuf.dma && buf == par->txbuf.buf) {
|
||||
t.tx_dma = par->txbuf.dma;
|
||||
m.is_dma_mapped = 1;
|
||||
}
|
||||
spi_message_add_tail(&t, &m);
|
||||
return spi_sync(par->spi, &m);
|
||||
}
|
||||
EXPORT_SYMBOL(fbtft_write_spi);
|
||||
|
||||
/**
|
||||
* fbtft_write_spi_emulate_9() - write SPI emulating 9-bit
|
||||
* @par: Driver data
|
||||
* @buf: Buffer to write
|
||||
* @len: Length of buffer (must be divisible by 8)
|
||||
*
|
||||
* When 9-bit SPI is not available, this function can be used to emulate that.
|
||||
* par->extra must hold a transformation buffer used for transfer.
|
||||
*/
|
||||
int fbtft_write_spi_emulate_9(struct fbtft_par *par, void *buf, size_t len)
|
||||
{
|
||||
u16 *src = buf;
|
||||
u8 *dst = par->extra;
|
||||
size_t size = len / 2;
|
||||
size_t added = 0;
|
||||
int bits, i, j;
|
||||
u64 val, dc, tmp;
|
||||
|
||||
fbtft_par_dbg_hex(DEBUG_WRITE, par, par->info->device, u8, buf, len,
|
||||
"%s(len=%d): ", __func__, len);
|
||||
|
||||
if (!par->extra) {
|
||||
dev_err(par->info->device, "%s: error: par->extra is NULL\n",
|
||||
__func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
if ((len % 8) != 0) {
|
||||
dev_err(par->info->device,
|
||||
"%s: error: len=%d must be divisible by 8\n",
|
||||
__func__, len);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
for (i = 0; i < size; i += 8) {
|
||||
tmp = 0;
|
||||
bits = 63;
|
||||
for (j = 0; j < 7; j++) {
|
||||
dc = (*src & 0x0100) ? 1 : 0;
|
||||
val = *src & 0x00FF;
|
||||
tmp |= dc << bits;
|
||||
bits -= 8;
|
||||
tmp |= val << bits--;
|
||||
src++;
|
||||
}
|
||||
tmp |= ((*src & 0x0100) ? 1 : 0);
|
||||
*(u64 *)dst = cpu_to_be64(tmp);
|
||||
dst += 8;
|
||||
*dst++ = (u8)(*src++ & 0x00FF);
|
||||
added++;
|
||||
}
|
||||
|
||||
return spi_write(par->spi, par->extra, size + added);
|
||||
}
|
||||
EXPORT_SYMBOL(fbtft_write_spi_emulate_9);
|
||||
|
||||
int fbtft_read_spi(struct fbtft_par *par, void *buf, size_t len)
|
||||
{
|
||||
int ret;
|
||||
u8 txbuf[32] = { 0, };
|
||||
struct spi_transfer t = {
|
||||
.speed_hz = 2000000,
|
||||
.rx_buf = buf,
|
||||
.len = len,
|
||||
};
|
||||
struct spi_message m;
|
||||
|
||||
if (!par->spi) {
|
||||
dev_err(par->info->device,
|
||||
"%s: par->spi is unexpectedly NULL\n", __func__);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if (par->startbyte) {
|
||||
if (len > 32) {
|
||||
dev_err(par->info->device,
|
||||
"%s: len=%d can't be larger than 32 when using 'startbyte'\n",
|
||||
__func__, len);
|
||||
return -EINVAL;
|
||||
}
|
||||
txbuf[0] = par->startbyte | 0x3;
|
||||
t.tx_buf = txbuf;
|
||||
fbtft_par_dbg_hex(DEBUG_READ, par, par->info->device, u8,
|
||||
txbuf, len, "%s(len=%d) txbuf => ", __func__, len);
|
||||
}
|
||||
|
||||
spi_message_init(&m);
|
||||
spi_message_add_tail(&t, &m);
|
||||
ret = spi_sync(par->spi, &m);
|
||||
fbtft_par_dbg_hex(DEBUG_READ, par, par->info->device, u8, buf, len,
|
||||
"%s(len=%d) buf <= ", __func__, len);
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(fbtft_read_spi);
|
||||
|
||||
|
||||
#ifdef CONFIG_ARCH_BCM2708
|
||||
|
||||
/*
|
||||
* Raspberry Pi
|
||||
* - writing directly to the registers is 40-50% faster than
|
||||
* optimized use of gpiolib
|
||||
*/
|
||||
|
||||
#define GPIOSET(no, ishigh) \
|
||||
do { \
|
||||
if (ishigh) \
|
||||
set |= (1 << (no)); \
|
||||
else \
|
||||
reset |= (1 << (no)); \
|
||||
} while (0)
|
||||
|
||||
int fbtft_write_gpio8_wr(struct fbtft_par *par, void *buf, size_t len)
|
||||
{
|
||||
unsigned int set = 0;
|
||||
unsigned int reset = 0;
|
||||
u8 data;
|
||||
|
||||
fbtft_par_dbg_hex(DEBUG_WRITE, par, par->info->device, u8, buf, len,
|
||||
"%s(len=%d): ", __func__, len);
|
||||
|
||||
while (len--) {
|
||||
data = *(u8 *) buf;
|
||||
buf++;
|
||||
|
||||
/* Set data */
|
||||
GPIOSET(par->gpio.db[0], (data&0x01));
|
||||
GPIOSET(par->gpio.db[1], (data&0x02));
|
||||
GPIOSET(par->gpio.db[2], (data&0x04));
|
||||
GPIOSET(par->gpio.db[3], (data&0x08));
|
||||
GPIOSET(par->gpio.db[4], (data&0x10));
|
||||
GPIOSET(par->gpio.db[5], (data&0x20));
|
||||
GPIOSET(par->gpio.db[6], (data&0x40));
|
||||
GPIOSET(par->gpio.db[7], (data&0x80));
|
||||
writel(set, __io_address(GPIO_BASE+0x1C));
|
||||
writel(reset, __io_address(GPIO_BASE+0x28));
|
||||
|
||||
/* Pulse /WR low */
|
||||
writel((1<<par->gpio.wr), __io_address(GPIO_BASE+0x28));
|
||||
writel(0, __io_address(GPIO_BASE+0x28)); /* used as a delay */
|
||||
writel((1<<par->gpio.wr), __io_address(GPIO_BASE+0x1C));
|
||||
|
||||
set = 0;
|
||||
reset = 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(fbtft_write_gpio8_wr);
|
||||
|
||||
int fbtft_write_gpio16_wr(struct fbtft_par *par, void *buf, size_t len)
|
||||
{
|
||||
unsigned int set = 0;
|
||||
unsigned int reset = 0;
|
||||
u16 data;
|
||||
|
||||
fbtft_par_dbg_hex(DEBUG_WRITE, par, par->info->device, u8, buf, len,
|
||||
"%s(len=%d): ", __func__, len);
|
||||
|
||||
while (len) {
|
||||
len -= 2;
|
||||
data = *(u16 *) buf;
|
||||
buf += 2;
|
||||
|
||||
/* Start writing by pulling down /WR */
|
||||
gpio_set_value(par->gpio.wr, 0);
|
||||
|
||||
/* Set data */
|
||||
GPIOSET(par->gpio.db[0], (data&0x0001));
|
||||
GPIOSET(par->gpio.db[1], (data&0x0002));
|
||||
GPIOSET(par->gpio.db[2], (data&0x0004));
|
||||
GPIOSET(par->gpio.db[3], (data&0x0008));
|
||||
GPIOSET(par->gpio.db[4], (data&0x0010));
|
||||
GPIOSET(par->gpio.db[5], (data&0x0020));
|
||||
GPIOSET(par->gpio.db[6], (data&0x0040));
|
||||
GPIOSET(par->gpio.db[7], (data&0x0080));
|
||||
|
||||
GPIOSET(par->gpio.db[8], (data&0x0100));
|
||||
GPIOSET(par->gpio.db[9], (data&0x0200));
|
||||
GPIOSET(par->gpio.db[10], (data&0x0400));
|
||||
GPIOSET(par->gpio.db[11], (data&0x0800));
|
||||
GPIOSET(par->gpio.db[12], (data&0x1000));
|
||||
GPIOSET(par->gpio.db[13], (data&0x2000));
|
||||
GPIOSET(par->gpio.db[14], (data&0x4000));
|
||||
GPIOSET(par->gpio.db[15], (data&0x8000));
|
||||
|
||||
writel(set, __io_address(GPIO_BASE+0x1C));
|
||||
writel(reset, __io_address(GPIO_BASE+0x28));
|
||||
|
||||
/* Pullup /WR */
|
||||
gpio_set_value(par->gpio.wr, 1);
|
||||
|
||||
set = 0;
|
||||
reset = 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(fbtft_write_gpio16_wr);
|
||||
|
||||
int fbtft_write_gpio16_wr_latched(struct fbtft_par *par, void *buf, size_t len)
|
||||
{
|
||||
unsigned int set = 0;
|
||||
unsigned int reset = 0;
|
||||
u16 data;
|
||||
|
||||
fbtft_par_dbg_hex(DEBUG_WRITE, par, par->info->device, u8, buf, len,
|
||||
"%s(len=%d): ", __func__, len);
|
||||
|
||||
while (len) {
|
||||
len -= 2;
|
||||
data = *(u16 *) buf;
|
||||
buf += 2;
|
||||
|
||||
/* Start writing by pulling down /WR */
|
||||
gpio_set_value(par->gpio.wr, 0);
|
||||
|
||||
/* Low byte */
|
||||
GPIOSET(par->gpio.db[0], (data&0x0001));
|
||||
GPIOSET(par->gpio.db[1], (data&0x0002));
|
||||
GPIOSET(par->gpio.db[2], (data&0x0004));
|
||||
GPIOSET(par->gpio.db[3], (data&0x0008));
|
||||
GPIOSET(par->gpio.db[4], (data&0x0010));
|
||||
GPIOSET(par->gpio.db[5], (data&0x0020));
|
||||
GPIOSET(par->gpio.db[6], (data&0x0040));
|
||||
GPIOSET(par->gpio.db[7], (data&0x0080));
|
||||
writel(set, __io_address(GPIO_BASE+0x1C));
|
||||
writel(reset, __io_address(GPIO_BASE+0x28));
|
||||
|
||||
/* Pulse 'latch' high */
|
||||
gpio_set_value(par->gpio.latch, 1);
|
||||
gpio_set_value(par->gpio.latch, 0);
|
||||
|
||||
/* High byte */
|
||||
GPIOSET(par->gpio.db[0], (data&0x0100));
|
||||
GPIOSET(par->gpio.db[1], (data&0x0200));
|
||||
GPIOSET(par->gpio.db[2], (data&0x0400));
|
||||
GPIOSET(par->gpio.db[3], (data&0x0800));
|
||||
GPIOSET(par->gpio.db[4], (data&0x1000));
|
||||
GPIOSET(par->gpio.db[5], (data&0x2000));
|
||||
GPIOSET(par->gpio.db[6], (data&0x4000));
|
||||
GPIOSET(par->gpio.db[7], (data&0x8000));
|
||||
writel(set, __io_address(GPIO_BASE+0x1C));
|
||||
writel(reset, __io_address(GPIO_BASE+0x28));
|
||||
|
||||
/* Pullup /WR */
|
||||
gpio_set_value(par->gpio.wr, 1);
|
||||
|
||||
set = 0;
|
||||
reset = 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(fbtft_write_gpio16_wr_latched);
|
||||
|
||||
#undef GPIOSET
|
||||
|
||||
#else
|
||||
|
||||
/*
|
||||
* Optimized use of gpiolib is twice as fast as no optimization
|
||||
* only one driver can use the optimized version at a time
|
||||
*/
|
||||
int fbtft_write_gpio8_wr(struct fbtft_par *par, void *buf, size_t len)
|
||||
{
|
||||
u8 data;
|
||||
int i;
|
||||
#ifndef DO_NOT_OPTIMIZE_FBTFT_WRITE_GPIO
|
||||
static u8 prev_data;
|
||||
#endif
|
||||
|
||||
fbtft_par_dbg_hex(DEBUG_WRITE, par, par->info->device, u8, buf, len,
|
||||
"%s(len=%d): ", __func__, len);
|
||||
|
||||
while (len--) {
|
||||
data = *(u8 *) buf;
|
||||
|
||||
/* Start writing by pulling down /WR */
|
||||
gpio_set_value(par->gpio.wr, 0);
|
||||
|
||||
/* Set data */
|
||||
#ifndef DO_NOT_OPTIMIZE_FBTFT_WRITE_GPIO
|
||||
if (data == prev_data) {
|
||||
gpio_set_value(par->gpio.wr, 0); /* used as delay */
|
||||
} else {
|
||||
for (i = 0; i < 8; i++) {
|
||||
if ((data & 1) != (prev_data & 1))
|
||||
gpio_set_value(par->gpio.db[i],
|
||||
(data & 1));
|
||||
data >>= 1;
|
||||
prev_data >>= 1;
|
||||
}
|
||||
}
|
||||
#else
|
||||
for (i = 0; i < 8; i++) {
|
||||
gpio_set_value(par->gpio.db[i], (data & 1));
|
||||
data >>= 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Pullup /WR */
|
||||
gpio_set_value(par->gpio.wr, 1);
|
||||
|
||||
#ifndef DO_NOT_OPTIMIZE_FBTFT_WRITE_GPIO
|
||||
prev_data = *(u8 *) buf;
|
||||
#endif
|
||||
buf++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(fbtft_write_gpio8_wr);
|
||||
|
||||
int fbtft_write_gpio16_wr(struct fbtft_par *par, void *buf, size_t len)
|
||||
{
|
||||
u16 data;
|
||||
int i;
|
||||
#ifndef DO_NOT_OPTIMIZE_FBTFT_WRITE_GPIO
|
||||
static u16 prev_data;
|
||||
#endif
|
||||
|
||||
fbtft_par_dbg_hex(DEBUG_WRITE, par, par->info->device, u8, buf, len,
|
||||
"%s(len=%d): ", __func__, len);
|
||||
|
||||
while (len) {
|
||||
data = *(u16 *) buf;
|
||||
|
||||
/* Start writing by pulling down /WR */
|
||||
gpio_set_value(par->gpio.wr, 0);
|
||||
|
||||
/* Set data */
|
||||
#ifndef DO_NOT_OPTIMIZE_FBTFT_WRITE_GPIO
|
||||
if (data == prev_data) {
|
||||
gpio_set_value(par->gpio.wr, 0); /* used as delay */
|
||||
} else {
|
||||
for (i = 0; i < 16; i++) {
|
||||
if ((data & 1) != (prev_data & 1))
|
||||
gpio_set_value(par->gpio.db[i],
|
||||
(data & 1));
|
||||
data >>= 1;
|
||||
prev_data >>= 1;
|
||||
}
|
||||
}
|
||||
#else
|
||||
for (i = 0; i < 16; i++) {
|
||||
gpio_set_value(par->gpio.db[i], (data & 1));
|
||||
data >>= 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Pullup /WR */
|
||||
gpio_set_value(par->gpio.wr, 1);
|
||||
|
||||
#ifndef DO_NOT_OPTIMIZE_FBTFT_WRITE_GPIO
|
||||
prev_data = *(u16 *) buf;
|
||||
#endif
|
||||
buf += 2;
|
||||
len -= 2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(fbtft_write_gpio16_wr);
|
||||
|
||||
int fbtft_write_gpio16_wr_latched(struct fbtft_par *par, void *buf, size_t len)
|
||||
{
|
||||
dev_err(par->info->device, "%s: function not implemented\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
EXPORT_SYMBOL(fbtft_write_gpio16_wr_latched);
|
||||
|
||||
#endif /* CONFIG_ARCH_BCM2708 */
|
|
@ -0,0 +1,222 @@
|
|||
#include "fbtft.h"
|
||||
|
||||
|
||||
static int get_next_ulong(char **str_p, unsigned long *val, char *sep, int base)
|
||||
{
|
||||
char *p_val;
|
||||
int ret;
|
||||
|
||||
if (!str_p || !(*str_p))
|
||||
return -EINVAL;
|
||||
|
||||
p_val = strsep(str_p, sep);
|
||||
|
||||
if (!p_val)
|
||||
return -EINVAL;
|
||||
|
||||
ret = kstrtoul(p_val, base, val);
|
||||
if (ret)
|
||||
return -EINVAL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fbtft_gamma_parse_str(struct fbtft_par *par, unsigned long *curves,
|
||||
const char *str, int size)
|
||||
{
|
||||
char *str_p, *curve_p = NULL;
|
||||
char *tmp;
|
||||
unsigned long val = 0;
|
||||
int ret = 0;
|
||||
int curve_counter, value_counter;
|
||||
|
||||
fbtft_par_dbg(DEBUG_SYSFS, par, "%s() str=\n", __func__);
|
||||
|
||||
if (!str || !curves)
|
||||
return -EINVAL;
|
||||
|
||||
fbtft_par_dbg(DEBUG_SYSFS, par, "%s\n", str);
|
||||
|
||||
tmp = kmalloc(size+1, GFP_KERNEL);
|
||||
if (!tmp)
|
||||
return -ENOMEM;
|
||||
memcpy(tmp, str, size+1);
|
||||
|
||||
/* replace optional separators */
|
||||
str_p = tmp;
|
||||
while (*str_p) {
|
||||
if (*str_p == ',')
|
||||
*str_p = ' ';
|
||||
if (*str_p == ';')
|
||||
*str_p = '\n';
|
||||
str_p++;
|
||||
}
|
||||
|
||||
str_p = strim(tmp);
|
||||
|
||||
curve_counter = 0;
|
||||
while (str_p) {
|
||||
if (curve_counter == par->gamma.num_curves) {
|
||||
dev_err(par->info->device, "Gamma: Too many curves\n");
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
curve_p = strsep(&str_p, "\n");
|
||||
value_counter = 0;
|
||||
while (curve_p) {
|
||||
if (value_counter == par->gamma.num_values) {
|
||||
dev_err(par->info->device,
|
||||
"Gamma: Too many values\n");
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
ret = get_next_ulong(&curve_p, &val, " ", 16);
|
||||
if (ret)
|
||||
goto out;
|
||||
curves[curve_counter * par->gamma.num_values + value_counter] = val;
|
||||
value_counter++;
|
||||
}
|
||||
if (value_counter != par->gamma.num_values) {
|
||||
dev_err(par->info->device, "Gamma: Too few values\n");
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
curve_counter++;
|
||||
}
|
||||
if (curve_counter != par->gamma.num_curves) {
|
||||
dev_err(par->info->device, "Gamma: Too few curves\n");
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
out:
|
||||
kfree(tmp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
sprintf_gamma(struct fbtft_par *par, unsigned long *curves, char *buf)
|
||||
{
|
||||
ssize_t len = 0;
|
||||
unsigned int i, j;
|
||||
|
||||
mutex_lock(&par->gamma.lock);
|
||||
for (i = 0; i < par->gamma.num_curves; i++) {
|
||||
for (j = 0; j < par->gamma.num_values; j++)
|
||||
len += scnprintf(&buf[len], PAGE_SIZE,
|
||||
"%04lx ", curves[i*par->gamma.num_values + j]);
|
||||
buf[len-1] = '\n';
|
||||
}
|
||||
mutex_unlock(&par->gamma.lock);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
static ssize_t store_gamma_curve(struct device *device,
|
||||
struct device_attribute *attr,
|
||||
const char *buf, size_t count)
|
||||
{
|
||||
struct fb_info *fb_info = dev_get_drvdata(device);
|
||||
struct fbtft_par *par = fb_info->par;
|
||||
unsigned long tmp_curves[FBTFT_GAMMA_MAX_VALUES_TOTAL];
|
||||
int ret;
|
||||
|
||||
ret = fbtft_gamma_parse_str(par, tmp_curves, buf, count);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = par->fbtftops.set_gamma(par, tmp_curves);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
mutex_lock(&par->gamma.lock);
|
||||
memcpy(par->gamma.curves, tmp_curves,
|
||||
par->gamma.num_curves * par->gamma.num_values * sizeof(tmp_curves[0]));
|
||||
mutex_unlock(&par->gamma.lock);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static ssize_t show_gamma_curve(struct device *device,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
struct fb_info *fb_info = dev_get_drvdata(device);
|
||||
struct fbtft_par *par = fb_info->par;
|
||||
|
||||
return sprintf_gamma(par, par->gamma.curves, buf);
|
||||
}
|
||||
|
||||
static struct device_attribute gamma_device_attrs[] = {
|
||||
__ATTR(gamma, 0660, show_gamma_curve, store_gamma_curve),
|
||||
};
|
||||
|
||||
|
||||
void fbtft_expand_debug_value(unsigned long *debug)
|
||||
{
|
||||
switch (*debug & 0b111) {
|
||||
case 1:
|
||||
*debug |= DEBUG_LEVEL_1;
|
||||
break;
|
||||
case 2:
|
||||
*debug |= DEBUG_LEVEL_2;
|
||||
break;
|
||||
case 3:
|
||||
*debug |= DEBUG_LEVEL_3;
|
||||
break;
|
||||
case 4:
|
||||
*debug |= DEBUG_LEVEL_4;
|
||||
break;
|
||||
case 5:
|
||||
*debug |= DEBUG_LEVEL_5;
|
||||
break;
|
||||
case 6:
|
||||
*debug |= DEBUG_LEVEL_6;
|
||||
break;
|
||||
case 7:
|
||||
*debug = 0xFFFFFFFF;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static ssize_t store_debug(struct device *device,
|
||||
struct device_attribute *attr,
|
||||
const char *buf, size_t count)
|
||||
{
|
||||
struct fb_info *fb_info = dev_get_drvdata(device);
|
||||
struct fbtft_par *par = fb_info->par;
|
||||
int ret;
|
||||
|
||||
ret = kstrtoul(buf, 10, &par->debug);
|
||||
if (ret)
|
||||
return ret;
|
||||
fbtft_expand_debug_value(&par->debug);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static ssize_t show_debug(struct device *device,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
struct fb_info *fb_info = dev_get_drvdata(device);
|
||||
struct fbtft_par *par = fb_info->par;
|
||||
|
||||
return snprintf(buf, PAGE_SIZE, "%lu\n", par->debug);
|
||||
}
|
||||
|
||||
static struct device_attribute debug_device_attr = \
|
||||
__ATTR(debug, 0660, show_debug, store_debug);
|
||||
|
||||
|
||||
void fbtft_sysfs_init(struct fbtft_par *par)
|
||||
{
|
||||
device_create_file(par->info->dev, &debug_device_attr);
|
||||
if (par->gamma.curves && par->fbtftops.set_gamma)
|
||||
device_create_file(par->info->dev, &gamma_device_attrs[0]);
|
||||
}
|
||||
|
||||
void fbtft_sysfs_exit(struct fbtft_par *par)
|
||||
{
|
||||
device_remove_file(par->info->dev, &debug_device_attr);
|
||||
if (par->gamma.curves && par->fbtftops.set_gamma)
|
||||
device_remove_file(par->info->dev, &gamma_device_attrs[0]);
|
||||
}
|
|
@ -0,0 +1,447 @@
|
|||
/*
|
||||
* Copyright (C) 2013 Noralf Tronnes
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef __LINUX_FBTFT_H
|
||||
#define __LINUX_FBTFT_H
|
||||
|
||||
#include <linux/fb.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/spi/spi.h>
|
||||
#include <linux/platform_device.h>
|
||||
|
||||
|
||||
#define FBTFT_NOP 0x00
|
||||
#define FBTFT_SWRESET 0x01
|
||||
#define FBTFT_RDDID 0x04
|
||||
#define FBTFT_RDDST 0x09
|
||||
#define FBTFT_CASET 0x2A
|
||||
#define FBTFT_RASET 0x2B
|
||||
#define FBTFT_RAMWR 0x2C
|
||||
|
||||
#define FBTFT_ONBOARD_BACKLIGHT 2
|
||||
|
||||
#define FBTFT_GPIO_NO_MATCH 0xFFFF
|
||||
#define FBTFT_GPIO_NAME_SIZE 32
|
||||
#define FBTFT_MAX_INIT_SEQUENCE 512
|
||||
#define FBTFT_GAMMA_MAX_VALUES_TOTAL 128
|
||||
|
||||
#define FBTFT_OF_INIT_CMD BIT(24)
|
||||
#define FBTFT_OF_INIT_DELAY BIT(25)
|
||||
|
||||
/**
|
||||
* struct fbtft_gpio - Structure that holds one pinname to gpio mapping
|
||||
* @name: pinname (reset, dc, etc.)
|
||||
* @gpio: GPIO number
|
||||
*
|
||||
*/
|
||||
struct fbtft_gpio {
|
||||
char name[FBTFT_GPIO_NAME_SIZE];
|
||||
unsigned gpio;
|
||||
};
|
||||
|
||||
struct fbtft_par;
|
||||
|
||||
/**
|
||||
* struct fbtft_ops - FBTFT operations structure
|
||||
* @write: Writes to interface bus
|
||||
* @read: Reads from interface bus
|
||||
* @write_vmem: Writes video memory to display
|
||||
* @write_reg: Writes to controller register
|
||||
* @set_addr_win: Set the GRAM update window
|
||||
* @reset: Reset the LCD controller
|
||||
* @mkdirty: Marks display lines for update
|
||||
* @update_display: Updates the display
|
||||
* @init_display: Initializes the display
|
||||
* @blank: Blank the display (optional)
|
||||
* @request_gpios_match: Do pinname to gpio matching
|
||||
* @request_gpios: Request gpios from the kernel
|
||||
* @free_gpios: Free previously requested gpios
|
||||
* @verify_gpios: Verify that necessary gpios is present (optional)
|
||||
* @register_backlight: Used to register backlight device (optional)
|
||||
* @unregister_backlight: Unregister backlight device (optional)
|
||||
* @set_var: Configure LCD with values from variables like @rotate and @bgr
|
||||
* (optional)
|
||||
* @set_gamma: Set Gamma curve (optional)
|
||||
*
|
||||
* Most of these operations have default functions assigned to them in
|
||||
* fbtft_framebuffer_alloc()
|
||||
*/
|
||||
struct fbtft_ops {
|
||||
int (*write)(struct fbtft_par *par, void *buf, size_t len);
|
||||
int (*read)(struct fbtft_par *par, void *buf, size_t len);
|
||||
int (*write_vmem)(struct fbtft_par *par, size_t offset, size_t len);
|
||||
void (*write_register)(struct fbtft_par *par, int len, ...);
|
||||
|
||||
void (*set_addr_win)(struct fbtft_par *par,
|
||||
int xs, int ys, int xe, int ye);
|
||||
void (*reset)(struct fbtft_par *par);
|
||||
void (*mkdirty)(struct fb_info *info, int from, int to);
|
||||
void (*update_display)(struct fbtft_par *par,
|
||||
unsigned start_line, unsigned end_line);
|
||||
int (*init_display)(struct fbtft_par *par);
|
||||
int (*blank)(struct fbtft_par *par, bool on);
|
||||
|
||||
unsigned long (*request_gpios_match)(struct fbtft_par *par,
|
||||
const struct fbtft_gpio *gpio);
|
||||
int (*request_gpios)(struct fbtft_par *par);
|
||||
int (*verify_gpios)(struct fbtft_par *par);
|
||||
|
||||
void (*register_backlight)(struct fbtft_par *par);
|
||||
void (*unregister_backlight)(struct fbtft_par *par);
|
||||
|
||||
int (*set_var)(struct fbtft_par *par);
|
||||
int (*set_gamma)(struct fbtft_par *par, unsigned long *curves);
|
||||
};
|
||||
|
||||
/**
|
||||
* struct fbtft_display - Describes the display properties
|
||||
* @width: Width of display in pixels
|
||||
* @height: Height of display in pixels
|
||||
* @regwidth: LCD Controller Register width in bits
|
||||
* @buswidth: Display interface bus width in bits
|
||||
* @backlight: Backlight type.
|
||||
* @fbtftops: FBTFT operations provided by driver or device (platform_data)
|
||||
* @bpp: Bits per pixel
|
||||
* @fps: Frames per second
|
||||
* @txbuflen: Size of transmit buffer
|
||||
* @init_sequence: Pointer to LCD initialization array
|
||||
* @gamma: String representation of Gamma curve(s)
|
||||
* @gamma_num: Number of Gamma curves
|
||||
* @gamma_len: Number of values per Gamma curve
|
||||
* @debug: Initial debug value
|
||||
*
|
||||
* This structure is not stored by FBTFT except for init_sequence.
|
||||
*/
|
||||
struct fbtft_display {
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
unsigned regwidth;
|
||||
unsigned buswidth;
|
||||
unsigned backlight;
|
||||
struct fbtft_ops fbtftops;
|
||||
unsigned bpp;
|
||||
unsigned fps;
|
||||
int txbuflen;
|
||||
int *init_sequence;
|
||||
char *gamma;
|
||||
int gamma_num;
|
||||
int gamma_len;
|
||||
unsigned long debug;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct fbtft_platform_data - Passes display specific data to the driver
|
||||
* @display: Display properties
|
||||
* @gpios: Pointer to an array of piname to gpio mappings
|
||||
* @rotate: Display rotation angle
|
||||
* @bgr: LCD Controller BGR bit
|
||||
* @fps: Frames per second (this will go away, use @fps in @fbtft_display)
|
||||
* @txbuflen: Size of transmit buffer
|
||||
* @startbyte: When set, enables use of Startbyte in transfers
|
||||
* @gamma: String representation of Gamma curve(s)
|
||||
* @extra: A way to pass extra info
|
||||
*/
|
||||
struct fbtft_platform_data {
|
||||
struct fbtft_display display;
|
||||
const struct fbtft_gpio *gpios;
|
||||
unsigned rotate;
|
||||
bool bgr;
|
||||
unsigned fps;
|
||||
int txbuflen;
|
||||
u8 startbyte;
|
||||
char *gamma;
|
||||
void *extra;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct fbtft_par - Main FBTFT data structure
|
||||
*
|
||||
* This structure holds all relevant data to operate the display
|
||||
*
|
||||
* See sourcefile for documentation since nested structs is not
|
||||
* supported by kernel-doc.
|
||||
*
|
||||
*/
|
||||
/* @spi: Set if it is a SPI device
|
||||
* @pdev: Set if it is a platform device
|
||||
* @info: Pointer to framebuffer fb_info structure
|
||||
* @pdata: Pointer to platform data
|
||||
* @ssbuf: Not used
|
||||
* @pseudo_palette: Used by fb_set_colreg()
|
||||
* @txbuf.buf: Transmit buffer
|
||||
* @txbuf.len: Transmit buffer length
|
||||
* @buf: Small buffer used when writing init data over SPI
|
||||
* @startbyte: Used by some controllers when in SPI mode.
|
||||
* Format: 6 bit Device id + RS bit + RW bit
|
||||
* @fbtftops: FBTFT operations provided by driver or device (platform_data)
|
||||
* @dirty_lock: Protects dirty_lines_start and dirty_lines_end
|
||||
* @dirty_lines_start: Where to begin updating display
|
||||
* @dirty_lines_end: Where to end updating display
|
||||
* @gpio.reset: GPIO used to reset display
|
||||
* @gpio.dc: Data/Command signal, also known as RS
|
||||
* @gpio.rd: Read latching signal
|
||||
* @gpio.wr: Write latching signal
|
||||
* @gpio.latch: Bus latch signal, eg. 16->8 bit bus latch
|
||||
* @gpio.cs: LCD Chip Select with parallel interface bus
|
||||
* @gpio.db[16]: Parallel databus
|
||||
* @gpio.led[16]: Led control signals
|
||||
* @gpio.aux[16]: Auxillary signals, not used by core
|
||||
* @init_sequence: Pointer to LCD initialization array
|
||||
* @gamma.lock: Mutex for Gamma curve locking
|
||||
* @gamma.curves: Pointer to Gamma curve array
|
||||
* @gamma.num_values: Number of values per Gamma curve
|
||||
* @gamma.num_curves: Number of Gamma curves
|
||||
* @debug: Pointer to debug value
|
||||
* @current_debug:
|
||||
* @first_update_done: Used to only time the first display update
|
||||
* @update_time: Used to calculate 'fps' in debug output
|
||||
* @bgr: BGR mode/\n
|
||||
* @extra: Extra info needed by driver
|
||||
*/
|
||||
struct fbtft_par {
|
||||
struct spi_device *spi;
|
||||
struct platform_device *pdev;
|
||||
struct fb_info *info;
|
||||
struct fbtft_platform_data *pdata;
|
||||
u16 *ssbuf;
|
||||
u32 pseudo_palette[16];
|
||||
struct {
|
||||
void *buf;
|
||||
dma_addr_t dma;
|
||||
size_t len;
|
||||
} txbuf;
|
||||
u8 *buf;
|
||||
u8 startbyte;
|
||||
struct fbtft_ops fbtftops;
|
||||
spinlock_t dirty_lock;
|
||||
unsigned dirty_lines_start;
|
||||
unsigned dirty_lines_end;
|
||||
struct {
|
||||
int reset;
|
||||
int dc;
|
||||
int rd;
|
||||
int wr;
|
||||
int latch;
|
||||
int cs;
|
||||
int db[16];
|
||||
int led[16];
|
||||
int aux[16];
|
||||
} gpio;
|
||||
int *init_sequence;
|
||||
struct {
|
||||
struct mutex lock;
|
||||
unsigned long *curves;
|
||||
int num_values;
|
||||
int num_curves;
|
||||
} gamma;
|
||||
unsigned long debug;
|
||||
bool first_update_done;
|
||||
struct timespec update_time;
|
||||
bool bgr;
|
||||
void *extra;
|
||||
};
|
||||
|
||||
#define NUMARGS(...) (sizeof((int[]){__VA_ARGS__})/sizeof(int))
|
||||
|
||||
#define write_reg(par, ...) \
|
||||
do { \
|
||||
par->fbtftops.write_register(par, NUMARGS(__VA_ARGS__), __VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
/* fbtft-core.c */
|
||||
extern void fbtft_dbg_hex(const struct device *dev,
|
||||
int groupsize, void *buf, size_t len, const char *fmt, ...);
|
||||
extern struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display,
|
||||
struct device *dev);
|
||||
extern void fbtft_framebuffer_release(struct fb_info *info);
|
||||
extern int fbtft_register_framebuffer(struct fb_info *fb_info);
|
||||
extern int fbtft_unregister_framebuffer(struct fb_info *fb_info);
|
||||
extern void fbtft_register_backlight(struct fbtft_par *par);
|
||||
extern void fbtft_unregister_backlight(struct fbtft_par *par);
|
||||
extern int fbtft_init_display(struct fbtft_par *par);
|
||||
extern int fbtft_probe_common(struct fbtft_display *display,
|
||||
struct spi_device *sdev, struct platform_device *pdev);
|
||||
extern int fbtft_remove_common(struct device *dev, struct fb_info *info);
|
||||
|
||||
/* fbtft-io.c */
|
||||
extern int fbtft_write_spi(struct fbtft_par *par, void *buf, size_t len);
|
||||
extern int fbtft_write_spi_emulate_9(struct fbtft_par *par,
|
||||
void *buf, size_t len);
|
||||
extern int fbtft_read_spi(struct fbtft_par *par, void *buf, size_t len);
|
||||
extern int fbtft_write_gpio8_wr(struct fbtft_par *par, void *buf, size_t len);
|
||||
extern int fbtft_write_gpio16_wr(struct fbtft_par *par, void *buf, size_t len);
|
||||
extern int fbtft_write_gpio16_wr_latched(struct fbtft_par *par,
|
||||
void *buf, size_t len);
|
||||
|
||||
/* fbtft-bus.c */
|
||||
extern int fbtft_write_vmem8_bus8(struct fbtft_par *par, size_t offset, size_t len);
|
||||
extern int fbtft_write_vmem16_bus16(struct fbtft_par *par, size_t offset, size_t len);
|
||||
extern int fbtft_write_vmem16_bus8(struct fbtft_par *par, size_t offset, size_t len);
|
||||
extern int fbtft_write_vmem16_bus9(struct fbtft_par *par, size_t offset, size_t len);
|
||||
extern void fbtft_write_reg8_bus8(struct fbtft_par *par, int len, ...);
|
||||
extern void fbtft_write_reg8_bus9(struct fbtft_par *par, int len, ...);
|
||||
extern void fbtft_write_reg16_bus8(struct fbtft_par *par, int len, ...);
|
||||
extern void fbtft_write_reg16_bus16(struct fbtft_par *par, int len, ...);
|
||||
|
||||
|
||||
#define FBTFT_REGISTER_DRIVER(_name, _compatible, _display) \
|
||||
\
|
||||
static int fbtft_driver_probe_spi(struct spi_device *spi) \
|
||||
{ \
|
||||
return fbtft_probe_common(_display, spi, NULL); \
|
||||
} \
|
||||
\
|
||||
static int fbtft_driver_remove_spi(struct spi_device *spi) \
|
||||
{ \
|
||||
struct fb_info *info = spi_get_drvdata(spi); \
|
||||
\
|
||||
return fbtft_remove_common(&spi->dev, info); \
|
||||
} \
|
||||
\
|
||||
static int fbtft_driver_probe_pdev(struct platform_device *pdev) \
|
||||
{ \
|
||||
return fbtft_probe_common(_display, NULL, pdev); \
|
||||
} \
|
||||
\
|
||||
static int fbtft_driver_remove_pdev(struct platform_device *pdev) \
|
||||
{ \
|
||||
struct fb_info *info = platform_get_drvdata(pdev); \
|
||||
\
|
||||
return fbtft_remove_common(&pdev->dev, info); \
|
||||
} \
|
||||
\
|
||||
static const struct of_device_id dt_ids[] = { \
|
||||
{ .compatible = _compatible }, \
|
||||
{}, \
|
||||
}; \
|
||||
\
|
||||
MODULE_DEVICE_TABLE(of, dt_ids); \
|
||||
\
|
||||
\
|
||||
static struct spi_driver fbtft_driver_spi_driver = { \
|
||||
.driver = { \
|
||||
.name = _name, \
|
||||
.owner = THIS_MODULE, \
|
||||
.of_match_table = of_match_ptr(dt_ids), \
|
||||
}, \
|
||||
.probe = fbtft_driver_probe_spi, \
|
||||
.remove = fbtft_driver_remove_spi, \
|
||||
}; \
|
||||
\
|
||||
static struct platform_driver fbtft_driver_platform_driver = { \
|
||||
.driver = { \
|
||||
.name = _name, \
|
||||
.owner = THIS_MODULE, \
|
||||
.of_match_table = of_match_ptr(dt_ids), \
|
||||
}, \
|
||||
.probe = fbtft_driver_probe_pdev, \
|
||||
.remove = fbtft_driver_remove_pdev, \
|
||||
}; \
|
||||
\
|
||||
static int __init fbtft_driver_module_init(void) \
|
||||
{ \
|
||||
int ret; \
|
||||
\
|
||||
ret = spi_register_driver(&fbtft_driver_spi_driver); \
|
||||
if (ret < 0) \
|
||||
return ret; \
|
||||
return platform_driver_register(&fbtft_driver_platform_driver); \
|
||||
} \
|
||||
\
|
||||
static void __exit fbtft_driver_module_exit(void) \
|
||||
{ \
|
||||
spi_unregister_driver(&fbtft_driver_spi_driver); \
|
||||
platform_driver_unregister(&fbtft_driver_platform_driver); \
|
||||
} \
|
||||
\
|
||||
module_init(fbtft_driver_module_init); \
|
||||
module_exit(fbtft_driver_module_exit);
|
||||
|
||||
|
||||
/* Debug macros */
|
||||
|
||||
/* shorthand debug levels */
|
||||
#define DEBUG_LEVEL_1 DEBUG_REQUEST_GPIOS
|
||||
#define DEBUG_LEVEL_2 (DEBUG_LEVEL_1 | DEBUG_DRIVER_INIT_FUNCTIONS | DEBUG_TIME_FIRST_UPDATE)
|
||||
#define DEBUG_LEVEL_3 (DEBUG_LEVEL_2 | DEBUG_RESET | DEBUG_INIT_DISPLAY | DEBUG_BLANK | DEBUG_REQUEST_GPIOS | DEBUG_FREE_GPIOS | DEBUG_VERIFY_GPIOS | DEBUG_BACKLIGHT | DEBUG_SYSFS)
|
||||
#define DEBUG_LEVEL_4 (DEBUG_LEVEL_2 | DEBUG_FB_READ | DEBUG_FB_WRITE | DEBUG_FB_FILLRECT | DEBUG_FB_COPYAREA | DEBUG_FB_IMAGEBLIT | DEBUG_FB_BLANK)
|
||||
#define DEBUG_LEVEL_5 (DEBUG_LEVEL_3 | DEBUG_UPDATE_DISPLAY)
|
||||
#define DEBUG_LEVEL_6 (DEBUG_LEVEL_4 | DEBUG_LEVEL_5)
|
||||
#define DEBUG_LEVEL_7 0xFFFFFFFF
|
||||
|
||||
#define DEBUG_DRIVER_INIT_FUNCTIONS (1<<3)
|
||||
#define DEBUG_TIME_FIRST_UPDATE (1<<4)
|
||||
#define DEBUG_TIME_EACH_UPDATE (1<<5)
|
||||
#define DEBUG_DEFERRED_IO (1<<6)
|
||||
#define DEBUG_FBTFT_INIT_FUNCTIONS (1<<7)
|
||||
|
||||
/* fbops */
|
||||
#define DEBUG_FB_READ (1<<8)
|
||||
#define DEBUG_FB_WRITE (1<<9)
|
||||
#define DEBUG_FB_FILLRECT (1<<10)
|
||||
#define DEBUG_FB_COPYAREA (1<<11)
|
||||
#define DEBUG_FB_IMAGEBLIT (1<<12)
|
||||
#define DEBUG_FB_SETCOLREG (1<<13)
|
||||
#define DEBUG_FB_BLANK (1<<14)
|
||||
|
||||
#define DEBUG_SYSFS (1<<16)
|
||||
|
||||
/* fbtftops */
|
||||
#define DEBUG_BACKLIGHT (1<<17)
|
||||
#define DEBUG_READ (1<<18)
|
||||
#define DEBUG_WRITE (1<<19)
|
||||
#define DEBUG_WRITE_VMEM (1<<20)
|
||||
#define DEBUG_WRITE_REGISTER (1<<21)
|
||||
#define DEBUG_SET_ADDR_WIN (1<<22)
|
||||
#define DEBUG_RESET (1<<23)
|
||||
#define DEBUG_MKDIRTY (1<<24)
|
||||
#define DEBUG_UPDATE_DISPLAY (1<<25)
|
||||
#define DEBUG_INIT_DISPLAY (1<<26)
|
||||
#define DEBUG_BLANK (1<<27)
|
||||
#define DEBUG_REQUEST_GPIOS (1<<28)
|
||||
#define DEBUG_FREE_GPIOS (1<<29)
|
||||
#define DEBUG_REQUEST_GPIOS_MATCH (1<<30)
|
||||
#define DEBUG_VERIFY_GPIOS (1<<31)
|
||||
|
||||
|
||||
#define fbtft_init_dbg(dev, format, arg...) \
|
||||
do { \
|
||||
if (unlikely((dev)->platform_data && \
|
||||
(((struct fbtft_platform_data *)(dev)->platform_data)->display.debug & DEBUG_DRIVER_INIT_FUNCTIONS))) \
|
||||
dev_info(dev, format, ##arg); \
|
||||
} while (0)
|
||||
|
||||
#define fbtft_par_dbg(level, par, format, arg...) \
|
||||
do { \
|
||||
if (unlikely(par->debug & level)) \
|
||||
dev_info(par->info->device, format, ##arg); \
|
||||
} while (0)
|
||||
|
||||
#define fbtft_dev_dbg(level, par, dev, format, arg...) \
|
||||
do { \
|
||||
if (unlikely(par->debug & level)) \
|
||||
dev_info(dev, format, ##arg); \
|
||||
} while (0)
|
||||
|
||||
#define fbtft_par_dbg_hex(level, par, dev, type, buf, num, format, arg...) \
|
||||
do { \
|
||||
if (unlikely(par->debug & level)) \
|
||||
fbtft_dbg_hex(dev, sizeof(type), buf, num * sizeof(type), format, ##arg); \
|
||||
} while (0)
|
||||
|
||||
#endif /* __LINUX_FBTFT_H */
|
Загрузка…
Ссылка в новой задаче