mpp.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 <log.h>
  13. #include <asm/io.h>
  14. #include <asm/arch/cpu.h>
  15. #include <asm/arch/soc.h>
  16. #include <asm/arch/mpp.h>
  17. static u32 kirkwood_variant(void)
  18. {
  19. switch (readl(KW_REG_DEVICE_ID) & 0x03) {
  20. case 1:
  21. return MPP_F6192_MASK;
  22. case 2:
  23. return MPP_F6281_MASK;
  24. default:
  25. debug("MPP setup: unknown kirkwood variant\n");
  26. return 0;
  27. }
  28. }
  29. #define MPP_CTRL(i) (KW_MPP_BASE + (i* 4))
  30. #define MPP_NR_REGS (1 + MPP_MAX/8)
  31. void kirkwood_mpp_conf(const u32 *mpp_list, u32 *mpp_save)
  32. {
  33. u32 mpp_ctrl[MPP_NR_REGS];
  34. unsigned int variant_mask;
  35. int i;
  36. variant_mask = kirkwood_variant();
  37. if (!variant_mask)
  38. return;
  39. debug( "initial MPP regs:");
  40. for (i = 0; i < MPP_NR_REGS; i++) {
  41. mpp_ctrl[i] = readl(MPP_CTRL(i));
  42. debug(" %08x", mpp_ctrl[i]);
  43. }
  44. debug("\n");
  45. while (*mpp_list) {
  46. unsigned int num = MPP_NUM(*mpp_list);
  47. unsigned int sel = MPP_SEL(*mpp_list);
  48. unsigned int sel_save;
  49. int shift;
  50. if (num > MPP_MAX) {
  51. debug("kirkwood_mpp_conf: invalid MPP "
  52. "number (%u)\n", num);
  53. continue;
  54. }
  55. if (!(*mpp_list & variant_mask)) {
  56. debug("kirkwood_mpp_conf: requested MPP%u config "
  57. "unavailable on this hardware\n", num);
  58. continue;
  59. }
  60. shift = (num & 7) << 2;
  61. if (mpp_save) {
  62. sel_save = (mpp_ctrl[num / 8] >> shift) & 0xf;
  63. *mpp_save = num | (sel_save << 8) | variant_mask;
  64. mpp_save++;
  65. }
  66. mpp_ctrl[num / 8] &= ~(0xf << shift);
  67. mpp_ctrl[num / 8] |= sel << shift;
  68. mpp_list++;
  69. }
  70. debug(" final MPP regs:");
  71. for (i = 0; i < MPP_NR_REGS; i++) {
  72. writel(mpp_ctrl[i], MPP_CTRL(i));
  73. debug(" %08x", mpp_ctrl[i]);
  74. }
  75. debug("\n");
  76. }