2 * Copyright (C) 2014 NVIDIA Corporation
4 * SPDX-License-Identifier: GPL-2.0+
10 #include <power/as3722.h>
11 #include <power/pmic.h>
15 int as3722_gpio_configure(struct udevice *pmic, unsigned int gpio,
21 if (flags & AS3722_GPIO_OUTPUT_VDDH)
22 value |= AS3722_GPIO_CONTROL_MODE_OUTPUT_VDDH;
24 if (flags & AS3722_GPIO_INVERT)
25 value |= AS3722_GPIO_CONTROL_INVERT;
27 err = pmic_reg_write(pmic, AS3722_GPIO_CONTROL(gpio), value);
29 error("failed to configure GPIO#%u: %d", gpio, err);
36 static int as3722_gpio_set_value(struct udevice *dev, unsigned int gpio,
39 struct udevice *pmic = dev_get_parent(dev);
44 if (gpio >= NUM_GPIOS)
47 err = pmic_reg_read(pmic, AS3722_GPIO_SIGNAL_OUT);
49 error("failed to read GPIO signal out register: %d", err);
55 value &= ~(1 << gpio);
62 err = pmic_reg_write(pmic, AS3722_GPIO_SIGNAL_OUT, value);
64 error("failed to set GPIO#%u %s: %d", gpio, l, err);
71 int as3722_gpio_direction_output(struct udevice *dev, unsigned int gpio,
74 struct udevice *pmic = dev_get_parent(dev);
81 value = AS3722_GPIO_CONTROL_MODE_OUTPUT_VDDL;
83 value = AS3722_GPIO_CONTROL_MODE_OUTPUT_VDDH;
85 err = pmic_reg_write(pmic, AS3722_GPIO_CONTROL(gpio), value);
87 error("failed to configure GPIO#%u as output: %d", gpio, err);
91 err = as3722_gpio_set_value(pmic, gpio, value);
93 error("failed to set GPIO#%u high: %d", gpio, err);
100 static int as3722_gpio_probe(struct udevice *dev)
102 struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
104 uc_priv->gpio_count = NUM_GPIOS;
105 uc_priv->bank_name = "as3722_";
110 static const struct dm_gpio_ops gpio_as3722_ops = {
111 .direction_output = as3722_gpio_direction_output,
112 .set_value = as3722_gpio_set_value,
115 U_BOOT_DRIVER(gpio_as3722) = {
116 .name = "gpio_as3722",
118 .ops = &gpio_as3722_ops,
119 .probe = as3722_gpio_probe,