Prafulla Wadaskar | 4efb77d | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 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> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 13 | #include <log.h> |
Lei Wen | a7efd71 | 2011-10-18 20:11:42 +0530 | [diff] [blame] | 14 | #include <asm/io.h> |
| 15 | #include <asm/arch/cpu.h> |
Stefan Roese | 3dc23f7 | 2014-10-22 12:13:06 +0200 | [diff] [blame] | 16 | #include <asm/arch/soc.h> |
Prafulla Wadaskar | 4efb77d | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 17 | #include <asm/arch/mpp.h> |
| 18 | |
| 19 | static 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 ARIBAUD | 9d86f0c | 2012-11-26 11:27:36 +0000 | [diff] [blame] | 35 | void kirkwood_mpp_conf(const u32 *mpp_list, u32 *mpp_save) |
Prafulla Wadaskar | 4efb77d | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 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); |
Valentin Longchamp | 8f5d7a0 | 2012-06-01 01:30:59 +0000 | [diff] [blame] | 56 | unsigned int sel_save; |
Prafulla Wadaskar | 4efb77d | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 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; |
Valentin Longchamp | 8f5d7a0 | 2012-06-01 01:30:59 +0000 | [diff] [blame] | 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 | |
Prafulla Wadaskar | 4efb77d | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 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 | } |