omegamoon/rockchip-rk3188-generic — pull request #1 by Galland (2013-06-16 19:17:13+00:00)
Title: Bugfix in sram_gpio_init for rk30 devices (affects board-pmu-tps65910.c and any other that used a pin in RK30_PIN6_*)

sram_gpio_init is called from mach-rk30/board-pmu-tps65910.c with
PMU_POWER_SLEEP (RK30_PIN6_PB1) as first argument. The return is -EINVAL
even though it's a valid pin.

This is caused, in rk3066, by the bad way in which sram_gpio_init checks
against the gpio_base array, taking into account that for RK3066 this
array is missing one element (RK30_GPIO5_BASE, which is ok). This makes
it give wrong results for any pin on GPIO6_BASE, because of this
comparison:
if(index/NUM_GROUP >= ARRAY_SIZE(gpio_base))

For example:
PMU_POWER_SLEEP = RK30_PIN6_PB1 = 361

Taking the previous line's index calc: index = gpio - PIN_BASE;
Knowing that:
- #define PIN_BASE NR_GIC_IRQS
- #define NR_GIC_IRQS (5 * 32)

index = gpio - PIN_BASE = 361 - 5*32 = 201

and then in the if we have:
- index/NUM_GROUP = 201 / 32 = 6.2 ... = 6
- ARRAY_SIZE(gpio_base) = 6

which is == to ARRAY_SIZE so RK30_PIN6_* fail here
due to using array_size without a RK30_GPIO5_BASE

Solution entails failing on pins in GPIO5_BASE, but allowing them in
GPIO6, and then pressing the right base into data->base by using index 5
for GPIO6, as expected.