Nicolas Pitre | 0100def | 2009-01-30 22:44:20 -0500 | [diff] [blame] | 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 | |
| 20 | static unsigned int __init kirkwood_variant(void) |
| 21 | { |
| 22 | u32 dev, rev; |
| 23 | |
| 24 | kirkwood_pcie_id(&dev, &rev); |
| 25 | |
Saeed Bishara | 1e4d2d3 | 2010-06-01 18:09:27 +0300 | [diff] [blame] | 26 | if ((dev == MV88F6281_DEV_ID && rev >= MV88F6281_REV_A0) || |
| 27 | (dev == MV88F6282_DEV_ID)) |
Nicolas Pitre | 0100def | 2009-01-30 22:44:20 -0500 | [diff] [blame] | 28 | return MPP_F6281_MASK; |
| 29 | if (dev == MV88F6192_DEV_ID && rev >= MV88F6192_REV_A0) |
| 30 | return MPP_F6192_MASK; |
| 31 | if (dev == MV88F6180_DEV_ID) |
| 32 | return MPP_F6180_MASK; |
| 33 | |
| 34 | printk(KERN_ERR "MPP setup: unknown kirkwood variant " |
| 35 | "(dev %#x rev %#x)\n", dev, rev); |
| 36 | return 0; |
| 37 | } |
| 38 | |
| 39 | #define MPP_CTRL(i) (DEV_BUS_VIRT_BASE + (i) * 4) |
| 40 | #define MPP_NR_REGS (1 + MPP_MAX/8) |
| 41 | |
| 42 | void __init kirkwood_mpp_conf(unsigned int *mpp_list) |
| 43 | { |
| 44 | u32 mpp_ctrl[MPP_NR_REGS]; |
| 45 | unsigned int variant_mask; |
| 46 | int i; |
| 47 | |
| 48 | variant_mask = kirkwood_variant(); |
| 49 | if (!variant_mask) |
| 50 | return; |
| 51 | |
Erik Benada | a886565 | 2009-05-28 17:08:55 -0700 | [diff] [blame] | 52 | /* Initialize gpiolib. */ |
| 53 | orion_gpio_init(); |
| 54 | |
Nicolas Pitre | 0100def | 2009-01-30 22:44:20 -0500 | [diff] [blame] | 55 | printk(KERN_DEBUG "initial MPP regs:"); |
| 56 | for (i = 0; i < MPP_NR_REGS; i++) { |
| 57 | mpp_ctrl[i] = readl(MPP_CTRL(i)); |
| 58 | printk(" %08x", mpp_ctrl[i]); |
| 59 | } |
| 60 | printk("\n"); |
| 61 | |
Mike Rapoport | 7350f41 | 2010-11-03 17:22:00 +0200 | [diff] [blame] | 62 | for ( ; *mpp_list; mpp_list++) { |
Nicolas Pitre | 0100def | 2009-01-30 22:44:20 -0500 | [diff] [blame] | 63 | unsigned int num = MPP_NUM(*mpp_list); |
| 64 | unsigned int sel = MPP_SEL(*mpp_list); |
| 65 | int shift, gpio_mode; |
| 66 | |
| 67 | if (num > MPP_MAX) { |
| 68 | printk(KERN_ERR "kirkwood_mpp_conf: invalid MPP " |
| 69 | "number (%u)\n", num); |
| 70 | continue; |
| 71 | } |
| 72 | if (!(*mpp_list & variant_mask)) { |
| 73 | printk(KERN_WARNING |
| 74 | "kirkwood_mpp_conf: requested MPP%u config " |
| 75 | "unavailable on this hardware\n", num); |
| 76 | continue; |
| 77 | } |
| 78 | |
| 79 | shift = (num & 7) << 2; |
| 80 | mpp_ctrl[num / 8] &= ~(0xf << shift); |
| 81 | mpp_ctrl[num / 8] |= sel << shift; |
| 82 | |
| 83 | gpio_mode = 0; |
| 84 | if (*mpp_list & MPP_INPUT_MASK) |
| 85 | gpio_mode |= GPIO_INPUT_OK; |
| 86 | if (*mpp_list & MPP_OUTPUT_MASK) |
| 87 | gpio_mode |= GPIO_OUTPUT_OK; |
| 88 | if (sel != 0) |
| 89 | gpio_mode = 0; |
| 90 | orion_gpio_set_valid(num, gpio_mode); |
Nicolas Pitre | 0100def | 2009-01-30 22:44:20 -0500 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | printk(KERN_DEBUG " final MPP regs:"); |
| 94 | for (i = 0; i < MPP_NR_REGS; i++) { |
| 95 | writel(mpp_ctrl[i], MPP_CTRL(i)); |
| 96 | printk(" %08x", mpp_ctrl[i]); |
| 97 | } |
| 98 | printk("\n"); |
| 99 | } |