summaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-tegra/board-pinmux.c
blob: adc3efe979b3cd6b09987e3180374b4a1f888ac3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
 * Copyright (c) 2011, NVIDIA CORPORATION.  All rights reserved.
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */

#include <linux/device.h>
#include <linux/kernel.h>
#include <linux/notifier.h>
#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;

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

		tegra_pinmux_config_table(confs[i]->pgs, confs[i]->pg_count);

		if (confs[i]->drives)
			tegra_drive_pinmux_config_table(confs[i]->drives,
							confs[i]->drive_count);
	}
}

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 (!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;
	}

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

static struct notifier_block nb = {
	.notifier_call = tegra_board_pinmux_bus_notify,
};

static struct platform_device *devices[] = {
	&tegra_gpio_device,
	&tegra_pinmux_device,
};

void tegra_board_pinmux_init(struct tegra_board_pinmux_conf *conf_a,
			     struct tegra_board_pinmux_conf *conf_b)
{
	confs[0] = conf_a;
	confs[1] = conf_b;

	bus_register_notifier(&platform_bus_type, &nb);

	if (!of_machine_is_compatible("nvidia,tegra20"))
		platform_add_devices(devices, ARRAY_SIZE(devices));
}