2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2017-05-07 18:09:30 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 Álvaro Fernández Rojas <noltari@gmail.com>
|
|
|
|
*
|
|
|
|
* Derived from linux/arch/mips/bcm63xx/gpio.c:
|
|
|
|
* Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
|
|
|
|
* Copyright (C) 2008-2011 Florian Fainelli <florian@openwrt.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2017-05-17 23:18:03 +00:00
|
|
|
#include <dm.h>
|
2017-05-07 18:09:30 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <asm/gpio.h>
|
|
|
|
#include <asm/io.h>
|
2020-05-10 17:40:13 +00:00
|
|
|
#include <linux/bitops.h>
|
2017-05-07 18:09:30 +00:00
|
|
|
|
|
|
|
struct bcm6345_gpio_priv {
|
|
|
|
void __iomem *reg_dirout;
|
|
|
|
void __iomem *reg_data;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int bcm6345_gpio_get_value(struct udevice *dev, unsigned offset)
|
|
|
|
{
|
|
|
|
struct bcm6345_gpio_priv *priv = dev_get_priv(dev);
|
|
|
|
|
2019-03-07 10:36:31 +00:00
|
|
|
return !!(readl(priv->reg_data) & BIT(offset));
|
2017-05-07 18:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int bcm6345_gpio_set_value(struct udevice *dev, unsigned offset,
|
|
|
|
int value)
|
|
|
|
{
|
|
|
|
struct bcm6345_gpio_priv *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
if (value)
|
2019-03-07 10:36:31 +00:00
|
|
|
setbits_32(priv->reg_data, BIT(offset));
|
2017-05-07 18:09:30 +00:00
|
|
|
else
|
2019-03-07 10:36:31 +00:00
|
|
|
clrbits_32(priv->reg_data, BIT(offset));
|
2017-05-07 18:09:30 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bcm6345_gpio_set_direction(void __iomem *dirout, unsigned offset,
|
|
|
|
bool input)
|
|
|
|
{
|
|
|
|
if (input)
|
2019-03-07 10:36:31 +00:00
|
|
|
clrbits_32(dirout, BIT(offset));
|
2017-05-07 18:09:30 +00:00
|
|
|
else
|
2019-03-07 10:36:31 +00:00
|
|
|
setbits_32(dirout, BIT(offset));
|
2017-05-07 18:09:30 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bcm6345_gpio_direction_input(struct udevice *dev, unsigned offset)
|
|
|
|
{
|
|
|
|
struct bcm6345_gpio_priv *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
return bcm6345_gpio_set_direction(priv->reg_dirout, offset, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bcm6345_gpio_direction_output(struct udevice *dev, unsigned offset,
|
|
|
|
int value)
|
|
|
|
{
|
|
|
|
struct bcm6345_gpio_priv *priv = dev_get_priv(dev);
|
|
|
|
|
2017-06-08 09:20:12 +00:00
|
|
|
bcm6345_gpio_set_value(dev, offset, value);
|
|
|
|
|
2017-05-07 18:09:30 +00:00
|
|
|
return bcm6345_gpio_set_direction(priv->reg_dirout, offset, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bcm6345_gpio_get_function(struct udevice *dev, unsigned offset)
|
|
|
|
{
|
|
|
|
struct bcm6345_gpio_priv *priv = dev_get_priv(dev);
|
|
|
|
|
2019-03-07 10:36:31 +00:00
|
|
|
if (readl(priv->reg_dirout) & BIT(offset))
|
2017-05-07 18:09:30 +00:00
|
|
|
return GPIOF_OUTPUT;
|
|
|
|
else
|
|
|
|
return GPIOF_INPUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct dm_gpio_ops bcm6345_gpio_ops = {
|
|
|
|
.direction_input = bcm6345_gpio_direction_input,
|
|
|
|
.direction_output = bcm6345_gpio_direction_output,
|
|
|
|
.get_value = bcm6345_gpio_get_value,
|
|
|
|
.set_value = bcm6345_gpio_set_value,
|
|
|
|
.get_function = bcm6345_gpio_get_function,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int bcm6345_gpio_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
|
|
|
|
struct bcm6345_gpio_priv *priv = dev_get_priv(dev);
|
|
|
|
|
2018-03-22 18:39:32 +00:00
|
|
|
priv->reg_dirout = dev_remap_addr_index(dev, 0);
|
|
|
|
if (!priv->reg_dirout)
|
2017-05-07 18:09:30 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
2018-03-22 18:39:32 +00:00
|
|
|
priv->reg_data = dev_remap_addr_index(dev, 1);
|
|
|
|
if (!priv->reg_data)
|
2017-05-07 18:09:30 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
2018-03-22 18:39:32 +00:00
|
|
|
uc_priv->gpio_count = dev_read_u32_default(dev, "ngpios", 32);
|
2017-05-07 18:09:30 +00:00
|
|
|
uc_priv->bank_name = dev->name;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct udevice_id bcm6345_gpio_ids[] = {
|
|
|
|
{ .compatible = "brcm,bcm6345-gpio" },
|
|
|
|
{ /* sentinel */ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(bcm6345_gpio) = {
|
|
|
|
.name = "bcm6345-gpio",
|
|
|
|
.id = UCLASS_GPIO,
|
|
|
|
.of_match = bcm6345_gpio_ids,
|
|
|
|
.ops = &bcm6345_gpio_ops,
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct bcm6345_gpio_priv),
|
2017-05-07 18:09:30 +00:00
|
|
|
.probe = bcm6345_gpio_probe,
|
|
|
|
};
|