tps65086.c 3.8 KB

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