mux.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * linux/arch/arm/plat-omap/mux.c
  3. *
  4. * Utility to set the Omap MUX and PULL_DWN registers from a table in mux.h
  5. *
  6. * Copyright (C) 2003 - 2008 Nokia Corporation
  7. *
  8. * Written by Tony Lindgren
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. *
  24. */
  25. #include <linux/module.h>
  26. #include <linux/init.h>
  27. #include <linux/kernel.h>
  28. #include <linux/io.h>
  29. #include <asm/system.h>
  30. #include <linux/spinlock.h>
  31. #include <mach/mux.h>
  32. #ifdef CONFIG_OMAP_MUX
  33. static struct omap_mux_cfg *mux_cfg;
  34. int __init omap_mux_register(struct omap_mux_cfg *arch_mux_cfg)
  35. {
  36. if (!arch_mux_cfg || !arch_mux_cfg->pins || arch_mux_cfg->size == 0
  37. || !arch_mux_cfg->cfg_reg) {
  38. printk(KERN_ERR "Invalid pin table\n");
  39. return -EINVAL;
  40. }
  41. mux_cfg = arch_mux_cfg;
  42. return 0;
  43. }
  44. /*
  45. * Sets the Omap MUX and PULL_DWN registers based on the table
  46. */
  47. int __init_or_module omap_cfg_reg(const unsigned long index)
  48. {
  49. struct pin_config *reg;
  50. if (mux_cfg == NULL) {
  51. printk(KERN_ERR "Pin mux table not initialized\n");
  52. return -ENODEV;
  53. }
  54. if (index >= mux_cfg->size) {
  55. printk(KERN_ERR "Invalid pin mux index: %lu (%lu)\n",
  56. index, mux_cfg->size);
  57. dump_stack();
  58. return -ENODEV;
  59. }
  60. reg = (struct pin_config *)&mux_cfg->pins[index];
  61. if (!mux_cfg->cfg_reg)
  62. return -ENODEV;
  63. return mux_cfg->cfg_reg(reg);
  64. }
  65. EXPORT_SYMBOL(omap_cfg_reg);
  66. #else
  67. #define omap_mux_init() do {} while(0)
  68. #define omap_cfg_reg(x) do {} while(0)
  69. #endif /* CONFIG_OMAP_MUX */