68
68
* which won't work on pure SMBus systems.
69
69
*/
70
70
71
- struct at24_client {
72
- struct i2c_client * client ;
73
- struct regmap * regmap ;
74
- };
75
-
76
71
struct at24_data {
77
72
/*
78
73
* Lock protects against activities from other Linux tasks,
@@ -94,9 +89,9 @@ struct at24_data {
94
89
95
90
/*
96
91
* Some chips tie up multiple I2C addresses; dummy devices reserve
97
- * them for us, and we'll use them with SMBus calls .
92
+ * them for us.
98
93
*/
99
- struct at24_client client [];
94
+ struct regmap * client_regmaps [];
100
95
};
101
96
102
97
/*
@@ -275,8 +270,8 @@ MODULE_DEVICE_TABLE(acpi, at24_acpi_ids);
275
270
* set the byte address; on a multi-master board, another master
276
271
* may have changed the chip's "current" address pointer.
277
272
*/
278
- static struct at24_client * at24_translate_offset (struct at24_data * at24 ,
279
- unsigned int * offset )
273
+ static struct regmap * at24_translate_offset (struct at24_data * at24 ,
274
+ unsigned int * offset )
280
275
{
281
276
unsigned int i ;
282
277
@@ -288,12 +283,12 @@ static struct at24_client *at24_translate_offset(struct at24_data *at24,
288
283
* offset &= 0xff ;
289
284
}
290
285
291
- return & at24 -> client [i ];
286
+ return at24 -> client_regmaps [i ];
292
287
}
293
288
294
289
static struct device * at24_base_client_dev (struct at24_data * at24 )
295
290
{
296
- return & at24 -> client [0 ]. client -> dev ;
291
+ return regmap_get_device ( at24 -> client_regmaps [0 ]) ;
297
292
}
298
293
299
294
static size_t at24_adjust_read_count (struct at24_data * at24 ,
@@ -324,14 +319,10 @@ static ssize_t at24_regmap_read(struct at24_data *at24, char *buf,
324
319
unsigned int offset , size_t count )
325
320
{
326
321
unsigned long timeout , read_time ;
327
- struct at24_client * at24_client ;
328
- struct i2c_client * client ;
329
322
struct regmap * regmap ;
330
323
int ret ;
331
324
332
- at24_client = at24_translate_offset (at24 , & offset );
333
- regmap = at24_client -> regmap ;
334
- client = at24_client -> client ;
325
+ regmap = at24_translate_offset (at24 , & offset );
335
326
count = at24_adjust_read_count (at24 , offset , count );
336
327
337
328
/* adjust offset for mac and serial read ops */
@@ -346,7 +337,7 @@ static ssize_t at24_regmap_read(struct at24_data *at24, char *buf,
346
337
read_time = jiffies ;
347
338
348
339
ret = regmap_bulk_read (regmap , offset , buf , count );
349
- dev_dbg (& client -> dev , "read %zu@%d --> %d (%ld)\n" ,
340
+ dev_dbg (regmap_get_device ( regmap ) , "read %zu@%d --> %d (%ld)\n" ,
350
341
count , offset , ret , jiffies );
351
342
if (!ret )
352
343
return count ;
@@ -387,14 +378,10 @@ static ssize_t at24_regmap_write(struct at24_data *at24, const char *buf,
387
378
unsigned int offset , size_t count )
388
379
{
389
380
unsigned long timeout , write_time ;
390
- struct at24_client * at24_client ;
391
- struct i2c_client * client ;
392
381
struct regmap * regmap ;
393
382
int ret ;
394
383
395
- at24_client = at24_translate_offset (at24 , & offset );
396
- regmap = at24_client -> regmap ;
397
- client = at24_client -> client ;
384
+ regmap = at24_translate_offset (at24 , & offset );
398
385
count = at24_adjust_write_count (at24 , offset , count );
399
386
timeout = jiffies + msecs_to_jiffies (at24_write_timeout );
400
387
@@ -406,7 +393,7 @@ static ssize_t at24_regmap_write(struct at24_data *at24, const char *buf,
406
393
write_time = jiffies ;
407
394
408
395
ret = regmap_bulk_write (regmap , offset , buf , count );
409
- dev_dbg (& client -> dev , "write %zu@%d --> %d (%ld)\n" ,
396
+ dev_dbg (regmap_get_device ( regmap ) , "write %zu@%d --> %d (%ld)\n" ,
410
397
count , offset , ret , jiffies );
411
398
if (!ret )
412
399
return count ;
@@ -538,16 +525,14 @@ static const struct at24_chip_data *at24_get_chip_data(struct device *dev)
538
525
}
539
526
540
527
static int at24_make_dummy_client (struct at24_data * at24 , unsigned int index ,
528
+ struct i2c_client * base_client ,
541
529
struct regmap_config * regmap_config )
542
530
{
543
- struct i2c_client * base_client , * dummy_client ;
531
+ struct i2c_client * dummy_client ;
544
532
struct regmap * regmap ;
545
- struct device * dev ;
546
-
547
- base_client = at24 -> client [0 ].client ;
548
- dev = & base_client -> dev ;
549
533
550
- dummy_client = devm_i2c_new_dummy_device (dev , base_client -> adapter ,
534
+ dummy_client = devm_i2c_new_dummy_device (& base_client -> dev ,
535
+ base_client -> adapter ,
551
536
base_client -> addr + index );
552
537
if (IS_ERR (dummy_client ))
553
538
return PTR_ERR (dummy_client );
@@ -556,8 +541,7 @@ static int at24_make_dummy_client(struct at24_data *at24, unsigned int index,
556
541
if (IS_ERR (regmap ))
557
542
return PTR_ERR (regmap );
558
543
559
- at24 -> client [index ].client = dummy_client ;
560
- at24 -> client [index ].regmap = regmap ;
544
+ at24 -> client_regmaps [index ] = regmap ;
561
545
562
546
return 0 ;
563
547
}
@@ -680,7 +664,7 @@ static int at24_probe(struct i2c_client *client)
680
664
if (IS_ERR (regmap ))
681
665
return PTR_ERR (regmap );
682
666
683
- at24 = devm_kzalloc (dev , struct_size (at24 , client , num_addresses ),
667
+ at24 = devm_kzalloc (dev , struct_size (at24 , client_regmaps , num_addresses ),
684
668
GFP_KERNEL );
685
669
if (!at24 )
686
670
return - ENOMEM ;
@@ -692,8 +676,7 @@ static int at24_probe(struct i2c_client *client)
692
676
at24 -> read_post = cdata -> read_post ;
693
677
at24 -> num_addresses = num_addresses ;
694
678
at24 -> offset_adj = at24_get_offset_adj (flags , byte_len );
695
- at24 -> client [0 ].client = client ;
696
- at24 -> client [0 ].regmap = regmap ;
679
+ at24 -> client_regmaps [0 ] = regmap ;
697
680
698
681
at24 -> vcc_reg = devm_regulator_get (dev , "vcc" );
699
682
if (IS_ERR (at24 -> vcc_reg ))
@@ -709,7 +692,7 @@ static int at24_probe(struct i2c_client *client)
709
692
710
693
/* use dummy devices for multiple-address chips */
711
694
for (i = 1 ; i < num_addresses ; i ++ ) {
712
- err = at24_make_dummy_client (at24 , i , & regmap_config );
695
+ err = at24_make_dummy_client (at24 , i , client , & regmap_config );
713
696
if (err )
714
697
return err ;
715
698
}
0 commit comments