Lines Matching refs:edev

203  * @edev:		the extcon device
204 * @cable_index: the index of this cable in the edev
219 struct extcon_dev *edev;
244 static int check_mutually_exclusive(struct extcon_dev *edev, u32 new_state)
248 if (!edev->mutually_exclusive)
251 for (i = 0; edev->mutually_exclusive[i]; i++) {
253 u32 correspondants = new_state & edev->mutually_exclusive[i];
264 static int find_cable_index_by_id(struct extcon_dev *edev, const unsigned int id)
268 /* Find the the index of extcon cable in edev->supported_cable */
269 for (i = 0; i < edev->max_supported; i++) {
270 if (edev->supported_cable[i] == id)
293 static bool is_extcon_attached(struct extcon_dev *edev, unsigned int index)
295 return !!(edev->state & BIT(index));
298 static bool is_extcon_changed(struct extcon_dev *edev, int index,
301 int state = !!(edev->state & BIT(index));
318 static int is_extcon_property_capability(struct extcon_dev *edev,
329 cable = &edev->cables[index];
351 static void init_property(struct extcon_dev *edev, unsigned int id, int index)
354 struct extcon_cable *cable = &edev->cables[index];
370 struct extcon_dev *edev = dev_get_drvdata(dev);
372 if (edev->max_supported == 0)
373 return sprintf(buf, "%u\n", edev->state);
375 for (i = 0; i < edev->max_supported; i++) {
377 extcon_info[edev->supported_cable[i]].name,
378 !!(edev->state & BIT(i)));
388 struct extcon_dev *edev = dev_get_drvdata(dev);
390 return sprintf(buf, "%s\n", edev->name);
402 extcon_info[cable->edev->supported_cable[i]].name);
414 extcon_get_state(cable->edev, cable->edev->supported_cable[i]));
419 * @edev: the extcon device
426 int extcon_sync(struct extcon_dev *edev, unsigned int id)
438 if (!edev)
441 index = find_cable_index_by_id(edev, id);
445 spin_lock_irqsave(&edev->lock, flags);
446 state = !!(edev->state & BIT(index));
447 spin_unlock_irqrestore(&edev->lock, flags);
453 raw_notifier_call_chain(&edev->nh[index], state, edev);
459 raw_notifier_call_chain(&edev->nh_all, state, edev);
461 spin_lock_irqsave(&edev->lock, flags);
466 spin_unlock_irqrestore(&edev->lock, flags);
468 dev_err(&edev->dev, "out of memory in extcon_set_state\n");
469 kobject_uevent(&edev->dev.kobj, KOBJ_CHANGE);
474 length = name_show(&edev->dev, NULL, prop_buf);
482 length = state_show(&edev->dev, NULL, prop_buf);
492 spin_unlock_irqrestore(&edev->lock, flags);
493 kobject_uevent_env(&edev->dev.kobj, KOBJ_CHANGE, envp);
502 * @edev: the extcon device
507 int extcon_get_state(struct extcon_dev *edev, const unsigned int id)
512 if (!edev)
515 index = find_cable_index_by_id(edev, id);
519 spin_lock_irqsave(&edev->lock, flags);
520 state = is_extcon_attached(edev, index);
521 spin_unlock_irqrestore(&edev->lock, flags);
529 * @edev: the extcon device
540 int extcon_set_state(struct extcon_dev *edev, unsigned int id, bool state)
545 if (!edev)
548 index = find_cable_index_by_id(edev, id);
552 spin_lock_irqsave(&edev->lock, flags);
555 if (!is_extcon_changed(edev, index, state))
558 if (check_mutually_exclusive(edev,
559 (edev->state & ~BIT(index)) | (state & BIT(index)))) {
569 init_property(edev, id, index);
573 edev->state |= BIT(index);
575 edev->state &= ~(BIT(index));
577 spin_unlock_irqrestore(&edev->lock, flags);
585 * @edev: the extcon device
595 int extcon_set_state_sync(struct extcon_dev *edev, unsigned int id, bool state)
600 index = find_cable_index_by_id(edev, id);
605 spin_lock_irqsave(&edev->lock, flags);
606 ret = is_extcon_changed(edev, index, state);
607 spin_unlock_irqrestore(&edev->lock, flags);
611 ret = extcon_set_state(edev, id, state);
615 return extcon_sync(edev, id);
621 * @edev: the extcon device
633 int extcon_get_property(struct extcon_dev *edev, unsigned int id,
643 if (!edev)
651 index = find_cable_index_by_id(edev, id);
655 spin_lock_irqsave(&edev->lock, flags);
658 if (!is_extcon_property_capability(edev, id, index, prop)) {
659 spin_unlock_irqrestore(&edev->lock, flags);
668 if (!is_extcon_attached(edev, index)) {
669 spin_unlock_irqrestore(&edev->lock, flags);
673 cable = &edev->cables[index];
694 spin_unlock_irqrestore(&edev->lock, flags);
702 * @edev: the extcon device
712 int extcon_set_property(struct extcon_dev *edev, unsigned int id,
720 if (!edev)
728 index = find_cable_index_by_id(edev, id);
732 spin_lock_irqsave(&edev->lock, flags);
735 if (!is_extcon_property_capability(edev, id, index, prop)) {
736 spin_unlock_irqrestore(&edev->lock, flags);
740 cable = &edev->cables[index];
761 spin_unlock_irqrestore(&edev->lock, flags);
777 int extcon_set_property_sync(struct extcon_dev *edev, unsigned int id,
783 ret = extcon_set_property(edev, id, prop, prop_val);
787 return extcon_sync(edev, id);
794 * @edev: the extcon device
800 int extcon_get_property_capability(struct extcon_dev *edev, unsigned int id,
805 if (!edev)
813 index = find_cable_index_by_id(edev, id);
817 return is_extcon_property_capability(edev, id, index, prop);
824 * @edev: the extcon device
834 int extcon_set_property_capability(struct extcon_dev *edev, unsigned int id,
840 if (!edev)
848 index = find_cable_index_by_id(edev, id);
856 cable = &edev->cables[index];
907 * @edev: the extcon device
917 int extcon_register_notifier(struct extcon_dev *edev, unsigned int id,
923 if (!edev || !nb)
926 idx = find_cable_index_by_id(edev, id);
930 spin_lock_irqsave(&edev->lock, flags);
931 ret = raw_notifier_chain_register(&edev->nh[idx], nb);
932 spin_unlock_irqrestore(&edev->lock, flags);
940 * @edev: the extcon device
946 int extcon_unregister_notifier(struct extcon_dev *edev, unsigned int id,
952 if (!edev || !nb)
955 idx = find_cable_index_by_id(edev, id);
959 spin_lock_irqsave(&edev->lock, flags);
960 ret = raw_notifier_chain_unregister(&edev->nh[idx], nb);
961 spin_unlock_irqrestore(&edev->lock, flags);
969 * @edev: the extcon device
979 int extcon_register_notifier_all(struct extcon_dev *edev,
985 if (!edev || !nb)
988 spin_lock_irqsave(&edev->lock, flags);
989 ret = raw_notifier_chain_register(&edev->nh_all, nb);
990 spin_unlock_irqrestore(&edev->lock, flags);
998 * @edev: the extcon device
1003 int extcon_unregister_notifier_all(struct extcon_dev *edev,
1009 if (!edev || !nb)
1012 spin_lock_irqsave(&edev->lock, flags);
1013 ret = raw_notifier_chain_unregister(&edev->nh_all, nb);
1014 spin_unlock_irqrestore(&edev->lock, flags);
1061 struct extcon_dev *edev;
1066 edev = kzalloc(sizeof(*edev), GFP_KERNEL);
1067 if (!edev)
1070 edev->max_supported = 0;
1071 edev->supported_cable = supported_cable;
1073 return edev;
1078 * @edev: the extcon device
1080 void extcon_dev_free(struct extcon_dev *edev)
1082 kfree(edev);
1088 * @edev: the extcon device to be registered
1090 * Among the members of edev struct, please set the "user initializing data"
1100 int extcon_dev_register(struct extcon_dev *edev)
1111 if (!edev || !edev->supported_cable)
1114 for (; edev->supported_cable[index] != EXTCON_NONE; index++);
1116 edev->max_supported = index;
1118 dev_err(&edev->dev,
1123 edev->dev.class = extcon_class;
1124 edev->dev.release = extcon_dev_release;
1126 edev->name = dev_name(edev->dev.parent);
1127 if (IS_ERR_OR_NULL(edev->name)) {
1128 dev_err(&edev->dev,
1132 dev_set_name(&edev->dev, "extcon%lu",
1135 if (edev->max_supported) {
1139 edev->cables = kcalloc(edev->max_supported,
1142 if (!edev->cables) {
1146 for (index = 0; index < edev->max_supported; index++) {
1147 cable = &edev->cables[index];
1152 cable = &edev->cables[index];
1160 cable->edev = edev;
1180 if (edev->max_supported && edev->mutually_exclusive) {
1184 for (index = 0; edev->mutually_exclusive[index]; index++)
1187 edev->attrs_muex = kcalloc(index + 1,
1190 if (!edev->attrs_muex) {
1195 edev->d_attrs_muex = kcalloc(index,
1198 if (!edev->d_attrs_muex) {
1200 kfree(edev->attrs_muex);
1204 for (index = 0; edev->mutually_exclusive[index]; index++) {
1206 edev->mutually_exclusive[index]);
1209 kfree(edev->d_attrs_muex[index].attr.
1212 kfree(edev->d_attrs_muex);
1213 kfree(edev->attrs_muex);
1217 sysfs_attr_init(&edev->d_attrs_muex[index].attr);
1218 edev->d_attrs_muex[index].attr.name = name;
1219 edev->d_attrs_muex[index].attr.mode = 0000;
1220 edev->attrs_muex[index] = &edev->d_attrs_muex[index]
1223 edev->attr_g_muex.name = muex_name;
1224 edev->attr_g_muex.attrs = edev->attrs_muex;
1228 if (edev->max_supported) {
1229 edev->extcon_dev_type.groups =
1230 kcalloc(edev->max_supported + 2,
1233 if (!edev->extcon_dev_type.groups) {
1238 edev->extcon_dev_type.name = dev_name(&edev->dev);
1239 edev->extcon_dev_type.release = dummy_sysfs_dev_release;
1241 for (index = 0; index < edev->max_supported; index++)
1242 edev->extcon_dev_type.groups[index] =
1243 &edev->cables[index].attr_g;
1244 if (edev->mutually_exclusive)
1245 edev->extcon_dev_type.groups[index] =
1246 &edev->attr_g_muex;
1248 edev->dev.type = &edev->extcon_dev_type;
1251 spin_lock_init(&edev->lock);
1252 if (edev->max_supported) {
1253 edev->nh = kcalloc(edev->max_supported, sizeof(*edev->nh),
1255 if (!edev->nh) {
1261 for (index = 0; index < edev->max_supported; index++)
1262 RAW_INIT_NOTIFIER_HEAD(&edev->nh[index]);
1264 RAW_INIT_NOTIFIER_HEAD(&edev->nh_all);
1266 dev_set_drvdata(&edev->dev, edev);
1267 edev->state = 0;
1269 ret = device_register(&edev->dev);
1271 put_device(&edev->dev);
1276 list_add(&edev->entry, &extcon_dev_list);
1282 if (edev->max_supported)
1283 kfree(edev->nh);
1285 if (edev->max_supported)
1286 kfree(edev->extcon_dev_type.groups);
1288 if (edev->max_supported && edev->mutually_exclusive) {
1289 for (index = 0; edev->mutually_exclusive[index]; index++)
1290 kfree(edev->d_attrs_muex[index].attr.name);
1291 kfree(edev->d_attrs_muex);
1292 kfree(edev->attrs_muex);
1295 for (index = 0; index < edev->max_supported; index++)
1296 kfree(edev->cables[index].attr_g.name);
1298 if (edev->max_supported)
1299 kfree(edev->cables);
1307 * @edev: the extcon device to be unregistered.
1309 * Note that this does not call kfree(edev) because edev was not allocated
1312 void extcon_dev_unregister(struct extcon_dev *edev)
1316 if (!edev)
1320 list_del(&edev->entry);
1323 if (IS_ERR_OR_NULL(get_device(&edev->dev))) {
1324 dev_err(&edev->dev, "Failed to unregister extcon_dev (%s)\n",
1325 dev_name(&edev->dev));
1329 device_unregister(&edev->dev);
1331 if (edev->mutually_exclusive && edev->max_supported) {
1332 for (index = 0; edev->mutually_exclusive[index];
1334 kfree(edev->d_attrs_muex[index].attr.name);
1335 kfree(edev->d_attrs_muex);
1336 kfree(edev->attrs_muex);
1339 for (index = 0; index < edev->max_supported; index++)
1340 kfree(edev->cables[index].attr_g.name);
1342 if (edev->max_supported) {
1343 kfree(edev->extcon_dev_type.groups);
1344 kfree(edev->cables);
1345 kfree(edev->nh);
1348 put_device(&edev->dev);
1356 * @node : OF node identifying edev
1362 struct extcon_dev *edev;
1365 list_for_each_entry(edev, &extcon_dev_list, entry)
1366 if (edev->dev.parent && edev->dev.parent->of_node == node)
1368 edev = ERR_PTR(-EPROBE_DEFER);
1372 return edev;
1385 struct extcon_dev *edev;
1402 edev = extcon_find_edev_by_node(node);
1405 return edev;
1427 * @edev: the extcon device
1429 const char *extcon_get_edev_name(struct extcon_dev *edev)
1431 return !edev ? NULL : edev->name;