--- /dev/null
+#include <linux/input.h>\r
+#include <linux/module.h>\r
+#include <linux/init.h>\r
+#include <linux/interrupt.h>\r
+#include <linux/kernel.h>\r
+#include <linux/fcntl.h>\r
+#include <linux/delay.h>\r
+#include <linux/device.h>\r
+#include <linux/miscdevice.h>\r
+#include <asm/types.h>\r
+#include <mach/gpio.h>\r
+#include <mach/iomux.h>\r
+#include <linux/platform_device.h>\r
+#include <asm/uaccess.h>\r
+#include <linux/wait.h>\r
+#include <mach/board.h>\r
+\r
+#if 1\r
+#define DBG(x...) printk(KERN_INFO x)\r
+#else\r
+#define DBG(x...)\r
+#endif\r
+#define PC_DISPLAY_MODE 1 \r
+#define ANDROID_DISPLAY_MODE 2\r
+\r
+#define USB_SWITCH_IOCTL_BASE 'u'\r
+#define USB_SWITCH_IOCTL_SET_USB_SWITCH_MODE _IOW(USB_SWITCH_IOCTL_BASE, 0x01, int)\r
+#define USB_SWITCH_IOCTL_GET_PC_STATE _IOR(USB_SWITCH_IOCTL_BASE, 0x02, int)\r
+\r
+static struct ac_usb_switch_platform_data *ac_usb_switch;\r
+\r
+\r
+static int setUsbSwitchMode(int mode){\r
+ struct ac_usb_switch_platform_data *pdata = ac_usb_switch;\r
+ if(pdata->usb_switch_pin == INVALID_GPIO){\r
+ DBG(" error ac_usb_switch_pin is null !!!\n");\r
+ return -1;\r
+ }\r
+ switch(mode){\r
+ case PC_DISPLAY_MODE:\r
+ gpio_set_value(pdata->usb_switch_pin,GPIO_LOW); \r
+ break;\r
+ case ANDROID_DISPLAY_MODE:\r
+ gpio_set_value(pdata->usb_switch_pin,GPIO_HIGH);\r
+ break;\r
+ default:\r
+ break;\r
+ }\r
+ return 0;\r
+}\r
+static int getPCstate(){\r
+ return 1;\r
+}\r
+\r
+static int ac_usb_switch_open(struct inode *inode, struct file *filp)\r
+{\r
+ DBG("ac_usb_switch_open\n");\r
+\r
+ return 0;\r
+}\r
+\r
+static ssize_t ac_usb_switch_read(struct file *filp, char __user *ptr, size_t size, loff_t *pos)\r
+{\r
+ if (ptr == NULL)\r
+ printk("%s: user space address is NULL\n", __func__);\r
+ return sizeof(int);\r
+}\r
+\r
+static long ac_usb_switch_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)\r
+{\r
+ long ret = 0; \r
+ int mode;\r
+ struct ac_usb_switch_platform_data *pdata = ac_usb_switch;\r
+\r
+ DBG("ac_usb_switch_ioctl: cmd = %d arg = %ld\n",cmd, arg);\r
+ \r
+ switch (cmd){\r
+ case USB_SWITCH_IOCTL_SET_USB_SWITCH_MODE:\r
+ DBG("ac_usb_switch_ioctl: USB_SWITCH_IOCTL_SET_USB_SWITCH_MODE\n");\r
+ mode = arg;\r
+ setUsbSwitchMode(mode);\r
+ break;\r
+ case USB_SWITCH_IOCTL_GET_PC_STATE:\r
+ DBG("ac_usb_switch_ioctl: USB_SWITCH_IOCTL_GET_PC_STATE\n");\r
+ return getPCstate();\r
+ \r
+ default:\r
+ printk("unknown ioctl cmd!\n");\r
+ ret = -EINVAL;\r
+ break;\r
+ }\r
+ return ret;\r
+}\r
+\r
+static int ac_usb_switch_release(struct inode *inode, struct file *filp)\r
+{\r
+ DBG("ac_usb_switch_release\n");\r
+ \r
+ return 0;\r
+}\r
+\r
+static struct file_operations ac_usb_switch_fops = {\r
+ .owner = THIS_MODULE,\r
+ .open = ac_usb_switch_open,\r
+ .read = ac_usb_switch_read,\r
+ .unlocked_ioctl = ac_usb_switch_ioctl,\r
+ .release = ac_usb_switch_release,\r
+};\r
+\r
+static struct miscdevice ac_usb_switch_dev = \r
+{\r
+ .minor = MISC_DYNAMIC_MINOR,\r
+ .name = "ac_usb_switch",\r
+ .fops = &ac_usb_switch_fops,\r
+};\r
+\r
+static int ac_usb_switch_probe(struct platform_device *pdev)\r
+{\r
+ int ret = 0;\r
+ int result;\r
+ struct ac_usb_switch_platform_data *pdata = pdev->dev.platform_data;\r
+ if(!pdata)\r
+ return -1;\r
+ ac_usb_switch = pdata;\r
+ ret = misc_register(&ac_usb_switch_dev);\r
+ if (ret < 0){\r
+ printk("ac_usb_switch register err!\n");\r
+ return ret;\r
+ }\r
+ \r
+ if(pdata->usb_switch_pin != INVALID_GPIO){\r
+ result = gpio_request(pdata->usb_switch_pin, "ac_usb_switch");\r
+ if(result)\r
+ {\r
+ printk("%s:fail to request gpio %d\n",__func__, pdata->usb_switch_pin);\r
+ //return -1;\r
+ }else{\r
+ gpio_direction_output(pdata->usb_switch_pin,GPIO_HIGH);\r
+ }\r
+ }\r
+\r
+ if(pdata->pc_state_pin != INVALID_GPIO){\r
+ result = gpio_request(pdata->pc_state_pin, "ac_usb_switch");\r
+ if(result)\r
+ {\r
+ printk("%s:fail to request gpio %d\n",__func__, pdata->pc_state_pin);\r
+ //return -1;\r
+ }else{\r
+ gpio_direction_input(pdata->pc_state_pin);\r
+ }\r
+ }\r
+ printk("%s: ok ...... \n", __func__);\r
+\r
+ return ret;\r
+}\r
+\r
+static int ac_usb_switch_suspend(struct platform_device *pdev, pm_message_t state)\r
+{\r
+ struct ac_usb_switch_platform_data *pdata = pdev->dev.platform_data;\r
+\r
+ if(!pdata) {\r
+ printk("%s: pdata = NULL ...... \n", __func__);\r
+ return -1;\r
+ }\r
+ printk("%s\n",__FUNCTION__);\r
+ return 0; \r
+}\r
+\r
+static int ac_usb_switch_resume(struct platform_device *pdev)\r
+{\r
+ struct ac_usb_switch_platform_data *pdata = pdev->dev.platform_data;\r
+\r
+ if(!pdata) {\r
+ printk("%s: pdata = NULL ...... \n", __func__);\r
+ return -1;\r
+ }\r
+ printk("%s\n",__FUNCTION__);\r
+ return 0;\r
+}\r
+\r
+static int ac_usb_switch_remove(struct platform_device *pdev)\r
+{\r
+ struct ac_usb_switch_platform_data *pdata = pdev->dev.platform_data;\r
+ if(!pdata)\r
+ return -1;\r
+\r
+ misc_deregister(&ac_usb_switch_dev);\r
+\r
+ return 0;\r
+}\r
+\r
+static struct platform_driver ac_usb_switch_driver = {\r
+ .probe = ac_usb_switch_probe,\r
+ .remove = ac_usb_switch_remove,\r
+ .suspend = ac_usb_switch_suspend,\r
+ .resume = ac_usb_switch_resume,\r
+ .driver = {\r
+ .name = "ac_usb_switch",\r
+ .owner = THIS_MODULE,\r
+ },\r
+};\r
+\r
+static int __init ac_usb_switch_init(void)\r
+{\r
+ return platform_driver_register(&ac_usb_switch_driver);\r
+}\r
+\r
+static void __exit ac_usb_switch_exit(void)\r
+{\r
+ platform_driver_unregister(&ac_usb_switch_driver);\r
+}\r
+\r
+module_init(ac_usb_switch_init);\r
+module_exit(ac_usb_switch_exit);\r
+MODULE_DESCRIPTION ("ac usb switch driver");\r
+MODULE_LICENSE("GPL");\r
+\r