Skip to content

Commit

Permalink
Merge pull request #23 from jonasblixt/cdns-usb
Browse files Browse the repository at this point in the history
Cdns usb
  • Loading branch information
jonasblixt committed May 5, 2023
2 parents d5af7a5 + bf965ce commit fa4124f
Show file tree
Hide file tree
Showing 17 changed files with 971 additions and 53 deletions.
16 changes: 8 additions & 8 deletions configs/imx8qxmek_defconfig
Expand Up @@ -35,20 +35,18 @@ CONFIG_IMX8X_SIGN_IMAGE=y
# Generic options
#
CONFIG_KEYSTORE="pki/internal_keystore.bpak"
CONFIG_LOGLEVEL=3
CONFIG_LOGLEVEL=2
CONFIG_ENABLE_WATCHDOG=y
CONFIG_PRINT_BOOT_BANNER=y
CONFIG_WATCHDOG_TIMEOUT=5
CONFIG_ENABLE_TIMESTAMPING=y
CONFIG_PRINT_TIMESTAMPS=y
CONFIG_NO_OF_TIMESTAMPS=64
# CONFIG_ENABLE_TIMESTAMPING is not set
CONFIG_DEVICE_UUID=y
CONFIG_CRYPTO=y
CONFIG_CRYPTO_MAX_HASH_OPS=1
CONFIG_CRYPTO_MAX_DSA_OPS=1
CONFIG_BIO_CORE=y
CONFIG_BIO_MAX_DEVS=32
CONFIG_SELF_TEST=y
# CONFIG_SELF_TEST is not set
# end of Generic options

#
Expand All @@ -67,7 +65,7 @@ CONFIG_BOOT_CORE=y
CONFIG_BOOT_BPAK_IMAGE_HELPERS=y
CONFIG_BOOT_AB_DRIVER=y
CONFIG_BOOT_LINUX=y
CONFIG_BOOT_LOAD_CHUNK_KiB=4096
CONFIG_BOOT_LOAD_CHUNK_kB=4096
# end of Boot

#
Expand Down Expand Up @@ -101,6 +99,7 @@ CONFIG_MMC_CORE=y
# CONFIG_MMC_CORE_DEBUG_CMDS is not set
# CONFIG_MMC_CORE_DEBUG_IOS is not set
# CONFIG_MMC_CORE_HS200_TUNE is not set
# CONFIG_MMC_CORE_OVERRIDE_BOOT_PART_SZ is not set
CONFIG_IMX_USDHC=y
# CONFIG_IMX_USDHC_XTRA_DEBUG is not set
# end of MMC Host drivers
Expand Down Expand Up @@ -128,9 +127,10 @@ CONFIG_DRIVERS_IMX_LPUART=y
# USB
#
CONFIG_DRIVER_USB_DEVICE=y
CONFIG_DRIVER_IMX_USB2_PHY=y
CONFIG_DRIVER_IMX_EHCI=y
# CONFIG_DRIVER_IMX_USB2_PHY is not set
# CONFIG_DRIVER_IMX_EHCI is not set
# CONFIG_DRIVER_IMX_USBDCD is not set
CONFIG_DRIVER_IMX_CDNS3_UDC=y
CONFIG_DRIVER_USB_PB_CLS=y
# end of USB

Expand Down
18 changes: 18 additions & 0 deletions include/drivers/usb/cdns3_udc_core.h
@@ -0,0 +1,18 @@
#ifndef INCLUDE_DRIVERS_USB_CDNS3_UDC_CORE_H
#define INCLUDE_DRIVERS_USB_CDNS3_UDC_CORE_H

#include <stdint.h>
#include <drivers/usb/usbd.h>

int cdns3_udc_core_init(void);
int cdns3_udc_core_stop(void);
int cdns3_udc_core_xfer_zlp(usb_ep_t ep);
int cdns3_udc_core_set_address(uint16_t addr);
int cdns3_udc_core_configure_ep(usb_ep_t ep, enum usb_ep_type ep_type, size_t pkt_sz);
int cdns3_udc_core_poll_setup_pkt(struct usb_setup_packet *pkt);
void cdns3_udc_core_xfer_cancel(usb_ep_t ep);
int cdns3_udc_core_xfer_complete(usb_ep_t ep);
int cdns3_udc_core_xfer_start(usb_ep_t ep, void *buf, size_t length);
void cdns3_udc_core_set_base(uintptr_t base_);

