mpp.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * arch/arm/mach-kirkwood/mpp.c
  3. *
  4. * MPP functions for Marvell Kirkwood SoCs
  5. * Referenced from Linux kernel source
  6. *
  7. * This file is licensed under the terms of the GNU General Public
  8. * License version 2. This program is licensed "as is" without any
  9. * warranty of any kind, whether express or implied.
  10. */
  11. #include <common.h>
  12. #include <asm/io.h>
  13. #include <asm/arch/cpu.h>
  14. #include <asm/arch/soc.h>
  15. #include <asm/arch/mpp.h>
  16. static u32 kirkwood_variant(void)
  17. {
  18. switch (readl(KW_REG_DEVICE_ID) & 0x03) {
  19. case 1:
  20. return MPP_F6192_MASK;
  21. case 2:
  22. return MPP_F6281_MASK;
  23. default:
  24. debug("MPP setup: unknown kirkwood variant\n");
  25. return 0;
  26. }
  27. }
  28. #define MPP_CTRL(i) (KW_MPP_BASE + (i* 4))
  29. #define MPP_NR_REGS (1 + MPP_MAX/8)
  30. void kirkwood_mpp_conf(const u32 *mpp_list, u32 *mpp_save)
  31. {
  32. u32 mpp_ctrl[MPP_NR_REGS];
  33. unsigned int variant_mask;
  34. int i;
  35. variant_mask = kirkwood_variant();
  36. if (!variant_mask)
  37. return;
  38. debug( "initial MPP regs:");
  39. for (i = 0; i < MPP_NR_REGS; i++) {
  40. mpp_ctrl[i] = readl(MPP_CTRL(i));
  41. debug(" %08x", mpp_ctrl[i]);
  42. }
  43. debug("\n");
  44. while (*mpp_list) {
  45. unsigned int num = MPP_NUM(*mpp_list);
  46. unsigned int sel = MPP_SEL(*mpp_list);
  47. unsigned int sel_save;
  48. int shift;
  49. if (num > MPP_MAX) {
  50. debug("kirkwood_mpp_conf: invalid MPP "
  51. "number (%u)\n", num);
  52. continue;
  53. }
  54. if (!(*mpp_list & variant_mask)) {
  55. debug("kirkwood_mpp_conf: requested MPP%u config "
  56. "unavailable on this hardware\n", num);
  57. continue;
  58. }
  59. shift = (num & 7) << 2;
  60. if (mpp_save) {
  61. sel_save = (mpp_ctrl[num / 8] >> shift) & 0xf;
  62. *mpp_save = num | (sel_save << 8) | variant_mask;
  63. mpp_save++;
  64. }
  65. mpp_ctrl[num / 8] &= ~(0xf << shift);
  66. mpp_ctrl[num / 8] |= sel << shift;
  67. mpp_list++;
  68. }
  69. debug(" final MPP regs:");
  70. for (i = 0; i < MPP_NR_REGS; i++) {
  71. writel(mpp_ctrl[i], MPP_CTRL(i));
  72. debug(" %08x", mpp_ctrl[i]);
  73. }
  74. debug("\n");
  75. }