2 * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
3 * Copyright (c) 2002-2008 Atheros Communications, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 * $Id: ar5312_gpio.c,v 1.1.1.1 2008/12/11 04:46:45 alc Exp $
21 #ifdef AH_SUPPORT_AR5312
24 #include "ah_internal.h"
27 #include "ar5312/ar5312.h"
28 #include "ar5312/ar5312reg.h"
29 #include "ar5312/ar5312phy.h"
31 #define AR_NUM_GPIO 6 /* 6 GPIO pins */
32 #define AR5312_GPIOD_MASK 0x0000002F /* GPIO data reg r/w mask */
35 * Configure GPIO Output lines
38 ar5312GpioCfgOutput(struct ath_hal
*ah
, uint32_t gpio
)
40 uint32_t gpioOffset
= (AR5312_GPIO_BASE
- ((uint32_t) ah
->ah_sh
));
42 HALASSERT(gpio
< AR_NUM_GPIO
);
44 OS_REG_WRITE(ah
, gpioOffset
+AR5312_GPIOCR
,
45 (OS_REG_READ(ah
, gpioOffset
+AR5312_GPIOCR
) &~ AR_GPIOCR_CR_A(gpio
))
46 | AR_GPIOCR_CR_A(gpio
));
52 * Configure GPIO Input lines
55 ar5312GpioCfgInput(struct ath_hal
*ah
, uint32_t gpio
)
57 uint32_t gpioOffset
= (AR5312_GPIO_BASE
- ((uint32_t) ah
->ah_sh
));
59 HALASSERT(gpio
< AR_NUM_GPIO
);
61 OS_REG_WRITE(ah
, gpioOffset
+AR5312_GPIOCR
,
62 (OS_REG_READ(ah
, gpioOffset
+AR5312_GPIOCR
) &~ AR_GPIOCR_CR_A(gpio
))
63 | AR_GPIOCR_CR_N(gpio
));
69 * Once configured for I/O - set output lines
72 ar5312GpioSet(struct ath_hal
*ah
, uint32_t gpio
, uint32_t val
)
75 uint32_t gpioOffset
= (AR5312_GPIO_BASE
- ((uint32_t) ah
->ah_sh
));
77 HALASSERT(gpio
< AR_NUM_GPIO
);
79 reg
= OS_REG_READ(ah
, gpioOffset
+AR5312_GPIODO
);
81 reg
|= (val
&1) << gpio
;
83 OS_REG_WRITE(ah
, gpioOffset
+AR5312_GPIODO
, reg
);
88 * Once configured for I/O - get input lines
91 ar5312GpioGet(struct ath_hal
*ah
, uint32_t gpio
)
93 uint32_t gpioOffset
= (AR5312_GPIO_BASE
- ((uint32_t) ah
->ah_sh
));
95 if (gpio
< AR_NUM_GPIO
) {
96 uint32_t val
= OS_REG_READ(ah
, gpioOffset
+AR5312_GPIODI
);
97 val
= ((val
& AR5312_GPIOD_MASK
) >> gpio
) & 0x1;
105 * Set the GPIO Interrupt
108 ar5312GpioSetIntr(struct ath_hal
*ah
, u_int gpio
, uint32_t ilevel
)
111 uint32_t gpioOffset
= (AR5312_GPIO_BASE
- ((uint32_t) ah
->ah_sh
));
113 /* XXX bounds check gpio */
114 val
= OS_REG_READ(ah
, gpioOffset
+AR5312_GPIOCR
);
115 val
&= ~(AR_GPIOCR_CR_A(gpio
) |
116 AR_GPIOCR_INT_MASK
| AR_GPIOCR_INT_ENA
| AR_GPIOCR_INT_SEL
);
117 val
|= AR_GPIOCR_CR_N(gpio
) | AR_GPIOCR_INT(gpio
) | AR_GPIOCR_INT_ENA
;
119 val
|= AR_GPIOCR_INT_SELH
; /* interrupt on pin high */
121 val
|= AR_GPIOCR_INT_SELL
; /* interrupt on pin low */
123 /* Don't need to change anything for low level interrupt. */
124 OS_REG_WRITE(ah
, gpioOffset
+AR5312_GPIOCR
, val
);
126 /* Change the interrupt mask. */
127 (void) ar5212SetInterrupts(ah
, AH5212(ah
)->ah_maskReg
| HAL_INT_GPIO
);
131 #endif /* AH_SUPPORT_AR5312 */