iomux.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 <common.h>
  22. #include <asm/errno.h>
  23. #include <asm/io.h>
  24. #include <asm/arch/clock.h>
  25. #include <asm/arch/iomux.h>
  26. #include <asm/arch/imx-regs.h>
  27. #if defined(CONFIG_MX23)
  28. #define DRIVE_OFFSET 0x200
  29. #define PULL_OFFSET 0x400
  30. #elif defined(CONFIG_MX28)
  31. #define DRIVE_OFFSET 0x300
  32. #define PULL_OFFSET 0x600
  33. #else
  34. #error "Please select CONFIG_MX23 or CONFIG_MX28"
  35. #endif
  36. /*
  37. * configures a single pad in the iomuxer
  38. */
  39. int mxs_iomux_setup_pad(iomux_cfg_t pad)
  40. {
  41. u32 reg, ofs, bp, bm;
  42. void *iomux_base = (void *)MXS_PINCTRL_BASE;
  43. struct mx28_register_32 *mxs_reg;
  44. /* muxsel */
  45. ofs = 0x100;
  46. ofs += PAD_BANK(pad) * 0x20 + PAD_PIN(pad) / 16 * 0x10;
  47. bp = PAD_PIN(pad) % 16 * 2;
  48. bm = 0x3 << bp;
  49. reg = readl(iomux_base + ofs);
  50. reg &= ~bm;
  51. reg |= PAD_MUXSEL(pad) << bp;
  52. writel(reg, iomux_base + ofs);
  53. /* drive */
  54. ofs = DRIVE_OFFSET;
  55. ofs += PAD_BANK(pad) * 0x40 + PAD_PIN(pad) / 8 * 0x10;
  56. /* mA */
  57. if (PAD_MA_VALID(pad)) {
  58. bp = PAD_PIN(pad) % 8 * 4;
  59. bm = 0x3 << bp;
  60. reg = readl(iomux_base + ofs);
  61. reg &= ~bm;
  62. reg |= PAD_MA(pad) << bp;
  63. writel(reg, iomux_base + ofs);
  64. }
  65. /* vol */
  66. if (PAD_VOL_VALID(pad)) {
  67. bp = PAD_PIN(pad) % 8 * 4 + 2;
  68. mxs_reg = (struct mx28_register_32 *)(iomux_base + ofs);
  69. if (PAD_VOL(pad))
  70. writel(1 << bp, &mxs_reg->reg_set);
  71. else
  72. writel(1 << bp, &mxs_reg->reg_clr);
  73. }
  74. /* pull */
  75. if (PAD_PULL_VALID(pad)) {
  76. ofs = PULL_OFFSET;
  77. ofs += PAD_BANK(pad) * 0x10;
  78. bp = PAD_PIN(pad);
  79. mxs_reg = (struct mx28_register_32 *)(iomux_base + ofs);
  80. if (PAD_PULL(pad))
  81. writel(1 << bp, &mxs_reg->reg_set);
  82. else
  83. writel(1 << bp, &mxs_reg->reg_clr);
  84. }
  85. return 0;
  86. }
  87. int mxs_iomux_setup_multiple_pads(const iomux_cfg_t *pad_list, unsigned count)
  88. {
  89. const iomux_cfg_t *p = pad_list;
  90. int i;
  91. int ret;
  92. for (i = 0; i < count; i++) {
  93. ret = mxs_iomux_setup_pad(*p);
  94. if (ret)
  95. return ret;
  96. p++;
  97. }
  98. return 0;
  99. }