diff options
author | Pantelis Antoniou <panto@antoniou-consulting.com> | 2012-11-21 16:13:47 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-11-26 19:16:35 -0500 |
commit | 8a1861d997d698a120401f3c125085679f729d64 (patch) | |
tree | 93581cfb0f56a23ce990650521bffbd9fb77e178 /drivers/w1 | |
parent | 277ed0d542778182c863c30bdbd2441dee3f964c (diff) |
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>
Diffstat (limited to 'drivers/w1')
-rw-r--r-- | drivers/w1/masters/w1-gpio.c | 58 |
1 files changed, 26 insertions, 32 deletions
diff --git a/drivers/w1/masters/w1-gpio.c b/drivers/w1/masters/w1-gpio.c index aec35bd46506..85b363a5bd0f 100644 --- a/drivers/w1/masters/w1-gpio.c +++ b/drivers/w1/masters/w1-gpio.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/of_gpio.h> | 18 | #include <linux/of_gpio.h> |
19 | #include <linux/pinctrl/consumer.h> | 19 | #include <linux/pinctrl/consumer.h> |
20 | #include <linux/err.h> | 20 | #include <linux/err.h> |
21 | #include <linux/of.h> | ||
21 | 22 | ||
22 | #include "../w1.h" | 23 | #include "../w1.h" |
23 | #include "../w1_int.h" | 24 | #include "../w1_int.h" |
@@ -46,7 +47,6 @@ static u8 w1_gpio_read_bit(void *data) | |||
46 | return gpio_get_value(pdata->pin) ? 1 : 0; | 47 | return gpio_get_value(pdata->pin) ? 1 : 0; |
47 | } | 48 | } |
48 | 49 | ||
49 | #ifdef CONFIG_OF | ||
50 | static struct of_device_id w1_gpio_dt_ids[] = { | 50 | static struct of_device_id w1_gpio_dt_ids[] = { |
51 | { .compatible = "w1-gpio" }, | 51 | { .compatible = "w1-gpio" }, |
52 | {} | 52 | {} |
@@ -57,11 +57,6 @@ static int w1_gpio_probe_dt(struct platform_device *pdev) | |||
57 | { | 57 | { |
58 | struct w1_gpio_platform_data *pdata = pdev->dev.platform_data; | 58 | struct w1_gpio_platform_data *pdata = pdev->dev.platform_data; |
59 | struct device_node *np = pdev->dev.of_node; | 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 | |||
63 | if (!of_id) | ||
64 | return 0; | ||
65 | 60 | ||
66 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); | 61 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
67 | if (!pdata) | 62 | if (!pdata) |
@@ -76,12 +71,6 @@ static int w1_gpio_probe_dt(struct platform_device *pdev) | |||
76 | 71 | ||
77 | return 0; | 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 | static int __init w1_gpio_probe(struct platform_device *pdev) | 75 | static int __init w1_gpio_probe(struct platform_device *pdev) |
87 | { | 76 | { |
@@ -94,28 +83,41 @@ static int __init w1_gpio_probe(struct platform_device *pdev) | |||
94 | if (IS_ERR(pinctrl)) | 83 | if (IS_ERR(pinctrl)) |
95 | dev_warn(&pdev->dev, "unable to select pin group\n"); | 84 | dev_warn(&pdev->dev, "unable to select pin group\n"); |
96 | 85 | ||
97 | err = w1_gpio_probe_dt(pdev); | 86 | if (of_have_populated_dt()) { |
98 | if (err < 0) | 87 | err = w1_gpio_probe_dt(pdev); |
99 | return err; | 88 | if (err < 0) { |
89 | dev_err(&pdev->dev, "Failed to parse DT\n"); | ||
90 | return err; | ||
91 | } | ||
92 | } | ||
100 | 93 | ||
101 | pdata = pdev->dev.platform_data; | 94 | pdata = pdev->dev.platform_data; |
102 | 95 | ||
103 | if (!pdata) | 96 | if (!pdata) { |
97 | dev_err(&pdev->dev, "No configuration data\n"); | ||
104 | return -ENXIO; | 98 | return -ENXIO; |
99 | } | ||
105 | 100 | ||
106 | master = kzalloc(sizeof(struct w1_bus_master), GFP_KERNEL); | 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 | return -ENOMEM; | 104 | return -ENOMEM; |
105 | } | ||
109 | 106 | ||
110 | err = gpio_request(pdata->pin, "w1"); | 107 | err = gpio_request(pdata->pin, "w1"); |
111 | if (err) | 108 | if (err) { |
109 | dev_err(&pdev->dev, "gpio_request (pin) failed\n"); | ||
112 | goto free_master; | 110 | goto free_master; |
111 | } | ||
113 | 112 | ||
114 | if (gpio_is_valid(pdata->ext_pullup_enable_pin)) { | 113 | if (gpio_is_valid(pdata->ext_pullup_enable_pin)) { |
115 | err = gpio_request_one(pdata->ext_pullup_enable_pin, | 114 | err = gpio_request_one(pdata->ext_pullup_enable_pin, |
116 | GPIOF_INIT_LOW, "w1 pullup"); | 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 | goto free_gpio; | 119 | goto free_gpio; |
120 | } | ||
119 | } | 121 | } |
120 | 122 | ||
121 | master->data = pdata; | 123 | master->data = pdata; |
@@ -130,8 +132,10 @@ static int __init w1_gpio_probe(struct platform_device *pdev) | |||
130 | } | 132 | } |
131 | 133 | ||
132 | err = w1_add_master_device(master); | 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 | goto free_gpio_ext_pu; | 137 | goto free_gpio_ext_pu; |
138 | } | ||
135 | 139 | ||
136 | if (pdata->enable_external_pullup) | 140 | if (pdata->enable_external_pullup) |
137 | pdata->enable_external_pullup(1); | 141 | pdata->enable_external_pullup(1); |
@@ -205,23 +209,13 @@ static struct platform_driver w1_gpio_driver = { | |||
205 | .owner = THIS_MODULE, | 209 | .owner = THIS_MODULE, |
206 | .of_match_table = of_match_ptr(w1_gpio_dt_ids), | 210 | .of_match_table = of_match_ptr(w1_gpio_dt_ids), |
207 | }, | 211 | }, |
212 | .probe = w1_gpio_probe, | ||
208 | .remove = __exit_p(w1_gpio_remove), | 213 | .remove = __exit_p(w1_gpio_remove), |
209 | .suspend = w1_gpio_suspend, | 214 | .suspend = w1_gpio_suspend, |
210 | .resume = w1_gpio_resume, | 215 | .resume = w1_gpio_resume, |
211 | }; | 216 | }; |
212 | 217 | ||
213 | static int __init w1_gpio_init(void) | 218 | module_platform_driver(w1_gpio_driver); |
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); | ||
225 | 219 | ||
226 | MODULE_DESCRIPTION("GPIO w1 bus master driver"); | 220 | MODULE_DESCRIPTION("GPIO w1 bus master driver"); |
227 | MODULE_AUTHOR("Ville Syrjala <syrjala@sci.fi>"); | 221 | MODULE_AUTHOR("Ville Syrjala <syrjala@sci.fi>"); |