Skip to content

Commit c820c87

Browse files
committed
ohci: Support configurable number of roothub ports
1 parent d367e8f commit c820c87

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

src/common/tusb_mcu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#elif TU_CHECK_MCU(OPT_MCU_LPC175X_6X, OPT_MCU_LPC177X_8X, OPT_MCU_LPC40XX)
5656
#define TUP_DCD_ENDPOINT_MAX 16
5757
#define TUP_USBIP_OHCI
58+
#define OHCI_RHPORTS 2
5859

5960
#elif TU_CHECK_MCU(OPT_MCU_LPC18XX, OPT_MCU_LPC43XX)
6061
// TODO USB0 has 6, USB1 has 4

src/portable/ohci/ohci.c

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828

2929
#if CFG_TUH_ENABLED && defined(TUP_USBIP_OHCI)
3030

31+
#ifndef OHCI_RHPORTS
32+
#error OHCI is enabled, but OHCI_RHPORTS is not defined.
33+
#endif
34+
3135
//--------------------------------------------------------------------+
3236
// INCLUDE
3337
//--------------------------------------------------------------------+
@@ -620,29 +624,30 @@ void hcd_int_handler(uint8_t hostid)
620624
//------------- RootHub status -------------//
621625
if ( int_status & OHCI_INT_RHPORT_STATUS_CHANGE_MASK )
622626
{
623-
uint32_t const rhport_status = OHCI_REG->rhport_status[0] & RHPORT_ALL_CHANGE_MASK;
624-
625-
// TODO dual port is not yet supported
626-
if ( rhport_status & RHPORT_CONNECT_STATUS_CHANGE_MASK )
627+
for (int i = 0; i < OHCI_RHPORTS; i++)
627628
{
628-
// TODO check if remote wake-up
629-
if ( OHCI_REG->rhport_status_bit[0].current_connect_status )
629+
uint32_t const rhport_status = OHCI_REG->rhport_status[i] & RHPORT_ALL_CHANGE_MASK;
630+
if ( rhport_status & RHPORT_CONNECT_STATUS_CHANGE_MASK )
630631
{
631-
// TODO reset port immediately, without this controller will got 2-3 (debouncing connection status change)
632-
OHCI_REG->rhport_status[0] = RHPORT_PORT_RESET_STATUS_MASK;
633-
hcd_event_device_attach(hostid, true);
634-
}else
635-
{
636-
hcd_event_device_remove(hostid, true);
632+
// TODO check if remote wake-up
633+
if ( OHCI_REG->rhport_status_bit[i].current_connect_status )
634+
{
635+
// TODO reset port immediately, without this controller will got 2-3 (debouncing connection status change)
636+
OHCI_REG->rhport_status[i] = RHPORT_PORT_RESET_STATUS_MASK;
637+
hcd_event_device_attach(i, true);
638+
}else
639+
{
640+
hcd_event_device_remove(i, true);
641+
}
637642
}
638-
}
639643

640-
if ( rhport_status & RHPORT_PORT_SUSPEND_CHANGE_MASK)
641-
{
644+
if ( rhport_status & RHPORT_PORT_SUSPEND_CHANGE_MASK)
645+
{
642646

643-
}
647+
}
644648

645-
OHCI_REG->rhport_status[0] = rhport_status; // acknowledge all interrupt
649+
OHCI_REG->rhport_status[i] = rhport_status; // acknowledge all interrupt
650+
}
646651
}
647652

648653
//------------- Transfer Complete -------------//

src/portable/ohci/ohci.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ typedef volatile struct
267267
};
268268

269269
union {
270-
uint32_t rhport_status[2]; // TODO NXP OHCI controller only has 2 ports
270+
uint32_t rhport_status[OHCI_RHPORTS];
271271
struct {
272272
uint32_t current_connect_status : 1;
273273
uint32_t port_enable_status : 1;
@@ -284,11 +284,11 @@ typedef volatile struct
284284
uint32_t port_over_current_indicator_change : 1;
285285
uint32_t port_reset_status_change : 1;
286286
uint32_t TU_RESERVED : 11;
287-
}rhport_status_bit[2];
287+
}rhport_status_bit[OHCI_RHPORTS];
288288
};
289289
}ohci_registers_t;
290290

291-
TU_VERIFY_STATIC( sizeof(ohci_registers_t) == 0x5c, "size is not correct");
291+
TU_VERIFY_STATIC( sizeof(ohci_registers_t) == (0x54 + (4 * OHCI_RHPORTS)), "size is not correct");
292292

293293
#ifdef __cplusplus
294294
}

0 commit comments

Comments
 (0)