| 1 |
1275 |
phoenix |
/* i2c-core.c - a device driver for the iic-bus interface */
|
| 2 |
|
|
/* ------------------------------------------------------------------------- */
|
| 3 |
|
|
/* Copyright (C) 1995-99 Simon G. Vogl
|
| 4 |
|
|
|
| 5 |
|
|
This program is free software; you can redistribute it and/or modify
|
| 6 |
|
|
it under the terms of the GNU General Public License as published by
|
| 7 |
|
|
the Free Software Foundation; either version 2 of the License, or
|
| 8 |
|
|
(at your option) any later version.
|
| 9 |
|
|
|
| 10 |
|
|
This program is distributed in the hope that it will be useful,
|
| 11 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
|
|
GNU General Public License for more details.
|
| 14 |
|
|
|
| 15 |
|
|
You should have received a copy of the GNU General Public License
|
| 16 |
|
|
along with this program; if not, write to the Free Software
|
| 17 |
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
| 18 |
|
|
/* ------------------------------------------------------------------------- */
|
| 19 |
|
|
|
| 20 |
|
|
/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi>.
|
| 21 |
|
|
All SMBus-related things are written by Frodo Looijaard <frodol@dds.nl> */
|
| 22 |
|
|
|
| 23 |
|
|
/* $Id: i2c-core.c,v 1.1.1.1 2004-04-15 01:38:25 phoenix Exp $ */
|
| 24 |
|
|
|
| 25 |
|
|
#include <linux/module.h>
|
| 26 |
|
|
#include <linux/kernel.h>
|
| 27 |
|
|
#include <linux/errno.h>
|
| 28 |
|
|
#include <linux/slab.h>
|
| 29 |
|
|
#include <linux/proc_fs.h>
|
| 30 |
|
|
#include <linux/config.h>
|
| 31 |
|
|
|
| 32 |
|
|
#include <linux/i2c.h>
|
| 33 |
|
|
|
| 34 |
|
|
/* ----- compatibility stuff ----------------------------------------------- */
|
| 35 |
|
|
|
| 36 |
|
|
#include <linux/init.h>
|
| 37 |
|
|
|
| 38 |
|
|
#include <asm/uaccess.h>
|
| 39 |
|
|
|
| 40 |
|
|
/* ----- global defines ---------------------------------------------------- */
|
| 41 |
|
|
|
| 42 |
|
|
/* exclusive access to the bus */
|
| 43 |
|
|
#define I2C_LOCK(adap) down(&adap->lock)
|
| 44 |
|
|
#define I2C_UNLOCK(adap) up(&adap->lock)
|
| 45 |
|
|
|
| 46 |
|
|
#define ADAP_LOCK() down(&adap_lock)
|
| 47 |
|
|
#define ADAP_UNLOCK() up(&adap_lock)
|
| 48 |
|
|
|
| 49 |
|
|
#define DRV_LOCK() down(&driver_lock)
|
| 50 |
|
|
#define DRV_UNLOCK() up(&driver_lock)
|
| 51 |
|
|
|
| 52 |
|
|
#define DEB(x) if (i2c_debug>=1) x;
|
| 53 |
|
|
#define DEB2(x) if (i2c_debug>=2) x;
|
| 54 |
|
|
|
| 55 |
|
|
/* ----- global variables -------------------------------------------------- */
|
| 56 |
|
|
|
| 57 |
|
|
/**** lock for writing to global variables: the adapter & driver list */
|
| 58 |
|
|
struct semaphore adap_lock;
|
| 59 |
|
|
struct semaphore driver_lock;
|
| 60 |
|
|
|
| 61 |
|
|
/**** adapter list */
|
| 62 |
|
|
static struct i2c_adapter *adapters[I2C_ADAP_MAX];
|
| 63 |
|
|
static int adap_count;
|
| 64 |
|
|
|
| 65 |
|
|
/**** drivers list */
|
| 66 |
|
|
static struct i2c_driver *drivers[I2C_DRIVER_MAX];
|
| 67 |
|
|
static int driver_count;
|
| 68 |
|
|
|
| 69 |
|
|
/**** debug level */
|
| 70 |
|
|
static int i2c_debug=1;
|
| 71 |
|
|
|
| 72 |
|
|
/* ---------------------------------------------------
|
| 73 |
|
|
* /proc entry declarations
|
| 74 |
|
|
*----------------------------------------------------
|
| 75 |
|
|
*/
|
| 76 |
|
|
|
| 77 |
|
|
#ifdef CONFIG_PROC_FS
|
| 78 |
|
|
|
| 79 |
|
|
static int i2cproc_init(void);
|
| 80 |
|
|
static int i2cproc_cleanup(void);
|
| 81 |
|
|
|
| 82 |
|
|
static ssize_t i2cproc_bus_read(struct file * file, char * buf,size_t count,
|
| 83 |
|
|
loff_t *ppos);
|
| 84 |
|
|
static int read_bus_i2c(char *buf, char **start, off_t offset, int len,
|
| 85 |
|
|
int *eof , void *private);
|
| 86 |
|
|
|
| 87 |
|
|
/* To implement the dynamic /proc/bus/i2c-? files, we need our own
|
| 88 |
|
|
implementation of the read hook */
|
| 89 |
|
|
static struct file_operations i2cproc_operations = {
|
| 90 |
|
|
read: i2cproc_bus_read,
|
| 91 |
|
|
};
|
| 92 |
|
|
|
| 93 |
|
|
static int i2cproc_initialized = 0;
|
| 94 |
|
|
|
| 95 |
|
|
#else /* undef CONFIG_PROC_FS */
|
| 96 |
|
|
|
| 97 |
|
|
#define i2cproc_init() 0
|
| 98 |
|
|
#define i2cproc_cleanup() 0
|
| 99 |
|
|
|
| 100 |
|
|
#endif /* CONFIG_PROC_FS */
|
| 101 |
|
|
|
| 102 |
|
|
|
| 103 |
|
|
/* ---------------------------------------------------
|
| 104 |
|
|
* registering functions
|
| 105 |
|
|
* ---------------------------------------------------
|
| 106 |
|
|
*/
|
| 107 |
|
|
|
| 108 |
|
|
/* -----
|
| 109 |
|
|
* i2c_add_adapter is called from within the algorithm layer,
|
| 110 |
|
|
* when a new hw adapter registers. A new device is register to be
|
| 111 |
|
|
* available for clients.
|
| 112 |
|
|
*/
|
| 113 |
|
|
int i2c_add_adapter(struct i2c_adapter *adap)
|
| 114 |
|
|
{
|
| 115 |
|
|
int i,j,res;
|
| 116 |
|
|
|
| 117 |
|
|
ADAP_LOCK();
|
| 118 |
|
|
for (i = 0; i < I2C_ADAP_MAX; i++)
|
| 119 |
|
|
if (NULL == adapters[i])
|
| 120 |
|
|
break;
|
| 121 |
|
|
if (I2C_ADAP_MAX == i) {
|
| 122 |
|
|
printk(KERN_WARNING
|
| 123 |
|
|
" i2c-core.o: register_adapter(%s) - enlarge I2C_ADAP_MAX.\n",
|
| 124 |
|
|
adap->name);
|
| 125 |
|
|
res = -ENOMEM;
|
| 126 |
|
|
goto ERROR0;
|
| 127 |
|
|
}
|
| 128 |
|
|
|
| 129 |
|
|
adapters[i] = adap;
|
| 130 |
|
|
adap_count++;
|
| 131 |
|
|
ADAP_UNLOCK();
|
| 132 |
|
|
|
| 133 |
|
|
/* init data types */
|
| 134 |
|
|
init_MUTEX(&adap->lock);
|
| 135 |
|
|
|
| 136 |
|
|
#ifdef CONFIG_PROC_FS
|
| 137 |
|
|
|
| 138 |
|
|
if (i2cproc_initialized) {
|
| 139 |
|
|
char name[8];
|
| 140 |
|
|
struct proc_dir_entry *proc_entry;
|
| 141 |
|
|
|
| 142 |
|
|
sprintf(name,"i2c-%d", i);
|
| 143 |
|
|
|
| 144 |
|
|
proc_entry = create_proc_entry(name,0,proc_bus);
|
| 145 |
|
|
if (! proc_entry) {
|
| 146 |
|
|
printk("i2c-core.o: Could not create /proc/bus/%s\n",
|
| 147 |
|
|
name);
|
| 148 |
|
|
res = -ENOENT;
|
| 149 |
|
|
goto ERROR1;
|
| 150 |
|
|
}
|
| 151 |
|
|
|
| 152 |
|
|
proc_entry->proc_fops = &i2cproc_operations;
|
| 153 |
|
|
proc_entry->owner = THIS_MODULE;
|
| 154 |
|
|
adap->inode = proc_entry->low_ino;
|
| 155 |
|
|
}
|
| 156 |
|
|
|
| 157 |
|
|
#endif /* def CONFIG_PROC_FS */
|
| 158 |
|
|
|
| 159 |
|
|
/* inform drivers of new adapters */
|
| 160 |
|
|
DRV_LOCK();
|
| 161 |
|
|
for (j=0;j<I2C_DRIVER_MAX;j++)
|
| 162 |
|
|
if (drivers[j]!=NULL &&
|
| 163 |
|
|
(drivers[j]->flags&(I2C_DF_NOTIFY|I2C_DF_DUMMY)))
|
| 164 |
|
|
/* We ignore the return code; if it fails, too bad */
|
| 165 |
|
|
drivers[j]->attach_adapter(adap);
|
| 166 |
|
|
DRV_UNLOCK();
|
| 167 |
|
|
|
| 168 |
|
|
DEB(printk(KERN_DEBUG "i2c-core.o: adapter %s registered as adapter %d.\n",
|
| 169 |
|
|
adap->name,i));
|
| 170 |
|
|
|
| 171 |
|
|
return 0;
|
| 172 |
|
|
|
| 173 |
|
|
|
| 174 |
|
|
ERROR1:
|
| 175 |
|
|
ADAP_LOCK();
|
| 176 |
|
|
adapters[i] = NULL;
|
| 177 |
|
|
adap_count--;
|
| 178 |
|
|
ERROR0:
|
| 179 |
|
|
ADAP_UNLOCK();
|
| 180 |
|
|
return res;
|
| 181 |
|
|
}
|
| 182 |
|
|
|
| 183 |
|
|
|
| 184 |
|
|
int i2c_del_adapter(struct i2c_adapter *adap)
|
| 185 |
|
|
{
|
| 186 |
|
|
int i,j,res;
|
| 187 |
|
|
|
| 188 |
|
|
ADAP_LOCK();
|
| 189 |
|
|
|
| 190 |
|
|
for (i = 0; i < I2C_ADAP_MAX; i++)
|
| 191 |
|
|
if (adap == adapters[i])
|
| 192 |
|
|
break;
|
| 193 |
|
|
if (I2C_ADAP_MAX == i) {
|
| 194 |
|
|
printk(KERN_WARNING "i2c-core.o: unregister_adapter adap [%s] not found.\n",
|
| 195 |
|
|
adap->name);
|
| 196 |
|
|
res = -ENODEV;
|
| 197 |
|
|
goto ERROR0;
|
| 198 |
|
|
}
|
| 199 |
|
|
|
| 200 |
|
|
/* DUMMY drivers do not register their clients, so we have to
|
| 201 |
|
|
* use a trick here: we call driver->attach_adapter to
|
| 202 |
|
|
* *detach* it! Of course, each dummy driver should know about
|
| 203 |
|
|
* this or hell will break loose...
|
| 204 |
|
|
*/
|
| 205 |
|
|
DRV_LOCK();
|
| 206 |
|
|
for (j = 0; j < I2C_DRIVER_MAX; j++)
|
| 207 |
|
|
if (drivers[j] && (drivers[j]->flags & I2C_DF_DUMMY))
|
| 208 |
|
|
if ((res = drivers[j]->attach_adapter(adap))) {
|
| 209 |
|
|
printk(KERN_WARNING "i2c-core.o: can't detach adapter %s "
|
| 210 |
|
|
"while detaching driver %s: driver not "
|
| 211 |
|
|
"detached!",adap->name,drivers[j]->name);
|
| 212 |
|
|
goto ERROR1;
|
| 213 |
|
|
}
|
| 214 |
|
|
DRV_UNLOCK();
|
| 215 |
|
|
|
| 216 |
|
|
|
| 217 |
|
|
/* detach any active clients. This must be done first, because
|
| 218 |
|
|
* it can fail; in which case we give upp. */
|
| 219 |
|
|
for (j=0;j<I2C_CLIENT_MAX;j++) {
|
| 220 |
|
|
struct i2c_client *client = adap->clients[j];
|
| 221 |
|
|
if (client!=NULL)
|
| 222 |
|
|
/* detaching devices is unconditional of the set notify
|
| 223 |
|
|
* flag, as _all_ clients that reside on the adapter
|
| 224 |
|
|
* must be deleted, as this would cause invalid states.
|
| 225 |
|
|
*/
|
| 226 |
|
|
if ((res=client->driver->detach_client(client))) {
|
| 227 |
|
|
printk(KERN_ERR "i2c-core.o: adapter %s not "
|
| 228 |
|
|
"unregistered, because client at "
|
| 229 |
|
|
"address %02x can't be detached. ",
|
| 230 |
|
|
adap->name, client->addr);
|
| 231 |
|
|
goto ERROR0;
|
| 232 |
|
|
}
|
| 233 |
|
|
}
|
| 234 |
|
|
#ifdef CONFIG_PROC_FS
|
| 235 |
|
|
if (i2cproc_initialized) {
|
| 236 |
|
|
char name[8];
|
| 237 |
|
|
sprintf(name,"i2c-%d", i);
|
| 238 |
|
|
remove_proc_entry(name,proc_bus);
|
| 239 |
|
|
}
|
| 240 |
|
|
#endif /* def CONFIG_PROC_FS */
|
| 241 |
|
|
|
| 242 |
|
|
adapters[i] = NULL;
|
| 243 |
|
|
adap_count--;
|
| 244 |
|
|
|
| 245 |
|
|
ADAP_UNLOCK();
|
| 246 |
|
|
DEB(printk(KERN_DEBUG "i2c-core.o: adapter unregistered: %s\n",adap->name));
|
| 247 |
|
|
return 0;
|
| 248 |
|
|
|
| 249 |
|
|
ERROR0:
|
| 250 |
|
|
ADAP_UNLOCK();
|
| 251 |
|
|
return res;
|
| 252 |
|
|
ERROR1:
|
| 253 |
|
|
DRV_UNLOCK();
|
| 254 |
|
|
return res;
|
| 255 |
|
|
}
|
| 256 |
|
|
|
| 257 |
|
|
|
| 258 |
|
|
/* -----
|
| 259 |
|
|
* What follows is the "upwards" interface: commands for talking to clients,
|
| 260 |
|
|
* which implement the functions to access the physical information of the
|
| 261 |
|
|
* chips.
|
| 262 |
|
|
*/
|
| 263 |
|
|
|
| 264 |
|
|
int i2c_add_driver(struct i2c_driver *driver)
|
| 265 |
|
|
{
|
| 266 |
|
|
int i;
|
| 267 |
|
|
DRV_LOCK();
|
| 268 |
|
|
for (i = 0; i < I2C_DRIVER_MAX; i++)
|
| 269 |
|
|
if (NULL == drivers[i])
|
| 270 |
|
|
break;
|
| 271 |
|
|
if (I2C_DRIVER_MAX == i) {
|
| 272 |
|
|
printk(KERN_WARNING
|
| 273 |
|
|
" i2c-core.o: register_driver(%s) "
|
| 274 |
|
|
"- enlarge I2C_DRIVER_MAX.\n",
|
| 275 |
|
|
driver->name);
|
| 276 |
|
|
DRV_UNLOCK();
|
| 277 |
|
|
return -ENOMEM;
|
| 278 |
|
|
}
|
| 279 |
|
|
|
| 280 |
|
|
drivers[i] = driver;
|
| 281 |
|
|
driver_count++;
|
| 282 |
|
|
|
| 283 |
|
|
DRV_UNLOCK(); /* driver was successfully added */
|
| 284 |
|
|
|
| 285 |
|
|
DEB(printk(KERN_DEBUG "i2c-core.o: driver %s registered.\n",driver->name));
|
| 286 |
|
|
|
| 287 |
|
|
ADAP_LOCK();
|
| 288 |
|
|
|
| 289 |
|
|
/* now look for instances of driver on our adapters
|
| 290 |
|
|
*/
|
| 291 |
|
|
if (driver->flags& (I2C_DF_NOTIFY|I2C_DF_DUMMY)) {
|
| 292 |
|
|
for (i=0;i<I2C_ADAP_MAX;i++)
|
| 293 |
|
|
if (adapters[i]!=NULL)
|
| 294 |
|
|
/* Ignore errors */
|
| 295 |
|
|
driver->attach_adapter(adapters[i]);
|
| 296 |
|
|
}
|
| 297 |
|
|
ADAP_UNLOCK();
|
| 298 |
|
|
return 0;
|
| 299 |
|
|
}
|
| 300 |
|
|
|
| 301 |
|
|
int i2c_del_driver(struct i2c_driver *driver)
|
| 302 |
|
|
{
|
| 303 |
|
|
int i,j,k,res;
|
| 304 |
|
|
|
| 305 |
|
|
DRV_LOCK();
|
| 306 |
|
|
for (i = 0; i < I2C_DRIVER_MAX; i++)
|
| 307 |
|
|
if (driver == drivers[i])
|
| 308 |
|
|
break;
|
| 309 |
|
|
if (I2C_DRIVER_MAX == i) {
|
| 310 |
|
|
printk(KERN_WARNING " i2c-core.o: unregister_driver: "
|
| 311 |
|
|
"[%s] not found\n",
|
| 312 |
|
|
driver->name);
|
| 313 |
|
|
DRV_UNLOCK();
|
| 314 |
|
|
return -ENODEV;
|
| 315 |
|
|
}
|
| 316 |
|
|
/* Have a look at each adapter, if clients of this driver are still
|
| 317 |
|
|
* attached. If so, detach them to be able to kill the driver
|
| 318 |
|
|
* afterwards.
|
| 319 |
|
|
*/
|
| 320 |
|
|
DEB2(printk(KERN_DEBUG "i2c-core.o: unregister_driver - looking for clients.\n"));
|
| 321 |
|
|
/* removing clients does not depend on the notify flag, else
|
| 322 |
|
|
* invalid operation might (will!) result, when using stale client
|
| 323 |
|
|
* pointers.
|
| 324 |
|
|
*/
|
| 325 |
|
|
ADAP_LOCK(); /* should be moved inside the if statement... */
|
| 326 |
|
|
for (k=0;k<I2C_ADAP_MAX;k++) {
|
| 327 |
|
|
struct i2c_adapter *adap = adapters[k];
|
| 328 |
|
|
if (adap == NULL) /* skip empty entries. */
|
| 329 |
|
|
continue;
|
| 330 |
|
|
DEB2(printk(KERN_DEBUG "i2c-core.o: examining adapter %s:\n",
|
| 331 |
|
|
adap->name));
|
| 332 |
|
|
if (driver->flags & I2C_DF_DUMMY) {
|
| 333 |
|
|
/* DUMMY drivers do not register their clients, so we have to
|
| 334 |
|
|
* use a trick here: we call driver->attach_adapter to
|
| 335 |
|
|
* *detach* it! Of course, each dummy driver should know about
|
| 336 |
|
|
* this or hell will break loose...
|
| 337 |
|
|
*/
|
| 338 |
|
|
if ((res = driver->attach_adapter(adap))) {
|
| 339 |
|
|
printk(KERN_WARNING "i2c-core.o: while unregistering "
|
| 340 |
|
|
"dummy driver %s, adapter %s could "
|
| 341 |
|
|
"not be detached properly; driver "
|
| 342 |
|
|
"not unloaded!",driver->name,
|
| 343 |
|
|
adap->name);
|
| 344 |
|
|
ADAP_UNLOCK();
|
| 345 |
|
|
return res;
|
| 346 |
|
|
}
|
| 347 |
|
|
} else {
|
| 348 |
|
|
for (j=0;j<I2C_CLIENT_MAX;j++) {
|
| 349 |
|
|
struct i2c_client *client = adap->clients[j];
|
| 350 |
|
|
if (client != NULL &&
|
| 351 |
|
|
client->driver == driver) {
|
| 352 |
|
|
DEB2(printk(KERN_DEBUG "i2c-core.o: "
|
| 353 |
|
|
"detaching client %s:\n",
|
| 354 |
|
|
client->name));
|
| 355 |
|
|
if ((res = driver->
|
| 356 |
|
|
detach_client(client)))
|
| 357 |
|
|
{
|
| 358 |
|
|
printk(KERN_ERR "i2c-core.o: while "
|
| 359 |
|
|
"unregistering driver "
|
| 360 |
|
|
"`%s', the client at "
|
| 361 |
|
|
"address %02x of "
|
| 362 |
|
|
"adapter `%s' could not"
|
| 363 |
|
|
"be detached; driver"
|
| 364 |
|
|
"not unloaded!",
|
| 365 |
|
|
driver->name,
|
| 366 |
|
|
client->addr,
|
| 367 |
|
|
adap->name);
|
| 368 |
|
|
ADAP_UNLOCK();
|
| 369 |
|
|
return res;
|
| 370 |
|
|
}
|
| 371 |
|
|
}
|
| 372 |
|
|
}
|
| 373 |
|
|
}
|
| 374 |
|
|
}
|
| 375 |
|
|
ADAP_UNLOCK();
|
| 376 |
|
|
drivers[i] = NULL;
|
| 377 |
|
|
driver_count--;
|
| 378 |
|
|
DRV_UNLOCK();
|
| 379 |
|
|
|
| 380 |
|
|
DEB(printk(KERN_DEBUG "i2c-core.o: driver unregistered: %s\n",driver->name));
|
| 381 |
|
|
return 0;
|
| 382 |
|
|
}
|
| 383 |
|
|
|
| 384 |
|
|
int i2c_check_addr (struct i2c_adapter *adapter, int addr)
|
| 385 |
|
|
{
|
| 386 |
|
|
int i;
|
| 387 |
|
|
for (i = 0; i < I2C_CLIENT_MAX ; i++)
|
| 388 |
|
|
if (adapter->clients[i] && (adapter->clients[i]->addr == addr))
|
| 389 |
|
|
return -EBUSY;
|
| 390 |
|
|
return 0;
|
| 391 |
|
|
}
|
| 392 |
|
|
|
| 393 |
|
|
int i2c_attach_client(struct i2c_client *client)
|
| 394 |
|
|
{
|
| 395 |
|
|
struct i2c_adapter *adapter = client->adapter;
|
| 396 |
|
|
int i;
|
| 397 |
|
|
|
| 398 |
|
|
if (i2c_check_addr(client->adapter,client->addr))
|
| 399 |
|
|
return -EBUSY;
|
| 400 |
|
|
|
| 401 |
|
|
for (i = 0; i < I2C_CLIENT_MAX; i++)
|
| 402 |
|
|
if (NULL == adapter->clients[i])
|
| 403 |
|
|
break;
|
| 404 |
|
|
if (I2C_CLIENT_MAX == i) {
|
| 405 |
|
|
printk(KERN_WARNING
|
| 406 |
|
|
" i2c-core.o: attach_client(%s) - enlarge I2C_CLIENT_MAX.\n",
|
| 407 |
|
|
client->name);
|
| 408 |
|
|
return -ENOMEM;
|
| 409 |
|
|
}
|
| 410 |
|
|
|
| 411 |
|
|
adapter->clients[i] = client;
|
| 412 |
|
|
adapter->client_count++;
|
| 413 |
|
|
|
| 414 |
|
|
if (adapter->client_register)
|
| 415 |
|
|
if (adapter->client_register(client))
|
| 416 |
|
|
printk(KERN_DEBUG "i2c-core.o: warning: client_register seems "
|
| 417 |
|
|
"to have failed for client %02x at adapter %s\n",
|
| 418 |
|
|
client->addr,adapter->name);
|
| 419 |
|
|
DEB(printk(KERN_DEBUG "i2c-core.o: client [%s] registered to adapter [%s](pos. %d).\n",
|
| 420 |
|
|
client->name, adapter->name,i));
|
| 421 |
|
|
|
| 422 |
|
|
if(client->flags & I2C_CLIENT_ALLOW_USE)
|
| 423 |
|
|
client->usage_count = 0;
|
| 424 |
|
|
|
| 425 |
|
|
return 0;
|
| 426 |
|
|
}
|
| 427 |
|
|
|
| 428 |
|
|
|
| 429 |
|
|
int i2c_detach_client(struct i2c_client *client)
|
| 430 |
|
|
{
|
| 431 |
|
|
struct i2c_adapter *adapter = client->adapter;
|
| 432 |
|
|
int i,res;
|
| 433 |
|
|
|
| 434 |
|
|
for (i = 0; i < I2C_CLIENT_MAX; i++)
|
| 435 |
|
|
if (client == adapter->clients[i])
|
| 436 |
|
|
break;
|
| 437 |
|
|
if (I2C_CLIENT_MAX == i) {
|
| 438 |
|
|
printk(KERN_WARNING " i2c-core.o: unregister_client "
|
| 439 |
|
|
"[%s] not found\n",
|
| 440 |
|
|
client->name);
|
| 441 |
|
|
return -ENODEV;
|
| 442 |
|
|
}
|
| 443 |
|
|
|
| 444 |
|
|
if( (client->flags & I2C_CLIENT_ALLOW_USE) &&
|
| 445 |
|
|
(client->usage_count>0))
|
| 446 |
|
|
return -EBUSY;
|
| 447 |
|
|
|
| 448 |
|
|
if (adapter->client_unregister != NULL)
|
| 449 |
|
|
if ((res = adapter->client_unregister(client))) {
|
| 450 |
|
|
printk(KERN_ERR "i2c-core.o: client_unregister [%s] failed, "
|
| 451 |
|
|
"client not detached",client->name);
|
| 452 |
|
|
return res;
|
| 453 |
|
|
}
|
| 454 |
|
|
|
| 455 |
|
|
adapter->clients[i] = NULL;
|
| 456 |
|
|
adapter->client_count--;
|
| 457 |
|
|
|
| 458 |
|
|
DEB(printk(KERN_DEBUG "i2c-core.o: client [%s] unregistered.\n",client->name));
|
| 459 |
|
|
return 0;
|
| 460 |
|
|
}
|
| 461 |
|
|
|
| 462 |
|
|
void i2c_inc_use_client(struct i2c_client *client)
|
| 463 |
|
|
{
|
| 464 |
|
|
|
| 465 |
|
|
if (client->driver->inc_use != NULL)
|
| 466 |
|
|
client->driver->inc_use(client);
|
| 467 |
|
|
|
| 468 |
|
|
if (client->adapter->inc_use != NULL)
|
| 469 |
|
|
client->adapter->inc_use(client->adapter);
|
| 470 |
|
|
}
|
| 471 |
|
|
|
| 472 |
|
|
void i2c_dec_use_client(struct i2c_client *client)
|
| 473 |
|
|
{
|
| 474 |
|
|
|
| 475 |
|
|
if (client->driver->dec_use != NULL)
|
| 476 |
|
|
client->driver->dec_use(client);
|
| 477 |
|
|
|
| 478 |
|
|
if (client->adapter->dec_use != NULL)
|
| 479 |
|
|
client->adapter->dec_use(client->adapter);
|
| 480 |
|
|
}
|
| 481 |
|
|
|
| 482 |
|
|
struct i2c_client *i2c_get_client(int driver_id, int adapter_id,
|
| 483 |
|
|
struct i2c_client *prev)
|
| 484 |
|
|
{
|
| 485 |
|
|
int i,j;
|
| 486 |
|
|
|
| 487 |
|
|
/* Will iterate through the list of clients in each adapter of adapters-list
|
| 488 |
|
|
in search for a client that matches the search criteria. driver_id or
|
| 489 |
|
|
adapter_id are ignored if set to 0. If both are ignored this returns
|
| 490 |
|
|
first client found. */
|
| 491 |
|
|
|
| 492 |
|
|
i = j = 0;
|
| 493 |
|
|
|
| 494 |
|
|
/* set starting point */
|
| 495 |
|
|
if(prev)
|
| 496 |
|
|
{
|
| 497 |
|
|
if(!(prev->adapter))
|
| 498 |
|
|
return (struct i2c_client *) -EINVAL;
|
| 499 |
|
|
|
| 500 |
|
|
for(j=0; j < I2C_ADAP_MAX; j++)
|
| 501 |
|
|
if(prev->adapter == adapters[j])
|
| 502 |
|
|
break;
|
| 503 |
|
|
|
| 504 |
|
|
/* invalid starting point? */
|
| 505 |
|
|
if (I2C_ADAP_MAX == j) {
|
| 506 |
|
|
printk(KERN_WARNING " i2c-core.o: get_client adapter for client:[%s] not found\n",
|
| 507 |
|
|
prev->name);
|
| 508 |
|
|
return (struct i2c_client *) -ENODEV;
|
| 509 |
|
|
}
|
| 510 |
|
|
|
| 511 |
|
|
for(i=0; i < I2C_CLIENT_MAX; i++)
|
| 512 |
|
|
if(prev == adapters[j]->clients[i])
|
| 513 |
|
|
break;
|
| 514 |
|
|
|
| 515 |
|
|
/* invalid starting point? */
|
| 516 |
|
|
if (I2C_CLIENT_MAX == i) {
|
| 517 |
|
|
printk(KERN_WARNING " i2c-core.o: get_client client:[%s] not found\n",
|
| 518 |
|
|
prev->name);
|
| 519 |
|
|
return (struct i2c_client *) -ENODEV;
|
| 520 |
|
|
}
|
| 521 |
|
|
|
| 522 |
|
|
i++; /* start from one after prev */
|
| 523 |
|
|
}
|
| 524 |
|
|
|
| 525 |
|
|
for(; j < I2C_ADAP_MAX; j++)
|
| 526 |
|
|
{
|
| 527 |
|
|
if(!adapters[j])
|
| 528 |
|
|
continue;
|
| 529 |
|
|
|
| 530 |
|
|
if(adapter_id && (adapters[j]->id != adapter_id))
|
| 531 |
|
|
continue;
|
| 532 |
|
|
|
| 533 |
|
|
for(; i < I2C_CLIENT_MAX; i++)
|
| 534 |
|
|
{
|
| 535 |
|
|
if(!adapters[j]->clients[i])
|
| 536 |
|
|
continue;
|
| 537 |
|
|
|
| 538 |
|
|
if(driver_id && (adapters[j]->clients[i]->driver->id != driver_id))
|
| 539 |
|
|
continue;
|
| 540 |
|
|
if(adapters[j]->clients[i]->flags & I2C_CLIENT_ALLOW_USE)
|
| 541 |
|
|
return adapters[j]->clients[i];
|
| 542 |
|
|
}
|
| 543 |
|
|
i = 0;
|
| 544 |
|
|
}
|
| 545 |
|
|
|
| 546 |
|
|
return 0;
|
| 547 |
|
|
}
|
| 548 |
|
|
|
| 549 |
|
|
int i2c_use_client(struct i2c_client *client)
|
| 550 |
|
|
{
|
| 551 |
|
|
if(client->flags & I2C_CLIENT_ALLOW_USE) {
|
| 552 |
|
|
if (client->flags & I2C_CLIENT_ALLOW_MULTIPLE_USE)
|
| 553 |
|
|
client->usage_count++;
|
| 554 |
|
|
else {
|
| 555 |
|
|
if(client->usage_count > 0)
|
| 556 |
|
|
return -EBUSY;
|
| 557 |
|
|
else
|
| 558 |
|
|
client->usage_count++;
|
| 559 |
|
|
}
|
| 560 |
|
|
}
|
| 561 |
|
|
|
| 562 |
|
|
i2c_inc_use_client(client);
|
| 563 |
|
|
|
| 564 |
|
|
return 0;
|
| 565 |
|
|
}
|
| 566 |
|
|
|
| 567 |
|
|
int i2c_release_client(struct i2c_client *client)
|
| 568 |
|
|
{
|
| 569 |
|
|
if(client->flags & I2C_CLIENT_ALLOW_USE) {
|
| 570 |
|
|
if(client->usage_count>0)
|
| 571 |
|
|
client->usage_count--;
|
| 572 |
|
|
else
|
| 573 |
|
|
{
|
| 574 |
|
|
printk(KERN_WARNING " i2c-core.o: dec_use_client used one too many times\n");
|
| 575 |
|
|
return -EPERM;
|
| 576 |
|
|
}
|
| 577 |
|
|
}
|
| 578 |
|
|
|
| 579 |
|
|
i2c_dec_use_client(client);
|
| 580 |
|
|
|
| 581 |
|
|
return 0;
|
| 582 |
|
|
}
|
| 583 |
|
|
|
| 584 |
|
|
/* ----------------------------------------------------
|
| 585 |
|
|
* The /proc functions
|
| 586 |
|
|
* ----------------------------------------------------
|
| 587 |
|
|
*/
|
| 588 |
|
|
|
| 589 |
|
|
#ifdef CONFIG_PROC_FS
|
| 590 |
|
|
|
| 591 |
|
|
/* This function generates the output for /proc/bus/i2c */
|
| 592 |
|
|
int read_bus_i2c(char *buf, char **start, off_t offset, int len, int *eof,
|
| 593 |
|
|
void *private)
|
| 594 |
|
|
{
|
| 595 |
|
|
int i;
|
| 596 |
|
|
int nr = 0;
|
| 597 |
|
|
/* Note that it is safe to write a `little' beyond len. Yes, really. */
|
| 598 |
|
|
for (i = 0; (i < I2C_ADAP_MAX) && (nr < len); i++)
|
| 599 |
|
|
if (adapters[i]) {
|
| 600 |
|
|
nr += sprintf(buf+nr, "i2c-%d\t", i);
|
| 601 |
|
|
if (adapters[i]->algo->smbus_xfer) {
|
| 602 |
|
|
if (adapters[i]->algo->master_xfer)
|
| 603 |
|
|
nr += sprintf(buf+nr,"smbus/i2c");
|
| 604 |
|
|
else
|
| 605 |
|
|
nr += sprintf(buf+nr,"smbus ");
|
| 606 |
|
|
} else if (adapters[i]->algo->master_xfer)
|
| 607 |
|
|
nr += sprintf(buf+nr,"i2c ");
|
| 608 |
|
|
else
|
| 609 |
|
|
nr += sprintf(buf+nr,"dummy ");
|
| 610 |
|
|
nr += sprintf(buf+nr,"\t%-32s\t%-32s\n",
|
| 611 |
|
|
adapters[i]->name,
|
| 612 |
|
|
adapters[i]->algo->name);
|
| 613 |
|
|
}
|
| 614 |
|
|
return nr;
|
| 615 |
|
|
}
|
| 616 |
|
|
|
| 617 |
|
|
/* This function generates the output for /proc/bus/i2c-? */
|
| 618 |
|
|
ssize_t i2cproc_bus_read(struct file * file, char * buf,size_t count,
|
| 619 |
|
|
loff_t *ppos)
|
| 620 |
|
|
{
|
| 621 |
|
|
struct inode * inode = file->f_dentry->d_inode;
|
| 622 |
|
|
char *kbuf;
|
| 623 |
|
|
struct i2c_client *client;
|
| 624 |
|
|
int i,j,k,order_nr,len=0;
|
| 625 |
|
|
size_t len_total;
|
| 626 |
|
|
int order[I2C_CLIENT_MAX];
|
| 627 |
|
|
|
| 628 |
|
|
if (count > 4000)
|
| 629 |
|
|
return -EINVAL;
|
| 630 |
|
|
len_total = file->f_pos + count;
|
| 631 |
|
|
/* Too bad if this gets longer (unlikely) */
|
| 632 |
|
|
if (len_total > 4000)
|
| 633 |
|
|
len_total = 4000;
|
| 634 |
|
|
for (i = 0; i < I2C_ADAP_MAX; i++)
|
| 635 |
|
|
if (adapters[i]->inode == inode->i_ino) {
|
| 636 |
|
|
/* We need a bit of slack in the kernel buffer; this makes the
|
| 637 |
|
|
sprintf safe. */
|
| 638 |
|
|
if (! (kbuf = kmalloc(count + 80,GFP_KERNEL)))
|
| 639 |
|
|
return -ENOMEM;
|
| 640 |
|
|
/* Order will hold the indexes of the clients
|
| 641 |
|
|
sorted by address */
|
| 642 |
|
|
order_nr=0;
|
| 643 |
|
|
for (j = 0; j < I2C_CLIENT_MAX; j++) {
|
| 644 |
|
|
if ((client = adapters[i]->clients[j]) &&
|
| 645 |
|
|
(client->driver->id != I2C_DRIVERID_I2CDEV)) {
|
| 646 |
|
|
for(k = order_nr;
|
| 647 |
|
|
(k > 0) &&
|
| 648 |
|
|
adapters[i]->clients[order[k-1]]->
|
| 649 |
|
|
addr > client->addr;
|
| 650 |
|
|
k--)
|
| 651 |
|
|
order[k] = order[k-1];
|
| 652 |
|
|
order[k] = j;
|
| 653 |
|
|
order_nr++;
|
| 654 |
|
|
}
|
| 655 |
|
|
}
|
| 656 |
|
|
|
| 657 |
|
|
|
| 658 |
|
|
for (j = 0; (j < order_nr) && (len < len_total); j++) {
|
| 659 |
|
|
client = adapters[i]->clients[order[j]];
|
| 660 |
|
|
len += sprintf(kbuf+len,"%02x\t%-32s\t%-32s\n",
|
| 661 |
|
|
client->addr,
|
| 662 |
|
|
client->name,
|
| 663 |
|
|
client->driver->name);
|
| 664 |
|
|
}
|
| 665 |
|
|
len = len - file->f_pos;
|
| 666 |
|
|
if (len > count)
|
| 667 |
|
|
len = count;
|
| 668 |
|
|
if (len < 0)
|
| 669 |
|
|
len = 0;
|
| 670 |
|
|
if (copy_to_user (buf,kbuf+file->f_pos, len)) {
|
| 671 |
|
|
kfree(kbuf);
|
| 672 |
|
|
return -EFAULT;
|
| 673 |
|
|
}
|
| 674 |
|
|
file->f_pos += len;
|
| 675 |
|
|
kfree(kbuf);
|
| 676 |
|
|
return len;
|
| 677 |
|
|
}
|
| 678 |
|
|
return -ENOENT;
|
| 679 |
|
|
}
|
| 680 |
|
|
|
| 681 |
|
|
int i2cproc_init(void)
|
| 682 |
|
|
{
|
| 683 |
|
|
|
| 684 |
|
|
struct proc_dir_entry *proc_bus_i2c;
|
| 685 |
|
|
|
| 686 |
|
|
i2cproc_initialized = 0;
|
| 687 |
|
|
|
| 688 |
|
|
if (! proc_bus) {
|
| 689 |
|
|
printk("i2c-core.o: /proc/bus/ does not exist");
|
| 690 |
|
|
i2cproc_cleanup();
|
| 691 |
|
|
return -ENOENT;
|
| 692 |
|
|
}
|
| 693 |
|
|
proc_bus_i2c = create_proc_entry("i2c",0,proc_bus);
|
| 694 |
|
|
if (!proc_bus_i2c) {
|
| 695 |
|
|
printk(KERN_ERR "i2c-core.o: Could not create /proc/bus/i2c");
|
| 696 |
|
|
i2cproc_cleanup();
|
| 697 |
|
|
return -ENOENT;
|
| 698 |
|
|
}
|
| 699 |
|
|
proc_bus_i2c->read_proc = &read_bus_i2c;
|
| 700 |
|
|
proc_bus_i2c->owner = THIS_MODULE;
|
| 701 |
|
|
i2cproc_initialized += 2;
|
| 702 |
|
|
return 0;
|
| 703 |
|
|
}
|
| 704 |
|
|
|
| 705 |
|
|
int i2cproc_cleanup(void)
|
| 706 |
|
|
{
|
| 707 |
|
|
|
| 708 |
|
|
if (i2cproc_initialized >= 1) {
|
| 709 |
|
|
remove_proc_entry("i2c",proc_bus);
|
| 710 |
|
|
i2cproc_initialized -= 2;
|
| 711 |
|
|
}
|
| 712 |
|
|
return 0;
|
| 713 |
|
|
}
|
| 714 |
|
|
|
| 715 |
|
|
|
| 716 |
|
|
#endif /* def CONFIG_PROC_FS */
|
| 717 |
|
|
|
| 718 |
|
|
/* ----------------------------------------------------
|
| 719 |
|
|
* the functional interface to the i2c busses.
|
| 720 |
|
|
* ----------------------------------------------------
|
| 721 |
|
|
*/
|
| 722 |
|
|
|
| 723 |
|
|
int i2c_transfer(struct i2c_adapter * adap, struct i2c_msg msgs[],int num)
|
| 724 |
|
|
{
|
| 725 |
|
|
int ret;
|
| 726 |
|
|
|
| 727 |
|
|
if (adap->algo->master_xfer) {
|
| 728 |
|
|
DEB2(printk(KERN_DEBUG "i2c-core.o: master_xfer: %s with %d msgs.\n",
|
| 729 |
|
|
adap->name,num));
|
| 730 |
|
|
|
| 731 |
|
|
I2C_LOCK(adap);
|
| 732 |
|
|
ret = adap->algo->master_xfer(adap,msgs,num);
|
| 733 |
|
|
I2C_UNLOCK(adap);
|
| 734 |
|
|
|
| 735 |
|
|
return ret;
|
| 736 |
|
|
} else {
|
| 737 |
|
|
printk(KERN_ERR "i2c-core.o: I2C adapter %04x: I2C level transfers not supported\n",
|
| 738 |
|
|
adap->id);
|
| 739 |
|
|
return -ENOSYS;
|
| 740 |
|
|
}
|
| 741 |
|
|
}
|
| 742 |
|
|
|
| 743 |
|
|
int i2c_master_send(struct i2c_client *client,const char *buf ,int count)
|
| 744 |
|
|
{
|
| 745 |
|
|
int ret;
|
| 746 |
|
|
struct i2c_adapter *adap=client->adapter;
|
| 747 |
|
|
struct i2c_msg msg;
|
| 748 |
|
|
|
| 749 |
|
|
if (client->adapter->algo->master_xfer) {
|
| 750 |
|
|
msg.addr = client->addr;
|
| 751 |
|
|
msg.flags = client->flags & I2C_M_TEN;
|
| 752 |
|
|
msg.len = count;
|
| 753 |
|
|
(const char *)msg.buf = buf;
|
| 754 |
|
|
|
| 755 |
|
|
DEB2(printk(KERN_DEBUG "i2c-core.o: master_send: writing %d bytes on %s.\n",
|
| 756 |
|
|
count,client->adapter->name));
|
| 757 |
|
|
|
| 758 |
|
|
I2C_LOCK(adap);
|
| 759 |
|
|
ret = adap->algo->master_xfer(adap,&msg,1);
|
| 760 |
|
|
I2C_UNLOCK(adap);
|
| 761 |
|
|
|
| 762 |
|
|
/* if everything went ok (i.e. 1 msg transmitted), return #bytes
|
| 763 |
|
|
* transmitted, else error code.
|
| 764 |
|
|
*/
|
| 765 |
|
|
return (ret == 1 )? count : ret;
|
| 766 |
|
|
} else {
|
| 767 |
|
|
printk(KERN_ERR "i2c-core.o: I2C adapter %04x: I2C level transfers not supported\n",
|
| 768 |
|
|
client->adapter->id);
|
| 769 |
|
|
return -ENOSYS;
|
| 770 |
|
|
}
|
| 771 |
|
|
}
|
| 772 |
|
|
|
| 773 |
|
|
int i2c_master_recv(struct i2c_client *client, char *buf ,int count)
|
| 774 |
|
|
{
|
| 775 |
|
|
struct i2c_adapter *adap=client->adapter;
|
| 776 |
|
|
struct i2c_msg msg;
|
| 777 |
|
|
int ret;
|
| 778 |
|
|
if (client->adapter->algo->master_xfer) {
|
| 779 |
|
|
msg.addr = client->addr;
|
| 780 |
|
|
msg.flags = client->flags & I2C_M_TEN;
|
| 781 |
|
|
msg.flags |= I2C_M_RD;
|
| 782 |
|
|
msg.len = count;
|
| 783 |
|
|
msg.buf = buf;
|
| 784 |
|
|
|
| 785 |
|
|
DEB2(printk(KERN_DEBUG "i2c-core.o: master_recv: reading %d bytes on %s.\n",
|
| 786 |
|
|
count,client->adapter->name));
|
| 787 |
|
|
|
| 788 |
|
|
I2C_LOCK(adap);
|
| 789 |
|
|
ret = adap->algo->master_xfer(adap,&msg,1);
|
| 790 |
|
|
I2C_UNLOCK(adap);
|
| 791 |
|
|
|
| 792 |
|
|
DEB2(printk(KERN_DEBUG "i2c-core.o: master_recv: return:%d (count:%d, addr:0x%02x)\n",
|
| 793 |
|
|
ret, count, client->addr));
|
| 794 |
|
|
|
| 795 |
|
|
/* if everything went ok (i.e. 1 msg transmitted), return #bytes
|
| 796 |
|
|
* transmitted, else error code.
|
| 797 |
|
|
*/
|
| 798 |
|
|
return (ret == 1 )? count : ret;
|
| 799 |
|
|
} else {
|
| 800 |
|
|
printk(KERN_ERR "i2c-core.o: I2C adapter %04x: I2C level transfers not supported\n",
|
| 801 |
|
|
client->adapter->id);
|
| 802 |
|
|
return -ENOSYS;
|
| 803 |
|
|
}
|
| 804 |
|
|
}
|
| 805 |
|
|
|
| 806 |
|
|
|
| 807 |
|
|
int i2c_control(struct i2c_client *client,
|
| 808 |
|
|
unsigned int cmd, unsigned long arg)
|
| 809 |
|
|
{
|
| 810 |
|
|
int ret = 0;
|
| 811 |
|
|
struct i2c_adapter *adap = client->adapter;
|
| 812 |
|
|
|
| 813 |
|
|
DEB2(printk(KERN_DEBUG "i2c-core.o: i2c ioctl, cmd: 0x%x, arg: %#lx\n", cmd, arg));
|
| 814 |
|
|
switch ( cmd ) {
|
| 815 |
|
|
case I2C_RETRIES:
|
| 816 |
|
|
adap->retries = arg;
|
| 817 |
|
|
break;
|
| 818 |
|
|
case I2C_TIMEOUT:
|
| 819 |
|
|
adap->timeout = arg;
|
| 820 |
|
|
break;
|
| 821 |
|
|
default:
|
| 822 |
|
|
if (adap->algo->algo_control!=NULL)
|
| 823 |
|
|
ret = adap->algo->algo_control(adap,cmd,arg);
|
| 824 |
|
|
}
|
| 825 |
|
|
return ret;
|
| 826 |
|
|
}
|
| 827 |
|
|
|
| 828 |
|
|
/* ----------------------------------------------------
|
| 829 |
|
|
* the i2c address scanning function
|
| 830 |
|
|
* Will not work for 10-bit addresses!
|
| 831 |
|
|
* ----------------------------------------------------
|
| 832 |
|
|
*/
|
| 833 |
|
|
int i2c_probe(struct i2c_adapter *adapter,
|
| 834 |
|
|
struct i2c_client_address_data *address_data,
|
| 835 |
|
|
i2c_client_found_addr_proc *found_proc)
|
| 836 |
|
|
{
|
| 837 |
|
|
int addr,i,found,err;
|
| 838 |
|
|
int adap_id = i2c_adapter_id(adapter);
|
| 839 |
|
|
|
| 840 |
|
|
/* Forget it if we can't probe using SMBUS_QUICK */
|
| 841 |
|
|
if (! i2c_check_functionality(adapter,I2C_FUNC_SMBUS_QUICK))
|
| 842 |
|
|
return -1;
|
| 843 |
|
|
|
| 844 |
|
|
for (addr = 0x00; addr <= 0x7f; addr++) {
|
| 845 |
|
|
|
| 846 |
|
|
/* Skip if already in use */
|
| 847 |
|
|
if (i2c_check_addr(adapter,addr))
|
| 848 |
|
|
continue;
|
| 849 |
|
|
|
| 850 |
|
|
/* If it is in one of the force entries, we don't do any detection
|
| 851 |
|
|
at all */
|
| 852 |
|
|
found = 0;
|
| 853 |
|
|
|
| 854 |
|
|
for (i = 0; !found && (address_data->force[i] != I2C_CLIENT_END); i += 3) {
|
| 855 |
|
|
if (((adap_id == address_data->force[i]) ||
|
| 856 |
|
|
(address_data->force[i] == ANY_I2C_BUS)) &&
|
| 857 |
|
|
(addr == address_data->force[i+1])) {
|
| 858 |
|
|
DEB2(printk(KERN_DEBUG "i2c-core.o: found force parameter for adapter %d, addr %04x\n",
|
| 859 |
|
|
adap_id,addr));
|
| 860 |
|
|
if ((err = found_proc(adapter,addr,0,0)))
|
| 861 |
|
|
return err;
|
| 862 |
|
|
found = 1;
|
| 863 |
|
|
}
|
| 864 |
|
|
}
|
| 865 |
|
|
if (found)
|
| 866 |
|
|
continue;
|
| 867 |
|
|
|
| 868 |
|
|
/* If this address is in one of the ignores, we can forget about
|
| 869 |
|
|
it right now */
|
| 870 |
|
|
for (i = 0;
|
| 871 |
|
|
!found && (address_data->ignore[i] != I2C_CLIENT_END);
|
| 872 |
|
|
i += 2) {
|
| 873 |
|
|
if (((adap_id == address_data->ignore[i]) ||
|
| 874 |
|
|
((address_data->ignore[i] == ANY_I2C_BUS))) &&
|
| 875 |
|
|
(addr == address_data->ignore[i+1])) {
|
| 876 |
|
|
DEB2(printk(KERN_DEBUG "i2c-core.o: found ignore parameter for adapter %d, "
|
| 877 |
|
|
"addr %04x\n", adap_id ,addr));
|
| 878 |
|
|
found = 1;
|
| 879 |
|
|
}
|
| 880 |
|
|
}
|
| 881 |
|
|
for (i = 0;
|
| 882 |
|
|
!found && (address_data->ignore_range[i] != I2C_CLIENT_END);
|
| 883 |
|
|
i += 3) {
|
| 884 |
|
|
if (((adap_id == address_data->ignore_range[i]) ||
|
| 885 |
|
|
((address_data->ignore_range[i]==ANY_I2C_BUS))) &&
|
| 886 |
|
|
(addr >= address_data->ignore_range[i+1]) &&
|
| 887 |
|
|
(addr <= address_data->ignore_range[i+2])) {
|
| 888 |
|
|
DEB2(printk(KERN_DEBUG "i2c-core.o: found ignore_range parameter for adapter %d, "
|
| 889 |
|
|
"addr %04x\n", adap_id,addr));
|
| 890 |
|
|
found = 1;
|
| 891 |
|
|
}
|
| 892 |
|
|
}
|
| 893 |
|
|
if (found)
|
| 894 |
|
|
continue;
|
| 895 |
|
|
|
| 896 |
|
|
/* Now, we will do a detection, but only if it is in the normal or
|
| 897 |
|
|
probe entries */
|
| 898 |
|
|
for (i = 0;
|
| 899 |
|
|
!found && (address_data->normal_i2c[i] != I2C_CLIENT_END);
|
| 900 |
|
|
i += 1) {
|
| 901 |
|
|
if (addr == address_data->normal_i2c[i]) {
|
| 902 |
|
|
found = 1;
|
| 903 |
|
|
DEB2(printk(KERN_DEBUG "i2c-core.o: found normal i2c entry for adapter %d, "
|
| 904 |
|
|
"addr %02x", adap_id,addr));
|
| 905 |
|
|
}
|
| 906 |
|
|
}
|
| 907 |
|
|
|
| 908 |
|
|
for (i = 0;
|
| 909 |
|
|
!found && (address_data->normal_i2c_range[i] != I2C_CLIENT_END);
|
| 910 |
|
|
i += 2) {
|
| 911 |
|
|
if ((addr >= address_data->normal_i2c_range[i]) &&
|
| 912 |
|
|
(addr <= address_data->normal_i2c_range[i+1])) {
|
| 913 |
|
|
found = 1;
|
| 914 |
|
|
DEB2(printk(KERN_DEBUG "i2c-core.o: found normal i2c_range entry for adapter %d, "
|
| 915 |
|
|
"addr %04x\n", adap_id,addr));
|
| 916 |
|
|
}
|
| 917 |
|
|
}
|
| 918 |
|
|
|
| 919 |
|
|
for (i = 0;
|
| 920 |
|
|
!found && (address_data->probe[i] != I2C_CLIENT_END);
|
| 921 |
|
|
i += 2) {
|
| 922 |
|
|
if (((adap_id == address_data->probe[i]) ||
|
| 923 |
|
|
((address_data->probe[i] == ANY_I2C_BUS))) &&
|
| 924 |
|
|
(addr == address_data->probe[i+1])) {
|
| 925 |
|
|
found = 1;
|
| 926 |
|
|
DEB2(printk(KERN_DEBUG "i2c-core.o: found probe parameter for adapter %d, "
|
| 927 |
|
|
"addr %04x\n", adap_id,addr));
|
| 928 |
|
|
}
|
| 929 |
|
|
}
|
| 930 |
|
|
for (i = 0;
|
| 931 |
|
|
!found && (address_data->probe_range[i] != I2C_CLIENT_END);
|
| 932 |
|
|
i += 3) {
|
| 933 |
|
|
if (((adap_id == address_data->probe_range[i]) ||
|
| 934 |
|
|
(address_data->probe_range[i] == ANY_I2C_BUS)) &&
|
| 935 |
|
|
(addr >= address_data->probe_range[i+1]) &&
|
| 936 |
|
|
(addr <= address_data->probe_range[i+2])) {
|
| 937 |
|
|
found = 1;
|
| 938 |
|
|
DEB2(printk(KERN_DEBUG "i2c-core.o: found probe_range parameter for adapter %d, "
|
| 939 |
|
|
"addr %04x\n", adap_id,addr));
|
| 940 |
|
|
}
|
| 941 |
|
|
}
|
| 942 |
|
|
if (!found)
|
| 943 |
|
|
continue;
|
| 944 |
|
|
|
| 945 |
|
|
/* OK, so we really should examine this address. First check
|
| 946 |
|
|
whether there is some client here at all! */
|
| 947 |
|
|
if (i2c_smbus_xfer(adapter,addr,0,0,0,I2C_SMBUS_QUICK,NULL) >= 0)
|
| 948 |
|
|
if ((err = found_proc(adapter,addr,0,-1)))
|
| 949 |
|
|
return err;
|
| 950 |
|
|
}
|
| 951 |
|
|
return 0;
|
| 952 |
|
|
}
|
| 953 |
|
|
|
| 954 |
|
|
/*
|
| 955 |
|
|
* return id number for a specific adapter
|
| 956 |
|
|
*/
|
| 957 |
|
|
int i2c_adapter_id(struct i2c_adapter *adap)
|
| 958 |
|
|
{
|
| 959 |
|
|
int i;
|
| 960 |
|
|
for (i = 0; i < I2C_ADAP_MAX; i++)
|
| 961 |
|
|
if (adap == adapters[i])
|
| 962 |
|
|
return i;
|
| 963 |
|
|
return -1;
|
| 964 |
|
|
}
|
| 965 |
|
|
|
| 966 |
|
|
/* The SMBus parts */
|
| 967 |
|
|
|
| 968 |
|
|
extern s32 i2c_smbus_write_quick(struct i2c_client * client, u8 value)
|
| 969 |
|
|
{
|
| 970 |
|
|
return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
|
| 971 |
|
|
value,0,I2C_SMBUS_QUICK,NULL);
|
| 972 |
|
|
}
|
| 973 |
|
|
|
| 974 |
|
|
extern s32 i2c_smbus_read_byte(struct i2c_client * client)
|
| 975 |
|
|
{
|
| 976 |
|
|
union i2c_smbus_data data;
|
| 977 |
|
|
if (i2c_smbus_xfer(client->adapter,client->addr,client->flags,
|
| 978 |
|
|
I2C_SMBUS_READ,0,I2C_SMBUS_BYTE, &data))
|
| 979 |
|
|
return -1;
|
| 980 |
|
|
else
|
| 981 |
|
|
return 0x0FF & data.byte;
|
| 982 |
|
|
}
|
| 983 |
|
|
|
| 984 |
|
|
extern s32 i2c_smbus_write_byte(struct i2c_client * client, u8 value)
|
| 985 |
|
|
{
|
| 986 |
|
|
return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
|
| 987 |
|
|
I2C_SMBUS_WRITE,value, I2C_SMBUS_BYTE,NULL);
|
| 988 |
|
|
}
|
| 989 |
|
|
|
| 990 |
|
|
extern s32 i2c_smbus_read_byte_data(struct i2c_client * client, u8 command)
|
| 991 |
|
|
{
|
| 992 |
|
|
union i2c_smbus_data data;
|
| 993 |
|
|
if (i2c_smbus_xfer(client->adapter,client->addr,client->flags,
|
| 994 |
|
|
I2C_SMBUS_READ,command, I2C_SMBUS_BYTE_DATA,&data))
|
| 995 |
|
|
return -1;
|
| 996 |
|
|
else
|
| 997 |
|
|
return 0x0FF & data.byte;
|
| 998 |
|
|
}
|
| 999 |
|
|
|
| 1000 |
|
|
extern s32 i2c_smbus_write_byte_data(struct i2c_client * client, u8 command,
|
| 1001 |
|
|
u8 value)
|
| 1002 |
|
|
{
|
| 1003 |
|
|
union i2c_smbus_data data;
|
| 1004 |
|
|
data.byte = value;
|
| 1005 |
|
|
return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
|
| 1006 |
|
|
I2C_SMBUS_WRITE,command,
|
| 1007 |
|
|
I2C_SMBUS_BYTE_DATA,&data);
|
| 1008 |
|
|
}
|
| 1009 |
|
|
|
| 1010 |
|
|
extern s32 i2c_smbus_read_word_data(struct i2c_client * client, u8 command)
|
| 1011 |
|
|
{
|
| 1012 |
|
|
union i2c_smbus_data data;
|
| 1013 |
|
|
if (i2c_smbus_xfer(client->adapter,client->addr,client->flags,
|
| 1014 |
|
|
I2C_SMBUS_READ,command, I2C_SMBUS_WORD_DATA, &data))
|
| 1015 |
|
|
return -1;
|
| 1016 |
|
|
else
|
| 1017 |
|
|
return 0x0FFFF & data.word;
|
| 1018 |
|
|
}
|
| 1019 |
|
|
|
| 1020 |
|
|
extern s32 i2c_smbus_write_word_data(struct i2c_client * client,
|
| 1021 |
|
|
u8 command, u16 value)
|
| 1022 |
|
|
{
|
| 1023 |
|
|
union i2c_smbus_data data;
|
| 1024 |
|
|
data.word = value;
|
| 1025 |
|
|
return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
|
| 1026 |
|
|
I2C_SMBUS_WRITE,command,
|
| 1027 |
|
|
I2C_SMBUS_WORD_DATA,&data);
|
| 1028 |
|
|
}
|
| 1029 |
|
|
|
| 1030 |
|
|
extern s32 i2c_smbus_process_call(struct i2c_client * client,
|
| 1031 |
|
|
u8 command, u16 value)
|
| 1032 |
|
|
{
|
| 1033 |
|
|
union i2c_smbus_data data;
|
| 1034 |
|
|
data.word = value;
|
| 1035 |
|
|
if (i2c_smbus_xfer(client->adapter,client->addr,client->flags,
|
| 1036 |
|
|
I2C_SMBUS_WRITE,command,
|
| 1037 |
|
|
I2C_SMBUS_PROC_CALL, &data))
|
| 1038 |
|
|
return -1;
|
| 1039 |
|
|
else
|
| 1040 |
|
|
return 0x0FFFF & data.word;
|
| 1041 |
|
|
}
|
| 1042 |
|
|
|
| 1043 |
|
|
/* Returns the number of read bytes */
|
| 1044 |
|
|
extern s32 i2c_smbus_read_block_data(struct i2c_client * client,
|
| 1045 |
|
|
u8 command, u8 *values)
|
| 1046 |
|
|
{
|
| 1047 |
|
|
union i2c_smbus_data data;
|
| 1048 |
|
|
int i;
|
| 1049 |
|
|
if (i2c_smbus_xfer(client->adapter,client->addr,client->flags,
|
| 1050 |
|
|
I2C_SMBUS_READ,command,
|
| 1051 |
|
|
I2C_SMBUS_BLOCK_DATA,&data))
|
| 1052 |
|
|
return -1;
|
| 1053 |
|
|
else {
|
| 1054 |
|
|
for (i = 1; i <= data.block[0]; i++)
|
| 1055 |
|
|
values[i-1] = data.block[i];
|
| 1056 |
|
|
return data.block[0];
|
| 1057 |
|
|
}
|
| 1058 |
|
|
}
|
| 1059 |
|
|
|
| 1060 |
|
|
extern s32 i2c_smbus_write_block_data(struct i2c_client * client,
|
| 1061 |
|
|
u8 command, u8 length, u8 *values)
|
| 1062 |
|
|
{
|
| 1063 |
|
|
union i2c_smbus_data data;
|
| 1064 |
|
|
int i;
|
| 1065 |
|
|
if (length > I2C_SMBUS_BLOCK_MAX)
|
| 1066 |
|
|
length = I2C_SMBUS_BLOCK_MAX;
|
| 1067 |
|
|
for (i = 1; i <= length; i++)
|
| 1068 |
|
|
data.block[i] = values[i-1];
|
| 1069 |
|
|
data.block[0] = length;
|
| 1070 |
|
|
return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
|
| 1071 |
|
|
I2C_SMBUS_WRITE,command,
|
| 1072 |
|
|
I2C_SMBUS_BLOCK_DATA,&data);
|
| 1073 |
|
|
}
|
| 1074 |
|
|
|
| 1075 |
|
|
extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client * client,
|
| 1076 |
|
|
u8 command, u8 length, u8 *values)
|
| 1077 |
|
|
{
|
| 1078 |
|
|
union i2c_smbus_data data;
|
| 1079 |
|
|
int i;
|
| 1080 |
|
|
if (length > I2C_SMBUS_I2C_BLOCK_MAX)
|
| 1081 |
|
|
length = I2C_SMBUS_I2C_BLOCK_MAX;
|
| 1082 |
|
|
for (i = 1; i <= length; i++)
|
| 1083 |
|
|
data.block[i] = values[i-1];
|
| 1084 |
|
|
data.block[0] = length;
|
| 1085 |
|
|
return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
|
| 1086 |
|
|
I2C_SMBUS_WRITE,command,
|
| 1087 |
|
|
I2C_SMBUS_I2C_BLOCK_DATA,&data);
|
| 1088 |
|
|
}
|
| 1089 |
|
|
|
| 1090 |
|
|
/* Simulate a SMBus command using the i2c protocol
|
| 1091 |
|
|
No checking of parameters is done! */
|
| 1092 |
|
|
static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
|
| 1093 |
|
|
unsigned short flags,
|
| 1094 |
|
|
char read_write, u8 command, int size,
|
| 1095 |
|
|
union i2c_smbus_data * data)
|
| 1096 |
|
|
{
|
| 1097 |
|
|
/* So we need to generate a series of msgs. In the case of writing, we
|
| 1098 |
|
|
need to use only one message; when reading, we need two. We initialize
|
| 1099 |
|
|
most things with sane defaults, to keep the code below somewhat
|
| 1100 |
|
|
simpler. */
|
| 1101 |
|
|
unsigned char msgbuf0[34];
|
| 1102 |
|
|
unsigned char msgbuf1[34];
|
| 1103 |
|
|
int num = read_write == I2C_SMBUS_READ?2:1;
|
| 1104 |
|
|
struct i2c_msg msg[2] = { { addr, flags, 1, msgbuf0 },
|
| 1105 |
|
|
{ addr, flags | I2C_M_RD, 0, msgbuf1 }
|
| 1106 |
|
|
};
|
| 1107 |
|
|
int i;
|
| 1108 |
|
|
|
| 1109 |
|
|
msgbuf0[0] = command;
|
| 1110 |
|
|
switch(size) {
|
| 1111 |
|
|
case I2C_SMBUS_QUICK:
|
| 1112 |
|
|
msg[0].len = 0;
|
| 1113 |
|
|
/* Special case: The read/write field is used as data */
|
| 1114 |
|
|
msg[0].flags = flags | (read_write==I2C_SMBUS_READ)?I2C_M_RD:0;
|
| 1115 |
|
|
num = 1;
|
| 1116 |
|
|
break;
|
| 1117 |
|
|
case I2C_SMBUS_BYTE:
|
| 1118 |
|
|
if (read_write == I2C_SMBUS_READ) {
|
| 1119 |
|
|
/* Special case: only a read! */
|
| 1120 |
|
|
msg[0].flags = I2C_M_RD | flags;
|
| 1121 |
|
|
num = 1;
|
| 1122 |
|
|
}
|
| 1123 |
|
|
break;
|
| 1124 |
|
|
case I2C_SMBUS_BYTE_DATA:
|
| 1125 |
|
|
if (read_write == I2C_SMBUS_READ)
|
| 1126 |
|
|
msg[1].len = 1;
|
| 1127 |
|
|
else {
|
| 1128 |
|
|
msg[0].len = 2;
|
| 1129 |
|
|
msgbuf0[1] = data->byte;
|
| 1130 |
|
|
}
|
| 1131 |
|
|
break;
|
| 1132 |
|
|
case I2C_SMBUS_WORD_DATA:
|
| 1133 |
|
|
if (read_write == I2C_SMBUS_READ)
|
| 1134 |
|
|
msg[1].len = 2;
|
| 1135 |
|
|
else {
|
| 1136 |
|
|
msg[0].len=3;
|
| 1137 |
|
|
msgbuf0[1] = data->word & 0xff;
|
| 1138 |
|
|
msgbuf0[2] = (data->word >> 8) & 0xff;
|
| 1139 |
|
|
}
|
| 1140 |
|
|
break;
|
| 1141 |
|
|
case I2C_SMBUS_PROC_CALL:
|
| 1142 |
|
|
num = 2; /* Special case */
|
| 1143 |
|
|
msg[0].len = 3;
|
| 1144 |
|
|
msg[1].len = 2;
|
| 1145 |
|
|
msgbuf0[1] = data->word & 0xff;
|
| 1146 |
|
|
msgbuf0[2] = (data->word >> 8) & 0xff;
|
| 1147 |
|
|
break;
|
| 1148 |
|
|
case I2C_SMBUS_BLOCK_DATA:
|
| 1149 |
|
|
if (read_write == I2C_SMBUS_READ) {
|
| 1150 |
|
|
printk(KERN_ERR "i2c-core.o: Block read not supported "
|
| 1151 |
|
|
"under I2C emulation!\n");
|
| 1152 |
|
|
return -1;
|
| 1153 |
|
|
} else {
|
| 1154 |
|
|
msg[0].len = data->block[0] + 2;
|
| 1155 |
|
|
if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 2) {
|
| 1156 |
|
|
printk(KERN_ERR "i2c-core.o: smbus_access called with "
|
| 1157 |
|
|
"invalid block write size (%d)\n",
|
| 1158 |
|
|
data->block[0]);
|
| 1159 |
|
|
return -1;
|
| 1160 |
|
|
}
|
| 1161 |
|
|
for (i = 1; i <= msg[0].len; i++)
|
| 1162 |
|
|
msgbuf0[i] = data->block[i-1];
|
| 1163 |
|
|
}
|
| 1164 |
|
|
break;
|
| 1165 |
|
|
default:
|
| 1166 |
|
|
printk(KERN_ERR "i2c-core.o: smbus_access called with invalid size (%d)\n",
|
| 1167 |
|
|
size);
|
| 1168 |
|
|
return -1;
|
| 1169 |
|
|
}
|
| 1170 |
|
|
|
| 1171 |
|
|
if (i2c_transfer(adapter, msg, num) < 0)
|
| 1172 |
|
|
return -1;
|
| 1173 |
|
|
|
| 1174 |
|
|
if (read_write == I2C_SMBUS_READ)
|
| 1175 |
|
|
switch(size) {
|
| 1176 |
|
|
case I2C_SMBUS_BYTE:
|
| 1177 |
|
|
data->byte = msgbuf0[0];
|
| 1178 |
|
|
break;
|
| 1179 |
|
|
case I2C_SMBUS_BYTE_DATA:
|
| 1180 |
|
|
data->byte = msgbuf1[0];
|
| 1181 |
|
|
break;
|
| 1182 |
|
|
case I2C_SMBUS_WORD_DATA:
|
| 1183 |
|
|
case I2C_SMBUS_PROC_CALL:
|
| 1184 |
|
|
data->word = msgbuf1[0] | (msgbuf1[1] << 8);
|
| 1185 |
|
|
break;
|
| 1186 |
|
|
}
|
| 1187 |
|
|
return 0;
|
| 1188 |
|
|
}
|
| 1189 |
|
|
|
| 1190 |
|
|
|
| 1191 |
|
|
s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags,
|
| 1192 |
|
|
char read_write, u8 command, int size,
|
| 1193 |
|
|
union i2c_smbus_data * data)
|
| 1194 |
|
|
{
|
| 1195 |
|
|
s32 res;
|
| 1196 |
|
|
flags = flags & I2C_M_TEN;
|
| 1197 |
|
|
if (adapter->algo->smbus_xfer) {
|
| 1198 |
|
|
I2C_LOCK(adapter);
|
| 1199 |
|
|
res = adapter->algo->smbus_xfer(adapter,addr,flags,read_write,
|
| 1200 |
|
|
command,size,data);
|
| 1201 |
|
|
I2C_UNLOCK(adapter);
|
| 1202 |
|
|
} else
|
| 1203 |
|
|
res = i2c_smbus_xfer_emulated(adapter,addr,flags,read_write,
|
| 1204 |
|
|
command,size,data);
|
| 1205 |
|
|
return res;
|
| 1206 |
|
|
}
|
| 1207 |
|
|
|
| 1208 |
|
|
|
| 1209 |
|
|
/* You should always define `functionality'; the 'else' is just for
|
| 1210 |
|
|
backward compatibility. */
|
| 1211 |
|
|
u32 i2c_get_functionality (struct i2c_adapter *adap)
|
| 1212 |
|
|
{
|
| 1213 |
|
|
if (adap->algo->functionality)
|
| 1214 |
|
|
return adap->algo->functionality(adap);
|
| 1215 |
|
|
else
|
| 1216 |
|
|
return 0xffffffff;
|
| 1217 |
|
|
}
|
| 1218 |
|
|
|
| 1219 |
|
|
int i2c_check_functionality (struct i2c_adapter *adap, u32 func)
|
| 1220 |
|
|
{
|
| 1221 |
|
|
u32 adap_func = i2c_get_functionality (adap);
|
| 1222 |
|
|
return (func & adap_func) == func;
|
| 1223 |
|
|
}
|
| 1224 |
|
|
|
| 1225 |
|
|
|
| 1226 |
|
|
static int __init i2c_init(void)
|
| 1227 |
|
|
{
|
| 1228 |
|
|
printk(KERN_INFO "i2c-core.o: i2c core module version %s (%s)\n", I2C_VERSION, I2C_DATE);
|
| 1229 |
|
|
memset(adapters,0,sizeof(adapters));
|
| 1230 |
|
|
memset(drivers,0,sizeof(drivers));
|
| 1231 |
|
|
adap_count=0;
|
| 1232 |
|
|
driver_count=0;
|
| 1233 |
|
|
|
| 1234 |
|
|
init_MUTEX(&adap_lock);
|
| 1235 |
|
|
init_MUTEX(&driver_lock);
|
| 1236 |
|
|
|
| 1237 |
|
|
i2cproc_init();
|
| 1238 |
|
|
|
| 1239 |
|
|
return 0;
|
| 1240 |
|
|
}
|
| 1241 |
|
|
|
| 1242 |
|
|
#ifndef MODULE
|
| 1243 |
|
|
#ifdef CONFIG_I2C_CHARDEV
|
| 1244 |
|
|
extern int i2c_dev_init(void);
|
| 1245 |
|
|
#endif
|
| 1246 |
|
|
#ifdef CONFIG_I2C_ALGOBIT
|
| 1247 |
|
|
extern int i2c_algo_bit_init(void);
|
| 1248 |
|
|
#endif
|
| 1249 |
|
|
#ifdef CONFIG_I2C_PHILIPSPAR
|
| 1250 |
|
|
extern int i2c_bitlp_init(void);
|
| 1251 |
|
|
#endif
|
| 1252 |
|
|
#ifdef CONFIG_I2C_ELV
|
| 1253 |
|
|
extern int i2c_bitelv_init(void);
|
| 1254 |
|
|
#endif
|
| 1255 |
|
|
#ifdef CONFIG_I2C_VELLEMAN
|
| 1256 |
|
|
extern int i2c_bitvelle_init(void);
|
| 1257 |
|
|
#endif
|
| 1258 |
|
|
#ifdef CONFIG_I2C_BITVIA
|
| 1259 |
|
|
extern int i2c_bitvia_init(void);
|
| 1260 |
|
|
#endif
|
| 1261 |
|
|
|
| 1262 |
|
|
#ifdef CONFIG_I2C_ALGOPCF
|
| 1263 |
|
|
extern int i2c_algo_pcf_init(void);
|
| 1264 |
|
|
#endif
|
| 1265 |
|
|
#ifdef CONFIG_I2C_ELEKTOR
|
| 1266 |
|
|
extern int i2c_pcfisa_init(void);
|
| 1267 |
|
|
#endif
|
| 1268 |
|
|
|
| 1269 |
|
|
#ifdef CONFIG_I2C_ALGO8XX
|
| 1270 |
|
|
extern int i2c_algo_8xx_init(void);
|
| 1271 |
|
|
#endif
|
| 1272 |
|
|
#ifdef CONFIG_I2C_RPXLITE
|
| 1273 |
|
|
extern int i2c_rpx_init(void);
|
| 1274 |
|
|
#endif
|
| 1275 |
|
|
|
| 1276 |
|
|
#ifdef CONFIG_I2C_ALGO_SIBYTE
|
| 1277 |
|
|
extern int i2c_algo_sibyte_init(void);
|
| 1278 |
|
|
extern int i2c_sibyte_init(void);
|
| 1279 |
|
|
#endif
|
| 1280 |
|
|
#ifdef CONFIG_I2C_MAX1617
|
| 1281 |
|
|
extern int i2c_max1617_init(void);
|
| 1282 |
|
|
#endif
|
| 1283 |
|
|
|
| 1284 |
|
|
#ifdef CONFIG_I2C_PROC
|
| 1285 |
|
|
extern int sensors_init(void);
|
| 1286 |
|
|
#endif
|
| 1287 |
|
|
|
| 1288 |
|
|
/* This is needed for automatic patch generation: sensors code starts here */
|
| 1289 |
|
|
/* This is needed for automatic patch generation: sensors code ends here */
|
| 1290 |
|
|
|
| 1291 |
|
|
int __init i2c_init_all(void)
|
| 1292 |
|
|
{
|
| 1293 |
|
|
/* --------------------- global ----- */
|
| 1294 |
|
|
i2c_init();
|
| 1295 |
|
|
|
| 1296 |
|
|
#ifdef CONFIG_I2C_CHARDEV
|
| 1297 |
|
|
i2c_dev_init();
|
| 1298 |
|
|
#endif
|
| 1299 |
|
|
/* --------------------- bit -------- */
|
| 1300 |
|
|
#ifdef CONFIG_I2C_ALGOBIT
|
| 1301 |
|
|
i2c_algo_bit_init();
|
| 1302 |
|
|
#endif
|
| 1303 |
|
|
#ifdef CONFIG_I2C_PHILIPSPAR
|
| 1304 |
|
|
i2c_bitlp_init();
|
| 1305 |
|
|
#endif
|
| 1306 |
|
|
#ifdef CONFIG_I2C_ELV
|
| 1307 |
|
|
i2c_bitelv_init();
|
| 1308 |
|
|
#endif
|
| 1309 |
|
|
#ifdef CONFIG_I2C_VELLEMAN
|
| 1310 |
|
|
i2c_bitvelle_init();
|
| 1311 |
|
|
#endif
|
| 1312 |
|
|
|
| 1313 |
|
|
/* --------------------- pcf -------- */
|
| 1314 |
|
|
#ifdef CONFIG_I2C_ALGOPCF
|
| 1315 |
|
|
i2c_algo_pcf_init();
|
| 1316 |
|
|
#endif
|
| 1317 |
|
|
#ifdef CONFIG_I2C_ELEKTOR
|
| 1318 |
|
|
i2c_pcfisa_init();
|
| 1319 |
|
|
#endif
|
| 1320 |
|
|
|
| 1321 |
|
|
/* --------------------- 8xx -------- */
|
| 1322 |
|
|
#ifdef CONFIG_I2C_ALGO8XX
|
| 1323 |
|
|
i2c_algo_8xx_init();
|
| 1324 |
|
|
#endif
|
| 1325 |
|
|
#ifdef CONFIG_I2C_RPXLITE
|
| 1326 |
|
|
i2c_rpx_init();
|
| 1327 |
|
|
#endif
|
| 1328 |
|
|
|
| 1329 |
|
|
/* --------------------- SiByte -------- */
|
| 1330 |
|
|
#ifdef CONFIG_I2C_ALGO_SIBYTE
|
| 1331 |
|
|
i2c_algo_sibyte_init();
|
| 1332 |
|
|
i2c_sibyte_init();
|
| 1333 |
|
|
#endif
|
| 1334 |
|
|
#ifdef CONFIG_I2C_MAX1617
|
| 1335 |
|
|
i2c_max1617_init();
|
| 1336 |
|
|
#endif
|
| 1337 |
|
|
|
| 1338 |
|
|
/* -------------- proc interface ---- */
|
| 1339 |
|
|
#ifdef CONFIG_I2C_PROC
|
| 1340 |
|
|
sensors_init();
|
| 1341 |
|
|
#endif
|
| 1342 |
|
|
/* This is needed for automatic patch generation: sensors code starts here */
|
| 1343 |
|
|
/* This is needed for automatic patch generation: sensors code ends here */
|
| 1344 |
|
|
|
| 1345 |
|
|
return 0;
|
| 1346 |
|
|
}
|
| 1347 |
|
|
|
| 1348 |
|
|
#endif
|
| 1349 |
|
|
|
| 1350 |
|
|
|
| 1351 |
|
|
|
| 1352 |
|
|
EXPORT_SYMBOL(i2c_add_adapter);
|
| 1353 |
|
|
EXPORT_SYMBOL(i2c_del_adapter);
|
| 1354 |
|
|
EXPORT_SYMBOL(i2c_add_driver);
|
| 1355 |
|
|
EXPORT_SYMBOL(i2c_del_driver);
|
| 1356 |
|
|
EXPORT_SYMBOL(i2c_attach_client);
|
| 1357 |
|
|
EXPORT_SYMBOL(i2c_detach_client);
|
| 1358 |
|
|
EXPORT_SYMBOL(i2c_inc_use_client);
|
| 1359 |
|
|
EXPORT_SYMBOL(i2c_dec_use_client);
|
| 1360 |
|
|
EXPORT_SYMBOL(i2c_get_client);
|
| 1361 |
|
|
EXPORT_SYMBOL(i2c_use_client);
|
| 1362 |
|
|
EXPORT_SYMBOL(i2c_release_client);
|
| 1363 |
|
|
EXPORT_SYMBOL(i2c_check_addr);
|
| 1364 |
|
|
|
| 1365 |
|
|
|
| 1366 |
|
|
EXPORT_SYMBOL(i2c_master_send);
|
| 1367 |
|
|
EXPORT_SYMBOL(i2c_master_recv);
|
| 1368 |
|
|
EXPORT_SYMBOL(i2c_control);
|
| 1369 |
|
|
EXPORT_SYMBOL(i2c_transfer);
|
| 1370 |
|
|
EXPORT_SYMBOL(i2c_adapter_id);
|
| 1371 |
|
|
EXPORT_SYMBOL(i2c_probe);
|
| 1372 |
|
|
|
| 1373 |
|
|
EXPORT_SYMBOL(i2c_smbus_xfer);
|
| 1374 |
|
|
EXPORT_SYMBOL(i2c_smbus_write_quick);
|
| 1375 |
|
|
EXPORT_SYMBOL(i2c_smbus_read_byte);
|
| 1376 |
|
|
EXPORT_SYMBOL(i2c_smbus_write_byte);
|
| 1377 |
|
|
EXPORT_SYMBOL(i2c_smbus_read_byte_data);
|
| 1378 |
|
|
EXPORT_SYMBOL(i2c_smbus_write_byte_data);
|
| 1379 |
|
|
EXPORT_SYMBOL(i2c_smbus_read_word_data);
|
| 1380 |
|
|
EXPORT_SYMBOL(i2c_smbus_write_word_data);
|
| 1381 |
|
|
EXPORT_SYMBOL(i2c_smbus_process_call);
|
| 1382 |
|
|
EXPORT_SYMBOL(i2c_smbus_read_block_data);
|
| 1383 |
|
|
EXPORT_SYMBOL(i2c_smbus_write_block_data);
|
| 1384 |
|
|
|
| 1385 |
|
|
EXPORT_SYMBOL(i2c_get_functionality);
|
| 1386 |
|
|
EXPORT_SYMBOL(i2c_check_functionality);
|
| 1387 |
|
|
|
| 1388 |
|
|
#ifdef MODULE
|
| 1389 |
|
|
MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
|
| 1390 |
|
|
MODULE_DESCRIPTION("I2C-Bus main module");
|
| 1391 |
|
|
MODULE_LICENSE("GPL");
|
| 1392 |
|
|
|
| 1393 |
|
|
MODULE_PARM(i2c_debug, "i");
|
| 1394 |
|
|
MODULE_PARM_DESC(i2c_debug,"debug level");
|
| 1395 |
|
|
|
| 1396 |
|
|
int init_module(void)
|
| 1397 |
|
|
{
|
| 1398 |
|
|
return i2c_init();
|
| 1399 |
|
|
}
|
| 1400 |
|
|
|
| 1401 |
|
|
void cleanup_module(void)
|
| 1402 |
|
|
{
|
| 1403 |
|
|
i2cproc_cleanup();
|
| 1404 |
|
|
}
|
| 1405 |
|
|
#endif
|