1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * dummy.c
4  *
5  * Copyright 2010 Wolfson Microelectronics PLC.
6  *
7  * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
8  *
9  * This is useful for systems with mixed controllable and
10  * non-controllable regulators, as well as for allowing testing on
11  * systems with no controllable regulators.
12  */
13 
14 #include <linux/err.h>
15 #include <linux/export.h>
16 #include <linux/platform_device.h>
17 #include <linux/regulator/driver.h>
18 #include <linux/regulator/machine.h>
19 
20 #include "dummy.h"
21 
22 struct regulator_dev *dummy_regulator_rdev;
23 
24 static const struct regulator_init_data dummy_initdata = {
25 	.constraints = {
26 		.always_on = 1,
27 	},
28 };
29 
30 static const struct regulator_ops dummy_ops;
31 
32 static const struct regulator_desc dummy_desc = {
33 	.name = "regulator-dummy",
34 	.id = -1,
35 	.type = REGULATOR_VOLTAGE,
36 	.owner = THIS_MODULE,
37 	.ops = &dummy_ops,
38 };
39 
dummy_regulator_probe(struct platform_device * pdev)40 static int dummy_regulator_probe(struct platform_device *pdev)
41 {
42 	struct regulator_config config = { };
43 	int ret;
44 
45 	config.dev = &pdev->dev;
46 	config.init_data = &dummy_initdata;
47 
48 	dummy_regulator_rdev = devm_regulator_register(&pdev->dev, &dummy_desc,
49 						       &config);
50 	if (IS_ERR(dummy_regulator_rdev)) {
51 		ret = PTR_ERR(dummy_regulator_rdev);
52 		pr_err("Failed to register regulator: %d\n", ret);
53 		return ret;
54 	}
55 
56 	return 0;
57 }
58 
59 static struct platform_driver dummy_regulator_driver = {
60 	.probe		= dummy_regulator_probe,
61 	.driver		= {
62 		.name		= "reg-dummy",
63 	},
64 };
65 
66 static struct platform_device *dummy_pdev;
67 
regulator_dummy_init(void)68 void __init regulator_dummy_init(void)
69 {
70 	int ret;
71 
72 	dummy_pdev = platform_device_alloc("reg-dummy", -1);
73 	if (!dummy_pdev) {
74 		pr_err("Failed to allocate dummy regulator device\n");
75 		return;
76 	}
77 
78 	ret = platform_device_add(dummy_pdev);
79 	if (ret != 0) {
80 		pr_err("Failed to register dummy regulator device: %d\n", ret);
81 		platform_device_put(dummy_pdev);
82 		return;
83 	}
84 
85 	ret = platform_driver_register(&dummy_regulator_driver);
86 	if (ret != 0) {
87 		pr_err("Failed to register dummy regulator driver: %d\n", ret);
88 		platform_device_unregister(dummy_pdev);
89 	}
90 }
91