|
@@ -14,10 +14,15 @@
|
|
|
#include <linux/io.h>
|
|
#include <linux/io.h>
|
|
|
#include "gpioregs.h"
|
|
#include "gpioregs.h"
|
|
|
|
|
|
|
|
|
|
+#if defined(PROJECT) && (PROJECT == POS)
|
|
|
|
|
+#define DEVICE_NAME "buzz0"
|
|
|
|
|
+#else
|
|
|
#define DEVICE_NAME "buzzer"
|
|
#define DEVICE_NAME "buzzer"
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
#define CLASS_NAME "buzzer_class"
|
|
#define CLASS_NAME "buzzer_class"
|
|
|
#define DRIVER_NAME "buzzer_driver"
|
|
#define DRIVER_NAME "buzzer_driver"
|
|
|
-#define BUFFER_SIZE 1024
|
|
|
|
|
|
|
+#define BUFFER_SIZE 4
|
|
|
|
|
|
|
|
#define note(x) ((119318200+(x)/2)/(x))
|
|
#define note(x) ((119318200+(x)/2)/(x))
|
|
|
|
|
|
|
@@ -81,12 +86,10 @@ static void delay_work_func(struct work_struct *work)
|
|
|
int duration = 0;
|
|
int duration = 0;
|
|
|
if(dev->size < 4)
|
|
if(dev->size < 4)
|
|
|
{
|
|
{
|
|
|
- printk(KERN_INFO "buzzer: size < 4\n");
|
|
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
// Close buzzer
|
|
// Close buzzer
|
|
|
BeepOff();
|
|
BeepOff();
|
|
|
- printk(KERN_INFO "delay_work_func\n");
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static int buzzer_open(struct inode *inode, struct file *filp)
|
|
static int buzzer_open(struct inode *inode, struct file *filp)
|
|
@@ -110,7 +113,6 @@ static int buzzer_open(struct inode *inode, struct file *filp)
|
|
|
static int buzzer_release(struct inode *inode, struct file *filp)
|
|
static int buzzer_release(struct inode *inode, struct file *filp)
|
|
|
{
|
|
{
|
|
|
// release_region(PORT_80, 1);
|
|
// release_region(PORT_80, 1);
|
|
|
- printk(KERN_INFO "buzzer: Device closed\n");
|
|
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -142,7 +144,6 @@ static ssize_t buzzer_read(struct file *filp, char __user *buf,
|
|
|
goto out;
|
|
goto out;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- printk(KERN_INFO "buzzer: Read %zu bytes\n", count);
|
|
|
|
|
|
|
|
|
|
out:
|
|
out:
|
|
|
mutex_unlock(&dev->lock);
|
|
mutex_unlock(&dev->lock);
|
|
@@ -199,7 +200,6 @@ static ssize_t buzzer_write(struct file *filp, const char __user *buf,
|
|
|
BeepOff();
|
|
BeepOff();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- printk(KERN_INFO "buzzer: Written %zu bytes\n", count);
|
|
|
|
|
|
|
|
|
|
out:
|
|
out:
|
|
|
mutex_unlock(&dev->lock);
|
|
mutex_unlock(&dev->lock);
|
|
@@ -219,6 +219,13 @@ static struct file_operations fops = {
|
|
|
.write = buzzer_write,
|
|
.write = buzzer_write,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+static char *my_devnode(struct device *dev, umode_t *mode) {
|
|
|
|
|
+ if (mode) {
|
|
|
|
|
+ *mode = 0666;
|
|
|
|
|
+ }
|
|
|
|
|
+ return NULL;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
int buzzer_init(void)
|
|
int buzzer_init(void)
|
|
|
{
|
|
{
|
|
|
int result;
|
|
int result;
|
|
@@ -242,8 +249,6 @@ int buzzer_init(void)
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- printk(KERN_INFO "buzzer: Registered with major=%d, minor=%d\n",
|
|
|
|
|
- MAJOR(dev_num), MINOR(dev_num));
|
|
|
|
|
|
|
|
|
|
dev = kmalloc(sizeof(struct buzzer_dev), GFP_KERNEL);
|
|
dev = kmalloc(sizeof(struct buzzer_dev), GFP_KERNEL);
|
|
|
if (!dev)
|
|
if (!dev)
|
|
@@ -281,6 +286,7 @@ int buzzer_init(void)
|
|
|
printk(KERN_ALERT "buzzer: Failed to create class\n");
|
|
printk(KERN_ALERT "buzzer: Failed to create class\n");
|
|
|
goto fail_class;
|
|
goto fail_class;
|
|
|
}
|
|
}
|
|
|
|
|
+ char_class->devnode = my_devnode;
|
|
|
|
|
|
|
|
char_device = device_create(char_class, NULL, dev_num, NULL, DEVICE_NAME);
|
|
char_device = device_create(char_class, NULL, dev_num, NULL, DEVICE_NAME);
|
|
|
if (IS_ERR(char_device))
|
|
if (IS_ERR(char_device))
|
|
@@ -290,9 +296,6 @@ int buzzer_init(void)
|
|
|
goto fail_device;
|
|
goto fail_device;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- printk(KERN_INFO "buzzer: Driver initialized successfully\n");
|
|
|
|
|
- printk(KERN_INFO "buzzer: Device node: /dev/%s (major=%d, minor=%d)\n",
|
|
|
|
|
- DEVICE_NAME, buzzer_major, buzzer_minor);
|
|
|
|
|
return 0;
|
|
return 0;
|
|
|
|
|
|
|
|
fail_device:
|
|
fail_device:
|