2 * Copyright (C) 2016 Stefan Roese <sr@denx.de>
4 * SPDX-License-Identifier: GPL-2.0+
13 DECLARE_GLOBAL_DATA_PTR;
15 #define MVEBU_GPIOS_PER_BANK 32
17 struct mvebu_gpio_regs {
25 struct mvebu_gpio_priv {
26 struct mvebu_gpio_regs *regs;
30 static int mvebu_gpio_direction_input(struct udevice *dev, unsigned int gpio)
32 struct mvebu_gpio_priv *priv = dev_get_priv(dev);
33 struct mvebu_gpio_regs *regs = priv->regs;
35 setbits_le32(®s->io_conf, BIT(gpio));
40 static int mvebu_gpio_direction_output(struct udevice *dev, unsigned gpio,
43 struct mvebu_gpio_priv *priv = dev_get_priv(dev);
44 struct mvebu_gpio_regs *regs = priv->regs;
47 setbits_le32(®s->data_out, BIT(gpio));
49 clrbits_le32(®s->data_out, BIT(gpio));
50 clrbits_le32(®s->io_conf, BIT(gpio));
55 static int mvebu_gpio_get_function(struct udevice *dev, unsigned gpio)
57 struct mvebu_gpio_priv *priv = dev_get_priv(dev);
58 struct mvebu_gpio_regs *regs = priv->regs;
61 val = readl(®s->io_conf) & BIT(gpio);
68 static int mvebu_gpio_set_value(struct udevice *dev, unsigned gpio,
71 struct mvebu_gpio_priv *priv = dev_get_priv(dev);
72 struct mvebu_gpio_regs *regs = priv->regs;
75 setbits_le32(®s->data_out, BIT(gpio));
77 clrbits_le32(®s->data_out, BIT(gpio));
82 static int mvebu_gpio_get_value(struct udevice *dev, unsigned gpio)
84 struct mvebu_gpio_priv *priv = dev_get_priv(dev);
85 struct mvebu_gpio_regs *regs = priv->regs;
87 return !!(readl(®s->data_in) & BIT(gpio));
90 static int mvebu_gpio_probe(struct udevice *dev)
92 struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
93 struct mvebu_gpio_priv *priv = dev_get_priv(dev);
95 priv->regs = (struct mvebu_gpio_regs *)devfdt_get_addr(dev);
96 uc_priv->gpio_count = MVEBU_GPIOS_PER_BANK;
97 priv->name[0] = 'A' + dev->req_seq;
98 uc_priv->bank_name = priv->name;
103 static const struct dm_gpio_ops mvebu_gpio_ops = {
104 .direction_input = mvebu_gpio_direction_input,
105 .direction_output = mvebu_gpio_direction_output,
106 .get_function = mvebu_gpio_get_function,
107 .get_value = mvebu_gpio_get_value,
108 .set_value = mvebu_gpio_set_value,
111 static const struct udevice_id mvebu_gpio_ids[] = {
112 { .compatible = "marvell,orion-gpio" },
116 U_BOOT_DRIVER(gpio_mvebu) = {
117 .name = "gpio_mvebu",
119 .of_match = mvebu_gpio_ids,
120 .ops = &mvebu_gpio_ops,
121 .probe = mvebu_gpio_probe,
122 .priv_auto_alloc_size = sizeof(struct mvebu_gpio_priv),