isl9305.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * isl9305 - Intersil ISL9305 DCDC regulator
  4. *
  5. * Copyright 2014 Linaro Ltd
  6. *
  7. * Author: Mark Brown <broonie@kernel.org>
  8. */
  9. #include <linux/module.h>
  10. #include <linux/err.h>
  11. #include <linux/i2c.h>
  12. #include <linux/of.h>
  13. #include <linux/platform_data/isl9305.h>
  14. #include <linux/regmap.h>
  15. #include <linux/regulator/driver.h>
  16. #include <linux/regulator/of_regulator.h>
  17. #include <linux/slab.h>
  18. /*
  19. * Registers
  20. */
  21. #define ISL9305_DCD1OUT 0x0
  22. #define ISL9305_DCD2OUT 0x1
  23. #define ISL9305_LDO1OUT 0x2
  24. #define ISL9305_LDO2OUT 0x3
  25. #define ISL9305_DCD_PARAMETER 0x4
  26. #define ISL9305_SYSTEM_PARAMETER 0x5
  27. #define ISL9305_DCD_SRCTL 0x6
  28. #define ISL9305_MAX_REG ISL9305_DCD_SRCTL
  29. /*
  30. * DCD_PARAMETER
  31. */
  32. #define ISL9305_DCD_PHASE 0x40
  33. #define ISL9305_DCD2_ULTRA 0x20
  34. #define ISL9305_DCD1_ULTRA 0x10
  35. #define ISL9305_DCD2_BLD 0x08
  36. #define ISL9305_DCD1_BLD 0x04
  37. #define ISL9305_DCD2_MODE 0x02
  38. #define ISL9305_DCD1_MODE 0x01
  39. /*
  40. * SYSTEM_PARAMETER
  41. */
  42. #define ISL9305_I2C_EN 0x40
  43. #define ISL9305_DCDPOR_MASK 0x30
  44. #define ISL9305_LDO2_EN 0x08
  45. #define ISL9305_LDO1_EN 0x04
  46. #define ISL9305_DCD2_EN 0x02
  47. #define ISL9305_DCD1_EN 0x01
  48. /*
  49. * DCD_SRCTL
  50. */
  51. #define ISL9305_DCD2SR_MASK 0xc0
  52. #define ISL9305_DCD1SR_MASK 0x07
  53. static const struct regulator_ops isl9305_ops = {
  54. .enable = regulator_enable_regmap,
  55. .disable = regulator_disable_regmap,
  56. .is_enabled = regulator_is_enabled_regmap,
  57. .list_voltage = regulator_list_voltage_linear,
  58. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  59. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  60. };
  61. static const struct regulator_desc isl9305_regulators[] = {
  62. [ISL9305_DCD1] = {
  63. .name = "DCD1",
  64. .of_match = of_match_ptr("dcd1"),
  65. .regulators_node = of_match_ptr("regulators"),
  66. .n_voltages = 0x70,
  67. .min_uV = 825000,
  68. .uV_step = 25000,
  69. .vsel_reg = ISL9305_DCD1OUT,
  70. .vsel_mask = 0x7f,
  71. .enable_reg = ISL9305_SYSTEM_PARAMETER,
  72. .enable_mask = ISL9305_DCD1_EN,
  73. .supply_name = "VINDCD1",
  74. .ops = &isl9305_ops,
  75. .owner = THIS_MODULE,
  76. },
  77. [ISL9305_DCD2] = {
  78. .name = "DCD2",
  79. .of_match = of_match_ptr("dcd2"),
  80. .regulators_node = of_match_ptr("regulators"),
  81. .n_voltages = 0x70,
  82. .min_uV = 825000,
  83. .uV_step = 25000,
  84. .vsel_reg = ISL9305_DCD2OUT,
  85. .vsel_mask = 0x7f,
  86. .enable_reg = ISL9305_SYSTEM_PARAMETER,
  87. .enable_mask = ISL9305_DCD2_EN,
  88. .supply_name = "VINDCD2",
  89. .ops = &isl9305_ops,
  90. .owner = THIS_MODULE,
  91. },
  92. [ISL9305_LDO1] = {
  93. .name = "LDO1",
  94. .of_match = of_match_ptr("ldo1"),
  95. .regulators_node = of_match_ptr("regulators"),
  96. .n_voltages = 0x37,
  97. .min_uV = 900000,
  98. .uV_step = 50000,
  99. .vsel_reg = ISL9305_LDO1OUT,
  100. .vsel_mask = 0x3f,
  101. .enable_reg = ISL9305_SYSTEM_PARAMETER,
  102. .enable_mask = ISL9305_LDO1_EN,
  103. .supply_name = "VINLDO1",
  104. .ops = &isl9305_ops,
  105. .owner = THIS_MODULE,
  106. },
  107. [ISL9305_LDO2] = {
  108. .name = "LDO2",
  109. .of_match = of_match_ptr("ldo2"),
  110. .regulators_node = of_match_ptr("regulators"),
  111. .n_voltages = 0x37,
  112. .min_uV = 900000,
  113. .uV_step = 50000,
  114. .vsel_reg = ISL9305_LDO2OUT,
  115. .vsel_mask = 0x3f,
  116. .enable_reg = ISL9305_SYSTEM_PARAMETER,
  117. .enable_mask = ISL9305_LDO2_EN,
  118. .supply_name = "VINLDO2",
  119. .ops = &isl9305_ops,
  120. .owner = THIS_MODULE,
  121. },
  122. };
  123. static const struct regmap_config isl9305_regmap = {
  124. .reg_bits = 8,
  125. .val_bits = 8,
  126. .max_register = ISL9305_MAX_REG,
  127. .cache_type = REGCACHE_RBTREE,
  128. };
  129. static int isl9305_i2c_probe(struct i2c_client *i2c)
  130. {
  131. struct regulator_config config = { };
  132. struct isl9305_pdata *pdata = i2c->dev.platform_data;
  133. struct regulator_dev *rdev;
  134. struct regmap *regmap;
  135. int i, ret;
  136. regmap = devm_regmap_init_i2c(i2c, &isl9305_regmap);
  137. if (IS_ERR(regmap)) {
  138. ret = PTR_ERR(regmap);
  139. dev_err(&i2c->dev, "Failed to create regmap: %d\n", ret);
  140. return ret;
  141. }
  142. config.dev = &i2c->dev;
  143. for (i = 0; i < ARRAY_SIZE(isl9305_regulators); i++) {
  144. if (pdata)
  145. config.init_data = pdata->init_data[i];
  146. else
  147. config.init_data = NULL;
  148. rdev = devm_regulator_register(&i2c->dev,
  149. &isl9305_regulators[i],
  150. &config);
  151. if (IS_ERR(rdev)) {
  152. ret = PTR_ERR(rdev);
  153. dev_err(&i2c->dev, "Failed to register %s: %d\n",
  154. isl9305_regulators[i].name, ret);
  155. return ret;
  156. }
  157. }
  158. return 0;
  159. }
  160. #ifdef CONFIG_OF
  161. static const struct of_device_id isl9305_dt_ids[] = {
  162. { .compatible = "isl,isl9305" }, /* for backward compat., don't use */
  163. { .compatible = "isil,isl9305" },
  164. { .compatible = "isl,isl9305h" }, /* for backward compat., don't use */
  165. { .compatible = "isil,isl9305h" },
  166. {},
  167. };
  168. MODULE_DEVICE_TABLE(of, isl9305_dt_ids);
  169. #endif
  170. static const struct i2c_device_id isl9305_i2c_id[] = {
  171. { "isl9305", },
  172. { "isl9305h", },
  173. { }
  174. };
  175. MODULE_DEVICE_TABLE(i2c, isl9305_i2c_id);
  176. static struct i2c_driver isl9305_regulator_driver = {
  177. .driver = {
  178. .name = "isl9305",
  179. .of_match_table = of_match_ptr(isl9305_dt_ids),
  180. },
  181. .probe_new = isl9305_i2c_probe,
  182. .id_table = isl9305_i2c_id,
  183. };
  184. module_i2c_driver(isl9305_regulator_driver);
  185. MODULE_AUTHOR("Mark Brown");
  186. MODULE_DESCRIPTION("Intersil ISL9305 DCDC regulator");
  187. MODULE_LICENSE("GPL");