Stephen Warren | 54862bf | 2011-12-16 15:12:31 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011, NVIDIA CORPORATION. All rights reserved. |
| 3 | * |
| 4 | * This software is licensed under the terms of the GNU General Public |
| 5 | * License version 2, as published by the Free Software Foundation, and |
| 6 | * may be copied, distributed, and modified under those terms. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | */ |
| 14 | |
Stephen Warren | a58116f | 2011-12-16 15:12:32 -0700 | [diff] [blame] | 15 | #include <linux/device.h> |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/notifier.h> |
Stephen Warren | 54862bf | 2011-12-16 15:12:31 -0700 | [diff] [blame] | 18 | #include <linux/of.h> |
Stephen Warren | a58116f | 2011-12-16 15:12:32 -0700 | [diff] [blame] | 19 | #include <linux/string.h> |
Stephen Warren | 54862bf | 2011-12-16 15:12:31 -0700 | [diff] [blame] | 20 | |
Stephen Warren | 54862bf | 2011-12-16 15:12:31 -0700 | [diff] [blame] | 21 | #include <mach/pinmux.h> |
| 22 | |
| 23 | #include "board-pinmux.h" |
| 24 | #include "devices.h" |
| 25 | |
Stephen Warren | a58116f | 2011-12-16 15:12:32 -0700 | [diff] [blame] | 26 | struct tegra_board_pinmux_conf *confs[2]; |
Stephen Warren | 54862bf | 2011-12-16 15:12:31 -0700 | [diff] [blame] | 27 | |
Stephen Warren | a58116f | 2011-12-16 15:12:32 -0700 | [diff] [blame] | 28 | static void tegra_board_pinmux_setup_pinmux(void) |
| 29 | { |
| 30 | int i; |
Stephen Warren | 54862bf | 2011-12-16 15:12:31 -0700 | [diff] [blame] | 31 | |
| 32 | for (i = 0; i < ARRAY_SIZE(confs); i++) { |
| 33 | if (!confs[i]) |
| 34 | continue; |
| 35 | |
| 36 | tegra_pinmux_config_table(confs[i]->pgs, confs[i]->pg_count); |
| 37 | |
| 38 | if (confs[i]->drives) |
| 39 | tegra_drive_pinmux_config_table(confs[i]->drives, |
| 40 | confs[i]->drive_count); |
Stephen Warren | 54862bf | 2011-12-16 15:12:31 -0700 | [diff] [blame] | 41 | } |
Stephen Warren | a58116f | 2011-12-16 15:12:32 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | static int tegra_board_pinmux_bus_notify(struct notifier_block *nb, |
| 45 | unsigned long event, void *vdev) |
| 46 | { |
Stephen Warren | a58116f | 2011-12-16 15:12:32 -0700 | [diff] [blame] | 47 | struct device *dev = vdev; |
Stephen Warren | a58116f | 2011-12-16 15:12:32 -0700 | [diff] [blame] | 48 | |
| 49 | if (event != BUS_NOTIFY_BOUND_DRIVER) |
| 50 | return NOTIFY_DONE; |
| 51 | |
Stephen Warren | 3e215d0 | 2012-02-18 01:04:55 -0700 | [diff] [blame^] | 52 | if (strcmp(dev_name(dev), PINMUX_DEV)) |
Stephen Warren | a58116f | 2011-12-16 15:12:32 -0700 | [diff] [blame] | 53 | return NOTIFY_DONE; |
Stephen Warren | 3e215d0 | 2012-02-18 01:04:55 -0700 | [diff] [blame^] | 54 | |
| 55 | tegra_board_pinmux_setup_pinmux(); |
| 56 | |
| 57 | return NOTIFY_STOP_MASK; |
Stephen Warren | a58116f | 2011-12-16 15:12:32 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | static struct notifier_block nb = { |
| 61 | .notifier_call = tegra_board_pinmux_bus_notify, |
| 62 | }; |
| 63 | |
| 64 | static struct platform_device *devices[] = { |
| 65 | &tegra_gpio_device, |
| 66 | &tegra_pinmux_device, |
| 67 | }; |
| 68 | |
| 69 | void tegra_board_pinmux_init(struct tegra_board_pinmux_conf *conf_a, |
| 70 | struct tegra_board_pinmux_conf *conf_b) |
| 71 | { |
| 72 | confs[0] = conf_a; |
| 73 | confs[1] = conf_b; |
| 74 | |
| 75 | bus_register_notifier(&platform_bus_type, &nb); |
Stephen Warren | 54862bf | 2011-12-16 15:12:31 -0700 | [diff] [blame] | 76 | |
| 77 | if (!of_machine_is_compatible("nvidia,tegra20")) |
| 78 | platform_add_devices(devices, ARRAY_SIZE(devices)); |
| 79 | } |