diff options
Diffstat (limited to 'drivers/w1/masters/w1-gpio.c')
-rw-r--r-- | drivers/w1/masters/w1-gpio.c | 48 |
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 | ||
48 | static struct of_device_id w1_gpio_dt_ids[] = { | ||
49 | { .compatible = "w1-gpio" }, | ||
50 | {} | ||
51 | }; | ||
52 | MODULE_DEVICE_TABLE(of, w1_gpio_dt_ids); | ||
53 | |||
54 | static 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 | ||
78 | static int w1_gpio_probe_dt(struct platform_device *pdev) | ||
79 | { | ||
80 | return 0; | ||
81 | } | ||
82 | #endif | ||
83 | |||
45 | static int __init w1_gpio_probe(struct platform_device *pdev) | 84 | static 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, |