44070a74b352c434180a62bb741f48bb7e5a7cc6
[firefly-linux-kernel-4.4.55.git] / drivers / bluetooth / vflash.c
1 /*\r
2  * Copyright (C) 2010 ROCKCHIP, Inc.\r
3  * Author: roger_chen <cz@rock-chips.com>\r
4  *\r
5  * This program is the virtual flash device \r
6  * used to store bd_addr or MAC\r
7  *\r
8  */\r
9 \r
10 \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
19 \r
20 #if 0\r
21 #define DBG(x...)   printk("vFlash:" x)\r
22 #else\r
23 #define DBG(x...)\r
24 #endif\r
25 \r
26 #define VERSION "0.1"\r
27 \r
28 static int minor = MISC_DYNAMIC_MINOR;\r
29 \r
30 static struct miscdevice vflash_miscdev;\r
31 \r
32 #define READ_BDADDR_FROM_FLASH  0x01\r
33 \r
34 extern char GetSNSectorInfo(char * pbuf);\r
35 extern unsigned char wlan_mac_addr[6];\r
36 \r
37 static int vflash_ioctl(struct inode *inode, struct file *file,\r
38                                         unsigned int cmd, unsigned long arg)\r
39 {\r
40         void __user *argp = (void __user *)arg;\r
41     unsigned long n = 0;\r
42     \r
43     DBG("%s---cmd=0x%x---arg=0x%x\n", __FUNCTION__, cmd, arg);\r
44 \r
45     if(NULL == argp)\r
46         return -EFAULT;\r
47         \r
48     switch(cmd)\r
49     {\r
50         case READ_BDADDR_FROM_FLASH:\r
51         {   \r
52 #if CONFIG_WIFI_MAC\r
53             unsigned char bd_addr[6] = {0};\r
54             int i;\r
55 \r
56             printk("vflash: wlan_mac_addr:%X:%X:%X:%x:%X:%x\n", wlan_mac_addr[0],\r
57                                                 wlan_mac_addr[1],\r
58                                                 wlan_mac_addr[2],\r
59                                                 wlan_mac_addr[3],\r
60                                                 wlan_mac_addr[4],\r
61                                                 wlan_mac_addr[5] );\r
62             for (i=1; i<6; i++) {\r
63                 bd_addr[i] = wlan_mac_addr[5-i];\r
64             }\r
65 \r
66             bd_addr[0] = wlan_mac_addr[5]+1;\r
67 \r
68             printk("vflash: bd_addr:%X:%X:%X:%x:%X:%x\n", bd_addr[5],\r
69                                                 bd_addr[4],\r
70                                                 bd_addr[3],\r
71                                                 bd_addr[2],\r
72                                                 bd_addr[1],\r
73                                                 bd_addr[0] );\r
74 \r
75 \r
76             if(copy_to_user(argp, bd_addr, 6)) {\r
77                 printk("ERROR: copy_to_user---%s\n", __FUNCTION__);\r
78                 return -EFAULT;\r
79             }\r
80 #else\r
81             char *tempBuf = (char *)kmalloc(512, GFP_KERNEL);\r
82             char bd_addr[6] = {0};\r
83             int i;\r
84 \r
85             GetSNSectorInfo(tempBuf);\r
86 \r
87             for(i=498; i<=504; i++)\r
88             {\r
89                 DBG("tempBuf[%d]=%x\n", i, tempBuf[i]);\r
90                 bd_addr[504-i] = tempBuf[i];\r
91             }\r
92 \r
93             \r
94             if(copy_to_user(argp, bd_addr, 6))\r
95                         {\r
96                             printk("ERROR: copy_to_user---%s\n", __FUNCTION__);\r
97                 kfree(tempBuf);\r
98                             return -EFAULT;\r
99             }\r
100             \r
101             kfree(tempBuf);\r
102 #endif\r
103         }\r
104         break;\r
105         default:\r
106         break;\r
107     }\r
108     \r
109         return 0;\r
110 }\r
111 \r
112 static int vflash_open(struct inode *inode, struct file *file)\r
113 {\r
114     DBG("%s\n", __FUNCTION__);\r
115         return 0;\r
116 }\r
117 \r
118 static int vflash_release(struct inode *inode, struct file *file)\r
119 {\r
120     DBG("%s\n", __FUNCTION__);\r
121         return 0;\r
122 }\r
123 \r
124 \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
130 };\r
131 \r
132 static struct miscdevice vflash_miscdev= {\r
133         .name           = "vflash",\r
134         .fops           = &vflash_fops,\r
135 };\r
136 \r
137 \r
138 static int vflash_init(void)\r
139 {\r
140         vflash_miscdev.minor = minor;\r
141 \r
142         if (misc_register(&vflash_miscdev) < 0) {\r
143                 printk(KERN_ERR"Can't register misc device with minor %d", minor);\r
144                 return -EIO;\r
145         }\r
146         return 0;\r
147 }\r
148 \r
149 static void vflash_exit(void)\r
150 {\r
151         if (misc_deregister(&vflash_miscdev) < 0)\r
152                 printk(KERN_ERR"Can't unregister misc device with minor %d", minor);\r
153 }\r
154 \r
155 \r
156 module_init(vflash_init);\r
157 module_exit(vflash_exit);\r
158 \r
159 module_param(minor, int, 0444);\r
160 MODULE_PARM_DESC(minor, "Miscellaneous minor device number");\r
161 \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
166 \r