Merge branch 'i2c-for-linus' of git://jdelvare.pck.nerim.net/jdelvare-2.6

* 'i2c-for-linus' of git://jdelvare.pck.nerim.net/jdelvare-2.6:
i2c/eeprom: Recognize VGN as a valid Sony Vaio name prefix
i2c/eeprom: Hide Sony Vaio serial numbers
i2c-pasemi: Fix NACK detection
i2c-pasemi: Replace obsolete "driverfs" reference with "sysfs"
i2c: Make i2c_check_addr static
i2c-dev: Unbound new-style i2c clients aren't busy
i2c-dev: "how does it work" comments

+115 -23
+6 -1
drivers/i2c/busses/i2c-pasemi.c
··· 51 #define MRXFIFO_DATA_M 0x000000ff 52 53 #define SMSTA_XEN 0x08000000 54 55 #define CTL_MRR 0x00000400 56 #define CTL_MTR 0x00000200 ··· 98 msleep(1); 99 status = reg_read(smbus, REG_SMSTA); 100 } 101 102 if (timeout < 0) { 103 dev_warn(&smbus->dev->dev, "Timeout, status 0x%08x\n", status); ··· 369 smbus->adapter.algo = &smbus_algorithm; 370 smbus->adapter.algo_data = smbus; 371 372 - /* set up the driverfs linkage to our parent device */ 373 smbus->adapter.dev.parent = &dev->dev; 374 375 reg_write(smbus, REG_CTL, (CTL_MTR | CTL_MRR |
··· 51 #define MRXFIFO_DATA_M 0x000000ff 52 53 #define SMSTA_XEN 0x08000000 54 + #define SMSTA_MTN 0x00200000 55 56 #define CTL_MRR 0x00000400 57 #define CTL_MTR 0x00000200 ··· 97 msleep(1); 98 status = reg_read(smbus, REG_SMSTA); 99 } 100 + 101 + /* Got NACK? */ 102 + if (status & SMSTA_MTN) 103 + return -ENXIO; 104 105 if (timeout < 0) { 106 dev_warn(&smbus->dev->dev, "Timeout, status 0x%08x\n", status); ··· 364 smbus->adapter.algo = &smbus_algorithm; 365 smbus->adapter.algo_data = smbus; 366 367 + /* set up the sysfs linkage to our parent device */ 368 smbus->adapter.dev.parent = &dev->dev; 369 370 reg_write(smbus, REG_CTL, (CTL_MTR | CTL_MRR |
+24 -13
drivers/i2c/chips/eeprom.c
··· 128 for (slice = off >> 5; slice <= (off + count - 1) >> 5; slice++) 129 eeprom_update_client(client, slice); 130 131 - /* Hide Vaio security settings to regular users (16 first bytes) */ 132 - if (data->nature == VAIO && off < 16 && !capable(CAP_SYS_ADMIN)) { 133 - size_t in_row1 = 16 - off; 134 - in_row1 = min(in_row1, count); 135 - memset(buf, 0, in_row1); 136 - if (count - in_row1 > 0) 137 - memcpy(buf + in_row1, &data->data[16], count - in_row1); 138 } else { 139 memcpy(buf, &data->data[off], count); 140 } ··· 204 goto exit_kfree; 205 206 /* Detect the Vaio nature of EEPROMs. 207 - We use the "PCG-" prefix as the signature. */ 208 if (address == 0x57) { 209 - if (i2c_smbus_read_byte_data(new_client, 0x80) == 'P' 210 - && i2c_smbus_read_byte(new_client) == 'C' 211 - && i2c_smbus_read_byte(new_client) == 'G' 212 - && i2c_smbus_read_byte(new_client) == '-') { 213 dev_info(&new_client->dev, "Vaio EEPROM detected, " 214 - "enabling password protection\n"); 215 data->nature = VAIO; 216 } 217 }
··· 128 for (slice = off >> 5; slice <= (off + count - 1) >> 5; slice++) 129 eeprom_update_client(client, slice); 130 131 + /* Hide Vaio private settings to regular users: 132 + - BIOS passwords: bytes 0x00 to 0x0f 133 + - UUID: bytes 0x10 to 0x1f 134 + - Serial number: 0xc0 to 0xdf */ 135 + if (data->nature == VAIO && !capable(CAP_SYS_ADMIN)) { 136 + int i; 137 + 138 + for (i = 0; i < count; i++) { 139 + if ((off + i <= 0x1f) || 140 + (off + i >= 0xc0 && off + i <= 0xdf)) 141 + buf[i] = 0; 142 + else 143 + buf[i] = data->data[off + i]; 144 + } 145 } else { 146 memcpy(buf, &data->data[off], count); 147 } ··· 197 goto exit_kfree; 198 199 /* Detect the Vaio nature of EEPROMs. 200 + We use the "PCG-" or "VGN-" prefix as the signature. */ 201 if (address == 0x57) { 202 + char name[4]; 203 + 204 + name[0] = i2c_smbus_read_byte_data(new_client, 0x80); 205 + name[1] = i2c_smbus_read_byte(new_client); 206 + name[2] = i2c_smbus_read_byte(new_client); 207 + name[3] = i2c_smbus_read_byte(new_client); 208 + 209 + if (!memcmp(name, "PCG-", 4) || !memcmp(name, "VGN-", 4)) { 210 dev_info(&new_client->dev, "Vaio EEPROM detected, " 211 + "enabling privacy protection\n"); 212 data->nature = VAIO; 213 } 214 }
+1 -2
drivers/i2c/i2c-core.c
··· 673 return 0; 674 } 675 676 - int i2c_check_addr(struct i2c_adapter *adapter, int addr) 677 { 678 int rval; 679 ··· 683 684 return rval; 685 } 686 - EXPORT_SYMBOL(i2c_check_addr); 687 688 int i2c_attach_client(struct i2c_client *client) 689 {
··· 673 return 0; 674 } 675 676 + static int i2c_check_addr(struct i2c_adapter *adapter, int addr) 677 { 678 int rval; 679 ··· 683 684 return rval; 685 } 686 687 int i2c_attach_client(struct i2c_client *client) 688 {
+84 -2
drivers/i2c/i2c-dev.c
··· 38 39 static struct i2c_driver i2cdev_driver; 40 41 struct i2c_dev { 42 struct list_head list; 43 struct i2c_adapter *adap; ··· 112 } 113 static DEVICE_ATTR(name, S_IRUGO, show_adapter_name, NULL); 114 115 static ssize_t i2cdev_read (struct file *file, char __user *buf, size_t count, 116 loff_t *offset) 117 { ··· 182 return ret; 183 } 184 185 static int i2cdev_ioctl(struct inode *inode, struct file *file, 186 unsigned int cmd, unsigned long arg) 187 { ··· 223 switch ( cmd ) { 224 case I2C_SLAVE: 225 case I2C_SLAVE_FORCE: 226 if ((arg > 0x3ff) || 227 (((client->flags & I2C_M_TEN) == 0) && arg > 0x7f)) 228 return -EINVAL; 229 - if ((cmd == I2C_SLAVE) && i2c_check_addr(client->adapter,arg)) 230 return -EBUSY; 231 client->addr = arg; 232 return 0; 233 case I2C_TENBIT: ··· 448 if (!adap) 449 return -ENODEV; 450 451 client = kzalloc(sizeof(*client), GFP_KERNEL); 452 if (!client) { 453 i2c_put_adapter(adap); ··· 463 snprintf(client->name, I2C_NAME_SIZE, "i2c-dev %d", adap->nr); 464 client->driver = &i2cdev_driver; 465 466 - /* registered with adapter, passed as client to user */ 467 client->adapter = adap; 468 file->private_data = client; 469 ··· 489 .open = i2cdev_open, 490 .release = i2cdev_release, 491 }; 492 493 static struct class *i2c_dev_class; 494 ··· 561 .detach_adapter = i2cdev_detach_adapter, 562 .detach_client = i2cdev_detach_client, 563 }; 564 565 static int __init i2c_dev_init(void) 566 {
··· 38 39 static struct i2c_driver i2cdev_driver; 40 41 + /* 42 + * An i2c_dev represents an i2c_adapter ... an I2C or SMBus master, not a 43 + * slave (i2c_client) with which messages will be exchanged. It's coupled 44 + * with a character special file which is accessed by user mode drivers. 45 + * 46 + * The list of i2c_dev structures is parallel to the i2c_adapter lists 47 + * maintained by the driver model, and is updated using notifications 48 + * delivered to the i2cdev_driver. 49 + */ 50 struct i2c_dev { 51 struct list_head list; 52 struct i2c_adapter *adap; ··· 103 } 104 static DEVICE_ATTR(name, S_IRUGO, show_adapter_name, NULL); 105 106 + /* ------------------------------------------------------------------------- */ 107 + 108 + /* 109 + * After opening an instance of this character special file, a file 110 + * descriptor starts out associated only with an i2c_adapter (and bus). 111 + * 112 + * Using the I2C_RDWR ioctl(), you can then *immediately* issue i2c_msg 113 + * traffic to any devices on the bus used by that adapter. That's because 114 + * the i2c_msg vectors embed all the addressing information they need, and 115 + * are submitted directly to an i2c_adapter. However, SMBus-only adapters 116 + * don't support that interface. 117 + * 118 + * To use read()/write() system calls on that file descriptor, or to use 119 + * SMBus interfaces (and work with SMBus-only hosts!), you must first issue 120 + * an I2C_SLAVE (or I2C_SLAVE_FORCE) ioctl. That configures an anonymous 121 + * (never registered) i2c_client so it holds the addressing information 122 + * needed by those system calls and by this SMBus interface. 123 + */ 124 + 125 static ssize_t i2cdev_read (struct file *file, char __user *buf, size_t count, 126 loff_t *offset) 127 { ··· 154 return ret; 155 } 156 157 + /* This address checking function differs from the one in i2c-core 158 + in that it considers an address with a registered device, but no 159 + bounded driver, as NOT busy. */ 160 + static int i2cdev_check_addr(struct i2c_adapter *adapter, unsigned int addr) 161 + { 162 + struct list_head *item; 163 + struct i2c_client *client; 164 + int res = 0; 165 + 166 + mutex_lock(&adapter->clist_lock); 167 + list_for_each(item, &adapter->clients) { 168 + client = list_entry(item, struct i2c_client, list); 169 + if (client->addr == addr) { 170 + if (client->driver) 171 + res = -EBUSY; 172 + break; 173 + } 174 + } 175 + mutex_unlock(&adapter->clist_lock); 176 + 177 + return res; 178 + } 179 + 180 static int i2cdev_ioctl(struct inode *inode, struct file *file, 181 unsigned int cmd, unsigned long arg) 182 { ··· 172 switch ( cmd ) { 173 case I2C_SLAVE: 174 case I2C_SLAVE_FORCE: 175 + /* NOTE: devices set up to work with "new style" drivers 176 + * can't use I2C_SLAVE, even when the device node is not 177 + * bound to a driver. Only I2C_SLAVE_FORCE will work. 178 + * 179 + * Setting the PEC flag here won't affect kernel drivers, 180 + * which will be using the i2c_client node registered with 181 + * the driver model core. Likewise, when that client has 182 + * the PEC flag already set, the i2c-dev driver won't see 183 + * (or use) this setting. 184 + */ 185 if ((arg > 0x3ff) || 186 (((client->flags & I2C_M_TEN) == 0) && arg > 0x7f)) 187 return -EINVAL; 188 + if (cmd == I2C_SLAVE && i2cdev_check_addr(client->adapter, arg)) 189 return -EBUSY; 190 + /* REVISIT: address could become busy later */ 191 client->addr = arg; 192 return 0; 193 case I2C_TENBIT: ··· 386 if (!adap) 387 return -ENODEV; 388 389 + /* This creates an anonymous i2c_client, which may later be 390 + * pointed to some address using I2C_SLAVE or I2C_SLAVE_FORCE. 391 + * 392 + * This client is ** NEVER REGISTERED ** with the driver model 393 + * or I2C core code!! It just holds private copies of addressing 394 + * information and maybe a PEC flag. 395 + */ 396 client = kzalloc(sizeof(*client), GFP_KERNEL); 397 if (!client) { 398 i2c_put_adapter(adap); ··· 394 snprintf(client->name, I2C_NAME_SIZE, "i2c-dev %d", adap->nr); 395 client->driver = &i2cdev_driver; 396 397 client->adapter = adap; 398 file->private_data = client; 399 ··· 421 .open = i2cdev_open, 422 .release = i2cdev_release, 423 }; 424 + 425 + /* ------------------------------------------------------------------------- */ 426 + 427 + /* 428 + * The legacy "i2cdev_driver" is used primarily to get notifications when 429 + * I2C adapters are added or removed, so that each one gets an i2c_dev 430 + * and is thus made available to userspace driver code. 431 + */ 432 433 static struct class *i2c_dev_class; 434 ··· 485 .detach_adapter = i2cdev_detach_adapter, 486 .detach_client = i2cdev_detach_client, 487 }; 488 + 489 + /* ------------------------------------------------------------------------- */ 490 + 491 + /* 492 + * module load/unload record keeping 493 + */ 494 495 static int __init i2c_dev_init(void) 496 {
-5
include/linux/i2c.h
··· 400 extern void i2c_clients_command(struct i2c_adapter *adap, 401 unsigned int cmd, void *arg); 402 403 - /* returns -EBUSY if address has been taken, 0 if not. Note that the only 404 - other place at which this is called is within i2c_attach_client; so 405 - you can cheat by simply not registering. Not recommended, of course! */ 406 - extern int i2c_check_addr (struct i2c_adapter *adapter, int addr); 407 - 408 /* Detect function. It iterates over all possible addresses itself. 409 * It will only call found_proc if some client is connected at the 410 * specific address (unless a 'force' matched);
··· 400 extern void i2c_clients_command(struct i2c_adapter *adap, 401 unsigned int cmd, void *arg); 402 403 /* Detect function. It iterates over all possible addresses itself. 404 * It will only call found_proc if some client is connected at the 405 * specific address (unless a 'force' matched);