Skip to contentSkip to conversation

mfd: rtsx: fix PM suspend for 5227 & 5249

PATCH Superseded [email protected] 2 participants 6 messages Sep 11, 2014 – Sep 12, 2014 Multifunction devices (MFD)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover mfd: rtsx: fix PM suspend for 5227 & 5249

From: Micky Ching <[email protected]>

This patch fix rts5227 and rts5249 suspend issue, when card reader resumed from suspend state, the power state should reset before send buffer command. The original not reset PM state first, so this will lead resume failed, and can not do anything more.

Micky Ching (2):
mfd: rtsx: fix PM suspend for 5227
mfd: rtsx: fix PM suspend for 5249

 drivers/mfd/rts5227.c        |   23 +++++++++++++++++++++++
 drivers/mfd/rts5249.c        |   21 +++++++++++++++++++++
 include/linux/mfd/rtsx_pci.h |   13 +++++++++++++
 3 files changed, 57 insertions(+)

--
1.7.9.5

#1 lore raw

PATCH 1/2 mfd: rtsx: fix PM suspend for 5227

From: Micky Ching <[email protected]>

Fix rts5227 failed send buffer cmd after suspend, PM_CTRL3 should reset before send any buffer cmd after suspend. Otherwise, buffer cmd will failed, this will lead resume fail.

---
 drivers/mfd/rts5227.c        |   23 +++++++++++++++++++++++
 include/linux/mfd/rtsx_pci.h |   13 +++++++++++++
 2 files changed, 36 insertions(+)
drivers/mfd/rts5227.c +23 -0
index 9c8eec8..3d4998e 100644
@@ -128,8 +128,31 @@ static int rts5227_extra_init_hw(struct rtsx_pcr *pcr)
 	return rtsx_pci_send_cmd(pcr, 100);
 }
 
+static int rts5227_pm_reset(struct rtsx_pcr *pcr)
+{
+	int err;
+
+	/* init aspm */
+	err = rtsx_pci_update_cfg_byte(pcr, LCTLR, 0xFC, 0);
+	if (err < 0)
+		return err;
+
+	/* reset PM_CTRL3 before send buffer cmd */
+	err = rtsx_pci_write_register(pcr, PM_CTRL3, 0x10, 0x00);
+	if (err < 0)
+		return err;
+
+	return err;
+}
+
 static int rts5227_optimize_phy(struct rtsx_pcr *pcr)
 {
+	int err;
+
+	err = rts5227_pm_reset(pcr);
+	if (err < 0)
+		return err;
+
 	/* Optimize RX sensitivity */
 	return rtsx_pci_write_phy_register(pcr, 0x00, 0xBA42);
 }
include/linux/mfd/rtsx_pci.h +13 -0
index 74346d5..037fbc5 100644
@@ -967,4 +967,17 @@ static inline u8 *rtsx_pci_get_cmd_data(struct rtsx_pcr *pcr)
 	return (u8 *)(pcr->host_cmds_ptr);
 }
 
+static inline int rtsx_pci_update_cfg_byte(struct rtsx_pcr *pcr, int addr,
+		u8 mask, u8 append)
+{
+	int err;
+	u8 val;
+
+	err = pci_read_config_byte(pcr->pci, addr, &val);
+	if (err)
+		return err;
+	err = pci_write_config_byte(pcr->pci, addr, (val & mask) | append);
+	return err;
+}
+
 #endif

--
1.7.9.5

#2 lore raw

Re: [PATCH 1/2] mfd: rtsx: fix PM suspend for 5227

drivers/mfd/rts5227.c static int rts5227_extra_init_hw(struct rtsx_pcr *pcr) · line 145

Quoted 6 lines · On Thu, Sep 11, 2014 at 03:17:52PM +0800, [email protected] wrote:
drivers/mfd/rts5227.c +6 -0
+	/* reset PM_CTRL3 before send buffer cmd */
+	err = rtsx_pci_write_register(pcr, PM_CTRL3, 0x10, 0x00);
+	if (err < 0)
+		return err;
+
+	return err;

Just do:

	return rtsx_pci_write_register(pcr, PM_CTRL3, 0x10, 0x00);
Quoted 20 lines
drivers/mfd/rts5227.c +8 -0
+}
+
 static int rts5227_optimize_phy(struct rtsx_pcr *pcr)
 {
+	int err;
+
+	err = rts5227_pm_reset(pcr);
+	if (err < 0)
+		return err;
+
 	/* Optimize RX sensitivity */
 	return rtsx_pci_write_phy_register(pcr, 0x00, 0xBA42);
 }
