summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/extcon/extcon.c44
-rw-r--r--include/linux/extcon.h6
2 files changed, 40 insertions, 10 deletions
diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c
index cb38c2747684..8bff5fd18185 100644
--- a/drivers/extcon/extcon.c
+++ b/drivers/extcon/extcon.c
@@ -1336,6 +1336,28 @@ void extcon_dev_unregister(struct extcon_dev *edev)
1336EXPORT_SYMBOL_GPL(extcon_dev_unregister); 1336EXPORT_SYMBOL_GPL(extcon_dev_unregister);
1337 1337
1338#ifdef CONFIG_OF 1338#ifdef CONFIG_OF
1339
1340/*
1341 * extcon_find_edev_by_node - Find the extcon device from devicetree.
1342 * @node : OF node identifying edev
1343 *
1344 * Return the pointer of extcon device if success or ERR_PTR(err) if fail.
1345 */
1346struct extcon_dev *extcon_find_edev_by_node(struct device_node *node)
1347{
1348 struct extcon_dev *edev;
1349
1350 mutex_lock(&extcon_dev_list_lock);
1351 list_for_each_entry(edev, &extcon_dev_list, entry)
1352 if (edev->dev.parent && edev->dev.parent->of_node == node)
1353 goto out;
1354 edev = ERR_PTR(-EPROBE_DEFER);
1355out:
1356 mutex_unlock(&extcon_dev_list_lock);
1357
1358 return edev;
1359}
1360
1339/* 1361/*
1340 * extcon_get_edev_by_phandle - Get the extcon device from devicetree. 1362 * extcon_get_edev_by_phandle - Get the extcon device from devicetree.
1341 * @dev : the instance to the given device 1363 * @dev : the instance to the given device
@@ -1363,25 +1385,27 @@ struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index)
1363 return ERR_PTR(-ENODEV); 1385 return ERR_PTR(-ENODEV);
1364 } 1386 }
1365 1387
1366 mutex_lock(&extcon_dev_list_lock); 1388 edev = extcon_find_edev_by_node(node);
1367 list_for_each_entry(edev, &extcon_dev_list, entry) {
1368 if (edev->dev.parent && edev->dev.parent->of_node == node) {
1369 mutex_unlock(&extcon_dev_list_lock);
1370 of_node_put(node);
1371 return edev;
1372 }
1373 }
1374 mutex_unlock(&extcon_dev_list_lock);
1375 of_node_put(node); 1389 of_node_put(node);
1376 1390
1377 return ERR_PTR(-EPROBE_DEFER); 1391 return edev;
1378} 1392}
1393
1379#else 1394#else
1395
1396struct extcon_dev *extcon_find_edev_by_node(struct device_node *node)
1397{
1398 return ERR_PTR(-ENOSYS);
1399}
1400
1380struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index) 1401struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index)
1381{ 1402{
1382 return ERR_PTR(-ENOSYS); 1403 return ERR_PTR(-ENOSYS);
1383} 1404}
1405
1384#endif /* CONFIG_OF */ 1406#endif /* CONFIG_OF */
1407
1408EXPORT_SYMBOL_GPL(extcon_find_edev_by_node);
1385EXPORT_SYMBOL_GPL(extcon_get_edev_by_phandle); 1409EXPORT_SYMBOL_GPL(extcon_get_edev_by_phandle);
1386 1410
1387/** 1411/**
diff --git a/include/linux/extcon.h b/include/linux/extcon.h
index 6d94e82c8ad9..7f033b1ea568 100644
--- a/include/linux/extcon.h
+++ b/include/linux/extcon.h
@@ -230,6 +230,7 @@ extern void devm_extcon_unregister_notifier_all(struct device *dev,
230 * Following APIs get the extcon_dev from devicetree or by through extcon name. 230 * Following APIs get the extcon_dev from devicetree or by through extcon name.
231 */ 231 */
232extern struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name); 232extern struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name);
233extern struct extcon_dev *extcon_find_edev_by_node(struct device_node *node);
233extern struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, 234extern struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev,
234 int index); 235 int index);
235 236
@@ -283,6 +284,11 @@ static inline struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name)
283 return ERR_PTR(-ENODEV); 284 return ERR_PTR(-ENODEV);
284} 285}
285 286
287static inline struct extcon_dev *extcon_find_edev_by_node(struct device_node *node)
288{
289 return ERR_PTR(-ENODEV);
290}
291
286static inline struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, 292static inline struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev,
287 int index) 293 int index)
288{ 294{