mvmfp.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * (C) Copyright 2010
  3. * Marvell Semiconductor <www.marvell.com>
  4. * Written-by: Prafulla Wadaskar <prafulla@marvell.com>,
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <common.h>
  9. #include <asm/io.h>
  10. #include <mvmfp.h>
  11. #include <asm/arch/mfp.h>
  12. /*
  13. * mfp_config
  14. *
  15. * On most of Marvell SoCs (ex. ARMADA100) there is Multi-Funtion-Pin
  16. * configuration registers to configure each GPIO/Function pin on the
  17. * SoC.
  18. *
  19. * This function reads the array of values for
  20. * MFPR_X registers and programms them into respective
  21. * Multi-Function Pin registers.
  22. * It supports - Alternate Function Selection programming.
  23. *
  24. * Whereas,
  25. * The Configureation value is constructed using MFP()
  26. * array consists of 32bit values as defined in MFP(xx,xx..) macro
  27. */
  28. void mfp_config(u32 *mfp_cfgs)
  29. {
  30. u32 *p_mfpr = NULL;
  31. u32 cfg_val, val;
  32. do {
  33. cfg_val = *mfp_cfgs++;
  34. /* exit if End of configuration table detected */
  35. if (cfg_val == MFP_EOC)
  36. break;
  37. p_mfpr = (u32 *)(MV_MFPR_BASE
  38. + MFP_REG_GET_OFFSET(cfg_val));
  39. /* Write a mfg register as per configuration */
  40. val = 0;
  41. if (cfg_val & MFP_AF_FLAG)
  42. /* Abstract and program Afternate-Func Selection */
  43. val |= cfg_val & MFP_AF_MASK;
  44. if (cfg_val & MFP_EDGE_FLAG)
  45. /* Abstract and program Edge configuration */
  46. val |= cfg_val & MFP_LPM_EDGE_MASK;
  47. if (cfg_val & MFP_DRIVE_FLAG)
  48. /* Abstract and program Drive configuration */
  49. val |= cfg_val & MFP_DRIVE_MASK;
  50. if (cfg_val & MFP_PULL_FLAG)
  51. /* Abstract and program Pullup/down configuration */
  52. val |= cfg_val & MFP_PULL_MASK;
  53. writel(val, p_mfpr);
  54. } while (1);
  55. /*
  56. * perform a read-back of any MFPR register to make sure the
  57. * previous writings are finished
  58. */
  59. readl(p_mfpr);
  60. }