xref: /linux/drivers/regulator/dummy.c (revision 0f82b6cf76516063fe26dac15e93544387c681eb)
134abbd68SMark Brown /*
234abbd68SMark Brown  * dummy.c
334abbd68SMark Brown  *
434abbd68SMark Brown  * Copyright 2010 Wolfson Microelectronics PLC.
534abbd68SMark Brown  *
634abbd68SMark Brown  * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
734abbd68SMark Brown  *
834abbd68SMark Brown  * This program is free software; you can redistribute it and/or
934abbd68SMark Brown  * modify it under the terms of the GNU General Public License as
1034abbd68SMark Brown  * published by the Free Software Foundation; either version 2 of the
1134abbd68SMark Brown  * License, or (at your option) any later version.
1234abbd68SMark Brown  *
1334abbd68SMark Brown  * This is useful for systems with mixed controllable and
1434abbd68SMark Brown  * non-controllable regulators, as well as for allowing testing on
1534abbd68SMark Brown  * systems with no controllable regulators.
1634abbd68SMark Brown  */
1734abbd68SMark Brown 
1834abbd68SMark Brown #include <linux/err.h>
1922be053fSPaul Gortmaker #include <linux/export.h>
2034abbd68SMark Brown #include <linux/platform_device.h>
2134abbd68SMark Brown #include <linux/regulator/driver.h>
2234abbd68SMark Brown #include <linux/regulator/machine.h>
2334abbd68SMark Brown 
2434abbd68SMark Brown #include "dummy.h"
2534abbd68SMark Brown 
2634abbd68SMark Brown struct regulator_dev *dummy_regulator_rdev;
2734abbd68SMark Brown 
2834abbd68SMark Brown static struct regulator_init_data dummy_initdata;
2934abbd68SMark Brown 
3034abbd68SMark Brown static struct regulator_ops dummy_ops;
3134abbd68SMark Brown 
3234abbd68SMark Brown static struct regulator_desc dummy_desc = {
3334abbd68SMark Brown 	.name = "dummy",
3434abbd68SMark Brown 	.id = -1,
3534abbd68SMark Brown 	.type = REGULATOR_VOLTAGE,
3634abbd68SMark Brown 	.owner = THIS_MODULE,
3734abbd68SMark Brown 	.ops = &dummy_ops,
3834abbd68SMark Brown };
3934abbd68SMark Brown 
40c08957a2SMark Brown static int __devinit dummy_regulator_probe(struct platform_device *pdev)
41c08957a2SMark Brown {
42c172708dSMark Brown 	struct regulator_config config = { };
43c08957a2SMark Brown 	int ret;
44c08957a2SMark Brown 
45*0f82b6cfSMark Brown 	config.dev = &pdev->dev;
46c172708dSMark Brown 	config.init_data = &dummy_initdata;
47c172708dSMark Brown 
48c172708dSMark Brown 	dummy_regulator_rdev = regulator_register(&dummy_desc, &config);
49c08957a2SMark Brown 	if (IS_ERR(dummy_regulator_rdev)) {
50c08957a2SMark Brown 		ret = PTR_ERR(dummy_regulator_rdev);
51c08957a2SMark Brown 		pr_err("Failed to register regulator: %d\n", ret);
52c08957a2SMark Brown 		return ret;
53c08957a2SMark Brown 	}
54c08957a2SMark Brown 
55c08957a2SMark Brown 	return 0;
56c08957a2SMark Brown }
57c08957a2SMark Brown 
58c08957a2SMark Brown static struct platform_driver dummy_regulator_driver = {
59c08957a2SMark Brown 	.probe		= dummy_regulator_probe,
60c08957a2SMark Brown 	.driver		= {
61c08957a2SMark Brown 		.name		= "reg-dummy",
62c08957a2SMark Brown 		.owner		= THIS_MODULE,
63c08957a2SMark Brown 	},
64c08957a2SMark Brown };
65c08957a2SMark Brown 
6634abbd68SMark Brown static struct platform_device *dummy_pdev;
6734abbd68SMark Brown 
6834abbd68SMark Brown void __init regulator_dummy_init(void)
6934abbd68SMark Brown {
7034abbd68SMark Brown 	int ret;
7134abbd68SMark Brown 
7234abbd68SMark Brown 	dummy_pdev = platform_device_alloc("reg-dummy", -1);
7334abbd68SMark Brown 	if (!dummy_pdev) {
7434abbd68SMark Brown 		pr_err("Failed to allocate dummy regulator device\n");
7534abbd68SMark Brown 		return;
7634abbd68SMark Brown 	}
7734abbd68SMark Brown 
7834abbd68SMark Brown 	ret = platform_device_add(dummy_pdev);
7934abbd68SMark Brown 	if (ret != 0) {
8034abbd68SMark Brown 		pr_err("Failed to register dummy regulator device: %d\n", ret);
8134abbd68SMark Brown 		platform_device_put(dummy_pdev);
8234abbd68SMark Brown 		return;
8334abbd68SMark Brown 	}
8434abbd68SMark Brown 
85c08957a2SMark Brown 	ret = platform_driver_register(&dummy_regulator_driver);
86c08957a2SMark Brown 	if (ret != 0) {
87c08957a2SMark Brown 		pr_err("Failed to register dummy regulator driver: %d\n", ret);
8834abbd68SMark Brown 		platform_device_unregister(dummy_pdev);
8934abbd68SMark Brown 	}
9034abbd68SMark Brown }
91