Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch Add USB stuff. Doesn't quite work yet.
details: https://anonhg.NetBSD.org/src/rev/fa20f05fe806
branches: trunk
changeset: 825079:fa20f05fe806
user: jmcneill <jmcneill%NetBSD.org@localhost>
date: Thu Jun 29 17:08:52 2017 +0000
description:
Add USB stuff. Doesn't quite work yet.
diffstat:
sys/arch/arm/sunxi/files.sunxi | 15 ++-
sys/arch/arm/sunxi/sun8i_h3_ccu.c | 74 ++++++++++-
sys/arch/arm/sunxi/sunxi_ccu.h | 3 +-
sys/arch/arm/sunxi/sunxi_ccu_prediv.c | 17 ++-
sys/arch/arm/sunxi/sunxi_usbphy.c | 215 ++++++++++++++++++++++++++++++++++
sys/arch/evbarm/conf/SUNXI | 14 +-
6 files changed, 316 insertions(+), 22 deletions(-)
diffs (truncated from 465 to 300 lines):
diff -r 3c881f9509af -r fa20f05fe806 sys/arch/arm/sunxi/files.sunxi
--- a/sys/arch/arm/sunxi/files.sunxi Thu Jun 29 17:06:21 2017 +0000
+++ b/sys/arch/arm/sunxi/files.sunxi Thu Jun 29 17:08:52 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.sunxi,v 1.2 2017/06/29 09:26:06 jmcneill Exp $
+# $NetBSD: files.sunxi,v 1.3 2017/06/29 17:08:52 jmcneill Exp $
#
# Configuration info for Allwinner sunxi family SoCs
#
@@ -39,6 +39,19 @@
attach sunximmc at fdt with sunxi_mmc
file arch/arm/sunxi/sunxi_mmc.c sunxi_mmc
+# USB PHY
+device sunxiusbphy
+attach sunxiusbphy at fdt with sunxi_usbphy
+file arch/arm/sunxi/sunxi_usbphy.c sunxi_usbphy
+
+# EHCI
+attach ehci at fdt with ehci_fdt
+file dev/fdt/ehci_fdt.c ehci_fdt
+
+# OHCI
+attach ohci at fdt with ohci_fdt
+file dev/fdt/ohci_fdt.c ohci_fdt
+
# SOC parameters
defflag opt_soc.h SOC_SUNXI
defflag opt_soc.h SOC_SUN8I: SOC_SUNXI
diff -r 3c881f9509af -r fa20f05fe806 sys/arch/arm/sunxi/sun8i_h3_ccu.c
--- a/sys/arch/arm/sunxi/sun8i_h3_ccu.c Thu Jun 29 17:06:21 2017 +0000
+++ b/sys/arch/arm/sunxi/sun8i_h3_ccu.c Thu Jun 29 17:08:52 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sun8i_h3_ccu.c,v 1.3 2017/06/29 10:53:59 jmcneill Exp $ */
+/* $NetBSD: sun8i_h3_ccu.c,v 1.4 2017/06/29 17:08:52 jmcneill Exp $ */
/*-
* Copyright (c) 2017 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -29,7 +29,7 @@
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: sun8i_h3_ccu.c,v 1.3 2017/06/29 10:53:59 jmcneill Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sun8i_h3_ccu.c,v 1.4 2017/06/29 17:08:52 jmcneill Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@@ -41,14 +41,6 @@
#include <arm/sunxi/sunxi_ccu.h>
#include <arm/sunxi/sun8i_h3_ccu.h>
-#define USBPHY_CFG_REG 0x0cc
-#define MBUS_RST_REG 0x0fc
-#define BUS_SOFT_RST_REG0 0x2c0
-#define BUS_SOFT_RST_REG1 0x2c4
-#define BUS_SOFT_RST_REG2 0x2c8
-#define BUS_SOFT_RST_REG3 0x2d0
-#define BUS_SOFT_RST_REG4 0x2d8
-
#define PLL_PERIPH0_CTRL_REG 0x028
#define AHB1_APB1_CFG_REG 0x054
#define APB2_CFG_REG 0x058
@@ -57,6 +49,13 @@
#define SDMMC0_CLK_REG 0x088
#define SDMMC1_CLK_REG 0x08c
#define SDMMC2_CLK_REG 0x090
+#define USBPHY_CFG_REG 0x0cc
+#define MBUS_RST_REG 0x0fc
+#define BUS_SOFT_RST_REG0 0x2c0
+#define BUS_SOFT_RST_REG1 0x2c4
+#define BUS_SOFT_RST_REG2 0x2c8
+#define BUS_SOFT_RST_REG3 0x2d0
+#define BUS_SOFT_RST_REG4 0x2d8
static int sun8i_h3_ccu_match(device_t, cfdata_t, void *);
static void sun8i_h3_ccu_attach(device_t, device_t, void *);
@@ -133,6 +132,7 @@
};
static const char *ahb1_parents[] = { "losc", "hosc", "axi", "pll_periph0" };
+static const char *ahb2_parents[] = { "ahb1", "pll_periph0" };
static const char *apb2_parents[] = { "losc", "hosc", "pll_periph0" };
static const char *mod_parents[] = { "hosc", "pll_periph0", "pll_periph1" };
@@ -153,6 +153,13 @@
__BITS(5,4), /* div */
__BITS(13,12), /* sel */
SUNXI_CCU_PREDIV_POWER_OF_TWO),
+ SUNXI_CCU_PREDIV(H3_CLK_AHB2, "ahb2", ahb2_parents,
+ APB2_CFG_REG, /* reg */
+ 0, /* prediv */
+ __BIT(1), /* prediv_sel */
+ 0, /* div */
+ __BITS(1,0), /* sel */
+ SUNXI_CCU_PREDIV_DIVIDE_BY_TWO),
SUNXI_CCU_NM(H3_CLK_APB2, "apb2", apb2_parents,
APB2_CFG_REG, /* reg */
@@ -178,9 +185,56 @@
BUS_CLK_GATING_REG0, 9),
SUNXI_CCU_GATE(H3_CLK_BUS_MMC2, "bus-mmc2", "ahb1",
BUS_CLK_GATING_REG0, 10),
+ SUNXI_CCU_GATE(H3_CLK_BUS_OTG, "bus-otg", "ahb1",
+ BUS_CLK_GATING_REG0, 23),
+ SUNXI_CCU_GATE(H3_CLK_BUS_EHCI0, "bus-ehci0", "ahb1",
+ BUS_CLK_GATING_REG0, 24),
+ SUNXI_CCU_GATE(H3_CLK_BUS_EHCI1, "bus-ehci1", "ahb2",
+ BUS_CLK_GATING_REG0, 25),
+ SUNXI_CCU_GATE(H3_CLK_BUS_EHCI2, "bus-ehci2", "ahb2",
+ BUS_CLK_GATING_REG0, 26),
+ SUNXI_CCU_GATE(H3_CLK_BUS_EHCI3, "bus-ehci3", "ahb2",
+ BUS_CLK_GATING_REG0, 27),
+ SUNXI_CCU_GATE(H3_CLK_BUS_OHCI0, "bus-ohci0", "ahb1",
+ BUS_CLK_GATING_REG0, 28),
+ SUNXI_CCU_GATE(H3_CLK_BUS_OHCI1, "bus-ohci1", "ahb2",
+ BUS_CLK_GATING_REG0, 29),
+ SUNXI_CCU_GATE(H3_CLK_BUS_OHCI2, "bus-ohci2", "ahb2",
+ BUS_CLK_GATING_REG0, 30),
+ SUNXI_CCU_GATE(H3_CLK_BUS_OHCI3, "bus-ohci3", "ahb2",
+ BUS_CLK_GATING_REG0, 31),
+ SUNXI_CCU_GATE(H3_CLK_BUS_I2C0, "bus-i2c0", "apb2",
+ BUS_CLK_GATING_REG3, 0),
+ SUNXI_CCU_GATE(H3_CLK_BUS_I2C1, "bus-i2c1", "apb2",
+ BUS_CLK_GATING_REG3, 1),
+ SUNXI_CCU_GATE(H3_CLK_BUS_I2C2, "bus-i2c2", "apb2",
+ BUS_CLK_GATING_REG3, 2),
SUNXI_CCU_GATE(H3_CLK_BUS_UART0, "bus-uart0", "apb2",
+ BUS_CLK_GATING_REG3, 16),
+ SUNXI_CCU_GATE(H3_CLK_BUS_UART1, "bus-uart1", "apb2",
+ BUS_CLK_GATING_REG3, 17),
+ SUNXI_CCU_GATE(H3_CLK_BUS_UART2, "bus-uart2", "apb2",
+ BUS_CLK_GATING_REG3, 18),
+ SUNXI_CCU_GATE(H3_CLK_BUS_UART3, "bus-uart3", "apb2",
BUS_CLK_GATING_REG3, 19),
+
+ SUNXI_CCU_GATE(H3_CLK_USBPHY0, "usb-phy0", "hosc",
+ USBPHY_CFG_REG, 8),
+ SUNXI_CCU_GATE(H3_CLK_USBPHY1, "usb-phy1", "hosc",
+ USBPHY_CFG_REG, 9),
+ SUNXI_CCU_GATE(H3_CLK_USBPHY2, "usb-phy2", "hosc",
+ USBPHY_CFG_REG, 10),
+ SUNXI_CCU_GATE(H3_CLK_USBPHY3, "usb-phy3", "hosc",
+ USBPHY_CFG_REG, 11),
+ SUNXI_CCU_GATE(H3_CLK_USBOHCI0, "usb-ohci0", "hosc",
+ USBPHY_CFG_REG, 16),
+ SUNXI_CCU_GATE(H3_CLK_USBOHCI1, "usb-ohci1", "hosc",
+ USBPHY_CFG_REG, 17),
+ SUNXI_CCU_GATE(H3_CLK_USBOHCI2, "usb-ohci2", "hosc",
+ USBPHY_CFG_REG, 18),
+ SUNXI_CCU_GATE(H3_CLK_USBOHCI3, "usb-ohci3", "hosc",
+ USBPHY_CFG_REG, 19),
};
static int
diff -r 3c881f9509af -r fa20f05fe806 sys/arch/arm/sunxi/sunxi_ccu.h
--- a/sys/arch/arm/sunxi/sunxi_ccu.h Thu Jun 29 17:06:21 2017 +0000
+++ b/sys/arch/arm/sunxi/sunxi_ccu.h Thu Jun 29 17:08:52 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_ccu.h,v 1.3 2017/06/29 10:53:59 jmcneill Exp $ */
+/* $NetBSD: sunxi_ccu.h,v 1.4 2017/06/29 17:08:52 jmcneill Exp $ */
/*-
* Copyright (c) 2017 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -180,6 +180,7 @@
uint32_t sel;
uint32_t flags;
#define SUNXI_CCU_PREDIV_POWER_OF_TWO __BIT(0)
+#define SUNXI_CCU_PREDIV_DIVIDE_BY_TWO __BIT(1)
};
u_int sunxi_ccu_prediv_get_rate(struct sunxi_ccu_softc *,
diff -r 3c881f9509af -r fa20f05fe806 sys/arch/arm/sunxi/sunxi_ccu_prediv.c
--- a/sys/arch/arm/sunxi/sunxi_ccu_prediv.c Thu Jun 29 17:06:21 2017 +0000
+++ b/sys/arch/arm/sunxi/sunxi_ccu_prediv.c Thu Jun 29 17:08:52 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_ccu_prediv.c,v 1.1 2017/06/29 09:26:06 jmcneill Exp $ */
+/* $NetBSD: sunxi_ccu_prediv.c,v 1.2 2017/06/29 17:08:52 jmcneill Exp $ */
/*-
* Copyright (c) 2017 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sunxi_ccu_prediv.c,v 1.1 2017/06/29 09:26:06 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_ccu_prediv.c,v 1.2 2017/06/29 17:08:52 jmcneill Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@@ -57,8 +57,14 @@
return 0;
val = CCU_READ(sc, prediv->reg);
- pre = __SHIFTOUT(val, prediv->prediv);
- div = __SHIFTOUT(val, prediv->div);
+ if (prediv->prediv)
+ pre = __SHIFTOUT(val, prediv->prediv);
+ else
+ pre = 0;
+ if (prediv->div)
+ div = __SHIFTOUT(val, prediv->div);
+ else
+ div = 0;
sel = __SHIFTOUT(val, prediv->sel);
if (prediv->flags & SUNXI_CCU_PREDIV_POWER_OF_TWO)
@@ -68,6 +74,9 @@
pre++;
+ if (prediv->flags & SUNXI_CCU_PREDIV_DIVIDE_BY_TWO)
+ pre *= 2;
+
if (prediv->prediv_sel & __BIT(sel))
return rate / pre / div;
else
diff -r 3c881f9509af -r fa20f05fe806 sys/arch/arm/sunxi/sunxi_usbphy.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/sunxi/sunxi_usbphy.c Thu Jun 29 17:08:52 2017 +0000
@@ -0,0 +1,215 @@
+/* $NetBSD: sunxi_usbphy.c,v 1.1 2017/06/29 17:08:52 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2017 Jared McNeill <jmcneill%invisible.ca@localhost>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+
+__KERNEL_RCSID(0, "$NetBSD: sunxi_usbphy.c,v 1.1 2017/06/29 17:08:52 jmcneill Exp $");
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/device.h>
+#include <sys/intr.h>
+#include <sys/systm.h>
+#include <sys/time.h>
+
+#include <dev/fdt/fdtvar.h>
+
+#define OTG_PHY_CFG 0x20
+#define OTG_PHY_ROUTE_OTG __BIT(0)
+
+#define HCI_ICR 0x00
+#define HCI_AHB_INCR8 __BIT(10)
+#define HCI_AHB_INCR4 __BIT(9)
+#define HCI_AHB_INCRX_ALIGN __BIT(8)
+#define HCI_ULPI_BYPASS __BIT(0)
+#define PMU_UNK_H3 0x10
+#define PMU_UNK_H3_CLR __BIT(1)
+
+static int sunxi_usbphy_match(device_t, cfdata_t, void *);
+static void sunxi_usbphy_attach(device_t, device_t, void *);
+
+static const char * const compatible[] = {
+ "allwinner,sun8i-h3-usb-phy",
+ NULL
+};
+
+#define SUNXI_MAXUSBPHY 5
+
+struct sunxi_usbphy {
+ u_int phy_index;
+ bus_space_handle_t phy_bsh;
+ struct fdtbus_regulator *phy_reg;
+};
+
+struct sunxi_usbphy_softc {
+ device_t sc_dev;
+ bus_space_tag_t sc_bst;
+
+ struct sunxi_usbphy sc_phys[SUNXI_MAXUSBPHY];
+ u_int sc_nphys;
+
+ struct fdtbus_gpio_pin *sc_gpio_id_det;
+ struct fdtbus_gpio_pin *sc_gpio_vbus_det;
+};
+
Home |
Main Index |
Thread Index |
Old Index