1 /*
2  * Copyright (c) 2017 Linaro Limited
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_DRIVERS_I2C_I2C_PRIV_H_
8 #define ZEPHYR_DRIVERS_I2C_I2C_PRIV_H_
9 
10 #include <zephyr/drivers/i2c.h>
11 #include <zephyr/dt-bindings/i2c/i2c.h>
12 #include <zephyr/logging/log.h>
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
i2c_map_dt_bitrate(uint32_t bitrate)18 static inline uint32_t i2c_map_dt_bitrate(uint32_t bitrate)
19 {
20 	switch (bitrate) {
21 	case I2C_BITRATE_STANDARD:
22 		return I2C_SPEED_STANDARD << I2C_SPEED_SHIFT;
23 	case I2C_BITRATE_FAST:
24 		return I2C_SPEED_FAST << I2C_SPEED_SHIFT;
25 	case I2C_BITRATE_FAST_PLUS:
26 		return I2C_SPEED_FAST_PLUS << I2C_SPEED_SHIFT;
27 	case I2C_BITRATE_HIGH:
28 		return I2C_SPEED_HIGH << I2C_SPEED_SHIFT;
29 	case I2C_BITRATE_ULTRA:
30 		return I2C_SPEED_ULTRA << I2C_SPEED_SHIFT;
31 	}
32 
33 	LOG_ERR("Invalid I2C bit rate value");
34 
35 	return 0;
36 }
37 
38 #ifdef __cplusplus
39 }
40 #endif
41 
42 #endif /* ZEPHYR_DRIVERS_I2C_I2C_PRIV_H_ */
43