[U-Boot] [PATCH 03/11] drivers: phy: add generic PHY framework
Jean-Jacques Hiblot
jjhiblot at ti.com
Fri Apr 14 11:08:01 UTC 2017
The PHY framework provides a set of APIs to control a PHY. This API is
derived from the linux version of the generic PHY framework.
Currently the API supports init(), deinit(), power_on, power_off() and
reset(). The framework provides a way to get a reference to a phy from the
device-tree.
Signed-off-by: Jean-Jacques Hiblot <jjhiblot at ti.com>
---
drivers/Kconfig | 2 ++
drivers/Makefile | 1 +
drivers/phy/Kconfig | 32 ++++++++++++++++++++++++
drivers/phy/Makefile | 2 ++
drivers/phy/phy-uclass.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++
include/dm/uclass-id.h | 1 +
include/generic-phy.h | 36 +++++++++++++++++++++++++++
7 files changed, 138 insertions(+)
create mode 100644 drivers/phy/Kconfig
create mode 100644 drivers/phy/Makefile
create mode 100644 drivers/phy/phy-uclass.c
create mode 100644 include/generic-phy.h
diff --git a/drivers/Kconfig b/drivers/Kconfig
index 0e5d97d..a90ceca 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -88,6 +88,8 @@ source "drivers/video/Kconfig"
source "drivers/watchdog/Kconfig"
+source "drivers/phy/Kconfig"
+
config PHYS_TO_BUS
bool "Custom physical to bus address mapping"
help
diff --git a/drivers/Makefile b/drivers/Makefile
index 5d8baa5..0be0624 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -7,6 +7,7 @@ obj-$(CONFIG_$(SPL_)CLK) += clk/
obj-$(CONFIG_$(SPL_)LED) += led/
obj-$(CONFIG_$(SPL_)PINCTRL) += pinctrl/
obj-$(CONFIG_$(SPL_)RAM) += ram/
+obj-$(CONFIG_$(SPL_)GENERIC_PHY) += phy/
ifdef CONFIG_SPL_BUILD
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
new file mode 100644
index 0000000..d66c9e3
--- /dev/null
+++ b/drivers/phy/Kconfig
@@ -0,0 +1,32 @@
+
+menu "PHY Subsystem"
+
+config GENERIC_PHY
+ bool "PHY Core"
+ depends on DM
+ help
+ Generic PHY support.
+
+ This framework is designed to provide a generic interface for PHY
+ devices. PHYs are commonly used for high speed interfaces such as
+ SATA or PCIe.
+ The API provides functions to initialize/deinitialize the
+ phy, power on/off the phy, and reset the phy. It's meant to be as
+ compatible as possible with the equivalent framework found in the
+ linux kernel.
+
+config SPL_GENERIC_PHY
+ bool "PHY Core in SPL"
+ depends on DM
+ help
+ Generic PHY support in SPL.
+
+ This framework is designed to provide a generic interface for PHY
+ devices. PHYs are commonly used for high speed interfaces such as
+ SATA or PCIe.
+ The API provides functions to initialize/deinitialize the
+ phy, power on/off the phy, and reset the phy. It's meant to be as
+ compatible as possible with the equivalent framework found in the
+ linux kernel.
+
+endmenu
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
new file mode 100644
index 0000000..b29a8b9
--- /dev/null
+++ b/drivers/phy/Makefile
@@ -0,0 +1,2 @@
+obj-$(CONFIG_$(SPL_)GENERIC_PHY) += phy-uclass.o
+
diff --git a/drivers/phy/phy-uclass.c b/drivers/phy/phy-uclass.c
new file mode 100644
index 0000000..e15ed43
--- /dev/null
+++ b/drivers/phy/phy-uclass.c
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
+ * Written by Jean-Jacques Hiblot <jjhiblot at ti.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <generic-phy.h>
+
+struct udevice *dm_generic_phy_get(struct udevice *parent, const char *string)
+{
+ struct udevice *dev;
+
+ int rc = uclass_get_device_by_phandle(UCLASS_PHY, parent,
+ string, &dev);
+ if (rc) {
+ debug("unable to find generic_phy device (err: %d)\n", rc);
+ return ERR_PTR(rc);
+ }
+
+ return dev;
+}
+
+int generic_phy_init(struct udevice *dev)
+{
+ struct generic_phy_ops const *ops = dev->driver->ops;
+
+ return (ops && ops->init) ? ops->init(dev) : 0;
+}
+
+int generic_phy_reset(struct udevice *dev)
+{
+ struct generic_phy_ops const *ops = dev->driver->ops;
+
+ return (ops && ops->reset) ? ops->reset(dev) : 0;
+}
+
+int generic_phy_exit(struct udevice *dev)
+{
+ struct generic_phy_ops const *ops = dev->driver->ops;
+
+ return (ops && ops->exit) ? ops->exit(dev) : 0;
+}
+
+int generic_phy_power_on(struct udevice *dev)
+{
+ struct generic_phy_ops const *ops = dev->driver->ops;
+
+ return (ops && ops->power_on) ? ops->power_on(dev) : 0;
+}
+
+int generic_phy_power_off(struct udevice *dev)
+{
+ struct generic_phy_ops const *ops = dev->driver->ops;
+
+ return (ops && ops->power_off) ? ops->power_off(dev) : 0;
+}
+
+UCLASS_DRIVER(generic_phy) = {
+ .id = UCLASS_PHY,
+ .name = "generic_phy",
+};
diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
index 8c92d0b..9d34a32 100644
--- a/include/dm/uclass-id.h
+++ b/include/dm/uclass-id.h
@@ -83,6 +83,7 @@ enum uclass_id {
UCLASS_VIDEO, /* Video or LCD device */
UCLASS_VIDEO_BRIDGE, /* Video bridge, e.g. DisplayPort to LVDS */
UCLASS_VIDEO_CONSOLE, /* Text console driver for video device */
+ UCLASS_PHY, /* generic PHY device */
UCLASS_COUNT,
UCLASS_INVALID = -1,
diff --git a/include/generic-phy.h b/include/generic-phy.h
new file mode 100644
index 0000000..24475f0
--- /dev/null
+++ b/include/generic-phy.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
+ * Written by Jean-Jacques Hiblot <jjhiblot at ti.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef __GENERIC_PHY_H
+#define __GENERIC_PHY_H
+
+/*
+ * struct udevice_ops - set of function pointers for phy operations
+ * @init: operation to be performed for initializing phy (optionnal)
+ * @exit: operation to be performed while exiting (optionnal)
+ * @reset: reset the phy (optionnal).
+ * @power_on: powering on the phy (optionnal)
+ * @power_off: powering off the phy (optionnal)
+ */
+struct generic_phy_ops {
+ int (*init)(struct udevice *phy);
+ int (*exit)(struct udevice *phy);
+ int (*reset)(struct udevice *phy);
+ int (*power_on)(struct udevice *phy);
+ int (*power_off)(struct udevice *phy);
+};
+
+
+int generic_phy_init(struct udevice *phy);
+int generic_phy_reset(struct udevice *phy);
+int generic_phy_exit(struct udevice *phy);
+int generic_phy_power_on(struct udevice *phy);
+int generic_phy_power_off(struct udevice *phy);
+
+struct udevice *dm_generic_phy_get(struct udevice *parent, const char *string);
+
+#endif /*__GENERIC_PHY_H */
--
1.9.1
More information about the U-Boot
mailing list