Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 1 | /* |
| 2 | * AppliedMicro X-Gene SoC Reboot Driver |
| 3 | * |
| 4 | * Copyright (c) 2013, Applied Micro Circuits Corporation |
| 5 | * Author: Feng Kan <fkan@apm.com> |
| 6 | * Author: Loc Ho <lho@apm.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | * |
| 23 | * This driver provides system reboot functionality for APM X-Gene SoC. |
| 24 | * For system shutdown, this is board specify. If a board designer |
| 25 | * implements GPIO shutdown, use the gpio-poweroff.c driver. |
| 26 | */ |
Guenter Roeck | 745e1976 | 2014-09-30 10:48:31 -0700 | [diff] [blame] | 27 | #include <linux/delay.h> |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 28 | #include <linux/io.h> |
Guenter Roeck | 8f57f23 | 2014-09-30 10:48:32 -0700 | [diff] [blame] | 29 | #include <linux/notifier.h> |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 30 | #include <linux/of_device.h> |
| 31 | #include <linux/of_address.h> |
| 32 | #include <linux/platform_device.h> |
Guenter Roeck | 8f57f23 | 2014-09-30 10:48:32 -0700 | [diff] [blame] | 33 | #include <linux/reboot.h> |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 34 | #include <linux/stat.h> |
| 35 | #include <linux/slab.h> |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 36 | |
| 37 | struct xgene_reboot_context { |
Guenter Roeck | 4316071 | 2014-09-30 10:48:30 -0700 | [diff] [blame] | 38 | struct device *dev; |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 39 | void *csr; |
| 40 | u32 mask; |
Guenter Roeck | 8f57f23 | 2014-09-30 10:48:32 -0700 | [diff] [blame] | 41 | struct notifier_block restart_handler; |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 42 | }; |
| 43 | |
Guenter Roeck | 8f57f23 | 2014-09-30 10:48:32 -0700 | [diff] [blame] | 44 | static int xgene_restart_handler(struct notifier_block *this, |
| 45 | unsigned long mode, void *cmd) |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 46 | { |
Guenter Roeck | 8f57f23 | 2014-09-30 10:48:32 -0700 | [diff] [blame] | 47 | struct xgene_reboot_context *ctx = |
| 48 | container_of(this, struct xgene_reboot_context, |
| 49 | restart_handler); |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 50 | |
| 51 | /* Issue the reboot */ |
Guenter Roeck | 8f57f23 | 2014-09-30 10:48:32 -0700 | [diff] [blame] | 52 | writel(ctx->mask, ctx->csr); |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 53 | |
Guenter Roeck | 745e1976 | 2014-09-30 10:48:31 -0700 | [diff] [blame] | 54 | mdelay(1000); |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 55 | |
Guenter Roeck | 4316071 | 2014-09-30 10:48:30 -0700 | [diff] [blame] | 56 | dev_emerg(ctx->dev, "Unable to restart system\n"); |
Guenter Roeck | 8f57f23 | 2014-09-30 10:48:32 -0700 | [diff] [blame] | 57 | |
| 58 | return NOTIFY_DONE; |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | static int xgene_reboot_probe(struct platform_device *pdev) |
| 62 | { |
| 63 | struct xgene_reboot_context *ctx; |
Guenter Roeck | 4316071 | 2014-09-30 10:48:30 -0700 | [diff] [blame] | 64 | struct device *dev = &pdev->dev; |
Guenter Roeck | 8f57f23 | 2014-09-30 10:48:32 -0700 | [diff] [blame] | 65 | int err; |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 66 | |
Guenter Roeck | 4316071 | 2014-09-30 10:48:30 -0700 | [diff] [blame] | 67 | ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); |
Guenter Roeck | ef288f9 | 2014-09-30 10:48:28 -0700 | [diff] [blame] | 68 | if (!ctx) |
| 69 | return -ENOMEM; |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 70 | |
Guenter Roeck | 4316071 | 2014-09-30 10:48:30 -0700 | [diff] [blame] | 71 | ctx->csr = of_iomap(dev->of_node, 0); |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 72 | if (!ctx->csr) { |
Guenter Roeck | 4316071 | 2014-09-30 10:48:30 -0700 | [diff] [blame] | 73 | dev_err(dev, "can not map resource\n"); |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 74 | return -ENODEV; |
| 75 | } |
| 76 | |
Guenter Roeck | 4316071 | 2014-09-30 10:48:30 -0700 | [diff] [blame] | 77 | if (of_property_read_u32(dev->of_node, "mask", &ctx->mask)) |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 78 | ctx->mask = 0xFFFFFFFF; |
| 79 | |
Guenter Roeck | 4316071 | 2014-09-30 10:48:30 -0700 | [diff] [blame] | 80 | ctx->dev = dev; |
Guenter Roeck | 8f57f23 | 2014-09-30 10:48:32 -0700 | [diff] [blame] | 81 | ctx->restart_handler.notifier_call = xgene_restart_handler; |
| 82 | ctx->restart_handler.priority = 128; |
| 83 | err = register_restart_handler(&ctx->restart_handler); |
Arvind Yadav | 896af83 | 2016-09-14 16:25:39 +0530 | [diff] [blame] | 84 | if (err) { |
| 85 | iounmap(ctx->csr); |
Guenter Roeck | 8f57f23 | 2014-09-30 10:48:32 -0700 | [diff] [blame] | 86 | dev_err(dev, "cannot register restart handler (err=%d)\n", err); |
Arvind Yadav | 896af83 | 2016-09-14 16:25:39 +0530 | [diff] [blame] | 87 | } |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 88 | |
Guenter Roeck | 8f57f23 | 2014-09-30 10:48:32 -0700 | [diff] [blame] | 89 | return err; |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 90 | } |
| 91 | |
Fabian Frederick | 8fb0885 | 2015-03-16 20:17:12 +0100 | [diff] [blame] | 92 | static const struct of_device_id xgene_reboot_of_match[] = { |
Loc Ho | 67778e0e | 2013-07-02 14:38:58 -0600 | [diff] [blame] | 93 | { .compatible = "apm,xgene-reboot" }, |
| 94 | {} |
| 95 | }; |
| 96 | |
| 97 | static struct platform_driver xgene_reboot_driver = { |
| 98 | .probe = xgene_reboot_probe, |
| 99 | .driver = { |
| 100 | .name = "xgene-reboot", |
| 101 | .of_match_table = xgene_reboot_of_match, |
| 102 | }, |
| 103 | }; |
| 104 | |
| 105 | static int __init xgene_reboot_init(void) |
| 106 | { |
| 107 | return platform_driver_register(&xgene_reboot_driver); |
| 108 | } |
| 109 | device_initcall(xgene_reboot_init); |