#include <linux/module.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/platform_device.h>
#include <linux/usb.h>
#include <linux/mmc/host.h>
#include <linux/mmc/mmc.h>
#include <linux/mmc/sd.h>
#include <linux/mmc/card.h>
#include <linux/scatterlist.h>
#include <linux/pm.h>
#include <linux/pm_runtime.h>
#include <linux/rtsx_usb.h>
#include <asm/unaligned.h>
#if defined(CONFIG_LEDS_CLASS) || (defined(CONFIG_LEDS_CLASS_MODULE) && \
defined(CONFIG_MMC_REALTEK_USB_MODULE))
#include <linux/leds.h>
#include <linux/workqueue.h>
#define RTSX_USB_USE_LEDS_CLASS
#endif
struct rtsx_usb_sdmmc { … };
static inline struct device *sdmmc_dev(struct rtsx_usb_sdmmc *host)
{ … }
static inline void sd_clear_error(struct rtsx_usb_sdmmc *host)
{ … }
#ifdef DEBUG
static void sd_print_debug_regs(struct rtsx_usb_sdmmc *host)
{
struct rtsx_ucr *ucr = host->ucr;
u8 val = 0;
rtsx_usb_ep0_read_register(ucr, SD_STAT1, &val);
dev_dbg(sdmmc_dev(host), "SD_STAT1: 0x%x\n", val);
rtsx_usb_ep0_read_register(ucr, SD_STAT2, &val);
dev_dbg(sdmmc_dev(host), "SD_STAT2: 0x%x\n", val);
rtsx_usb_ep0_read_register(ucr, SD_BUS_STAT, &val);
dev_dbg(sdmmc_dev(host), "SD_BUS_STAT: 0x%x\n", val);
}
#else
#define sd_print_debug_regs(host) …
#endif
static int sd_read_data(struct rtsx_usb_sdmmc *host, struct mmc_command *cmd,
u16 byte_cnt, u8 *buf, int buf_len, int timeout)
{ … }
static int sd_write_data(struct rtsx_usb_sdmmc *host, struct mmc_command *cmd,
u16 byte_cnt, u8 *buf, int buf_len, int timeout)
{ … }
static void sd_send_cmd_get_rsp(struct rtsx_usb_sdmmc *host,
struct mmc_command *cmd)
{ … }
static int sd_rw_multi(struct rtsx_usb_sdmmc *host, struct mmc_request *mrq)
{ … }
static inline void sd_enable_initial_mode(struct rtsx_usb_sdmmc *host)
{ … }
static inline void sd_disable_initial_mode(struct rtsx_usb_sdmmc *host)
{ … }
static void sd_normal_rw(struct rtsx_usb_sdmmc *host,
struct mmc_request *mrq)
{ … }
static int sd_change_phase(struct rtsx_usb_sdmmc *host, u8 sample_point, int tx)
{ … }
static inline u32 get_phase_point(u32 phase_map, unsigned int idx)
{ … }
static int get_phase_len(u32 phase_map, unsigned int idx)
{ … }
static u8 sd_search_final_phase(struct rtsx_usb_sdmmc *host, u32 phase_map)
{ … }
static void sd_wait_data_idle(struct rtsx_usb_sdmmc *host)
{ … }
static int sd_tuning_rx_cmd(struct rtsx_usb_sdmmc *host,
u8 opcode, u8 sample_point)
{ … }
static void sd_tuning_phase(struct rtsx_usb_sdmmc *host,
u8 opcode, u16 *phase_map)
{ … }
static int sd_tuning_rx(struct rtsx_usb_sdmmc *host, u8 opcode)
{ … }
static int sdmmc_get_ro(struct mmc_host *mmc)
{ … }
static int sdmmc_get_cd(struct mmc_host *mmc)
{ … }
static void sdmmc_request(struct mmc_host *mmc, struct mmc_request *mrq)
{ … }
static int sd_set_bus_width(struct rtsx_usb_sdmmc *host,
unsigned char bus_width)
{ … }
static int sd_pull_ctl_disable_lqfp48(struct rtsx_ucr *ucr)
{ … }
static int sd_pull_ctl_disable_qfn24(struct rtsx_ucr *ucr)
{ … }
static int sd_pull_ctl_enable_lqfp48(struct rtsx_ucr *ucr)
{ … }
static int sd_pull_ctl_enable_qfn24(struct rtsx_ucr *ucr)
{ … }
static int sd_power_on(struct rtsx_usb_sdmmc *host)
{ … }
static int sd_power_off(struct rtsx_usb_sdmmc *host)
{ … }
static int sd_set_power_mode(struct rtsx_usb_sdmmc *host,
unsigned char power_mode)
{ … }
static int sd_set_timing(struct rtsx_usb_sdmmc *host,
unsigned char timing, bool *ddr_mode)
{ … }
static void sdmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
{ … }
static int sdmmc_switch_voltage(struct mmc_host *mmc, struct mmc_ios *ios)
{ … }
static int sdmmc_card_busy(struct mmc_host *mmc)
{ … }
static int sdmmc_execute_tuning(struct mmc_host *mmc, u32 opcode)
{ … }
static const struct mmc_host_ops rtsx_usb_sdmmc_ops = …;
#ifdef RTSX_USB_USE_LEDS_CLASS
static void rtsx_usb_led_control(struct led_classdev *led,
enum led_brightness brightness)
{ … }
static void rtsx_usb_update_led(struct work_struct *work)
{ … }
#endif
static void rtsx_usb_init_host(struct rtsx_usb_sdmmc *host)
{ … }
static int rtsx_usb_sdmmc_drv_probe(struct platform_device *pdev)
{ … }
static void rtsx_usb_sdmmc_drv_remove(struct platform_device *pdev)
{ … }
#ifdef CONFIG_PM
static int rtsx_usb_sdmmc_runtime_suspend(struct device *dev)
{ … }
static int rtsx_usb_sdmmc_runtime_resume(struct device *dev)
{ … }
#endif
static const struct dev_pm_ops rtsx_usb_sdmmc_dev_pm_ops = …;
static const struct platform_device_id rtsx_usb_sdmmc_ids[] = …;
MODULE_DEVICE_TABLE(platform, rtsx_usb_sdmmc_ids);
static struct platform_driver rtsx_usb_sdmmc_driver = …;
module_platform_driver(…) …;
MODULE_LICENSE(…) …;
MODULE_AUTHOR(…) …;
MODULE_DESCRIPTION(…) …;