Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/arm/sunxi Make sunxi_ccu_div_set_rate() work on non...
details: https://anonhg.NetBSD.org/src/rev/c3c497c82c26
branches: trunk
changeset: 360624:c3c497c82c26
user: bouyer <bouyer%NetBSD.org@localhost>
date: Mon Mar 19 16:19:17 2018 +0000
description:
Make sunxi_ccu_div_set_rate() work on non-SUNXI_CCU_DIV_TIMES_TWO
clocks.
diffstat:
sys/arch/arm/sunxi/sunxi_ccu_div.c | 19 +++++++++++++------
1 files changed, 13 insertions(+), 6 deletions(-)
diffs (53 lines):
diff -r aaef25aff25c -r c3c497c82c26 sys/arch/arm/sunxi/sunxi_ccu_div.c
--- a/sys/arch/arm/sunxi/sunxi_ccu_div.c Mon Mar 19 16:18:30 2018 +0000
+++ b/sys/arch/arm/sunxi/sunxi_ccu_div.c Mon Mar 19 16:19:17 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_ccu_div.c,v 1.4 2017/10/09 14:01:59 jmcneill Exp $ */
+/* $NetBSD: sunxi_ccu_div.c,v 1.5 2018/03/19 16:19:17 bouyer Exp $ */
/*-
* Copyright (c) 2017 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sunxi_ccu_div.c,v 1.4 2017/10/09 14:01:59 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_ccu_div.c,v 1.5 2018/03/19 16:19:17 bouyer Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@@ -104,6 +104,7 @@
{
struct sunxi_ccu_div *div = &clk->u.div;
struct clk *clkp, *clkp_parent;
+ int parent_rate;
uint32_t val, raw_div;
int ratio;
@@ -123,16 +124,22 @@
val = CCU_READ(sc, div->reg);
+ parent_rate = clk_get_rate(clkp_parent);
+ if (parent_rate == 0)
+ return (new_rate == 0) ? 0 : ERANGE;
+
+ ratio = howmany(parent_rate, new_rate);
if ((div->flags & SUNXI_CCU_DIV_TIMES_TWO) != 0) {
- ratio = howmany(clk_get_rate(clkp_parent), new_rate);
if (ratio > 1 && (ratio & 1) != 0)
ratio++;
raw_div = ratio >> 1;
- if (raw_div > __SHIFTOUT_MASK(div->div))
- return ERANGE;
+ } else if ((div->flags & SUNXI_CCU_DIV_POWER_OF_TWO) != 0) {
+ return EINVAL;
} else {
- return EINVAL;
+ raw_div = (ratio > 0 ) ? ratio - 1 : 0;
}
+ if (raw_div > __SHIFTOUT_MASK(div->div))
+ return ERANGE;
val &= ~div->div;
val |= __SHIFTIN(raw_div, div->div);
Home |
Main Index |
Thread Index |
Old Index