1

I am wondering what the proper way is to remove EEPROMs dynamically. An alternate approach that will also work is telling the device to re-do the probe. I tried just echoing it to delete_device, but that gives an error that it can't find it in the device list. I am running 4.14.149 kernel (built with Yocto Pyro). The EEPROM in question is an Atmel 24CS02 (at24 compatible).

This is kind of an odd use case; this is in a simulator with two i.MX6 based SOMs that is used for Continuous Integration, and there is no physical EEPROM, so the initial probe at boot time will fail. This is why there is no eeprom file in the directory. The EEPROM is simulated by an FPGA (that isn't loaded and configured until after the initial boot). Once that is complete, I need to either re-probe (so that it will see an EEPROM there and populate the sysFS) or delete and re-add the device (which will re-trigger the probe).

Here is the output from when I try to remove it:

root@PLX-23-UUT:~# cd /sys/bus/i2c/devices/
root@PLX-23-UUT:/sys/bus/i2c/devices# ls
2-0041  2-0050  2-0052  2-0056  2-0057  2-006f  i2c-1  i2c-2
root@PLX-23-UUT:/sys/bus/i2c/devices# ls 2-0052
modalias  name  of_node  subsystem  uevent
root@PLX-23-UUT:/sys/bus/i2c/devices# echo 0x52 > i2c-2/delete_device
[   72.717009] i2c i2c-2: delete_device: Can't find device in list
-sh: echo: write error: No such file or directory
Eskimoalva
  • 449
  • 8
  • 20
  • Had you chance to read https://lwn.net/Articles/143397/ – 0andriy Nov 17 '19 at 11:58
  • I hadn't seen that, but binding and unbinding doesn't appear to be available for i2c devices. The idea behind it is what I am trying to accomplish (and gives me errors) noted above. – Eskimoalva Nov 18 '19 at 16:36

2 Answers2

3

You can unbind and bind the driver:

# echo 2-0052 > /sys/bus/i2c/drivers/at24/unbind
# echo 2-0052 > /sys/bus/i2c/drivers/at24/bind
at24 2-0052: supply vcc not found, using dummy regulator
at24 2-0052: 32768 byte 24c256 EEPROM, writable, 1 bytes/write
Alexandre Belloni
  • 2,244
  • 13
  • 12
0

https://github.com/torvalds/linux/blob/master/drivers/i2c/i2c-core-base.c

/*
 * And of course let the users delete the devices they instantiated, if
 * they got it wrong. This interface can only be used to delete devices
 * instantiated by i2c_sysfs_new_device above. This guarantees that we
 * don't delete devices to which some kernel code still has references.
 *
 * Parameter checking may look overzealous, but we really don't want
 * the user to delete the wrong device.
 */

In other words, if you didn't instantiate the device, you don't get to remove it.

Incognito
  • 3
  • 3