Lines Matching +full:int +full:- +full:property

1 // SPDX-License-Identifier: GPL-2.0-only
3 * drivers/extcon/extcon.c - External Connector (extcon) framework.
33 unsigned int type;
34 unsigned int id;
53 .name = "USB-HOST",
80 .name = "FAST-CHARGER",
85 .name = "SLOW-CHARGER",
112 .name = "LINE-IN",
117 .name = "LINE-OUT",
122 .name = "VIDEO-IN",
127 .name = "VIDEO-OUT",
132 .name = "SPDIF-IN",
137 .name = "SPDIF-OUT",
203 * struct extcon_cable - An internal data for an external connector.
214 * @usb_bits: the bit array of the USB connector property capabilities
215 * @chg_bits: the bit array of the charger connector property capabilities
216 * @jack_bits: the bit array of the jack connector property capabilities
217 * @disp_bits: the bit array of the display connector property capabilities
221 int cable_index;
246 static int check_mutually_exclusive(struct extcon_dev *edev, u32 new_state) in check_mutually_exclusive()
248 int i; in check_mutually_exclusive()
250 if (!edev->mutually_exclusive) in check_mutually_exclusive()
253 for (i = 0; edev->mutually_exclusive[i]; i++) { in check_mutually_exclusive()
254 int weight; in check_mutually_exclusive()
255 u32 correspondants = new_state & edev->mutually_exclusive[i]; in check_mutually_exclusive()
266 static int find_cable_index_by_id(struct extcon_dev *edev, const unsigned int id) in find_cable_index_by_id()
268 int i; in find_cable_index_by_id()
270 /* Find the index of extcon cable in edev->supported_cable */ in find_cable_index_by_id()
271 for (i = 0; i < edev->max_supported; i++) { in find_cable_index_by_id()
272 if (edev->supported_cable[i] == id) in find_cable_index_by_id()
276 return -EINVAL; in find_cable_index_by_id()
279 static int get_extcon_type(unsigned int prop) in get_extcon_type()
291 return -EINVAL; in get_extcon_type()
295 static bool is_extcon_attached(struct extcon_dev *edev, unsigned int index) in is_extcon_attached()
297 return !!(edev->state & BIT(index)); in is_extcon_attached()
300 static bool is_extcon_changed(struct extcon_dev *edev, int index, in is_extcon_changed()
303 int state = !!(edev->state & BIT(index)); in is_extcon_changed()
307 static bool is_extcon_property_supported(unsigned int id, unsigned int prop) in is_extcon_property_supported()
309 int type; in is_extcon_property_supported()
311 /* Check whether the property is supported or not. */ in is_extcon_property_supported()
316 /* Check whether a specific extcon id supports the property or not. */ in is_extcon_property_supported()
320 static int is_extcon_property_capability(struct extcon_dev *edev, in is_extcon_property_capability()
321 unsigned int id, int index,unsigned int prop) in is_extcon_property_capability()
324 int type, ret; in is_extcon_property_capability()
326 /* Check whether the property is supported or not. */ in is_extcon_property_capability()
331 cable = &edev->cables[index]; in is_extcon_property_capability()
335 ret = test_bit(prop - EXTCON_PROP_USB_MIN, cable->usb_bits); in is_extcon_property_capability()
338 ret = test_bit(prop - EXTCON_PROP_CHG_MIN, cable->chg_bits); in is_extcon_property_capability()
341 ret = test_bit(prop - EXTCON_PROP_JACK_MIN, cable->jack_bits); in is_extcon_property_capability()
344 ret = test_bit(prop - EXTCON_PROP_DISP_MIN, cable->disp_bits); in is_extcon_property_capability()
347 ret = -EINVAL; in is_extcon_property_capability()
353 static void init_property(struct extcon_dev *edev, unsigned int id, int index) in init_property()
355 unsigned int type = extcon_info[id].type; in init_property()
356 struct extcon_cable *cable = &edev->cables[index]; in init_property()
359 memset(cable->usb_propval, 0, sizeof(cable->usb_propval)); in init_property()
361 memset(cable->chg_propval, 0, sizeof(cable->chg_propval)); in init_property()
363 memset(cable->jack_propval, 0, sizeof(cable->jack_propval)); in init_property()
365 memset(cable->disp_propval, 0, sizeof(cable->disp_propval)); in init_property()
371 int i, count = 0; in state_show()
374 if (edev->max_supported == 0) in state_show()
375 return sysfs_emit(buf, "%u\n", edev->state); in state_show()
377 for (i = 0; i < edev->max_supported; i++) { in state_show()
379 extcon_info[edev->supported_cable[i]].name, in state_show()
380 !!(edev->state & BIT(i))); in state_show()
392 return sysfs_emit(buf, "%s\n", edev->name); in name_show()
401 int i = cable->cable_index; in cable_name_show()
404 extcon_info[cable->edev->supported_cable[i]].name); in cable_name_show()
413 int i = cable->cable_index; in cable_state_show()
416 extcon_get_state(cable->edev, cable->edev->supported_cable[i])); in cable_state_show()
420 * extcon_sync() - Synchronize the state for an external connector.
425 * the state and property of an external connector.
429 int extcon_sync(struct extcon_dev *edev, unsigned int id) in extcon_sync()
435 int env_offset = 0; in extcon_sync()
436 int length; in extcon_sync()
437 int index; in extcon_sync()
438 int state; in extcon_sync()
442 return -EINVAL; in extcon_sync()
448 spin_lock_irqsave(&edev->lock, flags); in extcon_sync()
449 state = !!(edev->state & BIT(index)); in extcon_sync()
450 spin_unlock_irqrestore(&edev->lock, flags); in extcon_sync()
456 raw_notifier_call_chain(&edev->nh[index], state, edev); in extcon_sync()
462 raw_notifier_call_chain(&edev->nh_all, state, edev); in extcon_sync()
464 spin_lock_irqsave(&edev->lock, flags); in extcon_sync()
469 spin_unlock_irqrestore(&edev->lock, flags); in extcon_sync()
471 dev_err(&edev->dev, "out of memory in extcon_set_state\n"); in extcon_sync()
472 kobject_uevent(&edev->dev.kobj, KOBJ_CHANGE); in extcon_sync()
474 return -ENOMEM; in extcon_sync()
477 length = name_show(&edev->dev, NULL, prop_buf); in extcon_sync()
479 if (prop_buf[length - 1] == '\n') in extcon_sync()
480 prop_buf[length - 1] = 0; in extcon_sync()
485 length = state_show(&edev->dev, NULL, prop_buf); in extcon_sync()
487 if (prop_buf[length - 1] == '\n') in extcon_sync()
488 prop_buf[length - 1] = 0; in extcon_sync()
495 spin_unlock_irqrestore(&edev->lock, flags); in extcon_sync()
496 kobject_uevent_env(&edev->dev.kobj, KOBJ_CHANGE, envp); in extcon_sync()
504 * extcon_get_state() - Get the state of an external connector.
510 int extcon_get_state(struct extcon_dev *edev, const unsigned int id) in extcon_get_state()
512 int index, state; in extcon_get_state()
516 return -EINVAL; in extcon_get_state()
522 spin_lock_irqsave(&edev->lock, flags); in extcon_get_state()
524 spin_unlock_irqrestore(&edev->lock, flags); in extcon_get_state()
531 * extcon_set_state() - Set the state of an external connector.
543 int extcon_set_state(struct extcon_dev *edev, unsigned int id, bool state) in extcon_set_state()
546 int index, ret = 0; in extcon_set_state()
549 return -EINVAL; in extcon_set_state()
555 spin_lock_irqsave(&edev->lock, flags); in extcon_set_state()
562 (edev->state & ~BIT(index)) | (state & BIT(index)))) { in extcon_set_state()
563 ret = -EPERM; in extcon_set_state()
568 * Initialize the value of extcon property before setting in extcon_set_state()
576 edev->state |= BIT(index); in extcon_set_state()
578 edev->state &= ~(BIT(index)); in extcon_set_state()
580 spin_unlock_irqrestore(&edev->lock, flags); in extcon_set_state()
587 * extcon_set_state_sync() - Set the state of an external connector with sync.
598 int extcon_set_state_sync(struct extcon_dev *edev, unsigned int id, bool state) in extcon_set_state_sync()
600 int ret; in extcon_set_state_sync()
611 * extcon_get_property() - Get the property value of an external connector.
614 * @prop: the property id indicating an extcon property
615 * @prop_val: the pointer which store the value of extcon property
617 * Note that when getting the property value of external connector,
619 * return 0 without property value. Also, the each property should be
624 int extcon_get_property(struct extcon_dev *edev, unsigned int id, in extcon_get_property()
625 unsigned int prop, in extcon_get_property()
630 int index, ret = 0; in extcon_get_property()
635 return -EINVAL; in extcon_get_property()
637 /* Check whether the property is supported or not */ in extcon_get_property()
639 return -EINVAL; in extcon_get_property()
646 spin_lock_irqsave(&edev->lock, flags); in extcon_get_property()
648 /* Check whether the property is available or not. */ in extcon_get_property()
650 spin_unlock_irqrestore(&edev->lock, flags); in extcon_get_property()
651 return -EPERM; in extcon_get_property()
657 * get the property value. in extcon_get_property()
660 spin_unlock_irqrestore(&edev->lock, flags); in extcon_get_property()
664 cable = &edev->cables[index]; in extcon_get_property()
666 /* Get the property value according to extcon type */ in extcon_get_property()
669 *prop_val = cable->usb_propval[prop - EXTCON_PROP_USB_MIN]; in extcon_get_property()
672 *prop_val = cable->chg_propval[prop - EXTCON_PROP_CHG_MIN]; in extcon_get_property()
675 *prop_val = cable->jack_propval[prop - EXTCON_PROP_JACK_MIN]; in extcon_get_property()
678 *prop_val = cable->disp_propval[prop - EXTCON_PROP_DISP_MIN]; in extcon_get_property()
681 ret = -EINVAL; in extcon_get_property()
685 spin_unlock_irqrestore(&edev->lock, flags); in extcon_get_property()
692 * extcon_set_property() - Set the property value of an external connector.
695 * @prop: the property id indicating an extcon property
696 * @prop_val: the pointer including the new value of extcon property
698 * Note that each property should be included in the list of supported
703 int extcon_set_property(struct extcon_dev *edev, unsigned int id, in extcon_set_property()
704 unsigned int prop, in extcon_set_property()
709 int index, ret = 0; in extcon_set_property()
712 return -EINVAL; in extcon_set_property()
714 /* Check whether the property is supported or not */ in extcon_set_property()
716 return -EINVAL; in extcon_set_property()
723 spin_lock_irqsave(&edev->lock, flags); in extcon_set_property()
725 /* Check whether the property is available or not. */ in extcon_set_property()
727 spin_unlock_irqrestore(&edev->lock, flags); in extcon_set_property()
728 return -EPERM; in extcon_set_property()
731 cable = &edev->cables[index]; in extcon_set_property()
733 /* Set the property value according to extcon type */ in extcon_set_property()
736 cable->usb_propval[prop - EXTCON_PROP_USB_MIN] = prop_val; in extcon_set_property()
739 cable->chg_propval[prop - EXTCON_PROP_CHG_MIN] = prop_val; in extcon_set_property()
742 cable->jack_propval[prop - EXTCON_PROP_JACK_MIN] = prop_val; in extcon_set_property()
745 cable->disp_propval[prop - EXTCON_PROP_DISP_MIN] = prop_val; in extcon_set_property()
748 ret = -EINVAL; in extcon_set_property()
752 spin_unlock_irqrestore(&edev->lock, flags); in extcon_set_property()
759 * extcon_set_property_sync() - Set property of an external connector with sync.
762 * @prop: the property id indicating an extcon property
763 * @prop_val: the pointer including the new value of extcon property
765 * Note that when setting the property value of external connector,
766 * the external connector should be attached. The each property should
771 int extcon_set_property_sync(struct extcon_dev *edev, unsigned int id, in extcon_set_property_sync()
772 unsigned int prop, in extcon_set_property_sync()
775 int ret; in extcon_set_property_sync()
786 * extcon_get_property_capability() - Get the capability of the property
790 * @prop: the property id indicating an extcon property
792 * Returns 1 if the property is available or 0 if not available.
794 int extcon_get_property_capability(struct extcon_dev *edev, unsigned int id, in extcon_get_property_capability()
795 unsigned int prop) in extcon_get_property_capability()
797 int index; in extcon_get_property_capability()
800 return -EINVAL; in extcon_get_property_capability()
802 /* Check whether the property is supported or not */ in extcon_get_property_capability()
804 return -EINVAL; in extcon_get_property_capability()
816 * extcon_set_property_capability() - Set the capability of the property
820 * @prop: the property id indicating an extcon property
822 * Note that this function set the capability of the property
824 * bitmap which mean the available state of the property.
828 int extcon_set_property_capability(struct extcon_dev *edev, unsigned int id, in extcon_set_property_capability()
829 unsigned int prop) in extcon_set_property_capability()
832 int index, type, ret = 0; in extcon_set_property_capability()
835 return -EINVAL; in extcon_set_property_capability()
837 /* Check whether the property is supported or not. */ in extcon_set_property_capability()
839 return -EINVAL; in extcon_set_property_capability()
850 cable = &edev->cables[index]; in extcon_set_property_capability()
854 __set_bit(prop - EXTCON_PROP_USB_MIN, cable->usb_bits); in extcon_set_property_capability()
857 __set_bit(prop - EXTCON_PROP_CHG_MIN, cable->chg_bits); in extcon_set_property_capability()
860 __set_bit(prop - EXTCON_PROP_JACK_MIN, cable->jack_bits); in extcon_set_property_capability()
863 __set_bit(prop - EXTCON_PROP_DISP_MIN, cable->disp_bits); in extcon_set_property_capability()
866 ret = -EINVAL; in extcon_set_property_capability()
874 * extcon_get_extcon_dev() - Get the extcon device instance from the name.
878 * NOTE: This function returns -EPROBE_DEFER so it may only be called from
886 return ERR_PTR(-EINVAL); in extcon_get_extcon_dev()
890 if (!strcmp(sd->name, extcon_name)) in extcon_get_extcon_dev()
893 sd = ERR_PTR(-EPROBE_DEFER); in extcon_get_extcon_dev()
901 * extcon_register_notifier() - Register a notifier block to get notified by
913 int extcon_register_notifier(struct extcon_dev *edev, unsigned int id, in extcon_register_notifier()
917 int ret, idx; in extcon_register_notifier()
920 return -EINVAL; in extcon_register_notifier()
926 spin_lock_irqsave(&edev->lock, flags); in extcon_register_notifier()
927 ret = raw_notifier_chain_register(&edev->nh[idx], nb); in extcon_register_notifier()
928 spin_unlock_irqrestore(&edev->lock, flags); in extcon_register_notifier()
935 * extcon_unregister_notifier() - Unregister a notifier block from the extcon.
942 int extcon_unregister_notifier(struct extcon_dev *edev, unsigned int id, in extcon_unregister_notifier()
946 int ret, idx; in extcon_unregister_notifier()
949 return -EINVAL; in extcon_unregister_notifier()
955 spin_lock_irqsave(&edev->lock, flags); in extcon_unregister_notifier()
956 ret = raw_notifier_chain_unregister(&edev->nh[idx], nb); in extcon_unregister_notifier()
957 spin_unlock_irqrestore(&edev->lock, flags); in extcon_unregister_notifier()
964 * extcon_register_notifier_all() - Register a notifier block for all connectors.
975 int extcon_register_notifier_all(struct extcon_dev *edev, in extcon_register_notifier_all()
979 int ret; in extcon_register_notifier_all()
982 return -EINVAL; in extcon_register_notifier_all()
984 spin_lock_irqsave(&edev->lock, flags); in extcon_register_notifier_all()
985 ret = raw_notifier_chain_register(&edev->nh_all, nb); in extcon_register_notifier_all()
986 spin_unlock_irqrestore(&edev->lock, flags); in extcon_register_notifier_all()
993 * extcon_unregister_notifier_all() - Unregister a notifier block from extcon.
999 int extcon_unregister_notifier_all(struct extcon_dev *edev, in extcon_unregister_notifier_all()
1003 int ret; in extcon_unregister_notifier_all()
1006 return -EINVAL; in extcon_unregister_notifier_all()
1008 spin_lock_irqsave(&edev->lock, flags); in extcon_unregister_notifier_all()
1009 ret = raw_notifier_chain_unregister(&edev->nh_all, nb); in extcon_unregister_notifier_all()
1010 spin_unlock_irqrestore(&edev->lock, flags); in extcon_unregister_notifier_all()
1023 static int create_extcon_class(void) in create_extcon_class()
1031 extcon_class->dev_groups = extcon_groups; in create_extcon_class()
1046 * extcon_dev_allocate() - Allocate the memory of extcon device.
1056 struct extcon_dev *extcon_dev_allocate(const unsigned int *supported_cable) in extcon_dev_allocate()
1061 return ERR_PTR(-EINVAL); in extcon_dev_allocate()
1065 return ERR_PTR(-ENOMEM); in extcon_dev_allocate()
1067 edev->max_supported = 0; in extcon_dev_allocate()
1068 edev->supported_cable = supported_cable; in extcon_dev_allocate()
1074 * extcon_dev_free() - Free the memory of extcon device.
1084 * extcon_alloc_cables() - alloc the cables for extcon device
1089 static int extcon_alloc_cables(struct extcon_dev *edev) in extcon_alloc_cables()
1091 int index; in extcon_alloc_cables()
1096 return -EINVAL; in extcon_alloc_cables()
1098 if (!edev->max_supported) in extcon_alloc_cables()
1101 edev->cables = kcalloc(edev->max_supported, sizeof(*edev->cables), in extcon_alloc_cables()
1103 if (!edev->cables) in extcon_alloc_cables()
1104 return -ENOMEM; in extcon_alloc_cables()
1106 for (index = 0; index < edev->max_supported; index++) { in extcon_alloc_cables()
1107 cable = &edev->cables[index]; in extcon_alloc_cables()
1111 for (index--; index >= 0; index--) { in extcon_alloc_cables()
1112 cable = &edev->cables[index]; in extcon_alloc_cables()
1113 kfree(cable->attr_g.name); in extcon_alloc_cables()
1116 kfree(edev->cables); in extcon_alloc_cables()
1117 return -ENOMEM; in extcon_alloc_cables()
1120 cable->edev = edev; in extcon_alloc_cables()
1121 cable->cable_index = index; in extcon_alloc_cables()
1122 cable->attrs[0] = &cable->attr_name.attr; in extcon_alloc_cables()
1123 cable->attrs[1] = &cable->attr_state.attr; in extcon_alloc_cables()
1124 cable->attrs[2] = NULL; in extcon_alloc_cables()
1125 cable->attr_g.name = str; in extcon_alloc_cables()
1126 cable->attr_g.attrs = cable->attrs; in extcon_alloc_cables()
1128 sysfs_attr_init(&cable->attr_name.attr); in extcon_alloc_cables()
1129 cable->attr_name.attr.name = "name"; in extcon_alloc_cables()
1130 cable->attr_name.attr.mode = 0444; in extcon_alloc_cables()
1131 cable->attr_name.show = cable_name_show; in extcon_alloc_cables()
1133 sysfs_attr_init(&cable->attr_state.attr); in extcon_alloc_cables()
1134 cable->attr_state.attr.name = "state"; in extcon_alloc_cables()
1135 cable->attr_state.attr.mode = 0444; in extcon_alloc_cables()
1136 cable->attr_state.show = cable_state_show; in extcon_alloc_cables()
1143 * extcon_alloc_muex() - alloc the mutual exclusive for extcon device
1148 static int extcon_alloc_muex(struct extcon_dev *edev) in extcon_alloc_muex()
1151 int index; in extcon_alloc_muex()
1154 return -EINVAL; in extcon_alloc_muex()
1156 if (!(edev->max_supported && edev->mutually_exclusive)) in extcon_alloc_muex()
1160 for (index = 0; edev->mutually_exclusive[index]; index++) in extcon_alloc_muex()
1163 edev->attrs_muex = kcalloc(index + 1, sizeof(*edev->attrs_muex), in extcon_alloc_muex()
1165 if (!edev->attrs_muex) in extcon_alloc_muex()
1166 return -ENOMEM; in extcon_alloc_muex()
1168 edev->d_attrs_muex = kcalloc(index, sizeof(*edev->d_attrs_muex), in extcon_alloc_muex()
1170 if (!edev->d_attrs_muex) { in extcon_alloc_muex()
1171 kfree(edev->attrs_muex); in extcon_alloc_muex()
1172 return -ENOMEM; in extcon_alloc_muex()
1175 for (index = 0; edev->mutually_exclusive[index]; index++) { in extcon_alloc_muex()
1177 edev->mutually_exclusive[index]); in extcon_alloc_muex()
1179 for (index--; index >= 0; index--) in extcon_alloc_muex()
1180 kfree(edev->d_attrs_muex[index].attr.name); in extcon_alloc_muex()
1182 kfree(edev->d_attrs_muex); in extcon_alloc_muex()
1183 kfree(edev->attrs_muex); in extcon_alloc_muex()
1184 return -ENOMEM; in extcon_alloc_muex()
1186 sysfs_attr_init(&edev->d_attrs_muex[index].attr); in extcon_alloc_muex()
1187 edev->d_attrs_muex[index].attr.name = name; in extcon_alloc_muex()
1188 edev->d_attrs_muex[index].attr.mode = 0000; in extcon_alloc_muex()
1189 edev->attrs_muex[index] = &edev->d_attrs_muex[index].attr; in extcon_alloc_muex()
1191 edev->attr_g_muex.name = muex_name; in extcon_alloc_muex()
1192 edev->attr_g_muex.attrs = edev->attrs_muex; in extcon_alloc_muex()
1198 * extcon_alloc_groups() - alloc the groups for extcon device
1203 static int extcon_alloc_groups(struct extcon_dev *edev) in extcon_alloc_groups()
1205 int index; in extcon_alloc_groups()
1208 return -EINVAL; in extcon_alloc_groups()
1210 if (!edev->max_supported) in extcon_alloc_groups()
1213 edev->extcon_dev_type.groups = kcalloc(edev->max_supported + 2, in extcon_alloc_groups()
1214 sizeof(*edev->extcon_dev_type.groups), in extcon_alloc_groups()
1216 if (!edev->extcon_dev_type.groups) in extcon_alloc_groups()
1217 return -ENOMEM; in extcon_alloc_groups()
1219 edev->extcon_dev_type.name = dev_name(&edev->dev); in extcon_alloc_groups()
1220 edev->extcon_dev_type.release = dummy_sysfs_dev_release; in extcon_alloc_groups()
1222 for (index = 0; index < edev->max_supported; index++) in extcon_alloc_groups()
1223 edev->extcon_dev_type.groups[index] = &edev->cables[index].attr_g; in extcon_alloc_groups()
1225 if (edev->mutually_exclusive) in extcon_alloc_groups()
1226 edev->extcon_dev_type.groups[index] = &edev->attr_g_muex; in extcon_alloc_groups()
1228 edev->dev.type = &edev->extcon_dev_type; in extcon_alloc_groups()
1234 * extcon_dev_register() - Register an new extcon device
1247 int extcon_dev_register(struct extcon_dev *edev) in extcon_dev_register()
1249 int ret, index; in extcon_dev_register()
1255 if (!edev || !edev->supported_cable) in extcon_dev_register()
1256 return -EINVAL; in extcon_dev_register()
1258 for (index = 0; edev->supported_cable[index] != EXTCON_NONE; index++); in extcon_dev_register()
1260 edev->max_supported = index; in extcon_dev_register()
1262 dev_err(&edev->dev, in extcon_dev_register()
1264 return -EINVAL; in extcon_dev_register()
1267 edev->dev.class = extcon_class; in extcon_dev_register()
1268 edev->dev.release = extcon_dev_release; in extcon_dev_register()
1270 edev->name = dev_name(edev->dev.parent); in extcon_dev_register()
1271 if (IS_ERR_OR_NULL(edev->name)) { in extcon_dev_register()
1272 dev_err(&edev->dev, in extcon_dev_register()
1274 return -EINVAL; in extcon_dev_register()
1281 edev->id = ret; in extcon_dev_register()
1295 spin_lock_init(&edev->lock); in extcon_dev_register()
1296 if (edev->max_supported) { in extcon_dev_register()
1297 edev->nh = kcalloc(edev->max_supported, sizeof(*edev->nh), in extcon_dev_register()
1299 if (!edev->nh) { in extcon_dev_register()
1300 ret = -ENOMEM; in extcon_dev_register()
1305 for (index = 0; index < edev->max_supported; index++) in extcon_dev_register()
1306 RAW_INIT_NOTIFIER_HEAD(&edev->nh[index]); in extcon_dev_register()
1308 RAW_INIT_NOTIFIER_HEAD(&edev->nh_all); in extcon_dev_register()
1310 dev_set_drvdata(&edev->dev, edev); in extcon_dev_register()
1311 dev_set_name(&edev->dev, "extcon%d", edev->id); in extcon_dev_register()
1312 edev->state = 0; in extcon_dev_register()
1314 ret = device_register(&edev->dev); in extcon_dev_register()
1316 put_device(&edev->dev); in extcon_dev_register()
1321 list_add(&edev->entry, &extcon_dev_list); in extcon_dev_register()
1327 if (edev->max_supported) in extcon_dev_register()
1328 kfree(edev->nh); in extcon_dev_register()
1330 if (edev->max_supported) in extcon_dev_register()
1331 kfree(edev->extcon_dev_type.groups); in extcon_dev_register()
1333 if (edev->max_supported && edev->mutually_exclusive) { in extcon_dev_register()
1334 for (index = 0; edev->mutually_exclusive[index]; index++) in extcon_dev_register()
1335 kfree(edev->d_attrs_muex[index].attr.name); in extcon_dev_register()
1336 kfree(edev->d_attrs_muex); in extcon_dev_register()
1337 kfree(edev->attrs_muex); in extcon_dev_register()
1340 for (index = 0; index < edev->max_supported; index++) in extcon_dev_register()
1341 kfree(edev->cables[index].attr_g.name); in extcon_dev_register()
1342 if (edev->max_supported) in extcon_dev_register()
1343 kfree(edev->cables); in extcon_dev_register()
1345 ida_free(&extcon_dev_ids, edev->id); in extcon_dev_register()
1352 * extcon_dev_unregister() - Unregister the extcon device.
1360 int index; in extcon_dev_unregister()
1366 list_del(&edev->entry); in extcon_dev_unregister()
1369 if (!get_device(&edev->dev)) { in extcon_dev_unregister()
1370 dev_err(&edev->dev, "Failed to unregister extcon_dev\n"); in extcon_dev_unregister()
1374 ida_free(&extcon_dev_ids, edev->id); in extcon_dev_unregister()
1376 device_unregister(&edev->dev); in extcon_dev_unregister()
1378 if (edev->mutually_exclusive && edev->max_supported) { in extcon_dev_unregister()
1379 for (index = 0; edev->mutually_exclusive[index]; in extcon_dev_unregister()
1381 kfree(edev->d_attrs_muex[index].attr.name); in extcon_dev_unregister()
1382 kfree(edev->d_attrs_muex); in extcon_dev_unregister()
1383 kfree(edev->attrs_muex); in extcon_dev_unregister()
1386 for (index = 0; index < edev->max_supported; index++) in extcon_dev_unregister()
1387 kfree(edev->cables[index].attr_g.name); in extcon_dev_unregister()
1389 if (edev->max_supported) { in extcon_dev_unregister()
1390 kfree(edev->extcon_dev_type.groups); in extcon_dev_unregister()
1391 kfree(edev->cables); in extcon_dev_unregister()
1392 kfree(edev->nh); in extcon_dev_unregister()
1395 put_device(&edev->dev); in extcon_dev_unregister()
1402 * extcon_find_edev_by_node - Find the extcon device from devicetree.
1413 if (edev->dev.parent && device_match_of_node(edev->dev.parent, node)) in extcon_find_edev_by_node()
1415 edev = ERR_PTR(-EPROBE_DEFER); in extcon_find_edev_by_node()
1423 * extcon_get_edev_by_phandle - Get the extcon device from devicetree.
1429 struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index) in extcon_get_edev_by_phandle()
1436 return ERR_PTR(-EINVAL); in extcon_get_edev_by_phandle()
1442 return ERR_PTR(-ENODEV); in extcon_get_edev_by_phandle()
1455 return ERR_PTR(-ENOSYS); in extcon_find_edev_by_node()
1458 struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index) in extcon_get_edev_by_phandle()
1460 return ERR_PTR(-ENOSYS); in extcon_get_edev_by_phandle()
1469 * extcon_get_edev_name() - Get the name of the extcon device.
1474 return !edev ? NULL : edev->name; in extcon_get_edev_name()
1478 static int __init extcon_class_init(void) in extcon_class_init()