@@ -197,68 +197,39 @@ static const struct i2c_driver_api i2c_gecko_driver_api = {
197197 .transfer = i2c_gecko_transfer ,
198198};
199199
200- #if DT_NODE_HAS_STATUS (DT_DRV_INST (0 ), okay )
201-
202- #define PIN_I2C_0_SDA {DT_INST_PROP_BY_IDX(0, location_sda, 1), \
203- DT_INST_PROP_BY_IDX(0, location_sda, 2), gpioModeWiredAnd, 1}
204- #define PIN_I2C_0_SCL {DT_INST_PROP_BY_IDX(0, location_scl, 1), \
205- DT_INST_PROP_BY_IDX(0, location_scl, 2), gpioModeWiredAnd, 1}
206-
207- static const struct i2c_gecko_config i2c_gecko_config_0 = {
208- .base = (I2C_TypeDef * )DT_INST_REG_ADDR (0 ),
209- .clock = cmuClock_I2C0 ,
210- .pin_sda = PIN_I2C_0_SDA ,
211- .pin_scl = PIN_I2C_0_SCL ,
212200#ifdef CONFIG_SOC_GECKO_HAS_INDIVIDUAL_PIN_LOCATION
213- .loc_sda = DT_INST_PROP_BY_IDX (0 , location_sda , 0 ),
214- .loc_scl = DT_INST_PROP_BY_IDX (0 , location_scl , 0 ),
201+ #define I2C_LOC_DATA (idx ) \
202+ .loc_sda = DT_INST_PROP_BY_IDX(idx, location_sda, 0), \
203+ .loc_scl = DT_INST_PROP_BY_IDX(idx, location_scl, 0)
204+ #define I2C_VALIDATE_LOC (idx ) BUILD_ASSERT(true, "")
215205#else
216- #if DT_INST_PROP_BY_IDX (0 , location_sda , 0 ) \
217- != DT_INST_PROP_BY_IDX (0 , location_scl , 0 )
218- #error I2C_0 DTS location-* properties must have identical value
206+ #define I2C_VALIDATE_LOC (idx ) \
207+ BUILD_ASSERT(DT_INST_PROP_BY_IDX(idx, location_sda, 0) \
208+ == DT_INST_PROP_BY_IDX(idx, location_scl, 0), \
209+ "DTS location-* properties must be equal"))
210+ #define I2C_LOC_DATA (idx ) \
211+ .loc = DT_INST_PROP_BY_IDX(idx, location_scl, 0)
219212#endif
220- .loc = DT_INST_PROP_BY_IDX (0 , location_scl , 0 ),
221- #endif
222- .bitrate = DT_INST_PROP (0 , clock_frequency ),
223- };
224-
225- static struct i2c_gecko_data i2c_gecko_data_0 ;
226-
227- DEVICE_DT_INST_DEFINE (0 , & i2c_gecko_init , device_pm_control_nop ,
228- & i2c_gecko_data_0 , & i2c_gecko_config_0 ,
229- POST_KERNEL , CONFIG_KERNEL_INIT_PRIORITY_DEVICE ,
230- & i2c_gecko_driver_api );
231- #endif /* DT_NODE_HAS_STATUS(DT_DRV_INST(0), okay) */
232-
233- #if DT_NODE_HAS_STATUS (DT_DRV_INST (1 ), okay )
234-
235- #define PIN_I2C_1_SDA {DT_INST_PROP_BY_IDX(1, location_sda, 1), \
236- DT_INST_PROP_BY_IDX(1, location_sda, 2), gpioModeWiredAnd, 1}
237- #define PIN_I2C_1_SCL {DT_INST_PROP_BY_IDX(1, location_scl, 1), \
238- DT_INST_PROP_BY_IDX(1, location_scl, 2), gpioModeWiredAnd, 1}
239-
240- static const struct i2c_gecko_config i2c_gecko_config_1 = {
241- .base = (I2C_TypeDef * )DT_INST_REG_ADDR (1 ),
242- .clock = cmuClock_I2C1 ,
243- .pin_sda = PIN_I2C_1_SDA ,
244- .pin_scl = PIN_I2C_1_SCL ,
245- #ifdef CONFIG_SOC_GECKO_HAS_INDIVIDUAL_PIN_LOCATION
246- .loc_sda = DT_INST_PROP_BY_IDX (1 , location_sda , 0 ),
247- .loc_scl = DT_INST_PROP_BY_IDX (1 , location_scl , 0 ),
248- #else
249- #if DT_INST_PROP_BY_IDX (1 , location_sda , 0 ) \
250- != DT_INST_PROP_BY_IDX (1 , location_scl , 0 )
251- #error I2C_1 DTS location-* properties must have identical value
252- #endif
253- .loc = DT_INST_PROP_BY_IDX (1 , location_scl , 0 ),
254- #endif
255- .bitrate = DT_INST_PROP (1 , clock_frequency ),
256- };
257-
258- static struct i2c_gecko_data i2c_gecko_data_1 ;
259213
260- DEVICE_DT_INST_DEFINE (1 , & i2c_gecko_init , device_pm_control_nop ,
261- & i2c_gecko_data_1 , & i2c_gecko_config_1 ,
262- POST_KERNEL , CONFIG_KERNEL_INIT_PRIORITY_DEVICE ,
263- & i2c_gecko_driver_api );
264- #endif /* DT_NODE_HAS_STATUS(DT_DRV_INST(1), okay) */
214+ #define I2C_INIT (idx ) \
215+ I2C_VALIDATE_LOC(idx); \
216+ static const struct i2c_gecko_config i2c_gecko_config_##idx = { \
217+ .base = (I2C_TypeDef *)DT_INST_REG_ADDR(idx), \
218+ .clock = cmuClock_I2C##idx, \
219+ .pin_sda = {DT_INST_PROP_BY_IDX(idx, location_sda, 1), \
220+ DT_INST_PROP_BY_IDX(idx, location_sda, 2), gpioModeWiredAnd, 1}, \
221+ .pin_scl = {DT_INST_PROP_BY_IDX(idx, location_scl, 1), \
222+ DT_INST_PROP_BY_IDX(idx, location_scl, 2), gpioModeWiredAnd, 1}, \
223+ I2C_LOC_DATA(idx), \
224+ .bitrate = DT_INST_PROP(idx, clock_frequency), \
225+ }; \
226+ \
227+ static struct i2c_gecko_data i2c_gecko_data_##idx; \
228+ \
229+ DEVICE_DT_INST_DEFINE(idx, &i2c_gecko_init, \
230+ device_pm_control_nop, \
231+ &i2c_gecko_data_##idx, &i2c_gecko_config_##idx, \
232+ POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
233+ &i2c_gecko_driver_api);
234+
235+ DT_INST_FOREACH_STATUS_OKAY (I2C_INIT )
0 commit comments