]>
git.ipfire.org Git - people/ms/u-boot.git/blob - drivers/gpio/spear_gpio.c
2 * Copyright (C) 2012 Stefan Roese <sr@denx.de>
4 * SPDX-License-Identifier: GPL-2.0+
8 * Driver for SPEAr600 GPIO controller
12 #include <asm/arch/hardware.h>
17 static int gpio_direction(unsigned gpio
,
18 enum gpio_direction direction
)
20 struct gpio_regs
*regs
= (struct gpio_regs
*)CONFIG_GPIO_BASE
;
23 val
= readl(®s
->gpiodir
);
25 if (direction
== GPIO_DIRECTION_OUT
)
30 writel(val
, ®s
->gpiodir
);
35 int gpio_set_value(unsigned gpio
, int value
)
37 struct gpio_regs
*regs
= (struct gpio_regs
*)CONFIG_GPIO_BASE
;
39 writel(1 << gpio
, ®s
->gpiodata
[DATA_REG_ADDR(gpio
)]);
44 int gpio_get_value(unsigned gpio
)
46 struct gpio_regs
*regs
= (struct gpio_regs
*)CONFIG_GPIO_BASE
;
49 val
= readl(®s
->gpiodata
[DATA_REG_ADDR(gpio
)]);
54 int gpio_request(unsigned gpio
, const char *label
)
56 if (gpio
>= SPEAR_GPIO_COUNT
)
62 int gpio_free(unsigned gpio
)
67 void gpio_toggle_value(unsigned gpio
)
69 gpio_set_value(gpio
, !gpio_get_value(gpio
));
72 int gpio_direction_input(unsigned gpio
)
74 return gpio_direction(gpio
, GPIO_DIRECTION_IN
);
77 int gpio_direction_output(unsigned gpio
, int value
)
79 int ret
= gpio_direction(gpio
, GPIO_DIRECTION_OUT
);
84 gpio_set_value(gpio
, value
);