This source file includes following definitions.
- ts4800_write_feed
- ts4800_wdt_start
- ts4800_wdt_stop
- ts4800_wdt_set_timeout
- ts4800_wdt_probe
   1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 
  10 
  11 #include <linux/kernel.h>
  12 #include <linux/mfd/syscon.h>
  13 #include <linux/module.h>
  14 #include <linux/of.h>
  15 #include <linux/platform_device.h>
  16 #include <linux/regmap.h>
  17 #include <linux/watchdog.h>
  18 
  19 static bool nowayout = WATCHDOG_NOWAYOUT;
  20 module_param(nowayout, bool, 0);
  21 MODULE_PARM_DESC(nowayout,
  22         "Watchdog cannot be stopped once started (default="
  23         __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
  24 
  25 
  26 #define TS4800_WDT_FEED_2S       0x1
  27 #define TS4800_WDT_FEED_10S      0x2
  28 #define TS4800_WDT_DISABLE       0x3
  29 
  30 struct ts4800_wdt {
  31         struct watchdog_device  wdd;
  32         struct regmap           *regmap;
  33         u32                     feed_offset;
  34         u32                     feed_val;
  35 };
  36 
  37 
  38 
  39 
  40 
  41 
  42 
  43 
  44 
  45 
  46 
  47 
  48 
  49 static const struct {
  50         const int timeout;
  51         const int regval;
  52 } ts4800_wdt_map[] = {
  53         { 2,  TS4800_WDT_FEED_2S },
  54         { 10, TS4800_WDT_FEED_10S },
  55 };
  56 
  57 #define MAX_TIMEOUT_INDEX       (ARRAY_SIZE(ts4800_wdt_map) - 1)
  58 
  59 static void ts4800_write_feed(struct ts4800_wdt *wdt, u32 val)
  60 {
  61         regmap_write(wdt->regmap, wdt->feed_offset, val);
  62 }
  63 
  64 static int ts4800_wdt_start(struct watchdog_device *wdd)
  65 {
  66         struct ts4800_wdt *wdt = watchdog_get_drvdata(wdd);
  67 
  68         ts4800_write_feed(wdt, wdt->feed_val);
  69         return 0;
  70 }
  71 
  72 static int ts4800_wdt_stop(struct watchdog_device *wdd)
  73 {
  74         struct ts4800_wdt *wdt = watchdog_get_drvdata(wdd);
  75 
  76         ts4800_write_feed(wdt, TS4800_WDT_DISABLE);
  77         return 0;
  78 }
  79 
  80 static int ts4800_wdt_set_timeout(struct watchdog_device *wdd,
  81                                   unsigned int timeout)
  82 {
  83         struct ts4800_wdt *wdt = watchdog_get_drvdata(wdd);
  84         int i;
  85 
  86         for (i = 0; i < MAX_TIMEOUT_INDEX; i++) {
  87                 if (ts4800_wdt_map[i].timeout >= timeout)
  88                         break;
  89         }
  90 
  91         wdd->timeout = ts4800_wdt_map[i].timeout;
  92         wdt->feed_val = ts4800_wdt_map[i].regval;
  93 
  94         return 0;
  95 }
  96 
  97 static const struct watchdog_ops ts4800_wdt_ops = {
  98         .owner = THIS_MODULE,
  99         .start = ts4800_wdt_start,
 100         .stop = ts4800_wdt_stop,
 101         .set_timeout = ts4800_wdt_set_timeout,
 102 };
 103 
 104 static const struct watchdog_info ts4800_wdt_info = {
 105         .options = WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING,
 106         .identity = "TS-4800 Watchdog",
 107 };
 108 
 109 static int ts4800_wdt_probe(struct platform_device *pdev)
 110 {
 111         struct device *dev = &pdev->dev;
 112         struct device_node *np = dev->of_node;
 113         struct device_node *syscon_np;
 114         struct watchdog_device *wdd;
 115         struct ts4800_wdt *wdt;
 116         u32 reg;
 117         int ret;
 118 
 119         syscon_np = of_parse_phandle(np, "syscon", 0);
 120         if (!syscon_np) {
 121                 dev_err(dev, "no syscon property\n");
 122                 return -ENODEV;
 123         }
 124 
 125         ret = of_property_read_u32_index(np, "syscon", 1, ®);
 126         if (ret < 0) {
 127                 dev_err(dev, "no offset in syscon\n");
 128                 return ret;
 129         }
 130 
 131         
 132         wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL);
 133         if (!wdt)
 134                 return -ENOMEM;
 135 
 136         
 137         wdt->feed_offset = reg;
 138         wdt->regmap = syscon_node_to_regmap(syscon_np);
 139         of_node_put(syscon_np);
 140         if (IS_ERR(wdt->regmap)) {
 141                 dev_err(dev, "cannot get parent's regmap\n");
 142                 return PTR_ERR(wdt->regmap);
 143         }
 144 
 145         
 146         wdd = &wdt->wdd;
 147         wdd->parent = dev;
 148         wdd->info = &ts4800_wdt_info;
 149         wdd->ops = &ts4800_wdt_ops;
 150         wdd->min_timeout = ts4800_wdt_map[0].timeout;
 151         wdd->max_timeout = ts4800_wdt_map[MAX_TIMEOUT_INDEX].timeout;
 152 
 153         watchdog_set_drvdata(wdd, wdt);
 154         watchdog_set_nowayout(wdd, nowayout);
 155         watchdog_init_timeout(wdd, 0, dev);
 156 
 157         
 158 
 159 
 160 
 161 
 162 
 163         if (!wdd->timeout)
 164                 wdd->timeout = wdd->max_timeout;
 165         ts4800_wdt_set_timeout(wdd, wdd->timeout);
 166 
 167         
 168 
 169 
 170 
 171         ts4800_wdt_stop(wdd);
 172 
 173         ret = devm_watchdog_register_device(dev, wdd);
 174         if (ret)
 175                 return ret;
 176 
 177         platform_set_drvdata(pdev, wdt);
 178 
 179         dev_info(dev, "initialized (timeout = %d sec, nowayout = %d)\n",
 180                  wdd->timeout, nowayout);
 181 
 182         return 0;
 183 }
 184 
 185 static const struct of_device_id ts4800_wdt_of_match[] = {
 186         { .compatible = "technologic,ts4800-wdt", },
 187         { },
 188 };
 189 MODULE_DEVICE_TABLE(of, ts4800_wdt_of_match);
 190 
 191 static struct platform_driver ts4800_wdt_driver = {
 192         .probe          = ts4800_wdt_probe,
 193         .driver         = {
 194                 .name   = "ts4800_wdt",
 195                 .of_match_table = ts4800_wdt_of_match,
 196         },
 197 };
 198 
 199 module_platform_driver(ts4800_wdt_driver);
 200 
 201 MODULE_AUTHOR("Damien Riegel <damien.riegel@savoirfairelinux.com>");
 202 MODULE_LICENSE("GPL v2");
 203 MODULE_ALIAS("platform:ts4800_wdt");