1 /* $NetBSD: i2c.c,v 1.8 2006/06/26 18:19:40 drochner Exp $ */ 2 3 /* 4 * Copyright (c) 2003 Wasabi Systems, Inc. 5 * All rights reserved. 6 * 7 * Written by Jason R. Thorpe for Wasabi Systems, Inc. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed for the NetBSD Project by 20 * Wasabi Systems, Inc. 21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse 22 * or promote products derived from this software without specific prior 23 * written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 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 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 35 * POSSIBILITY OF SUCH DAMAGE. 36 */ 37 38 #include <sys/param.h> 39 #include <sys/systm.h> 40 #include <sys/device.h> 41 #include <sys/event.h> 42 #include <sys/conf.h> 43 44 #include <dev/i2c/i2cvar.h> 45 46 #include "locators.h" 47 48 struct iic_softc { 49 struct device sc_dev; 50 i2c_tag_t sc_tag; 51 int sc_type; 52 }; 53 54 int 55 iicbus_print(void *aux, const char *pnp) 56 { 57 58 if (pnp != NULL) 59 aprint_normal("iic at %s", pnp); 60 61 return (UNCONF); 62 } 63 64 static int 65 iic_print(void *aux, const char *pnp) 66 { 67 struct i2c_attach_args *ia = aux; 68 69 if (ia->ia_addr != (i2c_addr_t)-1) 70 aprint_normal(" addr 0x%x", ia->ia_addr); 71 72 return (UNCONF); 73 } 74 75 static int 76 iic_search(struct device *parent, struct cfdata *cf, 77 const int *ldesc, void *aux) 78 { 79 struct iic_softc *sc = (void *) parent; 80 struct i2c_attach_args ia; 81 82 ia.ia_tag = sc->sc_tag; 83 ia.ia_addr = cf->cf_loc[IICCF_ADDR]; 84 ia.ia_size = cf->cf_loc[IICCF_SIZE]; 85 ia.ia_type = sc->sc_type; 86 87 if (config_match(parent, cf, &ia) > 0) 88 config_attach(parent, cf, &ia, iic_print); 89 90 return (0); 91 } 92 93 static int 94 iic_match(struct device *parent, struct cfdata *cf, void *aux) 95 { 96 97 return (1); 98 } 99 100 static void 101 iic_attach(struct device *parent, struct device *self, void *aux) 102 { 103 struct iic_softc *sc = device_private(self); 104 struct i2cbus_attach_args *iba = aux; 105 106 aprint_naive(": I2C bus\n"); 107 aprint_normal(": I2C bus\n"); 108 109 sc->sc_tag = iba->iba_tag; 110 sc->sc_type = iba->iba_type; 111 112 /* 113 * Attach all i2c devices described in the kernel 114 * configuration file. 115 */ 116 config_search_ia(iic_search, self, "iic", NULL); 117 } 118 119 CFATTACH_DECL(iic, sizeof(struct iic_softc), 120 iic_match, iic_attach, NULL, NULL); 121