xref: /netbsd-src/sys/arch/arm/rockchip/rk_cru_gate.c (revision 62d94959b408c2a3c62171bb182d06a053973ef9)
1*62d94959Sjmcneill /* $NetBSD: rk_cru_gate.c,v 1.2 2018/06/17 14:48:15 jmcneill Exp $ */
26726462dSjmcneill 
36726462dSjmcneill /*-
46726462dSjmcneill  * Copyright (c) 2018 Jared McNeill <jmcneill@invisible.ca>
56726462dSjmcneill  * All rights reserved.
66726462dSjmcneill  *
76726462dSjmcneill  * Redistribution and use in source and binary forms, with or without
86726462dSjmcneill  * modification, are permitted provided that the following conditions
96726462dSjmcneill  * are met:
106726462dSjmcneill  * 1. Redistributions of source code must retain the above copyright
116726462dSjmcneill  *    notice, this list of conditions and the following disclaimer.
126726462dSjmcneill  * 2. Redistributions in binary form must reproduce the above copyright
136726462dSjmcneill  *    notice, this list of conditions and the following disclaimer in the
146726462dSjmcneill  *    documentation and/or other materials provided with the distribution.
156726462dSjmcneill  *
166726462dSjmcneill  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
176726462dSjmcneill  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
186726462dSjmcneill  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
196726462dSjmcneill  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
206726462dSjmcneill  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
216726462dSjmcneill  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
226726462dSjmcneill  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
236726462dSjmcneill  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
246726462dSjmcneill  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
256726462dSjmcneill  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
266726462dSjmcneill  * SUCH DAMAGE.
276726462dSjmcneill  */
286726462dSjmcneill 
296726462dSjmcneill #include <sys/cdefs.h>
30*62d94959Sjmcneill __KERNEL_RCSID(0, "$NetBSD: rk_cru_gate.c,v 1.2 2018/06/17 14:48:15 jmcneill Exp $");
316726462dSjmcneill 
326726462dSjmcneill #include <sys/param.h>
336726462dSjmcneill #include <sys/bus.h>
346726462dSjmcneill 
356726462dSjmcneill #include <dev/clk/clk_backend.h>
366726462dSjmcneill 
376726462dSjmcneill #include <arm/rockchip/rk_cru.h>
386726462dSjmcneill 
396726462dSjmcneill int
rk_cru_gate_enable(struct rk_cru_softc * sc,struct rk_cru_clk * clk,int enable)406726462dSjmcneill rk_cru_gate_enable(struct rk_cru_softc *sc, struct rk_cru_clk *clk,
416726462dSjmcneill     int enable)
426726462dSjmcneill {
436726462dSjmcneill 	struct rk_cru_gate *gate = &clk->u.gate;
446726462dSjmcneill 
456726462dSjmcneill 	KASSERT(clk->type == RK_CRU_GATE);
466726462dSjmcneill 
476726462dSjmcneill 	const uint32_t write_mask = gate->mask << 16;
48*62d94959Sjmcneill 	const uint32_t write_val = enable ? 0 : gate->mask;
496726462dSjmcneill 
506726462dSjmcneill 	CRU_WRITE(sc, gate->reg, write_mask | write_val);
516726462dSjmcneill 
526726462dSjmcneill 	return 0;
536726462dSjmcneill }
546726462dSjmcneill 
556726462dSjmcneill const char *
rk_cru_gate_get_parent(struct rk_cru_softc * sc,struct rk_cru_clk * clk)566726462dSjmcneill rk_cru_gate_get_parent(struct rk_cru_softc *sc,
576726462dSjmcneill     struct rk_cru_clk *clk)
586726462dSjmcneill {
596726462dSjmcneill 	struct rk_cru_gate *gate = &clk->u.gate;
606726462dSjmcneill 
616726462dSjmcneill 	KASSERT(clk->type == RK_CRU_GATE);
626726462dSjmcneill 
636726462dSjmcneill 	return gate->parent;
646726462dSjmcneill }
65