arizona-ldo1.c 3.5 KB

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