aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/extcon
diff options
context:
space:
mode:
authorDonggeun Kim <dg77.kim@samsung.com>2012-04-20 01:16:24 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-04-20 12:23:09 -0400
commit74c5d09bd562edc220d6e076b8f1e118819c178f (patch)
tree65f35b6066fe135405797acc419b4bb6f346e4af /drivers/extcon
parentbe48308a24c7651bf968b561dbd590edb8166d62 (diff)
Extcon: support notification based on the state changes.
State changes of extcon devices have been notified via kobjet_uevent. This patch adds notifier interfaces in order to allow device drivers to get notified easily. Along with notifier interface, extcon_get_extcon_dev() function is added so that device drivers may discover a extcon_dev easily. Signed-off-by: Donggeun Kim <dg77.kim@samsung.com> Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com> Reviewed-by: Mark Brown <broonie@opensource.wolfsonmicro.com> -- Changes from RFC - Renamed switch to extcon - Bugfix: extcon_dev_unregister() - Bugfix: "edev->dev" is "internal" data. - Added kerneldoc comments. - Reworded comments. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/extcon')
-rw-r--r--drivers/extcon/extcon_class.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/drivers/extcon/extcon_class.c b/drivers/extcon/extcon_class.c
index 3c46368c279a..83a088f1edc4 100644
--- a/drivers/extcon/extcon_class.c
+++ b/drivers/extcon/extcon_class.c
@@ -36,6 +36,9 @@ struct class *extcon_class;
36static struct class_compat *switch_class; 36static struct class_compat *switch_class;
37#endif /* CONFIG_ANDROID && !defined(CONFIG_ANDROID_SWITCH) */ 37#endif /* CONFIG_ANDROID && !defined(CONFIG_ANDROID_SWITCH) */
38 38
39static LIST_HEAD(extcon_dev_list);
40static DEFINE_MUTEX(extcon_dev_list_lock);
41
39static ssize_t state_show(struct device *dev, struct device_attribute *attr, 42static ssize_t state_show(struct device *dev, struct device_attribute *attr,
40 char *buf) 43 char *buf)
41{ 44{
@@ -75,6 +78,9 @@ static ssize_t name_show(struct device *dev, struct device_attribute *attr,
75 * the name of extcon device (envp[0]) and the state output (envp[1]). 78 * the name of extcon device (envp[0]) and the state output (envp[1]).
76 * Tizen uses this format for extcon device to get events from ports. 79 * Tizen uses this format for extcon device to get events from ports.
77 * Android uses this format as well. 80 * Android uses this format as well.
81 *
82 * Note that notifier provides the which bits are changes in the state
83 * variable with "val" to the callback.
78 */ 84 */
79void extcon_set_state(struct extcon_dev *edev, u32 state) 85void extcon_set_state(struct extcon_dev *edev, u32 state)
80{ 86{
@@ -84,10 +90,14 @@ void extcon_set_state(struct extcon_dev *edev, u32 state)
84 char *envp[3]; 90 char *envp[3];
85 int env_offset = 0; 91 int env_offset = 0;
86 int length; 92 int length;
93 u32 old_state = edev->state;
87 94
88 if (edev->state != state) { 95 if (edev->state != state) {
89 edev->state = state; 96 edev->state = state;
90 97
98 raw_notifier_call_chain(&edev->nh, old_state ^ edev->state,
99 edev);
100
91 prop_buf = (char *)get_zeroed_page(GFP_KERNEL); 101 prop_buf = (char *)get_zeroed_page(GFP_KERNEL);
92 if (prop_buf) { 102 if (prop_buf) {
93 length = name_show(edev->dev, NULL, prop_buf); 103 length = name_show(edev->dev, NULL, prop_buf);
@@ -117,6 +127,51 @@ void extcon_set_state(struct extcon_dev *edev, u32 state)
117} 127}
118EXPORT_SYMBOL_GPL(extcon_set_state); 128EXPORT_SYMBOL_GPL(extcon_set_state);
119 129
130/**
131 * extcon_get_extcon_dev() - Get the extcon device instance from the name
132 * @extcon_name: The extcon name provided with extcon_dev_register()
133 */
134struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name)
135{
136 struct extcon_dev *sd;
137
138 mutex_lock(&extcon_dev_list_lock);
139 list_for_each_entry(sd, &extcon_dev_list, entry) {
140 if (!strcmp(sd->name, extcon_name))
141 goto out;
142 }
143 sd = NULL;
144out:
145 mutex_unlock(&extcon_dev_list_lock);
146 return sd;
147}
148EXPORT_SYMBOL_GPL(extcon_get_extcon_dev);
149
150/**
151 * extcon_register_notifier() - Register a notifee to get notified by
152 * any attach status changes from the extcon.
153 * @edev: the extcon device.
154 * @nb: a notifier block to be registered.
155 */
156int extcon_register_notifier(struct extcon_dev *edev,
157 struct notifier_block *nb)
158{
159 return raw_notifier_chain_register(&edev->nh, nb);
160}
161EXPORT_SYMBOL_GPL(extcon_register_notifier);
162
163/**
164 * extcon_unregister_notifier() - Unregister a notifee from the extcon device.
165 * @edev: the extcon device.
166 * @nb: a registered notifier block to be unregistered.
167 */
168int extcon_unregister_notifier(struct extcon_dev *edev,
169 struct notifier_block *nb)
170{
171 return raw_notifier_chain_unregister(&edev->nh, nb);
172}
173EXPORT_SYMBOL_GPL(extcon_unregister_notifier);
174
120static struct device_attribute extcon_attrs[] = { 175static struct device_attribute extcon_attrs[] = {
121 __ATTR_RO(state), 176 __ATTR_RO(state),
122 __ATTR_RO(name), 177 __ATTR_RO(name),
@@ -142,6 +197,10 @@ static int create_extcon_class(void)
142 197
143static void extcon_cleanup(struct extcon_dev *edev, bool skip) 198static void extcon_cleanup(struct extcon_dev *edev, bool skip)
144{ 199{
200 mutex_lock(&extcon_dev_list_lock);
201 list_del(&edev->entry);
202 mutex_unlock(&extcon_dev_list_lock);
203
145 if (!skip && get_device(edev->dev)) { 204 if (!skip && get_device(edev->dev)) {
146 device_unregister(edev->dev); 205 device_unregister(edev->dev);
147 put_device(edev->dev); 206 put_device(edev->dev);
@@ -194,8 +253,15 @@ int extcon_dev_register(struct extcon_dev *edev, struct device *dev)
194 dev); 253 dev);
195#endif /* CONFIG_ANDROID && !defined(CONFIG_ANDROID_SWITCH) */ 254#endif /* CONFIG_ANDROID && !defined(CONFIG_ANDROID_SWITCH) */
196 255
256 RAW_INIT_NOTIFIER_HEAD(&edev->nh);
257
197 dev_set_drvdata(edev->dev, edev); 258 dev_set_drvdata(edev->dev, edev);
198 edev->state = 0; 259 edev->state = 0;
260
261 mutex_lock(&extcon_dev_list_lock);
262 list_add(&edev->entry, &extcon_dev_list);
263 mutex_unlock(&extcon_dev_list_lock);
264
199 return 0; 265 return 0;
200 266
201err_dev: 267err_dev: