lp87565.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
  3. *
  4. * Author: Keerthy <j-keerthy@ti.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation version 2.
  9. */
  10. #include <linux/interrupt.h>
  11. #include <linux/mfd/core.h>
  12. #include <linux/module.h>
  13. #include <linux/of_device.h>
  14. #include <linux/regmap.h>
  15. #include <linux/mfd/lp87565.h>
  16. static const struct regmap_config lp87565_regmap_config = {
  17. .reg_bits = 8,
  18. .val_bits = 8,
  19. .max_register = LP87565_REG_MAX,
  20. };
  21. static const struct mfd_cell lp87565_cells[] = {
  22. { .name = "lp87565-q1-regulator", },
  23. { .name = "lp87565-q1-gpio", },
  24. };
  25. static const struct of_device_id of_lp87565_match_table[] = {
  26. { .compatible = "ti,lp87565", },
  27. {
  28. .compatible = "ti,lp87565-q1",
  29. .data = (void *)LP87565_DEVICE_TYPE_LP87565_Q1,
  30. },
  31. {}
  32. };
  33. MODULE_DEVICE_TABLE(of, of_lp87565_match_table);
  34. static int lp87565_probe(struct i2c_client *client,
  35. const struct i2c_device_id *ids)
  36. {
  37. struct lp87565 *lp87565;
  38. const struct of_device_id *of_id;
  39. int ret;
  40. unsigned int otpid;
  41. lp87565 = devm_kzalloc(&client->dev, sizeof(*lp87565), GFP_KERNEL);
  42. if (!lp87565)
  43. return -ENOMEM;
  44. lp87565->dev = &client->dev;
  45. lp87565->regmap = devm_regmap_init_i2c(client, &lp87565_regmap_config);
  46. if (IS_ERR(lp87565->regmap)) {
  47. ret = PTR_ERR(lp87565->regmap);
  48. dev_err(lp87565->dev,
  49. "Failed to initialize register map: %d\n", ret);
  50. return ret;
  51. }
  52. ret = regmap_read(lp87565->regmap, LP87565_REG_OTP_REV, &otpid);
  53. if (ret) {
  54. dev_err(lp87565->dev, "Failed to read OTP ID\n");
  55. return ret;
  56. }
  57. lp87565->rev = otpid & LP87565_OTP_REV_OTP_ID;
  58. of_id = of_match_device(of_lp87565_match_table, &client->dev);
  59. if (of_id)
  60. lp87565->dev_type = (enum lp87565_device_type)of_id->data;
  61. i2c_set_clientdata(client, lp87565);
  62. return devm_mfd_add_devices(lp87565->dev, PLATFORM_DEVID_AUTO,
  63. lp87565_cells, ARRAY_SIZE(lp87565_cells),
  64. NULL, 0, NULL);
  65. }
  66. static const struct i2c_device_id lp87565_id_table[] = {
  67. { "lp87565-q1", 0 },
  68. { },
  69. };
  70. MODULE_DEVICE_TABLE(i2c, lp87565_id_table);
  71. static struct i2c_driver lp87565_driver = {
  72. .driver = {
  73. .name = "lp87565",
  74. .of_match_table = of_lp87565_match_table,
  75. },
  76. .probe = lp87565_probe,
  77. .id_table = lp87565_id_table,
  78. };
  79. module_i2c_driver(lp87565_driver);
  80. MODULE_AUTHOR("J Keerthy <j-keerthy@ti.com>");
  81. MODULE_DESCRIPTION("lp87565 chip family Multi-Function Device driver");
  82. MODULE_LICENSE("GPL v2");