diff mbox series

[v1,1/3] clk: fractional-divider: Export approximation algo to the CCF users

Message ID 20210715120752.29174-1-andriy.shevchenko@linux.intel.com (mailing list archive)
State Superseded, archived
Headers show
Series [v1,1/3] clk: fractional-divider: Export approximation algo to the CCF users | expand

Commit Message

Andy Shevchenko July 15, 2021, 12:07 p.m. UTC
At least one user currently duplicates some functions that are provided
by fractional divider module. Let's export approximation algo and replace
the open-coded variant.

As a bonus the exported function will get better documentation in place.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/clk/clk-fractional-divider.c | 11 +++++++----
 drivers/clk/clk-fractional-divider.h |  9 +++++++++
 drivers/clk/rockchip/clk.c           | 17 +++--------------
 3 files changed, 19 insertions(+), 18 deletions(-)
 create mode 100644 drivers/clk/clk-fractional-divider.h

Comments

kernel test robot July 15, 2021, 3:38 p.m. UTC | #1
Hi Andy,

I love your patch! Yet something to improve:

[auto build test ERROR on clk/clk-next]
[also build test ERROR on rockchip/for-next linux/master linus/master v5.14-rc1 next-20210715]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Andy-Shevchenko/clk-fractional-divider-Export-approximation-algo-to-the-CCF-users/20210715-200828
base:   https://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git clk-next
config: arm64-randconfig-s032-20210715 (attached as .config)
compiler: aarch64-linux-gcc (GCC) 10.3.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # apt-get install sparse
        # sparse version: v0.6.3-341-g8af24329-dirty
        # https://github.com/0day-ci/linux/commit/bcba401c1ad5c03f7d638f99c799576a771e87ca
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Andy-Shevchenko/clk-fractional-divider-Export-approximation-algo-to-the-CCF-users/20210715-200828
        git checkout bcba401c1ad5c03f7d638f99c799576a771e87ca
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-10.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=arm64 SHELL=/bin/bash drivers/clk/rockchip/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> drivers/clk/rockchip/clk.c:27:10: fatal error: clk-fractional-divider.h: No such file or directory
      27 | #include "clk-fractional-divider.h"
         |          ^~~~~~~~~~~~~~~~~~~~~~~~~~
   compilation terminated.


vim +27 drivers/clk/rockchip/clk.c

    25	
    26	#include "clk.h"
  > 27	#include "clk-fractional-divider.h"
    28	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Andy Shevchenko July 15, 2021, 4:51 p.m. UTC | #2
On Thu, Jul 15, 2021 at 7:49 PM kernel test robot <lkp@intel.com> wrote:
> I love your patch! Yet something to improve:

Definitely!

> All errors (new ones prefixed by >>):
>
> >> drivers/clk/rockchip/clk.c:27:10: fatal error: clk-fractional-divider.h: No such file or directory
>       27 | #include "clk-fractional-divider.h"
>          |          ^~~~~~~~~~~~~~~~~~~~~~~~~~
>    compilation terminated.

Indeed. No idea how to compile-test this on x86.
Let me see what I can do to avoid other issues.
Robin Murphy July 15, 2021, 5:58 p.m. UTC | #3
On 2021-07-15 17:51, Andy Shevchenko wrote:
> On Thu, Jul 15, 2021 at 7:49 PM kernel test robot <lkp@intel.com> wrote:
>> I love your patch! Yet something to improve:
> 
> Definitely!
> 
>> All errors (new ones prefixed by >>):
>>
>>>> drivers/clk/rockchip/clk.c:27:10: fatal error: clk-fractional-divider.h: No such file or directory
>>        27 | #include "clk-fractional-divider.h"
>>           |          ^~~~~~~~~~~~~~~~~~~~~~~~~~
>>     compilation terminated.
> 
> Indeed. No idea how to compile-test this on x86.
> Let me see what I can do to avoid other issues.

Ha, the individual SoC-specific parts have COMPILE_TEST support, but the 
top-level COMMON_CLK_ROCKCHIP doesn't. That could probably be fixed.

Otherwise, you can always grab a toolchain from [1] (if your distro 
doesn't offer one already) and cross-compile - defconfig for arm64 or 
multi_v7_defconfig for arm should cover it.

Robin.

[1] https://cdn.kernel.org/pub/tools/crosstool/
kernel test robot July 15, 2021, 10:41 p.m. UTC | #4
Hi Andy,

I love your patch! Yet something to improve:

[auto build test ERROR on clk/clk-next]
[also build test ERROR on rockchip/for-next linux/master linus/master v5.14-rc1 next-20210715]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Andy-Shevchenko/clk-fractional-divider-Export-approximation-algo-to-the-CCF-users/20210715-200828
base:   https://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git clk-next
config: arm64-buildonly-randconfig-r001-20210715 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 0e49c54a8cbd3e779e5526a5888c683c01cc3c50)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install arm64 cross compiling tool for clang build
        # apt-get install binutils-aarch64-linux-gnu
        # https://github.com/0day-ci/linux/commit/bcba401c1ad5c03f7d638f99c799576a771e87ca
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Andy-Shevchenko/clk-fractional-divider-Export-approximation-algo-to-the-CCF-users/20210715-200828
        git checkout bcba401c1ad5c03f7d638f99c799576a771e87ca
        # save the attached .config to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross O=build_dir ARCH=arm64 SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> drivers/clk/rockchip/clk.c:27:10: fatal error: 'clk-fractional-divider.h' file not found
   #include "clk-fractional-divider.h"
            ^~~~~~~~~~~~~~~~~~~~~~~~~~
   1 error generated.


vim +27 drivers/clk/rockchip/clk.c

    25	
    26	#include "clk.h"
  > 27	#include "clk-fractional-divider.h"
    28	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Andy Shevchenko July 16, 2021, 1:09 p.m. UTC | #5
