cxgbe/t4_tom: Read the chip's DDP page sizes and save them in a
[freebsd-src.git] / sys / arm / lpc / lpc_pwr.c
blob2b56e8cf644482ad13d8c42dcc8b3f5a6d8b5830
1 /*-
2 * Copyright (c) 2011 Jakub Wojciech Klama <jceel@FreeBSD.org>
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/bus.h>
34 #include <sys/kernel.h>
35 #include <sys/module.h>
36 #include <sys/malloc.h>
37 #include <sys/rman.h>
38 #include <machine/bus.h>
39 #include <machine/intr.h>
41 #include <dev/ofw/ofw_bus.h>
42 #include <dev/ofw/ofw_bus_subr.h>
44 #include <arm/lpc/lpcreg.h>
45 #include <arm/lpc/lpcvar.h>
47 struct lpc_pwr_softc {
48 device_t dp_dev;
49 struct resource * dp_mem_res;
50 bus_space_tag_t dp_bst;
51 bus_space_handle_t dp_bsh;
54 static struct lpc_pwr_softc *lpc_pwr_sc = NULL;
56 static int lpc_pwr_probe(device_t);
57 static int lpc_pwr_attach(device_t);
59 #define lpc_pwr_read_4(_sc, _reg) \
60 bus_space_read_4((_sc)->dp_bst, (_sc)->dp_bsh, _reg)
61 #define lpc_pwr_write_4(_sc, _reg, _val) \
62 bus_space_write_4((_sc)->dp_bst, (_sc)->dp_bsh, _reg, _val)
64 static int
65 lpc_pwr_probe(device_t dev)
68 if (!ofw_bus_status_okay(dev))
69 return (ENXIO);
71 if (!ofw_bus_is_compatible(dev, "lpc,pwr"))
72 return (ENXIO);
74 device_set_desc(dev, "LPC32x0 Power Controller");
75 return (BUS_PROBE_DEFAULT);
78 static int
79 lpc_pwr_attach(device_t dev)
81 struct lpc_pwr_softc *sc = device_get_softc(dev);
82 int rid;
84 sc->dp_dev = dev;
86 rid = 0;
87 sc->dp_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
88 RF_ACTIVE);
89 if (!sc->dp_mem_res) {
90 device_printf(dev, "cannot allocate memory window\n");
91 return (ENXIO);
94 sc->dp_bst = rman_get_bustag(sc->dp_mem_res);
95 sc->dp_bsh = rman_get_bushandle(sc->dp_mem_res);
97 lpc_pwr_sc = sc;
99 return (0);
102 uint32_t
103 lpc_pwr_read(device_t dev, int reg)
105 return (lpc_pwr_read_4(lpc_pwr_sc, reg));
108 void
109 lpc_pwr_write(device_t dev, int reg, uint32_t value)
111 lpc_pwr_write_4(lpc_pwr_sc, reg, value);
114 static device_method_t lpc_pwr_methods[] = {
115 /* Device interface */
116 DEVMETHOD(device_probe, lpc_pwr_probe),
117 DEVMETHOD(device_attach, lpc_pwr_attach),
118 { 0, 0 }
121 static devclass_t lpc_pwr_devclass;
123 static driver_t lpc_pwr_driver = {
124 "pwr",
125 lpc_pwr_methods,
126 sizeof(struct lpc_pwr_softc),
129 DRIVER_MODULE(pwr, simplebus, lpc_pwr_driver, lpc_pwr_devclass, 0, 0);