/*
 * arch/arm/mach-discovery/gpio.c
 *
 * GPIO functions for Marvell Discovery SoCs
 *
 * This file is licensed under the terms of the GNU General Public
 * License version 2.  This program is licensed "as is" without any
 * warranty of any kind, whether express or implied.
 */

#include <common.h>
#include <asm/arch/discovery.h>
#include <asm/arch/gpio.h>

/*
 * disco_config_gpio - GPIO configuration
 */
void disco_config_gpio(u32 gpp_oe_val, u32 gpp_oe)
{
	struct discogpio_registers *gpioreg =
		(struct discogpio_registers *)DISCO_GPIO_BASE;

	/* Init GPIOS to default values as per board requirement */
	writel(gpp_oe_val, &gpioreg->dout);
	writel(gpp_oe, &gpioreg->oe);
}

u32 disco_get_gpio(u32 gpp)
{
	struct discogpio_registers *gpioreg =
		(struct discogpio_registers *)DISCO_GPIO_BASE;

	u32 gppBit = gpp%32;
	u32 gppMask=(1<<gppBit);
	u32 value;

	value = readl(&gpioreg->din);
	value = (value & gppMask) >> gppBit;

	return value;
}

void disco_set_gpio(u32 gpp, u32 bit)
{
	struct discogpio_registers *gpioreg =
		(struct discogpio_registers *)DISCO_GPIO_BASE;

	u32 gppBit = gpp%32;
	u32 gppMask=(1<<gppBit);

	if ((bit&1) == 0)
		writel(gppMask, &gpioreg->dout_clear);
	else
		writel(gppMask, &gpioreg->dout_set);

	return;
}
