Timo Kokkonen | 80e45b1 | 2009-03-27 16:42:17 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) Nokia Corporation |
| 3 | * |
| 4 | * Written by Timo Kokkonen <timo.t.kokkonen at nokia.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 20 | |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/types.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 23 | #include <linux/slab.h> |
Timo Kokkonen | 80e45b1 | 2009-03-27 16:42:17 +0200 | [diff] [blame] | 24 | #include <linux/kernel.h> |
Timo Kokkonen | 80e45b1 | 2009-03-27 16:42:17 +0200 | [diff] [blame] | 25 | #include <linux/watchdog.h> |
| 26 | #include <linux/platform_device.h> |
Santosh Shilimkar | b07682b | 2009-12-13 20:05:51 +0100 | [diff] [blame] | 27 | #include <linux/i2c/twl.h> |
Timo Kokkonen | 80e45b1 | 2009-03-27 16:42:17 +0200 | [diff] [blame] | 28 | |
| 29 | #define TWL4030_WATCHDOG_CFG_REG_OFFS 0x3 |
| 30 | |
Wim Van Sebroeck | 86a1e18 | 2012-03-05 16:51:11 +0100 | [diff] [blame] | 31 | static bool nowayout = WATCHDOG_NOWAYOUT; |
| 32 | module_param(nowayout, bool, 0); |
Timo Kokkonen | 80e45b1 | 2009-03-27 16:42:17 +0200 | [diff] [blame] | 33 | MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started " |
| 34 | "(default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); |
| 35 | |
| 36 | static int twl4030_wdt_write(unsigned char val) |
| 37 | { |
Peter Ujfalusi | 2bc3f62 | 2012-11-13 10:40:22 +0100 | [diff] [blame] | 38 | return twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, val, |
Timo Kokkonen | 80e45b1 | 2009-03-27 16:42:17 +0200 | [diff] [blame] | 39 | TWL4030_WATCHDOG_CFG_REG_OFFS); |
| 40 | } |
| 41 | |
Jarkko Nikula | b2c4e4b | 2012-09-11 09:01:10 +0300 | [diff] [blame] | 42 | static int twl4030_wdt_start(struct watchdog_device *wdt) |
Timo Kokkonen | 80e45b1 | 2009-03-27 16:42:17 +0200 | [diff] [blame] | 43 | { |
Jarkko Nikula | b2c4e4b | 2012-09-11 09:01:10 +0300 | [diff] [blame] | 44 | return twl4030_wdt_write(wdt->timeout + 1); |
Timo Kokkonen | 80e45b1 | 2009-03-27 16:42:17 +0200 | [diff] [blame] | 45 | } |
| 46 | |
Jarkko Nikula | b2c4e4b | 2012-09-11 09:01:10 +0300 | [diff] [blame] | 47 | static int twl4030_wdt_stop(struct watchdog_device *wdt) |
Timo Kokkonen | 80e45b1 | 2009-03-27 16:42:17 +0200 | [diff] [blame] | 48 | { |
| 49 | return twl4030_wdt_write(0); |
| 50 | } |
| 51 | |
Jarkko Nikula | b2c4e4b | 2012-09-11 09:01:10 +0300 | [diff] [blame] | 52 | static int twl4030_wdt_set_timeout(struct watchdog_device *wdt, |
| 53 | unsigned int timeout) |
Timo Kokkonen | 80e45b1 | 2009-03-27 16:42:17 +0200 | [diff] [blame] | 54 | { |
Jarkko Nikula | b2c4e4b | 2012-09-11 09:01:10 +0300 | [diff] [blame] | 55 | wdt->timeout = timeout; |
Timo Kokkonen | 80e45b1 | 2009-03-27 16:42:17 +0200 | [diff] [blame] | 56 | return 0; |
| 57 | } |
| 58 | |
Jarkko Nikula | b2c4e4b | 2012-09-11 09:01:10 +0300 | [diff] [blame] | 59 | static const struct watchdog_info twl4030_wdt_info = { |
Tony Lindgren | fb1cbea | 2014-10-14 12:25:19 -0700 | [diff] [blame] | 60 | .options = WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING, |
Jarkko Nikula | b2c4e4b | 2012-09-11 09:01:10 +0300 | [diff] [blame] | 61 | .identity = "TWL4030 Watchdog", |
| 62 | }; |
Timo Kokkonen | 80e45b1 | 2009-03-27 16:42:17 +0200 | [diff] [blame] | 63 | |
Jarkko Nikula | b2c4e4b | 2012-09-11 09:01:10 +0300 | [diff] [blame] | 64 | static const struct watchdog_ops twl4030_wdt_ops = { |
Timo Kokkonen | 80e45b1 | 2009-03-27 16:42:17 +0200 | [diff] [blame] | 65 | .owner = THIS_MODULE, |
Jarkko Nikula | b2c4e4b | 2012-09-11 09:01:10 +0300 | [diff] [blame] | 66 | .start = twl4030_wdt_start, |
| 67 | .stop = twl4030_wdt_stop, |
| 68 | .set_timeout = twl4030_wdt_set_timeout, |
Timo Kokkonen | 80e45b1 | 2009-03-27 16:42:17 +0200 | [diff] [blame] | 69 | }; |
| 70 | |
Bill Pemberton | 2d991a1 | 2012-11-19 13:21:41 -0500 | [diff] [blame] | 71 | static int twl4030_wdt_probe(struct platform_device *pdev) |
Timo Kokkonen | 80e45b1 | 2009-03-27 16:42:17 +0200 | [diff] [blame] | 72 | { |
| 73 | int ret = 0; |
Jarkko Nikula | b2c4e4b | 2012-09-11 09:01:10 +0300 | [diff] [blame] | 74 | struct watchdog_device *wdt; |
Timo Kokkonen | 80e45b1 | 2009-03-27 16:42:17 +0200 | [diff] [blame] | 75 | |
Jarkko Nikula | b2c4e4b | 2012-09-11 09:01:10 +0300 | [diff] [blame] | 76 | wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL); |
Timo Kokkonen | 80e45b1 | 2009-03-27 16:42:17 +0200 | [diff] [blame] | 77 | if (!wdt) |
| 78 | return -ENOMEM; |
| 79 | |
Jarkko Nikula | b2c4e4b | 2012-09-11 09:01:10 +0300 | [diff] [blame] | 80 | wdt->info = &twl4030_wdt_info; |
| 81 | wdt->ops = &twl4030_wdt_ops; |
| 82 | wdt->status = 0; |
| 83 | wdt->timeout = 30; |
| 84 | wdt->min_timeout = 1; |
| 85 | wdt->max_timeout = 30; |
Pratyush Anand | 6551881 | 2015-08-20 14:05:01 +0530 | [diff] [blame] | 86 | wdt->parent = &pdev->dev; |
Timo Kokkonen | 80e45b1 | 2009-03-27 16:42:17 +0200 | [diff] [blame] | 87 | |
Jarkko Nikula | b2c4e4b | 2012-09-11 09:01:10 +0300 | [diff] [blame] | 88 | watchdog_set_nowayout(wdt, nowayout); |
Timo Kokkonen | 80e45b1 | 2009-03-27 16:42:17 +0200 | [diff] [blame] | 89 | platform_set_drvdata(pdev, wdt); |
| 90 | |
Jarkko Nikula | b2c4e4b | 2012-09-11 09:01:10 +0300 | [diff] [blame] | 91 | twl4030_wdt_stop(wdt); |
Timo Kokkonen | 80e45b1 | 2009-03-27 16:42:17 +0200 | [diff] [blame] | 92 | |
Jarkko Nikula | b2c4e4b | 2012-09-11 09:01:10 +0300 | [diff] [blame] | 93 | ret = watchdog_register_device(wdt); |
Sachin Kamat | 6638f4e | 2013-05-04 01:41:18 +0530 | [diff] [blame] | 94 | if (ret) |
Timo Kokkonen | 80e45b1 | 2009-03-27 16:42:17 +0200 | [diff] [blame] | 95 | return ret; |
Jarkko Nikula | b2c4e4b | 2012-09-11 09:01:10 +0300 | [diff] [blame] | 96 | |
Timo Kokkonen | 80e45b1 | 2009-03-27 16:42:17 +0200 | [diff] [blame] | 97 | return 0; |
| 98 | } |
| 99 | |
Bill Pemberton | 4b12b89 | 2012-11-19 13:26:24 -0500 | [diff] [blame] | 100 | static int twl4030_wdt_remove(struct platform_device *pdev) |
Timo Kokkonen | 80e45b1 | 2009-03-27 16:42:17 +0200 | [diff] [blame] | 101 | { |
Jarkko Nikula | b2c4e4b | 2012-09-11 09:01:10 +0300 | [diff] [blame] | 102 | struct watchdog_device *wdt = platform_get_drvdata(pdev); |
Timo Kokkonen | 80e45b1 | 2009-03-27 16:42:17 +0200 | [diff] [blame] | 103 | |
Jarkko Nikula | b2c4e4b | 2012-09-11 09:01:10 +0300 | [diff] [blame] | 104 | watchdog_unregister_device(wdt); |
Timo Kokkonen | 80e45b1 | 2009-03-27 16:42:17 +0200 | [diff] [blame] | 105 | |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | #ifdef CONFIG_PM |
| 110 | static int twl4030_wdt_suspend(struct platform_device *pdev, pm_message_t state) |
| 111 | { |
Jarkko Nikula | b2c4e4b | 2012-09-11 09:01:10 +0300 | [diff] [blame] | 112 | struct watchdog_device *wdt = platform_get_drvdata(pdev); |
| 113 | if (watchdog_active(wdt)) |
| 114 | return twl4030_wdt_stop(wdt); |
Timo Kokkonen | 80e45b1 | 2009-03-27 16:42:17 +0200 | [diff] [blame] | 115 | |
| 116 | return 0; |
| 117 | } |
| 118 | |
| 119 | static int twl4030_wdt_resume(struct platform_device *pdev) |
| 120 | { |
Jarkko Nikula | b2c4e4b | 2012-09-11 09:01:10 +0300 | [diff] [blame] | 121 | struct watchdog_device *wdt = platform_get_drvdata(pdev); |
| 122 | if (watchdog_active(wdt)) |
| 123 | return twl4030_wdt_start(wdt); |
Timo Kokkonen | 80e45b1 | 2009-03-27 16:42:17 +0200 | [diff] [blame] | 124 | |
| 125 | return 0; |
| 126 | } |
| 127 | #else |
| 128 | #define twl4030_wdt_suspend NULL |
| 129 | #define twl4030_wdt_resume NULL |
| 130 | #endif |
| 131 | |
Aaro Koskinen | 8899b8d | 2012-12-23 22:03:37 +0200 | [diff] [blame] | 132 | static const struct of_device_id twl_wdt_of_match[] = { |
| 133 | { .compatible = "ti,twl4030-wdt", }, |
| 134 | { }, |
| 135 | }; |
| 136 | MODULE_DEVICE_TABLE(of, twl_wdt_of_match); |
| 137 | |
Timo Kokkonen | 80e45b1 | 2009-03-27 16:42:17 +0200 | [diff] [blame] | 138 | static struct platform_driver twl4030_wdt_driver = { |
| 139 | .probe = twl4030_wdt_probe, |
Bill Pemberton | 8226871 | 2012-11-19 13:21:12 -0500 | [diff] [blame] | 140 | .remove = twl4030_wdt_remove, |
Timo Kokkonen | 80e45b1 | 2009-03-27 16:42:17 +0200 | [diff] [blame] | 141 | .suspend = twl4030_wdt_suspend, |
| 142 | .resume = twl4030_wdt_resume, |
| 143 | .driver = { |
Aaro Koskinen | 8899b8d | 2012-12-23 22:03:37 +0200 | [diff] [blame] | 144 | .name = "twl4030_wdt", |
| 145 | .of_match_table = twl_wdt_of_match, |
Timo Kokkonen | 80e45b1 | 2009-03-27 16:42:17 +0200 | [diff] [blame] | 146 | }, |
| 147 | }; |
| 148 | |
Axel Lin | b8ec611 | 2011-11-29 13:56:27 +0800 | [diff] [blame] | 149 | module_platform_driver(twl4030_wdt_driver); |
Timo Kokkonen | 80e45b1 | 2009-03-27 16:42:17 +0200 | [diff] [blame] | 150 | |
| 151 | MODULE_AUTHOR("Nokia Corporation"); |
| 152 | MODULE_LICENSE("GPL"); |
Timo Kokkonen | 80e45b1 | 2009-03-27 16:42:17 +0200 | [diff] [blame] | 153 | MODULE_ALIAS("platform:twl4030_wdt"); |
| 154 | |