mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-19 03:08:31 +00:00
83d290c56f
When U-Boot started using SPDX tags we were among the early adopters and there weren't a lot of other examples to borrow from. So we picked the area of the file that usually had a full license text and replaced it with an appropriate SPDX-License-Identifier: entry. Since then, the Linux Kernel has adopted SPDX tags and they place it as the very first line in a file (except where shebangs are used, then it's second line) and with slightly different comment styles than us. In part due to community overlap, in part due to better tag visibility and in part for other minor reasons, switch over to that style. This commit changes all instances where we have a single declared license in the tag as both the before and after are identical in tag contents. There's also a few places where I found we did not have a tag and have introduced one. Signed-off-by: Tom Rini <trini@konsulko.com>
135 lines
3.3 KiB
C
135 lines
3.3 KiB
C
// SPDX-License-Identifier: GPL-2.0+
|
|
/*
|
|
* (C) Copyright 2015 Google, Inc
|
|
*
|
|
* (C) Copyright 2008-2014 Rockchip Electronics
|
|
* Peter, Software Engineering, <superpeter.cai@gmail.com>.
|
|
*/
|
|
|
|
#include <common.h>
|
|
#include <dm.h>
|
|
#include <syscon.h>
|
|
#include <linux/errno.h>
|
|
#include <asm/gpio.h>
|
|
#include <asm/io.h>
|
|
#include <asm/arch/clock.h>
|
|
#include <dm/pinctrl.h>
|
|
#include <dt-bindings/clock/rk3288-cru.h>
|
|
|
|
enum {
|
|
ROCKCHIP_GPIOS_PER_BANK = 32,
|
|
};
|
|
|
|
#define OFFSET_TO_BIT(bit) (1UL << (bit))
|
|
|
|
struct rockchip_gpio_priv {
|
|
struct rockchip_gpio_regs *regs;
|
|
struct udevice *pinctrl;
|
|
int bank;
|
|
char name[2];
|
|
};
|
|
|
|
static int rockchip_gpio_direction_input(struct udevice *dev, unsigned offset)
|
|
{
|
|
struct rockchip_gpio_priv *priv = dev_get_priv(dev);
|
|
struct rockchip_gpio_regs *regs = priv->regs;
|
|
|
|
clrbits_le32(®s->swport_ddr, OFFSET_TO_BIT(offset));
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int rockchip_gpio_direction_output(struct udevice *dev, unsigned offset,
|
|
int value)
|
|
{
|
|
struct rockchip_gpio_priv *priv = dev_get_priv(dev);
|
|
struct rockchip_gpio_regs *regs = priv->regs;
|
|
int mask = OFFSET_TO_BIT(offset);
|
|
|
|
clrsetbits_le32(®s->swport_dr, mask, value ? mask : 0);
|
|
setbits_le32(®s->swport_ddr, mask);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int rockchip_gpio_get_value(struct udevice *dev, unsigned offset)
|
|
{
|
|
struct rockchip_gpio_priv *priv = dev_get_priv(dev);
|
|
struct rockchip_gpio_regs *regs = priv->regs;
|
|
|
|
return readl(®s->ext_port) & OFFSET_TO_BIT(offset) ? 1 : 0;
|
|
}
|
|
|
|
static int rockchip_gpio_set_value(struct udevice *dev, unsigned offset,
|
|
int value)
|
|
{
|
|
struct rockchip_gpio_priv *priv = dev_get_priv(dev);
|
|
struct rockchip_gpio_regs *regs = priv->regs;
|
|
int mask = OFFSET_TO_BIT(offset);
|
|
|
|
clrsetbits_le32(®s->swport_dr, mask, value ? mask : 0);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int rockchip_gpio_get_function(struct udevice *dev, unsigned offset)
|
|
{
|
|
#ifdef CONFIG_SPL_BUILD
|
|
return -ENODATA;
|
|
#else
|
|
struct rockchip_gpio_priv *priv = dev_get_priv(dev);
|
|
struct rockchip_gpio_regs *regs = priv->regs;
|
|
bool is_output;
|
|
int ret;
|
|
|
|
ret = pinctrl_get_gpio_mux(priv->pinctrl, priv->bank, offset);
|
|
if (ret)
|
|
return ret;
|
|
is_output = readl(®s->swport_ddr) & OFFSET_TO_BIT(offset);
|
|
|
|
return is_output ? GPIOF_OUTPUT : GPIOF_INPUT;
|
|
#endif
|
|
}
|
|
|
|
static int rockchip_gpio_probe(struct udevice *dev)
|
|
{
|
|
struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
|
|
struct rockchip_gpio_priv *priv = dev_get_priv(dev);
|
|
char *end;
|
|
int ret;
|
|
|
|
priv->regs = dev_read_addr_ptr(dev);
|
|
ret = uclass_first_device_err(UCLASS_PINCTRL, &priv->pinctrl);
|
|
if (ret)
|
|
return ret;
|
|
|
|
uc_priv->gpio_count = ROCKCHIP_GPIOS_PER_BANK;
|
|
end = strrchr(dev->name, '@');
|
|
priv->bank = trailing_strtoln(dev->name, end);
|
|
priv->name[0] = 'A' + priv->bank;
|
|
uc_priv->bank_name = priv->name;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct dm_gpio_ops gpio_rockchip_ops = {
|
|
.direction_input = rockchip_gpio_direction_input,
|
|
.direction_output = rockchip_gpio_direction_output,
|
|
.get_value = rockchip_gpio_get_value,
|
|
.set_value = rockchip_gpio_set_value,
|
|
.get_function = rockchip_gpio_get_function,
|
|
};
|
|
|
|
static const struct udevice_id rockchip_gpio_ids[] = {
|
|
{ .compatible = "rockchip,gpio-bank" },
|
|
{ }
|
|
};
|
|
|
|
U_BOOT_DRIVER(gpio_rockchip) = {
|
|
.name = "gpio_rockchip",
|
|
.id = UCLASS_GPIO,
|
|
.of_match = rockchip_gpio_ids,
|
|
.ops = &gpio_rockchip_ops,
|
|
.priv_auto_alloc_size = sizeof(struct rockchip_gpio_priv),
|
|
.probe = rockchip_gpio_probe,
|
|
};
|