Merge tag 'iio-for-4.8b' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio...
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 29 Jun 2016 22:35:01 +0000 (15:35 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 29 Jun 2016 22:35:01 +0000 (15:35 -0700)
Jonathan writes:

Second round of new iio device support, features and cleanups in the 4.8 cycle

Firstly some contact detail updates:
* NXP took over freescale. Update the mma8452 header to reflect this.
* Martin Kepplinger email address change in mma8452 header.
* Adriana Reus has changed email address. Update .mailmap.
* Matt Ranostay has changed email address. Update .mailmap.

New Device Support
* max1363
  - add the missing i2c_device_ids for a couple of parts so they can actually
    be used.
* ms5867
  - add device ids for ms5805 and ms5837 parts.

New Features
* ad5755
  - DT support.  This one was a bit controversial and under review for a long
    time.  Still no one could come up with a better solution.
* stx104
  - add gpio support
* ti-adc081c
  - Add ACPI device ID matching.

Core changes
* Refuse to register triggers with duplicate names.  There is no way to
  distinguish between them so this makes no sense.  A few drivers do not
  generate unique names for each instance of the device present.  We can't
  fix this without changing ABI so leave them and wait for someone to
  actually take the rare step of two identical accelerometers on the same
  board.
* buffer-dma
  - use ARRAY_SIZE in a few appropriate locations.

Tools
* Fix the fact that the --trigger-num option in generic_buffer didn't allow
  0 which is perfectly valid in the ABI.

Cleanups
* as3935
  - improve error reporting.
  - remove redundant zeroing of a field in iio_priv.
* gp2ap020a00f
  - use the iio_device_claim_*_mode helpers rather than open coding locking
  around mode changes.
* isl29125
  - use the iio_device_claim_*_mode helpers rather than open coding locking.
* lidar
  - use the iio_device_claim_*_mode helpers rather than open coding locking.
* mma8452
  - more detail in devices supported description in comments (addresses and
  similar)
* sca3000
  - add a missing error check.
* tcs3414
  - use the iio_device_claim_*_mode helpers rather than open coding locking.
* tcs3472
  - use the iio_device_claim_*_mode helpers rather than open coding locking.

1  2 
.mailmap
drivers/iio/dac/Kconfig
drivers/iio/dac/stx104.c
drivers/iio/industrialio-trigger.c
drivers/iio/proximity/as3935.c

diff --combined .mailmap
+++ b/.mailmap
@@@ -11,6 -11,7 +11,7 @@@ Aaron Durbin <adurbin@google.com
  Adam Oldham <oldhamca@gmail.com>
  Adam Radford <aradford@gmail.com>
  Adrian Bunk <bunk@stusta.de>
+ Adriana Reus <adi.reus@gmail.com> <adriana.reus@intel.com>
  Alan Cox <alan@lxorguk.ukuu.org.uk>
  Alan Cox <root@hraefn.swansea.linux.org.uk>
  Aleksey Gorelov <aleksey_gorelov@phoenix.com>
@@@ -33,7 -34,6 +34,7 @@@ Björn Steinbrink <B.Steinbrink@gmx.de
  Brian Avery <b.avery@hp.com>
  Brian King <brking@us.ibm.com>
  Christoph Hellwig <hch@lst.de>
 +Christophe Ricard <christophe.ricard@gmail.com>
  Corey Minyard <minyard@acm.org>
  Damian Hobson-Garcia <dhobsong@igel.co.jp>
  David Brownell <david-b@pacbell.net>
@@@ -48,9 -48,6 +49,9 @@@ Felix Kuhling <fxkuehl@gmx.de
  Felix Moeller <felix@derklecks.de>
  Filipe Lautert <filipe@icewall.org>
  Franck Bui-Huu <vagabon.xyz@gmail.com>
 +Frank Rowand <frowand.list@gmail.com> <frowand@mvista.com>
 +Frank Rowand <frowand.list@gmail.com> <frank.rowand@am.sony.com>
 +Frank Rowand <frowand.list@gmail.com> <frank.rowand@sonymobile.com>
  Frank Zago <fzago@systemfabricworks.com>
  Greg Kroah-Hartman <greg@echidna.(none)>
  Greg Kroah-Hartman <gregkh@suse.de>
@@@ -69,7 -66,6 +70,7 @@@ Jean Tourrilhes <jt@hpl.hp.com
  Jeff Garzik <jgarzik@pretzel.yyz.us>
  Jens Axboe <axboe@suse.de>
  Jens Osterkamp <Jens.Osterkamp@de.ibm.com>
 +John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
  John Stultz <johnstul@us.ibm.com>
  <josh@joshtriplett.org> <josh@freedesktop.org>
  <josh@joshtriplett.org> <josh@kernel.org>
@@@ -83,13 -79,13 +84,15 @@@ Kay Sievers <kay.sievers@vrfy.org
  Kenneth W Chen <kenneth.w.chen@intel.com>
  Konstantin Khlebnikov <koct9i@gmail.com> <k.khlebnikov@samsung.com>
  Koushik <raghavendra.koushik@neterion.com>
 +Krzysztof Kozlowski <krzk@kernel.org> <k.kozlowski.k@gmail.com>
  Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  Leonid I Ananiev <leonid.i.ananiev@intel.com>
  Linas Vepstas <linas@austin.ibm.com>
  Mark Brown <broonie@sirena.org.uk>
  Matthieu CASTET <castet.matthieu@free.fr>
 +Mauro Carvalho Chehab <mchehab@kernel.org> <maurochehab@gmail.com> <mchehab@infradead.org> <mchehab@redhat.com> <m.chehab@samsung.com> <mchehab@osg.samsung.com> <mchehab@s-opensource.com>
+ Matt Ranostay <mranostay@gmail.com> Matthew Ranostay <mranostay@embeddedalley.com>
+ Matt Ranostay <mranostay@gmail.com> <matt.ranostay@intel.com>
  Mayuresh Janorkar <mayur@ti.com>
  Michael Buesch <m@bues.ch>
  Michel Dänzer <michel@tungstengraphics.com>
@@@ -123,7 -119,6 +126,7 @@@ Santosh Shilimkar <santosh.shilimkar@or
  Sascha Hauer <s.hauer@pengutronix.de>
  S.Çağlar Onur <caglar@pardus.org.tr>
  Shiraz Hashim <shiraz.linux.kernel@gmail.com> <shiraz.hashim@st.com>
 +Shuah Khan <shuah@kernel.org> <shuahkhan@gmail.com> <shuah.khan@hp.com> <shuahkh@osg.samsung.com> <shuah.kh@samsung.com>
  Simon Kelley <simon@thekelleys.org.uk>
  Stéphane Witzmann <stephane.witzmann@ubpmes.univ-bpclermont.fr>
  Stephen Hemminger <shemminger@osdl.org>
diff --combined drivers/iio/dac/Kconfig
@@@ -246,13 -246,14 +246,14 @@@ config MCP492
          will be called mcp4922.
  
  config STX104
 -      tristate "Apex Embedded Systems STX104 driver"
 -      depends on ISA
 +      tristate "Apex Embedded Systems STX104 DAC driver"
 +      depends on X86 && ISA_BUS_API
+       select GPIOLIB
        help
-         Say yes here to build support for the 2-channel DAC on the Apex
-         Embedded Systems STX104 integrated analog PC/104 card. The base port
-         addresses for the devices may be configured via the "base" module
-         parameter array.
+         Say yes here to build support for the 2-channel DAC and GPIO on the
+         Apex Embedded Systems STX104 integrated analog PC/104 card. The base
+         port addresses for the devices may be configured via the base array
+         module parameter.
  
  config VF610_DAC
        tristate "Vybrid vf610 DAC driver"
diff --combined drivers/iio/dac/stx104.c
@@@ -14,6 -14,7 +14,7 @@@
  #include <linux/bitops.h>
  #include <linux/device.h>
  #include <linux/errno.h>
+ #include <linux/gpio/driver.h>
  #include <linux/iio/iio.h>
  #include <linux/iio/types.h>
  #include <linux/io.h>
@@@ -21,6 -22,7 +22,7 @@@
  #include <linux/isa.h>
  #include <linux/module.h>
  #include <linux/moduleparam.h>
+ #include <linux/spinlock.h>
  
  #define STX104_NUM_CHAN 2
  
  }
  
  #define STX104_EXTENT 16
 -/**
 - * The highest base address possible for an ISA device is 0x3FF; this results in
 - * 1024 possible base addresses. Dividing the number of possible base addresses
 - * by the address extent taken by each device results in the maximum number of
 - * devices on a system.
 - */
 -#define MAX_NUM_STX104 (1024 / STX104_EXTENT)
  
 -static unsigned base[MAX_NUM_STX104];
 -static unsigned num_stx104;
 +static unsigned int base[max_num_isa_dev(STX104_EXTENT)];
 +static unsigned int num_stx104;
  module_param_array(base, uint, &num_stx104, 0);
  MODULE_PARM_DESC(base, "Apex Embedded Systems STX104 base addresses");
  
@@@ -49,6 -58,20 +51,20 @@@ struct stx104_iio 
        unsigned base;
  };
  
+ /**
+  * struct stx104_gpio - GPIO device private data structure
+  * @chip:     instance of the gpio_chip
+  * @lock:     synchronization lock to prevent I/O race conditions
+  * @base:     base port address of the GPIO device
+  * @out_state:        output bits state
+  */
+ struct stx104_gpio {
+       struct gpio_chip chip;
+       spinlock_t lock;
+       unsigned int base;
+       unsigned int out_state;
+ };
  static int stx104_read_raw(struct iio_dev *indio_dev,
        struct iio_chan_spec const *chan, int *val, int *val2, long mask)
  {
@@@ -88,15 -111,81 +104,81 @@@ static const struct iio_chan_spec stx10
        STX104_CHAN(1)
  };
  
+ static int stx104_gpio_get_direction(struct gpio_chip *chip,
+       unsigned int offset)
+ {
+       if (offset < 4)
+               return 1;
+       return 0;
+ }
+ static int stx104_gpio_direction_input(struct gpio_chip *chip,
+       unsigned int offset)
+ {
+       if (offset >= 4)
+               return -EINVAL;
+       return 0;
+ }
+ static int stx104_gpio_direction_output(struct gpio_chip *chip,
+       unsigned int offset, int value)
+ {
+       if (offset < 4)
+               return -EINVAL;
+       chip->set(chip, offset, value);
+       return 0;
+ }
+ static int stx104_gpio_get(struct gpio_chip *chip, unsigned int offset)
+ {
+       struct stx104_gpio *const stx104gpio = gpiochip_get_data(chip);
+       if (offset >= 4)
+               return -EINVAL;
+       return !!(inb(stx104gpio->base) & BIT(offset));
+ }
+ static void stx104_gpio_set(struct gpio_chip *chip, unsigned int offset,
+       int value)
+ {
+       struct stx104_gpio *const stx104gpio = gpiochip_get_data(chip);
+       const unsigned int mask = BIT(offset) >> 4;
+       unsigned long flags;
+       if (offset < 4)
+               return;
+       spin_lock_irqsave(&stx104gpio->lock, flags);
+       if (value)
+               stx104gpio->out_state |= mask;
+       else
+               stx104gpio->out_state &= ~mask;
+       outb(stx104gpio->out_state, stx104gpio->base);
+       spin_unlock_irqrestore(&stx104gpio->lock, flags);
+ }
  static int stx104_probe(struct device *dev, unsigned int id)
  {
        struct iio_dev *indio_dev;
        struct stx104_iio *priv;
+       struct stx104_gpio *stx104gpio;
+       int err;
  
        indio_dev = devm_iio_device_alloc(dev, sizeof(*priv));
        if (!indio_dev)
                return -ENOMEM;
  
+       stx104gpio = devm_kzalloc(dev, sizeof(*stx104gpio), GFP_KERNEL);
+       if (!stx104gpio)
+               return -ENOMEM;
        if (!devm_request_region(dev, base[id], STX104_EXTENT,
                dev_name(dev))) {
                dev_err(dev, "Unable to lock port addresses (0x%X-0x%X)\n",
        outw(0, base[id] + 4);
        outw(0, base[id] + 6);
  
-       return devm_iio_device_register(dev, indio_dev);
+       err = devm_iio_device_register(dev, indio_dev);
+       if (err) {
+               dev_err(dev, "IIO device registering failed (%d)\n", err);
+               return err;
+       }
+       stx104gpio->chip.label = dev_name(dev);
+       stx104gpio->chip.parent = dev;
+       stx104gpio->chip.owner = THIS_MODULE;
+       stx104gpio->chip.base = -1;
+       stx104gpio->chip.ngpio = 8;
+       stx104gpio->chip.get_direction = stx104_gpio_get_direction;
+       stx104gpio->chip.direction_input = stx104_gpio_direction_input;
+       stx104gpio->chip.direction_output = stx104_gpio_direction_output;
+       stx104gpio->chip.get = stx104_gpio_get;
+       stx104gpio->chip.set = stx104_gpio_set;
+       stx104gpio->base = base[id] + 3;
+       stx104gpio->out_state = 0x0;
+       spin_lock_init(&stx104gpio->lock);
+       dev_set_drvdata(dev, stx104gpio);
+       err = gpiochip_add_data(&stx104gpio->chip, stx104gpio);
+       if (err) {
+               dev_err(dev, "GPIO registering failed (%d)\n", err);
+               return err;
+       }
+       return 0;
+ }
+ static int stx104_remove(struct device *dev, unsigned int id)
+ {
+       struct stx104_gpio *const stx104gpio = dev_get_drvdata(dev);
+       gpiochip_remove(&stx104gpio->chip);
+       return 0;
  }
  
  static struct isa_driver stx104_driver = {
        .probe = stx104_probe,
        .driver = {
                .name = "stx104"
-       }
+       },
+       .remove = stx104_remove
  };
  
 -static void __exit stx104_exit(void)
 -{
 -      isa_unregister_driver(&stx104_driver);
 -}
 -
 -static int __init stx104_init(void)
 -{
 -      return isa_register_driver(&stx104_driver, num_stx104);
 -}
 -
 -module_init(stx104_init);
 -module_exit(stx104_exit);
 +module_isa_driver(stx104_driver, num_stx104);
  
  MODULE_AUTHOR("William Breathitt Gray <vilhelm.gray@gmail.com>");
  MODULE_DESCRIPTION("Apex Embedded Systems STX104 DAC driver");
@@@ -64,6 -64,8 +64,8 @@@ static struct attribute *iio_trig_dev_a
  };
  ATTRIBUTE_GROUPS(iio_trig_dev);
  
+ static struct iio_trigger *__iio_trigger_find_by_name(const char *name);
  int iio_trigger_register(struct iio_trigger *trig_info)
  {
        int ret;
  
        /* Add to list of available triggers held by the IIO core */
        mutex_lock(&iio_trigger_list_lock);
+       if (__iio_trigger_find_by_name(trig_info->name)) {
+               pr_err("Duplicate trigger name '%s'\n", trig_info->name);
+               ret = -EEXIST;
+               goto error_device_del;
+       }
        list_add_tail(&trig_info->list, &iio_trigger_list);
        mutex_unlock(&iio_trigger_list_lock);
  
        return 0;
  
+ error_device_del:
+       mutex_unlock(&iio_trigger_list_lock);
+       device_del(&trig_info->dev);
  error_unregister_id:
        ida_simple_remove(&iio_trigger_ida, trig_info->id);
        return ret;
@@@ -109,6 -119,18 +119,18 @@@ void iio_trigger_unregister(struct iio_
  }
  EXPORT_SYMBOL(iio_trigger_unregister);
  
+ /* Search for trigger by name, assuming iio_trigger_list_lock held */
+ static struct iio_trigger *__iio_trigger_find_by_name(const char *name)
+ {
+       struct iio_trigger *iter;
+       list_for_each_entry(iter, &iio_trigger_list, list)
+               if (!strcmp(iter->name, name))
+                       return iter;
+       return NULL;
+ }
  static struct iio_trigger *iio_trigger_find_by_name(const char *name,
                                                    size_t len)
  {
@@@ -213,35 -235,22 +235,35 @@@ static int iio_trigger_attach_poll_func
  
        /* Prevent the module from being removed whilst attached to a trigger */
        __module_get(pf->indio_dev->info->driver_module);
 +
 +      /* Get irq number */
        pf->irq = iio_trigger_get_irq(trig);
 +      if (pf->irq < 0)
 +              goto out_put_module;
 +
 +      /* Request irq */
        ret = request_threaded_irq(pf->irq, pf->h, pf->thread,
                                   pf->type, pf->name,
                                   pf);
 -      if (ret < 0) {
 -              module_put(pf->indio_dev->info->driver_module);
 -              return ret;
 -      }
 +      if (ret < 0)
 +              goto out_put_irq;
  
 +      /* Enable trigger in driver */
        if (trig->ops->set_trigger_state && notinuse) {
                ret = trig->ops->set_trigger_state(trig, true);
                if (ret < 0)
 -                      module_put(pf->indio_dev->info->driver_module);
 +                      goto out_free_irq;
        }
  
        return ret;
 +
 +out_free_irq:
 +      free_irq(pf->irq, pf);
 +out_put_irq:
 +      iio_trigger_put_irq(trig, pf->irq);
 +out_put_module:
 +      module_put(pf->indio_dev->info->driver_module);
 +      return ret;
  }
  
  static int iio_trigger_detach_poll_func(struct iio_trigger *trig,
@@@ -64,7 -64,6 +64,7 @@@ struct as3935_state 
        struct delayed_work work;
  
        u32 tune_cap;
 +      u8 buffer[16]; /* 8-bit data + 56-bit padding + 64-bit timestamp */
        u8 buf[2] ____cacheline_aligned;
  };
  
@@@ -73,8 -72,7 +73,8 @@@ static const struct iio_chan_spec as393
                .type           = IIO_PROXIMITY,
                .info_mask_separate =
                        BIT(IIO_CHAN_INFO_RAW) |
 -                      BIT(IIO_CHAN_INFO_PROCESSED),
 +                      BIT(IIO_CHAN_INFO_PROCESSED) |
 +                      BIT(IIO_CHAN_INFO_SCALE),
                .scan_index     = 0,
                .scan_type = {
                        .sign           = 'u',
@@@ -183,12 -181,7 +183,12 @@@ static int as3935_read_raw(struct iio_d
                /* storm out of range */
                if (*val == AS3935_DATA_MASK)
                        return -EINVAL;
 -              *val *= 1000;
 +
 +              if (m == IIO_CHAN_INFO_PROCESSED)
 +                      *val *= 1000;
 +              break;
 +      case IIO_CHAN_INFO_SCALE:
 +              *val = 1000;
                break;
        default:
                return -EINVAL;
@@@ -213,10 -206,10 +213,10 @@@ static irqreturn_t as3935_trigger_handl
        ret = as3935_read(st, AS3935_DATA, &val);
        if (ret)
                goto err_read;
 -      val &= AS3935_DATA_MASK;
 -      val *= 1000;
  
 -      iio_push_to_buffers_with_timestamp(indio_dev, &val, pf->timestamp);
 +      st->buffer[0] = val & AS3935_DATA_MASK;
 +      iio_push_to_buffers_with_timestamp(indio_dev, &st->buffer,
 +                                         pf->timestamp);
  err_read:
        iio_trigger_notify_done(indio_dev->trig);
  
@@@ -231,10 -224,16 +231,16 @@@ static void as3935_event_work(struct wo
  {
        struct as3935_state *st;
        int val;
+       int ret;
  
        st = container_of(work, struct as3935_state, work.work);
  
-       as3935_read(st, AS3935_INT, &val);
+       ret = as3935_read(st, AS3935_INT, &val);
+       if (ret) {
+               dev_warn(&st->spi->dev, "read error\n");
+               return;
+       }
        val &= AS3935_INT_MASK;
  
        switch (val) {
                iio_trigger_poll(st->trig);
                break;
        case AS3935_NOISE_INT:
-               dev_warn(&st->spi->dev, "noise level is too high");
+               dev_warn(&st->spi->dev, "noise level is too high\n");
                break;
        }
  }
@@@ -346,7 -345,6 +352,6 @@@ static int as3935_probe(struct spi_devi
  
        st = iio_priv(indio_dev);
        st->spi = spi;
-       st->tune_cap = 0;
  
        spi_set_drvdata(spi, indio_dev);
        mutex_init(&st->lock);