From patchwork Sun Nov 27 14:31:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 1709372 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=denx.de header.i=@denx.de header.a=rsa-sha256 header.s=phobos-20191101 header.b=bO4ycaU9; dkim=pass (2048-bit key) header.d=denx.de header.i=@denx.de header.a=rsa-sha256 header.s=phobos-20191101 header.b=shOBjYX7; 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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NKrfM75PCz23nJ for ; Mon, 28 Nov 2022 01:32:25 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4565184C47; Sun, 27 Nov 2022 15:32:17 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1669559537; bh=dWUqEUIC8nZUcU+EM8w+6G40AtQJPMTQcj03LTbXS9I=; h=From:To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=bO4ycaU9Uquu1djZAjlhkhnEgROrXJ6JvaWh+sKw5OEStL9kpGK/dsqCeO4tMJtYm k9DAwcdHq5Wutz/tkuNR+Lt7J+aEtLN36XEvo2fbWeezOjK2lAqANYUsEEF3ZkHnTj Qjenr/Q76WTM67vTYbyCqqDpFLAWwrIMlCsaX8oVUMNtuivGLt7dK2ATRVu7Ktu8OC GIf840Iei/6TPIr8AwIQrHNOEL9P/zW75f/8tZe0yFdHUgtYM3uoXiO8YUkhGkzEmR XKJoWY/RW94Tw+GZTURk48/ApqcTB9/uVEiEDAoTCnSorwZy7VaB6Z6lYdvoBa3cIw 89E+BGHqMvYgA== Received: from tr.lan (ip-86-49-120-218.bb.vodafone.cz [86.49.120.218]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 678A184567; Sun, 27 Nov 2022 15:32:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1669559535; bh=dWUqEUIC8nZUcU+EM8w+6G40AtQJPMTQcj03LTbXS9I=; h=From:To:Cc:Subject:Date:From; b=shOBjYX7lnkhN5TtZ0w3qVo3t6mJShB4VDtLpkssLS8nTEp+K6oxi9srOVQDdIyts P3i4awNV5u7baw+3LC7Cy2EH0TYJPJw7OoJ6UrQZ7EzWItdtCWmyo/OoUpTyEfhGrY ql0bgdvGppnZIjn87H0WRQT2ZwLQRyU+xSciO9LJiEViAhASBqTnJyQ6+r7N7w4//i eZEiYwM0/7IF0Ot+aQK+GJPoBdJ4jneCB5Jra/nMsuDRN3ZQG/FuEdSpndpywHtTN5 gXba2ZY+FZQQjTvPafUZK1AduB39trO0yK1egpe23OtvW0DN8aouZfDVIUzHIqKK2i Hwr3eXrFt3AfQ== From: Marek Vasut To: u-boot@lists.denx.de Cc: Marek Vasut , Sean Anderson , Angus Ainslie , Bin Meng , Fabio Estevam , Kunihiko Hayashi , Michal Simek , Peng Fan , Sean Anderson , Stefano Babic Subject: [PATCH v3 1/5] usb: dwc3: Cache ref_clk pointer in struct dwc3 Date: Sun, 27 Nov 2022 15:31:52 +0100 Message-Id: <20221127143156.18327-1-marex@denx.de> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.6 at phobos.denx.de X-Virus-Status: Clean Cache ref_clk clock pointer in struct dwc3 . This is a preparatory patch for subsequent backports from Linux kernel which configure GFLADJ register content based on the ref_clk rate and therefore need access to the ref_clk pointer. It is possible to extract the clock pointer from existing clk_bulk list of already claimed clock, no need to call clk_get*() again. Reviewed-by: Sean Anderson Signed-off-by: Marek Vasut --- Cc: Angus Ainslie Cc: Bin Meng Cc: Fabio Estevam Cc: Kunihiko Hayashi Cc: Michal Simek Cc: Peng Fan Cc: Sean Anderson Cc: Stefano Babic --- V2: Add paragraph on clk_get into commit message V3: No change --- drivers/usb/dwc3/core.h | 3 +++ drivers/usb/dwc3/dwc3-generic.c | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index d7cce3a861a..0d20fe285b0 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -668,6 +668,7 @@ struct dwc3_scratchpad_array { * @event_buffer_list: a list of event buffers * @gadget: device side representation of the peripheral controller * @gadget_driver: pointer to the gadget driver + * @ref_clk: reference clock * @regs: base address for our registers * @regs_size: address space size * @nr_scratch: number of scratch buffers @@ -766,6 +767,8 @@ struct dwc3 { struct usb_gadget gadget; struct usb_gadget_driver *gadget_driver; + struct clk *ref_clk; + void __iomem *regs; size_t regs_size; diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c index 466b25a0c38..78966718d01 100644 --- a/drivers/usb/dwc3/dwc3-generic.c +++ b/drivers/usb/dwc3/dwc3-generic.c @@ -59,12 +59,21 @@ static int dwc3_generic_probe(struct udevice *dev, struct dwc3_generic_plat *plat = dev_get_plat(dev); struct dwc3 *dwc3 = &priv->dwc3; struct dwc3_glue_data *glue = dev_get_plat(dev->parent); + int __maybe_unused index; + ofnode __maybe_unused node; dwc3->dev = dev; dwc3->maximum_speed = plat->maximum_speed; dwc3->dr_mode = plat->dr_mode; #if CONFIG_IS_ENABLED(OF_CONTROL) dwc3_of_parse(dwc3); + + node = dev_ofnode(dev->parent); + index = ofnode_stringlist_search(node, "clock-names", "ref"); + if (index < 0) + index = ofnode_stringlist_search(node, "clock-names", "ref_clk"); + if (index >= 0) + dwc3->ref_clk = &glue->clks.clks[index]; #endif /* From patchwork Sun Nov 27 14:31:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 1709373 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=denx.de header.i=@denx.de header.a=rsa-sha256 header.s=phobos-20191101 header.b=jHmc1SxR; dkim=pass (2048-bit key) header.d=denx.de header.i=@denx.de header.a=rsa-sha256 header.s=phobos-20191101 header.b=a+KQoLAJ; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NKrfW3xzKz23nJ for ; Mon, 28 Nov 2022 01:32:35 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6DB5284956; Sun, 27 Nov 2022 15:32:22 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1669559543; bh=LeZyEhFQpLznefoyTSvVlsnJhRf8OZTeCOLhRoyb2H4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=jHmc1SxRzSzsty2axpvirQSgEObd9fx6muHOgKTUlRdRQkJXrAFFXnT8W8zMdfsB9 vNuLa8ShIpqvoPT2PL8c45iBCNxWKNIXCCkRgrhgkiCfzIKSrHR18dP43I84kQKh5n mTSrVlQnGy3UZepJ1CH1ohyVCcKB8z82oaUnUbKm2/i91XID0Q0KQbvCPnOdrKf6yN Da7Y/6/cMrf8alP5kHY6OYczqHDhK1VCqYBqUKxoDCMfO9eP0tooLgC03842Aa8GMv FFu3EBoYJyZGWCO+CourBGxgekLVJaZztoBfxhlMq5EPl7z6KowtAG43DdJRfQUp7Z inQc6Gr62Ckag== Received: from tr.lan (ip-86-49-120-218.bb.vodafone.cz [86.49.120.218]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id E115384913; Sun, 27 Nov 2022 15:32:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1669559536; bh=LeZyEhFQpLznefoyTSvVlsnJhRf8OZTeCOLhRoyb2H4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a+KQoLAJqtKERRn36UcmJaokqgZCQ58T3w4Eno5JbPJPHoogISpMtANNFMIQesjTr r+HtBYqcYIPCKnvTthCIOVsCyPnyby2+s7B+kVOns4upHxOxysGpCN74u0t+CYMAUw yBcO6aELoKitZB9usbCHZR+OhMLoTtl6BQwww23dZB3l535+VE3hYR2tsYtC+GiECK vwx6KtXhv8oxWeSTX6hOWbYv+MgLa9Zr36LVOSXUiB/iZ9wuUvCzdHJ/70TQrb4fFR W8fMtcRm1ReoO0MOC7M15MyScWldXVK0NsKprmhRnmejcvuZRb0Qe/PtWgvHSjVkaG vHNfRiChdtKaQ== From: Marek Vasut To: u-boot@lists.denx.de Cc: Balaji Prakash J , Sean Anderson , Baruch Siach , Marek Vasut , Angus Ainslie , Bin Meng , Fabio Estevam , Kunihiko Hayashi , Michal Simek , Peng Fan , Sean Anderson , Stefano Babic Subject: [PATCH v3 2/5] usb: dwc3: reference clock period configuration Date: Sun, 27 Nov 2022 15:31:53 +0100 Message-Id: <20221127143156.18327-2-marex@denx.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221127143156.18327-1-marex@denx.de> References: <20221127143156.18327-1-marex@denx.de> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.6 at phobos.denx.de X-Virus-Status: Clean From: Balaji Prakash J Set reference clock period when it differs from dwc3 default hardware set. We could calculate clock period based on reference clock frequency. But this information is not always available. This is the case of PCI bus attached USB host. For that reason we use a custom property. Tested (USB2 only) on IPQ6010 SoC based board with 24 MHz reference clock while hardware default is 19.2 MHz. [ baruch: rewrite commit message; drop GFLADJ code; remove 'quirk-' from property name; mention tested hardware ] [ marek: Ported from Linux kernel commit 7bee318838890 ("usb: dwc3: reference clock period configuration") ] Reviewed-by: Sean Anderson Signed-off-by: Balaji Prakash J Signed-off-by: Baruch Siach Signed-off-by: Marek Vasut # Port from Linux --- Cc: Angus Ainslie Cc: Bin Meng Cc: Fabio Estevam Cc: Kunihiko Hayashi Cc: Michal Simek Cc: Peng Fan Cc: Sean Anderson Cc: Stefano Babic --- V2: No change V3: No change --- drivers/usb/dwc3/core.c | 27 +++++++++++++++++++++++++++ drivers/usb/dwc3/core.h | 6 ++++++ 2 files changed, 33 insertions(+) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index b592a487e00..300450100c9 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "core.h" #include "gadget.h" @@ -114,6 +115,28 @@ static void dwc3_frame_length_adjustment(struct dwc3 *dwc, u32 fladj) dwc3_writel(dwc->regs, DWC3_GFLADJ, reg); } +/** + * dwc3_ref_clk_period - Reference clock period configuration + * Default reference clock period depends on hardware + * configuration. For systems with reference clock that differs + * from the default, this will set clock period in DWC3_GUCTL + * register. + * @dwc: Pointer to our controller context structure + * @ref_clk_per: reference clock period in ns + */ +static void dwc3_ref_clk_period(struct dwc3 *dwc) +{ + u32 reg; + + if (dwc->ref_clk_per == 0) + return; + + reg = dwc3_readl(dwc->regs, DWC3_GUCTL); + reg &= ~DWC3_GUCTL_REFCLKPER_MASK; + reg |= FIELD_PREP(DWC3_GUCTL_REFCLKPER_MASK, dwc->ref_clk_per); + dwc3_writel(dwc->regs, DWC3_GUCTL, reg); +} + /** * dwc3_free_one_event_buffer - Frees one event buffer * @dwc: Pointer to our controller context structure @@ -640,6 +663,9 @@ static int dwc3_core_init(struct dwc3 *dwc) /* Adjust Frame Length */ dwc3_frame_length_adjustment(dwc, dwc->fladj); + /* Adjust Reference Clock Period */ + dwc3_ref_clk_period(dwc); + dwc3_set_incr_burst_type(dwc); return 0; @@ -1043,6 +1069,7 @@ void dwc3_of_parse(struct dwc3 *dwc) | (dwc->is_utmi_l1_suspend << 4); dev_read_u32(dev, "snps,quirk-frame-length-adjustment", &dwc->fladj); + dev_read_u32(dev, "snps,ref-clock-period-ns", &dwc->ref_clk_per); /* * Handle property "snps,incr-burst-type-adjustment". diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 0d20fe285b0..b4a7d9e52bc 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -249,6 +249,10 @@ #define DWC3_GFLADJ_30MHZ_SDBND_SEL (1 << 7) #define DWC3_GFLADJ_30MHZ_MASK 0x3f +/* Global User Control Register*/ +#define DWC3_GUCTL_REFCLKPER_MASK 0xffc00000 +#define DWC3_GUCTL_REFCLKPER_SEL 22 + /* Device Configuration Register */ #define DWC3_DCFG_DEVADDR(addr) ((addr) << 3) #define DWC3_DCFG_DEVADDR_MASK DWC3_DCFG_DEVADDR(0x7f) @@ -671,6 +675,7 @@ struct dwc3_scratchpad_array { * @ref_clk: reference clock * @regs: base address for our registers * @regs_size: address space size + * @ref_clk_per: reference clock period configuration * @nr_scratch: number of scratch buffers * @num_event_buffers: calculated number of event buffers * @u1u2: only used on revisions <1.83a for workaround @@ -832,6 +837,7 @@ struct dwc3 { u8 lpm_nyet_threshold; u8 hird_threshold; u32 fladj; + u32 ref_clk_per; u8 incrx_mode; u32 incrx_size; From patchwork Sun Nov 27 14:31:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 1709374 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=denx.de header.i=@denx.de header.a=rsa-sha256 header.s=phobos-20191101 header.b=0D0Wpv4e; dkim=pass (2048-bit key) header.d=denx.de header.i=@denx.de header.a=rsa-sha256 header.s=phobos-20191101 header.b=ZxOUxiPN; 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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NKrfj4B7Jz23nJ for ; Mon, 28 Nov 2022 01:32:45 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5355584F24; Sun, 27 Nov 2022 15:32:26 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1669559546; bh=U6dyqNOwhs8/aw9vJXzkBYNF+PI2tZzAafwCjFmFoz4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=0D0Wpv4eOGg1HBDHcsmiei87R9uAivPi5ViJs8pxLOeeueJEWqvxguLKwlFvlE8Uf IanTVldYhXuBqSgH+VKwF83NU5vzGoAmxjc5b4DHumlalwAxDXmxtuSqyzgseMSwlJ JHyx5btVwiM85/QM1BCuwr/VEGbWY9uN3mec6ylrVGUvXUGb8OXG2Cn9Yz6hzbHbI+ bEu0pBh1U27xuoC6UZnMwKSi/Z1dIcDcx5Ou+CbOydbzKgSctwF5/g9dBvdsSRMezW inK5UtGNW2RAmyYdVFXlbEPJJXuEZPMka0kwOQDuhuFarzZ25fnAkYhaDBS9SUWnLg 18p3esNpmYAIA== Received: from tr.lan (ip-86-49-120-218.bb.vodafone.cz [86.49.120.218]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id C21FE8492B; Sun, 27 Nov 2022 15:32:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1669559537; bh=U6dyqNOwhs8/aw9vJXzkBYNF+PI2tZzAafwCjFmFoz4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZxOUxiPNn8t9IDBRFTV3O93HwXfBIHmkCFEAzEHmH3gL0XxMdJxuWPkrERGig+ts4 H+hyBLoG+heuH13EsAbdetG+uOoduNACG2VLDc9vT/FKNsHibkrkgpBr2jcK20Z76l RKsqHVqB4Ld3UJIqhRdnuzhOFTg6CvTpmSQ16j1YhmA7wVRY8CTpFkDPk10fzEFVT3 RZA27KL8zPcnTWgK6ccctIpZ0kiIViH6qQ12rASClEV1gOYecILxPbl0al2YVle9f/ gRojSkn81lWgUVW3ZOH2J3HtVabSBZ8dplrOoZNdSbPXZqRz1g7oiczkDxqaFue+kg HFdXso/d15tKA== From: Marek Vasut To: u-boot@lists.denx.de Cc: Sean Anderson , Sean Anderson , Marek Vasut , Angus Ainslie , Bin Meng , Fabio Estevam , Kunihiko Hayashi , Michal Simek , Peng Fan , Stefano Babic Subject: [PATCH v3 3/5] usb: dwc3: Calculate REFCLKPER based on reference clock Date: Sun, 27 Nov 2022 15:31:54 +0100 Message-Id: <20221127143156.18327-3-marex@denx.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221127143156.18327-1-marex@denx.de> References: <20221127143156.18327-1-marex@denx.de> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.6 at phobos.denx.de X-Virus-Status: Clean From: Sean Anderson Instead of using a special property to determine the reference clock period, use the rate of the reference clock. When we have a legacy snps,ref-clock-period-ns property and no reference clock, use it instead. Fractional clocks are not currently supported, and will be dealt with in the next commit. [ marek: Ported from Linux kernel commit 5114c3ee24875 ("usb: dwc3: Calculate REFCLKPER based on reference clock") ] Reviewed-by: Sean Anderson Signed-off-by: Sean Anderson Signed-off-by: Marek Vasut # Port from Linux --- Cc: Angus Ainslie Cc: Bin Meng Cc: Fabio Estevam Cc: Kunihiko Hayashi Cc: Michal Simek Cc: Peng Fan Cc: Sean Anderson Cc: Stefano Babic --- V2: No change V3: Include clk.h --- drivers/usb/dwc3/core.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 300450100c9..ed5d0d16f78 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -14,6 +14,7 @@ */ #include +#include #include #include #include @@ -126,14 +127,24 @@ static void dwc3_frame_length_adjustment(struct dwc3 *dwc, u32 fladj) */ static void dwc3_ref_clk_period(struct dwc3 *dwc) { + unsigned long period; + unsigned long rate; u32 reg; - if (dwc->ref_clk_per == 0) + if (dwc->ref_clk) { + rate = clk_get_rate(dwc->ref_clk); + if (!rate) + return; + period = NSEC_PER_SEC / rate; + } else if (dwc->ref_clk_per) { + period = dwc->ref_clk_per; + } else { return; + } reg = dwc3_readl(dwc->regs, DWC3_GUCTL); reg &= ~DWC3_GUCTL_REFCLKPER_MASK; - reg |= FIELD_PREP(DWC3_GUCTL_REFCLKPER_MASK, dwc->ref_clk_per); + reg |= FIELD_PREP(DWC3_GUCTL_REFCLKPER_MASK, period); dwc3_writel(dwc->regs, DWC3_GUCTL, reg); } From patchwork Sun Nov 27 14:31:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 1709375 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=denx.de header.i=@denx.de header.a=rsa-sha256 header.s=phobos-20191101 header.b=ZBQ5O4xx; dkim=pass (2048-bit key) header.d=denx.de header.i=@denx.de header.a=rsa-sha256 header.s=phobos-20191101 header.b=Yxrhc2Sd; 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 ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NKrfy1Y9yz23nJ for ; Mon, 28 Nov 2022 01:32:58 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A537C84F68; Sun, 27 Nov 2022 15:32:28 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1669559548; bh=JcfcwykfSW3VOYbS1YuZ+Sdv45zo4+sixNaeuGZ7yVc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=ZBQ5O4xxZwSVFx9u/QcMadRbyts4eaiZPN0kArdaxcWe4Fpb9BrlgC1bsr7jf6dqN rRDIhCD6RJPQ8uYq7s0BTI+B2INzMcG3dKoa6YxiffzRfnv98fGNXfS/bNUeenKO6H i+sHlJcSaa5CYYmb52vmKPmyPi2CVEvNnLYxyaYZ3bBRU+6Q4kCrWM4BBJCTVJtJlT FZN5m9zhEFnDNMk22idgFZmX4mSiYz4nBgvB4yi0urj016JXq5NsTWlSQo6BEAts6j 2v8nOa8cBrtQMIjztvPh/kdpCHQuQpEZGXNBOp0c9MsoPNnAoLdxD/3TiIebUG4QbF Hv/ScWeIPkCHA== Received: from tr.lan (ip-86-49-120-218.bb.vodafone.cz [86.49.120.218]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 279CB84956; Sun, 27 Nov 2022 15:32:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1669559537; bh=JcfcwykfSW3VOYbS1YuZ+Sdv45zo4+sixNaeuGZ7yVc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Yxrhc2SdckcZtQhowOHeD8JVuGSr83XUj6rNaLThVX3CxxH9Pp6wMIDcHYzxW4m85 2U7N1Og4KB5EQUkhJ3PbEt3CdSXI6pM/eZVqWoueS/qzlzOue1sMx1oK0OsSqGGiuU QWKvnwh2bMTYU7zn9K7VyH180l2eMPp4/Y55nV/tPjwffzmCqKyYyV2CPwFRfaL1Z/ gVCnSGyRxEzkrqESSkxCSgbq3vl3IKz14C+Sa9gba32cd9oQiybx9WflcqlaKlzeG+ RvlFap+C+ap4hVIhwgKFb6N1G8ZAXzjwjA4GHxOuXXCT0FOwIX/SQru2tV6gmAk9Mm dk+r6Iw4Qcw5Q== From: Marek Vasut To: u-boot@lists.denx.de Cc: Sean Anderson , Sean Anderson , Marek Vasut , Angus Ainslie , Bin Meng , Fabio Estevam , Kunihiko Hayashi , Michal Simek , Peng Fan , Stefano Babic Subject: [PATCH v3 4/5] usb: dwc3: Program GFLADJ Date: Sun, 27 Nov 2022 15:31:55 +0100 Message-Id: <20221127143156.18327-4-marex@denx.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221127143156.18327-1-marex@denx.de> References: <20221127143156.18327-1-marex@denx.de> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.6 at phobos.denx.de X-Virus-Status: Clean From: Sean Anderson GUCTL.REFCLKPER can only account for clock frequencies with integer periods. To address this, program REFCLK_FLADJ with the relative error caused by period truncation. The formula given in the register reference has been rearranged to allow calculation based on rate (instead of period), and to allow for fixed-point arithmetic. Additionally, calculate a value for 240MHZDECR. This configures a simulated 240Mhz clock using a counter with one fractional bit (PLS1). This register is programmed only for versions >= 2.50a, since this is the check also used by commit db2be4e9e30c ("usb: dwc3: Add frame length adjustment quirk"). [ marek: Ported from Linux kernel commit 596c87856e08d ("usb: dwc3: Program GFLADJ") ] Reviewed-by: Sean Anderson Signed-off-by: Sean Anderson Signed-off-by: Marek Vasut # Port from Linux --- Cc: Angus Ainslie Cc: Bin Meng Cc: Fabio Estevam Cc: Kunihiko Hayashi Cc: Michal Simek Cc: Peng Fan Cc: Sean Anderson Cc: Stefano Babic --- V2: No change V3: No change --- drivers/usb/dwc3/core.c | 41 +++++++++++++++++++++++++++++++++++++++++ drivers/usb/dwc3/core.h | 3 +++ 2 files changed, 44 insertions(+) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index ed5d0d16f78..6e0876d2c45 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "core.h" #include "gadget.h" @@ -37,6 +38,8 @@ #include "linux-compat.h" +#define NSEC_PER_SEC 1000000000L + static LIST_HEAD(dwc3_list); /* -------------------------------------------------------------------------- */ @@ -128,6 +131,8 @@ static void dwc3_frame_length_adjustment(struct dwc3 *dwc, u32 fladj) static void dwc3_ref_clk_period(struct dwc3 *dwc) { unsigned long period; + unsigned long fladj; + unsigned long decr; unsigned long rate; u32 reg; @@ -138,6 +143,7 @@ static void dwc3_ref_clk_period(struct dwc3 *dwc) period = NSEC_PER_SEC / rate; } else if (dwc->ref_clk_per) { period = dwc->ref_clk_per; + rate = NSEC_PER_SEC / period; } else { return; } @@ -146,6 +152,41 @@ static void dwc3_ref_clk_period(struct dwc3 *dwc) reg &= ~DWC3_GUCTL_REFCLKPER_MASK; reg |= FIELD_PREP(DWC3_GUCTL_REFCLKPER_MASK, period); dwc3_writel(dwc->regs, DWC3_GUCTL, reg); + + if (dwc->revision <= DWC3_REVISION_250A) + return; + + /* + * The calculation below is + * + * 125000 * (NSEC_PER_SEC / (rate * period) - 1) + * + * but rearranged for fixed-point arithmetic. The division must be + * 64-bit because 125000 * NSEC_PER_SEC doesn't fit in 32 bits (and + * neither does rate * period). + * + * Note that rate * period ~= NSEC_PER_SECOND, minus the number of + * nanoseconds of error caused by the truncation which happened during + * the division when calculating rate or period (whichever one was + * derived from the other). We first calculate the relative error, then + * scale it to units of 8 ppm. + */ + fladj = div64_u64(125000ULL * NSEC_PER_SEC, (u64)rate * period); + fladj -= 125000; + + /* + * The documented 240MHz constant is scaled by 2 to get PLS1 as well. + */ + decr = 480000000 / rate; + + reg = dwc3_readl(dwc->regs, DWC3_GFLADJ); + reg &= ~DWC3_GFLADJ_REFCLK_FLADJ_MASK + & ~DWC3_GFLADJ_240MHZDECR + & ~DWC3_GFLADJ_240MHZDECR_PLS1; + reg |= FIELD_PREP(DWC3_GFLADJ_REFCLK_FLADJ_MASK, fladj) + | FIELD_PREP(DWC3_GFLADJ_240MHZDECR, decr >> 1) + | FIELD_PREP(DWC3_GFLADJ_240MHZDECR_PLS1, decr & 1); + dwc3_writel(dwc->regs, DWC3_GFLADJ, reg); } /** diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index b4a7d9e52bc..532746dd88d 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -248,6 +248,9 @@ /* Global Frame Length Adjustment Register */ #define DWC3_GFLADJ_30MHZ_SDBND_SEL (1 << 7) #define DWC3_GFLADJ_30MHZ_MASK 0x3f +#define DWC3_GFLADJ_REFCLK_FLADJ_MASK GENMASK(21, 8) +#define DWC3_GFLADJ_240MHZDECR GENMASK(30, 24) +#define DWC3_GFLADJ_240MHZDECR_PLS1 BIT(31) /* Global User Control Register*/ #define DWC3_GUCTL_REFCLKPER_MASK 0xffc00000 From patchwork Sun Nov 27 14:31:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 1709376 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=denx.de header.i=@denx.de header.a=rsa-sha256 header.s=phobos-20191101 header.b=SAQ9sIto; dkim=fail reason="signature verification failed" (2048-bit key) header.d=denx.de header.i=@denx.de header.a=rsa-sha256 header.s=phobos-20191101 header.b=Qmsoa3FI; 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 ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NKrgC43gqz23nJ for ; Mon, 28 Nov 2022 01:33:11 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id F3B1084F03; Sun, 27 Nov 2022 15:32:30 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1669559551; bh=NCYyb1bKSYuOfoV2J0y6uFMueA5Jned4MA4hLg9dgx8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=SAQ9sItobJUkMDvDgC2Np9VIETizqmhJrvTsFlu97Nn8kzEyXga2ht0ze98201LCt ngP9wV9q550MPtxJWCT1EbXF4xo7zDjPXf6tqvljCdM/Eg7X3FmG18B2KCo5mSMaUZ Tf+Bf3vU3dCYaQZK9mJEUgW/k6cCcHJOD7504TO+oOhY/QW3bWVxrT4vEiBUGpKBDU yutIttUD+jPXlZaZfs3I9h9eTtUcdT6IA726gt/4AS8fUJKTfr8sfyHjfQiRC25kpy InzQ/fBtjSOM6Y0j5SFdLnadAh+oSyBuzjGw7PliUybJPI+e04L4VHCDGIFP19uPwh dEVIv8zfkd+/A== Received: from tr.lan (ip-86-49-120-218.bb.vodafone.cz [86.49.120.218]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 81B9C84D54; Sun, 27 Nov 2022 15:32:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1669559537; bh=NCYyb1bKSYuOfoV2J0y6uFMueA5Jned4MA4hLg9dgx8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qmsoa3FIgH/v33tAbz5ofl67xU0GpedfVpgSs/XoigBab/QjQk+kOnhdhw1YkInmS ExbKbdYFCZO+cW9sXLiw4juhEg6tmbo8uZaxx5Q9I4Tz02dZjSqp4PCCUPWxcgbBJY 2Jq6SFOCMLAbNgriay7iiAhX/Qvk0DgQt8ivASqk4sRGtdNvQSsGbRhr8icarASp1/ ZNg12ysdTTxDYBMmZfHfzqrLiCSqPqr915uUEu/E7oHndaG6hY76LIkuJ74TnZg1pl Er8/vIGmn/knN0TryUO+LdoRLDW1lGZ3dq7UEOHvKZ3zP8RSH6t55irUYFvr6mjG9r H2PASAD6SZ1Cw== From: Marek Vasut To: u-boot@lists.denx.de Cc: Marek Vasut , Sean Anderson , Angus Ainslie , Bin Meng , Fabio Estevam , Kunihiko Hayashi , Michal Simek , Peng Fan , Sean Anderson , Stefano Babic Subject: [PATCH v3 5/5] usb: dwc3: Drop support for "snps, ref-clock-period-ns" DT property Date: Sun, 27 Nov 2022 15:31:56 +0100 Message-Id: <20221127143156.18327-5-marex@denx.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221127143156.18327-1-marex@denx.de> References: <20221127143156.18327-1-marex@denx.de> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.6 at phobos.denx.de X-Virus-Status: Clean Drop support for quickly deprecated DT property "snps,ref-clock-period-ns" to prevent its proliferation. Reviewed-by: Sean Anderson Signed-off-by: Marek Vasut --- Cc: Angus Ainslie Cc: Bin Meng Cc: Fabio Estevam Cc: Kunihiko Hayashi Cc: Michal Simek Cc: Peng Fan Cc: Sean Anderson Cc: Stefano Babic --- V2: New patch V3: No change --- drivers/usb/dwc3/core.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 6e0876d2c45..49f6a1900b0 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -141,9 +141,6 @@ static void dwc3_ref_clk_period(struct dwc3 *dwc) if (!rate) return; period = NSEC_PER_SEC / rate; - } else if (dwc->ref_clk_per) { - period = dwc->ref_clk_per; - rate = NSEC_PER_SEC / period; } else { return; } @@ -1121,7 +1118,6 @@ void dwc3_of_parse(struct dwc3 *dwc) | (dwc->is_utmi_l1_suspend << 4); dev_read_u32(dev, "snps,quirk-frame-length-adjustment", &dwc->fladj); - dev_read_u32(dev, "snps,ref-clock-period-ns", &dwc->ref_clk_per); /* * Handle property "snps,incr-burst-type-adjustment".