1*7e38c880Sjmcneill /* $NetBSD: meson_clk_mux.c,v 1.2 2019/02/25 19:30:17 jmcneill Exp $ */
2912cfa14Sjmcneill
3912cfa14Sjmcneill /*-
4912cfa14Sjmcneill * Copyright (c) 2017-2019 Jared McNeill <jmcneill@invisible.ca>
5912cfa14Sjmcneill * All rights reserved.
6912cfa14Sjmcneill *
7912cfa14Sjmcneill * Redistribution and use in source and binary forms, with or without
8912cfa14Sjmcneill * modification, are permitted provided that the following conditions
9912cfa14Sjmcneill * are met:
10912cfa14Sjmcneill * 1. Redistributions of source code must retain the above copyright
11912cfa14Sjmcneill * notice, this list of conditions and the following disclaimer.
12912cfa14Sjmcneill * 2. Redistributions in binary form must reproduce the above copyright
13912cfa14Sjmcneill * notice, this list of conditions and the following disclaimer in the
14912cfa14Sjmcneill * documentation and/or other materials provided with the distribution.
15912cfa14Sjmcneill *
16912cfa14Sjmcneill * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17912cfa14Sjmcneill * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18912cfa14Sjmcneill * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19912cfa14Sjmcneill * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20912cfa14Sjmcneill * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21912cfa14Sjmcneill * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22912cfa14Sjmcneill * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23912cfa14Sjmcneill * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24912cfa14Sjmcneill * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25912cfa14Sjmcneill * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26912cfa14Sjmcneill * SUCH DAMAGE.
27912cfa14Sjmcneill */
28912cfa14Sjmcneill
29912cfa14Sjmcneill #include <sys/cdefs.h>
30*7e38c880Sjmcneill __KERNEL_RCSID(0, "$NetBSD: meson_clk_mux.c,v 1.2 2019/02/25 19:30:17 jmcneill Exp $");
31912cfa14Sjmcneill
32912cfa14Sjmcneill #include <sys/param.h>
33912cfa14Sjmcneill #include <sys/bus.h>
34912cfa14Sjmcneill
35912cfa14Sjmcneill #include <dev/clk/clk_backend.h>
36912cfa14Sjmcneill
37912cfa14Sjmcneill #include <arm/amlogic/meson_clk.h>
38912cfa14Sjmcneill
39912cfa14Sjmcneill const char *
meson_clk_mux_get_parent(struct meson_clk_softc * sc,struct meson_clk_clk * clk)40912cfa14Sjmcneill meson_clk_mux_get_parent(struct meson_clk_softc *sc, struct meson_clk_clk *clk)
41912cfa14Sjmcneill {
42912cfa14Sjmcneill struct meson_clk_mux *mux = &clk->u.mux;
43912cfa14Sjmcneill uint32_t val;
44912cfa14Sjmcneill u_int sel;
45912cfa14Sjmcneill
46912cfa14Sjmcneill KASSERT(clk->type == MESON_CLK_MUX);
47912cfa14Sjmcneill
48*7e38c880Sjmcneill CLK_LOCK(sc);
49912cfa14Sjmcneill val = CLK_READ(sc, mux->reg);
50*7e38c880Sjmcneill CLK_UNLOCK(sc);
51*7e38c880Sjmcneill
52912cfa14Sjmcneill sel = __SHIFTOUT(val, mux->sel);
53912cfa14Sjmcneill if (sel >= mux->nparents)
54912cfa14Sjmcneill return NULL;
55912cfa14Sjmcneill
56912cfa14Sjmcneill return mux->parents[sel];
57912cfa14Sjmcneill }
58