Wed Mar 14 02:57:10 2012 UTC ()
Don't try to match a device if there's already a device attached at
the specified address.


(pgoyette)
diff -r1.37 -r1.38 src/sys/dev/i2c/i2c.c

cvs diff -r1.37 -r1.38 src/sys/dev/i2c/i2c.c (expand / switch to unified diff)

--- src/sys/dev/i2c/i2c.c 2011/10/11 15:19:09 1.37
+++ src/sys/dev/i2c/i2c.c 2012/03/14 02:57:10 1.38
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: i2c.c,v 1.37 2011/10/11 15:19:09 macallan Exp $ */ 1/* $NetBSD: i2c.c,v 1.38 2012/03/14 02:57:10 pgoyette Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2003 Wasabi Systems, Inc. 4 * Copyright (c) 2003 Wasabi Systems, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Written by Jason R. Thorpe for Wasabi Systems, Inc. 7 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -26,27 +26,27 @@ @@ -26,27 +26,27 @@
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE. 35 * POSSIBILITY OF SUCH DAMAGE.
36 */ 36 */
37 37
38#include <sys/cdefs.h> 38#include <sys/cdefs.h>
39__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.37 2011/10/11 15:19:09 macallan Exp $"); 39__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.38 2012/03/14 02:57:10 pgoyette Exp $");
40 40
41#include <sys/param.h> 41#include <sys/param.h>
42#include <sys/systm.h> 42#include <sys/systm.h>
43#include <sys/device.h> 43#include <sys/device.h>
44#include <sys/event.h> 44#include <sys/event.h>
45#include <sys/conf.h> 45#include <sys/conf.h>
46#include <sys/malloc.h> 46#include <sys/malloc.h>
47#include <sys/kmem.h> 47#include <sys/kmem.h>
48#include <sys/kthread.h> 48#include <sys/kthread.h>
49#include <sys/proc.h> 49#include <sys/proc.h>
50#include <sys/kernel.h> 50#include <sys/kernel.h>
51#include <sys/fcntl.h> 51#include <sys/fcntl.h>
52#include <sys/module.h> 52#include <sys/module.h>
@@ -108,30 +108,30 @@ iic_search(device_t parent, cfdata_t cf, @@ -108,30 +108,30 @@ iic_search(device_t parent, cfdata_t cf,
108{ 108{
109 struct iic_softc *sc = device_private(parent); 109 struct iic_softc *sc = device_private(parent);
110 struct i2c_attach_args ia; 110 struct i2c_attach_args ia;
111 111
112 ia.ia_tag = sc->sc_tag; 112 ia.ia_tag = sc->sc_tag;
113 ia.ia_addr = cf->cf_loc[IICCF_ADDR]; 113 ia.ia_addr = cf->cf_loc[IICCF_ADDR];
114 ia.ia_size = cf->cf_loc[IICCF_SIZE]; 114 ia.ia_size = cf->cf_loc[IICCF_SIZE];
115 ia.ia_type = sc->sc_type; 115 ia.ia_type = sc->sc_type;
116 116
117 ia.ia_name = NULL; 117 ia.ia_name = NULL;
118 ia.ia_ncompat = 0; 118 ia.ia_ncompat = 0;
119 ia.ia_compat = NULL; 119 ia.ia_compat = NULL;
120 120
121 if (config_match(parent, cf, &ia) > 0) { 121 if (ia.ia_addr != (i2c_addr_t)-1 &&
122 if (ia.ia_addr != (i2c_addr_t)-1 && 122 ia.ia_addr <= I2C_MAX_ADDR &&
123 ia.ia_addr <= I2C_MAX_ADDR && 123 !sc->sc_devices[ia.ia_addr])
124 !sc->sc_devices[ia.ia_addr]) 124 if (config_match(parent, cf, &ia) > 0) {
125 sc->sc_devices[ia.ia_addr] = 125 sc->sc_devices[ia.ia_addr] =
126 config_attach(parent, cf, &ia, iic_print); 126 config_attach(parent, cf, &ia, iic_print);
127 } 127 }
128 return 0; 128 return 0;
129} 129}
130 130
131static void 131static void
132iic_child_detach(device_t parent, device_t child) 132iic_child_detach(device_t parent, device_t child)
133{ 133{
134 struct iic_softc *sc = device_private(parent); 134 struct iic_softc *sc = device_private(parent);
135 int i; 135 int i;
136 136
137 for (i = 0; i <= I2C_MAX_ADDR; i++) 137 for (i = 0; i <= I2C_MAX_ADDR; i++)