Commit 4ef339bc authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Bartosz Golaszewski
Browse files

gpiolib: Unify access to the device properties



Some of the functions are using struct fwnode_handle, some struct device
pointer. In the GPIO library the firmware node of the GPIO device is the
same as GPIO node of the GPIO chip. Due to this fact we may use former
to access properties everywhere in the code.

Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: default avatarBrian Masney <bmasney@redhat.com>
Tested-by: default avatarMarijn Suijten <marijn.suijten@somainline.org>
[Bartosz: stick to the 80-char limit where it's not hurting readability]
Signed-off-by: default avatarBartosz Golaszewski <bartosz.golaszewski@linaro.org>
parent 923d011f
Loading
Loading
Loading
Loading
+10 −7
Original line number Original line Diff line number Diff line
@@ -367,12 +367,12 @@ static int gpiochip_set_desc_names(struct gpio_chip *gc)
static int devprop_gpiochip_set_names(struct gpio_chip *chip)
static int devprop_gpiochip_set_names(struct gpio_chip *chip)
{
{
	struct gpio_device *gdev = chip->gpiodev;
	struct gpio_device *gdev = chip->gpiodev;
	const struct fwnode_handle *fwnode = dev_fwnode(&gdev->dev);
	struct device *dev = &gdev->dev;
	const char **names;
	const char **names;
	int ret, i;
	int ret, i;
	int count;
	int count;


	count = fwnode_property_string_array_count(fwnode, "gpio-line-names");
	count = device_property_string_array_count(dev, "gpio-line-names");
	if (count < 0)
	if (count < 0)
		return 0;
		return 0;


@@ -385,7 +385,7 @@ static int devprop_gpiochip_set_names(struct gpio_chip *chip)
	 * gpiochips.
	 * gpiochips.
	 */
	 */
	if (count <= chip->offset) {
	if (count <= chip->offset) {
		dev_warn(&gdev->dev, "gpio-line-names too short (length %d), cannot map names for the gpiochip at offset %u\n",
		dev_warn(dev, "gpio-line-names too short (length %d), cannot map names for the gpiochip at offset %u\n",
			 count, chip->offset);
			 count, chip->offset);
		return 0;
		return 0;
	}
	}
@@ -394,10 +394,10 @@ static int devprop_gpiochip_set_names(struct gpio_chip *chip)
	if (!names)
	if (!names)
		return -ENOMEM;
		return -ENOMEM;


	ret = fwnode_property_read_string_array(fwnode, "gpio-line-names",
	ret = device_property_read_string_array(dev, "gpio-line-names",
						names, count);
						names, count);
	if (ret < 0) {
	if (ret < 0) {
		dev_warn(&gdev->dev, "failed to read GPIO line names\n");
		dev_warn(dev, "failed to read GPIO line names\n");
		kfree(names);
		kfree(names);
		return ret;
		return ret;
	}
	}
@@ -448,10 +448,11 @@ static unsigned long *gpiochip_allocate_mask(struct gpio_chip *gc)


static unsigned int gpiochip_count_reserved_ranges(struct gpio_chip *gc)
static unsigned int gpiochip_count_reserved_ranges(struct gpio_chip *gc)
{
{
	struct device *dev = &gc->gpiodev->dev;
	int size;
	int size;


	/* Format is "start, count, ..." */
	/* Format is "start, count, ..." */
	size = fwnode_property_count_u32(gc->fwnode, "gpio-reserved-ranges");
	size = device_property_count_u32(dev, "gpio-reserved-ranges");
	if (size > 0 && size % 2 == 0)
	if (size > 0 && size % 2 == 0)
		return size;
		return size;


@@ -472,6 +473,7 @@ static int gpiochip_alloc_valid_mask(struct gpio_chip *gc)


static int gpiochip_apply_reserved_ranges(struct gpio_chip *gc)
static int gpiochip_apply_reserved_ranges(struct gpio_chip *gc)
{
{
	struct device *dev = &gc->gpiodev->dev;
	unsigned int size;
	unsigned int size;
	u32 *ranges;
	u32 *ranges;
	int ret;
	int ret;
@@ -484,7 +486,8 @@ static int gpiochip_apply_reserved_ranges(struct gpio_chip *gc)
	if (!ranges)
	if (!ranges)
		return -ENOMEM;
		return -ENOMEM;


	ret = fwnode_property_read_u32_array(gc->fwnode, "gpio-reserved-ranges", ranges, size);
	ret = device_property_read_u32_array(dev, "gpio-reserved-ranges",
					     ranges, size);
	if (ret) {
	if (ret) {
		kfree(ranges);
		kfree(ranges);
		return ret;
		return ret;