coresight-replicator.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/module.h>
  14. #include <linux/init.h>
  15. #include <linux/device.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/io.h>
  18. #include <linux/err.h>
  19. #include <linux/slab.h>
  20. #include <linux/clk.h>
  21. #include <linux/of.h>
  22. #include <linux/coresight.h>
  23. #include "coresight-priv.h"
  24. /**
  25. * struct replicator_drvdata - specifics associated to a replicator component
  26. * @dev: the device entity associated with this component
  27. * @csdev: component vitals needed by the framework
  28. */
  29. struct replicator_drvdata {
  30. struct device *dev;
  31. struct coresight_device *csdev;
  32. };
  33. static int replicator_enable(struct coresight_device *csdev, int inport,
  34. int outport)
  35. {
  36. struct replicator_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
  37. dev_info(drvdata->dev, "REPLICATOR enabled\n");
  38. return 0;
  39. }
  40. static void replicator_disable(struct coresight_device *csdev, int inport,
  41. int outport)
  42. {
  43. struct replicator_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
  44. dev_info(drvdata->dev, "REPLICATOR disabled\n");
  45. }
  46. static const struct coresight_ops_link replicator_link_ops = {
  47. .enable = replicator_enable,
  48. .disable = replicator_disable,
  49. };
  50. static const struct coresight_ops replicator_cs_ops = {
  51. .link_ops = &replicator_link_ops,
  52. };
  53. static int replicator_probe(struct platform_device *pdev)
  54. {
  55. struct device *dev = &pdev->dev;
  56. struct coresight_platform_data *pdata = NULL;
  57. struct replicator_drvdata *drvdata;
  58. struct coresight_desc *desc;
  59. struct device_node *np = pdev->dev.of_node;
  60. if (np) {
  61. pdata = of_get_coresight_platform_data(dev, np);
  62. if (IS_ERR(pdata))
  63. return PTR_ERR(pdata);
  64. pdev->dev.platform_data = pdata;
  65. }
  66. drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
  67. if (!drvdata)
  68. return -ENOMEM;
  69. drvdata->dev = &pdev->dev;
  70. platform_set_drvdata(pdev, drvdata);
  71. desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL);
  72. if (!desc)
  73. return -ENOMEM;
  74. desc->type = CORESIGHT_DEV_TYPE_LINK;
  75. desc->subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_SPLIT;
  76. desc->ops = &replicator_cs_ops;
  77. desc->pdata = pdev->dev.platform_data;
  78. desc->dev = &pdev->dev;
  79. drvdata->csdev = coresight_register(desc);
  80. if (IS_ERR(drvdata->csdev))
  81. return PTR_ERR(drvdata->csdev);
  82. dev_info(dev, "REPLICATOR initialized\n");
  83. return 0;
  84. }
  85. static int replicator_remove(struct platform_device *pdev)
  86. {
  87. struct replicator_drvdata *drvdata = platform_get_drvdata(pdev);
  88. coresight_unregister(drvdata->csdev);
  89. return 0;
  90. }
  91. static const struct of_device_id replicator_match[] = {
  92. {.compatible = "arm,coresight-replicator"},
  93. {}
  94. };
  95. static struct platform_driver replicator_driver = {
  96. .probe = replicator_probe,
  97. .remove = replicator_remove,
  98. .driver = {
  99. .name = "coresight-replicator",
  100. .of_match_table = replicator_match,
  101. },
  102. };
  103. static int __init replicator_init(void)
  104. {
  105. return platform_driver_register(&replicator_driver);
  106. }
  107. module_init(replicator_init);
  108. static void __exit replicator_exit(void)
  109. {
  110. platform_driver_unregister(&replicator_driver);
  111. }
  112. module_exit(replicator_exit);
  113. MODULE_LICENSE("GPL v2");
  114. MODULE_DESCRIPTION("CoreSight Replicator driver");