2 * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org>
3 * Copyright (c) 2006-2008 Nick Kossifidis <mickflemm@gmail.com>
5 * Lightly modified for iPXE, July 2009, by Joshua Oreman <oremanj@rwcr.net>.
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
34 int ath5k_hw_set_gpio_input(struct ath5k_hw *ah, u32 gpio)
36 if (gpio >= AR5K_NUM_GPIO)
39 ath5k_hw_reg_write(ah,
40 (ath5k_hw_reg_read(ah, AR5K_GPIOCR) & ~AR5K_GPIOCR_OUT(gpio))
41 | AR5K_GPIOCR_IN(gpio), AR5K_GPIOCR);
49 int ath5k_hw_set_gpio_output(struct ath5k_hw *ah, u32 gpio)
51 if (gpio >= AR5K_NUM_GPIO)
54 ath5k_hw_reg_write(ah,
55 (ath5k_hw_reg_read(ah, AR5K_GPIOCR) & ~AR5K_GPIOCR_OUT(gpio))
56 | AR5K_GPIOCR_OUT(gpio), AR5K_GPIOCR);
64 u32 ath5k_hw_get_gpio(struct ath5k_hw *ah, u32 gpio)
66 if (gpio >= AR5K_NUM_GPIO)
69 /* GPIO input magic */
70 return ((ath5k_hw_reg_read(ah, AR5K_GPIODI) & AR5K_GPIODI_M) >> gpio) &
77 int ath5k_hw_set_gpio(struct ath5k_hw *ah, u32 gpio, u32 val)
81 if (gpio >= AR5K_NUM_GPIO)
84 /* GPIO output magic */
85 data = ath5k_hw_reg_read(ah, AR5K_GPIODO);
88 data |= (val & 1) << gpio;
90 ath5k_hw_reg_write(ah, data, AR5K_GPIODO);
96 * Initialize the GPIO interrupt (RFKill switch)
98 void ath5k_hw_set_gpio_intr(struct ath5k_hw *ah, unsigned int gpio,
103 if (gpio >= AR5K_NUM_GPIO)
107 * Set the GPIO interrupt
109 data = (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &
110 ~(AR5K_GPIOCR_INT_SEL(gpio) | AR5K_GPIOCR_INT_SELH |
111 AR5K_GPIOCR_INT_ENA | AR5K_GPIOCR_OUT(gpio))) |
112 (AR5K_GPIOCR_INT_SEL(gpio) | AR5K_GPIOCR_INT_ENA);
114 ath5k_hw_reg_write(ah, interrupt_level ? data :
115 (data | AR5K_GPIOCR_INT_SELH), AR5K_GPIOCR);
117 ah->ah_imr |= AR5K_IMR_GPIO;
119 /* Enable GPIO interrupts */
120 AR5K_REG_ENABLE_BITS(ah, AR5K_PIMR, AR5K_IMR_GPIO);