2 * Copyright (C) 2013 BayHub Technology Ltd.
4 * Authors: Peter Guo <peter.guo@bayhubtech.com>
5 * Adam Lee <adam.lee@canonical.com>
7 * This software is licensed under the terms of the GNU General Public
8 * License version 2, as published by the Free Software Foundation, and
9 * may be copied, distributed, and modified under those terms.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
18 #include <linux/pci.h>
21 #include "sdhci-pci.h"
22 #include "sdhci-pci-o2micro.h"
24 void sdhci_pci_o2_fujin2_pci_init(struct sdhci_pci_chip
*chip
)
28 /* Improve write performance for SD3.0 */
29 ret
= pci_read_config_dword(chip
->pdev
, O2_SD_DEV_CTRL
, &scratch_32
);
32 scratch_32
&= ~((1 << 12) | (1 << 13) | (1 << 14));
33 pci_write_config_dword(chip
->pdev
, O2_SD_DEV_CTRL
, scratch_32
);
35 /* Enable Link abnormal reset generating Reset */
36 ret
= pci_read_config_dword(chip
->pdev
, O2_SD_MISC_REG5
, &scratch_32
);
39 scratch_32
&= ~((1 << 19) | (1 << 11));
40 scratch_32
|= (1 << 10);
41 pci_write_config_dword(chip
->pdev
, O2_SD_MISC_REG5
, scratch_32
);
43 /* set card power over current protection */
44 ret
= pci_read_config_dword(chip
->pdev
, O2_SD_TEST_REG
, &scratch_32
);
47 scratch_32
|= (1 << 4);
48 pci_write_config_dword(chip
->pdev
, O2_SD_TEST_REG
, scratch_32
);
50 /* adjust the output delay for SD mode */
51 pci_write_config_dword(chip
->pdev
, O2_SD_DELAY_CTRL
, 0x00002492);
53 /* Set the output voltage setting of Aux 1.2v LDO */
54 ret
= pci_read_config_dword(chip
->pdev
, O2_SD_LD0_CTRL
, &scratch_32
);
57 scratch_32
&= ~(3 << 12);
58 pci_write_config_dword(chip
->pdev
, O2_SD_LD0_CTRL
, scratch_32
);
60 /* Set Max power supply capability of SD host */
61 ret
= pci_read_config_dword(chip
->pdev
, O2_SD_CAP_REG0
, &scratch_32
);
64 scratch_32
&= ~(0x01FE);
66 pci_write_config_dword(chip
->pdev
, O2_SD_CAP_REG0
, scratch_32
);
67 /* Set DLL Tuning Window */
68 ret
= pci_read_config_dword(chip
->pdev
,
69 O2_SD_TUNING_CTRL
, &scratch_32
);
72 scratch_32
&= ~(0x000000FF);
73 scratch_32
|= 0x00000066;
74 pci_write_config_dword(chip
->pdev
, O2_SD_TUNING_CTRL
, scratch_32
);
76 /* Set UHS2 T_EIDLE */
77 ret
= pci_read_config_dword(chip
->pdev
,
78 O2_SD_UHS2_L1_CTRL
, &scratch_32
);
81 scratch_32
&= ~(0x000000FC);
82 scratch_32
|= 0x00000084;
83 pci_write_config_dword(chip
->pdev
, O2_SD_UHS2_L1_CTRL
, scratch_32
);
85 /* Set UHS2 Termination */
86 ret
= pci_read_config_dword(chip
->pdev
, O2_SD_FUNC_REG3
, &scratch_32
);
89 scratch_32
&= ~((1 << 21) | (1 << 30));
91 /* Set RTD3 function disabled */
92 scratch_32
|= ((1 << 29) | (1 << 28));
93 pci_write_config_dword(chip
->pdev
, O2_SD_FUNC_REG3
, scratch_32
);
95 /* Set L1 Entrance Timer */
96 ret
= pci_read_config_dword(chip
->pdev
, O2_SD_CAPS
, &scratch_32
);
99 scratch_32
&= ~(0xf0000000);
100 scratch_32
|= 0x30000000;
101 pci_write_config_dword(chip
->pdev
, O2_SD_CAPS
, scratch_32
);
103 ret
= pci_read_config_dword(chip
->pdev
,
104 O2_SD_MISC_CTRL4
, &scratch_32
);
107 scratch_32
&= ~(0x000f0000);
108 scratch_32
|= 0x00080000;
109 pci_write_config_dword(chip
->pdev
, O2_SD_MISC_CTRL4
, scratch_32
);
111 EXPORT_SYMBOL_GPL(sdhci_pci_o2_fujin2_pci_init
);
113 int sdhci_pci_o2_probe_slot(struct sdhci_pci_slot
*slot
)
115 struct sdhci_pci_chip
*chip
;
116 struct sdhci_host
*host
;
121 switch (chip
->pdev
->device
) {
122 case PCI_DEVICE_ID_O2_SDS0
:
123 case PCI_DEVICE_ID_O2_SEABIRD0
:
124 case PCI_DEVICE_ID_O2_SEABIRD1
:
125 case PCI_DEVICE_ID_O2_SDS1
:
126 case PCI_DEVICE_ID_O2_FUJIN2
:
127 reg
= sdhci_readl(host
, O2_SD_VENDOR_SETTING
);
129 host
->quirks
|= SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12
;
131 if (chip
->pdev
->device
!= PCI_DEVICE_ID_O2_FUJIN2
)
133 /* set dll watch dog timer */
134 reg
= sdhci_readl(host
, O2_SD_VENDOR_SETTING2
);
136 sdhci_writel(host
, reg
, O2_SD_VENDOR_SETTING2
);
145 EXPORT_SYMBOL_GPL(sdhci_pci_o2_probe_slot
);
147 int sdhci_pci_o2_probe(struct sdhci_pci_chip
*chip
)
153 switch (chip
->pdev
->device
) {
154 case PCI_DEVICE_ID_O2_8220
:
155 case PCI_DEVICE_ID_O2_8221
:
156 case PCI_DEVICE_ID_O2_8320
:
157 case PCI_DEVICE_ID_O2_8321
:
158 /* This extra setup is required due to broken ADMA. */
159 ret
= pci_read_config_byte(chip
->pdev
,
160 O2_SD_LOCK_WP
, &scratch
);
164 pci_write_config_byte(chip
->pdev
, O2_SD_LOCK_WP
, scratch
);
166 /* Set Multi 3 to VCC3V# */
167 pci_write_config_byte(chip
->pdev
, O2_SD_MULTI_VCC3V
, 0x08);
169 /* Disable CLK_REQ# support after media DET */
170 ret
= pci_read_config_byte(chip
->pdev
,
171 O2_SD_CLKREQ
, &scratch
);
175 pci_write_config_byte(chip
->pdev
, O2_SD_CLKREQ
, scratch
);
177 /* Choose capabilities, enable SDMA. We have to write 0x01
178 * to the capabilities register first to unlock it.
180 ret
= pci_read_config_byte(chip
->pdev
, O2_SD_CAPS
, &scratch
);
184 pci_write_config_byte(chip
->pdev
, O2_SD_CAPS
, scratch
);
185 pci_write_config_byte(chip
->pdev
, O2_SD_CAPS
, 0x73);
187 /* Disable ADMA1/2 */
188 pci_write_config_byte(chip
->pdev
, O2_SD_ADMA1
, 0x39);
189 pci_write_config_byte(chip
->pdev
, O2_SD_ADMA2
, 0x08);
191 /* Disable the infinite transfer mode */
192 ret
= pci_read_config_byte(chip
->pdev
,
193 O2_SD_INF_MOD
, &scratch
);
197 pci_write_config_byte(chip
->pdev
, O2_SD_INF_MOD
, scratch
);
200 ret
= pci_read_config_byte(chip
->pdev
,
201 O2_SD_LOCK_WP
, &scratch
);
205 pci_write_config_byte(chip
->pdev
, O2_SD_LOCK_WP
, scratch
);
207 case PCI_DEVICE_ID_O2_SDS0
:
208 case PCI_DEVICE_ID_O2_SDS1
:
209 case PCI_DEVICE_ID_O2_FUJIN2
:
211 ret
= pci_read_config_byte(chip
->pdev
,
212 O2_SD_LOCK_WP
, &scratch
);
217 pci_write_config_byte(chip
->pdev
, O2_SD_LOCK_WP
, scratch
);
219 /* Set timeout CLK */
220 ret
= pci_read_config_dword(chip
->pdev
,
221 O2_SD_CLK_SETTING
, &scratch_32
);
225 scratch_32
&= ~(0xFF00);
226 scratch_32
|= 0x07E0C800;
227 pci_write_config_dword(chip
->pdev
,
228 O2_SD_CLK_SETTING
, scratch_32
);
230 ret
= pci_read_config_dword(chip
->pdev
,
231 O2_SD_CLKREQ
, &scratch_32
);
235 pci_write_config_dword(chip
->pdev
, O2_SD_CLKREQ
, scratch_32
);
237 ret
= pci_read_config_dword(chip
->pdev
,
238 O2_SD_PLL_SETTING
, &scratch_32
);
242 scratch_32
&= ~(0x1F3F070E);
243 scratch_32
|= 0x18270106;
244 pci_write_config_dword(chip
->pdev
,
245 O2_SD_PLL_SETTING
, scratch_32
);
247 /* Disable UHS1 funciton */
248 ret
= pci_read_config_dword(chip
->pdev
,
249 O2_SD_CAP_REG2
, &scratch_32
);
252 scratch_32
&= ~(0xE0);
253 pci_write_config_dword(chip
->pdev
,
254 O2_SD_CAP_REG2
, scratch_32
);
256 if (chip
->pdev
->device
== PCI_DEVICE_ID_O2_FUJIN2
)
257 sdhci_pci_o2_fujin2_pci_init(chip
);
260 ret
= pci_read_config_byte(chip
->pdev
,
261 O2_SD_LOCK_WP
, &scratch
);
265 pci_write_config_byte(chip
->pdev
, O2_SD_LOCK_WP
, scratch
);
267 case PCI_DEVICE_ID_O2_SEABIRD0
:
268 case PCI_DEVICE_ID_O2_SEABIRD1
:
270 ret
= pci_read_config_byte(chip
->pdev
,
271 O2_SD_LOCK_WP
, &scratch
);
276 pci_write_config_byte(chip
->pdev
, O2_SD_LOCK_WP
, scratch
);
278 ret
= pci_read_config_dword(chip
->pdev
,
279 O2_SD_FUNC_REG0
, &scratch_32
);
281 if ((scratch_32
& 0xff000000) == 0x01000000) {
282 scratch_32
&= 0x0000FFFF;
283 scratch_32
|= 0x1F340000;
285 pci_write_config_dword(chip
->pdev
,
286 O2_SD_PLL_SETTING
, scratch_32
);
288 scratch_32
&= 0x0000FFFF;
289 scratch_32
|= 0x2c280000;
291 pci_write_config_dword(chip
->pdev
,
292 O2_SD_PLL_SETTING
, scratch_32
);
294 ret
= pci_read_config_dword(chip
->pdev
,
297 scratch_32
|= (1 << 22);
298 pci_write_config_dword(chip
->pdev
,
299 O2_SD_FUNC_REG4
, scratch_32
);
303 ret
= pci_read_config_byte(chip
->pdev
,
304 O2_SD_LOCK_WP
, &scratch
);
308 pci_write_config_byte(chip
->pdev
, O2_SD_LOCK_WP
, scratch
);
314 EXPORT_SYMBOL_GPL(sdhci_pci_o2_probe
);
316 int sdhci_pci_o2_resume(struct sdhci_pci_chip
*chip
)
318 sdhci_pci_o2_probe(chip
);
321 EXPORT_SYMBOL_GPL(sdhci_pci_o2_resume
);