]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/mips/broadcom/bcma_nexus.c
Merge ACPICA 20170303.
[FreeBSD/FreeBSD.git] / sys / mips / broadcom / bcma_nexus.c
1 /*-
2  * Copyright (c) 2016 Michael Zhilin <mizhka@gmail.com>
3  * Copyright (c) 2015-2016 Landon Fuller <landon@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  * $FreeBSD$
31  */
32
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
35
36 #include <sys/param.h>
37 #include <sys/kernel.h>
38 #include <sys/bus.h>
39 #include <sys/module.h>
40
41 #include <machine/bus.h>
42 #include <sys/rman.h>
43 #include <machine/resource.h>
44
45 #include <dev/bhnd/bhnd_ids.h>
46
47 #include <dev/bhnd/bcma/bcmavar.h>
48
49 #include "bcm_machdep.h"
50
51 #include "bhnd_nexusvar.h"
52
53 /*
54  * Supports bcma(4) attachment to a MIPS nexus bus.
55  */
56
57 static int      bcma_nexus_attach(device_t);
58 static int      bcma_nexus_probe(device_t);
59
60 static int
61 bcma_nexus_probe(device_t dev)
62 {
63         int error;
64
65         switch (bcm_get_platform()->cid.chip_type) {
66         case BHND_CHIPTYPE_BCMA:
67         case BHND_CHIPTYPE_BCMA_ALT:
68         case BHND_CHIPTYPE_UBUS:
69                 break;
70         default:
71                 return (ENXIO);
72         }
73
74         if ((error = bcma_probe(dev)) > 0)
75                 return (error);
76
77         /* Set device description */
78         bhnd_set_default_bus_desc(dev, &bcm_get_platform()->cid);
79
80         return (BUS_PROBE_SPECIFIC);
81 }
82
83 static int
84 bcma_nexus_attach(device_t dev)
85 {
86         int error;
87
88         /* Perform initial attach and enumerate our children. */
89         if ((error = bcma_attach(dev)))
90                 goto failed;
91
92         /* Delegate remainder to standard bhnd method implementation */
93         if ((error = bhnd_generic_attach(dev)))
94                 goto failed;
95
96         return (0);
97
98 failed:
99         device_delete_children(dev);
100         return (error);
101 }
102
103 static device_method_t bcma_nexus_methods[] = {
104         DEVMETHOD(device_probe,                 bcma_nexus_probe),
105         DEVMETHOD(device_attach,                bcma_nexus_attach),
106
107         DEVMETHOD_END
108 };
109
110 DEFINE_CLASS_2(bhnd, bcma_nexus_driver, bcma_nexus_methods,
111     sizeof(struct bcma_softc), bhnd_nexus_driver, bcma_driver);
112
113 EARLY_DRIVER_MODULE(bcma_nexus, nexus, bcma_nexus_driver, bhnd_devclass, 0, 0,
114     BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE);