linux/drivers/watchdog/booke_wdt.c
<<
>>
Prefs
   1/*
   2 * Watchdog timer for PowerPC Book-E systems
   3 *
   4 * Author: Matthew McClintock
   5 * Maintainer: Kumar Gala <galak@kernel.crashing.org>
   6 *
   7 * Copyright 2005, 2008, 2010-2011 Freescale Semiconductor Inc.
   8 *
   9 * This program is free software; you can redistribute  it and/or modify it
  10 * under  the terms of  the GNU General  Public License as published by the
  11 * Free Software Foundation;  either version 2 of the  License, or (at your
  12 * option) any later version.
  13 */
  14
  15#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  16
  17#include <linux/module.h>
  18#include <linux/fs.h>
  19#include <linux/smp.h>
  20#include <linux/miscdevice.h>
  21#include <linux/notifier.h>
  22#include <linux/watchdog.h>
  23#include <linux/uaccess.h>
  24
  25#include <asm/reg_booke.h>
  26#include <asm/time.h>
  27#include <asm/div64.h>
  28
  29/* If the kernel parameter wdt=1, the watchdog will be enabled at boot.
  30 * Also, the wdt_period sets the watchdog timer period timeout.
  31 * For E500 cpus the wdt_period sets which bit changing from 0->1 will
  32 * trigger a watchog timeout. This watchdog timeout will occur 3 times, the
  33 * first time nothing will happen, the second time a watchdog exception will
  34 * occur, and the final time the board will reset.
  35 */
  36
  37u32 booke_wdt_enabled;
  38u32 booke_wdt_period = CONFIG_BOOKE_WDT_DEFAULT_TIMEOUT;
  39
  40#ifdef  CONFIG_PPC_FSL_BOOK3E
  41#define WDTP(x)         ((((x)&0x3)<<30)|(((x)&0x3c)<<15))
  42#define WDTP_MASK       (WDTP(0x3f))
  43#else
  44#define WDTP(x)         (TCR_WP(x))
  45#define WDTP_MASK       (TCR_WP_MASK)
  46#endif
  47
  48static DEFINE_SPINLOCK(booke_wdt_lock);
  49
  50/* For the specified period, determine the number of seconds
  51 * corresponding to the reset time.  There will be a watchdog
  52 * exception at approximately 3/5 of this time.
  53 *
  54 * The formula to calculate this is given by:
  55 * 2.5 * (2^(63-period+1)) / timebase_freq
  56 *
  57 * In order to simplify things, we assume that period is
  58 * at least 1.  This will still result in a very long timeout.
  59 */
  60static unsigned long long period_to_sec(unsigned int period)
  61{
  62        unsigned long long tmp = 1ULL << (64 - period);
  63        unsigned long tmp2 = ppc_tb_freq;
  64
  65        /* tmp may be a very large number and we don't want to overflow,
  66         * so divide the timebase freq instead of multiplying tmp
  67         */
  68        tmp2 = tmp2 / 5 * 2;
  69
  70        do_div(tmp, tmp2);
  71        return tmp;
  72}
  73
  74/*
  75 * This procedure will find the highest period which will give a timeout
  76 * greater than the one required. e.g. for a bus speed of 66666666 and
  77 * and a parameter of 2 secs, then this procedure will return a value of 38.
  78 */
  79static unsigned int sec_to_period(unsigned int secs)
  80{
  81        unsigned int period;
  82        for (period = 63; period > 0; period--) {
  83                if (period_to_sec(period) >= secs)
  84                        return period;
  85        }
  86        return 0;
  87}
  88
  89static void __booke_wdt_set(void *data)
  90{
  91        u32 val;
  92
  93        val = mfspr(SPRN_TCR);
  94        val &= ~WDTP_MASK;
  95        val |= WDTP(booke_wdt_period);
  96
  97        mtspr(SPRN_TCR, val);
  98}
  99
 100static void booke_wdt_set(void)
 101{
 102        on_each_cpu(__booke_wdt_set, NULL, 0);
 103}
 104
 105static void __booke_wdt_ping(void *data)
 106{
 107        mtspr(SPRN_TSR, TSR_ENW|TSR_WIS);
 108}
 109
 110static void booke_wdt_ping(void)
 111{
 112        on_each_cpu(__booke_wdt_ping, NULL, 0);
 113}
 114
 115static void __booke_wdt_enable(void *data)
 116{
 117        u32 val;
 118
 119        /* clear status before enabling watchdog */
 120        __booke_wdt_ping(NULL);
 121        val = mfspr(SPRN_TCR);
 122        val &= ~WDTP_MASK;
 123        val |= (TCR_WIE|TCR_WRC(WRC_CHIP)|WDTP(booke_wdt_period));
 124
 125        mtspr(SPRN_TCR, val);
 126}
 127
 128/**
 129 * booke_wdt_disable - disable the watchdog on the given CPU
 130 *
 131 * This function is called on each CPU.  It disables the watchdog on that CPU.
 132 *
 133 * TCR[WRC] cannot be changed once it has been set to non-zero, but we can
 134 * effectively disable the watchdog by setting its period to the maximum value.
 135 */
 136static void __booke_wdt_disable(void *data)
 137{
 138        u32 val;
 139
 140        val = mfspr(SPRN_TCR);
 141        val &= ~(TCR_WIE | WDTP_MASK);
 142        mtspr(SPRN_TCR, val);
 143
 144        /* clear status to make sure nothing is pending */
 145        __booke_wdt_ping(NULL);
 146
 147}
 148
 149static ssize_t booke_wdt_write(struct file *file, const char __user *buf,
 150                                size_t count, loff_t *ppos)
 151{
 152        booke_wdt_ping();
 153        return count;
 154}
 155
 156static struct watchdog_info ident = {
 157        .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
 158        .identity = "PowerPC Book-E Watchdog",
 159};
 160
 161static long booke_wdt_ioctl(struct file *file,
 162                                unsigned int cmd, unsigned long arg)
 163{
 164        u32 tmp = 0;
 165        u32 __user *p = (u32 __user *)arg;
 166
 167        switch (cmd) {
 168        case WDIOC_GETSUPPORT:
 169                return copy_to_user(p, &ident, sizeof(ident)) ? -EFAULT : 0;
 170        case WDIOC_GETSTATUS:
 171                return put_user(0, p);
 172        case WDIOC_GETBOOTSTATUS:
 173                /* XXX: something is clearing TSR */
 174                tmp = mfspr(SPRN_TSR) & TSR_WRS(3);
 175                /* returns CARDRESET if last reset was caused by the WDT */
 176                return put_user((tmp ? WDIOF_CARDRESET : 0), p);
 177        case WDIOC_SETOPTIONS:
 178                if (get_user(tmp, p))
 179                        return -EFAULT;
 180                if (tmp == WDIOS_ENABLECARD) {
 181                        booke_wdt_ping();
 182                        break;
 183                } else
 184                        return -EINVAL;
 185                return 0;
 186        case WDIOC_KEEPALIVE:
 187                booke_wdt_ping();
 188                return 0;
 189        case WDIOC_SETTIMEOUT:
 190                if (get_user(tmp, p))
 191                        return -EFAULT;
 192#ifdef  CONFIG_PPC_FSL_BOOK3E
 193                /* period of 1 gives the largest possible timeout */
 194                if (tmp > period_to_sec(1))
 195                        return -EINVAL;
 196                booke_wdt_period = sec_to_period(tmp);
 197#else
 198                booke_wdt_period = tmp;
 199#endif
 200                booke_wdt_set();
 201                /* Fall */
 202        case WDIOC_GETTIMEOUT:
 203#ifdef  CONFIG_FSL_BOOKE
 204                return put_user(period_to_sec(booke_wdt_period), p);
 205#else
 206                return put_user(booke_wdt_period, p);
 207#endif
 208        default:
 209                return -ENOTTY;
 210        }
 211
 212        return 0;
 213}
 214
 215/* wdt_is_active stores whether or not the /dev/watchdog device is opeode=*/
 21180t.c#Lt_set(void)
