Is it possible to use i2c1 (0x40012000) in tf-a?
Hi!
As far as I looked into the source code, only is i2c4 is used for communication to pmic.
Our custom board has an external PLL connected to i2c1. The PLL needs an initial configuraion to provide 48MHz.
It would be ideal if I could do this during tf-a bl2 stage.
What I have tried:
Added i2c1 to the device tree:
&i2c1 {
pinctrl-names = "default";
pinctrl-0 = <&i2c1_pins_c>;
i2c-scl-rising-time-ns = <100>;
i2c-scl-falling-time-ns = <7>;
clock-frequency = <400000>;
status = "okay";
};This is my i2c1 test code:
int ret, val;
struct dt_node_info i2c_info;
struct i2c_handle_s *i2c = &i2c_handle;
struct stm32_i2c_init_s i2c_init;
uint32_t pll_i2c_addr = 0x6D;
uint8_t data[18] = {0};
i2c_info.base = 0x40012000;
i2c_info.status = 2;
i2c_info.clock = I2C1_K;
i2c->i2c_base_addr = i2c_info.base;
i2c->dt_status = i2c_info.status;
i2c->clock = i2c_info.clock;
i2c->i2c_state = I2C_STATE_RESET;
i2c_init.own_address1 = pll_i2c_addr;
i2c_init.addressing_mode = I2C_ADDRESSINGMODE_7BIT;
i2c_init.dual_address_mode = I2C_DUALADDRESS_DISABLE;
i2c_init.own_address2 = 0;
i2c_init.own_address2_masks = I2C_OAR2_OA2NOMASK;
i2c_init.general_call_mode = I2C_GENERALCALL_DISABLE;
i2c_init.no_stretch_mode = I2C_NOSTRETCH_DISABLE;
i2c_init.rise_time = 185;
i2c_init.fall_time = 20;
i2c_init.bus_rate = 400000;
i2c_init.analog_filter = 1;
i2c_init.digital_filter_coef = 0;
ERROR("setup_nexdaq_pll\n");
ERROR("I2C base addr: 0x%x\n", i2c_info.base);
ERROR("I2C dt_status: 0x%x\n", i2c_info.status);
ERROR("I2C clock: 0x%x\n", i2c_info.clock);
ERROR("pll_i2c_addr: 0x%x\n", pll_i2c_addr);
ret = stm32_i2c_init(i2c, &i2c_init);
if (ret != 0) {
ERROR("Cannot initialize I2C %x (%d)\n",
i2c->i2c_base_addr, ret);
//panic();
}
{
val = stm32_i2c_mem_read(i2c, pll_i2c_addr, 0x94,
I2C_MEMADD_SIZE_8BIT, data, 1, 50);
if (val < 0) {
ERROR("stm32_i2c_mem_read failed = %d\n", val);
}
ERROR("data: %x\n", data[0]);
}
if (!stm32_i2c_is_device_ready(i2c, pll_i2c_addr, 1,
I2C_TIMEOUT_BUSY_MS)) {
ERROR("I2C device not ready\n");
//panic();
}This is the output with additional logging:
NOTICE: CPU: STM32MP157FAC Rev.Z
NOTICE: Model: DEWETRON NEXDAQ tf-a
ERROR: setup_nexdaq_pll
ERROR: I2C base addr: 0x40012000
ERROR: I2C dt_status: 0x2
ERROR: I2C clock: 0x89
ERROR: pmic_i2c_addr: 0x6d
ERROR: I2C timeout_init_us
ERROR: I2C i2c_request_memory_read
ERROR: i2c_request_memory_read
ERROR: stm32_i2c_mem_read failed = -5
ERROR: data: 0
ERROR: I2C device not readyIn Linux access to the device is possible:
root@stm32mp1-nexio:~# i2cdetect 0
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-0.
I will probe address range 0x08-0x77.
Continue? [Y/n] y
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- 6d -- --
70: -- -- -- -- -- -- -- --
root@stm32mp1-nexio:~# i2cde