tps65090.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*
  2. * Core driver for TI TPS65090 PMIC family
  3. *
  4. * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #include <linux/interrupt.h>
  16. #include <linux/irq.h>
  17. #include <linux/kernel.h>
  18. #include <linux/module.h>
  19. #include <linux/mutex.h>
  20. #include <linux/slab.h>
  21. #include <linux/i2c.h>
  22. #include <linux/mfd/core.h>
  23. #include <linux/mfd/tps65090.h>
  24. #include <linux/of.h>
  25. #include <linux/of_device.h>
  26. #include <linux/err.h>
  27. #define NUM_INT_REG 2
  28. #define TOTAL_NUM_REG 0x18
  29. /* interrupt status registers */
  30. #define TPS65090_INT_STS 0x0
  31. #define TPS65090_INT_STS2 0x1
  32. /* interrupt mask registers */
  33. #define TPS65090_INT_MSK 0x2
  34. #define TPS65090_INT_MSK2 0x3
  35. #define TPS65090_INT1_MASK_VAC_STATUS_CHANGE 1
  36. #define TPS65090_INT1_MASK_VSYS_STATUS_CHANGE 2
  37. #define TPS65090_INT1_MASK_BAT_STATUS_CHANGE 3
  38. #define TPS65090_INT1_MASK_CHARGING_STATUS_CHANGE 4
  39. #define TPS65090_INT1_MASK_CHARGING_COMPLETE 5
  40. #define TPS65090_INT1_MASK_OVERLOAD_DCDC1 6
  41. #define TPS65090_INT1_MASK_OVERLOAD_DCDC2 7
  42. #define TPS65090_INT2_MASK_OVERLOAD_DCDC3 0
  43. #define TPS65090_INT2_MASK_OVERLOAD_FET1 1
  44. #define TPS65090_INT2_MASK_OVERLOAD_FET2 2
  45. #define TPS65090_INT2_MASK_OVERLOAD_FET3 3
  46. #define TPS65090_INT2_MASK_OVERLOAD_FET4 4
  47. #define TPS65090_INT2_MASK_OVERLOAD_FET5 5
  48. #define TPS65090_INT2_MASK_OVERLOAD_FET6 6
  49. #define TPS65090_INT2_MASK_OVERLOAD_FET7 7
  50. static struct mfd_cell tps65090s[] = {
  51. {
  52. .name = "tps65090-pmic",
  53. },
  54. {
  55. .name = "tps65090-charger",
  56. },
  57. };
  58. static const struct regmap_irq tps65090_irqs[] = {
  59. /* INT1 IRQs*/
  60. [TPS65090_IRQ_VAC_STATUS_CHANGE] = {
  61. .mask = TPS65090_INT1_MASK_VAC_STATUS_CHANGE,
  62. },
  63. [TPS65090_IRQ_VSYS_STATUS_CHANGE] = {
  64. .mask = TPS65090_INT1_MASK_VSYS_STATUS_CHANGE,
  65. },
  66. [TPS65090_IRQ_BAT_STATUS_CHANGE] = {
  67. .mask = TPS65090_INT1_MASK_BAT_STATUS_CHANGE,
  68. },
  69. [TPS65090_IRQ_CHARGING_STATUS_CHANGE] = {
  70. .mask = TPS65090_INT1_MASK_CHARGING_STATUS_CHANGE,
  71. },
  72. [TPS65090_IRQ_CHARGING_COMPLETE] = {
  73. .mask = TPS65090_INT1_MASK_CHARGING_COMPLETE,
  74. },
  75. [TPS65090_IRQ_OVERLOAD_DCDC1] = {
  76. .mask = TPS65090_INT1_MASK_OVERLOAD_DCDC1,
  77. },
  78. [TPS65090_IRQ_OVERLOAD_DCDC2] = {
  79. .mask = TPS65090_INT1_MASK_OVERLOAD_DCDC2,
  80. },
  81. /* INT2 IRQs*/
  82. [TPS65090_IRQ_OVERLOAD_DCDC3] = {
  83. .reg_offset = 1,
  84. .mask = TPS65090_INT2_MASK_OVERLOAD_DCDC3,
  85. },
  86. [TPS65090_IRQ_OVERLOAD_FET1] = {
  87. .reg_offset = 1,
  88. .mask = TPS65090_INT2_MASK_OVERLOAD_FET1,
  89. },
  90. [TPS65090_IRQ_OVERLOAD_FET2] = {
  91. .reg_offset = 1,
  92. .mask = TPS65090_INT2_MASK_OVERLOAD_FET2,
  93. },
  94. [TPS65090_IRQ_OVERLOAD_FET3] = {
  95. .reg_offset = 1,
  96. .mask = TPS65090_INT2_MASK_OVERLOAD_FET3,
  97. },
  98. [TPS65090_IRQ_OVERLOAD_FET4] = {
  99. .reg_offset = 1,
  100. .mask = TPS65090_INT2_MASK_OVERLOAD_FET4,
  101. },
  102. [TPS65090_IRQ_OVERLOAD_FET5] = {
  103. .reg_offset = 1,
  104. .mask = TPS65090_INT2_MASK_OVERLOAD_FET5,
  105. },
  106. [TPS65090_IRQ_OVERLOAD_FET6] = {
  107. .reg_offset = 1,
  108. .mask = TPS65090_INT2_MASK_OVERLOAD_FET6,
  109. },
  110. [TPS65090_IRQ_OVERLOAD_FET7] = {
  111. .reg_offset = 1,
  112. .mask = TPS65090_INT2_MASK_OVERLOAD_FET7,
  113. },
  114. };
  115. static struct regmap_irq_chip tps65090_irq_chip = {
  116. .name = "tps65090",
  117. .irqs = tps65090_irqs,
  118. .num_irqs = ARRAY_SIZE(tps65090_irqs),
  119. .num_regs = NUM_INT_REG,
  120. .status_base = TPS65090_INT_STS,
  121. .mask_base = TPS65090_INT_MSK,
  122. .mask_invert = true,
  123. };
  124. static bool is_volatile_reg(struct device *dev, unsigned int reg)
  125. {
  126. if ((reg == TPS65090_INT_STS) || (reg == TPS65090_INT_STS2))
  127. return true;
  128. else
  129. return false;
  130. }
  131. static const struct regmap_config tps65090_regmap_config = {
  132. .reg_bits = 8,
  133. .val_bits = 8,
  134. .max_register = TOTAL_NUM_REG,
  135. .num_reg_defaults_raw = TOTAL_NUM_REG,
  136. .cache_type = REGCACHE_RBTREE,
  137. .volatile_reg = is_volatile_reg,
  138. };
  139. #ifdef CONFIG_OF
  140. static const struct of_device_id tps65090_of_match[] = {
  141. { .compatible = "ti,tps65090",},
  142. {},
  143. };
  144. MODULE_DEVICE_TABLE(of, tps65090_of_match);
  145. #endif
  146. static int tps65090_i2c_probe(struct i2c_client *client,
  147. const struct i2c_device_id *id)
  148. {
  149. struct tps65090_platform_data *pdata = client->dev.platform_data;
  150. int irq_base = 0;
  151. struct tps65090 *tps65090;
  152. int ret;
  153. if (!pdata && !client->dev.of_node) {
  154. dev_err(&client->dev,
  155. "tps65090 requires platform data or of_node\n");
  156. return -EINVAL;
  157. }
  158. if (pdata)
  159. irq_base = pdata->irq_base;
  160. tps65090 = devm_kzalloc(&client->dev, sizeof(*tps65090), GFP_KERNEL);
  161. if (!tps65090) {
  162. dev_err(&client->dev, "mem alloc for tps65090 failed\n");
  163. return -ENOMEM;
  164. }
  165. tps65090->dev = &client->dev;
  166. i2c_set_clientdata(client, tps65090);
  167. tps65090->rmap = devm_regmap_init_i2c(client, &tps65090_regmap_config);
  168. if (IS_ERR(tps65090->rmap)) {
  169. ret = PTR_ERR(tps65090->rmap);
  170. dev_err(&client->dev, "regmap_init failed with err: %d\n", ret);
  171. return ret;
  172. }
  173. if (client->irq) {
  174. ret = regmap_add_irq_chip(tps65090->rmap, client->irq,
  175. IRQF_ONESHOT | IRQF_TRIGGER_LOW, irq_base,
  176. &tps65090_irq_chip, &tps65090->irq_data);
  177. if (ret) {
  178. dev_err(&client->dev,
  179. "IRQ init failed with err: %d\n", ret);
  180. return ret;
  181. }
  182. }
  183. ret = mfd_add_devices(tps65090->dev, -1, tps65090s,
  184. ARRAY_SIZE(tps65090s), NULL,
  185. 0, regmap_irq_get_domain(tps65090->irq_data));
  186. if (ret) {
  187. dev_err(&client->dev, "add mfd devices failed with err: %d\n",
  188. ret);
  189. goto err_irq_exit;
  190. }
  191. return 0;
  192. err_irq_exit:
  193. if (client->irq)
  194. regmap_del_irq_chip(client->irq, tps65090->irq_data);
  195. return ret;
  196. }
  197. static int tps65090_i2c_remove(struct i2c_client *client)
  198. {
  199. struct tps65090 *tps65090 = i2c_get_clientdata(client);
  200. mfd_remove_devices(tps65090->dev);
  201. if (client->irq)
  202. regmap_del_irq_chip(client->irq, tps65090->irq_data);
  203. return 0;
  204. }
  205. static const struct i2c_device_id tps65090_id_table[] = {
  206. { "tps65090", 0 },
  207. { },
  208. };
  209. MODULE_DEVICE_TABLE(i2c, tps65090_id_table);
  210. static struct i2c_driver tps65090_driver = {
  211. .driver = {
  212. .name = "tps65090",
  213. .owner = THIS_MODULE,
  214. .of_match_table = of_match_ptr(tps65090_of_match),
  215. },
  216. .probe = tps65090_i2c_probe,
  217. .remove = tps65090_i2c_remove,
  218. .id_table = tps65090_id_table,
  219. };
  220. static int __init tps65090_init(void)
  221. {
  222. return i2c_add_driver(&tps65090_driver);
  223. }
  224. subsys_initcall(tps65090_init);
  225. static void __exit tps65090_exit(void)
  226. {
  227. i2c_del_driver(&tps65090_driver);
  228. }
  229. module_exit(tps65090_exit);
  230. MODULE_DESCRIPTION("TPS65090 core driver");
  231. MODULE_AUTHOR("Venu Byravarasu <vbyravarasu@nvidia.com>");
  232. MODULE_LICENSE("GPL v2");