Merge remote-tracking branch 'spi/topic/core' into spi-next
authorMark Brown <broonie@kernel.org>
Wed, 26 Apr 2017 14:57:58 +0000 (15:57 +0100)
committerMark Brown <broonie@kernel.org>
Wed, 26 Apr 2017 14:57:58 +0000 (15:57 +0100)
1  2 
drivers/spi/spi.c

diff --combined drivers/spi/spi.c
index 90b5b2efafbf45c2435af2771c4842a37786eee7,0af62c6f93a84834becac26845e760e7a9dd6ead..b4a8bb7759b2cdc7cf2a4e9688cda03523f431a9
@@@ -33,7 -33,6 +33,7 @@@
  #include <linux/pm_domain.h>
  #include <linux/export.h>
  #include <linux/sched/rt.h>
 +#include <uapi/linux/sched/types.h>
  #include <linux/delay.h>
  #include <linux/kthread.h>
  #include <linux/ioport.h>
@@@ -622,10 -621,8 +622,10 @@@ void spi_unregister_device(struct spi_d
        if (!spi)
                return;
  
 -      if (spi->dev.of_node)
 +      if (spi->dev.of_node) {
                of_node_clear_flag(spi->dev.of_node, OF_POPULATED);
 +              of_node_put(spi->dev.of_node);
 +      }
        if (ACPI_COMPANION(&spi->dev))
                acpi_device_clear_enumerated(ACPI_COMPANION(&spi->dev));
        device_unregister(&spi->dev);
@@@ -675,7 -672,7 +675,7 @@@ int spi_register_board_info(struct spi_
        if (!n)
                return -EINVAL;
  
 -      bi = kzalloc(n * sizeof(*bi), GFP_KERNEL);
 +      bi = kcalloc(n, sizeof(*bi), GFP_KERNEL);
        if (!bi)
                return -ENOMEM;
  
@@@ -808,12 -805,12 +808,12 @@@ static int __spi_map_msg(struct spi_mas
        if (master->dma_tx)
                tx_dev = master->dma_tx->device->dev;
        else
 -              tx_dev = &master->dev;
 +              tx_dev = master->dev.parent;
  
        if (master->dma_rx)
                rx_dev = master->dma_rx->device->dev;
        else
 -              rx_dev = &master->dev;
 +              rx_dev = master->dev.parent;
  
        list_for_each_entry(xfer, &msg->transfers, transfer_list) {
                if (!master->can_dma(master, msg->spi, xfer))
@@@ -855,12 -852,12 +855,12 @@@ static int __spi_unmap_msg(struct spi_m
        if (master->dma_tx)
                tx_dev = master->dma_tx->device->dev;
        else
 -              tx_dev = &master->dev;
 +              tx_dev = master->dev.parent;
  
        if (master->dma_rx)
                rx_dev = master->dma_rx->device->dev;
        else
 -              rx_dev = &master->dev;
 +              rx_dev = master->dev.parent;
  
        list_for_each_entry(xfer, &msg->transfers, transfer_list) {
                if (!master->can_dma(master, msg->spi, xfer))
@@@ -1015,7 -1012,7 +1015,7 @@@ static int spi_transfer_one_message(str
                                ret = 0;
                                ms = 8LL * 1000LL * xfer->len;
                                do_div(ms, xfer->speed_hz);
-                               ms += ms + 100; /* some tolerance */
+                               ms += ms + 200; /* some tolerance */
  
                                if (ms > UINT_MAX)
                                        ms = UINT_MAX;
@@@ -1505,18 -1502,37 +1505,18 @@@ err_init_queue
  /*-------------------------------------------------------------------------*/
  
  #if defined(CONFIG_OF)
 -static struct spi_device *
 -of_register_spi_device(struct spi_master *master, struct device_node *nc)
 +static int of_spi_parse_dt(struct spi_master *master, struct spi_device *spi,
 +                         struct device_node *nc)
  {
 -      struct spi_device *spi;
 -      int rc;
        u32 value;
 -
 -      /* Alloc an spi_device */
 -      spi = spi_alloc_device(master);
 -      if (!spi) {
 -              dev_err(&master->dev, "spi_device alloc error for %s\n",
 -                      nc->full_name);
 -              rc = -ENOMEM;
 -              goto err_out;
 -      }
 -
 -      /* Select device driver */
 -      rc = of_modalias_node(nc, spi->modalias,
 -                              sizeof(spi->modalias));
 -      if (rc < 0) {
 -              dev_err(&master->dev, "cannot find modalias for %s\n",
 -                      nc->full_name);
 -              goto err_out;
 -      }
 +      int rc;
  
        /* Device address */
        rc = of_property_read_u32(nc, "reg", &value);
        if (rc) {
                dev_err(&master->dev, "%s has no valid 'reg' property (%d)\n",
                        nc->full_name, rc);
 -              goto err_out;
 +              return rc;
        }
        spi->chip_select = value;
  
        if (rc) {
                dev_err(&master->dev, "%s has no valid 'spi-max-frequency' property (%d)\n",
                        nc->full_name, rc);
 -              goto err_out;
 +              return rc;
        }
        spi->max_speed_hz = value;
  
 +      return 0;
 +}
 +
 +static struct spi_device *
 +of_register_spi_device(struct spi_master *master, struct device_node *nc)
 +{
 +      struct spi_device *spi;
 +      int rc;
 +
 +      /* Alloc an spi_device */
 +      spi = spi_alloc_device(master);
 +      if (!spi) {
 +              dev_err(&master->dev, "spi_device alloc error for %s\n",
 +                      nc->full_name);
 +              rc = -ENOMEM;
 +              goto err_out;
 +      }
 +
 +      /* Select device driver */
 +      rc = of_modalias_node(nc, spi->modalias,
 +                              sizeof(spi->modalias));
 +      if (rc < 0) {
 +              dev_err(&master->dev, "cannot find modalias for %s\n",
 +                      nc->full_name);
 +              goto err_out;
 +      }
 +
 +      rc = of_spi_parse_dt(master, spi, nc);
 +      if (rc)
 +              goto err_out;
 +
        /* Store a pointer to the node in the device structure */
        of_node_get(nc);
        spi->dev.of_node = nc;
        if (rc) {
                dev_err(&master->dev, "spi_device register error %s\n",
                        nc->full_name);
 -              goto err_out;
 +              goto err_of_node_put;
        }
  
        return spi;
  
 +err_of_node_put:
 +      of_node_put(nc);
  err_out:
        spi_dev_put(spi);
        return ERR_PTR(rc);
@@@ -1739,15 -1722,13 +1739,15 @@@ static acpi_status acpi_register_spi_de
                return AE_OK;
        }
  
 +      acpi_set_modalias(adev, acpi_device_hid(adev), spi->modalias,
 +                        sizeof(spi->modalias));
 +
        if (spi->irq < 0)
                spi->irq = acpi_dev_gpio_irq_get(adev, 0);
  
        acpi_device_set_enumerated(adev);
  
        adev->power.flags.ignore_parent = true;
 -      strlcpy(spi->modalias, acpi_device_hid(adev), sizeof(spi->modalias));
        if (spi_add_device(spi)) {
                adev->power.flags.ignore_parent = false;
                dev_err(&master->dev, "failed to add SPI device %s from ACPI\n",