@@ -157,78 +157,46 @@ static int __devinit pm860x_probe(struct i2c_client *client,
157157 const struct i2c_device_id * id )
158158{
159159 struct pm860x_platform_data * pdata = client -> dev .platform_data ;
160- static struct pm860x_chip * chip ;
161- struct i2c_board_info i2c_info = {
162- .type = "88PM860x" ,
163- .platform_data = client -> dev .platform_data ,
164- };
165- int addr_c , found_companion = 0 ;
166-
167- if (pdata == NULL ) {
160+ struct pm860x_chip * chip ;
161+
162+ if (!pdata ) {
168163 pr_info ("No platform data in %s!\n" , __func__ );
169164 return - EINVAL ;
170165 }
171166
167+ chip = kzalloc (sizeof (struct pm860x_chip ), GFP_KERNEL );
168+ if (chip == NULL )
169+ return - ENOMEM ;
170+
171+ chip -> id = verify_addr (client );
172+ chip -> client = client ;
173+ i2c_set_clientdata (client , chip );
174+ chip -> dev = & client -> dev ;
175+ mutex_init (& chip -> io_lock );
176+ dev_set_drvdata (chip -> dev , chip );
177+
172178 /*
173179 * Both client and companion client shares same platform driver.
174180 * Driver distinguishes them by pdata->companion_addr.
175181 * pdata->companion_addr is only assigned if companion chip exists.
176182 * At the same time, the companion_addr shouldn't equal to client
177183 * address.
178184 */
179- addr_c = pdata -> companion_addr ;
180- if (addr_c && (addr_c != client -> addr )) {
181- i2c_info .addr = addr_c ;
182- found_companion = 1 ;
183- }
184-
185- if (found_companion || (addr_c == 0 )) {
186- chip = kzalloc (sizeof (struct pm860x_chip ), GFP_KERNEL );
187- if (chip == NULL )
188- return - ENOMEM ;
189-
190- chip -> id = verify_addr (client );
191- chip -> companion_addr = addr_c ;
192- chip -> client = client ;
193- i2c_set_clientdata (client , chip );
194- chip -> dev = & client -> dev ;
195- mutex_init (& chip -> io_lock );
196- dev_set_drvdata (chip -> dev , chip );
197-
198- if (found_companion ) {
199- /*
200- * If this driver is built in, probe function is
201- * recursive.
202- * If this driver is built as module, the next probe
203- * function is called after the first one finished.
204- */
205- chip -> companion = i2c_new_device (client -> adapter ,
206- & i2c_info );
207- }
208- }
209-
210- /*
211- * If companion chip existes, it's called by companion probe.
212- * If there's no companion chip, it's called by client probe.
213- */
214- if ((addr_c == 0 ) || (addr_c == client -> addr )) {
215- chip -> companion = client ;
185+ if (pdata -> companion_addr && (pdata -> companion_addr != client -> addr )) {
186+ chip -> companion_addr = pdata -> companion_addr ;
187+ chip -> companion = i2c_new_dummy (chip -> client -> adapter ,
188+ chip -> companion_addr );
216189 i2c_set_clientdata (chip -> companion , chip );
217- pm860x_device_init (chip , pdata );
218190 }
191+
192+ pm860x_device_init (chip , pdata );
219193 return 0 ;
220194}
221195
222196static int __devexit pm860x_remove (struct i2c_client * client )
223197{
224198 struct pm860x_chip * chip = i2c_get_clientdata (client );
225199
226- /*
227- * If companion existes, companion client is removed first.
228- * Because companion client is registered last and removed first.
229- */
230- if (chip -> companion_addr == client -> addr )
231- return 0 ;
232200 pm860x_device_exit (chip );
233201 i2c_unregister_device (chip -> companion );
234202 i2c_set_clientdata (chip -> companion , NULL );
0 commit comments