From: Juliana Rodrigues <juliana.orod@gmail.com>
To: lars@metafoo.de, jic23@kernel.org, knaack.h@gmx.de, pmeerw@pmeerw.net
Cc: outreachy-kernel@googlegroups.com
Subject: [PATCH] iio: adc: max1363: implemented IIO_CHAN_INFO_SAMP_FREQ
Date: Wed, 12 Oct 2016 19:10:20 -0300 [thread overview]
Message-ID: <20161012221020.GA17329@spock> (raw)
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
reply other threads:[~2016-10-12 22:10 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161012221020.GA17329@spock \
--to=juliana.orod@gmail.com \
--cc=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=outreachy-kernel@googlegroups.com \
--cc=pmeerw@pmeerw.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.