Lines Matching defs:host
16 #include <linux/mmc/host.h>
47 static inline struct device *sdmmc_dev(struct realtek_pci_sdmmc *host)
49 return &(host->pdev->dev);
52 static inline void sd_clear_error(struct realtek_pci_sdmmc *host)
54 rtsx_pci_write_register(host->pcr, CARD_STOP,
59 static void dump_reg_range(struct realtek_pci_sdmmc *host, u16 start, u16 end)
71 rtsx_pci_read_register(host->pcr, start + i + j,
73 dev_dbg(sdmmc_dev(host), "0x%04X(%d): %8ph\n",
78 static void sd_print_debug_regs(struct realtek_pci_sdmmc *host)
80 dump_reg_range(host, 0xFDA0, 0xFDB3);
81 dump_reg_range(host, 0xFD52, 0xFD69);
84 #define sd_print_debug_regs(host)
87 static inline int sd_get_cd_int(struct realtek_pci_sdmmc *host)
89 return rtsx_pci_readl(host->pcr, RTSX_BIPR) & SD_EXIST;
144 static int sd_pre_dma_transfer(struct realtek_pci_sdmmc *host,
147 struct rtsx_pcr *pcr = host->pcr;
152 if (!pre && data->host_cookie && data->host_cookie != host->cookie) {
153 dev_err(sdmmc_dev(host),
154 "error: data->host_cookie = %d, host->cookie = %d\n",
155 data->host_cookie, host->cookie);
159 if (pre || data->host_cookie != host->cookie) {
162 count = host->cookie_sg_count;
167 host->cookie_sg_count = count;
168 if (++host->cookie < 0)
169 host->cookie = 1;
170 data->host_cookie = host->cookie;
172 host->sg_count = count;
180 struct realtek_pci_sdmmc *host = mmc_priv(mmc);
184 dev_err(sdmmc_dev(host),
190 sd_pre_dma_transfer(host, data, true);
191 dev_dbg(sdmmc_dev(host), "pre dma sg: %d\n", host->cookie_sg_count);
197 struct realtek_pci_sdmmc *host = mmc_priv(mmc);
198 struct rtsx_pcr *pcr = host->pcr;
206 static void sd_send_cmd_get_rsp(struct realtek_pci_sdmmc *host,
209 struct rtsx_pcr *pcr = host->pcr;
220 dev_dbg(sdmmc_dev(host), "%s: SD/MMC CMD %d, arg = 0x%08x\n",
266 sd_print_debug_regs(host);
267 sd_clear_error(host);
268 dev_dbg(sdmmc_dev(host),
284 dev_dbg(sdmmc_dev(host), "Invalid response bit\n");
292 dev_dbg(sdmmc_dev(host), "CRC7 error\n");
307 dev_dbg(sdmmc_dev(host), "cmd->resp[%d] = 0x%08x\n",
312 dev_dbg(sdmmc_dev(host), "cmd->resp[0] = 0x%08x\n",
324 static int sd_read_data(struct realtek_pci_sdmmc *host, struct mmc_command *cmd,
327 struct rtsx_pcr *pcr = host->pcr;
331 dev_dbg(sdmmc_dev(host), "%s: SD/MMC CMD %d, arg = 0x%08x\n",
359 sd_print_debug_regs(host);
360 dev_dbg(sdmmc_dev(host),
368 dev_dbg(sdmmc_dev(host),
377 static int sd_write_data(struct realtek_pci_sdmmc *host,
381 struct rtsx_pcr *pcr = host->pcr;
384 dev_dbg(sdmmc_dev(host), "%s: SD/MMC CMD %d, arg = 0x%08x\n",
390 sd_send_cmd_get_rsp(host, cmd);
397 dev_dbg(sdmmc_dev(host),
415 sd_print_debug_regs(host);
416 dev_dbg(sdmmc_dev(host),
424 static int sd_read_long_data(struct realtek_pci_sdmmc *host,
427 struct rtsx_pcr *pcr = host->pcr;
428 struct mmc_host *mmc = host->mmc;
438 dev_dbg(sdmmc_dev(host), "%s: SD/MMC CMD %d, arg = 0x%08x\n",
472 err = rtsx_pci_dma_transfer(pcr, data->sg, host->sg_count, 1, 10000);
474 sd_print_debug_regs(host);
475 sd_clear_error(host);
482 static int sd_write_long_data(struct realtek_pci_sdmmc *host,
485 struct rtsx_pcr *pcr = host->pcr;
486 struct mmc_host *mmc = host->mmc;
495 sd_send_cmd_get_rsp(host, cmd);
499 dev_dbg(sdmmc_dev(host), "%s: SD/MMC CMD %d, arg = 0x%08x\n",
530 err = rtsx_pci_dma_transfer(pcr, data->sg, host->sg_count, 0, 10000);
532 sd_clear_error(host);
539 static inline void sd_enable_initial_mode(struct realtek_pci_sdmmc *host)
541 rtsx_pci_write_register(host->pcr, SD_CFG1,
545 static inline void sd_disable_initial_mode(struct realtek_pci_sdmmc *host)
547 rtsx_pci_write_register(host->pcr, SD_CFG1,
551 static int sd_rw_multi(struct realtek_pci_sdmmc *host, struct mmc_request *mrq)
556 if (host->sg_count < 0) {
557 data->error = host->sg_count;
558 dev_dbg(sdmmc_dev(host), "%s: sg_count = %d is invalid\n",
559 __func__, host->sg_count);
564 if (host->initial_mode)
565 sd_disable_initial_mode(host);
567 err = sd_read_long_data(host, mrq);
569 if (host->initial_mode)
570 sd_enable_initial_mode(host);
575 return sd_write_long_data(host, mrq);
578 static void sd_normal_rw(struct realtek_pci_sdmmc *host,
592 if (host->initial_mode)
593 sd_disable_initial_mode(host);
595 cmd->error = sd_read_data(host, cmd, (u16)data->blksz, buf,
598 if (host->initial_mode)
599 sd_enable_initial_mode(host);
605 cmd->error = sd_write_data(host, cmd, (u16)data->blksz, buf,
612 static int sd_change_phase(struct realtek_pci_sdmmc *host,
615 struct rtsx_pcr *pcr = host->pcr;
617 dev_dbg(sdmmc_dev(host), "%s(%s): sample_point = %d\n",
656 static u8 sd_search_final_phase(struct realtek_pci_sdmmc *host, u32 phase_map)
663 dev_err(sdmmc_dev(host), "phase error: [map:%x]\n", phase_map);
677 dev_dbg(sdmmc_dev(host), "phase: [map:%x] [maxlen:%d] [final:%d]\n",
683 static void sd_wait_data_idle(struct realtek_pci_sdmmc *host)
689 rtsx_pci_read_register(host->pcr, SD_DATA_STATE, &val);
697 static int sd_tuning_rx_cmd(struct realtek_pci_sdmmc *host,
702 struct rtsx_pcr *pcr = host->pcr;
704 sd_change_phase(host, sample_point, true);
710 err = sd_read_data(host, &cmd, 0x40, NULL, 0, 100);
713 sd_wait_data_idle(host);
714 sd_clear_error(host);
724 static int sd_tuning_phase(struct realtek_pci_sdmmc *host,
731 err = sd_tuning_rx_cmd(host, opcode, (u8)i);
742 static int sd_tuning_rx(struct realtek_pci_sdmmc *host, u8 opcode)
749 err = sd_tuning_phase(host, opcode, &(raw_phase_map[i]));
759 dev_dbg(sdmmc_dev(host), "RX raw_phase_map[%d] = 0x%08x\n",
763 dev_dbg(sdmmc_dev(host), "RX phase_map = 0x%08x\n", phase_map);
766 final_phase = sd_search_final_phase(host, phase_map);
770 err = sd_change_phase(host, final_phase, true);
795 struct realtek_pci_sdmmc *host = container_of(work,
797 struct rtsx_pcr *pcr = host->pcr;
799 struct mmc_host *mmc = host->mmc;
800 struct mmc_request *mrq = host->mrq;
807 if (host->eject || !sd_get_cd_int(host)) {
812 err = rtsx_pci_card_exclusive_check(host->pcr, RTSX_SD_CARD);
822 rtsx_pci_switch_clock(pcr, host->clock, host->ssc_depth,
823 host->initial_mode, host->double_clk, host->vpclk);
828 mutex_lock(&host->host_mutex);
829 host->mrq = mrq;
830 mutex_unlock(&host->host_mutex);
836 sd_send_cmd_get_rsp(host, cmd);
838 cmd->error = sd_rw_multi(host, mrq);
839 if (!host->using_cookie)
840 sdmmc_post_req(host->mmc, host->mrq, 0);
843 sd_send_cmd_get_rsp(host, mrq->stop);
845 sd_normal_rw(host, mrq);
859 dev_dbg(sdmmc_dev(host), "CMD %d 0x%08x error(%d)\n",
863 mutex_lock(&host->host_mutex);
864 host->mrq = NULL;
865 mutex_unlock(&host->host_mutex);
872 struct realtek_pci_sdmmc *host = mmc_priv(mmc);
875 mutex_lock(&host->host_mutex);
876 host->mrq = mrq;
877 mutex_unlock(&host->host_mutex);
880 host->using_cookie = sd_pre_dma_transfer(host, data, false);
882 schedule_work(&host->work);
885 static int sd_set_bus_width(struct realtek_pci_sdmmc *host,
896 err = rtsx_pci_write_register(host->pcr, SD_CFG1,
902 static int sd_power_on(struct realtek_pci_sdmmc *host, unsigned char power_mode)
904 struct rtsx_pcr *pcr = host->pcr;
907 if (host->prev_power_state == MMC_POWER_ON)
910 if (host->prev_power_state == MMC_POWER_UP) {
945 host->prev_power_state = power_mode;
949 static int sd_power_off(struct realtek_pci_sdmmc *host)
951 struct rtsx_pcr *pcr = host->pcr;
954 host->prev_power_state = MMC_POWER_OFF;
972 static int sd_set_power_mode(struct realtek_pci_sdmmc *host,
978 err = sd_power_off(host);
980 err = sd_power_on(host, power_mode);
985 static int sd_set_timing(struct realtek_pci_sdmmc *host, unsigned char timing)
987 struct rtsx_pcr *pcr = host->pcr;
1059 struct realtek_pci_sdmmc *host = mmc_priv(mmc);
1060 struct rtsx_pcr *pcr = host->pcr;
1062 if (host->eject)
1065 if (rtsx_pci_card_exclusive_check(host->pcr, RTSX_SD_CARD))
1072 sd_set_bus_width(host, ios->bus_width);
1073 sd_set_power_mode(host, ios->power_mode);
1074 sd_set_timing(host, ios->timing);
1076 host->vpclk = false;
1077 host->double_clk = true;
1082 host->ssc_depth = RTSX_SSC_DEPTH_2M;
1083 host->vpclk = true;
1084 host->double_clk = false;
1089 host->ssc_depth = RTSX_SSC_DEPTH_1M;
1092 host->ssc_depth = RTSX_SSC_DEPTH_500K;
1096 host->initial_mode = (ios->clock <= 1000000) ? true : false;
1098 host->clock = ios->clock;
1099 rtsx_pci_switch_clock(pcr, ios->clock, host->ssc_depth,
1100 host->initial_mode, host->double_clk, host->vpclk);
1107 struct realtek_pci_sdmmc *host = mmc_priv(mmc);
1108 struct rtsx_pcr *pcr = host->pcr;
1112 if (host->eject)
1121 dev_dbg(sdmmc_dev(host), "%s: RTSX_BIPR = 0x%08x\n", __func__, val);
1132 struct realtek_pci_sdmmc *host = mmc_priv(mmc);
1133 struct rtsx_pcr *pcr = host->pcr;
1137 if (host->eject)
1146 dev_dbg(sdmmc_dev(host), "%s: RTSX_BIPR = 0x%08x\n", __func__, val);
1155 static int sd_wait_voltage_stable_1(struct realtek_pci_sdmmc *host)
1157 struct rtsx_pcr *pcr = host->pcr;
1188 static int sd_wait_voltage_stable_2(struct realtek_pci_sdmmc *host)
1190 struct rtsx_pcr *pcr = host->pcr;
1207 /* SD_CMD, SD_DAT[3:0] should be pulled high by host */
1217 dev_dbg(sdmmc_dev(host),
1230 struct realtek_pci_sdmmc *host = mmc_priv(mmc);
1231 struct rtsx_pcr *pcr = host->pcr;
1235 dev_dbg(sdmmc_dev(host), "%s: signal_voltage = %d\n",
1238 if (host->eject)
1241 err = rtsx_pci_card_exclusive_check(host->pcr, RTSX_SD_CARD);
1255 err = sd_wait_voltage_stable_1(host);
1265 err = sd_wait_voltage_stable_2(host);
1282 struct realtek_pci_sdmmc *host = mmc_priv(mmc);
1283 struct rtsx_pcr *pcr = host->pcr;
1286 if (host->eject)
1289 err = rtsx_pci_card_exclusive_check(host->pcr, RTSX_SD_CARD);
1300 err = sd_change_phase(host, SDR104_TX_PHASE(pcr), false);
1304 err = sd_change_phase(host, SDR50_TX_PHASE(pcr), false);
1308 err = sd_change_phase(host, DDR50_TX_PHASE(pcr), false);
1321 err = sd_tuning_rx(host, opcode);
1323 err = sd_change_phase(host, DDR50_RX_PHASE(pcr), true);
1342 static void init_extra_caps(struct realtek_pci_sdmmc *host)
1344 struct mmc_host *mmc = host->mmc;
1345 struct rtsx_pcr *pcr = host->pcr;
1347 dev_dbg(sdmmc_dev(host), "pcr->extra_caps = 0x%x\n", pcr->extra_caps);
1363 static void realtek_init_host(struct realtek_pci_sdmmc *host)
1365 struct mmc_host *mmc = host->mmc;
1378 init_extra_caps(host);
1389 struct realtek_pci_sdmmc *host = platform_get_drvdata(pdev);
1391 host->cookie = -1;
1392 mmc_detect_change(host->mmc, 0);
1398 struct realtek_pci_sdmmc *host;
1411 mmc = mmc_alloc_host(sizeof(*host), &pdev->dev);
1415 host = mmc_priv(mmc);
1416 host->pcr = pcr;
1418 host->mmc = mmc;
1419 host->pdev = pdev;
1420 host->cookie = -1;
1421 host->prev_power_state = MMC_POWER_OFF;
1422 INIT_WORK(&host->work, sd_request);
1423 platform_set_drvdata(pdev, host);
1427 mutex_init(&host->host_mutex);
1429 realtek_init_host(host);
1438 struct realtek_pci_sdmmc *host = platform_get_drvdata(pdev);
1442 if (!host)
1445 pcr = host->pcr;
1448 mmc = host->mmc;
1450 cancel_work_sync(&host->work);
1452 mutex_lock(&host->host_mutex);
1453 if (host->mrq) {
1460 host->mrq->cmd->error = -ENOMEDIUM;
1461 if (host->mrq->stop)
1462 host->mrq->stop->error = -ENOMEDIUM;
1463 mmc_request_done(mmc, host->mrq);
1465 mutex_unlock(&host->host_mutex);
1468 host->eject = true;
1470 flush_work(&host->work);