// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright (C) 2015 Linaro
 * Peter Griffin <peter.griffin@linaro.org>
 */

#include <common.h>
#include <dm.h>
#include <asm/gpio.h>
#include <asm/io.h>
#include <errno.h>
#include <linux/bitops.h>

static int hi6220_gpio_direction_input(struct udevice *dev, unsigned int gpio)
{
	struct gpio_bank *bank = dev_get_priv(dev);
	u8 data;

	data = readb(bank->base + HI6220_GPIO_DIR);
	data &= ~(1 << gpio);
	writeb(data, bank->base + HI6220_GPIO_DIR);

	return 0;
}

static int hi6220_gpio_set_value(struct udevice *dev, unsigned gpio,
				  int value)
{
	struct gpio_bank *bank = dev_get_priv(dev);

	writeb(!!value << gpio, bank->base + (BIT(gpio + 2)));
	return 0;
}

static int hi6220_gpio_direction_output(struct udevice *dev, unsigned gpio,
					int value)
{
	struct gpio_bank *bank = dev_get_priv(dev);
	u8 data;

	data = readb(bank->base + HI6220_GPIO_DIR);
	data |= 1 << gpio;
	writeb(data, bank->base + HI6220_GPIO_DIR);

	hi6220_gpio_set_value(dev, gpio, value);

	return 0;
}

static int hi6220_gpio_get_value(struct udevice *dev, unsigned gpio)
{
	struct gpio_bank *bank = dev_get_priv(dev);

	return !!readb(bank->base + (BIT(gpio + 2)));
}



static const struct dm_gpio_ops gpio_hi6220_ops = {
	.direction_input	= hi6220_gpio_direction_input,
	.direction_output	= hi6220_gpio_direction_output,
	.get_value		= hi6220_gpio_get_value,
	.set_value		= hi6220_gpio_set_value,
};

static int hi6220_gpio_probe(struct udevice *dev)
{
	struct gpio_bank *bank = dev_get_priv(dev);
	struct hikey_gpio_platdata *plat = dev_get_platdata(dev);
	struct gpio_dev_priv *uc_priv = dev->uclass_priv;
	char name[18], *str;

	sprintf(name, "GPIO%d_", plat->bank_index);

	str = strdup(name);
	if (!str)
		return -ENOMEM;

	uc_priv->bank_name = str;
	uc_priv->gpio_count = HI6220_GPIO_PER_BANK;

	bank->base = (u8 *)plat->base;

	return 0;
}

U_BOOT_DRIVER(gpio_hi6220) = {
	.name	= "gpio_hi6220",
	.id	= UCLASS_GPIO,
	.ops	= &gpio_hi6220_ops,
	.probe	= hi6220_gpio_probe,
	.priv_auto_alloc_size = sizeof(struct gpio_bank),
};


