From patchwork Fri Mar 27 04:36:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baruch Siach X-Patchwork-Id: 6103421 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5BE7BBF90F for ; Fri, 27 Mar 2015 04:41:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 311602042B for ; Fri, 27 Mar 2015 04:41:56 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D7EB820429 for ; Fri, 27 Mar 2015 04:41:54 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YbM2T-00013P-03; Fri, 27 Mar 2015 04:38:33 +0000 Received: from guitar.tcltek.co.il ([192.115.133.116] helo=mx.tkos.co.il) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YbM25-0000qR-G7 for linux-arm-kernel@lists.infradead.org; Fri, 27 Mar 2015 04:38:11 +0000 Received: from tarshish.tkos.co.il (unknown [10.0.8.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mx.tkos.co.il (Postfix) with ESMTPSA id 54EF344073C; Fri, 27 Mar 2015 07:37:44 +0300 (IDT) From: Baruch Siach To: Kishon Vijay Abraham I Subject: [PATCH 2/2] phy: driver for Conexant Digicolor internal USB PHY Date: Fri, 27 Mar 2015 07:36:29 +0300 Message-Id: <4a9ceb0a240d49dd6a68d50c78f85d310d4b932f.1427430989.git.baruch@tkos.co.il> X-Mailer: git-send-email 2.1.4 In-Reply-To: <6284a7672647d46100281959552f9787f98bb552.1427430989.git.baruch@tkos.co.il> References: <6284a7672647d46100281959552f9787f98bb552.1427430989.git.baruch@tkos.co.il> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150326_213810_062470_7EE043B0 X-CRM114-Status: GOOD ( 16.60 ) X-Spam-Score: 0.0 (/) Cc: Marek Vasut , devicetree@vger.kernel.org, Baruch Siach , linux-kernel@vger.kernel.org, Richard Zhao , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add a driver for the USB PHY on the Conexant CX92755 SoC, from the Digicolor series of SoCs. The PHY is connected to the on-chip chipidea usb2 host. The hardware is somewhat similar to the phy-mxs-usb.c usb_phy, but it is different enough to merit its own driver. Also, this driver uses the generic phy infrastructure. Cc: Marek Vasut Cc: Richard Zhao Signed-off-by: Baruch Siach --- drivers/phy/Kconfig | 9 ++ drivers/phy/Makefile | 1 + drivers/phy/phy-digicolor-usb.c | 209 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 219 insertions(+) create mode 100644 drivers/phy/phy-digicolor-usb.c diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig index 2962de205ba7..9589056ef5c7 100644 --- a/drivers/phy/Kconfig +++ b/drivers/phy/Kconfig @@ -291,4 +291,13 @@ config PHY_QCOM_UFS help Support for UFS PHY on QCOM chipsets. +config PHY_DIGICOLOR_USB + tristate "Conexant Digicolor USB2 PHY Driver" + depends on ARCH_DIGICOLOR + select GENERIC_PHY + select USB_PHY + help + Enable this to support the USB 2.0 PHY that is part of Conexant + Digicolor SoC series. + endmenu diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile index f080e1bb2a74..392cb60d0240 100644 --- a/drivers/phy/Makefile +++ b/drivers/phy/Makefile @@ -38,3 +38,4 @@ obj-$(CONFIG_PHY_STIH41X_USB) += phy-stih41x-usb.o obj-$(CONFIG_PHY_QCOM_UFS) += phy-qcom-ufs.o obj-$(CONFIG_PHY_QCOM_UFS) += phy-qcom-ufs-qmp-20nm.o obj-$(CONFIG_PHY_QCOM_UFS) += phy-qcom-ufs-qmp-14nm.o +obj-$(CONFIG_PHY_DIGICOLOR_USB) += phy-digicolor-usb.o diff --git a/drivers/phy/phy-digicolor-usb.c b/drivers/phy/phy-digicolor-usb.c new file mode 100644 index 000000000000..a1d7503530a0 --- /dev/null +++ b/drivers/phy/phy-digicolor-usb.c @@ -0,0 +1,209 @@ +/* + * Conexant Digicolor Integrated USB PHY driver + * + * Copyright (C) 2014, 2015 Paradox Innovation Ltd. + * + * Author: Baruch Siach + * + * Based on phy-mxs-usb.c. + * + * Copyright 2012-2014 Freescale Semiconductor, Inc. + * Copyright (C) 2012 Marek Vasut + * on behalf of DENX Software Engineering GmbH + * + * The code contained herein is licensed under the GNU General Public + * License. You may obtain a copy of the GNU General Public License + * Version 2 or later at the following locations: + * + * http://www.opensource.org/licenses/gpl-license.html + * http://www.gnu.org/copyleft/gpl.html + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DRIVER_NAME "digicolor_usb_phy" + +#define HW_USBPHY_PWD 0x00 +#define HW_USBPHY_TX 0x10 +#define HW_USBPHY_CTRL 0x30 +#define HW_USBPHY_CTRL_SET 0x34 +#define HW_USBPHY_CTRL_CLR 0x38 + +#define HW_USBPHY_DEBUG 0x50 + +#define HW_USBPHY_IP 0x90 +#define HW_USBPHY_IP_SET 0x94 +#define HW_USBPHY_IP_CLR 0x98 + +#define BM_USBPHY_CTRL_SFTRST BIT(31) +#define BM_USBPHY_CTRL_CLKGATE BIT(30) +#define BM_USBPHY_CTRL_ENHOSTDISCONDETECT BIT(1) + +#define BM_USBPHY_IP_EN_USB_CLKS BIT(2) +#define BM_USBPHY_IP_PLL_LOCKED BIT(1) +#define BM_USBPHY_IP_PLL_POWER BIT(0) + +struct dc_usb_phy { + struct usb_phy phy; + struct device *dev; + void __iomem *regs; +}; + +static int digicolor_phy_init(struct phy *gphy) +{ + struct dc_usb_phy *phy = phy_get_drvdata(gphy); + + /* Disable PLL */ + writel(BM_USBPHY_IP_EN_USB_CLKS, phy->regs + HW_USBPHY_IP_CLR); + udelay(250); + writel(BM_USBPHY_IP_PLL_LOCKED, phy->regs + HW_USBPHY_IP_CLR); + udelay(250); + writel(BM_USBPHY_IP_PLL_POWER, phy->regs + HW_USBPHY_IP_CLR); + udelay(250); + + /* Reset PHY */ + writel(BM_USBPHY_CTRL_SFTRST, phy->regs + HW_USBPHY_CTRL_SET); + udelay(1000); + writel(BM_USBPHY_CTRL_SFTRST, phy->regs + HW_USBPHY_CTRL_CLR); + udelay(1000); + + /* Enable PHY clock */ + writel(BM_USBPHY_CTRL_CLKGATE, phy->regs + HW_USBPHY_CTRL_CLR); + udelay(250); + + /* Enable PLL */ + writel(BM_USBPHY_IP_PLL_POWER, phy->regs + HW_USBPHY_IP_SET); + udelay(250); + writel(BM_USBPHY_IP_PLL_LOCKED, phy->regs + HW_USBPHY_IP_SET); + udelay(250); + writel(BM_USBPHY_IP_EN_USB_CLKS, phy->regs + HW_USBPHY_IP_SET); + udelay(250); + + /* Power PHY up */ + writel(0, phy->regs + HW_USBPHY_PWD); + udelay(250); + + /* Set resistors parameters (power up default values) */ + writel(0x10060607, phy->regs + HW_USBPHY_TX); + writel(0x7f180000, phy->regs + HW_USBPHY_DEBUG); + + return 0; +} + +static int digicolor_phy_shutdown(struct phy *gphy) +{ + struct dc_usb_phy *phy = phy_get_drvdata(gphy); + + writel(BM_USBPHY_CTRL_CLKGATE, phy->regs + HW_USBPHY_CTRL_SET); + + return 0; +} + +static struct phy_ops dc_usb_phy_ops = { + .owner = THIS_MODULE, + .init = digicolor_phy_init, + .power_off = digicolor_phy_shutdown, +}; + +static int digicolor_phy_on_connect(struct usb_phy *phy, + enum usb_device_speed speed) +{ + dev_dbg(phy->dev, "%s device has connected\n", + (speed == USB_SPEED_HIGH) ? "HS" : "FS/LS"); + + if (speed == USB_SPEED_HIGH) + writel(BM_USBPHY_CTRL_ENHOSTDISCONDETECT, + phy->io_priv + HW_USBPHY_CTRL_SET); + + return 0; +} + +static int digicolor_phy_on_disconnect(struct usb_phy *phy, + enum usb_device_speed speed) +{ + dev_dbg(phy->dev, "%s device has disconnected\n", + (speed == USB_SPEED_HIGH) ? "HS" : "FS/LS"); + + if (speed == USB_SPEED_HIGH) + writel(BM_USBPHY_CTRL_ENHOSTDISCONDETECT, + phy->io_priv + HW_USBPHY_CTRL_CLR); + + return 0; +} + +static int digicolor_phy_probe(struct platform_device *pdev) +{ + struct resource *res; + struct dc_usb_phy *phy; + struct phy *generic_phy; + struct phy_provider *phy_provider; + + phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL); + if (!phy) + return -ENOMEM; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + phy->regs = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(phy->regs)) + return PTR_ERR(phy->regs); + + phy->dev = &pdev->dev; + + phy->phy.io_priv = phy->regs; + phy->phy.dev = &pdev->dev; + phy->phy.label = DRIVER_NAME; + phy->phy.notify_connect = digicolor_phy_on_connect; + phy->phy.notify_disconnect = digicolor_phy_on_disconnect; + phy->phy.type = USB_PHY_TYPE_USB2; + + platform_set_drvdata(pdev, phy); + + generic_phy = devm_phy_create(phy->dev, NULL, &dc_usb_phy_ops); + if (IS_ERR(generic_phy)) + return PTR_ERR(generic_phy); + phy_set_drvdata(generic_phy, phy); + + phy_provider = devm_of_phy_provider_register(phy->dev, + of_phy_simple_xlate); + if (IS_ERR(phy_provider)) + return PTR_ERR(phy_provider); + + return usb_add_phy_dev(&phy->phy); +} + +static int digicolor_phy_remove(struct platform_device *pdev) +{ + struct dc_usb_phy *phy = platform_get_drvdata(pdev); + + usb_remove_phy(&phy->phy); + + return 0; +} + +static const struct of_device_id digicolor_phy_dt_ids[] = { + { .compatible = "cnxt,cx92755-usbphy", }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, digicolor_phy_dt_ids); + +static struct platform_driver digicolor_phy_driver = { + .probe = digicolor_phy_probe, + .remove = digicolor_phy_remove, + .driver = { + .name = DRIVER_NAME, + .of_match_table = digicolor_phy_dt_ids, + }, +}; +module_platform_driver(digicolor_phy_driver); + +MODULE_ALIAS("platform:digicolor-usb-phy"); +MODULE_DESCRIPTION("Conexant Digicolor Internal USB PHY driver"); +MODULE_LICENSE("GPL");