GT2440按鍵驅動新增fasync機制

2021-06-12 21:09:31 字數 3334 閱讀 9671

完整驅動**如下:

#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define module_name_irq		"button_fasync"

#define button_irq_major 210

static struct class *btn_fasync_class;

static unsigned char key_vals[4] = ;

static declare_wait_queue_head(btn_fasync_waitq);

static define_mutex(btn_lock);

static volatile int ev_press = 0;

struct fasync_struct *btn_fasync_queue;

struct btn_fasync_desc ;

static struct btn_fasync_desc btns_irq_desc = , /* k1 */

, /* k2 */

, /* k3 */

/* k4 */

};static irqreturn_t irq_interrupt(int irq, void *dev_id)

return irq_retval(irq_handled);

}static int btn_fasync_open (struct inode *inode, struct file *file)

request_irq(btns_irq_desc[i].irq_num, irq_interrupt, irq_type_edge_both,

btns_irq_desc[i].btn_name,(void *)&btns_irq_desc[i]); }

return 0;

}static ssize_t btn_fasync_read (struct file *filp, char __user *buf, size_t count, loff_t *ppos)

ev_press = 0;

cnt = copy_to_user(buf, (const void *)key_vals, min(sizeof(key_vals), count));

return cnt ? -efault : min(sizeof(key_vals), count);

}static int btn_fasync_close (struct inode *inode, struct file *file)

free_irq(btns_irq_desc[i].irq_num, (void *)&btns_irq_desc[i]);

} up(&btn_lock);

return 0;

}static unsigned int btn_poll (struct file *file, struct poll_table_struct *wait)

static int btn_fasync (int fd, struct file *filp, int on)

static struct file_operations btn_fasync_fops = ;

static int __init __btn_fasync_init(void)

static void __exit __btn_fasync_exit(void)

module_init(__btn_fasync_init);

module_exit(__btn_fasync_exit);

module_license("gpl");

module_author("[email protected]");

module_description("button irq_module test for gt2440 board");

完整測試程式如下:

#include #include #include #include #include #include #include #include int  fd;

void button_signal_func(int signal_num)

; unsigned char key_tmp_vals[4];

signal_num = signal_num;

if (read(fd, key_tmp_vals, sizeof(key_tmp_vals)) != sizeof(key_tmp_vals))

for (i = 0; i < sizeof(key_vals)/sizeof(key_vals[0]); i++) }}

int main(int argv,char **argc)

fcntl(fd, f_setown, getpid());

oflags = fcntl(fd, f_getfl);

fcntl(fd, f_setfl, oflags | fasync);

while (1)

return 0;

}

makefile如下:

ifeq ($(kernelrelease),)

# learn to write makefile for driver

kern_version = /opt/gtstudio/gt2440/linux-2.6.38.6

pwd := $(shell pwd)

#specify flags for the module compilation.

#extar_cflags = -g -o0

# build kernerl module

modules:

$(make) -c $(kern_version) m=$(pwd) modules

modules_install:

$(make) -c $(kern_version) m=$(pwd) modules_install

clean:

rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions module* modules*

.phony: modules modules_install clean

else

# kernel module

obj-m += btn_fasync_dev.o

endif

GT2440啟動過程

一下為個人分析結果,可能存在錯誤。gt2440可以分兩種啟動方式 1.從nor flash啟動 2.從nand flash啟動 gt2440啟動時存在乙個位址對映問題,因為gt2440啟動總是從0x0這個位址開始的下面就兩種啟動方式分別做一下介紹 1.從nor flash啟動 當從nor flash...

GT911 LINUX 驅動新增

1.將 gt911驅動 gt9xx檔案 夾放在linux 原始碼 drivers input touchscreen 下 修改drivers input touchscreen makefile obj config touchscreen goodix gt9xx 2.更改系統配置 device ...

fl2440按鍵中斷驅動

include include include include include include include include include include include copy to user include 核心時鐘 include atomic t include s3c2410 gpf...