From patchwork Tue May 15 13:58:19 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Zhao X-Patchwork-Id: 8657 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 3C5C423E13 for ; Tue, 15 May 2012 13:59:37 +0000 (UTC) Received: from mail-gg0-f180.google.com (mail-gg0-f180.google.com [209.85.161.180]) by fiordland.canonical.com (Postfix) with ESMTP id 0C374A183E5 for ; Tue, 15 May 2012 13:59:36 +0000 (UTC) Received: by mail-gg0-f180.google.com with SMTP id f1so4764722ggn.11 for ; Tue, 15 May 2012 06:59:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf :x-spamscore:x-bigfish:x-forefront-antispam-report:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :mime-version:content-type:x-originatororg:x-gm-message-state; bh=yw3OWpHM6TUTmDU7qC3xgQhnlHltFA8zmmWz2b8Dodc=; b=fH4eKHOYj0GAt7wlKEidB2I9pSFRtrXI5Qbkyr62YdWS1MJi+kebY1z1VJpYCqpD9E /0uvqj7UscB15kUzo3FbbcNigsE+L7LgxkHuhev0lqNKL9lM00XLUebXFISRna4c61ij +L1zEIHrtxq+2ch7d9oXo1o/eUtB5TXUt3gWe8bU+opyxXdphsjY2RqHApn1+up8ipMZ fc9BuPJdEXbnnGhs5wCgVsoMypEZzQ3S5dFgHmwBtU9BanibLwXW7GAWFN3DrQAMRIw7 axUZcPFp09dhG1iEnR54Hx1LVep6icm/vGqvnYku6sTRme9mKBkw267n+mfGiDTZ2UTA eJrA== Received: by 10.50.154.169 with SMTP id vp9mr7072827igb.53.1337090376553; Tue, 15 May 2012 06:59:36 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.35.72 with SMTP id o8csp422564ibd; Tue, 15 May 2012 06:59:35 -0700 (PDT) Received: by 10.213.32.10 with SMTP id a10mr464688ebd.93.1337090375373; Tue, 15 May 2012 06:59:35 -0700 (PDT) Received: from am1outboundpool.messaging.microsoft.com (am1ehsobe004.messaging.microsoft.com. [213.199.154.207]) by mx.google.com with ESMTPS id p8si23180400weh.0.2012.05.15.06.59.05 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 15 May 2012 06:59:35 -0700 (PDT) Received-SPF: neutral (google.com: 213.199.154.207 is neither permitted nor denied by best guess record for domain of B20223@freescale.com) client-ip=213.199.154.207; Authentication-Results: mx.google.com; spf=neutral (google.com: 213.199.154.207 is neither permitted nor denied by best guess record for domain of B20223@freescale.com) smtp.mail=B20223@freescale.com Received: from mail112-am1-R.bigfish.com (10.3.201.252) by AM1EHSOBE005.bigfish.com (10.3.204.25) with Microsoft SMTP Server id 14.1.225.23; Tue, 15 May 2012 13:58:59 +0000 Received: from mail112-am1 (localhost [127.0.0.1]) by mail112-am1-R.bigfish.com (Postfix) with ESMTP id 71B0B180171; Tue, 15 May 2012 13:58:59 +0000 (UTC) X-SpamScore: 0 X-BigFish: VS0(zzzz1202hzz8275bh8275dhz2dh2a8h668h839hd24he5bh) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI Received: from mail112-am1 (localhost.localdomain [127.0.0.1]) by mail112-am1 (MessageSwitch) id 1337090338407060_23625; Tue, 15 May 2012 13:58:58 +0000 (UTC) Received: from AM1EHSMHS007.bigfish.com (unknown [10.3.201.228]) by mail112-am1.bigfish.com (Postfix) with ESMTP id 5BE383400E9; Tue, 15 May 2012 13:58:58 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by AM1EHSMHS007.bigfish.com (10.3.207.107) with Microsoft SMTP Server (TLS) id 14.1.225.23; Tue, 15 May 2012 13:58:57 +0000 Received: from az33smr01.freescale.net (10.64.34.199) by 039-SN1MMR1-002.039d.mgd.msft.net (10.84.1.15) with Microsoft SMTP Server id 14.2.298.5; Tue, 15 May 2012 08:59:01 -0500 Received: from b20223-02.ap.freescale.net (b20223-02.ap.freescale.net [10.192.242.124]) by az33smr01.freescale.net (8.13.1/8.13.0) with ESMTP id q4FDwjZM003112; Tue, 15 May 2012 08:58:58 -0500 (CDT) From: Richard Zhao To: , CC: , , , , , , , , , Richard Zhao Subject: [PATCH v1 3/7] usb: chipidea: add imx on-soc utmi phy driver Date: Tue, 15 May 2012 21:58:19 +0800 Message-ID: <1337090303-16046-4-git-send-email-richard.zhao@freescale.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1337090303-16046-1-git-send-email-richard.zhao@freescale.com> References: <1337090303-16046-1-git-send-email-richard.zhao@freescale.com> MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-Gm-Message-State: ALoCoQkRKu2wRlC+/TxK/uRVTPLAVSGs/Gl8G8uF2Dhz8rcdfbcR6TAxLV0u8/D3JqKzlw7u40Sq Signed-off-by: Richard Zhao --- drivers/usb/chipidea/Makefile | 4 + drivers/usb/chipidea/phy-imx-utmi.c | 140 +++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+), 0 deletions(-) create mode 100644 drivers/usb/chipidea/phy-imx-utmi.c diff --git a/drivers/usb/chipidea/Makefile b/drivers/usb/chipidea/Makefile index cc34937..0f34c0c 100644 --- a/drivers/usb/chipidea/Makefile +++ b/drivers/usb/chipidea/Makefile @@ -12,3 +12,7 @@ endif ifneq ($(CONFIG_ARCH_MSM),) obj-$(CONFIG_USB_CHIPIDEA) += ci13xxx_msm.o endif + +ifneq ($(CONFIG_ARCH_MXC),) + obj-$(CONFIG_USB_CHIPIDEA) += phy-imx-utmi.o +endif diff --git a/drivers/usb/chipidea/phy-imx-utmi.c b/drivers/usb/chipidea/phy-imx-utmi.c new file mode 100644 index 0000000..f7a0fe7 --- /dev/null +++ b/drivers/usb/chipidea/phy-imx-utmi.c @@ -0,0 +1,140 @@ +/* + * Copyright 2012 Freescale Semiconductor, Inc. + * + * 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 + +#define DRIVER_NAME "imx_utmi" + +#define HW_USBPHY_PWD (0x00000000) +#define HW_USBPHY_CTRL 0x00000030 + +#define BM_USBPHY_CTRL_SFTRST 0x80000000 +#define BM_USBPHY_CTRL_CLKGATE 0x40000000 +#define BM_USBPHY_CTRL_ENUTMILEVEL3 0x00008000 +#define BM_USBPHY_CTRL_ENUTMILEVEL2 0x00004000 + +struct imx_utmi_phy { + struct usb_phy phy; + struct clk *clk; +}; + +#define to_imx_phy(p) container_of((p), struct imx_utmi_phy, phy) + +static int imx_utmi_phy_init(struct usb_phy *phy) +{ + struct imx_utmi_phy *imx_phy; + u32 reg; + + imx_phy = to_imx_phy(phy); + + clk_prepare_enable(imx_phy->clk); + + reg = readl_relaxed(phy->io_priv + HW_USBPHY_CTRL); + reg &= ~BM_USBPHY_CTRL_CLKGATE; + writel_relaxed(reg, phy->io_priv + HW_USBPHY_CTRL); + + /* Reset USBPHY module */ + reg = readl_relaxed(phy->io_priv + HW_USBPHY_CTRL); + reg |= BM_USBPHY_CTRL_SFTRST; + writel_relaxed(reg, phy->io_priv + HW_USBPHY_CTRL); + udelay(10); + + /* Remove CLKGATE and SFTRST */ + reg = readl_relaxed(phy->io_priv + HW_USBPHY_CTRL); + reg &= ~(BM_USBPHY_CTRL_CLKGATE | BM_USBPHY_CTRL_SFTRST); + writel_relaxed(reg, phy->io_priv + HW_USBPHY_CTRL); + udelay(10); + + /* Power up the PHY */ + writel_relaxed(0, phy->io_priv + HW_USBPHY_PWD); + /* enable FS/LS device */ + reg = readl_relaxed(phy->io_priv + HW_USBPHY_CTRL); + reg |= BM_USBPHY_CTRL_ENUTMILEVEL2 | BM_USBPHY_CTRL_ENUTMILEVEL3; + writel_relaxed(reg, phy->io_priv + HW_USBPHY_CTRL); + + return 0; +} + +static void imx_utmi_phy_shutdown(struct usb_phy *phy) +{ + struct imx_utmi_phy *imx_phy; + + imx_phy = to_imx_phy(phy); + clk_disable_unprepare(imx_phy->clk); +} + +static int imx_utmi_probe(struct platform_device *pdev) +{ + struct resource *res; + void __iomem *base; + struct clk *clk; + struct imx_utmi_phy *imx_phy; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) { + dev_err(&pdev->dev, "can't get device resources\n"); + return -ENOENT; + } + + base = devm_request_and_ioremap(&pdev->dev, res); + if (!base) + return -EBUSY; + + clk = devm_clk_get(&pdev->dev, NULL); + if (IS_ERR(clk)) + return PTR_ERR(clk); + + imx_phy = devm_kzalloc(&pdev->dev, sizeof(*imx_phy), GFP_KERNEL); + if (!imx_phy) + return -ENOMEM; + + imx_phy->phy.io_priv = base; + imx_phy->phy.dev = &pdev->dev; + imx_phy->phy.label = DRIVER_NAME; + imx_phy->phy.init = imx_utmi_phy_init; + imx_phy->phy.shutdown = imx_utmi_phy_shutdown; + imx_phy->clk = clk; + platform_set_drvdata(pdev, &imx_phy->phy); + + return 0; +} + +static const struct of_device_id imx_utmi_dt_ids[] = { + { .compatible = "fsl,imx6q-usbphy", }, + { /* sentinel */ } +}; + +static struct platform_driver imx_utmi_driver = { + .probe = imx_utmi_probe, + .driver = { + .name = DRIVER_NAME, + .of_match_table = imx_utmi_dt_ids, + }, +}; + +static int __init imx_utmi_init(void) +{ + return platform_driver_register(&imx_utmi_driver); +} +postcore_initcall(imx_utmi_init); + +static void __exit imx_utmi_exit(void) +{ + platform_driver_unregister(&imx_utmi_driver); +} +module_exit(imx_utmi_exit);