[BACK]Return to i2c.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / dev / i2c

Annotation of src/sys/dev/i2c/i2c.c, Revision 1.2.2.2

1.2.2.2 ! skrll       1: /*     $NetBSD: i2c.c,v 1.2.2.1 2004/08/03 10:46:05 skrll 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: };
        !            52:
        !            53: int
        !            54: iicbus_print(void *aux, const char *pnp)
        !            55: {
        !            56:        struct i2cbus_attach_args *iba = aux;
        !            57:
        !            58:        if (pnp != NULL)
        !            59:                aprint_normal("%s at %s", iba->iba_name, 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:        aprint_normal(" addr 0x%x", ia->ia_addr);
        !            70:
        !            71:        return (UNCONF);
        !            72: }
        !            73:
        !            74: static int
        !            75: iic_search(struct device *parent, struct cfdata *cf, void *aux)
        !            76: {
        !            77:        struct iic_softc *sc = (void *) parent;
        !            78:        struct i2c_attach_args ia;
        !            79:
        !            80:        ia.ia_tag = sc->sc_tag;
        !            81:        ia.ia_addr = cf->cf_loc[IICCF_ADDR];
        !            82:        ia.ia_size = cf->cf_loc[IICCF_SIZE];
        !            83:
        !            84:        if (config_match(parent, cf, &ia) > 0)
        !            85:                config_attach(parent, cf, &ia, iic_print);
        !            86:
        !            87:        return (0);
        !            88: }
        !            89:
        !            90: static int
        !            91: iic_match(struct device *parent, struct cfdata *cf, void *aux)
        !            92: {
        !            93:        struct i2cbus_attach_args *iba = aux;
        !            94:
        !            95:        /* Just make sure we're looking for i2c. */
        !            96:        return (strcmp(iba->iba_name, cf->cf_name) == 0);
        !            97: }
        !            98:
        !            99: static void
        !           100: iic_attach(struct device *parent, struct device *self, void *aux)
        !           101: {
        !           102:        struct iic_softc *sc = (void *) self;
        !           103:        struct i2cbus_attach_args *iba = aux;
        !           104:
        !           105:        aprint_naive(": I2C bus\n");
        !           106:        aprint_normal(": I2C bus\n");
        !           107:
        !           108:        sc->sc_tag = iba->iba_tag;
        !           109:
        !           110:        /*
        !           111:         * Attach all i2c devices described in the kernel
        !           112:         * configuration file.
        !           113:         */
        !           114:        config_search(iic_search, self, NULL);
        !           115: }
        !           116:
        !           117: CFATTACH_DECL(iic, sizeof(struct iic_softc),
        !           118:     iic_match, iic_attach, NULL, NULL);

CVSweb <webmaster@jp.NetBSD.org>