coresight-modem-etm.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* Copyright (c) 2013, 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/types.h>
  16. #include <linux/device.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/io.h>
  19. #include <linux/err.h>
  20. #include <linux/sysfs.h>
  21. #include <linux/of_coresight.h>
  22. #include <linux/coresight.h>
  23. struct modem_etm_drvdata {
  24. struct device *dev;
  25. struct coresight_device *csdev;
  26. };
  27. static int modem_etm_enable(struct coresight_device *csdev)
  28. {
  29. struct modem_etm_drvdata *drvdata =
  30. dev_get_drvdata(csdev->dev.parent);
  31. dev_info(drvdata->dev, "Modem ETM tracing enabled\n");
  32. return 0;
  33. }
  34. static void modem_etm_disable(struct coresight_device *csdev)
  35. {
  36. struct modem_etm_drvdata *drvdata =
  37. dev_get_drvdata(csdev->dev.parent);
  38. dev_info(drvdata->dev, "Modem ETM tracing disabled\n");
  39. }
  40. static const struct coresight_ops_source modem_etm_source_ops = {
  41. .enable = modem_etm_enable,
  42. .disable = modem_etm_disable,
  43. };
  44. static const struct coresight_ops modem_cs_ops = {
  45. .source_ops = &modem_etm_source_ops,
  46. };
  47. static int modem_etm_probe(struct platform_device *pdev)
  48. {
  49. struct device *dev = &pdev->dev;
  50. struct coresight_platform_data *pdata;
  51. struct modem_etm_drvdata *drvdata;
  52. struct coresight_desc *desc;
  53. if (pdev->dev.of_node) {
  54. pdata = of_get_coresight_platform_data(dev, pdev->dev.of_node);
  55. if (IS_ERR(pdata))
  56. return PTR_ERR(pdata);
  57. pdev->dev.platform_data = pdata;
  58. }
  59. drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
  60. if (!drvdata)
  61. return -ENOMEM;
  62. drvdata->dev = &pdev->dev;
  63. platform_set_drvdata(pdev, drvdata);
  64. desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL);
  65. if (!desc)
  66. return -ENOMEM;
  67. desc->type = CORESIGHT_DEV_TYPE_SOURCE;
  68. desc->subtype.source_subtype = CORESIGHT_DEV_SUBTYPE_SOURCE_PROC;
  69. desc->ops = &modem_cs_ops;
  70. desc->pdata = pdev->dev.platform_data;
  71. desc->dev = &pdev->dev;
  72. desc->owner = THIS_MODULE;
  73. drvdata->csdev = coresight_register(desc);
  74. if (IS_ERR(drvdata->csdev))
  75. return PTR_ERR(drvdata->csdev);
  76. dev_info(dev, "Modem ETM initialized\n");
  77. return 0;
  78. }
  79. static int modem_etm_remove(struct platform_device *pdev)
  80. {
  81. struct modem_etm_drvdata *drvdata = platform_get_drvdata(pdev);
  82. coresight_unregister(drvdata->csdev);
  83. return 0;
  84. }
  85. static struct of_device_id modem_etm_match[] = {
  86. {.compatible = "qcom,coresight-modem-etm"},
  87. {}
  88. };
  89. static struct platform_driver modem_etm_driver = {
  90. .probe = modem_etm_probe,
  91. .remove = modem_etm_remove,
  92. .driver = {
  93. .name = "coresight-modem-etm",
  94. .owner = THIS_MODULE,
  95. .of_match_table = modem_etm_match,
  96. },
  97. };
  98. int __init modem_etm_init(void)
  99. {
  100. return platform_driver_register(&modem_etm_driver);
  101. }
  102. module_init(modem_etm_init);
  103. void __exit modem_etm_exit(void)
  104. {
  105. platform_driver_unregister(&modem_etm_driver);
  106. }
  107. module_exit(modem_etm_exit);
  108. MODULE_LICENSE("GPL v2");
  109. MODULE_DESCRIPTION("CoreSight Modem ETM driver");