Lines Matching +full:phy +full:- +full:device

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * phy-core.c -- Generic Phy framework.
5 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com
15 #include <linux/device.h>
18 #include <linux/phy/phy.h>
23 static void phy_release(struct device *dev);
25 .name = "phy",
35 static void devm_phy_release(struct device *dev, void *res) in devm_phy_release()
37 struct phy *phy = *(struct phy **)res; in devm_phy_release() local
39 phy_put(dev, phy); in devm_phy_release()
42 static void devm_phy_provider_release(struct device *dev, void *res) in devm_phy_provider_release()
49 static void devm_phy_consume(struct device *dev, void *res) in devm_phy_consume()
51 struct phy *phy = *(struct phy **)res; in devm_phy_consume() local
53 phy_destroy(phy); in devm_phy_consume()
56 static int devm_phy_match(struct device *dev, void *res, void *match_data) in devm_phy_match()
58 struct phy **phy = res; in devm_phy_match() local
60 return *phy == match_data; in devm_phy_match()
64 * phy_create_lookup() - allocate and register PHY/device association
65 * @phy: the phy of the association
66 * @con_id: connection ID string on device
67 * @dev_id: the device of the association
71 int phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id) in phy_create_lookup() argument
75 if (!phy || !dev_id || !con_id) in phy_create_lookup()
76 return -EINVAL; in phy_create_lookup()
80 return -ENOMEM; in phy_create_lookup()
82 pl->dev_id = dev_id; in phy_create_lookup()
83 pl->con_id = con_id; in phy_create_lookup()
84 pl->phy = phy; in phy_create_lookup()
87 list_add_tail(&pl->node, &phys); in phy_create_lookup()
95 * phy_remove_lookup() - find and remove PHY/device association
96 * @phy: the phy of the association
97 * @con_id: connection ID string on device
98 * @dev_id: the device of the association
103 void phy_remove_lookup(struct phy *phy, const char *con_id, const char *dev_id) in phy_remove_lookup() argument
107 if (!phy || !dev_id || !con_id) in phy_remove_lookup()
112 if (pl->phy == phy && !strcmp(pl->dev_id, dev_id) && in phy_remove_lookup()
113 !strcmp(pl->con_id, con_id)) { in phy_remove_lookup()
114 list_del(&pl->node); in phy_remove_lookup()
122 static struct phy *phy_find(struct device *dev, const char *con_id) in phy_find()
129 if (!strcmp(p->dev_id, dev_id) && !strcmp(p->con_id, con_id)) { in phy_find()
135 return pl ? pl->phy : ERR_PTR(-ENODEV); in phy_find()
144 if (phy_provider->dev->of_node == node) in of_phy_provider_lookup()
147 for_each_child_of_node(phy_provider->children, child) in of_phy_provider_lookup()
154 return ERR_PTR(-EPROBE_DEFER); in of_phy_provider_lookup()
157 int phy_pm_runtime_get(struct phy *phy) in phy_pm_runtime_get() argument
161 if (!phy) in phy_pm_runtime_get()
164 if (!pm_runtime_enabled(&phy->dev)) in phy_pm_runtime_get()
165 return -ENOTSUPP; in phy_pm_runtime_get()
167 ret = pm_runtime_get(&phy->dev); in phy_pm_runtime_get()
168 if (ret < 0 && ret != -EINPROGRESS) in phy_pm_runtime_get()
169 pm_runtime_put_noidle(&phy->dev); in phy_pm_runtime_get()
175 int phy_pm_runtime_get_sync(struct phy *phy) in phy_pm_runtime_get_sync() argument
179 if (!phy) in phy_pm_runtime_get_sync()
182 if (!pm_runtime_enabled(&phy->dev)) in phy_pm_runtime_get_sync()
183 return -ENOTSUPP; in phy_pm_runtime_get_sync()
185 ret = pm_runtime_get_sync(&phy->dev); in phy_pm_runtime_get_sync()
187 pm_runtime_put_sync(&phy->dev); in phy_pm_runtime_get_sync()
193 int phy_pm_runtime_put(struct phy *phy) in phy_pm_runtime_put() argument
195 if (!phy) in phy_pm_runtime_put()
198 if (!pm_runtime_enabled(&phy->dev)) in phy_pm_runtime_put()
199 return -ENOTSUPP; in phy_pm_runtime_put()
201 return pm_runtime_put(&phy->dev); in phy_pm_runtime_put()
205 int phy_pm_runtime_put_sync(struct phy *phy) in phy_pm_runtime_put_sync() argument
207 if (!phy) in phy_pm_runtime_put_sync()
210 if (!pm_runtime_enabled(&phy->dev)) in phy_pm_runtime_put_sync()
211 return -ENOTSUPP; in phy_pm_runtime_put_sync()
213 return pm_runtime_put_sync(&phy->dev); in phy_pm_runtime_put_sync()
218 * phy_init - phy internal initialization before phy operation
219 * @phy: the phy returned by phy_get()
221 * Used to allow phy's driver to perform phy internal initialization,
223 * is required by the phy to perform the start of operation.
228 int phy_init(struct phy *phy) in phy_init() argument
232 if (!phy) in phy_init()
235 ret = phy_pm_runtime_get_sync(phy); in phy_init()
236 if (ret < 0 && ret != -ENOTSUPP) in phy_init()
238 ret = 0; /* Override possible ret == -ENOTSUPP */ in phy_init()
240 mutex_lock(&phy->mutex); in phy_init()
241 if (phy->power_count > phy->init_count) in phy_init()
242 dev_warn(&phy->dev, "phy_power_on was called before phy_init\n"); in phy_init()
244 if (phy->init_count == 0 && phy->ops->init) { in phy_init()
245 ret = phy->ops->init(phy); in phy_init()
247 dev_err(&phy->dev, "phy init failed --> %d\n", ret); in phy_init()
251 ++phy->init_count; in phy_init()
254 mutex_unlock(&phy->mutex); in phy_init()
255 phy_pm_runtime_put(phy); in phy_init()
261 * phy_exit - Phy internal un-initialization
262 * @phy: the phy returned by phy_get()
268 int phy_exit(struct phy *phy) in phy_exit() argument
272 if (!phy) in phy_exit()
275 ret = phy_pm_runtime_get_sync(phy); in phy_exit()
276 if (ret < 0 && ret != -ENOTSUPP) in phy_exit()
278 ret = 0; /* Override possible ret == -ENOTSUPP */ in phy_exit()
280 mutex_lock(&phy->mutex); in phy_exit()
281 if (phy->init_count == 1 && phy->ops->exit) { in phy_exit()
282 ret = phy->ops->exit(phy); in phy_exit()
284 dev_err(&phy->dev, "phy exit failed --> %d\n", ret); in phy_exit()
288 --phy->init_count; in phy_exit()
291 mutex_unlock(&phy->mutex); in phy_exit()
292 phy_pm_runtime_put(phy); in phy_exit()
298 * phy_power_on - Enable the phy and enter proper operation
299 * @phy: the phy returned by phy_get()
305 int phy_power_on(struct phy *phy) in phy_power_on() argument
309 if (!phy) in phy_power_on()
312 if (phy->pwr) { in phy_power_on()
313 ret = regulator_enable(phy->pwr); in phy_power_on()
318 ret = phy_pm_runtime_get_sync(phy); in phy_power_on()
319 if (ret < 0 && ret != -ENOTSUPP) in phy_power_on()
322 ret = 0; /* Override possible ret == -ENOTSUPP */ in phy_power_on()
324 mutex_lock(&phy->mutex); in phy_power_on()
325 if (phy->power_count == 0 && phy->ops->power_on) { in phy_power_on()
326 ret = phy->ops->power_on(phy); in phy_power_on()
328 dev_err(&phy->dev, "phy poweron failed --> %d\n", ret); in phy_power_on()
332 ++phy->power_count; in phy_power_on()
333 mutex_unlock(&phy->mutex); in phy_power_on()
337 mutex_unlock(&phy->mutex); in phy_power_on()
338 phy_pm_runtime_put_sync(phy); in phy_power_on()
340 if (phy->pwr) in phy_power_on()
341 regulator_disable(phy->pwr); in phy_power_on()
348 * phy_power_off - Disable the phy.
349 * @phy: the phy returned by phy_get()
355 int phy_power_off(struct phy *phy) in phy_power_off() argument
359 if (!phy) in phy_power_off()
362 mutex_lock(&phy->mutex); in phy_power_off()
363 if (phy->power_count == 1 && phy->ops->power_off) { in phy_power_off()
364 ret = phy->ops->power_off(phy); in phy_power_off()
366 dev_err(&phy->dev, "phy poweroff failed --> %d\n", ret); in phy_power_off()
367 mutex_unlock(&phy->mutex); in phy_power_off()
371 --phy->power_count; in phy_power_off()
372 mutex_unlock(&phy->mutex); in phy_power_off()
373 phy_pm_runtime_put(phy); in phy_power_off()
375 if (phy->pwr) in phy_power_off()
376 regulator_disable(phy->pwr); in phy_power_off()
382 int phy_set_mode_ext(struct phy *phy, enum phy_mode mode, int submode) in phy_set_mode_ext() argument
386 if (!phy) in phy_set_mode_ext()
389 mutex_lock(&phy->mutex); in phy_set_mode_ext()
390 if (phy->ops->set_mode) in phy_set_mode_ext()
391 ret = phy->ops->set_mode(phy, mode, submode); in phy_set_mode_ext()
393 phy->attrs.mode = mode; in phy_set_mode_ext()
394 mutex_unlock(&phy->mutex); in phy_set_mode_ext()
400 int phy_set_media(struct phy *phy, enum phy_media media) in phy_set_media() argument
404 if (!phy || !phy->ops->set_media) in phy_set_media()
407 mutex_lock(&phy->mutex); in phy_set_media()
408 ret = phy->ops->set_media(phy, media); in phy_set_media()
409 mutex_unlock(&phy->mutex); in phy_set_media()
415 int phy_set_speed(struct phy *phy, int speed) in phy_set_speed() argument
419 if (!phy || !phy->ops->set_speed) in phy_set_speed()
422 mutex_lock(&phy->mutex); in phy_set_speed()
423 ret = phy->ops->set_speed(phy, speed); in phy_set_speed()
424 mutex_unlock(&phy->mutex); in phy_set_speed()
430 int phy_reset(struct phy *phy) in phy_reset() argument
434 if (!phy || !phy->ops->reset) in phy_reset()
437 ret = phy_pm_runtime_get_sync(phy); in phy_reset()
438 if (ret < 0 && ret != -ENOTSUPP) in phy_reset()
441 mutex_lock(&phy->mutex); in phy_reset()
442 ret = phy->ops->reset(phy); in phy_reset()
443 mutex_unlock(&phy->mutex); in phy_reset()
445 phy_pm_runtime_put(phy); in phy_reset()
452 * phy_calibrate() - Tunes the phy hw parameters for current configuration
453 * @phy: the phy returned by phy_get()
455 * Used to calibrate phy hardware, typically by adjusting some parameters in
461 int phy_calibrate(struct phy *phy) in phy_calibrate() argument
465 if (!phy || !phy->ops->calibrate) in phy_calibrate()
468 mutex_lock(&phy->mutex); in phy_calibrate()
469 ret = phy->ops->calibrate(phy); in phy_calibrate()
470 mutex_unlock(&phy->mutex); in phy_calibrate()
477 * phy_notify_connect() - phy connect notification
478 * @phy: the phy returned by phy_get()
481 * If the phy needs to get connection status, the callback can be used.
484 int phy_notify_connect(struct phy *phy, int port) in phy_notify_connect() argument
488 if (!phy || !phy->ops->connect) in phy_notify_connect()
491 mutex_lock(&phy->mutex); in phy_notify_connect()
492 ret = phy->ops->connect(phy, port); in phy_notify_connect()
493 mutex_unlock(&phy->mutex); in phy_notify_connect()
500 * phy_notify_disconnect() - phy disconnect notification
501 * @phy: the phy returned by phy_get()
504 * If the phy needs to get connection status, the callback can be used.
508 int phy_notify_disconnect(struct phy *phy, int port) in phy_notify_disconnect() argument
512 if (!phy || !phy->ops->disconnect) in phy_notify_disconnect()
515 mutex_lock(&phy->mutex); in phy_notify_disconnect()
516 ret = phy->ops->disconnect(phy, port); in phy_notify_disconnect()
517 mutex_unlock(&phy->mutex); in phy_notify_disconnect()
524 * phy_configure() - Changes the phy parameters
525 * @phy: the phy returned by phy_get()
528 * Used to change the PHY parameters. phy_init() must have been called
529 * on the phy. The configuration will be applied on the current phy
534 int phy_configure(struct phy *phy, union phy_configure_opts *opts) in phy_configure() argument
538 if (!phy) in phy_configure()
539 return -EINVAL; in phy_configure()
541 if (!phy->ops->configure) in phy_configure()
542 return -EOPNOTSUPP; in phy_configure()
544 mutex_lock(&phy->mutex); in phy_configure()
545 ret = phy->ops->configure(phy, opts); in phy_configure()
546 mutex_unlock(&phy->mutex); in phy_configure()
553 * phy_validate() - Checks the phy parameters
554 * @phy: the phy returned by phy_get()
556 * @submode: PHY submode the configuration is applicable to.
560 * the phy. Implementations are free to tune the parameters passed as
563 * PHY, so calling it as many times as deemed fit will have no side
568 int phy_validate(struct phy *phy, enum phy_mode mode, int submode, in phy_validate() argument
573 if (!phy) in phy_validate()
574 return -EINVAL; in phy_validate()
576 if (!phy->ops->validate) in phy_validate()
577 return -EOPNOTSUPP; in phy_validate()
579 mutex_lock(&phy->mutex); in phy_validate()
580 ret = phy->ops->validate(phy, mode, submode, opts); in phy_validate()
581 mutex_unlock(&phy->mutex); in phy_validate()
588 * _of_phy_get() - lookup and obtain a reference to a phy by phandle
589 * @np: device_node for which to get the phy
590 * @index: the index of the phy
592 * Returns the phy associated with the given phandle value,
593 * after getting a refcount to it or -ENODEV if there is no such phy or
594 * -EPROBE_DEFER if there is a phandle to the phy, but the device is
596 * while registering the phy_provider to find the phy instance.
598 static struct phy *_of_phy_get(struct device_node *np, int index) in _of_phy_get()
602 struct phy *phy = NULL; in _of_phy_get() local
605 ret = of_parse_phandle_with_args(np, "phys", "#phy-cells", in _of_phy_get()
608 return ERR_PTR(-ENODEV); in _of_phy_get()
610 /* This phy type handled by the usb-phy subsystem for now */ in _of_phy_get()
611 if (of_device_is_compatible(args.np, "usb-nop-xceiv")) { in _of_phy_get()
612 phy = ERR_PTR(-ENODEV); in _of_phy_get()
618 if (IS_ERR(phy_provider) || !try_module_get(phy_provider->owner)) { in _of_phy_get()
619 phy = ERR_PTR(-EPROBE_DEFER); in _of_phy_get()
624 dev_warn(phy_provider->dev, "Requested PHY is disabled\n"); in _of_phy_get()
625 phy = ERR_PTR(-ENODEV); in _of_phy_get()
629 phy = phy_provider->of_xlate(phy_provider->dev, &args); in _of_phy_get()
632 module_put(phy_provider->owner); in _of_phy_get()
639 return phy; in _of_phy_get()
643 * of_phy_get() - lookup and obtain a reference to a phy using a device_node.
644 * @np: device_node for which to get the phy
645 * @con_id: name of the phy from device's point of view
647 * Returns the phy driver, after getting a refcount to it; or
648 * -ENODEV if there is no such phy. The caller is responsible for
651 struct phy *of_phy_get(struct device_node *np, const char *con_id) in of_phy_get()
653 struct phy *phy = NULL; in of_phy_get() local
657 index = of_property_match_string(np, "phy-names", con_id); in of_phy_get()
659 phy = _of_phy_get(np, index); in of_phy_get()
660 if (IS_ERR(phy)) in of_phy_get()
661 return phy; in of_phy_get()
663 if (!try_module_get(phy->ops->owner)) in of_phy_get()
664 return ERR_PTR(-EPROBE_DEFER); in of_phy_get()
666 get_device(&phy->dev); in of_phy_get()
668 return phy; in of_phy_get()
673 * of_phy_put() - release the PHY
674 * @phy: the phy returned by of_phy_get()
678 void of_phy_put(struct phy *phy) in of_phy_put() argument
680 if (!phy || IS_ERR(phy)) in of_phy_put()
683 mutex_lock(&phy->mutex); in of_phy_put()
684 if (phy->ops->release) in of_phy_put()
685 phy->ops->release(phy); in of_phy_put()
686 mutex_unlock(&phy->mutex); in of_phy_put()
688 module_put(phy->ops->owner); in of_phy_put()
689 put_device(&phy->dev); in of_phy_put()
694 * phy_put() - release the PHY
695 * @dev: device that wants to release this phy
696 * @phy: the phy returned by phy_get()
700 void phy_put(struct device *dev, struct phy *phy) in phy_put() argument
702 device_link_remove(dev, &phy->dev); in phy_put()
703 of_phy_put(phy); in phy_put()
708 * devm_phy_put() - release the PHY
709 * @dev: device that wants to release this phy
710 * @phy: the phy returned by devm_phy_get()
712 * destroys the devres associated with this phy and invokes phy_put
713 * to release the phy.
715 void devm_phy_put(struct device *dev, struct phy *phy) in devm_phy_put() argument
719 if (!phy) in devm_phy_put()
722 r = devres_release(dev, devm_phy_release, devm_phy_match, phy); in devm_phy_put()
723 dev_WARN_ONCE(dev, r, "couldn't find PHY resource\n"); in devm_phy_put()
728 * of_phy_simple_xlate() - returns the phy instance from phy provider
729 * @dev: the PHY provider device (not used here)
732 * Intended to be used by phy provider for the common case where #phy-cells is
733 * 0. For other cases where #phy-cells is greater than '0', the phy provider
735 * the appropriate phy.
737 struct phy *of_phy_simple_xlate(struct device *dev, in of_phy_simple_xlate()
740 struct device *target_dev; in of_phy_simple_xlate()
742 target_dev = class_find_device_by_of_node(&phy_class, args->np); in of_phy_simple_xlate()
744 return ERR_PTR(-ENODEV); in of_phy_simple_xlate()
752 * phy_get() - lookup and obtain a reference to a phy.
753 * @dev: device that requests this phy
754 * @string: the phy name as given in the dt data or the name of the controller
755 * port for non-dt case
757 * Returns the phy driver, after getting a refcount to it; or
758 * -ENODEV if there is no such phy. The caller is responsible for
761 struct phy *phy_get(struct device *dev, const char *string) in phy_get()
764 struct phy *phy; in phy_get() local
767 if (dev->of_node) { in phy_get()
769 index = of_property_match_string(dev->of_node, "phy-names", in phy_get()
773 phy = _of_phy_get(dev->of_node, index); in phy_get()
777 return ERR_PTR(-EINVAL); in phy_get()
779 phy = phy_find(dev, string); in phy_get()
781 if (IS_ERR(phy)) in phy_get()
782 return phy; in phy_get()
784 if (!try_module_get(phy->ops->owner)) in phy_get()
785 return ERR_PTR(-EPROBE_DEFER); in phy_get()
787 get_device(&phy->dev); in phy_get()
789 link = device_link_add(dev, &phy->dev, DL_FLAG_STATELESS); in phy_get()
791 dev_dbg(dev, "failed to create device link to %s\n", in phy_get()
792 dev_name(phy->dev.parent)); in phy_get()
794 return phy; in phy_get()
799 * devm_phy_get() - lookup and obtain a reference to a phy.
800 * @dev: device that requests this phy
801 * @string: the phy name as given in the dt data or phy device name
802 * for non-dt case
804 * Gets the phy using phy_get(), and associates a device with it using
808 struct phy *devm_phy_get(struct device *dev, const char *string) in devm_phy_get()
810 struct phy **ptr, *phy; in devm_phy_get() local
814 return ERR_PTR(-ENOMEM); in devm_phy_get()
816 phy = phy_get(dev, string); in devm_phy_get()
817 if (!IS_ERR(phy)) { in devm_phy_get()
818 *ptr = phy; in devm_phy_get()
824 return phy; in devm_phy_get()
829 * devm_phy_optional_get() - lookup and obtain a reference to an optional phy.
830 * @dev: device that requests this phy
831 * @string: the phy name as given in the dt data or phy device name
832 * for non-dt case
834 * Gets the phy using phy_get(), and associates a device with it using
837 * that if the phy does not exist, it is not considered an error and
838 * -ENODEV will not be returned. Instead the NULL phy is returned,
839 * which can be passed to all other phy consumer calls.
841 struct phy *devm_phy_optional_get(struct device *dev, const char *string) in devm_phy_optional_get()
843 struct phy *phy = devm_phy_get(dev, string); in devm_phy_optional_get() local
845 if (PTR_ERR(phy) == -ENODEV) in devm_phy_optional_get()
846 phy = NULL; in devm_phy_optional_get()
848 return phy; in devm_phy_optional_get()
853 * devm_of_phy_get() - lookup and obtain a reference to a phy.
854 * @dev: device that requests this phy
855 * @np: node containing the phy
856 * @con_id: name of the phy from device's point of view
858 * Gets the phy using of_phy_get(), and associates a device with it using
862 struct phy *devm_of_phy_get(struct device *dev, struct device_node *np, in devm_of_phy_get()
865 struct phy **ptr, *phy; in devm_of_phy_get() local
870 return ERR_PTR(-ENOMEM); in devm_of_phy_get()
872 phy = of_phy_get(np, con_id); in devm_of_phy_get()
873 if (!IS_ERR(phy)) { in devm_of_phy_get()
874 *ptr = phy; in devm_of_phy_get()
878 return phy; in devm_of_phy_get()
881 link = device_link_add(dev, &phy->dev, DL_FLAG_STATELESS); in devm_of_phy_get()
883 dev_dbg(dev, "failed to create device link to %s\n", in devm_of_phy_get()
884 dev_name(phy->dev.parent)); in devm_of_phy_get()
886 return phy; in devm_of_phy_get()
891 * devm_of_phy_optional_get() - lookup and obtain a reference to an optional
892 * phy.
893 * @dev: device that requests this phy
894 * @np: node containing the phy
895 * @con_id: name of the phy from device's point of view
897 * Gets the phy using of_phy_get(), and associates a device with it using
900 * that if the phy does not exist, it is not considered an error and
901 * -ENODEV will not be returned. Instead the NULL phy is returned,
902 * which can be passed to all other phy consumer calls.
904 struct phy *devm_of_phy_optional_get(struct device *dev, struct device_node *np, in devm_of_phy_optional_get()
907 struct phy *phy = devm_of_phy_get(dev, np, con_id); in devm_of_phy_optional_get() local
909 if (PTR_ERR(phy) == -ENODEV) in devm_of_phy_optional_get()
910 phy = NULL; in devm_of_phy_optional_get()
912 if (IS_ERR(phy)) in devm_of_phy_optional_get()
913 dev_err_probe(dev, PTR_ERR(phy), "failed to get PHY %pOF:%s", in devm_of_phy_optional_get()
916 return phy; in devm_of_phy_optional_get()
921 * devm_of_phy_get_by_index() - lookup and obtain a reference to a phy by index.
922 * @dev: device that requests this phy
923 * @np: node containing the phy
924 * @index: index of the phy
926 * Gets the phy using _of_phy_get(), then gets a refcount to it,
927 * and associates a device with it using devres. On driver detach,
932 struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, in devm_of_phy_get_by_index()
935 struct phy **ptr, *phy; in devm_of_phy_get_by_index() local
940 return ERR_PTR(-ENOMEM); in devm_of_phy_get_by_index()
942 phy = _of_phy_get(np, index); in devm_of_phy_get_by_index()
943 if (IS_ERR(phy)) { in devm_of_phy_get_by_index()
945 return phy; in devm_of_phy_get_by_index()
948 if (!try_module_get(phy->ops->owner)) { in devm_of_phy_get_by_index()
950 return ERR_PTR(-EPROBE_DEFER); in devm_of_phy_get_by_index()
953 get_device(&phy->dev); in devm_of_phy_get_by_index()
955 *ptr = phy; in devm_of_phy_get_by_index()
958 link = device_link_add(dev, &phy->dev, DL_FLAG_STATELESS); in devm_of_phy_get_by_index()
960 dev_dbg(dev, "failed to create device link to %s\n", in devm_of_phy_get_by_index()
961 dev_name(phy->dev.parent)); in devm_of_phy_get_by_index()
963 return phy; in devm_of_phy_get_by_index()
968 * phy_create() - create a new phy
969 * @dev: device that is creating the new phy
970 * @node: device node of the phy
971 * @ops: function pointers for performing phy operations
973 * Called to create a phy using phy framework.
975 struct phy *phy_create(struct device *dev, struct device_node *node, in phy_create()
980 struct phy *phy; in phy_create() local
983 return ERR_PTR(-EINVAL); in phy_create()
985 phy = kzalloc(sizeof(*phy), GFP_KERNEL); in phy_create()
986 if (!phy) in phy_create()
987 return ERR_PTR(-ENOMEM); in phy_create()
996 device_initialize(&phy->dev); in phy_create()
997 mutex_init(&phy->mutex); in phy_create()
999 phy->dev.class = &phy_class; in phy_create()
1000 phy->dev.parent = dev; in phy_create()
1001 phy->dev.of_node = node ?: dev->of_node; in phy_create()
1002 phy->id = id; in phy_create()
1003 phy->ops = ops; in phy_create()
1005 ret = dev_set_name(&phy->dev, "phy-%s.%d", dev_name(dev), id); in phy_create()
1009 /* phy-supply */ in phy_create()
1010 phy->pwr = regulator_get_optional(&phy->dev, "phy"); in phy_create()
1011 if (IS_ERR(phy->pwr)) { in phy_create()
1012 ret = PTR_ERR(phy->pwr); in phy_create()
1013 if (ret == -EPROBE_DEFER) in phy_create()
1016 phy->pwr = NULL; in phy_create()
1019 ret = device_add(&phy->dev); in phy_create()
1024 pm_runtime_enable(&phy->dev); in phy_create()
1025 pm_runtime_no_callbacks(&phy->dev); in phy_create()
1028 phy->debugfs = debugfs_create_dir(dev_name(&phy->dev), phy_debugfs_root); in phy_create()
1030 return phy; in phy_create()
1033 put_device(&phy->dev); /* calls phy_release() which frees resources */ in phy_create()
1037 kfree(phy); in phy_create()
1043 * devm_phy_create() - create a new phy
1044 * @dev: device that is creating the new phy
1045 * @node: device node of the phy
1046 * @ops: function pointers for performing phy operations
1048 * Creates a new PHY device adding it to the PHY class.
1049 * While at that, it also associates the device with the phy using devres.
1053 struct phy *devm_phy_create(struct device *dev, struct device_node *node, in devm_phy_create()
1056 struct phy **ptr, *phy; in devm_phy_create() local
1060 return ERR_PTR(-ENOMEM); in devm_phy_create()
1062 phy = phy_create(dev, node, ops); in devm_phy_create()
1063 if (!IS_ERR(phy)) { in devm_phy_create()
1064 *ptr = phy; in devm_phy_create()
1070 return phy; in devm_phy_create()
1075 * phy_destroy() - destroy the phy
1076 * @phy: the phy to be destroyed
1078 * Called to destroy the phy.
1080 void phy_destroy(struct phy *phy) in phy_destroy() argument
1082 pm_runtime_disable(&phy->dev); in phy_destroy()
1083 device_unregister(&phy->dev); in phy_destroy()
1088 * devm_phy_destroy() - destroy the PHY
1089 * @dev: device that wants to release this phy
1090 * @phy: the phy returned by devm_phy_get()
1092 * destroys the devres associated with this phy and invokes phy_destroy
1093 * to destroy the phy.
1095 void devm_phy_destroy(struct device *dev, struct phy *phy) in devm_phy_destroy() argument
1099 r = devres_release(dev, devm_phy_consume, devm_phy_match, phy); in devm_phy_destroy()
1100 dev_WARN_ONCE(dev, r, "couldn't find PHY resource\n"); in devm_phy_destroy()
1105 * __of_phy_provider_register() - create/register phy provider with the framework
1106 * @dev: struct device of the phy provider
1107 * @children: device node containing children (if different from dev->of_node)
1109 * @of_xlate: function pointer to obtain phy instance from phy provider
1112 * This is used in the case of dt boot for finding the phy instance from
1113 * phy provider.
1115 * If the PHY provider doesn't nest children directly but uses a separate
1117 * can be used to override the default. If NULL, the default (dev->of_node)
1118 * will be used. If non-NULL, the device node must be a child (or further
1119 * descendant) of dev->of_node. Otherwise an ERR_PTR()-encoded -EINVAL
1122 struct phy_provider *__of_phy_provider_register(struct device *dev, in __of_phy_provider_register()
1124 struct phy * (*of_xlate)(struct device *dev, in __of_phy_provider_register()
1130 * If specified, the device node containing the children must itself in __of_phy_provider_register()
1131 * be the provider's device node or a child (or further descendant) in __of_phy_provider_register()
1138 if (parent == dev->of_node) in __of_phy_provider_register()
1147 return ERR_PTR(-EINVAL); in __of_phy_provider_register()
1151 children = dev->of_node; in __of_phy_provider_register()
1156 return ERR_PTR(-ENOMEM); in __of_phy_provider_register()
1158 phy_provider->dev = dev; in __of_phy_provider_register()
1159 phy_provider->children = of_node_get(children); in __of_phy_provider_register()
1160 phy_provider->owner = owner; in __of_phy_provider_register()
1161 phy_provider->of_xlate = of_xlate; in __of_phy_provider_register()
1164 list_add_tail(&phy_provider->list, &phy_provider_list); in __of_phy_provider_register()
1172 * __devm_of_phy_provider_register() - create/register phy provider with the
1174 * @dev: struct device of the phy provider
1175 * @children: device node containing children (if different from dev->of_node)
1177 * @of_xlate: function pointer to obtain phy instance from phy provider
1180 * This is used in the case of dt boot for finding the phy instance from
1181 * phy provider. While at that, it also associates the device with the
1182 * phy provider using devres. On driver detach, release function is invoked
1185 struct phy_provider *__devm_of_phy_provider_register(struct device *dev, in __devm_of_phy_provider_register()
1187 struct phy * (*of_xlate)(struct device *dev, in __devm_of_phy_provider_register()
1194 return ERR_PTR(-ENOMEM); in __devm_of_phy_provider_register()
1210 * of_phy_provider_unregister() - unregister phy provider from the framework
1211 * @phy_provider: phy provider returned by of_phy_provider_register()
1221 list_del(&phy_provider->list); in of_phy_provider_unregister()
1222 of_node_put(phy_provider->children); in of_phy_provider_unregister()
1229 * devm_of_phy_provider_unregister() - remove phy provider from the framework
1230 * @dev: struct device of the phy provider
1231 * @phy_provider: phy provider returned by of_phy_provider_register()
1233 * destroys the devres associated with this phy provider and invokes
1234 * of_phy_provider_unregister to unregister the phy provider.
1236 void devm_of_phy_provider_unregister(struct device *dev, in devm_of_phy_provider_unregister()
1243 dev_WARN_ONCE(dev, r, "couldn't find PHY provider device resource\n"); in devm_of_phy_provider_unregister()
1248 * phy_release() - release the phy
1249 * @dev: the dev member within phy
1251 * When the last reference to the device is removed, it is called
1254 static void phy_release(struct device *dev) in phy_release()
1256 struct phy *phy; in phy_release() local
1258 phy = to_phy(dev); in phy_release()
1260 debugfs_remove_recursive(phy->debugfs); in phy_release()
1261 regulator_put(phy->pwr); in phy_release()
1262 ida_free(&phy_ida, phy->id); in phy_release()
1263 kfree(phy); in phy_release()
1272 pr_err("failed to register phy class"); in phy_core_init()
1276 phy_debugfs_root = debugfs_create_dir("phy", NULL); in phy_core_init()