18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright © 2010 Intel Corporation 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 58c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 68c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation 78c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 88c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 98c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the next 128c2ecf20Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 138c2ecf20Sopenharmony_ci * Software. 148c2ecf20Sopenharmony_ci * 158c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 168c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 178c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 188c2ecf20Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 198c2ecf20Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 208c2ecf20Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 218c2ecf20Sopenharmony_ci * DEALINGS IN THE SOFTWARE. 228c2ecf20Sopenharmony_ci * 238c2ecf20Sopenharmony_ci * Authors: 248c2ecf20Sopenharmony_ci * Li Peng <peng.li@intel.com> 258c2ecf20Sopenharmony_ci */ 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#include <linux/delay.h> 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci#include <drm/drm.h> 308c2ecf20Sopenharmony_ci#include <drm/drm_simple_kms_helper.h> 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci#include "psb_drv.h" 338c2ecf20Sopenharmony_ci#include "psb_intel_drv.h" 348c2ecf20Sopenharmony_ci#include "psb_intel_reg.h" 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#define HDMI_READ(reg) readl(hdmi_dev->regs + (reg)) 378c2ecf20Sopenharmony_ci#define HDMI_WRITE(reg, val) writel(val, hdmi_dev->regs + (reg)) 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci#define HDMI_HCR 0x1000 408c2ecf20Sopenharmony_ci#define HCR_ENABLE_HDCP (1 << 5) 418c2ecf20Sopenharmony_ci#define HCR_ENABLE_AUDIO (1 << 2) 428c2ecf20Sopenharmony_ci#define HCR_ENABLE_PIXEL (1 << 1) 438c2ecf20Sopenharmony_ci#define HCR_ENABLE_TMDS (1 << 0) 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci#define HDMI_HICR 0x1004 468c2ecf20Sopenharmony_ci#define HDMI_HSR 0x1008 478c2ecf20Sopenharmony_ci#define HDMI_HISR 0x100C 488c2ecf20Sopenharmony_ci#define HDMI_DETECT_HDP (1 << 0) 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci#define HDMI_VIDEO_REG 0x3000 518c2ecf20Sopenharmony_ci#define HDMI_UNIT_EN (1 << 7) 528c2ecf20Sopenharmony_ci#define HDMI_MODE_OUTPUT (1 << 0) 538c2ecf20Sopenharmony_ci#define HDMI_HBLANK_A 0x3100 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci#define HDMI_AUDIO_CTRL 0x4000 568c2ecf20Sopenharmony_ci#define HDMI_ENABLE_AUDIO (1 << 0) 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci#define PCH_HTOTAL_B 0x3100 598c2ecf20Sopenharmony_ci#define PCH_HBLANK_B 0x3104 608c2ecf20Sopenharmony_ci#define PCH_HSYNC_B 0x3108 618c2ecf20Sopenharmony_ci#define PCH_VTOTAL_B 0x310C 628c2ecf20Sopenharmony_ci#define PCH_VBLANK_B 0x3110 638c2ecf20Sopenharmony_ci#define PCH_VSYNC_B 0x3114 648c2ecf20Sopenharmony_ci#define PCH_PIPEBSRC 0x311C 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci#define PCH_PIPEB_DSL 0x3800 678c2ecf20Sopenharmony_ci#define PCH_PIPEB_SLC 0x3804 688c2ecf20Sopenharmony_ci#define PCH_PIPEBCONF 0x3808 698c2ecf20Sopenharmony_ci#define PCH_PIPEBSTAT 0x3824 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci#define CDVO_DFT 0x5000 728c2ecf20Sopenharmony_ci#define CDVO_SLEWRATE 0x5004 738c2ecf20Sopenharmony_ci#define CDVO_STRENGTH 0x5008 748c2ecf20Sopenharmony_ci#define CDVO_RCOMP 0x500C 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci#define DPLL_CTRL 0x6000 778c2ecf20Sopenharmony_ci#define DPLL_PDIV_SHIFT 16 788c2ecf20Sopenharmony_ci#define DPLL_PDIV_MASK (0xf << 16) 798c2ecf20Sopenharmony_ci#define DPLL_PWRDN (1 << 4) 808c2ecf20Sopenharmony_ci#define DPLL_RESET (1 << 3) 818c2ecf20Sopenharmony_ci#define DPLL_FASTEN (1 << 2) 828c2ecf20Sopenharmony_ci#define DPLL_ENSTAT (1 << 1) 838c2ecf20Sopenharmony_ci#define DPLL_DITHEN (1 << 0) 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci#define DPLL_DIV_CTRL 0x6004 868c2ecf20Sopenharmony_ci#define DPLL_CLKF_MASK 0xffffffc0 878c2ecf20Sopenharmony_ci#define DPLL_CLKR_MASK (0x3f) 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci#define DPLL_CLK_ENABLE 0x6008 908c2ecf20Sopenharmony_ci#define DPLL_EN_DISP (1 << 31) 918c2ecf20Sopenharmony_ci#define DPLL_SEL_HDMI (1 << 8) 928c2ecf20Sopenharmony_ci#define DPLL_EN_HDMI (1 << 1) 938c2ecf20Sopenharmony_ci#define DPLL_EN_VGA (1 << 0) 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci#define DPLL_ADJUST 0x600C 968c2ecf20Sopenharmony_ci#define DPLL_STATUS 0x6010 978c2ecf20Sopenharmony_ci#define DPLL_UPDATE 0x6014 988c2ecf20Sopenharmony_ci#define DPLL_DFT 0x6020 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_cistruct intel_range { 1018c2ecf20Sopenharmony_ci int min, max; 1028c2ecf20Sopenharmony_ci}; 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_cistruct oaktrail_hdmi_limit { 1058c2ecf20Sopenharmony_ci struct intel_range vco, np, nr, nf; 1068c2ecf20Sopenharmony_ci}; 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_cistruct oaktrail_hdmi_clock { 1098c2ecf20Sopenharmony_ci int np; 1108c2ecf20Sopenharmony_ci int nr; 1118c2ecf20Sopenharmony_ci int nf; 1128c2ecf20Sopenharmony_ci int dot; 1138c2ecf20Sopenharmony_ci}; 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci#define VCO_MIN 320000 1168c2ecf20Sopenharmony_ci#define VCO_MAX 1650000 1178c2ecf20Sopenharmony_ci#define NP_MIN 1 1188c2ecf20Sopenharmony_ci#define NP_MAX 15 1198c2ecf20Sopenharmony_ci#define NR_MIN 1 1208c2ecf20Sopenharmony_ci#define NR_MAX 64 1218c2ecf20Sopenharmony_ci#define NF_MIN 2 1228c2ecf20Sopenharmony_ci#define NF_MAX 4095 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_cistatic const struct oaktrail_hdmi_limit oaktrail_hdmi_limit = { 1258c2ecf20Sopenharmony_ci .vco = { .min = VCO_MIN, .max = VCO_MAX }, 1268c2ecf20Sopenharmony_ci .np = { .min = NP_MIN, .max = NP_MAX }, 1278c2ecf20Sopenharmony_ci .nr = { .min = NR_MIN, .max = NR_MAX }, 1288c2ecf20Sopenharmony_ci .nf = { .min = NF_MIN, .max = NF_MAX }, 1298c2ecf20Sopenharmony_ci}; 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_cistatic void oaktrail_hdmi_audio_enable(struct drm_device *dev) 1328c2ecf20Sopenharmony_ci{ 1338c2ecf20Sopenharmony_ci struct drm_psb_private *dev_priv = dev->dev_private; 1348c2ecf20Sopenharmony_ci struct oaktrail_hdmi_dev *hdmi_dev = dev_priv->hdmi_priv; 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci HDMI_WRITE(HDMI_HCR, 0x67); 1378c2ecf20Sopenharmony_ci HDMI_READ(HDMI_HCR); 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci HDMI_WRITE(0x51a8, 0x10); 1408c2ecf20Sopenharmony_ci HDMI_READ(0x51a8); 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci HDMI_WRITE(HDMI_AUDIO_CTRL, 0x1); 1438c2ecf20Sopenharmony_ci HDMI_READ(HDMI_AUDIO_CTRL); 1448c2ecf20Sopenharmony_ci} 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_cistatic void oaktrail_hdmi_audio_disable(struct drm_device *dev) 1478c2ecf20Sopenharmony_ci{ 1488c2ecf20Sopenharmony_ci struct drm_psb_private *dev_priv = dev->dev_private; 1498c2ecf20Sopenharmony_ci struct oaktrail_hdmi_dev *hdmi_dev = dev_priv->hdmi_priv; 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci HDMI_WRITE(0x51a8, 0x0); 1528c2ecf20Sopenharmony_ci HDMI_READ(0x51a8); 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ci HDMI_WRITE(HDMI_AUDIO_CTRL, 0x0); 1558c2ecf20Sopenharmony_ci HDMI_READ(HDMI_AUDIO_CTRL); 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci HDMI_WRITE(HDMI_HCR, 0x47); 1588c2ecf20Sopenharmony_ci HDMI_READ(HDMI_HCR); 1598c2ecf20Sopenharmony_ci} 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_cistatic unsigned int htotal_calculate(struct drm_display_mode *mode) 1628c2ecf20Sopenharmony_ci{ 1638c2ecf20Sopenharmony_ci u32 new_crtc_htotal; 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_ci /* 1668c2ecf20Sopenharmony_ci * 1024 x 768 new_crtc_htotal = 0x1024; 1678c2ecf20Sopenharmony_ci * 1280 x 1024 new_crtc_htotal = 0x0c34; 1688c2ecf20Sopenharmony_ci */ 1698c2ecf20Sopenharmony_ci new_crtc_htotal = (mode->crtc_htotal - 1) * 200 * 1000 / mode->clock; 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci DRM_DEBUG_KMS("new crtc htotal 0x%4x\n", new_crtc_htotal); 1728c2ecf20Sopenharmony_ci return (mode->crtc_hdisplay - 1) | (new_crtc_htotal << 16); 1738c2ecf20Sopenharmony_ci} 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_cistatic void oaktrail_hdmi_find_dpll(struct drm_crtc *crtc, int target, 1768c2ecf20Sopenharmony_ci int refclk, struct oaktrail_hdmi_clock *best_clock) 1778c2ecf20Sopenharmony_ci{ 1788c2ecf20Sopenharmony_ci int np_min, np_max, nr_min, nr_max; 1798c2ecf20Sopenharmony_ci int np, nr, nf; 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_ci np_min = DIV_ROUND_UP(oaktrail_hdmi_limit.vco.min, target * 10); 1828c2ecf20Sopenharmony_ci np_max = oaktrail_hdmi_limit.vco.max / (target * 10); 1838c2ecf20Sopenharmony_ci if (np_min < oaktrail_hdmi_limit.np.min) 1848c2ecf20Sopenharmony_ci np_min = oaktrail_hdmi_limit.np.min; 1858c2ecf20Sopenharmony_ci if (np_max > oaktrail_hdmi_limit.np.max) 1868c2ecf20Sopenharmony_ci np_max = oaktrail_hdmi_limit.np.max; 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ci nr_min = DIV_ROUND_UP((refclk * 1000), (target * 10 * np_max)); 1898c2ecf20Sopenharmony_ci nr_max = DIV_ROUND_UP((refclk * 1000), (target * 10 * np_min)); 1908c2ecf20Sopenharmony_ci if (nr_min < oaktrail_hdmi_limit.nr.min) 1918c2ecf20Sopenharmony_ci nr_min = oaktrail_hdmi_limit.nr.min; 1928c2ecf20Sopenharmony_ci if (nr_max > oaktrail_hdmi_limit.nr.max) 1938c2ecf20Sopenharmony_ci nr_max = oaktrail_hdmi_limit.nr.max; 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_ci np = DIV_ROUND_UP((refclk * 1000), (target * 10 * nr_max)); 1968c2ecf20Sopenharmony_ci nr = DIV_ROUND_UP((refclk * 1000), (target * 10 * np)); 1978c2ecf20Sopenharmony_ci nf = DIV_ROUND_CLOSEST((target * 10 * np * nr), refclk); 1988c2ecf20Sopenharmony_ci DRM_DEBUG_KMS("np, nr, nf %d %d %d\n", np, nr, nf); 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci /* 2018c2ecf20Sopenharmony_ci * 1024 x 768 np = 1; nr = 0x26; nf = 0x0fd8000; 2028c2ecf20Sopenharmony_ci * 1280 x 1024 np = 1; nr = 0x17; nf = 0x1034000; 2038c2ecf20Sopenharmony_ci */ 2048c2ecf20Sopenharmony_ci best_clock->np = np; 2058c2ecf20Sopenharmony_ci best_clock->nr = nr - 1; 2068c2ecf20Sopenharmony_ci best_clock->nf = (nf << 14); 2078c2ecf20Sopenharmony_ci} 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_cistatic void scu_busy_loop(void __iomem *scu_base) 2108c2ecf20Sopenharmony_ci{ 2118c2ecf20Sopenharmony_ci u32 status = 0; 2128c2ecf20Sopenharmony_ci u32 loop_count = 0; 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ci status = readl(scu_base + 0x04); 2158c2ecf20Sopenharmony_ci while (status & 1) { 2168c2ecf20Sopenharmony_ci udelay(1); /* scu processing time is in few u secods */ 2178c2ecf20Sopenharmony_ci status = readl(scu_base + 0x04); 2188c2ecf20Sopenharmony_ci loop_count++; 2198c2ecf20Sopenharmony_ci /* break if scu doesn't reset busy bit after huge retry */ 2208c2ecf20Sopenharmony_ci if (loop_count > 1000) { 2218c2ecf20Sopenharmony_ci DRM_DEBUG_KMS("SCU IPC timed out"); 2228c2ecf20Sopenharmony_ci return; 2238c2ecf20Sopenharmony_ci } 2248c2ecf20Sopenharmony_ci } 2258c2ecf20Sopenharmony_ci} 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ci/* 2288c2ecf20Sopenharmony_ci * You don't want to know, you really really don't want to know.... 2298c2ecf20Sopenharmony_ci * 2308c2ecf20Sopenharmony_ci * This is magic. However it's safe magic because of the way the platform 2318c2ecf20Sopenharmony_ci * works and it is necessary magic. 2328c2ecf20Sopenharmony_ci */ 2338c2ecf20Sopenharmony_cistatic void oaktrail_hdmi_reset(struct drm_device *dev) 2348c2ecf20Sopenharmony_ci{ 2358c2ecf20Sopenharmony_ci void __iomem *base; 2368c2ecf20Sopenharmony_ci unsigned long scu_ipc_mmio = 0xff11c000UL; 2378c2ecf20Sopenharmony_ci int scu_len = 1024; 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_ci base = ioremap((resource_size_t)scu_ipc_mmio, scu_len); 2408c2ecf20Sopenharmony_ci if (base == NULL) { 2418c2ecf20Sopenharmony_ci DRM_ERROR("failed to map scu mmio\n"); 2428c2ecf20Sopenharmony_ci return; 2438c2ecf20Sopenharmony_ci } 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_ci /* scu ipc: assert hdmi controller reset */ 2468c2ecf20Sopenharmony_ci writel(0xff11d118, base + 0x0c); 2478c2ecf20Sopenharmony_ci writel(0x7fffffdf, base + 0x80); 2488c2ecf20Sopenharmony_ci writel(0x42005, base + 0x0); 2498c2ecf20Sopenharmony_ci scu_busy_loop(base); 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci /* scu ipc: de-assert hdmi controller reset */ 2528c2ecf20Sopenharmony_ci writel(0xff11d118, base + 0x0c); 2538c2ecf20Sopenharmony_ci writel(0x7fffffff, base + 0x80); 2548c2ecf20Sopenharmony_ci writel(0x42005, base + 0x0); 2558c2ecf20Sopenharmony_ci scu_busy_loop(base); 2568c2ecf20Sopenharmony_ci 2578c2ecf20Sopenharmony_ci iounmap(base); 2588c2ecf20Sopenharmony_ci} 2598c2ecf20Sopenharmony_ci 2608c2ecf20Sopenharmony_ciint oaktrail_crtc_hdmi_mode_set(struct drm_crtc *crtc, 2618c2ecf20Sopenharmony_ci struct drm_display_mode *mode, 2628c2ecf20Sopenharmony_ci struct drm_display_mode *adjusted_mode, 2638c2ecf20Sopenharmony_ci int x, int y, 2648c2ecf20Sopenharmony_ci struct drm_framebuffer *old_fb) 2658c2ecf20Sopenharmony_ci{ 2668c2ecf20Sopenharmony_ci struct drm_device *dev = crtc->dev; 2678c2ecf20Sopenharmony_ci struct drm_psb_private *dev_priv = dev->dev_private; 2688c2ecf20Sopenharmony_ci struct oaktrail_hdmi_dev *hdmi_dev = dev_priv->hdmi_priv; 2698c2ecf20Sopenharmony_ci int pipe = 1; 2708c2ecf20Sopenharmony_ci int htot_reg = (pipe == 0) ? HTOTAL_A : HTOTAL_B; 2718c2ecf20Sopenharmony_ci int hblank_reg = (pipe == 0) ? HBLANK_A : HBLANK_B; 2728c2ecf20Sopenharmony_ci int hsync_reg = (pipe == 0) ? HSYNC_A : HSYNC_B; 2738c2ecf20Sopenharmony_ci int vtot_reg = (pipe == 0) ? VTOTAL_A : VTOTAL_B; 2748c2ecf20Sopenharmony_ci int vblank_reg = (pipe == 0) ? VBLANK_A : VBLANK_B; 2758c2ecf20Sopenharmony_ci int vsync_reg = (pipe == 0) ? VSYNC_A : VSYNC_B; 2768c2ecf20Sopenharmony_ci int dspsize_reg = (pipe == 0) ? DSPASIZE : DSPBSIZE; 2778c2ecf20Sopenharmony_ci int dsppos_reg = (pipe == 0) ? DSPAPOS : DSPBPOS; 2788c2ecf20Sopenharmony_ci int pipesrc_reg = (pipe == 0) ? PIPEASRC : PIPEBSRC; 2798c2ecf20Sopenharmony_ci int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF; 2808c2ecf20Sopenharmony_ci int refclk; 2818c2ecf20Sopenharmony_ci struct oaktrail_hdmi_clock clock; 2828c2ecf20Sopenharmony_ci u32 dspcntr, pipeconf, dpll, temp; 2838c2ecf20Sopenharmony_ci int dspcntr_reg = DSPBCNTR; 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_ci if (!gma_power_begin(dev, true)) 2868c2ecf20Sopenharmony_ci return 0; 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_ci /* Disable the VGA plane that we never use */ 2898c2ecf20Sopenharmony_ci REG_WRITE(VGACNTRL, VGA_DISP_DISABLE); 2908c2ecf20Sopenharmony_ci 2918c2ecf20Sopenharmony_ci /* Disable dpll if necessary */ 2928c2ecf20Sopenharmony_ci dpll = REG_READ(DPLL_CTRL); 2938c2ecf20Sopenharmony_ci if ((dpll & DPLL_PWRDN) == 0) { 2948c2ecf20Sopenharmony_ci REG_WRITE(DPLL_CTRL, dpll | (DPLL_PWRDN | DPLL_RESET)); 2958c2ecf20Sopenharmony_ci REG_WRITE(DPLL_DIV_CTRL, 0x00000000); 2968c2ecf20Sopenharmony_ci REG_WRITE(DPLL_STATUS, 0x1); 2978c2ecf20Sopenharmony_ci } 2988c2ecf20Sopenharmony_ci udelay(150); 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_ci /* Reset controller */ 3018c2ecf20Sopenharmony_ci oaktrail_hdmi_reset(dev); 3028c2ecf20Sopenharmony_ci 3038c2ecf20Sopenharmony_ci /* program and enable dpll */ 3048c2ecf20Sopenharmony_ci refclk = 25000; 3058c2ecf20Sopenharmony_ci oaktrail_hdmi_find_dpll(crtc, adjusted_mode->clock, refclk, &clock); 3068c2ecf20Sopenharmony_ci 3078c2ecf20Sopenharmony_ci /* Set the DPLL */ 3088c2ecf20Sopenharmony_ci dpll = REG_READ(DPLL_CTRL); 3098c2ecf20Sopenharmony_ci dpll &= ~DPLL_PDIV_MASK; 3108c2ecf20Sopenharmony_ci dpll &= ~(DPLL_PWRDN | DPLL_RESET); 3118c2ecf20Sopenharmony_ci REG_WRITE(DPLL_CTRL, 0x00000008); 3128c2ecf20Sopenharmony_ci REG_WRITE(DPLL_DIV_CTRL, ((clock.nf << 6) | clock.nr)); 3138c2ecf20Sopenharmony_ci REG_WRITE(DPLL_ADJUST, ((clock.nf >> 14) - 1)); 3148c2ecf20Sopenharmony_ci REG_WRITE(DPLL_CTRL, (dpll | (clock.np << DPLL_PDIV_SHIFT) | DPLL_ENSTAT | DPLL_DITHEN)); 3158c2ecf20Sopenharmony_ci REG_WRITE(DPLL_UPDATE, 0x80000000); 3168c2ecf20Sopenharmony_ci REG_WRITE(DPLL_CLK_ENABLE, 0x80050102); 3178c2ecf20Sopenharmony_ci udelay(150); 3188c2ecf20Sopenharmony_ci 3198c2ecf20Sopenharmony_ci /* configure HDMI */ 3208c2ecf20Sopenharmony_ci HDMI_WRITE(0x1004, 0x1fd); 3218c2ecf20Sopenharmony_ci HDMI_WRITE(0x2000, 0x1); 3228c2ecf20Sopenharmony_ci HDMI_WRITE(0x2008, 0x0); 3238c2ecf20Sopenharmony_ci HDMI_WRITE(0x3130, 0x8); 3248c2ecf20Sopenharmony_ci HDMI_WRITE(0x101c, 0x1800810); 3258c2ecf20Sopenharmony_ci 3268c2ecf20Sopenharmony_ci temp = htotal_calculate(adjusted_mode); 3278c2ecf20Sopenharmony_ci REG_WRITE(htot_reg, temp); 3288c2ecf20Sopenharmony_ci REG_WRITE(hblank_reg, (adjusted_mode->crtc_hblank_start - 1) | ((adjusted_mode->crtc_hblank_end - 1) << 16)); 3298c2ecf20Sopenharmony_ci REG_WRITE(hsync_reg, (adjusted_mode->crtc_hsync_start - 1) | ((adjusted_mode->crtc_hsync_end - 1) << 16)); 3308c2ecf20Sopenharmony_ci REG_WRITE(vtot_reg, (adjusted_mode->crtc_vdisplay - 1) | ((adjusted_mode->crtc_vtotal - 1) << 16)); 3318c2ecf20Sopenharmony_ci REG_WRITE(vblank_reg, (adjusted_mode->crtc_vblank_start - 1) | ((adjusted_mode->crtc_vblank_end - 1) << 16)); 3328c2ecf20Sopenharmony_ci REG_WRITE(vsync_reg, (adjusted_mode->crtc_vsync_start - 1) | ((adjusted_mode->crtc_vsync_end - 1) << 16)); 3338c2ecf20Sopenharmony_ci REG_WRITE(pipesrc_reg, ((mode->crtc_hdisplay - 1) << 16) | (mode->crtc_vdisplay - 1)); 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_ci REG_WRITE(PCH_HTOTAL_B, (adjusted_mode->crtc_hdisplay - 1) | ((adjusted_mode->crtc_htotal - 1) << 16)); 3368c2ecf20Sopenharmony_ci REG_WRITE(PCH_HBLANK_B, (adjusted_mode->crtc_hblank_start - 1) | ((adjusted_mode->crtc_hblank_end - 1) << 16)); 3378c2ecf20Sopenharmony_ci REG_WRITE(PCH_HSYNC_B, (adjusted_mode->crtc_hsync_start - 1) | ((adjusted_mode->crtc_hsync_end - 1) << 16)); 3388c2ecf20Sopenharmony_ci REG_WRITE(PCH_VTOTAL_B, (adjusted_mode->crtc_vdisplay - 1) | ((adjusted_mode->crtc_vtotal - 1) << 16)); 3398c2ecf20Sopenharmony_ci REG_WRITE(PCH_VBLANK_B, (adjusted_mode->crtc_vblank_start - 1) | ((adjusted_mode->crtc_vblank_end - 1) << 16)); 3408c2ecf20Sopenharmony_ci REG_WRITE(PCH_VSYNC_B, (adjusted_mode->crtc_vsync_start - 1) | ((adjusted_mode->crtc_vsync_end - 1) << 16)); 3418c2ecf20Sopenharmony_ci REG_WRITE(PCH_PIPEBSRC, ((mode->crtc_hdisplay - 1) << 16) | (mode->crtc_vdisplay - 1)); 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_ci temp = adjusted_mode->crtc_hblank_end - adjusted_mode->crtc_hblank_start; 3448c2ecf20Sopenharmony_ci HDMI_WRITE(HDMI_HBLANK_A, ((adjusted_mode->crtc_hdisplay - 1) << 16) | temp); 3458c2ecf20Sopenharmony_ci 3468c2ecf20Sopenharmony_ci REG_WRITE(dspsize_reg, ((mode->vdisplay - 1) << 16) | (mode->hdisplay - 1)); 3478c2ecf20Sopenharmony_ci REG_WRITE(dsppos_reg, 0); 3488c2ecf20Sopenharmony_ci 3498c2ecf20Sopenharmony_ci /* Flush the plane changes */ 3508c2ecf20Sopenharmony_ci { 3518c2ecf20Sopenharmony_ci const struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; 3528c2ecf20Sopenharmony_ci crtc_funcs->mode_set_base(crtc, x, y, old_fb); 3538c2ecf20Sopenharmony_ci } 3548c2ecf20Sopenharmony_ci 3558c2ecf20Sopenharmony_ci /* Set up the display plane register */ 3568c2ecf20Sopenharmony_ci dspcntr = REG_READ(dspcntr_reg); 3578c2ecf20Sopenharmony_ci dspcntr |= DISPPLANE_GAMMA_ENABLE; 3588c2ecf20Sopenharmony_ci dspcntr |= DISPPLANE_SEL_PIPE_B; 3598c2ecf20Sopenharmony_ci dspcntr |= DISPLAY_PLANE_ENABLE; 3608c2ecf20Sopenharmony_ci 3618c2ecf20Sopenharmony_ci /* setup pipeconf */ 3628c2ecf20Sopenharmony_ci pipeconf = REG_READ(pipeconf_reg); 3638c2ecf20Sopenharmony_ci pipeconf |= PIPEACONF_ENABLE; 3648c2ecf20Sopenharmony_ci 3658c2ecf20Sopenharmony_ci REG_WRITE(pipeconf_reg, pipeconf); 3668c2ecf20Sopenharmony_ci REG_READ(pipeconf_reg); 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_ci REG_WRITE(PCH_PIPEBCONF, pipeconf); 3698c2ecf20Sopenharmony_ci REG_READ(PCH_PIPEBCONF); 3708c2ecf20Sopenharmony_ci gma_wait_for_vblank(dev); 3718c2ecf20Sopenharmony_ci 3728c2ecf20Sopenharmony_ci REG_WRITE(dspcntr_reg, dspcntr); 3738c2ecf20Sopenharmony_ci gma_wait_for_vblank(dev); 3748c2ecf20Sopenharmony_ci 3758c2ecf20Sopenharmony_ci gma_power_end(dev); 3768c2ecf20Sopenharmony_ci 3778c2ecf20Sopenharmony_ci return 0; 3788c2ecf20Sopenharmony_ci} 3798c2ecf20Sopenharmony_ci 3808c2ecf20Sopenharmony_civoid oaktrail_crtc_hdmi_dpms(struct drm_crtc *crtc, int mode) 3818c2ecf20Sopenharmony_ci{ 3828c2ecf20Sopenharmony_ci struct drm_device *dev = crtc->dev; 3838c2ecf20Sopenharmony_ci u32 temp; 3848c2ecf20Sopenharmony_ci 3858c2ecf20Sopenharmony_ci DRM_DEBUG_KMS("%s %d\n", __func__, mode); 3868c2ecf20Sopenharmony_ci 3878c2ecf20Sopenharmony_ci switch (mode) { 3888c2ecf20Sopenharmony_ci case DRM_MODE_DPMS_OFF: 3898c2ecf20Sopenharmony_ci REG_WRITE(VGACNTRL, 0x80000000); 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_ci /* Disable plane */ 3928c2ecf20Sopenharmony_ci temp = REG_READ(DSPBCNTR); 3938c2ecf20Sopenharmony_ci if ((temp & DISPLAY_PLANE_ENABLE) != 0) { 3948c2ecf20Sopenharmony_ci REG_WRITE(DSPBCNTR, temp & ~DISPLAY_PLANE_ENABLE); 3958c2ecf20Sopenharmony_ci REG_READ(DSPBCNTR); 3968c2ecf20Sopenharmony_ci /* Flush the plane changes */ 3978c2ecf20Sopenharmony_ci REG_WRITE(DSPBSURF, REG_READ(DSPBSURF)); 3988c2ecf20Sopenharmony_ci REG_READ(DSPBSURF); 3998c2ecf20Sopenharmony_ci } 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_ci /* Disable pipe B */ 4028c2ecf20Sopenharmony_ci temp = REG_READ(PIPEBCONF); 4038c2ecf20Sopenharmony_ci if ((temp & PIPEACONF_ENABLE) != 0) { 4048c2ecf20Sopenharmony_ci REG_WRITE(PIPEBCONF, temp & ~PIPEACONF_ENABLE); 4058c2ecf20Sopenharmony_ci REG_READ(PIPEBCONF); 4068c2ecf20Sopenharmony_ci } 4078c2ecf20Sopenharmony_ci 4088c2ecf20Sopenharmony_ci /* Disable LNW Pipes, etc */ 4098c2ecf20Sopenharmony_ci temp = REG_READ(PCH_PIPEBCONF); 4108c2ecf20Sopenharmony_ci if ((temp & PIPEACONF_ENABLE) != 0) { 4118c2ecf20Sopenharmony_ci REG_WRITE(PCH_PIPEBCONF, temp & ~PIPEACONF_ENABLE); 4128c2ecf20Sopenharmony_ci REG_READ(PCH_PIPEBCONF); 4138c2ecf20Sopenharmony_ci } 4148c2ecf20Sopenharmony_ci 4158c2ecf20Sopenharmony_ci /* wait for pipe off */ 4168c2ecf20Sopenharmony_ci udelay(150); 4178c2ecf20Sopenharmony_ci 4188c2ecf20Sopenharmony_ci /* Disable dpll */ 4198c2ecf20Sopenharmony_ci temp = REG_READ(DPLL_CTRL); 4208c2ecf20Sopenharmony_ci if ((temp & DPLL_PWRDN) == 0) { 4218c2ecf20Sopenharmony_ci REG_WRITE(DPLL_CTRL, temp | (DPLL_PWRDN | DPLL_RESET)); 4228c2ecf20Sopenharmony_ci REG_WRITE(DPLL_STATUS, 0x1); 4238c2ecf20Sopenharmony_ci } 4248c2ecf20Sopenharmony_ci 4258c2ecf20Sopenharmony_ci /* wait for dpll off */ 4268c2ecf20Sopenharmony_ci udelay(150); 4278c2ecf20Sopenharmony_ci 4288c2ecf20Sopenharmony_ci break; 4298c2ecf20Sopenharmony_ci case DRM_MODE_DPMS_ON: 4308c2ecf20Sopenharmony_ci case DRM_MODE_DPMS_STANDBY: 4318c2ecf20Sopenharmony_ci case DRM_MODE_DPMS_SUSPEND: 4328c2ecf20Sopenharmony_ci /* Enable dpll */ 4338c2ecf20Sopenharmony_ci temp = REG_READ(DPLL_CTRL); 4348c2ecf20Sopenharmony_ci if ((temp & DPLL_PWRDN) != 0) { 4358c2ecf20Sopenharmony_ci REG_WRITE(DPLL_CTRL, temp & ~(DPLL_PWRDN | DPLL_RESET)); 4368c2ecf20Sopenharmony_ci temp = REG_READ(DPLL_CLK_ENABLE); 4378c2ecf20Sopenharmony_ci REG_WRITE(DPLL_CLK_ENABLE, temp | DPLL_EN_DISP | DPLL_SEL_HDMI | DPLL_EN_HDMI); 4388c2ecf20Sopenharmony_ci REG_READ(DPLL_CLK_ENABLE); 4398c2ecf20Sopenharmony_ci } 4408c2ecf20Sopenharmony_ci /* wait for dpll warm up */ 4418c2ecf20Sopenharmony_ci udelay(150); 4428c2ecf20Sopenharmony_ci 4438c2ecf20Sopenharmony_ci /* Enable pipe B */ 4448c2ecf20Sopenharmony_ci temp = REG_READ(PIPEBCONF); 4458c2ecf20Sopenharmony_ci if ((temp & PIPEACONF_ENABLE) == 0) { 4468c2ecf20Sopenharmony_ci REG_WRITE(PIPEBCONF, temp | PIPEACONF_ENABLE); 4478c2ecf20Sopenharmony_ci REG_READ(PIPEBCONF); 4488c2ecf20Sopenharmony_ci } 4498c2ecf20Sopenharmony_ci 4508c2ecf20Sopenharmony_ci /* Enable LNW Pipe B */ 4518c2ecf20Sopenharmony_ci temp = REG_READ(PCH_PIPEBCONF); 4528c2ecf20Sopenharmony_ci if ((temp & PIPEACONF_ENABLE) == 0) { 4538c2ecf20Sopenharmony_ci REG_WRITE(PCH_PIPEBCONF, temp | PIPEACONF_ENABLE); 4548c2ecf20Sopenharmony_ci REG_READ(PCH_PIPEBCONF); 4558c2ecf20Sopenharmony_ci } 4568c2ecf20Sopenharmony_ci 4578c2ecf20Sopenharmony_ci gma_wait_for_vblank(dev); 4588c2ecf20Sopenharmony_ci 4598c2ecf20Sopenharmony_ci /* Enable plane */ 4608c2ecf20Sopenharmony_ci temp = REG_READ(DSPBCNTR); 4618c2ecf20Sopenharmony_ci if ((temp & DISPLAY_PLANE_ENABLE) == 0) { 4628c2ecf20Sopenharmony_ci REG_WRITE(DSPBCNTR, temp | DISPLAY_PLANE_ENABLE); 4638c2ecf20Sopenharmony_ci /* Flush the plane changes */ 4648c2ecf20Sopenharmony_ci REG_WRITE(DSPBSURF, REG_READ(DSPBSURF)); 4658c2ecf20Sopenharmony_ci REG_READ(DSPBSURF); 4668c2ecf20Sopenharmony_ci } 4678c2ecf20Sopenharmony_ci 4688c2ecf20Sopenharmony_ci gma_crtc_load_lut(crtc); 4698c2ecf20Sopenharmony_ci } 4708c2ecf20Sopenharmony_ci 4718c2ecf20Sopenharmony_ci /* DSPARB */ 4728c2ecf20Sopenharmony_ci REG_WRITE(DSPARB, 0x00003fbf); 4738c2ecf20Sopenharmony_ci 4748c2ecf20Sopenharmony_ci /* FW1 */ 4758c2ecf20Sopenharmony_ci REG_WRITE(0x70034, 0x3f880a0a); 4768c2ecf20Sopenharmony_ci 4778c2ecf20Sopenharmony_ci /* FW2 */ 4788c2ecf20Sopenharmony_ci REG_WRITE(0x70038, 0x0b060808); 4798c2ecf20Sopenharmony_ci 4808c2ecf20Sopenharmony_ci /* FW4 */ 4818c2ecf20Sopenharmony_ci REG_WRITE(0x70050, 0x08030404); 4828c2ecf20Sopenharmony_ci 4838c2ecf20Sopenharmony_ci /* FW5 */ 4848c2ecf20Sopenharmony_ci REG_WRITE(0x70054, 0x04040404); 4858c2ecf20Sopenharmony_ci 4868c2ecf20Sopenharmony_ci /* LNC Chicken Bits - Squawk! */ 4878c2ecf20Sopenharmony_ci REG_WRITE(0x70400, 0x4000); 4888c2ecf20Sopenharmony_ci 4898c2ecf20Sopenharmony_ci return; 4908c2ecf20Sopenharmony_ci} 4918c2ecf20Sopenharmony_ci 4928c2ecf20Sopenharmony_cistatic void oaktrail_hdmi_dpms(struct drm_encoder *encoder, int mode) 4938c2ecf20Sopenharmony_ci{ 4948c2ecf20Sopenharmony_ci static int dpms_mode = -1; 4958c2ecf20Sopenharmony_ci 4968c2ecf20Sopenharmony_ci struct drm_device *dev = encoder->dev; 4978c2ecf20Sopenharmony_ci struct drm_psb_private *dev_priv = dev->dev_private; 4988c2ecf20Sopenharmony_ci struct oaktrail_hdmi_dev *hdmi_dev = dev_priv->hdmi_priv; 4998c2ecf20Sopenharmony_ci u32 temp; 5008c2ecf20Sopenharmony_ci 5018c2ecf20Sopenharmony_ci if (dpms_mode == mode) 5028c2ecf20Sopenharmony_ci return; 5038c2ecf20Sopenharmony_ci 5048c2ecf20Sopenharmony_ci if (mode != DRM_MODE_DPMS_ON) 5058c2ecf20Sopenharmony_ci temp = 0x0; 5068c2ecf20Sopenharmony_ci else 5078c2ecf20Sopenharmony_ci temp = 0x99; 5088c2ecf20Sopenharmony_ci 5098c2ecf20Sopenharmony_ci dpms_mode = mode; 5108c2ecf20Sopenharmony_ci HDMI_WRITE(HDMI_VIDEO_REG, temp); 5118c2ecf20Sopenharmony_ci} 5128c2ecf20Sopenharmony_ci 5138c2ecf20Sopenharmony_cistatic enum drm_mode_status oaktrail_hdmi_mode_valid(struct drm_connector *connector, 5148c2ecf20Sopenharmony_ci struct drm_display_mode *mode) 5158c2ecf20Sopenharmony_ci{ 5168c2ecf20Sopenharmony_ci if (mode->clock > 165000) 5178c2ecf20Sopenharmony_ci return MODE_CLOCK_HIGH; 5188c2ecf20Sopenharmony_ci if (mode->clock < 20000) 5198c2ecf20Sopenharmony_ci return MODE_CLOCK_LOW; 5208c2ecf20Sopenharmony_ci 5218c2ecf20Sopenharmony_ci if (mode->flags & DRM_MODE_FLAG_DBLSCAN) 5228c2ecf20Sopenharmony_ci return MODE_NO_DBLESCAN; 5238c2ecf20Sopenharmony_ci 5248c2ecf20Sopenharmony_ci return MODE_OK; 5258c2ecf20Sopenharmony_ci} 5268c2ecf20Sopenharmony_ci 5278c2ecf20Sopenharmony_cistatic enum drm_connector_status 5288c2ecf20Sopenharmony_cioaktrail_hdmi_detect(struct drm_connector *connector, bool force) 5298c2ecf20Sopenharmony_ci{ 5308c2ecf20Sopenharmony_ci enum drm_connector_status status; 5318c2ecf20Sopenharmony_ci struct drm_device *dev = connector->dev; 5328c2ecf20Sopenharmony_ci struct drm_psb_private *dev_priv = dev->dev_private; 5338c2ecf20Sopenharmony_ci struct oaktrail_hdmi_dev *hdmi_dev = dev_priv->hdmi_priv; 5348c2ecf20Sopenharmony_ci u32 temp; 5358c2ecf20Sopenharmony_ci 5368c2ecf20Sopenharmony_ci temp = HDMI_READ(HDMI_HSR); 5378c2ecf20Sopenharmony_ci DRM_DEBUG_KMS("HDMI_HSR %x\n", temp); 5388c2ecf20Sopenharmony_ci 5398c2ecf20Sopenharmony_ci if ((temp & HDMI_DETECT_HDP) != 0) 5408c2ecf20Sopenharmony_ci status = connector_status_connected; 5418c2ecf20Sopenharmony_ci else 5428c2ecf20Sopenharmony_ci status = connector_status_disconnected; 5438c2ecf20Sopenharmony_ci 5448c2ecf20Sopenharmony_ci return status; 5458c2ecf20Sopenharmony_ci} 5468c2ecf20Sopenharmony_ci 5478c2ecf20Sopenharmony_cistatic const unsigned char raw_edid[] = { 5488c2ecf20Sopenharmony_ci 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x10, 0xac, 0x2f, 0xa0, 5498c2ecf20Sopenharmony_ci 0x53, 0x55, 0x33, 0x30, 0x16, 0x13, 0x01, 0x03, 0x0e, 0x3a, 0x24, 0x78, 5508c2ecf20Sopenharmony_ci 0xea, 0xe9, 0xf5, 0xac, 0x51, 0x30, 0xb4, 0x25, 0x11, 0x50, 0x54, 0xa5, 5518c2ecf20Sopenharmony_ci 0x4b, 0x00, 0x81, 0x80, 0xa9, 0x40, 0x71, 0x4f, 0xb3, 0x00, 0x01, 0x01, 5528c2ecf20Sopenharmony_ci 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x28, 0x3c, 0x80, 0xa0, 0x70, 0xb0, 5538c2ecf20Sopenharmony_ci 0x23, 0x40, 0x30, 0x20, 0x36, 0x00, 0x46, 0x6c, 0x21, 0x00, 0x00, 0x1a, 5548c2ecf20Sopenharmony_ci 0x00, 0x00, 0x00, 0xff, 0x00, 0x47, 0x4e, 0x37, 0x32, 0x31, 0x39, 0x35, 5558c2ecf20Sopenharmony_ci 0x52, 0x30, 0x33, 0x55, 0x53, 0x0a, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x44, 5568c2ecf20Sopenharmony_ci 0x45, 0x4c, 0x4c, 0x20, 0x32, 0x37, 0x30, 0x39, 0x57, 0x0a, 0x20, 0x20, 5578c2ecf20Sopenharmony_ci 0x00, 0x00, 0x00, 0xfd, 0x00, 0x38, 0x4c, 0x1e, 0x53, 0x11, 0x00, 0x0a, 5588c2ecf20Sopenharmony_ci 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x8d 5598c2ecf20Sopenharmony_ci}; 5608c2ecf20Sopenharmony_ci 5618c2ecf20Sopenharmony_cistatic int oaktrail_hdmi_get_modes(struct drm_connector *connector) 5628c2ecf20Sopenharmony_ci{ 5638c2ecf20Sopenharmony_ci struct i2c_adapter *i2c_adap; 5648c2ecf20Sopenharmony_ci struct edid *edid; 5658c2ecf20Sopenharmony_ci int ret = 0; 5668c2ecf20Sopenharmony_ci 5678c2ecf20Sopenharmony_ci /* 5688c2ecf20Sopenharmony_ci * FIXME: We need to figure this lot out. In theory we can 5698c2ecf20Sopenharmony_ci * read the EDID somehow but I've yet to find working reference 5708c2ecf20Sopenharmony_ci * code. 5718c2ecf20Sopenharmony_ci */ 5728c2ecf20Sopenharmony_ci i2c_adap = i2c_get_adapter(3); 5738c2ecf20Sopenharmony_ci if (i2c_adap == NULL) { 5748c2ecf20Sopenharmony_ci DRM_ERROR("No ddc adapter available!\n"); 5758c2ecf20Sopenharmony_ci edid = (struct edid *)raw_edid; 5768c2ecf20Sopenharmony_ci } else { 5778c2ecf20Sopenharmony_ci edid = (struct edid *)raw_edid; 5788c2ecf20Sopenharmony_ci /* FIXME ? edid = drm_get_edid(connector, i2c_adap); */ 5798c2ecf20Sopenharmony_ci } 5808c2ecf20Sopenharmony_ci 5818c2ecf20Sopenharmony_ci if (edid) { 5828c2ecf20Sopenharmony_ci drm_connector_update_edid_property(connector, edid); 5838c2ecf20Sopenharmony_ci ret = drm_add_edid_modes(connector, edid); 5848c2ecf20Sopenharmony_ci } 5858c2ecf20Sopenharmony_ci return ret; 5868c2ecf20Sopenharmony_ci} 5878c2ecf20Sopenharmony_ci 5888c2ecf20Sopenharmony_cistatic void oaktrail_hdmi_mode_set(struct drm_encoder *encoder, 5898c2ecf20Sopenharmony_ci struct drm_display_mode *mode, 5908c2ecf20Sopenharmony_ci struct drm_display_mode *adjusted_mode) 5918c2ecf20Sopenharmony_ci{ 5928c2ecf20Sopenharmony_ci struct drm_device *dev = encoder->dev; 5938c2ecf20Sopenharmony_ci 5948c2ecf20Sopenharmony_ci oaktrail_hdmi_audio_enable(dev); 5958c2ecf20Sopenharmony_ci return; 5968c2ecf20Sopenharmony_ci} 5978c2ecf20Sopenharmony_ci 5988c2ecf20Sopenharmony_cistatic void oaktrail_hdmi_destroy(struct drm_connector *connector) 5998c2ecf20Sopenharmony_ci{ 6008c2ecf20Sopenharmony_ci return; 6018c2ecf20Sopenharmony_ci} 6028c2ecf20Sopenharmony_ci 6038c2ecf20Sopenharmony_cistatic const struct drm_encoder_helper_funcs oaktrail_hdmi_helper_funcs = { 6048c2ecf20Sopenharmony_ci .dpms = oaktrail_hdmi_dpms, 6058c2ecf20Sopenharmony_ci .prepare = gma_encoder_prepare, 6068c2ecf20Sopenharmony_ci .mode_set = oaktrail_hdmi_mode_set, 6078c2ecf20Sopenharmony_ci .commit = gma_encoder_commit, 6088c2ecf20Sopenharmony_ci}; 6098c2ecf20Sopenharmony_ci 6108c2ecf20Sopenharmony_cistatic const struct drm_connector_helper_funcs 6118c2ecf20Sopenharmony_ci oaktrail_hdmi_connector_helper_funcs = { 6128c2ecf20Sopenharmony_ci .get_modes = oaktrail_hdmi_get_modes, 6138c2ecf20Sopenharmony_ci .mode_valid = oaktrail_hdmi_mode_valid, 6148c2ecf20Sopenharmony_ci .best_encoder = gma_best_encoder, 6158c2ecf20Sopenharmony_ci}; 6168c2ecf20Sopenharmony_ci 6178c2ecf20Sopenharmony_cistatic const struct drm_connector_funcs oaktrail_hdmi_connector_funcs = { 6188c2ecf20Sopenharmony_ci .dpms = drm_helper_connector_dpms, 6198c2ecf20Sopenharmony_ci .detect = oaktrail_hdmi_detect, 6208c2ecf20Sopenharmony_ci .fill_modes = drm_helper_probe_single_connector_modes, 6218c2ecf20Sopenharmony_ci .destroy = oaktrail_hdmi_destroy, 6228c2ecf20Sopenharmony_ci}; 6238c2ecf20Sopenharmony_ci 6248c2ecf20Sopenharmony_civoid oaktrail_hdmi_init(struct drm_device *dev, 6258c2ecf20Sopenharmony_ci struct psb_intel_mode_device *mode_dev) 6268c2ecf20Sopenharmony_ci{ 6278c2ecf20Sopenharmony_ci struct gma_encoder *gma_encoder; 6288c2ecf20Sopenharmony_ci struct gma_connector *gma_connector; 6298c2ecf20Sopenharmony_ci struct drm_connector *connector; 6308c2ecf20Sopenharmony_ci struct drm_encoder *encoder; 6318c2ecf20Sopenharmony_ci 6328c2ecf20Sopenharmony_ci gma_encoder = kzalloc(sizeof(struct gma_encoder), GFP_KERNEL); 6338c2ecf20Sopenharmony_ci if (!gma_encoder) 6348c2ecf20Sopenharmony_ci return; 6358c2ecf20Sopenharmony_ci 6368c2ecf20Sopenharmony_ci gma_connector = kzalloc(sizeof(struct gma_connector), GFP_KERNEL); 6378c2ecf20Sopenharmony_ci if (!gma_connector) 6388c2ecf20Sopenharmony_ci goto failed_connector; 6398c2ecf20Sopenharmony_ci 6408c2ecf20Sopenharmony_ci connector = &gma_connector->base; 6418c2ecf20Sopenharmony_ci encoder = &gma_encoder->base; 6428c2ecf20Sopenharmony_ci drm_connector_init(dev, connector, 6438c2ecf20Sopenharmony_ci &oaktrail_hdmi_connector_funcs, 6448c2ecf20Sopenharmony_ci DRM_MODE_CONNECTOR_DVID); 6458c2ecf20Sopenharmony_ci 6468c2ecf20Sopenharmony_ci drm_simple_encoder_init(dev, encoder, DRM_MODE_ENCODER_TMDS); 6478c2ecf20Sopenharmony_ci 6488c2ecf20Sopenharmony_ci gma_connector_attach_encoder(gma_connector, gma_encoder); 6498c2ecf20Sopenharmony_ci 6508c2ecf20Sopenharmony_ci gma_encoder->type = INTEL_OUTPUT_HDMI; 6518c2ecf20Sopenharmony_ci drm_encoder_helper_add(encoder, &oaktrail_hdmi_helper_funcs); 6528c2ecf20Sopenharmony_ci drm_connector_helper_add(connector, &oaktrail_hdmi_connector_helper_funcs); 6538c2ecf20Sopenharmony_ci 6548c2ecf20Sopenharmony_ci connector->display_info.subpixel_order = SubPixelHorizontalRGB; 6558c2ecf20Sopenharmony_ci connector->interlace_allowed = false; 6568c2ecf20Sopenharmony_ci connector->doublescan_allowed = false; 6578c2ecf20Sopenharmony_ci drm_connector_register(connector); 6588c2ecf20Sopenharmony_ci dev_info(dev->dev, "HDMI initialised.\n"); 6598c2ecf20Sopenharmony_ci 6608c2ecf20Sopenharmony_ci return; 6618c2ecf20Sopenharmony_ci 6628c2ecf20Sopenharmony_cifailed_connector: 6638c2ecf20Sopenharmony_ci kfree(gma_encoder); 6648c2ecf20Sopenharmony_ci} 6658c2ecf20Sopenharmony_ci 6668c2ecf20Sopenharmony_civoid oaktrail_hdmi_setup(struct drm_device *dev) 6678c2ecf20Sopenharmony_ci{ 6688c2ecf20Sopenharmony_ci struct drm_psb_private *dev_priv = dev->dev_private; 6698c2ecf20Sopenharmony_ci struct pci_dev *pdev; 6708c2ecf20Sopenharmony_ci struct oaktrail_hdmi_dev *hdmi_dev; 6718c2ecf20Sopenharmony_ci int ret; 6728c2ecf20Sopenharmony_ci 6738c2ecf20Sopenharmony_ci pdev = pci_get_device(PCI_VENDOR_ID_INTEL, 0x080d, NULL); 6748c2ecf20Sopenharmony_ci if (!pdev) 6758c2ecf20Sopenharmony_ci return; 6768c2ecf20Sopenharmony_ci 6778c2ecf20Sopenharmony_ci hdmi_dev = kzalloc(sizeof(struct oaktrail_hdmi_dev), GFP_KERNEL); 6788c2ecf20Sopenharmony_ci if (!hdmi_dev) { 6798c2ecf20Sopenharmony_ci dev_err(dev->dev, "failed to allocate memory\n"); 6808c2ecf20Sopenharmony_ci goto out; 6818c2ecf20Sopenharmony_ci } 6828c2ecf20Sopenharmony_ci 6838c2ecf20Sopenharmony_ci 6848c2ecf20Sopenharmony_ci ret = pci_enable_device(pdev); 6858c2ecf20Sopenharmony_ci if (ret) { 6868c2ecf20Sopenharmony_ci dev_err(dev->dev, "failed to enable hdmi controller\n"); 6878c2ecf20Sopenharmony_ci goto free; 6888c2ecf20Sopenharmony_ci } 6898c2ecf20Sopenharmony_ci 6908c2ecf20Sopenharmony_ci hdmi_dev->mmio = pci_resource_start(pdev, 0); 6918c2ecf20Sopenharmony_ci hdmi_dev->mmio_len = pci_resource_len(pdev, 0); 6928c2ecf20Sopenharmony_ci hdmi_dev->regs = ioremap(hdmi_dev->mmio, hdmi_dev->mmio_len); 6938c2ecf20Sopenharmony_ci if (!hdmi_dev->regs) { 6948c2ecf20Sopenharmony_ci dev_err(dev->dev, "failed to map hdmi mmio\n"); 6958c2ecf20Sopenharmony_ci goto free; 6968c2ecf20Sopenharmony_ci } 6978c2ecf20Sopenharmony_ci 6988c2ecf20Sopenharmony_ci hdmi_dev->dev = pdev; 6998c2ecf20Sopenharmony_ci pci_set_drvdata(pdev, hdmi_dev); 7008c2ecf20Sopenharmony_ci 7018c2ecf20Sopenharmony_ci /* Initialize i2c controller */ 7028c2ecf20Sopenharmony_ci ret = oaktrail_hdmi_i2c_init(hdmi_dev->dev); 7038c2ecf20Sopenharmony_ci if (ret) 7048c2ecf20Sopenharmony_ci dev_err(dev->dev, "HDMI I2C initialization failed\n"); 7058c2ecf20Sopenharmony_ci 7068c2ecf20Sopenharmony_ci dev_priv->hdmi_priv = hdmi_dev; 7078c2ecf20Sopenharmony_ci oaktrail_hdmi_audio_disable(dev); 7088c2ecf20Sopenharmony_ci 7098c2ecf20Sopenharmony_ci dev_info(dev->dev, "HDMI hardware present.\n"); 7108c2ecf20Sopenharmony_ci 7118c2ecf20Sopenharmony_ci return; 7128c2ecf20Sopenharmony_ci 7138c2ecf20Sopenharmony_cifree: 7148c2ecf20Sopenharmony_ci kfree(hdmi_dev); 7158c2ecf20Sopenharmony_ciout: 7168c2ecf20Sopenharmony_ci return; 7178c2ecf20Sopenharmony_ci} 7188c2ecf20Sopenharmony_ci 7198c2ecf20Sopenharmony_civoid oaktrail_hdmi_teardown(struct drm_device *dev) 7208c2ecf20Sopenharmony_ci{ 7218c2ecf20Sopenharmony_ci struct drm_psb_private *dev_priv = dev->dev_private; 7228c2ecf20Sopenharmony_ci struct oaktrail_hdmi_dev *hdmi_dev = dev_priv->hdmi_priv; 7238c2ecf20Sopenharmony_ci struct pci_dev *pdev; 7248c2ecf20Sopenharmony_ci 7258c2ecf20Sopenharmony_ci if (hdmi_dev) { 7268c2ecf20Sopenharmony_ci pdev = hdmi_dev->dev; 7278c2ecf20Sopenharmony_ci pci_set_drvdata(pdev, NULL); 7288c2ecf20Sopenharmony_ci oaktrail_hdmi_i2c_exit(pdev); 7298c2ecf20Sopenharmony_ci iounmap(hdmi_dev->regs); 7308c2ecf20Sopenharmony_ci kfree(hdmi_dev); 7318c2ecf20Sopenharmony_ci pci_dev_put(pdev); 7328c2ecf20Sopenharmony_ci } 7338c2ecf20Sopenharmony_ci} 7348c2ecf20Sopenharmony_ci 7358c2ecf20Sopenharmony_ci/* save HDMI register state */ 7368c2ecf20Sopenharmony_civoid oaktrail_hdmi_save(struct drm_device *dev) 7378c2ecf20Sopenharmony_ci{ 7388c2ecf20Sopenharmony_ci struct drm_psb_private *dev_priv = dev->dev_private; 7398c2ecf20Sopenharmony_ci struct oaktrail_hdmi_dev *hdmi_dev = dev_priv->hdmi_priv; 7408c2ecf20Sopenharmony_ci struct psb_state *regs = &dev_priv->regs.psb; 7418c2ecf20Sopenharmony_ci struct psb_pipe *pipeb = &dev_priv->regs.pipe[1]; 7428c2ecf20Sopenharmony_ci int i; 7438c2ecf20Sopenharmony_ci 7448c2ecf20Sopenharmony_ci /* dpll */ 7458c2ecf20Sopenharmony_ci hdmi_dev->saveDPLL_CTRL = PSB_RVDC32(DPLL_CTRL); 7468c2ecf20Sopenharmony_ci hdmi_dev->saveDPLL_DIV_CTRL = PSB_RVDC32(DPLL_DIV_CTRL); 7478c2ecf20Sopenharmony_ci hdmi_dev->saveDPLL_ADJUST = PSB_RVDC32(DPLL_ADJUST); 7488c2ecf20Sopenharmony_ci hdmi_dev->saveDPLL_UPDATE = PSB_RVDC32(DPLL_UPDATE); 7498c2ecf20Sopenharmony_ci hdmi_dev->saveDPLL_CLK_ENABLE = PSB_RVDC32(DPLL_CLK_ENABLE); 7508c2ecf20Sopenharmony_ci 7518c2ecf20Sopenharmony_ci /* pipe B */ 7528c2ecf20Sopenharmony_ci pipeb->conf = PSB_RVDC32(PIPEBCONF); 7538c2ecf20Sopenharmony_ci pipeb->src = PSB_RVDC32(PIPEBSRC); 7548c2ecf20Sopenharmony_ci pipeb->htotal = PSB_RVDC32(HTOTAL_B); 7558c2ecf20Sopenharmony_ci pipeb->hblank = PSB_RVDC32(HBLANK_B); 7568c2ecf20Sopenharmony_ci pipeb->hsync = PSB_RVDC32(HSYNC_B); 7578c2ecf20Sopenharmony_ci pipeb->vtotal = PSB_RVDC32(VTOTAL_B); 7588c2ecf20Sopenharmony_ci pipeb->vblank = PSB_RVDC32(VBLANK_B); 7598c2ecf20Sopenharmony_ci pipeb->vsync = PSB_RVDC32(VSYNC_B); 7608c2ecf20Sopenharmony_ci 7618c2ecf20Sopenharmony_ci hdmi_dev->savePCH_PIPEBCONF = PSB_RVDC32(PCH_PIPEBCONF); 7628c2ecf20Sopenharmony_ci hdmi_dev->savePCH_PIPEBSRC = PSB_RVDC32(PCH_PIPEBSRC); 7638c2ecf20Sopenharmony_ci hdmi_dev->savePCH_HTOTAL_B = PSB_RVDC32(PCH_HTOTAL_B); 7648c2ecf20Sopenharmony_ci hdmi_dev->savePCH_HBLANK_B = PSB_RVDC32(PCH_HBLANK_B); 7658c2ecf20Sopenharmony_ci hdmi_dev->savePCH_HSYNC_B = PSB_RVDC32(PCH_HSYNC_B); 7668c2ecf20Sopenharmony_ci hdmi_dev->savePCH_VTOTAL_B = PSB_RVDC32(PCH_VTOTAL_B); 7678c2ecf20Sopenharmony_ci hdmi_dev->savePCH_VBLANK_B = PSB_RVDC32(PCH_VBLANK_B); 7688c2ecf20Sopenharmony_ci hdmi_dev->savePCH_VSYNC_B = PSB_RVDC32(PCH_VSYNC_B); 7698c2ecf20Sopenharmony_ci 7708c2ecf20Sopenharmony_ci /* plane */ 7718c2ecf20Sopenharmony_ci pipeb->cntr = PSB_RVDC32(DSPBCNTR); 7728c2ecf20Sopenharmony_ci pipeb->stride = PSB_RVDC32(DSPBSTRIDE); 7738c2ecf20Sopenharmony_ci pipeb->addr = PSB_RVDC32(DSPBBASE); 7748c2ecf20Sopenharmony_ci pipeb->surf = PSB_RVDC32(DSPBSURF); 7758c2ecf20Sopenharmony_ci pipeb->linoff = PSB_RVDC32(DSPBLINOFF); 7768c2ecf20Sopenharmony_ci pipeb->tileoff = PSB_RVDC32(DSPBTILEOFF); 7778c2ecf20Sopenharmony_ci 7788c2ecf20Sopenharmony_ci /* cursor B */ 7798c2ecf20Sopenharmony_ci regs->saveDSPBCURSOR_CTRL = PSB_RVDC32(CURBCNTR); 7808c2ecf20Sopenharmony_ci regs->saveDSPBCURSOR_BASE = PSB_RVDC32(CURBBASE); 7818c2ecf20Sopenharmony_ci regs->saveDSPBCURSOR_POS = PSB_RVDC32(CURBPOS); 7828c2ecf20Sopenharmony_ci 7838c2ecf20Sopenharmony_ci /* save palette */ 7848c2ecf20Sopenharmony_ci for (i = 0; i < 256; i++) 7858c2ecf20Sopenharmony_ci pipeb->palette[i] = PSB_RVDC32(PALETTE_B + (i << 2)); 7868c2ecf20Sopenharmony_ci} 7878c2ecf20Sopenharmony_ci 7888c2ecf20Sopenharmony_ci/* restore HDMI register state */ 7898c2ecf20Sopenharmony_civoid oaktrail_hdmi_restore(struct drm_device *dev) 7908c2ecf20Sopenharmony_ci{ 7918c2ecf20Sopenharmony_ci struct drm_psb_private *dev_priv = dev->dev_private; 7928c2ecf20Sopenharmony_ci struct oaktrail_hdmi_dev *hdmi_dev = dev_priv->hdmi_priv; 7938c2ecf20Sopenharmony_ci struct psb_state *regs = &dev_priv->regs.psb; 7948c2ecf20Sopenharmony_ci struct psb_pipe *pipeb = &dev_priv->regs.pipe[1]; 7958c2ecf20Sopenharmony_ci int i; 7968c2ecf20Sopenharmony_ci 7978c2ecf20Sopenharmony_ci /* dpll */ 7988c2ecf20Sopenharmony_ci PSB_WVDC32(hdmi_dev->saveDPLL_CTRL, DPLL_CTRL); 7998c2ecf20Sopenharmony_ci PSB_WVDC32(hdmi_dev->saveDPLL_DIV_CTRL, DPLL_DIV_CTRL); 8008c2ecf20Sopenharmony_ci PSB_WVDC32(hdmi_dev->saveDPLL_ADJUST, DPLL_ADJUST); 8018c2ecf20Sopenharmony_ci PSB_WVDC32(hdmi_dev->saveDPLL_UPDATE, DPLL_UPDATE); 8028c2ecf20Sopenharmony_ci PSB_WVDC32(hdmi_dev->saveDPLL_CLK_ENABLE, DPLL_CLK_ENABLE); 8038c2ecf20Sopenharmony_ci udelay(150); 8048c2ecf20Sopenharmony_ci 8058c2ecf20Sopenharmony_ci /* pipe */ 8068c2ecf20Sopenharmony_ci PSB_WVDC32(pipeb->src, PIPEBSRC); 8078c2ecf20Sopenharmony_ci PSB_WVDC32(pipeb->htotal, HTOTAL_B); 8088c2ecf20Sopenharmony_ci PSB_WVDC32(pipeb->hblank, HBLANK_B); 8098c2ecf20Sopenharmony_ci PSB_WVDC32(pipeb->hsync, HSYNC_B); 8108c2ecf20Sopenharmony_ci PSB_WVDC32(pipeb->vtotal, VTOTAL_B); 8118c2ecf20Sopenharmony_ci PSB_WVDC32(pipeb->vblank, VBLANK_B); 8128c2ecf20Sopenharmony_ci PSB_WVDC32(pipeb->vsync, VSYNC_B); 8138c2ecf20Sopenharmony_ci 8148c2ecf20Sopenharmony_ci PSB_WVDC32(hdmi_dev->savePCH_PIPEBSRC, PCH_PIPEBSRC); 8158c2ecf20Sopenharmony_ci PSB_WVDC32(hdmi_dev->savePCH_HTOTAL_B, PCH_HTOTAL_B); 8168c2ecf20Sopenharmony_ci PSB_WVDC32(hdmi_dev->savePCH_HBLANK_B, PCH_HBLANK_B); 8178c2ecf20Sopenharmony_ci PSB_WVDC32(hdmi_dev->savePCH_HSYNC_B, PCH_HSYNC_B); 8188c2ecf20Sopenharmony_ci PSB_WVDC32(hdmi_dev->savePCH_VTOTAL_B, PCH_VTOTAL_B); 8198c2ecf20Sopenharmony_ci PSB_WVDC32(hdmi_dev->savePCH_VBLANK_B, PCH_VBLANK_B); 8208c2ecf20Sopenharmony_ci PSB_WVDC32(hdmi_dev->savePCH_VSYNC_B, PCH_VSYNC_B); 8218c2ecf20Sopenharmony_ci 8228c2ecf20Sopenharmony_ci PSB_WVDC32(pipeb->conf, PIPEBCONF); 8238c2ecf20Sopenharmony_ci PSB_WVDC32(hdmi_dev->savePCH_PIPEBCONF, PCH_PIPEBCONF); 8248c2ecf20Sopenharmony_ci 8258c2ecf20Sopenharmony_ci /* plane */ 8268c2ecf20Sopenharmony_ci PSB_WVDC32(pipeb->linoff, DSPBLINOFF); 8278c2ecf20Sopenharmony_ci PSB_WVDC32(pipeb->stride, DSPBSTRIDE); 8288c2ecf20Sopenharmony_ci PSB_WVDC32(pipeb->tileoff, DSPBTILEOFF); 8298c2ecf20Sopenharmony_ci PSB_WVDC32(pipeb->cntr, DSPBCNTR); 8308c2ecf20Sopenharmony_ci PSB_WVDC32(pipeb->surf, DSPBSURF); 8318c2ecf20Sopenharmony_ci 8328c2ecf20Sopenharmony_ci /* cursor B */ 8338c2ecf20Sopenharmony_ci PSB_WVDC32(regs->saveDSPBCURSOR_CTRL, CURBCNTR); 8348c2ecf20Sopenharmony_ci PSB_WVDC32(regs->saveDSPBCURSOR_POS, CURBPOS); 8358c2ecf20Sopenharmony_ci PSB_WVDC32(regs->saveDSPBCURSOR_BASE, CURBBASE); 8368c2ecf20Sopenharmony_ci 8378c2ecf20Sopenharmony_ci /* restore palette */ 8388c2ecf20Sopenharmony_ci for (i = 0; i < 256; i++) 8398c2ecf20Sopenharmony_ci PSB_WVDC32(pipeb->palette[i], PALETTE_B + (i << 2)); 8408c2ecf20Sopenharmony_ci} 841