25 #include <linux/sched.h>
66 for (i = 0; i <= chip->
max_lun; i++) {
83 #ifndef DISABLE_CARD_INT
89 #ifndef DISABLE_CARD_INT
90 for (i = 0; i <= chip->
max_lun; i++) {
155 #ifdef HW_AUTO_SWITCH_SD_BUS
156 static int rtsx_pre_handle_sdio_new(
struct rtsx_chip *chip)
159 int sw_bypass_sd = 0;
185 u8 cd_toggle_mask = 0;
189 cd_toggle_mask = 0x10;
191 cd_toggle_mask = 0x08;
193 if (tmp & cd_toggle_mask) {
365 #ifdef LED_AUTO_BLINK
511 rtsx_calibration(chip);
520 #ifdef HW_INT_WRITE_CLR
530 #ifdef HW_INT_WRITE_CLR
540 #ifdef HW_AUTO_SWITCH_SD_BUS
542 retval = rtsx_pre_handle_sdio_old(chip);
544 retval = rtsx_pre_handle_sdio_new(chip);
548 retval = rtsx_pre_handle_sdio_old(chip);
608 rtsx_reset_detected_cards(chip, 0);
615 static inline int check_sd_speed_prior(
u32 sd_speed_prior)
617 int i, fake_para = 0;
619 for (i = 0; i < 4; i++) {
620 u8 tmp = (
u8)(sd_speed_prior >> (i*8));
621 if ((tmp < 0x01) || (tmp > 0x04)) {
630 static inline int check_sd_current_prior(
u32 sd_current_prior)
632 int i, fake_para = 0;
634 for (i = 0; i < 4; i++) {
635 u8 tmp = (
u8)(sd_current_prior >> (i*8));
645 static int rts5209_init(
struct rtsx_chip *chip)
652 if ((val & 0x10) == 0)
696 val = (
u8)(lval >> 8);
698 clk = (val >> 5) & 0x07;
707 if (chip->
ss_en == 2) {
720 val = (
u8)(lval >> 16);
722 clk = (val >> 6) & 0x03;
728 clk = (val >> 4) & 0x03;
748 val = (
u8)(lval >> 24);
750 clk = (val >> 5) & 0x07;
766 0x1C, 0x02, 0x58, ®58);
771 0x1C, 0x02, 0x5B, ®5b);
775 RTSX_DEBUGP(
"reg58 = 0x%x, reg5b = 0x%x\n", reg58, reg5b);
777 if ((reg58 == 0x00) && (reg5b == 0x01))
785 static int rts5208_init(
struct rtsx_chip *chip)
803 RTSX_DEBUGP(
"Value of phy register 0x1C is 0x%x\n", reg);
846 static int rts5288_init(
struct rtsx_chip *chip)
849 u8 val = 0, max_func;
864 if (val & AUX_PWR_DETECTED)
886 max_func = (
u8)((lval >> 29) & 0x07);
887 RTSX_DEBUGP(
"Max function number: %d\n", max_func);
888 if (max_func == 0x02)
918 RTSX_DEBUGP(
"Vendor ID: 0x%04x, Product ID: 0x%04x\n",
981 retval = rts5209_init(chip);
986 retval = rts5208_init(chip);
991 retval = rts5288_init(chip);
997 if (chip->
ss_en == 2)
1049 #if !defined(LED_AUTO_BLINK) && defined(REGULAR_BLINK)
1050 static inline void rtsx_blink_led(
struct rtsx_chip *chip)
1063 static void rtsx_monitor_aspm_config(
struct rtsx_chip *chip)
1065 int maybe_support_aspm, reg_changed;
1069 maybe_support_aspm = 0;
1084 if ((reg0 & 0x03) && (
reg1 & 0x03))
1085 maybe_support_aspm = 1;
1089 maybe_support_aspm = 1;
1094 if (maybe_support_aspm)
1097 RTSX_DEBUGP(
"aspm_level[0] = 0x%02x, aspm_level[1] = 0x%02x\n",
1113 #ifdef SUPPORT_SD_LOCK
1156 #ifdef SUPPORT_SD_LOCK
1201 if (ss_allowed && !chip->
sd_io) {
1209 rtsx_exclusive_enter_ss(chip);
1216 rtsx_monitor_aspm_config(chip);
1218 #ifdef SUPPORT_SDIO_ASPM
1243 #if !defined(LED_AUTO_BLINK) && defined(REGULAR_BLINK)
1258 #if !defined(LED_AUTO_BLINK) && defined(REGULAR_BLINK)
1259 rtsx_blink_led(chip);
1278 #ifdef CONFIG_RTS_PSTOR_DEBUG
1331 RTSX_DEBUGP(
"False card inserted, do force delink\n");
1348 #ifdef HW_INT_WRITE_CLR
1399 for (i = 0; i <= 8; i++) {
1408 for (i = 0; i < 16; i++) {
1419 #define MAX_RW_REG_CNT 1024
1426 val |= (
u32)(addr & 0x3FFF) << 16;
1427 val |= (
u32)mask << 8;
1434 if ((val & (1 << 31)) == 0) {
1435 if (data != (
u8)val)
1453 val |= (
u32)(addr & 0x3FFF) << 16;
1459 if ((val & (1 << 31)) == 0)
1463 if (i >= MAX_RW_REG_CNT)
1467 *data = (
u8)(val & 0xFF);
1477 for (i = 0; i < 4; i++) {
1480 0xFF, (
u8)(val & mask & 0xFF));
1492 0x80 | mode | ((func_no & 0x03) << 4));
1496 if ((tmp & 0x80) == 0)
1516 if ((tmp & 0x80) == 0)
1520 for (i = 0; i < 4; i++) {
1522 data |= (
u32)tmp << (i * 8);
1544 if ((len + offset) % 4)
1545 dw_len = (len +
offset) / 4 + 1;
1547 dw_len = (len +
offset) / 4;
1562 for (i = 0; i < len; i++) {
1563 mask[
j] |= 0xFF << (offset * 8);
1564 data[
j] |= buf[
i] << (offset * 8);
1565 if (++offset == 4) {
1574 for (i = 0; i < dw_len; i++) {
1599 if ((len + offset) % 4)
1600 dw_len = (len +
offset) / 4 + 1;
1602 dw_len = (len +
offset) / 4;
1610 for (i = 0; i < dw_len; i++) {
1621 for (i = 0; i < len; i++) {
1622 buf[
i] = (
u8)(data[j] >> (offset * 8));
1623 if (++offset == 4) {
1645 for (i = 0; i < 100000; i++) {
1647 if (!(tmp & 0x80)) {
1668 for (i = 0; i < 100000; i++) {
1670 if (!(tmp & 0x80)) {
1682 data |= (
u16)tmp << 8;
1697 for (i = 0; i < 100; i++) {
1719 for (i = 0; i < 8; i++) {
1720 if (val & (
u8)(1 << i))
1723 tmp &= (~(
u8)(1 << i));
1729 for (j = 0; j < 100; j++) {
1754 if (value & (1 << bit)) {
1755 value &= ~(1 <<
bit);
1773 if (0 == (value & (1 << bit))) {
1774 value |= (1 <<
bit);
1799 static void rtsx_handle_pm_dstate(
struct rtsx_chip *chip,
u8 dstate)
1814 RTSX_DEBUGP(
"pm_dstate of function %d: 0x%x\n", (
int)func_no, ultmp);
1824 rtsx_handle_pm_dstate(chip, 2);
1921 #ifdef HW_INT_WRITE_CLR
1926 if (((chip->
int_reg & int_enable) == 0) || (chip->
int_reg == 0xFFFFFFFF))
1938 status = chip->
int_reg &= (int_enable | 0x7FFFFF);
1959 if (exit_ss && (status &
SD_EXIST))
1973 if (exit_ss && (status &
XD_EXIST))
1987 if (exit_ss && (status &
MS_EXIST))
2008 RTSX_DEBUGP(
"rtsx_do_before_power_down, pm_stat = %d\n", pm_stat);
2020 #ifdef HW_AUTO_SWITCH_SD_BUS
2047 if (pm_stat ==
PM_S1) {
2050 }
else if (pm_stat ==
PM_S3) {
2100 rtsx_monitor_aspm_config(chip);
2133 for (i = 0; i < buf_len/256; i++) {
2136 for (j = 0; j < 256; j++)
2150 for (j = 0; j < buf_len%256; j++)
2175 for (i = 0; i < buf_len/256; i++) {
2178 for (j = 0; j < 256; j++) {
2191 for (j = 0; j < buf_len%256; j++) {