treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / power / reset / syscon-reboot-mode.c
blobe0772c9f70f7a19cd8ec8a0b7fdbbaa7ba44afd0
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) 2016, Fuzhou Rockchip Electronics Co., Ltd
4 */
6 #include <linux/init.h>
7 #include <linux/module.h>
8 #include <linux/kernel.h>
9 #include <linux/of.h>
10 #include <linux/platform_device.h>
11 #include <linux/reboot.h>
12 #include <linux/regmap.h>
13 #include <linux/mfd/syscon.h>
14 #include <linux/reboot-mode.h>
16 struct syscon_reboot_mode {
17 struct regmap *map;
18 struct reboot_mode_driver reboot;
19 u32 offset;
20 u32 mask;
23 static int syscon_reboot_mode_write(struct reboot_mode_driver *reboot,
24 unsigned int magic)
26 struct syscon_reboot_mode *syscon_rbm;
27 int ret;
29 syscon_rbm = container_of(reboot, struct syscon_reboot_mode, reboot);
31 ret = regmap_update_bits(syscon_rbm->map, syscon_rbm->offset,
32 syscon_rbm->mask, magic);
33 if (ret < 0)
34 dev_err(reboot->dev, "update reboot mode bits failed\n");
36 return ret;
39 static int syscon_reboot_mode_probe(struct platform_device *pdev)
41 int ret;
42 struct syscon_reboot_mode *syscon_rbm;
44 syscon_rbm = devm_kzalloc(&pdev->dev, sizeof(*syscon_rbm), GFP_KERNEL);
45 if (!syscon_rbm)
46 return -ENOMEM;
48 syscon_rbm->reboot.dev = &pdev->dev;
49 syscon_rbm->reboot.write = syscon_reboot_mode_write;
50 syscon_rbm->mask = 0xffffffff;
52 syscon_rbm->map = syscon_node_to_regmap(pdev->dev.parent->of_node);
53 if (IS_ERR(syscon_rbm->map))
54 return PTR_ERR(syscon_rbm->map);
56 if (of_property_read_u32(pdev->dev.of_node, "offset",
57 &syscon_rbm->offset))
58 return -EINVAL;
60 of_property_read_u32(pdev->dev.of_node, "mask", &syscon_rbm->mask);
62 ret = devm_reboot_mode_register(&pdev->dev, &syscon_rbm->reboot);
63 if (ret)
64 dev_err(&pdev->dev, "can't register reboot mode\n");
66 return ret;
69 static const struct of_device_id syscon_reboot_mode_of_match[] = {
70 { .compatible = "syscon-reboot-mode" },
73 MODULE_DEVICE_TABLE(of, syscon_reboot_mode_of_match);
75 static struct platform_driver syscon_reboot_mode_driver = {
76 .probe = syscon_reboot_mode_probe,
77 .driver = {
78 .name = "syscon-reboot-mode",
79 .of_match_table = syscon_reboot_mode_of_match,
82 module_platform_driver(syscon_reboot_mode_driver);
84 MODULE_AUTHOR("Andy Yan <andy.yan@rock-chips.com");
85 MODULE_DESCRIPTION("SYSCON reboot mode driver");
86 MODULE_LICENSE("GPL v2");