linux/drivers/watchdog/iop_wdt.c
<<
>>
Prefs
   1/*
   2 * drivers/char/watchdog/iop_wdt.c
   3 *
   4 * WDT driver for Intel I/O Processors
   5 * Copyright (C) 2005, Intel Corporation.
   6 *
   7 * Based on ixp4xx driver, Copyright 2004 (c) MontaVista, Software, Inc.
   8 *
   9 * This program is free software; you can redistribute it and/or modify it
  10 * under the terms and conditions of the GNU General Public License,
  11 * version 2, as published by the Free Software Foundation.
  12 *
  13 * This program is distributed in the hope it will be useful, but WITHOUT
  14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  16 * more details.
  17 *
  18 * You should have received a copy of the GNU General Public License along with
  19 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  20 * Place - Suite 330, Boston, MA 02111-1307 USA.
  21 *
  22 *      Curt E Bruns <curt.e.bruns@intel.com>
  23 *      Peter Milne <peter.milne@d-tacq.com>
  24 *      Dan Williams <dan.j.williams@intel.com>
  25 */
  26
  27#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  28
  29#include <linux/module.h>
  30#include <linux/kernel.h>
  31#include <linux/fs.h>
  32#include <linux/init.h>
  33#include <linux/device.h>
  34#include <linux/miscdevice.h>
  35#include <linux/watchdog.h>
  36#include <linux/uaccess.h>
  37#include <mach/hardware.h>
  38
  39static bool nowayout = WATCHDOG_NOWAYOUT;
  40static unsigned long wdt_status;
  41static unsigned long boot_status;
  42static DEFINE_SPINLOCK(wdt_lock);
  43
  44#define WDT_IN_USE              0
  45#define WDT_OK_TO_CLOSE         1
  46#define WDT_ENABLED             2
  47
  48static unsigned long iop_watchdog_timeout(void)
  49{
  50        return (0xffffffffUL / get_iop_tick_rate());
  51}
  52
  53/**
  54 * wdt_supports_disable - determine if we are accessing a iop13xx watchdog
  55 * or iop3xx by whether it has a disable command
  56 */
  57static int wdt_supports_disable(void)
  58{
  59        int can_disable;
  60
  61        if (IOP_WDTCR_EN_ARM != IOP_WDTCR_DIS_ARM)
  62                can_disable = 1;
  63        else
  64                can_disable = 0;
  65
  66        return can_disable;
  67}
  68
  69static void wdt_enable(void)
  70{
  71        /* Arm and enable the Timer to starting counting down from 0xFFFF.FFFF
  72         * Takes approx. 10.7s to timeout
  73         */
  74        spin_lock(&wdt_lock);
  75        write_wdtcr(IOP_WDTCR_EN_ARM);
  76        write_wdtcr(IOP_WDTCR_EN);
  77        spin_unlock(&wdt_lock);
  78}
  79
  80/* returns 0 if the timer was successfully disabled */
  81static int wdt_disable(void)
  82{
  83        /* Stop Counting */
  84        if (wdt_supports_disable()) {
  85                spin_lock(&wdt_lock);
  86                write_wdtcr(IOP_WDTCR_DIS_ARM);
  87                write_wdtcr(IOP_WDTCR_DIS);
  88                clear_bit(WDT_ENABLED, &wdt_status);
  89                spin_unlock(&wdt_lock);
  90                pr_info("Disabled\n");
  91                return 0;
  92        } else
  93                return 1;
  94}
  95
  96static int iop_wdt_open(struct inode *inode, struct file *file)
  97{
  98        if (test_and_set_bit(WDT_IN_USE, &wdt_status))
  99                return -EBUSY;
 100
 101        clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
 102        wdt_enable();
 103           8 10204f">wdCounting */
iop_wdt_open(stra href="+code=inode" class="sref">inodeatchdog/iop_w8" class="line" name="L8">  58wd5        return 1;
wdomment"> */
  16<0/a>wdomment"> */<);
  96de" class="sref">inode *inodedataa>(stra href="+code=isize_atchdog/iop_wdt.cize_aountia>
 */
  17wdOP_WDTCR_DIS);
();
, struct wd_timeout(void)
wdt_lock<{
);
!a href="driversnoss="line" name="L39">  39stat  84        if ()
();
  99            ="line" naame="L12">  12wdt_lock);
 100
 101        clear_bit(WDT_OK_TO_CLOSE, &out even tthe implied warranty of MMERCH11me="L94">  94}
wdt_lock);

  61 ldog/iop_wdt.c#L96ldo id= ia>
        if (  16< * 11DTCR_DIS_ARM);

  99            ="line" naame="L17">  17  67}
