From patchwork Fri Oct 16 07:36:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?V2VpamllIEdhbyAo6auY5oOf5p2wKQ==?= X-Patchwork-Id: 1383158 X-Patchwork-Delegate: daniel.schwierzeck@googlemail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=mediatek.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=mediatek.com header.i=@mediatek.com header.a=rsa-sha256 header.s=dk header.b=kMDpPA6p; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CCJ160Hpsz9sTq for ; Fri, 16 Oct 2020 18:38:34 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E284A823C9; Fri, 16 Oct 2020 09:36:58 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=mediatek.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=mediatek.com header.i=@mediatek.com header.b="kMDpPA6p"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 52ABB823FC; Fri, 16 Oct 2020 09:36:57 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=0.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MIME_BASE64_TEXT,RDNS_NONE,SPF_HELO_NONE, UNPARSEABLE_RELAY,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from mailgw02.mediatek.com (unknown [1.203.163.81]) by phobos.denx.de (Postfix) with ESMTP id 4677B8244B for ; Fri, 16 Oct 2020 09:36:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=mediatek.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=weijie.gao@mediatek.com X-UUID: e29d230194714f6486b98d704376df59-20201016 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=UEQW21SKDVVap808CrY2s1bGVC+gsDYSHYUssrtY1nQ=; b=kMDpPA6pCDkenwd6lIIfFevNiPA1xMdzlv4lgYCOI6w1eO/dWwEuf1MygKnEgrfA4ZhWJ4BzTq5Bcdd9pGV0jfZ1oogz4ALAbtiCt7EXuJqNbq6RX2xnWY1+YS7mTKX9umgP8N9D23eG9IEozEogIoyv4DGzKojFwwoB04VzjIg=; X-UUID: e29d230194714f6486b98d704376df59-20201016 Received: from mtkcas35.mediatek.inc [(172.27.4.253)] by mailgw02.mediatek.com (envelope-from ) (mailgw01.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 461737506; Fri, 16 Oct 2020 15:36:49 +0800 Received: from MTKCAS32.mediatek.inc (172.27.4.184) by MTKMBS31N1.mediatek.inc (172.27.4.69) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 16 Oct 2020 15:36:47 +0800 Received: from mcddlt001.mediatek.inc (10.19.240.15) by MTKCAS32.mediatek.inc (172.27.4.170) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Fri, 16 Oct 2020 15:36:47 +0800 From: Weijie Gao To: CC: GSS_MTK_Uboot_upstream , Daniel Schwierzeck , Stefan Roese , Stefan Roese , Stefan Roese , Neil Armstrong , Robert Marko , Kever Yang , Jagan Teki , Srinath Mannam , Beniamino Galvani , Rayagonda Kokatanur , Weijie Gao Subject: [PATCH 15/18] phy: add USB PHY driver for MediaTek MT7620 SoC Date: Fri, 16 Oct 2020 15:36:46 +0800 Message-ID: <1602833806-19628-1-git-send-email-weijie.gao@mediatek.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-TM-SNTS-SMTP: 9673A53D82A1A6601DFCC3B1DAD7CE15217DD3853533914FF5D0CA1A6EDDFE4D2000:8 X-MTK: N X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean This patch adds USB PHY driver for MediaTek MT7620 SoC Signed-off-by: Weijie Gao --- drivers/phy/Kconfig | 7 +++ drivers/phy/Makefile | 1 + drivers/phy/mt7620-usb-phy.c | 108 +++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 drivers/phy/mt7620-usb-phy.c diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig index d12a6b02ad..ab638f0e7d 100644 --- a/drivers/phy/Kconfig +++ b/drivers/phy/Kconfig @@ -218,6 +218,13 @@ config KEYSTONE_USB_PHY This PHY is found on some Keystone (K2) devices supporting USB. +config MT7620_USB_PHY + bool "MediaTek MT7620 USB PHY support" + depends on PHY + depends on SOC_MT7620 + help + Support the intergated USB PHY in MediaTek MT7620 SoC + config MT76X8_USB_PHY bool "MediaTek MT76x8 (7628/88) USB PHY support" depends on PHY diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile index 45a7fe5b56..6b3761b8c8 100644 --- a/drivers/phy/Makefile +++ b/drivers/phy/Makefile @@ -24,6 +24,7 @@ obj-$(CONFIG_MESON_G12A_USB_PHY) += meson-g12a-usb2.o meson-g12a-usb3-pcie.o obj-$(CONFIG_MSM8916_USB_PHY) += msm8916-usbh-phy.o obj-$(CONFIG_OMAP_USB2_PHY) += omap-usb2-phy.o obj-$(CONFIG_KEYSTONE_USB_PHY) += keystone-usb-phy.o +obj-$(CONFIG_MT7620_USB_PHY) += mt7620-usb-phy.o obj-$(CONFIG_MT76X8_USB_PHY) += mt76x8-usb-phy.o obj-$(CONFIG_PHY_DA8XX_USB) += phy-da8xx-usb.o obj-$(CONFIG_PHY_MTK_TPHY) += phy-mtk-tphy.o diff --git a/drivers/phy/mt7620-usb-phy.c b/drivers/phy/mt7620-usb-phy.c new file mode 100644 index 0000000000..294ee166af --- /dev/null +++ b/drivers/phy/mt7620-usb-phy.c @@ -0,0 +1,108 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2020 MediaTek Inc. All Rights Reserved. + * + * Author: Weijie Gao + */ + +#include +#include +#include +#include +#include +#include +#include + +struct mt7620_usb_phy { + struct udevice *sysc; + struct clk_bulk clocks; + struct reset_ctl_bulk resets; +}; + +static int mt7620_usb_phy_power_on(struct phy *_phy) +{ + struct mt7620_usb_phy *phy = dev_get_priv(_phy->dev); + u32 mode = MT7620_SYSC_USB_HOST_MODE; + int ret; + + reset_deassert_bulk(&phy->resets); + + clk_enable_bulk(&phy->clocks); + + mdelay(10); + + ret = misc_ioctl(phy->sysc, MT7620_SYSC_IOCTL_SET_USB_MODE, &mode); + if (ret) { + dev_err(dev, "mt7620_usbphy: failed to set USB host mode\n"); + return ret; + } + + mdelay(10); + + return 0; +} + +static int mt7620_usb_phy_power_off(struct phy *_phy) +{ + struct mt7620_usb_phy *phy = dev_get_priv(_phy->dev); + + clk_disable_bulk(&phy->clocks); + + reset_assert_bulk(&phy->resets); + + return 0; +} + +static int mt7620_usb_phy_probe(struct udevice *dev) +{ + struct mt7620_usb_phy *phy = dev_get_priv(dev); + struct ofnode_phandle_args sysc_args; + int ret; + + ret = ofnode_parse_phandle_with_args(dev->node, "mediatek,sysc", NULL, + 0, 0, &sysc_args); + if (ret) { + dev_err(dev, "mt7620_usbphy: sysc property not found\n"); + return ret; + } + + ret = uclass_get_device_by_ofnode(UCLASS_MISC, sysc_args.node, + &phy->sysc); + if (ret) { + dev_err(dev, "mt7620_usbphy: failed to sysc device\n"); + return ret; + } + + ret = clk_get_bulk(dev, &phy->clocks); + if (ret) { + dev_err(dev, "mt7620_usbphy: failed to get clocks\n"); + return ret; + } + + ret = reset_get_bulk(dev, &phy->resets); + if (ret) { + dev_err(dev, "mt7620_usbphy: failed to get reset control\n"); + return ret; + } + + return 0; +} + +static struct phy_ops mt7620_usb_phy_ops = { + .power_on = mt7620_usb_phy_power_on, + .power_off = mt7620_usb_phy_power_off, +}; + +static const struct udevice_id mt7620_usb_phy_ids[] = { + { .compatible = "mediatek,mt7620-usbphy" }, + { } +}; + +U_BOOT_DRIVER(mt7620_usb_phy) = { + .name = "mt7620_usb_phy", + .id = UCLASS_PHY, + .of_match = mt7620_usb_phy_ids, + .ops = &mt7620_usb_phy_ops, + .probe = mt7620_usb_phy_probe, + .priv_auto_alloc_size = sizeof(struct mt7620_usb_phy), +};