blob: 4fdad99cadef54c0acc63b761b1a44176e5f1dff [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>
Simon Glassf7ae49f2020-05-10 11:40:05 -060013#include <log.h>
Lei Wena7efd712011-10-18 20:11:42 +053014#include <asm/io.h>
15#include <asm/arch/cpu.h>
Stefan Roese3dc23f72014-10-22 12:13:06 +020016#include <asm/arch/soc.h>
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020017#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
Albert ARIBAUD9d86f0c2012-11-26 11:27:36 +000035void kirkwood_mpp_conf(const u32 *mpp_list, u32 *mpp_save)
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020036{
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);
Valentin Longchamp8f5d7a02012-06-01 01:30:59 +000056 unsigned int sel_save;
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020057 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;
Valentin Longchamp8f5d7a02012-06-01 01:30:59 +000071
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
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020078 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}