aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@woody.linux-foundation.org>2007-11-15 14:01:07 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-11-15 14:01:07 -0500
commitecefe4a1c3dcc802c23ef42de6caa08730cfc1a1 (patch)
tree1f3424530cee33bf3d0561af6af5b5b1ce792527 /drivers
parent279e1dab949d33737557babfe9f74e0b74fbe39a (diff)
parent8b925a3dd8a4d7451092cb9aa11da727ba69e0f0 (diff)
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
Diffstat (limited to 'drivers')
-rw-r--r--drivers/i2c/busses/i2c-pasemi.c7
-rw-r--r--drivers/i2c/chips/eeprom.c37
-rw-r--r--drivers/i2c/i2c-core.c3
-rw-r--r--drivers/i2c/i2c-dev.c86
4 files changed, 115 insertions, 18 deletions
diff --git a/drivers/i2c/busses/i2c-pasemi.c b/drivers/i2c/busses/i2c-pasemi.c
index 58e32714afb5..ca18e0be4901 100644
--- a/drivers/i2c/busses/i2c-pasemi.c
+++ b/drivers/i2c/busses/i2c-pasemi.c
@@ -51,6 +51,7 @@ struct pasemi_smbus {
51#define MRXFIFO_DATA_M 0x000000ff 51#define MRXFIFO_DATA_M 0x000000ff
52 52
53#define SMSTA_XEN 0x08000000 53#define SMSTA_XEN 0x08000000
54#define SMSTA_MTN 0x00200000
54 55
55#define CTL_MRR 0x00000400 56#define CTL_MRR 0x00000400
56#define CTL_MTR 0x00000200 57#define CTL_MTR 0x00000200
@@ -98,6 +99,10 @@ static unsigned int pasemi_smb_waitready(struct pasemi_smbus *smbus)
98 status = reg_read(smbus, REG_SMSTA); 99 status = reg_read(smbus, REG_SMSTA);
99 } 100 }
100 101
102 /* Got NACK? */
103 if (status & SMSTA_MTN)
104 return -ENXIO;
105
101 if (timeout < 0) { 106 if (timeout < 0) {
102 dev_warn(&smbus->dev->dev, "Timeout, status 0x%08x\n", status); 107 dev_warn(&smbus->dev->dev, "Timeout, status 0x%08x\n", status);
103 reg_write(smbus, REG_SMSTA, status); 108 reg_write(smbus, REG_SMSTA, status);
@@ -364,7 +369,7 @@ static int __devinit pasemi_smb_probe(struct pci_dev *dev,
364 smbus->adapter.algo = &smbus_algorithm; 369 smbus->adapter.algo = &smbus_algorithm;
365 smbus->adapter.algo_data = smbus; 370 smbus->adapter.algo_data = smbus;
366 371
367 /* set up the driverfs linkage to our parent device */ 372 /* set up the sysfs linkage to our parent device */
368 smbus->adapter.dev.parent = &dev->dev; 373 smbus->adapter.dev.parent = &dev->dev;
369 374
370 reg_write(smbus, REG_CTL, (CTL_MTR | CTL_MRR | 375 reg_write(smbus, REG_CTL, (CTL_MTR | CTL_MRR |
diff --git a/drivers/i2c/chips/eeprom.c b/drivers/i2c/chips/eeprom.c
index d3da1fb05b9b..1a7eeebac506 100644
--- a/drivers/i2c/chips/eeprom.c
+++ b/drivers/i2c/chips/eeprom.c
@@ -128,13 +128,20 @@ static ssize_t eeprom_read(struct kobject *kobj, struct bin_attribute *bin_attr,
128 for (slice = off >> 5; slice <= (off + count - 1) >> 5; slice++) 128 for (slice = off >> 5; slice <= (off + count - 1) >> 5; slice++)
129 eeprom_update_client(client, slice); 129 eeprom_update_client(client, slice);
130 130
131 /* Hide Vaio security settings to regular users (16 first bytes) */ 131 /* Hide Vaio private settings to regular users:
132 if (data->nature == VAIO && off < 16 && !capable(CAP_SYS_ADMIN)) { 132 - BIOS passwords: bytes 0x00 to 0x0f
133 size_t in_row1 = 16 - off; 133 - UUID: bytes 0x10 to 0x1f
134 in_row1 = min(in_row1, count); 134 - Serial number: 0xc0 to 0xdf */
135 memset(buf, 0, in_row1); 135 if (data->nature == VAIO && !capable(CAP_SYS_ADMIN)) {
136 if (count - in_row1 > 0) 136 int i;
137 memcpy(buf + in_row1, &data->data[16], count - in_row1); 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 } else { 145 } else {
139 memcpy(buf, &data->data[off], count); 146 memcpy(buf, &data->data[off], count);
140 } 147 }
@@ -197,14 +204,18 @@ static int eeprom_detect(struct i2c_adapter *adapter, int address, int kind)
197 goto exit_kfree; 204 goto exit_kfree;
198 205
199 /* Detect the Vaio nature of EEPROMs. 206 /* Detect the Vaio nature of EEPROMs.
200 We use the "PCG-" prefix as the signature. */ 207 We use the "PCG-" or "VGN-" prefix as the signature. */
201 if (address == 0x57) { 208 if (address == 0x57) {
202 if (i2c_smbus_read_byte_data(new_client, 0x80) == 'P' 209 char name[4];
203 && i2c_smbus_read_byte(new_client) == 'C' 210
204 && i2c_smbus_read_byte(new_client) == 'G' 211 name[0] = i2c_smbus_read_byte_data(new_client, 0x80);
205 && i2c_smbus_read_byte(new_client) == '-') { 212 name[1] = i2c_smbus_read_byte(new_client);
213 name[2] = i2c_smbus_read_byte(new_client);
214 name[3] = i2c_smbus_read_byte(new_client);
215
216 if (!memcmp(name, "PCG-", 4) || !memcmp(name, "VGN-", 4)) {
206 dev_info(&new_client->dev, "Vaio EEPROM detected, " 217 dev_info(&new_client->dev, "Vaio EEPROM detected, "
207 "enabling password protection\n"); 218 "enabling privacy protection\n");
208 data->nature = VAIO; 219 data->nature = VAIO;
209 } 220 }
210 } 221 }
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 1a4e8dc03b36..b5e13e405e72 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -673,7 +673,7 @@ static int __i2c_check_addr(struct i2c_adapter *adapter, unsigned int addr)
673 return 0; 673 return 0;
674} 674}
675 675
676int i2c_check_addr(struct i2c_adapter *adapter, int addr) 676static int i2c_check_addr(struct i2c_adapter *adapter, int addr)
677{ 677{
678 int rval; 678 int rval;
679 679
@@ -683,7 +683,6 @@ int i2c_check_addr(struct i2c_adapter *adapter, int addr)
683 683
684 return rval; 684 return rval;
685} 685}
686EXPORT_SYMBOL(i2c_check_addr);
687 686
688int i2c_attach_client(struct i2c_client *client) 687int i2c_attach_client(struct i2c_client *client)
689{ 688{
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index 5a15e50748de..c21ae20ae362 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -38,6 +38,15 @@
38 38
39static struct i2c_driver i2cdev_driver; 39static 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 */
41struct i2c_dev { 50struct i2c_dev {
42 struct list_head list; 51 struct list_head list;
43 struct i2c_adapter *adap; 52 struct i2c_adapter *adap;
@@ -103,6 +112,25 @@ static ssize_t show_adapter_name(struct device *dev,
103} 112}
104static DEVICE_ATTR(name, S_IRUGO, show_adapter_name, NULL); 113static DEVICE_ATTR(name, S_IRUGO, show_adapter_name, NULL);
105 114
115/* ------------------------------------------------------------------------- */
116
117/*
118 * After opening an instance of this character special file, a file
119 * descriptor starts out associated only with an i2c_adapter (and bus).
120 *
121 * Using the I2C_RDWR ioctl(), you can then *immediately* issue i2c_msg
122 * traffic to any devices on the bus used by that adapter. That's because
123 * the i2c_msg vectors embed all the addressing information they need, and
124 * are submitted directly to an i2c_adapter. However, SMBus-only adapters
125 * don't support that interface.
126 *
127 * To use read()/write() system calls on that file descriptor, or to use
128 * SMBus interfaces (and work with SMBus-only hosts!), you must first issue
129 * an I2C_SLAVE (or I2C_SLAVE_FORCE) ioctl. That configures an anonymous
130 * (never registered) i2c_client so it holds the addressing information
131 * needed by those system calls and by this SMBus interface.
132 */
133
106static ssize_t i2cdev_read (struct file *file, char __user *buf, size_t count, 134static ssize_t i2cdev_read (struct file *file, char __user *buf, size_t count,
107 loff_t *offset) 135 loff_t *offset)
108{ 136{
@@ -154,6 +182,29 @@ static ssize_t i2cdev_write (struct file *file, const char __user *buf, size_t c
154 return ret; 182 return ret;
155} 183}
156 184
185/* This address checking function differs from the one in i2c-core
186 in that it considers an address with a registered device, but no
187 bounded driver, as NOT busy. */
188static int i2cdev_check_addr(struct i2c_adapter *adapter, unsigned int addr)
189{
190 struct list_head *item;
191 struct i2c_client *client;
192 int res = 0;
193
194 mutex_lock(&adapter->clist_lock);
195 list_for_each(item, &adapter->clients) {
196 client = list_entry(item, struct i2c_client, list);
197 if (client->addr == addr) {
198 if (client->driver)
199 res = -EBUSY;
200 break;
201 }
202 }
203 mutex_unlock(&adapter->clist_lock);
204
205 return res;
206}
207
157static int i2cdev_ioctl(struct inode *inode, struct file *file, 208static int i2cdev_ioctl(struct inode *inode, struct file *file,
158 unsigned int cmd, unsigned long arg) 209 unsigned int cmd, unsigned long arg)
159{ 210{
@@ -172,11 +223,22 @@ static int i2cdev_ioctl(struct inode *inode, struct file *file,
172 switch ( cmd ) { 223 switch ( cmd ) {
173 case I2C_SLAVE: 224 case I2C_SLAVE:
174 case I2C_SLAVE_FORCE: 225 case I2C_SLAVE_FORCE:
226 /* NOTE: devices set up to work with "new style" drivers
227 * can't use I2C_SLAVE, even when the device node is not
228 * bound to a driver. Only I2C_SLAVE_FORCE will work.
229 *
230 * Setting the PEC flag here won't affect kernel drivers,
231 * which will be using the i2c_client node registered with
232 * the driver model core. Likewise, when that client has
233 * the PEC flag already set, the i2c-dev driver won't see
234 * (or use) this setting.
235 */
175 if ((arg > 0x3ff) || 236 if ((arg > 0x3ff) ||
176 (((client->flags & I2C_M_TEN) == 0) && arg > 0x7f)) 237 (((client->flags & I2C_M_TEN) == 0) && arg > 0x7f))
177 return -EINVAL; 238 return -EINVAL;
178 if ((cmd == I2C_SLAVE) && i2c_check_addr(client->adapter,arg)) 239 if (cmd == I2C_SLAVE && i2cdev_check_addr(client->adapter, arg))
179 return -EBUSY; 240 return -EBUSY;
241 /* REVISIT: address could become busy later */
180 client->addr = arg; 242 client->addr = arg;
181 return 0; 243 return 0;
182 case I2C_TENBIT: 244 case I2C_TENBIT:
@@ -386,6 +448,13 @@ static int i2cdev_open(struct inode *inode, struct file *file)
386 if (!adap) 448 if (!adap)
387 return -ENODEV; 449 return -ENODEV;
388 450
451 /* This creates an anonymous i2c_client, which may later be
452 * pointed to some address using I2C_SLAVE or I2C_SLAVE_FORCE.
453 *
454 * This client is ** NEVER REGISTERED ** with the driver model
455 * or I2C core code!! It just holds private copies of addressing
456 * information and maybe a PEC flag.
457 */
389 client = kzalloc(sizeof(*client), GFP_KERNEL); 458 client = kzalloc(sizeof(*client), GFP_KERNEL);
390 if (!client) { 459 if (!client) {
391 i2c_put_adapter(adap); 460 i2c_put_adapter(adap);
@@ -394,7 +463,6 @@ static int i2cdev_open(struct inode *inode, struct file *file)
394 snprintf(client->name, I2C_NAME_SIZE, "i2c-dev %d", adap->nr); 463 snprintf(client->name, I2C_NAME_SIZE, "i2c-dev %d", adap->nr);
395 client->driver = &i2cdev_driver; 464 client->driver = &i2cdev_driver;
396 465
397 /* registered with adapter, passed as client to user */
398 client->adapter = adap; 466 client->adapter = adap;
399 file->private_data = client; 467 file->private_data = client;
400 468
@@ -422,6 +490,14 @@ static const struct file_operations i2cdev_fops = {
422 .release = i2cdev_release, 490 .release = i2cdev_release,
423}; 491};
424 492
493/* ------------------------------------------------------------------------- */
494
495/*
496 * The legacy "i2cdev_driver" is used primarily to get notifications when
497 * I2C adapters are added or removed, so that each one gets an i2c_dev
498 * and is thus made available to userspace driver code.
499 */
500
425static struct class *i2c_dev_class; 501static struct class *i2c_dev_class;
426 502
427static int i2cdev_attach_adapter(struct i2c_adapter *adap) 503static int i2cdev_attach_adapter(struct i2c_adapter *adap)
@@ -486,6 +562,12 @@ static struct i2c_driver i2cdev_driver = {
486 .detach_client = i2cdev_detach_client, 562 .detach_client = i2cdev_detach_client,
487}; 563};
488 564
565/* ------------------------------------------------------------------------- */
566
567/*
568 * module load/unload record keeping
569 */
570
489static int __init i2c_dev_init(void) 571static int __init i2c_dev_init(void)
490{ 572{
491 int res; 573 int res;