2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
9 #include <linux/kernel.h>
10 #include <linux/module.h>
11 #include <linux/spinlock.h>
12 #include <bcm63xx_cpu.h>
13 #include <bcm63xx_gpio.h>
14 #include <bcm63xx_io.h>
15 #include <bcm63xx_regs.h>
17 static DEFINE_SPINLOCK(bcm63xx_gpio_lock
);
19 void bcm63xx_gpio_set_dataout(int gpio
, int val
)
26 if (gpio
>= BCM63XX_GPIO_COUNT
)
30 reg
= GPIO_DATA_LO_REG
;
33 reg
= GPIO_DATA_HI_REG
;
34 mask
= 1 << (gpio
- 32);
37 spin_lock_irqsave(&bcm63xx_gpio_lock
, flags
);
38 tmp
= bcm_gpio_readl(reg
);
43 bcm_gpio_writel(tmp
, reg
);
44 spin_unlock_irqrestore(&bcm63xx_gpio_lock
, flags
);
47 EXPORT_SYMBOL(bcm63xx_gpio_set_dataout
);
49 int bcm63xx_gpio_get_datain(int gpio
)
54 if (gpio
>= BCM63XX_GPIO_COUNT
)
58 reg
= GPIO_DATA_LO_REG
;
61 reg
= GPIO_DATA_HI_REG
;
62 mask
= 1 << (gpio
- 32);
65 return !!(bcm_gpio_readl(reg
) & mask
);
68 EXPORT_SYMBOL(bcm63xx_gpio_get_datain
);
70 void bcm63xx_gpio_set_direction(int gpio
, int dir
)
77 if (gpio
>= BCM63XX_GPIO_COUNT
)
81 reg
= GPIO_CTL_LO_REG
;
84 reg
= GPIO_CTL_HI_REG
;
85 mask
= 1 << (gpio
- 32);
88 spin_lock_irqsave(&bcm63xx_gpio_lock
, flags
);
89 tmp
= bcm_gpio_readl(reg
);
90 if (dir
== GPIO_DIR_IN
)
94 bcm_gpio_writel(tmp
, reg
);
95 spin_unlock_irqrestore(&bcm63xx_gpio_lock
, flags
);
98 EXPORT_SYMBOL(bcm63xx_gpio_set_direction
);