]>
git.ipfire.org Git - thirdparty/u-boot.git/blob - drivers/gpio/spear_gpio.c
1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2012 Stefan Roese <sr@denx.de>
7 * Driver for SPEAr600 GPIO controller
11 #include <asm/arch/hardware.h>
16 static int gpio_direction(unsigned gpio
,
17 enum gpio_direction direction
)
19 struct gpio_regs
*regs
= (struct gpio_regs
*)CONFIG_GPIO_BASE
;
22 val
= readl(®s
->gpiodir
);
24 if (direction
== GPIO_DIRECTION_OUT
)
29 writel(val
, ®s
->gpiodir
);
34 int gpio_set_value(unsigned gpio
, int value
)
36 struct gpio_regs
*regs
= (struct gpio_regs
*)CONFIG_GPIO_BASE
;
39 writel(1 << gpio
, ®s
->gpiodata
[DATA_REG_ADDR(gpio
)]);
41 writel(0, ®s
->gpiodata
[DATA_REG_ADDR(gpio
)]);
46 int gpio_get_value(unsigned gpio
)
48 struct gpio_regs
*regs
= (struct gpio_regs
*)CONFIG_GPIO_BASE
;
51 val
= readl(®s
->gpiodata
[DATA_REG_ADDR(gpio
)]);
56 int gpio_request(unsigned gpio
, const char *label
)
58 if (gpio
>= SPEAR_GPIO_COUNT
)
64 int gpio_free(unsigned gpio
)
69 void gpio_toggle_value(unsigned gpio
)
71 gpio_set_value(gpio
, !gpio_get_value(gpio
));
74 int gpio_direction_input(unsigned gpio
)
76 return gpio_direction(gpio
, GPIO_DIRECTION_IN
);
79 int gpio_direction_output(unsigned gpio
, int value
)
81 int ret
= gpio_direction(gpio
, GPIO_DIRECTION_OUT
);
86 gpio_set_value(gpio
, value
);