|
11 | 11 | #include <linux/cleanup.h> |
12 | 12 | #include <linux/clk.h> |
13 | 13 | #include <linux/delay.h> |
| 14 | +#include <linux/device.h> |
14 | 15 | #include <linux/iopoll.h> |
15 | 16 | #include <linux/of.h> |
16 | 17 | #include <linux/of_platform.h> |
@@ -261,7 +262,7 @@ static struct qcom_ice *qcom_ice_create(struct device *dev, |
261 | 262 | * Return: ICE pointer on success, NULL if there is no ICE data provided by the |
262 | 263 | * consumer or ERR_PTR() on error. |
263 | 264 | */ |
264 | | -struct qcom_ice *of_qcom_ice_get(struct device *dev) |
| 265 | +static struct qcom_ice *of_qcom_ice_get(struct device *dev) |
265 | 266 | { |
266 | 267 | struct platform_device *pdev = to_platform_device(dev); |
267 | 268 | struct qcom_ice *ice; |
@@ -322,7 +323,53 @@ struct qcom_ice *of_qcom_ice_get(struct device *dev) |
322 | 323 |
|
323 | 324 | return ice; |
324 | 325 | } |
325 | | -EXPORT_SYMBOL_GPL(of_qcom_ice_get); |
| 326 | + |
| 327 | +static void qcom_ice_put(const struct qcom_ice *ice) |
| 328 | +{ |
| 329 | + struct platform_device *pdev = to_platform_device(ice->dev); |
| 330 | + |
| 331 | + if (!platform_get_resource_byname(pdev, IORESOURCE_MEM, "ice")) |
| 332 | + platform_device_put(pdev); |
| 333 | +} |
| 334 | + |
| 335 | +static void devm_of_qcom_ice_put(struct device *dev, void *res) |
| 336 | +{ |
| 337 | + qcom_ice_put(*(struct qcom_ice **)res); |
| 338 | +} |
| 339 | + |
| 340 | +/** |
| 341 | + * devm_of_qcom_ice_get() - Devres managed helper to get an ICE instance from |
| 342 | + * a DT node. |
| 343 | + * @dev: device pointer for the consumer device. |
| 344 | + * |
| 345 | + * This function will provide an ICE instance either by creating one for the |
| 346 | + * consumer device if its DT node provides the 'ice' reg range and the 'ice' |
| 347 | + * clock (for legacy DT style). On the other hand, if consumer provides a |
| 348 | + * phandle via 'qcom,ice' property to an ICE DT, the ICE instance will already |
| 349 | + * be created and so this function will return that instead. |
| 350 | + * |
| 351 | + * Return: ICE pointer on success, NULL if there is no ICE data provided by the |
| 352 | + * consumer or ERR_PTR() on error. |
| 353 | + */ |
| 354 | +struct qcom_ice *devm_of_qcom_ice_get(struct device *dev) |
| 355 | +{ |
| 356 | + struct qcom_ice *ice, **dr; |
| 357 | + |
| 358 | + dr = devres_alloc(devm_of_qcom_ice_put, sizeof(*dr), GFP_KERNEL); |
| 359 | + if (!dr) |
| 360 | + return ERR_PTR(-ENOMEM); |
| 361 | + |
| 362 | + ice = of_qcom_ice_get(dev); |
| 363 | + if (!IS_ERR_OR_NULL(ice)) { |
| 364 | + *dr = ice; |
| 365 | + devres_add(dev, dr); |
| 366 | + } else { |
| 367 | + devres_free(dr); |
| 368 | + } |
| 369 | + |
| 370 | + return ice; |
| 371 | +} |
| 372 | +EXPORT_SYMBOL_GPL(devm_of_qcom_ice_get); |
326 | 373 |
|
327 | 374 | static int qcom_ice_probe(struct platform_device *pdev) |
328 | 375 | { |
|
0 commit comments