2 * Copyright (c) 2011-2012 Stefan Bethke.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
29 #include <sys/param.h>
31 #include <sys/systm.h>
33 #include <dev/etherswitch/mdio.h>
38 mdio_identify(driver_t *driver, device_t parent)
41 if (device_find_child(parent, mdio_driver.name, -1) == NULL)
42 BUS_ADD_CHILD(parent, 0, mdio_driver.name, -1);
46 mdio_probe(device_t dev)
49 device_set_desc(dev, "MDIO");
51 return (BUS_PROBE_SPECIFIC);
55 mdio_attach(device_t dev)
58 bus_generic_probe(dev);
59 bus_enumerate_hinted_children(dev);
60 return (bus_generic_attach(dev));
64 mdio_detach(device_t dev)
67 bus_generic_detach(dev);
72 mdio_readreg(device_t dev, int phy, int reg)
75 return (MDIO_READREG(device_get_parent(dev), phy, reg));
79 mdio_writereg(device_t dev, int phy, int reg, int val)
82 return (MDIO_WRITEREG(device_get_parent(dev), phy, reg, val));
86 mdio_hinted_child(device_t dev, const char *name, int unit)
89 device_add_child(dev, name, unit);
92 static device_method_t mdio_methods[] = {
93 /* device interface */
94 DEVMETHOD(device_identify, mdio_identify),
95 DEVMETHOD(device_probe, mdio_probe),
96 DEVMETHOD(device_attach, mdio_attach),
97 DEVMETHOD(device_detach, mdio_detach),
98 DEVMETHOD(device_shutdown, bus_generic_shutdown),
101 DEVMETHOD(bus_add_child, device_add_child_ordered),
102 DEVMETHOD(bus_hinted_child, mdio_hinted_child),
105 DEVMETHOD(mdio_readreg, mdio_readreg),
106 DEVMETHOD(mdio_writereg, mdio_writereg),
111 driver_t mdio_driver = {
117 devclass_t mdio_devclass;