[RFC linus/master 2/4] phy: add raspberry pi driver

Alexander Aring alex.aring at gmail.com
Sat Oct 24 05:20:42 PDT 2015


This driver adds support for raspberry pi usb phy. This driver just
adapt the current infrastructure for usb phys that usb controller uses
to power the usb phy via regulators.

Cc: Eric Anholt <eric at anholt.net>
Signed-off-by: Alexander Aring <alex.aring at gmail.com>
---
 .../devicetree/bindings/phy/raspberrypi-phy.txt    | 15 ++++
 drivers/phy/Kconfig                                |  9 ++
 drivers/phy/Makefile                               |  1 +
 drivers/phy/phy-raspberrypi-usb.c                  | 96 ++++++++++++++++++++++
 4 files changed, 121 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/raspberrypi-phy.txt
 create mode 100644 drivers/phy/phy-raspberrypi-usb.c

diff --git a/Documentation/devicetree/bindings/phy/raspberrypi-phy.txt b/Documentation/devicetree/bindings/phy/raspberrypi-phy.txt
new file mode 100644
index 0000000..3fd780a
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/raspberrypi-phy.txt
@@ -0,0 +1,15 @@
+RASPBERRY PI USB PHY
+
+Required properties:
+ - compatible: raspberrypi,bcm2835-usbphy
+ - #phy-cells: must be 0
+ - phy-supply: regulator for the rpi usb phy
+Refer to phy/phy-bindings.txt for the generic PHY binding properties
+
+Example:
+
+	usbphy: usbphy {
+		compatible = "raspberrypi,bcm2835-usbphy";
+		#phy-cells = <0>;
+		phy-supply = <&usb_hcd_reg>;
+	};
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 47da573..c6ac9c0 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -183,6 +183,15 @@ config BCM_KONA_USB2_PHY
 	help
 	  Enable this to support the Broadcom Kona USB 2.0 PHY.
 
+config PHY_RASPBERRY_USB
+	tristate "Raspberry Pi USB PHY Driver"
+	depends on REGULATOR_RASPBERRYPI
+	select GENERIC_PHY
+	help
+	  Enable this to support the Raspberry Pi USB 2.0 dummy PHY
+	  to enable the USB Phy over regulators which triggers
+	  firmware protocol messages.
+
 config PHY_EXYNOS5250_SATA
 	tristate "Exynos5250 Sata SerDes/PHY driver"
 	depends on SOC_EXYNOS5250
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index a5b18c1..c8b1196 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_PHY_BERLIN_SATA)		+= phy-berlin-sata.o
 obj-$(CONFIG_PHY_DM816X_USB)		+= phy-dm816x-usb.o
 obj-$(CONFIG_ARMADA375_USBCLUSTER_PHY)	+= phy-armada375-usb2.o
 obj-$(CONFIG_BCM_KONA_USB2_PHY)		+= phy-bcm-kona-usb2.o
+obj-$(CONFIG_PHY_RASPBERRY_USB)		+= phy-raspberrypi-usb.o
 obj-$(CONFIG_PHY_EXYNOS_DP_VIDEO)	+= phy-exynos-dp-video.o
 obj-$(CONFIG_PHY_EXYNOS_MIPI_VIDEO)	+= phy-exynos-mipi-video.o
 obj-$(CONFIG_PHY_LPC18XX_USB_OTG)	+= phy-lpc18xx-usb-otg.o
diff --git a/drivers/phy/phy-raspberrypi-usb.c b/drivers/phy/phy-raspberrypi-usb.c
new file mode 100644
index 0000000..36292b4
--- /dev/null
+++ b/drivers/phy/phy-raspberrypi-usb.c
@@ -0,0 +1,96 @@
+/*
+ * raspberrypi-usb.c - Raspberry Pi Phy Driver
+ *
+ * (C) 2015 Pengutronix, Alexander Aring <aar at pengutronix.de>
+ *
+ * based on: phy-bcm-kona-usb2.c
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/err.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/phy/phy.h>
+#include <linux/platform_device.h>
+
+struct raspberrypi_usb {
+	struct regulator *reg;
+};
+
+static int raspberrypi_usb_phy_power_on(struct phy *gphy)
+{
+	struct raspberrypi_usb *phy = phy_get_drvdata(gphy);
+
+	return regulator_enable(phy->reg);
+}
+
+static int raspberrypi_usb_phy_power_off(struct phy *gphy)
+{
+	struct raspberrypi_usb *phy = phy_get_drvdata(gphy);
+
+	return regulator_disable(phy->reg);
+}
+
+static const struct phy_ops ops = {
+	.power_on	= raspberrypi_usb_phy_power_on,
+	.power_off	= raspberrypi_usb_phy_power_off,
+	.owner		= THIS_MODULE,
+};
+
+static int raspberrypi_usb_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct raspberrypi_usb *phy;
+	struct phy *gphy;
+	struct phy_provider *phy_provider;
+
+	phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL);
+	if (!phy)
+		return -ENOMEM;
+
+	phy->reg = devm_regulator_get(&pdev->dev, "phy");
+	if (IS_ERR(phy->reg))
+		return PTR_ERR(phy->reg);
+
+	platform_set_drvdata(pdev, phy);
+
+	gphy = devm_phy_create(dev, NULL, &ops);
+	if (IS_ERR(gphy))
+		return PTR_ERR(gphy);
+
+	phy_set_drvdata(gphy, phy);
+
+	phy_provider = devm_of_phy_provider_register(dev,
+			of_phy_simple_xlate);
+
+	return PTR_ERR_OR_ZERO(phy_provider);
+}
+
+static const struct of_device_id raspberrypi_usb_dt_ids[] = {
+	{ .compatible = "raspberrypi,bcm2835-usbphy" },
+	{ /* sentinel */ }
+};
+
+MODULE_DEVICE_TABLE(of, raspberrypi_usb_dt_ids);
+
+static struct platform_driver raspberrypi_usb_driver = {
+	.probe		= raspberrypi_usb_probe,
+	.driver		= {
+		.name	= "raspberrypi-usbphy",
+		.of_match_table = raspberrypi_usb_dt_ids,
+	},
+};
+
+module_platform_driver(raspberrypi_usb_driver);
+
+MODULE_AUTHOR("Alexander Aring <aar at pengutronix.de>");
+MODULE_DESCRIPTION("Raspberry Pi USB PHY driver");
+MODULE_LICENSE("GPL v2");
-- 
2.6.1




More information about the linux-rpi-kernel mailing list