oaktrail_hdmi.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  1. /*
  2. * Copyright © 2010 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. * DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Li Peng <[email protected]>
  25. */
  26. #include <linux/delay.h>
  27. #include <drm/drm.h>
  28. #include <drm/drm_edid.h>
  29. #include <drm/drm_simple_kms_helper.h>
  30. #include "psb_drv.h"
  31. #include "psb_intel_drv.h"
  32. #include "psb_intel_reg.h"
  33. #define HDMI_READ(reg) readl(hdmi_dev->regs + (reg))
  34. #define HDMI_WRITE(reg, val) writel(val, hdmi_dev->regs + (reg))
  35. #define HDMI_HCR 0x1000
  36. #define HCR_ENABLE_HDCP (1 << 5)
  37. #define HCR_ENABLE_AUDIO (1 << 2)
  38. #define HCR_ENABLE_PIXEL (1 << 1)
  39. #define HCR_ENABLE_TMDS (1 << 0)
  40. #define HDMI_HICR 0x1004
  41. #define HDMI_HSR 0x1008
  42. #define HDMI_HISR 0x100C
  43. #define HDMI_DETECT_HDP (1 << 0)
  44. #define HDMI_VIDEO_REG 0x3000
  45. #define HDMI_UNIT_EN (1 << 7)
  46. #define HDMI_MODE_OUTPUT (1 << 0)
  47. #define HDMI_HBLANK_A 0x3100
  48. #define HDMI_AUDIO_CTRL 0x4000
  49. #define HDMI_ENABLE_AUDIO (1 << 0)
  50. #define PCH_HTOTAL_B 0x3100
  51. #define PCH_HBLANK_B 0x3104
  52. #define PCH_HSYNC_B 0x3108
  53. #define PCH_VTOTAL_B 0x310C
  54. #define PCH_VBLANK_B 0x3110
  55. #define PCH_VSYNC_B 0x3114
  56. #define PCH_PIPEBSRC 0x311C
  57. #define PCH_PIPEB_DSL 0x3800
  58. #define PCH_PIPEB_SLC 0x3804
  59. #define PCH_PIPEBCONF 0x3808
  60. #define PCH_PIPEBSTAT 0x3824
  61. #define CDVO_DFT 0x5000
  62. #define CDVO_SLEWRATE 0x5004
  63. #define CDVO_STRENGTH 0x5008
  64. #define CDVO_RCOMP 0x500C
  65. #define DPLL_CTRL 0x6000
  66. #define DPLL_PDIV_SHIFT 16
  67. #define DPLL_PDIV_MASK (0xf << 16)
  68. #define DPLL_PWRDN (1 << 4)
  69. #define DPLL_RESET (1 << 3)
  70. #define DPLL_FASTEN (1 << 2)
  71. #define DPLL_ENSTAT (1 << 1)
  72. #define DPLL_DITHEN (1 << 0)
  73. #define DPLL_DIV_CTRL 0x6004
  74. #define DPLL_CLKF_MASK 0xffffffc0
  75. #define DPLL_CLKR_MASK (0x3f)
  76. #define DPLL_CLK_ENABLE 0x6008
  77. #define DPLL_EN_DISP (1 << 31)
  78. #define DPLL_SEL_HDMI (1 << 8)
  79. #define DPLL_EN_HDMI (1 << 1)
  80. #define DPLL_EN_VGA (1 << 0)
  81. #define DPLL_ADJUST 0x600C
  82. #define DPLL_STATUS 0x6010
  83. #define DPLL_UPDATE 0x6014
  84. #define DPLL_DFT 0x6020
  85. struct intel_range {
  86. int min, max;
  87. };
  88. struct oaktrail_hdmi_limit {
  89. struct intel_range vco, np, nr, nf;
  90. };
  91. struct oaktrail_hdmi_clock {
  92. int np;
  93. int nr;
  94. int nf;
  95. int dot;
  96. };
  97. #define VCO_MIN 320000
  98. #define VCO_MAX 1650000
  99. #define NP_MIN 1
  100. #define NP_MAX 15
  101. #define NR_MIN 1
  102. #define NR_MAX 64
  103. #define NF_MIN 2
  104. #define NF_MAX 4095
  105. static const struct oaktrail_hdmi_limit oaktrail_hdmi_limit = {
  106. .vco = { .min = VCO_MIN, .max = VCO_MAX },
  107. .np = { .min = NP_MIN, .max = NP_MAX },
  108. .nr = { .min = NR_MIN, .max = NR_MAX },
  109. .nf = { .min = NF_MIN, .max = NF_MAX },
  110. };
  111. static void oaktrail_hdmi_audio_enable(struct drm_device *dev)
  112. {
  113. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  114. struct oaktrail_hdmi_dev *hdmi_dev = dev_priv->hdmi_priv;
  115. HDMI_WRITE(HDMI_HCR, 0x67);
  116. HDMI_READ(HDMI_HCR);
  117. HDMI_WRITE(0x51a8, 0x10);
  118. HDMI_READ(0x51a8);
  119. HDMI_WRITE(HDMI_AUDIO_CTRL, 0x1);
  120. HDMI_READ(HDMI_AUDIO_CTRL);
  121. }
  122. static void oaktrail_hdmi_audio_disable(struct drm_device *dev)
  123. {
  124. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  125. struct oaktrail_hdmi_dev *hdmi_dev = dev_priv->hdmi_priv;
  126. HDMI_WRITE(0x51a8, 0x0);
  127. HDMI_READ(0x51a8);
  128. HDMI_WRITE(HDMI_AUDIO_CTRL, 0x0);
  129. HDMI_READ(HDMI_AUDIO_CTRL);
  130. HDMI_WRITE(HDMI_HCR, 0x47);
  131. HDMI_READ(HDMI_HCR);
  132. }
  133. static unsigned int htotal_calculate(struct drm_display_mode *mode)
  134. {
  135. u32 new_crtc_htotal;
  136. /*
  137. * 1024 x 768 new_crtc_htotal = 0x1024;
  138. * 1280 x 1024 new_crtc_htotal = 0x0c34;
  139. */
  140. new_crtc_htotal = (mode->crtc_htotal - 1) * 200 * 1000 / mode->clock;
  141. DRM_DEBUG_KMS("new crtc htotal 0x%4x\n", new_crtc_htotal);
  142. return (mode->crtc_hdisplay - 1) | (new_crtc_htotal << 16);
  143. }
  144. static void oaktrail_hdmi_find_dpll(struct drm_crtc *crtc, int target,
  145. int refclk, struct oaktrail_hdmi_clock *best_clock)
  146. {
  147. int np_min, np_max, nr_min, nr_max;
  148. int np, nr, nf;
  149. np_min = DIV_ROUND_UP(oaktrail_hdmi_limit.vco.min, target * 10);
  150. np_max = oaktrail_hdmi_limit.vco.max / (target * 10);
  151. if (np_min < oaktrail_hdmi_limit.np.min)
  152. np_min = oaktrail_hdmi_limit.np.min;
  153. if (np_max > oaktrail_hdmi_limit.np.max)
  154. np_max = oaktrail_hdmi_limit.np.max;
  155. nr_min = DIV_ROUND_UP((refclk * 1000), (target * 10 * np_max));
  156. nr_max = DIV_ROUND_UP((refclk * 1000), (target * 10 * np_min));
  157. if (nr_min < oaktrail_hdmi_limit.nr.min)
  158. nr_min = oaktrail_hdmi_limit.nr.min;
  159. if (nr_max > oaktrail_hdmi_limit.nr.max)
  160. nr_max = oaktrail_hdmi_limit.nr.max;
  161. np = DIV_ROUND_UP((refclk * 1000), (target * 10 * nr_max));
  162. nr = DIV_ROUND_UP((refclk * 1000), (target * 10 * np));
  163. nf = DIV_ROUND_CLOSEST((target * 10 * np * nr), refclk);
  164. DRM_DEBUG_KMS("np, nr, nf %d %d %d\n", np, nr, nf);
  165. /*
  166. * 1024 x 768 np = 1; nr = 0x26; nf = 0x0fd8000;
  167. * 1280 x 1024 np = 1; nr = 0x17; nf = 0x1034000;
  168. */
  169. best_clock->np = np;
  170. best_clock->nr = nr - 1;
  171. best_clock->nf = (nf << 14);
  172. }
  173. static void scu_busy_loop(void __iomem *scu_base)
  174. {
  175. u32 status = 0;
  176. u32 loop_count = 0;
  177. status = readl(scu_base + 0x04);
  178. while (status & 1) {
  179. udelay(1); /* scu processing time is in few u secods */
  180. status = readl(scu_base + 0x04);
  181. loop_count++;
  182. /* break if scu doesn't reset busy bit after huge retry */
  183. if (loop_count > 1000) {
  184. DRM_DEBUG_KMS("SCU IPC timed out");
  185. return;
  186. }
  187. }
  188. }
  189. /*
  190. * You don't want to know, you really really don't want to know....
  191. *
  192. * This is magic. However it's safe magic because of the way the platform
  193. * works and it is necessary magic.
  194. */
  195. static void oaktrail_hdmi_reset(struct drm_device *dev)
  196. {
  197. void __iomem *base;
  198. unsigned long scu_ipc_mmio = 0xff11c000UL;
  199. int scu_len = 1024;
  200. base = ioremap((resource_size_t)scu_ipc_mmio, scu_len);
  201. if (base == NULL) {
  202. DRM_ERROR("failed to map scu mmio\n");
  203. return;
  204. }
  205. /* scu ipc: assert hdmi controller reset */
  206. writel(0xff11d118, base + 0x0c);
  207. writel(0x7fffffdf, base + 0x80);
  208. writel(0x42005, base + 0x0);
  209. scu_busy_loop(base);
  210. /* scu ipc: de-assert hdmi controller reset */
  211. writel(0xff11d118, base + 0x0c);
  212. writel(0x7fffffff, base + 0x80);
  213. writel(0x42005, base + 0x0);
  214. scu_busy_loop(base);
  215. iounmap(base);
  216. }
  217. int oaktrail_crtc_hdmi_mode_set(struct drm_crtc *crtc,
  218. struct drm_display_mode *mode,
  219. struct drm_display_mode *adjusted_mode,
  220. int x, int y,
  221. struct drm_framebuffer *old_fb)
  222. {
  223. struct drm_device *dev = crtc->dev;
  224. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  225. struct oaktrail_hdmi_dev *hdmi_dev = dev_priv->hdmi_priv;
  226. int pipe = 1;
  227. int htot_reg = (pipe == 0) ? HTOTAL_A : HTOTAL_B;
  228. int hblank_reg = (pipe == 0) ? HBLANK_A : HBLANK_B;
  229. int hsync_reg = (pipe == 0) ? HSYNC_A : HSYNC_B;
  230. int vtot_reg = (pipe == 0) ? VTOTAL_A : VTOTAL_B;
  231. int vblank_reg = (pipe == 0) ? VBLANK_A : VBLANK_B;
  232. int vsync_reg = (pipe == 0) ? VSYNC_A : VSYNC_B;
  233. int dspsize_reg = (pipe == 0) ? DSPASIZE : DSPBSIZE;
  234. int dsppos_reg = (pipe == 0) ? DSPAPOS : DSPBPOS;
  235. int pipesrc_reg = (pipe == 0) ? PIPEASRC : PIPEBSRC;
  236. int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF;
  237. int refclk;
  238. struct oaktrail_hdmi_clock clock;
  239. u32 dspcntr, pipeconf, dpll, temp;
  240. int dspcntr_reg = DSPBCNTR;
  241. if (!gma_power_begin(dev, true))
  242. return 0;
  243. /* Disable the VGA plane that we never use */
  244. REG_WRITE(VGACNTRL, VGA_DISP_DISABLE);
  245. /* Disable dpll if necessary */
  246. dpll = REG_READ(DPLL_CTRL);
  247. if ((dpll & DPLL_PWRDN) == 0) {
  248. REG_WRITE(DPLL_CTRL, dpll | (DPLL_PWRDN | DPLL_RESET));
  249. REG_WRITE(DPLL_DIV_CTRL, 0x00000000);
  250. REG_WRITE(DPLL_STATUS, 0x1);
  251. }
  252. udelay(150);
  253. /* Reset controller */
  254. oaktrail_hdmi_reset(dev);
  255. /* program and enable dpll */
  256. refclk = 25000;
  257. oaktrail_hdmi_find_dpll(crtc, adjusted_mode->clock, refclk, &clock);
  258. /* Set the DPLL */
  259. dpll = REG_READ(DPLL_CTRL);
  260. dpll &= ~DPLL_PDIV_MASK;
  261. dpll &= ~(DPLL_PWRDN | DPLL_RESET);
  262. REG_WRITE(DPLL_CTRL, 0x00000008);
  263. REG_WRITE(DPLL_DIV_CTRL, ((clock.nf << 6) | clock.nr));
  264. REG_WRITE(DPLL_ADJUST, ((clock.nf >> 14) - 1));
  265. REG_WRITE(DPLL_CTRL, (dpll | (clock.np << DPLL_PDIV_SHIFT) | DPLL_ENSTAT | DPLL_DITHEN));
  266. REG_WRITE(DPLL_UPDATE, 0x80000000);
  267. REG_WRITE(DPLL_CLK_ENABLE, 0x80050102);
  268. udelay(150);
  269. /* configure HDMI */
  270. HDMI_WRITE(0x1004, 0x1fd);
  271. HDMI_WRITE(0x2000, 0x1);
  272. HDMI_WRITE(0x2008, 0x0);
  273. HDMI_WRITE(0x3130, 0x8);
  274. HDMI_WRITE(0x101c, 0x1800810);
  275. temp = htotal_calculate(adjusted_mode);
  276. REG_WRITE(htot_reg, temp);
  277. REG_WRITE(hblank_reg, (adjusted_mode->crtc_hblank_start - 1) | ((adjusted_mode->crtc_hblank_end - 1) << 16));
  278. REG_WRITE(hsync_reg, (adjusted_mode->crtc_hsync_start - 1) | ((adjusted_mode->crtc_hsync_end - 1) << 16));
  279. REG_WRITE(vtot_reg, (adjusted_mode->crtc_vdisplay - 1) | ((adjusted_mode->crtc_vtotal - 1) << 16));
  280. REG_WRITE(vblank_reg, (adjusted_mode->crtc_vblank_start - 1) | ((adjusted_mode->crtc_vblank_end - 1) << 16));
  281. REG_WRITE(vsync_reg, (adjusted_mode->crtc_vsync_start - 1) | ((adjusted_mode->crtc_vsync_end - 1) << 16));
  282. REG_WRITE(pipesrc_reg, ((mode->crtc_hdisplay - 1) << 16) | (mode->crtc_vdisplay - 1));
  283. REG_WRITE(PCH_HTOTAL_B, (adjusted_mode->crtc_hdisplay - 1) | ((adjusted_mode->crtc_htotal - 1) << 16));
  284. REG_WRITE(PCH_HBLANK_B, (adjusted_mode->crtc_hblank_start - 1) | ((adjusted_mode->crtc_hblank_end - 1) << 16));
  285. REG_WRITE(PCH_HSYNC_B, (adjusted_mode->crtc_hsync_start - 1) | ((adjusted_mode->crtc_hsync_end - 1) << 16));
  286. REG_WRITE(PCH_VTOTAL_B, (adjusted_mode->crtc_vdisplay - 1) | ((adjusted_mode->crtc_vtotal - 1) << 16));
  287. REG_WRITE(PCH_VBLANK_B, (adjusted_mode->crtc_vblank_start - 1) | ((adjusted_mode->crtc_vblank_end - 1) << 16));
  288. REG_WRITE(PCH_VSYNC_B, (adjusted_mode->crtc_vsync_start - 1) | ((adjusted_mode->crtc_vsync_end - 1) << 16));
  289. REG_WRITE(PCH_PIPEBSRC, ((mode->crtc_hdisplay - 1) << 16) | (mode->crtc_vdisplay - 1));
  290. temp = adjusted_mode->crtc_hblank_end - adjusted_mode->crtc_hblank_start;
  291. HDMI_WRITE(HDMI_HBLANK_A, ((adjusted_mode->crtc_hdisplay - 1) << 16) | temp);
  292. REG_WRITE(dspsize_reg, ((mode->vdisplay - 1) << 16) | (mode->hdisplay - 1));
  293. REG_WRITE(dsppos_reg, 0);
  294. /* Flush the plane changes */
  295. {
  296. const struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  297. crtc_funcs->mode_set_base(crtc, x, y, old_fb);
  298. }
  299. /* Set up the display plane register */
  300. dspcntr = REG_READ(dspcntr_reg);
  301. dspcntr |= DISPPLANE_GAMMA_ENABLE;
  302. dspcntr |= DISPPLANE_SEL_PIPE_B;
  303. dspcntr |= DISPLAY_PLANE_ENABLE;
  304. /* setup pipeconf */
  305. pipeconf = REG_READ(pipeconf_reg);
  306. pipeconf |= PIPEACONF_ENABLE;
  307. REG_WRITE(pipeconf_reg, pipeconf);
  308. REG_READ(pipeconf_reg);
  309. REG_WRITE(PCH_PIPEBCONF, pipeconf);
  310. REG_READ(PCH_PIPEBCONF);
  311. gma_wait_for_vblank(dev);
  312. REG_WRITE(dspcntr_reg, dspcntr);
  313. gma_wait_for_vblank(dev);
  314. gma_power_end(dev);
  315. return 0;
  316. }
  317. void oaktrail_crtc_hdmi_dpms(struct drm_crtc *crtc, int mode)
  318. {
  319. struct drm_device *dev = crtc->dev;
  320. u32 temp;
  321. DRM_DEBUG_KMS("%s %d\n", __func__, mode);
  322. switch (mode) {
  323. case DRM_MODE_DPMS_OFF:
  324. REG_WRITE(VGACNTRL, 0x80000000);
  325. /* Disable plane */
  326. temp = REG_READ(DSPBCNTR);
  327. if ((temp & DISPLAY_PLANE_ENABLE) != 0) {
  328. REG_WRITE(DSPBCNTR, temp & ~DISPLAY_PLANE_ENABLE);
  329. REG_READ(DSPBCNTR);
  330. /* Flush the plane changes */
  331. REG_WRITE(DSPBSURF, REG_READ(DSPBSURF));
  332. REG_READ(DSPBSURF);
  333. }
  334. /* Disable pipe B */
  335. temp = REG_READ(PIPEBCONF);
  336. if ((temp & PIPEACONF_ENABLE) != 0) {
  337. REG_WRITE(PIPEBCONF, temp & ~PIPEACONF_ENABLE);
  338. REG_READ(PIPEBCONF);
  339. }
  340. /* Disable LNW Pipes, etc */
  341. temp = REG_READ(PCH_PIPEBCONF);
  342. if ((temp & PIPEACONF_ENABLE) != 0) {
  343. REG_WRITE(PCH_PIPEBCONF, temp & ~PIPEACONF_ENABLE);
  344. REG_READ(PCH_PIPEBCONF);
  345. }
  346. /* wait for pipe off */
  347. udelay(150);
  348. /* Disable dpll */
  349. temp = REG_READ(DPLL_CTRL);
  350. if ((temp & DPLL_PWRDN) == 0) {
  351. REG_WRITE(DPLL_CTRL, temp | (DPLL_PWRDN | DPLL_RESET));
  352. REG_WRITE(DPLL_STATUS, 0x1);
  353. }
  354. /* wait for dpll off */
  355. udelay(150);
  356. break;
  357. case DRM_MODE_DPMS_ON:
  358. case DRM_MODE_DPMS_STANDBY:
  359. case DRM_MODE_DPMS_SUSPEND:
  360. /* Enable dpll */
  361. temp = REG_READ(DPLL_CTRL);
  362. if ((temp & DPLL_PWRDN) != 0) {
  363. REG_WRITE(DPLL_CTRL, temp & ~(DPLL_PWRDN | DPLL_RESET));
  364. temp = REG_READ(DPLL_CLK_ENABLE);
  365. REG_WRITE(DPLL_CLK_ENABLE, temp | DPLL_EN_DISP | DPLL_SEL_HDMI | DPLL_EN_HDMI);
  366. REG_READ(DPLL_CLK_ENABLE);
  367. }
  368. /* wait for dpll warm up */
  369. udelay(150);
  370. /* Enable pipe B */
  371. temp = REG_READ(PIPEBCONF);
  372. if ((temp & PIPEACONF_ENABLE) == 0) {
  373. REG_WRITE(PIPEBCONF, temp | PIPEACONF_ENABLE);
  374. REG_READ(PIPEBCONF);
  375. }
  376. /* Enable LNW Pipe B */
  377. temp = REG_READ(PCH_PIPEBCONF);
  378. if ((temp & PIPEACONF_ENABLE) == 0) {
  379. REG_WRITE(PCH_PIPEBCONF, temp | PIPEACONF_ENABLE);
  380. REG_READ(PCH_PIPEBCONF);
  381. }
  382. gma_wait_for_vblank(dev);
  383. /* Enable plane */
  384. temp = REG_READ(DSPBCNTR);
  385. if ((temp & DISPLAY_PLANE_ENABLE) == 0) {
  386. REG_WRITE(DSPBCNTR, temp | DISPLAY_PLANE_ENABLE);
  387. /* Flush the plane changes */
  388. REG_WRITE(DSPBSURF, REG_READ(DSPBSURF));
  389. REG_READ(DSPBSURF);
  390. }
  391. gma_crtc_load_lut(crtc);
  392. }
  393. /* DSPARB */
  394. REG_WRITE(DSPARB, 0x00003fbf);
  395. /* FW1 */
  396. REG_WRITE(0x70034, 0x3f880a0a);
  397. /* FW2 */
  398. REG_WRITE(0x70038, 0x0b060808);
  399. /* FW4 */
  400. REG_WRITE(0x70050, 0x08030404);
  401. /* FW5 */
  402. REG_WRITE(0x70054, 0x04040404);
  403. /* LNC Chicken Bits - Squawk! */
  404. REG_WRITE(0x70400, 0x4000);
  405. return;
  406. }
  407. static void oaktrail_hdmi_dpms(struct drm_encoder *encoder, int mode)
  408. {
  409. static int dpms_mode = -1;
  410. struct drm_device *dev = encoder->dev;
  411. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  412. struct oaktrail_hdmi_dev *hdmi_dev = dev_priv->hdmi_priv;
  413. u32 temp;
  414. if (dpms_mode == mode)
  415. return;
  416. if (mode != DRM_MODE_DPMS_ON)
  417. temp = 0x0;
  418. else
  419. temp = 0x99;
  420. dpms_mode = mode;
  421. HDMI_WRITE(HDMI_VIDEO_REG, temp);
  422. }
  423. static enum drm_mode_status oaktrail_hdmi_mode_valid(struct drm_connector *connector,
  424. struct drm_display_mode *mode)
  425. {
  426. if (mode->clock > 165000)
  427. return MODE_CLOCK_HIGH;
  428. if (mode->clock < 20000)
  429. return MODE_CLOCK_LOW;
  430. if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
  431. return MODE_NO_DBLESCAN;
  432. return MODE_OK;
  433. }
  434. static enum drm_connector_status
  435. oaktrail_hdmi_detect(struct drm_connector *connector, bool force)
  436. {
  437. enum drm_connector_status status;
  438. struct drm_device *dev = connector->dev;
  439. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  440. struct oaktrail_hdmi_dev *hdmi_dev = dev_priv->hdmi_priv;
  441. u32 temp;
  442. temp = HDMI_READ(HDMI_HSR);
  443. DRM_DEBUG_KMS("HDMI_HSR %x\n", temp);
  444. if ((temp & HDMI_DETECT_HDP) != 0)
  445. status = connector_status_connected;
  446. else
  447. status = connector_status_disconnected;
  448. return status;
  449. }
  450. static const unsigned char raw_edid[] = {
  451. 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x10, 0xac, 0x2f, 0xa0,
  452. 0x53, 0x55, 0x33, 0x30, 0x16, 0x13, 0x01, 0x03, 0x0e, 0x3a, 0x24, 0x78,
  453. 0xea, 0xe9, 0xf5, 0xac, 0x51, 0x30, 0xb4, 0x25, 0x11, 0x50, 0x54, 0xa5,
  454. 0x4b, 0x00, 0x81, 0x80, 0xa9, 0x40, 0x71, 0x4f, 0xb3, 0x00, 0x01, 0x01,
  455. 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x28, 0x3c, 0x80, 0xa0, 0x70, 0xb0,
  456. 0x23, 0x40, 0x30, 0x20, 0x36, 0x00, 0x46, 0x6c, 0x21, 0x00, 0x00, 0x1a,
  457. 0x00, 0x00, 0x00, 0xff, 0x00, 0x47, 0x4e, 0x37, 0x32, 0x31, 0x39, 0x35,
  458. 0x52, 0x30, 0x33, 0x55, 0x53, 0x0a, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x44,
  459. 0x45, 0x4c, 0x4c, 0x20, 0x32, 0x37, 0x30, 0x39, 0x57, 0x0a, 0x20, 0x20,
  460. 0x00, 0x00, 0x00, 0xfd, 0x00, 0x38, 0x4c, 0x1e, 0x53, 0x11, 0x00, 0x0a,
  461. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x8d
  462. };
  463. static int oaktrail_hdmi_get_modes(struct drm_connector *connector)
  464. {
  465. struct i2c_adapter *i2c_adap;
  466. struct edid *edid;
  467. int ret = 0;
  468. /*
  469. * FIXME: We need to figure this lot out. In theory we can
  470. * read the EDID somehow but I've yet to find working reference
  471. * code.
  472. */
  473. i2c_adap = i2c_get_adapter(3);
  474. if (i2c_adap == NULL) {
  475. DRM_ERROR("No ddc adapter available!\n");
  476. edid = (struct edid *)raw_edid;
  477. } else {
  478. edid = (struct edid *)raw_edid;
  479. /* FIXME ? edid = drm_get_edid(connector, i2c_adap); */
  480. }
  481. if (edid) {
  482. drm_connector_update_edid_property(connector, edid);
  483. ret = drm_add_edid_modes(connector, edid);
  484. }
  485. return ret;
  486. }
  487. static void oaktrail_hdmi_mode_set(struct drm_encoder *encoder,
  488. struct drm_display_mode *mode,
  489. struct drm_display_mode *adjusted_mode)
  490. {
  491. struct drm_device *dev = encoder->dev;
  492. oaktrail_hdmi_audio_enable(dev);
  493. return;
  494. }
  495. static void oaktrail_hdmi_destroy(struct drm_connector *connector)
  496. {
  497. return;
  498. }
  499. static const struct drm_encoder_helper_funcs oaktrail_hdmi_helper_funcs = {
  500. .dpms = oaktrail_hdmi_dpms,
  501. .prepare = gma_encoder_prepare,
  502. .mode_set = oaktrail_hdmi_mode_set,
  503. .commit = gma_encoder_commit,
  504. };
  505. static const struct drm_connector_helper_funcs
  506. oaktrail_hdmi_connector_helper_funcs = {
  507. .get_modes = oaktrail_hdmi_get_modes,
  508. .mode_valid = oaktrail_hdmi_mode_valid,
  509. .best_encoder = gma_best_encoder,
  510. };
  511. static const struct drm_connector_funcs oaktrail_hdmi_connector_funcs = {
  512. .dpms = drm_helper_connector_dpms,
  513. .detect = oaktrail_hdmi_detect,
  514. .fill_modes = drm_helper_probe_single_connector_modes,
  515. .destroy = oaktrail_hdmi_destroy,
  516. };
  517. void oaktrail_hdmi_init(struct drm_device *dev,
  518. struct psb_intel_mode_device *mode_dev)
  519. {
  520. struct gma_encoder *gma_encoder;
  521. struct gma_connector *gma_connector;
  522. struct drm_connector *connector;
  523. struct drm_encoder *encoder;
  524. gma_encoder = kzalloc(sizeof(struct gma_encoder), GFP_KERNEL);
  525. if (!gma_encoder)
  526. return;
  527. gma_connector = kzalloc(sizeof(struct gma_connector), GFP_KERNEL);
  528. if (!gma_connector)
  529. goto failed_connector;
  530. connector = &gma_connector->base;
  531. encoder = &gma_encoder->base;
  532. drm_connector_init(dev, connector,
  533. &oaktrail_hdmi_connector_funcs,
  534. DRM_MODE_CONNECTOR_DVID);
  535. drm_simple_encoder_init(dev, encoder, DRM_MODE_ENCODER_TMDS);
  536. gma_connector_attach_encoder(gma_connector, gma_encoder);
  537. gma_encoder->type = INTEL_OUTPUT_HDMI;
  538. drm_encoder_helper_add(encoder, &oaktrail_hdmi_helper_funcs);
  539. drm_connector_helper_add(connector, &oaktrail_hdmi_connector_helper_funcs);
  540. connector->display_info.subpixel_order = SubPixelHorizontalRGB;
  541. connector->interlace_allowed = false;
  542. connector->doublescan_allowed = false;
  543. dev_info(dev->dev, "HDMI initialised.\n");
  544. return;
  545. failed_connector:
  546. kfree(gma_encoder);
  547. }
  548. void oaktrail_hdmi_setup(struct drm_device *dev)
  549. {
  550. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  551. struct pci_dev *pdev;
  552. struct oaktrail_hdmi_dev *hdmi_dev;
  553. int ret;
  554. pdev = pci_get_device(PCI_VENDOR_ID_INTEL, 0x080d, NULL);
  555. if (!pdev)
  556. return;
  557. hdmi_dev = kzalloc(sizeof(struct oaktrail_hdmi_dev), GFP_KERNEL);
  558. if (!hdmi_dev) {
  559. dev_err(dev->dev, "failed to allocate memory\n");
  560. goto out;
  561. }
  562. ret = pci_enable_device(pdev);
  563. if (ret) {
  564. dev_err(dev->dev, "failed to enable hdmi controller\n");
  565. goto free;
  566. }
  567. hdmi_dev->mmio = pci_resource_start(pdev, 0);
  568. hdmi_dev->mmio_len = pci_resource_len(pdev, 0);
  569. hdmi_dev->regs = ioremap(hdmi_dev->mmio, hdmi_dev->mmio_len);
  570. if (!hdmi_dev->regs) {
  571. dev_err(dev->dev, "failed to map hdmi mmio\n");
  572. goto free;
  573. }
  574. hdmi_dev->dev = pdev;
  575. pci_set_drvdata(pdev, hdmi_dev);
  576. /* Initialize i2c controller */
  577. ret = oaktrail_hdmi_i2c_init(hdmi_dev->dev);
  578. if (ret)
  579. dev_err(dev->dev, "HDMI I2C initialization failed\n");
  580. dev_priv->hdmi_priv = hdmi_dev;
  581. oaktrail_hdmi_audio_disable(dev);
  582. dev_info(dev->dev, "HDMI hardware present.\n");
  583. return;
  584. free:
  585. kfree(hdmi_dev);
  586. out:
  587. return;
  588. }
  589. void oaktrail_hdmi_teardown(struct drm_device *dev)
  590. {
  591. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  592. struct oaktrail_hdmi_dev *hdmi_dev = dev_priv->hdmi_priv;
  593. struct pci_dev *pdev;
  594. if (hdmi_dev) {
  595. pdev = hdmi_dev->dev;
  596. pci_set_drvdata(pdev, NULL);
  597. oaktrail_hdmi_i2c_exit(pdev);
  598. iounmap(hdmi_dev->regs);
  599. kfree(hdmi_dev);
  600. pci_dev_put(pdev);
  601. }
  602. }
  603. /* save HDMI register state */
  604. void oaktrail_hdmi_save(struct drm_device *dev)
  605. {
  606. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  607. struct oaktrail_hdmi_dev *hdmi_dev = dev_priv->hdmi_priv;
  608. struct psb_state *regs = &dev_priv->regs.psb;
  609. struct psb_pipe *pipeb = &dev_priv->regs.pipe[1];
  610. int i;
  611. /* dpll */
  612. hdmi_dev->saveDPLL_CTRL = PSB_RVDC32(DPLL_CTRL);
  613. hdmi_dev->saveDPLL_DIV_CTRL = PSB_RVDC32(DPLL_DIV_CTRL);
  614. hdmi_dev->saveDPLL_ADJUST = PSB_RVDC32(DPLL_ADJUST);
  615. hdmi_dev->saveDPLL_UPDATE = PSB_RVDC32(DPLL_UPDATE);
  616. hdmi_dev->saveDPLL_CLK_ENABLE = PSB_RVDC32(DPLL_CLK_ENABLE);
  617. /* pipe B */
  618. pipeb->conf = PSB_RVDC32(PIPEBCONF);
  619. pipeb->src = PSB_RVDC32(PIPEBSRC);
  620. pipeb->htotal = PSB_RVDC32(HTOTAL_B);
  621. pipeb->hblank = PSB_RVDC32(HBLANK_B);
  622. pipeb->hsync = PSB_RVDC32(HSYNC_B);
  623. pipeb->vtotal = PSB_RVDC32(VTOTAL_B);
  624. pipeb->vblank = PSB_RVDC32(VBLANK_B);
  625. pipeb->vsync = PSB_RVDC32(VSYNC_B);
  626. hdmi_dev->savePCH_PIPEBCONF = PSB_RVDC32(PCH_PIPEBCONF);
  627. hdmi_dev->savePCH_PIPEBSRC = PSB_RVDC32(PCH_PIPEBSRC);
  628. hdmi_dev->savePCH_HTOTAL_B = PSB_RVDC32(PCH_HTOTAL_B);
  629. hdmi_dev->savePCH_HBLANK_B = PSB_RVDC32(PCH_HBLANK_B);
  630. hdmi_dev->savePCH_HSYNC_B = PSB_RVDC32(PCH_HSYNC_B);
  631. hdmi_dev->savePCH_VTOTAL_B = PSB_RVDC32(PCH_VTOTAL_B);
  632. hdmi_dev->savePCH_VBLANK_B = PSB_RVDC32(PCH_VBLANK_B);
  633. hdmi_dev->savePCH_VSYNC_B = PSB_RVDC32(PCH_VSYNC_B);
  634. /* plane */
  635. pipeb->cntr = PSB_RVDC32(DSPBCNTR);
  636. pipeb->stride = PSB_RVDC32(DSPBSTRIDE);
  637. pipeb->addr = PSB_RVDC32(DSPBBASE);
  638. pipeb->surf = PSB_RVDC32(DSPBSURF);
  639. pipeb->linoff = PSB_RVDC32(DSPBLINOFF);
  640. pipeb->tileoff = PSB_RVDC32(DSPBTILEOFF);
  641. /* cursor B */
  642. regs->saveDSPBCURSOR_CTRL = PSB_RVDC32(CURBCNTR);
  643. regs->saveDSPBCURSOR_BASE = PSB_RVDC32(CURBBASE);
  644. regs->saveDSPBCURSOR_POS = PSB_RVDC32(CURBPOS);
  645. /* save palette */
  646. for (i = 0; i < 256; i++)
  647. pipeb->palette[i] = PSB_RVDC32(PALETTE_B + (i << 2));
  648. }
  649. /* restore HDMI register state */
  650. void oaktrail_hdmi_restore(struct drm_device *dev)
  651. {
  652. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  653. struct oaktrail_hdmi_dev *hdmi_dev = dev_priv->hdmi_priv;
  654. struct psb_state *regs = &dev_priv->regs.psb;
  655. struct psb_pipe *pipeb = &dev_priv->regs.pipe[1];
  656. int i;
  657. /* dpll */
  658. PSB_WVDC32(hdmi_dev->saveDPLL_CTRL, DPLL_CTRL);
  659. PSB_WVDC32(hdmi_dev->saveDPLL_DIV_CTRL, DPLL_DIV_CTRL);
  660. PSB_WVDC32(hdmi_dev->saveDPLL_ADJUST, DPLL_ADJUST);
  661. PSB_WVDC32(hdmi_dev->saveDPLL_UPDATE, DPLL_UPDATE);
  662. PSB_WVDC32(hdmi_dev->saveDPLL_CLK_ENABLE, DPLL_CLK_ENABLE);
  663. udelay(150);
  664. /* pipe */
  665. PSB_WVDC32(pipeb->src, PIPEBSRC);
  666. PSB_WVDC32(pipeb->htotal, HTOTAL_B);
  667. PSB_WVDC32(pipeb->hblank, HBLANK_B);
  668. PSB_WVDC32(pipeb->hsync, HSYNC_B);
  669. PSB_WVDC32(pipeb->vtotal, VTOTAL_B);
  670. PSB_WVDC32(pipeb->vblank, VBLANK_B);
  671. PSB_WVDC32(pipeb->vsync, VSYNC_B);
  672. PSB_WVDC32(hdmi_dev->savePCH_PIPEBSRC, PCH_PIPEBSRC);
  673. PSB_WVDC32(hdmi_dev->savePCH_HTOTAL_B, PCH_HTOTAL_B);
  674. PSB_WVDC32(hdmi_dev->savePCH_HBLANK_B, PCH_HBLANK_B);
  675. PSB_WVDC32(hdmi_dev->savePCH_HSYNC_B, PCH_HSYNC_B);
  676. PSB_WVDC32(hdmi_dev->savePCH_VTOTAL_B, PCH_VTOTAL_B);
  677. PSB_WVDC32(hdmi_dev->savePCH_VBLANK_B, PCH_VBLANK_B);
  678. PSB_WVDC32(hdmi_dev->savePCH_VSYNC_B, PCH_VSYNC_B);
  679. PSB_WVDC32(pipeb->conf, PIPEBCONF);
  680. PSB_WVDC32(hdmi_dev->savePCH_PIPEBCONF, PCH_PIPEBCONF);
  681. /* plane */
  682. PSB_WVDC32(pipeb->linoff, DSPBLINOFF);
  683. PSB_WVDC32(pipeb->stride, DSPBSTRIDE);
  684. PSB_WVDC32(pipeb->tileoff, DSPBTILEOFF);
  685. PSB_WVDC32(pipeb->cntr, DSPBCNTR);
  686. PSB_WVDC32(pipeb->surf, DSPBSURF);
  687. /* cursor B */
  688. PSB_WVDC32(regs->saveDSPBCURSOR_CTRL, CURBCNTR);
  689. PSB_WVDC32(regs->saveDSPBCURSOR_POS, CURBPOS);
  690. PSB_WVDC32(regs->saveDSPBCURSOR_BASE, CURBBASE);
  691. /* restore palette */
  692. for (i = 0; i < 256; i++)
  693. PSB_WVDC32(pipeb->palette[i], PALETTE_B + (i << 2));
  694. }