1234861Sadrian/*- 2234861Sadrian * Copyright (c) 2011-2012 Stefan Bethke. 3234861Sadrian * All rights reserved. 4234861Sadrian * 5234861Sadrian * Redistribution and use in source and binary forms, with or without 6234861Sadrian * modification, are permitted provided that the following conditions 7234861Sadrian * are met: 8234861Sadrian * 1. Redistributions of source code must retain the above copyright 9234861Sadrian * notice, this list of conditions and the following disclaimer. 10234861Sadrian * 2. Redistributions in binary form must reproduce the above copyright 11234861Sadrian * notice, this list of conditions and the following disclaimer in the 12234861Sadrian * documentation and/or other materials provided with the distribution. 13234861Sadrian * 14234861Sadrian * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15234861Sadrian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16234861Sadrian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17234861Sadrian * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18234861Sadrian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19234861Sadrian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20234861Sadrian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21234861Sadrian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22234861Sadrian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23234861Sadrian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24234861Sadrian * SUCH DAMAGE. 25234861Sadrian * 26234861Sadrian * $FreeBSD$ 27234861Sadrian */ 28234861Sadrian 29234861Sadrian#include <sys/param.h> 30234861Sadrian#include <sys/bus.h> 31234861Sadrian#include <sys/systm.h> 32234861Sadrian 33234861Sadrian#include <dev/etherswitch/mdio.h> 34234861Sadrian 35234861Sadrian#include "mdio_if.h" 36234861Sadrian 37234861Sadrianstatic void 38234861Sadrianmdio_identify(driver_t *driver, device_t parent) 39234861Sadrian{ 40234861Sadrian 41234861Sadrian if (device_find_child(parent, mdio_driver.name, -1) == NULL) 42234861Sadrian BUS_ADD_CHILD(parent, 0, mdio_driver.name, -1); 43234861Sadrian} 44234861Sadrian 45234861Sadrianstatic int 46234861Sadrianmdio_probe(device_t dev) 47234861Sadrian{ 48234861Sadrian 49234861Sadrian device_set_desc(dev, "MDIO"); 50234861Sadrian 51234861Sadrian return (BUS_PROBE_SPECIFIC); 52234861Sadrian} 53234861Sadrian 54234861Sadrianstatic int 55234861Sadrianmdio_attach(device_t dev) 56234861Sadrian{ 57234861Sadrian 58234861Sadrian bus_generic_probe(dev); 59234861Sadrian bus_enumerate_hinted_children(dev); 60234861Sadrian return (bus_generic_attach(dev)); 61234861Sadrian} 62234861Sadrian 63234861Sadrianstatic int 64234861Sadrianmdio_detach(device_t dev) 65234861Sadrian{ 66234861Sadrian 67234861Sadrian bus_generic_detach(dev); 68234861Sadrian return (0); 69234861Sadrian} 70234861Sadrian 71234861Sadrianstatic int 72234861Sadrianmdio_readreg(device_t dev, int phy, int reg) 73234861Sadrian{ 74234861Sadrian 75234861Sadrian return (MDIO_READREG(device_get_parent(dev), phy, reg)); 76234861Sadrian} 77234861Sadrian 78234861Sadrianstatic int 79234861Sadrianmdio_writereg(device_t dev, int phy, int reg, int val) 80234861Sadrian{ 81234861Sadrian 82234861Sadrian return (MDIO_WRITEREG(device_get_parent(dev), phy, reg, val)); 83234861Sadrian} 84234861Sadrian 85234861Sadrianstatic void 86234861Sadrianmdio_hinted_child(device_t dev, const char *name, int unit) 87234861Sadrian{ 88234861Sadrian 89234861Sadrian device_add_child(dev, name, unit); 90234861Sadrian} 91234861Sadrian 92234861Sadrianstatic device_method_t mdio_methods[] = { 93234861Sadrian /* device interface */ 94234861Sadrian DEVMETHOD(device_identify, mdio_identify), 95234861Sadrian DEVMETHOD(device_probe, mdio_probe), 96234861Sadrian DEVMETHOD(device_attach, mdio_attach), 97234861Sadrian DEVMETHOD(device_detach, mdio_detach), 98234861Sadrian DEVMETHOD(device_shutdown, bus_generic_shutdown), 99234861Sadrian 100234861Sadrian /* bus interface */ 101234861Sadrian DEVMETHOD(bus_add_child, device_add_child_ordered), 102234861Sadrian DEVMETHOD(bus_hinted_child, mdio_hinted_child), 103234861Sadrian 104234861Sadrian /* MDIO access */ 105234861Sadrian DEVMETHOD(mdio_readreg, mdio_readreg), 106234861Sadrian DEVMETHOD(mdio_writereg, mdio_writereg), 107234861Sadrian 108234861Sadrian DEVMETHOD_END 109234861Sadrian}; 110234861Sadrian 111234861Sadriandriver_t mdio_driver = { 112234861Sadrian "mdio", 113234861Sadrian mdio_methods, 114234861Sadrian 0 115234861Sadrian}; 116234861Sadrian 117234861Sadriandevclass_t mdio_devclass; 118