1 // SPDX-License-Identifier: GPL-2.0+
5 * Derived from linux/arch/mips/bcm63xx/gpio.c:
14 #include <linux/bitops.h>
16 struct bcm6345_gpio_priv {
17 void __iomem *reg_dirout;
18 void __iomem *reg_data;
21 static int bcm6345_gpio_get_value(struct udevice *dev, unsigned offset)
23 struct bcm6345_gpio_priv *priv = dev_get_priv(dev);
25 return !!(readl(priv->reg_data) & BIT(offset));
28 static int bcm6345_gpio_set_value(struct udevice *dev, unsigned offset,
31 struct bcm6345_gpio_priv *priv = dev_get_priv(dev);
34 setbits_32(priv->reg_data, BIT(offset));
36 clrbits_32(priv->reg_data, BIT(offset));
41 static int bcm6345_gpio_set_direction(void __iomem *dirout, unsigned offset,
45 clrbits_32(dirout, BIT(offset));
47 setbits_32(dirout, BIT(offset));
52 static int bcm6345_gpio_direction_input(struct udevice *dev, unsigned offset)
54 struct bcm6345_gpio_priv *priv = dev_get_priv(dev);
56 return bcm6345_gpio_set_direction(priv->reg_dirout, offset, 1);
59 static int bcm6345_gpio_direction_output(struct udevice *dev, unsigned offset,
62 struct bcm6345_gpio_priv *priv = dev_get_priv(dev);
64 bcm6345_gpio_set_value(dev, offset, value);
66 return bcm6345_gpio_set_direction(priv->reg_dirout, offset, 0);
69 static int bcm6345_gpio_get_function(struct udevice *dev, unsigned offset)
71 struct bcm6345_gpio_priv *priv = dev_get_priv(dev);
73 if (readl(priv->reg_dirout) & BIT(offset))
79 static const struct dm_gpio_ops bcm6345_gpio_ops = {
80 .direction_input = bcm6345_gpio_direction_input,
81 .direction_output = bcm6345_gpio_direction_output,
82 .get_value = bcm6345_gpio_get_value,
83 .set_value = bcm6345_gpio_set_value,
84 .get_function = bcm6345_gpio_get_function,
87 static int bcm6345_gpio_probe(struct udevice *dev)
89 struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
90 struct bcm6345_gpio_priv *priv = dev_get_priv(dev);
92 priv->reg_dirout = dev_remap_addr_index(dev, 0);
93 if (!priv->reg_dirout)
96 priv->reg_data = dev_remap_addr_index(dev, 1);
100 uc_priv->gpio_count = dev_read_u32_default(dev, "ngpios", 32);
101 uc_priv->bank_name = dev->name;
106 static const struct udevice_id bcm6345_gpio_ids[] = {
107 { .compatible = "brcm,bcm6345-gpio" },
111 U_BOOT_DRIVER(bcm6345_gpio) = {
112 .name = "bcm6345-gpio",
114 .of_match = bcm6345_gpio_ids,
115 .ops = &bcm6345_gpio_ops,
116 .priv_auto = sizeof(struct bcm6345_gpio_priv),
117 .probe = bcm6345_gpio_probe,