From owner-svn-src-all@freebsd.org Thu Aug 25 10:27:24 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 07829BC56F5; Thu, 25 Aug 2016 10:27:24 +0000 (UTC) (envelope-from jmcneill@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A26A713E4; Thu, 25 Aug 2016 10:27:23 +0000 (UTC) (envelope-from jmcneill@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u7PARMBo014864; Thu, 25 Aug 2016 10:27:22 GMT (envelope-from jmcneill@FreeBSD.org) Received: (from jmcneill@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u7PARMmi014863; Thu, 25 Aug 2016 10:27:22 GMT (envelope-from jmcneill@FreeBSD.org) Message-Id: <201608251027.u7PARMmi014863@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jmcneill set sender to jmcneill@FreeBSD.org using -f From: Jared McNeill Date: Thu, 25 Aug 2016 10:27:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r304796 - head/sys/arm/allwinner/clk X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Aug 2016 10:27:24 -0000 Author: jmcneill Date: Thu Aug 25 10:27:22 2016 New Revision: 304796 URL: https://svnweb.freebsd.org/changeset/base/304796 Log: Switch parent clock when setting frequency if a new parent is a better candidate for the target rate. Reviewed by: andrew, manu Modified: head/sys/arm/allwinner/clk/aw_modclk.c Modified: head/sys/arm/allwinner/clk/aw_modclk.c ============================================================================== --- head/sys/arm/allwinner/clk/aw_modclk.c Thu Aug 25 10:24:14 2016 (r304795) +++ head/sys/arm/allwinner/clk/aw_modclk.c Thu Aug 25 10:27:22 2016 (r304796) @@ -160,28 +160,47 @@ aw_modclk_set_freq(struct clknode *clk, int flags, int *stop) { struct aw_modclk_sc *sc; - uint32_t val, m, n, best_m, best_n; + uint32_t val, m, n, src, best_m, best_n, best_src; uint64_t cur_freq; int64_t best_diff, cur_diff; + int error; sc = clknode_get_softc(clk); best_n = best_m = 0; best_diff = (int64_t)*fout; + best_src = 0; - for (n = 0; n <= CLK_RATIO_N_MAX; n++) - for (m = 0; m <= CLK_RATIO_M_MAX; m++) { - cur_freq = fin / (1 << n) / (m + 1); - cur_diff = (int64_t)*fout - cur_freq; - if (cur_diff >= 0 && cur_diff < best_diff) { - best_diff = cur_diff; - best_m = m; - best_n = n; + for (src = 0; src < CLK_SRC_SEL_MAX; src++) { + error = clknode_set_parent_by_idx(clk, src); + if (error != 0) + continue; + error = clknode_get_freq(clknode_get_parent(clk), &fin); + if (error != 0) + continue; + + for (n = 0; n <= CLK_RATIO_N_MAX; n++) + for (m = 0; m <= CLK_RATIO_M_MAX; m++) { + cur_freq = fin / (1 << n) / (m + 1); + cur_diff = (int64_t)*fout - cur_freq; + if (cur_diff >= 0 && cur_diff < best_diff) { + best_src = src; + best_diff = cur_diff; + best_m = m; + best_n = n; + } } - } + } if (best_diff == (int64_t)*fout) return (ERANGE); + error = clknode_set_parent_by_idx(clk, best_src); + if (error != 0) + return (error); + error = clknode_get_freq(clknode_get_parent(clk), &fin); + if (error != 0) + return (error); + DEVICE_LOCK(sc); MODCLK_READ(sc, &val); val &= ~(CLK_RATIO_N | CLK_RATIO_M);