ARM: OMAP2+: WDT: move init; add read_reset_sources pdata function pointer
authorPaul Walmsley <paul@pwsan.com>
Tue, 30 Oct 2012 02:49:44 +0000 (20:49 -0600)
committerPaul Walmsley <paul@pwsan.com>
Tue, 30 Oct 2012 02:49:44 +0000 (20:49 -0600)
The OMAP watchdog timer driver directly calls a function exported by
code in arch/arm/mach-omap2.  This is not good; it tightly couples
this driver to the mach-omap2 integration code.  Instead, add a
temporary platform_data function pointer to abstract this function
call.  A subsequent patch will convert the watchdog driver to use this
function pointer.

This patch also moves the device creation code out of
arch/arm/mach-omap2/devices.c and into arch/arm/mach-omap2/wd_timer.c.
This is another step towards the removal of
arch/arm/mach-omap2/devices.c.

Cc: Wim Van Sebroeck <wim@iguana.be>
Acked-by: Wim Van Sebroeck <wim@iguana.be>
[paul@pwsan.com: skip wd_timer device creation when DT blob is present]
Signed-off-by: Paul Walmsley <paul@pwsan.com>
arch/arm/mach-omap1/devices.c
arch/arm/mach-omap2/devices.c
arch/arm/mach-omap2/wd_timer.c
include/linux/platform_data/omap-wd-timer.h [new file with mode: 0644]

index 645668e2b1d5db50c13a7319aff2e17f4c7d59ff..745031870ce4bb1e6641aec7394bcb294ba9ad33 100644 (file)
@@ -17,6 +17,8 @@
 #include <linux/platform_device.h>
 #include <linux/spi/spi.h>
 
+#include <linux/platform_data/omap-wd-timer.h>
+
 #include <asm/mach/map.h>
 
 #include <mach/tc.h>
@@ -448,18 +450,31 @@ static struct resource wdt_resources[] = {
 };
 
 static struct platform_device omap_wdt_device = {
-       .name      = "omap_wdt",
-       .id          = -1,
+       .name           = "omap_wdt",
+       .id             = -1,
        .num_resources  = ARRAY_SIZE(wdt_resources),
        .resource       = wdt_resources,
 };
 
 static int __init omap_init_wdt(void)
 {
+       struct omap_wd_timer_platform_data pdata;
+       int ret;
+
        if (!cpu_is_omap16xx())
                return -ENODEV;
 
-       return platform_device_register(&omap_wdt_device);
+       pdata.read_reset_sources = omap1_get_reset_sources;
+
+       ret = platform_device_register(&omap_wdt_device);
+       if (!ret) {
+               ret = platform_device_add_data(&omap_wdt_device, &pdata,
+                                              sizeof(pdata));
+               if (ret)
+                       platform_device_del(&omap_wdt_device);
+       }
+
+       return ret;
 }
 subsys_initcall(omap_init_wdt);
 #endif
index 2ad491d6910ba53775f0cd398b1a617facbcd129..cf365c387c06e70677e54e30cbcb2425d451330f 100644 (file)
@@ -646,29 +646,3 @@ static int __init omap2_init_devices(void)
        return 0;
 }
 arch_initcall(omap2_init_devices);
-
-#if defined(CONFIG_OMAP_WATCHDOG) || defined(CONFIG_OMAP_WATCHDOG_MODULE)
-static int __init omap_init_wdt(void)
-{
-       int id = -1;
-       struct platform_device *pdev;
-       struct omap_hwmod *oh;
-       char *oh_name = "wd_timer2";
-       char *dev_name = "omap_wdt";
-
-       if (!cpu_class_is_omap2() || of_have_populated_dt())
-               return 0;
-
-       oh = omap_hwmod_lookup(oh_name);
-       if (!oh) {
-               pr_err("Could not look up wd_timer%d hwmod\n", id);
-               return -EINVAL;
-       }
-
-       pdev = omap_device_build(dev_name, id, oh, NULL, 0, NULL, 0, 0);
-       WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
-                               dev_name, oh->name);
-       return 0;
-}
-subsys_initcall(omap_init_wdt);
-#endif
index f6b6c37ac3f45fe5de8b3131315f6189397f4a43..5a8629ff0ab0e8c0cbe5013ac6c381b8f2b8ba7c 100644 (file)
 #include <linux/io.h>
 #include <linux/err.h>
 
-#include "omap_hwmod.h"
+#include <linux/platform_data/omap-wd-timer.h>
 
+#include "omap_hwmod.h"
+#include "omap_device.h"
 #include "wd_timer.h"
 #include "common.h"
+#include "prm.h"
+#include "soc.h"
 
 /*
  * In order to avoid any assumptions from bootloader regarding WDT
@@ -99,3 +103,32 @@ int omap2_wd_timer_reset(struct omap_hwmod *oh)
        return (c == MAX_MODULE_SOFTRESET_WAIT) ? -ETIMEDOUT :
                omap2_wd_timer_disable(oh);
 }
+
+static int __init omap_init_wdt(void)
+{
+       int id = -1;
+       struct platform_device *pdev;
+       struct omap_hwmod *oh;
+       char *oh_name = "wd_timer2";
+       char *dev_name = "omap_wdt";
+       struct omap_wd_timer_platform_data pdata;
+
+       if (!cpu_class_is_omap2() || of_have_populated_dt())
+               return 0;
+
+       oh = omap_hwmod_lookup(oh_name);
+       if (!oh) {
+               pr_err("Could not look up wd_timer%d hwmod\n", id);
+               return -EINVAL;
+       }
+
+       pdata.read_reset_sources = prm_read_reset_sources;
+
+       pdev = omap_device_build(dev_name, id, oh, &pdata,
+                                sizeof(struct omap_wd_timer_platform_data),
+                                NULL, 0, 0);
+       WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
+            dev_name, oh->name);
+       return 0;
+}
+subsys_initcall(omap_init_wdt);
diff --git a/include/linux/platform_data/omap-wd-timer.h b/include/linux/platform_data/omap-wd-timer.h
new file mode 100644 (file)
index 0000000..d75f5f8
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * OMAP2+ WDTIMER-specific function prototypes
+ *
+ * Copyright (C) 2012 Texas Instruments, Inc.
+ * Paul Walmsley
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#ifndef __LINUX_PLATFORM_DATA_OMAP_WD_TIMER_H
+#define __LINUX_PLATFORM_DATA_OMAP_WD_TIMER_H
+
+#include <linux/types.h>
+
+/*
+ * Standardized OMAP reset source bits
+ *
+ * This is a subset of the ones listed in arch/arm/mach-omap2/prm.h
+ * and are the only ones needed in the watchdog driver.
+ */
+#define OMAP_MPU_WD_RST_SRC_ID_SHIFT                           3
+
+/**
+ * struct omap_wd_timer_platform_data - WDTIMER integration to the host SoC
+ * @read_reset_sources - fn ptr for the SoC to indicate the last reset cause
+ *
+ * The function pointed to by @read_reset_sources must return its data
+ * in a standard format - search for RST_SRC_ID_SHIFT in
+ * arch/arm/mach-omap2
+ */
+struct omap_wd_timer_platform_data {
+       u32 (*read_reset_sources)(void);
+};
+
+#endif