initialize an I2c device during boot


renan.moraes2@...
 

Hi Malcolm,

To check the I2C protocol support in dh command, it is not necessary to setup protocols.

But, after checking via dh that the device you want to communicate, you can try the steps that you described, but I believe the connect controller is not necessary, you can replace it inside the loop by the Open protocol function directly.

Note: I think the correct I2C IO Guid would be gEfiI2cIoProtocolGuid instead of gEfiI2cMasterProtocolGuid

Please let me know if you were able to identify the device and protocol in dh command.

Thank you

Renan Moraes


malcolm.mcdowell@...
 

Hi Renan,

Thanks. I will check the devtree for I2C string tomorrow.

I have another question related to the processing sequence.

In order to see the information that you mention in the previous responses, do I have to setup the protocols? If so, are the following sequence of commands to see this information, correct?

Initialize:
HandleStatus = gBS->LocateHandleBuffer (
ByProtocol,
&gEfiI2cMasterProtocolGuid,
NULL,
&NumberOfHandles,
&HandleBuffer);
for (Index = 0; Index < NumberOfHandles; Index++) {
gBS->ConnectController (
HandleBuffer[Index],
DriverHandles,
NULL,
TRUE
);
}

Then in the Supported callback, I have:
Status = gBS->OpenProtocol (^M
Controller,
&gEfiI2cMasterProtocolGuid,
(VOID**) &I2cIo,
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_BY_DRIVER );

If you can point me to s specific example, that would be great.

Appreciated all your help.
Malcolm


renan.moraes2@...
 

Hi @Malcolm,

Generally the device should have the I2C string in its name shown in the devtree command. However I believe you can try another way, please run the command "dh >> dh_command.txt" and search for I2cIo in file generated. In this way, I believe it is possible to identify if there is any device that responds to the I2C IO protocol.

Renan Moraes


malcolm.mcdowell@...
 

Hi Renan,

Thanks for your response. I will look into it.

I did run "devtree" but could not tell if the I2c bus or device is active. I see many of the following:

 1B2 D - - 1 0 0 VenHw(1E5A432C-0466-4D31-B009-D4D9239271D3)/MemoryMapped(0x
B,0x2490000,0x249FFFF)/MAC(48B02D3B1A04,0x1)/IPv4(0.0.0.0)/Uri()
 1B5 D - - 1 0 0 VenHw(1E5A432C-0466-4D31-B009-D4D9239271D3)/MemoryMapped(0x
B,0x2490000,0x249FFFF)/MAC(48B02D3B1A04,0x1)/IPv6(0000:0000:0000:0000:0000:0000:
0000:0000)/Uri()

How can I tell if the I2C device or controller is available?

Thanks,
Malcolm


renan.moraes2@...
 

Hi Malcolm,

According to the specification (Platform Integration) you can use the EFI I2C I/O protocol to send an I2C transaction to the device.
PI Spec (https://uefi.org/sites/default/files/resources/PI_Spec_1_7_A_final_May1.pdf) - 17 I2C Protocol Stack

To look for a device that supports this protocol, you can use the LocateHandleBuffer function of EFI_BOOT_SERVICES and if you find a handle, you can open the protocol using the OpenProtocol function also of EFI_BOOT_SERVICES.

Tips:
Run "devtree" command in the EFI Shell and check if the I2C device you want to communicate with is being mapped.

If you find the device in the devtree, use the command dh + the handle found, for example dh 28a, with this, you will know all the protocols that the device in question responds to, it may be that if it responds to a more specific protocol, make it easier to establish a communication.

Renan Moraes


malcolm.mcdowell@...
 

Hi,

I am new to uefi. We need to send a command to an I2c device during boot. I have read through the documentation but have not been able to get a driver working to perform this function.

Is there an example of a similar driver or a specific chapter in a document that could help me with this?

I keep thinking that this should be simple... find the device and then write the command.

Any guidance would be appreciated.

Malcolm