clk: fractional-divider: do a clean up and update
Subsystems (5)
Andy Shevchenko
reviewerv6 cover clk: fractional-divider: do a clean up and update
The series provides a clean up for clk-fractional-divider together with moving it to use rational best approximation algorithm. I think the patches are self-explanatory.
The series was tested with 8250_dw UART driver on Intel Braswell.
Patch 5 is an amendment to existing user of the fractional divider outside of clock framework.
Changelog v6:
- rebase on top of latest clk-next branch
- add ACKs from Heikki
Changelog v5:
- drop patch 1 (there is another fix already in upstream)
- add tags (Ack, Review)
Changelog v4:
- remove dependency to clk_div_mask() and use GENMASK() instead
- apply changes to rockchip
- amend 8250_dw driver to use proposed changes
Changelog v3:
- add patch 2/3 to simplify further usage
- don't use mult_frac() due to potential overflow on 32 bit kernels
- guarantee in ->round_rate() that m and n will not overflow
Changelog v2:
- move to rational_best_approximation() and mult_frac()
- add patch 2/2
Andy Shevchenko (5):
clk: fractional-divider: rename prate -> parent_rate
clk: fractional-divider: keep mwidth and nwidth internally
clk: rockchip: save width in struct clk_fractional_divider
clk: fractional-divider: switch to rational best approximation
serial: 8250_dw: allow lower reference frequencies
drivers/clk/Kconfig | 1 + drivers/clk/clk-fractional-divider.c | 53 ++++++++++++++++++++++-------------- drivers/clk/rockchip/clk.c | 6 ++-- drivers/tty/serial/8250/8250_dw.c | 4 --- include/linux/clk-provider.h | 3 +- 5 files changed, 40 insertions(+), 27 deletions(-)
Signature · 1 line
2.5.1
Andy Shevchenko
reviewerPATCH v6 1/5 clk: fractional-divider: rename prate -> parent_rate
Rename function parameter to be more explicit what it is for. This also makes it in align with struct clk_ops.
There is no functional change.
--- drivers/clk/clk-fractional-divider.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/clk/clk-fractional-divider.c +5 -5
@@ -50,18 +50,18 @@ static unsigned long clk_fd_recalc_rate(struct clk_hw *hw, }static long clk_fd_round_rate (struct clk_hw *hw,unsigned long rate, -unsigned long *prate) +unsigned long *parent_rate) {struct clk_fractional_divider *fd =to_clk_fd (hw);unsigned maxn = (fd->nmask >> fd->nshift) +1 ;unsigned div; -if (!rate || rate >= *prate) -return *prate; +if (!rate || rate >= *parent_rate) +return *parent_rate; - div =gcd (*prate, rate); + div =gcd (*parent_rate, rate); -while ((*prate / div) > maxn) { +while ((*parent_rate / div) > maxn) { div <<=1 ; rate <<=1 ; }
Signature · 1 line
2.5.1
Stephen Boyd
AppliedRe: [PATCH v6 1/5] clk: fractional-divider: rename prate -> parent_rate
Quoted 8 lines · Andy Shevchenko
Rename function parameter to be more explicit what it is for. This also makes it in align with struct
clk_ops.There is no functional change.
Reviewed-by Heikki Krogerus <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>---
Applied to clk-next
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Andy Shevchenko
reviewerPATCH v6 2/5 clk: fractional-divider: keep mwidth and nwidth internally
In reply to Andy ShevchenkoThe patch adds mwidth and nwidth fields to the struct clk_fractional_divider for further usage. While here, use GENMASK() instead of open coding this functionality.
--- drivers/clk/clk-fractional-divider.c | 6 ++++-- include/linux/clk-provider.h | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-)
drivers/clk/clk-fractional-divider.c +4 -2
@@ -128,9 +128,11 @@ struct clk *clk_register_fractional_divider(struct device *dev, fd->reg = reg; fd->mshift = mshift; - fd->mmask = (BIT (mwidth) -1 ) << mshift; + fd->mwidth = mwidth; + fd->mmask =GENMASK (mwidth -1 ,0 ) << mshift; fd->nshift = nshift; - fd->nmask = (BIT (nwidth) -1 ) << nshift; + fd->nwidth = nwidth; + fd->nmask =GENMASK (nwidth -1 ,0 ) << nshift; fd->flags = clk_divider_flags; fd->lock = lock; fd->hw.init = &init;
include/linux/clk-provider.h +2 -1
@@ -500,13 +500,14 @@ struct clk *clk_register_fixed_factor(struct device *dev, const char *name,* * Clock with adjustable fractional divider affecting its output frequency. */ -struct clk_fractional_divider {struct clk_hw hw;void __iomem *reg;u8 mshift; +u8 mwidth;u32 mmask;u8 nshift; +u8 nwidth;u32 nmask;u8 flags;spinlock_t *lock;
Signature · 1 line
2.5.1
Stephen Boyd
AppliedRe: [PATCH v6 2/5] clk: fractional-divider: keep mwidth and nwidth internally
Quoted 7 lines · Andy Shevchenko
The patch adds mwidth and nwidth fields to the struct
clk_fractional_dividerfor further usage. While here, useGENMASK()instead of open coding this functionality.Reviewed-by Heikki Krogerus <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>---
Applied to clk-next
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Andy Shevchenko
reviewerPATCH v6 3/5 clk: rockchip: save width in struct clk_fractional_divider
In reply to Andy ShevchenkoThe ->mwidth and ->nwidth fields will be used by clk-fractional-divider when it will be switched to rational base approximation algorithm.
--- drivers/clk/rockchip/clk.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/clk/rockchip/clk.c +4 -2
@@ -135,9 +135,11 @@ static struct clk *rockchip_clk_register_frac_branch(const char *name, div->flags = div_flags; div->reg = base + muxdiv_offset; div->mshift =16 ; - div->mmask =0xffff0000 ; + div->mwidth =16 ; + div->mmask =GENMASK (div->mwidth -1 ,0 ) << div->mshift; div->nshift =0 ; - div->nmask =0xffff ; + div->nwidth =16 ; + div->nmask =GENMASK (div->nwidth -1 ,0 ) << div->nshift; div->lock = lock; div_ops = &clk_fractional_divider_ops;
Signature · 1 line
2.5.1
Stephen Boyd
AppliedRe: [PATCH v6 3/5] clk: rockchip: save width in struct clk_fractional_divider
Quoted 6 lines · Andy Shevchenko
The ->mwidth and ->nwidth fields will be used by clk-fractional-divider when it will be switched to rational base approximation algorithm.
Reviewed-by Heiko Stuebner <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>---
Applied to clk-next
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Andy Shevchenko
reviewerPATCH v6 4/5 clk: fractional-divider: switch to rational best approximation
In reply to Andy ShevchenkoThis patch converts the code to use rational best approximation algorithm which is much more precise.
--- drivers/clk/Kconfig | 1 + drivers/clk/clk-fractional-divider.c | 41 +++++++++++++++++++++++------------- 2 files changed, 27 insertions(+), 15 deletions(-)
drivers/clk/Kconfig +1 -0
@@ -14,6 +14,7 @@ config COMMON_CLK select HAVE_CLK_PREPARE select CLKDEV_LOOKUP select SRCU + select RATIONAL ---help--- The common clock framework is a single definition of struct clk, useful across many platforms, as well as an
drivers/clk/clk-fractional-divider.c +26 -15
79 lines not on this page · raw message
Signature · 1 line
2.5.1
Stephen Boyd
AppliedRe: [PATCH v6 4/5] clk: fractional-divider: switch to rational best approximation
Quoted 7 lines · Andy Shevchenko
This patch converts the code to use rational best approximation algorithm which is much more precise.
Suggested-by Stephen Boyd <[email protected]>Reviewed-by Heikki Krogerus <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>---
Applied to clk-next
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Andy Shevchenko
reviewerPATCH v6 5/5 serial: 8250_dw: allow lower reference frequencies
In reply to Andy ShevchenkoWe have couple of standard but rare used baudrates which are not supported by 1,8432MHz reference frequency. Besides that user can potentially ask for any baudrate (via BOTHER flag) and we currently don't fully support that. Since clk-fractional-divider is moved to use rational best approximation for reference frequency we may amend the driver to support whatever user wants.
--- drivers/tty/serial/8250/8250_dw.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/tty/serial/8250/8250_dw.c +0 -4
@@ -224,10 +224,6 @@ static void dw8250_set_termios(struct uart_port *p, struct ktermios *termios,if (IS_ERR (d->clk) || !old) goto out; -/* Not requesting clock rates below 1.8432Mhz */ -if (baud <115200 ) - baud =115200 ; -clk_disable_unprepare (d->clk); rate =clk_round_rate (d->clk, baud *16 ); ret =clk_set_rate (d->clk, rate);
Signature · 1 line
2.5.1
Stephen Boyd
AppliedRe: [PATCH v6 5/5] serial: 8250_dw: allow lower reference frequencies
Quoted 9 lines · Andy Shevchenko
We have couple of standard but rare used baudrates which are not supported by 1,8432MHz reference frequency. Besides that user can potentially ask for any baudrate (via BOTHER flag) and we currently don't fully support that. Since clk-fractional-divider is moved to use rational best approximation for reference frequency we may amend the driver to support whatever user wants.
Signed-off-by Andy Shevchenko <[email protected]>---
Applied to clk-next
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project