mvmfp.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * (C) Copyright 2010
  3. * Marvell Semiconductor <www.marvell.com>
  4. * Written-by: Prafulla Wadaskar <prafulla@marvell.com>,
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  22. * MA 02110-1301 USA
  23. */
  24. #include <common.h>
  25. #include <asm/io.h>
  26. #include <mvmfp.h>
  27. #include <asm/arch/mfp.h>
  28. #ifdef CONFIG_ARMADA100
  29. #include <asm/arch/armada100.h>
  30. #else
  31. #error Unsupported SoC...
  32. #endif
  33. /*
  34. * mfp_config
  35. *
  36. * On most of Marvell SoCs (ex. ARMADA100) there is Multi-Funtion-Pin
  37. * configuration registers to configure each GPIO/Function pin on the
  38. * SoC.
  39. *
  40. * This function reads the array of values for
  41. * MFPR_X registers and programms them into respective
  42. * Multi-Function Pin registers.
  43. * It supports - Alternate Function Selection programming.
  44. *
  45. * Whereas,
  46. * The Configureation value is constructed using MFP()
  47. * array consists of 32bit values as defined in MFP(xx,xx..) macro
  48. */
  49. void mfp_config(u32 *mfp_cfgs)
  50. {
  51. u32 *p_mfpr = NULL;
  52. u32 cfg_val, val;
  53. do {
  54. cfg_val = *mfp_cfgs++;
  55. /* exit if End of configuration table detected */
  56. if (cfg_val == MFP_EOC)
  57. break;
  58. p_mfpr = (u32 *)(MV_MFPR_BASE
  59. + MFP_REG_GET_OFFSET(cfg_val));
  60. /* Write a mfg register as per configuration */
  61. val = 0;
  62. if (cfg_val & MFP_AF_FLAG)
  63. /* Abstract and program Afternate-Func Selection */
  64. val |= cfg_val & MFP_AF_MASK;
  65. if (cfg_val & MFP_EDGE_FLAG)
  66. /* Abstract and program Edge configuration */
  67. val |= cfg_val & MFP_LPM_EDGE_MASK;
  68. if (cfg_val & MFP_DRIVE_FLAG)
  69. /* Abstract and program Drive configuration */
  70. val |= cfg_val & MFP_DRIVE_MASK;
  71. if (cfg_val & MFP_PULL_FLAG)
  72. /* Abstract and program Pullup/down configuration */
  73. val |= cfg_val & MFP_PULL_MASK;
  74. writel(val, p_mfpr);
  75. } while (1);
  76. /*
  77. * perform a read-back of any MFPR register to make sure the
  78. * previous writings are finished
  79. */
  80. readl(p_mfpr);
  81. }