Re: [PATCH v2 7/8] mtd: maps: gpio-addr-flash: Add support for device-tree devices

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

 



On Wed,  5 Sep 2018 16:36:42 +0200
Ricardo Ribalda Delgado <ricardo.ribalda@xxxxxxxxx> wrote:

> +static int gpio_flash_probe_gpios(struct platform_device *pdev,
> +				  struct async_state *state)
> +{
> +	struct physmap_flash_data *pdata;
> +	struct device_node *dn;
> +	struct resource *gpios = NULL;
> +	int i;
> +
> +	dn = pdev->dev.of_node;
> +	if (dn) {
> +		state->gpio_count = of_gpio_count(dn);
> +	} else {
> +		pdata = dev_get_platdata(&pdev->dev);
> +		if (!pdata)
> +			return -EINVAL;
> +		gpios = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
> +		if (IS_ERR(gpios) || !gpios->end)
> +			return -EINVAL;
> +		state->gpio_count = gpios->end;
> +	}
> +
> +	state->gpio_addrs = devm_kzalloc(&pdev->dev,
> +					 sizeof(state->gpio_addrs[0])
> +						* state->gpio_count,
> +					 GFP_KERNEL);
> +	if (!state->gpio_addrs)
> +		return -ENOMEM;
> +
> +	for (i = 0; i < state->gpio_count; i++) {
> +		long gpio;
> +		int ret;
> +
> +		if (dn)
> +			gpio = of_get_gpio(dn, i);
> +		else
> +			gpio = ((unsigned long *)gpios->start)[i];
> +

Hm, we should probably switch to GPIO descs (instead of GPIO numbers)
before adding DT support. This should make the code much more simpler
and remove one more user of the old/deprecated GPIO API.

> +		if (gpio < 0)
> +			return gpio;
> +
> +		ret =  devm_gpio_request(&pdev->dev, gpio, DRIVER_NAME);
> +		if (ret < 0) {
> +			dev_err(&pdev->dev, "failed to request gpio %ld\n",
> +				gpio);
> +			return ret;
> +		}
> +		state->gpio_addrs[i] = gpio;
> +		gpio_direction_output(state->gpio_addrs[i], 0);
> +	}
> +
> +	return 0;
> +}

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux