int __init bcm63xx_gpio_init(void) { gpio_out_low = bcm_gpio_readl(GPIO_DATA_LO_REG); gpio_out_high = bcm_gpio_readl(GPIO_DATA_HI_REG); bcm63xx_gpio_chip.ngpio = bcm63xx_gpio_count(); pr_info("registering %d GPIOs\n", bcm63xx_gpio_chip.ngpio); return gpiochip_add(&bcm63xx_gpio_chip); }
int __init bcm63xx_gpio_init(void) { bcm63xx_gpio_out_low_reg_init(); gpio_out_low = bcm_gpio_readl(gpio_out_low_reg); if (!BCMCPU_IS_6345()) gpio_out_high = bcm_gpio_readl(GPIO_DATA_HI_REG); bcm63xx_gpio_chip.ngpio = bcm63xx_gpio_count(); pr_info("registering %d GPIOs\n", bcm63xx_gpio_chip.ngpio); return gpiochip_add(&bcm63xx_gpio_chip); }
static int bcm63xx_gpio_set_direction(struct gpio_chip *chip, unsigned gpio, int dir) { u32 reg; u32 mask; u32 tmp; unsigned long flags; if (gpio >= chip->ngpio) BUG(); if (gpio < 32) { reg = GPIO_CTL_LO_REG; mask = 1 << gpio; } else { reg = GPIO_CTL_HI_REG; mask = 1 << (gpio - 32); } spin_lock_irqsave(&bcm63xx_gpio_lock, flags); tmp = bcm_gpio_readl(reg); if (dir == BCM63XX_GPIO_DIR_IN) tmp &= ~mask; else tmp |= mask; bcm_gpio_writel(tmp, reg); spin_unlock_irqrestore(&bcm63xx_gpio_lock, flags); return 0; }
static int __init bcm63xx_detect_flash_type(void) { u32 val; switch (bcm63xx_get_cpu_id()) { case BCM6328_CPU_ID: val = bcm_misc_readl(MISC_STRAPBUS_6328_REG); if (val & STRAPBUS_6328_BOOT_SEL_SERIAL) return BCM63XX_FLASH_TYPE_SERIAL; else return BCM63XX_FLASH_TYPE_NAND; case BCM6338_CPU_ID: case BCM6345_CPU_ID: case BCM6348_CPU_ID: /* no way to auto detect so assume parallel */ return BCM63XX_FLASH_TYPE_PARALLEL; case BCM3368_CPU_ID: case BCM6358_CPU_ID: val = bcm_gpio_readl(GPIO_STRAPBUS_REG); if (val & STRAPBUS_6358_BOOT_SEL_PARALLEL) return BCM63XX_FLASH_TYPE_PARALLEL; else return BCM63XX_FLASH_TYPE_SERIAL; case BCM6362_CPU_ID: val = bcm_misc_readl(MISC_STRAPBUS_6362_REG); if (val & STRAPBUS_6362_BOOT_SEL_SERIAL) return BCM63XX_FLASH_TYPE_SERIAL; else return BCM63XX_FLASH_TYPE_NAND; case BCM6368_CPU_ID: val = bcm_gpio_readl(GPIO_STRAPBUS_REG); switch (val & STRAPBUS_6368_BOOT_SEL_MASK) { case STRAPBUS_6368_BOOT_SEL_NAND: return BCM63XX_FLASH_TYPE_NAND; case STRAPBUS_6368_BOOT_SEL_SERIAL: return BCM63XX_FLASH_TYPE_SERIAL; case STRAPBUS_6368_BOOT_SEL_PARALLEL: return BCM63XX_FLASH_TYPE_PARALLEL; } default: return -EINVAL; } }
static void bcm_mpi_enable_extra_CSs(u16 cs) { /* Code adapted from http://pastebin.com/g0bQGPRj */ if (BCMCPU_IS_6358()) { if (cs >= 2) { /* BCM6358 */ u32 val; /* Enable Overlay for SPI SS Pins */ val = bcm_gpio_readl(GPIO_MODE_REG); val |= GPIO_MODE_6358_EXTRA_SPI_SS; bcm_gpio_writel(val, GPIO_MODE_REG); /* Enable SPI Slave Select as Output Pins */ /* GPIO 32 is SS2, GPIO 33 is SS3 */ val = bcm_gpio_readl(GPIO_CTL_HI_REG); val |= 0x0003; bcm_gpio_writel(val, GPIO_CTL_HI_REG); } } if (BCMCPU_IS_6368()) { if (cs >= 2) { /* BCM6368 */ u32 val; /* Enable Extra SPI CS */ val = bcm_gpio_readl(GPIO_MODE_REG); val |= (GPIO_MODE_6368_SPI_SSN2 << (cs - 2)); bcm_gpio_writel(val, GPIO_MODE_REG); /* Enable SPI Slave Select as Output Pins */ /* GPIO 28 is SS2, GPIO 29 is SS3, GPIO 30 is SS4, GPIO 31 is SS5*/ val = bcm_gpio_readl(GPIO_CTL_LO_REG); val |= (GPIO_MODE_6368_SPI_SSN2 << (cs - 2)); bcm_gpio_writel(val, GPIO_CTL_LO_REG); } } }
static int bcm63xx_gpio_get(struct gpio_chip *chip, unsigned gpio) { u32 reg; u32 mask; if (gpio >= chip->ngpio) BUG(); if (gpio < 32) { reg = GPIO_DATA_LO_REG; mask = 1 << gpio; } else { reg = GPIO_DATA_HI_REG; mask = 1 << (gpio - 32); } return !!(bcm_gpio_readl(reg) & mask); }