* [PATCH] iio: adc: max1363: implemented IIO_CHAN_INFO_SAMP_FREQ
@ 2016-10-12 22:10 Juliana Rodrigues
0 siblings, 0 replies; only message in thread
From: Juliana Rodrigues @ 2016-10-12 22:10 UTC (permalink / raw)
To: lars, jic23, knaack.h, pmeerw; +Cc: outreachy-kernel
Moved functionality from IIO_DEV_ATTR_SAMP_FREQ macro into
IIO_CHAN_INFO_SAMP_FREQ. Modified max1363_read_raw and added
max1363_write_raw to allow reading and writing the element.
Signed-off-by: Juliana Rodrigues <juliana.orod@gmail.com>
---
drivers/iio/adc/max1363.c | 98 +++++++++++++++++++++++++----------------------
1 file changed, 53 insertions(+), 45 deletions(-)
diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c
index 841a13c..6aa7e15 100644
--- a/drivers/iio/adc/max1363.c
+++ b/drivers/iio/adc/max1363.c
@@ -413,6 +413,34 @@ static int max1363_read_single_chan(struct iio_dev *indio_dev,
}
+static const int max1363_monitor_speeds[] = { 133000, 665000, 33300, 16600,
+ 8300, 4200, 2000, 1000 };
+
+/**
+ * write_raw handler for IIO_CHAN_INFO_SAMP_FREQ
+ */
+int max1363_write_raw_samp_freq(struct iio_dev *indio_dev,
+ struct max1363_state *st, int *val)
+{
+
+ int i, ret;
+ bool found = false;
+
+ for (i = 0; i < ARRAY_SIZE(max1363_monitor_speeds); i++)
+ if (ret == max1363_monitor_speeds[i]) {
+ found = true;
+ break;
+ }
+ if (!found)
+ return -EINVAL;
+
+ mutex_lock(&indio_dev->mlock);
+ st->monitor_speed = i;
+ mutex_unlock(&indio_dev->mlock);
+
+ return 0;
+}
+
static int max1363_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val,
@@ -432,12 +460,34 @@ static int max1363_read_raw(struct iio_dev *indio_dev,
*val = st->vref_uv / 1000;
*val2 = st->chip_info->bits;
return IIO_VAL_FRACTIONAL_LOG2;
+ case IIO_CHAN_INFO_SAMP_FREQ:
+ *val = max1363_monitor_speeds[st->monitor_speed];
+ return IIO_VAL_INT;
+
default:
return -EINVAL;
}
return 0;
}
+static int max1363_write_raw(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan,
+ int val,
+ int val2,
+ long m)
+{
+ struct max1363_state *st = iio_priv(indio_dev);
+
+ switch (m) {
+
+ case IIO_CHAN_INFO_SAMP_FREQ:
+ return max1363_write_raw_samp_freq(indio_dev, st, &val);
+
+ default:
+ return -EINVAL;
+ }
+}
+
/* Applies to max1363 */
static const enum max1363_modes max1363_mode_list[] = {
_s0, _s1, _s2, _s3,
@@ -468,6 +518,7 @@ static const struct iio_event_spec max1363_events[] = {
.address = addr, \
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
+ .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),\
.datasheet_name = "AIN"#num, \
.scan_type = { \
.sign = 'u', \
@@ -491,6 +542,7 @@ static const struct iio_event_spec max1363_events[] = {
.address = addr, \
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
+ .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),\
.datasheet_name = "AIN"#num"-AIN"#num2, \
.scan_type = { \
.sign = 's', \
@@ -675,50 +727,6 @@ enum { max1361,
max11647
};
-static const int max1363_monitor_speeds[] = { 133000, 665000, 33300, 16600,
- 8300, 4200, 2000, 1000 };
-
-static ssize_t max1363_monitor_show_freq(struct device *dev,
- struct device_attribute *attr,
- char *buf)
-{
- struct max1363_state *st = iio_priv(dev_to_iio_dev(dev));
- return sprintf(buf, "%d\n", max1363_monitor_speeds[st->monitor_speed]);
-}
-
-static ssize_t max1363_monitor_store_freq(struct device *dev,
- struct device_attribute *attr,
- const char *buf,
- size_t len)
-{
- struct iio_dev *indio_dev = dev_to_iio_dev(dev);
- struct max1363_state *st = iio_priv(indio_dev);
- int i, ret;
- unsigned long val;
- bool found = false;
-
- ret = kstrtoul(buf, 10, &val);
- if (ret)
- return -EINVAL;
- for (i = 0; i < ARRAY_SIZE(max1363_monitor_speeds); i++)
- if (val == max1363_monitor_speeds[i]) {
- found = true;
- break;
- }
- if (!found)
- return -EINVAL;
-
- mutex_lock(&indio_dev->mlock);
- st->monitor_speed = i;
- mutex_unlock(&indio_dev->mlock);
-
- return 0;
-}
-
-static IIO_DEV_ATTR_SAMP_FREQ(S_IRUGO | S_IWUSR,
- max1363_monitor_show_freq,
- max1363_monitor_store_freq);
-
static IIO_CONST_ATTR(sampling_frequency_available,
"133000 665000 33300 16600 8300 4200 2000 1000");
@@ -1002,7 +1010,6 @@ static int max1363_write_event_config(struct iio_dev *indio_dev,
* be combined.
*/
static struct attribute *max1363_event_attributes[] = {
- &iio_dev_attr_sampling_frequency.dev_attr.attr,
&iio_const_attr_sampling_frequency_available.dev_attr.attr,
NULL,
};
@@ -1039,6 +1046,7 @@ static const struct iio_info max1363_info = {
.read_event_config = &max1363_read_event_config,
.write_event_config = &max1363_write_event_config,
.read_raw = &max1363_read_raw,
+ .write_raw = &max1363_write_raw,
.update_scan_mode = &max1363_update_scan_mode,
.driver_module = THIS_MODULE,
.event_attrs = &max1363_event_attribute_group,
--
2.10.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2016-10-12 22:10 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-12 22:10 [PATCH] iio: adc: max1363: implemented IIO_CHAN_INFO_SAMP_FREQ Juliana Rodrigues
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.