blob: ea2f689d60ef334029180e50d5eee4152efb3b14 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Ajay Bhargav0c442292011-08-22 17:57:38 +05302/*
3 * (C) Copyright 2011
4 * eInfochips Ltd. <www.einfochips.com>
Ajay Bhargavc7c47ca2016-12-21 13:28:06 +05305 * Written-by: Ajay Bhargav <contact@8051projects.net>
Ajay Bhargav0c442292011-08-22 17:57:38 +05306 *
7 * (C) Copyright 2010
8 * Marvell Semiconductor <www.marvell.com>
Ajay Bhargav0c442292011-08-22 17:57:38 +05309 */
10
11#include <common.h>
12#include <asm/io.h>
Masahiro Yamada1221ce42016-09-21 11:28:55 +090013#include <linux/errno.h>
Ajay Bhargav0c442292011-08-22 17:57:38 +053014#include "mvgpio.h"
15#include <asm/gpio.h>
16
17#ifndef MV_MAX_GPIO
18#define MV_MAX_GPIO 128
19#endif
20
Joe Hershberger365d6072011-11-11 15:55:36 -060021int gpio_request(unsigned gpio, const char *label)
Ajay Bhargav0c442292011-08-22 17:57:38 +053022{
Joe Hershberger365d6072011-11-11 15:55:36 -060023 if (gpio >= MV_MAX_GPIO) {
24 printf("%s: Invalid GPIO requested %d\n", __func__, gpio);
25 return -1;
Ajay Bhargav0c442292011-08-22 17:57:38 +053026 }
27 return 0;
28}
29
Joe Hershberger365d6072011-11-11 15:55:36 -060030int gpio_free(unsigned gpio)
Ajay Bhargav0c442292011-08-22 17:57:38 +053031{
Ajay Bhargav0c442292011-08-22 17:57:38 +053032 return 0;
33}
34
Joe Hershberger365d6072011-11-11 15:55:36 -060035int gpio_direction_input(unsigned gpio)
Ajay Bhargav0c442292011-08-22 17:57:38 +053036{
37 struct gpio_reg *gpio_reg_bank;
38
Joe Hershberger365d6072011-11-11 15:55:36 -060039 if (gpio >= MV_MAX_GPIO) {
40 printf("%s: Invalid GPIO %d\n", __func__, gpio);
41 return -1;
Ajay Bhargav0c442292011-08-22 17:57:38 +053042 }
43
Joe Hershberger365d6072011-11-11 15:55:36 -060044 gpio_reg_bank = get_gpio_base(GPIO_TO_REG(gpio));
45 writel(GPIO_TO_BIT(gpio), &gpio_reg_bank->gcdr);
Ajay Bhargav0c442292011-08-22 17:57:38 +053046 return 0;
47}
48
Joe Hershberger365d6072011-11-11 15:55:36 -060049int gpio_direction_output(unsigned gpio, int value)
Ajay Bhargav0c442292011-08-22 17:57:38 +053050{
51 struct gpio_reg *gpio_reg_bank;
Ajay Bhargav0c442292011-08-22 17:57:38 +053052
Joe Hershberger365d6072011-11-11 15:55:36 -060053 if (gpio >= MV_MAX_GPIO) {
54 printf("%s: Invalid GPIO %d\n", __func__, gpio);
55 return -1;
Ajay Bhargav0c442292011-08-22 17:57:38 +053056 }
57
Joe Hershberger365d6072011-11-11 15:55:36 -060058 gpio_reg_bank = get_gpio_base(GPIO_TO_REG(gpio));
59 writel(GPIO_TO_BIT(gpio), &gpio_reg_bank->gsdr);
60 gpio_set_value(gpio, value);
61 return 0;
Ajay Bhargav0c442292011-08-22 17:57:38 +053062}
63
Joe Hershberger365d6072011-11-11 15:55:36 -060064int gpio_get_value(unsigned gpio)
65{
66 struct gpio_reg *gpio_reg_bank;
67 u32 gpio_val;
68
69 if (gpio >= MV_MAX_GPIO) {
70 printf("%s: Invalid GPIO %d\n", __func__, gpio);
71 return -1;
72 }
73
74 gpio_reg_bank = get_gpio_base(GPIO_TO_REG(gpio));
75 gpio_val = readl(&gpio_reg_bank->gplr);
76
77 return GPIO_VAL(gpio, gpio_val);
78}
79
80int gpio_set_value(unsigned gpio, int value)
Ajay Bhargav0c442292011-08-22 17:57:38 +053081{
82 struct gpio_reg *gpio_reg_bank;
83
Joe Hershberger365d6072011-11-11 15:55:36 -060084 if (gpio >= MV_MAX_GPIO) {
85 printf("%s: Invalid GPIO %d\n", __func__, gpio);
86 return -1;
Ajay Bhargav0c442292011-08-22 17:57:38 +053087 }
88
Joe Hershberger365d6072011-11-11 15:55:36 -060089 gpio_reg_bank = get_gpio_base(GPIO_TO_REG(gpio));
Ajay Bhargav0c442292011-08-22 17:57:38 +053090 if (value)
Joe Hershberger365d6072011-11-11 15:55:36 -060091 writel(GPIO_TO_BIT(gpio), &gpio_reg_bank->gpsr);
Ajay Bhargav0c442292011-08-22 17:57:38 +053092 else
Joe Hershberger365d6072011-11-11 15:55:36 -060093 writel(GPIO_TO_BIT(gpio), &gpio_reg_bank->gpcr);
94
95 return 0;
Ajay Bhargav0c442292011-08-22 17:57:38 +053096}