usbhost: add common usb host waiter and drivers initialization
add common usb host waiter and drivers initialization which is required for xHCI support Signed-off-by: p-szafonimateusz <p-szafonimateusz@xiaomi.com>
This commit is contained in:
parent
c5757ed71f
commit
3dc1ac91d6
7 changed files with 281 additions and 0 deletions
|
|
@ -55,6 +55,7 @@
|
||||||
#include <nuttx/vhost/vhost.h>
|
#include <nuttx/vhost/vhost.h>
|
||||||
#include <nuttx/virtio/virtio.h>
|
#include <nuttx/virtio/virtio.h>
|
||||||
#include <nuttx/drivers/optee.h>
|
#include <nuttx/drivers/optee.h>
|
||||||
|
#include <nuttx/usb/usbhost.h>
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
|
|
@ -268,6 +269,10 @@ void drivers_initialize(void)
|
||||||
mtd_loop_register();
|
mtd_loop_register();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_USBHOST_WAITER
|
||||||
|
usbhost_drivers_initialize();
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_PCI) && !defined(CONFIG_PCI_LATE_DRIVERS_REGISTER)
|
#if defined(CONFIG_PCI) && !defined(CONFIG_PCI_LATE_DRIVERS_REGISTER)
|
||||||
pci_register_drivers();
|
pci_register_drivers();
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,10 @@ if(CONFIG_USBHOST)
|
||||||
set(SRCS usbhost_registry.c usbhost_registerclass.c usbhost_findclass.c
|
set(SRCS usbhost_registry.c usbhost_registerclass.c usbhost_findclass.c
|
||||||
usbhost_enumerate.c usbhost_devaddr.c)
|
usbhost_enumerate.c usbhost_devaddr.c)
|
||||||
|
|
||||||
|
if(CONFIG_USBHOST_WAITER)
|
||||||
|
list(APPEND SRCS usbhost_waiter.c usbhost_drivers.c)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(CONFIG_USBHOST_HUB)
|
if(CONFIG_USBHOST_HUB)
|
||||||
list(APPEND SRCS usbhost_hub.c)
|
list(APPEND SRCS usbhost_hub.c)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,28 @@ config USBHOST_ASYNCH
|
||||||
I/O transfer. This may be required, for example, to receive
|
I/O transfer. This may be required, for example, to receive
|
||||||
infrequent, asynchronous input from an interrupt pipe.
|
infrequent, asynchronous input from an interrupt pipe.
|
||||||
|
|
||||||
|
config USBHOST_WAITER
|
||||||
|
bool "USB Host Waiter Support"
|
||||||
|
default n
|
||||||
|
---help---
|
||||||
|
Select this option to build in support for common USB host waiter.
|
||||||
|
|
||||||
|
if USBHOST_WAITER
|
||||||
|
|
||||||
|
config USBHOST_WAITER_PRIO
|
||||||
|
int "USB Host Waiter Thread Priority"
|
||||||
|
default 100
|
||||||
|
---help---
|
||||||
|
USB Host Waiter thread priority.
|
||||||
|
|
||||||
|
config USBHOST_WAITER_STACKSIZE
|
||||||
|
int "USB Host Waiter Thread Stack Size"
|
||||||
|
default DEFAULT_TASK_STACKSIZE
|
||||||
|
---help---
|
||||||
|
USB Host Waiter thread stack size
|
||||||
|
|
||||||
|
endif # USBHOST_WAITER
|
||||||
|
|
||||||
config USBHOST_HUB
|
config USBHOST_HUB
|
||||||
bool "USB Hub Support"
|
bool "USB Hub Support"
|
||||||
default n
|
default n
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,10 @@ ifeq ($(CONFIG_USBHOST),y)
|
||||||
CSRCS += usbhost_registry.c usbhost_registerclass.c usbhost_findclass.c
|
CSRCS += usbhost_registry.c usbhost_registerclass.c usbhost_findclass.c
|
||||||
CSRCS += usbhost_enumerate.c usbhost_devaddr.c
|
CSRCS += usbhost_enumerate.c usbhost_devaddr.c
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_USBHOST_WAITER),y)
|
||||||
|
CSRCS += usbhost_waiter.c usbhost_drivers.c
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_USBHOST_HUB),y)
|
ifeq ($(CONFIG_USBHOST_HUB),y)
|
||||||
CSRCS += usbhost_hub.c
|
CSRCS += usbhost_hub.c
|
||||||
endif
|
endif
|
||||||
|
|
|
||||||
118
drivers/usbhost/usbhost_drivers.c
Normal file
118
drivers/usbhost/usbhost_drivers.c
Normal file
|
|
@ -0,0 +1,118 @@
|
||||||
|
/****************************************************************************
|
||||||
|
* drivers/usbhost/usbhost_drivers.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 <debug.h>
|
||||||
|
|
||||||
|
#include <nuttx/usb/usbhost.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: usbhost_waiter_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize all enabled USB host device drivers.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void usbhost_drivers_initialize(void)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
UNUSED(ret);
|
||||||
|
|
||||||
|
/* First, register all of the class drivers needed to support the drivers
|
||||||
|
* that we care about:
|
||||||
|
*/
|
||||||
|
|
||||||
|
uinfo("Register class drivers\n");
|
||||||
|
|
||||||
|
#ifdef CONFIG_USBHOST_HUB
|
||||||
|
/* Initialize USB hub class support */
|
||||||
|
|
||||||
|
ret = usbhost_hub_initialize();
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
uerr("ERROR: usbhost_hub_initialize failed: %d\n", ret);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_USBHOST_MSC
|
||||||
|
/* Register the USB mass storage class */
|
||||||
|
|
||||||
|
ret = usbhost_msc_initialize();
|
||||||
|
if (ret != OK)
|
||||||
|
{
|
||||||
|
uerr("ERROR: Failed to register the mass storage class: %d\n", ret);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_USBHOST_CDCACM
|
||||||
|
/* Register the CDC/ACM serial class */
|
||||||
|
|
||||||
|
ret = usbhost_cdcacm_initialize();
|
||||||
|
if (ret != OK)
|
||||||
|
{
|
||||||
|
uerr("ERROR: Failed to register the CDC/ACM serial class: %d\n", ret);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_USBHOST_HIDKBD
|
||||||
|
/* Initialize the HID keyboard class */
|
||||||
|
|
||||||
|
ret = usbhost_kbdinit();
|
||||||
|
if (ret != OK)
|
||||||
|
{
|
||||||
|
uerr("ERROR: Failed to register the HID keyboard class\n");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_USBHOST_HIDMOUSE
|
||||||
|
/* Initialize the HID mouse class */
|
||||||
|
|
||||||
|
ret = usbhost_mouse_init();
|
||||||
|
if (ret != OK)
|
||||||
|
{
|
||||||
|
uerr("ERROR: Failed to register the HID mouse class\n");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_USBHOST_FT232R
|
||||||
|
/* Initialize the FT232R class */
|
||||||
|
|
||||||
|
ret = usbhost_ft232r_initialize();
|
||||||
|
if (ret != OK)
|
||||||
|
{
|
||||||
|
uerr("ERROR: Failed to register the FT232R class\n");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
105
drivers/usbhost/usbhost_waiter.c
Normal file
105
drivers/usbhost/usbhost_waiter.c
Normal file
|
|
@ -0,0 +1,105 @@
|
||||||
|
/****************************************************************************
|
||||||
|
* drivers/usbhost/usbhost_waiter.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 <stdbool.h>
|
||||||
|
#include <debug.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <nuttx/kthread.h>
|
||||||
|
#include <nuttx/usb/usbdev.h>
|
||||||
|
#include <nuttx/usb/usbhost.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: usbhost_waiter
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Wait for USB devices to be connected.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int usbhost_waiter(int argc, FAR char *argv[])
|
||||||
|
{
|
||||||
|
FAR struct usbhost_connection_s *conn =
|
||||||
|
(FAR struct usbhost_connection_s *)((uintptr_t)strtoul(argv[1],
|
||||||
|
NULL, 16));
|
||||||
|
FAR struct usbhost_hubport_s *hport;
|
||||||
|
|
||||||
|
uinfo("Running %p\n", conn);
|
||||||
|
for (; ; )
|
||||||
|
{
|
||||||
|
/* Wait for the device to change state */
|
||||||
|
|
||||||
|
DEBUGVERIFY(CONN_WAIT(conn, &hport));
|
||||||
|
uinfo("%s\n", hport->connected ? "connected" : "disconnected");
|
||||||
|
|
||||||
|
/* Did we just become connected? */
|
||||||
|
|
||||||
|
if (hport->connected)
|
||||||
|
{
|
||||||
|
/* Yes.. enumerate the newly connected device */
|
||||||
|
|
||||||
|
CONN_ENUMERATE(conn, hport);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Keep the compiler from complaining */
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: usbhost_waiter_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize the USB host waiter. This function will start a thread that
|
||||||
|
* will monitor for device connection/disconnection events.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int usbhost_waiter_initialize(FAR struct usbhost_connection_s *conn)
|
||||||
|
{
|
||||||
|
FAR char *argv[2];
|
||||||
|
char arg1[32];
|
||||||
|
|
||||||
|
/* Start a thread to handle device connection. */
|
||||||
|
|
||||||
|
snprintf(arg1, 16, "%p", conn);
|
||||||
|
argv[0] = arg1;
|
||||||
|
argv[1] = NULL;
|
||||||
|
return kthread_create("usbhost",
|
||||||
|
CONFIG_USBHOST_WAITER_PRIO,
|
||||||
|
CONFIG_USBHOST_WAITER_STACKSIZE,
|
||||||
|
usbhost_waiter, argv);
|
||||||
|
}
|
||||||
|
|
@ -1303,6 +1303,29 @@ int usbhost_wlaninit(void);
|
||||||
int usbhost_enumerate(FAR struct usbhost_hubport_s *hub,
|
int usbhost_enumerate(FAR struct usbhost_hubport_s *hub,
|
||||||
FAR struct usbhost_class_s **devclass);
|
FAR struct usbhost_class_s **devclass);
|
||||||
|
|
||||||
|
#ifdef CONFIG_USBHOST_WAITER
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: usbhost_waiter_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize the USB host waiter. This function will start a thread that
|
||||||
|
* will monitor for device connection/disconnection events.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int usbhost_waiter_initialize(FAR struct usbhost_connection_s *conn);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: usbhost_drivers_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize all enabled USB host device drivers.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void usbhost_drivers_initialize(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
#undef EXTERN
|
#undef EXTERN
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue