Module Name: src Committed By: skrll Date: Sun Aug 30 13:02:42 UTC 2015
Modified Files: src/sys/arch/arm/amlogic: amlogic_dwctwo.c src/sys/arch/arm/broadcom: bcm2835_dwctwo.c src/sys/arch/arm/rockchip: rockchip_dwctwo.c src/sys/arch/mips/cavium/dev: octeon_dwctwo.c src/sys/arch/mips/ingenic: ingenic_dwctwo.c src/sys/external/bsd/dwc2: dwc2.c dwc2.h Log Message: Update for latest dwc2 To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/sys/arch/arm/amlogic/amlogic_dwctwo.c cvs rdiff -u -r1.5 -r1.6 src/sys/arch/arm/broadcom/bcm2835_dwctwo.c cvs rdiff -u -r1.4 -r1.5 src/sys/arch/arm/rockchip/rockchip_dwctwo.c cvs rdiff -u -r1.5 -r1.6 src/sys/arch/mips/cavium/dev/octeon_dwctwo.c cvs rdiff -u -r1.11 -r1.12 src/sys/arch/mips/ingenic/ingenic_dwctwo.c cvs rdiff -u -r1.36 -r1.37 src/sys/external/bsd/dwc2/dwc2.c cvs rdiff -u -r1.6 -r1.7 src/sys/external/bsd/dwc2/dwc2.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/arm/amlogic/amlogic_dwctwo.c diff -u src/sys/arch/arm/amlogic/amlogic_dwctwo.c:1.4 src/sys/arch/arm/amlogic/amlogic_dwctwo.c:1.5 --- src/sys/arch/arm/amlogic/amlogic_dwctwo.c:1.4 Thu Jul 30 07:32:40 2015 +++ src/sys/arch/arm/amlogic/amlogic_dwctwo.c Sun Aug 30 13:02:42 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: amlogic_dwctwo.c,v 1.4 2015/07/30 07:32:40 skrll Exp $ */ +/* $NetBSD: amlogic_dwctwo.c,v 1.5 2015/08/30 13:02:42 skrll Exp $ */ /*- * Copyright (c) 2013 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: amlogic_dwctwo.c,v 1.4 2015/07/30 07:32:40 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: amlogic_dwctwo.c,v 1.5 2015/08/30 13:02:42 skrll Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -85,6 +85,8 @@ static struct dwc2_core_params amlogic_d .reload_ctl = -1, /* 0 - No (default for core < 2.92a) */ .ahbcfg = 0x3, /* INCR4 */ .uframe_sched = 1, /* True to enable microframe scheduler */ + .external_id_pin_ctl = -1, + .hibernation = -1, }; static int amlogic_dwctwo_match(device_t, struct cfdata *, void *); Index: src/sys/arch/arm/broadcom/bcm2835_dwctwo.c diff -u src/sys/arch/arm/broadcom/bcm2835_dwctwo.c:1.5 src/sys/arch/arm/broadcom/bcm2835_dwctwo.c:1.6 --- src/sys/arch/arm/broadcom/bcm2835_dwctwo.c:1.5 Thu Jul 30 07:32:40 2015 +++ src/sys/arch/arm/broadcom/bcm2835_dwctwo.c Sun Aug 30 13:02:42 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: bcm2835_dwctwo.c,v 1.5 2015/07/30 07:32:40 skrll Exp $ */ +/* $NetBSD: bcm2835_dwctwo.c,v 1.6 2015/08/30 13:02:42 skrll Exp $ */ /*- * Copyright (c) 2013 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: bcm2835_dwctwo.c,v 1.5 2015/07/30 07:32:40 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: bcm2835_dwctwo.c,v 1.6 2015/08/30 13:02:42 skrll Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -84,6 +84,8 @@ static struct dwc2_core_params bcmdwc2_p .reload_ctl = 0, .ahbcfg = 0x10, .uframe_sched = 1, + .external_id_pin_ctl = -1, + .hibernation = -1, }; static int bcmdwc2_match(device_t, struct cfdata *, void *); Index: src/sys/arch/arm/rockchip/rockchip_dwctwo.c diff -u src/sys/arch/arm/rockchip/rockchip_dwctwo.c:1.4 src/sys/arch/arm/rockchip/rockchip_dwctwo.c:1.5 --- src/sys/arch/arm/rockchip/rockchip_dwctwo.c:1.4 Thu Jul 30 07:32:40 2015 +++ src/sys/arch/arm/rockchip/rockchip_dwctwo.c Sun Aug 30 13:02:42 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: rockchip_dwctwo.c,v 1.4 2015/07/30 07:32:40 skrll Exp $ */ +/* $NetBSD: rockchip_dwctwo.c,v 1.5 2015/08/30 13:02:42 skrll Exp $ */ /*- * Copyright (c) 2013 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: rockchip_dwctwo.c,v 1.4 2015/07/30 07:32:40 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rockchip_dwctwo.c,v 1.5 2015/08/30 13:02:42 skrll Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -84,6 +84,8 @@ static struct dwc2_core_params rkdwc2_pa .reload_ctl = 0, /* 0 - No (default for core < 2.92a) */ .ahbcfg = 0x7, /* INCR16 */ .uframe_sched = 1, /* True to enable microframe scheduler */ + .external_id_pin_ctl = -1, + .hibernation = -1, }; static int rkdwc2_match(device_t, struct cfdata *, void *); Index: src/sys/arch/mips/cavium/dev/octeon_dwctwo.c diff -u src/sys/arch/mips/cavium/dev/octeon_dwctwo.c:1.5 src/sys/arch/mips/cavium/dev/octeon_dwctwo.c:1.6 --- src/sys/arch/mips/cavium/dev/octeon_dwctwo.c:1.5 Thu Jul 30 07:32:40 2015 +++ src/sys/arch/mips/cavium/dev/octeon_dwctwo.c Sun Aug 30 13:02:42 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: octeon_dwctwo.c,v 1.5 2015/07/30 07:32:40 skrll Exp $ */ +/* $NetBSD: octeon_dwctwo.c,v 1.6 2015/08/30 13:02:42 skrll Exp $ */ /* * Copyright (c) 2015 Masao Uebayashi <uebay...@tombiinc.com> @@ -43,7 +43,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: octeon_dwctwo.c,v 1.5 2015/07/30 07:32:40 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: octeon_dwctwo.c,v 1.6 2015/08/30 13:02:42 skrll Exp $"); #include "opt_octeon.h" #include "opt_usb.h" @@ -135,6 +135,8 @@ static struct dwc2_core_params octeon_dw .reload_ctl = 0, .ahbcfg = 0, /* XXX */ .uframe_sched = 1, + .external_id_pin_ctl = -1, + .hibernation = -1, }; CFATTACH_DECL_NEW(octeon_dwctwo, sizeof(struct octeon_dwc2_softc), Index: src/sys/arch/mips/ingenic/ingenic_dwctwo.c diff -u src/sys/arch/mips/ingenic/ingenic_dwctwo.c:1.11 src/sys/arch/mips/ingenic/ingenic_dwctwo.c:1.12 --- src/sys/arch/mips/ingenic/ingenic_dwctwo.c:1.11 Mon May 18 15:11:47 2015 +++ src/sys/arch/mips/ingenic/ingenic_dwctwo.c Sun Aug 30 13:02:42 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: ingenic_dwctwo.c,v 1.11 2015/05/18 15:11:47 macallan Exp $ */ +/* $NetBSD: ingenic_dwctwo.c,v 1.12 2015/08/30 13:02:42 skrll Exp $ */ /*- * Copyright (c) 2014 Michael Lorenz @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ingenic_dwctwo.c,v 1.11 2015/05/18 15:11:47 macallan Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ingenic_dwctwo.c,v 1.12 2015/08/30 13:02:42 skrll Exp $"); /* * adapted from bcm2835_dwctwo.c @@ -87,6 +87,8 @@ static struct dwc2_core_params ingenic_d .reload_ctl = -1, .ahbcfg = -1, .uframe_sched = 0, + .external_id_pin_ctl = -1, + .hibernation = -1, }; static int ingenic_dwc2_match(device_t, struct cfdata *, void *); Index: src/sys/external/bsd/dwc2/dwc2.c diff -u src/sys/external/bsd/dwc2/dwc2.c:1.36 src/sys/external/bsd/dwc2/dwc2.c:1.37 --- src/sys/external/bsd/dwc2/dwc2.c:1.36 Sun Aug 30 10:48:15 2015 +++ src/sys/external/bsd/dwc2/dwc2.c Sun Aug 30 13:02:42 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: dwc2.c,v 1.36 2015/08/30 10:48:15 skrll Exp $ */ +/* $NetBSD: dwc2.c,v 1.37 2015/08/30 13:02:42 skrll Exp $ */ /*- * Copyright (c) 2013 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: dwc2.c,v 1.36 2015/08/30 10:48:15 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dwc2.c,v 1.37 2015/08/30 13:02:42 skrll Exp $"); #include "opt_usb.h" @@ -1241,7 +1241,7 @@ dwc2_device_start(usbd_xfer_handle xfer) uint32_t flags = 0; uint32_t off = 0; - int retval, err = USBD_IN_PROGRESS; + int retval, err; int alloc_bandwidth = 0; int i; @@ -1298,6 +1298,8 @@ dwc2_device_start(usbd_xfer_handle xfer) memset(dwc2_urb, 0, sizeof(*dwc2_urb) + sizeof(dwc2_urb->iso_descs[0]) * DWC2_MAXISOCPACKETS); + dwc2_urb->priv = xfer; + dwc2_hcd_urb_set_pipeinfo(hsotg, dwc2_urb, addr, epnum, xfertype, dir, mps); @@ -1378,6 +1380,28 @@ dwc2_device_start(usbd_xfer_handle xfer) off += xfer->frlengths[i]; } + struct dwc2_qh *qh = dpipe->priv; + struct dwc2_qtd *qtd; + bool qh_allocated = false; + + /* Create QH for the endpoint if it doesn't exist */ + if (!qh) { + qh = dwc2_hcd_qh_create(hsotg, dwc2_urb, GFP_ATOMIC); + if (!qh) { + retval = -ENOMEM; + goto fail; + } + dpipe->priv = qh; + qh_allocated = true; + } + + qtd = pool_cache_get(sc->sc_qtdpool, PR_NOWAIT); + if (!qtd) { + retval = -ENOMEM; + goto fail1; + } + memset(qtd, 0, sizeof(*qtd)); + /* might need to check cpu_intr_p */ mutex_spin_enter(&hsotg->lock); @@ -1385,11 +1409,9 @@ dwc2_device_start(usbd_xfer_handle xfer) callout_reset(&xfer->timeout_handle, mstohz(xfer->timeout), dwc2_timeout, xfer); } - - dwc2_urb->priv = xfer; - retval = dwc2_hcd_urb_enqueue(hsotg, dwc2_urb, &dpipe->priv, 0); + retval = dwc2_hcd_urb_enqueue(hsotg, dwc2_urb, qh, qtd); if (retval) - goto fail; + goto fail2; if (alloc_bandwidth) { dwc2_allocate_bus_bandwidth(hsotg, @@ -1397,14 +1419,25 @@ dwc2_device_start(usbd_xfer_handle xfer) xfer); } -fail: mutex_spin_exit(&hsotg->lock); - // mutex_exit(&sc->sc_lock); + return USBD_IN_PROGRESS; + +fail2: + dwc2_urb->priv = NULL; + mutex_spin_exit(&hsotg->lock); + pool_cache_put(sc->sc_qtdpool, qtd); + +fail1: + if (qh_allocated) { + dpipe->priv = NULL; + dwc2_hcd_qh_free(hsotg, qh); + } +fail: + switch (retval) { - case 0: - break; + case -EINVAL: case -ENODEV: err = USBD_INVAL; break; @@ -1419,6 +1452,7 @@ fail: } +#if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE) void dwc2_worker(struct work *wk, void *priv) { @@ -1455,6 +1489,7 @@ Debugger(); } mutex_exit(&sc->sc_lock); } +#endif int dwc2_intr(void *p) { @@ -1600,15 +1635,66 @@ dwc2_init(struct dwc2_softc *sc) sc->sc_hsotg->dev = sc->sc_dev; sc->sc_hcdenabled = true; - err = dwc2_hcd_init(sc->sc_hsotg, sc->sc_params); - if (err) { - err = -err; + struct dwc2_hsotg *hsotg = sc->sc_hsotg; + struct dwc2_core_params defparams; + int retval; + + if (sc->sc_params == NULL) { + /* Default all params to autodetect */ + dwc2_set_all_params(&defparams, -1); + sc->sc_params = &defparams; + + /* + * Disable descriptor dma mode by default as the HW can support + * it, but does not support it for SPLIT transactions. + */ + defparams.dma_desc_enable = 0; + } + hsotg->dr_mode = USB_DR_MODE_HOST; + + /* Detect config values from hardware */ + retval = dwc2_get_hwparams(hsotg); + if (retval) { goto fail2; } + hsotg->core_params = kmem_zalloc(sizeof(*hsotg->core_params), KM_SLEEP); + if (!hsotg->core_params) { + retval = -ENOMEM; + goto fail2; + } + + dwc2_set_all_params(hsotg->core_params, -1); + + /* Validate parameter values */ + dwc2_set_parameters(hsotg, sc->sc_params); + +#if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \ + IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE) + if (hsotg->dr_mode != USB_DR_MODE_HOST) { + retval = dwc2_gadget_init(hsotg); + if (retval) + goto fail2; + hsotg->gadget_enabled = 1; + } +#endif +#if IS_ENABLED(CONFIG_USB_DWC2_HOST) || \ + IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE) + if (hsotg->dr_mode != USB_DR_MODE_PERIPHERAL) { + retval = dwc2_hcd_init(hsotg); + if (retval) { + if (hsotg->gadget_enabled) + s3c_hsotg_remove(hsotg); + goto fail2; + } + hsotg->hcd_enabled = 1; + } +#endif + return 0; fail2: + err = -retval; kmem_free(sc->sc_hsotg, sizeof(struct dwc2_hsotg)); fail1: softint_disestablish(sc->sc_rhc_si); @@ -1797,13 +1883,8 @@ _dwc2_hcd_start(struct dwc2_hsotg *hsotg mutex_spin_enter(&hsotg->lock); - hsotg->op_state = OTG_STATE_A_HOST; - dwc2_hcd_reinit(hsotg); - /*XXXNH*/ - delay(50); - mutex_spin_exit(&hsotg->lock); return 0; } Index: src/sys/external/bsd/dwc2/dwc2.h diff -u src/sys/external/bsd/dwc2/dwc2.h:1.6 src/sys/external/bsd/dwc2/dwc2.h:1.7 --- src/sys/external/bsd/dwc2/dwc2.h:1.6 Sun Aug 30 12:26:29 2015 +++ src/sys/external/bsd/dwc2/dwc2.h Sun Aug 30 13:02:42 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: dwc2.h,v 1.6 2015/08/30 12:26:29 skrll Exp $ */ +/* $NetBSD: dwc2.h,v 1.7 2015/08/30 13:02:42 skrll Exp $ */ /*- * Copyright (c) 2013 The NetBSD Foundation, Inc. @@ -36,6 +36,7 @@ #include <sys/callout.h> #include <sys/kernel.h> +#include <sys/proc.h> #include <sys/workqueue.h> #include <linux/list.h> @@ -45,6 +46,10 @@ // #define DWC2_DUMP_FRREM // #define CONFIG_USB_DWC2_TRACK_MISSED_SOFS +#define CONFIG_USB_DWC2_HOST 1 +#define CONFIG_USB_DWC2_DUAL_ROLE 0 +#define CONFIG_USB_DWC2_PERIPHERAL 0 + typedef int irqreturn_t; #define IRQ_NONE 0 #define IRQ_HANDLED 1 @@ -191,17 +196,84 @@ enum usb_otg_state { #define USB_PORT_STAT_C_RESET UPS_C_PORT_RESET #define USB_PORT_STAT_C_L1 UPS_C_PORT_L1 +#define USB_DT_HUB UDESC_HUB + +/* See USB 2.0 spec Table 11-13, offset 3 */ +#define HUB_CHAR_LPSM UHD_PWR +#define HUB_CHAR_COMMON_LPSM UHD_PWR_GANGED +#define HUB_CHAR_INDV_PORT_LPSM UHD_PWR_INDIVIDUAL +#define HUB_CHAR_NO_LPSM UHD_PWR_NO_SWITCH + +#define HUB_CHAR_COMPOUND UHD_COMPOUND + +#define HUB_CHAR_OCPM UHD_OC +#define HUB_CHAR_COMMON_OCPM UHD_OC_GLOBAL +#define HUB_CHAR_INDV_PORT_OCPM UHD_OC_INDIVIDUAL +#define HUB_CHAR_NO_OCPM UHD_OC_NONE + +#define HUB_CHAR_TTTT UHD_TT_THINK +#define HUB_CHAR_PORTIND UHD_PORT_IND + +enum usb_dr_mode { + USB_DR_MODE_UNKNOWN, + USB_DR_MODE_HOST, + USB_DR_MODE_PERIPHERAL, + USB_DR_MODE_OTG, +}; + +struct usb_phy; +struct usb_hcd; + +static inline int +usb_phy_set_suspend(struct usb_phy *x, int suspend) +{ + + return 0; +} + +static inline void +usb_hcd_resume_root_hub(struct usb_hcd *hcd) +{ + + return; +} + +static inline int +usb_disabled(void) +{ + + return 0; +} + static inline void udelay(unsigned long usecs) { + DELAY(usecs); } +static inline void +ndelay(unsigned long nsecs) +{ + + DELAY(nsecs / 1000); +} + +static inline void +msleep(unsigned int msecs) +{ + + kpause("mdelay", false, mstohz(msecs), NULL); +} + #define EREMOTEIO EIO #define ECOMM EIO +#define ENOTSUPP ENOTSUP #define NS_TO_US(ns) ((ns + 500L) / 1000L) +#define USB_RESUME_TIMEOUT 40 /* ms */ + void dw_callout(void *); void dwc2_worker(struct work *, void *);