stw481x-vmmc.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Regulator driver for STw4810/STw4811 VMMC regulator.
  3. *
  4. * Copyright (C) 2013 ST-Ericsson SA
  5. * Written on behalf of Linaro for ST-Ericsson
  6. *
  7. * Author: Linus Walleij <linus.walleij@linaro.org>
  8. *
  9. * License terms: GNU General Public License (GPL) version 2
  10. */
  11. #include <linux/err.h>
  12. #include <linux/init.h>
  13. #include <linux/mfd/stw481x.h>
  14. #include <linux/module.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/regulator/driver.h>
  17. #include <linux/regulator/of_regulator.h>
  18. static const unsigned int stw481x_vmmc_voltages[] = {
  19. 1800000,
  20. 1800000,
  21. 2850000,
  22. 3000000,
  23. 1850000,
  24. 2600000,
  25. 2700000,
  26. 3300000,
  27. };
  28. static struct regulator_ops stw481x_vmmc_ops = {
  29. .list_voltage = regulator_list_voltage_table,
  30. .enable = regulator_enable_regmap,
  31. .disable = regulator_disable_regmap,
  32. .is_enabled = regulator_is_enabled_regmap,
  33. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  34. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  35. };
  36. static struct regulator_desc vmmc_regulator = {
  37. .name = "VMMC",
  38. .id = 0,
  39. .ops = &stw481x_vmmc_ops,
  40. .type = REGULATOR_VOLTAGE,
  41. .owner = THIS_MODULE,
  42. .n_voltages = ARRAY_SIZE(stw481x_vmmc_voltages),
  43. .volt_table = stw481x_vmmc_voltages,
  44. .enable_time = 200, /* FIXME: look this up */
  45. .enable_reg = STW_CONF1,
  46. .enable_mask = STW_CONF1_PDN_VMMC | STW_CONF1_MMC_LS_STATUS,
  47. .enable_val = STW_CONF1_PDN_VMMC,
  48. .vsel_reg = STW_CONF1,
  49. .vsel_mask = STW_CONF1_VMMC_MASK,
  50. };
  51. static int stw481x_vmmc_regulator_probe(struct platform_device *pdev)
  52. {
  53. struct stw481x *stw481x = dev_get_platdata(&pdev->dev);
  54. struct regulator_config config = { };
  55. struct regulator_dev *rdev;
  56. int ret;
  57. /* First disable the external VMMC if it's active */
  58. ret = regmap_update_bits(stw481x->map, STW_CONF2,
  59. STW_CONF2_VMMC_EXT, 0);
  60. if (ret) {
  61. dev_err(&pdev->dev, "could not disable external VMMC\n");
  62. return ret;
  63. }
  64. /* Register VMMC regulator */
  65. config.dev = &pdev->dev;
  66. config.driver_data = stw481x;
  67. config.regmap = stw481x->map;
  68. config.of_node = pdev->dev.of_node;
  69. config.init_data = of_get_regulator_init_data(&pdev->dev,
  70. pdev->dev.of_node,
  71. &vmmc_regulator);
  72. rdev = devm_regulator_register(&pdev->dev, &vmmc_regulator, &config);
  73. if (IS_ERR(rdev)) {
  74. dev_err(&pdev->dev,
  75. "error initializing STw481x VMMC regulator\n");
  76. return PTR_ERR(rdev);
  77. }
  78. dev_info(&pdev->dev, "initialized STw481x VMMC regulator\n");
  79. return 0;
  80. }
  81. static const struct of_device_id stw481x_vmmc_match[] = {
  82. { .compatible = "st,stw481x-vmmc", },
  83. {},
  84. };
  85. static struct platform_driver stw481x_vmmc_regulator_driver = {
  86. .driver = {
  87. .name = "stw481x-vmmc-regulator",
  88. .of_match_table = stw481x_vmmc_match,
  89. },
  90. .probe = stw481x_vmmc_regulator_probe,
  91. };
  92. module_platform_driver(stw481x_vmmc_regulator_driver);