1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) Vaisala Oyj. All rights reserved.
6 #include <linux/init.h>
7 #include <linux/module.h>
8 #include <linux/kernel.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
,
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
));
29 dev_err(reboot
->dev
, "update reboot mode bits failed\n");
34 static int nvmem_reboot_mode_probe(struct platform_device
*pdev
)
37 struct nvmem_reboot_mode
*nvmem_rbm
;
39 nvmem_rbm
= devm_kzalloc(&pdev
->dev
, sizeof(*nvmem_rbm
), GFP_KERNEL
);
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
);
54 dev_err(&pdev
->dev
, "can't register reboot mode\n");
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
,
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");