iPXE
ath5k_gpio.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org>
3  * Copyright (c) 2006-2008 Nick Kossifidis <mickflemm@gmail.com>
4  *
5  * Lightly modified for iPXE, July 2009, by Joshua Oreman <oremanj@rwcr.net>.
6  *
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.
10  *
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.
18  *
19  */
20 
21 FILE_LICENCE ( MIT );
22 FILE_SECBOOT ( FORBIDDEN );
23 
24 /****************\
25  GPIO Functions
26 \****************/
27 
28 #include "ath5k.h"
29 #include "reg.h"
30 #include "base.h"
31 
32 /*
33  * Set GPIO inputs
34  */
36 {
37  if (gpio >= AR5K_NUM_GPIO)
38  return -EINVAL;
39 
43 
44  return 0;
45 }
46 
47 /*
48  * Set GPIO outputs
49  */
51 {
52  if (gpio >= AR5K_NUM_GPIO)
53  return -EINVAL;
54 
58 
59  return 0;
60 }
61 
62 /*
63  * Get GPIO state
64  */
66 {
67  if (gpio >= AR5K_NUM_GPIO)
68  return 0xffffffff;
69 
70  /* GPIO input magic */
72  0x1;
73 }
74 
75 /*
76  * Set GPIO state
77  */
79 {
80  u32 data;
81 
82  if (gpio >= AR5K_NUM_GPIO)
83  return -EINVAL;
84 
85  /* GPIO output magic */
87 
88  data &= ~(1 << gpio);
89  data |= (val & 1) << gpio;
90 
92 
93  return 0;
94 }
95 
96 /*
97  * Initialize the GPIO interrupt (RFKill switch)
98  */
99 void ath5k_hw_set_gpio_intr(struct ath5k_hw *ah, unsigned int gpio,
100  u32 interrupt_level)
101 {
102  u32 data;
103 
104  if (gpio >= AR5K_NUM_GPIO)
105  return;
106 
107  /*
108  * Set the GPIO interrupt
109  */
114 
115  ath5k_hw_reg_write(ah, interrupt_level ? data :
117 
118  ah->ah_imr |= AR5K_IMR_GPIO;
119 
120  /* Enable GPIO interrupts */
122 }
123 
#define EINVAL
Invalid argument.
Definition: errno.h:429
#define AR5K_GPIOCR_IN(n)
Definition: reg.h:939
#define AR5K_GPIOCR_INT_ENA
Definition: reg.h:936
void __asmcall int val
Definition: setjmp.h:12
u32 ath5k_hw_get_gpio(struct ath5k_hw *ah, u32 gpio)
Definition: ath5k_gpio.c:65
FILE_LICENCE(MIT)
int ath5k_hw_set_gpio(struct ath5k_hw *ah, u32 gpio, u32 val)
Definition: ath5k_gpio.c:78
#define AR5K_GPIODO
Definition: reg.h:948
#define AR5K_IMR_GPIO
Definition: reg.h:412
#define AR5K_GPIODI_M
Definition: reg.h:954
#define AR5K_GPIOCR_INT_SEL(n)
Definition: reg.h:943
ath5k_hw_get_isr - Get interrupt status
Definition: ath5k.h:955
FILE_SECBOOT(FORBIDDEN)
pseudo_bit_t gpio[0x00001]
Definition: arbel.h:30
void ath5k_hw_set_gpio_intr(struct ath5k_hw *ah, unsigned int gpio, u32 interrupt_level)
Definition: ath5k_gpio.c:99
int ath5k_hw_set_gpio_input(struct ath5k_hw *ah, u32 gpio)
Definition: ath5k_gpio.c:35
#define AR5K_GPIOCR
Definition: reg.h:935
#define AR5K_PIMR
Definition: reg.h:382
#define AR5K_NUM_GPIO
Definition: reg.h:933
static void ath5k_hw_reg_write(struct ath5k_hw *ah, u32 val, u16 reg)
Definition: ath5k.h:1224
#define AR5K_GPIODI
Definition: reg.h:953
uint8_t data[48]
Additional event data.
Definition: ena.h:22
#define AR5K_GPIOCR_OUT(n)
Definition: reg.h:942
uint8_t ah
Definition: registers.h:85
A GPIO pin.
Definition: gpio.h:18
#define AR5K_GPIOCR_INT_SELH
Definition: reg.h:938
static u32 ath5k_hw_reg_read(struct ath5k_hw *ah, u16 reg)
Definition: ath5k.h:1216
int ath5k_hw_set_gpio_output(struct ath5k_hw *ah, u32 gpio)
Definition: ath5k_gpio.c:50
uint32_t u32
Definition: stdint.h:24
#define AR5K_REG_ENABLE_BITS(ah, _reg, _flags)
Definition: ath5k.h:106