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