aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2007-07-12 08:12:31 -0400
committerJean Delvare <khali@hyperion.delvare>2007-07-12 08:12:31 -0400
commite296fb7f301f3c3398adc6d991b097cfa73e1c0c (patch)
tree8eb4fe324010c0bcd11e590334c69c224ad034ad /drivers/i2c
parentb9cdad74883a797952de52464d118d685cafc05a (diff)
i2c/tsl2550: Speed up initialization
There's some redundancy in the tsl2550 initialization sequence. It is powering up the device twice, and setting the operating mode twice too. Setting things just once saves SMBus transactions, which aren't always cheap, speeding up the device initialization. Signed-off-by: Jean Delvare <khali@linux-fr.org> Cc: Rodolfo Giometti <giometti@linux.it>
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/chips/tsl2550.c46
1 files changed, 26 insertions, 20 deletions
diff --git a/drivers/i2c/chips/tsl2550.c b/drivers/i2c/chips/tsl2550.c
index ef80330b855f..3de4b19ba08f 100644
--- a/drivers/i2c/chips/tsl2550.c
+++ b/drivers/i2c/chips/tsl2550.c
@@ -27,7 +27,7 @@
27#include <linux/delay.h> 27#include <linux/delay.h>
28 28
29#define TSL2550_DRV_NAME "tsl2550" 29#define TSL2550_DRV_NAME "tsl2550"
30#define DRIVER_VERSION "1.1.0" 30#define DRIVER_VERSION "1.1.1"
31 31
32/* 32/*
33 * Defines 33 * Defines
@@ -333,13 +333,30 @@ static const struct attribute_group tsl2550_attr_group = {
333 * Initialization function 333 * Initialization function
334 */ 334 */
335 335
336static void tsl2550_init_client(struct i2c_client *client) 336static int tsl2550_init_client(struct i2c_client *client)
337{ 337{
338 struct tsl2550_data *data = i2c_get_clientdata(client); 338 struct tsl2550_data *data = i2c_get_clientdata(client);
339 int err;
339 340
340 /* Power up the device and set the default operating mode */ 341 /*
341 tsl2550_set_power_state(client, 1); 342 * Probe the chip. To do so we try to power up the device and then to
342 tsl2550_set_operating_mode(client, data->operating_mode); 343 * read back the 0x03 code
344 */
345 err = i2c_smbus_write_byte(client, TSL2550_POWER_UP);
346 if (err < 0)
347 return err;
348 mdelay(1);
349 if (i2c_smbus_read_byte(client) != TSL2550_POWER_UP)
350 return -ENODEV;
351 data->power_state = 1;
352
353 /* Set the default operating mode */
354 err = i2c_smbus_write_byte(client,
355 TSL2550_MODE_RANGE[data->operating_mode]);
356 if (err < 0)
357 return err;
358
359 return 0;
343} 360}
344 361
345/* 362/*
@@ -381,24 +398,12 @@ static int __devinit tsl2550_probe(struct i2c_client *client)
381 dev_info(&client->dev, "%s operating mode\n", 398 dev_info(&client->dev, "%s operating mode\n",
382 data->operating_mode ? "extended" : "standard"); 399 data->operating_mode ? "extended" : "standard");
383 400
384 /*
385 * Probe the chip. To do so we try to power up the device and then to
386 * read back the 0x03 code
387 */
388 err = i2c_smbus_write_byte(client, TSL2550_POWER_UP);
389 if (err < 0)
390 goto exit_kfree;
391 mdelay(1);
392 err = i2c_smbus_read_byte(client);
393 if (err != TSL2550_POWER_UP) {
394 err = -ENODEV;
395 goto exit_kfree;
396 }
397
398 mutex_init(&data->update_lock); 401 mutex_init(&data->update_lock);
399 402
400 /* Initialize the TSL2550 chip */ 403 /* Initialize the TSL2550 chip */
401 tsl2550_init_client(client); 404 err = tsl2550_init_client(client);
405 if (err)
406 goto exit_kfree;
402 407
403 /* Register sysfs hooks */ 408 /* Register sysfs hooks */
404 err = sysfs_create_group(&client->dev.kobj, &tsl2550_attr_group); 409 err = sysfs_create_group(&client->dev.kobj, &tsl2550_attr_group);
@@ -449,6 +454,7 @@ static void __exit tsl2550_exit(void)
449MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>"); 454MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>");
450MODULE_DESCRIPTION("TSL2550 ambient light sensor driver"); 455MODULE_DESCRIPTION("TSL2550 ambient light sensor driver");
451MODULE_LICENSE("GPL"); 456MODULE_LICENSE("GPL");
457MODULE_VERSION(DRIVER_VERSION);
452 458
453module_init(tsl2550_init); 459module_init(tsl2550_init);
454module_exit(tsl2550_exit); 460module_exit(tsl2550_exit);