Skip to content

Commit 370ed7a

Browse files
Andrzej Hajdachanwoochoi
authored andcommitted
extcon: add possibility to get extcon device by OF node
Since extcon property is not allowed in DT, extcon subsystem requires another way to get extcon device. Lets try the simplest approach - get edev by of_node. Signed-off-by: Andrzej Hajda <[email protected]> Acked-by: Chanwoo Choi <[email protected]> Signed-off-by: Chanwoo Choi <[email protected]>
1 parent 1421717 commit 370ed7a

File tree

2 files changed

+40
-10
lines changed

2 files changed

+40
-10
lines changed

drivers/extcon/extcon.c

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,28 @@ void extcon_dev_unregister(struct extcon_dev *edev)
13361336
EXPORT_SYMBOL_GPL(extcon_dev_unregister);
13371337

13381338
#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+
*/
1346+
struct 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);
1355+
out:
1356+
mutex_unlock(&extcon_dev_list_lock);
1357+
1358+
return edev;
1359+
}
1360+
13391361
/*
13401362
* extcon_get_edev_by_phandle - Get the extcon device from devicetree.
13411363
* @dev : the instance to the given device
@@ -1363,25 +1385,27 @@ struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index)
13631385
return ERR_PTR(-ENODEV);
13641386
}
13651387

1366-
mutex_lock(&extcon_dev_list_lock);
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);
1388+
edev = extcon_find_edev_by_node(node);
13751389
of_node_put(node);
13761390

1377-
return ERR_PTR(-EPROBE_DEFER);
1391+
return edev;
13781392
}
1393+
13791394
#else
1395+
1396+
struct extcon_dev *extcon_find_edev_by_node(struct device_node *node)
1397+
{
1398+
return ERR_PTR(-ENOSYS);
1399+
}
1400+
13801401
struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index)
13811402
{
13821403
return ERR_PTR(-ENOSYS);
13831404
}
1405+
13841406
#endif /* CONFIG_OF */
1407+
1408+
EXPORT_SYMBOL_GPL(extcon_find_edev_by_node);
13851409
EXPORT_SYMBOL_GPL(extcon_get_edev_by_phandle);
13861410

13871411
/**

include/linux/extcon.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ extern void devm_extcon_unregister_notifier_all(struct device *dev,
230230
* Following APIs get the extcon_dev from devicetree or by through extcon name.
231231
*/
232232
extern struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name);
233+
extern struct extcon_dev *extcon_find_edev_by_node(struct device_node *node);
233234
extern struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev,
234235
int index);
235236

@@ -283,6 +284,11 @@ static inline struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name)
283284
return ERR_PTR(-ENODEV);
284285
}
285286

287+
static inline struct extcon_dev *extcon_find_edev_by_node(struct device_node *node)
288+
{
289+
return ERR_PTR(-ENODEV);
290+
}
291+
286292
static inline struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev,
287293
int index)
288294
{

0 commit comments

Comments
 (0)