Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * dummy.c
0004  *
0005  * Copyright 2010 Wolfson Microelectronics PLC.
0006  *
0007  * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
0008  *
0009  * This is useful for systems with mixed controllable and
0010  * non-controllable regulators, as well as for allowing testing on
0011  * systems with no controllable regulators.
0012  */
0013 
0014 #include <linux/err.h>
0015 #include <linux/export.h>
0016 #include <linux/platform_device.h>
0017 #include <linux/regulator/driver.h>
0018 #include <linux/regulator/machine.h>
0019 
0020 #include "dummy.h"
0021 
0022 struct regulator_dev *dummy_regulator_rdev;
0023 
0024 static const struct regulator_init_data dummy_initdata = {
0025     .constraints = {
0026         .always_on = 1,
0027     },
0028 };
0029 
0030 static const struct regulator_ops dummy_ops;
0031 
0032 static const struct regulator_desc dummy_desc = {
0033     .name = "regulator-dummy",
0034     .id = -1,
0035     .type = REGULATOR_VOLTAGE,
0036     .owner = THIS_MODULE,
0037     .ops = &dummy_ops,
0038 };
0039 
0040 static int dummy_regulator_probe(struct platform_device *pdev)
0041 {
0042     struct regulator_config config = { };
0043     int ret;
0044 
0045     config.dev = &pdev->dev;
0046     config.init_data = &dummy_initdata;
0047 
0048     dummy_regulator_rdev = devm_regulator_register(&pdev->dev, &dummy_desc,
0049                                &config);
0050     if (IS_ERR(dummy_regulator_rdev)) {
0051         ret = PTR_ERR(dummy_regulator_rdev);
0052         pr_err("Failed to register regulator: %d\n", ret);
0053         return ret;
0054     }
0055 
0056     return 0;
0057 }
0058 
0059 static struct platform_driver dummy_regulator_driver = {
0060     .probe      = dummy_regulator_probe,
0061     .driver     = {
0062         .name       = "reg-dummy",
0063     },
0064 };
0065 
0066 static struct platform_device *dummy_pdev;
0067 
0068 void __init regulator_dummy_init(void)
0069 {
0070     int ret;
0071 
0072     dummy_pdev = platform_device_alloc("reg-dummy", -1);
0073     if (!dummy_pdev) {
0074         pr_err("Failed to allocate dummy regulator device\n");
0075         return;
0076     }
0077 
0078     ret = platform_device_add(dummy_pdev);
0079     if (ret != 0) {
0080         pr_err("Failed to register dummy regulator device: %d\n", ret);
0081         platform_device_put(dummy_pdev);
0082         return;
0083     }
0084 
0085     ret = platform_driver_register(&dummy_regulator_driver);
0086     if (ret != 0) {
0087         pr_err("Failed to register dummy regulator driver: %d\n", ret);
0088         platform_device_unregister(dummy_pdev);
0089     }
0090 }