2 * Copyright (C) 2010 ROCKCHIP, Inc.
\r
3 * Author: roger_chen <cz@rock-chips.com>
\r
5 * This program is the virtual flash device
\r
6 * used to store bd_addr or MAC
\r
11 #include <linux/module.h>
\r
12 #include <linux/kernel.h>
\r
13 #include <linux/errno.h>
\r
14 #include <linux/miscdevice.h>
\r
15 #include <linux/fs.h>
\r
16 #include <linux/platform_device.h>
\r
17 #include <asm/uaccess.h>
\r
20 #define DBG(x...) printk("vFlash:" x)
\r
25 #define VERSION "0.1"
\r
27 static int minor = MISC_DYNAMIC_MINOR;
\r
29 static struct miscdevice vflash_miscdev;
\r
31 #define READ_BDADDR_FROM_FLASH 0x01
\r
33 extern char GetSNSectorInfo(char * pbuf);
\r
35 static int vflash_ioctl(struct inode *inode, struct file *file,
\r
36 unsigned int cmd, unsigned long arg)
\r
38 void __user *argp = (void __user *)arg;
\r
39 unsigned long n = 0;
\r
41 DBG("%s---cmd=0x%x---arg=0x%x\n", __FUNCTION__, cmd, arg);
\r
48 case READ_BDADDR_FROM_FLASH:
\r
50 char *tempBuf = (char *)kmalloc(512, GFP_KERNEL);
\r
53 GetSNSectorInfo(tempBuf);
\r
55 tempBuf[498] = 0x00;
\r
56 tempBuf[499] = 0x11;
\r
57 tempBuf[500] = 0x22;
\r
58 tempBuf[501] = 0x33;
\r
59 tempBuf[502] = 0x44;
\r
60 tempBuf[503] = 0x55;
\r
61 tempBuf[504] = 0x66;
\r
63 for(i=498; i<=504; i++)
\r
65 DBG("tempBuf[%d]=%x\n", i, tempBuf[i]);
\r
68 if(copy_to_user(argp, &(tempBuf[499]), 6))
\r
70 printk("ERROR: copy_to_user---%s\n", __FUNCTION__);
\r
85 static int vflash_open(struct inode *inode, struct file *file)
\r
87 DBG("%s\n", __FUNCTION__);
\r
91 static int vflash_release(struct inode *inode, struct file *file)
\r
93 DBG("%s\n", __FUNCTION__);
\r
98 static const struct file_operations vflash_fops = {
\r
99 .owner = THIS_MODULE,
\r
100 .ioctl = vflash_ioctl,
\r
101 .open = vflash_open,
\r
102 .release = vflash_release,
\r
105 static struct miscdevice vflash_miscdev= {
\r
107 .fops = &vflash_fops,
\r
111 static int vflash_init(void)
\r
113 vflash_miscdev.minor = minor;
\r
115 if (misc_register(&vflash_miscdev) < 0) {
\r
116 printk(KERN_ERR"Can't register misc device with minor %d", minor);
\r
122 static void vflash_exit(void)
\r
124 if (misc_deregister(&vflash_miscdev) < 0)
\r
125 printk(KERN_ERR"Can't unregister misc device with minor %d", minor);
\r
129 module_init(vflash_init);
\r
130 module_exit(vflash_exit);
\r
132 module_param(minor, int, 0444);
\r
133 MODULE_PARM_DESC(minor, "Miscellaneous minor device number");
\r
135 MODULE_AUTHOR("roger_chen <cz@rock-chips.com>");
\r
136 MODULE_DESCRIPTION("Bluetooth virtual flash driver ver " VERSION);
\r
137 MODULE_VERSION(VERSION);
\r
138 MODULE_LICENSE("GPL");
\r