From: Fabien Lahoudere <fabien.lahoudere@collabora.com>
To: unlisted-recipients:; (no To-header on input)
Cc: kernel@collabora.com,
Fabien Lahoudere <fabien.lahoudere@collabora.com>,
Nick Vaccaro <nvaccaro@chromium.org>,
Jonathan Cameron <jic23@kernel.org>,
Hartmut Knaack <knaack.h@gmx.de>,
Lars-Peter Clausen <lars@metafoo.de>,
Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] iio: common: cros_ec_sensors: set default frequencies
Date: Thu, 27 Jun 2019 16:04:30 +0200 [thread overview]
Message-ID: <7d3972d1200065fe6e98a310e66f53a7ed12e281.1561642224.git.fabien.lahoudere@collabora.com> (raw)
In-Reply-To: <cover.1561642224.git.fabien.lahoudere@collabora.com>
Version 3 of the EC protocol provides min and max frequencies for EC sensors.
Default frequencies are provided for earlier protocol.
Signed-off-by: Fabien Lahoudere <fabien.lahoudere@collabora.com>
Signed-off-by: Nick Vaccaro <nvaccaro@chromium.org>
---
.../cros_ec_sensors/cros_ec_sensors_core.c | 44 +++++++++++++++++++
.../linux/iio/common/cros_ec_sensors_core.h | 3 ++
2 files changed, 47 insertions(+)
diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
index 2e0f97448e64..72f56d54cccd 100644
--- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
+++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
@@ -50,6 +50,37 @@ static int cros_ec_get_host_cmd_version_mask(struct cros_ec_device *ec_dev,
return ret;
}
+static void get_default_min_max_freq(enum motionsensor_type type,
+ u32 *min_freq,
+ u32 *max_freq)
+{
+ switch (type) {
+ case MOTIONSENSE_TYPE_ACCEL:
+ case MOTIONSENSE_TYPE_GYRO:
+ *min_freq = 12500;
+ *max_freq = 100000;
+ break;
+ case MOTIONSENSE_TYPE_MAG:
+ *min_freq = 5000;
+ *max_freq = 25000;
+ break;
+ case MOTIONSENSE_TYPE_PROX:
+ case MOTIONSENSE_TYPE_LIGHT:
+ *min_freq = 100;
+ *max_freq = 50000;
+ break;
+ case MOTIONSENSE_TYPE_BARO:
+ *min_freq = 250;
+ *max_freq = 20000;
+ break;
+ case MOTIONSENSE_TYPE_ACTIVITY:
+ default:
+ *min_freq = 0;
+ *max_freq = 0;
+ break;
+ }
+}
+
int cros_ec_sensors_core_init(struct platform_device *pdev,
struct iio_dev *indio_dev,
bool physical_device)
@@ -100,6 +131,19 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
}
state->type = state->resp->info.type;
state->loc = state->resp->info.location;
+
+ /* Value to stop the device */
+ state->frequencies[0] = 0;
+ if (state->msg->version < 3) {
+ get_default_min_max_freq(state->resp->info.type,
+ &state->frequencies[1],
+ &state->frequencies[2]);
+ } else {
+ state->frequencies[1] =
+ state->resp->info_3.min_frequency;
+ state->frequencies[2] =
+ state->resp->info_3.max_frequency;
+ }
}
return 0;
diff --git a/include/linux/iio/common/cros_ec_sensors_core.h b/include/linux/iio/common/cros_ec_sensors_core.h
index 0c636b9fe8d7..94c87da22c04 100644
--- a/include/linux/iio/common/cros_ec_sensors_core.h
+++ b/include/linux/iio/common/cros_ec_sensors_core.h
@@ -70,6 +70,9 @@ struct cros_ec_sensors_core_state {
unsigned long scan_mask, s16 *data);
int curr_sampl_freq;
+
+ /* Disable, Min and Max Sampling Frequency in mHz */
+ int frequencies[3];
};
/**
--
2.20.1
next prev parent reply other threads:[~2019-06-27 14:05 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-27 14:04 [PATCH 0/2] Add protocol v3 support Fabien Lahoudere
2019-06-27 14:04 ` [PATCH 1/2] iio: common: cros_ec_sensors: determine protocol version Fabien Lahoudere
2019-06-27 15:59 ` Enric Balletbo i Serra
2019-06-27 21:59 ` Gwendal Grignou
2019-06-28 9:36 ` Fabien Lahoudere
2019-06-28 10:32 ` Enric Balletbo i Serra
2019-06-28 11:37 ` Fabien Lahoudere
2019-06-28 13:46 ` Enric Balletbo i Serra
2019-06-28 17:01 ` Gwendal Grignou
2019-06-27 14:04 ` Fabien Lahoudere [this message]
2019-06-27 15:48 ` [PATCH 2/2] iio: common: cros_ec_sensors: set default frequencies Enric Balletbo i Serra
2019-06-28 9:43 ` Fabien Lahoudere
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=7d3972d1200065fe6e98a310e66f53a7ed12e281.1561642224.git.fabien.lahoudere@collabora.com \
--to=fabien.lahoudere@collabora.com \
--cc=jic23@kernel.org \
--cc=kernel@collabora.com \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nvaccaro@chromium.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).