/* * Once configured for I/O - get input lines */ u_int32_t ar5416GpioGet(struct ath_hal *ah, u_int32_t gpio) { HALASSERT(gpio < AH_PRIVATE(ah)->ah_caps.hal_num_gpio_pins); if (gpio >= AH_PRIVATE(ah)->ah_caps.hal_num_gpio_pins) { return 0xffffffff; } // Read output value for all gpio's, shift it left, and verify whether a // specific gpio bit is set. if(AR_SREV_K2(ah)) { u_int32_t val; val = OS_REG_READ(ah, AR_GPIO_IN_OUT); if (val == (u_int32_t)(-1)) { return 0; } else { return (MS(val, AR9271_GPIO_IN_VAL) & AR_GPIO_BIT(gpio)) != 0; } } else if (AR_SREV_KIWI_10_OR_LATER(ah)) { return (MS(OS_REG_READ(ah, AR_GPIO_IN_OUT), AR9287_GPIO_IN_VAL) & AR_GPIO_BIT(gpio)) != 0; } else if (AR_SREV_KITE_10_OR_LATER(ah)) { return (MS(OS_REG_READ(ah, AR_GPIO_IN_OUT), AR9285_GPIO_IN_VAL) & AR_GPIO_BIT(gpio)) != 0; } else if (AR_SREV_MERLIN_10_OR_LATER(ah)) { return (MS(OS_REG_READ(ah, AR_GPIO_IN_OUT), AR928X_GPIO_IN_VAL) & AR_GPIO_BIT(gpio)) != 0; } else { return (MS(OS_REG_READ(ah, AR_GPIO_IN_OUT), AR_GPIO_IN_VAL) & AR_GPIO_BIT(gpio)) != 0; } }
/* * Once configured for I/O - get input lines */ uint32_t ar5416GpioGet(struct ath_hal *ah, uint32_t gpio) { if (gpio >= AR_NUM_GPIO) return 0xffffffff; return ((OS_REG_READ(ah, AR_GPIO_IN) & AR_GPIO_BIT(gpio)) >> gpio); }
/* * Configure GPIO Input lines */ HAL_BOOL ar5416GpioCfgInput(struct ath_hal *ah, uint32_t gpio) { HALASSERT(gpio < AR_NUM_GPIO); OS_REG_SET_BIT(ah, AR_GPIO_INTR_OUT, AR_GPIO_BIT(gpio)); return AH_TRUE; }
/* * Once configured for I/O - set output lines */ HAL_BOOL ar7010GpioSet(struct ath_hal *ah, u_int32_t gpio, u_int32_t val) { HALASSERT(gpio < AH_PRIVATE(ah)->ah_caps.hal_num_gpio_pins); OS_REG_RMW(ah, AR7010_GPIO_OUT, ((val&1) << gpio), AR_GPIO_BIT(gpio)); return AH_TRUE; }
/* * Once configured for I/O - set output lines */ HAL_BOOL ar9300GpioSet(struct ath_hal *ah, u_int32_t gpio, u_int32_t val) { HALASSERT(gpio < AH_PRIVATE(ah)->ah_caps.halNumGpioPins); OS_REG_RMW(ah, AR_HOSTIF_REG(ah, AR_GPIO_OUT), ((val&1) << gpio), AR_GPIO_BIT(gpio)); return AH_TRUE; }
/* * Once configured for I/O - get input lines */ u_int32_t ar9300GpioGet(struct ath_hal *ah, u_int32_t gpio) { u_int32_t gpio_in; HALASSERT(gpio < AH_PRIVATE(ah)->ah_caps.halNumGpioPins); if (gpio >= AH_PRIVATE(ah)->ah_caps.halNumGpioPins) { return 0xffffffff; } gpio_in = OS_REG_READ(ah, AR_HOSTIF_REG(ah, AR_GPIO_IN)); return (MS(gpio_in, AR_GPIO_IN_VAL) & AR_GPIO_BIT(gpio)) != 0; }
/* * Once configured for I/O - get input lines */ u_int32_t ar7010GpioGet(struct ath_hal *ah, u_int32_t gpio) { HALASSERT(gpio < AH_PRIVATE(ah)->ah_caps.hal_num_gpio_pins); if (gpio >= AH_PRIVATE(ah)->ah_caps.hal_num_gpio_pins) { return 0xffffffff; } /* Read output value for all gpio's, shift it left, and verify whether a * specific gpio bit is set. */ return (MS(OS_REG_READ(ah, AR7010_GPIO_IN), AR7010_GPIO_IN_VAL) & AR_GPIO_BIT(gpio)) != 0; }
/* * Set the GPIO Interrupt */ void ar5416GpioSetIntr(struct ath_hal *ah, u_int gpio, uint32_t ilevel) { uint32_t val; HALASSERT(gpio < AR_NUM_GPIO); /* XXX bounds check gpio */ val = MS(OS_REG_READ(ah, AR_GPIO_INTR_OUT), AR_GPIO_INTR_CTRL); if (ilevel) /* 0 == interrupt on pin high */ val &= ~AR_GPIO_BIT(gpio); else /* 1 == interrupt on pin low */ val |= AR_GPIO_BIT(gpio); OS_REG_RMW_FIELD(ah, AR_GPIO_INTR_OUT, AR_GPIO_INTR_CTRL, val); /* Change the interrupt mask. */ val = MS(OS_REG_READ(ah, AR_INTR_ASYNC_ENABLE), AR_INTR_GPIO); val |= AR_GPIO_BIT(gpio); OS_REG_RMW_FIELD(ah, AR_INTR_ASYNC_ENABLE, AR_INTR_GPIO, val); val = MS(OS_REG_READ(ah, AR_INTR_ASYNC_MASK), AR_INTR_GPIO); val |= AR_GPIO_BIT(gpio); OS_REG_RMW_FIELD(ah, AR_INTR_ASYNC_MASK, AR_INTR_GPIO, val); }
/* * Once configured for I/O - set output lines */ HAL_BOOL ar5416GpioSet(struct ath_hal *ah, uint32_t gpio, uint32_t val) { uint32_t reg; HALASSERT(gpio < AH_PRIVATE(ah)->ah_caps.halNumGpioPins); reg = OS_REG_READ(ah, AR_GPIO_IN_OUT); if (val & 1) reg |= AR_GPIO_BIT(gpio); else reg &= ~AR_GPIO_BIT(gpio); OS_REG_WRITE(ah, AR_GPIO_IN_OUT, reg); return AH_TRUE; }
/* * Once configured for I/O - set output lines */ HAL_BOOL ar5416GpioSet(struct ath_hal *ah, uint32_t gpio, uint32_t val) { uint32_t reg; HALASSERT(gpio < AR_NUM_GPIO); reg = MS(OS_REG_READ(ah, AR_GPIO_INTR_OUT), AR_GPIO_OUT_VAL); if (val & 1) reg |= AR_GPIO_BIT(gpio); else reg &= ~AR_GPIO_BIT(gpio); OS_REG_RMW_FIELD(ah, AR_GPIO_INTR_OUT, AR_GPIO_OUT_VAL, reg); return AH_TRUE; }
/* * Once configured for I/O - get input lines */ uint32_t ar5416GpioGet(struct ath_hal *ah, uint32_t gpio) { uint32_t bits; if (gpio >= AH_PRIVATE(ah)->ah_caps.halNumGpioPins) return 0xffffffff; /* * Read output value for all gpio's, shift it, * and verify whether the specific bit is set. */ if (AR_SREV_MERLIN_10_OR_LATER(ah)) bits = MS(OS_REG_READ(ah, AR_GPIO_IN_OUT), AR928X_GPIO_IN_VAL); else bits = MS(OS_REG_READ(ah, AR_GPIO_IN_OUT), AR_GPIO_IN_VAL); return ((bits & AR_GPIO_BIT(gpio)) != 0); }
/* * Set the GPIO Interrupt */ void ar5416GpioSetIntr(struct ath_hal *ah, u_int gpio, uint32_t ilevel) { uint32_t val, mask; HALASSERT(gpio < AH_PRIVATE(ah)->ah_caps.halNumGpioPins); if (ilevel == HAL_GPIO_INTR_DISABLE) { val = MS(OS_REG_READ(ah, AR_INTR_ASYNC_ENABLE), AR_INTR_ASYNC_ENABLE_GPIO) &~ AR_GPIO_BIT(gpio); OS_REG_RMW_FIELD(ah, AR_INTR_ASYNC_ENABLE, AR_INTR_ASYNC_ENABLE_GPIO, val); mask = MS(OS_REG_READ(ah, AR_INTR_ASYNC_MASK), AR_INTR_ASYNC_MASK_GPIO) &~ AR_GPIO_BIT(gpio); OS_REG_RMW_FIELD(ah, AR_INTR_ASYNC_MASK, AR_INTR_ASYNC_MASK_GPIO, mask); /* Clear synchronous GPIO interrupt registers and pending interrupt flag */ val = MS(OS_REG_READ(ah, AR_INTR_SYNC_ENABLE), AR_INTR_SYNC_ENABLE_GPIO) &~ AR_GPIO_BIT(gpio); OS_REG_RMW_FIELD(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_ENABLE_GPIO, val); mask = MS(OS_REG_READ(ah, AR_INTR_SYNC_MASK), AR_INTR_SYNC_MASK_GPIO) &~ AR_GPIO_BIT(gpio); OS_REG_RMW_FIELD(ah, AR_INTR_SYNC_MASK, AR_INTR_SYNC_MASK_GPIO, mask); val = MS(OS_REG_READ(ah, AR_INTR_SYNC_CAUSE), AR_INTR_SYNC_ENABLE_GPIO) | AR_GPIO_BIT(gpio); OS_REG_RMW_FIELD(ah, AR_INTR_SYNC_CAUSE, AR_INTR_SYNC_ENABLE_GPIO, val); } else { val = MS(OS_REG_READ(ah, AR_GPIO_INTR_POL), AR_GPIO_INTR_POL_VAL); if (ilevel == HAL_GPIO_INTR_HIGH) { /* 0 == interrupt on pin high */ val &= ~AR_GPIO_BIT(gpio); } else if (ilevel == HAL_GPIO_INTR_LOW) { /* 1 == interrupt on pin low */ val |= AR_GPIO_BIT(gpio); } OS_REG_RMW_FIELD(ah, AR_GPIO_INTR_POL, AR_GPIO_INTR_POL_VAL, val); /* Change the interrupt mask. */ val = MS(OS_REG_READ(ah, AR_INTR_ASYNC_ENABLE), AR_INTR_ASYNC_ENABLE_GPIO) | AR_GPIO_BIT(gpio); OS_REG_RMW_FIELD(ah, AR_INTR_ASYNC_ENABLE, AR_INTR_ASYNC_ENABLE_GPIO, val); mask = MS(OS_REG_READ(ah, AR_INTR_ASYNC_MASK), AR_INTR_ASYNC_MASK_GPIO) | AR_GPIO_BIT(gpio); OS_REG_RMW_FIELD(ah, AR_INTR_ASYNC_MASK, AR_INTR_ASYNC_MASK_GPIO, mask); /* Set synchronous GPIO interrupt registers as well */ val = MS(OS_REG_READ(ah, AR_INTR_SYNC_ENABLE), AR_INTR_SYNC_ENABLE_GPIO) | AR_GPIO_BIT(gpio); OS_REG_RMW_FIELD(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_ENABLE_GPIO, val); mask = MS(OS_REG_READ(ah, AR_INTR_SYNC_MASK), AR_INTR_SYNC_MASK_GPIO) | AR_GPIO_BIT(gpio); OS_REG_RMW_FIELD(ah, AR_INTR_SYNC_MASK, AR_INTR_SYNC_MASK_GPIO, mask); } AH5416(ah)->ah_gpioMask = mask; /* for ar5416SetInterrupts */ }
/* * Set the GPIO Interrupt * Sync and Async interrupts are both set/cleared. * Async GPIO interrupts may not be raised when the chip is put to sleep. */ void ar9300GpioSetIntr(struct ath_hal *ah, u_int gpio, u_int32_t ilevel) { #ifndef AR9340_EMULATION struct ath_hal_9300 *ahp = AH9300(ah); u_int32_t val, mask; HALASSERT(gpio < AH_PRIVATE(ah)->ah_caps.halNumGpioPins); if (ilevel == HAL_GPIO_INTR_DISABLE) { val = MS(OS_REG_READ(ah, AR_HOSTIF_REG(ah, AR_INTR_ASYNC_ENABLE)), AR_INTR_ASYNC_ENABLE_GPIO); val &= ~AR_GPIO_BIT(gpio); OS_REG_RMW_FIELD( ah, AR_HOSTIF_REG(ah, AR_INTR_ASYNC_ENABLE), AR_INTR_ASYNC_ENABLE_GPIO, val); mask = MS(OS_REG_READ(ah, AR_HOSTIF_REG(ah, AR_INTR_ASYNC_MASK)), AR_INTR_ASYNC_MASK_GPIO); mask &= ~AR_GPIO_BIT(gpio); OS_REG_RMW_FIELD(ah, AR_HOSTIF_REG(ah, AR_INTR_ASYNC_MASK), AR_INTR_ASYNC_MASK_GPIO, mask); /* * Clear synchronous GPIO interrupt registers and pending * interrupt flag */ val = MS(OS_REG_READ(ah, AR_HOSTIF_REG(ah, AR_INTR_SYNC_ENABLE)), AR_INTR_SYNC_ENABLE_GPIO); val &= ~AR_GPIO_BIT(gpio); OS_REG_RMW_FIELD( ah, AR_HOSTIF_REG(ah, AR_INTR_SYNC_ENABLE), AR_INTR_SYNC_ENABLE_GPIO, val); mask = MS(OS_REG_READ(ah, AR_HOSTIF_REG(ah, AR_INTR_SYNC_MASK)), AR_INTR_SYNC_MASK_GPIO); mask &= ~AR_GPIO_BIT(gpio); OS_REG_RMW_FIELD(ah, AR_HOSTIF_REG(ah, AR_INTR_SYNC_MASK), AR_INTR_SYNC_MASK_GPIO, mask); val = MS(OS_REG_READ(ah, AR_HOSTIF_REG(ah, AR_INTR_SYNC_CAUSE)), AR_INTR_SYNC_ENABLE_GPIO); val |= AR_GPIO_BIT(gpio); OS_REG_RMW_FIELD(ah, AR_HOSTIF_REG(ah, AR_INTR_SYNC_CAUSE), AR_INTR_SYNC_ENABLE_GPIO, val); } else { val = MS(OS_REG_READ(ah, AR_HOSTIF_REG(ah, AR_GPIO_INTR_POL)), AR_GPIO_INTR_POL_VAL); if (ilevel == HAL_GPIO_INTR_HIGH) { /* 0 == interrupt on pin high */ val &= ~AR_GPIO_BIT(gpio); } else if (ilevel == HAL_GPIO_INTR_LOW) { /* 1 == interrupt on pin low */ val |= AR_GPIO_BIT(gpio); } OS_REG_RMW_FIELD(ah, AR_HOSTIF_REG(ah, AR_GPIO_INTR_POL), AR_GPIO_INTR_POL_VAL, val); /* Change the interrupt mask. */ val = MS(OS_REG_READ(ah, AR_HOSTIF_REG(ah, AR_INTR_ASYNC_ENABLE)), AR_INTR_ASYNC_ENABLE_GPIO); val |= AR_GPIO_BIT(gpio); OS_REG_RMW_FIELD( ah, AR_HOSTIF_REG(ah, AR_INTR_ASYNC_ENABLE), AR_INTR_ASYNC_ENABLE_GPIO, val); mask = MS(OS_REG_READ(ah, AR_HOSTIF_REG(ah, AR_INTR_ASYNC_MASK)), AR_INTR_ASYNC_MASK_GPIO); mask |= AR_GPIO_BIT(gpio); OS_REG_RMW_FIELD(ah, AR_HOSTIF_REG(ah, AR_INTR_ASYNC_MASK), AR_INTR_ASYNC_MASK_GPIO, mask); /* Set synchronous GPIO interrupt registers as well */ val = MS(OS_REG_READ(ah, AR_HOSTIF_REG(ah, AR_INTR_SYNC_ENABLE)), AR_INTR_SYNC_ENABLE_GPIO); val |= AR_GPIO_BIT(gpio); OS_REG_RMW_FIELD( ah, AR_HOSTIF_REG(ah, AR_INTR_SYNC_ENABLE), AR_INTR_SYNC_ENABLE_GPIO, val); mask = MS(OS_REG_READ(ah, AR_HOSTIF_REG(ah, AR_INTR_SYNC_MASK)), AR_INTR_SYNC_MASK_GPIO); mask |= AR_GPIO_BIT(gpio); OS_REG_RMW_FIELD(ah, AR_HOSTIF_REG(ah, AR_INTR_SYNC_MASK), AR_INTR_SYNC_MASK_GPIO, mask); } /* Save GPIO interrupt mask */ HALASSERT(mask == val); ahp->ah_gpioMask = mask; #endif }