fixed-helper.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include <linux/slab.h>
  2. #include <linux/platform_device.h>
  3. #include <linux/regulator/machine.h>
  4. #include <linux/regulator/fixed.h>
  5. struct fixed_regulator_data {
  6. struct fixed_voltage_config cfg;
  7. struct regulator_init_data init_data;
  8. struct platform_device pdev;
  9. };
  10. static void regulator_fixed_release(struct device *dev)
  11. {
  12. struct fixed_regulator_data *data = container_of(dev,
  13. struct fixed_regulator_data, pdev.dev);
  14. kfree(data);
  15. }
  16. /**
  17. * regulator_register_fixed - register a no-op fixed regulator
  18. * @id: platform device id
  19. * @supplies: consumers for this regulator
  20. * @num_supplies: number of consumers
  21. */
  22. struct platform_device *regulator_register_fixed(int id,
  23. struct regulator_consumer_supply *supplies, int num_supplies)
  24. {
  25. struct fixed_regulator_data *data;
  26. data = kzalloc(sizeof(*data), GFP_KERNEL);
  27. if (!data)
  28. return NULL;
  29. data->cfg.supply_name = "fixed-dummy";
  30. data->cfg.microvolts = 0;
  31. data->cfg.gpio = -EINVAL;
  32. data->cfg.enabled_at_boot = 1;
  33. data->cfg.init_data = &data->init_data;
  34. data->init_data.constraints.always_on = 1;
  35. data->init_data.consumer_supplies = supplies;
  36. data->init_data.num_consumer_supplies = num_supplies;
  37. data->pdev.name = "reg-fixed-voltage";
  38. data->pdev.id = id;
  39. data->pdev.dev.platform_data = &data->cfg;
  40. data->pdev.dev.release = regulator_fixed_release;
  41. platform_device_register(&data->pdev);
  42. return &data->pdev;
  43. }