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,10 @@ 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+ u8 bank_addr_shift ;
95+ struct regmap * client_regmaps [];
10096};
10197
10298/*
@@ -123,6 +119,7 @@ MODULE_PARM_DESC(at24_write_timeout, "Time (in ms) to try writes (default 25)");
123119struct at24_chip_data {
124120 u32 byte_len ;
125121 u8 flags ;
122+ u8 bank_addr_shift ;
126123 void (* read_post )(unsigned int off , char * buf , size_t count );
127124};
128125
@@ -137,6 +134,12 @@ struct at24_chip_data {
137134 .read_post = _read_post, \
138135 }
139136
137+ #define AT24_CHIP_DATA_BS (_name , _len , _flags , _bank_addr_shift ) \
138+ static const struct at24_chip_data _name = { \
139+ .byte_len = _len, .flags = _flags, \
140+ .bank_addr_shift = _bank_addr_shift \
141+ }
142+
140143static void at24_read_post_vaio (unsigned int off , char * buf , size_t count )
141144{
142145 int i ;
@@ -197,6 +200,7 @@ AT24_CHIP_DATA(at24_data_24c128, 131072 / 8, AT24_FLAG_ADDR16);
197200AT24_CHIP_DATA (at24_data_24c256 , 262144 / 8 , AT24_FLAG_ADDR16 );
198201AT24_CHIP_DATA (at24_data_24c512 , 524288 / 8 , AT24_FLAG_ADDR16 );
199202AT24_CHIP_DATA (at24_data_24c1024 , 1048576 / 8 , AT24_FLAG_ADDR16 );
203+ AT24_CHIP_DATA_BS (at24_data_24c1025 , 1048576 / 8 , AT24_FLAG_ADDR16 , 2 );
200204AT24_CHIP_DATA (at24_data_24c2048 , 2097152 / 8 , AT24_FLAG_ADDR16 );
201205/* identical to 24c08 ? */
202206AT24_CHIP_DATA (at24_data_INT3499 , 8192 / 8 , 0 );
@@ -225,6 +229,7 @@ static const struct i2c_device_id at24_ids[] = {
225229 { "24c256" , (kernel_ulong_t )& at24_data_24c256 },
226230 { "24c512" , (kernel_ulong_t )& at24_data_24c512 },
227231 { "24c1024" , (kernel_ulong_t )& at24_data_24c1024 },
232+ { "24c1025" , (kernel_ulong_t )& at24_data_24c1025 },
228233 { "24c2048" , (kernel_ulong_t )& at24_data_24c2048 },
229234 { "at24" , 0 },
230235 { /* END OF LIST */ }
@@ -254,6 +259,7 @@ static const struct of_device_id at24_of_match[] = {
254259 { .compatible = "atmel,24c256" , .data = & at24_data_24c256 },
255260 { .compatible = "atmel,24c512" , .data = & at24_data_24c512 },
256261 { .compatible = "atmel,24c1024" , .data = & at24_data_24c1024 },
262+ { .compatible = "atmel,24c1025" , .data = & at24_data_24c1025 },
257263 { .compatible = "atmel,24c2048" , .data = & at24_data_24c2048 },
258264 { /* END OF LIST */ },
259265};
@@ -275,8 +281,8 @@ MODULE_DEVICE_TABLE(acpi, at24_acpi_ids);
275281 * set the byte address; on a multi-master board, another master
276282 * may have changed the chip's "current" address pointer.
277283 */
278- static struct at24_client * at24_translate_offset (struct at24_data * at24 ,
279- unsigned int * offset )
284+ static struct regmap * at24_translate_offset (struct at24_data * at24 ,
285+ unsigned int * offset )
280286{
281287 unsigned int i ;
282288
@@ -288,12 +294,12 @@ static struct at24_client *at24_translate_offset(struct at24_data *at24,
288294 * offset &= 0xff ;
289295 }
290296
291- return & at24 -> client [i ];
297+ return at24 -> client_regmaps [i ];
292298}
293299
294300static struct device * at24_base_client_dev (struct at24_data * at24 )
295301{
296- return & at24 -> client [0 ]. client -> dev ;
302+ return regmap_get_device ( at24 -> client_regmaps [0 ]) ;
297303}
298304
299305static size_t at24_adjust_read_count (struct at24_data * at24 ,
@@ -324,14 +330,10 @@ static ssize_t at24_regmap_read(struct at24_data *at24, char *buf,
324330 unsigned int offset , size_t count )
325331{
326332 unsigned long timeout , read_time ;
327- struct at24_client * at24_client ;
328- struct i2c_client * client ;
329333 struct regmap * regmap ;
330334 int ret ;
331335
332- at24_client = at24_translate_offset (at24 , & offset );
333- regmap = at24_client -> regmap ;
334- client = at24_client -> client ;
336+ regmap = at24_translate_offset (at24 , & offset );
335337 count = at24_adjust_read_count (at24 , offset , count );
336338
337339 /* adjust offset for mac and serial read ops */
@@ -346,7 +348,7 @@ static ssize_t at24_regmap_read(struct at24_data *at24, char *buf,
346348 read_time = jiffies ;
347349
348350 ret = regmap_bulk_read (regmap , offset , buf , count );
349- dev_dbg (& client -> dev , "read %zu@%d --> %d (%ld)\n" ,
351+ dev_dbg (regmap_get_device ( regmap ) , "read %zu@%d --> %d (%ld)\n" ,
350352 count , offset , ret , jiffies );
351353 if (!ret )
352354 return count ;
@@ -387,14 +389,10 @@ static ssize_t at24_regmap_write(struct at24_data *at24, const char *buf,
387389 unsigned int offset , size_t count )
388390{
389391 unsigned long timeout , write_time ;
390- struct at24_client * at24_client ;
391- struct i2c_client * client ;
392392 struct regmap * regmap ;
393393 int ret ;
394394
395- at24_client = at24_translate_offset (at24 , & offset );
396- regmap = at24_client -> regmap ;
397- client = at24_client -> client ;
395+ regmap = at24_translate_offset (at24 , & offset );
398396 count = at24_adjust_write_count (at24 , offset , count );
399397 timeout = jiffies + msecs_to_jiffies (at24_write_timeout );
400398
@@ -406,7 +404,7 @@ static ssize_t at24_regmap_write(struct at24_data *at24, const char *buf,
406404 write_time = jiffies ;
407405
408406 ret = regmap_bulk_write (regmap , offset , buf , count );
409- dev_dbg (& client -> dev , "write %zu@%d --> %d (%ld)\n" ,
407+ dev_dbg (regmap_get_device ( regmap ) , "write %zu@%d --> %d (%ld)\n" ,
410408 count , offset , ret , jiffies );
411409 if (!ret )
412410 return count ;
@@ -538,26 +536,24 @@ static const struct at24_chip_data *at24_get_chip_data(struct device *dev)
538536}
539537
540538static int at24_make_dummy_client (struct at24_data * at24 , unsigned int index ,
539+ struct i2c_client * base_client ,
541540 struct regmap_config * regmap_config )
542541{
543- struct i2c_client * base_client , * dummy_client ;
542+ struct i2c_client * dummy_client ;
544543 struct regmap * regmap ;
545- struct device * dev ;
546-
547- base_client = at24 -> client [0 ].client ;
548- dev = & base_client -> dev ;
549544
550- dummy_client = devm_i2c_new_dummy_device (dev , base_client -> adapter ,
551- base_client -> addr + index );
545+ dummy_client = devm_i2c_new_dummy_device (& base_client -> dev ,
546+ base_client -> adapter ,
547+ base_client -> addr +
548+ (index << at24 -> bank_addr_shift ));
552549 if (IS_ERR (dummy_client ))
553550 return PTR_ERR (dummy_client );
554551
555552 regmap = devm_regmap_init_i2c (dummy_client , regmap_config );
556553 if (IS_ERR (regmap ))
557554 return PTR_ERR (regmap );
558555
559- at24 -> client [index ].client = dummy_client ;
560- at24 -> client [index ].regmap = regmap ;
556+ at24 -> client_regmaps [index ] = regmap ;
561557
562558 return 0 ;
563559}
@@ -680,7 +676,7 @@ static int at24_probe(struct i2c_client *client)
680676 if (IS_ERR (regmap ))
681677 return PTR_ERR (regmap );
682678
683- at24 = devm_kzalloc (dev , struct_size (at24 , client , num_addresses ),
679+ at24 = devm_kzalloc (dev , struct_size (at24 , client_regmaps , num_addresses ),
684680 GFP_KERNEL );
685681 if (!at24 )
686682 return - ENOMEM ;
@@ -690,10 +686,10 @@ static int at24_probe(struct i2c_client *client)
690686 at24 -> page_size = page_size ;
691687 at24 -> flags = flags ;
692688 at24 -> read_post = cdata -> read_post ;
689+ at24 -> bank_addr_shift = cdata -> bank_addr_shift ;
693690 at24 -> num_addresses = num_addresses ;
694691 at24 -> offset_adj = at24_get_offset_adj (flags , byte_len );
695- at24 -> client [0 ].client = client ;
696- at24 -> client [0 ].regmap = regmap ;
692+ at24 -> client_regmaps [0 ] = regmap ;
697693
698694 at24 -> vcc_reg = devm_regulator_get (dev , "vcc" );
699695 if (IS_ERR (at24 -> vcc_reg ))
@@ -709,7 +705,7 @@ static int at24_probe(struct i2c_client *client)
709705
710706 /* use dummy devices for multiple-address chips */
711707 for (i = 1 ; i < num_addresses ; i ++ ) {
712- err = at24_make_dummy_client (at24 , i , & regmap_config );
708+ err = at24_make_dummy_client (at24 , i , client , & regmap_config );
713709 if (err )
714710 return err ;
715711 }
0 commit comments