Skip to content

Commit 9ce2fa0

Browse files
middleware: usb: update mcux usb host controller driver to support zephyr
- add one porting file to use SDK usb host driver files in Zephyr - EHCI and KHCI driver include Zephyr USB port file if it is Zephyr environment Signed-off-by: Mark Wang <yichang.wang@nxp.com>
1 parent 191af61 commit 9ce2fa0

File tree

3 files changed

+319
-1
lines changed

3 files changed

+319
-1
lines changed

mcux/middleware/mcux-sdk-middleware-usb/host/usb_host_ehci.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
*/
88
#include "usb_host_config.h"
99
#if ((defined USB_HOST_CONFIG_EHCI) && (USB_HOST_CONFIG_EHCI > 0U))
10+
#if (defined CONFIG_UHC_DRIVER)
11+
#include "usb_host_mcux_drv_port.h"
12+
#include "fsl_device_registers.h"
13+
#include "usb_host_ehci.h"
14+
#if ((defined FSL_FEATURE_SOC_USBPHY_COUNT) && (FSL_FEATURE_SOC_USBPHY_COUNT))
15+
#include "usb_phy.h"
16+
#endif
17+
#else
1018
#include "usb_host.h"
1119
#include "usb_host_hci.h"
1220
#include "usb_host_devices.h"
@@ -21,6 +29,7 @@
2129
#if ((defined USB_HOST_CONFIG_COMPLIANCE_TEST) && (USB_HOST_CONFIG_COMPLIANCE_TEST))
2230
#include "usb_host.h"
2331
#endif
32+
#endif
2433
#if (defined(FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET) && (FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET > 0U))
2534
#include "fsl_memory.h"
2635
#endif

mcux/middleware/mcux-sdk-middleware-usb/host/usb_host_khci.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,18 @@
88

