ofw_iicbus.c (189280) | ofw_iicbus.c (194138) |
---|---|
1/*- 2 * Copyright (c) 2009, Nathan Whitehorn <nwhitehorn@FreeBSD.org> 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 --- 11 unchanged lines hidden (view full) --- 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2009, Nathan Whitehorn <nwhitehorn@FreeBSD.org> 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 --- 11 unchanged lines hidden (view full) --- 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: head/sys/dev/ofw/ofw_iicbus.c 189280 2009-03-02 15:22:01Z nwhitehorn $"); | 28__FBSDID("$FreeBSD: head/sys/dev/ofw/ofw_iicbus.c 194138 2009-06-14 00:05:38Z marius $"); |
29 30#include <sys/param.h> 31#include <sys/bus.h> 32#include <sys/kernel.h> 33#include <sys/libkern.h> 34#include <sys/lock.h> 35#include <sys/module.h> 36#include <sys/mutex.h> --- 26 unchanged lines hidden (view full) --- 63 /* ofw_bus interface */ 64 DEVMETHOD(ofw_bus_get_devinfo, ofw_iicbus_get_devinfo), 65 DEVMETHOD(ofw_bus_get_compat, ofw_bus_gen_get_compat), 66 DEVMETHOD(ofw_bus_get_model, ofw_bus_gen_get_model), 67 DEVMETHOD(ofw_bus_get_name, ofw_bus_gen_get_name), 68 DEVMETHOD(ofw_bus_get_node, ofw_bus_gen_get_node), 69 DEVMETHOD(ofw_bus_get_type, ofw_bus_gen_get_type), 70 | 29 30#include <sys/param.h> 31#include <sys/bus.h> 32#include <sys/kernel.h> 33#include <sys/libkern.h> 34#include <sys/lock.h> 35#include <sys/module.h> 36#include <sys/mutex.h> --- 26 unchanged lines hidden (view full) --- 63 /* ofw_bus interface */ 64 DEVMETHOD(ofw_bus_get_devinfo, ofw_iicbus_get_devinfo), 65 DEVMETHOD(ofw_bus_get_compat, ofw_bus_gen_get_compat), 66 DEVMETHOD(ofw_bus_get_model, ofw_bus_gen_get_model), 67 DEVMETHOD(ofw_bus_get_name, ofw_bus_gen_get_name), 68 DEVMETHOD(ofw_bus_get_node, ofw_bus_gen_get_node), 69 DEVMETHOD(ofw_bus_get_type, ofw_bus_gen_get_type), 70 |
71 { 0, 0 } | 71 KOBJMETHOD_END |
72}; 73 74struct ofw_iicbus_devinfo { 75 struct iicbus_ivar opd_dinfo; 76 struct ofw_bus_devinfo opd_obdinfo; 77}; 78 79static devclass_t ofwiicbus_devclass; --- 15 unchanged lines hidden (view full) --- 95 return (0); 96} 97 98static int 99ofw_iicbus_attach(device_t dev) 100{ 101 struct iicbus_softc *sc = IICBUS_SOFTC(dev); 102 struct ofw_iicbus_devinfo *dinfo; | 72}; 73 74struct ofw_iicbus_devinfo { 75 struct iicbus_ivar opd_dinfo; 76 struct ofw_bus_devinfo opd_obdinfo; 77}; 78 79static devclass_t ofwiicbus_devclass; --- 15 unchanged lines hidden (view full) --- 95 return (0); 96} 97 98static int 99ofw_iicbus_attach(device_t dev) 100{ 101 struct iicbus_softc *sc = IICBUS_SOFTC(dev); 102 struct ofw_iicbus_devinfo *dinfo; |
103 phandle_t node, child; | 103 phandle_t child; |
104 device_t childdev; 105 uint32_t addr; 106 107 sc->dev = dev; 108 mtx_init(&sc->lock, "iicbus", NULL, MTX_DEF); 109 iicbus_reset(dev, IIC_FASTEST, 0, NULL); 110 111 bus_generic_probe(dev); 112 bus_enumerate_hinted_children(dev); 113 114 /* 115 * Attach those children represented in the device tree. 116 */ | 104 device_t childdev; 105 uint32_t addr; 106 107 sc->dev = dev; 108 mtx_init(&sc->lock, "iicbus", NULL, MTX_DEF); 109 iicbus_reset(dev, IIC_FASTEST, 0, NULL); 110 111 bus_generic_probe(dev); 112 bus_enumerate_hinted_children(dev); 113 114 /* 115 * Attach those children represented in the device tree. 116 */ |
117 118 node = ofw_bus_get_node(dev); 119 120 for (child = OF_child(node); child != 0; child = OF_peer(child)) { | 117 for (child = OF_child(ofw_bus_get_node(dev)); child != 0; 118 child = OF_peer(child)) { |
121 /* 122 * Try to get the I2C address first from the i2c-address | 119 /* 120 * Try to get the I2C address first from the i2c-address |
123 * property, then try the reg property. It moves around | 121 * property, then try the reg property. It moves around |
124 * on different systems. 125 */ | 122 * on different systems. 123 */ |
126 | |
127 if (OF_getprop(child, "i2c-address", &addr, sizeof(addr)) == -1) 128 if (OF_getprop(child, "reg", &addr, sizeof(addr)) == -1) 129 continue; 130 131 /* 132 * Now set up the I2C and OFW bus layer devinfo and add it 133 * to the bus. 134 */ | 124 if (OF_getprop(child, "i2c-address", &addr, sizeof(addr)) == -1) 125 if (OF_getprop(child, "reg", &addr, sizeof(addr)) == -1) 126 continue; 127 128 /* 129 * Now set up the I2C and OFW bus layer devinfo and add it 130 * to the bus. 131 */ |
135 | |
136 dinfo = malloc(sizeof(struct ofw_iicbus_devinfo), M_DEVBUF, 137 M_NOWAIT | M_ZERO); 138 if (dinfo == NULL) 139 continue; 140 dinfo->opd_dinfo.addr = addr; 141 if (ofw_bus_gen_setup_devinfo(&dinfo->opd_obdinfo, child) != 142 0) { 143 free(dinfo, M_DEVBUF); --- 10 unchanged lines hidden (view full) --- 154ofw_iicbus_add_child(device_t dev, int order, const char *name, int unit) 155{ 156 device_t child; 157 struct ofw_iicbus_devinfo *devi; 158 159 child = device_add_child_ordered(dev, order, name, unit); 160 if (child == NULL) 161 return (child); | 132 dinfo = malloc(sizeof(struct ofw_iicbus_devinfo), M_DEVBUF, 133 M_NOWAIT | M_ZERO); 134 if (dinfo == NULL) 135 continue; 136 dinfo->opd_dinfo.addr = addr; 137 if (ofw_bus_gen_setup_devinfo(&dinfo->opd_obdinfo, child) != 138 0) { 139 free(dinfo, M_DEVBUF); --- 10 unchanged lines hidden (view full) --- 150ofw_iicbus_add_child(device_t dev, int order, const char *name, int unit) 151{ 152 device_t child; 153 struct ofw_iicbus_devinfo *devi; 154 155 child = device_add_child_ordered(dev, order, name, unit); 156 if (child == NULL) 157 return (child); |
162 devi = malloc(sizeof(struct ofw_iicbus_devinfo), M_DEVBUF, | 158 devi = malloc(sizeof(struct ofw_iicbus_devinfo), M_DEVBUF, |
163 M_NOWAIT | M_ZERO); 164 if (devi == NULL) { 165 device_delete_child(dev, child); 166 return (0); 167 } 168 | 159 M_NOWAIT | M_ZERO); 160 if (devi == NULL) { 161 device_delete_child(dev, child); 162 return (0); 163 } 164 |
169 /* NULL all the OFW-related parts of the ivars for non-OFW children */ 170 | 165 /* 166 * NULL all the OFW-related parts of the ivars for non-OFW 167 * children. 168 */ |
171 devi->opd_obdinfo.obd_node = -1; 172 devi->opd_obdinfo.obd_name = NULL; 173 devi->opd_obdinfo.obd_compat = NULL; 174 devi->opd_obdinfo.obd_type = NULL; 175 devi->opd_obdinfo.obd_model = NULL; 176 177 device_set_ivars(child, devi); | 169 devi->opd_obdinfo.obd_node = -1; 170 devi->opd_obdinfo.obd_name = NULL; 171 devi->opd_obdinfo.obd_compat = NULL; 172 devi->opd_obdinfo.obd_type = NULL; 173 devi->opd_obdinfo.obd_model = NULL; 174 175 device_set_ivars(child, devi); |
178 | 176 |
179 return (child); 180} 181 182static const struct ofw_bus_devinfo * 183ofw_iicbus_get_devinfo(device_t bus, device_t dev) 184{ 185 struct ofw_iicbus_devinfo *dinfo; 186 187 dinfo = device_get_ivars(dev); 188 return (&dinfo->opd_obdinfo); 189} | 177 return (child); 178} 179 180static const struct ofw_bus_devinfo * 181ofw_iicbus_get_devinfo(device_t bus, device_t dev) 182{ 183 struct ofw_iicbus_devinfo *dinfo; 184 185 dinfo = device_get_ivars(dev); 186 return (&dinfo->opd_obdinfo); 187} |
190 | |