Lines Matching full:sc
183 static void aw_mmc_teardown_dma(struct aw_mmc_softc *sc);
222 struct aw_mmc_softc *sc; in aw_mmc_get_tran_settings() local
224 sc = device_get_softc(dev); in aw_mmc_get_tran_settings()
226 cts->host_ocr = sc->aw_host.host_ocr; in aw_mmc_get_tran_settings()
227 cts->host_f_min = sc->aw_host.f_min; in aw_mmc_get_tran_settings()
228 cts->host_f_max = sc->aw_host.f_max; in aw_mmc_get_tran_settings()
229 cts->host_caps = sc->aw_host.caps; in aw_mmc_get_tran_settings()
230 cts->host_max_data = (sc->aw_mmc_conf->dma_xferlen * in aw_mmc_get_tran_settings()
232 memcpy(&cts->ios, &sc->aw_host.ios, sizeof(struct mmc_ios)); in aw_mmc_get_tran_settings()
240 struct aw_mmc_softc *sc; in aw_mmc_set_tran_settings() local
244 sc = device_get_softc(dev); in aw_mmc_set_tran_settings()
245 ios = &sc->aw_host.ios; in aw_mmc_set_tran_settings()
252 device_printf(sc->aw_dev, "Clock => %d\n", ios->clock); in aw_mmc_set_tran_settings()
257 device_printf(sc->aw_dev, "VDD => %d\n", ios->vdd); in aw_mmc_set_tran_settings()
262 device_printf(sc->aw_dev, "CS => %d\n", ios->chip_select); in aw_mmc_set_tran_settings()
267 device_printf(sc->aw_dev, "Bus width => %d\n", ios->bus_width); in aw_mmc_set_tran_settings()
272 device_printf(sc->aw_dev, "Power mode => %d\n", ios->power_mode); in aw_mmc_set_tran_settings()
277 device_printf(sc->aw_dev, "Timing => %d\n", ios->timing); in aw_mmc_set_tran_settings()
282 device_printf(sc->aw_dev, "Bus mode => %d\n", ios->bus_mode); in aw_mmc_set_tran_settings()
285 return (aw_mmc_update_ios(sc->aw_dev, NULL)); in aw_mmc_set_tran_settings()
291 struct aw_mmc_softc *sc; in aw_mmc_cam_request() local
294 sc = device_get_softc(dev); in aw_mmc_cam_request()
297 AW_MMC_LOCK(sc); in aw_mmc_cam_request()
300 device_printf(sc->aw_dev, "CMD%u arg %#x flags %#x dlen %u dflags %#x\n", in aw_mmc_cam_request()
310 if (sc->ccb != NULL) { in aw_mmc_cam_request()
311 device_printf(sc->aw_dev, "Controller still has an active command\n"); in aw_mmc_cam_request()
314 sc->ccb = ccb; in aw_mmc_cam_request()
316 AW_MMC_UNLOCK(sc); in aw_mmc_cam_request()
317 aw_mmc_request(sc->aw_dev, NULL, NULL); in aw_mmc_cam_request()
325 struct aw_mmc_softc *sc; in aw_mmc_cam_poll() local
327 sc = device_get_softc(dev); in aw_mmc_cam_poll()
328 aw_mmc_intr(sc); in aw_mmc_cam_poll()
335 struct aw_mmc_softc *sc; in aw_mmc_helper_cd_handler() local
337 sc = device_get_softc(dev); in aw_mmc_helper_cd_handler()
339 mmc_cam_sim_discover(&sc->mmc_sim); in aw_mmc_helper_cd_handler()
343 if (sc->child == NULL) { in aw_mmc_helper_cd_handler()
345 device_printf(sc->aw_dev, "Card inserted\n"); in aw_mmc_helper_cd_handler()
347 sc->child = device_add_child(sc->aw_dev, "mmc", DEVICE_UNIT_ANY); in aw_mmc_helper_cd_handler()
348 if (sc->child) { in aw_mmc_helper_cd_handler()
349 device_set_ivars(sc->child, sc); in aw_mmc_helper_cd_handler()
350 (void)device_probe_and_attach(sc->child); in aw_mmc_helper_cd_handler()
355 if (sc->child != NULL) { in aw_mmc_helper_cd_handler()
357 device_printf(sc->aw_dev, "Card removed\n"); in aw_mmc_helper_cd_handler()
359 device_delete_child(sc->aw_dev, sc->child); in aw_mmc_helper_cd_handler()
360 sc->child = NULL; in aw_mmc_helper_cd_handler()
384 struct aw_mmc_softc *sc; in aw_mmc_attach() local
389 sc = device_get_softc(dev); in aw_mmc_attach()
390 sc->aw_dev = dev; in aw_mmc_attach()
392 sc->aw_mmc_conf = (struct aw_mmc_conf *)ofw_bus_search_compatible(dev, compat_data)->ocd_data; in aw_mmc_attach()
395 sc->aw_req = NULL; in aw_mmc_attach()
397 if (bus_alloc_resources(dev, aw_mmc_res_spec, sc->aw_res) != 0) { in aw_mmc_attach()
401 if (bus_setup_intr(dev, sc->aw_res[AW_MMC_IRQRES], in aw_mmc_attach()
402 INTR_TYPE_NET | INTR_MPSAFE, NULL, aw_mmc_intr, sc, in aw_mmc_attach()
403 &sc->aw_intrhand)) { in aw_mmc_attach()
404 bus_release_resources(dev, aw_mmc_res_spec, sc->aw_res); in aw_mmc_attach()
408 mtx_init(&sc->aw_mtx, device_get_nameunit(sc->aw_dev), "aw_mmc", in aw_mmc_attach()
410 callout_init_mtx(&sc->aw_timeoutc, &sc->aw_mtx, 0); in aw_mmc_attach()
413 if (hwreset_get_by_ofw_name(dev, 0, "ahb", &sc->aw_rst_ahb) == 0) { in aw_mmc_attach()
414 error = hwreset_deassert(sc->aw_rst_ahb); in aw_mmc_attach()
422 error = clk_get_by_ofw_name(dev, 0, "ahb", &sc->aw_clk_ahb); in aw_mmc_attach()
427 error = clk_enable(sc->aw_clk_ahb); in aw_mmc_attach()
432 error = clk_get_by_ofw_name(dev, 0, "mmc", &sc->aw_clk_mmc); in aw_mmc_attach()
437 error = clk_set_freq(sc->aw_clk_mmc, CARD_ID_FREQUENCY, in aw_mmc_attach()
443 error = clk_enable(sc->aw_clk_mmc); in aw_mmc_attach()
449 sc->aw_timeout = 10; in aw_mmc_attach()
453 &sc->aw_timeout, 0, "Request timeout in seconds"); in aw_mmc_attach()
456 if (aw_mmc_reset(sc) != 0) { in aw_mmc_attach()
461 if (aw_mmc_setup_dma(sc) != 0) { in aw_mmc_attach()
462 device_printf(sc->aw_dev, "Couldn't setup DMA!\n"); in aw_mmc_attach()
467 sc->aw_host.f_min = 400000; in aw_mmc_attach()
468 sc->aw_host.f_max = 52000000; in aw_mmc_attach()
469 sc->aw_host.host_ocr = MMC_OCR_320_330 | MMC_OCR_330_340; in aw_mmc_attach()
470 sc->aw_host.caps |= MMC_CAP_HSPEED | MMC_CAP_SIGNALING_330; in aw_mmc_attach()
471 mmc_fdt_parse(dev, 0, &sc->mmc_helper, &sc->aw_host); in aw_mmc_attach()
472 mmc_fdt_gpio_setup(dev, 0, &sc->mmc_helper, aw_mmc_helper_cd_handler); in aw_mmc_attach()
475 sc->ccb = NULL; in aw_mmc_attach()
477 if (mmc_cam_sim_alloc(dev, "aw_mmc", &sc->mmc_sim) != 0) { in aw_mmc_attach()
486 callout_drain(&sc->aw_timeoutc); in aw_mmc_attach()
487 mtx_destroy(&sc->aw_mtx); in aw_mmc_attach()
488 bus_teardown_intr(dev, sc->aw_res[AW_MMC_IRQRES], sc->aw_intrhand); in aw_mmc_attach()
489 bus_release_resources(dev, aw_mmc_res_spec, sc->aw_res); in aw_mmc_attach()
497 struct aw_mmc_softc *sc; in aw_mmc_detach() local
499 sc = device_get_softc(dev); in aw_mmc_detach()
501 clk_disable(sc->aw_clk_mmc); in aw_mmc_detach()
502 clk_disable(sc->aw_clk_ahb); in aw_mmc_detach()
503 hwreset_assert(sc->aw_rst_ahb); in aw_mmc_detach()
505 mmc_fdt_gpio_teardown(&sc->mmc_helper); in aw_mmc_detach()
507 callout_drain(&sc->aw_timeoutc); in aw_mmc_detach()
509 device_delete_children(sc->aw_dev); in aw_mmc_detach()
511 aw_mmc_teardown_dma(sc); in aw_mmc_detach()
513 mtx_destroy(&sc->aw_mtx); in aw_mmc_detach()
515 bus_teardown_intr(dev, sc->aw_res[AW_MMC_IRQRES], sc->aw_intrhand); in aw_mmc_detach()
516 bus_release_resources(dev, aw_mmc_res_spec, sc->aw_res); in aw_mmc_detach()
519 mmc_cam_sim_free(&sc->mmc_sim); in aw_mmc_detach()
528 struct aw_mmc_softc *sc; in aw_dma_desc_cb() local
530 sc = (struct aw_mmc_softc *)arg; in aw_dma_desc_cb()
532 sc->aw_dma_map_err = err; in aw_dma_desc_cb()
535 sc->aw_dma_desc_phys = segs[0].ds_addr; in aw_dma_desc_cb()
539 aw_mmc_setup_dma(struct aw_mmc_softc *sc) in aw_mmc_setup_dma() argument
545 bus_get_dma_tag(sc->aw_dev), /* parent */ in aw_mmc_setup_dma()
554 &sc->aw_dma_tag); in aw_mmc_setup_dma()
558 error = bus_dmamem_alloc(sc->aw_dma_tag, &sc->aw_dma_desc, in aw_mmc_setup_dma()
560 &sc->aw_dma_map); in aw_mmc_setup_dma()
564 error = bus_dmamap_load(sc->aw_dma_tag, in aw_mmc_setup_dma()
565 sc->aw_dma_map, in aw_mmc_setup_dma()
566 sc->aw_dma_desc, AW_MMC_DMA_DESC_SIZE, in aw_mmc_setup_dma()
567 aw_dma_desc_cb, sc, 0); in aw_mmc_setup_dma()
570 if (sc->aw_dma_map_err) in aw_mmc_setup_dma()
571 return (sc->aw_dma_map_err); in aw_mmc_setup_dma()
575 bus_get_dma_tag(sc->aw_dev), /* parent */ in aw_mmc_setup_dma()
580 sc->aw_mmc_conf->dma_xferlen * in aw_mmc_setup_dma()
582 sc->aw_mmc_conf->dma_xferlen, /* maxsegsize */ in aw_mmc_setup_dma()
585 &sc->aw_dma_buf_tag); in aw_mmc_setup_dma()
588 error = bus_dmamap_create(sc->aw_dma_buf_tag, 0, in aw_mmc_setup_dma()
589 &sc->aw_dma_buf_map); in aw_mmc_setup_dma()
597 aw_mmc_teardown_dma(struct aw_mmc_softc *sc) in aw_mmc_teardown_dma() argument
600 bus_dmamap_unload(sc->aw_dma_tag, sc->aw_dma_map); in aw_mmc_teardown_dma()
601 bus_dmamem_free(sc->aw_dma_tag, sc->aw_dma_desc, sc->aw_dma_map); in aw_mmc_teardown_dma()
602 if (bus_dma_tag_destroy(sc->aw_dma_tag) != 0) in aw_mmc_teardown_dma()
603 device_printf(sc->aw_dev, "Cannot destroy the dma tag\n"); in aw_mmc_teardown_dma()
605 bus_dmamap_unload(sc->aw_dma_buf_tag, sc->aw_dma_buf_map); in aw_mmc_teardown_dma()
606 bus_dmamap_destroy(sc->aw_dma_buf_tag, sc->aw_dma_buf_map); in aw_mmc_teardown_dma()
607 if (bus_dma_tag_destroy(sc->aw_dma_buf_tag) != 0) in aw_mmc_teardown_dma()
608 device_printf(sc->aw_dev, "Cannot destroy the dma buf tag\n"); in aw_mmc_teardown_dma()
616 struct aw_mmc_softc *sc; in aw_dma_cb() local
618 sc = (struct aw_mmc_softc *)arg; in aw_dma_cb()
619 sc->aw_dma_map_err = err; in aw_dma_cb()
624 dma_desc = sc->aw_dma_desc; in aw_dma_cb()
626 if ((segs[i].ds_len == sc->aw_mmc_conf->dma_xferlen) && in aw_dma_cb()
627 !sc->aw_mmc_conf->zero_is_skip) in aw_dma_cb()
632 sc->aw_mmc_conf->dma_desc_shift; in aw_dma_cb()
635 dma_desc[i].next = (sc->aw_dma_desc_phys + in aw_dma_cb()
637 sc->aw_mmc_conf->dma_desc_shift; in aw_dma_cb()
648 aw_mmc_prepare_dma(struct aw_mmc_softc *sc) in aw_mmc_prepare_dma() argument
656 cmd = &sc->ccb->mmcio.cmd; in aw_mmc_prepare_dma()
658 cmd = sc->aw_req->cmd; in aw_mmc_prepare_dma()
660 if (cmd->data->len > (sc->aw_mmc_conf->dma_xferlen * AW_MMC_DMA_SEGS)) in aw_mmc_prepare_dma()
662 error = bus_dmamap_load(sc->aw_dma_buf_tag, sc->aw_dma_buf_map, in aw_mmc_prepare_dma()
663 cmd->data->data, cmd->data->len, aw_dma_cb, sc, 0); in aw_mmc_prepare_dma()
666 if (sc->aw_dma_map_err) in aw_mmc_prepare_dma()
667 return (sc->aw_dma_map_err); in aw_mmc_prepare_dma()
673 bus_dmamap_sync(sc->aw_dma_buf_tag, sc->aw_dma_buf_map, sync_op); in aw_mmc_prepare_dma()
674 bus_dmamap_sync(sc->aw_dma_tag, sc->aw_dma_map, BUS_DMASYNC_PREWRITE); in aw_mmc_prepare_dma()
677 val = AW_MMC_READ_4(sc, AW_MMC_GCTL); in aw_mmc_prepare_dma()
680 AW_MMC_WRITE_4(sc, AW_MMC_GCTL, val); in aw_mmc_prepare_dma()
684 AW_MMC_WRITE_4(sc, AW_MMC_GCTL, val); in aw_mmc_prepare_dma()
686 AW_MMC_WRITE_4(sc, AW_MMC_DMAC, AW_MMC_DMAC_IDMAC_SOFT_RST); in aw_mmc_prepare_dma()
687 AW_MMC_WRITE_4(sc, AW_MMC_DMAC, in aw_mmc_prepare_dma()
691 val = AW_MMC_READ_4(sc, AW_MMC_IDIE); in aw_mmc_prepare_dma()
696 AW_MMC_WRITE_4(sc, AW_MMC_IDIE, val); in aw_mmc_prepare_dma()
699 AW_MMC_WRITE_4(sc, AW_MMC_DLBA, sc->aw_dma_desc_phys >> in aw_mmc_prepare_dma()
700 sc->aw_mmc_conf->dma_desc_shift); in aw_mmc_prepare_dma()
703 AW_MMC_WRITE_4(sc, AW_MMC_FWLR, AW_MMC_DMA_FTRGLEVEL); in aw_mmc_prepare_dma()
709 aw_mmc_reset(struct aw_mmc_softc *sc) in aw_mmc_reset() argument
714 reg = AW_MMC_READ_4(sc, AW_MMC_GCTL); in aw_mmc_reset()
716 AW_MMC_WRITE_4(sc, AW_MMC_GCTL, reg); in aw_mmc_reset()
719 if ((AW_MMC_READ_4(sc, AW_MMC_GCTL) & AW_MMC_GCTL_RESET) == 0) in aw_mmc_reset()
730 aw_mmc_init(struct aw_mmc_softc *sc) in aw_mmc_init() argument
735 ret = aw_mmc_reset(sc); in aw_mmc_init()
740 AW_MMC_WRITE_4(sc, AW_MMC_TMOR, in aw_mmc_init()
745 AW_MMC_WRITE_4(sc, AW_MMC_IMKR, 0); in aw_mmc_init()
748 AW_MMC_WRITE_4(sc, AW_MMC_RISR, 0xffffffff); in aw_mmc_init()
751 AW_MMC_WRITE_4(sc, AW_MMC_DBGC, 0xdeb); in aw_mmc_init()
754 AW_MMC_WRITE_4(sc, AW_MMC_FUNS, 0xceaa0000); in aw_mmc_init()
756 AW_MMC_WRITE_4(sc, AW_MMC_IDST, 0xffffffff); in aw_mmc_init()
759 reg = AW_MMC_READ_4(sc, AW_MMC_GCTL); in aw_mmc_init()
763 AW_MMC_WRITE_4(sc, AW_MMC_GCTL, reg); in aw_mmc_init()
769 aw_mmc_req_done(struct aw_mmc_softc *sc) in aw_mmc_req_done() argument
781 ccb = sc->ccb; in aw_mmc_req_done()
784 cmd = sc->aw_req->cmd; in aw_mmc_req_done()
787 device_printf(sc->aw_dev, "%s: cmd %d err %d\n", __func__, cmd->opcode, cmd->error); in aw_mmc_req_done()
792 val = AW_MMC_READ_4(sc, AW_MMC_GCTL); in aw_mmc_req_done()
793 AW_MMC_WRITE_4(sc, AW_MMC_GCTL, val | mask); in aw_mmc_req_done()
797 if ((AW_MMC_READ_4(sc, AW_MMC_GCTL) & in aw_mmc_req_done()
803 device_printf(sc->aw_dev, in aw_mmc_req_done()
805 aw_mmc_update_clock(sc, 1); in aw_mmc_req_done()
809 callout_stop(&sc->aw_timeoutc); in aw_mmc_req_done()
810 sc->aw_intr = 0; in aw_mmc_req_done()
811 sc->aw_resid = 0; in aw_mmc_req_done()
812 sc->aw_dma_map_err = 0; in aw_mmc_req_done()
813 sc->aw_intr_wait = 0; in aw_mmc_req_done()
815 sc->ccb = NULL; in aw_mmc_req_done()
820 req = sc->aw_req; in aw_mmc_req_done()
821 sc->aw_req = NULL; in aw_mmc_req_done()
827 aw_mmc_req_ok(struct aw_mmc_softc *sc) in aw_mmc_req_ok() argument
835 status = AW_MMC_READ_4(sc, AW_MMC_STAR); in aw_mmc_req_ok()
841 cmd = &sc->ccb->mmcio.cmd; in aw_mmc_req_ok()
843 cmd = sc->aw_req->cmd; in aw_mmc_req_ok()
847 aw_mmc_req_done(sc); in aw_mmc_req_ok()
852 cmd->resp[0] = AW_MMC_READ_4(sc, AW_MMC_RESP3); in aw_mmc_req_ok()
853 cmd->resp[1] = AW_MMC_READ_4(sc, AW_MMC_RESP2); in aw_mmc_req_ok()
854 cmd->resp[2] = AW_MMC_READ_4(sc, AW_MMC_RESP1); in aw_mmc_req_ok()
855 cmd->resp[3] = AW_MMC_READ_4(sc, AW_MMC_RESP0); in aw_mmc_req_ok()
857 cmd->resp[0] = AW_MMC_READ_4(sc, AW_MMC_RESP0); in aw_mmc_req_ok()
860 if (cmd->data != NULL && (sc->aw_resid << 2) < cmd->data->len) in aw_mmc_req_ok()
862 aw_mmc_req_done(sc); in aw_mmc_req_ok()
866 set_mmc_error(struct aw_mmc_softc *sc, int error_code) in set_mmc_error() argument
869 sc->ccb->mmcio.cmd.error = error_code; in set_mmc_error()
871 sc->aw_req->cmd->error = error_code; in set_mmc_error()
878 struct aw_mmc_softc *sc; local
880 sc = (struct aw_mmc_softc *)arg;
882 if (sc->ccb != NULL) {
884 if (sc->aw_req != NULL) {
886 device_printf(sc->aw_dev, "controller timeout\n");
887 set_mmc_error(sc, MMC_ERR_TIMEOUT);
888 aw_mmc_req_done(sc);
890 device_printf(sc->aw_dev,
920 struct aw_mmc_softc *sc; local
924 sc = (struct aw_mmc_softc *)arg;
925 AW_MMC_LOCK(sc);
926 rint = AW_MMC_READ_4(sc, AW_MMC_RISR);
927 idst = AW_MMC_READ_4(sc, AW_MMC_IDST);
928 imask = AW_MMC_READ_4(sc, AW_MMC_IMKR);
930 AW_MMC_UNLOCK(sc);
934 device_printf(sc->aw_dev, "idst: %#x, imask: %#x, rint: %#x\n",
938 if (sc->ccb == NULL) {
940 if (sc->aw_req == NULL) {
942 device_printf(sc->aw_dev,
950 device_printf(sc->aw_dev, "error rint: 0x%08X\n", rint);
954 set_mmc_error(sc, MMC_ERR_TIMEOUT);
956 set_mmc_error(sc, MMC_ERR_FAILED);
957 aw_mmc_req_done(sc);
962 device_printf(sc->aw_dev, "error idst: 0x%08x\n", idst);
963 set_mmc_error(sc, MMC_ERR_FAILED);
964 aw_mmc_req_done(sc);
968 sc->aw_intr |= rint;
970 data = sc->ccb->mmcio.cmd.data;
972 data = sc->aw_req->cmd->data;
979 bus_dmamap_sync(sc->aw_dma_buf_tag, sc->aw_dma_buf_map,
981 bus_dmamap_sync(sc->aw_dma_tag, sc->aw_dma_map,
983 bus_dmamap_unload(sc->aw_dma_buf_tag, sc->aw_dma_buf_map);
984 sc->aw_resid = data->len >> 2;
986 if ((sc->aw_intr & sc->aw_intr_wait) == sc->aw_intr_wait)
987 aw_mmc_req_ok(sc);
990 AW_MMC_WRITE_4(sc, AW_MMC_IDST, idst);
991 AW_MMC_WRITE_4(sc, AW_MMC_RISR, rint);
992 AW_MMC_UNLOCK(sc);
999 struct aw_mmc_softc *sc; local
1004 sc = device_get_softc(bus);
1006 AW_MMC_LOCK(sc);
1010 * For MMCCAM, sc->ccb has been NULL-checked and populated
1013 cmd = &sc->ccb->mmcio.cmd;
1015 if (sc->aw_req) {
1016 AW_MMC_UNLOCK(sc);
1019 sc->aw_req = req;
1023 device_printf(sc->aw_dev, "CMD%u arg %#x flags %#x dlen %u dflags %#x\n",
1031 sc->aw_intr_wait = 0;
1032 sc->aw_intr = 0;
1033 sc->aw_resid = 0;
1052 sc->aw_intr_wait |= AW_MMC_INT_AUTO_STOP_DONE;
1054 sc->aw_intr_wait |= AW_MMC_INT_DATA_OVER;
1061 AW_MMC_WRITE_4(sc, AW_MMC_BKSR, cmd->data->block_size);
1062 AW_MMC_WRITE_4(sc, AW_MMC_BYCR, cmd->data->len);
1067 AW_MMC_WRITE_4(sc, AW_MMC_BKSR, blksz);
1068 AW_MMC_WRITE_4(sc, AW_MMC_BYCR, cmd->data->len);
1075 AW_MMC_WRITE_4(sc, AW_MMC_IMKR, imask);
1076 AW_MMC_WRITE_4(sc, AW_MMC_RISR, 0xffffffff);
1079 AW_MMC_WRITE_4(sc, AW_MMC_A12A,
1083 AW_MMC_WRITE_4(sc, AW_MMC_CAGR, cmd->arg);
1090 AW_MMC_WRITE_4(sc, AW_MMC_CMDR, cmdreg | cmd->opcode);
1092 err = aw_mmc_prepare_dma(sc);
1094 device_printf(sc->aw_dev, "prepare_dma failed: %d\n", err);
1096 AW_MMC_WRITE_4(sc, AW_MMC_CMDR, cmdreg | cmd->opcode);
1100 callout_reset(&sc->aw_timeoutc, sc->aw_timeout * hz,
1101 aw_mmc_timeout, sc);
1103 AW_MMC_UNLOCK(sc);
1112 struct aw_mmc_softc *sc; local
1114 sc = device_get_softc(bus);
1119 *(int *)result = sc->aw_host.ios.bus_mode;
1122 *(int *)result = sc->aw_host.ios.bus_width;
1125 *(int *)result = sc->aw_host.ios.chip_select;
1128 *(int *)result = sc->aw_host.ios.clock;
1131 *(int *)result = sc->aw_host.f_min;
1134 *(int *)result = sc->aw_host.f_max;
1137 *(int *)result = sc->aw_host.host_ocr;
1140 *(int *)result = sc->aw_host.mode;
1143 *(int *)result = sc->aw_host.ocr;
1146 *(int *)result = sc->aw_host.ios.power_mode;
1149 *(int *)result = sc->aw_host.ios.vdd;
1152 *(int *)result = sc->aw_host.ios.vccq;
1155 *(int *)result = sc->aw_host.caps;
1158 *(int *)result = sc->aw_host.ios.timing;
1161 *(int *)result = (sc->aw_mmc_conf->dma_xferlen *
1176 struct aw_mmc_softc *sc; local
1178 sc = device_get_softc(bus);
1183 sc->aw_host.ios.bus_mode = value;
1186 sc->aw_host.ios.bus_width = value;
1189 sc->aw_host.ios.chip_select = value;
1192 sc->aw_host.ios.clock = value;
1195 sc->aw_host.mode = value;
1198 sc->aw_host.ocr = value;
1201 sc->aw_host.ios.power_mode = value;
1204 sc->aw_host.ios.vdd = value;
1207 sc->aw_host.ios.vccq = value;
1210 sc->aw_host.ios.timing = value;
1225 aw_mmc_update_clock(struct aw_mmc_softc *sc, uint32_t clkon) argument
1230 reg = AW_MMC_READ_4(sc, AW_MMC_CKCR);
1236 if (sc->aw_mmc_conf->mask_data0)
1239 AW_MMC_WRITE_4(sc, AW_MMC_CKCR, reg);
1243 AW_MMC_WRITE_4(sc, AW_MMC_CMDR, reg);
1247 reg = AW_MMC_READ_4(sc, AW_MMC_CMDR);
1250 AW_MMC_WRITE_4(sc, AW_MMC_RISR, 0xffffffff);
1253 device_printf(sc->aw_dev, "timeout updating clock\n");
1257 if (sc->aw_mmc_conf->mask_data0) {
1258 reg = AW_MMC_READ_4(sc, AW_MMC_CKCR);
1260 AW_MMC_WRITE_4(sc, AW_MMC_CKCR, reg);
1270 struct aw_mmc_softc *sc; local
1273 sc = device_get_softc(bus);
1275 if (sc->mmc_helper.vqmmc_supply == NULL)
1278 switch (sc->aw_host.ios.vccq) {
1289 err = regulator_set_voltage(sc->mmc_helper.vqmmc_supply, uvolt, uvolt);
1291 device_printf(sc->aw_dev,
1306 struct aw_mmc_softc *sc; local
1313 sc = device_get_softc(bus);
1315 ios = &sc->aw_host.ios;
1320 AW_MMC_WRITE_4(sc, AW_MMC_BWDR, AW_MMC_BWDR1);
1323 AW_MMC_WRITE_4(sc, AW_MMC_BWDR, AW_MMC_BWDR4);
1326 AW_MMC_WRITE_4(sc, AW_MMC_BWDR, AW_MMC_BWDR8);
1335 device_printf(sc->aw_dev, "Powering down sd/mmc\n");
1337 if (sc->mmc_helper.vmmc_supply) {
1338 rv = regulator_status(sc->mmc_helper.vmmc_supply, ®_status);
1340 regulator_disable(sc->mmc_helper.vmmc_supply);
1342 if (sc->mmc_helper.vqmmc_supply) {
1343 rv = regulator_status(sc->mmc_helper.vqmmc_supply, ®_status);
1345 regulator_disable(sc->mmc_helper.vqmmc_supply);
1348 if (sc->mmc_helper.mmc_pwrseq)
1349 MMC_PWRSEQ_SET_POWER(sc->mmc_helper.mmc_pwrseq, false);
1351 aw_mmc_reset(sc);
1355 device_printf(sc->aw_dev, "Powering up sd/mmc\n");
1357 if (sc->mmc_helper.vmmc_supply) {
1358 rv = regulator_status(sc->mmc_helper.vmmc_supply, ®_status);
1360 regulator_enable(sc->mmc_helper.vmmc_supply);
1362 if (sc->mmc_helper.vqmmc_supply) {
1363 rv = regulator_status(sc->mmc_helper.vqmmc_supply, ®_status);
1365 regulator_enable(sc->mmc_helper.vqmmc_supply);
1368 if (sc->mmc_helper.mmc_pwrseq)
1369 MMC_PWRSEQ_SET_POWER(sc->mmc_helper.mmc_pwrseq, true);
1370 aw_mmc_init(sc);
1375 reg = AW_MMC_READ_4(sc, AW_MMC_GCTL);
1381 AW_MMC_WRITE_4(sc, AW_MMC_GCTL, reg);
1383 if (ios->clock && ios->clock != sc->aw_clock) {
1384 sc->aw_clock = clock = ios->clock;
1387 error = aw_mmc_update_clock(sc, 0);
1392 (sc->aw_mmc_conf->new_timing ||
1399 reg = AW_MMC_READ_4(sc, AW_MMC_CKCR);
1402 AW_MMC_WRITE_4(sc, AW_MMC_CKCR, reg);
1405 if (sc->aw_mmc_conf->new_timing) {
1406 reg = AW_MMC_READ_4(sc, AW_MMC_NTSR);
1408 AW_MMC_WRITE_4(sc, AW_MMC_NTSR, reg);
1412 error = clk_disable(sc->aw_clk_mmc);
1414 device_printf(sc->aw_dev,
1416 error = clk_set_freq(sc->aw_clk_mmc, clock,
1419 device_printf(sc->aw_dev,
1424 error = clk_enable(sc->aw_clk_mmc);
1426 device_printf(sc->aw_dev,
1429 if (sc->aw_mmc_conf->can_calibrate)
1430 AW_MMC_WRITE_4(sc, AW_MMC_SAMP_DL, AW_MMC_SAMP_DL_SW_EN);
1433 error = aw_mmc_update_clock(sc, 1);
1445 struct aw_mmc_softc *sc; local
1447 sc = device_get_softc(bus);
1449 return (mmc_fdt_gpio_get_readonly(&sc->mmc_helper));
1455 struct aw_mmc_softc *sc; local
1458 sc = device_get_softc(bus);
1459 AW_MMC_LOCK(sc);
1460 while (sc->aw_bus_busy) {
1461 error = msleep(sc, &sc->aw_mtx, PCATCH, "mmchw", 0);
1463 AW_MMC_UNLOCK(sc);
1467 sc->aw_bus_busy++;
1468 AW_MMC_UNLOCK(sc);
1476 struct aw_mmc_softc *sc; local
1478 sc = device_get_softc(bus);
1479 AW_MMC_LOCK(sc);
1480 sc->aw_bus_busy--;
1481 wakeup(sc);
1482 AW_MMC_UNLOCK(sc);