linux/drivers/watchdog/at32ap700x_wdt.c
<<
ion> /spa14. /form4. a ion> href="../linux+v3.7.4/drivers/watchdog/at32ap700x_wdt.c">ion> img src="../.static/gfx/right.png" alt=">>">io /spa14.io spa1 class="lxr_search">ion>ion> input typ4ion> input typ4ion> butt v3typ4Search onclick="return ajax_prefs();">ion> Prefs. /a>io /spa14.n> /div4.n> form acv3.1="ajax+*" method="post" onsubmit="return false;">io input typ4in> /form4.in> div class="headingbott m"> div id /div4. div id. div id 1 /a> spa1 class="comment">/* /spa14. 2 /a> spa1 class="comment"> * Watchdog driver for Atmel AT32AP700X devices /spa14. 3 /a> spa1 class="comment"> * /spa14. 4 /a> spa1 class="comment"> * Copyright (C) 2005-2006 Atmel Corporav3.1 /spa14. 5 /a> spa1 class="comment"> * /spa14. 6 /a> spa1 class="comment"> * This program is free software; you ca1 redistribute it and/or modify /spa14. 7 /a> spa1 class="comment"> * it under the terms of the GNU General Public License vers v32 as /spa14. 8 /a> spa1 class="comment"> * published by the Free Software Foundav3.1. /spa14. 9 /a> spa1 class="comment"> * /spa14. aluea> spa1 class="comment"> * /spa14. 11 /a> spa1 class="comment"> * Errava: WDT Clear is blocked after WDT Reset /spa14. 12 /a> spa1 class="comment"> * /spa14. 13 /a> spa1 class="comment"> * A watchdog timer event will, after reset, block writes to the WDT_CLEAR /spa14. 14 /a> spa1 class="comment"> * register, preventing the program to clear the next Watchdog Timer Reset. /spa14. 15 /a> spa1 class="comment"> * /spa14. 16 /a> spa1 class="comment"> * If you still want to use the WDT after a WDT reset a small code ca1 be /spa14. 17 /a> spa1 class="comment"> * insterted at the startup checking the AVR32_PM.rcause register for WDT reset /spa14. 18 /a> spa1 class="comment"> * and use a GPIO pin to reset the system. This method requires that one of the /spa14. 19 /a> spa1 class="comment"> * GPIO pins are available and connected externally to the RESET_N pin. After /spa14. 2luea> spa1 class="comment"> * the GPIO pin has pulled down the reset line the GPIO will be reset and leave /spa14. 21 /a> spa1 class="comment"> * the pin tristated with pullup. /spa14. 22 /a> spa1 class="comment"> */ /spa14. 23 /a>. 24 /a>#include <linux/init.h /a>>. 25 /a>#include <linux/kernel.h /a>>. 26 /a>#include <linux/module.h /a>>. 27 /a>#include <linux/moduleparam.h /a>>. 28 /a>#include <linux/miscdevice.h /a>>. 29 /a>#include <linux/fs.h /a>>. 30 /a>#include <linux/platform_device.h /a>>. 31 /a>#include <linux/watchdog.h /a>>. 32 /a>#include <linux/uaccess.h /a>>. 33 /a>#include <linux/io.h /a>>. 34 /a>#include <linux/spinlock.h /a>>. 35 /a>#include <linux/slab.h /a>>. 36 /a>. 37 /a>#define a href="+code=TIMEOUT_MIN" class="sref">TIMEOUT_MIN /a> 1. 38 /a>#define a href="+code=TIMEOUT_MAX" class="sref">TIMEOUT_MAX /a> 2. 39 /a>#define a href="+code=TIMEOUT_DEFAULT" class="sref">TIMEOUT_DEFAULT /a> a href="+code=TIMEOUT_MAX" class="sref">TIMEOUT_MAX /a>. 40 /a>. 41 /a> spa1 class="comment">/* module parameters */ /spa14. 42 /a>static int a href="+code=timeout" class="sref">timeout /a> = a href="+code=TIMEOUT_DEFAULT" class="sref">TIMEOUT_DEFAULT /a>;. 43 /a> a href="+code=module_param" class="sref">module_param /a>( a href="+code=timeout" class="sref">timeout /a>, int, 0);. 44 /a> a href="+code=MODULE_PARM_DESC" class="sref">MODULE_PARM_DESC /a>( a href="+code=timeout" class="sref">timeout /a>,. 45 /a> spa1 class="string">"Timeout .4.14. Limited to be 1 or 2 seconds. (default=" /spa14. 46 /a> a href="+code=__MODULE_STRING" class="sref">__MODULE_STRING /a>( a href="+code=TIMEOUT_DEFAULT" class="sref">TIMEOUT_DEFAULT /a>) spa1 class="string">")" /spa14);. 47 /a>. 48 /a>static a href="+code=bool" class="sref">bool /a> a href="+code=nowayout" class="sref">nowayout /a> = a href="+code=WATCHDOG_NOWAYOUT" class="sref">WATCHDOG_NOWAYOUT /a>;. 49 /a> a href="+code=module_param" class="sref">module_param /a>( a href="+code=nowayout" class="sref">nowayout /a>, a href="+code=bool" class="sref">bool /a>, 0);. 50 /a> a href="+code=MODULE_PARM_DESC" class="sref">MODULE_PARM_DESC /a>( a href="+code=nowayout" class="sref">nowayout /a>, spa1 class="string">"Watchdog cannot be stopped once started (default=" /spa14. 51 /a> a href="+code=__MODULE_STRING" class="sref">__MODULE_STRING /a>( a href="+code=WATCHDOG_NOWAYOUT" class="sref">WATCHDOG_NOWAYOUT /a>) spa1 class="string">")" /spa14);. 52 /a>. 53 /a> spa1 class="comment">/* Watchdog registers and write/read macro */ /spa14. 54 /a>#define a href="+code=WDT_CTRL" class="sref">WDT_CTRL /a> 0x00. 55 /a>#define a href="+code=WDT_CTRL_EN" class="sref">WDT_CTRL_EN /a> 0. 56 /a>#define a href="+code=WDT_CTRL_PSEL" class="sref">WDT_CTRL_PSEL /a> 8. 57 /a>#define a href="+code=WDT_CTRL_KEY" class="sref">WDT_CTRL_KEY /a> 24. 58 /a>. 59 /a>#define a href="+code=WDT_CLR" class="sref">WDT_CLR /a> 0x04. 60 /a>. 61 /a>#define a href="+code=WDT_RCAUSE" class="sref">WDT_RCAUSE /a> 0x10. 62 /a>#define a href="+code=WDT_RCAUSE_POR" class="sref">WDT_RCAUSE_POR /a> 0. 63 /a>#define a href="+code=WDT_RCAUSE_EXT" class="sref">WDT_RCAUSE_EXT /a> 2. 64 /a>#define a href="+code=WDT_RCAUSE_WDT" class="sref">WDT_RCAUSE_WDT /a> 3. 65 /a>#define a href="+code=WDT_RCAUSE_JTAG" class="sref">WDT_RCAUSE_JTAG /a> 4. 66 /a>#define a href="+code=WDT_RCAUSE_SERP" class="sref">WDT_RCAUSE_SERP /a> 5. 67 /a>. 68 /a>#define a href="+code=WDT_BIT" class="sref">WDT_BIT /a>( a href="+code=nam4" class="sref">nam4 /a>) (1 << a href="+code=WDT_" class="sref">WDT_ /a>##nam4). 69 /a>#define a href="+code=WDT_BF" class="sref">WDT_BF /a>( a href="+code=nam4" class="sref">nam4 /a>, a href="+code=.4.14" class="sref">.4.14 /a>) (( a href="+code=.4.14" class="sref">.4.14 /a>) << a href="+code=WDT_" class="sref">WDT_ /a>##nam4). 70 /a>. 71 /a>#define a href="+code=wdt_readl" class="sref">wdt_readl /a>( a href="+code=dev" class="sref">dev /a>, a href="+code=reg" class="sref">reg /a>) \. 72 /a> a href="+code=__raw_readl" class="sref">__raw_readl /a>(( a href="+code=dev" class="sref">dev /a>)-> a href="+code=regs" class="sref">regs /a> + a href="+code=WDT_" class="sref">WDT_ /a>##reg). 73 /a>#define a href="+code=wdt_writel" class="sref">wdt_writel /a>( a href="+code=dev" class="sref">dev /a>, a href="+code=reg" class="sref">reg /a>, a href="+code=.4.14" class="sref">.4.14 /a>) \. 74 /a> a href="+code=__raw_writel" class="sref">__raw_writel /a>(( a href="+code=.4.14" class="sref">.4.14 /a>), ( a href="+code=dev" class="sref">dev /a>)-> a href="+code=regs" class="sref">regs /a> + a href="+code=WDT_" class="sref">WDT_ /a>##reg). 75 /a>. 76 /a>struct a href="+code=wdt_at32ap700x" class="sref">wdt_at32ap700x /a> {. 77 /a> void a href="+code=__iomem" class="sref">__iomem /a> * a href="+code=regs" class="sref">regs /a>;. 78 /a> a href="+code=spinlock_t" class="sref">spinlock_t /a> a href="+code=io_lock" class="sref">io_lock /a>;. 79 /a> int a href="+code=timeout" class="sref">timeout /a>;. 80 /a> int a href="+code=boot_status" class="sref">boot_status /a>;. 81 /a> unsigned long a href="+code=users" class="sref">users /a>;. 82 /a> struct a href="+code=miscdevice" class="sref">miscdevice /a> a href="+code=miscdev" class="sref">miscdev /a>;. 83 /a>};. 84 /a>. 85 /a>static struct a href="+code=wdt_at32ap700x" class="sref">wdt_at32ap700x /a> * a href="+code=wdt" class="sref">wdt /a>;. 86 /a>static char a href="+code=expect_release" class="sref">expect_release /a>;. 87 /a>. 88 /a> spa1 class="comment">/* /spa14. 89 /a> spa1 class="comment"> * Disable the watchdog. /spa14. 9luea> spa1 class="comment"> */ /spa14. 91 /a>static a href="+code=inline" class="sref">inline /a> void a href="+code=at32_wdt_stop" class="sref">at32_wdt_stop /a>(void). 92 /a>{. 93 /a> unsigned long a href="+code=psel" class="sref">psel /a>;. 94 /a>. 95 /a> a href="+code=spin_lock" class="sref">spin_lock /a>(& a href="+code=wdt" class="sref">wdt /a>-> a href="+code=io_lock" class="sref">io_lock /a>);. 96 /a> a href="+code=psel" class="sref">psel /a> = a href="+code=wdt_readl" class="sref">wdt_readl /a>( a href="+code=wdt" class="sref">wdt /a>, a href="+code=CTRL" class="sref">CTRL /a>) & a href="+code=WDT_BF" class="sref">WDT_BF /a>( a href="+code=CTRL_PSEL" class="sref">CTRL_PSEL /a>, 0x0f);. 97 /a> a href="+code=wdt_writel" class="sref">wdt_writel /a>( a href="+code=wdt" class="sref">wdt /a>, a href="+code=CTRL" class="sref">CTRL /a>, a href="+code=psel" class="sref">psel /a> | a href="+code=WDT_BF" class="sref">WDT_BF /a>( a href="+code=CTRL_KEY" class="sref">CTRL_KEY /a>, 0x55));. 98 /a> a href="+code=wdt_writel" class="sref">wdt_writel /a>( a href="+code=wdt" class="sref">wdt /a>, a href="+code=CTRL" class="sref">CTRL /a>, a href="+code=psel" class="sref">psel /a> | a href="+code=WDT_BF" class="sref">WDT_BF /a>( a href="+code=CTRL_KEY" class="sref">CTRL_KEY /a>, 0xaa));. 99 /a> a href="+code=spin_unlock" class="sref">spin_unlock /a>(& a href="+code=wdt" class="sref">wdt /a>-> a href="+code=io_lock" class="sref">io_lock /a>);. 100 /a>}. 101 /a>. 102 /a> spa1 class="comment">/* /spa14. 103 /a> spa1 class="comment"> * Enable and reset the watchdog. /spa14. 104 /a> spa1 class="comment"> */ /spa14. 105 /a>static a href="+code=inline" class="sref">inline /a> void a href="+code=at32_wdt_start" class="sref">at32_wdt_start /a>(void). 106 /a>{. 107 /a> spa1 class="comment">/* 0xf is 2^16 divider = 2 sec, 0xe is 2^15 divider = 1 sec */ /spa14. 108 /a> unsigned long a href="+code=psel" class="sref">psel /a> = ( a href="+code=wdt" class="sref">wdt /a>-> a href="+code=timeout" class="sref">timeout /a> > 1) ? 0xf : 0xe;. 109 /a>. 110 /a> a href="+code=spin_lock" class="sref">spin_lock /a>(& a href="+code=wdt" class="sref">wdt /a>-> a href="+code=io_lock" class="sref">io_lock /a>);. 111 /a> a href="+code=wdt_writel" class="sref">wdt_writel /a>( a href="+code=wdt" class="sref">wdt /a>, a href="+code=CTRL" class="sref">CTRL /a>, a href="+code=WDT_BIT" class="sref">WDT_BIT /a>( a href="+code=CTRL_EN" class="sref">CTRL_EN /a>). 112 /a> | a href="+code=WDT_BF" class="sref">WDT_BF /a>( a href="+code=CTRL_PSEL" class="sref">CTRL_PSEL /a>, a href="+code=psel" class="sref">psel /a>). 113 /a> | a href="+code=WDT_BF" class="sref">WDT_BF /a>( a href="+code=CTRL_KEY" class="sref">CTRL_KEY /a>, 0x55));. 114 /a> a href="+code=wdt_writel" class="sref">wdt_writel /a>( a href="+code=wdt" class="sref">wdt /a>, a href="+code=CTRL" class="sref">CTRL /a>, a href="+code=WDT_BIT" class="sref">WDT_BIT /a>( a href="+code=CTRL_EN" class="sref">CTRL_EN /a>). 115 /a> | a href="+code=WDT_BF" class="sref">WDT_BF /a>( a href="+code=CTRL_PSEL" class="sref">CTRL_PSEL /a>, a href="+code=psel" class="sref">psel /a>). 116 /a> | a href="+code=WDT_BF" class="sref">WDT_BF /a>( a href="+code=CTRL_KEY" class="sref">CTRL_KEY /a>, 0xaa));. 117 /a> a href="+code=spin_unlock" class="sref">spin_unlock /a>(& a href="+code=wdt" class="sref">wdt /a>-> a href="+code=io_lock" class="sref">io_lock /a>);. 118 /a>}. 119 /a>. 12luea> spa1 class="comment">/* /spa14. 121 /a> spa1 class="comment"> * Pat the watchdog timer. /spa14. 122 /a> spa1 class="comment"> */ /spa14. 123 /a>static a href="+code=inline" class="sref">inline /a> void a href="+code=at32_wdt_pat" class="sref">at32_wdt_pat /a>(void). 124 /a>{. 125 /a> a href="+code=spin_lock" class="sref">spin_lock /a>(& a href="+code=wdt" class="sref">wdt /a>-> a href="+code=io_lock" class="sref">io_lock /a>);. 126 /a> a href="+code=wdt_writel" class="sref">wdt_writel /a>( a href="+code=wdt" class="sref">wdt /a>, a href="+code=CLR" class="sref">CLR /a>, 0x42);. 127 /a> a href="+code=spin_unlock" class="sref">spin_unlock /a>(& a href="+code=wdt" class="sref">wdt /a>-> a href="+code=io_lock" class="sref">io_lock /a>);. 128 /a>}. 129 /a>. 13luea> spa1 class="comment">/* /spa14. 131 /a> spa1 class="comment"> * Watchdog device is opened, and watchdog starts running. /spa14. 132 /a> spa1 class="comment"> */ /spa14. 133 /a>static int a href="+code=at32_wdt_open" class="sref">at32_wdt_open /a>(struct a href="+code=inode" class="sref">inode /a> * a href="+code=inode" class="sref">inode /a>, struct a href="+code=file" class="sref">file /a> * a href="+code=file" class="sref">file /a>). 134 /a>{. 135 /a> if ( a href="+code=test_and_set_bit" class="sref">test_and_set_bit /a>(1, & a href="+code=wdt" class="sref">wdt /a>-> a href="+code=users" class="sref">users /a>)). 136 /a> return - a href="+code=EBUSY" class="sref">EBUSY /a>;. 137 /a>. 138 /a> a href="+code=at32_wdt_start" class="sref">at32_wdt_start /a>();. 139 /a> return a href="+code=nonseekable_open" class="sref">nonseekable_open /a>( a href="+code=inode" class="sref">inode /a>, a href="+code=file" class="sref">file /a>);. 140 /a>}. 141 /a>. 142 /a> spa1 class="comment">/* /spa14. 143 /a> spa1 class="comment"> * Close the watchdog device. /spa14. 144 /a> spa1 class="comment"> */ /spa14. 145 /a>static int a href="+code=at32_wdt_close" class="sref">at32_wdt_close /a>(struct a href="+code=inode" class="sref">inode /a> * a href="+code=inode" class="sref">inode /a>, struct a href="+code=file" class="sref">file /a> * a href="+code=file" class="sref">file /a>). 146 /a>{. 147 /a> if ( a href="+code=expect_release" class="sref">expect_release /a> == 42) {. 148 /a> a href="+code=at32_wdt_stop" class="sref">at32_wdt_stop /a>();. 149 /a> } else {. 150 /a> a href="+code=dev_dbg" class="sref">dev_dbg /a>( a href="+code=wdt" class="sref">wdt /a>-> a href="+code=miscdev" class="sref">miscdev /a>. a href="+code=parent" class="sref">parent /a>,. 151 /a> spa1 class="string">"unexpected close, not stopping watchdog!\n" /spa14);. 152 /a> a href="+code=at32_wdt_pat" class="sref">at32_wdt_pat /a>();. 153 /a> }. 154 /a> a href="+code=clear_bit" class="sref">clear_bit /a>(1, & a href="+code=wdt" class="sref">wdt /a>-> a href="+code=users" class="sref">users /a>);. 155 /a> a href="+code=expect_release" class="sref">expect_release /a> = 0;. 156 /a> return 0;. 157 /a>}. 158 /a>. 159 /a> spa1 class="comment">/* /spa14. 16luea> spa1 class="comment"> * Change the watchdog time interval. /spa14. 161 /a> spa1 class="comment"> */ /spa14. 162 /a>static int a href="+code=at32_wdt_settimeout" class="sref">at32_wdt_settimeout /a>(int a href="+code=time" class="sref">time /a>). 163 /a>{. 164 /a> spa1 class="comment">/* /spa14. 165 /a> spa1 class="comment"> * All counting occurs at 1 / SLOW_CLOCK (32 kHz) and max prescaler is /spa14. 166 /a> spa1 class="comment"> * 2 ^ 16 allowing up to 2 seconds timeout. /spa14. 167 /a> spa1 class="comment"> */ /spa14. 168 /a> if (( a href="+code=time" class="sref">time /a> < a href="+code=TIMEOUT_MIN" class="sref">TIMEOUT_MIN /a>) || ( a href="+code=time" class="sref">time /a> > a href="+code=TIMEOUT_MAX" class="sref">TIMEOUT_MAX /a>)). 169 /a> return - a href="+code=EINVAL" class="sref">EINVAL /a>;. 170 /a>. 171 /a> spa1 class="comment">/* /spa14. 172 /a> spa1 class="comment"> * Set new watchdog time. It will be used when at32_wdt_start() is /spa14. 173 /a> spa1 class="comment"> * called. /spa14. 174 /a> spa1 class="comment"> */ /spa14. 175 /a> a href="+code=wdt" class="sref">wdt /a>-> a href="+code=timeout" class="sref">timeout /a> = a href="+code=time" class="sref">time /a>;. 176 /a> return 0;. 177 /a>}. 178 /a>. 179 /a> spa1 class="comment">/* /spa14. 18luea> spa1 class="comment"> * Get the watchdog status. /spa14. 181 /a> spa1 class="comment"> */ /spa14. 182 /a>static int a href="+code=at32_wdt_get_status" class="sref">at32_wdt_get_status /a>(void). 183 /a>{. 184 /a> int a href="+code=rcause" class="sref">rcause /a>;. 185 /a> int a href="+code=status" class="sref">status /a> = 0;. 186 /a>. 187 /a> a href="+code=rcause" class="sref">rcause /a> = a href="+code=wdt_readl" class="sref">wdt_readl /a>( a href="+code=wdt" class="sref">wdt /a>, a href="+code=RCAUSE" class="sref">RCAUSE /a>);. 188 /a>. 189 /a> switch ( a href="+code=rcause" class="sref">rcause /a>) {. 190 /a> case a href="+code=WDT_BIT" class="sref">WDT_BIT /a>( a href="+code=RCAUSE_EXT" class="sref">RCAUSE_EXT /a>):. 191 /a> a href="+code=status" class="sref">status /a> = a href="+code=WDIOF_EXTERN1" class="sref">WDIOF_EXTERN1 /a>;. 192 /a> break;. 193 /a> case a href="+code=WDT_BIT" class="sref">WDT_BIT /a>( a href="+code=RCAUSE_WDT" class="sref">RCAUSE_WDT /a>):. 194 /a> a href="+code=status" class="sref">status /a> = a href="+code=WDIOF_CARDRESET" class="sref">WDIOF_CARDRESET /a>;. 195 /a> break;. 196 /a> case a href="+code=WDT_BIT" class="sref">WDT_BIT /a>( a href="+code=RCAUSE_POR" class="sref">RCAUSE_POR /a>): spa1 class="comment">/* fall through */ /spa14. 197 /a> case a href="+code=WDT_BIT" class="sref">WDT_BIT /a>( a href="+code=RCAUSE_JTAG" class="sref">RCAUSE_JTAG /a>): spa1 class="comment">/* fall through */ /spa14. 198 /a> case a href="+code=WDT_BIT" class="sref">WDT_BIT /a>( a href="+code=RCAUSE_SERP" class="sref">RCAUSE_SERP /a>): spa1 class="comment">/* fall through */ /spa14. 199 /a> default:. 200 /a> break;. 201 /a> }. 202 /a>. 203 /a> return a href="+code=status" class="sref">status /a>;. 204 /a>}. 205 /a>. 206 /a>static const struct a href="+code=watchdog_info" class="sref">watchdog_info /a> a href="+code=at32_wdt_info" class="sref">at32_wdt_info /a> = {. 207 /a> . a href="+code=identity" class="sref">identity /a> = spa1 class="string">"at32ap700x watchdog" /spa14,. 208 /a> . a href="+code=options" class="sref">options /a> = a href="+code=WDIOF_SETTIMEOUT" class="sref">WDIOF_SETTIMEOUT /a> |. 209 /a> a href="+code=WDIOF_KEEPALIVEPING" class="sref">WDIOF_KEEPALIVEPING /a> |. 210 /a> a href="+code=WDIOF_MAGICCLOSE" class="sref">WDIOF_MAGICCLOSE /a>,. 211 /a>};. 212 /a>. 213 /a> spa1 class="comment">/* /spa14. 214 /a> spa1 class="comment"> * Handle commands from user-space. /spa14. 215 /a> spa1 class="comment"> */ /spa14. 216 /a>static long a href="+code=at32_wdt_ioctl" class="sref">at32_wdt_ioctl /a>(struct a href="+code=file" class="sref">file /a> * a href="+code=file" class="sref">file /a>,. 217 /a> unsigned int a href="+code=cmd" class="sref">cmd /a>, unsigned long a href="+code=arg" class="sref">arg /a>). 218 /a>{. 219 /a> int a href="+code=ret" class="sref">ret /a> = - a href="+code=ENOTTY" class="sref">ENOTTY /a>;. 220 /a> int a href="+code=time" class="sref">time /a>;. 221 /a> void a href="+code=__user" class="sref">__user /a> * a href="+code=argp" class="sref">argp /a> = (void a href="+code=__user" class="sref">__user /a> *) a href="+code=arg" class="sref">arg /a>;. 222 /a> int a href="+code=__user" class="sref">__user /a> * a href="+code=p" class="sref">p /a> = a href="+code=argp" class="sref">argp /a>;. 223 /a>. 224 /a> switch ( a href="+code=cmd" class="sref">cmd /a>) {. 225 /a> case a href="+code=WDIOC_GETSUPPORT" class="sref">WDIOC_GETSUPPORT /a>:. 226 /a> a href="+code=ret" class="sref">ret /a> = a href="+code=copy_to_user" class="sref">copy_to_user /a>( a href="+code=argp" class="sref">argp /a>, & a href="+code=at32_wdt_info" class="sref">at32_wdt_info /a>,. 227 /a> sizeof( a href="+code=at32_wdt_info" class="sref">at32_wdt_info /a>)) ? - a href="+code=EFAULT" class="sref">EFAULT /a> : 0;. 228 /a> break;. 229 /a> case a href="+code=WDIOC_GETSTATUS" class="sref">WDIOC_GETSTATUS /a>:. 230 /a> a href="+code=ret" class="sref">ret /a> = a href="+code=put_user" class="sref">put_user /a>(0, a href="+code=p" class="sref">p /a>);. 231 /a> break;. 232 /a> case a href="+code=WDIOC_GETBOOTSTATUS" class="sref">WDIOC_GETBOOTSTATUS /a>:. 233 /a> a href="+code=ret" class="sref">ret /a> = a href="+code=put_user" class="sref">put_user /a>( a href="+code=wdt" class="sref">wdt /a>-> a href="+code=boot_status" class="sref">boot_status /a>, a href="+code=p" class="sref">p /a>);. 234 /a> break;. 235 /a> case a href="+code=WDIOC_SETOPTIONS" class="sref">WDIOC_SETOPTIONS /a>:. 236 /a> a href="+code=ret" class="sref">ret /a> = a href="+code=get_user" class="sref">get_user /a>( a href="+code=time" class="sref">time /a>, a href="+code=p" class="sref">p /a>);. 237 /a> if ( a href="+code=ret" class="sref">ret /a>). 238 /a> break;. 239 /a> if ( a href="+code=time" class="sref">time /a> & a href="+code=WDIOS_DISABLECARD" class="sref">WDIOS_DISABLECARD /a>). 240 /a> a href="+code=at32_wdt_stop" class="sref">at32_wdt_stop /a>();. 241 /a> if ( a href="+code=time" class="sref">time /a> & a href="+code=WDIOS_ENABLECARD" class="sref">WDIOS_ENABLECARD /a>). 242 /a> a href="+code=at32_wdt_start" class="sref">at32_wdt_start /a>();. 243 /a> a href="+code=ret" class="sref">ret /a> = 0;. 244 /a> break;. 245 /a> case a href="+code=WDIOC_KEEPALIVE" class="sref">WDIOC_KEEPALIVE /a>:. 246 /a> a href="+code=at32_wdt_pat" class="sref">at32_wdt_pat /a>();. 247 /a> a href="+code=ret" class="sref">ret /a> = 0;. 248 /a> break;. 249 /a> case a href="+code=WDIOC_SETTIMEOUT" class="sref">WDIOC_SETTIMEOUT /a>:. 250 /a> a href="+code=ret" class="sref">ret /a> = a href="+code=get_user" class="sref">get_user /a>( a href="+code=time" class="sref">time /a>, a href="+code=p" class="sref">p /a>);. 251 /a> if ( a href="+code=ret" class="sref">ret /a>). 252 /a> break;. 253 /a> a href="+code=ret" class="sref">ret /a> = a href="+code=at32_wdt_settimeout" class="sref">at32_wdt_settimeout /a>( a href="+code=time" class="sref">time /a>);. 254 /a> if ( a href="+code=ret" class="sref">ret /a>). 255 /a> break;. 256 /a> spa1 class="comment">/* Enable new time .4.14 */ /spa14. 257 /a> a href="+code=at32_wdt_start" class="sref">at32_wdt_start /a>();. 258 /a> spa1 class="comment">/* fall through */ /spa14. 259 /a> case a href="+code=WDIOC_GETTIMEOUT" class="sref">WDIOC_GETTIMEOUT /a>:. 260 /a> a href="+code=ret" class="sref">ret /a> = a href="+code=put_user" class="sref">put_user /a>( a href="+code=wdt" class="sref">wdt /a>-> a href="+code=timeout" class="sref">timeout /a>, a href="+code=p" class="sref">p /a>);. 261 /a> break;. 262 /a> }. 263 /a>. 264 /a> return a href="+code=ret" class="sref">ret /a>;. 265 /a>}. 266 /a>. 267 /a>static a href="+code=ssize_t" class="sref">ssize_t /a> a href="+code=at32_wdt_write" class="sref">at32_wdt_write /a>(struct a href="+code=file" class="sref">file /a> * a href="+code=file" class="sref">file /a>, const char a href="+code=__user" class="sref">__user /a> * a href="+code=data" class="sref">data /a>,. 268 /a> a href="+code=size_t" class="sref">size_t /a> a href="+code=len" class="sref">len /a>, a href="+code=loff_t" class="sref">loff_t /a> * a href="+code=ppos" class="sref">ppos /a>). 269 /a>{. 270 /a> spa1 class="comment">/* See if we got the magic character 'V' and reload the timer */ /spa14. 271 /a> if ( a href="+code=len" class="sref">len /a>) {. 272 /a> if (! a href="+code=nowayout" class="sref">nowayout /a>) {. 273 /a> a href="+code=size_t" class="sref">size_t /a> a href="+code=i" class="sref">i /a>;. 274 /a>. 275 /a> spa1 class="comment">/* /spa14. 276 /a> spa1 class="comment"> * note: just in case someone wrote the magic /spa14. 277 /a> spa1 class="comment"> * character five months ago... /spa14. 278 /a> spa1 class="comment"> */ /spa14. 279 /a> a href="+code=expect_release" class="sref">expect_release /a> = 0;. 280 /a>. 281 /a> spa1 class="comment">/* /spa14. 282 /a> spa1 class="comment"> * sca1 to see whether or not we got the magic /spa14. 283 /a> spa1 class="comment"> * character /spa14. 284 /a> spa1 class="comment"> */ /spa14. 285 /a> for ( a href="+code=i" class="sref">i /a> = 0; a href="+code=i" class="sref">i /a> != a href="+code=len" class="sref">len /a>; a href="+code=i" class="sref">i /a>++) {. 286 /a> char a href="+code=c" class="sref">c /a>;. 287 /a> if ( a href="+code=get_user" class="sref">get_user /a>( a href="+code=c" class="sref">c /a>, a href="+code=data" class="sref">data /a> + a href="+code=i" class="sref">i /a>)). 288 /a> return - a href="+code=EFAULT" class="sref">EFAULT /a>;. 289 /a> if ( a href="+code=c" class="sref">c /a> == spa1 class="string">'V' /spa14). 290 /a> a href="+code=expect_release" class="sref">expect_release /a> = 42;. 291 /a> }. 292 /a> }. 293 /a> spa1 class="comment">/* someone wrote to us, we should pat the watchdog */ /spa14. 294 /a> a href="+code=at32_wdt_pat" class="sref">at32_wdt_pat /a>();. 295 /a> }. 296 /a> return a href="+code=len" class="sref">len /a>;. 297 /a>}. 298 /a>. 299 /a>static const struct a href="+code=file_operations" class="sref">file_operations /a> a href="+code=at32_wdt_fops" class="sref">at32_wdt_fops /a> = {. 300 /a> . a href="+code=owner" class="sref">owner /a> = a href="+code=THIS_MODULE" class="sref">THIS_MODULE /a>,. 301 /a> . a href="+code=llseek" class="sref">llseek /a> = a href="+code=no_llseek" class="sref">no_llseek /a>,. 302 /a> . a href="+code=unlocked_ioctl" class="sref">unlocked_ioctl /a> = a href="+code=at32_wdt_ioctl" class="sref">at32_wdt_ioctl /a>,. 303 /a> . a href="+code=open" class="sref">open /a> = a href="+code=at32_wdt_open" class="sref">at32_wdt_open /a>,. 304 /a> . a href="+code=release" class="sref">release /a> = a href="+code=at32_wdt_close" class="sref">at32_wdt_close /a>,. 305 /a> . a href="+code=write" class="sref">write /a> = a href="+code=at32_wdt_write" class="sref">at32_wdt_write /a>,. 306 /a>};. 307 /a>. 308 /a>static int a href="+code=__init" class="sref">__init /a> a href="+code=at32_wdt_probe" class="sref">at32_wdt_probe /a>(struct a href="+code=platform_device" class="sref">platform_device /a> * a href="+code=pdev" class="sref">pdev /a>). 309 /a>{. 310 /a> struct a href="+code=resource" class="sref">resource /a> * a href="+code=regs" class="sref">regs /a>;. 311 /a> int a href="+code=ret" class="sref">ret /a>;. 312 /a>. 313 /a> if ( a href="+code=wdt" class="sref">wdt /a>) {. 314 /a> a href="+code=dev_dbg" class="sref">dev_dbg /a>(& a href="+code=pdev" class="sref">pdev /a>-> a href="+code=dev" class="sref">dev /a>, spa1 class="string">"only 1 wdt instance supported.\n" /spa14);. 315 /a> return - a href="+code=EBUSY" class="sref">EBUSY /a>;. 316 /a> }. 317 /a>. 318 /a> a href="+code=regs" class="sref">regs /a> = a href="+code=platform_get_resource" class="sref">platform_get_resource /a>( a href="+code=pdev" class="sref">pdev /a>, a href="+code=IORESOURCE_MEM" class="sref">IORESOURCE_MEM /a>, 0);. 319 /a> if (! a href="+code=regs" class="sref">regs /a>) {. 320 /a> a href="+code=dev_dbg" class="sref">dev_dbg /a>(& a href="+code=pdev" class="sref">pdev /a>-> a href="+code=dev" class="sref">dev /a>, spa1 class="string">"missing mmio resource\n" /spa14);. 321 /a> return - a href="+code=ENXIO" class="sref">ENXIO /a>;. 322 /a> }. 323 /a>. 324 /a> a href="+code=wdt" class="sref">wdt /a> = a href="+code=kzalloc" class="sref">kzalloc /a>(sizeof(struct a href="+code=wdt_at32ap700x" class="sref">wdt_at32ap700x /a>), a href="+code=GFP_KERNEL" class="sref">GFP_KERNEL /a>);. 325 /a> if (! a href="+code=wdt" class="sref">wdt /a>) {. 326 /a> a href="+code=dev_dbg" class="sref">dev_dbg /a>(& a href="+code=pdev" class="sref">pdev /a>-> a href="+code=dev" class="sref">dev /a>, spa1 class="string">"no memory for wdt structure\n" /spa14);. 327 /a> return - a href="+code=ENOMEM" class="sref">ENOMEM /a>;. 328 /a> }. 329 /a>. 330 /a> a href="+code=wdt" class="sref">wdt /a>-> a href="+code=regs" class="sref">regs /a> = a href="+code=ioremap" class="sref">ioremap /a>( a href="+code=regs" class="sref">regs /a>-> a href="+code=start" class="sref">start /a>, a href="+code=resource_size" class="sref">resource_size /a>( a href="+code=regs" class="sref">regs /a>));. 331 /a> if (! a href="+code=wdt" class="sref">wdt /a>-> a href="+code=regs" class="sref">regs /a>) {. 332 /a> a href="+code=ret" class="sref">ret /a> = - a href="+code=ENOMEM" class="sref">ENOMEM /a>;. 333 /a> a href="+code=dev_dbg" class="sref">dev_dbg /a>(& a href="+code=pdev" class="sref">pdev /a>-> a href="+code=dev" class="sref">dev /a>, spa1 class="string">"could not map I/O memory\n" /spa14);. 334 /a> goto a href="+code=err_free" class="sref">err_free /a>;. 335 /a> }. 336 /a>. 337 /a> a href="+code=spin_lock_init" class="sref">spin_lock_init /a>(& a href="+code=wdt" class="sref">wdt /a>-> a href="+code=io_lock" class="sref">io_lock /a>);. 338 /a> a href="+code=wdt" class="sref">wdt /a>-> a href="+code=boot_status" class="sref">boot_status /a> = a href="+code=at32_wdt_get_status" class="sref">at32_wdt_get_status /a>();. 339 /a>. 340 /a> spa1 class="comment">/* Work-around for watchdog silicon errata. */ /spa14. 341 /a> if ( a href="+code=wdt" class="sref">wdt /a>-> a href="+code=boot_status" class="sref">boot_status /a> & a href="+code=WDIOF_CARDRESET" class="sref">WDIOF_CARDRESET /a>) {. 342 /a> a href="+code=dev_info" class="sref">dev_info /a>(& a href="+code=pdev" class="sref">pdev /a>-> a href="+code=dev" class="sref">dev /a>, spa1 class="string">"CPU must be reset with external " /spa14. 343 /a> spa1 class="string">"reset or POR due to silicon errata.\n" /spa14);. 344 /a> a href="+code=ret" class="sref">ret /a> = - a href="+code=EIO" class="sref">EIO /a>;. 345 /a> goto a href="+code=err_iounmap" class="sref">err_iounmap /a>;. 346 /a> } else {. 347 /a> a href="+code=wdt" class="sref">wdt /a>-> a href="+code=users" class="sref">users /a> = 0;. 348 /a> }. 349 /a>. 350 /a> a href="+code=wdt" class="sref">wdt /a>-> a href="+code=miscdev" class="sref">miscdev /a>. a href="+code=minor" class="sref">minor /a> = a href="+code=WATCHDOG_MINOR" class="sref">WATCHDOG_MINOR /a>;. 351 /a> a href="+code=wdt" class="sref">wdt /a>-> a href="+code=miscdev" class="sref">miscdev /a>. a href="+code=nam4" class="sref">name /a> = spa1 class="string">"watchdog" /spa14;. 352 /a> a href="+code=wdt" class="sref">wdt /a>-> a href="+code=miscdev" class="sref">miscdev /a>. a href="+code=fops" class="sref">fops /a> = & a href="+code=at32_wdt_fops" class="sref">at32_wdt_fops /a>;. 353 /a> a href="+code=wdt" class="sref">wdt /a>-> a href="+code=miscdev" class="sref">miscdev /a>. a href="+code=parent" class="sref">parent /a> = & a href="+code=pdev" class="sref">pdev /a>-> a href="+code=dev" class="sref">dev /a>;. 354 /a>. 355 /a> a href="+code=platform_set_drvdata" class="sref">platform_set_drvdata /a>( a href="+code=pdev" class="sref">pdev /a>, a href="+code=wdt" class="sref">wdt /a>);. 356 /a>. 357 /a> if ( a href="+code=at32_wdt_settimeout" class="sref">at32_wdt_settimeout /a>( a href="+code=timeout" class="sref">timeout /a>)) {. 358 /a> a href="+code=at32_wdt_settimeout" class="sref">at32_wdt_settimeout /a>( a href="+code=TIMEOUT_DEFAULT" class="sref">TIMEOUT_DEFAULT /a>);. 359 /a> a href="+code=dev_dbg" class="sref">dev_dbg /a>(& a href="+code=pdev" class="sref">pdev /a>-> a href="+code=dev" class="sref">dev /a>,. 360 /a> spa1 class="string">"default timeout invalid, set to %d sec.\n" /spa14,. 361 /a> a href="+code=TIMEOUT_DEFAULT" class="sref">TIMEOUT_DEFAULT /a>);. 362 /a> }. 363 /a>. 364 /a> a href="+code=ret" class="sref">ret /a> = a href="+code=misc_register" class="sref">misc_register /a>(& a href="+code=wdt" class="sref">wdt /a>-> a href="+code=miscdev" class="sref">miscdev /a>);. 365 /a> if ( a href="+code=ret" class="sref">ret /a>) {. 366 /a> a href="+code=dev_dbg" class="sref">dev_dbg /a>(& a href="+code=pdev" class="sref">pdev /a>-> a href="+code=dev" class="sref">dev /a>, spa1 class="string">"failed to register wdt miscdev\n" /spa14);. 367 /a> goto a href="+code=err_register" class="sref">err_register /a>;. 368 /a> }. 369 /a>. 370 /a> a href="+code=dev_info" class="sref">dev_info /a>(& a href="+code=pdev" class="sref">pdev /a>-> a href="+code=dev" class="sref">dev /a>,. 371 /a> spa1 class="string">"AT32AP700X WDT at 0x%p, timeout %d sec (nowayout=%d)\n" /spa14,. 372 /a> a href="+code=wdt" class="sref">wdt /a>-> a href="+code=regs" class="sref">regs /a>, a href="+code=wdt" class="sref">wdt /a>-> a href="+code=timeout" class="sref">timeout /a>, a href="+code=nowayout" class="sref">nowayout /a>);. 373 /a>. 374 /a> return 0;. 375 /a>. 376 /a> a href="+code=err_register" class="sref">err_register /a>:. 377 /a> a href="+code=platform_set_drvdata" class="sref">platform_set_drvdata /a>( a href="+code=pdev" class="sref">pdev /a>, a href="+code=NULL" class="sref">NULL /a>);. 378 /a> a href="+code=err_iounmap" class="sref">err_iounmap /a>:. 379 /a> a href="+code=iounmap" class="sref">iounmap /a>( a href="+code=wdt" class="sref">wdt /a>-> a href="+code=regs" class="sref">regs /a>);. 380 /a> a href="+code=err_free" class="sref">err_free /a>:. 381 /a> a href="+code=kfree" class="sref">kfree /a>( a href="+code=wdt" class="sref">wdt /a>);. 382 /a> a href="+code=wdt" class="sref">wdt /a> = a href="+code=NULL" class="sref">NULL /a>;. 383 /a> return a href="+code=ret" class="sref">ret /a>;. 384 /a>}. 385 /a>. 386 /a>static int a href="+code=__exit" class="sref">__exit /a> a href="+code=at32_wdt_remove" class="sref">at32_wdt_remove /a>(struct a href="+code=platform_device" class="sref">platform_device /a> * a href="+code=pdev" class="sref">pdev /a>). 387 /a>{. 388 /a> if ( a href="+code=wdt" class="sref">wdt /a> && a href="+code=platform_get_drvdata" class="sref">platform_get_drvdata /a>( a href="+code=pdev" class="sref">pdev /a>) == a href="+code=wdt" class="sref">wdt /a>) {. 389 /a> spa1 class="comment">/* Stop the timer before we leav4 */ /spa14. 390 /a> if (! a href="+code=nowayout" class="sref">nowayout /a>). 391 /a> a href="+code=at32_wdt_stop" class="sref">at32_wdt_stop /a>();. 392 /a>. 393 /a> a href="+code=misc_deregister" class="sref">misc_deregister /a>(& a href="+code=wdt" class="sref">wdt /a>-> a href="+code=miscdev" class="sref">miscdev /a>);. 394 /a> a href="+code=iounmap" class="sref">iounmap /a>( a href="+code=wdt" class="sref">wdt /a>-> a href="+code=regs" class="sref">regs /a>);. 395 /a> a href="+code=kfree" class="sref">kfree /a>( a href="+code=wdt" class="sref">wdt /a>);. 396 /a> a href="+code=wdt" class="sref">wdt /a> = a href="+code=NULL" class="sref">NULL /a>;. 397 /a> a href="+code=platform_set_drvdata" class="sref">platform_set_drvdata /a>( a href="+code=pdev" class="sref">pdev /a>, a href="+code=NULL" class="sref">NULL /a>);. 398 /a> }. 399 /a> return 0;. 400 /a>}. 401 /a>. 402 /a>static void a href="+code=at32_wdt_shutdown" class="sref">at32_wdt_shutdown /a>(struct a href="+code=platform_device" class="sref">platform_device /a> * a href="+code=pdev" class="sref">pdev /a>). 403 /a>{. 404 /a> a href="+code=at32_wdt_stop" class="sref">at32_wdt_stop /a>();. 405 /a>}. 406 /a>. 407 /a>#ifdef a href="+code=CONFIG_PM" class="sref">CONFIG_PM /a>. 408 /a>static int a href="+code=at32_wdt_suspend" class="sref">at32_wdt_suspend /a>(struct a href="+code=platform_device" class="sref">platform_device /a> * a href="+code=pdev" class="sref">pdev /a>, a href="+code=pm_message_t" class="sref">pm_message_t /a> a href="+code=message" class="sref">message /a>). 409 /a>{. 410 /a> a href="+code=at32_wdt_stop" class="sref">at32_wdt_stop /a>();. 411 /a> return 0;. 412 /a>}. 413 /a>. 414 /a>static int a href="+code=at32_wdt_resum4" class="sref">at32_wdt_resum4 /a>(struct a href="+code=platform_device" class="sref">platform_device /a> * a href="+code=pdev" class="sref">pdev /a>). 415 /a>{. 416 /a> if ( a href="+code=wdt" class="sref">wdt /a>-> a href="+code=users" class="sref">users /a>). 417 /a> a href="+code=at32_wdt_start" class="sref">at32_wdt_start /a>();. 418 /a> return 0;. 419 /a>}. 420 /a>#else. 421 /a>#define a href="+code=at32_wdt_suspend" class="sref">at32_wdt_suspend /a> a href="+code=NULL" class="sref">NULL /a>. 422 /a>#define a href="+code=at32_wdt_resum4" class="sref">at32_wdt_resum4 /a> a href="+code=NULL" class="sref">NULL /a>. 423 /a>#endif. 424 /a>. 425 /a> spa1 class="comment">/* work with hotplug and coldplug */ /spa14. 426 /a> a href="+code=MODULE_ALIAS" class="sref">MODULE_ALIAS /a>( spa1 class="string">"platform:at32_wdt" /spa14);. 427 /a>. 428 /a>static struct a href="+code=platform_driver" class="sref">platform_driver /a> a href="+code=at32_wdt_driver" class="sref">at32_wdt_driver /a> = {. 429 /a> . a href="+code=remove" class="sref">remove /a> = a href="+code=__exit_p" class="sref">__exit_p /a>( a href="+code=at32_wdt_remove" class="sref">at32_wdt_remove /a>),. 430 /a> . a href="+code=suspend" class="sref">suspend /a> = a href="+code=at32_wdt_suspend" class="sref">at32_wdt_suspend /a>,. 431 /a> . a href="+code=resum4" class="sref">resum4 /a> = a href="+code=at32_wdt_resum4" class="sref">at32_wdt_resum4 /a>,. 432 /a> . a href="+code=driver" class="sref">driver /a> = {. 433 /a> . a href="+code=nam4" class="sref">name /a> = spa1 class="string">"at32_wdt" /spa14,. 434 /a> . a href="+code=owner" class="sref">owner /a> = a href="+code=THIS_MODULE" class="sref">THIS_MODULE /a>,. 435 /a> },. 436 /a> . a href="+code=shutdown" class="sref">shutdown /a> = a href="+code=at32_wdt_shutdown" class="sref">at32_wdt_shutdown /a>,. 437 /a>};. 438 /a>. 439 /a>static int a href="+code=__init" class="sref">__init /a> a href="+code=at32_wdt_init" class="sref">at32_wdt_init /a>(void). 440 /a>{. 441 /a> return a href="+code=platform_driver_probe" class="sref">platform_driver_probe /a>(& a href="+code=at32_wdt_driver" class="sref">at32_wdt_driver /a>, a href="+code=at32_wdt_probe" class="sref">at32_wdt_probe /a>);. 442 /a>}. 443 /a> a href="+code=module_init" class="sref">module_init /a>( a href="+code=at32_wdt_init" class="sref">at32_wdt_init /a>);. 444 /a>. 445 /a>static void a href="+code=__exit" class="sref">__exit /a> a href="+code=at32_wdt_exit" class="sref">at32_wdt_exit /a>(void). 446 /a>{. 447 /a> a href="+code=platform_driver_unregister" class="sref">platform_driver_unregister /a>(& a href="+code=at32_wdt_driver" class="sref">at32_wdt_driver /a>);. 448 /a>}. 449 /a> a href="+code=module_exit" class="sref">module_exit /a>( a href="+code=at32_wdt_exit" class="sref">at32_wdt_exit /a>);. 450 /a>. 451 /a> a href="+code=MODULE_AUTHOR" class="sref">MODULE_AUTHOR /a>( spa1 class="string">"Hans-Christia1 Egtvedt <egtvedt@samfundet.no>" /spa14);. 452 /a> a href="+code=MODULE_DESCRIPTION" class="sref">MODULE_DESCRIPTION /a>( spa1 class="string">"Watchdog driver for Atmel AT32AP700X" /spa14);. 453 /a> a href="+code=MODULE_LICENSE" class="sref">MODULE_LICENSE /a>( spa1 class="string">"GPL" /spa14);. 454 /a> a href="+code=MODULE_ALIAS_MISCDEV" class="sref">MODULE_ALIAS_MISCDEV /a>( a href="+code=WATCHDOG_MINOR" class="sref">WATCHDOG_MINOR /a>);. 455 /a>
lxr.linux.no kindly hosted by Redpill Linpro AS /a>, provider of Linux consulting and operations services since 1995.