On Sat,  1 Jun 2013 12:44:09 +0200 Jan Luebbe <j...@pengutronix.de> wrote:

> Instead of allocating a struct pps_gpio_platform_data in the DT case, store
> the necessary information in struct pps_gpio_device_data itself. This avoids
> an additional allocation and the ifdef. It also gets rid of some indirection.
> 
> Also use dev_err instead of pr_err in the changed code.
> 
> ...
>
>  static int pps_gpio_probe(struct platform_device *pdev)
>  {
>       struct pps_gpio_device_data *data;
> -     int irq;
> +     const char *gpio_label;
>       int ret;
>       int pps_default_params;
>       const struct pps_gpio_platform_data *pdata = pdev->dev.platform_data;
> +     struct device_node *np = pdev->dev.of_node;
>  
> +     /* allocate space for device info */
> +     data = devm_kzalloc(&pdev->dev, sizeof(struct pps_gpio_device_data),
> +                     GFP_KERNEL);
> +     if (!data)
> +             return -ENOMEM;
> +
> +     if (pdata) {
> +             data->gpio_pin = pdata->gpio_pin;
> +             gpio_label = pdata->gpio_label;
> +
> +             data->assert_falling_edge = pdata->assert_falling_edge;
> +             data->capture_clear = pdata->capture_clear;
> +     } else {
> +             ret = of_get_gpio(np, 0);
> +             if (ret < 0) {
> +                     dev_err(&pdev->dev, "failed to get GPIO from device 
> tree\n");
> +                     return ret;
> +             }
> +             data->gpio_pin = ret;
> +             gpio_label = PPS_GPIO_NAME;
> +
> +             if (of_get_property(np, "assert-falling-edge", NULL))
> +                     data->assert_falling_edge = true;
> +     }
>  
>       /* GPIO setup */
> -     ret = pps_gpio_setup(pdev);
> -     if (ret)
> -             return -EINVAL;
> +     ret = devm_gpio_request(&pdev->dev, data->gpio_pin, gpio_label);
> +     if (ret) {
> +             dev_err(&pdev->dev, "failed to request GPIO %u\n",
> +                     data->gpio_pin);
> +             return ret;
> +     }
>  
> -     /* IRQ setup */
> -     irq = gpio_to_irq(pdata->gpio_pin);
> -     if (irq < 0) {
> -             pr_err("failed to map GPIO to IRQ: %d\n", irq);
> +     ret = gpio_direction_input(data->gpio_pin);
> +     if (ret) {
> +             dev_err(&pdev->dev, "failed to set pin direction\n");
>               return -EINVAL;

Should we propagate the gpio_direction_input() return value?

>       }
>  

_______________________________________________
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss

Reply via email to