Lines Matching +full:device +full:- +full:id
1 // SPDX-License-Identifier: GPL-2.0-only
3 * drivers/extcon/extcon.c - External Connector (extcon) framework.
21 #include <linux/device.h>
34 unsigned int id; member
40 .id = EXTCON_NONE,
47 .id = EXTCON_USB,
52 .id = EXTCON_USB_HOST,
53 .name = "USB-HOST",
59 .id = EXTCON_CHG_USB_SDP,
64 .id = EXTCON_CHG_USB_DCP,
69 .id = EXTCON_CHG_USB_CDP,
74 .id = EXTCON_CHG_USB_ACA,
79 .id = EXTCON_CHG_USB_FAST,
80 .name = "FAST-CHARGER",
84 .id = EXTCON_CHG_USB_SLOW,
85 .name = "SLOW-CHARGER",
89 .id = EXTCON_CHG_WPT,
94 .id = EXTCON_CHG_USB_PD,
101 .id = EXTCON_JACK_MICROPHONE,
106 .id = EXTCON_JACK_HEADPHONE,
111 .id = EXTCON_JACK_LINE_IN,
112 .name = "LINE-IN",
116 .id = EXTCON_JACK_LINE_OUT,
117 .name = "LINE-OUT",
121 .id = EXTCON_JACK_VIDEO_IN,
122 .name = "VIDEO-IN",
126 .id = EXTCON_JACK_VIDEO_OUT,
127 .name = "VIDEO-OUT",
131 .id = EXTCON_JACK_SPDIF_IN,
132 .name = "SPDIF-IN",
136 .id = EXTCON_JACK_SPDIF_OUT,
137 .name = "SPDIF-OUT",
143 .id = EXTCON_DISP_HDMI,
148 .id = EXTCON_DISP_MHL,
153 .id = EXTCON_DISP_DVI,
158 .id = EXTCON_DISP_VGA,
163 .id = EXTCON_DISP_DP,
168 .id = EXTCON_DISP_HMD,
173 .id = EXTCON_DISP_CVBS,
178 .id = EXTCON_DISP_EDP,
185 .id = EXTCON_DOCK,
190 .id = EXTCON_JIG,
195 .id = EXTCON_MECHANICAL,
203 * struct extcon_cable - An internal data for an external connector.
204 * @edev: the extcon device
250 if (!edev->mutually_exclusive) in check_mutually_exclusive()
253 for (i = 0; edev->mutually_exclusive[i]; i++) { 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() argument
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()
291 return -EINVAL; in get_extcon_type()
297 return !!(edev->state & BIT(index)); in is_extcon_attached()
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() argument
316 /* Check whether a specific extcon id supports the property or not. */ in is_extcon_property_supported()
317 return !!(extcon_info[id].type & type); in is_extcon_property_supported()
321 unsigned int id, int index,unsigned int prop) in is_extcon_property_capability() argument
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() argument
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()
368 static ssize_t state_show(struct device *dev, struct device_attribute *attr, 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()
387 static ssize_t name_show(struct device *dev, struct device_attribute *attr, in name_show()
392 return sysfs_emit(buf, "%s\n", edev->name); in name_show()
396 static ssize_t cable_name_show(struct device *dev, in cable_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()
407 static ssize_t cable_state_show(struct device *dev, in cable_state_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.
421 * @edev: the extcon device
422 * @id: the unique id indicating an external connector
429 int extcon_sync(struct extcon_dev *edev, unsigned int id) in extcon_sync() argument
442 return -EINVAL; in extcon_sync()
444 index = find_cable_index_by_id(edev, id); 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.
505 * @edev: the extcon device
506 * @id: the unique id indicating an external connector
510 int extcon_get_state(struct extcon_dev *edev, const unsigned int id) in extcon_get_state() argument
516 return -EINVAL; in extcon_get_state()
518 index = find_cable_index_by_id(edev, id); 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.
532 * @edev: the extcon device
533 * @id: the unique id indicating an external connector
543 int extcon_set_state(struct extcon_dev *edev, unsigned int id, bool state) in extcon_set_state() argument
549 return -EINVAL; in extcon_set_state()
551 index = find_cable_index_by_id(edev, id); 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()
572 init_property(edev, id, index); 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.
588 * @edev: the extcon device
589 * @id: the unique id indicating an external connector
598 int extcon_set_state_sync(struct extcon_dev *edev, unsigned int id, bool state) in extcon_set_state_sync() argument
602 ret = extcon_set_state(edev, id, state); in extcon_set_state_sync()
606 return extcon_sync(edev, id); in extcon_set_state_sync()
611 * extcon_get_property() - Get the property value of an external connector.
612 * @edev: the extcon device
613 * @id: the unique id indicating an external connector
614 * @prop: the property id indicating an extcon property
624 int extcon_get_property(struct extcon_dev *edev, unsigned int id, in extcon_get_property() argument
635 return -EINVAL; in extcon_get_property()
638 if (!is_extcon_property_supported(id, prop)) in extcon_get_property()
639 return -EINVAL; in extcon_get_property()
641 /* Find the cable index of external connector by using id */ in extcon_get_property()
642 index = find_cable_index_by_id(edev, id); in extcon_get_property()
646 spin_lock_irqsave(&edev->lock, flags); in extcon_get_property()
649 if (!is_extcon_property_capability(edev, id, index, prop)) { in extcon_get_property()
650 spin_unlock_irqrestore(&edev->lock, flags); in extcon_get_property()
651 return -EPERM; in extcon_get_property()
660 spin_unlock_irqrestore(&edev->lock, flags); in extcon_get_property()
664 cable = &edev->cables[index]; 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.
693 * @edev: the extcon device
694 * @id: the unique id indicating an external connector
695 * @prop: the property id indicating an extcon property
703 int extcon_set_property(struct extcon_dev *edev, unsigned int id, in extcon_set_property() argument
712 return -EINVAL; in extcon_set_property()
715 if (!is_extcon_property_supported(id, prop)) in extcon_set_property()
716 return -EINVAL; in extcon_set_property()
718 /* Find the cable index of external connector by using id */ in extcon_set_property()
719 index = find_cable_index_by_id(edev, id); in extcon_set_property()
723 spin_lock_irqsave(&edev->lock, flags); in extcon_set_property()
726 if (!is_extcon_property_capability(edev, id, index, prop)) { 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()
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.
760 * @edev: the extcon device
761 * @id: the unique id indicating an external connector
762 * @prop: the property id indicating an extcon property
771 int extcon_set_property_sync(struct extcon_dev *edev, unsigned int id, in extcon_set_property_sync() argument
777 ret = extcon_set_property(edev, id, prop, prop_val); in extcon_set_property_sync()
781 return extcon_sync(edev, id); in extcon_set_property_sync()
786 * extcon_get_property_capability() - Get the capability of the property
788 * @edev: the extcon device
789 * @id: the unique id indicating an external connector
790 * @prop: the property id indicating an extcon property
794 int extcon_get_property_capability(struct extcon_dev *edev, unsigned int id, in extcon_get_property_capability() argument
800 return -EINVAL; in extcon_get_property_capability()
803 if (!is_extcon_property_supported(id, prop)) in extcon_get_property_capability()
804 return -EINVAL; in extcon_get_property_capability()
806 /* Find the cable index of external connector by using id */ in extcon_get_property_capability()
807 index = find_cable_index_by_id(edev, id); in extcon_get_property_capability()
811 return is_extcon_property_capability(edev, id, index, prop); in extcon_get_property_capability()
816 * extcon_set_property_capability() - Set the capability of the property
818 * @edev: the extcon device
819 * @id: the unique id indicating an external connector
820 * @prop: the property id indicating an extcon property
828 int extcon_set_property_capability(struct extcon_dev *edev, unsigned int id, in extcon_set_property_capability() argument
835 return -EINVAL; in extcon_set_property_capability()
838 if (!is_extcon_property_supported(id, prop)) in extcon_set_property_capability()
839 return -EINVAL; in extcon_set_property_capability()
841 /* Find the cable index of external connector by using id. */ in extcon_set_property_capability()
842 index = find_cable_index_by_id(edev, id); 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.
877 * Return the pointer of extcon device if success or ERR_PTR(err) if fail.
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
903 * @edev: the extcon device
904 * @id: the unique id indicating an external connector
909 * is the pointer of extcon device.
913 int extcon_register_notifier(struct extcon_dev *edev, unsigned int id, in extcon_register_notifier() argument
920 return -EINVAL; in extcon_register_notifier()
922 idx = find_cable_index_by_id(edev, id); 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.
936 * @edev: the extcon device
937 * @id: the unique id indicating an external connector
942 int extcon_unregister_notifier(struct extcon_dev *edev, unsigned int id, in extcon_unregister_notifier() argument
949 return -EINVAL; in extcon_unregister_notifier()
951 idx = find_cable_index_by_id(edev, id); 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.
965 * @edev: the extcon device
969 * the state change of all supported external connectors from extcon device.
971 * the current state and the third pameter is the pointer of extcon device.
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.
994 * @edev: the extcon device
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()
1031 extcon_class->dev_groups = extcon_groups; in create_extcon_class()
1036 static void extcon_dev_release(struct device *dev) in extcon_dev_release()
1041 static void dummy_sysfs_dev_release(struct device *dev) in dummy_sysfs_dev_release()
1046 * extcon_dev_allocate() - Allocate the memory of extcon device.
1050 * Note that this function allocates the memory for extcon device
1051 * and initialize default setting for the extcon device.
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.
1075 * @edev: the extcon device
1084 * extcon_alloc_cables() - alloc the cables for extcon device
1085 * @edev: extcon device which has 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
1144 * @edev: extcon device
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
1199 * @edev: extcon device
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
1235 * @edev: the extcon device to be registered
1242 * of an extcon device by using the extcon_dev_allocate(). And the extcon
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()
1273 "extcon device name is null\n"); 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.
1353 * @edev: the extcon device to be unregistered.
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.
1405 * Return the pointer of extcon device if success or ERR_PTR(err) if fail.
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.
1424 * @dev : the instance to the given device
1427 * Return the pointer of extcon device if success or ERR_PTR(err) if fail.
1429 struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index) in extcon_get_edev_by_phandle()
1435 dev_dbg(dev, "device does not have a device node entry\n"); 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.
1470 * @edev: the extcon device
1474 return !edev ? NULL : edev->name; in extcon_get_edev_name()