Lines Matching +full:tx +full:- +full:ping +full:- +full:pong
1 // SPDX-License-Identifier: GPL-2.0-only
4 * Copyright(c) 2009-2013 Realtek Semiconductor Corp. All rights reserved.
61 return &(host->pdev->dev); in sdmmc_dev()
66 struct rtsx_ucr *ucr = host->ucr; in sd_clear_error()
78 struct rtsx_ucr *ucr = host->ucr; in sd_print_debug_regs()
95 struct rtsx_ucr *ucr = host->ucr; in sd_read_data()
105 , cmd->opcode); in sd_read_data()
106 if (cmd->opcode == MMC_SEND_TUNING_BLOCK) in sd_read_data()
112 SD_CMD0, 0xFF, (u8)(cmd->opcode) | 0x40); in sd_read_data()
114 SD_CMD1, 0xFF, (u8)(cmd->arg >> 24)); in sd_read_data()
116 SD_CMD2, 0xFF, (u8)(cmd->arg >> 16)); in sd_read_data()
118 SD_CMD3, 0xFF, (u8)(cmd->arg >> 8)); in sd_read_data()
120 SD_CMD4, 0xFF, (u8)cmd->arg); in sd_read_data()
158 if (err || (ucr->rsp_buf[0] & SD_TRANSFER_ERR)) { in sd_read_data()
164 ucr->rsp_buf[0]); in sd_read_data()
165 err = -EIO; in sd_read_data()
175 cmd->resp[0] = get_unaligned_be32(ucr->rsp_buf + 1); in sd_read_data()
176 dev_dbg(sdmmc_dev(host), "cmd->resp[0] = 0x%08x\n", in sd_read_data()
177 cmd->resp[0]); in sd_read_data()
181 /* 2-byte aligned part */ in sd_read_data()
182 err = rtsx_usb_read_ppbuf(ucr, buf, byte_cnt - (byte_cnt % 2)); in sd_read_data()
193 buf + byte_cnt - 1); in sd_read_data()
202 struct rtsx_ucr *ucr = host->ucr; in sd_write_data()
224 cmd->opcode); in sd_write_data()
226 SD_CMD0, 0xFF, (u8)(cmd->opcode) | 0x40); in sd_write_data()
228 SD_CMD1, 0xFF, (u8)(cmd->arg >> 24)); in sd_write_data()
230 SD_CMD2, 0xFF, (u8)(cmd->arg >> 16)); in sd_write_data()
232 SD_CMD3, 0xFF, (u8)(cmd->arg >> 8)); in sd_write_data()
234 SD_CMD4, 0xFF, (u8)cmd->arg); in sd_write_data()
277 cmd->resp[0] = get_unaligned_be32(ucr->rsp_buf + 1); in sd_write_data()
278 dev_dbg(sdmmc_dev(host), "cmd->resp[0] = 0x%08x\n", in sd_write_data()
279 cmd->resp[0]); in sd_write_data()
288 struct rtsx_ucr *ucr = host->ucr; in sd_send_cmd_get_rsp()
289 u8 cmd_idx = (u8)cmd->opcode; in sd_send_cmd_get_rsp()
290 u32 arg = cmd->arg; in sd_send_cmd_get_rsp()
329 dev_dbg(sdmmc_dev(host), "cmd->flag is not valid\n"); in sd_send_cmd_get_rsp()
330 err = -EINVAL; in sd_send_cmd_get_rsp()
335 timeout = cmd->busy_timeout ? cmd->busy_timeout : 3000; in sd_send_cmd_get_rsp()
337 if (cmd->opcode == SD_SWITCH_VOLTAGE) { in sd_send_cmd_get_rsp()
363 /* Read data from ping-pong buffer */ in sd_send_cmd_get_rsp()
385 if (err || (ucr->rsp_buf[0] & SD_TRANSFER_ERR)) { in sd_send_cmd_get_rsp()
392 ucr->rsp_buf[0]); in sd_send_cmd_get_rsp()
393 err = -EIO; in sd_send_cmd_get_rsp()
408 ptr = ucr->rsp_buf + 1; in sd_send_cmd_get_rsp()
412 err = -EILSEQ; in sd_send_cmd_get_rsp()
420 err = -EILSEQ; in sd_send_cmd_get_rsp()
428 * The controller offloads the last byte {CRC-7, end bit 1'b1} in sd_send_cmd_get_rsp()
435 cmd->resp[i] = get_unaligned_be32(ptr + 1 + i * 4); in sd_send_cmd_get_rsp()
436 dev_dbg(sdmmc_dev(host), "cmd->resp[%d] = 0x%08x\n", in sd_send_cmd_get_rsp()
437 i, cmd->resp[i]); in sd_send_cmd_get_rsp()
440 cmd->resp[0] = get_unaligned_be32(ptr + 1); in sd_send_cmd_get_rsp()
441 dev_dbg(sdmmc_dev(host), "cmd->resp[0] = 0x%08x\n", in sd_send_cmd_get_rsp()
442 cmd->resp[0]); in sd_send_cmd_get_rsp()
446 cmd->error = err; in sd_send_cmd_get_rsp()
451 struct rtsx_ucr *ucr = host->ucr; in sd_rw_multi()
452 struct mmc_data *data = mrq->data; in sd_rw_multi()
453 int read = (data->flags & MMC_DATA_READ) ? 1 : 0; in sd_rw_multi()
457 size_t data_len = data->blksz * data->blocks; in sd_rw_multi()
479 0xFF, (u8)data->blocks); in sd_rw_multi()
481 0xFF, (u8)(data->blocks >> 8)); in sd_rw_multi()
517 pipe = usb_rcvbulkpipe(ucr->pusb_dev, EP_BULK_IN); in sd_rw_multi()
519 pipe = usb_sndbulkpipe(ucr->pusb_dev, EP_BULK_OUT); in sd_rw_multi()
521 err = rtsx_usb_transfer_data(ucr, pipe, data->sg, data_len, in sd_rw_multi()
522 data->sg_len, NULL, 10000); in sd_rw_multi()
535 rtsx_usb_write_register(host->ucr, SD_CFG1, in sd_enable_initial_mode()
541 rtsx_usb_write_register(host->ucr, SD_CFG1, in sd_disable_initial_mode()
548 struct mmc_command *cmd = mrq->cmd; in sd_normal_rw()
549 struct mmc_data *data = mrq->data; in sd_normal_rw()
552 buf = kzalloc(data->blksz, GFP_NOIO); in sd_normal_rw()
554 cmd->error = -ENOMEM; in sd_normal_rw()
558 if (data->flags & MMC_DATA_READ) { in sd_normal_rw()
559 if (host->initial_mode) in sd_normal_rw()
562 cmd->error = sd_read_data(host, cmd, (u16)data->blksz, buf, in sd_normal_rw()
563 data->blksz, 200); in sd_normal_rw()
565 if (host->initial_mode) in sd_normal_rw()
568 sg_copy_from_buffer(data->sg, data->sg_len, buf, data->blksz); in sd_normal_rw()
570 sg_copy_to_buffer(data->sg, data->sg_len, buf, data->blksz); in sd_normal_rw()
572 cmd->error = sd_write_data(host, cmd, (u16)data->blksz, buf, in sd_normal_rw()
573 data->blksz, 200); in sd_normal_rw()
579 static int sd_change_phase(struct rtsx_usb_sdmmc *host, u8 sample_point, int tx) in sd_change_phase() argument
581 struct rtsx_ucr *ucr = host->ucr; in sd_change_phase()
584 __func__, tx ? "TX" : "RX", sample_point); in sd_change_phase()
590 if (tx) in sd_change_phase()
656 rtsx_usb_ep0_read_register(host->ucr, SD_DATA_STATE, &val); in sd_wait_data_idle()
692 for (i = MAX_PHASE; i >= 0; i--) { in sd_tuning_phase()
708 /* setting fixed default TX phase */ in sd_tuning_rx()
711 dev_dbg(sdmmc_dev(host), "TX phase setting failed\n"); in sd_tuning_rx()
734 return -EINVAL; in sd_tuning_rx()
740 return -EINVAL; in sd_tuning_rx()
749 struct rtsx_ucr *ucr = host->ucr; in sdmmc_get_ro()
753 if (host->host_removal) in sdmmc_get_ro()
754 return -ENOMEDIUM; in sdmmc_get_ro()
756 mutex_lock(&ucr->dev_mutex); in sdmmc_get_ro()
761 mutex_unlock(&ucr->dev_mutex); in sdmmc_get_ro()
764 /* Treat failed detection as non-ro */ in sdmmc_get_ro()
777 struct rtsx_ucr *ucr = host->ucr; in sdmmc_get_cd()
781 if (host->host_removal) in sdmmc_get_cd()
782 return -ENOMEDIUM; in sdmmc_get_cd()
784 mutex_lock(&ucr->dev_mutex); in sdmmc_get_cd()
789 mutex_unlock(&ucr->dev_mutex); in sdmmc_get_cd()
791 /* Treat failed detection as non-exist */ in sdmmc_get_cd()
796 host->card_exist = true; in sdmmc_get_cd()
801 host->card_exist = false; in sdmmc_get_cd()
808 struct rtsx_ucr *ucr = host->ucr; in sdmmc_request()
809 struct mmc_command *cmd = mrq->cmd; in sdmmc_request()
810 struct mmc_data *data = mrq->data; in sdmmc_request()
815 if (host->host_removal) { in sdmmc_request()
816 cmd->error = -ENOMEDIUM; in sdmmc_request()
820 if ((!host->card_exist)) { in sdmmc_request()
821 cmd->error = -ENOMEDIUM; in sdmmc_request()
825 mutex_lock(&ucr->dev_mutex); in sdmmc_request()
827 mutex_lock(&host->host_mutex); in sdmmc_request()
828 host->mrq = mrq; in sdmmc_request()
829 mutex_unlock(&host->host_mutex); in sdmmc_request()
831 if (mrq->data) in sdmmc_request()
832 data_size = data->blocks * data->blksz; in sdmmc_request()
836 } else if ((!(data_size % 512) && cmd->opcode != MMC_SEND_EXT_CSD) || in sdmmc_request()
837 mmc_op_multi(cmd->opcode)) { in sdmmc_request()
840 if (!cmd->error) { in sdmmc_request()
843 if (mmc_op_multi(cmd->opcode) && mrq->stop) { in sdmmc_request()
844 sd_send_cmd_get_rsp(host, mrq->stop); in sdmmc_request()
853 if (mrq->data) { in sdmmc_request()
854 if (cmd->error || data->error) in sdmmc_request()
855 data->bytes_xfered = 0; in sdmmc_request()
857 data->bytes_xfered = data->blocks * data->blksz; in sdmmc_request()
860 mutex_unlock(&ucr->dev_mutex); in sdmmc_request()
863 if (cmd->error) { in sdmmc_request()
869 dev_dbg(sdmmc_dev(host), "cmd->error = %d\n", cmd->error); in sdmmc_request()
873 mutex_lock(&host->host_mutex); in sdmmc_request()
874 host->mrq = NULL; in sdmmc_request()
875 mutex_unlock(&host->host_mutex); in sdmmc_request()
891 err = rtsx_usb_write_register(host->ucr, SD_CFG1, in sd_set_bus_width()
955 struct rtsx_ucr *ucr = host->ucr; in sd_power_on()
994 struct rtsx_ucr *ucr = host->ucr; in sd_power_off()
1024 if (power_mode == host->power_mode) in sd_set_power_mode()
1036 host->power_mode = power_mode; in sd_set_power_mode()
1044 struct rtsx_ucr *ucr = host->ucr; in sd_set_timing()
1105 struct rtsx_ucr *ucr = host->ucr; in sdmmc_set_ios()
1108 mutex_lock(&ucr->dev_mutex); in sdmmc_set_ios()
1110 sd_set_power_mode(host, ios->power_mode); in sdmmc_set_ios()
1111 sd_set_bus_width(host, ios->bus_width); in sdmmc_set_ios()
1112 sd_set_timing(host, ios->timing, &host->ddr_mode); in sdmmc_set_ios()
1114 host->vpclk = false; in sdmmc_set_ios()
1115 host->double_clk = true; in sdmmc_set_ios()
1117 switch (ios->timing) { in sdmmc_set_ios()
1120 host->ssc_depth = SSC_DEPTH_2M; in sdmmc_set_ios()
1121 host->vpclk = true; in sdmmc_set_ios()
1122 host->double_clk = false; in sdmmc_set_ios()
1126 host->ssc_depth = SSC_DEPTH_1M; in sdmmc_set_ios()
1129 host->ssc_depth = SSC_DEPTH_512K; in sdmmc_set_ios()
1133 host->initial_mode = (ios->clock <= 1000000) ? true : false; in sdmmc_set_ios()
1134 host->clock = ios->clock; in sdmmc_set_ios()
1136 rtsx_usb_switch_clock(host->ucr, host->clock, host->ssc_depth, in sdmmc_set_ios()
1137 host->initial_mode, host->double_clk, host->vpclk); in sdmmc_set_ios()
1139 mutex_unlock(&ucr->dev_mutex); in sdmmc_set_ios()
1146 struct rtsx_ucr *ucr = host->ucr; in sdmmc_switch_voltage()
1150 __func__, ios->signal_voltage); in sdmmc_switch_voltage()
1152 if (host->host_removal) in sdmmc_switch_voltage()
1153 return -ENOMEDIUM; in sdmmc_switch_voltage()
1155 if (ios->signal_voltage == MMC_SIGNAL_VOLTAGE_120) in sdmmc_switch_voltage()
1156 return -EPERM; in sdmmc_switch_voltage()
1158 mutex_lock(&ucr->dev_mutex); in sdmmc_switch_voltage()
1162 mutex_unlock(&ucr->dev_mutex); in sdmmc_switch_voltage()
1166 /* Let mmc core do the busy checking, simply stop the forced-toggle in sdmmc_switch_voltage()
1171 if (ios->signal_voltage == MMC_SIGNAL_VOLTAGE_330) { in sdmmc_switch_voltage()
1187 mutex_unlock(&ucr->dev_mutex); in sdmmc_switch_voltage()
1195 struct rtsx_ucr *ucr = host->ucr; in sdmmc_card_busy()
1203 mutex_lock(&ucr->dev_mutex); in sdmmc_card_busy()
1220 mutex_unlock(&ucr->dev_mutex); in sdmmc_card_busy()
1235 struct rtsx_ucr *ucr = host->ucr; in sdmmc_execute_tuning()
1238 if (host->host_removal) in sdmmc_execute_tuning()
1239 return -ENOMEDIUM; in sdmmc_execute_tuning()
1241 mutex_lock(&ucr->dev_mutex); in sdmmc_execute_tuning()
1243 if (!host->ddr_mode) in sdmmc_execute_tuning()
1246 mutex_unlock(&ucr->dev_mutex); in sdmmc_execute_tuning()
1268 if (host->host_removal) in rtsx_usb_led_control()
1271 host->led.brightness = brightness; in rtsx_usb_led_control()
1272 schedule_work(&host->led_work); in rtsx_usb_led_control()
1279 struct rtsx_ucr *ucr = host->ucr; in rtsx_usb_update_led()
1282 mutex_lock(&ucr->dev_mutex); in rtsx_usb_update_led()
1284 if (host->power_mode == MMC_POWER_OFF) in rtsx_usb_update_led()
1287 if (host->led.brightness == LED_OFF) in rtsx_usb_update_led()
1293 mutex_unlock(&ucr->dev_mutex); in rtsx_usb_update_led()
1300 struct mmc_host *mmc = host->mmc; in rtsx_usb_init_host()
1302 mmc->f_min = 250000; in rtsx_usb_init_host()
1303 mmc->f_max = 208000000; in rtsx_usb_init_host()
1304 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195; in rtsx_usb_init_host()
1305 mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_SD_HIGHSPEED | in rtsx_usb_init_host()
1309 mmc->caps2 = MMC_CAP2_NO_PRESCAN_POWERUP | MMC_CAP2_FULL_PWR_CYCLE | in rtsx_usb_init_host()
1312 mmc->max_current_330 = 400; in rtsx_usb_init_host()
1313 mmc->max_current_180 = 800; in rtsx_usb_init_host()
1314 mmc->ops = &rtsx_usb_sdmmc_ops; in rtsx_usb_init_host()
1315 mmc->max_segs = 256; in rtsx_usb_init_host()
1316 mmc->max_seg_size = 65536; in rtsx_usb_init_host()
1317 mmc->max_blk_size = 512; in rtsx_usb_init_host()
1318 mmc->max_blk_count = 65535; in rtsx_usb_init_host()
1319 mmc->max_req_size = 524288; in rtsx_usb_init_host()
1321 host->power_mode = MMC_POWER_OFF; in rtsx_usb_init_host()
1334 ucr = usb_get_intfdata(to_usb_interface(pdev->dev.parent)); in rtsx_usb_sdmmc_drv_probe()
1336 return -ENXIO; in rtsx_usb_sdmmc_drv_probe()
1338 dev_dbg(&(pdev->dev), ": Realtek USB SD/MMC controller found\n"); in rtsx_usb_sdmmc_drv_probe()
1340 mmc = mmc_alloc_host(sizeof(*host), &pdev->dev); in rtsx_usb_sdmmc_drv_probe()
1342 return -ENOMEM; in rtsx_usb_sdmmc_drv_probe()
1345 host->ucr = ucr; in rtsx_usb_sdmmc_drv_probe()
1346 host->mmc = mmc; in rtsx_usb_sdmmc_drv_probe()
1347 host->pdev = pdev; in rtsx_usb_sdmmc_drv_probe()
1350 mutex_init(&host->host_mutex); in rtsx_usb_sdmmc_drv_probe()
1352 pm_runtime_enable(&pdev->dev); in rtsx_usb_sdmmc_drv_probe()
1355 snprintf(host->led_name, sizeof(host->led_name), in rtsx_usb_sdmmc_drv_probe()
1357 host->led.name = host->led_name; in rtsx_usb_sdmmc_drv_probe()
1358 host->led.brightness = LED_OFF; in rtsx_usb_sdmmc_drv_probe()
1359 host->led.default_trigger = mmc_hostname(mmc); in rtsx_usb_sdmmc_drv_probe()
1360 host->led.brightness_set = rtsx_usb_led_control; in rtsx_usb_sdmmc_drv_probe()
1362 err = led_classdev_register(mmc_dev(mmc), &host->led); in rtsx_usb_sdmmc_drv_probe()
1364 dev_err(&(pdev->dev), in rtsx_usb_sdmmc_drv_probe()
1366 INIT_WORK(&host->led_work, rtsx_usb_update_led); in rtsx_usb_sdmmc_drv_probe()
1372 led_classdev_unregister(&host->led); in rtsx_usb_sdmmc_drv_probe()
1375 pm_runtime_disable(&pdev->dev); in rtsx_usb_sdmmc_drv_probe()
1390 mmc = host->mmc; in rtsx_usb_sdmmc_drv_remove()
1391 host->host_removal = true; in rtsx_usb_sdmmc_drv_remove()
1393 mutex_lock(&host->host_mutex); in rtsx_usb_sdmmc_drv_remove()
1394 if (host->mrq) { in rtsx_usb_sdmmc_drv_remove()
1395 dev_dbg(&(pdev->dev), in rtsx_usb_sdmmc_drv_remove()
1398 host->mrq->cmd->error = -ENOMEDIUM; in rtsx_usb_sdmmc_drv_remove()
1399 if (host->mrq->stop) in rtsx_usb_sdmmc_drv_remove()
1400 host->mrq->stop->error = -ENOMEDIUM; in rtsx_usb_sdmmc_drv_remove()
1401 mmc_request_done(mmc, host->mrq); in rtsx_usb_sdmmc_drv_remove()
1403 mutex_unlock(&host->host_mutex); in rtsx_usb_sdmmc_drv_remove()
1408 cancel_work_sync(&host->led_work); in rtsx_usb_sdmmc_drv_remove()
1409 led_classdev_unregister(&host->led); in rtsx_usb_sdmmc_drv_remove()
1413 pm_runtime_disable(&pdev->dev); in rtsx_usb_sdmmc_drv_remove()
1416 dev_dbg(&(pdev->dev), in rtsx_usb_sdmmc_drv_remove()
1425 host->mmc->caps &= ~MMC_CAP_NEEDS_POLL; in rtsx_usb_sdmmc_runtime_suspend()
1433 host->mmc->caps |= MMC_CAP_NEEDS_POLL; in rtsx_usb_sdmmc_runtime_resume()
1434 if (sdmmc_get_cd(host->mmc) == 1) in rtsx_usb_sdmmc_runtime_resume()
1435 mmc_detect_change(host->mmc, 0); in rtsx_usb_sdmmc_runtime_resume()