From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.2 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A633C433E0 for ; Sat, 20 Jun 2020 08:59:51 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D751423A69 for ; Sat, 20 Jun 2020 08:59:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="WAvdajoa"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=armlinux.org.uk header.i=@armlinux.org.uk header.b="c0RvMXGf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D751423A69 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=armlinux.org.uk Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=MAthGZegVtirRCIxdfS6Hj40qyHq6D1bncn31y/muwo=; b=WAvdajoaByd22R AsqqFGBkY8V6JruzxmYPLzILeulYVCH/xaVoOu8DqIIjhVFGDgp7XcPEbwPKPF/DWhFocLu5NV5Eg ayrf0GpXxT6JHd2OXX4zP0jOhX0dgSyUWwg5L2QevtYiQVBrmZ9ECBFEJM5Z8iw9q4SvPmamafGyy Y1SokIC5FZr0Z1hjpRSYB3PmC+KuMvuv/adVXnrQQymOO3/S854ZoqbhBiOAspL6gRYh/qHgP8qzm pEniy+SUOwsM+Ow4z1qIJ0JPrliZ/Y7LsUSYnWlfuDm1JSVpwaV/SdP3BCXjQJI+3Fb3WpiTZ0N/+ ZD2litoWCsyOT4TKJPcg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jmZLd-0007sF-Rk; Sat, 20 Jun 2020 08:59:37 +0000 Received: from pandora.armlinux.org.uk ([2001:4d48:ad52:32c8:5054:ff:fe00:142]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jmZLa-0007l6-2A for linux-arm-kernel@lists.infradead.org; Sat, 20 Jun 2020 08:59:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: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=HkINJawlRBHwc9VNfEcMZvgjcar16lovqjBKst1T/h8=; b=c0RvMXGf8LMYYodMuFBnlGPA5 h3JK1D0vAcXa0tRBv93Q3jOqdlWFQcW1Y2zFSv9zuMaFffJHzW8y0a04xN1b5rtlaz2oBMbGC4ZIX uRoG02au1wR0yha0mGobF+Uhyj4gj/O6v6gihU6qJj9mnC+LDmvkJWZC2U83PkpFYyBRv1PCrTrLf SmrIxhXVJNpfqwG6smZdrlXW83kMBWT6Azs8qTaHYQ/BDAVm0tuWINrSRxGwlPdUxkN7Do1/pi0D5 WYLG50K8mu8WOowJ0Bev9At1TL/gy/77i5bRvhvW7GvcB0hD0aUcPCprpHBkRzK2gup6oC/BrgGYe oX9vd11Jg==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:58864) by pandora.armlinux.org.uk with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jmZII-0007Mf-B7; Sat, 20 Jun 2020 09:56:10 +0100 Received: from linux by shell.armlinux.org.uk with local (Exim 4.92) (envelope-from ) id 1jmYbZ-0006Th-Ck; Sat, 20 Jun 2020 09:12:01 +0100 Date: Sat, 20 Jun 2020 09:12:01 +0100 From: Russell King - ARM Linux admin To: Serge Semin Subject: Re: [PATCH v7 2/3] serial: 8250_dw: Simplify the ref clock rate setting procedure Message-ID: <20200620081201.GQ1551@shell.armlinux.org.uk> References: <20200619200251.9066-1-Sergey.Semin@baikalelectronics.ru> <20200619200251.9066-3-Sergey.Semin@baikalelectronics.ru> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200619200251.9066-3-Sergey.Semin@baikalelectronics.ru> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200620_015934_104356_996D76AE X-CRM114-Status: GOOD ( 15.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Bogendoerfer , linux-kernel@vger.kernel.org, Arnd Bergmann , Greg Kroah-Hartman , linux-mips@vger.kernel.org, Serge Semin , Alexey Malahov , Maxime Ripard , linux-serial@vger.kernel.org, Jiri Slaby , Andy Shevchenko , Will Deacon , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Jun 19, 2020 at 11:02:50PM +0300, Serge Semin wrote: > Really instead of twice checking the clk_round_rate() return value > we could do it once, and if it isn't error the clock rate can be changed. > By doing so we decrease a number of ret-value tests and remove a weird > goto-based construction implemented in the dw8250_set_termios() method. This doesn't look right to me - neither the before code nor the after code. > clk_disable_unprepare(d->clk); > rate = clk_round_rate(d->clk, baud * 16); > - if (rate < 0) > - ret = rate; > - else if (rate == 0) > - ret = -ENOENT; > - else > + if (rate > 0) { > ret = clk_set_rate(d->clk, rate); > + if (!ret) > + p->uartclk = rate; > + } > clk_prepare_enable(d->clk); > > - if (ret) > - goto out; > - > - p->uartclk = rate; newrate = baud * 16; clk_disable_unprepare(d->clk); rate = clk_round_rate(newrate); ret = clk_set_rate(d->clk, newrate); if (!ret) p->uartclk = rate; ret = elk_prepare_enable(d->clk); /* check ret for failure, means the clock is no longer running */ is all that should be necessary: note that clk_round_rate() is required to return the rate that a successful call to clk_set_rate() would result in for that clock. It is equivalent to: ret = clk_set_rate(d->clk, newrate); if (ret == 0) p->uartclk = clk_get_rate(d->clk); The other commonly misunderstood thing about the clk API is that the rate you pass in to clk_round_rate() to discover the actual clock rate and the value passed in to clk_set_rate() _should_ be the same value. You should _not_ do clk_set_rate(clk, clk_round_rate(clk, newrate)); -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last! _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel