linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/10] mfd: rtsx: add support for new rts524A and rts525A
@ 2015-01-15 11:18 micky_ching
  2015-01-15 11:18 ` [PATCH 01/10] mfd: rtsx: replace TAB by SPC after #define micky_ching
                   ` (9 more replies)
  0 siblings, 10 replies; 36+ messages in thread
From: micky_ching @ 2015-01-15 11:18 UTC (permalink / raw)
  To: sameo, lee.jones
  Cc: devel, linux-kernel, gregkh, rogerable, wei_wang, Micky Ching

From: Micky Ching <micky_ching@realsil.com.cn>

This patchset including re-format some coding-style and add two new chip
rts524A and rts525A.

Micky Ching (10):
  mfd: rtsx: replace TAB by SPC after #define
  mfd: rtsx: place register address and values togather
  mfd: rtsx: add debug info when access register failed
  mfd: rtsx: update PETXCFG address
  mfd: rtsx: update driving settings
  mfd: rtsx: update phy register
  mfd: rtsx: remove LCTLR defination
  mfd: rtsx: add support for rts524A
  mfd: rtsx: add support for rts525A
  mfd: rtsx: using pcr_dbg replace dev_dbg

 drivers/mfd/Makefile         |   2 +-
 drivers/mfd/rtl8411.c        |  11 +-
 drivers/mfd/rts5209.c        |   4 +-
 drivers/mfd/rts5227.c        |  12 +-
 drivers/mfd/rts5229.c        |   4 +-
 drivers/mfd/rts5249.c        | 274 ++++++++++---
 drivers/mfd/rtsx_gops.c      |  37 --
 drivers/mfd/rtsx_pcr.c       | 114 ++++--
 drivers/mfd/rtsx_pcr.h       |   5 +
 include/linux/mfd/rtsx_pci.h | 950 +++++++++++++++++++++----------------------
 10 files changed, 778 insertions(+), 635 deletions(-)
 delete mode 100644 drivers/mfd/rtsx_gops.c

-- 
1.9.1


^ permalink raw reply	[flat|nested] 36+ messages in thread

* [PATCH 01/10] mfd: rtsx: replace TAB by SPC after #define
  2015-01-15 11:18 [PATCH 00/10] mfd: rtsx: add support for new rts524A and rts525A micky_ching
@ 2015-01-15 11:18 ` micky_ching
  2015-01-18 12:39   ` Lee Jones
  2015-01-15 11:18 ` [PATCH 02/10] mfd: rtsx: place register address and values togather micky_ching
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 36+ messages in thread
From: micky_ching @ 2015-01-15 11:18 UTC (permalink / raw)
  To: sameo, lee.jones
  Cc: devel, linux-kernel, gregkh, rogerable, wei_wang, Micky Ching

From: Micky Ching <micky_ching@realsil.com.cn>

Re-format coding-style, using uniform SPC after "#define" keyword
instead of mixing using TAB and SPC.

Signed-off-by: Micky Ching <micky_ching@realsil.com.cn>
---
 include/linux/mfd/rtsx_pci.h | 254 +++++++++++++++++++++----------------------
 1 file changed, 127 insertions(+), 127 deletions(-)

diff --git a/include/linux/mfd/rtsx_pci.h b/include/linux/mfd/rtsx_pci.h
index 0c12628..a9c2a14 100644
--- a/include/linux/mfd/rtsx_pci.h
+++ b/include/linux/mfd/rtsx_pci.h
@@ -175,9 +175,9 @@
 /* CARD_SHARE_MODE */
 #define CARD_SHARE_MASK			0x0F
 #define CARD_SHARE_MULTI_LUN		0x00
-#define	CARD_SHARE_NORMAL		0x00
-#define	CARD_SHARE_48_SD		0x04
-#define	CARD_SHARE_48_MS		0x08
+#define CARD_SHARE_NORMAL		0x00
+#define CARD_SHARE_48_SD		0x04
+#define CARD_SHARE_48_MS		0x08
 /* CARD_SHARE_MODE for barossa */
 #define CARD_SHARE_BAROSSA_SD		0x01
 #define CARD_SHARE_BAROSSA_MS		0x02
@@ -249,76 +249,76 @@
 #define CD_AUTO_DISABLE			0x40
 
 /* SD_STAT1 */
-#define	SD_CRC7_ERR			0x80
-#define	SD_CRC16_ERR			0x40
-#define	SD_CRC_WRITE_ERR		0x20
-#define	SD_CRC_WRITE_ERR_MASK		0x1C
-#define	GET_CRC_TIME_OUT		0x02
-#define	SD_TUNING_COMPARE_ERR		0x01
+#define SD_CRC7_ERR			0x80
+#define SD_CRC16_ERR			0x40
+#define SD_CRC_WRITE_ERR		0x20
+#define SD_CRC_WRITE_ERR_MASK		0x1C
+#define GET_CRC_TIME_OUT		0x02
+#define SD_TUNING_COMPARE_ERR		0x01
 
 /* SD_STAT2 */
-#define	SD_RSP_80CLK_TIMEOUT		0x01
+#define SD_RSP_80CLK_TIMEOUT		0x01
 
 /* SD_BUS_STAT */
-#define	SD_CLK_TOGGLE_EN		0x80
-#define	SD_CLK_FORCE_STOP	        0x40
-#define	SD_DAT3_STATUS		        0x10
-#define	SD_DAT2_STATUS		        0x08
-#define	SD_DAT1_STATUS		        0x04
-#define	SD_DAT0_STATUS		        0x02
-#define	SD_CMD_STATUS			0x01
+#define SD_CLK_TOGGLE_EN		0x80
+#define SD_CLK_FORCE_STOP	        0x40
+#define SD_DAT3_STATUS		        0x10
+#define SD_DAT2_STATUS		        0x08
+#define SD_DAT1_STATUS		        0x04
+#define SD_DAT0_STATUS		        0x02
+#define SD_CMD_STATUS			0x01
 
 /* SD_PAD_CTL */
-#define	SD_IO_USING_1V8		        0x80
-#define	SD_IO_USING_3V3		        0x7F
-#define	TYPE_A_DRIVING		        0x00
-#define	TYPE_B_DRIVING			0x01
-#define	TYPE_C_DRIVING			0x02
-#define	TYPE_D_DRIVING		        0x03
+#define SD_IO_USING_1V8		        0x80
+#define SD_IO_USING_3V3		        0x7F
+#define TYPE_A_DRIVING		        0x00
+#define TYPE_B_DRIVING			0x01
+#define TYPE_C_DRIVING			0x02
+#define TYPE_D_DRIVING		        0x03
 
 /* SD_SAMPLE_POINT_CTL */
-#define	DDR_FIX_RX_DAT			0x00
-#define	DDR_VAR_RX_DAT			0x80
-#define	DDR_FIX_RX_DAT_EDGE		0x00
-#define	DDR_FIX_RX_DAT_14_DELAY		0x40
-#define	DDR_FIX_RX_CMD			0x00
-#define	DDR_VAR_RX_CMD			0x20
-#define	DDR_FIX_RX_CMD_POS_EDGE		0x00
-#define	DDR_FIX_RX_CMD_14_DELAY		0x10
-#define	SD20_RX_POS_EDGE		0x00
-#define	SD20_RX_14_DELAY		0x08
+#define DDR_FIX_RX_DAT			0x00
+#define DDR_VAR_RX_DAT			0x80
+#define DDR_FIX_RX_DAT_EDGE		0x00
+#define DDR_FIX_RX_DAT_14_DELAY		0x40
+#define DDR_FIX_RX_CMD			0x00
+#define DDR_VAR_RX_CMD			0x20
+#define DDR_FIX_RX_CMD_POS_EDGE		0x00
+#define DDR_FIX_RX_CMD_14_DELAY		0x10
+#define SD20_RX_POS_EDGE		0x00
+#define SD20_RX_14_DELAY		0x08
 #define SD20_RX_SEL_MASK		0x08
 
 /* SD_PUSH_POINT_CTL */
-#define	DDR_FIX_TX_CMD_DAT		0x00
-#define	DDR_VAR_TX_CMD_DAT		0x80
-#define	DDR_FIX_TX_DAT_14_TSU		0x00
-#define	DDR_FIX_TX_DAT_12_TSU		0x40
-#define	DDR_FIX_TX_CMD_NEG_EDGE		0x00
-#define	DDR_FIX_TX_CMD_14_AHEAD		0x20
-#define	SD20_TX_NEG_EDGE		0x00
-#define	SD20_TX_14_AHEAD		0x10
+#define DDR_FIX_TX_CMD_DAT		0x00
+#define DDR_VAR_TX_CMD_DAT		0x80
+#define DDR_FIX_TX_DAT_14_TSU		0x00
+#define DDR_FIX_TX_DAT_12_TSU		0x40
+#define DDR_FIX_TX_CMD_NEG_EDGE		0x00
+#define DDR_FIX_TX_CMD_14_AHEAD		0x20
+#define SD20_TX_NEG_EDGE		0x00
+#define SD20_TX_14_AHEAD		0x10
 #define SD20_TX_SEL_MASK		0x10
-#define	DDR_VAR_SDCLK_POL_SWAP		0x01
+#define DDR_VAR_SDCLK_POL_SWAP		0x01
 
 /* SD_TRANSFER */
-#define	SD_TRANSFER_START		0x80
-#define	SD_TRANSFER_END			0x40
+#define SD_TRANSFER_START		0x80
+#define SD_TRANSFER_END			0x40
 #define SD_STAT_IDLE			0x20
-#define	SD_TRANSFER_ERR			0x10
+#define SD_TRANSFER_ERR			0x10
 /* SD Transfer Mode definition */
-#define	SD_TM_NORMAL_WRITE		0x00
-#define	SD_TM_AUTO_WRITE_3		0x01
-#define	SD_TM_AUTO_WRITE_4		0x02
-#define	SD_TM_AUTO_READ_3		0x05
-#define	SD_TM_AUTO_READ_4		0x06
-#define	SD_TM_CMD_RSP			0x08
-#define	SD_TM_AUTO_WRITE_1		0x09
-#define	SD_TM_AUTO_WRITE_2		0x0A
-#define	SD_TM_NORMAL_READ		0x0C
-#define	SD_TM_AUTO_READ_1		0x0D
-#define	SD_TM_AUTO_READ_2		0x0E
-#define	SD_TM_AUTO_TUNING		0x0F
+#define SD_TM_NORMAL_WRITE		0x00
+#define SD_TM_AUTO_WRITE_3		0x01
+#define SD_TM_AUTO_WRITE_4		0x02
+#define SD_TM_AUTO_READ_3		0x05
+#define SD_TM_AUTO_READ_4		0x06
+#define SD_TM_CMD_RSP			0x08
+#define SD_TM_AUTO_WRITE_1		0x09
+#define SD_TM_AUTO_WRITE_2		0x0A
+#define SD_TM_NORMAL_READ		0x0C
+#define SD_TM_AUTO_READ_1		0x0D
+#define SD_TM_AUTO_READ_2		0x0E
+#define SD_TM_AUTO_TUNING		0x0F
 
 /* SD_VPTX_CTL / SD_VPRX_CTL */
 #define PHASE_CHANGE			0x80
@@ -332,15 +332,15 @@
 
 /* SD Configure 1 Register */
 #define SD_CLK_DIVIDE_0			0x00
-#define	SD_CLK_DIVIDE_256		0xC0
-#define	SD_CLK_DIVIDE_128		0x80
-#define	SD_BUS_WIDTH_1BIT		0x00
-#define	SD_BUS_WIDTH_4BIT		0x01
-#define	SD_BUS_WIDTH_8BIT		0x02
-#define	SD_ASYNC_FIFO_NOT_RST		0x10
-#define	SD_20_MODE			0x00
-#define	SD_DDR_MODE			0x04
-#define	SD_30_MODE			0x08
+#define SD_CLK_DIVIDE_256		0xC0
+#define SD_CLK_DIVIDE_128		0x80
+#define SD_BUS_WIDTH_1BIT		0x00
+#define SD_BUS_WIDTH_4BIT		0x01
+#define SD_BUS_WIDTH_8BIT		0x02
+#define SD_ASYNC_FIFO_NOT_RST		0x10
+#define SD_20_MODE			0x00
+#define SD_DDR_MODE			0x04
+#define SD_30_MODE			0x08
 
 #define SD_CLK_DIVIDE_MASK		0xC0
 
@@ -415,71 +415,71 @@
 #define CLK_DIV_8			0x04
 
 /* MS_CFG */
-#define	SAMPLE_TIME_RISING		0x00
-#define	SAMPLE_TIME_FALLING		0x80
-#define	PUSH_TIME_DEFAULT		0x00
-#define	PUSH_TIME_ODD			0x40
-#define	NO_EXTEND_TOGGLE		0x00
-#define	EXTEND_TOGGLE_CHK		0x20
-#define	MS_BUS_WIDTH_1			0x00
-#define	MS_BUS_WIDTH_4			0x10
-#define	MS_BUS_WIDTH_8			0x18
-#define	MS_2K_SECTOR_MODE		0x04
-#define	MS_512_SECTOR_MODE		0x00
-#define	MS_TOGGLE_TIMEOUT_EN		0x00
-#define	MS_TOGGLE_TIMEOUT_DISEN		0x01
+#define SAMPLE_TIME_RISING		0x00
+#define SAMPLE_TIME_FALLING		0x80
+#define PUSH_TIME_DEFAULT		0x00
+#define PUSH_TIME_ODD			0x40
+#define NO_EXTEND_TOGGLE		0x00
+#define EXTEND_TOGGLE_CHK		0x20
+#define MS_BUS_WIDTH_1			0x00
+#define MS_BUS_WIDTH_4			0x10
+#define MS_BUS_WIDTH_8			0x18
+#define MS_2K_SECTOR_MODE		0x04
+#define MS_512_SECTOR_MODE		0x00
+#define MS_TOGGLE_TIMEOUT_EN		0x00
+#define MS_TOGGLE_TIMEOUT_DISEN		0x01
 #define MS_NO_CHECK_INT			0x02
 
 /* MS_TRANS_CFG */
-#define	WAIT_INT			0x80
-#define	NO_WAIT_INT			0x00
-#define	NO_AUTO_READ_INT_REG		0x00
-#define	AUTO_READ_INT_REG		0x40
-#define	MS_CRC16_ERR			0x20
-#define	MS_RDY_TIMEOUT			0x10
-#define	MS_INT_CMDNK			0x08
-#define	MS_INT_BREQ			0x04
-#define	MS_INT_ERR			0x02
-#define	MS_INT_CED			0x01
+#define WAIT_INT			0x80
+#define NO_WAIT_INT			0x00
+#define NO_AUTO_READ_INT_REG		0x00
+#define AUTO_READ_INT_REG		0x40
+#define MS_CRC16_ERR			0x20
+#define MS_RDY_TIMEOUT			0x10
+#define MS_INT_CMDNK			0x08
+#define MS_INT_BREQ			0x04
+#define MS_INT_ERR			0x02
+#define MS_INT_CED			0x01
 
 /* MS_TRANSFER */
-#define	MS_TRANSFER_START		0x80
-#define	MS_TRANSFER_END			0x40
-#define	MS_TRANSFER_ERR			0x20
-#define	MS_BS_STATE			0x10
-#define	MS_TM_READ_BYTES		0x00
-#define	MS_TM_NORMAL_READ		0x01
-#define	MS_TM_WRITE_BYTES		0x04
-#define	MS_TM_NORMAL_WRITE		0x05
-#define	MS_TM_AUTO_READ			0x08
-#define	MS_TM_AUTO_WRITE		0x0C
+#define MS_TRANSFER_START		0x80
+#define MS_TRANSFER_END			0x40
+#define MS_TRANSFER_ERR			0x20
+#define MS_BS_STATE			0x10
+#define MS_TM_READ_BYTES		0x00
+#define MS_TM_NORMAL_READ		0x01
+#define MS_TM_WRITE_BYTES		0x04
+#define MS_TM_NORMAL_WRITE		0x05
+#define MS_TM_AUTO_READ			0x08
+#define MS_TM_AUTO_WRITE		0x0C
 
 /* SD Configure 2 Register */
-#define	SD_CALCULATE_CRC7		0x00
-#define	SD_NO_CALCULATE_CRC7		0x80
-#define	SD_CHECK_CRC16			0x00
-#define	SD_NO_CHECK_CRC16		0x40
+#define SD_CALCULATE_CRC7		0x00
+#define SD_NO_CALCULATE_CRC7		0x80
+#define SD_CHECK_CRC16			0x00
+#define SD_NO_CHECK_CRC16		0x40
 #define SD_NO_CHECK_WAIT_CRC_TO		0x20
-#define	SD_WAIT_BUSY_END		0x08
-#define	SD_NO_WAIT_BUSY_END		0x00
-#define	SD_CHECK_CRC7			0x00
-#define	SD_NO_CHECK_CRC7		0x04
-#define	SD_RSP_LEN_0			0x00
-#define	SD_RSP_LEN_6			0x01
-#define	SD_RSP_LEN_17			0x02
+#define SD_WAIT_BUSY_END		0x08
+#define SD_NO_WAIT_BUSY_END		0x00
+#define SD_CHECK_CRC7			0x00
+#define SD_NO_CHECK_CRC7		0x04
+#define SD_RSP_LEN_0			0x00
+#define SD_RSP_LEN_6			0x01
+#define SD_RSP_LEN_17			0x02
 /* SD/MMC Response Type Definition */
-#define	SD_RSP_TYPE_R0			0x04
-#define	SD_RSP_TYPE_R1			0x01
-#define	SD_RSP_TYPE_R1b			0x09
-#define	SD_RSP_TYPE_R2			0x02
-#define	SD_RSP_TYPE_R3			0x05
-#define	SD_RSP_TYPE_R4			0x05
-#define	SD_RSP_TYPE_R5			0x01
-#define	SD_RSP_TYPE_R6			0x01
-#define	SD_RSP_TYPE_R7			0x01
+#define SD_RSP_TYPE_R0			0x04
+#define SD_RSP_TYPE_R1			0x01
+#define SD_RSP_TYPE_R1b			0x09
+#define SD_RSP_TYPE_R2			0x02
+#define SD_RSP_TYPE_R3			0x05
+#define SD_RSP_TYPE_R4			0x05
+#define SD_RSP_TYPE_R5			0x01
+#define SD_RSP_TYPE_R6			0x01
+#define SD_RSP_TYPE_R7			0x01
 
 /* SD_CONFIGURE3 */
-#define	SD_RSP_80CLK_TIMEOUT_EN		0x01
+#define SD_RSP_80CLK_TIMEOUT_EN		0x01
 
 /* Card Transfer Reset Register */
 #define SPI_STOP			0x01
@@ -574,13 +574,13 @@
 
 #define SRCTL				0xFC13
 
-#define	DCM_DRP_CTL			0xFC23
-#define	DCM_DRP_TRIG			0xFC24
-#define	DCM_DRP_CFG			0xFC25
-#define	DCM_DRP_WR_DATA_L		0xFC26
-#define	DCM_DRP_WR_DATA_H		0xFC27
-#define	DCM_DRP_RD_DATA_L		0xFC28
-#define	DCM_DRP_RD_DATA_H		0xFC29
+#define DCM_DRP_CTL			0xFC23
+#define DCM_DRP_TRIG			0xFC24
+#define DCM_DRP_CFG			0xFC25
+#define DCM_DRP_WR_DATA_L		0xFC26
+#define DCM_DRP_WR_DATA_H		0xFC27
+#define DCM_DRP_RD_DATA_L		0xFC28
+#define DCM_DRP_RD_DATA_H		0xFC29
 #define SD_VPCLK0_CTL			0xFC2A
 #define SD_VPCLK1_CTL			0xFC2B
 #define SD_DCMPS0_CTL			0xFC2C
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 02/10] mfd: rtsx: place register address and values togather
  2015-01-15 11:18 [PATCH 00/10] mfd: rtsx: add support for new rts524A and rts525A micky_ching
  2015-01-15 11:18 ` [PATCH 01/10] mfd: rtsx: replace TAB by SPC after #define micky_ching
@ 2015-01-15 11:18 ` micky_ching
  2015-01-18 12:35   ` Lee Jones
  2015-01-15 11:19 ` [PATCH 03/10] mfd: rtsx: add debug info when access register failed micky_ching
                   ` (7 subsequent siblings)
  9 siblings, 1 reply; 36+ messages in thread
From: micky_ching @ 2015-01-15 11:18 UTC (permalink / raw)
  To: sameo, lee.jones
  Cc: devel, linux-kernel, gregkh, rogerable, wei_wang, Micky Ching

From: Micky Ching <micky_ching@realsil.com.cn>

It is more readable to place register address and values define
togather. The values define add two leading space indicate belong
to the register address defined above.

Signed-off-by: Micky Ching <micky_ching@realsil.com.cn>
---
 include/linux/mfd/rtsx_pci.h | 836 +++++++++++++++++++------------------------
 1 file changed, 369 insertions(+), 467 deletions(-)

diff --git a/include/linux/mfd/rtsx_pci.h b/include/linux/mfd/rtsx_pci.h
index a9c2a14..e81f2bb 100644
--- a/include/linux/mfd/rtsx_pci.h
+++ b/include/linux/mfd/rtsx_pci.h
@@ -28,74 +28,72 @@
 
 #define MAX_RW_REG_CNT			1024
 
-/* PCI Operation Register Address */
 #define RTSX_HCBAR			0x00
 #define RTSX_HCBCTLR			0x04
+#define   STOP_CMD			(0x01 << 28)
+#define   READ_REG_CMD			0
+#define   WRITE_REG_CMD			1
+#define   CHECK_REG_CMD			2
+
 #define RTSX_HDBAR			0x08
+#define   SG_INT			0x04
+#define   SG_END			0x02
+#define   SG_VALID			0x01
+#define   SG_NO_OP			0x00
+#define   SG_TRANS_DATA			(0x02 << 4)
+#define   SG_LINK_DESC			(0x03 << 4)
 #define RTSX_HDBCTLR			0x0C
+#define   SDMA_MODE			0x00
+#define   ADMA_MODE			(0x02 << 26)
+#define   STOP_DMA			(0x01 << 28)
+#define   TRIG_DMA			(0x01 << 31)
+
 #define RTSX_HAIMR			0x10
-#define RTSX_BIPR			0x14
-#define RTSX_BIER			0x18
+#define   HAIMR_TRANS_START		(0x01 << 31)
+#define   HAIMR_READ			0x00
+#define   HAIMR_WRITE			(0x01 << 30)
+#define   HAIMR_READ_START		(HAIMR_TRANS_START | HAIMR_READ)
+#define   HAIMR_WRITE_START		(HAIMR_TRANS_START | HAIMR_WRITE)
+#define   HAIMR_TRANS_END			(HAIMR_TRANS_START)
 
-/* Host command buffer control register */
-#define STOP_CMD			(0x01 << 28)
-
-/* Host data buffer control register */
-#define SDMA_MODE			0x00
-#define ADMA_MODE			(0x02 << 26)
-#define STOP_DMA			(0x01 << 28)
-#define TRIG_DMA			(0x01 << 31)
-
-/* Host access internal memory register */
-#define HAIMR_TRANS_START		(0x01 << 31)
-#define HAIMR_READ			0x00
-#define HAIMR_WRITE			(0x01 << 30)
-#define HAIMR_READ_START		(HAIMR_TRANS_START | HAIMR_READ)
-#define HAIMR_WRITE_START		(HAIMR_TRANS_START | HAIMR_WRITE)
-#define HAIMR_TRANS_END			(HAIMR_TRANS_START)
-
-/* Bus interrupt pending register */
-#define CMD_DONE_INT			(1 << 31)
-#define DATA_DONE_INT			(1 << 30)
-#define TRANS_OK_INT			(1 << 29)
-#define TRANS_FAIL_INT			(1 << 28)
-#define XD_INT				(1 << 27)
-#define MS_INT				(1 << 26)
-#define SD_INT				(1 << 25)
-#define GPIO0_INT			(1 << 24)
-#define OC_INT				(1 << 23)
-#define SD_WRITE_PROTECT		(1 << 19)
-#define XD_EXIST			(1 << 18)
-#define MS_EXIST			(1 << 17)
-#define SD_EXIST			(1 << 16)
-#define DELINK_INT			GPIO0_INT
-#define MS_OC_INT			(1 << 23)
-#define SD_OC_INT			(1 << 22)
+#define RTSX_BIPR			0x14
+#define   CMD_DONE_INT			(1 << 31)
+#define   DATA_DONE_INT			(1 << 30)
+#define   TRANS_OK_INT			(1 << 29)
+#define   TRANS_FAIL_INT		(1 << 28)
+#define   XD_INT			(1 << 27)
+#define   MS_INT			(1 << 26)
+#define   SD_INT			(1 << 25)
+#define   GPIO0_INT			(1 << 24)
+#define   OC_INT			(1 << 23)
+#define   SD_WRITE_PROTECT		(1 << 19)
+#define   XD_EXIST			(1 << 18)
+#define   MS_EXIST			(1 << 17)
+#define   SD_EXIST			(1 << 16)
+#define   DELINK_INT			GPIO0_INT
+#define   MS_OC_INT			(1 << 23)
+#define   SD_OC_INT			(1 << 22)
 
 #define CARD_INT		(XD_INT | MS_INT | SD_INT)
 #define NEED_COMPLETE_INT	(DATA_DONE_INT | TRANS_OK_INT | TRANS_FAIL_INT)
 #define RTSX_INT		(CMD_DONE_INT | NEED_COMPLETE_INT | \
 					CARD_INT | GPIO0_INT | OC_INT)
-
 #define CARD_EXIST		(XD_EXIST | MS_EXIST | SD_EXIST)
 
-/* Bus interrupt enable register */
-#define CMD_DONE_INT_EN		(1 << 31)
-#define DATA_DONE_INT_EN	(1 << 30)
-#define TRANS_OK_INT_EN		(1 << 29)
-#define TRANS_FAIL_INT_EN	(1 << 28)
-#define XD_INT_EN		(1 << 27)
-#define MS_INT_EN		(1 << 26)
-#define SD_INT_EN		(1 << 25)
-#define GPIO0_INT_EN		(1 << 24)
-#define OC_INT_EN		(1 << 23)
-#define DELINK_INT_EN		GPIO0_INT_EN
-#define MS_OC_INT_EN		(1 << 23)
-#define SD_OC_INT_EN		(1 << 22)
-
-#define READ_REG_CMD		0
-#define WRITE_REG_CMD		1
-#define CHECK_REG_CMD		2
+#define RTSX_BIER			0x18
+#define   CMD_DONE_INT_EN		(1 << 31)
+#define   DATA_DONE_INT_EN		(1 << 30)
+#define   TRANS_OK_INT_EN		(1 << 29)
+#define   TRANS_FAIL_INT_EN		(1 << 28)
+#define   XD_INT_EN			(1 << 27)
+#define   MS_INT_EN			(1 << 26)
+#define   SD_INT_EN			(1 << 25)
+#define   GPIO0_INT_EN			(1 << 24)
+#define   OC_INT_EN			(1 << 23)
+#define   DELINK_INT_EN			GPIO0_INT_EN
+#define   MS_OC_INT_EN			(1 << 23)
+#define   SD_OC_INT_EN			(1 << 22)
+
 
 /*
  * macros for easy use
@@ -125,423 +123,68 @@
 #define rtsx_pci_write_config_dword(pcr, where, val) \
 	pci_write_config_dword((pcr)->pci, where, val)
 
-#define STATE_TRANS_NONE	0
-#define STATE_TRANS_CMD		1
-#define STATE_TRANS_BUF		2
-#define STATE_TRANS_SG		3
-
-#define TRANS_NOT_READY		0
-#define TRANS_RESULT_OK		1
-#define TRANS_RESULT_FAIL	2
-#define TRANS_NO_DEVICE		3
-
-#define RTSX_RESV_BUF_LEN	4096
-#define HOST_CMDS_BUF_LEN	1024
-#define HOST_SG_TBL_BUF_LEN	(RTSX_RESV_BUF_LEN - HOST_CMDS_BUF_LEN)
-#define HOST_SG_TBL_ITEMS	(HOST_SG_TBL_BUF_LEN / 8)
-#define MAX_SG_ITEM_LEN		0x80000
-
-#define HOST_TO_DEVICE		0
-#define DEVICE_TO_HOST		1
-
-#define RTSX_PHASE_MAX		32
-#define RX_TUNING_CNT		3
-
-/* SG descriptor */
-#define SG_INT			0x04
-#define SG_END			0x02
-#define SG_VALID		0x01
-
-#define SG_NO_OP		0x00
-#define SG_TRANS_DATA		(0x02 << 4)
-#define SG_LINK_DESC		(0x03 << 4)
-
-/* Output voltage */
-#define OUTPUT_3V3		0
-#define OUTPUT_1V8		1
-
-/* Card Clock Enable Register */
-#define SD_CLK_EN			0x04
-#define MS_CLK_EN			0x08
-
-/* Card Select Register */
-#define SD_MOD_SEL			2
-#define MS_MOD_SEL			3
-
-/* Card Output Enable Register */
-#define SD_OUTPUT_EN			0x04
-#define MS_OUTPUT_EN			0x08
-
-/* CARD_SHARE_MODE */
-#define CARD_SHARE_MASK			0x0F
-#define CARD_SHARE_MULTI_LUN		0x00
-#define CARD_SHARE_NORMAL		0x00
-#define CARD_SHARE_48_SD		0x04
-#define CARD_SHARE_48_MS		0x08
-/* CARD_SHARE_MODE for barossa */
-#define CARD_SHARE_BAROSSA_SD		0x01
-#define CARD_SHARE_BAROSSA_MS		0x02
-
-/* CARD_DRIVE_SEL */
-#define MS_DRIVE_8mA			(0x01 << 6)
-#define MMC_DRIVE_8mA			(0x01 << 4)
-#define XD_DRIVE_8mA			(0x01 << 2)
-#define GPIO_DRIVE_8mA			0x01
-#define RTS5209_CARD_DRIVE_DEFAULT	(MS_DRIVE_8mA | MMC_DRIVE_8mA |\
-						XD_DRIVE_8mA | GPIO_DRIVE_8mA)
-#define RTL8411_CARD_DRIVE_DEFAULT	(MS_DRIVE_8mA | MMC_DRIVE_8mA |\
-						XD_DRIVE_8mA)
-#define RTSX_CARD_DRIVE_DEFAULT		(MS_DRIVE_8mA | GPIO_DRIVE_8mA)
+#define STATE_TRANS_NONE		0
+#define STATE_TRANS_CMD			1
+#define STATE_TRANS_BUF			2
+#define STATE_TRANS_SG			3
 
-/* SD30_DRIVE_SEL */
-#define DRIVER_TYPE_A			0x05
-#define DRIVER_TYPE_B			0x03
-#define DRIVER_TYPE_C			0x02
-#define DRIVER_TYPE_D			0x01
-#define CFG_DRIVER_TYPE_A		0x02
-#define CFG_DRIVER_TYPE_B		0x03
-#define CFG_DRIVER_TYPE_C		0x01
-#define CFG_DRIVER_TYPE_D		0x00
-
-/* FPDCTL */
-#define SSC_POWER_DOWN			0x01
-#define SD_OC_POWER_DOWN		0x02
-#define ALL_POWER_DOWN			0x07
-#define OC_POWER_DOWN			0x06
-
-/* CLK_CTL */
-#define CHANGE_CLK			0x01
-
-/* LDO_CTL */
-#define BPP_ASIC_1V7			0x00
-#define BPP_ASIC_1V8			0x01
-#define BPP_ASIC_1V9			0x02
-#define BPP_ASIC_2V0			0x03
-#define BPP_ASIC_2V7			0x04
-#define BPP_ASIC_2V8			0x05
-#define BPP_ASIC_3V2			0x06
-#define BPP_ASIC_3V3			0x07
-#define BPP_REG_TUNED18			0x07
-#define BPP_TUNED18_SHIFT_8402		5
-#define BPP_TUNED18_SHIFT_8411		4
-#define BPP_PAD_MASK			0x04
-#define BPP_PAD_3V3			0x04
-#define BPP_PAD_1V8			0x00
-#define BPP_LDO_POWB			0x03
-#define BPP_LDO_ON			0x00
-#define BPP_LDO_SUSPEND			0x02
-#define BPP_LDO_OFF			0x03
-
-/* CD_PAD_CTL */
-#define CD_DISABLE_MASK			0x07
-#define MS_CD_DISABLE			0x04
-#define SD_CD_DISABLE			0x02
-#define XD_CD_DISABLE			0x01
-#define CD_DISABLE			0x07
-#define CD_ENABLE			0x00
-#define MS_CD_EN_ONLY			0x03
-#define SD_CD_EN_ONLY			0x05
-#define XD_CD_EN_ONLY			0x06
-#define FORCE_CD_LOW_MASK		0x38
-#define FORCE_CD_XD_LOW			0x08
-#define FORCE_CD_SD_LOW			0x10
-#define FORCE_CD_MS_LOW			0x20
-#define CD_AUTO_DISABLE			0x40
-
-/* SD_STAT1 */
-#define SD_CRC7_ERR			0x80
-#define SD_CRC16_ERR			0x40
-#define SD_CRC_WRITE_ERR		0x20
-#define SD_CRC_WRITE_ERR_MASK		0x1C
-#define GET_CRC_TIME_OUT		0x02
-#define SD_TUNING_COMPARE_ERR		0x01
-
-/* SD_STAT2 */
-#define SD_RSP_80CLK_TIMEOUT		0x01
-
-/* SD_BUS_STAT */
-#define SD_CLK_TOGGLE_EN		0x80
-#define SD_CLK_FORCE_STOP	        0x40
-#define SD_DAT3_STATUS		        0x10
-#define SD_DAT2_STATUS		        0x08
-#define SD_DAT1_STATUS		        0x04
-#define SD_DAT0_STATUS		        0x02
-#define SD_CMD_STATUS			0x01
-
-/* SD_PAD_CTL */
-#define SD_IO_USING_1V8		        0x80
-#define SD_IO_USING_3V3		        0x7F
-#define TYPE_A_DRIVING		        0x00
-#define TYPE_B_DRIVING			0x01
-#define TYPE_C_DRIVING			0x02
-#define TYPE_D_DRIVING		        0x03
-
-/* SD_SAMPLE_POINT_CTL */
-#define DDR_FIX_RX_DAT			0x00
-#define DDR_VAR_RX_DAT			0x80
-#define DDR_FIX_RX_DAT_EDGE		0x00
-#define DDR_FIX_RX_DAT_14_DELAY		0x40
-#define DDR_FIX_RX_CMD			0x00
-#define DDR_VAR_RX_CMD			0x20
-#define DDR_FIX_RX_CMD_POS_EDGE		0x00
-#define DDR_FIX_RX_CMD_14_DELAY		0x10
-#define SD20_RX_POS_EDGE		0x00
-#define SD20_RX_14_DELAY		0x08
-#define SD20_RX_SEL_MASK		0x08
+#define TRANS_NOT_READY			0
+#define TRANS_RESULT_OK			1
+#define TRANS_RESULT_FAIL		2
+#define TRANS_NO_DEVICE			3
 
-/* SD_PUSH_POINT_CTL */
-#define DDR_FIX_TX_CMD_DAT		0x00
-#define DDR_VAR_TX_CMD_DAT		0x80
-#define DDR_FIX_TX_DAT_14_TSU		0x00
-#define DDR_FIX_TX_DAT_12_TSU		0x40
-#define DDR_FIX_TX_CMD_NEG_EDGE		0x00
-#define DDR_FIX_TX_CMD_14_AHEAD		0x20
-#define SD20_TX_NEG_EDGE		0x00
-#define SD20_TX_14_AHEAD		0x10
-#define SD20_TX_SEL_MASK		0x10
-#define DDR_VAR_SDCLK_POL_SWAP		0x01
-
-/* SD_TRANSFER */
-#define SD_TRANSFER_START		0x80
-#define SD_TRANSFER_END			0x40
-#define SD_STAT_IDLE			0x20
-#define SD_TRANSFER_ERR			0x10
-/* SD Transfer Mode definition */
-#define SD_TM_NORMAL_WRITE		0x00
-#define SD_TM_AUTO_WRITE_3		0x01
-#define SD_TM_AUTO_WRITE_4		0x02
-#define SD_TM_AUTO_READ_3		0x05
-#define SD_TM_AUTO_READ_4		0x06
-#define SD_TM_CMD_RSP			0x08
-#define SD_TM_AUTO_WRITE_1		0x09
-#define SD_TM_AUTO_WRITE_2		0x0A
-#define SD_TM_NORMAL_READ		0x0C
-#define SD_TM_AUTO_READ_1		0x0D
-#define SD_TM_AUTO_READ_2		0x0E
-#define SD_TM_AUTO_TUNING		0x0F
-
-/* SD_VPTX_CTL / SD_VPRX_CTL */
-#define PHASE_CHANGE			0x80
-#define PHASE_NOT_RESET			0x40
-
-/* SD_DCMPS_TX_CTL / SD_DCMPS_RX_CTL */
-#define DCMPS_CHANGE			0x80
-#define DCMPS_CHANGE_DONE		0x40
-#define DCMPS_ERROR			0x20
-#define DCMPS_CURRENT_PHASE		0x1F
-
-/* SD Configure 1 Register */
-#define SD_CLK_DIVIDE_0			0x00
-#define SD_CLK_DIVIDE_256		0xC0
-#define SD_CLK_DIVIDE_128		0x80
-#define SD_BUS_WIDTH_1BIT		0x00
-#define SD_BUS_WIDTH_4BIT		0x01
-#define SD_BUS_WIDTH_8BIT		0x02
-#define SD_ASYNC_FIFO_NOT_RST		0x10
-#define SD_20_MODE			0x00
-#define SD_DDR_MODE			0x04
-#define SD_30_MODE			0x08
-
-#define SD_CLK_DIVIDE_MASK		0xC0
-
-/* SD_CMD_STATE */
-#define SD_CMD_IDLE			0x80
-
-/* SD_DATA_STATE */
-#define SD_DATA_IDLE			0x80
-
-/* DCM_DRP_CTL */
-#define DCM_RESET			0x08
-#define DCM_LOCKED			0x04
-#define DCM_208M			0x00
-#define DCM_TX			        0x01
-#define DCM_RX			        0x02
-
-/* DCM_DRP_TRIG */
-#define DRP_START			0x80
-#define DRP_DONE			0x40
-
-/* DCM_DRP_CFG */
-#define DRP_WRITE			0x80
-#define DRP_READ			0x00
-#define DCM_WRITE_ADDRESS_50		0x50
-#define DCM_WRITE_ADDRESS_51		0x51
-#define DCM_READ_ADDRESS_00		0x00
-#define DCM_READ_ADDRESS_51		0x51
-
-/* IRQSTAT0 */
-#define DMA_DONE_INT			0x80
-#define SUSPEND_INT			0x40
-#define LINK_RDY_INT			0x20
-#define LINK_DOWN_INT			0x10
-
-/* DMACTL */
-#define DMA_RST				0x80
-#define DMA_BUSY			0x04
-#define DMA_DIR_TO_CARD			0x00
-#define DMA_DIR_FROM_CARD		0x02
-#define DMA_EN				0x01
-#define DMA_128				(0 << 4)
-#define DMA_256				(1 << 4)
-#define DMA_512				(2 << 4)
-#define DMA_1024			(3 << 4)
-#define DMA_PACK_SIZE_MASK		0x30
-
-/* SSC_CTL1 */
-#define SSC_RSTB			0x80
-#define SSC_8X_EN			0x40
-#define SSC_FIX_FRAC			0x20
-#define SSC_SEL_1M			0x00
-#define SSC_SEL_2M			0x08
-#define SSC_SEL_4M			0x10
-#define SSC_SEL_8M			0x18
-
-/* SSC_CTL2 */
-#define SSC_DEPTH_MASK			0x07
-#define SSC_DEPTH_DISALBE		0x00
-#define SSC_DEPTH_4M			0x01
-#define SSC_DEPTH_2M			0x02
-#define SSC_DEPTH_1M			0x03
-#define SSC_DEPTH_500K			0x04
-#define SSC_DEPTH_250K			0x05
-
-/* System Clock Control Register */
-#define CLK_LOW_FREQ			0x01
-
-/* System Clock Divider Register */
-#define CLK_DIV_1			0x01
-#define CLK_DIV_2			0x02
-#define CLK_DIV_4			0x03
-#define CLK_DIV_8			0x04
-
-/* MS_CFG */
-#define SAMPLE_TIME_RISING		0x00
-#define SAMPLE_TIME_FALLING		0x80
-#define PUSH_TIME_DEFAULT		0x00
-#define PUSH_TIME_ODD			0x40
-#define NO_EXTEND_TOGGLE		0x00
-#define EXTEND_TOGGLE_CHK		0x20
-#define MS_BUS_WIDTH_1			0x00
-#define MS_BUS_WIDTH_4			0x10
-#define MS_BUS_WIDTH_8			0x18
-#define MS_2K_SECTOR_MODE		0x04
-#define MS_512_SECTOR_MODE		0x00
-#define MS_TOGGLE_TIMEOUT_EN		0x00
-#define MS_TOGGLE_TIMEOUT_DISEN		0x01
-#define MS_NO_CHECK_INT			0x02
+#define RTSX_RESV_BUF_LEN		4096
+#define HOST_CMDS_BUF_LEN		1024
+#define HOST_SG_TBL_BUF_LEN		(RTSX_RESV_BUF_LEN - HOST_CMDS_BUF_LEN)
+#define HOST_SG_TBL_ITEMS		(HOST_SG_TBL_BUF_LEN / 8)
+#define MAX_SG_ITEM_LEN			0x80000
+#define HOST_TO_DEVICE			0
+#define DEVICE_TO_HOST			1
+
+#define OUTPUT_3V3			0
+#define OUTPUT_1V8			1
 
-/* MS_TRANS_CFG */
-#define WAIT_INT			0x80
-#define NO_WAIT_INT			0x00
-#define NO_AUTO_READ_INT_REG		0x00
-#define AUTO_READ_INT_REG		0x40
-#define MS_CRC16_ERR			0x20
-#define MS_RDY_TIMEOUT			0x10
-#define MS_INT_CMDNK			0x08
-#define MS_INT_BREQ			0x04
-#define MS_INT_ERR			0x02
-#define MS_INT_CED			0x01
-
-/* MS_TRANSFER */
-#define MS_TRANSFER_START		0x80
-#define MS_TRANSFER_END			0x40
-#define MS_TRANSFER_ERR			0x20
-#define MS_BS_STATE			0x10
-#define MS_TM_READ_BYTES		0x00
-#define MS_TM_NORMAL_READ		0x01
-#define MS_TM_WRITE_BYTES		0x04
-#define MS_TM_NORMAL_WRITE		0x05
-#define MS_TM_AUTO_READ			0x08
-#define MS_TM_AUTO_WRITE		0x0C
-
-/* SD Configure 2 Register */
-#define SD_CALCULATE_CRC7		0x00
-#define SD_NO_CALCULATE_CRC7		0x80
-#define SD_CHECK_CRC16			0x00
-#define SD_NO_CHECK_CRC16		0x40
-#define SD_NO_CHECK_WAIT_CRC_TO		0x20
-#define SD_WAIT_BUSY_END		0x08
-#define SD_NO_WAIT_BUSY_END		0x00
-#define SD_CHECK_CRC7			0x00
-#define SD_NO_CHECK_CRC7		0x04
-#define SD_RSP_LEN_0			0x00
-#define SD_RSP_LEN_6			0x01
-#define SD_RSP_LEN_17			0x02
-/* SD/MMC Response Type Definition */
-#define SD_RSP_TYPE_R0			0x04
-#define SD_RSP_TYPE_R1			0x01
-#define SD_RSP_TYPE_R1b			0x09
-#define SD_RSP_TYPE_R2			0x02
-#define SD_RSP_TYPE_R3			0x05
-#define SD_RSP_TYPE_R4			0x05
-#define SD_RSP_TYPE_R5			0x01
-#define SD_RSP_TYPE_R6			0x01
-#define SD_RSP_TYPE_R7			0x01
-
-/* SD_CONFIGURE3 */
-#define SD_RSP_80CLK_TIMEOUT_EN		0x01
-
-/* Card Transfer Reset Register */
-#define SPI_STOP			0x01
-#define XD_STOP				0x02
-#define SD_STOP				0x04
-#define MS_STOP				0x08
-#define SPI_CLR_ERR			0x10
-#define XD_CLR_ERR			0x20
-#define SD_CLR_ERR			0x40
-#define MS_CLR_ERR			0x80
-
-/* Card Data Source Register */
-#define PINGPONG_BUFFER			0x01
-#define RING_BUFFER			0x00
-
-/* Card Power Control Register */
-#define PMOS_STRG_MASK			0x10
-#define PMOS_STRG_800mA			0x10
-#define PMOS_STRG_400mA			0x00
-#define SD_POWER_OFF			0x03
-#define SD_PARTIAL_POWER_ON		0x01
-#define SD_POWER_ON			0x00
-#define SD_POWER_MASK			0x03
-#define MS_POWER_OFF			0x0C
-#define MS_PARTIAL_POWER_ON		0x04
-#define MS_POWER_ON			0x00
-#define MS_POWER_MASK			0x0C
-#define BPP_POWER_OFF			0x0F
-#define BPP_POWER_5_PERCENT_ON		0x0E
-#define BPP_POWER_10_PERCENT_ON		0x0C
-#define BPP_POWER_15_PERCENT_ON		0x08
-#define BPP_POWER_ON			0x00
-#define BPP_POWER_MASK			0x0F
-#define SD_VCC_PARTIAL_POWER_ON		0x02
-#define SD_VCC_POWER_ON			0x00
-
-/* PWR_GATE_CTRL */
-#define PWR_GATE_EN			0x01
-#define LDO3318_PWR_MASK		0x06
-#define LDO_ON				0x00
-#define LDO_SUSPEND			0x04
-#define LDO_OFF				0x06
-
-/* CARD_CLK_SOURCE */
-#define CRC_FIX_CLK			(0x00 << 0)
-#define CRC_VAR_CLK0			(0x01 << 0)
-#define CRC_VAR_CLK1			(0x02 << 0)
-#define SD30_FIX_CLK			(0x00 << 2)
-#define SD30_VAR_CLK0			(0x01 << 2)
-#define SD30_VAR_CLK1			(0x02 << 2)
-#define SAMPLE_FIX_CLK			(0x00 << 4)
-#define SAMPLE_VAR_CLK0			(0x01 << 4)
-#define SAMPLE_VAR_CLK1			(0x02 << 4)
-
-/* HOST_SLEEP_STATE */
-#define HOST_ENTER_S1			1
-#define HOST_ENTER_S3			2
+#define RTSX_PHASE_MAX			32
+#define RX_TUNING_CNT			3
 
 #define MS_CFG				0xFD40
+#define   SAMPLE_TIME_RISING		0x00
+#define   SAMPLE_TIME_FALLING		0x80
+#define   PUSH_TIME_DEFAULT		0x00
+#define   PUSH_TIME_ODD			0x40
+#define   NO_EXTEND_TOGGLE		0x00
+#define   EXTEND_TOGGLE_CHK		0x20
+#define   MS_BUS_WIDTH_1		0x00
+#define   MS_BUS_WIDTH_4		0x10
+#define   MS_BUS_WIDTH_8		0x18
+#define   MS_2K_SECTOR_MODE		0x04
+#define   MS_512_SECTOR_MODE		0x00
+#define   MS_TOGGLE_TIMEOUT_EN		0x00
+#define   MS_TOGGLE_TIMEOUT_DISEN	0x01
+#define MS_NO_CHECK_INT			0x02
 #define MS_TPC				0xFD41
 #define MS_TRANS_CFG			0xFD42
+#define   WAIT_INT			0x80
+#define   NO_WAIT_INT			0x00
+#define   NO_AUTO_READ_INT_REG		0x00
+#define   AUTO_READ_INT_REG		0x40
+#define   MS_CRC16_ERR			0x20
+#define   MS_RDY_TIMEOUT		0x10
+#define   MS_INT_CMDNK			0x08
+#define   MS_INT_BREQ			0x04
+#define   MS_INT_ERR			0x02
+#define   MS_INT_CED			0x01
 #define MS_TRANSFER			0xFD43
+#define   MS_TRANSFER_START		0x80
+#define   MS_TRANSFER_END		0x40
+#define   MS_TRANSFER_ERR		0x20
+#define   MS_BS_STATE			0x10
+#define   MS_TM_READ_BYTES		0x00
+#define   MS_TM_NORMAL_READ		0x01
+#define   MS_TM_WRITE_BYTES		0x04
+#define   MS_TM_NORMAL_WRITE		0x05
+#define   MS_TM_AUTO_READ		0x08
+#define   MS_TM_AUTO_WRITE		0x0C
 #define MS_INT_REG			0xFD44
 #define MS_BYTE_CNT			0xFD45
 #define MS_SECTOR_CNT_L			0xFD46
@@ -549,14 +192,90 @@
 #define MS_DBUS_H			0xFD48
 
 #define SD_CFG1				0xFDA0
+#define   SD_CLK_DIVIDE_0		0x00
+#define   SD_CLK_DIVIDE_256		0xC0
+#define   SD_CLK_DIVIDE_128		0x80
+#define   SD_BUS_WIDTH_1BIT		0x00
+#define   SD_BUS_WIDTH_4BIT		0x01
+#define   SD_BUS_WIDTH_8BIT		0x02
+#define   SD_ASYNC_FIFO_NOT_RST		0x10
+#define   SD_20_MODE			0x00
+#define   SD_DDR_MODE			0x04
+#define   SD_30_MODE			0x08
+#define   SD_CLK_DIVIDE_MASK		0xC0
 #define SD_CFG2				0xFDA1
+#define   SD_CALCULATE_CRC7		0x00
+#define   SD_NO_CALCULATE_CRC7		0x80
+#define   SD_CHECK_CRC16		0x00
+#define   SD_NO_CHECK_CRC16		0x40
+#define   SD_NO_CHECK_WAIT_CRC_TO	0x20
+#define   SD_WAIT_BUSY_END		0x08
+#define   SD_NO_WAIT_BUSY_END		0x00
+#define   SD_CHECK_CRC7			0x00
+#define   SD_NO_CHECK_CRC7		0x04
+#define   SD_RSP_LEN_0			0x00
+#define   SD_RSP_LEN_6			0x01
+#define   SD_RSP_LEN_17			0x02
+#define   SD_RSP_TYPE_R0		0x04
+#define   SD_RSP_TYPE_R1		0x01
+#define   SD_RSP_TYPE_R1b		0x09
+#define   SD_RSP_TYPE_R2		0x02
+#define   SD_RSP_TYPE_R3		0x05
+#define   SD_RSP_TYPE_R4		0x05
+#define   SD_RSP_TYPE_R5		0x01
+#define   SD_RSP_TYPE_R6		0x01
+#define   SD_RSP_TYPE_R7		0x01
 #define SD_CFG3				0xFDA2
+#define   SD_RSP_80CLK_TIMEOUT_EN	0x01
+
 #define SD_STAT1			0xFDA3
+#define   SD_CRC7_ERR			0x80
+#define   SD_CRC16_ERR			0x40
+#define   SD_CRC_WRITE_ERR		0x20
+#define   SD_CRC_WRITE_ERR_MASK		0x1C
+#define   GET_CRC_TIME_OUT		0x02
+#define   SD_TUNING_COMPARE_ERR		0x01
 #define SD_STAT2			0xFDA4
+#define   SD_RSP_80CLK_TIMEOUT		0x01
+
 #define SD_BUS_STAT			0xFDA5
+#define   SD_CLK_TOGGLE_EN		0x80
+#define   SD_CLK_FORCE_STOP		0x40
+#define   SD_DAT3_STATUS		0x10
+#define   SD_DAT2_STATUS		0x08
+#define   SD_DAT1_STATUS		0x04
+#define   SD_DAT0_STATUS		0x02
+#define   SD_CMD_STATUS			0x01
 #define SD_PAD_CTL			0xFDA6
+#define   SD_IO_USING_1V8		0x80
+#define   SD_IO_USING_3V3		0x7F
+#define   TYPE_A_DRIVING		0x00
+#define   TYPE_B_DRIVING		0x01
+#define   TYPE_C_DRIVING		0x02
+#define   TYPE_D_DRIVING		0x03
 #define SD_SAMPLE_POINT_CTL		0xFDA7
+#define   DDR_FIX_RX_DAT		0x00
+#define   DDR_VAR_RX_DAT		0x80
+#define   DDR_FIX_RX_DAT_EDGE		0x00
+#define   DDR_FIX_RX_DAT_14_DELAY	0x40
+#define   DDR_FIX_RX_CMD		0x00
+#define   DDR_VAR_RX_CMD		0x20
+#define   DDR_FIX_RX_CMD_POS_EDGE	0x00
+#define   DDR_FIX_RX_CMD_14_DELAY	0x10
+#define   SD20_RX_POS_EDGE		0x00
+#define   SD20_RX_14_DELAY		0x08
+#define SD20_RX_SEL_MASK		0x08
 #define SD_PUSH_POINT_CTL		0xFDA8
+#define   DDR_FIX_TX_CMD_DAT		0x00
+#define   DDR_VAR_TX_CMD_DAT		0x80
+#define   DDR_FIX_TX_DAT_14_TSU		0x00
+#define   DDR_FIX_TX_DAT_12_TSU		0x40
+#define   DDR_FIX_TX_CMD_NEG_EDGE	0x00
+#define   DDR_FIX_TX_CMD_14_AHEAD	0x20
+#define   SD20_TX_NEG_EDGE		0x00
+#define   SD20_TX_14_AHEAD		0x10
+#define   SD20_TX_SEL_MASK		0x10
+#define   DDR_VAR_SDCLK_POL_SWAP	0x01
 #define SD_CMD0				0xFDA9
 #define   SD_CMD_START			0x40
 #define SD_CMD1				0xFDAA
@@ -569,14 +288,46 @@
 #define SD_BLOCK_CNT_L			0xFDB1
 #define SD_BLOCK_CNT_H			0xFDB2
 #define SD_TRANSFER			0xFDB3
+#define   SD_TRANSFER_START		0x80
+#define   SD_TRANSFER_END		0x40
+#define   SD_STAT_IDLE			0x20
+#define   SD_TRANSFER_ERR		0x10
+#define   SD_TM_NORMAL_WRITE		0x00
+#define   SD_TM_AUTO_WRITE_3		0x01
+#define   SD_TM_AUTO_WRITE_4		0x02
+#define   SD_TM_AUTO_READ_3		0x05
+#define   SD_TM_AUTO_READ_4		0x06
+#define   SD_TM_CMD_RSP			0x08
+#define   SD_TM_AUTO_WRITE_1		0x09
+#define   SD_TM_AUTO_WRITE_2		0x0A
+#define   SD_TM_NORMAL_READ		0x0C
+#define   SD_TM_AUTO_READ_1		0x0D
+#define   SD_TM_AUTO_READ_2		0x0E
+#define   SD_TM_AUTO_TUNING		0x0F
 #define SD_CMD_STATE			0xFDB5
+#define   SD_CMD_IDLE			0x80
+
 #define SD_DATA_STATE			0xFDB6
+#define   SD_DATA_IDLE			0x80
 
 #define SRCTL				0xFC13
 
 #define DCM_DRP_CTL			0xFC23
+#define   DCM_RESET			0x08
+#define   DCM_LOCKED			0x04
+#define   DCM_208M			0x00
+#define   DCM_TX			0x01
+#define   DCM_RX			0x02
 #define DCM_DRP_TRIG			0xFC24
+#define   DRP_START			0x80
+#define   DRP_DONE			0x40
 #define DCM_DRP_CFG			0xFC25
+#define   DRP_WRITE			0x80
+#define   DRP_READ			0x00
+#define   DCM_WRITE_ADDRESS_50		0x50
+#define   DCM_WRITE_ADDRESS_51		0x51
+#define   DCM_READ_ADDRESS_00		0x00
+#define   DCM_READ_ADDRESS_51		0x51
 #define DCM_DRP_WR_DATA_L		0xFC26
 #define DCM_DRP_WR_DATA_H		0xFC27
 #define DCM_DRP_RD_DATA_L		0xFC28
@@ -587,42 +338,153 @@
 #define SD_DCMPS1_CTL			0xFC2D
 #define SD_VPTX_CTL			SD_VPCLK0_CTL
 #define SD_VPRX_CTL			SD_VPCLK1_CTL
+#define   PHASE_CHANGE			0x80
+#define   PHASE_NOT_RESET		0x40
 #define SD_DCMPS_TX_CTL			SD_DCMPS0_CTL
 #define SD_DCMPS_RX_CTL			SD_DCMPS1_CTL
+#define   DCMPS_CHANGE			0x80
+#define   DCMPS_CHANGE_DONE		0x40
+#define   DCMPS_ERROR			0x20
+#define   DCMPS_CURRENT_PHASE		0x1F
 #define CARD_CLK_SOURCE			0xFC2E
-
+#define   CRC_FIX_CLK			(0x00 << 0)
+#define   CRC_VAR_CLK0			(0x01 << 0)
+#define   CRC_VAR_CLK1			(0x02 << 0)
+#define   SD30_FIX_CLK			(0x00 << 2)
+#define   SD30_VAR_CLK0			(0x01 << 2)
+#define   SD30_VAR_CLK1			(0x02 << 2)
+#define   SAMPLE_FIX_CLK		(0x00 << 4)
+#define   SAMPLE_VAR_CLK0		(0x01 << 4)
+#define   SAMPLE_VAR_CLK1		(0x02 << 4)
 #define CARD_PWR_CTL			0xFD50
+#define   PMOS_STRG_MASK		0x10
+#define   PMOS_STRG_800mA		0x10
+#define   PMOS_STRG_400mA		0x00
+#define   SD_POWER_OFF			0x03
+#define   SD_PARTIAL_POWER_ON		0x01
+#define   SD_POWER_ON			0x00
+#define   SD_POWER_MASK			0x03
+#define   MS_POWER_OFF			0x0C
+#define   MS_PARTIAL_POWER_ON		0x04
+#define   MS_POWER_ON			0x00
+#define   MS_POWER_MASK			0x0C
+#define   BPP_POWER_OFF			0x0F
+#define   BPP_POWER_5_PERCENT_ON	0x0E
+#define   BPP_POWER_10_PERCENT_ON	0x0C
+#define   BPP_POWER_15_PERCENT_ON	0x08
+#define   BPP_POWER_ON			0x00
+#define   BPP_POWER_MASK		0x0F
+#define   SD_VCC_PARTIAL_POWER_ON	0x02
+#define   SD_VCC_POWER_ON		0x00
 #define CARD_CLK_SWITCH			0xFD51
 #define RTL8411B_PACKAGE_MODE		0xFD51
 #define CARD_SHARE_MODE			0xFD52
+#define   CARD_SHARE_MASK		0x0F
+#define   CARD_SHARE_MULTI_LUN		0x00
+#define   CARD_SHARE_NORMAL		0x00
+#define   CARD_SHARE_48_SD		0x04
+#define   CARD_SHARE_48_MS		0x08
+#define   CARD_SHARE_BAROSSA_SD		0x01
+#define   CARD_SHARE_BAROSSA_MS		0x02
 #define CARD_DRIVE_SEL			0xFD53
+#define   MS_DRIVE_8mA			(0x01 << 6)
+#define   MMC_DRIVE_8mA			(0x01 << 4)
+#define   XD_DRIVE_8mA			(0x01 << 2)
+#define   GPIO_DRIVE_8mA		0x01
+#define RTS5209_CARD_DRIVE_DEFAULT	(MS_DRIVE_8mA | MMC_DRIVE_8mA |\
+					XD_DRIVE_8mA | GPIO_DRIVE_8mA)
+#define RTL8411_CARD_DRIVE_DEFAULT	(MS_DRIVE_8mA | MMC_DRIVE_8mA |\
+					XD_DRIVE_8mA)
+#define RTSX_CARD_DRIVE_DEFAULT		(MS_DRIVE_8mA | GPIO_DRIVE_8mA)
+
 #define CARD_STOP			0xFD54
+#define   SPI_STOP			0x01
+#define   XD_STOP			0x02
+#define   SD_STOP			0x04
+#define   MS_STOP			0x08
+#define   SPI_CLR_ERR			0x10
+#define   XD_CLR_ERR			0x20
+#define   SD_CLR_ERR			0x40
+#define   MS_CLR_ERR			0x80
 #define CARD_OE				0xFD55
+#define   SD_OUTPUT_EN			0x04
+#define   MS_OUTPUT_EN			0x08
 #define CARD_AUTO_BLINK			0xFD56
 #define CARD_GPIO_DIR			0xFD57
 #define CARD_GPIO			0xFD58
 #define CARD_DATA_SOURCE		0xFD5B
+#define   PINGPONG_BUFFER		0x01
+#define   RING_BUFFER			0x00
 #define SD30_CLK_DRIVE_SEL		0xFD5A
+#define   DRIVER_TYPE_A			0x05
+#define   DRIVER_TYPE_B			0x03
+#define   DRIVER_TYPE_C			0x02
+#define   DRIVER_TYPE_D			0x01
 #define CARD_SELECT			0xFD5C
+#define   SD_MOD_SEL			2
+#define   MS_MOD_SEL			3
 #define SD30_DRIVE_SEL			0xFD5E
+#define   CFG_DRIVER_TYPE_A		0x02
+#define   CFG_DRIVER_TYPE_B		0x03
+#define   CFG_DRIVER_TYPE_C		0x01
+#define   CFG_DRIVER_TYPE_D		0x00
 #define SD30_CMD_DRIVE_SEL		0xFD5E
 #define SD30_DAT_DRIVE_SEL		0xFD5F
 #define CARD_CLK_EN			0xFD69
+#define   SD_CLK_EN			0x04
+#define   MS_CLK_EN			0x08
 #define SDIO_CTRL			0xFD6B
 #define CD_PAD_CTL			0xFD73
-
+#define   CD_DISABLE_MASK		0x07
+#define   MS_CD_DISABLE			0x04
+#define   SD_CD_DISABLE			0x02
+#define   XD_CD_DISABLE			0x01
+#define   CD_DISABLE			0x07
+#define   CD_ENABLE			0x00
+#define   MS_CD_EN_ONLY			0x03
+#define   SD_CD_EN_ONLY			0x05
+#define   XD_CD_EN_ONLY			0x06
+#define   FORCE_CD_LOW_MASK		0x38
+#define   FORCE_CD_XD_LOW		0x08
+#define   FORCE_CD_SD_LOW		0x10
+#define   FORCE_CD_MS_LOW		0x20
+#define   CD_AUTO_DISABLE		0x40
 #define FPDCTL				0xFC00
+#define   SSC_POWER_DOWN		0x01
+#define   SD_OC_POWER_DOWN		0x02
+#define   ALL_POWER_DOWN		0x07
+#define   OC_POWER_DOWN			0x06
 #define PDINFO				0xFC01
 
 #define CLK_CTL				0xFC02
+#define   CHANGE_CLK			0x01
+#define   CLK_LOW_FREQ			0x01
+
 #define CLK_DIV				0xFC03
+#define   CLK_DIV_1			0x01
+#define   CLK_DIV_2			0x02
+#define   CLK_DIV_4			0x03
+#define   CLK_DIV_8			0x04
 #define CLK_SEL				0xFC04
 
 #define SSC_DIV_N_0			0xFC0F
 #define SSC_DIV_N_1			0xFC10
 #define SSC_CTL1			0xFC11
+#define    SSC_RSTB			0x80
+#define    SSC_8X_EN			0x40
+#define    SSC_FIX_FRAC			0x20
+#define    SSC_SEL_1M			0x00
+#define    SSC_SEL_2M			0x08
+#define    SSC_SEL_4M			0x10
+#define    SSC_SEL_8M			0x18
 #define SSC_CTL2			0xFC12
-
+#define    SSC_DEPTH_MASK		0x07
+#define    SSC_DEPTH_DISALBE		0x00
+#define    SSC_DEPTH_4M			0x01
+#define    SSC_DEPTH_2M			0x02
+#define    SSC_DEPTH_1M			0x03
+#define    SSC_DEPTH_500K		0x04
+#define    SSC_DEPTH_250K		0x05
 #define RCCTL				0xFC14
 
 #define FPGA_PULL_CTL			0xFC1D
@@ -630,6 +492,24 @@
 #define GPIO_CTL			0xFC1F
 
 #define LDO_CTL				0xFC1E
+#define   BPP_ASIC_1V7			0x00
+#define   BPP_ASIC_1V8			0x01
+#define   BPP_ASIC_1V9			0x02
+#define   BPP_ASIC_2V0			0x03
+#define   BPP_ASIC_2V7			0x04
+#define   BPP_ASIC_2V8			0x05
+#define   BPP_ASIC_3V2			0x06
+#define   BPP_ASIC_3V3			0x07
+#define   BPP_REG_TUNED18		0x07
+#define   BPP_TUNED18_SHIFT_8402	5
+#define   BPP_TUNED18_SHIFT_8411	4
+#define   BPP_PAD_MASK			0x04
+#define   BPP_PAD_3V3			0x04
+#define   BPP_PAD_1V8			0x00
+#define   BPP_LDO_POWB			0x03
+#define   BPP_LDO_ON			0x00
+#define   BPP_LDO_SUSPEND		0x02
+#define   BPP_LDO_OFF			0x03
 #define SYS_VER				0xFC32
 
 #define CARD_PULL_CTL1			0xFD60
@@ -642,6 +522,10 @@
 /* PCI Express Related Registers */
 #define IRQEN0				0xFE20
 #define IRQSTAT0			0xFE21
+#define    DMA_DONE_INT			0x80
+#define    SUSPEND_INT			0x40
+#define    LINK_RDY_INT			0x20
+#define    LINK_DOWN_INT		0x10
 #define IRQEN1				0xFE22
 #define IRQSTAT1			0xFE23
 #define TLPRIEN				0xFE24
@@ -653,6 +537,16 @@
 #define DMATC2				0xFE2A
 #define DMATC3				0xFE2B
 #define DMACTL				0xFE2C
+#define   DMA_RST			0x80
+#define   DMA_BUSY			0x04
+#define   DMA_DIR_TO_CARD		0x00
+#define   DMA_DIR_FROM_CARD		0x02
+#define   DMA_EN			0x01
+#define   DMA_128			(0 << 4)
+#define   DMA_256			(1 << 4)
+#define   DMA_512			(2 << 4)
+#define   DMA_1024			(3 << 4)
+#define   DMA_PACK_SIZE_MASK		0x30
 #define BCTL				0xFE2D
 #define RBBC0				0xFE2E
 #define RBBC1				0xFE2F
@@ -693,11 +587,19 @@
 #define RESET_LOAD_REG			0xFE5E
 #define EFUSE_CONTENT			0xFE5F
 #define HOST_SLEEP_STATE		0xFE60
+#define   HOST_ENTER_S1			1
+#define   HOST_ENTER_S3			2
+
 #define SDIO_CFG			0xFE70
 
 #define NFTS_TX_CTRL			0xFE72
 
 #define PWR_GATE_CTRL			0xFE75
+#define   PWR_GATE_EN			0x01
+#define   LDO3318_PWR_MASK		0x06
+#define   LDO_ON			0x00
+#define   LDO_SUSPEND			0x04
+#define   LDO_OFF			0x06
 #define PWD_SUSPEND_EN			0xFE76
 #define LDO_PWR_SEL			0xFE78
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 03/10] mfd: rtsx: add debug info when access register failed
  2015-01-15 11:18 [PATCH 00/10] mfd: rtsx: add support for new rts524A and rts525A micky_ching
  2015-01-15 11:18 ` [PATCH 01/10] mfd: rtsx: replace TAB by SPC after #define micky_ching
  2015-01-15 11:18 ` [PATCH 02/10] mfd: rtsx: place register address and values togather micky_ching
@ 2015-01-15 11:19 ` micky_ching
  2015-01-18 12:35   ` Lee Jones
  2015-01-15 11:19 ` [PATCH 04/10] mfd: rtsx: update PETXCFG address micky_ching
                   ` (6 subsequent siblings)
  9 siblings, 1 reply; 36+ messages in thread
From: micky_ching @ 2015-01-15 11:19 UTC (permalink / raw)
  To: sameo, lee.jones
  Cc: devel, linux-kernel, gregkh, rogerable, wei_wang, Micky Ching

From: Micky Ching <micky_ching@realsil.com.cn>

Add debug info when access register failed, this is useful for
debug.

Signed-off-by: Micky Ching <micky_ching@realsil.com.cn>
---
 drivers/mfd/rtsx_pcr.c       | 22 +++++++++++++++++-----
 include/linux/mfd/rtsx_pci.h |  2 ++
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/drivers/mfd/rtsx_pcr.c b/drivers/mfd/rtsx_pcr.c
index 30f7ca8..92f5a41 100644
--- a/drivers/mfd/rtsx_pcr.c
+++ b/drivers/mfd/rtsx_pcr.c
@@ -96,12 +96,16 @@ int rtsx_pci_write_register(struct rtsx_pcr *pcr, u16 addr, u8 mask, u8 data)
 	for (i = 0; i < MAX_RW_REG_CNT; i++) {
 		val = rtsx_pci_readl(pcr, RTSX_HAIMR);
 		if ((val & HAIMR_TRANS_END) == 0) {
-			if (data != (u8)val)
+			if (data != (u8)val) {
+				pcr_dbg(pcr, "write register 0x%02x failed\n",
+					addr);
 				return -EIO;
+			}
 			return 0;
 		}
 	}
 
+	pcr_dbg(pcr, "write register 0x%02x failed\n", addr);
 	return -ETIMEDOUT;
 }
 EXPORT_SYMBOL_GPL(rtsx_pci_write_register);
@@ -120,8 +124,10 @@ int rtsx_pci_read_register(struct rtsx_pcr *pcr, u16 addr, u8 *data)
 			break;
 	}
 
-	if (i >= MAX_RW_REG_CNT)
+	if (i >= MAX_RW_REG_CNT) {
+		pcr_dbg(pcr, "read register 0x%02x failed\n", addr);
 		return -ETIMEDOUT;
+	}
 
 	if (data)
 		*data = (u8)(val & 0xFF);
@@ -157,8 +163,10 @@ int rtsx_pci_write_phy_register(struct rtsx_pcr *pcr, u8 addr, u16 val)
 		}
 	}
 
-	if (!finished)
+	if (!finished) {
+		pcr_dbg(pcr, "write phy 0x%x failed\n", addr);
 		return -ETIMEDOUT;
+	}
 
 	return 0;
 }
@@ -190,8 +198,10 @@ int rtsx_pci_read_phy_register(struct rtsx_pcr *pcr, u8 addr, u16 *val)
 		}
 	}
 
-	if (!finished)
+	if (!finished) {
+		pcr_dbg(pcr, "read phy 0x%x failed\n", addr);
 		return -ETIMEDOUT;
+	}
 
 	rtsx_pci_init_cmd(pcr);
 
@@ -199,8 +209,10 @@ int rtsx_pci_read_phy_register(struct rtsx_pcr *pcr, u8 addr, u16 *val)
 	rtsx_pci_add_cmd(pcr, READ_REG_CMD, PHYDATA1, 0, 0);
 
 	err = rtsx_pci_send_cmd(pcr, 100);
-	if (err < 0)
+	if (err < 0) {
+		pcr_dbg(pcr, "read phy 0x%x failed\n", addr);
 		return err;
+	}
 
 	ptr = rtsx_pci_get_cmd_data(pcr);
 	data = ((u16)ptr[1] << 8) | ptr[0];
diff --git a/include/linux/mfd/rtsx_pci.h b/include/linux/mfd/rtsx_pci.h
index e81f2bb..a680427 100644
--- a/include/linux/mfd/rtsx_pci.h
+++ b/include/linux/mfd/rtsx_pci.h
@@ -838,6 +838,8 @@ struct rtsx_pcr {
 #define PCI_VID(pcr)			((pcr)->pci->vendor)
 #define PCI_PID(pcr)			((pcr)->pci->device)
 
+#define pcr_dbg(pcr, fmt, arg...)			\
+	dev_dbg(&(pcr)->pci->dev, fmt, ##arg)
 #define SDR104_PHASE(val)		((val) & 0xFF)
 #define SDR50_PHASE(val)		(((val) >> 8) & 0xFF)
 #define DDR50_PHASE(val)		(((val) >> 16) & 0xFF)
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 04/10] mfd: rtsx: update PETXCFG address
  2015-01-15 11:18 [PATCH 00/10] mfd: rtsx: add support for new rts524A and rts525A micky_ching
                   ` (2 preceding siblings ...)
  2015-01-15 11:19 ` [PATCH 03/10] mfd: rtsx: add debug info when access register failed micky_ching
@ 2015-01-15 11:19 ` micky_ching
  2015-01-18 12:31   ` Lee Jones
  2015-01-15 11:19 ` [PATCH 05/10] mfd: rtsx: update driving settings micky_ching
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 36+ messages in thread
From: micky_ching @ 2015-01-15 11:19 UTC (permalink / raw)
  To: sameo, lee.jones
  Cc: devel, linux-kernel, gregkh, rogerable, wei_wang, Micky Ching

From: Micky Ching <micky_ching@realsil.com.cn>

PETXCFG is defined at 0xFF03, the old 0xFE49 not used any more.

Signed-off-by: Micky Ching <micky_ching@realsil.com.cn>
---
 drivers/mfd/rts5227.c        | 6 ++----
 drivers/mfd/rts5249.c        | 6 ++----
 include/linux/mfd/rtsx_pci.h | 2 +-
 3 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/mfd/rts5227.c b/drivers/mfd/rts5227.c
index 3240740..1f387d4 100644
--- a/drivers/mfd/rts5227.c
+++ b/drivers/mfd/rts5227.c
@@ -118,11 +118,9 @@ static int rts5227_extra_init_hw(struct rtsx_pcr *pcr)
 	rts5227_fill_driving(pcr, OUTPUT_3V3);
 	/* Configure force_clock_req */
 	if (pcr->flags & PCR_REVERSE_SOCKET)
-		rtsx_pci_add_cmd(pcr, WRITE_REG_CMD,
-				AUTOLOAD_CFG_BASE + 3, 0xB8, 0xB8);
+		rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PETXCFG, 0xB8, 0xB8);
 	else
-		rtsx_pci_add_cmd(pcr, WRITE_REG_CMD,
-				AUTOLOAD_CFG_BASE + 3, 0xB8, 0x88);
+		rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PETXCFG, 0xB8, 0x88);
 	rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PM_CTRL3, 0x10, 0x00);
 
 	return rtsx_pci_send_cmd(pcr, 100);
diff --git a/drivers/mfd/rts5249.c b/drivers/mfd/rts5249.c
index cf425cc..225ad55 100644
--- a/drivers/mfd/rts5249.c
+++ b/drivers/mfd/rts5249.c
@@ -116,11 +116,9 @@ static int rts5249_extra_init_hw(struct rtsx_pcr *pcr)
 	/* Configure driving */
 	rts5249_fill_driving(pcr, OUTPUT_3V3);
 	if (pcr->flags & PCR_REVERSE_SOCKET)
-		rtsx_pci_add_cmd(pcr, WRITE_REG_CMD,
-				AUTOLOAD_CFG_BASE + 3, 0xB0, 0xB0);
+		rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PETXCFG, 0xB0, 0xB0);
 	else
-		rtsx_pci_add_cmd(pcr, WRITE_REG_CMD,
-				AUTOLOAD_CFG_BASE + 3, 0xB0, 0x80);
+		rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PETXCFG, 0xB0, 0x80);
 	rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PM_CTRL3, 0x10, 0x00);
 
 	return rtsx_pci_send_cmd(pcr, 100);
diff --git a/include/linux/mfd/rtsx_pci.h b/include/linux/mfd/rtsx_pci.h
index a680427..80baa10 100644
--- a/include/linux/mfd/rtsx_pci.h
+++ b/include/linux/mfd/rtsx_pci.h
@@ -572,7 +572,6 @@
 #define MSGTXDATA2			0xFE46
 #define MSGTXDATA3			0xFE47
 #define MSGTXCTL			0xFE48
-#define PETXCFG				0xFE49
 #define LTR_CTL				0xFE4A
 #define OBFF_CFG			0xFE4C
 
@@ -606,6 +605,7 @@
 #define DUMMY_REG_RESET_0		0xFE90
 
 #define AUTOLOAD_CFG_BASE		0xFF00
+#define PETXCFG				0xFF03
 
 #define PM_CTRL1			0xFF44
 #define PM_CTRL2			0xFF45
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 05/10] mfd: rtsx: update driving settings
  2015-01-15 11:18 [PATCH 00/10] mfd: rtsx: add support for new rts524A and rts525A micky_ching
                   ` (3 preceding siblings ...)
  2015-01-15 11:19 ` [PATCH 04/10] mfd: rtsx: update PETXCFG address micky_ching
@ 2015-01-15 11:19 ` micky_ching
  2015-01-18 12:32   ` Lee Jones
  2015-01-15 11:19 ` [PATCH 06/10] mfd: rtsx: update phy register micky_ching
                   ` (4 subsequent siblings)
  9 siblings, 1 reply; 36+ messages in thread
From: micky_ching @ 2015-01-15 11:19 UTC (permalink / raw)
  To: sameo, lee.jones
  Cc: devel, linux-kernel, gregkh, rogerable, wei_wang, Micky Ching

From: Micky Ching <micky_ching@realsil.com.cn>

update card drive settings, This setting can be used for rts5249
rts524A and rts525A.

Signed-off-by: Micky Ching <micky_ching@realsil.com.cn>
---
 drivers/mfd/rts5249.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/mfd/rts5249.c b/drivers/mfd/rts5249.c
index 225ad55..2fe2854 100644
--- a/drivers/mfd/rts5249.c
+++ b/drivers/mfd/rts5249.c
@@ -36,16 +36,16 @@ static u8 rts5249_get_ic_version(struct rtsx_pcr *pcr)
 static void rts5249_fill_driving(struct rtsx_pcr *pcr, u8 voltage)
 {
 	u8 driving_3v3[4][3] = {
-		{0x11, 0x11, 0x11},
+		{0x11, 0x11, 0x18},
 		{0x55, 0x55, 0x5C},
-		{0x99, 0x99, 0x92},
-		{0x99, 0x99, 0x92},
+		{0xFF, 0xFF, 0xFF},
+		{0x96, 0x96, 0x96},
 	};
 	u8 driving_1v8[4][3] = {
+		{0xC4, 0xC4, 0xC4},
 		{0x3C, 0x3C, 0x3C},
-		{0xB3, 0xB3, 0xB3},
 		{0xFE, 0xFE, 0xFE},
-		{0xC4, 0xC4, 0xC4},
+		{0xB3, 0xB3, 0xB3},
 	};
 	u8 (*driving)[3], drive_sel;
 
@@ -341,7 +341,7 @@ void rts5249_init_params(struct rtsx_pcr *pcr)
 
 	pcr->flags = 0;
 	pcr->card_drive_sel = RTSX_CARD_DRIVE_DEFAULT;
-	pcr->sd30_drive_sel_1v8 = CFG_DRIVER_TYPE_C;
+	pcr->sd30_drive_sel_1v8 = CFG_DRIVER_TYPE_B;
 	pcr->sd30_drive_sel_3v3 = CFG_DRIVER_TYPE_B;
 	pcr->aspm_en = ASPM_L1_EN;
 	pcr->tx_initial_phase = SET_CLOCK_PHASE(1, 29, 16);
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 06/10] mfd: rtsx: update phy register
  2015-01-15 11:18 [PATCH 00/10] mfd: rtsx: add support for new rts524A and rts525A micky_ching
                   ` (4 preceding siblings ...)
  2015-01-15 11:19 ` [PATCH 05/10] mfd: rtsx: update driving settings micky_ching
@ 2015-01-15 11:19 ` micky_ching
  2015-01-18 12:29   ` Lee Jones
  2015-01-15 11:19 ` [PATCH 07/10] mfd: rtsx: remove LCTLR defination micky_ching
                   ` (3 subsequent siblings)
  9 siblings, 1 reply; 36+ messages in thread
From: micky_ching @ 2015-01-15 11:19 UTC (permalink / raw)
  To: sameo, lee.jones
  Cc: devel, linux-kernel, gregkh, rogerable, wei_wang, Micky Ching

From: Micky Ching <micky_ching@realsil.com.cn>

update phy register value and using direct value instead of macros.
It is much easier to debug using constant value than a lot of macros.
We usually need compare the value directly to check the configure.

Signed-off-by: Micky Ching <micky_ching@realsil.com.cn>
---
 drivers/mfd/rts5249.c | 46 ++++++++++++++--------------------------------
 1 file changed, 14 insertions(+), 32 deletions(-)

diff --git a/drivers/mfd/rts5249.c b/drivers/mfd/rts5249.c
index 2fe2854..00208d1 100644
--- a/drivers/mfd/rts5249.c
+++ b/drivers/mfd/rts5249.c
@@ -132,57 +132,39 @@ static int rts5249_optimize_phy(struct rtsx_pcr *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 |
-			PHY_REG_REV_RX_PWST | PHY_REG_REV_CLKREQ_DLY_TIMER_1_0 |
-			PHY_REG_REV_STOP_CLKRD | PHY_REG_REV_STOP_CLKWR);
+	err = rtsx_pci_write_phy_register(pcr, 0x19, 0xFE6C);
 	if (err < 0)
 		return err;
 
 	msleep(1);
 
-	err = rtsx_pci_write_phy_register(pcr, PHY_BPCR,
-			PHY_BPCR_IBRXSEL | PHY_BPCR_IBTXSEL |
-			PHY_BPCR_IB_FILTER | PHY_BPCR_CMIRROR_EN);
+	err = rtsx_pci_write_phy_register(pcr, 0x0A, 0x05C0);
 	if (err < 0)
 		return err;
-	err = rtsx_pci_write_phy_register(pcr, PHY_PCR,
-			PHY_PCR_FORCE_CODE | PHY_PCR_OOBS_CALI_50 |
-			PHY_PCR_OOBS_VCM_08 | PHY_PCR_OOBS_SEN_90 |
-			PHY_PCR_RSSI_EN);
+
+	err = rtsx_pci_write_phy_register(pcr, 0x00, 0xBA43);
+	if (err < 0)
+		return err;
+	err = rtsx_pci_write_phy_register(pcr, 0x03, 0xC152);
 	if (err < 0)
 		return err;
-	err = rtsx_pci_write_phy_register(pcr, PHY_RCR2,
-			PHY_RCR2_EMPHASE_EN | PHY_RCR2_NADJR |
-			PHY_RCR2_CDR_CP_10 | PHY_RCR2_CDR_SR_2 |
-			PHY_RCR2_FREQSEL_12 | PHY_RCR2_CPADJEN |
-			PHY_RCR2_CDR_SC_8 | PHY_RCR2_CALIB_LATE);
+	err = rtsx_pci_write_phy_register(pcr, 0x1E, 0x78EB);
 	if (err < 0)
 		return err;
-	err = rtsx_pci_write_phy_register(pcr, PHY_FLD4,
-			PHY_FLD4_FLDEN_SEL | PHY_FLD4_REQ_REF |
-			PHY_FLD4_RXAMP_OFF | PHY_FLD4_REQ_ADDA |
-			PHY_FLD4_BER_COUNT | PHY_FLD4_BER_TIMER |
-			PHY_FLD4_BER_CHK_EN);
+	err = rtsx_pci_write_phy_register(pcr, 0x05, 0x4600);
 	if (err < 0)
 		return err;
-	err = rtsx_pci_write_phy_register(pcr, PHY_RDR, PHY_RDR_RXDSEL_1_9);
+	err = rtsx_pci_write_phy_register(pcr, 0x02, 0x041F);
 	if (err < 0)
 		return err;
-	err = rtsx_pci_write_phy_register(pcr, PHY_RCR1,
-			PHY_RCR1_ADP_TIME | PHY_RCR1_VCO_COARSE);
+	err = rtsx_pci_write_phy_register(pcr, 0x1D, 0x0824);
 	if (err < 0)
 		return err;
-	err = rtsx_pci_write_phy_register(pcr, PHY_FLD3,
-			PHY_FLD3_TIMER_4 | PHY_FLD3_TIMER_6 |
-			PHY_FLD3_RXDELINK);
+	err = rtsx_pci_write_phy_register(pcr, 0x08, 0x4FE4);
 	if (err < 0)
 		return err;
-	return rtsx_pci_write_phy_register(pcr, PHY_TUNE,
-			PHY_TUNE_TUNEREF_1_0 | PHY_TUNE_VBGSEL_1252 |
-			PHY_TUNE_SDBUS_33 | PHY_TUNE_TUNED18 |
-			PHY_TUNE_TUNED12);
+
+	return 0;
 }
 
 static int rts5249_turn_on_led(struct rtsx_pcr *pcr)
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 07/10] mfd: rtsx: remove LCTLR defination
  2015-01-15 11:18 [PATCH 00/10] mfd: rtsx: add support for new rts524A and rts525A micky_ching
                   ` (5 preceding siblings ...)
  2015-01-15 11:19 ` [PATCH 06/10] mfd: rtsx: update phy register micky_ching
@ 2015-01-15 11:19 ` micky_ching
  2015-01-18 12:28   ` Lee Jones
  2015-01-15 11:19 ` [PATCH 08/10] mfd: rtsx: add support for rts524A micky_ching
                   ` (2 subsequent siblings)
  9 siblings, 1 reply; 36+ messages in thread
From: micky_ching @ 2015-01-15 11:19 UTC (permalink / raw)
  To: sameo, lee.jones
  Cc: devel, linux-kernel, gregkh, rogerable, wei_wang, Micky Ching

From: Micky Ching <micky_ching@realsil.com.cn>

To enable/disable ASPM we should find LINK CONTROL register
in PCI config space. All old chip use 0x80 address, but new
chip may use another address, so we using pci_find_capability()
to get LINK CONTROL address.

rtsx_gops.c was removed, we consider to put some common operations
to this file, but the actual thing is, only a group of chips
are in common ops1, and another group of chips in common ops2,
it is hard to decide put which ops into generic ops file.

Signed-off-by: Micky Ching <micky_ching@realsil.com.cn>
---
 drivers/mfd/Makefile         |  2 +-
 drivers/mfd/rts5227.c        |  2 +-
 drivers/mfd/rts5249.c        |  3 +--
 drivers/mfd/rtsx_gops.c      | 37 -------------------------------------
 drivers/mfd/rtsx_pcr.c       | 25 ++++++++++++++++++++-----
 include/linux/mfd/rtsx_pci.h |  9 ---------
 6 files changed, 23 insertions(+), 55 deletions(-)
 delete mode 100644 drivers/mfd/rtsx_gops.c

diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 53467e2..2cd7e74 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -13,7 +13,7 @@ obj-$(CONFIG_MFD_CROS_EC)	+= cros_ec.o
 obj-$(CONFIG_MFD_CROS_EC_I2C)	+= cros_ec_i2c.o
 obj-$(CONFIG_MFD_CROS_EC_SPI)	+= cros_ec_spi.o
 
-rtsx_pci-objs			:= rtsx_pcr.o rtsx_gops.o rts5209.o rts5229.o rtl8411.o rts5227.o rts5249.o
+rtsx_pci-objs			:= rtsx_pcr.o rts5209.o rts5229.o rtl8411.o rts5227.o rts5249.o
 obj-$(CONFIG_MFD_RTSX_PCI)	+= rtsx_pci.o
 obj-$(CONFIG_MFD_RTSX_USB)	+= rtsx_usb.o
 
diff --git a/drivers/mfd/rts5227.c b/drivers/mfd/rts5227.c
index 1f387d4..0c02831 100644
--- a/drivers/mfd/rts5227.c
+++ b/drivers/mfd/rts5227.c
@@ -130,7 +130,7 @@ static int rts5227_optimize_phy(struct rtsx_pcr *pcr)
 {
 	int err;
 
-	err = rtsx_gops_pm_reset(pcr);
+	err = rtsx_pci_write_register(pcr, PM_CTRL3, D3_DELINK_MODE_EN, 0x00);
 	if (err < 0)
 		return err;
 
diff --git a/drivers/mfd/rts5249.c b/drivers/mfd/rts5249.c
index 00208d1..5eb9819 100644
--- a/drivers/mfd/rts5249.c
+++ b/drivers/mfd/rts5249.c
@@ -119,7 +119,6 @@ static int rts5249_extra_init_hw(struct rtsx_pcr *pcr)
 		rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PETXCFG, 0xB0, 0xB0);
 	else
 		rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PETXCFG, 0xB0, 0x80);
-	rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PM_CTRL3, 0x10, 0x00);
 
 	return rtsx_pci_send_cmd(pcr, 100);
 }
@@ -128,7 +127,7 @@ static int rts5249_optimize_phy(struct rtsx_pcr *pcr)
 {
 	int err;
 
-	err = rtsx_gops_pm_reset(pcr);
+	err = rtsx_pci_write_register(pcr, PM_CTRL3, D3_DELINK_MODE_EN, 0x00);
 	if (err < 0)
 		return err;
 
diff --git a/drivers/mfd/rtsx_gops.c b/drivers/mfd/rtsx_gops.c
deleted file mode 100644
index b1a98c6..0000000
--- a/drivers/mfd/rtsx_gops.c
+++ /dev/null
@@ -1,37 +0,0 @@
-/* Driver for Realtek PCI-Express card reader
- *
- * Copyright(c) 2009-2013 Realtek Semiconductor Corp. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2, or (at your option) any
- * later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, see <http://www.gnu.org/licenses/>.
- *
- * Author:
- *   Micky Ching <micky_ching@realsil.com.cn>
- */
-
-#include <linux/mfd/rtsx_pci.h>
-#include "rtsx_pcr.h"
-
-int rtsx_gops_pm_reset(struct rtsx_pcr *pcr)
-{
-	int err;
-
-	/* init aspm */
-	rtsx_pci_write_register(pcr, ASPM_FORCE_CTL, 0xFF, 0x00);
-	err = rtsx_pci_update_cfg_byte(pcr, LCTLR, ~LCTLR_ASPM_CTL_MASK, 0x00);
-	if (err < 0)
-		return err;
-
-	/* reset PM_CTRL3 before send buffer cmd */
-	return rtsx_pci_write_register(pcr, PM_CTRL3, D3_DELINK_MODE_EN, 0x00);
-}
diff --git a/drivers/mfd/rtsx_pcr.c b/drivers/mfd/rtsx_pcr.c
index 92f5a41..3065edc 100644
--- a/drivers/mfd/rtsx_pcr.c
+++ b/drivers/mfd/rtsx_pcr.c
@@ -63,6 +63,20 @@ static const struct pci_device_id rtsx_pci_ids[] = {
 
 MODULE_DEVICE_TABLE(pci, rtsx_pci_ids);
 
+static inline void rtsx_pci_enable_aspm(struct rtsx_pcr *pcr)
+{
+	int exp = pci_find_capability(pcr->pci, PCI_CAP_ID_EXP);
+
+	rtsx_pci_update_cfg_byte(pcr, exp + PCI_EXP_LNKCTL, 0xFC, pcr->aspm_en);
+}
+
+static inline void rtsx_pci_disable_aspm(struct rtsx_pcr *pcr)
+{
+	int exp = pci_find_capability(pcr->pci, PCI_CAP_ID_EXP);
+
+	rtsx_pci_update_cfg_byte(pcr, exp + PCI_EXP_LNKCTL, 0xFC, 0);
+}
+
 void rtsx_pci_start_run(struct rtsx_pcr *pcr)
 {
 	/* If pci device removed, don't queue idle work any more */
@@ -75,7 +89,8 @@ void rtsx_pci_start_run(struct rtsx_pcr *pcr)
 			pcr->ops->enable_auto_blink(pcr);
 
 		if (pcr->aspm_en)
-			rtsx_pci_write_config_byte(pcr, LCTLR, 0);
+			rtsx_pci_disable_aspm(pcr);
+
 	}
 
 	mod_delayed_work(system_wq, &pcr->idle_work, msecs_to_jiffies(200));
@@ -954,7 +969,7 @@ static void rtsx_pci_idle_work(struct work_struct *work)
 		pcr->ops->turn_off_led(pcr);
 
 	if (pcr->aspm_en)
-		rtsx_pci_write_config_byte(pcr, LCTLR, pcr->aspm_en);
+		rtsx_pci_enable_aspm(pcr);
 
 	mutex_unlock(&pcr->pcr_mutex);
 }
@@ -979,6 +994,7 @@ static void rtsx_pci_power_off(struct rtsx_pcr *pcr, u8 pm_state)
 static int rtsx_pci_init_hw(struct rtsx_pcr *pcr)
 {
 	int err;
+	int exp = pci_find_capability(pcr->pci, PCI_CAP_ID_EXP);
 
 	rtsx_pci_writel(pcr, RTSX_HCBAR, pcr->host_cmds_addr);
 
@@ -992,6 +1008,7 @@ static int rtsx_pci_init_hw(struct rtsx_pcr *pcr)
 	/* Wait SSC power stable */
 	udelay(200);
 
+	rtsx_pci_disable_aspm(pcr);
 	if (pcr->ops->optimize_phy) {
 		err = pcr->ops->optimize_phy(pcr);
 		if (err < 0)
@@ -1040,10 +1057,8 @@ static int rtsx_pci_init_hw(struct rtsx_pcr *pcr)
 	if (err < 0)
 		return err;
 
-	rtsx_pci_write_config_byte(pcr, LCTLR, 0);
-
 	/* Enable clk_request_n to enable clock power management */
-	rtsx_pci_write_config_byte(pcr, 0x81, 1);
+	rtsx_pci_write_config_byte(pcr, exp + PCI_EXP_LNKCTL + 1, 1);
 	/* Enter L1 when host tx idle */
 	rtsx_pci_write_config_byte(pcr, 0x70F, 0x5B);
 
diff --git a/include/linux/mfd/rtsx_pci.h b/include/linux/mfd/rtsx_pci.h
index 80baa10..f7cebdb 100644
--- a/include/linux/mfd/rtsx_pci.h
+++ b/include/linux/mfd/rtsx_pci.h
@@ -662,15 +662,6 @@
 #define PHY_FLD4			0x1E
 #define PHY_DUM_REG			0x1F
 
-#define LCTLR				0x80
-#define   LCTLR_EXT_SYNC		0x80
-#define   LCTLR_COMMON_CLOCK_CFG	0x40
-#define   LCTLR_RETRAIN_LINK		0x20
-#define   LCTLR_LINK_DISABLE		0x10
-#define   LCTLR_RCB			0x08
-#define   LCTLR_RESERVED		0x04
-#define   LCTLR_ASPM_CTL_MASK		0x03
-
 #define PCR_SETTING_REG1		0x724
 #define PCR_SETTING_REG2		0x814
 #define PCR_SETTING_REG3		0x747
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 08/10] mfd: rtsx: add support for rts524A
  2015-01-15 11:18 [PATCH 00/10] mfd: rtsx: add support for new rts524A and rts525A micky_ching
                   ` (6 preceding siblings ...)
  2015-01-15 11:19 ` [PATCH 07/10] mfd: rtsx: remove LCTLR defination micky_ching
@ 2015-01-15 11:19 ` micky_ching
  2015-01-18 12:20   ` Lee Jones
  2015-01-15 11:19 ` [PATCH 09/10] mfd: rtsx: add support for rts525A micky_ching
  2015-01-15 11:19 ` [PATCH 10/10] mfd: rtsx: using pcr_dbg replace dev_dbg micky_ching
  9 siblings, 1 reply; 36+ messages in thread
From: micky_ching @ 2015-01-15 11:19 UTC (permalink / raw)
  To: sameo, lee.jones
  Cc: devel, linux-kernel, gregkh, rogerable, wei_wang, Micky Ching

From: Micky Ching <micky_ching@realsil.com.cn>

add support for new chip rts524A.

Signed-off-by: Micky Ching <micky_ching@realsil.com.cn>
---
 drivers/mfd/rts5249.c        | 112 +++++++++++++++++++++++++++++++++++++++----
 drivers/mfd/rtsx_pcr.c       |   5 ++
 drivers/mfd/rtsx_pcr.h       |   4 ++
 include/linux/mfd/rtsx_pci.h |  87 ++++++++++++++++++++++++++++++++-
 4 files changed, 198 insertions(+), 10 deletions(-)

diff --git a/drivers/mfd/rts5249.c b/drivers/mfd/rts5249.c
index 5eb9819..1ce03a6 100644
--- a/drivers/mfd/rts5249.c
+++ b/drivers/mfd/rts5249.c
@@ -72,8 +72,10 @@ static void rts5249_fetch_vendor_settings(struct rtsx_pcr *pcr)
 	rtsx_pci_read_config_dword(pcr, PCR_SETTING_REG1, &reg);
 	dev_dbg(&(pcr->pci->dev), "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG1, reg);
 
-	if (!rtsx_vendor_setting_valid(reg))
+	if (!rtsx_vendor_setting_valid(reg)) {
+		pcr_dbg(pcr, "skip fetch vendor setting\n");
 		return;
+	}
 
 	pcr->aspm_en = rtsx_reg_to_aspm(reg);
 	pcr->sd30_drive_sel_1v8 = rtsx_reg_to_sd30_drive_sel_1v8(reg);
@@ -94,8 +96,14 @@ static void rts5249_force_power_down(struct rtsx_pcr *pcr, u8 pm_state)
 	rtsx_pci_write_register(pcr, AUTOLOAD_CFG_BASE + 2, 0xFF, 0);
 	rtsx_pci_write_register(pcr, AUTOLOAD_CFG_BASE + 3, 0x01, 0);
 
-	if (pm_state == HOST_ENTER_S3)
-		rtsx_pci_write_register(pcr, PM_CTRL3, 0x10, 0x10);
+	if (pm_state == HOST_ENTER_S3) {
+		if (PCI_PID(pcr) == 0x524A)
+			rtsx_pci_write_register(pcr, RTS524A_PM_CTRL3,
+				D3_DELINK_MODE_EN, D3_DELINK_MODE_EN);
+		else if (PCI_PID(pcr) == 0x5249)
+			rtsx_pci_write_register(pcr, PM_CTRL3,
+				D3_DELINK_MODE_EN, D3_DELINK_MODE_EN);
+	}
 
 	rtsx_pci_write_register(pcr, FPDCTL, 0x03, 0x03);
 }
@@ -104,6 +112,8 @@ static int rts5249_extra_init_hw(struct rtsx_pcr *pcr)
 {
 	rtsx_pci_init_cmd(pcr);
 
+	/* Rest L1SUB Config */
+	rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, L1SUB_CONFIG3, 0xFF, 0x00);
 	/* Configure GPIO as output */
 	rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, GPIO_CTL, 0x02, 0x02);
 	/* Reset ASPM state to default value */
@@ -228,14 +238,20 @@ static int rts5249_switch_output_voltage(struct rtsx_pcr *pcr, u8 voltage)
 	int err;
 
 	if (voltage == OUTPUT_3V3) {
-		err = rtsx_pci_write_phy_register(pcr, PHY_TUNE, 0x4FC0 | 0x24);
+		err = rtsx_pci_update_phy(pcr, PHY_TUNE, 0xFC3F, 0x03C0);
 		if (err < 0)
 			return err;
 	} else if (voltage == OUTPUT_1V8) {
-		err = rtsx_pci_write_phy_register(pcr, PHY_BACR, 0x3C02);
-		if (err < 0)
-			return err;
-		err = rtsx_pci_write_phy_register(pcr, PHY_TUNE, 0x4C40 | 0x24);
+		u16 append = 0x0100;
+
+		if (PCI_PID(pcr) == 0x5249) {
+			err = rtsx_pci_update_phy(pcr, PHY_BACR, 0xFFF3, 0);
+			if (err < 0)
+				return err;
+			append = 0x0080;
+		}
+
+		err = rtsx_pci_update_phy(pcr, PHY_TUNE, 0xFC3F, append);
 		if (err < 0)
 			return err;
 	} else {
@@ -334,3 +350,83 @@ void rts5249_init_params(struct rtsx_pcr *pcr)
 	pcr->ms_pull_ctl_enable_tbl = rts5249_ms_pull_ctl_enable_tbl;
 	pcr->ms_pull_ctl_disable_tbl = rts5249_ms_pull_ctl_disable_tbl;
 }
+
+static inline int rts524a_write_phy(struct rtsx_pcr *pcr, u8 addr, u16 val)
+{
+	addr = addr & 0x80 ? (addr & 0x7F) | 0x40 : addr;
+	return rtsx_pci_write_phy_register(pcr, addr, val);
+}
+
+static int rts524a_optimize_phy(struct rtsx_pcr *pcr)
+{
+	int err;
+
+	err = rtsx_pci_write_register(pcr, RTS524A_PM_CTRL3,
+		D3_DELINK_MODE_EN, 0x00);
+	if (err < 0)
+		return err;
+
+	rts524a_write_phy(pcr, 0x00, 0xBA42);
+	rts524a_write_phy(pcr, 0x03, 0x2748);
+
+	if (is_version(pcr, 0x524A, IC_VER_A)) {
+		rts524a_write_phy(pcr, 0x03, 0x2748);
+		rts524a_write_phy(pcr, 0x02, 0x0A1F);
+		rts524a_write_phy(pcr, 0x1A, 0x2546);
+		rts524a_write_phy(pcr, 0x1D, 0x0004);
+		rts524a_write_phy(pcr, 0x1E, 0x5C7F);
+	}
+
+	rts524a_write_phy(pcr, 0x08, 0x57E4);
+
+	return 0;
+}
+
+static int rts524a_extra_init_hw(struct rtsx_pcr *pcr)
+{
+	rts5249_extra_init_hw(pcr);
+
+	rtsx_pci_write_register(pcr, FUNC_FORCE_CTL, 0x02, 0x02);
+	rtsx_pci_write_register(pcr, PM_EVENT_DEBUG, PME_DEBUG_0, PME_DEBUG_0);
+	rtsx_pci_write_register(pcr, LDO_VCC_CFG1, LDO_VCC_LMT_EN,
+		LDO_VCC_LMT_EN);
+	rtsx_pci_write_register(pcr, PCLK_CTL, PCLK_MODE_SEL, PCLK_MODE_SEL);
+	if (is_version(pcr, 0x524A, IC_VER_A)) {
+		rtsx_pci_write_register(pcr, LDO_DV18_CFG,
+			LDO_DV18_SR_MASK, LDO_DV18_SR_DF);
+		rtsx_pci_write_register(pcr, LDO_VCC_CFG1,
+			LDO_VCC_REF_TUNE_MASK, LDO_VCC_REF_1V2);
+		rtsx_pci_write_register(pcr, LDO_VIO_CFG,
+			LDO_VIO_REF_TUNE_MASK, LDO_VIO_REF_1V2);
+		rtsx_pci_write_register(pcr, LDO_VIO_CFG,
+			LDO_VIO_SR_MASK, LDO_VIO_SR_DF);
+		rtsx_pci_write_register(pcr, LDO_DV12S_CFG,
+			LDO_REF12_TUNE_MASK, LDO_REF12_TUNE_DF);
+		rtsx_pci_write_register(pcr, SD40_LDO_CTL1,
+			SD40_VIO_TUNE_MASK, SD40_VIO_TUNE_1V7);
+	}
+
+	return 0;
+}
+
+static const struct pcr_ops rts524a_pcr_ops = {
+	.fetch_vendor_settings = rts5249_fetch_vendor_settings,
+	.extra_init_hw = rts524a_extra_init_hw,
+	.optimize_phy = rts524a_optimize_phy,
+	.turn_on_led = rts5249_turn_on_led,
+	.turn_off_led = rts5249_turn_off_led,
+	.enable_auto_blink = rts5249_enable_auto_blink,
+	.disable_auto_blink = rts5249_disable_auto_blink,
+	.card_power_on = rts5249_card_power_on,
+	.card_power_off = rts5249_card_power_off,
+	.switch_output_voltage = rts5249_switch_output_voltage,
+	.force_power_down = rts5249_force_power_down,
+};
+
+void rts524a_init_params(struct rtsx_pcr *pcr)
+{
+	rts5249_init_params(pcr);
+
+	pcr->ops = &rts524a_pcr_ops;
+}
+
diff --git a/drivers/mfd/rtsx_pcr.c b/drivers/mfd/rtsx_pcr.c
index 3065edc..17334ba 100644
--- a/drivers/mfd/rtsx_pcr.c
+++ b/drivers/mfd/rtsx_pcr.c
@@ -58,6 +58,7 @@ static const struct pci_device_id rtsx_pci_ids[] = {
 	{ PCI_DEVICE(0x10EC, 0x5249), PCI_CLASS_OTHERS << 16, 0xFF0000 },
 	{ PCI_DEVICE(0x10EC, 0x5287), PCI_CLASS_OTHERS << 16, 0xFF0000 },
 	{ PCI_DEVICE(0x10EC, 0x5286), PCI_CLASS_OTHERS << 16, 0xFF0000 },
+	{ PCI_DEVICE(0x10EC, 0x524A), PCI_CLASS_OTHERS << 16, 0xFF0000 },
 	{ 0, }
 };
 
@@ -1108,6 +1109,10 @@ static int rtsx_pci_init_chip(struct rtsx_pcr *pcr)
 		rts5249_init_params(pcr);
 		break;
 
+	case 0x524A:
+		rts524a_init_params(pcr);
+		break;
+
 	case 0x5287:
 		rtl8411b_init_params(pcr);
 		break;
diff --git a/drivers/mfd/rtsx_pcr.h b/drivers/mfd/rtsx_pcr.h
index fe2bbb6..0535265 100644
--- a/drivers/mfd/rtsx_pcr.h
+++ b/drivers/mfd/rtsx_pcr.h
@@ -27,12 +27,16 @@
 #define MIN_DIV_N_PCR		80
 #define MAX_DIV_N_PCR		208
 
+#define RTS524A_PME_FORCE_CTL		0xFF78
+#define RTS524A_PM_CTRL3		0xFF7E
+
 void rts5209_init_params(struct rtsx_pcr *pcr);
 void rts5229_init_params(struct rtsx_pcr *pcr);
 void rtl8411_init_params(struct rtsx_pcr *pcr);
 void rtl8402_init_params(struct rtsx_pcr *pcr);
 void rts5227_init_params(struct rtsx_pcr *pcr);
 void rts5249_init_params(struct rtsx_pcr *pcr);
+void rts524a_init_params(struct rtsx_pcr *pcr);
 void rtl8411b_init_params(struct rtsx_pcr *pcr);
 
 static inline u8 map_sd_drive(int idx)
diff --git a/include/linux/mfd/rtsx_pci.h b/include/linux/mfd/rtsx_pci.h
index f7cebdb..ab6da29 100644
--- a/include/linux/mfd/rtsx_pci.h
+++ b/include/linux/mfd/rtsx_pci.h
@@ -577,8 +577,13 @@
 
 #define CDRESUMECTL			0xFE52
 #define WAKE_SEL_CTL			0xFE54
+#define PCLK_CTL			0xFE55
+#define   PCLK_MODE_SEL			0x20
 #define PME_FORCE_CTL			0xFE56
+
 #define ASPM_FORCE_CTL			0xFE57
+#define   FORCE_ASPM_CTL0		0x10
+#define   FORCE_ASPM_VAL_MASK		0x03
 #define PM_CLK_FORCE_CTL		0xFE58
 #define FUNC_FORCE_CTL			0xFE59
 #define PERST_GLITCH_WIDTH		0xFE5C
@@ -590,7 +595,8 @@
 #define   HOST_ENTER_S3			2
 
 #define SDIO_CFG			0xFE70
-
+#define PM_EVENT_DEBUG			0xFE71
+#define   PME_DEBUG_0			0x08
 #define NFTS_TX_CTRL			0xFE72
 
 #define PWR_GATE_CTRL			0xFE75
@@ -602,12 +608,19 @@
 #define PWD_SUSPEND_EN			0xFE76
 #define LDO_PWR_SEL			0xFE78
 
+#define L1SUB_CONFIG1			0xFE8D
+#define L1SUB_CONFIG2			0xFE8E
+#define   L1SUB_AUTO_CFG		0x02
+#define L1SUB_CONFIG3			0xFE8F
+
 #define DUMMY_REG_RESET_0		0xFE90
 
 #define AUTOLOAD_CFG_BASE		0xFF00
 #define PETXCFG				0xFF03
 
 #define PM_CTRL1			0xFF44
+#define   CD_RESUME_EN_MASK		0xF0
+
 #define PM_CTRL2			0xFF45
 #define PM_CTRL3			0xFF46
 #define   SDIO_SEND_PME_EN		0x80
@@ -628,6 +641,61 @@
 #define IMAGE_FLAG_ADDR0		0xCE80
 #define IMAGE_FLAG_ADDR1		0xCE81
 
+#define RREF_CFG			0xFF6C
+#define   RREF_VBGSEL_MASK		0x38
+#define   RREF_VBGSEL_1V25		0x28
+
+#define OOBS_CONFIG			0xFF6E
+#define   OOBS_AUTOK_DIS		0x80
+#define   OOBS_VAL_MASK			0x1F
+
+#define LDO_DV18_CFG			0xFF70
+#define   LDO_DV18_SR_MASK		0xC0
+#define   LDO_DV18_SR_DF		0x40
+
+#define LDO_CONFIG2			0xFF71
+#define   LDO_D3318_MASK		0x07
+#define   LDO_D3318_33V			0x07
+#define   LDO_D3318_18V			0x02
+
+#define LDO_VCC_CFG0			0xFF72
+#define   LDO_VCC_LMTVTH_MASK		0x30
+#define   LDO_VCC_LMTVTH_2A		0x10
+
+#define LDO_VCC_CFG1			0xFF73
+#define   LDO_VCC_REF_TUNE_MASK		0x30
+#define   LDO_VCC_REF_1V2		0x20
+#define   LDO_VCC_TUNE_MASK		0x07
+#define   LDO_VCC_1V8			0x04
+#define   LDO_VCC_3V3			0x07
+#define   LDO_VCC_LMT_EN		0x08
+
+#define LDO_VIO_CFG			0xFF75
+#define   LDO_VIO_SR_MASK		0xC0
+#define   LDO_VIO_SR_DF			0x40
+#define   LDO_VIO_REF_TUNE_MASK		0x30
+#define   LDO_VIO_REF_1V2		0x20
+#define   LDO_VIO_TUNE_MASK		0x07
+#define   LDO_VIO_1V7			0x03
+#define   LDO_VIO_1V8			0x04
+#define   LDO_VIO_3V3			0x07
+
+#define LDO_DV12S_CFG			0xFF76
+#define   LDO_REF12_TUNE_MASK		0x18
+#define   LDO_REF12_TUNE_DF		0x10
+#define   LDO_D12_TUNE_MASK		0x07
+#define   LDO_D12_TUNE_DF		0x04
+
+#define LDO_AV12S_CFG			0xFF77
+#define   LDO_AV12S_TUNE_MASK		0x07
+#define   LDO_AV12S_TUNE_DF		0x04
+
+#define SD40_LDO_CTL1			0xFE7D
+#define   SD40_VIO_TUNE_MASK		0x70
+#define   SD40_VIO_TUNE_1V7		0x30
+#define   SD_VIO_LDO_1V8		0x40
+#define   SD_VIO_LDO_3V3		0x70
+
 /* Phy register */
 #define PHY_PCR				0x00
 #define PHY_RCR0			0x01
@@ -828,7 +896,8 @@ struct rtsx_pcr {
 #define CHK_PCI_PID(pcr, pid)		((pcr)->pci->device == (pid))
 #define PCI_VID(pcr)			((pcr)->pci->vendor)
 #define PCI_PID(pcr)			((pcr)->pci->device)
-
+#define is_version(pcr, pid, ver)				\
+	(CHK_PCI_PID(pcr, pid) && (pcr)->ic_version == (ver))
 #define pcr_dbg(pcr, fmt, arg...)			\
 	dev_dbg(&(pcr)->pci->dev, fmt, ##arg)
 #define SDR104_PHASE(val)		((val) & 0xFF)
@@ -899,4 +968,18 @@ static inline void rtsx_pci_write_be32(struct rtsx_pcr *pcr, u16 reg, u32 val)
 	rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, reg + 3, 0xFF, val);
 }
 
+static inline int rtsx_pci_update_phy(struct rtsx_pcr *pcr, u8 addr,
+	u16 mask, u16 append)
+{
+	int err = 0;
+	u16 val = 0;
+
+	err = rtsx_pci_read_phy_register(pcr, addr, &val);
+	if (err < 0)
+		return err;
+
+	err = rtsx_pci_write_phy_register(pcr, addr, (val & mask) | append);
+	return err;
+}
+
 #endif
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 09/10] mfd: rtsx: add support for rts525A
  2015-01-15 11:18 [PATCH 00/10] mfd: rtsx: add support for new rts524A and rts525A micky_ching
                   ` (7 preceding siblings ...)
  2015-01-15 11:19 ` [PATCH 08/10] mfd: rtsx: add support for rts524A micky_ching
@ 2015-01-15 11:19 ` micky_ching
  2015-01-18 11:13   ` Lee Jones
  2015-01-15 11:19 ` [PATCH 10/10] mfd: rtsx: using pcr_dbg replace dev_dbg micky_ching
  9 siblings, 1 reply; 36+ messages in thread
From: micky_ching @ 2015-01-15 11:19 UTC (permalink / raw)
  To: sameo, lee.jones
  Cc: devel, linux-kernel, gregkh, rogerable, wei_wang, Micky Ching

From: Micky Ching <micky_ching@realsil.com.cn>

add support for new chip rts525A.

Signed-off-by: Micky Ching <micky_ching@realsil.com.cn>
---
 drivers/mfd/rts5249.c  | 93 +++++++++++++++++++++++++++++++++++++++++++++++++-
 drivers/mfd/rtsx_pcr.c | 13 +++++--
 drivers/mfd/rtsx_pcr.h |  1 +
 3 files changed, 103 insertions(+), 4 deletions(-)

diff --git a/drivers/mfd/rts5249.c b/drivers/mfd/rts5249.c
index 1ce03a6..46b6522 100644
--- a/drivers/mfd/rts5249.c
+++ b/drivers/mfd/rts5249.c
@@ -97,7 +97,7 @@ static void rts5249_force_power_down(struct rtsx_pcr *pcr, u8 pm_state)
 	rtsx_pci_write_register(pcr, AUTOLOAD_CFG_BASE + 3, 0x01, 0);
 
 	if (pm_state == HOST_ENTER_S3) {
-		if (PCI_PID(pcr) == 0x524A)
+		if (PCI_PID(pcr) == 0x524A || PCI_PID(pcr) == 0x525A)
 			rtsx_pci_write_register(pcr, RTS524A_PM_CTRL3,
 				D3_DELINK_MODE_EN, D3_DELINK_MODE_EN);
 		else if (PCI_PID(pcr) == 0x5249)
@@ -430,3 +430,94 @@ void rts524a_init_params(struct rtsx_pcr *pcr)
 	pcr->ops = &rts524a_pcr_ops;
 }
 
+static int rts525a_card_power_on(struct rtsx_pcr *pcr, int card)
+{
+	rtsx_pci_write_register(pcr, LDO_VCC_CFG1,
+		LDO_VCC_TUNE_MASK, LDO_VCC_3V3);
+	return rts5249_card_power_on(pcr, card);
+}
+
+static int rts525a_switch_output_voltage(struct rtsx_pcr *pcr, u8 voltage)
+{
+	if (voltage == OUTPUT_3V3) {
+		rtsx_pci_write_register(pcr, LDO_CONFIG2,
+			LDO_D3318_MASK, LDO_D3318_33V);
+		rtsx_pci_write_register(pcr, SD_PAD_CTL, SD_IO_USING_1V8, 0);
+	} else if (voltage == OUTPUT_1V8) {
+		rtsx_pci_write_register(pcr, LDO_CONFIG2,
+			LDO_D3318_MASK, LDO_D3318_18V);
+		rtsx_pci_write_register(pcr, SD_PAD_CTL, SD_IO_USING_1V8,
+			SD_IO_USING_1V8);
+	} else {
+		return -EINVAL;
+	}
+
+	rtsx_pci_init_cmd(pcr);
+	rts5249_fill_driving(pcr, voltage);
+	return rtsx_pci_send_cmd(pcr, 100);
+}
+
+static int rts525a_optimize_phy(struct rtsx_pcr *pcr)
+{
+	int err;
+
+	err = rtsx_pci_write_register(pcr, RTS524A_PM_CTRL3,
+		D3_DELINK_MODE_EN, 0x00);
+	if (err < 0)
+		return err;
+
+	rtsx_pci_write_phy_register(pcr, 0x1D, 0x99FF);
+	rtsx_pci_write_phy_register(pcr, 0x03, 0x2748);
+
+	if (is_version(pcr, 0x525A, IC_VER_A))
+		rtsx_pci_write_phy_register(pcr, 0x19, 0x3902);
+
+	return 0;
+}
+
+static int rts525a_extra_init_hw(struct rtsx_pcr *pcr)
+{
+	rts5249_extra_init_hw(pcr);
+
+	rtsx_pci_write_register(pcr, PCLK_CTL, PCLK_MODE_SEL, PCLK_MODE_SEL);
+	if (is_version(pcr, 0x525A, IC_VER_A)) {
+		rtsx_pci_write_register(pcr, L1SUB_CONFIG2,
+			L1SUB_AUTO_CFG, L1SUB_AUTO_CFG);
+		rtsx_pci_write_register(pcr, RREF_CFG,
+			RREF_VBGSEL_MASK, RREF_VBGSEL_1V25);
+		rtsx_pci_write_register(pcr, LDO_VIO_CFG,
+			LDO_VIO_TUNE_MASK, LDO_VIO_1V7);
+		rtsx_pci_write_register(pcr, LDO_DV12S_CFG,
+			LDO_D12_TUNE_MASK, LDO_D12_TUNE_DF);
+		rtsx_pci_write_register(pcr, LDO_AV12S_CFG,
+			LDO_AV12S_TUNE_MASK, LDO_AV12S_TUNE_DF);
+		rtsx_pci_write_register(pcr, LDO_VCC_CFG0,
+			LDO_VCC_LMTVTH_MASK, LDO_VCC_LMTVTH_2A);
+		rtsx_pci_write_register(pcr, OOBS_CONFIG,
+			OOBS_AUTOK_DIS | OOBS_VAL_MASK, 0x89);
+	}
+
+	return 0;
+}
+
+static const struct pcr_ops rts525a_pcr_ops = {
+	.fetch_vendor_settings = rts5249_fetch_vendor_settings,
+	.extra_init_hw = rts525a_extra_init_hw,
+	.optimize_phy = rts525a_optimize_phy,
+	.turn_on_led = rts5249_turn_on_led,
+	.turn_off_led = rts5249_turn_off_led,
+	.enable_auto_blink = rts5249_enable_auto_blink,
+	.disable_auto_blink = rts5249_disable_auto_blink,
+	.card_power_on = rts525a_card_power_on,
+	.card_power_off = rts5249_card_power_off,
+	.switch_output_voltage = rts525a_switch_output_voltage,
+	.force_power_down = rts5249_force_power_down,
+};
+
+void rts525a_init_params(struct rtsx_pcr *pcr)
+{
+	rts5249_init_params(pcr);
+
+	pcr->ops = &rts525a_pcr_ops;
+}
+
diff --git a/drivers/mfd/rtsx_pcr.c b/drivers/mfd/rtsx_pcr.c
index 17334ba..33aa30b 100644
--- a/drivers/mfd/rtsx_pcr.c
+++ b/drivers/mfd/rtsx_pcr.c
@@ -59,6 +59,7 @@ static const struct pci_device_id rtsx_pci_ids[] = {
 	{ PCI_DEVICE(0x10EC, 0x5287), PCI_CLASS_OTHERS << 16, 0xFF0000 },
 	{ PCI_DEVICE(0x10EC, 0x5286), PCI_CLASS_OTHERS << 16, 0xFF0000 },
 	{ PCI_DEVICE(0x10EC, 0x524A), PCI_CLASS_OTHERS << 16, 0xFF0000 },
+	{ PCI_DEVICE(0x10EC, 0x525A), PCI_CLASS_OTHERS << 16, 0xFF0000 },
 	{ 0, }
 };
 
@@ -1113,6 +1114,10 @@ static int rtsx_pci_init_chip(struct rtsx_pcr *pcr)
 		rts524a_init_params(pcr);
 		break;
 
+	case 0x525A:
+		rts525a_init_params(pcr);
+		break;
+
 	case 0x5287:
 		rtl8411b_init_params(pcr);
 		break;
@@ -1158,7 +1163,7 @@ static int rtsx_pci_probe(struct pci_dev *pcidev,
 	struct rtsx_pcr *pcr;
 	struct pcr_handle *handle;
 	u32 base, len;
-	int ret, i;
+	int ret, i, bar = 0;
 
 	dev_dbg(&(pcidev->dev),
 		": Realtek PCI-E Card Reader found at %s [%04x:%04x] (rev %x)\n",
@@ -1203,8 +1208,10 @@ static int rtsx_pci_probe(struct pci_dev *pcidev,
 	pcr->pci = pcidev;
 	dev_set_drvdata(&pcidev->dev, handle);
 
-	len = pci_resource_len(pcidev, 0);
-	base = pci_resource_start(pcidev, 0);
+	if (PCI_PID(pcr) == 0x525A)
+		bar = 1;
+	len = pci_resource_len(pcidev, bar);
+	base = pci_resource_start(pcidev, bar);
 	pcr->remap_addr = ioremap_nocache(base, len);
 	if (!pcr->remap_addr) {
 		ret = -ENOMEM;
diff --git a/drivers/mfd/rtsx_pcr.h b/drivers/mfd/rtsx_pcr.h
index 0535265..4c00544 100644
--- a/drivers/mfd/rtsx_pcr.h
+++ b/drivers/mfd/rtsx_pcr.h
@@ -37,6 +37,7 @@ void rtl8402_init_params(struct rtsx_pcr *pcr);
 void rts5227_init_params(struct rtsx_pcr *pcr);
 void rts5249_init_params(struct rtsx_pcr *pcr);
 void rts524a_init_params(struct rtsx_pcr *pcr);
+void rts525a_init_params(struct rtsx_pcr *pcr);
 void rtl8411b_init_params(struct rtsx_pcr *pcr);
 
 static inline u8 map_sd_drive(int idx)
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 10/10] mfd: rtsx: using pcr_dbg replace dev_dbg
  2015-01-15 11:18 [PATCH 00/10] mfd: rtsx: add support for new rts524A and rts525A micky_ching
                   ` (8 preceding siblings ...)
  2015-01-15 11:19 ` [PATCH 09/10] mfd: rtsx: add support for rts525A micky_ching
@ 2015-01-15 11:19 ` micky_ching
  2015-01-18 10:43   ` Lee Jones
  9 siblings, 1 reply; 36+ messages in thread
From: micky_ching @ 2015-01-15 11:19 UTC (permalink / raw)
  To: sameo, lee.jones
  Cc: devel, linux-kernel, gregkh, rogerable, wei_wang, Micky Ching

From: Micky Ching <micky_ching@realsil.com.cn>

pcr_dbg is a wrapper of dev_dbg, which can save some code,
and help to enable/disable debug message static.

Signed-off-by: Micky Ching <micky_ching@realsil.com.cn>
---
 drivers/mfd/rtl8411.c  | 11 +++++------
 drivers/mfd/rts5209.c  |  4 ++--
 drivers/mfd/rts5227.c  |  4 ++--
 drivers/mfd/rts5229.c  |  4 ++--
 drivers/mfd/rts5249.c  |  4 ++--
 drivers/mfd/rtsx_pcr.c | 49 ++++++++++++++++++++++---------------------------
 6 files changed, 35 insertions(+), 41 deletions(-)

diff --git a/drivers/mfd/rtl8411.c b/drivers/mfd/rtl8411.c
index fdd34c8..b3ae659 100644
--- a/drivers/mfd/rtl8411.c
+++ b/drivers/mfd/rtl8411.c
@@ -53,7 +53,7 @@ static void rtl8411_fetch_vendor_settings(struct rtsx_pcr *pcr)
 	u8 reg3 = 0;
 
 	rtsx_pci_read_config_dword(pcr, PCR_SETTING_REG1, &reg1);
-	dev_dbg(&(pcr->pci->dev), "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG1, reg1);
+	pcr_dbg(pcr, "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG1, reg1);
 
 	if (!rtsx_vendor_setting_valid(reg1))
 		return;
@@ -65,7 +65,7 @@ static void rtl8411_fetch_vendor_settings(struct rtsx_pcr *pcr)
 	pcr->card_drive_sel |= rtsx_reg_to_card_drive_sel(reg1);
 
 	rtsx_pci_read_config_byte(pcr, PCR_SETTING_REG3, &reg3);
-	dev_dbg(&(pcr->pci->dev), "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG3, reg3);
+	pcr_dbg(pcr, "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG3, reg3);
 	pcr->sd30_drive_sel_3v3 = rtl8411_reg_to_sd30_drive_sel_3v3(reg3);
 }
 
@@ -74,7 +74,7 @@ static void rtl8411b_fetch_vendor_settings(struct rtsx_pcr *pcr)
 	u32 reg = 0;
 
 	rtsx_pci_read_config_dword(pcr, PCR_SETTING_REG1, &reg);
-	dev_dbg(&(pcr->pci->dev), "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG1, reg);
+	pcr_dbg(pcr, "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG1, reg);
 
 	if (!rtsx_vendor_setting_valid(reg))
 		return;
@@ -260,9 +260,8 @@ static unsigned int rtl8411_cd_deglitch(struct rtsx_pcr *pcr)
 		rtsx_pci_write_register(pcr, CARD_PWR_CTL,
 				BPP_POWER_MASK, BPP_POWER_OFF);
 
-		dev_dbg(&(pcr->pci->dev),
-				"After CD deglitch, card_exist = 0x%x\n",
-				card_exist);
+		pcr_dbg(pcr, "After CD deglitch, card_exist = 0x%x\n",
+			card_exist);
 	}
 
 	if (card_exist & MS_EXIST) {
diff --git a/drivers/mfd/rts5209.c b/drivers/mfd/rts5209.c
index cb04174..373e253 100644
--- a/drivers/mfd/rts5209.c
+++ b/drivers/mfd/rts5209.c
@@ -38,7 +38,7 @@ static void rts5209_fetch_vendor_settings(struct rtsx_pcr *pcr)
 	u32 reg;
 
 	rtsx_pci_read_config_dword(pcr, PCR_SETTING_REG1, &reg);
-	dev_dbg(&(pcr->pci->dev), "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG1, reg);
+	pcr_dbg(pcr, "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG1, reg);
 
 	if (rts5209_vendor_setting1_valid(reg)) {
 		if (rts5209_reg_check_ms_pmos(reg))
@@ -47,7 +47,7 @@ static void rts5209_fetch_vendor_settings(struct rtsx_pcr *pcr)
 	}
 
 	rtsx_pci_read_config_dword(pcr, PCR_SETTING_REG2, &reg);
-	dev_dbg(&(pcr->pci->dev), "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG2, reg);
+	pcr_dbg(pcr, "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG2, reg);
 
 	if (rts5209_vendor_setting2_valid(reg)) {
 		pcr->sd30_drive_sel_1v8 =
diff --git a/drivers/mfd/rts5227.c b/drivers/mfd/rts5227.c
index 0c02831..ce012d7 100644
--- a/drivers/mfd/rts5227.c
+++ b/drivers/mfd/rts5227.c
@@ -63,7 +63,7 @@ static void rts5227_fetch_vendor_settings(struct rtsx_pcr *pcr)
 	u32 reg;
 
 	rtsx_pci_read_config_dword(pcr, PCR_SETTING_REG1, &reg);
-	dev_dbg(&(pcr->pci->dev), "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG1, reg);
+	pcr_dbg(pcr, "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG1, reg);
 
 	if (!rtsx_vendor_setting_valid(reg))
 		return;
@@ -74,7 +74,7 @@ static void rts5227_fetch_vendor_settings(struct rtsx_pcr *pcr)
 	pcr->card_drive_sel |= rtsx_reg_to_card_drive_sel(reg);
 
 	rtsx_pci_read_config_dword(pcr, PCR_SETTING_REG2, &reg);
-	dev_dbg(&(pcr->pci->dev), "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG2, reg);
+	pcr_dbg(pcr, "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG2, reg);
 	pcr->sd30_drive_sel_3v3 = rtsx_reg_to_sd30_drive_sel_3v3(reg);
 	if (rtsx_reg_check_reverse_socket(reg))
 		pcr->flags |= PCR_REVERSE_SOCKET;
diff --git a/drivers/mfd/rts5229.c b/drivers/mfd/rts5229.c
index 6353f5d..ace4538 100644
--- a/drivers/mfd/rts5229.c
+++ b/drivers/mfd/rts5229.c
@@ -38,7 +38,7 @@ static void rts5229_fetch_vendor_settings(struct rtsx_pcr *pcr)
 	u32 reg;
 
 	rtsx_pci_read_config_dword(pcr, PCR_SETTING_REG1, &reg);
-	dev_dbg(&(pcr->pci->dev), "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG1, reg);
+	pcr_dbg(pcr, "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG1, reg);
 
 	if (!rtsx_vendor_setting_valid(reg))
 		return;
@@ -50,7 +50,7 @@ static void rts5229_fetch_vendor_settings(struct rtsx_pcr *pcr)
 	pcr->card_drive_sel |= rtsx_reg_to_card_drive_sel(reg);
 
 	rtsx_pci_read_config_dword(pcr, PCR_SETTING_REG2, &reg);
-	dev_dbg(&(pcr->pci->dev), "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG2, reg);
+	pcr_dbg(pcr, "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG2, reg);
 	pcr->sd30_drive_sel_3v3 =
 		map_sd_drive(rtsx_reg_to_sd30_drive_sel_3v3(reg));
 }
diff --git a/drivers/mfd/rts5249.c b/drivers/mfd/rts5249.c
index 46b6522..620a8d6 100644
--- a/drivers/mfd/rts5249.c
+++ b/drivers/mfd/rts5249.c
@@ -70,7 +70,7 @@ static void rts5249_fetch_vendor_settings(struct rtsx_pcr *pcr)
 	u32 reg;
 
 	rtsx_pci_read_config_dword(pcr, PCR_SETTING_REG1, &reg);
-	dev_dbg(&(pcr->pci->dev), "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG1, reg);
+	pcr_dbg(pcr, "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG1, reg);
 
 	if (!rtsx_vendor_setting_valid(reg)) {
 		pcr_dbg(pcr, "skip fetch vendor setting\n");
@@ -83,7 +83,7 @@ static void rts5249_fetch_vendor_settings(struct rtsx_pcr *pcr)
 	pcr->card_drive_sel |= rtsx_reg_to_card_drive_sel(reg);
 
 	rtsx_pci_read_config_dword(pcr, PCR_SETTING_REG2, &reg);
-	dev_dbg(&(pcr->pci->dev), "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG2, reg);
+	pcr_dbg(pcr, "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG2, reg);
 	pcr->sd30_drive_sel_3v3 = rtsx_reg_to_sd30_drive_sel_3v3(reg);
 	if (rtsx_reg_check_reverse_socket(reg))
 		pcr->flags |= PCR_REVERSE_SOCKET;
diff --git a/drivers/mfd/rtsx_pcr.c b/drivers/mfd/rtsx_pcr.c
index 33aa30b..1b65f04 100644
--- a/drivers/mfd/rtsx_pcr.c
+++ b/drivers/mfd/rtsx_pcr.c
@@ -315,8 +315,7 @@ int rtsx_pci_send_cmd(struct rtsx_pcr *pcr, int timeout)
 	timeleft = wait_for_completion_interruptible_timeout(
 			&trans_done, msecs_to_jiffies(timeout));
 	if (timeleft <= 0) {
-		dev_dbg(&(pcr->pci->dev), "Timeout (%s %d)\n",
-				__func__, __LINE__);
+		pcr_dbg(pcr, "Timeout (%s %d)\n", __func__, __LINE__);
 		err = -ETIMEDOUT;
 		goto finish_send_cmd;
 	}
@@ -352,8 +351,7 @@ static void rtsx_pci_add_sg_tbl(struct rtsx_pcr *pcr,
 	u64 val;
 	u8 option = SG_VALID | SG_TRANS_DATA;
 
-	dev_dbg(&(pcr->pci->dev), "DMA addr: 0x%x, Len: 0x%x\n",
-			(unsigned int)addr, len);
+	pcr_dbg(pcr, "DMA addr: 0x%x, Len: 0x%x\n", (unsigned int)addr, len);
 
 	if (end)
 		option |= SG_END;
@@ -368,11 +366,11 @@ int rtsx_pci_transfer_data(struct rtsx_pcr *pcr, struct scatterlist *sglist,
 {
 	int err = 0, count;
 
-	dev_dbg(&(pcr->pci->dev), "--> %s: num_sg = %d\n", __func__, num_sg);
+	pcr_dbg(pcr, "--> %s: num_sg = %d\n", __func__, num_sg);
 	count = rtsx_pci_dma_map_sg(pcr, sglist, num_sg, read);
 	if (count < 1)
 		return -EINVAL;
-	dev_dbg(&(pcr->pci->dev), "DMA mapping count: %d\n", count);
+	pcr_dbg(pcr, "DMA mapping count: %d\n", count);
 
 	err = rtsx_pci_dma_transfer(pcr, sglist, count, read, timeout);
 
@@ -446,8 +444,7 @@ int rtsx_pci_dma_transfer(struct rtsx_pcr *pcr, struct scatterlist *sglist,
 	timeleft = wait_for_completion_interruptible_timeout(
 			&trans_done, msecs_to_jiffies(timeout));
 	if (timeleft <= 0) {
-		dev_dbg(&(pcr->pci->dev), "Timeout (%s %d)\n",
-				__func__, __LINE__);
+		pcr_dbg(pcr, "Timeout (%s %d)\n", __func__, __LINE__);
 		err = -ETIMEDOUT;
 		goto out;
 	}
@@ -621,7 +618,7 @@ static void rtsx_pci_enable_bus_int(struct rtsx_pcr *pcr)
 	/* Enable Bus Interrupt */
 	rtsx_pci_writel(pcr, RTSX_BIER, pcr->bier);
 
-	dev_dbg(&(pcr->pci->dev), "RTSX_BIER: 0x%08x\n", pcr->bier);
+	pcr_dbg(pcr, "RTSX_BIER: 0x%08x\n", pcr->bier);
 }
 
 static inline u8 double_ssc_depth(u8 depth)
@@ -667,14 +664,13 @@ int rtsx_pci_switch_clock(struct rtsx_pcr *pcr, unsigned int card_clock,
 		return err;
 
 	card_clock /= 1000000;
-	dev_dbg(&(pcr->pci->dev), "Switch card clock to %dMHz\n", card_clock);
+	pcr_dbg(pcr, "Switch card clock to %dMHz\n", card_clock);
 
 	clk = card_clock;
 	if (!initial_mode && double_clk)
 		clk = card_clock * 2;
-	dev_dbg(&(pcr->pci->dev),
-			"Internal SSC clock: %dMHz (cur_clock = %d)\n",
-			clk, pcr->cur_clock);
+	pcr_dbg(pcr, "Internal SSC clock: %dMHz (cur_clock = %d)\n",
+		clk, pcr->cur_clock);
 
 	if (clk == pcr->cur_clock)
 		return 0;
@@ -703,14 +699,14 @@ int rtsx_pci_switch_clock(struct rtsx_pcr *pcr, unsigned int card_clock,
 		}
 		div++;
 	}
-	dev_dbg(&(pcr->pci->dev), "n = %d, div = %d\n", n, div);
+	pcr_dbg(pcr, "n = %d, div = %d\n", n, div);
 
 	ssc_depth = depth[ssc_depth];
 	if (double_clk)
 		ssc_depth = double_ssc_depth(ssc_depth);
 
 	ssc_depth = revise_ssc_depth(ssc_depth, div);
-	dev_dbg(&(pcr->pci->dev), "ssc_depth = %d\n", ssc_depth);
+	pcr_dbg(pcr, "ssc_depth = %d\n", ssc_depth);
 
 	rtsx_pci_init_cmd(pcr);
 	rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, CLK_CTL,
@@ -832,13 +828,13 @@ static void rtsx_pci_card_detect(struct work_struct *work)
 	dwork = to_delayed_work(work);
 	pcr = container_of(dwork, struct rtsx_pcr, carddet_work);
 
-	dev_dbg(&(pcr->pci->dev), "--> %s\n", __func__);
+	pcr_dbg(pcr, "--> %s\n", __func__);
 
 	mutex_lock(&pcr->pcr_mutex);
 	spin_lock_irqsave(&pcr->lock, flags);
 
 	irq_status = rtsx_pci_readl(pcr, RTSX_BIPR);
-	dev_dbg(&(pcr->pci->dev), "irq_status: 0x%08x\n", irq_status);
+	pcr_dbg(pcr, "irq_status: 0x%08x\n", irq_status);
 
 	irq_status &= CARD_EXIST;
 	card_inserted = pcr->card_inserted & irq_status;
@@ -849,9 +845,8 @@ static void rtsx_pci_card_detect(struct work_struct *work)
 	spin_unlock_irqrestore(&pcr->lock, flags);
 
 	if (card_inserted || card_removed) {
-		dev_dbg(&(pcr->pci->dev),
-				"card_inserted: 0x%x, card_removed: 0x%x\n",
-				card_inserted, card_removed);
+		pcr_dbg(pcr, "card_inserted: 0x%x, card_removed: 0x%x\n",
+			card_inserted, card_removed);
 
 		if (pcr->ops->cd_deglitch)
 			card_inserted = pcr->ops->cd_deglitch(pcr);
@@ -959,7 +954,7 @@ static void rtsx_pci_idle_work(struct work_struct *work)
 	struct delayed_work *dwork = to_delayed_work(work);
 	struct rtsx_pcr *pcr = container_of(dwork, struct rtsx_pcr, idle_work);
 
-	dev_dbg(&(pcr->pci->dev), "--> %s\n", __func__);
+	pcr_dbg(pcr, "--> %s\n", __func__);
 
 	mutex_lock(&pcr->pcr_mutex);
 
@@ -1127,7 +1122,7 @@ static int rtsx_pci_init_chip(struct rtsx_pcr *pcr)
 		break;
 	}
 
-	dev_dbg(&(pcr->pci->dev), "PID: 0x%04x, IC version: 0x%02x\n",
+	pcr_dbg(pcr, "PID: 0x%04x, IC version: 0x%02x\n",
 			PCI_PID(pcr), pcr->ic_version);
 
 	pcr->slots = kcalloc(pcr->num_slots, sizeof(struct rtsx_slot),
@@ -1138,14 +1133,14 @@ static int rtsx_pci_init_chip(struct rtsx_pcr *pcr)
 	if (pcr->ops->fetch_vendor_settings)
 		pcr->ops->fetch_vendor_settings(pcr);
 
-	dev_dbg(&(pcr->pci->dev), "pcr->aspm_en = 0x%x\n", pcr->aspm_en);
-	dev_dbg(&(pcr->pci->dev), "pcr->sd30_drive_sel_1v8 = 0x%x\n",
+	pcr_dbg(pcr, "pcr->aspm_en = 0x%x\n", pcr->aspm_en);
+	pcr_dbg(pcr, "pcr->sd30_drive_sel_1v8 = 0x%x\n",
 			pcr->sd30_drive_sel_1v8);
-	dev_dbg(&(pcr->pci->dev), "pcr->sd30_drive_sel_3v3 = 0x%x\n",
+	pcr_dbg(pcr, "pcr->sd30_drive_sel_3v3 = 0x%x\n",
 			pcr->sd30_drive_sel_3v3);
-	dev_dbg(&(pcr->pci->dev), "pcr->card_drive_sel = 0x%x\n",
+	pcr_dbg(pcr, "pcr->card_drive_sel = 0x%x\n",
 			pcr->card_drive_sel);
-	dev_dbg(&(pcr->pci->dev), "pcr->flags = 0x%x\n", pcr->flags);
+	pcr_dbg(pcr, "pcr->flags = 0x%x\n", pcr->flags);
 
 	pcr->state = PDEV_STAT_IDLE;
 	err = rtsx_pci_init_hw(pcr);
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* Re: [PATCH 10/10] mfd: rtsx: using pcr_dbg replace dev_dbg
  2015-01-15 11:19 ` [PATCH 10/10] mfd: rtsx: using pcr_dbg replace dev_dbg micky_ching
@ 2015-01-18 10:43   ` Lee Jones
  0 siblings, 0 replies; 36+ messages in thread
From: Lee Jones @ 2015-01-18 10:43 UTC (permalink / raw)
  To: micky_ching; +Cc: sameo, devel, linux-kernel, gregkh, rogerable, wei_wang

On Thu, 15 Jan 2015, micky_ching@realsil.com.cn wrote:

> From: Micky Ching <micky_ching@realsil.com.cn>
> 
> pcr_dbg is a wrapper of dev_dbg, which can save some code,
> and help to enable/disable debug message static.
> 
> Signed-off-by: Micky Ching <micky_ching@realsil.com.cn>
> ---
>  drivers/mfd/rtl8411.c  | 11 +++++------
>  drivers/mfd/rts5209.c  |  4 ++--
>  drivers/mfd/rts5227.c  |  4 ++--
>  drivers/mfd/rts5229.c  |  4 ++--
>  drivers/mfd/rts5249.c  |  4 ++--
>  drivers/mfd/rtsx_pcr.c | 49 ++++++++++++++++++++++---------------------------
>  6 files changed, 35 insertions(+), 41 deletions(-)

Looks fine.

Acked-by: Lee Jones <lee.jones@linaro.org>

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 09/10] mfd: rtsx: add support for rts525A
  2015-01-15 11:19 ` [PATCH 09/10] mfd: rtsx: add support for rts525A micky_ching
@ 2015-01-18 11:13   ` Lee Jones
  2015-01-19  2:53     ` 敬锐
  0 siblings, 1 reply; 36+ messages in thread
From: Lee Jones @ 2015-01-18 11:13 UTC (permalink / raw)
  To: micky_ching; +Cc: sameo, devel, linux-kernel, gregkh, rogerable, wei_wang

On Thu, 15 Jan 2015, micky_ching@realsil.com.cn wrote:

> From: Micky Ching <micky_ching@realsil.com.cn>
> 
> add support for new chip rts525A.
> 
> Signed-off-by: Micky Ching <micky_ching@realsil.com.cn>
> ---
>  drivers/mfd/rts5249.c  | 93 +++++++++++++++++++++++++++++++++++++++++++++++++-
>  drivers/mfd/rtsx_pcr.c | 13 +++++--
>  drivers/mfd/rtsx_pcr.h |  1 +
>  3 files changed, 103 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/mfd/rts5249.c b/drivers/mfd/rts5249.c
> index 1ce03a6..46b6522 100644
> --- a/drivers/mfd/rts5249.c
> +++ b/drivers/mfd/rts5249.c
> @@ -97,7 +97,7 @@ static void rts5249_force_power_down(struct rtsx_pcr *pcr, u8 pm_state)
>  	rtsx_pci_write_register(pcr, AUTOLOAD_CFG_BASE + 3, 0x01, 0);
>  
>  	if (pm_state == HOST_ENTER_S3) {
> -		if (PCI_PID(pcr) == 0x524A)
> +		if (PCI_PID(pcr) == 0x524A || PCI_PID(pcr) == 0x525A)

Shouldn't these be defined somewhere?

I have a particular distaste for magic numbers.

>  			rtsx_pci_write_register(pcr, RTS524A_PM_CTRL3,
>  				D3_DELINK_MODE_EN, D3_DELINK_MODE_EN);
>  		else if (PCI_PID(pcr) == 0x5249)
> @@ -430,3 +430,94 @@ void rts524a_init_params(struct rtsx_pcr *pcr)
>  	pcr->ops = &rts524a_pcr_ops;
>  }
>  
> +static int rts525a_card_power_on(struct rtsx_pcr *pcr, int card)
> +{
> +	rtsx_pci_write_register(pcr, LDO_VCC_CFG1,
> +		LDO_VCC_TUNE_MASK, LDO_VCC_3V3);
> +	return rts5249_card_power_on(pcr, card);
> +}

Small formatting nit: I'd prefer if you'd line up the wrap to the '('
and leave a '\n' before the return line.

> +static int rts525a_switch_output_voltage(struct rtsx_pcr *pcr, u8 voltage)
> +{
> +	if (voltage == OUTPUT_3V3) {
> +		rtsx_pci_write_register(pcr, LDO_CONFIG2,
> +			LDO_D3318_MASK, LDO_D3318_33V);
> +		rtsx_pci_write_register(pcr, SD_PAD_CTL, SD_IO_USING_1V8, 0);
> +	} else if (voltage == OUTPUT_1V8) {
> +		rtsx_pci_write_register(pcr, LDO_CONFIG2,
> +			LDO_D3318_MASK, LDO_D3318_18V);
> +		rtsx_pci_write_register(pcr, SD_PAD_CTL, SD_IO_USING_1V8,
> +			SD_IO_USING_1V8);
> +	} else {
> +		return -EINVAL;
> +	}

This might look nicer as a switch().

> +	rtsx_pci_init_cmd(pcr);
> +	rts5249_fill_driving(pcr, voltage);
> +	return rtsx_pci_send_cmd(pcr, 100);
> +}
> +
> +static int rts525a_optimize_phy(struct rtsx_pcr *pcr)
> +{
> +	int err;
> +
> +	err = rtsx_pci_write_register(pcr, RTS524A_PM_CTRL3,
> +		D3_DELINK_MODE_EN, 0x00);
> +	if (err < 0)
> +		return err;

rtsx_pci_write_register() can't return >0, so just check for (err).

> +	rtsx_pci_write_phy_register(pcr, 0x1D, 0x99FF);
> +	rtsx_pci_write_phy_register(pcr, 0x03, 0x2748);

More magic numbers that I have absolutely no idea what the mean.

Please define them (includes the one below).

> +	if (is_version(pcr, 0x525A, IC_VER_A))
> +		rtsx_pci_write_phy_register(pcr, 0x19, 0x3902);
> +
> +	return 0;
> +}
> +
> +static int rts525a_extra_init_hw(struct rtsx_pcr *pcr)
> +{
> +	rts5249_extra_init_hw(pcr);
> +
> +	rtsx_pci_write_register(pcr, PCLK_CTL, PCLK_MODE_SEL, PCLK_MODE_SEL);
> +	if (is_version(pcr, 0x525A, IC_VER_A)) {
> +		rtsx_pci_write_register(pcr, L1SUB_CONFIG2,
> +			L1SUB_AUTO_CFG, L1SUB_AUTO_CFG);
> +		rtsx_pci_write_register(pcr, RREF_CFG,
> +			RREF_VBGSEL_MASK, RREF_VBGSEL_1V25);
> +		rtsx_pci_write_register(pcr, LDO_VIO_CFG,
> +			LDO_VIO_TUNE_MASK, LDO_VIO_1V7);
> +		rtsx_pci_write_register(pcr, LDO_DV12S_CFG,
> +			LDO_D12_TUNE_MASK, LDO_D12_TUNE_DF);
> +		rtsx_pci_write_register(pcr, LDO_AV12S_CFG,
> +			LDO_AV12S_TUNE_MASK, LDO_AV12S_TUNE_DF);
> +		rtsx_pci_write_register(pcr, LDO_VCC_CFG0,
> +			LDO_VCC_LMTVTH_MASK, LDO_VCC_LMTVTH_2A);
> +		rtsx_pci_write_register(pcr, OOBS_CONFIG,
> +			OOBS_AUTOK_DIS | OOBS_VAL_MASK, 0x89);
> +	}
> +
> +	return 0;
> +}
> +
> +static const struct pcr_ops rts525a_pcr_ops = {
> +	.fetch_vendor_settings = rts5249_fetch_vendor_settings,
> +	.extra_init_hw = rts525a_extra_init_hw,
> +	.optimize_phy = rts525a_optimize_phy,
> +	.turn_on_led = rts5249_turn_on_led,
> +	.turn_off_led = rts5249_turn_off_led,
> +	.enable_auto_blink = rts5249_enable_auto_blink,
> +	.disable_auto_blink = rts5249_disable_auto_blink,
> +	.card_power_on = rts525a_card_power_on,
> +	.card_power_off = rts5249_card_power_off,
> +	.switch_output_voltage = rts525a_switch_output_voltage,
> +	.force_power_down = rts5249_force_power_down,
> +};
> +
> +void rts525a_init_params(struct rtsx_pcr *pcr)
> +{
> +	rts5249_init_params(pcr);
> +
> +	pcr->ops = &rts525a_pcr_ops;
> +}
> +
> diff --git a/drivers/mfd/rtsx_pcr.c b/drivers/mfd/rtsx_pcr.c
> index 17334ba..33aa30b 100644
> --- a/drivers/mfd/rtsx_pcr.c
> +++ b/drivers/mfd/rtsx_pcr.c
> @@ -59,6 +59,7 @@ static const struct pci_device_id rtsx_pci_ids[] = {
>  	{ PCI_DEVICE(0x10EC, 0x5287), PCI_CLASS_OTHERS << 16, 0xFF0000 },
>  	{ PCI_DEVICE(0x10EC, 0x5286), PCI_CLASS_OTHERS << 16, 0xFF0000 },
>  	{ PCI_DEVICE(0x10EC, 0x524A), PCI_CLASS_OTHERS << 16, 0xFF0000 },
> +	{ PCI_DEVICE(0x10EC, 0x525A), PCI_CLASS_OTHERS << 16, 0xFF0000 },
>  	{ 0, }
>  };
>  
> @@ -1113,6 +1114,10 @@ static int rtsx_pci_init_chip(struct rtsx_pcr *pcr)
>  		rts524a_init_params(pcr);
>  		break;
>  
> +	case 0x525A:
> +		rts525a_init_params(pcr);
> +		break;
> +
>  	case 0x5287:
>  		rtl8411b_init_params(pcr);
>  		break;
> @@ -1158,7 +1163,7 @@ static int rtsx_pci_probe(struct pci_dev *pcidev,
>  	struct rtsx_pcr *pcr;
>  	struct pcr_handle *handle;
>  	u32 base, len;
> -	int ret, i;
> +	int ret, i, bar = 0;
>  
>  	dev_dbg(&(pcidev->dev),
>  		": Realtek PCI-E Card Reader found at %s [%04x:%04x] (rev %x)\n",
> @@ -1203,8 +1208,10 @@ static int rtsx_pci_probe(struct pci_dev *pcidev,
>  	pcr->pci = pcidev;
>  	dev_set_drvdata(&pcidev->dev, handle);
>  
> -	len = pci_resource_len(pcidev, 0);
> -	base = pci_resource_start(pcidev, 0);
> +	if (PCI_PID(pcr) == 0x525A)
> +		bar = 1;
> +	len = pci_resource_len(pcidev, bar);
> +	base = pci_resource_start(pcidev, bar);
>  	pcr->remap_addr = ioremap_nocache(base, len);
>  	if (!pcr->remap_addr) {
>  		ret = -ENOMEM;
> diff --git a/drivers/mfd/rtsx_pcr.h b/drivers/mfd/rtsx_pcr.h
> index 0535265..4c00544 100644
> --- a/drivers/mfd/rtsx_pcr.h
> +++ b/drivers/mfd/rtsx_pcr.h
> @@ -37,6 +37,7 @@ void rtl8402_init_params(struct rtsx_pcr *pcr);
>  void rts5227_init_params(struct rtsx_pcr *pcr);
>  void rts5249_init_params(struct rtsx_pcr *pcr);
>  void rts524a_init_params(struct rtsx_pcr *pcr);
> +void rts525a_init_params(struct rtsx_pcr *pcr);
>  void rtl8411b_init_params(struct rtsx_pcr *pcr);
>  
>  static inline u8 map_sd_drive(int idx)

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 08/10] mfd: rtsx: add support for rts524A
  2015-01-15 11:19 ` [PATCH 08/10] mfd: rtsx: add support for rts524A micky_ching
@ 2015-01-18 12:20   ` Lee Jones
  2015-01-19  2:32     ` 敬锐
                       ` (2 more replies)
  0 siblings, 3 replies; 36+ messages in thread
From: Lee Jones @ 2015-01-18 12:20 UTC (permalink / raw)
  To: micky_ching; +Cc: sameo, devel, linux-kernel, gregkh, rogerable, wei_wang

On Thu, 15 Jan 2015, micky_ching@realsil.com.cn wrote:

> From: Micky Ching <micky_ching@realsil.com.cn>
> 
> add support for new chip rts524A.
> 
> Signed-off-by: Micky Ching <micky_ching@realsil.com.cn>
> ---
>  drivers/mfd/rts5249.c        | 112 +++++++++++++++++++++++++++++++++++++++----
>  drivers/mfd/rtsx_pcr.c       |   5 ++
>  drivers/mfd/rtsx_pcr.h       |   4 ++
>  include/linux/mfd/rtsx_pci.h |  87 ++++++++++++++++++++++++++++++++-
>  4 files changed, 198 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/mfd/rts5249.c b/drivers/mfd/rts5249.c
> index 5eb9819..1ce03a6 100644
> --- a/drivers/mfd/rts5249.c
> +++ b/drivers/mfd/rts5249.c
> @@ -72,8 +72,10 @@ static void rts5249_fetch_vendor_settings(struct rtsx_pcr *pcr)
>  	rtsx_pci_read_config_dword(pcr, PCR_SETTING_REG1, &reg);
>  	dev_dbg(&(pcr->pci->dev), "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG1, reg);
>  
> -	if (!rtsx_vendor_setting_valid(reg))
> +	if (!rtsx_vendor_setting_valid(reg)) {
> +		pcr_dbg(pcr, "skip fetch vendor setting\n");
>  		return;
> +	}

This doesn't have anything to do with adding the new chip.

And I'm not sure it's even required.

>  	pcr->aspm_en = rtsx_reg_to_aspm(reg);
>  	pcr->sd30_drive_sel_1v8 = rtsx_reg_to_sd30_drive_sel_1v8(reg);
> @@ -94,8 +96,14 @@ static void rts5249_force_power_down(struct rtsx_pcr *pcr, u8 pm_state)
>  	rtsx_pci_write_register(pcr, AUTOLOAD_CFG_BASE + 2, 0xFF, 0);
>  	rtsx_pci_write_register(pcr, AUTOLOAD_CFG_BASE + 3, 0x01, 0);
>  
> -	if (pm_state == HOST_ENTER_S3)
> -		rtsx_pci_write_register(pcr, PM_CTRL3, 0x10, 0x10);
> +	if (pm_state == HOST_ENTER_S3) {
> +		if (PCI_PID(pcr) == 0x524A)
> +			rtsx_pci_write_register(pcr, RTS524A_PM_CTRL3,
> +				D3_DELINK_MODE_EN, D3_DELINK_MODE_EN);
> +		else if (PCI_PID(pcr) == 0x5249)
> +			rtsx_pci_write_register(pcr, PM_CTRL3,
> +				D3_DELINK_MODE_EN, D3_DELINK_MODE_EN);
> +	}
>  
>  	rtsx_pci_write_register(pcr, FPDCTL, 0x03, 0x03);
>  }
> @@ -104,6 +112,8 @@ static int rts5249_extra_init_hw(struct rtsx_pcr *pcr)
>  {
>  	rtsx_pci_init_cmd(pcr);
>  
> +	/* Rest L1SUB Config */
> +	rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, L1SUB_CONFIG3, 0xFF, 0x00);
>  	/* Configure GPIO as output */
>  	rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, GPIO_CTL, 0x02, 0x02);
>  	/* Reset ASPM state to default value */
> @@ -228,14 +238,20 @@ static int rts5249_switch_output_voltage(struct rtsx_pcr *pcr, u8 voltage)
>  	int err;

This function name is now misleading.

Please change it, or at least add a comment saying that it doesn't
only support the 5249.

>  	if (voltage == OUTPUT_3V3) {
> -		err = rtsx_pci_write_phy_register(pcr, PHY_TUNE, 0x4FC0 | 0x24);
> +		err = rtsx_pci_update_phy(pcr, PHY_TUNE, 0xFC3F, 0x03C0);
>  		if (err < 0)
>  			return err;
>  	} else if (voltage == OUTPUT_1V8) {
> -		err = rtsx_pci_write_phy_register(pcr, PHY_BACR, 0x3C02);
> -		if (err < 0)
> -			return err;
> -		err = rtsx_pci_write_phy_register(pcr, PHY_TUNE, 0x4C40 | 0x24);
> +		u16 append = 0x0100;
> +
> +		if (PCI_PID(pcr) == 0x5249) {
> +			err = rtsx_pci_update_phy(pcr, PHY_BACR, 0xFFF3, 0);
> +			if (err < 0)
> +				return err;
> +			append = 0x0080;
> +		}
> +
> +		err = rtsx_pci_update_phy(pcr, PHY_TUNE, 0xFC3F, append);
>  		if (err < 0)
>  			return err;
>  	} else {
> @@ -334,3 +350,83 @@ void rts5249_init_params(struct rtsx_pcr *pcr)
>  	pcr->ms_pull_ctl_enable_tbl = rts5249_ms_pull_ctl_enable_tbl;
>  	pcr->ms_pull_ctl_disable_tbl = rts5249_ms_pull_ctl_disable_tbl;
>  }
> +
> +static inline int rts524a_write_phy(struct rtsx_pcr *pcr, u8 addr, u16 val)
> +{
> +	addr = addr & 0x80 ? (addr & 0x7F) | 0x40 : addr;
> +	return rtsx_pci_write_phy_register(pcr, addr, val);
> +}
> +
> +static int rts524a_optimize_phy(struct rtsx_pcr *pcr)
> +{
> +	int err;
> +
> +	err = rtsx_pci_write_register(pcr, RTS524A_PM_CTRL3,
> +		D3_DELINK_MODE_EN, 0x00);
> +	if (err < 0)
> +		return err;

if (err)

> +	rts524a_write_phy(pcr, 0x00, 0xBA42);
> +	rts524a_write_phy(pcr, 0x03, 0x2748);
> +
> +	if (is_version(pcr, 0x524A, IC_VER_A)) {
> +		rts524a_write_phy(pcr, 0x03, 0x2748);
> +		rts524a_write_phy(pcr, 0x02, 0x0A1F);
> +		rts524a_write_phy(pcr, 0x1A, 0x2546);
> +		rts524a_write_phy(pcr, 0x1D, 0x0004);
> +		rts524a_write_phy(pcr, 0x1E, 0x5C7F);

I have no idea what this is doing!

Please humanise this nonsense.

> +	}
> +
> +	rts524a_write_phy(pcr, 0x08, 0x57E4);
> +
> +	return 0;
> +}
> +
> +static int rts524a_extra_init_hw(struct rtsx_pcr *pcr)
> +{
> +	rts5249_extra_init_hw(pcr);
> +
> +	rtsx_pci_write_register(pcr, FUNC_FORCE_CTL, 0x02, 0x02);

?

> +	rtsx_pci_write_register(pcr, PM_EVENT_DEBUG, PME_DEBUG_0, PME_DEBUG_0);
> +	rtsx_pci_write_register(pcr, LDO_VCC_CFG1, LDO_VCC_LMT_EN,
> +		LDO_VCC_LMT_EN);
> +	rtsx_pci_write_register(pcr, PCLK_CTL, PCLK_MODE_SEL, PCLK_MODE_SEL);
> +	if (is_version(pcr, 0x524A, IC_VER_A)) {
> +		rtsx_pci_write_register(pcr, LDO_DV18_CFG,
> +			LDO_DV18_SR_MASK, LDO_DV18_SR_DF);
> +		rtsx_pci_write_register(pcr, LDO_VCC_CFG1,
> +			LDO_VCC_REF_TUNE_MASK, LDO_VCC_REF_1V2);
> +		rtsx_pci_write_register(pcr, LDO_VIO_CFG,
> +			LDO_VIO_REF_TUNE_MASK, LDO_VIO_REF_1V2);
> +		rtsx_pci_write_register(pcr, LDO_VIO_CFG,
> +			LDO_VIO_SR_MASK, LDO_VIO_SR_DF);
> +		rtsx_pci_write_register(pcr, LDO_DV12S_CFG,
> +			LDO_REF12_TUNE_MASK, LDO_REF12_TUNE_DF);
> +		rtsx_pci_write_register(pcr, SD40_LDO_CTL1,
> +			SD40_VIO_TUNE_MASK, SD40_VIO_TUNE_1V7);
> +	}
> +
> +	return 0;
> +}
> +
> +static const struct pcr_ops rts524a_pcr_ops = {
> +	.fetch_vendor_settings = rts5249_fetch_vendor_settings,
> +	.extra_init_hw = rts524a_extra_init_hw,
> +	.optimize_phy = rts524a_optimize_phy,
> +	.turn_on_led = rts5249_turn_on_led,
> +	.turn_off_led = rts5249_turn_off_led,
> +	.enable_auto_blink = rts5249_enable_auto_blink,
> +	.disable_auto_blink = rts5249_disable_auto_blink,
> +	.card_power_on = rts5249_card_power_on,
> +	.card_power_off = rts5249_card_power_off,
> +	.switch_output_voltage = rts5249_switch_output_voltage,
> +	.force_power_down = rts5249_force_power_down,

You might need to change the name of some of these functions (or at
least add comments) if you plan on using them for multiple devices.

> +};
> +
> +void rts524a_init_params(struct rtsx_pcr *pcr)
> +{
> +	rts5249_init_params(pcr);
> +
> +	pcr->ops = &rts524a_pcr_ops;
> +}

I see a couple of these now.  Why don't you make 'ops' a parameter of
*_init_params().

> diff --git a/drivers/mfd/rtsx_pcr.c b/drivers/mfd/rtsx_pcr.c
> index 3065edc..17334ba 100644
> --- a/drivers/mfd/rtsx_pcr.c
> +++ b/drivers/mfd/rtsx_pcr.c
> @@ -58,6 +58,7 @@ static const struct pci_device_id rtsx_pci_ids[] = {
>  	{ PCI_DEVICE(0x10EC, 0x5249), PCI_CLASS_OTHERS << 16, 0xFF0000 },
>  	{ PCI_DEVICE(0x10EC, 0x5287), PCI_CLASS_OTHERS << 16, 0xFF0000 },
>  	{ PCI_DEVICE(0x10EC, 0x5286), PCI_CLASS_OTHERS << 16, 0xFF0000 },
> +	{ PCI_DEVICE(0x10EC, 0x524A), PCI_CLASS_OTHERS << 16, 0xFF0000 },
>  	{ 0, }
>  };
>  
> @@ -1108,6 +1109,10 @@ static int rtsx_pci_init_chip(struct rtsx_pcr *pcr)
>  		rts5249_init_params(pcr);
>  		break;
>  
> +	case 0x524A:
> +		rts524a_init_params(pcr);
> +		break;
> +
>  	case 0x5287:
>  		rtl8411b_init_params(pcr);
>  		break;
> diff --git a/drivers/mfd/rtsx_pcr.h b/drivers/mfd/rtsx_pcr.h
> index fe2bbb6..0535265 100644
> --- a/drivers/mfd/rtsx_pcr.h
> +++ b/drivers/mfd/rtsx_pcr.h
> @@ -27,12 +27,16 @@
>  #define MIN_DIV_N_PCR		80
>  #define MAX_DIV_N_PCR		208
>  
> +#define RTS524A_PME_FORCE_CTL		0xFF78
> +#define RTS524A_PM_CTRL3		0xFF7E
> +
>  void rts5209_init_params(struct rtsx_pcr *pcr);
>  void rts5229_init_params(struct rtsx_pcr *pcr);
>  void rtl8411_init_params(struct rtsx_pcr *pcr);
>  void rtl8402_init_params(struct rtsx_pcr *pcr);
>  void rts5227_init_params(struct rtsx_pcr *pcr);
>  void rts5249_init_params(struct rtsx_pcr *pcr);
> +void rts524a_init_params(struct rtsx_pcr *pcr);
>  void rtl8411b_init_params(struct rtsx_pcr *pcr);
>  
>  static inline u8 map_sd_drive(int idx)
> diff --git a/include/linux/mfd/rtsx_pci.h b/include/linux/mfd/rtsx_pci.h
> index f7cebdb..ab6da29 100644
> --- a/include/linux/mfd/rtsx_pci.h
> +++ b/include/linux/mfd/rtsx_pci.h
> @@ -577,8 +577,13 @@
>  
>  #define CDRESUMECTL			0xFE52
>  #define WAKE_SEL_CTL			0xFE54
> +#define PCLK_CTL			0xFE55
> +#define   PCLK_MODE_SEL			0x20
>  #define PME_FORCE_CTL			0xFE56
> +
>  #define ASPM_FORCE_CTL			0xFE57
> +#define   FORCE_ASPM_CTL0		0x10
> +#define   FORCE_ASPM_VAL_MASK		0x03
>  #define PM_CLK_FORCE_CTL		0xFE58
>  #define FUNC_FORCE_CTL			0xFE59
>  #define PERST_GLITCH_WIDTH		0xFE5C
> @@ -590,7 +595,8 @@
>  #define   HOST_ENTER_S3			2
>  
>  #define SDIO_CFG			0xFE70
> -
> +#define PM_EVENT_DEBUG			0xFE71
> +#define   PME_DEBUG_0			0x08
>  #define NFTS_TX_CTRL			0xFE72
>  
>  #define PWR_GATE_CTRL			0xFE75
> @@ -602,12 +608,19 @@
>  #define PWD_SUSPEND_EN			0xFE76
>  #define LDO_PWR_SEL			0xFE78
>  
> +#define L1SUB_CONFIG1			0xFE8D
> +#define L1SUB_CONFIG2			0xFE8E
> +#define   L1SUB_AUTO_CFG		0x02
> +#define L1SUB_CONFIG3			0xFE8F
> +
>  #define DUMMY_REG_RESET_0		0xFE90
>  
>  #define AUTOLOAD_CFG_BASE		0xFF00
>  #define PETXCFG				0xFF03
>  
>  #define PM_CTRL1			0xFF44
> +#define   CD_RESUME_EN_MASK		0xF0
> +
>  #define PM_CTRL2			0xFF45
>  #define PM_CTRL3			0xFF46
>  #define   SDIO_SEND_PME_EN		0x80
> @@ -628,6 +641,61 @@
>  #define IMAGE_FLAG_ADDR0		0xCE80
>  #define IMAGE_FLAG_ADDR1		0xCE81
>  
> +#define RREF_CFG			0xFF6C
> +#define   RREF_VBGSEL_MASK		0x38
> +#define   RREF_VBGSEL_1V25		0x28
> +
> +#define OOBS_CONFIG			0xFF6E
> +#define   OOBS_AUTOK_DIS		0x80
> +#define   OOBS_VAL_MASK			0x1F
> +
> +#define LDO_DV18_CFG			0xFF70
> +#define   LDO_DV18_SR_MASK		0xC0
> +#define   LDO_DV18_SR_DF		0x40
> +
> +#define LDO_CONFIG2			0xFF71
> +#define   LDO_D3318_MASK		0x07
> +#define   LDO_D3318_33V			0x07
> +#define   LDO_D3318_18V			0x02
> +
> +#define LDO_VCC_CFG0			0xFF72
> +#define   LDO_VCC_LMTVTH_MASK		0x30
> +#define   LDO_VCC_LMTVTH_2A		0x10
> +
> +#define LDO_VCC_CFG1			0xFF73
> +#define   LDO_VCC_REF_TUNE_MASK		0x30
> +#define   LDO_VCC_REF_1V2		0x20
> +#define   LDO_VCC_TUNE_MASK		0x07
> +#define   LDO_VCC_1V8			0x04
> +#define   LDO_VCC_3V3			0x07
> +#define   LDO_VCC_LMT_EN		0x08
> +
> +#define LDO_VIO_CFG			0xFF75
> +#define   LDO_VIO_SR_MASK		0xC0
> +#define   LDO_VIO_SR_DF			0x40
> +#define   LDO_VIO_REF_TUNE_MASK		0x30
> +#define   LDO_VIO_REF_1V2		0x20
> +#define   LDO_VIO_TUNE_MASK		0x07
> +#define   LDO_VIO_1V7			0x03
> +#define   LDO_VIO_1V8			0x04
> +#define   LDO_VIO_3V3			0x07
> +
> +#define LDO_DV12S_CFG			0xFF76
> +#define   LDO_REF12_TUNE_MASK		0x18
> +#define   LDO_REF12_TUNE_DF		0x10
> +#define   LDO_D12_TUNE_MASK		0x07
> +#define   LDO_D12_TUNE_DF		0x04
> +
> +#define LDO_AV12S_CFG			0xFF77
> +#define   LDO_AV12S_TUNE_MASK		0x07
> +#define   LDO_AV12S_TUNE_DF		0x04
> +
> +#define SD40_LDO_CTL1			0xFE7D
> +#define   SD40_VIO_TUNE_MASK		0x70
> +#define   SD40_VIO_TUNE_1V7		0x30
> +#define   SD_VIO_LDO_1V8		0x40
> +#define   SD_VIO_LDO_3V3		0x70
> +
>  /* Phy register */
>  #define PHY_PCR				0x00
>  #define PHY_RCR0			0x01
> @@ -828,7 +896,8 @@ struct rtsx_pcr {
>  #define CHK_PCI_PID(pcr, pid)		((pcr)->pci->device == (pid))
>  #define PCI_VID(pcr)			((pcr)->pci->vendor)
>  #define PCI_PID(pcr)			((pcr)->pci->device)
> -
> +#define is_version(pcr, pid, ver)				\
> +	(CHK_PCI_PID(pcr, pid) && (pcr)->ic_version == (ver))
>  #define pcr_dbg(pcr, fmt, arg...)			\
>  	dev_dbg(&(pcr)->pci->dev, fmt, ##arg)
>  #define SDR104_PHASE(val)		((val) & 0xFF)
> @@ -899,4 +968,18 @@ static inline void rtsx_pci_write_be32(struct rtsx_pcr *pcr, u16 reg, u32 val)
>  	rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, reg + 3, 0xFF, val);
>  }
>  
> +static inline int rtsx_pci_update_phy(struct rtsx_pcr *pcr, u8 addr,
> +	u16 mask, u16 append)
> +{
> +	int err = 0;
> +	u16 val = 0;

Not sure why you've pre-initialised these?

> +	err = rtsx_pci_read_phy_register(pcr, addr, &val);
> +	if (err < 0)

if (err)

> +		return err;
> +
> +	err = rtsx_pci_write_phy_register(pcr, addr, (val & mask) | append);
> +	return err;

Just return right away.  No need to load 'err'.

> +}
> +
>  #endif

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 07/10] mfd: rtsx: remove LCTLR defination
  2015-01-15 11:19 ` [PATCH 07/10] mfd: rtsx: remove LCTLR defination micky_ching
@ 2015-01-18 12:28   ` Lee Jones
  2015-01-19  1:12     ` 敬锐
  0 siblings, 1 reply; 36+ messages in thread
From: Lee Jones @ 2015-01-18 12:28 UTC (permalink / raw)
  To: micky_ching; +Cc: sameo, devel, linux-kernel, gregkh, rogerable, wei_wang

On Thu, 15 Jan 2015, micky_ching@realsil.com.cn wrote:

> From: Micky Ching <micky_ching@realsil.com.cn>
> 
> To enable/disable ASPM we should find LINK CONTROL register
> in PCI config space. All old chip use 0x80 address, but new
> chip may use another address, so we using pci_find_capability()
> to get LINK CONTROL address.
> 
> rtsx_gops.c was removed, we consider to put some common operations
> to this file, but the actual thing is, only a group of chips
> are in common ops1, and another group of chips in common ops2,
> it is hard to decide put which ops into generic ops file.
> 
> Signed-off-by: Micky Ching <micky_ching@realsil.com.cn>
> ---
>  drivers/mfd/Makefile         |  2 +-
>  drivers/mfd/rts5227.c        |  2 +-
>  drivers/mfd/rts5249.c        |  3 +--
>  drivers/mfd/rtsx_gops.c      | 37 -------------------------------------
>  drivers/mfd/rtsx_pcr.c       | 25 ++++++++++++++++++++-----
>  include/linux/mfd/rtsx_pci.h |  9 ---------
>  6 files changed, 23 insertions(+), 55 deletions(-)
>  delete mode 100644 drivers/mfd/rtsx_gops.c
> 
> diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
> index 53467e2..2cd7e74 100644
> --- a/drivers/mfd/Makefile
> +++ b/drivers/mfd/Makefile
> @@ -13,7 +13,7 @@ obj-$(CONFIG_MFD_CROS_EC)	+= cros_ec.o
>  obj-$(CONFIG_MFD_CROS_EC_I2C)	+= cros_ec_i2c.o
>  obj-$(CONFIG_MFD_CROS_EC_SPI)	+= cros_ec_spi.o
>  
> -rtsx_pci-objs			:= rtsx_pcr.o rtsx_gops.o rts5209.o rts5229.o rtl8411.o rts5227.o rts5249.o
> +rtsx_pci-objs			:= rtsx_pcr.o rts5209.o rts5229.o rtl8411.o rts5227.o rts5249.o
>  obj-$(CONFIG_MFD_RTSX_PCI)	+= rtsx_pci.o
>  obj-$(CONFIG_MFD_RTSX_USB)	+= rtsx_usb.o
>  
> diff --git a/drivers/mfd/rts5227.c b/drivers/mfd/rts5227.c
> index 1f387d4..0c02831 100644
> --- a/drivers/mfd/rts5227.c
> +++ b/drivers/mfd/rts5227.c
> @@ -130,7 +130,7 @@ static int rts5227_optimize_phy(struct rtsx_pcr *pcr)
>  {
>  	int err;
>  
> -	err = rtsx_gops_pm_reset(pcr);
> +	err = rtsx_pci_write_register(pcr, PM_CTRL3, D3_DELINK_MODE_EN, 0x00);
>  	if (err < 0)
>  		return err;
>  
> diff --git a/drivers/mfd/rts5249.c b/drivers/mfd/rts5249.c
> index 00208d1..5eb9819 100644
> --- a/drivers/mfd/rts5249.c
> +++ b/drivers/mfd/rts5249.c
> @@ -119,7 +119,6 @@ static int rts5249_extra_init_hw(struct rtsx_pcr *pcr)
>  		rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PETXCFG, 0xB0, 0xB0);
>  	else
>  		rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PETXCFG, 0xB0, 0x80);
> -	rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PM_CTRL3, 0x10, 0x00);

What's this doing?  Why is it not required anymore?

>  	return rtsx_pci_send_cmd(pcr, 100);
>  }
> @@ -128,7 +127,7 @@ static int rts5249_optimize_phy(struct rtsx_pcr *pcr)
>  {
>  	int err;
>  
> -	err = rtsx_gops_pm_reset(pcr);
> +	err = rtsx_pci_write_register(pcr, PM_CTRL3, D3_DELINK_MODE_EN, 0x00);
>  	if (err < 0)
>  		return err;
>  
> diff --git a/drivers/mfd/rtsx_gops.c b/drivers/mfd/rtsx_gops.c
> deleted file mode 100644
> index b1a98c6..0000000
> --- a/drivers/mfd/rtsx_gops.c
> +++ /dev/null
> @@ -1,37 +0,0 @@
> -/* Driver for Realtek PCI-Express card reader
> - *
> - * Copyright(c) 2009-2013 Realtek Semiconductor Corp. All rights reserved.
> - *
> - * This program is free software; you can redistribute it and/or modify it
> - * under the terms of the GNU General Public License as published by the
> - * Free Software Foundation; either version 2, or (at your option) any
> - * later version.
> - *
> - * This program is distributed in the hope that it will be useful, but
> - * WITHOUT ANY WARRANTY; without even the implied warranty of
> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> - * General Public License for more details.
> - *
> - * You should have received a copy of the GNU General Public License along
> - * with this program; if not, see <http://www.gnu.org/licenses/>.
> - *
> - * Author:
> - *   Micky Ching <micky_ching@realsil.com.cn>
> - */
> -
> -#include <linux/mfd/rtsx_pci.h>
> -#include "rtsx_pcr.h"
> -
> -int rtsx_gops_pm_reset(struct rtsx_pcr *pcr)
> -{
> -	int err;
> -
> -	/* init aspm */
> -	rtsx_pci_write_register(pcr, ASPM_FORCE_CTL, 0xFF, 0x00);
> -	err = rtsx_pci_update_cfg_byte(pcr, LCTLR, ~LCTLR_ASPM_CTL_MASK, 0x00);
> -	if (err < 0)
> -		return err;
> -
> -	/* reset PM_CTRL3 before send buffer cmd */
> -	return rtsx_pci_write_register(pcr, PM_CTRL3, D3_DELINK_MODE_EN, 0x00);
> -}
> diff --git a/drivers/mfd/rtsx_pcr.c b/drivers/mfd/rtsx_pcr.c
> index 92f5a41..3065edc 100644
> --- a/drivers/mfd/rtsx_pcr.c
> +++ b/drivers/mfd/rtsx_pcr.c
> @@ -63,6 +63,20 @@ static const struct pci_device_id rtsx_pci_ids[] = {
>  
>  MODULE_DEVICE_TABLE(pci, rtsx_pci_ids);
>  
> +static inline void rtsx_pci_enable_aspm(struct rtsx_pcr *pcr)
> +{
> +	int exp = pci_find_capability(pcr->pci, PCI_CAP_ID_EXP);
> +
> +	rtsx_pci_update_cfg_byte(pcr, exp + PCI_EXP_LNKCTL, 0xFC, pcr->aspm_en);
> +}
> +
> +static inline void rtsx_pci_disable_aspm(struct rtsx_pcr *pcr)
> +{
> +	int exp = pci_find_capability(pcr->pci, PCI_CAP_ID_EXP);
> +
> +	rtsx_pci_update_cfg_byte(pcr, exp + PCI_EXP_LNKCTL, 0xFC, 0);
> +}
> +
>  void rtsx_pci_start_run(struct rtsx_pcr *pcr)
>  {
>  	/* If pci device removed, don't queue idle work any more */
> @@ -75,7 +89,8 @@ void rtsx_pci_start_run(struct rtsx_pcr *pcr)
>  			pcr->ops->enable_auto_blink(pcr);
>  
>  		if (pcr->aspm_en)
> -			rtsx_pci_write_config_byte(pcr, LCTLR, 0);
> +			rtsx_pci_disable_aspm(pcr);
> +

?

>  	}
>  
>  	mod_delayed_work(system_wq, &pcr->idle_work, msecs_to_jiffies(200));
> @@ -954,7 +969,7 @@ static void rtsx_pci_idle_work(struct work_struct *work)
>  		pcr->ops->turn_off_led(pcr);
>  
>  	if (pcr->aspm_en)
> -		rtsx_pci_write_config_byte(pcr, LCTLR, pcr->aspm_en);
> +		rtsx_pci_enable_aspm(pcr);
>  
>  	mutex_unlock(&pcr->pcr_mutex);
>  }
> @@ -979,6 +994,7 @@ static void rtsx_pci_power_off(struct rtsx_pcr *pcr, u8 pm_state)
>  static int rtsx_pci_init_hw(struct rtsx_pcr *pcr)
>  {
>  	int err;
> +	int exp = pci_find_capability(pcr->pci, PCI_CAP_ID_EXP);
>  
>  	rtsx_pci_writel(pcr, RTSX_HCBAR, pcr->host_cmds_addr);
>  
> @@ -992,6 +1008,7 @@ static int rtsx_pci_init_hw(struct rtsx_pcr *pcr)
>  	/* Wait SSC power stable */
>  	udelay(200);
>  
> +	rtsx_pci_disable_aspm(pcr);
>  	if (pcr->ops->optimize_phy) {
>  		err = pcr->ops->optimize_phy(pcr);
>  		if (err < 0)
> @@ -1040,10 +1057,8 @@ static int rtsx_pci_init_hw(struct rtsx_pcr *pcr)
>  	if (err < 0)
>  		return err;
>  
> -	rtsx_pci_write_config_byte(pcr, LCTLR, 0);
> -
>  	/* Enable clk_request_n to enable clock power management */
> -	rtsx_pci_write_config_byte(pcr, 0x81, 1);
> +	rtsx_pci_write_config_byte(pcr, exp + PCI_EXP_LNKCTL + 1, 1);
>  	/* Enter L1 when host tx idle */
>  	rtsx_pci_write_config_byte(pcr, 0x70F, 0x5B);
>  
> diff --git a/include/linux/mfd/rtsx_pci.h b/include/linux/mfd/rtsx_pci.h
> index 80baa10..f7cebdb 100644
> --- a/include/linux/mfd/rtsx_pci.h
> +++ b/include/linux/mfd/rtsx_pci.h
> @@ -662,15 +662,6 @@
>  #define PHY_FLD4			0x1E
>  #define PHY_DUM_REG			0x1F
>  
> -#define LCTLR				0x80
> -#define   LCTLR_EXT_SYNC		0x80
> -#define   LCTLR_COMMON_CLOCK_CFG	0x40
> -#define   LCTLR_RETRAIN_LINK		0x20
> -#define   LCTLR_LINK_DISABLE		0x10
> -#define   LCTLR_RCB			0x08
> -#define   LCTLR_RESERVED		0x04
> -#define   LCTLR_ASPM_CTL_MASK		0x03
> -
>  #define PCR_SETTING_REG1		0x724
>  #define PCR_SETTING_REG2		0x814
>  #define PCR_SETTING_REG3		0x747

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 06/10] mfd: rtsx: update phy register
  2015-01-15 11:19 ` [PATCH 06/10] mfd: rtsx: update phy register micky_ching
@ 2015-01-18 12:29   ` Lee Jones
  2015-01-19  1:55     ` 敬锐
  0 siblings, 1 reply; 36+ messages in thread
From: Lee Jones @ 2015-01-18 12:29 UTC (permalink / raw)
  To: micky_ching; +Cc: sameo, devel, linux-kernel, gregkh, rogerable, wei_wang

On Thu, 15 Jan 2015, micky_ching@realsil.com.cn wrote:

> From: Micky Ching <micky_ching@realsil.com.cn>
> 
> update phy register value and using direct value instead of macros.
> It is much easier to debug using constant value than a lot of macros.
> We usually need compare the value directly to check the configure.

NACK.  This is the opposite of what I would like to see.

> Signed-off-by: Micky Ching <micky_ching@realsil.com.cn>
> ---
>  drivers/mfd/rts5249.c | 46 ++++++++++++++--------------------------------
>  1 file changed, 14 insertions(+), 32 deletions(-)
> 
> diff --git a/drivers/mfd/rts5249.c b/drivers/mfd/rts5249.c
> index 2fe2854..00208d1 100644
> --- a/drivers/mfd/rts5249.c
> +++ b/drivers/mfd/rts5249.c
> @@ -132,57 +132,39 @@ static int rts5249_optimize_phy(struct rtsx_pcr *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 |
> -			PHY_REG_REV_RX_PWST | PHY_REG_REV_CLKREQ_DLY_TIMER_1_0 |
> -			PHY_REG_REV_STOP_CLKRD | PHY_REG_REV_STOP_CLKWR);
> +	err = rtsx_pci_write_phy_register(pcr, 0x19, 0xFE6C);
>  	if (err < 0)
>  		return err;
>  
>  	msleep(1);
>  
> -	err = rtsx_pci_write_phy_register(pcr, PHY_BPCR,
> -			PHY_BPCR_IBRXSEL | PHY_BPCR_IBTXSEL |
> -			PHY_BPCR_IB_FILTER | PHY_BPCR_CMIRROR_EN);
> +	err = rtsx_pci_write_phy_register(pcr, 0x0A, 0x05C0);
>  	if (err < 0)
>  		return err;
> -	err = rtsx_pci_write_phy_register(pcr, PHY_PCR,
> -			PHY_PCR_FORCE_CODE | PHY_PCR_OOBS_CALI_50 |
> -			PHY_PCR_OOBS_VCM_08 | PHY_PCR_OOBS_SEN_90 |
> -			PHY_PCR_RSSI_EN);
> +
> +	err = rtsx_pci_write_phy_register(pcr, 0x00, 0xBA43);
> +	if (err < 0)
> +		return err;
> +	err = rtsx_pci_write_phy_register(pcr, 0x03, 0xC152);
>  	if (err < 0)
>  		return err;
> -	err = rtsx_pci_write_phy_register(pcr, PHY_RCR2,
> -			PHY_RCR2_EMPHASE_EN | PHY_RCR2_NADJR |
> -			PHY_RCR2_CDR_CP_10 | PHY_RCR2_CDR_SR_2 |
> -			PHY_RCR2_FREQSEL_12 | PHY_RCR2_CPADJEN |
> -			PHY_RCR2_CDR_SC_8 | PHY_RCR2_CALIB_LATE);
> +	err = rtsx_pci_write_phy_register(pcr, 0x1E, 0x78EB);
>  	if (err < 0)
>  		return err;
> -	err = rtsx_pci_write_phy_register(pcr, PHY_FLD4,
> -			PHY_FLD4_FLDEN_SEL | PHY_FLD4_REQ_REF |
> -			PHY_FLD4_RXAMP_OFF | PHY_FLD4_REQ_ADDA |
> -			PHY_FLD4_BER_COUNT | PHY_FLD4_BER_TIMER |
> -			PHY_FLD4_BER_CHK_EN);
> +	err = rtsx_pci_write_phy_register(pcr, 0x05, 0x4600);
>  	if (err < 0)
>  		return err;
> -	err = rtsx_pci_write_phy_register(pcr, PHY_RDR, PHY_RDR_RXDSEL_1_9);
> +	err = rtsx_pci_write_phy_register(pcr, 0x02, 0x041F);
>  	if (err < 0)
>  		return err;
> -	err = rtsx_pci_write_phy_register(pcr, PHY_RCR1,
> -			PHY_RCR1_ADP_TIME | PHY_RCR1_VCO_COARSE);
> +	err = rtsx_pci_write_phy_register(pcr, 0x1D, 0x0824);
>  	if (err < 0)
>  		return err;
> -	err = rtsx_pci_write_phy_register(pcr, PHY_FLD3,
> -			PHY_FLD3_TIMER_4 | PHY_FLD3_TIMER_6 |
> -			PHY_FLD3_RXDELINK);
> +	err = rtsx_pci_write_phy_register(pcr, 0x08, 0x4FE4);
>  	if (err < 0)
>  		return err;
> -	return rtsx_pci_write_phy_register(pcr, PHY_TUNE,
> -			PHY_TUNE_TUNEREF_1_0 | PHY_TUNE_VBGSEL_1252 |
> -			PHY_TUNE_SDBUS_33 | PHY_TUNE_TUNED18 |
> -			PHY_TUNE_TUNED12);
> +
> +	return 0;
>  }
>  
>  static int rts5249_turn_on_led(struct rtsx_pcr *pcr)

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 04/10] mfd: rtsx: update PETXCFG address
  2015-01-15 11:19 ` [PATCH 04/10] mfd: rtsx: update PETXCFG address micky_ching
@ 2015-01-18 12:31   ` Lee Jones
  0 siblings, 0 replies; 36+ messages in thread
From: Lee Jones @ 2015-01-18 12:31 UTC (permalink / raw)
  To: micky_ching; +Cc: sameo, devel, linux-kernel, gregkh, rogerable, wei_wang

On Thu, 15 Jan 2015, micky_ching@realsil.com.cn wrote:

> From: Micky Ching <micky_ching@realsil.com.cn>
> 
> PETXCFG is defined at 0xFF03, the old 0xFE49 not used any more.
> 
> Signed-off-by: Micky Ching <micky_ching@realsil.com.cn>
> ---
>  drivers/mfd/rts5227.c        | 6 ++----
>  drivers/mfd/rts5249.c        | 6 ++----
>  include/linux/mfd/rtsx_pci.h | 2 +-
>  3 files changed, 5 insertions(+), 9 deletions(-)

Acked-by: Lee Jones <lee.jones@linaro.org>

> diff --git a/drivers/mfd/rts5227.c b/drivers/mfd/rts5227.c
> index 3240740..1f387d4 100644
> --- a/drivers/mfd/rts5227.c
> +++ b/drivers/mfd/rts5227.c
> @@ -118,11 +118,9 @@ static int rts5227_extra_init_hw(struct rtsx_pcr *pcr)
>  	rts5227_fill_driving(pcr, OUTPUT_3V3);
>  	/* Configure force_clock_req */
>  	if (pcr->flags & PCR_REVERSE_SOCKET)
> -		rtsx_pci_add_cmd(pcr, WRITE_REG_CMD,
> -				AUTOLOAD_CFG_BASE + 3, 0xB8, 0xB8);
> +		rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PETXCFG, 0xB8, 0xB8);
>  	else
> -		rtsx_pci_add_cmd(pcr, WRITE_REG_CMD,
> -				AUTOLOAD_CFG_BASE + 3, 0xB8, 0x88);
> +		rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PETXCFG, 0xB8, 0x88);
>  	rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PM_CTRL3, 0x10, 0x00);
>  
>  	return rtsx_pci_send_cmd(pcr, 100);
> diff --git a/drivers/mfd/rts5249.c b/drivers/mfd/rts5249.c
> index cf425cc..225ad55 100644
> --- a/drivers/mfd/rts5249.c
> +++ b/drivers/mfd/rts5249.c
> @@ -116,11 +116,9 @@ static int rts5249_extra_init_hw(struct rtsx_pcr *pcr)
>  	/* Configure driving */
>  	rts5249_fill_driving(pcr, OUTPUT_3V3);
>  	if (pcr->flags & PCR_REVERSE_SOCKET)
> -		rtsx_pci_add_cmd(pcr, WRITE_REG_CMD,
> -				AUTOLOAD_CFG_BASE + 3, 0xB0, 0xB0);
> +		rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PETXCFG, 0xB0, 0xB0);
>  	else
> -		rtsx_pci_add_cmd(pcr, WRITE_REG_CMD,
> -				AUTOLOAD_CFG_BASE + 3, 0xB0, 0x80);
> +		rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PETXCFG, 0xB0, 0x80);
>  	rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PM_CTRL3, 0x10, 0x00);
>  
>  	return rtsx_pci_send_cmd(pcr, 100);
> diff --git a/include/linux/mfd/rtsx_pci.h b/include/linux/mfd/rtsx_pci.h
> index a680427..80baa10 100644
> --- a/include/linux/mfd/rtsx_pci.h
> +++ b/include/linux/mfd/rtsx_pci.h
> @@ -572,7 +572,6 @@
>  #define MSGTXDATA2			0xFE46
>  #define MSGTXDATA3			0xFE47
>  #define MSGTXCTL			0xFE48
> -#define PETXCFG				0xFE49
>  #define LTR_CTL				0xFE4A
>  #define OBFF_CFG			0xFE4C
>  
> @@ -606,6 +605,7 @@
>  #define DUMMY_REG_RESET_0		0xFE90
>  
>  #define AUTOLOAD_CFG_BASE		0xFF00
> +#define PETXCFG				0xFF03
>  
>  #define PM_CTRL1			0xFF44
>  #define PM_CTRL2			0xFF45

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 05/10] mfd: rtsx: update driving settings
  2015-01-15 11:19 ` [PATCH 05/10] mfd: rtsx: update driving settings micky_ching
@ 2015-01-18 12:32   ` Lee Jones
  0 siblings, 0 replies; 36+ messages in thread
From: Lee Jones @ 2015-01-18 12:32 UTC (permalink / raw)
  To: micky_ching; +Cc: sameo, devel, linux-kernel, gregkh, rogerable, wei_wang

On Thu, 15 Jan 2015, micky_ching@realsil.com.cn wrote:

> From: Micky Ching <micky_ching@realsil.com.cn>
> 
> update card drive settings, This setting can be used for rts5249
> rts524A and rts525A.
> 
> Signed-off-by: Micky Ching <micky_ching@realsil.com.cn>
> ---
>  drivers/mfd/rts5249.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)

There is no way for me to know if this is correct or not.

Code looks fine though, so:

Acked-by: Lee Jones <lee.jones@linaro.org>

> diff --git a/drivers/mfd/rts5249.c b/drivers/mfd/rts5249.c
> index 225ad55..2fe2854 100644
> --- a/drivers/mfd/rts5249.c
> +++ b/drivers/mfd/rts5249.c
> @@ -36,16 +36,16 @@ static u8 rts5249_get_ic_version(struct rtsx_pcr *pcr)
>  static void rts5249_fill_driving(struct rtsx_pcr *pcr, u8 voltage)
>  {
>  	u8 driving_3v3[4][3] = {
> -		{0x11, 0x11, 0x11},
> +		{0x11, 0x11, 0x18},
>  		{0x55, 0x55, 0x5C},
> -		{0x99, 0x99, 0x92},
> -		{0x99, 0x99, 0x92},
> +		{0xFF, 0xFF, 0xFF},
> +		{0x96, 0x96, 0x96},
>  	};
>  	u8 driving_1v8[4][3] = {
> +		{0xC4, 0xC4, 0xC4},
>  		{0x3C, 0x3C, 0x3C},
> -		{0xB3, 0xB3, 0xB3},
>  		{0xFE, 0xFE, 0xFE},
> -		{0xC4, 0xC4, 0xC4},
> +		{0xB3, 0xB3, 0xB3},
>  	};
>  	u8 (*driving)[3], drive_sel;
>  
> @@ -341,7 +341,7 @@ void rts5249_init_params(struct rtsx_pcr *pcr)
>  
>  	pcr->flags = 0;
>  	pcr->card_drive_sel = RTSX_CARD_DRIVE_DEFAULT;
> -	pcr->sd30_drive_sel_1v8 = CFG_DRIVER_TYPE_C;
> +	pcr->sd30_drive_sel_1v8 = CFG_DRIVER_TYPE_B;
>  	pcr->sd30_drive_sel_3v3 = CFG_DRIVER_TYPE_B;
>  	pcr->aspm_en = ASPM_L1_EN;
>  	pcr->tx_initial_phase = SET_CLOCK_PHASE(1, 29, 16);

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 03/10] mfd: rtsx: add debug info when access register failed
  2015-01-15 11:19 ` [PATCH 03/10] mfd: rtsx: add debug info when access register failed micky_ching
@ 2015-01-18 12:35   ` Lee Jones
  0 siblings, 0 replies; 36+ messages in thread
From: Lee Jones @ 2015-01-18 12:35 UTC (permalink / raw)
  To: micky_ching; +Cc: sameo, devel, linux-kernel, gregkh, rogerable, wei_wang

On Thu, 15 Jan 2015, micky_ching@realsil.com.cn wrote:

> From: Micky Ching <micky_ching@realsil.com.cn>
> 
> Add debug info when access register failed, this is useful for
> debug.

Pull the creation of the macro into another patch.  I'm happy to apply
that, but I don't really want dbg prints scattered everywhere.  Feel
free to keep this patch on a branch and apply it when you need it, but
I'm not keen on having them in Mainline.

> Signed-off-by: Micky Ching <micky_ching@realsil.com.cn>
> ---
>  drivers/mfd/rtsx_pcr.c       | 22 +++++++++++++++++-----
>  include/linux/mfd/rtsx_pci.h |  2 ++
>  2 files changed, 19 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/mfd/rtsx_pcr.c b/drivers/mfd/rtsx_pcr.c
> index 30f7ca8..92f5a41 100644
> --- a/drivers/mfd/rtsx_pcr.c
> +++ b/drivers/mfd/rtsx_pcr.c
> @@ -96,12 +96,16 @@ int rtsx_pci_write_register(struct rtsx_pcr *pcr, u16 addr, u8 mask, u8 data)
>  	for (i = 0; i < MAX_RW_REG_CNT; i++) {
>  		val = rtsx_pci_readl(pcr, RTSX_HAIMR);
>  		if ((val & HAIMR_TRANS_END) == 0) {
> -			if (data != (u8)val)
> +			if (data != (u8)val) {
> +				pcr_dbg(pcr, "write register 0x%02x failed\n",
> +					addr);
>  				return -EIO;
> +			}
>  			return 0;
>  		}
>  	}
>  
> +	pcr_dbg(pcr, "write register 0x%02x failed\n", addr);
>  	return -ETIMEDOUT;
>  }
>  EXPORT_SYMBOL_GPL(rtsx_pci_write_register);
> @@ -120,8 +124,10 @@ int rtsx_pci_read_register(struct rtsx_pcr *pcr, u16 addr, u8 *data)
>  			break;
>  	}
>  
> -	if (i >= MAX_RW_REG_CNT)
> +	if (i >= MAX_RW_REG_CNT) {
> +		pcr_dbg(pcr, "read register 0x%02x failed\n", addr);
>  		return -ETIMEDOUT;
> +	}
>  
>  	if (data)
>  		*data = (u8)(val & 0xFF);
> @@ -157,8 +163,10 @@ int rtsx_pci_write_phy_register(struct rtsx_pcr *pcr, u8 addr, u16 val)
>  		}
>  	}
>  
> -	if (!finished)
> +	if (!finished) {
> +		pcr_dbg(pcr, "write phy 0x%x failed\n", addr);
>  		return -ETIMEDOUT;
> +	}
>  
>  	return 0;
>  }
> @@ -190,8 +198,10 @@ int rtsx_pci_read_phy_register(struct rtsx_pcr *pcr, u8 addr, u16 *val)
>  		}
>  	}
>  
> -	if (!finished)
> +	if (!finished) {
> +		pcr_dbg(pcr, "read phy 0x%x failed\n", addr);
>  		return -ETIMEDOUT;
> +	}
>  
>  	rtsx_pci_init_cmd(pcr);
>  
> @@ -199,8 +209,10 @@ int rtsx_pci_read_phy_register(struct rtsx_pcr *pcr, u8 addr, u16 *val)
>  	rtsx_pci_add_cmd(pcr, READ_REG_CMD, PHYDATA1, 0, 0);
>  
>  	err = rtsx_pci_send_cmd(pcr, 100);
> -	if (err < 0)
> +	if (err < 0) {
> +		pcr_dbg(pcr, "read phy 0x%x failed\n", addr);
>  		return err;
> +	}
>  
>  	ptr = rtsx_pci_get_cmd_data(pcr);
>  	data = ((u16)ptr[1] << 8) | ptr[0];
> diff --git a/include/linux/mfd/rtsx_pci.h b/include/linux/mfd/rtsx_pci.h
> index e81f2bb..a680427 100644
> --- a/include/linux/mfd/rtsx_pci.h
> +++ b/include/linux/mfd/rtsx_pci.h
> @@ -838,6 +838,8 @@ struct rtsx_pcr {
>  #define PCI_VID(pcr)			((pcr)->pci->vendor)
>  #define PCI_PID(pcr)			((pcr)->pci->device)
>  
> +#define pcr_dbg(pcr, fmt, arg...)			\
> +	dev_dbg(&(pcr)->pci->dev, fmt, ##arg)
>  #define SDR104_PHASE(val)		((val) & 0xFF)
>  #define SDR50_PHASE(val)		(((val) >> 8) & 0xFF)
>  #define DDR50_PHASE(val)		(((val) >> 16) & 0xFF)

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 02/10] mfd: rtsx: place register address and values togather
  2015-01-15 11:18 ` [PATCH 02/10] mfd: rtsx: place register address and values togather micky_ching
@ 2015-01-18 12:35   ` Lee Jones
  0 siblings, 0 replies; 36+ messages in thread
From: Lee Jones @ 2015-01-18 12:35 UTC (permalink / raw)
  To: micky_ching; +Cc: sameo, devel, linux-kernel, gregkh, rogerable, wei_wang

On Thu, 15 Jan 2015, micky_ching@realsil.com.cn wrote:

> From: Micky Ching <micky_ching@realsil.com.cn>
> 
> It is more readable to place register address and values define
> togather. The values define add two leading space indicate belong
> to the register address defined above.
> 
> Signed-off-by: Micky Ching <micky_ching@realsil.com.cn>
> ---
>  include/linux/mfd/rtsx_pci.h | 836 +++++++++++++++++++------------------------
>  1 file changed, 369 insertions(+), 467 deletions(-)

As you wish.

Acked-by: Lee Jones <lee.jones@linaro.org>

> diff --git a/include/linux/mfd/rtsx_pci.h b/include/linux/mfd/rtsx_pci.h
> index a9c2a14..e81f2bb 100644
> --- a/include/linux/mfd/rtsx_pci.h
> +++ b/include/linux/mfd/rtsx_pci.h
> @@ -28,74 +28,72 @@
>  
>  #define MAX_RW_REG_CNT			1024
>  
> -/* PCI Operation Register Address */
>  #define RTSX_HCBAR			0x00
>  #define RTSX_HCBCTLR			0x04
> +#define   STOP_CMD			(0x01 << 28)
> +#define   READ_REG_CMD			0
> +#define   WRITE_REG_CMD			1
> +#define   CHECK_REG_CMD			2
> +
>  #define RTSX_HDBAR			0x08
> +#define   SG_INT			0x04
> +#define   SG_END			0x02
> +#define   SG_VALID			0x01
> +#define   SG_NO_OP			0x00
> +#define   SG_TRANS_DATA			(0x02 << 4)
> +#define   SG_LINK_DESC			(0x03 << 4)
>  #define RTSX_HDBCTLR			0x0C
> +#define   SDMA_MODE			0x00
> +#define   ADMA_MODE			(0x02 << 26)
> +#define   STOP_DMA			(0x01 << 28)
> +#define   TRIG_DMA			(0x01 << 31)
> +
>  #define RTSX_HAIMR			0x10
> -#define RTSX_BIPR			0x14
> -#define RTSX_BIER			0x18
> +#define   HAIMR_TRANS_START		(0x01 << 31)
> +#define   HAIMR_READ			0x00
> +#define   HAIMR_WRITE			(0x01 << 30)
> +#define   HAIMR_READ_START		(HAIMR_TRANS_START | HAIMR_READ)
> +#define   HAIMR_WRITE_START		(HAIMR_TRANS_START | HAIMR_WRITE)
> +#define   HAIMR_TRANS_END			(HAIMR_TRANS_START)
>  
> -/* Host command buffer control register */
> -#define STOP_CMD			(0x01 << 28)
> -
> -/* Host data buffer control register */
> -#define SDMA_MODE			0x00
> -#define ADMA_MODE			(0x02 << 26)
> -#define STOP_DMA			(0x01 << 28)
> -#define TRIG_DMA			(0x01 << 31)
> -
> -/* Host access internal memory register */
> -#define HAIMR_TRANS_START		(0x01 << 31)
> -#define HAIMR_READ			0x00
> -#define HAIMR_WRITE			(0x01 << 30)
> -#define HAIMR_READ_START		(HAIMR_TRANS_START | HAIMR_READ)
> -#define HAIMR_WRITE_START		(HAIMR_TRANS_START | HAIMR_WRITE)
> -#define HAIMR_TRANS_END			(HAIMR_TRANS_START)
> -
> -/* Bus interrupt pending register */
> -#define CMD_DONE_INT			(1 << 31)
> -#define DATA_DONE_INT			(1 << 30)
> -#define TRANS_OK_INT			(1 << 29)
> -#define TRANS_FAIL_INT			(1 << 28)
> -#define XD_INT				(1 << 27)
> -#define MS_INT				(1 << 26)
> -#define SD_INT				(1 << 25)
> -#define GPIO0_INT			(1 << 24)
> -#define OC_INT				(1 << 23)
> -#define SD_WRITE_PROTECT		(1 << 19)
> -#define XD_EXIST			(1 << 18)
> -#define MS_EXIST			(1 << 17)
> -#define SD_EXIST			(1 << 16)
> -#define DELINK_INT			GPIO0_INT
> -#define MS_OC_INT			(1 << 23)
> -#define SD_OC_INT			(1 << 22)
> +#define RTSX_BIPR			0x14
> +#define   CMD_DONE_INT			(1 << 31)
> +#define   DATA_DONE_INT			(1 << 30)
> +#define   TRANS_OK_INT			(1 << 29)
> +#define   TRANS_FAIL_INT		(1 << 28)
> +#define   XD_INT			(1 << 27)
> +#define   MS_INT			(1 << 26)
> +#define   SD_INT			(1 << 25)
> +#define   GPIO0_INT			(1 << 24)
> +#define   OC_INT			(1 << 23)
> +#define   SD_WRITE_PROTECT		(1 << 19)
> +#define   XD_EXIST			(1 << 18)
> +#define   MS_EXIST			(1 << 17)
> +#define   SD_EXIST			(1 << 16)
> +#define   DELINK_INT			GPIO0_INT
> +#define   MS_OC_INT			(1 << 23)
> +#define   SD_OC_INT			(1 << 22)
>  
>  #define CARD_INT		(XD_INT | MS_INT | SD_INT)
>  #define NEED_COMPLETE_INT	(DATA_DONE_INT | TRANS_OK_INT | TRANS_FAIL_INT)
>  #define RTSX_INT		(CMD_DONE_INT | NEED_COMPLETE_INT | \
>  					CARD_INT | GPIO0_INT | OC_INT)
> -
>  #define CARD_EXIST		(XD_EXIST | MS_EXIST | SD_EXIST)
>  
> -/* Bus interrupt enable register */
> -#define CMD_DONE_INT_EN		(1 << 31)
> -#define DATA_DONE_INT_EN	(1 << 30)
> -#define TRANS_OK_INT_EN		(1 << 29)
> -#define TRANS_FAIL_INT_EN	(1 << 28)
> -#define XD_INT_EN		(1 << 27)
> -#define MS_INT_EN		(1 << 26)
> -#define SD_INT_EN		(1 << 25)
> -#define GPIO0_INT_EN		(1 << 24)
> -#define OC_INT_EN		(1 << 23)
> -#define DELINK_INT_EN		GPIO0_INT_EN
> -#define MS_OC_INT_EN		(1 << 23)
> -#define SD_OC_INT_EN		(1 << 22)
> -
> -#define READ_REG_CMD		0
> -#define WRITE_REG_CMD		1
> -#define CHECK_REG_CMD		2
> +#define RTSX_BIER			0x18
> +#define   CMD_DONE_INT_EN		(1 << 31)
> +#define   DATA_DONE_INT_EN		(1 << 30)
> +#define   TRANS_OK_INT_EN		(1 << 29)
> +#define   TRANS_FAIL_INT_EN		(1 << 28)
> +#define   XD_INT_EN			(1 << 27)
> +#define   MS_INT_EN			(1 << 26)
> +#define   SD_INT_EN			(1 << 25)
> +#define   GPIO0_INT_EN			(1 << 24)
> +#define   OC_INT_EN			(1 << 23)
> +#define   DELINK_INT_EN			GPIO0_INT_EN
> +#define   MS_OC_INT_EN			(1 << 23)
> +#define   SD_OC_INT_EN			(1 << 22)
> +
>  
>  /*
>   * macros for easy use
> @@ -125,423 +123,68 @@
>  #define rtsx_pci_write_config_dword(pcr, where, val) \
>  	pci_write_config_dword((pcr)->pci, where, val)
>  
> -#define STATE_TRANS_NONE	0
> -#define STATE_TRANS_CMD		1
> -#define STATE_TRANS_BUF		2
> -#define STATE_TRANS_SG		3
> -
> -#define TRANS_NOT_READY		0
> -#define TRANS_RESULT_OK		1
> -#define TRANS_RESULT_FAIL	2
> -#define TRANS_NO_DEVICE		3
> -
> -#define RTSX_RESV_BUF_LEN	4096
> -#define HOST_CMDS_BUF_LEN	1024
> -#define HOST_SG_TBL_BUF_LEN	(RTSX_RESV_BUF_LEN - HOST_CMDS_BUF_LEN)
> -#define HOST_SG_TBL_ITEMS	(HOST_SG_TBL_BUF_LEN / 8)
> -#define MAX_SG_ITEM_LEN		0x80000
> -
> -#define HOST_TO_DEVICE		0
> -#define DEVICE_TO_HOST		1
> -
> -#define RTSX_PHASE_MAX		32
> -#define RX_TUNING_CNT		3
> -
> -/* SG descriptor */
> -#define SG_INT			0x04
> -#define SG_END			0x02
> -#define SG_VALID		0x01
> -
> -#define SG_NO_OP		0x00
> -#define SG_TRANS_DATA		(0x02 << 4)
> -#define SG_LINK_DESC		(0x03 << 4)
> -
> -/* Output voltage */
> -#define OUTPUT_3V3		0
> -#define OUTPUT_1V8		1
> -
> -/* Card Clock Enable Register */
> -#define SD_CLK_EN			0x04
> -#define MS_CLK_EN			0x08
> -
> -/* Card Select Register */
> -#define SD_MOD_SEL			2
> -#define MS_MOD_SEL			3
> -
> -/* Card Output Enable Register */
> -#define SD_OUTPUT_EN			0x04
> -#define MS_OUTPUT_EN			0x08
> -
> -/* CARD_SHARE_MODE */
> -#define CARD_SHARE_MASK			0x0F
> -#define CARD_SHARE_MULTI_LUN		0x00
> -#define CARD_SHARE_NORMAL		0x00
> -#define CARD_SHARE_48_SD		0x04
> -#define CARD_SHARE_48_MS		0x08
> -/* CARD_SHARE_MODE for barossa */
> -#define CARD_SHARE_BAROSSA_SD		0x01
> -#define CARD_SHARE_BAROSSA_MS		0x02
> -
> -/* CARD_DRIVE_SEL */
> -#define MS_DRIVE_8mA			(0x01 << 6)
> -#define MMC_DRIVE_8mA			(0x01 << 4)
> -#define XD_DRIVE_8mA			(0x01 << 2)
> -#define GPIO_DRIVE_8mA			0x01
> -#define RTS5209_CARD_DRIVE_DEFAULT	(MS_DRIVE_8mA | MMC_DRIVE_8mA |\
> -						XD_DRIVE_8mA | GPIO_DRIVE_8mA)
> -#define RTL8411_CARD_DRIVE_DEFAULT	(MS_DRIVE_8mA | MMC_DRIVE_8mA |\
> -						XD_DRIVE_8mA)
> -#define RTSX_CARD_DRIVE_DEFAULT		(MS_DRIVE_8mA | GPIO_DRIVE_8mA)
> +#define STATE_TRANS_NONE		0
> +#define STATE_TRANS_CMD			1
> +#define STATE_TRANS_BUF			2
> +#define STATE_TRANS_SG			3
>  
> -/* SD30_DRIVE_SEL */
> -#define DRIVER_TYPE_A			0x05
> -#define DRIVER_TYPE_B			0x03
> -#define DRIVER_TYPE_C			0x02
> -#define DRIVER_TYPE_D			0x01
> -#define CFG_DRIVER_TYPE_A		0x02
> -#define CFG_DRIVER_TYPE_B		0x03
> -#define CFG_DRIVER_TYPE_C		0x01
> -#define CFG_DRIVER_TYPE_D		0x00
> -
> -/* FPDCTL */
> -#define SSC_POWER_DOWN			0x01
> -#define SD_OC_POWER_DOWN		0x02
> -#define ALL_POWER_DOWN			0x07
> -#define OC_POWER_DOWN			0x06
> -
> -/* CLK_CTL */
> -#define CHANGE_CLK			0x01
> -
> -/* LDO_CTL */
> -#define BPP_ASIC_1V7			0x00
> -#define BPP_ASIC_1V8			0x01
> -#define BPP_ASIC_1V9			0x02
> -#define BPP_ASIC_2V0			0x03
> -#define BPP_ASIC_2V7			0x04
> -#define BPP_ASIC_2V8			0x05
> -#define BPP_ASIC_3V2			0x06
> -#define BPP_ASIC_3V3			0x07
> -#define BPP_REG_TUNED18			0x07
> -#define BPP_TUNED18_SHIFT_8402		5
> -#define BPP_TUNED18_SHIFT_8411		4
> -#define BPP_PAD_MASK			0x04
> -#define BPP_PAD_3V3			0x04
> -#define BPP_PAD_1V8			0x00
> -#define BPP_LDO_POWB			0x03
> -#define BPP_LDO_ON			0x00
> -#define BPP_LDO_SUSPEND			0x02
> -#define BPP_LDO_OFF			0x03
> -
> -/* CD_PAD_CTL */
> -#define CD_DISABLE_MASK			0x07
> -#define MS_CD_DISABLE			0x04
> -#define SD_CD_DISABLE			0x02
> -#define XD_CD_DISABLE			0x01
> -#define CD_DISABLE			0x07
> -#define CD_ENABLE			0x00
> -#define MS_CD_EN_ONLY			0x03
> -#define SD_CD_EN_ONLY			0x05
> -#define XD_CD_EN_ONLY			0x06
> -#define FORCE_CD_LOW_MASK		0x38
> -#define FORCE_CD_XD_LOW			0x08
> -#define FORCE_CD_SD_LOW			0x10
> -#define FORCE_CD_MS_LOW			0x20
> -#define CD_AUTO_DISABLE			0x40
> -
> -/* SD_STAT1 */
> -#define SD_CRC7_ERR			0x80
> -#define SD_CRC16_ERR			0x40
> -#define SD_CRC_WRITE_ERR		0x20
> -#define SD_CRC_WRITE_ERR_MASK		0x1C
> -#define GET_CRC_TIME_OUT		0x02
> -#define SD_TUNING_COMPARE_ERR		0x01
> -
> -/* SD_STAT2 */
> -#define SD_RSP_80CLK_TIMEOUT		0x01
> -
> -/* SD_BUS_STAT */
> -#define SD_CLK_TOGGLE_EN		0x80
> -#define SD_CLK_FORCE_STOP	        0x40
> -#define SD_DAT3_STATUS		        0x10
> -#define SD_DAT2_STATUS		        0x08
> -#define SD_DAT1_STATUS		        0x04
> -#define SD_DAT0_STATUS		        0x02
> -#define SD_CMD_STATUS			0x01
> -
> -/* SD_PAD_CTL */
> -#define SD_IO_USING_1V8		        0x80
> -#define SD_IO_USING_3V3		        0x7F
> -#define TYPE_A_DRIVING		        0x00
> -#define TYPE_B_DRIVING			0x01
> -#define TYPE_C_DRIVING			0x02
> -#define TYPE_D_DRIVING		        0x03
> -
> -/* SD_SAMPLE_POINT_CTL */
> -#define DDR_FIX_RX_DAT			0x00
> -#define DDR_VAR_RX_DAT			0x80
> -#define DDR_FIX_RX_DAT_EDGE		0x00
> -#define DDR_FIX_RX_DAT_14_DELAY		0x40
> -#define DDR_FIX_RX_CMD			0x00
> -#define DDR_VAR_RX_CMD			0x20
> -#define DDR_FIX_RX_CMD_POS_EDGE		0x00
> -#define DDR_FIX_RX_CMD_14_DELAY		0x10
> -#define SD20_RX_POS_EDGE		0x00
> -#define SD20_RX_14_DELAY		0x08
> -#define SD20_RX_SEL_MASK		0x08
> +#define TRANS_NOT_READY			0
> +#define TRANS_RESULT_OK			1
> +#define TRANS_RESULT_FAIL		2
> +#define TRANS_NO_DEVICE			3
>  
> -/* SD_PUSH_POINT_CTL */
> -#define DDR_FIX_TX_CMD_DAT		0x00
> -#define DDR_VAR_TX_CMD_DAT		0x80
> -#define DDR_FIX_TX_DAT_14_TSU		0x00
> -#define DDR_FIX_TX_DAT_12_TSU		0x40
> -#define DDR_FIX_TX_CMD_NEG_EDGE		0x00
> -#define DDR_FIX_TX_CMD_14_AHEAD		0x20
> -#define SD20_TX_NEG_EDGE		0x00
> -#define SD20_TX_14_AHEAD		0x10
> -#define SD20_TX_SEL_MASK		0x10
> -#define DDR_VAR_SDCLK_POL_SWAP		0x01
> -
> -/* SD_TRANSFER */
> -#define SD_TRANSFER_START		0x80
> -#define SD_TRANSFER_END			0x40
> -#define SD_STAT_IDLE			0x20
> -#define SD_TRANSFER_ERR			0x10
> -/* SD Transfer Mode definition */
> -#define SD_TM_NORMAL_WRITE		0x00
> -#define SD_TM_AUTO_WRITE_3		0x01
> -#define SD_TM_AUTO_WRITE_4		0x02
> -#define SD_TM_AUTO_READ_3		0x05
> -#define SD_TM_AUTO_READ_4		0x06
> -#define SD_TM_CMD_RSP			0x08
> -#define SD_TM_AUTO_WRITE_1		0x09
> -#define SD_TM_AUTO_WRITE_2		0x0A
> -#define SD_TM_NORMAL_READ		0x0C
> -#define SD_TM_AUTO_READ_1		0x0D
> -#define SD_TM_AUTO_READ_2		0x0E
> -#define SD_TM_AUTO_TUNING		0x0F
> -
> -/* SD_VPTX_CTL / SD_VPRX_CTL */
> -#define PHASE_CHANGE			0x80
> -#define PHASE_NOT_RESET			0x40
> -
> -/* SD_DCMPS_TX_CTL / SD_DCMPS_RX_CTL */
> -#define DCMPS_CHANGE			0x80
> -#define DCMPS_CHANGE_DONE		0x40
> -#define DCMPS_ERROR			0x20
> -#define DCMPS_CURRENT_PHASE		0x1F
> -
> -/* SD Configure 1 Register */
> -#define SD_CLK_DIVIDE_0			0x00
> -#define SD_CLK_DIVIDE_256		0xC0
> -#define SD_CLK_DIVIDE_128		0x80
> -#define SD_BUS_WIDTH_1BIT		0x00
> -#define SD_BUS_WIDTH_4BIT		0x01
> -#define SD_BUS_WIDTH_8BIT		0x02
> -#define SD_ASYNC_FIFO_NOT_RST		0x10
> -#define SD_20_MODE			0x00
> -#define SD_DDR_MODE			0x04
> -#define SD_30_MODE			0x08
> -
> -#define SD_CLK_DIVIDE_MASK		0xC0
> -
> -/* SD_CMD_STATE */
> -#define SD_CMD_IDLE			0x80
> -
> -/* SD_DATA_STATE */
> -#define SD_DATA_IDLE			0x80
> -
> -/* DCM_DRP_CTL */
> -#define DCM_RESET			0x08
> -#define DCM_LOCKED			0x04
> -#define DCM_208M			0x00
> -#define DCM_TX			        0x01
> -#define DCM_RX			        0x02
> -
> -/* DCM_DRP_TRIG */
> -#define DRP_START			0x80
> -#define DRP_DONE			0x40
> -
> -/* DCM_DRP_CFG */
> -#define DRP_WRITE			0x80
> -#define DRP_READ			0x00
> -#define DCM_WRITE_ADDRESS_50		0x50
> -#define DCM_WRITE_ADDRESS_51		0x51
> -#define DCM_READ_ADDRESS_00		0x00
> -#define DCM_READ_ADDRESS_51		0x51
> -
> -/* IRQSTAT0 */
> -#define DMA_DONE_INT			0x80
> -#define SUSPEND_INT			0x40
> -#define LINK_RDY_INT			0x20
> -#define LINK_DOWN_INT			0x10
> -
> -/* DMACTL */
> -#define DMA_RST				0x80
> -#define DMA_BUSY			0x04
> -#define DMA_DIR_TO_CARD			0x00
> -#define DMA_DIR_FROM_CARD		0x02
> -#define DMA_EN				0x01
> -#define DMA_128				(0 << 4)
> -#define DMA_256				(1 << 4)
> -#define DMA_512				(2 << 4)
> -#define DMA_1024			(3 << 4)
> -#define DMA_PACK_SIZE_MASK		0x30
> -
> -/* SSC_CTL1 */
> -#define SSC_RSTB			0x80
> -#define SSC_8X_EN			0x40
> -#define SSC_FIX_FRAC			0x20
> -#define SSC_SEL_1M			0x00
> -#define SSC_SEL_2M			0x08
> -#define SSC_SEL_4M			0x10
> -#define SSC_SEL_8M			0x18
> -
> -/* SSC_CTL2 */
> -#define SSC_DEPTH_MASK			0x07
> -#define SSC_DEPTH_DISALBE		0x00
> -#define SSC_DEPTH_4M			0x01
> -#define SSC_DEPTH_2M			0x02
> -#define SSC_DEPTH_1M			0x03
> -#define SSC_DEPTH_500K			0x04
> -#define SSC_DEPTH_250K			0x05
> -
> -/* System Clock Control Register */
> -#define CLK_LOW_FREQ			0x01
> -
> -/* System Clock Divider Register */
> -#define CLK_DIV_1			0x01
> -#define CLK_DIV_2			0x02
> -#define CLK_DIV_4			0x03
> -#define CLK_DIV_8			0x04
> -
> -/* MS_CFG */
> -#define SAMPLE_TIME_RISING		0x00
> -#define SAMPLE_TIME_FALLING		0x80
> -#define PUSH_TIME_DEFAULT		0x00
> -#define PUSH_TIME_ODD			0x40
> -#define NO_EXTEND_TOGGLE		0x00
> -#define EXTEND_TOGGLE_CHK		0x20
> -#define MS_BUS_WIDTH_1			0x00
> -#define MS_BUS_WIDTH_4			0x10
> -#define MS_BUS_WIDTH_8			0x18
> -#define MS_2K_SECTOR_MODE		0x04
> -#define MS_512_SECTOR_MODE		0x00
> -#define MS_TOGGLE_TIMEOUT_EN		0x00
> -#define MS_TOGGLE_TIMEOUT_DISEN		0x01
> -#define MS_NO_CHECK_INT			0x02
> +#define RTSX_RESV_BUF_LEN		4096
> +#define HOST_CMDS_BUF_LEN		1024
> +#define HOST_SG_TBL_BUF_LEN		(RTSX_RESV_BUF_LEN - HOST_CMDS_BUF_LEN)
> +#define HOST_SG_TBL_ITEMS		(HOST_SG_TBL_BUF_LEN / 8)
> +#define MAX_SG_ITEM_LEN			0x80000
> +#define HOST_TO_DEVICE			0
> +#define DEVICE_TO_HOST			1
> +
> +#define OUTPUT_3V3			0
> +#define OUTPUT_1V8			1
>  
> -/* MS_TRANS_CFG */
> -#define WAIT_INT			0x80
> -#define NO_WAIT_INT			0x00
> -#define NO_AUTO_READ_INT_REG		0x00
> -#define AUTO_READ_INT_REG		0x40
> -#define MS_CRC16_ERR			0x20
> -#define MS_RDY_TIMEOUT			0x10
> -#define MS_INT_CMDNK			0x08
> -#define MS_INT_BREQ			0x04
> -#define MS_INT_ERR			0x02
> -#define MS_INT_CED			0x01
> -
> -/* MS_TRANSFER */
> -#define MS_TRANSFER_START		0x80
> -#define MS_TRANSFER_END			0x40
> -#define MS_TRANSFER_ERR			0x20
> -#define MS_BS_STATE			0x10
> -#define MS_TM_READ_BYTES		0x00
> -#define MS_TM_NORMAL_READ		0x01
> -#define MS_TM_WRITE_BYTES		0x04
> -#define MS_TM_NORMAL_WRITE		0x05
> -#define MS_TM_AUTO_READ			0x08
> -#define MS_TM_AUTO_WRITE		0x0C
> -
> -/* SD Configure 2 Register */
> -#define SD_CALCULATE_CRC7		0x00
> -#define SD_NO_CALCULATE_CRC7		0x80
> -#define SD_CHECK_CRC16			0x00
> -#define SD_NO_CHECK_CRC16		0x40
> -#define SD_NO_CHECK_WAIT_CRC_TO		0x20
> -#define SD_WAIT_BUSY_END		0x08
> -#define SD_NO_WAIT_BUSY_END		0x00
> -#define SD_CHECK_CRC7			0x00
> -#define SD_NO_CHECK_CRC7		0x04
> -#define SD_RSP_LEN_0			0x00
> -#define SD_RSP_LEN_6			0x01
> -#define SD_RSP_LEN_17			0x02
> -/* SD/MMC Response Type Definition */
> -#define SD_RSP_TYPE_R0			0x04
> -#define SD_RSP_TYPE_R1			0x01
> -#define SD_RSP_TYPE_R1b			0x09
> -#define SD_RSP_TYPE_R2			0x02
> -#define SD_RSP_TYPE_R3			0x05
> -#define SD_RSP_TYPE_R4			0x05
> -#define SD_RSP_TYPE_R5			0x01
> -#define SD_RSP_TYPE_R6			0x01
> -#define SD_RSP_TYPE_R7			0x01
> -
> -/* SD_CONFIGURE3 */
> -#define SD_RSP_80CLK_TIMEOUT_EN		0x01
> -
> -/* Card Transfer Reset Register */
> -#define SPI_STOP			0x01
> -#define XD_STOP				0x02
> -#define SD_STOP				0x04
> -#define MS_STOP				0x08
> -#define SPI_CLR_ERR			0x10
> -#define XD_CLR_ERR			0x20
> -#define SD_CLR_ERR			0x40
> -#define MS_CLR_ERR			0x80
> -
> -/* Card Data Source Register */
> -#define PINGPONG_BUFFER			0x01
> -#define RING_BUFFER			0x00
> -
> -/* Card Power Control Register */
> -#define PMOS_STRG_MASK			0x10
> -#define PMOS_STRG_800mA			0x10
> -#define PMOS_STRG_400mA			0x00
> -#define SD_POWER_OFF			0x03
> -#define SD_PARTIAL_POWER_ON		0x01
> -#define SD_POWER_ON			0x00
> -#define SD_POWER_MASK			0x03
> -#define MS_POWER_OFF			0x0C
> -#define MS_PARTIAL_POWER_ON		0x04
> -#define MS_POWER_ON			0x00
> -#define MS_POWER_MASK			0x0C
> -#define BPP_POWER_OFF			0x0F
> -#define BPP_POWER_5_PERCENT_ON		0x0E
> -#define BPP_POWER_10_PERCENT_ON		0x0C
> -#define BPP_POWER_15_PERCENT_ON		0x08
> -#define BPP_POWER_ON			0x00
> -#define BPP_POWER_MASK			0x0F
> -#define SD_VCC_PARTIAL_POWER_ON		0x02
> -#define SD_VCC_POWER_ON			0x00
> -
> -/* PWR_GATE_CTRL */
> -#define PWR_GATE_EN			0x01
> -#define LDO3318_PWR_MASK		0x06
> -#define LDO_ON				0x00
> -#define LDO_SUSPEND			0x04
> -#define LDO_OFF				0x06
> -
> -/* CARD_CLK_SOURCE */
> -#define CRC_FIX_CLK			(0x00 << 0)
> -#define CRC_VAR_CLK0			(0x01 << 0)
> -#define CRC_VAR_CLK1			(0x02 << 0)
> -#define SD30_FIX_CLK			(0x00 << 2)
> -#define SD30_VAR_CLK0			(0x01 << 2)
> -#define SD30_VAR_CLK1			(0x02 << 2)
> -#define SAMPLE_FIX_CLK			(0x00 << 4)
> -#define SAMPLE_VAR_CLK0			(0x01 << 4)
> -#define SAMPLE_VAR_CLK1			(0x02 << 4)
> -
> -/* HOST_SLEEP_STATE */
> -#define HOST_ENTER_S1			1
> -#define HOST_ENTER_S3			2
> +#define RTSX_PHASE_MAX			32
> +#define RX_TUNING_CNT			3
>  
>  #define MS_CFG				0xFD40
> +#define   SAMPLE_TIME_RISING		0x00
> +#define   SAMPLE_TIME_FALLING		0x80
> +#define   PUSH_TIME_DEFAULT		0x00
> +#define   PUSH_TIME_ODD			0x40
> +#define   NO_EXTEND_TOGGLE		0x00
> +#define   EXTEND_TOGGLE_CHK		0x20
> +#define   MS_BUS_WIDTH_1		0x00
> +#define   MS_BUS_WIDTH_4		0x10
> +#define   MS_BUS_WIDTH_8		0x18
> +#define   MS_2K_SECTOR_MODE		0x04
> +#define   MS_512_SECTOR_MODE		0x00
> +#define   MS_TOGGLE_TIMEOUT_EN		0x00
> +#define   MS_TOGGLE_TIMEOUT_DISEN	0x01
> +#define MS_NO_CHECK_INT			0x02
>  #define MS_TPC				0xFD41
>  #define MS_TRANS_CFG			0xFD42
> +#define   WAIT_INT			0x80
> +#define   NO_WAIT_INT			0x00
> +#define   NO_AUTO_READ_INT_REG		0x00
> +#define   AUTO_READ_INT_REG		0x40
> +#define   MS_CRC16_ERR			0x20
> +#define   MS_RDY_TIMEOUT		0x10
> +#define   MS_INT_CMDNK			0x08
> +#define   MS_INT_BREQ			0x04
> +#define   MS_INT_ERR			0x02
> +#define   MS_INT_CED			0x01
>  #define MS_TRANSFER			0xFD43
> +#define   MS_TRANSFER_START		0x80
> +#define   MS_TRANSFER_END		0x40
> +#define   MS_TRANSFER_ERR		0x20
> +#define   MS_BS_STATE			0x10
> +#define   MS_TM_READ_BYTES		0x00
> +#define   MS_TM_NORMAL_READ		0x01
> +#define   MS_TM_WRITE_BYTES		0x04
> +#define   MS_TM_NORMAL_WRITE		0x05
> +#define   MS_TM_AUTO_READ		0x08
> +#define   MS_TM_AUTO_WRITE		0x0C
>  #define MS_INT_REG			0xFD44
>  #define MS_BYTE_CNT			0xFD45
>  #define MS_SECTOR_CNT_L			0xFD46
> @@ -549,14 +192,90 @@
>  #define MS_DBUS_H			0xFD48
>  
>  #define SD_CFG1				0xFDA0
> +#define   SD_CLK_DIVIDE_0		0x00
> +#define   SD_CLK_DIVIDE_256		0xC0
> +#define   SD_CLK_DIVIDE_128		0x80
> +#define   SD_BUS_WIDTH_1BIT		0x00
> +#define   SD_BUS_WIDTH_4BIT		0x01
> +#define   SD_BUS_WIDTH_8BIT		0x02
> +#define   SD_ASYNC_FIFO_NOT_RST		0x10
> +#define   SD_20_MODE			0x00
> +#define   SD_DDR_MODE			0x04
> +#define   SD_30_MODE			0x08
> +#define   SD_CLK_DIVIDE_MASK		0xC0
>  #define SD_CFG2				0xFDA1
> +#define   SD_CALCULATE_CRC7		0x00
> +#define   SD_NO_CALCULATE_CRC7		0x80
> +#define   SD_CHECK_CRC16		0x00
> +#define   SD_NO_CHECK_CRC16		0x40
> +#define   SD_NO_CHECK_WAIT_CRC_TO	0x20
> +#define   SD_WAIT_BUSY_END		0x08
> +#define   SD_NO_WAIT_BUSY_END		0x00
> +#define   SD_CHECK_CRC7			0x00
> +#define   SD_NO_CHECK_CRC7		0x04
> +#define   SD_RSP_LEN_0			0x00
> +#define   SD_RSP_LEN_6			0x01
> +#define   SD_RSP_LEN_17			0x02
> +#define   SD_RSP_TYPE_R0		0x04
> +#define   SD_RSP_TYPE_R1		0x01
> +#define   SD_RSP_TYPE_R1b		0x09
> +#define   SD_RSP_TYPE_R2		0x02
> +#define   SD_RSP_TYPE_R3		0x05
> +#define   SD_RSP_TYPE_R4		0x05
> +#define   SD_RSP_TYPE_R5		0x01
> +#define   SD_RSP_TYPE_R6		0x01
> +#define   SD_RSP_TYPE_R7		0x01
>  #define SD_CFG3				0xFDA2
> +#define   SD_RSP_80CLK_TIMEOUT_EN	0x01
> +
>  #define SD_STAT1			0xFDA3
> +#define   SD_CRC7_ERR			0x80
> +#define   SD_CRC16_ERR			0x40
> +#define   SD_CRC_WRITE_ERR		0x20
> +#define   SD_CRC_WRITE_ERR_MASK		0x1C
> +#define   GET_CRC_TIME_OUT		0x02
> +#define   SD_TUNING_COMPARE_ERR		0x01
>  #define SD_STAT2			0xFDA4
> +#define   SD_RSP_80CLK_TIMEOUT		0x01
> +
>  #define SD_BUS_STAT			0xFDA5
> +#define   SD_CLK_TOGGLE_EN		0x80
> +#define   SD_CLK_FORCE_STOP		0x40
> +#define   SD_DAT3_STATUS		0x10
> +#define   SD_DAT2_STATUS		0x08
> +#define   SD_DAT1_STATUS		0x04
> +#define   SD_DAT0_STATUS		0x02
> +#define   SD_CMD_STATUS			0x01
>  #define SD_PAD_CTL			0xFDA6
> +#define   SD_IO_USING_1V8		0x80
> +#define   SD_IO_USING_3V3		0x7F
> +#define   TYPE_A_DRIVING		0x00
> +#define   TYPE_B_DRIVING		0x01
> +#define   TYPE_C_DRIVING		0x02
> +#define   TYPE_D_DRIVING		0x03
>  #define SD_SAMPLE_POINT_CTL		0xFDA7
> +#define   DDR_FIX_RX_DAT		0x00
> +#define   DDR_VAR_RX_DAT		0x80
> +#define   DDR_FIX_RX_DAT_EDGE		0x00
> +#define   DDR_FIX_RX_DAT_14_DELAY	0x40
> +#define   DDR_FIX_RX_CMD		0x00
> +#define   DDR_VAR_RX_CMD		0x20
> +#define   DDR_FIX_RX_CMD_POS_EDGE	0x00
> +#define   DDR_FIX_RX_CMD_14_DELAY	0x10
> +#define   SD20_RX_POS_EDGE		0x00
> +#define   SD20_RX_14_DELAY		0x08
> +#define SD20_RX_SEL_MASK		0x08
>  #define SD_PUSH_POINT_CTL		0xFDA8
> +#define   DDR_FIX_TX_CMD_DAT		0x00
> +#define   DDR_VAR_TX_CMD_DAT		0x80
> +#define   DDR_FIX_TX_DAT_14_TSU		0x00
> +#define   DDR_FIX_TX_DAT_12_TSU		0x40
> +#define   DDR_FIX_TX_CMD_NEG_EDGE	0x00
> +#define   DDR_FIX_TX_CMD_14_AHEAD	0x20
> +#define   SD20_TX_NEG_EDGE		0x00
> +#define   SD20_TX_14_AHEAD		0x10
> +#define   SD20_TX_SEL_MASK		0x10
> +#define   DDR_VAR_SDCLK_POL_SWAP	0x01
>  #define SD_CMD0				0xFDA9
>  #define   SD_CMD_START			0x40
>  #define SD_CMD1				0xFDAA
> @@ -569,14 +288,46 @@
>  #define SD_BLOCK_CNT_L			0xFDB1
>  #define SD_BLOCK_CNT_H			0xFDB2
>  #define SD_TRANSFER			0xFDB3
> +#define   SD_TRANSFER_START		0x80
> +#define   SD_TRANSFER_END		0x40
> +#define   SD_STAT_IDLE			0x20
> +#define   SD_TRANSFER_ERR		0x10
> +#define   SD_TM_NORMAL_WRITE		0x00
> +#define   SD_TM_AUTO_WRITE_3		0x01
> +#define   SD_TM_AUTO_WRITE_4		0x02
> +#define   SD_TM_AUTO_READ_3		0x05
> +#define   SD_TM_AUTO_READ_4		0x06
> +#define   SD_TM_CMD_RSP			0x08
> +#define   SD_TM_AUTO_WRITE_1		0x09
> +#define   SD_TM_AUTO_WRITE_2		0x0A
> +#define   SD_TM_NORMAL_READ		0x0C
> +#define   SD_TM_AUTO_READ_1		0x0D
> +#define   SD_TM_AUTO_READ_2		0x0E
> +#define   SD_TM_AUTO_TUNING		0x0F
>  #define SD_CMD_STATE			0xFDB5
> +#define   SD_CMD_IDLE			0x80
> +
>  #define SD_DATA_STATE			0xFDB6
> +#define   SD_DATA_IDLE			0x80
>  
>  #define SRCTL				0xFC13
>  
>  #define DCM_DRP_CTL			0xFC23
> +#define   DCM_RESET			0x08
> +#define   DCM_LOCKED			0x04
> +#define   DCM_208M			0x00
> +#define   DCM_TX			0x01
> +#define   DCM_RX			0x02
>  #define DCM_DRP_TRIG			0xFC24
> +#define   DRP_START			0x80
> +#define   DRP_DONE			0x40
>  #define DCM_DRP_CFG			0xFC25
> +#define   DRP_WRITE			0x80
> +#define   DRP_READ			0x00
> +#define   DCM_WRITE_ADDRESS_50		0x50
> +#define   DCM_WRITE_ADDRESS_51		0x51
> +#define   DCM_READ_ADDRESS_00		0x00
> +#define   DCM_READ_ADDRESS_51		0x51
>  #define DCM_DRP_WR_DATA_L		0xFC26
>  #define DCM_DRP_WR_DATA_H		0xFC27
>  #define DCM_DRP_RD_DATA_L		0xFC28
> @@ -587,42 +338,153 @@
>  #define SD_DCMPS1_CTL			0xFC2D
>  #define SD_VPTX_CTL			SD_VPCLK0_CTL
>  #define SD_VPRX_CTL			SD_VPCLK1_CTL
> +#define   PHASE_CHANGE			0x80
> +#define   PHASE_NOT_RESET		0x40
>  #define SD_DCMPS_TX_CTL			SD_DCMPS0_CTL
>  #define SD_DCMPS_RX_CTL			SD_DCMPS1_CTL
> +#define   DCMPS_CHANGE			0x80
> +#define   DCMPS_CHANGE_DONE		0x40
> +#define   DCMPS_ERROR			0x20
> +#define   DCMPS_CURRENT_PHASE		0x1F
>  #define CARD_CLK_SOURCE			0xFC2E
> -
> +#define   CRC_FIX_CLK			(0x00 << 0)
> +#define   CRC_VAR_CLK0			(0x01 << 0)
> +#define   CRC_VAR_CLK1			(0x02 << 0)
> +#define   SD30_FIX_CLK			(0x00 << 2)
> +#define   SD30_VAR_CLK0			(0x01 << 2)
> +#define   SD30_VAR_CLK1			(0x02 << 2)
> +#define   SAMPLE_FIX_CLK		(0x00 << 4)
> +#define   SAMPLE_VAR_CLK0		(0x01 << 4)
> +#define   SAMPLE_VAR_CLK1		(0x02 << 4)
>  #define CARD_PWR_CTL			0xFD50
> +#define   PMOS_STRG_MASK		0x10
> +#define   PMOS_STRG_800mA		0x10
> +#define   PMOS_STRG_400mA		0x00
> +#define   SD_POWER_OFF			0x03
> +#define   SD_PARTIAL_POWER_ON		0x01
> +#define   SD_POWER_ON			0x00
> +#define   SD_POWER_MASK			0x03
> +#define   MS_POWER_OFF			0x0C
> +#define   MS_PARTIAL_POWER_ON		0x04
> +#define   MS_POWER_ON			0x00
> +#define   MS_POWER_MASK			0x0C
> +#define   BPP_POWER_OFF			0x0F
> +#define   BPP_POWER_5_PERCENT_ON	0x0E
> +#define   BPP_POWER_10_PERCENT_ON	0x0C
> +#define   BPP_POWER_15_PERCENT_ON	0x08
> +#define   BPP_POWER_ON			0x00
> +#define   BPP_POWER_MASK		0x0F
> +#define   SD_VCC_PARTIAL_POWER_ON	0x02
> +#define   SD_VCC_POWER_ON		0x00
>  #define CARD_CLK_SWITCH			0xFD51
>  #define RTL8411B_PACKAGE_MODE		0xFD51
>  #define CARD_SHARE_MODE			0xFD52
> +#define   CARD_SHARE_MASK		0x0F
> +#define   CARD_SHARE_MULTI_LUN		0x00
> +#define   CARD_SHARE_NORMAL		0x00
> +#define   CARD_SHARE_48_SD		0x04
> +#define   CARD_SHARE_48_MS		0x08
> +#define   CARD_SHARE_BAROSSA_SD		0x01
> +#define   CARD_SHARE_BAROSSA_MS		0x02
>  #define CARD_DRIVE_SEL			0xFD53
> +#define   MS_DRIVE_8mA			(0x01 << 6)
> +#define   MMC_DRIVE_8mA			(0x01 << 4)
> +#define   XD_DRIVE_8mA			(0x01 << 2)
> +#define   GPIO_DRIVE_8mA		0x01
> +#define RTS5209_CARD_DRIVE_DEFAULT	(MS_DRIVE_8mA | MMC_DRIVE_8mA |\
> +					XD_DRIVE_8mA | GPIO_DRIVE_8mA)
> +#define RTL8411_CARD_DRIVE_DEFAULT	(MS_DRIVE_8mA | MMC_DRIVE_8mA |\
> +					XD_DRIVE_8mA)
> +#define RTSX_CARD_DRIVE_DEFAULT		(MS_DRIVE_8mA | GPIO_DRIVE_8mA)
> +
>  #define CARD_STOP			0xFD54
> +#define   SPI_STOP			0x01
> +#define   XD_STOP			0x02
> +#define   SD_STOP			0x04
> +#define   MS_STOP			0x08
> +#define   SPI_CLR_ERR			0x10
> +#define   XD_CLR_ERR			0x20
> +#define   SD_CLR_ERR			0x40
> +#define   MS_CLR_ERR			0x80
>  #define CARD_OE				0xFD55
> +#define   SD_OUTPUT_EN			0x04
> +#define   MS_OUTPUT_EN			0x08
>  #define CARD_AUTO_BLINK			0xFD56
>  #define CARD_GPIO_DIR			0xFD57
>  #define CARD_GPIO			0xFD58
>  #define CARD_DATA_SOURCE		0xFD5B
> +#define   PINGPONG_BUFFER		0x01
> +#define   RING_BUFFER			0x00
>  #define SD30_CLK_DRIVE_SEL		0xFD5A
> +#define   DRIVER_TYPE_A			0x05
> +#define   DRIVER_TYPE_B			0x03
> +#define   DRIVER_TYPE_C			0x02
> +#define   DRIVER_TYPE_D			0x01
>  #define CARD_SELECT			0xFD5C
> +#define   SD_MOD_SEL			2
> +#define   MS_MOD_SEL			3
>  #define SD30_DRIVE_SEL			0xFD5E
> +#define   CFG_DRIVER_TYPE_A		0x02
> +#define   CFG_DRIVER_TYPE_B		0x03
> +#define   CFG_DRIVER_TYPE_C		0x01
> +#define   CFG_DRIVER_TYPE_D		0x00
>  #define SD30_CMD_DRIVE_SEL		0xFD5E
>  #define SD30_DAT_DRIVE_SEL		0xFD5F
>  #define CARD_CLK_EN			0xFD69
> +#define   SD_CLK_EN			0x04
> +#define   MS_CLK_EN			0x08
>  #define SDIO_CTRL			0xFD6B
>  #define CD_PAD_CTL			0xFD73
> -
> +#define   CD_DISABLE_MASK		0x07
> +#define   MS_CD_DISABLE			0x04
> +#define   SD_CD_DISABLE			0x02
> +#define   XD_CD_DISABLE			0x01
> +#define   CD_DISABLE			0x07
> +#define   CD_ENABLE			0x00
> +#define   MS_CD_EN_ONLY			0x03
> +#define   SD_CD_EN_ONLY			0x05
> +#define   XD_CD_EN_ONLY			0x06
> +#define   FORCE_CD_LOW_MASK		0x38
> +#define   FORCE_CD_XD_LOW		0x08
> +#define   FORCE_CD_SD_LOW		0x10
> +#define   FORCE_CD_MS_LOW		0x20
> +#define   CD_AUTO_DISABLE		0x40
>  #define FPDCTL				0xFC00
> +#define   SSC_POWER_DOWN		0x01
> +#define   SD_OC_POWER_DOWN		0x02
> +#define   ALL_POWER_DOWN		0x07
> +#define   OC_POWER_DOWN			0x06
>  #define PDINFO				0xFC01
>  
>  #define CLK_CTL				0xFC02
> +#define   CHANGE_CLK			0x01
> +#define   CLK_LOW_FREQ			0x01
> +
>  #define CLK_DIV				0xFC03
> +#define   CLK_DIV_1			0x01
> +#define   CLK_DIV_2			0x02
> +#define   CLK_DIV_4			0x03
> +#define   CLK_DIV_8			0x04
>  #define CLK_SEL				0xFC04
>  
>  #define SSC_DIV_N_0			0xFC0F
>  #define SSC_DIV_N_1			0xFC10
>  #define SSC_CTL1			0xFC11
> +#define    SSC_RSTB			0x80
> +#define    SSC_8X_EN			0x40
> +#define    SSC_FIX_FRAC			0x20
> +#define    SSC_SEL_1M			0x00
> +#define    SSC_SEL_2M			0x08
> +#define    SSC_SEL_4M			0x10
> +#define    SSC_SEL_8M			0x18
>  #define SSC_CTL2			0xFC12
> -
> +#define    SSC_DEPTH_MASK		0x07
> +#define    SSC_DEPTH_DISALBE		0x00
> +#define    SSC_DEPTH_4M			0x01
> +#define    SSC_DEPTH_2M			0x02
> +#define    SSC_DEPTH_1M			0x03
> +#define    SSC_DEPTH_500K		0x04
> +#define    SSC_DEPTH_250K		0x05
>  #define RCCTL				0xFC14
>  
>  #define FPGA_PULL_CTL			0xFC1D
> @@ -630,6 +492,24 @@
>  #define GPIO_CTL			0xFC1F
>  
>  #define LDO_CTL				0xFC1E
> +#define   BPP_ASIC_1V7			0x00
> +#define   BPP_ASIC_1V8			0x01
> +#define   BPP_ASIC_1V9			0x02
> +#define   BPP_ASIC_2V0			0x03
> +#define   BPP_ASIC_2V7			0x04
> +#define   BPP_ASIC_2V8			0x05
> +#define   BPP_ASIC_3V2			0x06
> +#define   BPP_ASIC_3V3			0x07
> +#define   BPP_REG_TUNED18		0x07
> +#define   BPP_TUNED18_SHIFT_8402	5
> +#define   BPP_TUNED18_SHIFT_8411	4
> +#define   BPP_PAD_MASK			0x04
> +#define   BPP_PAD_3V3			0x04
> +#define   BPP_PAD_1V8			0x00
> +#define   BPP_LDO_POWB			0x03
> +#define   BPP_LDO_ON			0x00
> +#define   BPP_LDO_SUSPEND		0x02
> +#define   BPP_LDO_OFF			0x03
>  #define SYS_VER				0xFC32
>  
>  #define CARD_PULL_CTL1			0xFD60
> @@ -642,6 +522,10 @@
>  /* PCI Express Related Registers */
>  #define IRQEN0				0xFE20
>  #define IRQSTAT0			0xFE21
> +#define    DMA_DONE_INT			0x80
> +#define    SUSPEND_INT			0x40
> +#define    LINK_RDY_INT			0x20
> +#define    LINK_DOWN_INT		0x10
>  #define IRQEN1				0xFE22
>  #define IRQSTAT1			0xFE23
>  #define TLPRIEN				0xFE24
> @@ -653,6 +537,16 @@
>  #define DMATC2				0xFE2A
>  #define DMATC3				0xFE2B
>  #define DMACTL				0xFE2C
> +#define   DMA_RST			0x80
> +#define   DMA_BUSY			0x04
> +#define   DMA_DIR_TO_CARD		0x00
> +#define   DMA_DIR_FROM_CARD		0x02
> +#define   DMA_EN			0x01
> +#define   DMA_128			(0 << 4)
> +#define   DMA_256			(1 << 4)
> +#define   DMA_512			(2 << 4)
> +#define   DMA_1024			(3 << 4)
> +#define   DMA_PACK_SIZE_MASK		0x30
>  #define BCTL				0xFE2D
>  #define RBBC0				0xFE2E
>  #define RBBC1				0xFE2F
> @@ -693,11 +587,19 @@
>  #define RESET_LOAD_REG			0xFE5E
>  #define EFUSE_CONTENT			0xFE5F
>  #define HOST_SLEEP_STATE		0xFE60
> +#define   HOST_ENTER_S1			1
> +#define   HOST_ENTER_S3			2
> +
>  #define SDIO_CFG			0xFE70
>  
>  #define NFTS_TX_CTRL			0xFE72
>  
>  #define PWR_GATE_CTRL			0xFE75
> +#define   PWR_GATE_EN			0x01
> +#define   LDO3318_PWR_MASK		0x06
> +#define   LDO_ON			0x00
> +#define   LDO_SUSPEND			0x04
> +#define   LDO_OFF			0x06
>  #define PWD_SUSPEND_EN			0xFE76
>  #define LDO_PWR_SEL			0xFE78
>  

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 01/10] mfd: rtsx: replace TAB by SPC after #define
  2015-01-15 11:18 ` [PATCH 01/10] mfd: rtsx: replace TAB by SPC after #define micky_ching
@ 2015-01-18 12:39   ` Lee Jones
  2015-01-19  1:23     ` 敬锐
  0 siblings, 1 reply; 36+ messages in thread
From: Lee Jones @ 2015-01-18 12:39 UTC (permalink / raw)
  To: micky_ching; +Cc: sameo, devel, linux-kernel, gregkh, rogerable, wei_wang

On Thu, 15 Jan 2015, micky_ching@realsil.com.cn wrote:

> From: Micky Ching <micky_ching@realsil.com.cn>
> 
> Re-format coding-style, using uniform SPC after "#define" keyword
> instead of mixing using TAB and SPC.

Tabs and spaces in this context usually have different meanings
i.e. space after #define usually denotes that the following define is
a register address, whereas a tab commonly describes a bit field.

Please ensure you're not messing with these conventions.  By the looks
of it you are not, but I need you to confirm that you know what you're
doing.

> Signed-off-by: Micky Ching <micky_ching@realsil.com.cn>
> ---
>  include/linux/mfd/rtsx_pci.h | 254 +++++++++++++++++++++----------------------
>  1 file changed, 127 insertions(+), 127 deletions(-)
> 
> diff --git a/include/linux/mfd/rtsx_pci.h b/include/linux/mfd/rtsx_pci.h
> index 0c12628..a9c2a14 100644
> --- a/include/linux/mfd/rtsx_pci.h
> +++ b/include/linux/mfd/rtsx_pci.h
> @@ -175,9 +175,9 @@
>  /* CARD_SHARE_MODE */
>  #define CARD_SHARE_MASK			0x0F
>  #define CARD_SHARE_MULTI_LUN		0x00
> -#define	CARD_SHARE_NORMAL		0x00
> -#define	CARD_SHARE_48_SD		0x04
> -#define	CARD_SHARE_48_MS		0x08
> +#define CARD_SHARE_NORMAL		0x00
> +#define CARD_SHARE_48_SD		0x04
> +#define CARD_SHARE_48_MS		0x08
>  /* CARD_SHARE_MODE for barossa */
>  #define CARD_SHARE_BAROSSA_SD		0x01
>  #define CARD_SHARE_BAROSSA_MS		0x02
> @@ -249,76 +249,76 @@
>  #define CD_AUTO_DISABLE			0x40
>  
>  /* SD_STAT1 */
> -#define	SD_CRC7_ERR			0x80
> -#define	SD_CRC16_ERR			0x40
> -#define	SD_CRC_WRITE_ERR		0x20
> -#define	SD_CRC_WRITE_ERR_MASK		0x1C
> -#define	GET_CRC_TIME_OUT		0x02
> -#define	SD_TUNING_COMPARE_ERR		0x01
> +#define SD_CRC7_ERR			0x80
> +#define SD_CRC16_ERR			0x40
> +#define SD_CRC_WRITE_ERR		0x20
> +#define SD_CRC_WRITE_ERR_MASK		0x1C
> +#define GET_CRC_TIME_OUT		0x02
> +#define SD_TUNING_COMPARE_ERR		0x01
>  
>  /* SD_STAT2 */
> -#define	SD_RSP_80CLK_TIMEOUT		0x01
> +#define SD_RSP_80CLK_TIMEOUT		0x01
>  
>  /* SD_BUS_STAT */
> -#define	SD_CLK_TOGGLE_EN		0x80
> -#define	SD_CLK_FORCE_STOP	        0x40
> -#define	SD_DAT3_STATUS		        0x10
> -#define	SD_DAT2_STATUS		        0x08
> -#define	SD_DAT1_STATUS		        0x04
> -#define	SD_DAT0_STATUS		        0x02
> -#define	SD_CMD_STATUS			0x01
> +#define SD_CLK_TOGGLE_EN		0x80
> +#define SD_CLK_FORCE_STOP	        0x40
> +#define SD_DAT3_STATUS		        0x10
> +#define SD_DAT2_STATUS		        0x08
> +#define SD_DAT1_STATUS		        0x04
> +#define SD_DAT0_STATUS		        0x02
> +#define SD_CMD_STATUS			0x01
>  
>  /* SD_PAD_CTL */
> -#define	SD_IO_USING_1V8		        0x80
> -#define	SD_IO_USING_3V3		        0x7F
> -#define	TYPE_A_DRIVING		        0x00
> -#define	TYPE_B_DRIVING			0x01
> -#define	TYPE_C_DRIVING			0x02
> -#define	TYPE_D_DRIVING		        0x03
> +#define SD_IO_USING_1V8		        0x80
> +#define SD_IO_USING_3V3		        0x7F
> +#define TYPE_A_DRIVING		        0x00
> +#define TYPE_B_DRIVING			0x01
> +#define TYPE_C_DRIVING			0x02
> +#define TYPE_D_DRIVING		        0x03
>  
>  /* SD_SAMPLE_POINT_CTL */
> -#define	DDR_FIX_RX_DAT			0x00
> -#define	DDR_VAR_RX_DAT			0x80
> -#define	DDR_FIX_RX_DAT_EDGE		0x00
> -#define	DDR_FIX_RX_DAT_14_DELAY		0x40
> -#define	DDR_FIX_RX_CMD			0x00
> -#define	DDR_VAR_RX_CMD			0x20
> -#define	DDR_FIX_RX_CMD_POS_EDGE		0x00
> -#define	DDR_FIX_RX_CMD_14_DELAY		0x10
> -#define	SD20_RX_POS_EDGE		0x00
> -#define	SD20_RX_14_DELAY		0x08
> +#define DDR_FIX_RX_DAT			0x00
> +#define DDR_VAR_RX_DAT			0x80
> +#define DDR_FIX_RX_DAT_EDGE		0x00
> +#define DDR_FIX_RX_DAT_14_DELAY		0x40
> +#define DDR_FIX_RX_CMD			0x00
> +#define DDR_VAR_RX_CMD			0x20
> +#define DDR_FIX_RX_CMD_POS_EDGE		0x00
> +#define DDR_FIX_RX_CMD_14_DELAY		0x10
> +#define SD20_RX_POS_EDGE		0x00
> +#define SD20_RX_14_DELAY		0x08
>  #define SD20_RX_SEL_MASK		0x08
>  
>  /* SD_PUSH_POINT_CTL */
> -#define	DDR_FIX_TX_CMD_DAT		0x00
> -#define	DDR_VAR_TX_CMD_DAT		0x80
> -#define	DDR_FIX_TX_DAT_14_TSU		0x00
> -#define	DDR_FIX_TX_DAT_12_TSU		0x40
> -#define	DDR_FIX_TX_CMD_NEG_EDGE		0x00
> -#define	DDR_FIX_TX_CMD_14_AHEAD		0x20
> -#define	SD20_TX_NEG_EDGE		0x00
> -#define	SD20_TX_14_AHEAD		0x10
> +#define DDR_FIX_TX_CMD_DAT		0x00
> +#define DDR_VAR_TX_CMD_DAT		0x80
> +#define DDR_FIX_TX_DAT_14_TSU		0x00
> +#define DDR_FIX_TX_DAT_12_TSU		0x40
> +#define DDR_FIX_TX_CMD_NEG_EDGE		0x00
> +#define DDR_FIX_TX_CMD_14_AHEAD		0x20
> +#define SD20_TX_NEG_EDGE		0x00
> +#define SD20_TX_14_AHEAD		0x10
>  #define SD20_TX_SEL_MASK		0x10
> -#define	DDR_VAR_SDCLK_POL_SWAP		0x01
> +#define DDR_VAR_SDCLK_POL_SWAP		0x01
>  
>  /* SD_TRANSFER */
> -#define	SD_TRANSFER_START		0x80
> -#define	SD_TRANSFER_END			0x40
> +#define SD_TRANSFER_START		0x80
> +#define SD_TRANSFER_END			0x40
>  #define SD_STAT_IDLE			0x20
> -#define	SD_TRANSFER_ERR			0x10
> +#define SD_TRANSFER_ERR			0x10
>  /* SD Transfer Mode definition */
> -#define	SD_TM_NORMAL_WRITE		0x00
> -#define	SD_TM_AUTO_WRITE_3		0x01
> -#define	SD_TM_AUTO_WRITE_4		0x02
> -#define	SD_TM_AUTO_READ_3		0x05
> -#define	SD_TM_AUTO_READ_4		0x06
> -#define	SD_TM_CMD_RSP			0x08
> -#define	SD_TM_AUTO_WRITE_1		0x09
> -#define	SD_TM_AUTO_WRITE_2		0x0A
> -#define	SD_TM_NORMAL_READ		0x0C
> -#define	SD_TM_AUTO_READ_1		0x0D
> -#define	SD_TM_AUTO_READ_2		0x0E
> -#define	SD_TM_AUTO_TUNING		0x0F
> +#define SD_TM_NORMAL_WRITE		0x00
> +#define SD_TM_AUTO_WRITE_3		0x01
> +#define SD_TM_AUTO_WRITE_4		0x02
> +#define SD_TM_AUTO_READ_3		0x05
> +#define SD_TM_AUTO_READ_4		0x06
> +#define SD_TM_CMD_RSP			0x08
> +#define SD_TM_AUTO_WRITE_1		0x09
> +#define SD_TM_AUTO_WRITE_2		0x0A
> +#define SD_TM_NORMAL_READ		0x0C
> +#define SD_TM_AUTO_READ_1		0x0D
> +#define SD_TM_AUTO_READ_2		0x0E
> +#define SD_TM_AUTO_TUNING		0x0F
>  
>  /* SD_VPTX_CTL / SD_VPRX_CTL */
>  #define PHASE_CHANGE			0x80
> @@ -332,15 +332,15 @@
>  
>  /* SD Configure 1 Register */
>  #define SD_CLK_DIVIDE_0			0x00
> -#define	SD_CLK_DIVIDE_256		0xC0
> -#define	SD_CLK_DIVIDE_128		0x80
> -#define	SD_BUS_WIDTH_1BIT		0x00
> -#define	SD_BUS_WIDTH_4BIT		0x01
> -#define	SD_BUS_WIDTH_8BIT		0x02
> -#define	SD_ASYNC_FIFO_NOT_RST		0x10
> -#define	SD_20_MODE			0x00
> -#define	SD_DDR_MODE			0x04
> -#define	SD_30_MODE			0x08
> +#define SD_CLK_DIVIDE_256		0xC0
> +#define SD_CLK_DIVIDE_128		0x80
> +#define SD_BUS_WIDTH_1BIT		0x00
> +#define SD_BUS_WIDTH_4BIT		0x01
> +#define SD_BUS_WIDTH_8BIT		0x02
> +#define SD_ASYNC_FIFO_NOT_RST		0x10
> +#define SD_20_MODE			0x00
> +#define SD_DDR_MODE			0x04
> +#define SD_30_MODE			0x08
>  
>  #define SD_CLK_DIVIDE_MASK		0xC0
>  
> @@ -415,71 +415,71 @@
>  #define CLK_DIV_8			0x04
>  
>  /* MS_CFG */
> -#define	SAMPLE_TIME_RISING		0x00
> -#define	SAMPLE_TIME_FALLING		0x80
> -#define	PUSH_TIME_DEFAULT		0x00
> -#define	PUSH_TIME_ODD			0x40
> -#define	NO_EXTEND_TOGGLE		0x00
> -#define	EXTEND_TOGGLE_CHK		0x20
> -#define	MS_BUS_WIDTH_1			0x00
> -#define	MS_BUS_WIDTH_4			0x10
> -#define	MS_BUS_WIDTH_8			0x18
> -#define	MS_2K_SECTOR_MODE		0x04
> -#define	MS_512_SECTOR_MODE		0x00
> -#define	MS_TOGGLE_TIMEOUT_EN		0x00
> -#define	MS_TOGGLE_TIMEOUT_DISEN		0x01
> +#define SAMPLE_TIME_RISING		0x00
> +#define SAMPLE_TIME_FALLING		0x80
> +#define PUSH_TIME_DEFAULT		0x00
> +#define PUSH_TIME_ODD			0x40
> +#define NO_EXTEND_TOGGLE		0x00
> +#define EXTEND_TOGGLE_CHK		0x20
> +#define MS_BUS_WIDTH_1			0x00
> +#define MS_BUS_WIDTH_4			0x10
> +#define MS_BUS_WIDTH_8			0x18
> +#define MS_2K_SECTOR_MODE		0x04
> +#define MS_512_SECTOR_MODE		0x00
> +#define MS_TOGGLE_TIMEOUT_EN		0x00
> +#define MS_TOGGLE_TIMEOUT_DISEN		0x01
>  #define MS_NO_CHECK_INT			0x02
>  
>  /* MS_TRANS_CFG */
> -#define	WAIT_INT			0x80
> -#define	NO_WAIT_INT			0x00
> -#define	NO_AUTO_READ_INT_REG		0x00
> -#define	AUTO_READ_INT_REG		0x40
> -#define	MS_CRC16_ERR			0x20
> -#define	MS_RDY_TIMEOUT			0x10
> -#define	MS_INT_CMDNK			0x08
> -#define	MS_INT_BREQ			0x04
> -#define	MS_INT_ERR			0x02
> -#define	MS_INT_CED			0x01
> +#define WAIT_INT			0x80
> +#define NO_WAIT_INT			0x00
> +#define NO_AUTO_READ_INT_REG		0x00
> +#define AUTO_READ_INT_REG		0x40
> +#define MS_CRC16_ERR			0x20
> +#define MS_RDY_TIMEOUT			0x10
> +#define MS_INT_CMDNK			0x08
> +#define MS_INT_BREQ			0x04
> +#define MS_INT_ERR			0x02
> +#define MS_INT_CED			0x01
>  
>  /* MS_TRANSFER */
> -#define	MS_TRANSFER_START		0x80
> -#define	MS_TRANSFER_END			0x40
> -#define	MS_TRANSFER_ERR			0x20
> -#define	MS_BS_STATE			0x10
> -#define	MS_TM_READ_BYTES		0x00
> -#define	MS_TM_NORMAL_READ		0x01
> -#define	MS_TM_WRITE_BYTES		0x04
> -#define	MS_TM_NORMAL_WRITE		0x05
> -#define	MS_TM_AUTO_READ			0x08
> -#define	MS_TM_AUTO_WRITE		0x0C
> +#define MS_TRANSFER_START		0x80
> +#define MS_TRANSFER_END			0x40
> +#define MS_TRANSFER_ERR			0x20
> +#define MS_BS_STATE			0x10
> +#define MS_TM_READ_BYTES		0x00
> +#define MS_TM_NORMAL_READ		0x01
> +#define MS_TM_WRITE_BYTES		0x04
> +#define MS_TM_NORMAL_WRITE		0x05
> +#define MS_TM_AUTO_READ			0x08
> +#define MS_TM_AUTO_WRITE		0x0C
>  
>  /* SD Configure 2 Register */
> -#define	SD_CALCULATE_CRC7		0x00
> -#define	SD_NO_CALCULATE_CRC7		0x80
> -#define	SD_CHECK_CRC16			0x00
> -#define	SD_NO_CHECK_CRC16		0x40
> +#define SD_CALCULATE_CRC7		0x00
> +#define SD_NO_CALCULATE_CRC7		0x80
> +#define SD_CHECK_CRC16			0x00
> +#define SD_NO_CHECK_CRC16		0x40
>  #define SD_NO_CHECK_WAIT_CRC_TO		0x20
> -#define	SD_WAIT_BUSY_END		0x08
> -#define	SD_NO_WAIT_BUSY_END		0x00
> -#define	SD_CHECK_CRC7			0x00
> -#define	SD_NO_CHECK_CRC7		0x04
> -#define	SD_RSP_LEN_0			0x00
> -#define	SD_RSP_LEN_6			0x01
> -#define	SD_RSP_LEN_17			0x02
> +#define SD_WAIT_BUSY_END		0x08
> +#define SD_NO_WAIT_BUSY_END		0x00
> +#define SD_CHECK_CRC7			0x00
> +#define SD_NO_CHECK_CRC7		0x04
> +#define SD_RSP_LEN_0			0x00
> +#define SD_RSP_LEN_6			0x01
> +#define SD_RSP_LEN_17			0x02
>  /* SD/MMC Response Type Definition */
> -#define	SD_RSP_TYPE_R0			0x04
> -#define	SD_RSP_TYPE_R1			0x01
> -#define	SD_RSP_TYPE_R1b			0x09
> -#define	SD_RSP_TYPE_R2			0x02
> -#define	SD_RSP_TYPE_R3			0x05
> -#define	SD_RSP_TYPE_R4			0x05
> -#define	SD_RSP_TYPE_R5			0x01
> -#define	SD_RSP_TYPE_R6			0x01
> -#define	SD_RSP_TYPE_R7			0x01
> +#define SD_RSP_TYPE_R0			0x04
> +#define SD_RSP_TYPE_R1			0x01
> +#define SD_RSP_TYPE_R1b			0x09
> +#define SD_RSP_TYPE_R2			0x02
> +#define SD_RSP_TYPE_R3			0x05
> +#define SD_RSP_TYPE_R4			0x05
> +#define SD_RSP_TYPE_R5			0x01
> +#define SD_RSP_TYPE_R6			0x01
> +#define SD_RSP_TYPE_R7			0x01
>  
>  /* SD_CONFIGURE3 */
> -#define	SD_RSP_80CLK_TIMEOUT_EN		0x01
> +#define SD_RSP_80CLK_TIMEOUT_EN		0x01
>  
>  /* Card Transfer Reset Register */
>  #define SPI_STOP			0x01
> @@ -574,13 +574,13 @@
>  
>  #define SRCTL				0xFC13
>  
> -#define	DCM_DRP_CTL			0xFC23
> -#define	DCM_DRP_TRIG			0xFC24
> -#define	DCM_DRP_CFG			0xFC25
> -#define	DCM_DRP_WR_DATA_L		0xFC26
> -#define	DCM_DRP_WR_DATA_H		0xFC27
> -#define	DCM_DRP_RD_DATA_L		0xFC28
> -#define	DCM_DRP_RD_DATA_H		0xFC29
> +#define DCM_DRP_CTL			0xFC23
> +#define DCM_DRP_TRIG			0xFC24
> +#define DCM_DRP_CFG			0xFC25
> +#define DCM_DRP_WR_DATA_L		0xFC26
> +#define DCM_DRP_WR_DATA_H		0xFC27
> +#define DCM_DRP_RD_DATA_L		0xFC28
> +#define DCM_DRP_RD_DATA_H		0xFC29
>  #define SD_VPCLK0_CTL			0xFC2A
>  #define SD_VPCLK1_CTL			0xFC2B
>  #define SD_DCMPS0_CTL			0xFC2C

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 07/10] mfd: rtsx: remove LCTLR defination
  2015-01-18 12:28   ` Lee Jones
@ 2015-01-19  1:12     ` 敬锐
  2015-01-19  8:06       ` Lee Jones
  0 siblings, 1 reply; 36+ messages in thread
From: 敬锐 @ 2015-01-19  1:12 UTC (permalink / raw)
  To: Lee Jones; +Cc: sameo, devel, linux-kernel, gregkh, rogerable, 王炜

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 8329 bytes --]


On 01/18/2015 08:28 PM, Lee Jones wrote:
> On Thu, 15 Jan 2015, micky_ching@realsil.com.cn wrote:
>
>> From: Micky Ching <micky_ching@realsil.com.cn>
>>
>> To enable/disable ASPM we should find LINK CONTROL register
>> in PCI config space. All old chip use 0x80 address, but new
>> chip may use another address, so we using pci_find_capability()
>> to get LINK CONTROL address.
>>
>> rtsx_gops.c was removed, we consider to put some common operations
>> to this file, but the actual thing is, only a group of chips
>> are in common ops1, and another group of chips in common ops2,
>> it is hard to decide put which ops into generic ops file.
>>
>> Signed-off-by: Micky Ching <micky_ching@realsil.com.cn>
>> ---
>>   drivers/mfd/Makefile         |  2 +-
>>   drivers/mfd/rts5227.c        |  2 +-
>>   drivers/mfd/rts5249.c        |  3 +--
>>   drivers/mfd/rtsx_gops.c      | 37 -------------------------------------
>>   drivers/mfd/rtsx_pcr.c       | 25 ++++++++++++++++++++-----
>>   include/linux/mfd/rtsx_pci.h |  9 ---------
>>   6 files changed, 23 insertions(+), 55 deletions(-)
>>   delete mode 100644 drivers/mfd/rtsx_gops.c
>>
>> diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
>> index 53467e2..2cd7e74 100644
>> --- a/drivers/mfd/Makefile
>> +++ b/drivers/mfd/Makefile
>> @@ -13,7 +13,7 @@ obj-$(CONFIG_MFD_CROS_EC)	+= cros_ec.o
>>   obj-$(CONFIG_MFD_CROS_EC_I2C)	+= cros_ec_i2c.o
>>   obj-$(CONFIG_MFD_CROS_EC_SPI)	+= cros_ec_spi.o
>>   
>> -rtsx_pci-objs			:= rtsx_pcr.o rtsx_gops.o rts5209.o rts5229.o rtl8411.o rts5227.o rts5249.o
>> +rtsx_pci-objs			:= rtsx_pcr.o rts5209.o rts5229.o rtl8411.o rts5227.o rts5249.o
>>   obj-$(CONFIG_MFD_RTSX_PCI)	+= rtsx_pci.o
>>   obj-$(CONFIG_MFD_RTSX_USB)	+= rtsx_usb.o
>>   
>> diff --git a/drivers/mfd/rts5227.c b/drivers/mfd/rts5227.c
>> index 1f387d4..0c02831 100644
>> --- a/drivers/mfd/rts5227.c
>> +++ b/drivers/mfd/rts5227.c
>> @@ -130,7 +130,7 @@ static int rts5227_optimize_phy(struct rtsx_pcr *pcr)
>>   {
>>   	int err;
>>   
>> -	err = rtsx_gops_pm_reset(pcr);
>> +	err = rtsx_pci_write_register(pcr, PM_CTRL3, D3_DELINK_MODE_EN, 0x00);
>>   	if (err < 0)
>>   		return err;
>>   
>> diff --git a/drivers/mfd/rts5249.c b/drivers/mfd/rts5249.c
>> index 00208d1..5eb9819 100644
>> --- a/drivers/mfd/rts5249.c
>> +++ b/drivers/mfd/rts5249.c
>> @@ -119,7 +119,6 @@ static int rts5249_extra_init_hw(struct rtsx_pcr *pcr)
>>   		rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PETXCFG, 0xB0, 0xB0);
>>   	else
>>   		rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PETXCFG, 0xB0, 0x80);
>> -	rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PM_CTRL3, 0x10, 0x00);
> What's this doing?  Why is it not required anymore?
PM_CTRL3 have been set in rts5249_optimize_phy, this function
rts5249_extra_init will be call for rts524A/rts525A, but their PM_CTRL3
address is redefined to RTS524A_PM_CTRL3, using a different address.
if we set PM_CTRL3 here, the rts524A/rts525A will also set,
but it's not a right address.
>
>>   	return rtsx_pci_send_cmd(pcr, 100);
>>   }
>> @@ -128,7 +127,7 @@ static int rts5249_optimize_phy(struct rtsx_pcr *pcr)
>>   {
>>   	int err;
>>   
>> -	err = rtsx_gops_pm_reset(pcr);
>> +	err = rtsx_pci_write_register(pcr, PM_CTRL3, D3_DELINK_MODE_EN, 0x00);
>>   	if (err < 0)
>>   		return err;
>>   
>> diff --git a/drivers/mfd/rtsx_gops.c b/drivers/mfd/rtsx_gops.c
>> deleted file mode 100644
>> index b1a98c6..0000000
>> --- a/drivers/mfd/rtsx_gops.c
>> +++ /dev/null
>> @@ -1,37 +0,0 @@
>> -/* Driver for Realtek PCI-Express card reader
>> - *
>> - * Copyright(c) 2009-2013 Realtek Semiconductor Corp. All rights reserved.
>> - *
>> - * This program is free software; you can redistribute it and/or modify it
>> - * under the terms of the GNU General Public License as published by the
>> - * Free Software Foundation; either version 2, or (at your option) any
>> - * later version.
>> - *
>> - * This program is distributed in the hope that it will be useful, but
>> - * WITHOUT ANY WARRANTY; without even the implied warranty of
>> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>> - * General Public License for more details.
>> - *
>> - * You should have received a copy of the GNU General Public License along
>> - * with this program; if not, see <http://www.gnu.org/licenses/>.
>> - *
>> - * Author:
>> - *   Micky Ching <micky_ching@realsil.com.cn>
>> - */
>> -
>> -#include <linux/mfd/rtsx_pci.h>
>> -#include "rtsx_pcr.h"
>> -
>> -int rtsx_gops_pm_reset(struct rtsx_pcr *pcr)
>> -{
>> -	int err;
>> -
>> -	/* init aspm */
>> -	rtsx_pci_write_register(pcr, ASPM_FORCE_CTL, 0xFF, 0x00);
>> -	err = rtsx_pci_update_cfg_byte(pcr, LCTLR, ~LCTLR_ASPM_CTL_MASK, 0x00);
>> -	if (err < 0)
>> -		return err;
>> -
>> -	/* reset PM_CTRL3 before send buffer cmd */
>> -	return rtsx_pci_write_register(pcr, PM_CTRL3, D3_DELINK_MODE_EN, 0x00);
>> -}
>> diff --git a/drivers/mfd/rtsx_pcr.c b/drivers/mfd/rtsx_pcr.c
>> index 92f5a41..3065edc 100644
>> --- a/drivers/mfd/rtsx_pcr.c
>> +++ b/drivers/mfd/rtsx_pcr.c
>> @@ -63,6 +63,20 @@ static const struct pci_device_id rtsx_pci_ids[] = {
>>   
>>   MODULE_DEVICE_TABLE(pci, rtsx_pci_ids);
>>   
>> +static inline void rtsx_pci_enable_aspm(struct rtsx_pcr *pcr)
>> +{
>> +	int exp = pci_find_capability(pcr->pci, PCI_CAP_ID_EXP);
>> +
>> +	rtsx_pci_update_cfg_byte(pcr, exp + PCI_EXP_LNKCTL, 0xFC, pcr->aspm_en);
>> +}
>> +
>> +static inline void rtsx_pci_disable_aspm(struct rtsx_pcr *pcr)
>> +{
>> +	int exp = pci_find_capability(pcr->pci, PCI_CAP_ID_EXP);
>> +
>> +	rtsx_pci_update_cfg_byte(pcr, exp + PCI_EXP_LNKCTL, 0xFC, 0);
>> +}
>> +
>>   void rtsx_pci_start_run(struct rtsx_pcr *pcr)
>>   {
>>   	/* If pci device removed, don't queue idle work any more */
>> @@ -75,7 +89,8 @@ void rtsx_pci_start_run(struct rtsx_pcr *pcr)
>>   			pcr->ops->enable_auto_blink(pcr);
>>   
>>   		if (pcr->aspm_en)
>> -			rtsx_pci_write_config_byte(pcr, LCTLR, 0);
>> +			rtsx_pci_disable_aspm(pcr);
>> +
> ?
We set LCTLR to disable aspm, all old chip using 0x80 address,
but new chip will not use this address, the best way to find
this address is using pci_find_capability().
>
>>   	}
>>   
>>   	mod_delayed_work(system_wq, &pcr->idle_work, msecs_to_jiffies(200));
>> @@ -954,7 +969,7 @@ static void rtsx_pci_idle_work(struct work_struct *work)
>>   		pcr->ops->turn_off_led(pcr);
>>   
>>   	if (pcr->aspm_en)
>> -		rtsx_pci_write_config_byte(pcr, LCTLR, pcr->aspm_en);
>> +		rtsx_pci_enable_aspm(pcr);
>>   
>>   	mutex_unlock(&pcr->pcr_mutex);
>>   }
>> @@ -979,6 +994,7 @@ static void rtsx_pci_power_off(struct rtsx_pcr *pcr, u8 pm_state)
>>   static int rtsx_pci_init_hw(struct rtsx_pcr *pcr)
>>   {
>>   	int err;
>> +	int exp = pci_find_capability(pcr->pci, PCI_CAP_ID_EXP);
>>   
>>   	rtsx_pci_writel(pcr, RTSX_HCBAR, pcr->host_cmds_addr);
>>   
>> @@ -992,6 +1008,7 @@ static int rtsx_pci_init_hw(struct rtsx_pcr *pcr)
>>   	/* Wait SSC power stable */
>>   	udelay(200);
>>   
>> +	rtsx_pci_disable_aspm(pcr);
>>   	if (pcr->ops->optimize_phy) {
>>   		err = pcr->ops->optimize_phy(pcr);
>>   		if (err < 0)
>> @@ -1040,10 +1057,8 @@ static int rtsx_pci_init_hw(struct rtsx_pcr *pcr)
>>   	if (err < 0)
>>   		return err;
>>   
>> -	rtsx_pci_write_config_byte(pcr, LCTLR, 0);
>> -
>>   	/* Enable clk_request_n to enable clock power management */
>> -	rtsx_pci_write_config_byte(pcr, 0x81, 1);
>> +	rtsx_pci_write_config_byte(pcr, exp + PCI_EXP_LNKCTL + 1, 1);
>>   	/* Enter L1 when host tx idle */
>>   	rtsx_pci_write_config_byte(pcr, 0x70F, 0x5B);
>>   
>> diff --git a/include/linux/mfd/rtsx_pci.h b/include/linux/mfd/rtsx_pci.h
>> index 80baa10..f7cebdb 100644
>> --- a/include/linux/mfd/rtsx_pci.h
>> +++ b/include/linux/mfd/rtsx_pci.h
>> @@ -662,15 +662,6 @@
>>   #define PHY_FLD4			0x1E
>>   #define PHY_DUM_REG			0x1F
>>   
>> -#define LCTLR				0x80
>> -#define   LCTLR_EXT_SYNC		0x80
>> -#define   LCTLR_COMMON_CLOCK_CFG	0x40
>> -#define   LCTLR_RETRAIN_LINK		0x20
>> -#define   LCTLR_LINK_DISABLE		0x10
>> -#define   LCTLR_RCB			0x08
>> -#define   LCTLR_RESERVED		0x04
>> -#define   LCTLR_ASPM_CTL_MASK		0x03
>> -
>>   #define PCR_SETTING_REG1		0x724
>>   #define PCR_SETTING_REG2		0x814
>>   #define PCR_SETTING_REG3		0x747
ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 01/10] mfd: rtsx: replace TAB by SPC after #define
  2015-01-18 12:39   ` Lee Jones
@ 2015-01-19  1:23     ` 敬锐
  2015-01-19  7:49       ` Lee Jones
  0 siblings, 1 reply; 36+ messages in thread
From: 敬锐 @ 2015-01-19  1:23 UTC (permalink / raw)
  To: Lee Jones; +Cc: sameo, devel, linux-kernel, gregkh, rogerable, 王炜

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 12050 bytes --]


On 01/18/2015 08:39 PM, Lee Jones wrote:
> On Thu, 15 Jan 2015, micky_ching@realsil.com.cn wrote:
>
>> From: Micky Ching <micky_ching@realsil.com.cn>
>>
>> Re-format coding-style, using uniform SPC after "#define" keyword
>> instead of mixing using TAB and SPC.
> Tabs and spaces in this context usually have different meanings
> i.e. space after #define usually denotes that the following define is
> a register address, whereas a tab commonly describes a bit field.
>
> Please ensure you're not messing with these conventions.  By the looks
> of it you are not, but I need you to confirm that you know what you're
> doing.
if using TAB describe a bit field, and define TAB length = 8 SPC,
the editor will not show any difference(if not highlight TAB/SPC).
And the mix is not to show difference between address and field.
so all replaced by space, and show difference by next patch(02/10).
>> Signed-off-by: Micky Ching <micky_ching@realsil.com.cn>
>> ---
>>   include/linux/mfd/rtsx_pci.h | 254 +++++++++++++++++++++----------------------
>>   1 file changed, 127 insertions(+), 127 deletions(-)
>>
>> diff --git a/include/linux/mfd/rtsx_pci.h b/include/linux/mfd/rtsx_pci.h
>> index 0c12628..a9c2a14 100644
>> --- a/include/linux/mfd/rtsx_pci.h
>> +++ b/include/linux/mfd/rtsx_pci.h
>> @@ -175,9 +175,9 @@
>>   /* CARD_SHARE_MODE */
>>   #define CARD_SHARE_MASK			0x0F
>>   #define CARD_SHARE_MULTI_LUN		0x00
>> -#define	CARD_SHARE_NORMAL		0x00
>> -#define	CARD_SHARE_48_SD		0x04
>> -#define	CARD_SHARE_48_MS		0x08
>> +#define CARD_SHARE_NORMAL		0x00
>> +#define CARD_SHARE_48_SD		0x04
>> +#define CARD_SHARE_48_MS		0x08
>>   /* CARD_SHARE_MODE for barossa */
>>   #define CARD_SHARE_BAROSSA_SD		0x01
>>   #define CARD_SHARE_BAROSSA_MS		0x02
>> @@ -249,76 +249,76 @@
>>   #define CD_AUTO_DISABLE			0x40
>>   
>>   /* SD_STAT1 */
>> -#define	SD_CRC7_ERR			0x80
>> -#define	SD_CRC16_ERR			0x40
>> -#define	SD_CRC_WRITE_ERR		0x20
>> -#define	SD_CRC_WRITE_ERR_MASK		0x1C
>> -#define	GET_CRC_TIME_OUT		0x02
>> -#define	SD_TUNING_COMPARE_ERR		0x01
>> +#define SD_CRC7_ERR			0x80
>> +#define SD_CRC16_ERR			0x40
>> +#define SD_CRC_WRITE_ERR		0x20
>> +#define SD_CRC_WRITE_ERR_MASK		0x1C
>> +#define GET_CRC_TIME_OUT		0x02
>> +#define SD_TUNING_COMPARE_ERR		0x01
>>   
>>   /* SD_STAT2 */
>> -#define	SD_RSP_80CLK_TIMEOUT		0x01
>> +#define SD_RSP_80CLK_TIMEOUT		0x01
>>   
>>   /* SD_BUS_STAT */
>> -#define	SD_CLK_TOGGLE_EN		0x80
>> -#define	SD_CLK_FORCE_STOP	        0x40
>> -#define	SD_DAT3_STATUS		        0x10
>> -#define	SD_DAT2_STATUS		        0x08
>> -#define	SD_DAT1_STATUS		        0x04
>> -#define	SD_DAT0_STATUS		        0x02
>> -#define	SD_CMD_STATUS			0x01
>> +#define SD_CLK_TOGGLE_EN		0x80
>> +#define SD_CLK_FORCE_STOP	        0x40
>> +#define SD_DAT3_STATUS		        0x10
>> +#define SD_DAT2_STATUS		        0x08
>> +#define SD_DAT1_STATUS		        0x04
>> +#define SD_DAT0_STATUS		        0x02
>> +#define SD_CMD_STATUS			0x01
>>   
>>   /* SD_PAD_CTL */
>> -#define	SD_IO_USING_1V8		        0x80
>> -#define	SD_IO_USING_3V3		        0x7F
>> -#define	TYPE_A_DRIVING		        0x00
>> -#define	TYPE_B_DRIVING			0x01
>> -#define	TYPE_C_DRIVING			0x02
>> -#define	TYPE_D_DRIVING		        0x03
>> +#define SD_IO_USING_1V8		        0x80
>> +#define SD_IO_USING_3V3		        0x7F
>> +#define TYPE_A_DRIVING		        0x00
>> +#define TYPE_B_DRIVING			0x01
>> +#define TYPE_C_DRIVING			0x02
>> +#define TYPE_D_DRIVING		        0x03
>>   
>>   /* SD_SAMPLE_POINT_CTL */
>> -#define	DDR_FIX_RX_DAT			0x00
>> -#define	DDR_VAR_RX_DAT			0x80
>> -#define	DDR_FIX_RX_DAT_EDGE		0x00
>> -#define	DDR_FIX_RX_DAT_14_DELAY		0x40
>> -#define	DDR_FIX_RX_CMD			0x00
>> -#define	DDR_VAR_RX_CMD			0x20
>> -#define	DDR_FIX_RX_CMD_POS_EDGE		0x00
>> -#define	DDR_FIX_RX_CMD_14_DELAY		0x10
>> -#define	SD20_RX_POS_EDGE		0x00
>> -#define	SD20_RX_14_DELAY		0x08
>> +#define DDR_FIX_RX_DAT			0x00
>> +#define DDR_VAR_RX_DAT			0x80
>> +#define DDR_FIX_RX_DAT_EDGE		0x00
>> +#define DDR_FIX_RX_DAT_14_DELAY		0x40
>> +#define DDR_FIX_RX_CMD			0x00
>> +#define DDR_VAR_RX_CMD			0x20
>> +#define DDR_FIX_RX_CMD_POS_EDGE		0x00
>> +#define DDR_FIX_RX_CMD_14_DELAY		0x10
>> +#define SD20_RX_POS_EDGE		0x00
>> +#define SD20_RX_14_DELAY		0x08
>>   #define SD20_RX_SEL_MASK		0x08
>>   
>>   /* SD_PUSH_POINT_CTL */
>> -#define	DDR_FIX_TX_CMD_DAT		0x00
>> -#define	DDR_VAR_TX_CMD_DAT		0x80
>> -#define	DDR_FIX_TX_DAT_14_TSU		0x00
>> -#define	DDR_FIX_TX_DAT_12_TSU		0x40
>> -#define	DDR_FIX_TX_CMD_NEG_EDGE		0x00
>> -#define	DDR_FIX_TX_CMD_14_AHEAD		0x20
>> -#define	SD20_TX_NEG_EDGE		0x00
>> -#define	SD20_TX_14_AHEAD		0x10
>> +#define DDR_FIX_TX_CMD_DAT		0x00
>> +#define DDR_VAR_TX_CMD_DAT		0x80
>> +#define DDR_FIX_TX_DAT_14_TSU		0x00
>> +#define DDR_FIX_TX_DAT_12_TSU		0x40
>> +#define DDR_FIX_TX_CMD_NEG_EDGE		0x00
>> +#define DDR_FIX_TX_CMD_14_AHEAD		0x20
>> +#define SD20_TX_NEG_EDGE		0x00
>> +#define SD20_TX_14_AHEAD		0x10
>>   #define SD20_TX_SEL_MASK		0x10
>> -#define	DDR_VAR_SDCLK_POL_SWAP		0x01
>> +#define DDR_VAR_SDCLK_POL_SWAP		0x01
>>   
>>   /* SD_TRANSFER */
>> -#define	SD_TRANSFER_START		0x80
>> -#define	SD_TRANSFER_END			0x40
>> +#define SD_TRANSFER_START		0x80
>> +#define SD_TRANSFER_END			0x40
>>   #define SD_STAT_IDLE			0x20
>> -#define	SD_TRANSFER_ERR			0x10
>> +#define SD_TRANSFER_ERR			0x10
>>   /* SD Transfer Mode definition */
>> -#define	SD_TM_NORMAL_WRITE		0x00
>> -#define	SD_TM_AUTO_WRITE_3		0x01
>> -#define	SD_TM_AUTO_WRITE_4		0x02
>> -#define	SD_TM_AUTO_READ_3		0x05
>> -#define	SD_TM_AUTO_READ_4		0x06
>> -#define	SD_TM_CMD_RSP			0x08
>> -#define	SD_TM_AUTO_WRITE_1		0x09
>> -#define	SD_TM_AUTO_WRITE_2		0x0A
>> -#define	SD_TM_NORMAL_READ		0x0C
>> -#define	SD_TM_AUTO_READ_1		0x0D
>> -#define	SD_TM_AUTO_READ_2		0x0E
>> -#define	SD_TM_AUTO_TUNING		0x0F
>> +#define SD_TM_NORMAL_WRITE		0x00
>> +#define SD_TM_AUTO_WRITE_3		0x01
>> +#define SD_TM_AUTO_WRITE_4		0x02
>> +#define SD_TM_AUTO_READ_3		0x05
>> +#define SD_TM_AUTO_READ_4		0x06
>> +#define SD_TM_CMD_RSP			0x08
>> +#define SD_TM_AUTO_WRITE_1		0x09
>> +#define SD_TM_AUTO_WRITE_2		0x0A
>> +#define SD_TM_NORMAL_READ		0x0C
>> +#define SD_TM_AUTO_READ_1		0x0D
>> +#define SD_TM_AUTO_READ_2		0x0E
>> +#define SD_TM_AUTO_TUNING		0x0F
>>   
>>   /* SD_VPTX_CTL / SD_VPRX_CTL */
>>   #define PHASE_CHANGE			0x80
>> @@ -332,15 +332,15 @@
>>   
>>   /* SD Configure 1 Register */
>>   #define SD_CLK_DIVIDE_0			0x00
>> -#define	SD_CLK_DIVIDE_256		0xC0
>> -#define	SD_CLK_DIVIDE_128		0x80
>> -#define	SD_BUS_WIDTH_1BIT		0x00
>> -#define	SD_BUS_WIDTH_4BIT		0x01
>> -#define	SD_BUS_WIDTH_8BIT		0x02
>> -#define	SD_ASYNC_FIFO_NOT_RST		0x10
>> -#define	SD_20_MODE			0x00
>> -#define	SD_DDR_MODE			0x04
>> -#define	SD_30_MODE			0x08
>> +#define SD_CLK_DIVIDE_256		0xC0
>> +#define SD_CLK_DIVIDE_128		0x80
>> +#define SD_BUS_WIDTH_1BIT		0x00
>> +#define SD_BUS_WIDTH_4BIT		0x01
>> +#define SD_BUS_WIDTH_8BIT		0x02
>> +#define SD_ASYNC_FIFO_NOT_RST		0x10
>> +#define SD_20_MODE			0x00
>> +#define SD_DDR_MODE			0x04
>> +#define SD_30_MODE			0x08
>>   
>>   #define SD_CLK_DIVIDE_MASK		0xC0
>>   
>> @@ -415,71 +415,71 @@
>>   #define CLK_DIV_8			0x04
>>   
>>   /* MS_CFG */
>> -#define	SAMPLE_TIME_RISING		0x00
>> -#define	SAMPLE_TIME_FALLING		0x80
>> -#define	PUSH_TIME_DEFAULT		0x00
>> -#define	PUSH_TIME_ODD			0x40
>> -#define	NO_EXTEND_TOGGLE		0x00
>> -#define	EXTEND_TOGGLE_CHK		0x20
>> -#define	MS_BUS_WIDTH_1			0x00
>> -#define	MS_BUS_WIDTH_4			0x10
>> -#define	MS_BUS_WIDTH_8			0x18
>> -#define	MS_2K_SECTOR_MODE		0x04
>> -#define	MS_512_SECTOR_MODE		0x00
>> -#define	MS_TOGGLE_TIMEOUT_EN		0x00
>> -#define	MS_TOGGLE_TIMEOUT_DISEN		0x01
>> +#define SAMPLE_TIME_RISING		0x00
>> +#define SAMPLE_TIME_FALLING		0x80
>> +#define PUSH_TIME_DEFAULT		0x00
>> +#define PUSH_TIME_ODD			0x40
>> +#define NO_EXTEND_TOGGLE		0x00
>> +#define EXTEND_TOGGLE_CHK		0x20
>> +#define MS_BUS_WIDTH_1			0x00
>> +#define MS_BUS_WIDTH_4			0x10
>> +#define MS_BUS_WIDTH_8			0x18
>> +#define MS_2K_SECTOR_MODE		0x04
>> +#define MS_512_SECTOR_MODE		0x00
>> +#define MS_TOGGLE_TIMEOUT_EN		0x00
>> +#define MS_TOGGLE_TIMEOUT_DISEN		0x01
>>   #define MS_NO_CHECK_INT			0x02
>>   
>>   /* MS_TRANS_CFG */
>> -#define	WAIT_INT			0x80
>> -#define	NO_WAIT_INT			0x00
>> -#define	NO_AUTO_READ_INT_REG		0x00
>> -#define	AUTO_READ_INT_REG		0x40
>> -#define	MS_CRC16_ERR			0x20
>> -#define	MS_RDY_TIMEOUT			0x10
>> -#define	MS_INT_CMDNK			0x08
>> -#define	MS_INT_BREQ			0x04
>> -#define	MS_INT_ERR			0x02
>> -#define	MS_INT_CED			0x01
>> +#define WAIT_INT			0x80
>> +#define NO_WAIT_INT			0x00
>> +#define NO_AUTO_READ_INT_REG		0x00
>> +#define AUTO_READ_INT_REG		0x40
>> +#define MS_CRC16_ERR			0x20
>> +#define MS_RDY_TIMEOUT			0x10
>> +#define MS_INT_CMDNK			0x08
>> +#define MS_INT_BREQ			0x04
>> +#define MS_INT_ERR			0x02
>> +#define MS_INT_CED			0x01
>>   
>>   /* MS_TRANSFER */
>> -#define	MS_TRANSFER_START		0x80
>> -#define	MS_TRANSFER_END			0x40
>> -#define	MS_TRANSFER_ERR			0x20
>> -#define	MS_BS_STATE			0x10
>> -#define	MS_TM_READ_BYTES		0x00
>> -#define	MS_TM_NORMAL_READ		0x01
>> -#define	MS_TM_WRITE_BYTES		0x04
>> -#define	MS_TM_NORMAL_WRITE		0x05
>> -#define	MS_TM_AUTO_READ			0x08
>> -#define	MS_TM_AUTO_WRITE		0x0C
>> +#define MS_TRANSFER_START		0x80
>> +#define MS_TRANSFER_END			0x40
>> +#define MS_TRANSFER_ERR			0x20
>> +#define MS_BS_STATE			0x10
>> +#define MS_TM_READ_BYTES		0x00
>> +#define MS_TM_NORMAL_READ		0x01
>> +#define MS_TM_WRITE_BYTES		0x04
>> +#define MS_TM_NORMAL_WRITE		0x05
>> +#define MS_TM_AUTO_READ			0x08
>> +#define MS_TM_AUTO_WRITE		0x0C
>>   
>>   /* SD Configure 2 Register */
>> -#define	SD_CALCULATE_CRC7		0x00
>> -#define	SD_NO_CALCULATE_CRC7		0x80
>> -#define	SD_CHECK_CRC16			0x00
>> -#define	SD_NO_CHECK_CRC16		0x40
>> +#define SD_CALCULATE_CRC7		0x00
>> +#define SD_NO_CALCULATE_CRC7		0x80
>> +#define SD_CHECK_CRC16			0x00
>> +#define SD_NO_CHECK_CRC16		0x40
>>   #define SD_NO_CHECK_WAIT_CRC_TO		0x20
>> -#define	SD_WAIT_BUSY_END		0x08
>> -#define	SD_NO_WAIT_BUSY_END		0x00
>> -#define	SD_CHECK_CRC7			0x00
>> -#define	SD_NO_CHECK_CRC7		0x04
>> -#define	SD_RSP_LEN_0			0x00
>> -#define	SD_RSP_LEN_6			0x01
>> -#define	SD_RSP_LEN_17			0x02
>> +#define SD_WAIT_BUSY_END		0x08
>> +#define SD_NO_WAIT_BUSY_END		0x00
>> +#define SD_CHECK_CRC7			0x00
>> +#define SD_NO_CHECK_CRC7		0x04
>> +#define SD_RSP_LEN_0			0x00
>> +#define SD_RSP_LEN_6			0x01
>> +#define SD_RSP_LEN_17			0x02
>>   /* SD/MMC Response Type Definition */
>> -#define	SD_RSP_TYPE_R0			0x04
>> -#define	SD_RSP_TYPE_R1			0x01
>> -#define	SD_RSP_TYPE_R1b			0x09
>> -#define	SD_RSP_TYPE_R2			0x02
>> -#define	SD_RSP_TYPE_R3			0x05
>> -#define	SD_RSP_TYPE_R4			0x05
>> -#define	SD_RSP_TYPE_R5			0x01
>> -#define	SD_RSP_TYPE_R6			0x01
>> -#define	SD_RSP_TYPE_R7			0x01
>> +#define SD_RSP_TYPE_R0			0x04
>> +#define SD_RSP_TYPE_R1			0x01
>> +#define SD_RSP_TYPE_R1b			0x09
>> +#define SD_RSP_TYPE_R2			0x02
>> +#define SD_RSP_TYPE_R3			0x05
>> +#define SD_RSP_TYPE_R4			0x05
>> +#define SD_RSP_TYPE_R5			0x01
>> +#define SD_RSP_TYPE_R6			0x01
>> +#define SD_RSP_TYPE_R7			0x01
>>   
>>   /* SD_CONFIGURE3 */
>> -#define	SD_RSP_80CLK_TIMEOUT_EN		0x01
>> +#define SD_RSP_80CLK_TIMEOUT_EN		0x01
>>   
>>   /* Card Transfer Reset Register */
>>   #define SPI_STOP			0x01
>> @@ -574,13 +574,13 @@
>>   
>>   #define SRCTL				0xFC13
>>   
>> -#define	DCM_DRP_CTL			0xFC23
>> -#define	DCM_DRP_TRIG			0xFC24
>> -#define	DCM_DRP_CFG			0xFC25
>> -#define	DCM_DRP_WR_DATA_L		0xFC26
>> -#define	DCM_DRP_WR_DATA_H		0xFC27
>> -#define	DCM_DRP_RD_DATA_L		0xFC28
>> -#define	DCM_DRP_RD_DATA_H		0xFC29
>> +#define DCM_DRP_CTL			0xFC23
>> +#define DCM_DRP_TRIG			0xFC24
>> +#define DCM_DRP_CFG			0xFC25
>> +#define DCM_DRP_WR_DATA_L		0xFC26
>> +#define DCM_DRP_WR_DATA_H		0xFC27
>> +#define DCM_DRP_RD_DATA_L		0xFC28
>> +#define DCM_DRP_RD_DATA_H		0xFC29
>>   #define SD_VPCLK0_CTL			0xFC2A
>>   #define SD_VPCLK1_CTL			0xFC2B
>>   #define SD_DCMPS0_CTL			0xFC2C
ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 06/10] mfd: rtsx: update phy register
  2015-01-18 12:29   ` Lee Jones
@ 2015-01-19  1:55     ` 敬锐
  2015-01-19  7:47       ` Lee Jones
  0 siblings, 1 reply; 36+ messages in thread
From: 敬锐 @ 2015-01-19  1:55 UTC (permalink / raw)
  To: Lee Jones; +Cc: sameo, devel, linux-kernel, gregkh, rogerable, 王炜

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 4026 bytes --]


On 01/18/2015 08:29 PM, Lee Jones wrote:
> On Thu, 15 Jan 2015, micky_ching@realsil.com.cn wrote:
>
>> From: Micky Ching <micky_ching@realsil.com.cn>
>>
>> update phy register value and using direct value instead of macros.
>> It is much easier to debug using constant value than a lot of macros.
>> We usually need compare the value directly to check the configure.
> NACK.  This is the opposite of what I would like to see.
>
When we debug, we usually need to compare the value provided from hardware,
of course we can compare by print them to kernel log. but I think it more
convenient from source code. And we only set phy register when 
initialize chip,
so the value will not scattered everywhere, we will not benefit from macros.

if we want to know the meaning of setting, we can look at the register 
define.

>> Signed-off-by: Micky Ching <micky_ching@realsil.com.cn>
>> ---
>>   drivers/mfd/rts5249.c | 46 ++++++++++++++--------------------------------
>>   1 file changed, 14 insertions(+), 32 deletions(-)
>>
>> diff --git a/drivers/mfd/rts5249.c b/drivers/mfd/rts5249.c
>> index 2fe2854..00208d1 100644
>> --- a/drivers/mfd/rts5249.c
>> +++ b/drivers/mfd/rts5249.c
>> @@ -132,57 +132,39 @@ static int rts5249_optimize_phy(struct rtsx_pcr *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 |
>> -			PHY_REG_REV_RX_PWST | PHY_REG_REV_CLKREQ_DLY_TIMER_1_0 |
>> -			PHY_REG_REV_STOP_CLKRD | PHY_REG_REV_STOP_CLKWR);
>> +	err = rtsx_pci_write_phy_register(pcr, 0x19, 0xFE6C);
>>   	if (err < 0)
>>   		return err;
>>   
>>   	msleep(1);
>>   
>> -	err = rtsx_pci_write_phy_register(pcr, PHY_BPCR,
>> -			PHY_BPCR_IBRXSEL | PHY_BPCR_IBTXSEL |
>> -			PHY_BPCR_IB_FILTER | PHY_BPCR_CMIRROR_EN);
>> +	err = rtsx_pci_write_phy_register(pcr, 0x0A, 0x05C0);
>>   	if (err < 0)
>>   		return err;
>> -	err = rtsx_pci_write_phy_register(pcr, PHY_PCR,
>> -			PHY_PCR_FORCE_CODE | PHY_PCR_OOBS_CALI_50 |
>> -			PHY_PCR_OOBS_VCM_08 | PHY_PCR_OOBS_SEN_90 |
>> -			PHY_PCR_RSSI_EN);
>> +
>> +	err = rtsx_pci_write_phy_register(pcr, 0x00, 0xBA43);
>> +	if (err < 0)
>> +		return err;
>> +	err = rtsx_pci_write_phy_register(pcr, 0x03, 0xC152);
>>   	if (err < 0)
>>   		return err;
>> -	err = rtsx_pci_write_phy_register(pcr, PHY_RCR2,
>> -			PHY_RCR2_EMPHASE_EN | PHY_RCR2_NADJR |
>> -			PHY_RCR2_CDR_CP_10 | PHY_RCR2_CDR_SR_2 |
>> -			PHY_RCR2_FREQSEL_12 | PHY_RCR2_CPADJEN |
>> -			PHY_RCR2_CDR_SC_8 | PHY_RCR2_CALIB_LATE);
>> +	err = rtsx_pci_write_phy_register(pcr, 0x1E, 0x78EB);
>>   	if (err < 0)
>>   		return err;
>> -	err = rtsx_pci_write_phy_register(pcr, PHY_FLD4,
>> -			PHY_FLD4_FLDEN_SEL | PHY_FLD4_REQ_REF |
>> -			PHY_FLD4_RXAMP_OFF | PHY_FLD4_REQ_ADDA |
>> -			PHY_FLD4_BER_COUNT | PHY_FLD4_BER_TIMER |
>> -			PHY_FLD4_BER_CHK_EN);
>> +	err = rtsx_pci_write_phy_register(pcr, 0x05, 0x4600);
>>   	if (err < 0)
>>   		return err;
>> -	err = rtsx_pci_write_phy_register(pcr, PHY_RDR, PHY_RDR_RXDSEL_1_9);
>> +	err = rtsx_pci_write_phy_register(pcr, 0x02, 0x041F);
>>   	if (err < 0)
>>   		return err;
>> -	err = rtsx_pci_write_phy_register(pcr, PHY_RCR1,
>> -			PHY_RCR1_ADP_TIME | PHY_RCR1_VCO_COARSE);
>> +	err = rtsx_pci_write_phy_register(pcr, 0x1D, 0x0824);
>>   	if (err < 0)
>>   		return err;
>> -	err = rtsx_pci_write_phy_register(pcr, PHY_FLD3,
>> -			PHY_FLD3_TIMER_4 | PHY_FLD3_TIMER_6 |
>> -			PHY_FLD3_RXDELINK);
>> +	err = rtsx_pci_write_phy_register(pcr, 0x08, 0x4FE4);
>>   	if (err < 0)
>>   		return err;
>> -	return rtsx_pci_write_phy_register(pcr, PHY_TUNE,
>> -			PHY_TUNE_TUNEREF_1_0 | PHY_TUNE_VBGSEL_1252 |
>> -			PHY_TUNE_SDBUS_33 | PHY_TUNE_TUNED18 |
>> -			PHY_TUNE_TUNED12);
>> +
>> +	return 0;
>>   }
>>   
>>   static int rts5249_turn_on_led(struct rtsx_pcr *pcr)
ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 08/10] mfd: rtsx: add support for rts524A
  2015-01-18 12:20   ` Lee Jones
@ 2015-01-19  2:32     ` 敬锐
  2015-01-19  2:36     ` 敬锐
  2015-01-19  3:09     ` 敬锐
  2 siblings, 0 replies; 36+ messages in thread
From: 敬锐 @ 2015-01-19  2:32 UTC (permalink / raw)
  To: Lee Jones; +Cc: sameo, devel, linux-kernel, gregkh, rogerable, 王炜

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 809 bytes --]


On 01/18/2015 08:20 PM, Lee Jones wrote:
>> @@ -72,8 +72,10 @@ static void rts5249_fetch_vendor_settings(struct rtsx_pcr *pcr)
>> >  	rtsx_pci_read_config_dword(pcr, PCR_SETTING_REG1, &reg);
>> >  	dev_dbg(&(pcr->pci->dev), "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG1, reg);
>> >  
>> >-	if (!rtsx_vendor_setting_valid(reg))
>> >+	if (!rtsx_vendor_setting_valid(reg)) {
>> >+		pcr_dbg(pcr, "skip fetch vendor setting\n");
>> >  		return;
>> >+	}
> This doesn't have anything to do with adding the new chip.
>
> And I'm not sure it's even required.
>
Yes, it can be removed, but it is useful for debug,
help us to know whether config is load from hardware.ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 08/10] mfd: rtsx: add support for rts524A
  2015-01-18 12:20   ` Lee Jones
  2015-01-19  2:32     ` 敬锐
@ 2015-01-19  2:36     ` 敬锐
  2015-01-19  7:40       ` Lee Jones
  2015-01-19  3:09     ` 敬锐
  2 siblings, 1 reply; 36+ messages in thread
From: 敬锐 @ 2015-01-19  2:36 UTC (permalink / raw)
  To: Lee Jones; +Cc: sameo, devel, linux-kernel, gregkh, rogerable, 王炜

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 652 bytes --]


On 01/18/2015 08:20 PM, Lee Jones wrote:
>> +static int rts524a_optimize_phy(struct rtsx_pcr *pcr)
>> >+{
>> >+	int err;
>> >+
>> >+	err = rtsx_pci_write_register(pcr, RTS524A_PM_CTRL3,
>> >+		D3_DELINK_MODE_EN, 0x00);
>> >+	if (err < 0)
>> >+		return err;
> if (err)
>
err value will never be positive, but I have to make it consistence
with driver in other place, because all the check using if (err < 0) form.
And maybe, it make reserved for future the function may return positive
value.ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 09/10] mfd: rtsx: add support for rts525A
  2015-01-18 11:13   ` Lee Jones
@ 2015-01-19  2:53     ` 敬锐
  2015-01-19  7:41       ` Lee Jones
  0 siblings, 1 reply; 36+ messages in thread
From: 敬锐 @ 2015-01-19  2:53 UTC (permalink / raw)
  To: Lee Jones; +Cc: sameo, devel, linux-kernel, gregkh, rogerable, 王炜

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 710 bytes --]


On 01/18/2015 07:13 PM, Lee Jones wrote:
>> @@ -97,7 +97,7 @@ static void rts5249_force_power_down(struct rtsx_pcr *pcr, u8 pm_state)
>> >  	rtsx_pci_write_register(pcr, AUTOLOAD_CFG_BASE + 3, 0x01, 0);
>> >  
>> >  	if (pm_state == HOST_ENTER_S3) {
>> >-		if (PCI_PID(pcr) == 0x524A)
>> >+		if (PCI_PID(pcr) == 0x524A || PCI_PID(pcr) == 0x525A)
> Shouldn't these be defined somewhere?
>
> I have a particular distaste for magic numbers.
>
This is the chip ID number, no need define, just using it.
if we define, it will like RTS525A_PCI_ID, so bad.ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 08/10] mfd: rtsx: add support for rts524A
  2015-01-18 12:20   ` Lee Jones
  2015-01-19  2:32     ` 敬锐
  2015-01-19  2:36     ` 敬锐
@ 2015-01-19  3:09     ` 敬锐
  2015-01-19  7:38       ` Lee Jones
  2 siblings, 1 reply; 36+ messages in thread
From: 敬锐 @ 2015-01-19  3:09 UTC (permalink / raw)
  To: Lee Jones; +Cc: sameo, devel, linux-kernel, gregkh, rogerable, 王炜

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 634 bytes --]


On 01/18/2015 08:20 PM, Lee Jones wrote:
>> +};
>> >+
>> >+void rts524a_init_params(struct rtsx_pcr *pcr)
>> >+{
>> >+	rts5249_init_params(pcr);
>> >+
>> >+	pcr->ops = &rts524a_pcr_ops;
>> >+}
> I see a couple of these now.  Why don't you make 'ops' a parameter of
> *_init_params().
>
*_init_params() is called from rtsx_pcr.c, and the ops parameter should
be static, if we make ops as a parameter, the rts524a_pcr_ops defination
should move to rtsx_pcr.c, not reasonable.ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 08/10] mfd: rtsx: add support for rts524A
  2015-01-19  3:09     ` 敬锐
@ 2015-01-19  7:38       ` Lee Jones
  0 siblings, 0 replies; 36+ messages in thread
From: Lee Jones @ 2015-01-19  7:38 UTC (permalink / raw)
  To: 敬锐
  Cc: sameo, devel, linux-kernel, gregkh, rogerable, 王炜

On Mon, 19 Jan 2015, 敬锐 wrote:

> 
> On 01/18/2015 08:20 PM, Lee Jones wrote:
> >> +};
> >> >+
> >> >+void rts524a_init_params(struct rtsx_pcr *pcr)
> >> >+{
> >> >+	rts5249_init_params(pcr);
> >> >+
> >> >+	pcr->ops = &rts524a_pcr_ops;
> >> >+}
> > I see a couple of these now.  Why don't you make 'ops' a parameter of
> > *_init_params().
> >
> *_init_params() is called from rtsx_pcr.c, and the ops parameter should
> be static, if we make ops as a parameter, the rts524a_pcr_ops defination
> should move to rtsx_pcr.c, not reasonable.

Fair enough.

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 08/10] mfd: rtsx: add support for rts524A
  2015-01-19  2:36     ` 敬锐
@ 2015-01-19  7:40       ` Lee Jones
  0 siblings, 0 replies; 36+ messages in thread
From: Lee Jones @ 2015-01-19  7:40 UTC (permalink / raw)
  To: 敬锐
  Cc: sameo, devel, linux-kernel, gregkh, rogerable, 王炜

On Mon, 19 Jan 2015, 敬锐 wrote:

> 
> On 01/18/2015 08:20 PM, Lee Jones wrote:
> >> +static int rts524a_optimize_phy(struct rtsx_pcr *pcr)
> >> >+{
> >> >+	int err;
> >> >+
> >> >+	err = rtsx_pci_write_register(pcr, RTS524A_PM_CTRL3,
> >> >+		D3_DELINK_MODE_EN, 0x00);
> >> >+	if (err < 0)
> >> >+		return err;
> > if (err)
> >
> err value will never be positive, but I have to make it consistence
> with driver in other place, because all the check using if (err < 0) form.

Then all of them should be changed.

> And maybe, it make reserved for future the function may return positive
> value.

I'd prefer not to live in the world of 'what if'.  I think only
checking for a less than zero error value insinuates that a greater
than zero return is acceptable, but in this case is it not.

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 09/10] mfd: rtsx: add support for rts525A
  2015-01-19  2:53     ` 敬锐
@ 2015-01-19  7:41       ` Lee Jones
  0 siblings, 0 replies; 36+ messages in thread
From: Lee Jones @ 2015-01-19  7:41 UTC (permalink / raw)
  To: 敬锐
  Cc: sameo, devel, linux-kernel, gregkh, rogerable, 王炜

On Mon, 19 Jan 2015, 敬锐 wrote:

> 
> On 01/18/2015 07:13 PM, Lee Jones wrote:
> >> @@ -97,7 +97,7 @@ static void rts5249_force_power_down(struct rtsx_pcr *pcr, u8 pm_state)
> >> >  	rtsx_pci_write_register(pcr, AUTOLOAD_CFG_BASE + 3, 0x01, 0);
> >> >  
> >> >  	if (pm_state == HOST_ENTER_S3) {
> >> >-		if (PCI_PID(pcr) == 0x524A)
> >> >+		if (PCI_PID(pcr) == 0x524A || PCI_PID(pcr) == 0x525A)
> > Shouldn't these be defined somewhere?
> >
> > I have a particular distaste for magic numbers.
> >
> This is the chip ID number, no need define, just using it.
> if we define, it will like RTS525A_PCI_ID, so bad.

Looks good.  Please do that.
-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 06/10] mfd: rtsx: update phy register
  2015-01-19  1:55     ` 敬锐
@ 2015-01-19  7:47       ` Lee Jones
  2015-01-20  2:07         ` 敬锐
  0 siblings, 1 reply; 36+ messages in thread
From: Lee Jones @ 2015-01-19  7:47 UTC (permalink / raw)
  To: 敬锐
  Cc: sameo, devel, linux-kernel, gregkh, rogerable, 王炜

On Mon, 19 Jan 2015, 敬锐 wrote:
> On 01/18/2015 08:29 PM, Lee Jones wrote:
> > On Thu, 15 Jan 2015, micky_ching@realsil.com.cn wrote:
> >
> >> From: Micky Ching <micky_ching@realsil.com.cn>
> >>
> >> update phy register value and using direct value instead of macros.
> >> It is much easier to debug using constant value than a lot of macros.
> >> We usually need compare the value directly to check the configure.
> > NACK.  This is the opposite of what I would like to see.
> >
> When we debug, we usually need to compare the value provided from hardware,
> of course we can compare by print them to kernel log. but I think it more
> convenient from source code. And we only set phy register when 
> initialize chip,
> so the value will not scattered everywhere, we will not benefit from macros.
> 
> if we want to know the meaning of setting, we can look at the register 
> define.

This is not acceptable and is the complete opposite of what we're
trying to achieve.  I promote readability (by humans) as one of the
highest priorities when writing code.  0xFE6C is far from readable.

> >> Signed-off-by: Micky Ching <micky_ching@realsil.com.cn>
> >> ---
> >>   drivers/mfd/rts5249.c | 46 ++++++++++++++--------------------------------
> >>   1 file changed, 14 insertions(+), 32 deletions(-)
> >>
> >> diff --git a/drivers/mfd/rts5249.c b/drivers/mfd/rts5249.c
> >> index 2fe2854..00208d1 100644
> >> --- a/drivers/mfd/rts5249.c
> >> +++ b/drivers/mfd/rts5249.c
> >> @@ -132,57 +132,39 @@ static int rts5249_optimize_phy(struct rtsx_pcr *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 |
> >> -			PHY_REG_REV_RX_PWST | PHY_REG_REV_CLKREQ_DLY_TIMER_1_0 |
> >> -			PHY_REG_REV_STOP_CLKRD | PHY_REG_REV_STOP_CLKWR);
> >> +	err = rtsx_pci_write_phy_register(pcr, 0x19, 0xFE6C);
> >>   	if (err < 0)
> >>   		return err;
> >>   
> >>   	msleep(1);
> >>   
> >> -	err = rtsx_pci_write_phy_register(pcr, PHY_BPCR,
> >> -			PHY_BPCR_IBRXSEL | PHY_BPCR_IBTXSEL |
> >> -			PHY_BPCR_IB_FILTER | PHY_BPCR_CMIRROR_EN);
> >> +	err = rtsx_pci_write_phy_register(pcr, 0x0A, 0x05C0);
> >>   	if (err < 0)
> >>   		return err;
> >> -	err = rtsx_pci_write_phy_register(pcr, PHY_PCR,
> >> -			PHY_PCR_FORCE_CODE | PHY_PCR_OOBS_CALI_50 |
> >> -			PHY_PCR_OOBS_VCM_08 | PHY_PCR_OOBS_SEN_90 |
> >> -			PHY_PCR_RSSI_EN);
> >> +
> >> +	err = rtsx_pci_write_phy_register(pcr, 0x00, 0xBA43);
> >> +	if (err < 0)
> >> +		return err;
> >> +	err = rtsx_pci_write_phy_register(pcr, 0x03, 0xC152);
> >>   	if (err < 0)
> >>   		return err;
> >> -	err = rtsx_pci_write_phy_register(pcr, PHY_RCR2,
> >> -			PHY_RCR2_EMPHASE_EN | PHY_RCR2_NADJR |
> >> -			PHY_RCR2_CDR_CP_10 | PHY_RCR2_CDR_SR_2 |
> >> -			PHY_RCR2_FREQSEL_12 | PHY_RCR2_CPADJEN |
> >> -			PHY_RCR2_CDR_SC_8 | PHY_RCR2_CALIB_LATE);
> >> +	err = rtsx_pci_write_phy_register(pcr, 0x1E, 0x78EB);
> >>   	if (err < 0)
> >>   		return err;
> >> -	err = rtsx_pci_write_phy_register(pcr, PHY_FLD4,
> >> -			PHY_FLD4_FLDEN_SEL | PHY_FLD4_REQ_REF |
> >> -			PHY_FLD4_RXAMP_OFF | PHY_FLD4_REQ_ADDA |
> >> -			PHY_FLD4_BER_COUNT | PHY_FLD4_BER_TIMER |
> >> -			PHY_FLD4_BER_CHK_EN);
> >> +	err = rtsx_pci_write_phy_register(pcr, 0x05, 0x4600);
> >>   	if (err < 0)
> >>   		return err;
> >> -	err = rtsx_pci_write_phy_register(pcr, PHY_RDR, PHY_RDR_RXDSEL_1_9);
> >> +	err = rtsx_pci_write_phy_register(pcr, 0x02, 0x041F);
> >>   	if (err < 0)
> >>   		return err;
> >> -	err = rtsx_pci_write_phy_register(pcr, PHY_RCR1,
> >> -			PHY_RCR1_ADP_TIME | PHY_RCR1_VCO_COARSE);
> >> +	err = rtsx_pci_write_phy_register(pcr, 0x1D, 0x0824);
> >>   	if (err < 0)
> >>   		return err;
> >> -	err = rtsx_pci_write_phy_register(pcr, PHY_FLD3,
> >> -			PHY_FLD3_TIMER_4 | PHY_FLD3_TIMER_6 |
> >> -			PHY_FLD3_RXDELINK);
> >> +	err = rtsx_pci_write_phy_register(pcr, 0x08, 0x4FE4);
> >>   	if (err < 0)
> >>   		return err;
> >> -	return rtsx_pci_write_phy_register(pcr, PHY_TUNE,
> >> -			PHY_TUNE_TUNEREF_1_0 | PHY_TUNE_VBGSEL_1252 |
> >> -			PHY_TUNE_SDBUS_33 | PHY_TUNE_TUNED18 |
> >> -			PHY_TUNE_TUNED12);
> >> +
> >> +	return 0;
> >>   }
> >>   
> >>   static int rts5249_turn_on_led(struct rtsx_pcr *pcr)

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 01/10] mfd: rtsx: replace TAB by SPC after #define
  2015-01-19  1:23     ` 敬锐
@ 2015-01-19  7:49       ` Lee Jones
  0 siblings, 0 replies; 36+ messages in thread
From: Lee Jones @ 2015-01-19  7:49 UTC (permalink / raw)
  To: 敬锐
  Cc: sameo, devel, linux-kernel, gregkh, rogerable, 王炜

On Mon, 19 Jan 2015, 敬锐 wrote:

> 
> On 01/18/2015 08:39 PM, Lee Jones wrote:
> > On Thu, 15 Jan 2015, micky_ching@realsil.com.cn wrote:
> >
> >> From: Micky Ching <micky_ching@realsil.com.cn>
> >>
> >> Re-format coding-style, using uniform SPC after "#define" keyword
> >> instead of mixing using TAB and SPC.
> > Tabs and spaces in this context usually have different meanings
> > i.e. space after #define usually denotes that the following define is
> > a register address, whereas a tab commonly describes a bit field.
> >
> > Please ensure you're not messing with these conventions.  By the looks
> > of it you are not, but I need you to confirm that you know what you're
> > doing.
> if using TAB describe a bit field, and define TAB length = 8 SPC,
> the editor will not show any difference(if not highlight TAB/SPC).
> And the mix is not to show difference between address and field.
> so all replaced by space, and show difference by next patch(02/10).

Okay, so you have gone for a 1 space/2 space to differentiate.

Sounds good.

Acked-by: Lee Jones <lee.jones@linaro.org>

> >> Signed-off-by: Micky Ching <micky_ching@realsil.com.cn>
> >> ---
> >>   include/linux/mfd/rtsx_pci.h | 254 +++++++++++++++++++++----------------------
> >>   1 file changed, 127 insertions(+), 127 deletions(-)
> >>
> >> diff --git a/include/linux/mfd/rtsx_pci.h b/include/linux/mfd/rtsx_pci.h
> >> index 0c12628..a9c2a14 100644
> >> --- a/include/linux/mfd/rtsx_pci.h
> >> +++ b/include/linux/mfd/rtsx_pci.h
> >> @@ -175,9 +175,9 @@
> >>   /* CARD_SHARE_MODE */
> >>   #define CARD_SHARE_MASK			0x0F
> >>   #define CARD_SHARE_MULTI_LUN		0x00
> >> -#define	CARD_SHARE_NORMAL		0x00
> >> -#define	CARD_SHARE_48_SD		0x04
> >> -#define	CARD_SHARE_48_MS		0x08
> >> +#define CARD_SHARE_NORMAL		0x00
> >> +#define CARD_SHARE_48_SD		0x04
> >> +#define CARD_SHARE_48_MS		0x08
> >>   /* CARD_SHARE_MODE for barossa */
> >>   #define CARD_SHARE_BAROSSA_SD		0x01
> >>   #define CARD_SHARE_BAROSSA_MS		0x02
> >> @@ -249,76 +249,76 @@
> >>   #define CD_AUTO_DISABLE			0x40
> >>   
> >>   /* SD_STAT1 */
> >> -#define	SD_CRC7_ERR			0x80
> >> -#define	SD_CRC16_ERR			0x40
> >> -#define	SD_CRC_WRITE_ERR		0x20
> >> -#define	SD_CRC_WRITE_ERR_MASK		0x1C
> >> -#define	GET_CRC_TIME_OUT		0x02
> >> -#define	SD_TUNING_COMPARE_ERR		0x01
> >> +#define SD_CRC7_ERR			0x80
> >> +#define SD_CRC16_ERR			0x40
> >> +#define SD_CRC_WRITE_ERR		0x20
> >> +#define SD_CRC_WRITE_ERR_MASK		0x1C
> >> +#define GET_CRC_TIME_OUT		0x02
> >> +#define SD_TUNING_COMPARE_ERR		0x01
> >>   
> >>   /* SD_STAT2 */
> >> -#define	SD_RSP_80CLK_TIMEOUT		0x01
> >> +#define SD_RSP_80CLK_TIMEOUT		0x01
> >>   
> >>   /* SD_BUS_STAT */
> >> -#define	SD_CLK_TOGGLE_EN		0x80
> >> -#define	SD_CLK_FORCE_STOP	        0x40
> >> -#define	SD_DAT3_STATUS		        0x10
> >> -#define	SD_DAT2_STATUS		        0x08
> >> -#define	SD_DAT1_STATUS		        0x04
> >> -#define	SD_DAT0_STATUS		        0x02
> >> -#define	SD_CMD_STATUS			0x01
> >> +#define SD_CLK_TOGGLE_EN		0x80
> >> +#define SD_CLK_FORCE_STOP	        0x40
> >> +#define SD_DAT3_STATUS		        0x10
> >> +#define SD_DAT2_STATUS		        0x08
> >> +#define SD_DAT1_STATUS		        0x04
> >> +#define SD_DAT0_STATUS		        0x02
> >> +#define SD_CMD_STATUS			0x01
> >>   
> >>   /* SD_PAD_CTL */
> >> -#define	SD_IO_USING_1V8		        0x80
> >> -#define	SD_IO_USING_3V3		        0x7F
> >> -#define	TYPE_A_DRIVING		        0x00
> >> -#define	TYPE_B_DRIVING			0x01
> >> -#define	TYPE_C_DRIVING			0x02
> >> -#define	TYPE_D_DRIVING		        0x03
> >> +#define SD_IO_USING_1V8		        0x80
> >> +#define SD_IO_USING_3V3		        0x7F
> >> +#define TYPE_A_DRIVING		        0x00
> >> +#define TYPE_B_DRIVING			0x01
> >> +#define TYPE_C_DRIVING			0x02
> >> +#define TYPE_D_DRIVING		        0x03
> >>   
> >>   /* SD_SAMPLE_POINT_CTL */
> >> -#define	DDR_FIX_RX_DAT			0x00
> >> -#define	DDR_VAR_RX_DAT			0x80
> >> -#define	DDR_FIX_RX_DAT_EDGE		0x00
> >> -#define	DDR_FIX_RX_DAT_14_DELAY		0x40
> >> -#define	DDR_FIX_RX_CMD			0x00
> >> -#define	DDR_VAR_RX_CMD			0x20
> >> -#define	DDR_FIX_RX_CMD_POS_EDGE		0x00
> >> -#define	DDR_FIX_RX_CMD_14_DELAY		0x10
> >> -#define	SD20_RX_POS_EDGE		0x00
> >> -#define	SD20_RX_14_DELAY		0x08
> >> +#define DDR_FIX_RX_DAT			0x00
> >> +#define DDR_VAR_RX_DAT			0x80
> >> +#define DDR_FIX_RX_DAT_EDGE		0x00
> >> +#define DDR_FIX_RX_DAT_14_DELAY		0x40
> >> +#define DDR_FIX_RX_CMD			0x00
> >> +#define DDR_VAR_RX_CMD			0x20
> >> +#define DDR_FIX_RX_CMD_POS_EDGE		0x00
> >> +#define DDR_FIX_RX_CMD_14_DELAY		0x10
> >> +#define SD20_RX_POS_EDGE		0x00
> >> +#define SD20_RX_14_DELAY		0x08
> >>   #define SD20_RX_SEL_MASK		0x08
> >>   
> >>   /* SD_PUSH_POINT_CTL */
> >> -#define	DDR_FIX_TX_CMD_DAT		0x00
> >> -#define	DDR_VAR_TX_CMD_DAT		0x80
> >> -#define	DDR_FIX_TX_DAT_14_TSU		0x00
> >> -#define	DDR_FIX_TX_DAT_12_TSU		0x40
> >> -#define	DDR_FIX_TX_CMD_NEG_EDGE		0x00
> >> -#define	DDR_FIX_TX_CMD_14_AHEAD		0x20
> >> -#define	SD20_TX_NEG_EDGE		0x00
> >> -#define	SD20_TX_14_AHEAD		0x10
> >> +#define DDR_FIX_TX_CMD_DAT		0x00
> >> +#define DDR_VAR_TX_CMD_DAT		0x80
> >> +#define DDR_FIX_TX_DAT_14_TSU		0x00
> >> +#define DDR_FIX_TX_DAT_12_TSU		0x40
> >> +#define DDR_FIX_TX_CMD_NEG_EDGE		0x00
> >> +#define DDR_FIX_TX_CMD_14_AHEAD		0x20
> >> +#define SD20_TX_NEG_EDGE		0x00
> >> +#define SD20_TX_14_AHEAD		0x10
> >>   #define SD20_TX_SEL_MASK		0x10
> >> -#define	DDR_VAR_SDCLK_POL_SWAP		0x01
> >> +#define DDR_VAR_SDCLK_POL_SWAP		0x01
> >>   
> >>   /* SD_TRANSFER */
> >> -#define	SD_TRANSFER_START		0x80
> >> -#define	SD_TRANSFER_END			0x40
> >> +#define SD_TRANSFER_START		0x80
> >> +#define SD_TRANSFER_END			0x40
> >>   #define SD_STAT_IDLE			0x20
> >> -#define	SD_TRANSFER_ERR			0x10
> >> +#define SD_TRANSFER_ERR			0x10
> >>   /* SD Transfer Mode definition */
> >> -#define	SD_TM_NORMAL_WRITE		0x00
> >> -#define	SD_TM_AUTO_WRITE_3		0x01
> >> -#define	SD_TM_AUTO_WRITE_4		0x02
> >> -#define	SD_TM_AUTO_READ_3		0x05
> >> -#define	SD_TM_AUTO_READ_4		0x06
> >> -#define	SD_TM_CMD_RSP			0x08
> >> -#define	SD_TM_AUTO_WRITE_1		0x09
> >> -#define	SD_TM_AUTO_WRITE_2		0x0A
> >> -#define	SD_TM_NORMAL_READ		0x0C
> >> -#define	SD_TM_AUTO_READ_1		0x0D
> >> -#define	SD_TM_AUTO_READ_2		0x0E
> >> -#define	SD_TM_AUTO_TUNING		0x0F
> >> +#define SD_TM_NORMAL_WRITE		0x00
> >> +#define SD_TM_AUTO_WRITE_3		0x01
> >> +#define SD_TM_AUTO_WRITE_4		0x02
> >> +#define SD_TM_AUTO_READ_3		0x05
> >> +#define SD_TM_AUTO_READ_4		0x06
> >> +#define SD_TM_CMD_RSP			0x08
> >> +#define SD_TM_AUTO_WRITE_1		0x09
> >> +#define SD_TM_AUTO_WRITE_2		0x0A
> >> +#define SD_TM_NORMAL_READ		0x0C
> >> +#define SD_TM_AUTO_READ_1		0x0D
> >> +#define SD_TM_AUTO_READ_2		0x0E
> >> +#define SD_TM_AUTO_TUNING		0x0F
> >>   
> >>   /* SD_VPTX_CTL / SD_VPRX_CTL */
> >>   #define PHASE_CHANGE			0x80
> >> @@ -332,15 +332,15 @@
> >>   
> >>   /* SD Configure 1 Register */
> >>   #define SD_CLK_DIVIDE_0			0x00
> >> -#define	SD_CLK_DIVIDE_256		0xC0
> >> -#define	SD_CLK_DIVIDE_128		0x80
> >> -#define	SD_BUS_WIDTH_1BIT		0x00
> >> -#define	SD_BUS_WIDTH_4BIT		0x01
> >> -#define	SD_BUS_WIDTH_8BIT		0x02
> >> -#define	SD_ASYNC_FIFO_NOT_RST		0x10
> >> -#define	SD_20_MODE			0x00
> >> -#define	SD_DDR_MODE			0x04
> >> -#define	SD_30_MODE			0x08
> >> +#define SD_CLK_DIVIDE_256		0xC0
> >> +#define SD_CLK_DIVIDE_128		0x80
> >> +#define SD_BUS_WIDTH_1BIT		0x00
> >> +#define SD_BUS_WIDTH_4BIT		0x01
> >> +#define SD_BUS_WIDTH_8BIT		0x02
> >> +#define SD_ASYNC_FIFO_NOT_RST		0x10
> >> +#define SD_20_MODE			0x00
> >> +#define SD_DDR_MODE			0x04
> >> +#define SD_30_MODE			0x08
> >>   
> >>   #define SD_CLK_DIVIDE_MASK		0xC0
> >>   
> >> @@ -415,71 +415,71 @@
> >>   #define CLK_DIV_8			0x04
> >>   
> >>   /* MS_CFG */
> >> -#define	SAMPLE_TIME_RISING		0x00
> >> -#define	SAMPLE_TIME_FALLING		0x80
> >> -#define	PUSH_TIME_DEFAULT		0x00
> >> -#define	PUSH_TIME_ODD			0x40
> >> -#define	NO_EXTEND_TOGGLE		0x00
> >> -#define	EXTEND_TOGGLE_CHK		0x20
> >> -#define	MS_BUS_WIDTH_1			0x00
> >> -#define	MS_BUS_WIDTH_4			0x10
> >> -#define	MS_BUS_WIDTH_8			0x18
> >> -#define	MS_2K_SECTOR_MODE		0x04
> >> -#define	MS_512_SECTOR_MODE		0x00
> >> -#define	MS_TOGGLE_TIMEOUT_EN		0x00
> >> -#define	MS_TOGGLE_TIMEOUT_DISEN		0x01
> >> +#define SAMPLE_TIME_RISING		0x00
> >> +#define SAMPLE_TIME_FALLING		0x80
> >> +#define PUSH_TIME_DEFAULT		0x00
> >> +#define PUSH_TIME_ODD			0x40
> >> +#define NO_EXTEND_TOGGLE		0x00
> >> +#define EXTEND_TOGGLE_CHK		0x20
> >> +#define MS_BUS_WIDTH_1			0x00
> >> +#define MS_BUS_WIDTH_4			0x10
> >> +#define MS_BUS_WIDTH_8			0x18
> >> +#define MS_2K_SECTOR_MODE		0x04
> >> +#define MS_512_SECTOR_MODE		0x00
> >> +#define MS_TOGGLE_TIMEOUT_EN		0x00
> >> +#define MS_TOGGLE_TIMEOUT_DISEN		0x01
> >>   #define MS_NO_CHECK_INT			0x02
> >>   
> >>   /* MS_TRANS_CFG */
> >> -#define	WAIT_INT			0x80
> >> -#define	NO_WAIT_INT			0x00
> >> -#define	NO_AUTO_READ_INT_REG		0x00
> >> -#define	AUTO_READ_INT_REG		0x40
> >> -#define	MS_CRC16_ERR			0x20
> >> -#define	MS_RDY_TIMEOUT			0x10
> >> -#define	MS_INT_CMDNK			0x08
> >> -#define	MS_INT_BREQ			0x04
> >> -#define	MS_INT_ERR			0x02
> >> -#define	MS_INT_CED			0x01
> >> +#define WAIT_INT			0x80
> >> +#define NO_WAIT_INT			0x00
> >> +#define NO_AUTO_READ_INT_REG		0x00
> >> +#define AUTO_READ_INT_REG		0x40
> >> +#define MS_CRC16_ERR			0x20
> >> +#define MS_RDY_TIMEOUT			0x10
> >> +#define MS_INT_CMDNK			0x08
> >> +#define MS_INT_BREQ			0x04
> >> +#define MS_INT_ERR			0x02
> >> +#define MS_INT_CED			0x01
> >>   
> >>   /* MS_TRANSFER */
> >> -#define	MS_TRANSFER_START		0x80
> >> -#define	MS_TRANSFER_END			0x40
> >> -#define	MS_TRANSFER_ERR			0x20
> >> -#define	MS_BS_STATE			0x10
> >> -#define	MS_TM_READ_BYTES		0x00
> >> -#define	MS_TM_NORMAL_READ		0x01
> >> -#define	MS_TM_WRITE_BYTES		0x04
> >> -#define	MS_TM_NORMAL_WRITE		0x05
> >> -#define	MS_TM_AUTO_READ			0x08
> >> -#define	MS_TM_AUTO_WRITE		0x0C
> >> +#define MS_TRANSFER_START		0x80
> >> +#define MS_TRANSFER_END			0x40
> >> +#define MS_TRANSFER_ERR			0x20
> >> +#define MS_BS_STATE			0x10
> >> +#define MS_TM_READ_BYTES		0x00
> >> +#define MS_TM_NORMAL_READ		0x01
> >> +#define MS_TM_WRITE_BYTES		0x04
> >> +#define MS_TM_NORMAL_WRITE		0x05
> >> +#define MS_TM_AUTO_READ			0x08
> >> +#define MS_TM_AUTO_WRITE		0x0C
> >>   
> >>   /* SD Configure 2 Register */
> >> -#define	SD_CALCULATE_CRC7		0x00
> >> -#define	SD_NO_CALCULATE_CRC7		0x80
> >> -#define	SD_CHECK_CRC16			0x00
> >> -#define	SD_NO_CHECK_CRC16		0x40
> >> +#define SD_CALCULATE_CRC7		0x00
> >> +#define SD_NO_CALCULATE_CRC7		0x80
> >> +#define SD_CHECK_CRC16			0x00
> >> +#define SD_NO_CHECK_CRC16		0x40
> >>   #define SD_NO_CHECK_WAIT_CRC_TO		0x20
> >> -#define	SD_WAIT_BUSY_END		0x08
> >> -#define	SD_NO_WAIT_BUSY_END		0x00
> >> -#define	SD_CHECK_CRC7			0x00
> >> -#define	SD_NO_CHECK_CRC7		0x04
> >> -#define	SD_RSP_LEN_0			0x00
> >> -#define	SD_RSP_LEN_6			0x01
> >> -#define	SD_RSP_LEN_17			0x02
> >> +#define SD_WAIT_BUSY_END		0x08
> >> +#define SD_NO_WAIT_BUSY_END		0x00
> >> +#define SD_CHECK_CRC7			0x00
> >> +#define SD_NO_CHECK_CRC7		0x04
> >> +#define SD_RSP_LEN_0			0x00
> >> +#define SD_RSP_LEN_6			0x01
> >> +#define SD_RSP_LEN_17			0x02
> >>   /* SD/MMC Response Type Definition */
> >> -#define	SD_RSP_TYPE_R0			0x04
> >> -#define	SD_RSP_TYPE_R1			0x01
> >> -#define	SD_RSP_TYPE_R1b			0x09
> >> -#define	SD_RSP_TYPE_R2			0x02
> >> -#define	SD_RSP_TYPE_R3			0x05
> >> -#define	SD_RSP_TYPE_R4			0x05
> >> -#define	SD_RSP_TYPE_R5			0x01
> >> -#define	SD_RSP_TYPE_R6			0x01
> >> -#define	SD_RSP_TYPE_R7			0x01
> >> +#define SD_RSP_TYPE_R0			0x04
> >> +#define SD_RSP_TYPE_R1			0x01
> >> +#define SD_RSP_TYPE_R1b			0x09
> >> +#define SD_RSP_TYPE_R2			0x02
> >> +#define SD_RSP_TYPE_R3			0x05
> >> +#define SD_RSP_TYPE_R4			0x05
> >> +#define SD_RSP_TYPE_R5			0x01
> >> +#define SD_RSP_TYPE_R6			0x01
> >> +#define SD_RSP_TYPE_R7			0x01
> >>   
> >>   /* SD_CONFIGURE3 */
> >> -#define	SD_RSP_80CLK_TIMEOUT_EN		0x01
> >> +#define SD_RSP_80CLK_TIMEOUT_EN		0x01
> >>   
> >>   /* Card Transfer Reset Register */
> >>   #define SPI_STOP			0x01
> >> @@ -574,13 +574,13 @@
> >>   
> >>   #define SRCTL				0xFC13
> >>   
> >> -#define	DCM_DRP_CTL			0xFC23
> >> -#define	DCM_DRP_TRIG			0xFC24
> >> -#define	DCM_DRP_CFG			0xFC25
> >> -#define	DCM_DRP_WR_DATA_L		0xFC26
> >> -#define	DCM_DRP_WR_DATA_H		0xFC27
> >> -#define	DCM_DRP_RD_DATA_L		0xFC28
> >> -#define	DCM_DRP_RD_DATA_H		0xFC29
> >> +#define DCM_DRP_CTL			0xFC23
> >> +#define DCM_DRP_TRIG			0xFC24
> >> +#define DCM_DRP_CFG			0xFC25
> >> +#define DCM_DRP_WR_DATA_L		0xFC26
> >> +#define DCM_DRP_WR_DATA_H		0xFC27
> >> +#define DCM_DRP_RD_DATA_L		0xFC28
> >> +#define DCM_DRP_RD_DATA_H		0xFC29
> >>   #define SD_VPCLK0_CTL			0xFC2A
> >>   #define SD_VPCLK1_CTL			0xFC2B
> >>   #define SD_DCMPS0_CTL			0xFC2C

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 07/10] mfd: rtsx: remove LCTLR defination
  2015-01-19  1:12     ` 敬锐
@ 2015-01-19  8:06       ` Lee Jones
  0 siblings, 0 replies; 36+ messages in thread
From: Lee Jones @ 2015-01-19  8:06 UTC (permalink / raw)
  To: 敬锐
  Cc: sameo, devel, linux-kernel, gregkh, rogerable, 王炜

On Mon, 19 Jan 2015, 敬锐 wrote:

> 
> On 01/18/2015 08:28 PM, Lee Jones wrote:
> > On Thu, 15 Jan 2015, micky_ching@realsil.com.cn wrote:
> >
> >> From: Micky Ching <micky_ching@realsil.com.cn>
> >>
> >> To enable/disable ASPM we should find LINK CONTROL register
> >> in PCI config space. All old chip use 0x80 address, but new
> >> chip may use another address, so we using pci_find_capability()
> >> to get LINK CONTROL address.
> >>
> >> rtsx_gops.c was removed, we consider to put some common operations
> >> to this file, but the actual thing is, only a group of chips
> >> are in common ops1, and another group of chips in common ops2,
> >> it is hard to decide put which ops into generic ops file.
> >>
> >> Signed-off-by: Micky Ching <micky_ching@realsil.com.cn>
> >> ---
> >>   drivers/mfd/Makefile         |  2 +-
> >>   drivers/mfd/rts5227.c        |  2 +-
> >>   drivers/mfd/rts5249.c        |  3 +--
> >>   drivers/mfd/rtsx_gops.c      | 37 -------------------------------------
> >>   drivers/mfd/rtsx_pcr.c       | 25 ++++++++++++++++++++-----
> >>   include/linux/mfd/rtsx_pci.h |  9 ---------
> >>   6 files changed, 23 insertions(+), 55 deletions(-)
> >>   delete mode 100644 drivers/mfd/rtsx_gops.c
> >>
> >> diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
> >> index 53467e2..2cd7e74 100644
> >> --- a/drivers/mfd/Makefile
> >> +++ b/drivers/mfd/Makefile
> >> @@ -13,7 +13,7 @@ obj-$(CONFIG_MFD_CROS_EC)	+= cros_ec.o
> >>   obj-$(CONFIG_MFD_CROS_EC_I2C)	+= cros_ec_i2c.o
> >>   obj-$(CONFIG_MFD_CROS_EC_SPI)	+= cros_ec_spi.o
> >>   
> >> -rtsx_pci-objs			:= rtsx_pcr.o rtsx_gops.o rts5209.o rts5229.o rtl8411.o rts5227.o rts5249.o
> >> +rtsx_pci-objs			:= rtsx_pcr.o rts5209.o rts5229.o rtl8411.o rts5227.o rts5249.o
> >>   obj-$(CONFIG_MFD_RTSX_PCI)	+= rtsx_pci.o
> >>   obj-$(CONFIG_MFD_RTSX_USB)	+= rtsx_usb.o
> >>   
> >> diff --git a/drivers/mfd/rts5227.c b/drivers/mfd/rts5227.c
> >> index 1f387d4..0c02831 100644
> >> --- a/drivers/mfd/rts5227.c
> >> +++ b/drivers/mfd/rts5227.c
> >> @@ -130,7 +130,7 @@ static int rts5227_optimize_phy(struct rtsx_pcr *pcr)
> >>   {
> >>   	int err;
> >>   
> >> -	err = rtsx_gops_pm_reset(pcr);
> >> +	err = rtsx_pci_write_register(pcr, PM_CTRL3, D3_DELINK_MODE_EN, 0x00);
> >>   	if (err < 0)
> >>   		return err;
> >>   
> >> diff --git a/drivers/mfd/rts5249.c b/drivers/mfd/rts5249.c
> >> index 00208d1..5eb9819 100644
> >> --- a/drivers/mfd/rts5249.c
> >> +++ b/drivers/mfd/rts5249.c
> >> @@ -119,7 +119,6 @@ static int rts5249_extra_init_hw(struct rtsx_pcr *pcr)
> >>   		rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PETXCFG, 0xB0, 0xB0);
> >>   	else
> >>   		rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PETXCFG, 0xB0, 0x80);
> >> -	rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PM_CTRL3, 0x10, 0x00);
> > What's this doing?  Why is it not required anymore?
> PM_CTRL3 have been set in rts5249_optimize_phy, this function
> rts5249_extra_init will be call for rts524A/rts525A, but their PM_CTRL3
> address is redefined to RTS524A_PM_CTRL3, using a different address.
> if we set PM_CTRL3 here, the rts524A/rts525A will also set,
> but it's not a right address.

Okay.

> >>   	return rtsx_pci_send_cmd(pcr, 100);
> >>   }
> >> @@ -128,7 +127,7 @@ static int rts5249_optimize_phy(struct rtsx_pcr *pcr)
> >>   {
> >>   	int err;
> >>   
> >> -	err = rtsx_gops_pm_reset(pcr);
> >> +	err = rtsx_pci_write_register(pcr, PM_CTRL3, D3_DELINK_MODE_EN, 0x00);
> >>   	if (err < 0)
> >>   		return err;
> >>   
> >> diff --git a/drivers/mfd/rtsx_gops.c b/drivers/mfd/rtsx_gops.c
> >> deleted file mode 100644
> >> index b1a98c6..0000000
> >> --- a/drivers/mfd/rtsx_gops.c
> >> +++ /dev/null
> >> @@ -1,37 +0,0 @@
> >> -/* Driver for Realtek PCI-Express card reader
> >> - *
> >> - * Copyright(c) 2009-2013 Realtek Semiconductor Corp. All rights reserved.
> >> - *
> >> - * This program is free software; you can redistribute it and/or modify it
> >> - * under the terms of the GNU General Public License as published by the
> >> - * Free Software Foundation; either version 2, or (at your option) any
> >> - * later version.
> >> - *
> >> - * This program is distributed in the hope that it will be useful, but
> >> - * WITHOUT ANY WARRANTY; without even the implied warranty of
> >> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> >> - * General Public License for more details.
> >> - *
> >> - * You should have received a copy of the GNU General Public License along
> >> - * with this program; if not, see <http://www.gnu.org/licenses/>.
> >> - *
> >> - * Author:
> >> - *   Micky Ching <micky_ching@realsil.com.cn>
> >> - */
> >> -
> >> -#include <linux/mfd/rtsx_pci.h>
> >> -#include "rtsx_pcr.h"
> >> -
> >> -int rtsx_gops_pm_reset(struct rtsx_pcr *pcr)
> >> -{
> >> -	int err;
> >> -
> >> -	/* init aspm */
> >> -	rtsx_pci_write_register(pcr, ASPM_FORCE_CTL, 0xFF, 0x00);
> >> -	err = rtsx_pci_update_cfg_byte(pcr, LCTLR, ~LCTLR_ASPM_CTL_MASK, 0x00);
> >> -	if (err < 0)
> >> -		return err;
> >> -
> >> -	/* reset PM_CTRL3 before send buffer cmd */
> >> -	return rtsx_pci_write_register(pcr, PM_CTRL3, D3_DELINK_MODE_EN, 0x00);
> >> -}
> >> diff --git a/drivers/mfd/rtsx_pcr.c b/drivers/mfd/rtsx_pcr.c
> >> index 92f5a41..3065edc 100644
> >> --- a/drivers/mfd/rtsx_pcr.c
> >> +++ b/drivers/mfd/rtsx_pcr.c
> >> @@ -63,6 +63,20 @@ static const struct pci_device_id rtsx_pci_ids[] = {
> >>   
> >>   MODULE_DEVICE_TABLE(pci, rtsx_pci_ids);
> >>   
> >> +static inline void rtsx_pci_enable_aspm(struct rtsx_pcr *pcr)
> >> +{
> >> +	int exp = pci_find_capability(pcr->pci, PCI_CAP_ID_EXP);
> >> +
> >> +	rtsx_pci_update_cfg_byte(pcr, exp + PCI_EXP_LNKCTL, 0xFC, pcr->aspm_en);
> >> +}
> >> +
> >> +static inline void rtsx_pci_disable_aspm(struct rtsx_pcr *pcr)
> >> +{
> >> +	int exp = pci_find_capability(pcr->pci, PCI_CAP_ID_EXP);
> >> +
> >> +	rtsx_pci_update_cfg_byte(pcr, exp + PCI_EXP_LNKCTL, 0xFC, 0);
> >> +}
> >> +
> >>   void rtsx_pci_start_run(struct rtsx_pcr *pcr)
> >>   {
> >>   	/* If pci device removed, don't queue idle work any more */
> >> @@ -75,7 +89,8 @@ void rtsx_pci_start_run(struct rtsx_pcr *pcr)
> >>   			pcr->ops->enable_auto_blink(pcr);
> >>   
> >>   		if (pcr->aspm_en)
> >> -			rtsx_pci_write_config_byte(pcr, LCTLR, 0);
> >> +			rtsx_pci_disable_aspm(pcr);
> >> +
> > ?
> We set LCTLR to disable aspm, all old chip using 0x80 address,
> but new chip will not use this address, the best way to find
> this address is using pci_find_capability().

I was more concerned with the random '\n' you are adding here.

> >>   	}
> >>   
> >>   	mod_delayed_work(system_wq, &pcr->idle_work, msecs_to_jiffies(200));
> >> @@ -954,7 +969,7 @@ static void rtsx_pci_idle_work(struct work_struct *work)
> >>   		pcr->ops->turn_off_led(pcr);
> >>   
> >>   	if (pcr->aspm_en)
> >> -		rtsx_pci_write_config_byte(pcr, LCTLR, pcr->aspm_en);
> >> +		rtsx_pci_enable_aspm(pcr);
> >>   
> >>   	mutex_unlock(&pcr->pcr_mutex);
> >>   }
> >> @@ -979,6 +994,7 @@ static void rtsx_pci_power_off(struct rtsx_pcr *pcr, u8 pm_state)
> >>   static int rtsx_pci_init_hw(struct rtsx_pcr *pcr)
> >>   {
> >>   	int err;
> >> +	int exp = pci_find_capability(pcr->pci, PCI_CAP_ID_EXP);
> >>   
> >>   	rtsx_pci_writel(pcr, RTSX_HCBAR, pcr->host_cmds_addr);
> >>   
> >> @@ -992,6 +1008,7 @@ static int rtsx_pci_init_hw(struct rtsx_pcr *pcr)
> >>   	/* Wait SSC power stable */
> >>   	udelay(200);
> >>   
> >> +	rtsx_pci_disable_aspm(pcr);
> >>   	if (pcr->ops->optimize_phy) {
> >>   		err = pcr->ops->optimize_phy(pcr);
> >>   		if (err < 0)
> >> @@ -1040,10 +1057,8 @@ static int rtsx_pci_init_hw(struct rtsx_pcr *pcr)
> >>   	if (err < 0)
> >>   		return err;
> >>   
> >> -	rtsx_pci_write_config_byte(pcr, LCTLR, 0);
> >> -
> >>   	/* Enable clk_request_n to enable clock power management */
> >> -	rtsx_pci_write_config_byte(pcr, 0x81, 1);
> >> +	rtsx_pci_write_config_byte(pcr, exp + PCI_EXP_LNKCTL + 1, 1);
> >>   	/* Enter L1 when host tx idle */
> >>   	rtsx_pci_write_config_byte(pcr, 0x70F, 0x5B);
> >>   
> >> diff --git a/include/linux/mfd/rtsx_pci.h b/include/linux/mfd/rtsx_pci.h
> >> index 80baa10..f7cebdb 100644
> >> --- a/include/linux/mfd/rtsx_pci.h
> >> +++ b/include/linux/mfd/rtsx_pci.h
> >> @@ -662,15 +662,6 @@
> >>   #define PHY_FLD4			0x1E
> >>   #define PHY_DUM_REG			0x1F
> >>   
> >> -#define LCTLR				0x80
> >> -#define   LCTLR_EXT_SYNC		0x80
> >> -#define   LCTLR_COMMON_CLOCK_CFG	0x40
> >> -#define   LCTLR_RETRAIN_LINK		0x20
> >> -#define   LCTLR_LINK_DISABLE		0x10
> >> -#define   LCTLR_RCB			0x08
> >> -#define   LCTLR_RESERVED		0x04
> >> -#define   LCTLR_ASPM_CTL_MASK		0x03
> >> -
> >>   #define PCR_SETTING_REG1		0x724
> >>   #define PCR_SETTING_REG2		0x814
> >>   #define PCR_SETTING_REG3		0x747

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 06/10] mfd: rtsx: update phy register
  2015-01-19  7:47       ` Lee Jones
@ 2015-01-20  2:07         ` 敬锐
  2015-01-20  9:45           ` Lee Jones
  0 siblings, 1 reply; 36+ messages in thread
From: 敬锐 @ 2015-01-20  2:07 UTC (permalink / raw)
  To: Lee Jones; +Cc: sameo, devel, linux-kernel, gregkh, rogerable, 王炜

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 2213 bytes --]


On 01/19/2015 03:47 PM, Lee Jones wrote:
> On Mon, 19 Jan 2015, 敬锐 wrote:
>> >On 01/18/2015 08:29 PM, Lee Jones wrote:
>>> > >On Thu, 15 Jan 2015,micky_ching@realsil.com.cn  wrote:
>>> > >
>>>> > >>From: Micky Ching<micky_ching@realsil.com.cn>
>>>> > >>
>>>> > >>update phy register value and using direct value instead of macros.
>>>> > >>It is much easier to debug using constant value than a lot of macros.
>>>> > >>We usually need compare the value directly to check the configure.
>>> > >NACK.  This is the opposite of what I would like to see.
>>> > >
>> >When we debug, we usually need to compare the value provided from hardware,
>> >of course we can compare by print them to kernel log. but I think it more
>> >convenient from source code. And we only set phy register when
>> >initialize chip,
>> >so the value will not scattered everywhere, we will not benefit from macros.
>> >
>> >if we want to know the meaning of setting, we can look at the register
>> >define.
> This is not acceptable and is the complete opposite of what we're
> trying to achieve.  I promote readability (by humans) as one of the
> highest priorities when writing code.  0xFE6C is far from readable.
>
Because the truly thing we concerned is the address and value, not
a lot of macros. 0xFE6C is a magic number, but a lot of macros
even hide the magic number we curious. To verify if the source
code is right, we only need to compare the value, if too much macros
joined together, the work is boring and easy to inject errors.
I hate magic number too, but in this case using magic number
is deserved for correctness.

Two method can help enhance readability.
(1). define register address and values
If we want to know what the bit field means, we can jump to the register
define. This is very easy by tag system.
eg.
rtsx_pci_write_phy_register(pcr, PHY_BPCR, 0x05C0);
we can jump to PHY_BPCR to see bit-field define.

(2). add comment for magic number.
I don't like comment.

If you still like macro list, I will update the register next patch.

regards.
micky.
ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 06/10] mfd: rtsx: update phy register
  2015-01-20  2:07         ` 敬锐
@ 2015-01-20  9:45           ` Lee Jones
  0 siblings, 0 replies; 36+ messages in thread
From: Lee Jones @ 2015-01-20  9:45 UTC (permalink / raw)
  To: 敬锐
  Cc: sameo, devel, linux-kernel, gregkh, rogerable, 王炜

On Tue, 20 Jan 2015, 敬锐 wrote:
> On 01/19/2015 03:47 PM, Lee Jones wrote:
> > On Mon, 19 Jan 2015, 敬锐 wrote:
> >> >On 01/18/2015 08:29 PM, Lee Jones wrote:
> >>> > >On Thu, 15 Jan 2015,micky_ching@realsil.com.cn  wrote:
> >>> > >
> >>>> > >>From: Micky Ching<micky_ching@realsil.com.cn>
> >>>> > >>
> >>>> > >>update phy register value and using direct value instead of macros.
> >>>> > >>It is much easier to debug using constant value than a lot of macros.
> >>>> > >>We usually need compare the value directly to check the configure.
> >>> > >NACK.  This is the opposite of what I would like to see.
> >>> > >
> >> >When we debug, we usually need to compare the value provided from hardware,
> >> >of course we can compare by print them to kernel log. but I think it more
> >> >convenient from source code. And we only set phy register when
> >> >initialize chip,
> >> >so the value will not scattered everywhere, we will not benefit from macros.
> >> >
> >> >if we want to know the meaning of setting, we can look at the register
> >> >define.
> > This is not acceptable and is the complete opposite of what we're
> > trying to achieve.  I promote readability (by humans) as one of the
> > highest priorities when writing code.  0xFE6C is far from readable.
> >
> Because the truly thing we concerned is the address and value, not
> a lot of macros. 0xFE6C is a magic number, but a lot of macros
> even hide the magic number we curious. To verify if the source
> code is right, we only need to compare the value, if too much macros
> joined together, the work is boring and easy to inject errors.

I completely disagree and think the converse to be true.  It's _much_
easier to get the magic number incorrect.

> I hate magic number too, but in this case using magic number
> is deserved for correctness.
> 
> Two method can help enhance readability.
> (1). define register address and values
> If we want to know what the bit field means, we can jump to the register
> define. This is very easy by tag system.
> eg.
> rtsx_pci_write_phy_register(pcr, PHY_BPCR, 0x05C0);
> we can jump to PHY_BPCR to see bit-field define.
>
> (2). add comment for magic number.
> I don't like comment.
> 
> If you still like macro list, I will update the register next patch.

Defining register values and bit fields is the _correct_ way to do
this.  Using magic numbers is the _wrong_ way.

I'm sorry Micky, but I am not moving on this.

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 36+ messages in thread

end of thread, other threads:[~2015-01-20  9:46 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-15 11:18 [PATCH 00/10] mfd: rtsx: add support for new rts524A and rts525A micky_ching
2015-01-15 11:18 ` [PATCH 01/10] mfd: rtsx: replace TAB by SPC after #define micky_ching
2015-01-18 12:39   ` Lee Jones
2015-01-19  1:23     ` 敬锐
2015-01-19  7:49       ` Lee Jones
2015-01-15 11:18 ` [PATCH 02/10] mfd: rtsx: place register address and values togather micky_ching
2015-01-18 12:35   ` Lee Jones
2015-01-15 11:19 ` [PATCH 03/10] mfd: rtsx: add debug info when access register failed micky_ching
2015-01-18 12:35   ` Lee Jones
2015-01-15 11:19 ` [PATCH 04/10] mfd: rtsx: update PETXCFG address micky_ching
2015-01-18 12:31   ` Lee Jones
2015-01-15 11:19 ` [PATCH 05/10] mfd: rtsx: update driving settings micky_ching
2015-01-18 12:32   ` Lee Jones
2015-01-15 11:19 ` [PATCH 06/10] mfd: rtsx: update phy register micky_ching
2015-01-18 12:29   ` Lee Jones
2015-01-19  1:55     ` 敬锐
2015-01-19  7:47       ` Lee Jones
2015-01-20  2:07         ` 敬锐
2015-01-20  9:45           ` Lee Jones
2015-01-15 11:19 ` [PATCH 07/10] mfd: rtsx: remove LCTLR defination micky_ching
2015-01-18 12:28   ` Lee Jones
2015-01-19  1:12     ` 敬锐
2015-01-19  8:06       ` Lee Jones
2015-01-15 11:19 ` [PATCH 08/10] mfd: rtsx: add support for rts524A micky_ching
2015-01-18 12:20   ` Lee Jones
2015-01-19  2:32     ` 敬锐
2015-01-19  2:36     ` 敬锐
2015-01-19  7:40       ` Lee Jones
2015-01-19  3:09     ` 敬锐
2015-01-19  7:38       ` Lee Jones
2015-01-15 11:19 ` [PATCH 09/10] mfd: rtsx: add support for rts525A micky_ching
2015-01-18 11:13   ` Lee Jones
2015-01-19  2:53     ` 敬锐
2015-01-19  7:41       ` Lee Jones
2015-01-15 11:19 ` [PATCH 10/10] mfd: rtsx: using pcr_dbg replace dev_dbg micky_ching
2015-01-18 10:43   ` Lee Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).