On Thu, Jul 15, 2021 at 06:58:40PM +0100, Robin Murphy wrote:
> On 2021-07-15 17:51, Andy Shevchenko wrote:
> > On Thu, Jul 15, 2021 at 7:49 PM kernel test robot <lkp@intel.com> wrote:
> > > I love your patch! Yet something to improve:
> > 
> > Definitely!
> > 
> > > All errors (new ones prefixed by >>):
> > > 
> > > > > drivers/clk/rockchip/clk.c:27:10: fatal error: clk-fractional-divider.h: No such file or directory
> > >        27 | #include "clk-fractional-divider.h"
> > >           |          ^~~~~~~~~~~~~~~~~~~~~~~~~~
> > >     compilation terminated.
> > 
> > Indeed. No idea how to compile-test this on x86.
> > Let me see what I can do to avoid other issues.
> 
> Ha, the individual SoC-specific parts have COMPILE_TEST support, but the
> top-level COMMON_CLK_ROCKCHIP doesn't. That could probably be fixed.
> 
> Otherwise, you can always grab a toolchain from [1] (if your distro doesn't
> offer one already) and cross-compile - defconfig for arm64 or
> multi_v7_defconfig for arm should cover it.

With a hack patch I was able to compile-test.
diff mbox series

Patch

diff --git a/drivers/clk/clk-fractional-divider.c b/drivers/clk/clk-fractional-divider.c
index b1e556f20911..535d299af646 100644
--- a/drivers/clk/clk-fractional-divider.c
+++ b/drivers/clk/clk-fractional-divider.c
@@ -14,6 +14,8 @@ 
 #include <linux/slab.h>
 #include <linux/rational.h>
 
+#include "clk-fractional-divider.h"
+
 static inline u32 clk_fd_readl(struct clk_fractional_divider *fd)
 {
 	if (fd->flags & CLK_FRAC_DIVIDER_BIG_ENDIAN)
@@ -68,9 +70,10 @@  static unsigned long clk_fd_recalc_rate(struct clk_hw *hw,
 	return ret;
 }
 
-static void clk_fd_general_approximation(struct clk_hw *hw, unsigned long rate,
-					 unsigned long *parent_rate,
-					 unsigned long *m, unsigned long *n)
+void clk_fractional_divider_general_approximation(struct clk_hw *hw,
+						  unsigned long rate,
+						  unsigned long *parent_rate,
+						  unsigned long *m, unsigned long *n)
 {
 	struct clk_fractional_divider *fd = to_clk_fd(hw);
 	unsigned long scale;
@@ -102,7 +105,7 @@  static long clk_fd_round_rate(struct clk_hw *hw, unsigned long rate,
 	if (fd->approximation)
 		fd->approximation(hw, rate, parent_rate, &m, &n);
 	else
-		clk_fd_general_approximation(hw, rate, parent_rate, &m, &n);
+		clk_fractional_divider_general_approximation(hw, rate, parent_rate, &m, &n);
 
 	ret = (u64)*parent_rate * m;
 	do_div(ret, n);
diff --git a/drivers/clk/clk-fractional-divider.h b/drivers/clk/clk-fractional-divider.h
new file mode 100644
index 000000000000..4fa359a12ef4
--- /dev/null
+++ b/drivers/clk/clk-fractional-divider.h
@@ -0,0 +1,9 @@ 
+/* SPDX-License-Identifier: GPL-2.0 */
+
+struct clk_hw;
+
+void clk_fractional_divider_general_approximation(struct clk_hw *hw,
+						  unsigned long rate,
+						  unsigned long *parent_rate,
+						  unsigned long *m,
+						  unsigned long *n);
diff --git a/drivers/clk/rockchip/clk.c b/drivers/clk/rockchip/clk.c
index 049e5e0b64f6..ce7b71594827 100644
--- a/drivers/clk/rockchip/clk.c
+++ b/drivers/clk/rockchip/clk.c
@@ -22,7 +22,9 @@ 
 #include <linux/regmap.h>
 #include <linux/reboot.h>
 #include <linux/rational.h>
+
 #include "clk.h"
+#include "clk-fractional-divider.h"
 
 /*
  * Register a clock branch.
@@ -178,10 +180,8 @@  static void rockchip_fractional_approximation(struct clk_hw *hw,
 		unsigned long rate, unsigned long *parent_rate,
 		unsigned long *m, unsigned long *n)
 {
-	struct clk_fractional_divider *fd = to_clk_fd(hw);
 	unsigned long p_rate, p_parent_rate;
 	struct clk_hw *p_parent;
-	unsigned long scale;
 
 	p_rate = clk_hw_get_rate(clk_hw_get_parent(hw));
 	if ((rate * 20 > p_rate) && (p_rate % rate != 0)) {
@@ -190,18 +190,7 @@  static void rockchip_fractional_approximation(struct clk_hw *hw,
 		*parent_rate = p_parent_rate;
 	}
 
-	/*
-	 * Get rate closer to *parent_rate to guarantee there is no overflow
-	 * for m and n. In the result it will be the nearest rate left shifted
-	 * by (scale - fd->nwidth) bits.
-	 */
-	scale = fls_long(*parent_rate / rate - 1);
-	if (scale > fd->nwidth)
-		rate <<= scale - fd->nwidth;
-
-	rational_best_approximation(rate, *parent_rate,
-			GENMASK(fd->mwidth - 1, 0), GENMASK(fd->nwidth - 1, 0),
-			m, n);
+	clk_fractional_divider_general_approximation(hw, rate, parent_rate, m, n);
 }
 
 static struct clk *rockchip_clk_register_frac_branch(