coresight-fuse.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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/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/of.h>
  21. #include <linux/of_coresight.h>
  22. #include <linux/coresight.h>
  23. #include "coresight-priv.h"
  24. #define fuse_writel(drvdata, val, off) __raw_writel((val), drvdata->base + off)
  25. #define fuse_readl(drvdata, off) __raw_readl(drvdata->base + off)
  26. #define OEM_CONFIG0 (0x000)
  27. #define OEM_CONFIG1 (0x004)
  28. #define ALL_DEBUG_DISABLE BIT(21)
  29. #define APPS_DBGEN_DISABLE BIT(0)
  30. #define APPS_NIDEN_DISABLE BIT(1)
  31. #define APPS_SPIDEN_DISABLE BIT(2)
  32. #define APPS_SPNIDEN_DISABLE BIT(3)
  33. #define DAP_DBGEN_DISABLE BIT(4)
  34. #define DAP_NIDEN_DISABLE BIT(5)
  35. #define DAP_SPIDEN_DISABLE BIT(6)
  36. #define DAP_SPNIDEN_DISABLE BIT(7)
  37. #define DAP_DEVICEEN_DISABLE BIT(8)
  38. struct fuse_drvdata {
  39. void __iomem *base;
  40. struct device *dev;
  41. struct coresight_device *csdev;
  42. };
  43. static struct fuse_drvdata *fusedrvdata;
  44. bool coresight_fuse_access_disabled(void)
  45. {
  46. struct fuse_drvdata *drvdata = fusedrvdata;
  47. uint32_t config0, config1;
  48. bool ret;
  49. config0 = fuse_readl(drvdata, OEM_CONFIG0);
  50. config1 = fuse_readl(drvdata, OEM_CONFIG1);
  51. dev_dbg(drvdata->dev, "config0: %lx\n", (unsigned long)config0);
  52. dev_dbg(drvdata->dev, "config1: %lx\n", (unsigned long)config1);
  53. if (config0 & ALL_DEBUG_DISABLE)
  54. ret = true;
  55. else if (config1 & DAP_DBGEN_DISABLE)
  56. ret = true;
  57. else if (config1 & DAP_NIDEN_DISABLE)
  58. ret = true;
  59. else if (config1 & DAP_SPIDEN_DISABLE)
  60. ret = true;
  61. else if (config1 & DAP_SPNIDEN_DISABLE)
  62. ret = true;
  63. else if (config1 & DAP_DEVICEEN_DISABLE)
  64. ret = true;
  65. else
  66. ret = false;
  67. if (ret)
  68. dev_dbg(drvdata->dev, "coresight fuse disabled\n");
  69. return ret;
  70. }
  71. EXPORT_SYMBOL(coresight_fuse_access_disabled);
  72. bool coresight_fuse_apps_access_disabled(void)
  73. {
  74. struct fuse_drvdata *drvdata = fusedrvdata;
  75. uint32_t config0, config1;
  76. bool ret;
  77. config0 = fuse_readl(drvdata, OEM_CONFIG0);
  78. config1 = fuse_readl(drvdata, OEM_CONFIG1);
  79. dev_dbg(drvdata->dev, "apps config0: %lx\n", (unsigned long)config0);
  80. dev_dbg(drvdata->dev, "apps config1: %lx\n", (unsigned long)config1);
  81. if (config0 & ALL_DEBUG_DISABLE)
  82. ret = true;
  83. else if (config1 & APPS_DBGEN_DISABLE)
  84. ret = true;
  85. else if (config1 & APPS_NIDEN_DISABLE)
  86. ret = true;
  87. else if (config1 & APPS_SPIDEN_DISABLE)
  88. ret = true;
  89. else if (config1 & APPS_SPNIDEN_DISABLE)
  90. ret = true;
  91. else if (config1 & DAP_DEVICEEN_DISABLE)
  92. ret = true;
  93. else
  94. ret = false;
  95. if (ret)
  96. dev_dbg(drvdata->dev, "apps fuse disabled\n");
  97. return ret;
  98. }
  99. EXPORT_SYMBOL(coresight_fuse_apps_access_disabled);
  100. static int __devinit fuse_probe(struct platform_device *pdev)
  101. {
  102. struct device *dev = &pdev->dev;
  103. struct coresight_platform_data *pdata;
  104. struct fuse_drvdata *drvdata;
  105. struct resource *res;
  106. struct coresight_desc *desc;
  107. if (pdev->dev.of_node) {
  108. pdata = of_get_coresight_platform_data(dev, pdev->dev.of_node);
  109. if (IS_ERR(pdata))
  110. return PTR_ERR(pdata);
  111. pdev->dev.platform_data = pdata;
  112. }
  113. drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
  114. if (!drvdata)
  115. return -ENOMEM;
  116. /* Store the driver data pointer for use in exported functions */
  117. fusedrvdata = drvdata;
  118. drvdata->dev = &pdev->dev;
  119. platform_set_drvdata(pdev, drvdata);
  120. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fuse-base");
  121. if (!res)
  122. return -ENODEV;
  123. drvdata->base = devm_ioremap(dev, res->start, resource_size(res));
  124. if (!drvdata->base)
  125. return -ENOMEM;
  126. desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL);
  127. if (!desc)
  128. return -ENOMEM;
  129. desc->type = CORESIGHT_DEV_TYPE_NONE;
  130. desc->pdata = pdev->dev.platform_data;
  131. desc->dev = &pdev->dev;
  132. desc->owner = THIS_MODULE;
  133. drvdata->csdev = coresight_register(desc);
  134. if (IS_ERR(drvdata->csdev))
  135. return PTR_ERR(drvdata->csdev);
  136. dev_info(dev, "Fuse initialized\n");
  137. return 0;
  138. }
  139. static int __devexit fuse_remove(struct platform_device *pdev)
  140. {
  141. struct fuse_drvdata *drvdata = platform_get_drvdata(pdev);
  142. coresight_unregister(drvdata->csdev);
  143. return 0;
  144. }
  145. static struct of_device_id fuse_match[] = {
  146. {.compatible = "arm,coresight-fuse"},
  147. {}
  148. };
  149. static struct platform_driver fuse_driver = {
  150. .probe = fuse_probe,
  151. .remove = __devexit_p(fuse_remove),
  152. .driver = {
  153. .name = "coresight-fuse",
  154. .owner = THIS_MODULE,
  155. .of_match_table = fuse_match,
  156. },
  157. };
  158. static int __init fuse_init(void)
  159. {
  160. return platform_driver_register(&fuse_driver);
  161. }
  162. module_init(fuse_init);
  163. static void __exit fuse_exit(void)
  164. {
  165. platform_driver_unregister(&fuse_driver);
  166. }
  167. module_exit(fuse_exit);
  168. MODULE_LICENSE("GPL v2");
  169. MODULE_DESCRIPTION("CoreSight Fuse driver");