Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 1 | /* Geode LX framebuffer driver |
| 2 | * |
| 3 | * Copyright (C) 2006-2007, Advanced Micro Devices,Inc. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License as published by the |
| 7 | * Free Software Foundation; either version 2 of the License, or (at your |
| 8 | * option) any later version. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/errno.h> |
| 13 | #include <linux/fb.h> |
| 14 | #include <linux/uaccess.h> |
| 15 | #include <linux/delay.h> |
Andres Salomon | 32bf87e | 2008-04-28 02:14:53 -0700 | [diff] [blame] | 16 | #include <asm/geode.h> |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 17 | |
| 18 | #include "lxfb.h" |
| 19 | |
| 20 | /* TODO |
| 21 | * Support panel scaling |
| 22 | * Add acceleration |
| 23 | * Add support for interlacing (TV out) |
| 24 | * Support compression |
| 25 | */ |
| 26 | |
| 27 | /* This is the complete list of PLL frequencies that we can set - |
| 28 | * we will choose the closest match to the incoming clock. |
| 29 | * freq is the frequency of the dotclock * 1000 (for example, |
| 30 | * 24823 = 24.983 Mhz). |
| 31 | * pllval is the corresponding PLL value |
| 32 | */ |
| 33 | |
| 34 | static const struct { |
| 35 | unsigned int pllval; |
| 36 | unsigned int freq; |
| 37 | } pll_table[] = { |
Jens Rottmann | 3888d46 | 2008-04-28 02:15:22 -0700 | [diff] [blame] | 38 | { 0x000131AC, 6231 }, |
| 39 | { 0x0001215D, 6294 }, |
| 40 | { 0x00011087, 6750 }, |
| 41 | { 0x0001216C, 7081 }, |
| 42 | { 0x0001218D, 7140 }, |
| 43 | { 0x000110C9, 7800 }, |
| 44 | { 0x00013147, 7875 }, |
| 45 | { 0x000110A7, 8258 }, |
| 46 | { 0x00012159, 8778 }, |
| 47 | { 0x00014249, 8875 }, |
| 48 | { 0x00010057, 9000 }, |
| 49 | { 0x0001219A, 9472 }, |
| 50 | { 0x00012158, 9792 }, |
| 51 | { 0x00010045, 10000 }, |
| 52 | { 0x00010089, 10791 }, |
| 53 | { 0x000110E7, 11225 }, |
| 54 | { 0x00012136, 11430 }, |
| 55 | { 0x00013207, 12375 }, |
| 56 | { 0x00012187, 12500 }, |
| 57 | { 0x00014286, 14063 }, |
| 58 | { 0x000110E5, 15016 }, |
| 59 | { 0x00014214, 16250 }, |
| 60 | { 0x00011105, 17045 }, |
| 61 | { 0x000131E4, 18563 }, |
| 62 | { 0x00013183, 18750 }, |
| 63 | { 0x00014284, 19688 }, |
| 64 | { 0x00011104, 20400 }, |
| 65 | { 0x00016363, 23625 }, |
| 66 | { 0x00015303, 24380 }, |
| 67 | { 0x000031AC, 24923 }, |
| 68 | { 0x0000215D, 25175 }, |
| 69 | { 0x00001087, 27000 }, |
| 70 | { 0x0000216C, 28322 }, |
| 71 | { 0x0000218D, 28560 }, |
| 72 | { 0x00010041, 29913 }, |
| 73 | { 0x000010C9, 31200 }, |
| 74 | { 0x00003147, 31500 }, |
| 75 | { 0x000141A1, 32400 }, |
| 76 | { 0x000010A7, 33032 }, |
| 77 | { 0x00012182, 33375 }, |
| 78 | { 0x000141B1, 33750 }, |
| 79 | { 0x00002159, 35112 }, |
| 80 | { 0x00004249, 35500 }, |
| 81 | { 0x00000057, 36000 }, |
| 82 | { 0x000141E1, 37125 }, |
| 83 | { 0x0000219A, 37889 }, |
| 84 | { 0x00002158, 39168 }, |
| 85 | { 0x00000045, 40000 }, |
| 86 | { 0x000131A1, 40500 }, |
| 87 | { 0x00010061, 42301 }, |
| 88 | { 0x00000089, 43163 }, |
| 89 | { 0x00012151, 43875 }, |
| 90 | { 0x000010E7, 44900 }, |
| 91 | { 0x00002136, 45720 }, |
| 92 | { 0x000152E1, 47250 }, |
| 93 | { 0x00010071, 48000 }, |
| 94 | { 0x00003207, 49500 }, |
| 95 | { 0x00002187, 50000 }, |
| 96 | { 0x00014291, 50625 }, |
| 97 | { 0x00011101, 51188 }, |
| 98 | { 0x00017481, 54563 }, |
| 99 | { 0x00004286, 56250 }, |
| 100 | { 0x00014170, 57375 }, |
| 101 | { 0x00016210, 58500 }, |
| 102 | { 0x000010E5, 60065 }, |
| 103 | { 0x00013140, 62796 }, |
| 104 | { 0x00004214, 65000 }, |
| 105 | { 0x00016250, 65250 }, |
| 106 | { 0x00001105, 68179 }, |
| 107 | { 0x000141C0, 69600 }, |
| 108 | { 0x00015220, 70160 }, |
| 109 | { 0x00010050, 72000 }, |
| 110 | { 0x000031E4, 74250 }, |
| 111 | { 0x00003183, 75000 }, |
| 112 | { 0x00004284, 78750 }, |
| 113 | { 0x00012130, 80052 }, |
| 114 | { 0x00001104, 81600 }, |
| 115 | { 0x00006363, 94500 }, |
| 116 | { 0x00005303, 97520 }, |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 117 | { 0x00002183, 100187 }, |
| 118 | { 0x00002122, 101420 }, |
| 119 | { 0x00001081, 108000 }, |
| 120 | { 0x00006201, 113310 }, |
| 121 | { 0x00000041, 119650 }, |
| 122 | { 0x000041A1, 129600 }, |
| 123 | { 0x00002182, 133500 }, |
| 124 | { 0x000041B1, 135000 }, |
| 125 | { 0x00000051, 144000 }, |
| 126 | { 0x000041E1, 148500 }, |
| 127 | { 0x000062D1, 157500 }, |
| 128 | { 0x000031A1, 162000 }, |
| 129 | { 0x00000061, 169203 }, |
| 130 | { 0x00004231, 172800 }, |
| 131 | { 0x00002151, 175500 }, |
| 132 | { 0x000052E1, 189000 }, |
| 133 | { 0x00000071, 192000 }, |
| 134 | { 0x00003201, 198000 }, |
| 135 | { 0x00004291, 202500 }, |
| 136 | { 0x00001101, 204750 }, |
| 137 | { 0x00007481, 218250 }, |
| 138 | { 0x00004170, 229500 }, |
| 139 | { 0x00006210, 234000 }, |
| 140 | { 0x00003140, 251182 }, |
| 141 | { 0x00006250, 261000 }, |
| 142 | { 0x000041C0, 278400 }, |
| 143 | { 0x00005220, 280640 }, |
| 144 | { 0x00000050, 288000 }, |
| 145 | { 0x000041E0, 297000 }, |
| 146 | { 0x00002130, 320207 } |
| 147 | }; |
| 148 | |
| 149 | |
| 150 | static void lx_set_dotpll(u32 pllval) |
| 151 | { |
| 152 | u32 dotpll_lo, dotpll_hi; |
| 153 | int i; |
| 154 | |
Andres Salomon | 32bf87e | 2008-04-28 02:14:53 -0700 | [diff] [blame] | 155 | rdmsr(MSR_GLCP_DOTPLL, dotpll_lo, dotpll_hi); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 156 | |
Andres Salomon | aec4053 | 2008-04-28 02:15:26 -0700 | [diff] [blame^] | 157 | if ((dotpll_lo & MSR_GLCP_DOTPLL_LOCK) && (dotpll_hi == pllval)) |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 158 | return; |
| 159 | |
| 160 | dotpll_hi = pllval; |
Andres Salomon | aec4053 | 2008-04-28 02:15:26 -0700 | [diff] [blame^] | 161 | dotpll_lo &= ~(MSR_GLCP_DOTPLL_BYPASS | MSR_GLCP_DOTPLL_HALFPIX); |
| 162 | dotpll_lo |= MSR_GLCP_DOTPLL_DOTRESET; |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 163 | |
Andres Salomon | 32bf87e | 2008-04-28 02:14:53 -0700 | [diff] [blame] | 164 | wrmsr(MSR_GLCP_DOTPLL, dotpll_lo, dotpll_hi); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 165 | |
| 166 | /* Wait 100us for the PLL to lock */ |
| 167 | |
| 168 | udelay(100); |
| 169 | |
| 170 | /* Now, loop for the lock bit */ |
| 171 | |
| 172 | for (i = 0; i < 1000; i++) { |
Andres Salomon | 32bf87e | 2008-04-28 02:14:53 -0700 | [diff] [blame] | 173 | rdmsr(MSR_GLCP_DOTPLL, dotpll_lo, dotpll_hi); |
Andres Salomon | aec4053 | 2008-04-28 02:15:26 -0700 | [diff] [blame^] | 174 | if (dotpll_lo & MSR_GLCP_DOTPLL_LOCK) |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 175 | break; |
| 176 | } |
| 177 | |
| 178 | /* Clear the reset bit */ |
| 179 | |
Andres Salomon | aec4053 | 2008-04-28 02:15:26 -0700 | [diff] [blame^] | 180 | dotpll_lo &= ~MSR_GLCP_DOTPLL_DOTRESET; |
Andres Salomon | 32bf87e | 2008-04-28 02:14:53 -0700 | [diff] [blame] | 181 | wrmsr(MSR_GLCP_DOTPLL, dotpll_lo, dotpll_hi); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | /* Set the clock based on the frequency specified by the current mode */ |
| 185 | |
| 186 | static void lx_set_clock(struct fb_info *info) |
| 187 | { |
| 188 | unsigned int diff, min, best = 0; |
| 189 | unsigned int freq, i; |
| 190 | |
Jens Rottmann | 3888d46 | 2008-04-28 02:15:22 -0700 | [diff] [blame] | 191 | freq = (unsigned int) (1000000000 / info->var.pixclock); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 192 | |
| 193 | min = abs(pll_table[0].freq - freq); |
| 194 | |
| 195 | for (i = 0; i < ARRAY_SIZE(pll_table); i++) { |
| 196 | diff = abs(pll_table[i].freq - freq); |
| 197 | if (diff < min) { |
| 198 | min = diff; |
| 199 | best = i; |
| 200 | } |
| 201 | } |
| 202 | |
Jens Rottmann | 3888d46 | 2008-04-28 02:15:22 -0700 | [diff] [blame] | 203 | lx_set_dotpll(pll_table[best].pllval & 0x00017FFF); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | static void lx_graphics_disable(struct fb_info *info) |
| 207 | { |
| 208 | struct lxfb_par *par = info->par; |
| 209 | unsigned int val, gcfg; |
| 210 | |
| 211 | /* Note: This assumes that the video is in a quitet state */ |
| 212 | |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 213 | write_vp(par, VP_A1T, 0); |
| 214 | write_vp(par, VP_A2T, 0); |
| 215 | write_vp(par, VP_A3T, 0); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 216 | |
| 217 | /* Turn off the VGA and video enable */ |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 218 | val = read_dc(par, DC_GENERAL_CFG) & ~(DC_GENERAL_CFG_VGAE | |
| 219 | DC_GENERAL_CFG_VIDE); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 220 | |
Andres Salomon | 9286361 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 221 | write_dc(par, DC_GENERAL_CFG, val); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 222 | |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 223 | val = read_vp(par, VP_VCFG) & ~VP_VCFG_VID_EN; |
| 224 | write_vp(par, VP_VCFG, val); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 225 | |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 226 | write_dc(par, DC_IRQ, DC_IRQ_MASK | DC_IRQ_VIP_VSYNC_LOSS_IRQ_MASK | |
| 227 | DC_IRQ_STATUS | DC_IRQ_VIP_VSYNC_IRQ_STATUS); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 228 | |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 229 | val = read_dc(par, DC_GENLK_CTL) & ~DC_GENLK_CTL_GENLK_EN; |
| 230 | write_dc(par, DC_GENLK_CTL, val); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 231 | |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 232 | val = read_dc(par, DC_CLR_KEY); |
| 233 | write_dc(par, DC_CLR_KEY, val & ~DC_CLR_KEY_CLR_KEY_EN); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 234 | |
| 235 | /* We don't actually blank the panel, due to the long latency |
| 236 | involved with bringing it back */ |
| 237 | |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 238 | val = read_vp(par, VP_MISC) | VP_MISC_DACPWRDN; |
| 239 | write_vp(par, VP_MISC, val); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 240 | |
| 241 | /* Turn off the display */ |
| 242 | |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 243 | val = read_vp(par, VP_DCFG); |
| 244 | write_vp(par, VP_DCFG, val & ~(VP_DCFG_CRT_EN | VP_DCFG_HSYNC_EN | |
| 245 | VP_DCFG_VSYNC_EN | VP_DCFG_DAC_BL_EN)); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 246 | |
Andres Salomon | 9286361 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 247 | gcfg = read_dc(par, DC_GENERAL_CFG); |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 248 | gcfg &= ~(DC_GENERAL_CFG_CMPE | DC_GENERAL_CFG_DECE); |
Andres Salomon | 9286361 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 249 | write_dc(par, DC_GENERAL_CFG, gcfg); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 250 | |
| 251 | /* Turn off the TGEN */ |
Andres Salomon | 9286361 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 252 | val = read_dc(par, DC_DISPLAY_CFG); |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 253 | val &= ~DC_DISPLAY_CFG_TGEN; |
Andres Salomon | 9286361 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 254 | write_dc(par, DC_DISPLAY_CFG, val); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 255 | |
| 256 | /* Wait 1000 usecs to ensure that the TGEN is clear */ |
| 257 | udelay(1000); |
| 258 | |
| 259 | /* Turn off the FIFO loader */ |
| 260 | |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 261 | gcfg &= ~DC_GENERAL_CFG_DFLE; |
Andres Salomon | 9286361 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 262 | write_dc(par, DC_GENERAL_CFG, gcfg); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 263 | |
| 264 | /* Lastly, wait for the GP to go idle */ |
| 265 | |
| 266 | do { |
Andres Salomon | 9286361 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 267 | val = read_gp(par, GP_BLT_STATUS); |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 268 | } while ((val & GP_BLT_STATUS_PB) || !(val & GP_BLT_STATUS_CE)); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | static void lx_graphics_enable(struct fb_info *info) |
| 272 | { |
| 273 | struct lxfb_par *par = info->par; |
| 274 | u32 temp, config; |
| 275 | |
| 276 | /* Set the video request register */ |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 277 | write_vp(par, VP_VRR, 0); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 278 | |
| 279 | /* Set up the polarities */ |
| 280 | |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 281 | config = read_vp(par, VP_DCFG); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 282 | |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 283 | config &= ~(VP_DCFG_CRT_SYNC_SKW | VP_DCFG_PWR_SEQ_DELAY | |
| 284 | VP_DCFG_CRT_HSYNC_POL | VP_DCFG_CRT_VSYNC_POL); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 285 | |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 286 | config |= (VP_DCFG_CRT_SYNC_SKW_DEFAULT | VP_DCFG_PWR_SEQ_DELAY_DEFAULT |
| 287 | | VP_DCFG_GV_GAM); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 288 | |
| 289 | if (info->var.sync & FB_SYNC_HOR_HIGH_ACT) |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 290 | config |= VP_DCFG_CRT_HSYNC_POL; |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 291 | |
| 292 | if (info->var.sync & FB_SYNC_VERT_HIGH_ACT) |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 293 | config |= VP_DCFG_CRT_VSYNC_POL; |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 294 | |
| 295 | if (par->output & OUTPUT_PANEL) { |
| 296 | u32 msrlo, msrhi; |
| 297 | |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 298 | write_fp(par, FP_PT1, 0); |
| 299 | write_fp(par, FP_PT2, FP_PT2_SCRC); |
| 300 | write_fp(par, FP_DFC, FP_DFC_BC); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 301 | |
Andres Salomon | aec4053 | 2008-04-28 02:15:26 -0700 | [diff] [blame^] | 302 | msrlo = MSR_LX_MSR_PADSEL_TFT_SEL_LOW; |
| 303 | msrhi = MSR_LX_MSR_PADSEL_TFT_SEL_HIGH; |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 304 | |
Andres Salomon | 32bf87e | 2008-04-28 02:14:53 -0700 | [diff] [blame] | 305 | wrmsr(MSR_LX_MSR_PADSEL, msrlo, msrhi); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | if (par->output & OUTPUT_CRT) { |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 309 | config |= VP_DCFG_CRT_EN | VP_DCFG_HSYNC_EN | |
| 310 | VP_DCFG_VSYNC_EN | VP_DCFG_DAC_BL_EN; |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 311 | } |
| 312 | |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 313 | write_vp(par, VP_DCFG, config); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 314 | |
| 315 | /* Turn the CRT dacs back on */ |
| 316 | |
| 317 | if (par->output & OUTPUT_CRT) { |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 318 | temp = read_vp(par, VP_MISC); |
| 319 | temp &= ~(VP_MISC_DACPWRDN | VP_MISC_APWRDN); |
| 320 | write_vp(par, VP_MISC, temp); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | /* Turn the panel on (if it isn't already) */ |
| 324 | |
| 325 | if (par->output & OUTPUT_PANEL) { |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 326 | temp = read_fp(par, FP_PM); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 327 | |
| 328 | if (!(temp & 0x09)) |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 329 | write_fp(par, FP_PM, temp | FP_PM_P); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 330 | } |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | unsigned int lx_framebuffer_size(void) |
| 334 | { |
| 335 | unsigned int val; |
| 336 | |
| 337 | /* The frame buffer size is reported by a VSM in VSA II */ |
| 338 | /* Virtual Register Class = 0x02 */ |
| 339 | /* VG_MEM_SIZE (1MB units) = 0x00 */ |
| 340 | |
| 341 | outw(0xFC53, 0xAC1C); |
| 342 | outw(0x0200, 0xAC1C); |
| 343 | |
| 344 | val = (unsigned int)(inw(0xAC1E)) & 0xFE; |
| 345 | return (val << 20); |
| 346 | } |
| 347 | |
| 348 | void lx_set_mode(struct fb_info *info) |
| 349 | { |
| 350 | struct lxfb_par *par = info->par; |
| 351 | u64 msrval; |
| 352 | |
| 353 | unsigned int max, dv, val, size; |
| 354 | |
| 355 | unsigned int gcfg, dcfg; |
| 356 | int hactive, hblankstart, hsyncstart, hsyncend, hblankend, htotal; |
| 357 | int vactive, vblankstart, vsyncstart, vsyncend, vblankend, vtotal; |
| 358 | |
| 359 | /* Unlock the DC registers */ |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 360 | write_dc(par, DC_UNLOCK, DC_UNLOCK_UNLOCK); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 361 | |
| 362 | lx_graphics_disable(info); |
| 363 | |
| 364 | lx_set_clock(info); |
| 365 | |
| 366 | /* Set output mode */ |
| 367 | |
Andres Salomon | 32bf87e | 2008-04-28 02:14:53 -0700 | [diff] [blame] | 368 | rdmsrl(MSR_LX_GLD_MSR_CONFIG, msrval); |
Andres Salomon | aec4053 | 2008-04-28 02:15:26 -0700 | [diff] [blame^] | 369 | msrval &= ~MSR_LX_GLD_MSR_CONFIG_FMT; |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 370 | |
| 371 | if (par->output & OUTPUT_PANEL) { |
Andres Salomon | aec4053 | 2008-04-28 02:15:26 -0700 | [diff] [blame^] | 372 | msrval |= MSR_LX_GLD_MSR_CONFIG_FMT_FP; |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 373 | |
| 374 | if (par->output & OUTPUT_CRT) |
Andres Salomon | aec4053 | 2008-04-28 02:15:26 -0700 | [diff] [blame^] | 375 | msrval |= MSR_LX_GLD_MSR_CONFIG_FPC; |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 376 | else |
Andres Salomon | aec4053 | 2008-04-28 02:15:26 -0700 | [diff] [blame^] | 377 | msrval &= ~MSR_LX_GLD_MSR_CONFIG_FPC; |
| 378 | } else |
| 379 | msrval |= MSR_LX_GLD_MSR_CONFIG_FMT_CRT; |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 380 | |
Andres Salomon | 32bf87e | 2008-04-28 02:14:53 -0700 | [diff] [blame] | 381 | wrmsrl(MSR_LX_GLD_MSR_CONFIG, msrval); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 382 | |
| 383 | /* Clear the various buffers */ |
| 384 | /* FIXME: Adjust for panning here */ |
| 385 | |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 386 | write_dc(par, DC_FB_ST_OFFSET, 0); |
| 387 | write_dc(par, DC_CB_ST_OFFSET, 0); |
| 388 | write_dc(par, DC_CURS_ST_OFFSET, 0); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 389 | |
| 390 | /* FIXME: Add support for interlacing */ |
| 391 | /* FIXME: Add support for scaling */ |
| 392 | |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 393 | val = read_dc(par, DC_GENLK_CTL); |
| 394 | val &= ~(DC_GENLK_CTL_ALPHA_FLICK_EN | DC_GENLK_CTL_FLICK_EN | |
| 395 | DC_GENLK_CTL_FLICK_SEL_MASK); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 396 | |
| 397 | /* Default scaling params */ |
| 398 | |
Andres Salomon | 9286361 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 399 | write_dc(par, DC_GFX_SCALE, (0x4000 << 16) | 0x4000); |
| 400 | write_dc(par, DC_IRQ_FILT_CTL, 0); |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 401 | write_dc(par, DC_GENLK_CTL, val); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 402 | |
| 403 | /* FIXME: Support compression */ |
| 404 | |
| 405 | if (info->fix.line_length > 4096) |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 406 | dv = DC_DV_CTL_DV_LINE_SIZE_8K; |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 407 | else if (info->fix.line_length > 2048) |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 408 | dv = DC_DV_CTL_DV_LINE_SIZE_4K; |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 409 | else if (info->fix.line_length > 1024) |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 410 | dv = DC_DV_CTL_DV_LINE_SIZE_2K; |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 411 | else |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 412 | dv = DC_DV_CTL_DV_LINE_SIZE_1K; |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 413 | |
| 414 | max = info->fix.line_length * info->var.yres; |
| 415 | max = (max + 0x3FF) & 0xFFFFFC00; |
| 416 | |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 417 | write_dc(par, DC_DV_TOP, max | DC_DV_TOP_DV_TOP_EN); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 418 | |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 419 | val = read_dc(par, DC_DV_CTL) & ~DC_DV_CTL_DV_LINE_SIZE; |
Andres Salomon | 9286361 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 420 | write_dc(par, DC_DV_CTL, val | dv); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 421 | |
| 422 | size = info->var.xres * (info->var.bits_per_pixel >> 3); |
| 423 | |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 424 | write_dc(par, DC_GFX_PITCH, info->fix.line_length >> 3); |
Andres Salomon | 9286361 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 425 | write_dc(par, DC_LINE_SIZE, (size + 7) >> 3); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 426 | |
| 427 | /* Set default watermark values */ |
| 428 | |
Andres Salomon | 32bf87e | 2008-04-28 02:14:53 -0700 | [diff] [blame] | 429 | rdmsrl(MSR_LX_SPARE_MSR, msrval); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 430 | |
Andres Salomon | aec4053 | 2008-04-28 02:15:26 -0700 | [diff] [blame^] | 431 | msrval &= ~(MSR_LX_SPARE_MSR_DIS_CFIFO_HGO |
| 432 | | MSR_LX_SPARE_MSR_VFIFO_ARB_SEL |
| 433 | | MSR_LX_SPARE_MSR_LOAD_WM_LPEN_M |
| 434 | | MSR_LX_SPARE_MSR_WM_LPEN_OVRD); |
| 435 | msrval |= MSR_LX_SPARE_MSR_DIS_VIFO_WM | |
| 436 | MSR_LX_SPARE_MSR_DIS_INIT_V_PRI; |
Andres Salomon | 32bf87e | 2008-04-28 02:14:53 -0700 | [diff] [blame] | 437 | wrmsrl(MSR_LX_SPARE_MSR, msrval); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 438 | |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 439 | gcfg = DC_GENERAL_CFG_DFLE; /* Display fifo enable */ |
| 440 | gcfg |= (0x6 << DC_GENERAL_CFG_DFHPSL_SHIFT) | /* default priority */ |
| 441 | (0xb << DC_GENERAL_CFG_DFHPEL_SHIFT); |
| 442 | gcfg |= DC_GENERAL_CFG_FDTY; /* Set the frame dirty mode */ |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 443 | |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 444 | dcfg = DC_DISPLAY_CFG_VDEN; /* Enable video data */ |
| 445 | dcfg |= DC_DISPLAY_CFG_GDEN; /* Enable graphics */ |
| 446 | dcfg |= DC_DISPLAY_CFG_TGEN; /* Turn on the timing generator */ |
| 447 | dcfg |= DC_DISPLAY_CFG_TRUP; /* Update timings immediately */ |
| 448 | dcfg |= DC_DISPLAY_CFG_PALB; /* Palette bypass in > 8 bpp modes */ |
| 449 | dcfg |= DC_DISPLAY_CFG_VISL; |
| 450 | dcfg |= DC_DISPLAY_CFG_DCEN; /* Always center the display */ |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 451 | |
| 452 | /* Set the current BPP mode */ |
| 453 | |
| 454 | switch (info->var.bits_per_pixel) { |
| 455 | case 8: |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 456 | dcfg |= DC_DISPLAY_CFG_DISP_MODE_8BPP; |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 457 | break; |
| 458 | |
| 459 | case 16: |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 460 | dcfg |= DC_DISPLAY_CFG_DISP_MODE_16BPP; |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 461 | break; |
| 462 | |
| 463 | case 32: |
| 464 | case 24: |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 465 | dcfg |= DC_DISPLAY_CFG_DISP_MODE_24BPP; |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 466 | break; |
| 467 | } |
| 468 | |
| 469 | /* Now - set up the timings */ |
| 470 | |
| 471 | hactive = info->var.xres; |
| 472 | hblankstart = hactive; |
| 473 | hsyncstart = hblankstart + info->var.right_margin; |
| 474 | hsyncend = hsyncstart + info->var.hsync_len; |
| 475 | hblankend = hsyncend + info->var.left_margin; |
| 476 | htotal = hblankend; |
| 477 | |
| 478 | vactive = info->var.yres; |
| 479 | vblankstart = vactive; |
| 480 | vsyncstart = vblankstart + info->var.lower_margin; |
| 481 | vsyncend = vsyncstart + info->var.vsync_len; |
| 482 | vblankend = vsyncend + info->var.upper_margin; |
| 483 | vtotal = vblankend; |
| 484 | |
Andres Salomon | 9286361 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 485 | write_dc(par, DC_H_ACTIVE_TIMING, (hactive - 1) | ((htotal - 1) << 16)); |
| 486 | write_dc(par, DC_H_BLANK_TIMING, |
| 487 | (hblankstart - 1) | ((hblankend - 1) << 16)); |
| 488 | write_dc(par, DC_H_SYNC_TIMING, |
| 489 | (hsyncstart - 1) | ((hsyncend - 1) << 16)); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 490 | |
Andres Salomon | 9286361 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 491 | write_dc(par, DC_V_ACTIVE_TIMING, (vactive - 1) | ((vtotal - 1) << 16)); |
| 492 | write_dc(par, DC_V_BLANK_TIMING, |
| 493 | (vblankstart - 1) | ((vblankend - 1) << 16)); |
| 494 | write_dc(par, DC_V_SYNC_TIMING, |
| 495 | (vsyncstart - 1) | ((vsyncend - 1) << 16)); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 496 | |
Andres Salomon | 9286361 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 497 | write_dc(par, DC_FB_ACTIVE, |
| 498 | (info->var.xres - 1) << 16 | (info->var.yres - 1)); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 499 | |
| 500 | /* And re-enable the graphics output */ |
| 501 | lx_graphics_enable(info); |
| 502 | |
| 503 | /* Write the two main configuration registers */ |
Andres Salomon | 9286361 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 504 | write_dc(par, DC_DISPLAY_CFG, dcfg); |
| 505 | write_dc(par, DC_ARB_CFG, 0); |
| 506 | write_dc(par, DC_GENERAL_CFG, gcfg); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 507 | |
| 508 | /* Lock the DC registers */ |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 509 | write_dc(par, DC_UNLOCK, DC_UNLOCK_LOCK); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | void lx_set_palette_reg(struct fb_info *info, unsigned regno, |
| 513 | unsigned red, unsigned green, unsigned blue) |
| 514 | { |
| 515 | struct lxfb_par *par = info->par; |
| 516 | int val; |
| 517 | |
| 518 | /* Hardware palette is in RGB 8-8-8 format. */ |
| 519 | |
| 520 | val = (red << 8) & 0xff0000; |
| 521 | val |= (green) & 0x00ff00; |
| 522 | val |= (blue >> 8) & 0x0000ff; |
| 523 | |
Andres Salomon | 9286361 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 524 | write_dc(par, DC_PAL_ADDRESS, regno); |
| 525 | write_dc(par, DC_PAL_DATA, val); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | int lx_blank_display(struct fb_info *info, int blank_mode) |
| 529 | { |
| 530 | struct lxfb_par *par = info->par; |
| 531 | u32 dcfg, fp_pm; |
| 532 | int blank, hsync, vsync; |
| 533 | |
| 534 | /* CRT power saving modes. */ |
| 535 | switch (blank_mode) { |
| 536 | case FB_BLANK_UNBLANK: |
| 537 | blank = 0; hsync = 1; vsync = 1; |
| 538 | break; |
| 539 | case FB_BLANK_NORMAL: |
| 540 | blank = 1; hsync = 1; vsync = 1; |
| 541 | break; |
| 542 | case FB_BLANK_VSYNC_SUSPEND: |
| 543 | blank = 1; hsync = 1; vsync = 0; |
| 544 | break; |
| 545 | case FB_BLANK_HSYNC_SUSPEND: |
| 546 | blank = 1; hsync = 0; vsync = 1; |
| 547 | break; |
| 548 | case FB_BLANK_POWERDOWN: |
| 549 | blank = 1; hsync = 0; vsync = 0; |
| 550 | break; |
| 551 | default: |
| 552 | return -EINVAL; |
| 553 | } |
| 554 | |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 555 | dcfg = read_vp(par, VP_DCFG); |
| 556 | dcfg &= ~(VP_DCFG_DAC_BL_EN | VP_DCFG_HSYNC_EN | VP_DCFG_VSYNC_EN); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 557 | if (!blank) |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 558 | dcfg |= VP_DCFG_DAC_BL_EN; |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 559 | if (hsync) |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 560 | dcfg |= VP_DCFG_HSYNC_EN; |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 561 | if (vsync) |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 562 | dcfg |= VP_DCFG_VSYNC_EN; |
| 563 | write_vp(par, VP_DCFG, dcfg); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 564 | |
| 565 | /* Power on/off flat panel */ |
| 566 | |
| 567 | if (par->output & OUTPUT_PANEL) { |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 568 | fp_pm = read_fp(par, FP_PM); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 569 | if (blank_mode == FB_BLANK_POWERDOWN) |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 570 | fp_pm &= ~FP_PM_P; |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 571 | else |
Andres Salomon | f5c90e8 | 2008-04-28 02:15:24 -0700 | [diff] [blame] | 572 | fp_pm |= FP_PM_P; |
| 573 | write_fp(par, FP_PM, fp_pm); |
Jordan Crouse | 3968cb49 | 2007-07-31 00:37:40 -0700 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | return 0; |
| 577 | } |