mdp5_cfg.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * Copyright (c) 2014 The Linux Foundation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 and
  6. * only version 2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include "mdp5_kms.h"
  14. #include "mdp5_cfg.h"
  15. struct mdp5_cfg_handler {
  16. int revision;
  17. struct mdp5_cfg config;
  18. };
  19. /* mdp5_cfg must be exposed (used in mdp5.xml.h) */
  20. const struct mdp5_cfg_hw *mdp5_cfg = NULL;
  21. const struct mdp5_cfg_hw msm8x74_config = {
  22. .name = "msm8x74",
  23. .smp = {
  24. .mmb_count = 22,
  25. .mmb_size = 4096,
  26. },
  27. .ctl = {
  28. .count = 5,
  29. .base = { 0x00600, 0x00700, 0x00800, 0x00900, 0x00a00 },
  30. },
  31. .pipe_vig = {
  32. .count = 3,
  33. .base = { 0x01200, 0x01600, 0x01a00 },
  34. },
  35. .pipe_rgb = {
  36. .count = 3,
  37. .base = { 0x01e00, 0x02200, 0x02600 },
  38. },
  39. .pipe_dma = {
  40. .count = 2,
  41. .base = { 0x02a00, 0x02e00 },
  42. },
  43. .lm = {
  44. .count = 5,
  45. .base = { 0x03200, 0x03600, 0x03a00, 0x03e00, 0x04200 },
  46. .nb_stages = 5,
  47. },
  48. .dspp = {
  49. .count = 3,
  50. .base = { 0x04600, 0x04a00, 0x04e00 },
  51. },
  52. .ad = {
  53. .count = 2,
  54. .base = { 0x13100, 0x13300 }, /* NOTE: no ad in v1.0 */
  55. },
  56. .intf = {
  57. .count = 4,
  58. .base = { 0x12500, 0x12700, 0x12900, 0x12b00 },
  59. },
  60. .max_clk = 200000000,
  61. };
  62. const struct mdp5_cfg_hw apq8084_config = {
  63. .name = "apq8084",
  64. .smp = {
  65. .mmb_count = 44,
  66. .mmb_size = 8192,
  67. .reserved_state[0] = GENMASK(7, 0), /* first 8 MMBs */
  68. .reserved[CID_RGB0] = 2,
  69. .reserved[CID_RGB1] = 2,
  70. .reserved[CID_RGB2] = 2,
  71. .reserved[CID_RGB3] = 2,
  72. },
  73. .ctl = {
  74. .count = 5,
  75. .base = { 0x00600, 0x00700, 0x00800, 0x00900, 0x00a00 },
  76. },
  77. .pipe_vig = {
  78. .count = 4,
  79. .base = { 0x01200, 0x01600, 0x01a00, 0x01e00 },
  80. },
  81. .pipe_rgb = {
  82. .count = 4,
  83. .base = { 0x02200, 0x02600, 0x02a00, 0x02e00 },
  84. },
  85. .pipe_dma = {
  86. .count = 2,
  87. .base = { 0x03200, 0x03600 },
  88. },
  89. .lm = {
  90. .count = 6,
  91. .base = { 0x03a00, 0x03e00, 0x04200, 0x04600, 0x04a00, 0x04e00 },
  92. .nb_stages = 5,
  93. },
  94. .dspp = {
  95. .count = 4,
  96. .base = { 0x05200, 0x05600, 0x05a00, 0x05e00 },
  97. },
  98. .ad = {
  99. .count = 3,
  100. .base = { 0x13500, 0x13700, 0x13900 },
  101. },
  102. .intf = {
  103. .count = 5,
  104. .base = { 0x12500, 0x12700, 0x12900, 0x12b00, 0x12d00 },
  105. },
  106. .max_clk = 320000000,
  107. };
  108. static const struct mdp5_cfg_handler cfg_handlers[] = {
  109. { .revision = 0, .config = { .hw = &msm8x74_config } },
  110. { .revision = 2, .config = { .hw = &msm8x74_config } },
  111. { .revision = 3, .config = { .hw = &apq8084_config } },
  112. };
  113. static struct mdp5_cfg_platform *mdp5_get_config(struct platform_device *dev);
  114. const struct mdp5_cfg_hw *mdp5_cfg_get_hw_config(struct mdp5_cfg_handler *cfg_handler)
  115. {
  116. return cfg_handler->config.hw;
  117. }
  118. struct mdp5_cfg *mdp5_cfg_get_config(struct mdp5_cfg_handler *cfg_handler)
  119. {
  120. return &cfg_handler->config;
  121. }
  122. int mdp5_cfg_get_hw_rev(struct mdp5_cfg_handler *cfg_handler)
  123. {
  124. return cfg_handler->revision;
  125. }
  126. void mdp5_cfg_destroy(struct mdp5_cfg_handler *cfg_handler)
  127. {
  128. kfree(cfg_handler);
  129. }
  130. struct mdp5_cfg_handler *mdp5_cfg_init(struct mdp5_kms *mdp5_kms,
  131. uint32_t major, uint32_t minor)
  132. {
  133. struct drm_device *dev = mdp5_kms->dev;
  134. struct platform_device *pdev = dev->platformdev;
  135. struct mdp5_cfg_handler *cfg_handler;
  136. struct mdp5_cfg_platform *pconfig;
  137. int i, ret = 0;
  138. cfg_handler = kzalloc(sizeof(*cfg_handler), GFP_KERNEL);
  139. if (unlikely(!cfg_handler)) {
  140. ret = -ENOMEM;
  141. goto fail;
  142. }
  143. if (major != 1) {
  144. dev_err(dev->dev, "unexpected MDP major version: v%d.%d\n",
  145. major, minor);
  146. ret = -ENXIO;
  147. goto fail;
  148. }
  149. /* only after mdp5_cfg global pointer's init can we access the hw */
  150. for (i = 0; i < ARRAY_SIZE(cfg_handlers); i++) {
  151. if (cfg_handlers[i].revision != minor)
  152. continue;
  153. mdp5_cfg = cfg_handlers[i].config.hw;
  154. break;
  155. }
  156. if (unlikely(!mdp5_cfg)) {
  157. dev_err(dev->dev, "unexpected MDP minor revision: v%d.%d\n",
  158. major, minor);
  159. ret = -ENXIO;
  160. goto fail;
  161. }
  162. cfg_handler->revision = minor;
  163. cfg_handler->config.hw = mdp5_cfg;
  164. pconfig = mdp5_get_config(pdev);
  165. memcpy(&cfg_handler->config.platform, pconfig, sizeof(*pconfig));
  166. DBG("MDP5: %s hw config selected", mdp5_cfg->name);
  167. return cfg_handler;
  168. fail:
  169. if (cfg_handler)
  170. mdp5_cfg_destroy(cfg_handler);
  171. return NULL;
  172. }
  173. static struct mdp5_cfg_platform *mdp5_get_config(struct platform_device *dev)
  174. {
  175. static struct mdp5_cfg_platform config = {};
  176. #ifdef CONFIG_OF
  177. /* TODO */
  178. #endif
  179. config.iommu = iommu_domain_alloc(&platform_bus_type);
  180. return &config;
  181. }