| 434 | } |
| 435 | |
| 436 | static int |
| 437 | aw_mmc_attach(device_t dev) |
| 438 | { |
| 439 | struct aw_mmc_softc *sc; |
| 440 | struct sysctl_ctx_list *ctx; |
| 441 | struct sysctl_oid_list *tree; |
| 442 | int error; |
| 443 | |
| 444 | sc = device_get_softc(dev); |
| 445 | sc->aw_dev = dev; |
| 446 | |
| 447 | sc->aw_mmc_conf = (struct aw_mmc_conf *)ofw_bus_search_compatible(dev, compat_data)->ocd_data; |
| 448 | |
| 449 | #ifndef MMCCAM |
| 450 | sc->aw_req = NULL; |
| 451 | #endif |
| 452 | if (bus_alloc_resources(dev, aw_mmc_res_spec, sc->aw_res) != 0) { |
| 453 | device_printf(dev, "cannot allocate device resources\n"); |
| 454 | return (ENXIO); |
| 455 | } |
| 456 | if (bus_setup_intr(dev, sc->aw_res[AW_MMC_IRQRES], |
| 457 | INTR_TYPE_NET | INTR_MPSAFE, NULL, aw_mmc_intr, sc, |
| 458 | &sc->aw_intrhand)) { |
| 459 | bus_release_resources(dev, aw_mmc_res_spec, sc->aw_res); |
| 460 | device_printf(dev, "cannot setup interrupt handler\n"); |
| 461 | return (ENXIO); |
| 462 | } |
| 463 | mtx_init(&sc->aw_mtx, device_get_nameunit(sc->aw_dev), "aw_mmc", |
| 464 | MTX_DEF); |
| 465 | callout_init_mtx(&sc->aw_timeoutc, &sc->aw_mtx, 0); |
| 466 | |
| 467 | /* De-assert reset */ |
| 468 | if (hwreset_get_by_ofw_name(dev, 0, "ahb", &sc->aw_rst_ahb) == 0) { |
| 469 | error = hwreset_deassert(sc->aw_rst_ahb); |
| 470 | if (error != 0) { |
| 471 | device_printf(dev, "cannot de-assert reset\n"); |
| 472 | goto fail; |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | /* Activate the module clock. */ |
| 477 | error = clk_get_by_ofw_name(dev, 0, "ahb", &sc->aw_clk_ahb); |
| 478 | if (error != 0) { |
| 479 | device_printf(dev, "cannot get ahb clock\n"); |
| 480 | goto fail; |
| 481 | } |
| 482 | error = clk_enable(sc->aw_clk_ahb); |
| 483 | if (error != 0) { |
| 484 | device_printf(dev, "cannot enable ahb clock\n"); |
| 485 | goto fail; |
| 486 | } |
| 487 | error = clk_get_by_ofw_name(dev, 0, "mmc", &sc->aw_clk_mmc); |
| 488 | if (error != 0) { |
| 489 | device_printf(dev, "cannot get mmc clock\n"); |
| 490 | goto fail; |
| 491 | } |
| 492 | error = clk_set_freq(sc->aw_clk_mmc, CARD_ID_FREQUENCY, |
| 493 | CLK_SET_ROUND_DOWN); |
nothing calls this directly
no test coverage detected