lp873x.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2016 Texas Instruments Incorporated - https://www.ti.com/
  4. *
  5. * Author: Keerthy <[email protected]>
  6. */
  7. #include <linux/interrupt.h>
  8. #include <linux/mfd/core.h>
  9. #include <linux/module.h>
  10. #include <linux/of_device.h>
  11. #include <linux/regmap.h>
  12. #include <linux/mfd/lp873x.h>
  13. static const struct regmap_config lp873x_regmap_config = {
  14. .reg_bits = 8,
  15. .val_bits = 8,
  16. .max_register = LP873X_REG_MAX,
  17. };
  18. static const struct mfd_cell lp873x_cells[] = {
  19. { .name = "lp873x-regulator", },
  20. { .name = "lp873x-gpio", },
  21. };
  22. static int lp873x_probe(struct i2c_client *client,
  23. const struct i2c_device_id *ids)
  24. {
  25. struct lp873x *lp873;
  26. int ret;
  27. unsigned int otpid;
  28. lp873 = devm_kzalloc(&client->dev, sizeof(*lp873), GFP_KERNEL);
  29. if (!lp873)
  30. return -ENOMEM;
  31. lp873->dev = &client->dev;
  32. lp873->regmap = devm_regmap_init_i2c(client, &lp873x_regmap_config);
  33. if (IS_ERR(lp873->regmap)) {
  34. ret = PTR_ERR(lp873->regmap);
  35. dev_err(lp873->dev,
  36. "Failed to initialize register map: %d\n", ret);
  37. return ret;
  38. }
  39. ret = regmap_read(lp873->regmap, LP873X_REG_OTP_REV, &otpid);
  40. if (ret) {
  41. dev_err(lp873->dev, "Failed to read OTP ID\n");
  42. return ret;
  43. }
  44. lp873->rev = otpid & LP873X_OTP_REV_OTP_ID;
  45. i2c_set_clientdata(client, lp873);
  46. ret = mfd_add_devices(lp873->dev, PLATFORM_DEVID_AUTO, lp873x_cells,
  47. ARRAY_SIZE(lp873x_cells), NULL, 0, NULL);
  48. return ret;
  49. }
  50. static const struct of_device_id of_lp873x_match_table[] = {
  51. { .compatible = "ti,lp8733", },
  52. { .compatible = "ti,lp8732", },
  53. {}
  54. };
  55. MODULE_DEVICE_TABLE(of, of_lp873x_match_table);
  56. static const struct i2c_device_id lp873x_id_table[] = {
  57. { "lp873x", 0 },
  58. { },
  59. };
  60. MODULE_DEVICE_TABLE(i2c, lp873x_id_table);
  61. static struct i2c_driver lp873x_driver = {
  62. .driver = {
  63. .name = "lp873x",
  64. .of_match_table = of_lp873x_match_table,
  65. },
  66. .probe = lp873x_probe,
  67. .id_table = lp873x_id_table,
  68. };
  69. module_i2c_driver(lp873x_driver);
  70. MODULE_AUTHOR("J Keerthy <[email protected]>");
  71. MODULE_DESCRIPTION("LP873X chip family Multi-Function Device driver");
  72. MODULE_LICENSE("GPL v2");