platform裝置驅動之按鍵掃瞄(cdev裝置)

2021-06-06 01:31:36 字數 3972 閱讀 5330

一、開發環境

1、硬體平台:fs2410

2、主機:ubuntu 10.10

3、核心版本:linux 2.6.35

4、交叉編譯工具鏈:arm-none-linux-gnueabi-

二、詳細**

1、button_device.c(platform_device)

#include #include #include #include #include #include struct resource button_resource = ,

[1] = ,

[2] = ,

[3] = ,

[4] = ,

};struct platform_device button_device = ;

static int __init button_device_init(void)

static void __exit button_device_exit(void)

module_init(button_device_init);

module_exit(button_device_exit);

module_author("yhr");

module_license("gpl");

2、button_driver.c(platform_driver)

#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define extint0		*(volatile unsigned int *)s3c2410_extint0

#define extint1 *(volatile unsigned int *)s3c2410_extint1

#define extint2 *(volatile unsigned int *)s3c2410_extint2

static int button_major = 255;

struct button_dev

;struct button_irq_desc

;static struct button_irq_desc button_irqs =

, , , ,

};struct button_dev dev;

static volatile unsigned int *gpecon;

static volatile unsigned int *gpedat;

static volatile unsigned int *gpfcon;

static volatile unsigned int *gpfdat;

static volatile unsigned int *gpgcon;

static volatile unsigned int *gpgdat;

static void init_gpio(void)

extint0 = (extint0 & (~0x07)) + 0x02;

extint0 = (extint0 & (~(0x07 << 8))) + (0x02 << 8);

extint1 = (extint1 & (~(0x07 << 12))) + (0x02 << 12);

extint2 = (extint2 & (~(0x07 << 12))) + (0x02 << 12);

}static __inline unsigned char button_scan(int irq)

static irqreturn_t button_interrupt(int irq, void *dev_id)

static __inline void free_irqs(void)

return;

}static int button_open(struct inode *inode,struct file *filp)

static int button_release(struct inode *inode,struct file *filp)

static ssize_t button_read(struct file *filp, char *buf, size_t size, loff_t *ppos)

ret = size;

dev.key_value = 0;

return ret;

}static ssize_t button_write(struct file *filp, const char __user *buf, size_t size, loff_t *ppos)

static int button_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)

static unsigned int button_poll(struct file *filp, poll_table *wait)

static struct file_operations button_fops =

;static void button_setup_cdev(struct cdev *dev, int index)

static int button_cdev_init(void)

if(result < 0)

return result;

printk("button_major : %d\n", button_major);

button_setup_cdev(&dev.cdev, 0);

init_waitqueue_head(&dev.r_wait);

return 0;

}void ioremap_gpio(struct resource *res)

static int button_probe(struct platform_device *pdev)

return 0;

}void iounmap_gpio(void)

static int button_remove(struct platform_device *pdev)

static struct platform_driver button_driver =

};static int __init button_init(void)

static void __exit button_exit(void)

module_init(button_init);

module_exit(button_exit);

module_author("yhr");

module_license("gpl");

3、makefile

ifeq ($(kernelrelease),)

# set your object kernel dir

kerneldir = /home/linux/linux-2.6.35

pwd := $(shell pwd)

modules:

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

modules_install:

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

clean:

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

.phony: modules modules_install clean

else

obj-m := button_device.o button_driver.o

endif

按鍵驅動 platform裝置的例子

下面將之前的按鍵驅動改寫為platform裝置。1 建立資料夾key platform 2 在資料夾key platform下建立裝置檔案keydevice.c。include include include include include include module author wjb mod...

按鍵驅動 platform裝置的例子

下面將之前的按鍵驅動改寫為platform裝置。1 建立資料夾key platform 2 在資料夾key platform下建立裝置檔案keydevice.c。include include include include include include module author wjb mod...

驅動案例三 platform按鍵驅動(一 裝置)

plat device.c include include include include include include include include include static struct resource s3c buttons resource 0 start s3c24xx pa g...