From patchwork Wed Jun 21 09:00:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiancheng Xue X-Patchwork-Id: 9801349 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AE30260329 for ; Wed, 21 Jun 2017 09:40:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5132A28508 for ; Wed, 21 Jun 2017 09:40:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 44D8628564; Wed, 21 Jun 2017 09:40:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7DF9B28508 for ; Wed, 21 Jun 2017 09:40:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=lEB8stjStFaW8rGteBFyaVfwy6QVGk7jMwPYuAHGNYM=; b=P7jUS5Mgoi9juO 0paX6s6oaKEIg4y7PpQMQ1AM0RyXZqc7w4hfNhM9RXgj9dtx0vGeRxThRnOOGXyPb6yyGAQyYaUBM sM+hTSJluNCHnJObd4Q04Nink+xXL/JoVJ6k0Xmgtr6FF21umPI/uGxqNZA0PgNeCLFSjJngyP+4v pq2yjyKGCjJmnuDq28F2+ZJ7OcdLSH53tjIAQs0Gho8/DrZARPowiwUD8hJbEYVFpg260Lgo5D2At 2MbuojqMsshp45x5ZSYdquQwKmGOvB7gTuwcbHJoXgJWYhPKWXiHhzE9ehbvXFTxw2hh7H/44wdGU 9l1P8lDE+M8tje0+jcHA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dNc7h-0001IV-U6; Wed, 21 Jun 2017 09:40:29 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dNc7b-0007vk-4g for linux-arm-kernel@bombadil.infradead.org; Wed, 21 Jun 2017 09:40:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:CC:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=rkA6VCjUTMVGdB68kt+zQWee75geFwESkQTHTidoXxE=; b=dmkC5u2VDWtnvsqHNTSIlpKUq epQf/f9y6yqXX7G/deMOTorR1ssV2LDp60xDBqW8BEZMMJbI8sDrAMJjmkP+aoEwNA7oVFlHQ3o28 yZ6axB31jACc5uGQnPpiIFCHZx1cCt8CTmuraIgg1T7hMvUbFt2mxcMOdxZCE3Er8ipdDkgNkUpWb dSFHZCPiMNbxMbc0YlmzgV9fH9L8/YdyAaO08BGn1wgTeSmhk2aWR6YiaXUnY7miiobiu+40A6Aem 4zDmanRqjXqEQtMWQ3rI1WVMHxJjgdki0jAsL5e0vTg1JZg2sORLVtTekq6W6UGZmiArFFSijYs3r mI8vWHFfw==; Received: from szxga02-in.huawei.com ([45.249.212.188]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dNbzi-0004KQ-4R for linux-arm-kernel@lists.infradead.org; Wed, 21 Jun 2017 09:32:17 +0000 Received: from 172.30.72.53 (EHLO DGGEML401-HUB.china.huawei.com) ([172.30.72.53]) by dggrg02-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id APT48851; Wed, 21 Jun 2017 17:23:12 +0800 (CST) Received: from wind-Tecal-RH2285.huawei.com (10.67.212.71) by DGGEML401-HUB.china.huawei.com (10.3.17.32) with Microsoft SMTP Server id 14.3.301.0; Wed, 21 Jun 2017 17:23:02 +0800 From: Jiancheng Xue To: , , , , , Subject: [PATCH 3/5] phy: add inno-usb2-phy driver for hi3798cv200 SoC Date: Wed, 21 Jun 2017 17:00:43 +0800 Message-ID: <1498035645-22804-4-git-send-email-xuejiancheng@hisilicon.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1498035645-22804-1-git-send-email-xuejiancheng@hisilicon.com> References: <1498035645-22804-1-git-send-email-xuejiancheng@hisilicon.com> MIME-Version: 1.0 X-Originating-IP: [10.67.212.71] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090202.594A3B02.011B, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 29b54fa53f7f84e4d05f1ccc6881f1f8 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170621_103215_391767_A00ADEA8 X-CRM114-Status: GOOD ( 26.07 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, project-aspen-dev@linaro.org, yanhaifeng@hisilicon.com, Jiancheng Xue , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Pengcheng Li Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Pengcheng Li Add inno-usb2-phy driver for hi3798cv200 SoC. Signed-off-by: Pengcheng Li Signed-off-by: Jiancheng Xue --- drivers/phy/Kconfig | 10 ++ drivers/phy/Makefile | 1 + drivers/phy/phy-hisi-inno-usb2.c | 287 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 298 insertions(+) create mode 100644 drivers/phy/phy-hisi-inno-usb2.c diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig index afaf7b6..f86b9b7 100644 --- a/drivers/phy/Kconfig +++ b/drivers/phy/Kconfig @@ -225,6 +225,16 @@ config PHY_EXYNOS5250_SATA SATA 3.0 Gb/s, SATA 6.0 Gb/s speeds. It supports one SATA host port to accept one SATA device. +config PHY_HISI_INNO_USB2 + tristate "HiSilicon INNO USB2 PHY support" + depends on (ARCH_HISI) || COMPILE_TEST + select GENERIC_PHY + select MFD_SYSCON + help + Support for INNO USB2 PHY on HiSilicon SoCs. This Phy supports + USB 1.5Mb/s, USB 12Mb/s, USB 480Mb/s speeds. It supports one + USB host port to accept one USB device. + config PHY_HIX5HD2_SATA tristate "HIX5HD2 SATA PHY Driver" depends on ARCH_HIX5HD2 && OF && HAS_IOMEM diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile index f8047b4..a275547 100644 --- a/drivers/phy/Makefile +++ b/drivers/phy/Makefile @@ -27,6 +27,7 @@ obj-$(CONFIG_TWL4030_USB) += phy-twl4030-usb.o obj-$(CONFIG_PHY_EXYNOS5250_SATA) += phy-exynos5250-sata.o obj-$(CONFIG_PHY_HIX5HD2_SATA) += phy-hix5hd2-sata.o obj-$(CONFIG_PHY_HI6220_USB) += phy-hi6220-usb.o +obj-$(CONFIG_PHY_HISI_INNO_USB2) += phy-hisi-inno-usb2.o obj-$(CONFIG_PHY_MT65XX_USB3) += phy-mt65xx-usb3.o obj-$(CONFIG_PHY_SUN4I_USB) += phy-sun4i-usb.o obj-$(CONFIG_PHY_SUN9I_USB) += phy-sun9i-usb.o diff --git a/drivers/phy/phy-hisi-inno-usb2.c b/drivers/phy/phy-hisi-inno-usb2.c new file mode 100644 index 0000000..582c500 --- /dev/null +++ b/drivers/phy/phy-hisi-inno-usb2.c @@ -0,0 +1,287 @@ +/* + * HiSilicon INNO USB2 PHY Driver. + * + * Copyright (c) 2016-2017 HiSilicon Technologies Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX_PORTS 4 +#define REF_CLK_STABLE_TIME 100 /*unit:us*/ +#define UTMI_CLK_STABLE_TIME 200 /*unit:us*/ +#define UTMI_RST_COMPLETE_TIME 200 /*unit:us*/ +#define PORT_RST_COMPLETE_TIME 2 /*unit:ms*/ +#define TEST_RST_COMPLETE_TIME 100 /*unit:us*/ +#define POR_RST_COMPLETE_TIME 300 /*unit:us*/ + + +struct hisi_inno_phy_port { + struct clk *utmi_clk; + struct reset_control *port_rst; + struct reset_control *utmi_rst; +}; + +struct hisi_inno_phy_priv { + struct regmap *reg_peri; + struct clk *ref_clk; + struct reset_control *test_rst; + struct reset_control *por_rst; + const struct reg_sequence *reg_seq; + u32 reg_num; + struct hisi_inno_phy_port *ports; + u8 port_num; +}; + +#define HI3798CV200_PERI_USB0 0x120 +static const struct reg_sequence hi3798cv200_reg_seq[] = { + { HI3798CV200_PERI_USB0, 0x00a00604, }, + { HI3798CV200_PERI_USB0, 0x00e00604, }, + { HI3798CV200_PERI_USB0, 0x00a00604, 1000 }, +}; + +static int hisi_inno_phy_setup(struct hisi_inno_phy_priv *priv) +{ + return regmap_multi_reg_write_bypassed(priv->reg_peri, + priv->reg_seq, priv->reg_num); +} + +static int hisi_inno_port_init(struct hisi_inno_phy_port *port) +{ + int ret; + + reset_control_deassert(port->port_rst); + msleep(PORT_RST_COMPLETE_TIME); + + ret = clk_prepare_enable(port->utmi_clk); + if (ret) + return ret; + udelay(UTMI_CLK_STABLE_TIME); + + reset_control_deassert(port->utmi_rst); + udelay(UTMI_RST_COMPLETE_TIME); + + return 0; +} + +static int hisi_inno_phy_init(struct phy *phy) +{ + struct hisi_inno_phy_priv *priv = phy_get_drvdata(phy); + int ret, port; + + ret = clk_prepare_enable(priv->ref_clk); + if (ret) + return ret; + udelay(REF_CLK_STABLE_TIME); + + if (priv->test_rst) { + reset_control_deassert(priv->test_rst); + udelay(TEST_RST_COMPLETE_TIME); + } + + reset_control_deassert(priv->por_rst); + udelay(POR_RST_COMPLETE_TIME); + + /* config phy clk and phy eye diagram */ + ret = hisi_inno_phy_setup(priv); + if (ret) + goto err_disable_ref_clk; + + for (port = 0; port < priv->port_num; port++) { + ret = hisi_inno_port_init(&priv->ports[port]); + if (ret) + goto err_disable_clks; + } + + return 0; + +err_disable_clks: + while (--port >= 0) + clk_disable_unprepare(priv->ports[port].utmi_clk); +err_disable_ref_clk: + clk_disable_unprepare(priv->ref_clk); + + return ret; +} + +static void hisi_inno_phy_disable(struct phy *phy) +{ + struct hisi_inno_phy_priv *priv = phy_get_drvdata(phy); + int i; + + for (i = 0; i < priv->port_num; i++) + clk_disable_unprepare(priv->ports[i].utmi_clk); + + clk_disable_unprepare(priv->ref_clk); +} + +static int hisi_inno_phy_of_get_ports(struct device *dev, + struct hisi_inno_phy_priv *priv) +{ + struct device_node *node = dev->of_node; + struct device_node *child; + int port = 0; + int ret; + + priv->port_num = of_get_child_count(node); + if (priv->port_num > MAX_PORTS) { + dev_err(dev, "too many ports : %d (max = %d)\n", + priv->port_num, MAX_PORTS); + return -EINVAL; + } + + priv->ports = devm_kcalloc(dev, priv->port_num, + sizeof(struct hisi_inno_phy_port), GFP_KERNEL); + if (!priv->ports) + return -ENOMEM; + + for_each_child_of_node(node, child) { + struct hisi_inno_phy_port *phy_port = &priv->ports[port]; + + phy_port->utmi_clk = devm_get_clk_from_child(dev, child, NULL); + if (IS_ERR(phy_port->utmi_clk)) { + ret = PTR_ERR(phy_port->utmi_clk); + goto fail; + } + + phy_port->port_rst = of_reset_control_get_exclusive(child, "port_rst"); + if (IS_ERR(phy_port->port_rst)) { + ret = PTR_ERR(phy_port->port_rst); + goto fail; + } + + phy_port->utmi_rst = of_reset_control_get_exclusive(child, "utmi_rst"); + if (IS_ERR(phy_port->utmi_rst)) { + ret = PTR_ERR(phy_port->utmi_rst); + reset_control_put(phy_port->port_rst); + goto fail; + } + port++; + } + + return 0; + +fail: + while (--port >= 0) { + struct hisi_inno_phy_port *phy_port = &priv->ports[port]; + + reset_control_put(phy_port->utmi_rst); + reset_control_put(phy_port->port_rst); + clk_put(phy_port->utmi_clk); + } + of_node_put(child); + + return ret; +} + +static int hisi_inno_phy_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct phy *phy; + struct hisi_inno_phy_priv *priv; + struct device_node *node = dev->of_node; + int ret = 0; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + if (of_device_is_compatible(node, "hisilicon,hi3798cv200-usb2-phy")) { + priv->reg_seq = hi3798cv200_reg_seq; + priv->reg_num = sizeof(hi3798cv200_reg_seq) + / sizeof(struct reg_sequence); + } + + priv->reg_peri = syscon_regmap_lookup_by_phandle(node, + "hisilicon,peripheral-syscon"); + if (IS_ERR(priv->reg_peri)) { + dev_err(dev, "no hisilicon,peripheral-syscon\n"); + return PTR_ERR(priv->reg_peri); + } + + priv->ref_clk = devm_clk_get(dev, NULL); + if (IS_ERR(priv->ref_clk)) + return PTR_ERR(priv->ref_clk); + + priv->por_rst = devm_reset_control_get_exclusive(dev, "por_rst"); + if (IS_ERR(priv->por_rst)) + return PTR_ERR(priv->por_rst); + + priv->test_rst = devm_reset_control_get_optional_exclusive(dev, "test_rst"); + if (IS_ERR(priv->test_rst)) + return PTR_ERR(priv->test_rst); + + ret = hisi_inno_phy_of_get_ports(dev, priv); + if (ret) + return ret; + + phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); + if (!phy) + return -ENOMEM; + + platform_set_drvdata(pdev, phy); + phy_set_drvdata(phy, priv); + + return hisi_inno_phy_init(phy); +} + +#ifdef CONFIG_PM_SLEEP +static int hisi_inno_phy_suspend(struct device *dev) +{ + struct phy *phy = dev_get_drvdata(dev); + + hisi_inno_phy_disable(phy); + + return 0; +} + +static int hisi_inno_phy_resume(struct device *dev) +{ + struct phy *phy = dev_get_drvdata(dev); + + return hisi_inno_phy_init(phy); +} +#endif /* CONFIG_PM_SLEEP */ + +static const struct dev_pm_ops hisi_inno_phy_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(hisi_inno_phy_suspend, hisi_inno_phy_resume) +}; + +static const struct of_device_id hisi_inno_phy_of_match[] = { + {.compatible = "hisilicon,inno-usb2-phy",}, + {.compatible = "hisilicon,hi3798cv200-usb2-phy",}, + { }, +}; +MODULE_DEVICE_TABLE(of, hisi_inno_phy_of_match); + +static struct platform_driver hisi_inno_phy_driver = { + .probe = hisi_inno_phy_probe, + .driver = { + .name = "hisi-inno-phy", + .of_match_table = hisi_inno_phy_of_match, + .pm = &hisi_inno_phy_pm_ops, + } +}; +module_platform_driver(hisi_inno_phy_driver); + +MODULE_DESCRIPTION("HiSilicon INNO USB2 PHY Driver"); +MODULE_LICENSE("GPL v2");