1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2016 Stefan Roese <sr@denx.de>
11 #include <linux/bitops.h>
13 #define MVEBU_GPIOS_PER_BANK 32
15 struct mvebu_gpio_regs {
23 struct mvebu_gpio_priv {
24 struct mvebu_gpio_regs *regs;
28 static int mvebu_gpio_direction_input(struct udevice *dev, unsigned int gpio)
30 struct mvebu_gpio_priv *priv = dev_get_priv(dev);
31 struct mvebu_gpio_regs *regs = priv->regs;
33 setbits_le32(®s->io_conf, BIT(gpio));
38 static int mvebu_gpio_direction_output(struct udevice *dev, unsigned gpio,
41 struct mvebu_gpio_priv *priv = dev_get_priv(dev);
42 struct mvebu_gpio_regs *regs = priv->regs;
45 setbits_le32(®s->data_out, BIT(gpio));
47 clrbits_le32(®s->data_out, BIT(gpio));
48 clrbits_le32(®s->io_conf, BIT(gpio));
53 static int mvebu_gpio_get_function(struct udevice *dev, unsigned gpio)
55 struct mvebu_gpio_priv *priv = dev_get_priv(dev);
56 struct mvebu_gpio_regs *regs = priv->regs;
59 val = readl(®s->io_conf) & BIT(gpio);
66 static int mvebu_gpio_set_value(struct udevice *dev, unsigned gpio,
69 struct mvebu_gpio_priv *priv = dev_get_priv(dev);
70 struct mvebu_gpio_regs *regs = priv->regs;
73 setbits_le32(®s->data_out, BIT(gpio));
75 clrbits_le32(®s->data_out, BIT(gpio));
80 static int mvebu_gpio_get_value(struct udevice *dev, unsigned gpio)
82 struct mvebu_gpio_priv *priv = dev_get_priv(dev);
83 struct mvebu_gpio_regs *regs = priv->regs;
85 return !!(readl(®s->data_in) & BIT(gpio));
88 static int mvebu_gpio_probe(struct udevice *dev)
90 struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
91 struct mvebu_gpio_priv *priv = dev_get_priv(dev);
93 priv->regs = dev_read_addr_ptr(dev);
94 uc_priv->gpio_count = MVEBU_GPIOS_PER_BANK;
95 priv->name[0] = 'A' + dev_seq(dev);
96 uc_priv->bank_name = priv->name;
101 static const struct dm_gpio_ops mvebu_gpio_ops = {
102 .direction_input = mvebu_gpio_direction_input,
103 .direction_output = mvebu_gpio_direction_output,
104 .get_function = mvebu_gpio_get_function,
105 .get_value = mvebu_gpio_get_value,
106 .set_value = mvebu_gpio_set_value,
109 static const struct udevice_id mvebu_gpio_ids[] = {
110 { .compatible = "marvell,orion-gpio" },
114 U_BOOT_DRIVER(gpio_mvebu) = {
115 .name = "gpio_mvebu",
117 .of_match = mvebu_gpio_ids,
118 .ops = &mvebu_gpio_ops,
119 .probe = mvebu_gpio_probe,
120 .priv_auto = sizeof(struct mvebu_gpio_priv),