Skip to content

Commit 830ae44

Browse files
committed
extcon: Remove the deprecated extcon functions
This patch removes the deprecated extcon functions using string type to identify the type of external connector. The Commit 2a9de9c ("extcon: Use the unique id for external connector instead of string) uses the unique id to separate the type of external connector instead of string name. - extcon_register_interest() - extcon_unregister_interest() - extcon_set_cable_state() - extcon_get_cable_state() And, extcon_register_interest() finds the first extcon device to include the requested external connector from extcon client device and then register the notifier if extcon device argument is NULL. Instead, extcon_register_notifier() supports this feature. But, this patch remains the deprecatd function definition to prevent the build break. Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
1 parent b396cff commit 830ae44

2 files changed

Lines changed: 47 additions & 234 deletions

File tree

‎drivers/extcon/extcon.c‎

Lines changed: 24 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
162130
static 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
}
374342
EXPORT_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
}
422371
EXPORT_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
}
467394
EXPORT_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
}

‎include/linux/extcon.h‎

Lines changed: 23 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -146,22 +146,6 @@ struct extcon_cable {
146146
struct attribute *attrs[3]; /* to be fed to attr_g.attrs */
147147
};
148148

149-
/**
150-
* struct extcon_specific_cable_nb - An internal data for
151-
* extcon_register_interest().
152-
* @user_nb: user provided notifier block for events from
153-
* a specific cable.
154-
* @cable_index: the target cable.
155-
* @edev: the target extcon device.
156-
* @previous_value: the saved previous event value.
157-
*/
158-
struct extcon_specific_cable_nb {
159-
struct notifier_block *user_nb;
160-
int cable_index;
161-
struct extcon_dev *edev;
162-
unsigned long previous_value;
163-
};
164-
165149
#if IS_ENABLED(CONFIG_EXTCON)
166150

167151
/*
@@ -207,23 +191,6 @@ extern int extcon_get_cable_state_(struct extcon_dev *edev, unsigned int id);
207191
extern int extcon_set_cable_state_(struct extcon_dev *edev, unsigned int id,
208192
bool cable_state);
209193

210-
extern int extcon_get_cable_state(struct extcon_dev *edev,
211-
const char *cable_name);
212-
extern int extcon_set_cable_state(struct extcon_dev *edev,
213-
const char *cable_name, bool cable_state);
214-
215-
/*
216-
* Following APIs are for notifiees (those who want to be notified)
217-
* to register a callback for events from a specific cable of the extcon.
218-
* Notifiees are the connected device drivers wanting to get notified by
219-
* a specific external port of a connection device.
220-
*/
221-
extern int extcon_register_interest(struct extcon_specific_cable_nb *obj,
222-
const char *extcon_name,
223-
const char *cable_name,
224-
struct notifier_block *nb);
225-
extern int extcon_unregister_interest(struct extcon_specific_cable_nb *nb);
226-
227194
/*
228195
* Following APIs are to monitor every action of a notifier.
229196
* Registrar gets notified for every external port of a connection device.
@@ -246,6 +213,7 @@ extern struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev,
246213
/* Following API to get information of extcon device */
247214
extern const char *extcon_get_edev_name(struct extcon_dev *edev);
248215

216+
249217
#else /* CONFIG_EXTCON */
250218
static inline int extcon_dev_register(struct extcon_dev *edev)
251219
{
@@ -306,18 +274,6 @@ static inline int extcon_set_cable_state_(struct extcon_dev *edev,
306274
return 0;
307275
}
308276

309-
static inline int extcon_get_cable_state(struct extcon_dev *edev,
310-
const char *cable_name)
311-
{
312-
return 0;
313-
}
314-
315-
static inline int extcon_set_cable_state(struct extcon_dev *edev,
316-
const char *cable_name, int state)
317-
{
318-
return 0;
319-
}
320-
321277
static inline struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name)
322278
{
323279
return NULL;
@@ -337,24 +293,34 @@ static inline int extcon_unregister_notifier(struct extcon_dev *edev,
337293
return 0;
338294
}
339295

340-
static inline int extcon_register_interest(struct extcon_specific_cable_nb *obj,
341-
const char *extcon_name,
342-
const char *cable_name,
343-
struct notifier_block *nb)
296+
static inline struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev,
297+
int index)
344298
{
345-
return 0;
299+
return ERR_PTR(-ENODEV);
346300
}
301+
#endif /* CONFIG_EXTCON */
347302

348-
static inline int extcon_unregister_interest(struct extcon_specific_cable_nb
349-
*obj)
303+
/*
304+
* Following structure and API are deprecated. EXTCON remains the function
305+
* definition to prevent the build break.
306+
*/
307+
struct extcon_specific_cable_nb {
308+
struct notifier_block *user_nb;
309+
int cable_index;
310+
struct extcon_dev *edev;
311+
unsigned long previous_value;
312+
};
313+
314+
static inline int extcon_register_interest(struct extcon_specific_cable_nb *obj,
315+
const char *extcon_name, const char *cable_name,
316+
struct notifier_block *nb)
350317
{
351-
return 0;
318+
return -EINVAL;
352319
}
353320

354-
static inline struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev,
355-
int index)
321+
static inline int extcon_unregister_interest(struct extcon_specific_cable_nb
322+
*obj)
356323
{
357-
return ERR_PTR(-ENODEV);
324+
return -EINVAL;
358325
}
359-
#endif /* CONFIG_EXTCON */
360326
#endif /* __LINUX_EXTCON_H__ */

0 commit comments

Comments
 (0)