paul@0 | 1 | /* |
paul@0 | 2 | * GPIO driver for Ingenic JZ4730. |
paul@0 | 3 | * (See below for additional copyright and licensing notices.) |
paul@0 | 4 | * |
paul@0 | 5 | * (c) 2017, 2018 Paul Boddie <paul@boddie.org.uk> |
paul@0 | 6 | * |
paul@0 | 7 | * This program is free software; you can redistribute it and/or |
paul@0 | 8 | * modify it under the terms of the GNU General Public License as |
paul@0 | 9 | * published by the Free Software Foundation; either version 2 of |
paul@0 | 10 | * the License, or (at your option) any later version. |
paul@0 | 11 | * |
paul@0 | 12 | * This program is distributed in the hope that it will be useful, |
paul@0 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@0 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@0 | 15 | * GNU General Public License for more details. |
paul@0 | 16 | * |
paul@0 | 17 | * You should have received a copy of the GNU General Public License |
paul@0 | 18 | * along with this program; if not, write to the Free Software |
paul@0 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@0 | 20 | * Boston, MA 02110-1301, USA |
paul@0 | 21 | * |
paul@0 | 22 | * |
paul@0 | 23 | * Subject to other copyrights, being derived from the bcm2835.cc and |
paul@0 | 24 | * omap.cc GPIO driver implementations. |
paul@0 | 25 | * |
paul@0 | 26 | * This file is part of TUD:OS and distributed under the terms of the |
paul@0 | 27 | * GNU General Public License 2. |
paul@0 | 28 | * Please see the COPYING-GPL-2 file for details. |
paul@0 | 29 | */ |
paul@0 | 30 | |
paul@0 | 31 | #include <l4/sys/icu.h> |
paul@0 | 32 | #include <l4/util/util.h> |
paul@0 | 33 | #include <l4/devices/hw_mmio_register_block.h> |
paul@0 | 34 | |
paul@0 | 35 | #include "gpio-jz4730.h" |
paul@0 | 36 | |
paul@0 | 37 | // GPIO register offsets (x in A..D). |
paul@0 | 38 | |
paul@0 | 39 | enum Regs |
paul@0 | 40 | { |
paul@0 | 41 | Port_data = 0x000, // PxGPDR |
paul@0 | 42 | Port_direction = 0x004, // PxGPDIR |
paul@0 | 43 | Pull_enable = 0x00c, // PxGPPUR |
paul@0 | 44 | Port_function_lower = 0x010, // PxGPALR |
paul@0 | 45 | Port_function_upper = 0x014, // PxGPAUR |
paul@0 | 46 | Irq_detect_lower = 0x018, // PxGPDLR |
paul@0 | 47 | Irq_detect_upper = 0x01c, // PxGPDUR |
paul@0 | 48 | Irq_enable = 0x020, // PxGPIER |
paul@0 | 49 | Irq_flag = 0x028, // PxGPFR |
paul@0 | 50 | }; |
paul@0 | 51 | |
paul@0 | 52 | |
paul@0 | 53 | |
paul@0 | 54 | // Select the appropriate register and pin where two bits are assigned per pin, |
paul@0 | 55 | // thus requiring two 32-bit registers to hold the configuration of 32 pins. |
paul@0 | 56 | |
paul@0 | 57 | static |
paul@0 | 58 | uint32_t |
paul@0 | 59 | _select_bank_for_pin(uint32_t reg_upper, uint32_t reg_lower, uint8_t pin, uint8_t *pin_out) |
paul@0 | 60 | { |
paul@0 | 61 | if (pin < 16) |
paul@0 | 62 | { |
paul@0 | 63 | *pin_out = pin; |
paul@0 | 64 | return reg_lower; |
paul@0 | 65 | } |
paul@0 | 66 | else |
paul@0 | 67 | { |
paul@0 | 68 | *pin_out = pin - 16; |
paul@0 | 69 | return reg_upper; |
paul@0 | 70 | } |
paul@0 | 71 | } |
paul@0 | 72 | |
paul@0 | 73 | |
paul@0 | 74 | |
paul@0 | 75 | // IRQ control for each GPIO pin. |
paul@0 | 76 | |
paul@0 | 77 | Gpio_jz4730_irq_pin::Gpio_jz4730_irq_pin(unsigned pin, Hw::Register_block<32> const ®s) |
paul@0 | 78 | : _pin(pin), _regs(regs) |
paul@0 | 79 | {} |
paul@0 | 80 | |
paul@0 | 81 | void |
paul@0 | 82 | Gpio_jz4730_irq_pin::write_reg_pin(unsigned reg) |
paul@0 | 83 | { |
paul@0 | 84 | // Write the pin bit to the register, setting or clearing the pin |
paul@0 | 85 | // depending on the register chosen. |
paul@0 | 86 | |
paul@0 | 87 | _regs[reg] = _pin_bit(_pin); |
paul@0 | 88 | } |
paul@0 | 89 | |
paul@0 | 90 | void |
paul@0 | 91 | Gpio_jz4730_irq_pin::clear_reg_pin(unsigned reg) |
paul@0 | 92 | { |
paul@0 | 93 | // Clear the pin bit in the register. |
paul@0 | 94 | |
paul@0 | 95 | _regs[reg] = _regs[reg] & ~(_pin_bit(_pin)); |
paul@0 | 96 | } |
paul@0 | 97 | |
paul@0 | 98 | void |
paul@0 | 99 | Gpio_jz4730_irq_pin::set_reg_pin(unsigned reg) |
paul@0 | 100 | { |
paul@0 | 101 | // Set the pin bit in the register. |
paul@0 | 102 | |
paul@0 | 103 | _regs[reg] = _regs[reg] | _pin_bit(_pin); |
paul@0 | 104 | } |
paul@0 | 105 | |
paul@0 | 106 | // Clear the pin bits in the appropriate register. |
paul@0 | 107 | |
paul@0 | 108 | void |
paul@0 | 109 | Gpio_jz4730_irq_pin::clear_reg_pins(uint32_t reg_upper, uint32_t reg_lower) |
paul@0 | 110 | { |
paul@0 | 111 | uint8_t pin_out; |
paul@0 | 112 | uint32_t reg = _select_bank_for_pin(reg_upper, reg_lower, _pin, &pin_out); |
paul@0 | 113 | |
paul@0 | 114 | _regs[reg] = _regs[reg] & ~(3 << (pin_out << 1)); |
paul@0 | 115 | } |
paul@0 | 116 | |
paul@0 | 117 | // Clear and set the given value in the pin bits of the appropriate register. |
paul@0 | 118 | |
paul@0 | 119 | void |
paul@0 | 120 | Gpio_jz4730_irq_pin::set_reg_pins(uint32_t reg_upper, uint32_t reg_lower, uint8_t value) |
paul@0 | 121 | { |
paul@0 | 122 | uint8_t pin_out; |
paul@0 | 123 | uint32_t reg = _select_bank_for_pin(reg_upper, reg_lower, _pin, &pin_out); |
paul@0 | 124 | |
paul@0 | 125 | _regs[reg] = (_regs[reg] & ~(3 << (pin_out << 1))) | (value << (pin_out << 1)); |
paul@0 | 126 | } |
paul@0 | 127 | |
paul@0 | 128 | void Gpio_jz4730_irq_pin::do_mask() |
paul@0 | 129 | { |
paul@0 | 130 | // Set the interrupt bit in the PxGPIER register. |
paul@0 | 131 | |
paul@0 | 132 | clear_reg_pin(Irq_enable); |
paul@0 | 133 | } |
paul@0 | 134 | |
paul@0 | 135 | void Gpio_jz4730_irq_pin::do_unmask() |
paul@0 | 136 | { |
paul@0 | 137 | // Set the interrupt bit in the PxGPIER register, first also clearing the |
paul@0 | 138 | // flag bit in the PxGPFR register to allow interrupts to be delivered. |
paul@0 | 139 | |
paul@0 | 140 | clear_reg_pin(Irq_flag); |
paul@0 | 141 | set_reg_pin(Irq_enable); |
paul@0 | 142 | } |
paul@0 | 143 | |
paul@0 | 144 | bool Gpio_jz4730_irq_pin::do_set_mode(unsigned mode) |
paul@0 | 145 | { |
paul@0 | 146 | // Standard comment found for this method: |
paul@0 | 147 | // this operation touches multiple mmio registers and is thus |
paul@0 | 148 | // not atomic, that's why we first mask the IRQ and if it was |
paul@0 | 149 | // enabled we unmask it after we have changed the mode |
paul@0 | 150 | |
paul@0 | 151 | if (enabled()) |
paul@0 | 152 | do_mask(); |
paul@0 | 153 | |
paul@0 | 154 | // Do the PxGPDUR/PxGPDLR configuration. |
paul@0 | 155 | |
paul@0 | 156 | switch(mode) |
paul@0 | 157 | { |
paul@0 | 158 | case L4_IRQ_F_LEVEL_HIGH: |
paul@0 | 159 | set_reg_pins(Irq_detect_upper, Irq_detect_lower, 1); |
paul@0 | 160 | break; |
paul@0 | 161 | case L4_IRQ_F_LEVEL_LOW: |
paul@0 | 162 | set_reg_pins(Irq_detect_upper, Irq_detect_lower, 0); |
paul@0 | 163 | break; |
paul@0 | 164 | case L4_IRQ_F_POS_EDGE: |
paul@0 | 165 | set_reg_pins(Irq_detect_upper, Irq_detect_lower, 3); |
paul@0 | 166 | break; |
paul@0 | 167 | case L4_IRQ_F_NEG_EDGE: |
paul@0 | 168 | set_reg_pins(Irq_detect_upper, Irq_detect_lower, 2); |
paul@0 | 169 | break; |
paul@0 | 170 | |
paul@0 | 171 | default: |
paul@0 | 172 | return false; |
paul@0 | 173 | } |
paul@0 | 174 | |
paul@0 | 175 | // Do the PxGPDIR, PxGPAUR/PxGPALR configuration. |
paul@0 | 176 | |
paul@0 | 177 | clear_reg_pin(Port_direction); |
paul@0 | 178 | clear_reg_pins(Port_function_upper, Port_function_lower); |
paul@0 | 179 | |
paul@0 | 180 | if (enabled()) |
paul@0 | 181 | do_unmask(); |
paul@0 | 182 | |
paul@0 | 183 | return true; |
paul@0 | 184 | } |
paul@0 | 185 | |
paul@0 | 186 | int Gpio_jz4730_irq_pin::clear() |
paul@0 | 187 | { |
paul@0 | 188 | // Obtain the flag status for the pin, clearing it if set. |
paul@0 | 189 | |
paul@0 | 190 | l4_uint32_t e = _regs[Irq_flag] & (1UL << _pin); |
paul@0 | 191 | if (e) |
paul@0 | 192 | clear_reg_pin(Irq_flag); |
paul@0 | 193 | |
paul@0 | 194 | return (e >> _pin); |
paul@0 | 195 | } |
paul@0 | 196 | |
paul@0 | 197 | bool Gpio_jz4730_irq_pin::enabled() |
paul@0 | 198 | { |
paul@0 | 199 | return true; |
paul@0 | 200 | } |
paul@0 | 201 | |
paul@0 | 202 | |
paul@0 | 203 | |
paul@0 | 204 | // Return two bitmaps for the given bitmap and value. |
paul@0 | 205 | |
paul@0 | 206 | static |
paul@0 | 207 | void |
paul@0 | 208 | _get_bitmaps(uint32_t bitmap, uint8_t value, uint32_t *upper, uint32_t *lower) |
paul@0 | 209 | { |
paul@0 | 210 | uint32_t mask = 0x80000000; |
paul@0 | 211 | |
paul@0 | 212 | *upper = 0; *lower = 0; |
paul@0 | 213 | |
paul@0 | 214 | while (mask != 0x8000) |
paul@0 | 215 | { |
paul@0 | 216 | *upper = (*upper << 2) | (bitmap & mask ? value : 0); |
paul@0 | 217 | mask >>= 1; |
paul@0 | 218 | } |
paul@0 | 219 | |
paul@0 | 220 | while (mask != 0) |
paul@0 | 221 | { |
paul@0 | 222 | *lower = (*lower << 2) | (bitmap & mask ? value : 0); |
paul@0 | 223 | mask >>= 1; |
paul@0 | 224 | } |
paul@0 | 225 | } |
paul@0 | 226 | |
paul@0 | 227 | |
paul@0 | 228 | |
paul@0 | 229 | // Initialise the GPIO controller. |
paul@0 | 230 | |
paul@0 | 231 | Gpio_jz4730_chip::Gpio_jz4730_chip(l4_addr_t start, l4_addr_t end, |
paul@0 | 232 | unsigned nr_pins) |
paul@0 | 233 | : _start(start), _end(end), |
paul@0 | 234 | _nr_pins(nr_pins) |
paul@0 | 235 | { |
paul@0 | 236 | _regs = new Hw::Mmio_register_block<32>(_start); |
paul@0 | 237 | } |
paul@0 | 238 | |
paul@0 | 239 | // Return the value of a pin. |
paul@0 | 240 | |
paul@0 | 241 | int |
paul@0 | 242 | Gpio_jz4730_chip::get(unsigned pin) |
paul@0 | 243 | { |
paul@0 | 244 | if (pin >= _nr_pins) |
paul@0 | 245 | throw -L4_EINVAL; |
paul@0 | 246 | |
paul@0 | 247 | l4_uint32_t val = _regs[Port_data]; |
paul@0 | 248 | return (val >> _pin_shift(pin)) & 1; |
paul@0 | 249 | } |
paul@0 | 250 | |
paul@0 | 251 | // Return multiple pin values. |
paul@0 | 252 | |
paul@0 | 253 | unsigned |
paul@0 | 254 | Gpio_jz4730_chip::multi_get(unsigned offset) |
paul@0 | 255 | { |
paul@0 | 256 | _reg_offset_check(offset); |
paul@0 | 257 | return _regs[Port_data]; |
paul@0 | 258 | } |
paul@0 | 259 | |
paul@0 | 260 | // Set the value of a pin. |
paul@0 | 261 | |
paul@0 | 262 | void |
paul@0 | 263 | Gpio_jz4730_chip::set(unsigned pin, int value) |
paul@0 | 264 | { |
paul@0 | 265 | if (pin >= _nr_pins) |
paul@0 | 266 | throw -L4_EINVAL; |
paul@0 | 267 | |
paul@0 | 268 | if (value) |
paul@0 | 269 | _regs[Port_data] = _regs[Port_data] | _pin_bit(pin); |
paul@0 | 270 | else |
paul@0 | 271 | _regs[Port_data] = _regs[Port_data] & ~_pin_bit(pin); |
paul@0 | 272 | } |
paul@0 | 273 | |
paul@0 | 274 | // Set multiple pin values. |
paul@0 | 275 | |
paul@0 | 276 | void |
paul@0 | 277 | Gpio_jz4730_chip::multi_set(Pin_slice const &mask, unsigned data) |
paul@0 | 278 | { |
paul@0 | 279 | _reg_offset_check(mask.offset); |
paul@0 | 280 | _regs[Port_data] = (_regs[Port_data] & ~(mask.mask)) | data; |
paul@0 | 281 | } |
paul@0 | 282 | |
paul@0 | 283 | // Set a pin up with the given mode and value (if appropriate). |
paul@0 | 284 | |
paul@0 | 285 | void |
paul@0 | 286 | Gpio_jz4730_chip::setup(unsigned pin, unsigned mode, int value) |
paul@0 | 287 | { |
paul@0 | 288 | if (pin >= _nr_pins) |
paul@0 | 289 | throw -L4_EINVAL; |
paul@0 | 290 | |
paul@0 | 291 | config(pin, mode); |
paul@0 | 292 | |
paul@0 | 293 | if (mode == Output) |
paul@0 | 294 | set(pin, value); |
paul@0 | 295 | } |
paul@0 | 296 | |
paul@0 | 297 | // Configuration of a pin using the generic input/output/IRQ mode. |
paul@0 | 298 | |
paul@0 | 299 | void |
paul@0 | 300 | Gpio_jz4730_chip::config(unsigned pin, unsigned mode) |
paul@0 | 301 | { |
paul@0 | 302 | _config(_pin_bit(pin), mode); |
paul@0 | 303 | } |
paul@0 | 304 | |
paul@0 | 305 | void |
paul@0 | 306 | Gpio_jz4730_chip::_config(unsigned bitmap, unsigned mode) |
paul@0 | 307 | { |
paul@0 | 308 | uint32_t upper_mask, lower_mask; |
paul@0 | 309 | unsigned bitmap_values = bitmap; |
paul@0 | 310 | |
paul@0 | 311 | switch (mode) |
paul@0 | 312 | { |
paul@0 | 313 | case Input: |
paul@0 | 314 | case Irq: |
paul@0 | 315 | // Clear the direction flags below. |
paul@0 | 316 | bitmap_values = 0; |
paul@0 | 317 | // Fall through to the next case to complete the operation. |
paul@0 | 318 | |
paul@0 | 319 | case Output: |
paul@0 | 320 | // Clear the flags if set immediately above; otherwise, set them. |
paul@0 | 321 | _regs[Port_direction] = (_regs[Port_direction] & ~bitmap) | bitmap_values; |
paul@0 | 322 | |
paul@0 | 323 | // Clear the port function for the bits. |
paul@0 | 324 | _get_bitmaps(bitmap, 3, &upper_mask, &lower_mask); |
paul@0 | 325 | _regs[Port_function_upper] = (_regs[Port_function_upper] & ~upper_mask); |
paul@0 | 326 | _regs[Port_function_lower] = (_regs[Port_function_lower] & ~lower_mask); |
paul@0 | 327 | break; |
paul@0 | 328 | |
paul@0 | 329 | default: |
paul@0 | 330 | break; |
paul@0 | 331 | } |
paul@0 | 332 | } |
paul@0 | 333 | |
paul@0 | 334 | // Pull-up configuration for a pin. |
paul@0 | 335 | |
paul@0 | 336 | void |
paul@0 | 337 | Gpio_jz4730_chip::config_pull(unsigned pin, unsigned mode) |
paul@0 | 338 | { |
paul@0 | 339 | if (pin >= _nr_pins) |
paul@0 | 340 | throw -L4_EINVAL; |
paul@0 | 341 | |
paul@0 | 342 | _config_pull(_pin_bit(pin), mode); |
paul@0 | 343 | } |
paul@0 | 344 | |
paul@0 | 345 | void |
paul@0 | 346 | Gpio_jz4730_chip::_config_pull(unsigned bitmap, unsigned mode) |
paul@0 | 347 | { |
paul@0 | 348 | switch (mode) |
paul@0 | 349 | { |
paul@0 | 350 | case Pull_none: |
paul@0 | 351 | _regs[Pull_enable] = _regs[Pull_enable] & ~bitmap; |
paul@0 | 352 | break; |
paul@0 | 353 | case Pull_up: |
paul@0 | 354 | _regs[Pull_enable] = _regs[Pull_enable] | bitmap; |
paul@0 | 355 | break; |
paul@0 | 356 | default: |
paul@0 | 357 | // Invalid pull-up/down mode for pin. |
paul@0 | 358 | throw -L4_EINVAL; |
paul@0 | 359 | } |
paul@0 | 360 | } |
paul@0 | 361 | |
paul@0 | 362 | // Pin function configuration. |
paul@0 | 363 | |
paul@0 | 364 | void |
paul@0 | 365 | Gpio_jz4730_chip::config_pad(unsigned pin, unsigned func, unsigned value) |
paul@0 | 366 | { |
paul@0 | 367 | if (pin >= _nr_pins) |
paul@0 | 368 | throw -L4_EINVAL; |
paul@0 | 369 | |
paul@0 | 370 | _config_pad(_pin_bit(pin), func, value); |
paul@0 | 371 | } |
paul@0 | 372 | |
paul@0 | 373 | void |
paul@0 | 374 | Gpio_jz4730_chip::_config_pad(unsigned bitmap, unsigned func, unsigned value) |
paul@0 | 375 | { |
paul@0 | 376 | uint32_t upper_mask = 0, lower_mask = 0, upper = 0, lower = 0; |
paul@0 | 377 | |
paul@0 | 378 | if (value > 3) |
paul@0 | 379 | throw -L4_EINVAL; |
paul@0 | 380 | |
paul@0 | 381 | switch (func) |
paul@0 | 382 | { |
paul@0 | 383 | case Hw::Gpio_chip::Function_alt: |
paul@0 | 384 | _get_bitmaps(bitmap, value, &upper, &lower); |
paul@0 | 385 | // Fall through to the next case to complete the operation. |
paul@0 | 386 | |
paul@0 | 387 | case Hw::Gpio_chip::Function_gpio: |
paul@0 | 388 | _get_bitmaps(bitmap, 3, &upper_mask, &lower_mask); |
paul@0 | 389 | _regs[Port_function_upper] = (_regs[Port_function_upper] & ~upper_mask) | upper; |
paul@0 | 390 | _regs[Port_function_lower] = (_regs[Port_function_lower] & ~lower_mask) | lower; |
paul@0 | 391 | break; |
paul@0 | 392 | |
paul@0 | 393 | default: |
paul@0 | 394 | throw -L4_EINVAL; |
paul@0 | 395 | } |
paul@0 | 396 | } |
paul@0 | 397 | |
paul@0 | 398 | // Obtain a pin's configuration from a register in the supplied value. |
paul@0 | 399 | |
paul@0 | 400 | void |
paul@0 | 401 | Gpio_jz4730_chip::config_get(unsigned pin, unsigned reg, unsigned *value) |
paul@0 | 402 | { |
paul@0 | 403 | if (pin >= _nr_pins) |
paul@0 | 404 | throw -L4_EINVAL; |
paul@0 | 405 | |
paul@0 | 406 | *value = (_regs[reg] >> _pin_shift(pin)) & 1; |
paul@0 | 407 | } |
paul@0 | 408 | |
paul@0 | 409 | // Obtain an IRQ abstraction for a pin. |
paul@0 | 410 | |
paul@0 | 411 | Hw::Gpio_irq_pin * |
paul@0 | 412 | Gpio_jz4730_chip::get_irq(unsigned pin) |
paul@0 | 413 | { |
paul@0 | 414 | if (pin >= _nr_pins) |
paul@0 | 415 | throw -L4_EINVAL; |
paul@0 | 416 | |
paul@0 | 417 | return new Gpio_jz4730_irq_pin(pin, _regs); |
paul@0 | 418 | } |
paul@0 | 419 | |
paul@0 | 420 | // Pull-up function configuration for multiple pins. |
paul@0 | 421 | |
paul@0 | 422 | void |
paul@0 | 423 | Gpio_jz4730_chip::multi_config_pull(Pin_slice const &mask, unsigned mode) |
paul@0 | 424 | { |
paul@0 | 425 | _config_pull(mask.mask << mask.offset, mode); |
paul@0 | 426 | } |
paul@0 | 427 | |
paul@0 | 428 | // Pin function configuration for multiple pins. |
paul@0 | 429 | |
paul@0 | 430 | void |
paul@0 | 431 | Gpio_jz4730_chip::multi_config_pad(Pin_slice const &mask, unsigned func, unsigned val) |
paul@0 | 432 | { |
paul@0 | 433 | _config_pad(mask.mask << mask.offset, func, val); |
paul@0 | 434 | } |
paul@0 | 435 | |
paul@0 | 436 | // Set up multiple pins with the given mode. |
paul@0 | 437 | |
paul@0 | 438 | void |
paul@0 | 439 | Gpio_jz4730_chip::multi_setup(Pin_slice const &mask, unsigned mode, unsigned outvalues) |
paul@0 | 440 | { |
paul@0 | 441 | _config(mask.mask << mask.offset, mode); |
paul@0 | 442 | |
paul@0 | 443 | if (mode == Output) |
paul@0 | 444 | multi_set(mask, outvalues); |
paul@0 | 445 | } |
paul@0 | 446 | |
paul@0 | 447 | |
paul@0 | 448 | |
paul@0 | 449 | // C language interface functions. |
paul@0 | 450 | |
paul@0 | 451 | void *jz4730_gpio_init(l4_addr_t start, l4_addr_t end, unsigned pins) |
paul@0 | 452 | { |
paul@0 | 453 | return (void *) new Gpio_jz4730_chip(start, end, pins); |
paul@0 | 454 | } |
paul@0 | 455 | |
paul@0 | 456 | void jz4730_gpio_setup(void *gpio, unsigned pin, unsigned mode, int value) |
paul@0 | 457 | { |
paul@0 | 458 | static_cast<Gpio_jz4730_chip *>(gpio)->setup(pin, mode, value); |
paul@0 | 459 | } |
paul@0 | 460 | |
paul@0 | 461 | void jz4730_gpio_config_pull(void *gpio, unsigned pin, unsigned mode) |
paul@0 | 462 | { |
paul@0 | 463 | static_cast<Gpio_jz4730_chip *>(gpio)->config_pull(pin, mode); |
paul@0 | 464 | } |
paul@0 | 465 | |
paul@0 | 466 | void jz4730_gpio_config_pad(void *gpio, unsigned pin, unsigned func, unsigned value) |
paul@0 | 467 | { |
paul@0 | 468 | static_cast<Gpio_jz4730_chip *>(gpio)->config_pad(pin, func, value); |
paul@0 | 469 | } |
paul@0 | 470 | |
paul@0 | 471 | void jz4730_gpio_config_get(void *gpio, unsigned pin, unsigned reg, unsigned *value) |
paul@0 | 472 | { |
paul@0 | 473 | static_cast<Gpio_jz4730_chip *>(gpio)->config_get(pin, reg, value); |
paul@0 | 474 | } |
paul@0 | 475 | |
paul@0 | 476 | void jz4730_gpio_multi_setup(void *gpio, Pin_slice const *mask, unsigned mode, unsigned outvalues) |
paul@0 | 477 | { |
paul@0 | 478 | static_cast<Gpio_jz4730_chip *>(gpio)->multi_setup(*mask, mode, outvalues); |
paul@0 | 479 | } |
paul@0 | 480 | |
paul@0 | 481 | void jz4730_gpio_multi_config_pull(void *gpio, Pin_slice const *mask, unsigned mode) |
paul@0 | 482 | { |
paul@0 | 483 | static_cast<Gpio_jz4730_chip *>(gpio)->multi_config_pull(*mask, mode); |
paul@0 | 484 | } |
paul@0 | 485 | |
paul@0 | 486 | void jz4730_gpio_multi_config_pad(void *gpio, Pin_slice const *mask, unsigned func, unsigned value) |
paul@0 | 487 | { |
paul@0 | 488 | static_cast<Gpio_jz4730_chip *>(gpio)->multi_config_pad(*mask, func, value); |
paul@0 | 489 | } |
paul@0 | 490 | |
paul@0 | 491 | void jz4730_gpio_multi_set(void *gpio, Pin_slice const *mask, unsigned data) |
paul@0 | 492 | { |
paul@0 | 493 | static_cast<Gpio_jz4730_chip *>(gpio)->multi_set(*mask, data); |
paul@0 | 494 | } |
paul@0 | 495 | |
paul@0 | 496 | unsigned jz4730_gpio_multi_get(void *gpio, unsigned offset) |
paul@0 | 497 | { |
paul@0 | 498 | return static_cast<Gpio_jz4730_chip *>(gpio)->multi_get(offset); |
paul@0 | 499 | } |
paul@0 | 500 | |
paul@0 | 501 | int jz4730_gpio_get(void *gpio, unsigned pin) |
paul@0 | 502 | { |
paul@0 | 503 | return static_cast<Gpio_jz4730_chip *>(gpio)->get(pin); |
paul@0 | 504 | } |
paul@0 | 505 | |
paul@0 | 506 | void jz4730_gpio_set(void *gpio, unsigned pin, int value) |
paul@0 | 507 | { |
paul@0 | 508 | static_cast<Gpio_jz4730_chip *>(gpio)->set(pin, value); |
paul@0 | 509 | } |
paul@0 | 510 | |
paul@0 | 511 | void *jz4730_gpio_get_irq(void *gpio, unsigned pin) |
paul@0 | 512 | { |
paul@0 | 513 | return (void *) static_cast<Gpio_jz4730_chip *>(gpio)->get_irq(pin); |
paul@0 | 514 | } |
paul@0 | 515 | |
paul@0 | 516 | bool jz4730_gpio_irq_set_mode(void *gpio_irq, unsigned mode) |
paul@0 | 517 | { |
paul@0 | 518 | return static_cast<Hw::Gpio_irq_pin *>(gpio_irq)->do_set_mode(mode); |
paul@0 | 519 | } |