Matthew.Shyu | 55f40e9 | 2014-07-18 11:47:47 +0800 | [diff] [blame] | 1 | /* main.c */
|
| 2 | /********************************************
|
| 3 | this file because m6 usb power control is defferent with other
|
| 4 | usbA and usbB por is connected.
|
| 5 | *********************************************/
|
| 6 | #include <stdio.h>
|
| 7 | #include <stdlib.h>
|
| 8 | #include <errno.h>
|
| 9 | #include <string.h>
|
| 10 | #include <sys/stat.h>
|
| 11 | #include <sys/types.h>
|
| 12 |
|
| 13 | #include <fcntl.h>
|
| 14 | #include <dirent.h>
|
| 15 | #include "porting.h"
|
| 16 |
|
| 17 | #define LOG_TAG "USBtestpm_mx"
|
| 18 |
|
Matthew.Shyu | 55f40e9 | 2014-07-18 11:47:47 +0800 | [diff] [blame] | 19 | #include "usbctrl.h"
|
| 20 |
|
| 21 |
|
| 22 | int usbcheck(int index)
|
| 23 | {
|
| 24 | int rc = 0;
|
| 25 | rc = usbpower(index,USB_CMD_IF);
|
| 26 | return rc;
|
| 27 | }
|
| 28 |
|
| 29 | int usbset(int index,int cmd)
|
| 30 | {
|
| 31 | int rc = 0;
|
| 32 | rc = usbpower(index,cmd);
|
| 33 | return rc;
|
| 34 | }
|
| 35 |
|
| 36 | static const char USBA_DEVICE_PATH[] = "/sys/devices/lm0";
|
| 37 | static const char USBB_DEVICE_PATH[] = "/sys/devices/lm1";
|
| 38 |
|
| 39 | int check_usb_devices_exists(int port)
|
| 40 | {
|
| 41 | if (port == 0) {
|
| 42 | if (access(USBA_DEVICE_PATH, R_OK) == 0) {
|
| 43 | return 0;
|
| 44 | } else {
|
| 45 | return -1;
|
| 46 | }
|
| 47 | } else {
|
| 48 | if (access(USBB_DEVICE_PATH, R_OK) == 0) {
|
| 49 | return 0;
|
| 50 | } else {
|
| 51 | return -1;
|
| 52 | }
|
| 53 | }
|
| 54 |
|
| 55 | }
|
| 56 |
|
| 57 | int main()
|
| 58 | {
|
| 59 | int usb_a_exist = 0;
|
| 60 | int usb_b_exist = 0;
|
| 61 | int on_flag;
|
| 62 | int checkflag,ret;
|
| 63 |
|
| 64 | ret = get_dwc_driver_version();
|
| 65 |
|
| 66 | if(ret == -1)
|
| 67 | {
|
| 68 | printf("This dwc_otg version not support. Please check!\n");
|
| 69 | return -1;
|
| 70 | }
|
| 71 |
|
| 72 | if (check_usb_devices_exists(0) == 0)
|
| 73 | {
|
| 74 | usb_a_exist = 1;
|
| 75 | on_flag = 1;
|
| 76 | }
|
| 77 | else
|
| 78 | {
|
| 79 | usb_a_exist = 0;
|
| 80 | on_flag = 0;
|
| 81 | }
|
| 82 |
|
| 83 | if (check_usb_devices_exists(1) == 0)
|
| 84 | {
|
| 85 | usb_b_exist = 1;
|
| 86 | on_flag = 1;
|
| 87 | }
|
| 88 | else
|
| 89 | {
|
| 90 | usb_b_exist = 0;
|
| 91 | on_flag = 0;
|
| 92 | }
|
| 93 |
|
| 94 | if (usb_a_exist || usb_b_exist) {
|
| 95 | while(1) {
|
| 96 | if(on_flag == 0)
|
| 97 | {
|
| 98 | usbset(0,USB_CMD_ON);
|
| 99 | on_flag = 1;
|
| 100 | usleep(500000);
|
| 101 | }
|
| 102 | else
|
| 103 | {
|
| 104 | checkflag = 0;
|
| 105 | if(usb_a_exist)
|
| 106 | checkflag |= usbcheck(0);
|
| 107 | if(usb_b_exist)
|
| 108 | checkflag |= usbcheck(1);
|
| 109 | if (checkflag == 0)
|
| 110 | {
|
| 111 | usbset(0,USB_CMD_OFF);
|
| 112 | on_flag = 0;
|
| 113 | }
|
| 114 | sleep(1);
|
| 115 | }
|
| 116 |
|
| 117 | }
|
| 118 | }
|
| 119 | else
|
| 120 | {
|
| 121 | usbset(0,USB_CMD_OFF);
|
| 122 | }
|
| 123 |
|
| 124 | }
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|