Lines Matching refs:host
45 void mmcsd_host_lock(struct rt_mmcsd_host *host) in mmcsd_host_lock() argument
47 rt_mutex_take(&host->bus_lock, RT_WAITING_FOREVER); in mmcsd_host_lock()
50 void mmcsd_host_unlock(struct rt_mmcsd_host *host) in mmcsd_host_unlock() argument
52 rt_mutex_release(&host->bus_lock); in mmcsd_host_unlock()
55 void mmcsd_req_complete(struct rt_mmcsd_host *host) in mmcsd_req_complete() argument
57 rt_sem_release(&host->sem_ack); in mmcsd_req_complete()
60 void mmcsd_send_request(struct rt_mmcsd_host *host, struct rt_mmcsd_req *req) in mmcsd_send_request() argument
79 host->ops->request(host, req); in mmcsd_send_request()
81 rt_sem_take(&host->sem_ack, RT_WAITING_FOREVER); in mmcsd_send_request()
89 rt_int32_t mmcsd_send_cmd(struct rt_mmcsd_host *host, in mmcsd_send_cmd() argument
102 mmcsd_send_request(host, &req); in mmcsd_send_cmd()
107 rt_int32_t mmcsd_go_idle(struct rt_mmcsd_host *host) in mmcsd_go_idle() argument
112 if (!controller_is_spi(host)) in mmcsd_go_idle()
114 mmcsd_set_chip_select(host, MMCSD_CS_HIGH); in mmcsd_go_idle()
124 err = mmcsd_send_cmd(host, &cmd, 0); in mmcsd_go_idle()
128 if (!controller_is_spi(host)) in mmcsd_go_idle()
130 mmcsd_set_chip_select(host, MMCSD_CS_IGNORE); in mmcsd_go_idle()
137 rt_int32_t mmcsd_spi_read_ocr(struct rt_mmcsd_host *host, in mmcsd_spi_read_ocr() argument
150 err = mmcsd_send_cmd(host, &cmd, 0); in mmcsd_spi_read_ocr()
157 rt_int32_t mmcsd_all_get_cid(struct rt_mmcsd_host *host, rt_uint32_t *cid) in mmcsd_all_get_cid() argument
168 err = mmcsd_send_cmd(host, &cmd, 3); in mmcsd_all_get_cid()
177 rt_int32_t mmcsd_get_cid(struct rt_mmcsd_host *host, rt_uint32_t *cid) in mmcsd_get_cid() argument
185 if (!controller_is_spi(host)) in mmcsd_get_cid()
187 if (!host->card) in mmcsd_get_cid()
192 cmd.arg = host->card->rca << 16; in mmcsd_get_cid()
194 err = mmcsd_send_cmd(host, &cmd, 3); in mmcsd_get_cid()
239 mmcsd_send_request(host, &req); in mmcsd_get_cid()
263 if (!controller_is_spi(card->host)) in mmcsd_get_csd()
270 err = mmcsd_send_cmd(card->host, &cmd, 3); in mmcsd_get_csd()
316 mmcsd_send_request(card->host, &req); in mmcsd_get_csd()
332 static rt_int32_t _mmcsd_select_card(struct rt_mmcsd_host *host, in _mmcsd_select_card() argument
353 err = mmcsd_send_cmd(host, &cmd, 3); in _mmcsd_select_card()
362 return _mmcsd_select_card(card->host, card); in mmcsd_select_card()
367 return _mmcsd_select_card(card->host, RT_NULL); in mmcsd_deselect_cards()
370 rt_int32_t mmcsd_spi_use_crc(struct rt_mmcsd_host *host, rt_int32_t use_crc) in mmcsd_spi_use_crc() argument
381 err = mmcsd_send_cmd(host, &cmd, 0); in mmcsd_spi_use_crc()
383 host->spi_use_crc = use_crc; in mmcsd_spi_use_crc()
388 rt_inline void mmcsd_set_iocfg(struct rt_mmcsd_host *host) in mmcsd_set_iocfg() argument
390 struct rt_mmcsd_io_cfg *io_cfg = &host->io_cfg; in mmcsd_set_iocfg()
398 host->ops->set_iocfg(host, io_cfg); in mmcsd_set_iocfg()
404 void mmcsd_set_chip_select(struct rt_mmcsd_host *host, rt_int32_t mode) in mmcsd_set_chip_select() argument
406 host->io_cfg.chip_select = mode; in mmcsd_set_chip_select()
407 mmcsd_set_iocfg(host); in mmcsd_set_chip_select()
414 void mmcsd_set_clock(struct rt_mmcsd_host *host, rt_uint32_t clk) in mmcsd_set_clock() argument
416 if (clk < host->freq_min) in mmcsd_set_clock()
421 host->io_cfg.clock = clk; in mmcsd_set_clock()
422 mmcsd_set_iocfg(host); in mmcsd_set_clock()
428 void mmcsd_set_bus_mode(struct rt_mmcsd_host *host, rt_uint32_t mode) in mmcsd_set_bus_mode() argument
430 host->io_cfg.bus_mode = mode; in mmcsd_set_bus_mode()
431 mmcsd_set_iocfg(host); in mmcsd_set_bus_mode()
437 void mmcsd_set_bus_width(struct rt_mmcsd_host *host, rt_uint32_t width) in mmcsd_set_bus_width() argument
439 host->io_cfg.bus_width = width; in mmcsd_set_bus_width()
440 mmcsd_set_iocfg(host); in mmcsd_set_bus_width()
443 void mmcsd_set_timing(struct rt_mmcsd_host *host, rt_uint32_t timing) in mmcsd_set_timing() argument
445 host->io_cfg.timing = timing; in mmcsd_set_timing()
446 mmcsd_set_iocfg(host); in mmcsd_set_timing()
486 (card->host->io_cfg.clock / 1000); in mmcsd_set_data_timeout()
507 if (controller_is_spi(card->host)) in mmcsd_set_data_timeout()
526 rt_uint32_t mmcsd_select_voltage(struct rt_mmcsd_host *host, rt_uint32_t ocr) in mmcsd_select_voltage() argument
531 ocr &= host->valid_ocr; in mmcsd_select_voltage()
540 host->io_cfg.vdd = bit; in mmcsd_select_voltage()
541 mmcsd_set_iocfg(host); in mmcsd_select_voltage()
552 static void mmcsd_power_up(struct rt_mmcsd_host *host) in mmcsd_power_up() argument
554 int bit = __rt_fls(host->valid_ocr) - 1; in mmcsd_power_up()
556 host->io_cfg.vdd = bit; in mmcsd_power_up()
557 if (controller_is_spi(host)) in mmcsd_power_up()
559 host->io_cfg.chip_select = MMCSD_CS_HIGH; in mmcsd_power_up()
560 host->io_cfg.bus_mode = MMCSD_BUSMODE_PUSHPULL; in mmcsd_power_up()
564 host->io_cfg.chip_select = MMCSD_CS_IGNORE; in mmcsd_power_up()
565 host->io_cfg.bus_mode = MMCSD_BUSMODE_OPENDRAIN; in mmcsd_power_up()
567 host->io_cfg.power_mode = MMCSD_POWER_UP; in mmcsd_power_up()
568 host->io_cfg.bus_width = MMCSD_BUS_WIDTH_1; in mmcsd_power_up()
569 mmcsd_set_iocfg(host); in mmcsd_power_up()
577 host->io_cfg.clock = host->freq_min; in mmcsd_power_up()
578 host->io_cfg.power_mode = MMCSD_POWER_ON; in mmcsd_power_up()
579 mmcsd_set_iocfg(host); in mmcsd_power_up()
588 static void mmcsd_power_off(struct rt_mmcsd_host *host) in mmcsd_power_off() argument
590 host->io_cfg.clock = 0; in mmcsd_power_off()
591 host->io_cfg.vdd = 0; in mmcsd_power_off()
592 if (!controller_is_spi(host)) in mmcsd_power_off()
594 host->io_cfg.bus_mode = MMCSD_BUSMODE_OPENDRAIN; in mmcsd_power_off()
595 host->io_cfg.chip_select = MMCSD_CS_IGNORE; in mmcsd_power_off()
597 host->io_cfg.power_mode = MMCSD_POWER_OFF; in mmcsd_power_off()
598 host->io_cfg.bus_width = MMCSD_BUS_WIDTH_1; in mmcsd_power_off()
599 mmcsd_set_iocfg(host); in mmcsd_power_off()
604 struct rt_mmcsd_host *host; in mmcsd_wait_cd_changed() local
605 if (rt_mb_recv(&mmcsd_hotpluge_mb, (rt_ubase_t *)&host, timeout) == RT_EOK) in mmcsd_wait_cd_changed()
607 if (host->card == RT_NULL) in mmcsd_wait_cd_changed()
620 void mmcsd_change(struct rt_mmcsd_host *host) in mmcsd_change() argument
622 rt_mb_send(&mmcsd_detect_mb, (rt_ubase_t)host); in mmcsd_change()
627 struct rt_mmcsd_host *host; in mmcsd_detect() local
633 if (rt_mb_recv(&mmcsd_detect_mb, (rt_ubase_t *)&host, RT_WAITING_FOREVER) == RT_EOK) in mmcsd_detect()
635 if (host->card == RT_NULL) in mmcsd_detect()
637 mmcsd_host_lock(host); in mmcsd_detect()
638 mmcsd_power_up(host); in mmcsd_detect()
639 mmcsd_go_idle(host); in mmcsd_detect()
641 mmcsd_send_if_cond(host, host->valid_ocr); in mmcsd_detect()
643 err = sdio_io_send_op_cond(host, 0, &ocr); in mmcsd_detect()
646 if (init_sdio(host, ocr)) in mmcsd_detect()
647 mmcsd_power_off(host); in mmcsd_detect()
648 mmcsd_host_unlock(host); in mmcsd_detect()
655 err = mmcsd_send_app_op_cond(host, 0, &ocr); in mmcsd_detect()
658 if (init_sd(host, ocr)) in mmcsd_detect()
659 mmcsd_power_off(host); in mmcsd_detect()
660 mmcsd_host_unlock(host); in mmcsd_detect()
661 rt_mb_send(&mmcsd_hotpluge_mb, (rt_ubase_t)host); in mmcsd_detect()
668 err = mmc_send_op_cond(host, 0, &ocr); in mmcsd_detect()
671 if (init_mmc(host, ocr)) in mmcsd_detect()
672 mmcsd_power_off(host); in mmcsd_detect()
673 mmcsd_host_unlock(host); in mmcsd_detect()
674 rt_mb_send(&mmcsd_hotpluge_mb, (rt_ubase_t)host); in mmcsd_detect()
677 mmcsd_host_unlock(host); in mmcsd_detect()
682 mmcsd_host_lock(host); in mmcsd_detect()
683 if (host->card->sdio_function_num != 0) in mmcsd_detect()
689 rt_mmcsd_blk_remove(host->card); in mmcsd_detect()
690 rt_free(host->card); in mmcsd_detect()
692 host->card = RT_NULL; in mmcsd_detect()
694 mmcsd_host_unlock(host); in mmcsd_detect()
695 rt_mb_send(&mmcsd_hotpluge_mb, (rt_ubase_t)host); in mmcsd_detect()
701 void mmcsd_host_init(struct rt_mmcsd_host *host) in mmcsd_host_init() argument
703 rt_memset(host, 0, sizeof(struct rt_mmcsd_host)); in mmcsd_host_init()
704 strncpy(host->name, "sd", sizeof(host->name) - 1); in mmcsd_host_init()
705 host->max_seg_size = 65535; in mmcsd_host_init()
706 host->max_dma_segs = 1; in mmcsd_host_init()
707 host->max_blk_size = 512; in mmcsd_host_init()
708 host->max_blk_count = 4096; in mmcsd_host_init()
710 rt_mutex_init(&host->bus_lock, "sd_bus_lock", RT_IPC_FLAG_FIFO); in mmcsd_host_init()
711 rt_sem_init(&host->sem_ack, "sd_ack", 0, RT_IPC_FLAG_FIFO); in mmcsd_host_init()
716 struct rt_mmcsd_host *host; in mmcsd_alloc_host() local
718 host = rt_malloc(sizeof(struct rt_mmcsd_host)); in mmcsd_alloc_host()
719 if (!host) in mmcsd_alloc_host()
726 mmcsd_host_init(host); in mmcsd_alloc_host()
728 return host; in mmcsd_alloc_host()
731 void mmcsd_free_host(struct rt_mmcsd_host *host) in mmcsd_free_host() argument
733 rt_mutex_detach(&host->bus_lock); in mmcsd_free_host()
734 rt_sem_detach(&host->sem_ack); in mmcsd_free_host()
735 rt_free(host); in mmcsd_free_host()
740 struct rt_mmcsd_host *host = card->host; in mmcsd_excute_tuning() local
743 if (!host->ops->execute_tuning) in mmcsd_excute_tuning()
751 return host->ops->execute_tuning(host, opcode);; in mmcsd_excute_tuning()