fixed-helper.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <linux/slab.h>
  2. #include <linux/string.h>
  3. #include <linux/platform_device.h>
  4. #include <linux/regulator/machine.h>
  5. #include <linux/regulator/fixed.h>
  6. struct fixed_regulator_data {
  7. struct fixed_voltage_config cfg;
  8. struct regulator_init_data init_data;
  9. struct platform_device pdev;
  10. };
  11. static void regulator_fixed_release(struct device *dev)
  12. {
  13. struct fixed_regulator_data *data = container_of(dev,
  14. struct fixed_regulator_data, pdev.dev);
  15. kfree(data->cfg.supply_name);
  16. kfree(data);
  17. }
  18. /**
  19. * regulator_register_fixed_name - register a no-op fixed regulator
  20. * @id: platform device id
  21. * @name: name to be used for the regulator
  22. * @supplies: consumers for this regulator
  23. * @num_supplies: number of consumers
  24. * @uv: voltage in microvolts
  25. */
  26. struct platform_device *regulator_register_always_on(int id, const char *name,
  27. struct regulator_consumer_supply *supplies, int num_supplies, int uv)
  28. {
  29. struct fixed_regulator_data *data;
  30. data = kzalloc(sizeof(*data), GFP_KERNEL);
  31. if (!data)
  32. return NULL;
  33. data->cfg.supply_name = kstrdup(name, GFP_KERNEL);
  34. if (!data->cfg.supply_name) {
  35. kfree(data);
  36. return NULL;
  37. }
  38. data->cfg.microvolts = uv;
  39. data->cfg.gpio = -EINVAL;
  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. }