Commit 8a1861d997d698a120401f3c125085679f729d64
Committed by
Greg Kroah-Hartman
1 parent
277ed0d542
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
w1-gpio: Simplify & get rid of defines
There's no reason to have the OF defines; it complicates the driver. There's also no need for the funky platform_driver_probe. Add a few warnings in case there's a failure; helps us find out what went wrong. Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com> Signed-off-by: Evgeniy Polyakov <zbr@ioremap.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Showing 1 changed file with 26 additions and 32 deletions Side-by-side Diff
drivers/w1/masters/w1-gpio.c
... | ... | @@ -18,6 +18,7 @@ |
18 | 18 | #include <linux/of_gpio.h> |
19 | 19 | #include <linux/pinctrl/consumer.h> |
20 | 20 | #include <linux/err.h> |
21 | +#include <linux/of.h> | |
21 | 22 | |
22 | 23 | #include "../w1.h" |
23 | 24 | #include "../w1_int.h" |
... | ... | @@ -46,7 +47,6 @@ |
46 | 47 | return gpio_get_value(pdata->pin) ? 1 : 0; |
47 | 48 | } |
48 | 49 | |
49 | -#ifdef CONFIG_OF | |
50 | 50 | static struct of_device_id w1_gpio_dt_ids[] = { |
51 | 51 | { .compatible = "w1-gpio" }, |
52 | 52 | {} |
53 | 53 | |
... | ... | @@ -57,12 +57,7 @@ |
57 | 57 | { |
58 | 58 | struct w1_gpio_platform_data *pdata = pdev->dev.platform_data; |
59 | 59 | struct device_node *np = pdev->dev.of_node; |
60 | - const struct of_device_id *of_id = | |
61 | - of_match_device(w1_gpio_dt_ids, &pdev->dev); | |
62 | 60 | |
63 | - if (!of_id) | |
64 | - return 0; | |
65 | - | |
66 | 61 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
67 | 62 | if (!pdata) |
68 | 63 | return -ENOMEM; |
... | ... | @@ -76,12 +71,6 @@ |
76 | 71 | |
77 | 72 | return 0; |
78 | 73 | } |
79 | -#else | |
80 | -static int w1_gpio_probe_dt(struct platform_device *pdev) | |
81 | -{ | |
82 | - return 0; | |
83 | -} | |
84 | -#endif | |
85 | 74 | |
86 | 75 | static int __init w1_gpio_probe(struct platform_device *pdev) |
87 | 76 | { |
88 | 77 | |
89 | 78 | |
90 | 79 | |
91 | 80 | |
92 | 81 | |
93 | 82 | |
94 | 83 | |
95 | 84 | |
... | ... | @@ -94,28 +83,41 @@ |
94 | 83 | if (IS_ERR(pinctrl)) |
95 | 84 | dev_warn(&pdev->dev, "unable to select pin group\n"); |
96 | 85 | |
97 | - err = w1_gpio_probe_dt(pdev); | |
98 | - if (err < 0) | |
99 | - return err; | |
86 | + if (of_have_populated_dt()) { | |
87 | + err = w1_gpio_probe_dt(pdev); | |
88 | + if (err < 0) { | |
89 | + dev_err(&pdev->dev, "Failed to parse DT\n"); | |
90 | + return err; | |
91 | + } | |
92 | + } | |
100 | 93 | |
101 | 94 | pdata = pdev->dev.platform_data; |
102 | 95 | |
103 | - if (!pdata) | |
96 | + if (!pdata) { | |
97 | + dev_err(&pdev->dev, "No configuration data\n"); | |
104 | 98 | return -ENXIO; |
99 | + } | |
105 | 100 | |
106 | 101 | master = kzalloc(sizeof(struct w1_bus_master), GFP_KERNEL); |
107 | - if (!master) | |
102 | + if (!master) { | |
103 | + dev_err(&pdev->dev, "Out of memory\n"); | |
108 | 104 | return -ENOMEM; |
105 | + } | |
109 | 106 | |
110 | 107 | err = gpio_request(pdata->pin, "w1"); |
111 | - if (err) | |
108 | + if (err) { | |
109 | + dev_err(&pdev->dev, "gpio_request (pin) failed\n"); | |
112 | 110 | goto free_master; |
111 | + } | |
113 | 112 | |
114 | 113 | if (gpio_is_valid(pdata->ext_pullup_enable_pin)) { |
115 | 114 | err = gpio_request_one(pdata->ext_pullup_enable_pin, |
116 | 115 | GPIOF_INIT_LOW, "w1 pullup"); |
117 | - if (err < 0) | |
116 | + if (err < 0) { | |
117 | + dev_err(&pdev->dev, "gpio_request_one " | |
118 | + "(ext_pullup_enable_pin) failed\n"); | |
118 | 119 | goto free_gpio; |
120 | + } | |
119 | 121 | } |
120 | 122 | |
121 | 123 | master->data = pdata; |
122 | 124 | |
... | ... | @@ -130,8 +132,10 @@ |
130 | 132 | } |
131 | 133 | |
132 | 134 | err = w1_add_master_device(master); |
133 | - if (err) | |
135 | + if (err) { | |
136 | + dev_err(&pdev->dev, "w1_add_master device failed\n"); | |
134 | 137 | goto free_gpio_ext_pu; |
138 | + } | |
135 | 139 | |
136 | 140 | if (pdata->enable_external_pullup) |
137 | 141 | pdata->enable_external_pullup(1); |
138 | 142 | |
... | ... | @@ -205,23 +209,13 @@ |
205 | 209 | .owner = THIS_MODULE, |
206 | 210 | .of_match_table = of_match_ptr(w1_gpio_dt_ids), |
207 | 211 | }, |
212 | + .probe = w1_gpio_probe, | |
208 | 213 | .remove = __exit_p(w1_gpio_remove), |
209 | 214 | .suspend = w1_gpio_suspend, |
210 | 215 | .resume = w1_gpio_resume, |
211 | 216 | }; |
212 | 217 | |
213 | -static int __init w1_gpio_init(void) | |
214 | -{ | |
215 | - return platform_driver_probe(&w1_gpio_driver, w1_gpio_probe); | |
216 | -} | |
217 | - | |
218 | -static void __exit w1_gpio_exit(void) | |
219 | -{ | |
220 | - platform_driver_unregister(&w1_gpio_driver); | |
221 | -} | |
222 | - | |
223 | -module_init(w1_gpio_init); | |
224 | -module_exit(w1_gpio_exit); | |
218 | +module_platform_driver(w1_gpio_driver); | |
225 | 219 | |
226 | 220 | MODULE_DESCRIPTION("GPIO w1 bus master driver"); |
227 | 221 | MODULE_AUTHOR("Ville Syrjala <syrjala@sci.fi>"); |