I spotted likely another error in the same file (debounce bit setting in tegra_gpio_set_debounce()), so I consolidated the fixes below in addition to snarky’s suggestion:
diff --git a/Linux_for_Tegra/sources/kernel/t18x/drivers/gpio/gpio-tegra186.c b/Linux_for_Tegra/sources/kernel/t18x/drivers/gpio/gpio-tegra186.c
index f4a714555..2002e4cee 100644
--- a/Linux_for_Tegra/sources/kernel/t18x/drivers/gpio/gpio-tegra186.c
+++ b/Linux_for_Tegra/sources/kernel/t18x/drivers/gpio/gpio-tegra186.c
@@ -387,7 +387,7 @@ static int tegra186_gpio_to_wake(struct tegra_gpio_info *tgi, int gpio)
if (tgi->soc->wake_table[i] == gpio) {
pr_info("gpio %s wake%d for gpio=%d(%s:%d)\n",
tgi->soc->name, i, gpio,
- tgi->soc->port[GPIO_PORT(gpio)].port_name, gpio % 7);
+ tgi->soc->port[GPIO_PORT(gpio)].port_name, GPIO_PIN(gpio));
return i;
}
}
@@ -454,12 +454,12 @@ static inline bool gpio_is_accessible(struct tegra_gpio_info *tgi, u32 offset)
static void tegra_gpio_enable(struct tegra_gpio_info *tgi, int gpio)
{
- tegra_gpio_update(tgi, gpio, GPIO_ENB_CONFIG_REG, 0x1, 0x1);
+ tegra_gpio_update(tgi, gpio, GPIO_ENB_CONFIG_REG, GPIO_ENB_BIT, GPIO_ENB_BIT);
}
static void tegra_gpio_disable(struct tegra_gpio_info *tgi, int gpio)
{
- tegra_gpio_update(tgi, gpio, GPIO_ENB_CONFIG_REG, 0x1, 0x0);
+ tegra_gpio_update(tgi, gpio, GPIO_ENB_CONFIG_REG, GPIO_ENB_BIT, 0x0);
}
static int tegra_gpio_request(struct gpio_chip *chip, unsigned offset)
@@ -505,14 +505,8 @@ static void set_gpio_direction_mode(struct gpio_chip *chip, u32 offset,
bool mode)
{
struct tegra_gpio_info *tgi = gpiochip_get_data(chip);
- u32 val;
- val = tegra_gpio_readl(tgi, offset, GPIO_ENB_CONFIG_REG);
- if (mode)
- val |= GPIO_INOUT_BIT;
- else
- val &= ~GPIO_INOUT_BIT;
- tegra_gpio_writel(tgi, val, offset, GPIO_ENB_CONFIG_REG);
+ tegra_gpio_update(tgi, offset, GPIO_ENB_CONFIG_REG, GPIO_INOUT_BIT, mode ? GPIO_INOUT_BIT : 0);
}
static int tegra_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
@@ -551,8 +545,7 @@ static int tegra_gpio_set_debounce(struct gpio_chip *chip, unsigned offset,
struct tegra_gpio_info *tgi = gpiochip_get_data(chip);
unsigned dbc_ms = DIV_ROUND_UP(debounce, 1000);
- tegra_gpio_update(tgi, offset, GPIO_ENB_CONFIG_REG, 0x1, 0x1);
- tegra_gpio_update(tgi, offset, GPIO_DEB_FUNC_BIT, 0x5, 0x1);
+ tegra_gpio_update(tgi, offset, GPIO_ENB_CONFIG_REG, GPIO_ENB_BIT | GPIO_DEB_FUNC_BIT, GPIO_ENB_BIT);
/* Update debounce threshold */
tegra_gpio_writel(tgi, dbc_ms, offset, GPIO_DBC_THRES_REG);
@@ -565,11 +558,11 @@ static int tegra_gpio_is_enabled(struct gpio_chip *chip, unsigned offset)
u32 val;
if (!gpio_is_accessible(tgi, offset))
- return 0;
+ return -EBUSY;
val = tegra_gpio_readl(tgi, offset, GPIO_ENB_CONFIG_REG);
- return !!(val & 0x1);
+ return !!(val & GPIO_ENB_BIT);
}
static int tegra_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
@@ -578,11 +571,11 @@ static int tegra_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
u32 val;
if (!gpio_is_accessible(tgi, offset))
- return 0;
+ return -EBUSY;
- val = tegra_gpio_readl(tgi, offset, GPIO_OUT_CTRL_REG);
+ val = tegra_gpio_readl(tgi, offset, GPIO_ENB_CONFIG_REG);
- return (val & 0x1);
+ return !(val & GPIO_INOUT_BIT);
}
static int tegra_gpio_to_irq(struct gpio_chip *chip, unsigned offset)