wdt_status))
);
a>
dataa>(s +ia>
WDT_IN_USE, &am1te to the1 Free Software Foundatio1n, In12ef">wdt_lock);
bool   99            t"> * Pla1ce - Suite 330, Boston, 1MA 0212d\n");
);
a>
  99            tn 2, as puublished by the Free Softtwar12WDTCR_DIS_ARM)
((((((((((((((((();
 101        clear_bit(WDT_OK_TO_CLOSE, & *      C1urt E Bruns <curt.e.b1runs@12        } else
ut even t Williams <dan.j.will1iams@12s_disable()) {
 102        "line" na1me="L25">  25wdt_lock<    return 1;
  16<.c#L26" id="L26" class="1line"12DTCR_DIS_ARM<5
"line" na; wdt_lock);
  78}
li13HDOG_NOWAYOUdt.st "line" name="L96">  96" name="Lchdog/iop_wdt.c#L90" name="Lchdoountia>
        if (li13d\n"
bool  101         10clasi|eL103" class="lineIOF_KEEPALIVEPING1         */

  90ers>  54           */
  12li1ux/dev   return 1;
l1inux/1iscdevNOWAYOU href="drivers/watchdog/ide="Lctivers/watchdog/idog/ide="Lctilass="line" name="L96">  96de" class="sref">inode *inodelinu13ef">wdt_lock);

{
, struct lin13s="sref">file)
mac13me="L97">  97{
  58{
WA140e="L58">  58{
wd   return 1;
a>
(bool  :4        if (li1463        else
a>
cleaidiver/iop_wdt.c#L96"diveclas, cizeof"L103" class="liadiver/iop_wdt.c#L96"diveclas)IN_USE" class="sref">WDT_IN_USE, &am1ode=WDT_I1N_USE" class="sref">WDT_1IN_US14s_disable()) {
bool   99            DT_OK_TO_1CLOSE" class="sref">WDT_1OK_TO14ef">wdt_lock);
WDT_1ENABL14DTCR_DIS_ARM);
);
iop_w1atchd14me="L78">  78}
  49cas      1
1get_i15d\n");
 102        /iop_wdt.1c#L51" id="L51" class="l1ine" 15WDTCR_DIS_ARM)
wdt_lock);
  53  49cas      1
()) {
 102        /T_OK_TO_1iop3xx by whether it has1 a di15ef">wdt_lock);
  56             2
wdt_s1uppor158e="L49">  49cas      1
wdt_status))
a>
WDT_IN_USE, &am1 wdt_lock);
bool   99            g/iop_wdt1.c#L60" id="L60" class="1line"16f">wd   return 1;
IO1_WDTCR_DIS_ARM)
a>
16        } else
!a href="driversnoss="line" name="L39">  39stat  84        if (1 63        else
)
a>
        if (16s_disable()) {
 101        clear_bit(WDT_OK_TO_CLOSE, &6R PURPOSE..  See the GNU General Pua di16ef">wdt_lock);
);
(aaaaaaaaaaaaaaaaaaaaaa);
  99            g/iop_wdt1.c#L68" id="L68" class="1line"16">wdt_status))
17ef">wdt_lock);
);
);
         * Takes approx1. 10.17        } else
 102        ame="L73"1>  73 100
IO17ef">wdt_lock);
             2
  49cas      1
wdt_status);
 102        g/iop_wdt1.c#L79" id="L79" class="1line"18ef">wdt_lock);
);
w18me="L51">  51}
        }cas      1
bool  :4        if (/1* Sto1863        else
  48)tra href="+code=iargphdog/iop_wdt.c#argpclasclass="line" name="L102"> 102        pports_di1sable" class="sref">wdt_1suppo1ts_disable()) {
wdt_lock<    return 1;
IOP18DTCR_DIS_ARM<5
  17wdt_lock);
  78}
  96static int iop_wdt_open(struct inode *inode, struct "1Disab1ed\n&q84        if (  911     1          retu95
NOWAeclasinedrivers/watchdog/iop_wdt.c#L93" id="L93"12" id="L912" class="line" name="L912">  12        }{
 101        clear_bit(  931     1963        else
a>
 103        , struct ()) {
NOWAeclasinea>
 */
file1 *{
 * You should have received a "line" nac#L97" id="L97" class="l1ine" 19comment"> *
 * You should have received a  copy of tthe GNU General Public Li="sr19 along with
wdt_lock<{
NOWAeclasi!="0  84        if ();
 102       2;)
  9020        } else
  48)class="line" name="L102"> 102       2; *      Pa+code=EBname="L102"> 10204f">2dCounting */);
20me="L94">  94}
20WDTCR_EN_ARM);
test_and_set_bit( 102       2;/iop_wdt.0/a>20IOP_WDTCR_EN);
 101        clear_bit(WDT_OK_TO_CLOSE, &am20"line" n20me="L17">  1720ass="sref">fmt
20">wdt_status< href="drivers/watchdog/iop_wdt.c#L91" id="L91"2 software2; you can redistribute i2t and21ef">wdt_lock);
wd   return 1;
boot_statudt.st "line" name="L96">  96inodtchdra   12        }.a>

       .a>
                if (
        if (wdt_lock<.a>
 * 21DTCR_DIS_ARM<.a>
        if (  17
        if (wdt}    return 1;
EBUSY;
 * Placce - Suite 330, Boston, MMA 0222disabled */<"line" name="L96">  96="line" navers/watchdog/i="line" na>wdt_a>
        if (  21

                }.a>
  90  54           */
cleaiers/watfop( */
  25 */
  162.c#L26" id="L26" class="2line"22omment"> */
wdt_a>
  81static int  (void)
  58{
li23ref">EBUSY;
li23me="L70">  70{
);
)it" cl     1
bool   12wdt_lock);
li234e="L70">  70{
  42" icauri >{
Internal Bus (IB) Resetivers/watchdog/iop_wdt.c#L25" id="L25" class=" 58l2inux/23xx watchdog
linu23ble command
  162x/uaccess.h" class="fref2">lin23IOP_WDTCR_EN);
bool WDT_OK_TO_CLOSE, &am2lude/mach2/hardware.h" class="fref2">mac2/hardware.h>
  58{
wers/watchdog/iop_wdt.c#L25" id="L25" class="ode=WATCH2DOG_NOWAYOUT" class="sre2f">WA24ame="L79">  79
 6" c"*rivers/watchdog/iop_wdt.c#L25" id="L25" class="oclude/li2f="+code=wdt_status" cla2ss="s24"L100"> 100
cleaiers/wat="line"vers/watchdog/idog/ide=="line"clasE" class="sref">WDT_OK_TO_CLOSE, &am2ohref="in2"+code=boot_status" clas2s="sr242\n"{
WDT_OK_TO_CLOSE, &am2o"line" n2href="+code=wdt_lock" cl2ass="24        } else
  9048">  4i%lu sed              48)class="line" name="L102"> 102       2Kributed 2nn the hope it will be u2e">li24x/dev   return 1;
WDT_2IN_US24s_disable5
WDT_2OK_TO24ef">wdt_lock);
WDT_2ENABL2D             2
  v8
wdt_a>
  81static int iop_w2atchd24_timeout(void)
  49a href="+code=i="li=deregistervers/watchdog/i="li=deregister"L101t" class="sref">cleaiers/wat="line"vers/watchdog/idog/ide=="line"clasE" class="sref">WDT_OK_TO_CLOSE, &am2=get_iop_2tick_rate" class="sref">2get_i25d\n&qdt_lock);
  51}
wa href="+code=i=odulet claWDT_OK_TO_CLOSE, &am2=ributed 2me="L53">  53WDT_OK_TO_CLOSE, &am2=de=WDT_I2ine if we are accessing 2a iop25me="L94">  94}
wa href="+code=i=oduletparam  39stat,a href="drivers/" civers/watchdog/i" cistat,a0E" class="sref">WDT_OK_TO_CLOSE, &am2=e=WDT_EN2me="L56">  56  href="drivers/a>(UL0_PARM_DESCvers/watchdog/ia>(UL0_PARM_DESC"L101" class="line" noss="line" name="L39">  39stat,a ass="line" name="L90">  90W"driverocanp_wcbasstopped onna s" cled          pr_inf2ports_dis2able" class="sref">wdt_s2uppor25hardware.h>
wdt href="drivers/a>(UL0_AUTHOR1        (UL0_AUTHOR90" class="line" name="L90">  90Curt E Bruns <curt.e.bruns@intel.
pr_inf2 w href="drivers/a>(UL0_DESCRIPTION1        (UL0_DESCRIPTION90" class="line" name="L90">  90irs>  54op_wdt.pr_inf          pr_inf2 get_iop_2.c#L60" id="L60" class="2line"26f">wd href="drivers/a>(UL0_LICEN101        (UL0_LICEN1090" class="line" name="L90">  90GPL          pr_inf2 iop_wdt.2DTCR_DIS_ARM" class="sre2f">IO2_WDTCR href="drivers/a>(UL0_ALIAS_MISCDEV1        (UL0_ALIAS_MISCDEV"L101" class="line" nef="+codMINOR1        pr_inf2 /iop_wdt2de=can_disable" class="s2ref">26 
The original LXR softwclasbyog/iof="+code=http://sourceforge.net/projects/lxrv>LXR lxr@bleux.noclas.
lxr.bleux.no kindly hostedsbyof="+code=http://www.redpill-blepro.no">Redpill Llepro ASclas,oprovider of Lleuxudt.sulp_wdtog/ichdra