Init basesystem source codes.
[staging/basesystem.git] / video_in_hal / usb_hal / inc / usb_hal_internal.h
1 /*
2  * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef INC_USB_HAL_INTERNAL_H_
18 #define INC_USB_HAL_INTERNAL_H_
19
20 #define FILE_CONTENT_LENGTH (32)
21 #define FILE_PATH_LENGTH (128)
22
23 /**
24  * USB role file
25  */
26 #define USB_ROLE_FILE "/sys/devices/platform/soc/ee080200.usb-phy/role"
27
28 /**
29  * USB host value
30  */
31 #define USB_HOST_STRING "host\n"
32
33 /**
34  * USB function value
35  */
36 #define USB_FUNCTION_STRING "peripheral\n"
37
38 /**
39  * gpio high value
40  */
41 const char kUsbGpioHighValue = '1';
42
43 /**
44  * gpio low value
45  */
46 const char kUsbGpioLowValue = '0';
47
48 /**
49  * gpio export file
50  */
51 const char kUsbGpioExportFile[] = "/sys/class/gpio/export";
52
53 /**
54  * gpio file prefix
55  */
56 const char kUsbGpioFilePrefix[] = "/sys/class/gpio/gpio";
57
58 /**
59  * gpio direction file
60  */
61 const char kUsbGpioDirectionFile[] = "/direction";
62
63 /**
64  * gpio direction in
65  */
66 const char kUsbGpioDirectionIn[] = "in";
67
68 /**
69  * gpio direction out high
70  */
71 const char kUsbGpioDirectionHigh[] = "high";
72
73 /**
74  * gpio direction out low
75  */
76 const char kUsbGpioDirectionLow[] = "low";
77
78 /**
79  * gpio value file
80  */
81 const char kUsbGpioValueFile[] = "/value";
82
83 /**
84  * structure of USB role switch information
85  */
86 struct UsbRoleSwitchInfo {
87   const char* file_path;           //!< USB role switch file path
88   const char* usb_host_value;      //!< USB host value
89   const char* usb_function_value;  //!< USB function value
90 };
91
92 /**
93  * USB gpio port definition
94  */
95 enum UsbGpioPort {
96   USB_GPIO_PORT_USB0_PWEN = 0,  //!< USB0 power enable
97   USB_GPIO_PORT_USB1_PWEN,      //!< USB1 power enable
98   USB_GPIO_PORT_USB2_PWEN,      //!< USB2 power enable
99   USB_GPIO_PORT_USB0_OVC,       //!< USB0 overcurrent
100   USB_GPIO_PORT_USB1_OVC,       //!< USB1 overcurrent
101   USB_GPIO_PORT_USB2_OVC,       //!< USB2 overcurrent
102   USB_GPIO_PORT_MAX
103 };
104
105 /**
106  * USB gpio port value definition
107  */
108 enum GpioPortValue {
109   GPIO_PORT_OFF = 0,  //!< gpio port on
110   GPIO_PORT_ON        //!< gpio port off
111 };
112
113 /**
114  * Length for USB gpio port name
115  */
116 #define USB_PORT_NAME_LENGTH (8)
117
118 /**
119  * USB gpio port information
120  */
121 struct UsbGpioPortInfo {
122   bool active_low;        //!< active low or high
123   bool is_output;         //!< direction output or input
124   const char* port_name;  //!< gpio port name
125   char default_value;     //!< output port default value (high or low)
126 };
127
128 /**
129  * USB gpio port config table
130  */
131 const char kUsbGpioPortNameUsb0Pwen[] = "375";
132 const char kUsbGpioPortNameUsb1Pwen[] = "387";
133 const char kUsbGpioPortNameUsb2Pwen[] = "389";
134 const char kUsbGpioPortNameUsb0Ovc[] = "376";
135 const char kUsbGpioPortNameUsb1Ovc[] = "388";
136 const char kUsbGpioPortNameUsb2Ovc[] = "390";
137
138 const UsbGpioPortInfo kUsbGpioInfo[] = {
139   { false, true, kUsbGpioPortNameUsb0Pwen, kUsbGpioHighValue },
140   { false, true, kUsbGpioPortNameUsb1Pwen, kUsbGpioHighValue },
141   { false, true, kUsbGpioPortNameUsb2Pwen, kUsbGpioHighValue },
142   { false, false, kUsbGpioPortNameUsb0Ovc, kUsbGpioLowValue },
143   { false, false, kUsbGpioPortNameUsb1Ovc, kUsbGpioLowValue },
144   { false, false, kUsbGpioPortNameUsb2Ovc, kUsbGpioLowValue }
145 };
146
147 /**
148  * gpio port list of USB power enable
149  */
150 const UsbGpioPort kUsbPowerEnableGpio[] = {
151   USB_GPIO_PORT_USB0_PWEN,
152   USB_GPIO_PORT_USB1_PWEN,
153   USB_GPIO_PORT_USB2_PWEN
154 };
155
156 /**
157  * gpio port list of USB overcurrent
158  */
159 const UsbGpioPort kUsbOvercurrentGpio[] = {
160   USB_GPIO_PORT_USB0_OVC,
161   USB_GPIO_PORT_USB1_OVC,
162   USB_GPIO_PORT_USB2_OVC
163 };
164
165 #endif  // INC_USB_HAL_INTERNAL_H_