usb: dwc3: unregister extcon notify if probe fail
[firefly-linux-kernel-4.4.55.git] / drivers / misc / rk2928_callpad_misc / audio_switch.c
1 #include <linux/module.h>\r
2 #include <linux/kernel.h>\r
3 #include <linux/i2c.h>\r
4 #include <linux/irq.h>\r
5 #include <linux/gpio.h>\r
6 #include <linux/input.h>\r
7 #include <linux/platform_device.h>\r
8 #include <linux/fs.h>\r
9 #include <linux/uaccess.h>\r
10 #include <linux/miscdevice.h>\r
11 #include <linux/circ_buf.h>\r
12 #include <linux/interrupt.h>\r
13 #include <linux/miscdevice.h>\r
14 #include <mach/iomux.h>\r
15 #include <mach/gpio.h>\r
16 #include <linux/delay.h>\r
17 #include <linux/poll.h>\r
18 #include <linux/wait.h>\r
19 #include <linux/wakelock.h>\r
20 #include <linux/workqueue.h>\r
21 #include <mach/iomux.h>\r
22 #include<linux/ioctl.h>\r
23 \r
24 #include <linux/slab.h>\r
25    \r
26 MODULE_LICENSE("GPL");\r
27 \r
28 struct rk29_audio_switch_data {\r
29         struct device *dev;\r
30         unsigned int gpio_switch_fm_ap;\r
31         unsigned int gpio_switch_bb_ap;\r
32         int state;\r
33 };\r
34 \r
35 struct rk29_audio_switch_data *gpdata = NULL;\r
36 \r
37 #define AUDIO_SWTICH_IO 0XA2\r
38 #define AS_IOCTL_AP     _IO(AUDIO_SWTICH_IO,0X01)\r
39 #define AS_IOCTL_BP     _IO(AUDIO_SWTICH_IO,0X02)\r
40 #define AS_IOCTL_FM     _IO(AUDIO_SWTICH_IO,0X03)\r
41 \r
42 \r
43 static int as_open(struct inode *inode, struct file *file)\r
44 {\r
45         return 0;\r
46 }\r
47 \r
48 static int as_release(struct inode *inode, struct file *file)\r
49 {\r
50         return 0;\r
51 }\r
52 \r
53 static long as_ioctl(struct file *file, unsigned int cmd, unsigned long arg)\r
54 {\r
55     \r
56         switch(cmd)\r
57         {\r
58                 case AS_IOCTL_AP:       \r
59                     gpio_set_value(gpdata->gpio_switch_fm_ap, GPIO_LOW);\r
60                     break;\r
61                 case AS_IOCTL_BP:\r
62                     break;\r
63                 case AS_IOCTL_FM:\r
64                     gpio_set_value(gpdata->gpio_switch_fm_ap, GPIO_HIGH);\r
65                     break;\r
66                 default:\r
67                         break;\r
68         }\r
69         return 0;\r
70 }\r
71 \r
72 static struct file_operations as_fops = {\r
73         .owner = THIS_MODULE,\r
74         .open = as_open,\r
75         .release = as_release,\r
76         .unlocked_ioctl = as_ioctl\r
77 };\r
78 \r
79 static struct miscdevice as_misc = {\r
80         .minor = MISC_DYNAMIC_MINOR,\r
81         .name = "audio_switch",\r
82         .fops = &as_fops\r
83 };\r
84 \r
85 static int as_probe(struct platform_device *pdev)\r
86 {\r
87     int result=0;\r
88     gpdata = kzalloc(sizeof(struct rk29_audio_switch_data), GFP_KERNEL);\r
89 \r
90     rk30_mux_api_set(GPIO1B0_SPI_CLK_UART1_CTSN_NAME, GPIO1B_GPIO1B0);\r
91     gpdata->gpio_switch_fm_ap = gpio_request(RK2928_PIN1_PB0,"switch_bb_ap");\r
92         gpio_direction_output(gpdata->gpio_switch_fm_ap,GPIO_LOW);      \r
93         \r
94         platform_set_drvdata(pdev, gpdata);     \r
95 \r
96         result = misc_register(&as_misc);\r
97         if(result){\r
98                 gpio_free(gpdata->gpio_switch_fm_ap);\r
99                 kfree(gpdata);\r
100         }       \r
101         return result;\r
102 }\r
103 \r
104 int as_suspend(struct platform_device *pdev, pm_message_t state)\r
105 {\r
106         return 0;\r
107 }\r
108 \r
109 int as_resume(struct platform_device *pdev)\r
110 {\r
111         return 0;\r
112 }\r
113 \r
114 void as_shutdown(struct platform_device *pdev)\r
115 {\r
116     gpio_free(gpdata->gpio_switch_fm_ap);\r
117     kfree(gpdata);\r
118 }\r
119 \r
120 static struct platform_driver as_driver = {\r
121         .probe  = as_probe,\r
122         .shutdown       = as_shutdown,\r
123         .suspend        = as_suspend,\r
124         .resume         = as_resume,\r
125         .driver = {\r
126                 .name   = "audio_switch",\r
127                 .owner  = THIS_MODULE,\r
128         },\r
129 };\r
130 \r
131 static int __init audio_switch_init(void)\r
132 {\r
133         return platform_driver_register(&as_driver);\r
134 }\r
135 \r
136 static void __exit audio_switch_exit(void)\r
137 {\r
138         platform_driver_unregister(&as_driver);\r
139 }\r
140 \r
141 module_init(audio_switch_init);\r
142 \r
143 module_exit(audio_switch_exit);\r