CONFIG_FSL_BOOKE
booke_wdt_period--) {
 |  162        in   >        case arg;
c
 220ing();
 21180t.c#Lt_set 2onlent">ref="+cctiveode=Wb0ref">CONFIG_FSL_BOOKE
SPRN_TCR);
TCR_WRC(( 165          50/* For the speci2al" class2"sref">val);
tmp);
/* For the speci2a#L81" id=rivers/watchdog/booke_wd2.c#L12288                return 0;
116"> 116{
 114
 * booke_wdt_2isabl22c#L199" id="L199" class="line" name=pr_debuwatchdog/booke_wpr_debuw"L113"rs/watchdog/booke_wdt.c#L1L107" id=d" clas (t;  160
EINVAL 205#else
 114
 * This functi2n is 23" name="L212"> 212        return 0;
  50/* For the speci2pan class2"comment"> * TCR[WRC] ca2not b23="sref">mfspr(c
/a>/* For the speci2ps="sref"2dog/booke_wdt.c#L135" id2"L13523L156"> 156static struct ident 2ef">data<2a>)
 *ss="sref">__user * *same="L162"> 162        in   >        case arg;
c
232 val;
CONFIf="+codWATCHDOG_NOWAYclaa href="+code=ident" class="sref">ident 2ewdt.c#L12l =          */ = CONFIG_FSL_BOOKE
SPRN_TCR);
CONFIG_FSL_BOOKE
WDTP_MA2K24lass="line" name="L132"> 132llllllll*oL107" id=should/bomain=d" clas.  Soe tims="commit onlenife=Wb0ref">CONFIG_FSL_BOOKE
val);
 1362clear sta2us to make sure nothing 2s pen24="line" name="L134"> 134llllllll*de=Wb0ref">CONFIG_FSL_BOOKE
 165        "L137"> 137{
 114
  214
 114
29" id="L149" class="line2 name24" class="line" name="L209"> 209                rass="sref2>ssize_t booke_wdt_write2struct 
 114
25>(struct fi2_ping" cl2ss="sref">booke_wdt_ping2/a>()25chdog/booke_wdt.c#L74"> 214
 12325  74/*
 154}
,
val;
watchdog_i2foWDIOF_KEEPALIVEwn_wdt.c#L207" id="Ewn_w/booke_wdt.c#L200" id=THIS_MODULer" class="sref"THIS_MODULeme="L">val;
WDIOF_KEEPALIVllseekr" class="sref"llseek/booke_wdt.c#L200" id=no_llseekr" class="sref"no_llseekme="L">val;
2 href="+code=WDIOF_KEEPA2IVEPI2G" class="sref">WDIOF_KEEPALIV class="sref">__userref="+codke_wdt.c#L200" id=rivers/wat class="sref">__user *val;
val;
WDIOF_KEEPALIVEef=f
val;
booke_wdt_2octl<260id="L146" cl">WDIOF_KEEPALIVre"> *ss="sref">__userre"> *same=ke_wdt.c#L200" id=rivers/watre"> *ss="sref">__user * *same=L">val;
 161static long arg)
mfspr(232 __usermisc"L108 hdog/ass="line" namerivers/watmisc"L1s="sref">__user *val;
 1">WDIOF_KEEPALIVmino_wdt.c#L175" id="ino_ame=ke_wdt.c#L200" id=WATCHDOG_MINO 175        WATCHDOG_MINO ame=L">val;
WDIOF_KEEPALIVode=r" class="sref"nde=ame=ke_wrs/watchdog/booke_wdt.c#L1L107" idne" name="L160"> 160
cmd) {
WDIOF_KEEPALIVfop/a>,
,
 160
2="L168"> 168        2ase <2 href="> 161static long  26e_wdt_write" class="sref">booke_wdt_write2amp;i26c#L90" id="L90" class="line" name=exil */

 112         1727ref">val;
__user * 114
/*
27ng */
SPRN_TSR)2&27L156"dt.c#L1e2e2e2e2e2e2e2e2e/a__inil */

 112        WDIOF_CARDRESe2e2e2e2e2e2e2e2e/arll */
 214
 27+co>
p))
 139
 */ 114
 1279id="L146" class="line" name70        case WDIOF_KEEPALIVfirmware_hrefio=f

