Changeset 3417

Show
Ignore:
Timestamp:
12/08/99 21:33:58 (9 years ago)
Author:
frodo
Message:

Previously announced i2c_check_addr function added

Changes in i2c-core.c:

i2c_check_addr(adapter,addr) checks all registered clients of this adapter
to see whether addr is already claimed. If so, it returns -EBUSY; if not,
it returns 0.

i2c_attach_client returns -EBUSY if you try to register a client whose
address is already in use. Note that you can cheat by using a client
without registering it; there is no check for this (I can imagine
situations in which this is useful).

i2c_probe will skip already used addresses.

Changes in i2c-dev.c:

Ioctl I2C_SLAVE (which sets the address to read from/write to) fails
if you try to set it to an already used address. A new ioctl called
I2C_SLAVE_FORCE overrides this, allowing you to access already
claimed addresses. This is the old behaviour, AND MAY BE DANGEROUS!

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • i2c/trunk/doc/writing-clients

    r3412 r3417  
    357357The i2c_probe or sensors_detect function will call the foo_detect_client 
    358358function only for those i2c addresses that actually have a device on 
    359 them (unless a `force' parameter was used). 
     359them (unless a `force' parameter was used). In addition, addresses that 
     360are already in use (by some other registered client) are skipped. 
    360361 
    361362 
  • i2c/trunk/kernel/i2c-core.c

    r3411 r3417  
    452452} 
    453453 
     454int i2c_check_addr (struct i2c_adapter *adapter, int addr) 
     455{ 
     456  int i; 
     457  for (i = 0; i < I2C_CLIENT_MAX ; i++)  
     458    if (adapter->clients[i] && (adapter->clients[i]->addr == addr)) 
     459      return -EBUSY; 
     460  return 0; 
     461} 
    454462 
    455463int i2c_attach_client(struct i2c_client *client) 
     
    457465        struct i2c_adapter *adapter = client->adapter; 
    458466        int i; 
     467 
     468        if (i2c_check_addr(client->adapter,client->addr)) 
     469          return -EBUSY; 
    459470 
    460471        for (i = 0; i < I2C_CLIENT_MAX; i++) 
     
    855866       addr <= 0x7f; 
    856867       addr++) { 
     868 
     869    /* Skip if already in use */ 
     870    if (i2c_check_addr(adapter,addr)) 
     871      continue; 
    857872 
    858873    /* If it is in one of the force entries, we don't do any detection 
     
    13121327EXPORT_SYMBOL(i2c_inc_use_client); 
    13131328EXPORT_SYMBOL(i2c_dec_use_client); 
     1329EXPORT_SYMBOL(i2c_check_addr); 
    13141330 
    13151331 
  • i2c/trunk/kernel/i2c-dev.c

    r3406 r3417  
    278278  switch ( cmd ) { 
    279279    case I2C_SLAVE: 
     280    case I2C_SLAVE_FORCE: 
    280281      if ((arg > 0x3ff) || (((client->flags & I2C_M_TEN) == 0) && arg > 0x7f)) 
    281282        return -EINVAL; 
     283      if ((cmd == I2C_SLAVE) && i2c_check_addr(client->adapter,arg)) 
     284        return -EBUSY; 
    282285      client->addr = arg; 
    283286      return 0; 
  • i2c/trunk/kernel/i2c.h

    r3408 r3417  
    325325extern void i2c_dec_use_client(struct i2c_client *); 
    326326 
     327/* returns -EBUSY if address has been taken, 0 if not. Note that the only 
     328   other place at which this is called is within i2c_attach_client; so 
     329   you can cheat by simply not registering. Not recommended, of course! */ 
     330extern int i2c_check_addr (struct i2c_adapter *adapter, int addr); 
    327331 
    328332/* Detect function. It itterates over all possible addresses itself. 
     
    428432#define I2C_SLAVE       0x0703  /* Change slave address                 */ 
    429433                                /* Attn.: Slave address is 7 or 10 bits */ 
     434#define I2C_SLAVE_FORCE 0x0706  /* Change slave address                 */ 
     435                                /* Attn.: Slave address is 7 or 10 bits */ 
     436                                /* This changes the address, even if it */ 
     437                                /* is already taken!                    */ 
    430438#define I2C_TENBIT      0x0704  /* 0 for 7 bit addrs, != 0 for 10 bit   */ 
    431439