06f48328e4e1235cfef5eef75ba5d423ca5608bb
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files / arch / mips / ar71xx / mach-rb750.c
1 /*
2 * MikroTik RouterBOARD 750 support
3 *
4 * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
9 */
10
11 #include <asm/mach-ar71xx/ar71xx.h>
12 #include <asm/mach-ar71xx/mach-rb750.h>
13
14 #include "machtype.h"
15 #include "dev-ap91-eth.h"
16
17 int rb750_latch_change(u32 mask_clr, u32 mask_set)
18 {
19 static DEFINE_SPINLOCK(lock);
20 static u32 latch_set = RB750_LED_BITS | RB750_LVC573_LE;
21 static u32 latch_oe;
22 static u32 latch_clr;
23 unsigned long flags;
24 u32 t;
25 int ret = 0;
26
27 spin_lock_irqsave(&lock, flags);
28
29 if ((mask_clr & BIT(31)) != 0 &&
30 (latch_set & RB750_LVC573_LE) == 0) {
31 goto unlock;
32 }
33
34 latch_set = (latch_set | mask_set) & ~mask_clr;
35 latch_clr = (latch_clr | mask_clr) & ~mask_set;
36
37 if (latch_oe == 0)
38 latch_oe = __raw_readl(ar71xx_gpio_base + GPIO_REG_OE);
39
40 if (likely(latch_set & RB750_LVC573_LE)) {
41 void __iomem *base = ar71xx_gpio_base;
42
43 t = __raw_readl(base + GPIO_REG_OE);
44 t |= mask_clr | latch_oe | mask_set;
45
46 __raw_writel(t, base + GPIO_REG_OE);
47 __raw_writel(latch_clr, base + GPIO_REG_CLEAR);
48 __raw_writel(latch_set, base + GPIO_REG_SET);
49 } else if (mask_clr & RB750_LVC573_LE) {
50 void __iomem *base = ar71xx_gpio_base;
51
52 latch_oe = __raw_readl(base + GPIO_REG_OE);
53 __raw_writel(RB750_LVC573_LE, base + GPIO_REG_CLEAR);
54 /* flush write */
55 __raw_readl(base + GPIO_REG_CLEAR);
56 }
57
58 ret = 1;
59
60 unlock:
61 spin_unlock_irqrestore(&lock, flags);
62 return ret;
63 }
64 EXPORT_SYMBOL_GPL(rb750_latch_change);
65
66 static void __init rb750_setup(void)
67 {
68 ap91_eth_init(NULL);
69 }
70
71 MIPS_MACHINE(AR71XX_MACH_RB_750, "750i", "MikroTik RouterBOARD 750",
72 rb750_setup);