qcom_wcnss_iris.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * Qualcomm Wireless Connectivity Subsystem Iris driver
  3. *
  4. * Copyright (C) 2016 Linaro Ltd
  5. * Copyright (C) 2014 Sony Mobile Communications AB
  6. * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #include <linux/clk.h>
  18. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/of_device.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/regulator/consumer.h>
  23. #include "qcom_wcnss.h"
  24. struct qcom_iris {
  25. struct device *dev;
  26. struct clk *xo_clk;
  27. struct regulator_bulk_data *vregs;
  28. size_t num_vregs;
  29. };
  30. struct iris_data {
  31. const struct wcnss_vreg_info *vregs;
  32. size_t num_vregs;
  33. bool use_48mhz_xo;
  34. };
  35. static const struct iris_data wcn3620_data = {
  36. .vregs = (struct wcnss_vreg_info[]) {
  37. { "vddxo", 1800000, 1800000, 10000 },
  38. { "vddrfa", 1300000, 1300000, 100000 },
  39. { "vddpa", 3300000, 3300000, 515000 },
  40. { "vdddig", 1800000, 1800000, 10000 },
  41. },
  42. .num_vregs = 4,
  43. .use_48mhz_xo = false,
  44. };
  45. static const struct iris_data wcn3660_data = {
  46. .vregs = (struct wcnss_vreg_info[]) {
  47. { "vddxo", 1800000, 1800000, 10000 },
  48. { "vddrfa", 1300000, 1300000, 100000 },
  49. { "vddpa", 2900000, 3000000, 515000 },
  50. { "vdddig", 1200000, 1225000, 10000 },
  51. },
  52. .num_vregs = 4,
  53. .use_48mhz_xo = true,
  54. };
  55. static const struct iris_data wcn3680_data = {
  56. .vregs = (struct wcnss_vreg_info[]) {
  57. { "vddxo", 1800000, 1800000, 10000 },
  58. { "vddrfa", 1300000, 1300000, 100000 },
  59. { "vddpa", 3300000, 3300000, 515000 },
  60. { "vdddig", 1800000, 1800000, 10000 },
  61. },
  62. .num_vregs = 4,
  63. .use_48mhz_xo = true,
  64. };
  65. int qcom_iris_enable(struct qcom_iris *iris)
  66. {
  67. int ret;
  68. ret = regulator_bulk_enable(iris->num_vregs, iris->vregs);
  69. if (ret)
  70. return ret;
  71. ret = clk_prepare_enable(iris->xo_clk);
  72. if (ret) {
  73. dev_err(iris->dev, "failed to enable xo clk\n");
  74. goto disable_regulators;
  75. }
  76. return 0;
  77. disable_regulators:
  78. regulator_bulk_disable(iris->num_vregs, iris->vregs);
  79. return ret;
  80. }
  81. void qcom_iris_disable(struct qcom_iris *iris)
  82. {
  83. clk_disable_unprepare(iris->xo_clk);
  84. regulator_bulk_disable(iris->num_vregs, iris->vregs);
  85. }
  86. static int qcom_iris_probe(struct platform_device *pdev)
  87. {
  88. const struct iris_data *data;
  89. struct qcom_wcnss *wcnss;
  90. struct qcom_iris *iris;
  91. int ret;
  92. int i;
  93. iris = devm_kzalloc(&pdev->dev, sizeof(struct qcom_iris), GFP_KERNEL);
  94. if (!iris)
  95. return -ENOMEM;
  96. data = of_device_get_match_data(&pdev->dev);
  97. wcnss = dev_get_drvdata(pdev->dev.parent);
  98. iris->xo_clk = devm_clk_get(&pdev->dev, "xo");
  99. if (IS_ERR(iris->xo_clk)) {
  100. if (PTR_ERR(iris->xo_clk) != -EPROBE_DEFER)
  101. dev_err(&pdev->dev, "failed to acquire xo clk\n");
  102. return PTR_ERR(iris->xo_clk);
  103. }
  104. iris->num_vregs = data->num_vregs;
  105. iris->vregs = devm_kcalloc(&pdev->dev,
  106. iris->num_vregs,
  107. sizeof(struct regulator_bulk_data),
  108. GFP_KERNEL);
  109. if (!iris->vregs)
  110. return -ENOMEM;
  111. for (i = 0; i < iris->num_vregs; i++)
  112. iris->vregs[i].supply = data->vregs[i].name;
  113. ret = devm_regulator_bulk_get(&pdev->dev, iris->num_vregs, iris->vregs);
  114. if (ret) {
  115. dev_err(&pdev->dev, "failed to get regulators\n");
  116. return ret;
  117. }
  118. for (i = 0; i < iris->num_vregs; i++) {
  119. if (data->vregs[i].max_voltage)
  120. regulator_set_voltage(iris->vregs[i].consumer,
  121. data->vregs[i].min_voltage,
  122. data->vregs[i].max_voltage);
  123. if (data->vregs[i].load_uA)
  124. regulator_set_load(iris->vregs[i].consumer,
  125. data->vregs[i].load_uA);
  126. }
  127. qcom_wcnss_assign_iris(wcnss, iris, data->use_48mhz_xo);
  128. return 0;
  129. }
  130. static int qcom_iris_remove(struct platform_device *pdev)
  131. {
  132. struct qcom_wcnss *wcnss = dev_get_drvdata(pdev->dev.parent);
  133. qcom_wcnss_assign_iris(wcnss, NULL, false);
  134. return 0;
  135. }
  136. static const struct of_device_id iris_of_match[] = {
  137. { .compatible = "qcom,wcn3620", .data = &wcn3620_data },
  138. { .compatible = "qcom,wcn3660", .data = &wcn3660_data },
  139. { .compatible = "qcom,wcn3680", .data = &wcn3680_data },
  140. {}
  141. };
  142. MODULE_DEVICE_TABLE(of, iris_of_match);
  143. struct platform_driver qcom_iris_driver = {
  144. .probe = qcom_iris_probe,
  145. .remove = qcom_iris_remove,
  146. .driver = {
  147. .name = "qcom-iris",
  148. .of_match_table = iris_of_match,
  149. },
  150. };