Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/video/omap2/dss/dispc.c |
| 3 | * |
| 4 | * Copyright (C) 2009 Nokia Corporation |
| 5 | * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com> |
| 6 | * |
| 7 | * Some code and ideas taken from drivers/video/omap/ driver |
| 8 | * by Imre Deak. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License version 2 as published by |
| 12 | * the Free Software Foundation. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 17 | * more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along with |
| 20 | * this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | */ |
| 22 | |
| 23 | #define DSS_SUBSYS_NAME "DISPC" |
| 24 | |
| 25 | #include <linux/kernel.h> |
| 26 | #include <linux/dma-mapping.h> |
| 27 | #include <linux/vmalloc.h> |
| 28 | #include <linux/clk.h> |
| 29 | #include <linux/io.h> |
| 30 | #include <linux/jiffies.h> |
| 31 | #include <linux/seq_file.h> |
| 32 | #include <linux/delay.h> |
| 33 | #include <linux/workqueue.h> |
Tomi Valkeinen | ab83b14 | 2010-06-09 15:31:01 +0300 | [diff] [blame] | 34 | #include <linux/hardirq.h> |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 35 | |
| 36 | #include <plat/sram.h> |
| 37 | #include <plat/clock.h> |
| 38 | |
| 39 | #include <plat/display.h> |
| 40 | |
| 41 | #include "dss.h" |
Archit Taneja | a0acb55 | 2010-09-15 19:20:00 +0530 | [diff] [blame] | 42 | #include "dss_features.h" |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 43 | |
| 44 | /* DISPC */ |
| 45 | #define DISPC_BASE 0x48050400 |
| 46 | |
Sumit Semwal | 8613b00 | 2010-12-02 11:27:09 +0000 | [diff] [blame] | 47 | #define DISPC_SZ_REGS SZ_4K |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 48 | |
| 49 | struct dispc_reg { u16 idx; }; |
| 50 | |
| 51 | #define DISPC_REG(idx) ((const struct dispc_reg) { idx }) |
| 52 | |
Sumit Semwal | 8613b00 | 2010-12-02 11:27:09 +0000 | [diff] [blame] | 53 | /* |
| 54 | * DISPC common registers and |
| 55 | * DISPC channel registers , ch = 0 for LCD, ch = 1 for |
| 56 | * DIGIT, and ch = 2 for LCD2 |
| 57 | */ |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 58 | #define DISPC_REVISION DISPC_REG(0x0000) |
| 59 | #define DISPC_SYSCONFIG DISPC_REG(0x0010) |
| 60 | #define DISPC_SYSSTATUS DISPC_REG(0x0014) |
| 61 | #define DISPC_IRQSTATUS DISPC_REG(0x0018) |
| 62 | #define DISPC_IRQENABLE DISPC_REG(0x001C) |
| 63 | #define DISPC_CONTROL DISPC_REG(0x0040) |
Sumit Semwal | 8613b00 | 2010-12-02 11:27:09 +0000 | [diff] [blame] | 64 | #define DISPC_CONTROL2 DISPC_REG(0x0238) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 65 | #define DISPC_CONFIG DISPC_REG(0x0044) |
Sumit Semwal | 8613b00 | 2010-12-02 11:27:09 +0000 | [diff] [blame] | 66 | #define DISPC_CONFIG2 DISPC_REG(0x0620) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 67 | #define DISPC_CAPABLE DISPC_REG(0x0048) |
Sumit Semwal | 8613b00 | 2010-12-02 11:27:09 +0000 | [diff] [blame] | 68 | #define DISPC_DEFAULT_COLOR(ch) DISPC_REG(ch == 0 ? 0x004C : \ |
| 69 | (ch == 1 ? 0x0050 : 0x03AC)) |
| 70 | #define DISPC_TRANS_COLOR(ch) DISPC_REG(ch == 0 ? 0x0054 : \ |
| 71 | (ch == 1 ? 0x0058 : 0x03B0)) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 72 | #define DISPC_LINE_STATUS DISPC_REG(0x005C) |
| 73 | #define DISPC_LINE_NUMBER DISPC_REG(0x0060) |
Sumit Semwal | 8613b00 | 2010-12-02 11:27:09 +0000 | [diff] [blame] | 74 | #define DISPC_TIMING_H(ch) DISPC_REG(ch != 2 ? 0x0064 : 0x0400) |
| 75 | #define DISPC_TIMING_V(ch) DISPC_REG(ch != 2 ? 0x0068 : 0x0404) |
| 76 | #define DISPC_POL_FREQ(ch) DISPC_REG(ch != 2 ? 0x006C : 0x0408) |
| 77 | #define DISPC_DIVISOR(ch) DISPC_REG(ch != 2 ? 0x0070 : 0x040C) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 78 | #define DISPC_GLOBAL_ALPHA DISPC_REG(0x0074) |
| 79 | #define DISPC_SIZE_DIG DISPC_REG(0x0078) |
Sumit Semwal | 8613b00 | 2010-12-02 11:27:09 +0000 | [diff] [blame] | 80 | #define DISPC_SIZE_LCD(ch) DISPC_REG(ch != 2 ? 0x007C : 0x03CC) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 81 | |
| 82 | /* DISPC GFX plane */ |
| 83 | #define DISPC_GFX_BA0 DISPC_REG(0x0080) |
| 84 | #define DISPC_GFX_BA1 DISPC_REG(0x0084) |
| 85 | #define DISPC_GFX_POSITION DISPC_REG(0x0088) |
| 86 | #define DISPC_GFX_SIZE DISPC_REG(0x008C) |
| 87 | #define DISPC_GFX_ATTRIBUTES DISPC_REG(0x00A0) |
| 88 | #define DISPC_GFX_FIFO_THRESHOLD DISPC_REG(0x00A4) |
| 89 | #define DISPC_GFX_FIFO_SIZE_STATUS DISPC_REG(0x00A8) |
| 90 | #define DISPC_GFX_ROW_INC DISPC_REG(0x00AC) |
| 91 | #define DISPC_GFX_PIXEL_INC DISPC_REG(0x00B0) |
| 92 | #define DISPC_GFX_WINDOW_SKIP DISPC_REG(0x00B4) |
| 93 | #define DISPC_GFX_TABLE_BA DISPC_REG(0x00B8) |
| 94 | |
Sumit Semwal | 8613b00 | 2010-12-02 11:27:09 +0000 | [diff] [blame] | 95 | #define DISPC_DATA_CYCLE1(ch) DISPC_REG(ch != 2 ? 0x01D4 : 0x03C0) |
| 96 | #define DISPC_DATA_CYCLE2(ch) DISPC_REG(ch != 2 ? 0x01D8 : 0x03C4) |
| 97 | #define DISPC_DATA_CYCLE3(ch) DISPC_REG(ch != 2 ? 0x01DC : 0x03C8) |
| 98 | #define DISPC_CPR_COEF_R(ch) DISPC_REG(ch != 2 ? 0x0220 : 0x03BC) |
| 99 | #define DISPC_CPR_COEF_G(ch) DISPC_REG(ch != 2 ? 0x0224 : 0x03B8) |
| 100 | #define DISPC_CPR_COEF_B(ch) DISPC_REG(ch != 2 ? 0x0228 : 0x03B4) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 101 | |
| 102 | #define DISPC_GFX_PRELOAD DISPC_REG(0x022C) |
| 103 | |
| 104 | /* DISPC Video plane, n = 0 for VID1 and n = 1 for VID2 */ |
| 105 | #define DISPC_VID_REG(n, idx) DISPC_REG(0x00BC + (n)*0x90 + idx) |
| 106 | |
| 107 | #define DISPC_VID_BA0(n) DISPC_VID_REG(n, 0x0000) |
| 108 | #define DISPC_VID_BA1(n) DISPC_VID_REG(n, 0x0004) |
| 109 | #define DISPC_VID_POSITION(n) DISPC_VID_REG(n, 0x0008) |
| 110 | #define DISPC_VID_SIZE(n) DISPC_VID_REG(n, 0x000C) |
| 111 | #define DISPC_VID_ATTRIBUTES(n) DISPC_VID_REG(n, 0x0010) |
| 112 | #define DISPC_VID_FIFO_THRESHOLD(n) DISPC_VID_REG(n, 0x0014) |
| 113 | #define DISPC_VID_FIFO_SIZE_STATUS(n) DISPC_VID_REG(n, 0x0018) |
| 114 | #define DISPC_VID_ROW_INC(n) DISPC_VID_REG(n, 0x001C) |
| 115 | #define DISPC_VID_PIXEL_INC(n) DISPC_VID_REG(n, 0x0020) |
| 116 | #define DISPC_VID_FIR(n) DISPC_VID_REG(n, 0x0024) |
| 117 | #define DISPC_VID_PICTURE_SIZE(n) DISPC_VID_REG(n, 0x0028) |
| 118 | #define DISPC_VID_ACCU0(n) DISPC_VID_REG(n, 0x002C) |
| 119 | #define DISPC_VID_ACCU1(n) DISPC_VID_REG(n, 0x0030) |
| 120 | |
| 121 | /* coef index i = {0, 1, 2, 3, 4, 5, 6, 7} */ |
| 122 | #define DISPC_VID_FIR_COEF_H(n, i) DISPC_REG(0x00F0 + (n)*0x90 + (i)*0x8) |
| 123 | /* coef index i = {0, 1, 2, 3, 4, 5, 6, 7} */ |
| 124 | #define DISPC_VID_FIR_COEF_HV(n, i) DISPC_REG(0x00F4 + (n)*0x90 + (i)*0x8) |
| 125 | /* coef index i = {0, 1, 2, 3, 4} */ |
| 126 | #define DISPC_VID_CONV_COEF(n, i) DISPC_REG(0x0130 + (n)*0x90 + (i)*0x4) |
| 127 | /* coef index i = {0, 1, 2, 3, 4, 5, 6, 7} */ |
| 128 | #define DISPC_VID_FIR_COEF_V(n, i) DISPC_REG(0x01E0 + (n)*0x20 + (i)*0x4) |
| 129 | |
| 130 | #define DISPC_VID_PRELOAD(n) DISPC_REG(0x230 + (n)*0x04) |
| 131 | |
| 132 | |
| 133 | #define DISPC_IRQ_MASK_ERROR (DISPC_IRQ_GFX_FIFO_UNDERFLOW | \ |
| 134 | DISPC_IRQ_OCP_ERR | \ |
| 135 | DISPC_IRQ_VID1_FIFO_UNDERFLOW | \ |
| 136 | DISPC_IRQ_VID2_FIFO_UNDERFLOW | \ |
| 137 | DISPC_IRQ_SYNC_LOST | \ |
| 138 | DISPC_IRQ_SYNC_LOST_DIGIT) |
| 139 | |
| 140 | #define DISPC_MAX_NR_ISRS 8 |
| 141 | |
| 142 | struct omap_dispc_isr_data { |
| 143 | omap_dispc_isr_t isr; |
| 144 | void *arg; |
| 145 | u32 mask; |
| 146 | }; |
| 147 | |
Grazvydas Ignotas | 66be8f6 | 2010-08-24 15:18:43 +0200 | [diff] [blame] | 148 | struct dispc_h_coef { |
| 149 | s8 hc4; |
| 150 | s8 hc3; |
| 151 | u8 hc2; |
| 152 | s8 hc1; |
| 153 | s8 hc0; |
| 154 | }; |
| 155 | |
| 156 | struct dispc_v_coef { |
| 157 | s8 vc22; |
| 158 | s8 vc2; |
| 159 | u8 vc1; |
| 160 | s8 vc0; |
| 161 | s8 vc00; |
| 162 | }; |
| 163 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 164 | #define REG_GET(idx, start, end) \ |
| 165 | FLD_GET(dispc_read_reg(idx), start, end) |
| 166 | |
| 167 | #define REG_FLD_MOD(idx, val, start, end) \ |
| 168 | dispc_write_reg(idx, FLD_MOD(dispc_read_reg(idx), val, start, end)) |
| 169 | |
| 170 | static const struct dispc_reg dispc_reg_att[] = { DISPC_GFX_ATTRIBUTES, |
| 171 | DISPC_VID_ATTRIBUTES(0), |
| 172 | DISPC_VID_ATTRIBUTES(1) }; |
| 173 | |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 174 | struct dispc_irq_stats { |
| 175 | unsigned long last_reset; |
| 176 | unsigned irq_count; |
| 177 | unsigned irqs[32]; |
| 178 | }; |
| 179 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 180 | static struct { |
| 181 | void __iomem *base; |
| 182 | |
| 183 | u32 fifo_size[3]; |
| 184 | |
| 185 | spinlock_t irq_lock; |
| 186 | u32 irq_error_mask; |
| 187 | struct omap_dispc_isr_data registered_isr[DISPC_MAX_NR_ISRS]; |
| 188 | u32 error_irqs; |
| 189 | struct work_struct error_work; |
| 190 | |
| 191 | u32 ctx[DISPC_SZ_REGS / sizeof(u32)]; |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 192 | |
| 193 | #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS |
| 194 | spinlock_t irq_stats_lock; |
| 195 | struct dispc_irq_stats irq_stats; |
| 196 | #endif |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 197 | } dispc; |
| 198 | |
| 199 | static void _omap_dispc_set_irqs(void); |
| 200 | |
| 201 | static inline void dispc_write_reg(const struct dispc_reg idx, u32 val) |
| 202 | { |
| 203 | __raw_writel(val, dispc.base + idx.idx); |
| 204 | } |
| 205 | |
| 206 | static inline u32 dispc_read_reg(const struct dispc_reg idx) |
| 207 | { |
| 208 | return __raw_readl(dispc.base + idx.idx); |
| 209 | } |
| 210 | |
| 211 | #define SR(reg) \ |
| 212 | dispc.ctx[(DISPC_##reg).idx / sizeof(u32)] = dispc_read_reg(DISPC_##reg) |
| 213 | #define RR(reg) \ |
| 214 | dispc_write_reg(DISPC_##reg, dispc.ctx[(DISPC_##reg).idx / sizeof(u32)]) |
| 215 | |
| 216 | void dispc_save_context(void) |
| 217 | { |
| 218 | if (cpu_is_omap24xx()) |
| 219 | return; |
| 220 | |
| 221 | SR(SYSCONFIG); |
| 222 | SR(IRQENABLE); |
| 223 | SR(CONTROL); |
| 224 | SR(CONFIG); |
Sumit Semwal | 8613b00 | 2010-12-02 11:27:09 +0000 | [diff] [blame] | 225 | SR(DEFAULT_COLOR(0)); |
| 226 | SR(DEFAULT_COLOR(1)); |
| 227 | SR(TRANS_COLOR(0)); |
| 228 | SR(TRANS_COLOR(1)); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 229 | SR(LINE_NUMBER); |
Sumit Semwal | 8613b00 | 2010-12-02 11:27:09 +0000 | [diff] [blame] | 230 | SR(TIMING_H(0)); |
| 231 | SR(TIMING_V(0)); |
| 232 | SR(POL_FREQ(0)); |
| 233 | SR(DIVISOR(0)); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 234 | SR(GLOBAL_ALPHA); |
| 235 | SR(SIZE_DIG); |
Sumit Semwal | 8613b00 | 2010-12-02 11:27:09 +0000 | [diff] [blame] | 236 | SR(SIZE_LCD(0)); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 237 | if (dss_has_feature(FEAT_MGR_LCD2)) { |
| 238 | SR(CONTROL2); |
| 239 | SR(DEFAULT_COLOR(2)); |
| 240 | SR(TRANS_COLOR(2)); |
| 241 | SR(SIZE_LCD(2)); |
| 242 | SR(TIMING_H(2)); |
| 243 | SR(TIMING_V(2)); |
| 244 | SR(POL_FREQ(2)); |
| 245 | SR(DIVISOR(2)); |
| 246 | SR(CONFIG2); |
| 247 | } |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 248 | |
| 249 | SR(GFX_BA0); |
| 250 | SR(GFX_BA1); |
| 251 | SR(GFX_POSITION); |
| 252 | SR(GFX_SIZE); |
| 253 | SR(GFX_ATTRIBUTES); |
| 254 | SR(GFX_FIFO_THRESHOLD); |
| 255 | SR(GFX_ROW_INC); |
| 256 | SR(GFX_PIXEL_INC); |
| 257 | SR(GFX_WINDOW_SKIP); |
| 258 | SR(GFX_TABLE_BA); |
| 259 | |
Sumit Semwal | 8613b00 | 2010-12-02 11:27:09 +0000 | [diff] [blame] | 260 | SR(DATA_CYCLE1(0)); |
| 261 | SR(DATA_CYCLE2(0)); |
| 262 | SR(DATA_CYCLE3(0)); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 263 | |
Sumit Semwal | 8613b00 | 2010-12-02 11:27:09 +0000 | [diff] [blame] | 264 | SR(CPR_COEF_R(0)); |
| 265 | SR(CPR_COEF_G(0)); |
| 266 | SR(CPR_COEF_B(0)); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 267 | if (dss_has_feature(FEAT_MGR_LCD2)) { |
| 268 | SR(CPR_COEF_B(2)); |
| 269 | SR(CPR_COEF_G(2)); |
| 270 | SR(CPR_COEF_R(2)); |
| 271 | |
| 272 | SR(DATA_CYCLE1(2)); |
| 273 | SR(DATA_CYCLE2(2)); |
| 274 | SR(DATA_CYCLE3(2)); |
| 275 | } |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 276 | |
| 277 | SR(GFX_PRELOAD); |
| 278 | |
| 279 | /* VID1 */ |
| 280 | SR(VID_BA0(0)); |
| 281 | SR(VID_BA1(0)); |
| 282 | SR(VID_POSITION(0)); |
| 283 | SR(VID_SIZE(0)); |
| 284 | SR(VID_ATTRIBUTES(0)); |
| 285 | SR(VID_FIFO_THRESHOLD(0)); |
| 286 | SR(VID_ROW_INC(0)); |
| 287 | SR(VID_PIXEL_INC(0)); |
| 288 | SR(VID_FIR(0)); |
| 289 | SR(VID_PICTURE_SIZE(0)); |
| 290 | SR(VID_ACCU0(0)); |
| 291 | SR(VID_ACCU1(0)); |
| 292 | |
| 293 | SR(VID_FIR_COEF_H(0, 0)); |
| 294 | SR(VID_FIR_COEF_H(0, 1)); |
| 295 | SR(VID_FIR_COEF_H(0, 2)); |
| 296 | SR(VID_FIR_COEF_H(0, 3)); |
| 297 | SR(VID_FIR_COEF_H(0, 4)); |
| 298 | SR(VID_FIR_COEF_H(0, 5)); |
| 299 | SR(VID_FIR_COEF_H(0, 6)); |
| 300 | SR(VID_FIR_COEF_H(0, 7)); |
| 301 | |
| 302 | SR(VID_FIR_COEF_HV(0, 0)); |
| 303 | SR(VID_FIR_COEF_HV(0, 1)); |
| 304 | SR(VID_FIR_COEF_HV(0, 2)); |
| 305 | SR(VID_FIR_COEF_HV(0, 3)); |
| 306 | SR(VID_FIR_COEF_HV(0, 4)); |
| 307 | SR(VID_FIR_COEF_HV(0, 5)); |
| 308 | SR(VID_FIR_COEF_HV(0, 6)); |
| 309 | SR(VID_FIR_COEF_HV(0, 7)); |
| 310 | |
| 311 | SR(VID_CONV_COEF(0, 0)); |
| 312 | SR(VID_CONV_COEF(0, 1)); |
| 313 | SR(VID_CONV_COEF(0, 2)); |
| 314 | SR(VID_CONV_COEF(0, 3)); |
| 315 | SR(VID_CONV_COEF(0, 4)); |
| 316 | |
| 317 | SR(VID_FIR_COEF_V(0, 0)); |
| 318 | SR(VID_FIR_COEF_V(0, 1)); |
| 319 | SR(VID_FIR_COEF_V(0, 2)); |
| 320 | SR(VID_FIR_COEF_V(0, 3)); |
| 321 | SR(VID_FIR_COEF_V(0, 4)); |
| 322 | SR(VID_FIR_COEF_V(0, 5)); |
| 323 | SR(VID_FIR_COEF_V(0, 6)); |
| 324 | SR(VID_FIR_COEF_V(0, 7)); |
| 325 | |
| 326 | SR(VID_PRELOAD(0)); |
| 327 | |
| 328 | /* VID2 */ |
| 329 | SR(VID_BA0(1)); |
| 330 | SR(VID_BA1(1)); |
| 331 | SR(VID_POSITION(1)); |
| 332 | SR(VID_SIZE(1)); |
| 333 | SR(VID_ATTRIBUTES(1)); |
| 334 | SR(VID_FIFO_THRESHOLD(1)); |
| 335 | SR(VID_ROW_INC(1)); |
| 336 | SR(VID_PIXEL_INC(1)); |
| 337 | SR(VID_FIR(1)); |
| 338 | SR(VID_PICTURE_SIZE(1)); |
| 339 | SR(VID_ACCU0(1)); |
| 340 | SR(VID_ACCU1(1)); |
| 341 | |
| 342 | SR(VID_FIR_COEF_H(1, 0)); |
| 343 | SR(VID_FIR_COEF_H(1, 1)); |
| 344 | SR(VID_FIR_COEF_H(1, 2)); |
| 345 | SR(VID_FIR_COEF_H(1, 3)); |
| 346 | SR(VID_FIR_COEF_H(1, 4)); |
| 347 | SR(VID_FIR_COEF_H(1, 5)); |
| 348 | SR(VID_FIR_COEF_H(1, 6)); |
| 349 | SR(VID_FIR_COEF_H(1, 7)); |
| 350 | |
| 351 | SR(VID_FIR_COEF_HV(1, 0)); |
| 352 | SR(VID_FIR_COEF_HV(1, 1)); |
| 353 | SR(VID_FIR_COEF_HV(1, 2)); |
| 354 | SR(VID_FIR_COEF_HV(1, 3)); |
| 355 | SR(VID_FIR_COEF_HV(1, 4)); |
| 356 | SR(VID_FIR_COEF_HV(1, 5)); |
| 357 | SR(VID_FIR_COEF_HV(1, 6)); |
| 358 | SR(VID_FIR_COEF_HV(1, 7)); |
| 359 | |
| 360 | SR(VID_CONV_COEF(1, 0)); |
| 361 | SR(VID_CONV_COEF(1, 1)); |
| 362 | SR(VID_CONV_COEF(1, 2)); |
| 363 | SR(VID_CONV_COEF(1, 3)); |
| 364 | SR(VID_CONV_COEF(1, 4)); |
| 365 | |
| 366 | SR(VID_FIR_COEF_V(1, 0)); |
| 367 | SR(VID_FIR_COEF_V(1, 1)); |
| 368 | SR(VID_FIR_COEF_V(1, 2)); |
| 369 | SR(VID_FIR_COEF_V(1, 3)); |
| 370 | SR(VID_FIR_COEF_V(1, 4)); |
| 371 | SR(VID_FIR_COEF_V(1, 5)); |
| 372 | SR(VID_FIR_COEF_V(1, 6)); |
| 373 | SR(VID_FIR_COEF_V(1, 7)); |
| 374 | |
| 375 | SR(VID_PRELOAD(1)); |
| 376 | } |
| 377 | |
| 378 | void dispc_restore_context(void) |
| 379 | { |
| 380 | RR(SYSCONFIG); |
Ville Syrjälä | 75c7d59 | 2010-03-05 01:13:11 +0200 | [diff] [blame] | 381 | /*RR(IRQENABLE);*/ |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 382 | /*RR(CONTROL);*/ |
| 383 | RR(CONFIG); |
Sumit Semwal | 8613b00 | 2010-12-02 11:27:09 +0000 | [diff] [blame] | 384 | RR(DEFAULT_COLOR(0)); |
| 385 | RR(DEFAULT_COLOR(1)); |
| 386 | RR(TRANS_COLOR(0)); |
| 387 | RR(TRANS_COLOR(1)); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 388 | RR(LINE_NUMBER); |
Sumit Semwal | 8613b00 | 2010-12-02 11:27:09 +0000 | [diff] [blame] | 389 | RR(TIMING_H(0)); |
| 390 | RR(TIMING_V(0)); |
| 391 | RR(POL_FREQ(0)); |
| 392 | RR(DIVISOR(0)); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 393 | RR(GLOBAL_ALPHA); |
| 394 | RR(SIZE_DIG); |
Sumit Semwal | 8613b00 | 2010-12-02 11:27:09 +0000 | [diff] [blame] | 395 | RR(SIZE_LCD(0)); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 396 | if (dss_has_feature(FEAT_MGR_LCD2)) { |
| 397 | RR(DEFAULT_COLOR(2)); |
| 398 | RR(TRANS_COLOR(2)); |
| 399 | RR(SIZE_LCD(2)); |
| 400 | RR(TIMING_H(2)); |
| 401 | RR(TIMING_V(2)); |
| 402 | RR(POL_FREQ(2)); |
| 403 | RR(DIVISOR(2)); |
| 404 | RR(CONFIG2); |
| 405 | } |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 406 | |
| 407 | RR(GFX_BA0); |
| 408 | RR(GFX_BA1); |
| 409 | RR(GFX_POSITION); |
| 410 | RR(GFX_SIZE); |
| 411 | RR(GFX_ATTRIBUTES); |
| 412 | RR(GFX_FIFO_THRESHOLD); |
| 413 | RR(GFX_ROW_INC); |
| 414 | RR(GFX_PIXEL_INC); |
| 415 | RR(GFX_WINDOW_SKIP); |
| 416 | RR(GFX_TABLE_BA); |
| 417 | |
Sumit Semwal | 8613b00 | 2010-12-02 11:27:09 +0000 | [diff] [blame] | 418 | RR(DATA_CYCLE1(0)); |
| 419 | RR(DATA_CYCLE2(0)); |
| 420 | RR(DATA_CYCLE3(0)); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 421 | |
Sumit Semwal | 8613b00 | 2010-12-02 11:27:09 +0000 | [diff] [blame] | 422 | RR(CPR_COEF_R(0)); |
| 423 | RR(CPR_COEF_G(0)); |
| 424 | RR(CPR_COEF_B(0)); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 425 | if (dss_has_feature(FEAT_MGR_LCD2)) { |
| 426 | RR(DATA_CYCLE1(2)); |
| 427 | RR(DATA_CYCLE2(2)); |
| 428 | RR(DATA_CYCLE3(2)); |
| 429 | |
| 430 | RR(CPR_COEF_B(2)); |
| 431 | RR(CPR_COEF_G(2)); |
| 432 | RR(CPR_COEF_R(2)); |
| 433 | } |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 434 | |
| 435 | RR(GFX_PRELOAD); |
| 436 | |
| 437 | /* VID1 */ |
| 438 | RR(VID_BA0(0)); |
| 439 | RR(VID_BA1(0)); |
| 440 | RR(VID_POSITION(0)); |
| 441 | RR(VID_SIZE(0)); |
| 442 | RR(VID_ATTRIBUTES(0)); |
| 443 | RR(VID_FIFO_THRESHOLD(0)); |
| 444 | RR(VID_ROW_INC(0)); |
| 445 | RR(VID_PIXEL_INC(0)); |
| 446 | RR(VID_FIR(0)); |
| 447 | RR(VID_PICTURE_SIZE(0)); |
| 448 | RR(VID_ACCU0(0)); |
| 449 | RR(VID_ACCU1(0)); |
| 450 | |
| 451 | RR(VID_FIR_COEF_H(0, 0)); |
| 452 | RR(VID_FIR_COEF_H(0, 1)); |
| 453 | RR(VID_FIR_COEF_H(0, 2)); |
| 454 | RR(VID_FIR_COEF_H(0, 3)); |
| 455 | RR(VID_FIR_COEF_H(0, 4)); |
| 456 | RR(VID_FIR_COEF_H(0, 5)); |
| 457 | RR(VID_FIR_COEF_H(0, 6)); |
| 458 | RR(VID_FIR_COEF_H(0, 7)); |
| 459 | |
| 460 | RR(VID_FIR_COEF_HV(0, 0)); |
| 461 | RR(VID_FIR_COEF_HV(0, 1)); |
| 462 | RR(VID_FIR_COEF_HV(0, 2)); |
| 463 | RR(VID_FIR_COEF_HV(0, 3)); |
| 464 | RR(VID_FIR_COEF_HV(0, 4)); |
| 465 | RR(VID_FIR_COEF_HV(0, 5)); |
| 466 | RR(VID_FIR_COEF_HV(0, 6)); |
| 467 | RR(VID_FIR_COEF_HV(0, 7)); |
| 468 | |
| 469 | RR(VID_CONV_COEF(0, 0)); |
| 470 | RR(VID_CONV_COEF(0, 1)); |
| 471 | RR(VID_CONV_COEF(0, 2)); |
| 472 | RR(VID_CONV_COEF(0, 3)); |
| 473 | RR(VID_CONV_COEF(0, 4)); |
| 474 | |
| 475 | RR(VID_FIR_COEF_V(0, 0)); |
| 476 | RR(VID_FIR_COEF_V(0, 1)); |
| 477 | RR(VID_FIR_COEF_V(0, 2)); |
| 478 | RR(VID_FIR_COEF_V(0, 3)); |
| 479 | RR(VID_FIR_COEF_V(0, 4)); |
| 480 | RR(VID_FIR_COEF_V(0, 5)); |
| 481 | RR(VID_FIR_COEF_V(0, 6)); |
| 482 | RR(VID_FIR_COEF_V(0, 7)); |
| 483 | |
| 484 | RR(VID_PRELOAD(0)); |
| 485 | |
| 486 | /* VID2 */ |
| 487 | RR(VID_BA0(1)); |
| 488 | RR(VID_BA1(1)); |
| 489 | RR(VID_POSITION(1)); |
| 490 | RR(VID_SIZE(1)); |
| 491 | RR(VID_ATTRIBUTES(1)); |
| 492 | RR(VID_FIFO_THRESHOLD(1)); |
| 493 | RR(VID_ROW_INC(1)); |
| 494 | RR(VID_PIXEL_INC(1)); |
| 495 | RR(VID_FIR(1)); |
| 496 | RR(VID_PICTURE_SIZE(1)); |
| 497 | RR(VID_ACCU0(1)); |
| 498 | RR(VID_ACCU1(1)); |
| 499 | |
| 500 | RR(VID_FIR_COEF_H(1, 0)); |
| 501 | RR(VID_FIR_COEF_H(1, 1)); |
| 502 | RR(VID_FIR_COEF_H(1, 2)); |
| 503 | RR(VID_FIR_COEF_H(1, 3)); |
| 504 | RR(VID_FIR_COEF_H(1, 4)); |
| 505 | RR(VID_FIR_COEF_H(1, 5)); |
| 506 | RR(VID_FIR_COEF_H(1, 6)); |
| 507 | RR(VID_FIR_COEF_H(1, 7)); |
| 508 | |
| 509 | RR(VID_FIR_COEF_HV(1, 0)); |
| 510 | RR(VID_FIR_COEF_HV(1, 1)); |
| 511 | RR(VID_FIR_COEF_HV(1, 2)); |
| 512 | RR(VID_FIR_COEF_HV(1, 3)); |
| 513 | RR(VID_FIR_COEF_HV(1, 4)); |
| 514 | RR(VID_FIR_COEF_HV(1, 5)); |
| 515 | RR(VID_FIR_COEF_HV(1, 6)); |
| 516 | RR(VID_FIR_COEF_HV(1, 7)); |
| 517 | |
| 518 | RR(VID_CONV_COEF(1, 0)); |
| 519 | RR(VID_CONV_COEF(1, 1)); |
| 520 | RR(VID_CONV_COEF(1, 2)); |
| 521 | RR(VID_CONV_COEF(1, 3)); |
| 522 | RR(VID_CONV_COEF(1, 4)); |
| 523 | |
| 524 | RR(VID_FIR_COEF_V(1, 0)); |
| 525 | RR(VID_FIR_COEF_V(1, 1)); |
| 526 | RR(VID_FIR_COEF_V(1, 2)); |
| 527 | RR(VID_FIR_COEF_V(1, 3)); |
| 528 | RR(VID_FIR_COEF_V(1, 4)); |
| 529 | RR(VID_FIR_COEF_V(1, 5)); |
| 530 | RR(VID_FIR_COEF_V(1, 6)); |
| 531 | RR(VID_FIR_COEF_V(1, 7)); |
| 532 | |
| 533 | RR(VID_PRELOAD(1)); |
| 534 | |
| 535 | /* enable last, because LCD & DIGIT enable are here */ |
| 536 | RR(CONTROL); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 537 | if (dss_has_feature(FEAT_MGR_LCD2)) |
| 538 | RR(CONTROL2); |
Ville Syrjälä | 75c7d59 | 2010-03-05 01:13:11 +0200 | [diff] [blame] | 539 | /* clear spurious SYNC_LOST_DIGIT interrupts */ |
| 540 | dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT); |
| 541 | |
| 542 | /* |
| 543 | * enable last so IRQs won't trigger before |
| 544 | * the context is fully restored |
| 545 | */ |
| 546 | RR(IRQENABLE); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | #undef SR |
| 550 | #undef RR |
| 551 | |
| 552 | static inline void enable_clocks(bool enable) |
| 553 | { |
| 554 | if (enable) |
| 555 | dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK1); |
| 556 | else |
| 557 | dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK1); |
| 558 | } |
| 559 | |
| 560 | bool dispc_go_busy(enum omap_channel channel) |
| 561 | { |
| 562 | int bit; |
| 563 | |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 564 | if (channel == OMAP_DSS_CHANNEL_LCD || |
| 565 | channel == OMAP_DSS_CHANNEL_LCD2) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 566 | bit = 5; /* GOLCD */ |
| 567 | else |
| 568 | bit = 6; /* GODIGIT */ |
| 569 | |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 570 | if (channel == OMAP_DSS_CHANNEL_LCD2) |
| 571 | return REG_GET(DISPC_CONTROL2, bit, bit) == 1; |
| 572 | else |
| 573 | return REG_GET(DISPC_CONTROL, bit, bit) == 1; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | void dispc_go(enum omap_channel channel) |
| 577 | { |
| 578 | int bit; |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 579 | bool enable_bit, go_bit; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 580 | |
| 581 | enable_clocks(1); |
| 582 | |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 583 | if (channel == OMAP_DSS_CHANNEL_LCD || |
| 584 | channel == OMAP_DSS_CHANNEL_LCD2) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 585 | bit = 0; /* LCDENABLE */ |
| 586 | else |
| 587 | bit = 1; /* DIGITALENABLE */ |
| 588 | |
| 589 | /* if the channel is not enabled, we don't need GO */ |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 590 | if (channel == OMAP_DSS_CHANNEL_LCD2) |
| 591 | enable_bit = REG_GET(DISPC_CONTROL2, bit, bit) == 1; |
| 592 | else |
| 593 | enable_bit = REG_GET(DISPC_CONTROL, bit, bit) == 1; |
| 594 | |
| 595 | if (!enable_bit) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 596 | goto end; |
| 597 | |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 598 | if (channel == OMAP_DSS_CHANNEL_LCD || |
| 599 | channel == OMAP_DSS_CHANNEL_LCD2) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 600 | bit = 5; /* GOLCD */ |
| 601 | else |
| 602 | bit = 6; /* GODIGIT */ |
| 603 | |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 604 | if (channel == OMAP_DSS_CHANNEL_LCD2) |
| 605 | go_bit = REG_GET(DISPC_CONTROL2, bit, bit) == 1; |
| 606 | else |
| 607 | go_bit = REG_GET(DISPC_CONTROL, bit, bit) == 1; |
| 608 | |
| 609 | if (go_bit) { |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 610 | DSSERR("GO bit not down for channel %d\n", channel); |
| 611 | goto end; |
| 612 | } |
| 613 | |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 614 | DSSDBG("GO %s\n", channel == OMAP_DSS_CHANNEL_LCD ? "LCD" : |
| 615 | (channel == OMAP_DSS_CHANNEL_LCD2 ? "LCD2" : "DIGIT")); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 616 | |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 617 | if (channel == OMAP_DSS_CHANNEL_LCD2) |
| 618 | REG_FLD_MOD(DISPC_CONTROL2, 1, bit, bit); |
| 619 | else |
| 620 | REG_FLD_MOD(DISPC_CONTROL, 1, bit, bit); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 621 | end: |
| 622 | enable_clocks(0); |
| 623 | } |
| 624 | |
| 625 | static void _dispc_write_firh_reg(enum omap_plane plane, int reg, u32 value) |
| 626 | { |
| 627 | BUG_ON(plane == OMAP_DSS_GFX); |
| 628 | |
| 629 | dispc_write_reg(DISPC_VID_FIR_COEF_H(plane-1, reg), value); |
| 630 | } |
| 631 | |
| 632 | static void _dispc_write_firhv_reg(enum omap_plane plane, int reg, u32 value) |
| 633 | { |
| 634 | BUG_ON(plane == OMAP_DSS_GFX); |
| 635 | |
| 636 | dispc_write_reg(DISPC_VID_FIR_COEF_HV(plane-1, reg), value); |
| 637 | } |
| 638 | |
| 639 | static void _dispc_write_firv_reg(enum omap_plane plane, int reg, u32 value) |
| 640 | { |
| 641 | BUG_ON(plane == OMAP_DSS_GFX); |
| 642 | |
| 643 | dispc_write_reg(DISPC_VID_FIR_COEF_V(plane-1, reg), value); |
| 644 | } |
| 645 | |
| 646 | static void _dispc_set_scale_coef(enum omap_plane plane, int hscaleup, |
| 647 | int vscaleup, int five_taps) |
| 648 | { |
| 649 | /* Coefficients for horizontal up-sampling */ |
Grazvydas Ignotas | 66be8f6 | 2010-08-24 15:18:43 +0200 | [diff] [blame] | 650 | static const struct dispc_h_coef coef_hup[8] = { |
| 651 | { 0, 0, 128, 0, 0 }, |
| 652 | { -1, 13, 124, -8, 0 }, |
| 653 | { -2, 30, 112, -11, -1 }, |
| 654 | { -5, 51, 95, -11, -2 }, |
| 655 | { 0, -9, 73, 73, -9 }, |
| 656 | { -2, -11, 95, 51, -5 }, |
| 657 | { -1, -11, 112, 30, -2 }, |
| 658 | { 0, -8, 124, 13, -1 }, |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 659 | }; |
| 660 | |
| 661 | /* Coefficients for vertical up-sampling */ |
Grazvydas Ignotas | 66be8f6 | 2010-08-24 15:18:43 +0200 | [diff] [blame] | 662 | static const struct dispc_v_coef coef_vup_3tap[8] = { |
| 663 | { 0, 0, 128, 0, 0 }, |
| 664 | { 0, 3, 123, 2, 0 }, |
| 665 | { 0, 12, 111, 5, 0 }, |
| 666 | { 0, 32, 89, 7, 0 }, |
| 667 | { 0, 0, 64, 64, 0 }, |
| 668 | { 0, 7, 89, 32, 0 }, |
| 669 | { 0, 5, 111, 12, 0 }, |
| 670 | { 0, 2, 123, 3, 0 }, |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 671 | }; |
| 672 | |
Grazvydas Ignotas | 66be8f6 | 2010-08-24 15:18:43 +0200 | [diff] [blame] | 673 | static const struct dispc_v_coef coef_vup_5tap[8] = { |
| 674 | { 0, 0, 128, 0, 0 }, |
| 675 | { -1, 13, 124, -8, 0 }, |
| 676 | { -2, 30, 112, -11, -1 }, |
| 677 | { -5, 51, 95, -11, -2 }, |
| 678 | { 0, -9, 73, 73, -9 }, |
| 679 | { -2, -11, 95, 51, -5 }, |
| 680 | { -1, -11, 112, 30, -2 }, |
| 681 | { 0, -8, 124, 13, -1 }, |
| 682 | }; |
| 683 | |
| 684 | /* Coefficients for horizontal down-sampling */ |
| 685 | static const struct dispc_h_coef coef_hdown[8] = { |
| 686 | { 0, 36, 56, 36, 0 }, |
| 687 | { 4, 40, 55, 31, -2 }, |
| 688 | { 8, 44, 54, 27, -5 }, |
| 689 | { 12, 48, 53, 22, -7 }, |
| 690 | { -9, 17, 52, 51, 17 }, |
| 691 | { -7, 22, 53, 48, 12 }, |
| 692 | { -5, 27, 54, 44, 8 }, |
| 693 | { -2, 31, 55, 40, 4 }, |
| 694 | }; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 695 | |
| 696 | /* Coefficients for vertical down-sampling */ |
Grazvydas Ignotas | 66be8f6 | 2010-08-24 15:18:43 +0200 | [diff] [blame] | 697 | static const struct dispc_v_coef coef_vdown_3tap[8] = { |
| 698 | { 0, 36, 56, 36, 0 }, |
| 699 | { 0, 40, 57, 31, 0 }, |
| 700 | { 0, 45, 56, 27, 0 }, |
| 701 | { 0, 50, 55, 23, 0 }, |
| 702 | { 0, 18, 55, 55, 0 }, |
| 703 | { 0, 23, 55, 50, 0 }, |
| 704 | { 0, 27, 56, 45, 0 }, |
| 705 | { 0, 31, 57, 40, 0 }, |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 706 | }; |
| 707 | |
Grazvydas Ignotas | 66be8f6 | 2010-08-24 15:18:43 +0200 | [diff] [blame] | 708 | static const struct dispc_v_coef coef_vdown_5tap[8] = { |
| 709 | { 0, 36, 56, 36, 0 }, |
| 710 | { 4, 40, 55, 31, -2 }, |
| 711 | { 8, 44, 54, 27, -5 }, |
| 712 | { 12, 48, 53, 22, -7 }, |
| 713 | { -9, 17, 52, 51, 17 }, |
| 714 | { -7, 22, 53, 48, 12 }, |
| 715 | { -5, 27, 54, 44, 8 }, |
| 716 | { -2, 31, 55, 40, 4 }, |
| 717 | }; |
| 718 | |
| 719 | const struct dispc_h_coef *h_coef; |
| 720 | const struct dispc_v_coef *v_coef; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 721 | int i; |
| 722 | |
| 723 | if (hscaleup) |
| 724 | h_coef = coef_hup; |
| 725 | else |
| 726 | h_coef = coef_hdown; |
| 727 | |
Grazvydas Ignotas | 66be8f6 | 2010-08-24 15:18:43 +0200 | [diff] [blame] | 728 | if (vscaleup) |
| 729 | v_coef = five_taps ? coef_vup_5tap : coef_vup_3tap; |
| 730 | else |
| 731 | v_coef = five_taps ? coef_vdown_5tap : coef_vdown_3tap; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 732 | |
| 733 | for (i = 0; i < 8; i++) { |
| 734 | u32 h, hv; |
| 735 | |
Grazvydas Ignotas | 66be8f6 | 2010-08-24 15:18:43 +0200 | [diff] [blame] | 736 | h = FLD_VAL(h_coef[i].hc0, 7, 0) |
| 737 | | FLD_VAL(h_coef[i].hc1, 15, 8) |
| 738 | | FLD_VAL(h_coef[i].hc2, 23, 16) |
| 739 | | FLD_VAL(h_coef[i].hc3, 31, 24); |
| 740 | hv = FLD_VAL(h_coef[i].hc4, 7, 0) |
| 741 | | FLD_VAL(v_coef[i].vc0, 15, 8) |
| 742 | | FLD_VAL(v_coef[i].vc1, 23, 16) |
| 743 | | FLD_VAL(v_coef[i].vc2, 31, 24); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 744 | |
| 745 | _dispc_write_firh_reg(plane, i, h); |
| 746 | _dispc_write_firhv_reg(plane, i, hv); |
| 747 | } |
| 748 | |
Grazvydas Ignotas | 66be8f6 | 2010-08-24 15:18:43 +0200 | [diff] [blame] | 749 | if (five_taps) { |
| 750 | for (i = 0; i < 8; i++) { |
| 751 | u32 v; |
| 752 | v = FLD_VAL(v_coef[i].vc00, 7, 0) |
| 753 | | FLD_VAL(v_coef[i].vc22, 15, 8); |
| 754 | _dispc_write_firv_reg(plane, i, v); |
| 755 | } |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 756 | } |
| 757 | } |
| 758 | |
| 759 | static void _dispc_setup_color_conv_coef(void) |
| 760 | { |
| 761 | const struct color_conv_coef { |
| 762 | int ry, rcr, rcb, gy, gcr, gcb, by, bcr, bcb; |
| 763 | int full_range; |
| 764 | } ctbl_bt601_5 = { |
| 765 | 298, 409, 0, 298, -208, -100, 298, 0, 517, 0, |
| 766 | }; |
| 767 | |
| 768 | const struct color_conv_coef *ct; |
| 769 | |
| 770 | #define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0)) |
| 771 | |
| 772 | ct = &ctbl_bt601_5; |
| 773 | |
| 774 | dispc_write_reg(DISPC_VID_CONV_COEF(0, 0), CVAL(ct->rcr, ct->ry)); |
| 775 | dispc_write_reg(DISPC_VID_CONV_COEF(0, 1), CVAL(ct->gy, ct->rcb)); |
| 776 | dispc_write_reg(DISPC_VID_CONV_COEF(0, 2), CVAL(ct->gcb, ct->gcr)); |
| 777 | dispc_write_reg(DISPC_VID_CONV_COEF(0, 3), CVAL(ct->bcr, ct->by)); |
| 778 | dispc_write_reg(DISPC_VID_CONV_COEF(0, 4), CVAL(0, ct->bcb)); |
| 779 | |
| 780 | dispc_write_reg(DISPC_VID_CONV_COEF(1, 0), CVAL(ct->rcr, ct->ry)); |
| 781 | dispc_write_reg(DISPC_VID_CONV_COEF(1, 1), CVAL(ct->gy, ct->rcb)); |
| 782 | dispc_write_reg(DISPC_VID_CONV_COEF(1, 2), CVAL(ct->gcb, ct->gcr)); |
| 783 | dispc_write_reg(DISPC_VID_CONV_COEF(1, 3), CVAL(ct->bcr, ct->by)); |
| 784 | dispc_write_reg(DISPC_VID_CONV_COEF(1, 4), CVAL(0, ct->bcb)); |
| 785 | |
| 786 | #undef CVAL |
| 787 | |
| 788 | REG_FLD_MOD(DISPC_VID_ATTRIBUTES(0), ct->full_range, 11, 11); |
| 789 | REG_FLD_MOD(DISPC_VID_ATTRIBUTES(1), ct->full_range, 11, 11); |
| 790 | } |
| 791 | |
| 792 | |
| 793 | static void _dispc_set_plane_ba0(enum omap_plane plane, u32 paddr) |
| 794 | { |
| 795 | const struct dispc_reg ba0_reg[] = { DISPC_GFX_BA0, |
| 796 | DISPC_VID_BA0(0), |
| 797 | DISPC_VID_BA0(1) }; |
| 798 | |
| 799 | dispc_write_reg(ba0_reg[plane], paddr); |
| 800 | } |
| 801 | |
| 802 | static void _dispc_set_plane_ba1(enum omap_plane plane, u32 paddr) |
| 803 | { |
| 804 | const struct dispc_reg ba1_reg[] = { DISPC_GFX_BA1, |
| 805 | DISPC_VID_BA1(0), |
| 806 | DISPC_VID_BA1(1) }; |
| 807 | |
| 808 | dispc_write_reg(ba1_reg[plane], paddr); |
| 809 | } |
| 810 | |
| 811 | static void _dispc_set_plane_pos(enum omap_plane plane, int x, int y) |
| 812 | { |
| 813 | const struct dispc_reg pos_reg[] = { DISPC_GFX_POSITION, |
| 814 | DISPC_VID_POSITION(0), |
| 815 | DISPC_VID_POSITION(1) }; |
| 816 | |
| 817 | u32 val = FLD_VAL(y, 26, 16) | FLD_VAL(x, 10, 0); |
| 818 | dispc_write_reg(pos_reg[plane], val); |
| 819 | } |
| 820 | |
| 821 | static void _dispc_set_pic_size(enum omap_plane plane, int width, int height) |
| 822 | { |
| 823 | const struct dispc_reg siz_reg[] = { DISPC_GFX_SIZE, |
| 824 | DISPC_VID_PICTURE_SIZE(0), |
| 825 | DISPC_VID_PICTURE_SIZE(1) }; |
| 826 | u32 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0); |
| 827 | dispc_write_reg(siz_reg[plane], val); |
| 828 | } |
| 829 | |
| 830 | static void _dispc_set_vid_size(enum omap_plane plane, int width, int height) |
| 831 | { |
| 832 | u32 val; |
| 833 | const struct dispc_reg vsi_reg[] = { DISPC_VID_SIZE(0), |
| 834 | DISPC_VID_SIZE(1) }; |
| 835 | |
| 836 | BUG_ON(plane == OMAP_DSS_GFX); |
| 837 | |
| 838 | val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0); |
| 839 | dispc_write_reg(vsi_reg[plane-1], val); |
| 840 | } |
| 841 | |
Rajkumar N | fd28a39 | 2010-11-04 12:28:42 +0100 | [diff] [blame] | 842 | static void _dispc_set_pre_mult_alpha(enum omap_plane plane, bool enable) |
| 843 | { |
| 844 | if (!dss_has_feature(FEAT_PRE_MULT_ALPHA)) |
| 845 | return; |
| 846 | |
| 847 | if (!dss_has_feature(FEAT_GLOBAL_ALPHA_VID1) && |
| 848 | plane == OMAP_DSS_VIDEO1) |
| 849 | return; |
| 850 | |
| 851 | REG_FLD_MOD(dispc_reg_att[plane], enable ? 1 : 0, 28, 28); |
| 852 | } |
| 853 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 854 | static void _dispc_setup_global_alpha(enum omap_plane plane, u8 global_alpha) |
| 855 | { |
Archit Taneja | a0acb55 | 2010-09-15 19:20:00 +0530 | [diff] [blame] | 856 | if (!dss_has_feature(FEAT_GLOBAL_ALPHA)) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 857 | return; |
| 858 | |
Rajkumar N | fd28a39 | 2010-11-04 12:28:42 +0100 | [diff] [blame] | 859 | if (!dss_has_feature(FEAT_GLOBAL_ALPHA_VID1) && |
| 860 | plane == OMAP_DSS_VIDEO1) |
| 861 | return; |
Archit Taneja | a0acb55 | 2010-09-15 19:20:00 +0530 | [diff] [blame] | 862 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 863 | if (plane == OMAP_DSS_GFX) |
| 864 | REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, 7, 0); |
| 865 | else if (plane == OMAP_DSS_VIDEO2) |
| 866 | REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, 23, 16); |
| 867 | } |
| 868 | |
| 869 | static void _dispc_set_pix_inc(enum omap_plane plane, s32 inc) |
| 870 | { |
| 871 | const struct dispc_reg ri_reg[] = { DISPC_GFX_PIXEL_INC, |
| 872 | DISPC_VID_PIXEL_INC(0), |
| 873 | DISPC_VID_PIXEL_INC(1) }; |
| 874 | |
| 875 | dispc_write_reg(ri_reg[plane], inc); |
| 876 | } |
| 877 | |
| 878 | static void _dispc_set_row_inc(enum omap_plane plane, s32 inc) |
| 879 | { |
| 880 | const struct dispc_reg ri_reg[] = { DISPC_GFX_ROW_INC, |
| 881 | DISPC_VID_ROW_INC(0), |
| 882 | DISPC_VID_ROW_INC(1) }; |
| 883 | |
| 884 | dispc_write_reg(ri_reg[plane], inc); |
| 885 | } |
| 886 | |
| 887 | static void _dispc_set_color_mode(enum omap_plane plane, |
| 888 | enum omap_color_mode color_mode) |
| 889 | { |
| 890 | u32 m = 0; |
| 891 | |
| 892 | switch (color_mode) { |
| 893 | case OMAP_DSS_COLOR_CLUT1: |
| 894 | m = 0x0; break; |
| 895 | case OMAP_DSS_COLOR_CLUT2: |
| 896 | m = 0x1; break; |
| 897 | case OMAP_DSS_COLOR_CLUT4: |
| 898 | m = 0x2; break; |
| 899 | case OMAP_DSS_COLOR_CLUT8: |
| 900 | m = 0x3; break; |
| 901 | case OMAP_DSS_COLOR_RGB12U: |
| 902 | m = 0x4; break; |
| 903 | case OMAP_DSS_COLOR_ARGB16: |
| 904 | m = 0x5; break; |
| 905 | case OMAP_DSS_COLOR_RGB16: |
| 906 | m = 0x6; break; |
| 907 | case OMAP_DSS_COLOR_RGB24U: |
| 908 | m = 0x8; break; |
| 909 | case OMAP_DSS_COLOR_RGB24P: |
| 910 | m = 0x9; break; |
| 911 | case OMAP_DSS_COLOR_YUV2: |
| 912 | m = 0xa; break; |
| 913 | case OMAP_DSS_COLOR_UYVY: |
| 914 | m = 0xb; break; |
| 915 | case OMAP_DSS_COLOR_ARGB32: |
| 916 | m = 0xc; break; |
| 917 | case OMAP_DSS_COLOR_RGBA32: |
| 918 | m = 0xd; break; |
| 919 | case OMAP_DSS_COLOR_RGBX32: |
| 920 | m = 0xe; break; |
| 921 | default: |
| 922 | BUG(); break; |
| 923 | } |
| 924 | |
| 925 | REG_FLD_MOD(dispc_reg_att[plane], m, 4, 1); |
| 926 | } |
| 927 | |
| 928 | static void _dispc_set_channel_out(enum omap_plane plane, |
| 929 | enum omap_channel channel) |
| 930 | { |
| 931 | int shift; |
| 932 | u32 val; |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 933 | int chan = 0, chan2 = 0; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 934 | |
| 935 | switch (plane) { |
| 936 | case OMAP_DSS_GFX: |
| 937 | shift = 8; |
| 938 | break; |
| 939 | case OMAP_DSS_VIDEO1: |
| 940 | case OMAP_DSS_VIDEO2: |
| 941 | shift = 16; |
| 942 | break; |
| 943 | default: |
| 944 | BUG(); |
| 945 | return; |
| 946 | } |
| 947 | |
| 948 | val = dispc_read_reg(dispc_reg_att[plane]); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 949 | if (dss_has_feature(FEAT_MGR_LCD2)) { |
| 950 | switch (channel) { |
| 951 | case OMAP_DSS_CHANNEL_LCD: |
| 952 | chan = 0; |
| 953 | chan2 = 0; |
| 954 | break; |
| 955 | case OMAP_DSS_CHANNEL_DIGIT: |
| 956 | chan = 1; |
| 957 | chan2 = 0; |
| 958 | break; |
| 959 | case OMAP_DSS_CHANNEL_LCD2: |
| 960 | chan = 0; |
| 961 | chan2 = 1; |
| 962 | break; |
| 963 | default: |
| 964 | BUG(); |
| 965 | } |
| 966 | |
| 967 | val = FLD_MOD(val, chan, shift, shift); |
| 968 | val = FLD_MOD(val, chan2, 31, 30); |
| 969 | } else { |
| 970 | val = FLD_MOD(val, channel, shift, shift); |
| 971 | } |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 972 | dispc_write_reg(dispc_reg_att[plane], val); |
| 973 | } |
| 974 | |
| 975 | void dispc_set_burst_size(enum omap_plane plane, |
| 976 | enum omap_burst_size burst_size) |
| 977 | { |
| 978 | int shift; |
| 979 | u32 val; |
| 980 | |
| 981 | enable_clocks(1); |
| 982 | |
| 983 | switch (plane) { |
| 984 | case OMAP_DSS_GFX: |
| 985 | shift = 6; |
| 986 | break; |
| 987 | case OMAP_DSS_VIDEO1: |
| 988 | case OMAP_DSS_VIDEO2: |
| 989 | shift = 14; |
| 990 | break; |
| 991 | default: |
| 992 | BUG(); |
| 993 | return; |
| 994 | } |
| 995 | |
| 996 | val = dispc_read_reg(dispc_reg_att[plane]); |
| 997 | val = FLD_MOD(val, burst_size, shift+1, shift); |
| 998 | dispc_write_reg(dispc_reg_att[plane], val); |
| 999 | |
| 1000 | enable_clocks(0); |
| 1001 | } |
| 1002 | |
| 1003 | static void _dispc_set_vid_color_conv(enum omap_plane plane, bool enable) |
| 1004 | { |
| 1005 | u32 val; |
| 1006 | |
| 1007 | BUG_ON(plane == OMAP_DSS_GFX); |
| 1008 | |
| 1009 | val = dispc_read_reg(dispc_reg_att[plane]); |
| 1010 | val = FLD_MOD(val, enable, 9, 9); |
| 1011 | dispc_write_reg(dispc_reg_att[plane], val); |
| 1012 | } |
| 1013 | |
| 1014 | void dispc_enable_replication(enum omap_plane plane, bool enable) |
| 1015 | { |
| 1016 | int bit; |
| 1017 | |
| 1018 | if (plane == OMAP_DSS_GFX) |
| 1019 | bit = 5; |
| 1020 | else |
| 1021 | bit = 10; |
| 1022 | |
| 1023 | enable_clocks(1); |
| 1024 | REG_FLD_MOD(dispc_reg_att[plane], enable, bit, bit); |
| 1025 | enable_clocks(0); |
| 1026 | } |
| 1027 | |
Sumit Semwal | 64ba4f7 | 2010-12-02 11:27:10 +0000 | [diff] [blame] | 1028 | void dispc_set_lcd_size(enum omap_channel channel, u16 width, u16 height) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1029 | { |
| 1030 | u32 val; |
| 1031 | BUG_ON((width > (1 << 11)) || (height > (1 << 11))); |
| 1032 | val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0); |
| 1033 | enable_clocks(1); |
Sumit Semwal | 64ba4f7 | 2010-12-02 11:27:10 +0000 | [diff] [blame] | 1034 | dispc_write_reg(DISPC_SIZE_LCD(channel), val); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1035 | enable_clocks(0); |
| 1036 | } |
| 1037 | |
| 1038 | void dispc_set_digit_size(u16 width, u16 height) |
| 1039 | { |
| 1040 | u32 val; |
| 1041 | BUG_ON((width > (1 << 11)) || (height > (1 << 11))); |
| 1042 | val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0); |
| 1043 | enable_clocks(1); |
| 1044 | dispc_write_reg(DISPC_SIZE_DIG, val); |
| 1045 | enable_clocks(0); |
| 1046 | } |
| 1047 | |
| 1048 | static void dispc_read_plane_fifo_sizes(void) |
| 1049 | { |
| 1050 | const struct dispc_reg fsz_reg[] = { DISPC_GFX_FIFO_SIZE_STATUS, |
| 1051 | DISPC_VID_FIFO_SIZE_STATUS(0), |
| 1052 | DISPC_VID_FIFO_SIZE_STATUS(1) }; |
| 1053 | u32 size; |
| 1054 | int plane; |
Archit Taneja | a0acb55 | 2010-09-15 19:20:00 +0530 | [diff] [blame] | 1055 | u8 start, end; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1056 | |
| 1057 | enable_clocks(1); |
| 1058 | |
Archit Taneja | a0acb55 | 2010-09-15 19:20:00 +0530 | [diff] [blame] | 1059 | dss_feat_get_reg_field(FEAT_REG_FIFOSIZE, &start, &end); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1060 | |
Archit Taneja | a0acb55 | 2010-09-15 19:20:00 +0530 | [diff] [blame] | 1061 | for (plane = 0; plane < ARRAY_SIZE(dispc.fifo_size); ++plane) { |
| 1062 | size = FLD_GET(dispc_read_reg(fsz_reg[plane]), start, end); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1063 | dispc.fifo_size[plane] = size; |
| 1064 | } |
| 1065 | |
| 1066 | enable_clocks(0); |
| 1067 | } |
| 1068 | |
| 1069 | u32 dispc_get_plane_fifo_size(enum omap_plane plane) |
| 1070 | { |
| 1071 | return dispc.fifo_size[plane]; |
| 1072 | } |
| 1073 | |
| 1074 | void dispc_setup_plane_fifo(enum omap_plane plane, u32 low, u32 high) |
| 1075 | { |
| 1076 | const struct dispc_reg ftrs_reg[] = { DISPC_GFX_FIFO_THRESHOLD, |
| 1077 | DISPC_VID_FIFO_THRESHOLD(0), |
| 1078 | DISPC_VID_FIFO_THRESHOLD(1) }; |
Archit Taneja | a0acb55 | 2010-09-15 19:20:00 +0530 | [diff] [blame] | 1079 | u8 hi_start, hi_end, lo_start, lo_end; |
| 1080 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1081 | enable_clocks(1); |
| 1082 | |
| 1083 | DSSDBG("fifo(%d) low/high old %u/%u, new %u/%u\n", |
| 1084 | plane, |
| 1085 | REG_GET(ftrs_reg[plane], 11, 0), |
| 1086 | REG_GET(ftrs_reg[plane], 27, 16), |
| 1087 | low, high); |
| 1088 | |
Archit Taneja | a0acb55 | 2010-09-15 19:20:00 +0530 | [diff] [blame] | 1089 | dss_feat_get_reg_field(FEAT_REG_FIFOHIGHTHRESHOLD, &hi_start, &hi_end); |
| 1090 | dss_feat_get_reg_field(FEAT_REG_FIFOLOWTHRESHOLD, &lo_start, &lo_end); |
| 1091 | |
| 1092 | dispc_write_reg(ftrs_reg[plane], |
| 1093 | FLD_VAL(high, hi_start, hi_end) | |
| 1094 | FLD_VAL(low, lo_start, lo_end)); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1095 | |
| 1096 | enable_clocks(0); |
| 1097 | } |
| 1098 | |
| 1099 | void dispc_enable_fifomerge(bool enable) |
| 1100 | { |
| 1101 | enable_clocks(1); |
| 1102 | |
| 1103 | DSSDBG("FIFO merge %s\n", enable ? "enabled" : "disabled"); |
| 1104 | REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 14, 14); |
| 1105 | |
| 1106 | enable_clocks(0); |
| 1107 | } |
| 1108 | |
| 1109 | static void _dispc_set_fir(enum omap_plane plane, int hinc, int vinc) |
| 1110 | { |
| 1111 | u32 val; |
| 1112 | const struct dispc_reg fir_reg[] = { DISPC_VID_FIR(0), |
| 1113 | DISPC_VID_FIR(1) }; |
Archit Taneja | a0acb55 | 2010-09-15 19:20:00 +0530 | [diff] [blame] | 1114 | u8 hinc_start, hinc_end, vinc_start, vinc_end; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1115 | |
| 1116 | BUG_ON(plane == OMAP_DSS_GFX); |
| 1117 | |
Archit Taneja | a0acb55 | 2010-09-15 19:20:00 +0530 | [diff] [blame] | 1118 | dss_feat_get_reg_field(FEAT_REG_FIRHINC, &hinc_start, &hinc_end); |
| 1119 | dss_feat_get_reg_field(FEAT_REG_FIRVINC, &vinc_start, &vinc_end); |
| 1120 | |
| 1121 | val = FLD_VAL(vinc, vinc_start, vinc_end) | |
| 1122 | FLD_VAL(hinc, hinc_start, hinc_end); |
| 1123 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1124 | dispc_write_reg(fir_reg[plane-1], val); |
| 1125 | } |
| 1126 | |
| 1127 | static void _dispc_set_vid_accu0(enum omap_plane plane, int haccu, int vaccu) |
| 1128 | { |
| 1129 | u32 val; |
| 1130 | const struct dispc_reg ac0_reg[] = { DISPC_VID_ACCU0(0), |
| 1131 | DISPC_VID_ACCU0(1) }; |
| 1132 | |
| 1133 | BUG_ON(plane == OMAP_DSS_GFX); |
| 1134 | |
| 1135 | val = FLD_VAL(vaccu, 25, 16) | FLD_VAL(haccu, 9, 0); |
| 1136 | dispc_write_reg(ac0_reg[plane-1], val); |
| 1137 | } |
| 1138 | |
| 1139 | static void _dispc_set_vid_accu1(enum omap_plane plane, int haccu, int vaccu) |
| 1140 | { |
| 1141 | u32 val; |
| 1142 | const struct dispc_reg ac1_reg[] = { DISPC_VID_ACCU1(0), |
| 1143 | DISPC_VID_ACCU1(1) }; |
| 1144 | |
| 1145 | BUG_ON(plane == OMAP_DSS_GFX); |
| 1146 | |
| 1147 | val = FLD_VAL(vaccu, 25, 16) | FLD_VAL(haccu, 9, 0); |
| 1148 | dispc_write_reg(ac1_reg[plane-1], val); |
| 1149 | } |
| 1150 | |
| 1151 | |
| 1152 | static void _dispc_set_scaling(enum omap_plane plane, |
| 1153 | u16 orig_width, u16 orig_height, |
| 1154 | u16 out_width, u16 out_height, |
| 1155 | bool ilace, bool five_taps, |
| 1156 | bool fieldmode) |
| 1157 | { |
| 1158 | int fir_hinc; |
| 1159 | int fir_vinc; |
| 1160 | int hscaleup, vscaleup; |
| 1161 | int accu0 = 0; |
| 1162 | int accu1 = 0; |
| 1163 | u32 l; |
| 1164 | |
| 1165 | BUG_ON(plane == OMAP_DSS_GFX); |
| 1166 | |
| 1167 | hscaleup = orig_width <= out_width; |
| 1168 | vscaleup = orig_height <= out_height; |
| 1169 | |
| 1170 | _dispc_set_scale_coef(plane, hscaleup, vscaleup, five_taps); |
| 1171 | |
| 1172 | if (!orig_width || orig_width == out_width) |
| 1173 | fir_hinc = 0; |
| 1174 | else |
| 1175 | fir_hinc = 1024 * orig_width / out_width; |
| 1176 | |
| 1177 | if (!orig_height || orig_height == out_height) |
| 1178 | fir_vinc = 0; |
| 1179 | else |
| 1180 | fir_vinc = 1024 * orig_height / out_height; |
| 1181 | |
| 1182 | _dispc_set_fir(plane, fir_hinc, fir_vinc); |
| 1183 | |
| 1184 | l = dispc_read_reg(dispc_reg_att[plane]); |
| 1185 | l &= ~((0x0f << 5) | (0x3 << 21)); |
| 1186 | |
| 1187 | l |= fir_hinc ? (1 << 5) : 0; |
| 1188 | l |= fir_vinc ? (1 << 6) : 0; |
| 1189 | |
| 1190 | l |= hscaleup ? 0 : (1 << 7); |
| 1191 | l |= vscaleup ? 0 : (1 << 8); |
| 1192 | |
| 1193 | l |= five_taps ? (1 << 21) : 0; |
| 1194 | l |= five_taps ? (1 << 22) : 0; |
| 1195 | |
| 1196 | dispc_write_reg(dispc_reg_att[plane], l); |
| 1197 | |
| 1198 | /* |
| 1199 | * field 0 = even field = bottom field |
| 1200 | * field 1 = odd field = top field |
| 1201 | */ |
| 1202 | if (ilace && !fieldmode) { |
| 1203 | accu1 = 0; |
| 1204 | accu0 = (fir_vinc / 2) & 0x3ff; |
| 1205 | if (accu0 >= 1024/2) { |
| 1206 | accu1 = 1024/2; |
| 1207 | accu0 -= accu1; |
| 1208 | } |
| 1209 | } |
| 1210 | |
| 1211 | _dispc_set_vid_accu0(plane, 0, accu0); |
| 1212 | _dispc_set_vid_accu1(plane, 0, accu1); |
| 1213 | } |
| 1214 | |
| 1215 | static void _dispc_set_rotation_attrs(enum omap_plane plane, u8 rotation, |
| 1216 | bool mirroring, enum omap_color_mode color_mode) |
| 1217 | { |
| 1218 | if (color_mode == OMAP_DSS_COLOR_YUV2 || |
| 1219 | color_mode == OMAP_DSS_COLOR_UYVY) { |
| 1220 | int vidrot = 0; |
| 1221 | |
| 1222 | if (mirroring) { |
| 1223 | switch (rotation) { |
| 1224 | case OMAP_DSS_ROT_0: |
| 1225 | vidrot = 2; |
| 1226 | break; |
| 1227 | case OMAP_DSS_ROT_90: |
| 1228 | vidrot = 1; |
| 1229 | break; |
| 1230 | case OMAP_DSS_ROT_180: |
| 1231 | vidrot = 0; |
| 1232 | break; |
| 1233 | case OMAP_DSS_ROT_270: |
| 1234 | vidrot = 3; |
| 1235 | break; |
| 1236 | } |
| 1237 | } else { |
| 1238 | switch (rotation) { |
| 1239 | case OMAP_DSS_ROT_0: |
| 1240 | vidrot = 0; |
| 1241 | break; |
| 1242 | case OMAP_DSS_ROT_90: |
| 1243 | vidrot = 1; |
| 1244 | break; |
| 1245 | case OMAP_DSS_ROT_180: |
| 1246 | vidrot = 2; |
| 1247 | break; |
| 1248 | case OMAP_DSS_ROT_270: |
| 1249 | vidrot = 3; |
| 1250 | break; |
| 1251 | } |
| 1252 | } |
| 1253 | |
| 1254 | REG_FLD_MOD(dispc_reg_att[plane], vidrot, 13, 12); |
| 1255 | |
| 1256 | if (rotation == OMAP_DSS_ROT_90 || rotation == OMAP_DSS_ROT_270) |
| 1257 | REG_FLD_MOD(dispc_reg_att[plane], 0x1, 18, 18); |
| 1258 | else |
| 1259 | REG_FLD_MOD(dispc_reg_att[plane], 0x0, 18, 18); |
| 1260 | } else { |
| 1261 | REG_FLD_MOD(dispc_reg_att[plane], 0, 13, 12); |
| 1262 | REG_FLD_MOD(dispc_reg_att[plane], 0, 18, 18); |
| 1263 | } |
| 1264 | } |
| 1265 | |
| 1266 | static int color_mode_to_bpp(enum omap_color_mode color_mode) |
| 1267 | { |
| 1268 | switch (color_mode) { |
| 1269 | case OMAP_DSS_COLOR_CLUT1: |
| 1270 | return 1; |
| 1271 | case OMAP_DSS_COLOR_CLUT2: |
| 1272 | return 2; |
| 1273 | case OMAP_DSS_COLOR_CLUT4: |
| 1274 | return 4; |
| 1275 | case OMAP_DSS_COLOR_CLUT8: |
| 1276 | return 8; |
| 1277 | case OMAP_DSS_COLOR_RGB12U: |
| 1278 | case OMAP_DSS_COLOR_RGB16: |
| 1279 | case OMAP_DSS_COLOR_ARGB16: |
| 1280 | case OMAP_DSS_COLOR_YUV2: |
| 1281 | case OMAP_DSS_COLOR_UYVY: |
| 1282 | return 16; |
| 1283 | case OMAP_DSS_COLOR_RGB24P: |
| 1284 | return 24; |
| 1285 | case OMAP_DSS_COLOR_RGB24U: |
| 1286 | case OMAP_DSS_COLOR_ARGB32: |
| 1287 | case OMAP_DSS_COLOR_RGBA32: |
| 1288 | case OMAP_DSS_COLOR_RGBX32: |
| 1289 | return 32; |
| 1290 | default: |
| 1291 | BUG(); |
| 1292 | } |
| 1293 | } |
| 1294 | |
| 1295 | static s32 pixinc(int pixels, u8 ps) |
| 1296 | { |
| 1297 | if (pixels == 1) |
| 1298 | return 1; |
| 1299 | else if (pixels > 1) |
| 1300 | return 1 + (pixels - 1) * ps; |
| 1301 | else if (pixels < 0) |
| 1302 | return 1 - (-pixels + 1) * ps; |
| 1303 | else |
| 1304 | BUG(); |
| 1305 | } |
| 1306 | |
| 1307 | static void calc_vrfb_rotation_offset(u8 rotation, bool mirror, |
| 1308 | u16 screen_width, |
| 1309 | u16 width, u16 height, |
| 1310 | enum omap_color_mode color_mode, bool fieldmode, |
| 1311 | unsigned int field_offset, |
| 1312 | unsigned *offset0, unsigned *offset1, |
| 1313 | s32 *row_inc, s32 *pix_inc) |
| 1314 | { |
| 1315 | u8 ps; |
| 1316 | |
| 1317 | /* FIXME CLUT formats */ |
| 1318 | switch (color_mode) { |
| 1319 | case OMAP_DSS_COLOR_CLUT1: |
| 1320 | case OMAP_DSS_COLOR_CLUT2: |
| 1321 | case OMAP_DSS_COLOR_CLUT4: |
| 1322 | case OMAP_DSS_COLOR_CLUT8: |
| 1323 | BUG(); |
| 1324 | return; |
| 1325 | case OMAP_DSS_COLOR_YUV2: |
| 1326 | case OMAP_DSS_COLOR_UYVY: |
| 1327 | ps = 4; |
| 1328 | break; |
| 1329 | default: |
| 1330 | ps = color_mode_to_bpp(color_mode) / 8; |
| 1331 | break; |
| 1332 | } |
| 1333 | |
| 1334 | DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width, |
| 1335 | width, height); |
| 1336 | |
| 1337 | /* |
| 1338 | * field 0 = even field = bottom field |
| 1339 | * field 1 = odd field = top field |
| 1340 | */ |
| 1341 | switch (rotation + mirror * 4) { |
| 1342 | case OMAP_DSS_ROT_0: |
| 1343 | case OMAP_DSS_ROT_180: |
| 1344 | /* |
| 1345 | * If the pixel format is YUV or UYVY divide the width |
| 1346 | * of the image by 2 for 0 and 180 degree rotation. |
| 1347 | */ |
| 1348 | if (color_mode == OMAP_DSS_COLOR_YUV2 || |
| 1349 | color_mode == OMAP_DSS_COLOR_UYVY) |
| 1350 | width = width >> 1; |
| 1351 | case OMAP_DSS_ROT_90: |
| 1352 | case OMAP_DSS_ROT_270: |
| 1353 | *offset1 = 0; |
| 1354 | if (field_offset) |
| 1355 | *offset0 = field_offset * screen_width * ps; |
| 1356 | else |
| 1357 | *offset0 = 0; |
| 1358 | |
| 1359 | *row_inc = pixinc(1 + (screen_width - width) + |
| 1360 | (fieldmode ? screen_width : 0), |
| 1361 | ps); |
| 1362 | *pix_inc = pixinc(1, ps); |
| 1363 | break; |
| 1364 | |
| 1365 | case OMAP_DSS_ROT_0 + 4: |
| 1366 | case OMAP_DSS_ROT_180 + 4: |
| 1367 | /* If the pixel format is YUV or UYVY divide the width |
| 1368 | * of the image by 2 for 0 degree and 180 degree |
| 1369 | */ |
| 1370 | if (color_mode == OMAP_DSS_COLOR_YUV2 || |
| 1371 | color_mode == OMAP_DSS_COLOR_UYVY) |
| 1372 | width = width >> 1; |
| 1373 | case OMAP_DSS_ROT_90 + 4: |
| 1374 | case OMAP_DSS_ROT_270 + 4: |
| 1375 | *offset1 = 0; |
| 1376 | if (field_offset) |
| 1377 | *offset0 = field_offset * screen_width * ps; |
| 1378 | else |
| 1379 | *offset0 = 0; |
| 1380 | *row_inc = pixinc(1 - (screen_width + width) - |
| 1381 | (fieldmode ? screen_width : 0), |
| 1382 | ps); |
| 1383 | *pix_inc = pixinc(1, ps); |
| 1384 | break; |
| 1385 | |
| 1386 | default: |
| 1387 | BUG(); |
| 1388 | } |
| 1389 | } |
| 1390 | |
| 1391 | static void calc_dma_rotation_offset(u8 rotation, bool mirror, |
| 1392 | u16 screen_width, |
| 1393 | u16 width, u16 height, |
| 1394 | enum omap_color_mode color_mode, bool fieldmode, |
| 1395 | unsigned int field_offset, |
| 1396 | unsigned *offset0, unsigned *offset1, |
| 1397 | s32 *row_inc, s32 *pix_inc) |
| 1398 | { |
| 1399 | u8 ps; |
| 1400 | u16 fbw, fbh; |
| 1401 | |
| 1402 | /* FIXME CLUT formats */ |
| 1403 | switch (color_mode) { |
| 1404 | case OMAP_DSS_COLOR_CLUT1: |
| 1405 | case OMAP_DSS_COLOR_CLUT2: |
| 1406 | case OMAP_DSS_COLOR_CLUT4: |
| 1407 | case OMAP_DSS_COLOR_CLUT8: |
| 1408 | BUG(); |
| 1409 | return; |
| 1410 | default: |
| 1411 | ps = color_mode_to_bpp(color_mode) / 8; |
| 1412 | break; |
| 1413 | } |
| 1414 | |
| 1415 | DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width, |
| 1416 | width, height); |
| 1417 | |
| 1418 | /* width & height are overlay sizes, convert to fb sizes */ |
| 1419 | |
| 1420 | if (rotation == OMAP_DSS_ROT_0 || rotation == OMAP_DSS_ROT_180) { |
| 1421 | fbw = width; |
| 1422 | fbh = height; |
| 1423 | } else { |
| 1424 | fbw = height; |
| 1425 | fbh = width; |
| 1426 | } |
| 1427 | |
| 1428 | /* |
| 1429 | * field 0 = even field = bottom field |
| 1430 | * field 1 = odd field = top field |
| 1431 | */ |
| 1432 | switch (rotation + mirror * 4) { |
| 1433 | case OMAP_DSS_ROT_0: |
| 1434 | *offset1 = 0; |
| 1435 | if (field_offset) |
| 1436 | *offset0 = *offset1 + field_offset * screen_width * ps; |
| 1437 | else |
| 1438 | *offset0 = *offset1; |
| 1439 | *row_inc = pixinc(1 + (screen_width - fbw) + |
| 1440 | (fieldmode ? screen_width : 0), |
| 1441 | ps); |
| 1442 | *pix_inc = pixinc(1, ps); |
| 1443 | break; |
| 1444 | case OMAP_DSS_ROT_90: |
| 1445 | *offset1 = screen_width * (fbh - 1) * ps; |
| 1446 | if (field_offset) |
| 1447 | *offset0 = *offset1 + field_offset * ps; |
| 1448 | else |
| 1449 | *offset0 = *offset1; |
| 1450 | *row_inc = pixinc(screen_width * (fbh - 1) + 1 + |
| 1451 | (fieldmode ? 1 : 0), ps); |
| 1452 | *pix_inc = pixinc(-screen_width, ps); |
| 1453 | break; |
| 1454 | case OMAP_DSS_ROT_180: |
| 1455 | *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps; |
| 1456 | if (field_offset) |
| 1457 | *offset0 = *offset1 - field_offset * screen_width * ps; |
| 1458 | else |
| 1459 | *offset0 = *offset1; |
| 1460 | *row_inc = pixinc(-1 - |
| 1461 | (screen_width - fbw) - |
| 1462 | (fieldmode ? screen_width : 0), |
| 1463 | ps); |
| 1464 | *pix_inc = pixinc(-1, ps); |
| 1465 | break; |
| 1466 | case OMAP_DSS_ROT_270: |
| 1467 | *offset1 = (fbw - 1) * ps; |
| 1468 | if (field_offset) |
| 1469 | *offset0 = *offset1 - field_offset * ps; |
| 1470 | else |
| 1471 | *offset0 = *offset1; |
| 1472 | *row_inc = pixinc(-screen_width * (fbh - 1) - 1 - |
| 1473 | (fieldmode ? 1 : 0), ps); |
| 1474 | *pix_inc = pixinc(screen_width, ps); |
| 1475 | break; |
| 1476 | |
| 1477 | /* mirroring */ |
| 1478 | case OMAP_DSS_ROT_0 + 4: |
| 1479 | *offset1 = (fbw - 1) * ps; |
| 1480 | if (field_offset) |
| 1481 | *offset0 = *offset1 + field_offset * screen_width * ps; |
| 1482 | else |
| 1483 | *offset0 = *offset1; |
| 1484 | *row_inc = pixinc(screen_width * 2 - 1 + |
| 1485 | (fieldmode ? screen_width : 0), |
| 1486 | ps); |
| 1487 | *pix_inc = pixinc(-1, ps); |
| 1488 | break; |
| 1489 | |
| 1490 | case OMAP_DSS_ROT_90 + 4: |
| 1491 | *offset1 = 0; |
| 1492 | if (field_offset) |
| 1493 | *offset0 = *offset1 + field_offset * ps; |
| 1494 | else |
| 1495 | *offset0 = *offset1; |
| 1496 | *row_inc = pixinc(-screen_width * (fbh - 1) + 1 + |
| 1497 | (fieldmode ? 1 : 0), |
| 1498 | ps); |
| 1499 | *pix_inc = pixinc(screen_width, ps); |
| 1500 | break; |
| 1501 | |
| 1502 | case OMAP_DSS_ROT_180 + 4: |
| 1503 | *offset1 = screen_width * (fbh - 1) * ps; |
| 1504 | if (field_offset) |
| 1505 | *offset0 = *offset1 - field_offset * screen_width * ps; |
| 1506 | else |
| 1507 | *offset0 = *offset1; |
| 1508 | *row_inc = pixinc(1 - screen_width * 2 - |
| 1509 | (fieldmode ? screen_width : 0), |
| 1510 | ps); |
| 1511 | *pix_inc = pixinc(1, ps); |
| 1512 | break; |
| 1513 | |
| 1514 | case OMAP_DSS_ROT_270 + 4: |
| 1515 | *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps; |
| 1516 | if (field_offset) |
| 1517 | *offset0 = *offset1 - field_offset * ps; |
| 1518 | else |
| 1519 | *offset0 = *offset1; |
| 1520 | *row_inc = pixinc(screen_width * (fbh - 1) - 1 - |
| 1521 | (fieldmode ? 1 : 0), |
| 1522 | ps); |
| 1523 | *pix_inc = pixinc(-screen_width, ps); |
| 1524 | break; |
| 1525 | |
| 1526 | default: |
| 1527 | BUG(); |
| 1528 | } |
| 1529 | } |
| 1530 | |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 1531 | static unsigned long calc_fclk_five_taps(enum omap_channel channel, u16 width, |
| 1532 | u16 height, u16 out_width, u16 out_height, |
| 1533 | enum omap_color_mode color_mode) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1534 | { |
| 1535 | u32 fclk = 0; |
| 1536 | /* FIXME venc pclk? */ |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 1537 | u64 tmp, pclk = dispc_pclk_rate(channel); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1538 | |
| 1539 | if (height > out_height) { |
| 1540 | /* FIXME get real display PPL */ |
| 1541 | unsigned int ppl = 800; |
| 1542 | |
| 1543 | tmp = pclk * height * out_width; |
| 1544 | do_div(tmp, 2 * out_height * ppl); |
| 1545 | fclk = tmp; |
| 1546 | |
Ville Syrjälä | 2d9c559 | 2010-01-08 11:56:41 +0200 | [diff] [blame] | 1547 | if (height > 2 * out_height) { |
| 1548 | if (ppl == out_width) |
| 1549 | return 0; |
| 1550 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1551 | tmp = pclk * (height - 2 * out_height) * out_width; |
| 1552 | do_div(tmp, 2 * out_height * (ppl - out_width)); |
| 1553 | fclk = max(fclk, (u32) tmp); |
| 1554 | } |
| 1555 | } |
| 1556 | |
| 1557 | if (width > out_width) { |
| 1558 | tmp = pclk * width; |
| 1559 | do_div(tmp, out_width); |
| 1560 | fclk = max(fclk, (u32) tmp); |
| 1561 | |
| 1562 | if (color_mode == OMAP_DSS_COLOR_RGB24U) |
| 1563 | fclk <<= 1; |
| 1564 | } |
| 1565 | |
| 1566 | return fclk; |
| 1567 | } |
| 1568 | |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 1569 | static unsigned long calc_fclk(enum omap_channel channel, u16 width, |
| 1570 | u16 height, u16 out_width, u16 out_height) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1571 | { |
| 1572 | unsigned int hf, vf; |
| 1573 | |
| 1574 | /* |
| 1575 | * FIXME how to determine the 'A' factor |
| 1576 | * for the no downscaling case ? |
| 1577 | */ |
| 1578 | |
| 1579 | if (width > 3 * out_width) |
| 1580 | hf = 4; |
| 1581 | else if (width > 2 * out_width) |
| 1582 | hf = 3; |
| 1583 | else if (width > out_width) |
| 1584 | hf = 2; |
| 1585 | else |
| 1586 | hf = 1; |
| 1587 | |
| 1588 | if (height > out_height) |
| 1589 | vf = 2; |
| 1590 | else |
| 1591 | vf = 1; |
| 1592 | |
| 1593 | /* FIXME venc pclk? */ |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 1594 | return dispc_pclk_rate(channel) * vf * hf; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1595 | } |
| 1596 | |
| 1597 | void dispc_set_channel_out(enum omap_plane plane, enum omap_channel channel_out) |
| 1598 | { |
| 1599 | enable_clocks(1); |
| 1600 | _dispc_set_channel_out(plane, channel_out); |
| 1601 | enable_clocks(0); |
| 1602 | } |
| 1603 | |
| 1604 | static int _dispc_setup_plane(enum omap_plane plane, |
| 1605 | u32 paddr, u16 screen_width, |
| 1606 | u16 pos_x, u16 pos_y, |
| 1607 | u16 width, u16 height, |
| 1608 | u16 out_width, u16 out_height, |
| 1609 | enum omap_color_mode color_mode, |
| 1610 | bool ilace, |
| 1611 | enum omap_dss_rotation_type rotation_type, |
| 1612 | u8 rotation, int mirror, |
Rajkumar N | fd28a39 | 2010-11-04 12:28:42 +0100 | [diff] [blame] | 1613 | u8 global_alpha, |
| 1614 | u8 pre_mult_alpha) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1615 | { |
| 1616 | const int maxdownscale = cpu_is_omap34xx() ? 4 : 2; |
| 1617 | bool five_taps = 0; |
| 1618 | bool fieldmode = 0; |
| 1619 | int cconv = 0; |
| 1620 | unsigned offset0, offset1; |
| 1621 | s32 row_inc; |
| 1622 | s32 pix_inc; |
| 1623 | u16 frame_height = height; |
| 1624 | unsigned int field_offset = 0; |
| 1625 | |
| 1626 | if (paddr == 0) |
| 1627 | return -EINVAL; |
| 1628 | |
| 1629 | if (ilace && height == out_height) |
| 1630 | fieldmode = 1; |
| 1631 | |
| 1632 | if (ilace) { |
| 1633 | if (fieldmode) |
| 1634 | height /= 2; |
| 1635 | pos_y /= 2; |
| 1636 | out_height /= 2; |
| 1637 | |
| 1638 | DSSDBG("adjusting for ilace: height %d, pos_y %d, " |
| 1639 | "out_height %d\n", |
| 1640 | height, pos_y, out_height); |
| 1641 | } |
| 1642 | |
Archit Taneja | 8dad2ab | 2010-11-25 17:58:10 +0530 | [diff] [blame] | 1643 | if (!dss_feat_color_mode_supported(plane, color_mode)) |
| 1644 | return -EINVAL; |
| 1645 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1646 | if (plane == OMAP_DSS_GFX) { |
| 1647 | if (width != out_width || height != out_height) |
| 1648 | return -EINVAL; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1649 | } else { |
| 1650 | /* video plane */ |
| 1651 | |
| 1652 | unsigned long fclk = 0; |
| 1653 | |
| 1654 | if (out_width < width / maxdownscale || |
| 1655 | out_width > width * 8) |
| 1656 | return -EINVAL; |
| 1657 | |
| 1658 | if (out_height < height / maxdownscale || |
| 1659 | out_height > height * 8) |
| 1660 | return -EINVAL; |
| 1661 | |
Archit Taneja | 8dad2ab | 2010-11-25 17:58:10 +0530 | [diff] [blame] | 1662 | if (color_mode == OMAP_DSS_COLOR_YUV2 || |
| 1663 | color_mode == OMAP_DSS_COLOR_UYVY) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1664 | cconv = 1; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1665 | |
| 1666 | /* Must use 5-tap filter? */ |
| 1667 | five_taps = height > out_height * 2; |
| 1668 | |
| 1669 | if (!five_taps) { |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 1670 | fclk = calc_fclk(OMAP_DSS_CHANNEL_LCD, width, height, |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1671 | out_width, out_height); |
| 1672 | |
| 1673 | /* Try 5-tap filter if 3-tap fclk is too high */ |
| 1674 | if (cpu_is_omap34xx() && height > out_height && |
| 1675 | fclk > dispc_fclk_rate()) |
| 1676 | five_taps = true; |
| 1677 | } |
| 1678 | |
| 1679 | if (width > (2048 >> five_taps)) { |
| 1680 | DSSERR("failed to set up scaling, fclk too low\n"); |
| 1681 | return -EINVAL; |
| 1682 | } |
| 1683 | |
| 1684 | if (five_taps) |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 1685 | fclk = calc_fclk_five_taps(OMAP_DSS_CHANNEL_LCD, width, |
| 1686 | height, out_width, out_height, |
| 1687 | color_mode); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1688 | |
| 1689 | DSSDBG("required fclk rate = %lu Hz\n", fclk); |
| 1690 | DSSDBG("current fclk rate = %lu Hz\n", dispc_fclk_rate()); |
| 1691 | |
Ville Syrjälä | 2d9c559 | 2010-01-08 11:56:41 +0200 | [diff] [blame] | 1692 | if (!fclk || fclk > dispc_fclk_rate()) { |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1693 | DSSERR("failed to set up scaling, " |
| 1694 | "required fclk rate = %lu Hz, " |
| 1695 | "current fclk rate = %lu Hz\n", |
| 1696 | fclk, dispc_fclk_rate()); |
| 1697 | return -EINVAL; |
| 1698 | } |
| 1699 | } |
| 1700 | |
| 1701 | if (ilace && !fieldmode) { |
| 1702 | /* |
| 1703 | * when downscaling the bottom field may have to start several |
| 1704 | * source lines below the top field. Unfortunately ACCUI |
| 1705 | * registers will only hold the fractional part of the offset |
| 1706 | * so the integer part must be added to the base address of the |
| 1707 | * bottom field. |
| 1708 | */ |
| 1709 | if (!height || height == out_height) |
| 1710 | field_offset = 0; |
| 1711 | else |
| 1712 | field_offset = height / out_height / 2; |
| 1713 | } |
| 1714 | |
| 1715 | /* Fields are independent but interleaved in memory. */ |
| 1716 | if (fieldmode) |
| 1717 | field_offset = 1; |
| 1718 | |
| 1719 | if (rotation_type == OMAP_DSS_ROT_DMA) |
| 1720 | calc_dma_rotation_offset(rotation, mirror, |
| 1721 | screen_width, width, frame_height, color_mode, |
| 1722 | fieldmode, field_offset, |
| 1723 | &offset0, &offset1, &row_inc, &pix_inc); |
| 1724 | else |
| 1725 | calc_vrfb_rotation_offset(rotation, mirror, |
| 1726 | screen_width, width, frame_height, color_mode, |
| 1727 | fieldmode, field_offset, |
| 1728 | &offset0, &offset1, &row_inc, &pix_inc); |
| 1729 | |
| 1730 | DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n", |
| 1731 | offset0, offset1, row_inc, pix_inc); |
| 1732 | |
| 1733 | _dispc_set_color_mode(plane, color_mode); |
| 1734 | |
| 1735 | _dispc_set_plane_ba0(plane, paddr + offset0); |
| 1736 | _dispc_set_plane_ba1(plane, paddr + offset1); |
| 1737 | |
| 1738 | _dispc_set_row_inc(plane, row_inc); |
| 1739 | _dispc_set_pix_inc(plane, pix_inc); |
| 1740 | |
| 1741 | DSSDBG("%d,%d %dx%d -> %dx%d\n", pos_x, pos_y, width, height, |
| 1742 | out_width, out_height); |
| 1743 | |
| 1744 | _dispc_set_plane_pos(plane, pos_x, pos_y); |
| 1745 | |
| 1746 | _dispc_set_pic_size(plane, width, height); |
| 1747 | |
| 1748 | if (plane != OMAP_DSS_GFX) { |
| 1749 | _dispc_set_scaling(plane, width, height, |
| 1750 | out_width, out_height, |
| 1751 | ilace, five_taps, fieldmode); |
| 1752 | _dispc_set_vid_size(plane, out_width, out_height); |
| 1753 | _dispc_set_vid_color_conv(plane, cconv); |
| 1754 | } |
| 1755 | |
| 1756 | _dispc_set_rotation_attrs(plane, rotation, mirror, color_mode); |
| 1757 | |
Rajkumar N | fd28a39 | 2010-11-04 12:28:42 +0100 | [diff] [blame] | 1758 | _dispc_set_pre_mult_alpha(plane, pre_mult_alpha); |
| 1759 | _dispc_setup_global_alpha(plane, global_alpha); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1760 | |
| 1761 | return 0; |
| 1762 | } |
| 1763 | |
| 1764 | static void _dispc_enable_plane(enum omap_plane plane, bool enable) |
| 1765 | { |
| 1766 | REG_FLD_MOD(dispc_reg_att[plane], enable ? 1 : 0, 0, 0); |
| 1767 | } |
| 1768 | |
| 1769 | static void dispc_disable_isr(void *data, u32 mask) |
| 1770 | { |
| 1771 | struct completion *compl = data; |
| 1772 | complete(compl); |
| 1773 | } |
| 1774 | |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 1775 | static void _enable_lcd_out(enum omap_channel channel, bool enable) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1776 | { |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 1777 | if (channel == OMAP_DSS_CHANNEL_LCD2) |
| 1778 | REG_FLD_MOD(DISPC_CONTROL2, enable ? 1 : 0, 0, 0); |
| 1779 | else |
| 1780 | REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 0, 0); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1781 | } |
| 1782 | |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 1783 | static void dispc_enable_lcd_out(enum omap_channel channel, bool enable) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1784 | { |
| 1785 | struct completion frame_done_completion; |
| 1786 | bool is_on; |
| 1787 | int r; |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 1788 | u32 irq; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1789 | |
| 1790 | enable_clocks(1); |
| 1791 | |
| 1792 | /* When we disable LCD output, we need to wait until frame is done. |
| 1793 | * Otherwise the DSS is still working, and turning off the clocks |
| 1794 | * prevents DSS from going to OFF mode */ |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 1795 | is_on = channel == OMAP_DSS_CHANNEL_LCD2 ? |
| 1796 | REG_GET(DISPC_CONTROL2, 0, 0) : |
| 1797 | REG_GET(DISPC_CONTROL, 0, 0); |
| 1798 | |
| 1799 | irq = channel == OMAP_DSS_CHANNEL_LCD2 ? DISPC_IRQ_FRAMEDONE2 : |
| 1800 | DISPC_IRQ_FRAMEDONE; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1801 | |
| 1802 | if (!enable && is_on) { |
| 1803 | init_completion(&frame_done_completion); |
| 1804 | |
| 1805 | r = omap_dispc_register_isr(dispc_disable_isr, |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 1806 | &frame_done_completion, irq); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1807 | |
| 1808 | if (r) |
| 1809 | DSSERR("failed to register FRAMEDONE isr\n"); |
| 1810 | } |
| 1811 | |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 1812 | _enable_lcd_out(channel, enable); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1813 | |
| 1814 | if (!enable && is_on) { |
| 1815 | if (!wait_for_completion_timeout(&frame_done_completion, |
| 1816 | msecs_to_jiffies(100))) |
| 1817 | DSSERR("timeout waiting for FRAME DONE\n"); |
| 1818 | |
| 1819 | r = omap_dispc_unregister_isr(dispc_disable_isr, |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 1820 | &frame_done_completion, irq); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1821 | |
| 1822 | if (r) |
| 1823 | DSSERR("failed to unregister FRAMEDONE isr\n"); |
| 1824 | } |
| 1825 | |
| 1826 | enable_clocks(0); |
| 1827 | } |
| 1828 | |
| 1829 | static void _enable_digit_out(bool enable) |
| 1830 | { |
| 1831 | REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 1, 1); |
| 1832 | } |
| 1833 | |
Tomi Valkeinen | a2faee8 | 2010-01-08 17:14:53 +0200 | [diff] [blame] | 1834 | static void dispc_enable_digit_out(bool enable) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1835 | { |
| 1836 | struct completion frame_done_completion; |
| 1837 | int r; |
| 1838 | |
| 1839 | enable_clocks(1); |
| 1840 | |
| 1841 | if (REG_GET(DISPC_CONTROL, 1, 1) == enable) { |
| 1842 | enable_clocks(0); |
| 1843 | return; |
| 1844 | } |
| 1845 | |
| 1846 | if (enable) { |
| 1847 | unsigned long flags; |
| 1848 | /* When we enable digit output, we'll get an extra digit |
| 1849 | * sync lost interrupt, that we need to ignore */ |
| 1850 | spin_lock_irqsave(&dispc.irq_lock, flags); |
| 1851 | dispc.irq_error_mask &= ~DISPC_IRQ_SYNC_LOST_DIGIT; |
| 1852 | _omap_dispc_set_irqs(); |
| 1853 | spin_unlock_irqrestore(&dispc.irq_lock, flags); |
| 1854 | } |
| 1855 | |
| 1856 | /* When we disable digit output, we need to wait until fields are done. |
| 1857 | * Otherwise the DSS is still working, and turning off the clocks |
| 1858 | * prevents DSS from going to OFF mode. And when enabling, we need to |
| 1859 | * wait for the extra sync losts */ |
| 1860 | init_completion(&frame_done_completion); |
| 1861 | |
| 1862 | r = omap_dispc_register_isr(dispc_disable_isr, &frame_done_completion, |
| 1863 | DISPC_IRQ_EVSYNC_EVEN | DISPC_IRQ_EVSYNC_ODD); |
| 1864 | if (r) |
| 1865 | DSSERR("failed to register EVSYNC isr\n"); |
| 1866 | |
| 1867 | _enable_digit_out(enable); |
| 1868 | |
| 1869 | /* XXX I understand from TRM that we should only wait for the |
| 1870 | * current field to complete. But it seems we have to wait |
| 1871 | * for both fields */ |
| 1872 | if (!wait_for_completion_timeout(&frame_done_completion, |
| 1873 | msecs_to_jiffies(100))) |
| 1874 | DSSERR("timeout waiting for EVSYNC\n"); |
| 1875 | |
| 1876 | if (!wait_for_completion_timeout(&frame_done_completion, |
| 1877 | msecs_to_jiffies(100))) |
| 1878 | DSSERR("timeout waiting for EVSYNC\n"); |
| 1879 | |
| 1880 | r = omap_dispc_unregister_isr(dispc_disable_isr, |
| 1881 | &frame_done_completion, |
| 1882 | DISPC_IRQ_EVSYNC_EVEN | DISPC_IRQ_EVSYNC_ODD); |
| 1883 | if (r) |
| 1884 | DSSERR("failed to unregister EVSYNC isr\n"); |
| 1885 | |
| 1886 | if (enable) { |
| 1887 | unsigned long flags; |
| 1888 | spin_lock_irqsave(&dispc.irq_lock, flags); |
| 1889 | dispc.irq_error_mask = DISPC_IRQ_MASK_ERROR; |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 1890 | if (dss_has_feature(FEAT_MGR_LCD2)) |
| 1891 | dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST2; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1892 | dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT); |
| 1893 | _omap_dispc_set_irqs(); |
| 1894 | spin_unlock_irqrestore(&dispc.irq_lock, flags); |
| 1895 | } |
| 1896 | |
| 1897 | enable_clocks(0); |
| 1898 | } |
| 1899 | |
Tomi Valkeinen | a2faee8 | 2010-01-08 17:14:53 +0200 | [diff] [blame] | 1900 | bool dispc_is_channel_enabled(enum omap_channel channel) |
| 1901 | { |
| 1902 | if (channel == OMAP_DSS_CHANNEL_LCD) |
| 1903 | return !!REG_GET(DISPC_CONTROL, 0, 0); |
| 1904 | else if (channel == OMAP_DSS_CHANNEL_DIGIT) |
| 1905 | return !!REG_GET(DISPC_CONTROL, 1, 1); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 1906 | else if (channel == OMAP_DSS_CHANNEL_LCD2) |
| 1907 | return !!REG_GET(DISPC_CONTROL2, 0, 0); |
Tomi Valkeinen | a2faee8 | 2010-01-08 17:14:53 +0200 | [diff] [blame] | 1908 | else |
| 1909 | BUG(); |
| 1910 | } |
| 1911 | |
| 1912 | void dispc_enable_channel(enum omap_channel channel, bool enable) |
| 1913 | { |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 1914 | if (channel == OMAP_DSS_CHANNEL_LCD || |
| 1915 | channel == OMAP_DSS_CHANNEL_LCD2) |
| 1916 | dispc_enable_lcd_out(channel, enable); |
Tomi Valkeinen | a2faee8 | 2010-01-08 17:14:53 +0200 | [diff] [blame] | 1917 | else if (channel == OMAP_DSS_CHANNEL_DIGIT) |
| 1918 | dispc_enable_digit_out(enable); |
| 1919 | else |
| 1920 | BUG(); |
| 1921 | } |
| 1922 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1923 | void dispc_lcd_enable_signal_polarity(bool act_high) |
| 1924 | { |
Archit Taneja | 6ced40b | 2010-12-02 11:27:13 +0000 | [diff] [blame^] | 1925 | if (!dss_has_feature(FEAT_LCDENABLEPOL)) |
| 1926 | return; |
| 1927 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1928 | enable_clocks(1); |
| 1929 | REG_FLD_MOD(DISPC_CONTROL, act_high ? 1 : 0, 29, 29); |
| 1930 | enable_clocks(0); |
| 1931 | } |
| 1932 | |
| 1933 | void dispc_lcd_enable_signal(bool enable) |
| 1934 | { |
Archit Taneja | 6ced40b | 2010-12-02 11:27:13 +0000 | [diff] [blame^] | 1935 | if (!dss_has_feature(FEAT_LCDENABLESIGNAL)) |
| 1936 | return; |
| 1937 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1938 | enable_clocks(1); |
| 1939 | REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 28, 28); |
| 1940 | enable_clocks(0); |
| 1941 | } |
| 1942 | |
| 1943 | void dispc_pck_free_enable(bool enable) |
| 1944 | { |
Archit Taneja | 6ced40b | 2010-12-02 11:27:13 +0000 | [diff] [blame^] | 1945 | if (!dss_has_feature(FEAT_PCKFREEENABLE)) |
| 1946 | return; |
| 1947 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1948 | enable_clocks(1); |
| 1949 | REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 27, 27); |
| 1950 | enable_clocks(0); |
| 1951 | } |
| 1952 | |
Sumit Semwal | 64ba4f7 | 2010-12-02 11:27:10 +0000 | [diff] [blame] | 1953 | void dispc_enable_fifohandcheck(enum omap_channel channel, bool enable) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1954 | { |
| 1955 | enable_clocks(1); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 1956 | if (channel == OMAP_DSS_CHANNEL_LCD2) |
| 1957 | REG_FLD_MOD(DISPC_CONFIG2, enable ? 1 : 0, 16, 16); |
| 1958 | else |
| 1959 | REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 16, 16); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1960 | enable_clocks(0); |
| 1961 | } |
| 1962 | |
| 1963 | |
Sumit Semwal | 64ba4f7 | 2010-12-02 11:27:10 +0000 | [diff] [blame] | 1964 | void dispc_set_lcd_display_type(enum omap_channel channel, |
| 1965 | enum omap_lcd_display_type type) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1966 | { |
| 1967 | int mode; |
| 1968 | |
| 1969 | switch (type) { |
| 1970 | case OMAP_DSS_LCD_DISPLAY_STN: |
| 1971 | mode = 0; |
| 1972 | break; |
| 1973 | |
| 1974 | case OMAP_DSS_LCD_DISPLAY_TFT: |
| 1975 | mode = 1; |
| 1976 | break; |
| 1977 | |
| 1978 | default: |
| 1979 | BUG(); |
| 1980 | return; |
| 1981 | } |
| 1982 | |
| 1983 | enable_clocks(1); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 1984 | if (channel == OMAP_DSS_CHANNEL_LCD2) |
| 1985 | REG_FLD_MOD(DISPC_CONTROL2, mode, 3, 3); |
| 1986 | else |
| 1987 | REG_FLD_MOD(DISPC_CONTROL, mode, 3, 3); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1988 | enable_clocks(0); |
| 1989 | } |
| 1990 | |
| 1991 | void dispc_set_loadmode(enum omap_dss_load_mode mode) |
| 1992 | { |
| 1993 | enable_clocks(1); |
| 1994 | REG_FLD_MOD(DISPC_CONFIG, mode, 2, 1); |
| 1995 | enable_clocks(0); |
| 1996 | } |
| 1997 | |
| 1998 | |
| 1999 | void dispc_set_default_color(enum omap_channel channel, u32 color) |
| 2000 | { |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2001 | enable_clocks(1); |
Sumit Semwal | 8613b00 | 2010-12-02 11:27:09 +0000 | [diff] [blame] | 2002 | dispc_write_reg(DISPC_DEFAULT_COLOR(channel), color); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2003 | enable_clocks(0); |
| 2004 | } |
| 2005 | |
| 2006 | u32 dispc_get_default_color(enum omap_channel channel) |
| 2007 | { |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2008 | u32 l; |
| 2009 | |
| 2010 | BUG_ON(channel != OMAP_DSS_CHANNEL_DIGIT && |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 2011 | channel != OMAP_DSS_CHANNEL_LCD && |
| 2012 | channel != OMAP_DSS_CHANNEL_LCD2); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2013 | |
| 2014 | enable_clocks(1); |
Sumit Semwal | 8613b00 | 2010-12-02 11:27:09 +0000 | [diff] [blame] | 2015 | l = dispc_read_reg(DISPC_DEFAULT_COLOR(channel)); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2016 | enable_clocks(0); |
| 2017 | |
| 2018 | return l; |
| 2019 | } |
| 2020 | |
| 2021 | void dispc_set_trans_key(enum omap_channel ch, |
| 2022 | enum omap_dss_trans_key_type type, |
| 2023 | u32 trans_key) |
| 2024 | { |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2025 | enable_clocks(1); |
| 2026 | if (ch == OMAP_DSS_CHANNEL_LCD) |
| 2027 | REG_FLD_MOD(DISPC_CONFIG, type, 11, 11); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 2028 | else if (ch == OMAP_DSS_CHANNEL_DIGIT) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2029 | REG_FLD_MOD(DISPC_CONFIG, type, 13, 13); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 2030 | else /* OMAP_DSS_CHANNEL_LCD2 */ |
| 2031 | REG_FLD_MOD(DISPC_CONFIG2, type, 11, 11); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2032 | |
Sumit Semwal | 8613b00 | 2010-12-02 11:27:09 +0000 | [diff] [blame] | 2033 | dispc_write_reg(DISPC_TRANS_COLOR(ch), trans_key); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2034 | enable_clocks(0); |
| 2035 | } |
| 2036 | |
| 2037 | void dispc_get_trans_key(enum omap_channel ch, |
| 2038 | enum omap_dss_trans_key_type *type, |
| 2039 | u32 *trans_key) |
| 2040 | { |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2041 | enable_clocks(1); |
| 2042 | if (type) { |
| 2043 | if (ch == OMAP_DSS_CHANNEL_LCD) |
| 2044 | *type = REG_GET(DISPC_CONFIG, 11, 11); |
| 2045 | else if (ch == OMAP_DSS_CHANNEL_DIGIT) |
| 2046 | *type = REG_GET(DISPC_CONFIG, 13, 13); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 2047 | else if (ch == OMAP_DSS_CHANNEL_LCD2) |
| 2048 | *type = REG_GET(DISPC_CONFIG2, 11, 11); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2049 | else |
| 2050 | BUG(); |
| 2051 | } |
| 2052 | |
| 2053 | if (trans_key) |
Sumit Semwal | 8613b00 | 2010-12-02 11:27:09 +0000 | [diff] [blame] | 2054 | *trans_key = dispc_read_reg(DISPC_TRANS_COLOR(ch)); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2055 | enable_clocks(0); |
| 2056 | } |
| 2057 | |
| 2058 | void dispc_enable_trans_key(enum omap_channel ch, bool enable) |
| 2059 | { |
| 2060 | enable_clocks(1); |
| 2061 | if (ch == OMAP_DSS_CHANNEL_LCD) |
| 2062 | REG_FLD_MOD(DISPC_CONFIG, enable, 10, 10); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 2063 | else if (ch == OMAP_DSS_CHANNEL_DIGIT) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2064 | REG_FLD_MOD(DISPC_CONFIG, enable, 12, 12); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 2065 | else /* OMAP_DSS_CHANNEL_LCD2 */ |
| 2066 | REG_FLD_MOD(DISPC_CONFIG2, enable, 10, 10); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2067 | enable_clocks(0); |
| 2068 | } |
| 2069 | void dispc_enable_alpha_blending(enum omap_channel ch, bool enable) |
| 2070 | { |
Archit Taneja | a0acb55 | 2010-09-15 19:20:00 +0530 | [diff] [blame] | 2071 | if (!dss_has_feature(FEAT_GLOBAL_ALPHA)) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2072 | return; |
| 2073 | |
| 2074 | enable_clocks(1); |
| 2075 | if (ch == OMAP_DSS_CHANNEL_LCD) |
| 2076 | REG_FLD_MOD(DISPC_CONFIG, enable, 18, 18); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 2077 | else if (ch == OMAP_DSS_CHANNEL_DIGIT) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2078 | REG_FLD_MOD(DISPC_CONFIG, enable, 19, 19); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 2079 | else /* OMAP_DSS_CHANNEL_LCD2 */ |
| 2080 | REG_FLD_MOD(DISPC_CONFIG2, enable, 18, 18); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2081 | enable_clocks(0); |
| 2082 | } |
| 2083 | bool dispc_alpha_blending_enabled(enum omap_channel ch) |
| 2084 | { |
| 2085 | bool enabled; |
| 2086 | |
Archit Taneja | a0acb55 | 2010-09-15 19:20:00 +0530 | [diff] [blame] | 2087 | if (!dss_has_feature(FEAT_GLOBAL_ALPHA)) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2088 | return false; |
| 2089 | |
| 2090 | enable_clocks(1); |
| 2091 | if (ch == OMAP_DSS_CHANNEL_LCD) |
| 2092 | enabled = REG_GET(DISPC_CONFIG, 18, 18); |
| 2093 | else if (ch == OMAP_DSS_CHANNEL_DIGIT) |
Archit Taneja | 712247a | 2010-11-08 12:56:21 +0100 | [diff] [blame] | 2094 | enabled = REG_GET(DISPC_CONFIG, 19, 19); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 2095 | else if (ch == OMAP_DSS_CHANNEL_LCD2) |
| 2096 | enabled = REG_GET(DISPC_CONFIG2, 18, 18); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2097 | else |
| 2098 | BUG(); |
| 2099 | enable_clocks(0); |
| 2100 | |
| 2101 | return enabled; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2102 | } |
| 2103 | |
| 2104 | |
| 2105 | bool dispc_trans_key_enabled(enum omap_channel ch) |
| 2106 | { |
| 2107 | bool enabled; |
| 2108 | |
| 2109 | enable_clocks(1); |
| 2110 | if (ch == OMAP_DSS_CHANNEL_LCD) |
| 2111 | enabled = REG_GET(DISPC_CONFIG, 10, 10); |
| 2112 | else if (ch == OMAP_DSS_CHANNEL_DIGIT) |
| 2113 | enabled = REG_GET(DISPC_CONFIG, 12, 12); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 2114 | else if (ch == OMAP_DSS_CHANNEL_LCD2) |
| 2115 | enabled = REG_GET(DISPC_CONFIG2, 10, 10); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2116 | else |
| 2117 | BUG(); |
| 2118 | enable_clocks(0); |
| 2119 | |
| 2120 | return enabled; |
| 2121 | } |
| 2122 | |
| 2123 | |
Sumit Semwal | 64ba4f7 | 2010-12-02 11:27:10 +0000 | [diff] [blame] | 2124 | void dispc_set_tft_data_lines(enum omap_channel channel, u8 data_lines) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2125 | { |
| 2126 | int code; |
| 2127 | |
| 2128 | switch (data_lines) { |
| 2129 | case 12: |
| 2130 | code = 0; |
| 2131 | break; |
| 2132 | case 16: |
| 2133 | code = 1; |
| 2134 | break; |
| 2135 | case 18: |
| 2136 | code = 2; |
| 2137 | break; |
| 2138 | case 24: |
| 2139 | code = 3; |
| 2140 | break; |
| 2141 | default: |
| 2142 | BUG(); |
| 2143 | return; |
| 2144 | } |
| 2145 | |
| 2146 | enable_clocks(1); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 2147 | if (channel == OMAP_DSS_CHANNEL_LCD2) |
| 2148 | REG_FLD_MOD(DISPC_CONTROL2, code, 9, 8); |
| 2149 | else |
| 2150 | REG_FLD_MOD(DISPC_CONTROL, code, 9, 8); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2151 | enable_clocks(0); |
| 2152 | } |
| 2153 | |
Sumit Semwal | 64ba4f7 | 2010-12-02 11:27:10 +0000 | [diff] [blame] | 2154 | void dispc_set_parallel_interface_mode(enum omap_channel channel, |
| 2155 | enum omap_parallel_interface_mode mode) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2156 | { |
| 2157 | u32 l; |
| 2158 | int stallmode; |
| 2159 | int gpout0 = 1; |
| 2160 | int gpout1; |
| 2161 | |
| 2162 | switch (mode) { |
| 2163 | case OMAP_DSS_PARALLELMODE_BYPASS: |
| 2164 | stallmode = 0; |
| 2165 | gpout1 = 1; |
| 2166 | break; |
| 2167 | |
| 2168 | case OMAP_DSS_PARALLELMODE_RFBI: |
| 2169 | stallmode = 1; |
| 2170 | gpout1 = 0; |
| 2171 | break; |
| 2172 | |
| 2173 | case OMAP_DSS_PARALLELMODE_DSI: |
| 2174 | stallmode = 1; |
| 2175 | gpout1 = 1; |
| 2176 | break; |
| 2177 | |
| 2178 | default: |
| 2179 | BUG(); |
| 2180 | return; |
| 2181 | } |
| 2182 | |
| 2183 | enable_clocks(1); |
| 2184 | |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 2185 | if (channel == OMAP_DSS_CHANNEL_LCD2) { |
| 2186 | l = dispc_read_reg(DISPC_CONTROL2); |
| 2187 | l = FLD_MOD(l, stallmode, 11, 11); |
| 2188 | dispc_write_reg(DISPC_CONTROL2, l); |
| 2189 | } else { |
| 2190 | l = dispc_read_reg(DISPC_CONTROL); |
| 2191 | l = FLD_MOD(l, stallmode, 11, 11); |
Sumit Semwal | 64ba4f7 | 2010-12-02 11:27:10 +0000 | [diff] [blame] | 2192 | l = FLD_MOD(l, gpout0, 15, 15); |
| 2193 | l = FLD_MOD(l, gpout1, 16, 16); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 2194 | dispc_write_reg(DISPC_CONTROL, l); |
Sumit Semwal | 64ba4f7 | 2010-12-02 11:27:10 +0000 | [diff] [blame] | 2195 | } |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2196 | |
| 2197 | enable_clocks(0); |
| 2198 | } |
| 2199 | |
| 2200 | static bool _dispc_lcd_timings_ok(int hsw, int hfp, int hbp, |
| 2201 | int vsw, int vfp, int vbp) |
| 2202 | { |
| 2203 | if (cpu_is_omap24xx() || omap_rev() < OMAP3430_REV_ES3_0) { |
| 2204 | if (hsw < 1 || hsw > 64 || |
| 2205 | hfp < 1 || hfp > 256 || |
| 2206 | hbp < 1 || hbp > 256 || |
| 2207 | vsw < 1 || vsw > 64 || |
| 2208 | vfp < 0 || vfp > 255 || |
| 2209 | vbp < 0 || vbp > 255) |
| 2210 | return false; |
| 2211 | } else { |
| 2212 | if (hsw < 1 || hsw > 256 || |
| 2213 | hfp < 1 || hfp > 4096 || |
| 2214 | hbp < 1 || hbp > 4096 || |
| 2215 | vsw < 1 || vsw > 256 || |
| 2216 | vfp < 0 || vfp > 4095 || |
| 2217 | vbp < 0 || vbp > 4095) |
| 2218 | return false; |
| 2219 | } |
| 2220 | |
| 2221 | return true; |
| 2222 | } |
| 2223 | |
| 2224 | bool dispc_lcd_timings_ok(struct omap_video_timings *timings) |
| 2225 | { |
| 2226 | return _dispc_lcd_timings_ok(timings->hsw, timings->hfp, |
| 2227 | timings->hbp, timings->vsw, |
| 2228 | timings->vfp, timings->vbp); |
| 2229 | } |
| 2230 | |
Sumit Semwal | 64ba4f7 | 2010-12-02 11:27:10 +0000 | [diff] [blame] | 2231 | static void _dispc_set_lcd_timings(enum omap_channel channel, int hsw, |
| 2232 | int hfp, int hbp, int vsw, int vfp, int vbp) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2233 | { |
| 2234 | u32 timing_h, timing_v; |
| 2235 | |
| 2236 | if (cpu_is_omap24xx() || omap_rev() < OMAP3430_REV_ES3_0) { |
| 2237 | timing_h = FLD_VAL(hsw-1, 5, 0) | FLD_VAL(hfp-1, 15, 8) | |
| 2238 | FLD_VAL(hbp-1, 27, 20); |
| 2239 | |
| 2240 | timing_v = FLD_VAL(vsw-1, 5, 0) | FLD_VAL(vfp, 15, 8) | |
| 2241 | FLD_VAL(vbp, 27, 20); |
| 2242 | } else { |
| 2243 | timing_h = FLD_VAL(hsw-1, 7, 0) | FLD_VAL(hfp-1, 19, 8) | |
| 2244 | FLD_VAL(hbp-1, 31, 20); |
| 2245 | |
| 2246 | timing_v = FLD_VAL(vsw-1, 7, 0) | FLD_VAL(vfp, 19, 8) | |
| 2247 | FLD_VAL(vbp, 31, 20); |
| 2248 | } |
| 2249 | |
| 2250 | enable_clocks(1); |
Sumit Semwal | 64ba4f7 | 2010-12-02 11:27:10 +0000 | [diff] [blame] | 2251 | dispc_write_reg(DISPC_TIMING_H(channel), timing_h); |
| 2252 | dispc_write_reg(DISPC_TIMING_V(channel), timing_v); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2253 | enable_clocks(0); |
| 2254 | } |
| 2255 | |
| 2256 | /* change name to mode? */ |
Sumit Semwal | 64ba4f7 | 2010-12-02 11:27:10 +0000 | [diff] [blame] | 2257 | void dispc_set_lcd_timings(enum omap_channel channel, |
| 2258 | struct omap_video_timings *timings) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2259 | { |
| 2260 | unsigned xtot, ytot; |
| 2261 | unsigned long ht, vt; |
| 2262 | |
| 2263 | if (!_dispc_lcd_timings_ok(timings->hsw, timings->hfp, |
| 2264 | timings->hbp, timings->vsw, |
| 2265 | timings->vfp, timings->vbp)) |
| 2266 | BUG(); |
| 2267 | |
Sumit Semwal | 64ba4f7 | 2010-12-02 11:27:10 +0000 | [diff] [blame] | 2268 | _dispc_set_lcd_timings(channel, timings->hsw, timings->hfp, |
| 2269 | timings->hbp, timings->vsw, timings->vfp, |
| 2270 | timings->vbp); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2271 | |
Sumit Semwal | 64ba4f7 | 2010-12-02 11:27:10 +0000 | [diff] [blame] | 2272 | dispc_set_lcd_size(channel, timings->x_res, timings->y_res); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2273 | |
| 2274 | xtot = timings->x_res + timings->hfp + timings->hsw + timings->hbp; |
| 2275 | ytot = timings->y_res + timings->vfp + timings->vsw + timings->vbp; |
| 2276 | |
| 2277 | ht = (timings->pixel_clock * 1000) / xtot; |
| 2278 | vt = (timings->pixel_clock * 1000) / xtot / ytot; |
| 2279 | |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 2280 | DSSDBG("channel %d xres %u yres %u\n", channel, timings->x_res, |
| 2281 | timings->y_res); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2282 | DSSDBG("pck %u\n", timings->pixel_clock); |
| 2283 | DSSDBG("hsw %d hfp %d hbp %d vsw %d vfp %d vbp %d\n", |
| 2284 | timings->hsw, timings->hfp, timings->hbp, |
| 2285 | timings->vsw, timings->vfp, timings->vbp); |
| 2286 | |
| 2287 | DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt); |
| 2288 | } |
| 2289 | |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 2290 | static void dispc_set_lcd_divisor(enum omap_channel channel, u16 lck_div, |
| 2291 | u16 pck_div) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2292 | { |
| 2293 | BUG_ON(lck_div < 1); |
| 2294 | BUG_ON(pck_div < 2); |
| 2295 | |
| 2296 | enable_clocks(1); |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 2297 | dispc_write_reg(DISPC_DIVISOR(channel), |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2298 | FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0)); |
| 2299 | enable_clocks(0); |
| 2300 | } |
| 2301 | |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 2302 | static void dispc_get_lcd_divisor(enum omap_channel channel, int *lck_div, |
| 2303 | int *pck_div) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2304 | { |
| 2305 | u32 l; |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 2306 | l = dispc_read_reg(DISPC_DIVISOR(channel)); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2307 | *lck_div = FLD_GET(l, 23, 16); |
| 2308 | *pck_div = FLD_GET(l, 7, 0); |
| 2309 | } |
| 2310 | |
| 2311 | unsigned long dispc_fclk_rate(void) |
| 2312 | { |
| 2313 | unsigned long r = 0; |
| 2314 | |
Tomi Valkeinen | 63cf28a | 2010-02-23 17:40:00 +0200 | [diff] [blame] | 2315 | if (dss_get_dispc_clk_source() == DSS_SRC_DSS1_ALWON_FCLK) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2316 | r = dss_clk_get_rate(DSS_CLK_FCK1); |
| 2317 | else |
| 2318 | #ifdef CONFIG_OMAP2_DSS_DSI |
| 2319 | r = dsi_get_dsi1_pll_rate(); |
| 2320 | #else |
| 2321 | BUG(); |
| 2322 | #endif |
| 2323 | return r; |
| 2324 | } |
| 2325 | |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 2326 | unsigned long dispc_lclk_rate(enum omap_channel channel) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2327 | { |
| 2328 | int lcd; |
| 2329 | unsigned long r; |
| 2330 | u32 l; |
| 2331 | |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 2332 | l = dispc_read_reg(DISPC_DIVISOR(channel)); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2333 | |
| 2334 | lcd = FLD_GET(l, 23, 16); |
| 2335 | |
| 2336 | r = dispc_fclk_rate(); |
| 2337 | |
| 2338 | return r / lcd; |
| 2339 | } |
| 2340 | |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 2341 | unsigned long dispc_pclk_rate(enum omap_channel channel) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2342 | { |
| 2343 | int lcd, pcd; |
| 2344 | unsigned long r; |
| 2345 | u32 l; |
| 2346 | |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 2347 | l = dispc_read_reg(DISPC_DIVISOR(channel)); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2348 | |
| 2349 | lcd = FLD_GET(l, 23, 16); |
| 2350 | pcd = FLD_GET(l, 7, 0); |
| 2351 | |
| 2352 | r = dispc_fclk_rate(); |
| 2353 | |
| 2354 | return r / lcd / pcd; |
| 2355 | } |
| 2356 | |
| 2357 | void dispc_dump_clocks(struct seq_file *s) |
| 2358 | { |
| 2359 | int lcd, pcd; |
| 2360 | |
| 2361 | enable_clocks(1); |
| 2362 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2363 | seq_printf(s, "- DISPC -\n"); |
| 2364 | |
| 2365 | seq_printf(s, "dispc fclk source = %s\n", |
Tomi Valkeinen | 63cf28a | 2010-02-23 17:40:00 +0200 | [diff] [blame] | 2366 | dss_get_dispc_clk_source() == DSS_SRC_DSS1_ALWON_FCLK ? |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2367 | "dss1_alwon_fclk" : "dsi1_pll_fclk"); |
| 2368 | |
| 2369 | seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate()); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 2370 | |
| 2371 | seq_printf(s, "- LCD1 -\n"); |
| 2372 | |
| 2373 | dispc_get_lcd_divisor(OMAP_DSS_CHANNEL_LCD, &lcd, &pcd); |
| 2374 | |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 2375 | seq_printf(s, "lck\t\t%-16lulck div\t%u\n", |
| 2376 | dispc_lclk_rate(OMAP_DSS_CHANNEL_LCD), lcd); |
| 2377 | seq_printf(s, "pck\t\t%-16lupck div\t%u\n", |
| 2378 | dispc_pclk_rate(OMAP_DSS_CHANNEL_LCD), pcd); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 2379 | if (dss_has_feature(FEAT_MGR_LCD2)) { |
| 2380 | seq_printf(s, "- LCD2 -\n"); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2381 | |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 2382 | dispc_get_lcd_divisor(OMAP_DSS_CHANNEL_LCD2, &lcd, &pcd); |
| 2383 | |
| 2384 | seq_printf(s, "lck\t\t%-16lulck div\t%u\n", |
| 2385 | dispc_lclk_rate(OMAP_DSS_CHANNEL_LCD2), lcd); |
| 2386 | seq_printf(s, "pck\t\t%-16lupck div\t%u\n", |
| 2387 | dispc_pclk_rate(OMAP_DSS_CHANNEL_LCD2), pcd); |
| 2388 | } |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2389 | enable_clocks(0); |
| 2390 | } |
| 2391 | |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 2392 | #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS |
| 2393 | void dispc_dump_irqs(struct seq_file *s) |
| 2394 | { |
| 2395 | unsigned long flags; |
| 2396 | struct dispc_irq_stats stats; |
| 2397 | |
| 2398 | spin_lock_irqsave(&dispc.irq_stats_lock, flags); |
| 2399 | |
| 2400 | stats = dispc.irq_stats; |
| 2401 | memset(&dispc.irq_stats, 0, sizeof(dispc.irq_stats)); |
| 2402 | dispc.irq_stats.last_reset = jiffies; |
| 2403 | |
| 2404 | spin_unlock_irqrestore(&dispc.irq_stats_lock, flags); |
| 2405 | |
| 2406 | seq_printf(s, "period %u ms\n", |
| 2407 | jiffies_to_msecs(jiffies - stats.last_reset)); |
| 2408 | |
| 2409 | seq_printf(s, "irqs %d\n", stats.irq_count); |
| 2410 | #define PIS(x) \ |
| 2411 | seq_printf(s, "%-20s %10d\n", #x, stats.irqs[ffs(DISPC_IRQ_##x)-1]); |
| 2412 | |
| 2413 | PIS(FRAMEDONE); |
| 2414 | PIS(VSYNC); |
| 2415 | PIS(EVSYNC_EVEN); |
| 2416 | PIS(EVSYNC_ODD); |
| 2417 | PIS(ACBIAS_COUNT_STAT); |
| 2418 | PIS(PROG_LINE_NUM); |
| 2419 | PIS(GFX_FIFO_UNDERFLOW); |
| 2420 | PIS(GFX_END_WIN); |
| 2421 | PIS(PAL_GAMMA_MASK); |
| 2422 | PIS(OCP_ERR); |
| 2423 | PIS(VID1_FIFO_UNDERFLOW); |
| 2424 | PIS(VID1_END_WIN); |
| 2425 | PIS(VID2_FIFO_UNDERFLOW); |
| 2426 | PIS(VID2_END_WIN); |
| 2427 | PIS(SYNC_LOST); |
| 2428 | PIS(SYNC_LOST_DIGIT); |
| 2429 | PIS(WAKEUP); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 2430 | if (dss_has_feature(FEAT_MGR_LCD2)) { |
| 2431 | PIS(FRAMEDONE2); |
| 2432 | PIS(VSYNC2); |
| 2433 | PIS(ACBIAS_COUNT_STAT2); |
| 2434 | PIS(SYNC_LOST2); |
| 2435 | } |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 2436 | #undef PIS |
| 2437 | } |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 2438 | #endif |
| 2439 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2440 | void dispc_dump_regs(struct seq_file *s) |
| 2441 | { |
| 2442 | #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dispc_read_reg(r)) |
| 2443 | |
| 2444 | dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK1); |
| 2445 | |
| 2446 | DUMPREG(DISPC_REVISION); |
| 2447 | DUMPREG(DISPC_SYSCONFIG); |
| 2448 | DUMPREG(DISPC_SYSSTATUS); |
| 2449 | DUMPREG(DISPC_IRQSTATUS); |
| 2450 | DUMPREG(DISPC_IRQENABLE); |
| 2451 | DUMPREG(DISPC_CONTROL); |
| 2452 | DUMPREG(DISPC_CONFIG); |
| 2453 | DUMPREG(DISPC_CAPABLE); |
Sumit Semwal | 8613b00 | 2010-12-02 11:27:09 +0000 | [diff] [blame] | 2454 | DUMPREG(DISPC_DEFAULT_COLOR(0)); |
| 2455 | DUMPREG(DISPC_DEFAULT_COLOR(1)); |
| 2456 | DUMPREG(DISPC_TRANS_COLOR(0)); |
| 2457 | DUMPREG(DISPC_TRANS_COLOR(1)); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2458 | DUMPREG(DISPC_LINE_STATUS); |
| 2459 | DUMPREG(DISPC_LINE_NUMBER); |
Sumit Semwal | 8613b00 | 2010-12-02 11:27:09 +0000 | [diff] [blame] | 2460 | DUMPREG(DISPC_TIMING_H(0)); |
| 2461 | DUMPREG(DISPC_TIMING_V(0)); |
| 2462 | DUMPREG(DISPC_POL_FREQ(0)); |
| 2463 | DUMPREG(DISPC_DIVISOR(0)); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2464 | DUMPREG(DISPC_GLOBAL_ALPHA); |
| 2465 | DUMPREG(DISPC_SIZE_DIG); |
Sumit Semwal | 8613b00 | 2010-12-02 11:27:09 +0000 | [diff] [blame] | 2466 | DUMPREG(DISPC_SIZE_LCD(0)); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 2467 | if (dss_has_feature(FEAT_MGR_LCD2)) { |
| 2468 | DUMPREG(DISPC_CONTROL2); |
| 2469 | DUMPREG(DISPC_CONFIG2); |
| 2470 | DUMPREG(DISPC_DEFAULT_COLOR(2)); |
| 2471 | DUMPREG(DISPC_TRANS_COLOR(2)); |
| 2472 | DUMPREG(DISPC_TIMING_H(2)); |
| 2473 | DUMPREG(DISPC_TIMING_V(2)); |
| 2474 | DUMPREG(DISPC_POL_FREQ(2)); |
| 2475 | DUMPREG(DISPC_DIVISOR(2)); |
| 2476 | DUMPREG(DISPC_SIZE_LCD(2)); |
| 2477 | } |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2478 | |
| 2479 | DUMPREG(DISPC_GFX_BA0); |
| 2480 | DUMPREG(DISPC_GFX_BA1); |
| 2481 | DUMPREG(DISPC_GFX_POSITION); |
| 2482 | DUMPREG(DISPC_GFX_SIZE); |
| 2483 | DUMPREG(DISPC_GFX_ATTRIBUTES); |
| 2484 | DUMPREG(DISPC_GFX_FIFO_THRESHOLD); |
| 2485 | DUMPREG(DISPC_GFX_FIFO_SIZE_STATUS); |
| 2486 | DUMPREG(DISPC_GFX_ROW_INC); |
| 2487 | DUMPREG(DISPC_GFX_PIXEL_INC); |
| 2488 | DUMPREG(DISPC_GFX_WINDOW_SKIP); |
| 2489 | DUMPREG(DISPC_GFX_TABLE_BA); |
| 2490 | |
Sumit Semwal | 8613b00 | 2010-12-02 11:27:09 +0000 | [diff] [blame] | 2491 | DUMPREG(DISPC_DATA_CYCLE1(0)); |
| 2492 | DUMPREG(DISPC_DATA_CYCLE2(0)); |
| 2493 | DUMPREG(DISPC_DATA_CYCLE3(0)); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2494 | |
Sumit Semwal | 8613b00 | 2010-12-02 11:27:09 +0000 | [diff] [blame] | 2495 | DUMPREG(DISPC_CPR_COEF_R(0)); |
| 2496 | DUMPREG(DISPC_CPR_COEF_G(0)); |
| 2497 | DUMPREG(DISPC_CPR_COEF_B(0)); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 2498 | if (dss_has_feature(FEAT_MGR_LCD2)) { |
| 2499 | DUMPREG(DISPC_DATA_CYCLE1(2)); |
| 2500 | DUMPREG(DISPC_DATA_CYCLE2(2)); |
| 2501 | DUMPREG(DISPC_DATA_CYCLE3(2)); |
| 2502 | |
| 2503 | DUMPREG(DISPC_CPR_COEF_R(2)); |
| 2504 | DUMPREG(DISPC_CPR_COEF_G(2)); |
| 2505 | DUMPREG(DISPC_CPR_COEF_B(2)); |
| 2506 | } |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2507 | |
| 2508 | DUMPREG(DISPC_GFX_PRELOAD); |
| 2509 | |
| 2510 | DUMPREG(DISPC_VID_BA0(0)); |
| 2511 | DUMPREG(DISPC_VID_BA1(0)); |
| 2512 | DUMPREG(DISPC_VID_POSITION(0)); |
| 2513 | DUMPREG(DISPC_VID_SIZE(0)); |
| 2514 | DUMPREG(DISPC_VID_ATTRIBUTES(0)); |
| 2515 | DUMPREG(DISPC_VID_FIFO_THRESHOLD(0)); |
| 2516 | DUMPREG(DISPC_VID_FIFO_SIZE_STATUS(0)); |
| 2517 | DUMPREG(DISPC_VID_ROW_INC(0)); |
| 2518 | DUMPREG(DISPC_VID_PIXEL_INC(0)); |
| 2519 | DUMPREG(DISPC_VID_FIR(0)); |
| 2520 | DUMPREG(DISPC_VID_PICTURE_SIZE(0)); |
| 2521 | DUMPREG(DISPC_VID_ACCU0(0)); |
| 2522 | DUMPREG(DISPC_VID_ACCU1(0)); |
| 2523 | |
| 2524 | DUMPREG(DISPC_VID_BA0(1)); |
| 2525 | DUMPREG(DISPC_VID_BA1(1)); |
| 2526 | DUMPREG(DISPC_VID_POSITION(1)); |
| 2527 | DUMPREG(DISPC_VID_SIZE(1)); |
| 2528 | DUMPREG(DISPC_VID_ATTRIBUTES(1)); |
| 2529 | DUMPREG(DISPC_VID_FIFO_THRESHOLD(1)); |
| 2530 | DUMPREG(DISPC_VID_FIFO_SIZE_STATUS(1)); |
| 2531 | DUMPREG(DISPC_VID_ROW_INC(1)); |
| 2532 | DUMPREG(DISPC_VID_PIXEL_INC(1)); |
| 2533 | DUMPREG(DISPC_VID_FIR(1)); |
| 2534 | DUMPREG(DISPC_VID_PICTURE_SIZE(1)); |
| 2535 | DUMPREG(DISPC_VID_ACCU0(1)); |
| 2536 | DUMPREG(DISPC_VID_ACCU1(1)); |
| 2537 | |
| 2538 | DUMPREG(DISPC_VID_FIR_COEF_H(0, 0)); |
| 2539 | DUMPREG(DISPC_VID_FIR_COEF_H(0, 1)); |
| 2540 | DUMPREG(DISPC_VID_FIR_COEF_H(0, 2)); |
| 2541 | DUMPREG(DISPC_VID_FIR_COEF_H(0, 3)); |
| 2542 | DUMPREG(DISPC_VID_FIR_COEF_H(0, 4)); |
| 2543 | DUMPREG(DISPC_VID_FIR_COEF_H(0, 5)); |
| 2544 | DUMPREG(DISPC_VID_FIR_COEF_H(0, 6)); |
| 2545 | DUMPREG(DISPC_VID_FIR_COEF_H(0, 7)); |
| 2546 | DUMPREG(DISPC_VID_FIR_COEF_HV(0, 0)); |
| 2547 | DUMPREG(DISPC_VID_FIR_COEF_HV(0, 1)); |
| 2548 | DUMPREG(DISPC_VID_FIR_COEF_HV(0, 2)); |
| 2549 | DUMPREG(DISPC_VID_FIR_COEF_HV(0, 3)); |
| 2550 | DUMPREG(DISPC_VID_FIR_COEF_HV(0, 4)); |
| 2551 | DUMPREG(DISPC_VID_FIR_COEF_HV(0, 5)); |
| 2552 | DUMPREG(DISPC_VID_FIR_COEF_HV(0, 6)); |
| 2553 | DUMPREG(DISPC_VID_FIR_COEF_HV(0, 7)); |
| 2554 | DUMPREG(DISPC_VID_CONV_COEF(0, 0)); |
| 2555 | DUMPREG(DISPC_VID_CONV_COEF(0, 1)); |
| 2556 | DUMPREG(DISPC_VID_CONV_COEF(0, 2)); |
| 2557 | DUMPREG(DISPC_VID_CONV_COEF(0, 3)); |
| 2558 | DUMPREG(DISPC_VID_CONV_COEF(0, 4)); |
| 2559 | DUMPREG(DISPC_VID_FIR_COEF_V(0, 0)); |
| 2560 | DUMPREG(DISPC_VID_FIR_COEF_V(0, 1)); |
| 2561 | DUMPREG(DISPC_VID_FIR_COEF_V(0, 2)); |
| 2562 | DUMPREG(DISPC_VID_FIR_COEF_V(0, 3)); |
| 2563 | DUMPREG(DISPC_VID_FIR_COEF_V(0, 4)); |
| 2564 | DUMPREG(DISPC_VID_FIR_COEF_V(0, 5)); |
| 2565 | DUMPREG(DISPC_VID_FIR_COEF_V(0, 6)); |
| 2566 | DUMPREG(DISPC_VID_FIR_COEF_V(0, 7)); |
| 2567 | |
| 2568 | DUMPREG(DISPC_VID_FIR_COEF_H(1, 0)); |
| 2569 | DUMPREG(DISPC_VID_FIR_COEF_H(1, 1)); |
| 2570 | DUMPREG(DISPC_VID_FIR_COEF_H(1, 2)); |
| 2571 | DUMPREG(DISPC_VID_FIR_COEF_H(1, 3)); |
| 2572 | DUMPREG(DISPC_VID_FIR_COEF_H(1, 4)); |
| 2573 | DUMPREG(DISPC_VID_FIR_COEF_H(1, 5)); |
| 2574 | DUMPREG(DISPC_VID_FIR_COEF_H(1, 6)); |
| 2575 | DUMPREG(DISPC_VID_FIR_COEF_H(1, 7)); |
| 2576 | DUMPREG(DISPC_VID_FIR_COEF_HV(1, 0)); |
| 2577 | DUMPREG(DISPC_VID_FIR_COEF_HV(1, 1)); |
| 2578 | DUMPREG(DISPC_VID_FIR_COEF_HV(1, 2)); |
| 2579 | DUMPREG(DISPC_VID_FIR_COEF_HV(1, 3)); |
| 2580 | DUMPREG(DISPC_VID_FIR_COEF_HV(1, 4)); |
| 2581 | DUMPREG(DISPC_VID_FIR_COEF_HV(1, 5)); |
| 2582 | DUMPREG(DISPC_VID_FIR_COEF_HV(1, 6)); |
| 2583 | DUMPREG(DISPC_VID_FIR_COEF_HV(1, 7)); |
| 2584 | DUMPREG(DISPC_VID_CONV_COEF(1, 0)); |
| 2585 | DUMPREG(DISPC_VID_CONV_COEF(1, 1)); |
| 2586 | DUMPREG(DISPC_VID_CONV_COEF(1, 2)); |
| 2587 | DUMPREG(DISPC_VID_CONV_COEF(1, 3)); |
| 2588 | DUMPREG(DISPC_VID_CONV_COEF(1, 4)); |
| 2589 | DUMPREG(DISPC_VID_FIR_COEF_V(1, 0)); |
| 2590 | DUMPREG(DISPC_VID_FIR_COEF_V(1, 1)); |
| 2591 | DUMPREG(DISPC_VID_FIR_COEF_V(1, 2)); |
| 2592 | DUMPREG(DISPC_VID_FIR_COEF_V(1, 3)); |
| 2593 | DUMPREG(DISPC_VID_FIR_COEF_V(1, 4)); |
| 2594 | DUMPREG(DISPC_VID_FIR_COEF_V(1, 5)); |
| 2595 | DUMPREG(DISPC_VID_FIR_COEF_V(1, 6)); |
| 2596 | DUMPREG(DISPC_VID_FIR_COEF_V(1, 7)); |
| 2597 | |
| 2598 | DUMPREG(DISPC_VID_PRELOAD(0)); |
| 2599 | DUMPREG(DISPC_VID_PRELOAD(1)); |
| 2600 | |
| 2601 | dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK1); |
| 2602 | #undef DUMPREG |
| 2603 | } |
| 2604 | |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 2605 | static void _dispc_set_pol_freq(enum omap_channel channel, bool onoff, bool rf, |
| 2606 | bool ieo, bool ipc, bool ihs, bool ivs, u8 acbi, u8 acb) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2607 | { |
| 2608 | u32 l = 0; |
| 2609 | |
| 2610 | DSSDBG("onoff %d rf %d ieo %d ipc %d ihs %d ivs %d acbi %d acb %d\n", |
| 2611 | onoff, rf, ieo, ipc, ihs, ivs, acbi, acb); |
| 2612 | |
| 2613 | l |= FLD_VAL(onoff, 17, 17); |
| 2614 | l |= FLD_VAL(rf, 16, 16); |
| 2615 | l |= FLD_VAL(ieo, 15, 15); |
| 2616 | l |= FLD_VAL(ipc, 14, 14); |
| 2617 | l |= FLD_VAL(ihs, 13, 13); |
| 2618 | l |= FLD_VAL(ivs, 12, 12); |
| 2619 | l |= FLD_VAL(acbi, 11, 8); |
| 2620 | l |= FLD_VAL(acb, 7, 0); |
| 2621 | |
| 2622 | enable_clocks(1); |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 2623 | dispc_write_reg(DISPC_POL_FREQ(channel), l); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2624 | enable_clocks(0); |
| 2625 | } |
| 2626 | |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 2627 | void dispc_set_pol_freq(enum omap_channel channel, |
| 2628 | enum omap_panel_config config, u8 acbi, u8 acb) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2629 | { |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 2630 | _dispc_set_pol_freq(channel, (config & OMAP_DSS_LCD_ONOFF) != 0, |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2631 | (config & OMAP_DSS_LCD_RF) != 0, |
| 2632 | (config & OMAP_DSS_LCD_IEO) != 0, |
| 2633 | (config & OMAP_DSS_LCD_IPC) != 0, |
| 2634 | (config & OMAP_DSS_LCD_IHS) != 0, |
| 2635 | (config & OMAP_DSS_LCD_IVS) != 0, |
| 2636 | acbi, acb); |
| 2637 | } |
| 2638 | |
| 2639 | /* with fck as input clock rate, find dispc dividers that produce req_pck */ |
| 2640 | void dispc_find_clk_divs(bool is_tft, unsigned long req_pck, unsigned long fck, |
| 2641 | struct dispc_clock_info *cinfo) |
| 2642 | { |
| 2643 | u16 pcd_min = is_tft ? 2 : 3; |
| 2644 | unsigned long best_pck; |
| 2645 | u16 best_ld, cur_ld; |
| 2646 | u16 best_pd, cur_pd; |
| 2647 | |
| 2648 | best_pck = 0; |
| 2649 | best_ld = 0; |
| 2650 | best_pd = 0; |
| 2651 | |
| 2652 | for (cur_ld = 1; cur_ld <= 255; ++cur_ld) { |
| 2653 | unsigned long lck = fck / cur_ld; |
| 2654 | |
| 2655 | for (cur_pd = pcd_min; cur_pd <= 255; ++cur_pd) { |
| 2656 | unsigned long pck = lck / cur_pd; |
| 2657 | long old_delta = abs(best_pck - req_pck); |
| 2658 | long new_delta = abs(pck - req_pck); |
| 2659 | |
| 2660 | if (best_pck == 0 || new_delta < old_delta) { |
| 2661 | best_pck = pck; |
| 2662 | best_ld = cur_ld; |
| 2663 | best_pd = cur_pd; |
| 2664 | |
| 2665 | if (pck == req_pck) |
| 2666 | goto found; |
| 2667 | } |
| 2668 | |
| 2669 | if (pck < req_pck) |
| 2670 | break; |
| 2671 | } |
| 2672 | |
| 2673 | if (lck / pcd_min < req_pck) |
| 2674 | break; |
| 2675 | } |
| 2676 | |
| 2677 | found: |
| 2678 | cinfo->lck_div = best_ld; |
| 2679 | cinfo->pck_div = best_pd; |
| 2680 | cinfo->lck = fck / cinfo->lck_div; |
| 2681 | cinfo->pck = cinfo->lck / cinfo->pck_div; |
| 2682 | } |
| 2683 | |
| 2684 | /* calculate clock rates using dividers in cinfo */ |
| 2685 | int dispc_calc_clock_rates(unsigned long dispc_fclk_rate, |
| 2686 | struct dispc_clock_info *cinfo) |
| 2687 | { |
| 2688 | if (cinfo->lck_div > 255 || cinfo->lck_div == 0) |
| 2689 | return -EINVAL; |
| 2690 | if (cinfo->pck_div < 2 || cinfo->pck_div > 255) |
| 2691 | return -EINVAL; |
| 2692 | |
| 2693 | cinfo->lck = dispc_fclk_rate / cinfo->lck_div; |
| 2694 | cinfo->pck = cinfo->lck / cinfo->pck_div; |
| 2695 | |
| 2696 | return 0; |
| 2697 | } |
| 2698 | |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 2699 | int dispc_set_clock_div(enum omap_channel channel, |
| 2700 | struct dispc_clock_info *cinfo) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2701 | { |
| 2702 | DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div); |
| 2703 | DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div); |
| 2704 | |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 2705 | dispc_set_lcd_divisor(channel, cinfo->lck_div, cinfo->pck_div); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2706 | |
| 2707 | return 0; |
| 2708 | } |
| 2709 | |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 2710 | int dispc_get_clock_div(enum omap_channel channel, |
| 2711 | struct dispc_clock_info *cinfo) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2712 | { |
| 2713 | unsigned long fck; |
| 2714 | |
| 2715 | fck = dispc_fclk_rate(); |
| 2716 | |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 2717 | cinfo->lck_div = REG_GET(DISPC_DIVISOR(channel), 23, 16); |
| 2718 | cinfo->pck_div = REG_GET(DISPC_DIVISOR(channel), 7, 0); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2719 | |
| 2720 | cinfo->lck = fck / cinfo->lck_div; |
| 2721 | cinfo->pck = cinfo->lck / cinfo->pck_div; |
| 2722 | |
| 2723 | return 0; |
| 2724 | } |
| 2725 | |
| 2726 | /* dispc.irq_lock has to be locked by the caller */ |
| 2727 | static void _omap_dispc_set_irqs(void) |
| 2728 | { |
| 2729 | u32 mask; |
| 2730 | u32 old_mask; |
| 2731 | int i; |
| 2732 | struct omap_dispc_isr_data *isr_data; |
| 2733 | |
| 2734 | mask = dispc.irq_error_mask; |
| 2735 | |
| 2736 | for (i = 0; i < DISPC_MAX_NR_ISRS; i++) { |
| 2737 | isr_data = &dispc.registered_isr[i]; |
| 2738 | |
| 2739 | if (isr_data->isr == NULL) |
| 2740 | continue; |
| 2741 | |
| 2742 | mask |= isr_data->mask; |
| 2743 | } |
| 2744 | |
| 2745 | enable_clocks(1); |
| 2746 | |
| 2747 | old_mask = dispc_read_reg(DISPC_IRQENABLE); |
| 2748 | /* clear the irqstatus for newly enabled irqs */ |
| 2749 | dispc_write_reg(DISPC_IRQSTATUS, (mask ^ old_mask) & mask); |
| 2750 | |
| 2751 | dispc_write_reg(DISPC_IRQENABLE, mask); |
| 2752 | |
| 2753 | enable_clocks(0); |
| 2754 | } |
| 2755 | |
| 2756 | int omap_dispc_register_isr(omap_dispc_isr_t isr, void *arg, u32 mask) |
| 2757 | { |
| 2758 | int i; |
| 2759 | int ret; |
| 2760 | unsigned long flags; |
| 2761 | struct omap_dispc_isr_data *isr_data; |
| 2762 | |
| 2763 | if (isr == NULL) |
| 2764 | return -EINVAL; |
| 2765 | |
| 2766 | spin_lock_irqsave(&dispc.irq_lock, flags); |
| 2767 | |
| 2768 | /* check for duplicate entry */ |
| 2769 | for (i = 0; i < DISPC_MAX_NR_ISRS; i++) { |
| 2770 | isr_data = &dispc.registered_isr[i]; |
| 2771 | if (isr_data->isr == isr && isr_data->arg == arg && |
| 2772 | isr_data->mask == mask) { |
| 2773 | ret = -EINVAL; |
| 2774 | goto err; |
| 2775 | } |
| 2776 | } |
| 2777 | |
| 2778 | isr_data = NULL; |
| 2779 | ret = -EBUSY; |
| 2780 | |
| 2781 | for (i = 0; i < DISPC_MAX_NR_ISRS; i++) { |
| 2782 | isr_data = &dispc.registered_isr[i]; |
| 2783 | |
| 2784 | if (isr_data->isr != NULL) |
| 2785 | continue; |
| 2786 | |
| 2787 | isr_data->isr = isr; |
| 2788 | isr_data->arg = arg; |
| 2789 | isr_data->mask = mask; |
| 2790 | ret = 0; |
| 2791 | |
| 2792 | break; |
| 2793 | } |
| 2794 | |
| 2795 | _omap_dispc_set_irqs(); |
| 2796 | |
| 2797 | spin_unlock_irqrestore(&dispc.irq_lock, flags); |
| 2798 | |
| 2799 | return 0; |
| 2800 | err: |
| 2801 | spin_unlock_irqrestore(&dispc.irq_lock, flags); |
| 2802 | |
| 2803 | return ret; |
| 2804 | } |
| 2805 | EXPORT_SYMBOL(omap_dispc_register_isr); |
| 2806 | |
| 2807 | int omap_dispc_unregister_isr(omap_dispc_isr_t isr, void *arg, u32 mask) |
| 2808 | { |
| 2809 | int i; |
| 2810 | unsigned long flags; |
| 2811 | int ret = -EINVAL; |
| 2812 | struct omap_dispc_isr_data *isr_data; |
| 2813 | |
| 2814 | spin_lock_irqsave(&dispc.irq_lock, flags); |
| 2815 | |
| 2816 | for (i = 0; i < DISPC_MAX_NR_ISRS; i++) { |
| 2817 | isr_data = &dispc.registered_isr[i]; |
| 2818 | if (isr_data->isr != isr || isr_data->arg != arg || |
| 2819 | isr_data->mask != mask) |
| 2820 | continue; |
| 2821 | |
| 2822 | /* found the correct isr */ |
| 2823 | |
| 2824 | isr_data->isr = NULL; |
| 2825 | isr_data->arg = NULL; |
| 2826 | isr_data->mask = 0; |
| 2827 | |
| 2828 | ret = 0; |
| 2829 | break; |
| 2830 | } |
| 2831 | |
| 2832 | if (ret == 0) |
| 2833 | _omap_dispc_set_irqs(); |
| 2834 | |
| 2835 | spin_unlock_irqrestore(&dispc.irq_lock, flags); |
| 2836 | |
| 2837 | return ret; |
| 2838 | } |
| 2839 | EXPORT_SYMBOL(omap_dispc_unregister_isr); |
| 2840 | |
| 2841 | #ifdef DEBUG |
| 2842 | static void print_irq_status(u32 status) |
| 2843 | { |
| 2844 | if ((status & dispc.irq_error_mask) == 0) |
| 2845 | return; |
| 2846 | |
| 2847 | printk(KERN_DEBUG "DISPC IRQ: 0x%x: ", status); |
| 2848 | |
| 2849 | #define PIS(x) \ |
| 2850 | if (status & DISPC_IRQ_##x) \ |
| 2851 | printk(#x " "); |
| 2852 | PIS(GFX_FIFO_UNDERFLOW); |
| 2853 | PIS(OCP_ERR); |
| 2854 | PIS(VID1_FIFO_UNDERFLOW); |
| 2855 | PIS(VID2_FIFO_UNDERFLOW); |
| 2856 | PIS(SYNC_LOST); |
| 2857 | PIS(SYNC_LOST_DIGIT); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 2858 | if (dss_has_feature(FEAT_MGR_LCD2)) |
| 2859 | PIS(SYNC_LOST2); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2860 | #undef PIS |
| 2861 | |
| 2862 | printk("\n"); |
| 2863 | } |
| 2864 | #endif |
| 2865 | |
| 2866 | /* Called from dss.c. Note that we don't touch clocks here, |
| 2867 | * but we presume they are on because we got an IRQ. However, |
| 2868 | * an irq handler may turn the clocks off, so we may not have |
| 2869 | * clock later in the function. */ |
| 2870 | void dispc_irq_handler(void) |
| 2871 | { |
| 2872 | int i; |
| 2873 | u32 irqstatus; |
| 2874 | u32 handledirqs = 0; |
| 2875 | u32 unhandled_errors; |
| 2876 | struct omap_dispc_isr_data *isr_data; |
| 2877 | struct omap_dispc_isr_data registered_isr[DISPC_MAX_NR_ISRS]; |
| 2878 | |
| 2879 | spin_lock(&dispc.irq_lock); |
| 2880 | |
| 2881 | irqstatus = dispc_read_reg(DISPC_IRQSTATUS); |
| 2882 | |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 2883 | #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS |
| 2884 | spin_lock(&dispc.irq_stats_lock); |
| 2885 | dispc.irq_stats.irq_count++; |
| 2886 | dss_collect_irq_stats(irqstatus, dispc.irq_stats.irqs); |
| 2887 | spin_unlock(&dispc.irq_stats_lock); |
| 2888 | #endif |
| 2889 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2890 | #ifdef DEBUG |
| 2891 | if (dss_debug) |
| 2892 | print_irq_status(irqstatus); |
| 2893 | #endif |
| 2894 | /* Ack the interrupt. Do it here before clocks are possibly turned |
| 2895 | * off */ |
| 2896 | dispc_write_reg(DISPC_IRQSTATUS, irqstatus); |
| 2897 | /* flush posted write */ |
| 2898 | dispc_read_reg(DISPC_IRQSTATUS); |
| 2899 | |
| 2900 | /* make a copy and unlock, so that isrs can unregister |
| 2901 | * themselves */ |
| 2902 | memcpy(registered_isr, dispc.registered_isr, |
| 2903 | sizeof(registered_isr)); |
| 2904 | |
| 2905 | spin_unlock(&dispc.irq_lock); |
| 2906 | |
| 2907 | for (i = 0; i < DISPC_MAX_NR_ISRS; i++) { |
| 2908 | isr_data = ®istered_isr[i]; |
| 2909 | |
| 2910 | if (!isr_data->isr) |
| 2911 | continue; |
| 2912 | |
| 2913 | if (isr_data->mask & irqstatus) { |
| 2914 | isr_data->isr(isr_data->arg, irqstatus); |
| 2915 | handledirqs |= isr_data->mask; |
| 2916 | } |
| 2917 | } |
| 2918 | |
| 2919 | spin_lock(&dispc.irq_lock); |
| 2920 | |
| 2921 | unhandled_errors = irqstatus & ~handledirqs & dispc.irq_error_mask; |
| 2922 | |
| 2923 | if (unhandled_errors) { |
| 2924 | dispc.error_irqs |= unhandled_errors; |
| 2925 | |
| 2926 | dispc.irq_error_mask &= ~unhandled_errors; |
| 2927 | _omap_dispc_set_irqs(); |
| 2928 | |
| 2929 | schedule_work(&dispc.error_work); |
| 2930 | } |
| 2931 | |
| 2932 | spin_unlock(&dispc.irq_lock); |
| 2933 | } |
| 2934 | |
| 2935 | static void dispc_error_worker(struct work_struct *work) |
| 2936 | { |
| 2937 | int i; |
| 2938 | u32 errors; |
| 2939 | unsigned long flags; |
| 2940 | |
| 2941 | spin_lock_irqsave(&dispc.irq_lock, flags); |
| 2942 | errors = dispc.error_irqs; |
| 2943 | dispc.error_irqs = 0; |
| 2944 | spin_unlock_irqrestore(&dispc.irq_lock, flags); |
| 2945 | |
| 2946 | if (errors & DISPC_IRQ_GFX_FIFO_UNDERFLOW) { |
| 2947 | DSSERR("GFX_FIFO_UNDERFLOW, disabling GFX\n"); |
| 2948 | for (i = 0; i < omap_dss_get_num_overlays(); ++i) { |
| 2949 | struct omap_overlay *ovl; |
| 2950 | ovl = omap_dss_get_overlay(i); |
| 2951 | |
| 2952 | if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC)) |
| 2953 | continue; |
| 2954 | |
| 2955 | if (ovl->id == 0) { |
| 2956 | dispc_enable_plane(ovl->id, 0); |
| 2957 | dispc_go(ovl->manager->id); |
| 2958 | mdelay(50); |
| 2959 | break; |
| 2960 | } |
| 2961 | } |
| 2962 | } |
| 2963 | |
| 2964 | if (errors & DISPC_IRQ_VID1_FIFO_UNDERFLOW) { |
| 2965 | DSSERR("VID1_FIFO_UNDERFLOW, disabling VID1\n"); |
| 2966 | for (i = 0; i < omap_dss_get_num_overlays(); ++i) { |
| 2967 | struct omap_overlay *ovl; |
| 2968 | ovl = omap_dss_get_overlay(i); |
| 2969 | |
| 2970 | if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC)) |
| 2971 | continue; |
| 2972 | |
| 2973 | if (ovl->id == 1) { |
| 2974 | dispc_enable_plane(ovl->id, 0); |
| 2975 | dispc_go(ovl->manager->id); |
| 2976 | mdelay(50); |
| 2977 | break; |
| 2978 | } |
| 2979 | } |
| 2980 | } |
| 2981 | |
| 2982 | if (errors & DISPC_IRQ_VID2_FIFO_UNDERFLOW) { |
| 2983 | DSSERR("VID2_FIFO_UNDERFLOW, disabling VID2\n"); |
| 2984 | for (i = 0; i < omap_dss_get_num_overlays(); ++i) { |
| 2985 | struct omap_overlay *ovl; |
| 2986 | ovl = omap_dss_get_overlay(i); |
| 2987 | |
| 2988 | if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC)) |
| 2989 | continue; |
| 2990 | |
| 2991 | if (ovl->id == 2) { |
| 2992 | dispc_enable_plane(ovl->id, 0); |
| 2993 | dispc_go(ovl->manager->id); |
| 2994 | mdelay(50); |
| 2995 | break; |
| 2996 | } |
| 2997 | } |
| 2998 | } |
| 2999 | |
| 3000 | if (errors & DISPC_IRQ_SYNC_LOST) { |
| 3001 | struct omap_overlay_manager *manager = NULL; |
| 3002 | bool enable = false; |
| 3003 | |
| 3004 | DSSERR("SYNC_LOST, disabling LCD\n"); |
| 3005 | |
| 3006 | for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) { |
| 3007 | struct omap_overlay_manager *mgr; |
| 3008 | mgr = omap_dss_get_overlay_manager(i); |
| 3009 | |
| 3010 | if (mgr->id == OMAP_DSS_CHANNEL_LCD) { |
| 3011 | manager = mgr; |
| 3012 | enable = mgr->device->state == |
| 3013 | OMAP_DSS_DISPLAY_ACTIVE; |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 3014 | mgr->device->driver->disable(mgr->device); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3015 | break; |
| 3016 | } |
| 3017 | } |
| 3018 | |
| 3019 | if (manager) { |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 3020 | struct omap_dss_device *dssdev = manager->device; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3021 | for (i = 0; i < omap_dss_get_num_overlays(); ++i) { |
| 3022 | struct omap_overlay *ovl; |
| 3023 | ovl = omap_dss_get_overlay(i); |
| 3024 | |
| 3025 | if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC)) |
| 3026 | continue; |
| 3027 | |
| 3028 | if (ovl->id != 0 && ovl->manager == manager) |
| 3029 | dispc_enable_plane(ovl->id, 0); |
| 3030 | } |
| 3031 | |
| 3032 | dispc_go(manager->id); |
| 3033 | mdelay(50); |
| 3034 | if (enable) |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 3035 | dssdev->driver->enable(dssdev); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3036 | } |
| 3037 | } |
| 3038 | |
| 3039 | if (errors & DISPC_IRQ_SYNC_LOST_DIGIT) { |
| 3040 | struct omap_overlay_manager *manager = NULL; |
| 3041 | bool enable = false; |
| 3042 | |
| 3043 | DSSERR("SYNC_LOST_DIGIT, disabling TV\n"); |
| 3044 | |
| 3045 | for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) { |
| 3046 | struct omap_overlay_manager *mgr; |
| 3047 | mgr = omap_dss_get_overlay_manager(i); |
| 3048 | |
| 3049 | if (mgr->id == OMAP_DSS_CHANNEL_DIGIT) { |
| 3050 | manager = mgr; |
| 3051 | enable = mgr->device->state == |
| 3052 | OMAP_DSS_DISPLAY_ACTIVE; |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 3053 | mgr->device->driver->disable(mgr->device); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3054 | break; |
| 3055 | } |
| 3056 | } |
| 3057 | |
| 3058 | if (manager) { |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 3059 | struct omap_dss_device *dssdev = manager->device; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3060 | for (i = 0; i < omap_dss_get_num_overlays(); ++i) { |
| 3061 | struct omap_overlay *ovl; |
| 3062 | ovl = omap_dss_get_overlay(i); |
| 3063 | |
| 3064 | if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC)) |
| 3065 | continue; |
| 3066 | |
| 3067 | if (ovl->id != 0 && ovl->manager == manager) |
| 3068 | dispc_enable_plane(ovl->id, 0); |
| 3069 | } |
| 3070 | |
| 3071 | dispc_go(manager->id); |
| 3072 | mdelay(50); |
| 3073 | if (enable) |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 3074 | dssdev->driver->enable(dssdev); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3075 | } |
| 3076 | } |
| 3077 | |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 3078 | if (errors & DISPC_IRQ_SYNC_LOST2) { |
| 3079 | struct omap_overlay_manager *manager = NULL; |
| 3080 | bool enable = false; |
| 3081 | |
| 3082 | DSSERR("SYNC_LOST for LCD2, disabling LCD2\n"); |
| 3083 | |
| 3084 | for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) { |
| 3085 | struct omap_overlay_manager *mgr; |
| 3086 | mgr = omap_dss_get_overlay_manager(i); |
| 3087 | |
| 3088 | if (mgr->id == OMAP_DSS_CHANNEL_LCD2) { |
| 3089 | manager = mgr; |
| 3090 | enable = mgr->device->state == |
| 3091 | OMAP_DSS_DISPLAY_ACTIVE; |
| 3092 | mgr->device->driver->disable(mgr->device); |
| 3093 | break; |
| 3094 | } |
| 3095 | } |
| 3096 | |
| 3097 | if (manager) { |
| 3098 | struct omap_dss_device *dssdev = manager->device; |
| 3099 | for (i = 0; i < omap_dss_get_num_overlays(); ++i) { |
| 3100 | struct omap_overlay *ovl; |
| 3101 | ovl = omap_dss_get_overlay(i); |
| 3102 | |
| 3103 | if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC)) |
| 3104 | continue; |
| 3105 | |
| 3106 | if (ovl->id != 0 && ovl->manager == manager) |
| 3107 | dispc_enable_plane(ovl->id, 0); |
| 3108 | } |
| 3109 | |
| 3110 | dispc_go(manager->id); |
| 3111 | mdelay(50); |
| 3112 | if (enable) |
| 3113 | dssdev->driver->enable(dssdev); |
| 3114 | } |
| 3115 | } |
| 3116 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3117 | if (errors & DISPC_IRQ_OCP_ERR) { |
| 3118 | DSSERR("OCP_ERR\n"); |
| 3119 | for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) { |
| 3120 | struct omap_overlay_manager *mgr; |
| 3121 | mgr = omap_dss_get_overlay_manager(i); |
| 3122 | |
| 3123 | if (mgr->caps & OMAP_DSS_OVL_CAP_DISPC) |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 3124 | mgr->device->driver->disable(mgr->device); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3125 | } |
| 3126 | } |
| 3127 | |
| 3128 | spin_lock_irqsave(&dispc.irq_lock, flags); |
| 3129 | dispc.irq_error_mask |= errors; |
| 3130 | _omap_dispc_set_irqs(); |
| 3131 | spin_unlock_irqrestore(&dispc.irq_lock, flags); |
| 3132 | } |
| 3133 | |
| 3134 | int omap_dispc_wait_for_irq_timeout(u32 irqmask, unsigned long timeout) |
| 3135 | { |
| 3136 | void dispc_irq_wait_handler(void *data, u32 mask) |
| 3137 | { |
| 3138 | complete((struct completion *)data); |
| 3139 | } |
| 3140 | |
| 3141 | int r; |
| 3142 | DECLARE_COMPLETION_ONSTACK(completion); |
| 3143 | |
| 3144 | r = omap_dispc_register_isr(dispc_irq_wait_handler, &completion, |
| 3145 | irqmask); |
| 3146 | |
| 3147 | if (r) |
| 3148 | return r; |
| 3149 | |
| 3150 | timeout = wait_for_completion_timeout(&completion, timeout); |
| 3151 | |
| 3152 | omap_dispc_unregister_isr(dispc_irq_wait_handler, &completion, irqmask); |
| 3153 | |
| 3154 | if (timeout == 0) |
| 3155 | return -ETIMEDOUT; |
| 3156 | |
| 3157 | if (timeout == -ERESTARTSYS) |
| 3158 | return -ERESTARTSYS; |
| 3159 | |
| 3160 | return 0; |
| 3161 | } |
| 3162 | |
| 3163 | int omap_dispc_wait_for_irq_interruptible_timeout(u32 irqmask, |
| 3164 | unsigned long timeout) |
| 3165 | { |
| 3166 | void dispc_irq_wait_handler(void *data, u32 mask) |
| 3167 | { |
| 3168 | complete((struct completion *)data); |
| 3169 | } |
| 3170 | |
| 3171 | int r; |
| 3172 | DECLARE_COMPLETION_ONSTACK(completion); |
| 3173 | |
| 3174 | r = omap_dispc_register_isr(dispc_irq_wait_handler, &completion, |
| 3175 | irqmask); |
| 3176 | |
| 3177 | if (r) |
| 3178 | return r; |
| 3179 | |
| 3180 | timeout = wait_for_completion_interruptible_timeout(&completion, |
| 3181 | timeout); |
| 3182 | |
| 3183 | omap_dispc_unregister_isr(dispc_irq_wait_handler, &completion, irqmask); |
| 3184 | |
| 3185 | if (timeout == 0) |
| 3186 | return -ETIMEDOUT; |
| 3187 | |
| 3188 | if (timeout == -ERESTARTSYS) |
| 3189 | return -ERESTARTSYS; |
| 3190 | |
| 3191 | return 0; |
| 3192 | } |
| 3193 | |
| 3194 | #ifdef CONFIG_OMAP2_DSS_FAKE_VSYNC |
| 3195 | void dispc_fake_vsync_irq(void) |
| 3196 | { |
| 3197 | u32 irqstatus = DISPC_IRQ_VSYNC; |
| 3198 | int i; |
| 3199 | |
Tomi Valkeinen | ab83b14 | 2010-06-09 15:31:01 +0300 | [diff] [blame] | 3200 | WARN_ON(!in_interrupt()); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3201 | |
| 3202 | for (i = 0; i < DISPC_MAX_NR_ISRS; i++) { |
| 3203 | struct omap_dispc_isr_data *isr_data; |
| 3204 | isr_data = &dispc.registered_isr[i]; |
| 3205 | |
| 3206 | if (!isr_data->isr) |
| 3207 | continue; |
| 3208 | |
| 3209 | if (isr_data->mask & irqstatus) |
| 3210 | isr_data->isr(isr_data->arg, irqstatus); |
| 3211 | } |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3212 | } |
| 3213 | #endif |
| 3214 | |
| 3215 | static void _omap_dispc_initialize_irq(void) |
| 3216 | { |
| 3217 | unsigned long flags; |
| 3218 | |
| 3219 | spin_lock_irqsave(&dispc.irq_lock, flags); |
| 3220 | |
| 3221 | memset(dispc.registered_isr, 0, sizeof(dispc.registered_isr)); |
| 3222 | |
| 3223 | dispc.irq_error_mask = DISPC_IRQ_MASK_ERROR; |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 3224 | if (dss_has_feature(FEAT_MGR_LCD2)) |
| 3225 | dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST2; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3226 | |
| 3227 | /* there's SYNC_LOST_DIGIT waiting after enabling the DSS, |
| 3228 | * so clear it */ |
| 3229 | dispc_write_reg(DISPC_IRQSTATUS, dispc_read_reg(DISPC_IRQSTATUS)); |
| 3230 | |
| 3231 | _omap_dispc_set_irqs(); |
| 3232 | |
| 3233 | spin_unlock_irqrestore(&dispc.irq_lock, flags); |
| 3234 | } |
| 3235 | |
| 3236 | void dispc_enable_sidle(void) |
| 3237 | { |
| 3238 | REG_FLD_MOD(DISPC_SYSCONFIG, 2, 4, 3); /* SIDLEMODE: smart idle */ |
| 3239 | } |
| 3240 | |
| 3241 | void dispc_disable_sidle(void) |
| 3242 | { |
| 3243 | REG_FLD_MOD(DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */ |
| 3244 | } |
| 3245 | |
| 3246 | static void _omap_dispc_initial_config(void) |
| 3247 | { |
| 3248 | u32 l; |
| 3249 | |
| 3250 | l = dispc_read_reg(DISPC_SYSCONFIG); |
| 3251 | l = FLD_MOD(l, 2, 13, 12); /* MIDLEMODE: smart standby */ |
| 3252 | l = FLD_MOD(l, 2, 4, 3); /* SIDLEMODE: smart idle */ |
| 3253 | l = FLD_MOD(l, 1, 2, 2); /* ENWAKEUP */ |
| 3254 | l = FLD_MOD(l, 1, 0, 0); /* AUTOIDLE */ |
| 3255 | dispc_write_reg(DISPC_SYSCONFIG, l); |
| 3256 | |
| 3257 | /* FUNCGATED */ |
Archit Taneja | 6ced40b | 2010-12-02 11:27:13 +0000 | [diff] [blame^] | 3258 | if (dss_has_feature(FEAT_FUNCGATED)) |
| 3259 | REG_FLD_MOD(DISPC_CONFIG, 1, 9, 9); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3260 | |
| 3261 | /* L3 firewall setting: enable access to OCM RAM */ |
| 3262 | /* XXX this should be somewhere in plat-omap */ |
| 3263 | if (cpu_is_omap24xx()) |
| 3264 | __raw_writel(0x402000b0, OMAP2_L3_IO_ADDRESS(0x680050a0)); |
| 3265 | |
| 3266 | _dispc_setup_color_conv_coef(); |
| 3267 | |
| 3268 | dispc_set_loadmode(OMAP_DSS_LOAD_FRAME_ONLY); |
| 3269 | |
| 3270 | dispc_read_plane_fifo_sizes(); |
| 3271 | } |
| 3272 | |
| 3273 | int dispc_init(void) |
| 3274 | { |
| 3275 | u32 rev; |
| 3276 | |
| 3277 | spin_lock_init(&dispc.irq_lock); |
| 3278 | |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 3279 | #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS |
| 3280 | spin_lock_init(&dispc.irq_stats_lock); |
| 3281 | dispc.irq_stats.last_reset = jiffies; |
| 3282 | #endif |
| 3283 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3284 | INIT_WORK(&dispc.error_work, dispc_error_worker); |
| 3285 | |
| 3286 | dispc.base = ioremap(DISPC_BASE, DISPC_SZ_REGS); |
| 3287 | if (!dispc.base) { |
| 3288 | DSSERR("can't ioremap DISPC\n"); |
| 3289 | return -ENOMEM; |
| 3290 | } |
| 3291 | |
| 3292 | enable_clocks(1); |
| 3293 | |
| 3294 | _omap_dispc_initial_config(); |
| 3295 | |
| 3296 | _omap_dispc_initialize_irq(); |
| 3297 | |
| 3298 | dispc_save_context(); |
| 3299 | |
| 3300 | rev = dispc_read_reg(DISPC_REVISION); |
| 3301 | printk(KERN_INFO "OMAP DISPC rev %d.%d\n", |
| 3302 | FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0)); |
| 3303 | |
| 3304 | enable_clocks(0); |
| 3305 | |
| 3306 | return 0; |
| 3307 | } |
| 3308 | |
| 3309 | void dispc_exit(void) |
| 3310 | { |
| 3311 | iounmap(dispc.base); |
| 3312 | } |
| 3313 | |
| 3314 | int dispc_enable_plane(enum omap_plane plane, bool enable) |
| 3315 | { |
| 3316 | DSSDBG("dispc_enable_plane %d, %d\n", plane, enable); |
| 3317 | |
| 3318 | enable_clocks(1); |
| 3319 | _dispc_enable_plane(plane, enable); |
| 3320 | enable_clocks(0); |
| 3321 | |
| 3322 | return 0; |
| 3323 | } |
| 3324 | |
| 3325 | int dispc_setup_plane(enum omap_plane plane, |
| 3326 | u32 paddr, u16 screen_width, |
| 3327 | u16 pos_x, u16 pos_y, |
| 3328 | u16 width, u16 height, |
| 3329 | u16 out_width, u16 out_height, |
| 3330 | enum omap_color_mode color_mode, |
| 3331 | bool ilace, |
| 3332 | enum omap_dss_rotation_type rotation_type, |
Rajkumar N | fd28a39 | 2010-11-04 12:28:42 +0100 | [diff] [blame] | 3333 | u8 rotation, bool mirror, u8 global_alpha, |
| 3334 | u8 pre_mult_alpha) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3335 | { |
| 3336 | int r = 0; |
| 3337 | |
| 3338 | DSSDBG("dispc_setup_plane %d, pa %x, sw %d, %d,%d, %dx%d -> " |
| 3339 | "%dx%d, ilace %d, cmode %x, rot %d, mir %d\n", |
| 3340 | plane, paddr, screen_width, pos_x, pos_y, |
| 3341 | width, height, |
| 3342 | out_width, out_height, |
| 3343 | ilace, color_mode, |
| 3344 | rotation, mirror); |
| 3345 | |
| 3346 | enable_clocks(1); |
| 3347 | |
| 3348 | r = _dispc_setup_plane(plane, |
| 3349 | paddr, screen_width, |
| 3350 | pos_x, pos_y, |
| 3351 | width, height, |
| 3352 | out_width, out_height, |
| 3353 | color_mode, ilace, |
| 3354 | rotation_type, |
| 3355 | rotation, mirror, |
Rajkumar N | fd28a39 | 2010-11-04 12:28:42 +0100 | [diff] [blame] | 3356 | global_alpha, |
| 3357 | pre_mult_alpha); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3358 | |
| 3359 | enable_clocks(0); |
| 3360 | |
| 3361 | return r; |
| 3362 | } |