sdhci-pci-o2micro.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. /*
  2. * Copyright (C) 2013 BayHub Technology Ltd.
  3. *
  4. * Authors: Peter Guo <peter.guo@bayhubtech.com>
  5. * Adam Lee <adam.lee@canonical.com>
  6. *
  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.
  10. *
  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.
  15. *
  16. */
  17. #include <linux/pci.h>
  18. #include "sdhci.h"
  19. #include "sdhci-pci.h"
  20. #include "sdhci-pci-o2micro.h"
  21. void sdhci_pci_o2_fujin2_pci_init(struct sdhci_pci_chip *chip)
  22. {
  23. u32 scratch_32;
  24. int ret;
  25. /* Improve write performance for SD3.0 */
  26. ret = pci_read_config_dword(chip->pdev, O2_SD_DEV_CTRL, &scratch_32);
  27. if (ret)
  28. return;
  29. scratch_32 &= ~((1 << 12) | (1 << 13) | (1 << 14));
  30. pci_write_config_dword(chip->pdev, O2_SD_DEV_CTRL, scratch_32);
  31. /* Enable Link abnormal reset generating Reset */
  32. ret = pci_read_config_dword(chip->pdev, O2_SD_MISC_REG5, &scratch_32);
  33. if (ret)
  34. return;
  35. scratch_32 &= ~((1 << 19) | (1 << 11));
  36. scratch_32 |= (1 << 10);
  37. pci_write_config_dword(chip->pdev, O2_SD_MISC_REG5, scratch_32);
  38. /* set card power over current protection */
  39. ret = pci_read_config_dword(chip->pdev, O2_SD_TEST_REG, &scratch_32);
  40. if (ret)
  41. return;
  42. scratch_32 |= (1 << 4);
  43. pci_write_config_dword(chip->pdev, O2_SD_TEST_REG, scratch_32);
  44. /* adjust the output delay for SD mode */
  45. pci_write_config_dword(chip->pdev, O2_SD_DELAY_CTRL, 0x00002492);
  46. /* Set the output voltage setting of Aux 1.2v LDO */
  47. ret = pci_read_config_dword(chip->pdev, O2_SD_LD0_CTRL, &scratch_32);
  48. if (ret)
  49. return;
  50. scratch_32 &= ~(3 << 12);
  51. pci_write_config_dword(chip->pdev, O2_SD_LD0_CTRL, scratch_32);
  52. /* Set Max power supply capability of SD host */
  53. ret = pci_read_config_dword(chip->pdev, O2_SD_CAP_REG0, &scratch_32);
  54. if (ret)
  55. return;
  56. scratch_32 &= ~(0x01FE);
  57. scratch_32 |= 0x00CC;
  58. pci_write_config_dword(chip->pdev, O2_SD_CAP_REG0, scratch_32);
  59. /* Set DLL Tuning Window */
  60. ret = pci_read_config_dword(chip->pdev,
  61. O2_SD_TUNING_CTRL, &scratch_32);
  62. if (ret)
  63. return;
  64. scratch_32 &= ~(0x000000FF);
  65. scratch_32 |= 0x00000066;
  66. pci_write_config_dword(chip->pdev, O2_SD_TUNING_CTRL, scratch_32);
  67. /* Set UHS2 T_EIDLE */
  68. ret = pci_read_config_dword(chip->pdev,
  69. O2_SD_UHS2_L1_CTRL, &scratch_32);
  70. if (ret)
  71. return;
  72. scratch_32 &= ~(0x000000FC);
  73. scratch_32 |= 0x00000084;
  74. pci_write_config_dword(chip->pdev, O2_SD_UHS2_L1_CTRL, scratch_32);
  75. /* Set UHS2 Termination */
  76. ret = pci_read_config_dword(chip->pdev, O2_SD_FUNC_REG3, &scratch_32);
  77. if (ret)
  78. return;
  79. scratch_32 &= ~((1 << 21) | (1 << 30));
  80. /* Set RTD3 function disabled */
  81. scratch_32 |= ((1 << 29) | (1 << 28));
  82. pci_write_config_dword(chip->pdev, O2_SD_FUNC_REG3, scratch_32);
  83. /* Set L1 Entrance Timer */
  84. ret = pci_read_config_dword(chip->pdev, O2_SD_CAPS, &scratch_32);
  85. if (ret)
  86. return;
  87. scratch_32 &= ~(0xf0000000);
  88. scratch_32 |= 0x30000000;
  89. pci_write_config_dword(chip->pdev, O2_SD_CAPS, scratch_32);
  90. ret = pci_read_config_dword(chip->pdev,
  91. O2_SD_MISC_CTRL4, &scratch_32);
  92. if (ret)
  93. return;
  94. scratch_32 &= ~(0x000f0000);
  95. scratch_32 |= 0x00080000;
  96. pci_write_config_dword(chip->pdev, O2_SD_MISC_CTRL4, scratch_32);
  97. }
  98. EXPORT_SYMBOL_GPL(sdhci_pci_o2_fujin2_pci_init);
  99. int sdhci_pci_o2_probe_slot(struct sdhci_pci_slot *slot)
  100. {
  101. struct sdhci_pci_chip *chip;
  102. struct sdhci_host *host;
  103. u32 reg;
  104. chip = slot->chip;
  105. host = slot->host;
  106. switch (chip->pdev->device) {
  107. case PCI_DEVICE_ID_O2_SDS0:
  108. case PCI_DEVICE_ID_O2_SEABIRD0:
  109. case PCI_DEVICE_ID_O2_SEABIRD1:
  110. case PCI_DEVICE_ID_O2_SDS1:
  111. case PCI_DEVICE_ID_O2_FUJIN2:
  112. reg = sdhci_readl(host, O2_SD_VENDOR_SETTING);
  113. if (reg & 0x1)
  114. host->quirks |= SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12;
  115. if (chip->pdev->device != PCI_DEVICE_ID_O2_FUJIN2)
  116. break;
  117. /* set dll watch dog timer */
  118. reg = sdhci_readl(host, O2_SD_VENDOR_SETTING2);
  119. reg |= (1 << 12);
  120. sdhci_writel(host, reg, O2_SD_VENDOR_SETTING2);
  121. break;
  122. default:
  123. break;
  124. }
  125. return 0;
  126. }
  127. EXPORT_SYMBOL_GPL(sdhci_pci_o2_probe_slot);
  128. int sdhci_pci_o2_probe(struct sdhci_pci_chip *chip)
  129. {
  130. int ret;
  131. u8 scratch;
  132. u32 scratch_32;
  133. switch (chip->pdev->device) {
  134. case PCI_DEVICE_ID_O2_8220:
  135. case PCI_DEVICE_ID_O2_8221:
  136. case PCI_DEVICE_ID_O2_8320:
  137. case PCI_DEVICE_ID_O2_8321:
  138. /* This extra setup is required due to broken ADMA. */
  139. ret = pci_read_config_byte(chip->pdev,
  140. O2_SD_LOCK_WP, &scratch);
  141. if (ret)
  142. return ret;
  143. scratch &= 0x7f;
  144. pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch);
  145. /* Set Multi 3 to VCC3V# */
  146. pci_write_config_byte(chip->pdev, O2_SD_MULTI_VCC3V, 0x08);
  147. /* Disable CLK_REQ# support after media DET */
  148. ret = pci_read_config_byte(chip->pdev,
  149. O2_SD_CLKREQ, &scratch);
  150. if (ret)
  151. return ret;
  152. scratch |= 0x20;
  153. pci_write_config_byte(chip->pdev, O2_SD_CLKREQ, scratch);
  154. /* Choose capabilities, enable SDMA. We have to write 0x01
  155. * to the capabilities register first to unlock it.
  156. */
  157. ret = pci_read_config_byte(chip->pdev, O2_SD_CAPS, &scratch);
  158. if (ret)
  159. return ret;
  160. scratch |= 0x01;
  161. pci_write_config_byte(chip->pdev, O2_SD_CAPS, scratch);
  162. pci_write_config_byte(chip->pdev, O2_SD_CAPS, 0x73);
  163. /* Disable ADMA1/2 */
  164. pci_write_config_byte(chip->pdev, O2_SD_ADMA1, 0x39);
  165. pci_write_config_byte(chip->pdev, O2_SD_ADMA2, 0x08);
  166. /* Disable the infinite transfer mode */
  167. ret = pci_read_config_byte(chip->pdev,
  168. O2_SD_INF_MOD, &scratch);
  169. if (ret)
  170. return ret;
  171. scratch |= 0x08;
  172. pci_write_config_byte(chip->pdev, O2_SD_INF_MOD, scratch);
  173. /* Lock WP */
  174. ret = pci_read_config_byte(chip->pdev,
  175. O2_SD_LOCK_WP, &scratch);
  176. if (ret)
  177. return ret;
  178. scratch |= 0x80;
  179. pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch);
  180. break;
  181. case PCI_DEVICE_ID_O2_SDS0:
  182. case PCI_DEVICE_ID_O2_SDS1:
  183. case PCI_DEVICE_ID_O2_FUJIN2:
  184. /* UnLock WP */
  185. ret = pci_read_config_byte(chip->pdev,
  186. O2_SD_LOCK_WP, &scratch);
  187. if (ret)
  188. return ret;
  189. scratch &= 0x7f;
  190. pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch);
  191. /* Set timeout CLK */
  192. ret = pci_read_config_dword(chip->pdev,
  193. O2_SD_CLK_SETTING, &scratch_32);
  194. if (ret)
  195. return ret;
  196. scratch_32 &= ~(0xFF00);
  197. scratch_32 |= 0x07E0C800;
  198. pci_write_config_dword(chip->pdev,
  199. O2_SD_CLK_SETTING, scratch_32);
  200. ret = pci_read_config_dword(chip->pdev,
  201. O2_SD_CLKREQ, &scratch_32);
  202. if (ret)
  203. return ret;
  204. scratch_32 |= 0x3;
  205. pci_write_config_dword(chip->pdev, O2_SD_CLKREQ, scratch_32);
  206. ret = pci_read_config_dword(chip->pdev,
  207. O2_SD_PLL_SETTING, &scratch_32);
  208. if (ret)
  209. return ret;
  210. scratch_32 &= ~(0x1F3F070E);
  211. scratch_32 |= 0x18270106;
  212. pci_write_config_dword(chip->pdev,
  213. O2_SD_PLL_SETTING, scratch_32);
  214. /* Disable UHS1 funciton */
  215. ret = pci_read_config_dword(chip->pdev,
  216. O2_SD_CAP_REG2, &scratch_32);
  217. if (ret)
  218. return ret;
  219. scratch_32 &= ~(0xE0);
  220. pci_write_config_dword(chip->pdev,
  221. O2_SD_CAP_REG2, scratch_32);
  222. if (chip->pdev->device == PCI_DEVICE_ID_O2_FUJIN2)
  223. sdhci_pci_o2_fujin2_pci_init(chip);
  224. /* Lock WP */
  225. ret = pci_read_config_byte(chip->pdev,
  226. O2_SD_LOCK_WP, &scratch);
  227. if (ret)
  228. return ret;
  229. scratch |= 0x80;
  230. pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch);
  231. break;
  232. case PCI_DEVICE_ID_O2_SEABIRD0:
  233. case PCI_DEVICE_ID_O2_SEABIRD1:
  234. /* UnLock WP */
  235. ret = pci_read_config_byte(chip->pdev,
  236. O2_SD_LOCK_WP, &scratch);
  237. if (ret)
  238. return ret;
  239. scratch &= 0x7f;
  240. pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch);
  241. ret = pci_read_config_dword(chip->pdev,
  242. O2_SD_FUNC_REG0, &scratch_32);
  243. if ((scratch_32 & 0xff000000) == 0x01000000) {
  244. scratch_32 &= 0x0000FFFF;
  245. scratch_32 |= 0x1F340000;
  246. pci_write_config_dword(chip->pdev,
  247. O2_SD_PLL_SETTING, scratch_32);
  248. } else {
  249. scratch_32 &= 0x0000FFFF;
  250. scratch_32 |= 0x2c280000;
  251. pci_write_config_dword(chip->pdev,
  252. O2_SD_PLL_SETTING, scratch_32);
  253. ret = pci_read_config_dword(chip->pdev,
  254. O2_SD_FUNC_REG4,
  255. &scratch_32);
  256. scratch_32 |= (1 << 22);
  257. pci_write_config_dword(chip->pdev,
  258. O2_SD_FUNC_REG4, scratch_32);
  259. }
  260. /* Lock WP */
  261. ret = pci_read_config_byte(chip->pdev,
  262. O2_SD_LOCK_WP, &scratch);
  263. if (ret)
  264. return ret;
  265. scratch |= 0x80;
  266. pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch);
  267. break;
  268. }
  269. return 0;
  270. }
  271. EXPORT_SYMBOL_GPL(sdhci_pci_o2_probe);
  272. int sdhci_pci_o2_resume(struct sdhci_pci_chip *chip)
  273. {
  274. sdhci_pci_o2_probe(chip);
  275. return 0;
  276. }
  277. EXPORT_SYMBOL_GPL(sdhci_pci_o2_resume);