fixed-helper.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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.gpio = -EINVAL;
  41. data->cfg.enabled_at_boot = 1;
  42. data->cfg.init_data = &data->init_data;
  43. data->init_data.constraints.always_on = 1;
  44. data->init_data.consumer_supplies = supplies;
  45. data->init_data.num_consumer_supplies = num_supplies;
  46. data->pdev.name = "reg-fixed-voltage";
  47. data->pdev.id = id;
  48. data->pdev.dev.platform_data = &data->cfg;
  49. data->pdev.dev.release = regulator_fixed_release;
  50. platform_device_register(&data->pdev);
  51. return &data->pdev;
  52. }