Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usb: Adapt USB stack to work on ia32 #525

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _targets/Makefile.ia32-generic
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
# Copyright 2019 Phoenix Systems
#

DEFAULT_COMPONENTS := pc-tty uart16550 pc-ata
DEFAULT_COMPONENTS := pc-tty uart16550 pc-ata libusbehci umass
8 changes: 6 additions & 2 deletions usb/ehci/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#
# Makefile for Phoenix-RTOS imx6ull-ehci
# Makefile for Phoenix-RTOS ehci
#
# Copyright 2018, 2019 Phoenix Systems
#

# FIXME: rename usb host component
NAME := libusbehci
LOCAL_SRCS := ehci.c ehci-hub.c phy-$(TARGET_SUBFAMILY).c
LOCAL_SRCS := ehci.c ehci-hub.c phy-$(TARGET_FAMILY)-$(TARGET_SUBFAMILY).c

ifneq (,$(findstring imx,$(TARGET_SUBFAMILY)))
CFLAGS += -DEHCI_IMX
endif

include $(static-lib.mk)
66 changes: 54 additions & 12 deletions usb/ehci/ehci-hub.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*
* ehci root hub implementation
*
* Copyright 2021 Phoenix Systems
* Author: Maciej Purski
* Copyright 2021, 2024 Phoenix Systems
* Author: Maciej Purski, Adam Greloch
*
* This file is part of Phoenix-RTOS.
*
Expand All @@ -20,7 +20,7 @@

#include <sys/minmax.h>

#include <hcd.h>

Check failure on line 23 in usb/ehci/ehci-hub.c

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-qemu)

hcd.h: No such file or directory

Check failure on line 23 in usb/ehci/ehci-hub.c

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-pc)

hcd.h: No such file or directory
#include <hub.h>
#include "ehci.h"

Expand All @@ -39,7 +39,12 @@
.bcdUSB = 0x0200,
.bDeviceClass = USB_CLASS_HUB,
.bDeviceSubClass = 0,
#ifdef EHCI_IMX
/* imx deviation: the controller has an embedded TT */
.bDeviceProtocol = 1, /* Single TT */
#else
.bDeviceProtocol = 0, /* Root hub */
#endif
.bMaxPacketSize0 = 64,
.idVendor = 0x0,
.idProduct = 0x0,
Expand Down Expand Up @@ -87,17 +92,44 @@
static void ehci_resetPort(hcd_t *hcd, int port)
{
ehci_t *ehci = (ehci_t *)hcd->priv;
volatile int *reg = (hcd->base + portsc1) + (port - 1);
volatile int *reg = (ehci->opbase + portsc1) + (port - 1);
int tmp;

*reg &= ~PORTSC_ENA;
*reg |= PORTSC_PR;
log_debug("resetting port %d", port);

tmp = *reg;
tmp &= ~(PORTSC_ENA | PORTSC_PR);
*reg = tmp | PORTSC_PR;

#ifdef EHCI_IMX
/*
* This is imx deviation. According to ehci documentation
* imx deviation: According to ehci documentation
* it is up to software to set the PR bit 0 after waiting 20ms
*/
while (*reg & PORTSC_PR)
;
usleep(20 * 1000);
#else
/* Wait for reset to complete */
usleep(50 * 1000);

/* Stop the reset sequence */
*reg = tmp;

/* Wait until reset sequence stops */
while ((*reg & PORTSC_PR) != 0)
;

usleep(20 * 1000);
#endif

tmp = *reg;

log_debug("port %d reset done, status after reset=%x", port, tmp);

if ((tmp & PORTSC_ENA) == 0) {
log_debug("device on port %d is not a highspeed device", port);
}

ehci->portResetChange = 1 << port;

Expand All @@ -118,7 +150,7 @@
status->wPortChange = 0;
status->wPortStatus = 0;

val = *(hcd->base + portsc1 + port - 1);
val = *(ehci->opbase + portsc1 + port - 1);
if (val & PORTSC_CCS)
status->wPortStatus |= USB_PORT_STAT_CONNECTION;

Expand Down Expand Up @@ -152,10 +184,16 @@
if (ehci->portResetChange & (1 << port))
status->wPortChange |= USB_PORT_STAT_C_RESET;

#ifdef EHCI_IMX
if ((val & PORTSC_PSPD) >> 26 == 1)
status->wPortStatus |= USB_PORT_STAT_LOW_SPEED;
else if ((val & PORTSC_PSPD) >> 26 == 2)
status->wPortStatus |= USB_PORT_STAT_HIGH_SPEED;
#endif

/* TODO handle low/full speed devices on ia32 */

status->wPortStatus |= USB_PORT_STAT_HIGH_SPEED;

/* TODO: set indicator */

Expand Down Expand Up @@ -192,7 +230,7 @@
{
hcd_t *hcd = hub->hcd;
ehci_t *ehci = (ehci_t *)hcd->priv;
volatile int *portsc = hcd->base + portsc1 + port - 1;
volatile int *portsc = ehci->opbase + portsc1 + port - 1;
uint32_t val = *portsc;

if (port > hub->nports)
Expand Down Expand Up @@ -285,6 +323,7 @@
static int ehci_getDesc(usb_dev_t *hub, int type, int index, char *buf, size_t size)
{
hcd_t *hcd = hub->hcd;
ehci_t *ehci = (ehci_t *)hcd->priv;
usb_hub_desc_t *hdesc;
int bytes = 0;

Expand All @@ -309,7 +348,7 @@
hdesc->wHubCharacteristics = 0x1;
hdesc->bPwrOn2PwrGood = 10;
hdesc->bHubContrCurrent = 10;
hdesc->bNbrPorts = *(hcd->base + hcsparams) & 0xf;
hdesc->bNbrPorts = *(ehci->base + hcsparams) & 0xf;
hdesc->variable[0] = 0; /* Device not removable */
hdesc->variable[1] = 0xff; /* PortPwrCtrlMask */
break;
Expand All @@ -327,11 +366,13 @@
ehci_t *ehci = (ehci_t *)hcd->priv;

for (i = 0; i < hub->nports; i++) {
val = ehci->portsc;
val = *(ehci->opbase + portsc1 + i);
log_debug("(INT%d) port %d portsc: %x", hcd->info->irq, i + 1, val);
if (val & (PORTSC_CSC | PORTSC_PEC | PORTSC_OCC))
status |= 1 << (i + 1);
}

log_debug("(INT%d): status: %x", hcd->info->irq, status);
return status;
}

Expand All @@ -340,12 +381,13 @@
{
usb_setup_packet_t *setup = t->setup;
int ret;
ehci_t *ehci = (ehci_t *)hub->hcd->priv;

/* It will be finished, when a port status changes */
if (t->type == usb_transfer_interrupt) {
/* Enable Port Status Changed interrupt if this is a first call */
if ((*(hub->hcd->base + usbintr) & USBSTS_PCI) == 0)
*(hub->hcd->base + usbintr) |= USBSTS_PCI;
if ((*(ehci->opbase + usbintr) & USBSTS_PCI) == 0)
*(ehci->opbase + usbintr) |= USBSTS_PCI;
return 0;
}

Expand Down
Loading
Loading