arizona-ldo1.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. .owner = THIS_MODULE,
  53. };
  54. static const struct regulator_init_data arizona_ldo1_default = {
  55. .constraints = {
  56. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  57. },
  58. .num_consumer_supplies = 1,
  59. };
  60. static __devinit int arizona_ldo1_probe(struct platform_device *pdev)
  61. {
  62. struct arizona *arizona = dev_get_drvdata(pdev->dev.parent);
  63. struct regulator_config config = { };
  64. struct arizona_ldo1 *ldo1;
  65. int ret;
  66. ldo1 = devm_kzalloc(&pdev->dev, sizeof(*ldo1), GFP_KERNEL);
  67. if (ldo1 == NULL) {
  68. dev_err(&pdev->dev, "Unable to allocate private data\n");
  69. return -ENOMEM;
  70. }
  71. ldo1->arizona = arizona;
  72. /*
  73. * Since the chip usually supplies itself we provide some
  74. * default init_data for it. This will be overridden with
  75. * platform data if provided.
  76. */
  77. ldo1->init_data = arizona_ldo1_default;
  78. ldo1->init_data.consumer_supplies = &ldo1->supply;
  79. ldo1->supply.supply = "DCVDD";
  80. ldo1->supply.dev_name = dev_name(arizona->dev);
  81. config.dev = arizona->dev;
  82. config.driver_data = ldo1;
  83. config.regmap = arizona->regmap;
  84. config.ena_gpio = arizona->pdata.ldoena;
  85. if (arizona->pdata.ldo1)
  86. config.init_data = arizona->pdata.ldo1;
  87. else
  88. config.init_data = &ldo1->init_data;
  89. ldo1->regulator = regulator_register(&arizona_ldo1, &config);
  90. if (IS_ERR(ldo1->regulator)) {
  91. ret = PTR_ERR(ldo1->regulator);
  92. dev_err(arizona->dev, "Failed to register LDO1 supply: %d\n",
  93. ret);
  94. return ret;
  95. }
  96. platform_set_drvdata(pdev, ldo1);
  97. return 0;
  98. }
  99. static __devexit int arizona_ldo1_remove(struct platform_device *pdev)
  100. {
  101. struct arizona_ldo1 *ldo1 = platform_get_drvdata(pdev);
  102. regulator_unregister(ldo1->regulator);
  103. return 0;
  104. }
  105. static struct platform_driver arizona_ldo1_driver = {
  106. .probe = arizona_ldo1_probe,
  107. .remove = __devexit_p(arizona_ldo1_remove),
  108. .driver = {
  109. .name = "arizona-ldo1",
  110. .owner = THIS_MODULE,
  111. },
  112. };
  113. module_platform_driver(arizona_ldo1_driver);
  114. /* Module information */
  115. MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
  116. MODULE_DESCRIPTION("Arizona LDO1 driver");
  117. MODULE_LICENSE("GPL");
  118. MODULE_ALIAS("platform:arizona-ldo1");