1
/*******************************************************************************
3
This software file (the "File") is distributed by Marvell International Ltd.
4
or its affiliate(s) under the terms of the GNU General Public License Version 2,
5
June 1991 (the "License"). You may use, redistribute and/or modify this File
6
in accordance with the terms and conditions of the License, a copy of which
7
is available along with the File in the license.txt file or by writing to the
8
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
9
or on the worldwide web at http://www.gnu.org/licenses/gpl.txt.
11
THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE IMPLIED
12
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY
13
DISCLAIMED. The GPL License provides additional details about this warranty
16
(C) Copyright 2004 - 2007 Marvell Semiconductor Israel Ltd. All Rights Reserved.
17
(C) Copyright 1999 - 2004 Chipidea Microelectronica, S.A. All Rights Reserved.
19
*******************************************************************************/
21
#include "mvUsbDevApi.h"
22
#include "mvUsbDevPrv.h"
23
#include "mvUsbDefs.h"
25
/* Test packet for Test Mode : TEST_PACKET. USB 2.0 Specification section 7.1.20 */
26
uint_8 test_packet[USB_TEST_MODE_TEST_PACKET_LENGTH] =
30
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
31
0x00, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
32
0xAA, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
33
0xEE, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
34
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xBF, 0xDF,
35
0xEF, 0xF7, 0xFB, 0xFD, 0xFC, 0x7E, 0xBF, 0xDF,
36
0xEF, 0xF7, 0xFB, 0xFD, 0x7E
39
/*FUNCTION*-------------------------------------------------------------
41
* Function Name : _usb_dci_vusb20_assert_resume
42
* Returned Value : None
44
* Resume signalling for remote wakeup
46
*END*-----------------------------------------------------------------*/
47
void _usb_dci_vusb20_assert_resume
49
/* [IN] the USB_dev_initialize state structure */
50
_usb_device_handle handle
53
USB_DEV_STATE_STRUCT_PTR usb_dev_ptr;
54
VUSB20_REG_STRUCT_PTR dev_ptr;
57
usb_dev_ptr = (USB_DEV_STATE_STRUCT_PTR)handle;
58
dev_ptr = (VUSB20_REG_STRUCT_PTR)usb_dev_ptr->DEV_PTR;
60
/* Assert the Resume signal */
61
temp = USB_32BIT_LE(dev_ptr->REGISTERS.OPERATIONAL_DEVICE_REGISTERS.PORTSCX[0]);
62
temp &= ~EHCI_PORTSCX_W1C_BITS;
63
temp |= EHCI_PORTSCX_PORT_FORCE_RESUME;
64
dev_ptr->REGISTERS.OPERATIONAL_DEVICE_REGISTERS.PORTSCX[0] = USB_32BIT_LE(temp);
66
/* Port change interrupt will be asserted at the end of resume
72
/*FUNCTION*-------------------------------------------------------------
74
* Function Name : _usb_dci_vusb20_stall_endpoint
75
* Returned Value : None
77
* Stalls the specified endpoint
79
*END*-----------------------------------------------------------------*/
80
void _usb_dci_vusb20_stall_endpoint
82
/* [IN] the USB_dev_initialize state structure */
83
_usb_device_handle handle,
85
/* [IN] the Endpoint number */
92
USB_DEV_STATE_STRUCT_PTR usb_dev_ptr;
93
VUSB20_REG_STRUCT_PTR dev_ptr;
94
VUSB20_EP_QUEUE_HEAD_STRUCT _PTR_ ep_queue_head_ptr;
96
usb_dev_ptr = (USB_DEV_STATE_STRUCT_PTR)handle;
97
dev_ptr = (VUSB20_REG_STRUCT_PTR)usb_dev_ptr->DEV_PTR;
99
/* Get the endpoint queue head address */
100
ep_queue_head_ptr = (VUSB20_EP_QUEUE_HEAD_STRUCT_PTR)usb_dev_ptr->EP_QUEUE_HEAD_PTR +
101
2*ep_num + direction;
102
/* Stall the endpoint for Rx or Tx and set the endpoint type */
103
if (ep_queue_head_ptr->MAX_PKT_LENGTH & USB_32BIT_LE(VUSB_EP_QUEUE_HEAD_IOS))
105
/* This is a control endpoint so STALL both directions */
106
dev_ptr->REGISTERS.OPERATIONAL_DEVICE_REGISTERS.ENDPTCTRLX[ep_num] |=
107
USB_32BIT_LE((EHCI_EPCTRL_TX_EP_STALL | EHCI_EPCTRL_RX_EP_STALL));
113
dev_ptr->REGISTERS.OPERATIONAL_DEVICE_REGISTERS.ENDPTCTRLX[ep_num] |=
114
USB_32BIT_LE(EHCI_EPCTRL_TX_EP_STALL);
117
dev_ptr->REGISTERS.OPERATIONAL_DEVICE_REGISTERS.ENDPTCTRLX[ep_num] |=
118
USB_32BIT_LE(EHCI_EPCTRL_RX_EP_STALL);
122
ARC_DEBUG_TRACE(ARC_DEBUG_FLAG_STALL,
123
"STALL ep=%d %s: EPCTRLX=0x%x, CURR_dTD=0x%x, NEXT_dTD=0x%x, SIZE=0x%x\n",
124
ep_num, direction ? "SEND" : "RECV",
125
(unsigned)USB_32BIT_LE(dev_ptr->REGISTERS.OPERATIONAL_DEVICE_REGISTERS.ENDPTCTRLX[ep_num]),
126
(unsigned)USB_32BIT_LE(ep_queue_head_ptr->CURR_DTD_PTR),
127
(unsigned)USB_32BIT_LE(ep_queue_head_ptr->NEXT_DTD_PTR),
128
(unsigned)USB_32BIT_LE(ep_queue_head_ptr->SIZE_IOC_INT_STS));
132
/*FUNCTION*-------------------------------------------------------------
134
* Function Name : _usb_dci_vusb20_unstall_endpoint
135
* Returned Value : None
137
* Unstall the specified endpoint in the specified direction
139
*END*-----------------------------------------------------------------*/
140
void _usb_dci_vusb20_unstall_endpoint
142
/* [IN] the USB_dev_initialize state structure */
143
_usb_device_handle handle,
145
/* [IN] the Endpoint number */
152
USB_DEV_STATE_STRUCT_PTR usb_dev_ptr;
153
VUSB20_REG_STRUCT_PTR dev_ptr;
155
usb_dev_ptr = (USB_DEV_STATE_STRUCT_PTR)handle;
156
dev_ptr = (VUSB20_REG_STRUCT_PTR)usb_dev_ptr->DEV_PTR;
158
/* Enable the endpoint for Rx or Tx and set the endpoint type */
161
dev_ptr->REGISTERS.OPERATIONAL_DEVICE_REGISTERS.ENDPTCTRLX[ep_num] |=
162
USB_32BIT_LE(EHCI_EPCTRL_TX_DATA_TOGGLE_RST);
164
dev_ptr->REGISTERS.OPERATIONAL_DEVICE_REGISTERS.ENDPTCTRLX[ep_num] &=
165
~(USB_32BIT_LE(EHCI_EPCTRL_TX_EP_STALL));
169
dev_ptr->REGISTERS.OPERATIONAL_DEVICE_REGISTERS.ENDPTCTRLX[ep_num] |=
170
USB_32BIT_LE(EHCI_EPCTRL_RX_DATA_TOGGLE_RST);
172
dev_ptr->REGISTERS.OPERATIONAL_DEVICE_REGISTERS.ENDPTCTRLX[ep_num] &=
173
~(USB_32BIT_LE(EHCI_EPCTRL_RX_EP_STALL));
176
ARC_DEBUG_TRACE(ARC_DEBUG_FLAG_STALL,
177
"UNSTALL ep=%d %s: EPCTRLX=0x%x\n",
178
ep_num, direction ? "SEND" : "RECV",
179
(unsigned)USB_32BIT_LE(dev_ptr->REGISTERS.OPERATIONAL_DEVICE_REGISTERS.ENDPTCTRLX[ep_num]));
184
/*FUNCTION*----------------------------------------------------------------
186
* Function Name : _usb_dci_vusb20_is_endpoint_stalled
187
* Returned Value : None
189
* Gets the endpoint status
191
*END*--------------------------------------------------------------------*/
192
uint_8 _usb_dci_vusb20_is_endpoint_stalled
194
/* [IN] Handle to the USB device */
195
_usb_device_handle handle,
197
/* [IN] Endpoint number */
200
/* [IN] Endpoint direction */
204
USB_DEV_STATE_STRUCT_PTR usb_dev_ptr;
205
VUSB20_REG_STRUCT_PTR dev_ptr;
208
ARC_DEBUG_TRACE(ARC_DEBUG_FLAG_TRACE, "is_endpoint_stalled\n");
210
usb_dev_ptr = (USB_DEV_STATE_STRUCT_PTR)handle;
211
dev_ptr = (VUSB20_REG_STRUCT_PTR)usb_dev_ptr->DEV_PTR;
215
value = dev_ptr->REGISTERS.OPERATIONAL_DEVICE_REGISTERS.ENDPTCTRLX[ep] &
216
(USB_32BIT_LE(EHCI_EPCTRL_TX_EP_STALL));
220
value = dev_ptr->REGISTERS.OPERATIONAL_DEVICE_REGISTERS.ENDPTCTRLX[ep] &
221
(USB_32BIT_LE(EHCI_EPCTRL_RX_EP_STALL));
223
return (value) ? 1 : 0;
226
/*FUNCTION*----------------------------------------------------------------
228
* Function Name : _usb_dci_vusb20_set_test_mode
229
* Returned Value : None
231
* sets/resets the test mode
233
*END*--------------------------------------------------------------------*/
234
void _usb_dci_vusb20_set_test_mode
236
/* [IN] Handle to the USB device */
237
_usb_device_handle handle,
243
USB_DEV_STATE_STRUCT_PTR usb_dev_ptr;
244
VUSB20_REG_STRUCT_PTR dev_ptr;
247
ARC_DEBUG_TRACE(ARC_DEBUG_FLAG_ANY, "set_test_mode\n");
249
usb_dev_ptr = (USB_DEV_STATE_STRUCT_PTR)handle;
250
dev_ptr = (VUSB20_REG_STRUCT_PTR)usb_dev_ptr->DEV_PTR;
252
temp = USB_32BIT_LE(dev_ptr->REGISTERS.OPERATIONAL_DEVICE_REGISTERS.ENDPTCTRLX[0]);
254
dev_ptr->REGISTERS.OPERATIONAL_DEVICE_REGISTERS.ENDPTCTRLX[0] =
255
USB_32BIT_LE((temp | EHCI_EPCTRL_TX_DATA_TOGGLE_RST));
257
if (test_mode == ARC_USB_TEST_MODE_TEST_PACKET)
259
USB_memcopy(test_packet, usb_dev_ptr->TEST_PKT_PTR, USB_TEST_MODE_TEST_PACKET_LENGTH);
260
_usb_device_send_data(handle, 0, usb_dev_ptr->TEST_PKT_PTR, USB_TEST_MODE_TEST_PACKET_LENGTH);
264
temp = USB_32BIT_LE(dev_ptr->REGISTERS.OPERATIONAL_DEVICE_REGISTERS.PORTSCX[0]);
265
temp &= ~EHCI_PORTSCX_W1C_BITS;
267
dev_ptr->REGISTERS.OPERATIONAL_DEVICE_REGISTERS.PORTSCX[0] =
268
USB_32BIT_LE(temp | ((uint_32)test_mode << 8));