5987d9212a52ff73415378d1afee75fc9fc0f334
[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 <asm/uaccess.h>\r
18 \r
19 #if 0\r
20 #define DBG(x...)   printk("vFlash:" x)\r
21 #else\r
22 #define DBG(x...)\r
23 #endif\r
24 \r
25 #define VERSION "0.1"\r
26 \r
27 static int minor = MISC_DYNAMIC_MINOR;\r
28 \r
29 static struct miscdevice vflash_miscdev;\r
30 \r
31 #define READ_BDADDR_FROM_FLASH  0x01\r
32 \r
33 extern char GetSNSectorInfo(char * pbuf);\r
34 \r
35 static int vflash_ioctl(struct inode *inode, struct file *file,\r
36                                         unsigned int cmd, unsigned long arg)\r
37 {\r
38         void __user *argp = (void __user *)arg;\r
39     unsigned long n = 0;\r
40     \r
41     DBG("%s---cmd=0x%x---arg=0x%x\n", __FUNCTION__, cmd, arg);\r
42 \r
43     if(NULL == argp)\r
44         return -EFAULT;\r
45         \r
46     switch(cmd)\r
47     {\r
48         case READ_BDADDR_FROM_FLASH:\r
49         {   \r
50             char *tempBuf = (char *)kmalloc(512, GFP_KERNEL);\r
51             char bd_addr[6] = {0};\r
52             int i;\r
53 \r
54             GetSNSectorInfo(tempBuf);\r
55 \r
56             for(i=498; i<=504; i++)\r
57             {\r
58                 DBG("tempBuf[%d]=%x\n", i, tempBuf[i]);\r
59                 bd_addr[504-i] = tempBuf[i];\r
60             }\r
61 \r
62             \r
63             if(copy_to_user(argp, bd_addr, 6))\r
64                         {\r
65                             printk("ERROR: copy_to_user---%s\n", __FUNCTION__);\r
66                 kfree(tempBuf);\r
67                             return -EFAULT;\r
68             }\r
69             \r
70             kfree(tempBuf);\r
71         }\r
72         break;\r
73         default:\r
74         break;\r
75     }\r
76     \r
77         return 0;\r
78 }\r
79 \r
80 static int vflash_open(struct inode *inode, struct file *file)\r
81 {\r
82     DBG("%s\n", __FUNCTION__);\r
83         return 0;\r
84 }\r
85 \r
86 static int vflash_release(struct inode *inode, struct file *file)\r
87 {\r
88     DBG("%s\n", __FUNCTION__);\r
89         return 0;\r
90 }\r
91 \r
92 \r
93 static const struct file_operations vflash_fops = {\r
94         .owner          = THIS_MODULE,\r
95         .ioctl          = vflash_ioctl,\r
96         .open           = vflash_open,\r
97         .release        = vflash_release,\r
98 };\r
99 \r
100 static struct miscdevice vflash_miscdev= {\r
101         .name           = "vflash",\r
102         .fops           = &vflash_fops,\r
103 };\r
104 \r
105 \r
106 static int vflash_init(void)\r
107 {\r
108         vflash_miscdev.minor = minor;\r
109 \r
110         if (misc_register(&vflash_miscdev) < 0) {\r
111                 printk(KERN_ERR"Can't register misc device with minor %d", minor);\r
112                 return -EIO;\r
113         }\r
114         return 0;\r
115 }\r
116 \r
117 static void vflash_exit(void)\r
118 {\r
119         if (misc_deregister(&vflash_miscdev) < 0)\r
120                 printk(KERN_ERR"Can't unregister misc device with minor %d", minor);\r
121 }\r
122 \r
123 \r
124 module_init(vflash_init);\r
125 module_exit(vflash_exit);\r
126 \r
127 module_param(minor, int, 0444);\r
128 MODULE_PARM_DESC(minor, "Miscellaneous minor device number");\r
129 \r
130 MODULE_AUTHOR("roger_chen <cz@rock-chips.com>");\r
131 MODULE_DESCRIPTION("Bluetooth virtual flash driver ver " VERSION);\r
132 MODULE_VERSION(VERSION);\r
133 MODULE_LICENSE("GPL");\r
134 \r