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.6 1998/12/07 21:58:16 archie 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 * 77 * XXX only one smb driver should exist for each I2C interface |
78 */ 79struct iicbus_device iicbus_children[] = { 80 { "iicsmb", IICBUS_DRIVER_CLASS, "I2C to SMB bridge" }, |
81 { "iic", IICBUS_DRIVER_CLASS, "I2C general purpose I/O" }, |
82#if 0 |
83 { "ic", IICBUS_DEVICE_CLASS, "network interface", PCF_MASTER_ADDRESS }, |
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 device_set_desc(dev, "Philips I2C bus"); 125 |
126 return (0); 127} 128 |
129#if 0 |
130static int 131iic_probe_device(device_t dev, u_char addr) 132{ 133 int count; 134 char byte; 135 136 if ((addr & 1) == 0) { 137 /* is device writable? */ --- 4 unchanged lines hidden (view full) --- 142 } else { 143 /* is device readable? */ 144 if (!iicbus_block_read(dev, (u_char)addr, &byte, 1, &count)) 145 return (1); 146 } 147 148 return (0); 149} |
150#endif |
151 152/* 153 * We add all the devices which we know about. 154 * The generic attach routine will attach them if they are alive. 155 */ 156static int 157iicbus_attach(device_t dev) 158{ 159 struct iicbus_device *iicdev; 160 device_t child; |
161 162 iicbus_reset(dev, IIC_FASTEST, 0, NULL); 163 |
164 /* device probing is meaningless since the bus is supposed to be 165 * hot-plug. Moreover, some I2C chips do not appreciate random 166 * accesses like stop after start to fast, reads for less than 167 * x bytes... 168 */ 169#if 0 |
170 printf("Probing for devices on iicbus%d:", device_get_unit(dev)); 171 172 /* probe any devices */ 173 for (addr = FIRST_SLAVE_ADDR; addr <= LAST_SLAVE_ADDR; addr++) { 174 if (iic_probe_device(dev, (u_char)addr)) { 175 printf(" <%x>", addr); 176 } 177 } 178 printf("\n"); |
179#endif |
180 181 /* attach known devices */ 182 for (iicdev = iicbus_children; iicdev->iicd_name; iicdev++) { 183 switch (iicdev->iicd_class) { 184 case IICBUS_DEVICE_CLASS: 185 /* check if the devclass exists */ |
186 if (devclass_find(iicdev->iicd_name)) |
187 iicdev->iicd_alive = 1; |
188 else if (bootverbose) 189 printf("iicbus: %s devclass not found\n", 190 iicdev->iicd_name); |
191 break; 192 193 case IICBUS_DRIVER_CLASS: 194 /* check if the devclass exists */ |
195 if (devclass_find(iicdev->iicd_name)) |
196 iicdev->iicd_alive = 1; |
197 else if (bootverbose) 198 printf("iicbus: %s devclass not found\n", 199 iicdev->iicd_name); |
200 break; 201 202 default: 203 panic("%s: unknown class!", __FUNCTION__); 204 } 205 206 if (iicdev->iicd_alive) { 207 child = device_add_child(dev, iicdev->iicd_name, --- 73 unchanged lines hidden (view full) --- 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); |