1 /******************************************************************************
3 * Copyright (C) 2017 Xilinx, Inc. All rights reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
31 ******************************************************************************/
32 /*****************************************************************************/
35 * @file xusb_wrapper.c
37 * This file contains implementation of USBPSU Driver wrappers.
40 * MODIFICATION HISTORY:
42 * Ver Who Date Changes
43 * ----- ---- -------- -------------------------------------------------------
44 * 1.0 BK 12/01/18 First release
45 * MYK 12/01/18 Added hibernation support for device mode
46 * vak 13/03/18 Moved the setup interrupt system calls from driver to
51 *****************************************************************************/
53 /***************************** Include Files *********************************/
54 #include "xusb_wrapper.h"
56 /************************** Variable Definitions *****************************/
58 /************************** Function Prototypes ******************************/
59 Usb_Config* LookupConfig(u16 DeviceId)
61 return XUsbPsu_LookupConfig(DeviceId);
69 s32 CfgInitialize(struct Usb_DevData *InstancePtr,
70 Usb_Config *ConfigPtr, u32 BaseAddress)
72 PrivateData.AppData = InstancePtr;
73 InstancePtr->PrivateData = (void *)&PrivateData;
75 return XUsbPsu_CfgInitialize((struct XUsbPsu *)InstancePtr->PrivateData,
76 ConfigPtr, BaseAddress);
81 void (*func)(struct Usb_DevData *, SetupPacket *))
83 XUsbPsu_set_ch9handler((struct XUsbPsu *)InstancePtr, func);
86 void Set_RstHandler(void *InstancePtr, void (*func)(struct Usb_DevData *))
88 XUsbPsu_set_rsthandler((struct XUsbPsu *)InstancePtr, func);
91 void Set_Disconnect(void *InstancePtr, void (*func)(struct Usb_DevData *))
93 XUsbPsu_set_disconnect((struct XUsbPsu *)InstancePtr, func);
96 void EpConfigure(void *UsbInstance, u8 EndpointNo, u8 dir, u32 Type)
104 s32 ConfigureDevice(void *UsbInstance, u8 *MemPtr, u32 memSize)
112 void SetEpHandler(void *InstancePtr, u8 Epnum,
113 u8 Dir, void (*Handler)(void *, u32, u32))
115 XUsbPsu_SetEpHandler((struct XUsbPsu *)InstancePtr, Epnum, Dir, Handler);
118 s32 Usb_Start(void *InstancePtr)
120 return XUsbPsu_Start((struct XUsbPsu *)InstancePtr);
123 void *Get_DrvData(void *InstancePtr)
125 return XUsbPsu_get_drvdata((struct XUsbPsu *)InstancePtr);
128 void Set_DrvData(void *InstancePtr, void *data)
130 XUsbPsu_set_drvdata((struct XUsbPsu *)InstancePtr, data);
133 s32 IsEpStalled(void *InstancePtr, u8 Epnum, u8 Dir)
135 return XUsbPsu_IsEpStalled((struct XUsbPsu *)InstancePtr, Epnum, Dir);
138 void EpClearStall(void *InstancePtr, u8 Epnum, u8 Dir)
140 XUsbPsu_EpClearStall((struct XUsbPsu *)InstancePtr, Epnum, Dir);
143 s32 EpBufferSend(void *InstancePtr, u8 UsbEp,
144 u8 *BufferPtr, u32 BufferLen)
146 if (UsbEp == 0 && BufferLen == 0)
149 return XUsbPsu_EpBufferSend((struct XUsbPsu *)InstancePtr,
150 UsbEp, BufferPtr, BufferLen);
154 s32 EpBufferRecv(void *InstancePtr, u8 UsbEp,
155 u8 *BufferPtr, u32 Length)
157 return XUsbPsu_EpBufferRecv((struct XUsbPsu *)InstancePtr, UsbEp,
161 void EpSetStall(void *InstancePtr, u8 Epnum, u8 Dir)
163 XUsbPsu_EpSetStall((struct XUsbPsu *)InstancePtr, Epnum, Dir);
166 void SetBits(void *InstancePtr, u32 TestSel)
172 s32 SetDeviceAddress(void *InstancePtr, u16 Addr)
174 return XUsbPsu_SetDeviceAddress((struct XUsbPsu *)InstancePtr, Addr);
177 s32 SetU1SleepTimeout(void *InstancePtr, u8 Sleep)
179 return XUsbPsu_SetU1SleepTimeout((struct XUsbPsu *)InstancePtr, Sleep);
182 s32 SetU2SleepTimeout(void *InstancePtr, u8 Sleep)
184 return XUsbPsu_SetU2SleepTimeout((struct XUsbPsu *)InstancePtr, Sleep);
187 s32 AcceptU1U2Sleep(void *InstancePtr)
189 return XUsbPsu_AcceptU1U2Sleep((struct XUsbPsu *)InstancePtr);
193 s32 U1SleepEnable(void *InstancePtr)
195 return XUsbPsu_U1SleepEnable((struct XUsbPsu *)InstancePtr);
198 s32 U2SleepEnable(void *InstancePtr)
200 return XUsbPsu_U2SleepEnable((struct XUsbPsu *)InstancePtr);
203 s32 U1SleepDisable(void *InstancePtr)
205 return XUsbPsu_U1SleepDisable((struct XUsbPsu *)InstancePtr);
208 s32 U2SleepDisable(void *InstancePtr)
210 return XUsbPsu_U2SleepDisable((struct XUsbPsu *)InstancePtr);
213 s32 EpEnable(void *InstancePtr, u8 UsbEpNum, u8 Dir, u16 Maxsize, u8 Type)
215 return XUsbPsu_EpEnable((struct XUsbPsu *)InstancePtr, UsbEpNum, Dir,
216 Maxsize, Type, FALSE);
219 s32 EpDisable(void *InstancePtr, u8 UsbEpNum, u8 Dir)
221 return XUsbPsu_EpDisable((struct XUsbPsu *)InstancePtr, UsbEpNum, Dir);
224 void Usb_SetSpeed(void *InstancePtr, u32 Speed)
226 XUsbPsu_SetSpeed((struct XUsbPsu *)InstancePtr, Speed);
229 /****************************************************************************/
231 * Sets speed of the Core for connecting to Host
233 * @param InstancePtr is a pointer to the Usb_DevData instance.
235 * @return XST_SUCCESS else XST_FAILURE
239 *****************************************************************************/
240 s32 IsSuperSpeed(struct Usb_DevData *InstancePtr)
242 if (InstancePtr->Speed != XUSBPSU_SPEED_SUPER) {
249 /****************************************************************************/
251 * Set the Config state
253 * @param InstancePtr is a private member of Usb_DevData instance.
254 * @param Flag is the config value.
260 *****************************************************************************/
261 void SetConfigDone(void *InstancePtr, u8 Flag)
263 ((struct XUsbPsu *)InstancePtr)->IsConfigDone = Flag;
266 /****************************************************************************/
268 * Get the Config state
270 * @param InstancePtr is a private member of Usb_DevData instance.
272 * @return Current configuration value
276 *****************************************************************************/
277 u8 GetConfigDone(void *InstancePtr)
279 return (((struct XUsbPsu *)InstancePtr)->IsConfigDone);
282 void Ep0StallRestart(void *InstancePtr)
284 XUsbPsu_Ep0StallRestart((struct XUsbPsu *)InstancePtr);
287 /******************************************************************************/
289 * This function sets Endpoint Interval.
291 * @param InstancePtr is a private member of Usb_DevData instance.
292 * @param UsbEpnum is Endpoint Number.
293 * @param Dir is Endpoint Direction(In/Out).
294 * @param Interval is the data transfer service interval
300 ******************************************************************************/
301 void SetEpInterval(void *InstancePtr, u8 UsbEpNum, u8 Dir, u32 Interval)
304 struct XUsbPsu_Ep *Ept;
306 PhyEpNum = PhysicalEp(UsbEpNum, Dir);
307 Ept = &((struct XUsbPsu *)InstancePtr)->eps[PhyEpNum];
308 Ept->Interval = Interval;
311 void StopTransfer(void *InstancePtr, u8 EpNum, u8 Dir)
313 XUsbPsu_StopTransfer((struct XUsbPsu *)InstancePtr, EpNum, Dir, TRUE);
316 s32 StreamOn(void *InstancePtr, u8 EpNum, u8 Dir, u8 *BufferPtr)
322 /* Streaming will start on TxferNotReady Event */
326 void StreamOff(void *InstancePtr, u8 EpNum, u8 Dir)
328 StopTransfer((struct XUsbPsu *)InstancePtr, EpNum, Dir);