From patchwork Fri Nov 1 19:45:57 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Porter X-Patchwork-Id: 3127521 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CF44C9F3C4 for ; Fri, 1 Nov 2013 19:59:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D7C4B204C9 for ; Fri, 1 Nov 2013 19:59:22 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AEE6120462 for ; Fri, 1 Nov 2013 19:59:21 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VcKhk-0004kU-Pc; Fri, 01 Nov 2013 19:48:26 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VcKh6-00084k-LI; Fri, 01 Nov 2013 19:47:44 +0000 Received: from mail-ie0-f177.google.com ([209.85.223.177]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VcKgB-0007uQ-Gg for linux-arm-kernel@lists.infradead.org; Fri, 01 Nov 2013 19:46:50 +0000 Received: by mail-ie0-f177.google.com with SMTP id e14so8094695iej.22 for ; Fri, 01 Nov 2013 12:46:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=361Xrv1twzrNuRxkh1ZWzHmkteTqSPbmzmJLkTU5tKo=; b=VntOq9Ypz0m3cHHtkAbJece2kpqUIfBdds3PnlJ09munk/oVps42QJDaqjo6Swddzv 92nGuvA8y5/WJJgMN/wGko2iwv7U+LixCjyW8Yl/Q7KMF5X6kC8vB5yezq9ENTX8NINe 6pcItu9lp+o/N5ccyZVAQ/NF1UkPZ0gVxFPPkZTfRU5XK7fR6NldS1aaqBH1NSqfYfVp 3PPH1Fk6+QuOjdg1CRcMt4Xqbb1KT14lwN3zcGvkbm62s3Fl2QfQQwWWVUZ8/qYO9zky z2RdQ+QmHAfJRIiHPDULbIUPha3pdzre09Irp1x+9GxiV3rmewpKYPkKXUcu2R4KaCLP CgHQ== X-Gm-Message-State: ALoCoQn/9716LW+BObC0kixS1D3UAwdgPWqrSu0up/A8rcN6Jb1CgOvRVH5pe6BDLEYZPLThzt2H X-Received: by 10.42.92.84 with SMTP id s20mr1338528icm.63.1383335188231; Fri, 01 Nov 2013 12:46:28 -0700 (PDT) Received: from beef.ohporter.com (cpe-98-27-254-98.neo.res.rr.com. [98.27.254.98]) by mx.google.com with ESMTPSA id f5sm5616338igc.4.2013.11.01.12.46.26 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 01 Nov 2013 12:46:27 -0700 (PDT) From: Matt Porter To: Felipe Balbi , Greg Kroah-Hartman , Kishon Vijay Abraham I , Rob Herring , Pawel Moll , Mark Rutland , Kumar Gala , Ian Campbell , Christian Daudt , Paul Zimmerman Subject: [PATCH v2 8/9] phy: add Broadcom Kona USB2 PHY driver Date: Fri, 1 Nov 2013 15:45:57 -0400 Message-Id: <1383335158-19730-9-git-send-email-matt.porter@linaro.org> X-Mailer: git-send-email 1.8.4 In-Reply-To: <1383335158-19730-1-git-send-email-matt.porter@linaro.org> References: <1383335158-19730-1-git-send-email-matt.porter@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131101_154647_740491_5F2E3E32 X-CRM114-Status: GOOD ( 17.98 ) X-Spam-Score: -2.6 (--) Cc: Devicetree List , Linux USB List , Linux Kernel Mailing List , Linux ARM Kernel List , Linaro Patches X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 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.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 internal Broadcom Kona USB 2.0 PHY found on the BCM281xx family of SoCs. Signed-off-by: Matt Porter --- drivers/phy/Kconfig | 6 ++ drivers/phy/Makefile | 2 + drivers/phy/phy-bcm-kona-usb2.c | 161 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 169 insertions(+) create mode 100644 drivers/phy/phy-bcm-kona-usb2.c diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig index 349bef2..cedada5 100644 --- a/drivers/phy/Kconfig +++ b/drivers/phy/Kconfig @@ -15,4 +15,10 @@ config GENERIC_PHY phy users can obtain reference to the PHY. All the users of this framework should select this config. +config BCM_KONA_USB2_PHY + tristate "Broadcom Kona USB2 PHY Driver" + depends on GENERIC_PHY + help + Enable this to support the Broadcom Kona USB 2.0 PHY. + endmenu diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile index 9e9560f..ce83a14 100644 --- a/drivers/phy/Makefile +++ b/drivers/phy/Makefile @@ -3,3 +3,5 @@ # obj-$(CONFIG_GENERIC_PHY) += phy-core.o + +obj-$(CONFIG_BCM_KONA_USB2_PHY) += phy-bcm-kona-usb2.o diff --git a/drivers/phy/phy-bcm-kona-usb2.c b/drivers/phy/phy-bcm-kona-usb2.c new file mode 100644 index 0000000..1beea7f --- /dev/null +++ b/drivers/phy/phy-bcm-kona-usb2.c @@ -0,0 +1,161 @@ +/* + * phy-bcm-kona-usb2.c - Broadcom Kona USB2 Phy Driver + * + * Copyright (C) 2013 Linaro Limited + * Matt Porter + * + * 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 +#include +#include +#include +#include +#include +#include +#include + +#define OTGCTL_OTGSTAT2 (1 << 31) +#define OTGCTL_OTGSTAT1 (1 << 30) +#define OTGCTL_PRST_N_SW (1 << 11) +#define OTGCTL_HRESET_N (1 << 10) +#define OTGCTL_UTMI_LINE_STATE1 (1 << 9) +#define OTGCTL_UTMI_LINE_STATE0 (1 << 8) + +#define P1CTL_SOFT_RESET (1 << 1) +#define P1CTL_NON_DRIVING (1 << 0) + +struct bcm_kona_usb_phy_regs { + u32 ctrl; + u32 cfg; + u32 p1ctl; + u32 status; + u32 bc_cfg; + u32 tp_in; + u32 tp_out; + u32 phy_ctrl; + u32 usbreg; + u32 usbproben; +}; + +struct bcm_kona_usb { + struct bcm_kona_usb_phy_regs *regs; +}; + +static void bcm_kona_usb_phy_power(struct bcm_kona_usb *phy, int on) +{ + u32 val; + + val = readl(&phy->regs->ctrl); + if (on) { + /* Configure and power PHY */ + val &= ~(OTGCTL_OTGSTAT2 | OTGCTL_OTGSTAT1 | + OTGCTL_UTMI_LINE_STATE1 | OTGCTL_UTMI_LINE_STATE0); + val |= OTGCTL_PRST_N_SW | OTGCTL_HRESET_N; + writel(val, &phy->regs->ctrl); + + /* Soft reset PHY */ + val = readl(&phy->regs->p1ctl); + val &= ~P1CTL_NON_DRIVING; + val |= P1CTL_SOFT_RESET; + writel(val, &phy->regs->p1ctl); + writel(val & ~P1CTL_SOFT_RESET, &phy->regs->p1ctl); + /* Reset needs to be asserted for 2ms */ + mdelay(2); + writel(val | P1CTL_SOFT_RESET, &phy->regs->p1ctl); + } else { + val &= ~(OTGCTL_PRST_N_SW | OTGCTL_HRESET_N); + writel(val, &phy->regs->ctrl); + } +} + +static int bcm_kona_usb_phy_power_on(struct phy *gphy) +{ + struct bcm_kona_usb *phy = phy_get_drvdata(gphy); + + bcm_kona_usb_phy_power(phy, 1); + + return 0; +} + +static int bcm_kona_usb_phy_power_off(struct phy *gphy) +{ + struct bcm_kona_usb *phy = phy_get_drvdata(gphy); + + bcm_kona_usb_phy_power(phy, 0); + + return 0; +} + +static struct phy_ops ops = { + .power_on = bcm_kona_usb_phy_power_on, + .power_off = bcm_kona_usb_phy_power_off, + .owner = THIS_MODULE, +}; + +static int bcm_kona_usb2_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct bcm_kona_usb *phy; + struct resource *res; + struct phy *gphy; + struct phy_provider *phy_provider; + + phy = devm_kzalloc(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); + + platform_set_drvdata(pdev, phy); + + phy_provider = devm_of_phy_provider_register(dev, + of_phy_simple_xlate); + if (IS_ERR(phy_provider)) + return PTR_ERR(phy_provider); + + gphy = devm_phy_create(dev, &ops, NULL); + if (IS_ERR(gphy)) + return PTR_ERR(gphy); + + /* The Kona PHY supports an 8-bit wide UTMI interface */ + phy_set_bus_width(gphy, 8); + + phy_set_drvdata(gphy, phy); + + return 0; +} + +static const struct of_device_id bcm_kona_usb2_dt_ids[] = { + { .compatible = "brcm,kona-usb2-phy" }, + { /* sentinel */ } +}; + +MODULE_DEVICE_TABLE(of, bcm_kona_usb2_dt_ids); + +static struct platform_driver bcm_kona_usb2_driver = { + .probe = bcm_kona_usb2_probe, + .driver = { + .name = "bcm-kona-usb2", + .owner = THIS_MODULE, + .of_match_table = bcm_kona_usb2_dt_ids, + }, +}; + +module_platform_driver(bcm_kona_usb2_driver); + +MODULE_ALIAS("platform:bcm-kona-usb2"); +MODULE_AUTHOR("Matt Porter"); +MODULE_DESCRIPTION("BCM Kona USB 2.0 PHY driver"); +MODULE_LICENSE("GPL v2");