rts5229.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /* Driver for Realtek PCI-Express card reader
  2. *
  3. * Copyright(c) 2009 Realtek Semiconductor Corp. All rights reserved.
  4. *
  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
  8. * later version.
  9. *
  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.
  14. *
  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/>.
  17. *
  18. * Author:
  19. * Wei WANG <wei_wang@realsil.com.cn>
  20. * No. 450, Shenhu Road, Suzhou Industry Park, Suzhou, China
  21. */
  22. #include <linux/module.h>
  23. #include <linux/delay.h>
  24. #include <linux/mfd/rtsx_pci.h>
  25. #include "rtsx_pcr.h"
  26. static u8 rts5229_get_ic_version(struct rtsx_pcr *pcr)
  27. {
  28. u8 val;
  29. rtsx_pci_read_register(pcr, DUMMY_REG_RESET_0, &val);
  30. return val & 0x0F;
  31. }
  32. static int rts5229_extra_init_hw(struct rtsx_pcr *pcr)
  33. {
  34. rtsx_pci_init_cmd(pcr);
  35. /* Configure GPIO as output */
  36. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, GPIO_CTL, 0x02, 0x02);
  37. /* Switch LDO3318 source from DV33 to card_3v3 */
  38. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, LDO_PWR_SEL, 0x03, 0x00);
  39. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, LDO_PWR_SEL, 0x03, 0x01);
  40. /* LED shine disabled, set initial shine cycle period */
  41. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, OLT_LED_CTL, 0x0F, 0x02);
  42. return rtsx_pci_send_cmd(pcr, 100);
  43. }
  44. static int rts5229_optimize_phy(struct rtsx_pcr *pcr)
  45. {
  46. /* Optimize RX sensitivity */
  47. return rtsx_pci_write_phy_register(pcr, 0x00, 0xBA42);
  48. }
  49. static int rts5229_turn_on_led(struct rtsx_pcr *pcr)
  50. {
  51. return rtsx_pci_write_register(pcr, GPIO_CTL, 0x02, 0x02);
  52. }
  53. static int rts5229_turn_off_led(struct rtsx_pcr *pcr)
  54. {
  55. return rtsx_pci_write_register(pcr, GPIO_CTL, 0x02, 0x00);
  56. }
  57. static int rts5229_enable_auto_blink(struct rtsx_pcr *pcr)
  58. {
  59. return rtsx_pci_write_register(pcr, OLT_LED_CTL, 0x08, 0x08);
  60. }
  61. static int rts5229_disable_auto_blink(struct rtsx_pcr *pcr)
  62. {
  63. return rtsx_pci_write_register(pcr, OLT_LED_CTL, 0x08, 0x00);
  64. }
  65. static int rts5229_card_power_on(struct rtsx_pcr *pcr, int card)
  66. {
  67. int err;
  68. rtsx_pci_init_cmd(pcr);
  69. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, CARD_PWR_CTL,
  70. SD_POWER_MASK, SD_PARTIAL_POWER_ON);
  71. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PWR_GATE_CTRL,
  72. LDO3318_PWR_MASK, 0x02);
  73. err = rtsx_pci_send_cmd(pcr, 100);
  74. if (err < 0)
  75. return err;
  76. /* To avoid too large in-rush current */
  77. udelay(150);
  78. rtsx_pci_init_cmd(pcr);
  79. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, CARD_PWR_CTL,
  80. SD_POWER_MASK, SD_POWER_ON);
  81. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PWR_GATE_CTRL,
  82. LDO3318_PWR_MASK, 0x06);
  83. err = rtsx_pci_send_cmd(pcr, 100);
  84. if (err < 0)
  85. return err;
  86. return 0;
  87. }
  88. static int rts5229_card_power_off(struct rtsx_pcr *pcr, int card)
  89. {
  90. rtsx_pci_init_cmd(pcr);
  91. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, CARD_PWR_CTL,
  92. SD_POWER_MASK | PMOS_STRG_MASK,
  93. SD_POWER_OFF | PMOS_STRG_400mA);
  94. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PWR_GATE_CTRL,
  95. LDO3318_PWR_MASK, 0X00);
  96. return rtsx_pci_send_cmd(pcr, 100);
  97. }
  98. static const struct pcr_ops rts5229_pcr_ops = {
  99. .extra_init_hw = rts5229_extra_init_hw,
  100. .optimize_phy = rts5229_optimize_phy,
  101. .turn_on_led = rts5229_turn_on_led,
  102. .turn_off_led = rts5229_turn_off_led,
  103. .enable_auto_blink = rts5229_enable_auto_blink,
  104. .disable_auto_blink = rts5229_disable_auto_blink,
  105. .card_power_on = rts5229_card_power_on,
  106. .card_power_off = rts5229_card_power_off,
  107. .cd_deglitch = NULL,
  108. };
  109. /* SD Pull Control Enable:
  110. * SD_DAT[3:0] ==> pull up
  111. * SD_CD ==> pull up
  112. * SD_WP ==> pull up
  113. * SD_CMD ==> pull up
  114. * SD_CLK ==> pull down
  115. */
  116. static const u32 rts5229_sd_pull_ctl_enable_tbl1[] = {
  117. RTSX_REG_PAIR(CARD_PULL_CTL2, 0xAA),
  118. RTSX_REG_PAIR(CARD_PULL_CTL3, 0xE9),
  119. 0,
  120. };
  121. /* For RTS5229 version C */
  122. static const u32 rts5229_sd_pull_ctl_enable_tbl2[] = {
  123. RTSX_REG_PAIR(CARD_PULL_CTL2, 0xAA),
  124. RTSX_REG_PAIR(CARD_PULL_CTL3, 0xD9),
  125. 0,
  126. };
  127. /* SD Pull Control Disable:
  128. * SD_DAT[3:0] ==> pull down
  129. * SD_CD ==> pull up
  130. * SD_WP ==> pull down
  131. * SD_CMD ==> pull down
  132. * SD_CLK ==> pull down
  133. */
  134. static const u32 rts5229_sd_pull_ctl_disable_tbl1[] = {
  135. RTSX_REG_PAIR(CARD_PULL_CTL2, 0x55),
  136. RTSX_REG_PAIR(CARD_PULL_CTL3, 0xD5),
  137. 0,
  138. };
  139. /* For RTS5229 version C */
  140. static const u32 rts5229_sd_pull_ctl_disable_tbl2[] = {
  141. RTSX_REG_PAIR(CARD_PULL_CTL2, 0x55),
  142. RTSX_REG_PAIR(CARD_PULL_CTL3, 0xE5),
  143. 0,
  144. };
  145. /* MS Pull Control Enable:
  146. * MS CD ==> pull up
  147. * others ==> pull down
  148. */
  149. static const u32 rts5229_ms_pull_ctl_enable_tbl[] = {
  150. RTSX_REG_PAIR(CARD_PULL_CTL5, 0x55),
  151. RTSX_REG_PAIR(CARD_PULL_CTL6, 0x15),
  152. 0,
  153. };
  154. /* MS Pull Control Disable:
  155. * MS CD ==> pull up
  156. * others ==> pull down
  157. */
  158. static const u32 rts5229_ms_pull_ctl_disable_tbl[] = {
  159. RTSX_REG_PAIR(CARD_PULL_CTL5, 0x55),
  160. RTSX_REG_PAIR(CARD_PULL_CTL6, 0x15),
  161. 0,
  162. };
  163. void rts5229_init_params(struct rtsx_pcr *pcr)
  164. {
  165. pcr->extra_caps = EXTRA_CAPS_SD_SDR50 | EXTRA_CAPS_SD_SDR104;
  166. pcr->num_slots = 2;
  167. pcr->ops = &rts5229_pcr_ops;
  168. pcr->ic_version = rts5229_get_ic_version(pcr);
  169. if (pcr->ic_version == IC_VER_C) {
  170. pcr->sd_pull_ctl_enable_tbl = rts5229_sd_pull_ctl_enable_tbl2;
  171. pcr->sd_pull_ctl_disable_tbl = rts5229_sd_pull_ctl_disable_tbl2;
  172. } else {
  173. pcr->sd_pull_ctl_enable_tbl = rts5229_sd_pull_ctl_enable_tbl1;
  174. pcr->sd_pull_ctl_disable_tbl = rts5229_sd_pull_ctl_disable_tbl1;
  175. }
  176. pcr->ms_pull_ctl_enable_tbl = rts5229_ms_pull_ctl_enable_tbl;
  177. pcr->ms_pull_ctl_disable_tbl = rts5229_ms_pull_ctl_disable_tbl;
  178. }