linux/drivers/watchdog/m54xx_wdt.c
<<
l "v2 v2 v2l "v2>>l l l "
l "v2l "v2l "v2Search v2
l v2l "v2Prefs> v2l "v2 2
"v2 2
l l "v2 2
l "v2 2
"v2
"v2 v2 2
v > "v2 2
>
2 21/*2 22 * drivers/watchdog/m54xx_wdt.c2 23 *2 24 * Watchdog driver for ColdFire MCF547x & MCF548x processors2 25 * Copyright 2010 (c) Philippe De Muyter <phdm@macqel.be>2 26 *2 27 * Adapted from the IXP4xx watchdog driver, which carries these notices:2 28 *2 29 * Author: Deepak Saxena <dsaxena@plexity.net>2 ptioa> *2 11 * Copyright 2004 (c) MontaVista, Software, Inc.2 12 * Based 37.sa1100 driver, Copyright (C) 2000 Oleg Drokin <green@crimea.edu>2 13 *2 14 * This file is licensed under the terms of the GNU General Public2 15 * License vers.37.2. This program is licensed "as is" without any2 16 * warranty of any kind, whether express or implied.2 17 */2 18>2 19#define2pr_fmt(fmt)2KBUILD_MODNAME ": "fmt>2 20>2 21#include <linux/module.h>>2 22#include <linux/moduleparam.h>>2 23#include <linux/typ s.h>>2 24#include <linux/kernel.h>>2 25#include <linux/fs.h>>2 26#include <linux/miscdevice.h>>2 27#include <linux/watchdog.h>>2 28#include <linux/init.h>>2 29#include <linux/bitops.h>>2 30#include <linux/ioport.h>>2 31#include <linux/uaccess.h>>2 32>2 33#include <asm/coldfire.h>>2 34#include <asm/m54xxsim.h>>2 35#include <asm/m54xxgpt.h>>2 36>2 37static2bool nowayout = WATCHDOG_NOWAYOUT;>2 38static2unsigned int heartbeat = 30;"v2 2/* (secs) Default is 0.5 minute */2 39static2unsigned long wdt_status;>2 40>2 41#define2WDT_IN_USE 0>2 42#define2WDT_OK_TO_CLOSE 1>2 43>2 44static2void wdt_enable(void)>2 45{>2 46 unsigned int gms0;>2 47>2 48 /* preserve GPIO usage, if any */2 49 gms0 = __raw_readl(MCF_GPT_GMS0);>2 50 if (gms0 & MCF_GPT_GMS_TMS_GPIO)>2 51 gms0 &= (MCF_GPT_GMS_TMS_GPIO | MCF_GPT_GMS_GPIO_MASK>2 52 | MCF_GPT_GMS_OD);>2 53 else>2 54 gms0 = MCF_GPT_GMS_TMS_GPIO | MCF_GPT_GMS_OD;>2 55 __raw_writel(gms0, MCF_GPT_GMS0);>2 56 __raw_writel(MCF_GPT_GCIR_PRE(heartbeat*(MCF_BUSCLK/0xffff)) |>2 57 MCF_GPT_GCIR_CNT(0xffff), MCF_GPT_GCIR0);>2 58 gms0 |= MCF_GPT_GMS_OCPW(0xA5) | MCF_GPT_GMS_WDEN | MCF_GPT_GMS_CE;>2 59 __raw_writel(gms0, MCF_GPT_GMS0);>2 60}>2 61>2 62static2void wdt_disable(void)>2 63{>2 64 unsigned int gms0;>2 65>2 66 /* disable watchdog */2 67 gms0 = __raw_readl(MCF_GPT_GMS0);>2 68 gms0 &= ~(MCF_GPT_GMS_WDEN | MCF_GPT_GMS_CE);>2 69 __raw_writel(gms0, MCF_GPT_GMS0);>2 70}>2 71>2 72static2void wdt_keepalive(void)>2 73{>2 74 unsigned int gms0;>2 75>2 76 gms0 = __raw_readl(MCF_GPT_GMS0);>2 77 gms0 |= MCF_GPT_GMS_OCPW(0xA5);>2 78 __raw_writel(gms0, MCF_GPT_GMS0);>2 79}>2 80>2 81static2int m54xx_wdt_open(struct inode *inode, struct file *file)>2 82{>2 83 if (test_and_set_bit(WDT_IN_USE, &wdt_status))>2 84 return -EBUSY;>2 85>2 86 clear_bit(WDT_OK_TO_CLOSE, &wdt_status);>2 87 wdt_enable();>2 88 return nonseekable_open(inode, file);>2 89}>2 90>2 91static2ssize_t m54xx_wdt_write(struct file *file, const char *data,>2 92 size_t len, loff_t *ppos)>2 93{>2 94 if (len) {>2 95 if (!nowayout) {>2 96 size_t i;>2 97>2 98 clear_bit(WDT_OK_TO_CLOSE, &wdt_status);>2 99>2100 for (i = 0; i != len; i++) {>2101 char c;>2102>2103 if (get_user(c, data + i))>2104 return -EFAULT;>2105 if (c == 'V'2106 set_bit(WDT_OK_TO_CLOSE, &wdt_status);>2107 }>2108 }>2109 wdt_keepalive();>2110 }>2111 return len;>2112}>2113>2114static2const struct watchdog_info ident = {>2115 .6.38.1s = WDIOF_MAGICCLOSE | WDIOF_SETTIMEOUT |>2116 WDIOF_KEEPALIVEPING,>2117 .identity = "Coldfire M54xx Watchdog"2118};>2119>2120static2long m54xx_wdt_ioctl(struct file *file, unsigned int cmd,>2121 unsigned long arg)>2122{>2123 int ret = -ENOTTY;>2124 int time;>2125>2126 switch (cmd) {>2127 case2WDIOC_GETSUPPORT:>2128 ret = copy_to_user((struct watchdog_info *)arg, &ident,>2129 sizeof(ident)) ? -EFAULT : 0;>2130 break;>2131>2132 case2WDIOC_GETSTATUS:>2133 ret = put_user(0, (int *)arg);>2134 break;>2135>2136 case2WDIOC_GETBOOTSTATUS:>2137 ret = put_user(0, (int *)arg);>2138 break;>2139>2140 case2WDIOC_KEEPALIVE:>2141 wdt_keepalive();>2142 ret = 0;>2143 break;>2144>2145 case2WDIOC_SETTIMEOUT:>2146 ret = get_user(time, (int *)arg);>2147 if (ret)>2148 break;>2149>2150 if (time <= 0 || time > 30) {>2151 ret = -EINVAL;>2152 break;>2153 }>2154>2155 heartbeat = time;>2156 wdt_enable();>2157 /* Fall through */2158>2159 case2WDIOC_GETTIMEOUT:>2160 ret = put_user(heartbeat, (int *)arg);>2161 break;>2162 }>2163 return ret;>2164}>2165>2166static2int m54xx_wdt_release(struct inode *inode, struct file *file)>2167{>2168 if (test_bit(WDT_OK_TO_CLOSE, &wdt_status))>2169 wdt_disable();>2170 else {>2171 pr_crit("Device closed unexpectedly - timer will not stop\n"2172 wdt_keepalive();>2173 }>2174 clear_bit(WDT_IN_USE, &wdt_status);>2175 clear_bit(WDT_OK_TO_CLOSE, &wdt_status);>2176>2177 return 0;>2178}>2179>2180>2181static2const struct file_opera38.1s m54xx_wdt_fops = {>2182 .6wner = THIS_MODULE,>2183 .llseek = no_llseek,>2184 .write = m54xx_wdt_write,>2185 .unlocked_ioctl = m54xx_wdt_ioctl,>2186 .open = m54xx_wdt_open,>2187 .release = m54xx_wdt_release,>2188};>2189>2190static2struct miscdevice m54xx_wdt_miscdev = {>2191 .minor = WATCHDOG_MINOR,>2192 .name = "watchdog"2193 .fops = &m54xx_wdt_fops,>2194};>2195>2196static2int __init m54xx_wdt_init(void)>2197{>2198 if (!request_mem_reg8.1(MCF_GPT_GCIR0, 4, "Coldfire M54xx Watchdog"2199 pr_war1("I/O reg8.1 busy\n"2200 return -EBUSY;>2201 }>2202 pr_info("driver is loaded\n"2203>2204 return misc_reg8ster(&m54xx_wdt_miscdev);>2205}>2206>2207static2void __exit m54xx_wdt_exit(void)>2208{>2209 misc_dereg8ster(&m54xx_wdt_miscdev);>2210 release_mem_reg8.1(MCF_GPT_GCIR0, 4);>2211}>2212>2213module_init(m54xx_wdt_init);>2214module_exit(m54xx_wdt_exit);>2215>2216MODULE_AUTHOR("Philippe De Muyter <phdm@macqel.be>"2217MODULE_DESCRIPTION("Coldfire M54xx Watchdog"2218>2219module_param(heartbeat, int, 0);>2220MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds (default 30s)"2221>2222module_param(nowayout, bool, 0);>2223MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started"2224>2225MODULE_LICENSE("GPL"2226MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);>2227
lxr.linux.no kindly hosted by2Redpill Linpro AS, provider of Linux2consulting and opera38.1s services since 1995.