xref: /freebsd/sys/dev/dpaa/fman_fdt.c (revision b2e4da0b53ad082768b8f6f83766e030fd00d02a)
1 /*-
2  * Copyright (c) 2012 Semihalf.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26 
27 #include <sys/param.h>
28 #include <sys/systm.h>
29 #include <sys/kernel.h>
30 #include <sys/bus.h>
31 #include <sys/module.h>
32 
33 #include <dev/fdt/simplebus.h>
34 #include <dev/ofw/ofw_bus.h>
35 #include <dev/ofw/ofw_bus_subr.h>
36 
37 #include "fman.h"
38 #include "fman_if.h"
39 
40 #define	FFMAN_DEVSTR	"Freescale Frame Manager"
41 
42 static int	fman_fdt_probe(device_t dev);
43 
44 static device_method_t fman_methods[] = {
45 	/* Device interface */
46 	DEVMETHOD(device_probe,		fman_fdt_probe),
47 	DEVMETHOD(device_attach,	fman_attach),
48 	DEVMETHOD(device_detach,	fman_detach),
49 
50 	DEVMETHOD(device_shutdown,	fman_shutdown),
51 	DEVMETHOD(device_suspend,	fman_suspend),
52 	DEVMETHOD(device_resume,	fman_resume_dev),
53 
54 	DEVMETHOD(bus_alloc_resource,	fman_alloc_resource),
55 	DEVMETHOD(bus_activate_resource,	fman_activate_resource),
56 	DEVMETHOD(bus_release_resource,	fman_release_resource),
57 
58 	DEVMETHOD(fman_get_revision,	fman_get_revision),
59 	DEVMETHOD(fman_reset_mac,	fman_reset_mac),
60 	DEVMETHOD(fman_set_port_params,	fman_set_port_params),
61 	DEVMETHOD(fman_get_qman_channel_id,	fman_qman_channel_id),
62 
63 	DEVMETHOD_END
64 };
65 
66 DEFINE_CLASS_1(fman, fman_driver, fman_methods,
67     sizeof(struct fman_softc), simplebus_driver);
68 EARLY_DRIVER_MODULE(fman, simplebus, fman_driver, 0, 0,
69     BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE);
70 
71 
72 static int
73 fman_fdt_probe(device_t dev)
74 {
75 
76 	if (!ofw_bus_status_okay(dev))
77 		return (ENXIO);
78 
79 	if (!ofw_bus_is_compatible(dev, "fsl,fman"))
80 		return (ENXIO);
81 
82 	device_set_desc(dev, FFMAN_DEVSTR);
83 
84 	return (BUS_PROBE_DEFAULT);
85 }
86 
87 uint32_t
88 fman_get_clock(struct fman_softc *sc)
89 {
90 	device_t dev;
91 	phandle_t node;
92 	pcell_t fman_clock;
93 
94 	dev = sc->sc_base.dev;
95 	node = ofw_bus_get_node(dev);
96 
97 	if ((OF_getprop(node, "clock-frequency", &fman_clock,
98 	    sizeof(fman_clock)) <= 0) || (fman_clock == 0)) {
99 		device_printf(dev,
100 		    "could not acquire correct frequency from DTS\n");
101 
102 		return (0);
103 	}
104 
105 	return ((uint32_t)fman_clock);
106 }
107 
108