Re: [PATCH 5/6] gpiolib: consolidate GPIO lookups

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Nov 03, 2022 at 11:10:15PM -0700, Dmitry Torokhov wrote:
> Ensure that all paths to obtain/look up GPIOD from generic
> consumer-visible APIs go through the new gpiod_find_and_request()
> helper, so that we can easily extend it with support for new firmware
> mechanisms.

...

> +static struct gpio_desc *gpiod_find_by_fwnode(struct fwnode_handle *fwnode,
> +					      struct device *consumer,
> +					      const char *con_id,
> +					      unsigned int idx,
> +					      enum gpiod_flags *flags,
> +					      unsigned long *lookupflags)
>  {

> +	struct gpio_desc *desc = ERR_PTR(-ENOENT);

No need, just return directly.

> +	dev_dbg(consumer, "GPIO lookup for consumer %s in node '%s'\n",
> +		con_id, fwnode_get_name(fwnode));

%pfwP ?

> +
> +	/* Using device tree? */
>  	if (is_of_node(fwnode)) {
> +		dev_dbg(consumer, "using device tree for GPIO lookup\n");
> +		desc = of_find_gpio(to_of_node(fwnode),
> +				    con_id, idx, lookupflags);
>  	} else if (is_acpi_node(fwnode)) {

With direct return, no need for 'else' here.

> +		dev_dbg(consumer, "using ACPI for GPIO lookup\n");
> +		desc = acpi_find_gpio(fwnode, con_id, idx, flags, lookupflags);
>  	}
>  
> +	return desc;
> +}

...

> +static struct gpio_desc *gpiod_find_and_request(struct device *consumer,
> +						struct fwnode_handle *fwnode,
> +						const char *con_id,
> +						unsigned int idx,
> +						enum gpiod_flags flags,
> +						const char *label,
> +						bool platform_lookup_allowed)
> +{

> +	struct gpio_desc *desc = ERR_PTR(-ENOENT);

We can get rid of the assignment, see below.


> +	unsigned long lookupflags;
> +	int ret;

> +	if (fwnode)

Do we need this check?

Debug message above (when %pfw is used) would be even useful when
fwnode == NULL.

> +		desc = gpiod_find_by_fwnode(fwnode, consumer, con_id, idx,
> +					    &flags, &lookupflags);

> +

The blank line can be removed after above comments being addressed.

> +	if (gpiod_not_found(desc) && platform_lookup_allowed) {
> +		/*
> +		 * Either we are not using DT or ACPI, or their lookup did not
> +		 * return a result. In that case, use platform lookup as a
> +		 * fallback.
> +		 */
> +		dev_dbg(consumer, "using lookup tables for GPIO lookup\n");
> +		desc = gpiod_find(consumer, con_id, idx, &lookupflags);
> +	}
> +
> +	if (IS_ERR(desc)) {
> +		dev_dbg(consumer, "No GPIO consumer %s found\n", con_id);
> +		return desc;
> +	}
> +
> +	/*
> +	 * If a connection label was passed use that, else attempt to use
> +	 * the device name as label
> +	 */
>  	ret = gpiod_request(desc, label);
> +	if (ret) {
> +		if (!(ret == -EBUSY && flags & GPIOD_FLAGS_BIT_NONEXCLUSIVE))
> +			return ERR_PTR(ret);
> +
> +		/*
> +		 * This happens when there are several consumers for
> +		 * the same GPIO line: we just return here without
> +		 * further initialization. It is a bit of a hack.
> +		 * This is necessary to support fixed regulators.
> +		 *
> +		 * FIXME: Make this more sane and safe.
> +		 */

> +		dev_info(consumer,
> +			 "nonexclusive access to GPIO for %s\n", con_id);

Cam be one line.

> +		return desc;
> +	}
>  
> +	ret = gpiod_configure_flags(desc, con_id, lookupflags, flags);
>  	if (ret < 0) {
> +		dev_dbg(consumer, "setup of GPIO %s failed\n", con_id);
>  		gpiod_put(desc);
>  		return ERR_PTR(ret);
>  	}

...

>  struct gpio_desc *fwnode_gpiod_get_index(struct fwnode_handle *fwnode,
> +					 const char *con_id,
> +					 int index,
>  					 enum gpiod_flags flags,
>  					 const char *label)
>  {
>  

Unnecessary blank line?

> +	return gpiod_find_and_request(NULL, fwnode, con_id, index, flags, label,
> +				      false);

Can be one line.

>  }

...


> +	return gpiod_find_and_request(dev, fwnode, con_id, idx, flags, label,
> +				      true);

Ditto.

-- 
With Best Regards,
Andy Shevchenko





[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux