Merge tag 'sound-6.0-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai...
[linux-2.6-block.git] / drivers / platform / x86 / serial-multi-instantiate.c
index e98007197cf5239e9193cc2525254478984d1001..5362f1a7b77c5df4c654c62c8b14fc09910feb16 100644 (file)
@@ -61,36 +61,35 @@ static int smi_get_irq(struct platform_device *pdev, struct acpi_device *adev,
        default:
                return 0;
        }
-
        if (ret < 0)
-               dev_err_probe(&pdev->dev, ret, "Error requesting irq at index %d: %d\n",
-                             inst->irq_idx, ret);
+               return dev_err_probe(&pdev->dev, ret, "Error requesting irq at index %d\n",
+                                    inst->irq_idx);
 
        return ret;
 }
 
 static void smi_devs_unregister(struct smi *smi)
 {
-       while (smi->i2c_num > 0)
-               i2c_unregister_device(smi->i2c_devs[--smi->i2c_num]);
+       while (smi->i2c_num--)
+               i2c_unregister_device(smi->i2c_devs[smi->i2c_num]);
 
-       while (smi->spi_num > 0)
-               spi_unregister_device(smi->spi_devs[--smi->spi_num]);
+       while (smi->spi_num--)
+               spi_unregister_device(smi->spi_devs[smi->spi_num]);
 }
 
 /**
  * smi_spi_probe - Instantiate multiple SPI devices from inst array
  * @pdev:      Platform device
- * @adev:      ACPI device
  * @smi:       Internal struct for Serial multi instantiate driver
  * @inst_array:        Array of instances to probe
  *
  * Returns the number of SPI devices instantiate, Zero if none is found or a negative error code.
  */
-static int smi_spi_probe(struct platform_device *pdev, struct acpi_device *adev, struct smi *smi,
+static int smi_spi_probe(struct platform_device *pdev, struct smi *smi,
                         const struct smi_instance *inst_array)
 {
        struct device *dev = &pdev->dev;
+       struct acpi_device *adev = ACPI_COMPANION(dev);
        struct spi_controller *ctlr;
        struct spi_device *spi_dev;
        char name[50];
@@ -99,8 +98,8 @@ static int smi_spi_probe(struct platform_device *pdev, struct acpi_device *adev,
        ret = acpi_spi_count_resources(adev);
        if (ret < 0)
                return ret;
-       else if (!ret)
-               return -ENODEV;
+       if (!ret)
+               return -ENOENT;
 
        count = ret;
 
@@ -112,9 +111,8 @@ static int smi_spi_probe(struct platform_device *pdev, struct acpi_device *adev,
 
                spi_dev = acpi_spi_device_alloc(NULL, adev, i);
                if (IS_ERR(spi_dev)) {
-                       ret = PTR_ERR(spi_dev);
-                       dev_err_probe(dev, ret, "failed to allocate SPI device %s from ACPI: %d\n",
-                                     dev_name(&adev->dev), ret);
+                       ret = dev_err_probe(dev, PTR_ERR(spi_dev), "failed to allocate SPI device %s from ACPI\n",
+                                           dev_name(&adev->dev));
                        goto error;
                }
 
@@ -135,9 +133,8 @@ static int smi_spi_probe(struct platform_device *pdev, struct acpi_device *adev,
 
                ret = spi_add_device(spi_dev);
                if (ret) {
-                       dev_err_probe(&ctlr->dev, ret,
-                                     "failed to add SPI device %s from ACPI: %d\n",
-                                     dev_name(&adev->dev), ret);
+                       dev_err_probe(&ctlr->dev, ret, "failed to add SPI device %s from ACPI\n",
+                                     dev_name(&adev->dev));
                        spi_dev_put(spi_dev);
                        goto error;
                }
@@ -166,25 +163,25 @@ error:
 /**
  * smi_i2c_probe - Instantiate multiple I2C devices from inst array
  * @pdev:      Platform device
- * @adev:      ACPI device
  * @smi:       Internal struct for Serial multi instantiate driver
  * @inst_array:        Array of instances to probe
  *
  * Returns the number of I2C devices instantiate, Zero if none is found or a negative error code.
  */
-static int smi_i2c_probe(struct platform_device *pdev, struct acpi_device *adev, struct smi *smi,
+static int smi_i2c_probe(struct platform_device *pdev, struct smi *smi,
                         const struct smi_instance *inst_array)
 {
        struct i2c_board_info board_info = {};
        struct device *dev = &pdev->dev;
+       struct acpi_device *adev = ACPI_COMPANION(dev);
        char name[32];
        int i, ret, count;
 
        ret = i2c_acpi_client_count(adev);
        if (ret < 0)
                return ret;
-       else if (!ret)
-               return -ENODEV;
+       if (!ret)
+               return -ENOENT;
 
        count = ret;
 
@@ -230,12 +227,8 @@ static int smi_probe(struct platform_device *pdev)
 {
        struct device *dev = &pdev->dev;
        const struct smi_node *node;
-       struct acpi_device *adev;
        struct smi *smi;
-
-       adev = ACPI_COMPANION(dev);
-       if (!adev)
-               return -ENODEV;
+       int ret;
 
        node = device_get_match_data(dev);
        if (!node) {
@@ -251,19 +244,25 @@ static int smi_probe(struct platform_device *pdev)
 
        switch (node->bus_type) {
        case SMI_I2C:
-               return smi_i2c_probe(pdev, adev, smi, node->instances);
+               return smi_i2c_probe(pdev, smi, node->instances);
        case SMI_SPI:
-               return smi_spi_probe(pdev, adev, smi, node->instances);
+               return smi_spi_probe(pdev, smi, node->instances);
        case SMI_AUTO_DETECT:
-               if (i2c_acpi_client_count(adev) > 0)
-                       return smi_i2c_probe(pdev, adev, smi, node->instances);
-               else
-                       return smi_spi_probe(pdev, adev, smi, node->instances);
+               /*
+                * For backwards-compatibility with the existing nodes I2C
+                * is checked first and if such entries are found ONLY I2C
+                * devices are created. Since some existing nodes that were
+                * already handled by this driver could also contain unrelated
+                * SpiSerialBus nodes that were previously ignored, and this
+                * preserves that behavior.
+                */
+               ret = smi_i2c_probe(pdev, smi, node->instances);
+               if (ret != -ENOENT)
+                       return ret;
+               return smi_spi_probe(pdev, smi, node->instances);
        default:
                return -EINVAL;
        }
-
-       return 0; /* never reached */
 }
 
 static int smi_remove(struct platform_device *pdev)
@@ -325,8 +324,8 @@ static const struct smi_node cs35l41_hda = {
 static const struct acpi_device_id smi_acpi_ids[] = {
        { "BSG1160", (unsigned long)&bsg1160_data },
        { "BSG2150", (unsigned long)&bsg2150_data },
-       { "INT3515", (unsigned long)&int3515_data },
        { "CSC3551", (unsigned long)&cs35l41_hda },
+       { "INT3515", (unsigned long)&int3515_data },
        /* Non-conforming _HID for Cirrus Logic already released */
        { "CLSA0100", (unsigned long)&cs35l41_hda },
        { "CLSA0101", (unsigned long)&cs35l41_hda },