stw481x-vmmc.c 2.7 KB

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