Lines Matching defs:host

17 #include <linux/mmc/host.h>
51 static inline struct device *sdmmc_dev(struct realtek_pci_sdmmc *host)
53 return &(host->pdev->dev);
56 static inline void sd_clear_error(struct realtek_pci_sdmmc *host)
58 rtsx_pci_write_register(host->pcr, CARD_STOP,
63 static void dump_reg_range(struct realtek_pci_sdmmc *host, u16 start, u16 end)
75 rtsx_pci_read_register(host->pcr, start + i + j,
77 dev_dbg(sdmmc_dev(host), "0x%04X(%d): %8ph\n",
82 static void sd_print_debug_regs(struct realtek_pci_sdmmc *host)
84 dump_reg_range(host, 0xFDA0, 0xFDB3);
85 dump_reg_range(host, 0xFD52, 0xFD69);
88 #define sd_print_debug_regs(host)
91 static inline int sd_get_cd_int(struct realtek_pci_sdmmc *host)
93 return rtsx_pci_readl(host->pcr, RTSX_BIPR) & SD_EXIST;
148 static int sd_pre_dma_transfer(struct realtek_pci_sdmmc *host,
151 struct rtsx_pcr *pcr = host->pcr;
156 if (!pre && data->host_cookie && data->host_cookie != host->cookie) {
157 dev_err(sdmmc_dev(host),
158 "error: data->host_cookie = %d, host->cookie = %d\n",
159 data->host_cookie, host->cookie);
163 if (pre || data->host_cookie != host->cookie) {
166 count = host->cookie_sg_count;
171 host->cookie_sg_count = count;
172 if (++host->cookie < 0)
173 host->cookie = 1;
174 data->host_cookie = host->cookie;
176 host->sg_count = count;
184 struct realtek_pci_sdmmc *host = mmc_priv(mmc);
188 dev_err(sdmmc_dev(host),
194 sd_pre_dma_transfer(host, data, true);
195 dev_dbg(sdmmc_dev(host), "pre dma sg: %d\n", host->cookie_sg_count);
201 struct realtek_pci_sdmmc *host = mmc_priv(mmc);
202 struct rtsx_pcr *pcr = host->pcr;
210 static void sd_send_cmd_get_rsp(struct realtek_pci_sdmmc *host,
213 struct rtsx_pcr *pcr = host->pcr;
224 dev_dbg(sdmmc_dev(host), "%s: SD/MMC CMD %d, arg = 0x%08x\n",
270 sd_print_debug_regs(host);
271 sd_clear_error(host);
272 dev_dbg(sdmmc_dev(host),
288 dev_dbg(sdmmc_dev(host), "Invalid response bit\n");
296 dev_dbg(sdmmc_dev(host), "CRC7 error\n");
311 dev_dbg(sdmmc_dev(host), "cmd->resp[%d] = 0x%08x\n",
316 dev_dbg(sdmmc_dev(host), "cmd->resp[0] = 0x%08x\n",
328 static int sd_read_data(struct realtek_pci_sdmmc *host, struct mmc_command *cmd,
331 struct rtsx_pcr *pcr = host->pcr;
335 dev_dbg(sdmmc_dev(host), "%s: SD/MMC CMD %d, arg = 0x%08x\n",
363 sd_print_debug_regs(host);
364 dev_dbg(sdmmc_dev(host),
372 dev_dbg(sdmmc_dev(host),
381 static int sd_write_data(struct realtek_pci_sdmmc *host,
385 struct rtsx_pcr *pcr = host->pcr;
388 dev_dbg(sdmmc_dev(host), "%s: SD/MMC CMD %d, arg = 0x%08x\n",
394 sd_send_cmd_get_rsp(host, cmd);
401 dev_dbg(sdmmc_dev(host),
419 sd_print_debug_regs(host);
420 dev_dbg(sdmmc_dev(host),
428 static int sd_read_long_data(struct realtek_pci_sdmmc *host,
431 struct rtsx_pcr *pcr = host->pcr;
432 struct mmc_host *mmc = host->mmc;
442 dev_dbg(sdmmc_dev(host), "%s: SD/MMC CMD %d, arg = 0x%08x\n",
476 err = rtsx_pci_dma_transfer(pcr, data->sg, host->sg_count, 1, 10000);
478 sd_print_debug_regs(host);
479 sd_clear_error(host);
486 static int sd_write_long_data(struct realtek_pci_sdmmc *host,
489 struct rtsx_pcr *pcr = host->pcr;
490 struct mmc_host *mmc = host->mmc;
499 sd_send_cmd_get_rsp(host, cmd);
503 dev_dbg(sdmmc_dev(host), "%s: SD/MMC CMD %d, arg = 0x%08x\n",
534 err = rtsx_pci_dma_transfer(pcr, data->sg, host->sg_count, 0, 10000);
536 sd_clear_error(host);
543 static inline void sd_enable_initial_mode(struct realtek_pci_sdmmc *host)
545 rtsx_pci_write_register(host->pcr, SD_CFG1,
549 static inline void sd_disable_initial_mode(struct realtek_pci_sdmmc *host)
551 rtsx_pci_write_register(host->pcr, SD_CFG1,
555 static int sd_rw_multi(struct realtek_pci_sdmmc *host, struct mmc_request *mrq)
560 if (host->sg_count < 0) {
561 data->error = host->sg_count;
562 dev_dbg(sdmmc_dev(host), "%s: sg_count = %d is invalid\n",
563 __func__, host->sg_count);
568 if (host->initial_mode)
569 sd_disable_initial_mode(host);
571 err = sd_read_long_data(host, mrq);
573 if (host->initial_mode)
574 sd_enable_initial_mode(host);
579 return sd_write_long_data(host, mrq);
582 static void sd_normal_rw(struct realtek_pci_sdmmc *host,
596 if (host->initial_mode)
597 sd_disable_initial_mode(host);
599 cmd->error = sd_read_data(host, cmd, (u16)data->blksz, buf,
602 if (host->initial_mode)
603 sd_enable_initial_mode(host);
609 cmd->error = sd_write_data(host, cmd, (u16)data->blksz, buf,
616 static int sd_change_phase(struct realtek_pci_sdmmc *host,
619 struct rtsx_pcr *pcr = host->pcr;
621 dev_dbg(sdmmc_dev(host), "%s(%s): sample_point = %d\n",
660 static u8 sd_search_final_phase(struct realtek_pci_sdmmc *host, u32 phase_map)
667 dev_err(sdmmc_dev(host), "phase error: [map:%x]\n", phase_map);
681 dev_dbg(sdmmc_dev(host), "phase: [map:%x] [maxlen:%d] [final:%d]\n",
687 static void sd_wait_data_idle(struct realtek_pci_sdmmc *host)
693 rtsx_pci_read_register(host->pcr, SD_DATA_STATE, &val);
701 static int sd_tuning_rx_cmd(struct realtek_pci_sdmmc *host,
706 struct rtsx_pcr *pcr = host->pcr;
708 sd_change_phase(host, sample_point, true);
714 err = sd_read_data(host, &cmd, 0x40, NULL, 0, 100);
717 sd_wait_data_idle(host);
718 sd_clear_error(host);
728 static int sd_tuning_phase(struct realtek_pci_sdmmc *host,
735 err = sd_tuning_rx_cmd(host, opcode, (u8)i);
746 static int sd_tuning_rx(struct realtek_pci_sdmmc *host, u8 opcode)
753 err = sd_tuning_phase(host, opcode, &(raw_phase_map[i]));
763 dev_dbg(sdmmc_dev(host), "RX raw_phase_map[%d] = 0x%08x\n",
767 dev_dbg(sdmmc_dev(host), "RX phase_map = 0x%08x\n", phase_map);
770 final_phase = sd_search_final_phase(host, phase_map);
774 err = sd_change_phase(host, final_phase, true);
799 struct realtek_pci_sdmmc *host = container_of(work,
801 struct rtsx_pcr *pcr = host->pcr;
803 struct mmc_host *mmc = host->mmc;
804 struct mmc_request *mrq = host->mrq;
811 if (host->eject || !sd_get_cd_int(host)) {
816 err = rtsx_pci_card_exclusive_check(host->pcr, RTSX_SD_CARD);
826 rtsx_pci_switch_clock(pcr, host->clock, host->ssc_depth,
827 host->initial_mode, host->double_clk, host->vpclk);
832 mutex_lock(&host->host_mutex);
833 host->mrq = mrq;
834 mutex_unlock(&host->host_mutex);
840 sd_send_cmd_get_rsp(host, cmd);
842 cmd->error = sd_rw_multi(host, mrq);
843 if (!host->using_cookie)
844 sdmmc_post_req(host->mmc, host->mrq, 0);
847 sd_send_cmd_get_rsp(host, mrq->stop);
849 sd_normal_rw(host, mrq);
863 dev_dbg(sdmmc_dev(host), "CMD %d 0x%08x error(%d)\n",
867 mutex_lock(&host->host_mutex);
868 host->mrq = NULL;
869 mutex_unlock(&host->host_mutex);
876 struct realtek_pci_sdmmc *host = mmc_priv(mmc);
879 mutex_lock(&host->host_mutex);
880 host->mrq = mrq;
881 mutex_unlock(&host->host_mutex);
884 host->using_cookie = sd_pre_dma_transfer(host, data, false);
886 schedule_work(&host->work);
889 static int sd_set_bus_width(struct realtek_pci_sdmmc *host,
900 err = rtsx_pci_write_register(host->pcr, SD_CFG1,
906 static int sd_power_on(struct realtek_pci_sdmmc *host, unsigned char power_mode)
908 struct rtsx_pcr *pcr = host->pcr;
909 struct mmc_host *mmc = host->mmc;
914 if (host->prev_power_state == MMC_POWER_ON)
917 if (host->prev_power_state == MMC_POWER_UP) {
976 host->prev_power_state = power_mode;
980 static int sd_power_off(struct realtek_pci_sdmmc *host)
982 struct rtsx_pcr *pcr = host->pcr;
985 host->prev_power_state = MMC_POWER_OFF;
1003 static int sd_set_power_mode(struct realtek_pci_sdmmc *host,
1009 err = sd_power_off(host);
1011 err = sd_power_on(host, power_mode);
1016 static int sd_set_timing(struct realtek_pci_sdmmc *host, unsigned char timing)
1018 struct rtsx_pcr *pcr = host->pcr;
1090 struct realtek_pci_sdmmc *host = mmc_priv(mmc);
1091 struct rtsx_pcr *pcr = host->pcr;
1093 if (host->eject)
1096 if (rtsx_pci_card_exclusive_check(host->pcr, RTSX_SD_CARD))
1103 sd_set_bus_width(host, ios->bus_width);
1104 sd_set_power_mode(host, ios->power_mode);
1105 sd_set_timing(host, ios->timing);
1107 host->vpclk = false;
1108 host->double_clk = true;
1113 host->ssc_depth = RTSX_SSC_DEPTH_2M;
1114 host->vpclk = true;
1115 host->double_clk = false;
1120 host->ssc_depth = RTSX_SSC_DEPTH_1M;
1123 host->ssc_depth = RTSX_SSC_DEPTH_500K;
1127 host->initial_mode = (ios->clock <= 1000000) ? true : false;
1129 host->clock = ios->clock;
1130 rtsx_pci_switch_clock(pcr, ios->clock, host->ssc_depth,
1131 host->initial_mode, host->double_clk, host->vpclk);
1138 struct realtek_pci_sdmmc *host = mmc_priv(mmc);
1139 struct rtsx_pcr *pcr = host->pcr;
1143 if (host->eject)
1152 dev_dbg(sdmmc_dev(host), "%s: RTSX_BIPR = 0x%08x\n", __func__, val);
1163 struct realtek_pci_sdmmc *host = mmc_priv(mmc);
1164 struct rtsx_pcr *pcr = host->pcr;
1168 if (host->eject)
1177 dev_dbg(sdmmc_dev(host), "%s: RTSX_BIPR = 0x%08x\n", __func__, val);
1186 static int sd_wait_voltage_stable_1(struct realtek_pci_sdmmc *host)
1188 struct rtsx_pcr *pcr = host->pcr;
1219 static int sd_wait_voltage_stable_2(struct realtek_pci_sdmmc *host)
1221 struct rtsx_pcr *pcr = host->pcr;
1238 /* SD_CMD, SD_DAT[3:0] should be pulled high by host */
1248 dev_dbg(sdmmc_dev(host),
1261 struct realtek_pci_sdmmc *host = mmc_priv(mmc);
1262 struct rtsx_pcr *pcr = host->pcr;
1266 dev_dbg(sdmmc_dev(host), "%s: signal_voltage = %d\n",
1269 if (host->eject)
1272 err = rtsx_pci_card_exclusive_check(host->pcr, RTSX_SD_CARD);
1286 err = sd_wait_voltage_stable_1(host);
1296 err = sd_wait_voltage_stable_2(host);
1313 struct realtek_pci_sdmmc *host = mmc_priv(mmc);
1314 struct rtsx_pcr *pcr = host->pcr;
1317 if (host->eject)
1320 err = rtsx_pci_card_exclusive_check(host->pcr, RTSX_SD_CARD);
1331 err = sd_change_phase(host, SDR104_TX_PHASE(pcr), false);
1335 err = sd_change_phase(host, SDR50_TX_PHASE(pcr), false);
1339 err = sd_change_phase(host, DDR50_TX_PHASE(pcr), false);
1352 err = sd_tuning_rx(host, opcode);
1354 err = sd_change_phase(host, DDR50_RX_PHASE(pcr), true);
1365 struct realtek_pci_sdmmc *host = mmc_priv(mmc);
1366 struct rtsx_pcr *pcr = host->pcr;
1411 host->eject = true;
1427 static void init_extra_caps(struct realtek_pci_sdmmc *host)
1429 struct mmc_host *mmc = host->mmc;
1430 struct rtsx_pcr *pcr = host->pcr;
1432 dev_dbg(sdmmc_dev(host), "pcr->extra_caps = 0x%x\n", pcr->extra_caps);
1450 static void realtek_init_host(struct realtek_pci_sdmmc *host)
1452 struct mmc_host *mmc = host->mmc;
1453 struct rtsx_pcr *pcr = host->pcr;
1469 init_extra_caps(host);
1480 struct realtek_pci_sdmmc *host = platform_get_drvdata(pdev);
1482 host->cookie = -1;
1483 mmc_detect_change(host->mmc, 0);
1489 struct realtek_pci_sdmmc *host;
1503 mmc = mmc_alloc_host(sizeof(*host), &pdev->dev);
1507 host = mmc_priv(mmc);
1508 host->pcr = pcr;
1510 host->mmc = mmc;
1511 host->pdev = pdev;
1512 host->cookie = -1;
1513 host->prev_power_state = MMC_POWER_OFF;
1514 INIT_WORK(&host->work, sd_request);
1515 platform_set_drvdata(pdev, host);
1519 mutex_init(&host->host_mutex);
1521 realtek_init_host(host);
1543 struct realtek_pci_sdmmc *host = platform_get_drvdata(pdev);
1547 pcr = host->pcr;
1550 mmc = host->mmc;
1552 cancel_work_sync(&host->work);
1554 mutex_lock(&host->host_mutex);
1555 if (host->mrq) {
1562 host->mrq->cmd->error = -ENOMEDIUM;
1563 if (host->mrq->stop)
1564 host->mrq->stop->error = -ENOMEDIUM;
1565 mmc_request_done(mmc, host->mrq);
1567 mutex_unlock(&host->host_mutex);
1570 host->eject = true;
1572 flush_work(&host->work);