linux/drivers/mfd/rts5209.c
<<
>>
Prefs
   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
  29static u8 rts5209_get_ic_version(struct rtsx_pcr *pcr)
  30{
  31        u8 val;
  32
  33        val = rtsx_pci_readb(pcr, 0x1C);
  34        return val & 0x0F;
  35}
  36
  37static void rts5209_init_vendor_cfg(struct rtsx_pcr *pcr)
  38{
  39        u32 val;
  40
  41        rtsx_pci_read_config_dword(pcr, 0x724, &val);
  42        dev_dbg(&(pcr->pci->dev), "Cfg 0x724: 0x%x\n", val);
  43
  44        if (!(val & 0x80)) {
  45                if (val & 0x08)
  46                        pcr->ms_pmos = false;
  47                else
  48                        pcr->ms_pmos = true;
  49        }
  50}
  51
  52static int rts5209_extra_init_hw(struct rtsx_pcr *pcr)
  53{
  54        rtsx_pci_init_cmd(pcr);
  55
  56        /* Turn off LED */
  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);
  60
  61        return rtsx_pci_send_cmd(pcr, 100);
  62}
  63
  64static int rts5209_optimize_phy(struct rtsx_pcr *pcr)
  65{
  66        return rtsx_pci_write_phy_register(pcr, 0x00, 0xB966);
  67}
  68
  69static int rts5209_turn_on_led(struct rtsx_pcr *pcr)
  70{
  71        return rtsx_pci_write_register(pcr, CARD_GPIO, 0x01, 0x00);
  72}
  73
  74static int rts5209_turn_off_led(struct rtsx_pcr *pcr)
  75{
  76        return rtsx_pci_write_register(pcr, CARD_GPIO, 0x01, 0x01);
  77}
  78
  79static int rts5209_enable_auto_blink(struct rtsx_pcr *pcr)
  80{
  81        return rtsx_pci_write_register(pcr, CARD_AUTO_BLINK, 0xFF, 0x0D);
  82}
  83
  84static int rts5209_disable_auto_blink(struct rtsx_pcr *pcr)
  85{
  86        return rtsx_pci_write_register(pcr, CARD_AUTO_BLINK, 0x08, 0x00);
  87}
  88
  89static int rts5209_card_power_on(struct rtsx_pcr *pcr, int card)
  90{
  91        int err;
  92        u8 pwr_mask, partial_pwr_on, pwr_on;
  93
  94        pwr_mask = SD_POWER_MASK;
  95        partial_pwr_on = SD_PARTIAL_POWER_ON;
  96        pwr_on = SD_POWER_ON;
  97
  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;
 102        }
 103
 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);
 110        if (err < 0)
 111                return err;
 112
 113        /* To avoid too large in-rush current */
 114        udelay(150);
 115
 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);
 121        if (err < 0)
 122                return err;
 123
 124        return 0;
 125}
 126
 127static int rts5209_card_power_off(struct rtsx_pcr *pcr, int card)
 128{
 129        u8 pwr_mask, pwr_off;
 130
 131        pwr_mask = SD_POWER_MASK;
 132        pwr_off = SD_POWER_OFF;
 133
 134        if (pcr->ms_pmos && (card == RTSX_MS_CARD)) {
 135                pwr_mask = MS_POWER_MASK;
 136                pwr_off = MS_POWER_OFF;
 137        }
 138
 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);
 145}
 146
 147static int rts5209_switch_output_voltage(struct rtsx_pcr *pcr, u8 voltage)
 148{
 149        int err;
 150
 151        if (voltage == OUTPUT_3V3) {
 152                err = rtsx_pci_write_phy_register(pcr, 0x08, 0x4FC0 | 0x24);
 153                if (err < 0)
 154                        return err;
 155        } else if (voltage == OUTPUT_1V8) {
 156                err = rtsx_pci_write_phy_register(pcr, 0x08, 0x4C40 | 0x24);
 157                if (err < 0)
 158                        return err;
 159        } else {
 160                return -EINVAL;
 161        }
 162
 163        return 0;
 164}
 165
 166static const struct pcr_ops rts5209_pcr_ops = {
 167        .extra_init_hw = rts5209_extra_init_hw,
 168        .optimize_phy = rts5209_optimize_phy,
 169        .turn_on_led = rts5209_turn_on_led,
 170        .turn_off_led = rts5209_turn_off_led,
 171        .enable_auto_blink = rts5209_enable_auto_blink,
 172        .disable_auto_blink = rts5209_disable_auto_blink,
 173        .card_power_on = rts5209_card_power_on,
 174        .card_power_off = rts5209_card_power_off,
 175        .switch_output_voltage = rts5209_switch_output_voltage,
 176        .cd_deglitch = NULL,
 177        .conv_clk_and_div_n = NULL,
 178};
 179
 180/* SD Pull Control Enable:
 181 *     SD_DAT[3:0] ==> pull up
 182 *     SD_CD       ==> pull up
 183 *     SD_WP       ==> pull up
 184 *     SD_CMD      ==> pull up
 185 *     SD_CLK      ==> pull down
 186 */
 187static const u32 rts5209_sd_pull_ctl_enable_tbl[] = {
 188        RTSX_REG_PAIR(CARD_PULL_CTL1, 0xAA),
 189        RTSX_REG_PAIR(CARD_PULL_CTL2, 0xAA),
 190        RTSX_REG_PAIR(CARD_PULL_CTL3, 0xE9),
 191        0,
 192};
 193
 194/* SD Pull Control Disable:
 195 *     SD_DAT[3:0] ==> pull down
 196 *     SD_CD       ==> pull up
 197 *     SD_WP       ==> pull down
 198 *     SD_CMD      ==> pull down
 199 *     SD_CLK      ==> pull down
 200 */
 201static const u32 rts5209_sd_pull_ctl_disable_tbl[] = {
 202        RTSX_REG_PAIR(CARD_PULL_CTL1, 0x55),
 203        RTSX_REG_PAIR(CARD_PULL_CTL2, 0x55),
 204        RTSX_REG_PAIR(CARD_PULL_CTL3, 0xD5),
 205        0,
 206};
 207
 208/* MS Pull Control Enable:
 209 *     MS CD       ==> pull up
 210 *     others      ==> pull down
 211 */
 212static const u32 rts5209_ms_pull_ctl_enable_tbl[] = {
 213        RTSX_REG_PAIR(CARD_PULL_CTL4, 0x55),
 214        RTSX_REG_PAIR(CARD_PULL_CTL5, 0x55),
 215        RTSX_REG_PAIR(CARD_PULL_CTL6, 0x15),
 216        0,
 217};
 218
 219/* MS Pull Control Disable:
 220 *     MS CD       ==> pull up
 221 *     others      ==> pull down
 222 */
 223static const u32 rts5209_ms_pull_ctl_disable_tbl[] = {
 224        RTSX_REG_PAIR(CARD_PULL_CTL4, 0x55),
 225        RTSX_REG_PAIR(CARD_PULL_CTL5, 0x55),
 226        RTSX_REG_PAIR(CARD_PULL_CTL6, 0x15),
 227        0,
 228};
 229
 230void rts5209_init_params(struct rtsx_pcr *pcr)
 231{
 232        pcr->extra_caps = EXTRA_CAPS_SD_SDR50 |
 233                EXTRA_CAPS_SD_SDR104 | EXTRA_CAPS_MMC_8BIT;
 234        pcr->num_slots = 2;
 235        pcr->ops = &rts5209_pcr_ops;
 236
 237        rts5209_init_vendor_cfg(pcr);
 238
 239        pcr->ic_version = rts5209_get_ic_version(pcr);
 240        pcr->sd_pull_ctl_enable_tbl = rts5209_sd_pull_ctl_enable_tbl;
 241        pcr->sd_pull_ctl_disable_tbl = rts5209_sd_pull_ctl_disable_tbl;
 242        pcr->ms_pull_ctl_enable_tbl = rts5209_ms_pull_ctl_enable_tbl;
 243        pcr->ms_pull_ctl_disable_tbl = rts5209_ms_pull_ctl_disable_tbl;
 244}
 245
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.