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