mt6397-core.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (c) 2014 MediaTek Inc.
  3. * Author: Flora Fu, MediaTek
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #include <linux/interrupt.h>
  15. #include <linux/module.h>
  16. #include <linux/of_device.h>
  17. #include <linux/of_irq.h>
  18. #include <linux/regmap.h>
  19. #include <linux/mfd/core.h>
  20. #include <linux/mfd/mt6397/core.h>
  21. #include <linux/mfd/mt6397/registers.h>
  22. static const struct mfd_cell mt6397_devs[] = {
  23. {
  24. .name = "mt6397-pmic",
  25. .of_compatible = "mediatek,mt6397-pmic",
  26. }, {
  27. .name = "mt6397-regulator",
  28. .of_compatible = "mediatek,mt6397-regulator",
  29. }, {
  30. .name = "mt6397-pinctrl",
  31. .of_compatible = "mediatek,mt6397-pinctrl",
  32. }, {
  33. .name = "mt6397-codec",
  34. .of_compatible = "mediatek,mt6397-codec",
  35. },
  36. };
  37. static int mt6397_probe(struct platform_device *pdev)
  38. {
  39. int ret;
  40. struct mt6397_chip *mt6397;
  41. mt6397 = devm_kzalloc(&pdev->dev, sizeof(*mt6397), GFP_KERNEL);
  42. if (!mt6397)
  43. return -ENOMEM;
  44. mt6397->dev = &pdev->dev;
  45. /*
  46. * mt6397 MFD is child device of soc pmic wrapper.
  47. * Regmap is set from its parent.
  48. */
  49. mt6397->regmap = dev_get_regmap(pdev->dev.parent, NULL);
  50. if (!mt6397->regmap)
  51. return -ENODEV;
  52. platform_set_drvdata(pdev, mt6397);
  53. mt6397->irq = platform_get_irq(pdev, 0);
  54. if (mt6397->irq <= 0)
  55. return -EINVAL;
  56. ret = mfd_add_devices(&pdev->dev, -1, mt6397_devs,
  57. ARRAY_SIZE(mt6397_devs), NULL, 0, NULL);
  58. if (ret)
  59. dev_err(&pdev->dev, "failed to add child devices: %d\n", ret);
  60. return ret;
  61. }
  62. static int mt6397_remove(struct platform_device *pdev)
  63. {
  64. mfd_remove_devices(&pdev->dev);
  65. return 0;
  66. }
  67. static const struct of_device_id mt6397_of_match[] = {
  68. { .compatible = "mediatek,mt6397" },
  69. { }
  70. };
  71. MODULE_DEVICE_TABLE(of, mt6397_of_match);
  72. static struct platform_driver mt6397_driver = {
  73. .probe = mt6397_probe,
  74. .remove = mt6397_remove,
  75. .driver = {
  76. .name = "mt6397",
  77. .of_match_table = of_match_ptr(mt6397_of_match),
  78. },
  79. };
  80. module_platform_driver(mt6397_driver);
  81. MODULE_AUTHOR("Flora Fu, MediaTek");
  82. MODULE_DESCRIPTION("Driver for MediaTek MT6397 PMIC");
  83. MODULE_LICENSE("GPL");
  84. MODULE_ALIAS("platform:mt6397");