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 
23 /****************\
24  GPIO Functions
25 \****************/
26 
27 #include "ath5k.h"
28 #include "reg.h"
29 #include "base.h"
30 
31 /*
32  * Set GPIO inputs
33  */
35 {
36  if (gpio >= AR5K_NUM_GPIO)
37  return -EINVAL;
38 
42 
43  return 0;
44 }
45 
46 /*
47  * Set GPIO outputs
48  */
50 {
51  if (gpio >= AR5K_NUM_GPIO)
52  return -EINVAL;
53 
57 
58  return 0;
59 }
60 
61 /*
62  * Get GPIO state
63  */
65 {
66  if (gpio >= AR5K_NUM_GPIO)
67  return 0xffffffff;
68 
69  /* GPIO input magic */
71  0x1;
72 }
73 
74 /*
75  * Set GPIO state
76  */
78 {
79  u32 data;
80 
81  if (gpio >= AR5K_NUM_GPIO)
82  return -EINVAL;
83 
84  /* GPIO output magic */
86 
87  data &= ~(1 << gpio);
88  data |= (val & 1) << gpio;
89 
91 
92  return 0;
93 }
94 
95 /*
96  * Initialize the GPIO interrupt (RFKill switch)
97  */
98 void ath5k_hw_set_gpio_intr(struct ath5k_hw *ah, unsigned int gpio,
99  u32 interrupt_level)
100 {
101  u32 data;
102 
103  if (gpio >= AR5K_NUM_GPIO)
104  return;
105 
106  /*
107  * Set the GPIO interrupt
108  */
113 
114  ath5k_hw_reg_write(ah, interrupt_level ? data :
116 
117  ah->ah_imr |= AR5K_IMR_GPIO;
118 
119  /* Enable GPIO interrupts */
121 }
122 
#define EINVAL
Invalid argument.
Definition: errno.h:428
#define AR5K_GPIOCR_IN(n)
Definition: reg.h:937
#define AR5K_GPIOCR_INT_ENA
Definition: reg.h:934
u32 ath5k_hw_get_gpio(struct ath5k_hw *ah, u32 gpio)
Definition: ath5k_gpio.c:64
FILE_LICENCE(MIT)
int ath5k_hw_set_gpio(struct ath5k_hw *ah, u32 gpio, u32 val)
Definition: ath5k_gpio.c:77
#define AR5K_GPIODO
Definition: reg.h:946
#define AR5K_IMR_GPIO
Definition: reg.h:410
#define AR5K_GPIODI_M
Definition: reg.h:952
#define AR5K_GPIOCR_INT_SEL(n)
Definition: reg.h:941
ath5k_hw_get_isr - Get interrupt status
Definition: ath5k.h:953
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:98
int ath5k_hw_set_gpio_input(struct ath5k_hw *ah, u32 gpio)
Definition: ath5k_gpio.c:34
#define AR5K_GPIOCR
Definition: reg.h:933
#define AR5K_PIMR
Definition: reg.h:380
#define AR5K_NUM_GPIO
Definition: reg.h:931
static void ath5k_hw_reg_write(struct ath5k_hw *ah, u32 val, u16 reg)
Definition: ath5k.h:1222
void __asmcall int val
Definition: setjmp.h:28
#define AR5K_GPIODI
Definition: reg.h:951
#define AR5K_GPIOCR_OUT(n)
Definition: reg.h:940
uint8_t ah
Definition: registers.h:85
#define AR5K_GPIOCR_INT_SELH
Definition: reg.h:936
static u32 ath5k_hw_reg_read(struct ath5k_hw *ah, u16 reg)
Definition: ath5k.h:1214
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
int ath5k_hw_set_gpio_output(struct ath5k_hw *ah, u32 gpio)
Definition: ath5k_gpio.c:49
uint32_t u32
Definition: stdint.h:23
#define AR5K_REG_ENABLE_BITS(ah, _reg, _flags)
Definition: ath5k.h:104