#endif
14 changes: 14 additions & 0 deletions include/drivers/usb/imx_cdns3_udc.h
@@ -0,0 +1,14 @@
#ifndef INCLUDE_DRIVERS_USB_IMX_CDNS3_UDC_H
#define INCLUDE_DRIVERS_USB_IMX_CDNS3_UDC_H

#include <stdint.h>

struct imx_cdns3_udc_config {
uintptr_t base;
uintptr_t non_core_base;
uintptr_t phy_base;
};

int imx_cdns3_udc_init(const struct imx_cdns3_udc_config *cfg);

#endif
8 changes: 8 additions & 0 deletions include/drivers/usb/imx_salvo_phy.h
@@ -0,0 +1,8 @@
#ifndef INCLUDE_DRIVERS_USB_IMX_SALVO_PHY_H
#define INCLUDE_DRIVERS_USB_IMX_SALVO_PHY_H

#include <stdint.h>

int imx_salvo_phy_init(uintptr_t base);

#endif
8 changes: 6 additions & 2 deletions include/drivers/usb/usbd.h
Expand Up @@ -171,19 +171,23 @@ struct usbd_hal_ops
{
int (*init)(void);
int (*stop)(void);
int (*xfer_start)(usb_ep_t ep, uintptr_t buf, size_t length);
int (*xfer_start)(usb_ep_t ep, void *buf, size_t length);
int (*xfer_complete)(usb_ep_t ep);
void (*xfer_cancel)(usb_ep_t ep);
int (*poll_setup_pkt)(struct usb_setup_packet *pkt);
int (*configure_ep)(usb_ep_t ep, enum usb_ep_type ep_type, size_t pkt_sz);
int (*set_address)(uint16_t addr);
int (*ep0_xfer_zlp)(usb_ep_t ep);
};

/* USB Device interface */
const char *ep_to_str(usb_ep_t ep);
int usbd_init_hal_ops(const struct usbd_hal_ops *ops);
int usbd_init_cls(const struct usbd_cls_config *cfg);
int usbd_init(void);
int usbd_connect(void);
int usbd_disconnect(void);
int usbd_xfer(usb_ep_t ep, uintptr_t buf, size_t length);
int usbd_xfer(usb_ep_t ep, void *buf, size_t length);


#endif // INCLUDE_DRIVERS_USB_USBD_H
3 changes: 2 additions & 1 deletion src/bio.c
Expand Up @@ -114,7 +114,8 @@ int64_t bio_size(bio_dev_t dev)
if (rc != PB_OK)
return rc;

return (bio_pool[dev].last_lba - bio_pool[dev].first_lba + 1) * bio_pool[dev].block_sz;
return (bio_pool[dev].last_lba - bio_pool[dev].first_lba + 1) * \
(int64_t) bio_pool[dev].block_sz;
}

