summaryrefslogtreecommitdiffstats
path: root/usb_hal/inc/usb_hal_internal.h
blob: 86c39056a40b8d8c4beca58c0a8a46d497ba78d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
 * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef INC_USB_HAL_INTERNAL_H_
#define INC_USB_HAL_INTERNAL_H_

#define FILE_CONTENT_LENGTH (32)
#define FILE_PATH_LENGTH (128)

/**
 * USB role file
 */
#define USB_ROLE_FILE "/sys/devices/platform/soc/ee080200.usb-phy/role"

/**
 * USB host value
 */
#define USB_HOST_STRING "host\n"

/**
 * USB function value
 */
#define USB_FUNCTION_STRING "peripheral\n"

/**
 * gpio high value
 */
const char kUsbGpioHighValue = '1';

/**
 * gpio low value
 */
const char kUsbGpioLowValue = '0';

/**
 * gpio export file
 */
const char kUsbGpioExportFile[] = "/sys/class/gpio/export";

/**
 * gpio file prefix
 */
const char kUsbGpioFilePrefix[] = "/sys/class/gpio/gpio";

/**
 * gpio direction file
 */
const char kUsbGpioDirectionFile[] = "/direction";

/**
 * gpio direction in
 */
const char kUsbGpioDirectionIn[] = "in";

/**
 * gpio direction out high
 */
const char kUsbGpioDirectionHigh[] = "high";

/**
 * gpio direction out low
 */
const char kUsbGpioDirectionLow[] = "low";

/**
 * gpio value file
 */
const char kUsbGpioValueFile[] = "/value";

/**
 * structure of USB role switch information
 */
struct UsbRoleSwitchInfo {
  const char* file_path;           //!< USB role switch file path
  const char* usb_host_value;      //!< USB host value
  const char* usb_function_value;  //!< USB function value
};

/**
 * USB gpio port definition
 */
enum UsbGpioPort {
  USB_GPIO_PORT_USB0_PWEN = 0,  //!< USB0 power enable
  USB_GPIO_PORT_USB1_PWEN,      //!< USB1 power enable
  USB_GPIO_PORT_USB2_PWEN,      //!< USB2 power enable
  USB_GPIO_PORT_USB0_OVC,       //!< USB0 overcurrent
  USB_GPIO_PORT_USB1_OVC,       //!< USB1 overcurrent
  USB_GPIO_PORT_USB2_OVC,       //!< USB2 overcurrent
  USB_GPIO_PORT_MAX
};

/**
 * USB gpio port value definition
 */
enum GpioPortValue {
  GPIO_PORT_OFF = 0,  //!< gpio port on
  GPIO_PORT_ON        //!< gpio port off
};

/**
 * Length for USB gpio port name
 */
#define USB_PORT_NAME_LENGTH (8)

/**
 * USB gpio port information
 */
struct UsbGpioPortInfo {
  bool active_low;        //!< active low or high
  bool is_output;         //!< direction output or input
  const char* port_name;  //!< gpio port name
  char default_value;     //!< output port default value (high or low)
};

/**
 * USB gpio port config table
 */
const char kUsbGpioPortNameUsb0Pwen[] = "375";
const char kUsbGpioPortNameUsb1Pwen[] = "387";
const char kUsbGpioPortNameUsb2Pwen[] = "389";
const char kUsbGpioPortNameUsb0Ovc[] = "376";
const char kUsbGpioPortNameUsb1Ovc[] = "388";
const char kUsbGpioPortNameUsb2Ovc[] = "390";

const UsbGpioPortInfo kUsbGpioInfo[] = {
  { false, true, kUsbGpioPortNameUsb0Pwen, kUsbGpioHighValue },
  { false, true, kUsbGpioPortNameUsb1Pwen, kUsbGpioHighValue },
  { false, true, kUsbGpioPortNameUsb2Pwen, kUsbGpioHighValue },
  { false, false, kUsbGpioPortNameUsb0Ovc, kUsbGpioLowValue },
  { false, false, kUsbGpioPortNameUsb1Ovc, kUsbGpioLowValue },
  { false, false, kUsbGpioPortNameUsb2Ovc, kUsbGpioLowValue }
};

/**
 * gpio port list of USB power enable
 */
const UsbGpioPort kUsbPowerEnableGpio[] = {
  USB_GPIO_PORT_USB0_PWEN,
  USB_GPIO_PORT_USB1_PWEN,
  USB_GPIO_PORT_USB2_PWEN
};

/**
 * gpio port list of USB overcurrent
 */
const UsbGpioPort kUsbOvercurrentGpio[] = {
  USB_GPIO_PORT_USB0_OVC,
  USB_GPIO_PORT_USB1_OVC,
  USB_GPIO_PORT_USB2_OVC
};

#endif  // INC_USB_HAL_INTERNAL_H_