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) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *    Filename: cfag12864b.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *     Version: 0.1.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Description: cfag12864b LCD driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *     Depends: ks0108
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *      Author: Copyright (C) Miguel Ojeda Sandonis
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *        Date: 2006-10-31
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/cdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/ks0108.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/cfag12864b.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define CFAG12864B_NAME "cfag12864b"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * Module Parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) static unsigned int cfag12864b_rate = CONFIG_CFAG12864B_RATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) module_param(cfag12864b_rate, uint, S_IRUGO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) MODULE_PARM_DESC(cfag12864b_rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	"Refresh rate (hertz)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) unsigned int cfag12864b_getrate(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	return cfag12864b_rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * cfag12864b Commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  *	E = Enable signal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  *		Every time E switch from low to high,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  *		cfag12864b/ks0108 reads the command/data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  *	CS1 = First ks0108controller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  *		If high, the first ks0108 controller receives commands/data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  *	CS2 = Second ks0108 controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  *		If high, the second ks0108 controller receives commands/data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  *	DI = Data/Instruction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  *		If low, cfag12864b will expect commands.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  *		If high, cfag12864b will expect data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) #define bit(n) (((unsigned char)1)<<(n))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) #define CFAG12864B_BIT_E	(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) #define CFAG12864B_BIT_CS1	(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) #define CFAG12864B_BIT_CS2	(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) #define CFAG12864B_BIT_DI	(3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) static unsigned char cfag12864b_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) static void cfag12864b_set(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	ks0108_writecontrol(cfag12864b_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) static void cfag12864b_setbit(unsigned char state, unsigned char n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	if (state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		cfag12864b_state |= bit(n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		cfag12864b_state &= ~bit(n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) static void cfag12864b_e(unsigned char state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	cfag12864b_setbit(state, CFAG12864B_BIT_E);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	cfag12864b_set();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) static void cfag12864b_cs1(unsigned char state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	cfag12864b_setbit(state, CFAG12864B_BIT_CS1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) static void cfag12864b_cs2(unsigned char state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	cfag12864b_setbit(state, CFAG12864B_BIT_CS2);
^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 void cfag12864b_di(unsigned char state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	cfag12864b_setbit(state, CFAG12864B_BIT_DI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static void cfag12864b_setcontrollers(unsigned char first,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	unsigned char second)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (first)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		cfag12864b_cs1(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		cfag12864b_cs1(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	if (second)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		cfag12864b_cs2(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		cfag12864b_cs2(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static void cfag12864b_controller(unsigned char which)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	if (which == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		cfag12864b_setcontrollers(1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	else if (which == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		cfag12864b_setcontrollers(0, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static void cfag12864b_displaystate(unsigned char state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	cfag12864b_di(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	cfag12864b_e(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	ks0108_displaystate(state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	cfag12864b_e(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) static void cfag12864b_address(unsigned char address)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	cfag12864b_di(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	cfag12864b_e(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	ks0108_address(address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	cfag12864b_e(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) static void cfag12864b_page(unsigned char page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	cfag12864b_di(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	cfag12864b_e(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	ks0108_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	cfag12864b_e(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static void cfag12864b_startline(unsigned char startline)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	cfag12864b_di(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	cfag12864b_e(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	ks0108_startline(startline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	cfag12864b_e(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static void cfag12864b_writebyte(unsigned char byte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	cfag12864b_di(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	cfag12864b_e(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	ks0108_writedata(byte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	cfag12864b_e(0);
^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) static void cfag12864b_nop(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	cfag12864b_startline(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)  * cfag12864b Internal Commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) static void cfag12864b_on(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	cfag12864b_setcontrollers(1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	cfag12864b_displaystate(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) static void cfag12864b_off(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	cfag12864b_setcontrollers(1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	cfag12864b_displaystate(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static void cfag12864b_clear(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	unsigned char i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	cfag12864b_setcontrollers(1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	for (i = 0; i < CFAG12864B_PAGES; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		cfag12864b_page(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		cfag12864b_address(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		for (j = 0; j < CFAG12864B_ADDRESSES; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 			cfag12864b_writebyte(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)  * Update work
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) unsigned char *cfag12864b_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static unsigned char *cfag12864b_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static DEFINE_MUTEX(cfag12864b_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) static unsigned char cfag12864b_updating;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) static void cfag12864b_update(struct work_struct *delayed_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) static struct workqueue_struct *cfag12864b_workqueue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) static DECLARE_DELAYED_WORK(cfag12864b_work, cfag12864b_update);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) static void cfag12864b_queue(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	queue_delayed_work(cfag12864b_workqueue, &cfag12864b_work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		HZ / cfag12864b_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) unsigned char cfag12864b_enable(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	unsigned char ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	mutex_lock(&cfag12864b_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	if (!cfag12864b_updating) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		cfag12864b_updating = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		cfag12864b_queue();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	mutex_unlock(&cfag12864b_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) void cfag12864b_disable(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	mutex_lock(&cfag12864b_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	if (cfag12864b_updating) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		cfag12864b_updating = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		cancel_delayed_work(&cfag12864b_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		flush_workqueue(cfag12864b_workqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	mutex_unlock(&cfag12864b_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) unsigned char cfag12864b_isenabled(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	return cfag12864b_updating;
^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) static void cfag12864b_update(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	unsigned char c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	unsigned short i, j, k, b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	if (memcmp(cfag12864b_cache, cfag12864b_buffer, CFAG12864B_SIZE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		for (i = 0; i < CFAG12864B_CONTROLLERS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 			cfag12864b_controller(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 			cfag12864b_nop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 			for (j = 0; j < CFAG12864B_PAGES; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 				cfag12864b_page(j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 				cfag12864b_nop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 				cfag12864b_address(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 				cfag12864b_nop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 				for (k = 0; k < CFAG12864B_ADDRESSES; k++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 					for (c = 0, b = 0; b < 8; b++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 						if (cfag12864b_buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 							[i * CFAG12864B_ADDRESSES / 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 							+ k / 8 + (j * 8 + b) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 							CFAG12864B_WIDTH / 8]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 							& bit(k % 8))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 							c |= bit(b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 					cfag12864b_writebyte(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		memcpy(cfag12864b_cache, cfag12864b_buffer, CFAG12864B_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	if (cfag12864b_updating)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		cfag12864b_queue();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)  * cfag12864b Exported Symbols
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) EXPORT_SYMBOL_GPL(cfag12864b_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) EXPORT_SYMBOL_GPL(cfag12864b_getrate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) EXPORT_SYMBOL_GPL(cfag12864b_enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) EXPORT_SYMBOL_GPL(cfag12864b_disable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) EXPORT_SYMBOL_GPL(cfag12864b_isenabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)  * Is the module inited?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) static unsigned char cfag12864b_inited;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) unsigned char cfag12864b_isinited(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	return cfag12864b_inited;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) EXPORT_SYMBOL_GPL(cfag12864b_isinited);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)  * Module Init & Exit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) static int __init cfag12864b_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	int ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	/* ks0108_init() must be called first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	if (!ks0108_isinited()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		printk(KERN_ERR CFAG12864B_NAME ": ERROR: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 			"ks0108 is not initialized\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		goto none;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	BUILD_BUG_ON(PAGE_SIZE < CFAG12864B_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	cfag12864b_buffer = (unsigned char *) get_zeroed_page(GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	if (cfag12864b_buffer == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		printk(KERN_ERR CFAG12864B_NAME ": ERROR: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 			"can't get a free page\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		goto none;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	cfag12864b_cache = kmalloc(CFAG12864B_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 				   GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	if (cfag12864b_cache == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		printk(KERN_ERR CFAG12864B_NAME ": ERROR: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 			"can't alloc cache buffer (%i bytes)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 			CFAG12864B_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		goto bufferalloced;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	cfag12864b_workqueue = create_singlethread_workqueue(CFAG12864B_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	if (cfag12864b_workqueue == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		goto cachealloced;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	cfag12864b_clear();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	cfag12864b_on();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	cfag12864b_inited = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) cachealloced:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	kfree(cfag12864b_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) bufferalloced:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	free_page((unsigned long) cfag12864b_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) none:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) static void __exit cfag12864b_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	cfag12864b_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	cfag12864b_off();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	destroy_workqueue(cfag12864b_workqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	kfree(cfag12864b_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	free_page((unsigned long) cfag12864b_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) module_init(cfag12864b_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) module_exit(cfag12864b_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) MODULE_AUTHOR("Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) MODULE_DESCRIPTION("cfag12864b LCD driver");