omap_crtc.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. /*
  2. * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
  3. * Author: Rob Clark <rob@ti.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published by
  7. * the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <drm/drm_atomic.h>
  18. #include <drm/drm_atomic_helper.h>
  19. #include <drm/drm_crtc.h>
  20. #include <drm/drm_crtc_helper.h>
  21. #include <drm/drm_mode.h>
  22. #include <drm/drm_plane_helper.h>
  23. #include <linux/math64.h>
  24. #include "omap_drv.h"
  25. #define to_omap_crtc_state(x) container_of(x, struct omap_crtc_state, base)
  26. struct omap_crtc_state {
  27. /* Must be first. */
  28. struct drm_crtc_state base;
  29. /* Shadow values for legacy userspace support. */
  30. unsigned int rotation;
  31. unsigned int zpos;
  32. };
  33. #define to_omap_crtc(x) container_of(x, struct omap_crtc, base)
  34. struct omap_crtc {
  35. struct drm_crtc base;
  36. const char *name;
  37. struct omap_drm_pipeline *pipe;
  38. enum omap_channel channel;
  39. struct videomode vm;
  40. bool ignore_digit_sync_lost;
  41. bool enabled;
  42. bool pending;
  43. wait_queue_head_t pending_wait;
  44. struct drm_pending_vblank_event *event;
  45. };
  46. /* -----------------------------------------------------------------------------
  47. * Helper Functions
  48. */
  49. struct videomode *omap_crtc_timings(struct drm_crtc *crtc)
  50. {
  51. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  52. return &omap_crtc->vm;
  53. }
  54. enum omap_channel omap_crtc_channel(struct drm_crtc *crtc)
  55. {
  56. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  57. return omap_crtc->channel;
  58. }
  59. static bool omap_crtc_is_pending(struct drm_crtc *crtc)
  60. {
  61. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  62. unsigned long flags;
  63. bool pending;
  64. spin_lock_irqsave(&crtc->dev->event_lock, flags);
  65. pending = omap_crtc->pending;
  66. spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
  67. return pending;
  68. }
  69. int omap_crtc_wait_pending(struct drm_crtc *crtc)
  70. {
  71. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  72. /*
  73. * Timeout is set to a "sufficiently" high value, which should cover
  74. * a single frame refresh even on slower displays.
  75. */
  76. return wait_event_timeout(omap_crtc->pending_wait,
  77. !omap_crtc_is_pending(crtc),
  78. msecs_to_jiffies(250));
  79. }
  80. /* -----------------------------------------------------------------------------
  81. * DSS Manager Functions
  82. */
  83. /*
  84. * Manager-ops, callbacks from output when they need to configure
  85. * the upstream part of the video pipe.
  86. *
  87. * Most of these we can ignore until we add support for command-mode
  88. * panels.. for video-mode the crtc-helpers already do an adequate
  89. * job of sequencing the setup of the video pipe in the proper order
  90. */
  91. /* we can probably ignore these until we support command-mode panels: */
  92. static void omap_crtc_dss_start_update(struct omap_drm_private *priv,
  93. enum omap_channel channel)
  94. {
  95. }
  96. /* Called only from the encoder enable/disable and suspend/resume handlers. */
  97. static void omap_crtc_set_enabled(struct drm_crtc *crtc, bool enable)
  98. {
  99. struct drm_device *dev = crtc->dev;
  100. struct omap_drm_private *priv = dev->dev_private;
  101. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  102. enum omap_channel channel = omap_crtc->channel;
  103. struct omap_irq_wait *wait;
  104. u32 framedone_irq, vsync_irq;
  105. int ret;
  106. if (WARN_ON(omap_crtc->enabled == enable))
  107. return;
  108. if (omap_crtc->pipe->output->output_type == OMAP_DISPLAY_TYPE_HDMI) {
  109. priv->dispc_ops->mgr_enable(priv->dispc, channel, enable);
  110. omap_crtc->enabled = enable;
  111. return;
  112. }
  113. if (omap_crtc->channel == OMAP_DSS_CHANNEL_DIGIT) {
  114. /*
  115. * Digit output produces some sync lost interrupts during the
  116. * first frame when enabling, so we need to ignore those.
  117. */
  118. omap_crtc->ignore_digit_sync_lost = true;
  119. }
  120. framedone_irq = priv->dispc_ops->mgr_get_framedone_irq(priv->dispc,
  121. channel);
  122. vsync_irq = priv->dispc_ops->mgr_get_vsync_irq(priv->dispc, channel);
  123. if (enable) {
  124. wait = omap_irq_wait_init(dev, vsync_irq, 1);
  125. } else {
  126. /*
  127. * When we disable the digit output, we need to wait for
  128. * FRAMEDONE to know that DISPC has finished with the output.
  129. *
  130. * OMAP2/3 does not have FRAMEDONE irq for digit output, and in
  131. * that case we need to use vsync interrupt, and wait for both
  132. * even and odd frames.
  133. */
  134. if (framedone_irq)
  135. wait = omap_irq_wait_init(dev, framedone_irq, 1);
  136. else
  137. wait = omap_irq_wait_init(dev, vsync_irq, 2);
  138. }
  139. priv->dispc_ops->mgr_enable(priv->dispc, channel, enable);
  140. omap_crtc->enabled = enable;
  141. ret = omap_irq_wait(dev, wait, msecs_to_jiffies(100));
  142. if (ret) {
  143. dev_err(dev->dev, "%s: timeout waiting for %s\n",
  144. omap_crtc->name, enable ? "enable" : "disable");
  145. }
  146. if (omap_crtc->channel == OMAP_DSS_CHANNEL_DIGIT) {
  147. omap_crtc->ignore_digit_sync_lost = false;
  148. /* make sure the irq handler sees the value above */
  149. mb();
  150. }
  151. }
  152. static int omap_crtc_dss_enable(struct omap_drm_private *priv,
  153. enum omap_channel channel)
  154. {
  155. struct drm_crtc *crtc = priv->channels[channel]->crtc;
  156. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  157. priv->dispc_ops->mgr_set_timings(priv->dispc, omap_crtc->channel,
  158. &omap_crtc->vm);
  159. omap_crtc_set_enabled(&omap_crtc->base, true);
  160. return 0;
  161. }
  162. static void omap_crtc_dss_disable(struct omap_drm_private *priv,
  163. enum omap_channel channel)
  164. {
  165. struct drm_crtc *crtc = priv->channels[channel]->crtc;
  166. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  167. omap_crtc_set_enabled(&omap_crtc->base, false);
  168. }
  169. static void omap_crtc_dss_set_timings(struct omap_drm_private *priv,
  170. enum omap_channel channel,
  171. const struct videomode *vm)
  172. {
  173. struct drm_crtc *crtc = priv->channels[channel]->crtc;
  174. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  175. DBG("%s", omap_crtc->name);
  176. omap_crtc->vm = *vm;
  177. }
  178. static void omap_crtc_dss_set_lcd_config(struct omap_drm_private *priv,
  179. enum omap_channel channel,
  180. const struct dss_lcd_mgr_config *config)
  181. {
  182. struct drm_crtc *crtc = priv->channels[channel]->crtc;
  183. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  184. DBG("%s", omap_crtc->name);
  185. priv->dispc_ops->mgr_set_lcd_config(priv->dispc, omap_crtc->channel,
  186. config);
  187. }
  188. static int omap_crtc_dss_register_framedone(
  189. struct omap_drm_private *priv, enum omap_channel channel,
  190. void (*handler)(void *), void *data)
  191. {
  192. return 0;
  193. }
  194. static void omap_crtc_dss_unregister_framedone(
  195. struct omap_drm_private *priv, enum omap_channel channel,
  196. void (*handler)(void *), void *data)
  197. {
  198. }
  199. static const struct dss_mgr_ops mgr_ops = {
  200. .start_update = omap_crtc_dss_start_update,
  201. .enable = omap_crtc_dss_enable,
  202. .disable = omap_crtc_dss_disable,
  203. .set_timings = omap_crtc_dss_set_timings,
  204. .set_lcd_config = omap_crtc_dss_set_lcd_config,
  205. .register_framedone_handler = omap_crtc_dss_register_framedone,
  206. .unregister_framedone_handler = omap_crtc_dss_unregister_framedone,
  207. };
  208. /* -----------------------------------------------------------------------------
  209. * Setup, Flush and Page Flip
  210. */
  211. void omap_crtc_error_irq(struct drm_crtc *crtc, u32 irqstatus)
  212. {
  213. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  214. if (omap_crtc->ignore_digit_sync_lost) {
  215. irqstatus &= ~DISPC_IRQ_SYNC_LOST_DIGIT;
  216. if (!irqstatus)
  217. return;
  218. }
  219. DRM_ERROR_RATELIMITED("%s: errors: %08x\n", omap_crtc->name, irqstatus);
  220. }
  221. void omap_crtc_vblank_irq(struct drm_crtc *crtc)
  222. {
  223. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  224. struct drm_device *dev = omap_crtc->base.dev;
  225. struct omap_drm_private *priv = dev->dev_private;
  226. bool pending;
  227. spin_lock(&crtc->dev->event_lock);
  228. /*
  229. * If the dispc is busy we're racing the flush operation. Try again on
  230. * the next vblank interrupt.
  231. */
  232. if (priv->dispc_ops->mgr_go_busy(priv->dispc, omap_crtc->channel)) {
  233. spin_unlock(&crtc->dev->event_lock);
  234. return;
  235. }
  236. /* Send the vblank event if one has been requested. */
  237. if (omap_crtc->event) {
  238. drm_crtc_send_vblank_event(crtc, omap_crtc->event);
  239. omap_crtc->event = NULL;
  240. }
  241. pending = omap_crtc->pending;
  242. omap_crtc->pending = false;
  243. spin_unlock(&crtc->dev->event_lock);
  244. if (pending)
  245. drm_crtc_vblank_put(crtc);
  246. /* Wake up omap_atomic_complete. */
  247. wake_up(&omap_crtc->pending_wait);
  248. DBG("%s: apply done", omap_crtc->name);
  249. }
  250. static void omap_crtc_write_crtc_properties(struct drm_crtc *crtc)
  251. {
  252. struct omap_drm_private *priv = crtc->dev->dev_private;
  253. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  254. struct omap_overlay_manager_info info;
  255. memset(&info, 0, sizeof(info));
  256. info.default_color = 0x000000;
  257. info.trans_enabled = false;
  258. info.partial_alpha_enabled = false;
  259. info.cpr_enable = false;
  260. priv->dispc_ops->mgr_setup(priv->dispc, omap_crtc->channel, &info);
  261. }
  262. /* -----------------------------------------------------------------------------
  263. * CRTC Functions
  264. */
  265. static void omap_crtc_destroy(struct drm_crtc *crtc)
  266. {
  267. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  268. DBG("%s", omap_crtc->name);
  269. drm_crtc_cleanup(crtc);
  270. kfree(omap_crtc);
  271. }
  272. static void omap_crtc_arm_event(struct drm_crtc *crtc)
  273. {
  274. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  275. WARN_ON(omap_crtc->pending);
  276. omap_crtc->pending = true;
  277. if (crtc->state->event) {
  278. omap_crtc->event = crtc->state->event;
  279. crtc->state->event = NULL;
  280. }
  281. }
  282. static void omap_crtc_atomic_enable(struct drm_crtc *crtc,
  283. struct drm_crtc_state *old_state)
  284. {
  285. struct omap_drm_private *priv = crtc->dev->dev_private;
  286. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  287. int ret;
  288. DBG("%s", omap_crtc->name);
  289. priv->dispc_ops->runtime_get(priv->dispc);
  290. spin_lock_irq(&crtc->dev->event_lock);
  291. drm_crtc_vblank_on(crtc);
  292. ret = drm_crtc_vblank_get(crtc);
  293. WARN_ON(ret != 0);
  294. omap_crtc_arm_event(crtc);
  295. spin_unlock_irq(&crtc->dev->event_lock);
  296. }
  297. static void omap_crtc_atomic_disable(struct drm_crtc *crtc,
  298. struct drm_crtc_state *old_state)
  299. {
  300. struct omap_drm_private *priv = crtc->dev->dev_private;
  301. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  302. DBG("%s", omap_crtc->name);
  303. spin_lock_irq(&crtc->dev->event_lock);
  304. if (crtc->state->event) {
  305. drm_crtc_send_vblank_event(crtc, crtc->state->event);
  306. crtc->state->event = NULL;
  307. }
  308. spin_unlock_irq(&crtc->dev->event_lock);
  309. drm_crtc_vblank_off(crtc);
  310. priv->dispc_ops->runtime_put(priv->dispc);
  311. }
  312. static enum drm_mode_status omap_crtc_mode_valid(struct drm_crtc *crtc,
  313. const struct drm_display_mode *mode)
  314. {
  315. struct omap_drm_private *priv = crtc->dev->dev_private;
  316. /* Check for bandwidth limit */
  317. if (priv->max_bandwidth) {
  318. /*
  319. * Estimation for the bandwidth need of a given mode with one
  320. * full screen plane:
  321. * bandwidth = resolution * 32bpp * (pclk / (vtotal * htotal))
  322. * ^^ Refresh rate ^^
  323. *
  324. * The interlaced mode is taken into account by using the
  325. * pixelclock in the calculation.
  326. *
  327. * The equation is rearranged for 64bit arithmetic.
  328. */
  329. uint64_t bandwidth = mode->clock * 1000;
  330. unsigned int bpp = 4;
  331. bandwidth = bandwidth * mode->hdisplay * mode->vdisplay * bpp;
  332. bandwidth = div_u64(bandwidth, mode->htotal * mode->vtotal);
  333. /*
  334. * Reject modes which would need more bandwidth if used with one
  335. * full resolution plane (most common use case).
  336. */
  337. if (priv->max_bandwidth < bandwidth)
  338. return MODE_BAD;
  339. }
  340. return MODE_OK;
  341. }
  342. static void omap_crtc_mode_set_nofb(struct drm_crtc *crtc)
  343. {
  344. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  345. struct drm_display_mode *mode = &crtc->state->adjusted_mode;
  346. DBG("%s: set mode: %d:\"%s\" %d %d %d %d %d %d %d %d %d %d 0x%x 0x%x",
  347. omap_crtc->name, mode->base.id, mode->name,
  348. mode->vrefresh, mode->clock,
  349. mode->hdisplay, mode->hsync_start, mode->hsync_end, mode->htotal,
  350. mode->vdisplay, mode->vsync_start, mode->vsync_end, mode->vtotal,
  351. mode->type, mode->flags);
  352. drm_display_mode_to_videomode(mode, &omap_crtc->vm);
  353. }
  354. static int omap_crtc_atomic_check(struct drm_crtc *crtc,
  355. struct drm_crtc_state *state)
  356. {
  357. struct drm_plane_state *pri_state;
  358. if (state->color_mgmt_changed && state->gamma_lut) {
  359. unsigned int length = state->gamma_lut->length /
  360. sizeof(struct drm_color_lut);
  361. if (length < 2)
  362. return -EINVAL;
  363. }
  364. pri_state = drm_atomic_get_new_plane_state(state->state, crtc->primary);
  365. if (pri_state) {
  366. struct omap_crtc_state *omap_crtc_state =
  367. to_omap_crtc_state(state);
  368. /* Mirror new values for zpos and rotation in omap_crtc_state */
  369. omap_crtc_state->zpos = pri_state->zpos;
  370. omap_crtc_state->rotation = pri_state->rotation;
  371. }
  372. return 0;
  373. }
  374. static void omap_crtc_atomic_begin(struct drm_crtc *crtc,
  375. struct drm_crtc_state *old_crtc_state)
  376. {
  377. }
  378. static void omap_crtc_atomic_flush(struct drm_crtc *crtc,
  379. struct drm_crtc_state *old_crtc_state)
  380. {
  381. struct omap_drm_private *priv = crtc->dev->dev_private;
  382. struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
  383. int ret;
  384. if (crtc->state->color_mgmt_changed) {
  385. struct drm_color_lut *lut = NULL;
  386. unsigned int length = 0;
  387. if (crtc->state->gamma_lut) {
  388. lut = (struct drm_color_lut *)
  389. crtc->state->gamma_lut->data;
  390. length = crtc->state->gamma_lut->length /
  391. sizeof(*lut);
  392. }
  393. priv->dispc_ops->mgr_set_gamma(priv->dispc, omap_crtc->channel,
  394. lut, length);
  395. }
  396. omap_crtc_write_crtc_properties(crtc);
  397. /* Only flush the CRTC if it is currently enabled. */
  398. if (!omap_crtc->enabled)
  399. return;
  400. DBG("%s: GO", omap_crtc->name);
  401. ret = drm_crtc_vblank_get(crtc);
  402. WARN_ON(ret != 0);
  403. spin_lock_irq(&crtc->dev->event_lock);
  404. priv->dispc_ops->mgr_go(priv->dispc, omap_crtc->channel);
  405. omap_crtc_arm_event(crtc);
  406. spin_unlock_irq(&crtc->dev->event_lock);
  407. }
  408. static int omap_crtc_atomic_set_property(struct drm_crtc *crtc,
  409. struct drm_crtc_state *state,
  410. struct drm_property *property,
  411. u64 val)
  412. {
  413. struct omap_drm_private *priv = crtc->dev->dev_private;
  414. struct drm_plane_state *plane_state;
  415. /*
  416. * Delegate property set to the primary plane. Get the plane state and
  417. * set the property directly, the shadow copy will be assigned in the
  418. * omap_crtc_atomic_check callback. This way updates to plane state will
  419. * always be mirrored in the crtc state correctly.
  420. */
  421. plane_state = drm_atomic_get_plane_state(state->state, crtc->primary);
  422. if (IS_ERR(plane_state))
  423. return PTR_ERR(plane_state);
  424. if (property == crtc->primary->rotation_property)
  425. plane_state->rotation = val;
  426. else if (property == priv->zorder_prop)
  427. plane_state->zpos = val;
  428. else
  429. return -EINVAL;
  430. return 0;
  431. }
  432. static int omap_crtc_atomic_get_property(struct drm_crtc *crtc,
  433. const struct drm_crtc_state *state,
  434. struct drm_property *property,
  435. u64 *val)
  436. {
  437. struct omap_drm_private *priv = crtc->dev->dev_private;
  438. struct omap_crtc_state *omap_state = to_omap_crtc_state(state);
  439. if (property == crtc->primary->rotation_property)
  440. *val = omap_state->rotation;
  441. else if (property == priv->zorder_prop)
  442. *val = omap_state->zpos;
  443. else
  444. return -EINVAL;
  445. return 0;
  446. }
  447. static void omap_crtc_reset(struct drm_crtc *crtc)
  448. {
  449. if (crtc->state)
  450. __drm_atomic_helper_crtc_destroy_state(crtc->state);
  451. kfree(crtc->state);
  452. crtc->state = kzalloc(sizeof(struct omap_crtc_state), GFP_KERNEL);
  453. if (crtc->state)
  454. crtc->state->crtc = crtc;
  455. }
  456. static struct drm_crtc_state *
  457. omap_crtc_duplicate_state(struct drm_crtc *crtc)
  458. {
  459. struct omap_crtc_state *state, *current_state;
  460. if (WARN_ON(!crtc->state))
  461. return NULL;
  462. current_state = to_omap_crtc_state(crtc->state);
  463. state = kmalloc(sizeof(*state), GFP_KERNEL);
  464. if (!state)
  465. return NULL;
  466. __drm_atomic_helper_crtc_duplicate_state(crtc, &state->base);
  467. state->zpos = current_state->zpos;
  468. state->rotation = current_state->rotation;
  469. return &state->base;
  470. }
  471. static const struct drm_crtc_funcs omap_crtc_funcs = {
  472. .reset = omap_crtc_reset,
  473. .set_config = drm_atomic_helper_set_config,
  474. .destroy = omap_crtc_destroy,
  475. .page_flip = drm_atomic_helper_page_flip,
  476. .gamma_set = drm_atomic_helper_legacy_gamma_set,
  477. .atomic_duplicate_state = omap_crtc_duplicate_state,
  478. .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
  479. .atomic_set_property = omap_crtc_atomic_set_property,
  480. .atomic_get_property = omap_crtc_atomic_get_property,
  481. .enable_vblank = omap_irq_enable_vblank,
  482. .disable_vblank = omap_irq_disable_vblank,
  483. };
  484. static const struct drm_crtc_helper_funcs omap_crtc_helper_funcs = {
  485. .mode_set_nofb = omap_crtc_mode_set_nofb,
  486. .atomic_check = omap_crtc_atomic_check,
  487. .atomic_begin = omap_crtc_atomic_begin,
  488. .atomic_flush = omap_crtc_atomic_flush,
  489. .atomic_enable = omap_crtc_atomic_enable,
  490. .atomic_disable = omap_crtc_atomic_disable,
  491. .mode_valid = omap_crtc_mode_valid,
  492. };
  493. /* -----------------------------------------------------------------------------
  494. * Init and Cleanup
  495. */
  496. static const char *channel_names[] = {
  497. [OMAP_DSS_CHANNEL_LCD] = "lcd",
  498. [OMAP_DSS_CHANNEL_DIGIT] = "tv",
  499. [OMAP_DSS_CHANNEL_LCD2] = "lcd2",
  500. [OMAP_DSS_CHANNEL_LCD3] = "lcd3",
  501. };
  502. void omap_crtc_pre_init(struct omap_drm_private *priv)
  503. {
  504. dss_install_mgr_ops(priv->dss, &mgr_ops, priv);
  505. }
  506. void omap_crtc_pre_uninit(struct omap_drm_private *priv)
  507. {
  508. dss_uninstall_mgr_ops(priv->dss);
  509. }
  510. /* initialize crtc */
  511. struct drm_crtc *omap_crtc_init(struct drm_device *dev,
  512. struct omap_drm_pipeline *pipe,
  513. struct drm_plane *plane)
  514. {
  515. struct omap_drm_private *priv = dev->dev_private;
  516. struct drm_crtc *crtc = NULL;
  517. struct omap_crtc *omap_crtc;
  518. enum omap_channel channel;
  519. int ret;
  520. channel = pipe->output->dispc_channel;
  521. DBG("%s", channel_names[channel]);
  522. omap_crtc = kzalloc(sizeof(*omap_crtc), GFP_KERNEL);
  523. if (!omap_crtc)
  524. return ERR_PTR(-ENOMEM);
  525. crtc = &omap_crtc->base;
  526. init_waitqueue_head(&omap_crtc->pending_wait);
  527. omap_crtc->pipe = pipe;
  528. omap_crtc->channel = channel;
  529. omap_crtc->name = channel_names[channel];
  530. ret = drm_crtc_init_with_planes(dev, crtc, plane, NULL,
  531. &omap_crtc_funcs, NULL);
  532. if (ret < 0) {
  533. dev_err(dev->dev, "%s(): could not init crtc for: %s\n",
  534. __func__, pipe->display->name);
  535. kfree(omap_crtc);
  536. return ERR_PTR(ret);
  537. }
  538. drm_crtc_helper_add(crtc, &omap_crtc_helper_funcs);
  539. /* The dispc API adapts to what ever size, but the HW supports
  540. * 256 element gamma table for LCDs and 1024 element table for
  541. * OMAP_DSS_CHANNEL_DIGIT. X server assumes 256 element gamma
  542. * tables so lets use that. Size of HW gamma table can be
  543. * extracted with dispc_mgr_gamma_size(). If it returns 0
  544. * gamma table is not supprted.
  545. */
  546. if (priv->dispc_ops->mgr_gamma_size(priv->dispc, channel)) {
  547. unsigned int gamma_lut_size = 256;
  548. drm_crtc_enable_color_mgmt(crtc, 0, false, gamma_lut_size);
  549. drm_mode_crtc_set_gamma_size(crtc, gamma_lut_size);
  550. }
  551. omap_plane_install_properties(crtc->primary, &crtc->base);
  552. return crtc;
  553. }