]> git.ipfire.org Git - people/ms/u-boot.git/blame - drivers/gpio/mvgpio.c
gpio: mvebu_gpio: Add missing out value set to gpio_direction_output()
[people/ms/u-boot.git] / drivers / gpio / mvgpio.c
CommitLineData
0c442298
AB
1/*
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 *
1a459660 9 * SPDX-License-Identifier: GPL-2.0+
0c442298
AB
10 */
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
365d6070 22int gpio_request(unsigned gpio, const char *label)
0c442298 23{
365d6070
JH
24 if (gpio >= MV_MAX_GPIO) {
25 printf("%s: Invalid GPIO requested %d\n", __func__, gpio);
26 return -1;
0c442298
AB
27 }
28 return 0;
29}
30
365d6070 31int gpio_free(unsigned gpio)
0c442298 32{
365d6070 33 return 0;
0c442298
AB
34}
35
365d6070 36int gpio_direction_input(unsigned gpio)
0c442298
AB
37{
38 struct gpio_reg *gpio_reg_bank;
39
365d6070
JH
40 if (gpio >= MV_MAX_GPIO) {
41 printf("%s: Invalid GPIO %d\n", __func__, gpio);
42 return -1;
0c442298
AB
43 }
44
365d6070
JH
45 gpio_reg_bank = get_gpio_base(GPIO_TO_REG(gpio));
46 writel(GPIO_TO_BIT(gpio), &gpio_reg_bank->gcdr);
0c442298
AB
47 return 0;
48}
49
365d6070 50int gpio_direction_output(unsigned gpio, int value)
0c442298
AB
51{
52 struct gpio_reg *gpio_reg_bank;
53
365d6070
JH
54 if (gpio >= MV_MAX_GPIO) {
55 printf("%s: Invalid GPIO %d\n", __func__, gpio);
56 return -1;
0c442298
AB
57 }
58
365d6070
JH
59 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);
0c442298
AB
62 return 0;
63}
64
365d6070 65int gpio_get_value(unsigned gpio)
0c442298
AB
66{
67 struct gpio_reg *gpio_reg_bank;
365d6070 68 u32 gpio_val;
0c442298 69
365d6070
JH
70 if (gpio >= MV_MAX_GPIO) {
71 printf("%s: Invalid GPIO %d\n", __func__, gpio);
72 return -1;
0c442298
AB
73 }
74
365d6070
JH
75 gpio_reg_bank = get_gpio_base(GPIO_TO_REG(gpio));
76 gpio_val = readl(&gpio_reg_bank->gplr);
0c442298 77
365d6070 78 return GPIO_VAL(gpio, gpio_val);
0c442298
AB
79}
80
365d6070 81int gpio_set_value(unsigned gpio, int value)
0c442298
AB
82{
83 struct gpio_reg *gpio_reg_bank;
84
365d6070
JH
85 if (gpio >= MV_MAX_GPIO) {
86 printf("%s: Invalid GPIO %d\n", __func__, gpio);
87 return -1;
0c442298
AB
88 }
89
365d6070 90 gpio_reg_bank = get_gpio_base(GPIO_TO_REG(gpio));
0c442298 91 if (value)
365d6070 92 writel(GPIO_TO_BIT(gpio), &gpio_reg_bank->gpsr);
0c442298 93 else
365d6070
JH
94 writel(GPIO_TO_BIT(gpio), &gpio_reg_bank->gpcr);
95
96 return 0;
0c442298 97}