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,10 @@ 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
+ u8 bank_addr_shift ;
95
+ struct regmap * client_regmaps [];
100
96
};
101
97
102
98
/*
@@ -123,6 +119,7 @@ MODULE_PARM_DESC(at24_write_timeout, "Time (in ms) to try writes (default 25)");
123
119
struct at24_chip_data {
124
120
u32 byte_len ;
125
121
u8 flags ;
122
+ u8 bank_addr_shift ;
126
123
void (* read_post )(unsigned int off , char * buf , size_t count );
127
124
};
128
125
@@ -137,6 +134,12 @@ struct at24_chip_data {
137
134
.read_post = _read_post, \
138
135
}
139
136
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
+
140
143
static void at24_read_post_vaio (unsigned int off , char * buf , size_t count )
141
144
{
142
145
int i ;
@@ -197,6 +200,7 @@ AT24_CHIP_DATA(at24_data_24c128, 131072 / 8, AT24_FLAG_ADDR16);
197
200
AT24_CHIP_DATA (at24_data_24c256 , 262144 / 8 , AT24_FLAG_ADDR16 );
198
201
AT24_CHIP_DATA (at24_data_24c512 , 524288 / 8 , AT24_FLAG_ADDR16 );
199
202
AT24_CHIP_DATA (at24_data_24c1024 , 1048576 / 8 , AT24_FLAG_ADDR16 );
203
+ AT24_CHIP_DATA_BS (at24_data_24c1025 , 1048576 / 8 , AT24_FLAG_ADDR16 , 2 );
200
204
AT24_CHIP_DATA (at24_data_24c2048 , 2097152 / 8 , AT24_FLAG_ADDR16 );
201
205
/* identical to 24c08 ? */
202
206
AT24_CHIP_DATA (at24_data_INT3499 , 8192 / 8 , 0 );
@@ -225,6 +229,7 @@ static const struct i2c_device_id at24_ids[] = {
225
229
{ "24c256" , (kernel_ulong_t )& at24_data_24c256 },
226
230
{ "24c512" , (kernel_ulong_t )& at24_data_24c512 },
227
231
{ "24c1024" , (kernel_ulong_t )& at24_data_24c1024 },
232
+ { "24c1025" , (kernel_ulong_t )& at24_data_24c1025 },
228
233
{ "24c2048" , (kernel_ulong_t )& at24_data_24c2048 },
229
234
{ "at24" , 0 },
230
235
{ /* END OF LIST */ }
@@ -254,6 +259,7 @@ static const struct of_device_id at24_of_match[] = {
254
259
{ .compatible = "atmel,24c256" , .data = & at24_data_24c256 },
255
260
{ .compatible = "atmel,24c512" , .data = & at24_data_24c512 },
256
261
{ .compatible = "atmel,24c1024" , .data = & at24_data_24c1024 },
262
+ { .compatible = "atmel,24c1025" , .data = & at24_data_24c1025 },
257
263
{ .compatible = "atmel,24c2048" , .data = & at24_data_24c2048 },
258
264
{ /* END OF LIST */ },
259
265
};
@@ -275,8 +281,8 @@ MODULE_DEVICE_TABLE(acpi, at24_acpi_ids);
275
281
* set the byte address; on a multi-master board, another master
276
282
* may have changed the chip's "current" address pointer.
277
283
*/
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 )
280
286
{
281
287
unsigned int i ;
282
288
@@ -288,12 +294,12 @@ static struct at24_client *at24_translate_offset(struct at24_data *at24,
288
294
* offset &= 0xff ;
289
295
}
290
296
291
- return & at24 -> client [i ];
297
+ return at24 -> client_regmaps [i ];
292
298
}
293
299
294
300
static struct device * at24_base_client_dev (struct at24_data * at24 )
295
301
{
296
- return & at24 -> client [0 ]. client -> dev ;
302
+ return regmap_get_device ( at24 -> client_regmaps [0 ]) ;
297
303
}
298
304
299
305
static 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,
324
330
unsigned int offset , size_t count )
325
331
{
326
332
unsigned long timeout , read_time ;
327
- struct at24_client * at24_client ;
328
- struct i2c_client * client ;
329
333
struct regmap * regmap ;
330
334
int ret ;
331
335
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 );
335
337
count = at24_adjust_read_count (at24 , offset , count );
336
338
337
339
/* adjust offset for mac and serial read ops */
@@ -346,7 +348,7 @@ static ssize_t at24_regmap_read(struct at24_data *at24, char *buf,
346
348
read_time = jiffies ;
347
349
348
350
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" ,
350
352
count , offset , ret , jiffies );
351
353
if (!ret )
352
354
return count ;
@@ -387,14 +389,10 @@ static ssize_t at24_regmap_write(struct at24_data *at24, const char *buf,
387
389
unsigned int offset , size_t count )
388
390
{
389
391
unsigned long timeout , write_time ;
390
- struct at24_client * at24_client ;
391
- struct i2c_client * client ;
392
392
struct regmap * regmap ;
393
393
int ret ;
394
394
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 );
398
396
count = at24_adjust_write_count (at24 , offset , count );
399
397
timeout = jiffies + msecs_to_jiffies (at24_write_timeout );
400
398
@@ -406,7 +404,7 @@ static ssize_t at24_regmap_write(struct at24_data *at24, const char *buf,
406
404
write_time = jiffies ;
407
405
408
406
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" ,
410
408
count , offset , ret , jiffies );
411
409
if (!ret )
412
410
return count ;
@@ -538,26 +536,24 @@ static const struct at24_chip_data *at24_get_chip_data(struct device *dev)
538
536
}
539
537
540
538
static int at24_make_dummy_client (struct at24_data * at24 , unsigned int index ,
539
+ struct i2c_client * base_client ,
541
540
struct regmap_config * regmap_config )
542
541
{
543
- struct i2c_client * base_client , * dummy_client ;
542
+ struct i2c_client * dummy_client ;
544
543
struct regmap * regmap ;
545
- struct device * dev ;
546
-
547
- base_client = at24 -> client [0 ].client ;
548
- dev = & base_client -> dev ;
549
544
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 ));
552
549
if (IS_ERR (dummy_client ))
553
550
return PTR_ERR (dummy_client );
554
551
555
552
regmap = devm_regmap_init_i2c (dummy_client , regmap_config );
556
553
if (IS_ERR (regmap ))
557
554
return PTR_ERR (regmap );
558
555
559
- at24 -> client [index ].client = dummy_client ;
560
- at24 -> client [index ].regmap = regmap ;
556
+ at24 -> client_regmaps [index ] = regmap ;
561
557
562
558
return 0 ;
563
559
}
@@ -680,7 +676,7 @@ static int at24_probe(struct i2c_client *client)
680
676
if (IS_ERR (regmap ))
681
677
return PTR_ERR (regmap );
682
678
683
- at24 = devm_kzalloc (dev , struct_size (at24 , client , num_addresses ),
679
+ at24 = devm_kzalloc (dev , struct_size (at24 , client_regmaps , num_addresses ),
684
680
GFP_KERNEL );
685
681
if (!at24 )
686
682
return - ENOMEM ;
@@ -690,10 +686,10 @@ static int at24_probe(struct i2c_client *client)
690
686
at24 -> page_size = page_size ;
691
687
at24 -> flags = flags ;
692
688
at24 -> read_post = cdata -> read_post ;
689
+ at24 -> bank_addr_shift = cdata -> bank_addr_shift ;
693
690
at24 -> num_addresses = num_addresses ;
694
691
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 ;
697
693
698
694
at24 -> vcc_reg = devm_regulator_get (dev , "vcc" );
699
695
if (IS_ERR (at24 -> vcc_reg ))
@@ -709,7 +705,7 @@ static int at24_probe(struct i2c_client *client)
709
705
710
706
/* use dummy devices for multiple-address chips */
711
707
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 );
713
709
if (err )
714
710
return err ;
715
711
}
0 commit comments