From patchwork Thu Dec 19 14:23:09 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Porter X-Patchwork-Id: 22637 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f69.google.com (mail-pa0-f69.google.com [209.85.220.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 73BAC23FCA for ; Thu, 19 Dec 2013 14:23:40 +0000 (UTC) Received: by mail-pa0-f69.google.com with SMTP id hz1sf3070741pad.4 for ; Thu, 19 Dec 2013 06:23:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=bOv0jGB6f03k3+RbI9cpGSHtBEywcc6ALyMxu1oytmM=; b=YVuK5DzO7Sip+gA01j5sxrCgpJ5aDNYwqawVNYuIYsaGdrECtfyWsoD3ujEmdFbv8K z+cXFQd1l5hkBj/cbnVTzsi1d2gxorEgNLioMBo9BqlHJ7zZ+LViGon92gL92k2r8HQu u1WgdTaLSTcpv3H0PF4bCOkrDjvc3vPt1m2aDJYW96vghrb9uV/+KwVKBkCSZnXC9c2t TMaKUQMQZe37dU0dynHbvpJDx3Haj4U0ZpINvkvIXOlqkYCfMSYUOuEPm8X/ch/o9Jpt DA0ZvQZk1vf8fGGMZxWEFfE2NWNAU0I5oaeBhDyh/WQvqDi0OqorsW8zUVBLBVZVItX9 vsfA== X-Gm-Message-State: ALoCoQkB1OLDjUvngJj8hC7KHk9ATWUXC6JBvsq8leOPZAH8DBrBAkqbSEImH45qgVvzrjlwO9T8 X-Received: by 10.66.190.38 with SMTP id gn6mr929606pac.30.1387463019764; Thu, 19 Dec 2013 06:23:39 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.76.72 with SMTP id i8ls371857qew.59.gmail; Thu, 19 Dec 2013 06:23:39 -0800 (PST) X-Received: by 10.58.133.137 with SMTP id pc9mr5603veb.53.1387463019498; Thu, 19 Dec 2013 06:23:39 -0800 (PST) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by mx.google.com with ESMTPS id sl9si721963vdc.112.2013.12.19.06.23.39 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 19 Dec 2013 06:23:39 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.174 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.174; Received: by mail-vc0-f174.google.com with SMTP id if17so169285vcb.19 for ; Thu, 19 Dec 2013 06:23:39 -0800 (PST) X-Received: by 10.220.58.1 with SMTP id e1mr1150001vch.0.1387463019406; Thu, 19 Dec 2013 06:23:39 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.59.13.131 with SMTP id ey3csp323648ved; Thu, 19 Dec 2013 06:23:38 -0800 (PST) X-Received: by 10.42.24.138 with SMTP id w10mr1251029icb.22.1387463018408; Thu, 19 Dec 2013 06:23:38 -0800 (PST) Received: from mail-ie0-f172.google.com (mail-ie0-f172.google.com [209.85.223.172]) by mx.google.com with ESMTPS id sa19si4558609igc.34.2013.12.19.06.23.38 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 19 Dec 2013 06:23:38 -0800 (PST) Received-SPF: neutral (google.com: 209.85.223.172 is neither permitted nor denied by best guess record for domain of mporter@linaro.org) client-ip=209.85.223.172; Received: by mail-ie0-f172.google.com with SMTP id qd12so1380793ieb.17 for ; Thu, 19 Dec 2013 06:23:38 -0800 (PST) X-Received: by 10.50.110.74 with SMTP id hy10mr3074286igb.0.1387463018122; Thu, 19 Dec 2013 06:23:38 -0800 (PST) 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 l7sm5656642igx.2.2013.12.19.06.23.36 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 19 Dec 2013 06:23:37 -0800 (PST) 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 Cc: Tomasz Figa , Kamil Debski , Kyungmin Park , Dinh Nguyen , Russell King , Linux USB List , Linux ARM Kernel List , Linux Kernel Mailing List , Devicetree List , Linaro Patches Subject: [PATCH v8 8/9] phy: add Broadcom Kona USB2 PHY driver Date: Thu, 19 Dec 2013 09:23:09 -0500 Message-Id: <1387462990-12039-9-git-send-email-mporter@linaro.org> X-Mailer: git-send-email 1.8.4 In-Reply-To: <1387462990-12039-1-git-send-email-mporter@linaro.org> References: <1387462990-12039-1-git-send-email-mporter@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: mporter@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.174 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 | 1 + drivers/phy/phy-bcm-kona-usb2.c | 158 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 165 insertions(+) create mode 100644 drivers/phy/phy-bcm-kona-usb2.c diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig index a344f3d..2e87fa8 100644 --- a/drivers/phy/Kconfig +++ b/drivers/phy/Kconfig @@ -51,4 +51,10 @@ config PHY_EXYNOS_DP_VIDEO help Support for Display Port PHY found on Samsung EXYNOS SoCs. +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 d0caae9..c447f1a 100644 --- a/drivers/phy/Makefile +++ b/drivers/phy/Makefile @@ -3,6 +3,7 @@ # obj-$(CONFIG_GENERIC_PHY) += phy-core.o +obj-$(CONFIG_BCM_KONA_USB2_PHY) += phy-bcm-kona-usb2.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_OMAP_USB2) += phy-omap-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..efc5c1a --- /dev/null +++ b/drivers/phy/phy-bcm-kona-usb2.c @@ -0,0 +1,158 @@ +/* + * 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 (0) +#define OTGCTL_OTGSTAT2 BIT(31) +#define OTGCTL_OTGSTAT1 BIT(30) +#define OTGCTL_PRST_N_SW BIT(11) +#define OTGCTL_HRESET_N BIT(10) +#define OTGCTL_UTMI_LINE_STATE1 BIT(9) +#define OTGCTL_UTMI_LINE_STATE0 BIT(8) + +#define P1CTL (8) +#define P1CTL_SOFT_RESET BIT(1) +#define P1CTL_NON_DRIVING BIT(0) + +struct bcm_kona_usb { + void __iomem *regs; +}; + +static void bcm_kona_usb_phy_power(struct bcm_kona_usb *phy, int on) +{ + u32 val; + + val = readl(phy->regs + OTGCTL); + 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; + } else { + val &= ~(OTGCTL_PRST_N_SW | OTGCTL_HRESET_N); + } + writel(val, phy->regs + OTGCTL); +} + +static int bcm_kona_usb_phy_init(struct phy *gphy) +{ + struct bcm_kona_usb *phy = phy_get_drvdata(gphy); + u32 val; + + /* 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); + + return 0; +} + +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 = { + .init = bcm_kona_usb_phy_init, + .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); + + 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); + + phy_provider = devm_of_phy_provider_register(dev, + of_phy_simple_xlate); + if (IS_ERR(phy_provider)) + return PTR_ERR(phy_provider); + + 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");