2 * Copyright (c) 2011 Jakub Wojciech Klama <jceel@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
31 #include <sys/param.h>
32 #include <sys/systm.h>
34 #include <sys/kernel.h>
35 #include <sys/module.h>
36 #include <sys/malloc.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
{
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)
65 lpc_pwr_probe(device_t dev
)
68 if (!ofw_bus_status_okay(dev
))
71 if (!ofw_bus_is_compatible(dev
, "lpc,pwr"))
74 device_set_desc(dev
, "LPC32x0 Power Controller");
75 return (BUS_PROBE_DEFAULT
);
79 lpc_pwr_attach(device_t dev
)
81 struct lpc_pwr_softc
*sc
= device_get_softc(dev
);
87 sc
->dp_mem_res
= bus_alloc_resource_any(dev
, SYS_RES_MEMORY
, &rid
,
89 if (!sc
->dp_mem_res
) {
90 device_printf(dev
, "cannot allocate memory window\n");
94 sc
->dp_bst
= rman_get_bustag(sc
->dp_mem_res
);
95 sc
->dp_bsh
= rman_get_bushandle(sc
->dp_mem_res
);
103 lpc_pwr_read(device_t dev
, int reg
)
105 return (lpc_pwr_read_4(lpc_pwr_sc
, reg
));
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
),
121 static devclass_t lpc_pwr_devclass
;
123 static driver_t lpc_pwr_driver
= {
126 sizeof(struct lpc_pwr_softc
),
129 DRIVER_MODULE(pwr
, simplebus
, lpc_pwr_driver
, lpc_pwr_devclass
, 0, 0);