iomux.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright 2004-2006,2010 Freescale Semiconductor, Inc. All Rights Reserved.
  3. * Copyright (C) 2008 by Sascha Hauer <kernel@pengutronix.de>
  4. * Copyright (C) 2009 by Jan Weitzel Phytec Messtechnik GmbH,
  5. * <armlinux@phytec.de>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  19. * MA 02110-1301, USA.
  20. */
  21. #include <linux/errno.h>
  22. #include <linux/init.h>
  23. #include <linux/kernel.h>
  24. #include <linux/module.h>
  25. #include <linux/string.h>
  26. #include <linux/gpio.h>
  27. #include <asm/mach/map.h>
  28. #include <mach/mxs.h>
  29. #include <mach/iomux.h>
  30. /*
  31. * configures a single pad in the iomuxer
  32. */
  33. int mxs_iomux_setup_pad(iomux_cfg_t pad)
  34. {
  35. u32 reg, ofs, bp, bm;
  36. void __iomem *iomux_base = MXS_IO_ADDRESS(MXS_PINCTRL_BASE_ADDR);
  37. /* muxsel */
  38. ofs = 0x100;
  39. ofs += PAD_BANK(pad) * 0x20 + PAD_PIN(pad) / 16 * 0x10;
  40. bp = PAD_PIN(pad) % 16 * 2;
  41. bm = 0x3 << bp;
  42. reg = __raw_readl(iomux_base + ofs);
  43. reg &= ~bm;
  44. reg |= PAD_MUXSEL(pad) << bp;
  45. __raw_writel(reg, iomux_base + ofs);
  46. /* drive */
  47. ofs = cpu_is_mx23() ? 0x200 : 0x300;
  48. ofs += PAD_BANK(pad) * 0x40 + PAD_PIN(pad) / 8 * 0x10;
  49. /* mA */
  50. if (PAD_MA_VALID(pad)) {
  51. bp = PAD_PIN(pad) % 8 * 4;
  52. bm = 0x3 << bp;
  53. reg = __raw_readl(iomux_base + ofs);
  54. reg &= ~bm;
  55. reg |= PAD_MA(pad) << bp;
  56. __raw_writel(reg, iomux_base + ofs);
  57. }
  58. /* vol */
  59. if (PAD_VOL_VALID(pad)) {
  60. bp = PAD_PIN(pad) % 8 * 4 + 2;
  61. if (PAD_VOL(pad))
  62. __mxs_setl(1 << bp, iomux_base + ofs);
  63. else
  64. __mxs_clrl(1 << bp, iomux_base + ofs);
  65. }
  66. /* pull */
  67. if (PAD_PULL_VALID(pad)) {
  68. ofs = cpu_is_mx23() ? 0x400 : 0x600;
  69. ofs += PAD_BANK(pad) * 0x10;
  70. bp = PAD_PIN(pad);
  71. if (PAD_PULL(pad))
  72. __mxs_setl(1 << bp, iomux_base + ofs);
  73. else
  74. __mxs_clrl(1 << bp, iomux_base + ofs);
  75. }
  76. return 0;
  77. }
  78. int mxs_iomux_setup_multiple_pads(const iomux_cfg_t *pad_list, unsigned count)
  79. {
  80. const iomux_cfg_t *p = pad_list;
  81. int i;
  82. int ret;
  83. for (i = 0; i < count; i++) {
  84. ret = mxs_iomux_setup_pad(*p);
  85. if (ret)
  86. return ret;
  87. p++;
  88. }
  89. return 0;
  90. }