Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * linux/drivers/video/metronomefb.c -- FB driver for Metronome controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2008, Jaya Kumar
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * License. See the file COPYING in the main directory of this archive for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * Layout is based on skeletonfb.c by James Simmons and Geert Uytterhoeven.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * This work was made possible by help and equipment support from E-Ink
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * Corporation. https://www.eink.com/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * This driver is written to be used with the Metronome display controller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * It is intended to be architecture independent. A board specific driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * must be used to perform all the physical IO interactions. An example
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * is provided as am200epd.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/fb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <linux/firmware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <linux/dma-mapping.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include <video/metronomefb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #include <asm/unaligned.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) /* Display specific information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define DPY_W 832
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define DPY_H 622
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) static int user_wfm_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) /* frame differs from image. frame includes non-visible pixels */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) struct epd_frame {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	int fw; /* frame width */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	int fh; /* frame height */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	u16 config[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	int wfm_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) static struct epd_frame epd_frame_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		.fw = 832,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		.fh = 622,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		.config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 			15 /* sdlew */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 			| 2 << 8 /* sdosz */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 			| 0 << 11 /* sdor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 			| 0 << 12 /* sdces */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 			| 0 << 15, /* sdcer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 			42 /* gdspl */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 			| 1 << 8 /* gdr1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 			| 1 << 9 /* sdshr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 			| 0 << 15, /* gdspp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 			18 /* gdspw */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 			| 0 << 15, /* dispc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 			599 /* vdlc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 			| 0 << 11 /* dsi */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 			| 0 << 12, /* dsic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		.wfm_size = 47001,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		.fw = 1088,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		.fh = 791,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		.config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			0x0104,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			0x031f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			0x0088,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			0x02ff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		.wfm_size = 46770,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		.fw = 1200,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		.fh = 842,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		.config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			0x0101,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			0x030e,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			0x0012,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			0x0280,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		.wfm_size = 46770,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static struct fb_fix_screeninfo metronomefb_fix = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	.id =		"metronomefb",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	.type =		FB_TYPE_PACKED_PIXELS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	.visual =	FB_VISUAL_STATIC_PSEUDOCOLOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	.xpanstep =	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	.ypanstep =	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	.ywrapstep =	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	.line_length =	DPY_W,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	.accel =	FB_ACCEL_NONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static struct fb_var_screeninfo metronomefb_var = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	.xres		= DPY_W,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	.yres		= DPY_H,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	.xres_virtual	= DPY_W,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	.yres_virtual	= DPY_H,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	.bits_per_pixel	= 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	.grayscale	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	.nonstd		= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	.red =		{ 4, 3, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	.green =	{ 0, 0, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	.blue =		{ 0, 0, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	.transp =	{ 0, 0, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /* the waveform structure that is coming from userspace firmware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct waveform_hdr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	u8 stuff[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	u8 wmta[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	u8 fvsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	u8 luts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	u8 mc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	u8 trc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	u8 stuff3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	u8 endb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	u8 swtb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	u8 stuff2a[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	u8 stuff2b[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	u8 wfm_cs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) } __attribute__ ((packed));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) /* main metronomefb functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static u8 calc_cksum(int start, int end, u8 *mem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	u8 tmp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	for (i = start; i < end; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		tmp += mem[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	return tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static u16 calc_img_cksum(u16 *start, int length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	u16 tmp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	while (length--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		tmp += *start++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	return tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) /* here we decode the incoming waveform file and populate metromem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) static int load_waveform(u8 *mem, size_t size, int m, int t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			 struct metronomefb_par *par)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	int tta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	int wmta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	int trn = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	unsigned char v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	u8 cksum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	int cksum_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	int wfm_idx, owfm_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	int mem_idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	struct waveform_hdr *wfm_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	u8 *metromem = par->metromem_wfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	struct device *dev = par->info->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	if (user_wfm_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		epd_frame_table[par->dt].wfm_size = user_wfm_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	if (size != epd_frame_table[par->dt].wfm_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		dev_err(dev, "Error: unexpected size %zd != %d\n", size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 					epd_frame_table[par->dt].wfm_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	wfm_hdr = (struct waveform_hdr *) mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	if (wfm_hdr->fvsn != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		dev_err(dev, "Error: bad fvsn %x\n", wfm_hdr->fvsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	if (wfm_hdr->luts != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		dev_err(dev, "Error: bad luts %x\n", wfm_hdr->luts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	cksum = calc_cksum(32, 47, mem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	if (cksum != wfm_hdr->wfm_cs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		dev_err(dev, "Error: bad cksum %x != %x\n", cksum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 					wfm_hdr->wfm_cs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	wfm_hdr->mc += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	wfm_hdr->trc += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	for (i = 0; i < 5; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		if (*(wfm_hdr->stuff2a + i) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 			dev_err(dev, "Error: unexpected value in padding\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	/* calculating trn. trn is something used to index into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	the waveform. presumably selecting the right one for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	desired temperature. it works out the offset of the first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	v that exceeds the specified temperature */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	if ((sizeof(*wfm_hdr) + wfm_hdr->trc) > size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	for (i = sizeof(*wfm_hdr); i <= sizeof(*wfm_hdr) + wfm_hdr->trc; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		if (mem[i] > t) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			trn = i - sizeof(*wfm_hdr) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	/* check temperature range table checksum */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	cksum_idx = sizeof(*wfm_hdr) + wfm_hdr->trc + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	if (cksum_idx >= size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	cksum = calc_cksum(sizeof(*wfm_hdr), cksum_idx, mem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	if (cksum != mem[cksum_idx]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		dev_err(dev, "Error: bad temperature range table cksum"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 				" %x != %x\n", cksum, mem[cksum_idx]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	/* check waveform mode table address checksum */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	wmta = get_unaligned_le32(wfm_hdr->wmta) & 0x00FFFFFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	cksum_idx = wmta + m*4 + 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	if (cksum_idx >= size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	cksum = calc_cksum(cksum_idx - 3, cksum_idx, mem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	if (cksum != mem[cksum_idx]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		dev_err(dev, "Error: bad mode table address cksum"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 				" %x != %x\n", cksum, mem[cksum_idx]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	/* check waveform temperature table address checksum */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	tta = get_unaligned_le32(mem + wmta + m * 4) & 0x00FFFFFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	cksum_idx = tta + trn*4 + 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	if (cksum_idx >= size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	cksum = calc_cksum(cksum_idx - 3, cksum_idx, mem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	if (cksum != mem[cksum_idx]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		dev_err(dev, "Error: bad temperature table address cksum"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 			" %x != %x\n", cksum, mem[cksum_idx]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	/* here we do the real work of putting the waveform into the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	metromem buffer. this does runlength decoding of the waveform */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	wfm_idx = get_unaligned_le32(mem + tta + trn * 4) & 0x00FFFFFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	owfm_idx = wfm_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	if (wfm_idx >= size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	while (wfm_idx < size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		unsigned char rl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		v = mem[wfm_idx++];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		if (v == wfm_hdr->swtb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 			while (((v = mem[wfm_idx++]) != wfm_hdr->swtb) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 				wfm_idx < size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 				metromem[mem_idx++] = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		if (v == wfm_hdr->endb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		rl = mem[wfm_idx++];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		for (i = 0; i <= rl; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 			metromem[mem_idx++] = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	cksum_idx = wfm_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	if (cksum_idx >= size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	cksum = calc_cksum(owfm_idx, cksum_idx, mem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	if (cksum != mem[cksum_idx]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		dev_err(dev, "Error: bad waveform data cksum"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 				" %x != %x\n", cksum, mem[cksum_idx]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	par->frame_count = (mem_idx/64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) static int metronome_display_cmd(struct metronomefb_par *par)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	u16 cs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	u16 opcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	static u8 borderval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	/* setup display command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	we can't immediately set the opcode since the controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	will try parse the command before we've set it all up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	so we just set cs here and set the opcode at the end */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	if (par->metromem_cmd->opcode == 0xCC40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		opcode = cs = 0xCC41;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		opcode = cs = 0xCC40;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	/* set the args ( 2 bytes ) for display */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	par->metromem_cmd->args[i] = 	1 << 3 /* border update */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 					| ((borderval++ % 4) & 0x0F) << 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 					| (par->frame_count - 1) << 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	cs += par->metromem_cmd->args[i++];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	/* the rest are 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	memset((u8 *) (par->metromem_cmd->args + i), 0, (32-i)*2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	par->metromem_cmd->csum = cs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	par->metromem_cmd->opcode = opcode; /* display cmd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	return par->board->met_wait_event_intr(par);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) static int metronome_powerup_cmd(struct metronomefb_par *par)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	u16 cs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	/* setup power up command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	par->metromem_cmd->opcode = 0x1234; /* pwr up pseudo cmd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	cs = par->metromem_cmd->opcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	/* set pwr1,2,3 to 1024 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	for (i = 0; i < 3; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		par->metromem_cmd->args[i] = 1024;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		cs += par->metromem_cmd->args[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	/* the rest are 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	memset(&par->metromem_cmd->args[i], 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	       (ARRAY_SIZE(par->metromem_cmd->args) - i) * 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	par->metromem_cmd->csum = cs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	msleep(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	par->board->set_rst(par, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	msleep(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	par->board->set_stdby(par, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	return par->board->met_wait_event(par);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) static int metronome_config_cmd(struct metronomefb_par *par)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	/* setup config command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	we can't immediately set the opcode since the controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	will try parse the command before we've set it all up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	memcpy(par->metromem_cmd->args, epd_frame_table[par->dt].config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		sizeof(epd_frame_table[par->dt].config));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	/* the rest are 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	memset(&par->metromem_cmd->args[4], 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	       (ARRAY_SIZE(par->metromem_cmd->args) - 4) * 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	par->metromem_cmd->csum = 0xCC10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	par->metromem_cmd->csum += calc_img_cksum(par->metromem_cmd->args, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	par->metromem_cmd->opcode = 0xCC10; /* config cmd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	return par->board->met_wait_event(par);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) static int metronome_init_cmd(struct metronomefb_par *par)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	u16 cs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	/* setup init command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	we can't immediately set the opcode since the controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	will try parse the command before we've set it all up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	so we just set cs here and set the opcode at the end */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	cs = 0xCC20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	/* set the args ( 2 bytes ) for init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	par->metromem_cmd->args[i] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	cs += par->metromem_cmd->args[i++];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	/* the rest are 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	memset((u8 *) (par->metromem_cmd->args + i), 0, (32-i)*2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	par->metromem_cmd->csum = cs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	par->metromem_cmd->opcode = 0xCC20; /* init cmd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	return par->board->met_wait_event(par);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) static int metronome_init_regs(struct metronomefb_par *par)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	res = par->board->setup_io(par);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	res = metronome_powerup_cmd(par);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	res = metronome_config_cmd(par);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	res = metronome_init_cmd(par);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) static void metronomefb_dpy_update(struct metronomefb_par *par)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	int fbsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	u16 cksum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	unsigned char *buf = (unsigned char __force *)par->info->screen_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	fbsize = par->info->fix.smem_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	/* copy from vm to metromem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	memcpy(par->metromem_img, buf, fbsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	cksum = calc_img_cksum((u16 *) par->metromem_img, fbsize/2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	*((u16 *)(par->metromem_img) + fbsize/2) = cksum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	metronome_display_cmd(par);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) static u16 metronomefb_dpy_update_page(struct metronomefb_par *par, int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	u16 csum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	u16 *buf = (u16 __force *)(par->info->screen_base + index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	u16 *img = (u16 *)(par->metromem_img + index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	/* swizzle from vm to metromem and recalc cksum at the same time*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	for (i = 0; i < PAGE_SIZE/2; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 		*(img + i) = (buf[i] << 5) & 0xE0E0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 		csum += *(img + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	return csum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) /* this is called back from the deferred io workqueue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) static void metronomefb_dpy_deferred_io(struct fb_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 				struct list_head *pagelist)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	u16 cksum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	struct page *cur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	struct fb_deferred_io *fbdefio = info->fbdefio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	struct metronomefb_par *par = info->par;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	/* walk the written page list and swizzle the data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	list_for_each_entry(cur, &fbdefio->pagelist, lru) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		cksum = metronomefb_dpy_update_page(par,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 					(cur->index << PAGE_SHIFT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 		par->metromem_img_csum -= par->csum_table[cur->index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 		par->csum_table[cur->index] = cksum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 		par->metromem_img_csum += cksum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	metronome_display_cmd(par);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) static void metronomefb_fillrect(struct fb_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 				   const struct fb_fillrect *rect)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	struct metronomefb_par *par = info->par;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	sys_fillrect(info, rect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	metronomefb_dpy_update(par);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) static void metronomefb_copyarea(struct fb_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 				   const struct fb_copyarea *area)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	struct metronomefb_par *par = info->par;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	sys_copyarea(info, area);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	metronomefb_dpy_update(par);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) static void metronomefb_imageblit(struct fb_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 				const struct fb_image *image)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	struct metronomefb_par *par = info->par;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	sys_imageblit(info, image);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	metronomefb_dpy_update(par);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)  * this is the slow path from userspace. they can seek and write to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)  * the fb. it is based on fb_sys_write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) static ssize_t metronomefb_write(struct fb_info *info, const char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 				size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	struct metronomefb_par *par = info->par;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	unsigned long p = *ppos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	void *dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	unsigned long total_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	if (info->state != FBINFO_STATE_RUNNING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 		return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	total_size = info->fix.smem_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	if (p > total_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 		return -EFBIG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	if (count > total_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 		err = -EFBIG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 		count = total_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	if (count + p > total_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 		if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 			err = -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 		count = total_size - p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	dst = (void __force *)(info->screen_base + p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	if (copy_from_user(dst, buf, count))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 		err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	if  (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 		*ppos += count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	metronomefb_dpy_update(par);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	return (err) ? err : count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) static const struct fb_ops metronomefb_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	.fb_write	= metronomefb_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	.fb_fillrect	= metronomefb_fillrect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	.fb_copyarea	= metronomefb_copyarea,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	.fb_imageblit	= metronomefb_imageblit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) static struct fb_deferred_io metronomefb_defio = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	.delay		= HZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	.deferred_io	= metronomefb_dpy_deferred_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) static int metronomefb_probe(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	struct fb_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	struct metronome_board *board;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	int retval = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	int videomemorysize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	unsigned char *videomemory;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	struct metronomefb_par *par;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	const struct firmware *fw_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	int panel_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	int fw, fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	int epd_dt_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	/* pick up board specific routines */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 	board = dev->dev.platform_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	if (!board)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	/* try to count device specific driver, if can't, platform recalls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	if (!try_module_get(board->owner))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	info = framebuffer_alloc(sizeof(struct metronomefb_par), &dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 	if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 	/* we have two blocks of memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	info->screen_base which is vm, and is the fb used by apps.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	par->metromem which is physically contiguous memory and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 	contains the display controller commands, waveform,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	processed image data and padding. this is the data pulled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	by the device's LCD controller and pushed to Metronome.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	the metromem memory is allocated by the board driver and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 	is provided to us */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	panel_type = board->get_panel_type();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 	switch (panel_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 	case 6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 		epd_dt_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 	case 8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 		epd_dt_index = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	case 97:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 		epd_dt_index = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 		dev_err(&dev->dev, "Unexpected panel type. Defaulting to 6\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 		epd_dt_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	fw = epd_frame_table[epd_dt_index].fw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 	fh = epd_frame_table[epd_dt_index].fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 	/* we need to add a spare page because our csum caching scheme walks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 	 * to the end of the page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 	videomemorysize = PAGE_SIZE + (fw * fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 	videomemory = vzalloc(videomemorysize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 	if (!videomemory)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 		goto err_fb_rel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	info->screen_base = (char __force __iomem *)videomemory;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 	info->fbops = &metronomefb_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 	metronomefb_fix.line_length = fw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 	metronomefb_var.xres = fw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 	metronomefb_var.yres = fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	metronomefb_var.xres_virtual = fw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	metronomefb_var.yres_virtual = fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 	info->var = metronomefb_var;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	info->fix = metronomefb_fix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	info->fix.smem_len = videomemorysize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	par = info->par;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 	par->info = info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 	par->board = board;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 	par->dt = epd_dt_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 	init_waitqueue_head(&par->waitq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	/* this table caches per page csum values. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	par->csum_table = vmalloc(videomemorysize/PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	if (!par->csum_table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 		goto err_vfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 	/* the physical framebuffer that we use is setup by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	 * the platform device driver. It will provide us
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 	 * with cmd, wfm and image memory in a contiguous area. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 	retval = board->setup_fb(par);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 	if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 		dev_err(&dev->dev, "Failed to setup fb\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 		goto err_csum_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 	/* after this point we should have a framebuffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 	if ((!par->metromem_wfm) ||  (!par->metromem_img) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 		(!par->metromem_dma)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 		dev_err(&dev->dev, "fb access failure\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 		retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 		goto err_csum_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 	info->fix.smem_start = par->metromem_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 	/* load the waveform in. assume mode 3, temp 31 for now
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 		a) request the waveform file from userspace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 		b) process waveform and decode into metromem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 	retval = request_firmware(&fw_entry, "metronome.wbf", &dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 	if (retval < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 		dev_err(&dev->dev, "Failed to get waveform\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 		goto err_csum_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 	retval = load_waveform((u8 *) fw_entry->data, fw_entry->size, 3, 31,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 				par);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	release_firmware(fw_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 	if (retval < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 		dev_err(&dev->dev, "Failed processing waveform\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 		goto err_csum_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 	retval = board->setup_irq(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 		goto err_csum_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 	retval = metronome_init_regs(par);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 	if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 		goto err_free_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 	info->flags = FBINFO_FLAG_DEFAULT | FBINFO_VIRTFB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 	info->fbdefio = &metronomefb_defio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 	fb_deferred_io_init(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 	retval = fb_alloc_cmap(&info->cmap, 8, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 	if (retval < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 		dev_err(&dev->dev, "Failed to allocate colormap\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 		goto err_free_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 	/* set cmap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 	for (i = 0; i < 8; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 		info->cmap.red[i] = (((2*i)+1)*(0xFFFF))/16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 	memcpy(info->cmap.green, info->cmap.red, sizeof(u16)*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 	memcpy(info->cmap.blue, info->cmap.red, sizeof(u16)*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 	retval = register_framebuffer(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 	if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 		goto err_cmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 	platform_set_drvdata(dev, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 	dev_dbg(&dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 		"fb%d: Metronome frame buffer device, using %dK of video"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 		" memory\n", info->node, videomemorysize >> 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) err_cmap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 	fb_dealloc_cmap(&info->cmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) err_free_irq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 	board->cleanup(par);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) err_csum_table:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 	vfree(par->csum_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) err_vfree:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 	vfree(videomemory);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) err_fb_rel:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 	framebuffer_release(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 	module_put(board->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) static int metronomefb_remove(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 	struct fb_info *info = platform_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 	if (info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 		struct metronomefb_par *par = info->par;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 		unregister_framebuffer(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 		fb_deferred_io_cleanup(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 		fb_dealloc_cmap(&info->cmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) 		par->board->cleanup(par);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 		vfree(par->csum_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) 		vfree((void __force *)info->screen_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) 		module_put(par->board->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) 		dev_dbg(&dev->dev, "calling release\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) 		framebuffer_release(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) static struct platform_driver metronomefb_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) 	.probe	= metronomefb_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) 	.remove = metronomefb_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 	.driver	= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) 		.name	= "metronomefb",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) module_platform_driver(metronomefb_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) module_param(user_wfm_size, uint, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) MODULE_PARM_DESC(user_wfm_size, "Set custom waveform size");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) MODULE_DESCRIPTION("fbdev driver for Metronome controller");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) MODULE_AUTHOR("Jaya Kumar");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) MODULE_LICENSE("GPL");