6868 * which won't work on pure SMBus systems.
6969 */
7070
71- struct at24_client {
72- struct i2c_client * client ;
73- struct regmap * regmap ;
74- };
75-
7671struct at24_data {
7772 /*
7873 * Lock protects against activities from other Linux tasks,
@@ -94,9 +89,9 @@ struct at24_data {
9489
9590 /*
9691 * 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.
9893 */
99- struct at24_client client [];
94+ struct regmap * client_regmaps [];
10095};
10196
10297/*
@@ -275,8 +270,8 @@ MODULE_DEVICE_TABLE(acpi, at24_acpi_ids);
275270 * set the byte address; on a multi-master board, another master
276271 * may have changed the chip's "current" address pointer.
277272 */
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 )
280275{
281276 unsigned int i ;
282277
@@ -288,12 +283,12 @@ static struct at24_client *at24_translate_offset(struct at24_data *at24,
288283 * offset &= 0xff ;
289284 }
290285
291- return & at24 -> client [i ];
286+ return at24 -> client_regmaps [i ];
292287}
293288
294289static struct device * at24_base_client_dev (struct at24_data * at24 )
295290{
296- return & at24 -> client [0 ]. client -> dev ;
291+ return regmap_get_device ( at24 -> client_regmaps [0 ]) ;
297292}
298293
299294static 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,
324319 unsigned int offset , size_t count )
325320{
326321 unsigned long timeout , read_time ;
327- struct at24_client * at24_client ;
328- struct i2c_client * client ;
329322 struct regmap * regmap ;
330323 int ret ;
331324
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 );
335326 count = at24_adjust_read_count (at24 , offset , count );
336327
337328 /* adjust offset for mac and serial read ops */
@@ -346,7 +337,7 @@ static ssize_t at24_regmap_read(struct at24_data *at24, char *buf,
346337 read_time = jiffies ;
347338
348339 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" ,
350341 count , offset , ret , jiffies );
351342 if (!ret )
352343 return count ;
@@ -387,14 +378,10 @@ static ssize_t at24_regmap_write(struct at24_data *at24, const char *buf,
387378 unsigned int offset , size_t count )
388379{
389380 unsigned long timeout , write_time ;
390- struct at24_client * at24_client ;
391- struct i2c_client * client ;
392381 struct regmap * regmap ;
393382 int ret ;
394383
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 );
398385 count = at24_adjust_write_count (at24 , offset , count );
399386 timeout = jiffies + msecs_to_jiffies (at24_write_timeout );
400387
@@ -406,7 +393,7 @@ static ssize_t at24_regmap_write(struct at24_data *at24, const char *buf,
406393 write_time = jiffies ;
407394
408395 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" ,
410397 count , offset , ret , jiffies );
411398 if (!ret )
412399 return count ;
@@ -538,16 +525,14 @@ static const struct at24_chip_data *at24_get_chip_data(struct device *dev)
538525}
539526
540527static int at24_make_dummy_client (struct at24_data * at24 , unsigned int index ,
528+ struct i2c_client * base_client ,
541529 struct regmap_config * regmap_config )
542530{
543- struct i2c_client * base_client , * dummy_client ;
531+ struct i2c_client * dummy_client ;
544532 struct regmap * regmap ;
545- struct device * dev ;
546-
547- base_client = at24 -> client [0 ].client ;
548- dev = & base_client -> dev ;
549533
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 ,
551536 base_client -> addr + index );
552537 if (IS_ERR (dummy_client ))
553538 return PTR_ERR (dummy_client );
@@ -556,8 +541,7 @@ static int at24_make_dummy_client(struct at24_data *at24, unsigned int index,
556541 if (IS_ERR (regmap ))
557542 return PTR_ERR (regmap );
558543
559- at24 -> client [index ].client = dummy_client ;
560- at24 -> client [index ].regmap = regmap ;
544+ at24 -> client_regmaps [index ] = regmap ;
561545
562546 return 0 ;
563547}
@@ -680,7 +664,7 @@ static int at24_probe(struct i2c_client *client)
680664 if (IS_ERR (regmap ))
681665 return PTR_ERR (regmap );
682666
683- at24 = devm_kzalloc (dev , struct_size (at24 , client , num_addresses ),
667+ at24 = devm_kzalloc (dev , struct_size (at24 , client_regmaps , num_addresses ),
684668 GFP_KERNEL );
685669 if (!at24 )
686670 return - ENOMEM ;
@@ -692,8 +676,7 @@ static int at24_probe(struct i2c_client *client)
692676 at24 -> read_post = cdata -> read_post ;
693677 at24 -> num_addresses = num_addresses ;
694678 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 ;
697680
698681 at24 -> vcc_reg = devm_regulator_get (dev , "vcc" );
699682 if (IS_ERR (at24 -> vcc_reg ))
@@ -709,7 +692,7 @@ static int at24_probe(struct i2c_client *client)
709692
710693 /* use dummy devices for multiple-address chips */
711694 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 );
713696 if (err )
714697 return err ;
715698 }
0 commit comments