From: Jonathan Cameron <jic23@kernel.org>
To: Karol Wrona <k.wrona@samsung.com>,
linux-iio@vger.kernel.org, Hartmut Knaack <knaack.h@gmx.de>,
linux-kernel@vger.kernel.org
Cc: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>,
Kyungmin Park <kyungmin.park@samsung.com>,
Karol Wrona <wrona.vy@gmail.com>
Subject: Re: [PATCH v3 5/5] iio: common: ssp_sensors: Add sensorhub gyroscope sensor
Date: Sat, 06 Dec 2014 14:53:39 +0000 [thread overview]
Message-ID: <54831873.3050809@kernel.org> (raw)
In-Reply-To: <1417809290-9662-6-git-send-email-k.wrona@samsung.com>
On 05/12/14 19:54, Karol Wrona wrote:
> This patch adds gyroscope iio driver which uses sensorhub as data
> provider.
>
> Change-Id: Ia16bc92159d062a29957de8e62ea3fefdcd7985a
> Signed-off-by: Karol Wrona <k.wrona@samsung.com>
> Acked-by: Kyungmin Park <kyungmin.park@samsung.com>
hmm. This is obviously very similar to the accelerometer driver so same
comments (I haven't read it ;)
> ---
> drivers/iio/gyro/Makefile | 2 +
> drivers/iio/gyro/ssp_gyro_sensor.c | 202 ++++++++++++++++++++++++++++++++++++
> 2 files changed, 204 insertions(+)
> create mode 100644 drivers/iio/gyro/ssp_gyro_sensor.c
>
> diff --git a/drivers/iio/gyro/Makefile b/drivers/iio/gyro/Makefile
> index 36a3877..68f1437 100644
> --- a/drivers/iio/gyro/Makefile
> +++ b/drivers/iio/gyro/Makefile
> @@ -16,6 +16,8 @@ itg3200-y := itg3200_core.o
> itg3200-$(CONFIG_IIO_BUFFER) += itg3200_buffer.o
> obj-$(CONFIG_ITG3200) += itg3200.o
>
> +obj-$(CONFIG_IIO_SSP_SENSOR) += ssp_gyro_sensor.o
> +
> obj-$(CONFIG_IIO_ST_GYRO_3AXIS) += st_gyro.o
> st_gyro-y := st_gyro_core.o
> st_gyro-$(CONFIG_IIO_BUFFER) += st_gyro_buffer.o
> diff --git a/drivers/iio/gyro/ssp_gyro_sensor.c b/drivers/iio/gyro/ssp_gyro_sensor.c
> new file mode 100644
> index 0000000..5820a43
> --- /dev/null
> +++ b/drivers/iio/gyro/ssp_gyro_sensor.c
> @@ -0,0 +1,202 @@
> +/*
> + * Copyright (C) 2014, Samsung Electronics Co. Ltd. All Rights Reserved.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + */
> +
> +#include <linux/iio/common/ssp_sensors.h>
> +#include <linux/iio/iio.h>
> +#include <linux/iio/kfifo_buf.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/slab.h>
> +#include "../common/ssp_sensors/ssp_iio_sensor.h"
> +
> +#define SSP_CHANNEL_COUNT 3
> +
> +#define SSP_GYROSCOPE_NAME "ssp-gyroscope"
> +static const char ssp_gyro_name[] = SSP_GYROSCOPE_NAME;
> +
> +enum ssp_gyro_3d_channel {
> + SSP_CHANNEL_SCAN_INDEX_X,
> + SSP_CHANNEL_SCAN_INDEX_Y,
> + SSP_CHANNEL_SCAN_INDEX_Z,
> + SSP_CHANNEL_SCAN_INDEX_TIME,
> + GYRO_3D_CHANNEL_MAX,
> +};
> +
> +static int ssp_gyro_read_raw(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan, int *val,
> + int *val2, long mask)
> +{
> + u32 t;
> + struct ssp_data *data = dev_get_drvdata(indio_dev->dev.parent->parent);
> +
> + switch (mask) {
> + case IIO_CHAN_INFO_SAMP_FREQ:
> + t = ssp_get_sensor_delay(data, SSP_GYROSCOPE_SENSOR);
> + ssp_convert_to_freq(t, val, val2);
> + return IIO_VAL_INT_PLUS_MICRO;
> + default:
> + break;
> + }
> +
> + return -EINVAL;
> +}
> +
> +static int ssp_gyro_write_raw(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan, int val,
> + int val2, long mask)
> +{
> + int ret;
> + struct ssp_data *data = dev_get_drvdata(indio_dev->dev.parent->parent);
> +
> + switch (mask) {
> + case IIO_CHAN_INFO_SAMP_FREQ:
> + ret = ssp_convert_to_time(val, val2);
> + ret = ssp_change_delay(data, SSP_GYROSCOPE_SENSOR, ret);
> + if (ret < 0)
> + dev_err(&indio_dev->dev, "gyro sensor enable fail\n");
> +
> + return ret;
> + default:
> + break;
> + }
> +
> + return -EINVAL;
> +}
> +
> +static struct iio_info ssp_gyro_iio_info = {
> + .read_raw = &ssp_gyro_read_raw,
> + .write_raw = &ssp_gyro_write_raw,
> +};
> +
> +static const struct iio_chan_spec ssp_gyro_channels[] = {
> + SSP_CHANNEL_AG(IIO_ANGL_VEL, IIO_MOD_X, SSP_CHANNEL_SCAN_INDEX_X),
> + SSP_CHANNEL_AG(IIO_ANGL_VEL, IIO_MOD_Y, SSP_CHANNEL_SCAN_INDEX_Y),
> + SSP_CHANNEL_AG(IIO_ANGL_VEL, IIO_MOD_Z, SSP_CHANNEL_SCAN_INDEX_Z),
> + IIO_CHAN_SOFT_TIMESTAMP(SSP_CHANNEL_SCAN_INDEX_TIME),
> +};
> +
> +static int ssp_process_gyro_data(struct iio_dev *indio_dev, void *buf,
> + int64_t timestamp)
> +{
> + __le32 time;
> + const int len = SSP_GYROSCOPE_SIZE;
> + int64_t calculated_time;
> + char *data;
> + int ret;
> +
> + if (indio_dev->scan_bytes == 0)
> + return 0;
> +
> + data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
> + if (!data)
> + return -ENOMEM;
> +
> + memcpy(data, buf, len);
> +
> + if (indio_dev->scan_timestamp) {
> + memcpy(&time, &((char *)buf)[len], SSP_TIME_SIZE);
> + calculated_time =
> + timestamp + (int64_t)le32_to_cpu(time) * 1000000;
> + }
> +
> + ret = iio_push_to_buffers_with_timestamp(indio_dev, data,
> + calculated_time);
> +
> + kfree(data);
> +
> + return ret;
> +}
> +
> +static const struct iio_buffer_setup_ops ssp_gyro_buffer_ops = {
> + .postenable = &ssp_common_buffer_postenable,
> + .predisable = &ssp_common_buffer_predisable,
> +};
> +
> +static int ssp_gyro_probe(struct platform_device *pdev)
> +{
> + int ret;
> + struct iio_dev *indio_dev;
> + struct ssp_sensor_data *spd;
> +
> + indio_dev = iio_device_alloc(sizeof(*spd));
> + if (!indio_dev)
> + return -ENOMEM;
> +
> + spd = iio_priv(indio_dev);
> +
> + spd->process_data = ssp_process_gyro_data;
> + spd->type = SSP_GYROSCOPE_SENSOR;
> +
> + indio_dev->name = ssp_gyro_name;
> + indio_dev->dev.parent = &pdev->dev;
> + indio_dev->info = &ssp_gyro_iio_info;
> + indio_dev->modes = INDIO_BUFFER_HARDWARE;
> + indio_dev->channels = ssp_gyro_channels;
> + indio_dev->num_channels = ARRAY_SIZE(ssp_gyro_channels);
> +
> + ret = ssp_common_setup_buffer(indio_dev, &ssp_gyro_buffer_ops);
> + if (ret < 0) {
> + dev_err(&pdev->dev, "Buffer setup fail\n");
> + return ret;
> + }
> +
> + platform_set_drvdata(pdev, indio_dev);
> +
> + ret = iio_device_register(indio_dev);
> + if (ret < 0) {
> + iio_buffer_unregister(indio_dev);
> + iio_kfifo_free(indio_dev->buffer);
> + return ret;
> + };
> +
> + /* similar to accel */
> + ssp_register_consumer(indio_dev, SSP_GYROSCOPE_SENSOR);
> +
> + return 0;
> +}
> +
> +static int ssp_gyro_remove(struct platform_device *pdev)
> +{
> + struct iio_dev *indio_dev = platform_get_drvdata(pdev);
> +
> + iio_device_unregister(indio_dev);
> + iio_buffer_unregister(indio_dev);
> + iio_kfifo_free(indio_dev->buffer);
> +
> + return 0;
> +}
> +
> +static const struct of_device_id ssp_gyro_id_table[] = {
> + {
> + .compatible = "samsung,mpu6500-gyro",
> + },
> + {},
> +};
> +
> +static struct platform_driver ssp_gyro_driver = {
> + .driver = {
> + .owner = THIS_MODULE,
> + .name = SSP_GYROSCOPE_NAME,
> + .of_match_table = ssp_gyro_id_table,
> + },
> + .probe = ssp_gyro_probe,
> + .remove = ssp_gyro_remove,
> +};
> +
> +module_platform_driver(ssp_gyro_driver);
> +
> +MODULE_AUTHOR("Karol Wrona <k.wrona@samsung.com>");
> +MODULE_DESCRIPTION("Samsung sensorhub gyroscopes driver");
> +MODULE_LICENSE("GPL");
>
next prev parent reply other threads:[~2014-12-07 17:43 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-05 19:54 [PATCH v3 0/5] iio: common: ssp_sensors: Add sensorhub driver Karol Wrona
2014-12-05 19:54 ` [PATCH v3 1/5] " Karol Wrona
2014-12-06 14:09 ` Jonathan Cameron
2014-12-16 10:17 ` Karol Wrona
2014-12-26 12:27 ` Jonathan Cameron
2014-12-17 22:11 ` Hartmut Knaack
2014-12-05 19:54 ` [PATCH v3 2/5] iio: sensorhub: Add sensorhub bindings Karol Wrona
2014-12-06 14:29 ` Jonathan Cameron
2014-12-06 14:29 ` Jonathan Cameron
2014-12-16 7:30 ` Karol Wrona
2014-12-16 7:30 ` Karol Wrona
2014-12-26 12:29 ` Jonathan Cameron
2014-12-26 12:29 ` Jonathan Cameron
2014-12-05 19:54 ` [PATCH v3 3/5] iio: common: ssp_sensors: Add sensorhub iio commons Karol Wrona
2014-12-06 14:39 ` Jonathan Cameron
2015-01-13 16:03 ` Karol Wrona
2015-01-13 17:33 ` Jonathan Cameron
2014-12-17 22:15 ` Hartmut Knaack
2014-12-05 19:54 ` [PATCH v3 4/5] iio: common: ssp_sensors: Add sensorhub accelerometer sensor Karol Wrona
2014-12-06 14:52 ` Jonathan Cameron
2014-12-08 10:41 ` Karol Wrona
2014-12-26 12:34 ` Jonathan Cameron
2014-12-17 22:18 ` Hartmut Knaack
2014-12-05 19:54 ` [PATCH v3 5/5] iio: common: ssp_sensors: Add sensorhub gyroscope sensor Karol Wrona
2014-12-06 14:53 ` Jonathan Cameron [this message]
2014-12-17 22:20 ` Hartmut Knaack
2014-12-05 20:13 ` [PATCH v3 0/5] iio: common: ssp_sensors: Add sensorhub driver Karol Wrona
2014-12-05 20:13 ` Karol Wrona
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=54831873.3050809@kernel.org \
--to=jic23@kernel.org \
--cc=b.zolnierkie@samsung.com \
--cc=k.wrona@samsung.com \
--cc=knaack.h@gmx.de \
--cc=kyungmin.park@samsung.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=wrona.vy@gmail.com \
/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.