dc.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076
  1. /*
  2. * Copyright (C) 2012 Avionic Design GmbH
  3. * Copyright (C) 2012 NVIDIA CORPORATION. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. #include <linux/clk.h>
  10. #include <linux/debugfs.h>
  11. #include <linux/module.h>
  12. #include <linux/of.h>
  13. #include <linux/platform_device.h>
  14. #include <mach/clk.h>
  15. #include "drm.h"
  16. #include "dc.h"
  17. struct tegra_plane {
  18. struct drm_plane base;
  19. unsigned int index;
  20. };
  21. static inline struct tegra_plane *to_tegra_plane(struct drm_plane *plane)
  22. {
  23. return container_of(plane, struct tegra_plane, base);
  24. }
  25. static int tegra_plane_update(struct drm_plane *plane, struct drm_crtc *crtc,
  26. struct drm_framebuffer *fb, int crtc_x,
  27. int crtc_y, unsigned int crtc_w,
  28. unsigned int crtc_h, uint32_t src_x,
  29. uint32_t src_y, uint32_t src_w, uint32_t src_h)
  30. {
  31. struct tegra_plane *p = to_tegra_plane(plane);
  32. struct tegra_dc *dc = to_tegra_dc(crtc);
  33. struct tegra_dc_window window;
  34. unsigned int i;
  35. memset(&window, 0, sizeof(window));
  36. window.src.x = src_x >> 16;
  37. window.src.y = src_y >> 16;
  38. window.src.w = src_w >> 16;
  39. window.src.h = src_h >> 16;
  40. window.dst.x = crtc_x;
  41. window.dst.y = crtc_y;
  42. window.dst.w = crtc_w;
  43. window.dst.h = crtc_h;
  44. window.format = tegra_dc_format(fb->pixel_format);
  45. window.bits_per_pixel = fb->bits_per_pixel;
  46. for (i = 0; i < drm_format_num_planes(fb->pixel_format); i++) {
  47. struct drm_gem_cma_object *gem = drm_fb_cma_get_gem_obj(fb, i);
  48. window.base[i] = gem->paddr + fb->offsets[i];
  49. /*
  50. * Tegra doesn't support different strides for U and V planes
  51. * so we display a warning if the user tries to display a
  52. * framebuffer with such a configuration.
  53. */
  54. if (i >= 2) {
  55. if (fb->pitches[i] != window.stride[1])
  56. DRM_ERROR("unsupported UV-plane configuration\n");
  57. } else {
  58. window.stride[i] = fb->pitches[i];
  59. }
  60. }
  61. return tegra_dc_setup_window(dc, p->index, &window);
  62. }
  63. static int tegra_plane_disable(struct drm_plane *plane)
  64. {
  65. struct tegra_dc *dc = to_tegra_dc(plane->crtc);
  66. struct tegra_plane *p = to_tegra_plane(plane);
  67. unsigned long value;
  68. value = WINDOW_A_SELECT << p->index;
  69. tegra_dc_writel(dc, value, DC_CMD_DISPLAY_WINDOW_HEADER);
  70. value = tegra_dc_readl(dc, DC_WIN_WIN_OPTIONS);
  71. value &= ~WIN_ENABLE;
  72. tegra_dc_writel(dc, value, DC_WIN_WIN_OPTIONS);
  73. tegra_dc_writel(dc, WIN_A_UPDATE << p->index, DC_CMD_STATE_CONTROL);
  74. tegra_dc_writel(dc, WIN_A_ACT_REQ << p->index, DC_CMD_STATE_CONTROL);
  75. return 0;
  76. }
  77. static void tegra_plane_destroy(struct drm_plane *plane)
  78. {
  79. tegra_plane_disable(plane);
  80. drm_plane_cleanup(plane);
  81. }
  82. static const struct drm_plane_funcs tegra_plane_funcs = {
  83. .update_plane = tegra_plane_update,
  84. .disable_plane = tegra_plane_disable,
  85. .destroy = tegra_plane_destroy,
  86. };
  87. static const uint32_t plane_formats[] = {
  88. DRM_FORMAT_XRGB8888,
  89. DRM_FORMAT_UYVY,
  90. DRM_FORMAT_YUV420,
  91. DRM_FORMAT_YUV422,
  92. };
  93. static int tegra_dc_add_planes(struct drm_device *drm, struct tegra_dc *dc)
  94. {
  95. unsigned int i;
  96. int err = 0;
  97. for (i = 0; i < 2; i++) {
  98. struct tegra_plane *plane;
  99. plane = devm_kzalloc(drm->dev, sizeof(*plane), GFP_KERNEL);
  100. if (!plane)
  101. return -ENOMEM;
  102. plane->index = 1 + i;
  103. err = drm_plane_init(drm, &plane->base, 1 << dc->pipe,
  104. &tegra_plane_funcs, plane_formats,
  105. ARRAY_SIZE(plane_formats), false);
  106. if (err < 0)
  107. return err;
  108. }
  109. return 0;
  110. }
  111. static const struct drm_crtc_funcs tegra_crtc_funcs = {
  112. .set_config = drm_crtc_helper_set_config,
  113. .destroy = drm_crtc_cleanup,
  114. };
  115. static void tegra_crtc_disable(struct drm_crtc *crtc)
  116. {
  117. struct drm_device *drm = crtc->dev;
  118. struct drm_plane *plane;
  119. list_for_each_entry(plane, &drm->mode_config.plane_list, head) {
  120. if (plane->crtc == crtc) {
  121. tegra_plane_disable(plane);
  122. plane->crtc = NULL;
  123. if (plane->fb) {
  124. drm_framebuffer_unreference(plane->fb);
  125. plane->fb = NULL;
  126. }
  127. }
  128. }
  129. }
  130. static bool tegra_crtc_mode_fixup(struct drm_crtc *crtc,
  131. const struct drm_display_mode *mode,
  132. struct drm_display_mode *adjusted)
  133. {
  134. return true;
  135. }
  136. static inline u32 compute_dda_inc(unsigned int in, unsigned int out, bool v,
  137. unsigned int bpp)
  138. {
  139. fixed20_12 outf = dfixed_init(out);
  140. fixed20_12 inf = dfixed_init(in);
  141. u32 dda_inc;
  142. int max;
  143. if (v)
  144. max = 15;
  145. else {
  146. switch (bpp) {
  147. case 2:
  148. max = 8;
  149. break;
  150. default:
  151. WARN_ON_ONCE(1);
  152. /* fallthrough */
  153. case 4:
  154. max = 4;
  155. break;
  156. }
  157. }
  158. outf.full = max_t(u32, outf.full - dfixed_const(1), dfixed_const(1));
  159. inf.full -= dfixed_const(1);
  160. dda_inc = dfixed_div(inf, outf);
  161. dda_inc = min_t(u32, dda_inc, dfixed_const(max));
  162. return dda_inc;
  163. }
  164. static inline u32 compute_initial_dda(unsigned int in)
  165. {
  166. fixed20_12 inf = dfixed_init(in);
  167. return dfixed_frac(inf);
  168. }
  169. static int tegra_dc_set_timings(struct tegra_dc *dc,
  170. struct drm_display_mode *mode)
  171. {
  172. /* TODO: For HDMI compliance, h & v ref_to_sync should be set to 1 */
  173. unsigned int h_ref_to_sync = 0;
  174. unsigned int v_ref_to_sync = 0;
  175. unsigned long value;
  176. tegra_dc_writel(dc, 0x0, DC_DISP_DISP_TIMING_OPTIONS);
  177. value = (v_ref_to_sync << 16) | h_ref_to_sync;
  178. tegra_dc_writel(dc, value, DC_DISP_REF_TO_SYNC);
  179. value = ((mode->vsync_end - mode->vsync_start) << 16) |
  180. ((mode->hsync_end - mode->hsync_start) << 0);
  181. tegra_dc_writel(dc, value, DC_DISP_SYNC_WIDTH);
  182. value = ((mode->vtotal - mode->vsync_end) << 16) |
  183. ((mode->htotal - mode->hsync_end) << 0);
  184. tegra_dc_writel(dc, value, DC_DISP_BACK_PORCH);
  185. value = ((mode->vsync_start - mode->vdisplay) << 16) |
  186. ((mode->hsync_start - mode->hdisplay) << 0);
  187. tegra_dc_writel(dc, value, DC_DISP_FRONT_PORCH);
  188. value = (mode->vdisplay << 16) | mode->hdisplay;
  189. tegra_dc_writel(dc, value, DC_DISP_ACTIVE);
  190. return 0;
  191. }
  192. static int tegra_crtc_setup_clk(struct drm_crtc *crtc,
  193. struct drm_display_mode *mode,
  194. unsigned long *div)
  195. {
  196. unsigned long pclk = mode->clock * 1000, rate;
  197. struct tegra_dc *dc = to_tegra_dc(crtc);
  198. struct tegra_output *output = NULL;
  199. struct drm_encoder *encoder;
  200. long err;
  201. list_for_each_entry(encoder, &crtc->dev->mode_config.encoder_list, head)
  202. if (encoder->crtc == crtc) {
  203. output = encoder_to_output(encoder);
  204. break;
  205. }
  206. if (!output)
  207. return -ENODEV;
  208. /*
  209. * This assumes that the display controller will divide its parent
  210. * clock by 2 to generate the pixel clock.
  211. */
  212. err = tegra_output_setup_clock(output, dc->clk, pclk * 2);
  213. if (err < 0) {
  214. dev_err(dc->dev, "failed to setup clock: %ld\n", err);
  215. return err;
  216. }
  217. rate = clk_get_rate(dc->clk);
  218. *div = (rate * 2 / pclk) - 2;
  219. DRM_DEBUG_KMS("rate: %lu, div: %lu\n", rate, *div);
  220. return 0;
  221. }
  222. static bool tegra_dc_format_is_yuv(unsigned int format, bool *planar)
  223. {
  224. switch (format) {
  225. case WIN_COLOR_DEPTH_YCbCr422:
  226. case WIN_COLOR_DEPTH_YUV422:
  227. if (planar)
  228. *planar = false;
  229. return true;
  230. case WIN_COLOR_DEPTH_YCbCr420P:
  231. case WIN_COLOR_DEPTH_YUV420P:
  232. case WIN_COLOR_DEPTH_YCbCr422P:
  233. case WIN_COLOR_DEPTH_YUV422P:
  234. case WIN_COLOR_DEPTH_YCbCr422R:
  235. case WIN_COLOR_DEPTH_YUV422R:
  236. case WIN_COLOR_DEPTH_YCbCr422RA:
  237. case WIN_COLOR_DEPTH_YUV422RA:
  238. if (planar)
  239. *planar = true;
  240. return true;
  241. }
  242. return false;
  243. }
  244. int tegra_dc_setup_window(struct tegra_dc *dc, unsigned int index,
  245. const struct tegra_dc_window *window)
  246. {
  247. unsigned h_offset, v_offset, h_size, v_size, h_dda, v_dda, bpp;
  248. unsigned long value;
  249. bool yuv, planar;
  250. /*
  251. * For YUV planar modes, the number of bytes per pixel takes into
  252. * account only the luma component and therefore is 1.
  253. */
  254. yuv = tegra_dc_format_is_yuv(window->format, &planar);
  255. if (!yuv)
  256. bpp = window->bits_per_pixel / 8;
  257. else
  258. bpp = planar ? 1 : 2;
  259. value = WINDOW_A_SELECT << index;
  260. tegra_dc_writel(dc, value, DC_CMD_DISPLAY_WINDOW_HEADER);
  261. tegra_dc_writel(dc, window->format, DC_WIN_COLOR_DEPTH);
  262. tegra_dc_writel(dc, 0, DC_WIN_BYTE_SWAP);
  263. value = V_POSITION(window->dst.y) | H_POSITION(window->dst.x);
  264. tegra_dc_writel(dc, value, DC_WIN_POSITION);
  265. value = V_SIZE(window->dst.h) | H_SIZE(window->dst.w);
  266. tegra_dc_writel(dc, value, DC_WIN_SIZE);
  267. h_offset = window->src.x * bpp;
  268. v_offset = window->src.y;
  269. h_size = window->src.w * bpp;
  270. v_size = window->src.h;
  271. value = V_PRESCALED_SIZE(v_size) | H_PRESCALED_SIZE(h_size);
  272. tegra_dc_writel(dc, value, DC_WIN_PRESCALED_SIZE);
  273. /*
  274. * For DDA computations the number of bytes per pixel for YUV planar
  275. * modes needs to take into account all Y, U and V components.
  276. */
  277. if (yuv && planar)
  278. bpp = 2;
  279. h_dda = compute_dda_inc(window->src.w, window->dst.w, false, bpp);
  280. v_dda = compute_dda_inc(window->src.h, window->dst.h, true, bpp);
  281. value = V_DDA_INC(v_dda) | H_DDA_INC(h_dda);
  282. tegra_dc_writel(dc, value, DC_WIN_DDA_INC);
  283. h_dda = compute_initial_dda(window->src.x);
  284. v_dda = compute_initial_dda(window->src.y);
  285. tegra_dc_writel(dc, h_dda, DC_WIN_H_INITIAL_DDA);
  286. tegra_dc_writel(dc, v_dda, DC_WIN_V_INITIAL_DDA);
  287. tegra_dc_writel(dc, 0, DC_WIN_UV_BUF_STRIDE);
  288. tegra_dc_writel(dc, 0, DC_WIN_BUF_STRIDE);
  289. tegra_dc_writel(dc, window->base[0], DC_WINBUF_START_ADDR);
  290. if (yuv && planar) {
  291. tegra_dc_writel(dc, window->base[1], DC_WINBUF_START_ADDR_U);
  292. tegra_dc_writel(dc, window->base[2], DC_WINBUF_START_ADDR_V);
  293. value = window->stride[1] << 16 | window->stride[0];
  294. tegra_dc_writel(dc, value, DC_WIN_LINE_STRIDE);
  295. } else {
  296. tegra_dc_writel(dc, window->stride[0], DC_WIN_LINE_STRIDE);
  297. }
  298. tegra_dc_writel(dc, h_offset, DC_WINBUF_ADDR_H_OFFSET);
  299. tegra_dc_writel(dc, v_offset, DC_WINBUF_ADDR_V_OFFSET);
  300. value = WIN_ENABLE;
  301. if (yuv) {
  302. /* setup default colorspace conversion coefficients */
  303. tegra_dc_writel(dc, 0x00f0, DC_WIN_CSC_YOF);
  304. tegra_dc_writel(dc, 0x012a, DC_WIN_CSC_KYRGB);
  305. tegra_dc_writel(dc, 0x0000, DC_WIN_CSC_KUR);
  306. tegra_dc_writel(dc, 0x0198, DC_WIN_CSC_KVR);
  307. tegra_dc_writel(dc, 0x039b, DC_WIN_CSC_KUG);
  308. tegra_dc_writel(dc, 0x032f, DC_WIN_CSC_KVG);
  309. tegra_dc_writel(dc, 0x0204, DC_WIN_CSC_KUB);
  310. tegra_dc_writel(dc, 0x0000, DC_WIN_CSC_KVB);
  311. value |= CSC_ENABLE;
  312. } else if (bpp < 24) {
  313. value |= COLOR_EXPAND;
  314. }
  315. tegra_dc_writel(dc, value, DC_WIN_WIN_OPTIONS);
  316. /*
  317. * Disable blending and assume Window A is the bottom-most window,
  318. * Window C is the top-most window and Window B is in the middle.
  319. */
  320. tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_NOKEY);
  321. tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_1WIN);
  322. switch (index) {
  323. case 0:
  324. tegra_dc_writel(dc, 0x000000, DC_WIN_BLEND_2WIN_X);
  325. tegra_dc_writel(dc, 0x000000, DC_WIN_BLEND_2WIN_Y);
  326. tegra_dc_writel(dc, 0x000000, DC_WIN_BLEND_3WIN_XY);
  327. break;
  328. case 1:
  329. tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_2WIN_X);
  330. tegra_dc_writel(dc, 0x000000, DC_WIN_BLEND_2WIN_Y);
  331. tegra_dc_writel(dc, 0x000000, DC_WIN_BLEND_3WIN_XY);
  332. break;
  333. case 2:
  334. tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_2WIN_X);
  335. tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_2WIN_Y);
  336. tegra_dc_writel(dc, 0xffff00, DC_WIN_BLEND_3WIN_XY);
  337. break;
  338. }
  339. tegra_dc_writel(dc, WIN_A_UPDATE << index, DC_CMD_STATE_CONTROL);
  340. tegra_dc_writel(dc, WIN_A_ACT_REQ << index, DC_CMD_STATE_CONTROL);
  341. return 0;
  342. }
  343. unsigned int tegra_dc_format(uint32_t format)
  344. {
  345. switch (format) {
  346. case DRM_FORMAT_XRGB8888:
  347. return WIN_COLOR_DEPTH_B8G8R8A8;
  348. case DRM_FORMAT_RGB565:
  349. return WIN_COLOR_DEPTH_B5G6R5;
  350. case DRM_FORMAT_UYVY:
  351. return WIN_COLOR_DEPTH_YCbCr422;
  352. case DRM_FORMAT_YUV420:
  353. return WIN_COLOR_DEPTH_YCbCr420P;
  354. case DRM_FORMAT_YUV422:
  355. return WIN_COLOR_DEPTH_YCbCr422P;
  356. default:
  357. break;
  358. }
  359. WARN(1, "unsupported pixel format %u, using default\n", format);
  360. return WIN_COLOR_DEPTH_B8G8R8A8;
  361. }
  362. static int tegra_crtc_mode_set(struct drm_crtc *crtc,
  363. struct drm_display_mode *mode,
  364. struct drm_display_mode *adjusted,
  365. int x, int y, struct drm_framebuffer *old_fb)
  366. {
  367. struct drm_gem_cma_object *gem = drm_fb_cma_get_gem_obj(crtc->fb, 0);
  368. struct tegra_dc *dc = to_tegra_dc(crtc);
  369. struct tegra_dc_window window;
  370. unsigned long div, value;
  371. int err;
  372. err = tegra_crtc_setup_clk(crtc, mode, &div);
  373. if (err) {
  374. dev_err(dc->dev, "failed to setup clock for CRTC: %d\n", err);
  375. return err;
  376. }
  377. /* program display mode */
  378. tegra_dc_set_timings(dc, mode);
  379. value = DE_SELECT_ACTIVE | DE_CONTROL_NORMAL;
  380. tegra_dc_writel(dc, value, DC_DISP_DATA_ENABLE_OPTIONS);
  381. value = tegra_dc_readl(dc, DC_COM_PIN_OUTPUT_POLARITY(1));
  382. value &= ~LVS_OUTPUT_POLARITY_LOW;
  383. value &= ~LHS_OUTPUT_POLARITY_LOW;
  384. tegra_dc_writel(dc, value, DC_COM_PIN_OUTPUT_POLARITY(1));
  385. value = DISP_DATA_FORMAT_DF1P1C | DISP_ALIGNMENT_MSB |
  386. DISP_ORDER_RED_BLUE;
  387. tegra_dc_writel(dc, value, DC_DISP_DISP_INTERFACE_CONTROL);
  388. tegra_dc_writel(dc, 0x00010001, DC_DISP_SHIFT_CLOCK_OPTIONS);
  389. value = SHIFT_CLK_DIVIDER(div) | PIXEL_CLK_DIVIDER_PCD1;
  390. tegra_dc_writel(dc, value, DC_DISP_DISP_CLOCK_CONTROL);
  391. /* setup window parameters */
  392. memset(&window, 0, sizeof(window));
  393. window.src.x = 0;
  394. window.src.y = 0;
  395. window.src.w = mode->hdisplay;
  396. window.src.h = mode->vdisplay;
  397. window.dst.x = 0;
  398. window.dst.y = 0;
  399. window.dst.w = mode->hdisplay;
  400. window.dst.h = mode->vdisplay;
  401. window.format = tegra_dc_format(crtc->fb->pixel_format);
  402. window.bits_per_pixel = crtc->fb->bits_per_pixel;
  403. window.stride[0] = crtc->fb->pitches[0];
  404. window.base[0] = gem->paddr;
  405. err = tegra_dc_setup_window(dc, 0, &window);
  406. if (err < 0)
  407. dev_err(dc->dev, "failed to enable root plane\n");
  408. return 0;
  409. }
  410. static void tegra_crtc_prepare(struct drm_crtc *crtc)
  411. {
  412. struct tegra_dc *dc = to_tegra_dc(crtc);
  413. unsigned int syncpt;
  414. unsigned long value;
  415. /* hardware initialization */
  416. tegra_periph_reset_deassert(dc->clk);
  417. usleep_range(10000, 20000);
  418. if (dc->pipe)
  419. syncpt = SYNCPT_VBLANK1;
  420. else
  421. syncpt = SYNCPT_VBLANK0;
  422. /* initialize display controller */
  423. tegra_dc_writel(dc, 0x00000100, DC_CMD_GENERAL_INCR_SYNCPT_CNTRL);
  424. tegra_dc_writel(dc, 0x100 | syncpt, DC_CMD_CONT_SYNCPT_VSYNC);
  425. value = WIN_A_UF_INT | WIN_B_UF_INT | WIN_C_UF_INT | WIN_A_OF_INT;
  426. tegra_dc_writel(dc, value, DC_CMD_INT_TYPE);
  427. value = WIN_A_UF_INT | WIN_B_UF_INT | WIN_C_UF_INT |
  428. WIN_A_OF_INT | WIN_B_OF_INT | WIN_C_OF_INT;
  429. tegra_dc_writel(dc, value, DC_CMD_INT_POLARITY);
  430. value = PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE |
  431. PW4_ENABLE | PM0_ENABLE | PM1_ENABLE;
  432. tegra_dc_writel(dc, value, DC_CMD_DISPLAY_POWER_CONTROL);
  433. value = tegra_dc_readl(dc, DC_CMD_DISPLAY_COMMAND);
  434. value |= DISP_CTRL_MODE_C_DISPLAY;
  435. tegra_dc_writel(dc, value, DC_CMD_DISPLAY_COMMAND);
  436. /* initialize timer */
  437. value = CURSOR_THRESHOLD(0) | WINDOW_A_THRESHOLD(0x20) |
  438. WINDOW_B_THRESHOLD(0x20) | WINDOW_C_THRESHOLD(0x20);
  439. tegra_dc_writel(dc, value, DC_DISP_DISP_MEM_HIGH_PRIORITY);
  440. value = CURSOR_THRESHOLD(0) | WINDOW_A_THRESHOLD(1) |
  441. WINDOW_B_THRESHOLD(1) | WINDOW_C_THRESHOLD(1);
  442. tegra_dc_writel(dc, value, DC_DISP_DISP_MEM_HIGH_PRIORITY_TIMER);
  443. value = VBLANK_INT | WIN_A_UF_INT | WIN_B_UF_INT | WIN_C_UF_INT;
  444. tegra_dc_writel(dc, value, DC_CMD_INT_MASK);
  445. value = VBLANK_INT | WIN_A_UF_INT | WIN_B_UF_INT | WIN_C_UF_INT;
  446. tegra_dc_writel(dc, value, DC_CMD_INT_ENABLE);
  447. }
  448. static void tegra_crtc_commit(struct drm_crtc *crtc)
  449. {
  450. struct tegra_dc *dc = to_tegra_dc(crtc);
  451. unsigned long update_mask;
  452. unsigned long value;
  453. update_mask = GENERAL_ACT_REQ | WIN_A_ACT_REQ;
  454. tegra_dc_writel(dc, update_mask << 8, DC_CMD_STATE_CONTROL);
  455. value = tegra_dc_readl(dc, DC_CMD_INT_ENABLE);
  456. value |= FRAME_END_INT;
  457. tegra_dc_writel(dc, value, DC_CMD_INT_ENABLE);
  458. value = tegra_dc_readl(dc, DC_CMD_INT_MASK);
  459. value |= FRAME_END_INT;
  460. tegra_dc_writel(dc, value, DC_CMD_INT_MASK);
  461. tegra_dc_writel(dc, update_mask, DC_CMD_STATE_CONTROL);
  462. }
  463. static void tegra_crtc_load_lut(struct drm_crtc *crtc)
  464. {
  465. }
  466. static const struct drm_crtc_helper_funcs tegra_crtc_helper_funcs = {
  467. .disable = tegra_crtc_disable,
  468. .mode_fixup = tegra_crtc_mode_fixup,
  469. .mode_set = tegra_crtc_mode_set,
  470. .prepare = tegra_crtc_prepare,
  471. .commit = tegra_crtc_commit,
  472. .load_lut = tegra_crtc_load_lut,
  473. };
  474. static irqreturn_t tegra_drm_irq(int irq, void *data)
  475. {
  476. struct tegra_dc *dc = data;
  477. unsigned long status;
  478. status = tegra_dc_readl(dc, DC_CMD_INT_STATUS);
  479. tegra_dc_writel(dc, status, DC_CMD_INT_STATUS);
  480. if (status & FRAME_END_INT) {
  481. /*
  482. dev_dbg(dc->dev, "%s(): frame end\n", __func__);
  483. */
  484. }
  485. if (status & VBLANK_INT) {
  486. /*
  487. dev_dbg(dc->dev, "%s(): vertical blank\n", __func__);
  488. */
  489. drm_handle_vblank(dc->base.dev, dc->pipe);
  490. }
  491. if (status & (WIN_A_UF_INT | WIN_B_UF_INT | WIN_C_UF_INT)) {
  492. /*
  493. dev_dbg(dc->dev, "%s(): underflow\n", __func__);
  494. */
  495. }
  496. return IRQ_HANDLED;
  497. }
  498. static int tegra_dc_show_regs(struct seq_file *s, void *data)
  499. {
  500. struct drm_info_node *node = s->private;
  501. struct tegra_dc *dc = node->info_ent->data;
  502. #define DUMP_REG(name) \
  503. seq_printf(s, "%-40s %#05x %08lx\n", #name, name, \
  504. tegra_dc_readl(dc, name))
  505. DUMP_REG(DC_CMD_GENERAL_INCR_SYNCPT);
  506. DUMP_REG(DC_CMD_GENERAL_INCR_SYNCPT_CNTRL);
  507. DUMP_REG(DC_CMD_GENERAL_INCR_SYNCPT_ERROR);
  508. DUMP_REG(DC_CMD_WIN_A_INCR_SYNCPT);
  509. DUMP_REG(DC_CMD_WIN_A_INCR_SYNCPT_CNTRL);
  510. DUMP_REG(DC_CMD_WIN_A_INCR_SYNCPT_ERROR);
  511. DUMP_REG(DC_CMD_WIN_B_INCR_SYNCPT);
  512. DUMP_REG(DC_CMD_WIN_B_INCR_SYNCPT_CNTRL);
  513. DUMP_REG(DC_CMD_WIN_B_INCR_SYNCPT_ERROR);
  514. DUMP_REG(DC_CMD_WIN_C_INCR_SYNCPT);
  515. DUMP_REG(DC_CMD_WIN_C_INCR_SYNCPT_CNTRL);
  516. DUMP_REG(DC_CMD_WIN_C_INCR_SYNCPT_ERROR);
  517. DUMP_REG(DC_CMD_CONT_SYNCPT_VSYNC);
  518. DUMP_REG(DC_CMD_DISPLAY_COMMAND_OPTION0);
  519. DUMP_REG(DC_CMD_DISPLAY_COMMAND);
  520. DUMP_REG(DC_CMD_SIGNAL_RAISE);
  521. DUMP_REG(DC_CMD_DISPLAY_POWER_CONTROL);
  522. DUMP_REG(DC_CMD_INT_STATUS);
  523. DUMP_REG(DC_CMD_INT_MASK);
  524. DUMP_REG(DC_CMD_INT_ENABLE);
  525. DUMP_REG(DC_CMD_INT_TYPE);
  526. DUMP_REG(DC_CMD_INT_POLARITY);
  527. DUMP_REG(DC_CMD_SIGNAL_RAISE1);
  528. DUMP_REG(DC_CMD_SIGNAL_RAISE2);
  529. DUMP_REG(DC_CMD_SIGNAL_RAISE3);
  530. DUMP_REG(DC_CMD_STATE_ACCESS);
  531. DUMP_REG(DC_CMD_STATE_CONTROL);
  532. DUMP_REG(DC_CMD_DISPLAY_WINDOW_HEADER);
  533. DUMP_REG(DC_CMD_REG_ACT_CONTROL);
  534. DUMP_REG(DC_COM_CRC_CONTROL);
  535. DUMP_REG(DC_COM_CRC_CHECKSUM);
  536. DUMP_REG(DC_COM_PIN_OUTPUT_ENABLE(0));
  537. DUMP_REG(DC_COM_PIN_OUTPUT_ENABLE(1));
  538. DUMP_REG(DC_COM_PIN_OUTPUT_ENABLE(2));
  539. DUMP_REG(DC_COM_PIN_OUTPUT_ENABLE(3));
  540. DUMP_REG(DC_COM_PIN_OUTPUT_POLARITY(0));
  541. DUMP_REG(DC_COM_PIN_OUTPUT_POLARITY(1));
  542. DUMP_REG(DC_COM_PIN_OUTPUT_POLARITY(2));
  543. DUMP_REG(DC_COM_PIN_OUTPUT_POLARITY(3));
  544. DUMP_REG(DC_COM_PIN_OUTPUT_DATA(0));
  545. DUMP_REG(DC_COM_PIN_OUTPUT_DATA(1));
  546. DUMP_REG(DC_COM_PIN_OUTPUT_DATA(2));
  547. DUMP_REG(DC_COM_PIN_OUTPUT_DATA(3));
  548. DUMP_REG(DC_COM_PIN_INPUT_ENABLE(0));
  549. DUMP_REG(DC_COM_PIN_INPUT_ENABLE(1));
  550. DUMP_REG(DC_COM_PIN_INPUT_ENABLE(2));
  551. DUMP_REG(DC_COM_PIN_INPUT_ENABLE(3));
  552. DUMP_REG(DC_COM_PIN_INPUT_DATA(0));
  553. DUMP_REG(DC_COM_PIN_INPUT_DATA(1));
  554. DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(0));
  555. DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(1));
  556. DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(2));
  557. DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(3));
  558. DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(4));
  559. DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(5));
  560. DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(6));
  561. DUMP_REG(DC_COM_PIN_MISC_CONTROL);
  562. DUMP_REG(DC_COM_PIN_PM0_CONTROL);
  563. DUMP_REG(DC_COM_PIN_PM0_DUTY_CYCLE);
  564. DUMP_REG(DC_COM_PIN_PM1_CONTROL);
  565. DUMP_REG(DC_COM_PIN_PM1_DUTY_CYCLE);
  566. DUMP_REG(DC_COM_SPI_CONTROL);
  567. DUMP_REG(DC_COM_SPI_START_BYTE);
  568. DUMP_REG(DC_COM_HSPI_WRITE_DATA_AB);
  569. DUMP_REG(DC_COM_HSPI_WRITE_DATA_CD);
  570. DUMP_REG(DC_COM_HSPI_CS_DC);
  571. DUMP_REG(DC_COM_SCRATCH_REGISTER_A);
  572. DUMP_REG(DC_COM_SCRATCH_REGISTER_B);
  573. DUMP_REG(DC_COM_GPIO_CTRL);
  574. DUMP_REG(DC_COM_GPIO_DEBOUNCE_COUNTER);
  575. DUMP_REG(DC_COM_CRC_CHECKSUM_LATCHED);
  576. DUMP_REG(DC_DISP_DISP_SIGNAL_OPTIONS0);
  577. DUMP_REG(DC_DISP_DISP_SIGNAL_OPTIONS1);
  578. DUMP_REG(DC_DISP_DISP_WIN_OPTIONS);
  579. DUMP_REG(DC_DISP_DISP_MEM_HIGH_PRIORITY);
  580. DUMP_REG(DC_DISP_DISP_MEM_HIGH_PRIORITY_TIMER);
  581. DUMP_REG(DC_DISP_DISP_TIMING_OPTIONS);
  582. DUMP_REG(DC_DISP_REF_TO_SYNC);
  583. DUMP_REG(DC_DISP_SYNC_WIDTH);
  584. DUMP_REG(DC_DISP_BACK_PORCH);
  585. DUMP_REG(DC_DISP_ACTIVE);
  586. DUMP_REG(DC_DISP_FRONT_PORCH);
  587. DUMP_REG(DC_DISP_H_PULSE0_CONTROL);
  588. DUMP_REG(DC_DISP_H_PULSE0_POSITION_A);
  589. DUMP_REG(DC_DISP_H_PULSE0_POSITION_B);
  590. DUMP_REG(DC_DISP_H_PULSE0_POSITION_C);
  591. DUMP_REG(DC_DISP_H_PULSE0_POSITION_D);
  592. DUMP_REG(DC_DISP_H_PULSE1_CONTROL);
  593. DUMP_REG(DC_DISP_H_PULSE1_POSITION_A);
  594. DUMP_REG(DC_DISP_H_PULSE1_POSITION_B);
  595. DUMP_REG(DC_DISP_H_PULSE1_POSITION_C);
  596. DUMP_REG(DC_DISP_H_PULSE1_POSITION_D);
  597. DUMP_REG(DC_DISP_H_PULSE2_CONTROL);
  598. DUMP_REG(DC_DISP_H_PULSE2_POSITION_A);
  599. DUMP_REG(DC_DISP_H_PULSE2_POSITION_B);
  600. DUMP_REG(DC_DISP_H_PULSE2_POSITION_C);
  601. DUMP_REG(DC_DISP_H_PULSE2_POSITION_D);
  602. DUMP_REG(DC_DISP_V_PULSE0_CONTROL);
  603. DUMP_REG(DC_DISP_V_PULSE0_POSITION_A);
  604. DUMP_REG(DC_DISP_V_PULSE0_POSITION_B);
  605. DUMP_REG(DC_DISP_V_PULSE0_POSITION_C);
  606. DUMP_REG(DC_DISP_V_PULSE1_CONTROL);
  607. DUMP_REG(DC_DISP_V_PULSE1_POSITION_A);
  608. DUMP_REG(DC_DISP_V_PULSE1_POSITION_B);
  609. DUMP_REG(DC_DISP_V_PULSE1_POSITION_C);
  610. DUMP_REG(DC_DISP_V_PULSE2_CONTROL);
  611. DUMP_REG(DC_DISP_V_PULSE2_POSITION_A);
  612. DUMP_REG(DC_DISP_V_PULSE3_CONTROL);
  613. DUMP_REG(DC_DISP_V_PULSE3_POSITION_A);
  614. DUMP_REG(DC_DISP_M0_CONTROL);
  615. DUMP_REG(DC_DISP_M1_CONTROL);
  616. DUMP_REG(DC_DISP_DI_CONTROL);
  617. DUMP_REG(DC_DISP_PP_CONTROL);
  618. DUMP_REG(DC_DISP_PP_SELECT_A);
  619. DUMP_REG(DC_DISP_PP_SELECT_B);
  620. DUMP_REG(DC_DISP_PP_SELECT_C);
  621. DUMP_REG(DC_DISP_PP_SELECT_D);
  622. DUMP_REG(DC_DISP_DISP_CLOCK_CONTROL);
  623. DUMP_REG(DC_DISP_DISP_INTERFACE_CONTROL);
  624. DUMP_REG(DC_DISP_DISP_COLOR_CONTROL);
  625. DUMP_REG(DC_DISP_SHIFT_CLOCK_OPTIONS);
  626. DUMP_REG(DC_DISP_DATA_ENABLE_OPTIONS);
  627. DUMP_REG(DC_DISP_SERIAL_INTERFACE_OPTIONS);
  628. DUMP_REG(DC_DISP_LCD_SPI_OPTIONS);
  629. DUMP_REG(DC_DISP_BORDER_COLOR);
  630. DUMP_REG(DC_DISP_COLOR_KEY0_LOWER);
  631. DUMP_REG(DC_DISP_COLOR_KEY0_UPPER);
  632. DUMP_REG(DC_DISP_COLOR_KEY1_LOWER);
  633. DUMP_REG(DC_DISP_COLOR_KEY1_UPPER);
  634. DUMP_REG(DC_DISP_CURSOR_FOREGROUND);
  635. DUMP_REG(DC_DISP_CURSOR_BACKGROUND);
  636. DUMP_REG(DC_DISP_CURSOR_START_ADDR);
  637. DUMP_REG(DC_DISP_CURSOR_START_ADDR_NS);
  638. DUMP_REG(DC_DISP_CURSOR_POSITION);
  639. DUMP_REG(DC_DISP_CURSOR_POSITION_NS);
  640. DUMP_REG(DC_DISP_INIT_SEQ_CONTROL);
  641. DUMP_REG(DC_DISP_SPI_INIT_SEQ_DATA_A);
  642. DUMP_REG(DC_DISP_SPI_INIT_SEQ_DATA_B);
  643. DUMP_REG(DC_DISP_SPI_INIT_SEQ_DATA_C);
  644. DUMP_REG(DC_DISP_SPI_INIT_SEQ_DATA_D);
  645. DUMP_REG(DC_DISP_DC_MCCIF_FIFOCTRL);
  646. DUMP_REG(DC_DISP_MCCIF_DISPLAY0A_HYST);
  647. DUMP_REG(DC_DISP_MCCIF_DISPLAY0B_HYST);
  648. DUMP_REG(DC_DISP_MCCIF_DISPLAY1A_HYST);
  649. DUMP_REG(DC_DISP_MCCIF_DISPLAY1B_HYST);
  650. DUMP_REG(DC_DISP_DAC_CRT_CTRL);
  651. DUMP_REG(DC_DISP_DISP_MISC_CONTROL);
  652. DUMP_REG(DC_DISP_SD_CONTROL);
  653. DUMP_REG(DC_DISP_SD_CSC_COEFF);
  654. DUMP_REG(DC_DISP_SD_LUT(0));
  655. DUMP_REG(DC_DISP_SD_LUT(1));
  656. DUMP_REG(DC_DISP_SD_LUT(2));
  657. DUMP_REG(DC_DISP_SD_LUT(3));
  658. DUMP_REG(DC_DISP_SD_LUT(4));
  659. DUMP_REG(DC_DISP_SD_LUT(5));
  660. DUMP_REG(DC_DISP_SD_LUT(6));
  661. DUMP_REG(DC_DISP_SD_LUT(7));
  662. DUMP_REG(DC_DISP_SD_LUT(8));
  663. DUMP_REG(DC_DISP_SD_FLICKER_CONTROL);
  664. DUMP_REG(DC_DISP_DC_PIXEL_COUNT);
  665. DUMP_REG(DC_DISP_SD_HISTOGRAM(0));
  666. DUMP_REG(DC_DISP_SD_HISTOGRAM(1));
  667. DUMP_REG(DC_DISP_SD_HISTOGRAM(2));
  668. DUMP_REG(DC_DISP_SD_HISTOGRAM(3));
  669. DUMP_REG(DC_DISP_SD_HISTOGRAM(4));
  670. DUMP_REG(DC_DISP_SD_HISTOGRAM(5));
  671. DUMP_REG(DC_DISP_SD_HISTOGRAM(6));
  672. DUMP_REG(DC_DISP_SD_HISTOGRAM(7));
  673. DUMP_REG(DC_DISP_SD_BL_TF(0));
  674. DUMP_REG(DC_DISP_SD_BL_TF(1));
  675. DUMP_REG(DC_DISP_SD_BL_TF(2));
  676. DUMP_REG(DC_DISP_SD_BL_TF(3));
  677. DUMP_REG(DC_DISP_SD_BL_CONTROL);
  678. DUMP_REG(DC_DISP_SD_HW_K_VALUES);
  679. DUMP_REG(DC_DISP_SD_MAN_K_VALUES);
  680. DUMP_REG(DC_WIN_WIN_OPTIONS);
  681. DUMP_REG(DC_WIN_BYTE_SWAP);
  682. DUMP_REG(DC_WIN_BUFFER_CONTROL);
  683. DUMP_REG(DC_WIN_COLOR_DEPTH);
  684. DUMP_REG(DC_WIN_POSITION);
  685. DUMP_REG(DC_WIN_SIZE);
  686. DUMP_REG(DC_WIN_PRESCALED_SIZE);
  687. DUMP_REG(DC_WIN_H_INITIAL_DDA);
  688. DUMP_REG(DC_WIN_V_INITIAL_DDA);
  689. DUMP_REG(DC_WIN_DDA_INC);
  690. DUMP_REG(DC_WIN_LINE_STRIDE);
  691. DUMP_REG(DC_WIN_BUF_STRIDE);
  692. DUMP_REG(DC_WIN_UV_BUF_STRIDE);
  693. DUMP_REG(DC_WIN_BUFFER_ADDR_MODE);
  694. DUMP_REG(DC_WIN_DV_CONTROL);
  695. DUMP_REG(DC_WIN_BLEND_NOKEY);
  696. DUMP_REG(DC_WIN_BLEND_1WIN);
  697. DUMP_REG(DC_WIN_BLEND_2WIN_X);
  698. DUMP_REG(DC_WIN_BLEND_2WIN_Y);
  699. DUMP_REG(DC_WIN_BLEND_3WIN_XY);
  700. DUMP_REG(DC_WIN_HP_FETCH_CONTROL);
  701. DUMP_REG(DC_WINBUF_START_ADDR);
  702. DUMP_REG(DC_WINBUF_START_ADDR_NS);
  703. DUMP_REG(DC_WINBUF_START_ADDR_U);
  704. DUMP_REG(DC_WINBUF_START_ADDR_U_NS);
  705. DUMP_REG(DC_WINBUF_START_ADDR_V);
  706. DUMP_REG(DC_WINBUF_START_ADDR_V_NS);
  707. DUMP_REG(DC_WINBUF_ADDR_H_OFFSET);
  708. DUMP_REG(DC_WINBUF_ADDR_H_OFFSET_NS);
  709. DUMP_REG(DC_WINBUF_ADDR_V_OFFSET);
  710. DUMP_REG(DC_WINBUF_ADDR_V_OFFSET_NS);
  711. DUMP_REG(DC_WINBUF_UFLOW_STATUS);
  712. DUMP_REG(DC_WINBUF_AD_UFLOW_STATUS);
  713. DUMP_REG(DC_WINBUF_BD_UFLOW_STATUS);
  714. DUMP_REG(DC_WINBUF_CD_UFLOW_STATUS);
  715. #undef DUMP_REG
  716. return 0;
  717. }
  718. static struct drm_info_list debugfs_files[] = {
  719. { "regs", tegra_dc_show_regs, 0, NULL },
  720. };
  721. static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
  722. {
  723. unsigned int i;
  724. char *name;
  725. int err;
  726. name = kasprintf(GFP_KERNEL, "dc.%d", dc->pipe);
  727. dc->debugfs = debugfs_create_dir(name, minor->debugfs_root);
  728. kfree(name);
  729. if (!dc->debugfs)
  730. return -ENOMEM;
  731. dc->debugfs_files = kmemdup(debugfs_files, sizeof(debugfs_files),
  732. GFP_KERNEL);
  733. if (!dc->debugfs_files) {
  734. err = -ENOMEM;
  735. goto remove;
  736. }
  737. for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
  738. dc->debugfs_files[i].data = dc;
  739. err = drm_debugfs_create_files(dc->debugfs_files,
  740. ARRAY_SIZE(debugfs_files),
  741. dc->debugfs, minor);
  742. if (err < 0)
  743. goto free;
  744. dc->minor = minor;
  745. return 0;
  746. free:
  747. kfree(dc->debugfs_files);
  748. dc->debugfs_files = NULL;
  749. remove:
  750. debugfs_remove(dc->debugfs);
  751. dc->debugfs = NULL;
  752. return err;
  753. }
  754. static int tegra_dc_debugfs_exit(struct tegra_dc *dc)
  755. {
  756. drm_debugfs_remove_files(dc->debugfs_files, ARRAY_SIZE(debugfs_files),
  757. dc->minor);
  758. dc->minor = NULL;
  759. kfree(dc->debugfs_files);
  760. dc->debugfs_files = NULL;
  761. debugfs_remove(dc->debugfs);
  762. dc->debugfs = NULL;
  763. return 0;
  764. }
  765. static int tegra_dc_drm_init(struct host1x_client *client,
  766. struct drm_device *drm)
  767. {
  768. struct tegra_dc *dc = host1x_client_to_dc(client);
  769. int err;
  770. dc->pipe = drm->mode_config.num_crtc;
  771. drm_crtc_init(drm, &dc->base, &tegra_crtc_funcs);
  772. drm_mode_crtc_set_gamma_size(&dc->base, 256);
  773. drm_crtc_helper_add(&dc->base, &tegra_crtc_helper_funcs);
  774. err = tegra_dc_rgb_init(drm, dc);
  775. if (err < 0 && err != -ENODEV) {
  776. dev_err(dc->dev, "failed to initialize RGB output: %d\n", err);
  777. return err;
  778. }
  779. err = tegra_dc_add_planes(drm, dc);
  780. if (err < 0)
  781. return err;
  782. if (IS_ENABLED(CONFIG_DEBUG_FS)) {
  783. err = tegra_dc_debugfs_init(dc, drm->primary);
  784. if (err < 0)
  785. dev_err(dc->dev, "debugfs setup failed: %d\n", err);
  786. }
  787. err = devm_request_irq(dc->dev, dc->irq, tegra_drm_irq, 0,
  788. dev_name(dc->dev), dc);
  789. if (err < 0) {
  790. dev_err(dc->dev, "failed to request IRQ#%u: %d\n", dc->irq,
  791. err);
  792. return err;
  793. }
  794. return 0;
  795. }
  796. static int tegra_dc_drm_exit(struct host1x_client *client)
  797. {
  798. struct tegra_dc *dc = host1x_client_to_dc(client);
  799. int err;
  800. devm_free_irq(dc->dev, dc->irq, dc);
  801. if (IS_ENABLED(CONFIG_DEBUG_FS)) {
  802. err = tegra_dc_debugfs_exit(dc);
  803. if (err < 0)
  804. dev_err(dc->dev, "debugfs cleanup failed: %d\n", err);
  805. }
  806. err = tegra_dc_rgb_exit(dc);
  807. if (err) {
  808. dev_err(dc->dev, "failed to shutdown RGB output: %d\n", err);
  809. return err;
  810. }
  811. return 0;
  812. }
  813. static const struct host1x_client_ops dc_client_ops = {
  814. .drm_init = tegra_dc_drm_init,
  815. .drm_exit = tegra_dc_drm_exit,
  816. };
  817. static int tegra_dc_probe(struct platform_device *pdev)
  818. {
  819. struct host1x *host1x = dev_get_drvdata(pdev->dev.parent);
  820. struct resource *regs;
  821. struct tegra_dc *dc;
  822. int err;
  823. dc = devm_kzalloc(&pdev->dev, sizeof(*dc), GFP_KERNEL);
  824. if (!dc)
  825. return -ENOMEM;
  826. INIT_LIST_HEAD(&dc->list);
  827. dc->dev = &pdev->dev;
  828. dc->clk = devm_clk_get(&pdev->dev, NULL);
  829. if (IS_ERR(dc->clk)) {
  830. dev_err(&pdev->dev, "failed to get clock\n");
  831. return PTR_ERR(dc->clk);
  832. }
  833. err = clk_prepare_enable(dc->clk);
  834. if (err < 0)
  835. return err;
  836. regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  837. if (!regs) {
  838. dev_err(&pdev->dev, "failed to get registers\n");
  839. return -ENXIO;
  840. }
  841. dc->regs = devm_request_and_ioremap(&pdev->dev, regs);
  842. if (!dc->regs) {
  843. dev_err(&pdev->dev, "failed to remap registers\n");
  844. return -ENXIO;
  845. }
  846. dc->irq = platform_get_irq(pdev, 0);
  847. if (dc->irq < 0) {
  848. dev_err(&pdev->dev, "failed to get IRQ\n");
  849. return -ENXIO;
  850. }
  851. INIT_LIST_HEAD(&dc->client.list);
  852. dc->client.ops = &dc_client_ops;
  853. dc->client.dev = &pdev->dev;
  854. err = tegra_dc_rgb_probe(dc);
  855. if (err < 0 && err != -ENODEV) {
  856. dev_err(&pdev->dev, "failed to probe RGB output: %d\n", err);
  857. return err;
  858. }
  859. err = host1x_register_client(host1x, &dc->client);
  860. if (err < 0) {
  861. dev_err(&pdev->dev, "failed to register host1x client: %d\n",
  862. err);
  863. return err;
  864. }
  865. platform_set_drvdata(pdev, dc);
  866. return 0;
  867. }
  868. static int tegra_dc_remove(struct platform_device *pdev)
  869. {
  870. struct host1x *host1x = dev_get_drvdata(pdev->dev.parent);
  871. struct tegra_dc *dc = platform_get_drvdata(pdev);
  872. int err;
  873. err = host1x_unregister_client(host1x, &dc->client);
  874. if (err < 0) {
  875. dev_err(&pdev->dev, "failed to unregister host1x client: %d\n",
  876. err);
  877. return err;
  878. }
  879. clk_disable_unprepare(dc->clk);
  880. return 0;
  881. }
  882. static struct of_device_id tegra_dc_of_match[] = {
  883. { .compatible = "nvidia,tegra30-dc", },
  884. { .compatible = "nvidia,tegra20-dc", },
  885. { },
  886. };
  887. struct platform_driver tegra_dc_driver = {
  888. .driver = {
  889. .name = "tegra-dc",
  890. .owner = THIS_MODULE,
  891. .of_match_table = tegra_dc_of_match,
  892. },
  893. .probe = tegra_dc_probe,
  894. .remove = tegra_dc_remove,
  895. };