GpioCfg *new_braswell_gpio_input(int community, int offset) { GpioCfg *gpio = xzalloc(sizeof(GpioCfg)); uintptr_t reg_addr; reg_addr = COMMUNITY_BASE(community); reg_addr += GPIO_OFFSET(offset); gpio->addr = (uint32_t *)reg_addr; gpio->ops.get = &braswell_get_gpio; return gpio; }
int gpio_set_cfgpin(unsigned int pin, unsigned int val) { unsigned int gpio_num = GPIO_NUM(pin); #if defined(RK3188) unsigned int bank = GPIO_BANK(gpio_num); unsigned int offset = GPIO_OFFSET(gpio_num); #elif defined(AM3352) unsigned int bank = GPIO_BANK(pin); unsigned long offset = 1 << gpio_num; #endif debug("PIN: %d\n", pin); debug("GPIO_NUM: %d\n", gpio_num); debug("GPIO_BANK: %d\n", bank); debug("OFFSET: 0x%08lx\n", offset); if (gpio[bank].gpio_pio_base == 0) { return -1; } struct gpio_reg *pio = ((struct gpio_reg *) gpio[bank].gpio_pio_base); debug("GPIO_OE: 0x%08lx\n", pio->gpio_oe); if (val == GPIO_INPUT) { #if defined(RK3188) pio->gpio_swport_ddr &= ~offset; #elif defined(AM3352) pio->gpio_oe |= offset; #endif } else { #if defined(RK3188) pio->gpio_swport_ddr |= offset; #elif defined(AM3352) pio->gpio_oe &= ~offset; #endif } debug("GPIO_OE: 0x%08lx\n", pio->gpio_oe); return 0; }
int gpio_get_cfgpin(unsigned int pin) { unsigned int gpio_num = GPIO_NUM(pin); #if defined(RK3188) unsigned int bank = GPIO_BANK(gpio_num); unsigned int offset = GPIO_OFFSET(gpio_num); #elif defined(AM3352) unsigned int bank = GPIO_BANK(pin); unsigned int offset = 1 << gpio_num; #endif if (gpio[bank].gpio_pio_base == 0) { return -1; } struct gpio_reg *pio = ((struct gpio_reg *) gpio[bank].gpio_pio_base); #if defined(RK3188) return !!(pio->gpio_swport_ddr & offset); #elif defined(AM3352) return !!(pio->gpio_oe & offset); #endif }
int gpio_input(unsigned int pin) { unsigned int gpio_num = GPIO_NUM(pin); #if defined(RK3188) unsigned int bank = GPIO_BANK(gpio_num); unsigned int offset = GPIO_OFFSET(gpio_num); #elif defined(AM3352) unsigned int bank = GPIO_BANK(pin); unsigned int offset = 1 << gpio_num; #endif if (gpio[bank].gpio_pio_base == 0) { return -1; } struct gpio_reg *pio = ((struct gpio_reg *) gpio[bank].gpio_pio_base); #if defined(RK3188) return !!(pio->gpio_ext_port & offset); #elif defined(AM3352) return !!(pio->gpio_datain & offset); #endif }
int gpio_output(unsigned int pin, unsigned int val) { unsigned int gpio_num = GPIO_NUM(pin); #if defined(RK3188) unsigned int bank = GPIO_BANK(gpio_num); unsigned int offset = GPIO_OFFSET(gpio_num); #elif defined(AM3352) unsigned int bank = GPIO_BANK(pin); unsigned int offset = 1 << gpio_num; #endif if (gpio[bank].gpio_pio_base == 0) { return -1; } struct gpio_reg *pio = ((struct gpio_reg *) gpio[bank].gpio_pio_base); debug("GPIO_DATAOUT: 0x%08lx\n", pio->gpio_dataout); if (!val) { #if defined(RK3188) pio->gpio_swport_dr &= ~offset; #elif defined(AM3352) pio->gpio_cleardataout = offset; #endif } else { #if defined(RK3188) pio->gpio_swport_dr |= offset; #elif defined(AM3352) pio->gpio_setdataout = offset; #endif debug("GPIO_SWPORT_DR: 0x%08lx\n", pio->gpio_dataout); } return 0; }