2 * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org>
3 * Copyright (c) 2006-2008 Nick Kossifidis <mickflemm@gmail.com>
5 * Permission to use, copy, modify, and 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.
31 void ath5k_hw_set_ledstate(struct ath5k_hw
*ah
, unsigned int state
)
34 /*5210 has different led mode handling*/
37 ATH5K_TRACE(ah
->ah_sc
);
40 if (ah
->ah_version
!= AR5K_AR5210
)
41 AR5K_REG_DISABLE_BITS(ah
, AR5K_PCICFG
,
42 AR5K_PCICFG_LEDMODE
| AR5K_PCICFG_LED
);
44 AR5K_REG_DISABLE_BITS(ah
, AR5K_PCICFG
, AR5K_PCICFG_LED
);
47 * Some blinking values, define at your wish
52 led
= AR5K_PCICFG_LEDMODE_PROP
| AR5K_PCICFG_LED_PEND
;
53 led_5210
= AR5K_PCICFG_LED_PEND
| AR5K_PCICFG_LED_BCTL
;
57 led
= AR5K_PCICFG_LEDMODE_PROP
| AR5K_PCICFG_LED_NONE
;
58 led_5210
= AR5K_PCICFG_LED_PEND
;
63 led
= AR5K_PCICFG_LEDMODE_PROP
| AR5K_PCICFG_LED_ASSOC
;
64 led_5210
= AR5K_PCICFG_LED_ASSOC
;
68 led
= AR5K_PCICFG_LEDMODE_PROM
| AR5K_PCICFG_LED_NONE
;
69 led_5210
= AR5K_PCICFG_LED_PEND
;
73 /*Write new status to the register*/
74 if (ah
->ah_version
!= AR5K_AR5210
)
75 AR5K_REG_ENABLE_BITS(ah
, AR5K_PCICFG
, led
);
77 AR5K_REG_ENABLE_BITS(ah
, AR5K_PCICFG
, led_5210
);
83 int ath5k_hw_set_gpio_input(struct ath5k_hw
*ah
, u32 gpio
)
85 ATH5K_TRACE(ah
->ah_sc
);
86 if (gpio
>= AR5K_NUM_GPIO
)
89 ath5k_hw_reg_write(ah
,
90 (ath5k_hw_reg_read(ah
, AR5K_GPIOCR
) & ~AR5K_GPIOCR_OUT(gpio
))
91 | AR5K_GPIOCR_IN(gpio
), AR5K_GPIOCR
);
99 int ath5k_hw_set_gpio_output(struct ath5k_hw
*ah
, u32 gpio
)
101 ATH5K_TRACE(ah
->ah_sc
);
102 if (gpio
>= AR5K_NUM_GPIO
)
105 ath5k_hw_reg_write(ah
,
106 (ath5k_hw_reg_read(ah
, AR5K_GPIOCR
) & ~AR5K_GPIOCR_OUT(gpio
))
107 | AR5K_GPIOCR_OUT(gpio
), AR5K_GPIOCR
);
115 u32
ath5k_hw_get_gpio(struct ath5k_hw
*ah
, u32 gpio
)
117 ATH5K_TRACE(ah
->ah_sc
);
118 if (gpio
>= AR5K_NUM_GPIO
)
121 /* GPIO input magic */
122 return ((ath5k_hw_reg_read(ah
, AR5K_GPIODI
) & AR5K_GPIODI_M
) >> gpio
) &
129 int ath5k_hw_set_gpio(struct ath5k_hw
*ah
, u32 gpio
, u32 val
)
132 ATH5K_TRACE(ah
->ah_sc
);
134 if (gpio
>= AR5K_NUM_GPIO
)
137 /* GPIO output magic */
138 data
= ath5k_hw_reg_read(ah
, AR5K_GPIODO
);
140 data
&= ~(1 << gpio
);
141 data
|= (val
& 1) << gpio
;
143 ath5k_hw_reg_write(ah
, data
, AR5K_GPIODO
);
149 * Initialize the GPIO interrupt (RFKill switch)
151 void ath5k_hw_set_gpio_intr(struct ath5k_hw
*ah
, unsigned int gpio
,
156 ATH5K_TRACE(ah
->ah_sc
);
157 if (gpio
>= AR5K_NUM_GPIO
)
161 * Set the GPIO interrupt
163 data
= (ath5k_hw_reg_read(ah
, AR5K_GPIOCR
) &
164 ~(AR5K_GPIOCR_INT_SEL(gpio
) | AR5K_GPIOCR_INT_SELH
|
165 AR5K_GPIOCR_INT_ENA
| AR5K_GPIOCR_OUT(gpio
))) |
166 (AR5K_GPIOCR_INT_SEL(gpio
) | AR5K_GPIOCR_INT_ENA
);
168 ath5k_hw_reg_write(ah
, interrupt_level
? data
:
169 (data
| AR5K_GPIOCR_INT_SELH
), AR5K_GPIOCR
);
171 ah
->ah_imr
|= AR5K_IMR_GPIO
;
173 /* Enable GPIO interrupts */
174 AR5K_REG_ENABLE_BITS(ah
, AR5K_PIMR
, AR5K_IMR_GPIO
);