/*
* linux/drivers/video/metronomefb.c -- FB driver for Metronome controller
*
* Copyright (C) 2008, Jaya Kumar
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file COPYING in the main directory of this archive for
* more details.
*
* Layout is based on skeletonfb.c by James Simmons and Geert Uytterhoeven.
*
* This work was made possible by help and equipment support from E-Ink
* Corporation. http://support.eink.com/community
*
* This driver is written to be used with the Metronome display controller.
* It was tested with an E-Ink 800x600 Vizplex EPD on a Gumstix Connex board
* using the Lyre interface board.
*
* General notes:
* - User must set metronomefb_enable=1 to enable it.
* - See Documentation/fb/metronomefb.txt for how metronome works.
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/string.h>
#include <linux/mm.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/fb.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/list.h>
#include <linux/firmware.h>
#include <linux/dma-mapping.h>
#include <linux/uaccess.h>
#include <linux/irq.h>
#include <asm/arch/pxa-regs.h>
#include <asm/unaligned.h>
#define DEBUG 1
#ifdef DEBUG
#define DPRINTK(f, a...) printk(KERN_DEBUG "%s: " f, __func__ , ## a)
#else
#define DPRINTK(f, a...)
#endif
/* Display specific information */
#define DPY_W 832
#define DPY_H 622
struct metromem_desc {
u32 mFDADR0;
u32 mFSADR0;
u32 mFIDR0;
u32 mLDCMD0;
};
struct metromem_cmd {
u16 opcode;
u16 args[((64-2)/2)];
u16 csum;
};
struct metronomefb_par {
unsigned char *metromem;
struct metromem_desc *metromem_desc;
struct metromem_cmd *metromem_cmd;
unsigned char *metromem_wfm;
unsigned char *metromem_img;
u16 *metromem_img_csum;
u16 *csum_table;
int metromemsize;
dma_addr_t metromem_dma;
dma_addr_t metromem_desc_dma;
struct fb_info *info;
wait_queue_head_t waitq;
u8 frame_count;
};
/* frame differs from image. frame includes non-visible pixels */
struct epd_frame {
int fw; /* frame width */
int fh; /* frame height */
};
static struct epd_frame epd_frame_table[] = {
{
.fw = 832,
.fh = 622
},
};
static struct fb_fix_screeninfo metronomefb_fix __devinitdata = {
.id = "metronomefb",
.type = FB_TYPE_PACKED_PIXELS,
.visual = FB_VISUAL_STATIC_PSEUDOCOLOR,
.xpanstep = 0,
.ypanstep = 0,
.ywrapstep = 0,
.line_length = DPY_W,
.accel = FB_ACCEL_NONE,
};
static struct fb_var_screeninfo metronomefb_var __devinitdata = {
.xres = DPY_W,
.yres = DPY_H,
.xres_virtual = DPY_W,
.yres_virtual = DPY_H,
.bits_per_pixel = 8,
.grayscale = 1,
.nonstd = 1,
.red = { 4, 3, 0 },
.green = { 0, 0, 0 },
.blue = { 0, 0, 0 },
.transp = { 0, 0, 0 },
};
static unsigned int metronomefb_enable;
struct waveform_hdr {
u8 stuff[32];
u8 wmta[3];
u8 fvsn;
u8 luts;
u8 mc;
u8 trc;
u8 stuff3;
u8 endb;
u8 swtb;
u8 stuff2a[2];
u8 stuff2b[3];
u8 wfm_cs;
} __attribute__ ((packed));
/* main metronomefb functions */
static u8 calc_cksum(int start, int end, u8 *mem)
{
u8 tmp = 0;
int i;
for (i = start; i < end; i++)
tmp += mem[i];
return tmp;
}
static u16 calc_img_cksum(u16 *start, int length)
{
u16 tmp = 0;
while (length--)
tmp += *start++;
return tmp;
}
/* here we decode the incoming waveform file and populate metromem */
#define EXP_WFORM_SIZE 47001
static int load_waveform(u8 *mem, size_t size, u8 *metromem, int m, int t,
u8 *frame_count)
{
int tta;
int wmta;
int trn = 0;
int i;
unsigned char v;
u8 cksum;
int cksum_idx;
int wfm_idx, owfm_idx;
int mem_idx = 0;
struct waveform_hdr *wfm_hdr;
if (size != EXP_WFORM_SIZE) {
printk(