[coreboot] i2c_writeb vs i2c_raw_write output
punitvara at gmail.com
Sat Oct 8 07:26:30 CEST 2016
+1 Julius. As an extra note you should also remember master can only
enter writing mode after reading mode and slave can enter into reading
mode only after writing mode.
On Sat, Oct 8, 2016 at 6:21 AM, Julius Werner <jwerner at chromium.org> wrote:
> I2C is a very simple bus format with some common conventions attached
> to it that are followed by most (but not all) devices. You can find a
> pretty good summary of how it works on Wikipedia:
> For devices which follow this convention, the device exposes registers
> that usually have a 1-byte register address and contain somewhere
> between 1 to 4 bytes of data (the convention isn't super strict in
> many aspects, so a lot of it is device dependent). In order to write
> to a register you're supposed to make two consecutive transactions
> (with what's called a "repeated start" in between): one transaction
> that writes the 1-byte register address, and one transaction that
> writes the 1-4 bytes of data you want to write into that register.
> Similarly, for a read you first do a write transaction with the
> register address, followed by a read transaction where the device will
> return the register contents.
> i2c_readb() and i2c_writeb() are convenience wrappers that encapsulate
> this whole thing for registers containing 1-byte values for you. This
> is what you want for most devices, but sometimes you have a device
> that doesn't adhere to the conventions and needs special treatment
> (e.g. maybe it doesn't really have a concept of registers at all and
> just treats all data as a single stream or something). For those cases
> you have i2c_read_raw() and i2c_write_raw(): these just directly read
> or write any amount of raw bytes you want out on the bus. Therefore,
> 'val = i2c_readb(1, 2, 3, 4)' is roughly equivalent to 'reg = 3 &&
> i2c_write_raw(1, 2, ®, 1) && i2c_read_raw(1, 2, &val, 1)'.
> Also, I think all of these functions only work on non-x86 devices
> right now so they're probably not really helpful to you (I'd be
> surprised if they even compile and link for your board). The I2C API
> is unfortunately one of those areas where x86 and non-x86 coreboot
> still lead very separate side-by-side lives right now. For x86 you
> probably need the i2c_dev_xxx() functions, which should in theory work
> similar but I have no experience with them. You might also need to use
> the smbus_xxx() functions instead (SMBUS is some
> kinda-the-same-but-not-quite thing related to I2C on x86 that I never
> bothered to fully understand).
> On Thu, Sep 29, 2016 at 3:10 PM, Haleigh Novak <haleigh at edt.com> wrote:
>> Hello All,
>> I am currently trying to send POST codes from Coreboot (downloaded
>> approximately a month ago) to a Beagle I2C/SPI reader, specifically via i2c.
>> I don't know the register needed for i2c_writeb() so I figured I would use
>> i2c_raw_write(). In general since I have been unable to locate anything
>> explaining the difference between the two functions I would really
>> appriciate it if someone could explain it or direct me to where I can find
>> documentation. I am hoping that the explaination/resource will either tell
>> me where / or direct me to how I can figure out where the i2c_raw_write will
>> write to (if it will just write directly to the Beagle or somewhere else)?
>> Or would it be better to send it to a register with i2c_writeb()? I am
>> running Coreboot on an ASROCK Mainboard, model IMB-A180.
>> Thank you.
>> coreboot mailing list: coreboot at coreboot.org
> coreboot mailing list: coreboot at coreboot.org
More information about the coreboot