Merge remote branch 'linux-2.6.32.y/master' into develop
[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             int i;\r
52             #if 0\r
53             GetSNSectorInfo(tempBuf);\r
54             #else\r
55             tempBuf[498] = 0x00;\r
56             tempBuf[499] = 0x11;\r
57             tempBuf[500] = 0x22;\r
58             tempBuf[501] = 0x33;\r
59             tempBuf[502] = 0x44;\r
60             tempBuf[503] = 0x55;\r
61             tempBuf[504] = 0x66;\r
62             #endif\r
63             for(i=498; i<=504; i++)\r
64             {\r
65                 DBG("tempBuf[%d]=%x\n", i, tempBuf[i]);\r
66             }\r
67             \r
68                         if(copy_to_user(argp, &(tempBuf[499]), 6))\r
69                         {\r
70                             printk("ERROR: copy_to_user---%s\n", __FUNCTION__);\r
71                 kfree(tempBuf);\r
72                             return -EFAULT;\r
73             }\r
74             \r
75             kfree(tempBuf);\r
76         }\r
77         break;\r
78         default:\r
79         break;\r
80     }\r
81     \r
82         return 0;\r
83 }\r
84 \r
85 static int vflash_open(struct inode *inode, struct file *file)\r
86 {\r
87     DBG("%s\n", __FUNCTION__);\r
88         return 0;\r
89 }\r
90 \r
91 static int vflash_release(struct inode *inode, struct file *file)\r
92 {\r
93     DBG("%s\n", __FUNCTION__);\r
94         return 0;\r
95 }\r
96 \r
97 \r
98 static const struct file_operations vflash_fops = {\r
99         .owner          = THIS_MODULE,\r
100         .ioctl          = vflash_ioctl,\r
101         .open           = vflash_open,\r
102         .release        = vflash_release,\r
103 };\r
104 \r
105 static struct miscdevice vflash_miscdev= {\r
106         .name           = "vflash",\r
107         .fops           = &vflash_fops,\r
108 };\r
109 \r
110 \r
111 static int vflash_init(void)\r
112 {\r
113         vflash_miscdev.minor = minor;\r
114 \r
115         if (misc_register(&vflash_miscdev) < 0) {\r
116                 printk(KERN_ERR"Can't register misc device with minor %d", minor);\r
117                 return -EIO;\r
118         }\r
119         return 0;\r
120 }\r
121 \r
122 static void vflash_exit(void)\r
123 {\r
124         if (misc_deregister(&vflash_miscdev) < 0)\r
125                 printk(KERN_ERR"Can't unregister misc device with minor %d", minor);\r
126 }\r
127 \r
128 \r
129 module_init(vflash_init);\r
130 module_exit(vflash_exit);\r
131 \r
132 module_param(minor, int, 0444);\r
133 MODULE_PARM_DESC(minor, "Miscellaneous minor device number");\r
134 \r
135 MODULE_AUTHOR("roger_chen <cz@rock-chips.com>");\r
136 MODULE_DESCRIPTION("Bluetooth virtual flash driver ver " VERSION);\r
137 MODULE_VERSION(VERSION);\r
138 MODULE_LICENSE("GPL");\r
139 \r