From owner-svn-src-head@freebsd.org Mon May 7 07:29:49 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 61A47FA9146; Mon, 7 May 2018 07:29:49 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 136FF7CE60; Mon, 7 May 2018 07:29:49 +0000 (UTC) (envelope-from manu@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 0703418304; Mon, 7 May 2018 07:29:49 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w477TmbV071868; Mon, 7 May 2018 07:29:48 GMT (envelope-from manu@FreeBSD.org) Received: (from manu@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w477TmE6071867; Mon, 7 May 2018 07:29:48 GMT (envelope-from manu@FreeBSD.org) Message-Id: <201805070729.w477TmE6071867@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: manu set sender to manu@FreeBSD.org using -f From: Emmanuel Vadot Date: Mon, 7 May 2018 07:29:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r333317 - head/sys/arm64/rockchip/clk X-SVN-Group: head X-SVN-Commit-Author: manu X-SVN-Commit-Paths: head/sys/arm64/rockchip/clk X-SVN-Commit-Revision: 333317 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 May 2018 07:29:49 -0000 Author: manu Date: Mon May 7 07:29:48 2018 New Revision: 333317 URL: https://svnweb.freebsd.org/changeset/base/333317 Log: arm64: rockchip: clk: Add support to reparent to clk_composite All clk_composite type have the possibility to reparent (choosing another parent to find a better frequency), add the support for that. Modified: head/sys/arm64/rockchip/clk/rk_clk_composite.c Modified: head/sys/arm64/rockchip/clk/rk_clk_composite.c ============================================================================== --- head/sys/arm64/rockchip/clk/rk_clk_composite.c Mon May 7 07:28:47 2018 (r333316) +++ head/sys/arm64/rockchip/clk/rk_clk_composite.c Mon May 7 07:29:48 2018 (r333317) @@ -155,22 +155,50 @@ rk_clk_composite_recalc(struct clknode *clk, uint64_t return (0); } +static uint32_t +rk_clk_composite_find_best(struct rk_clk_composite_sc *sc, uint64_t fparent, + uint64_t freq) +{ + uint64_t best, cur; + uint32_t best_div, div; + + for (best = 0, best_div = 0, div = 0; + div <= ((sc->div_mask >> sc->div_shift) + 1); div++) { + cur = fparent / div; + if ((freq - cur) < (freq - best)) { + best = cur; + best_div = div; + break; + } + } + + return (best_div); +} + static int rk_clk_composite_set_freq(struct clknode *clk, uint64_t fparent, uint64_t *fout, int flags, int *stop) { struct rk_clk_composite_sc *sc; + struct clknode *p_clk; + const char **p_names; uint64_t best, cur; uint32_t div, best_div, val; + int p_idx, best_parent; sc = clknode_get_softc(clk); - for (best = 0, best_div = 0, div = 0; div <= sc->div_mask; div++) { + p_names = clknode_get_parent_names(clk); + for (best_div = 0, best = 0, p_idx = 0; + p_idx != clknode_get_parents_num(clk); p_idx++) { + p_clk = clknode_find_by_name(p_names[p_idx]); + clknode_get_freq(p_clk, &fparent); + div = rk_clk_composite_find_best(sc, fparent, *fout); cur = fparent / div; if ((*fout - cur) < (*fout - best)) { best = cur; best_div = div; - break; + best_parent = p_idx; } } @@ -193,6 +221,9 @@ rk_clk_composite_set_freq(struct clknode *clk, uint64_ *stop = 1; return (0); } + + if (p_idx != best_parent) + clknode_set_parent_by_idx(clk, best_parent); DEVICE_LOCK(clk); READ4(clk, sc->muxdiv_offset, &val);