Read/Write from I2C device EEPROM

when I do I2C detect able to detect onboard eeprom @0x50 and rtc @0x68. Not able read/write data to eeprom using i2cset and i2c get command. How to read/write data to i2c devices?

Computer on Module - Apalis iMX8
Carrier Board - Ixora Carrier Board
Computer on Module OS - Torizon
Development PC OS - Linux

apalis-imx8-06852506:~$ i2cdetect -l   
i2c-3	i2c       	5a810000.i2c                    	I2C adapter
i2c-4	i2c       	5a820000.i2c                    	I2C adapter
i2c-2	i2c       	5a800000.i2c                    	I2C adapter
i2c-5	i2c       	5a830000.i2c                    	I2C adapter
apalis-imx8-06852506:~$ i2cdetect -y -r 4
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: 30 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         
apalis-imx8-06852506:~$ i2cget -y 4 0x50 0x00 b
Error: Could not set address to 0x50: Device or resource busy

A driver has control of that device. You can see the driver by looking in
/sys/bus/i2c/devices/(address)/name

You’ll either have to disable the driver or use the driver for reading/writing. For an eeprom, there should be plenty of references for doing that via userland using stuff like /sys/bus/i2c/devices/0-0050/eeprom

Hello @jeremias.tx @DaveM ,
Thank you for your help.
As @DaveM said eeprom is not accessible because driver has control over it.
1)How to unbind or disable the driver to access the eeprom?
2)How to access the eeprom without disabling the driver?

ab301@lab301:~$ ssh torizon@172.26.34.23
torizon@172.26.34.23's password: 
Last login: Tue Jan 18 05:08:13 2022 from 172.26.34.215
apalis-imx8-06852506:~$ cat /sys/
block/      class/      devices/    fs/         kernel/     power/
bus/        dev/        firmware/   hypervisor/ module/     
apalis-imx8-06852506:~$ cat /sys/bus/
ac97/         event_source/ mmc/          scsi/         ulpi/
amba/         genpd/        mmc_rpmb/     sdio/         usb/
cec/          gpio/         node/         serial/       usb-serial/
clockevents/  hid/          nvmem/        serio/        virtio/
clocksource/  i2c/          pci/          soc/          workqueue/
container/    iio/          pci_express/  spi/          xen/
coresight/    mdio_bus/     platform/     spmi/         xen-backend/
cpu/          media/        pnp/          tee/          
edac/         mipi-dsi/     rpmsg/        typec/        
apalis-imx8-06852506:~$ cat /sys/bus/i2c/devices/
3-0008/ 4-0044/ 4-0068/ i2c-2/  i2c-4/  
3-000a/ 4-0050/ 5-0042/ i2c-3/  i2c-5/  
apalis-imx8-06852506:~$ cat /sys/bus/i2c/devices/4-0050/
4-00500/   driver/    modalias   of_node/   subsystem/ uevent     
consumers  eeprom     name       power/     suppliers  
apalis-imx8-06852506:~$ cat /sys/bus/i2c/devices/4-0050/driver/
4-0050/ bind    uevent  unbind  
apalis-imx8-06852506:~$ cat /sys/bus/i2c/devices/4-0050/driver/unbind 
cat: /sys/bus/i2c/devices/4-0050/driver/unbind: Permission denied
apalis-imx8-06852506:~$ sudo cat /sys/bus/i2c/devices/4-0050/driver/unbind 
Password: 
cat: /sys/bus/i2c/devices/4-0050/driver/unbind: Permission denied
apalis-imx8-06852506:~$ 


Usually hardware peripherals get binded to drivers via the device tree. I imagine in your device tree there’s something binding this EEPROM to this mystery driver. If you remove this association in the device tree then the kernel shouldn’t bind it anymore. It also might help to see dmesg and other kernel logs to see what driver is using the EEPROM to begin with, if the logs reveal this.

Best Regards,
Jeremias

Hello @jeremias.tx
Thanks for your reply.
Unbind the driver worked well. Now I can access it. I am not aware of how to use driver to access the device. Can you guide to access the eeprom using driver instead of disabling it.

Onboard eeprom - AT34C02D
Compatible driver - at24 
(https://github.com/torvalds/linux/blob/master/drivers/misc/eeprom/at24.c)

To simply access it using the driver you can just access the file version of the EEPROM in /sys/class. In your case the /sys/bus/i2c/devices/4-0050/eeprom file is created by the at24 driver. I believe you should be able to manipulate it like any other file as seen here: c - Reading and writing EEPROM via I2C with Linux - Stack Overflow

I’m unsure of any other features of this particular driver.

Best Regards,
Jeremias

Hello @jeremias.tx @DaveM
Thank you for all your support.
Finally I am able to use my eeprom from user space as well as kernel space.

Glad I was able to assist!

1 Like