static void i2c_set_freq_port(const struct i2c_port_t *p) { int port = p->port; /* Disable port */ STM32_I2C_CR1(port) = 0; STM32_I2C_CR2(port) = 0; /* Set clock frequency */ switch (p->kbps) { case 1000: STM32_I2C_TIMINGR(port) = 0x50110103; break; case 400: STM32_I2C_TIMINGR(port) = 0x50330309; break; case 100: STM32_I2C_TIMINGR(port) = 0xB0420F13; break; default: /* unknown speed, defaults to 100kBps */ CPRINTS("I2C bad speed %d kBps", p->kbps); STM32_I2C_TIMINGR(port) = 0xB0420F13; } /* Enable port */ STM32_I2C_CR1(port) = STM32_I2C_CR1_PE; }
static void i2c_set_freq_port(const struct i2c_port_t *p, enum stm32_i2c_clk_src src, enum i2c_freq freq) { int port = p->port; const uint32_t *regs = timingr_regs[src]; /* Disable port */ STM32_I2C_CR1(port) = 0; STM32_I2C_CR2(port) = 0; /* Set clock frequency */ STM32_I2C_TIMINGR(port) = regs[freq]; /* Enable port */ STM32_I2C_CR1(port) = STM32_I2C_CR1_PE; }