18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci#include <linux/slab.h> 38c2ecf20Sopenharmony_ci#include <linux/string.h> 48c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 58c2ecf20Sopenharmony_ci#include <linux/regulator/machine.h> 68c2ecf20Sopenharmony_ci#include <linux/regulator/fixed.h> 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_cistruct fixed_regulator_data { 98c2ecf20Sopenharmony_ci struct fixed_voltage_config cfg; 108c2ecf20Sopenharmony_ci struct regulator_init_data init_data; 118c2ecf20Sopenharmony_ci struct platform_device pdev; 128c2ecf20Sopenharmony_ci}; 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_cistatic void regulator_fixed_release(struct device *dev) 158c2ecf20Sopenharmony_ci{ 168c2ecf20Sopenharmony_ci struct fixed_regulator_data *data = container_of(dev, 178c2ecf20Sopenharmony_ci struct fixed_regulator_data, pdev.dev); 188c2ecf20Sopenharmony_ci kfree(data->cfg.supply_name); 198c2ecf20Sopenharmony_ci kfree(data); 208c2ecf20Sopenharmony_ci} 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci/** 238c2ecf20Sopenharmony_ci * regulator_register_fixed_name - register a no-op fixed regulator 248c2ecf20Sopenharmony_ci * @id: platform device id 258c2ecf20Sopenharmony_ci * @name: name to be used for the regulator 268c2ecf20Sopenharmony_ci * @supplies: consumers for this regulator 278c2ecf20Sopenharmony_ci * @num_supplies: number of consumers 288c2ecf20Sopenharmony_ci * @uv: voltage in microvolts 298c2ecf20Sopenharmony_ci */ 308c2ecf20Sopenharmony_cistruct platform_device *regulator_register_always_on(int id, const char *name, 318c2ecf20Sopenharmony_ci struct regulator_consumer_supply *supplies, int num_supplies, int uv) 328c2ecf20Sopenharmony_ci{ 338c2ecf20Sopenharmony_ci struct fixed_regulator_data *data; 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci data = kzalloc(sizeof(*data), GFP_KERNEL); 368c2ecf20Sopenharmony_ci if (!data) 378c2ecf20Sopenharmony_ci return NULL; 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci data->cfg.supply_name = kstrdup(name, GFP_KERNEL); 408c2ecf20Sopenharmony_ci if (!data->cfg.supply_name) { 418c2ecf20Sopenharmony_ci kfree(data); 428c2ecf20Sopenharmony_ci return NULL; 438c2ecf20Sopenharmony_ci } 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci data->cfg.microvolts = uv; 468c2ecf20Sopenharmony_ci data->cfg.enabled_at_boot = 1; 478c2ecf20Sopenharmony_ci data->cfg.init_data = &data->init_data; 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci data->init_data.constraints.always_on = 1; 508c2ecf20Sopenharmony_ci data->init_data.consumer_supplies = supplies; 518c2ecf20Sopenharmony_ci data->init_data.num_consumer_supplies = num_supplies; 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci data->pdev.name = "reg-fixed-voltage"; 548c2ecf20Sopenharmony_ci data->pdev.id = id; 558c2ecf20Sopenharmony_ci data->pdev.dev.platform_data = &data->cfg; 568c2ecf20Sopenharmony_ci data->pdev.dev.release = regulator_fixed_release; 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci platform_device_register(&data->pdev); 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci return &data->pdev; 618c2ecf20Sopenharmony_ci} 62