xref: /freebsd/sys/powerpc/powermac/uninorth.c (revision bfed756af67e4b84d61b4b8af4d0a103ddd6f628)
160727d8bSWarner Losh /*-
271e3c308SPedro F. Giffuni  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
371e3c308SPedro F. Giffuni  *
498f8e6c0SBenno Rice  * Copyright (C) 2002 Benno Rice.
598f8e6c0SBenno Rice  * All rights reserved.
698f8e6c0SBenno Rice  *
798f8e6c0SBenno Rice  * Redistribution and use in source and binary forms, with or without
898f8e6c0SBenno Rice  * modification, are permitted provided that the following conditions
998f8e6c0SBenno Rice  * are met:
1098f8e6c0SBenno Rice  * 1. Redistributions of source code must retain the above copyright
1198f8e6c0SBenno Rice  *    notice, this list of conditions and the following disclaimer.
1298f8e6c0SBenno Rice  * 2. Redistributions in binary form must reproduce the above copyright
1398f8e6c0SBenno Rice  *    notice, this list of conditions and the following disclaimer in the
1498f8e6c0SBenno Rice  *    documentation and/or other materials provided with the distribution.
1598f8e6c0SBenno Rice  *
1698f8e6c0SBenno Rice  * THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND ANY EXPRESS OR
1798f8e6c0SBenno Rice  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1898f8e6c0SBenno Rice  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1998f8e6c0SBenno Rice  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2098f8e6c0SBenno Rice  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2198f8e6c0SBenno Rice  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
2298f8e6c0SBenno Rice  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
2398f8e6c0SBenno Rice  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
2498f8e6c0SBenno Rice  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
2598f8e6c0SBenno Rice  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2698f8e6c0SBenno Rice  *
2798f8e6c0SBenno Rice  * $FreeBSD$
2898f8e6c0SBenno Rice  */
2998f8e6c0SBenno Rice 
3098f8e6c0SBenno Rice #include <sys/param.h>
3198f8e6c0SBenno Rice #include <sys/systm.h>
3240cdee9dSPeter Grehan #include <sys/module.h>
3398f8e6c0SBenno Rice #include <sys/bus.h>
3498f8e6c0SBenno Rice #include <sys/conf.h>
3598f8e6c0SBenno Rice #include <sys/kernel.h>
3698f8e6c0SBenno Rice 
3798f8e6c0SBenno Rice #include <dev/ofw/openfirm.h>
3898f8e6c0SBenno Rice #include <dev/ofw/ofw_pci.h>
3951d163d3SNathan Whitehorn #include <dev/ofw/ofw_bus.h>
4094b4a038SNathan Whitehorn #include <dev/ofw/ofw_bus_subr.h>
4198f8e6c0SBenno Rice 
4298f8e6c0SBenno Rice #include <dev/pci/pcivar.h>
4398f8e6c0SBenno Rice #include <dev/pci/pcireg.h>
4498f8e6c0SBenno Rice 
4598f8e6c0SBenno Rice #include <machine/bus.h>
46ca2c1931SNathan Whitehorn #include <machine/intr_machdep.h>
4798f8e6c0SBenno Rice #include <machine/md_var.h>
48de2fa7b8SMarcel Moolenaar #include <machine/pio.h>
4998f8e6c0SBenno Rice #include <machine/resource.h>
5098f8e6c0SBenno Rice 
5198f8e6c0SBenno Rice #include <sys/rman.h>
5298f8e6c0SBenno Rice 
5398f8e6c0SBenno Rice #include <powerpc/powermac/uninorthvar.h>
5498f8e6c0SBenno Rice 
5598f8e6c0SBenno Rice #include <vm/vm.h>
5698f8e6c0SBenno Rice #include <vm/pmap.h>
5798f8e6c0SBenno Rice 
58ca2c1931SNathan Whitehorn /*
59ca2c1931SNathan Whitehorn  * Driver for the Uninorth chip itself.
60ca2c1931SNathan Whitehorn  */
6198f8e6c0SBenno Rice 
62ca2c1931SNathan Whitehorn static MALLOC_DEFINE(M_UNIN, "unin", "unin device information");
6398f8e6c0SBenno Rice 
6498f8e6c0SBenno Rice /*
6598f8e6c0SBenno Rice  * Device interface.
6698f8e6c0SBenno Rice  */
67ca2c1931SNathan Whitehorn 
68ca2c1931SNathan Whitehorn static int  unin_chip_probe(device_t);
69ca2c1931SNathan Whitehorn static int  unin_chip_attach(device_t);
7098f8e6c0SBenno Rice 
7198f8e6c0SBenno Rice /*
7298f8e6c0SBenno Rice  * Bus interface.
7398f8e6c0SBenno Rice  */
74ca2c1931SNathan Whitehorn static int  unin_chip_print_child(device_t dev, device_t child);
75ca2c1931SNathan Whitehorn static void unin_chip_probe_nomatch(device_t, device_t);
76ca2c1931SNathan Whitehorn static struct resource *unin_chip_alloc_resource(device_t, device_t, int, int *,
772dd1bdf1SJustin Hibbits 						 rman_res_t, rman_res_t,
782dd1bdf1SJustin Hibbits 						 rman_res_t, u_int);
79ca2c1931SNathan Whitehorn static int  unin_chip_activate_resource(device_t, device_t, int, int,
80ca2c1931SNathan Whitehorn 					struct resource *);
81ca2c1931SNathan Whitehorn static int  unin_chip_deactivate_resource(device_t, device_t, int, int,
82ca2c1931SNathan Whitehorn 					  struct resource *);
83ca2c1931SNathan Whitehorn static int  unin_chip_release_resource(device_t, device_t, int, int,
84ca2c1931SNathan Whitehorn 				       struct resource *);
85ca2c1931SNathan Whitehorn static struct resource_list *unin_chip_get_resource_list (device_t, device_t);
8698f8e6c0SBenno Rice 
8798f8e6c0SBenno Rice /*
8851d163d3SNathan Whitehorn  * OFW Bus interface
8951d163d3SNathan Whitehorn  */
9051d163d3SNathan Whitehorn 
91ca2c1931SNathan Whitehorn static ofw_bus_get_devinfo_t unin_chip_get_devinfo;
9251d163d3SNathan Whitehorn 
9351d163d3SNathan Whitehorn /*
94ca2c1931SNathan Whitehorn  * Local routines
9598f8e6c0SBenno Rice  */
96ca2c1931SNathan Whitehorn 
97ca2c1931SNathan Whitehorn static void		unin_enable_gmac(device_t dev);
98ca2c1931SNathan Whitehorn static void		unin_enable_mpic(device_t dev);
9998f8e6c0SBenno Rice 
10098f8e6c0SBenno Rice /*
10198f8e6c0SBenno Rice  * Driver methods.
10298f8e6c0SBenno Rice  */
103ca2c1931SNathan Whitehorn static device_method_t unin_chip_methods[] = {
104ca2c1931SNathan Whitehorn 
10598f8e6c0SBenno Rice 	/* Device interface */
106ca2c1931SNathan Whitehorn 	DEVMETHOD(device_probe,         unin_chip_probe),
107ca2c1931SNathan Whitehorn 	DEVMETHOD(device_attach,        unin_chip_attach),
10898f8e6c0SBenno Rice 
10998f8e6c0SBenno Rice 	/* Bus interface */
110ca2c1931SNathan Whitehorn 	DEVMETHOD(bus_print_child,      unin_chip_print_child),
111ca2c1931SNathan Whitehorn 	DEVMETHOD(bus_probe_nomatch,    unin_chip_probe_nomatch),
11298f8e6c0SBenno Rice 	DEVMETHOD(bus_setup_intr,       bus_generic_setup_intr),
11398f8e6c0SBenno Rice 	DEVMETHOD(bus_teardown_intr,    bus_generic_teardown_intr),
11498f8e6c0SBenno Rice 
115ca2c1931SNathan Whitehorn 	DEVMETHOD(bus_alloc_resource,   unin_chip_alloc_resource),
116ca2c1931SNathan Whitehorn 	DEVMETHOD(bus_release_resource, unin_chip_release_resource),
117ca2c1931SNathan Whitehorn 	DEVMETHOD(bus_activate_resource, unin_chip_activate_resource),
118ca2c1931SNathan Whitehorn 	DEVMETHOD(bus_deactivate_resource, unin_chip_deactivate_resource),
119ca2c1931SNathan Whitehorn 	DEVMETHOD(bus_get_resource_list, unin_chip_get_resource_list),
12098f8e6c0SBenno Rice 
1214fe8025dSNathan Whitehorn 	DEVMETHOD(bus_child_pnpinfo_str, ofw_bus_gen_child_pnpinfo_str),
1224fe8025dSNathan Whitehorn 
12351d163d3SNathan Whitehorn         /* ofw_bus interface */
124ca2c1931SNathan Whitehorn 	DEVMETHOD(ofw_bus_get_devinfo,	unin_chip_get_devinfo),
125ca2c1931SNathan Whitehorn 	DEVMETHOD(ofw_bus_get_compat,	ofw_bus_gen_get_compat),
126ca2c1931SNathan Whitehorn 	DEVMETHOD(ofw_bus_get_model,	ofw_bus_gen_get_model),
127ca2c1931SNathan Whitehorn 	DEVMETHOD(ofw_bus_get_name,	ofw_bus_gen_get_name),
128ca2c1931SNathan Whitehorn 	DEVMETHOD(ofw_bus_get_node,	ofw_bus_gen_get_node),
129ca2c1931SNathan Whitehorn 	DEVMETHOD(ofw_bus_get_type,	ofw_bus_gen_get_type),
13051d163d3SNathan Whitehorn 
13198f8e6c0SBenno Rice 	{ 0, 0 }
13298f8e6c0SBenno Rice };
13398f8e6c0SBenno Rice 
134ca2c1931SNathan Whitehorn static driver_t	unin_chip_driver = {
135ca2c1931SNathan Whitehorn 	"unin",
136ca2c1931SNathan Whitehorn 	unin_chip_methods,
137ca2c1931SNathan Whitehorn 	sizeof(struct unin_chip_softc)
13898f8e6c0SBenno Rice };
13998f8e6c0SBenno Rice 
140ca2c1931SNathan Whitehorn static devclass_t	unin_chip_devclass;
14198f8e6c0SBenno Rice 
1424702d987SJustin Hibbits /*
1434702d987SJustin Hibbits  * Assume there is only one unin chip in a PowerMac, so that pmu.c functions can
1444702d987SJustin Hibbits  * suspend the chip after the whole rest of the device tree is suspended, not
1454702d987SJustin Hibbits  * earlier.
1464702d987SJustin Hibbits  */
1474702d987SJustin Hibbits static device_t		unin_chip;
1484702d987SJustin Hibbits 
149*bfed756aSJustin Hibbits EARLY_DRIVER_MODULE(unin, ofwbus, unin_chip_driver, unin_chip_devclass, 0, 0,
150*bfed756aSJustin Hibbits     BUS_PASS_BUS);
15198f8e6c0SBenno Rice 
15251d163d3SNathan Whitehorn /*
153ca2c1931SNathan Whitehorn  * Add an interrupt to the dev's resource list if present
15451d163d3SNathan Whitehorn  */
155ca2c1931SNathan Whitehorn static void
156ca2c1931SNathan Whitehorn unin_chip_add_intr(phandle_t devnode, struct unin_chip_devinfo *dinfo)
157ca2c1931SNathan Whitehorn {
158eaef5f0aSNathan Whitehorn 	phandle_t iparent;
159ca2c1931SNathan Whitehorn 	int	*intr;
160ca2c1931SNathan Whitehorn 	int	i, nintr;
161ca2c1931SNathan Whitehorn 	int 	icells;
16251d163d3SNathan Whitehorn 
163ca2c1931SNathan Whitehorn 	if (dinfo->udi_ninterrupts >= 6) {
164ca2c1931SNathan Whitehorn 		printf("unin: device has more than 6 interrupts\n");
165ca2c1931SNathan Whitehorn 		return;
16651d163d3SNathan Whitehorn 	}
16798f8e6c0SBenno Rice 
168217d17bcSOleksandr Tymoshenko 	nintr = OF_getprop_alloc_multi(devnode, "interrupts", sizeof(*intr),
169ca2c1931SNathan Whitehorn 		(void **)&intr);
170ca2c1931SNathan Whitehorn 	if (nintr == -1) {
171217d17bcSOleksandr Tymoshenko 		nintr = OF_getprop_alloc_multi(devnode, "AAPL,interrupts",
172ca2c1931SNathan Whitehorn 			sizeof(*intr), (void **)&intr);
173ca2c1931SNathan Whitehorn 		if (nintr == -1)
174ca2c1931SNathan Whitehorn 			return;
175ca2c1931SNathan Whitehorn 	}
176ca2c1931SNathan Whitehorn 
177ca2c1931SNathan Whitehorn 	if (intr[0] == -1)
178ca2c1931SNathan Whitehorn 		return;
179ca2c1931SNathan Whitehorn 
180ca2c1931SNathan Whitehorn 	if (OF_getprop(devnode, "interrupt-parent", &iparent, sizeof(iparent))
181ca2c1931SNathan Whitehorn 	    <= 0)
182ca2c1931SNathan Whitehorn 		panic("Interrupt but no interrupt parent!\n");
183ca2c1931SNathan Whitehorn 
184ca2c1931SNathan Whitehorn 	if (OF_searchprop(iparent, "#interrupt-cells", &icells, sizeof(icells))
185ca2c1931SNathan Whitehorn 	    <= 0)
186ca2c1931SNathan Whitehorn 		icells = 1;
187ca2c1931SNathan Whitehorn 
188ca2c1931SNathan Whitehorn 	for (i = 0; i < nintr; i+=icells) {
189607ebaafSMarcel Moolenaar 		u_int irq = MAP_IRQ(iparent, intr[i]);
190607ebaafSMarcel Moolenaar 
191ca2c1931SNathan Whitehorn 		resource_list_add(&dinfo->udi_resources, SYS_RES_IRQ,
192607ebaafSMarcel Moolenaar 		    dinfo->udi_ninterrupts, irq, irq, 1);
193ca2c1931SNathan Whitehorn 
194eaef5f0aSNathan Whitehorn 		if (icells > 1) {
195607ebaafSMarcel Moolenaar 			powerpc_config_intr(irq,
196eaef5f0aSNathan Whitehorn 			    (intr[i+1] & 1) ? INTR_TRIGGER_LEVEL :
197a7a32004SNathan Whitehorn 			    INTR_TRIGGER_EDGE, INTR_POLARITY_LOW);
198eaef5f0aSNathan Whitehorn 		}
199eaef5f0aSNathan Whitehorn 
200607ebaafSMarcel Moolenaar 		dinfo->udi_interrupts[dinfo->udi_ninterrupts] = irq;
201ca2c1931SNathan Whitehorn 		dinfo->udi_ninterrupts++;
202ca2c1931SNathan Whitehorn 	}
203ca2c1931SNathan Whitehorn }
204ca2c1931SNathan Whitehorn 
205ca2c1931SNathan Whitehorn static void
206ca2c1931SNathan Whitehorn unin_chip_add_reg(phandle_t devnode, struct unin_chip_devinfo *dinfo)
207ca2c1931SNathan Whitehorn {
208ca2c1931SNathan Whitehorn 	struct	unin_chip_reg *reg;
209ca2c1931SNathan Whitehorn 	int	i, nreg;
210ca2c1931SNathan Whitehorn 
211217d17bcSOleksandr Tymoshenko 	nreg = OF_getprop_alloc_multi(devnode, "reg", sizeof(*reg), (void **)&reg);
212ca2c1931SNathan Whitehorn 	if (nreg == -1)
213ca2c1931SNathan Whitehorn 		return;
214ca2c1931SNathan Whitehorn 
215ca2c1931SNathan Whitehorn 	for (i = 0; i < nreg; i++) {
216ca2c1931SNathan Whitehorn 		resource_list_add(&dinfo->udi_resources, SYS_RES_MEMORY, i,
217ca2c1931SNathan Whitehorn 				  reg[i].mr_base,
218ca2c1931SNathan Whitehorn 				  reg[i].mr_base + reg[i].mr_size,
219ca2c1931SNathan Whitehorn 				  reg[i].mr_size);
220ca2c1931SNathan Whitehorn 	}
221ca2c1931SNathan Whitehorn }
222ca2c1931SNathan Whitehorn 
223ca2c1931SNathan Whitehorn static void
2244702d987SJustin Hibbits unin_update_reg(device_t dev, uint32_t regoff, uint32_t set, uint32_t clr)
225ca2c1931SNathan Whitehorn {
2264702d987SJustin Hibbits 	volatile u_int *reg;
227ca2c1931SNathan Whitehorn 	struct unin_chip_softc *sc;
228ca2c1931SNathan Whitehorn 	u_int32_t tmpl;
229ca2c1931SNathan Whitehorn 
230ca2c1931SNathan Whitehorn 	sc = device_get_softc(dev);
2314702d987SJustin Hibbits 	reg = (void *)(sc->sc_addr + regoff);
2324702d987SJustin Hibbits 	tmpl = inl(reg);
2334702d987SJustin Hibbits 	tmpl &= ~clr;
2344702d987SJustin Hibbits 	tmpl |= set;
2354702d987SJustin Hibbits 	outl(reg, tmpl);
2364702d987SJustin Hibbits }
2374702d987SJustin Hibbits 
2384702d987SJustin Hibbits static void
2394702d987SJustin Hibbits unin_enable_gmac(device_t dev)
2404702d987SJustin Hibbits {
2414702d987SJustin Hibbits 	unin_update_reg(dev, UNIN_CLOCKCNTL, UNIN_CLOCKCNTL_GMAC, 0);
242ca2c1931SNathan Whitehorn }
243ca2c1931SNathan Whitehorn 
244ca2c1931SNathan Whitehorn static void
245ca2c1931SNathan Whitehorn unin_enable_mpic(device_t dev)
246ca2c1931SNathan Whitehorn {
2474702d987SJustin Hibbits 	unin_update_reg(dev, UNIN_TOGGLE_REG, UNIN_MPIC_RESET | UNIN_MPIC_OUTPUT_ENABLE, 0);
248ca2c1931SNathan Whitehorn }
249ca2c1931SNathan Whitehorn 
250ca2c1931SNathan Whitehorn static int
251ca2c1931SNathan Whitehorn unin_chip_probe(device_t dev)
252ca2c1931SNathan Whitehorn {
253ca2c1931SNathan Whitehorn 	const char	*name;
254ca2c1931SNathan Whitehorn 
255ca2c1931SNathan Whitehorn 	name = ofw_bus_get_name(dev);
256ca2c1931SNathan Whitehorn 
257ca2c1931SNathan Whitehorn 	if (name == NULL)
25898f8e6c0SBenno Rice 		return (ENXIO);
25998f8e6c0SBenno Rice 
260ca2c1931SNathan Whitehorn 	if (strcmp(name, "uni-n") != 0 && strcmp(name, "u3") != 0
261ca2c1931SNathan Whitehorn 	    && strcmp(name, "u4") != 0)
26298f8e6c0SBenno Rice 		return (ENXIO);
263ca2c1931SNathan Whitehorn 
264ca2c1931SNathan Whitehorn 	device_set_desc(dev, "Apple UniNorth System Controller");
265ca2c1931SNathan Whitehorn 	return (0);
26698f8e6c0SBenno Rice }
26798f8e6c0SBenno Rice 
268ca2c1931SNathan Whitehorn static int
269ca2c1931SNathan Whitehorn unin_chip_attach(device_t dev)
270ca2c1931SNathan Whitehorn {
271ca2c1931SNathan Whitehorn 	struct unin_chip_softc *sc;
272ca2c1931SNathan Whitehorn 	struct unin_chip_devinfo *dinfo;
273ca2c1931SNathan Whitehorn 	phandle_t  root;
274ca2c1931SNathan Whitehorn 	phandle_t  child;
27543cbf1a6SAndreas Tobler 	phandle_t  iparent;
276ca2c1931SNathan Whitehorn 	device_t   cdev;
2774ee63553SNathan Whitehorn 	cell_t     acells, scells;
278ca2c1931SNathan Whitehorn 	char compat[32];
27943cbf1a6SAndreas Tobler 	char name[32];
28043cbf1a6SAndreas Tobler 	u_int irq, reg[3];
281ca2c1931SNathan Whitehorn 	int error, i = 0;
282ca2c1931SNathan Whitehorn 
283ca2c1931SNathan Whitehorn 	sc = device_get_softc(dev);
284ca2c1931SNathan Whitehorn 	root = ofw_bus_get_node(dev);
285ca2c1931SNathan Whitehorn 
286ca2c1931SNathan Whitehorn 	if (OF_getprop(root, "reg", reg, sizeof(reg)) < 8)
28798f8e6c0SBenno Rice 		return (ENXIO);
288ca2c1931SNathan Whitehorn 
2894ee63553SNathan Whitehorn 	acells = scells = 1;
2904ee63553SNathan Whitehorn 	OF_getprop(OF_parent(root), "#address-cells", &acells, sizeof(acells));
2914ee63553SNathan Whitehorn 	OF_getprop(OF_parent(root), "#size-cells", &scells, sizeof(scells));
292ca2c1931SNathan Whitehorn 
2934ee63553SNathan Whitehorn 	i = 0;
2944ee63553SNathan Whitehorn 	sc->sc_physaddr = reg[i++];
2954ee63553SNathan Whitehorn 	if (acells == 2) {
2964ee63553SNathan Whitehorn 		sc->sc_physaddr <<= 32;
2974ee63553SNathan Whitehorn 		sc->sc_physaddr |= reg[i++];
2984ee63553SNathan Whitehorn 	}
2994ee63553SNathan Whitehorn 	sc->sc_size = reg[i++];
3004ee63553SNathan Whitehorn 	if (scells == 2) {
3014ee63553SNathan Whitehorn 		sc->sc_size <<= 32;
3024ee63553SNathan Whitehorn 		sc->sc_size |= reg[i++];
3034ee63553SNathan Whitehorn 	}
304ca2c1931SNathan Whitehorn 
30598f8e6c0SBenno Rice 	sc->sc_mem_rman.rm_type = RMAN_ARRAY;
306ca2c1931SNathan Whitehorn 	sc->sc_mem_rman.rm_descr = "UniNorth Device Memory";
307ca2c1931SNathan Whitehorn 
308bda386dbSKevin Lo 	error = rman_init(&sc->sc_mem_rman);
309ca2c1931SNathan Whitehorn 
310bda386dbSKevin Lo 	if (error) {
311bda386dbSKevin Lo 		device_printf(dev, "rman_init() failed. error = %d\n", error);
312bda386dbSKevin Lo 		return (error);
31398f8e6c0SBenno Rice 	}
314ca2c1931SNathan Whitehorn 
315ca2c1931SNathan Whitehorn 	error = rman_manage_region(&sc->sc_mem_rman, sc->sc_physaddr,
316ca2c1931SNathan Whitehorn 				   sc->sc_physaddr + sc->sc_size - 1);
317bda386dbSKevin Lo 	if (error) {
31898f8e6c0SBenno Rice 		device_printf(dev,
319ca2c1931SNathan Whitehorn 			      "rman_manage_region() failed. error = %d\n",
320ca2c1931SNathan Whitehorn 			      error);
321bda386dbSKevin Lo 		return (error);
32298f8e6c0SBenno Rice 	}
32398f8e6c0SBenno Rice 
3244702d987SJustin Hibbits 	if (unin_chip == NULL)
3254702d987SJustin Hibbits 		unin_chip = dev;
3264702d987SJustin Hibbits 
327d48bbef3SPeter Grehan         /*
328ca2c1931SNathan Whitehorn 	 * Iterate through the sub-devices
329d48bbef3SPeter Grehan 	 */
330ca2c1931SNathan Whitehorn 	for (child = OF_child(root); child != 0; child = OF_peer(child)) {
331ca2c1931SNathan Whitehorn 		dinfo = malloc(sizeof(*dinfo), M_UNIN, M_WAITOK | M_ZERO);
332ca2c1931SNathan Whitehorn 		if (ofw_bus_gen_setup_devinfo(&dinfo->udi_obdinfo, child)
333ca2c1931SNathan Whitehorn 		    != 0)
334ca2c1931SNathan Whitehorn 		{
335ca2c1931SNathan Whitehorn 			free(dinfo, M_UNIN);
336ca2c1931SNathan Whitehorn 			continue;
337ca2c1931SNathan Whitehorn 		}
338d48bbef3SPeter Grehan 
339ca2c1931SNathan Whitehorn 		resource_list_init(&dinfo->udi_resources);
340ca2c1931SNathan Whitehorn 		dinfo->udi_ninterrupts = 0;
341ca2c1931SNathan Whitehorn 		unin_chip_add_intr(child, dinfo);
342ca2c1931SNathan Whitehorn 
34343cbf1a6SAndreas Tobler 		/*
34443cbf1a6SAndreas Tobler 		 * Some Apple machines do have a bug in OF, they miss
34543cbf1a6SAndreas Tobler 		 * the interrupt entries on the U3 I2C node. That means they
34643cbf1a6SAndreas Tobler 		 * do not have an entry with number of interrupts nor the
34743cbf1a6SAndreas Tobler 		 * entry of the interrupt parent handle.
34843cbf1a6SAndreas Tobler 		 * We define an interrupt and hardwire it to the /u3/mpic
34943cbf1a6SAndreas Tobler 		 * handle.
35043cbf1a6SAndreas Tobler 		 */
35143cbf1a6SAndreas Tobler 
35243cbf1a6SAndreas Tobler 		if (OF_getprop(child, "name", name, sizeof(name)) <= 0)
35343cbf1a6SAndreas Tobler 			device_printf(dev, "device has no name!\n");
35443cbf1a6SAndreas Tobler 		if (dinfo->udi_ninterrupts == 0 &&
35543cbf1a6SAndreas Tobler 		    (strcmp(name, "i2c-bus") == 0 ||
35643cbf1a6SAndreas Tobler 		     strcmp(name, "i2c")  == 0)) {
35743cbf1a6SAndreas Tobler 			if (OF_getprop(child, "interrupt-parent", &iparent,
35843cbf1a6SAndreas Tobler 				       sizeof(iparent)) <= 0) {
35943cbf1a6SAndreas Tobler 				iparent = OF_finddevice("/u3/mpic");
36043cbf1a6SAndreas Tobler 				device_printf(dev, "Set /u3/mpic as iparent!\n");
36143cbf1a6SAndreas Tobler 			}
36243cbf1a6SAndreas Tobler 			/* Add an interrupt number 0 to the parent. */
36343cbf1a6SAndreas Tobler 			irq = MAP_IRQ(iparent, 0);
36443cbf1a6SAndreas Tobler 			resource_list_add(&dinfo->udi_resources, SYS_RES_IRQ,
36543cbf1a6SAndreas Tobler 					  dinfo->udi_ninterrupts, irq, irq, 1);
36643cbf1a6SAndreas Tobler 			dinfo->udi_interrupts[dinfo->udi_ninterrupts] = irq;
36743cbf1a6SAndreas Tobler 			dinfo->udi_ninterrupts++;
36843cbf1a6SAndreas Tobler 		}
36943cbf1a6SAndreas Tobler 
370ca2c1931SNathan Whitehorn 		unin_chip_add_reg(child, dinfo);
371ca2c1931SNathan Whitehorn 
372ca2c1931SNathan Whitehorn 		cdev = device_add_child(dev, NULL, -1);
373ca2c1931SNathan Whitehorn 		if (cdev == NULL) {
374ca2c1931SNathan Whitehorn 			device_printf(dev, "<%s>: device_add_child failed\n",
375ca2c1931SNathan Whitehorn 				      dinfo->udi_obdinfo.obd_name);
376ca2c1931SNathan Whitehorn 			resource_list_free(&dinfo->udi_resources);
377ca2c1931SNathan Whitehorn 			ofw_bus_gen_destroy_devinfo(&dinfo->udi_obdinfo);
378ca2c1931SNathan Whitehorn 			free(dinfo, M_UNIN);
379ca2c1931SNathan Whitehorn 			continue;
380ca2c1931SNathan Whitehorn 		}
381ca2c1931SNathan Whitehorn 
382ca2c1931SNathan Whitehorn 		device_set_ivars(cdev, dinfo);
383ca2c1931SNathan Whitehorn 	}
384ca2c1931SNathan Whitehorn 
385ca2c1931SNathan Whitehorn 	/*
386ca2c1931SNathan Whitehorn 	 * Only map the first page, since that is where the registers
387ca2c1931SNathan Whitehorn 	 * of interest lie.
388ca2c1931SNathan Whitehorn 	 */
389ca2c1931SNathan Whitehorn 	sc->sc_addr = (vm_offset_t)pmap_mapdev(sc->sc_physaddr, PAGE_SIZE);
390ca2c1931SNathan Whitehorn 
391ca2c1931SNathan Whitehorn 	sc->sc_version = *(u_int *)sc->sc_addr;
392ca2c1931SNathan Whitehorn 	device_printf(dev, "Version %d\n", sc->sc_version);
393ca2c1931SNathan Whitehorn 
394ca2c1931SNathan Whitehorn 	/*
395ca2c1931SNathan Whitehorn 	 * Enable the GMAC Ethernet cell and the integrated OpenPIC
396ca2c1931SNathan Whitehorn 	 * if Open Firmware says they are used.
397ca2c1931SNathan Whitehorn 	 */
398ca2c1931SNathan Whitehorn 	for (child = OF_child(root); child; child = OF_peer(child)) {
399d48bbef3SPeter Grehan 		memset(compat, 0, sizeof(compat));
400d48bbef3SPeter Grehan 		OF_getprop(child, "compatible", compat, sizeof(compat));
401ca2c1931SNathan Whitehorn 		if (strcmp(compat, "gmac") == 0)
402ca2c1931SNathan Whitehorn 			unin_enable_gmac(dev);
403ca2c1931SNathan Whitehorn 		if (strcmp(compat, "chrp,open-pic") == 0)
404ca2c1931SNathan Whitehorn 			unin_enable_mpic(dev);
405d48bbef3SPeter Grehan 	}
406d48bbef3SPeter Grehan 
407ca2c1931SNathan Whitehorn 	/*
408ca2c1931SNathan Whitehorn 	 * GMAC lives under the PCI bus, so just check if enet is gmac.
409ca2c1931SNathan Whitehorn 	 */
410ca2c1931SNathan Whitehorn 	child = OF_finddevice("enet");
411ca2c1931SNathan Whitehorn 	memset(compat, 0, sizeof(compat));
412ca2c1931SNathan Whitehorn 	OF_getprop(child, "compatible", compat, sizeof(compat));
413ca2c1931SNathan Whitehorn 	if (strcmp(compat, "gmac") == 0)
414ca2c1931SNathan Whitehorn 		unin_enable_gmac(dev);
41594b4a038SNathan Whitehorn 
41698f8e6c0SBenno Rice 	return (bus_generic_attach(dev));
41798f8e6c0SBenno Rice }
41898f8e6c0SBenno Rice 
41998f8e6c0SBenno Rice static int
420ca2c1931SNathan Whitehorn unin_chip_print_child(device_t dev, device_t child)
42198f8e6c0SBenno Rice {
422ca2c1931SNathan Whitehorn         struct unin_chip_devinfo *dinfo;
423ca2c1931SNathan Whitehorn         struct resource_list *rl;
424ca2c1931SNathan Whitehorn         int retval = 0;
42598f8e6c0SBenno Rice 
426ca2c1931SNathan Whitehorn         dinfo = device_get_ivars(child);
427ca2c1931SNathan Whitehorn         rl = &dinfo->udi_resources;
42898f8e6c0SBenno Rice 
429ca2c1931SNathan Whitehorn         retval += bus_print_child_header(dev, child);
43098f8e6c0SBenno Rice 
431f8fd3fb5SJustin Hibbits         retval += resource_list_print_type(rl, "mem", SYS_RES_MEMORY, "%#jx");
432f8fd3fb5SJustin Hibbits         retval += resource_list_print_type(rl, "irq", SYS_RES_IRQ, "%jd");
43398f8e6c0SBenno Rice 
434ca2c1931SNathan Whitehorn         retval += bus_print_child_footer(dev, child);
43598f8e6c0SBenno Rice 
436ca2c1931SNathan Whitehorn         return (retval);
43798f8e6c0SBenno Rice }
43898f8e6c0SBenno Rice 
43998f8e6c0SBenno Rice static void
440ca2c1931SNathan Whitehorn unin_chip_probe_nomatch(device_t dev, device_t child)
44198f8e6c0SBenno Rice {
442ca2c1931SNathan Whitehorn         struct unin_chip_devinfo *dinfo;
443ca2c1931SNathan Whitehorn         struct resource_list *rl;
444ca2c1931SNathan Whitehorn 	const char *type;
44598f8e6c0SBenno Rice 
446ca2c1931SNathan Whitehorn 	if (bootverbose) {
447ca2c1931SNathan Whitehorn 		dinfo = device_get_ivars(child);
448ca2c1931SNathan Whitehorn 		rl = &dinfo->udi_resources;
44998f8e6c0SBenno Rice 
450ca2c1931SNathan Whitehorn 		if ((type = ofw_bus_get_type(child)) == NULL)
451ca2c1931SNathan Whitehorn 			type = "(unknown)";
452ca2c1931SNathan Whitehorn 		device_printf(dev, "<%s, %s>", type, ofw_bus_get_name(child));
453f8fd3fb5SJustin Hibbits 		resource_list_print_type(rl, "mem", SYS_RES_MEMORY, "%#jx");
454f8fd3fb5SJustin Hibbits 		resource_list_print_type(rl, "irq", SYS_RES_IRQ, "%jd");
455ca2c1931SNathan Whitehorn 		printf(" (no driver attached)\n");
45698f8e6c0SBenno Rice 	}
45798f8e6c0SBenno Rice }
45898f8e6c0SBenno Rice 
45998f8e6c0SBenno Rice 
46098f8e6c0SBenno Rice static struct resource *
461ca2c1931SNathan Whitehorn unin_chip_alloc_resource(device_t bus, device_t child, int type, int *rid,
4622dd1bdf1SJustin Hibbits 			 rman_res_t start, rman_res_t end, rman_res_t count,
4632dd1bdf1SJustin Hibbits 			 u_int flags)
46498f8e6c0SBenno Rice {
465ca2c1931SNathan Whitehorn 	struct		unin_chip_softc *sc;
466ca2c1931SNathan Whitehorn 	int		needactivate;
46798f8e6c0SBenno Rice 	struct		resource *rv;
46898f8e6c0SBenno Rice 	struct		rman *rm;
469ca2c1931SNathan Whitehorn 	u_long		adjstart, adjend, adjcount;
470ca2c1931SNathan Whitehorn 	struct		unin_chip_devinfo *dinfo;
471ca2c1931SNathan Whitehorn 	struct		resource_list_entry *rle;
472ca2c1931SNathan Whitehorn 
473ca2c1931SNathan Whitehorn 	sc = device_get_softc(bus);
474ca2c1931SNathan Whitehorn 	dinfo = device_get_ivars(child);
47598f8e6c0SBenno Rice 
47698f8e6c0SBenno Rice 	needactivate = flags & RF_ACTIVE;
47798f8e6c0SBenno Rice 	flags &= ~RF_ACTIVE;
47898f8e6c0SBenno Rice 
47998f8e6c0SBenno Rice 	switch (type) {
48098f8e6c0SBenno Rice 	case SYS_RES_MEMORY:
481ca2c1931SNathan Whitehorn 	case SYS_RES_IOPORT:
482ca2c1931SNathan Whitehorn 		rle = resource_list_find(&dinfo->udi_resources, SYS_RES_MEMORY,
483ca2c1931SNathan Whitehorn 					 *rid);
484ca2c1931SNathan Whitehorn 		if (rle == NULL) {
485ca2c1931SNathan Whitehorn 			device_printf(bus, "no rle for %s memory %d\n",
486ca2c1931SNathan Whitehorn 				      device_get_nameunit(child), *rid);
487ca2c1931SNathan Whitehorn 			return (NULL);
488ca2c1931SNathan Whitehorn 		}
489ca2c1931SNathan Whitehorn 
490ca2c1931SNathan Whitehorn 		rle->end = rle->end - 1; /* Hack? */
491ca2c1931SNathan Whitehorn 
492ca2c1931SNathan Whitehorn 		if (start < rle->start)
493ca2c1931SNathan Whitehorn 			adjstart = rle->start;
494ca2c1931SNathan Whitehorn 		else if (start > rle->end)
495ca2c1931SNathan Whitehorn 			adjstart = rle->end;
496ca2c1931SNathan Whitehorn 		else
497ca2c1931SNathan Whitehorn 			adjstart = start;
498ca2c1931SNathan Whitehorn 
499ca2c1931SNathan Whitehorn 		if (end < rle->start)
500ca2c1931SNathan Whitehorn 			adjend = rle->start;
501ca2c1931SNathan Whitehorn 		else if (end > rle->end)
502ca2c1931SNathan Whitehorn 			adjend = rle->end;
503ca2c1931SNathan Whitehorn 		else
504ca2c1931SNathan Whitehorn 			adjend = end;
505ca2c1931SNathan Whitehorn 
506ca2c1931SNathan Whitehorn 		adjcount = adjend - adjstart;
507ca2c1931SNathan Whitehorn 
50898f8e6c0SBenno Rice 		rm = &sc->sc_mem_rman;
50998f8e6c0SBenno Rice 		break;
510714aa5b9SAndrew Gallatin 
51198f8e6c0SBenno Rice 	case SYS_RES_IRQ:
512ca2c1931SNathan Whitehorn 		/* Check for passthrough from subattachments. */
513ca2c1931SNathan Whitehorn 		if (device_get_parent(child) != bus)
514ca2c1931SNathan Whitehorn 			return BUS_ALLOC_RESOURCE(device_get_parent(bus), child,
515ca2c1931SNathan Whitehorn 						  type, rid, start, end, count,
516ca2c1931SNathan Whitehorn 						  flags);
517de2fa7b8SMarcel Moolenaar 
518ca2c1931SNathan Whitehorn 		rle = resource_list_find(&dinfo->udi_resources, SYS_RES_IRQ,
519ca2c1931SNathan Whitehorn 		    *rid);
520ca2c1931SNathan Whitehorn 		if (rle == NULL) {
521ca2c1931SNathan Whitehorn 			if (dinfo->udi_ninterrupts >= 6) {
522ca2c1931SNathan Whitehorn 				device_printf(bus,
523ca2c1931SNathan Whitehorn 					      "%s has more than 6 interrupts\n",
524ca2c1931SNathan Whitehorn 					      device_get_nameunit(child));
525ca2c1931SNathan Whitehorn 				return (NULL);
526ca2c1931SNathan Whitehorn 			}
527ca2c1931SNathan Whitehorn 			resource_list_add(&dinfo->udi_resources, SYS_RES_IRQ,
528ca2c1931SNathan Whitehorn 					  dinfo->udi_ninterrupts, start, start,
529ca2c1931SNathan Whitehorn 					  1);
530ca2c1931SNathan Whitehorn 
531ca2c1931SNathan Whitehorn 			dinfo->udi_interrupts[dinfo->udi_ninterrupts] = start;
532ca2c1931SNathan Whitehorn 			dinfo->udi_ninterrupts++;
533ca2c1931SNathan Whitehorn 		}
534ca2c1931SNathan Whitehorn 
535ca2c1931SNathan Whitehorn 		return (resource_list_alloc(&dinfo->udi_resources, bus, child,
536ca2c1931SNathan Whitehorn 					    type, rid, start, end, count,
537ca2c1931SNathan Whitehorn 					    flags));
53898f8e6c0SBenno Rice 	default:
53998f8e6c0SBenno Rice 		device_printf(bus, "unknown resource request from %s\n",
54098f8e6c0SBenno Rice 			      device_get_nameunit(child));
54198f8e6c0SBenno Rice 		return (NULL);
54298f8e6c0SBenno Rice 	}
54398f8e6c0SBenno Rice 
544ca2c1931SNathan Whitehorn 	rv = rman_reserve_resource(rm, adjstart, adjend, adjcount, flags,
545ca2c1931SNathan Whitehorn 				   child);
54698f8e6c0SBenno Rice 	if (rv == NULL) {
547ca2c1931SNathan Whitehorn 		device_printf(bus,
548ca2c1931SNathan Whitehorn 			      "failed to reserve resource %#lx - %#lx (%#lx)"
549ca2c1931SNathan Whitehorn 			      " for %s\n", adjstart, adjend, adjcount,
55098f8e6c0SBenno Rice 			      device_get_nameunit(child));
55198f8e6c0SBenno Rice 		return (NULL);
55298f8e6c0SBenno Rice 	}
55398f8e6c0SBenno Rice 
554bdfb66f8SWarner Losh 	rman_set_rid(rv, *rid);
55598f8e6c0SBenno Rice 
55698f8e6c0SBenno Rice 	if (needactivate) {
55798f8e6c0SBenno Rice 		if (bus_activate_resource(child, type, *rid, rv) != 0) {
55898f8e6c0SBenno Rice                         device_printf(bus,
55998f8e6c0SBenno Rice 				      "failed to activate resource for %s\n",
56098f8e6c0SBenno Rice 				      device_get_nameunit(child));
56198f8e6c0SBenno Rice 			rman_release_resource(rv);
56298f8e6c0SBenno Rice 			return (NULL);
56398f8e6c0SBenno Rice                 }
56498f8e6c0SBenno Rice         }
56598f8e6c0SBenno Rice 
56698f8e6c0SBenno Rice 	return (rv);
56798f8e6c0SBenno Rice }
56898f8e6c0SBenno Rice 
56998f8e6c0SBenno Rice static int
570ca2c1931SNathan Whitehorn unin_chip_release_resource(device_t bus, device_t child, int type, int rid,
57198f8e6c0SBenno Rice 			   struct resource *res)
57298f8e6c0SBenno Rice {
573ca2c1931SNathan Whitehorn 	if (rman_get_flags(res) & RF_ACTIVE) {
574ca2c1931SNathan Whitehorn 		int error = bus_deactivate_resource(child, type, rid, res);
575ca2c1931SNathan Whitehorn 		if (error)
576ca2c1931SNathan Whitehorn 			return error;
577ca2c1931SNathan Whitehorn 	}
578ca2c1931SNathan Whitehorn 
579ca2c1931SNathan Whitehorn 	return (rman_release_resource(res));
580ca2c1931SNathan Whitehorn }
581ca2c1931SNathan Whitehorn 
582ca2c1931SNathan Whitehorn static int
583ca2c1931SNathan Whitehorn unin_chip_activate_resource(device_t bus, device_t child, int type, int rid,
584ca2c1931SNathan Whitehorn 			    struct resource *res)
585ca2c1931SNathan Whitehorn {
58698f8e6c0SBenno Rice 	void    *p;
587714aa5b9SAndrew Gallatin 
58898f8e6c0SBenno Rice 	if (type == SYS_RES_IRQ)
58998f8e6c0SBenno Rice                 return (bus_activate_resource(bus, type, rid, res));
59098f8e6c0SBenno Rice 
591ca2c1931SNathan Whitehorn 	if ((type == SYS_RES_MEMORY) || (type == SYS_RES_IOPORT)) {
592714aa5b9SAndrew Gallatin 		vm_offset_t start;
593714aa5b9SAndrew Gallatin 
594714aa5b9SAndrew Gallatin 		start = (vm_offset_t) rman_get_start(res);
595714aa5b9SAndrew Gallatin 
596714aa5b9SAndrew Gallatin 		if (bootverbose)
597da1b038aSJustin Hibbits 			printf("unin mapdev: start %zx, len %jd\n", start,
598714aa5b9SAndrew Gallatin 			       rman_get_size(res));
599714aa5b9SAndrew Gallatin 
600714aa5b9SAndrew Gallatin 		p = pmap_mapdev(start, (vm_size_t) rman_get_size(res));
60198f8e6c0SBenno Rice 		if (p == NULL)
60298f8e6c0SBenno Rice 			return (ENOMEM);
60398f8e6c0SBenno Rice 		rman_set_virtual(res, p);
604ca2c1931SNathan Whitehorn 		rman_set_bustag(res, &bs_be_tag);
60598f8e6c0SBenno Rice 		rman_set_bushandle(res, (u_long)p);
60698f8e6c0SBenno Rice 	}
60798f8e6c0SBenno Rice 
60898f8e6c0SBenno Rice 	return (rman_activate_resource(res));
60998f8e6c0SBenno Rice }
61098f8e6c0SBenno Rice 
611ca2c1931SNathan Whitehorn 
61298f8e6c0SBenno Rice static int
613ca2c1931SNathan Whitehorn unin_chip_deactivate_resource(device_t bus, device_t child, int type, int rid,
614ca2c1931SNathan Whitehorn 			      struct resource *res)
61598f8e6c0SBenno Rice {
61698f8e6c0SBenno Rice         /*
617ca2c1931SNathan Whitehorn          * If this is a memory resource, unmap it.
61898f8e6c0SBenno Rice          */
619ca2c1931SNathan Whitehorn         if ((type == SYS_RES_MEMORY) || (type == SYS_RES_IOPORT)) {
620ca2c1931SNathan Whitehorn 		u_int32_t psize;
62198f8e6c0SBenno Rice 
622ca2c1931SNathan Whitehorn 		psize = rman_get_size(res);
623ca2c1931SNathan Whitehorn 		pmap_unmapdev((vm_offset_t)rman_get_virtual(res), psize);
62498f8e6c0SBenno Rice 	}
62598f8e6c0SBenno Rice 
626ca2c1931SNathan Whitehorn 	return (rman_deactivate_resource(res));
62798f8e6c0SBenno Rice }
62898f8e6c0SBenno Rice 
629ca2c1931SNathan Whitehorn 
630ca2c1931SNathan Whitehorn static struct resource_list *
631ca2c1931SNathan Whitehorn unin_chip_get_resource_list (device_t dev, device_t child)
63251d163d3SNathan Whitehorn {
633ca2c1931SNathan Whitehorn 	struct unin_chip_devinfo *dinfo;
63451d163d3SNathan Whitehorn 
635ca2c1931SNathan Whitehorn 	dinfo = device_get_ivars(child);
636ca2c1931SNathan Whitehorn 	return (&dinfo->udi_resources);
63751d163d3SNathan Whitehorn }
63851d163d3SNathan Whitehorn 
639ca2c1931SNathan Whitehorn static const struct ofw_bus_devinfo *
640ca2c1931SNathan Whitehorn unin_chip_get_devinfo(device_t dev, device_t child)
64198f8e6c0SBenno Rice {
642ca2c1931SNathan Whitehorn 	struct unin_chip_devinfo *dinfo;
64398f8e6c0SBenno Rice 
644ca2c1931SNathan Whitehorn 	dinfo = device_get_ivars(child);
645ca2c1931SNathan Whitehorn 	return (&dinfo->udi_obdinfo);
64698f8e6c0SBenno Rice }
64798f8e6c0SBenno Rice 
6484702d987SJustin Hibbits int
6494702d987SJustin Hibbits unin_chip_wake(device_t dev)
6504702d987SJustin Hibbits {
6514702d987SJustin Hibbits 
6524702d987SJustin Hibbits 	if (dev == NULL)
6534702d987SJustin Hibbits 		dev = unin_chip;
6544702d987SJustin Hibbits 	unin_update_reg(dev, UNIN_PWR_MGMT, UNIN_PWR_NORMAL, UNIN_PWR_MASK);
6554702d987SJustin Hibbits 	DELAY(10);
6564702d987SJustin Hibbits 	unin_update_reg(dev, UNIN_HWINIT_STATE, UNIN_RUNNING, 0);
6574702d987SJustin Hibbits 	DELAY(100);
6584702d987SJustin Hibbits 
6594702d987SJustin Hibbits 	return (0);
6604702d987SJustin Hibbits }
6614702d987SJustin Hibbits 
6624702d987SJustin Hibbits int
6634702d987SJustin Hibbits unin_chip_sleep(device_t dev, int idle)
6644702d987SJustin Hibbits {
6654702d987SJustin Hibbits 	if (dev == NULL)
6664702d987SJustin Hibbits 		dev = unin_chip;
6674702d987SJustin Hibbits 
6684702d987SJustin Hibbits 	unin_update_reg(dev, UNIN_HWINIT_STATE, UNIN_SLEEPING, 0);
6694702d987SJustin Hibbits 	DELAY(10);
6704702d987SJustin Hibbits 	if (idle)
6714702d987SJustin Hibbits 		unin_update_reg(dev, UNIN_PWR_MGMT, UNIN_PWR_IDLE2, UNIN_PWR_MASK);
6724702d987SJustin Hibbits 	else
6734702d987SJustin Hibbits 		unin_update_reg(dev, UNIN_PWR_MGMT, UNIN_PWR_SLEEP, UNIN_PWR_MASK);
6744702d987SJustin Hibbits 	DELAY(10);
6754702d987SJustin Hibbits 
6764702d987SJustin Hibbits 	return (0);
6774702d987SJustin Hibbits }
678