Re: [RFC PATCH 1/1] PM / domains: Add support for virtual power domains

2015-02-02 Thread Karol Wrona
On 01/30/2015 12:57 PM, Lorenzo Pieralisi wrote:
 On Fri, Jan 30, 2015 at 08:43:22AM +, amit daniel kachhap wrote:
 Hi Karol,

 I guess this patch series is not complete and use case implementation
 will be more helpful for clarity. Also I can think of another way in
 which this complete implementation can be done with pd name as
 something pd-virt. This pd can be handled differently inside the
 platform specific exynos power off/on function.
 
 Yes, it would be nice to provide an example to understand what this
 patchset has to achieve. Is this supposed to be a power domain
 used as a container to check for devices runtime state ie dependencies ?
 
Yes, something like that.

In our case exynos do not enter LPD state with mmc host working and its is in
top pd which is not managed in conventional way. If we know runtime status of
the host we can decide what to do. Soon I will send full patchset.


I thought about it as exynos specific but I wonder if that would be needed not
only in exynos.

BR,
Karol


[...]
--
To unsubscribe from this list: send the line unsubscribe devicetree in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFC PATCH 0/1] PM / domains: Add support for virtual power domains

2015-01-29 Thread Karol Wrona
Hello,

This patch adds virtual power domain handling.  Some comments are needed if
such approach has any sense.  The goal is to know the state of devices
residing in domain which is never gated or are gated only during sleep.
I.e. in Exynos3250 SoC there is one domain which is only put into retention
in LPD state and to enter it some devices (i.e. mmc host controller) have
to be inactive.  Using domains and runtime PM it would be able to give
an information to PM core that the SoC is ready for deeper power state.

TODO: binding doc, add child-parent hierarchy 

Thanks,
Karol

Karol Wrona (1):
  PM / domains: Add support for virtual power domains

 drivers/base/power/Makefile  |3 +-
 drivers/base/power/pm_domains_virt.c |   54 ++
 2 files changed, 56 insertions(+), 1 deletion(-)
 create mode 100644 drivers/base/power/pm_domains_virt.c

-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe devicetree in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFC PATCH 1/1] PM / domains: Add support for virtual power domains

2015-01-29 Thread Karol Wrona
There are the power domains which are turned off or put to retention only during
suspend or special processor states.  In such case there is a need to register
some devices which belong to such domain that PM core could know the state of
such devices and decide which power mode should be chosen i.e. the domain can
not be put to retention if some devices are active.  Virtual power domain has
empty power_on/off callbacks as there is no need to gate anything.

Signed-off-by: Karol Wrona k.wr...@samsung.com
---
 drivers/base/power/Makefile  |3 +-
 drivers/base/power/pm_domains_virt.c |   54 ++
 2 files changed, 56 insertions(+), 1 deletion(-)
 create mode 100644 drivers/base/power/pm_domains_virt.c

diff --git a/drivers/base/power/Makefile b/drivers/base/power/Makefile
index 1cb8544..360a0e2 100644
--- a/drivers/base/power/Makefile
+++ b/drivers/base/power/Makefile
@@ -2,7 +2,8 @@ obj-$(CONFIG_PM)+= sysfs.o generic_ops.o common.o qos.o 
runtime.o
 obj-$(CONFIG_PM_SLEEP) += main.o wakeup.o
 obj-$(CONFIG_PM_TRACE_RTC) += trace.o
 obj-$(CONFIG_PM_OPP)   += opp.o
-obj-$(CONFIG_PM_GENERIC_DOMAINS)   +=  domain.o domain_governor.o
+obj-$(CONFIG_PM_GENERIC_DOMAINS)   += domain.o domain_governor.o \
+  pm_domains_virt.o
 obj-$(CONFIG_HAVE_CLK) += clock_ops.o
 
 ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG
diff --git a/drivers/base/power/pm_domains_virt.c 
b/drivers/base/power/pm_domains_virt.c
new file mode 100644
index 000..bd4d6b6
--- /dev/null
+++ b/drivers/base/power/pm_domains_virt.c
@@ -0,0 +1,54 @@
+/*
+ *  Copyright (C) 2015, 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/err.h
+#include linux/of.h
+#include linux/pm_domain.h
+#include linux/slab.h
+
+static int pd_power_off(struct generic_pm_domain *domain)
+{
+   return 0;
+}
+
+static int pd_power_on(struct generic_pm_domain *domain)
+{
+   return 0;
+}
+
+int __init virt_pm_domains_init(void)
+{
+   struct device_node *np;
+
+   for_each_compatible_node(np, NULL, linux,virtual-pm-domains) {
+   struct generic_pm_domain *pd;
+
+   pd = kzalloc(sizeof(*pd), GFP_KERNEL);
+   if (!pd)
+   return -ENOMEM;
+
+   pd-power_off = pd_power_off;
+   pd-power_on = pd_power_on;
+   pd-name = kstrdup(np-name, GFP_KERNEL);
+   if (!pd-name)
+   return -ENOMEM;
+
+   pm_genpd_init(pd, NULL, false);
+   of_genpd_add_provider_simple(np, pd);
+   }
+
+   return 0;
+}
+arch_initcall(virt_pm_domains_init);
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe devicetree in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 1/5] iio: common: ssp_sensors: Add sensorhub driver

2015-01-29 Thread Karol Wrona
On 01/29/2015 07:35 PM, Jonathan Cameron wrote:
 On 28/01/15 14:05, Karol Wrona wrote:
 Sensorhub  is MCU dedicated to collect data and manage several sensors.
 Sensorhub is a spi device which provides a layer for IIO devices. It provides
 some data parsing and common mechanism for sensorhub sensors.

 Adds common sensorhub library for sensorhub driver and iio drivers
 which uses sensorhub MCU to communicate with sensors.

 Signed-off-by: Karol Wrona k.wr...@samsung.com
 Acked-by: Kyungmin Park kyungmin.p...@samsung.com
 A couple of build errors from this one...
 
 I've fixed them up and applied to the togreg branch of iio.git.
 Pushed out as testing.  If you get a chance to check I didn't
 mess anything up that would be great.
 ---
  drivers/iio/common/Kconfig   |1 +
  drivers/iio/common/Makefile  |1 +
  drivers/iio/common/ssp_sensors/Kconfig   |   26 ++
  drivers/iio/common/ssp_sensors/Makefile  |8 +
  drivers/iio/common/ssp_sensors/ssp.h |  257 +++
  drivers/iio/common/ssp_sensors/ssp_dev.c |  712 
 ++
  drivers/iio/common/ssp_sensors/ssp_spi.c |  608 +
  include/linux/iio/common/ssp_sensors.h   |   82 
  8 files changed, 1695 insertions(+)
  create mode 100644 drivers/iio/common/ssp_sensors/Kconfig
  create mode 100644 drivers/iio/common/ssp_sensors/Makefile
  create mode 100644 drivers/iio/common/ssp_sensors/ssp.h
  create mode 100644 drivers/iio/common/ssp_sensors/ssp_dev.c
  create mode 100644 drivers/iio/common/ssp_sensors/ssp_spi.c
  create mode 100644 include/linux/iio/common/ssp_sensors.h

 diff --git a/drivers/iio/common/Kconfig b/drivers/iio/common/Kconfig
 index 0b6e97d..790f106 100644
 --- a/drivers/iio/common/Kconfig
 +++ b/drivers/iio/common/Kconfig
 @@ -3,4 +3,5 @@
  #
  
  source drivers/iio/common/hid-sensors/Kconfig
 +source drivers/iio/common/ssp_sensors/Kconfig
  source drivers/iio/common/st_sensors/Kconfig
 diff --git a/drivers/iio/common/Makefile b/drivers/iio/common/Makefile
 index 3112df0..b1e4d9c 100644
 --- a/drivers/iio/common/Makefile
 +++ b/drivers/iio/common/Makefile
 @@ -8,4 +8,5 @@
  
  # When adding new entries keep the list in alphabetical order
  obj-y += hid-sensors/
 +obj-y += ssp_sensors/
  obj-y += st_sensors/
 diff --git a/drivers/iio/common/ssp_sensors/Kconfig 
 b/drivers/iio/common/ssp_sensors/Kconfig
 new file mode 100644
 index 000..0ea4faf
 --- /dev/null
 +++ b/drivers/iio/common/ssp_sensors/Kconfig
 @@ -0,0 +1,26 @@
 +#
 +# SSP sensor drivers and commons configuration
 +#
 +menu SSP Sensor Common
 +
 +config IIO_SSP_SENSORS_COMMONS
 +tristate Commons for all SSP Sensor IIO drivers
 +depends on IIO_SSP_SENSORHUB
 +select IIO_BUFFER
 +select IIO_KFIFO_BUF
 +help
 +  Say yes here to build commons for SSP sensors.
 +  To compile this as a module, choose M here: the module
 +  will be called ssp_iio.
 +
 +config IIO_SSP_SENSORHUB
 +tristate Samsung Sensorhub driver
 +depends on SPI
 +select MFD_CORE
 +help
 +  SSP driver for sensorhub. + If you say yes here you get ssp 
 support for sensorhub.
 +  To compile this driver as a module, choose M here: the
 +  module will be called sensorhub.
 +
 +endmenu
 diff --git a/drivers/iio/common/ssp_sensors/Makefile 
 b/drivers/iio/common/ssp_sensors/Makefile
 new file mode 100644
 index 000..1e0389e
 --- /dev/null
 +++ b/drivers/iio/common/ssp_sensors/Makefile
 @@ -0,0 +1,8 @@
 +#
 +# Makefile for SSP sensor drivers and commons.
 +#
 +
 +sensorhub-objs  := ssp_dev.o ssp_spi.o
 +obj-$(CONFIG_IIO_SSP_SENSORHUB) += sensorhub.o
 +
 +obj-$(CONFIG_IIO_SSP_SENSORS_COMMONS)   += ssp_iio.o
 This file isn't in this patch.

Thanks for doing that.
I had to mess sth up during rebase.

[...]
--
To unsubscribe from this list: send the line unsubscribe devicetree in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 5/5] iio: common: ssp_sensors: Add sensorhub gyroscope sensor

2015-01-28 Thread Karol Wrona
This patch adds gyroscope iio driver which uses sensorhub as data
provider.

Signed-off-by: Karol Wrona k.wr...@samsung.com
Acked-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/iio/gyro/Makefile  |2 +
 drivers/iio/gyro/ssp_gyro_sensor.c |  168 
 2 files changed, 170 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..f46341b 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_SENSORS_COMMONS) += 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 000..0a8afdd
--- /dev/null
+++ b/drivers/iio/gyro/ssp_gyro_sensor.c
@@ -0,0 +1,168 @@
+/*
+ *  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,
+};
+
+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 unsigned long ssp_gyro_scan_mask[] = { 0x07, 0, };
+
+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),
+   SSP_CHAN_TIMESTAMP(SSP_CHANNEL_SCAN_INDEX_TIME),
+};
+
+static int ssp_process_gyro_data(struct iio_dev *indio_dev, void *buf,
+int64_t timestamp)
+{
+   return ssp_common_process_data(indio_dev, buf, SSP_GYROSCOPE_SIZE,
+  timestamp);
+}
+
+static const struct iio_buffer_setup_ops ssp_gyro_buffer_ops = {
+   .postenable = ssp_common_buffer_postenable,
+   .postdisable = ssp_common_buffer_postdisable,
+};
+
+static int ssp_gyro_probe(struct platform_device *pdev)
+{
+   int ret;
+   struct iio_dev *indio_dev;
+   struct ssp_sensor_data *spd;
+   struct iio_buffer *buffer;
+
+   indio_dev = devm_iio_device_alloc(pdev-dev, 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

[PATCH v5 0/5] iio: Add sensorhub driver

2015-01-28 Thread Karol Wrona
Hello,

This patchset adds support for sensorhub.  It is an external mcu which
manages and collects data from several sensors i.e. on Galaxy Gear 2 watch.

It contains:
- spi driver for sensorhub device
- DT binding for the device
- IIO common utils for ssp sensors (iio kfifo setup helpers, pre/post callbacks)
- IIO accelerometer driver
- IIO gyroscope driver

For now the driver supports traditional sensors but new ones types are
intended to be used.

The patchset depends on INDIO_BUFFER_SOFTWARE adding patch.

From v1:
  - Adopted to new stm32fwu v5
  - Fixed sensors' data process callbacks
  - Fixed comments style

From v2:
  - Fixes after Hartmut Knaack review
  - Sensorhub driver was moved from misc to iio after the discussion with Arnd
and Jonathan
  - Firmware upgrade is not supported in this patchset. I hope it will be
applied when it will find its own place in the tree.

From v3:
  - change buffer allocation manner for iio devices buffers
  - centralize irq buffer
  - style fixes
  - sensors' devices as mfd cells
  - remove iio_buffer_register from the sensorhub drivers
  - fix DT binding and remove optional attributes

From v4:
  - fix Kconfig - missing MFD_CORE dependency
  - rebase on next-20150128
  - remove THIS_MODULE usage in sensors' drivers as not needed


Thanks,
Karol


Karol Wrona (5):
  iio: common: ssp_sensors: Add sensorhub driver
  iio: sensorhub: Add sensorhub bindings
  iio: common: ssp_sensors: Add sensorhub iio commons
  iio: common: ssp_sensors: Add sensorhub accelerometer sensor
  iio: common: ssp_sensors: Add sensorhub gyroscope sensor

 .../devicetree/bindings/iio/sensorhub.txt  |   25 +
 drivers/iio/accel/Makefile |1 +
 drivers/iio/accel/ssp_accel_sensor.c   |  169 +
 drivers/iio/common/Kconfig |1 +
 drivers/iio/common/Makefile|1 +
 drivers/iio/common/ssp_sensors/Kconfig |   26 +
 drivers/iio/common/ssp_sensors/Makefile|8 +
 drivers/iio/common/ssp_sensors/ssp.h   |  257 +++
 drivers/iio/common/ssp_sensors/ssp_dev.c   |  712 
 drivers/iio/common/ssp_sensors/ssp_iio.c   |  107 +++
 drivers/iio/common/ssp_sensors/ssp_iio_sensor.h|   70 ++
 drivers/iio/common/ssp_sensors/ssp_spi.c   |  608 +
 drivers/iio/gyro/Makefile  |2 +
 drivers/iio/gyro/ssp_gyro_sensor.c |  168 +
 include/linux/iio/common/ssp_sensors.h |   82 +++
 15 files changed, 2237 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/sensorhub.txt
 create mode 100644 drivers/iio/accel/ssp_accel_sensor.c
 create mode 100644 drivers/iio/common/ssp_sensors/Kconfig
 create mode 100644 drivers/iio/common/ssp_sensors/Makefile
 create mode 100644 drivers/iio/common/ssp_sensors/ssp.h
 create mode 100644 drivers/iio/common/ssp_sensors/ssp_dev.c
 create mode 100644 drivers/iio/common/ssp_sensors/ssp_iio.c
 create mode 100644 drivers/iio/common/ssp_sensors/ssp_iio_sensor.h
 create mode 100644 drivers/iio/common/ssp_sensors/ssp_spi.c
 create mode 100644 drivers/iio/gyro/ssp_gyro_sensor.c
 create mode 100644 include/linux/iio/common/ssp_sensors.h

-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe devicetree in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 2/5] iio: sensorhub: Add sensorhub bindings

2015-01-28 Thread Karol Wrona
Add sensorhub bindings for sensorhub on Galaxy Gear 2.

Signed-off-by: Karol Wrona k.wr...@samsung.com
Acked-by: Kyungmin Park kyungmin.p...@samsung.com
---
 .../devicetree/bindings/iio/sensorhub.txt  |   25 
 1 file changed, 25 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/sensorhub.txt

diff --git a/Documentation/devicetree/bindings/iio/sensorhub.txt 
b/Documentation/devicetree/bindings/iio/sensorhub.txt
new file mode 100644
index 000..8d57571
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/sensorhub.txt
@@ -0,0 +1,25 @@
+Samsung Sensorhub driver
+
+Sensorhub is a MCU which manages several sensors and also plays the role
+of a virtual sensor device.
+
+Required properties:
+- compatible: samsung,sensorhub-rinato or samsung,sensorhub-thermostat
+- spi-max-frequency: max SPI clock frequency
+- interrupt-parent: interrupt parent
+- interrupts: communication interrupt
+- ap-mcu-gpios: [out] ap to sensorhub line - used during communication
+- mcu-ap-gpios: [in] sensorhub to ap - used during communication
+- mcu-reset-gpios: [out] sensorhub reset
+
+Example:
+
+   shub_spi: shub {
+   compatible = samsung,sensorhub-rinato;
+   spi-max-frequency = 500;
+   interrupt-parent = gpx0;
+   interrupts = 2 0;
+   ap-mcu-gpios = gpx0 0 0;
+   mcu-ap-gpios = gpx0 4 0;
+   mcu-reset-gpios = gpx0 5 0;
+   };
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe devicetree in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 4/5] iio: common: ssp_sensors: Add sensorhub accelerometer sensor

2015-01-28 Thread Karol Wrona
This patch adds accelerometer iio driver which uses sensorhub as data
provider.

Signed-off-by: Karol Wrona k.wr...@samsung.com
Acked-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/iio/accel/Makefile   |1 +
 drivers/iio/accel/ssp_accel_sensor.c |  169 ++
 2 files changed, 170 insertions(+)
 create mode 100644 drivers/iio/accel/ssp_accel_sensor.c

diff --git a/drivers/iio/accel/Makefile b/drivers/iio/accel/Makefile
index de5b9cb..69c64b6 100644
--- a/drivers/iio/accel/Makefile
+++ b/drivers/iio/accel/Makefile
@@ -10,6 +10,7 @@ obj-$(CONFIG_KXCJK1013) += kxcjk-1013.o
 obj-$(CONFIG_KXSD9)+= kxsd9.o
 obj-$(CONFIG_MMA8452)  += mma8452.o
 obj-$(CONFIG_MMA9551)  += mma9551.o
+obj-$(CONFIG_IIO_SSP_SENSORS_COMMONS) += ssp_accel_sensor.o
 
 obj-$(CONFIG_IIO_ST_ACCEL_3AXIS) += st_accel.o
 st_accel-y := st_accel_core.o
diff --git a/drivers/iio/accel/ssp_accel_sensor.c 
b/drivers/iio/accel/ssp_accel_sensor.c
new file mode 100644
index 000..4ae05fc
--- /dev/null
+++ b/drivers/iio/accel/ssp_accel_sensor.c
@@ -0,0 +1,169 @@
+/*
+ *  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_ACCEL_NAME ssp-accelerometer
+static const char ssp_accel_device_name[] = SSP_ACCEL_NAME;
+
+enum ssp_accel_3d_channel {
+   SSP_CHANNEL_SCAN_INDEX_X,
+   SSP_CHANNEL_SCAN_INDEX_Y,
+   SSP_CHANNEL_SCAN_INDEX_Z,
+   SSP_CHANNEL_SCAN_INDEX_TIME,
+};
+
+static int ssp_accel_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_ACCELEROMETER_SENSOR);
+   ssp_convert_to_freq(t, val, val2);
+   return IIO_VAL_INT_PLUS_MICRO;
+   default:
+   break;
+   }
+
+   return -EINVAL;
+}
+
+static int ssp_accel_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_ACCELEROMETER_SENSOR, ret);
+   if (ret  0)
+   dev_err(indio_dev-dev, accel sensor enable fail\n);
+
+   return ret;
+   default:
+   break;
+   }
+
+   return -EINVAL;
+}
+
+static struct iio_info ssp_accel_iio_info = {
+   .read_raw = ssp_accel_read_raw,
+   .write_raw = ssp_accel_write_raw,
+};
+
+static const unsigned long ssp_accel_scan_mask[] = { 0x7, 0, };
+
+static const struct iio_chan_spec ssp_acc_channels[] = {
+   SSP_CHANNEL_AG(IIO_ACCEL, IIO_MOD_X, SSP_CHANNEL_SCAN_INDEX_X),
+   SSP_CHANNEL_AG(IIO_ACCEL, IIO_MOD_Y, SSP_CHANNEL_SCAN_INDEX_Y),
+   SSP_CHANNEL_AG(IIO_ACCEL, IIO_MOD_Z, SSP_CHANNEL_SCAN_INDEX_Z),
+   SSP_CHAN_TIMESTAMP(SSP_CHANNEL_SCAN_INDEX_TIME),
+};
+
+static int ssp_process_accel_data(struct iio_dev *indio_dev, void *buf,
+ int64_t timestamp)
+{
+   return ssp_common_process_data(indio_dev, buf, SSP_ACCELEROMETER_SIZE,
+  timestamp);
+}
+
+static const struct iio_buffer_setup_ops ssp_accel_buffer_ops = {
+   .postenable = ssp_common_buffer_postenable,
+   .postdisable = ssp_common_buffer_postdisable,
+};
+
+static int ssp_accel_probe(struct platform_device *pdev)
+{
+   int ret;
+   struct iio_dev *indio_dev;
+   struct ssp_sensor_data *spd;
+   struct iio_buffer *buffer;
+
+   indio_dev = devm_iio_device_alloc(pdev-dev, sizeof(*spd));
+   if (!indio_dev)
+   return -ENOMEM;
+
+   spd = iio_priv(indio_dev);
+
+   spd-process_data = ssp_process_accel_data;
+   spd-type = SSP_ACCELEROMETER_SENSOR;
+
+   indio_dev-name

[PATCH v5 1/5] iio: common: ssp_sensors: Add sensorhub driver

2015-01-28 Thread Karol Wrona
Sensorhub  is MCU dedicated to collect data and manage several sensors.
Sensorhub is a spi device which provides a layer for IIO devices. It provides
some data parsing and common mechanism for sensorhub sensors.

Adds common sensorhub library for sensorhub driver and iio drivers
which uses sensorhub MCU to communicate with sensors.

Signed-off-by: Karol Wrona k.wr...@samsung.com
Acked-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/iio/common/Kconfig   |1 +
 drivers/iio/common/Makefile  |1 +
 drivers/iio/common/ssp_sensors/Kconfig   |   26 ++
 drivers/iio/common/ssp_sensors/Makefile  |8 +
 drivers/iio/common/ssp_sensors/ssp.h |  257 +++
 drivers/iio/common/ssp_sensors/ssp_dev.c |  712 ++
 drivers/iio/common/ssp_sensors/ssp_spi.c |  608 +
 include/linux/iio/common/ssp_sensors.h   |   82 
 8 files changed, 1695 insertions(+)
 create mode 100644 drivers/iio/common/ssp_sensors/Kconfig
 create mode 100644 drivers/iio/common/ssp_sensors/Makefile
 create mode 100644 drivers/iio/common/ssp_sensors/ssp.h
 create mode 100644 drivers/iio/common/ssp_sensors/ssp_dev.c
 create mode 100644 drivers/iio/common/ssp_sensors/ssp_spi.c
 create mode 100644 include/linux/iio/common/ssp_sensors.h

diff --git a/drivers/iio/common/Kconfig b/drivers/iio/common/Kconfig
index 0b6e97d..790f106 100644
--- a/drivers/iio/common/Kconfig
+++ b/drivers/iio/common/Kconfig
@@ -3,4 +3,5 @@
 #
 
 source drivers/iio/common/hid-sensors/Kconfig
+source drivers/iio/common/ssp_sensors/Kconfig
 source drivers/iio/common/st_sensors/Kconfig
diff --git a/drivers/iio/common/Makefile b/drivers/iio/common/Makefile
index 3112df0..b1e4d9c 100644
--- a/drivers/iio/common/Makefile
+++ b/drivers/iio/common/Makefile
@@ -8,4 +8,5 @@
 
 # When adding new entries keep the list in alphabetical order
 obj-y += hid-sensors/
+obj-y += ssp_sensors/
 obj-y += st_sensors/
diff --git a/drivers/iio/common/ssp_sensors/Kconfig 
b/drivers/iio/common/ssp_sensors/Kconfig
new file mode 100644
index 000..0ea4faf
--- /dev/null
+++ b/drivers/iio/common/ssp_sensors/Kconfig
@@ -0,0 +1,26 @@
+#
+# SSP sensor drivers and commons configuration
+#
+menu SSP Sensor Common
+
+config IIO_SSP_SENSORS_COMMONS
+   tristate Commons for all SSP Sensor IIO drivers
+   depends on IIO_SSP_SENSORHUB
+   select IIO_BUFFER
+   select IIO_KFIFO_BUF
+   help
+ Say yes here to build commons for SSP sensors.
+ To compile this as a module, choose M here: the module
+ will be called ssp_iio.
+
+config IIO_SSP_SENSORHUB
+   tristate Samsung Sensorhub driver
+   depends on SPI
+   select MFD_CORE
+   help
+ SSP driver for sensorhub.
+ If you say yes here you get ssp support for sensorhub.
+ To compile this driver as a module, choose M here: the
+ module will be called sensorhub.
+
+endmenu
diff --git a/drivers/iio/common/ssp_sensors/Makefile 
b/drivers/iio/common/ssp_sensors/Makefile
new file mode 100644
index 000..1e0389e
--- /dev/null
+++ b/drivers/iio/common/ssp_sensors/Makefile
@@ -0,0 +1,8 @@
+#
+# Makefile for SSP sensor drivers and commons.
+#
+
+sensorhub-objs := ssp_dev.o ssp_spi.o
+obj-$(CONFIG_IIO_SSP_SENSORHUB)+= sensorhub.o
+
+obj-$(CONFIG_IIO_SSP_SENSORS_COMMONS)  += ssp_iio.o
diff --git a/drivers/iio/common/ssp_sensors/ssp.h 
b/drivers/iio/common/ssp_sensors/ssp.h
new file mode 100644
index 000..b910e91
--- /dev/null
+++ b/drivers/iio/common/ssp_sensors/ssp.h
@@ -0,0 +1,257 @@
+/*
+ *  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.
+ *
+ */
+
+#ifndef __SSP_SENSORHUB_H__
+#define __SSP_SENSORHUB_H__
+
+#include linux/delay.h
+#include linux/gpio.h
+#include linux/iio/common/ssp_sensors.h
+#include linux/iio/iio.h
+#include linux/spi/spi.h
+
+#define SSP_DEVICE_ID  0x55
+
+#ifdef SSP_DBG
+#define ssp_dbg(format, ...) pr_info([SSP] format, ##__VA_ARGS__)
+#else
+#define ssp_dbg(format, ...)
+#endif
+
+#define SSP_SW_RESET_TIME  3000
+/* Sensor polling in ms */
+#define SSP_DEFAULT_POLLING_DELAY  200
+#define SSP_DEFAULT_RETRIES3
+#define SSP_DATA_PACKET_SIZE   960
+#define SSP_HEADER_BUFFER_SIZE 4
+
+enum {
+   SSP_KERNEL_BINARY = 0,
+   SSP_KERNEL_CRASHED_BINARY,
+};
+
+enum {
+   SSP_INITIALIZATION_STATE = 0,
+   SSP_NO_SENSOR_STATE

[PATCH v5 3/5] iio: common: ssp_sensors: Add sensorhub iio commons

2015-01-28 Thread Karol Wrona
This patch adds common library for sensorhub iio drivers.

Signed-off-by: Karol Wrona k.wr...@samsung.com
Acked-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/iio/common/ssp_sensors/ssp_iio.c|  107 +++
 drivers/iio/common/ssp_sensors/ssp_iio_sensor.h |   70 +++
 2 files changed, 177 insertions(+)
 create mode 100644 drivers/iio/common/ssp_sensors/ssp_iio.c
 create mode 100644 drivers/iio/common/ssp_sensors/ssp_iio_sensor.h

diff --git a/drivers/iio/common/ssp_sensors/ssp_iio.c 
b/drivers/iio/common/ssp_sensors/ssp_iio.c
new file mode 100644
index 000..a3ae165
--- /dev/null
+++ b/drivers/iio/common/ssp_sensors/ssp_iio.c
@@ -0,0 +1,107 @@
+/*
+ *  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/kfifo_buf.h
+#include linux/module.h
+#include linux/slab.h
+#include ssp_iio_sensor.h
+
+/**
+ * ssp_common_buffer_postenable() - generic postenable callback for ssp buffer
+ *
+ * @indio_dev: iio device
+ *
+ * Returns 0 or negative value in case of error
+ */
+int ssp_common_buffer_postenable(struct iio_dev *indio_dev)
+{
+   struct ssp_sensor_data *spd = iio_priv(indio_dev);
+   struct ssp_data *data = dev_get_drvdata(indio_dev-dev.parent-parent);
+
+   /* the allocation is made in post because scan size is known in this
+* moment
+* */
+   spd-buffer = kmalloc(indio_dev-scan_bytes, GFP_KERNEL | GFP_DMA);
+   if (!spd-buffer)
+   return -ENOMEM;
+
+   return ssp_enable_sensor(data, spd-type,
+ssp_get_sensor_delay(data, spd-type));
+}
+EXPORT_SYMBOL(ssp_common_buffer_postenable);
+
+/**
+ * ssp_common_buffer_postdisable() - generic postdisable callback for ssp 
buffer
+ *
+ * @indio_dev: iio device
+ *
+ * Returns 0 or negative value in case of error
+ */
+int ssp_common_buffer_postdisable(struct iio_dev *indio_dev)
+{
+   int ret;
+   struct ssp_sensor_data *spd = iio_priv(indio_dev);
+   struct ssp_data *data = dev_get_drvdata(indio_dev-dev.parent-parent);
+
+   ret = ssp_disable_sensor(data, spd-type);
+   if (ret  0)
+   return ret;
+
+   kfree(spd-buffer);
+
+   return ret;
+}
+EXPORT_SYMBOL(ssp_common_buffer_postdisable);
+
+/**
+ * ssp_common_process_data() - Common process data callback for ssp sensors
+ *
+ * @indio_dev: iio device
+ * @buf:   source buffer
+ * @len:   sensor data length
+ * @timestamp: system timestamp
+ *
+ * Returns 0 or negative value in case of error
+ */
+int ssp_common_process_data(struct iio_dev *indio_dev, void *buf,
+   unsigned int len, int64_t timestamp)
+{
+   __le32 time;
+   int64_t calculated_time;
+   struct ssp_sensor_data *spd = iio_priv(indio_dev);
+
+   if (indio_dev-scan_bytes == 0)
+   return 0;
+
+   /*
+* it always sends full set of samples, remember about available masks
+*/
+   memcpy(spd-buffer, buf, len);
+
+   if (indio_dev-scan_timestamp) {
+   memcpy(time, ((char *)buf)[len], SSP_TIME_SIZE);
+   calculated_time =
+   timestamp + (int64_t)le32_to_cpu(time) * 100;
+   }
+
+   return iio_push_to_buffers_with_timestamp(indio_dev, spd-buffer,
+ calculated_time);
+}
+EXPORT_SYMBOL(ssp_common_process_data);
+
+MODULE_AUTHOR(Karol Wrona k.wr...@samsung.com);
+MODULE_DESCRIPTION(Samsung sensorhub commons);
+MODULE_LICENSE(GPL);
diff --git a/drivers/iio/common/ssp_sensors/ssp_iio_sensor.h 
b/drivers/iio/common/ssp_sensors/ssp_iio_sensor.h
new file mode 100644
index 000..dda267c
--- /dev/null
+++ b/drivers/iio/common/ssp_sensors/ssp_iio_sensor.h
@@ -0,0 +1,70 @@
+#ifndef __SSP_IIO_SENSOR_H__
+#define __SSP_IIO_SENSOR_H__
+
+#define SSP_CHANNEL_AG(_type, _mod, _index) \
+{ \
+   .type = _type,\
+   .modified = 1,\
+   .channel2 = _mod,\
+   .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ),\
+   .scan_index = _index,\
+   .scan_type = {\
+   .sign = 's',\
+   .realbits = 16,\
+   .storagebits = 16,\
+   .shift = 0,\
+   .endianness = IIO_LE

[PATCH v4 2/5] iio: sensorhub: Add sensorhub bindings

2015-01-14 Thread Karol Wrona
Add sensorhub bindings for sensorhub on Galaxy Gear 2.

Signed-off-by: Karol Wrona k.wr...@samsung.com
Acked-by: Kyungmin Park kyungmin.p...@samsung.com
---
 .../devicetree/bindings/iio/sensorhub.txt  |   25 
 1 file changed, 25 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/sensorhub.txt

diff --git a/Documentation/devicetree/bindings/iio/sensorhub.txt 
b/Documentation/devicetree/bindings/iio/sensorhub.txt
new file mode 100644
index 000..8d57571
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/sensorhub.txt
@@ -0,0 +1,25 @@
+Samsung Sensorhub driver
+
+Sensorhub is a MCU which manages several sensors and also plays the role
+of a virtual sensor device.
+
+Required properties:
+- compatible: samsung,sensorhub-rinato or samsung,sensorhub-thermostat
+- spi-max-frequency: max SPI clock frequency
+- interrupt-parent: interrupt parent
+- interrupts: communication interrupt
+- ap-mcu-gpios: [out] ap to sensorhub line - used during communication
+- mcu-ap-gpios: [in] sensorhub to ap - used during communication
+- mcu-reset-gpios: [out] sensorhub reset
+
+Example:
+
+   shub_spi: shub {
+   compatible = samsung,sensorhub-rinato;
+   spi-max-frequency = 500;
+   interrupt-parent = gpx0;
+   interrupts = 2 0;
+   ap-mcu-gpios = gpx0 0 0;
+   mcu-ap-gpios = gpx0 4 0;
+   mcu-reset-gpios = gpx0 5 0;
+   };
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe devicetree in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 2/5] iio: sensorhub: Add sensorhub bindings

2014-12-15 Thread Karol Wrona
On 12/06/2014 03:29 PM, Jonathan Cameron wrote:
 On 05/12/14 19:54, Karol Wrona wrote:
 Add sensorhub bindings for sensorhub on Galaxy Gear 2.

 Change-Id: I4ee25aef33c21a4662de230841de9a8684f2c26b
 Signed-off-by: Karol Wrona k.wr...@samsung.com
 Acked-by: Kyungmin Park kyungmin.p...@samsung.com
 Looks good to me.  Comments inline.  Note I either need a device tree
 ack or a long delay before I can take this though.  Unlikely to get the
 device tree ack as you haven't cc'd the maintainers or list ;)
I am curious about DT community opinion and I prefer to know it before
v4 sending.

 
 I've added the cc's. Please make sure future versions have them or you'll
 just be slowing the process down (particularly if no one notices they 
 are missing!)
Thanks, I will remember that.
 
 ---
  .../devicetree/bindings/iio/sensorhub.txt  |   46 
 
  1 file changed, 46 insertions(+)
  create mode 100644 Documentation/devicetree/bindings/iio/sensorhub.txt

 diff --git a/Documentation/devicetree/bindings/iio/sensorhub.txt 
 b/Documentation/devicetree/bindings/iio/sensorhub.txt
 new file mode 100644
 index 000..2aca0c3
 --- /dev/null
 +++ b/Documentation/devicetree/bindings/iio/sensorhub.txt
 @@ -0,0 +1,46 @@
 +Samsung Sensorhub driver
 +
 +Sensorhub is a MCU which manages several sensors and also plays the role
 +of a virtual sensor device.
 +
 +Required properties:
 +- compatible: samsung,sensorhub-rinato or samsung,sensorhub-thermostat
 +- spi-max-frequency: max SPI clock frequency
 +- interrupt-parent: interrupt parent
 +- interrupts: communication interrupt
 +- ap-mcu-gpio: [out] ap to sensorhub line - used during communication
 +- mcu-ap-gpio: [in] sensorhub to ap - used during communication
 +- mcu-reset: [out] sensorhub reset
 as commented in previous patch, why do the first two have -gpio and the
 third not?
Ok, all 3 will have gpios ending
 +
 +Optional properties:
 +- sensor's nodes:
 +  compatible = samsung,mpu6500-accel
 +  compatible = samsung,mpu6500-gyro
 +  compatible = samsung,adpd142
 +
 +Sensor compatibles are used to match proper sensor driver to real sensor on
 +the board. The firmware does not give such information, so it helps to 
 specify
 +some sensors properties. Sensors have samsung prefixes because frequently
 +they will not have much in common with sensors used without sensorhub 
 because
 +it can do some data processing.
 We'll keep that under review.  Might make sense, sometimes, to unify the
 drivers.  The different compatible will probably still be needed, but if
 these devices proliferate I don't want two drivers for everything that
 gets stuck behind them.
I think that sensorhub is very similar hid-sensor (without hotpluging) where
every sensor type has its own representation.  The real sensors are not driven
directly but by external MCU so very often these sensors will not have much
common with real ones.  So I wonder if it could be better to resign from these
sensor compatibles and represent each sensor as mfd cell so optional properties
probably will dropped (?)
Generally I intended to have i.e. one ssp-accel driver if they use another
accelerometer then mpu6500 the buffering manner and sysfs will be handled in the
same way.  I think I was mistaken with these compatibles.  There is also some
probability that the firmware will be fixed someday and it will be able to tell
more about sensor then the type.

 +
 +Example:
 +
 +shub_spi: shub {
 +compatible = samsung,sensorhub-rinato;
 +spi-max-frequency = 500;
 +interrupt-parent = gpx0;
 +interrupts = 2 0;
 +ap-mcu-gpio = gpx0 0 0;
 +mcu-ap-gpio = gpx0 4 0;
 +mcu-reset = gpx0 5 0;
 +sensor@0 {
 +compatible = samsung,mpu6500-accel;
 +};
 +sensor@1 {
 +compatible = samsung,mpu6500-gyro;
 +};
 +sensor@2 {
 +compatible = samsung,adpd142;
 +};
 +};

 
 

--
To unsubscribe from this list: send the line unsubscribe devicetree in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html