aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/extcon/extcon-class.c
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-09-26 23:47:25 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-09-26 23:47:25 -0400
commit2424a7339bdc5468b8a6b3bddd750647e45b314d (patch)
treeec1e5df7df1a3d54d6cb4952914955b301eaab82 /drivers/extcon/extcon-class.c
parent33b06938cf81939135448ed448ee5aa95fa86d04 (diff)
parent42d7d7539a7bcf1d493b989465283c464f4a0525 (diff)
Merge tag 'extcon-next-for-3.13' of git://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/extcon into char-misc-next
Chanwoo writes: Update extcon for 3.13 This patchset modify extcon core to remove unnecessary allocation sequence for 'dev' instance and change extcon_dev_register() interface. extcon-gpio use gpiolib API to get debounce time and include small fix of extcon core/device driver. Detailed description for patchset: 1. Modify extcon core driver - The extcon-gpio driver use gpio_set_debounce() API provided from gpiolib if gpio driver for SoC support gpio_set_debounce() function and support 'gpio_ activ_low' filed to check whether gpio active state is 1(high) or 0(low). - Change field type of 'dev' in structure extcon_dev and remove the sequence of allocating memory of 'struct dev' on extcon_dev_register() function because extcon device must need 'struct device. - Change extcon_dev_register() prototype to simplify it and remove unnecessary parameter as below: 2. Fix coding style and typo - extcon core : Fix indentation coding style and remove unnecessary casting - extcon-max8997 : Fix checkpatch warning - extcon-max77693 : Fix checkpatch warning - extcon-arizona : Fix typo of comment and modify minor issue - extcon-palmas : Use dev_get_platdata() 3. Modify extcon-arizona driver - Modify minor issue about micbias and comparision statement
Diffstat (limited to 'drivers/extcon/extcon-class.c')
-rw-r--r--drivers/extcon/extcon-class.c95
1 files changed, 46 insertions, 49 deletions
diff --git a/drivers/extcon/extcon-class.c b/drivers/extcon/extcon-class.c
index b6a3d379fe9a..15443d3b6be1 100644
--- a/drivers/extcon/extcon-class.c
+++ b/drivers/extcon/extcon-class.c
@@ -74,7 +74,7 @@ static DEFINE_MUTEX(extcon_dev_list_lock);
74 74
75/** 75/**
76 * check_mutually_exclusive - Check if new_state violates mutually_exclusive 76 * check_mutually_exclusive - Check if new_state violates mutually_exclusive
77 * condition. 77 * condition.
78 * @edev: the extcon device 78 * @edev: the extcon device
79 * @new_state: new cable attach status for @edev 79 * @new_state: new cable attach status for @edev
80 * 80 *
@@ -105,7 +105,7 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr,
105 char *buf) 105 char *buf)
106{ 106{
107 int i, count = 0; 107 int i, count = 0;
108 struct extcon_dev *edev = (struct extcon_dev *) dev_get_drvdata(dev); 108 struct extcon_dev *edev = dev_get_drvdata(dev);
109 109
110 if (edev->print_state) { 110 if (edev->print_state) {
111 int ret = edev->print_state(edev, buf); 111 int ret = edev->print_state(edev, buf);
@@ -134,7 +134,7 @@ static ssize_t state_store(struct device *dev, struct device_attribute *attr,
134{ 134{
135 u32 state; 135 u32 state;
136 ssize_t ret = 0; 136 ssize_t ret = 0;
137 struct extcon_dev *edev = (struct extcon_dev *) dev_get_drvdata(dev); 137 struct extcon_dev *edev = dev_get_drvdata(dev);
138 138
139 ret = sscanf(buf, "0x%x", &state); 139 ret = sscanf(buf, "0x%x", &state);
140 if (ret == 0) 140 if (ret == 0)
@@ -152,7 +152,7 @@ static DEVICE_ATTR_RW(state);
152static ssize_t name_show(struct device *dev, struct device_attribute *attr, 152static ssize_t name_show(struct device *dev, struct device_attribute *attr,
153 char *buf) 153 char *buf)
154{ 154{
155 struct extcon_dev *edev = (struct extcon_dev *) dev_get_drvdata(dev); 155 struct extcon_dev *edev = dev_get_drvdata(dev);
156 156
157 /* Optional callback given by the user */ 157 /* Optional callback given by the user */
158 if (edev->print_name) { 158 if (edev->print_name) {
@@ -161,7 +161,7 @@ static ssize_t name_show(struct device *dev, struct device_attribute *attr,
161 return ret; 161 return ret;
162 } 162 }
163 163
164 return sprintf(buf, "%s\n", dev_name(edev->dev)); 164 return sprintf(buf, "%s\n", dev_name(&edev->dev));
165} 165}
166static DEVICE_ATTR_RO(name); 166static DEVICE_ATTR_RO(name);
167 167
@@ -188,7 +188,7 @@ static ssize_t cable_state_show(struct device *dev,
188 188
189/** 189/**
190 * extcon_update_state() - Update the cable attach states of the extcon device 190 * extcon_update_state() - Update the cable attach states of the extcon device
191 * only for the masked bits. 191 * only for the masked bits.
192 * @edev: the extcon device 192 * @edev: the extcon device
193 * @mask: the bit mask to designate updated bits. 193 * @mask: the bit mask to designate updated bits.
194 * @state: new cable attach status for @edev 194 * @state: new cable attach status for @edev
@@ -226,11 +226,10 @@ int extcon_update_state(struct extcon_dev *edev, u32 mask, u32 state)
226 edev->state |= state & mask; 226 edev->state |= state & mask;
227 227
228 raw_notifier_call_chain(&edev->nh, old_state, edev); 228 raw_notifier_call_chain(&edev->nh, old_state, edev);
229
230 /* This could be in interrupt handler */ 229 /* This could be in interrupt handler */
231 prop_buf = (char *)get_zeroed_page(GFP_ATOMIC); 230 prop_buf = (char *)get_zeroed_page(GFP_ATOMIC);
232 if (prop_buf) { 231 if (prop_buf) {
233 length = name_show(edev->dev, NULL, prop_buf); 232 length = name_show(&edev->dev, NULL, prop_buf);
234 if (length > 0) { 233 if (length > 0) {
235 if (prop_buf[length - 1] == '\n') 234 if (prop_buf[length - 1] == '\n')
236 prop_buf[length - 1] = 0; 235 prop_buf[length - 1] = 0;
@@ -238,7 +237,7 @@ int extcon_update_state(struct extcon_dev *edev, u32 mask, u32 state)
238 "NAME=%s", prop_buf); 237 "NAME=%s", prop_buf);
239 envp[env_offset++] = name_buf; 238 envp[env_offset++] = name_buf;
240 } 239 }
241 length = state_show(edev->dev, NULL, prop_buf); 240 length = state_show(&edev->dev, NULL, prop_buf);
242 if (length > 0) { 241 if (length > 0) {
243 if (prop_buf[length - 1] == '\n') 242 if (prop_buf[length - 1] == '\n')
244 prop_buf[length - 1] = 0; 243 prop_buf[length - 1] = 0;
@@ -250,14 +249,14 @@ int extcon_update_state(struct extcon_dev *edev, u32 mask, u32 state)
250 /* Unlock early before uevent */ 249 /* Unlock early before uevent */
251 spin_unlock_irqrestore(&edev->lock, flags); 250 spin_unlock_irqrestore(&edev->lock, flags);
252 251
253 kobject_uevent_env(&edev->dev->kobj, KOBJ_CHANGE, envp); 252 kobject_uevent_env(&edev->dev.kobj, KOBJ_CHANGE, envp);
254 free_page((unsigned long)prop_buf); 253 free_page((unsigned long)prop_buf);
255 } else { 254 } else {
256 /* Unlock early before uevent */ 255 /* Unlock early before uevent */
257 spin_unlock_irqrestore(&edev->lock, flags); 256 spin_unlock_irqrestore(&edev->lock, flags);
258 257
259 dev_err(edev->dev, "out of memory in extcon_set_state\n"); 258 dev_err(&edev->dev, "out of memory in extcon_set_state\n");
260 kobject_uevent(&edev->dev->kobj, KOBJ_CHANGE); 259 kobject_uevent(&edev->dev.kobj, KOBJ_CHANGE);
261 } 260 }
262 } else { 261 } else {
263 /* No changes */ 262 /* No changes */
@@ -338,8 +337,9 @@ EXPORT_SYMBOL_GPL(extcon_get_cable_state);
338 337
339/** 338/**
340 * extcon_set_cable_state_() - Set the status of a specific cable. 339 * extcon_set_cable_state_() - Set the status of a specific cable.
341 * @edev: the extcon device that has the cable. 340 * @edev: the extcon device that has the cable.
342 * @index: cable index that can be retrieved by extcon_find_cable_index(). 341 * @index: cable index that can be retrieved by
342 * extcon_find_cable_index().
343 * @cable_state: the new cable status. The default semantics is 343 * @cable_state: the new cable status. The default semantics is
344 * true: attached / false: detached. 344 * true: attached / false: detached.
345 */ 345 */
@@ -358,8 +358,8 @@ EXPORT_SYMBOL_GPL(extcon_set_cable_state_);
358 358
359/** 359/**
360 * extcon_set_cable_state() - Set the status of a specific cable. 360 * extcon_set_cable_state() - Set the status of a specific cable.
361 * @edev: the extcon device that has the cable. 361 * @edev: the extcon device that has the cable.
362 * @cable_name: cable name. 362 * @cable_name: cable name.
363 * @cable_state: the new cable status. The default semantics is 363 * @cable_state: the new cable status. The default semantics is
364 * true: attached / false: detached. 364 * true: attached / false: detached.
365 * 365 *
@@ -418,14 +418,14 @@ static int _call_per_cable(struct notifier_block *nb, unsigned long val,
418 418
419/** 419/**
420 * extcon_register_interest() - Register a notifier for a state change of a 420 * extcon_register_interest() - Register a notifier for a state change of a
421 * specific cable, not an entier set of cables of a 421 * specific cable, not an entier set of cables of a
422 * extcon device. 422 * extcon device.
423 * @obj: an empty extcon_specific_cable_nb object to be returned. 423 * @obj: an empty extcon_specific_cable_nb object to be returned.
424 * @extcon_name: the name of extcon device. 424 * @extcon_name: the name of extcon device.
425 * if NULL, extcon_register_interest will register 425 * if NULL, extcon_register_interest will register
426 * every cable with the target cable_name given. 426 * every cable with the target cable_name given.
427 * @cable_name: the target cable name. 427 * @cable_name: the target cable name.
428 * @nb: the notifier block to get notified. 428 * @nb: the notifier block to get notified.
429 * 429 *
430 * Provide an empty extcon_specific_cable_nb. extcon_register_interest() sets 430 * Provide an empty extcon_specific_cable_nb. extcon_register_interest() sets
431 * the struct for you. 431 * the struct for you.
@@ -471,7 +471,7 @@ int extcon_register_interest(struct extcon_specific_cable_nb *obj,
471 return -ENODEV; 471 return -ENODEV;
472 class_dev_iter_init(&iter, extcon_class, NULL, NULL); 472 class_dev_iter_init(&iter, extcon_class, NULL, NULL);
473 while ((dev = class_dev_iter_next(&iter))) { 473 while ((dev = class_dev_iter_next(&iter))) {
474 extd = (struct extcon_dev *)dev_get_drvdata(dev); 474 extd = dev_get_drvdata(dev);
475 475
476 if (extcon_find_cable_index(extd, cable_name) < 0) 476 if (extcon_find_cable_index(extd, cable_name) < 0)
477 continue; 477 continue;
@@ -488,7 +488,7 @@ EXPORT_SYMBOL_GPL(extcon_register_interest);
488 488
489/** 489/**
490 * extcon_unregister_interest() - Unregister the notifier registered by 490 * extcon_unregister_interest() - Unregister the notifier registered by
491 * extcon_register_interest(). 491 * extcon_register_interest().
492 * @obj: the extcon_specific_cable_nb object returned by 492 * @obj: the extcon_specific_cable_nb object returned by
493 * extcon_register_interest(). 493 * extcon_register_interest().
494 */ 494 */
@@ -503,7 +503,7 @@ EXPORT_SYMBOL_GPL(extcon_unregister_interest);
503 503
504/** 504/**
505 * extcon_register_notifier() - Register a notifiee to get notified by 505 * extcon_register_notifier() - Register a notifiee to get notified by
506 * any attach status changes from the extcon. 506 * any attach status changes from the extcon.
507 * @edev: the extcon device. 507 * @edev: the extcon device.
508 * @nb: a notifier block to be registered. 508 * @nb: a notifier block to be registered.
509 * 509 *
@@ -557,7 +557,6 @@ static int create_extcon_class(void)
557 557
558static void extcon_dev_release(struct device *dev) 558static void extcon_dev_release(struct device *dev)
559{ 559{
560 kfree(dev);
561} 560}
562 561
563static const char *muex_name = "mutually_exclusive"; 562static const char *muex_name = "mutually_exclusive";
@@ -568,14 +567,13 @@ static void dummy_sysfs_dev_release(struct device *dev)
568/** 567/**
569 * extcon_dev_register() - Register a new extcon device 568 * extcon_dev_register() - Register a new extcon device
570 * @edev : the new extcon device (should be allocated before calling) 569 * @edev : the new extcon device (should be allocated before calling)
571 * @dev : the parent device for this extcon device.
572 * 570 *
573 * Among the members of edev struct, please set the "user initializing data" 571 * Among the members of edev struct, please set the "user initializing data"
574 * in any case and set the "optional callbacks" if required. However, please 572 * in any case and set the "optional callbacks" if required. However, please
575 * do not set the values of "internal data", which are initialized by 573 * do not set the values of "internal data", which are initialized by
576 * this function. 574 * this function.
577 */ 575 */
578int extcon_dev_register(struct extcon_dev *edev, struct device *dev) 576int extcon_dev_register(struct extcon_dev *edev)
579{ 577{
580 int ret, index = 0; 578 int ret, index = 0;
581 579
@@ -595,19 +593,20 @@ int extcon_dev_register(struct extcon_dev *edev, struct device *dev)
595 } 593 }
596 594
597 if (index > SUPPORTED_CABLE_MAX) { 595 if (index > SUPPORTED_CABLE_MAX) {
598 dev_err(edev->dev, "extcon: maximum number of supported cables exceeded.\n"); 596 dev_err(&edev->dev, "extcon: maximum number of supported cables exceeded.\n");
599 return -EINVAL; 597 return -EINVAL;
600 } 598 }
601 599
602 edev->dev = kzalloc(sizeof(struct device), GFP_KERNEL); 600 edev->dev.class = extcon_class;
603 if (!edev->dev) 601 edev->dev.release = extcon_dev_release;
604 return -ENOMEM;
605 edev->dev->parent = dev;
606 edev->dev->class = extcon_class;
607 edev->dev->release = extcon_dev_release;
608 602
609 edev->name = edev->name ? edev->name : dev_name(dev); 603 edev->name = edev->name ? edev->name : dev_name(edev->dev.parent);
610 dev_set_name(edev->dev, "%s", edev->name); 604 if (IS_ERR_OR_NULL(edev->name)) {
605 dev_err(&edev->dev,
606 "extcon device name is null\n");
607 return -EINVAL;
608 }
609 dev_set_name(&edev->dev, "%s", edev->name);
611 610
612 if (edev->max_supported) { 611 if (edev->max_supported) {
613 char buf[10]; 612 char buf[10];
@@ -715,7 +714,7 @@ int extcon_dev_register(struct extcon_dev *edev, struct device *dev)
715 goto err_alloc_groups; 714 goto err_alloc_groups;
716 } 715 }
717 716
718 edev->extcon_dev_type.name = dev_name(edev->dev); 717 edev->extcon_dev_type.name = dev_name(&edev->dev);
719 edev->extcon_dev_type.release = dummy_sysfs_dev_release; 718 edev->extcon_dev_type.release = dummy_sysfs_dev_release;
720 719
721 for (index = 0; index < edev->max_supported; index++) 720 for (index = 0; index < edev->max_supported; index++)
@@ -725,25 +724,24 @@ int extcon_dev_register(struct extcon_dev *edev, struct device *dev)
725 edev->extcon_dev_type.groups[index] = 724 edev->extcon_dev_type.groups[index] =
726 &edev->attr_g_muex; 725 &edev->attr_g_muex;
727 726
728 edev->dev->type = &edev->extcon_dev_type; 727 edev->dev.type = &edev->extcon_dev_type;
729 } 728 }
730 729
731 ret = device_register(edev->dev); 730 ret = device_register(&edev->dev);
732 if (ret) { 731 if (ret) {
733 put_device(edev->dev); 732 put_device(&edev->dev);
734 goto err_dev; 733 goto err_dev;
735 } 734 }
736#if defined(CONFIG_ANDROID) 735#if defined(CONFIG_ANDROID)
737 if (switch_class) 736 if (switch_class)
738 ret = class_compat_create_link(switch_class, edev->dev, 737 ret = class_compat_create_link(switch_class, &edev->dev, NULL);
739 NULL);
740#endif /* CONFIG_ANDROID */ 738#endif /* CONFIG_ANDROID */
741 739
742 spin_lock_init(&edev->lock); 740 spin_lock_init(&edev->lock);
743 741
744 RAW_INIT_NOTIFIER_HEAD(&edev->nh); 742 RAW_INIT_NOTIFIER_HEAD(&edev->nh);
745 743
746 dev_set_drvdata(edev->dev, edev); 744 dev_set_drvdata(&edev->dev, edev);
747 edev->state = 0; 745 edev->state = 0;
748 746
749 mutex_lock(&extcon_dev_list_lock); 747 mutex_lock(&extcon_dev_list_lock);
@@ -769,7 +767,6 @@ err_alloc_cables:
769 if (edev->max_supported) 767 if (edev->max_supported)
770 kfree(edev->cables); 768 kfree(edev->cables);
771err_sysfs_alloc: 769err_sysfs_alloc:
772 kfree(edev->dev);
773 return ret; 770 return ret;
774} 771}
775EXPORT_SYMBOL_GPL(extcon_dev_register); 772EXPORT_SYMBOL_GPL(extcon_dev_register);
@@ -789,9 +786,9 @@ void extcon_dev_unregister(struct extcon_dev *edev)
789 list_del(&edev->entry); 786 list_del(&edev->entry);
790 mutex_unlock(&extcon_dev_list_lock); 787 mutex_unlock(&extcon_dev_list_lock);
791 788
792 if (IS_ERR_OR_NULL(get_device(edev->dev))) { 789 if (IS_ERR_OR_NULL(get_device(&edev->dev))) {
793 dev_err(edev->dev, "Failed to unregister extcon_dev (%s)\n", 790 dev_err(&edev->dev, "Failed to unregister extcon_dev (%s)\n",
794 dev_name(edev->dev)); 791 dev_name(&edev->dev));
795 return; 792 return;
796 } 793 }
797 794
@@ -813,10 +810,10 @@ void extcon_dev_unregister(struct extcon_dev *edev)
813 810
814#if defined(CONFIG_ANDROID) 811#if defined(CONFIG_ANDROID)
815 if (switch_class) 812 if (switch_class)
816 class_compat_remove_link(switch_class, edev->dev, NULL); 813 class_compat_remove_link(switch_class, &edev->dev, NULL);
817#endif 814#endif
818 device_unregister(edev->dev); 815 device_unregister(&edev->dev);
819 put_device(edev->dev); 816 put_device(&edev->dev);
820} 817}
821EXPORT_SYMBOL_GPL(extcon_dev_unregister); 818EXPORT_SYMBOL_GPL(extcon_dev_unregister);
822 819