Skip to content

Commit bb47523

Browse files
RamiroOliveirapH5
authored andcommitted
reset: make optional functions really optional
The *_get_optional_* functions weren't really optional so this patch makes them really optional. These *_get_optional_* functions will now return NULL instead of an error if no matching reset phandle is found in the DT, and all the reset_control_* functions now accept NULL rstc pointers. Signed-off-by: Ramiro Oliveira <Ramiro.Oliveira@synopsys.com> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
1 parent ee48c72 commit bb47523

File tree

2 files changed

+65
-29
lines changed

2 files changed

+65
-29
lines changed

drivers/reset/core.c

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,18 @@ EXPORT_SYMBOL_GPL(devm_reset_controller_register);
143143
* a no-op.
144144
* Consumers must not use reset_control_(de)assert on shared reset lines when
145145
* reset_control_reset has been used.
146+
*
147+
* If rstc is NULL it is an optional reset and the function will just
148+
* return 0.
146149
*/
147150
int reset_control_reset(struct reset_control *rstc)
148151
{
149152
int ret;
150153

151-
if (WARN_ON(IS_ERR_OR_NULL(rstc)))
154+
if (!rstc)
155+
return 0;
156+
157+
if (WARN_ON(IS_ERR(rstc)))
152158
return -EINVAL;
153159

154160
if (!rstc->rcdev->ops->reset)
@@ -182,10 +188,17 @@ EXPORT_SYMBOL_GPL(reset_control_reset);
182188
* internal state to be reset, but must be prepared for this to happen.
183189
* Consumers must not use reset_control_reset on shared reset lines when
184190
* reset_control_(de)assert has been used.
191+
* return 0.
192+
*
193+
* If rstc is NULL it is an optional reset and the function will just
194+
* return 0.
185195
*/
186196
int reset_control_assert(struct reset_control *rstc)
187197
{
188-
if (WARN_ON(IS_ERR_OR_NULL(rstc)))
198+
if (!rstc)
199+
return 0;
200+
201+
if (WARN_ON(IS_ERR(rstc)))
189202
return -EINVAL;
190203

191204
if (!rstc->rcdev->ops->assert)
@@ -213,10 +226,17 @@ EXPORT_SYMBOL_GPL(reset_control_assert);
213226
* After calling this function, the reset is guaranteed to be deasserted.
214227
* Consumers must not use reset_control_reset on shared reset lines when
215228
* reset_control_(de)assert has been used.
229+
* return 0.
230+
*
231+
* If rstc is NULL it is an optional reset and the function will just
232+
* return 0.
216233
*/
217234
int reset_control_deassert(struct reset_control *rstc)
218235
{
219-
if (WARN_ON(IS_ERR_OR_NULL(rstc)))
236+
if (!rstc)
237+
return 0;
238+
239+
if (WARN_ON(IS_ERR(rstc)))
220240
return -EINVAL;
221241

222242
if (!rstc->rcdev->ops->deassert)
@@ -237,12 +257,15 @@ EXPORT_SYMBOL_GPL(reset_control_deassert);
237257
/**
238258
* reset_control_status - returns a negative errno if not supported, a
239259
* positive value if the reset line is asserted, or zero if the reset
240-
* line is not asserted.
260+
* line is not asserted or if the desc is NULL (optional reset).
241261
* @rstc: reset controller
242262
*/
243263
int reset_control_status(struct reset_control *rstc)
244264
{
245-
if (WARN_ON(IS_ERR_OR_NULL(rstc)))
265+
if (!rstc)
266+
return 0;
267+
268+
if (WARN_ON(IS_ERR(rstc)))
246269
return -EINVAL;
247270

248271
if (rstc->rcdev->ops->status)
@@ -299,7 +322,8 @@ static void __reset_control_put(struct reset_control *rstc)
299322
}
300323

301324
struct reset_control *__of_reset_control_get(struct device_node *node,
302-
const char *id, int index, bool shared)
325+
const char *id, int index, bool shared,
326+
bool optional)
303327
{
304328
struct reset_control *rstc;
305329
struct reset_controller_dev *r, *rcdev;
@@ -313,14 +337,18 @@ struct reset_control *__of_reset_control_get(struct device_node *node,
313337
if (id) {
314338
index = of_property_match_string(node,
315339
"reset-names", id);
340+
if (index == -EILSEQ)
341+
return ERR_PTR(index);
316342
if (index < 0)
317-
return ERR_PTR(-ENOENT);
343+
return optional ? NULL : ERR_PTR(-ENOENT);
318344
}
319345

320346
ret = of_parse_phandle_with_args(node, "resets", "#reset-cells",
321347
index, &args);
322-
if (ret)
348+
if (ret == -EINVAL)
323349
return ERR_PTR(ret);
350+
if (ret)
351+
return optional ? NULL : ERR_PTR(ret);
324352

325353
mutex_lock(&reset_list_mutex);
326354
rcdev = NULL;
@@ -379,7 +407,8 @@ static void devm_reset_control_release(struct device *dev, void *res)
379407
}
380408

381409
struct reset_control *__devm_reset_control_get(struct device *dev,
382-
const char *id, int index, bool shared)
410+
const char *id, int index, bool shared,
411+
bool optional)
383412
{
384413
struct reset_control **ptr, *rstc;
385414

@@ -389,7 +418,7 @@ struct reset_control *__devm_reset_control_get(struct device *dev,
389418
return ERR_PTR(-ENOMEM);
390419

391420
rstc = __of_reset_control_get(dev ? dev->of_node : NULL,
392-
id, index, shared);
421+
id, index, shared, optional);
393422
if (!IS_ERR(rstc)) {
394423
*ptr = rstc;
395424
devres_add(dev, ptr);

include/linux/reset.h

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ int reset_control_deassert(struct reset_control *rstc);
1313
int reset_control_status(struct reset_control *rstc);
1414

1515
struct reset_control *__of_reset_control_get(struct device_node *node,
16-
const char *id, int index, bool shared);
16+
const char *id, int index, bool shared,
17+
bool optional);
1718
void reset_control_put(struct reset_control *rstc);
1819
struct reset_control *__devm_reset_control_get(struct device *dev,
19-
const char *id, int index, bool shared);
20+
const char *id, int index, bool shared,
21+
bool optional);
2022

2123
int __must_check device_reset(struct device *dev);
2224

@@ -69,14 +71,15 @@ static inline int device_reset_optional(struct device *dev)
6971

7072
static inline struct reset_control *__of_reset_control_get(
7173
struct device_node *node,
72-
const char *id, int index, bool shared)
74+
const char *id, int index, bool shared,
75+
bool optional)
7376
{
7477
return ERR_PTR(-ENOTSUPP);
7578
}
7679

7780
static inline struct reset_control *__devm_reset_control_get(
78-
struct device *dev,
79-
const char *id, int index, bool shared)
81+
struct device *dev, const char *id,
82+
int index, bool shared, bool optional)
8083
{
8184
return ERR_PTR(-ENOTSUPP);
8285
}
@@ -104,7 +107,8 @@ __must_check reset_control_get_exclusive(struct device *dev, const char *id)
104107
#ifndef CONFIG_RESET_CONTROLLER
105108
WARN_ON(1);
106109
#endif
107-
return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, 0);
110+
return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, false,
111+
false);
108112
}
109113

