Skip to content

Commit 2a71746

Browse files
lduberaiden00pl
authored andcommitted
boards/sama5d3-xplained: Use common usb host waiter.
Delete the board-specific usb host waiters and use the common code.
1 parent 8776147 commit 2a71746

File tree

2 files changed

+20
-110
lines changed

2 files changed

+20
-110
lines changed

arch/arm/src/sama5/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4120,6 +4120,7 @@ config SAMA5_OHCI
41204120
default n
41214121
select USBHOST
41224122
select USBHOST_HAVE_ASYNCH
4123+
select USBHOST_WAITER
41234124
---help---
41244125
Build support for the SAMA5 USB full speed Open Host Controller
41254126
Interface (OHCI).
@@ -4156,6 +4157,7 @@ config SAMA5_EHCI
41564157
default n
41574158
select USBHOST
41584159
select USBHOST_HAVE_ASYNCH
4160+
select USBHOST_WAITER
41594161
---help---
41604162
Build support for the SAMA5 USB high speed Enhanced Host Controller
41614163
Interface (EHCI). If low/full speed is needed too, then you must

boards/arm/sama5/sama5d3-xplained/src/sam_usb.c

Lines changed: 18 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,6 @@
5252
* Pre-processor Definitions
5353
****************************************************************************/
5454

55-
#ifndef CONFIG_SAMA5D3XPLAINED_USBHOST_PRIO
56-
# define CONFIG_SAMA5D3XPLAINED_USBHOST_PRIO 50
57-
#endif
58-
59-
#ifndef CONFIG_SAMA5D3XPLAINED_USBHOST_STACKSIZE
60-
# define CONFIG_SAMA5D3XPLAINED_USBHOST_STACKSIZE 1024
61-
#endif
62-
6355
#ifdef HAVE_USBDEV
6456
# undef CONFIG_SAMA5_UHPHS_RHPORT1
6557
#endif
@@ -68,15 +60,6 @@
6860
* Private Data
6961
****************************************************************************/
7062

71-
/* Retained device driver handles */
72-
73-
#ifdef CONFIG_SAMA5_OHCI
74-
static struct usbhost_connection_s *g_ohciconn;
75-
#endif
76-
#ifdef CONFIG_SAMA5_EHCI
77-
static struct usbhost_connection_s *g_ehciconn;
78-
#endif
79-
8063
/* Overcurrent interrupt handler */
8164

8265
#if defined(HAVE_USBHOST) && defined(CONFIG_SAMA5_PIOD_IRQ)
@@ -87,86 +70,6 @@ static xcpt_t g_ochandler;
8770
* Private Functions
8871
****************************************************************************/
8972

