2011-08-22 12:27:38 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2011
|
|
|
|
* eInfochips Ltd. <www.einfochips.com>
|
2016-12-21 07:58:06 +00:00
|
|
|
* Written-by: Ajay Bhargav <contact@8051projects.net>
|
2011-08-22 12:27:38 +00:00
|
|
|
*
|
|
|
|
* (C) Copyright 2010
|
|
|
|
* Marvell Semiconductor <www.marvell.com>
|
|
|
|
*
|
2013-07-08 07:37:19 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2011-08-22 12:27:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <asm/io.h>
|
2016-09-21 02:28:55 +00:00
|
|
|
#include <linux/errno.h>
|
2011-08-22 12:27:38 +00:00
|
|
|
#include "mvgpio.h"
|
|
|
|
#include <asm/gpio.h>
|
|
|
|
|
|
|
|
#ifndef MV_MAX_GPIO
|
|
|
|
#define MV_MAX_GPIO 128
|
|
|
|
#endif
|
|
|
|
|
2011-11-11 21:55:36 +00:00
|
|
|
int gpio_request(unsigned gpio, const char *label)
|
2011-08-22 12:27:38 +00:00
|
|
|
{
|
2011-11-11 21:55:36 +00:00
|
|
|
if (gpio >= MV_MAX_GPIO) {
|
|
|
|
printf("%s: Invalid GPIO requested %d\n", __func__, gpio);
|
|
|
|
return -1;
|
2011-08-22 12:27:38 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-11-11 21:55:36 +00:00
|
|
|
int gpio_free(unsigned gpio)
|
2011-08-22 12:27:38 +00:00
|
|
|
{
|
2011-11-11 21:55:36 +00:00
|
|
|
return 0;
|
2011-08-22 12:27:38 +00:00
|
|
|
}
|
|
|
|
|
2011-11-11 21:55:36 +00:00
|
|
|
int gpio_direction_input(unsigned gpio)
|
2011-08-22 12:27:38 +00:00
|
|
|
{
|
|
|
|
struct gpio_reg *gpio_reg_bank;
|
|
|
|
|
2011-11-11 21:55:36 +00:00
|
|
|
if (gpio >= MV_MAX_GPIO) {
|
|
|
|
printf("%s: Invalid GPIO %d\n", __func__, gpio);
|
|
|
|
return -1;
|
2011-08-22 12:27:38 +00:00
|
|
|
}
|
|
|
|
|
2011-11-11 21:55:36 +00:00
|
|
|
gpio_reg_bank = get_gpio_base(GPIO_TO_REG(gpio));
|
|
|
|
writel(GPIO_TO_BIT(gpio), &gpio_reg_bank->gcdr);
|
2011-08-22 12:27:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-11-11 21:55:36 +00:00
|
|
|
int gpio_direction_output(unsigned gpio, int value)
|
2011-08-22 12:27:38 +00:00
|
|
|
{
|
|
|
|
struct gpio_reg *gpio_reg_bank;
|
|
|
|
|
2011-11-11 21:55:36 +00:00
|
|
|
if (gpio >= MV_MAX_GPIO) {
|
|
|
|
printf("%s: Invalid GPIO %d\n", __func__, gpio);
|
|
|
|
return -1;
|
2011-08-22 12:27:38 +00:00
|
|
|
}
|
|
|
|
|
2011-11-11 21:55:36 +00:00
|
|
|
gpio_reg_bank = get_gpio_base(GPIO_TO_REG(gpio));
|
|
|
|
writel(GPIO_TO_BIT(gpio), &gpio_reg_bank->gsdr);
|
|
|
|
gpio_set_value(gpio, value);
|
2011-08-22 12:27:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-11-11 21:55:36 +00:00
|
|
|
int gpio_get_value(unsigned gpio)
|
2011-08-22 12:27:38 +00:00
|
|
|
{
|
|
|
|
struct gpio_reg *gpio_reg_bank;
|
2011-11-11 21:55:36 +00:00
|
|
|
u32 gpio_val;
|
2011-08-22 12:27:38 +00:00
|
|
|
|
2011-11-11 21:55:36 +00:00
|
|
|
if (gpio >= MV_MAX_GPIO) {
|
|
|
|
printf("%s: Invalid GPIO %d\n", __func__, gpio);
|
|
|
|
return -1;
|
2011-08-22 12:27:38 +00:00
|
|
|
}
|
|
|
|
|
2011-11-11 21:55:36 +00:00
|
|
|
gpio_reg_bank = get_gpio_base(GPIO_TO_REG(gpio));
|
|
|
|
gpio_val = readl(&gpio_reg_bank->gplr);
|
2011-08-22 12:27:38 +00:00
|
|
|
|
2011-11-11 21:55:36 +00:00
|
|
|
return GPIO_VAL(gpio, gpio_val);
|
2011-08-22 12:27:38 +00:00
|
|
|
}
|
|
|
|
|
2011-11-11 21:55:36 +00:00
|
|
|
int gpio_set_value(unsigned gpio, int value)
|
2011-08-22 12:27:38 +00:00
|
|
|
{
|
|
|
|
struct gpio_reg *gpio_reg_bank;
|
|
|
|
|
2011-11-11 21:55:36 +00:00
|
|
|
if (gpio >= MV_MAX_GPIO) {
|
|
|
|
printf("%s: Invalid GPIO %d\n", __func__, gpio);
|
|
|
|
return -1;
|
2011-08-22 12:27:38 +00:00
|
|
|
}
|
|
|
|
|
2011-11-11 21:55:36 +00:00
|
|
|
gpio_reg_bank = get_gpio_base(GPIO_TO_REG(gpio));
|
2011-08-22 12:27:38 +00:00
|
|
|
if (value)
|
2011-11-11 21:55:36 +00:00
|
|
|
writel(GPIO_TO_BIT(gpio), &gpio_reg_bank->gpsr);
|
2011-08-22 12:27:38 +00:00
|
|
|
else
|
2011-11-11 21:55:36 +00:00
|
|
|
writel(GPIO_TO_BIT(gpio), &gpio_reg_bank->gpcr);
|
|
|
|
|
|
|
|
return 0;
|
2011-08-22 12:27:38 +00:00
|
|
|
}
|