blob: 55c21e688095e674c7e919506ec37bab901a2a34 [file] [log] [blame]
Matthew.Shyu55f40e92014-07-18 11:47:47 +08001/* main.c */
2
3#include <stdio.h>
4#include <stdlib.h>
5#include <errno.h>
6#include <string.h>
7#include <sys/stat.h>
8#include <sys/types.h>
9
10#include <fcntl.h>
11#include <dirent.h>
12#include "porting.h"
13
14#define LOG_TAG "USBtestpm"
15
Matthew.Shyu55f40e92014-07-18 11:47:47 +080016#include "usbctrl.h"
17
18
19int usbcheck(int index)
20{
21 int rc = 0;
22 rc = usbpower(index,USB_CMD_IF);
23 return rc;
24}
25
26int usbset(int index,int cmd)
27{
28 int rc = 0;
29 rc = usbpower(index,cmd);
30 return rc;
31}
32
33static const char USBA_DEVICE_PATH[] = "/sys/devices/lm0";
34static const char USBB_DEVICE_PATH[] = "/sys/devices/lm1";
35
36int check_usb_devices_exists(int port)
37{
38 if (port == 0) {
39 if (access(USBA_DEVICE_PATH, R_OK) == 0) {
40 return 0;
41 } else {
42 return -1;
43 }
44 } else {
45 if (access(USBB_DEVICE_PATH, R_OK) == 0) {
46 return 0;
47 } else {
48 return -1;
49 }
50 }
51
52}
53
54int main(int argc, char * argv[])
55{
56 int usb_a_exist = 0;
57 int usb_b_exist = 0;
58 int a_on_flag,b_on_flag;
59 int ret;
60 char * parastr=NULL;
61 int para_a=1,para_b=1;
62
63 parastr = argv[1];
64
65 if(parastr!=NULL)
66 {
67 if(strcmp(parastr, "AB")==0)
68 {
69 para_a = 1;
70 para_b = 1;
71 }
72 else if(strcmp(parastr, "A")==0)
73 {
74 para_a = 1;
75 para_b = 0;
76 }
77 else if(strcmp(parastr, "B")==0)
78 {
79 para_a = 0;
80 para_b = 1;
81 }
82 }
83 ret = get_dwc_driver_version();
84
85 if(ret == -1)
86 {
87 printf("This dwc_otg version not support. Please check!\n");
88 return -1;
89 }
90
91 if(para_a && (check_usb_devices_exists(0) == 0))
92 {
93 usb_a_exist = 1;
94 a_on_flag = 1;
95 }
96 else
97 usbset(0,USB_CMD_OFF);
98
99 if (para_b &&(check_usb_devices_exists(1) == 0))
100 {
101 usb_b_exist = 1;
102 b_on_flag = 1;
103 }
104 else
105 usbset(1,USB_CMD_OFF);
106
107 if (usb_a_exist || usb_b_exist) {
108 while(1) {
109 if (usb_a_exist) {
110 if(a_on_flag == 0)
111 {
112 usbset(0,USB_CMD_ON);
113 a_on_flag = 1;
114 usleep(500000);
115 if (usbcheck(0) != 1)
116 {
117 usbset(0,USB_CMD_OFF);
118 a_on_flag = 0;
119 }
120 }
121 else
122 {
123 if (usbcheck(0) != 1)
124 {
125 usbset(0,USB_CMD_OFF);
126 a_on_flag = 0;
127 }
128 }
129 }
130
131 if (usb_b_exist) {
132 if(b_on_flag == 0)
133 {
134 usbset(1,USB_CMD_ON);
135 b_on_flag = 1;
136 usleep(500000);
137 if (usbcheck(1) != 1)
138 {
139 usbset(1,USB_CMD_OFF);
140 b_on_flag = 0;
141 }
142 }
143 else
144 {
145 if (usbcheck(1) != 1)
146 {
147 usbset(1,USB_CMD_OFF);
148 b_on_flag = 0;
149 }
150 }
151 }
152
153 usleep(500000); //
154
155 }
156 }
157
158}
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173