Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * mpc8xx_wdt.c - MPC8xx watchdog userspace interface |
| 3 | * |
| 4 | * Author: Florian Schirmer <jolt@tuxbox.org> |
| 5 | * |
| 6 | * 2002 (c) Florian Schirmer <jolt@tuxbox.org> This file is licensed under |
| 7 | * the terms of the GNU General Public License version 2. This program |
| 8 | * is licensed "as is" without any warranty of any kind, whether express |
| 9 | * or implied. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/config.h> |
| 13 | #include <linux/fs.h> |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/miscdevice.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/watchdog.h> |
| 19 | #include <asm/8xx_immap.h> |
| 20 | #include <asm/uaccess.h> |
Marcelo Tosatti | 398f685 | 2005-12-05 19:31:36 -0200 | [diff] [blame^] | 21 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <syslib/m8xx_wdt.h> |
| 23 | |
| 24 | static unsigned long wdt_opened; |
| 25 | static int wdt_status; |
| 26 | |
| 27 | static void mpc8xx_wdt_handler_disable(void) |
| 28 | { |
Marcelo Tosatti | 398f685 | 2005-12-05 19:31:36 -0200 | [diff] [blame^] | 29 | volatile uint __iomem *piscr; |
| 30 | piscr = (uint *)&((immap_t*)IMAP_ADDR)->im_sit.sit_piscr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
Marcelo Tosatti | fb64c24 | 2005-11-24 11:32:09 -0200 | [diff] [blame] | 32 | if (!m8xx_has_internal_rtc) |
| 33 | m8xx_wdt_stop_timer(); |
| 34 | else |
Marcelo Tosatti | 398f685 | 2005-12-05 19:31:36 -0200 | [diff] [blame^] | 35 | out_be32(piscr, in_be32(piscr) & ~(PISCR_PIE | PISCR_PTE)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | printk(KERN_NOTICE "mpc8xx_wdt: keep-alive handler deactivated\n"); |
| 38 | } |
| 39 | |
| 40 | static void mpc8xx_wdt_handler_enable(void) |
| 41 | { |
Marcelo Tosatti | 398f685 | 2005-12-05 19:31:36 -0200 | [diff] [blame^] | 42 | volatile uint __iomem *piscr; |
| 43 | piscr = (uint *)&((immap_t*)IMAP_ADDR)->im_sit.sit_piscr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
Marcelo Tosatti | fb64c24 | 2005-11-24 11:32:09 -0200 | [diff] [blame] | 45 | if (!m8xx_has_internal_rtc) |
| 46 | m8xx_wdt_install_timer(); |
| 47 | else |
Marcelo Tosatti | 398f685 | 2005-12-05 19:31:36 -0200 | [diff] [blame^] | 48 | out_be32(piscr, in_be32(piscr) | PISCR_PIE | PISCR_PTE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
| 50 | printk(KERN_NOTICE "mpc8xx_wdt: keep-alive handler activated\n"); |
| 51 | } |
| 52 | |
| 53 | static int mpc8xx_wdt_open(struct inode *inode, struct file *file) |
| 54 | { |
| 55 | if (test_and_set_bit(0, &wdt_opened)) |
| 56 | return -EBUSY; |
| 57 | |
| 58 | m8xx_wdt_reset(); |
| 59 | mpc8xx_wdt_handler_disable(); |
| 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | static int mpc8xx_wdt_release(struct inode *inode, struct file *file) |
| 65 | { |
| 66 | m8xx_wdt_reset(); |
| 67 | |
| 68 | #if !defined(CONFIG_WATCHDOG_NOWAYOUT) |
| 69 | mpc8xx_wdt_handler_enable(); |
| 70 | #endif |
| 71 | |
| 72 | clear_bit(0, &wdt_opened); |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | static ssize_t mpc8xx_wdt_write(struct file *file, const char *data, size_t len, |
| 78 | loff_t * ppos) |
| 79 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | if (len) |
| 81 | m8xx_wdt_reset(); |
| 82 | |
| 83 | return len; |
| 84 | } |
| 85 | |
| 86 | static int mpc8xx_wdt_ioctl(struct inode *inode, struct file *file, |
| 87 | unsigned int cmd, unsigned long arg) |
| 88 | { |
| 89 | int timeout; |
| 90 | static struct watchdog_info info = { |
| 91 | .options = WDIOF_KEEPALIVEPING, |
| 92 | .firmware_version = 0, |
| 93 | .identity = "MPC8xx watchdog", |
| 94 | }; |
| 95 | |
| 96 | switch (cmd) { |
| 97 | case WDIOC_GETSUPPORT: |
| 98 | if (copy_to_user((void *)arg, &info, sizeof(info))) |
| 99 | return -EFAULT; |
| 100 | break; |
| 101 | |
| 102 | case WDIOC_GETSTATUS: |
| 103 | case WDIOC_GETBOOTSTATUS: |
| 104 | if (put_user(wdt_status, (int *)arg)) |
| 105 | return -EFAULT; |
| 106 | wdt_status &= ~WDIOF_KEEPALIVEPING; |
| 107 | break; |
| 108 | |
| 109 | case WDIOC_GETTEMP: |
| 110 | return -EOPNOTSUPP; |
| 111 | |
| 112 | case WDIOC_SETOPTIONS: |
| 113 | return -EOPNOTSUPP; |
| 114 | |
| 115 | case WDIOC_KEEPALIVE: |
| 116 | m8xx_wdt_reset(); |
| 117 | wdt_status |= WDIOF_KEEPALIVEPING; |
| 118 | break; |
| 119 | |
| 120 | case WDIOC_SETTIMEOUT: |
| 121 | return -EOPNOTSUPP; |
| 122 | |
| 123 | case WDIOC_GETTIMEOUT: |
| 124 | timeout = m8xx_wdt_get_timeout(); |
| 125 | if (put_user(timeout, (int *)arg)) |
| 126 | return -EFAULT; |
| 127 | break; |
| 128 | |
| 129 | default: |
| 130 | return -ENOIOCTLCMD; |
| 131 | } |
| 132 | |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | static struct file_operations mpc8xx_wdt_fops = { |
| 137 | .owner = THIS_MODULE, |
| 138 | .llseek = no_llseek, |
| 139 | .write = mpc8xx_wdt_write, |
| 140 | .ioctl = mpc8xx_wdt_ioctl, |
| 141 | .open = mpc8xx_wdt_open, |
| 142 | .release = mpc8xx_wdt_release, |
| 143 | }; |
| 144 | |
| 145 | static struct miscdevice mpc8xx_wdt_miscdev = { |
| 146 | .minor = WATCHDOG_MINOR, |
| 147 | .name = "watchdog", |
| 148 | .fops = &mpc8xx_wdt_fops, |
| 149 | }; |
| 150 | |
| 151 | static int __init mpc8xx_wdt_init(void) |
| 152 | { |
| 153 | return misc_register(&mpc8xx_wdt_miscdev); |
| 154 | } |
| 155 | |
| 156 | static void __exit mpc8xx_wdt_exit(void) |
| 157 | { |
| 158 | misc_deregister(&mpc8xx_wdt_miscdev); |
| 159 | |
| 160 | m8xx_wdt_reset(); |
| 161 | mpc8xx_wdt_handler_enable(); |
| 162 | } |
| 163 | |
| 164 | module_init(mpc8xx_wdt_init); |
| 165 | module_exit(mpc8xx_wdt_exit); |
| 166 | |
| 167 | MODULE_AUTHOR("Florian Schirmer <jolt@tuxbox.org>"); |
| 168 | MODULE_DESCRIPTION("MPC8xx watchdog driver"); |
| 169 | MODULE_LICENSE("GPL"); |
| 170 | MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); |