@@ -66,6 +66,9 @@ static const unsigned short normal_i2c[] = {
66
66
#define SPD5118_EEPROM_BASE 0x80
67
67
#define SPD5118_EEPROM_SIZE (SPD5118_PAGE_SIZE * SPD5118_NUM_PAGES)
68
68
69
+ #define PAGE_ADDR0 (page ) (((page) & BIT(0)) << 6)
70
+ #define PAGE_ADDR1_4 (page ) (((page) & GENMASK(4, 1)) >> 1)
71
+
69
72
/* Temperature unit in millicelsius */
70
73
#define SPD5118_TEMP_UNIT (MILLIDEGREE_PER_DEGREE / 4)
71
74
/* Representable temperature range in millicelsius */
@@ -75,6 +78,7 @@ static const unsigned short normal_i2c[] = {
75
78
struct spd5118_data {
76
79
struct regmap * regmap ;
77
80
struct mutex nvmem_lock ;
81
+ bool is_16bit ;
78
82
};
79
83
80
84
/* hwmon */
@@ -331,18 +335,25 @@ static const struct hwmon_chip_info spd5118_chip_info = {
331
335
332
336
/* nvmem */
333
337
334
- static ssize_t spd5118_nvmem_read_page (struct regmap * regmap , char * buf ,
338
+ static ssize_t spd5118_nvmem_read_page (struct spd5118_data * data , char * buf ,
335
339
unsigned int offset , size_t count )
336
340
{
337
- int addr = (offset >> SPD5118_PAGE_SHIFT ) * 0x100 + SPD5118_EEPROM_BASE ;
338
- int err ;
341
+ int page = offset >> SPD5118_PAGE_SHIFT ;
342
+ struct regmap * regmap = data -> regmap ;
343
+ int err , addr ;
339
344
340
345
offset &= SPD5118_PAGE_MASK ;
341
346
342
347
/* Can't cross page boundaries */
343
348
if (offset + count > SPD5118_PAGE_SIZE )
344
349
count = SPD5118_PAGE_SIZE - offset ;
345
350
351
+ if (data -> is_16bit ) {
352
+ addr = SPD5118_EEPROM_BASE | PAGE_ADDR0 (page ) |
353
+ (PAGE_ADDR1_4 (page ) << 8 );
354
+ } else {
355
+ addr = page * 0x100 + SPD5118_EEPROM_BASE ;
356
+ }
346
357
err = regmap_bulk_read (regmap , addr + offset , buf , count );
347
358
if (err )
348
359
return err ;
@@ -365,7 +376,7 @@ static int spd5118_nvmem_read(void *priv, unsigned int off, void *val, size_t co
365
376
mutex_lock (& data -> nvmem_lock );
366
377
367
378
while (count ) {
368
- ret = spd5118_nvmem_read_page (data -> regmap , buf , off , count );
379
+ ret = spd5118_nvmem_read_page (data , buf , off , count );
369
380
if (ret < 0 ) {
370
381
mutex_unlock (& data -> nvmem_lock );
371
382
return ret ;
@@ -516,6 +527,13 @@ static int spd5118_common_probe(struct device *dev, struct regmap *regmap)
516
527
if (!(capability & SPD5118_CAP_TS_SUPPORT ))
517
528
return - ENODEV ;
518
529
530
+ /*
531
+ * 16-bit register addresses are not (yet) supported with I2C.
532
+ * Therefore, if this is an I2C device, register addresses must be
533
+ * 8 bit wide.
534
+ */
535
+ data -> is_16bit = !!i2c_verify_adapter (dev );
536
+
519
537
err = regmap_read (regmap , SPD5118_REG_REVISION , & revision );
520
538
if (err )
521
539
return err ;
0 commit comments