]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/mips/broadcom/bcm_mips74k.c
MFV r316863: 3871 fix issues introduced by 3604
[FreeBSD/FreeBSD.git] / sys / mips / broadcom / bcm_mips74k.c
1 /*-
2  * Copyright (c) 2016 Michael Zhilin <mizhka@gmail.com>
3  * Copyright (c) 2016 Landon Fuller <landonf@FreeBSD.org>
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer,
11  *    without modification.
12  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
13  *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
14  *    redistribution must be conditioned upon including a substantially
15  *    similar Disclaimer requirement for further binary redistribution.
16  *
17  * NO WARRANTY
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
21  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
23  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
26  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28  * THE POSSIBILITY OF SUCH DAMAGES.
29  */
30
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
33
34 #include <sys/param.h>
35 #include <sys/kernel.h>
36 #include <sys/bus.h>
37 #include <sys/module.h>
38
39 #include <machine/bus.h>
40 #include <sys/rman.h>
41 #include <machine/resource.h>
42
43 #include <dev/bhnd/bhnd.h>
44
45 #include "bcm_mips74kreg.h"
46
47 /*
48  * Broadcom MIPS74K Core
49  *
50  * These cores are only found on bcma(4) chipsets, allowing
51  * us to assume the availability of bcma interrupt registers.
52  */
53
54 static const struct bhnd_device bcm_mips74k_devs[] = {
55         BHND_DEVICE(MIPS, MIPS74K, NULL, NULL, BHND_DF_SOC),
56         BHND_DEVICE_END
57 };
58
59 struct bcm_mips74k_softc {
60         device_t                 dev;
61         struct resource         *mem_res;
62         int                      mem_rid;
63 };
64
65 static int
66 bcm_mips74k_probe(device_t dev)
67 {
68         const struct bhnd_device        *id;
69
70         id = bhnd_device_lookup(dev, bcm_mips74k_devs,
71             sizeof(bcm_mips74k_devs[0]));
72         if (id == NULL)
73                 return (ENXIO);
74
75         bhnd_set_default_core_desc(dev);
76         return (BUS_PROBE_DEFAULT);
77 }
78
79 static int
80 bcm_mips74k_attach(device_t dev)
81 {
82         struct bcm_mips74k_softc *sc;
83
84         sc = device_get_softc(dev);
85         sc->dev = dev;
86
87         /* Allocate bus resources */
88         sc->mem_rid = 0;
89         sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->mem_rid,
90             RF_ACTIVE);
91         if (sc->mem_res == NULL)
92                 return (ENXIO);
93
94         /* Route MIPS timer to IRQ5 */
95         bus_write_4(sc->mem_res, BCM_MIPS74K_INTR5_SEL,
96             (1<<BCM_MIPS74K_TIMER_IVEC));
97
98         return (0);
99 }
100
101 static int
102 bcm_mips74k_detach(device_t dev)
103 {
104         struct bcm_mips74k_softc        *sc;
105
106         sc = device_get_softc(dev);
107
108         bus_release_resource(dev, SYS_RES_MEMORY, sc->mem_rid, sc->mem_res);
109
110         return (0);
111 }
112
113 static device_method_t bcm_mips74k_methods[] = {
114         /* Device interface */
115         DEVMETHOD(device_probe,                 bcm_mips74k_probe),
116         DEVMETHOD(device_attach,                bcm_mips74k_attach),
117         DEVMETHOD(device_detach,                bcm_mips74k_detach),
118         
119         DEVMETHOD_END
120 };
121
122 static devclass_t bcm_mips_devclass;
123
124 DEFINE_CLASS_0(bcm_mips, bcm_mips74k_driver, bcm_mips74k_methods, sizeof(struct bcm_mips74k_softc));
125 EARLY_DRIVER_MODULE(bcm_mips74k, bhnd, bcm_mips74k_driver, bcm_mips_devclass, 0, 0, BUS_PASS_CPU + BUS_PASS_ORDER_EARLY);
126 MODULE_VERSION(bcm_mips74k, 1);
127 MODULE_DEPEND(bcm_mips74k, bhnd, 1, 1, 1);