xref: /freebsd/sys/arm/mv/mv_cp110_clock.c (revision 73450c4a7acad0e72dced5ce8f0a92d69be93be3)
1*73450c4aSEmmanuel Vadot /*-
2*73450c4aSEmmanuel Vadot  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3*73450c4aSEmmanuel Vadot  *
4*73450c4aSEmmanuel Vadot  * Copyright (c) 2018 Rubicon Communications, LLC (Netgate)
5*73450c4aSEmmanuel Vadot  *
6*73450c4aSEmmanuel Vadot  * Redistribution and use in source and binary forms, with or without
7*73450c4aSEmmanuel Vadot  * modification, are permitted provided that the following conditions
8*73450c4aSEmmanuel Vadot  * are met:
9*73450c4aSEmmanuel Vadot  * 1. Redistributions of source code must retain the above copyright
10*73450c4aSEmmanuel Vadot  *    notice, this list of conditions and the following disclaimer.
11*73450c4aSEmmanuel Vadot  * 2. Redistributions in binary form must reproduce the above copyright
12*73450c4aSEmmanuel Vadot  *    notice, this list of conditions and the following disclaimer in the
13*73450c4aSEmmanuel Vadot  *    documentation and/or other materials provided with the distribution.
14*73450c4aSEmmanuel Vadot  *
15*73450c4aSEmmanuel Vadot  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16*73450c4aSEmmanuel Vadot  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17*73450c4aSEmmanuel Vadot  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18*73450c4aSEmmanuel Vadot  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19*73450c4aSEmmanuel Vadot  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20*73450c4aSEmmanuel Vadot  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21*73450c4aSEmmanuel Vadot  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22*73450c4aSEmmanuel Vadot  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23*73450c4aSEmmanuel Vadot  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24*73450c4aSEmmanuel Vadot  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25*73450c4aSEmmanuel Vadot  * SUCH DAMAGE.
26*73450c4aSEmmanuel Vadot  *
27*73450c4aSEmmanuel Vadot  * $FreeBSD$
28*73450c4aSEmmanuel Vadot  */
29*73450c4aSEmmanuel Vadot 
30*73450c4aSEmmanuel Vadot #include <sys/cdefs.h>
31*73450c4aSEmmanuel Vadot __FBSDID("$FreeBSD$");
32*73450c4aSEmmanuel Vadot 
33*73450c4aSEmmanuel Vadot #include <sys/param.h>
34*73450c4aSEmmanuel Vadot #include <sys/systm.h>
35*73450c4aSEmmanuel Vadot #include <sys/bus.h>
36*73450c4aSEmmanuel Vadot 
37*73450c4aSEmmanuel Vadot #include <sys/kernel.h>
38*73450c4aSEmmanuel Vadot #include <sys/module.h>
39*73450c4aSEmmanuel Vadot #include <sys/rman.h>
40*73450c4aSEmmanuel Vadot #include <sys/lock.h>
41*73450c4aSEmmanuel Vadot #include <sys/mutex.h>
42*73450c4aSEmmanuel Vadot 
43*73450c4aSEmmanuel Vadot #include <machine/bus.h>
44*73450c4aSEmmanuel Vadot #include <machine/resource.h>
45*73450c4aSEmmanuel Vadot #include <machine/intr.h>
46*73450c4aSEmmanuel Vadot 
47*73450c4aSEmmanuel Vadot #include <dev/fdt/simplebus.h>
48*73450c4aSEmmanuel Vadot 
49*73450c4aSEmmanuel Vadot #include <dev/ofw/ofw_bus.h>
50*73450c4aSEmmanuel Vadot #include <dev/ofw/ofw_bus_subr.h>
51*73450c4aSEmmanuel Vadot 
52*73450c4aSEmmanuel Vadot #include <dev/extres/clk/clk_fixed.h>
53*73450c4aSEmmanuel Vadot #include <dev/extres/clk/clk_gate.h>
54*73450c4aSEmmanuel Vadot 
55*73450c4aSEmmanuel Vadot #include <arm/mv/mv_cp110_clock.h>
56*73450c4aSEmmanuel Vadot 
57*73450c4aSEmmanuel Vadot #include "clkdev_if.h"
58*73450c4aSEmmanuel Vadot 
59*73450c4aSEmmanuel Vadot /* Clocks */
60*73450c4aSEmmanuel Vadot static struct clk_fixed_def cp110_clk_pll_0 = {
61*73450c4aSEmmanuel Vadot 	.clkdef.id = CP110_PLL_0,
62*73450c4aSEmmanuel Vadot 	.freq = 1000000000,
63*73450c4aSEmmanuel Vadot };
64*73450c4aSEmmanuel Vadot 
65*73450c4aSEmmanuel Vadot static const char *clk_parents_0[] = {"cp110-pll0-0"};
66*73450c4aSEmmanuel Vadot static const char *clk_parents_1[] = {"cp110-pll0-1"};
67*73450c4aSEmmanuel Vadot 
68*73450c4aSEmmanuel Vadot static struct clk_fixed_def cp110_clk_ppv2_core = {
69*73450c4aSEmmanuel Vadot 	.clkdef.id = CP110_PPV2_CORE,
70*73450c4aSEmmanuel Vadot 	.clkdef.parent_cnt = 1,
71*73450c4aSEmmanuel Vadot 	.mult = 1,
72*73450c4aSEmmanuel Vadot 	.div = 3,
73*73450c4aSEmmanuel Vadot };
74*73450c4aSEmmanuel Vadot 
75*73450c4aSEmmanuel Vadot static struct clk_fixed_def cp110_clk_x2core = {
76*73450c4aSEmmanuel Vadot 	.clkdef.id = CP110_X2CORE,
77*73450c4aSEmmanuel Vadot 	.clkdef.parent_cnt = 1,
78*73450c4aSEmmanuel Vadot 	.mult = 1,
79*73450c4aSEmmanuel Vadot 	.div = 2,
80*73450c4aSEmmanuel Vadot };
81*73450c4aSEmmanuel Vadot 
82*73450c4aSEmmanuel Vadot static const char *core_parents_0[] = {"cp110-x2core-0"};
83*73450c4aSEmmanuel Vadot static const char *core_parents_1[] = {"cp110-x2core-1"};
84*73450c4aSEmmanuel Vadot 
85*73450c4aSEmmanuel Vadot static struct clk_fixed_def cp110_clk_core = {
86*73450c4aSEmmanuel Vadot 	.clkdef.id = CP110_CORE,
87*73450c4aSEmmanuel Vadot 	.clkdef.parent_cnt = 1,
88*73450c4aSEmmanuel Vadot 	.mult = 1,
89*73450c4aSEmmanuel Vadot 	.div = 2,
90*73450c4aSEmmanuel Vadot };
91*73450c4aSEmmanuel Vadot 
92*73450c4aSEmmanuel Vadot static struct clk_fixed_def cp110_clk_sdio = {
93*73450c4aSEmmanuel Vadot 	.clkdef.id = CP110_SDIO,
94*73450c4aSEmmanuel Vadot 	.clkdef.parent_cnt = 1,
95*73450c4aSEmmanuel Vadot 	.mult = 2,
96*73450c4aSEmmanuel Vadot 	.div = 5,
97*73450c4aSEmmanuel Vadot };
98*73450c4aSEmmanuel Vadot 
99*73450c4aSEmmanuel Vadot /* Gates */
100*73450c4aSEmmanuel Vadot 
101*73450c4aSEmmanuel Vadot static struct cp110_gate cp110_gates[] = {
102*73450c4aSEmmanuel Vadot 	CCU_GATE(CP110_GATE_AUDIO, "cp110-gate-audio", 0)
103*73450c4aSEmmanuel Vadot 	CCU_GATE(CP110_GATE_COMM_UNIT, "cp110-gate-comm_unit", 1)
104*73450c4aSEmmanuel Vadot 	/* CCU_GATE(CP110_GATE_NAND, "cp110-gate-nand", 2) */
105*73450c4aSEmmanuel Vadot 	CCU_GATE(CP110_GATE_PPV2, "cp110-gate-ppv2", 3)
106*73450c4aSEmmanuel Vadot 	CCU_GATE(CP110_GATE_SDIO, "cp110-gate-sdio", 4)
107*73450c4aSEmmanuel Vadot 	CCU_GATE(CP110_GATE_MG, "cp110-gate-mg", 5)
108*73450c4aSEmmanuel Vadot 	CCU_GATE(CP110_GATE_MG_CORE, "cp110-gate-mg_core", 6)
109*73450c4aSEmmanuel Vadot 	CCU_GATE(CP110_GATE_XOR1, "cp110-gate-xor1", 7)
110*73450c4aSEmmanuel Vadot 	CCU_GATE(CP110_GATE_XOR0, "cp110-gate-xor0", 8)
111*73450c4aSEmmanuel Vadot 	CCU_GATE(CP110_GATE_GOP_DP, "cp110-gate-gop_dp", 9)
112*73450c4aSEmmanuel Vadot 	CCU_GATE(CP110_GATE_PCIE_X1_0, "cp110-gate-pcie_x10", 11)
113*73450c4aSEmmanuel Vadot 	CCU_GATE(CP110_GATE_PCIE_X1_1, "cp110-gate-pcie_x11", 12)
114*73450c4aSEmmanuel Vadot 	CCU_GATE(CP110_GATE_PCIE_X4, "cp110-gate-pcie_x4", 13)
115*73450c4aSEmmanuel Vadot 	CCU_GATE(CP110_GATE_PCIE_XOR, "cp110-gate-pcie_xor", 14)
116*73450c4aSEmmanuel Vadot 	CCU_GATE(CP110_GATE_SATA, "cp110-gate-sata", 15)
117*73450c4aSEmmanuel Vadot 	CCU_GATE(CP110_GATE_SATA_USB, "cp110-gate-sata_usb", 16)
118*73450c4aSEmmanuel Vadot 	CCU_GATE(CP110_GATE_MAIN, "cp110-gate-main", 17)
119*73450c4aSEmmanuel Vadot 	CCU_GATE(CP110_GATE_SDMMC_GOP, "cp110-gate-sdmmc_gop", 18)
120*73450c4aSEmmanuel Vadot 	CCU_GATE(CP110_GATE_SLOW_IO, "cp110-gate-slow_io", 21)
121*73450c4aSEmmanuel Vadot 	CCU_GATE(CP110_GATE_USB3H0, "cp110-gate-usb3h0", 22)
122*73450c4aSEmmanuel Vadot 	CCU_GATE(CP110_GATE_USB3H1, "cp110-gate-usb3h1", 23)
123*73450c4aSEmmanuel Vadot 	CCU_GATE(CP110_GATE_USB3DEV, "cp110-gate-usb3dev", 24)
124*73450c4aSEmmanuel Vadot 	CCU_GATE(CP110_GATE_EIP150, "cp110-gate-eip150", 25)
125*73450c4aSEmmanuel Vadot 	CCU_GATE(CP110_GATE_EIP197, "cp110-gate-eip197", 26)
126*73450c4aSEmmanuel Vadot };
127*73450c4aSEmmanuel Vadot 
128*73450c4aSEmmanuel Vadot struct mv_cp110_clock_softc {
129*73450c4aSEmmanuel Vadot 	struct simplebus_softc	simplebus_sc;
130*73450c4aSEmmanuel Vadot 	device_t		dev;
131*73450c4aSEmmanuel Vadot 	struct resource		*res;
132*73450c4aSEmmanuel Vadot 	struct mtx		mtx;
133*73450c4aSEmmanuel Vadot };
134*73450c4aSEmmanuel Vadot 
135*73450c4aSEmmanuel Vadot static struct resource_spec mv_cp110_clock_res_spec[] = {
136*73450c4aSEmmanuel Vadot 	{ SYS_RES_MEMORY,	0,	RF_ACTIVE | RF_SHAREABLE },
137*73450c4aSEmmanuel Vadot 	{ -1, 0 }
138*73450c4aSEmmanuel Vadot };
139*73450c4aSEmmanuel Vadot 
140*73450c4aSEmmanuel Vadot static struct ofw_compat_data compat_data[] = {
141*73450c4aSEmmanuel Vadot 	{"marvell,cp110-clock", 1},
142*73450c4aSEmmanuel Vadot 	{NULL,             0}
143*73450c4aSEmmanuel Vadot };
144*73450c4aSEmmanuel Vadot 
145*73450c4aSEmmanuel Vadot #define	RD4(sc, reg)		bus_read_4((sc)->res, (reg))
146*73450c4aSEmmanuel Vadot #define	WR4(sc, reg, val)	bus_write_4((sc)->res, (reg), (val))
147*73450c4aSEmmanuel Vadot 
148*73450c4aSEmmanuel Vadot static char *
149*73450c4aSEmmanuel Vadot mv_cp110_clock_name(device_t dev, const char *name)
150*73450c4aSEmmanuel Vadot {
151*73450c4aSEmmanuel Vadot 	char *clkname = NULL;
152*73450c4aSEmmanuel Vadot 	int unit;
153*73450c4aSEmmanuel Vadot 
154*73450c4aSEmmanuel Vadot 	unit = device_get_unit(dev);
155*73450c4aSEmmanuel Vadot 	if (asprintf(&clkname, M_DEVBUF, "%s-%d", name, unit) <= 0)
156*73450c4aSEmmanuel Vadot 		panic("Cannot generate unique clock name for %s\n", name);
157*73450c4aSEmmanuel Vadot 	return (clkname);
158*73450c4aSEmmanuel Vadot }
159*73450c4aSEmmanuel Vadot 
160*73450c4aSEmmanuel Vadot static int
161*73450c4aSEmmanuel Vadot mv_cp110_clock_probe(device_t dev)
162*73450c4aSEmmanuel Vadot {
163*73450c4aSEmmanuel Vadot 
164*73450c4aSEmmanuel Vadot 	if (!ofw_bus_status_okay(dev))
165*73450c4aSEmmanuel Vadot 		return (ENXIO);
166*73450c4aSEmmanuel Vadot 
167*73450c4aSEmmanuel Vadot 	if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0)
168*73450c4aSEmmanuel Vadot 		return (ENXIO);
169*73450c4aSEmmanuel Vadot 
170*73450c4aSEmmanuel Vadot 	device_set_desc(dev, "Marvell CP110 Clock Controller");
171*73450c4aSEmmanuel Vadot 	return (BUS_PROBE_DEFAULT);
172*73450c4aSEmmanuel Vadot }
173*73450c4aSEmmanuel Vadot 
174*73450c4aSEmmanuel Vadot static int
175*73450c4aSEmmanuel Vadot cp110_ofw_map(struct clkdom *clkdom, uint32_t ncells,
176*73450c4aSEmmanuel Vadot     phandle_t *cells, struct clknode **clk)
177*73450c4aSEmmanuel Vadot {
178*73450c4aSEmmanuel Vadot 	int id = 0;
179*73450c4aSEmmanuel Vadot 
180*73450c4aSEmmanuel Vadot 	if (ncells != 2)
181*73450c4aSEmmanuel Vadot 		return (ENXIO);
182*73450c4aSEmmanuel Vadot 
183*73450c4aSEmmanuel Vadot 	id = cells[1];
184*73450c4aSEmmanuel Vadot 	if (cells[0] == 1)
185*73450c4aSEmmanuel Vadot 		id += CP110_MAX_CLOCK;
186*73450c4aSEmmanuel Vadot 
187*73450c4aSEmmanuel Vadot 	*clk = clknode_find_by_id(clkdom, id);
188*73450c4aSEmmanuel Vadot 
189*73450c4aSEmmanuel Vadot 	return (0);
190*73450c4aSEmmanuel Vadot }
191*73450c4aSEmmanuel Vadot 
192*73450c4aSEmmanuel Vadot static int
193*73450c4aSEmmanuel Vadot mv_cp110_clock_attach(device_t dev)
194*73450c4aSEmmanuel Vadot {
195*73450c4aSEmmanuel Vadot 	struct mv_cp110_clock_softc *sc;
196*73450c4aSEmmanuel Vadot 	struct clkdom *clkdom;
197*73450c4aSEmmanuel Vadot 	struct clk_gate_def def;
198*73450c4aSEmmanuel Vadot 	char *pll0_name;
199*73450c4aSEmmanuel Vadot 	int unit, i;
200*73450c4aSEmmanuel Vadot 
201*73450c4aSEmmanuel Vadot 	sc = device_get_softc(dev);
202*73450c4aSEmmanuel Vadot 	sc->dev = dev;
203*73450c4aSEmmanuel Vadot 
204*73450c4aSEmmanuel Vadot 	if (bus_alloc_resources(dev, mv_cp110_clock_res_spec, &sc->res) != 0) {
205*73450c4aSEmmanuel Vadot 		device_printf(dev, "cannot allocate resources for device\n");
206*73450c4aSEmmanuel Vadot 		return (ENXIO);
207*73450c4aSEmmanuel Vadot 	}
208*73450c4aSEmmanuel Vadot 
209*73450c4aSEmmanuel Vadot 	unit = device_get_unit(dev);
210*73450c4aSEmmanuel Vadot 	if (unit > 1) {
211*73450c4aSEmmanuel Vadot 		device_printf(dev, "Bogus cp110-system-controller unit %d\n", unit);
212*73450c4aSEmmanuel Vadot 		return (ENXIO);
213*73450c4aSEmmanuel Vadot 	}
214*73450c4aSEmmanuel Vadot 
215*73450c4aSEmmanuel Vadot 	mtx_init(&sc->mtx, device_get_nameunit(dev), NULL, MTX_DEF);
216*73450c4aSEmmanuel Vadot 
217*73450c4aSEmmanuel Vadot 	clkdom = clkdom_create(dev);
218*73450c4aSEmmanuel Vadot 	clkdom_set_ofw_mapper(clkdom, cp110_ofw_map);
219*73450c4aSEmmanuel Vadot 
220*73450c4aSEmmanuel Vadot 	pll0_name = mv_cp110_clock_name(dev, "cp110-pll0");
221*73450c4aSEmmanuel Vadot 	cp110_clk_pll_0.clkdef.name = pll0_name;
222*73450c4aSEmmanuel Vadot 	clknode_fixed_register(clkdom, &cp110_clk_pll_0);
223*73450c4aSEmmanuel Vadot 
224*73450c4aSEmmanuel Vadot 	cp110_clk_ppv2_core.clkdef.name = mv_cp110_clock_name(dev, "cp110-ppv2");
225*73450c4aSEmmanuel Vadot 	cp110_clk_ppv2_core.clkdef.parent_names = (unit == 0) ? clk_parents_0 : clk_parents_1;
226*73450c4aSEmmanuel Vadot 	clknode_fixed_register(clkdom, &cp110_clk_ppv2_core);
227*73450c4aSEmmanuel Vadot 
228*73450c4aSEmmanuel Vadot 	cp110_clk_x2core.clkdef.name = mv_cp110_clock_name(dev, "cp110-x2core");
229*73450c4aSEmmanuel Vadot 	cp110_clk_x2core.clkdef.parent_names = (unit == 0) ? clk_parents_0 : clk_parents_1;
230*73450c4aSEmmanuel Vadot 	clknode_fixed_register(clkdom, &cp110_clk_x2core);
231*73450c4aSEmmanuel Vadot 
232*73450c4aSEmmanuel Vadot 	cp110_clk_core.clkdef.name = mv_cp110_clock_name(dev, "cp110-core");
233*73450c4aSEmmanuel Vadot 	cp110_clk_core.clkdef.parent_names = (unit == 0) ? core_parents_0 : core_parents_1;
234*73450c4aSEmmanuel Vadot 	clknode_fixed_register(clkdom, &cp110_clk_core);
235*73450c4aSEmmanuel Vadot 
236*73450c4aSEmmanuel Vadot 	/* NAND missing */
237*73450c4aSEmmanuel Vadot 
238*73450c4aSEmmanuel Vadot 	cp110_clk_sdio.clkdef.name = mv_cp110_clock_name(dev, "cp110-sdio");
239*73450c4aSEmmanuel Vadot 	cp110_clk_sdio.clkdef.parent_names = (unit == 0) ? clk_parents_0 : clk_parents_1;
240*73450c4aSEmmanuel Vadot 	clknode_fixed_register(clkdom, &cp110_clk_sdio);
241*73450c4aSEmmanuel Vadot 
242*73450c4aSEmmanuel Vadot 	for (i = 0; i < nitems(cp110_gates); i++) {
243*73450c4aSEmmanuel Vadot 		if (cp110_gates[i].name == NULL)
244*73450c4aSEmmanuel Vadot 			continue;
245*73450c4aSEmmanuel Vadot 
246*73450c4aSEmmanuel Vadot 		memset(&def, 0, sizeof(def));
247*73450c4aSEmmanuel Vadot 		def.clkdef.id = CP110_MAX_CLOCK + i;
248*73450c4aSEmmanuel Vadot 		def.clkdef.name = mv_cp110_clock_name(dev, cp110_gates[i].name);
249*73450c4aSEmmanuel Vadot 		def.clkdef.parent_cnt = 1;
250*73450c4aSEmmanuel Vadot 		def.offset = CP110_CLOCK_GATING_OFFSET;
251*73450c4aSEmmanuel Vadot 		def.shift = cp110_gates[i].shift;
252*73450c4aSEmmanuel Vadot 		def.mask = 1;
253*73450c4aSEmmanuel Vadot 		def.on_value = 1;
254*73450c4aSEmmanuel Vadot 		def.off_value = 0;
255*73450c4aSEmmanuel Vadot 
256*73450c4aSEmmanuel Vadot 		switch (i) {
257*73450c4aSEmmanuel Vadot 		case CP110_GATE_MG:
258*73450c4aSEmmanuel Vadot 		case CP110_GATE_GOP_DP:
259*73450c4aSEmmanuel Vadot 		case CP110_GATE_PPV2:
260*73450c4aSEmmanuel Vadot 			def.clkdef.parent_names = &cp110_clk_ppv2_core.clkdef.name;
261*73450c4aSEmmanuel Vadot 			break;
262*73450c4aSEmmanuel Vadot 		case CP110_GATE_SDIO:
263*73450c4aSEmmanuel Vadot 			def.clkdef.parent_names = &cp110_clk_sdio.clkdef.name;
264*73450c4aSEmmanuel Vadot 			break;
265*73450c4aSEmmanuel Vadot 		case CP110_GATE_MAIN:
266*73450c4aSEmmanuel Vadot 		case CP110_GATE_PCIE_XOR:
267*73450c4aSEmmanuel Vadot 		case CP110_GATE_PCIE_X4:
268*73450c4aSEmmanuel Vadot 		case CP110_GATE_EIP150:
269*73450c4aSEmmanuel Vadot 		case CP110_GATE_EIP197:
270*73450c4aSEmmanuel Vadot 			def.clkdef.parent_names = &cp110_clk_x2core.clkdef.name;
271*73450c4aSEmmanuel Vadot 			break;
272*73450c4aSEmmanuel Vadot 		default:
273*73450c4aSEmmanuel Vadot 			def.clkdef.parent_names = &cp110_clk_core.clkdef.name;
274*73450c4aSEmmanuel Vadot 			break;
275*73450c4aSEmmanuel Vadot 		}
276*73450c4aSEmmanuel Vadot 
277*73450c4aSEmmanuel Vadot 		clknode_gate_register(clkdom, &def);
278*73450c4aSEmmanuel Vadot 	}
279*73450c4aSEmmanuel Vadot 
280*73450c4aSEmmanuel Vadot 	clkdom_finit(clkdom);
281*73450c4aSEmmanuel Vadot 
282*73450c4aSEmmanuel Vadot 	if (bootverbose)
283*73450c4aSEmmanuel Vadot 		clkdom_dump(clkdom);
284*73450c4aSEmmanuel Vadot 
285*73450c4aSEmmanuel Vadot 	return (0);
286*73450c4aSEmmanuel Vadot }
287*73450c4aSEmmanuel Vadot 
288*73450c4aSEmmanuel Vadot static int
289*73450c4aSEmmanuel Vadot mv_cp110_clock_detach(device_t dev)
290*73450c4aSEmmanuel Vadot {
291*73450c4aSEmmanuel Vadot 
292*73450c4aSEmmanuel Vadot 	return (EBUSY);
293*73450c4aSEmmanuel Vadot }
294*73450c4aSEmmanuel Vadot 
295*73450c4aSEmmanuel Vadot static int
296*73450c4aSEmmanuel Vadot mv_cp110_clock_write_4(device_t dev, bus_addr_t addr, uint32_t val)
297*73450c4aSEmmanuel Vadot {
298*73450c4aSEmmanuel Vadot 	struct mv_cp110_clock_softc *sc;
299*73450c4aSEmmanuel Vadot 
300*73450c4aSEmmanuel Vadot 	sc = device_get_softc(dev);
301*73450c4aSEmmanuel Vadot 	WR4(sc, addr, val);
302*73450c4aSEmmanuel Vadot 	return (0);
303*73450c4aSEmmanuel Vadot }
304*73450c4aSEmmanuel Vadot 
305*73450c4aSEmmanuel Vadot static int
306*73450c4aSEmmanuel Vadot mv_cp110_clock_read_4(device_t dev, bus_addr_t addr, uint32_t *val)
307*73450c4aSEmmanuel Vadot {
308*73450c4aSEmmanuel Vadot 	struct mv_cp110_clock_softc *sc;
309*73450c4aSEmmanuel Vadot 
310*73450c4aSEmmanuel Vadot 	sc = device_get_softc(dev);
311*73450c4aSEmmanuel Vadot 
312*73450c4aSEmmanuel Vadot 	*val = RD4(sc, addr);
313*73450c4aSEmmanuel Vadot 	return (0);
314*73450c4aSEmmanuel Vadot }
315*73450c4aSEmmanuel Vadot 
316*73450c4aSEmmanuel Vadot static int
317*73450c4aSEmmanuel Vadot mv_cp110_clock_modify_4(device_t dev, bus_addr_t addr, uint32_t clr, uint32_t set)
318*73450c4aSEmmanuel Vadot {
319*73450c4aSEmmanuel Vadot 	struct mv_cp110_clock_softc *sc;
320*73450c4aSEmmanuel Vadot 	uint32_t reg;
321*73450c4aSEmmanuel Vadot 
322*73450c4aSEmmanuel Vadot 	sc = device_get_softc(dev);
323*73450c4aSEmmanuel Vadot 
324*73450c4aSEmmanuel Vadot 	reg = RD4(sc, addr);
325*73450c4aSEmmanuel Vadot 	reg &= ~clr;
326*73450c4aSEmmanuel Vadot 	reg |= set;
327*73450c4aSEmmanuel Vadot 	WR4(sc, addr, reg);
328*73450c4aSEmmanuel Vadot 
329*73450c4aSEmmanuel Vadot 	return (0);
330*73450c4aSEmmanuel Vadot }
331*73450c4aSEmmanuel Vadot 
332*73450c4aSEmmanuel Vadot static void
333*73450c4aSEmmanuel Vadot mv_cp110_clock_device_lock(device_t dev)
334*73450c4aSEmmanuel Vadot {
335*73450c4aSEmmanuel Vadot 	struct mv_cp110_clock_softc *sc;
336*73450c4aSEmmanuel Vadot 
337*73450c4aSEmmanuel Vadot 	sc = device_get_softc(dev);
338*73450c4aSEmmanuel Vadot 	mtx_lock(&sc->mtx);
339*73450c4aSEmmanuel Vadot }
340*73450c4aSEmmanuel Vadot 
341*73450c4aSEmmanuel Vadot static void
342*73450c4aSEmmanuel Vadot mv_cp110_clock_device_unlock(device_t dev)
343*73450c4aSEmmanuel Vadot {
344*73450c4aSEmmanuel Vadot 	struct mv_cp110_clock_softc *sc;
345*73450c4aSEmmanuel Vadot 
346*73450c4aSEmmanuel Vadot 	sc = device_get_softc(dev);
347*73450c4aSEmmanuel Vadot 	mtx_unlock(&sc->mtx);
348*73450c4aSEmmanuel Vadot }
349*73450c4aSEmmanuel Vadot 
350*73450c4aSEmmanuel Vadot static device_method_t mv_cp110_clock_methods[] = {
351*73450c4aSEmmanuel Vadot 	/* Device interface */
352*73450c4aSEmmanuel Vadot 	DEVMETHOD(device_probe,		mv_cp110_clock_probe),
353*73450c4aSEmmanuel Vadot 	DEVMETHOD(device_attach,	mv_cp110_clock_attach),
354*73450c4aSEmmanuel Vadot 	DEVMETHOD(device_detach,	mv_cp110_clock_detach),
355*73450c4aSEmmanuel Vadot 
356*73450c4aSEmmanuel Vadot 	/* clkdev interface */
357*73450c4aSEmmanuel Vadot 	DEVMETHOD(clkdev_write_4,	mv_cp110_clock_write_4),
358*73450c4aSEmmanuel Vadot 	DEVMETHOD(clkdev_read_4,	mv_cp110_clock_read_4),
359*73450c4aSEmmanuel Vadot 	DEVMETHOD(clkdev_modify_4,	mv_cp110_clock_modify_4),
360*73450c4aSEmmanuel Vadot 	DEVMETHOD(clkdev_device_lock,	mv_cp110_clock_device_lock),
361*73450c4aSEmmanuel Vadot 	DEVMETHOD(clkdev_device_unlock,	mv_cp110_clock_device_unlock),
362*73450c4aSEmmanuel Vadot 
363*73450c4aSEmmanuel Vadot 	DEVMETHOD_END
364*73450c4aSEmmanuel Vadot };
365*73450c4aSEmmanuel Vadot 
366*73450c4aSEmmanuel Vadot static devclass_t mv_cp110_clock_devclass;
367*73450c4aSEmmanuel Vadot 
368*73450c4aSEmmanuel Vadot static driver_t mv_cp110_clock_driver = {
369*73450c4aSEmmanuel Vadot 	"mv_cp110_clock",
370*73450c4aSEmmanuel Vadot 	mv_cp110_clock_methods,
371*73450c4aSEmmanuel Vadot 	sizeof(struct mv_cp110_clock_softc),
372*73450c4aSEmmanuel Vadot };
373*73450c4aSEmmanuel Vadot 
374*73450c4aSEmmanuel Vadot EARLY_DRIVER_MODULE(mv_cp110_clock, simplebus, mv_cp110_clock_driver,
375*73450c4aSEmmanuel Vadot     mv_cp110_clock_devclass, 0, 0, BUS_PASS_RESOURCE + BUS_PASS_ORDER_LATE);
376