pruss.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * PRU-ICSS platform driver for various TI SoCs
  4. *
  5. * Copyright (C) 2020-2021 Texas Instruments Incorporated - https://www.ti.com/
  6. */
  7. #include <common.h>
  8. #include <dm.h>
  9. #include <dm/of_access.h>
  10. #include <errno.h>
  11. #include <clk.h>
  12. #include <reset.h>
  13. #include <regmap.h>
  14. #include <syscon.h>
  15. #include <asm/io.h>
  16. #include <power-domain.h>
  17. #include <linux/pruss_driver.h>
  18. #include <dm/device_compat.h>
  19. #define PRUSS_CFG_IEPCLK 0x30
  20. #define ICSSG_CFG_CORE_SYNC 0x3c
  21. #define ICSSG_TASK_MGR_OFFSET 0x2a000
  22. /* PRUSS_IEPCLK register bits */
  23. #define PRUSS_IEPCLK_IEP_OCP_CLK_EN BIT(0)
  24. /* ICSSG CORE_SYNC register bits */
  25. #define ICSSG_CORE_VBUSP_SYNC_EN BIT(0)
  26. /*
  27. * pruss_request_tm_region() - Request pruss for task manager region
  28. * @dev: corresponding k3 device
  29. * @loc: the task manager physical address
  30. *
  31. * Return: 0 if all goes good, else appropriate error message.
  32. */
  33. int pruss_request_tm_region(struct udevice *dev, phys_addr_t *loc)
  34. {
  35. struct pruss *priv;
  36. priv = dev_get_priv(dev);
  37. if (!priv || !priv->mem_regions[PRUSS_MEM_DRAM0].pa)
  38. return -EINVAL;
  39. *loc = priv->mem_regions[PRUSS_MEM_DRAM0].pa + ICSSG_TASK_MGR_OFFSET;
  40. return 0;
  41. }
  42. /**
  43. * pruss_request_mem_region() - request a memory resource
  44. * @dev: the pruss device
  45. * @mem_id: the memory resource id
  46. * @region: pointer to memory region structure to be filled in
  47. *
  48. * This function allows a client driver to request a memory resource,
  49. * and if successful, will let the client driver own the particular
  50. * memory region until released using the pruss_release_mem_region()
  51. * API.
  52. *
  53. * Returns the memory region if requested resource is available, an
  54. * error otherwise
  55. */
  56. int pruss_request_mem_region(struct udevice *dev, enum pruss_mem mem_id,
  57. struct pruss_mem_region *region)
  58. {
  59. struct pruss *pruss;
  60. pruss = dev_get_priv(dev);
  61. if (!pruss || !region)
  62. return -EINVAL;
  63. if (mem_id >= PRUSS_MEM_MAX)
  64. return -EINVAL;
  65. if (pruss->mem_in_use[mem_id])
  66. return -EBUSY;
  67. *region = pruss->mem_regions[mem_id];
  68. pruss->mem_in_use[mem_id] = region;
  69. return 0;
  70. }
  71. /**
  72. * pruss_release_mem_region() - release a memory resource
  73. * @dev: the pruss device
  74. * @region: the memory region to release
  75. *
  76. * This function is the complimentary function to
  77. * pruss_request_mem_region(), and allows the client drivers to
  78. * release back a memory resource.
  79. *
  80. * Returns 0 on success, an error code otherwise
  81. */
  82. int pruss_release_mem_region(struct udevice *dev,
  83. struct pruss_mem_region *region)
  84. {
  85. struct pruss *pruss;
  86. int id;
  87. pruss = dev_get_priv(dev);
  88. if (!pruss || !region)
  89. return -EINVAL;
  90. /* find out the memory region being released */
  91. for (id = 0; id < PRUSS_MEM_MAX; id++) {
  92. if (pruss->mem_in_use[id] == region)
  93. break;
  94. }
  95. if (id == PRUSS_MEM_MAX)
  96. return -EINVAL;
  97. pruss->mem_in_use[id] = NULL;
  98. return 0;
  99. }
  100. /**
  101. * pruss_cfg_update() - configure a PRUSS CFG sub-module register
  102. * @dev: the pruss device
  103. * @reg: register offset within the CFG sub-module
  104. * @mask: bit mask to use for programming the @val
  105. * @val: value to write
  106. *
  107. * Programs a given register within the PRUSS CFG sub-module
  108. *
  109. * Returns 0 on success, or an error code otherwise
  110. */
  111. int pruss_cfg_update(struct udevice *dev, unsigned int reg,
  112. unsigned int mask, unsigned int val)
  113. {
  114. struct pruss *pruss;
  115. pruss = dev_get_priv(dev);
  116. if (IS_ERR_OR_NULL(pruss))
  117. return -EINVAL;
  118. return regmap_update_bits(pruss->cfg, reg, mask, val);
  119. }
  120. /**
  121. * pruss_probe() - Basic probe
  122. * @dev: corresponding k3 device
  123. *
  124. * Return: 0 if all goes good, else appropriate error message.
  125. */
  126. static int pruss_probe(struct udevice *dev)
  127. {
  128. const char *mem_names[PRUSS_MEM_MAX] = { "dram0", "dram1", "shrdram2" };
  129. ofnode sub_node, node, memories;
  130. struct udevice *syscon;
  131. struct pruss *priv;
  132. int ret, idx, i;
  133. priv = dev_get_priv(dev);
  134. node = dev_ofnode(dev);
  135. priv->dev = dev;
  136. memories = ofnode_find_subnode(node, "memories");
  137. for (i = 0; i < ARRAY_SIZE(mem_names); i++) {
  138. idx = ofnode_stringlist_search(memories, "reg-names", mem_names[i]);
  139. priv->mem_regions[i].pa = ofnode_get_addr_size_index(memories, idx,
  140. (u64 *)&priv->mem_regions[i].size);
  141. }
  142. sub_node = ofnode_find_subnode(node, "cfg");
  143. ret = uclass_get_device_by_ofnode(UCLASS_SYSCON, sub_node,
  144. &syscon);
  145. priv->cfg = syscon_get_regmap(syscon);
  146. if (IS_ERR(priv->cfg)) {
  147. dev_err(dev, "unable to get cfg regmap (%ld)\n",
  148. PTR_ERR(priv->cfg));
  149. return -ENODEV;
  150. }
  151. /*
  152. * ToDo: To be modelled as clocks.
  153. * The CORE block uses two multiplexers to allow software to
  154. * select one of three source clocks (ICSSGn_CORE_CLK, ICSSGn_ICLK or
  155. * ICSSGn_IEP_CLK) for the final clock source of the CORE block.
  156. * The user needs to configure ICSSG_CORE_SYNC_REG[0] CORE_VBUSP_SYNC_EN
  157. * bit & ICSSG_IEPCLK_REG[0] IEP_OCP_CLK_EN bit in order to select the
  158. * clock source to the CORE block.
  159. */
  160. ret = regmap_update_bits(priv->cfg, ICSSG_CFG_CORE_SYNC,
  161. ICSSG_CORE_VBUSP_SYNC_EN,
  162. ICSSG_CORE_VBUSP_SYNC_EN);
  163. if (ret)
  164. return ret;
  165. ret = regmap_update_bits(priv->cfg, PRUSS_CFG_IEPCLK,
  166. PRUSS_IEPCLK_IEP_OCP_CLK_EN,
  167. PRUSS_IEPCLK_IEP_OCP_CLK_EN);
  168. if (ret)
  169. return ret;
  170. dev_dbg(dev, "pruss successfully probed %s\n", dev->name);
  171. return 0;
  172. }
  173. static const struct udevice_id pruss_ids[] = {
  174. { .compatible = "ti,am654-icssg"},
  175. {}
  176. };
  177. U_BOOT_DRIVER(pruss) = {
  178. .name = "pruss",
  179. .of_match = pruss_ids,
  180. .id = UCLASS_MISC,
  181. .probe = pruss_probe,
  182. .priv_auto = sizeof(struct pruss),
  183. };