Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <linux/slab.h>
0003 #include <linux/string.h>
0004 #include <linux/platform_device.h>
0005 #include <linux/regulator/machine.h>
0006 #include <linux/regulator/fixed.h>
0007 
0008 struct fixed_regulator_data {
0009     struct fixed_voltage_config cfg;
0010     struct regulator_init_data init_data;
0011     struct platform_device pdev;
0012 };
0013 
0014 static void regulator_fixed_release(struct device *dev)
0015 {
0016     struct fixed_regulator_data *data = container_of(dev,
0017             struct fixed_regulator_data, pdev.dev);
0018     kfree(data->cfg.supply_name);
0019     kfree(data);
0020 }
0021 
0022 /**
0023  * regulator_register_fixed_name - register a no-op fixed regulator
0024  * @id: platform device id
0025  * @name: name to be used for the regulator
0026  * @supplies: consumers for this regulator
0027  * @num_supplies: number of consumers
0028  * @uv: voltage in microvolts
0029  */
0030 struct platform_device *regulator_register_always_on(int id, const char *name,
0031     struct regulator_consumer_supply *supplies, int num_supplies, int uv)
0032 {
0033     struct fixed_regulator_data *data;
0034 
0035     data = kzalloc(sizeof(*data), GFP_KERNEL);
0036     if (!data)
0037         return NULL;
0038 
0039     data->cfg.supply_name = kstrdup(name, GFP_KERNEL);
0040     if (!data->cfg.supply_name) {
0041         kfree(data);
0042         return NULL;
0043     }
0044 
0045     data->cfg.microvolts = uv;
0046     data->cfg.enabled_at_boot = 1;
0047     data->cfg.init_data = &data->init_data;
0048 
0049     data->init_data.constraints.always_on = 1;
0050     data->init_data.consumer_supplies = supplies;
0051     data->init_data.num_consumer_supplies = num_supplies;
0052 
0053     data->pdev.name = "reg-fixed-voltage";
0054     data->pdev.id = id;
0055     data->pdev.dev.platform_data = &data->cfg;
0056     data->pdev.dev.release = regulator_fixed_release;
0057 
0058     platform_device_register(&data->pdev);
0059 
0060     return &data->pdev;
0061 }