From owner-svn-src-head@freebsd.org Sun Aug 5 06:15:36 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 5C6E71068155; Sun, 5 Aug 2018 06:15:36 +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 13E637E090; Sun, 5 Aug 2018 06:15:36 +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 E6CA31A7FA; Sun, 5 Aug 2018 06:15:35 +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 w756FZgI008811; Sun, 5 Aug 2018 06:15:35 GMT (envelope-from manu@FreeBSD.org) Received: (from manu@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w756FZcn008810; Sun, 5 Aug 2018 06:15:35 GMT (envelope-from manu@FreeBSD.org) Message-Id: <201808050615.w756FZcn008810@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: manu set sender to manu@FreeBSD.org using -f From: Emmanuel Vadot Date: Sun, 5 Aug 2018 06:15:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r337346 - head/sys/dev/extres/clk X-SVN-Group: head X-SVN-Commit-Author: manu X-SVN-Commit-Paths: head/sys/dev/extres/clk X-SVN-Commit-Revision: 337346 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.27 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: Sun, 05 Aug 2018 06:15:36 -0000 Author: manu Date: Sun Aug 5 06:15:35 2018 New Revision: 337346 URL: https://svnweb.freebsd.org/changeset/base/337346 Log: extres: clkdiv: Fix div_with_table We didn't allowed a divider register value of 0 which can exists and also didn't wrote the value but the divider, which result of a wrong frequency to be selected Modified: head/sys/dev/extres/clk/clk_div.c Modified: head/sys/dev/extres/clk/clk_div.c ============================================================================== --- head/sys/dev/extres/clk/clk_div.c Sun Aug 5 06:10:13 2018 (r337345) +++ head/sys/dev/extres/clk/clk_div.c Sun Aug 5 06:15:35 2018 (r337346) @@ -97,19 +97,21 @@ clknode_div_table_get_divider(struct clknode_div_sc *s return (0); } -static uint32_t -clknode_div_table_get_value(struct clknode_div_sc *sc, uint32_t divider) +static int +clknode_div_table_get_value(struct clknode_div_sc *sc, uint32_t *divider) { struct clk_div_table *table; if (!(sc->div_flags & CLK_DIV_WITH_TABLE)) - return (divider); + return (0); for (table = sc->div_table; table->divider != 0; table++) - if (table->divider == sc->divider) - return (table->value); + if (table->divider == *divider) { + *divider = table->value; + return (0); + } - return (0); + return (ENOENT); } static int @@ -164,7 +166,7 @@ clknode_div_set_freq(struct clknode *clk, uint64_t fin { struct clknode_div_sc *sc; uint64_t divider, _fin, _fout; - uint32_t reg, i_div, f_div, hw_i_div; + uint32_t div_value, reg, i_div, f_div, hw_i_div; int rv; sc = clknode_get_softc(clk); @@ -215,9 +217,11 @@ clknode_div_set_freq(struct clknode *clk, uint64_t fin (*fout != (_fin / divider))) return (ERANGE); - divider = clknode_div_table_get_value(sc, divider); - if (divider == 0) + div_value = divider; + if (clknode_div_table_get_value(sc, &div_value) != 0) return (ERANGE); + if (div_value != divider) + i_div = div_value; DEVICE_LOCK(clk); rv = MD4(clk, sc->offset,