1818#include <linux/of_gpio.h>
1919#include <linux/pinctrl/consumer.h>
2020#include <linux/err.h>
21+ #include <linux/of.h>
2122
2223#include "../w1.h"
2324#include "../w1_int.h"
@@ -46,7 +47,6 @@ static u8 w1_gpio_read_bit(void *data)
4647 return gpio_get_value (pdata -> pin ) ? 1 : 0 ;
4748}
4849
49- #ifdef CONFIG_OF
5050static struct of_device_id w1_gpio_dt_ids [] = {
5151 { .compatible = "w1-gpio" },
5252 {}
@@ -57,11 +57,6 @@ static int w1_gpio_probe_dt(struct platform_device *pdev)
5757{
5858 struct w1_gpio_platform_data * pdata = pdev -> dev .platform_data ;
5959 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 ;
6560
6661 pdata = devm_kzalloc (& pdev -> dev , sizeof (* pdata ), GFP_KERNEL );
6762 if (!pdata )
@@ -76,12 +71,6 @@ static int w1_gpio_probe_dt(struct platform_device *pdev)
7671
7772 return 0 ;
7873}
79- #else
80- static int w1_gpio_probe_dt (struct platform_device * pdev )
81- {
82- return 0 ;
83- }
84- #endif
8574
8675static int __init w1_gpio_probe (struct platform_device * pdev )
8776{
@@ -94,28 +83,41 @@ static int __init w1_gpio_probe(struct platform_device *pdev)
9483 if (IS_ERR (pinctrl ))
9584 dev_warn (& pdev -> dev , "unable to select pin group\n" );
9685
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+ }
10093
10194 pdata = pdev -> dev .platform_data ;
10295
103- if (!pdata )
96+ if (!pdata ) {
97+ dev_err (& pdev -> dev , "No configuration data\n" );
10498 return - ENXIO ;
99+ }
105100
106101 master = kzalloc (sizeof (struct w1_bus_master ), GFP_KERNEL );
107- if (!master )
102+ if (!master ) {
103+ dev_err (& pdev -> dev , "Out of memory\n" );
108104 return - ENOMEM ;
105+ }
109106
110107 err = gpio_request (pdata -> pin , "w1" );
111- if (err )
108+ if (err ) {
109+ dev_err (& pdev -> dev , "gpio_request (pin) failed\n" );
112110 goto free_master ;
111+ }
113112
114113 if (gpio_is_valid (pdata -> ext_pullup_enable_pin )) {
115114 err = gpio_request_one (pdata -> ext_pullup_enable_pin ,
116115 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" );
118119 goto free_gpio ;
120+ }
119121 }
120122
121123 master -> data = pdata ;
@@ -130,8 +132,10 @@ static int __init w1_gpio_probe(struct platform_device *pdev)
130132 }
131133
132134 err = w1_add_master_device (master );
133- if (err )
135+ if (err ) {
136+ dev_err (& pdev -> dev , "w1_add_master device failed\n" );
134137 goto free_gpio_ext_pu ;
138+ }
135139
136140 if (pdata -> enable_external_pullup )
137141 pdata -> enable_external_pullup (1 );
@@ -205,23 +209,13 @@ static struct platform_driver w1_gpio_driver = {
205209 .owner = THIS_MODULE ,
206210 .of_match_table = of_match_ptr (w1_gpio_dt_ids ),
207211 },
212+ .probe = w1_gpio_probe ,
208213 .remove = __exit_p (w1_gpio_remove ),
209214 .suspend = w1_gpio_suspend ,
210215 .resume = w1_gpio_resume ,
211216};
212217
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 );
225219
226220MODULE_DESCRIPTION ("GPIO w1 bus master driver" );
227221MODULE_AUTHOR ("Ville Syrjala <syrjala@sci.fi>" );
0 commit comments