Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 354189
b: refs/heads/master
c: 3f6a0ba
h: refs/heads/master
i:
  354187: 4dc0e16
v: v3
  • Loading branch information
Lars-Peter Clausen authored and Jonathan Cameron committed Jan 26, 2013
1 parent e8c7aa1 commit eb2a570
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 67 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: 06ddd353f5c8678238d519dcecf9d557e5e1f7a6
refs/heads/master: 3f6a0bad61e34c648fd08ff8dcbfdd58148963d2
78 changes: 12 additions & 66 deletions trunk/drivers/staging/iio/light/tsl2x7x_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,59 +291,6 @@ static const u8 device_channel_config[] = {
ALSPRX2
};

/**
* tsl2x7x_parse_buffer() - parse a decimal result from a buffer.
* @*buf: pointer to char buffer to parse
* @*result: pointer to buffer to contain
* resulting interger / decimal as ints.
*
*/
static int
tsl2x7x_parse_buffer(const char *buf, struct tsl2x7x_parse_result *result)
{
int integer = 0, fract = 0, fract_mult = 100000;
bool integer_part = true, negative = false;

if (buf[0] == '-') {
negative = true;
buf++;
}

while (*buf) {
if ('0' <= *buf && *buf <= '9') {
if (integer_part)
integer = integer*10 + *buf - '0';
else {
fract += fract_mult*(*buf - '0');
if (fract_mult == 1)
break;
fract_mult /= 10;
}
} else if (*buf == '\n') {
if (*(buf + 1) == '\0')
break;
else
return -EINVAL;
} else if (*buf == '.') {
integer_part = false;
} else {
return -EINVAL;
}
buf++;
}
if (negative) {
if (integer)
integer = -integer;
else
fract = -fract;
}

result->integer = integer;
result->fract = fract;

return 0;
}

/**
* tsl2x7x_i2c_read() - Read a byte from a register.
* @client: i2c client
Expand Down Expand Up @@ -1036,13 +983,12 @@ static ssize_t tsl2x7x_als_time_store(struct device *dev,
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
struct tsl2X7X_chip *chip = iio_priv(indio_dev);
struct tsl2x7x_parse_result result;
int ret;

result.integer = 0;
result.fract = 0;

tsl2x7x_parse_buffer(buf, &result);
ret = iio_str_to_fixpoint(buf, 100, &result.integer, &result.fract);
if (ret)
return ret;

result.fract /= 1000;
result.fract /= 3;
chip->tsl2x7x_settings.als_time =
(TSL2X7X_MAX_TIMER_CNT - (u8)result.fract);
Expand Down Expand Up @@ -1109,12 +1055,12 @@ static ssize_t tsl2x7x_als_persistence_store(struct device *dev,
struct tsl2X7X_chip *chip = iio_priv(indio_dev);
struct tsl2x7x_parse_result result;
int y, z, filter_delay;
int ret;

result.integer = 0;
result.fract = 0;
tsl2x7x_parse_buffer(buf, &result);
ret = iio_str_to_fixpoint(buf, 100, &result.integer, &result.fract);
if (ret)
return ret;

result.fract /= 1000;
y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->tsl2x7x_settings.als_time) + 1;
z = y * TSL2X7X_MIN_ITIME;

Expand Down Expand Up @@ -1155,12 +1101,12 @@ static ssize_t tsl2x7x_prox_persistence_store(struct device *dev,
struct tsl2X7X_chip *chip = iio_priv(indio_dev);
struct tsl2x7x_parse_result result;
int y, z, filter_delay;
int ret;

result.integer = 0;
result.fract = 0;
tsl2x7x_parse_buffer(buf, &result);
ret = iio_str_to_fixpoint(buf, 100, &result.integer, &result.fract);
if (ret)
return ret;

result.fract /= 1000;
y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->tsl2x7x_settings.prx_time) + 1;
z = y * TSL2X7X_MIN_ITIME;

Expand Down

0 comments on commit eb2a570

Please sign in to comment.