1 // SPDX-License-Identifier: GPL-2.0
3 * slg7xl45106_i2c_gpo driver
5 * Copyright (C) 2021 Xilinx, Inc.
13 #include <dt-bindings/gpio/gpio.h>
14 #include <asm/arch/hardware.h>
16 #define SLG7XL45106_REG 0xdb
18 static int slg7xl45106_i2c_gpo_direction_input(struct udevice *dev,
24 static int slg7xl45106_i2c_gpo_xlate(struct udevice *dev,
25 struct gpio_desc *desc,
26 struct ofnode_phandle_args *args)
28 desc->offset = (unsigned int)args->args[0];
29 desc->flags = (args->args[1] & GPIO_ACTIVE_LOW ? GPIOD_ACTIVE_LOW : 0);
34 static int slg7xl45106_i2c_gpo_set_value(struct udevice *dev,
35 unsigned int offset, int value)
40 ret = dm_i2c_read(dev, SLG7XL45106_REG, &val, 1);
49 return dm_i2c_write(dev, SLG7XL45106_REG, &val, 1);
52 static int slg7xl45106_i2c_gpo_direction_output(struct udevice *dev,
53 unsigned int offset, int value)
55 return slg7xl45106_i2c_gpo_set_value(dev, offset, value);
58 static int slg7xl45106_i2c_gpo_get_value(struct udevice *dev,
64 ret = dm_i2c_read(dev, SLG7XL45106_REG, &val, 1);
68 return !!(val & BIT(offset));
71 static int slg7xl45106_i2c_gpo_get_function(struct udevice *dev,
77 static const struct dm_gpio_ops slg7xl45106_i2c_gpo_ops = {
78 .direction_input = slg7xl45106_i2c_gpo_direction_input,
79 .direction_output = slg7xl45106_i2c_gpo_direction_output,
80 .get_value = slg7xl45106_i2c_gpo_get_value,
81 .set_value = slg7xl45106_i2c_gpo_set_value,
82 .get_function = slg7xl45106_i2c_gpo_get_function,
83 .xlate = slg7xl45106_i2c_gpo_xlate,
86 static int slg7xl45106_i2c_gpo_probe(struct udevice *dev)
88 struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
89 const void *label_ptr;
91 label_ptr = dev_read_prop(dev, "label", NULL);
93 uc_priv->bank_name = strdup(label_ptr);
94 if (!uc_priv->bank_name)
97 uc_priv->bank_name = dev->name;
100 uc_priv->gpio_count = 8;
105 static const struct udevice_id slg7xl45106_i2c_gpo_ids[] = {
106 { .compatible = "dlg,slg7xl45106",},
110 U_BOOT_DRIVER(slg7xl45106_i2c_gpo) = {
111 .name = "slg7xl45106_i2c_gpo",
113 .ops = &slg7xl45106_i2c_gpo_ops,
114 .of_match = slg7xl45106_i2c_gpo_ids,
115 .probe = slg7xl45106_i2c_gpo_probe,