@@ -1136,6 +1136,92 @@ static int find_sdca_entity_pde(struct device *dev,
1136
1136
return 0 ;
1137
1137
}
1138
1138
1139
+ struct raw_ge_mode {
1140
+ u8 val ;
1141
+ u8 num_controls ;
1142
+ struct {
1143
+ u8 id ;
1144
+ u8 sel ;
1145
+ u8 cn ;
1146
+ __le32 val ;
1147
+ } __packed controls [] __counted_by (num_controls );
1148
+ } __packed ;
1149
+
1150
+ static int find_sdca_entity_ge (struct device * dev ,
1151
+ struct fwnode_handle * entity_node ,
1152
+ struct sdca_entity * entity )
1153
+ {
1154
+ struct sdca_entity_ge * group = & entity -> ge ;
1155
+ u8 * affected_list __free (kfree ) = NULL ;
1156
+ u8 * affected_iter ;
1157
+ int num_affected ;
1158
+ int i , j ;
1159
+
1160
+ num_affected = fwnode_property_count_u8 (entity_node ,
1161
+ "mipi-sdca-ge-selectedmode-controls-affected" );
1162
+ if (!num_affected || num_affected == - EINVAL ) {
1163
+ return 0 ;
1164
+ } else if (num_affected < 0 ) {
1165
+ dev_err (dev , "%s: failed to read affected controls: %d\n" ,
1166
+ entity -> label , num_affected );
1167
+ return num_affected ;
1168
+ } else if (num_affected > SDCA_MAX_AFFECTED_COUNT ) {
1169
+ dev_err (dev , "%s: maximum affected controls size exceeded\n" ,
1170
+ entity -> label );
1171
+ return - EINVAL ;
1172
+ }
1173
+
1174
+ affected_list = kcalloc (num_affected , sizeof (* affected_list ), GFP_KERNEL );
1175
+ if (!affected_list )
1176
+ return - ENOMEM ;
1177
+
1178
+ fwnode_property_read_u8_array (entity_node ,
1179
+ "mipi-sdca-ge-selectedmode-controls-affected" ,
1180
+ affected_list , num_affected );
1181
+
1182
+ group -> num_modes = * affected_list ;
1183
+ affected_iter = affected_list + 1 ;
1184
+
1185
+ group -> modes = devm_kcalloc (dev , group -> num_modes , sizeof (* group -> modes ),
1186
+ GFP_KERNEL );
1187
+ if (!group -> modes )
1188
+ return - ENOMEM ;
1189
+
1190
+ for (i = 0 ; i < group -> num_modes ; i ++ ) {
1191
+ struct raw_ge_mode * raw = (struct raw_ge_mode * )affected_iter ;
1192
+ struct sdca_ge_mode * mode = & group -> modes [i ];
1193
+
1194
+ affected_iter += sizeof (* raw );
1195
+ if (affected_iter > affected_list + num_affected )
1196
+ goto bad_list ;
1197
+
1198
+ mode -> val = raw -> val ;
1199
+ mode -> num_controls = raw -> num_controls ;
1200
+
1201
+ affected_iter += mode -> num_controls * sizeof (raw -> controls [0 ]);
1202
+ if (affected_iter > affected_list + num_affected )
1203
+ goto bad_list ;
1204
+
1205
+ mode -> controls = devm_kcalloc (dev , mode -> num_controls ,
1206
+ sizeof (* mode -> controls ), GFP_KERNEL );
1207
+ if (!mode -> controls )
1208
+ return - ENOMEM ;
1209
+
1210
+ for (j = 0 ; j < mode -> num_controls ; j ++ ) {
1211
+ mode -> controls [j ].id = raw -> controls [j ].id ;
1212
+ mode -> controls [j ].sel = raw -> controls [j ].sel ;
1213
+ mode -> controls [j ].cn = raw -> controls [j ].cn ;
1214
+ mode -> controls [j ].val = le32_to_cpu (raw -> controls [j ].val );
1215
+ }
1216
+ }
1217
+
1218
+ return 0 ;
1219
+
1220
+ bad_list :
1221
+ dev_err (dev , "%s: malformed affected controls list\n" , entity -> label );
1222
+ return - EINVAL ;
1223
+ }
1224
+
1139
1225
static int find_sdca_entity (struct device * dev ,
1140
1226
struct fwnode_handle * function_node ,
1141
1227
struct fwnode_handle * entity_node ,
@@ -1174,6 +1260,9 @@ static int find_sdca_entity(struct device *dev,
1174
1260
case SDCA_ENTITY_TYPE_PDE :
1175
1261
ret = find_sdca_entity_pde (dev , entity_node , entity );
1176
1262
break ;
1263
+ case SDCA_ENTITY_TYPE_GE :
1264
+ ret = find_sdca_entity_ge (dev , entity_node , entity );
1265
+ break ;
1177
1266
default :
1178
1267
break ;
1179
1268
}
@@ -1384,6 +1473,42 @@ static int find_sdca_entity_connection_pde(struct device *dev,
1384
1473
return 0 ;
1385
1474
}
1386
1475
1476
+ static int find_sdca_entity_connection_ge (struct device * dev ,
1477
+ struct sdca_function_data * function ,
1478
+ struct fwnode_handle * entity_node ,
1479
+ struct sdca_entity * entity )
1480
+ {
1481
+ int i , j ;
1482
+
1483
+ for (i = 0 ; i < entity -> ge .num_modes ; i ++ ) {
1484
+ struct sdca_ge_mode * mode = & entity -> ge .modes [i ];
1485
+
1486
+ for (j = 0 ; j < mode -> num_controls ; j ++ ) {
1487
+ struct sdca_ge_control * affected = & mode -> controls [j ];
1488
+ struct sdca_entity * managed ;
1489
+
1490
+ managed = find_sdca_entity_by_id (function , affected -> id );
1491
+ if (!managed ) {
1492
+ dev_err (dev , "%s: failed to find entity with id %#x\n" ,
1493
+ entity -> label , affected -> id );
1494
+ return - EINVAL ;
1495
+ }
1496
+
1497
+ if (managed -> group && managed -> group != entity ) {
1498
+ dev_err (dev ,
1499
+ "%s: entity controlled by two groups %s, %s\n" ,
1500
+ managed -> label , managed -> group -> label ,
1501
+ entity -> label );
1502
+ return - EINVAL ;
1503
+ }
1504
+
1505
+ managed -> group = entity ;
1506
+ }
1507
+ }
1508
+
1509
+ return 0 ;
1510
+ }
1511
+
1387
1512
static int find_sdca_entity_connection (struct device * dev ,
1388
1513
struct sdca_function_data * function ,
1389
1514
struct fwnode_handle * entity_node ,
@@ -1404,6 +1529,10 @@ static int find_sdca_entity_connection(struct device *dev,
1404
1529
ret = find_sdca_entity_connection_pde (dev , function ,
1405
1530
entity_node , entity );
1406
1531
break ;
1532
+ case SDCA_ENTITY_TYPE_GE :
1533
+ ret = find_sdca_entity_connection_ge (dev , function ,
1534
+ entity_node , entity );
1535
+ break ;
1407
1536
default :
1408
1537
ret = 0 ;
1409
1538
break ;
0 commit comments