FROMLIST: drm: bridge: dw-hdmi: add HDMI vendor specific infoframe config
[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 long vflash_ioctl(struct file *file,\r
38                                         unsigned int cmd, unsigned long arg)\r
39 {\r
40         void __user *argp = (void __user *)arg;\r
41     \r
42     DBG("%s---cmd=0x%x---arg=0x%x\n", __FUNCTION__, cmd, arg);\r
43 \r
44     if(NULL == argp)\r
45         return -EFAULT;\r
46         \r
47     switch(cmd)\r
48     {\r
49         case READ_BDADDR_FROM_FLASH:\r
50         {   \r
51 #ifdef CONFIG_WIFI_MAC\r
52             unsigned char bd_addr[6] = {0};\r
53             int i;\r
54 \r
55             printk("vflash: wlan_mac_addr:%X:%X:%X:%x:%X:%x\n", wlan_mac_addr[0],\r
56                                                 wlan_mac_addr[1],\r
57                                                 wlan_mac_addr[2],\r
58                                                 wlan_mac_addr[3],\r
59                                                 wlan_mac_addr[4],\r
60                                                 wlan_mac_addr[5] );\r
61             for (i=1; i<6; i++) {\r
62                 bd_addr[i] = wlan_mac_addr[5-i];\r
63             }\r
64 \r
65             bd_addr[0] = wlan_mac_addr[5]+1;\r
66 \r
67             printk("vflash: bd_addr:%X:%X:%X:%x:%X:%x\n", bd_addr[5],\r
68                                                 bd_addr[4],\r
69                                                 bd_addr[3],\r
70                                                 bd_addr[2],\r
71                                                 bd_addr[1],\r
72                                                 bd_addr[0] );\r
73 \r
74 \r
75             if(copy_to_user(argp, bd_addr, 6)) {\r
76                 printk("ERROR: copy_to_user---%s\n", __FUNCTION__);\r
77                 return -EFAULT;\r
78             }\r
79 #else\r
80             char *tempBuf = (char *)kmalloc(512, GFP_KERNEL);\r
81             char bd_addr[7] = {0};\r
82             int i;\r
83 \r
84             GetSNSectorInfo(tempBuf);\r
85 \r
86             for(i=498; i<=504; i++)\r
87             {\r
88                 DBG("tempBuf[%d]=%x\n", i, tempBuf[i]);\r
89                 bd_addr[504-i] = tempBuf[i];\r
90             }\r
91 \r
92             \r
93             //printk("%s: ====> get bt addr from flash=[%02x:%02x:%02x:%02x:%02x:%02x]\n", __FUNCTION__,\r
94             //      bd_addr[5], bd_addr[4], bd_addr[3], bd_addr[2], bd_addr[1], bd_addr[0]);\r
95             if(copy_to_user(argp, bd_addr, 6))\r
96             {\r
97                 printk("ERROR: copy_to_user---%s\n", __FUNCTION__);\r
98                 kfree(tempBuf);\r
99                 return -EFAULT;\r
100             }\r
101             \r
102             kfree(tempBuf);\r
103 #endif\r
104         }\r
105         break;\r
106         default:\r
107         break;\r
108     }\r
109     \r
110         return 0;\r
111 }\r
112 \r
113 static int vflash_open(struct inode *inode, struct file *file)\r
114 {\r
115     DBG("%s\n", __FUNCTION__);\r
116         return 0;\r
117 }\r
118 \r
119 static int vflash_release(struct inode *inode, struct file *file)\r
120 {\r
121     DBG("%s\n", __FUNCTION__);\r
122         return 0;\r
123 }\r
124 \r
125 \r
126 static const struct file_operations vflash_fops = {\r
127         .owner          = THIS_MODULE,\r
128         .unlocked_ioctl = vflash_ioctl,\r
129         .open           = vflash_open,\r
130         .release        = vflash_release,\r
131 };\r
132 \r
133 static struct miscdevice vflash_miscdev= {\r
134         .name           = "vflash",\r
135         .fops           = &vflash_fops,\r
136 };\r
137 \r
138 \r
139 static int vflash_init(void)\r
140 {\r
141         vflash_miscdev.minor = minor;\r
142 \r
143         if (misc_register(&vflash_miscdev) < 0) {\r
144                 printk(KERN_ERR"Can't register misc device with minor %d", minor);\r
145                 return -EIO;\r
146         }\r
147         return 0;\r
148 }\r
149 \r
150 static void vflash_exit(void)\r
151 {\r
152         if (misc_deregister(&vflash_miscdev) < 0)\r
153                 printk(KERN_ERR"Can't unregister misc device with minor %d", minor);\r
154 }\r
155 \r
156 \r
157 module_init(vflash_init);\r
158 module_exit(vflash_exit);\r
159 \r
160 module_param(minor, int, 0444);\r
161 MODULE_PARM_DESC(minor, "Miscellaneous minor device number");\r
162 \r
163 MODULE_AUTHOR("roger_chen <cz@rock-chips.com>");\r
164 MODULE_DESCRIPTION("Bluetooth virtual flash driver ver " VERSION);\r
165 MODULE_VERSION(VERSION);\r
166 MODULE_LICENSE("GPL");\r
167 \r