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