90-
/****************************************************************************
91-
* Name: usbhost_waiter
92-
*
93-
* Description:
94-
* Wait for USB devices to be connected to either the OHCI or EHCI hub.
95-
*
96-
****************************************************************************/
97-
98-
#ifdef HAVE_USBHOST
99-
#ifdef CONFIG_DEBUG_USB
100-
static int usbhost_waiter(struct usbhost_connection_s *dev,
101-
const char *hcistr)
102-
#else
103-
static int usbhost_waiter(struct usbhost_connection_s *dev)
104-
#endif
105-
{
106-
struct usbhost_hubport_s *hport;
107-
108-
uinfo("Running\n");
109-
for (; ; )
110-
{
111-
/* Wait for the device to change state */
112-
113-
DEBUGVERIFY(CONN_WAIT(dev, &hport));
114-
uinfo("%s\n", hport->connected ? "connected" : "disconnected");
115-
116-
/* Did we just become connected? */
117-
118-
if (hport->connected)
119-
{
120-
/* Yes.. enumerate the newly connected device */
121-
122-
CONN_ENUMERATE(dev, hport);
123-
}
124-
}
125-
126-
/* Keep the compiler from complaining */
127-
128-
return 0;
129-
}
130-
#endif
131-
132-
/****************************************************************************
133-
* Name: ohci_waiter
134-
*
135-
* Description:
136-
* Wait for USB devices to be connected to the OHCI hub.
137-
*
138-
****************************************************************************/
139-
140-
#ifdef CONFIG_SAMA5_OHCI
141-
static int ohci_waiter(int argc, char *argv[])
142-
{
143-
#ifdef CONFIG_DEBUG_USB
144-
return usbhost_waiter(g_ohciconn, "OHCI");
145-
#else
146-
return usbhost_waiter(g_ohciconn);
147-
#endif
148-
}
149-
#endif
150-
151-
/****************************************************************************
152-
* Name: ehci_waiter
153-
*
154-
* Description:
155-
* Wait for USB devices to be connected to the EHCI hub.
156-
*
157-
****************************************************************************/
158-
159-
#ifdef CONFIG_SAMA5_EHCI
160-
static int ehci_waiter(int argc, char *argv[])
161-
{
162-
#ifdef CONFIG_DEBUG_USB
163-
return usbhost_waiter(g_ehciconn, "EHCI");
164-
#else
165-
return usbhost_waiter(g_ehciconn);
166-
#endif
167-
}
168-
#endif
169-
17073
/****************************************************************************
17174
* Public Functions
17275
****************************************************************************/
@@ -175,7 +78,7 @@ static int ehci_waiter(int argc, char *argv[])
17578
* Name: sam_usbinitialize
17679
*
17780
* Description:
178-
* Called from sam_usbinitialize very early in inialization to setup
81+
* Called from sam_usbinitialize very early in initialization to setup
17982
* USB-related GPIO pins for the SAMA5D3-Xplained board.
18083
*
18184
* USB Ports
@@ -290,6 +193,13 @@ int sam_usbhost_initialize(void)
290193
{
291194
int ret;
292195

196+
#ifdef CONFIG_SAMA5_OHCI
197+
struct usbhost_connection_s *ohciconn;
198+
#endif
199+
#ifdef CONFIG_SAMA5_EHCI
200+
struct usbhost_connection_s *ehciconn;
201+
#endif
202+
293203
/* First, register all of the class drivers needed to support the drivers
294204
* that we care about
295205
*/
@@ -359,18 +269,17 @@ int sam_usbhost_initialize(void)
359269
#ifdef CONFIG_SAMA5_OHCI
360270
/* Get an instance of the USB OHCI interface */
361271

362-
g_ohciconn = sam_ohci_initialize(0);
363-
if (!g_ohciconn)
272+
ohciconn = sam_ohci_initialize(0);
273+
if (!ohciconn)
364274
{
365275
uerr("ERROR: sam_ohci_initialize failed\n");
366276
return -ENODEV;
367277
}
368278

369-
/* Start a thread to handle device connection. */
279+
/* Initialize waiter */
280+
281+
ret = usbhost_waiter_initialize(ohciconn);
370282

371-
ret = kthread_create("OHCI Monitor", CONFIG_SAMA5D3XPLAINED_USBHOST_PRIO,
372-
CONFIG_SAMA5D3XPLAINED_USBHOST_STACKSIZE,
373-
ohci_waiter, NULL);
374283
if (ret < 0)
375284
{
376285
uerr("ERROR: Failed to create ohci_waiter task: %d\n", ret);
@@ -381,18 +290,17 @@ int sam_usbhost_initialize(void)
381290
#ifdef CONFIG_SAMA5_EHCI
382291
/* Get an instance of the USB EHCI interface */
383292

384-
g_ehciconn = sam_ehci_initialize(0);
385-
if (!g_ehciconn)
293+
ehciconn = sam_ehci_initialize(0);
294+
if (!ehciconn)
386295
{
387296
uerr("ERROR: sam_ehci_initialize failed\n");
388297
return -ENODEV;
389298
}
390299

391-
/* Start a thread to handle device connection. */
300+
/* Initialize waiter */
301+
302+
ret = usbhost_waiter_initialize(ehciconn);
392303

393-
ret = kthread_create("EHCI Monitor", CONFIG_SAMA5D3XPLAINED_USBHOST_PRIO,
394-
CONFIG_SAMA5D3XPLAINED_USBHOST_STACKSIZE,
395-
ehci_waiter, NULL);
396304
if (ret < 0)
397305
{
398306
uerr("ERROR: Failed to create ehci_waiter task: %d\n", ret);

0 commit comments

Comments
 (0)