1 // SPDX-License-Identifier: GPL-2.0
3 * slg7xl45106_i2c_gpo driver
5 * Copyright (C) 2021 Xilinx, Inc.
14 #include <dt-bindings/gpio/gpio.h>
15 #include <asm/arch/hardware.h>
17 #define SLG7XL45106_REG 0xdb
19 static int slg7xl45106_i2c_gpo_direction_input(struct udevice *dev,
25 static int slg7xl45106_i2c_gpo_xlate(struct udevice *dev,
26 struct gpio_desc *desc,
27 struct ofnode_phandle_args *args)
29 desc->offset = (unsigned int)args->args[0];
30 desc->flags = (args->args[1] & GPIO_ACTIVE_LOW ? GPIOD_ACTIVE_LOW : 0);
35 static int slg7xl45106_i2c_gpo_set_value(struct udevice *dev,
36 unsigned int offset, int value)
41 ret = dm_i2c_read(dev, SLG7XL45106_REG, &val, 1);
50 return dm_i2c_write(dev, SLG7XL45106_REG, &val, 1);
53 static int slg7xl45106_i2c_gpo_direction_output(struct udevice *dev,
54 unsigned int offset, int value)
56 return slg7xl45106_i2c_gpo_set_value(dev, offset, value);
59 static int slg7xl45106_i2c_gpo_get_value(struct udevice *dev,
65 ret = dm_i2c_read(dev, SLG7XL45106_REG, &val, 1);
69 return !!(val & BIT(offset));
72 static int slg7xl45106_i2c_gpo_get_function(struct udevice *dev,
78 static const struct dm_gpio_ops slg7xl45106_i2c_gpo_ops = {
79 .direction_input = slg7xl45106_i2c_gpo_direction_input,
80 .direction_output = slg7xl45106_i2c_gpo_direction_output,
81 .get_value = slg7xl45106_i2c_gpo_get_value,
82 .set_value = slg7xl45106_i2c_gpo_set_value,
83 .get_function = slg7xl45106_i2c_gpo_get_function,
84 .xlate = slg7xl45106_i2c_gpo_xlate,
87 static int slg7xl45106_i2c_gpo_probe(struct udevice *dev)
89 struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
90 const void *label_ptr;
92 label_ptr = dev_read_prop(dev, "label", NULL);
94 uc_priv->bank_name = strdup(label_ptr);
95 if (!uc_priv->bank_name)
98 uc_priv->bank_name = dev->name;
101 uc_priv->gpio_count = 8;
106 static const struct udevice_id slg7xl45106_i2c_gpo_ids[] = {
107 { .compatible = "dlg,slg7xl45106",},
111 U_BOOT_DRIVER(slg7xl45106_i2c_gpo) = {
112 .name = "slg7xl45106_i2c_gpo",
114 .ops = &slg7xl45106_i2c_gpo_ops,
115 .of_match = slg7xl45106_i2c_gpo_ids,
116 .probe = slg7xl45106_i2c_gpo_probe,