blob: 888aa07c4cc2ace9a415534c97cb8d207407cad6 [file] [log] [blame]
Ajay Bhargavf56ba5d2011-08-22 17:57:38 +05301/*
2 * (C) Copyright 2011
3 * eInfochips Ltd. <www.einfochips.com>
4 * Written-by: Ajay Bhargav <ajay.bhargav@einfochips.com>
5 *
6 * (C) Copyright 2010
7 * Marvell Semiconductor <www.marvell.com>
8 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02009 * SPDX-License-Identifier: GPL-2.0+
Ajay Bhargavf56ba5d2011-08-22 17:57:38 +053010 */
11
12#include <common.h>
13#include <asm/io.h>
14#include <asm/errno.h>
15#include "mvgpio.h"
16#include <asm/gpio.h>
17
18#ifndef MV_MAX_GPIO
19#define MV_MAX_GPIO 128
20#endif
21
Joe Hershbergerf8928f12011-11-11 15:55:36 -060022int gpio_request(unsigned gpio, const char *label)
Ajay Bhargavf56ba5d2011-08-22 17:57:38 +053023{
Joe Hershbergerf8928f12011-11-11 15:55:36 -060024 if (gpio >= MV_MAX_GPIO) {
25 printf("%s: Invalid GPIO requested %d\n", __func__, gpio);
26 return -1;
Ajay Bhargavf56ba5d2011-08-22 17:57:38 +053027 }
28 return 0;
29}
30
Joe Hershbergerf8928f12011-11-11 15:55:36 -060031int gpio_free(unsigned gpio)
Ajay Bhargavf56ba5d2011-08-22 17:57:38 +053032{
Joe Hershbergerf8928f12011-11-11 15:55:36 -060033 return 0;
Ajay Bhargavf56ba5d2011-08-22 17:57:38 +053034}
35
Joe Hershbergerf8928f12011-11-11 15:55:36 -060036int gpio_direction_input(unsigned gpio)
Ajay Bhargavf56ba5d2011-08-22 17:57:38 +053037{
38 struct gpio_reg *gpio_reg_bank;
39
Joe Hershbergerf8928f12011-11-11 15:55:36 -060040 if (gpio >= MV_MAX_GPIO) {
41 printf("%s: Invalid GPIO %d\n", __func__, gpio);
42 return -1;
Ajay Bhargavf56ba5d2011-08-22 17:57:38 +053043 }
44
Joe Hershbergerf8928f12011-11-11 15:55:36 -060045 gpio_reg_bank = get_gpio_base(GPIO_TO_REG(gpio));
46 writel(GPIO_TO_BIT(gpio), &gpio_reg_bank->gcdr);
Ajay Bhargavf56ba5d2011-08-22 17:57:38 +053047 return 0;
48}
49
Joe Hershbergerf8928f12011-11-11 15:55:36 -060050int gpio_direction_output(unsigned gpio, int value)
Ajay Bhargavf56ba5d2011-08-22 17:57:38 +053051{
52 struct gpio_reg *gpio_reg_bank;
53
Joe Hershbergerf8928f12011-11-11 15:55:36 -060054 if (gpio >= MV_MAX_GPIO) {
55 printf("%s: Invalid GPIO %d\n", __func__, gpio);
56 return -1;
Ajay Bhargavf56ba5d2011-08-22 17:57:38 +053057 }
58
Joe Hershbergerf8928f12011-11-11 15:55:36 -060059 gpio_reg_bank = get_gpio_base(GPIO_TO_REG(gpio));
60 writel(GPIO_TO_BIT(gpio), &gpio_reg_bank->gsdr);
61 gpio_set_value(gpio, value);
Ajay Bhargavf56ba5d2011-08-22 17:57:38 +053062 return 0;
63}
64
Joe Hershbergerf8928f12011-11-11 15:55:36 -060065int gpio_get_value(unsigned gpio)
Ajay Bhargavf56ba5d2011-08-22 17:57:38 +053066{
67 struct gpio_reg *gpio_reg_bank;
Joe Hershbergerf8928f12011-11-11 15:55:36 -060068 u32 gpio_val;
Ajay Bhargavf56ba5d2011-08-22 17:57:38 +053069
Joe Hershbergerf8928f12011-11-11 15:55:36 -060070 if (gpio >= MV_MAX_GPIO) {
71 printf("%s: Invalid GPIO %d\n", __func__, gpio);
72 return -1;
Ajay Bhargavf56ba5d2011-08-22 17:57:38 +053073 }
74
Joe Hershbergerf8928f12011-11-11 15:55:36 -060075 gpio_reg_bank = get_gpio_base(GPIO_TO_REG(gpio));
76 gpio_val = readl(&gpio_reg_bank->gplr);
Ajay Bhargavf56ba5d2011-08-22 17:57:38 +053077
Joe Hershbergerf8928f12011-11-11 15:55:36 -060078 return GPIO_VAL(gpio, gpio_val);
Ajay Bhargavf56ba5d2011-08-22 17:57:38 +053079}
80
Joe Hershbergerf8928f12011-11-11 15:55:36 -060081int gpio_set_value(unsigned gpio, int value)
Ajay Bhargavf56ba5d2011-08-22 17:57:38 +053082{
83 struct gpio_reg *gpio_reg_bank;
84
Joe Hershbergerf8928f12011-11-11 15:55:36 -060085 if (gpio >= MV_MAX_GPIO) {
86 printf("%s: Invalid GPIO %d\n", __func__, gpio);
87 return -1;
Ajay Bhargavf56ba5d2011-08-22 17:57:38 +053088 }
89
Joe Hershbergerf8928f12011-11-11 15:55:36 -060090 gpio_reg_bank = get_gpio_base(GPIO_TO_REG(gpio));
Ajay Bhargavf56ba5d2011-08-22 17:57:38 +053091 if (value)
Joe Hershbergerf8928f12011-11-11 15:55:36 -060092 writel(GPIO_TO_BIT(gpio), &gpio_reg_bank->gpsr);
Ajay Bhargavf56ba5d2011-08-22 17:57:38 +053093 else
Joe Hershbergerf8928f12011-11-11 15:55:36 -060094 writel(GPIO_TO_BIT(gpio), &gpio_reg_bank->gpcr);
95
96 return 0;
Ajay Bhargavf56ba5d2011-08-22 17:57:38 +053097}