board-pinmux.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. #include <linux/device.h>
  15. #include <linux/kernel.h>
  16. #include <linux/notifier.h>
  17. #include <linux/of.h>
  18. #include <linux/string.h>
  19. #include <mach/gpio-tegra.h>
  20. #include <mach/pinmux.h>
  21. #include "board-pinmux.h"
  22. #include "devices.h"
  23. struct tegra_board_pinmux_conf *confs[2];
  24. static void tegra_board_pinmux_setup_gpios(void)
  25. {
  26. int i;
  27. for (i = 0; i < ARRAY_SIZE(confs); i++) {
  28. if (!confs[i])
  29. continue;
  30. tegra_gpio_config(confs[i]->gpios, confs[i]->gpio_count);
  31. }
  32. }
  33. static void tegra_board_pinmux_setup_pinmux(void)
  34. {
  35. int i;
  36. for (i = 0; i < ARRAY_SIZE(confs); i++) {
  37. if (!confs[i])
  38. continue;
  39. tegra_pinmux_config_table(confs[i]->pgs, confs[i]->pg_count);
  40. if (confs[i]->drives)
  41. tegra_drive_pinmux_config_table(confs[i]->drives,
  42. confs[i]->drive_count);
  43. }
  44. }
  45. static int tegra_board_pinmux_bus_notify(struct notifier_block *nb,
  46. unsigned long event, void *vdev)
  47. {
  48. static bool had_gpio;
  49. static bool had_pinmux;
  50. struct device *dev = vdev;
  51. const char *devname;
  52. if (event != BUS_NOTIFY_BOUND_DRIVER)
  53. return NOTIFY_DONE;
  54. devname = dev_name(dev);
  55. if (!had_gpio && !strcmp(devname, GPIO_DEV)) {
  56. tegra_board_pinmux_setup_gpios();
  57. had_gpio = true;
  58. } else if (!had_pinmux && !strcmp(devname, PINMUX_DEV)) {
  59. tegra_board_pinmux_setup_pinmux();
  60. had_pinmux = true;
  61. }
  62. if (had_gpio && had_pinmux)
  63. return NOTIFY_STOP_MASK;
  64. else
  65. return NOTIFY_DONE;
  66. }
  67. static struct notifier_block nb = {
  68. .notifier_call = tegra_board_pinmux_bus_notify,
  69. };
  70. static struct platform_device *devices[] = {
  71. &tegra_gpio_device,
  72. &tegra_pinmux_device,
  73. };
  74. void tegra_board_pinmux_init(struct tegra_board_pinmux_conf *conf_a,
  75. struct tegra_board_pinmux_conf *conf_b)
  76. {
  77. confs[0] = conf_a;
  78. confs[1] = conf_b;
  79. bus_register_notifier(&platform_bus_type, &nb);
  80. if (!of_machine_is_compatible("nvidia,tegra20"))
  81. platform_add_devices(devices, ARRAY_SIZE(devices));
  82. }