pm2250_spmi.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2020, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/of.h>
  6. #include <linux/of_platform.h>
  7. #include <linux/module.h>
  8. #include <linux/init.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/pm.h>
  11. #include <linux/regmap.h>
  12. #include <linux/slab.h>
  13. /**
  14. * @regmap: regmap used to access PMIC registers
  15. */
  16. struct pm2250_spmi {
  17. struct regmap *regmap;
  18. };
  19. static const struct of_device_id pm2250_id_table[] = {
  20. { .compatible = "qcom,pm2250-spmi" },
  21. { },
  22. };
  23. MODULE_DEVICE_TABLE(of, pm2250_id_table);
  24. int pm2250_spmi_write(struct device *dev, int reg, int value)
  25. {
  26. int rc;
  27. struct pm2250_spmi *spmi_dd;
  28. if (!of_device_is_compatible(dev->of_node, "qcom,pm2250-spmi")) {
  29. pr_err("%s: Device node is invalid\n", __func__);
  30. return -EINVAL;
  31. }
  32. spmi_dd = dev_get_drvdata(dev);
  33. if (!spmi_dd)
  34. return -EINVAL;
  35. rc = regmap_write(spmi_dd->regmap, reg, value);
  36. if (rc)
  37. dev_err(dev, "%s: Write to PMIC register failed\n", __func__);
  38. return rc;
  39. }
  40. EXPORT_SYMBOL(pm2250_spmi_write);
  41. static int pm2250_spmi_probe(struct platform_device *pdev)
  42. {
  43. struct pm2250_spmi *spmi_dd;
  44. const struct of_device_id *match;
  45. match = of_match_node(pm2250_id_table, pdev->dev.of_node);
  46. if (!match)
  47. return -ENXIO;
  48. spmi_dd = devm_kzalloc(&pdev->dev, sizeof(*spmi_dd), GFP_KERNEL);
  49. if (spmi_dd == NULL)
  50. return -ENOMEM;
  51. spmi_dd->regmap = dev_get_regmap(pdev->dev.parent, NULL);
  52. if (!spmi_dd->regmap) {
  53. dev_err(&pdev->dev, "Parent regmap unavailable.\n");
  54. return -ENXIO;
  55. }
  56. platform_set_drvdata(pdev, spmi_dd);
  57. dev_dbg(&pdev->dev, "Probe success !!\n");
  58. return 0;
  59. }
  60. static int pm2250_spmi_remove(struct platform_device *pdev)
  61. {
  62. of_platform_depopulate(&pdev->dev);
  63. return 0;
  64. }
  65. static struct platform_driver pm2250_spmi_driver = {
  66. .probe = pm2250_spmi_probe,
  67. .remove = pm2250_spmi_remove,
  68. .driver = {
  69. .name = "pm2250-spmi",
  70. .of_match_table = pm2250_id_table,
  71. },
  72. };
  73. module_platform_driver(pm2250_spmi_driver);
  74. MODULE_ALIAS("platform:pm2250-spmi");
  75. MODULE_DESCRIPTION("PMIC SPMI driver");
  76. MODULE_LICENSE("GPL v2");