@@ -127,38 +127,6 @@ static int find_cable_index_by_id(struct extcon_dev *edev, const unsigned int id
127127 return - EINVAL ;
128128}
129129
130- static int find_cable_id_by_name (struct extcon_dev * edev , const char * name )
131- {
132- int id = - EINVAL ;
133- int i = 0 ;
134-
135- /* Find the id of extcon cable */
136- while (extcon_name [i ]) {
137- if (!strncmp (extcon_name [i ], name , CABLE_NAME_MAX )) {
138- id = i ;
139- break ;
140- }
141- i ++ ;
142- }
143-
144- return id ;
145- }
146-
147- static int find_cable_index_by_name (struct extcon_dev * edev , const char * name )
148- {
149- int id ;
150-
151- if (edev -> max_supported == 0 )
152- return - EINVAL ;
153-
154- /* Find the the number of extcon cable */
155- id = find_cable_id_by_name (edev , name );
156- if (id < 0 )
157- return id ;
158-
159- return find_cable_index_by_id (edev , id );
160- }
161-
162130static bool is_extcon_changed (u32 prev , u32 new , int idx , bool * attached )
163131{
164132 if (((prev >> idx ) & 0x1 ) != ((new >> idx ) & 0x1 )) {
@@ -373,25 +341,6 @@ int extcon_get_cable_state_(struct extcon_dev *edev, const unsigned int id)
373341}
374342EXPORT_SYMBOL_GPL (extcon_get_cable_state_ );
375343
376- /**
377- * extcon_get_cable_state() - Get the status of a specific cable.
378- * @edev: the extcon device that has the cable.
379- * @cable_name: cable name.
380- *
381- * Note that this is slower than extcon_get_cable_state_.
382- */
383- int extcon_get_cable_state (struct extcon_dev * edev , const char * cable_name )
384- {
385- int id ;
386-
387- id = find_cable_id_by_name (edev , cable_name );
388- if (id < 0 )
389- return id ;
390-
391- return extcon_get_cable_state_ (edev , id );
392- }
393- EXPORT_SYMBOL_GPL (extcon_get_cable_state );
394-
395344/**
396345 * extcon_set_cable_state_() - Set the status of a specific cable.
397346 * @edev: the extcon device that has the cable.
@@ -421,28 +370,6 @@ int extcon_set_cable_state_(struct extcon_dev *edev, unsigned int id,
421370}
422371EXPORT_SYMBOL_GPL (extcon_set_cable_state_ );
423372
424- /**
425- * extcon_set_cable_state() - Set the status of a specific cable.
426- * @edev: the extcon device that has the cable.
427- * @cable_name: cable name.
428- * @cable_state: the new cable status. The default semantics is
429- * true: attached / false: detached.
430- *
431- * Note that this is slower than extcon_set_cable_state_.
432- */
433- int extcon_set_cable_state (struct extcon_dev * edev ,
434- const char * cable_name , bool cable_state )
435- {
436- int id ;
437-
438- id = find_cable_id_by_name (edev , cable_name );
439- if (id < 0 )
440- return id ;
441-
442- return extcon_set_cable_state_ (edev , id , cable_state );
443- }
444- EXPORT_SYMBOL_GPL (extcon_set_cable_state );
445-
446373/**
447374 * extcon_get_extcon_dev() - Get the extcon device instance from the name
448375 * @extcon_name: The extcon name provided with extcon_dev_register()
@@ -466,105 +393,6 @@ struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name)
466393}
467394EXPORT_SYMBOL_GPL (extcon_get_extcon_dev );
468395
469- /**
470- * extcon_register_interest() - Register a notifier for a state change of a
471- * specific cable, not an entier set of cables of a
472- * extcon device.
473- * @obj: an empty extcon_specific_cable_nb object to be returned.
474- * @extcon_name: the name of extcon device.
475- * if NULL, extcon_register_interest will register
476- * every cable with the target cable_name given.
477- * @cable_name: the target cable name.
478- * @nb: the notifier block to get notified.
479- *
480- * Provide an empty extcon_specific_cable_nb. extcon_register_interest() sets
481- * the struct for you.
482- *
483- * extcon_register_interest is a helper function for those who want to get
484- * notification for a single specific cable's status change. If a user wants
485- * to get notification for any changes of all cables of a extcon device,
486- * he/she should use the general extcon_register_notifier().
487- *
488- * Note that the second parameter given to the callback of nb (val) is
489- * "old_state", not the current state. The current state can be retrieved
490- * by looking at the third pameter (edev pointer)'s state value.
491- */
492- int extcon_register_interest (struct extcon_specific_cable_nb * obj ,
493- const char * extcon_name , const char * cable_name ,
494- struct notifier_block * nb )
495- {
496- unsigned long flags ;
497- int ret ;
498-
499- if (!obj || !cable_name || !nb )
500- return - EINVAL ;
501-
502- if (extcon_name ) {
503- obj -> edev = extcon_get_extcon_dev (extcon_name );
504- if (!obj -> edev )
505- return - ENODEV ;
506-
507- obj -> cable_index = find_cable_index_by_name (obj -> edev ,
508- cable_name );
509- if (obj -> cable_index < 0 )
510- return obj -> cable_index ;
511-
512- obj -> user_nb = nb ;
513-
514- spin_lock_irqsave (& obj -> edev -> lock , flags );
515- ret = raw_notifier_chain_register (
516- & obj -> edev -> nh [obj -> cable_index ],
517- obj -> user_nb );
518- spin_unlock_irqrestore (& obj -> edev -> lock , flags );
519- } else {
520- struct class_dev_iter iter ;
521- struct extcon_dev * extd ;
522- struct device * dev ;
523-
524- if (!extcon_class )
525- return - ENODEV ;
526- class_dev_iter_init (& iter , extcon_class , NULL , NULL );
527- while ((dev = class_dev_iter_next (& iter ))) {
528- extd = dev_get_drvdata (dev );
529-
530- if (find_cable_index_by_name (extd , cable_name ) < 0 )
531- continue ;
532-
533- class_dev_iter_exit (& iter );
534- return extcon_register_interest (obj , extd -> name ,
535- cable_name , nb );
536- }
537-
538- ret = - ENODEV ;
539- }
540-
541- return ret ;
542- }
543- EXPORT_SYMBOL_GPL (extcon_register_interest );
544-
545- /**
546- * extcon_unregister_interest() - Unregister the notifier registered by
547- * extcon_register_interest().
548- * @obj: the extcon_specific_cable_nb object returned by
549- * extcon_register_interest().
550- */
551- int extcon_unregister_interest (struct extcon_specific_cable_nb * obj )
552- {
553- unsigned long flags ;
554- int ret ;
555-
556- if (!obj )
557- return - EINVAL ;
558-
559- spin_lock_irqsave (& obj -> edev -> lock , flags );
560- ret = raw_notifier_chain_unregister (
561- & obj -> edev -> nh [obj -> cable_index ], obj -> user_nb );
562- spin_unlock_irqrestore (& obj -> edev -> lock , flags );
563-
564- return ret ;
565- }
566- EXPORT_SYMBOL_GPL (extcon_unregister_interest );
567-
568396/**
569397 * extcon_register_notifier() - Register a notifiee to get notified by
570398 * any attach status changes from the extcon.
@@ -582,14 +410,33 @@ int extcon_register_notifier(struct extcon_dev *edev, unsigned int id,
582410 unsigned long flags ;
583411 int ret , idx ;
584412
585- if (!edev || ! nb )
413+ if (!nb )
586414 return - EINVAL ;
587415
588- idx = find_cable_index_by_id (edev , id );
416+ if (edev ) {
417+ idx = find_cable_index_by_id (edev , id );
589418
590- spin_lock_irqsave (& edev -> lock , flags );
591- ret = raw_notifier_chain_register (& edev -> nh [idx ], nb );
592- spin_unlock_irqrestore (& edev -> lock , flags );
419+ spin_lock_irqsave (& edev -> lock , flags );
420+ ret = raw_notifier_chain_register (& edev -> nh [idx ], nb );
421+ spin_unlock_irqrestore (& edev -> lock , flags );
422+ } else {
423+ struct extcon_dev * extd ;
424+
425+ mutex_lock (& extcon_dev_list_lock );
426+ list_for_each_entry (extd , & extcon_dev_list , entry ) {
427+ idx = find_cable_index_by_id (extd , id );
428+ if (idx >= 0 )
429+ break ;
430+ }
431+ mutex_unlock (& extcon_dev_list_lock );
432+
433+ if (idx >= 0 ) {
434+ edev = extd ;
435+ return extcon_register_notifier (extd , id , nb );
436+ } else {
437+ ret = - ENODEV ;
438+ }
439+ }
593440
594441 return ret ;
595442}
0 commit comments