Commit 24cba406 authored by Jonathan Cameron's avatar Jonathan Cameron Committed by Greg Kroah-Hartman

staging:iio:adc:ad799x use a table for frequency values rather than big switch.

Signed-off-by: default avatarJonathan Cameron <jic23@cam.ac.uk>
Acked-by: default avatarMichael Hennerich <michael.hennerich@analog.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 5357ba3d
...@@ -169,7 +169,15 @@ static int ad799x_read_raw(struct iio_dev *dev_info, ...@@ -169,7 +169,15 @@ static int ad799x_read_raw(struct iio_dev *dev_info,
} }
return -EINVAL; return -EINVAL;
} }
static const unsigned int ad7998_frequencies[] = {
[AD7998_CYC_DIS] = 0,
[AD7998_CYC_TCONF_32] = 15625,
[AD7998_CYC_TCONF_64] = 7812,
[AD7998_CYC_TCONF_128] = 3906,
[AD7998_CYC_TCONF_512] = 976,
[AD7998_CYC_TCONF_1024] = 488,
[AD7998_CYC_TCONF_2048] = 244,
};
static ssize_t ad799x_read_frequency(struct device *dev, static ssize_t ad799x_read_frequency(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
char *buf) char *buf)
...@@ -177,7 +185,7 @@ static ssize_t ad799x_read_frequency(struct device *dev, ...@@ -177,7 +185,7 @@ static ssize_t ad799x_read_frequency(struct device *dev,
struct iio_dev *dev_info = dev_get_drvdata(dev); struct iio_dev *dev_info = dev_get_drvdata(dev);
struct ad799x_state *st = iio_priv(dev_info); struct ad799x_state *st = iio_priv(dev_info);
int ret, len = 0; int ret;
u8 val; u8 val;
ret = ad799x_i2c_read8(st, AD7998_CYCLE_TMR_REG, &val); ret = ad799x_i2c_read8(st, AD7998_CYCLE_TMR_REG, &val);
if (ret) if (ret)
...@@ -185,33 +193,7 @@ static ssize_t ad799x_read_frequency(struct device *dev, ...@@ -185,33 +193,7 @@ static ssize_t ad799x_read_frequency(struct device *dev,
val &= AD7998_CYC_MASK; val &= AD7998_CYC_MASK;
switch (val) { return sprintf(buf, "%u\n", ad7998_frequencies[val]);
case AD7998_CYC_DIS:
len = sprintf(buf, "0\n");
break;
case AD7998_CYC_TCONF_32:
len = sprintf(buf, "15625\n");
break;
case AD7998_CYC_TCONF_64:
len = sprintf(buf, "7812\n");
break;
case AD7998_CYC_TCONF_128:
len = sprintf(buf, "3906\n");
break;
case AD7998_CYC_TCONF_256:
len = sprintf(buf, "1953\n");
break;
case AD7998_CYC_TCONF_512:
len = sprintf(buf, "976\n");
break;
case AD7998_CYC_TCONF_1024:
len = sprintf(buf, "488\n");
break;
case AD7998_CYC_TCONF_2048:
len = sprintf(buf, "244\n");
break;
}
return len;
} }
static ssize_t ad799x_write_frequency(struct device *dev, static ssize_t ad799x_write_frequency(struct device *dev,
...@@ -223,7 +205,7 @@ static ssize_t ad799x_write_frequency(struct device *dev, ...@@ -223,7 +205,7 @@ static ssize_t ad799x_write_frequency(struct device *dev,
struct ad799x_state *st = iio_priv(dev_info); struct ad799x_state *st = iio_priv(dev_info);
long val; long val;
int ret; int ret, i;
u8 t; u8 t;
ret = strict_strtol(buf, 10, &val); ret = strict_strtol(buf, 10, &val);
...@@ -237,36 +219,14 @@ static ssize_t ad799x_write_frequency(struct device *dev, ...@@ -237,36 +219,14 @@ static ssize_t ad799x_write_frequency(struct device *dev,
/* Wipe the bits clean */ /* Wipe the bits clean */
t &= ~AD7998_CYC_MASK; t &= ~AD7998_CYC_MASK;
switch (val) { for (i = 0; i < ARRAY_SIZE(ad7998_frequencies); i++)
case 15625: if (val == ad7998_frequencies[i])
t |= AD7998_CYC_TCONF_32;
break;
case 7812:
t |= AD7998_CYC_TCONF_64;
break;
case 3906:
t |= AD7998_CYC_TCONF_128;
break;
case 1953:
t |= AD7998_CYC_TCONF_256;
break;
case 976:
t |= AD7998_CYC_TCONF_512;
break;
case 488:
t |= AD7998_CYC_TCONF_1024;
break; break;
case 244: if (i == ARRAY_SIZE(ad7998_frequencies)) {
t |= AD7998_CYC_TCONF_2048;
break;
case 0:
t |= AD7998_CYC_DIS;
break;
default:
ret = -EINVAL; ret = -EINVAL;
goto error_ret_mutex; goto error_ret_mutex;
} }
t |= i;
ret = ad799x_i2c_write8(st, AD7998_CYCLE_TMR_REG, t); ret = ad799x_i2c_write8(st, AD7998_CYCLE_TMR_REG, t);
error_ret_mutex: error_ret_mutex:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment