mfd: Fix warning in WM8350
[linux-2.6.git] / drivers / mfd / wm8350-core.c
index 9a1a0b2..25a7a5d 100644 (file)
@@ -1130,12 +1130,37 @@ out:
 }
 EXPORT_SYMBOL_GPL(wm8350_create_cache);
 
+/*
+ * Register a client device.  This is non-fatal since there is no need to
+ * fail the entire device init due to a single platform device failing.
+ */
+static void wm8350_client_dev_register(struct wm8350 *wm8350,
+                                      const char *name,
+                                      struct platform_device **pdev)
+{
+       int ret;
+
+       *pdev = platform_device_alloc(name, -1);
+       if (pdev == NULL) {
+               dev_err(wm8350->dev, "Failed to allocate %s\n", name);
+               return;
+       }
+
+       (*pdev)->dev.parent = wm8350->dev;
+       platform_set_drvdata(*pdev, wm8350);
+       ret = platform_device_add(*pdev);
+       if (ret != 0) {
+               dev_err(wm8350->dev, "Failed to register %s: %d\n", name, ret);
+               platform_device_put(*pdev);
+               *pdev = NULL;
+       }
+}
+
 int wm8350_device_init(struct wm8350 *wm8350, int irq,
                       struct wm8350_platform_data *pdata)
 {
        int ret = -EINVAL;
        u16 id1, id2, mask, mode;
-       int i;
 
        /* get WM8350 revision and config mode */
        wm8350->read_dev(wm8350, WM8350_RESET_ID, sizeof(id1), &id1);
@@ -1208,6 +1233,15 @@ int wm8350_device_init(struct wm8350 *wm8350, int irq,
 
        wm8350_reg_write(wm8350, WM8350_SYSTEM_INTERRUPTS_MASK, 0x0);
 
+       wm8350_client_dev_register(wm8350, "wm8350-codec",
+                                  &(wm8350->codec.pdev));
+       wm8350_client_dev_register(wm8350, "wm8350-gpio",
+                                  &(wm8350->gpio.pdev));
+       wm8350_client_dev_register(wm8350, "wm8350-power",
+                                  &(wm8350->power.pdev));
+       wm8350_client_dev_register(wm8350, "wm8350-rtc", &(wm8350->rtc.pdev));
+       wm8350_client_dev_register(wm8350, "wm8350-wdt", &(wm8350->wdt.pdev));
+
        return 0;
 
 err:
@@ -1221,8 +1255,13 @@ void wm8350_device_exit(struct wm8350 *wm8350)
        int i;
 
        for (i = 0; i < ARRAY_SIZE(wm8350->pmic.pdev); i++)
-               if (wm8350->pmic.pdev[i] != NULL)
-                       platform_device_unregister(wm8350->pmic.pdev[i]);
+               platform_device_unregister(wm8350->pmic.pdev[i]);
+
+       platform_device_unregister(wm8350->wdt.pdev);
+       platform_device_unregister(wm8350->rtc.pdev);
+       platform_device_unregister(wm8350->power.pdev);
+       platform_device_unregister(wm8350->gpio.pdev);
+       platform_device_unregister(wm8350->codec.pdev);
 
        free_irq(wm8350->chip_irq, wm8350);
        flush_work(&wm8350->irq_work);