110114
/**
@@ -132,19 +136,22 @@ __must_check reset_control_get_exclusive(struct device *dev, const char *id)
132136
static inline struct reset_control *reset_control_get_shared(
133137
struct device *dev, const char *id)
134138
{
135-
return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, true);
139+
return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, true,
140+
false);
136141
}
137142

138143
static inline struct reset_control *reset_control_get_optional_exclusive(
139144
struct device *dev, const char *id)
140145
{
141-
return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, false);
146+
return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, false,
147+
true);
142148
}
143149

144150
static inline struct reset_control *reset_control_get_optional_shared(
145151
struct device *dev, const char *id)
146152
{
147-
return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, true);
153+
return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, true,
154+
true);
148155
}
149156

150157
/**
@@ -160,7 +167,7 @@ static inline struct reset_control *reset_control_get_optional_shared(
160167
static inline struct reset_control *of_reset_control_get_exclusive(
161168
struct device_node *node, const char *id)
162169
{
163-
return __of_reset_control_get(node, id, 0, 0);
170+
return __of_reset_control_get(node, id, 0, false, false);
164171
}
165172

166173
/**
@@ -185,7 +192,7 @@ static inline struct reset_control *of_reset_control_get_exclusive(
185192
static inline struct reset_control *of_reset_control_get_shared(
186193
struct device_node *node, const char *id)
187194
{
188-
return __of_reset_control_get(node, id, 0, true);
195+
return __of_reset_control_get(node, id, 0, true, false);
189196
}
190197

191198
/**
@@ -202,7 +209,7 @@ static inline struct reset_control *of_reset_control_get_shared(
202209
static inline struct reset_control *of_reset_control_get_exclusive_by_index(
203210
struct device_node *node, int index)
204211
{
205-
return __of_reset_control_get(node, NULL, index, false);
212+
return __of_reset_control_get(node, NULL, index, false, false);
206213
}
207214

208215
/**
@@ -230,7 +237,7 @@ static inline struct reset_control *of_reset_control_get_exclusive_by_index(
230237
static inline struct reset_control *of_reset_control_get_shared_by_index(
231238
struct device_node *node, int index)
232239
{
233-
return __of_reset_control_get(node, NULL, index, true);
240+
return __of_reset_control_get(node, NULL, index, true, false);
234241
}
235242

236243
/**
@@ -252,7 +259,7 @@ __must_check devm_reset_control_get_exclusive(struct device *dev,
252259
#ifndef CONFIG_RESET_CONTROLLER
253260
WARN_ON(1);
254261
#endif
255-
return __devm_reset_control_get(dev, id, 0, false);
262+
return __devm_reset_control_get(dev, id, 0, false, false);
256263
}
257264

258265
/**
@@ -267,19 +274,19 @@ __must_check devm_reset_control_get_exclusive(struct device *dev,
267274
static inline struct reset_control *devm_reset_control_get_shared(
268275
struct device *dev, const char *id)
269276
{
270-
return __devm_reset_control_get(dev, id, 0, true);
277+
return __devm_reset_control_get(dev, id, 0, true, false);
271278
}
272279

273280
static inline struct reset_control *devm_reset_control_get_optional_exclusive(
274281
struct device *dev, const char *id)
275282
{
276-
return __devm_reset_control_get(dev, id, 0, false);
283+
return __devm_reset_control_get(dev, id, 0, false, true);
277284
}
278285

279286
static inline struct reset_control *devm_reset_control_get_optional_shared(
280287
struct device *dev, const char *id)
281288
{
282-
return __devm_reset_control_get(dev, id, 0, true);
289+
return __devm_reset_control_get(dev, id, 0, true, true);
283290
}
284291

285292
/**
@@ -297,7 +304,7 @@ static inline struct reset_control *devm_reset_control_get_optional_shared(
297304
static inline struct reset_control *
298305
devm_reset_control_get_exclusive_by_index(struct device *dev, int index)
299306
{
300-
return __devm_reset_control_get(dev, NULL, index, false);
307+
return __devm_reset_control_get(dev, NULL, index, false, false);
301308
}
302309

303310
/**
@@ -313,7 +320,7 @@ devm_reset_control_get_exclusive_by_index(struct device *dev, int index)
313320
static inline struct reset_control *
314321
devm_reset_control_get_shared_by_index(struct device *dev, int index)
315322
{
316-
return __devm_reset_control_get(dev, NULL, index, true);
323+
return __devm_reset_control_get(dev, NULL, index, true, false);
317324
}
318325

319326
/*

0 commit comments

Comments
 (0)