i2c: Support i2c_register_spd() on multiplexed bus segments
Subsystems (5)
cover i2c: Support i2c_register_spd() on multiplexed bus segments
i801 is the last bus driver supporting I2C_CLASS_SPD. It's used for device probing on muxed bus segments. Only known use case so far is systems with more than 8 memory modules (with thermal sensor) on muxed smbus segments.
As discussed with Jean, to be able to remove I2C_CLASS_SPD completely the following has to be done:
1. Extend i2c_register_spd() for use on muxed bus segments
2. Enable explicit instantiation of thermal sensors on memory modules
3. Extend i801 to call i2c_register_spd() on muxed bus segments
Step 2 has been accomplished:caba40ec3531 ("eeprom: at24: Probe for DDR3 thermal sensor in the SPD case") 393bd1000f81 ("eeprom: ee1004: add support for temperature sensor")
Patch 1 does step 1
Patches 2 and 3 provide the basis for patch 4
Patch 4 does step 3
Note: i801 creates the mux platform device, loading and probing of the mux driver may be asynchronous. Therefore we can't call i2c_register_spd() for the muxed segments from i801. Instead we have to add a flag to the platform data, so that the mux driver knows it's supposed to call i2c_register_spd().
This series replaces the earlier RFC series.
Heiner Kallweit (4):
i2c: smbus: Prepare i2c_register_spd for usage on muxed segments
i2c: mux: add basic support for calling i2c_register_spd on muxed bus
segments
i2c: mux: gpio: Allow to call i2c_register_spd on a muxed segment
i2c: i801: Call i2c_register_spd() on muxed bus segments
drivers/i2c/busses/i2c-i801.c | 1 + drivers/i2c/i2c-mux.c | 4 ++++ drivers/i2c/i2c-smbus.c | 19 ++++++++++++------- drivers/i2c/muxes/i2c-mux-gpio.c | 1 + include/linux/i2c-mux.h | 1 + include/linux/platform_data/i2c-mux-gpio.h | 2 ++ 6 files changed, 21 insertions(+), 7 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/4 i2c: smbus: Prepare i2c_register_spd for usage on muxed segments
If this is an adapter on a muxed bus segment, assume that each segment is connected to a subset of the (> 8) overall memory slots. In this case let's probe the maximum of 8 slots, however stop if the number of overall populated slots is reached.
If we're not on a muxed segment and the total number of slots is > 8, report an error, because then not all SPD eeproms can be addressed. Presumably the bus is muxed, but the mux config is missing.
--- drivers/i2c/i2c-smbus.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/i2c/i2c-smbus.c +12 -7
@@ -351,13 +351,18 @@ void i2c_register_spd(struct i2c_adapter *adap)if (!dimm_count)return ; -dev_info (&adap->dev,"%d/%d memory slots populated (from DMI)\n" , - dimm_count, slot_count); - -if (slot_count >8 ) { -dev_warn (&adap->dev, -"Systems with more than 8 memory slots not supported yet, not instantiating SPD\n" ); -return ; +/* Check whether we're a child adapter on a muxed segment */ +if (i2c_parent_is_i2c_adapter (adap)) { +if (slot_count >8 ) + slot_count =8 ; + }else { +dev_info (&adap->dev,"%d/%d memory slots populated (from DMI)\n" , + dimm_count, slot_count); +if (slot_count >8 ) { +dev_err (&adap->dev, +"More than 8 memory slots on a single bus, mux config missing?\n" ); +return ; + } }/*
Signature · 1 line
2.43.0
Re: [PATCH 1/4] i2c: smbus: Prepare i2c_register_spd for usage on muxed segments
Hi!
Quoted 23 lines · Heiner Kallweit
If this is an adapter on a muxed bus segment, assume that each segment is connected to a subset of the (> 8) overall memory slots. In this case let's probe the maximum of 8 slots, however stop if the number of overall populated slots is reached.
If we're not on a muxed segment and the total number of slots is > 8, report an error, because then not all SPD eeproms can be addressed. Presumably the bus is muxed, but the mux config is missing.
Signed-off-by Heiner Kallweit <[email protected]>--- drivers/i2c/i2c-smbus.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)drivers/i2c/i2c-smbus.c +0
-1@@ -351,13 +351,18 @@ void i2c_register_spd(struct i2c_adapter *adap)if (!dimm_count)return ; - dev_info(&adap->dev, "%d/%d memory slots populated (from DMI)\n",
drivers/i2c/i2c-smbus.c void i2c_register_spd(struct i2c_adapter *adap) · line 357
Quoted 10 lines
drivers/i2c/i2c-smbus.c +4
-6- dimm_count, slot_count); - -if (slot_count >8 ) { -dev_warn (&adap->dev, -"Systems with more than 8 memory slots not supported yet, not instantiating SPD\n" ); -return ; +/* Check whether we're a child adapter on a muxed segment */ +if (i2c_parent_is_i2c_adapter (adap)) { +if (slot_count >8 ) + slot_count = 8;'
The comment "Only works on systems with 1 to 8 memory slots" above i2c_register_spd() is now incorrect and needs adjusting.
drivers/i2c/i2c-smbus.c void i2c_register_spd(struct i2c_adapter *adap) · line 368
Quoted 11 lines
drivers/i2c/i2c-smbus.c +8
-0+ }else { +dev_info (&adap->dev,"%d/%d memory slots populated (from DMI)\n" , + dimm_count, slot_count); +if (slot_count >8 ) { +dev_err (&adap->dev, +"More than 8 memory slots on a single bus, mux config missing?\n" ); +return ; + } }/*
The loop below this hunk is limited by dimm_count, but it is checked separately for each muxed segment. It is therefore now possible to instantiate a total number of slots larger than the dimm_count. That was not possible before. I don't know if that's a problem, but the check have been (silently) relaxed.
Cheers,
Peter
Re: [PATCH 1/4] i2c: smbus: Prepare i2c_register_spd for usage on muxed segments
Quoted 25 lines · Peter Rosin
Hi!
Quoted 22 lines · Heiner Kallweit
If this is an adapter on a muxed bus segment, assume that each segment is connected to a subset of the (> 8) overall memory slots. In this case let's probe the maximum of 8 slots, however stop if the number of overall populated slots is reached.
If we're not on a muxed segment and the total number of slots is > 8, report an error, because then not all SPD eeproms can be addressed. Presumably the bus is muxed, but the mux config is missing.
Signed-off-by Heiner Kallweit <[email protected]>--- drivers/i2c/i2c-smbus.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)drivers/i2c/i2c-smbus.c +0
-0@@ -351,13 +351,18 @@ void i2c_register_spd(struct i2c_adapter *adap)if (!dimm_count)return ;
Quoted 15 lines
drivers/i2c/i2c-smbus.c void i2c_register_spd(struct i2c_adapter *adap)
Quoted 11 lines
drivers/i2c/i2c-smbus.c +4
-7-dev_info (&adap->dev,"%d/%d memory slots populated (from DMI)\n" , - dimm_count, slot_count); - -if (slot_count >8 ) { -dev_warn (&adap->dev, -"Systems with more than 8 memory slots not supported yet, not instantiating SPD\n" ); -return ; +/* Check whether we're a child adapter on a muxed segment */ +if (i2c_parent_is_i2c_adapter (adap)) { +if (slot_count >8 ) + slot_count = 8;'The comment "Only works on systems with 1 to 8 memory slots" above
i2c_register_spd()is now incorrect and needs adjusting.
Right, this comment can be removed.
I'll wait for more feedback on the series before submitting a v2.
Quoted 10 lines
Quoted 10 lines
drivers/i2c/i2c-smbus.c +8
-0+ }else { +dev_info (&adap->dev,"%d/%d memory slots populated (from DMI)\n" , + dimm_count, slot_count); +if (slot_count >8 ) { +dev_err (&adap->dev, +"More than 8 memory slots on a single bus, mux config missing?\n" ); +return ; + } }
Quoted 8 lines
drivers/i2c/i2c-smbus.c void i2c_register_spd(struct i2c_adapter *adap) · line 368
Quoted 1 line
drivers/i2c/i2c-smbus.c +0
-0/* The loop below this hunk is limited by
dimm_count, but it is checked separately for each muxed segment. It is therefore now possible to instantiate a total number of slots larger than thedimm_count. That was not possible before. I don't know if that's a problem, but the check have been (silently) relaxed.
That's intentional. Keeping the current logic would have required to add some kind of counter at the parent level, keeping track of how many memory modules were instantiated per muxed segment.
For the sake of simplicity this was omitted. Instead we may probe more slots than needed, however only impact should be that i2c_register_spd() may take a little bit longer on affected systems.
Quoted 2 lines
Cheers,
Peter
Heiner
PATCH 2/4 i2c: mux: add basic support for calling i2c_register_spd on muxed bus segments
In reply to Heiner KallweitThis extension allows mux drivers to instruct i2c_mux_add_adapter to call i2c_register_spd. First user of this feature will be gpio mux.
--- drivers/i2c/i2c-mux.c | 4 ++++ include/linux/i2c-mux.h | 1 + 2 files changed, 5 insertions(+)
drivers/i2c/i2c-mux.c +4 -0
@@ -22,6 +22,7 @@#include <linux/acpi.h> #include <linux/i2c.h> #include <linux/i2c-mux.h> +#include <linux/i2c-smbus.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/of.h>
@@ -429,6 +430,9 @@ int i2c_mux_add_adapter(struct i2c_mux_core *muxc,dev_info (&parent->dev,"Added multiplexed i2c bus %d\n" ,i2c_adapter_id (&priv->adap)); +if (muxc->register_spd) +i2c_register_spd (&priv->adap); + muxc->adapter[muxc->num_adapters++] = &priv->adap;return 0 ;
include/linux/i2c-mux.h +1 -0
@@ -21,6 +21,7 @@ struct i2c_mux_core { unsigned int mux_locked:1; unsigned int arbitrator:1; unsigned int gate:1; + unsigned int register_spd:1;void *priv;
Signature · 1 line
2.43.0
kernel test robot
build botRe: [PATCH 2/4] i2c: mux: add basic support for calling i2c_register_spd on muxed bus segments
kernel test robot noticed the following build errors:
Hi Heiner,
kernel test robot noticed the following build errors:
[auto build test ERROR on wsa/i2c/for-next]
[also build test ERROR on next-20240111]
[cannot apply to linus/master v6.7]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Heiner-Kallweit/i2c-smbus-Prepare-i2c_register_spd-for-usage-on-muxed-segments/20240111-042152 base: https://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git i2c/for-next patch link: https://lore.kernel.org/r/53e5c71a-d954-4211-91a1-de067451d532%40gmail.com patch subject: [PATCH 2/4] i2c: mux: add basic support for calling i2c_register_spd on muxed bus segments config: i386-randconfig-053-20240111 (https://download.01.org/0day-ci/archive/20240111/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240111/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
ld: drivers/i2c/i2c-mux.o: in function `i2c_mux_add_adapter':
>> drivers/i2c/i2c-mux.c:434: undefined reference to `i2c_register_spd'
vim +434 drivers/i2c/i2c-mux.c
283
284 int i2c_mux_add_adapter(struct i2c_mux_core *muxc,
285 u32 force_nr, u32 chan_id,
286 unsigned int class)
287 {
288 struct i2c_adapter *parent = muxc->parent;
289 struct i2c_mux_priv *priv;
290 char symlink_name[20];
291 int ret;
292
293 if (muxc->num_adapters >= muxc->max_adapters) {
294 dev_err(muxc->dev, "No room for more i2c-mux adapters\n");
295 return -EINVAL;
296 }
297
298 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
299 if (!priv)
300 return -ENOMEM;
301
302 /* Set up private adapter data */
303 priv->muxc = muxc;
304 priv->chan_id = chan_id;
305
306 /* Need to do algo dynamically because we don't know ahead
307 * of time what sort of physical adapter we'll be dealing with.
308 */
309 if (parent->algo->master_xfer) {
310 if (muxc->mux_locked)
311 priv->algo.master_xfer = i2c_mux_master_xfer;
312 else
313 priv->algo.master_xfer = __i2c_mux_master_xfer;
314 }
315 if (parent->algo->master_xfer_atomic)
316 priv->algo.master_xfer_atomic = priv->algo.master_xfer;
317
318 if (parent->algo->smbus_xfer) {
319 if (muxc->mux_locked)
320 priv->algo.smbus_xfer = i2c_mux_smbus_xfer;
321 else
322 priv->algo.smbus_xfer = __i2c_mux_smbus_xfer;
323 }
324 if (parent->algo->smbus_xfer_atomic)
325 priv->algo.smbus_xfer_atomic = priv->algo.smbus_xfer;
326
327 priv->algo.functionality = i2c_mux_functionality;
328
329 /* Now fill out new adapter structure */
330 snprintf(priv->adap.name, sizeof(priv->adap.name),
331 "i2c-%d-mux (chan_id %d)", i2c_adapter_id(parent), chan_id);
332 priv->adap.owner = THIS_MODULE;
333 priv->adap.algo = &priv->algo;
334 priv->adap.algo_data = priv;
335 priv->adap.dev.parent = &parent->dev;
336 priv->adap.retries = parent->retries;
337 priv->adap.timeout = parent->timeout;
338 priv->adap.quirks = parent->quirks;
339 if (muxc->mux_locked)
340 priv->adap.lock_ops = &i2c_mux_lock_ops;
341 else
342 priv->adap.lock_ops = &i2c_parent_lock_ops;
343
344 /* Sanity check on class */
345 if (i2c_mux_parent_classes(parent) & class & ~I2C_CLASS_DEPRECATED)
346 dev_err(&parent->dev,
347 "Segment %d behind mux can't share classes with ancestors\n",
348 chan_id);
349 else
350 priv->adap.class = class;
351
352 /*
353 * Try to populate the mux adapter's of_node, expands to
354 * nothing if !CONFIG_OF.
355 */
356 if (muxc->dev->of_node) {
357 struct device_node *dev_node = muxc->dev->of_node;
358 struct device_node *mux_node, *child = NULL;
359 u32 reg;
360
361 if (muxc->arbitrator)
362 mux_node = of_get_child_by_name(dev_node, "i2c-arb");
363 else if (muxc->gate)
364 mux_node = of_get_child_by_name(dev_node, "i2c-gate");
365 else
366 mux_node = of_get_child_by_name(dev_node, "i2c-mux");
367
368 if (mux_node) {
369 /* A "reg" property indicates an old-style DT entry */
370 if (!of_property_read_u32(mux_node, "reg", ®)) {
371 of_node_put(mux_node);
372 mux_node = NULL;
373 }
374 }
375
376 if (!mux_node)
377 mux_node = of_node_get(dev_node);
378 else if (muxc->arbitrator || muxc->gate)
379 child = of_node_get(mux_node);
380
381 if (!child) {
382 for_each_child_of_node(mux_node, child) {
383 ret = of_property_read_u32(child, "reg", ®);
384 if (ret)
385 continue;
386 if (chan_id == reg)
387 break;
388 }
389 }
390
391 priv->adap.dev.of_node = child;
392 of_node_put(mux_node);
393 }
394
395 /*
396 * Associate the mux channel with an ACPI node.
397 */
398 if (has_acpi_companion(muxc->dev))
399 acpi_preset_companion(&priv->adap.dev,
400 ACPI_COMPANION(muxc->dev),
401 chan_id);
402
403 if (force_nr) {
404 priv->adap.nr = force_nr;
405 ret = i2c_add_numbered_adapter(&priv->adap);
406 if (ret < 0) {
407 dev_err(&parent->dev,
408 "failed to add mux-adapter %u as bus %u (error=%d)\n",
409 chan_id, force_nr, ret);
410 goto err_free_priv;
411 }
412 } else {
413 ret = i2c_add_adapter(&priv->adap);
414 if (ret < 0) {
415 dev_err(&parent->dev,
416 "failed to add mux-adapter %u (error=%d)\n",
417 chan_id, ret);
418 goto err_free_priv;
419 }
420 }
421
422 WARN(sysfs_create_link(&priv->adap.dev.kobj, &muxc->dev->kobj,
423 "mux_device"),
424 "can't create symlink to mux device\n");
425
426 snprintf(symlink_name, sizeof(symlink_name), "channel-%u", chan_id);
427 WARN(sysfs_create_link(&muxc->dev->kobj, &priv->adap.dev.kobj,
428 symlink_name),
429 "can't create symlink to channel %u\n", chan_id);
430 dev_info(&parent->dev, "Added multiplexed i2c bus %d\n",
431 i2c_adapter_id(&priv->adap));
432
433 if (muxc->register_spd)
> 434 i2c_register_spd(&priv->adap);
435
436 muxc->adapter[muxc->num_adapters++] = &priv->adap;
437 return 0;
438
439 err_free_priv:
440 kfree(priv);
441 return ret;
442 }
443 EXPORT_SYMBOL_GPL(i2c_mux_add_adapter);
444
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH 2/4] i2c: mux: add basic support for calling i2c_register_spd on muxed bus segments
In reply to Heiner Kallweitkernel test robot noticed the following build errors:
Hi Heiner,
kernel test robot noticed the following build errors:
[auto build test ERROR on wsa/i2c/for-next]
[also build test ERROR on next-20240112]
[cannot apply to linus/master v6.7]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Heiner-Kallweit/i2c-smbus-Prepare-i2c_register_spd-for-usage-on-muxed-segments/20240111-042152 base: https://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git i2c/for-next patch link: https://lore.kernel.org/r/53e5c71a-d954-4211-91a1-de067451d532%40gmail.com patch subject: [PATCH 2/4] i2c: mux: add basic support for calling i2c_register_spd on muxed bus segments config: loongarch-randconfig-001-20240111 (https://download.01.org/0day-ci/archive/20240113/[email protected]/config) compiler: loongarch64-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240113/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
loongarch64-linux-ld: drivers/i2c/i2c-mux.o: in function `.L155':
>> i2c-mux.c:(.text+0xc84): undefined reference to `i2c_register_spd'
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH 3/4 i2c: mux: gpio: Allow to call i2c_register_spd on a muxed segment
In reply to Heiner KallweitAllow the gpio-based multiplexer to call i2c_register_spd on muxed segments. First user will be i801.
--- drivers/i2c/muxes/i2c-mux-gpio.c | 1 + include/linux/platform_data/i2c-mux-gpio.h | 2 ++ 2 files changed, 3 insertions(+)
drivers/i2c/muxes/i2c-mux-gpio.c +1 -0
@@ -161,6 +161,7 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev) } mux->gpios = muxc->priv; muxc->priv = mux; + muxc->register_spd = mux->data.register_spd;platform_set_drvdata (pdev, muxc);
include/linux/platform_data/i2c-mux-gpio.h +2 -0
@@ -20,6 +20,7 @@* @n_values: Number of multiplexer positions (busses to instantiate) * @classes: Optional I2C auto-detection classes * @idle: Bitmask to write to MUX when idle or GPIO_I2CMUX_NO_IDLE if not used +* @register_spd: call i2c_register_spd for the child adapters on muxed segments */ struct i2c_mux_gpio_platform_data {int parent;
@@ -28,6 +29,7 @@ struct i2c_mux_gpio_platform_data {int n_values;const unsigned *classes;unsigned idle; + unsigned int register_spd:1; };#endif /* _LINUX_I2C_MUX_GPIO_H */
Signature · 1 line
2.43.0
PATCH 4/4 i2c: i801: Call i2c_register_spd() on muxed bus segments
In reply to Heiner KallweitInstruct child adapters to call i2c_register_spd() for each muxed bus segment.
--- drivers/i2c/busses/i2c-i801.c | 1 + 1 file changed, 1 insertion(+)
drivers/i2c/busses/i2c-i801.c +1 -0
@@ -1404,6 +1404,7 @@ static void i801_add_mux(struct i801_priv *priv) gpio_data.n_values = mux_config->n_values; gpio_data.classes = mux_config->classes; gpio_data.idle =I2C_MUX_GPIO_NO_IDLE ; + gpio_data.register_spd =1 ;/* Register GPIO descriptor lookup table */ lookup = devm_kzalloc(dev,
Signature · 1 line
2.43.0