-
Notifications
You must be signed in to change notification settings - Fork 65
/
0003-pps-gpio-add-device-tree-binding-and-support.patch
130 lines (122 loc) · 3.57 KB
/
0003-pps-gpio-add-device-tree-binding-and-support.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
From 01810c998042b42333154bb3510879f7c4b20166 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20L=C3=BCbbe?= <jlu@pengutronix.de>
Date: Mon, 17 Jun 2013 20:30:30 +0000
Subject: [PATCH 3/3] pps-gpio: add device-tree binding and support
Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
Acked-by: Rodolfo Giometti <giometti@enneenne.com>
Signed-off-by: Matt Ranostay <mranostay@gmail.com>
---
Documentation/devicetree/bindings/pps/pps-gpio.txt | 20 ++++++++
drivers/pps/clients/pps-gpio.c | 55 +++++++++++++++++++++-
2 files changed, 73 insertions(+), 2 deletions(-)
create mode 100644 Documentation/devicetree/bindings/pps/pps-gpio.txt
diff --git a/Documentation/devicetree/bindings/pps/pps-gpio.txt b/Documentation/devicetree/bindings/pps/pps-gpio.txt
new file mode 100644
index 0000000..40bf9c3
--- /dev/null
+++ b/Documentation/devicetree/bindings/pps/pps-gpio.txt
@@ -0,0 +1,20 @@
+Device-Tree Bindings for a PPS Signal on GPIO
+
+These properties describe a PPS (pulse-per-second) signal connected to
+a GPIO pin.
+
+Required properties:
+- compatible: should be "pps-gpio"
+- gpios: one PPS GPIO in the format described by ../gpio/gpio.txt
+
+Optional properties:
+- assert-falling-edge: when present, assert is indicated by a falling edge
+ (instead of by a rising edge)
+
+Example:
+ pps {
+ compatible = "pps-gpio";
+ gpios = <&gpio2 6 0>;
+
+ assert-falling-edge;
+ };
diff --git a/drivers/pps/clients/pps-gpio.c b/drivers/pps/clients/pps-gpio.c
index 7e0e93b..9b405b3 100644
--- a/drivers/pps/clients/pps-gpio.c
+++ b/drivers/pps/clients/pps-gpio.c
@@ -33,6 +33,8 @@
#include <linux/pps-gpio.h>
#include <linux/gpio.h>
#include <linux/list.h>
+#include <linux/of_device.h>
+#include <linux/of_gpio.h>
/* Info for each registered platform device */
struct pps_gpio_device_data {
@@ -104,14 +106,62 @@ get_irqf_trigger_flags(const struct pps_gpio_platform_data *pdata)
return flags;
}
+#ifdef CONFIG_OF
+static const struct of_device_id pps_gpio_dt_ids[] = {
+ { .compatible = "pps-gpio", },
+ { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, pps_gpio_dt_ids);
+
+static struct pps_gpio_platform_data *
+of_get_pps_gpio_pdata(struct platform_device *pdev)
+{
+ struct device_node *np = pdev->dev.of_node;
+ struct pps_gpio_platform_data *pdata;
+ int ret;
+
+ pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
+ if (!pdata)
+ return NULL;
+
+ ret = of_get_gpio(np, 0);
+ if (ret < 0) {
+ pr_err("failed to get GPIO from device tree\n");
+ return NULL;
+ }
+
+ pdata->gpio_pin = ret;
+ pdata->gpio_label = PPS_GPIO_NAME;
+
+ if (of_get_property(np, "assert-falling-edge", NULL))
+ pdata->assert_falling_edge = true;
+
+ return pdata;
+}
+#else
+static struct pps_gpio_platform_data *
+of_get_pps_gpio_pdata(struct platform_device *pdev)
+{
+ return NULL;
+}
+#endif
+
static int pps_gpio_probe(struct platform_device *pdev)
{
struct pps_gpio_device_data *data;
int irq;
int ret;
int pps_default_params;
- const struct pps_gpio_platform_data *pdata = pdev->dev.platform_data;
+ struct pps_gpio_platform_data *pdata;
+ const struct of_device_id *match;
+
+ match = of_match_device(pps_gpio_dt_ids, &pdev->dev);
+ if (match)
+ pdev->dev.platform_data = of_get_pps_gpio_pdata(pdev);
+ pdata = pdev->dev.platform_data;
+ if (!pdata)
+ return -ENODEV;
/* GPIO setup */
ret = pps_gpio_setup(pdev);
@@ -187,7 +237,8 @@ static struct platform_driver pps_gpio_driver = {
.remove = pps_gpio_remove,
.driver = {
.name = PPS_GPIO_NAME,
- .owner = THIS_MODULE
+ .owner = THIS_MODULE,
+ .of_match_table = of_match_ptr(pps_gpio_dt_ids),
},
};
--
1.8.2.1