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 long vflash_ioctl(struct file *file,
\r
38 unsigned int cmd, unsigned long arg)
\r
40 void __user *argp = (void __user *)arg;
\r
42 DBG("%s---cmd=0x%x---arg=0x%x\n", __FUNCTION__, cmd, arg);
\r
49 case READ_BDADDR_FROM_FLASH:
\r
51 #ifdef CONFIG_WIFI_MAC
\r
52 unsigned char bd_addr[6] = {0};
\r
55 printk("vflash: wlan_mac_addr:%X:%X:%X:%x:%X:%x\n", wlan_mac_addr[0],
\r
61 for (i=1; i<6; i++) {
\r
62 bd_addr[i] = wlan_mac_addr[5-i];
\r
65 bd_addr[0] = wlan_mac_addr[5]+1;
\r
67 printk("vflash: bd_addr:%X:%X:%X:%x:%X:%x\n", bd_addr[5],
\r
75 if(copy_to_user(argp, bd_addr, 6)) {
\r
76 printk("ERROR: copy_to_user---%s\n", __FUNCTION__);
\r
80 char *tempBuf = (char *)kmalloc(512, GFP_KERNEL);
\r
81 char bd_addr[6] = {0};
\r
84 GetSNSectorInfo(tempBuf);
\r
86 for(i=498; i<=504; i++)
\r
88 DBG("tempBuf[%d]=%x\n", i, tempBuf[i]);
\r
89 bd_addr[504-i] = tempBuf[i];
\r
93 if(copy_to_user(argp, bd_addr, 6))
\r
95 printk("ERROR: copy_to_user---%s\n", __FUNCTION__);
\r
111 static int vflash_open(struct inode *inode, struct file *file)
\r
113 DBG("%s\n", __FUNCTION__);
\r
117 static int vflash_release(struct inode *inode, struct file *file)
\r
119 DBG("%s\n", __FUNCTION__);
\r
124 static const struct file_operations vflash_fops = {
\r
125 .owner = THIS_MODULE,
\r
126 .unlocked_ioctl = vflash_ioctl,
\r
127 .open = vflash_open,
\r
128 .release = vflash_release,
\r
131 static struct miscdevice vflash_miscdev= {
\r
133 .fops = &vflash_fops,
\r
137 static int vflash_init(void)
\r
139 vflash_miscdev.minor = minor;
\r
141 if (misc_register(&vflash_miscdev) < 0) {
\r
142 printk(KERN_ERR"Can't register misc device with minor %d", minor);
\r
148 static void vflash_exit(void)
\r
150 if (misc_deregister(&vflash_miscdev) < 0)
\r
151 printk(KERN_ERR"Can't unregister misc device with minor %d", minor);
\r
155 module_init(vflash_init);
\r
156 module_exit(vflash_exit);
\r
158 module_param(minor, int, 0444);
\r
159 MODULE_PARM_DESC(minor, "Miscellaneous minor device number");
\r
161 MODULE_AUTHOR("roger_chen <cz@rock-chips.com>");
\r
162 MODULE_DESCRIPTION("Bluetooth virtual flash driver ver " VERSION);
\r
163 MODULE_VERSION(VERSION);
\r
164 MODULE_LICENSE("GPL");
\r