arizona-ldo1.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * arizona-ldo1.c -- LDO1 supply for Arizona devices
  3. *
  4. * Copyright 2012 Wolfson Microelectronics PLC.
  5. *
  6. * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/moduleparam.h>
  15. #include <linux/init.h>
  16. #include <linux/bitops.h>
  17. #include <linux/err.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/regulator/driver.h>
  20. #include <linux/regulator/machine.h>
  21. #include <linux/gpio.h>
  22. #include <linux/slab.h>
  23. #include <linux/mfd/arizona/core.h>
  24. #include <linux/mfd/arizona/pdata.h>
  25. #include <linux/mfd/arizona/registers.h>
  26. struct arizona_ldo1 {
  27. struct regulator_dev *regulator;
  28. struct arizona *arizona;
  29. struct regulator_consumer_supply supply;
  30. struct regulator_init_data init_data;
  31. };
  32. static struct regulator_ops arizona_ldo1_ops = {
  33. .list_voltage = regulator_list_voltage_linear,
  34. .map_voltage = regulator_map_voltage_linear,
  35. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  36. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  37. .get_bypass = regulator_get_bypass_regmap,
  38. .set_bypass = regulator_set_bypass_regmap,
  39. };
  40. static const struct regulator_desc arizona_ldo1 = {
  41. .name = "LDO1",
  42. .supply_name = "LDOVDD",
  43. .type = REGULATOR_VOLTAGE,
  44. .ops = &arizona_ldo1_ops,
  45. .vsel_reg = ARIZONA_LDO1_CONTROL_1,
  46. .vsel_mask = ARIZONA_LDO1_VSEL_MASK,
  47. .bypass_reg = ARIZONA_LDO1_CONTROL_1,
  48. .bypass_mask = ARIZONA_LDO1_BYPASS,
  49. .min_uV = 900000,
  50. .uV_step = 50000,
  51. .n_voltages = 7,
  52. .enable_time = 500,
  53. .owner = THIS_MODULE,
  54. };
  55. static const struct regulator_init_data arizona_ldo1_dvfs = {
  56. .constraints = {
  57. .min_uV = 1200000,
  58. .max_uV = 1800000,
  59. .valid_ops_mask = REGULATOR_CHANGE_STATUS |
  60. REGULATOR_CHANGE_VOLTAGE,
  61. },
  62. .num_consumer_supplies = 1,
  63. };
  64. static const struct regulator_init_data arizona_ldo1_default = {
  65. .constraints = {
  66. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  67. },
  68. .num_consumer_supplies = 1,
  69. };
  70. static __devinit int arizona_ldo1_probe(struct platform_device *pdev)
  71. {
  72. struct arizona *arizona = dev_get_drvdata(pdev->dev.parent);
  73. struct regulator_config config = { };
  74. struct arizona_ldo1 *ldo1;
  75. int ret;
  76. ldo1 = devm_kzalloc(&pdev->dev, sizeof(*ldo1), GFP_KERNEL);
  77. if (ldo1 == NULL) {
  78. dev_err(&pdev->dev, "Unable to allocate private data\n");
  79. return -ENOMEM;
  80. }
  81. ldo1->arizona = arizona;
  82. /*
  83. * Since the chip usually supplies itself we provide some
  84. * default init_data for it. This will be overridden with
  85. * platform data if provided.
  86. */
  87. switch (arizona->type) {
  88. case WM5102:
  89. ldo1->init_data = arizona_ldo1_dvfs;
  90. break;
  91. default:
  92. ldo1->init_data = arizona_ldo1_default;
  93. break;
  94. }
  95. ldo1->init_data.consumer_supplies = &ldo1->supply;
  96. ldo1->supply.supply = "DCVDD";
  97. ldo1->supply.dev_name = dev_name(arizona->dev);
  98. config.dev = arizona->dev;
  99. config.driver_data = ldo1;
  100. config.regmap = arizona->regmap;
  101. config.ena_gpio = arizona->pdata.ldoena;
  102. if (arizona->pdata.ldo1)
  103. config.init_data = arizona->pdata.ldo1;
  104. else
  105. config.init_data = &ldo1->init_data;
  106. ldo1->regulator = regulator_register(&arizona_ldo1, &config);
  107. if (IS_ERR(ldo1->regulator)) {
  108. ret = PTR_ERR(ldo1->regulator);
  109. dev_err(arizona->dev, "Failed to register LDO1 supply: %d\n",
  110. ret);
  111. return ret;
  112. }
  113. platform_set_drvdata(pdev, ldo1);
  114. return 0;
  115. }
  116. static __devexit int arizona_ldo1_remove(struct platform_device *pdev)
  117. {
  118. struct arizona_ldo1 *ldo1 = platform_get_drvdata(pdev);
  119. regulator_unregister(ldo1->regulator);
  120. return 0;
  121. }
  122. static struct platform_driver arizona_ldo1_driver = {
  123. .probe = arizona_ldo1_probe,
  124. .remove = __devexit_p(arizona_ldo1_remove),
  125. .driver = {
  126. .name = "arizona-ldo1",
  127. .owner = THIS_MODULE,
  128. },
  129. };
  130. module_platform_driver(arizona_ldo1_driver);
  131. /* Module information */
  132. MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
  133. MODULE_DESCRIPTION("Arizona LDO1 driver");
  134. MODULE_LICENSE("GPL");
  135. MODULE_ALIAS("platform:arizona-ldo1");