2 {
fi2_wdt.c#L122" id="L182" class="line2 name28
__user * 114

();
EINVALa>
 160
 125                return 0wdt.c#L200" id=WATCHDOG_MINO 175        WATCHDOG_MINO ame=Livers/watchdog/brll */
 114
WDIOC_KEEPALIVE:vers/watchdog/brll */
 114
 182          /a>/*
28+co>
 139
  50/* For the speci290" id="L290" class="line" name="L290"> 290         class="line" name=e" name="L> p))
        . 160
 122#ifdef  EINVAL 205#else
 114
        116"> 116{
 114
/*
(1))2 165          50/* For the speci26" id="L126" class="line" name="L126"> 129ident 2"sref">se2_to_period( 114
2ooke_29L149"> 149static ;
booke_wdt_write2ode=booke2wdt_set" class="sref">bo2ke_wd2_set
 205
/* For the speci31" id="L231" class="line" name="L231"> 231 vers/watchdog/bmoduletexil */
 205
/* For the speci311 id="L231" class="line" name="L13 213}
 303"line" name="L2MODULe_DESCRI>(
( */ 114
 304 114



The original LXR software">put_us 114 http://sourc"srege.net/projects/lxwd>LXR "> 1unhref="dpan>is exog/b134lxw@iveux.nof="+"
lxw.iveux.no kindly host_d">pu 114 http://www.redpill-ivepro.no">Redpill Lvepro ASf="dpaprovidtchdf Lveux1nameulhref=and refraING