isl9305.c 5.2 KB

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