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 <linux/slab.h>
\r
18 #include <asm/uaccess.h>
\r
21 #define DBG(x...) printk("vFlash:" x)
\r
26 #define VERSION "0.1"
\r
28 static int minor = MISC_DYNAMIC_MINOR;
\r
30 static struct miscdevice vflash_miscdev;
\r
32 #define READ_BDADDR_FROM_FLASH 0x01
\r
34 extern char GetSNSectorInfo(char * pbuf);
\r
35 extern unsigned char wlan_mac_addr[6];
\r
37 static int vflash_ioctl(struct inode *inode, struct file *file,
\r
38 unsigned int cmd, unsigned long arg)
\r
40 void __user *argp = (void __user *)arg;
\r
41 unsigned long n = 0;
\r
43 DBG("%s---cmd=0x%x---arg=0x%x\n", __FUNCTION__, cmd, arg);
\r
50 case READ_BDADDR_FROM_FLASH:
\r
53 unsigned char bd_addr[6] = {0};
\r
56 printk("vflash: wlan_mac_addr:%X:%X:%X:%x:%X:%x\n", wlan_mac_addr[0],
\r
62 for (i=1; i<6; i++) {
\r
63 bd_addr[i] = wlan_mac_addr[5-i];
\r
66 bd_addr[0] = wlan_mac_addr[5]+1;
\r
68 printk("vflash: bd_addr:%X:%X:%X:%x:%X:%x\n", bd_addr[5],
\r
76 if(copy_to_user(argp, bd_addr, 6)) {
\r
77 printk("ERROR: copy_to_user---%s\n", __FUNCTION__);
\r
81 char *tempBuf = (char *)kmalloc(512, GFP_KERNEL);
\r
82 char bd_addr[6] = {0};
\r
85 GetSNSectorInfo(tempBuf);
\r
87 for(i=498; i<=504; i++)
\r
89 DBG("tempBuf[%d]=%x\n", i, tempBuf[i]);
\r
90 bd_addr[504-i] = tempBuf[i];
\r
94 if(copy_to_user(argp, bd_addr, 6))
\r
96 printk("ERROR: copy_to_user---%s\n", __FUNCTION__);
\r
112 static int vflash_open(struct inode *inode, struct file *file)
\r
114 DBG("%s\n", __FUNCTION__);
\r
118 static int vflash_release(struct inode *inode, struct file *file)
\r
120 DBG("%s\n", __FUNCTION__);
\r
125 static const struct file_operations vflash_fops = {
\r
126 .owner = THIS_MODULE,
\r
127 .unlocked_ioctl = vflash_ioctl,
\r
128 .open = vflash_open,
\r
129 .release = vflash_release,
\r
132 static struct miscdevice vflash_miscdev= {
\r
134 .fops = &vflash_fops,
\r
138 static int vflash_init(void)
\r
140 vflash_miscdev.minor = minor;
\r
142 if (misc_register(&vflash_miscdev) < 0) {
\r
143 printk(KERN_ERR"Can't register misc device with minor %d", minor);
\r
149 static void vflash_exit(void)
\r
151 if (misc_deregister(&vflash_miscdev) < 0)
\r
152 printk(KERN_ERR"Can't unregister misc device with minor %d", minor);
\r
156 module_init(vflash_init);
\r
157 module_exit(vflash_exit);
\r
159 module_param(minor, int, 0444);
\r
160 MODULE_PARM_DESC(minor, "Miscellaneous minor device number");
\r
162 MODULE_AUTHOR("roger_chen <cz@rock-chips.com>");
\r
163 MODULE_DESCRIPTION("Bluetooth virtual flash driver ver " VERSION);
\r
164 MODULE_VERSION(VERSION);
\r
165 MODULE_LICENSE("GPL");
\r