ssize_t bio_block_size(bio_dev_t dev)
Expand Down
40 changes: 34 additions & 6 deletions src/board/imx8qxmek/board.c
Expand Up @@ -26,6 +26,7 @@
#include <drivers/usb/usbd.h>
#include <drivers/usb/imx_ehci.h>
#include <drivers/usb/imx_usb2_phy.h>
#include <drivers/usb/imx_cdns3_udc.h>
#include <drivers/usb/pb_dev_cls.h>
#include <pb/cm.h>
#include <drivers/crypto/imx_caam.h>
Expand Down Expand Up @@ -478,16 +479,43 @@ int board_init(struct imx8x_platform *plat_ptr)
int cm_board_init(void)
{
int rc;
/* Enable usb stuff */
sc_pm_set_resource_power_mode(plat->ipc, SC_R_USB_0, SC_PM_PW_MODE_ON);
sc_pm_set_resource_power_mode(plat->ipc, SC_R_USB_0_PHY, SC_PM_PW_MODE_ON);

imx_usb2_phy_init(0x5B100000);
/* Request power domains */
sc_pm_set_resource_power_mode(plat->ipc, SC_R_USB_2, SC_PM_PW_MODE_ON);
sc_pm_set_resource_power_mode(plat->ipc, SC_R_USB_2_PHY, SC_PM_PW_MODE_ON);

rc = imx_ehci_init(IMX_EHCI_BASE);
/* Request clocks */
rc = sc_pm_clock_enable(plat->ipc, SC_R_USB_2, SC_PM_CLK_PER, true, false);

if (rc != SC_ERR_NONE) {
LOG_ERR("USB_2 per clk enable failed!");
return -PB_ERR;
}

rc = sc_pm_clock_enable(plat->ipc, SC_R_USB_2, SC_PM_CLK_MISC, true, false);

if (rc != SC_ERR_NONE) {
LOG_ERR("USB_2 misc clk enable failed!");
return -PB_ERR;
}

rc = sc_pm_clock_enable(plat->ipc, SC_R_USB_2, SC_PM_CLK_MST_BUS, true, false);

if (rc != SC_ERR_NONE) {
LOG_ERR("USB_2 mst bus clk enable failed!");
return -PB_ERR;
}

static const struct imx_cdns3_udc_config usb_cfg = {
.base = 0x5B120000,
.non_core_base = 0x5B110000,
.phy_base = 0x5B160000,
};

rc = imx_cdns3_udc_init(&usb_cfg);

if (rc != PB_OK) {
LOG_ERR("imx_ehci_init failed (%i)", rc);
LOG_ERR("cdns_usb_init failed (%i)", rc);
return rc;
}

Expand Down
2 changes: 2 additions & 0 deletions src/cm/cm_main.c
Expand Up @@ -673,6 +673,7 @@ static int pb_command_parse(void)
break;
case PB_CMD_DEVICE_READ_CAPS:
{
LOG_INFO("Read caps");
struct pb_result_device_caps caps = {0};
caps.stream_no_of_buffers = 2;
caps.stream_buffer_size = CONFIG_CM_BUF_SIZE_KiB*1024;
Expand Down Expand Up @@ -739,6 +740,7 @@ static int pb_command_parse(void)
break;
case PB_CMD_DEVICE_IDENTIFIER_READ:
{
LOG_INFO("Read identifier");
struct pb_result_device_identifier *ident = \
(struct pb_result_device_identifier *) buffer;
memset(ident->board_id, 0, sizeof(ident->board_id));
Expand Down
3 changes: 3 additions & 0 deletions src/drivers/crypto/mbedtls/makefile.mk
@@ -1,3 +1,4 @@
ifeq (${CONFIG_DRIVERS_CRYPTO_MBEDTLS}, y)

ifeq (${MBEDTLS_DIR},)
$(error Error: MBEDTLS_DIR not set)
Expand Down Expand Up @@ -40,3 +41,5 @@ src-$(CONFIG_DRIVERS_CRYPTO_MBEDTLS) += src/drivers/crypto/mbedtls/mbedtls_pb.c

cflags-$(CONFIG_DRIVERS_CRYPTO_MBEDTLS) += -DMBEDTLS_CONFIG_FILE=\"$(shell readlink -f src/drivers/crypto/mbedtls/mbedtls_config.h)\"
cflags-$(CONFIG_DRIVERS_CRYPTO_MBEDTLS) += -I${MBEDTLS_DIR}/include

endif
5 changes: 5 additions & 0 deletions src/drivers/usb/Kconfig
Expand Up @@ -21,6 +21,11 @@ config DRIVER_IMX_USBDCD
depends on DRIVER_USB_DEVICE
default n

config DRIVER_IMX_CDNS3_UDC
bool "i.MX CDNS3 UDC Driver"
depends on SOC_FAMILY_IMX
default n

config DRIVER_USB_PB_CLS
bool "Punchboot device class"
default y
Expand Down

0 comments on commit fa4124f

Please sign in to comment.