staging: rtl8188eu: rename HalSetBrateCfg() - style
[linux/fpc-iii.git] / drivers / power / reset / ocelot-reset.c
blob5a13a5cc818836b9d07db2eba3f5d8d1d2e3f21a
1 // SPDX-License-Identifier: (GPL-2.0 OR MIT)
2 /*
3 * Microsemi MIPS SoC reset driver
5 * License: Dual MIT/GPL
6 * Copyright (c) 2017 Microsemi Corporation
7 */
8 #include <linux/delay.h>
9 #include <linux/io.h>
10 #include <linux/notifier.h>
11 #include <linux/mfd/syscon.h>
12 #include <linux/of_address.h>
13 #include <linux/of_device.h>
14 #include <linux/platform_device.h>
15 #include <linux/reboot.h>
16 #include <linux/regmap.h>
18 struct ocelot_reset_context {
19 void __iomem *base;
20 struct regmap *cpu_ctrl;
21 struct notifier_block restart_handler;
24 #define ICPU_CFG_CPU_SYSTEM_CTRL_RESET 0x20
25 #define CORE_RST_PROTECT BIT(2)
27 #define SOFT_CHIP_RST BIT(0)
29 static int ocelot_restart_handle(struct notifier_block *this,
30 unsigned long mode, void *cmd)
32 struct ocelot_reset_context *ctx = container_of(this, struct
33 ocelot_reset_context,
34 restart_handler);
36 /* Make sure the core is not protected from reset */
37 regmap_update_bits(ctx->cpu_ctrl, ICPU_CFG_CPU_SYSTEM_CTRL_RESET,
38 CORE_RST_PROTECT, 0);
40 writel(SOFT_CHIP_RST, ctx->base);
42 pr_emerg("Unable to restart system\n");
43 return NOTIFY_DONE;
46 static int ocelot_reset_probe(struct platform_device *pdev)
48 struct ocelot_reset_context *ctx;
49 struct resource *res;
51 struct device *dev = &pdev->dev;
52 int err;
54 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
55 if (!ctx)
56 return -ENOMEM;
58 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
59 ctx->base = devm_ioremap_resource(dev, res);
60 if (IS_ERR(ctx->base))
61 return PTR_ERR(ctx->base);
63 ctx->cpu_ctrl = syscon_regmap_lookup_by_compatible("mscc,ocelot-cpu-syscon");
64 if (IS_ERR(ctx->cpu_ctrl))
65 return PTR_ERR(ctx->cpu_ctrl);
67 ctx->restart_handler.notifier_call = ocelot_restart_handle;
68 ctx->restart_handler.priority = 192;
69 err = register_restart_handler(&ctx->restart_handler);
70 if (err)
71 dev_err(dev, "can't register restart notifier (err=%d)\n", err);
73 return err;
76 static const struct of_device_id ocelot_reset_of_match[] = {
77 { .compatible = "mscc,ocelot-chip-reset" },
81 static struct platform_driver ocelot_reset_driver = {
82 .probe = ocelot_reset_probe,
83 .driver = {
84 .name = "ocelot-chip-reset",
85 .of_match_table = ocelot_reset_of_match,
88 builtin_platform_driver(ocelot_reset_driver);