#include <linux/module.h>
#include <linux/errno.h>
#include <linux/miscdevice.h>
#include <linux/fcntl.h>
#include <linux/semaphore.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/proc_fs.h>
#include <linux/workqueue.h>
#include <linux/gpio.h>
#include <linux/irq.h>
#include <asm/uaccess.h>
#include <asm/io.h>
#include "lcd.h"
#include <linux/sched.h>
#include <linux/kthread.h>
#include <linux/interrupt.h>
#include <linux/workqueue.h>
#define GPIO9_6 (9*8+6) //K1_P
#define GPIO9_7 (9*8+7) //K2_P
#define GPIO9_2 (9*8+2) //K3_P
#define GPIO9_3 (9*8+3) //K4_P
#define GPIO9_1 (9*8+1) //K5_P
#define GPIO4_1 (4*8+1) //LCD_RES
#define GPIO4_2 (4*8+2) //LCD_SCL
#define GPIO4_3 (4*8+3) //LCD_DATA
#define GPIO4_4 (4*8+4) //LCD_A0
#define GPIO4_5 (4*8+5) //LCD_CS
static DEFINE_SEMAPHORE(gpio_sem);
static DECLARE_WAIT_QUEUE_HEAD(key_waitq);
static unsigned int LCD_CS = GPIO4_5;
static unsigned int LCD_SCL = GPIO4_2;
static unsigned int LCD_DATA = GPIO4_3;
static unsigned int LCD_A0 = GPIO4_4;
static unsigned int LCD_RES = GPIO4_1;
static unsigned int lcd_gpio_array[] = {GPIO4_1,GPIO4_2,GPIO4_3,GPIO4_4,GPIO4_5 };
static unsigned char g_page = 0;
static unsigned char g_column = 0;
static unsigned char lcd_pix_buff[8*132] = {0 };
static unsigned char lcd_pix_buff_old[8*132] = {0 };
static struct task_struct *lcdflash_thread = NULL;
struct key_desc{
unsigned int gpio_num;
char *key_name;
unsigned int key_id;
unsigned int key_down;
struct delayed_work work;
};
struct key_desc key_desc_array[] = {
{GPIO9_6,"key1", 1,0},
{GPIO9_7,"key2", 2,0},
{GPIO9_2,"key3", 3,0},
{GPIO9_3,"key4", 4,0},
{GPIO9_1,"key5", 5,0},
};
static unsigned char key_val;
static volatile int ev_press = 0;
static struct fasync_struct *lcd_async;
static void lcm_init_cmz(void);
static void lcm_init2_cmz(void);
static void keys_work(struct work_struct *work)
{
int value = 0;
struct key_desc *kdesc = container_of(work,
struct key_desc, work.work);
//printk("[%s %d] %s \n", __func__, __LINE__,kdesc->key_name);
value = gpio_get_value(kdesc->gpio_num);
/*key down*/
if((value == 0) && (kdesc->key_down == 0) )
{
kdesc->key_down = 1;
//printk("[%s %d] %s down \n", __func__, __LINE__,kdesc->key_name);
key_val = 0x80 | kdesc->key_id;
ev_press = 1;
wake_up_interruptible(&key_waitq);
}
/*key up */
if((value == 1) && (kdesc->key_down == 1) )
{
kdesc->key_down = 0;
//printk("[%s %d] %s up \n", __func__, __LINE__,kdesc->key_name);
key_val = kdesc->key_id;
ev_press = 1;
wake_up_interruptible(&key_waitq);
}
}
static irqreturn_t gpio_key_isr(int irq, void *dev_id)
{
struct key_desc *kdesc = (struct key_desc *)dev_id;
//printk("[%s %d] %s \n", __func__, __LINE__,kdesc->key_name);
schedule_delayed_work(&kdesc->work, msecs_to_jiffies(10));
#if 0
struct key_desc *irq_pd = (struct key_desc *)dev_id;
int i = 0;
int value = 0;
printk("[%s %d] irq=%d %s \n", __func__, __LINE__,irq,irq_pd->key_name);
for(i = 0; i < ARRAY_SIZE(key_desc_array); i++)
{
value = gpio_get_value(key_desc_array[i].gpio_num);
printk("%s = %d \n", key_desc_array[i].key_name,value);
}
#endif
return IRQ_HANDLED;
}
//
#include <linux/spi/spi.h>
extern struct bus_type spi_bus_type;
static unsigned bus_num = 0;
static unsigned csn = 0;
module_param(bus_num, uint, S_IRUGO);
MODULE_PARM_DESC(bus_num, "spi bus number");
module_param(csn, uint, S_IRUGO);
MODULE_PARM_DESC(csn, "chip select number");
struct spi_master *hi_master;
struct spi_device *hi_spi;
static int __init sspdev_init(void)
{
int status = 0;
struct device *d;
char *spi_name;
hi_master = spi_busnum_to_master(bus_num);
if (hi_master) {
spi_name = kzalloc(strlen(dev_name(&hi_master->dev)) + 10 , GFP_KERNEL);
if (!spi_name) {
status = -ENOMEM;
goto end0;
}
sprintf(spi_name, "%s.%u", dev_name(&hi_master->dev),csn);
printk("spi_name = %s \n",spi_name);
d = bus_find_device_by_name(&spi_bus_type, NULL, spi_name);
if (d == NULL) {
status = -ENXIO;
goto end1;
}
hi_spi = to_spi_device(d);
if(hi_spi == NULL) {