56
int
mhn_gpio_set_direction(int gpio_id, int dir) 57 { 58 unsigned long flags; 59 int gpio = MFP2GPIO(gpio_id); 60 61 GPIO_ID_VERIFY(gpio); 62 63 spin_lock_irqsave(&gpio_spin_lock, flags); 64 #if defined(CONFIG_MONAHANS_GPIOEX) 65 if (gpio >= GPIO_EXP_START) { 66 spin_unlock_irqrestore(&gpio_spin_lock, flags); 67 return gpio_exp_set_direction(gpio, dir); 68 } 69 #endif 70 if (dir == GPIO_DIR_IN) 71 G CDR(gpio) = 1u << (gpio & 0x1f); 72 else 73 GSDR(gpio) = 1u << (gpio & 0x1f); 74 75 spin_unlock_irqrestore(&gpio_spin_lock, flags); 76 77 return 0; 78 } |
80
int
mhn_gpio_get_direction(int gpio_id) 81 { 82 int gpio = MFP2GPIO(gpio_id); 83 84 GPIO_ID_VERIFY(gpio); 85 #if defined(CONFIG_MONAHANS_GPIOEX) 86 if (gpio >= GPIO_EXP_START) 87 return gpio_exp_get_direction(gpio); 88 #endif 89 90 if (GPDR(gpio) & (1u << (gpio & 0x1f))) 91 return GPIO_DIR_OUT; 92 else 93 return GPIO_DIR_IN; 94 } |
96
int
mhn_gpio_set_level(int gpio_id, int level) 97 { 98 unsigned long flags; 99 int gpio = MFP2GPIO(gpio_id); 100 101 GPIO_ID_VERIFY(gpio); 102 103 spin_lock_irqsave(&gpio_spin_lock, flags); 104 #if defined(CONFIG_MONAHANS_GPIOEX) 105 if (gpio >= GPIO_EXP_START) { 106 spin_unlock_irqrestore(&gpio_spin_lock, flags); 107 return gpio_exp_set_level(gpio, level); 108 } 109 #endif 110 111 if (level == GPIO_LEVEL_LOW) 112 GPCR(gpio) = 1u << (gpio & 0x1f); 113 else 114 GPSR(gpio) = 1u << (gpio & 0x1f); 115 116 spin_unlock_irqrestore(&gpio_spin_lock, flags); 117 118 return 0; 119 } |
121
int
mhn_gpio_get_level(int gpio_id) 122 { 123 int gpio = MFP2GPIO(gpio_id); 124 125 GPIO_ID_VERIFY(gpio); 126 #if defined(CONFIG_MONAHANS_GPIOEX) 127 if (gpio >= GPIO_EXP_START) 128 return gpio_exp_get_level(gpio); 129 #endif 130 131 if (GPLR(gpio) & (1u << (gpio & 0x1f))) 132 return GPIO_LEVEL_HIGH; 133 else 134 return GPIO_LEVEL_LOW; 135 } |
140
int
mhn_gpio_set_rising_edge_detect(int gpio_id, int enable) 141 { 142 unsigned long flags; 143 int gpio = MFP2GPIO(gpio_id); 144 145 GPIO_ID_VERIFY(gpio); 146 #if defined(CONFIG_MONAHANS_GPIOEX) 147 if (gpio >= GPIO_EXP_START) 148 return 0; 149 #endif 150 151 spin_lock_irqsave(&gpio_spin_lock, flags); 152 153 if (enable == 0) 154 GCRER(gpio) = 1u << (gpio & 0x1f); 155 else 156 GSRER(gpio) = 1u << (gpio & 0x1f); 157 158 spin_unlock_irqrestore(&gpio_spin_lock, flags); 159 160 return 0; 161 } |
163
int
mhn_gpio_get_rising_edge_detect(int gpio_id) 164 { 165 int gpio = MFP2GPIO(gpio_id); 166 167 GPIO_ID_VERIFY(gpio); 168 #if defined(CONFIG_MONAHANS_GPIOEX) 169 if (gpio >= GPIO_EXP_START) 170 return 0; 171 #endif 172 173 if (GRER(gpio) & (1u << (gpio & 0x1f))) 174 return 1; 175 176 return 0; 177 } |
179
int
mhn_gpio_set_falling_edge_detect(int gpio_id, int enable) 180 { 181 unsigned long flags; 182 int gpio = MFP2GPIO(gpio_id); 183 184 GPIO_ID_VERIFY(gpio); 185 186 #if defined(CONFIG_MONAHANS_GPIOEX) 187 if (gpio >= GPIO_EXP_START) 188 return 0; 189 #endif 190 191 spin_lock_irqsave(&gpio_spin_lock, flags); 192 193 if (enable == 0) 194 GCRER(gpio) = 1u << (gpio & 0x1f); 195 else 196 GSRER(gpio) = 1u << (gpio & 0x1f); 197 198 spin_unlock_irqrestore(&gpio_spin_lock, flags); 199 200 return 0; 201 } |
203
int
mhn_gpio_get_falling_edge_detect(int gpio_id) 204 { 205 int gpio = MFP2GPIO(gpio_id); 206 207 GPIO_ID_VERIFY(gpio); 208 209 #if defined(CONFIG_MONAHANS_GPIOEX) 210 if (gpio >= GPIO_EXP_START) 211 return 0; 212 #endif 213 214 if (GFER(gpio) & (1u << (gpio & 0x1f))) 215 return 1; 216 217 return 0; 218 } |
220
int
mhn_gpio_get_edge_detect_status(int gpio_id) 221 { 222 int gpio = MFP2GPIO(gpio_id); 223 224 GPIO_ID_VERIFY(gpio); 225 226 #if defined(CONFIG_MONAHANS_GPIOEX) 227 if (gpio >= GPIO_EXP_START) 228 return 0; 229 #endif 230 231 if (GEDR(gpio) & (1u << (gpio & 0x1f))) 232 return 1; 233 234 return 0; 235 } |
237
int
mhn_gpio_clear_edge_detect_status(int gpio_id) 238 { 239 unsigned long flags; 240 int gpio = MFP2GPIO(gpio_id); 241 242 GPIO_ID_VERIFY(gpio); 243 244 #if defined(CONFIG_MONAHANS_GPIOEX) 245 if (gpio >= GPIO_EXP_START) 246 return 0; 247 #endif 248 249 spin_lock_irqsave(&gpio_spin_lock, flags); 250 251 GEDR(gpio) = 1u << (gpio & 0x1f); 252 253 spin_unlock_irqrestore(&gpio_spin_lock, flags); 254 255 return 0; 256 } |
262
void
mhn_gpio_save(void) 263 { 264 gpio_saved_reg.gpdr0 = GPDR0; 265 gpio_saved_reg.gpdr1 = GPDR1; 266 gpio_saved_reg.gpdr2 = GPDR2; 267 gpio_saved_reg.gpdr3 = GPDR3; 268 269 gpio_saved_reg.gplr0 = GPLR0; 270 gpio_saved_reg.gplr1 = GPLR1; 271 gpio_saved_reg.gplr2 = GPLR2; 272 gpio_saved_reg.gplr3 = GPLR3; 273 274 gpio_saved_reg.grer0 = GRER0; 275 gpio_saved_reg.grer1 = GRER1; 276 gpio_saved_reg.grer2 = GRER2; 277 gpio_saved_reg.grer3 = GRER3; 278 279 gpio_saved_reg.gfer0 = GFER0; 280 gpio_saved_reg.gfer1 = GFER1; 281 gpio_saved_reg.gfer2 = GFER2; 282 gpio_saved_reg.gfer3 = GFER3; 283 } 284 285 void mhn_gpio_restore(void) 286 { 287 GPDR0 = gpio_saved_reg.gpdr0; 288 GPDR1 = gpio_saved_reg.gpdr1; 289 GPDR2 = gpio_saved_reg.gpdr2; 290 GPDR3 = gpio_saved_reg.gpdr3; 291 292 GPSR0 = gpio_saved_reg.gplr0; 293 GPSR1 = gpio_saved_reg.gplr1; 294 GPSR2 = gpio_saved_reg.gplr2; 295 GPSR3 = gpio_saved_reg.gplr3; 296 GPCR0 = ~(gpio_saved_reg.gplr0); 297 GPCR1 = ~(gpio_saved_reg.gplr1); 298 GPCR2 = ~(gpio_saved_reg.gplr2); 299 GPCR3 = ~(gpio_saved_reg.gplr3); 300 301 GRER0 = gpio_saved_reg.grer0; 302 GRER1 = gpio_saved_reg.grer1; 303 GRER2 = gpio_saved_reg.grer2; 304 GRER3 = gpio_saved_reg.grer3; 305 306 GFER0 = gpio_saved_reg.gfer0; 307 GFER1 = gpio_saved_reg.gfer1; 308 GFER2 = gpio_saved_reg.gfer2; 309 GFER3 = gpio_saved_reg.gfer3; 310 } |