From patchwork Thu Feb 5 14:47:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangfei Gao X-Patchwork-Id: 44464 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0255E21173 for ; Thu, 5 Feb 2015 14:47:46 +0000 (UTC) Received: by mail-lb0-f200.google.com with SMTP id u14sf849404lbd.3 for ; Thu, 05 Feb 2015 06:47:45 -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:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=jZ1BNfjV1BUbxz1uy96RhL2GpRcq8774XnkVoZZukIg=; b=alA6CgYDN8Z8Ejse824W95tVznwGlyjYdKHAj2doN85zLFSHNKVN68Y2R/Xzf69OVc PAT18dDf5sIbpPwV1pdWV6/yAjqxEfPx5FrSafySuz1XzbyZmDbOTwqfaX/BSJgpi+KO doH8x6tt3Sft3q4+AxRDtkhL9UAgsta9pwnsoCEzA48bNs0nTX6tin9UwXPNbdYYlM3O w6dkijngmjevZv1u1hfAPaldTqw2u7G/Ll6lXrJDdv4uv4cdMpJRGmmENGIymAt/osT2 HCIXncDm1B77I5h5ybbWd9LtWNG5m3Ruhj1U5lI99WvB9oNc8NjNc4wCTIr4RqgHxv36 vitA== X-Gm-Message-State: ALoCoQkZHn23YRroqYYj6ndqXP/Re6I0OjQkeJYDsnlZY/jtcpQ4RTnqRUczWqEVmGjtjxLGTbRW X-Received: by 10.194.221.65 with SMTP id qc1mr542319wjc.7.1423147664965; Thu, 05 Feb 2015 06:47:44 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.26.74 with SMTP id j10ls170774lag.7.gmail; Thu, 05 Feb 2015 06:47:44 -0800 (PST) X-Received: by 10.112.184.198 with SMTP id ew6mr3869797lbc.71.1423147664680; Thu, 05 Feb 2015 06:47:44 -0800 (PST) Received: from mail-lb0-f180.google.com (mail-lb0-f180.google.com. [209.85.217.180]) by mx.google.com with ESMTPS id dw2si4115706lbc.62.2015.02.05.06.47.44 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Feb 2015 06:47:44 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) client-ip=209.85.217.180; Received: by mail-lb0-f180.google.com with SMTP id b6so7895521lbj.11 for ; Thu, 05 Feb 2015 06:47:44 -0800 (PST) X-Received: by 10.152.45.100 with SMTP id l4mr409644lam.112.1423147664549; Thu, 05 Feb 2015 06:47:44 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp1186383lbj; Thu, 5 Feb 2015 06:47:43 -0800 (PST) X-Received: by 10.69.1.7 with SMTP id bc7mr1443718pbd.121.1423147661798; Thu, 05 Feb 2015 06:47:41 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id rn9si6284062pbc.203.2015.02.05.06.47.40; Thu, 05 Feb 2015 06:47:41 -0800 (PST) Received-SPF: none (google.com: devicetree-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757800AbbBEOrj (ORCPT + 5 others); Thu, 5 Feb 2015 09:47:39 -0500 Received: from mail-pd0-f178.google.com ([209.85.192.178]:36615 "EHLO mail-pd0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757633AbbBEOri (ORCPT ); Thu, 5 Feb 2015 09:47:38 -0500 Received: by pdev10 with SMTP id v10so8157826pde.3 for ; Thu, 05 Feb 2015 06:47:37 -0800 (PST) X-Received: by 10.70.134.97 with SMTP id pj1mr6064894pdb.125.1423147657870; Thu, 05 Feb 2015 06:47:37 -0800 (PST) Received: from localhost.localdomain (119.81.172.112-static.reverse.softlayer.com. [119.81.172.112]) by mx.google.com with ESMTPSA id rb3sm5353511pab.29.2015.02.05.06.47.32 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 05 Feb 2015 06:47:36 -0800 (PST) From: Zhangfei Gao To: balbi@ti.com, john.youn@synopsys.com, Mian Yousaf Kaukab , "dan . zhao" Cc: linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-usb@vger.kernel.org, Zhangfei Gao Subject: [PATCH 4/4] usb: phy: add phy-hi6220 Date: Thu, 5 Feb 2015 22:47:00 +0800 Message-Id: <1423147620-5760-5-git-send-email-zhangfei.gao@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1423147620-5760-1-git-send-email-zhangfei.gao@linaro.org> References: <1423147620-5760-1-git-send-email-zhangfei.gao@linaro.org> Sender: devicetree-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: devicetree@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: zhangfei.gao@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Add usb phy controller for hi6220 platform Signed-off-by: Zhangfei Gao --- drivers/usb/phy/Kconfig | 9 ++ drivers/usb/phy/Makefile | 1 + drivers/usb/phy/phy-hi6220.c | 290 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 300 insertions(+) create mode 100644 drivers/usb/phy/phy-hi6220.c diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig index c6d0c8e..405a3d0 100644 --- a/drivers/usb/phy/Kconfig +++ b/drivers/usb/phy/Kconfig @@ -173,6 +173,15 @@ config USB_MXS_PHY MXS Phy is used by some of the i.MX SoCs, for example imx23/28/6x. +config USB_HI6220_PHY + tristate "hi6220 USB PHY support" + select USB_PHY + select MFD_SYSCON + help + Enable this to support the HISILICON HI6220 USB PHY. + + To compile this driver as a module, choose M here. + config USB_RCAR_PHY tristate "Renesas R-Car USB PHY support" depends on USB || USB_GADGET diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile index 75f2bba..819283c 100644 --- a/drivers/usb/phy/Makefile +++ b/drivers/usb/phy/Makefile @@ -18,6 +18,7 @@ obj-$(CONFIG_SAMSUNG_USBPHY) += phy-samsung-usb.o obj-$(CONFIG_TWL6030_USB) += phy-twl6030-usb.o obj-$(CONFIG_USB_EHCI_TEGRA) += phy-tegra-usb.o obj-$(CONFIG_USB_GPIO_VBUS) += phy-gpio-vbus-usb.o +obj-$(CONFIG_USB_HI6220_PHY) += phy-hi6220.o obj-$(CONFIG_USB_ISP1301) += phy-isp1301.o obj-$(CONFIG_USB_MSM_OTG) += phy-msm-usb.o obj-$(CONFIG_USB_MV_OTG) += phy-mv-usb.o diff --git a/drivers/usb/phy/phy-hi6220.c b/drivers/usb/phy/phy-hi6220.c new file mode 100644 index 0000000..87b1f0e --- /dev/null +++ b/drivers/usb/phy/phy-hi6220.c @@ -0,0 +1,290 @@ +/* + * Copyright (c) 2015 Linaro Ltd. + * Copyright (c) 2015 Hisilicon Limited. + * + * 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. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define SC_PERIPH_CTRL4 0x00c + +#define PERIPH_CTRL4_PICO_SIDDQ BIT(6) +#define PERIPH_CTRL4_PICO_OGDISABLE BIT(8) +#define PERIPH_CTRL4_PICO_VBUSVLDEXT BIT(10) +#define PERIPH_CTRL4_PICO_VBUSVLDEXTSEL BIT(11) +#define PERIPH_CTRL4_OTG_PHY_SEL BIT(21) + +#define SC_PERIPH_CTRL5 0x010 + +#define PERIPH_CTRL5_USBOTG_RES_SEL BIT(3) +#define PERIPH_CTRL5_PICOPHY_ACAENB BIT(4) +#define PERIPH_CTRL5_PICOPHY_BC_MODE BIT(5) +#define PERIPH_CTRL5_PICOPHY_CHRGSEL BIT(6) +#define PERIPH_CTRL5_PICOPHY_VDATSRCEND BIT(7) +#define PERIPH_CTRL5_PICOPHY_VDATDETENB BIT(8) +#define PERIPH_CTRL5_PICOPHY_DCDENB BIT(9) +#define PERIPH_CTRL5_PICOPHY_IDDIG BIT(10) + +#define SC_PERIPH_CTRL8 0x018 + +#define EYE_PATTERN_PARA 0x7053348c + +#define SC_PERIPH_RSTDIS0 0x304 + +#define PERIPH_RSTDIS0_USBOTG_BUS BIT(4) +#define PERIPH_RSTDIS0_POR_PICOPHY BIT(5) +#define PERIPH_RSTDIS0_USBOTG BIT(6) +#define PERIPH_RSTDIS0_USBOTG_32K BIT(7) + +enum usb_mode { + USB_EMPTY, + GADGET_DEVICE, + OTG_HOST, +}; + +struct hi6220_priv { + struct usb_phy phy; + struct delayed_work work; + struct regmap *reg; + struct clk *clk; + struct regulator *vcc; + int gpio_vbus_det; + int gpio_id_det; + enum usb_mode mode; +}; + +static void hi6220_start_periphrals(struct hi6220_priv *priv, bool on) +{ + struct usb_otg *otg = priv->phy.otg; + + if (!otg->gadget) + return; + + if (on) + usb_gadget_connect(otg->gadget); + else + usb_gadget_disconnect(otg->gadget); +} + +static void hi6220_detect_work(struct work_struct *work) +{ + struct hi6220_priv *priv = + container_of(work, struct hi6220_priv, work.work); + int id_det, vbus_det; + enum usb_mode mode; + + if (!gpio_is_valid(priv->gpio_id_det) || + !gpio_is_valid(priv->gpio_vbus_det)) + return; + + id_det = gpio_get_value_cansleep(priv->gpio_id_det); + vbus_det = gpio_get_value_cansleep(priv->gpio_vbus_det); + + if (vbus_det == 0) { + if (id_det == 1) + mode = GADGET_DEVICE; + else + mode = OTG_HOST; + } else { + mode = USB_EMPTY; + } + + if (mode == GADGET_DEVICE && priv->mode == USB_EMPTY) + hi6220_start_periphrals(priv, true); + if (mode == USB_EMPTY && priv->mode == GADGET_DEVICE) + hi6220_start_periphrals(priv, false); + + priv->mode = mode; +} + +static irqreturn_t hiusb_gpio_intr(int irq, void *data) +{ + struct hi6220_priv *priv = (struct hi6220_priv *)data; + + /* add debounce time */ + schedule_delayed_work(&priv->work, msecs_to_jiffies(100)); + return IRQ_HANDLED; +} + +static int mv_otg_set_peripheral(struct usb_otg *otg, + struct usb_gadget *gadget) +{ + struct hi6220_priv *priv; + + priv = container_of(otg->usb_phy, struct hi6220_priv, phy); + otg->gadget = gadget; + return 0; +} + +static void hi6220_phy_setup(struct hi6220_priv *priv) +{ + u32 val, mask; + int ret; + + if (priv->reg == NULL) + return; + + val = PERIPH_RSTDIS0_USBOTG_BUS | PERIPH_RSTDIS0_POR_PICOPHY | + PERIPH_RSTDIS0_USBOTG | PERIPH_RSTDIS0_USBOTG_32K; + mask = val; + ret = regmap_update_bits(priv->reg, SC_PERIPH_RSTDIS0, mask, val); + if (ret) + return; + + ret = regmap_read(priv->reg, SC_PERIPH_CTRL5, &val); + val = PERIPH_CTRL5_USBOTG_RES_SEL | PERIPH_CTRL5_PICOPHY_ACAENB; + mask = val | PERIPH_CTRL5_PICOPHY_BC_MODE; + ret = regmap_update_bits(priv->reg, SC_PERIPH_CTRL5, mask, val); + if (ret) + return; + + val = PERIPH_CTRL4_PICO_VBUSVLDEXT | PERIPH_CTRL4_PICO_VBUSVLDEXTSEL | + PERIPH_CTRL4_OTG_PHY_SEL; + mask = val | PERIPH_CTRL4_PICO_SIDDQ | PERIPH_CTRL4_PICO_OGDISABLE; + ret = regmap_update_bits(priv->reg, SC_PERIPH_CTRL4, mask, val); + if (ret) + return; + + ret = regmap_write(priv->reg, SC_PERIPH_CTRL8, EYE_PATTERN_PARA); + if (ret) + return; +} + +static int hi6220_phy_probe(struct platform_device *pdev) +{ + struct hi6220_priv *priv; + struct usb_otg *otg; + struct device_node *np = pdev->dev.of_node; + int ret, irq; + + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + otg = devm_kzalloc(&pdev->dev, sizeof(*otg), GFP_KERNEL); + if (!otg) + return -ENOMEM; + + priv->phy.dev = &pdev->dev; + priv->phy.otg = otg; + priv->phy.label = "hi6220"; + platform_set_drvdata(pdev, priv); + otg->set_peripheral = mv_otg_set_peripheral; + + priv->gpio_vbus_det = of_get_named_gpio(np, "hisilicon,gpio_vbus_det", 0); + if (priv->gpio_vbus_det == -EPROBE_DEFER) + return -EPROBE_DEFER; + if (!gpio_is_valid(priv->gpio_vbus_det)) { + dev_err(&pdev->dev, "invalid gpio %d\n", priv->gpio_vbus_det); + return -ENODEV; + } + + priv->gpio_id_det = of_get_named_gpio(np, "hisilicon,gpio_id_det", 0); + if (priv->gpio_id_det == -EPROBE_DEFER) + return -EPROBE_DEFER; + if (!gpio_is_valid(priv->gpio_id_det)) { + dev_err(&pdev->dev, "invalid gpio %d\n", priv->gpio_id_det); + return -ENODEV; + } + + priv->reg = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, + "hisilicon,peripheral-syscon"); + if (IS_ERR(priv->reg)) + priv->reg = NULL; + + INIT_DELAYED_WORK(&priv->work, hi6220_detect_work); + + ret = devm_gpio_request_one(&pdev->dev, priv->gpio_vbus_det, + GPIOF_IN, "gpio_vbus_det"); + if (ret < 0) { + dev_err(&pdev->dev, "gpio request failed for gpio_vbus_det\n"); + return ret; + } + + ret = devm_gpio_request_one(&pdev->dev, priv->gpio_id_det, + GPIOF_IN, "gpio_id_det"); + if (ret < 0) { + dev_err(&pdev->dev, "gpio request failed for gpio_id_det\n"); + return ret; + } + + priv->vcc = devm_regulator_get(&pdev->dev, "vcc"); + if (!IS_ERR(priv->vcc)) { + ret = regulator_enable(priv->vcc); + if (ret) { + dev_err(&pdev->dev, "Failed to enable regulator\n"); + return -ENODEV; + } + } + + priv->clk = devm_clk_get(&pdev->dev, NULL); + if (IS_ERR(priv->clk)) { + regulator_disable(priv->vcc); + return PTR_ERR(priv->clk); + } + clk_prepare_enable(priv->clk); + + irq = gpio_to_irq(priv->gpio_vbus_det); + ret = devm_request_irq(&pdev->dev, gpio_to_irq(priv->gpio_vbus_det), + hiusb_gpio_intr, IRQF_NO_SUSPEND | + IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, + "vbus_gpio_intr", priv); + if (ret) { + dev_err(&pdev->dev, "request gpio irq failed.\n"); + goto err_irq; + } + + hi6220_phy_setup(priv); + ret = usb_add_phy(&priv->phy, USB_PHY_TYPE_USB2); + if (ret) { + dev_err(&pdev->dev, "Can't register transceiver\n"); + goto err_irq; + } + schedule_delayed_work(&priv->work, 0); + + return 0; +err_irq: + clk_disable_unprepare(priv->clk); + regulator_disable(priv->vcc); + return ret; +} + +static int hi6220_phy_remove(struct platform_device *pdev) +{ + struct hi6220_priv *priv = platform_get_drvdata(pdev); + + clk_disable_unprepare(priv->clk); + regulator_disable(priv->vcc); + return 0; +} + +static const struct of_device_id hi6220_phy_of_match[] = { + {.compatible = "hisilicon,hi6220-usb-phy",}, + { }, +}; +MODULE_DEVICE_TABLE(of, hi6220_phy_of_match); + +static struct platform_driver hi6220_phy_driver = { + .probe = hi6220_phy_probe, + .remove = hi6220_phy_remove, + .driver = { + .name = "hi6220-usb-phy", + .of_match_table = hi6220_phy_of_match, + } +}; +module_platform_driver(hi6220_phy_driver); + +MODULE_DESCRIPTION("HISILICON HI6220 USB PHY driver"); +MODULE_ALIAS("platform:hi6220-usb-phy"); +MODULE_LICENSE("GPL");