gpio.c (d4bbf7e7759afc172e2bfbc5c416324590049cdd) | gpio.c (c47faa364cfb249d5d7670fb7293a6f9acd8aa9e) |
---|---|
1/* 2 * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org> 3 * Copyright (c) 2006-2008 Nick Kossifidis <mickflemm@gmail.com> 4 * 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. 8 * --- 10 unchanged lines hidden (view full) --- 19/****************\ 20 GPIO Functions 21\****************/ 22 23#include "ath5k.h" 24#include "reg.h" 25#include "debug.h" 26 | 1/* 2 * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org> 3 * Copyright (c) 2006-2008 Nick Kossifidis <mickflemm@gmail.com> 4 * 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. 8 * --- 10 unchanged lines hidden (view full) --- 19/****************\ 20 GPIO Functions 21\****************/ 22 23#include "ath5k.h" 24#include "reg.h" 25#include "debug.h" 26 |
27/* 28 * Set led state | 27 28/** 29 * DOC: GPIO/LED functions 30 * 31 * Here we control the 6 bidirectional GPIO pins provided by the hw. 32 * We can set a GPIO pin to be an input or an output pin on GPIO control 33 * register and then read or set its status from GPIO data input/output 34 * registers. 35 * 36 * We also control the two LED pins provided by the hw, LED_0 is our 37 * "power" LED and LED_1 is our "network activity" LED but many scenarios 38 * are available from hw. Vendors might also provide LEDs connected to the 39 * GPIO pins, we handle them through the LED subsystem on led.c |
29 */ | 40 */ |
30void ath5k_hw_set_ledstate(struct ath5k_hw *ah, unsigned int state) | 41 42 43/** 44 * ath5k_hw_set_ledstate() - Set led state 45 * @ah: The &struct ath5k_hw 46 * @state: One of AR5K_LED_* 47 * 48 * Used to set the LED blinking state. This only 49 * works for the LED connected to the LED_0, LED_1 pins, 50 * not the GPIO based. 51 */ 52void 53ath5k_hw_set_ledstate(struct ath5k_hw *ah, unsigned int state) |
31{ 32 u32 led; 33 /*5210 has different led mode handling*/ 34 u32 led_5210; 35 36 /*Reset led status*/ 37 if (ah->ah_version != AR5K_AR5210) 38 AR5K_REG_DISABLE_BITS(ah, AR5K_PCICFG, --- 30 unchanged lines hidden (view full) --- 69 70 /*Write new status to the register*/ 71 if (ah->ah_version != AR5K_AR5210) 72 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, led); 73 else 74 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, led_5210); 75} 76 | 54{ 55 u32 led; 56 /*5210 has different led mode handling*/ 57 u32 led_5210; 58 59 /*Reset led status*/ 60 if (ah->ah_version != AR5K_AR5210) 61 AR5K_REG_DISABLE_BITS(ah, AR5K_PCICFG, --- 30 unchanged lines hidden (view full) --- 92 93 /*Write new status to the register*/ 94 if (ah->ah_version != AR5K_AR5210) 95 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, led); 96 else 97 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, led_5210); 98} 99 |
77/* 78 * Set GPIO inputs | 100/** 101 * ath5k_hw_set_gpio_input() - Set GPIO inputs 102 * @ah: The &struct ath5k_hw 103 * @gpio: GPIO pin to set as input |
79 */ | 104 */ |
80int ath5k_hw_set_gpio_input(struct ath5k_hw *ah, u32 gpio) | 105int 106ath5k_hw_set_gpio_input(struct ath5k_hw *ah, u32 gpio) |
81{ 82 if (gpio >= AR5K_NUM_GPIO) 83 return -EINVAL; 84 85 ath5k_hw_reg_write(ah, 86 (ath5k_hw_reg_read(ah, AR5K_GPIOCR) & ~AR5K_GPIOCR_OUT(gpio)) 87 | AR5K_GPIOCR_IN(gpio), AR5K_GPIOCR); 88 89 return 0; 90} 91 | 107{ 108 if (gpio >= AR5K_NUM_GPIO) 109 return -EINVAL; 110 111 ath5k_hw_reg_write(ah, 112 (ath5k_hw_reg_read(ah, AR5K_GPIOCR) & ~AR5K_GPIOCR_OUT(gpio)) 113 | AR5K_GPIOCR_IN(gpio), AR5K_GPIOCR); 114 115 return 0; 116} 117 |
92/* 93 * Set GPIO outputs | 118/** 119 * ath5k_hw_set_gpio_output() - Set GPIO outputs 120 * @ah: The &struct ath5k_hw 121 * @gpio: The GPIO pin to set as output |
94 */ | 122 */ |
95int ath5k_hw_set_gpio_output(struct ath5k_hw *ah, u32 gpio) | 123int 124ath5k_hw_set_gpio_output(struct ath5k_hw *ah, u32 gpio) |
96{ 97 if (gpio >= AR5K_NUM_GPIO) 98 return -EINVAL; 99 100 ath5k_hw_reg_write(ah, 101 (ath5k_hw_reg_read(ah, AR5K_GPIOCR) & ~AR5K_GPIOCR_OUT(gpio)) 102 | AR5K_GPIOCR_OUT(gpio), AR5K_GPIOCR); 103 104 return 0; 105} 106 | 125{ 126 if (gpio >= AR5K_NUM_GPIO) 127 return -EINVAL; 128 129 ath5k_hw_reg_write(ah, 130 (ath5k_hw_reg_read(ah, AR5K_GPIOCR) & ~AR5K_GPIOCR_OUT(gpio)) 131 | AR5K_GPIOCR_OUT(gpio), AR5K_GPIOCR); 132 133 return 0; 134} 135 |
107/* 108 * Get GPIO state | 136/** 137 * ath5k_hw_get_gpio() - Get GPIO state 138 * @ah: The &struct ath5k_hw 139 * @gpio: The GPIO pin to read |
109 */ | 140 */ |
110u32 ath5k_hw_get_gpio(struct ath5k_hw *ah, u32 gpio) | 141u32 142ath5k_hw_get_gpio(struct ath5k_hw *ah, u32 gpio) |
111{ 112 if (gpio >= AR5K_NUM_GPIO) 113 return 0xffffffff; 114 115 /* GPIO input magic */ 116 return ((ath5k_hw_reg_read(ah, AR5K_GPIODI) & AR5K_GPIODI_M) >> gpio) & 117 0x1; 118} 119 | 143{ 144 if (gpio >= AR5K_NUM_GPIO) 145 return 0xffffffff; 146 147 /* GPIO input magic */ 148 return ((ath5k_hw_reg_read(ah, AR5K_GPIODI) & AR5K_GPIODI_M) >> gpio) & 149 0x1; 150} 151 |
120/* 121 * Set GPIO state | 152/** 153 * ath5k_hw_set_gpio() - Set GPIO state 154 * @ah: The &struct ath5k_hw 155 * @gpio: The GPIO pin to set 156 * @val: Value to set (boolean) |
122 */ | 157 */ |
123int ath5k_hw_set_gpio(struct ath5k_hw *ah, u32 gpio, u32 val) | 158int 159ath5k_hw_set_gpio(struct ath5k_hw *ah, u32 gpio, u32 val) |
124{ 125 u32 data; 126 127 if (gpio >= AR5K_NUM_GPIO) 128 return -EINVAL; 129 130 /* GPIO output magic */ 131 data = ath5k_hw_reg_read(ah, AR5K_GPIODO); 132 133 data &= ~(1 << gpio); 134 data |= (val & 1) << gpio; 135 136 ath5k_hw_reg_write(ah, data, AR5K_GPIODO); 137 138 return 0; 139} 140 | 160{ 161 u32 data; 162 163 if (gpio >= AR5K_NUM_GPIO) 164 return -EINVAL; 165 166 /* GPIO output magic */ 167 data = ath5k_hw_reg_read(ah, AR5K_GPIODO); 168 169 data &= ~(1 << gpio); 170 data |= (val & 1) << gpio; 171 172 ath5k_hw_reg_write(ah, data, AR5K_GPIODO); 173 174 return 0; 175} 176 |
141/* 142 * Initialize the GPIO interrupt (RFKill switch) | 177/** 178 * ath5k_hw_set_gpio_intr() - Initialize the GPIO interrupt (RFKill switch) 179 * @ah: The &struct ath5k_hw 180 * @gpio: The GPIO pin to use 181 * @interrupt_level: True to generate interrupt on active pin (high) 182 * 183 * This function is used to set up the GPIO interrupt for the hw RFKill switch. 184 * That switch is connected to a GPIO pin and it's number is stored on EEPROM. 185 * It can either open or close the circuit to indicate that we should disable 186 * RF/Wireless to save power (we also get that from EEPROM). |
143 */ | 187 */ |
144void ath5k_hw_set_gpio_intr(struct ath5k_hw *ah, unsigned int gpio, | 188void 189ath5k_hw_set_gpio_intr(struct ath5k_hw *ah, unsigned int gpio, |
145 u32 interrupt_level) 146{ 147 u32 data; 148 149 if (gpio >= AR5K_NUM_GPIO) 150 return; 151 152 /* --- 16 unchanged lines hidden --- | 190 u32 interrupt_level) 191{ 192 u32 data; 193 194 if (gpio >= AR5K_NUM_GPIO) 195 return; 196 197 /* --- 16 unchanged lines hidden --- |