@@ -773,12 +773,19 @@ EXPORT_SYMBOL_GPL(reset_control_bulk_release);
773
773
774
774
static struct reset_control *
775
775
__reset_control_get_internal (struct reset_controller_dev * rcdev ,
776
- unsigned int index , bool shared , bool acquired )
776
+ unsigned int index , enum reset_control_flags flags )
777
777
{
778
+ bool shared = flags & RESET_CONTROL_FLAGS_BIT_SHARED ;
779
+ bool acquired = flags & RESET_CONTROL_FLAGS_BIT_ACQUIRED ;
778
780
struct reset_control * rstc ;
779
781
780
782
lockdep_assert_held (& reset_list_mutex );
781
783
784
+ /* Expect callers to filter out OPTIONAL and DEASSERTED bits */
785
+ if (WARN_ON (flags & ~(RESET_CONTROL_FLAGS_BIT_SHARED |
786
+ RESET_CONTROL_FLAGS_BIT_ACQUIRED )))
787
+ return ERR_PTR (- EINVAL );
788
+
782
789
list_for_each_entry (rstc , & rcdev -> reset_control_head , list ) {
783
790
if (rstc -> id == index ) {
784
791
/*
@@ -994,8 +1001,9 @@ static struct reset_controller_dev *__reset_find_rcdev(const struct of_phandle_a
994
1001
995
1002
struct reset_control *
996
1003
__of_reset_control_get (struct device_node * node , const char * id , int index ,
997
- bool shared , bool optional , bool acquired )
1004
+ enum reset_control_flags flags )
998
1005
{
1006
+ bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL ;
999
1007
bool gpio_fallback = false;
1000
1008
struct reset_control * rstc ;
1001
1009
struct reset_controller_dev * rcdev ;
@@ -1059,8 +1067,10 @@ __of_reset_control_get(struct device_node *node, const char *id, int index,
1059
1067
goto out_unlock ;
1060
1068
}
1061
1069
1070
+ flags &= ~RESET_CONTROL_FLAGS_BIT_OPTIONAL ;
1071
+
1062
1072
/* reset_list_mutex also protects the rcdev's reset_control list */
1063
- rstc = __reset_control_get_internal (rcdev , rstc_id , shared , acquired );
1073
+ rstc = __reset_control_get_internal (rcdev , rstc_id , flags );
1064
1074
1065
1075
out_unlock :
1066
1076
mutex_unlock (& reset_list_mutex );
@@ -1091,8 +1101,9 @@ __reset_controller_by_name(const char *name)
1091
1101
1092
1102
static struct reset_control *
1093
1103
__reset_control_get_from_lookup (struct device * dev , const char * con_id ,
1094
- bool shared , bool optional , bool acquired )
1104
+ enum reset_control_flags flags )
1095
1105
{
1106
+ bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL ;
1096
1107
const struct reset_control_lookup * lookup ;
1097
1108
struct reset_controller_dev * rcdev ;
1098
1109
const char * dev_id = dev_name (dev );
@@ -1116,9 +1127,11 @@ __reset_control_get_from_lookup(struct device *dev, const char *con_id,
1116
1127
return ERR_PTR (- EPROBE_DEFER );
1117
1128
}
1118
1129
1130
+ flags &= ~RESET_CONTROL_FLAGS_BIT_OPTIONAL ;
1131
+
1119
1132
rstc = __reset_control_get_internal (rcdev ,
1120
1133
lookup -> index ,
1121
- shared , acquired );
1134
+ flags );
1122
1135
mutex_unlock (& reset_list_mutex );
1123
1136
break ;
1124
1137
}
@@ -1133,30 +1146,29 @@ __reset_control_get_from_lookup(struct device *dev, const char *con_id,
1133
1146
}
1134
1147
1135
1148
struct reset_control * __reset_control_get (struct device * dev , const char * id ,
1136
- int index , bool shared , bool optional ,
1137
- bool acquired )
1149
+ int index , enum reset_control_flags flags )
1138
1150
{
1151
+ bool shared = flags & RESET_CONTROL_FLAGS_BIT_SHARED ;
1152
+ bool acquired = flags & RESET_CONTROL_FLAGS_BIT_ACQUIRED ;
1153
+
1139
1154
if (WARN_ON (shared && acquired ))
1140
1155
return ERR_PTR (- EINVAL );
1141
1156
1142
1157
if (dev -> of_node )
1143
- return __of_reset_control_get (dev -> of_node , id , index , shared ,
1144
- optional , acquired );
1158
+ return __of_reset_control_get (dev -> of_node , id , index , flags );
1145
1159
1146
- return __reset_control_get_from_lookup (dev , id , shared , optional ,
1147
- acquired );
1160
+ return __reset_control_get_from_lookup (dev , id , flags );
1148
1161
}
1149
1162
EXPORT_SYMBOL_GPL (__reset_control_get );
1150
1163
1151
1164
int __reset_control_bulk_get (struct device * dev , int num_rstcs ,
1152
1165
struct reset_control_bulk_data * rstcs ,
1153
- bool shared , bool optional , bool acquired )
1166
+ enum reset_control_flags flags )
1154
1167
{
1155
1168
int ret , i ;
1156
1169
1157
1170
for (i = 0 ; i < num_rstcs ; i ++ ) {
1158
- rstcs [i ].rstc = __reset_control_get (dev , rstcs [i ].id , 0 ,
1159
- shared , optional , acquired );
1171
+ rstcs [i ].rstc = __reset_control_get (dev , rstcs [i ].id , 0 , flags );
1160
1172
if (IS_ERR (rstcs [i ].rstc )) {
1161
1173
ret = PTR_ERR (rstcs [i ].rstc );
1162
1174
goto err ;
@@ -1226,7 +1238,7 @@ static void devm_reset_control_release(struct device *dev, void *res)
1226
1238
1227
1239
struct reset_control *
1228
1240
__devm_reset_control_get (struct device * dev , const char * id , int index ,
1229
- bool shared , bool optional , bool acquired )
1241
+ enum reset_control_flags flags )
1230
1242
{
1231
1243
struct reset_control * * ptr , * rstc ;
1232
1244
@@ -1235,7 +1247,7 @@ __devm_reset_control_get(struct device *dev, const char *id, int index,
1235
1247
if (!ptr )
1236
1248
return ERR_PTR (- ENOMEM );
1237
1249
1238
- rstc = __reset_control_get (dev , id , index , shared , optional , acquired );
1250
+ rstc = __reset_control_get (dev , id , index , flags );
1239
1251
if (IS_ERR_OR_NULL (rstc )) {
1240
1252
devres_free (ptr );
1241
1253
return rstc ;
@@ -1262,7 +1274,7 @@ static void devm_reset_control_bulk_release(struct device *dev, void *res)
1262
1274
1263
1275
int __devm_reset_control_bulk_get (struct device * dev , int num_rstcs ,
1264
1276
struct reset_control_bulk_data * rstcs ,
1265
- bool shared , bool optional , bool acquired )
1277
+ enum reset_control_flags flags )
1266
1278
{
1267
1279
struct reset_control_bulk_devres * ptr ;
1268
1280
int ret ;
@@ -1272,7 +1284,7 @@ int __devm_reset_control_bulk_get(struct device *dev, int num_rstcs,
1272
1284
if (!ptr )
1273
1285
return - ENOMEM ;
1274
1286
1275
- ret = __reset_control_bulk_get (dev , num_rstcs , rstcs , shared , optional , acquired );
1287
+ ret = __reset_control_bulk_get (dev , num_rstcs , rstcs , flags );
1276
1288
if (ret < 0 ) {
1277
1289
devres_free (ptr );
1278
1290
return ret ;
@@ -1298,6 +1310,7 @@ EXPORT_SYMBOL_GPL(__devm_reset_control_bulk_get);
1298
1310
*/
1299
1311
int __device_reset (struct device * dev , bool optional )
1300
1312
{
1313
+ enum reset_control_flags flags ;
1301
1314
struct reset_control * rstc ;
1302
1315
int ret ;
1303
1316
@@ -1313,7 +1326,8 @@ int __device_reset(struct device *dev, bool optional)
1313
1326
}
1314
1327
#endif
1315
1328
1316
- rstc = __reset_control_get (dev , NULL , 0 , 0 , optional , true);
1329
+ flags = optional ? RESET_CONTROL_OPTIONAL_EXCLUSIVE : RESET_CONTROL_EXCLUSIVE ;
1330
+ rstc = __reset_control_get (dev , NULL , 0 , flags );
1317
1331
if (IS_ERR (rstc ))
1318
1332
return PTR_ERR (rstc );
1319
1333
@@ -1356,17 +1370,14 @@ static int of_reset_control_get_count(struct device_node *node)
1356
1370
* device node.
1357
1371
*
1358
1372
* @np: device node for the device that requests the reset controls array
1359
- * @shared: whether reset controls are shared or not
1360
- * @optional: whether it is optional to get the reset controls
1361
- * @acquired: only one reset control may be acquired for a given controller
1362
- * and ID
1373
+ * @flags: whether reset controls are shared, optional, acquired
1363
1374
*
1364
1375
* Returns pointer to allocated reset_control on success or error on failure
1365
1376
*/
1366
1377
struct reset_control *
1367
- of_reset_control_array_get (struct device_node * np , bool shared , bool optional ,
1368
- bool acquired )
1378
+ of_reset_control_array_get (struct device_node * np , enum reset_control_flags flags )
1369
1379
{
1380
+ bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL ;
1370
1381
struct reset_control_array * resets ;
1371
1382
struct reset_control * rstc ;
1372
1383
int num , i ;
@@ -1381,8 +1392,7 @@ of_reset_control_array_get(struct device_node *np, bool shared, bool optional,
1381
1392
resets -> num_rstcs = num ;
1382
1393
1383
1394
for (i = 0 ; i < num ; i ++ ) {
1384
- rstc = __of_reset_control_get (np , NULL , i , shared , optional ,
1385
- acquired );
1395
+ rstc = __of_reset_control_get (np , NULL , i , flags );
1386
1396
if (IS_ERR (rstc ))
1387
1397
goto err_rst ;
1388
1398
resets -> rstc [i ] = rstc ;
@@ -1407,8 +1417,7 @@ EXPORT_SYMBOL_GPL(of_reset_control_array_get);
1407
1417
* devm_reset_control_array_get - Resource managed reset control array get
1408
1418
*
1409
1419
* @dev: device that requests the list of reset controls
1410
- * @shared: whether reset controls are shared or not
1411
- * @optional: whether it is optional to get the reset controls
1420
+ * @flags: whether reset controls are shared, optional, acquired
1412
1421
*
1413
1422
* The reset control array APIs are intended for a list of resets
1414
1423
* that just have to be asserted or deasserted, without any
@@ -1417,7 +1426,7 @@ EXPORT_SYMBOL_GPL(of_reset_control_array_get);
1417
1426
* Returns pointer to allocated reset_control on success or error on failure
1418
1427
*/
1419
1428
struct reset_control *
1420
- devm_reset_control_array_get (struct device * dev , bool shared , bool optional )
1429
+ devm_reset_control_array_get (struct device * dev , enum reset_control_flags flags )
1421
1430
{
1422
1431
struct reset_control * * ptr , * rstc ;
1423
1432
@@ -1426,7 +1435,7 @@ devm_reset_control_array_get(struct device *dev, bool shared, bool optional)
1426
1435
if (!ptr )
1427
1436
return ERR_PTR (- ENOMEM );
1428
1437
1429
- rstc = of_reset_control_array_get (dev -> of_node , shared , optional , true );
1438
+ rstc = of_reset_control_array_get (dev -> of_node , flags );
1430
1439
if (IS_ERR_OR_NULL (rstc )) {
1431
1440
devres_free (ptr );
1432
1441
return rstc ;
0 commit comments