Lines Matching refs:host

70 static inline struct device *sdmmc_dev(struct rtsx_usb_sdmmc *host)  in sdmmc_dev()  argument
72 return &(host->pdev->dev); in sdmmc_dev()
75 static inline void sd_clear_error(struct rtsx_usb_sdmmc *host) in sd_clear_error() argument
77 struct rtsx_ucr *ucr = host->ucr; in sd_clear_error()
87 static void sd_print_debug_regs(struct rtsx_usb_sdmmc *host) in sd_print_debug_regs() argument
89 struct rtsx_ucr *ucr = host->ucr; in sd_print_debug_regs()
93 dev_dbg(sdmmc_dev(host), "SD_STAT1: 0x%x\n", val); in sd_print_debug_regs()
95 dev_dbg(sdmmc_dev(host), "SD_STAT2: 0x%x\n", val); in sd_print_debug_regs()
97 dev_dbg(sdmmc_dev(host), "SD_BUS_STAT: 0x%x\n", val); in sd_print_debug_regs()
100 #define sd_print_debug_regs(host) argument
103 static int sd_read_data(struct rtsx_usb_sdmmc *host, struct mmc_command *cmd, in sd_read_data() argument
106 struct rtsx_ucr *ucr = host->ucr; in sd_read_data()
115 dev_dbg(sdmmc_dev(host), "%s: SD/MMC CMD%d\n", __func__ in sd_read_data()
163 dev_dbg(sdmmc_dev(host), in sd_read_data()
170 sd_print_debug_regs(host); in sd_read_data()
173 dev_dbg(sdmmc_dev(host), in sd_read_data()
178 dev_dbg(sdmmc_dev(host), in sd_read_data()
187 dev_dbg(sdmmc_dev(host), "cmd->resp[0] = 0x%08x\n", in sd_read_data()
195 dev_dbg(sdmmc_dev(host), in sd_read_data()
210 static int sd_write_data(struct rtsx_usb_sdmmc *host, struct mmc_command *cmd, in sd_write_data() argument
213 struct rtsx_ucr *ucr = host->ucr; in sd_write_data()
223 dev_dbg(sdmmc_dev(host), in sd_write_data()
234 dev_dbg(sdmmc_dev(host), "%s: SD/MMC CMD%d\n", __func__, in sd_write_data()
274 dev_dbg(sdmmc_dev(host), in sd_write_data()
281 sd_print_debug_regs(host); in sd_write_data()
282 dev_dbg(sdmmc_dev(host), in sd_write_data()
289 dev_dbg(sdmmc_dev(host), "cmd->resp[0] = 0x%08x\n", in sd_write_data()
296 static void sd_send_cmd_get_rsp(struct rtsx_usb_sdmmc *host, in sd_send_cmd_get_rsp() argument
299 struct rtsx_ucr *ucr = host->ucr; in sd_send_cmd_get_rsp()
310 dev_dbg(sdmmc_dev(host), "%s: SD/MMC CMD %d, arg = 0x%08x\n", in sd_send_cmd_get_rsp()
340 dev_dbg(sdmmc_dev(host), "cmd->flag is not valid\n"); in sd_send_cmd_get_rsp()
390 dev_dbg(sdmmc_dev(host), in sd_send_cmd_get_rsp()
397 sd_print_debug_regs(host); in sd_send_cmd_get_rsp()
398 sd_clear_error(host); in sd_send_cmd_get_rsp()
401 dev_dbg(sdmmc_dev(host), in sd_send_cmd_get_rsp()
406 dev_dbg(sdmmc_dev(host), in sd_send_cmd_get_rsp()
424 dev_dbg(sdmmc_dev(host), "Invalid response bit\n"); in sd_send_cmd_get_rsp()
432 dev_dbg(sdmmc_dev(host), "CRC7 error\n"); in sd_send_cmd_get_rsp()
447 dev_dbg(sdmmc_dev(host), "cmd->resp[%d] = 0x%08x\n", in sd_send_cmd_get_rsp()
452 dev_dbg(sdmmc_dev(host), "cmd->resp[0] = 0x%08x\n", in sd_send_cmd_get_rsp()
460 static int sd_rw_multi(struct rtsx_usb_sdmmc *host, struct mmc_request *mrq) in sd_rw_multi() argument
462 struct rtsx_ucr *ucr = host->ucr; in sd_rw_multi()
472 dev_dbg(sdmmc_dev(host), "%s: read %zu bytes\n", in sd_rw_multi()
478 dev_dbg(sdmmc_dev(host), "%s: write %zu bytes\n", in sd_rw_multi()
535 dev_dbg(sdmmc_dev(host), "rtsx_usb_transfer_data error %d\n" in sd_rw_multi()
537 sd_clear_error(host); in sd_rw_multi()
544 static inline void sd_enable_initial_mode(struct rtsx_usb_sdmmc *host) in sd_enable_initial_mode() argument
546 rtsx_usb_write_register(host->ucr, SD_CFG1, in sd_enable_initial_mode()
550 static inline void sd_disable_initial_mode(struct rtsx_usb_sdmmc *host) in sd_disable_initial_mode() argument
552 rtsx_usb_write_register(host->ucr, SD_CFG1, in sd_disable_initial_mode()
556 static void sd_normal_rw(struct rtsx_usb_sdmmc *host, in sd_normal_rw() argument
570 if (host->initial_mode) in sd_normal_rw()
571 sd_disable_initial_mode(host); in sd_normal_rw()
573 cmd->error = sd_read_data(host, cmd, (u16)data->blksz, buf, in sd_normal_rw()
576 if (host->initial_mode) in sd_normal_rw()
577 sd_enable_initial_mode(host); in sd_normal_rw()
583 cmd->error = sd_write_data(host, cmd, (u16)data->blksz, buf, in sd_normal_rw()
590 static int sd_change_phase(struct rtsx_usb_sdmmc *host, u8 sample_point, int tx) in sd_change_phase() argument
592 struct rtsx_ucr *ucr = host->ucr; in sd_change_phase()
595 dev_dbg(sdmmc_dev(host), "%s: %s sample_point = %d\n", in sd_change_phase()
639 static u8 sd_search_final_phase(struct rtsx_usb_sdmmc *host, u32 phase_map) in sd_search_final_phase() argument
646 dev_dbg(sdmmc_dev(host), "Phase: [map:%x]\n", phase_map); in sd_search_final_phase()
660 dev_dbg(sdmmc_dev(host), "Phase: [map:%x] [maxlen:%d] [final:%d]\n", in sd_search_final_phase()
666 static void sd_wait_data_idle(struct rtsx_usb_sdmmc *host) in sd_wait_data_idle() argument
672 err = rtsx_usb_ep0_read_register(host->ucr, in sd_wait_data_idle()
681 static int sd_tuning_rx_cmd(struct rtsx_usb_sdmmc *host, in sd_tuning_rx_cmd() argument
687 err = sd_change_phase(host, sample_point, 0); in sd_tuning_rx_cmd()
692 err = sd_read_data(host, &cmd, 0x40, NULL, 0, 100); in sd_tuning_rx_cmd()
695 sd_wait_data_idle(host); in sd_tuning_rx_cmd()
696 sd_clear_error(host); in sd_tuning_rx_cmd()
703 static void sd_tuning_phase(struct rtsx_usb_sdmmc *host, in sd_tuning_phase() argument
710 err = sd_tuning_rx_cmd(host, opcode, (u8)i); in sd_tuning_phase()
719 static int sd_tuning_rx(struct rtsx_usb_sdmmc *host, u8 opcode) in sd_tuning_rx() argument
726 err = sd_change_phase(host, 0x01, 1); in sd_tuning_rx()
728 dev_dbg(sdmmc_dev(host), "TX phase setting failed\n"); in sd_tuning_rx()
734 sd_tuning_phase(host, opcode, &(raw_phase_map[i])); in sd_tuning_rx()
742 dev_dbg(sdmmc_dev(host), "RX raw_phase_map[%d] = 0x%04x\n", in sd_tuning_rx()
746 dev_dbg(sdmmc_dev(host), "RX phase_map = 0x%04x\n", phase_map); in sd_tuning_rx()
749 final_phase = sd_search_final_phase(host, phase_map); in sd_tuning_rx()
753 err = sd_change_phase(host, final_phase, 0); in sd_tuning_rx()
765 struct rtsx_usb_sdmmc *host = mmc_priv(mmc); in sdmmc_get_ro() local
766 struct rtsx_ucr *ucr = host->ucr; in sdmmc_get_ro()
770 if (host->host_removal) in sdmmc_get_ro()
793 struct rtsx_usb_sdmmc *host = mmc_priv(mmc); in sdmmc_get_cd() local
794 struct rtsx_ucr *ucr = host->ucr; in sdmmc_get_cd()
798 if (host->host_removal) in sdmmc_get_cd()
813 host->card_exist = true; in sdmmc_get_cd()
818 host->card_exist = false; in sdmmc_get_cd()
824 struct rtsx_usb_sdmmc *host = mmc_priv(mmc); in sdmmc_request() local
825 struct rtsx_ucr *ucr = host->ucr; in sdmmc_request()
830 dev_dbg(sdmmc_dev(host), "%s\n", __func__); in sdmmc_request()
832 if (host->host_removal) { in sdmmc_request()
837 if ((!host->card_exist)) { in sdmmc_request()
855 mutex_lock(&host->host_mutex); in sdmmc_request()
856 host->mrq = mrq; in sdmmc_request()
857 mutex_unlock(&host->host_mutex); in sdmmc_request()
863 sd_send_cmd_get_rsp(host, cmd); in sdmmc_request()
866 sd_send_cmd_get_rsp(host, cmd); in sdmmc_request()
869 sd_rw_multi(host, mrq); in sdmmc_request()
872 sd_send_cmd_get_rsp(host, mrq->stop); in sdmmc_request()
878 sd_normal_rw(host, mrq); in sdmmc_request()
897 dev_dbg(sdmmc_dev(host), "cmd->error = %d\n", cmd->error); in sdmmc_request()
901 mutex_lock(&host->host_mutex); in sdmmc_request()
902 host->mrq = NULL; in sdmmc_request()
903 mutex_unlock(&host->host_mutex); in sdmmc_request()
908 static int sd_set_bus_width(struct rtsx_usb_sdmmc *host, in sd_set_bus_width() argument
919 err = rtsx_usb_write_register(host->ucr, SD_CFG1, in sd_set_bus_width()
981 static int sd_power_on(struct rtsx_usb_sdmmc *host) in sd_power_on() argument
983 struct rtsx_ucr *ucr = host->ucr; in sd_power_on()
986 dev_dbg(sdmmc_dev(host), "%s\n", __func__); in sd_power_on()
1020 static int sd_power_off(struct rtsx_usb_sdmmc *host) in sd_power_off() argument
1022 struct rtsx_ucr *ucr = host->ucr; in sd_power_off()
1025 dev_dbg(sdmmc_dev(host), "%s\n", __func__); in sd_power_off()
1044 static int sd_set_power_mode(struct rtsx_usb_sdmmc *host, in sd_set_power_mode() argument
1052 if (power_mode == host->power_mode) in sd_set_power_mode()
1056 err = sd_power_off(host); in sd_set_power_mode()
1057 pm_runtime_put(sdmmc_dev(host)); in sd_set_power_mode()
1059 pm_runtime_get_sync(sdmmc_dev(host)); in sd_set_power_mode()
1060 err = sd_power_on(host); in sd_set_power_mode()
1064 host->power_mode = power_mode; in sd_set_power_mode()
1069 static int sd_set_timing(struct rtsx_usb_sdmmc *host, in sd_set_timing() argument
1072 struct rtsx_ucr *ucr = host->ucr; in sd_set_timing()
1135 struct rtsx_usb_sdmmc *host = mmc_priv(mmc); in sdmmc_set_ios() local
1136 struct rtsx_ucr *ucr = host->ucr; in sdmmc_set_ios()
1138 dev_dbg(sdmmc_dev(host), "%s\n", __func__); in sdmmc_set_ios()
1146 sd_set_power_mode(host, ios->power_mode); in sdmmc_set_ios()
1147 sd_set_bus_width(host, ios->bus_width); in sdmmc_set_ios()
1148 sd_set_timing(host, ios->timing, &host->ddr_mode); in sdmmc_set_ios()
1150 host->vpclk = false; in sdmmc_set_ios()
1151 host->double_clk = true; in sdmmc_set_ios()
1156 host->ssc_depth = SSC_DEPTH_2M; in sdmmc_set_ios()
1157 host->vpclk = true; in sdmmc_set_ios()
1158 host->double_clk = false; in sdmmc_set_ios()
1162 host->ssc_depth = SSC_DEPTH_1M; in sdmmc_set_ios()
1165 host->ssc_depth = SSC_DEPTH_512K; in sdmmc_set_ios()
1169 host->initial_mode = (ios->clock <= 1000000) ? true : false; in sdmmc_set_ios()
1170 host->clock = ios->clock; in sdmmc_set_ios()
1172 rtsx_usb_switch_clock(host->ucr, host->clock, host->ssc_depth, in sdmmc_set_ios()
1173 host->initial_mode, host->double_clk, host->vpclk); in sdmmc_set_ios()
1176 dev_dbg(sdmmc_dev(host), "%s end\n", __func__); in sdmmc_set_ios()
1181 struct rtsx_usb_sdmmc *host = mmc_priv(mmc); in sdmmc_switch_voltage() local
1182 struct rtsx_ucr *ucr = host->ucr; in sdmmc_switch_voltage()
1185 dev_dbg(sdmmc_dev(host), "%s: signal_voltage = %d\n", in sdmmc_switch_voltage()
1188 if (host->host_removal) in sdmmc_switch_voltage()
1230 struct rtsx_usb_sdmmc *host = mmc_priv(mmc); in sdmmc_card_busy() local
1231 struct rtsx_ucr *ucr = host->ucr; in sdmmc_card_busy()
1237 dev_dbg(sdmmc_dev(host), "%s\n", __func__); in sdmmc_card_busy()
1270 struct rtsx_usb_sdmmc *host = mmc_priv(mmc); in sdmmc_execute_tuning() local
1271 struct rtsx_ucr *ucr = host->ucr; in sdmmc_execute_tuning()
1274 if (host->host_removal) in sdmmc_execute_tuning()
1279 if (!host->ddr_mode) in sdmmc_execute_tuning()
1280 err = sd_tuning_rx(host, MMC_SEND_TUNING_BLOCK); in sdmmc_execute_tuning()
1301 struct rtsx_usb_sdmmc *host = container_of(led, in rtsx_usb_led_control() local
1304 if (host->host_removal) in rtsx_usb_led_control()
1307 host->led.brightness = brightness; in rtsx_usb_led_control()
1308 schedule_work(&host->led_work); in rtsx_usb_led_control()
1313 struct rtsx_usb_sdmmc *host = in rtsx_usb_update_led() local
1315 struct rtsx_ucr *ucr = host->ucr; in rtsx_usb_update_led()
1319 if (host->led.brightness == LED_OFF) in rtsx_usb_update_led()
1328 static void rtsx_usb_init_host(struct rtsx_usb_sdmmc *host) in rtsx_usb_init_host() argument
1330 struct mmc_host *mmc = host->mmc; in rtsx_usb_init_host()
1350 host->power_mode = MMC_POWER_OFF; in rtsx_usb_init_host()
1356 struct rtsx_usb_sdmmc *host; in rtsx_usb_sdmmc_drv_probe() local
1368 mmc = mmc_alloc_host(sizeof(*host), &pdev->dev); in rtsx_usb_sdmmc_drv_probe()
1372 host = mmc_priv(mmc); in rtsx_usb_sdmmc_drv_probe()
1373 host->ucr = ucr; in rtsx_usb_sdmmc_drv_probe()
1374 host->mmc = mmc; in rtsx_usb_sdmmc_drv_probe()
1375 host->pdev = pdev; in rtsx_usb_sdmmc_drv_probe()
1376 platform_set_drvdata(pdev, host); in rtsx_usb_sdmmc_drv_probe()
1378 mutex_init(&host->host_mutex); in rtsx_usb_sdmmc_drv_probe()
1379 rtsx_usb_init_host(host); in rtsx_usb_sdmmc_drv_probe()
1383 snprintf(host->led_name, sizeof(host->led_name), in rtsx_usb_sdmmc_drv_probe()
1385 host->led.name = host->led_name; in rtsx_usb_sdmmc_drv_probe()
1386 host->led.brightness = LED_OFF; in rtsx_usb_sdmmc_drv_probe()
1387 host->led.default_trigger = mmc_hostname(mmc); in rtsx_usb_sdmmc_drv_probe()
1388 host->led.brightness_set = rtsx_usb_led_control; in rtsx_usb_sdmmc_drv_probe()
1390 err = led_classdev_register(mmc_dev(mmc), &host->led); in rtsx_usb_sdmmc_drv_probe()
1394 INIT_WORK(&host->led_work, rtsx_usb_update_led); in rtsx_usb_sdmmc_drv_probe()
1404 struct rtsx_usb_sdmmc *host = platform_get_drvdata(pdev); in rtsx_usb_sdmmc_drv_remove() local
1407 if (!host) in rtsx_usb_sdmmc_drv_remove()
1410 mmc = host->mmc; in rtsx_usb_sdmmc_drv_remove()
1411 host->host_removal = true; in rtsx_usb_sdmmc_drv_remove()
1413 mutex_lock(&host->host_mutex); in rtsx_usb_sdmmc_drv_remove()
1414 if (host->mrq) { in rtsx_usb_sdmmc_drv_remove()
1418 host->mrq->cmd->error = -ENOMEDIUM; in rtsx_usb_sdmmc_drv_remove()
1419 if (host->mrq->stop) in rtsx_usb_sdmmc_drv_remove()
1420 host->mrq->stop->error = -ENOMEDIUM; in rtsx_usb_sdmmc_drv_remove()
1421 mmc_request_done(mmc, host->mrq); in rtsx_usb_sdmmc_drv_remove()
1423 mutex_unlock(&host->host_mutex); in rtsx_usb_sdmmc_drv_remove()
1428 cancel_work_sync(&host->led_work); in rtsx_usb_sdmmc_drv_remove()
1429 led_classdev_unregister(&host->led); in rtsx_usb_sdmmc_drv_remove()