Home | History | Annotate | Line # | Download | only in ar5210
      1  1.1  alc /*
      2  1.1  alc  * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
      3  1.1  alc  * Copyright (c) 2002-2004 Atheros Communications, Inc.
      4  1.1  alc  *
      5  1.1  alc  * Permission to use, copy, modify, and/or distribute this software for any
      6  1.1  alc  * purpose with or without fee is hereby granted, provided that the above
      7  1.1  alc  * copyright notice and this permission notice appear in all copies.
      8  1.1  alc  *
      9  1.1  alc  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     10  1.1  alc  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     11  1.1  alc  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     12  1.1  alc  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     13  1.1  alc  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     14  1.1  alc  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     15  1.1  alc  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     16  1.1  alc  *
     17  1.1  alc  * $Id: ar5210_power.c,v 1.1.1.1 2008/12/11 04:46:27 alc Exp $
     18  1.1  alc  */
     19  1.1  alc #include "opt_ah.h"
     20  1.1  alc 
     21  1.1  alc #include "ah.h"
     22  1.1  alc #include "ah_internal.h"
     23  1.1  alc 
     24  1.1  alc #include "ar5210/ar5210.h"
     25  1.1  alc #include "ar5210/ar5210reg.h"
     26  1.1  alc 
     27  1.1  alc /*
     28  1.1  alc  * Notify Power Mgt is disabled in self-generated frames.
     29  1.1  alc  * If requested, set Power Mode of chip to auto/normal.
     30  1.1  alc  */
     31  1.1  alc static void
     32  1.1  alc ar5210SetPowerModeAuto(struct ath_hal *ah, int setChip)
     33  1.1  alc {
     34  1.1  alc 	OS_REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SV);
     35  1.1  alc 	if (setChip)
     36  1.1  alc 		OS_REG_RMW_FIELD(ah, AR_SCR, AR_SCR_SLE, AR_SCR_SLE_ALLOW);
     37  1.1  alc }
     38  1.1  alc 
     39  1.1  alc /*
     40  1.1  alc  * Notify Power Mgt is enabled in self-generated frames.
     41  1.1  alc  * If requested, force chip awake.
     42  1.1  alc  *
     43  1.1  alc  * Returns A_OK if chip is awake or successfully forced awake.
     44  1.1  alc  *
     45  1.1  alc  * WARNING WARNING WARNING
     46  1.1  alc  * There is a problem with the chip where sometimes it will not wake up.
     47  1.1  alc  */
     48  1.1  alc static HAL_BOOL
     49  1.1  alc ar5210SetPowerModeAwake(struct ath_hal *ah, int setChip)
     50  1.1  alc {
     51  1.1  alc #define	POWER_UP_TIME	2000
     52  1.1  alc 	uint32_t val;
     53  1.1  alc 	int i;
     54  1.1  alc 
     55  1.1  alc 	if (setChip) {
     56  1.1  alc 		OS_REG_RMW_FIELD(ah, AR_SCR, AR_SCR_SLE, AR_SCR_SLE_WAKE);
     57  1.1  alc 		OS_DELAY(2000);	/* Give chip the chance to awake */
     58  1.1  alc 
     59  1.1  alc 		for (i = POWER_UP_TIME / 200; i != 0; i--) {
     60  1.1  alc 			val = OS_REG_READ(ah, AR_PCICFG);
     61  1.1  alc 			if ((val & AR_PCICFG_SPWR_DN) == 0)
     62  1.1  alc 				break;
     63  1.1  alc 			OS_DELAY(200);
     64  1.1  alc 			OS_REG_RMW_FIELD(ah, AR_SCR, AR_SCR_SLE,
     65  1.1  alc 				AR_SCR_SLE_WAKE);
     66  1.1  alc 		}
     67  1.1  alc 		if (i == 0) {
     68  1.1  alc #ifdef AH_DEBUG
     69  1.1  alc 			ath_hal_printf(ah, "%s: Failed to wakeup in %ums\n",
     70  1.1  alc 				__func__, POWER_UP_TIME/20);
     71  1.1  alc #endif
     72  1.1  alc 			return AH_FALSE;
     73  1.1  alc 		}
     74  1.1  alc 	}
     75  1.1  alc 
     76  1.1  alc 	OS_REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SV);
     77  1.1  alc 	return AH_TRUE;
     78  1.1  alc #undef POWER_UP_TIME
     79  1.1  alc }
     80  1.1  alc 
     81  1.1  alc /*
     82  1.1  alc  * Notify Power Mgt is disabled in self-generated frames.
     83  1.1  alc  * If requested, force chip to sleep.
     84  1.1  alc  */
     85  1.1  alc static void
     86  1.1  alc ar5210SetPowerModeSleep(struct ath_hal *ah, int setChip)
     87  1.1  alc {
     88  1.1  alc 	OS_REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SV);
     89  1.1  alc 	if (setChip)
     90  1.1  alc 		OS_REG_RMW_FIELD(ah, AR_SCR, AR_SCR_SLE, AR_SCR_SLE_SLP);
     91  1.1  alc }
     92  1.1  alc 
     93  1.1  alc HAL_BOOL
     94  1.1  alc ar5210SetPowerMode(struct ath_hal *ah, HAL_POWER_MODE mode, int setChip)
     95  1.1  alc {
     96  1.1  alc 	struct ath_hal_5210 *ahp = AH5210(ah);
     97  1.1  alc #ifdef AH_DEBUG
     98  1.1  alc 	static const char* modes[] = {
     99  1.1  alc 		"AWAKE",
    100  1.1  alc 		"FULL-SLEEP",
    101  1.1  alc 		"NETWORK SLEEP",
    102  1.1  alc 		"UNDEFINED"
    103  1.1  alc 	};
    104  1.1  alc #endif
    105  1.1  alc 	int status = AH_TRUE;
    106  1.1  alc 
    107  1.1  alc 	HALDEBUG(ah, HAL_DEBUG_POWER, "%s: %s -> %s (%s)\n", __func__,
    108  1.1  alc 		modes[ahp->ah_powerMode], modes[mode],
    109  1.1  alc 		setChip ? "set chip " : "");
    110  1.1  alc 	switch (mode) {
    111  1.1  alc 	case HAL_PM_AWAKE:
    112  1.1  alc 		status = ar5210SetPowerModeAwake(ah, setChip);
    113  1.1  alc 		break;
    114  1.1  alc 	case HAL_PM_FULL_SLEEP:
    115  1.1  alc 		ar5210SetPowerModeSleep(ah, setChip);
    116  1.1  alc 		break;
    117  1.1  alc 	case HAL_PM_NETWORK_SLEEP:
    118  1.1  alc 		ar5210SetPowerModeAuto(ah, setChip);
    119  1.1  alc 		break;
    120  1.1  alc 	default:
    121  1.1  alc 		HALDEBUG(ah, HAL_DEBUG_ANY, "%s: unknown power mode %u\n",
    122  1.1  alc 		    __func__, mode);
    123  1.1  alc 		return AH_FALSE;
    124  1.1  alc 	}
    125  1.1  alc 	ahp->ah_powerMode = mode;
    126  1.1  alc 	return status;
    127  1.1  alc }
    128  1.1  alc 
    129  1.1  alc HAL_POWER_MODE
    130  1.1  alc ar5210GetPowerMode(struct ath_hal *ah)
    131  1.1  alc {
    132  1.1  alc 	/* Just so happens the h/w maps directly to the abstracted value */
    133  1.1  alc 	return MS(OS_REG_READ(ah, AR_SCR), AR_SCR_SLE);
    134  1.1  alc }
    135