1 /*- 2 * Copyright (c) 2016 Michal Meloun <mmel@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27 #include <sys/cdefs.h> 28 __FBSDID("$FreeBSD$"); 29 30 #include <sys/param.h> 31 #include <sys/systm.h> 32 #include <sys/bus.h> 33 #include <sys/kernel.h> 34 #include <sys/kobj.h> 35 #include <sys/module.h> 36 #include <sys/malloc.h> 37 #include <sys/rman.h> 38 #include <sys/lock.h> 39 #include <sys/mutex.h> 40 41 #include <machine/bus.h> 42 #include <machine/cpu.h> 43 44 #include <dev/extres/clk/clk_div.h> 45 #include <dev/extres/clk/clk_fixed.h> 46 #include <dev/extres/clk/clk_gate.h> 47 #include <dev/extres/clk/clk_mux.h> 48 #include <dev/extres/hwreset/hwreset.h> 49 #include <dev/ofw/openfirm.h> 50 #include <dev/ofw/ofw_bus.h> 51 #include <dev/ofw/ofw_bus_subr.h> 52 53 #include <gnu/dts/include/dt-bindings/clock/tegra124-car.h> 54 55 #include "clkdev_if.h" 56 #include "hwreset_if.h" 57 #include "tegra124_car.h" 58 59 static struct ofw_compat_data compat_data[] = { 60 {"nvidia,tegra124-car", 1}, 61 {NULL, 0}, 62 }; 63 64 #define PLIST(x) static const char *x[] 65 66 /* Pure multiplexer. */ 67 #define MUX(_id, cname, plists, o, s, w) \ 68 { \ 69 .clkdef.id = _id, \ 70 .clkdef.name = cname, \ 71 .clkdef.parent_names = plists, \ 72 .clkdef.parent_cnt = nitems(plists), \ 73 .clkdef.flags = CLK_NODE_STATIC_STRINGS, \ 74 .offset = o, \ 75 .shift = s, \ 76 .width = w, \ 77 } 78 79 /* Fractional divider (7.1). */ 80 #define DIV7_1(_id, cname, plist, o, s) \ 81 { \ 82 .clkdef.id = _id, \ 83 .clkdef.name = cname, \ 84 .clkdef.parent_names = (const char *[]){plist}, \ 85 .clkdef.parent_cnt = 1, \ 86 .clkdef.flags = CLK_NODE_STATIC_STRINGS, \ 87 .offset = o, \ 88 .i_shift = (s) + 1, \ 89 .i_width = 7, \ 90 .f_shift = s, \ 91 .f_width = 1, \ 92 } 93 94 /* Integer divider. */ 95 #define DIV(_id, cname, plist, o, s, w, f) \ 96 { \ 97 .clkdef.id = _id, \ 98 .clkdef.name = cname, \ 99 .clkdef.parent_names = (const char *[]){plist}, \ 100 .clkdef.parent_cnt = 1, \ 101 .clkdef.flags = CLK_NODE_STATIC_STRINGS, \ 102 .offset = o, \ 103 .i_shift = s, \ 104 .i_width = w, \ 105 .div_flags = f, \ 106 } 107 108 /* Gate in PLL block. */ 109 #define GATE_PLL(_id, cname, plist, o, s) \ 110 { \ 111 .clkdef.id = _id, \ 112 .clkdef.name = cname, \ 113 .clkdef.parent_names = (const char *[]){plist}, \ 114 .clkdef.parent_cnt = 1, \ 115 .clkdef.flags = CLK_NODE_STATIC_STRINGS, \ 116 .offset = o, \ 117 .shift = s, \ 118 .mask = 3, \ 119 .on_value = 3, \ 120 .off_value = 0, \ 121 } 122 123 /* Standard gate. */ 124 #define GATE(_id, cname, plist, o, s) \ 125 { \ 126 .clkdef.id = _id, \ 127 .clkdef.name = cname, \ 128 .clkdef.parent_names = (const char *[]){plist}, \ 129 .clkdef.parent_cnt = 1, \ 130 .clkdef.flags = CLK_NODE_STATIC_STRINGS, \ 131 .offset = o, \ 132 .shift = s, \ 133 .mask = 1, \ 134 .on_value = 1, \ 135 .off_value = 0, \ 136 } 137 138 /* Inverted gate. */ 139 #define GATE_INV(_id, cname, plist, o, s) \ 140 { \ 141 .clkdef.id = _id, \ 142 .clkdef.name = cname, \ 143 .clkdef.parent_names = (const char *[]){plist}, \ 144 .clkdef.parent_cnt = 1, \ 145 .clkdef.flags = CLK_NODE_STATIC_STRINGS, \ 146 .offset = o, \ 147 .shift = s, \ 148 .mask = 1, \ 149 .on_value = 0, \ 150 .off_value = 1, \ 151 } 152 153 /* Fixed rate clock. */ 154 #define FRATE(_id, cname, _freq) \ 155 { \ 156 .clkdef.id = _id, \ 157 .clkdef.name = cname, \ 158 .clkdef.parent_names = NULL, \ 159 .clkdef.parent_cnt = 0, \ 160 .clkdef.flags = CLK_NODE_STATIC_STRINGS, \ 161 .freq = _freq, \ 162 } 163 164 /* Fixed rate multipier/divider. */ 165 #define FACT(_id, cname, pname, _mult, _div) \ 166 { \ 167 .clkdef.id = _id, \ 168 .clkdef.name = cname, \ 169 .clkdef.parent_names = (const char *[]){pname}, \ 170 .clkdef.parent_cnt = 1, \ 171 .clkdef.flags = CLK_NODE_STATIC_STRINGS, \ 172 .mult = _mult, \ 173 .div = _div, \ 174 } 175 176 static uint32_t osc_freqs[16] = { 177 [0] = 13000000, 178 [1] = 16800000, 179 [4] = 19200000, 180 [5] = 38400000, 181 [8] = 12000000, 182 [9] = 48000000, 183 [12] = 260000000, 184 }; 185 186 187 /* Parent lists. */ 188 PLIST(mux_pll_srcs) = {"osc_div_clk", NULL, "pllP_out0", NULL}; /* FIXME */ 189 PLIST(mux_plle_src1) = {"osc_div_clk", "pllP_out0"}; 190 PLIST(mux_plle_src) = {"pllE_src1", "pllREFE_out"}; 191 PLIST(mux_plld_out0_plld2_out0) = {"pllD_out0", "pllD2_out0"}; 192 PLIST(mux_pllmcp_clkm) = {"pllM_out0", "pllC_out0", "pllP_out0", "clk_m", 193 "pllM_UD", "pllC2_out0", "pllC3_out0", "pllC_UD"}; 194 PLIST(mux_xusb_hs) = {"pc_xusb_ss", "pllU_60"}; 195 PLIST(mux_xusb_ss) = {"pc_xusb_ss", "osc_div_clk"}; 196 197 198 /* Clocks ajusted online. */ 199 static struct clk_fixed_def fixed_clk_m = 200 FRATE(0, "clk_m", 12000000); 201 static struct clk_fixed_def fixed_osc_div_clk = 202 FACT(0, "osc_div_clk", "clk_m", 1, 1); 203 204 static struct clk_fixed_def tegra124_fixed_clks[] = { 205 /* Core clocks. */ 206 FRATE(0, "clk_s", 32768), 207 FACT(0, "clk_m_div2", "clk_m", 1, 2), 208 FACT(0, "clk_m_div4", "clk_m", 1, 3), 209 FACT(0, "pllU_60", "pllU_out", 1, 8), 210 FACT(0, "pllU_48", "pllU_out", 1, 10), 211 FACT(0, "pllU_12", "pllU_out", 1, 40), 212 FACT(TEGRA124_CLK_PLL_D_OUT0, "pllD_out0", "pllD_out", 1, 2), 213 FACT(TEGRA124_CLK_PLL_D2_OUT0, "pllD2_out0", "pllD2_out", 1, 1), 214 FACT(0, "pllX_out0", "pllX_out", 1, 2), 215 FACT(0, "pllC_UD", "pllC_out0", 1, 1), 216 FACT(0, "pllM_UD", "pllM_out0", 1, 1), 217 218 /* Audio clocks. */ 219 FRATE(0, "audio0", 10000000), 220 FRATE(0, "audio1", 10000000), 221 FRATE(0, "audio2", 10000000), 222 FRATE(0, "audio3", 10000000), 223 FRATE(0, "audio4", 10000000), 224 FRATE(0, "ext_vimclk", 10000000), 225 }; 226 227 228 static struct clk_mux_def tegra124_mux_clks[] = { 229 /* Core clocks. */ 230 MUX(0, "pllD2_src", mux_pll_srcs, PLLD2_BASE, 25, 2), 231 MUX(0, "pllDP_src", mux_pll_srcs, PLLDP_BASE, 25, 2), 232 MUX(0, "pllC4_src", mux_pll_srcs, PLLC4_BASE, 25, 2), 233 MUX(0, "pllE_src1", mux_plle_src1, PLLE_AUX, 2, 1), 234 MUX(0, "pllE_src", mux_plle_src, PLLE_AUX, 28, 1), 235 236 /* Base peripheral clocks. */ 237 MUX(0, "dsia_mux", mux_plld_out0_plld2_out0, PLLD_BASE, 25, 1), 238 MUX(0, "dsib_mux", mux_plld_out0_plld2_out0, PLLD2_BASE, 25, 1), 239 MUX(0, "emc_mux", mux_pllmcp_clkm, CLK_SOURCE_EMC, 29, 3), 240 241 /* USB. */ 242 MUX(0, "xusb_hs", mux_xusb_hs, CLK_SOURCE_XUSB_SS, 25, 1), 243 MUX(0, "xusb_ss_mux", mux_xusb_ss, CLK_SOURCE_XUSB_SS, 24, 1), 244 245 }; 246 247 248 static struct clk_gate_def tegra124_gate_clks[] = { 249 /* Core clocks. */ 250 GATE_PLL(0, "pllC_out1", "pllC_out1_div", PLLC_OUT, 0), 251 GATE_PLL(0, "pllM_out1", "pllM_out1_div", PLLM_OUT, 0), 252 GATE_PLL(0, "pllU_480", "pllU_out", PLLU_BASE, 22), 253 GATE_PLL(0, "pllP_outX0", "pllP_outX0_div", PLLP_RESHIFT, 0), 254 GATE_PLL(0, "pllP_out1", "pllP_out1_div", PLLP_OUTA, 0), 255 GATE_PLL(0, "pllP_out2", "pllP_out2_div", PLLP_OUTA, 16), 256 GATE_PLL(0, "pllP_out3", "pllP_out3_div", PLLP_OUTB, 0), 257 GATE_PLL(0, "pllP_out4", "pllP_out4_div", PLLP_OUTB, 16), 258 GATE_PLL(0, "pllP_out5", "pllP_out5_div", PLLP_OUTC, 16), 259 GATE_PLL(0, "pllA_out0", "pllA_out1_div", PLLA_OUT, 0), 260 261 /* Base peripheral clocks. */ 262 GATE(TEGRA124_CLK_CML0, "cml0", "pllE_out0", PLLE_AUX, 0), 263 GATE(TEGRA124_CLK_CML1, "cml1", "pllE_out0", PLLE_AUX, 1), 264 GATE_INV(TEGRA124_CLK_HCLK, "hclk", "hclk_div", CLK_SYSTEM_RATE, 7), 265 GATE_INV(TEGRA124_CLK_PCLK, "pclk", "pclk_div", CLK_SYSTEM_RATE, 3), 266 }; 267 268 static struct clk_div_def tegra124_div_clks[] = { 269 /* Core clocks. */ 270 DIV7_1(0, "pllC_out1_div", "pllC_out0", PLLC_OUT, 2), 271 DIV7_1(0, "pllM_out1_div", "pllM_out0", PLLM_OUT, 8), 272 DIV7_1(0, "pllP_outX0_div", "pllP_out0", PLLP_RESHIFT, 2), 273 DIV7_1(0, "pllP_out1_div", "pllP_out0", PLLP_OUTA, 8), 274 DIV7_1(0, "pllP_out2_div", "pllP_out0", PLLP_OUTA, 24), 275 DIV7_1(0, "pllP_out3_div", "pllP_out0", PLLP_OUTB, 8), 276 DIV7_1(0, "pllP_out4_div", "pllP_out0", PLLP_OUTB, 24), 277 DIV7_1(0, "pllP_out5_div", "pllP_out0", PLLP_OUTC, 24), 278 DIV7_1(0, "pllA_out1_div", "pllA_out", PLLA_OUT, 8), 279 280 /* Base peripheral clocks. */ 281 DIV(0, "hclk_div", "sclk", CLK_SYSTEM_RATE, 4, 2, 0), 282 DIV(0, "pclk_div", "hclk", CLK_SYSTEM_RATE, 0, 2, 0), 283 }; 284 285 /* Initial setup table. */ 286 static struct tegra124_init_item clk_init_table[] = { 287 /* clock, partent, frequency, enable */ 288 {"uarta", "pllP_out0", 408000000, 0}, 289 {"uartb", "pllP_out0", 408000000, 0}, 290 {"uartc", "pllP_out0", 408000000, 0}, 291 {"uartd", "pllP_out0", 408000000, 0}, 292 {"pllA_out", NULL, 282240000, 1}, 293 {"pllA_out0", NULL, 11289600, 1}, 294 {"extperiph1", "pllA_out0", 0, 1}, 295 {"i2s0", "pllA_out0", 11289600, 0}, 296 {"i2s1", "pllA_out0", 11289600, 0}, 297 {"i2s2", "pllA_out0", 11289600, 0}, 298 {"i2s3", "pllA_out0", 11289600, 0}, 299 {"i2s4", "pllA_out0", 11289600, 0}, 300 {"vde", "pllP_out0", 0, 0}, 301 {"host1x", "pllP_out0", 136000000, 1}, 302 {"sclk", "pllP_out2", 102000000, 1}, 303 {"dvfs_soc", "pllP_out0", 51000000, 1}, 304 {"dvfs_ref", "pllP_out0", 51000000, 1}, 305 {"pllC_out0", NULL, 600000000, 0}, 306 {"pllC_out1", NULL, 100000000, 0}, 307 {"spi4", "pllP_out0", 12000000, 1}, 308 {"tsec", "pllC3_out0", 0, 0}, 309 {"msenc", "pllC3_out0", 0, 0}, 310 {"pllREFE_out", NULL, 672000000, 0}, 311 {"pc_xusb_ss", "pllU_480", 120000000, 0}, 312 {"xusb_ss", "pc_xusb_ss", 120000000, 0}, 313 {"pc_xusb_fs", "pllU_48", 48000000, 0}, 314 {"xusb_hs", "pllU_60", 60000000, 0}, 315 {"pc_xusb_falcon", "pllREFE_out", 224000000, 0}, 316 {"xusb_core_host", "pllREFE_out", 112000000, 0}, 317 {"sata", "pllP_out0", 102000000, 0}, 318 {"sata_oob", "pllP_out0", 204000000, 0}, 319 {"sata_cold", NULL, 0, 1}, 320 {"emc", NULL, 0, 1}, 321 {"mselect", NULL, 0, 1}, 322 {"csite", NULL, 0, 1}, 323 {"tsensor", "clk_m", 400000, 0}, 324 325 /* tegra124 only*/ 326 {"soc_therm", "pllP_out0", 51000000, 0}, 327 {"cclk_g", NULL, 0, 1}, 328 {"hda", "pllP_out0", 102000000, 0}, 329 {"hda2codec_2x", "pllP_out0", 48000000, 0}, 330 }; 331 332 static void 333 init_divs(struct tegra124_car_softc *sc, struct clk_div_def *clks, int nclks) 334 { 335 int i, rv; 336 337 for (i = 0; i < nclks; i++) { 338 rv = clknode_div_register(sc->clkdom, clks + i); 339 if (rv != 0) 340 panic("clk_div_register failed"); 341 } 342 } 343 344 static void 345 init_gates(struct tegra124_car_softc *sc, struct clk_gate_def *clks, int nclks) 346 { 347 int i, rv; 348 349 350 for (i = 0; i < nclks; i++) { 351 rv = clknode_gate_register(sc->clkdom, clks + i); 352 if (rv != 0) 353 panic("clk_gate_register failed"); 354 } 355 } 356 357 static void 358 init_muxes(struct tegra124_car_softc *sc, struct clk_mux_def *clks, int nclks) 359 { 360 int i, rv; 361 362 363 for (i = 0; i < nclks; i++) { 364 rv = clknode_mux_register(sc->clkdom, clks + i); 365 if (rv != 0) 366 panic("clk_mux_register failed"); 367 } 368 } 369 370 static void 371 init_fixeds(struct tegra124_car_softc *sc, struct clk_fixed_def *clks, 372 int nclks) 373 { 374 int i, rv; 375 uint32_t val; 376 int osc_idx; 377 378 CLKDEV_READ_4(sc->dev, OSC_CTRL, &val); 379 osc_idx = val >> OSC_CTRL_OSC_FREQ_SHIFT; 380 fixed_clk_m.freq = osc_freqs[osc_idx]; 381 if (fixed_clk_m.freq == 0) 382 panic("Undefined input frequency"); 383 rv = clknode_fixed_register(sc->clkdom, &fixed_clk_m); 384 if (rv != 0) panic("clk_fixed_register failed"); 385 386 val = (val >> OSC_CTRL_PLL_REF_DIV_SHIFT) & 3; 387 fixed_osc_div_clk.div = 1 << val; 388 rv = clknode_fixed_register(sc->clkdom, &fixed_osc_div_clk); 389 if (rv != 0) panic("clk_fixed_register failed"); 390 391 for (i = 0; i < nclks; i++) { 392 rv = clknode_fixed_register(sc->clkdom, clks + i); 393 if (rv != 0) 394 panic("clk_fixed_register failed"); 395 } 396 } 397 398 static void 399 postinit_clock(struct tegra124_car_softc *sc) 400 { 401 int i; 402 struct tegra124_init_item *tbl; 403 struct clknode *clknode; 404 int rv; 405 406 for (i = 0; i < nitems(clk_init_table); i++) { 407 tbl = &clk_init_table[i]; 408 409 clknode = clknode_find_by_name(tbl->name); 410 if (clknode == NULL) { 411 device_printf(sc->dev, "Cannot find clock %s\n", 412 tbl->name); 413 continue; 414 } 415 if (tbl->parent != NULL) { 416 rv = clknode_set_parent_by_name(clknode, tbl->parent); 417 if (rv != 0) { 418 device_printf(sc->dev, 419 "Cannot set parent for %s (to %s): %d\n", 420 tbl->name, tbl->parent, rv); 421 continue; 422 } 423 } 424 if (tbl->frequency != 0) { 425 rv = clknode_set_freq(clknode, tbl->frequency, 0 , 9999); 426 if (rv != 0) { 427 device_printf(sc->dev, 428 "Cannot set frequency for %s: %d\n", 429 tbl->name, rv); 430 continue; 431 } 432 } 433 if (tbl->enable!= 0) { 434 rv = clknode_enable(clknode); 435 if (rv != 0) { 436 device_printf(sc->dev, 437 "Cannot enable %s: %d\n", tbl->name, rv); 438 continue; 439 } 440 } 441 } 442 } 443 444 static void 445 register_clocks(device_t dev) 446 { 447 struct tegra124_car_softc *sc; 448 449 sc = device_get_softc(dev); 450 sc->clkdom = clkdom_create(dev); 451 if (sc->clkdom == NULL) 452 panic("clkdom == NULL"); 453 454 tegra124_init_plls(sc); 455 init_fixeds(sc, tegra124_fixed_clks, nitems(tegra124_fixed_clks)); 456 init_muxes(sc, tegra124_mux_clks, nitems(tegra124_mux_clks)); 457 init_divs(sc, tegra124_div_clks, nitems(tegra124_div_clks)); 458 init_gates(sc, tegra124_gate_clks, nitems(tegra124_gate_clks)); 459 tegra124_periph_clock(sc); 460 tegra124_super_mux_clock(sc); 461 clkdom_finit(sc->clkdom); 462 clkdom_xlock(sc->clkdom); 463 postinit_clock(sc); 464 clkdom_unlock(sc->clkdom); 465 if (bootverbose) 466 clkdom_dump(sc->clkdom); 467 } 468 469 static int 470 tegra124_car_clkdev_read_4(device_t dev, bus_addr_t addr, uint32_t *val) 471 { 472 struct tegra124_car_softc *sc; 473 474 sc = device_get_softc(dev); 475 *val = bus_read_4(sc->mem_res, addr); 476 return (0); 477 } 478 479 static int 480 tegra124_car_clkdev_write_4(device_t dev, bus_addr_t addr, uint32_t val) 481 { 482 struct tegra124_car_softc *sc; 483 484 sc = device_get_softc(dev); 485 bus_write_4(sc->mem_res, addr, val); 486 return (0); 487 } 488 489 static int 490 tegra124_car_clkdev_modify_4(device_t dev, bus_addr_t addr, uint32_t clear_mask, 491 uint32_t set_mask) 492 { 493 struct tegra124_car_softc *sc; 494 uint32_t reg; 495 496 sc = device_get_softc(dev); 497 reg = bus_read_4(sc->mem_res, addr); 498 reg &= ~clear_mask; 499 reg |= set_mask; 500 bus_write_4(sc->mem_res, addr, reg); 501 return (0); 502 } 503 504 static void 505 tegra124_car_clkdev_device_lock(device_t dev) 506 { 507 struct tegra124_car_softc *sc; 508 509 sc = device_get_softc(dev); 510 mtx_lock(&sc->mtx); 511 } 512 513 static void 514 tegra124_car_clkdev_device_unlock(device_t dev) 515 { 516 struct tegra124_car_softc *sc; 517 518 sc = device_get_softc(dev); 519 mtx_unlock(&sc->mtx); 520 } 521 522 static int 523 tegra124_car_detach(device_t dev) 524 { 525 526 device_printf(dev, "Error: Clock driver cannot be detached\n"); 527 return (EBUSY); 528 } 529 530 static int 531 tegra124_car_probe(device_t dev) 532 { 533 534 if (!ofw_bus_status_okay(dev)) 535 return (ENXIO); 536 537 if (ofw_bus_search_compatible(dev, compat_data)->ocd_data != 0) { 538 device_set_desc(dev, "Tegra Clock Driver"); 539 return (BUS_PROBE_DEFAULT); 540 } 541 542 return (ENXIO); 543 } 544 545 static int 546 tegra124_car_attach(device_t dev) 547 { 548 struct tegra124_car_softc *sc = device_get_softc(dev); 549 int rid, rv; 550 551 sc->dev = dev; 552 553 mtx_init(&sc->mtx, device_get_nameunit(dev), NULL, MTX_DEF); 554 sc->type = ofw_bus_search_compatible(dev, compat_data)->ocd_data; 555 556 /* Resource setup. */ 557 rid = 0; 558 sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, 559 RF_ACTIVE); 560 if (!sc->mem_res) { 561 device_printf(dev, "cannot allocate memory resource\n"); 562 rv = ENXIO; 563 goto fail; 564 } 565 566 register_clocks(dev); 567 hwreset_register_ofw_provider(dev); 568 return (0); 569 570 fail: 571 if (sc->mem_res) 572 bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->mem_res); 573 574 return (rv); 575 } 576 577 static int 578 tegra124_car_hwreset_assert(device_t dev, intptr_t id, bool value) 579 { 580 struct tegra124_car_softc *sc = device_get_softc(dev); 581 582 return (tegra124_hwreset_by_idx(sc, id, value)); 583 } 584 585 static device_method_t tegra124_car_methods[] = { 586 /* Device interface */ 587 DEVMETHOD(device_probe, tegra124_car_probe), 588 DEVMETHOD(device_attach, tegra124_car_attach), 589 DEVMETHOD(device_detach, tegra124_car_detach), 590 591 /* Clkdev interface*/ 592 DEVMETHOD(clkdev_read_4, tegra124_car_clkdev_read_4), 593 DEVMETHOD(clkdev_write_4, tegra124_car_clkdev_write_4), 594 DEVMETHOD(clkdev_modify_4, tegra124_car_clkdev_modify_4), 595 DEVMETHOD(clkdev_device_lock, tegra124_car_clkdev_device_lock), 596 DEVMETHOD(clkdev_device_unlock, tegra124_car_clkdev_device_unlock), 597 598 /* Reset interface */ 599 DEVMETHOD(hwreset_assert, tegra124_car_hwreset_assert), 600 601 DEVMETHOD_END 602 }; 603 604 static devclass_t tegra124_car_devclass; 605 static DEFINE_CLASS_0(car, tegra124_car_driver, tegra124_car_methods, 606 sizeof(struct tegra124_car_softc)); 607 EARLY_DRIVER_MODULE(tegra124_car, simplebus, tegra124_car_driver, 608 tegra124_car_devclass, NULL, NULL, BUS_PASS_TIMER); 609