omap-ocp2scp.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * omap-ocp2scp.c - transform ocp interface protocol to scp protocol
  4. *
  5. * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com
  6. * Author: Kishon Vijay Abraham I <kishon@ti.com>
  7. */
  8. #include <linux/io.h>
  9. #include <linux/module.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/err.h>
  12. #include <linux/pm_runtime.h>
  13. #include <linux/of.h>
  14. #include <linux/of_platform.h>
  15. #define OCP2SCP_TIMING 0x18
  16. #define SYNC2_MASK 0xf
  17. static int ocp2scp_remove_devices(struct device *dev, void *c)
  18. {
  19. struct platform_device *pdev = to_platform_device(dev);
  20. platform_device_unregister(pdev);
  21. return 0;
  22. }
  23. static int omap_ocp2scp_probe(struct platform_device *pdev)
  24. {
  25. int ret;
  26. u32 reg;
  27. void __iomem *regs;
  28. struct resource *res;
  29. struct device_node *np = pdev->dev.of_node;
  30. if (np) {
  31. ret = of_platform_populate(np, NULL, NULL, &pdev->dev);
  32. if (ret) {
  33. dev_err(&pdev->dev,
  34. "failed to add resources for ocp2scp child\n");
  35. goto err0;
  36. }
  37. }
  38. pm_runtime_enable(&pdev->dev);
  39. /*
  40. * As per AM572x TRM: http://www.ti.com/lit/ug/spruhz6/spruhz6.pdf
  41. * under section 26.3.2.2, table 26-26 OCP2SCP TIMING Caution;
  42. * As per OMAP4430 TRM: http://www.ti.com/lit/ug/swpu231ap/swpu231ap.pdf
  43. * under section 23.12.6.2.2 , Table 23-1213 OCP2SCP TIMING Caution;
  44. * As per OMAP4460 TRM: http://www.ti.com/lit/ug/swpu235ab/swpu235ab.pdf
  45. * under section 23.12.6.2.2, Table 23-1213 OCP2SCP TIMING Caution;
  46. * As per OMAP543x TRM http://www.ti.com/lit/pdf/swpu249
  47. * under section 27.3.2.2, Table 27-27 OCP2SCP TIMING Caution;
  48. *
  49. * Read path of OCP2SCP is not working properly due to low reset value
  50. * of SYNC2 parameter in OCP2SCP. Suggested reset value is 0x6 or more.
  51. */
  52. if (!of_device_is_compatible(np, "ti,am437x-ocp2scp")) {
  53. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  54. regs = devm_ioremap_resource(&pdev->dev, res);
  55. if (IS_ERR(regs)) {
  56. ret = PTR_ERR(regs);
  57. goto err1;
  58. }
  59. pm_runtime_get_sync(&pdev->dev);
  60. reg = readl_relaxed(regs + OCP2SCP_TIMING);
  61. reg &= ~(SYNC2_MASK);
  62. reg |= 0x6;
  63. writel_relaxed(reg, regs + OCP2SCP_TIMING);
  64. pm_runtime_put_sync(&pdev->dev);
  65. }
  66. return 0;
  67. err1:
  68. pm_runtime_disable(&pdev->dev);
  69. err0:
  70. device_for_each_child(&pdev->dev, NULL, ocp2scp_remove_devices);
  71. return ret;
  72. }
  73. static int omap_ocp2scp_remove(struct platform_device *pdev)
  74. {
  75. pm_runtime_disable(&pdev->dev);
  76. device_for_each_child(&pdev->dev, NULL, ocp2scp_remove_devices);
  77. return 0;
  78. }
  79. #ifdef CONFIG_OF
  80. static const struct of_device_id omap_ocp2scp_id_table[] = {
  81. { .compatible = "ti,omap-ocp2scp" },
  82. { .compatible = "ti,am437x-ocp2scp" },
  83. {}
  84. };
  85. MODULE_DEVICE_TABLE(of, omap_ocp2scp_id_table);
  86. #endif
  87. static struct platform_driver omap_ocp2scp_driver = {
  88. .probe = omap_ocp2scp_probe,
  89. .remove = omap_ocp2scp_remove,
  90. .driver = {
  91. .name = "omap-ocp2scp",
  92. .of_match_table = of_match_ptr(omap_ocp2scp_id_table),
  93. },
  94. };
  95. module_platform_driver(omap_ocp2scp_driver);
  96. MODULE_ALIAS("platform:omap-ocp2scp");
  97. MODULE_AUTHOR("Texas Instruments Inc.");
  98. MODULE_DESCRIPTION("OMAP OCP2SCP driver");
  99. MODULE_LICENSE("GPL v2");