Deleted Added
full compact
iicbus.c (87599) iicbus.c (93023)
1/*-
1/*-
2 * Copyright (c) 1998 Nicolas Souchu
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
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright

--- 7 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
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 *
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
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright

--- 7 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
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 * $FreeBSD: head/sys/dev/iicbus/iicbus.c 87599 2001-12-10 08:09:49Z obrien $
26 * $FreeBSD: head/sys/dev/iicbus/iicbus.c 93023 2002-03-23 15:49:15Z nsouch $
27 *
28 */
29
30/*
31 * Autoconfiguration and support routines for the Philips serial I2C bus
32 */
33
34#include <sys/param.h>

--- 5 unchanged lines hidden (view full) ---

40
41#include <dev/iicbus/iiconf.h>
42#include <dev/iicbus/iicbus.h>
43
44#include "iicbus_if.h"
45
46#define DEVTOIICBUS(dev) ((struct iicbus_device*)device_get_ivars(dev))
47
27 *
28 */
29
30/*
31 * Autoconfiguration and support routines for the Philips serial I2C bus
32 */
33
34#include <sys/param.h>

--- 5 unchanged lines hidden (view full) ---

40
41#include <dev/iicbus/iiconf.h>
42#include <dev/iicbus/iicbus.h>
43
44#include "iicbus_if.h"
45
46#define DEVTOIICBUS(dev) ((struct iicbus_device*)device_get_ivars(dev))
47
48/*
49 * structure used to attach devices to the I2C bus
50 */
51struct iicbus_device {
52 const char *iicd_name; /* device name */
53 int iicd_class; /* driver or slave device class */
54 const char *iicd_desc; /* device descriptor */
55 u_char iicd_addr; /* address of the device */
56 int iicd_waitack; /* wait for ack timeout or delay */
57 int iicd_alive; /* 1 if device found */
58};
59
60/*
61 * Common I2C addresses
62 */
63#define I2C_GENERAL_CALL 0x0
64#define PCF_MASTER_ADDRESS 0xaa
65#define FIRST_SLAVE_ADDR 0x2
66
67#define LAST_SLAVE_ADDR 255
68
69#define IICBUS_UNKNOWN_CLASS 0
70#define IICBUS_DEVICE_CLASS 1
71#define IICBUS_DRIVER_CLASS 2
72
73/*
74 * list of known devices
75 *
76 * XXX only one smb driver should exist for each I2C interface
77 */
78static struct iicbus_device iicbus_children[] = {
79 { "iicsmb", IICBUS_DRIVER_CLASS, "I2C to SMB bridge" },
80 { "iic", IICBUS_DRIVER_CLASS, "I2C general purpose I/O" },
81#if 0
82 { "ic", IICBUS_DEVICE_CLASS, "network interface", PCF_MASTER_ADDRESS },
83#endif
84 { NULL, 0 }
85};
86
87static devclass_t iicbus_devclass;
88
89/*
90 * Device methods
91 */
92static int iicbus_probe(device_t);
93static int iicbus_attach(device_t);
48static devclass_t iicbus_devclass;
49
50/*
51 * Device methods
52 */
53static int iicbus_probe(device_t);
54static int iicbus_attach(device_t);
94static int iicbus_print_child(device_t, device_t);
95static int iicbus_read_ivar(device_t , device_t, int, u_long *);
96static int iicbus_write_ivar(device_t , device_t, int, u_long);
55static int iicbus_detach(device_t);
56static int iicbus_add_child(device_t dev, int order, const char *name, int unit);
97
98static device_method_t iicbus_methods[] = {
99 /* device interface */
100 DEVMETHOD(device_probe, iicbus_probe),
101 DEVMETHOD(device_attach, iicbus_attach),
57
58static device_method_t iicbus_methods[] = {
59 /* device interface */
60 DEVMETHOD(device_probe, iicbus_probe),
61 DEVMETHOD(device_attach, iicbus_attach),
102 DEVMETHOD(device_detach, bus_generic_detach),
103 DEVMETHOD(device_shutdown, bus_generic_shutdown),
62 DEVMETHOD(device_detach, iicbus_detach),
104
105 /* bus interface */
63
64 /* bus interface */
106 DEVMETHOD(bus_print_child, iicbus_print_child),
107 DEVMETHOD(bus_read_ivar, iicbus_read_ivar),
108 DEVMETHOD(bus_write_ivar, iicbus_write_ivar),
65 DEVMETHOD(bus_add_child, iicbus_add_child),
66 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
67 DEVMETHOD(bus_print_child, bus_generic_print_child),
109
110 { 0, 0 }
111};
112
113static driver_t iicbus_driver = {
114 "iicbus",
115 iicbus_methods,
116 sizeof(struct iicbus_softc),

--- 32 unchanged lines hidden (view full) ---

149
150/*
151 * We add all the devices which we know about.
152 * The generic attach routine will attach them if they are alive.
153 */
154static int
155iicbus_attach(device_t dev)
156{
68
69 { 0, 0 }
70};
71
72static driver_t iicbus_driver = {
73 "iicbus",
74 iicbus_methods,
75 sizeof(struct iicbus_softc),

--- 32 unchanged lines hidden (view full) ---

108
109/*
110 * We add all the devices which we know about.
111 * The generic attach routine will attach them if they are alive.
112 */
113static int
114iicbus_attach(device_t dev)
115{
157 struct iicbus_device *iicdev;
158 device_t child;
159
160 iicbus_reset(dev, IIC_FASTEST, 0, NULL);
161
162 /* device probing is meaningless since the bus is supposed to be
163 * hot-plug. Moreover, some I2C chips do not appreciate random
164 * accesses like stop after start to fast, reads for less than
165 * x bytes...
166 */
167#if 0
168 printf("Probing for devices on iicbus%d:", device_get_unit(dev));
169
170 /* probe any devices */
171 for (addr = FIRST_SLAVE_ADDR; addr <= LAST_SLAVE_ADDR; addr++) {
172 if (iic_probe_device(dev, (u_char)addr)) {
173 printf(" <%x>", addr);
174 }
175 }
176 printf("\n");
177#endif
116 iicbus_reset(dev, IIC_FASTEST, 0, NULL);
117
118 /* device probing is meaningless since the bus is supposed to be
119 * hot-plug. Moreover, some I2C chips do not appreciate random
120 * accesses like stop after start to fast, reads for less than
121 * x bytes...
122 */
123#if 0
124 printf("Probing for devices on iicbus%d:", device_get_unit(dev));
125
126 /* probe any devices */
127 for (addr = FIRST_SLAVE_ADDR; addr <= LAST_SLAVE_ADDR; addr++) {
128 if (iic_probe_device(dev, (u_char)addr)) {
129 printf(" <%x>", addr);
130 }
131 }
132 printf("\n");
133#endif
134
135 /* attach any known device */
136 device_add_child(dev, NULL, -1);
178
137
179 /* attach known devices */
180 for (iicdev = iicbus_children; iicdev->iicd_name; iicdev++) {
181 switch (iicdev->iicd_class) {
182 case IICBUS_DEVICE_CLASS:
183 /* check if the devclass exists */
184 if (devclass_find(iicdev->iicd_name))
185 iicdev->iicd_alive = 1;
186 else if (bootverbose)
187 printf("iicbus: %s devclass not found\n",
188 iicdev->iicd_name);
189 break;
190
191 case IICBUS_DRIVER_CLASS:
192 /* check if the devclass exists */
193 if (devclass_find(iicdev->iicd_name))
194 iicdev->iicd_alive = 1;
195 else if (bootverbose)
196 printf("iicbus: %s devclass not found\n",
197 iicdev->iicd_name);
198 break;
199
200 default:
201 panic("%s: unknown class!", __func__);
202 }
203
204 if (iicdev->iicd_alive) {
205 child = device_add_child(dev, iicdev->iicd_name, -1);
206 device_set_ivars(child, iicdev);
207 device_set_desc(child, iicdev->iicd_desc);
208 }
209 }
210 bus_generic_attach(dev);
211
212 return (0);
213}
138 bus_generic_attach(dev);
139
140 return (0);
141}
142
143static int
144iicbus_detach(device_t dev)
145{
146 iicbus_reset(dev, IIC_FASTEST, 0, NULL);
147
148 bus_generic_detach(dev);
149
150 return (0);
151}
152
153static int
154iicbus_add_child(device_t dev, int order, const char *name, int unit)
155{
156 device_add_child_ordered(dev, order, name, unit);
214
157
158 bus_generic_attach(dev);
159
160 return (0);
161}
162
215int
216iicbus_generic_intr(device_t dev, int event, char *buf)
217{
218 return (0);
219}
220
221int
222iicbus_null_callback(device_t dev, int index, caddr_t data)
223{
224 return (0);
225}
226
227int
228iicbus_null_repeated_start(device_t dev, u_char addr)
229{
230 return (IIC_ENOTSUPP);
231}
232
163int
164iicbus_generic_intr(device_t dev, int event, char *buf)
165{
166 return (0);
167}
168
169int
170iicbus_null_callback(device_t dev, int index, caddr_t data)
171{
172 return (0);
173}
174
175int
176iicbus_null_repeated_start(device_t dev, u_char addr)
177{
178 return (IIC_ENOTSUPP);
179}
180
233static int
234iicbus_print_child(device_t bus, device_t dev)
235{
236 struct iicbus_device* iicdev = DEVTOIICBUS(dev);
237 int retval = 0;
238
239 retval += bus_print_child_header(bus, dev);
240
241 switch (iicdev->iicd_class) {
242 case IICBUS_DEVICE_CLASS:
243 retval += printf(" on %s addr 0x%x\n",
244 device_get_nameunit(bus), iicdev->iicd_addr);
245 break;
246
247 case IICBUS_DRIVER_CLASS:
248 retval += bus_print_child_footer(bus, dev);
249 break;
250
251 default:
252 panic("%s: unknown class!", __func__);
253 }
254
255 return (retval);
256}
257
258static int
259iicbus_read_ivar(device_t bus, device_t dev, int index, u_long* result)
260{
261 struct iicbus_device* iicdev = DEVTOIICBUS(dev);
262
263 switch (index) {
264 case IICBUS_IVAR_ADDR:
265 *result = (u_long)iicdev->iicd_addr;
266 break;
267
268 default:
269 return (ENOENT);
270 }
271
272 return (0);
273}
274
275static int
276iicbus_write_ivar(device_t bus, device_t dev, int index, u_long val)
277{
278 switch (index) {
279 default:
280 return (ENOENT);
281 }
282
283 return (0);
284}
285
286DRIVER_MODULE(iicbus, pcf, iicbus_driver, iicbus_devclass, 0, 0);
287DRIVER_MODULE(iicbus, iicbb, iicbus_driver, iicbus_devclass, 0, 0);
288DRIVER_MODULE(iicbus, bti2c, iicbus_driver, iicbus_devclass, 0, 0);
181DRIVER_MODULE(iicbus, pcf, iicbus_driver, iicbus_devclass, 0, 0);
182DRIVER_MODULE(iicbus, iicbb, iicbus_driver, iicbus_devclass, 0, 0);
183DRIVER_MODULE(iicbus, bti2c, iicbus_driver, iicbus_devclass, 0, 0);
184MODULE_VERSION(iicbus, IICBUS_MODVER);