Re: [PATCH v2] pps-gpio: add device-tree binding and support

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

 



On Sat,  1 Jun 2013 12:44:09 +0200 Jan Luebbe <jlu@xxxxxxxxxxxxxx> 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?

>  	}
>  

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux