Commit Graph

41 Commits

Author SHA1 Message Date
Peter Rosin 00c5f80c2f iio: inkern: add helpers to query available values from channels
Specifically a helper for reading the available maximum raw value of a
channel and a helper for forwarding read_avail requests for raw values
from one iio driver to an iio channel that is consumed.

These rather specific helpers are in turn built with generic helpers
making it easy to build more helpers for available values as needed.

Signed-off-by: Peter Rosin <peda@axentia.se>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-13 11:40:26 +00:00
Matt Ranostay 0023e67dd8 iio: inkern: add iio_read_channel_offset helper
Allow access to underlying channel IIO_CHAN_INFO_OFFSET from a consumer.

Signed-off-by: Matt Ranostay <matt@ranostay.consulting>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-09-27 20:33:02 +01:00
Laxman Dewangan efc2c0133f iio: core: Add devm_ APIs for iio_channel_{get,release}_all
Some of kernel driver uses the IIO framework to get the sensor
value via ADC or IIO HW driver. The client driver get iio channel
by iio_channel_get_all() and release it by calling
iio_channel_release_all().

Add resource managed version (devm_*) of these APIs so that if client
calls the devm_iio_channel_get_all() then it need not to release it
explicitly, it can be done by managed device framework when driver
get un-binded.

This reduces the code in error path and also need of .remove callback in
some cases.

Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-04-19 19:58:15 +01:00
Laxman Dewangan 8bf872d8d2 iio: core: Add devm_ APIs for iio_channel_{get,release}
Some of kernel driver uses the IIO framework to get the sensor
value via ADC or IIO HW driver. The client driver get iio channel
by iio_channel_get() and release it by calling iio_channel_release().

Add resource managed version (devm_*) of these APIs so that if client
calls the devm_iio_channel_get() then it need not to release it explicitly,
it can be done by managed device framework when driver get un-binded.

This reduces the code in error path and also need of .remove callback in
some cases.

Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-04-19 19:58:14 +01:00
Slawomir Stepien fc0b81704f iio: inkern: add a missing space before if
This fixes the error reported by checkpatch.pl:

ERROR: space required before the open parenthesis '('

