1 #include <linux/input.h>
\r
2 #include <linux/module.h>
\r
3 #include <linux/init.h>
\r
4 #include <linux/interrupt.h>
\r
5 #include <linux/kernel.h>
\r
6 #include <linux/fcntl.h>
\r
7 #include <linux/delay.h>
\r
8 #include <linux/device.h>
\r
9 #include <linux/miscdevice.h>
\r
10 #include <asm/types.h>
\r
11 #include <mach/gpio.h>
\r
12 #include <mach/iomux.h>
\r
13 #include <linux/platform_device.h>
\r
14 #include <asm/uaccess.h>
\r
15 #include <linux/wait.h>
\r
16 #include <mach/board.h>
\r
19 #define DBG(x...) printk(KERN_INFO x)
\r
23 #define PC_DISPLAY_MODE 2
\r
24 #define ANDROID_DISPLAY_MODE 1
\r
26 #define USB_SWITCH_IOCTL_BASE 'u'
\r
27 #define USB_SWITCH_IOCTL_SET_USB_SWITCH_MODE _IOW(USB_SWITCH_IOCTL_BASE, 0x01, int)
\r
28 #define USB_SWITCH_IOCTL_GET_PC_STATE _IOR(USB_SWITCH_IOCTL_BASE, 0x02, int)
\r
30 static struct ac_usb_switch_platform_data *ac_usb_switch;
\r
33 static int setUsbSwitchMode(int mode){
\r
34 struct ac_usb_switch_platform_data *pdata = ac_usb_switch;
\r
35 if(pdata->usb_switch_pin == INVALID_GPIO){
\r
36 DBG(" error ac_usb_switch_pin is null !!!\n");
\r
40 case PC_DISPLAY_MODE:
\r
41 gpio_set_value(pdata->usb_switch_pin,GPIO_LOW);
\r
43 case ANDROID_DISPLAY_MODE:
\r
44 gpio_set_value(pdata->usb_switch_pin,GPIO_HIGH);
\r
51 static int getPCstate(){
\r
55 static int ac_usb_switch_open(struct inode *inode, struct file *filp)
\r
57 DBG("ac_usb_switch_open\n");
\r
62 static ssize_t ac_usb_switch_read(struct file *filp, char __user *ptr, size_t size, loff_t *pos)
\r
65 printk("%s: user space address is NULL\n", __func__);
\r
69 static long ac_usb_switch_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
\r
73 struct ac_usb_switch_platform_data *pdata = ac_usb_switch;
\r
75 DBG("ac_usb_switch_ioctl: cmd = %d arg = %ld\n",cmd, arg);
\r
78 case USB_SWITCH_IOCTL_SET_USB_SWITCH_MODE:
\r
79 DBG("ac_usb_switch_ioctl: USB_SWITCH_IOCTL_SET_USB_SWITCH_MODE\n");
\r
81 setUsbSwitchMode(mode);
\r
83 case USB_SWITCH_IOCTL_GET_PC_STATE:
\r
84 DBG("ac_usb_switch_ioctl: USB_SWITCH_IOCTL_GET_PC_STATE\n");
\r
85 return getPCstate();
\r
88 printk("unknown ioctl cmd!\n");
\r
95 static int ac_usb_switch_release(struct inode *inode, struct file *filp)
\r
97 DBG("ac_usb_switch_release\n");
\r
102 static struct file_operations ac_usb_switch_fops = {
\r
103 .owner = THIS_MODULE,
\r
104 .open = ac_usb_switch_open,
\r
105 .read = ac_usb_switch_read,
\r
106 .unlocked_ioctl = ac_usb_switch_ioctl,
\r
107 .release = ac_usb_switch_release,
\r
110 static struct miscdevice ac_usb_switch_dev =
\r
112 .minor = MISC_DYNAMIC_MINOR,
\r
113 .name = "ac_usb_switch",
\r
114 .fops = &ac_usb_switch_fops,
\r
117 static int ac_usb_switch_probe(struct platform_device *pdev)
\r
121 struct ac_usb_switch_platform_data *pdata = pdev->dev.platform_data;
\r
124 ac_usb_switch = pdata;
\r
125 ret = misc_register(&ac_usb_switch_dev);
\r
127 printk("ac_usb_switch register err!\n");
\r
131 if(pdata->usb_switch_pin != INVALID_GPIO){
\r
132 result = gpio_request(pdata->usb_switch_pin, "ac_usb_switch");
\r
135 printk("%s:fail to request gpio %d\n",__func__, pdata->usb_switch_pin);
\r
138 gpio_direction_output(pdata->usb_switch_pin,GPIO_HIGH);
\r
142 if(pdata->pc_state_pin != INVALID_GPIO){
\r
143 result = gpio_request(pdata->pc_state_pin, "ac_usb_switch");
\r
146 printk("%s:fail to request gpio %d\n",__func__, pdata->pc_state_pin);
\r
149 gpio_direction_input(pdata->pc_state_pin);
\r
152 printk("%s: ok ...... \n", __func__);
\r
157 static int ac_usb_switch_suspend(struct platform_device *pdev, pm_message_t state)
\r
159 struct ac_usb_switch_platform_data *pdata = pdev->dev.platform_data;
\r
162 printk("%s: pdata = NULL ...... \n", __func__);
\r
165 printk("%s\n",__FUNCTION__);
\r
169 static int ac_usb_switch_resume(struct platform_device *pdev)
\r
171 struct ac_usb_switch_platform_data *pdata = pdev->dev.platform_data;
\r
174 printk("%s: pdata = NULL ...... \n", __func__);
\r
177 printk("%s\n",__FUNCTION__);
\r
181 static int ac_usb_switch_remove(struct platform_device *pdev)
\r
183 struct ac_usb_switch_platform_data *pdata = pdev->dev.platform_data;
\r
187 misc_deregister(&ac_usb_switch_dev);
\r
192 static struct platform_driver ac_usb_switch_driver = {
\r
193 .probe = ac_usb_switch_probe,
\r
194 .remove = ac_usb_switch_remove,
\r
195 .suspend = ac_usb_switch_suspend,
\r
196 .resume = ac_usb_switch_resume,
\r
198 .name = "ac_usb_switch",
\r
199 .owner = THIS_MODULE,
\r
203 static int __init ac_usb_switch_init(void)
\r
205 return platform_driver_register(&ac_usb_switch_driver);
\r
208 static void __exit ac_usb_switch_exit(void)
\r
210 platform_driver_unregister(&ac_usb_switch_driver);
\r
213 module_init(ac_usb_switch_init);
\r
214 module_exit(ac_usb_switch_exit);
\r
215 MODULE_DESCRIPTION ("ac usb switch driver");
\r
216 MODULE_LICENSE("GPL");
\r