Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 2 | /* |
| 3 | * AppliedMicro X-Gene SoC Reboot Driver |
| 4 | * |
| 5 | * Copyright (c) 2013, Applied Micro Circuits Corporation |
| 6 | * Author: Feng Kan <fkan@apm.com> |
| 7 | * Author: Loc Ho <lho@apm.com> |
| 8 | * |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 9 | * This driver provides system reboot functionality for APM X-Gene SoC. |
| 10 | * For system shutdown, this is board specify. If a board designer |
| 11 | * implements GPIO shutdown, use the gpio-poweroff.c driver. |
| 12 | */ |
Guenter Roeck | 745e1976 | 2014-09-30 10:48:31 -0700 | [diff] [blame] | 13 | #include <linux/delay.h> |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 14 | #include <linux/io.h> |
Guenter Roeck | 8f57f23 | 2014-09-30 10:48:32 -0700 | [diff] [blame] | 15 | #include <linux/notifier.h> |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 16 | #include <linux/of_device.h> |
| 17 | #include <linux/of_address.h> |
| 18 | #include <linux/platform_device.h> |
Guenter Roeck | 8f57f23 | 2014-09-30 10:48:32 -0700 | [diff] [blame] | 19 | #include <linux/reboot.h> |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 20 | #include <linux/stat.h> |
| 21 | #include <linux/slab.h> |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 22 | |
| 23 | struct xgene_reboot_context { |
Guenter Roeck | 4316071 | 2014-09-30 10:48:30 -0700 | [diff] [blame] | 24 | struct device *dev; |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 25 | void *csr; |
| 26 | u32 mask; |
Guenter Roeck | 8f57f23 | 2014-09-30 10:48:32 -0700 | [diff] [blame] | 27 | struct notifier_block restart_handler; |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 28 | }; |
| 29 | |
Guenter Roeck | 8f57f23 | 2014-09-30 10:48:32 -0700 | [diff] [blame] | 30 | static int xgene_restart_handler(struct notifier_block *this, |
| 31 | unsigned long mode, void *cmd) |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 32 | { |
Guenter Roeck | 8f57f23 | 2014-09-30 10:48:32 -0700 | [diff] [blame] | 33 | struct xgene_reboot_context *ctx = |
| 34 | container_of(this, struct xgene_reboot_context, |
| 35 | restart_handler); |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 36 | |
| 37 | /* Issue the reboot */ |
Guenter Roeck | 8f57f23 | 2014-09-30 10:48:32 -0700 | [diff] [blame] | 38 | writel(ctx->mask, ctx->csr); |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 39 | |
Guenter Roeck | 745e1976 | 2014-09-30 10:48:31 -0700 | [diff] [blame] | 40 | mdelay(1000); |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 41 | |
Guenter Roeck | 4316071 | 2014-09-30 10:48:30 -0700 | [diff] [blame] | 42 | dev_emerg(ctx->dev, "Unable to restart system\n"); |
Guenter Roeck | 8f57f23 | 2014-09-30 10:48:32 -0700 | [diff] [blame] | 43 | |
| 44 | return NOTIFY_DONE; |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | static int xgene_reboot_probe(struct platform_device *pdev) |
| 48 | { |
| 49 | struct xgene_reboot_context *ctx; |
Guenter Roeck | 4316071 | 2014-09-30 10:48:30 -0700 | [diff] [blame] | 50 | struct device *dev = &pdev->dev; |
Guenter Roeck | 8f57f23 | 2014-09-30 10:48:32 -0700 | [diff] [blame] | 51 | int err; |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 52 | |
Guenter Roeck | 4316071 | 2014-09-30 10:48:30 -0700 | [diff] [blame] | 53 | ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); |
Guenter Roeck | ef288f9 | 2014-09-30 10:48:28 -0700 | [diff] [blame] | 54 | if (!ctx) |
| 55 | return -ENOMEM; |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 56 | |
Guenter Roeck | 4316071 | 2014-09-30 10:48:30 -0700 | [diff] [blame] | 57 | ctx->csr = of_iomap(dev->of_node, 0); |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 58 | if (!ctx->csr) { |
Guenter Roeck | 4316071 | 2014-09-30 10:48:30 -0700 | [diff] [blame] | 59 | dev_err(dev, "can not map resource\n"); |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 60 | return -ENODEV; |
| 61 | } |
| 62 | |
Guenter Roeck | 4316071 | 2014-09-30 10:48:30 -0700 | [diff] [blame] | 63 | if (of_property_read_u32(dev->of_node, "mask", &ctx->mask)) |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 64 | ctx->mask = 0xFFFFFFFF; |
| 65 | |
Guenter Roeck | 4316071 | 2014-09-30 10:48:30 -0700 | [diff] [blame] | 66 | ctx->dev = dev; |
Guenter Roeck | 8f57f23 | 2014-09-30 10:48:32 -0700 | [diff] [blame] | 67 | ctx->restart_handler.notifier_call = xgene_restart_handler; |
| 68 | ctx->restart_handler.priority = 128; |
| 69 | err = register_restart_handler(&ctx->restart_handler); |
Arvind Yadav | 896af83 | 2016-09-14 16:25:39 +0530 | [diff] [blame] | 70 | if (err) { |
| 71 | iounmap(ctx->csr); |
Guenter Roeck | 8f57f23 | 2014-09-30 10:48:32 -0700 | [diff] [blame] | 72 | dev_err(dev, "cannot register restart handler (err=%d)\n", err); |
Arvind Yadav | 896af83 | 2016-09-14 16:25:39 +0530 | [diff] [blame] | 73 | } |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 74 | |
Guenter Roeck | 8f57f23 | 2014-09-30 10:48:32 -0700 | [diff] [blame] | 75 | return err; |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 76 | } |
| 77 | |
Fabian Frederick | 8fb0885 | 2015-03-16 20:17:12 +0100 | [diff] [blame] | 78 | static const struct of_device_id xgene_reboot_of_match[] = { |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 79 | { .compatible = "apm,xgene-reboot" }, |
| 80 | {} |
| 81 | }; |
| 82 | |
| 83 | static struct platform_driver xgene_reboot_driver = { |
| 84 | .probe = xgene_reboot_probe, |
| 85 | .driver = { |
| 86 | .name = "xgene-reboot", |
| 87 | .of_match_table = xgene_reboot_of_match, |
| 88 | }, |
| 89 | }; |
| 90 | |
| 91 | static int __init xgene_reboot_init(void) |
| 92 | { |
| 93 | return platform_driver_register(&xgene_reboot_driver); |
| 94 | } |
| 95 | device_initcall(xgene_reboot_init); |