phy-core.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  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. #include <linux/kernel.h>
  14. #include <linux/export.h>
  15. #include <linux/module.h>
  16. #include <linux/err.h>
  17. #include <linux/device.h>
  18. #include <linux/slab.h>
  19. #include <linux/of.h>
  20. #include <linux/phy/phy.h>
  21. #include <linux/idr.h>
  22. #include <linux/pm_runtime.h>
  23. static struct class *phy_class;
  24. static DEFINE_MUTEX(phy_provider_mutex);
  25. static LIST_HEAD(phy_provider_list);
  26. static DEFINE_IDA(phy_ida);
  27. static void devm_phy_release(struct device *dev, void *res)
  28. {
  29. struct phy *phy = *(struct phy **)res;
  30. phy_put(phy);
  31. }
  32. static void devm_phy_provider_release(struct device *dev, void *res)
  33. {
  34. struct phy_provider *phy_provider = *(struct phy_provider **)res;
  35. of_phy_provider_unregister(phy_provider);
  36. }
  37. static void devm_phy_consume(struct device *dev, void *res)
  38. {
  39. struct phy *phy = *(struct phy **)res;
  40. phy_destroy(phy);
  41. }
  42. static int devm_phy_match(struct device *dev, void *res, void *match_data)
  43. {
  44. return res == match_data;
  45. }
  46. static struct phy *phy_lookup(struct device *device, const char *port)
  47. {
  48. unsigned int count;
  49. struct phy *phy;
  50. struct device *dev;
  51. struct phy_consumer *consumers;
  52. struct class_dev_iter iter;
  53. class_dev_iter_init(&iter, phy_class, NULL, NULL);
  54. while ((dev = class_dev_iter_next(&iter))) {
  55. phy = to_phy(dev);
  56. count = phy->init_data->num_consumers;
  57. consumers = phy->init_data->consumers;
  58. while (count--) {
  59. if (!strcmp(consumers->dev_name, dev_name(device)) &&
  60. !strcmp(consumers->port, port)) {
  61. class_dev_iter_exit(&iter);
  62. return phy;
  63. }
  64. consumers++;
  65. }
  66. }
  67. class_dev_iter_exit(&iter);
  68. return ERR_PTR(-ENODEV);
  69. }
  70. static struct phy_provider *of_phy_provider_lookup(struct device_node *node)
  71. {
  72. struct phy_provider *phy_provider;
  73. list_for_each_entry(phy_provider, &phy_provider_list, list) {
  74. if (phy_provider->dev->of_node == node)
  75. return phy_provider;
  76. }
  77. return ERR_PTR(-EPROBE_DEFER);
  78. }
  79. int phy_pm_runtime_get(struct phy *phy)
  80. {
  81. int ret;
  82. if (!pm_runtime_enabled(&phy->dev))
  83. return -ENOTSUPP;
  84. ret = pm_runtime_get(&phy->dev);
  85. if (ret < 0 && ret != -EINPROGRESS)
  86. pm_runtime_put_noidle(&phy->dev);
  87. return ret;
  88. }
  89. EXPORT_SYMBOL_GPL(phy_pm_runtime_get);
  90. int phy_pm_runtime_get_sync(struct phy *phy)
  91. {
  92. int ret;
  93. if (!pm_runtime_enabled(&phy->dev))
  94. return -ENOTSUPP;
  95. ret = pm_runtime_get_sync(&phy->dev);
  96. if (ret < 0)
  97. pm_runtime_put_sync(&phy->dev);
  98. return ret;
  99. }
  100. EXPORT_SYMBOL_GPL(phy_pm_runtime_get_sync);
  101. int phy_pm_runtime_put(struct phy *phy)
  102. {
  103. if (!pm_runtime_enabled(&phy->dev))
  104. return -ENOTSUPP;
  105. return pm_runtime_put(&phy->dev);
  106. }
  107. EXPORT_SYMBOL_GPL(phy_pm_runtime_put);
  108. int phy_pm_runtime_put_sync(struct phy *phy)
  109. {
  110. if (!pm_runtime_enabled(&phy->dev))
  111. return -ENOTSUPP;
  112. return pm_runtime_put_sync(&phy->dev);
  113. }
  114. EXPORT_SYMBOL_GPL(phy_pm_runtime_put_sync);
  115. void phy_pm_runtime_allow(struct phy *phy)
  116. {
  117. if (!pm_runtime_enabled(&phy->dev))
  118. return;
  119. pm_runtime_allow(&phy->dev);
  120. }
  121. EXPORT_SYMBOL_GPL(phy_pm_runtime_allow);
  122. void phy_pm_runtime_forbid(struct phy *phy)
  123. {
  124. if (!pm_runtime_enabled(&phy->dev))
  125. return;
  126. pm_runtime_forbid(&phy->dev);
  127. }
  128. EXPORT_SYMBOL_GPL(phy_pm_runtime_forbid);
  129. int phy_init(struct phy *phy)
  130. {
  131. int ret;
  132. ret = phy_pm_runtime_get_sync(phy);
  133. if (ret < 0 && ret != -ENOTSUPP)
  134. return ret;
  135. mutex_lock(&phy->mutex);
  136. if (phy->init_count == 0 && phy->ops->init) {
  137. ret = phy->ops->init(phy);
  138. if (ret < 0) {
  139. dev_err(&phy->dev, "phy init failed --> %d\n", ret);
  140. goto out;
  141. }
  142. }
  143. ++phy->init_count;
  144. out:
  145. mutex_unlock(&phy->mutex);
  146. phy_pm_runtime_put(phy);
  147. return ret;
  148. }
  149. EXPORT_SYMBOL_GPL(phy_init);
  150. int phy_exit(struct phy *phy)
  151. {
  152. int ret;
  153. ret = phy_pm_runtime_get_sync(phy);
  154. if (ret < 0 && ret != -ENOTSUPP)
  155. return ret;
  156. mutex_lock(&phy->mutex);
  157. if (phy->init_count == 1 && phy->ops->exit) {
  158. ret = phy->ops->exit(phy);
  159. if (ret < 0) {
  160. dev_err(&phy->dev, "phy exit failed --> %d\n", ret);
  161. goto out;
  162. }
  163. }
  164. --phy->init_count;
  165. out:
  166. mutex_unlock(&phy->mutex);
  167. phy_pm_runtime_put(phy);
  168. return ret;
  169. }
  170. EXPORT_SYMBOL_GPL(phy_exit);
  171. int phy_power_on(struct phy *phy)
  172. {
  173. int ret;
  174. ret = phy_pm_runtime_get_sync(phy);
  175. if (ret < 0 && ret != -ENOTSUPP)
  176. return ret;
  177. mutex_lock(&phy->mutex);
  178. if (phy->power_count == 0 && phy->ops->power_on) {
  179. ret = phy->ops->power_on(phy);
  180. if (ret < 0) {
  181. dev_err(&phy->dev, "phy poweron failed --> %d\n", ret);
  182. goto out;
  183. }
  184. }
  185. ++phy->power_count;
  186. mutex_unlock(&phy->mutex);
  187. return 0;
  188. out:
  189. mutex_unlock(&phy->mutex);
  190. phy_pm_runtime_put_sync(phy);
  191. return ret;
  192. }
  193. EXPORT_SYMBOL_GPL(phy_power_on);
  194. int phy_power_off(struct phy *phy)
  195. {
  196. int ret;
  197. mutex_lock(&phy->mutex);
  198. if (phy->power_count == 1 && phy->ops->power_off) {
  199. ret = phy->ops->power_off(phy);
  200. if (ret < 0) {
  201. dev_err(&phy->dev, "phy poweroff failed --> %d\n", ret);
  202. mutex_unlock(&phy->mutex);
  203. return ret;
  204. }
  205. }
  206. --phy->power_count;
  207. mutex_unlock(&phy->mutex);
  208. phy_pm_runtime_put(phy);
  209. return 0;
  210. }
  211. EXPORT_SYMBOL_GPL(phy_power_off);
  212. /**
  213. * of_phy_get() - lookup and obtain a reference to a phy by phandle
  214. * @dev: device that requests this phy
  215. * @index: the index of the phy
  216. *
  217. * Returns the phy associated with the given phandle value,
  218. * after getting a refcount to it or -ENODEV if there is no such phy or
  219. * -EPROBE_DEFER if there is a phandle to the phy, but the device is
  220. * not yet loaded. This function uses of_xlate call back function provided
  221. * while registering the phy_provider to find the phy instance.
  222. */
  223. static struct phy *of_phy_get(struct device *dev, int index)
  224. {
  225. int ret;
  226. struct phy_provider *phy_provider;
  227. struct phy *phy = NULL;
  228. struct of_phandle_args args;
  229. ret = of_parse_phandle_with_args(dev->of_node, "phys", "#phy-cells",
  230. index, &args);
  231. if (ret) {
  232. dev_dbg(dev, "failed to get phy in %s node\n",
  233. dev->of_node->full_name);
  234. return ERR_PTR(-ENODEV);
  235. }
  236. mutex_lock(&phy_provider_mutex);
  237. phy_provider = of_phy_provider_lookup(args.np);
  238. if (IS_ERR(phy_provider) || !try_module_get(phy_provider->owner)) {
  239. phy = ERR_PTR(-EPROBE_DEFER);
  240. goto err0;
  241. }
  242. phy = phy_provider->of_xlate(phy_provider->dev, &args);
  243. module_put(phy_provider->owner);
  244. err0:
  245. mutex_unlock(&phy_provider_mutex);
  246. of_node_put(args.np);
  247. return phy;
  248. }
  249. /**
  250. * phy_put() - release the PHY
  251. * @phy: the phy returned by phy_get()
  252. *
  253. * Releases a refcount the caller received from phy_get().
  254. */
  255. void phy_put(struct phy *phy)
  256. {
  257. if (IS_ERR(phy))
  258. return;
  259. module_put(phy->ops->owner);
  260. put_device(&phy->dev);
  261. }
  262. EXPORT_SYMBOL_GPL(phy_put);
  263. /**
  264. * devm_phy_put() - release the PHY
  265. * @dev: device that wants to release this phy
  266. * @phy: the phy returned by devm_phy_get()
  267. *
  268. * destroys the devres associated with this phy and invokes phy_put
  269. * to release the phy.
  270. */
  271. void devm_phy_put(struct device *dev, struct phy *phy)
  272. {
  273. int r;
  274. r = devres_destroy(dev, devm_phy_release, devm_phy_match, phy);
  275. dev_WARN_ONCE(dev, r, "couldn't find PHY resource\n");
  276. }
  277. EXPORT_SYMBOL_GPL(devm_phy_put);
  278. /**
  279. * of_phy_simple_xlate() - returns the phy instance from phy provider
  280. * @dev: the PHY provider device
  281. * @args: of_phandle_args (not used here)
  282. *
  283. * Intended to be used by phy provider for the common case where #phy-cells is
  284. * 0. For other cases where #phy-cells is greater than '0', the phy provider
  285. * should provide a custom of_xlate function that reads the *args* and returns
  286. * the appropriate phy.
  287. */
  288. struct phy *of_phy_simple_xlate(struct device *dev, struct of_phandle_args
  289. *args)
  290. {
  291. struct phy *phy;
  292. struct class_dev_iter iter;
  293. struct device_node *node = dev->of_node;
  294. class_dev_iter_init(&iter, phy_class, NULL, NULL);
  295. while ((dev = class_dev_iter_next(&iter))) {
  296. phy = to_phy(dev);
  297. if (node != phy->dev.of_node)
  298. continue;
  299. class_dev_iter_exit(&iter);
  300. return phy;
  301. }
  302. class_dev_iter_exit(&iter);
  303. return ERR_PTR(-ENODEV);
  304. }
  305. EXPORT_SYMBOL_GPL(of_phy_simple_xlate);
  306. /**
  307. * phy_get() - lookup and obtain a reference to a phy.
  308. * @dev: device that requests this phy
  309. * @string: the phy name as given in the dt data or the name of the controller
  310. * port for non-dt case
  311. *
  312. * Returns the phy driver, after getting a refcount to it; or
  313. * -ENODEV if there is no such phy. The caller is responsible for
  314. * calling phy_put() to release that count.
  315. */
  316. struct phy *phy_get(struct device *dev, const char *string)
  317. {
  318. int index = 0;
  319. struct phy *phy;
  320. if (string == NULL) {
  321. dev_WARN(dev, "missing string\n");
  322. return ERR_PTR(-EINVAL);
  323. }
  324. if (dev->of_node) {
  325. index = of_property_match_string(dev->of_node, "phy-names",
  326. string);
  327. phy = of_phy_get(dev, index);
  328. if (IS_ERR(phy)) {
  329. dev_err(dev, "unable to find phy\n");
  330. return phy;
  331. }
  332. } else {
  333. phy = phy_lookup(dev, string);
  334. if (IS_ERR(phy)) {
  335. dev_err(dev, "unable to find phy\n");
  336. return phy;
  337. }
  338. }
  339. if (!try_module_get(phy->ops->owner))
  340. return ERR_PTR(-EPROBE_DEFER);
  341. get_device(&phy->dev);
  342. return phy;
  343. }
  344. EXPORT_SYMBOL_GPL(phy_get);
  345. /**
  346. * devm_phy_get() - lookup and obtain a reference to a phy.
  347. * @dev: device that requests this phy
  348. * @string: the phy name as given in the dt data or phy device name
  349. * for non-dt case
  350. *
  351. * Gets the phy using phy_get(), and associates a device with it using
  352. * devres. On driver detach, release function is invoked on the devres data,
  353. * then, devres data is freed.
  354. */
  355. struct phy *devm_phy_get(struct device *dev, const char *string)
  356. {
  357. struct phy **ptr, *phy;
  358. ptr = devres_alloc(devm_phy_release, sizeof(*ptr), GFP_KERNEL);
  359. if (!ptr)
  360. return ERR_PTR(-ENOMEM);
  361. phy = phy_get(dev, string);
  362. if (!IS_ERR(phy)) {
  363. *ptr = phy;
  364. devres_add(dev, ptr);
  365. } else {
  366. devres_free(ptr);
  367. }
  368. return phy;
  369. }
  370. EXPORT_SYMBOL_GPL(devm_phy_get);
  371. /**
  372. * phy_create() - create a new phy
  373. * @dev: device that is creating the new phy
  374. * @ops: function pointers for performing phy operations
  375. * @init_data: contains the list of PHY consumers or NULL
  376. *
  377. * Called to create a phy using phy framework.
  378. */
  379. struct phy *phy_create(struct device *dev, const struct phy_ops *ops,
  380. struct phy_init_data *init_data)
  381. {
  382. int ret;
  383. int id;
  384. struct phy *phy;
  385. if (WARN_ON(!dev))
  386. return ERR_PTR(-EINVAL);
  387. phy = kzalloc(sizeof(*phy), GFP_KERNEL);
  388. if (!phy)
  389. return ERR_PTR(-ENOMEM);
  390. id = ida_simple_get(&phy_ida, 0, 0, GFP_KERNEL);
  391. if (id < 0) {
  392. dev_err(dev, "unable to get id\n");
  393. ret = id;
  394. goto free_phy;
  395. }
  396. device_initialize(&phy->dev);
  397. mutex_init(&phy->mutex);
  398. phy->dev.class = phy_class;
  399. phy->dev.parent = dev;
  400. phy->dev.of_node = dev->of_node;
  401. phy->id = id;
  402. phy->ops = ops;
  403. phy->init_data = init_data;
  404. ret = dev_set_name(&phy->dev, "phy-%s.%d", dev_name(dev), id);
  405. if (ret)
  406. goto put_dev;
  407. ret = device_add(&phy->dev);
  408. if (ret)
  409. goto put_dev;
  410. if (pm_runtime_enabled(dev)) {
  411. pm_runtime_enable(&phy->dev);
  412. pm_runtime_no_callbacks(&phy->dev);
  413. }
  414. return phy;
  415. put_dev:
  416. put_device(&phy->dev);
  417. ida_remove(&phy_ida, phy->id);
  418. free_phy:
  419. kfree(phy);
  420. return ERR_PTR(ret);
  421. }
  422. EXPORT_SYMBOL_GPL(phy_create);
  423. /**
  424. * devm_phy_create() - create a new phy
  425. * @dev: device that is creating the new phy
  426. * @ops: function pointers for performing phy operations
  427. * @init_data: contains the list of PHY consumers or NULL
  428. *
  429. * Creates a new PHY device adding it to the PHY class.
  430. * While at that, it also associates the device with the phy using devres.
  431. * On driver detach, release function is invoked on the devres data,
  432. * then, devres data is freed.
  433. */
  434. struct phy *devm_phy_create(struct device *dev, const struct phy_ops *ops,
  435. struct phy_init_data *init_data)
  436. {
  437. struct phy **ptr, *phy;
  438. ptr = devres_alloc(devm_phy_consume, sizeof(*ptr), GFP_KERNEL);
  439. if (!ptr)
  440. return ERR_PTR(-ENOMEM);
  441. phy = phy_create(dev, ops, init_data);
  442. if (!IS_ERR(phy)) {
  443. *ptr = phy;
  444. devres_add(dev, ptr);
  445. } else {
  446. devres_free(ptr);
  447. }
  448. return phy;
  449. }
  450. EXPORT_SYMBOL_GPL(devm_phy_create);
  451. /**
  452. * phy_destroy() - destroy the phy
  453. * @phy: the phy to be destroyed
  454. *
  455. * Called to destroy the phy.
  456. */
  457. void phy_destroy(struct phy *phy)
  458. {
  459. pm_runtime_disable(&phy->dev);
  460. device_unregister(&phy->dev);
  461. }
  462. EXPORT_SYMBOL_GPL(phy_destroy);
  463. /**
  464. * devm_phy_destroy() - destroy the PHY
  465. * @dev: device that wants to release this phy
  466. * @phy: the phy returned by devm_phy_get()
  467. *
  468. * destroys the devres associated with this phy and invokes phy_destroy
  469. * to destroy the phy.
  470. */
  471. void devm_phy_destroy(struct device *dev, struct phy *phy)
  472. {
  473. int r;
  474. r = devres_destroy(dev, devm_phy_consume, devm_phy_match, phy);
  475. dev_WARN_ONCE(dev, r, "couldn't find PHY resource\n");
  476. }
  477. EXPORT_SYMBOL_GPL(devm_phy_destroy);
  478. /**
  479. * __of_phy_provider_register() - create/register phy provider with the framework
  480. * @dev: struct device of the phy provider
  481. * @owner: the module owner containing of_xlate
  482. * @of_xlate: function pointer to obtain phy instance from phy provider
  483. *
  484. * Creates struct phy_provider from dev and of_xlate function pointer.
  485. * This is used in the case of dt boot for finding the phy instance from
  486. * phy provider.
  487. */
  488. struct phy_provider *__of_phy_provider_register(struct device *dev,
  489. struct module *owner, struct phy * (*of_xlate)(struct device *dev,
  490. struct of_phandle_args *args))
  491. {
  492. struct phy_provider *phy_provider;
  493. phy_provider = kzalloc(sizeof(*phy_provider), GFP_KERNEL);
  494. if (!phy_provider)
  495. return ERR_PTR(-ENOMEM);
  496. phy_provider->dev = dev;
  497. phy_provider->owner = owner;
  498. phy_provider->of_xlate = of_xlate;
  499. mutex_lock(&phy_provider_mutex);
  500. list_add_tail(&phy_provider->list, &phy_provider_list);
  501. mutex_unlock(&phy_provider_mutex);
  502. return phy_provider;
  503. }
  504. EXPORT_SYMBOL_GPL(__of_phy_provider_register);
  505. /**
  506. * __devm_of_phy_provider_register() - create/register phy provider with the
  507. * framework
  508. * @dev: struct device of the phy provider
  509. * @owner: the module owner containing of_xlate
  510. * @of_xlate: function pointer to obtain phy instance from phy provider
  511. *
  512. * Creates struct phy_provider from dev and of_xlate function pointer.
  513. * This is used in the case of dt boot for finding the phy instance from
  514. * phy provider. While at that, it also associates the device with the
  515. * phy provider using devres. On driver detach, release function is invoked
  516. * on the devres data, then, devres data is freed.
  517. */
  518. struct phy_provider *__devm_of_phy_provider_register(struct device *dev,
  519. struct module *owner, struct phy * (*of_xlate)(struct device *dev,
  520. struct of_phandle_args *args))
  521. {
  522. struct phy_provider **ptr, *phy_provider;
  523. ptr = devres_alloc(devm_phy_provider_release, sizeof(*ptr), GFP_KERNEL);
  524. if (!ptr)
  525. return ERR_PTR(-ENOMEM);
  526. phy_provider = __of_phy_provider_register(dev, owner, of_xlate);
  527. if (!IS_ERR(phy_provider)) {
  528. *ptr = phy_provider;
  529. devres_add(dev, ptr);
  530. } else {
  531. devres_free(ptr);
  532. }
  533. return phy_provider;
  534. }
  535. EXPORT_SYMBOL_GPL(__devm_of_phy_provider_register);
  536. /**
  537. * of_phy_provider_unregister() - unregister phy provider from the framework
  538. * @phy_provider: phy provider returned by of_phy_provider_register()
  539. *
  540. * Removes the phy_provider created using of_phy_provider_register().
  541. */
  542. void of_phy_provider_unregister(struct phy_provider *phy_provider)
  543. {
  544. if (IS_ERR(phy_provider))
  545. return;
  546. mutex_lock(&phy_provider_mutex);
  547. list_del(&phy_provider->list);
  548. kfree(phy_provider);
  549. mutex_unlock(&phy_provider_mutex);
  550. }
  551. EXPORT_SYMBOL_GPL(of_phy_provider_unregister);
  552. /**
  553. * devm_of_phy_provider_unregister() - remove phy provider from the framework
  554. * @dev: struct device of the phy provider
  555. *
  556. * destroys the devres associated with this phy provider and invokes
  557. * of_phy_provider_unregister to unregister the phy provider.
  558. */
  559. void devm_of_phy_provider_unregister(struct device *dev,
  560. struct phy_provider *phy_provider) {
  561. int r;
  562. r = devres_destroy(dev, devm_phy_provider_release, devm_phy_match,
  563. phy_provider);
  564. dev_WARN_ONCE(dev, r, "couldn't find PHY provider device resource\n");
  565. }
  566. EXPORT_SYMBOL_GPL(devm_of_phy_provider_unregister);
  567. /**
  568. * phy_release() - release the phy
  569. * @dev: the dev member within phy
  570. *
  571. * When the last reference to the device is removed, it is called
  572. * from the embedded kobject as release method.
  573. */
  574. static void phy_release(struct device *dev)
  575. {
  576. struct phy *phy;
  577. phy = to_phy(dev);
  578. dev_vdbg(dev, "releasing '%s'\n", dev_name(dev));
  579. ida_remove(&phy_ida, phy->id);
  580. kfree(phy);
  581. }
  582. static int __init phy_core_init(void)
  583. {
  584. phy_class = class_create(THIS_MODULE, "phy");
  585. if (IS_ERR(phy_class)) {
  586. pr_err("failed to create phy class --> %ld\n",
  587. PTR_ERR(phy_class));
  588. return PTR_ERR(phy_class);
  589. }
  590. phy_class->dev_release = phy_release;
  591. return 0;
  592. }
  593. module_init(phy_core_init);
  594. static void __exit phy_core_exit(void)
  595. {
  596. class_destroy(phy_class);
  597. }
  598. module_exit(phy_core_exit);
  599. MODULE_DESCRIPTION("Generic PHY Framework");
  600. MODULE_AUTHOR("Kishon Vijay Abraham I <kishon@ti.com>");
  601. MODULE_LICENSE("GPL v2");