1 /* Driver for Realtek PCI-Express card reader
3 * Copyright(c) 2009 Realtek Semiconductor Corp. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2, or (at your option) any
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, see <http://www.gnu.org/licenses/>.
19 * Wei WANG <wei_wang@realsil.com.cn>
20 * No. 450, Shenhu Road, Suzhou Industry Park, Suzhou, China
23 #include <linux/module.h>
24 #include <linux/delay.h>
25 #include <linux/mfd/rtsx_pci.h>
29 static u8
rts5209_get_ic_version(struct rtsx_pcr
*pcr
)
33 val
= rtsx_pci_readb(pcr
, 0x1C);
37 static void rts5209_init_vendor_cfg(struct rtsx_pcr
*pcr
)
41 rtsx_pci_read_config_dword(pcr
, 0x724, &val
);
42 dev_dbg(&(pcr
->pci
->dev
), "Cfg 0x724: 0x%x\n", val
);
52 static int rts5209_extra_init_hw(struct rtsx_pcr
*pcr
)
54 rtsx_pci_init_cmd(pcr
);
57 rtsx_pci_add_cmd(pcr
, WRITE_REG_CMD
, CARD_GPIO
, 0xFF, 0x03);
58 /* Configure GPIO as output */
59 rtsx_pci_add_cmd(pcr
, WRITE_REG_CMD
, CARD_GPIO_DIR
, 0xFF, 0x03);
61 return rtsx_pci_send_cmd(pcr
, 100);
64 static int rts5209_optimize_phy(struct rtsx_pcr
*pcr
)
66 return rtsx_pci_write_phy_register(pcr
, 0x00, 0xB966);
69 static int rts5209_turn_on_led(struct rtsx_pcr
*pcr
)
71 return rtsx_pci_write_register(pcr
, CARD_GPIO
, 0x01, 0x00);
74 static int rts5209_turn_off_led(struct rtsx_pcr
*pcr
)
76 return rtsx_pci_write_register(pcr
, CARD_GPIO
, 0x01, 0x01);
79 static int rts5209_enable_auto_blink(struct rtsx_pcr
*pcr
)
81 return rtsx_pci_write_register(pcr
, CARD_AUTO_BLINK
, 0xFF, 0x0D);
84 static int rts5209_disable_auto_blink(struct rtsx_pcr
*pcr
)
86 return rtsx_pci_write_register(pcr
, CARD_AUTO_BLINK
, 0x08, 0x00);
89 static int rts5209_card_power_on(struct rtsx_pcr
*pcr
, int card
)
92 u8 pwr_mask
, partial_pwr_on
, pwr_on
;
94 pwr_mask
= SD_POWER_MASK
;
95 partial_pwr_on
= SD_PARTIAL_POWER_ON
;
98 if (pcr
->ms_pmos
&& (card
== RTSX_MS_CARD
)) {
99 pwr_mask
= MS_POWER_MASK
;
100 partial_pwr_on
= MS_PARTIAL_POWER_ON
;
101 pwr_on
= MS_POWER_ON
;
104 rtsx_pci_init_cmd(pcr
);
105 rtsx_pci_add_cmd(pcr
, WRITE_REG_CMD
, CARD_PWR_CTL
,
106 pwr_mask
, partial_pwr_on
);
107 rtsx_pci_add_cmd(pcr
, WRITE_REG_CMD
, PWR_GATE_CTRL
,
108 LDO3318_PWR_MASK
, 0x04);
109 err
= rtsx_pci_send_cmd(pcr
, 100);
113 /* To avoid too large in-rush current */
116 rtsx_pci_init_cmd(pcr
);
117 rtsx_pci_add_cmd(pcr
, WRITE_REG_CMD
, CARD_PWR_CTL
, pwr_mask
, pwr_on
);
118 rtsx_pci_add_cmd(pcr
, WRITE_REG_CMD
, PWR_GATE_CTRL
,
119 LDO3318_PWR_MASK
, 0x00);
120 err
= rtsx_pci_send_cmd(pcr
, 100);
127 static int rts5209_card_power_off(struct rtsx_pcr
*pcr
, int card
)
129 u8 pwr_mask
, pwr_off
;
131 pwr_mask
= SD_POWER_MASK
;
132 pwr_off
= SD_POWER_OFF
;
134 if (pcr
->ms_pmos
&& (card
== RTSX_MS_CARD
)) {
135 pwr_mask
= MS_POWER_MASK
;
136 pwr_off
= MS_POWER_OFF
;
139 rtsx_pci_init_cmd(pcr
);
140 rtsx_pci_add_cmd(pcr
, WRITE_REG_CMD
, CARD_PWR_CTL
,
141 pwr_mask
| PMOS_STRG_MASK
, pwr_off
| PMOS_STRG_400mA
);
142 rtsx_pci_add_cmd(pcr
, WRITE_REG_CMD
, PWR_GATE_CTRL
,
143 LDO3318_PWR_MASK
, 0X06);
144 return rtsx_pci_send_cmd(pcr
, 100);
147 static const struct pcr_ops rts5209_pcr_ops
= {
148 .extra_init_hw
= rts5209_extra_init_hw
,
149 .optimize_phy
= rts5209_optimize_phy
,
150 .turn_on_led
= rts5209_turn_on_led
,
151 .turn_off_led
= rts5209_turn_off_led
,
152 .enable_auto_blink
= rts5209_enable_auto_blink
,
153 .disable_auto_blink
= rts5209_disable_auto_blink
,
154 .card_power_on
= rts5209_card_power_on
,
155 .card_power_off
= rts5209_card_power_off
,
159 /* SD Pull Control Enable:
160 * SD_DAT[3:0] ==> pull up
164 * SD_CLK ==> pull down
166 static const u32 rts5209_sd_pull_ctl_enable_tbl
[] = {
167 RTSX_REG_PAIR(CARD_PULL_CTL1
, 0xAA),
168 RTSX_REG_PAIR(CARD_PULL_CTL2
, 0xAA),
169 RTSX_REG_PAIR(CARD_PULL_CTL3
, 0xE9),
173 /* SD Pull Control Disable:
174 * SD_DAT[3:0] ==> pull down
176 * SD_WP ==> pull down
177 * SD_CMD ==> pull down
178 * SD_CLK ==> pull down
180 static const u32 rts5209_sd_pull_ctl_disable_tbl
[] = {
181 RTSX_REG_PAIR(CARD_PULL_CTL1
, 0x55),
182 RTSX_REG_PAIR(CARD_PULL_CTL2
, 0x55),
183 RTSX_REG_PAIR(CARD_PULL_CTL3
, 0xD5),
187 /* MS Pull Control Enable:
189 * others ==> pull down
191 static const u32 rts5209_ms_pull_ctl_enable_tbl
[] = {
192 RTSX_REG_PAIR(CARD_PULL_CTL4
, 0x55),
193 RTSX_REG_PAIR(CARD_PULL_CTL5
, 0x55),
194 RTSX_REG_PAIR(CARD_PULL_CTL6
, 0x15),
198 /* MS Pull Control Disable:
200 * others ==> pull down
202 static const u32 rts5209_ms_pull_ctl_disable_tbl
[] = {
203 RTSX_REG_PAIR(CARD_PULL_CTL4
, 0x55),
204 RTSX_REG_PAIR(CARD_PULL_CTL5
, 0x55),
205 RTSX_REG_PAIR(CARD_PULL_CTL6
, 0x15),
209 void rts5209_init_params(struct rtsx_pcr
*pcr
)
211 pcr
->extra_caps
= EXTRA_CAPS_SD_SDR50
|
212 EXTRA_CAPS_SD_SDR104
| EXTRA_CAPS_MMC_8BIT
;
214 pcr
->ops
= &rts5209_pcr_ops
;
216 rts5209_init_vendor_cfg(pcr
);
218 pcr
->ic_version
= rts5209_get_ic_version(pcr
);
219 pcr
->sd_pull_ctl_enable_tbl
= rts5209_sd_pull_ctl_enable_tbl
;
220 pcr
->sd_pull_ctl_disable_tbl
= rts5209_sd_pull_ctl_disable_tbl
;
221 pcr
->ms_pull_ctl_enable_tbl
= rts5209_ms_pull_ctl_enable_tbl
;
222 pcr
->ms_pull_ctl_disable_tbl
= rts5209_ms_pull_ctl_disable_tbl
;