Skip to content

Commit 4d6d35d

Browse files
0xff07Andi Shyti
authored andcommitted
i2c: smbus: introduce Write Disable-aware SPD instantiating functions
Some SMBus controllers may restrict writes to addresses where SPD sensors may reside. This may lead to some SPD sensors not functioning correctly, and might need extra handling. Introduce new SPD-instantiating functions that are aware of this, and use them instead. Signed-off-by: Yo-Jung Lin (Leo) <[email protected]> Reviewed-by: Guenter Roeck <[email protected]> Link: https://lore.kernel.org/r/20250430-for-upstream-i801-spd5118-no-instantiate-v2-1-2f54d91ae2c7@canonical.com Signed-off-by: Andi Shyti <[email protected]>
1 parent 8b28497 commit 4d6d35d

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

drivers/i2c/busses/i2c-i801.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,7 @@ static void i801_probe_optional_targets(struct i801_priv *priv)
11801180
#ifdef CONFIG_I2C_I801_MUX
11811181
if (!priv->mux_pdev)
11821182
#endif
1183-
i2c_register_spd(&priv->adapter);
1183+
i2c_register_spd_write_enable(&priv->adapter);
11841184
}
11851185
#else
11861186
static void __init input_apanel_init(void) {}
@@ -1283,7 +1283,7 @@ static int i801_notifier_call(struct notifier_block *nb, unsigned long action,
12831283
return NOTIFY_DONE;
12841284

12851285
/* Call i2c_register_spd for muxed child segments */
1286-
i2c_register_spd(to_i2c_adapter(dev));
1286+
i2c_register_spd_write_enable(to_i2c_adapter(dev));
12871287

12881288
return NOTIFY_OK;
12891289
}

drivers/i2c/busses/i2c-piix4.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ static int piix4_add_adapter(struct pci_dev *dev, unsigned short smba,
971971
* This would allow the ee1004 to be probed incorrectly.
972972
*/
973973
if (port == 0)
974-
i2c_register_spd(adap);
974+
i2c_register_spd_write_enable(adap);
975975

976976
*padap = adap;
977977
return 0;

drivers/i2c/i2c-smbus.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,12 +372,13 @@ EXPORT_SYMBOL_GPL(i2c_free_slave_host_notify_device);
372372
* - Only works on systems with 1 to 8 memory slots
373373
*/
374374
#if IS_ENABLED(CONFIG_DMI)
375-
void i2c_register_spd(struct i2c_adapter *adap)
375+
static void i2c_register_spd(struct i2c_adapter *adap, bool write_disabled)
376376
{
377377
int n, slot_count = 0, dimm_count = 0;
378378
u16 handle;
379379
u8 common_mem_type = 0x0, mem_type;
380380
u64 mem_size;
381+
bool instantiate = true;
381382
const char *name;
382383

383384
while ((handle = dmi_memdev_handle(slot_count)) != 0xffff) {
@@ -438,6 +439,7 @@ void i2c_register_spd(struct i2c_adapter *adap)
438439
case 0x22: /* DDR5 */
439440
case 0x23: /* LPDDR5 */
440441
name = "spd5118";
442+
instantiate = !write_disabled;
441443
break;
442444
default:
443445
dev_info(&adap->dev,
@@ -461,6 +463,9 @@ void i2c_register_spd(struct i2c_adapter *adap)
461463
addr_list[0] = 0x50 + n;
462464
addr_list[1] = I2C_CLIENT_END;
463465

466+
if (!instantiate)
467+
continue;
468+
464469
if (!IS_ERR(i2c_new_scanned_device(adap, &info, addr_list, NULL))) {
465470
dev_info(&adap->dev,
466471
"Successfully instantiated SPD at 0x%hx\n",
@@ -469,7 +474,19 @@ void i2c_register_spd(struct i2c_adapter *adap)
469474
}
470475
}
471476
}
472-
EXPORT_SYMBOL_GPL(i2c_register_spd);
477+
478+
void i2c_register_spd_write_disable(struct i2c_adapter *adap)
479+
{
480+
i2c_register_spd(adap, true);
481+
}
482+
EXPORT_SYMBOL_GPL(i2c_register_spd_write_disable);
483+
484+
void i2c_register_spd_write_enable(struct i2c_adapter *adap)
485+
{
486+
i2c_register_spd(adap, false);
487+
}
488+
EXPORT_SYMBOL_GPL(i2c_register_spd_write_enable);
489+
473490
#endif
474491

475492
MODULE_AUTHOR("Jean Delvare <[email protected]>");

include/linux/i2c-smbus.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ static inline void i2c_free_slave_host_notify_device(struct i2c_client *client)
4444
#endif
4545

4646
#if IS_ENABLED(CONFIG_I2C_SMBUS) && IS_ENABLED(CONFIG_DMI)
47-
void i2c_register_spd(struct i2c_adapter *adap);
47+
void i2c_register_spd_write_disable(struct i2c_adapter *adap);
48+
void i2c_register_spd_write_enable(struct i2c_adapter *adap);
4849
#else
49-
static inline void i2c_register_spd(struct i2c_adapter *adap) { }
50+
static inline void i2c_register_spd_write_disable(struct i2c_adapter *adap) { }
51+
static inline void i2c_register_spd_write_enable(struct i2c_adapter *adap) { }
5052
#endif
5153

5254
#endif /* _LINUX_I2C_SMBUS_H */

0 commit comments

Comments
 (0)