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;
1107 struct rtsx_usb_sdmmc *host = mmc_priv(mmc);
1108 struct rtsx_ucr *ucr = host->ucr;
1110 dev_dbg(sdmmc_dev(host), "%s\n", __func__);
1113 sd_set_power_mode(host, ios->power_mode);
1114 sd_set_bus_width(host, ios->bus_width);
1115 sd_set_timing(host, ios->timing, &host->ddr_mode);
1117 host->vpclk = false;
1118 host->double_clk = true;
1123 host->ssc_depth = SSC_DEPTH_2M;
1124 host->vpclk = true;
1125 host->double_clk = false;
1129 host->ssc_depth = SSC_DEPTH_1M;
1132 host->ssc_depth = SSC_DEPTH_512K;
1136 host->initial_mode = (ios->clock <= 1000000) ? true : false;
1137 host->clock = ios->clock;
1139 rtsx_usb_switch_clock(host->ucr, host->clock, host->ssc_depth,
1140 host->initial_mode, host->double_clk, host->vpclk);
1143 dev_dbg(sdmmc_dev(host), "%s end\n", __func__);
1148 struct rtsx_usb_sdmmc *host = mmc_priv(mmc);
1149 struct rtsx_ucr *ucr = host->ucr;
1152 dev_dbg(sdmmc_dev(host), "%s: signal_voltage = %d\n",
1155 if (host->host_removal)
1197 struct rtsx_usb_sdmmc *host = mmc_priv(mmc);
1198 struct rtsx_ucr *ucr = host->ucr;
1204 dev_dbg(sdmmc_dev(host), "%s\n", __func__);
1237 struct rtsx_usb_sdmmc *host = mmc_priv(mmc);
1238 struct rtsx_ucr *ucr = host->ucr;
1241 if (host->host_removal)
1246 if (!host->ddr_mode)
1247 err = sd_tuning_rx(host, MMC_SEND_TUNING_BLOCK);
1268 struct rtsx_usb_sdmmc *host = container_of(led,
1271 if (host->host_removal)
1274 host->led.brightness = brightness;
1275 schedule_work(&host->led_work);
1280 struct rtsx_usb_sdmmc *host =
1282 struct rtsx_ucr *ucr = host->ucr;
1284 pm_runtime_get_noresume(sdmmc_dev(host));
1287 if (host->power_mode == MMC_POWER_OFF)
1290 if (host->led.brightness == LED_OFF)
1297 pm_runtime_put_sync_suspend(sdmmc_dev(host));
1301 static void rtsx_usb_init_host(struct rtsx_usb_sdmmc *host)
1303 struct mmc_host *mmc = host->mmc;
1324 host->power_mode = MMC_POWER_OFF;
1330 struct rtsx_usb_sdmmc *host;
1343 mmc = mmc_alloc_host(sizeof(*host), &pdev->dev);
1347 host = mmc_priv(mmc);
1348 host->ucr = ucr;
1349 host->mmc = mmc;
1350 host->pdev = pdev;
1351 platform_set_drvdata(pdev, host);
1353 mutex_init(&host->host_mutex);
1354 rtsx_usb_init_host(host);
1358 snprintf(host->led_name, sizeof(host->led_name),
1360 host->led.name = host->led_name;
1361 host->led.brightness = LED_OFF;
1362 host->led.default_trigger = mmc_hostname(mmc);
1363 host->led.brightness_set = rtsx_usb_led_control;
1365 err = led_classdev_register(mmc_dev(mmc), &host->led);
1369 INIT_WORK(&host->led_work, rtsx_usb_update_led);
1375 led_classdev_unregister(&host->led);
1387 struct rtsx_usb_sdmmc *host = platform_get_drvdata(pdev);
1390 if (!host)
1393 mmc = host->mmc;
1394 host->host_removal = true;
1396 mutex_lock(&host->host_mutex);
1397 if (host->mrq) {
1401 host->mrq->cmd->error = -ENOMEDIUM;
1402 if (host->mrq->stop)
1403 host->mrq->stop->error = -ENOMEDIUM;
1404 mmc_request_done(mmc, host->mrq);
1406 mutex_unlock(&host->host_mutex);
1411 cancel_work_sync(&host->led_work);
1412 led_classdev_unregister(&host->led);
1428 struct rtsx_usb_sdmmc *host = dev_get_drvdata(dev);
1430 host->mmc->caps &= ~MMC_CAP_NEEDS_POLL;
1436 struct rtsx_usb_sdmmc *host = dev_get_drvdata(dev);
1438 host->mmc->caps |= MMC_CAP_NEEDS_POLL;
1439 if (sdmmc_get_cd(host->mmc) == 1)
1440 mmc_detect_change(host->mmc, 0);