linux/drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_api_8822b_sdio.c
<<
>>
Prefs
   1/******************************************************************************
   2 *
   3 * Copyright(c) 2016  Realtek Corporation.
   4 *
   5 * This program is free software; you can redistribute it and/or modify it
   6 * under the terms of version 2 of the GNU General Public License as
   7 * published by the Free Software Foundation.
   8 *
   9 * This program is distributed in the hope that it will be useful, but WITHOUT
  10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  12 * more details.
  13 *
  14 * The full GNU General Public License is included in this distribution in the
  15 * file called LICENSE.
  16 *
  17 * Contact Information:
  18 * wlanfae <wlanfae@realtek.com>
  19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
  20 * Hsinchu 300, Taiwan.
  21 *
  22 * Larry Finger <Larry.Finger@lwfinger.net>
  23 *
  24 *****************************************************************************/
  25#include "halmac_8822b_cfg.h"
  26
  27/**
  28 * halmac_mac_power_switch_8822b_sdio() - switch mac power
  29 * @halmac_adapter : the adapter of halmac
  30 * @halmac_power : power state
  31 * Author : KaiYuan Chang/Ivan Lin
  32 * Return : enum halmac_ret_status
  33 * More details of status code can be found in prototype document
  34 */
  35enum halmac_ret_status
  36halmac_mac_power_switch_8822b_sdio(struct halmac_adapter *halmac_adapter,
  37                                   enum halmac_mac_power halmac_power)
  38{
  39        u8 interface_mask;
  40        u8 value8;
  41        u8 rpwm;
  42        u32 imr_backup;
  43        void *driver_adapter = NULL;
  44        struct halmac_api *halmac_api;
  45
  46        if (halmac_adapter_validate(halmac_adapter) != HALMAC_RET_SUCCESS)
  47                return HALMAC_RET_ADAPTER_INVALID;
  48
  49        if (halmac_api_validate(halmac_adapter) != HALMAC_RET_SUCCESS)
  50                return HALMAC_RET_API_INVALID;
  51
  52        driver_adapter = halmac_adapter->driver_adapter;
  53        halmac_api = (struct halmac_api *)halmac_adapter->halmac_api;
  54
  55        HALMAC_RT_TRACE(
  56                driver_adapter, HALMAC_MSG_PWR, DBG_DMESG,
  57                "[TRACE]halmac_mac_power_switch_88xx_sdio==========>\n");
  58        HALMAC_RT_TRACE(driver_adapter, HALMAC_MSG_PWR, DBG_DMESG,
  59                        "[TRACE]halmac_power = %x ==========>\n", halmac_power);
  60        HALMAC_RT_TRACE(driver_adapter, HALMAC_MSG_PWR, DBG_DMESG,
  61                        "[TRACE]8822B pwr seq ver = %s\n",
  62                        HALMAC_8822B_PWR_SEQ_VER);
  63
  64        interface_mask = HALMAC_PWR_INTF_SDIO_MSK;
  65
  66        halmac_adapter->rpwm_record =
  67                HALMAC_REG_READ_8(halmac_adapter, REG_SDIO_HRPWM1);
  68
  69        /* Check FW still exist or not */
  70        if (HALMAC_REG_READ_16(halmac_adapter, REG_MCUFW_CTRL) == 0xC078) {
  71                /* Leave 32K */
  72                rpwm = (u8)((halmac_adapter->rpwm_record ^ BIT(7)) & 0x80);
  73                HALMAC_REG_WRITE_8(halmac_adapter, REG_SDIO_HRPWM1, rpwm);
  74        }
  75
  76        value8 = HALMAC_REG_READ_8(halmac_adapter, REG_CR);
  77        if (value8 == 0xEA)
  78                halmac_adapter->halmac_state.mac_power = HALMAC_MAC_POWER_OFF;
  79        else
  80                halmac_adapter->halmac_state.mac_power = HALMAC_MAC_POWER_ON;
  81
  82        /*Check if power switch is needed*/
  83        if (halmac_power == HALMAC_MAC_POWER_ON &&
  84            halmac_adapter->halmac_state.mac_power == HALMAC_MAC_POWER_ON) {
  85                HALMAC_RT_TRACE(
  86                        driver_adapter, HALMAC_MSG_PWR, DBG_WARNING,
  87                        "[WARN]halmac_mac_power_switch power state unchange!\n");
  88                return HALMAC_RET_PWR_UNCHANGE;
  89        }
  90
  91        imr_backup = HALMAC_REG_READ_32(halmac_adapter, REG_SDIO_HIMR);
  92        HALMAC_REG_WRITE_32(halmac_adapter, REG_SDIO_HIMR, 0);
  93
  94        if (halmac_power == HALMAC_MAC_POWER_OFF) {
  95                if (halmac_pwr_seq_parser_88xx(
  96                            halmac_adapter, HALMAC_PWR_CUT_ALL_MSK,
  97                            HALMAC_PWR_FAB_TSMC_MSK, interface_mask,
  98                            halmac_8822b_card_disable_flow) !=
  99                    HALMAC_RET_SUCCESS) {
 100                        pr_err("[ERR]Handle power off cmd error\n");
 101                        HALMAC_REG_WRITE_32(halmac_adapter, REG_SDIO_HIMR,
 102                                            imr_backup);
 103                        return HALMAC_RET_POWER_OFF_FAIL;
 104                }
 105
 106                halmac_adapter->halmac_state.mac_power = HALMAC_MAC_POWER_OFF;
 107                halmac_adapter->halmac_state.ps_state =
 108                        HALMAC_PS_STATE_UNDEFINE;
 109                halmac_adapter->halmac_state.dlfw_state = HALMAC_DLFW_NONE;
 110                halmac_init_adapter_dynamic_para_88xx(halmac_adapter);
 111        } else {
 112                if (halmac_pwr_seq_parser_88xx(
 113                            halmac_adapter, HALMAC_PWR_CUT_ALL_MSK,
 114                            HALMAC_PWR_FAB_TSMC_MSK, interface_mask,
 115                            halmac_8822b_card_enable_flow) !=
 116                    HALMAC_RET_SUCCESS) {
 117                        pr_err("[ERR]Handle power on cmd error\n");
 118                        HALMAC_REG_WRITE_32(halmac_adapter, REG_SDIO_HIMR,
 119                                            imr_backup);
 120                        return HALMAC_RET_POWER_ON_FAIL;
 121                }
 122
 123                halmac_adapter->halmac_state.mac_power = HALMAC_MAC_POWER_ON;
 124                halmac_adapter->halmac_state.ps_state = HALMAC_PS_STATE_ACT;
 125        }
 126
 127        HALMAC_REG_WRITE_32(halmac_adapter, REG_SDIO_HIMR, imr_backup);
 128
 129        HALMAC_RT_TRACE(
 130                driver_adapter, HALMAC_MSG_PWR, DBG_DMESG,
 131                "[TRACE]halmac_mac_power_switch_88xx_sdio <==========\n");
 132
 133        return HALMAC_RET_SUCCESS;
 134}
 135
 136/**
 137 * halmac_phy_cfg_8822b_sdio() - phy config
 138 * @halmac_adapter : the adapter of halmac
 139 * Author : KaiYuan Chang
 140 * Return : enum halmac_ret_status
 141 * More details of status code can be found in prototype document
 142 */
 143enum halmac_ret_status
 144halmac_phy_cfg_8822b_sdio(struct halmac_adapter *halmac_adapter,
 145                          enum halmac_intf_phy_platform platform)
 146{
 147        void *driver_adapter = NULL;
 148        struct halmac_api *halmac_api;
 149
 150        if (halmac_adapter_validate(halmac_adapter) != HALMAC_RET_SUCCESS)
 151                return HALMAC_RET_ADAPTER_INVALID;
 152
 153        if (halmac_api_validate(halmac_adapter) != HALMAC_RET_SUCCESS)
 154                return HALMAC_RET_API_INVALID;
 155
 156        halmac_api_record_id_88xx(halmac_adapter, HALMAC_API_PHY_CFG);
 157
 158        driver_adapter = halmac_adapter->driver_adapter;
 159        halmac_api = (struct halmac_api *)halmac_adapter->halmac_api;
 160
 161        HALMAC_RT_TRACE(driver_adapter, HALMAC_MSG_PWR, DBG_DMESG,
 162                        "halmac_phy_cfg ==========>\n");
 163
 164        HALMAC_RT_TRACE(driver_adapter, HALMAC_MSG_PWR, DBG_DMESG,
 165                        "sdio no phy\n");
 166
 167        HALMAC_RT_TRACE(driver_adapter, HALMAC_MSG_PWR, DBG_DMESG,
 168                        "halmac_phy_cfg <==========\n");
 169
 170        return HALMAC_RET_SUCCESS;
 171}
 172
 173/**
 174 * halmac_interface_integration_tuning_8822b_sdio() - sdio interface fine tuning
 175 * @halmac_adapter : the adapter of halmac
 176 * Author : Ivan
 177 * Return : enum halmac_ret_status
 178 * More details of status code can be found in prototype document
 179 */
 180enum halmac_ret_status halmac_interface_integration_tuning_8822b_sdio(
 181        struct halmac_adapter *halmac_adapter)
 182{
 183        return HALMAC_RET_SUCCESS;
 184}
 185