[PATCH v6 1/2] usb: phy: samsung: Common out the generic stuff
Moving register and structure definitions to header file, and keeping the generic functions to be used across multiple PHYs in common phy helper driver under SAMSUNG_USBPHY, and moving USB 2.0 PHY driver under SAMSUNG_USB2PHY. Also allowing samsung PHY drivers be built as modules. Signed-off-by: Vivek Gautam Signed-off-by: Felipe Balbi Acked-by: Kukjin Kim --- drivers/usb/phy/Kconfig | 17 +- drivers/usb/phy/Makefile |1 + drivers/usb/phy/samsung-usb2phy.c | 511 ++ drivers/usb/phy/samsung-usbphy.c | 722 + drivers/usb/phy/samsung-usbphy.h | 247 + 5 files changed, 785 insertions(+), 713 deletions(-) create mode 100644 drivers/usb/phy/samsung-usb2phy.c create mode 100644 drivers/usb/phy/samsung-usbphy.h diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig index 65217a5..4d72962 100644 --- a/drivers/usb/phy/Kconfig +++ b/drivers/usb/phy/Kconfig @@ -66,10 +66,17 @@ config USB_RCAR_PHY To compile this driver as a module, choose M here: the module will be called rcar-phy. -config SAMSUNG_USBPHY - bool "Samsung USB PHY controller Driver" - depends on USB_S3C_HSOTG || USB_EHCI_S5P || USB_OHCI_EXYNOS +config SAMSUNG_USB2PHY + tristate "Samsung USB 2.0 PHY controller Driver" + select SAMSUNG_USBPHY select USB_OTG_UTILS help - Enable this to support Samsung USB phy controller for samsung - SoCs. + Enable this to support Samsung USB 2.0 (High Speed) PHY controller + driver for Samsung SoCs. + +config SAMSUNG_USBPHY + tristate "Samsung USB PHY Driver" + help + Enable this to support Samsung USB phy helper driver for Samsung SoCs. + This driver provides common interface to interact, for Samsung USB 2.0 PHY + driver and later for Samsung USB 3.0 PHY driver. diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile index b13faa1..1efa174 100644 --- a/drivers/usb/phy/Makefile +++ b/drivers/usb/phy/Makefile @@ -12,3 +12,4 @@ obj-$(CONFIG_MV_U3D_PHY) += mv_u3d_phy.o obj-$(CONFIG_USB_EHCI_TEGRA) += tegra_usb_phy.o obj-$(CONFIG_USB_RCAR_PHY) += rcar-phy.o obj-$(CONFIG_SAMSUNG_USBPHY) += samsung-usbphy.o +obj-$(CONFIG_SAMSUNG_USB2PHY) += samsung-usb2phy.o diff --git a/drivers/usb/phy/samsung-usb2phy.c b/drivers/usb/phy/samsung-usb2phy.c new file mode 100644 index 000..55ac3a8 --- /dev/null +++ b/drivers/usb/phy/samsung-usb2phy.c @@ -0,0 +1,511 @@ +/* linux/drivers/usb/phy/samsung-usb2phy.c + * + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * http://www.samsung.com + * + * Author: Praveen Paneri + * + * Samsung USB2.0 PHY transceiver; talks to S3C HS OTG controller, EHCI-S5P and + * OHCI-EXYNOS controllers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "samsung-usbphy.h" + +int samsung_usb2phy_set_host(struct usb_otg *otg, struct usb_bus *host) +{ + if (!otg) + return -ENODEV; + + if (!otg->host) + otg->host = host; + + return 0; +} + +static bool exynos5_phyhost_is_on(void *regs) +{ + u32 reg; + + reg = readl(regs + EXYNOS5_PHY_HOST_CTRL0); + + return !(reg & HOST_CTRL0_SIDDQ); +} + +static void samsung_exynos5_usb2phy_enable(struct samsung_usbphy *sphy) +{ + void __iomem *regs = sphy->regs; + u32 phyclk = sphy->ref_clk_freq; + u32 phyhost; + u32 phyotg; + u32 phyhsic; + u32 ehcictrl; + u32 ohcictrl; + + /* +* phy_usage helps in keeping usage count for phy +* so that the first consumer enabling the phy is also +* the last consumer to disable it. +*/ + + atomic_inc(>phy_usage); + + if (exynos5_phyhost_is_on(regs)) { + dev_info(sphy->dev, "Already power on PHY\n"); + return; + } + + /* Host configuration */ + phyhost = readl(regs + EXYNOS5_PHY_HOST_CTRL0); + + /* phy reference clock configuration */ + phyhost &= ~HOST_CTRL0_FSEL_MASK; + phyhost |= HOST_CTRL0_FSEL(phyclk); + + /* host phy reset */ + phyhost &= ~(HOST_CTRL0_PHYSWRST | + HOST_CTRL0_PHYSWRSTALL | + HOST_CTRL0_SIDDQ | + /* Enable normal mode of operation */ + HOST_CTRL0_FORCESUSPEND | +
[PATCH v6 1/2] usb: phy: samsung: Common out the generic stuff
Moving register and structure definitions to header file, and keeping the generic functions to be used across multiple PHYs in common phy helper driver under SAMSUNG_USBPHY, and moving USB 2.0 PHY driver under SAMSUNG_USB2PHY. Also allowing samsung PHY drivers be built as modules. Signed-off-by: Vivek Gautam gautam.vi...@samsung.com Signed-off-by: Felipe Balbi ba...@ti.com Acked-by: Kukjin Kim kgene@samsung.com --- drivers/usb/phy/Kconfig | 17 +- drivers/usb/phy/Makefile |1 + drivers/usb/phy/samsung-usb2phy.c | 511 ++ drivers/usb/phy/samsung-usbphy.c | 722 + drivers/usb/phy/samsung-usbphy.h | 247 + 5 files changed, 785 insertions(+), 713 deletions(-) create mode 100644 drivers/usb/phy/samsung-usb2phy.c create mode 100644 drivers/usb/phy/samsung-usbphy.h diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig index 65217a5..4d72962 100644 --- a/drivers/usb/phy/Kconfig +++ b/drivers/usb/phy/Kconfig @@ -66,10 +66,17 @@ config USB_RCAR_PHY To compile this driver as a module, choose M here: the module will be called rcar-phy. -config SAMSUNG_USBPHY - bool Samsung USB PHY controller Driver - depends on USB_S3C_HSOTG || USB_EHCI_S5P || USB_OHCI_EXYNOS +config SAMSUNG_USB2PHY + tristate Samsung USB 2.0 PHY controller Driver + select SAMSUNG_USBPHY select USB_OTG_UTILS help - Enable this to support Samsung USB phy controller for samsung - SoCs. + Enable this to support Samsung USB 2.0 (High Speed) PHY controller + driver for Samsung SoCs. + +config SAMSUNG_USBPHY + tristate Samsung USB PHY Driver + help + Enable this to support Samsung USB phy helper driver for Samsung SoCs. + This driver provides common interface to interact, for Samsung USB 2.0 PHY + driver and later for Samsung USB 3.0 PHY driver. diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile index b13faa1..1efa174 100644 --- a/drivers/usb/phy/Makefile +++ b/drivers/usb/phy/Makefile @@ -12,3 +12,4 @@ obj-$(CONFIG_MV_U3D_PHY) += mv_u3d_phy.o obj-$(CONFIG_USB_EHCI_TEGRA) += tegra_usb_phy.o obj-$(CONFIG_USB_RCAR_PHY) += rcar-phy.o obj-$(CONFIG_SAMSUNG_USBPHY) += samsung-usbphy.o +obj-$(CONFIG_SAMSUNG_USB2PHY) += samsung-usb2phy.o diff --git a/drivers/usb/phy/samsung-usb2phy.c b/drivers/usb/phy/samsung-usb2phy.c new file mode 100644 index 000..55ac3a8 --- /dev/null +++ b/drivers/usb/phy/samsung-usb2phy.c @@ -0,0 +1,511 @@ +/* linux/drivers/usb/phy/samsung-usb2phy.c + * + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * http://www.samsung.com + * + * Author: Praveen Paneri p.pan...@samsung.com + * + * Samsung USB2.0 PHY transceiver; talks to S3C HS OTG controller, EHCI-S5P and + * OHCI-EXYNOS controllers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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/module.h +#include linux/platform_device.h +#include linux/clk.h +#include linux/delay.h +#include linux/device.h +#include linux/err.h +#include linux/io.h +#include linux/of.h +#include linux/usb/otg.h +#include linux/usb/samsung_usb_phy.h +#include linux/platform_data/samsung-usbphy.h + +#include samsung-usbphy.h + +int samsung_usb2phy_set_host(struct usb_otg *otg, struct usb_bus *host) +{ + if (!otg) + return -ENODEV; + + if (!otg-host) + otg-host = host; + + return 0; +} + +static bool exynos5_phyhost_is_on(void *regs) +{ + u32 reg; + + reg = readl(regs + EXYNOS5_PHY_HOST_CTRL0); + + return !(reg HOST_CTRL0_SIDDQ); +} + +static void samsung_exynos5_usb2phy_enable(struct samsung_usbphy *sphy) +{ + void __iomem *regs = sphy-regs; + u32 phyclk = sphy-ref_clk_freq; + u32 phyhost; + u32 phyotg; + u32 phyhsic; + u32 ehcictrl; + u32 ohcictrl; + + /* +* phy_usage helps in keeping usage count for phy +* so that the first consumer enabling the phy is also +* the last consumer to disable it. +*/ + + atomic_inc(sphy-phy_usage); + + if (exynos5_phyhost_is_on(regs)) { + dev_info(sphy-dev, Already power on PHY\n); + return; + } + + /* Host configuration */ + phyhost = readl(regs + EXYNOS5_PHY_HOST_CTRL0); + + /* phy reference clock configuration */ + phyhost = ~HOST_CTRL0_FSEL_MASK; + phyhost |= HOST_CTRL0_FSEL(phyclk); + + /* host phy reset */ +