Separate wait() and enumerate() methods from struct usbhost_driver_s and move to new interface, struct usbhost_connection_s. This is part of the necessary restructuring of the USB host interface to support multiple root hub ports.

This commit is contained in:
Gregory Nutt 2013-08-13 15:03:46 -06:00
parent b4645f73ec
commit 34418d12bb
6 changed files with 69 additions and 47 deletions

View File

@ -294,8 +294,9 @@ static int lpc17_usbinterrupt(int irq, FAR void *context);
/* USB host controller operations **********************************************/
static int lpc17_wait(FAR struct usbhost_driver_s *drvr, FAR bool *connected);
static int lpc17_enumerate(FAR struct usbhost_driver_s *drvr, int rhpndx);
static int lpc17_wait(FAR struct usbhost_connection_s *conn, FAR bool *connected);
static int lpc17_enumerate(FAR struct usbhost_connection_s *conn, int rhpndx);
static int lpc17_ep0configure(FAR struct usbhost_driver_s *drvr, uint8_t funcaddr,
uint16_t maxpacketsize);
static int lpc17_epalloc(FAR struct usbhost_driver_s *drvr,
@ -334,8 +335,6 @@ static struct lpc17_usbhost_s g_usbhost =
{
.drvr =
{
.wait = lpc17_wait,
.enumerate = lpc17_enumerate,
.ep0configure = lpc17_ep0configure,
.epalloc = lpc17_epalloc,
.epfree = lpc17_epfree,
@ -351,6 +350,14 @@ static struct lpc17_usbhost_s g_usbhost =
.class = NULL,
};
/* This is the connection/enumeration interact */
static struct usbhost_connection_s g_usbconn =
{
.wait = lpc17_wait,
.enumerate = lpc17_enumerate,
};
/* This is a free list of EDs and TD buffers */
static struct lpc17_list_s *g_edfree; /* List of unused EDs */
@ -1516,8 +1523,8 @@ static int lpc17_usbinterrupt(int irq, FAR void *context)
* Wait for a device to be connected or disconneced.
*
* Input Parameters:
* drvr - The USB host driver instance obtained as a parameter from the call to
* the class create() method.
* conn - The USB host connection instance obtained as a parameter from the call to
* the USB driver initialization logic.
* connected - A pointer to a boolean value: TRUE: Wait for device to be
* connected; FALSE: wait for device to be disconnected
*
@ -1533,9 +1540,9 @@ static int lpc17_usbinterrupt(int irq, FAR void *context)
*
*******************************************************************************/
static int lpc17_wait(FAR struct usbhost_driver_s *drvr, FAR bool *connected)
static int lpc17_wait(FAR struct usbhost_connection_s *conn, FAR bool *connected)
{
struct lpc17_usbhost_s *priv = (struct lpc17_usbhost_s *)drvr;
struct lpc17_usbhost_s *priv = (struct lpc17_usbhost_s *)&g_usbhost;
irqstate_t flags;
/* Are we already connected? */
@ -1569,8 +1576,8 @@ static int lpc17_wait(FAR struct usbhost_driver_s *drvr, FAR bool *connected)
* charge of the sequence of operations.
*
* Input Parameters:
* drvr - The USB host driver instance obtained as a parameter from the call to
* the class create() method.
* conn - The USB host connection instance obtained as a parameter from the call to
* the USB driver initialization logic.
* rphndx - Root hub port index. 0-(n-1) corresponds to root hub port 1-n.
*
* Returned Values:
@ -1584,9 +1591,9 @@ static int lpc17_wait(FAR struct usbhost_driver_s *drvr, FAR bool *connected)
*
*******************************************************************************/
static int lpc17_enumerate(FAR struct usbhost_driver_s *drvr, int rphndx)
static int lpc17_enumerate(FAR struct usbhost_connection_s *conn, int rphndx)
{
struct lpc17_usbhost_s *priv = (struct lpc17_usbhost_s *)drvr;
struct lpc17_usbhost_s *priv = (struct lpc17_usbhost_s *)&g_usbhost;
DEBUGASSERT(priv && rhpndx == 0);
/* Are we connected to a device? The caller should have called the wait()
@ -2479,7 +2486,7 @@ static inline void lpc17_ep0init(struct lpc17_usbhost_s *priv)
*
*******************************************************************************/
FAR struct usbhost_driver_s *usbhost_initialize(int controller)
FAR struct usbhost_connection_s *usbhost_initialize(int controller)
{
struct lpc17_usbhost_s *priv = &g_usbhost;
uint32_t regval;
@ -2707,5 +2714,5 @@ FAR struct usbhost_driver_s *usbhost_initialize(int controller)
udbg("USB host Initialized, Device connected:%s\n",
priv->connected ? "YES" : "NO");
return &priv->drvr;
return &g_usbconn;
}

View File

@ -93,8 +93,8 @@ extern "C"
*******************************************************************************/
#ifdef CONFIG_USBHOST
struct usbhost_driver_s;
FAR struct usbhost_driver_s *usbhost_initialize(int controller);
struct usbhost_connection_s;
FAR struct usbhost_connection_s *usbhost_initialize(int controller);
#endif
#undef EXTERN

View File

@ -351,8 +351,9 @@ static int sam_ohci_interrupt(int irq, FAR void *context);
/* USB host controller operations **********************************************/
static int sam_wait(FAR struct usbhost_driver_s *drvr, FAR const bool *connected);
static int sam_enumerate(FAR struct usbhost_driver_s *drvr, int rhpndx);
static int sam_wait(FAR struct usbhost_connection_s *conn, FAR const bool *connected);
static int sam_enumerate(FAR struct usbhost_connection_s *conn, int rhpndx);
static int sam_ep0configure(FAR struct usbhost_driver_s *drvr, uint8_t funcaddr,
uint16_t maxpacketsize);
static int sam_epalloc(FAR struct usbhost_driver_s *drvr,
@ -391,8 +392,6 @@ static struct sam_ohci_s g_usbhost =
{
.drvr =
{
.wait = sam_wait,
.enumerate = sam_enumerate,
.ep0configure = sam_ep0configure,
.epalloc = sam_epalloc,
.epfree = sam_epfree,
@ -407,6 +406,14 @@ static struct sam_ohci_s g_usbhost =
},
};
/* This is the connection/enumeration interact */
static struct usbhost_connection_s g_usbconn =
{
.wait = sam_wait,
.enumerate = sam_enumerate,
};
/* This is a free list of EDs and TD buffers */
static struct sam_list_s *g_edfree; /* List of unused EDs */
@ -1630,8 +1637,8 @@ static int sam_ohci_interrupt(int irq, FAR void *context)
* Wait for a device to be connected or disconnected to/from a root hub port.
*
* Input Parameters:
* drvr - The USB host driver instance obtained as a parameter from the call
* to the class create() method.
* conn - The USB host connection instance obtained as a parameter from the call to
* the USB driver initialization logic.
* connected - A pointer to an array of 3 boolean values corresponding to
* root hubs 1, 2, and 3. For each boolean value: TRUE: Wait for a device
* to be connected on the root hub; FALSE: wait for device to be
@ -1651,9 +1658,10 @@ static int sam_ohci_interrupt(int irq, FAR void *context)
*
*******************************************************************************/
static int sam_wait(FAR struct usbhost_driver_s *drvr, FAR const bool *connected)
static int sam_wait(FAR struct usbhost_connection_s *conn,
FAR const bool *connected)
{
struct sam_ohci_s *priv = (struct sam_ohci_s *)drvr;
struct sam_ohci_s *priv = &g_usbhost;
irqstate_t flags;
int rhpndx;
@ -1707,8 +1715,8 @@ static int sam_wait(FAR struct usbhost_driver_s *drvr, FAR const bool *connected
* charge of the sequence of operations.
*
* Input Parameters:
* drvr - The USB host driver instance obtained as a parameter from the call to
* the class create() method.
* conn - The USB host connection instance obtained as a parameter from the call to
* the USB driver initialization logic.
* rphndx - Root hub port index. 0-(n-1) corresponds to root hub port 1-n.
*
* Returned Values:
@ -1722,9 +1730,9 @@ static int sam_wait(FAR struct usbhost_driver_s *drvr, FAR const bool *connected
*
*******************************************************************************/
static int sam_enumerate(FAR struct usbhost_driver_s *drvr, int rhpndx)
static int sam_enumerate(FAR struct usbhost_connection_s *conn, int rhpndx)
{
struct sam_ohci_s *priv = (struct sam_ohci_s *)drvr;
struct sam_ohci_s *priv = &g_usbhost;
struct sam_rhport_s *rhport;
uint32_t regaddr;
@ -2734,5 +2742,5 @@ FAR struct usbhost_driver_s *sam_ohci_initialize(int controller)
up_enable_irq(SAM_IRQ_UHPHS); /* enable USB interrupt */
uvdbg("USB OHCI Initialized\n");
return &priv->drvr;
return &g_usbconn;
}

View File

@ -107,8 +107,8 @@ extern "C"
*******************************************************************************/
#ifdef CONFIG_SAMA5_OHCI
struct usbhost_driver_s;
FAR struct usbhost_driver_s *sam_ohci_initialize(int controller);
struct usbhost_connection_s;
FAR struct usbhost_connection_s *sam_ohci_initialize(int controller);
#endif
/*******************************************************************************

View File

@ -99,8 +99,8 @@ extern "C"
*******************************************************************************/
#ifdef CONFIG_USBHOST
struct usbhost_driver_s;
FAR struct usbhost_driver_s *stm32_otgfshost_initialize(int controller);
struct usbhost_connection_s;
FAR struct usbhost_connection_s *stm32_otgfshost_initialize(int controller);
#endif
/************************************************************************************

View File

@ -358,8 +358,9 @@ static void stm32_txfe_enable(FAR struct stm32_usbhost_s *priv, int chidx);
/* USB host controller operations **********************************************/
static int stm32_wait(FAR struct usbhost_driver_s *drvr, FAR bool *connected);
static int stm32_enumerate(FAR struct usbhost_driver_s *drvr, int rhpndx);
static int stm32_wait(FAR struct usbhost_connection_s *conn, FAR bool *connected);
static int stm32_enumerate(FAR struct usbhost_connection_s *conn, int rhpndx);
static int stm32_ep0configure(FAR struct usbhost_driver_s *drvr, uint8_t funcaddr,
uint16_t maxpacketsize);
static int stm32_epalloc(FAR struct usbhost_driver_s *drvr,
@ -406,8 +407,6 @@ static struct stm32_usbhost_s g_usbhost =
{
.drvr =
{
.wait = stm32_wait,
.enumerate = stm32_enumerate,
.ep0configure = stm32_ep0configure,
.epalloc = stm32_epalloc,
.epfree = stm32_epfree,
@ -423,6 +422,14 @@ static struct stm32_usbhost_s g_usbhost =
.class = NULL,
};
/* This is the connection/enumeration interact */
static struct usbhost_connection_s g_usbconn =
{
.wait = stm32_wait,
.enumerate = stm32_enumerate,
};
/*******************************************************************************
* Public Data
*******************************************************************************/
@ -3011,8 +3018,8 @@ static void stm32_txfe_enable(FAR struct stm32_usbhost_s *priv, int chidx)
* Wait for a device to be connected or disconneced.
*
* Input Parameters:
* drvr - The USB host driver instance obtained as a parameter from the call to
* the class create() method.
* conn - The USB host connection instance obtained as a parameter from the call to
* the USB driver initialization logic.
* connected - A pointer to a boolean value. TRUE: Wait for device to be
* connected; FALSE: wait for device to be disconnected
*
@ -3028,9 +3035,9 @@ static void stm32_txfe_enable(FAR struct stm32_usbhost_s *priv, int chidx)
*
*******************************************************************************/
static int stm32_wait(FAR struct usbhost_driver_s *drvr, FAR bool *connected)
static int stm32_wait(FAR struct usbhost_connection_s *conn, FAR bool *connected)
{
FAR struct stm32_usbhost_s *priv = (FAR struct stm32_usbhost_s *)drvr;
FAR struct stm32_usbhost_s *priv = &g_usbhost;
irqstate_t flags;
/* Are we already connected? */
@ -3064,8 +3071,8 @@ static int stm32_wait(FAR struct usbhost_driver_s *drvr, FAR bool *connected)
* charge of the sequence of operations.
*
* Input Parameters:
* drvr - The USB host driver instance obtained as a parameter from the call to
* the class create() method.
* conn - The USB host connection instance obtained as a parameter from the call to
* the USB driver initialization logic.
* rphndx - Root hub port index. 0-(n-1) corresponds to root hub port 1-n.
*
* Returned Values:
@ -3079,9 +3086,9 @@ static int stm32_wait(FAR struct usbhost_driver_s *drvr, FAR bool *connected)
*
*******************************************************************************/
static int stm32_enumerate(FAR struct usbhost_driver_s *drvr, int rhpndx)
static int stm32_enumerate(FAR struct usbhost_connection_s *conn, int rhpndx)
{
struct stm32_usbhost_s *priv = (struct stm32_usbhost_s *)drvr;
FAR struct stm32_usbhost_s *priv = &g_usbhost;
uint32_t regval;
int chidx;
int ret;
@ -4222,7 +4229,7 @@ static inline int stm32_hw_initialize(FAR struct stm32_usbhost_s *priv)
*
*******************************************************************************/
FAR struct usbhost_driver_s *stm32_otgfshost_initialize(int controller)
FAR struct usbhost_connection_s *stm32_otgfshost_initialize(int controller)
{
/* At present, there is only support for a single OTG FS host. Hence it is
* pre-allocated as g_usbhost. However, in most code, the private data
@ -4296,7 +4303,7 @@ FAR struct usbhost_driver_s *stm32_otgfshost_initialize(int controller)
/* Enable interrupts at the interrupt controller */
up_enable_irq(STM32_IRQ_OTGFS);
return &priv->drvr;
return &g_usbconn;
}
#endif /* CONFIG_USBHOST && CONFIG_STM32_OTGFS */