iomux.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright 2004-2006 Freescale Semiconductor, Inc. All Rights Reserved.
  3. * Copyright (C) 2008 by Sascha Hauer <kernel@pengutronix.de>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or (at your option) any later version.
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  17. * MA 02110-1301, USA.
  18. */
  19. #include <linux/module.h>
  20. #include <linux/spinlock.h>
  21. #include <linux/io.h>
  22. #include <linux/gpio.h>
  23. #include <mach/hardware.h>
  24. #include <mach/gpio.h>
  25. #include <mach/iomux-mx3.h>
  26. /*
  27. * IOMUX register (base) addresses
  28. */
  29. #define IOMUX_BASE IO_ADDRESS(IOMUXC_BASE_ADDR)
  30. #define IOMUXINT_OBS1 (IOMUX_BASE + 0x000)
  31. #define IOMUXINT_OBS2 (IOMUX_BASE + 0x004)
  32. #define IOMUXGPR (IOMUX_BASE + 0x008)
  33. #define IOMUXSW_MUX_CTL (IOMUX_BASE + 0x00C)
  34. #define IOMUXSW_PAD_CTL (IOMUX_BASE + 0x154)
  35. static DEFINE_SPINLOCK(gpio_mux_lock);
  36. #define IOMUX_REG_MASK (IOMUX_PADNUM_MASK & ~0x3)
  37. /*
  38. * set the mode for a IOMUX pin.
  39. */
  40. int mxc_iomux_mode(unsigned int pin_mode)
  41. {
  42. u32 field, l, mode, ret = 0;
  43. void __iomem *reg;
  44. reg = IOMUXSW_MUX_CTL + (pin_mode & IOMUX_REG_MASK);
  45. field = pin_mode & 0x3;
  46. mode = (pin_mode & IOMUX_MODE_MASK) >> IOMUX_MODE_SHIFT;
  47. pr_debug("%s: reg offset = 0x%x field = %d mode = 0x%02x\n",
  48. __func__, (pin_mode & IOMUX_REG_MASK), field, mode);
  49. spin_lock(&gpio_mux_lock);
  50. l = __raw_readl(reg);
  51. l &= ~(0xff << (field * 8));
  52. l |= mode << (field * 8);
  53. __raw_writel(l, reg);
  54. spin_unlock(&gpio_mux_lock);
  55. return ret;
  56. }
  57. EXPORT_SYMBOL(mxc_iomux_mode);
  58. /*
  59. * This function configures the pad value for a IOMUX pin.
  60. */
  61. void mxc_iomux_set_pad(enum iomux_pins pin, u32 config)
  62. {
  63. u32 field, l;
  64. void __iomem *reg;
  65. reg = IOMUXSW_PAD_CTL + (pin + 2) / 3;
  66. field = (pin + 2) % 3;
  67. pr_debug("%s: reg offset = 0x%x field = %d\n",
  68. __func__, (pin + 2) / 3, field);
  69. spin_lock(&gpio_mux_lock);
  70. l = __raw_readl(reg);
  71. l &= ~(0x1ff << (field * 9));
  72. l |= config << (field * 9);
  73. __raw_writel(l, reg);
  74. spin_unlock(&gpio_mux_lock);
  75. }
  76. EXPORT_SYMBOL(mxc_iomux_set_pad);
  77. /*
  78. * This function enables/disables the general purpose function for a particular
  79. * signal.
  80. */
  81. void mxc_iomux_set_gpr(enum iomux_gp_func gp, bool en)
  82. {
  83. u32 l;
  84. spin_lock(&gpio_mux_lock);
  85. l = __raw_readl(IOMUXGPR);
  86. if (en)
  87. l |= gp;
  88. else
  89. l &= ~gp;
  90. __raw_writel(l, IOMUXGPR);
  91. spin_unlock(&gpio_mux_lock);
  92. }
  93. EXPORT_SYMBOL(mxc_iomux_set_gpr);