aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/w1
diff options
context:
space:
mode:
authorDaniel Mack <zonque@gmail.com>2012-07-23 10:36:35 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-08-16 13:00:23 -0400
commit5f3d1382e3ca39a54032784414f0ad4e7078b37e (patch)
tree7d1efb0ca10940719547e04d2f82074568e0da51 /drivers/w1
parent73f2989d37a36614fe13f24891ebe1e44fe5887d (diff)
onewire: w1-gpio: add DT bindings
This patch add DT bindings to the w1-gpio driver, along with some documentation on how to use them. Signed-off-by: Daniel Mack <zonque@gmail.com> Acked-by: Evgeniy Polyakov <zbr@ioremap.net> Acked-by: Ville Syrjälä <syrjala@sci.fi> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/w1')
-rw-r--r--drivers/w1/masters/w1-gpio.c48
1 files changed, 47 insertions, 1 deletions
diff --git a/drivers/w1/masters/w1-gpio.c b/drivers/w1/masters/w1-gpio.c
index df600d14974d..f01c336233da 100644
--- a/drivers/w1/masters/w1-gpio.c
+++ b/drivers/w1/masters/w1-gpio.c
@@ -14,6 +14,8 @@
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/w1-gpio.h> 15#include <linux/w1-gpio.h>
16#include <linux/gpio.h> 16#include <linux/gpio.h>
17#include <linux/of_platform.h>
18#include <linux/of_gpio.h>
17 19
18#include "../w1.h" 20#include "../w1.h"
19#include "../w1_int.h" 21#include "../w1_int.h"
@@ -42,12 +44,55 @@ static u8 w1_gpio_read_bit(void *data)
42 return gpio_get_value(pdata->pin) ? 1 : 0; 44 return gpio_get_value(pdata->pin) ? 1 : 0;
43} 45}
44 46
47#ifdef CONFIG_OF
48static struct of_device_id w1_gpio_dt_ids[] = {
49 { .compatible = "w1-gpio" },
50 {}
51};
52MODULE_DEVICE_TABLE(of, w1_gpio_dt_ids);
53
54static int w1_gpio_probe_dt(struct platform_device *pdev)
55{
56 struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
57 struct device_node *np = pdev->dev.of_node;
58 const struct of_device_id *of_id =
59 of_match_device(w1_gpio_dt_ids, &pdev->dev);
60
61 if (!of_id)
62 return 0;
63
64 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
65 if (!pdata)
66 return -ENOMEM;
67
68 if (of_get_property(np, "linux,open-drain", NULL))
69 pdata->is_open_drain = 1;
70
71 pdata->pin = of_get_gpio(np, 0);
72 pdata->ext_pullup_enable_pin = of_get_gpio(np, 1);
73 pdev->dev.platform_data = pdata;
74
75 return 0;
76}
77#else
78static int w1_gpio_probe_dt(struct platform_device *pdev)
79{
80 return 0;
81}
82#endif
83
45static int __init w1_gpio_probe(struct platform_device *pdev) 84static int __init w1_gpio_probe(struct platform_device *pdev)
46{ 85{
47 struct w1_bus_master *master; 86 struct w1_bus_master *master;
48 struct w1_gpio_platform_data *pdata = pdev->dev.platform_data; 87 struct w1_gpio_platform_data *pdata;
49 int err; 88 int err;
50 89
90 err = w1_gpio_probe_dt(pdev);
91 if (err < 0)
92 return err;
93
94 pdata = pdev->dev.platform_data;
95
51 if (!pdata) 96 if (!pdata)
52 return -ENXIO; 97 return -ENXIO;
53 98
@@ -135,6 +180,7 @@ static struct platform_driver w1_gpio_driver = {
135 .driver = { 180 .driver = {
136 .name = "w1-gpio", 181 .name = "w1-gpio",
137 .owner = THIS_MODULE, 182 .owner = THIS_MODULE,
183 .of_match_table = of_match_ptr(w1_gpio_dt_ids),
138 }, 184 },
139 .remove = __exit_p(w1_gpio_remove), 185 .remove = __exit_p(w1_gpio_remove),
140 .suspend = w1_gpio_suspend, 186 .suspend = w1_gpio_suspend,