mdp5_kms.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. /*
  2. * Copyright (c) 2014, The Linux Foundation. All rights reserved.
  3. * Copyright (C) 2013 Red Hat
  4. * Author: Rob Clark <robdclark@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published by
  8. * the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "msm_drv.h"
  19. #include "msm_mmu.h"
  20. #include "mdp5_kms.h"
  21. static const char *iommu_ports[] = {
  22. "mdp_0",
  23. };
  24. static int mdp5_hw_init(struct msm_kms *kms)
  25. {
  26. struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(kms));
  27. struct drm_device *dev = mdp5_kms->dev;
  28. unsigned long flags;
  29. pm_runtime_get_sync(dev->dev);
  30. /* Magic unknown register writes:
  31. *
  32. * W VBIF:0x004 00000001 (mdss_mdp.c:839)
  33. * W MDP5:0x2e0 0xe9 (mdss_mdp.c:839)
  34. * W MDP5:0x2e4 0x55 (mdss_mdp.c:839)
  35. * W MDP5:0x3ac 0xc0000ccc (mdss_mdp.c:839)
  36. * W MDP5:0x3b4 0xc0000ccc (mdss_mdp.c:839)
  37. * W MDP5:0x3bc 0xcccccc (mdss_mdp.c:839)
  38. * W MDP5:0x4a8 0xcccc0c0 (mdss_mdp.c:839)
  39. * W MDP5:0x4b0 0xccccc0c0 (mdss_mdp.c:839)
  40. * W MDP5:0x4b8 0xccccc000 (mdss_mdp.c:839)
  41. *
  42. * Downstream fbdev driver gets these register offsets/values
  43. * from DT.. not really sure what these registers are or if
  44. * different values for different boards/SoC's, etc. I guess
  45. * they are the golden registers.
  46. *
  47. * Not setting these does not seem to cause any problem. But
  48. * we may be getting lucky with the bootloader initializing
  49. * them for us. OTOH, if we can always count on the bootloader
  50. * setting the golden registers, then perhaps we don't need to
  51. * care.
  52. */
  53. spin_lock_irqsave(&mdp5_kms->resource_lock, flags);
  54. mdp5_write(mdp5_kms, REG_MDP5_MDP_DISP_INTF_SEL(0), 0);
  55. spin_unlock_irqrestore(&mdp5_kms->resource_lock, flags);
  56. mdp5_ctlm_hw_reset(mdp5_kms->ctlm);
  57. pm_runtime_put_sync(dev->dev);
  58. return 0;
  59. }
  60. static void mdp5_prepare_commit(struct msm_kms *kms, struct drm_atomic_state *state)
  61. {
  62. struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(kms));
  63. mdp5_enable(mdp5_kms);
  64. }
  65. static void mdp5_complete_commit(struct msm_kms *kms, struct drm_atomic_state *state)
  66. {
  67. int i;
  68. struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(kms));
  69. int nplanes = mdp5_kms->dev->mode_config.num_total_plane;
  70. for (i = 0; i < nplanes; i++) {
  71. struct drm_plane *plane = state->planes[i];
  72. struct drm_plane_state *plane_state = state->plane_states[i];
  73. if (!plane)
  74. continue;
  75. mdp5_plane_complete_commit(plane, plane_state);
  76. }
  77. mdp5_disable(mdp5_kms);
  78. }
  79. static void mdp5_wait_for_crtc_commit_done(struct msm_kms *kms,
  80. struct drm_crtc *crtc)
  81. {
  82. mdp5_crtc_wait_for_commit_done(crtc);
  83. }
  84. static long mdp5_round_pixclk(struct msm_kms *kms, unsigned long rate,
  85. struct drm_encoder *encoder)
  86. {
  87. return rate;
  88. }
  89. static int mdp5_set_split_display(struct msm_kms *kms,
  90. struct drm_encoder *encoder,
  91. struct drm_encoder *slave_encoder,
  92. bool is_cmd_mode)
  93. {
  94. if (is_cmd_mode)
  95. return mdp5_cmd_encoder_set_split_display(encoder,
  96. slave_encoder);
  97. else
  98. return mdp5_encoder_set_split_display(encoder, slave_encoder);
  99. }
  100. static void mdp5_preclose(struct msm_kms *kms, struct drm_file *file)
  101. {
  102. struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(kms));
  103. struct msm_drm_private *priv = mdp5_kms->dev->dev_private;
  104. unsigned i;
  105. for (i = 0; i < priv->num_crtcs; i++)
  106. mdp5_crtc_cancel_pending_flip(priv->crtcs[i], file);
  107. }
  108. static void mdp5_destroy(struct msm_kms *kms)
  109. {
  110. struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(kms));
  111. struct msm_mmu *mmu = mdp5_kms->mmu;
  112. mdp5_irq_domain_fini(mdp5_kms);
  113. if (mmu) {
  114. mmu->funcs->detach(mmu, iommu_ports, ARRAY_SIZE(iommu_ports));
  115. mmu->funcs->destroy(mmu);
  116. }
  117. if (mdp5_kms->ctlm)
  118. mdp5_ctlm_destroy(mdp5_kms->ctlm);
  119. if (mdp5_kms->smp)
  120. mdp5_smp_destroy(mdp5_kms->smp);
  121. if (mdp5_kms->cfg)
  122. mdp5_cfg_destroy(mdp5_kms->cfg);
  123. kfree(mdp5_kms);
  124. }
  125. static const struct mdp_kms_funcs kms_funcs = {
  126. .base = {
  127. .hw_init = mdp5_hw_init,
  128. .irq_preinstall = mdp5_irq_preinstall,
  129. .irq_postinstall = mdp5_irq_postinstall,
  130. .irq_uninstall = mdp5_irq_uninstall,
  131. .irq = mdp5_irq,
  132. .enable_vblank = mdp5_enable_vblank,
  133. .disable_vblank = mdp5_disable_vblank,
  134. .prepare_commit = mdp5_prepare_commit,
  135. .complete_commit = mdp5_complete_commit,
  136. .wait_for_crtc_commit_done = mdp5_wait_for_crtc_commit_done,
  137. .get_format = mdp_get_format,
  138. .round_pixclk = mdp5_round_pixclk,
  139. .set_split_display = mdp5_set_split_display,
  140. .preclose = mdp5_preclose,
  141. .destroy = mdp5_destroy,
  142. },
  143. .set_irqmask = mdp5_set_irqmask,
  144. };
  145. int mdp5_disable(struct mdp5_kms *mdp5_kms)
  146. {
  147. DBG("");
  148. clk_disable_unprepare(mdp5_kms->ahb_clk);
  149. clk_disable_unprepare(mdp5_kms->axi_clk);
  150. clk_disable_unprepare(mdp5_kms->core_clk);
  151. if (mdp5_kms->lut_clk)
  152. clk_disable_unprepare(mdp5_kms->lut_clk);
  153. return 0;
  154. }
  155. int mdp5_enable(struct mdp5_kms *mdp5_kms)
  156. {
  157. DBG("");
  158. clk_prepare_enable(mdp5_kms->ahb_clk);
  159. clk_prepare_enable(mdp5_kms->axi_clk);
  160. clk_prepare_enable(mdp5_kms->core_clk);
  161. if (mdp5_kms->lut_clk)
  162. clk_prepare_enable(mdp5_kms->lut_clk);
  163. return 0;
  164. }
  165. static struct drm_encoder *construct_encoder(struct mdp5_kms *mdp5_kms,
  166. enum mdp5_intf_type intf_type, int intf_num,
  167. enum mdp5_intf_mode intf_mode, struct mdp5_ctl *ctl)
  168. {
  169. struct drm_device *dev = mdp5_kms->dev;
  170. struct msm_drm_private *priv = dev->dev_private;
  171. struct drm_encoder *encoder;
  172. struct mdp5_interface intf = {
  173. .num = intf_num,
  174. .type = intf_type,
  175. .mode = intf_mode,
  176. };
  177. if ((intf_type == INTF_DSI) &&
  178. (intf_mode == MDP5_INTF_DSI_MODE_COMMAND))
  179. encoder = mdp5_cmd_encoder_init(dev, &intf, ctl);
  180. else
  181. encoder = mdp5_encoder_init(dev, &intf, ctl);
  182. if (IS_ERR(encoder)) {
  183. dev_err(dev->dev, "failed to construct encoder\n");
  184. return encoder;
  185. }
  186. encoder->possible_crtcs = (1 << priv->num_crtcs) - 1;
  187. priv->encoders[priv->num_encoders++] = encoder;
  188. return encoder;
  189. }
  190. static int get_dsi_id_from_intf(const struct mdp5_cfg_hw *hw_cfg, int intf_num)
  191. {
  192. const enum mdp5_intf_type *intfs = hw_cfg->intf.connect;
  193. const int intf_cnt = ARRAY_SIZE(hw_cfg->intf.connect);
  194. int id = 0, i;
  195. for (i = 0; i < intf_cnt; i++) {
  196. if (intfs[i] == INTF_DSI) {
  197. if (intf_num == i)
  198. return id;
  199. id++;
  200. }
  201. }
  202. return -EINVAL;
  203. }
  204. static int modeset_init_intf(struct mdp5_kms *mdp5_kms, int intf_num)
  205. {
  206. struct drm_device *dev = mdp5_kms->dev;
  207. struct msm_drm_private *priv = dev->dev_private;
  208. const struct mdp5_cfg_hw *hw_cfg =
  209. mdp5_cfg_get_hw_config(mdp5_kms->cfg);
  210. enum mdp5_intf_type intf_type = hw_cfg->intf.connect[intf_num];
  211. struct mdp5_ctl_manager *ctlm = mdp5_kms->ctlm;
  212. struct mdp5_ctl *ctl;
  213. struct drm_encoder *encoder;
  214. int ret = 0;
  215. switch (intf_type) {
  216. case INTF_DISABLED:
  217. break;
  218. case INTF_eDP:
  219. if (!priv->edp)
  220. break;
  221. ctl = mdp5_ctlm_request(ctlm, intf_num);
  222. if (!ctl) {
  223. ret = -EINVAL;
  224. break;
  225. }
  226. encoder = construct_encoder(mdp5_kms, INTF_eDP, intf_num,
  227. MDP5_INTF_MODE_NONE, ctl);
  228. if (IS_ERR(encoder)) {
  229. ret = PTR_ERR(encoder);
  230. break;
  231. }
  232. ret = msm_edp_modeset_init(priv->edp, dev, encoder);
  233. break;
  234. case INTF_HDMI:
  235. if (!priv->hdmi)
  236. break;
  237. ctl = mdp5_ctlm_request(ctlm, intf_num);
  238. if (!ctl) {
  239. ret = -EINVAL;
  240. break;
  241. }
  242. encoder = construct_encoder(mdp5_kms, INTF_HDMI, intf_num,
  243. MDP5_INTF_MODE_NONE, ctl);
  244. if (IS_ERR(encoder)) {
  245. ret = PTR_ERR(encoder);
  246. break;
  247. }
  248. ret = hdmi_modeset_init(priv->hdmi, dev, encoder);
  249. break;
  250. case INTF_DSI:
  251. {
  252. int dsi_id = get_dsi_id_from_intf(hw_cfg, intf_num);
  253. struct drm_encoder *dsi_encs[MSM_DSI_ENCODER_NUM];
  254. enum mdp5_intf_mode mode;
  255. int i;
  256. if ((dsi_id >= ARRAY_SIZE(priv->dsi)) || (dsi_id < 0)) {
  257. dev_err(dev->dev, "failed to find dsi from intf %d\n",
  258. intf_num);
  259. ret = -EINVAL;
  260. break;
  261. }
  262. if (!priv->dsi[dsi_id])
  263. break;
  264. ctl = mdp5_ctlm_request(ctlm, intf_num);
  265. if (!ctl) {
  266. ret = -EINVAL;
  267. break;
  268. }
  269. for (i = 0; i < MSM_DSI_ENCODER_NUM; i++) {
  270. mode = (i == MSM_DSI_CMD_ENCODER_ID) ?
  271. MDP5_INTF_DSI_MODE_COMMAND :
  272. MDP5_INTF_DSI_MODE_VIDEO;
  273. dsi_encs[i] = construct_encoder(mdp5_kms, INTF_DSI,
  274. intf_num, mode, ctl);
  275. if (IS_ERR(dsi_encs[i])) {
  276. ret = PTR_ERR(dsi_encs[i]);
  277. break;
  278. }
  279. }
  280. ret = msm_dsi_modeset_init(priv->dsi[dsi_id], dev, dsi_encs);
  281. break;
  282. }
  283. default:
  284. dev_err(dev->dev, "unknown intf: %d\n", intf_type);
  285. ret = -EINVAL;
  286. break;
  287. }
  288. return ret;
  289. }
  290. static int modeset_init(struct mdp5_kms *mdp5_kms)
  291. {
  292. static const enum mdp5_pipe crtcs[] = {
  293. SSPP_RGB0, SSPP_RGB1, SSPP_RGB2, SSPP_RGB3,
  294. };
  295. static const enum mdp5_pipe vig_planes[] = {
  296. SSPP_VIG0, SSPP_VIG1, SSPP_VIG2, SSPP_VIG3,
  297. };
  298. static const enum mdp5_pipe dma_planes[] = {
  299. SSPP_DMA0, SSPP_DMA1,
  300. };
  301. struct drm_device *dev = mdp5_kms->dev;
  302. struct msm_drm_private *priv = dev->dev_private;
  303. const struct mdp5_cfg_hw *hw_cfg;
  304. int i, ret;
  305. hw_cfg = mdp5_cfg_get_hw_config(mdp5_kms->cfg);
  306. /* register our interrupt-controller for hdmi/eDP/dsi/etc
  307. * to use for irqs routed through mdp:
  308. */
  309. ret = mdp5_irq_domain_init(mdp5_kms);
  310. if (ret)
  311. goto fail;
  312. /* construct CRTCs and their private planes: */
  313. for (i = 0; i < hw_cfg->pipe_rgb.count; i++) {
  314. struct drm_plane *plane;
  315. struct drm_crtc *crtc;
  316. plane = mdp5_plane_init(dev, crtcs[i], true,
  317. hw_cfg->pipe_rgb.base[i], hw_cfg->pipe_rgb.caps);
  318. if (IS_ERR(plane)) {
  319. ret = PTR_ERR(plane);
  320. dev_err(dev->dev, "failed to construct plane for %s (%d)\n",
  321. pipe2name(crtcs[i]), ret);
  322. goto fail;
  323. }
  324. crtc = mdp5_crtc_init(dev, plane, i);
  325. if (IS_ERR(crtc)) {
  326. ret = PTR_ERR(crtc);
  327. dev_err(dev->dev, "failed to construct crtc for %s (%d)\n",
  328. pipe2name(crtcs[i]), ret);
  329. goto fail;
  330. }
  331. priv->crtcs[priv->num_crtcs++] = crtc;
  332. }
  333. /* Construct video planes: */
  334. for (i = 0; i < hw_cfg->pipe_vig.count; i++) {
  335. struct drm_plane *plane;
  336. plane = mdp5_plane_init(dev, vig_planes[i], false,
  337. hw_cfg->pipe_vig.base[i], hw_cfg->pipe_vig.caps);
  338. if (IS_ERR(plane)) {
  339. ret = PTR_ERR(plane);
  340. dev_err(dev->dev, "failed to construct %s plane: %d\n",
  341. pipe2name(vig_planes[i]), ret);
  342. goto fail;
  343. }
  344. }
  345. /* DMA planes */
  346. for (i = 0; i < hw_cfg->pipe_dma.count; i++) {
  347. struct drm_plane *plane;
  348. plane = mdp5_plane_init(dev, dma_planes[i], false,
  349. hw_cfg->pipe_dma.base[i], hw_cfg->pipe_dma.caps);
  350. if (IS_ERR(plane)) {
  351. ret = PTR_ERR(plane);
  352. dev_err(dev->dev, "failed to construct %s plane: %d\n",
  353. pipe2name(dma_planes[i]), ret);
  354. goto fail;
  355. }
  356. }
  357. /* Construct encoders and modeset initialize connector devices
  358. * for each external display interface.
  359. */
  360. for (i = 0; i < ARRAY_SIZE(hw_cfg->intf.connect); i++) {
  361. ret = modeset_init_intf(mdp5_kms, i);
  362. if (ret)
  363. goto fail;
  364. }
  365. return 0;
  366. fail:
  367. return ret;
  368. }
  369. static void read_hw_revision(struct mdp5_kms *mdp5_kms,
  370. uint32_t *major, uint32_t *minor)
  371. {
  372. uint32_t version;
  373. mdp5_enable(mdp5_kms);
  374. version = mdp5_read(mdp5_kms, REG_MDSS_HW_VERSION);
  375. mdp5_disable(mdp5_kms);
  376. *major = FIELD(version, MDSS_HW_VERSION_MAJOR);
  377. *minor = FIELD(version, MDSS_HW_VERSION_MINOR);
  378. DBG("MDP5 version v%d.%d", *major, *minor);
  379. }
  380. static int get_clk(struct platform_device *pdev, struct clk **clkp,
  381. const char *name, bool mandatory)
  382. {
  383. struct device *dev = &pdev->dev;
  384. struct clk *clk = devm_clk_get(dev, name);
  385. if (IS_ERR(clk) && mandatory) {
  386. dev_err(dev, "failed to get %s (%ld)\n", name, PTR_ERR(clk));
  387. return PTR_ERR(clk);
  388. }
  389. if (IS_ERR(clk))
  390. DBG("skipping %s", name);
  391. else
  392. *clkp = clk;
  393. return 0;
  394. }
  395. struct msm_kms *mdp5_kms_init(struct drm_device *dev)
  396. {
  397. struct platform_device *pdev = dev->platformdev;
  398. struct mdp5_cfg *config;
  399. struct mdp5_kms *mdp5_kms;
  400. struct msm_kms *kms = NULL;
  401. struct msm_mmu *mmu;
  402. uint32_t major, minor;
  403. int i, ret;
  404. mdp5_kms = kzalloc(sizeof(*mdp5_kms), GFP_KERNEL);
  405. if (!mdp5_kms) {
  406. dev_err(dev->dev, "failed to allocate kms\n");
  407. ret = -ENOMEM;
  408. goto fail;
  409. }
  410. spin_lock_init(&mdp5_kms->resource_lock);
  411. mdp_kms_init(&mdp5_kms->base, &kms_funcs);
  412. kms = &mdp5_kms->base.base;
  413. mdp5_kms->dev = dev;
  414. /* mdp5_kms->mmio actually represents the MDSS base address */
  415. mdp5_kms->mmio = msm_ioremap(pdev, "mdp_phys", "MDP5");
  416. if (IS_ERR(mdp5_kms->mmio)) {
  417. ret = PTR_ERR(mdp5_kms->mmio);
  418. goto fail;
  419. }
  420. mdp5_kms->vbif = msm_ioremap(pdev, "vbif_phys", "VBIF");
  421. if (IS_ERR(mdp5_kms->vbif)) {
  422. ret = PTR_ERR(mdp5_kms->vbif);
  423. goto fail;
  424. }
  425. mdp5_kms->vdd = devm_regulator_get(&pdev->dev, "vdd");
  426. if (IS_ERR(mdp5_kms->vdd)) {
  427. ret = PTR_ERR(mdp5_kms->vdd);
  428. goto fail;
  429. }
  430. ret = regulator_enable(mdp5_kms->vdd);
  431. if (ret) {
  432. dev_err(dev->dev, "failed to enable regulator vdd: %d\n", ret);
  433. goto fail;
  434. }
  435. /* mandatory clocks: */
  436. ret = get_clk(pdev, &mdp5_kms->axi_clk, "bus_clk", true);
  437. if (ret)
  438. goto fail;
  439. ret = get_clk(pdev, &mdp5_kms->ahb_clk, "iface_clk", true);
  440. if (ret)
  441. goto fail;
  442. ret = get_clk(pdev, &mdp5_kms->src_clk, "core_clk_src", true);
  443. if (ret)
  444. goto fail;
  445. ret = get_clk(pdev, &mdp5_kms->core_clk, "core_clk", true);
  446. if (ret)
  447. goto fail;
  448. ret = get_clk(pdev, &mdp5_kms->vsync_clk, "vsync_clk", true);
  449. if (ret)
  450. goto fail;
  451. /* optional clocks: */
  452. get_clk(pdev, &mdp5_kms->lut_clk, "lut_clk", false);
  453. /* we need to set a default rate before enabling. Set a safe
  454. * rate first, then figure out hw revision, and then set a
  455. * more optimal rate:
  456. */
  457. clk_set_rate(mdp5_kms->src_clk, 200000000);
  458. read_hw_revision(mdp5_kms, &major, &minor);
  459. mdp5_kms->cfg = mdp5_cfg_init(mdp5_kms, major, minor);
  460. if (IS_ERR(mdp5_kms->cfg)) {
  461. ret = PTR_ERR(mdp5_kms->cfg);
  462. mdp5_kms->cfg = NULL;
  463. goto fail;
  464. }
  465. config = mdp5_cfg_get_config(mdp5_kms->cfg);
  466. mdp5_kms->caps = config->hw->mdp.caps;
  467. /* TODO: compute core clock rate at runtime */
  468. clk_set_rate(mdp5_kms->src_clk, config->hw->max_clk);
  469. /*
  470. * Some chipsets have a Shared Memory Pool (SMP), while others
  471. * have dedicated latency buffering per source pipe instead;
  472. * this section initializes the SMP:
  473. */
  474. if (mdp5_kms->caps & MDP_CAP_SMP) {
  475. mdp5_kms->smp = mdp5_smp_init(mdp5_kms->dev, &config->hw->smp);
  476. if (IS_ERR(mdp5_kms->smp)) {
  477. ret = PTR_ERR(mdp5_kms->smp);
  478. mdp5_kms->smp = NULL;
  479. goto fail;
  480. }
  481. }
  482. mdp5_kms->ctlm = mdp5_ctlm_init(dev, mdp5_kms->mmio, mdp5_kms->cfg);
  483. if (IS_ERR(mdp5_kms->ctlm)) {
  484. ret = PTR_ERR(mdp5_kms->ctlm);
  485. mdp5_kms->ctlm = NULL;
  486. goto fail;
  487. }
  488. /* make sure things are off before attaching iommu (bootloader could
  489. * have left things on, in which case we'll start getting faults if
  490. * we don't disable):
  491. */
  492. mdp5_enable(mdp5_kms);
  493. for (i = 0; i < MDP5_INTF_NUM_MAX; i++) {
  494. if (mdp5_cfg_intf_is_virtual(config->hw->intf.connect[i]) ||
  495. !config->hw->intf.base[i])
  496. continue;
  497. mdp5_write(mdp5_kms, REG_MDP5_INTF_TIMING_ENGINE_EN(i), 0);
  498. }
  499. mdp5_disable(mdp5_kms);
  500. mdelay(16);
  501. if (config->platform.iommu) {
  502. mmu = msm_iommu_new(&pdev->dev, config->platform.iommu);
  503. if (IS_ERR(mmu)) {
  504. ret = PTR_ERR(mmu);
  505. dev_err(dev->dev, "failed to init iommu: %d\n", ret);
  506. iommu_domain_free(config->platform.iommu);
  507. goto fail;
  508. }
  509. ret = mmu->funcs->attach(mmu, iommu_ports,
  510. ARRAY_SIZE(iommu_ports));
  511. if (ret) {
  512. dev_err(dev->dev, "failed to attach iommu: %d\n", ret);
  513. mmu->funcs->destroy(mmu);
  514. goto fail;
  515. }
  516. } else {
  517. dev_info(dev->dev, "no iommu, fallback to phys "
  518. "contig buffers for scanout\n");
  519. mmu = NULL;
  520. }
  521. mdp5_kms->mmu = mmu;
  522. mdp5_kms->id = msm_register_mmu(dev, mmu);
  523. if (mdp5_kms->id < 0) {
  524. ret = mdp5_kms->id;
  525. dev_err(dev->dev, "failed to register mdp5 iommu: %d\n", ret);
  526. goto fail;
  527. }
  528. ret = modeset_init(mdp5_kms);
  529. if (ret) {
  530. dev_err(dev->dev, "modeset_init failed: %d\n", ret);
  531. goto fail;
  532. }
  533. dev->mode_config.min_width = 0;
  534. dev->mode_config.min_height = 0;
  535. dev->mode_config.max_width = config->hw->lm.max_width;
  536. dev->mode_config.max_height = config->hw->lm.max_height;
  537. return kms;
  538. fail:
  539. if (kms)
  540. mdp5_destroy(kms);
  541. return ERR_PTR(ret);
  542. }