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