Deleted Added
sdiff udiff text old ( 41591 ) new ( 42442 )
full compact
1/*-
2 * Copyright (c) 1998 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 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 * $Id: iicbus.c,v 1.5 1998/11/22 22:01:42 nsouch Exp $
27 *
28 */
29
30/*
31 * Autoconfiguration and support routines for the Philips serial I2C bus
32 */
33
34#include <sys/param.h>

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

68#define LAST_SLAVE_ADDR 255
69
70#define IICBUS_UNKNOWN_CLASS 0
71#define IICBUS_DEVICE_CLASS 1
72#define IICBUS_DRIVER_CLASS 2
73
74/*
75 * list of known devices
76 */
77struct iicbus_device iicbus_children[] = {
78 { "iicsmb", IICBUS_DRIVER_CLASS, "I2C to SMB bridge" },
79 { "iic", IICBUS_DEVICE_CLASS, "PCF8574 I2C to 8 bits parallel i/o", 64},
80 { "iic", IICBUS_DEVICE_CLASS, "PCF8584 as slave", PCF_MASTER_ADDRESS },
81 { "ic", IICBUS_DEVICE_CLASS, "network interface", PCF_MASTER_ADDRESS },
82#if 0
83 { "iic", IICBUS_DRIVER_CLASS, "General Call", I2C_GENERAL_CALL },
84#endif
85 { NULL, 0 }
86};
87
88static devclass_t iicbus_devclass;
89
90/*
91 * Device methods

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

116 iicbus_methods,
117 DRIVER_TYPE_MISC,
118 sizeof(struct iicbus_softc),
119};
120
121static int
122iicbus_probe(device_t dev)
123{
124 /* always present if probed */
125 return (0);
126}
127
128static int
129iic_probe_device(device_t dev, u_char addr)
130{
131 int count;
132 char byte;
133
134 if ((addr & 1) == 0) {
135 /* is device writable? */

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

140 } else {
141 /* is device readable? */
142 if (!iicbus_block_read(dev, (u_char)addr, &byte, 1, &count))
143 return (1);
144 }
145
146 return (0);
147}
148
149/*
150 * We add all the devices which we know about.
151 * The generic attach routine will attach them if they are alive.
152 */
153static int
154iicbus_attach(device_t dev)
155{
156 struct iicbus_device *iicdev;
157 device_t child;
158 int addr;
159
160 iicbus_reset(dev, IIC_FASTEST, 0, NULL);
161
162 printf("Probing for devices on iicbus%d:", device_get_unit(dev));
163
164 /* probe any devices */
165 for (addr = FIRST_SLAVE_ADDR; addr <= LAST_SLAVE_ADDR; addr++) {
166 if (iic_probe_device(dev, (u_char)addr)) {
167 printf(" <%x>", addr);
168 }
169 }
170 printf("\n");
171
172 /* attach known devices */
173 for (iicdev = iicbus_children; iicdev->iicd_name; iicdev++) {
174 switch (iicdev->iicd_class) {
175 case IICBUS_DEVICE_CLASS:
176 /* check if the devclass exists */
177 if (devclass_find(iicdev->iicd_name) &&
178 iic_probe_device(dev, iicdev->iicd_addr))
179 iicdev->iicd_alive = 1;
180 break;
181
182 case IICBUS_DRIVER_CLASS:
183 /* check if the devclass exists */
184 if (!devclass_find(iicdev->iicd_name))
185 iicdev->iicd_alive = 1;
186 break;
187
188 default:
189 panic("%s: unknown class!", __FUNCTION__);
190 }
191
192 if (iicdev->iicd_alive) {
193 child = device_add_child(dev, iicdev->iicd_name,

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

267 }
268
269 return (0);
270}
271
272DRIVER_MODULE(iicbus, pcf, iicbus_driver, iicbus_devclass, 0, 0);
273DRIVER_MODULE(iicbus, iicbb, iicbus_driver, iicbus_devclass, 0, 0);
274DRIVER_MODULE(iicbus, bti2c, iicbus_driver, iicbus_devclass, 0, 0);
275DRIVER_MODULE(iicbus, smbtx, iicbus_driver, iicbus_devclass, 0, 0);