source: rtems-libbsd/freebsd/sys/arm/lpc/lpc_pwr.c @ 9f2205a

55-freebsd-126-freebsd-12
Last change on this file since 9f2205a was 9f2205a, checked in by Kevin Kirspel <kevin-kirspel@…>, on 01/30/17 at 16:58:16

Port LPC32XX Ethernet and USB OHCI to RTEMS

  • Property mode set to 100755
File size: 3.7 KB
Line 
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#ifndef __rtems__
42#include <machine/intr.h>
43
44#include <dev/ofw/ofw_bus.h>
45#include <dev/ofw/ofw_bus_subr.h>
46#endif /* __rtems__ */
47
48#include <arm/lpc/lpcreg.h>
49#include <arm/lpc/lpcvar.h>
50
51struct lpc_pwr_softc {
52        device_t                dp_dev;
53        struct resource *       dp_mem_res;
54        bus_space_tag_t         dp_bst;
55        bus_space_handle_t      dp_bsh;
56};
57
58static struct lpc_pwr_softc *lpc_pwr_sc = NULL;
59
60static int lpc_pwr_probe(device_t);
61static int lpc_pwr_attach(device_t);
62
63#define lpc_pwr_read_4(_sc, _reg)                       \
64    bus_space_read_4((_sc)->dp_bst, (_sc)->dp_bsh, _reg)
65#define lpc_pwr_write_4(_sc, _reg, _val)                \
66    bus_space_write_4((_sc)->dp_bst, (_sc)->dp_bsh, _reg, _val)
67
68static int
69lpc_pwr_probe(device_t dev)
70{
71       
72#ifndef __rtems__
73        if (!ofw_bus_status_okay(dev))
74                return (ENXIO);
75
76        if (!ofw_bus_is_compatible(dev, "lpc,pwr"))
77                return (ENXIO);
78#endif /* __rtems__ */
79
80        device_set_desc(dev, "LPC32x0 Power Controller");
81        return (BUS_PROBE_DEFAULT);
82}
83
84static int
85lpc_pwr_attach(device_t dev)
86{
87        struct lpc_pwr_softc *sc = device_get_softc(dev);
88        int rid;
89
90        sc->dp_dev = dev;
91
92        rid = 0;
93        sc->dp_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
94            RF_ACTIVE);
95        if (!sc->dp_mem_res) {
96                device_printf(dev, "cannot allocate memory window\n");
97                return (ENXIO);
98        }
99
100        sc->dp_bst = rman_get_bustag(sc->dp_mem_res);
101        sc->dp_bsh = rman_get_bushandle(sc->dp_mem_res);
102
103        lpc_pwr_sc = sc;
104
105        return (0);
106}
107
108uint32_t
109lpc_pwr_read(device_t dev, int reg)
110{
111        return (lpc_pwr_read_4(lpc_pwr_sc, reg));
112}
113
114void
115lpc_pwr_write(device_t dev, int reg, uint32_t value)
116{
117        lpc_pwr_write_4(lpc_pwr_sc, reg, value);
118}
119
120static device_method_t lpc_pwr_methods[] = {
121        /* Device interface */
122        DEVMETHOD(device_probe,         lpc_pwr_probe),
123        DEVMETHOD(device_attach,        lpc_pwr_attach),
124        { 0, 0 }
125};
126
127static devclass_t lpc_pwr_devclass;
128
129static driver_t lpc_pwr_driver = {
130        "pwr",
131        lpc_pwr_methods,
132        sizeof(struct lpc_pwr_softc),
133};
134
135#ifndef __rtems__
136DRIVER_MODULE(pwr, simplebus, lpc_pwr_driver, lpc_pwr_devclass, 0, 0);
137#else /* __rtems__ */
138DRIVER_MODULE(pwr, nexus, lpc_pwr_driver, lpc_pwr_devclass, 0, 0);
139#endif /* __rtems__ */
Note: See TracBrowser for help on using the repository browser.