lp873x.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (C) 2016 Texas Instruments Incorporated - https://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. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  11. * kind, whether express or implied; without even the implied warranty
  12. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <linux/interrupt.h>
  16. #include <linux/mfd/core.h>
  17. #include <linux/module.h>
  18. #include <linux/of_device.h>
  19. #include <linux/regmap.h>
  20. #include <linux/mfd/lp873x.h>
  21. static const struct regmap_config lp873x_regmap_config = {
  22. .reg_bits = 8,
  23. .val_bits = 8,
  24. .max_register = LP873X_REG_MAX,
  25. };
  26. static const struct mfd_cell lp873x_cells[] = {
  27. { .name = "lp873x-regulator", },
  28. { .name = "lp873x-gpio", },
  29. };
  30. static int lp873x_probe(struct i2c_client *client,
  31. const struct i2c_device_id *ids)
  32. {
  33. struct lp873x *lp873;
  34. int ret;
  35. unsigned int otpid;
  36. lp873 = devm_kzalloc(&client->dev, sizeof(*lp873), GFP_KERNEL);
  37. if (!lp873)
  38. return -ENOMEM;
  39. lp873->dev = &client->dev;
  40. lp873->regmap = devm_regmap_init_i2c(client, &lp873x_regmap_config);
  41. if (IS_ERR(lp873->regmap)) {
  42. ret = PTR_ERR(lp873->regmap);
  43. dev_err(lp873->dev,
  44. "Failed to initialize register map: %d\n", ret);
  45. return ret;
  46. }
  47. ret = regmap_read(lp873->regmap, LP873X_REG_OTP_REV, &otpid);
  48. if (ret) {
  49. dev_err(lp873->dev, "Failed to read OTP ID\n");
  50. return ret;
  51. }
  52. lp873->rev = otpid & LP873X_OTP_REV_OTP_ID;
  53. i2c_set_clientdata(client, lp873);
  54. ret = mfd_add_devices(lp873->dev, PLATFORM_DEVID_AUTO, lp873x_cells,
  55. ARRAY_SIZE(lp873x_cells), NULL, 0, NULL);
  56. return ret;
  57. }
  58. static const struct of_device_id of_lp873x_match_table[] = {
  59. { .compatible = "ti,lp8733", },
  60. { .compatible = "ti,lp8732", },
  61. {}
  62. };
  63. MODULE_DEVICE_TABLE(of, of_lp873x_match_table);
  64. static const struct i2c_device_id lp873x_id_table[] = {
  65. { "lp873x", 0 },
  66. { },
  67. };
  68. MODULE_DEVICE_TABLE(i2c, lp873x_id_table);
  69. static struct i2c_driver lp873x_driver = {
  70. .driver = {
  71. .name = "lp873x",
  72. .of_match_table = of_lp873x_match_table,
  73. },
  74. .probe = lp873x_probe,
  75. .id_table = lp873x_id_table,
  76. };
  77. module_i2c_driver(lp873x_driver);
  78. MODULE_AUTHOR("J Keerthy <j-keerthy@ti.com>");
  79. MODULE_DESCRIPTION("LP873X chip family Multi-Function Device driver");
  80. MODULE_LICENSE("GPL v2");