blob: 8bfbc3a585b0ce91616647192228ee50760f7bd5 [file] [log] [blame]
Ajay Bhargav0c442292011-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 Denk1a459662013-07-08 09:37:19 +02009 * SPDX-License-Identifier: GPL-2.0+
Ajay Bhargav0c442292011-08-22 17:57:38 +053010 */
11
12#include <common.h>
13#include <asm/io.h>
Masahiro Yamada1221ce42016-09-21 11:28:55 +090014#include <linux/errno.h>
Ajay Bhargav0c442292011-08-22 17:57:38 +053015#include "mvgpio.h"
16#include <asm/gpio.h>
17
18#ifndef MV_MAX_GPIO
19#define MV_MAX_GPIO 128
20#endif
21
Joe Hershberger365d6072011-11-11 15:55:36 -060022int gpio_request(unsigned gpio, const char *label)
Ajay Bhargav0c442292011-08-22 17:57:38 +053023{
Joe Hershberger365d6072011-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 Bhargav0c442292011-08-22 17:57:38 +053027 }
28 return 0;
29}
30
Joe Hershberger365d6072011-11-11 15:55:36 -060031int gpio_free(unsigned gpio)
Ajay Bhargav0c442292011-08-22 17:57:38 +053032{
Ajay Bhargav0c442292011-08-22 17:57:38 +053033 return 0;
34}
35
Joe Hershberger365d6072011-11-11 15:55:36 -060036int gpio_direction_input(unsigned gpio)
Ajay Bhargav0c442292011-08-22 17:57:38 +053037{
38 struct gpio_reg *gpio_reg_bank;
39
Joe Hershberger365d6072011-11-11 15:55:36 -060040 if (gpio >= MV_MAX_GPIO) {
41 printf("%s: Invalid GPIO %d\n", __func__, gpio);
42 return -1;
Ajay Bhargav0c442292011-08-22 17:57:38 +053043 }
44
Joe Hershberger365d6072011-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 Bhargav0c442292011-08-22 17:57:38 +053047 return 0;
48}
49
Joe Hershberger365d6072011-11-11 15:55:36 -060050int gpio_direction_output(unsigned gpio, int value)
Ajay Bhargav0c442292011-08-22 17:57:38 +053051{
52 struct gpio_reg *gpio_reg_bank;
Ajay Bhargav0c442292011-08-22 17:57:38 +053053
Joe Hershberger365d6072011-11-11 15:55:36 -060054 if (gpio >= MV_MAX_GPIO) {
55 printf("%s: Invalid GPIO %d\n", __func__, gpio);
56 return -1;
Ajay Bhargav0c442292011-08-22 17:57:38 +053057 }
58
Joe Hershberger365d6072011-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);
62 return 0;
Ajay Bhargav0c442292011-08-22 17:57:38 +053063}
64
Joe Hershberger365d6072011-11-11 15:55:36 -060065int gpio_get_value(unsigned gpio)
66{
67 struct gpio_reg *gpio_reg_bank;
68 u32 gpio_val;
69
70 if (gpio >= MV_MAX_GPIO) {
71 printf("%s: Invalid GPIO %d\n", __func__, gpio);
72 return -1;
73 }
74
75 gpio_reg_bank = get_gpio_base(GPIO_TO_REG(gpio));
76 gpio_val = readl(&gpio_reg_bank->gplr);
77
78 return GPIO_VAL(gpio, gpio_val);
79}
80
81int gpio_set_value(unsigned gpio, int value)
Ajay Bhargav0c442292011-08-22 17:57:38 +053082{
83 struct gpio_reg *gpio_reg_bank;
84
Joe Hershberger365d6072011-11-11 15:55:36 -060085 if (gpio >= MV_MAX_GPIO) {
86 printf("%s: Invalid GPIO %d\n", __func__, gpio);
87 return -1;
Ajay Bhargav0c442292011-08-22 17:57:38 +053088 }
89
Joe Hershberger365d6072011-11-11 15:55:36 -060090 gpio_reg_bank = get_gpio_base(GPIO_TO_REG(gpio));
Ajay Bhargav0c442292011-08-22 17:57:38 +053091 if (value)
Joe Hershberger365d6072011-11-11 15:55:36 -060092 writel(GPIO_TO_BIT(gpio), &gpio_reg_bank->gpsr);
Ajay Bhargav0c442292011-08-22 17:57:38 +053093 else
Joe Hershberger365d6072011-11-11 15:55:36 -060094 writel(GPIO_TO_BIT(gpio), &gpio_reg_bank->gpcr);
95
96 return 0;
Ajay Bhargav0c442292011-08-22 17:57:38 +053097}