The U-Boot Driver Model Project
===============================
Watchdog device subsystem analysis
==================================

Tomas Hlavacek <tmshlvck@gmail.com>
2012-03-09

I) Overview
-----------

U-Boot currently implements an API for HW watchdog devices as explicit drivers
in drivers/watchdog directory. There are also drivers for both hardware and
software watchdog on particular CPUs implemented in arch/*/cpu/*/cpu.c. There
are macros in include/watchdog.h that selects between SW and HW watchdog and
assembly SW implementation.

The current common interface comprises of one set out of these two possible
variants:

    1)
    void watchdog_reset(void);
    int watchdog_disable(void);
    int watchdog_init(void);

    2)
    void hw_watchdog_reset(void);
    void hw_watchdog_init(void);

The watchdog implementations are also spread through board/*/*.c that in
some cases. The API and semantics is in most cases same as the above
mentioned common functions.


II) Approach
------------

  1) New API
  ----------

  In the UDM each watchdog driver would register itself by a function

    int watchdog_device_register(struct instance *i,
				 const struct watchdog_device_ops *o);

  The structure being defined as follows:

    struct watchdog_device_ops {
	int (*disable)(struct instance *i);
	void (*reset)(struct instance *i);
    };

  The watchdog_init() function will be dissolved into probe() function.

  2) Conversion thougths
  ----------------------

  Conversion of watchdog implementations to a new API could be divided
  to three subsections: a) HW implementations, which are mostly compliant
  to the above mentioned API; b) SW implementations, which are compliant
  to the above mentioned API and c) SW implementations that are not compliant
  to the API and has to be rectified or partially rewritten.

III) Analysis of in-tree drivers
--------------------------------

  drivers/watchdog/at91sam9_wdt.c
  -------------------------------
  The driver is standard HW watchdog. Simple conversion is possible.


  drivers/watchdog/ftwdt010_wdt.c
  -------------------------------
  The driver is ad-hoc HW watchdog. Conversion has to take into account
  driver parts spread in include/faraday/*. Restructuring the driver and
  code cleanup has to be considered.


  arch/arm/cpu/arm1136/mx31/timer.c
  ---------------------------------
  The driver is semi-standard ad-hoc HW watchdog. Conversion has to take
  into account driver parts spread in the timer.c file.


  arch/arm/cpu/arm926ejs/davinci/timer.c
  --------------------------------------
  The driver is ad-hoc semi-standard HW watchdog. Conversion has to take
  into account driver parts spread in the timer.c file.


  arch/arm/cpu/armv7/omap-common/hwinit-common.c
  ----------------------------------------------
  The driver is non-standard ad-hoc HW watchdog. Conversion is possible
  but functions has to be renamed and constants moved to another places.


  arch/arm/cpu/armv7/omap3/board.c
  --------------------------------
  The driver is non-standard ad-hoc HW watchdog. Conversion is possible
  but functions has to be renamed and constants moved to another places.


  arch/blackfin/cpu/watchdog.c
  ----------------------------
  The driver is standard HW watchdog. Simple conversion is possible.


  arch/m68k/cpu/mcf523x/cpu.c
  ---------------------------
  The driver is standard HW watchdog. Simple conversion is possible.


  arch/m68k/cpu/mcf52x2/cpu.c
  ---------------------------
  The driver is standard HW watchdog. Simple conversion is possible.


  arch/m68k/cpu/mcf532x/cpu.c
  ---------------------------
  The driver is standard HW watchdog. Simple conversion is possible.


  arch/m68k/cpu/mcf547x_8x/cpu.c
  ------------------------------
  The driver is standard HW watchdog (there is slight naming convention
  violation that has to be rectified). Simple conversion is possible.


  arch/powerpc/cpu/74xx_7xx/cpu.c
  -------------------------------
  The driver is standard HW watchdog. Simple conversion is possible.


  arch/powerpc/cpu/mpc512x/cpu.c
  ------------------------------
  The driver is standard HW watchdog. Simple conversion is possible.


  arch/powerpc/cpu/mpc5xx/cpu.c
  -----------------------------
  The driver is standard HW watchdog. Simple conversion is possible.


  arch/powerpc/cpu/mpc5xxx/cpu.c
  ------------------------------
  The driver is standard HW watchdog. Simple conversion is possible.


  arch/powerpc/cpu/mpc8260/cpu.c
  ------------------------------
  The driver is standard HW watchdog. Simple conversion is possible.


  arch/powerpc/cpu/mpc83xx/cpu.c
  ------------------------------
  The driver is standard HW watchdog. Simple conversion is possible.


  arch/powerpc/cpu/mpc85xx/cpu.c
  ------------------------------
  The driver is standard HW watchdog. Simple conversion is possible.


  arch/powerpc/cpu/mpc86xx/cpu.c
  ------------------------------
  The driver is standard HW watchdog. Simple conversion is possible.


  arch/powerpc/cpu/mpc8xx/cpu.c
  -----------------------------
  The driver is standard HW watchdog. Simple conversion is possible.


  arch/powerpc/cpu/ppc4xx/cpu.c
  -----------------------------
  The driver is standard HW watchdog. Simple conversion is possible.


  arch/sh/cpu/sh2/watchdog.c
  --------------------------
  The driver is standard HW watchdog. Simple conversion is possible.


  arch/sh/cpu/sh3/watchdog.c
  --------------------------
  The driver is standard HW watchdog. Simple conversion is possible.


  arch/sh/cpu/sh4/watchdog.c
  --------------------------
  The driver is standard HW watchdog. Simple conversion is possible.


  board/amcc/luan/luan.c
  ----------------------
  The driver is standard HW watchdog. Simple conversion is possible.


  board/amcc/yosemite/yosemite.c
  ------------------------------
  The driver is standard HW watchdog. Simple conversion is possible.


  board/apollon/apollon.c
  -----------------------
  The driver is standard HW watchdog however the watchdog_init()
  function is called in early initialization. Simple conversion is possible.


  board/bmw/m48t59y.c
  -------------------
  Special watchdog driver. Dead code. To be removed.


  board/davedenx/qong/qong.c
  --------------------------
  The driver is standard HW watchdog. Simple conversion is possible.


  board/dvlhost/watchdog.c
  ------------------------
  The driver is standard HW watchdog. Simple conversion is possible.


  board/eNET/eNET.c
  -----------------
  The driver is standard HW watchdog. Simple conversion is possible.


  board/eltec/elppc/elppc.c
  -------------------------
  The driver is standard HW watchdog. Simple conversion is possible.


  board/enbw/enbw_cmc/enbw_cmc.c
  ------------------------------
  Only function proxy call. Code cleanup needed.


  board/freescale/mx31pdk/mx31pdk.c
  ---------------------------------
  Only function proxy call. Code cleanup needed.


  board/gth2/gth2.c
  -----------------
  The driver is standard HW watchdog. Simple conversion is possible.


  board/lwmon5/lwmon5.c
  ---------------------
  The driver is standard HW watchdog. Simple conversion is possible.


  board/manroland/mucmc52/mucmc52.c
  ---------------------------------
  The driver is standard HW watchdog. Simple conversion is possible.


  board/manroland/uc101/uc101.c
  -----------------------------
  The driver is standard HW watchdog. Simple conversion is possible.


  board/mousse/m48t59y.c
  ----------------------
  Special watchdog driver. Dead code. To be removed.


  board/mvblue/mvblue.c
  ---------------------
  The driver is standard HW watchdog. Simple conversion is possible.


  board/netphone/netphone.c
  -------------------------
  The driver is standard HW watchdog. Simple conversion is possible.


  board/netta/netta.c
  -------------------
  The driver is standard HW watchdog. Simple conversion is possible.


  board/netta2/netta2.c
  ---------------------
  The driver is standard HW watchdog. Simple conversion is possible.


  board/omicron/calimain/calimain.c
  ---------------------------------
  Only function proxy call. Code cleanup needed.


  board/pcs440ep/pcs440ep.c
  -------------------------
  The driver is standard HW watchdog. Simple conversion is possible.


  board/stx/stxxtc/stxxtc.c
  -------------------------
  The driver is standard HW watchdog. Simple conversion is possible.


  board/ti/omap2420h4/omap2420h4.c
  --------------------------------
  The driver is standard HW watchdog. Simple conversion is possible.


  board/ttcontrol/vision2/vision2.c
  ---------------------------------
  The driver is standard HW watchdog but namespace is polluted by
  non-standard macros. Simple conversion is possible, code cleanup
  needed.


  board/v38b/v38b.c
  -----------------
  The driver is standard HW watchdog. Simple conversion is possible.


  board/ve8313/ve8313.c
  ---------------------
  The driver is standard HW watchdog. Simple conversion is possible.


  board/w7o/watchdog.c
  --------------------
  The driver is standard HW watchdog. Simple conversion is possible.
