bcm2835-pm.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * PM MFD driver for Broadcom BCM2835
  4. *
  5. * This driver binds to the PM block and creates the MFD device for
  6. * the WDT and power drivers.
  7. */
  8. #include <linux/delay.h>
  9. #include <linux/io.h>
  10. #include <linux/mfd/bcm2835-pm.h>
  11. #include <linux/mfd/core.h>
  12. #include <linux/module.h>
  13. #include <linux/of_address.h>
  14. #include <linux/of_platform.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/types.h>
  17. #include <linux/watchdog.h>
  18. static const struct mfd_cell bcm2835_pm_devs[] = {
  19. { .name = "bcm2835-wdt" },
  20. };
  21. static const struct mfd_cell bcm2835_power_devs[] = {
  22. { .name = "bcm2835-power" },
  23. };
  24. static int bcm2835_pm_probe(struct platform_device *pdev)
  25. {
  26. struct resource *res;
  27. struct device *dev = &pdev->dev;
  28. struct bcm2835_pm *pm;
  29. int ret;
  30. pm = devm_kzalloc(dev, sizeof(*pm), GFP_KERNEL);
  31. if (!pm)
  32. return -ENOMEM;
  33. platform_set_drvdata(pdev, pm);
  34. pm->dev = dev;
  35. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  36. pm->base = devm_ioremap_resource(dev, res);
  37. if (IS_ERR(pm->base))
  38. return PTR_ERR(pm->base);
  39. ret = devm_mfd_add_devices(dev, -1,
  40. bcm2835_pm_devs, ARRAY_SIZE(bcm2835_pm_devs),
  41. NULL, 0, NULL);
  42. if (ret)
  43. return ret;
  44. /* We'll use the presence of the AXI ASB regs in the
  45. * bcm2835-pm binding as the key for whether we can reference
  46. * the full PM register range and support power domains.
  47. */
  48. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  49. if (res) {
  50. pm->asb = devm_ioremap_resource(dev, res);
  51. if (IS_ERR(pm->asb))
  52. return PTR_ERR(pm->asb);
  53. ret = devm_mfd_add_devices(dev, -1,
  54. bcm2835_power_devs,
  55. ARRAY_SIZE(bcm2835_power_devs),
  56. NULL, 0, NULL);
  57. if (ret)
  58. return ret;
  59. }
  60. return 0;
  61. }
  62. static const struct of_device_id bcm2835_pm_of_match[] = {
  63. { .compatible = "brcm,bcm2835-pm-wdt", },
  64. { .compatible = "brcm,bcm2835-pm", },
  65. {},
  66. };
  67. MODULE_DEVICE_TABLE(of, bcm2835_pm_of_match);
  68. static struct platform_driver bcm2835_pm_driver = {
  69. .probe = bcm2835_pm_probe,
  70. .driver = {
  71. .name = "bcm2835-pm",
  72. .of_match_table = bcm2835_pm_of_match,
  73. },
  74. };
  75. module_platform_driver(bcm2835_pm_driver);
  76. MODULE_AUTHOR("Eric Anholt <eric@anholt.net>");
  77. MODULE_DESCRIPTION("Driver for Broadcom BCM2835 PM MFD");
  78. MODULE_LICENSE("GPL");