Make gate enable/disable logic easier to read. NFC.diff -r1.1 -r1.2 src/sys/arch/arm/rockchip/rk_cru_composite.c
(jmcneill)
--- src/sys/arch/arm/rockchip/rk_cru_composite.c 2018/06/16 00:19:04 1.1
+++ src/sys/arch/arm/rockchip/rk_cru_composite.c 2018/06/17 14:48:15 1.2
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: rk_cru_composite.c,v 1.1 2018/06/16 00:19:04 jmcneill Exp $ */ | 1 | /* $NetBSD: rk_cru_composite.c,v 1.2 2018/06/17 14:48:15 jmcneill Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2018 Jared McNeill <jmcneill@invisible.ca> | 4 | * Copyright (c) 2018 Jared McNeill <jmcneill@invisible.ca> | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -17,48 +17,48 @@ | @@ -17,48 +17,48 @@ | |||
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | |
23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
26 | * SUCH DAMAGE. | 26 | * SUCH DAMAGE. | |
27 | */ | 27 | */ | |
28 | 28 | |||
29 | #include <sys/cdefs.h> | 29 | #include <sys/cdefs.h> | |
30 | __KERNEL_RCSID(0, "$NetBSD: rk_cru_composite.c,v 1.1 2018/06/16 00:19:04 jmcneill Exp $"); | 30 | __KERNEL_RCSID(0, "$NetBSD: rk_cru_composite.c,v 1.2 2018/06/17 14:48:15 jmcneill Exp $"); | |
31 | 31 | |||
32 | #include <sys/param.h> | 32 | #include <sys/param.h> | |
33 | #include <sys/bus.h> | 33 | #include <sys/bus.h> | |
34 | 34 | |||
35 | #include <dev/clk/clk_backend.h> | 35 | #include <dev/clk/clk_backend.h> | |
36 | 36 | |||
37 | #include <arm/rockchip/rk_cru.h> | 37 | #include <arm/rockchip/rk_cru.h> | |
38 | 38 | |||
39 | int | 39 | int | |
40 | rk_cru_composite_enable(struct rk_cru_softc *sc, struct rk_cru_clk *clk, | 40 | rk_cru_composite_enable(struct rk_cru_softc *sc, struct rk_cru_clk *clk, | |
41 | int enable) | 41 | int enable) | |
42 | { | 42 | { | |
43 | struct rk_cru_composite *composite = &clk->u.composite; | 43 | struct rk_cru_composite *composite = &clk->u.composite; | |
44 | 44 | |||
45 | KASSERT(clk->type == RK_CRU_COMPOSITE); | 45 | KASSERT(clk->type == RK_CRU_COMPOSITE); | |
46 | 46 | |||
47 | if (composite->gate_mask == 0) | 47 | if (composite->gate_mask == 0) | |
48 | return enable ? 0 : ENXIO; | 48 | return enable ? 0 : ENXIO; | |
49 | 49 | |||
50 | const uint32_t write_mask = composite->gate_mask << 16; | 50 | const uint32_t write_mask = composite->gate_mask << 16; | |
51 | const uint32_t write_val = __SHIFTIN(!enable, composite->gate_mask); | 51 | const uint32_t write_val = enable ? 0 : composite->gate_mask; | |
52 | 52 | |||
53 | CRU_WRITE(sc, composite->gate_reg, write_mask | write_val); | 53 | CRU_WRITE(sc, composite->gate_reg, write_mask | write_val); | |
54 | 54 | |||
55 | return 0; | 55 | return 0; | |
56 | } | 56 | } | |
57 | 57 | |||
58 | u_int | 58 | u_int | |
59 | rk_cru_composite_get_rate(struct rk_cru_softc *sc, | 59 | rk_cru_composite_get_rate(struct rk_cru_softc *sc, | |
60 | struct rk_cru_clk *clk) | 60 | struct rk_cru_clk *clk) | |
61 | { | 61 | { | |
62 | struct rk_cru_composite *composite = &clk->u.composite; | 62 | struct rk_cru_composite *composite = &clk->u.composite; | |
63 | struct clk *clkp, *clkp_parent; | 63 | struct clk *clkp, *clkp_parent; | |
64 | 64 |
--- src/sys/arch/arm/rockchip/rk_cru_gate.c 2018/06/16 00:19:04 1.1
+++ src/sys/arch/arm/rockchip/rk_cru_gate.c 2018/06/17 14:48:15 1.2
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: rk_cru_gate.c,v 1.1 2018/06/16 00:19:04 jmcneill Exp $ */ | 1 | /* $NetBSD: rk_cru_gate.c,v 1.2 2018/06/17 14:48:15 jmcneill Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2018 Jared McNeill <jmcneill@invisible.ca> | 4 | * Copyright (c) 2018 Jared McNeill <jmcneill@invisible.ca> | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -17,45 +17,45 @@ | @@ -17,45 +17,45 @@ | |||
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | |
23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
26 | * SUCH DAMAGE. | 26 | * SUCH DAMAGE. | |
27 | */ | 27 | */ | |
28 | 28 | |||
29 | #include <sys/cdefs.h> | 29 | #include <sys/cdefs.h> | |
30 | __KERNEL_RCSID(0, "$NetBSD: rk_cru_gate.c,v 1.1 2018/06/16 00:19:04 jmcneill Exp $"); | 30 | __KERNEL_RCSID(0, "$NetBSD: rk_cru_gate.c,v 1.2 2018/06/17 14:48:15 jmcneill Exp $"); | |
31 | 31 | |||
32 | #include <sys/param.h> | 32 | #include <sys/param.h> | |
33 | #include <sys/bus.h> | 33 | #include <sys/bus.h> | |
34 | 34 | |||
35 | #include <dev/clk/clk_backend.h> | 35 | #include <dev/clk/clk_backend.h> | |
36 | 36 | |||
37 | #include <arm/rockchip/rk_cru.h> | 37 | #include <arm/rockchip/rk_cru.h> | |
38 | 38 | |||
39 | int | 39 | int | |
40 | rk_cru_gate_enable(struct rk_cru_softc *sc, struct rk_cru_clk *clk, | 40 | rk_cru_gate_enable(struct rk_cru_softc *sc, struct rk_cru_clk *clk, | |
41 | int enable) | 41 | int enable) | |
42 | { | 42 | { | |
43 | struct rk_cru_gate *gate = &clk->u.gate; | 43 | struct rk_cru_gate *gate = &clk->u.gate; | |
44 | 44 | |||
45 | KASSERT(clk->type == RK_CRU_GATE); | 45 | KASSERT(clk->type == RK_CRU_GATE); | |
46 | 46 | |||
47 | const uint32_t write_mask = gate->mask << 16; | 47 | const uint32_t write_mask = gate->mask << 16; | |
48 | const uint32_t write_val = __SHIFTIN(!enable, gate->mask); | 48 | const uint32_t write_val = enable ? 0 : gate->mask; | |
49 | 49 | |||
50 | CRU_WRITE(sc, gate->reg, write_mask | write_val); | 50 | CRU_WRITE(sc, gate->reg, write_mask | write_val); | |
51 | 51 | |||
52 | return 0; | 52 | return 0; | |
53 | } | 53 | } | |
54 | 54 | |||
55 | const char * | 55 | const char * | |
56 | rk_cru_gate_get_parent(struct rk_cru_softc *sc, | 56 | rk_cru_gate_get_parent(struct rk_cru_softc *sc, | |
57 | struct rk_cru_clk *clk) | 57 | struct rk_cru_clk *clk) | |
58 | { | 58 | { | |
59 | struct rk_cru_gate *gate = &clk->u.gate; | 59 | struct rk_cru_gate *gate = &clk->u.gate; | |
60 | 60 | |||
61 | KASSERT(clk->type == RK_CRU_GATE); | 61 | KASSERT(clk->type == RK_CRU_GATE); |