mirror of
https://github.com/apache/nuttx.git
synced 2026-05-23 14:58:13 +08:00
drivers/usbhost: add xHCI support
add xHCI PCI driver (usbhost). Signed-off-by: p-szafonimateusz <p-szafonimateusz@xiaomi.com>
This commit is contained in:
committed by
Xiang Xiao
parent
3dc1ac91d6
commit
fab4f68b6f
@@ -106,3 +106,19 @@ An example command to run the driver on ``x86_64`` looks like this:
|
||||
-nographic -serial mon:stdio -object can-bus,id=canbus0-bus \
|
||||
-object can-host-socketcan,if=can0,canbus=canbus0-bus,id=canbus0-socketcan \
|
||||
-device ctucan_pci,canbus0=canbus0-bus,canbus1=canbus0-bus
|
||||
|
||||
xHCI over PCI
|
||||
-------------
|
||||
|
||||
xHCI support was tested on x86_64 target, both on QEMU and real hardware.
|
||||
|
||||
Known issues with this driver:
|
||||
|
||||
- Currently only USB2.0 is supported, there is no USB3.0 support in NuttX yet.
|
||||
|
||||
- USB HUB devices not supported yet
|
||||
|
||||
To enable xHCI support on QEMU, we have to add ``-device qemu-xhci`` argument.
|
||||
All supported USB devices in QEMU can be found in
|
||||
`QEMU documentation <https://qemu-project.gitlab.io/qemu/system/devices/usb.html>`_,
|
||||
but not all classes are supported in NuttX.
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include <nuttx/net/igc.h>
|
||||
#include <nuttx/can/kvaser_pci.h>
|
||||
#include <nuttx/can/ctucanfd_pci.h>
|
||||
#include <nuttx/usb/xhci_pci.h>
|
||||
|
||||
#include "pci_drivers.h"
|
||||
|
||||
@@ -182,6 +183,16 @@ int pci_register_drivers(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Initialization xHCI pci driver */
|
||||
|
||||
#ifdef CONFIG_USBHOST_XHCI_PCI
|
||||
ret = pci_xhci_init();
|
||||
if (ret < 0)
|
||||
{
|
||||
pcierr("pci_xhci_init failed, ret=%d\n", ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
ret = pci_dev_register();
|
||||
if (ret < 0)
|
||||
{
|
||||
|
||||
@@ -75,6 +75,10 @@ if(CONFIG_USBHOST)
|
||||
list(APPEND SRCS usbhost_ft232r.c)
|
||||
endif()
|
||||
|
||||
if(CONFIG_USBHOST_XHCI_PCI)
|
||||
list(APPEND SRCS usbhost_xhci_pci.c usbhost_xhci_trace.c)
|
||||
endif()
|
||||
|
||||
# HCD debug/trace logic
|
||||
|
||||
if(CONFIG_USBHOST_TRACE)
|
||||
|
||||
@@ -752,4 +752,23 @@ config USBHOST_BTHCI
|
||||
---help---
|
||||
Select this option to build in support for USB Bluetooth HCI devices.
|
||||
|
||||
menuconfig USBHOST_XHCI_PCI
|
||||
bool "USB xHCI PCI Host Driver Support"
|
||||
default n
|
||||
depends on PCI && PCI_MSIX && USBHOST_WAITER && SCHED_HPWORK && SCHED_LPWORK
|
||||
select USBHOST_HAVE_ASYNCH
|
||||
---help---
|
||||
USB xHCI PCI host driver support.
|
||||
|
||||
if USBHOST_XHCI_PCI
|
||||
|
||||
config USBHOST_XHCI_MAX_DEVS
|
||||
int "xHCI maximum supported devices"
|
||||
default 8
|
||||
range 1 256
|
||||
---help---
|
||||
How many USB devices will be supported by xHCI driver.
|
||||
|
||||
endif # USBHOST_XHCI_PCI
|
||||
|
||||
endif # USBHOST
|
||||
|
||||
@@ -80,6 +80,10 @@ ifeq ($(CONFIG_USBHOST_BTHCI),y)
|
||||
CSRCS += usbhost_bthci.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_USBHOST_XHCI_PCI),y)
|
||||
CSRCS += usbhost_xhci_pci.c usbhost_xhci_trace.c
|
||||
endif
|
||||
|
||||
# HCD debug/trace logic
|
||||
|
||||
ifeq ($(CONFIG_USBHOST_TRACE),y)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,140 @@
|
||||
/****************************************************************************
|
||||
* drivers/usbhost/usbhost_xhci_trace.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "usbhost_xhci_trace.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define TRENTRY(id,string) {string}
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
struct xhci_usbhost_trace_s
|
||||
{
|
||||
const char *string;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static const struct xhci_usbhost_trace_s g_trace1[TRACE1_NSTRINGS] =
|
||||
{
|
||||
TRENTRY(XHCI_TRACE1_RESET_FAILED,
|
||||
"XHCI ERROR: xhci_reset failed %d\n"),
|
||||
TRENTRY(XHCI_TRACE1_START_FAILED,
|
||||
"XHCI ERROR: XHCI Failed to start\n"),
|
||||
TRENTRY(XHCI_TRACE1_SLOTEN_FAILED,
|
||||
"XHCI ERROR: XHCI Slot Enable failed %d\n"),
|
||||
TRENTRY(XHCI_TRACE1_TRANSFER_FAILED,
|
||||
"XHCI ERROR: XHCI transfer failed %d\n"),
|
||||
TRENTRY(XHCI_TRACE1_BADXFRTYPE,
|
||||
"XHCI ERROR: XHCI bad transfer type %d\n"),
|
||||
|
||||
/* Verbose */
|
||||
|
||||
TRENTRY(XHCI_VTRACE1_INITIALIZING,
|
||||
"XHCI Initializing XHCI Stack\n"),
|
||||
TRENTRY(XHCI_VTRACE1_INIITIALIZED,
|
||||
"XHCI USB XHCI Initialized\n"),
|
||||
TRENTRY(XHCI_VTRACE1_PORTSC_CSC,
|
||||
"XHCI Connect Status Change: %06x\n"),
|
||||
TRENTRY(XHCI_VTRACE1_PORTSC_CONNALREADY,
|
||||
"XHCI Already connected: %06x\n"),
|
||||
TRENTRY(XHCI_VTRACE1_PORTSC_DISCALREADY,
|
||||
"XHCI Already disconnected: %06x\n"),
|
||||
};
|
||||
|
||||
static const struct xhci_usbhost_trace_s g_trace2[TRACE2_NSTRINGS] =
|
||||
{
|
||||
TRENTRY(XHCI_TRACE2_EPSTALLED,
|
||||
"XHCI EP%d Stalled: TOKEN=%04x\n"),
|
||||
|
||||
/* Verbose */
|
||||
|
||||
TRENTRY(XHCI_VTRACE2_PORTSC,
|
||||
"XHCI PORTSC%d: %08x\n"),
|
||||
TRENTRY(XHCI_VTRACE2_PORTSC_CONNECTED,
|
||||
"XHCI RHPort%d connected, pscwait: %d\n"),
|
||||
TRENTRY(XHCI_VTRACE2_PORTSC_DISCONND,
|
||||
"XHCI RHport%d disconnected, pscwait: %d\n"),
|
||||
TRENTRY(XHCI_VTRACE2_MONWAKEUP,
|
||||
"XHCI Hub port%d connected: %d\n"),
|
||||
TRENTRY(XHCI_VTRACE2_CTRLINOUT,
|
||||
"HXCI CTRLIN/OUT: RHPort%d req: %02x\n"),
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: usbhost_trformat1 and usbhost_trformat2
|
||||
*
|
||||
* Description:
|
||||
* This interface must be provided by platform specific logic that knows
|
||||
* the HCDs encoding of USB trace data.
|
||||
*
|
||||
* Given an 9-bit index, return a format string suitable for use with, say,
|
||||
* printf. The returned format is expected to handle two unsigned integer
|
||||
* values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
const char *usbhost_trformat1(uint16_t id)
|
||||
{
|
||||
int ndx = TRACE1_INDEX(id);
|
||||
|
||||
if (ndx < TRACE1_NSTRINGS)
|
||||
{
|
||||
return g_trace1[ndx].string;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *usbhost_trformat2(uint16_t id)
|
||||
{
|
||||
int ndx = TRACE2_INDEX(id);
|
||||
|
||||
if (ndx < TRACE2_NSTRINGS)
|
||||
{
|
||||
return g_trace2[ndx].string;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/****************************************************************************
|
||||
* drivers/usbhost/usbhost_xhci_trace.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you 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 __DRIVERS_USBHOST_USBHOST_XHCI_TRACE_H
|
||||
#define __DRIVERS_USBHOST_USBHOST_XHCI_TRACE_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
enum usbhost_trace1codes_e
|
||||
{
|
||||
__TRACE1_BASEVALUE = 0, /* This will force the first value to be 1 */
|
||||
|
||||
XHCI_TRACE1_RESET_FAILED, /* XHCI ERROR: sam_reset failed */
|
||||
XHCI_TRACE1_START_FAILED, /* XHCI ERROR: XHCI Failed to start */
|
||||
XHCI_TRACE1_SLOTEN_FAILED, /* XHCI ERROR: XHCI Slot Enable failed */
|
||||
XHCI_TRACE1_TRANSFER_FAILED, /* XHCI ERROR: XHCI transfer failed */
|
||||
XHCI_TRACE1_BADXFRTYPE, /* XHCI ERROR: XHCI bad transfer type */
|
||||
|
||||
/* Verbose */
|
||||
|
||||
XHCI_VTRACE1_INITIALIZING, /* XHCI Initializing XHCI Stack */
|
||||
XHCI_VTRACE1_INIITIALIZED, /* XHCI USB XHCI Initialized */
|
||||
XHCI_VTRACE1_PORTSC_CSC, /* XHCI Connect Status Change */
|
||||
XHCI_VTRACE1_PORTSC_CONNALREADY, /* XHCI Already connected */
|
||||
XHCI_VTRACE1_PORTSC_DISCALREADY, /* XHCI Already disconnected */
|
||||
|
||||
__TRACE1_NSTRINGS, /* Separates the format 1 from the format 2 strings */
|
||||
|
||||
XHCI_TRACE2_EPSTALLED, /* XHCI EP Stalled */
|
||||
|
||||
/* Verbose */
|
||||
|
||||
XHCI_VTRACE2_PORTSC, /* XHCI PORTSC */
|
||||
XHCI_VTRACE2_PORTSC_CONNECTED, /* XHCI RHPort connected */
|
||||
XHCI_VTRACE2_PORTSC_DISCONND, /* XHCI RHport disconnected */
|
||||
XHCI_VTRACE2_MONWAKEUP, /* XHCI RHPort connected wakeup */
|
||||
XHCI_VTRACE2_CTRLINOUT, /* XHCI CTRLIN/OUT */
|
||||
__TRACE2_NSTRINGS /* Total number of enumeration values */
|
||||
};
|
||||
|
||||
#define TRACE1_FIRST ((int)__TRACE1_BASEVALUE + 1)
|
||||
#define TRACE1_INDEX(id) ((int)(id) - TRACE1_FIRST)
|
||||
#define TRACE1_NSTRINGS TRACE1_INDEX(__TRACE1_NSTRINGS)
|
||||
|
||||
#define TRACE2_FIRST ((int)__TRACE1_NSTRINGS + 1)
|
||||
#define TRACE2_INDEX(id) ((int)(id) - TRACE2_FIRST)
|
||||
#define TRACE2_NSTRINGS TRACE2_INDEX(__TRACE2_NSTRINGS)
|
||||
|
||||
#endif /* #define __DRIVERS_USBHOST_USBHOST_XHCI_TRACE_H */
|
||||
@@ -918,7 +918,7 @@ struct usbhost_driver_s
|
||||
usbhost_asynch_t callback, FAR void *arg);
|
||||
#endif
|
||||
|
||||
/* Cancel any pending syncrhonous or asynchronous transfer on an
|
||||
/* Cancel any pending synchronous or asynchronous transfer on an
|
||||
* endpoint
|
||||
*/
|
||||
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/usb/xhci_pci.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you 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 __INCLUDE_NUTTX_USB_XHCI_PCI_H
|
||||
#define __INCLUDE_NUTTX_USB_XHCI_PCI_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_USBHOST_XHCI_PCI
|
||||
int pci_xhci_init(void);
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_USB_XHCI_PCI_H */
|
||||
Reference in New Issue
Block a user