]>
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
;
40 writel(1 << gpio
, ®s
->gpiodata
[DATA_REG_ADDR(gpio
)]);
42 writel(0, ®s
->gpiodata
[DATA_REG_ADDR(gpio
)]);
47 int gpio_get_value(unsigned gpio
)
49 struct gpio_regs
*regs
= (struct gpio_regs
*)CONFIG_GPIO_BASE
;
52 val
= readl(®s
->gpiodata
[DATA_REG_ADDR(gpio
)]);
57 int gpio_request(unsigned gpio
, const char *label
)
59 if (gpio
>= SPEAR_GPIO_COUNT
)
65 int gpio_free(unsigned gpio
)
70 void gpio_toggle_value(unsigned gpio
)
72 gpio_set_value(gpio
, !gpio_get_value(gpio
));
75 int gpio_direction_input(unsigned gpio
)
77 return gpio_direction(gpio
, GPIO_DIRECTION_IN
);
80 int gpio_direction_output(unsigned gpio
, int value
)
82 int ret
= gpio_direction(gpio
, GPIO_DIRECTION_OUT
);
87 gpio_set_value(gpio
, value
);