xref: /netbsd-src/sys/arch/arm/nxp/imx_ccm_gate.c (revision 8644267a503e0f573f2833152303dbf2ce4aca52)
1*8644267aSskrll /* $NetBSD: imx_ccm_gate.c,v 1.1 2020/12/23 14:42:38 skrll Exp $ */
2*8644267aSskrll 
3*8644267aSskrll /*-
4*8644267aSskrll  * Copyright (c) 2020 Jared McNeill <jmcneill@invisible.ca>
5*8644267aSskrll  * All rights reserved.
6*8644267aSskrll  *
7*8644267aSskrll  * Redistribution and use in source and binary forms, with or without
8*8644267aSskrll  * modification, are permitted provided that the following conditions
9*8644267aSskrll  * are met:
10*8644267aSskrll  * 1. Redistributions of source code must retain the above copyright
11*8644267aSskrll  *    notice, this list of conditions and the following disclaimer.
12*8644267aSskrll  * 2. Redistributions in binary form must reproduce the above copyright
13*8644267aSskrll  *    notice, this list of conditions and the following disclaimer in the
14*8644267aSskrll  *    documentation and/or other materials provided with the distribution.
15*8644267aSskrll  *
16*8644267aSskrll  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17*8644267aSskrll  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18*8644267aSskrll  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19*8644267aSskrll  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20*8644267aSskrll  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21*8644267aSskrll  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22*8644267aSskrll  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23*8644267aSskrll  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24*8644267aSskrll  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25*8644267aSskrll  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*8644267aSskrll  * SUCH DAMAGE.
27*8644267aSskrll  */
28*8644267aSskrll 
29*8644267aSskrll #include <sys/cdefs.h>
30*8644267aSskrll __KERNEL_RCSID(0, "$NetBSD: imx_ccm_gate.c,v 1.1 2020/12/23 14:42:38 skrll Exp $");
31*8644267aSskrll 
32*8644267aSskrll #include <sys/param.h>
33*8644267aSskrll #include <sys/bus.h>
34*8644267aSskrll 
35*8644267aSskrll #include <dev/clk/clk_backend.h>
36*8644267aSskrll 
37*8644267aSskrll #include <arm/nxp/imx_ccm.h>
38*8644267aSskrll 
39*8644267aSskrll int
imx_ccm_gate_enable(struct imx_ccm_softc * sc,struct imx_ccm_clk * clk,int enable)40*8644267aSskrll imx_ccm_gate_enable(struct imx_ccm_softc *sc, struct imx_ccm_clk *clk,
41*8644267aSskrll     int enable)
42*8644267aSskrll {
43*8644267aSskrll 	struct imx_ccm_gate *gate = &clk->u.gate;
44*8644267aSskrll 	uint32_t val;
45*8644267aSskrll 
46*8644267aSskrll 	KASSERT(clk->type == IMX_CCM_GATE);
47*8644267aSskrll 
48*8644267aSskrll 	val = CCM_READ(sc, clk->regidx, gate->reg);
49*8644267aSskrll 	if (enable)
50*8644267aSskrll 		val |= gate->mask;
51*8644267aSskrll 	else
52*8644267aSskrll 		val &= ~gate->mask;
53*8644267aSskrll 	CCM_WRITE(sc, clk->regidx, gate->reg, val);
54*8644267aSskrll 
55*8644267aSskrll 	return 0;
56*8644267aSskrll }
57*8644267aSskrll 
58*8644267aSskrll const char *
imx_ccm_gate_get_parent(struct imx_ccm_softc * sc,struct imx_ccm_clk * clk)59*8644267aSskrll imx_ccm_gate_get_parent(struct imx_ccm_softc *sc,
60*8644267aSskrll     struct imx_ccm_clk *clk)
61*8644267aSskrll {
62*8644267aSskrll 	struct imx_ccm_gate *gate = &clk->u.gate;
63*8644267aSskrll 
64*8644267aSskrll 	KASSERT(clk->type == IMX_CCM_GATE);
65*8644267aSskrll 
66*8644267aSskrll 	return gate->parent;
67*8644267aSskrll }
68