xref: /freebsd/sys/powerpc/mikrotik/platform_rb.c (revision fdafd315ad0d0f28a11b9fb4476a9ab059c62b92)
1*6aabc119SJustin Hibbits /*-
2*6aabc119SJustin Hibbits  * Copyright (c) 2015 Justin Hibbits
3*6aabc119SJustin Hibbits  * All rights reserved.
4*6aabc119SJustin Hibbits  *
5*6aabc119SJustin Hibbits  * Redistribution and use in source and binary forms, with or without
6*6aabc119SJustin Hibbits  * modification, are permitted provided that the following conditions
7*6aabc119SJustin Hibbits  * are met:
8*6aabc119SJustin Hibbits  *
9*6aabc119SJustin Hibbits  * 1. Redistributions of source code must retain the above copyright
10*6aabc119SJustin Hibbits  *    notice, this list of conditions and the following disclaimer.
11*6aabc119SJustin Hibbits  * 2. Redistributions in binary form must reproduce the above copyright
12*6aabc119SJustin Hibbits  *    notice, this list of conditions and the following disclaimer in the
13*6aabc119SJustin Hibbits  *    documentation and/or other materials provided with the distribution.
14*6aabc119SJustin Hibbits  *
15*6aabc119SJustin Hibbits  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16*6aabc119SJustin Hibbits  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17*6aabc119SJustin Hibbits  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18*6aabc119SJustin Hibbits  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19*6aabc119SJustin Hibbits  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20*6aabc119SJustin Hibbits  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21*6aabc119SJustin Hibbits  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22*6aabc119SJustin Hibbits  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23*6aabc119SJustin Hibbits  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24*6aabc119SJustin Hibbits  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*6aabc119SJustin Hibbits  */
26*6aabc119SJustin Hibbits 
27*6aabc119SJustin Hibbits #include <sys/param.h>
28*6aabc119SJustin Hibbits #include <sys/systm.h>
29*6aabc119SJustin Hibbits #include <sys/kernel.h>
30*6aabc119SJustin Hibbits #include <sys/bus.h>
31*6aabc119SJustin Hibbits #include <sys/malloc.h>
32*6aabc119SJustin Hibbits #include <sys/smp.h>
33*6aabc119SJustin Hibbits 
34*6aabc119SJustin Hibbits #include <machine/platform.h>
35*6aabc119SJustin Hibbits #include <machine/platformvar.h>
36*6aabc119SJustin Hibbits 
37*6aabc119SJustin Hibbits #include <dev/ofw/openfirm.h>
38*6aabc119SJustin Hibbits 
39*6aabc119SJustin Hibbits #include <powerpc/mpc85xx/mpc85xx.h>
40*6aabc119SJustin Hibbits 
41*6aabc119SJustin Hibbits #include "platform_if.h"
42*6aabc119SJustin Hibbits 
43*6aabc119SJustin Hibbits static int rb_probe(platform_t);
44*6aabc119SJustin Hibbits static int rb_attach(platform_t);
45*6aabc119SJustin Hibbits 
46*6aabc119SJustin Hibbits static platform_method_t rb_methods[] = {
47*6aabc119SJustin Hibbits 	PLATFORMMETHOD(platform_probe,		rb_probe),
48*6aabc119SJustin Hibbits 	PLATFORMMETHOD(platform_attach,		rb_attach),
49*6aabc119SJustin Hibbits 	PLATFORMMETHOD_END
50*6aabc119SJustin Hibbits };
51*6aabc119SJustin Hibbits 
52*6aabc119SJustin Hibbits DEFINE_CLASS_1(rb, rb_platform, rb_methods, 0, mpc85xx_platform);
53*6aabc119SJustin Hibbits 
54*6aabc119SJustin Hibbits PLATFORM_DEF(rb_platform);
55*6aabc119SJustin Hibbits 
56*6aabc119SJustin Hibbits static int
rb_probe(platform_t plat)57*6aabc119SJustin Hibbits rb_probe(platform_t plat)
58*6aabc119SJustin Hibbits {
59*6aabc119SJustin Hibbits 	phandle_t rootnode;
60*6aabc119SJustin Hibbits 	char model[32];
61*6aabc119SJustin Hibbits 
62*6aabc119SJustin Hibbits 	rootnode = OF_finddevice("/");
63*6aabc119SJustin Hibbits 
64*6aabc119SJustin Hibbits 	if (OF_getprop(rootnode, "model", model, sizeof(model)) > 0) {
65*6aabc119SJustin Hibbits 		if (strcmp(model, "RB800") == 0)
66*6aabc119SJustin Hibbits 			return (BUS_PROBE_SPECIFIC);
67*6aabc119SJustin Hibbits 	}
68*6aabc119SJustin Hibbits 
69*6aabc119SJustin Hibbits 	return (ENXIO);
70*6aabc119SJustin Hibbits }
71*6aabc119SJustin Hibbits 
72*6aabc119SJustin Hibbits static int
rb_attach(platform_t plat)73*6aabc119SJustin Hibbits rb_attach(platform_t plat)
74*6aabc119SJustin Hibbits {
75*6aabc119SJustin Hibbits 	int error;
76*6aabc119SJustin Hibbits 
77*6aabc119SJustin Hibbits 	error = mpc85xx_attach(plat);
78*6aabc119SJustin Hibbits 	if (error)
79*6aabc119SJustin Hibbits 		return (error);
80*6aabc119SJustin Hibbits 
81*6aabc119SJustin Hibbits 	return (0);
82*6aabc119SJustin Hibbits }
83