lkml.org 
[lkml]   [2018]   [Sep]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2 7/8] mtd: maps: gpio-addr-flash: Add support for device-tree devices
On Wed,  5 Sep 2018 16:36:42 +0200
Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com> 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;
> +}

\
 
 \ /
  Last update: 2018-09-27 13:39    [W:0.148 / U:0.604 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site