iicbus.c (282668) | iicbus.c (282674) |
---|---|
1/*- 2 * Copyright (c) 1998, 2001 Nicolas Souchu 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 * 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/cdefs.h> | 1/*- 2 * Copyright (c) 1998, 2001 Nicolas Souchu 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 * 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/cdefs.h> |
28__FBSDID("$FreeBSD: head/sys/dev/iicbus/iicbus.c 282668 2015-05-08 21:51:37Z loos $"); | 28__FBSDID("$FreeBSD: head/sys/dev/iicbus/iicbus.c 282674 2015-05-09 03:05:44Z loos $"); |
29 30/* 31 * Autoconfiguration and support routines for the Philips serial I2C bus 32 */ 33 34#include <sys/param.h> 35#include <sys/systm.h> 36#include <sys/kernel.h> 37#include <sys/lock.h> 38#include <sys/malloc.h> 39#include <sys/module.h> 40#include <sys/mutex.h> | 29 30/* 31 * Autoconfiguration and support routines for the Philips serial I2C bus 32 */ 33 34#include <sys/param.h> 35#include <sys/systm.h> 36#include <sys/kernel.h> 37#include <sys/lock.h> 38#include <sys/malloc.h> 39#include <sys/module.h> 40#include <sys/mutex.h> |
41#include <sys/rman.h> |
|
41#include <sys/sysctl.h> 42#include <sys/bus.h> 43 44#include <dev/iicbus/iiconf.h> 45#include <dev/iicbus/iicbus.h> 46 47#include "iicbus_if.h" 48 --- 93 unchanged lines hidden (view full) --- 142iicbus_print_child(device_t dev, device_t child) 143{ 144 struct iicbus_ivar *devi = IICBUS_IVAR(child); 145 int retval = 0; 146 147 retval += bus_print_child_header(dev, child); 148 if (devi->addr != 0) 149 retval += printf(" at addr %#x", devi->addr); | 42#include <sys/sysctl.h> 43#include <sys/bus.h> 44 45#include <dev/iicbus/iiconf.h> 46#include <dev/iicbus/iicbus.h> 47 48#include "iicbus_if.h" 49 --- 93 unchanged lines hidden (view full) --- 143iicbus_print_child(device_t dev, device_t child) 144{ 145 struct iicbus_ivar *devi = IICBUS_IVAR(child); 146 int retval = 0; 147 148 retval += bus_print_child_header(dev, child); 149 if (devi->addr != 0) 150 retval += printf(" at addr %#x", devi->addr); |
151 resource_list_print_type(&devi->rl, "irq", SYS_RES_IRQ, "%ld"); |
|
150 retval += bus_print_child_footer(dev, child); 151 152 return (retval); 153} 154 155static void 156iicbus_probe_nomatch(device_t bus, device_t child) 157{ 158 struct iicbus_ivar *devi = IICBUS_IVAR(child); 159 | 152 retval += bus_print_child_footer(dev, child); 153 154 return (retval); 155} 156 157static void 158iicbus_probe_nomatch(device_t bus, device_t child) 159{ 160 struct iicbus_ivar *devi = IICBUS_IVAR(child); 161 |
160 device_printf(bus, "<unknown card>"); 161 printf(" at addr %#x\n", devi->addr); 162 return; | 162 device_printf(bus, "<unknown card> at addr %#x", devi->addr); 163 resource_list_print_type(&devi->rl, "irq", SYS_RES_IRQ, "%ld"); 164 printf("\n"); |
163} 164 165static int 166iicbus_child_location_str(device_t bus, device_t child, char *buf, 167 size_t buflen) 168{ 169 struct iicbus_ivar *devi = IICBUS_IVAR(child); 170 --- 33 unchanged lines hidden (view full) --- 204 child = device_add_child_ordered(dev, order, name, unit); 205 if (child == NULL) 206 return (child); 207 devi = malloc(sizeof(struct iicbus_ivar), M_DEVBUF, M_NOWAIT | M_ZERO); 208 if (devi == NULL) { 209 device_delete_child(dev, child); 210 return (0); 211 } | 165} 166 167static int 168iicbus_child_location_str(device_t bus, device_t child, char *buf, 169 size_t buflen) 170{ 171 struct iicbus_ivar *devi = IICBUS_IVAR(child); 172 --- 33 unchanged lines hidden (view full) --- 206 child = device_add_child_ordered(dev, order, name, unit); 207 if (child == NULL) 208 return (child); 209 devi = malloc(sizeof(struct iicbus_ivar), M_DEVBUF, M_NOWAIT | M_ZERO); 210 if (devi == NULL) { 211 device_delete_child(dev, child); 212 return (0); 213 } |
214 resource_list_init(&devi->rl); |
|
212 device_set_ivars(child, devi); 213 return (child); 214} 215 216static void 217iicbus_hinted_child(device_t bus, const char *dname, int dunit) 218{ 219 device_t child; | 215 device_set_ivars(child, devi); 216 return (child); 217} 218 219static void 220iicbus_hinted_child(device_t bus, const char *dname, int dunit) 221{ 222 device_t child; |
223 int irq; |
|
220 struct iicbus_ivar *devi; 221 222 child = BUS_ADD_CHILD(bus, 0, dname, dunit); 223 devi = IICBUS_IVAR(child); 224 resource_int_value(dname, dunit, "addr", &devi->addr); | 224 struct iicbus_ivar *devi; 225 226 child = BUS_ADD_CHILD(bus, 0, dname, dunit); 227 devi = IICBUS_IVAR(child); 228 resource_int_value(dname, dunit, "addr", &devi->addr); |
229 if (resource_int_value(dname, dunit, "irq", &irq) == 0) { 230 if (bus_set_resource(child, SYS_RES_IRQ, 0, irq, 1) != 0) 231 device_printf(bus, 232 "warning: bus_set_resource() failed\n"); 233 } |
|
225} 226 | 234} 235 |
236static int 237iicbus_set_resource(device_t dev, device_t child, int type, int rid, 238 u_long start, u_long count) 239{ 240 struct iicbus_ivar *devi; 241 struct resource_list_entry *rle; 242 243 devi = IICBUS_IVAR(child); 244 rle = resource_list_add(&devi->rl, type, rid, start, 245 start + count - 1, count); 246 if (rle == NULL) 247 return (ENXIO); 248 249 return (0); 250} 251 252static struct resource * 253iicbus_alloc_resource(device_t bus, device_t child, int type, int *rid, 254 u_long start, u_long end, u_long count, u_int flags) 255{ 256 struct resource_list *rl; 257 struct resource_list_entry *rle; 258 259 /* Only IRQ resources are supported. */ 260 if (type != SYS_RES_IRQ) 261 return (NULL); 262 263 /* 264 * Request for the default allocation with a given rid: use resource 265 * list stored in the local device info. 266 */ 267 if ((start == 0UL) && (end == ~0UL)) { 268 rl = BUS_GET_RESOURCE_LIST(bus, child); 269 if (rl == NULL) 270 return (NULL); 271 rle = resource_list_find(rl, type, *rid); 272 if (rle == NULL) { 273 if (bootverbose) 274 device_printf(bus, "no default resources for " 275 "rid = %d, type = %d\n", *rid, type); 276 return (NULL); 277 } 278 start = rle->start; 279 end = rle->end; 280 count = rle->count; 281 } 282 283 return (bus_generic_alloc_resource(bus, child, type, rid, start, end, 284 count, flags)); 285} 286 287static struct resource_list * 288iicbus_get_resource_list(device_t bus __unused, device_t child) 289{ 290 struct iicbus_ivar *devi; 291 292 devi = IICBUS_IVAR(child); 293 return (&devi->rl); 294} 295 |
|
227int 228iicbus_generic_intr(device_t dev, int event, char *buf) 229{ 230 231 return (0); 232} 233 234int --- 57 unchanged lines hidden (view full) --- 292 293static device_method_t iicbus_methods[] = { 294 /* device interface */ 295 DEVMETHOD(device_probe, iicbus_probe), 296 DEVMETHOD(device_attach, iicbus_attach), 297 DEVMETHOD(device_detach, iicbus_detach), 298 299 /* bus interface */ | 296int 297iicbus_generic_intr(device_t dev, int event, char *buf) 298{ 299 300 return (0); 301} 302 303int --- 57 unchanged lines hidden (view full) --- 361 362static device_method_t iicbus_methods[] = { 363 /* device interface */ 364 DEVMETHOD(device_probe, iicbus_probe), 365 DEVMETHOD(device_attach, iicbus_attach), 366 DEVMETHOD(device_detach, iicbus_detach), 367 368 /* bus interface */ |
369 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), 370 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), 371 DEVMETHOD(bus_release_resource, bus_generic_release_resource), 372 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), 373 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), 374 DEVMETHOD(bus_adjust_resource, bus_generic_adjust_resource), 375 DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource), 376 DEVMETHOD(bus_alloc_resource, iicbus_alloc_resource), 377 DEVMETHOD(bus_get_resource_list, iicbus_get_resource_list), 378 DEVMETHOD(bus_set_resource, iicbus_set_resource), |
|
300 DEVMETHOD(bus_add_child, iicbus_add_child), 301 DEVMETHOD(bus_print_child, iicbus_print_child), 302 DEVMETHOD(bus_probe_nomatch, iicbus_probe_nomatch), 303 DEVMETHOD(bus_read_ivar, iicbus_read_ivar), 304 DEVMETHOD(bus_child_pnpinfo_str, iicbus_child_pnpinfo_str), 305 DEVMETHOD(bus_child_location_str, iicbus_child_location_str), 306 DEVMETHOD(bus_hinted_child, iicbus_hinted_child), 307 --- 17 unchanged lines hidden --- | 379 DEVMETHOD(bus_add_child, iicbus_add_child), 380 DEVMETHOD(bus_print_child, iicbus_print_child), 381 DEVMETHOD(bus_probe_nomatch, iicbus_probe_nomatch), 382 DEVMETHOD(bus_read_ivar, iicbus_read_ivar), 383 DEVMETHOD(bus_child_pnpinfo_str, iicbus_child_pnpinfo_str), 384 DEVMETHOD(bus_child_location_str, iicbus_child_location_str), 385 DEVMETHOD(bus_hinted_child, iicbus_hinted_child), 386 --- 17 unchanged lines hidden --- |