99
#include "usb_host_config.h"
1010
#if ((defined USB_HOST_CONFIG_KHCI) && (USB_HOST_CONFIG_KHCI))
11+
#if (defined CONFIG_UHC_DRIVER)
12+
#include "usb_host_mcux_drv_port.h"
13+
#include "fsl_device_registers.h"
14+
#include "usb_host_khci.h"
15+
#else
1116
#include "usb_host.h"
1217
#include "usb_host_hci.h"
1318
#include "fsl_device_registers.h"
1419
#include "usb_host_khci.h"
1520
#include "usb_host_devices.h"
1621
#include "usb_host_framework.h"
22+
#endif
1723
/*******************************************************************************
1824
* Variables
1925
******************************************************************************/
@@ -1703,7 +1709,7 @@ usb_status_t USB_HostKhciOpenPipe(usb_host_controller_handle controllerHandle,
17031709
{
17041710
usb_khci_host_state_struct_t *usbHostPointer = (usb_khci_host_state_struct_t *)controllerHandle;
17051711
usb_host_pipe_t *pipePointer;
1706-
usb_host_pipe_t *prePipePointer;
1712+
usb_host_pipe_t *prePipePointer = NULL;
17071713
usb_host_pipe_t *tempPipePointer;
17081714

17091715
OSA_SR_ALLOC();
Lines changed: 303 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,303 @@
1+
/*
2+
* Copyright 2024 NXP
3+
* All rights reserved.
4+
*
5+
* SPDX-License-Identifier: BSD-3-Clause
6+
*/
7+
8+
#ifndef _USB_HOST_MCUX_DRV_PORT_H_
9+
#define _USB_HOST_MCUX_DRV_PORT_H_
10+
11+
/*******************************************************************************
12+
* Definitions
13+
******************************************************************************/
14+
15+
/*! @brief USB host controller handle type define */
16+
typedef void *usb_host_controller_handle;
17+
18+
/*! @brief USB host pipe handle type define */
19+
typedef void *usb_host_pipe_handle;
20+
21+
/*! @brief USB host configuration handle type define */
22+
typedef void *usb_host_configuration_handle;
23+
24+
/*! @brief USB host controller control code */
25+
typedef enum _usb_host_controller_control {
26+
kUSB_HostCancelTransfer = 1U, /*!< Cancel transfer code */
27+
kUSB_HostBusControl, /*!< Bus control code */
28+
kUSB_HostGetFrameNumber, /*!< Get frame number code */
29+
kUSB_HostUpdateControlEndpointAddress, /*!< Update control endpoint address */
30+
kUSB_HostUpdateControlPacketSize, /*!< Update control endpoint maximum packet size */
31+
kUSB_HostPortAttachDisable, /*!< Disable the port attach event */
32+
kUSB_HostPortAttachEnable, /*!< Enable the port attach event */
33+
kUSB_HostL1Config, /*!< L1 suspend Bus control code */
34+
kUSB_HostSetChargerType, /*!< set charger type */
35+
#if ((defined USB_HOST_CONFIG_COMPLIANCE_TEST) && (USB_HOST_CONFIG_COMPLIANCE_TEST))
36+
kUSB_HostTestModeInit, /*!< initialize charger type */
37+
#endif
38+
} usb_host_controller_control_t;
39+
40+
/*! @brief USB host controller bus control code */
41+
typedef enum _usb_host_bus_control {
42+
kUSB_HostBusReset = 1U, /*!< Reset bus */
43+
kUSB_HostBusRestart, /*!< Restart bus */
44+
kUSB_HostBusEnableAttach, /*!< Enable attach */
45+
kUSB_HostBusDisableAttach, /*!< Disable attach */
46+
kUSB_HostBusSuspend, /*!< Suspend BUS */
47+
kUSB_HostBusResume, /*!< Resume BUS */
48+
kUSB_HostBusL1SuspendInit, /*!< L1 Suspend BUS */
49+
kUSB_HostBusL1Sleep, /*!< L1 Suspend BUS */
50+
kUSB_HostBusL1Resume, /*!< L1 Resume BUS */
51+
} usb_host_bus_control_t;
52+
53+
/*! @brief USB host device information code */
54+
typedef enum _usb_host_dev_info {
55+
kUSB_HostGetDeviceAddress = 1U, /*!< Device's address */
56+
kUSB_HostGetDeviceHubNumber, /*!< Device's first hub address */
57+
kUSB_HostGetDevicePortNumber, /*!< Device's first hub port number */
58+
kUSB_HostGetDeviceSpeed, /*!< Device's speed */
59+
kUSB_HostGetDeviceHSHubNumber, /*!< Device's first high-speed hub address */
60+
kUSB_HostGetDeviceHSHubPort, /*!< Device's first high-speed hub number */
61+
kUSB_HostGetDeviceLevel, /*!< Device's hub level */
62+
kUSB_HostGetHostHandle, /*!< Device's host handle */
63+
kUSB_HostGetDeviceControlPipe, /*!< Device's control pipe handle */
64+
kUSB_HostGetDevicePID, /*!< Device's PID */
65+
kUSB_HostGetDeviceVID, /*!< Device's VID */
66+
kUSB_HostGetHubThinkTime, /*!< Device's hub total think time */
67+
kUSB_HostGetDeviceConfigIndex, /*!< Device's running zero-based config index */
68+
kUSB_HostGetConfigurationDes, /*!< Device's configuration descriptor pointer */
69+
kUSB_HostGetConfigurationLength,/*!< Device's configuration descriptor pointer */
70+
} usb_host_dev_info_t;
71+
72+
struct _usb_host_transfer;
73+
/*!
74+
* @brief Host stack inner transfer callback function typedef.
75+
*
76+
* This callback function is used to notify the upper layer the result of a transfer.
77+
* This callback pointer is passed when initializing the structure usb_host_transfer_t.
78+
*
79+
* @param param The parameter pointer, which is passed when calling the send/receive APIs.
80+
* @param transfer The transfer information; See the structure usb_host_transfer_t.
81+
* @param status A USB error code or kStatus_USB_Success.
82+
*/
83+
typedef void (*host_inner_transfer_callback_t)(void *param,
84+
struct _usb_host_transfer *transfer, usb_status_t status);
85+
86+
/*!
87+
* @brief Host callback function typedef.
88+
*
89+
* This callback function is used to notify application device attach/detach event.
90+
* This callback pointer is passed when initializing the host.
91+
*
92+
* @param deviceHandle The device handle, which indicates the attached device.
93+
* @param configurationHandle The configuration handle contains the attached device's
94+
* configuration information.
95+
* @param event_code The callback event code; See the enumeration host_event_t.
96+
*
97+
* @return A USB error code or kStatus_USB_Success.
98+
* @retval kStatus_USB_Success Application handles the attached device successfully.
99+
* @retval kStatus_USB_NotSupported Application don't support the attached device.
100+
* @retval kStatus_USB_Error Application handles the attached device falsely.
101+
*/
102+
typedef usb_status_t (*host_callback_t)(usb_device_handle deviceHandle,
103+
usb_host_configuration_handle configurationHandle,
104+
uint32_t eventCode);
105+
106+
/*! @brief USB host pipe information structure for opening pipe */
107+
typedef struct _usb_host_pipe_init {
108+
void *devInstance; /*!< Device instance handle*/
109+
uint16_t nakCount; /*!< Maximum NAK retry count. MUST be zero for interrupt*/
110+
uint16_t maxPacketSize; /*!< Pipe's maximum packet size*/
111+
uint8_t interval; /*!< Pipe's interval*/
112+
uint8_t endpointAddress;/*!< Endpoint address*/
113+
uint8_t direction; /*!< Endpoint direction*/
114+
uint8_t pipeType; /*!< Endpoint type, the value is USB_ENDPOINT_INTERRUPT,
115+
* USB_ENDPOINT_CONTROL, USB_ENDPOINT_ISOCHRONOUS,
116+
* USB_ENDPOINT_BULK
117+
*/
118+
uint8_t numberPerUframe;/*!< Transaction number for each micro-frame*/
119+
} usb_host_pipe_init_t;
120+
121+
/*! @brief USB host pipe common structure */
122+
typedef struct _usb_host_pipe {
123+
struct _usb_host_pipe *next; /*!< Link the idle pipes*/
124+
usb_device_handle deviceHandle; /*!< This pipe's device's handle*/
125+
uint16_t currentCount; /*!< For KHCI transfer*/
126+
uint16_t nakCount; /*!< Maximum NAK count*/
127+
uint16_t maxPacketSize; /*!< Maximum packet size*/
128+
uint16_t interval; /*!< FS/LS: frame unit; HS: micro-frame unit*/
129+
uint8_t open; /*!< 0 - closed, 1 - open*/
130+
uint8_t nextdata01; /*!< Data toggle*/
131+
uint8_t endpointAddress; /*!< Endpoint address*/
132+
uint8_t direction; /*!< Pipe direction*/
133+
uint8_t pipeType; /*!< Pipe type, for example USB_ENDPOINT_BULK*/
134+
uint8_t numberPerUframe; /*!< Transaction number per micro-frame*/
135+
} usb_host_pipe_t;
136+
137+
/*! @brief USB host transfer structure */
138+
typedef struct _usb_host_transfer {
139+
struct _usb_host_transfer *next; /*!< The next transfer structure*/
140+
uint8_t *transferBuffer; /*!< Transfer data buffer*/
141+
uint32_t transferLength; /*!< Transfer data length*/
142+
uint32_t transferSofar; /*!< Length transferred so far*/
143+
host_inner_transfer_callback_t callbackFn; /*!< Transfer callback function*/
144+
void *callbackParam; /*!< Transfer callback parameter*/
145+
usb_host_pipe_t *transferPipe; /*!< Transfer pipe pointer*/
146+
usb_setup_struct_t *setupPacket; /*!< Set up packet buffer*/
147+
/*! Transfer direction; it's values are USB_OUT or USB_IN */
148+
uint8_t direction;
149+
uint8_t setupStatus; /*!< Set up the transfer status*/
150+
union {
151+
uint32_t unitHead; /*!< xTD head for this transfer*/
152+
int32_t transferResult; /*!< KHCI transfer result */
153+
} union1;
154+
155+
union {
156+
uint32_t unitTail; /*!<xTD tail for this transfer*/
157+
uint32_t frame; /*!< KHCI transfer frame number */
158+
} union2;
159+
160+
#if USB_HOST_CONFIG_KHCI
161+
uint16_t nakTimeout; /*!< KHCI transfer NAK timeout */
162+
uint16_t retry; /*!< KHCI transfer retry */
163+
#endif
164+
void *uhc_xfer;
165+
} usb_host_transfer_t;
166+
167+
/*! @brief Cancel transfer parameter structure */
168+
typedef struct _usb_host_cancel_param {
169+
usb_host_pipe_handle pipeHandle; /*!< Canceling pipe handle*/
170+
usb_host_transfer_t *transfer; /*!< Canceling transfer*/
171+
} usb_host_cancel_param_t;
172+
173+
/*! @brief USB host controller interface structure */
174+
typedef struct _usb_host_controller_interface {
175+
/*! Create a controller instance function prototype*/
176+
usb_status_t (*controllerCreate)(
177+
uint8_t controllerId,
178+
usb_host_handle upperLayerHandle,
179+
usb_host_controller_handle *controllerHandle);
180+
/*! Destroy a controller instance function prototype*/
181+
usb_status_t (*controllerDestory)(
182+
usb_host_controller_handle controllerHandle);
183+
/*! Open a controller pipe function prototype*/
184+
usb_status_t (*controllerOpenPipe)(usb_host_controller_handle controllerHandle,
185+
usb_host_pipe_handle *pipeHandle,
186+
usb_host_pipe_init_t *pipeInit);
187+
/*! Close a controller pipe function prototype*/
188+
usb_status_t (*controllerClosePipe)(
189+
usb_host_controller_handle controllerHandle,
190+
usb_host_pipe_handle pipeHandle);
191+
/*! Write data to a pipe function prototype*/
192+
usb_status_t (*controllerWritePipe)(usb_host_controller_handle controllerHandle,
193+
usb_host_pipe_handle pipeHandle,
194+
usb_host_transfer_t *transfer);
195+
/*! Read data from a pipe function prototype*/
196+
usb_status_t (*controllerReadPipe)(usb_host_controller_handle controllerHandle,
197+
usb_host_pipe_handle pipeHandle,
198+
usb_host_transfer_t *transfer);
199+
/*! Control a controller function prototype*/
200+
usb_status_t (*controllerIoctl)(usb_host_controller_handle controllerHandle,
201+
uint32_t ioctlEvent,
202+
void *ioctlParam);
203+
} usb_host_controller_interface_t;
204+
205+
/*! @brief USB host instance structure */
206+
typedef struct _usb_host_instance {
207+
void *controllerHandle; /*!< The low level controller handle*/
208+
host_callback_t deviceCallback; /*!< Device attach/detach callback*/
209+
} usb_host_instance_t;
210+
211+
/*!
212+
* @brief Controller driver calls this function when device detaches.
213+
*
214+
* @param hostHandle Host instance handle.
215+
* @param hubNumber Device hub no. root device's hub no. is 0.
216+
* @param portNumber Device port no. root device's port no. is 0.
217+
*
218+
* @return kStatus_USB_Success or error codes.
219+
*/
220+
usb_status_t USB_HostDetachDevice(usb_host_handle hostHandle, uint8_t hubNumber,
221+
uint8_t portNumber);
222+
223+
/*!
224+
* @brief Controller driver calls this function when device attach.
225+
*
226+
* @param hostHandle Host instance handle.
227+
* @param speed Device speed.
228+
* @param hubNumber Device hub no. root device's hub no. is 0.
229+
* @param portNumber Device port no. root device's port no. is 0.
230+
* @param level Device level. root device's level is 1.
231+
* @param deviceHandle Return device handle.
232+
*
233+
* @return kStatus_USB_Success or error codes.
234+
*/
235+
usb_status_t USB_HostAttachDevice(usb_host_handle hostHandle,
236+
uint8_t speed,
237+
uint8_t hubNumber,
238+
uint8_t portNumber,
239+
uint8_t level,
240+
usb_device_handle *deviceHandle);
241+
242+
/*!
243+
* @brief Controller driver calls this function to get the device information.
244+
*
245+
* This function gets the device information.
246+
*
247+
* @param[in] deviceHandle Removing device handle.
248+
* @param[in] infoCode See the enumeration host_dev_info_t.
249+
* @param[out] infoValue Return the information value.
250+
*
251+
* @retval kStatus_USB_Success Close successfully.
252+
* @retval kStatus_USB_InvalidParameter The deviceHandle or info_value is a NULL pointer.
253+
* @retval kStatus_USB_Error The info_code is not the host_dev_info_t value.
254+
*/
255+
usb_status_t USB_HostHelperGetPeripheralInformation(usb_device_handle deviceHandle,
256+
uint32_t infoCode,
257+
uint32_t *infoValue);
258+
259+
#ifdef CONFIG_USB_UHC_NXP_EHCI
260+
/*!
261+
* @brief Device EHCI ISR function.
262+
*
263+
* The function is the EHCI interrupt service routine.
264+
*
265+
* @param[in] hostHandle The host handle.
266+
*/
267+
void USB_HostEhciIsrFunction(void *hostHandle);
268+
269+
/*!
270+
* @brief EHCI task function.
271+
*
272+
* The function is used to handle the EHCI controller message.
273+
* In the bare metal environment, this function should be called periodically in the main function.
274+
* In the RTOS environment, this function should be used as a function entry to create a task.
275+
*
276+
* @param[in] hostHandle The host handle.
277+
*/
278+
void USB_HostEhciTaskFunction(void *hostHandle);
279+
#endif
280+
281+
#ifdef CONFIG_USB_UHC_NXP_KHCI
282+
/*!
283+
* @brief Device KHCI ISR function.
284+
*
285+
* The function is the KHCI interrupt service routine.
286+
*
287+
* @param[in] hostHandle The host handle.
288+
*/
289+
void USB_HostKhciIsrFunction(void *hostHandle);
290+
291+
/*!
292+
* @brief KHCI task function.
293+
*
294+
* The function is used to handle the KHCI controller message.
295+
* In the bare metal environment, this function should be called periodically in the main function.
296+
* In the RTOS environment, this function should be used as a function entry to create a task.
297+
*
298+
* @param[in] hostHandle The host handle.
299+
*/
300+
void USB_HostKhciTaskFunction(void *hostHandle);
301+
#endif
302+
303+
#endif /* _USB_HOST_MCUX_DRV_PORT_H_ */

0 commit comments

Comments
 (0)