Skip to content

Commit

Permalink
gpio: tegra: Hide tegra_gpio_enable/disable()
Browse files Browse the repository at this point in the history
Recent pinctrl discussions concluded that gpiolib APIs should in fact do
whatever is required to mux a GPIO onto pins, by calling pinctrl APIs if
required. This change implements this for the Tegra GPIO driver, and removes
calls to the Tegra-specific APIs from drivers and board files.

Cc: Chris Ball <cjb@laptop.org>
Cc: linux-mmc@vger.kernel.org
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Chris Ball <cjb@laptop.org> # for sdhci-tegra.c
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Olof Johansson <olof@lixom.net>
  • Loading branch information
Stephen Warren committed Apr 18, 2012
1 parent c61b3da commit 3e215d0
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 158 deletions.
1 change: 0 additions & 1 deletion arch/arm/mach-tegra/board-dt-tegra20.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ void ventana_pinmux_init(void);

struct of_dev_auxdata tegra20_auxdata_lookup[] __initdata = {
OF_DEV_AUXDATA("nvidia,tegra20-pinmux", TEGRA_APB_MISC_BASE + 0x14, "tegra-pinmux", NULL),
OF_DEV_AUXDATA("nvidia,tegra20-gpio", TEGRA_GPIO_BASE, "tegra-gpio", NULL),
OF_DEV_AUXDATA("nvidia,tegra20-sdhci", TEGRA_SDMMC1_BASE, "sdhci-tegra.0", NULL),
OF_DEV_AUXDATA("nvidia,tegra20-sdhci", TEGRA_SDMMC2_BASE, "sdhci-tegra.1", NULL),
OF_DEV_AUXDATA("nvidia,tegra20-sdhci", TEGRA_SDMMC3_BASE, "sdhci-tegra.2", NULL),
Expand Down
17 changes: 0 additions & 17 deletions arch/arm/mach-tegra/board-harmony-pinmux.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
*/

#include <linux/kernel.h>
#include <linux/gpio.h>
#include <linux/of.h>

#include <mach/pinmux.h>
#include <mach/pinmux-tegra20.h>

#include "gpio-names.h"
#include "board-harmony.h"
#include "board-pinmux.h"

Expand Down Expand Up @@ -144,24 +142,9 @@ static struct tegra_pingroup_config harmony_pinmux[] = {
{TEGRA_PINGROUP_XM2D, TEGRA_MUX_NONE, TEGRA_PUPD_NORMAL, TEGRA_TRI_NORMAL},
};

static struct tegra_gpio_table gpio_table[] = {
{ .gpio = TEGRA_GPIO_SD2_CD, .enable = true },
{ .gpio = TEGRA_GPIO_SD2_WP, .enable = true },
{ .gpio = TEGRA_GPIO_SD2_POWER, .enable = true },
{ .gpio = TEGRA_GPIO_SD4_CD, .enable = true },
{ .gpio = TEGRA_GPIO_SD4_WP, .enable = true },
{ .gpio = TEGRA_GPIO_SD4_POWER, .enable = true },
{ .gpio = TEGRA_GPIO_CDC_IRQ, .enable = true },
{ .gpio = TEGRA_GPIO_HP_DET, .enable = true },
{ .gpio = TEGRA_GPIO_INT_MIC_EN, .enable = true },
{ .gpio = TEGRA_GPIO_EXT_MIC_EN, .enable = true },
};

static struct tegra_board_pinmux_conf conf = {
.pgs = harmony_pinmux,
.pg_count = ARRAY_SIZE(harmony_pinmux),
.gpios = gpio_table,
.gpio_count = ARRAY_SIZE(gpio_table),
};

void harmony_pinmux_init(void)
Expand Down
14 changes: 0 additions & 14 deletions arch/arm/mach-tegra/board-paz00-pinmux.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
*/

#include <linux/kernel.h>
#include <linux/gpio.h>
#include <linux/of.h>

#include <mach/pinmux.h>
#include <mach/pinmux-tegra20.h>

#include "gpio-names.h"
#include "board-paz00.h"
#include "board-pinmux.h"

Expand Down Expand Up @@ -144,21 +142,9 @@ static struct tegra_pingroup_config paz00_pinmux[] = {
{TEGRA_PINGROUP_XM2D, TEGRA_MUX_NONE, TEGRA_PUPD_NORMAL, TEGRA_TRI_NORMAL},
};

static struct tegra_gpio_table gpio_table[] = {
{ .gpio = TEGRA_GPIO_SD1_CD, .enable = true },
{ .gpio = TEGRA_GPIO_SD1_WP, .enable = true },
{ .gpio = TEGRA_GPIO_SD1_POWER, .enable = true },
{ .gpio = TEGRA_ULPI_RST, .enable = true },
{ .gpio = TEGRA_WIFI_PWRN, .enable = true },
{ .gpio = TEGRA_WIFI_RST, .enable = true },
{ .gpio = TEGRA_WIFI_LED, .enable = true },
};

static struct tegra_board_pinmux_conf conf = {
.pgs = paz00_pinmux,
.pg_count = ARRAY_SIZE(paz00_pinmux),
.gpios = gpio_table,
.gpio_count = ARRAY_SIZE(gpio_table),
};

void paz00_pinmux_init(void)
Expand Down
33 changes: 4 additions & 29 deletions arch/arm/mach-tegra/board-pinmux.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,13 @@
#include <linux/of.h>
#include <linux/string.h>

#include <mach/gpio-tegra.h>
#include <mach/pinmux.h>

#include "board-pinmux.h"
#include "devices.h"

struct tegra_board_pinmux_conf *confs[2];

static void tegra_board_pinmux_setup_gpios(void)
{
int i;

for (i = 0; i < ARRAY_SIZE(confs); i++) {
if (!confs[i])
continue;

tegra_gpio_config(confs[i]->gpios, confs[i]->gpio_count);
}
}

static void tegra_board_pinmux_setup_pinmux(void)
{
int i;
Expand All @@ -57,29 +44,17 @@ static void tegra_board_pinmux_setup_pinmux(void)
static int tegra_board_pinmux_bus_notify(struct notifier_block *nb,
unsigned long event, void *vdev)
{
static bool had_gpio;
static bool had_pinmux;

struct device *dev = vdev;
const char *devname;

if (event != BUS_NOTIFY_BOUND_DRIVER)
return NOTIFY_DONE;

devname = dev_name(dev);
if (strcmp(dev_name(dev), PINMUX_DEV))
return NOTIFY_DONE;

if (!had_gpio && !strcmp(devname, GPIO_DEV)) {
tegra_board_pinmux_setup_gpios();
had_gpio = true;
} else if (!had_pinmux && !strcmp(devname, PINMUX_DEV)) {
tegra_board_pinmux_setup_pinmux();
had_pinmux = true;
}
tegra_board_pinmux_setup_pinmux();

if (had_gpio && had_pinmux)
return NOTIFY_STOP_MASK;
else
return NOTIFY_DONE;
return NOTIFY_STOP_MASK;
}

static struct notifier_block nb = {
Expand Down
5 changes: 0 additions & 5 deletions arch/arm/mach-tegra/board-pinmux.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,16 @@
#ifndef __MACH_TEGRA_BOARD_PINMUX_H
#define __MACH_TEGRA_BOARD_PINMUX_H

#define GPIO_DEV "tegra-gpio"
#define PINMUX_DEV "tegra-pinmux"

struct tegra_pingroup_config;
struct tegra_gpio_table;

struct tegra_board_pinmux_conf {
struct tegra_pingroup_config *pgs;
int pg_count;

struct tegra_drive_pingroup_config *drives;
int drive_count;

struct tegra_gpio_table *gpios;
int gpio_count;
};

void tegra_board_pinmux_init(struct tegra_board_pinmux_conf *conf_a,
Expand Down
32 changes: 0 additions & 32 deletions arch/arm/mach-tegra/board-seaboard-pinmux.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/gpio.h>
#include <linux/of.h>

#include <mach/pinmux.h>
#include <mach/pinmux-tegra20.h>

#include "gpio-names.h"
#include "board-pinmux.h"
#include "board-seaboard.h"

Expand Down Expand Up @@ -179,51 +177,21 @@ static struct tegra_pingroup_config ventana_pinmux[] = {
{TEGRA_PINGROUP_SPIG, TEGRA_MUX_SPI2_ALT, TEGRA_PUPD_NORMAL, TEGRA_TRI_TRISTATE},
};

static struct tegra_gpio_table common_gpio_table[] = {
{ .gpio = TEGRA_GPIO_SD2_CD, .enable = true },
{ .gpio = TEGRA_GPIO_SD2_WP, .enable = true },
{ .gpio = TEGRA_GPIO_SD2_POWER, .enable = true },
{ .gpio = TEGRA_GPIO_CDC_IRQ, .enable = true },
};

static struct tegra_gpio_table seaboard_gpio_table[] = {
{ .gpio = TEGRA_GPIO_LIDSWITCH, .enable = true },
{ .gpio = TEGRA_GPIO_POWERKEY, .enable = true },
{ .gpio = TEGRA_GPIO_HP_DET, .enable = true },
{ .gpio = TEGRA_GPIO_ISL29018_IRQ, .enable = true },
{ .gpio = TEGRA_GPIO_USB1, .enable = true },
};

static struct tegra_gpio_table ventana_gpio_table[] = {
/* hp_det */
{ .gpio = TEGRA_GPIO_PW2, .enable = true },
/* int_mic_en */
{ .gpio = TEGRA_GPIO_PX0, .enable = true },
/* ext_mic_en */
{ .gpio = TEGRA_GPIO_PX1, .enable = true },
};

static struct tegra_board_pinmux_conf common_conf = {
.pgs = common_pinmux,
.pg_count = ARRAY_SIZE(common_pinmux),
.gpios = common_gpio_table,
.gpio_count = ARRAY_SIZE(common_gpio_table),
};

static struct tegra_board_pinmux_conf seaboard_conf = {
.pgs = seaboard_pinmux,
.pg_count = ARRAY_SIZE(seaboard_pinmux),
.drives = seaboard_drive_pinmux,
.drive_count = ARRAY_SIZE(seaboard_drive_pinmux),
.gpios = seaboard_gpio_table,
.gpio_count = ARRAY_SIZE(seaboard_gpio_table),
};

static struct tegra_board_pinmux_conf ventana_conf = {
.pgs = ventana_pinmux,
.pg_count = ARRAY_SIZE(ventana_pinmux),
.gpios = ventana_gpio_table,
.gpio_count = ARRAY_SIZE(ventana_gpio_table),
};

void seaboard_pinmux_init(void)
Expand Down
1 change: 0 additions & 1 deletion arch/arm/mach-tegra/board-seaboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ static void __init tegra_kaen_init(void)
debug_uart_platform_data[0].irq = INT_UARTB;

seaboard_audio_pdata.gpio_hp_mute = TEGRA_GPIO_KAEN_HP_MUTE;
tegra_gpio_enable(TEGRA_GPIO_KAEN_HP_MUTE);

seaboard_common_init();

Expand Down
12 changes: 0 additions & 12 deletions arch/arm/mach-tegra/board-trimslice-pinmux.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@
* GNU General Public License for more details.
*
*/
#include <linux/gpio.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/of.h>

#include <mach/pinmux.h>
#include <mach/pinmux-tegra20.h>

#include "gpio-names.h"
#include "board-pinmux.h"
#include "board-trimslice.h"

Expand Down Expand Up @@ -144,19 +142,9 @@ static struct tegra_pingroup_config trimslice_pinmux[] = {
{TEGRA_PINGROUP_XM2D, TEGRA_MUX_NONE, TEGRA_PUPD_NORMAL, TEGRA_TRI_NORMAL},
};

static struct tegra_gpio_table gpio_table[] = {
{ .gpio = TRIMSLICE_GPIO_SD4_CD, .enable = true }, /* mmc4 cd */
{ .gpio = TRIMSLICE_GPIO_SD4_WP, .enable = true }, /* mmc4 wp */

{ .gpio = TRIMSLICE_GPIO_USB1_MODE, .enable = true }, /* USB1 mode */
{ .gpio = TRIMSLICE_GPIO_USB2_RST, .enable = true }, /* USB2 PHY rst */
};

static struct tegra_board_pinmux_conf conf = {
.pgs = trimslice_pinmux,
.pg_count = ARRAY_SIZE(trimslice_pinmux),
.gpios = gpio_table,
.gpio_count = ARRAY_SIZE(gpio_table),
};

void trimslice_pinmux_init(void)
Expand Down
9 changes: 0 additions & 9 deletions arch/arm/mach-tegra/include/mach/gpio-tegra.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,4 @@

#define TEGRA_NR_GPIOS INT_GPIO_NR

struct tegra_gpio_table {
int gpio; /* GPIO number */
bool enable; /* Enable for GPIO at init? */
};

void tegra_gpio_config(struct tegra_gpio_table *table, int num);
void tegra_gpio_enable(int gpio);
void tegra_gpio_disable(int gpio);

#endif
1 change: 0 additions & 1 deletion arch/arm/mach-tegra/usb_phy.c
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,6 @@ struct tegra_usb_phy *tegra_usb_phy_open(int instance, void __iomem *regs,
err = -ENXIO;
goto err1;
}
tegra_gpio_enable(ulpi_config->reset_gpio);
gpio_request(ulpi_config->reset_gpio, "ulpi_phy_reset_b");
gpio_direction_output(ulpi_config->reset_gpio, 0);
phy->ulpi = otg_ulpi_create(&ulpi_viewport_access_ops, 0);
Expand Down
36 changes: 18 additions & 18 deletions drivers/gpio/gpio-tegra.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
#include <linux/platform_device.h>
#include <linux/module.h>
#include <linux/irqdomain.h>
#include <linux/pinctrl/consumer.h>

#include <asm/mach/irq.h>

#include <mach/gpio-tegra.h>
#include <mach/iomap.h>
#include <mach/suspend.h>

Expand Down Expand Up @@ -108,18 +108,29 @@ static void tegra_gpio_mask_write(u32 reg, int gpio, int value)
tegra_gpio_writel(val, reg);
}

void tegra_gpio_enable(int gpio)
static void tegra_gpio_enable(int gpio)
{
tegra_gpio_mask_write(GPIO_MSK_CNF(gpio), gpio, 1);
}
EXPORT_SYMBOL_GPL(tegra_gpio_enable);

void tegra_gpio_disable(int gpio)
static void tegra_gpio_disable(int gpio)
{
tegra_gpio_mask_write(GPIO_MSK_CNF(gpio), gpio, 0);
}
EXPORT_SYMBOL_GPL(tegra_gpio_disable);

int tegra_gpio_request(struct gpio_chip *chip, unsigned offset)
{
return pinctrl_request_gpio(offset);
}

void tegra_gpio_free(struct gpio_chip *chip, unsigned offset)
{
pinctrl_free_gpio(offset);
tegra_gpio_disable(offset);
}

static void tegra_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
{
tegra_gpio_mask_write(GPIO_MSK_OUT(offset), offset, value);
Expand All @@ -133,6 +144,7 @@ static int tegra_gpio_get(struct gpio_chip *chip, unsigned offset)
static int tegra_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
{
tegra_gpio_mask_write(GPIO_MSK_OE(offset), offset, 0);
tegra_gpio_enable(offset);
return 0;
}

Expand All @@ -141,6 +153,7 @@ static int tegra_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
{
tegra_gpio_set(chip, offset, value);
tegra_gpio_mask_write(GPIO_MSK_OE(offset), offset, 1);
tegra_gpio_enable(offset);
return 0;
}

Expand All @@ -151,13 +164,14 @@ static int tegra_gpio_to_irq(struct gpio_chip *chip, unsigned offset)

static struct gpio_chip tegra_gpio_chip = {
.label = "tegra-gpio",
.request = tegra_gpio_request,
.free = tegra_gpio_free,
.direction_input = tegra_gpio_direction_input,
.get = tegra_gpio_get,
.direction_output = tegra_gpio_direction_output,
.set = tegra_gpio_set,
.to_irq = tegra_gpio_to_irq,
.base = 0,
.ngpio = TEGRA_NR_GPIOS,
};

static void tegra_gpio_irq_ack(struct irq_data *d)
Expand Down Expand Up @@ -493,20 +507,6 @@ static int __init tegra_gpio_init(void)
}
postcore_initcall(tegra_gpio_init);

void tegra_gpio_config(struct tegra_gpio_table *table, int num)
{
int i;

for (i = 0; i < num; i++) {
int gpio = table[i].gpio;

if (table[i].enable)
tegra_gpio_enable(gpio);
else
tegra_gpio_disable(gpio);
}
}

#ifdef CONFIG_DEBUG_FS

#include <linux/debugfs.h>
Expand Down
Loading

0 comments on commit 3e215d0

Please sign in to comment.