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