xrp_hw_comm.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * XRP: Linux device driver for Xtensa Remote Processing
  3. *
  4. * Copyright (c) 2015 - 2017 Cadence Design Systems, Inc.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining
  7. * a copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sublicense, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included
  15. * in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  20. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  21. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  22. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  23. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. *
  25. * Alternatively you can use and distribute this file under the terms of
  26. * the GNU General Public License version 2 or later.
  27. */
  28. #include <linux/version.h>
  29. #include <linux/atomic.h>
  30. #include <linux/acpi.h>
  31. #include <linux/completion.h>
  32. #include <linux/delay.h>
  33. #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 16, 0)
  34. #include <linux/dma-mapping.h>
  35. #else
  36. #include <linux/dma-direct.h>
  37. #endif
  38. #include <linux/firmware.h>
  39. #include <linux/fs.h>
  40. #include <linux/hashtable.h>
  41. #include <linux/highmem.h>
  42. #include <linux/idr.h>
  43. #include <linux/interrupt.h>
  44. #include <linux/io.h>
  45. #include <linux/kernel.h>
  46. #include <linux/module.h>
  47. #include <linux/of.h>
  48. #include <linux/of_address.h>
  49. #include <linux/of_device.h>
  50. #include <linux/of_reserved_mem.h>
  51. #include <linux/platform_device.h>
  52. #include <linux/pm_runtime.h>
  53. #include <linux/property.h>
  54. #include <linux/sched.h>
  55. #include <linux/slab.h>
  56. #include <linux/sort.h>
  57. #include <asm/mman.h>
  58. #include <linux/mman.h>
  59. #include <asm/uaccess.h>
  60. #include "xrp_cma_alloc.h"
  61. #include "xrp_firmware.h"
  62. #include "xrp_hw.h"
  63. #include "xrp_internal.h"
  64. #include "xrp_kernel_defs.h"
  65. #include "xrp_kernel_dsp_interface.h"
  66. #include "xrp_private_alloc.h"
  67. #define DRIVER_NAME "xrp_hw_com"
  68. struct xrp_hw_common_drvdata {
  69. phys_addr_t sys_reg_phys;
  70. void __iomem *sys_regs;
  71. size_t sys_reg_size;
  72. struct mutex lock;
  73. };
  74. static struct xrp_hw_common_drvdata *hw_drvdata = NULL;
  75. #define XRP_REG_RESET (0x28)
  76. #define DSP0_RESET_BIT_MASK (0x1<<8)
  77. #define DSP1_RESET_BIT_MASK (0x1<<12)
  78. int xrp_set_reset_reg(int dsp_id)
  79. {
  80. uint32_t bit_mask = dsp_id==0?DSP0_RESET_BIT_MASK
  81. :DSP1_RESET_BIT_MASK;
  82. pr_debug("%s,reset\n", __func__);
  83. if(!hw_drvdata)
  84. {
  85. pr_debug("%s hw_drvdata is NULL \n",__func__);
  86. return -1;
  87. }
  88. mutex_lock(&hw_drvdata->lock);
  89. uint32_t old_value = __raw_readl(hw_drvdata->sys_regs+XRP_REG_RESET);
  90. pr_debug("%s,reset reg:%x\n",__func__,old_value);
  91. __raw_writel(old_value^bit_mask,hw_drvdata->sys_regs+XRP_REG_RESET);
  92. udelay(10000);
  93. __raw_writel(old_value,hw_drvdata->sys_regs+XRP_REG_RESET);
  94. mutex_unlock(&hw_drvdata->lock);
  95. return 0;
  96. }
  97. EXPORT_SYMBOL(xrp_set_reset_reg);
  98. static const struct of_device_id xrp_hw_common_of_match[] = {
  99. {
  100. .compatible = "thead,dsp-hw-common",
  101. }, {},
  102. };
  103. // MODULE_DEVICE_TABLE(of, xrp_hw_common_of_match);
  104. static int xrp_hw_common_probe(struct platform_device *pdev)
  105. {
  106. long ret = -EINVAL;
  107. struct resource *mem;
  108. hw_drvdata =
  109. devm_kzalloc(&pdev->dev, sizeof(*hw_drvdata), GFP_KERNEL);
  110. if (!hw_drvdata)
  111. return -ENOMEM;
  112. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  113. if (!mem) {
  114. return -ENODEV;
  115. }
  116. hw_drvdata->sys_reg_phys = mem->start;
  117. hw_drvdata->sys_reg_size =mem->end-mem->start;
  118. hw_drvdata->sys_regs = devm_ioremap_resource(&pdev->dev, mem);
  119. pr_debug("%s,sys_reg_phys:%lx,sys_regs:%lx,size:%x\n", __func__,
  120. hw_drvdata->sys_reg_phys,hw_drvdata->sys_regs,hw_drvdata->sys_reg_size);
  121. mutex_init(&hw_drvdata->lock);
  122. return 0;
  123. }
  124. static int xrp_hw_common_remove(struct platform_device *pdev)
  125. {
  126. return 0;
  127. }
  128. static struct platform_driver xrp_hw_common_driver = {
  129. .probe = xrp_hw_common_probe,
  130. .remove = xrp_hw_common_remove,
  131. .driver = {
  132. .name = DRIVER_NAME,
  133. .of_match_table = of_match_ptr( xrp_hw_common_of_match),
  134. },
  135. };
  136. module_platform_driver(xrp_hw_common_driver);
  137. MODULE_AUTHOR("T-HEAD");
  138. MODULE_DESCRIPTION("XRP: Linux device driver for Xtensa Remote Processing");
  139. MODULE_LICENSE("Dual MIT/GPL");