Skip to content
Snippets Groups Projects
Commit ff57e476 authored by 최준영's avatar 최준영
Browse files

Add new file

parent 86d18b15
No related branches found
No related tags found
No related merge requests found
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/uaccess.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <asm/mach/map.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#define BUZZER_MAJOR_NUMBER 502
#define BUZZER_DEV_NAME "buzzer_ioctl"
//GPIO18
#define GPIO_BASE_ADDR 0x3F200000
#define GPFSEL1 0x04
#define GPSET0 0x1C
#define GPCLR0 0x28
#define GPFSEL2 0x08
#define GPLEV0 0x34
#define IOCTL_MAGIC_NUMBER 'k'
#define IOCTL_CMD_BUZZER_OFF _IO(IOCTL_MAGIC_NUMBER, 0)
#define IOCTL_CMD_BUZZER_ON _IO(IOCTL_MAGIC_NUMBER, 1)
#define IOCTL_CMD_BUTTON_CLICKED _IO(IOCTL_MAGIC_NUMBER, 2)
static void __iomem *gpio_base;
volatile unsigned int *gpsel1;
volatile unsigned int *gpset1;
volatile unsigned int *gpclr1;
volatile unsigned int *gpsel2;
volatile unsigned int *gplev0;
int buzzer_open(struct inode *inode, struct file *flip) {
printk(KERN_ALERT "buzzer driver open!!\n");
gpio_base = ioremap(GPIO_BASE_ADDR, 0x60);
gpsel1 = (volatile unsigned int *)(gpio_base + GPFSEL1);
gpset1 = (volatile unsigned int *)(gpio_base + GPSET0);
gpclr1 = (volatile unsigned int *)(gpio_base + GPCLR0);
gpsel2 = (volatile unsigned int *)(gpio_base + GPFSEL2);
gplev0 = (volatile unsigned int *)(gpio_base + GPLEV0);
//set direction out
*gpsel2 |= (1 << 3);
*gpsel1 |= (1 << 24);
*gpset1 |= (1 << 18);
*gpset1 |= (1 << 21);
return 0;
}
int buzzer_release(struct inode *inode, struct file *filp) {
printk(KERN_ALERT "buzzer driver closed!!\n");
iounmap((void *)gpio_base);
return 0;
}
long buzzer_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
switch (cmd) {
case IOCTL_CMD_BUZZER_OFF:
printk(KERN_ALERT "buzzer off!!\n");
*gpset1 |= (1 << 18);
break;
case IOCTL_CMD_BUZZER_ON:
printk(KERN_ALERT "buzzer on!!\n");
*gpclr1 |= (1 << 18);
break;
case IOCTL_CMD_BUTTON_CLICKED:
printk(KERN_ALERT "button on!!\n");
if((*gplev0 & (1<<20)) == (1<<20)){
return 0;
}else return 1;
}
return 0;
}
static struct file_operations buzzer_fops = {
.owner = THIS_MODULE,
.open = buzzer_open,
.release = buzzer_release,
.unlocked_ioctl = buzzer_ioctl
};
int __init buzzer_init(void) {
if (register_chrdev(BUZZER_MAJOR_NUMBER, BUZZER_DEV_NAME, &buzzer_fops) < 0)
printk(KERN_ALERT "buzzer driver initialization fail\n");
else
printk(KERN_ALERT "buzzer driver initailization success\n");
return 0;
}
void __exit buzzer_exit(void) {
unregister_chrdev(BUZZER_MAJOR_NUMBER, BUZZER_DEV_NAME);
printk(KERN_ALERT "buzzer driver exit done\n");
}
module_init(buzzer_init);
module_exit(buzzer_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Jaehoon");
MODULE_DESCRIPTION("des");
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment