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 51 #define MRXFIFO_DATA_M 0x000000ff 52 52 53 53 #define SMSTA_XEN 0x08000000 54 + #define SMSTA_MTN 0x00200000 54 55 55 56 #define CTL_MRR 0x00000400 56 57 #define CTL_MTR 0x00000200 ··· 98 97 msleep(1); 99 98 status = reg_read(smbus, REG_SMSTA); 100 99 } 100 + 101 + /* Got NACK? */ 102 + if (status & SMSTA_MTN) 103 + return -ENXIO; 101 104 102 105 if (timeout < 0) { 103 106 dev_warn(&smbus->dev->dev, "Timeout, status 0x%08x\n", status); ··· 369 364 smbus->adapter.algo = &smbus_algorithm; 370 365 smbus->adapter.algo_data = smbus; 371 366 372 - /* set up the driverfs linkage to our parent device */ 367 + /* set up the sysfs linkage to our parent device */ 373 368 smbus->adapter.dev.parent = &dev->dev; 374 369 375 370 reg_write(smbus, REG_CTL, (CTL_MTR | CTL_MRR |
+24 -13
drivers/i2c/chips/eeprom.c
··· 128 128 for (slice = off >> 5; slice <= (off + count - 1) >> 5; slice++) 129 129 eeprom_update_client(client, slice); 130 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); 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 + } 138 145 } else { 139 146 memcpy(buf, &data->data[off], count); 140 147 } ··· 204 197 goto exit_kfree; 205 198 206 199 /* Detect the Vaio nature of EEPROMs. 207 - We use the "PCG-" prefix as the signature. */ 200 + We use the "PCG-" or "VGN-" prefix as the signature. */ 208 201 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) == '-') { 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)) { 213 210 dev_info(&new_client->dev, "Vaio EEPROM detected, " 214 - "enabling password protection\n"); 211 + "enabling privacy protection\n"); 215 212 data->nature = VAIO; 216 213 } 217 214 }
+1 -2
drivers/i2c/i2c-core.c
··· 673 673 return 0; 674 674 } 675 675 676 - int i2c_check_addr(struct i2c_adapter *adapter, int addr) 676 + static int i2c_check_addr(struct i2c_adapter *adapter, int addr) 677 677 { 678 678 int rval; 679 679 ··· 683 683 684 684 return rval; 685 685 } 686 - EXPORT_SYMBOL(i2c_check_addr); 687 686 688 687 int i2c_attach_client(struct i2c_client *client) 689 688 {
+84 -2
drivers/i2c/i2c-dev.c
··· 38 38 39 39 static struct i2c_driver i2cdev_driver; 40 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 + */ 41 50 struct i2c_dev { 42 51 struct list_head list; 43 52 struct i2c_adapter *adap; ··· 112 103 } 113 104 static DEVICE_ATTR(name, S_IRUGO, show_adapter_name, NULL); 114 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 + 115 125 static ssize_t i2cdev_read (struct file *file, char __user *buf, size_t count, 116 126 loff_t *offset) 117 127 { ··· 182 154 return ret; 183 155 } 184 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 + 185 180 static int i2cdev_ioctl(struct inode *inode, struct file *file, 186 181 unsigned int cmd, unsigned long arg) 187 182 { ··· 223 172 switch ( cmd ) { 224 173 case I2C_SLAVE: 225 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 + */ 226 185 if ((arg > 0x3ff) || 227 186 (((client->flags & I2C_M_TEN) == 0) && arg > 0x7f)) 228 187 return -EINVAL; 229 - if ((cmd == I2C_SLAVE) && i2c_check_addr(client->adapter,arg)) 188 + if (cmd == I2C_SLAVE && i2cdev_check_addr(client->adapter, arg)) 230 189 return -EBUSY; 190 + /* REVISIT: address could become busy later */ 231 191 client->addr = arg; 232 192 return 0; 233 193 case I2C_TENBIT: ··· 448 386 if (!adap) 449 387 return -ENODEV; 450 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 + */ 451 396 client = kzalloc(sizeof(*client), GFP_KERNEL); 452 397 if (!client) { 453 398 i2c_put_adapter(adap); ··· 463 394 snprintf(client->name, I2C_NAME_SIZE, "i2c-dev %d", adap->nr); 464 395 client->driver = &i2cdev_driver; 465 396 466 - /* registered with adapter, passed as client to user */ 467 397 client->adapter = adap; 468 398 file->private_data = client; 469 399 ··· 489 421 .open = i2cdev_open, 490 422 .release = i2cdev_release, 491 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 + */ 492 432 493 433 static struct class *i2c_dev_class; 494 434 ··· 561 485 .detach_adapter = i2cdev_detach_adapter, 562 486 .detach_client = i2cdev_detach_client, 563 487 }; 488 + 489 + /* ------------------------------------------------------------------------- */ 490 + 491 + /* 492 + * module load/unload record keeping 493 + */ 564 494 565 495 static int __init i2c_dev_init(void) 566 496 {
-5
include/linux/i2c.h
··· 400 400 extern void i2c_clients_command(struct i2c_adapter *adap, 401 401 unsigned int cmd, void *arg); 402 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 403 /* Detect function. It iterates over all possible addresses itself. 409 404 * It will only call found_proc if some client is connected at the 410 405 * specific address (unless a 'force' matched);