rtsx_polling_func is a big function that manage a lot of independent
tasks.
This patch aims to refactor the code using a series of helper functions,
to make it more readable.
Plus, the following checkpatch warning is corrected:
* PARENTHESIS_ALIGNMENT at row 1246
Fabio Falzoi (7):
Staging: rts5208: helper function to manage sd erase status
Staging: rts5208: helper function to manage power off
Staging: rts5208: helper function to manage ss
Staging: rts5208: helper function to manage aspm
Staging: rts5208: helper function to manage idle
Staging: rts5208: helper function to manage 1lun and 2lun modes
Staging: rts5208: helper function to manage delink states
drivers/staging/rts5208/rtsx_chip.c | 452 +++++++++++++++++++-----------------
1 file changed, 244 insertions(+), 208 deletions(-)
--
2.1.4
Use a helper function to manage SD erase status when SUPPORT_SD_LOCK is
defined
Signed-off-by: Fabio Falzoi <[email protected]>
---
drivers/staging/rts5208/rtsx_chip.c | 38 ++++++++++++++++++++-----------------
1 file changed, 21 insertions(+), 17 deletions(-)
diff --git a/drivers/staging/rts5208/rtsx_chip.c b/drivers/staging/rts5208/rtsx_chip.c
index 0c1716e..e7d3280 100644
--- a/drivers/staging/rts5208/rtsx_chip.c
+++ b/drivers/staging/rts5208/rtsx_chip.c
@@ -1143,11 +1143,30 @@ static void rtsx_monitor_aspm_config(struct rtsx_chip *chip)
}
}
-void rtsx_polling_func(struct rtsx_chip *chip)
+static void rtsx_manage_sd_lock(struct rtsx_chip *chip)
{
#ifdef SUPPORT_SD_LOCK
struct sd_info *sd_card = &chip->sd_card;
+ u8 val;
+
+ if (!sd_card->sd_erase_status)
+ return;
+
+ if (chip->card_exist & SD_CARD) {
+ rtsx_read_register(chip, 0xFD30, &val);
+ if (val & 0x02) {
+ sd_card->sd_erase_status = SD_NOT_ERASE;
+ sd_card->sd_lock_notify = 1;
+ chip->need_reinit |= SD_CARD;
+ }
+ } else {
+ sd_card->sd_erase_status = SD_NOT_ERASE;
+ }
#endif
+}
+
+void rtsx_polling_func(struct rtsx_chip *chip)
+{
bool ss_allowed;
if (rtsx_chk_stat(chip, RTSX_STAT_SUSPEND))
@@ -1180,22 +1199,7 @@ void rtsx_polling_func(struct rtsx_chip *chip)
}
#endif
-#ifdef SUPPORT_SD_LOCK
- if (sd_card->sd_erase_status) {
- if (chip->card_exist & SD_CARD) {
- u8 val;
-
- rtsx_read_register(chip, 0xFD30, &val);
- if (val & 0x02) {
- sd_card->sd_erase_status = SD_NOT_ERASE;
- sd_card->sd_lock_notify = 1;
- chip->need_reinit |= SD_CARD;
- }
- } else {
- sd_card->sd_erase_status = SD_NOT_ERASE;
- }
- }
-#endif
+ rtsx_manage_sd_lock(chip);
rtsx_init_cards(chip);
--
2.1.4
Use a helper function to check if power off is needed.
Signed-off-by: Fabio Falzoi <[email protected]>
---
drivers/staging/rts5208/rtsx_chip.c | 34 ++++++++++++++++++++--------------
1 file changed, 20 insertions(+), 14 deletions(-)
diff --git a/drivers/staging/rts5208/rtsx_chip.c b/drivers/staging/rts5208/rtsx_chip.c
index e7d3280..5946cc4 100644
--- a/drivers/staging/rts5208/rtsx_chip.c
+++ b/drivers/staging/rts5208/rtsx_chip.c
@@ -1143,6 +1143,25 @@ static void rtsx_monitor_aspm_config(struct rtsx_chip *chip)
}
}
+static void rtsx_manage_ocp(struct rtsx_chip *chip)
+{
+#ifdef SUPPORT_OCP
+ if (!chip->ocp_int)
+ return;
+
+ rtsx_read_register(chip, OCPSTAT, &chip->ocp_stat);
+
+ if (chip->card_exist & SD_CARD)
+ sd_power_off_card3v3(chip);
+ else if (chip->card_exist & MS_CARD)
+ ms_power_off_card3v3(chip);
+ else if (chip->card_exist & XD_CARD)
+ xd_power_off_card3v3(chip);
+
+ chip->ocp_int = 0;
+#endif
+}
+
static void rtsx_manage_sd_lock(struct rtsx_chip *chip)
{
#ifdef SUPPORT_SD_LOCK
@@ -1184,20 +1203,7 @@ void rtsx_polling_func(struct rtsx_chip *chip)
if (rtsx_chk_stat(chip, RTSX_STAT_SS))
return;
-#ifdef SUPPORT_OCP
- if (chip->ocp_int) {
- rtsx_read_register(chip, OCPSTAT, &chip->ocp_stat);
-
- if (chip->card_exist & SD_CARD)
- sd_power_off_card3v3(chip);
- else if (chip->card_exist & MS_CARD)
- ms_power_off_card3v3(chip);
- else if (chip->card_exist & XD_CARD)
- xd_power_off_card3v3(chip);
-
- chip->ocp_int = 0;
- }
-#endif
+ rtsx_manage_ocp(chip);
rtsx_manage_sd_lock(chip);
--
2.1.4
Use a helper function to manage ss_counter
Signed-off-by: Fabio Falzoi <[email protected]>
---
drivers/staging/rts5208/rtsx_chip.c | 66 ++++++++++++++++++-------------------
1 file changed, 33 insertions(+), 33 deletions(-)
diff --git a/drivers/staging/rts5208/rtsx_chip.c b/drivers/staging/rts5208/rtsx_chip.c
index 5946cc4..373ccd0 100644
--- a/drivers/staging/rts5208/rtsx_chip.c
+++ b/drivers/staging/rts5208/rtsx_chip.c
@@ -1184,10 +1184,40 @@ static void rtsx_manage_sd_lock(struct rtsx_chip *chip)
#endif
}
-void rtsx_polling_func(struct rtsx_chip *chip)
+static bool rtsx_is_ss_allowed(struct rtsx_chip *chip)
+{
+ u32 val;
+
+ if (!chip->ss_en || CHECK_PID(chip, 0x5288))
+ return false;
+
+ if (CHK_SDIO_EXIST(chip) && !CHK_SDIO_IGNORED(chip)) {
+ rtsx_read_cfg_dw(chip, 1, 0x04, &val);
+ if (val & 0x07)
+ return false;
+ }
+
+ return true;
+}
+
+static void rtsx_manage_ss(struct rtsx_chip *chip)
{
- bool ss_allowed;
+ if (!rtsx_is_ss_allowed(chip) || chip->sd_io)
+ return;
+
+ if (rtsx_get_stat(chip) != RTSX_STAT_IDLE) {
+ chip->ss_counter = 0;
+ return;
+ }
+ if (chip->ss_counter < (chip->ss_idle_period / POLLING_INTERVAL))
+ chip->ss_counter++;
+ else
+ rtsx_exclusive_enter_ss(chip);
+}
+
+void rtsx_polling_func(struct rtsx_chip *chip)
+{
if (rtsx_chk_stat(chip, RTSX_STAT_SUSPEND))
return;
@@ -1209,37 +1239,7 @@ void rtsx_polling_func(struct rtsx_chip *chip)
rtsx_init_cards(chip);
- if (chip->ss_en) {
- ss_allowed = true;
-
- if (CHECK_PID(chip, 0x5288)) {
- ss_allowed = false;
- } else {
- if (CHK_SDIO_EXIST(chip) && !CHK_SDIO_IGNORED(chip)) {
- u32 val;
-
- rtsx_read_cfg_dw(chip, 1, 0x04, &val);
- if (val & 0x07)
- ss_allowed = false;
- }
- }
- } else {
- ss_allowed = false;
- }
-
- if (ss_allowed && !chip->sd_io) {
- if (rtsx_get_stat(chip) != RTSX_STAT_IDLE) {
- chip->ss_counter = 0;
- } else {
- if (chip->ss_counter <
- (chip->ss_idle_period / POLLING_INTERVAL)) {
- chip->ss_counter++;
- } else {
- rtsx_exclusive_enter_ss(chip);
- return;
- }
- }
- }
+ rtsx_manage_ss(chip);
if (CHECK_PID(chip, 0x5208)) {
rtsx_monitor_aspm_config(chip);
--
2.1.4
Use a helper function to manage aspm mode
Signed-off-by: Fabio Falzoi <[email protected]>
---
drivers/staging/rts5208/rtsx_chip.c | 51 ++++++++++++++++++++++---------------
1 file changed, 30 insertions(+), 21 deletions(-)
diff --git a/drivers/staging/rts5208/rtsx_chip.c b/drivers/staging/rts5208/rtsx_chip.c
index 373ccd0..ee331f2 100644
--- a/drivers/staging/rts5208/rtsx_chip.c
+++ b/drivers/staging/rts5208/rtsx_chip.c
@@ -1216,6 +1216,35 @@ static void rtsx_manage_ss(struct rtsx_chip *chip)
rtsx_exclusive_enter_ss(chip);
}
+static void rtsx_manage_aspm(struct rtsx_chip *chip)
+{
+ u8 data;
+
+ if (!CHECK_PID(chip, 0x5208))
+ return;
+
+ rtsx_monitor_aspm_config(chip);
+
+#ifdef SUPPORT_SDIO_ASPM
+ if (!CHK_SDIO_EXIST(chip) || CHK_SDIO_IGNORED(chip) ||
+ !chip->aspm_l0s_l1_en || !chip->dynamic_aspm)
+ return;
+
+ if (chip->sd_io) {
+ dynamic_configure_sdio_aspm(chip);
+ return;
+ }
+
+ if (chip->sdio_aspm)
+ return;
+
+ dev_dbg(rtsx_dev(chip), "SDIO enter ASPM!\n");
+ data = 0x30 | (chip->aspm_level[1] << 2);
+ rtsx_write_register(chip, ASPM_FORCE_CTL, 0xFC, data);
+ chip->sdio_aspm = 1;
+#endif
+}
+
void rtsx_polling_func(struct rtsx_chip *chip)
{
if (rtsx_chk_stat(chip, RTSX_STAT_SUSPEND))
@@ -1241,27 +1270,7 @@ void rtsx_polling_func(struct rtsx_chip *chip)
rtsx_manage_ss(chip);
- if (CHECK_PID(chip, 0x5208)) {
- rtsx_monitor_aspm_config(chip);
-
-#ifdef SUPPORT_SDIO_ASPM
- if (CHK_SDIO_EXIST(chip) && !CHK_SDIO_IGNORED(chip) &&
- chip->aspm_l0s_l1_en && chip->dynamic_aspm) {
- if (chip->sd_io) {
- dynamic_configure_sdio_aspm(chip);
- } else {
- if (!chip->sdio_aspm) {
- dev_dbg(rtsx_dev(chip), "SDIO enter ASPM!\n");
- rtsx_write_register(chip,
- ASPM_FORCE_CTL, 0xFC,
- 0x30 |
- (chip->aspm_level[1] << 2));
- chip->sdio_aspm = 1;
- }
- }
- }
-#endif
- }
+ rtsx_manage_aspm(chip);
if (chip->idle_counter < IDLE_MAX_COUNT) {
chip->idle_counter++;
--
2.1.4
Use a helper function to manage idle state
Signed-off-by: Fabio Falzoi <[email protected]>
---
drivers/staging/rts5208/rtsx_chip.c | 45 ++++++++++++++++++++-----------------
1 file changed, 25 insertions(+), 20 deletions(-)
diff --git a/drivers/staging/rts5208/rtsx_chip.c b/drivers/staging/rts5208/rtsx_chip.c
index ee331f2..01b20fb 100644
--- a/drivers/staging/rts5208/rtsx_chip.c
+++ b/drivers/staging/rts5208/rtsx_chip.c
@@ -1245,6 +1245,30 @@ static void rtsx_manage_aspm(struct rtsx_chip *chip)
#endif
}
+static void rtsx_manage_idle(struct rtsx_chip *chip)
+{
+ if (chip->idle_counter < IDLE_MAX_COUNT) {
+ chip->idle_counter++;
+ return;
+ }
+
+ if (rtsx_get_stat(chip) == RTSX_STAT_IDLE)
+ return;
+
+ dev_dbg(rtsx_dev(chip), "Idle state!\n");
+ rtsx_set_stat(chip, RTSX_STAT_IDLE);
+
+#if !defined(LED_AUTO_BLINK) && defined(REGULAR_BLINK)
+ chip->led_toggle_counter = 0;
+#endif
+ rtsx_force_power_on(chip, SSC_PDCTL);
+
+ turn_off_led(chip, LED_GPIO);
+
+ if (chip->auto_power_down && !chip->card_ready && !chip->sd_io)
+ rtsx_force_power_down(chip, SSC_PDCTL | OC_PDCTL);
+}
+
void rtsx_polling_func(struct rtsx_chip *chip)
{
if (rtsx_chk_stat(chip, RTSX_STAT_SUSPEND))
@@ -1272,26 +1296,7 @@ void rtsx_polling_func(struct rtsx_chip *chip)
rtsx_manage_aspm(chip);
- if (chip->idle_counter < IDLE_MAX_COUNT) {
- chip->idle_counter++;
- } else {
- if (rtsx_get_stat(chip) != RTSX_STAT_IDLE) {
- dev_dbg(rtsx_dev(chip), "Idle state!\n");
- rtsx_set_stat(chip, RTSX_STAT_IDLE);
-
-#if !defined(LED_AUTO_BLINK) && defined(REGULAR_BLINK)
- chip->led_toggle_counter = 0;
-#endif
- rtsx_force_power_on(chip, SSC_PDCTL);
-
- turn_off_led(chip, LED_GPIO);
-
- if (chip->auto_power_down && !chip->card_ready &&
- !chip->sd_io)
- rtsx_force_power_down(chip,
- SSC_PDCTL | OC_PDCTL);
- }
- }
+ rtsx_manage_idle(chip);
switch (rtsx_get_stat(chip)) {
case RTSX_STAT_RUN:
--
2.1.4
Use a helper function to manage lun modes when SUPPORT_OCP is defined
Signed-off-by: Fabio Falzoi <[email protected]>
---
drivers/staging/rts5208/rtsx_chip.c | 97 ++++++++++++++++++++-----------------
1 file changed, 53 insertions(+), 44 deletions(-)
diff --git a/drivers/staging/rts5208/rtsx_chip.c b/drivers/staging/rts5208/rtsx_chip.c
index 01b20fb..298163a 100644
--- a/drivers/staging/rts5208/rtsx_chip.c
+++ b/drivers/staging/rts5208/rtsx_chip.c
@@ -1269,6 +1269,55 @@ static void rtsx_manage_idle(struct rtsx_chip *chip)
rtsx_force_power_down(chip, SSC_PDCTL | OC_PDCTL);
}
+static void rtsx_manage_2lun_mode(struct rtsx_chip *chip)
+{
+#ifdef SUPPORT_OCP
+ u8 sd_oc, ms_oc;
+
+ sd_oc = chip->ocp_stat & (SD_OC_NOW | SD_OC_EVER);
+ ms_oc = chip->ocp_stat & (MS_OC_NOW | MS_OC_EVER);
+
+ if (sd_oc || ms_oc)
+ dev_dbg(rtsx_dev(chip), "Over current, OCPSTAT is 0x%x\n",
+ chip->ocp_stat);
+
+ if (sd_oc && (chip->card_exist & SD_CARD)) {
+ rtsx_write_register(chip, CARD_OE, SD_OUTPUT_EN, 0);
+ card_power_off(chip, SD_CARD);
+ chip->card_fail |= SD_CARD;
+ }
+
+ if (ms_oc && (chip->card_exist & MS_CARD)) {
+ rtsx_write_register(chip, CARD_OE, MS_OUTPUT_EN, 0);
+ card_power_off(chip, MS_CARD);
+ chip->card_fail |= MS_CARD;
+ }
+#endif
+}
+
+static void rtsx_manage_1lun_mode(struct rtsx_chip *chip)
+{
+#ifdef SUPPORT_OCP
+ if (!(chip->ocp_stat & (SD_OC_NOW | SD_OC_EVER)))
+ return;
+
+ dev_dbg(rtsx_dev(chip), "Over current, OCPSTAT is 0x%x\n",
+ chip->ocp_stat);
+
+ if (chip->card_exist & SD_CARD) {
+ rtsx_write_register(chip, CARD_OE, SD_OUTPUT_EN, 0);
+ chip->card_fail |= SD_CARD;
+ } else if (chip->card_exist & MS_CARD) {
+ rtsx_write_register(chip, CARD_OE, MS_OUTPUT_EN, 0);
+ chip->card_fail |= MS_CARD;
+ } else if (chip->card_exist & XD_CARD) {
+ rtsx_write_register(chip, CARD_OE, XD_OUTPUT_EN, 0);
+ chip->card_fail |= XD_CARD;
+ }
+ card_power_off(chip, SD_CARD);
+#endif
+}
+
void rtsx_polling_func(struct rtsx_chip *chip)
{
if (rtsx_chk_stat(chip, RTSX_STAT_SUSPEND))
@@ -1317,50 +1366,10 @@ void rtsx_polling_func(struct rtsx_chip *chip)
break;
}
-#ifdef SUPPORT_OCP
- if (CHECK_LUN_MODE(chip, SD_MS_2LUN)) {
- if (chip->ocp_stat &
- (SD_OC_NOW | SD_OC_EVER | MS_OC_NOW | MS_OC_EVER))
- dev_dbg(rtsx_dev(chip), "Over current, OCPSTAT is 0x%x\n",
- chip->ocp_stat);
-
- if (chip->ocp_stat & (SD_OC_NOW | SD_OC_EVER)) {
- if (chip->card_exist & SD_CARD) {
- rtsx_write_register(chip, CARD_OE, SD_OUTPUT_EN,
- 0);
- card_power_off(chip, SD_CARD);
- chip->card_fail |= SD_CARD;
- }
- }
- if (chip->ocp_stat & (MS_OC_NOW | MS_OC_EVER)) {
- if (chip->card_exist & MS_CARD) {
- rtsx_write_register(chip, CARD_OE, MS_OUTPUT_EN,
- 0);
- card_power_off(chip, MS_CARD);
- chip->card_fail |= MS_CARD;
- }
- }
- } else {
- if (chip->ocp_stat & (SD_OC_NOW | SD_OC_EVER)) {
- dev_dbg(rtsx_dev(chip), "Over current, OCPSTAT is 0x%x\n",
- chip->ocp_stat);
- if (chip->card_exist & SD_CARD) {
- rtsx_write_register(chip, CARD_OE, SD_OUTPUT_EN,
- 0);
- chip->card_fail |= SD_CARD;
- } else if (chip->card_exist & MS_CARD) {
- rtsx_write_register(chip, CARD_OE, MS_OUTPUT_EN,
- 0);
- chip->card_fail |= MS_CARD;
- } else if (chip->card_exist & XD_CARD) {
- rtsx_write_register(chip, CARD_OE, XD_OUTPUT_EN,
- 0);
- chip->card_fail |= XD_CARD;
- }
- card_power_off(chip, SD_CARD);
- }
- }
-#endif
+ if (CHECK_LUN_MODE(chip, SD_MS_2LUN))
+ rtsx_manage_2lun_mode(chip);
+ else
+ rtsx_manage_1lun_mode(chip);
delink_stage:
if (chip->auto_delink_en && chip->auto_delink_allowed &&
--
2.1.4
Use a helper function to manage delink states
Signed-off-by: Fabio Falzoi <[email protected]>
---
drivers/staging/rts5208/rtsx_chip.c | 141 ++++++++++++++++++------------------
1 file changed, 72 insertions(+), 69 deletions(-)
diff --git a/drivers/staging/rts5208/rtsx_chip.c b/drivers/staging/rts5208/rtsx_chip.c
index 298163a..d6fb6cd 100644
--- a/drivers/staging/rts5208/rtsx_chip.c
+++ b/drivers/staging/rts5208/rtsx_chip.c
@@ -1318,6 +1318,77 @@ static void rtsx_manage_1lun_mode(struct rtsx_chip *chip)
#endif
}
+static void rtsx_delink_stage1(struct rtsx_chip *chip, int enter_L1,
+ int stage3_cnt)
+{
+ u8 val;
+
+ rtsx_set_stat(chip, RTSX_STAT_DELINK);
+
+ if (chip->asic_code && CHECK_PID(chip, 0x5208))
+ rtsx_set_phy_reg_bit(chip, 0x1C, 2);
+
+ if (chip->card_exist)
+ dev_dbg(rtsx_dev(chip), "False card inserted, do force delink\n");
+ else
+ dev_dbg(rtsx_dev(chip), "No card inserted, do delink\n");
+
+ if (enter_L1)
+ rtsx_write_register(chip, HOST_SLEEP_STATE, 0x03, 1);
+
+ if (chip->card_exist)
+ val = 0x03;
+ else
+ val = 0x0A;
+
+ rtsx_write_register(chip, CHANGE_LINK_STATE, val, val);
+
+ if (enter_L1)
+ rtsx_enter_L1(chip);
+
+ if (chip->card_exist)
+ chip->auto_delink_cnt = stage3_cnt + 1;
+}
+
+static void rtsx_delink_stage(struct rtsx_chip *chip)
+{
+ int delink_stage1_cnt, delink_stage2_cnt, delink_stage3_cnt;
+ int enter_L1;
+
+ if (!chip->auto_delink_en || !chip->auto_delink_allowed ||
+ chip->card_ready || chip->card_ejected || chip->sd_io) {
+ chip->auto_delink_cnt = 0;
+ return;
+ }
+
+ enter_L1 = chip->auto_delink_in_L1 &&
+ (chip->aspm_l0s_l1_en || chip->ss_en);
+
+ delink_stage1_cnt = chip->delink_stage1_step;
+ delink_stage2_cnt = delink_stage1_cnt + chip->delink_stage2_step;
+ delink_stage3_cnt = delink_stage2_cnt + chip->delink_stage3_step;
+
+ if (chip->auto_delink_cnt > delink_stage3_cnt)
+ return;
+
+ if (chip->auto_delink_cnt == delink_stage1_cnt)
+ rtsx_delink_stage1(chip, enter_L1, delink_stage3_cnt);
+
+ if (chip->auto_delink_cnt == delink_stage2_cnt) {
+ dev_dbg(rtsx_dev(chip), "Try to do force delink\n");
+
+ if (enter_L1)
+ rtsx_exit_L1(chip);
+
+ if (chip->asic_code && CHECK_PID(chip, 0x5208))
+ rtsx_set_phy_reg_bit(chip, 0x1C, 2);
+
+ rtsx_write_register(chip, CHANGE_LINK_STATE, 0x0A, 0x0A);
+ }
+
+ chip->auto_delink_cnt++;
+}
+
void rtsx_polling_func(struct rtsx_chip *chip)
{
if (rtsx_chk_stat(chip, RTSX_STAT_SUSPEND))
@@ -1372,75 +1443,7 @@ void rtsx_polling_func(struct rtsx_chip *chip)
rtsx_manage_1lun_mode(chip);
delink_stage:
- if (chip->auto_delink_en && chip->auto_delink_allowed &&
- !chip->card_ready && !chip->card_ejected && !chip->sd_io) {
- int enter_L1 = chip->auto_delink_in_L1 && (
- chip->aspm_l0s_l1_en || chip->ss_en);
- int delink_stage1_cnt = chip->delink_stage1_step;
- int delink_stage2_cnt = delink_stage1_cnt +
- chip->delink_stage2_step;
- int delink_stage3_cnt = delink_stage2_cnt +
- chip->delink_stage3_step;
-
- if (chip->auto_delink_cnt <= delink_stage3_cnt) {
- if (chip->auto_delink_cnt == delink_stage1_cnt) {
- rtsx_set_stat(chip, RTSX_STAT_DELINK);
-
- if (chip->asic_code && CHECK_PID(chip, 0x5208))
- rtsx_set_phy_reg_bit(chip, 0x1C, 2);
-
- if (chip->card_exist) {
- dev_dbg(rtsx_dev(chip), "False card inserted, do force delink\n");
-
- if (enter_L1)
- rtsx_write_register(chip,
- HOST_SLEEP_STATE,
- 0x03, 1);
-
- rtsx_write_register(chip,
- CHANGE_LINK_STATE,
- 0x0A, 0x0A);
-
- if (enter_L1)
- rtsx_enter_L1(chip);
-
- chip->auto_delink_cnt =
- delink_stage3_cnt + 1;
- } else {
- dev_dbg(rtsx_dev(chip), "No card inserted, do delink\n");
-
- if (enter_L1)
- rtsx_write_register(chip,
- HOST_SLEEP_STATE,
- 0x03, 1);
-
- rtsx_write_register(chip,
- CHANGE_LINK_STATE,
- 0x02, 0x02);
-
- if (enter_L1)
- rtsx_enter_L1(chip);
- }
- }
-
- if (chip->auto_delink_cnt == delink_stage2_cnt) {
- dev_dbg(rtsx_dev(chip), "Try to do force delink\n");
-
- if (enter_L1)
- rtsx_exit_L1(chip);
-
- if (chip->asic_code && CHECK_PID(chip, 0x5208))
- rtsx_set_phy_reg_bit(chip, 0x1C, 2);
-
- rtsx_write_register(chip, CHANGE_LINK_STATE,
- 0x0A, 0x0A);
- }
-
- chip->auto_delink_cnt++;
- }
- } else {
- chip->auto_delink_cnt = 0;
- }
+ rtsx_delink_stage(chip);
}
void rtsx_undo_delink(struct rtsx_chip *chip)
--
2.1.4
On Sun, Jun 14, 2015 at 03:48:53PM +0200, Fabio Falzoi wrote:
> Use a helper function to manage delink states
>
> Signed-off-by: Fabio Falzoi <[email protected]>
> ---
> drivers/staging/rts5208/rtsx_chip.c | 141 ++++++++++++++++++------------------
> 1 file changed, 72 insertions(+), 69 deletions(-)
>
> diff --git a/drivers/staging/rts5208/rtsx_chip.c b/drivers/staging/rts5208/rtsx_chip.c
> index 298163a..d6fb6cd 100644
> --- a/drivers/staging/rts5208/rtsx_chip.c
> +++ b/drivers/staging/rts5208/rtsx_chip.c
> @@ -1318,6 +1318,77 @@ static void rtsx_manage_1lun_mode(struct rtsx_chip *chip)
> #endif
> }
>
> +static void rtsx_delink_stage1(struct rtsx_chip *chip, int enter_L1,
> + int stage3_cnt)
> +{
> + u8 val;
> +
> + rtsx_set_stat(chip, RTSX_STAT_DELINK);
> +
> + if (chip->asic_code && CHECK_PID(chip, 0x5208))
> + rtsx_set_phy_reg_bit(chip, 0x1C, 2);
> +
> + if (chip->card_exist)
> + dev_dbg(rtsx_dev(chip), "False card inserted, do force delink\n");
> + else
> + dev_dbg(rtsx_dev(chip), "No card inserted, do delink\n");
> +
> + if (enter_L1)
> + rtsx_write_register(chip, HOST_SLEEP_STATE, 0x03, 1);
> +
> + if (chip->card_exist)
> + val = 0x03;
This should be 0x02. Please fix it in another patch.
> + else
> + val = 0x0A;
> +
> + rtsx_write_register(chip, CHANGE_LINK_STATE, val, val);
> +
> + if (enter_L1)
> + rtsx_enter_L1(chip);
> +
> + if (chip->card_exist)
> + chip->auto_delink_cnt = stage3_cnt + 1;
> +}
> +
> +static void rtsx_delink_stage(struct rtsx_chip *chip)
> +{
> + int delink_stage1_cnt, delink_stage2_cnt, delink_stage3_cnt;
> + int enter_L1;
> +
> + if (!chip->auto_delink_en || !chip->auto_delink_allowed ||
> + chip->card_ready || chip->card_ejected || chip->sd_io) {
> + chip->auto_delink_cnt = 0;
> + return;
> + }
> +
> + enter_L1 = chip->auto_delink_in_L1 &&
> + (chip->aspm_l0s_l1_en || chip->ss_en);
> +
> + delink_stage1_cnt = chip->delink_stage1_step;
> + delink_stage2_cnt = delink_stage1_cnt + chip->delink_stage2_step;
> + delink_stage3_cnt = delink_stage2_cnt + chip->delink_stage3_step;
> +
> + if (chip->auto_delink_cnt > delink_stage3_cnt)
> + return;
> +
> + if (chip->auto_delink_cnt == delink_stage1_cnt)
> + rtsx_delink_stage1(chip, enter_L1, delink_stage3_cnt);
> +
> + if (chip->auto_delink_cnt == delink_stage2_cnt) {
> + dev_dbg(rtsx_dev(chip), "Try to do force delink\n");
> +
> + if (enter_L1)
> + rtsx_exit_L1(chip);
> +
> + if (chip->asic_code && CHECK_PID(chip, 0x5208))
> + rtsx_set_phy_reg_bit(chip, 0x1C, 2);
> +
> + rtsx_write_register(chip, CHANGE_LINK_STATE, 0x0A, 0x0A);
> + }
> +
> + chip->auto_delink_cnt++;
You didn't introduce this, but I'm not positive the
chip->auto_delink_cnt value is correct. It feels like
rtsx_delink_stage1() increments it; fine; but then if it's
not equal to delink_stage2_cnt should we increment it again?
It's fine if you don't know the answer, I was just wondering if maybe
someone on the CC list knows.
regards,
dan carpenter
> +}
> +
> void rtsx_polling_func(struct rtsx_chip *chip)
> {
> if (rtsx_chk_stat(chip, RTSX_STAT_SUSPEND))
> @@ -1372,75 +1443,7 @@ void rtsx_polling_func(struct rtsx_chip *chip)
> rtsx_manage_1lun_mode(chip);
>
> delink_stage:
> - if (chip->auto_delink_en && chip->auto_delink_allowed &&
> - !chip->card_ready && !chip->card_ejected && !chip->sd_io) {
> - int enter_L1 = chip->auto_delink_in_L1 && (
> - chip->aspm_l0s_l1_en || chip->ss_en);
> - int delink_stage1_cnt = chip->delink_stage1_step;
> - int delink_stage2_cnt = delink_stage1_cnt +
> - chip->delink_stage2_step;
> - int delink_stage3_cnt = delink_stage2_cnt +
> - chip->delink_stage3_step;
> -
> - if (chip->auto_delink_cnt <= delink_stage3_cnt) {
> - if (chip->auto_delink_cnt == delink_stage1_cnt) {
> - rtsx_set_stat(chip, RTSX_STAT_DELINK);
> -
> - if (chip->asic_code && CHECK_PID(chip, 0x5208))
> - rtsx_set_phy_reg_bit(chip, 0x1C, 2);
> -
> - if (chip->card_exist) {
> - dev_dbg(rtsx_dev(chip), "False card inserted, do force delink\n");
> -
> - if (enter_L1)
> - rtsx_write_register(chip,
> - HOST_SLEEP_STATE,
> - 0x03, 1);
> -
> - rtsx_write_register(chip,
> - CHANGE_LINK_STATE,
> - 0x0A, 0x0A);
> -
> - if (enter_L1)
> - rtsx_enter_L1(chip);
> -
> - chip->auto_delink_cnt =
> - delink_stage3_cnt + 1;
> - } else {
> - dev_dbg(rtsx_dev(chip), "No card inserted, do delink\n");
> -
> - if (enter_L1)
> - rtsx_write_register(chip,
> - HOST_SLEEP_STATE,
> - 0x03, 1);
> -
> - rtsx_write_register(chip,
> - CHANGE_LINK_STATE,
> - 0x02, 0x02);
> -
> - if (enter_L1)
> - rtsx_enter_L1(chip);
> - }
> - }
> -
> - if (chip->auto_delink_cnt == delink_stage2_cnt) {
> - dev_dbg(rtsx_dev(chip), "Try to do force delink\n");
> -
> - if (enter_L1)
> - rtsx_exit_L1(chip);
> -
> - if (chip->asic_code && CHECK_PID(chip, 0x5208))
> - rtsx_set_phy_reg_bit(chip, 0x1C, 2);
> -
> - rtsx_write_register(chip, CHANGE_LINK_STATE,
> - 0x0A, 0x0A);
> - }
> -
> - chip->auto_delink_cnt++;
> - }
> - } else {
> - chip->auto_delink_cnt = 0;
> - }
> + rtsx_delink_stage(chip);
> }
>
> void rtsx_undo_delink(struct rtsx_chip *chip)
> --
> 2.1.4
>
> _______________________________________________
> devel mailing list
> [email protected]
> http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel