Lines Matching defs:sc
103 struct sdmmc_softc *sc = (struct sdmmc_softc *)self;
129 sc->sct = saa->sct;
130 sc->sch = saa->sch;
131 sc->sc_dmat = saa->dmat;
132 sc->sc_dmap = saa->dmap;
133 sc->sc_flags = saa->flags;
134 sc->sc_caps = saa->caps;
135 sc->sc_max_seg = saa->max_seg ? saa->max_seg : MAXPHYS;
136 sc->sc_max_xfer = saa->max_xfer;
137 memcpy(&sc->sc_cookies, &saa->cookies, sizeof(sc->sc_cookies));
139 if (ISSET(sc->sc_caps, SMC_CAPS_DMA) && sc->sc_dmap == NULL) {
140 error = bus_dmamap_create(sc->sc_dmat, MAXPHYS, SDMMC_MAXNSEGS,
141 sc->sc_max_seg, saa->dma_boundary,
143 &sc->sc_dmap);
145 printf("%s: can't create DMA map\n", DEVNAME(sc));
150 SIMPLEQ_INIT(&sc->sf_head);
151 TAILQ_INIT(&sc->sc_tskq);
152 TAILQ_INIT(&sc->sc_intrq);
153 sdmmc_init_task(&sc->sc_discover_task, sdmmc_discover_task, sc);
154 sdmmc_init_task(&sc->sc_intr_task, sdmmc_intr_task, sc);
155 rw_init(&sc->sc_lock, DEVNAME(sc));
159 printf("%s: unable to register ioctl\n", DEVNAME(sc));
167 SET(sc->sc_flags, SMF_CONFIG_PENDING);
169 kthread_create_deferred(sdmmc_create_thread, sc);
175 struct sdmmc_softc *sc = (struct sdmmc_softc *)self;
177 sc->sc_dying = 1;
178 while (sc->sc_task_thread != NULL) {
179 wakeup(&sc->sc_tskq);
180 tsleep_nsec(sc, PWAIT, "mmcdie", INFSLP);
183 if (sc->sc_dmap)
184 bus_dmamap_destroy(sc->sc_dmat, sc->sc_dmap);
192 struct sdmmc_softc *sc = (struct sdmmc_softc *)self;
199 if (ISSET(sc->sc_flags, SMF_CARD_PRESENT) &&
200 !ISSET(sc->sc_caps, SMC_CAPS_NONREMOVABLE) &&
201 !sdmmc_holds_root_device(sc))
202 sc->sc_dying = -1;
205 wakeup(&sc->sc_tskq);
216 sdmmc_holds_root_device(struct sdmmc_softc *sc)
219 rootdv->dv_parent->dv_parent == &sc->sc_dev)
228 struct sdmmc_softc *sc = arg;
230 if (kthread_create(sdmmc_task_thread, sc, &sc->sc_task_thread,
231 DEVNAME(sc)) != 0)
232 printf("%s: can't create task thread\n", DEVNAME(sc));
239 struct sdmmc_softc *sc = arg;
244 sdmmc_needs_discover(&sc->sc_dev);
247 while (!sc->sc_dying) {
248 for (task = TAILQ_FIRST(&sc->sc_tskq); task != NULL;
249 task = TAILQ_FIRST(&sc->sc_tskq)) {
255 tsleep_nsec(&sc->sc_tskq, PWAIT, "mmctsk", INFSLP);
259 if (ISSET(sc->sc_flags, SMF_CARD_PRESENT)) {
260 rw_enter_write(&sc->sc_lock);
261 sdmmc_card_detach(sc, DETACH_FORCE);
262 rw_exit(&sc->sc_lock);
269 if (sc->sc_dying == -1) {
270 CLR(sc->sc_flags, SMF_CARD_PRESENT);
271 sc->sc_dying = 0;
274 sc->sc_task_thread = NULL;
275 wakeup(sc);
280 sdmmc_add_task(struct sdmmc_softc *sc, struct sdmmc_task *task)
285 TAILQ_INSERT_TAIL(&sc->sc_tskq, task, next);
287 task->sc = sc;
288 wakeup(&sc->sc_tskq);
295 struct sdmmc_softc *sc = task->sc;
298 if (sc == NULL)
302 task->sc = NULL;
304 TAILQ_REMOVE(&sc->sc_tskq, task, next);
311 struct sdmmc_softc *sc = (struct sdmmc_softc *)self;
313 if (!sdmmc_task_pending(&sc->sc_discover_task))
314 sdmmc_add_task(sc, &sc->sc_discover_task);
320 struct sdmmc_softc *sc = arg;
322 if (sdmmc_chip_card_detect(sc->sct, sc->sch)) {
323 if (!ISSET(sc->sc_flags, SMF_CARD_PRESENT)) {
324 SET(sc->sc_flags, SMF_CARD_PRESENT);
325 sdmmc_card_attach(sc);
328 if (ISSET(sc->sc_flags, SMF_CARD_PRESENT)) {
329 CLR(sc->sc_flags, SMF_CARD_PRESENT);
330 rw_enter_write(&sc->sc_lock);
331 sdmmc_card_detach(sc, DETACH_FORCE);
332 rw_exit(&sc->sc_lock);
336 if (ISSET(sc->sc_flags, SMF_CONFIG_PENDING)) {
337 CLR(sc->sc_flags, SMF_CONFIG_PENDING);
346 sdmmc_card_attach(struct sdmmc_softc *sc)
348 DPRINTF(1,("%s: attach card\n", DEVNAME(sc)));
350 rw_enter_write(&sc->sc_lock);
351 CLR(sc->sc_flags, SMF_CARD_ATTACHED);
356 if (sdmmc_enable(sc) != 0) {
357 printf("%s: can't enable card\n", DEVNAME(sc));
365 if (sdmmc_scan(sc) != 0) {
366 printf("%s: no functions\n", DEVNAME(sc));
373 if (sdmmc_init(sc) != 0) {
374 printf("%s: init failed\n", DEVNAME(sc));
379 if (ISSET(sc->sc_flags, SMF_MEM_MODE))
380 sdmmc_scsi_attach(sc);
383 if (ISSET(sc->sc_flags, SMF_IO_MODE))
384 sdmmc_io_attach(sc);
386 SET(sc->sc_flags, SMF_CARD_ATTACHED);
387 rw_exit(&sc->sc_lock);
390 sdmmc_card_detach(sc, DETACH_FORCE);
391 rw_exit(&sc->sc_lock);
399 sdmmc_card_detach(struct sdmmc_softc *sc, int flags)
403 rw_assert_wrlock(&sc->sc_lock);
405 DPRINTF(1,("%s: detach card\n", DEVNAME(sc)));
407 if (ISSET(sc->sc_flags, SMF_CARD_ATTACHED)) {
409 if (ISSET(sc->sc_flags, SMF_IO_MODE))
410 sdmmc_io_detach(sc);
413 if (ISSET(sc->sc_flags, SMF_MEM_MODE))
414 sdmmc_scsi_detach(sc);
416 CLR(sc->sc_flags, SMF_CARD_ATTACHED);
420 sdmmc_disable(sc);
423 for (sf = SIMPLEQ_FIRST(&sc->sf_head); sf != NULL; sf = sfnext) {
427 SIMPLEQ_INIT(&sc->sf_head);
428 sc->sc_function_count = 0;
429 sc->sc_fn0 = NULL;
433 sdmmc_enable(struct sdmmc_softc *sc)
438 rw_assert_wrlock(&sc->sc_lock);
444 host_ocr = sdmmc_chip_host_ocr(sc->sct, sc->sch);
445 error = sdmmc_chip_bus_power(sc->sct, sc->sch, host_ocr);
447 printf("%s: can't supply bus power\n", DEVNAME(sc));
454 error = sdmmc_chip_bus_clock(sc->sct, sc->sch,
457 printf("%s: can't supply clock\n", DEVNAME(sc));
465 if ((error = sdmmc_io_enable(sc)) != 0)
469 if (ISSET(sc->sc_flags, SMF_MEM_MODE) &&
470 (error = sdmmc_mem_enable(sc)) != 0)
475 sdmmc_disable(sc);
481 sdmmc_disable(struct sdmmc_softc *sc)
485 rw_assert_wrlock(&sc->sc_lock);
488 (void)sdmmc_select_card(sc, NULL);
491 (void)sdmmc_chip_bus_clock(sc->sct, sc->sch,
493 (void)sdmmc_chip_bus_power(sc->sct, sc->sch, 0);
500 sdmmc_set_bus_power(struct sdmmc_softc *sc, u_int32_t host_ocr,
505 rw_assert_wrlock(&sc->sc_lock);
508 DPRINTF(1,("%s: host_ocr=%x ", DEVNAME(sc), host_ocr));
519 sdmmc_chip_bus_power(sc->sct, sc->sch, host_ocr) != 0)
525 sdmmc_function_alloc(struct sdmmc_softc *sc)
531 sf->sc = sc;
536 sf->cur_blklen = sdmmc_chip_host_maxblklen(sc->sct, sc->sch);
551 sdmmc_scan(struct sdmmc_softc *sc)
554 rw_assert_wrlock(&sc->sc_lock);
557 if (ISSET(sc->sc_flags, SMF_IO_MODE))
558 sdmmc_io_scan(sc);
561 if (ISSET(sc->sc_flags, SMF_MEM_MODE))
562 sdmmc_mem_scan(sc);
565 if (SIMPLEQ_EMPTY(&sc->sf_head)) {
566 printf("%s: can't identify card\n", DEVNAME(sc));
577 sdmmc_init(struct sdmmc_softc *sc)
581 rw_assert_wrlock(&sc->sc_lock);
584 SIMPLEQ_FOREACH(sf, &sc->sf_head, sf_list) {
585 if (ISSET(sc->sc_flags, SMF_IO_MODE) &&
586 sdmmc_io_init(sc, sf) != 0)
587 printf("%s: i/o init failed\n", DEVNAME(sc));
589 if (ISSET(sc->sc_flags, SMF_MEM_MODE) &&
590 sdmmc_mem_init(sc, sf) != 0)
591 printf("%s: mem init failed\n", DEVNAME(sc));
595 SIMPLEQ_FOREACH(sf, &sc->sf_head, sf_list) {
613 sdmmc_app_command(struct sdmmc_softc *sc, struct sdmmc_command *cmd)
618 rw_assert_wrlock(&sc->sc_lock);
623 if (sc->sc_card != NULL) {
624 acmd.c_arg = sc->sc_card->rca << 16;
628 error = sdmmc_mmc_command(sc, &acmd);
638 error = sdmmc_mmc_command(sc, cmd);
648 sdmmc_mmc_command(struct sdmmc_softc *sc, struct sdmmc_command *cmd)
652 rw_assert_wrlock(&sc->sc_lock);
654 sdmmc_chip_exec_command(sc->sct, sc->sch, cmd);
657 sdmmc_dump_command(sc, cmd);
671 sdmmc_go_idle_state(struct sdmmc_softc *sc)
675 rw_assert_wrlock(&sc->sc_lock);
681 (void)sdmmc_mmc_command(sc, &cmd);
688 sdmmc_send_if_cond(struct sdmmc_softc *sc, uint32_t card_ocr)
694 rw_assert_wrlock(&sc->sc_lock);
702 if (sdmmc_mmc_command(sc, &cmd) != 0)
716 sdmmc_set_relative_addr(struct sdmmc_softc *sc,
721 rw_assert_wrlock(&sc->sc_lock);
725 if (ISSET(sc->sc_flags, SMF_SD_MODE)) {
734 if (sdmmc_mmc_command(sc, &cmd) != 0)
737 if (ISSET(sc->sc_flags, SMF_SD_MODE))
743 sdmmc_select_card(struct sdmmc_softc *sc, struct sdmmc_function *sf)
748 rw_assert_wrlock(&sc->sc_lock);
750 if (sc->sc_card == sf || (sf && sc->sc_card &&
751 sc->sc_card->rca == sf->rca)) {
752 sc->sc_card = sf;
760 error = sdmmc_mmc_command(sc, &cmd);
762 sc->sc_card = sf;
770 struct sdmmc_softc *sc = (struct sdmmc_softc *)self;
817 rw_enter_write(&sc->sc_lock);
819 error = sdmmc_mmc_command(sc, &cmd);
821 error = sdmmc_app_command(sc, &cmd);
822 rw_exit(&sc->sc_lock);
849 sdmmc_dump_command(struct sdmmc_softc *sc, struct sdmmc_command *cmd)
853 rw_assert_wrlock(&sc->sc_lock);
856 "proc=\"%s\" (error %d)\n", DEVNAME(sc), cmd->c_opcode,
863 printf("%s: resp=", DEVNAME(sc));