Lines Matching refs:host
63 static inline struct device *sdmmc_dev(struct realtek_pci_sdmmc *host) in sdmmc_dev() argument
65 return &(host->pdev->dev); in sdmmc_dev()
68 static inline void sd_clear_error(struct realtek_pci_sdmmc *host) in sd_clear_error() argument
70 rtsx_pci_write_register(host->pcr, CARD_STOP, in sd_clear_error()
75 static void dump_reg_range(struct realtek_pci_sdmmc *host, u16 start, u16 end) in dump_reg_range() argument
87 rtsx_pci_read_register(host->pcr, start + i + j, in dump_reg_range()
89 dev_dbg(sdmmc_dev(host), "0x%04X(%d): %8ph\n", in dump_reg_range()
94 static void sd_print_debug_regs(struct realtek_pci_sdmmc *host) in sd_print_debug_regs() argument
96 dump_reg_range(host, 0xFDA0, 0xFDB3); in sd_print_debug_regs()
97 dump_reg_range(host, 0xFD52, 0xFD69); in sd_print_debug_regs()
100 #define sd_print_debug_regs(host) argument
103 static inline int sd_get_cd_int(struct realtek_pci_sdmmc *host) in sd_get_cd_int() argument
105 return rtsx_pci_readl(host->pcr, RTSX_BIPR) & SD_EXIST; in sd_get_cd_int()
160 static int sd_pre_dma_transfer(struct realtek_pci_sdmmc *host, in sd_pre_dma_transfer() argument
163 struct rtsx_pcr *pcr = host->pcr; in sd_pre_dma_transfer()
168 if (!pre && data->host_cookie && data->host_cookie != host->cookie) { in sd_pre_dma_transfer()
169 dev_err(sdmmc_dev(host), in sd_pre_dma_transfer()
171 data->host_cookie, host->cookie); in sd_pre_dma_transfer()
175 if (pre || data->host_cookie != host->cookie) { in sd_pre_dma_transfer()
178 count = host->cookie_sg_count; in sd_pre_dma_transfer()
183 host->cookie_sg_count = count; in sd_pre_dma_transfer()
184 if (++host->cookie < 0) in sd_pre_dma_transfer()
185 host->cookie = 1; in sd_pre_dma_transfer()
186 data->host_cookie = host->cookie; in sd_pre_dma_transfer()
188 host->sg_count = count; in sd_pre_dma_transfer()
197 struct realtek_pci_sdmmc *host = mmc_priv(mmc); in sdmmc_pre_req() local
201 dev_err(sdmmc_dev(host), in sdmmc_pre_req()
207 sd_pre_dma_transfer(host, data, true); in sdmmc_pre_req()
208 dev_dbg(sdmmc_dev(host), "pre dma sg: %d\n", host->cookie_sg_count); in sdmmc_pre_req()
214 struct realtek_pci_sdmmc *host = mmc_priv(mmc); in sdmmc_post_req() local
215 struct rtsx_pcr *pcr = host->pcr; in sdmmc_post_req()
223 static void sd_send_cmd_get_rsp(struct realtek_pci_sdmmc *host, in sd_send_cmd_get_rsp() argument
226 struct rtsx_pcr *pcr = host->pcr; in sd_send_cmd_get_rsp()
237 dev_dbg(sdmmc_dev(host), "%s: SD/MMC CMD %d, arg = 0x%08x\n", in sd_send_cmd_get_rsp()
283 sd_print_debug_regs(host); in sd_send_cmd_get_rsp()
284 sd_clear_error(host); in sd_send_cmd_get_rsp()
285 dev_dbg(sdmmc_dev(host), in sd_send_cmd_get_rsp()
301 dev_dbg(sdmmc_dev(host), "Invalid response bit\n"); in sd_send_cmd_get_rsp()
309 dev_dbg(sdmmc_dev(host), "CRC7 error\n"); in sd_send_cmd_get_rsp()
324 dev_dbg(sdmmc_dev(host), "cmd->resp[%d] = 0x%08x\n", in sd_send_cmd_get_rsp()
329 dev_dbg(sdmmc_dev(host), "cmd->resp[0] = 0x%08x\n", in sd_send_cmd_get_rsp()
341 static int sd_read_data(struct realtek_pci_sdmmc *host, struct mmc_command *cmd, in sd_read_data() argument
344 struct rtsx_pcr *pcr = host->pcr; in sd_read_data()
348 dev_dbg(sdmmc_dev(host), "%s: SD/MMC CMD %d, arg = 0x%08x\n", in sd_read_data()
376 sd_print_debug_regs(host); in sd_read_data()
377 dev_dbg(sdmmc_dev(host), in sd_read_data()
385 dev_dbg(sdmmc_dev(host), in sd_read_data()
394 static int sd_write_data(struct realtek_pci_sdmmc *host, in sd_write_data() argument
398 struct rtsx_pcr *pcr = host->pcr; in sd_write_data()
401 dev_dbg(sdmmc_dev(host), "%s: SD/MMC CMD %d, arg = 0x%08x\n", in sd_write_data()
407 sd_send_cmd_get_rsp(host, cmd); in sd_write_data()
414 dev_dbg(sdmmc_dev(host), in sd_write_data()
432 sd_print_debug_regs(host); in sd_write_data()
433 dev_dbg(sdmmc_dev(host), in sd_write_data()
441 static int sd_read_long_data(struct realtek_pci_sdmmc *host, in sd_read_long_data() argument
444 struct rtsx_pcr *pcr = host->pcr; in sd_read_long_data()
445 struct mmc_host *mmc = host->mmc; in sd_read_long_data()
455 dev_dbg(sdmmc_dev(host), "%s: SD/MMC CMD %d, arg = 0x%08x\n", in sd_read_long_data()
489 err = rtsx_pci_dma_transfer(pcr, data->sg, host->sg_count, 1, 10000); in sd_read_long_data()
491 sd_print_debug_regs(host); in sd_read_long_data()
492 sd_clear_error(host); in sd_read_long_data()
499 static int sd_write_long_data(struct realtek_pci_sdmmc *host, in sd_write_long_data() argument
502 struct rtsx_pcr *pcr = host->pcr; in sd_write_long_data()
503 struct mmc_host *mmc = host->mmc; in sd_write_long_data()
512 sd_send_cmd_get_rsp(host, cmd); in sd_write_long_data()
516 dev_dbg(sdmmc_dev(host), "%s: SD/MMC CMD %d, arg = 0x%08x\n", in sd_write_long_data()
547 err = rtsx_pci_dma_transfer(pcr, data->sg, host->sg_count, 0, 10000); in sd_write_long_data()
549 sd_clear_error(host); in sd_write_long_data()
556 static int sd_rw_multi(struct realtek_pci_sdmmc *host, struct mmc_request *mrq) in sd_rw_multi() argument
560 if (host->sg_count < 0) { in sd_rw_multi()
561 data->error = host->sg_count; in sd_rw_multi()
562 dev_dbg(sdmmc_dev(host), "%s: sg_count = %d is invalid\n", in sd_rw_multi()
563 __func__, host->sg_count); in sd_rw_multi()
568 return sd_read_long_data(host, mrq); in sd_rw_multi()
570 return sd_write_long_data(host, mrq); in sd_rw_multi()
573 static inline void sd_enable_initial_mode(struct realtek_pci_sdmmc *host) in sd_enable_initial_mode() argument
575 rtsx_pci_write_register(host->pcr, SD_CFG1, in sd_enable_initial_mode()
579 static inline void sd_disable_initial_mode(struct realtek_pci_sdmmc *host) in sd_disable_initial_mode() argument
581 rtsx_pci_write_register(host->pcr, SD_CFG1, in sd_disable_initial_mode()
585 static void sd_normal_rw(struct realtek_pci_sdmmc *host, in sd_normal_rw() argument
599 if (host->initial_mode) in sd_normal_rw()
600 sd_disable_initial_mode(host); in sd_normal_rw()
602 cmd->error = sd_read_data(host, cmd, (u16)data->blksz, buf, in sd_normal_rw()
605 if (host->initial_mode) in sd_normal_rw()
606 sd_enable_initial_mode(host); in sd_normal_rw()
612 cmd->error = sd_write_data(host, cmd, (u16)data->blksz, buf, in sd_normal_rw()
619 static int sd_change_phase(struct realtek_pci_sdmmc *host, in sd_change_phase() argument
622 struct rtsx_pcr *pcr = host->pcr; in sd_change_phase()
625 dev_dbg(sdmmc_dev(host), "%s(%s): sample_point = %d\n", in sd_change_phase()
667 static u8 sd_search_final_phase(struct realtek_pci_sdmmc *host, u32 phase_map) in sd_search_final_phase() argument
674 dev_err(sdmmc_dev(host), "phase error: [map:%x]\n", phase_map); in sd_search_final_phase()
688 dev_dbg(sdmmc_dev(host), "phase: [map:%x] [maxlen:%d] [final:%d]\n", in sd_search_final_phase()
694 static void sd_wait_data_idle(struct realtek_pci_sdmmc *host) in sd_wait_data_idle() argument
700 err = rtsx_pci_read_register(host->pcr, SD_DATA_STATE, &val); in sd_wait_data_idle()
708 static int sd_tuning_rx_cmd(struct realtek_pci_sdmmc *host, in sd_tuning_rx_cmd() argument
714 err = sd_change_phase(host, sample_point, true); in sd_tuning_rx_cmd()
719 err = sd_read_data(host, &cmd, 0x40, NULL, 0, 100); in sd_tuning_rx_cmd()
722 sd_wait_data_idle(host); in sd_tuning_rx_cmd()
723 sd_clear_error(host); in sd_tuning_rx_cmd()
730 static int sd_tuning_phase(struct realtek_pci_sdmmc *host, in sd_tuning_phase() argument
737 err = sd_tuning_rx_cmd(host, opcode, (u8)i); in sd_tuning_phase()
748 static int sd_tuning_rx(struct realtek_pci_sdmmc *host, u8 opcode) in sd_tuning_rx() argument
755 err = sd_tuning_phase(host, opcode, &(raw_phase_map[i])); in sd_tuning_rx()
765 dev_dbg(sdmmc_dev(host), "RX raw_phase_map[%d] = 0x%08x\n", in sd_tuning_rx()
769 dev_dbg(sdmmc_dev(host), "RX phase_map = 0x%08x\n", phase_map); in sd_tuning_rx()
772 final_phase = sd_search_final_phase(host, phase_map); in sd_tuning_rx()
776 err = sd_change_phase(host, final_phase, true); in sd_tuning_rx()
801 struct realtek_pci_sdmmc *host = container_of(work, in sd_request() local
803 struct rtsx_pcr *pcr = host->pcr; in sd_request()
805 struct mmc_host *mmc = host->mmc; in sd_request()
806 struct mmc_request *mrq = host->mrq; in sd_request()
813 if (host->eject || !sd_get_cd_int(host)) { in sd_request()
818 err = rtsx_pci_card_exclusive_check(host->pcr, RTSX_SD_CARD); in sd_request()
828 rtsx_pci_switch_clock(pcr, host->clock, host->ssc_depth, in sd_request()
829 host->initial_mode, host->double_clk, host->vpclk); in sd_request()
834 mutex_lock(&host->host_mutex); in sd_request()
835 host->mrq = mrq; in sd_request()
836 mutex_unlock(&host->host_mutex); in sd_request()
842 sd_send_cmd_get_rsp(host, cmd); in sd_request()
844 cmd->error = sd_rw_multi(host, mrq); in sd_request()
845 if (!host->using_cookie) in sd_request()
846 sdmmc_post_req(host->mmc, host->mrq, 0); in sd_request()
849 sd_send_cmd_get_rsp(host, mrq->stop); in sd_request()
851 sd_normal_rw(host, mrq); in sd_request()
865 dev_dbg(sdmmc_dev(host), "CMD %d 0x%08x error(%d)\n", in sd_request()
869 mutex_lock(&host->host_mutex); in sd_request()
870 host->mrq = NULL; in sd_request()
871 mutex_unlock(&host->host_mutex); in sd_request()
878 struct realtek_pci_sdmmc *host = mmc_priv(mmc); in sdmmc_request() local
881 mutex_lock(&host->host_mutex); in sdmmc_request()
882 host->mrq = mrq; in sdmmc_request()
883 mutex_unlock(&host->host_mutex); in sdmmc_request()
886 host->using_cookie = sd_pre_dma_transfer(host, data, false); in sdmmc_request()
888 queue_work(host->workq, &host->work); in sdmmc_request()
891 static int sd_set_bus_width(struct realtek_pci_sdmmc *host, in sd_set_bus_width() argument
902 err = rtsx_pci_write_register(host->pcr, SD_CFG1, in sd_set_bus_width()
908 static int sd_power_on(struct realtek_pci_sdmmc *host) in sd_power_on() argument
910 struct rtsx_pcr *pcr = host->pcr; in sd_power_on()
913 if (host->power_state == SDMMC_POWER_ON) in sd_power_on()
938 host->power_state = SDMMC_POWER_ON; in sd_power_on()
942 static int sd_power_off(struct realtek_pci_sdmmc *host) in sd_power_off() argument
944 struct rtsx_pcr *pcr = host->pcr; in sd_power_off()
947 host->power_state = SDMMC_POWER_OFF; in sd_power_off()
965 static int sd_set_power_mode(struct realtek_pci_sdmmc *host, in sd_set_power_mode() argument
971 err = sd_power_off(host); in sd_set_power_mode()
973 err = sd_power_on(host); in sd_set_power_mode()
978 static int sd_set_timing(struct realtek_pci_sdmmc *host, unsigned char timing) in sd_set_timing() argument
980 struct rtsx_pcr *pcr = host->pcr; in sd_set_timing()
1052 struct realtek_pci_sdmmc *host = mmc_priv(mmc); in sdmmc_set_ios() local
1053 struct rtsx_pcr *pcr = host->pcr; in sdmmc_set_ios()
1055 if (host->eject) in sdmmc_set_ios()
1058 if (rtsx_pci_card_exclusive_check(host->pcr, RTSX_SD_CARD)) in sdmmc_set_ios()
1065 sd_set_bus_width(host, ios->bus_width); in sdmmc_set_ios()
1066 sd_set_power_mode(host, ios->power_mode); in sdmmc_set_ios()
1067 sd_set_timing(host, ios->timing); in sdmmc_set_ios()
1069 host->vpclk = false; in sdmmc_set_ios()
1070 host->double_clk = true; in sdmmc_set_ios()
1075 host->ssc_depth = RTSX_SSC_DEPTH_2M; in sdmmc_set_ios()
1076 host->vpclk = true; in sdmmc_set_ios()
1077 host->double_clk = false; in sdmmc_set_ios()
1082 host->ssc_depth = RTSX_SSC_DEPTH_1M; in sdmmc_set_ios()
1085 host->ssc_depth = RTSX_SSC_DEPTH_500K; in sdmmc_set_ios()
1089 host->initial_mode = (ios->clock <= 1000000) ? true : false; in sdmmc_set_ios()
1091 host->clock = ios->clock; in sdmmc_set_ios()
1092 rtsx_pci_switch_clock(pcr, ios->clock, host->ssc_depth, in sdmmc_set_ios()
1093 host->initial_mode, host->double_clk, host->vpclk); in sdmmc_set_ios()
1100 struct realtek_pci_sdmmc *host = mmc_priv(mmc); in sdmmc_get_ro() local
1101 struct rtsx_pcr *pcr = host->pcr; in sdmmc_get_ro()
1105 if (host->eject) in sdmmc_get_ro()
1114 dev_dbg(sdmmc_dev(host), "%s: RTSX_BIPR = 0x%08x\n", __func__, val); in sdmmc_get_ro()
1125 struct realtek_pci_sdmmc *host = mmc_priv(mmc); in sdmmc_get_cd() local
1126 struct rtsx_pcr *pcr = host->pcr; in sdmmc_get_cd()
1130 if (host->eject) in sdmmc_get_cd()
1139 dev_dbg(sdmmc_dev(host), "%s: RTSX_BIPR = 0x%08x\n", __func__, val); in sdmmc_get_cd()
1148 static int sd_wait_voltage_stable_1(struct realtek_pci_sdmmc *host) in sd_wait_voltage_stable_1() argument
1150 struct rtsx_pcr *pcr = host->pcr; in sd_wait_voltage_stable_1()
1181 static int sd_wait_voltage_stable_2(struct realtek_pci_sdmmc *host) in sd_wait_voltage_stable_2() argument
1183 struct rtsx_pcr *pcr = host->pcr; in sd_wait_voltage_stable_2()
1210 dev_dbg(sdmmc_dev(host), in sd_wait_voltage_stable_2()
1223 struct realtek_pci_sdmmc *host = mmc_priv(mmc); in sdmmc_switch_voltage() local
1224 struct rtsx_pcr *pcr = host->pcr; in sdmmc_switch_voltage()
1228 dev_dbg(sdmmc_dev(host), "%s: signal_voltage = %d\n", in sdmmc_switch_voltage()
1231 if (host->eject) in sdmmc_switch_voltage()
1234 err = rtsx_pci_card_exclusive_check(host->pcr, RTSX_SD_CARD); in sdmmc_switch_voltage()
1248 err = sd_wait_voltage_stable_1(host); in sdmmc_switch_voltage()
1258 err = sd_wait_voltage_stable_2(host); in sdmmc_switch_voltage()
1275 struct realtek_pci_sdmmc *host = mmc_priv(mmc); in sdmmc_execute_tuning() local
1276 struct rtsx_pcr *pcr = host->pcr; in sdmmc_execute_tuning()
1279 if (host->eject) in sdmmc_execute_tuning()
1282 err = rtsx_pci_card_exclusive_check(host->pcr, RTSX_SD_CARD); in sdmmc_execute_tuning()
1293 err = sd_change_phase(host, SDR104_TX_PHASE(pcr), false); in sdmmc_execute_tuning()
1297 err = sd_change_phase(host, SDR50_TX_PHASE(pcr), false); in sdmmc_execute_tuning()
1301 err = sd_change_phase(host, DDR50_TX_PHASE(pcr), false); in sdmmc_execute_tuning()
1314 err = sd_tuning_rx(host, opcode); in sdmmc_execute_tuning()
1316 err = sd_change_phase(host, DDR50_RX_PHASE(pcr), true); in sdmmc_execute_tuning()
1335 static void init_extra_caps(struct realtek_pci_sdmmc *host) in init_extra_caps() argument
1337 struct mmc_host *mmc = host->mmc; in init_extra_caps()
1338 struct rtsx_pcr *pcr = host->pcr; in init_extra_caps()
1340 dev_dbg(sdmmc_dev(host), "pcr->extra_caps = 0x%x\n", pcr->extra_caps); in init_extra_caps()
1354 static void realtek_init_host(struct realtek_pci_sdmmc *host) in realtek_init_host() argument
1356 struct mmc_host *mmc = host->mmc; in realtek_init_host()
1369 init_extra_caps(host); in realtek_init_host()
1380 struct realtek_pci_sdmmc *host = platform_get_drvdata(pdev); in rtsx_pci_sdmmc_card_event() local
1382 host->cookie = -1; in rtsx_pci_sdmmc_card_event()
1383 mmc_detect_change(host->mmc, 0); in rtsx_pci_sdmmc_card_event()
1389 struct realtek_pci_sdmmc *host; in rtsx_pci_sdmmc_drv_probe() local
1402 mmc = mmc_alloc_host(sizeof(*host), &pdev->dev); in rtsx_pci_sdmmc_drv_probe()
1406 host = mmc_priv(mmc); in rtsx_pci_sdmmc_drv_probe()
1407 host->workq = create_singlethread_workqueue(SDMMC_WORKQ_NAME); in rtsx_pci_sdmmc_drv_probe()
1408 if (!host->workq) { in rtsx_pci_sdmmc_drv_probe()
1412 host->pcr = pcr; in rtsx_pci_sdmmc_drv_probe()
1413 host->mmc = mmc; in rtsx_pci_sdmmc_drv_probe()
1414 host->pdev = pdev; in rtsx_pci_sdmmc_drv_probe()
1415 host->cookie = -1; in rtsx_pci_sdmmc_drv_probe()
1416 host->power_state = SDMMC_POWER_OFF; in rtsx_pci_sdmmc_drv_probe()
1417 INIT_WORK(&host->work, sd_request); in rtsx_pci_sdmmc_drv_probe()
1418 platform_set_drvdata(pdev, host); in rtsx_pci_sdmmc_drv_probe()
1422 mutex_init(&host->host_mutex); in rtsx_pci_sdmmc_drv_probe()
1424 realtek_init_host(host); in rtsx_pci_sdmmc_drv_probe()
1433 struct realtek_pci_sdmmc *host = platform_get_drvdata(pdev); in rtsx_pci_sdmmc_drv_remove() local
1437 if (!host) in rtsx_pci_sdmmc_drv_remove()
1440 pcr = host->pcr; in rtsx_pci_sdmmc_drv_remove()
1443 mmc = host->mmc; in rtsx_pci_sdmmc_drv_remove()
1445 cancel_work_sync(&host->work); in rtsx_pci_sdmmc_drv_remove()
1447 mutex_lock(&host->host_mutex); in rtsx_pci_sdmmc_drv_remove()
1448 if (host->mrq) { in rtsx_pci_sdmmc_drv_remove()
1455 host->mrq->cmd->error = -ENOMEDIUM; in rtsx_pci_sdmmc_drv_remove()
1456 if (host->mrq->stop) in rtsx_pci_sdmmc_drv_remove()
1457 host->mrq->stop->error = -ENOMEDIUM; in rtsx_pci_sdmmc_drv_remove()
1458 mmc_request_done(mmc, host->mrq); in rtsx_pci_sdmmc_drv_remove()
1460 mutex_unlock(&host->host_mutex); in rtsx_pci_sdmmc_drv_remove()
1463 host->eject = true; in rtsx_pci_sdmmc_drv_remove()
1465 flush_workqueue(host->workq); in rtsx_pci_sdmmc_drv_remove()
1466 destroy_workqueue(host->workq); in rtsx_pci_sdmmc_drv_remove()
1467 host->workq = NULL; in rtsx_pci_sdmmc_drv_remove()