Signed-off-by: Slawomir Stepien <sst@poczta.fm>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-04-16 13:39:22 +01:00
Greg Kroah-Hartman 48436e82fd First set of IIO fixes for the 4.5 cycle.
This set comprises those not dependent on patches in the 4.5 merge cycle.
 A second set will follow shortly with ones that are.
 
 * core in kernel interfaces
   - fix a possible NULL dereference that is a theoretical possibility
     via odd usage of iio_channel_release. Pretty much a hardening of
     the interface, but observed in the wild with the twl4030_charger
     driver.
 * acpi-als
   - report the data as processed as it is in lux.  This fixes a wrong
     use of the IIO ABI.  However, old _raw version retained to avoid
     breaking any userspace in the wild that is relying on that (none
     known but it doesn't hurt us much to retain it)
 * ade7753
   - fix some error handling to avoid use of unitialized data.
 * ltr501
   - use a signed return type for ltr501_match_samp_freq so as to allow
     returning of an error code.
 * mcp4725
   - set name field of struct iio_dev to ensure the sysfs name attribute
     doesn't give NULL.
 * mpl115
   - temperature offset sign is wrong.
 * stk8ba50
   - IIO_TRIGGER dependency added
 * ti_am335x_adc
   - Label buffer as a software buffer. It's actually a hybrid of a
     true hardware buffer feeding a kfifo, but the meaning of these fields
     has changed a little recently and in this case it should be labeled
     a software buffer ensure it is allowed to use the kfifo.
 * vf610_adc
   - HAS_IOMEM dependency
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2
 
 iQIcBAABCAAGBQJWr7r1AAoJEFSFNJnE9BaIEu4QAIb4FPipmsRLbNlPpngtYL9k
 uH13UiZLdGRdZsif2S9B0S5L0+PG25UTzXbtgleUq4IxdY4LnSyfa+/V+Ifn3SPE
 +F3Vr5Uqd9S/uRNNwJjgvSMf60s9J8Vm3PqFJ7aH8glJ7CRR4IbDAPJ7GXhUx4mt
 o5VXYLIm178JbwC6zKu8AanYGtRADG6orLqMbjCEWksK0SAuCz772CLgUCLMFxHC
 z1n/mdG8nadTZZDbuaHda5C5r9Baiqt/Wl7e/3gg7gHBl5LjcGUejlyD2VKRilpO
 4exHIARkHqlx/fXBxUxRN9kDbRK+6cuxca8MHn01Kn/XM7D8XoeZ1orQm+bItyOL
 9aHIoV2szS+VQMDE1oB+eKU8KZRGD0rLNKJRNumho+0lFtdbSZ0VqeBqn/wGYEBa
 QyGjpjdVCltdZJ2BX4kaUGcCQeWnpqqLc6jrXuUN0qSzvHyspt3XsllCKrTWbvNu
 oV1uDM+R8+YSsDQmgTpGuoTmpRHq2ED2lAJqRVan/Zi+Yk6gjxyDcIe1V4LbLdTt
 asXxzxp/eYFfM/K5nJyyASp3jl66f8QoQaVDly5XjXsf400xQKa3PlahQLWx66JM
 YfGJfHwhyzamO+mgiyuX1O4C7CO7uvHZgC/H+p7bB03GdtcUzjT1ZlBrR0JJlojg
 crBzUtRyX26wUNTGxHXG
 =27Pv
 -----END PGP SIGNATURE-----

Merge tag 'iio-fixes-for-4.5a' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-linus

Jonathan writes:

First set of IIO fixes for the 4.5 cycle.

This set comprises those not dependent on patches in the 4.5 merge cycle.
A second set will follow shortly with ones that are.

* core in kernel interfaces
  - fix a possible NULL dereference that is a theoretical possibility
    via odd usage of iio_channel_release. Pretty much a hardening of
    the interface, but observed in the wild with the twl4030_charger
    driver.
* acpi-als
  - report the data as processed as it is in lux.  This fixes a wrong
    use of the IIO ABI.  However, old _raw version retained to avoid
    breaking any userspace in the wild that is relying on that (none
    known but it doesn't hurt us much to retain it)
* ade7753
  - fix some error handling to avoid use of unitialized data.
* ltr501
  - use a signed return type for ltr501_match_samp_freq so as to allow
    returning of an error code.
* mcp4725
  - set name field of struct iio_dev to ensure the sysfs name attribute
    doesn't give NULL.
* mpl115
  - temperature offset sign is wrong.
* stk8ba50
  - IIO_TRIGGER dependency added
* ti_am335x_adc
  - Label buffer as a software buffer. It's actually a hybrid of a
    true hardware buffer feeding a kfifo, but the meaning of these fields
    has changed a little recently and in this case it should be labeled
    a software buffer ensure it is allowed to use the kfifo.
* vf610_adc
  - HAS_IOMEM dependency
2016-02-01 13:07:38 -08:00
Dan Carpenter d81dac3c1c iio: inkern: fix a NULL dereference on error
In twl4030_bci_probe() there are some failure paths where we call
iio_channel_release() with a NULL pointer.  (Apparently, that driver can
opperate without a valid channel pointer).  Let's fix it by adding a
NULL check in iio_channel_release().

Fixes: 2202e1fc5a ('drivers: power: twl4030_charger: fix link problems when building as module')
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-01-30 15:37:40 +00:00
Anshul Garg c34c18195d iio/inkern.c Use list_for_each_entry_safe
Use list_for_each_entry_safe instead of list_for_each_safe
and list_entry call.

Signed-off-by: Anshul Garg <aksgarg1989@gmail.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2015-12-12 17:23:37 +00:00
Greg Kroah-Hartman 6e49557b31 First round of IIO new drivers, cleanups and functionality for the 3.20 cycle take 2
Updated pull request with Daniel's fix on top for the power management
 Kconfig changes that had snuck in since last update of the IIO tree
 worked it's way through from mainline.
 
 Original pull message
 
 New device support
 * jsa1212 proxmity / ambient light sensor
 * SM08500 supported added to the kxcjk-1013 accelerometer driver
 * KMX61 Accelerometer/Magnetometer.  This took a somewhat rocky path
   being first merged, then reverted for a rewrite after a discussion of
   how to support additional functionality and finally being merged prior
   to some last reviews coming in, with resultant follow up patches.
 * Freescale mma9551l driver (minor follow up warning supression patch).
 * Semtech SX9500 proximity device driver.
 * ak8975 gains support for ak09911 and ak09912 and drop the standalone driver
   for the ak09911.
 
 New functionality
  * Dummy driver gains some virtual registers making it more flexible.
  * IIO_ACTIVITY channel types, with modifiers running, walking etc.  This is
    to support on chip motion clasifiers.  As such it is in the form of a
    confidence percentage.  The only devices so far only do binary decisions
    but this gives us room when other devices give more nuanced clasification.
  * IIO_EV_DIR_NONE type for events where there is no obvious direction.
    First case is step detection.
  * IIO_STEPS channel type for pedometers.
  * ENABLE mask element used to control turning on counting types such as
    the pedometer that need a 'start point'.
  * INSTANCE event type to support things that happen once.
  * info element for height calibration (used in various motion estimation
    algorithms). Note heigh tof use
  * dummy driver demonstration of the use of all the new bits above.
  * event monitor support for the new events.
  * inv_mpu6050 gains an i2c mux to allow bypassing the device to access
    additional devices connected on the other side of it.  Note that in
    Windows these are handled by firmware on the device and not exposed
    directly.
  * inv_mpu6050 gains ACPI enumeration.
  * inkern interface gains iio_write_channel_raw to allow in kernel users
    of DAC functionality via a simple wrapper.
  * Document input current readings in the ABI docs.
  * Add an error message when we get an out of range error in device tree
    processing for the in kernel interfaces.  Basically a device tree debugging
    aid.
  * Add a sanity check that a scan index for a channel is unique during
    registration.  There to help catch bugs as this should never happen
    in a bug free driver.
 
 Cleanups and fixlets
 
  A rework of buffer registration from Lars - a precursor to some other
  upcoming new stuff (a few patches from others rolled in here as well).
  * Ensure all drivers register the same channels for the device and buffer.
  * Move buffer registration into the core rather than using the old
    two step approach.  Now we have simple ways of using a unified set channels
    for both without requiring channels be exposed by both interface, this
    removes a fair bit of boilerplate.
  * Stop sca3000 and ad5933 (both in staging) enabling buffer channels by
    default. It has long be convention in IIO to startup with no channels
    enabled and leave it up to userspace to say what goes in the buffer.
    Getting rid of these allows us to drop export of iio_scan_mask_set.
  * Drop get_bytes_per_datum from iio_buffer_access_funcs as not been used
    for a while.
  * Allocate standard buffer attributes in the core rather than in every
    driver with a buffer.
  * Make the length attribute read only when a driver is not able to set
    the length.
  * Drop the get_length callback for buffers as it is already available in
    struct iio_buffer.
  * Drop an unused arguement form iio_kfifo_allocate and add devm allocator
    for it.
  * some kconfig entries gain anotation with the resulting module name.
  * Fix a resulting compile issue in dummy driver due to a stub taking
    wrong parameters as a result of the above rework.
  * Fix an off by 2 error in copying the core assigned buffer attributes.
 
 Other cleanups,
  * Trivial space before comma fixups.
  * ak8975 fixlets - none critical.  Rework to allow more device support.
  * Drop unnecessary sizeof(u8) calls.
  * bmp280 - refactor the compensation code to reduce copy operations and
    code length.  A second patch futher optimized this and performed some
    other minor cleanups.
  * kxcjk-1013 - various power control cleanups to avoid unnecessary enable
    / disable of device.  Make sure it is only controlled at all if CONFIG_PM
    is enabled.  Also som cleanups of error paths.
  * Small cleanups in adf4530 driver - pointless message and unnecessary braces.
  * Clarifiy the proximity ABI docs to make it clear it should get bigger
    as we move futher away.
  * Drop a misleading comment form industrialio-core.c
  * Trivial white space cleanups.
  * sca3000 looses an unused debug function.
  * Fix char unsigned ordering in ad8366
  * Increase the sleep time in ad9523 to make it predictable (value didn't
    really matter so make it more than 20 msecs)
  * mxs-lradc touchscreen property cleanups in device tree are fixed to ensure
    the meet all the 'interesting' documentation.
  * A couple of cleanups for the staging ad5933 driver to avoid unnecessary
    conversion to a processed temperature vlaue in kernel and remove
    platform data form the state structure as not needed after probe.
  * Fix a wrong scale factor in the docs.
 
 Misc
  * Add IIO include files to the maintainers entry.
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2
 
 iQIcBAABCAAGBQJUvtDlAAoJEFSFNJnE9BaIaNMQAI9ZYOrOmvSpxPV4ab71it9z
 gi03VG8+iJl0dPgwcSHeFZvSDiNAOWSX/XdWLoxFAdpjpsnytIp01s9+c3ogz58j
 pYbjxuOT2Qcf+36REuaFkQPFV2ppXMvwDwFUUNeFVupu+bVUKeZuNafBDp00aN1c
 o4MPDwoS1EcTHL+77iCg06exL8LozOwLabfUTRVIRkhIqikemghcmubQHH06m+dk
 EMddtNcXTVR4cJLX076nkKsNDHgmfoBYL9Hy/OvQbjWYAxoZg+q90ZX8yCy0Z5oW
 otChj5XpoYRIa7X6xvP5kTebD4iiR/COWer83EyqFosXhmQ/27rWasST42j1K3q/
 mU40skbscDef4F6COMlgBtVh1FhKUm9AHPAGk5swW792Qjpd4xdt+GShU5bJCa4O
 OOZYk8ulraELeWVz2IK+CrOvJYeTSrNQR6VA6sBjWRHeqxtB0yOJkhxX9NUcSIgJ
 GwM8qNTrQUkvI7OGvFGvf8hp9cboJTKEfzC+yspj+OJSjgJgNWw2pOjzJjsexxaL
 nT2rKhPg46hC+FR4IvPPjhGihCtMSgBWkwbHSeXH+TgRfbbTUh6y6sqEUZraVhnQ
 LKde54G0aH1XBFIM6fwWIPgdWBWsI3b3pFuBRMzhORdcCuAUOvDSyc5hVcaA8qb5
 UZghapUruB556xjoMV3n
 =LlJD
 -----END PGP SIGNATURE-----

Merge tag 'iio-for-3.20a_take2' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-testing

Jonathan writes:

First round of IIO new drivers, cleanups and functionality for the 3.20 cycle take 2

Updated pull request with Daniel's fix on top for the power management
Kconfig changes that had snuck in since last update of the IIO tree
worked it's way through from mainline.

Original pull message

New device support
* jsa1212 proxmity / ambient light sensor
* SM08500 supported added to the kxcjk-1013 accelerometer driver
* KMX61 Accelerometer/Magnetometer.  This took a somewhat rocky path
  being first merged, then reverted for a rewrite after a discussion of
  how to support additional functionality and finally being merged prior
  to some last reviews coming in, with resultant follow up patches.
* Freescale mma9551l driver (minor follow up warning supression patch).
* Semtech SX9500 proximity device driver.
* ak8975 gains support for ak09911 and ak09912 and drop the standalone driver
  for the ak09911.

New functionality
 * Dummy driver gains some virtual registers making it more flexible.
 * IIO_ACTIVITY channel types, with modifiers running, walking etc.  This is
   to support on chip motion clasifiers.  As such it is in the form of a
   confidence percentage.  The only devices so far only do binary decisions
   but this gives us room when other devices give more nuanced clasification.
 * IIO_EV_DIR_NONE type for events where there is no obvious direction.
   First case is step detection.
 * IIO_STEPS channel type for pedometers.
 * ENABLE mask element used to control turning on counting types such as
   the pedometer that need a 'start point'.
 * INSTANCE event type to support things that happen once.
 * info element for height calibration (used in various motion estimation
   algorithms). Note heigh tof use
 * dummy driver demonstration of the use of all the new bits above.
 * event monitor support for the new events.
 * inv_mpu6050 gains an i2c mux to allow bypassing the device to access
   additional devices connected on the other side of it.  Note that in
   Windows these are handled by firmware on the device and not exposed
   directly.
 * inv_mpu6050 gains ACPI enumeration.
 * inkern interface gains iio_write_channel_raw to allow in kernel users
   of DAC functionality via a simple wrapper.
 * Document input current readings in the ABI docs.
 * Add an error message when we get an out of range error in device tree
   processing for the in kernel interfaces.  Basically a device tree debugging
   aid.
 * Add a sanity check that a scan index for a channel is unique during
   registration.  There to help catch bugs as this should never happen
   in a bug free driver.

Cleanups and fixlets

 A rework of buffer registration from Lars - a precursor to some other
 upcoming new stuff (a few patches from others rolled in here as well).
 * Ensure all drivers register the same channels for the device and buffer.
 * Move buffer registration into the core rather than using the old
   two step approach.  Now we have simple ways of using a unified set channels
   for both without requiring channels be exposed by both interface, this
   removes a fair bit of boilerplate.
 * Stop sca3000 and ad5933 (both in staging) enabling buffer channels by
   default. It has long be convention in IIO to startup with no channels
   enabled and leave it up to userspace to say what goes in the buffer.
   Getting rid of these allows us to drop export of iio_scan_mask_set.
 * Drop get_bytes_per_datum from iio_buffer_access_funcs as not been used
   for a while.
 * Allocate standard buffer attributes in the core rather than in every
   driver with a buffer.
 * Make the length attribute read only when a driver is not able to set
   the length.
 * Drop the get_length callback for buffers as it is already available in
   struct iio_buffer.
 * Drop an unused arguement form iio_kfifo_allocate and add devm allocator
   for it.
 * some kconfig entries gain anotation with the resulting module name.
 * Fix a resulting compile issue in dummy driver due to a stub taking
   wrong parameters as a result of the above rework.
 * Fix an off by 2 error in copying the core assigned buffer attributes.

Other cleanups,
 * Trivial space before comma fixups.
 * ak8975 fixlets - none critical.  Rework to allow more device support.
 * Drop unnecessary sizeof(u8) calls.
 * bmp280 - refactor the compensation code to reduce copy operations and
   code length.  A second patch futher optimized this and performed some
   other minor cleanups.
 * kxcjk-1013 - various power control cleanups to avoid unnecessary enable
   / disable of device.  Make sure it is only controlled at all if CONFIG_PM
   is enabled.  Also som cleanups of error paths.
 * Small cleanups in adf4530 driver - pointless message and unnecessary braces.
 * Clarifiy the proximity ABI docs to make it clear it should get bigger
   as we move futher away.
 * Drop a misleading comment form industrialio-core.c
 * Trivial white space cleanups.
 * sca3000 looses an unused debug function.
 * Fix char unsigned ordering in ad8366
 * Increase the sleep time in ad9523 to make it predictable (value didn't
   really matter so make it more than 20 msecs)
 * mxs-lradc touchscreen property cleanups in device tree are fixed to ensure
   the meet all the 'interesting' documentation.
 * A couple of cleanups for the staging ad5933 driver to avoid unnecessary
   conversion to a processed temperature vlaue in kernel and remove
   platform data form the state structure as not needed after probe.
 * Fix a wrong scale factor in the docs.

Misc
 * Add IIO include files to the maintainers entry.
2015-01-21 10:13:37 +08:00
Greg Kroah-Hartman 8ecb55b849 First round of IIO fixes for the 3.19 cycle.
* ad799x fix ad7991/ad7995/ad7999 setup as they do not have a configuration
   register to write to.  It is written during the convesion sequence. As
   such we don't want to write to it at other times.
 * Fix iio_channel_read utility function to return to ensure it is apparent
   if the relevant element is not there. This avoids using a wrong value
   if some channels have the element and others do not.
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2
 
 iQIcBAABCAAGBQJUqvMpAAoJEFSFNJnE9BaIuCMP+gIEdqqtPZAs7TH/tkQx0aqN
 DerVFgVwDrXFwAPKWYdwinE/u7qyRI77tNAo2f/QR4NBG1sjHc6FHhpgDCK2jPbh
 6QMQ64WH8svXlacStZTb45il2sh419tUj8BQeld8MjpqdpWK4RW8Ca4q8XjlmehG
 S4EyEHvYj/MQWpDy84RZEYEYlmeWhghxo2FGIWG2gKJ63Ejyo6kwjlxTJiNafj9/
 YN+J+C6J9r7o2mLuDtucslnGg6rTedLW7UijLAHGxfzAJFqjaMDGD0RZXgpEpfkx
 wRca7M0537psXuBy3onGXQTEKy72GP3Km9A/0yojbCWMj2OKI0LPSW7oTnWQ6gCw
 +V1ius+wPWSJ8PdRLZvp2hsWgZK9jE0zUSHsuB41ZJARTpsbExW56y8QOHSM1oX1
 3cmrhz6410qx8qe+qn8UwLIzJZCTbA71B4kdh6OiBmIUfV6CZBcwYOvrGKd9hGj/
 zmNl427NwhzgxO/OXeD5+lQR1tL2wVaKlrGFcwcMghCHno/c7o8aP8QuIYHkpNmq
 7f7ebIXpNHZHskGVacLFECRrZMEkVmq49b3PMIH+4zCgFTLtIBX8MS7VzGutThWw
 5ok1iUaG6aXh2jY8USYt3nCRi8DQoOSjJ5SXI1U3X6gS2tworeqmtMw9yTuc1juK
 s+XDwVFMJao56MdrzDyO
 =7f+n
 -----END PGP SIGNATURE-----

Merge tag 'iio-fixes-for-3.19a' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-linus

Jonathan writes:

First round of IIO fixes for the 3.19 cycle.

* ad799x fix ad7991/ad7995/ad7999 setup as they do not have a configuration
  register to write to.  It is written during the convesion sequence. As
  such we don't want to write to it at other times.
* Fix iio_channel_read utility function to return to ensure it is apparent
  if the relevant element is not there. This avoids using a wrong value
  if some channels have the element and others do not.
2015-01-08 17:59:04 -08:00
Stefan Wahren 1f202725b7 iio: inkern: add out of range error message
If the DT contains an invalid channel specifier then the probe of
iio_hwmon fails with the following message:

iio_hwmon: probe of iio_hwmon failed with error -22

So it's better to print out the relevant channel specifier in
error case to locate the problem.

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2015-01-05 18:59:50 +00:00
Fabien Proriol 65de7654d3 iio: iio: Fix iio_channel_read return if channel havn't info
When xilinx-xadc is used with hwmon driver to read voltage, offset used
for temperature is always applied whatever the channel.

iio_channel_read must return an error to avoid offset for channel
without IIO_CHAN_INFO_OFFSET property.

Signed-off-by: Fabien Proriol <fabien.proriol@jdsu.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2015-01-01 12:46:48 +00:00
Dmitry Eremin-Solenikov f9380e7123 iio: inkern: add iio_write_channel_raw
Introduce API for easy in-kernel setting of DAC values.

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2014-12-12 12:28:27 +00:00
Greg Kroah-Hartman be61a0d784 First round of new drivers, features and cleanups for IIO in the 3.19 cycle.
New drivers / supported parts
 * rockchip - rk3066-tsadc variant
 * si7020 humidity and temperature sensor
 * mcp320x - add mcp3001, mcp3002, mcp3004, mcp3008, mcp3201, mcp3202
 * bmp280 pressure and temperature sensor
 * Qualcomm SPMI PMIC current ADC driver
 * Exynos_adc - support exynos7
 
 New features
 * vf610-adc - add temperature sensor support
 * Documentation of current attributes, scaled pressure, offset and
   scaled humidity, RGBC intensity gain factor and scale applied to
   differential voltage channels.
 * Bring iio_event_monitor up to date with newer modifiers.
 * Add of_xlate function to allow for complex channel mappings from the
   device tree.
 * Add -g parameter to generic_buffer example to allow for devices with
   directly fed (no trigger) buffers.
 * Move exynos driver over to syscon for PMU register access.
 
 Cleanups, fixes for new drivers
 * lis3l02dq drop an unneeded else.
 * st sensors - renam st_sensors to st_sensor_settings (for clarity)
 * st sensors - drop an unused parameter from all the probe utility
   functions.
 * vf610 better error handling and tidy up.
 * si7020 - cleanups following merge
 * as3935 - drop some unnecessary semicolons.
 * bmp280 - fix the pressure calculation.
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2
 
 iQIcBAABAgAGBQJUWnZBAAoJEFSFNJnE9BaIZAAQAJpkot0ZAYPwtIkmtV1JqrLQ
 EZRkBN+cIf3q5zp/TnQTqfyhKbpHbJ9/Pnb0zHvn7Yh3WpZod2tyoC3xb8JAlX2h
 3tJRrA7plkdMjtwO/ryOxrVJYrm6rCeqKpciwMpDf4E/4fhU5CU++TpmWbhn04qB
 7PEZJN5dkmdnQYSIyNle11MYN+NpCAB4zqDvRJoJHpqZV6zAqygJy03H1PqXFS/S
 iNBL3jS8/PTbeUURUFOQTiqnJw5KuDke7OoXxUfvCpUwQfNLD8mOTrVrEoId1cM0
 Y2fmasfHteh83KP34/MOTwNA3EezM8iQOMzJnXtOpxpySPDrDSP68FDAJs15TUJm
 je8E1xxxdjOWuzgSd9djNm9qhlBkoYgbRwzc8wSAHMK7mCV7pP485WZk5E8rRX2z
 gMFgUmu4LkiZ2V9glGTAcHqnjhLNDTRCp1Nl/sMVgssFBBNjgR5+nZjUFqDR2QpD
 eo4ReIzev7Rzxe2lACRjnRrCnO+KKcjiDkyCdM3X2zdTddQRVrP5Uz+jgnvGAeMO
 hCYDHSOiMzV/r5emVfmNG9w8P9a6rZqu4KqcM/KjSzAfHFQTqmfr4Tkfn/hbeUjY
 h/zzB18EM4kUSxm3E6+CbFRWcfC7b/PLcUOwSitdujb9cYaX72gdesO2/P3jNFAK
 2bjoLRr5l4M4n/DeHae4
 =BDOo
 -----END PGP SIGNATURE-----

Merge tag 'iio-for-3.19a' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next

Jonathan writes:

First round of new drivers, features and cleanups for IIO in the 3.19 cycle.

New drivers / supported parts
* rockchip - rk3066-tsadc variant
* si7020 humidity and temperature sensor
* mcp320x - add mcp3001, mcp3002, mcp3004, mcp3008, mcp3201, mcp3202
* bmp280 pressure and temperature sensor
* Qualcomm SPMI PMIC current ADC driver
* Exynos_adc - support exynos7

New features
* vf610-adc - add temperature sensor support
* Documentation of current attributes, scaled pressure, offset and
  scaled humidity, RGBC intensity gain factor and scale applied to
  differential voltage channels.
* Bring iio_event_monitor up to date with newer modifiers.
* Add of_xlate function to allow for complex channel mappings from the
  device tree.
* Add -g parameter to generic_buffer example to allow for devices with
  directly fed (no trigger) buffers.
* Move exynos driver over to syscon for PMU register access.

Cleanups, fixes for new drivers
* lis3l02dq drop an unneeded else.
* st sensors - renam st_sensors to st_sensor_settings (for clarity)
* st sensors - drop an unused parameter from all the probe utility
  functions.
* vf610 better error handling and tidy up.
* si7020 - cleanups following merge
* as3935 - drop some unnecessary semicolons.
* bmp280 - fix the pressure calculation.
2014-11-05 11:42:48 -08:00
Ivan T. Ivanov acd8256723 iio: inkern: Add of_xlate function to struct iio_info
When #iio-cells is greater than '0', the driver could provide
a custom of_xlate function that reads the *args* and returns
the appropriate index in registered IIO channels array.

Add simple translation function, suitable for the most 1:1
mapped channels in IIO chips, and use it when driver did not
provide custom implementation.

Signed-off-by: Ivan T. Ivanov <iivanov@mm-sol.com>
Reviewed-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2014-10-25 11:03:40 +01:00
Johannes Pointner 872687f626 iio:inkern: fix overwritten -EPROBE_DEFER in of_iio_channel_get_by_name
Fixes: a2c12493ed ('iio: of_iio_channel_get_by_name() returns non-null pointers for error legs')

which improperly assumes that of_iio_channel_get_by_name must always
return NULL and thus now hides -EPROBE_DEFER.

Signed-off-by: Johannes Pointner <johannes.pointner@br-automation.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Cc: Stable@vger.kernel.org
2014-08-25 16:55:28 +01:00
Adam Thomson a2c12493ed iio: of_iio_channel_get_by_name() returns non-null pointers for error legs
Currently in the inkern.c code for IIO framework, the function
of_iio_channel_get_by_name() will return a non-NULL pointer when
it cannot find a channel using of_iio_channel_get() and when it
tries to search for 'io-channel-ranges' property and fails. This
is incorrect behaviour as the function which calls this expects
a NULL pointer for failure. This patch rectifies the issue.

Signed-off-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Cc: Stable@vger.kernel.org
2014-06-21 12:31:38 +01:00
Srinivas Pandruvada 9fbfb4b37e IIO: core: Introduce read_raw_multi
This callback is introduced to overcome some limitations of existing
read_raw callback. The functionality of both existing read_raw and
read_raw_multi is similar, both are used to request values from the
device. The current read_raw callback allows only two return values.
The new read_raw_multi allows returning multiple values. Instead of
passing just address of val and val2, it passes length and pointer
to values. Depending on the type and length of passed buffer, iio
client drivers can return multiple values.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2014-04-29 22:05:32 +01:00
Sebastian Reichel 476d4af22c iio: inkern: add iio_read_channel_average_raw
Add iio_read_channel_average_raw to support reading
averaged raw values in consumer drivers.

Signed-off-by: Sebastian Reichel <sre@debian.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2014-03-16 18:00:33 +00:00
Alexandre Belloni f91d1b63a4 iio: inkern: fix iio_convert_raw_to_processed_unlocked
When reading IIO_CHAN_INFO_OFFSET, the return value of iio_channel_read() for
success will be IIO_VAL*, checking for 0 is not correct.

Without this fix the offset applied by iio drivers will be ignored when
converting a raw value to one in appropriate base units (e.g mV) in
a IIO client drivers that use iio_convert_raw_to_processed including
iio-hwmon.

Cc: <stable@vger.kernel.org> # 3.10.x
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2013-07-03 20:30:52 +01:00
Michael Hennerich 6c5d4c96f9 iio:inkern: Fix typo/bug in convert raw to processed.
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2013-06-04 18:46:45 +01:00
Joe Perches e916b80d2b inkern: iio_device_put after incorrect return/goto
The code uses

    return foo;
    goto err_type;

when instead the form should have been

    ret = foo;
    goto err_type;

Here this causes a useful iio_device_put to be skipped.

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2013-06-04 18:28:21 +01:00
Guenter Roeck 17d82b47a2 iio: Add OF support
Provide bindings and parse OF data during initialization.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2013-03-16 10:17:59 +00:00
Guenter Roeck 5aa57f0a65 iio: Update iio_channel_get API to use consumer device pointer as argument
For iio_channel_get to work with OF based configurations, it needs the
consumer device pointer instead of the consumer device name as argument.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Anton Vorontsov <anton@enomsg.org>
Acked-by: Chanwoo Choi <cw00.choi@samsung.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2013-02-06 19:23:52 +00:00
Guenter Roeck 6cb2afd7c0 iio: Simplify iio_map_array_unregister API
Instead of requiring the map to unregister, simply unregister all map entries
associated with the given iio device. This simplifies map removal and also works
for maps generated through devicetree.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2013-02-02 12:02:20 +00:00
Guenter Roeck ca7d98dbd7 iio: Update iio_channel_get_all and iio_channel_get_all_cb API
Pass device pointer instead of device name as parameter to iio_channel_get_all
and iio_channel_get_all_cb. This will enable us to use OF information to
retrieve consumer channel information.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2013-02-02 11:58:46 +00:00
Jonathan Cameron 0464415dd2 staging:iio:in kernel users: Add a data field for channel specific info.
Used to allow information about a given channel mapping to be passed
through from board files to the consumer drivers.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2012-11-10 10:17:27 +00:00
Lars-Peter Clausen 103d9fb907 iio: Add a logarithmic fractional value type
For ADCs or DACs the denominator for fractional types often is a power of two.
In this case we can use a shift operation instead of the rather expensive 64 bit
division. This patch adds a new fractional type which expects the denominator to
be specified as the log2 of the actual denominator. E.g. for ADCs and DACs this
will usually be the number of significant bits.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2012-10-19 18:46:51 +01:00
Lars-Peter Clausen 7737fa6d1e iio: Don't compare boolean values to true/false
Fixes the following warnings from coccicheck:
	drivers/iio/inkern.c:81:6-14: WARNING: Comparison to bool
	drivers/iio/dac/ad5686.c:191:5-11: WARNING: Comparison to bool

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2012-10-19 16:26:24 +01:00
Kim, Milo 3183bac16f iio: inkern: clean up error return code
When the IIO consumer tries to get specific IIO channel,
 few error cases can be happened.
 (a) Memory allocation failure
 (b) No matched ADC channel error
 (c) Invalid input arguments
 This patch enables cleaning up error handling in case of (a) and (b).

 In error handling code,
 (a): the reference count of the IIO device should be decreased.
 (b): the allocated memory should be freed with restoring the reference count.
 Therefore iio_deivce_put() is called in both cases.
 This can be handled in the last error statement.

 Additionally, integer variable is used for stating each error case explicitly.
 Then, the error returns as ERR_PTR() with this value.

Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2012-09-22 10:13:33 +01:00
Kim, Milo 801c4b5ca3 iio: inkern: put the IIO device when it fails to allocate memory
The reference count of the IIO device is increased if the IIO map has
 matched consumer name.
 After then, it tries to allocate the iio_channel which is used by the consumer.
 If it fails to allocate memory, the reference count should be decreased.

 This patch enables restoring the reference count of the IIO device.

Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2012-09-22 10:13:32 +01:00
Lars-Peter Clausen 48e44ce0f8 iio:inkern: Add function to read the processed value
Add a function to read a processed value from a channel. The function will first
attempt to read the IIO_CHAN_INFO_PROCESSED attribute. If that fails it will
read the IIO_CHAN_INFO_RAW attribute and convert the result from a raw value to
a processed value.

The patch also introduces a function to convert raw value to a processed value
and exports it, in case a user needs or wants to do the conversion by itself.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2012-09-17 21:48:51 +01:00
Kim, Milo b2b79ffa40 iio: inkern: add error case in iio_channel_get()
The datasheet name is defined in the IIO driver.
 On the other hand, the adc_channel_label is configured in
 the platform side.
 If the datasheet name is not matched with any adc_channel_label,
 the iio_channel_get() should be returned as error for preventing
 invalid channel data access.

 This can be handled either way.
 (a) checking null data when using it : in the xxx_read_raw()
 or
 (b) error returns when the channel is requested : this patch

 The IIO consumer can't use the channel with invalid channel spec.
 Therefore case (b) is more reasonable.

Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2012-09-17 19:16:42 +01:00
Kim, Milo 2cc412b513 iio: inkern: allocate zeroed memory
Use kzalloc() rather than kmalloc() for initializing the iio_channel structure.
 This patch enables the iio_dev and iio_chan_spec are set to NULL.
 This may prevent the page fault problem because the pointer of iio_chan_spec
 is initialized as NULL.

 The iio_chan_spec is updated only in case that the IIO map has
 specific channel label.
 When the map has no ADC channel label, then the value of iio_chan_spec
 remains as invalid pointer.
 To prevent this problem, the pointer should be initialized as NULL.

Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2012-09-15 10:27:40 +01:00
Kim, Milo d965a8bc0c iio: use IIO_CHAN_INFO_RAW rather than 0
(a) For better readability, replace 0 with IIO_CHAN_INFO_RAW.
(b) Make same line-format as other apis()
    : iio_read_channel_scale() and iio_read_channel_offset()

Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2012-08-27 18:24:45 +01:00
Dan Carpenter e59b9afecf iio: double unlock on error path
We should be holding the mutex when we goto error_free_chans.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2012-07-12 20:00:20 +01:00
Jonathan Cameron 7b7627410e iio: Fix inkern remove incorrect put of device
The device_get is after this point so on error we should not be
removing it.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2012-07-08 20:02:31 +01:00
Jonathan Cameron 314be14bb8 iio: Rename _st_ functions to loose the bit that meant the staging version.
These were originally introduced when the plan was to have parallel
IIO cores in and out of staging with a slow move between them.
Now we have reached the point where the whole core has moved,
they need clearing up!

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2012-06-30 10:15:12 +01:00
Lars-Peter Clausen 1875ffd218 iio:inkern: Use iio_device_{get,put}
Use iio_device_get and iio_device_put instead of open-coding it.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Acked-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-06-04 21:21:29 -07:00
Greg Kroah-Hartman d210267741 Merge 3.4-rc5 into staging-next
This resolves the conflict in:
	drivers/staging/vt6656/ioctl.c

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-05-02 11:48:07 -07:00
Jonathan Cameron a980e04609 IIO: Move the core files to drivers/iio
Take the core support + the kfifo buffer implentation out of
staging.  Whilst we are far from done in improving this subsystem
it is now at a stage where the userspae interfaces (provided by
the core) can be considered stable.

Drivers will follow over a longer time scale.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-04-25 11:11:38 -07:00