aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-kirkwood/mpp.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm/mach-kirkwood/mpp.c')
-rw-r--r--arch/arm/mach-kirkwood/mpp.c97
1 files changed, 97 insertions, 0 deletions
diff --git a/arch/arm/mach-kirkwood/mpp.c b/arch/arm/mach-kirkwood/mpp.c
new file mode 100644
index 000000000000..63c44934391a
--- /dev/null
+++ b/arch/arm/mach-kirkwood/mpp.c
@@ -0,0 +1,97 @@
1/*
2 * arch/arm/mach-kirkwood/mpp.c
3 *
4 * MPP functions for Marvell Kirkwood SoCs
5 *
6 * This file is licensed under the terms of the GNU General Public
7 * License version 2. This program is licensed "as is" without any
8 * warranty of any kind, whether express or implied.
9 */
10
11#include <linux/kernel.h>
12#include <linux/init.h>
13#include <linux/mbus.h>
14#include <linux/io.h>
15#include <asm/gpio.h>
16#include <mach/hardware.h>
17#include "common.h"
18#include "mpp.h"
19
20static unsigned int __init kirkwood_variant(void)
21{
22 u32 dev, rev;
23
24 kirkwood_pcie_id(&dev, &rev);
25
26 if (dev == MV88F6281_DEV_ID && rev >= MV88F6281_REV_A0)
27 return MPP_F6281_MASK;
28 if (dev == MV88F6192_DEV_ID && rev >= MV88F6192_REV_A0)
29 return MPP_F6192_MASK;
30 if (dev == MV88F6180_DEV_ID)
31 return MPP_F6180_MASK;
32
33 printk(KERN_ERR "MPP setup: unknown kirkwood variant "
34 "(dev %#x rev %#x)\n", dev, rev);
35 return 0;
36}
37
38#define MPP_CTRL(i) (DEV_BUS_VIRT_BASE + (i) * 4)
39#define MPP_NR_REGS (1 + MPP_MAX/8)
40
41void __init kirkwood_mpp_conf(unsigned int *mpp_list)
42{
43 u32 mpp_ctrl[MPP_NR_REGS];
44 unsigned int variant_mask;
45 int i;
46
47 variant_mask = kirkwood_variant();
48 if (!variant_mask)
49 return;
50
51 printk(KERN_DEBUG "initial MPP regs:");
52 for (i = 0; i < MPP_NR_REGS; i++) {
53 mpp_ctrl[i] = readl(MPP_CTRL(i));
54 printk(" %08x", mpp_ctrl[i]);
55 }
56 printk("\n");
57
58 while (*mpp_list) {
59 unsigned int num = MPP_NUM(*mpp_list);
60 unsigned int sel = MPP_SEL(*mpp_list);
61 int shift, gpio_mode;
62
63 if (num > MPP_MAX) {
64 printk(KERN_ERR "kirkwood_mpp_conf: invalid MPP "
65 "number (%u)\n", num);
66 continue;
67 }
68 if (!(*mpp_list & variant_mask)) {
69 printk(KERN_WARNING
70 "kirkwood_mpp_conf: requested MPP%u config "
71 "unavailable on this hardware\n", num);
72 continue;
73 }
74
75 shift = (num & 7) << 2;
76 mpp_ctrl[num / 8] &= ~(0xf << shift);
77 mpp_ctrl[num / 8] |= sel << shift;
78
79 gpio_mode = 0;
80 if (*mpp_list & MPP_INPUT_MASK)
81 gpio_mode |= GPIO_INPUT_OK;
82 if (*mpp_list & MPP_OUTPUT_MASK)
83 gpio_mode |= GPIO_OUTPUT_OK;
84 if (sel != 0)
85 gpio_mode = 0;
86 orion_gpio_set_valid(num, gpio_mode);
87
88 mpp_list++;
89 }
90
91 printk(KERN_DEBUG " final MPP regs:");
92 for (i = 0; i < MPP_NR_REGS; i++) {
93 writel(mpp_ctrl[i], MPP_CTRL(i));
94 printk(" %08x", mpp_ctrl[i]);
95 }
96 printk("\n");
97}