| .. | .. |
|---|
| 35 | 35 | * Watchdog timer block registers. |
|---|
| 36 | 36 | */ |
|---|
| 37 | 37 | #define TIMER_CTRL 0x0000 |
|---|
| 38 | | -#define TIMER_A370_STATUS 0x04 |
|---|
| 38 | +#define TIMER1_FIXED_ENABLE_BIT BIT(12) |
|---|
| 39 | +#define WDT_AXP_FIXED_ENABLE_BIT BIT(10) |
|---|
| 40 | +#define TIMER1_ENABLE_BIT BIT(2) |
|---|
| 41 | + |
|---|
| 42 | +#define TIMER_A370_STATUS 0x0004 |
|---|
| 43 | +#define WDT_A370_EXPIRED BIT(31) |
|---|
| 44 | +#define TIMER1_STATUS_BIT BIT(8) |
|---|
| 45 | + |
|---|
| 46 | +#define TIMER1_VAL_OFF 0x001c |
|---|
| 39 | 47 | |
|---|
| 40 | 48 | #define WDT_MAX_CYCLE_COUNT 0xffffffff |
|---|
| 41 | 49 | |
|---|
| .. | .. |
|---|
| 43 | 51 | #define WDT_A370_RATIO_SHIFT 5 |
|---|
| 44 | 52 | #define WDT_A370_RATIO (1 << WDT_A370_RATIO_SHIFT) |
|---|
| 45 | 53 | |
|---|
| 46 | | -#define WDT_AXP_FIXED_ENABLE_BIT BIT(10) |
|---|
| 47 | | -#define WDT_A370_EXPIRED BIT(31) |
|---|
| 48 | | - |
|---|
| 49 | 54 | static bool nowayout = WATCHDOG_NOWAYOUT; |
|---|
| 50 | | -static int heartbeat = -1; /* module parameter (seconds) */ |
|---|
| 55 | +static int heartbeat; /* module parameter (seconds) */ |
|---|
| 51 | 56 | |
|---|
| 52 | 57 | struct orion_watchdog; |
|---|
| 53 | 58 | |
|---|
| .. | .. |
|---|
| 158 | 163 | struct orion_watchdog *dev) |
|---|
| 159 | 164 | { |
|---|
| 160 | 165 | int ret; |
|---|
| 166 | + u32 val; |
|---|
| 161 | 167 | |
|---|
| 162 | 168 | dev->clk = of_clk_get_by_name(pdev->dev.of_node, "fixed"); |
|---|
| 163 | 169 | if (IS_ERR(dev->clk)) |
|---|
| .. | .. |
|---|
| 168 | 174 | return ret; |
|---|
| 169 | 175 | } |
|---|
| 170 | 176 | |
|---|
| 171 | | - /* Enable the fixed watchdog clock input */ |
|---|
| 172 | | - atomic_io_modify(dev->reg + TIMER_CTRL, |
|---|
| 173 | | - WDT_AXP_FIXED_ENABLE_BIT, |
|---|
| 174 | | - WDT_AXP_FIXED_ENABLE_BIT); |
|---|
| 177 | + /* Fix the wdt and timer1 clock freqency to 25MHz */ |
|---|
| 178 | + val = WDT_AXP_FIXED_ENABLE_BIT | TIMER1_FIXED_ENABLE_BIT; |
|---|
| 179 | + atomic_io_modify(dev->reg + TIMER_CTRL, val, val); |
|---|
| 175 | 180 | |
|---|
| 176 | 181 | dev->clk_rate = clk_get_rate(dev->clk); |
|---|
| 177 | 182 | return 0; |
|---|
| .. | .. |
|---|
| 183 | 188 | /* Reload watchdog duration */ |
|---|
| 184 | 189 | writel(dev->clk_rate * wdt_dev->timeout, |
|---|
| 185 | 190 | dev->reg + dev->data->wdt_counter_offset); |
|---|
| 191 | + if (dev->wdt.info->options & WDIOF_PRETIMEOUT) |
|---|
| 192 | + writel(dev->clk_rate * (wdt_dev->timeout - wdt_dev->pretimeout), |
|---|
| 193 | + dev->reg + TIMER1_VAL_OFF); |
|---|
| 194 | + |
|---|
| 186 | 195 | return 0; |
|---|
| 187 | 196 | } |
|---|
| 188 | 197 | |
|---|
| .. | .. |
|---|
| 194 | 203 | /* Set watchdog duration */ |
|---|
| 195 | 204 | writel(dev->clk_rate * wdt_dev->timeout, |
|---|
| 196 | 205 | dev->reg + dev->data->wdt_counter_offset); |
|---|
| 206 | + if (dev->wdt.info->options & WDIOF_PRETIMEOUT) |
|---|
| 207 | + writel(dev->clk_rate * (wdt_dev->timeout - wdt_dev->pretimeout), |
|---|
| 208 | + dev->reg + TIMER1_VAL_OFF); |
|---|
| 197 | 209 | |
|---|
| 198 | 210 | /* Clear the watchdog expiration bit */ |
|---|
| 199 | 211 | atomic_io_modify(dev->reg + TIMER_A370_STATUS, WDT_A370_EXPIRED, 0); |
|---|
| 200 | 212 | |
|---|
| 201 | 213 | /* Enable watchdog timer */ |
|---|
| 202 | | - atomic_io_modify(dev->reg + TIMER_CTRL, dev->data->wdt_enable_bit, |
|---|
| 203 | | - dev->data->wdt_enable_bit); |
|---|
| 214 | + reg = dev->data->wdt_enable_bit; |
|---|
| 215 | + if (dev->wdt.info->options & WDIOF_PRETIMEOUT) |
|---|
| 216 | + reg |= TIMER1_ENABLE_BIT; |
|---|
| 217 | + atomic_io_modify(dev->reg + TIMER_CTRL, reg, reg); |
|---|
| 204 | 218 | |
|---|
| 205 | 219 | /* Enable reset on watchdog */ |
|---|
| 206 | 220 | reg = readl(dev->rstout); |
|---|
| .. | .. |
|---|
| 277 | 291 | static int armada375_stop(struct watchdog_device *wdt_dev) |
|---|
| 278 | 292 | { |
|---|
| 279 | 293 | struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev); |
|---|
| 280 | | - u32 reg; |
|---|
| 294 | + u32 reg, mask; |
|---|
| 281 | 295 | |
|---|
| 282 | 296 | /* Disable reset on watchdog */ |
|---|
| 283 | 297 | atomic_io_modify(dev->rstout_mask, dev->data->rstout_mask_bit, |
|---|
| .. | .. |
|---|
| 287 | 301 | writel(reg, dev->rstout); |
|---|
| 288 | 302 | |
|---|
| 289 | 303 | /* Disable watchdog timer */ |
|---|
| 290 | | - atomic_io_modify(dev->reg + TIMER_CTRL, dev->data->wdt_enable_bit, 0); |
|---|
| 304 | + mask = dev->data->wdt_enable_bit; |
|---|
| 305 | + if (wdt_dev->info->options & WDIOF_PRETIMEOUT) |
|---|
| 306 | + mask |= TIMER1_ENABLE_BIT; |
|---|
| 307 | + atomic_io_modify(dev->reg + TIMER_CTRL, mask, 0); |
|---|
| 291 | 308 | |
|---|
| 292 | 309 | return 0; |
|---|
| 293 | 310 | } |
|---|
| .. | .. |
|---|
| 349 | 366 | return readl(dev->reg + dev->data->wdt_counter_offset) / dev->clk_rate; |
|---|
| 350 | 367 | } |
|---|
| 351 | 368 | |
|---|
| 352 | | -static int orion_wdt_set_timeout(struct watchdog_device *wdt_dev, |
|---|
| 353 | | - unsigned int timeout) |
|---|
| 354 | | -{ |
|---|
| 355 | | - wdt_dev->timeout = timeout; |
|---|
| 356 | | - return 0; |
|---|
| 357 | | -} |
|---|
| 358 | | - |
|---|
| 359 | | -static const struct watchdog_info orion_wdt_info = { |
|---|
| 369 | +static struct watchdog_info orion_wdt_info = { |
|---|
| 360 | 370 | .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE, |
|---|
| 361 | 371 | .identity = "Orion Watchdog", |
|---|
| 362 | 372 | }; |
|---|
| .. | .. |
|---|
| 366 | 376 | .start = orion_wdt_start, |
|---|
| 367 | 377 | .stop = orion_wdt_stop, |
|---|
| 368 | 378 | .ping = orion_wdt_ping, |
|---|
| 369 | | - .set_timeout = orion_wdt_set_timeout, |
|---|
| 370 | 379 | .get_timeleft = orion_wdt_get_timeleft, |
|---|
| 371 | 380 | }; |
|---|
| 372 | 381 | |
|---|
| 373 | 382 | static irqreturn_t orion_wdt_irq(int irq, void *devid) |
|---|
| 374 | 383 | { |
|---|
| 375 | 384 | panic("Watchdog Timeout"); |
|---|
| 385 | + return IRQ_HANDLED; |
|---|
| 386 | +} |
|---|
| 387 | + |
|---|
| 388 | +static irqreturn_t orion_wdt_pre_irq(int irq, void *devid) |
|---|
| 389 | +{ |
|---|
| 390 | + struct orion_watchdog *dev = devid; |
|---|
| 391 | + |
|---|
| 392 | + atomic_io_modify(dev->reg + TIMER_A370_STATUS, |
|---|
| 393 | + TIMER1_STATUS_BIT, 0); |
|---|
| 394 | + watchdog_notify_pretimeout(&dev->wdt); |
|---|
| 376 | 395 | return IRQ_HANDLED; |
|---|
| 377 | 396 | } |
|---|
| 378 | 397 | |
|---|
| .. | .. |
|---|
| 502 | 521 | of_device_is_compatible(node, "marvell,armada-xp-wdt")) { |
|---|
| 503 | 522 | |
|---|
| 504 | 523 | /* Dedicated RSTOUT register, can be requested. */ |
|---|
| 505 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
|---|
| 506 | | - dev->rstout = devm_ioremap_resource(&pdev->dev, res); |
|---|
| 524 | + dev->rstout = devm_platform_ioremap_resource(pdev, 1); |
|---|
| 507 | 525 | if (IS_ERR(dev->rstout)) |
|---|
| 508 | 526 | return PTR_ERR(dev->rstout); |
|---|
| 509 | 527 | |
|---|
| .. | .. |
|---|
| 511 | 529 | of_device_is_compatible(node, "marvell,armada-380-wdt")) { |
|---|
| 512 | 530 | |
|---|
| 513 | 531 | /* Dedicated RSTOUT register, can be requested. */ |
|---|
| 514 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
|---|
| 515 | | - dev->rstout = devm_ioremap_resource(&pdev->dev, res); |
|---|
| 532 | + dev->rstout = devm_platform_ioremap_resource(pdev, 1); |
|---|
| 516 | 533 | if (IS_ERR(dev->rstout)) |
|---|
| 517 | 534 | return PTR_ERR(dev->rstout); |
|---|
| 518 | 535 | |
|---|
| .. | .. |
|---|
| 585 | 602 | set_bit(WDOG_HW_RUNNING, &dev->wdt.status); |
|---|
| 586 | 603 | |
|---|
| 587 | 604 | /* Request the IRQ only after the watchdog is disabled */ |
|---|
| 588 | | - irq = platform_get_irq(pdev, 0); |
|---|
| 605 | + irq = platform_get_irq_optional(pdev, 0); |
|---|
| 589 | 606 | if (irq > 0) { |
|---|
| 590 | 607 | /* |
|---|
| 591 | 608 | * Not all supported platforms specify an interrupt for the |
|---|
| .. | .. |
|---|
| 599 | 616 | } |
|---|
| 600 | 617 | } |
|---|
| 601 | 618 | |
|---|
| 619 | + /* Optional 2nd interrupt for pretimeout */ |
|---|
| 620 | + irq = platform_get_irq_optional(pdev, 1); |
|---|
| 621 | + if (irq > 0) { |
|---|
| 622 | + orion_wdt_info.options |= WDIOF_PRETIMEOUT; |
|---|
| 623 | + ret = devm_request_irq(&pdev->dev, irq, orion_wdt_pre_irq, |
|---|
| 624 | + 0, pdev->name, dev); |
|---|
| 625 | + if (ret < 0) { |
|---|
| 626 | + dev_err(&pdev->dev, "failed to request IRQ\n"); |
|---|
| 627 | + goto disable_clk; |
|---|
| 628 | + } |
|---|
| 629 | + } |
|---|
| 630 | + |
|---|
| 631 | + |
|---|
| 602 | 632 | watchdog_set_nowayout(&dev->wdt, nowayout); |
|---|
| 603 | 633 | ret = watchdog_register_device(&dev->wdt); |
|---|
| 604 | 634 | if (ret) |
|---|