Lines Matching defs:host

16 #include <linux/mmc/host.h>
50 static inline struct device *sdmmc_dev(struct realtek_pci_sdmmc *host)
52 return &(host->pdev->dev);
55 static inline void sd_clear_error(struct realtek_pci_sdmmc *host)
57 rtsx_pci_write_register(host->pcr, CARD_STOP,
62 static void dump_reg_range(struct realtek_pci_sdmmc *host, u16 start, u16 end)
74 rtsx_pci_read_register(host->pcr, start + i + j,
76 dev_dbg(sdmmc_dev(host), "0x%04X(%d): %8ph\n",
81 static void sd_print_debug_regs(struct realtek_pci_sdmmc *host)
83 dump_reg_range(host, 0xFDA0, 0xFDB3);
84 dump_reg_range(host, 0xFD52, 0xFD69);
87 #define sd_print_debug_regs(host)
90 static inline int sd_get_cd_int(struct realtek_pci_sdmmc *host)
92 return rtsx_pci_readl(host->pcr, RTSX_BIPR) & SD_EXIST;
147 static int sd_pre_dma_transfer(struct realtek_pci_sdmmc *host,
150 struct rtsx_pcr *pcr = host->pcr;
155 if (!pre && data->host_cookie && data->host_cookie != host->cookie) {
156 dev_err(sdmmc_dev(host),
157 "error: data->host_cookie = %d, host->cookie = %d\n",
158 data->host_cookie, host->cookie);
162 if (pre || data->host_cookie != host->cookie) {
165 count = host->cookie_sg_count;
170 host->cookie_sg_count = count;
171 if (++host->cookie < 0)
172 host->cookie = 1;
173 data->host_cookie = host->cookie;
175 host->sg_count = count;
183 struct realtek_pci_sdmmc *host = mmc_priv(mmc);
187 dev_err(sdmmc_dev(host),
193 sd_pre_dma_transfer(host, data, true);
194 dev_dbg(sdmmc_dev(host), "pre dma sg: %d\n", host->cookie_sg_count);
200 struct realtek_pci_sdmmc *host = mmc_priv(mmc);
201 struct rtsx_pcr *pcr = host->pcr;
209 static void sd_send_cmd_get_rsp(struct realtek_pci_sdmmc *host,
212 struct rtsx_pcr *pcr = host->pcr;
223 dev_dbg(sdmmc_dev(host), "%s: SD/MMC CMD %d, arg = 0x%08x\n",
269 sd_print_debug_regs(host);
270 sd_clear_error(host);
271 dev_dbg(sdmmc_dev(host),
287 dev_dbg(sdmmc_dev(host), "Invalid response bit\n");
295 dev_dbg(sdmmc_dev(host), "CRC7 error\n");
310 dev_dbg(sdmmc_dev(host), "cmd->resp[%d] = 0x%08x\n",
315 dev_dbg(sdmmc_dev(host), "cmd->resp[0] = 0x%08x\n",
327 static int sd_read_data(struct realtek_pci_sdmmc *host, struct mmc_command *cmd,
330 struct rtsx_pcr *pcr = host->pcr;
334 dev_dbg(sdmmc_dev(host), "%s: SD/MMC CMD %d, arg = 0x%08x\n",
362 sd_print_debug_regs(host);
363 dev_dbg(sdmmc_dev(host),
371 dev_dbg(sdmmc_dev(host),
380 static int sd_write_data(struct realtek_pci_sdmmc *host,
384 struct rtsx_pcr *pcr = host->pcr;
387 dev_dbg(sdmmc_dev(host), "%s: SD/MMC CMD %d, arg = 0x%08x\n",
393 sd_send_cmd_get_rsp(host, cmd);
400 dev_dbg(sdmmc_dev(host),
418 sd_print_debug_regs(host);
419 dev_dbg(sdmmc_dev(host),
427 static int sd_read_long_data(struct realtek_pci_sdmmc *host,
430 struct rtsx_pcr *pcr = host->pcr;
431 struct mmc_host *mmc = host->mmc;
441 dev_dbg(sdmmc_dev(host), "%s: SD/MMC CMD %d, arg = 0x%08x\n",
475 err = rtsx_pci_dma_transfer(pcr, data->sg, host->sg_count, 1, 10000);
477 sd_print_debug_regs(host);
478 sd_clear_error(host);
485 static int sd_write_long_data(struct realtek_pci_sdmmc *host,
488 struct rtsx_pcr *pcr = host->pcr;
489 struct mmc_host *mmc = host->mmc;
498 sd_send_cmd_get_rsp(host, cmd);
502 dev_dbg(sdmmc_dev(host), "%s: SD/MMC CMD %d, arg = 0x%08x\n",
533 err = rtsx_pci_dma_transfer(pcr, data->sg, host->sg_count, 0, 10000);
535 sd_clear_error(host);
542 static inline void sd_enable_initial_mode(struct realtek_pci_sdmmc *host)
544 rtsx_pci_write_register(host->pcr, SD_CFG1,
548 static inline void sd_disable_initial_mode(struct realtek_pci_sdmmc *host)
550 rtsx_pci_write_register(host->pcr, SD_CFG1,
554 static int sd_rw_multi(struct realtek_pci_sdmmc *host, struct mmc_request *mrq)
559 if (host->sg_count < 0) {
560 data->error = host->sg_count;
561 dev_dbg(sdmmc_dev(host), "%s: sg_count = %d is invalid\n",
562 __func__, host->sg_count);
567 if (host->initial_mode)
568 sd_disable_initial_mode(host);
570 err = sd_read_long_data(host, mrq);
572 if (host->initial_mode)
573 sd_enable_initial_mode(host);
578 return sd_write_long_data(host, mrq);
581 static void sd_normal_rw(struct realtek_pci_sdmmc *host,
595 if (host->initial_mode)
596 sd_disable_initial_mode(host);
598 cmd->error = sd_read_data(host, cmd, (u16)data->blksz, buf,
601 if (host->initial_mode)
602 sd_enable_initial_mode(host);
608 cmd->error = sd_write_data(host, cmd, (u16)data->blksz, buf,
615 static int sd_change_phase(struct realtek_pci_sdmmc *host,
618 struct rtsx_pcr *pcr = host->pcr;
620 dev_dbg(sdmmc_dev(host), "%s(%s): sample_point = %d\n",
659 static u8 sd_search_final_phase(struct realtek_pci_sdmmc *host, u32 phase_map)
666 dev_err(sdmmc_dev(host), "phase error: [map:%x]\n", phase_map);
680 dev_dbg(sdmmc_dev(host), "phase: [map:%x] [maxlen:%d] [final:%d]\n",
686 static void sd_wait_data_idle(struct realtek_pci_sdmmc *host)
692 rtsx_pci_read_register(host->pcr, SD_DATA_STATE, &val);
700 static int sd_tuning_rx_cmd(struct realtek_pci_sdmmc *host,
705 struct rtsx_pcr *pcr = host->pcr;
707 sd_change_phase(host, sample_point, true);
713 err = sd_read_data(host, &cmd, 0x40, NULL, 0, 100);
716 sd_wait_data_idle(host);
717 sd_clear_error(host);
727 static int sd_tuning_phase(struct realtek_pci_sdmmc *host,
734 err = sd_tuning_rx_cmd(host, opcode, (u8)i);
745 static int sd_tuning_rx(struct realtek_pci_sdmmc *host, u8 opcode)
752 err = sd_tuning_phase(host, opcode, &(raw_phase_map[i]));
762 dev_dbg(sdmmc_dev(host), "RX raw_phase_map[%d] = 0x%08x\n",
766 dev_dbg(sdmmc_dev(host), "RX phase_map = 0x%08x\n", phase_map);
769 final_phase = sd_search_final_phase(host, phase_map);
773 err = sd_change_phase(host, final_phase, true);
798 struct realtek_pci_sdmmc *host = container_of(work,
800 struct rtsx_pcr *pcr = host->pcr;
802 struct mmc_host *mmc = host->mmc;
803 struct mmc_request *mrq = host->mrq;
810 if (host->eject || !sd_get_cd_int(host)) {
815 err = rtsx_pci_card_exclusive_check(host->pcr, RTSX_SD_CARD);
825 rtsx_pci_switch_clock(pcr, host->clock, host->ssc_depth,
826 host->initial_mode, host->double_clk, host->vpclk);
831 mutex_lock(&host->host_mutex);
832 host->mrq = mrq;
833 mutex_unlock(&host->host_mutex);
839 sd_send_cmd_get_rsp(host, cmd);
841 cmd->error = sd_rw_multi(host, mrq);
842 if (!host->using_cookie)
843 sdmmc_post_req(host->mmc, host->mrq, 0);
846 sd_send_cmd_get_rsp(host, mrq->stop);
848 sd_normal_rw(host, mrq);
862 dev_dbg(sdmmc_dev(host), "CMD %d 0x%08x error(%d)\n",
866 mutex_lock(&host->host_mutex);
867 host->mrq = NULL;
868 mutex_unlock(&host->host_mutex);
875 struct realtek_pci_sdmmc *host = mmc_priv(mmc);
878 mutex_lock(&host->host_mutex);
879 host->mrq = mrq;
880 mutex_unlock(&host->host_mutex);
883 host->using_cookie = sd_pre_dma_transfer(host, data, false);
885 schedule_work(&host->work);
888 static int sd_set_bus_width(struct realtek_pci_sdmmc *host,
899 err = rtsx_pci_write_register(host->pcr, SD_CFG1,
905 static int sd_power_on(struct realtek_pci_sdmmc *host, unsigned char power_mode)
907 struct rtsx_pcr *pcr = host->pcr;
908 struct mmc_host *mmc = host->mmc;
913 if (host->prev_power_state == MMC_POWER_ON)
916 if (host->prev_power_state == MMC_POWER_UP) {
975 host->prev_power_state = power_mode;
979 static int sd_power_off(struct realtek_pci_sdmmc *host)
981 struct rtsx_pcr *pcr = host->pcr;
984 host->prev_power_state = MMC_POWER_OFF;
1002 static int sd_set_power_mode(struct realtek_pci_sdmmc *host,
1008 err = sd_power_off(host);
1010 err = sd_power_on(host, power_mode);
1015 static int sd_set_timing(struct realtek_pci_sdmmc *host, unsigned char timing)
1017 struct rtsx_pcr *pcr = host->pcr;
1089 struct realtek_pci_sdmmc *host = mmc_priv(mmc);
1090 struct rtsx_pcr *pcr = host->pcr;
1092 if (host->eject)
1095 if (rtsx_pci_card_exclusive_check(host->pcr, RTSX_SD_CARD))
1102 sd_set_bus_width(host, ios->bus_width);
1103 sd_set_power_mode(host, ios->power_mode);
1104 sd_set_timing(host, ios->timing);
1106 host->vpclk = false;
1107 host->double_clk = true;
1112 host->ssc_depth = RTSX_SSC_DEPTH_2M;
1113 host->vpclk = true;
1114 host->double_clk = false;
1119 host->ssc_depth = RTSX_SSC_DEPTH_1M;
1122 host->ssc_depth = RTSX_SSC_DEPTH_500K;
1126 host->initial_mode = (ios->clock <= 1000000) ? true : false;
1128 host->clock = ios->clock;
1129 rtsx_pci_switch_clock(pcr, ios->clock, host->ssc_depth,
1130 host->initial_mode, host->double_clk, host->vpclk);
1137 struct realtek_pci_sdmmc *host = mmc_priv(mmc);
1138 struct rtsx_pcr *pcr = host->pcr;
1142 if (host->eject)
1151 dev_dbg(sdmmc_dev(host), "%s: RTSX_BIPR = 0x%08x\n", __func__, val);
1162 struct realtek_pci_sdmmc *host = mmc_priv(mmc);
1163 struct rtsx_pcr *pcr = host->pcr;
1167 if (host->eject)
1176 dev_dbg(sdmmc_dev(host), "%s: RTSX_BIPR = 0x%08x\n", __func__, val);
1185 static int sd_wait_voltage_stable_1(struct realtek_pci_sdmmc *host)
1187 struct rtsx_pcr *pcr = host->pcr;
1218 static int sd_wait_voltage_stable_2(struct realtek_pci_sdmmc *host)
1220 struct rtsx_pcr *pcr = host->pcr;
1237 /* SD_CMD, SD_DAT[3:0] should be pulled high by host */
1247 dev_dbg(sdmmc_dev(host),
1260 struct realtek_pci_sdmmc *host = mmc_priv(mmc);
1261 struct rtsx_pcr *pcr = host->pcr;
1265 dev_dbg(sdmmc_dev(host), "%s: signal_voltage = %d\n",
1268 if (host->eject)
1271 err = rtsx_pci_card_exclusive_check(host->pcr, RTSX_SD_CARD);
1285 err = sd_wait_voltage_stable_1(host);
1295 err = sd_wait_voltage_stable_2(host);
1312 struct realtek_pci_sdmmc *host = mmc_priv(mmc);
1313 struct rtsx_pcr *pcr = host->pcr;
1316 if (host->eject)
1319 err = rtsx_pci_card_exclusive_check(host->pcr, RTSX_SD_CARD);
1330 err = sd_change_phase(host, SDR104_TX_PHASE(pcr), false);
1334 err = sd_change_phase(host, SDR50_TX_PHASE(pcr), false);
1338 err = sd_change_phase(host, DDR50_TX_PHASE(pcr), false);
1351 err = sd_tuning_rx(host, opcode);
1353 err = sd_change_phase(host, DDR50_RX_PHASE(pcr), true);
1364 struct realtek_pci_sdmmc *host = mmc_priv(mmc);
1365 struct rtsx_pcr *pcr = host->pcr;
1396 host->eject = true;
1412 static void init_extra_caps(struct realtek_pci_sdmmc *host)
1414 struct mmc_host *mmc = host->mmc;
1415 struct rtsx_pcr *pcr = host->pcr;
1417 dev_dbg(sdmmc_dev(host), "pcr->extra_caps = 0x%x\n", pcr->extra_caps);
1435 static void realtek_init_host(struct realtek_pci_sdmmc *host)
1437 struct mmc_host *mmc = host->mmc;
1438 struct rtsx_pcr *pcr = host->pcr;
1454 init_extra_caps(host);
1465 struct realtek_pci_sdmmc *host = platform_get_drvdata(pdev);
1467 host->cookie = -1;
1468 mmc_detect_change(host->mmc, 0);
1474 struct realtek_pci_sdmmc *host;
1488 mmc = mmc_alloc_host(sizeof(*host), &pdev->dev);
1492 host = mmc_priv(mmc);
1493 host->pcr = pcr;
1495 host->mmc = mmc;
1496 host->pdev = pdev;
1497 host->cookie = -1;
1498 host->prev_power_state = MMC_POWER_OFF;
1499 INIT_WORK(&host->work, sd_request);
1500 platform_set_drvdata(pdev, host);
1504 mutex_init(&host->host_mutex);
1506 realtek_init_host(host);
1528 struct realtek_pci_sdmmc *host = platform_get_drvdata(pdev);
1532 pcr = host->pcr;
1535 mmc = host->mmc;
1537 cancel_work_sync(&host->work);
1539 mutex_lock(&host->host_mutex);
1540 if (host->mrq) {
1547 host->mrq->cmd->error = -ENOMEDIUM;
1548 if (host->mrq->stop)
1549 host->mrq->stop->error = -ENOMEDIUM;
1550 mmc_request_done(mmc, host->mrq);
1552 mutex_unlock(&host->host_mutex);
1555 host->eject = true;
1557 flush_work(&host->work);