Home | History | Annotate | Line # | Download | only in broadcom
bcm53xx_ccb.c revision 1.5.2.2
      1 /*-
      2  * Copyright (c) 2012 The NetBSD Foundation, Inc.
      3  * All rights reserved.
      4  *
      5  * This code is derived from software contributed to The NetBSD Foundation
      6  * by Matt Thomas of 3am Software Foundry.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  *
     17  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     20  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     21  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     27  * POSSIBILITY OF SUCH DAMAGE.
     28  */
     29 
     30 #include "opt_broadcom.h"
     31 #include "locators.h"
     32 
     33 #define IDM_PRIVATE
     34 
     35 #include <sys/cdefs.h>
     36 
     37 __KERNEL_RCSID(1, "$NetBSD: bcm53xx_ccb.c,v 1.5.2.2 2014/02/15 16:18:36 matt Exp $");
     38 
     39 #include <sys/param.h>
     40 #include <sys/bus.h>
     41 #include <sys/device.h>
     42 #include <sys/intr.h>
     43 #include <sys/systm.h>
     44 
     45 #include <arm/mainbus/mainbus.h>
     46 
     47 #include <arm/broadcom/bcm53xx_reg.h>
     48 #include <arm/broadcom/bcm53xx_var.h>
     49 
     50 static int bcmccb_mainbus_match(device_t, cfdata_t, void *);
     51 static void bcmccb_mainbus_attach(device_t, device_t, void *);
     52 
     53 struct bcmccb_softc {
     54 	device_t sc_dev;
     55 	bus_space_tag_t sc_bst;
     56 	bus_space_handle_t sc_bsh;
     57 };
     58 
     59 static struct bcmccb_softc bcmccb_sc;
     60 
     61 CFATTACH_DECL_NEW(bcmccb, 0,
     62     bcmccb_mainbus_match, bcmccb_mainbus_attach, NULL, NULL);
     63 
     64 static int
     65 bcmccb_mainbus_match(device_t parent, cfdata_t cf, void *aux)
     66 {
     67 	if (bcmccb_sc.sc_dev != NULL)
     68 		return 0;
     69 
     70 	return 1;
     71 }
     72 
     73 static int
     74 bcmccb_print(void *aux, const char *pnp)
     75 {
     76 	const struct bcmccb_attach_args * const ccbaa = aux;
     77 
     78 	if (ccbaa->ccbaa_loc.loc_port != BCMCCBCF_PORT_DEFAULT)
     79 		aprint_normal(" port %d", ccbaa->ccbaa_loc.loc_port);
     80 
     81 	return QUIET;
     82 }
     83 
     84 __unused static inline uint32_t
     85 bcmccb_read_4(struct bcmccb_softc *sc, bus_size_t o)
     86 {
     87 	return bus_space_read_4(sc->sc_bst, sc->sc_bsh, o);
     88 }
     89 
     90 __unused static inline void
     91 bcmccb_write_4(struct bcmccb_softc *sc, bus_size_t o, uint32_t v)
     92 {
     93 	return bus_space_write_4(sc->sc_bst, sc->sc_bsh, o, v);
     94 }
     95 
     96 static const struct bcm_locators bcmccb_locators[] = {
     97 	{ "bcmpwn", PWM_BASE, 0x1000, BCMCCBCF_PORT_DEFAULT },
     98 	{ "bcmmdio", MII_BASE, 0x1000, BCMCCBCF_PORT_DEFAULT },
     99 	{ "bcmrng", RNG_BASE, 0x1000, BCMCCBCF_PORT_DEFAULT, 1, { IRQ_RNG } },
    100 	{ "bcmtmr", TIMER0_BASE, 0x1000, BCMCCBCF_PORT_DEFAULT, 2, { IRQ_TIMER0_1, IRQ_TIMER0_2 } },
    101 	{ "bcmtmr", TIMER1_BASE, 0x1000, BCMCCBCF_PORT_DEFAULT, 2, { IRQ_TIMER1_1, IRQ_TIMER1_2 } },
    102 	{ "bcmsw", SRAB_BASE, 0x1000, BCMCCBCF_PORT_DEFAULT, },
    103 	{ "bcmcom", UART2_BASE, 0x1000, BCMCCBCF_PORT_DEFAULT, 1, { IRQ_UART2 } },
    104 #ifdef BCM5301X
    105 	{ "bcmi2c", SMBUS1_BASE, 0x1000, BCMCCBCF_PORT_DEFAULT, 1, { IRQ_SMBUS1 } },
    106 #endif
    107 #ifdef BCM536XX
    108 	{ "bcmi2c", SMBUS1_BASE, 0x1000, 1, 1, { IRQ_SMBUS1 } },
    109 	{ "bcmi2c", SMBUS2_BASE, 0x1000, 2, 1, { IRQ_SMBUS2 } },
    110 #endif
    111 	{ "bcmcru", CRU_BASE, 0x1000, BCMCCBCF_PORT_DEFAULT },
    112 	{ "bcmdmu", DMU_BASE, 0x1000, BCMCCBCF_PORT_DEFAULT },
    113 	{ "bcmddr", DDR_BASE, 0x1000, BCMCCBCF_PORT_DEFAULT, 1, { IRQ_DDR_CONTROLLER } },
    114 	{ "bcmeth", GMAC0_BASE, 0x1000, 0, 1, { IRQ_GMAC0 }, },
    115 	{ "bcmeth", GMAC1_BASE, 0x1000, 1, 1, { IRQ_GMAC1 }, },
    116 #ifdef GMAC2_BASE
    117 	{ "bcmeth", GMAC2_BASE, 0x1000, 2, 1, { IRQ_GMAC2 }, },
    118 #endif
    119 	// { "bcmeth", GMAC3_BASE, 0x1000, 3, 1, { IRQ_GMAC3 }, },
    120 	{ "bcmpax", PCIE0_BASE, 0x1000, 0, 6, { IRQ_PCIE_INT0 }, },
    121 	{ "bcmpax", PCIE1_BASE, 0x1000, 1, 6, { IRQ_PCIE_INT1 }, },
    122 #ifdef PCIE2_BASE
    123 	{ "bcmpax", PCIE2_BASE, 0x1000, 2, 6, { IRQ_PCIE_INT2 }, },
    124 #endif
    125 #ifdef SDIO_BASE
    126 	{ "sdhc", SDIO_BASE, 0x1000, BCMCCBCF_PORT_DEFAULT, 1, { IRQ_SDIO } },
    127 #endif
    128 	{ "bcmnand", NAND_BASE, 0x1000, BCMCCBCF_PORT_DEFAULT, 8,
    129 	  { IRQ_NAND_RD_MISS, IRQ_NAND_BLK_ERASE_COMP,
    130 	    IRQ_NAND_COPY_BACK_COMP, IRQ_NAND_PGM_PAGE_COMP,
    131 	    IRQ_NAND_RO_CTLR_READY, IRQ_NAND_RB_B,
    132 	    IRQ_NAND_ECC_MIPS_UNCORR, IRQ_NAND_ECC_MIPS_CORR } },
    133 	{ "bcmusb", EHCI_BASE, 0x2000, BCMCCBCF_PORT_DEFAULT, 1, { IRQ_USB2 } },
    134 };
    135 
    136 static int
    137 bcmccb_find(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
    138 {
    139 	struct bcmccb_attach_args * const ccbaa = aux;
    140 
    141 	if (strcmp(cf->cf_name, ccbaa->ccbaa_loc.loc_name) != 0)
    142 		return 0;
    143 
    144 	const bool is_bcmeth_p = strcmp(cf->cf_name, "bcmeth") == 0;
    145 	const bool is_bcmpax_p = !is_bcmeth_p && strcmp(cf->cf_name, "bcmpax") == 0;
    146 	if (cf->cf_loc[BCMCCBCF_PORT] != BCMCCBCF_PORT_DEFAULT
    147 	    && (cf->cf_loc[BCMCCBCF_PORT] != ccbaa->ccbaa_loc.loc_port
    148 		|| (!is_bcmeth_p && !is_bcmpax_p)))
    149 		return 0;
    150 
    151 	ccbaa->ccbaa_loc.loc_mdio = cf->cf_loc[BCMCCBCF_MDIO];
    152 	ccbaa->ccbaa_loc.loc_phy = cf->cf_loc[BCMCCBCF_PHY];
    153 	if (!is_bcmeth_p) {
    154 		const bool is_mdio_default_p = ccbaa->ccbaa_loc.loc_mdio == BCMCCBCF_MDIO_DEFAULT;
    155 		const bool is_phy_default_p = ccbaa->ccbaa_loc.loc_phy == BCMCCBCF_PHY_DEFAULT;
    156 		if (!is_mdio_default_p || !is_phy_default_p)
    157 			return 0;
    158 	}
    159 
    160 	return config_match(parent, cf, ccbaa);
    161 }
    162 
    163 static void
    164 bcmccb_mainbus_attach(device_t parent, device_t self, void *aux)
    165 {
    166 	struct bcmccb_softc * const sc = &bcmccb_sc;
    167 
    168 	sc->sc_dev = self;
    169 	self->dv_private = sc;
    170 
    171 	sc->sc_bst = bcm53xx_ioreg_bst;
    172 
    173 	bus_space_subregion (sc->sc_bst, bcm53xx_ioreg_bsh,
    174 	    CCB_BASE, CCB_SIZE, &sc->sc_bsh);
    175 
    176 	aprint_naive("\n");
    177 	aprint_normal("\n");
    178 
    179 	for (size_t i = 0; i < __arraycount(bcmccb_locators); i++) {
    180 		const struct bcm_locators *loc = &bcmccb_locators[i];
    181 
    182 #ifdef BCM5301X
    183 		if (strcmp(loc->loc_name, "bcmsw") == 0) {
    184 			bcm53xx_srab_init();	// need this for ethernet.
    185 		}
    186 #endif
    187 
    188 		struct bcmccb_attach_args ccbaa = {
    189 			.ccbaa_ccb_bst = sc->sc_bst,
    190 			.ccbaa_ccb_bsh = sc->sc_bsh,
    191 			.ccbaa_dmat = &bcm53xx_dma_tag,
    192 			.ccbaa_loc = *loc,
    193 		};
    194 
    195 		/*
    196 		 * If the device might be in reset, let's try to take it
    197 		 * out of it.  If it fails or is unavailable, skip it.
    198 		 */
    199 		if (!bcm53xx_idm_device_init(loc, sc->sc_bst, sc->sc_bsh))
    200 			continue;
    201 
    202 		cfdata_t cf = config_search_ia(bcmccb_find, self, "bcmccb",
    203 		    &ccbaa);
    204 		if (cf != NULL)
    205 			config_attach(self, cf, &ccbaa, bcmccb_print);
    206 	}
    207 }
    208