Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 165148
b: refs/heads/master
c: ac78094
h: refs/heads/master
v: v3
  • Loading branch information
Jean Delvare committed Sep 18, 2009
1 parent ac4e8bc commit 8572125
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 33 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 27693ce5f372c0af3b0730f5152b35432afa0fd7
refs/heads/master: ac7809414fb1e3e49b88ad6016e57598594aa4e2
42 changes: 10 additions & 32 deletions trunk/drivers/i2c/chips/tsl2550.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/mutex.h>
#include <linux/delay.h>

#define TSL2550_DRV_NAME "tsl2550"
#define DRIVER_VERSION "1.1.2"
#define DRIVER_VERSION "1.2"

/*
* Defines
Expand Down Expand Up @@ -96,32 +95,13 @@ static int tsl2550_set_power_state(struct i2c_client *client, int state)

static int tsl2550_get_adc_value(struct i2c_client *client, u8 cmd)
{
unsigned long end;
int loop = 0, ret = 0;
int ret;

/*
* Read ADC channel waiting at most 400ms (see data sheet for further
* info).
* To avoid long busy wait we spin for few milliseconds then
* start sleeping.
*/
end = jiffies + msecs_to_jiffies(400);
while (time_before(jiffies, end)) {
i2c_smbus_write_byte(client, cmd);

if (loop++ < 5)
mdelay(1);
else
msleep(1);

ret = i2c_smbus_read_byte(client);
if (ret < 0)
return ret;
else if (ret & 0x0080)
break;
}
ret = i2c_smbus_read_byte_data(client, cmd);
if (ret < 0)
return ret;
if (!(ret & 0x80))
return -EIO;
return -EAGAIN;
return ret & 0x7f; /* remove the "valid" bit */
}

Expand Down Expand Up @@ -285,8 +265,6 @@ static ssize_t __tsl2550_show_lux(struct i2c_client *client, char *buf)
return ret;
ch0 = ret;

mdelay(1);

ret = tsl2550_get_adc_value(client, TSL2550_READ_ADC1);
if (ret < 0)
return ret;
Expand Down Expand Up @@ -345,11 +323,10 @@ static int tsl2550_init_client(struct i2c_client *client)
* Probe the chip. To do so we try to power up the device and then to
* read back the 0x03 code
*/
err = i2c_smbus_write_byte(client, TSL2550_POWER_UP);
err = i2c_smbus_read_byte_data(client, TSL2550_POWER_UP);
if (err < 0)
return err;
mdelay(1);
if (i2c_smbus_read_byte(client) != TSL2550_POWER_UP)
if (err != TSL2550_POWER_UP)
return -ENODEV;
data->power_state = 1;

Expand All @@ -374,7 +351,8 @@ static int __devinit tsl2550_probe(struct i2c_client *client,
struct tsl2550_data *data;
int *opmode, err = 0;

if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) {
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BYTE
| I2C_FUNC_SMBUS_READ_BYTE_DATA)) {
err = -EIO;
goto exit;
}
Expand Down

0 comments on commit 8572125

Please sign in to comment.