8
8
9
9
#include <linux/acpi.h>
10
10
#include <linux/bitops.h>
11
+ #include <linux/capability.h>
11
12
#include <linux/delay.h>
12
13
#include <linux/i2c.h>
13
14
#include <linux/init.h>
@@ -89,6 +90,7 @@ struct at24_data {
89
90
90
91
struct nvmem_device * nvmem ;
91
92
struct regulator * vcc_reg ;
93
+ void (* read_post )(unsigned int off , char * buf , size_t count );
92
94
93
95
/*
94
96
* Some chips tie up multiple I2C addresses; dummy devices reserve
@@ -121,13 +123,40 @@ MODULE_PARM_DESC(at24_write_timeout, "Time (in ms) to try writes (default 25)");
121
123
struct at24_chip_data {
122
124
u32 byte_len ;
123
125
u8 flags ;
126
+ void (* read_post )(unsigned int off , char * buf , size_t count );
124
127
};
125
128
126
129
#define AT24_CHIP_DATA (_name , _len , _flags ) \
127
130
static const struct at24_chip_data _name = { \
128
131
.byte_len = _len, .flags = _flags, \
129
132
}
130
133
134
+ #define AT24_CHIP_DATA_CB (_name , _len , _flags , _read_post ) \
135
+ static const struct at24_chip_data _name = { \
136
+ .byte_len = _len, .flags = _flags, \
137
+ .read_post = _read_post, \
138
+ }
139
+
140
+ static void at24_read_post_vaio (unsigned int off , char * buf , size_t count )
141
+ {
142
+ int i ;
143
+
144
+ if (capable (CAP_SYS_ADMIN ))
145
+ return ;
146
+
147
+ /*
148
+ * Hide VAIO private settings to regular users:
149
+ * - BIOS passwords: bytes 0x00 to 0x0f
150
+ * - UUID: bytes 0x10 to 0x1f
151
+ * - Serial number: 0xc0 to 0xdf
152
+ */
153
+ for (i = 0 ; i < count ; i ++ ) {
154
+ if ((off + i <= 0x1f ) ||
155
+ (off + i >= 0xc0 && off + i <= 0xdf ))
156
+ buf [i ] = 0 ;
157
+ }
158
+ }
159
+
131
160
/* needs 8 addresses as A0-A2 are ignored */
132
161
AT24_CHIP_DATA (at24_data_24c00 , 128 / 8 , AT24_FLAG_TAKE8ADDR );
133
162
/* old variants can't be handled with this generic entry! */
@@ -144,6 +173,10 @@ AT24_CHIP_DATA(at24_data_24mac602, 64 / 8,
144
173
/* spd is a 24c02 in memory DIMMs */
145
174
AT24_CHIP_DATA (at24_data_spd , 2048 / 8 ,
146
175
AT24_FLAG_READONLY | AT24_FLAG_IRUGO );
176
+ /* 24c02_vaio is a 24c02 on some Sony laptops */
177
+ AT24_CHIP_DATA_CB (at24_data_24c02_vaio , 2048 / 8 ,
178
+ AT24_FLAG_READONLY | AT24_FLAG_IRUGO ,
179
+ at24_read_post_vaio );
147
180
AT24_CHIP_DATA (at24_data_24c04 , 4096 / 8 , 0 );
148
181
AT24_CHIP_DATA (at24_data_24cs04 , 16 ,
149
182
AT24_FLAG_SERIAL | AT24_FLAG_READONLY );
@@ -177,6 +210,7 @@ static const struct i2c_device_id at24_ids[] = {
177
210
{ "24mac402" , (kernel_ulong_t )& at24_data_24mac402 },
178
211
{ "24mac602" , (kernel_ulong_t )& at24_data_24mac602 },
179
212
{ "spd" , (kernel_ulong_t )& at24_data_spd },
213
+ { "24c02-vaio" , (kernel_ulong_t )& at24_data_24c02_vaio },
180
214
{ "24c04" , (kernel_ulong_t )& at24_data_24c04 },
181
215
{ "24cs04" , (kernel_ulong_t )& at24_data_24cs04 },
182
216
{ "24c08" , (kernel_ulong_t )& at24_data_24c08 },
@@ -388,7 +422,7 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count)
388
422
struct at24_data * at24 ;
389
423
struct device * dev ;
390
424
char * buf = val ;
391
- int ret ;
425
+ int i , ret ;
392
426
393
427
at24 = priv ;
394
428
dev = at24_base_client_dev (at24 );
@@ -411,22 +445,22 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count)
411
445
*/
412
446
mutex_lock (& at24 -> lock );
413
447
414
- while ( count ) {
415
- ret = at24_regmap_read (at24 , buf , off , count );
448
+ for ( i = 0 ; count ; i += ret , count -= ret ) {
449
+ ret = at24_regmap_read (at24 , buf + i , off + i , count );
416
450
if (ret < 0 ) {
417
451
mutex_unlock (& at24 -> lock );
418
452
pm_runtime_put (dev );
419
453
return ret ;
420
454
}
421
- buf += ret ;
422
- off += ret ;
423
- count -= ret ;
424
455
}
425
456
426
457
mutex_unlock (& at24 -> lock );
427
458
428
459
pm_runtime_put (dev );
429
460
461
+ if (unlikely (at24 -> read_post ))
462
+ at24 -> read_post (off , buf , i );
463
+
430
464
return 0 ;
431
465
}
432
466
@@ -654,6 +688,7 @@ static int at24_probe(struct i2c_client *client)
654
688
at24 -> byte_len = byte_len ;
655
689
at24 -> page_size = page_size ;
656
690
at24 -> flags = flags ;
691
+ at24 -> read_post = cdata -> read_post ;
657
692
at24 -> num_addresses = num_addresses ;
658
693
at24 -> offset_adj = at24_get_offset_adj (flags , byte_len );
659
694
at24 -> client [0 ].client = client ;
@@ -678,8 +713,30 @@ static int at24_probe(struct i2c_client *client)
678
713
return err ;
679
714
}
680
715
681
- nvmem_config .name = dev_name (dev );
716
+ /*
717
+ * If the 'label' property is not present for the AT24 EEPROM,
718
+ * then nvmem_config.id is initialised to NVMEM_DEVID_AUTO,
719
+ * and this will append the 'devid' to the name of the NVMEM
720
+ * device. This is purely legacy and the AT24 driver has always
721
+ * defaulted to this. However, if the 'label' property is
722
+ * present then this means that the name is specified by the
723
+ * firmware and this name should be used verbatim and so it is
724
+ * not necessary to append the 'devid'.
725
+ */
726
+ if (device_property_present (dev , "label" )) {
727
+ nvmem_config .id = NVMEM_DEVID_NONE ;
728
+ err = device_property_read_string (dev , "label" ,
729
+ & nvmem_config .name );
730
+ if (err )
731
+ return err ;
732
+ } else {
733
+ nvmem_config .id = NVMEM_DEVID_AUTO ;
734
+ nvmem_config .name = dev_name (dev );
735
+ }
736
+
737
+ nvmem_config .type = NVMEM_TYPE_EEPROM ;
682
738
nvmem_config .dev = dev ;
739
+ nvmem_config .id = NVMEM_DEVID_AUTO ;
683
740
nvmem_config .read_only = !writable ;
684
741
nvmem_config .root_only = !(flags & AT24_FLAG_IRUGO );
685
742
nvmem_config .owner = THIS_MODULE ;
0 commit comments