12
12
#include <linux/init.h>
13
13
#include <linux/interrupt.h>
14
14
#include <linux/module.h>
15
+ #include <linux/mutex.h>
15
16
#include <linux/regmap.h>
16
17
#include <linux/regulator/driver.h>
17
18
#include <linux/regulator/machine.h>
@@ -293,21 +294,24 @@ static int attiny_i2c_probe(struct i2c_client *i2c)
293
294
if (!state )
294
295
return - ENOMEM ;
295
296
296
- mutex_init (& state -> lock );
297
+ ret = devm_mutex_init (& i2c -> dev , & state -> lock );
298
+ if (ret )
299
+ return ret ;
300
+
297
301
i2c_set_clientdata (i2c , state );
298
302
299
303
regmap = devm_regmap_init_i2c (i2c , & attiny_regmap_config );
300
304
if (IS_ERR (regmap )) {
301
305
ret = PTR_ERR (regmap );
302
306
dev_err (& i2c -> dev , "Failed to allocate register map: %d\n" ,
303
307
ret );
304
- goto error ;
308
+ return ret ;
305
309
}
306
310
307
311
ret = attiny_i2c_read (i2c , REG_ID , & data );
308
312
if (ret < 0 ) {
309
313
dev_err (& i2c -> dev , "Failed to read REG_ID reg: %d\n" , ret );
310
- goto error ;
314
+ return ret ;
311
315
}
312
316
313
317
switch (data ) {
@@ -316,8 +320,7 @@ static int attiny_i2c_probe(struct i2c_client *i2c)
316
320
break ;
317
321
default :
318
322
dev_err (& i2c -> dev , "Unknown Atmel firmware revision: 0x%02x\n" , data );
319
- ret = - ENODEV ;
320
- goto error ;
323
+ return - ENODEV ;
321
324
}
322
325
323
326
regmap_write (regmap , REG_POWERON , 0 );
@@ -333,8 +336,7 @@ static int attiny_i2c_probe(struct i2c_client *i2c)
333
336
rdev = devm_regulator_register (& i2c -> dev , & attiny_regulator , & config );
334
337
if (IS_ERR (rdev )) {
335
338
dev_err (& i2c -> dev , "Failed to register ATTINY regulator\n" );
336
- ret = PTR_ERR (rdev );
337
- goto error ;
339
+ return PTR_ERR (rdev );
338
340
}
339
341
340
342
props .type = BACKLIGHT_RAW ;
@@ -345,10 +347,8 @@ static int attiny_i2c_probe(struct i2c_client *i2c)
345
347
bl = devm_backlight_device_register (& i2c -> dev , dev_name (& i2c -> dev ),
346
348
& i2c -> dev , state , & attiny_bl ,
347
349
& props );
348
- if (IS_ERR (bl )) {
349
- ret = PTR_ERR (bl );
350
- goto error ;
351
- }
350
+ if (IS_ERR (bl ))
351
+ return PTR_ERR (bl );
352
352
353
353
bl -> props .brightness = 0xff ;
354
354
@@ -363,26 +363,12 @@ static int attiny_i2c_probe(struct i2c_client *i2c)
363
363
state -> gc .can_sleep = true;
364
364
365
365
ret = devm_gpiochip_add_data (& i2c -> dev , & state -> gc , state );
366
- if (ret ) {
366
+ if (ret )
367
367
dev_err (& i2c -> dev , "Failed to create gpiochip: %d\n" , ret );
368
- goto error ;
369
- }
370
-
371
- return 0 ;
372
-
373
- error :
374
- mutex_destroy (& state -> lock );
375
368
376
369
return ret ;
377
370
}
378
371
379
- static void attiny_i2c_remove (struct i2c_client * client )
380
- {
381
- struct attiny_lcd * state = i2c_get_clientdata (client );
382
-
383
- mutex_destroy (& state -> lock );
384
- }
385
-
386
372
static const struct of_device_id attiny_dt_ids [] = {
387
373
{ .compatible = "raspberrypi,7inch-touchscreen-panel-regulator" },
388
374
{},
@@ -396,7 +382,6 @@ static struct i2c_driver attiny_regulator_driver = {
396
382
.of_match_table = attiny_dt_ids ,
397
383
},
398
384
.probe = attiny_i2c_probe ,
399
- .remove = attiny_i2c_remove ,
400
385
};
401
386
402
387
module_i2c_driver (attiny_regulator_driver );
0 commit comments