blob: b2f0ad55e3ca51db27ea17e98bfc054dcba4a354 [file] [log] [blame]
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +02001/*
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 <asm/arch/kirkwood.h>
14#include <asm/arch/mpp.h>
15
16static 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
29#define MPP_CTRL(i) (KW_MPP_BASE + (i* 4))
30#define MPP_NR_REGS (1 + MPP_MAX/8)
31
32void kirkwood_mpp_conf(u32 *mpp_list)
33{
34 u32 mpp_ctrl[MPP_NR_REGS];
35 unsigned int variant_mask;
36 int i;
37
38 variant_mask = kirkwood_variant();
39 if (!variant_mask)
40 return;
41
42 debug( "initial MPP regs:");
43 for (i = 0; i < MPP_NR_REGS; i++) {
44 mpp_ctrl[i] = readl(MPP_CTRL(i));
45 debug(" %08x", mpp_ctrl[i]);
46 }
47 debug("\n");
48
49
50 while (*mpp_list) {
51 unsigned int num = MPP_NUM(*mpp_list);
52 unsigned int sel = MPP_SEL(*mpp_list);
53 int shift;
54
55 if (num > MPP_MAX) {
56 debug("kirkwood_mpp_conf: invalid MPP "
57 "number (%u)\n", num);
58 continue;
59 }
60 if (!(*mpp_list & variant_mask)) {
61 debug("kirkwood_mpp_conf: requested MPP%u config "
62 "unavailable on this hardware\n", num);
63 continue;
64 }
65
66 shift = (num & 7) << 2;
67 mpp_ctrl[num / 8] &= ~(0xf << shift);
68 mpp_ctrl[num / 8] |= sel << shift;
69
70 mpp_list++;
71 }
72
73 debug(" final MPP regs:");
74 for (i = 0; i < MPP_NR_REGS; i++) {
75 writel(mpp_ctrl[i], MPP_CTRL(i));
76 debug(" %08x", mpp_ctrl[i]);
77 }
78 debug("\n");
79
80}