Home | History | Annotate | Line # | Download | only in sunxi
sunxi_usbphy.c revision 1.9
      1  1.9  jmcneill /* $NetBSD: sunxi_usbphy.c,v 1.9 2017/10/06 22:25:05 jmcneill Exp $ */
      2  1.1  jmcneill 
      3  1.1  jmcneill /*-
      4  1.1  jmcneill  * Copyright (c) 2017 Jared McNeill <jmcneill (at) invisible.ca>
      5  1.1  jmcneill  * All rights reserved.
      6  1.1  jmcneill  *
      7  1.1  jmcneill  * Redistribution and use in source and binary forms, with or without
      8  1.1  jmcneill  * modification, are permitted provided that the following conditions
      9  1.1  jmcneill  * are met:
     10  1.1  jmcneill  * 1. Redistributions of source code must retain the above copyright
     11  1.1  jmcneill  *    notice, this list of conditions and the following disclaimer.
     12  1.1  jmcneill  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  jmcneill  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  jmcneill  *    documentation and/or other materials provided with the distribution.
     15  1.1  jmcneill  *
     16  1.1  jmcneill  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17  1.1  jmcneill  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  1.1  jmcneill  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  1.1  jmcneill  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20  1.1  jmcneill  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  1.1  jmcneill  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  1.1  jmcneill  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  1.1  jmcneill  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  1.1  jmcneill  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  1.1  jmcneill  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  1.1  jmcneill  * POSSIBILITY OF SUCH DAMAGE.
     27  1.1  jmcneill  */
     28  1.1  jmcneill 
     29  1.1  jmcneill #include <sys/cdefs.h>
     30  1.1  jmcneill 
     31  1.9  jmcneill __KERNEL_RCSID(0, "$NetBSD: sunxi_usbphy.c,v 1.9 2017/10/06 22:25:05 jmcneill Exp $");
     32  1.1  jmcneill 
     33  1.1  jmcneill #include <sys/param.h>
     34  1.1  jmcneill #include <sys/bus.h>
     35  1.1  jmcneill #include <sys/device.h>
     36  1.1  jmcneill #include <sys/intr.h>
     37  1.1  jmcneill #include <sys/systm.h>
     38  1.1  jmcneill #include <sys/time.h>
     39  1.1  jmcneill 
     40  1.1  jmcneill #include <dev/fdt/fdtvar.h>
     41  1.1  jmcneill 
     42  1.8  jmcneill /* PHY control registers */
     43  1.8  jmcneill #define	PHYCTL_ICR		0x00
     44  1.8  jmcneill #define	 PHYCTL_ICR_ID_PULLUP	__BIT(17)
     45  1.8  jmcneill #define	 PHYCTL_ICR_DPDM_PULLUP	__BIT(16)
     46  1.8  jmcneill #define	 PHYCTL_ICR_FORCE_ID	__BITS(15,14)
     47  1.8  jmcneill #define	  PHYCTL_ICR_FORCE_ID_LOW	2
     48  1.8  jmcneill #define	  PHYCTL_ICR_FORCE_ID_HIGH	3
     49  1.8  jmcneill #define	 PHYCTL_ICR_FORCE_VBUS	__BITS(13,12)
     50  1.8  jmcneill #define	  PHYCTL_ICR_FORCE_VBUS_LOW	2
     51  1.8  jmcneill #define	  PHYCTL_ICR_FORCE_VBUS_HIGH	3
     52  1.8  jmcneill #define	PHYCTL_A10		0x04
     53  1.8  jmcneill #define	PHYCTL_A33		0x10
     54  1.8  jmcneill #define	 PHYCTL_ADDR		__BITS(15,8)
     55  1.8  jmcneill #define	 PHYCTL_DATA		__BIT(7)
     56  1.8  jmcneill #define	PHYCTL_OTG_CFG		0x20
     57  1.8  jmcneill #define	 PHYCTL_OTG_ROUTE_OTG	__BIT(0)
     58  1.8  jmcneill 
     59  1.8  jmcneill /* PHY registers */
     60  1.8  jmcneill #define	PHY_RES45_CAL_EN	0x0c
     61  1.8  jmcneill #define	PHY_TX_AMPLITUDE_TUNE	0x20
     62  1.8  jmcneill #define	PHY_DISCON_TH_SEL	0x2a
     63  1.8  jmcneill 
     64  1.8  jmcneill /* PMU registers */
     65  1.8  jmcneill #define	PMU_CFG			0x00
     66  1.8  jmcneill #define	 AHB_INCR8		__BIT(10)
     67  1.8  jmcneill #define	 AHB_INCR4		__BIT(9)
     68  1.8  jmcneill #define	 AHB_INCRX_ALIGN	__BIT(8)
     69  1.8  jmcneill #define	 ULPI_BYPASS		__BIT(0)
     70  1.1  jmcneill #define	PMU_UNK_H3		0x10
     71  1.1  jmcneill #define	 PMU_UNK_H3_CLR		__BIT(1)
     72  1.1  jmcneill 
     73  1.1  jmcneill static int sunxi_usbphy_match(device_t, cfdata_t, void *);
     74  1.1  jmcneill static void sunxi_usbphy_attach(device_t, device_t, void *);
     75  1.1  jmcneill 
     76  1.3  jmcneill enum sunxi_usbphy_type {
     77  1.9  jmcneill 	USBPHY_A10 = 1,
     78  1.4  jmcneill 	USBPHY_A13,
     79  1.9  jmcneill 	USBPHY_A20,
     80  1.3  jmcneill 	USBPHY_A31,
     81  1.3  jmcneill 	USBPHY_H3,
     82  1.6  jmcneill 	USBPHY_A64,
     83  1.3  jmcneill };
     84  1.3  jmcneill 
     85  1.3  jmcneill static const struct of_compat_data compat_data[] = {
     86  1.9  jmcneill 	{ "allwinner,sun4i-a10-usb-phy",	USBPHY_A10 },
     87  1.4  jmcneill 	{ "allwinner,sun5i-a13-usb-phy",	USBPHY_A13 },
     88  1.3  jmcneill 	{ "allwinner,sun6i-a31-usb-phy",	USBPHY_A31 },
     89  1.9  jmcneill 	{ "allwinner,sun7i-a20-usb-phy",	USBPHY_A20 },
     90  1.3  jmcneill 	{ "allwinner,sun8i-h3-usb-phy",		USBPHY_H3 },
     91  1.6  jmcneill 	{ "allwinner,sun50i-a64-usb-phy",	USBPHY_A64 },
     92  1.3  jmcneill 	{ NULL }
     93  1.1  jmcneill };
     94  1.1  jmcneill 
     95  1.2  jmcneill #define	SUNXI_MAXUSBPHY		4
     96  1.1  jmcneill 
     97  1.1  jmcneill struct sunxi_usbphy {
     98  1.1  jmcneill 	u_int			phy_index;
     99  1.1  jmcneill 	bus_space_handle_t	phy_bsh;
    100  1.1  jmcneill 	struct fdtbus_regulator *phy_reg;
    101  1.1  jmcneill };
    102  1.1  jmcneill 
    103  1.1  jmcneill struct sunxi_usbphy_softc {
    104  1.1  jmcneill 	device_t		sc_dev;
    105  1.1  jmcneill 	bus_space_tag_t		sc_bst;
    106  1.2  jmcneill 	bus_space_handle_t	sc_bsh_phy_ctrl;
    107  1.3  jmcneill 	enum sunxi_usbphy_type	sc_type;
    108  1.1  jmcneill 
    109  1.1  jmcneill 	struct sunxi_usbphy	sc_phys[SUNXI_MAXUSBPHY];
    110  1.1  jmcneill 	u_int			sc_nphys;
    111  1.1  jmcneill 
    112  1.1  jmcneill 	struct fdtbus_gpio_pin	*sc_gpio_id_det;
    113  1.1  jmcneill 	struct fdtbus_gpio_pin	*sc_gpio_vbus_det;
    114  1.1  jmcneill };
    115  1.1  jmcneill 
    116  1.8  jmcneill #define	PHYCTL_READ(sc, reg)				\
    117  1.8  jmcneill 	bus_space_read_4((sc)->sc_bst,			\
    118  1.8  jmcneill 	    (sc)->sc_bsh_phy_ctrl, (reg))
    119  1.8  jmcneill #define	PHYCTL_WRITE(sc, reg, val)			\
    120  1.8  jmcneill 	bus_space_write_4((sc)->sc_bst,			\
    121  1.8  jmcneill 	    (sc)->sc_bsh_phy_ctrl, (reg), (val))
    122  1.8  jmcneill #define	PMU_READ(sc, id, reg)			\
    123  1.1  jmcneill 	bus_space_read_4((sc)->sc_bst,			\
    124  1.1  jmcneill 	    (sc)->sc_phys[(id)].phy_bsh, (reg))
    125  1.8  jmcneill #define	PMU_WRITE(sc, id, reg, val)			\
    126  1.1  jmcneill 	bus_space_write_4((sc)->sc_bst,			\
    127  1.1  jmcneill 	    (sc)->sc_phys[(id)].phy_bsh, (reg), (val))
    128  1.1  jmcneill 
    129  1.1  jmcneill CFATTACH_DECL_NEW(sunxi_usbphy, sizeof(struct sunxi_usbphy_softc),
    130  1.1  jmcneill 	sunxi_usbphy_match, sunxi_usbphy_attach, NULL, NULL);
    131  1.1  jmcneill 
    132  1.8  jmcneill static void
    133  1.8  jmcneill sunxi_usbphy_write(struct sunxi_usbphy_softc *sc,
    134  1.8  jmcneill     struct sunxi_usbphy *phy, u_int bit_addr, u_int bits,
    135  1.8  jmcneill     u_int len)
    136  1.8  jmcneill {
    137  1.8  jmcneill 	const uint32_t usbc_mask = __BIT(phy->phy_index * 2);;
    138  1.8  jmcneill 	bus_size_t reg;
    139  1.8  jmcneill 	uint32_t val;
    140  1.8  jmcneill 
    141  1.8  jmcneill 	switch (sc->sc_type) {
    142  1.9  jmcneill 	case USBPHY_A10:
    143  1.8  jmcneill 	case USBPHY_A13:
    144  1.9  jmcneill 	case USBPHY_A20:
    145  1.8  jmcneill 	case USBPHY_A31:
    146  1.8  jmcneill 		reg = PHYCTL_A10;
    147  1.8  jmcneill 		break;
    148  1.8  jmcneill 	case USBPHY_H3:
    149  1.8  jmcneill 	case USBPHY_A64:
    150  1.8  jmcneill 		reg = PHYCTL_A33;
    151  1.8  jmcneill 		break;
    152  1.8  jmcneill 	default:
    153  1.8  jmcneill 		panic("unsupported phy type");
    154  1.8  jmcneill 	}
    155  1.8  jmcneill 
    156  1.8  jmcneill 	if (reg == PHYCTL_A33)
    157  1.8  jmcneill 		PHYCTL_WRITE(sc, reg, 0);
    158  1.8  jmcneill 
    159  1.8  jmcneill 	for (; len > 0; bit_addr++, bits >>= 1, len--) {
    160  1.8  jmcneill 		val = PHYCTL_READ(sc, reg);
    161  1.8  jmcneill 		val &= ~PHYCTL_ADDR;
    162  1.8  jmcneill 		val |= __SHIFTIN(bit_addr, PHYCTL_ADDR);
    163  1.8  jmcneill 		PHYCTL_WRITE(sc, reg, val);
    164  1.8  jmcneill 
    165  1.8  jmcneill 		val = PHYCTL_READ(sc, reg);
    166  1.8  jmcneill 		val &= ~PHYCTL_DATA;
    167  1.8  jmcneill 		val |= __SHIFTIN(bits & 1, PHYCTL_DATA);
    168  1.8  jmcneill 		PHYCTL_WRITE(sc, reg, val);
    169  1.8  jmcneill 
    170  1.8  jmcneill 		PHYCTL_READ(sc, reg);
    171  1.8  jmcneill 		val |= usbc_mask;
    172  1.8  jmcneill 		PHYCTL_WRITE(sc, reg, val);
    173  1.8  jmcneill 
    174  1.8  jmcneill 		PHYCTL_READ(sc, reg);
    175  1.8  jmcneill 		val &= ~usbc_mask;
    176  1.8  jmcneill 		PHYCTL_WRITE(sc, reg, val);
    177  1.8  jmcneill 	}
    178  1.8  jmcneill }
    179  1.8  jmcneill 
    180  1.1  jmcneill static bool
    181  1.1  jmcneill sunxi_usbphy_vbus_detect(struct sunxi_usbphy_softc *sc)
    182  1.1  jmcneill {
    183  1.1  jmcneill 	if (sc->sc_gpio_vbus_det)
    184  1.1  jmcneill 		return fdtbus_gpio_read(sc->sc_gpio_vbus_det);
    185  1.1  jmcneill 	return 1;
    186  1.1  jmcneill }
    187  1.1  jmcneill 
    188  1.1  jmcneill static void *
    189  1.1  jmcneill sunxi_usbphy_acquire(device_t dev, const void *data, size_t len)
    190  1.1  jmcneill {
    191  1.1  jmcneill 	struct sunxi_usbphy_softc * const sc = device_private(dev);
    192  1.1  jmcneill 
    193  1.1  jmcneill 	if (len != 4)
    194  1.1  jmcneill 		return NULL;
    195  1.1  jmcneill 
    196  1.1  jmcneill 	const int phy_id = be32dec(data);
    197  1.1  jmcneill 	if (phy_id >= sc->sc_nphys)
    198  1.1  jmcneill 		return NULL;
    199  1.1  jmcneill 
    200  1.1  jmcneill 	return &sc->sc_phys[phy_id];
    201  1.1  jmcneill }
    202  1.1  jmcneill 
    203  1.1  jmcneill static void
    204  1.1  jmcneill sunxi_usbphy_release(device_t dev, void *priv)
    205  1.1  jmcneill {
    206  1.1  jmcneill }
    207  1.1  jmcneill 
    208  1.1  jmcneill static int
    209  1.1  jmcneill sunxi_usbphy_enable(device_t dev, void *priv, bool enable)
    210  1.1  jmcneill {
    211  1.1  jmcneill 	struct sunxi_usbphy_softc * const sc = device_private(dev);
    212  1.1  jmcneill 	struct sunxi_usbphy * const phy = priv;
    213  1.8  jmcneill 	u_int disc_thresh;
    214  1.8  jmcneill 	bool phy0_reroute;
    215  1.1  jmcneill 	uint32_t val;
    216  1.1  jmcneill 
    217  1.8  jmcneill 	switch (sc->sc_type) {
    218  1.8  jmcneill 	case USBPHY_A13:
    219  1.8  jmcneill 		disc_thresh = 0x2;
    220  1.8  jmcneill 		phy0_reroute = false;
    221  1.8  jmcneill 		break;
    222  1.9  jmcneill 	case USBPHY_A10:
    223  1.9  jmcneill 	case USBPHY_A20:
    224  1.8  jmcneill 	case USBPHY_A31:
    225  1.8  jmcneill 		disc_thresh = 0x3;
    226  1.8  jmcneill 		phy0_reroute = false;
    227  1.8  jmcneill 		break;
    228  1.8  jmcneill 	case USBPHY_A64:
    229  1.8  jmcneill 	case USBPHY_H3:
    230  1.8  jmcneill 		disc_thresh = 0x3;
    231  1.8  jmcneill 		phy0_reroute = true;
    232  1.8  jmcneill 		break;
    233  1.9  jmcneill 	default:
    234  1.9  jmcneill 		aprint_error_dev(dev, "unsupported board\n");
    235  1.9  jmcneill 		return ENXIO;
    236  1.8  jmcneill 	}
    237  1.8  jmcneill 
    238  1.8  jmcneill 	if (phy->phy_bsh) {
    239  1.8  jmcneill 		/* Enable/disable passby */
    240  1.8  jmcneill 		const uint32_t mask =
    241  1.8  jmcneill 		    ULPI_BYPASS|AHB_INCR8|AHB_INCR4|AHB_INCRX_ALIGN;
    242  1.8  jmcneill 		val = PMU_READ(sc, phy->phy_index, PMU_CFG);
    243  1.8  jmcneill 		if (enable)
    244  1.8  jmcneill 			val |= mask;
    245  1.8  jmcneill 		else
    246  1.8  jmcneill 			val &= ~mask;
    247  1.8  jmcneill 		PMU_WRITE(sc, phy->phy_index, PMU_CFG, val);
    248  1.1  jmcneill 	}
    249  1.1  jmcneill 
    250  1.7  jmcneill 	switch (sc->sc_type) {
    251  1.7  jmcneill 	case USBPHY_H3:
    252  1.7  jmcneill 	case USBPHY_A64:
    253  1.8  jmcneill 		if (enable && phy->phy_bsh) {
    254  1.8  jmcneill 			val = PMU_READ(sc, phy->phy_index, PMU_UNK_H3);
    255  1.8  jmcneill 			val &= ~PMU_UNK_H3_CLR;
    256  1.8  jmcneill 			PMU_WRITE(sc, phy->phy_index, PMU_UNK_H3, val);
    257  1.8  jmcneill 		}
    258  1.7  jmcneill 		break;
    259  1.7  jmcneill 	default:
    260  1.7  jmcneill 		break;
    261  1.3  jmcneill 	}
    262  1.1  jmcneill 
    263  1.8  jmcneill 	if (enable) {
    264  1.8  jmcneill 		if (phy->phy_index == 0)
    265  1.8  jmcneill 			sunxi_usbphy_write(sc, phy, PHY_RES45_CAL_EN, 0x1, 1);
    266  1.8  jmcneill 		sunxi_usbphy_write(sc, phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5);
    267  1.8  jmcneill 		sunxi_usbphy_write(sc, phy, PHY_DISCON_TH_SEL, disc_thresh, 2);
    268  1.8  jmcneill 	}
    269  1.8  jmcneill 
    270  1.8  jmcneill 	if (phy->phy_index == 0) {
    271  1.8  jmcneill 		const uint32_t mask =
    272  1.8  jmcneill 		    PHYCTL_ICR_ID_PULLUP|PHYCTL_ICR_DPDM_PULLUP;
    273  1.8  jmcneill 		val = PHYCTL_READ(sc, PHYCTL_ICR);
    274  1.8  jmcneill 
    275  1.8  jmcneill 		if (enable)
    276  1.8  jmcneill 			val |= mask;
    277  1.8  jmcneill 		else
    278  1.8  jmcneill 			val &= ~mask;
    279  1.8  jmcneill 
    280  1.8  jmcneill 		/* XXX only host mode is supported */
    281  1.8  jmcneill 		val &= ~PHYCTL_ICR_FORCE_ID;
    282  1.8  jmcneill 		val |= __SHIFTIN(PHYCTL_ICR_FORCE_ID_LOW, PHYCTL_ICR_FORCE_ID);
    283  1.8  jmcneill 		val &= ~PHYCTL_ICR_FORCE_VBUS;
    284  1.8  jmcneill 		val |= __SHIFTIN(PHYCTL_ICR_FORCE_VBUS_HIGH, PHYCTL_ICR_FORCE_VBUS);
    285  1.8  jmcneill 
    286  1.8  jmcneill 		PHYCTL_WRITE(sc, PHYCTL_ICR, val);
    287  1.8  jmcneill 
    288  1.8  jmcneill 		if (phy0_reroute) {
    289  1.8  jmcneill 			val = PHYCTL_READ(sc, PHYCTL_OTG_CFG);
    290  1.8  jmcneill 			val &= ~PHYCTL_OTG_ROUTE_OTG;
    291  1.8  jmcneill 			PHYCTL_WRITE(sc, PHYCTL_OTG_CFG, val);
    292  1.8  jmcneill 		}
    293  1.8  jmcneill 	}
    294  1.8  jmcneill 
    295  1.1  jmcneill 	if (phy->phy_reg == NULL)
    296  1.1  jmcneill 		return 0;
    297  1.1  jmcneill 
    298  1.1  jmcneill 	if (enable) {
    299  1.1  jmcneill 		/* If an external vbus is detected, do not enable phy 0 */
    300  1.1  jmcneill 		if (phy->phy_index == 0 && sunxi_usbphy_vbus_detect(sc))
    301  1.1  jmcneill 			return 0;
    302  1.1  jmcneill 		return fdtbus_regulator_enable(phy->phy_reg);
    303  1.1  jmcneill 	} else {
    304  1.1  jmcneill 		return fdtbus_regulator_disable(phy->phy_reg);
    305  1.1  jmcneill 	}
    306  1.1  jmcneill }
    307  1.1  jmcneill 
    308  1.1  jmcneill const struct fdtbus_phy_controller_func sunxi_usbphy_funcs = {
    309  1.1  jmcneill 	.acquire = sunxi_usbphy_acquire,
    310  1.1  jmcneill 	.release = sunxi_usbphy_release,
    311  1.1  jmcneill 	.enable = sunxi_usbphy_enable,
    312  1.1  jmcneill };
    313  1.1  jmcneill 
    314  1.1  jmcneill static int
    315  1.1  jmcneill sunxi_usbphy_match(device_t parent, cfdata_t cf, void *aux)
    316  1.1  jmcneill {
    317  1.1  jmcneill 	struct fdt_attach_args * const faa = aux;
    318  1.1  jmcneill 
    319  1.3  jmcneill 	return of_match_compat_data(faa->faa_phandle, compat_data);
    320  1.1  jmcneill }
    321  1.1  jmcneill 
    322  1.1  jmcneill static void
    323  1.1  jmcneill sunxi_usbphy_attach(device_t parent, device_t self, void *aux)
    324  1.1  jmcneill {
    325  1.1  jmcneill 	struct sunxi_usbphy_softc * const sc = device_private(self);
    326  1.1  jmcneill 	struct fdt_attach_args * const faa = aux;
    327  1.1  jmcneill 	const int phandle = faa->faa_phandle;
    328  1.1  jmcneill 	struct fdtbus_reset *rst;
    329  1.1  jmcneill 	struct sunxi_usbphy *phy;
    330  1.1  jmcneill 	struct clk *clk;
    331  1.1  jmcneill 	bus_addr_t addr;
    332  1.1  jmcneill 	bus_size_t size;
    333  1.1  jmcneill 	char pname[20];
    334  1.1  jmcneill 	u_int n;
    335  1.1  jmcneill 
    336  1.1  jmcneill 	sc->sc_dev = self;
    337  1.1  jmcneill 	sc->sc_bst = faa->faa_bst;
    338  1.3  jmcneill 	sc->sc_type = of_search_compatible(phandle, compat_data)->data;
    339  1.1  jmcneill 
    340  1.5  jmcneill 	if (fdtbus_get_reg_byname(phandle, "phy_ctrl", &addr, &size) != 0) {
    341  1.2  jmcneill 		aprint_error(": couldn't get phy ctrl registers\n");
    342  1.2  jmcneill 		return;
    343  1.2  jmcneill 	}
    344  1.2  jmcneill 	if (bus_space_map(sc->sc_bst, addr, size, 0, &sc->sc_bsh_phy_ctrl) != 0) {
    345  1.2  jmcneill 		aprint_error(": couldn't map phy ctrl registers\n");
    346  1.2  jmcneill 		return;
    347  1.2  jmcneill 	}
    348  1.2  jmcneill 
    349  1.1  jmcneill 	for (sc->sc_nphys = 0; sc->sc_nphys < SUNXI_MAXUSBPHY; sc->sc_nphys++) {
    350  1.1  jmcneill 		phy = &sc->sc_phys[sc->sc_nphys];
    351  1.1  jmcneill 		phy->phy_index = sc->sc_nphys;
    352  1.5  jmcneill 		snprintf(pname, sizeof(pname), "pmu%d", sc->sc_nphys);
    353  1.5  jmcneill 		if (fdtbus_get_reg_byname(phandle, pname, &addr, &size) != 0) {
    354  1.5  jmcneill 			/* There may be no registers for OTG PHY */
    355  1.5  jmcneill 			if (sc->sc_nphys > 0)
    356  1.5  jmcneill 				break;
    357  1.5  jmcneill 		} else if (bus_space_map(sc->sc_bst, addr, size, 0, &phy->phy_bsh) != 0) {
    358  1.1  jmcneill 			aprint_error(": failed to map reg #%d\n", sc->sc_nphys);
    359  1.1  jmcneill 			return;
    360  1.1  jmcneill 		}
    361  1.1  jmcneill 		/* Get optional regulator */
    362  1.1  jmcneill 		snprintf(pname, sizeof(pname), "usb%d_vbus-supply", sc->sc_nphys);
    363  1.1  jmcneill 		phy->phy_reg = fdtbus_regulator_acquire(phandle, pname);
    364  1.1  jmcneill 	}
    365  1.1  jmcneill 
    366  1.1  jmcneill 	/* Enable clocks */
    367  1.1  jmcneill 	for (n = 0; (clk = fdtbus_clock_get_index(phandle, n)) != NULL; n++)
    368  1.1  jmcneill 		if (clk_enable(clk) != 0) {
    369  1.1  jmcneill 			aprint_error(": couldn't enable clock #%d\n", n);
    370  1.1  jmcneill 			return;
    371  1.1  jmcneill 		}
    372  1.1  jmcneill 	/* De-assert resets */
    373  1.1  jmcneill 	for (n = 0; (rst = fdtbus_reset_get_index(phandle, n)) != NULL; n++)
    374  1.1  jmcneill 		if (fdtbus_reset_deassert(rst) != 0) {
    375  1.1  jmcneill 			aprint_error(": couldn't de-assert reset #%d\n", n);
    376  1.1  jmcneill 			return;
    377  1.1  jmcneill 		}
    378  1.1  jmcneill 
    379  1.1  jmcneill 	aprint_naive("\n");
    380  1.1  jmcneill 	aprint_normal(": USB PHY\n");
    381  1.1  jmcneill 
    382  1.1  jmcneill 	fdtbus_register_phy_controller(self, phandle, &sunxi_usbphy_funcs);
    383  1.1  jmcneill }
    384