@@ -28,6 +28,7 @@ struct tca954x_root_data {
28
28
struct tca954x_channel_config {
29
29
const struct device * root ;
30
30
uint8_t chan_mask ;
31
+ bool has_enable ;
31
32
};
32
33
33
34
static inline struct tca954x_root_data *
@@ -143,7 +144,8 @@ static int tca954x_channel_init(const struct device *dev)
143
144
return - ENODEV ;
144
145
}
145
146
146
- if (chan_cfg -> chan_mask >= BIT (root_cfg -> nchans )) {
147
+ if ((chan_cfg -> chan_mask >= BIT (root_cfg -> nchans ) && !chan_cfg -> has_enable ) ||
148
+ (chan_cfg -> chan_mask > (BIT (2 ) | (root_cfg -> nchans - 1 )) && chan_cfg -> has_enable )) {
147
149
LOG_ERR ("Wrong DTS address provided for %s" , dev -> name );
148
150
return - EINVAL ;
149
151
}
@@ -162,11 +164,13 @@ static const struct i2c_driver_api tca954x_api_funcs = {
162
164
BUILD_ASSERT (CONFIG_I2C_TCA954X_CHANNEL_INIT_PRIO > CONFIG_I2C_TCA954X_ROOT_INIT_PRIO ,
163
165
"I2C multiplexer channels must be initialized after their root" );
164
166
165
- #define TCA954x_CHILD_DEFINE (node_id , n ) \
167
+ #define TCA954x_CHILD_DEFINE (node_id , n , has_enable_bit ) \
166
168
static const struct tca954x_channel_config \
167
169
tca##n##a_down_config_##node_id = { \
168
- .chan_mask = BIT(DT_REG_ADDR(node_id)), \
170
+ .chan_mask = has_enable_bit ? BIT(2) | DT_REG_ADDR(node_id) \
171
+ : BIT(DT_REG_ADDR(node_id)), \
169
172
.root = DEVICE_DT_GET(DT_PARENT(node_id)), \
173
+ .has_enable = has_enable_bit, \
170
174
}; \
171
175
DEVICE_DT_DEFINE(node_id, \
172
176
tca954x_channel_init, \
@@ -176,7 +180,7 @@ BUILD_ASSERT(CONFIG_I2C_TCA954X_CHANNEL_INIT_PRIO > CONFIG_I2C_TCA954X_ROOT_INIT
176
180
POST_KERNEL, CONFIG_I2C_TCA954X_CHANNEL_INIT_PRIO, \
177
181
&tca954x_api_funcs);
178
182
179
- #define TCA954x_ROOT_DEFINE (n , inst , ch ) \
183
+ #define TCA954x_ROOT_DEFINE (n , inst , ch , has_enable_bit ) \
180
184
static const struct tca954x_root_config tca##n##a_cfg_##inst = { \
181
185
.i2c = I2C_DT_SPEC_INST_GET(inst), \
182
186
.nchans = ch, \
@@ -191,20 +195,29 @@ BUILD_ASSERT(CONFIG_I2C_TCA954X_CHANNEL_INIT_PRIO > CONFIG_I2C_TCA954X_ROOT_INIT
191
195
&tca##n##a_data_##inst, &tca##n##a_cfg_##inst, \
192
196
POST_KERNEL, CONFIG_I2C_TCA954X_ROOT_INIT_PRIO, \
193
197
NULL); \
194
- DT_FOREACH_CHILD_VARGS(DT_INST(inst, ti_tca##n##a), TCA954x_CHILD_DEFINE, n);
198
+ DT_FOREACH_CHILD_VARGS(DT_INST(inst, ti_tca##n##a), TCA954x_CHILD_DEFINE, n, \
199
+ has_enable_bit);
195
200
196
201
/*
197
- * TCA9546A : 4 channels
202
+ * TCA9544A : 4 channels mux
198
203
*/
199
- #define TCA9546A_INIT (n ) TCA954x_ROOT_DEFINE(9546, n, 4)
204
+ #define TCA9544A_INIT (n ) TCA954x_ROOT_DEFINE(9544, n, 4, true)
205
+ #undef DT_DRV_COMPAT
206
+ #define DT_DRV_COMPAT ti_tca9544a
207
+ DT_INST_FOREACH_STATUS_OKAY (TCA9544A_INIT )
208
+
209
+ /*
210
+ * TCA9546A: 4 channels switch
211
+ */
212
+ #define TCA9546A_INIT (n ) TCA954x_ROOT_DEFINE(9546, n, 4, false)
200
213
#undef DT_DRV_COMPAT
201
214
#define DT_DRV_COMPAT ti_tca9546a
202
215
DT_INST_FOREACH_STATUS_OKAY (TCA9546A_INIT )
203
216
204
217
/*
205
- * TCA9548A: 8 channels
218
+ * TCA9548A: 8 channels switch
206
219
*/
207
- #define TCA9548A_INIT (n ) TCA954x_ROOT_DEFINE(9548, n, 8)
220
+ #define TCA9548A_INIT (n ) TCA954x_ROOT_DEFINE(9548, n, 8, false )
208
221
#undef DT_DRV_COMPAT
209
222
#define DT_DRV_COMPAT ti_tca9548a
210
223
DT_INST_FOREACH_STATUS_OKAY (TCA9548A_INIT )
0 commit comments