From patchwork Tue Mar 26 15:15:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 1065712 X-Patchwork-Delegate: lukma@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="I2uKvZk1"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44TF9l5Cqhz9sNf for ; Wed, 27 Mar 2019 02:17:31 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 68941C21E02; Tue, 26 Mar 2019 15:16:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 97720C21E52; Tue, 26 Mar 2019 15:15:57 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 78FD2C21DE8; Tue, 26 Mar 2019 15:15:49 +0000 (UTC) Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by lists.denx.de (Postfix) with ESMTPS id 9E63DC21E0D for ; Tue, 26 Mar 2019 15:15:44 +0000 (UTC) Received: by mail-wm1-f68.google.com with SMTP id o25so13036506wmf.5 for ; Tue, 26 Mar 2019 08:15:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0mggUSjmXFXGcVUCUiWN0uenJecDUdG1SsbVKs0JHcU=; b=I2uKvZk1EFPXMReOBEowIh5rYjmgxTOgnRkBAqXhkWn4eXlzT7MPelKx2gjOQFqPJ0 VGrpM7vIrhLyAMrYwQpm7SckyvloxE6y61nC//Qovy1nBUTfza2dOk0bAd1ibNvfvWny Cy7JSq+C9pfNfWP8NHVajpzDTtbg4kVtsUbJhMTlu3PR5MH2WDUg456d+jOl4QXWwaga SDoa7xdnoIY2yMdS1loZoCQNZexsHe1rZ4dzVA3nZy+lzzH5LJdDgzYp8SApq/9BhaUy VU0RAj/dIPsCqacSWqhWqgFNkQzJrgcuSPKMHZMmaztVUZu/k0D9YA8gWLSWbhHUUKpg zMBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0mggUSjmXFXGcVUCUiWN0uenJecDUdG1SsbVKs0JHcU=; b=ZwQjllIVWZkWLdv/cInS08FZ90j9p9zFC79aj5IciBkstm2DHWXjgznWd+ZhUy2T1O JCUYinHF/CNJhmLhH7CvBTyAU2EbGnFKEbGKl7pu/XtqQjPhgVcKRZKoDjAWjTdyootc ZsP0Bbh6Wp2mn+tYKa7SS6eUmggTJ6FGuiQRb0Gswl5OUS/4eHW5o2i+aYHneLaUYehJ lx2nrz6MXXS5Pnjs0FJVYXpe5jyPQzP3qku9zg37xn88fJF01Tas3TEv+qjHnC0NQPOj D+Ww+H7UgDsCqPzV+TU1oa75hxjGSjDI4Uv3M9Kct5L7Kr2fo9G9cGG6x1cxiHMT/yFZ UC3w== X-Gm-Message-State: APjAAAWb1RkExFRJUPON378WNX6aFh7MGydCjS6BeEfR0/RtfagQfE03 MaEY1n5UCeUXvR3RPz8pXWPcKg== X-Google-Smtp-Source: APXvYqxK6HnEp4xfnLyPxSqrR/q/Mx4WGOScXTEZy5u5Ev+Cn4l1WsjmHYWl4liKTUYB6nAigfR7+g== X-Received: by 2002:a1c:80cd:: with SMTP id b196mr9397738wmd.84.1553613344128; Tue, 26 Mar 2019 08:15:44 -0700 (PDT) Received: from localhost.localdomain (wal59-h01-176-150-251-154.dsl.sta.abo.bbox.fr. [176.150.251.154]) by smtp.gmail.com with ESMTPSA id e12sm21282537wrt.94.2019.03.26.08.15.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 26 Mar 2019 08:15:43 -0700 (PDT) From: Neil Armstrong To: marex@denx.de Date: Tue, 26 Mar 2019 16:15:37 +0100 Message-Id: <20190326151537.23118-4-narmstrong@baylibre.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190326151537.23118-1-narmstrong@baylibre.com> References: <20190326151537.23118-1-narmstrong@baylibre.com> MIME-Version: 1.0 Cc: u-boot@lists.denx.de, u-boot-amlogic@groups.io Subject: [U-Boot] [PATCH 3/3] mach-meson: g12a: add DWC2 peripheral mode support X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" Adds support for Amlogic G12A USB Device mode. The DWC2 Controller behind the Glue can be connected to an OTG capable PHY. The Glue setups the PHY mode. This patch implements Device mode support by adding a board_usb_init/cleanup setting up the DWC2 controller and switch the OTG capable port to Device before starting the DWC2 controller in Device mode. Signed-off-by: Neil Armstrong --- arch/arm/include/asm/arch-meson/usb.h | 12 +++ arch/arm/mach-meson/board-g12a.c | 126 ++++++++++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 arch/arm/include/asm/arch-meson/usb.h diff --git a/arch/arm/include/asm/arch-meson/usb.h b/arch/arm/include/asm/arch-meson/usb.h new file mode 100644 index 0000000000..b794b5ce77 --- /dev/null +++ b/arch/arm/include/asm/arch-meson/usb.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (C) 2019 BayLibre, SAS + * Author: Neil Armstrong + */ + +#ifndef __MESON_USB_H__ +#define __MESON_USB_H__ + +int dwc3_meson_g12a_force_mode(struct udevice *dev, enum usb_dr_mode mode); + +#endif /* __MESON_USB_H__ */ diff --git a/arch/arm/mach-meson/board-g12a.c b/arch/arm/mach-meson/board-g12a.c index fc3764b960..1652970fbd 100644 --- a/arch/arm/mach-meson/board-g12a.c +++ b/arch/arm/mach-meson/board-g12a.c @@ -12,7 +12,12 @@ #include #include #include +#include +#include +#include +#include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -148,3 +153,124 @@ void meson_eth_init(phy_interface_t mode, unsigned int flags) /* Enable power gate */ clrbits_le32(G12A_MEM_PD_REG_0, G12A_MEM_PD_REG_0_ETH_MASK); } + +#if CONFIG_IS_ENABLED(USB_DWC3_MESON_G12A) && \ + CONFIG_IS_ENABLED(USB_GADGET_DWC2_OTG) +static struct dwc2_plat_otg_data meson_g12a_dwc2_data; + +int board_usb_init(int index, enum usb_init_type init) +{ + struct fdtdec_phandle_args args; + const void *blob = gd->fdt_blob; + int node, dwc2_node; + struct udevice *dev, *clk_dev; + struct clk clk; + int ret; + + /* find the usb glue node */ + node = fdt_node_offset_by_compatible(blob, -1, + "amlogic,meson-g12a-usb-ctrl"); + if (node < 0) { + debug("Not found usb-control node\n"); + return -ENODEV; + } + + if (!fdtdec_get_is_enabled(blob, node)) { + debug("usb is disabled in the device tree\n"); + return -ENODEV; + } + + ret = uclass_get_device_by_of_offset(UCLASS_SIMPLE_BUS, node, &dev); + if (ret) { + debug("Not found usb-control device\n"); + return ret; + } + + /* find the dwc2 node */ + dwc2_node = fdt_node_offset_by_compatible(blob, node, + "amlogic,meson-g12a-usb"); + if (dwc2_node < 0) { + debug("Not found dwc2 node\n"); + return -ENODEV; + } + + if (!fdtdec_get_is_enabled(blob, dwc2_node)) { + debug("dwc2 is disabled in the device tree\n"); + return -ENODEV; + } + + meson_g12a_dwc2_data.regs_otg = fdtdec_get_addr(blob, dwc2_node, "reg"); + if (meson_g12a_dwc2_data.regs_otg == FDT_ADDR_T_NONE) { + debug("usbotg: can't get base address\n"); + return -ENODATA; + } + + /* Enable clock */ + ret = fdtdec_parse_phandle_with_args(blob, dwc2_node, "clocks", + "#clock-cells", 0, 0, &args); + if (ret) { + debug("usbotg has no clocks defined in the device tree\n"); + return ret; + } + + ret = uclass_get_device_by_of_offset(UCLASS_CLK, args.node, &clk_dev); + if (ret) + return ret; + + if (args.args_count != 1) { + debug("Can't find clock ID in the device tree\n"); + return -ENODATA; + } + + clk.dev = clk_dev; + clk.id = args.args[0]; + + ret = clk_enable(&clk); + if (ret) { + debug("Failed to enable usbotg clock\n"); + return ret; + } + + meson_g12a_dwc2_data.rx_fifo_sz = fdtdec_get_int(blob, dwc2_node, + "g-rx-fifo-size", 0); + meson_g12a_dwc2_data.np_tx_fifo_sz = fdtdec_get_int(blob, dwc2_node, + "g-np-tx-fifo-size", 0); + meson_g12a_dwc2_data.tx_fifo_sz = fdtdec_get_int(blob, dwc2_node, + "g-tx-fifo-size", 0); + + /* Switch to peripheral mode */ + ret = dwc3_meson_g12a_force_mode(dev, USB_DR_MODE_PERIPHERAL); + if (ret) + return ret; + + return dwc2_udc_probe(&meson_g12a_dwc2_data); +} + +int board_usb_cleanup(int index, enum usb_init_type init) +{ + const void *blob = gd->fdt_blob; + struct udevice *dev; + int node; + int ret; + + /* find the usb glue node */ + node = fdt_node_offset_by_compatible(blob, -1, + "amlogic,meson-g12a-usb-ctrl"); + if (node < 0) + return -ENODEV; + + if (!fdtdec_get_is_enabled(blob, node)) + return -ENODEV; + + ret = uclass_get_device_by_of_offset(UCLASS_SIMPLE_BUS, node, &dev); + if (ret) + return ret; + + /* Switch to OTG mode */ + ret = dwc3_meson_g12a_force_mode(dev, USB_DR_MODE_HOST); + if (ret) + return ret; + + return 0; +} +#endif