omap-ocp2scp.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 omap_ocp2scp_probe(struct platform_device *pdev)
  18. {
  19. int ret;
  20. u32 reg;
  21. void __iomem *regs;
  22. struct resource *res;
  23. struct device_node *np = pdev->dev.of_node;
  24. if (np) {
  25. ret = of_platform_populate(np, NULL, NULL, &pdev->dev);
  26. if (ret) {
  27. dev_err(&pdev->dev,
  28. "failed to add resources for ocp2scp child\n");
  29. goto err0;
  30. }
  31. }
  32. pm_runtime_enable(&pdev->dev);
  33. /*
  34. * As per AM572x TRM: http://www.ti.com/lit/ug/spruhz6/spruhz6.pdf
  35. * under section 26.3.2.2, table 26-26 OCP2SCP TIMING Caution;
  36. * As per OMAP4430 TRM: http://www.ti.com/lit/ug/swpu231ap/swpu231ap.pdf
  37. * under section 23.12.6.2.2 , Table 23-1213 OCP2SCP TIMING Caution;
  38. * As per OMAP4460 TRM: http://www.ti.com/lit/ug/swpu235ab/swpu235ab.pdf
  39. * under section 23.12.6.2.2, Table 23-1213 OCP2SCP TIMING Caution;
  40. * As per OMAP543x TRM http://www.ti.com/lit/pdf/swpu249
  41. * under section 27.3.2.2, Table 27-27 OCP2SCP TIMING Caution;
  42. *
  43. * Read path of OCP2SCP is not working properly due to low reset value
  44. * of SYNC2 parameter in OCP2SCP. Suggested reset value is 0x6 or more.
  45. */
  46. if (!of_device_is_compatible(np, "ti,am437x-ocp2scp")) {
  47. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  48. regs = devm_ioremap_resource(&pdev->dev, res);
  49. if (IS_ERR(regs)) {
  50. ret = PTR_ERR(regs);
  51. goto err1;
  52. }
  53. pm_runtime_get_sync(&pdev->dev);
  54. reg = readl_relaxed(regs + OCP2SCP_TIMING);
  55. reg &= ~(SYNC2_MASK);
  56. reg |= 0x6;
  57. writel_relaxed(reg, regs + OCP2SCP_TIMING);
  58. pm_runtime_put_sync(&pdev->dev);
  59. }
  60. return 0;
  61. err1:
  62. pm_runtime_disable(&pdev->dev);
  63. err0:
  64. of_platform_depopulate(&pdev->dev);
  65. return ret;
  66. }
  67. static void omap_ocp2scp_remove(struct platform_device *pdev)
  68. {
  69. pm_runtime_disable(&pdev->dev);
  70. of_platform_depopulate(&pdev->dev);
  71. }
  72. #ifdef CONFIG_OF
  73. static const struct of_device_id omap_ocp2scp_id_table[] = {
  74. { .compatible = "ti,omap-ocp2scp" },
  75. { .compatible = "ti,am437x-ocp2scp" },
  76. {}
  77. };
  78. MODULE_DEVICE_TABLE(of, omap_ocp2scp_id_table);
  79. #endif
  80. static struct platform_driver omap_ocp2scp_driver = {
  81. .probe = omap_ocp2scp_probe,
  82. .remove = omap_ocp2scp_remove,
  83. .driver = {
  84. .name = "omap-ocp2scp",
  85. .of_match_table = of_match_ptr(omap_ocp2scp_id_table),
  86. },
  87. };
  88. module_platform_driver(omap_ocp2scp_driver);
  89. MODULE_ALIAS("platform:omap-ocp2scp");
  90. MODULE_AUTHOR("Texas Instruments Inc.");
  91. MODULE_DESCRIPTION("OMAP OCP2SCP driver");
  92. MODULE_LICENSE("GPL v2");