tps65086.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Copyright (C) 2015 Texas Instruments Incorporated - https://www.ti.com/
  3. * Andrew F. Davis <afd@ti.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  10. * kind, whether expressed or implied; without even the implied warranty
  11. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License version 2 for more details.
  13. *
  14. * Based on the TPS65912 driver
  15. */
  16. #include <linux/i2c.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/mfd/core.h>
  19. #include <linux/module.h>
  20. #include <linux/mfd/tps65086.h>
  21. static const struct mfd_cell tps65086_cells[] = {
  22. { .name = "tps65086-regulator", },
  23. { .name = "tps65086-gpio", },
  24. };
  25. static const struct regmap_range tps65086_yes_ranges[] = {
  26. regmap_reg_range(TPS65086_IRQ, TPS65086_IRQ),
  27. regmap_reg_range(TPS65086_PMICSTAT, TPS65086_SHUTDNSRC),
  28. regmap_reg_range(TPS65086_GPOCTRL, TPS65086_GPOCTRL),
  29. regmap_reg_range(TPS65086_PG_STATUS1, TPS65086_OC_STATUS),
  30. };
  31. static const struct regmap_access_table tps65086_volatile_table = {
  32. .yes_ranges = tps65086_yes_ranges,
  33. .n_yes_ranges = ARRAY_SIZE(tps65086_yes_ranges),
  34. };
  35. static const struct regmap_config tps65086_regmap_config = {
  36. .reg_bits = 8,
  37. .val_bits = 8,
  38. .cache_type = REGCACHE_RBTREE,
  39. .volatile_table = &tps65086_volatile_table,
  40. };
  41. static const struct regmap_irq tps65086_irqs[] = {
  42. REGMAP_IRQ_REG(TPS65086_IRQ_DIETEMP, 0, TPS65086_IRQ_DIETEMP_MASK),
  43. REGMAP_IRQ_REG(TPS65086_IRQ_SHUTDN, 0, TPS65086_IRQ_SHUTDN_MASK),
  44. REGMAP_IRQ_REG(TPS65086_IRQ_FAULT, 0, TPS65086_IRQ_FAULT_MASK),
  45. };
  46. static struct regmap_irq_chip tps65086_irq_chip = {
  47. .name = "tps65086",
  48. .status_base = TPS65086_IRQ,
  49. .mask_base = TPS65086_IRQ_MASK,
  50. .ack_base = TPS65086_IRQ,
  51. .init_ack_masked = true,
  52. .num_regs = 1,
  53. .irqs = tps65086_irqs,
  54. .num_irqs = ARRAY_SIZE(tps65086_irqs),
  55. };
  56. static const struct of_device_id tps65086_of_match_table[] = {
  57. { .compatible = "ti,tps65086", },
  58. { /* sentinel */ }
  59. };
  60. MODULE_DEVICE_TABLE(of, tps65086_of_match_table);
  61. static int tps65086_probe(struct i2c_client *client,
  62. const struct i2c_device_id *ids)
  63. {
  64. struct tps65086 *tps;
  65. unsigned int version;
  66. int ret;
  67. tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
  68. if (!tps)
  69. return -ENOMEM;
  70. i2c_set_clientdata(client, tps);
  71. tps->dev = &client->dev;
  72. tps->irq = client->irq;
  73. tps->regmap = devm_regmap_init_i2c(client, &tps65086_regmap_config);
  74. if (IS_ERR(tps->regmap)) {
  75. dev_err(tps->dev, "Failed to initialize register map\n");
  76. return PTR_ERR(tps->regmap);
  77. }
  78. ret = regmap_read(tps->regmap, TPS65086_DEVICEID, &version);
  79. if (ret) {
  80. dev_err(tps->dev, "Failed to read revision register\n");
  81. return ret;
  82. }
  83. dev_info(tps->dev, "Device: TPS65086%01lX, OTP: %c, Rev: %ld\n",
  84. (version & TPS65086_DEVICEID_PART_MASK),
  85. (char)((version & TPS65086_DEVICEID_OTP_MASK) >> 4) + 'A',
  86. (version & TPS65086_DEVICEID_REV_MASK) >> 6);
  87. ret = regmap_add_irq_chip(tps->regmap, tps->irq, IRQF_ONESHOT, 0,
  88. &tps65086_irq_chip, &tps->irq_data);
  89. if (ret) {
  90. dev_err(tps->dev, "Failed to register IRQ chip\n");
  91. return ret;
  92. }
  93. ret = mfd_add_devices(tps->dev, PLATFORM_DEVID_AUTO, tps65086_cells,
  94. ARRAY_SIZE(tps65086_cells), NULL, 0,
  95. regmap_irq_get_domain(tps->irq_data));
  96. if (ret) {
  97. regmap_del_irq_chip(tps->irq, tps->irq_data);
  98. return ret;
  99. }
  100. return 0;
  101. }
  102. static int tps65086_remove(struct i2c_client *client)
  103. {
  104. struct tps65086 *tps = i2c_get_clientdata(client);
  105. regmap_del_irq_chip(tps->irq, tps->irq_data);
  106. return 0;
  107. }
  108. static const struct i2c_device_id tps65086_id_table[] = {
  109. { "tps65086", 0 },
  110. { /* sentinel */ }
  111. };
  112. MODULE_DEVICE_TABLE(i2c, tps65086_id_table);
  113. static struct i2c_driver tps65086_driver = {
  114. .driver = {
  115. .name = "tps65086",
  116. .of_match_table = tps65086_of_match_table,
  117. },
  118. .probe = tps65086_probe,
  119. .remove = tps65086_remove,
  120. .id_table = tps65086_id_table,
  121. };
  122. module_i2c_driver(tps65086_driver);
  123. MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
  124. MODULE_DESCRIPTION("TPS65086 PMIC Driver");
  125. MODULE_LICENSE("GPL v2");