hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/phy/phy-core.c
....@@ -1,14 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * phy-core.c -- Generic Phy framework.
34 *
45 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com
56 *
67 * 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.
128 */
139
1410 #include <linux/kernel.h>
....@@ -33,7 +29,7 @@
3329 {
3430 struct phy *phy = *(struct phy **)res;
3531
36
- phy_put(phy);
32
+ phy_put(dev, phy);
3733 }
3834
3935 static void devm_phy_provider_release(struct device *dev, void *res)
....@@ -360,7 +356,7 @@
360356 }
361357 EXPORT_SYMBOL_GPL(phy_power_off);
362358
363
-int phy_set_mode(struct phy *phy, enum phy_mode mode)
359
+int phy_set_mode_ext(struct phy *phy, enum phy_mode mode, int submode)
364360 {
365361 int ret;
366362
....@@ -368,14 +364,14 @@
368364 return 0;
369365
370366 mutex_lock(&phy->mutex);
371
- ret = phy->ops->set_mode(phy, mode);
367
+ ret = phy->ops->set_mode(phy, mode, submode);
372368 if (!ret)
373369 phy->attrs.mode = mode;
374370 mutex_unlock(&phy->mutex);
375371
376372 return ret;
377373 }
378
-EXPORT_SYMBOL_GPL(phy_set_mode);
374
+EXPORT_SYMBOL_GPL(phy_set_mode_ext);
379375
380376 int phy_reset(struct phy *phy)
381377 {
....@@ -384,27 +380,36 @@
384380 if (!phy || !phy->ops->reset)
385381 return 0;
386382
383
+ ret = phy_pm_runtime_get_sync(phy);
384
+ if (ret < 0 && ret != -ENOTSUPP)
385
+ return ret;
386
+
387387 mutex_lock(&phy->mutex);
388388 ret = phy->ops->reset(phy);
389389 mutex_unlock(&phy->mutex);
390
+
391
+ phy_pm_runtime_put(phy);
390392
391393 return ret;
392394 }
393395 EXPORT_SYMBOL_GPL(phy_reset);
394396
397
+/**
398
+ * phy_calibrate() - Tunes the phy hw parameters for current configuration
399
+ * @phy: the phy returned by phy_get()
400
+ *
401
+ * Used to calibrate phy hardware, typically by adjusting some parameters in
402
+ * runtime, which are otherwise lost after host controller reset and cannot
403
+ * be applied in phy_init() or phy_power_on().
404
+ *
405
+ * Returns: 0 if successful, an negative error code otherwise
406
+ */
395407 int phy_calibrate(struct phy *phy)
396408 {
397409 int ret;
398410
399411 if (!phy || !phy->ops->calibrate)
400412 return 0;
401
-
402
- if (phy->dev.parent &&
403
- of_device_is_compatible(phy->dev.parent->of_node,
404
- "rockchip,rv1126-usb2phy")) {
405
- ret = phy->ops->calibrate(phy);
406
- return ret;
407
- }
408413
409414 mutex_lock(&phy->mutex);
410415 ret = phy->ops->calibrate(phy);
....@@ -561,18 +566,37 @@
561566 EXPORT_SYMBOL_GPL(of_phy_get);
562567
563568 /**
564
- * phy_put() - release the PHY
565
- * @phy: the phy returned by phy_get()
569
+ * of_phy_put() - release the PHY
570
+ * @phy: the phy returned by of_phy_get()
566571 *
567
- * Releases a refcount the caller received from phy_get().
572
+ * Releases a refcount the caller received from of_phy_get().
568573 */
569
-void phy_put(struct phy *phy)
574
+void of_phy_put(struct phy *phy)
570575 {
571576 if (!phy || IS_ERR(phy))
572577 return;
573578
579
+ mutex_lock(&phy->mutex);
580
+ if (phy->ops->release)
581
+ phy->ops->release(phy);
582
+ mutex_unlock(&phy->mutex);
583
+
574584 module_put(phy->ops->owner);
575585 put_device(&phy->dev);
586
+}
587
+EXPORT_SYMBOL_GPL(of_phy_put);
588
+
589
+/**
590
+ * phy_put() - release the PHY
591
+ * @dev: device that wants to release this phy
592
+ * @phy: the phy returned by phy_get()
593
+ *
594
+ * Releases a refcount the caller received from phy_get().
595
+ */
596
+void phy_put(struct device *dev, struct phy *phy)
597
+{
598
+ device_link_remove(dev, &phy->dev);
599
+ of_phy_put(phy);
576600 }
577601 EXPORT_SYMBOL_GPL(phy_put);
578602
....@@ -641,6 +665,7 @@
641665 {
642666 int index = 0;
643667 struct phy *phy;
668
+ struct device_link *link;
644669
645670 if (string == NULL) {
646671 dev_WARN(dev, "missing string\n");
....@@ -662,6 +687,11 @@
662687
663688 get_device(&phy->dev);
664689
690
+ link = device_link_add(dev, &phy->dev, DL_FLAG_STATELESS);
691
+ if (!link)
692
+ dev_dbg(dev, "failed to create device link to %s\n",
693
+ dev_name(phy->dev.parent));
694
+
665695 return phy;
666696 }
667697 EXPORT_SYMBOL_GPL(phy_get);
....@@ -680,7 +710,7 @@
680710 {
681711 struct phy *phy = phy_get(dev, string);
682712
683
- if (IS_ERR(phy) && (PTR_ERR(phy) == -ENODEV))
713
+ if (PTR_ERR(phy) == -ENODEV)
684714 phy = NULL;
685715
686716 return phy;
....@@ -734,7 +764,7 @@
734764 {
735765 struct phy *phy = devm_phy_get(dev, string);
736766
737
- if (IS_ERR(phy) && (PTR_ERR(phy) == -ENODEV))
767
+ if (PTR_ERR(phy) == -ENODEV)
738768 phy = NULL;
739769
740770 return phy;
....@@ -755,6 +785,7 @@
755785 const char *con_id)
756786 {
757787 struct phy **ptr, *phy;
788
+ struct device_link *link;
758789
759790 ptr = devres_alloc(devm_phy_release, sizeof(*ptr), GFP_KERNEL);
760791 if (!ptr)
....@@ -766,7 +797,13 @@
766797 devres_add(dev, ptr);
767798 } else {
768799 devres_free(ptr);
800
+ return phy;
769801 }
802
+
803
+ link = device_link_add(dev, &phy->dev, DL_FLAG_STATELESS);
804
+ if (!link)
805
+ dev_dbg(dev, "failed to create device link to %s\n",
806
+ dev_name(phy->dev.parent));
770807
771808 return phy;
772809 }
....@@ -788,6 +825,7 @@
788825 int index)
789826 {
790827 struct phy **ptr, *phy;
828
+ struct device_link *link;
791829
792830 ptr = devres_alloc(devm_phy_release, sizeof(*ptr), GFP_KERNEL);
793831 if (!ptr)
....@@ -808,6 +846,11 @@
808846
809847 *ptr = phy;
810848 devres_add(dev, ptr);
849
+
850
+ link = device_link_add(dev, &phy->dev, DL_FLAG_STATELESS);
851
+ if (!link)
852
+ dev_dbg(dev, "failed to create device link to %s\n",
853
+ dev_name(phy->dev.parent));
811854
812855 return phy;
813856 }
....@@ -1019,6 +1062,7 @@
10191062 * __devm_of_phy_provider_register() - create/register phy provider with the
10201063 * framework
10211064 * @dev: struct device of the phy provider
1065
+ * @children: device node containing children (if different from dev->of_node)
10221066 * @owner: the module owner containing of_xlate
10231067 * @of_xlate: function pointer to obtain phy instance from phy provider
10241068 *
....@@ -1074,12 +1118,14 @@
10741118 /**
10751119 * devm_of_phy_provider_unregister() - remove phy provider from the framework
10761120 * @dev: struct device of the phy provider
1121
+ * @phy_provider: phy provider returned by of_phy_provider_register()
10771122 *
10781123 * destroys the devres associated with this phy provider and invokes
10791124 * of_phy_provider_unregister to unregister the phy provider.
10801125 */
10811126 void devm_of_phy_provider_unregister(struct device *dev,
1082
- struct phy_provider *phy_provider) {
1127
+ struct phy_provider *phy_provider)
1128
+{
10831129 int r;
10841130
10851131 r = devres_destroy(dev, devm_phy_provider_release, devm_phy_match,
....@@ -1119,18 +1165,4 @@
11191165
11201166 return 0;
11211167 }
1122
-#ifdef CONFIG_ROCKCHIP_THUNDER_BOOT
1123
-subsys_initcall(phy_core_init);
1124
-#else
1125
-module_init(phy_core_init);
1126
-#endif
1127
-
1128
-static void __exit phy_core_exit(void)
1129
-{
1130
- class_destroy(phy_class);
1131
-}
1132
-module_exit(phy_core_exit);
1133
-
1134
-MODULE_DESCRIPTION("Generic PHY Framework");
1135
-MODULE_AUTHOR("Kishon Vijay Abraham I <kishon@ti.com>");
1136
-MODULE_LICENSE("GPL v2");
1168
+device_initcall(phy_core_init);