The GPIO banks are broken up into two 16-bit registers for each
bank set. Unfortunately, the math that determines how to shift
blindly shifted by the number of the gpio. This worked for gpio
numbers under 32, but higher gpio's are broken. This fixes the
gpio index, so the bank is passed and the shift amount within
the register is passed now instead of the gpio number.
Fixes:
8e51c0f25406("dm: gpio: Add DM compatibility to
GPIO driver for Davinci")
Signed-off-by: Adam Ford <aford173@gmail.com>
#include <asm/gpio.h>
#include <asm/arch/hardware.h>
#include <asm/arch/davinci_misc.h>
#include <asm/gpio.h>
#include <asm/arch/hardware.h>
#include <asm/arch/davinci_misc.h>
+#include <dt-bindings/gpio/gpio.h>
#ifndef CONFIG_DM_GPIO
static struct gpio_registry {
#ifndef CONFIG_DM_GPIO
static struct gpio_registry {
static struct davinci_gpio *davinci_get_gpio_bank(struct udevice *dev, unsigned int offset)
{
struct davinci_gpio_bank *bank = dev_get_priv(dev);
static struct davinci_gpio *davinci_get_gpio_bank(struct udevice *dev, unsigned int offset)
{
struct davinci_gpio_bank *bank = dev_get_priv(dev);
- /* The device tree is not broken into banks but the infrastructure is
+ /*
+ * The device tree is not broken into banks but the infrastructure is
* expecting it this way, so we'll first include the 0x10 offset, then
* calculate the bank manually based on the offset.
* expecting it this way, so we'll first include the 0x10 offset, then
* calculate the bank manually based on the offset.
+ * Casting 'addr' as Unsigned long is needed to make the math work.
-
- return ((struct davinci_gpio *)bank->base) + 0x10 + (offset >> 5);
+ addr = ((unsigned long)(struct davinci_gpio *)bank->base) +
+ 0x10 + (0x28 * (offset >> 5));
+ return (struct davinci_gpio *)addr;
}
static int davinci_gpio_direction_input(struct udevice *dev, unsigned int offset)
{
struct davinci_gpio *base = davinci_get_gpio_bank(dev, offset);
}
static int davinci_gpio_direction_input(struct udevice *dev, unsigned int offset)
{
struct davinci_gpio *base = davinci_get_gpio_bank(dev, offset);
- _gpio_direction_input(base, offset);
+ /*
+ * Fetch the address based on GPIO, but only pass the masked low 32-bits
+ */
+ _gpio_direction_input(base, (offset & 0x1f));
{
struct davinci_gpio *base = davinci_get_gpio_bank(dev, offset);
{
struct davinci_gpio *base = davinci_get_gpio_bank(dev, offset);
- _gpio_direction_output(base, offset, value);
+ _gpio_direction_output(base, (offset & 0x1f), value);
{
struct davinci_gpio *base = davinci_get_gpio_bank(dev, offset);
{
struct davinci_gpio *base = davinci_get_gpio_bank(dev, offset);
- return _gpio_get_value(base, offset);
+ return _gpio_get_value(base, (offset & 0x1f));
}
static int davinci_gpio_set_value(struct udevice *dev, unsigned int offset,
}
static int davinci_gpio_set_value(struct udevice *dev, unsigned int offset,
{
struct davinci_gpio *base = davinci_get_gpio_bank(dev, offset);
{
struct davinci_gpio *base = davinci_get_gpio_bank(dev, offset);
- _gpio_set_value(base, offset, value);
+ _gpio_set_value(base, (offset & 0x1f), value);