mt6323-core.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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/mt6323/core.h>
  21. #include <linux/mfd/mt6323/registers.h>
  22. static const struct mfd_cell mt6323_devs[] = {
  23. {
  24. .name = "mt6323-regulator",
  25. .of_compatible = "mediatek,mt6323-regulator"
  26. }, {
  27. .name = "mt6323-pmic",
  28. .of_compatible = "mediatek,mt6323-pmic"
  29. },
  30. };
  31. static int mt6323_probe(struct platform_device *pdev)
  32. {
  33. int ret;
  34. struct mt6323_chip *mt6323;
  35. mt6323 = devm_kzalloc(&pdev->dev, sizeof(*mt6323), GFP_KERNEL);
  36. if (!mt6323)
  37. return -ENOMEM;
  38. mt6323->dev = &pdev->dev;
  39. /*
  40. * mt6323 MFD is child device of soc pmic wrapper.
  41. * Regmap is set from its parent.
  42. */
  43. mt6323->regmap = dev_get_regmap(pdev->dev.parent, NULL);
  44. if (!mt6323->regmap)
  45. return -ENODEV;
  46. platform_set_drvdata(pdev, mt6323);
  47. ret = mfd_add_devices(&pdev->dev, -1, mt6323_devs,
  48. ARRAY_SIZE(mt6323_devs), NULL, 0, NULL);
  49. if (ret)
  50. dev_err(&pdev->dev, "failed to add child devices: %d\n", ret);
  51. return ret;
  52. }
  53. static int mt6323_remove(struct platform_device *pdev)
  54. {
  55. mfd_remove_devices(&pdev->dev);
  56. return 0;
  57. }
  58. static const struct of_device_id mt6323_of_match[] = {
  59. { .compatible = "mediatek,mt6323" },
  60. { }
  61. };
  62. MODULE_DEVICE_TABLE(of, mt6323_of_match);
  63. static struct platform_driver mt6323_driver = {
  64. .probe = mt6323_probe,
  65. .remove = mt6323_remove,
  66. .driver = {
  67. .name = "mt6323",
  68. .of_match_table = of_match_ptr(mt6323_of_match),
  69. },
  70. };
  71. module_platform_driver(mt6323_driver);
  72. MODULE_AUTHOR("Flora Fu, MediaTek");
  73. MODULE_DESCRIPTION("Driver for MediaTek MT6323 PMIC");
  74. MODULE_LICENSE("GPL");
  75. MODULE_ALIAS("platform:mt6323");