Kishon Vijay Abraham I | 6eee5b3 | 2013-06-11 20:48:02 +0900 | [diff] [blame] | 1 | /* |
| 2 | * OF helpers for External connector (extcon) framework |
| 3 | * |
| 4 | * Copyright (C) 2013 Texas Instruments, Inc. |
| 5 | * Kishon Vijay Abraham I <kishon@ti.com> |
| 6 | * |
| 7 | * Copyright (C) 2013 Samsung Electronics |
| 8 | * Chanwoo Choi <cw00.choi@samsung.com> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | */ |
| 15 | |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/slab.h> |
| 18 | #include <linux/err.h> |
| 19 | #include <linux/extcon.h> |
| 20 | #include <linux/of.h> |
| 21 | #include <linux/of_platform.h> |
| 22 | #include <linux/extcon/of_extcon.h> |
| 23 | |
| 24 | /* |
| 25 | * of_extcon_get_extcon_dev - Get the name of extcon device from devicetree |
| 26 | * @dev - instance to the given device |
| 27 | * @index - index into list of extcon_dev |
| 28 | * |
| 29 | * return the instance of extcon device |
| 30 | */ |
| 31 | struct extcon_dev *of_extcon_get_extcon_dev(struct device *dev, int index) |
| 32 | { |
| 33 | struct device_node *node; |
| 34 | struct extcon_dev *edev; |
Kishon Vijay Abraham I | 6eee5b3 | 2013-06-11 20:48:02 +0900 | [diff] [blame] | 35 | |
| 36 | if (!dev->of_node) { |
| 37 | dev_dbg(dev, "device does not have a device node entry\n"); |
| 38 | return ERR_PTR(-EINVAL); |
| 39 | } |
| 40 | |
| 41 | node = of_parse_phandle(dev->of_node, "extcon", index); |
| 42 | if (!node) { |
| 43 | dev_dbg(dev, "failed to get phandle in %s node\n", |
| 44 | dev->of_node->full_name); |
| 45 | return ERR_PTR(-ENODEV); |
| 46 | } |
| 47 | |
Chanwoo Choi | ca48824 | 2014-03-18 19:09:41 +0900 | [diff] [blame^] | 48 | edev = extcon_get_extcon_dev(node->name); |
Kishon Vijay Abraham I | 6eee5b3 | 2013-06-11 20:48:02 +0900 | [diff] [blame] | 49 | if (!edev) { |
Chanwoo Choi | ca48824 | 2014-03-18 19:09:41 +0900 | [diff] [blame^] | 50 | dev_dbg(dev, "unable to get extcon device : %s\n", node->name); |
Kishon Vijay Abraham I | 6eee5b3 | 2013-06-11 20:48:02 +0900 | [diff] [blame] | 51 | return ERR_PTR(-ENODEV); |
| 52 | } |
| 53 | |
| 54 | return edev; |
| 55 | } |
| 56 | EXPORT_SYMBOL_GPL(of_extcon_get_extcon_dev); |