1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2016 Stefan Roese <sr@denx.de>
12 #define MVEBU_GPIOS_PER_BANK 32
14 struct mvebu_gpio_regs {
22 struct mvebu_gpio_priv {
23 struct mvebu_gpio_regs *regs;
27 static int mvebu_gpio_direction_input(struct udevice *dev, unsigned int gpio)
29 struct mvebu_gpio_priv *priv = dev_get_priv(dev);
30 struct mvebu_gpio_regs *regs = priv->regs;
32 setbits_le32(®s->io_conf, BIT(gpio));
37 static int mvebu_gpio_direction_output(struct udevice *dev, unsigned gpio,
40 struct mvebu_gpio_priv *priv = dev_get_priv(dev);
41 struct mvebu_gpio_regs *regs = priv->regs;
44 setbits_le32(®s->data_out, BIT(gpio));
46 clrbits_le32(®s->data_out, BIT(gpio));
47 clrbits_le32(®s->io_conf, BIT(gpio));
52 static int mvebu_gpio_get_function(struct udevice *dev, unsigned gpio)
54 struct mvebu_gpio_priv *priv = dev_get_priv(dev);
55 struct mvebu_gpio_regs *regs = priv->regs;
58 val = readl(®s->io_conf) & BIT(gpio);
65 static int mvebu_gpio_set_value(struct udevice *dev, unsigned gpio,
68 struct mvebu_gpio_priv *priv = dev_get_priv(dev);
69 struct mvebu_gpio_regs *regs = priv->regs;
72 setbits_le32(®s->data_out, BIT(gpio));
74 clrbits_le32(®s->data_out, BIT(gpio));
79 static int mvebu_gpio_get_value(struct udevice *dev, unsigned gpio)
81 struct mvebu_gpio_priv *priv = dev_get_priv(dev);
82 struct mvebu_gpio_regs *regs = priv->regs;
84 return !!(readl(®s->data_in) & BIT(gpio));
87 static int mvebu_gpio_probe(struct udevice *dev)
89 struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
90 struct mvebu_gpio_priv *priv = dev_get_priv(dev);
92 priv->regs = (struct mvebu_gpio_regs *)devfdt_get_addr(dev);
93 uc_priv->gpio_count = MVEBU_GPIOS_PER_BANK;
94 priv->name[0] = 'A' + dev->req_seq;
95 uc_priv->bank_name = priv->name;
100 static const struct dm_gpio_ops mvebu_gpio_ops = {
101 .direction_input = mvebu_gpio_direction_input,
102 .direction_output = mvebu_gpio_direction_output,
103 .get_function = mvebu_gpio_get_function,
104 .get_value = mvebu_gpio_get_value,
105 .set_value = mvebu_gpio_set_value,
108 static const struct udevice_id mvebu_gpio_ids[] = {
109 { .compatible = "marvell,orion-gpio" },
113 U_BOOT_DRIVER(gpio_mvebu) = {
114 .name = "gpio_mvebu",
116 .of_match = mvebu_gpio_ids,
117 .ops = &mvebu_gpio_ops,
118 .probe = mvebu_gpio_probe,
119 .priv_auto_alloc_size = sizeof(struct mvebu_gpio_priv),