Lines Matching defs:host
15 #include <linux/mmc/host.h>
59 static inline struct device *sdmmc_dev(struct rtsx_usb_sdmmc *host)
61 return &(host->pdev->dev);
64 static inline void sd_clear_error(struct rtsx_usb_sdmmc *host)
66 struct rtsx_ucr *ucr = host->ucr;
76 static void sd_print_debug_regs(struct rtsx_usb_sdmmc *host)
78 struct rtsx_ucr *ucr = host->ucr;
82 dev_dbg(sdmmc_dev(host), "SD_STAT1: 0x%x\n", val);
84 dev_dbg(sdmmc_dev(host), "SD_STAT2: 0x%x\n", val);
86 dev_dbg(sdmmc_dev(host), "SD_BUS_STAT: 0x%x\n", val);
89 #define sd_print_debug_regs(host)
92 static int sd_read_data(struct rtsx_usb_sdmmc *host, struct mmc_command *cmd,
95 struct rtsx_ucr *ucr = host->ucr;
104 dev_dbg(sdmmc_dev(host), "%s: SD/MMC CMD%d\n", __func__
152 dev_dbg(sdmmc_dev(host),
159 sd_print_debug_regs(host);
162 dev_dbg(sdmmc_dev(host),
167 dev_dbg(sdmmc_dev(host),
176 dev_dbg(sdmmc_dev(host), "cmd->resp[0] = 0x%08x\n",
184 dev_dbg(sdmmc_dev(host),
199 static int sd_write_data(struct rtsx_usb_sdmmc *host, struct mmc_command *cmd,
202 struct rtsx_ucr *ucr = host->ucr;
212 dev_dbg(sdmmc_dev(host),
223 dev_dbg(sdmmc_dev(host), "%s: SD/MMC CMD%d\n", __func__,
263 dev_dbg(sdmmc_dev(host),
270 sd_print_debug_regs(host);
271 dev_dbg(sdmmc_dev(host),
278 dev_dbg(sdmmc_dev(host), "cmd->resp[0] = 0x%08x\n",
285 static void sd_send_cmd_get_rsp(struct rtsx_usb_sdmmc *host,
288 struct rtsx_ucr *ucr = host->ucr;
299 dev_dbg(sdmmc_dev(host), "%s: SD/MMC CMD %d, arg = 0x%08x\n",
329 dev_dbg(sdmmc_dev(host), "cmd->flag is not valid\n");
379 dev_dbg(sdmmc_dev(host),
386 sd_print_debug_regs(host);
387 sd_clear_error(host);
390 dev_dbg(sdmmc_dev(host),
395 dev_dbg(sdmmc_dev(host),
413 dev_dbg(sdmmc_dev(host), "Invalid response bit\n");
421 dev_dbg(sdmmc_dev(host), "CRC7 error\n");
436 dev_dbg(sdmmc_dev(host), "cmd->resp[%d] = 0x%08x\n",
441 dev_dbg(sdmmc_dev(host), "cmd->resp[0] = 0x%08x\n",
449 static int sd_rw_multi(struct rtsx_usb_sdmmc *host, struct mmc_request *mrq)
451 struct rtsx_ucr *ucr = host->ucr;
461 dev_dbg(sdmmc_dev(host), "%s: read %zu bytes\n",
467 dev_dbg(sdmmc_dev(host), "%s: write %zu bytes\n",
524 dev_dbg(sdmmc_dev(host), "rtsx_usb_transfer_data error %d\n"
526 sd_clear_error(host);
533 static inline void sd_enable_initial_mode(struct rtsx_usb_sdmmc *host)
535 rtsx_usb_write_register(host->ucr, SD_CFG1,
539 static inline void sd_disable_initial_mode(struct rtsx_usb_sdmmc *host)
541 rtsx_usb_write_register(host->ucr, SD_CFG1,
545 static void sd_normal_rw(struct rtsx_usb_sdmmc *host,
559 if (host->initial_mode)
560 sd_disable_initial_mode(host);
562 cmd->error = sd_read_data(host, cmd, (u16)data->blksz, buf,
565 if (host->initial_mode)
566 sd_enable_initial_mode(host);
572 cmd->error = sd_write_data(host, cmd, (u16)data->blksz, buf,
579 static int sd_change_phase(struct rtsx_usb_sdmmc *host, u8 sample_point, int tx)
581 struct rtsx_ucr *ucr = host->ucr;
583 dev_dbg(sdmmc_dev(host), "%s: %s sample_point = %d\n",
623 static u8 sd_search_final_phase(struct rtsx_usb_sdmmc *host, u32 phase_map)
630 dev_dbg(sdmmc_dev(host), "Phase: [map:%x]\n", phase_map);
644 dev_dbg(sdmmc_dev(host), "Phase: [map:%x] [maxlen:%d] [final:%d]\n",
650 static void sd_wait_data_idle(struct rtsx_usb_sdmmc *host)
656 rtsx_usb_ep0_read_register(host->ucr, SD_DATA_STATE, &val);
664 static int sd_tuning_rx_cmd(struct rtsx_usb_sdmmc *host,
670 err = sd_change_phase(host, sample_point, 0);
675 err = sd_read_data(host, &cmd, 0x40, NULL, 0, 100);
678 sd_wait_data_idle(host);
679 sd_clear_error(host);
686 static void sd_tuning_phase(struct rtsx_usb_sdmmc *host,
693 err = sd_tuning_rx_cmd(host, opcode, (u8)i);
702 static int sd_tuning_rx(struct rtsx_usb_sdmmc *host, u8 opcode)
709 err = sd_change_phase(host, 0x01, 1);
711 dev_dbg(sdmmc_dev(host), "TX phase setting failed\n");
717 sd_tuning_phase(host, opcode, &(raw_phase_map[i]));
725 dev_dbg(sdmmc_dev(host), "RX raw_phase_map[%d] = 0x%04x\n",
729 dev_dbg(sdmmc_dev(host), "RX phase_map = 0x%04x\n", phase_map);
732 final_phase = sd_search_final_phase(host, phase_map);
736 err = sd_change_phase(host, final_phase, 0);
748 struct rtsx_usb_sdmmc *host = mmc_priv(mmc);
749 struct rtsx_ucr *ucr = host->ucr;
753 if (host->host_removal)
776 struct rtsx_usb_sdmmc *host = mmc_priv(mmc);
777 struct rtsx_ucr *ucr = host->ucr;
781 if (host->host_removal)
796 host->card_exist = true;
801 host->card_exist = false;
807 struct rtsx_usb_sdmmc *host = mmc_priv(mmc);
808 struct rtsx_ucr *ucr = host->ucr;
813 dev_dbg(sdmmc_dev(host), "%s\n", __func__);
815 if (host->host_removal) {
820 if ((!host->card_exist)) {
827 mutex_lock(&host->host_mutex);
828 host->mrq = mrq;
829 mutex_unlock(&host->host_mutex);
835 sd_send_cmd_get_rsp(host, cmd);
838 sd_send_cmd_get_rsp(host, cmd);
841 sd_rw_multi(host, mrq);
844 sd_send_cmd_get_rsp(host, mrq->stop);
850 sd_normal_rw(host, mrq);
869 dev_dbg(sdmmc_dev(host), "cmd->error = %d\n", cmd->error);
873 mutex_lock(&host->host_mutex);
874 host->mrq = NULL;
875 mutex_unlock(&host->host_mutex);
880 static int sd_set_bus_width(struct rtsx_usb_sdmmc *host,
891 err = rtsx_usb_write_register(host->ucr, SD_CFG1,
953 static int sd_power_on(struct rtsx_usb_sdmmc *host)
955 struct rtsx_ucr *ucr = host->ucr;
958 dev_dbg(sdmmc_dev(host), "%s\n", __func__);
992 static int sd_power_off(struct rtsx_usb_sdmmc *host)
994 struct rtsx_ucr *ucr = host->ucr;
997 dev_dbg(sdmmc_dev(host), "%s\n", __func__);
1016 static int sd_set_power_mode(struct rtsx_usb_sdmmc *host,
1024 if (power_mode == host->power_mode)
1028 err = sd_power_off(host);
1029 pm_runtime_put_noidle(sdmmc_dev(host));
1031 pm_runtime_get_noresume(sdmmc_dev(host));
1032 err = sd_power_on(host);
1036 host->power_mode = power_mode;
1041 static int sd_set_timing(struct rtsx_usb_sdmmc *host,
1044 struct rtsx_ucr *ucr = host->ucr;
1104 struct rtsx_usb_sdmmc *host = mmc_priv(mmc);
1105 struct rtsx_ucr *ucr = host->ucr;
1107 dev_dbg(sdmmc_dev(host), "%s\n", __func__);
1110 sd_set_power_mode(host, ios->power_mode);
1111 sd_set_bus_width(host, ios->bus_width);
1112 sd_set_timing(host, ios->timing, &host->ddr_mode);
1114 host->vpclk = false;
1115 host->double_clk = true;
1120 host->ssc_depth = SSC_DEPTH_2M;
1121 host->vpclk = true;
1122 host->double_clk = false;
1126 host->ssc_depth = SSC_DEPTH_1M;
1129 host->ssc_depth = SSC_DEPTH_512K;
1133 host->initial_mode = (ios->clock <= 1000000) ? true : false;
1134 host->clock = ios->clock;
1136 rtsx_usb_switch_clock(host->ucr, host->clock, host->ssc_depth,
1137 host->initial_mode, host->double_clk, host->vpclk);
1140 dev_dbg(sdmmc_dev(host), "%s end\n", __func__);
1145 struct rtsx_usb_sdmmc *host = mmc_priv(mmc);
1146 struct rtsx_ucr *ucr = host->ucr;
1149 dev_dbg(sdmmc_dev(host), "%s: signal_voltage = %d\n",
1152 if (host->host_removal)
1194 struct rtsx_usb_sdmmc *host = mmc_priv(mmc);
1195 struct rtsx_ucr *ucr = host->ucr;
1201 dev_dbg(sdmmc_dev(host), "%s\n", __func__);
1234 struct rtsx_usb_sdmmc *host = mmc_priv(mmc);
1235 struct rtsx_ucr *ucr = host->ucr;
1238 if (host->host_removal)
1243 if (!host->ddr_mode)
1244 err = sd_tuning_rx(host, MMC_SEND_TUNING_BLOCK);
1265 struct rtsx_usb_sdmmc *host = container_of(led,
1268 if (host->host_removal)
1271 host->led.brightness = brightness;
1272 schedule_work(&host->led_work);
1277 struct rtsx_usb_sdmmc *host =
1279 struct rtsx_ucr *ucr = host->ucr;
1281 pm_runtime_get_noresume(sdmmc_dev(host));
1284 if (host->power_mode == MMC_POWER_OFF)
1287 if (host->led.brightness == LED_OFF)
1294 pm_runtime_put_sync_suspend(sdmmc_dev(host));
1298 static void rtsx_usb_init_host(struct rtsx_usb_sdmmc *host)
1300 struct mmc_host *mmc = host->mmc;
1321 host->power_mode = MMC_POWER_OFF;
1327 struct rtsx_usb_sdmmc *host;
1340 mmc = mmc_alloc_host(sizeof(*host), &pdev->dev);
1344 host = mmc_priv(mmc);
1345 host->ucr = ucr;
1346 host->mmc = mmc;
1347 host->pdev = pdev;
1348 platform_set_drvdata(pdev, host);
1350 mutex_init(&host->host_mutex);
1351 rtsx_usb_init_host(host);
1355 snprintf(host->led_name, sizeof(host->led_name),
1357 host->led.name = host->led_name;
1358 host->led.brightness = LED_OFF;
1359 host->led.default_trigger = mmc_hostname(mmc);
1360 host->led.brightness_set = rtsx_usb_led_control;
1362 err = led_classdev_register(mmc_dev(mmc), &host->led);
1366 INIT_WORK(&host->led_work, rtsx_usb_update_led);
1372 led_classdev_unregister(&host->led);
1384 struct rtsx_usb_sdmmc *host = platform_get_drvdata(pdev);
1387 if (!host)
1390 mmc = host->mmc;
1391 host->host_removal = true;
1393 mutex_lock(&host->host_mutex);
1394 if (host->mrq) {
1398 host->mrq->cmd->error = -ENOMEDIUM;
1399 if (host->mrq->stop)
1400 host->mrq->stop->error = -ENOMEDIUM;
1401 mmc_request_done(mmc, host->mrq);
1403 mutex_unlock(&host->host_mutex);
1408 cancel_work_sync(&host->led_work);
1409 led_classdev_unregister(&host->led);
1423 struct rtsx_usb_sdmmc *host = dev_get_drvdata(dev);
1425 host->mmc->caps &= ~MMC_CAP_NEEDS_POLL;
1431 struct rtsx_usb_sdmmc *host = dev_get_drvdata(dev);
1433 host->mmc->caps |= MMC_CAP_NEEDS_POLL;
1434 if (sdmmc_get_cd(host->mmc) == 1)
1435 mmc_detect_change(host->mmc, 0);