linux-tegra.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
To: Olof Johansson <olof-nZhT3qVonbNeoWH0uzbU5w@public.gmane.org>,
	Colin Cross <ccross-z5hGa2qSFaRBDgjK7y7TUQ@public.gmane.org>
Cc: linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
Subject: [PATCH 9/9] arm/tegra: Use bus notifiers to trigger pinmux setup
Date: Fri, 16 Dec 2011 15:12:32 -0700	[thread overview]
Message-ID: <1324073552-15542-10-git-send-email-swarren@nvidia.com> (raw)
In-Reply-To: <1324073552-15542-1-git-send-email-swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>

Currently, the Tegra pinmux is initialized at different times when booting
with and without device tree:

Without device tree:

1) Pinmux and GPIO drivers are registered.
2) Pinmux is configured.
3) All other drivers are registered.

With device tree:

1) All drivers are registered and probed, including pinmux and GPIO.
2) Pinmux is configured.

This change modifies board-pinmux.c to detect pinmux and GPIO driver
registration using bus notifiers. This allows pinmux configuration to
happen immediately after the pinmux driver is probed, irrespective of
whether the pinmux driver is manually registered by board-pinmux.c, or
if it's instantiated during device tree parsing.

To support this with device tree, the pinmux init functions must be
called prior to instantiating devices from device tree, so that the
notifiers are set up before-hand.

Signed-off-by: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
 arch/arm/mach-tegra/board-dt.c     |   14 +++---
 arch/arm/mach-tegra/board-pinmux.c |   72 +++++++++++++++++++++++++++++++-----
 2 files changed, 69 insertions(+), 17 deletions(-)

diff --git a/arch/arm/mach-tegra/board-dt.c b/arch/arm/mach-tegra/board-dt.c
index f062051..b44633b 100644
--- a/arch/arm/mach-tegra/board-dt.c
+++ b/arch/arm/mach-tegra/board-dt.c
@@ -123,13 +123,6 @@ static void __init tegra_dt_init(void)
 
 	tegra_clk_init_from_table(tegra_dt_clk_init_table);
 
-	/*
-	 * Finished with the static registrations now; fill in the missing
-	 * devices
-	 */
-	of_platform_populate(NULL, tegra_dt_match_table,
-				tegra20_auxdata_lookup, NULL);
-
 	for (i = 0; i < ARRAY_SIZE(pinmux_configs); i++) {
 		if (of_machine_is_compatible(pinmux_configs[i].machine)) {
 			pinmux_configs[i].init();
@@ -139,6 +132,13 @@ static void __init tegra_dt_init(void)
 
 	WARN(i == ARRAY_SIZE(pinmux_configs),
 		"Unknown platform! Pinmuxing not initialized\n");
+
+	/*
+	 * Finished with the static registrations now; fill in the missing
+	 * devices
+	 */
+	of_platform_populate(NULL, tegra_dt_match_table,
+				tegra20_auxdata_lookup, NULL);
 }
 
 static const char * tegra_dt_board_compat[] = {
diff --git a/arch/arm/mach-tegra/board-pinmux.c b/arch/arm/mach-tegra/board-pinmux.c
index 103ef65..adc3efe 100644
--- a/arch/arm/mach-tegra/board-pinmux.c
+++ b/arch/arm/mach-tegra/board-pinmux.c
@@ -12,7 +12,11 @@
  *
  */
 
+#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>
@@ -20,19 +24,23 @@
 #include "board-pinmux.h"
 #include "devices.h"
 
-static struct platform_device *devices[] = {
-	&tegra_gpio_device,
-	&tegra_pinmux_device,
-};
+struct tegra_board_pinmux_conf *confs[2];
 
-void tegra_board_pinmux_init(struct tegra_board_pinmux_conf *conf_a,
-			     struct tegra_board_pinmux_conf *conf_b)
+static void tegra_board_pinmux_setup_gpios(void)
 {
-	struct tegra_board_pinmux_conf *confs[] = {conf_a, conf_b};
 	int i;
 
-	if (of_machine_is_compatible("nvidia,tegra20"))
-		platform_add_devices(devices, ARRAY_SIZE(devices));
+	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])
@@ -43,10 +51,54 @@ void tegra_board_pinmux_init(struct tegra_board_pinmux_conf *conf_a,
 		if (confs[i]->drives)
 			tegra_drive_pinmux_config_table(confs[i]->drives,
 							confs[i]->drive_count);
+	}
+}
 
-		tegra_gpio_config(confs[i]->gpios, confs[i]->gpio_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));
 }
-- 
1.7.0.4

  parent reply	other threads:[~2011-12-16 22:12 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-16 22:12 [PATCH 0/9] arm/tegra: Various pinmux-related cleanups Stephen Warren
     [not found] ` <1324073552-15542-1-git-send-email-swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2011-12-16 22:12   ` [PATCH 1/9] arm/tegra: Split Seaboard GPIO table to allow for Ventana Stephen Warren
2011-12-16 22:12   ` [PATCH 2/9] arm/tegra: Add AUXDATA for tegra-pinmux and tegra-gpio Stephen Warren
2011-12-16 22:12   ` [PATCH 3/9] arm/tegra: Harmony PCIe: Don't touch pinmux Stephen Warren
2011-12-16 22:12   ` [PATCH 4/9] arm/tegra: PCIe: Remove include of mach/pinmux.h Stephen Warren
2011-12-16 22:12   ` [PATCH 5/9] arm/tegra: Remove useless entries from ventana_pinmux[] Stephen Warren
2011-12-16 22:12   ` [PATCH 6/9] arm/tegra: Rework Seaboard-vs-Ventana pinmux table Stephen Warren
2011-12-16 22:12   ` [PATCH 7/9] arm/tegra: Fix mistake in Trimslice's pinmux Stephen Warren
2011-12-16 22:12   ` [PATCH 8/9] arm/tegra: Refactor board-*-pinmux.c to share code Stephen Warren
2011-12-16 22:12   ` Stephen Warren [this message]
2011-12-18  0:57   ` [PATCH 0/9] arm/tegra: Various pinmux-related cleanups Olof Johansson
     [not found]     ` <20111218005702.GA4336-O5ziIzlqnXUVNXGz7ipsyg@public.gmane.org>
2011-12-19 17:49       ` Stephen Warren
     [not found]         ` <74CDBE0F657A3D45AFBB94109FB122FF176BE92A4A-C7FfzLzN0UxDw2glCA4ptUEOCMrvLtNR@public.gmane.org>
2011-12-20  2:03           ` Olof Johansson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1324073552-15542-10-git-send-email-swarren@nvidia.com \
    --to=swarren-ddmlm1+adcrqt0dzr+alfa@public.gmane.org \
    --cc=ccross-z5hGa2qSFaRBDgjK7y7TUQ@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=olof-nZhT3qVonbNeoWH0uzbU5w@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).