i2c.c revision 1.3 1 /* $NetBSD: i2c.c,v 1.3 2004/09/13 12:55:47 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 };
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,
76 const locdesc_t *ldesc, void *aux)
77 {
78 struct iic_softc *sc = (void *) parent;
79 struct i2c_attach_args ia;
80
81 ia.ia_tag = sc->sc_tag;
82 ia.ia_addr = cf->cf_loc[IICCF_ADDR];
83 ia.ia_size = cf->cf_loc[IICCF_SIZE];
84
85 if (config_match(parent, cf, &ia) > 0)
86 config_attach(parent, cf, &ia, iic_print);
87
88 return (0);
89 }
90
91 static int
92 iic_match(struct device *parent, struct cfdata *cf, void *aux)
93 {
94 struct i2cbus_attach_args *iba = aux;
95
96 /* Just make sure we're looking for i2c. */
97 return (strcmp(iba->iba_name, cf->cf_name) == 0);
98 }
99
100 static void
101 iic_attach(struct device *parent, struct device *self, void *aux)
102 {
103 struct iic_softc *sc = (void *) 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
111 /*
112 * Attach all i2c devices described in the kernel
113 * configuration file.
114 */
115 config_search_ia(iic_search, self, "iic", NULL);
116 }
117
118 CFATTACH_DECL(iic, sizeof(struct iic_softc),
119 iic_match, iic_attach, NULL, NULL);
120