tps68470.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * TPS68470 chip Parent driver
  3. *
  4. * Copyright (C) 2017 Intel Corporation
  5. *
  6. * Authors:
  7. * Rajmohan Mani <rajmohan.mani@intel.com>
  8. * Tianshu Qiu <tian.shu.qiu@intel.com>
  9. * Jian Xu Zheng <jian.xu.zheng@intel.com>
  10. * Yuning Pu <yuning.pu@intel.com>
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation version 2.
  15. *
  16. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  17. * kind, whether express or implied; without even the implied warranty
  18. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. */
  21. #include <linux/acpi.h>
  22. #include <linux/delay.h>
  23. #include <linux/i2c.h>
  24. #include <linux/init.h>
  25. #include <linux/mfd/core.h>
  26. #include <linux/mfd/tps68470.h>
  27. #include <linux/regmap.h>
  28. static const struct mfd_cell tps68470s[] = {
  29. { .name = "tps68470-gpio" },
  30. { .name = "tps68470_pmic_opregion" },
  31. };
  32. static const struct regmap_config tps68470_regmap_config = {
  33. .reg_bits = 8,
  34. .val_bits = 8,
  35. .max_register = TPS68470_REG_MAX,
  36. };
  37. static int tps68470_chip_init(struct device *dev, struct regmap *regmap)
  38. {
  39. unsigned int version;
  40. int ret;
  41. /* Force software reset */
  42. ret = regmap_write(regmap, TPS68470_REG_RESET, TPS68470_REG_RESET_MASK);
  43. if (ret)
  44. return ret;
  45. ret = regmap_read(regmap, TPS68470_REG_REVID, &version);
  46. if (ret) {
  47. dev_err(dev, "Failed to read revision register: %d\n", ret);
  48. return ret;
  49. }
  50. dev_info(dev, "TPS68470 REVID: 0x%x\n", version);
  51. return 0;
  52. }
  53. static int tps68470_probe(struct i2c_client *client)
  54. {
  55. struct device *dev = &client->dev;
  56. struct regmap *regmap;
  57. int ret;
  58. regmap = devm_regmap_init_i2c(client, &tps68470_regmap_config);
  59. if (IS_ERR(regmap)) {
  60. dev_err(dev, "devm_regmap_init_i2c Error %ld\n",
  61. PTR_ERR(regmap));
  62. return PTR_ERR(regmap);
  63. }
  64. i2c_set_clientdata(client, regmap);
  65. ret = tps68470_chip_init(dev, regmap);
  66. if (ret < 0) {
  67. dev_err(dev, "TPS68470 Init Error %d\n", ret);
  68. return ret;
  69. }
  70. ret = devm_mfd_add_devices(dev, PLATFORM_DEVID_NONE, tps68470s,
  71. ARRAY_SIZE(tps68470s), NULL, 0, NULL);
  72. if (ret < 0) {
  73. dev_err(dev, "devm_mfd_add_devices failed: %d\n", ret);
  74. return ret;
  75. }
  76. return 0;
  77. }
  78. static const struct acpi_device_id tps68470_acpi_ids[] = {
  79. {"INT3472"},
  80. {},
  81. };
  82. MODULE_DEVICE_TABLE(acpi, tps68470_acpi_ids);
  83. static struct i2c_driver tps68470_driver = {
  84. .driver = {
  85. .name = "tps68470",
  86. .acpi_match_table = tps68470_acpi_ids,
  87. },
  88. .probe_new = tps68470_probe,
  89. };
  90. builtin_i2c_driver(tps68470_driver);