cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Contributor
Contributor
287 Views
Registered: ‎03-25-2009

U-Boot I2C Usage Example Request

I cannot find a (c code) example of reading an eeprom or configuring an IC using I2C anywhere : the caveat is from within U-Boot, my interest is in the specifics of the U-boot environment.

The target platform is a Zynq, the U-Boot runs and provides a useful console which permits peek/poke of attached I2C devices and a 21st century equivalent of keying in the boot loader.

It would be nice not to have to reverse engineer the cookery, but simply to slot the code into board_late_init(_xilinx). 

The configuration has to be performed between bitstream load and Linux boot : hence U-Boot.

Martin

0 Kudos
Reply
4 Replies
Teacher
Teacher
268 Views
Registered: ‎01-28-2008

Hi @mjdbishop 

  I'm not a U-Boot expert by any means, but the file under u-boot-xlnx/board/xilinx/common/board.c has a few examples that parse the device tree and fetch an I2C device, then proceed to read it.

	struct udevice *dev;
	ofnode eeprom;

	eeprom = ofnode_get_chosen_node("xlnx,eeprom");
        ...
	ret = uclass_get_device_by_ofnode(UCLASS_I2C_EEPROM, eeprom, &dev);
        ...
	ret = dm_i2c_read(dev, CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET, ethaddr, 6);

Thanks,

-Pat

 

 

Give kudos if helpful. Accept as solution if it solves your problem.
https://tuxengineering.com/blog

0 Kudos
Reply
Contributor
Contributor
249 Views
Registered: ‎03-25-2009

Hi @patocarr 

Thank you for the pointer, I had already eyeballed the board.c example and discounted it as too opaque and distant from my Si53xx target device.

As the build process is longwinded and the debugger another lengthy evolution, I really need a canned example or a documentation stack.

Best Regards

Martin

0 Kudos
Reply
Moderator
Moderator
231 Views
Registered: ‎09-12-2007

It would be tough to find a pre-canned example that fits all as every i2c bus topology would be different.

However, You can view the zcu111 rfdc driver example code (*_clk.c/.h) as a reference point. This programs the clocks (and clock cleaners)

https://github.com/Xilinx/embeddedsw/blob/master/XilinxProcessorIPLib/drivers/rfdc/examples/xrfdc_clk.c#L702

This is obviously specific to the zcu111 I2C topology. However, I discuss the sequence here (mux -> bridge -> clock)

https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/84541826/Programming+Clocks+on+the+ZCU111

 

0 Kudos
Reply
Contributor
Contributor
212 Views
Registered: ‎03-25-2009

@stephenm 

Thank you for suggesting solutions to this problem.  Unfortunately, the solutions you link to do not address the specific problem I was looking for guidance on - c code for U-Boot to drive i2c.

I already have working baremetal / standalone code using the XiicPs_ routines, and can initialise the clock standalone.  I could enhance the pci device driver to first configure the clock, but would prefer a simpler solution.

However, U-Boot's scripting cabability has provided a viable solution.  In brief a modified version of boot.scr.

0) extract the essence of boot.scr using Gedit

1) prepare boot.txt comprising the i2c console script, which can be developed interactively with U-Boot

2) then the boot script proper by mkimage -A arm -O linux -T script -C none -d boot.txt boot.scr boot.scr is essentially a gzip

3) place boot.scr on the boot media and test

I appreciate this is unlikely to be the correct way to patch boot.scr

A snipped version of boot.txt is:

# This is a boot script for U-Boot
# Generate boot.scr:
# mkimage -c none -A arm -T script -d boot.cmd.default boot.scr
#
################

echo Boot script for PlAio2 clock configuration / DrB / 22 Sep 20

i2c dev 1
i2c probe 68
i2c mw 68 02 a2
i2c mw 68 03 15
.<< snip >>
i2c md 68 82 1

echo clock initialised

sleep 5
i2c md 68 82

for boot_target in ${boot_targets};
do
if test "${boot_target}" = "jtag" ; then
bootm 0x00200000 0x04000000 0x00100000
exit;
fi

<< snip >>

A programatic (c code) solution to this U-Boot configuration requirement remains of interest

Martin

0 Kudos
Reply