diff mbox series

[RFC,2/3] reset: renesas: Add rzg2l_usbphy_ctrl_select_vbus_ctrl()

Message ID 20230518155649.516346-3-biju.das.jz@bp.renesas.com (mailing list archive)
State Under Review
Delegated to: Geert Uytterhoeven
Headers show
Series Support VBUSEN selection control for RZ/G2L | expand

Commit Message

Biju Das May 18, 2023, 3:56 p.m. UTC
As per RZ/G2L HW(Rev.1.30 May2023) manual, VBUSEN can be controlled by
the Port Power bit of the EHCI/OHCI operational register or by the VBOUT
bit of the VBUS Control Register. VBUSEN selection is determined by the
VBUSEN control (VBENCTL) register in USBPHY Control.

Add support for VBUSEN selection.

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
 drivers/reset/reset-rzg2l-usbphy-ctrl.c | 27 +++++++++++++++++++++++++
 include/linux/reset/rzg2l-usbphy-ctrl.h | 16 +++++++++++++++
 2 files changed, 43 insertions(+)
 create mode 100644 include/linux/reset/rzg2l-usbphy-ctrl.h
diff mbox series

Patch

diff --git a/drivers/reset/reset-rzg2l-usbphy-ctrl.c b/drivers/reset/reset-rzg2l-usbphy-ctrl.c
index a8dde4606360..83de261bf460 100644
--- a/drivers/reset/reset-rzg2l-usbphy-ctrl.c
+++ b/drivers/reset/reset-rzg2l-usbphy-ctrl.c
@@ -14,6 +14,7 @@ 
 #include <linux/reset-controller.h>
 
 #define RESET			0x000
+#define VBENCTL			0x03c
 
 #define RESET_SEL_PLLRESET	BIT(12)
 #define RESET_PLLRESET		BIT(8)
@@ -88,6 +89,32 @@  static int rzg2l_usbphy_ctrl_status(struct reset_controller_dev *rcdev,
 	return !!(readl(priv->base + RESET) & port_mask);
 }
 
+int rzg2l_usbphy_ctrl_select_vbus_ctrl(struct reset_control *rstc, bool vbctrl)
+{
+	struct reset_controller_dev *rcdev = reset_controller_get_dev(rstc);
+	struct rzg2l_usbphy_ctrl_priv *priv;
+	unsigned long flags;
+	u32 val;
+
+	if (!rstc)
+		return 0;
+
+	priv = rcdev_to_priv(rcdev);
+
+	spin_lock_irqsave(&priv->lock, flags);
+	val = readl(priv->base + VBENCTL);
+	if (vbctrl)
+		val |= BIT(0);
+	else
+		val &= ~BIT(0);
+
+	writel(val, priv->base + VBENCTL);
+	spin_unlock_irqrestore(&priv->lock, flags);
+
+	return 0;
+}
+EXPORT_SYMBOL(rzg2l_usbphy_ctrl_select_vbus_ctrl);
+
 static const struct of_device_id rzg2l_usbphy_ctrl_match_table[] = {
 	{ .compatible = "renesas,rzg2l-usbphy-ctrl" },
 	{ /* Sentinel */ }
diff --git a/include/linux/reset/rzg2l-usbphy-ctrl.h b/include/linux/reset/rzg2l-usbphy-ctrl.h
new file mode 100644
index 000000000000..c531bd4a6a63
--- /dev/null
+++ b/include/linux/reset/rzg2l-usbphy-ctrl.h
@@ -0,0 +1,16 @@ 
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_RESET_RZG2L_USBPHY_CTRL_H_
+#define _LINUX_RESET_RZG2L_USBPHY_CTRL_H_
+
+#if IS_ENABLED(CONFIG_RESET_RZG2L_USBPHY_CTRL)
+int rzg2l_usbphy_ctrl_select_vbus_ctrl(struct reset_control *rstc,
+				       bool vbctrl);
+#else
+static inline int
+rzg2l_usbphy_ctrl_select_vbus_ctrl(struct reset_control *rstc, bool vbctrl)
+{
+	return 0;
+}
+#endif
+
+#endif /* _LINUX_RESET_RZG2L_USBPHY_CTRL_H_ */