Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pps: descriptor-based gpio

This patch changes the GPIO access for the pps-gpio driver from the
integer based API to the descriptor based API.

The integer based API is considered deprecated and the descriptor based
API is the preferred way to access GPIOs as per
Documentation/driver-api/gpio/intro.rst

No changes are made to userspace interfaces.

Link: http://lkml.kernel.org/r/20190324043305.6627-2-tom@aussec.com
Signed-off-by: Tom Burkart <tom@aussec.com>
Acked-by: Rodolfo Giometti <giometti@enneenne.com>
Reviewed-by: Philipp Zabel <philipp.zabel@gmail.com>
Cc: Lukas Senger <lukas@fridolin.com>
Cc: Rob Herring <robh@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Tom Burkart and committed by
Linus Torvalds
4461d651 b287a25a

+32 -38
+31 -36
drivers/pps/clients/pps-gpio.c
··· 31 31 #include <linux/slab.h> 32 32 #include <linux/pps_kernel.h> 33 33 #include <linux/pps-gpio.h> 34 - #include <linux/gpio.h> 34 + #include <linux/gpio/consumer.h> 35 35 #include <linux/list.h> 36 36 #include <linux/of_device.h> 37 37 #include <linux/of_gpio.h> ··· 41 41 int irq; /* IRQ used as PPS source */ 42 42 struct pps_device *pps; /* PPS source device */ 43 43 struct pps_source_info info; /* PPS source information */ 44 + struct gpio_desc *gpio_pin; /* GPIO port descriptors */ 44 45 bool assert_falling_edge; 45 46 bool capture_clear; 46 - unsigned int gpio_pin; 47 47 }; 48 48 49 49 /* ··· 61 61 62 62 info = data; 63 63 64 - rising_edge = gpio_get_value(info->gpio_pin); 64 + rising_edge = gpiod_get_value(info->gpio_pin); 65 65 if ((rising_edge && !info->assert_falling_edge) || 66 66 (!rising_edge && info->assert_falling_edge)) 67 67 pps_event(info->pps, &ts, PPS_CAPTUREASSERT, NULL); 68 68 else if (info->capture_clear && 69 69 ((rising_edge && info->assert_falling_edge) || 70 - (!rising_edge && !info->assert_falling_edge))) 70 + (!rising_edge && !info->assert_falling_edge))) 71 71 pps_event(info->pps, &ts, PPS_CAPTURECLEAR, NULL); 72 72 73 73 return IRQ_HANDLED; 74 + } 75 + 76 + static int pps_gpio_setup(struct platform_device *pdev) 77 + { 78 + struct pps_gpio_device_data *data = platform_get_drvdata(pdev); 79 + struct device_node *np = pdev->dev.of_node; 80 + 81 + data->gpio_pin = devm_gpiod_get(&pdev->dev, 82 + NULL, /* request "gpios" */ 83 + GPIOD_IN); 84 + if (IS_ERR(data->gpio_pin)) { 85 + dev_err(&pdev->dev, 86 + "failed to request PPS GPIO\n"); 87 + return PTR_ERR(data->gpio_pin); 88 + } 89 + 90 + if (of_property_read_bool(np, "assert-falling-edge")) 91 + data->assert_falling_edge = true; 92 + return 0; 74 93 } 75 94 76 95 static unsigned long ··· 109 90 static int pps_gpio_probe(struct platform_device *pdev) 110 91 { 111 92 struct pps_gpio_device_data *data; 112 - const char *gpio_label; 113 93 int ret; 114 94 int pps_default_params; 115 95 const struct pps_gpio_platform_data *pdata = pdev->dev.platform_data; 116 - struct device_node *np = pdev->dev.of_node; 117 96 118 97 /* allocate space for device info */ 119 - data = devm_kzalloc(&pdev->dev, sizeof(struct pps_gpio_device_data), 120 - GFP_KERNEL); 98 + data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); 121 99 if (!data) 122 100 return -ENOMEM; 101 + platform_set_drvdata(pdev, data); 123 102 103 + /* GPIO setup */ 124 104 if (pdata) { 125 105 data->gpio_pin = pdata->gpio_pin; 126 - gpio_label = pdata->gpio_label; 127 106 128 107 data->assert_falling_edge = pdata->assert_falling_edge; 129 108 data->capture_clear = pdata->capture_clear; 130 109 } else { 131 - ret = of_get_gpio(np, 0); 132 - if (ret < 0) { 133 - dev_err(&pdev->dev, "failed to get GPIO from device tree\n"); 134 - return ret; 135 - } 136 - data->gpio_pin = ret; 137 - gpio_label = PPS_GPIO_NAME; 138 - 139 - if (of_get_property(np, "assert-falling-edge", NULL)) 140 - data->assert_falling_edge = true; 141 - } 142 - 143 - /* GPIO setup */ 144 - ret = devm_gpio_request(&pdev->dev, data->gpio_pin, gpio_label); 145 - if (ret) { 146 - dev_err(&pdev->dev, "failed to request GPIO %u\n", 147 - data->gpio_pin); 148 - return ret; 149 - } 150 - 151 - ret = gpio_direction_input(data->gpio_pin); 152 - if (ret) { 153 - dev_err(&pdev->dev, "failed to set pin direction\n"); 154 - return -EINVAL; 110 + ret = pps_gpio_setup(pdev); 111 + if (ret) 112 + return -EINVAL; 155 113 } 156 114 157 115 /* IRQ setup */ 158 - ret = gpio_to_irq(data->gpio_pin); 116 + ret = gpiod_to_irq(data->gpio_pin); 159 117 if (ret < 0) { 160 118 dev_err(&pdev->dev, "failed to map GPIO to IRQ: %d\n", ret); 161 119 return -EINVAL; ··· 169 173 return -EINVAL; 170 174 } 171 175 172 - platform_set_drvdata(pdev, data); 173 176 dev_info(data->pps->dev, "Registered IRQ %d as PPS source\n", 174 177 data->irq); 175 178 ··· 204 209 MODULE_AUTHOR("James Nuss <jamesnuss@nanometrics.ca>"); 205 210 MODULE_DESCRIPTION("Use GPIO pin as PPS source"); 206 211 MODULE_LICENSE("GPL"); 207 - MODULE_VERSION("1.0.0"); 212 + MODULE_VERSION("1.1.0");
+1 -2
include/linux/pps-gpio.h
··· 23 23 #define _PPS_GPIO_H 24 24 25 25 struct pps_gpio_platform_data { 26 + struct gpio_desc *gpio_pin; 26 27 bool assert_falling_edge; 27 28 bool capture_clear; 28 - unsigned int gpio_pin; 29 - const char *gpio_label; 30 29 }; 31 30 32 31 #endif /* _PPS_GPIO_H */