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