isl9305.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. .owner = THIS_MODULE,
  80. },
  81. [ISL9305_DCD2] = {
  82. .name = "DCD2",
  83. .of_match = of_match_ptr("dcd2"),
  84. .regulators_node = of_match_ptr("regulators"),
  85. .n_voltages = 0x70,
  86. .min_uV = 825000,
  87. .uV_step = 25000,
  88. .vsel_reg = ISL9305_DCD2OUT,
  89. .vsel_mask = 0x7f,
  90. .enable_reg = ISL9305_SYSTEM_PARAMETER,
  91. .enable_mask = ISL9305_DCD2_EN,
  92. .supply_name = "VINDCD2",
  93. .ops = &isl9305_ops,
  94. .owner = THIS_MODULE,
  95. },
  96. [ISL9305_LDO1] = {
  97. .name = "LDO1",
  98. .of_match = of_match_ptr("ldo1"),
  99. .regulators_node = of_match_ptr("regulators"),
  100. .n_voltages = 0x37,
  101. .min_uV = 900000,
  102. .uV_step = 50000,
  103. .vsel_reg = ISL9305_LDO1OUT,
  104. .vsel_mask = 0x3f,
  105. .enable_reg = ISL9305_SYSTEM_PARAMETER,
  106. .enable_mask = ISL9305_LDO1_EN,
  107. .supply_name = "VINLDO1",
  108. .ops = &isl9305_ops,
  109. .owner = THIS_MODULE,
  110. },
  111. [ISL9305_LDO2] = {
  112. .name = "LDO2",
  113. .of_match = of_match_ptr("ldo2"),
  114. .regulators_node = of_match_ptr("regulators"),
  115. .n_voltages = 0x37,
  116. .min_uV = 900000,
  117. .uV_step = 50000,
  118. .vsel_reg = ISL9305_LDO2OUT,
  119. .vsel_mask = 0x3f,
  120. .enable_reg = ISL9305_SYSTEM_PARAMETER,
  121. .enable_mask = ISL9305_LDO2_EN,
  122. .supply_name = "VINLDO2",
  123. .ops = &isl9305_ops,
  124. .owner = THIS_MODULE,
  125. },
  126. };
  127. static const struct regmap_config isl9305_regmap = {
  128. .reg_bits = 8,
  129. .val_bits = 8,
  130. .max_register = ISL9305_MAX_REG,
  131. .cache_type = REGCACHE_RBTREE,
  132. };
  133. static int isl9305_i2c_probe(struct i2c_client *i2c,
  134. const struct i2c_device_id *id)
  135. {
  136. struct regulator_config config = { };
  137. struct isl9305_pdata *pdata = i2c->dev.platform_data;
  138. struct regulator_dev *rdev;
  139. struct regmap *regmap;
  140. int i, ret;
  141. regmap = devm_regmap_init_i2c(i2c, &isl9305_regmap);
  142. if (IS_ERR(regmap)) {
  143. ret = PTR_ERR(regmap);
  144. dev_err(&i2c->dev, "Failed to create regmap: %d\n", ret);
  145. return ret;
  146. }
  147. config.dev = &i2c->dev;
  148. for (i = 0; i < ARRAY_SIZE(isl9305_regulators); i++) {
  149. if (pdata)
  150. config.init_data = pdata->init_data[i];
  151. else
  152. config.init_data = NULL;
  153. rdev = devm_regulator_register(&i2c->dev,
  154. &isl9305_regulators[i],
  155. &config);
  156. if (IS_ERR(rdev)) {
  157. ret = PTR_ERR(rdev);
  158. dev_err(&i2c->dev, "Failed to register %s: %d\n",
  159. isl9305_regulators[i].name, ret);
  160. return ret;
  161. }
  162. }
  163. return 0;
  164. }
  165. #ifdef CONFIG_OF
  166. static const struct of_device_id isl9305_dt_ids[] = {
  167. { .compatible = "isl,isl9305" }, /* for backward compat., don't use */
  168. { .compatible = "isil,isl9305" },
  169. { .compatible = "isl,isl9305h" }, /* for backward compat., don't use */
  170. { .compatible = "isil,isl9305h" },
  171. {},
  172. };
  173. MODULE_DEVICE_TABLE(of, isl9305_dt_ids);
  174. #endif
  175. static const struct i2c_device_id isl9305_i2c_id[] = {
  176. { "isl9305", },
  177. { "isl9305h", },
  178. { }
  179. };
  180. MODULE_DEVICE_TABLE(i2c, isl9305_i2c_id);
  181. static struct i2c_driver isl9305_regulator_driver = {
  182. .driver = {
  183. .name = "isl9305",
  184. .of_match_table = of_match_ptr(isl9305_dt_ids),
  185. },
  186. .probe = isl9305_i2c_probe,
  187. .id_table = isl9305_i2c_id,
  188. };
  189. module_i2c_driver(isl9305_regulator_driver);
  190. MODULE_AUTHOR("Mark Brown");
  191. MODULE_DESCRIPTION("Intersil ISL9305 DCDC regulator");
  192. MODULE_LICENSE("GPL");