include/linux/mfd/rtsx_pci.h +0 -0
index 74346d5..037fbc5 100644
@@ -967,4 +967,17 @@ static inline u8 *rtsx_pci_get_cmd_data(struct rtsx_pcr *pcr)
 	return (u8 *)(pcr->host_cmds_ptr);
 }

include/linux/mfd/rtsx_pci.h static inline u8 *rtsx_pci_get_cmd_data(struct rtsx_pcr *pcr) · line 978

Quoted 10 lines
include/linux/mfd/rtsx_pci.h +9 -0
 
+static inline int rtsx_pci_update_cfg_byte(struct rtsx_pcr *pcr, int addr,
+		u8 mask, u8 append)
+{
+	int err;
+	u8 val;
+
+	err = pci_read_config_byte(pcr->pci, addr, &val);
+	if (err)
+		return err;

Some of these check for "if (err) " and some check for "if (err < 0) ". What is the significance of that? I'm a newbie here. Did you mean for them to be different?

include/linux/mfd/rtsx_pci.h static inline u8 *rtsx_pci_get_cmd_data(struct rtsx_pcr *pcr) · line 980

Quoted 2 lines
include/linux/mfd/rtsx_pci.h +2 -0
+	err = pci_write_config_byte(pcr->pci, addr, (val & mask) | append);
+	return err;
	return pci_write_config_byte(pcr->pci, addr, (val & mask) | append);

regards,
dan carpenter

#3 lore raw

Re: [PATCH 1/2] mfd: rtsx: fix PM suspend for 5227

Quoted 8 lines · Dan Carpenter

include/linux/mfd/rtsx_pci.h static inline u8 *rtsx_pci_get_cmd_data(struct rtsx_pcr *pcr) · line 978

Quoted 3 lines · On Thu, Sep 11, 2014 at 03:17:52PM +0800, [email protected] wrote:
include/linux/mfd/rtsx_pci.h +3 -0
+	err = pci_read_config_byte(pcr->pci, addr, &val);
+	if (err)
+		return err;

Some of these check for "if (err) " and some check for "if (err < 0) ". What is the significance of that? I'm a newbie here. Did you mean for them to be different?

You've updated them all to be "if (err < 0)" how is that different from "if (err)"? What I'm saying is that could you reply to the question?

I guess I normally prefer "if (err)" over "if (err < 0)" but I don't know if it makes a difference here?

regards,
dan carpenter

Quoted 1 line
author
#4 lore raw

Re: [PATCH 1/2] mfd: rtsx: fix PM suspend for 5227

Quoted 5 lines · Dan Carpenter

You've updated them all to be "if (err < 0)" how is that different from "if (err)"? What I'm saying is that could you reply to the question?

I guess I normally prefer "if (err)" over "if (err < 0)" but I don't know if it makes a difference here?

Hi Dan,

these function never return positive value, but other part of the driver code use (err < 0), I use (err < 0) here for consistency.

(err) and (err < 0) is same at least for these function called here.

Best Regards.
micky.

#5 lore raw

PATCH 2/2 mfd: rtsx: fix PM suspend for 5249

In reply to [email protected]

From: Micky Ching <[email protected]>

Fix rts5249 failed send buffer cmd after suspend, PM_CTRL3 should reset before send any buffer cmd after suspend. Otherwise, buffer cmd will failed, this will lead resume fail.

---
 drivers/mfd/rts5249.c |   21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
drivers/mfd/rts5249.c +21 -0
index 573de7b..d6cc546 100644
@@ -126,10 +126,31 @@ static int rts5249_extra_init_hw(struct rtsx_pcr *pcr)
 	return rtsx_pci_send_cmd(pcr, 100);
 }
 
+static int rts5249_pm_reset(struct rtsx_pcr *pcr)
+{
+	int err;
+
+	/* init aspm */
+	err = rtsx_pci_update_cfg_byte(pcr, LCTLR, 0xFC, 0);
+	if (err < 0)
+		return err;
+
+	/* reset PM_CTRL3 before send buffer cmd */
+	err = rtsx_pci_write_register(pcr, PM_CTRL3, 0x10, 0x00);
+	if (err < 0)
+		return err;
+
+	return err;
+}
+
 static int rts5249_optimize_phy(struct rtsx_pcr *pcr)
 {
 	int err;
 
+	err = rts5249_pm_reset(pcr);
+	if (err < 0)
+		return err;
+
 	err = rtsx_pci_write_phy_register(pcr, PHY_REG_REV,
 			PHY_REG_REV_RESV | PHY_REG_REV_RXIDLE_LATCHED |
 			PHY_REG_REV_P1_EN | PHY_REG_REV_RXIDLE_EN |

--
1.7.9.5