tps65912-core.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Core functions for TI TPS65912x PMICs
  3. *
  4. * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
  5. * Andrew F. Davis <afd@ti.com>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  12. * kind, whether expressed or implied; without even the implied warranty
  13. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License version 2 for more details.
  15. *
  16. * Based on the TPS65218 driver and the previous TPS65912 driver by
  17. * Margarita Olaya Cabrera <magi@slimlogic.co.uk>
  18. */
  19. #include <linux/interrupt.h>
  20. #include <linux/mfd/core.h>
  21. #include <linux/module.h>
  22. #include <linux/mfd/tps65912.h>
  23. static const struct mfd_cell tps65912_cells[] = {
  24. { .name = "tps65912-regulator", },
  25. { .name = "tps65912-gpio", },
  26. };
  27. static const struct regmap_irq tps65912_irqs[] = {
  28. /* INT_STS IRQs */
  29. REGMAP_IRQ_REG(TPS65912_IRQ_PWRHOLD_F, 0, TPS65912_INT_STS_PWRHOLD_F),
  30. REGMAP_IRQ_REG(TPS65912_IRQ_VMON, 0, TPS65912_INT_STS_VMON),
  31. REGMAP_IRQ_REG(TPS65912_IRQ_PWRON, 0, TPS65912_INT_STS_PWRON),
  32. REGMAP_IRQ_REG(TPS65912_IRQ_PWRON_LP, 0, TPS65912_INT_STS_PWRON_LP),
  33. REGMAP_IRQ_REG(TPS65912_IRQ_PWRHOLD_R, 0, TPS65912_INT_STS_PWRHOLD_R),
  34. REGMAP_IRQ_REG(TPS65912_IRQ_HOTDIE, 0, TPS65912_INT_STS_HOTDIE),
  35. REGMAP_IRQ_REG(TPS65912_IRQ_GPIO1_R, 0, TPS65912_INT_STS_GPIO1_R),
  36. REGMAP_IRQ_REG(TPS65912_IRQ_GPIO1_F, 0, TPS65912_INT_STS_GPIO1_F),
  37. /* INT_STS2 IRQs */
  38. REGMAP_IRQ_REG(TPS65912_IRQ_GPIO2_R, 1, TPS65912_INT_STS2_GPIO2_R),
  39. REGMAP_IRQ_REG(TPS65912_IRQ_GPIO2_F, 1, TPS65912_INT_STS2_GPIO2_F),
  40. REGMAP_IRQ_REG(TPS65912_IRQ_GPIO3_R, 1, TPS65912_INT_STS2_GPIO3_R),
  41. REGMAP_IRQ_REG(TPS65912_IRQ_GPIO3_F, 1, TPS65912_INT_STS2_GPIO3_F),
  42. REGMAP_IRQ_REG(TPS65912_IRQ_GPIO4_R, 1, TPS65912_INT_STS2_GPIO4_R),
  43. REGMAP_IRQ_REG(TPS65912_IRQ_GPIO4_F, 1, TPS65912_INT_STS2_GPIO4_F),
  44. REGMAP_IRQ_REG(TPS65912_IRQ_GPIO5_R, 1, TPS65912_INT_STS2_GPIO5_R),
  45. REGMAP_IRQ_REG(TPS65912_IRQ_GPIO5_F, 1, TPS65912_INT_STS2_GPIO5_F),
  46. /* INT_STS3 IRQs */
  47. REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_DCDC1, 2, TPS65912_INT_STS3_PGOOD_DCDC1),
  48. REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_DCDC2, 2, TPS65912_INT_STS3_PGOOD_DCDC2),
  49. REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_DCDC3, 2, TPS65912_INT_STS3_PGOOD_DCDC3),
  50. REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_DCDC4, 2, TPS65912_INT_STS3_PGOOD_DCDC4),
  51. REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO1, 2, TPS65912_INT_STS3_PGOOD_LDO1),
  52. REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO2, 2, TPS65912_INT_STS3_PGOOD_LDO2),
  53. REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO3, 2, TPS65912_INT_STS3_PGOOD_LDO3),
  54. REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO4, 2, TPS65912_INT_STS3_PGOOD_LDO4),
  55. /* INT_STS4 IRQs */
  56. REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO5, 3, TPS65912_INT_STS4_PGOOD_LDO5),
  57. REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO6, 3, TPS65912_INT_STS4_PGOOD_LDO6),
  58. REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO7, 3, TPS65912_INT_STS4_PGOOD_LDO7),
  59. REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO8, 3, TPS65912_INT_STS4_PGOOD_LDO8),
  60. REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO9, 3, TPS65912_INT_STS4_PGOOD_LDO9),
  61. REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO10, 3, TPS65912_INT_STS4_PGOOD_LDO10),
  62. };
  63. static struct regmap_irq_chip tps65912_irq_chip = {
  64. .name = "tps65912",
  65. .irqs = tps65912_irqs,
  66. .num_irqs = ARRAY_SIZE(tps65912_irqs),
  67. .num_regs = 4,
  68. .irq_reg_stride = 2,
  69. .mask_base = TPS65912_INT_MSK,
  70. .status_base = TPS65912_INT_STS,
  71. .ack_base = TPS65912_INT_STS,
  72. .init_ack_masked = true,
  73. };
  74. int tps65912_device_init(struct tps65912 *tps)
  75. {
  76. int ret;
  77. ret = regmap_add_irq_chip(tps->regmap, tps->irq, IRQF_ONESHOT, 0,
  78. &tps65912_irq_chip, &tps->irq_data);
  79. if (ret)
  80. return ret;
  81. ret = mfd_add_devices(tps->dev, PLATFORM_DEVID_AUTO, tps65912_cells,
  82. ARRAY_SIZE(tps65912_cells), NULL, 0,
  83. regmap_irq_get_domain(tps->irq_data));
  84. if (ret) {
  85. regmap_del_irq_chip(tps->irq, tps->irq_data);
  86. return ret;
  87. }
  88. return 0;
  89. }
  90. EXPORT_SYMBOL_GPL(tps65912_device_init);
  91. int tps65912_device_exit(struct tps65912 *tps)
  92. {
  93. regmap_del_irq_chip(tps->irq, tps->irq_data);
  94. return 0;
  95. }
  96. EXPORT_SYMBOL_GPL(tps65912_device_exit);
  97. MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
  98. MODULE_DESCRIPTION("TPS65912x MFD Driver");
  99. MODULE_LICENSE("GPL v2");