WIP FPC-III support
[linux/fpc-iii.git] / drivers / power / reset / nvmem-reboot-mode.c
blobe229308d43e25c747eba3fbf3bcdb4c10fea2378
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (c) Vaisala Oyj. All rights reserved.
4 */
6 #include <linux/init.h>
7 #include <linux/module.h>
8 #include <linux/kernel.h>
9 #include <linux/of.h>
10 #include <linux/nvmem-consumer.h>
11 #include <linux/platform_device.h>
12 #include <linux/reboot-mode.h>
14 struct nvmem_reboot_mode {
15 struct reboot_mode_driver reboot;
16 struct nvmem_cell *cell;
19 static int nvmem_reboot_mode_write(struct reboot_mode_driver *reboot,
20 unsigned int magic)
22 int ret;
23 struct nvmem_reboot_mode *nvmem_rbm;
25 nvmem_rbm = container_of(reboot, struct nvmem_reboot_mode, reboot);
27 ret = nvmem_cell_write(nvmem_rbm->cell, &magic, sizeof(magic));
28 if (ret < 0)
29 dev_err(reboot->dev, "update reboot mode bits failed\n");
31 return ret;
34 static int nvmem_reboot_mode_probe(struct platform_device *pdev)
36 int ret;
37 struct nvmem_reboot_mode *nvmem_rbm;
39 nvmem_rbm = devm_kzalloc(&pdev->dev, sizeof(*nvmem_rbm), GFP_KERNEL);
40 if (!nvmem_rbm)
41 return -ENOMEM;
43 nvmem_rbm->reboot.dev = &pdev->dev;
44 nvmem_rbm->reboot.write = nvmem_reboot_mode_write;
46 nvmem_rbm->cell = devm_nvmem_cell_get(&pdev->dev, "reboot-mode");
47 if (IS_ERR(nvmem_rbm->cell)) {
48 dev_err(&pdev->dev, "failed to get the nvmem cell reboot-mode\n");
49 return PTR_ERR(nvmem_rbm->cell);
52 ret = devm_reboot_mode_register(&pdev->dev, &nvmem_rbm->reboot);
53 if (ret)
54 dev_err(&pdev->dev, "can't register reboot mode\n");
56 return ret;
59 static const struct of_device_id nvmem_reboot_mode_of_match[] = {
60 { .compatible = "nvmem-reboot-mode" },
63 MODULE_DEVICE_TABLE(of, nvmem_reboot_mode_of_match);
65 static struct platform_driver nvmem_reboot_mode_driver = {
66 .probe = nvmem_reboot_mode_probe,
67 .driver = {
68 .name = "nvmem-reboot-mode",
69 .of_match_table = nvmem_reboot_mode_of_match,
72 module_platform_driver(nvmem_reboot_mode_driver);
74 MODULE_AUTHOR("Nandor Han <nandor.han@vaisala.com>");
75 MODULE_DESCRIPTION("NVMEM reboot mode driver");
76 MODULE_LICENSE("GPL");