phy: fix kernel oops in phy_lookup()
[platform/adaptation/renesas_rcar/renesas_kernel.git] / drivers / phy / phy-core.c
1 /*
2  * phy-core.c  --  Generic Phy framework.
3  *
4  * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com
5  *
6  * Author: Kishon Vijay Abraham I <kishon@ti.com>
7  *
8  * This program is free software; you can redistribute  it and/or modify it
9  * under  the terms of  the GNU General  Public License as published by the
10  * Free Software Foundation;  either version 2 of the  License, or (at your
11  * option) any later version.
12  */
13
14 #include <linux/kernel.h>
15 #include <linux/export.h>
16 #include <linux/module.h>
17 #include <linux/err.h>
18 #include <linux/device.h>
19 #include <linux/slab.h>
20 #include <linux/of.h>
21 #include <linux/phy/phy.h>
22 #include <linux/idr.h>
23 #include <linux/pm_runtime.h>
24
25 static struct class *phy_class;
26 static DEFINE_MUTEX(phy_provider_mutex);
27 static LIST_HEAD(phy_provider_list);
28 static DEFINE_IDA(phy_ida);
29
30 static void devm_phy_release(struct device *dev, void *res)
31 {
32         struct phy *phy = *(struct phy **)res;
33
34         phy_put(phy);
35 }
36
37 static void devm_phy_provider_release(struct device *dev, void *res)
38 {
39         struct phy_provider *phy_provider = *(struct phy_provider **)res;
40
41         of_phy_provider_unregister(phy_provider);
42 }
43
44 static void devm_phy_consume(struct device *dev, void *res)
45 {
46         struct phy *phy = *(struct phy **)res;
47
48         phy_destroy(phy);
49 }
50
51 static int devm_phy_match(struct device *dev, void *res, void *match_data)
52 {
53         return res == match_data;
54 }
55
56 static struct phy *phy_lookup(struct device *device, const char *port)
57 {
58         unsigned int count;
59         struct phy *phy;
60         struct device *dev;
61         struct phy_consumer *consumers;
62         struct class_dev_iter iter;
63
64         class_dev_iter_init(&iter, phy_class, NULL, NULL);
65         while ((dev = class_dev_iter_next(&iter))) {
66                 phy = to_phy(dev);
67
68                 if (!phy->init_data)
69                         continue;
70                 count = phy->init_data->num_consumers;
71                 consumers = phy->init_data->consumers;
72                 while (count--) {
73                         if (!strcmp(consumers->dev_name, dev_name(device)) &&
74                                         !strcmp(consumers->port, port)) {
75                                 class_dev_iter_exit(&iter);
76                                 return phy;
77                         }
78                         consumers++;
79                 }
80         }
81
82         class_dev_iter_exit(&iter);
83         return ERR_PTR(-ENODEV);
84 }
85
86 static struct phy_provider *of_phy_provider_lookup(struct device_node *node)
87 {
88         struct phy_provider *phy_provider;
89
90         list_for_each_entry(phy_provider, &phy_provider_list, list) {
91                 if (phy_provider->dev->of_node == node)
92                         return phy_provider;
93         }
94
95         return ERR_PTR(-EPROBE_DEFER);
96 }
97
98 int phy_pm_runtime_get(struct phy *phy)
99 {
100         int ret;
101
102         if (!pm_runtime_enabled(&phy->dev))
103                 return -ENOTSUPP;
104
105         ret = pm_runtime_get(&phy->dev);
106         if (ret < 0 && ret != -EINPROGRESS)
107                 pm_runtime_put_noidle(&phy->dev);
108
109         return ret;
110 }
111 EXPORT_SYMBOL_GPL(phy_pm_runtime_get);
112
113 int phy_pm_runtime_get_sync(struct phy *phy)
114 {
115         int ret;
116
117         if (!pm_runtime_enabled(&phy->dev))
118                 return -ENOTSUPP;
119
120         ret = pm_runtime_get_sync(&phy->dev);
121         if (ret < 0)
122                 pm_runtime_put_sync(&phy->dev);
123
124         return ret;
125 }
126 EXPORT_SYMBOL_GPL(phy_pm_runtime_get_sync);
127
128 int phy_pm_runtime_put(struct phy *phy)
129 {
130         if (!pm_runtime_enabled(&phy->dev))
131                 return -ENOTSUPP;
132
133         return pm_runtime_put(&phy->dev);
134 }
135 EXPORT_SYMBOL_GPL(phy_pm_runtime_put);
136
137 int phy_pm_runtime_put_sync(struct phy *phy)
138 {
139         if (!pm_runtime_enabled(&phy->dev))
140                 return -ENOTSUPP;
141
142         return pm_runtime_put_sync(&phy->dev);
143 }
144 EXPORT_SYMBOL_GPL(phy_pm_runtime_put_sync);
145
146 void phy_pm_runtime_allow(struct phy *phy)
147 {
148         if (!pm_runtime_enabled(&phy->dev))
149                 return;
150
151         pm_runtime_allow(&phy->dev);
152 }
153 EXPORT_SYMBOL_GPL(phy_pm_runtime_allow);
154
155 void phy_pm_runtime_forbid(struct phy *phy)
156 {
157         if (!pm_runtime_enabled(&phy->dev))
158                 return;
159
160         pm_runtime_forbid(&phy->dev);
161 }
162 EXPORT_SYMBOL_GPL(phy_pm_runtime_forbid);
163
164 int phy_init(struct phy *phy)
165 {
166         int ret;
167
168         if (!phy)
169                 return 0;
170
171         ret = phy_pm_runtime_get_sync(phy);
172         if (ret < 0 && ret != -ENOTSUPP)
173                 return ret;
174
175         mutex_lock(&phy->mutex);
176         if (phy->init_count == 0 && phy->ops->init) {
177                 ret = phy->ops->init(phy);
178                 if (ret < 0) {
179                         dev_err(&phy->dev, "phy init failed --> %d\n", ret);
180                         goto out;
181                 }
182         } else {
183                 ret = 0; /* Override possible ret == -ENOTSUPP */
184         }
185         ++phy->init_count;
186
187 out:
188         mutex_unlock(&phy->mutex);
189         phy_pm_runtime_put(phy);
190         return ret;
191 }
192 EXPORT_SYMBOL_GPL(phy_init);
193
194 int phy_exit(struct phy *phy)
195 {
196         int ret;
197
198         if (!phy)
199                 return 0;
200
201         ret = phy_pm_runtime_get_sync(phy);
202         if (ret < 0 && ret != -ENOTSUPP)
203                 return ret;
204
205         mutex_lock(&phy->mutex);
206         if (phy->init_count == 1 && phy->ops->exit) {
207                 ret = phy->ops->exit(phy);
208                 if (ret < 0) {
209                         dev_err(&phy->dev, "phy exit failed --> %d\n", ret);
210                         goto out;
211                 }
212         }
213         --phy->init_count;
214
215 out:
216         mutex_unlock(&phy->mutex);
217         phy_pm_runtime_put(phy);
218         return ret;
219 }
220 EXPORT_SYMBOL_GPL(phy_exit);
221
222 int phy_power_on(struct phy *phy)
223 {
224         int ret;
225
226         if (!phy)
227                 return 0;
228
229         ret = phy_pm_runtime_get_sync(phy);
230         if (ret < 0 && ret != -ENOTSUPP)
231                 return ret;
232
233         mutex_lock(&phy->mutex);
234         if (phy->power_count == 0 && phy->ops->power_on) {
235                 ret = phy->ops->power_on(phy);
236                 if (ret < 0) {
237                         dev_err(&phy->dev, "phy poweron failed --> %d\n", ret);
238                         goto out;
239                 }
240         } else {
241                 ret = 0; /* Override possible ret == -ENOTSUPP */
242         }
243         ++phy->power_count;
244         mutex_unlock(&phy->mutex);
245         return 0;
246
247 out:
248         mutex_unlock(&phy->mutex);
249         phy_pm_runtime_put_sync(phy);
250
251         return ret;
252 }
253 EXPORT_SYMBOL_GPL(phy_power_on);
254
255 int phy_power_off(struct phy *phy)
256 {
257         int ret;
258
259         if (!phy)
260                 return 0;
261
262         mutex_lock(&phy->mutex);
263         if (phy->power_count == 1 && phy->ops->power_off) {
264                 ret =  phy->ops->power_off(phy);
265                 if (ret < 0) {
266                         dev_err(&phy->dev, "phy poweroff failed --> %d\n", ret);
267                         mutex_unlock(&phy->mutex);
268                         return ret;
269                 }
270         }
271         --phy->power_count;
272         mutex_unlock(&phy->mutex);
273         phy_pm_runtime_put(phy);
274
275         return 0;
276 }
277 EXPORT_SYMBOL_GPL(phy_power_off);
278
279 /**
280  * of_phy_get() - lookup and obtain a reference to a phy by phandle
281  * @dev: device that requests this phy
282  * @index: the index of the phy
283  *
284  * Returns the phy associated with the given phandle value,
285  * after getting a refcount to it or -ENODEV if there is no such phy or
286  * -EPROBE_DEFER if there is a phandle to the phy, but the device is
287  * not yet loaded. This function uses of_xlate call back function provided
288  * while registering the phy_provider to find the phy instance.
289  */
290 static struct phy *of_phy_get(struct device *dev, int index)
291 {
292         int ret;
293         struct phy_provider *phy_provider;
294         struct phy *phy = NULL;
295         struct of_phandle_args args;
296
297         ret = of_parse_phandle_with_args(dev->of_node, "phys", "#phy-cells",
298                 index, &args);
299         if (ret) {
300                 dev_dbg(dev, "failed to get phy in %s node\n",
301                         dev->of_node->full_name);
302                 return ERR_PTR(-ENODEV);
303         }
304
305         mutex_lock(&phy_provider_mutex);
306         phy_provider = of_phy_provider_lookup(args.np);
307         if (IS_ERR(phy_provider) || !try_module_get(phy_provider->owner)) {
308                 phy = ERR_PTR(-EPROBE_DEFER);
309                 goto err0;
310         }
311
312         phy = phy_provider->of_xlate(phy_provider->dev, &args);
313         module_put(phy_provider->owner);
314
315 err0:
316         mutex_unlock(&phy_provider_mutex);
317         of_node_put(args.np);
318
319         return phy;
320 }
321
322 /**
323  * phy_put() - release the PHY
324  * @phy: the phy returned by phy_get()
325  *
326  * Releases a refcount the caller received from phy_get().
327  */
328 void phy_put(struct phy *phy)
329 {
330         if (!phy || IS_ERR(phy))
331                 return;
332
333         module_put(phy->ops->owner);
334         put_device(&phy->dev);
335 }
336 EXPORT_SYMBOL_GPL(phy_put);
337
338 /**
339  * devm_phy_put() - release the PHY
340  * @dev: device that wants to release this phy
341  * @phy: the phy returned by devm_phy_get()
342  *
343  * destroys the devres associated with this phy and invokes phy_put
344  * to release the phy.
345  */
346 void devm_phy_put(struct device *dev, struct phy *phy)
347 {
348         int r;
349
350         if (!phy)
351                 return;
352
353         r = devres_destroy(dev, devm_phy_release, devm_phy_match, phy);
354         dev_WARN_ONCE(dev, r, "couldn't find PHY resource\n");
355 }
356 EXPORT_SYMBOL_GPL(devm_phy_put);
357
358 /**
359  * of_phy_simple_xlate() - returns the phy instance from phy provider
360  * @dev: the PHY provider device
361  * @args: of_phandle_args (not used here)
362  *
363  * Intended to be used by phy provider for the common case where #phy-cells is
364  * 0. For other cases where #phy-cells is greater than '0', the phy provider
365  * should provide a custom of_xlate function that reads the *args* and returns
366  * the appropriate phy.
367  */
368 struct phy *of_phy_simple_xlate(struct device *dev, struct of_phandle_args
369         *args)
370 {
371         struct phy *phy;
372         struct class_dev_iter iter;
373         struct device_node *node = dev->of_node;
374         struct device_node *child;
375
376         class_dev_iter_init(&iter, phy_class, NULL, NULL);
377         while ((dev = class_dev_iter_next(&iter))) {
378                 phy = to_phy(dev);
379                 if (node != phy->dev.of_node) {
380                         for_each_child_of_node(node, child) {
381                                 if (child == phy->dev.of_node)
382                                         goto phy_found;
383                         }
384                         continue;
385                 }
386
387 phy_found:
388                 class_dev_iter_exit(&iter);
389                 return phy;
390         }
391
392         class_dev_iter_exit(&iter);
393         return ERR_PTR(-ENODEV);
394 }
395 EXPORT_SYMBOL_GPL(of_phy_simple_xlate);
396
397 /**
398  * phy_get() - lookup and obtain a reference to a phy.
399  * @dev: device that requests this phy
400  * @string: the phy name as given in the dt data or the name of the controller
401  * port for non-dt case
402  *
403  * Returns the phy driver, after getting a refcount to it; or
404  * -ENODEV if there is no such phy.  The caller is responsible for
405  * calling phy_put() to release that count.
406  */
407 struct phy *phy_get(struct device *dev, const char *string)
408 {
409         int index = 0;
410         struct phy *phy;
411
412         if (string == NULL) {
413                 dev_WARN(dev, "missing string\n");
414                 return ERR_PTR(-EINVAL);
415         }
416
417         if (dev->of_node) {
418                 index = of_property_match_string(dev->of_node, "phy-names",
419                         string);
420                 phy = of_phy_get(dev, index);
421         } else {
422                 phy = phy_lookup(dev, string);
423         }
424         if (IS_ERR(phy))
425                 return phy;
426
427         if (!try_module_get(phy->ops->owner))
428                 return ERR_PTR(-EPROBE_DEFER);
429
430         get_device(&phy->dev);
431
432         return phy;
433 }
434 EXPORT_SYMBOL_GPL(phy_get);
435
436 /**
437  * phy_optional_get() - lookup and obtain a reference to an optional phy.
438  * @dev: device that requests this phy
439  * @string: the phy name as given in the dt data or the name of the controller
440  * port for non-dt case
441  *
442  * Returns the phy driver, after getting a refcount to it; or
443  * NULL if there is no such phy.  The caller is responsible for
444  * calling phy_put() to release that count.
445  */
446 struct phy *phy_optional_get(struct device *dev, const char *string)
447 {
448         struct phy *phy = phy_get(dev, string);
449
450         if (PTR_ERR(phy) == -ENODEV)
451                 phy = NULL;
452
453         return phy;
454 }
455 EXPORT_SYMBOL_GPL(phy_optional_get);
456
457 /**
458  * devm_phy_get() - lookup and obtain a reference to a phy.
459  * @dev: device that requests this phy
460  * @string: the phy name as given in the dt data or phy device name
461  * for non-dt case
462  *
463  * Gets the phy using phy_get(), and associates a device with it using
464  * devres. On driver detach, release function is invoked on the devres data,
465  * then, devres data is freed.
466  */
467 struct phy *devm_phy_get(struct device *dev, const char *string)
468 {
469         struct phy **ptr, *phy;
470
471         ptr = devres_alloc(devm_phy_release, sizeof(*ptr), GFP_KERNEL);
472         if (!ptr)
473                 return ERR_PTR(-ENOMEM);
474
475         phy = phy_get(dev, string);
476         if (!IS_ERR(phy)) {
477                 *ptr = phy;
478                 devres_add(dev, ptr);
479         } else {
480                 devres_free(ptr);
481         }
482
483         return phy;
484 }
485 EXPORT_SYMBOL_GPL(devm_phy_get);
486
487 /**
488  * devm_phy_optional_get() - lookup and obtain a reference to an optional phy.
489  * @dev: device that requests this phy
490  * @string: the phy name as given in the dt data or phy device name
491  * for non-dt case
492  *
493  * Gets the phy using phy_get(), and associates a device with it using
494  * devres. On driver detach, release function is invoked on the devres
495  * data, then, devres data is freed. This differs to devm_phy_get() in
496  * that if the phy does not exist, it is not considered an error and
497  * -ENODEV will not be returned. Instead the NULL phy is returned,
498  * which can be passed to all other phy consumer calls.
499  */
500 struct phy *devm_phy_optional_get(struct device *dev, const char *string)
501 {
502         struct phy *phy = devm_phy_get(dev, string);
503
504         if (PTR_ERR(phy) == -ENODEV)
505                 phy = NULL;
506
507         return phy;
508 }
509 EXPORT_SYMBOL_GPL(devm_phy_optional_get);
510
511 /**
512  * phy_create() - create a new phy
513  * @dev: device that is creating the new phy
514  * @node: device node of the phy
515  * @ops: function pointers for performing phy operations
516  * @init_data: contains the list of PHY consumers or NULL
517  *
518  * Called to create a phy using phy framework.
519  */
520 struct phy *phy_create(struct device *dev, struct device_node *node,
521                        const struct phy_ops *ops,
522                        struct phy_init_data *init_data)
523 {
524         int ret;
525         int id;
526         struct phy *phy;
527
528         if (WARN_ON(!dev))
529                 return ERR_PTR(-EINVAL);
530
531         phy = kzalloc(sizeof(*phy), GFP_KERNEL);
532         if (!phy)
533                 return ERR_PTR(-ENOMEM);
534
535         id = ida_simple_get(&phy_ida, 0, 0, GFP_KERNEL);
536         if (id < 0) {
537                 dev_err(dev, "unable to get id\n");
538                 ret = id;
539                 goto free_phy;
540         }
541
542         device_initialize(&phy->dev);
543         mutex_init(&phy->mutex);
544
545         phy->dev.class = phy_class;
546         phy->dev.parent = dev;
547         phy->dev.of_node = node ?: dev->of_node;
548         phy->id = id;
549         phy->ops = ops;
550         phy->init_data = init_data;
551
552         ret = dev_set_name(&phy->dev, "phy-%s.%d", dev_name(dev), id);
553         if (ret)
554                 goto put_dev;
555
556         ret = device_add(&phy->dev);
557         if (ret)
558                 goto put_dev;
559
560         if (pm_runtime_enabled(dev)) {
561                 pm_runtime_enable(&phy->dev);
562                 pm_runtime_no_callbacks(&phy->dev);
563         }
564
565         return phy;
566
567 put_dev:
568         put_device(&phy->dev);  /* calls phy_release() which frees resources */
569         return ERR_PTR(ret);
570
571 free_phy:
572         kfree(phy);
573         return ERR_PTR(ret);
574 }
575 EXPORT_SYMBOL_GPL(phy_create);
576
577 /**
578  * devm_phy_create() - create a new phy
579  * @dev: device that is creating the new phy
580  * @node: device node of the phy
581  * @ops: function pointers for performing phy operations
582  * @init_data: contains the list of PHY consumers or NULL
583  *
584  * Creates a new PHY device adding it to the PHY class.
585  * While at that, it also associates the device with the phy using devres.
586  * On driver detach, release function is invoked on the devres data,
587  * then, devres data is freed.
588  */
589 struct phy *devm_phy_create(struct device *dev, struct device_node *node,
590                             const struct phy_ops *ops,
591                             struct phy_init_data *init_data)
592 {
593         struct phy **ptr, *phy;
594
595         ptr = devres_alloc(devm_phy_consume, sizeof(*ptr), GFP_KERNEL);
596         if (!ptr)
597                 return ERR_PTR(-ENOMEM);
598
599         phy = phy_create(dev, node, ops, init_data);
600         if (!IS_ERR(phy)) {
601                 *ptr = phy;
602                 devres_add(dev, ptr);
603         } else {
604                 devres_free(ptr);
605         }
606
607         return phy;
608 }
609 EXPORT_SYMBOL_GPL(devm_phy_create);
610
611 /**
612  * phy_destroy() - destroy the phy
613  * @phy: the phy to be destroyed
614  *
615  * Called to destroy the phy.
616  */
617 void phy_destroy(struct phy *phy)
618 {
619         pm_runtime_disable(&phy->dev);
620         device_unregister(&phy->dev);
621 }
622 EXPORT_SYMBOL_GPL(phy_destroy);
623
624 /**
625  * devm_phy_destroy() - destroy the PHY
626  * @dev: device that wants to release this phy
627  * @phy: the phy returned by devm_phy_get()
628  *
629  * destroys the devres associated with this phy and invokes phy_destroy
630  * to destroy the phy.
631  */
632 void devm_phy_destroy(struct device *dev, struct phy *phy)
633 {
634         int r;
635
636         r = devres_destroy(dev, devm_phy_consume, devm_phy_match, phy);
637         dev_WARN_ONCE(dev, r, "couldn't find PHY resource\n");
638 }
639 EXPORT_SYMBOL_GPL(devm_phy_destroy);
640
641 /**
642  * __of_phy_provider_register() - create/register phy provider with the framework
643  * @dev: struct device of the phy provider
644  * @owner: the module owner containing of_xlate
645  * @of_xlate: function pointer to obtain phy instance from phy provider
646  *
647  * Creates struct phy_provider from dev and of_xlate function pointer.
648  * This is used in the case of dt boot for finding the phy instance from
649  * phy provider.
650  */
651 struct phy_provider *__of_phy_provider_register(struct device *dev,
652         struct module *owner, struct phy * (*of_xlate)(struct device *dev,
653         struct of_phandle_args *args))
654 {
655         struct phy_provider *phy_provider;
656
657         phy_provider = kzalloc(sizeof(*phy_provider), GFP_KERNEL);
658         if (!phy_provider)
659                 return ERR_PTR(-ENOMEM);
660
661         phy_provider->dev = dev;
662         phy_provider->owner = owner;
663         phy_provider->of_xlate = of_xlate;
664
665         mutex_lock(&phy_provider_mutex);
666         list_add_tail(&phy_provider->list, &phy_provider_list);
667         mutex_unlock(&phy_provider_mutex);
668
669         return phy_provider;
670 }
671 EXPORT_SYMBOL_GPL(__of_phy_provider_register);
672
673 /**
674  * __devm_of_phy_provider_register() - create/register phy provider with the
675  * framework
676  * @dev: struct device of the phy provider
677  * @owner: the module owner containing of_xlate
678  * @of_xlate: function pointer to obtain phy instance from phy provider
679  *
680  * Creates struct phy_provider from dev and of_xlate function pointer.
681  * This is used in the case of dt boot for finding the phy instance from
682  * phy provider. While at that, it also associates the device with the
683  * phy provider using devres. On driver detach, release function is invoked
684  * on the devres data, then, devres data is freed.
685  */
686 struct phy_provider *__devm_of_phy_provider_register(struct device *dev,
687         struct module *owner, struct phy * (*of_xlate)(struct device *dev,
688         struct of_phandle_args *args))
689 {
690         struct phy_provider **ptr, *phy_provider;
691
692         ptr = devres_alloc(devm_phy_provider_release, sizeof(*ptr), GFP_KERNEL);
693         if (!ptr)
694                 return ERR_PTR(-ENOMEM);
695
696         phy_provider = __of_phy_provider_register(dev, owner, of_xlate);
697         if (!IS_ERR(phy_provider)) {
698                 *ptr = phy_provider;
699                 devres_add(dev, ptr);
700         } else {
701                 devres_free(ptr);
702         }
703
704         return phy_provider;
705 }
706 EXPORT_SYMBOL_GPL(__devm_of_phy_provider_register);
707
708 /**
709  * of_phy_provider_unregister() - unregister phy provider from the framework
710  * @phy_provider: phy provider returned by of_phy_provider_register()
711  *
712  * Removes the phy_provider created using of_phy_provider_register().
713  */
714 void of_phy_provider_unregister(struct phy_provider *phy_provider)
715 {
716         if (IS_ERR(phy_provider))
717                 return;
718
719         mutex_lock(&phy_provider_mutex);
720         list_del(&phy_provider->list);
721         kfree(phy_provider);
722         mutex_unlock(&phy_provider_mutex);
723 }
724 EXPORT_SYMBOL_GPL(of_phy_provider_unregister);
725
726 /**
727  * devm_of_phy_provider_unregister() - remove phy provider from the framework
728  * @dev: struct device of the phy provider
729  *
730  * destroys the devres associated with this phy provider and invokes
731  * of_phy_provider_unregister to unregister the phy provider.
732  */
733 void devm_of_phy_provider_unregister(struct device *dev,
734         struct phy_provider *phy_provider) {
735         int r;
736
737         r = devres_destroy(dev, devm_phy_provider_release, devm_phy_match,
738                 phy_provider);
739         dev_WARN_ONCE(dev, r, "couldn't find PHY provider device resource\n");
740 }
741 EXPORT_SYMBOL_GPL(devm_of_phy_provider_unregister);
742
743 /**
744  * phy_release() - release the phy
745  * @dev: the dev member within phy
746  *
747  * When the last reference to the device is removed, it is called
748  * from the embedded kobject as release method.
749  */
750 static void phy_release(struct device *dev)
751 {
752         struct phy *phy;
753
754         phy = to_phy(dev);
755         dev_vdbg(dev, "releasing '%s'\n", dev_name(dev));
756         ida_simple_remove(&phy_ida, phy->id);
757         kfree(phy);
758 }
759
760 static int __init phy_core_init(void)
761 {
762         phy_class = class_create(THIS_MODULE, "phy");
763         if (IS_ERR(phy_class)) {
764                 pr_err("failed to create phy class --> %ld\n",
765                         PTR_ERR(phy_class));
766                 return PTR_ERR(phy_class);
767         }
768
769         phy_class->dev_release = phy_release;
770
771         return 0;
772 }
773 module_init(phy_core_init);
774
775 static void __exit phy_core_exit(void)
776 {
777         class_destroy(phy_class);
778 }
779 module_exit(phy_core_exit);
780
781 MODULE_DESCRIPTION("Generic PHY Framework");
782 MODULE_AUTHOR("Kishon Vijay Abraham I <kishon@ti.com>");
783 MODULE_LICENSE("GPL v2");