fixed-helper.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/slab.h>
  3. #include <linux/string.h>
  4. #include <linux/platform_device.h>
  5. #include <linux/regulator/machine.h>
  6. #include <linux/regulator/fixed.h>
  7. struct fixed_regulator_data {
  8. struct fixed_voltage_config cfg;
  9. struct regulator_init_data init_data;
  10. struct platform_device pdev;
  11. };
  12. static void regulator_fixed_release(struct device *dev)
  13. {
  14. struct fixed_regulator_data *data = container_of(dev,
  15. struct fixed_regulator_data, pdev.dev);
  16. kfree(data->cfg.supply_name);
  17. kfree(data);
  18. }
  19. /**
  20. * regulator_register_fixed_name - register a no-op fixed regulator
  21. * @id: platform device id
  22. * @name: name to be used for the regulator
  23. * @supplies: consumers for this regulator
  24. * @num_supplies: number of consumers
  25. * @uv: voltage in microvolts
  26. */
  27. struct platform_device *regulator_register_always_on(int id, const char *name,
  28. struct regulator_consumer_supply *supplies, int num_supplies, int uv)
  29. {
  30. struct fixed_regulator_data *data;
  31. data = kzalloc(sizeof(*data), GFP_KERNEL);
  32. if (!data)
  33. return NULL;
  34. data->cfg.supply_name = kstrdup(name, GFP_KERNEL);
  35. if (!data->cfg.supply_name) {
  36. kfree(data);
  37. return NULL;
  38. }
  39. data->cfg.microvolts = uv;
  40. data->cfg.enabled_at_boot = 1;
  41. data->cfg.init_data = &data->init_data;
  42. data->init_data.constraints.always_on = 1;
  43. data->init_data.consumer_supplies = supplies;
  44. data->init_data.num_consumer_supplies = num_supplies;
  45. data->pdev.name = "reg-fixed-voltage";
  46. data->pdev.id = id;
  47. data->pdev.dev.platform_data = &data->cfg;
  48. data->pdev.dev.release = regulator_fixed_release;
  49. platform_device_register(&data->pdev);
  50. return &data->pdev;
  51. }