]>
Commit | Line | Data |
---|---|---|
f93022c3 JR |
1 | /* |
2 | * Generic ULPI interface. | |
3 | * | |
4 | * Copyright (C) 2011 Jana Rapava <fermata7@gmail.com> | |
5 | * Copyright (C) 2011 CompuLab, Ltd. <www.compulab.co.il> | |
6 | * | |
7 | * Authors: Jana Rapava <fermata7@gmail.com> | |
8 | * Igor Grinberg <grinberg@compulab.co.il> | |
9 | * | |
10 | * Register offsets taken from: | |
11 | * linux/include/linux/usb/ulpi.h | |
12 | * | |
13 | * Original Copyrights follow: | |
14 | * Copyright (C) 2010 Nokia Corporation | |
15 | * | |
5b8031cc | 16 | * SPDX-License-Identifier: GPL-2.0 |
f93022c3 JR |
17 | */ |
18 | ||
19 | #ifndef __USB_ULPI_H__ | |
20 | #define __USB_ULPI_H__ | |
21 | ||
22 | #define ULPI_ERROR (1 << 8) /* overflow from any register value */ | |
23 | ||
24 | #ifndef CONFIG_USB_ULPI_TIMEOUT | |
25 | #define CONFIG_USB_ULPI_TIMEOUT 1000 /* timeout in us */ | |
26 | #endif | |
27 | ||
3e6e809f G |
28 | /* |
29 | * ulpi view port address and | |
30 | * Port_number that can be passed. | |
31 | * Any additional data to be passed can | |
32 | * be extended from this structure | |
33 | */ | |
34 | struct ulpi_viewport { | |
35 | u32 viewport_addr; | |
36 | u32 port_num; | |
37 | }; | |
38 | ||
f93022c3 JR |
39 | /* |
40 | * Initialize the ULPI transciever and check the interface integrity. | |
3e6e809f | 41 | * @ulpi_vp - structure containing ULPI viewport data |
f93022c3 JR |
42 | * |
43 | * returns 0 on success, ULPI_ERROR on failure. | |
44 | */ | |
3e6e809f | 45 | int ulpi_init(struct ulpi_viewport *ulpi_vp); |
f93022c3 JR |
46 | |
47 | /* | |
48 | * Select transceiver speed. | |
49 | * @speed - ULPI_FC_HIGH_SPEED, ULPI_FC_FULL_SPEED (default), | |
50 | * ULPI_FC_LOW_SPEED, ULPI_FC_FS4LS | |
51 | * returns 0 on success, ULPI_ERROR on failure. | |
52 | */ | |
3e6e809f | 53 | int ulpi_select_transceiver(struct ulpi_viewport *ulpi_vp, unsigned speed); |
f93022c3 JR |
54 | |
55 | /* | |
56 | * Enable/disable VBUS. | |
57 | * @ext_power - external VBUS supply is used (default is false) | |
58 | * @ext_indicator - external VBUS over-current indicator is used | |
59 | * | |
60 | * returns 0 on success, ULPI_ERROR on failure. | |
61 | */ | |
141288b3 LS |
62 | int ulpi_set_vbus(struct ulpi_viewport *ulpi_vp, int on, int ext_power); |
63 | ||
64 | /* | |
65 | * Configure VBUS indicator | |
66 | * @external - external VBUS over-current indicator is used | |
67 | * @passthru - disables ANDing of internal VBUS comparator | |
68 | * with external VBUS input | |
69 | * @complement - inverts the external VBUS input | |
70 | */ | |
71 | int ulpi_set_vbus_indicator(struct ulpi_viewport *ulpi_vp, int external, | |
72 | int passthru, int complement); | |
f93022c3 JR |
73 | |
74 | /* | |
75 | * Enable/disable pull-down resistors on D+ and D- USB lines. | |
76 | * | |
77 | * returns 0 on success, ULPI_ERROR on failure. | |
78 | */ | |
3e6e809f | 79 | int ulpi_set_pd(struct ulpi_viewport *ulpi_vp, int enable); |
f93022c3 JR |
80 | |
81 | /* | |
82 | * Select OpMode. | |
83 | * @opmode - ULPI_FC_OPMODE_NORMAL (default), ULPI_FC_OPMODE_NONDRIVING, | |
84 | * ULPI_FC_OPMODE_DISABLE_NRZI, ULPI_FC_OPMODE_NOSYNC_NOEOP | |
85 | * | |
86 | * returns 0 on success, ULPI_ERROR on failure. | |
87 | */ | |
3e6e809f | 88 | int ulpi_opmode_sel(struct ulpi_viewport *ulpi_vp, unsigned opmode); |
f93022c3 JR |
89 | |
90 | /* | |
91 | * Switch to Serial Mode. | |
92 | * @smode - ULPI_IFACE_6_PIN_SERIAL_MODE or ULPI_IFACE_3_PIN_SERIAL_MODE | |
93 | * | |
94 | * returns 0 on success, ULPI_ERROR on failure. | |
95 | * | |
96 | * Notes: | |
97 | * Switches immediately to Serial Mode. | |
98 | * To return from Serial Mode, STP line needs to be asserted. | |
99 | */ | |
3e6e809f | 100 | int ulpi_serial_mode_enable(struct ulpi_viewport *ulpi_vp, unsigned smode); |
f93022c3 JR |
101 | |
102 | /* | |
103 | * Put PHY into low power mode. | |
104 | * | |
105 | * returns 0 on success, ULPI_ERROR on failure. | |
106 | * | |
107 | * Notes: | |
108 | * STP line must be driven low to keep the PHY in suspend. | |
109 | * To resume the PHY, STP line needs to be asserted. | |
110 | */ | |
3e6e809f | 111 | int ulpi_suspend(struct ulpi_viewport *ulpi_vp); |
f93022c3 JR |
112 | |
113 | /* | |
114 | * Reset the transceiver. ULPI interface and registers are not affected. | |
115 | * | |
116 | * returns 0 on success, ULPI_ERROR on failure. | |
117 | */ | |
3e6e809f | 118 | int ulpi_reset(struct ulpi_viewport *ulpi_vp); |
f93022c3 JR |
119 | |
120 | ||
121 | /* ULPI access methods below must be implemented for each ULPI viewport. */ | |
122 | ||
123 | /* | |
124 | * Write to the ULPI PHY register via the viewport. | |
125 | * @reg - the ULPI register (one of the fields in struct ulpi_regs). | |
126 | * @value - the value - only 8 lower bits are used, others ignored. | |
127 | * | |
128 | * returns 0 on success, ULPI_ERROR on failure. | |
129 | */ | |
3e6e809f | 130 | int ulpi_write(struct ulpi_viewport *ulpi_vp, u8 *reg, u32 value); |
f93022c3 JR |
131 | |
132 | /* | |
133 | * Read the ULPI PHY register content via the viewport. | |
134 | * @reg - the ULPI register (one of the fields in struct ulpi_regs). | |
135 | * | |
136 | * returns register content on success, ULPI_ERROR on failure. | |
137 | */ | |
3e6e809f | 138 | u32 ulpi_read(struct ulpi_viewport *ulpi_vp, u8 *reg); |
f93022c3 JR |
139 | |
140 | /* | |
141 | * Wait for the reset to complete. | |
142 | * The Link must not attempt to access the PHY until the reset has | |
143 | * completed and DIR line is de-asserted. | |
144 | */ | |
3e6e809f | 145 | int ulpi_reset_wait(struct ulpi_viewport *ulpi_vp); |
f93022c3 JR |
146 | |
147 | /* Access Extended Register Set (indicator) */ | |
148 | #define ACCESS_EXT_REGS_OFFSET 0x2f /* read-write */ | |
149 | /* Vendor-specific */ | |
150 | #define VENDOR_SPEC_OFFSET 0x30 | |
151 | ||
152 | /* | |
153 | * Extended Register Set | |
154 | * | |
155 | * Addresses 0x00-0x3F map directly to Immediate Register Set. | |
156 | * Addresses 0x40-0x7F are reserved. | |
157 | * Addresses 0x80-0xff are vendor-specific. | |
158 | */ | |
159 | #define EXT_VENDOR_SPEC_OFFSET 0x80 | |
160 | ||
161 | /* ULPI registers, bits and offsets definitions */ | |
162 | struct ulpi_regs { | |
163 | /* Vendor ID and Product ID: 0x00 - 0x03 Read-only */ | |
164 | u8 vendor_id_low; | |
165 | u8 vendor_id_high; | |
166 | u8 product_id_low; | |
167 | u8 product_id_high; | |
168 | /* Function Control: 0x04 - 0x06 Read */ | |
169 | u8 function_ctrl; /* 0x04 Write */ | |
170 | u8 function_ctrl_set; /* 0x05 Set */ | |
171 | u8 function_ctrl_clear; /* 0x06 Clear */ | |
172 | /* Interface Control: 0x07 - 0x09 Read */ | |
173 | u8 iface_ctrl; /* 0x07 Write */ | |
174 | u8 iface_ctrl_set; /* 0x08 Set */ | |
175 | u8 iface_ctrl_clear; /* 0x09 Clear */ | |
176 | /* OTG Control: 0x0A - 0x0C Read */ | |
177 | u8 otg_ctrl; /* 0x0A Write */ | |
178 | u8 otg_ctrl_set; /* 0x0B Set */ | |
179 | u8 otg_ctrl_clear; /* 0x0C Clear */ | |
180 | /* USB Interrupt Enable Rising: 0x0D - 0x0F Read */ | |
181 | u8 usb_ie_rising; /* 0x0D Write */ | |
182 | u8 usb_ie_rising_set; /* 0x0E Set */ | |
183 | u8 usb_ie_rising_clear; /* 0x0F Clear */ | |
184 | /* USB Interrupt Enable Falling: 0x10 - 0x12 Read */ | |
185 | u8 usb_ie_falling; /* 0x10 Write */ | |
186 | u8 usb_ie_falling_set; /* 0x11 Set */ | |
187 | u8 usb_ie_falling_clear; /* 0x12 Clear */ | |
188 | /* USB Interrupt Status: 0x13 Read-only */ | |
189 | u8 usb_int_status; | |
190 | /* USB Interrupt Latch: 0x14 Read-only with auto-clear */ | |
191 | u8 usb_int_latch; | |
192 | /* Debug: 0x15 Read-only */ | |
193 | u8 debug; | |
194 | /* Scratch Register: 0x16 - 0x18 Read */ | |
195 | u8 scratch; /* 0x16 Write */ | |
196 | u8 scratch_set; /* 0x17 Set */ | |
197 | u8 scratch_clear; /* 0x18 Clear */ | |
198 | /* | |
199 | * Optional Carkit registers: | |
200 | * Carkit Control: 0x19 - 0x1B Read | |
201 | */ | |
202 | u8 carkit_ctrl; /* 0x19 Write */ | |
203 | u8 carkit_ctrl_set; /* 0x1A Set */ | |
204 | u8 carkit_ctrl_clear; /* 0x1B Clear */ | |
205 | /* Carkit Interrupt Delay: 0x1C Read, Write */ | |
206 | u8 carkit_int_delay; | |
207 | /* Carkit Interrupt Enable: 0x1D - 0x1F Read */ | |
208 | u8 carkit_ie; /* 0x1D Write */ | |
209 | u8 carkit_ie_set; /* 0x1E Set */ | |
210 | u8 carkit_ie_clear; /* 0x1F Clear */ | |
211 | /* Carkit Interrupt Status: 0x20 Read-only */ | |
212 | u8 carkit_int_status; | |
213 | /* Carkit Interrupt Latch: 0x21 Read-only with auto-clear */ | |
214 | u8 carkit_int_latch; | |
215 | /* Carkit Pulse Control: 0x22 - 0x24 Read */ | |
216 | u8 carkit_pulse_ctrl; /* 0x22 Write */ | |
217 | u8 carkit_pulse_ctrl_set; /* 0x23 Set */ | |
218 | u8 carkit_pulse_ctrl_clear; /* 0x24 Clear */ | |
219 | /* | |
220 | * Other optional registers: | |
221 | * Transmit Positive Width: 0x25 Read, Write | |
222 | */ | |
223 | u8 transmit_pos_width; | |
224 | /* Transmit Negative Width: 0x26 Read, Write */ | |
225 | u8 transmit_neg_width; | |
226 | /* Receive Polarity Recovery: 0x27 Read, Write */ | |
227 | u8 recv_pol_recovery; | |
228 | /* | |
229 | * Addresses 0x28 - 0x2E are reserved, so we use offsets | |
230 | * for immediate registers with higher addresses | |
231 | */ | |
232 | }; | |
233 | ||
234 | /* | |
235 | * Register Bits | |
236 | */ | |
237 | ||
238 | /* Function Control */ | |
239 | #define ULPI_FC_XCVRSEL_MASK (3 << 0) | |
240 | #define ULPI_FC_HIGH_SPEED (0 << 0) | |
241 | #define ULPI_FC_FULL_SPEED (1 << 0) | |
242 | #define ULPI_FC_LOW_SPEED (2 << 0) | |
243 | #define ULPI_FC_FS4LS (3 << 0) | |
244 | #define ULPI_FC_TERMSELECT (1 << 2) | |
245 | #define ULPI_FC_OPMODE_MASK (3 << 3) | |
246 | #define ULPI_FC_OPMODE_NORMAL (0 << 3) | |
247 | #define ULPI_FC_OPMODE_NONDRIVING (1 << 3) | |
248 | #define ULPI_FC_OPMODE_DISABLE_NRZI (2 << 3) | |
249 | #define ULPI_FC_OPMODE_NOSYNC_NOEOP (3 << 3) | |
250 | #define ULPI_FC_RESET (1 << 5) | |
251 | #define ULPI_FC_SUSPENDM (1 << 6) | |
252 | ||
253 | /* Interface Control */ | |
254 | #define ULPI_IFACE_6_PIN_SERIAL_MODE (1 << 0) | |
255 | #define ULPI_IFACE_3_PIN_SERIAL_MODE (1 << 1) | |
256 | #define ULPI_IFACE_CARKITMODE (1 << 2) | |
257 | #define ULPI_IFACE_CLOCKSUSPENDM (1 << 3) | |
258 | #define ULPI_IFACE_AUTORESUME (1 << 4) | |
259 | #define ULPI_IFACE_EXTVBUS_COMPLEMENT (1 << 5) | |
260 | #define ULPI_IFACE_PASSTHRU (1 << 6) | |
261 | #define ULPI_IFACE_PROTECT_IFC_DISABLE (1 << 7) | |
262 | ||
263 | /* OTG Control */ | |
264 | #define ULPI_OTG_ID_PULLUP (1 << 0) | |
265 | #define ULPI_OTG_DP_PULLDOWN (1 << 1) | |
266 | #define ULPI_OTG_DM_PULLDOWN (1 << 2) | |
267 | #define ULPI_OTG_DISCHRGVBUS (1 << 3) | |
268 | #define ULPI_OTG_CHRGVBUS (1 << 4) | |
269 | #define ULPI_OTG_DRVVBUS (1 << 5) | |
270 | #define ULPI_OTG_DRVVBUS_EXT (1 << 6) | |
271 | #define ULPI_OTG_EXTVBUSIND (1 << 7) | |
272 | ||
273 | /* | |
274 | * USB Interrupt Enable Rising, | |
275 | * USB Interrupt Enable Falling, | |
276 | * USB Interrupt Status and | |
277 | * USB Interrupt Latch | |
278 | */ | |
279 | #define ULPI_INT_HOST_DISCONNECT (1 << 0) | |
280 | #define ULPI_INT_VBUS_VALID (1 << 1) | |
281 | #define ULPI_INT_SESS_VALID (1 << 2) | |
282 | #define ULPI_INT_SESS_END (1 << 3) | |
283 | #define ULPI_INT_IDGRD (1 << 4) | |
284 | ||
285 | /* Debug */ | |
286 | #define ULPI_DEBUG_LINESTATE0 (1 << 0) | |
287 | #define ULPI_DEBUG_LINESTATE1 (1 << 1) | |
288 | ||
289 | /* Carkit Control */ | |
290 | #define ULPI_CARKIT_CTRL_CARKITPWR (1 << 0) | |
291 | #define ULPI_CARKIT_CTRL_IDGNDDRV (1 << 1) | |
292 | #define ULPI_CARKIT_CTRL_TXDEN (1 << 2) | |
293 | #define ULPI_CARKIT_CTRL_RXDEN (1 << 3) | |
294 | #define ULPI_CARKIT_CTRL_SPKLEFTEN (1 << 4) | |
295 | #define ULPI_CARKIT_CTRL_SPKRIGHTEN (1 << 5) | |
296 | #define ULPI_CARKIT_CTRL_MICEN (1 << 6) | |
297 | ||
298 | /* Carkit Interrupt Enable */ | |
299 | #define ULPI_CARKIT_INT_EN_IDFLOAT_RISE (1 << 0) | |
300 | #define ULPI_CARKIT_INT_EN_IDFLOAT_FALL (1 << 1) | |
301 | #define ULPI_CARKIT_INT_EN_CARINTDET (1 << 2) | |
302 | #define ULPI_CARKIT_INT_EN_DP_RISE (1 << 3) | |
303 | #define ULPI_CARKIT_INT_EN_DP_FALL (1 << 4) | |
304 | ||
305 | /* Carkit Interrupt Status and Latch */ | |
306 | #define ULPI_CARKIT_INT_IDFLOAT (1 << 0) | |
307 | #define ULPI_CARKIT_INT_CARINTDET (1 << 1) | |
308 | #define ULPI_CARKIT_INT_DP (1 << 2) | |
309 | ||
310 | /* Carkit Pulse Control*/ | |
311 | #define ULPI_CARKIT_PLS_CTRL_TXPLSEN (1 << 0) | |
312 | #define ULPI_CARKIT_PLS_CTRL_RXPLSEN (1 << 1) | |
313 | #define ULPI_CARKIT_PLS_CTRL_SPKRLEFT_BIASEN (1 << 2) | |
314 | #define ULPI_CARKIT_PLS_CTRL_SPKRRIGHT_BIASEN (1 << 3) | |
315 | ||
316 | ||
317 | #endif /* __USB_ULPI_H__ */ |