DECLARE_GLOBAL_DATA_PTR;
+/**
+ * gpio_desc_init() - Initialize the GPIO descriptor
+ *
+ * @desc: GPIO descriptor to initialize
+ * @dev: GPIO device
+ * @offset: Offset of device GPIO
+ */
+static void gpio_desc_init(struct gpio_desc *desc,
+ struct udevice *dev,
+ uint offset)
+{
+ desc->dev = dev;
+ desc->offset = offset;
+ desc->flags = 0;
+}
+
/**
* gpio_to_device() - Convert global GPIO number to device, number
*
uc_priv = dev_get_uclass_priv(dev);
if (gpio >= uc_priv->gpio_base &&
gpio < uc_priv->gpio_base + uc_priv->gpio_count) {
- desc->dev = dev;
- desc->offset = gpio - uc_priv->gpio_base;
- desc->flags = 0;
+ gpio_desc_init(desc, dev, gpio - uc_priv->gpio_base);
return 0;
}
}
if (!dev)
return ret ? ret : -EINVAL;
- desc->dev = dev;
- desc->offset = offset;
+ gpio_desc_init(desc, dev, offset);
return 0;
}
struct gpio_desc *desc, int flags,
bool add_index, struct udevice *gpio_dev)
{
- desc->dev = gpio_dev;
- desc->offset = 0;
- desc->flags = 0;
+ gpio_desc_init(desc, gpio_dev, 0);
if (ret)
goto err;