Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/video/omap2/dss/dsi.c |
| 3 | * |
| 4 | * Copyright (C) 2009 Nokia Corporation |
| 5 | * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License version 2 as published by |
| 9 | * the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 14 | * more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #define DSS_SUBSYS_NAME "DSI" |
| 21 | |
| 22 | #include <linux/kernel.h> |
| 23 | #include <linux/io.h> |
| 24 | #include <linux/clk.h> |
| 25 | #include <linux/device.h> |
| 26 | #include <linux/err.h> |
| 27 | #include <linux/interrupt.h> |
| 28 | #include <linux/delay.h> |
| 29 | #include <linux/mutex.h> |
Tomi Valkeinen | b9eb5d7 | 2010-01-11 16:33:56 +0200 | [diff] [blame] | 30 | #include <linux/semaphore.h> |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 31 | #include <linux/seq_file.h> |
| 32 | #include <linux/platform_device.h> |
| 33 | #include <linux/regulator/consumer.h> |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 34 | #include <linux/wait.h> |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 35 | #include <linux/workqueue.h> |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 36 | #include <linux/sched.h> |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 37 | #include <linux/slab.h> |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 38 | #include <linux/debugfs.h> |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 39 | #include <linux/pm_runtime.h> |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 40 | |
Tomi Valkeinen | a0b38cc | 2011-05-11 14:05:07 +0300 | [diff] [blame] | 41 | #include <video/omapdss.h> |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 42 | #include <plat/clock.h> |
| 43 | |
| 44 | #include "dss.h" |
Archit Taneja | 819d807 | 2011-03-01 11:54:00 +0530 | [diff] [blame] | 45 | #include "dss_features.h" |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 46 | |
| 47 | /*#define VERBOSE_IRQ*/ |
| 48 | #define DSI_CATCH_MISSING_TE |
| 49 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 50 | struct dsi_reg { u16 idx; }; |
| 51 | |
| 52 | #define DSI_REG(idx) ((const struct dsi_reg) { idx }) |
| 53 | |
| 54 | #define DSI_SZ_REGS SZ_1K |
| 55 | /* DSI Protocol Engine */ |
| 56 | |
| 57 | #define DSI_REVISION DSI_REG(0x0000) |
| 58 | #define DSI_SYSCONFIG DSI_REG(0x0010) |
| 59 | #define DSI_SYSSTATUS DSI_REG(0x0014) |
| 60 | #define DSI_IRQSTATUS DSI_REG(0x0018) |
| 61 | #define DSI_IRQENABLE DSI_REG(0x001C) |
| 62 | #define DSI_CTRL DSI_REG(0x0040) |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 63 | #define DSI_GNQ DSI_REG(0x0044) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 64 | #define DSI_COMPLEXIO_CFG1 DSI_REG(0x0048) |
| 65 | #define DSI_COMPLEXIO_IRQ_STATUS DSI_REG(0x004C) |
| 66 | #define DSI_COMPLEXIO_IRQ_ENABLE DSI_REG(0x0050) |
| 67 | #define DSI_CLK_CTRL DSI_REG(0x0054) |
| 68 | #define DSI_TIMING1 DSI_REG(0x0058) |
| 69 | #define DSI_TIMING2 DSI_REG(0x005C) |
| 70 | #define DSI_VM_TIMING1 DSI_REG(0x0060) |
| 71 | #define DSI_VM_TIMING2 DSI_REG(0x0064) |
| 72 | #define DSI_VM_TIMING3 DSI_REG(0x0068) |
| 73 | #define DSI_CLK_TIMING DSI_REG(0x006C) |
| 74 | #define DSI_TX_FIFO_VC_SIZE DSI_REG(0x0070) |
| 75 | #define DSI_RX_FIFO_VC_SIZE DSI_REG(0x0074) |
| 76 | #define DSI_COMPLEXIO_CFG2 DSI_REG(0x0078) |
| 77 | #define DSI_RX_FIFO_VC_FULLNESS DSI_REG(0x007C) |
| 78 | #define DSI_VM_TIMING4 DSI_REG(0x0080) |
| 79 | #define DSI_TX_FIFO_VC_EMPTINESS DSI_REG(0x0084) |
| 80 | #define DSI_VM_TIMING5 DSI_REG(0x0088) |
| 81 | #define DSI_VM_TIMING6 DSI_REG(0x008C) |
| 82 | #define DSI_VM_TIMING7 DSI_REG(0x0090) |
| 83 | #define DSI_STOPCLK_TIMING DSI_REG(0x0094) |
| 84 | #define DSI_VC_CTRL(n) DSI_REG(0x0100 + (n * 0x20)) |
| 85 | #define DSI_VC_TE(n) DSI_REG(0x0104 + (n * 0x20)) |
| 86 | #define DSI_VC_LONG_PACKET_HEADER(n) DSI_REG(0x0108 + (n * 0x20)) |
| 87 | #define DSI_VC_LONG_PACKET_PAYLOAD(n) DSI_REG(0x010C + (n * 0x20)) |
| 88 | #define DSI_VC_SHORT_PACKET_HEADER(n) DSI_REG(0x0110 + (n * 0x20)) |
| 89 | #define DSI_VC_IRQSTATUS(n) DSI_REG(0x0118 + (n * 0x20)) |
| 90 | #define DSI_VC_IRQENABLE(n) DSI_REG(0x011C + (n * 0x20)) |
| 91 | |
| 92 | /* DSIPHY_SCP */ |
| 93 | |
| 94 | #define DSI_DSIPHY_CFG0 DSI_REG(0x200 + 0x0000) |
| 95 | #define DSI_DSIPHY_CFG1 DSI_REG(0x200 + 0x0004) |
| 96 | #define DSI_DSIPHY_CFG2 DSI_REG(0x200 + 0x0008) |
| 97 | #define DSI_DSIPHY_CFG5 DSI_REG(0x200 + 0x0014) |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 98 | #define DSI_DSIPHY_CFG10 DSI_REG(0x200 + 0x0028) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 99 | |
| 100 | /* DSI_PLL_CTRL_SCP */ |
| 101 | |
| 102 | #define DSI_PLL_CONTROL DSI_REG(0x300 + 0x0000) |
| 103 | #define DSI_PLL_STATUS DSI_REG(0x300 + 0x0004) |
| 104 | #define DSI_PLL_GO DSI_REG(0x300 + 0x0008) |
| 105 | #define DSI_PLL_CONFIGURATION1 DSI_REG(0x300 + 0x000C) |
| 106 | #define DSI_PLL_CONFIGURATION2 DSI_REG(0x300 + 0x0010) |
| 107 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 108 | #define REG_GET(dsidev, idx, start, end) \ |
| 109 | FLD_GET(dsi_read_reg(dsidev, idx), start, end) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 110 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 111 | #define REG_FLD_MOD(dsidev, idx, val, start, end) \ |
| 112 | dsi_write_reg(dsidev, idx, FLD_MOD(dsi_read_reg(dsidev, idx), val, start, end)) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 113 | |
| 114 | /* Global interrupts */ |
| 115 | #define DSI_IRQ_VC0 (1 << 0) |
| 116 | #define DSI_IRQ_VC1 (1 << 1) |
| 117 | #define DSI_IRQ_VC2 (1 << 2) |
| 118 | #define DSI_IRQ_VC3 (1 << 3) |
| 119 | #define DSI_IRQ_WAKEUP (1 << 4) |
| 120 | #define DSI_IRQ_RESYNC (1 << 5) |
| 121 | #define DSI_IRQ_PLL_LOCK (1 << 7) |
| 122 | #define DSI_IRQ_PLL_UNLOCK (1 << 8) |
| 123 | #define DSI_IRQ_PLL_RECALL (1 << 9) |
| 124 | #define DSI_IRQ_COMPLEXIO_ERR (1 << 10) |
| 125 | #define DSI_IRQ_HS_TX_TIMEOUT (1 << 14) |
| 126 | #define DSI_IRQ_LP_RX_TIMEOUT (1 << 15) |
| 127 | #define DSI_IRQ_TE_TRIGGER (1 << 16) |
| 128 | #define DSI_IRQ_ACK_TRIGGER (1 << 17) |
| 129 | #define DSI_IRQ_SYNC_LOST (1 << 18) |
| 130 | #define DSI_IRQ_LDO_POWER_GOOD (1 << 19) |
| 131 | #define DSI_IRQ_TA_TIMEOUT (1 << 20) |
| 132 | #define DSI_IRQ_ERROR_MASK \ |
| 133 | (DSI_IRQ_HS_TX_TIMEOUT | DSI_IRQ_LP_RX_TIMEOUT | DSI_IRQ_SYNC_LOST | \ |
| 134 | DSI_IRQ_TA_TIMEOUT) |
| 135 | #define DSI_IRQ_CHANNEL_MASK 0xf |
| 136 | |
| 137 | /* Virtual channel interrupts */ |
| 138 | #define DSI_VC_IRQ_CS (1 << 0) |
| 139 | #define DSI_VC_IRQ_ECC_CORR (1 << 1) |
| 140 | #define DSI_VC_IRQ_PACKET_SENT (1 << 2) |
| 141 | #define DSI_VC_IRQ_FIFO_TX_OVF (1 << 3) |
| 142 | #define DSI_VC_IRQ_FIFO_RX_OVF (1 << 4) |
| 143 | #define DSI_VC_IRQ_BTA (1 << 5) |
| 144 | #define DSI_VC_IRQ_ECC_NO_CORR (1 << 6) |
| 145 | #define DSI_VC_IRQ_FIFO_TX_UDF (1 << 7) |
| 146 | #define DSI_VC_IRQ_PP_BUSY_CHANGE (1 << 8) |
| 147 | #define DSI_VC_IRQ_ERROR_MASK \ |
| 148 | (DSI_VC_IRQ_CS | DSI_VC_IRQ_ECC_CORR | DSI_VC_IRQ_FIFO_TX_OVF | \ |
| 149 | DSI_VC_IRQ_FIFO_RX_OVF | DSI_VC_IRQ_ECC_NO_CORR | \ |
| 150 | DSI_VC_IRQ_FIFO_TX_UDF) |
| 151 | |
| 152 | /* ComplexIO interrupts */ |
| 153 | #define DSI_CIO_IRQ_ERRSYNCESC1 (1 << 0) |
| 154 | #define DSI_CIO_IRQ_ERRSYNCESC2 (1 << 1) |
| 155 | #define DSI_CIO_IRQ_ERRSYNCESC3 (1 << 2) |
Tomi Valkeinen | 6705615 | 2011-03-24 16:30:17 +0200 | [diff] [blame] | 156 | #define DSI_CIO_IRQ_ERRSYNCESC4 (1 << 3) |
| 157 | #define DSI_CIO_IRQ_ERRSYNCESC5 (1 << 4) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 158 | #define DSI_CIO_IRQ_ERRESC1 (1 << 5) |
| 159 | #define DSI_CIO_IRQ_ERRESC2 (1 << 6) |
| 160 | #define DSI_CIO_IRQ_ERRESC3 (1 << 7) |
Tomi Valkeinen | 6705615 | 2011-03-24 16:30:17 +0200 | [diff] [blame] | 161 | #define DSI_CIO_IRQ_ERRESC4 (1 << 8) |
| 162 | #define DSI_CIO_IRQ_ERRESC5 (1 << 9) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 163 | #define DSI_CIO_IRQ_ERRCONTROL1 (1 << 10) |
| 164 | #define DSI_CIO_IRQ_ERRCONTROL2 (1 << 11) |
| 165 | #define DSI_CIO_IRQ_ERRCONTROL3 (1 << 12) |
Tomi Valkeinen | 6705615 | 2011-03-24 16:30:17 +0200 | [diff] [blame] | 166 | #define DSI_CIO_IRQ_ERRCONTROL4 (1 << 13) |
| 167 | #define DSI_CIO_IRQ_ERRCONTROL5 (1 << 14) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 168 | #define DSI_CIO_IRQ_STATEULPS1 (1 << 15) |
| 169 | #define DSI_CIO_IRQ_STATEULPS2 (1 << 16) |
| 170 | #define DSI_CIO_IRQ_STATEULPS3 (1 << 17) |
Tomi Valkeinen | 6705615 | 2011-03-24 16:30:17 +0200 | [diff] [blame] | 171 | #define DSI_CIO_IRQ_STATEULPS4 (1 << 18) |
| 172 | #define DSI_CIO_IRQ_STATEULPS5 (1 << 19) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 173 | #define DSI_CIO_IRQ_ERRCONTENTIONLP0_1 (1 << 20) |
| 174 | #define DSI_CIO_IRQ_ERRCONTENTIONLP1_1 (1 << 21) |
| 175 | #define DSI_CIO_IRQ_ERRCONTENTIONLP0_2 (1 << 22) |
| 176 | #define DSI_CIO_IRQ_ERRCONTENTIONLP1_2 (1 << 23) |
| 177 | #define DSI_CIO_IRQ_ERRCONTENTIONLP0_3 (1 << 24) |
| 178 | #define DSI_CIO_IRQ_ERRCONTENTIONLP1_3 (1 << 25) |
Tomi Valkeinen | 6705615 | 2011-03-24 16:30:17 +0200 | [diff] [blame] | 179 | #define DSI_CIO_IRQ_ERRCONTENTIONLP0_4 (1 << 26) |
| 180 | #define DSI_CIO_IRQ_ERRCONTENTIONLP1_4 (1 << 27) |
| 181 | #define DSI_CIO_IRQ_ERRCONTENTIONLP0_5 (1 << 28) |
| 182 | #define DSI_CIO_IRQ_ERRCONTENTIONLP1_5 (1 << 29) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 183 | #define DSI_CIO_IRQ_ULPSACTIVENOT_ALL0 (1 << 30) |
| 184 | #define DSI_CIO_IRQ_ULPSACTIVENOT_ALL1 (1 << 31) |
Tomi Valkeinen | bbecb50 | 2010-05-10 14:35:33 +0300 | [diff] [blame] | 185 | #define DSI_CIO_IRQ_ERROR_MASK \ |
| 186 | (DSI_CIO_IRQ_ERRSYNCESC1 | DSI_CIO_IRQ_ERRSYNCESC2 | \ |
Tomi Valkeinen | 6705615 | 2011-03-24 16:30:17 +0200 | [diff] [blame] | 187 | DSI_CIO_IRQ_ERRSYNCESC3 | DSI_CIO_IRQ_ERRSYNCESC4 | \ |
| 188 | DSI_CIO_IRQ_ERRSYNCESC5 | \ |
| 189 | DSI_CIO_IRQ_ERRESC1 | DSI_CIO_IRQ_ERRESC2 | \ |
| 190 | DSI_CIO_IRQ_ERRESC3 | DSI_CIO_IRQ_ERRESC4 | \ |
| 191 | DSI_CIO_IRQ_ERRESC5 | \ |
| 192 | DSI_CIO_IRQ_ERRCONTROL1 | DSI_CIO_IRQ_ERRCONTROL2 | \ |
| 193 | DSI_CIO_IRQ_ERRCONTROL3 | DSI_CIO_IRQ_ERRCONTROL4 | \ |
| 194 | DSI_CIO_IRQ_ERRCONTROL5 | \ |
Tomi Valkeinen | bbecb50 | 2010-05-10 14:35:33 +0300 | [diff] [blame] | 195 | DSI_CIO_IRQ_ERRCONTENTIONLP0_1 | DSI_CIO_IRQ_ERRCONTENTIONLP1_1 | \ |
| 196 | DSI_CIO_IRQ_ERRCONTENTIONLP0_2 | DSI_CIO_IRQ_ERRCONTENTIONLP1_2 | \ |
Tomi Valkeinen | 6705615 | 2011-03-24 16:30:17 +0200 | [diff] [blame] | 197 | DSI_CIO_IRQ_ERRCONTENTIONLP0_3 | DSI_CIO_IRQ_ERRCONTENTIONLP1_3 | \ |
| 198 | DSI_CIO_IRQ_ERRCONTENTIONLP0_4 | DSI_CIO_IRQ_ERRCONTENTIONLP1_4 | \ |
| 199 | DSI_CIO_IRQ_ERRCONTENTIONLP0_5 | DSI_CIO_IRQ_ERRCONTENTIONLP1_5) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 200 | |
| 201 | #define DSI_DT_DCS_SHORT_WRITE_0 0x05 |
| 202 | #define DSI_DT_DCS_SHORT_WRITE_1 0x15 |
| 203 | #define DSI_DT_DCS_READ 0x06 |
| 204 | #define DSI_DT_SET_MAX_RET_PKG_SIZE 0x37 |
| 205 | #define DSI_DT_NULL_PACKET 0x09 |
| 206 | #define DSI_DT_DCS_LONG_WRITE 0x39 |
| 207 | |
| 208 | #define DSI_DT_RX_ACK_WITH_ERR 0x02 |
| 209 | #define DSI_DT_RX_DCS_LONG_READ 0x1c |
| 210 | #define DSI_DT_RX_SHORT_READ_1 0x21 |
| 211 | #define DSI_DT_RX_SHORT_READ_2 0x22 |
| 212 | |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 213 | typedef void (*omap_dsi_isr_t) (void *arg, u32 mask); |
| 214 | |
| 215 | #define DSI_MAX_NR_ISRS 2 |
| 216 | |
| 217 | struct dsi_isr_data { |
| 218 | omap_dsi_isr_t isr; |
| 219 | void *arg; |
| 220 | u32 mask; |
| 221 | }; |
| 222 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 223 | enum fifo_size { |
| 224 | DSI_FIFO_SIZE_0 = 0, |
| 225 | DSI_FIFO_SIZE_32 = 1, |
| 226 | DSI_FIFO_SIZE_64 = 2, |
| 227 | DSI_FIFO_SIZE_96 = 3, |
| 228 | DSI_FIFO_SIZE_128 = 4, |
| 229 | }; |
| 230 | |
| 231 | enum dsi_vc_mode { |
| 232 | DSI_VC_MODE_L4 = 0, |
| 233 | DSI_VC_MODE_VP, |
| 234 | }; |
| 235 | |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 236 | enum dsi_lane { |
| 237 | DSI_CLK_P = 1 << 0, |
| 238 | DSI_CLK_N = 1 << 1, |
| 239 | DSI_DATA1_P = 1 << 2, |
| 240 | DSI_DATA1_N = 1 << 3, |
| 241 | DSI_DATA2_P = 1 << 4, |
| 242 | DSI_DATA2_N = 1 << 5, |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 243 | DSI_DATA3_P = 1 << 6, |
| 244 | DSI_DATA3_N = 1 << 7, |
| 245 | DSI_DATA4_P = 1 << 8, |
| 246 | DSI_DATA4_N = 1 << 9, |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 247 | }; |
| 248 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 249 | struct dsi_update_region { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 250 | u16 x, y, w, h; |
| 251 | struct omap_dss_device *device; |
| 252 | }; |
| 253 | |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 254 | struct dsi_irq_stats { |
| 255 | unsigned long last_reset; |
| 256 | unsigned irq_count; |
| 257 | unsigned dsi_irqs[32]; |
| 258 | unsigned vc_irqs[4][32]; |
| 259 | unsigned cio_irqs[32]; |
| 260 | }; |
| 261 | |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 262 | struct dsi_isr_tables { |
| 263 | struct dsi_isr_data isr_table[DSI_MAX_NR_ISRS]; |
| 264 | struct dsi_isr_data isr_table_vc[4][DSI_MAX_NR_ISRS]; |
| 265 | struct dsi_isr_data isr_table_cio[DSI_MAX_NR_ISRS]; |
| 266 | }; |
| 267 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 268 | struct dsi_data { |
Senthilvadivu Guruswamy | c8aac01 | 2011-01-24 06:22:02 +0000 | [diff] [blame] | 269 | struct platform_device *pdev; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 270 | void __iomem *base; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 271 | |
archit taneja | affe360 | 2011-02-23 08:41:03 +0000 | [diff] [blame] | 272 | int irq; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 273 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 274 | struct clk *dss_clk; |
| 275 | struct clk *sys_clk; |
| 276 | |
Tomi Valkeinen | 5bc416c | 2011-06-15 15:21:12 +0300 | [diff] [blame] | 277 | int (*enable_pads)(int dsi_id, unsigned lane_mask); |
| 278 | void (*disable_pads)(int dsi_id, unsigned lane_mask); |
Tomi Valkeinen | d1f5857 | 2010-07-30 11:57:57 +0300 | [diff] [blame] | 279 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 280 | struct dsi_clock_info current_cinfo; |
| 281 | |
Tomi Valkeinen | 2a89dc1 | 2010-07-30 12:39:34 +0300 | [diff] [blame] | 282 | bool vdds_dsi_enabled; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 283 | struct regulator *vdds_dsi_reg; |
| 284 | |
| 285 | struct { |
| 286 | enum dsi_vc_mode mode; |
| 287 | struct omap_dss_device *dssdev; |
| 288 | enum fifo_size fifo_size; |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 289 | int vc_id; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 290 | } vc[4]; |
| 291 | |
| 292 | struct mutex lock; |
Tomi Valkeinen | b9eb5d7 | 2010-01-11 16:33:56 +0200 | [diff] [blame] | 293 | struct semaphore bus_lock; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 294 | |
| 295 | unsigned pll_locked; |
| 296 | |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 297 | spinlock_t irq_lock; |
| 298 | struct dsi_isr_tables isr_tables; |
| 299 | /* space for a copy used by the interrupt handler */ |
| 300 | struct dsi_isr_tables isr_tables_copy; |
| 301 | |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 302 | int update_channel; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 303 | struct dsi_update_region update_region; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 304 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 305 | bool te_enabled; |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 306 | bool ulps_enabled; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 307 | |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 308 | void (*framedone_callback)(int, void *); |
| 309 | void *framedone_data; |
| 310 | |
| 311 | struct delayed_work framedone_timeout_work; |
| 312 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 313 | #ifdef DSI_CATCH_MISSING_TE |
| 314 | struct timer_list te_timer; |
| 315 | #endif |
| 316 | |
| 317 | unsigned long cache_req_pck; |
| 318 | unsigned long cache_clk_freq; |
| 319 | struct dsi_clock_info cache_cinfo; |
| 320 | |
| 321 | u32 errors; |
| 322 | spinlock_t errors_lock; |
| 323 | #ifdef DEBUG |
| 324 | ktime_t perf_setup_time; |
| 325 | ktime_t perf_start_time; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 326 | #endif |
| 327 | int debug_read; |
| 328 | int debug_write; |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 329 | |
| 330 | #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS |
| 331 | spinlock_t irq_stats_lock; |
| 332 | struct dsi_irq_stats irq_stats; |
| 333 | #endif |
Taneja, Archit | 4964111 | 2011-03-14 23:28:23 -0500 | [diff] [blame] | 334 | /* DSI PLL Parameter Ranges */ |
| 335 | unsigned long regm_max, regn_max; |
| 336 | unsigned long regm_dispc_max, regm_dsi_max; |
| 337 | unsigned long fint_min, fint_max; |
| 338 | unsigned long lpdiv_max; |
Tomi Valkeinen | 24c1ae4 | 2011-04-13 17:12:52 +0300 | [diff] [blame] | 339 | |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 340 | int num_data_lanes; |
| 341 | |
Tomi Valkeinen | 24c1ae4 | 2011-04-13 17:12:52 +0300 | [diff] [blame] | 342 | unsigned scp_clk_refcount; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 343 | }; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 344 | |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 345 | struct dsi_packet_sent_handler_data { |
| 346 | struct platform_device *dsidev; |
| 347 | struct completion *completion; |
| 348 | }; |
| 349 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 350 | static struct platform_device *dsi_pdev_map[MAX_NUM_DSI]; |
| 351 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 352 | #ifdef DEBUG |
| 353 | static unsigned int dsi_perf; |
| 354 | module_param_named(dsi_perf, dsi_perf, bool, 0644); |
| 355 | #endif |
| 356 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 357 | static inline struct dsi_data *dsi_get_dsidrv_data(struct platform_device *dsidev) |
| 358 | { |
| 359 | return dev_get_drvdata(&dsidev->dev); |
| 360 | } |
| 361 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 362 | static inline struct platform_device *dsi_get_dsidev_from_dssdev(struct omap_dss_device *dssdev) |
| 363 | { |
| 364 | return dsi_pdev_map[dssdev->phy.dsi.module]; |
| 365 | } |
| 366 | |
| 367 | struct platform_device *dsi_get_dsidev_from_id(int module) |
| 368 | { |
| 369 | return dsi_pdev_map[module]; |
| 370 | } |
| 371 | |
Tomi Valkeinen | 7c68dd9 | 2011-08-03 14:00:57 +0300 | [diff] [blame] | 372 | static inline int dsi_get_dsidev_id(struct platform_device *dsidev) |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 373 | { |
Tomi Valkeinen | 7c68dd9 | 2011-08-03 14:00:57 +0300 | [diff] [blame] | 374 | return dsidev->id; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 375 | } |
| 376 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 377 | static inline void dsi_write_reg(struct platform_device *dsidev, |
| 378 | const struct dsi_reg idx, u32 val) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 379 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 380 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 381 | |
| 382 | __raw_writel(val, dsi->base + idx.idx); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 383 | } |
| 384 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 385 | static inline u32 dsi_read_reg(struct platform_device *dsidev, |
| 386 | const struct dsi_reg idx) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 387 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 388 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 389 | |
| 390 | return __raw_readl(dsi->base + idx.idx); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 391 | } |
| 392 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 393 | void dsi_bus_lock(struct omap_dss_device *dssdev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 394 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 395 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 396 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 397 | |
| 398 | down(&dsi->bus_lock); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 399 | } |
| 400 | EXPORT_SYMBOL(dsi_bus_lock); |
| 401 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 402 | void dsi_bus_unlock(struct omap_dss_device *dssdev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 403 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 404 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 405 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 406 | |
| 407 | up(&dsi->bus_lock); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 408 | } |
| 409 | EXPORT_SYMBOL(dsi_bus_unlock); |
| 410 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 411 | static bool dsi_bus_is_locked(struct platform_device *dsidev) |
Tomi Valkeinen | 4f76502 | 2010-01-18 16:27:52 +0200 | [diff] [blame] | 412 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 413 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 414 | |
| 415 | return dsi->bus_lock.count == 0; |
Tomi Valkeinen | 4f76502 | 2010-01-18 16:27:52 +0200 | [diff] [blame] | 416 | } |
| 417 | |
Tomi Valkeinen | f36a06e | 2011-03-02 14:48:41 +0200 | [diff] [blame] | 418 | static void dsi_completion_handler(void *data, u32 mask) |
| 419 | { |
| 420 | complete((struct completion *)data); |
| 421 | } |
| 422 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 423 | static inline int wait_for_bit_change(struct platform_device *dsidev, |
| 424 | const struct dsi_reg idx, int bitnum, int value) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 425 | { |
| 426 | int t = 100000; |
| 427 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 428 | while (REG_GET(dsidev, idx, bitnum, bitnum) != value) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 429 | if (--t == 0) |
| 430 | return !value; |
| 431 | } |
| 432 | |
| 433 | return value; |
| 434 | } |
| 435 | |
| 436 | #ifdef DEBUG |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 437 | static void dsi_perf_mark_setup(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 438 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 439 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 440 | dsi->perf_setup_time = ktime_get(); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 441 | } |
| 442 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 443 | static void dsi_perf_mark_start(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 444 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 445 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 446 | dsi->perf_start_time = ktime_get(); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 447 | } |
| 448 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 449 | static void dsi_perf_show(struct platform_device *dsidev, const char *name) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 450 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 451 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 452 | ktime_t t, setup_time, trans_time; |
| 453 | u32 total_bytes; |
| 454 | u32 setup_us, trans_us, total_us; |
| 455 | |
| 456 | if (!dsi_perf) |
| 457 | return; |
| 458 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 459 | t = ktime_get(); |
| 460 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 461 | setup_time = ktime_sub(dsi->perf_start_time, dsi->perf_setup_time); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 462 | setup_us = (u32)ktime_to_us(setup_time); |
| 463 | if (setup_us == 0) |
| 464 | setup_us = 1; |
| 465 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 466 | trans_time = ktime_sub(t, dsi->perf_start_time); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 467 | trans_us = (u32)ktime_to_us(trans_time); |
| 468 | if (trans_us == 0) |
| 469 | trans_us = 1; |
| 470 | |
| 471 | total_us = setup_us + trans_us; |
| 472 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 473 | total_bytes = dsi->update_region.w * |
| 474 | dsi->update_region.h * |
| 475 | dsi->update_region.device->ctrl.pixel_size / 8; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 476 | |
Tomi Valkeinen | 1bbb275 | 2010-01-11 16:41:10 +0200 | [diff] [blame] | 477 | printk(KERN_INFO "DSI(%s): %u us + %u us = %u us (%uHz), " |
| 478 | "%u bytes, %u kbytes/sec\n", |
| 479 | name, |
| 480 | setup_us, |
| 481 | trans_us, |
| 482 | total_us, |
| 483 | 1000*1000 / total_us, |
| 484 | total_bytes, |
| 485 | total_bytes * 1000 / total_us); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 486 | } |
| 487 | #else |
Tomi Valkeinen | 4a9a5e3 | 2011-05-23 16:36:09 +0300 | [diff] [blame] | 488 | static inline void dsi_perf_mark_setup(struct platform_device *dsidev) |
| 489 | { |
| 490 | } |
| 491 | |
| 492 | static inline void dsi_perf_mark_start(struct platform_device *dsidev) |
| 493 | { |
| 494 | } |
| 495 | |
| 496 | static inline void dsi_perf_show(struct platform_device *dsidev, |
| 497 | const char *name) |
| 498 | { |
| 499 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 500 | #endif |
| 501 | |
| 502 | static void print_irq_status(u32 status) |
| 503 | { |
Tomi Valkeinen | d80d499 | 2011-03-02 15:53:07 +0200 | [diff] [blame] | 504 | if (status == 0) |
| 505 | return; |
| 506 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 507 | #ifndef VERBOSE_IRQ |
| 508 | if ((status & ~DSI_IRQ_CHANNEL_MASK) == 0) |
| 509 | return; |
| 510 | #endif |
| 511 | printk(KERN_DEBUG "DSI IRQ: 0x%x: ", status); |
| 512 | |
| 513 | #define PIS(x) \ |
| 514 | if (status & DSI_IRQ_##x) \ |
| 515 | printk(#x " "); |
| 516 | #ifdef VERBOSE_IRQ |
| 517 | PIS(VC0); |
| 518 | PIS(VC1); |
| 519 | PIS(VC2); |
| 520 | PIS(VC3); |
| 521 | #endif |
| 522 | PIS(WAKEUP); |
| 523 | PIS(RESYNC); |
| 524 | PIS(PLL_LOCK); |
| 525 | PIS(PLL_UNLOCK); |
| 526 | PIS(PLL_RECALL); |
| 527 | PIS(COMPLEXIO_ERR); |
| 528 | PIS(HS_TX_TIMEOUT); |
| 529 | PIS(LP_RX_TIMEOUT); |
| 530 | PIS(TE_TRIGGER); |
| 531 | PIS(ACK_TRIGGER); |
| 532 | PIS(SYNC_LOST); |
| 533 | PIS(LDO_POWER_GOOD); |
| 534 | PIS(TA_TIMEOUT); |
| 535 | #undef PIS |
| 536 | |
| 537 | printk("\n"); |
| 538 | } |
| 539 | |
| 540 | static void print_irq_status_vc(int channel, u32 status) |
| 541 | { |
Tomi Valkeinen | d80d499 | 2011-03-02 15:53:07 +0200 | [diff] [blame] | 542 | if (status == 0) |
| 543 | return; |
| 544 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 545 | #ifndef VERBOSE_IRQ |
| 546 | if ((status & ~DSI_VC_IRQ_PACKET_SENT) == 0) |
| 547 | return; |
| 548 | #endif |
| 549 | printk(KERN_DEBUG "DSI VC(%d) IRQ 0x%x: ", channel, status); |
| 550 | |
| 551 | #define PIS(x) \ |
| 552 | if (status & DSI_VC_IRQ_##x) \ |
| 553 | printk(#x " "); |
| 554 | PIS(CS); |
| 555 | PIS(ECC_CORR); |
| 556 | #ifdef VERBOSE_IRQ |
| 557 | PIS(PACKET_SENT); |
| 558 | #endif |
| 559 | PIS(FIFO_TX_OVF); |
| 560 | PIS(FIFO_RX_OVF); |
| 561 | PIS(BTA); |
| 562 | PIS(ECC_NO_CORR); |
| 563 | PIS(FIFO_TX_UDF); |
| 564 | PIS(PP_BUSY_CHANGE); |
| 565 | #undef PIS |
| 566 | printk("\n"); |
| 567 | } |
| 568 | |
| 569 | static void print_irq_status_cio(u32 status) |
| 570 | { |
Tomi Valkeinen | d80d499 | 2011-03-02 15:53:07 +0200 | [diff] [blame] | 571 | if (status == 0) |
| 572 | return; |
| 573 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 574 | printk(KERN_DEBUG "DSI CIO IRQ 0x%x: ", status); |
| 575 | |
| 576 | #define PIS(x) \ |
| 577 | if (status & DSI_CIO_IRQ_##x) \ |
| 578 | printk(#x " "); |
| 579 | PIS(ERRSYNCESC1); |
| 580 | PIS(ERRSYNCESC2); |
| 581 | PIS(ERRSYNCESC3); |
| 582 | PIS(ERRESC1); |
| 583 | PIS(ERRESC2); |
| 584 | PIS(ERRESC3); |
| 585 | PIS(ERRCONTROL1); |
| 586 | PIS(ERRCONTROL2); |
| 587 | PIS(ERRCONTROL3); |
| 588 | PIS(STATEULPS1); |
| 589 | PIS(STATEULPS2); |
| 590 | PIS(STATEULPS3); |
| 591 | PIS(ERRCONTENTIONLP0_1); |
| 592 | PIS(ERRCONTENTIONLP1_1); |
| 593 | PIS(ERRCONTENTIONLP0_2); |
| 594 | PIS(ERRCONTENTIONLP1_2); |
| 595 | PIS(ERRCONTENTIONLP0_3); |
| 596 | PIS(ERRCONTENTIONLP1_3); |
| 597 | PIS(ULPSACTIVENOT_ALL0); |
| 598 | PIS(ULPSACTIVENOT_ALL1); |
| 599 | #undef PIS |
| 600 | |
| 601 | printk("\n"); |
| 602 | } |
| 603 | |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 604 | #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 605 | static void dsi_collect_irq_stats(struct platform_device *dsidev, u32 irqstatus, |
| 606 | u32 *vcstatus, u32 ciostatus) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 607 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 608 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 609 | int i; |
| 610 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 611 | spin_lock(&dsi->irq_stats_lock); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 612 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 613 | dsi->irq_stats.irq_count++; |
| 614 | dss_collect_irq_stats(irqstatus, dsi->irq_stats.dsi_irqs); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 615 | |
| 616 | for (i = 0; i < 4; ++i) |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 617 | dss_collect_irq_stats(vcstatus[i], dsi->irq_stats.vc_irqs[i]); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 618 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 619 | dss_collect_irq_stats(ciostatus, dsi->irq_stats.cio_irqs); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 620 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 621 | spin_unlock(&dsi->irq_stats_lock); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 622 | } |
| 623 | #else |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 624 | #define dsi_collect_irq_stats(dsidev, irqstatus, vcstatus, ciostatus) |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 625 | #endif |
| 626 | |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 627 | static int debug_irq; |
| 628 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 629 | static void dsi_handle_irq_errors(struct platform_device *dsidev, u32 irqstatus, |
| 630 | u32 *vcstatus, u32 ciostatus) |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 631 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 632 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 633 | int i; |
| 634 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 635 | if (irqstatus & DSI_IRQ_ERROR_MASK) { |
| 636 | DSSERR("DSI error, irqstatus %x\n", irqstatus); |
| 637 | print_irq_status(irqstatus); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 638 | spin_lock(&dsi->errors_lock); |
| 639 | dsi->errors |= irqstatus & DSI_IRQ_ERROR_MASK; |
| 640 | spin_unlock(&dsi->errors_lock); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 641 | } else if (debug_irq) { |
| 642 | print_irq_status(irqstatus); |
| 643 | } |
| 644 | |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 645 | for (i = 0; i < 4; ++i) { |
| 646 | if (vcstatus[i] & DSI_VC_IRQ_ERROR_MASK) { |
| 647 | DSSERR("DSI VC(%d) error, vc irqstatus %x\n", |
| 648 | i, vcstatus[i]); |
| 649 | print_irq_status_vc(i, vcstatus[i]); |
| 650 | } else if (debug_irq) { |
| 651 | print_irq_status_vc(i, vcstatus[i]); |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | if (ciostatus & DSI_CIO_IRQ_ERROR_MASK) { |
| 656 | DSSERR("DSI CIO error, cio irqstatus %x\n", ciostatus); |
| 657 | print_irq_status_cio(ciostatus); |
| 658 | } else if (debug_irq) { |
| 659 | print_irq_status_cio(ciostatus); |
| 660 | } |
| 661 | } |
| 662 | |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 663 | static void dsi_call_isrs(struct dsi_isr_data *isr_array, |
| 664 | unsigned isr_array_size, u32 irqstatus) |
| 665 | { |
| 666 | struct dsi_isr_data *isr_data; |
| 667 | int i; |
| 668 | |
| 669 | for (i = 0; i < isr_array_size; i++) { |
| 670 | isr_data = &isr_array[i]; |
| 671 | if (isr_data->isr && isr_data->mask & irqstatus) |
| 672 | isr_data->isr(isr_data->arg, irqstatus); |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | static void dsi_handle_isrs(struct dsi_isr_tables *isr_tables, |
| 677 | u32 irqstatus, u32 *vcstatus, u32 ciostatus) |
| 678 | { |
| 679 | int i; |
| 680 | |
| 681 | dsi_call_isrs(isr_tables->isr_table, |
| 682 | ARRAY_SIZE(isr_tables->isr_table), |
| 683 | irqstatus); |
| 684 | |
| 685 | for (i = 0; i < 4; ++i) { |
| 686 | if (vcstatus[i] == 0) |
| 687 | continue; |
| 688 | dsi_call_isrs(isr_tables->isr_table_vc[i], |
| 689 | ARRAY_SIZE(isr_tables->isr_table_vc[i]), |
| 690 | vcstatus[i]); |
| 691 | } |
| 692 | |
| 693 | if (ciostatus != 0) |
| 694 | dsi_call_isrs(isr_tables->isr_table_cio, |
| 695 | ARRAY_SIZE(isr_tables->isr_table_cio), |
| 696 | ciostatus); |
| 697 | } |
| 698 | |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 699 | static irqreturn_t omap_dsi_irq_handler(int irq, void *arg) |
| 700 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 701 | struct platform_device *dsidev; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 702 | struct dsi_data *dsi; |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 703 | u32 irqstatus, vcstatus[4], ciostatus; |
| 704 | int i; |
| 705 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 706 | dsidev = (struct platform_device *) arg; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 707 | dsi = dsi_get_dsidrv_data(dsidev); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 708 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 709 | spin_lock(&dsi->irq_lock); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 710 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 711 | irqstatus = dsi_read_reg(dsidev, DSI_IRQSTATUS); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 712 | |
| 713 | /* IRQ is not for us */ |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 714 | if (!irqstatus) { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 715 | spin_unlock(&dsi->irq_lock); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 716 | return IRQ_NONE; |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 717 | } |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 718 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 719 | dsi_write_reg(dsidev, DSI_IRQSTATUS, irqstatus & ~DSI_IRQ_CHANNEL_MASK); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 720 | /* flush posted write */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 721 | dsi_read_reg(dsidev, DSI_IRQSTATUS); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 722 | |
| 723 | for (i = 0; i < 4; ++i) { |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 724 | if ((irqstatus & (1 << i)) == 0) { |
| 725 | vcstatus[i] = 0; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 726 | continue; |
Tomi Valkeinen | ab83b14 | 2010-06-09 15:31:01 +0300 | [diff] [blame] | 727 | } |
| 728 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 729 | vcstatus[i] = dsi_read_reg(dsidev, DSI_VC_IRQSTATUS(i)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 730 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 731 | dsi_write_reg(dsidev, DSI_VC_IRQSTATUS(i), vcstatus[i]); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 732 | /* flush posted write */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 733 | dsi_read_reg(dsidev, DSI_VC_IRQSTATUS(i)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | if (irqstatus & DSI_IRQ_COMPLEXIO_ERR) { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 737 | ciostatus = dsi_read_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 738 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 739 | dsi_write_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS, ciostatus); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 740 | /* flush posted write */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 741 | dsi_read_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 742 | } else { |
| 743 | ciostatus = 0; |
| 744 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 745 | |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 746 | #ifdef DSI_CATCH_MISSING_TE |
| 747 | if (irqstatus & DSI_IRQ_TE_TRIGGER) |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 748 | del_timer(&dsi->te_timer); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 749 | #endif |
| 750 | |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 751 | /* make a copy and unlock, so that isrs can unregister |
| 752 | * themselves */ |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 753 | memcpy(&dsi->isr_tables_copy, &dsi->isr_tables, |
| 754 | sizeof(dsi->isr_tables)); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 755 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 756 | spin_unlock(&dsi->irq_lock); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 757 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 758 | dsi_handle_isrs(&dsi->isr_tables_copy, irqstatus, vcstatus, ciostatus); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 759 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 760 | dsi_handle_irq_errors(dsidev, irqstatus, vcstatus, ciostatus); |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 761 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 762 | dsi_collect_irq_stats(dsidev, irqstatus, vcstatus, ciostatus); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 763 | |
archit taneja | affe360 | 2011-02-23 08:41:03 +0000 | [diff] [blame] | 764 | return IRQ_HANDLED; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 765 | } |
| 766 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 767 | /* dsi->irq_lock has to be locked by the caller */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 768 | static void _omap_dsi_configure_irqs(struct platform_device *dsidev, |
| 769 | struct dsi_isr_data *isr_array, |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 770 | unsigned isr_array_size, u32 default_mask, |
| 771 | const struct dsi_reg enable_reg, |
| 772 | const struct dsi_reg status_reg) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 773 | { |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 774 | struct dsi_isr_data *isr_data; |
| 775 | u32 mask; |
| 776 | u32 old_mask; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 777 | int i; |
| 778 | |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 779 | mask = default_mask; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 780 | |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 781 | for (i = 0; i < isr_array_size; i++) { |
| 782 | isr_data = &isr_array[i]; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 783 | |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 784 | if (isr_data->isr == NULL) |
| 785 | continue; |
| 786 | |
| 787 | mask |= isr_data->mask; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 788 | } |
| 789 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 790 | old_mask = dsi_read_reg(dsidev, enable_reg); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 791 | /* clear the irqstatus for newly enabled irqs */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 792 | dsi_write_reg(dsidev, status_reg, (mask ^ old_mask) & mask); |
| 793 | dsi_write_reg(dsidev, enable_reg, mask); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 794 | |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 795 | /* flush posted writes */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 796 | dsi_read_reg(dsidev, enable_reg); |
| 797 | dsi_read_reg(dsidev, status_reg); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 798 | } |
| 799 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 800 | /* dsi->irq_lock has to be locked by the caller */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 801 | static void _omap_dsi_set_irqs(struct platform_device *dsidev) |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 802 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 803 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 804 | u32 mask = DSI_IRQ_ERROR_MASK; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 805 | #ifdef DSI_CATCH_MISSING_TE |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 806 | mask |= DSI_IRQ_TE_TRIGGER; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 807 | #endif |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 808 | _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table, |
| 809 | ARRAY_SIZE(dsi->isr_tables.isr_table), mask, |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 810 | DSI_IRQENABLE, DSI_IRQSTATUS); |
| 811 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 812 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 813 | /* dsi->irq_lock has to be locked by the caller */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 814 | static void _omap_dsi_set_irqs_vc(struct platform_device *dsidev, int vc) |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 815 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 816 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 817 | |
| 818 | _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table_vc[vc], |
| 819 | ARRAY_SIZE(dsi->isr_tables.isr_table_vc[vc]), |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 820 | DSI_VC_IRQ_ERROR_MASK, |
| 821 | DSI_VC_IRQENABLE(vc), DSI_VC_IRQSTATUS(vc)); |
| 822 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 823 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 824 | /* dsi->irq_lock has to be locked by the caller */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 825 | static void _omap_dsi_set_irqs_cio(struct platform_device *dsidev) |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 826 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 827 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 828 | |
| 829 | _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table_cio, |
| 830 | ARRAY_SIZE(dsi->isr_tables.isr_table_cio), |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 831 | DSI_CIO_IRQ_ERROR_MASK, |
| 832 | DSI_COMPLEXIO_IRQ_ENABLE, DSI_COMPLEXIO_IRQ_STATUS); |
| 833 | } |
| 834 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 835 | static void _dsi_initialize_irq(struct platform_device *dsidev) |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 836 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 837 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 838 | unsigned long flags; |
| 839 | int vc; |
| 840 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 841 | spin_lock_irqsave(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 842 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 843 | memset(&dsi->isr_tables, 0, sizeof(dsi->isr_tables)); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 844 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 845 | _omap_dsi_set_irqs(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 846 | for (vc = 0; vc < 4; ++vc) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 847 | _omap_dsi_set_irqs_vc(dsidev, vc); |
| 848 | _omap_dsi_set_irqs_cio(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 849 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 850 | spin_unlock_irqrestore(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | static int _dsi_register_isr(omap_dsi_isr_t isr, void *arg, u32 mask, |
| 854 | struct dsi_isr_data *isr_array, unsigned isr_array_size) |
| 855 | { |
| 856 | struct dsi_isr_data *isr_data; |
| 857 | int free_idx; |
| 858 | int i; |
| 859 | |
| 860 | BUG_ON(isr == NULL); |
| 861 | |
| 862 | /* check for duplicate entry and find a free slot */ |
| 863 | free_idx = -1; |
| 864 | for (i = 0; i < isr_array_size; i++) { |
| 865 | isr_data = &isr_array[i]; |
| 866 | |
| 867 | if (isr_data->isr == isr && isr_data->arg == arg && |
| 868 | isr_data->mask == mask) { |
| 869 | return -EINVAL; |
| 870 | } |
| 871 | |
| 872 | if (isr_data->isr == NULL && free_idx == -1) |
| 873 | free_idx = i; |
| 874 | } |
| 875 | |
| 876 | if (free_idx == -1) |
| 877 | return -EBUSY; |
| 878 | |
| 879 | isr_data = &isr_array[free_idx]; |
| 880 | isr_data->isr = isr; |
| 881 | isr_data->arg = arg; |
| 882 | isr_data->mask = mask; |
| 883 | |
| 884 | return 0; |
| 885 | } |
| 886 | |
| 887 | static int _dsi_unregister_isr(omap_dsi_isr_t isr, void *arg, u32 mask, |
| 888 | struct dsi_isr_data *isr_array, unsigned isr_array_size) |
| 889 | { |
| 890 | struct dsi_isr_data *isr_data; |
| 891 | int i; |
| 892 | |
| 893 | for (i = 0; i < isr_array_size; i++) { |
| 894 | isr_data = &isr_array[i]; |
| 895 | if (isr_data->isr != isr || isr_data->arg != arg || |
| 896 | isr_data->mask != mask) |
| 897 | continue; |
| 898 | |
| 899 | isr_data->isr = NULL; |
| 900 | isr_data->arg = NULL; |
| 901 | isr_data->mask = 0; |
| 902 | |
| 903 | return 0; |
| 904 | } |
| 905 | |
| 906 | return -EINVAL; |
| 907 | } |
| 908 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 909 | static int dsi_register_isr(struct platform_device *dsidev, omap_dsi_isr_t isr, |
| 910 | void *arg, u32 mask) |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 911 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 912 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 913 | unsigned long flags; |
| 914 | int r; |
| 915 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 916 | spin_lock_irqsave(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 917 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 918 | r = _dsi_register_isr(isr, arg, mask, dsi->isr_tables.isr_table, |
| 919 | ARRAY_SIZE(dsi->isr_tables.isr_table)); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 920 | |
| 921 | if (r == 0) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 922 | _omap_dsi_set_irqs(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 923 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 924 | spin_unlock_irqrestore(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 925 | |
| 926 | return r; |
| 927 | } |
| 928 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 929 | static int dsi_unregister_isr(struct platform_device *dsidev, |
| 930 | omap_dsi_isr_t isr, void *arg, u32 mask) |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 931 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 932 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 933 | unsigned long flags; |
| 934 | int r; |
| 935 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 936 | spin_lock_irqsave(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 937 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 938 | r = _dsi_unregister_isr(isr, arg, mask, dsi->isr_tables.isr_table, |
| 939 | ARRAY_SIZE(dsi->isr_tables.isr_table)); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 940 | |
| 941 | if (r == 0) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 942 | _omap_dsi_set_irqs(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 943 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 944 | spin_unlock_irqrestore(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 945 | |
| 946 | return r; |
| 947 | } |
| 948 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 949 | static int dsi_register_isr_vc(struct platform_device *dsidev, int channel, |
| 950 | omap_dsi_isr_t isr, void *arg, u32 mask) |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 951 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 952 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 953 | unsigned long flags; |
| 954 | int r; |
| 955 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 956 | spin_lock_irqsave(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 957 | |
| 958 | r = _dsi_register_isr(isr, arg, mask, |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 959 | dsi->isr_tables.isr_table_vc[channel], |
| 960 | ARRAY_SIZE(dsi->isr_tables.isr_table_vc[channel])); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 961 | |
| 962 | if (r == 0) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 963 | _omap_dsi_set_irqs_vc(dsidev, channel); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 964 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 965 | spin_unlock_irqrestore(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 966 | |
| 967 | return r; |
| 968 | } |
| 969 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 970 | static int dsi_unregister_isr_vc(struct platform_device *dsidev, int channel, |
| 971 | omap_dsi_isr_t isr, void *arg, u32 mask) |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 972 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 973 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 974 | unsigned long flags; |
| 975 | int r; |
| 976 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 977 | spin_lock_irqsave(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 978 | |
| 979 | r = _dsi_unregister_isr(isr, arg, mask, |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 980 | dsi->isr_tables.isr_table_vc[channel], |
| 981 | ARRAY_SIZE(dsi->isr_tables.isr_table_vc[channel])); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 982 | |
| 983 | if (r == 0) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 984 | _omap_dsi_set_irqs_vc(dsidev, channel); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 985 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 986 | spin_unlock_irqrestore(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 987 | |
| 988 | return r; |
| 989 | } |
| 990 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 991 | static int dsi_register_isr_cio(struct platform_device *dsidev, |
| 992 | omap_dsi_isr_t isr, void *arg, u32 mask) |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 993 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 994 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 995 | unsigned long flags; |
| 996 | int r; |
| 997 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 998 | spin_lock_irqsave(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 999 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1000 | r = _dsi_register_isr(isr, arg, mask, dsi->isr_tables.isr_table_cio, |
| 1001 | ARRAY_SIZE(dsi->isr_tables.isr_table_cio)); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1002 | |
| 1003 | if (r == 0) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1004 | _omap_dsi_set_irqs_cio(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1005 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1006 | spin_unlock_irqrestore(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1007 | |
| 1008 | return r; |
| 1009 | } |
| 1010 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1011 | static int dsi_unregister_isr_cio(struct platform_device *dsidev, |
| 1012 | omap_dsi_isr_t isr, void *arg, u32 mask) |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1013 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1014 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1015 | unsigned long flags; |
| 1016 | int r; |
| 1017 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1018 | spin_lock_irqsave(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1019 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1020 | r = _dsi_unregister_isr(isr, arg, mask, dsi->isr_tables.isr_table_cio, |
| 1021 | ARRAY_SIZE(dsi->isr_tables.isr_table_cio)); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1022 | |
| 1023 | if (r == 0) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1024 | _omap_dsi_set_irqs_cio(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1025 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1026 | spin_unlock_irqrestore(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1027 | |
| 1028 | return r; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1029 | } |
| 1030 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1031 | static u32 dsi_get_errors(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1032 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1033 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1034 | unsigned long flags; |
| 1035 | u32 e; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1036 | spin_lock_irqsave(&dsi->errors_lock, flags); |
| 1037 | e = dsi->errors; |
| 1038 | dsi->errors = 0; |
| 1039 | spin_unlock_irqrestore(&dsi->errors_lock, flags); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1040 | return e; |
| 1041 | } |
| 1042 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1043 | int dsi_runtime_get(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1044 | { |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1045 | int r; |
| 1046 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1047 | |
| 1048 | DSSDBG("dsi_runtime_get\n"); |
| 1049 | |
| 1050 | r = pm_runtime_get_sync(&dsi->pdev->dev); |
| 1051 | WARN_ON(r < 0); |
| 1052 | return r < 0 ? r : 0; |
| 1053 | } |
| 1054 | |
| 1055 | void dsi_runtime_put(struct platform_device *dsidev) |
| 1056 | { |
| 1057 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1058 | int r; |
| 1059 | |
| 1060 | DSSDBG("dsi_runtime_put\n"); |
| 1061 | |
| 1062 | r = pm_runtime_put(&dsi->pdev->dev); |
| 1063 | WARN_ON(r < 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1064 | } |
| 1065 | |
| 1066 | /* source clock for DSI PLL. this could also be PCLKFREE */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1067 | static inline void dsi_enable_pll_clock(struct platform_device *dsidev, |
| 1068 | bool enable) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1069 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1070 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1071 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1072 | if (enable) |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1073 | clk_enable(dsi->sys_clk); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1074 | else |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1075 | clk_disable(dsi->sys_clk); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1076 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1077 | if (enable && dsi->pll_locked) { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1078 | if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 1, 1) != 1) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1079 | DSSERR("cannot lock PLL when enabling clocks\n"); |
| 1080 | } |
| 1081 | } |
| 1082 | |
| 1083 | #ifdef DEBUG |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1084 | static void _dsi_print_reset_status(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1085 | { |
| 1086 | u32 l; |
Tomi Valkeinen | c335cbf | 2010-10-07 13:27:42 +0300 | [diff] [blame] | 1087 | int b0, b1, b2; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1088 | |
| 1089 | if (!dss_debug) |
| 1090 | return; |
| 1091 | |
| 1092 | /* A dummy read using the SCP interface to any DSIPHY register is |
| 1093 | * required after DSIPHY reset to complete the reset of the DSI complex |
| 1094 | * I/O. */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1095 | l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1096 | |
| 1097 | printk(KERN_DEBUG "DSI resets: "); |
| 1098 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1099 | l = dsi_read_reg(dsidev, DSI_PLL_STATUS); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1100 | printk("PLL (%d) ", FLD_GET(l, 0, 0)); |
| 1101 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1102 | l = dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1103 | printk("CIO (%d) ", FLD_GET(l, 29, 29)); |
| 1104 | |
Tomi Valkeinen | c335cbf | 2010-10-07 13:27:42 +0300 | [diff] [blame] | 1105 | if (dss_has_feature(FEAT_DSI_REVERSE_TXCLKESC)) { |
| 1106 | b0 = 28; |
| 1107 | b1 = 27; |
| 1108 | b2 = 26; |
| 1109 | } else { |
| 1110 | b0 = 24; |
| 1111 | b1 = 25; |
| 1112 | b2 = 26; |
| 1113 | } |
| 1114 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1115 | l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5); |
Tomi Valkeinen | c335cbf | 2010-10-07 13:27:42 +0300 | [diff] [blame] | 1116 | printk("PHY (%x%x%x, %d, %d, %d)\n", |
| 1117 | FLD_GET(l, b0, b0), |
| 1118 | FLD_GET(l, b1, b1), |
| 1119 | FLD_GET(l, b2, b2), |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1120 | FLD_GET(l, 29, 29), |
| 1121 | FLD_GET(l, 30, 30), |
| 1122 | FLD_GET(l, 31, 31)); |
| 1123 | } |
| 1124 | #else |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1125 | #define _dsi_print_reset_status(x) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1126 | #endif |
| 1127 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1128 | static inline int dsi_if_enable(struct platform_device *dsidev, bool enable) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1129 | { |
| 1130 | DSSDBG("dsi_if_enable(%d)\n", enable); |
| 1131 | |
| 1132 | enable = enable ? 1 : 0; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1133 | REG_FLD_MOD(dsidev, DSI_CTRL, enable, 0, 0); /* IF_EN */ |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1134 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1135 | if (wait_for_bit_change(dsidev, DSI_CTRL, 0, enable) != enable) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1136 | DSSERR("Failed to set dsi_if_enable to %d\n", enable); |
| 1137 | return -EIO; |
| 1138 | } |
| 1139 | |
| 1140 | return 0; |
| 1141 | } |
| 1142 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1143 | unsigned long dsi_get_pll_hsdiv_dispc_rate(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1144 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1145 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1146 | |
| 1147 | return dsi->current_cinfo.dsi_pll_hsdiv_dispc_clk; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1148 | } |
| 1149 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1150 | static unsigned long dsi_get_pll_hsdiv_dsi_rate(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1151 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1152 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1153 | |
| 1154 | return dsi->current_cinfo.dsi_pll_hsdiv_dsi_clk; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1155 | } |
| 1156 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1157 | static unsigned long dsi_get_txbyteclkhs(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1158 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1159 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1160 | |
| 1161 | return dsi->current_cinfo.clkin4ddr / 16; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1162 | } |
| 1163 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1164 | static unsigned long dsi_fclk_rate(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1165 | { |
| 1166 | unsigned long r; |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 1167 | int dsi_module = dsi_get_dsidev_id(dsidev); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1168 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1169 | |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 1170 | if (dss_get_dsi_clk_source(dsi_module) == OMAP_DSS_CLK_SRC_FCK) { |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1171 | /* DSI FCLK source is DSS_CLK_FCK */ |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1172 | r = clk_get_rate(dsi->dss_clk); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1173 | } else { |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1174 | /* DSI FCLK source is dsi_pll_hsdiv_dsi_clk */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1175 | r = dsi_get_pll_hsdiv_dsi_rate(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1176 | } |
| 1177 | |
| 1178 | return r; |
| 1179 | } |
| 1180 | |
| 1181 | static int dsi_set_lp_clk_divisor(struct omap_dss_device *dssdev) |
| 1182 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1183 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1184 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1185 | unsigned long dsi_fclk; |
| 1186 | unsigned lp_clk_div; |
| 1187 | unsigned long lp_clk; |
| 1188 | |
Tomi Valkeinen | c6940a3 | 2011-02-22 13:36:10 +0200 | [diff] [blame] | 1189 | lp_clk_div = dssdev->clocks.dsi.lp_clk_div; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1190 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1191 | if (lp_clk_div == 0 || lp_clk_div > dsi->lpdiv_max) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1192 | return -EINVAL; |
| 1193 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1194 | dsi_fclk = dsi_fclk_rate(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1195 | |
| 1196 | lp_clk = dsi_fclk / 2 / lp_clk_div; |
| 1197 | |
| 1198 | DSSDBG("LP_CLK_DIV %u, LP_CLK %lu\n", lp_clk_div, lp_clk); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1199 | dsi->current_cinfo.lp_clk = lp_clk; |
| 1200 | dsi->current_cinfo.lp_clk_div = lp_clk_div; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1201 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1202 | /* LP_CLK_DIVISOR */ |
| 1203 | REG_FLD_MOD(dsidev, DSI_CLK_CTRL, lp_clk_div, 12, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1204 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1205 | /* LP_RX_SYNCHRO_ENABLE */ |
| 1206 | REG_FLD_MOD(dsidev, DSI_CLK_CTRL, dsi_fclk > 30000000 ? 1 : 0, 21, 21); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1207 | |
| 1208 | return 0; |
| 1209 | } |
| 1210 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1211 | static void dsi_enable_scp_clk(struct platform_device *dsidev) |
Tomi Valkeinen | 24c1ae4 | 2011-04-13 17:12:52 +0300 | [diff] [blame] | 1212 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1213 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1214 | |
| 1215 | if (dsi->scp_clk_refcount++ == 0) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1216 | REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 14, 14); /* CIO_CLK_ICG */ |
Tomi Valkeinen | 24c1ae4 | 2011-04-13 17:12:52 +0300 | [diff] [blame] | 1217 | } |
| 1218 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1219 | static void dsi_disable_scp_clk(struct platform_device *dsidev) |
Tomi Valkeinen | 24c1ae4 | 2011-04-13 17:12:52 +0300 | [diff] [blame] | 1220 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1221 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1222 | |
| 1223 | WARN_ON(dsi->scp_clk_refcount == 0); |
| 1224 | if (--dsi->scp_clk_refcount == 0) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1225 | REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 14, 14); /* CIO_CLK_ICG */ |
Tomi Valkeinen | 24c1ae4 | 2011-04-13 17:12:52 +0300 | [diff] [blame] | 1226 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1227 | |
| 1228 | enum dsi_pll_power_state { |
| 1229 | DSI_PLL_POWER_OFF = 0x0, |
| 1230 | DSI_PLL_POWER_ON_HSCLK = 0x1, |
| 1231 | DSI_PLL_POWER_ON_ALL = 0x2, |
| 1232 | DSI_PLL_POWER_ON_DIV = 0x3, |
| 1233 | }; |
| 1234 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1235 | static int dsi_pll_power(struct platform_device *dsidev, |
| 1236 | enum dsi_pll_power_state state) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1237 | { |
| 1238 | int t = 0; |
| 1239 | |
Tomi Valkeinen | c94dfe05 | 2011-04-15 10:42:59 +0300 | [diff] [blame] | 1240 | /* DSI-PLL power command 0x3 is not working */ |
| 1241 | if (dss_has_feature(FEAT_DSI_PLL_PWR_BUG) && |
| 1242 | state == DSI_PLL_POWER_ON_DIV) |
| 1243 | state = DSI_PLL_POWER_ON_ALL; |
| 1244 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1245 | /* PLL_PWR_CMD */ |
| 1246 | REG_FLD_MOD(dsidev, DSI_CLK_CTRL, state, 31, 30); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1247 | |
| 1248 | /* PLL_PWR_STATUS */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1249 | while (FLD_GET(dsi_read_reg(dsidev, DSI_CLK_CTRL), 29, 28) != state) { |
Tomi Valkeinen | 24be78b | 2010-01-07 14:19:48 +0200 | [diff] [blame] | 1250 | if (++t > 1000) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1251 | DSSERR("Failed to set DSI PLL power mode to %d\n", |
| 1252 | state); |
| 1253 | return -ENODEV; |
| 1254 | } |
Tomi Valkeinen | 24be78b | 2010-01-07 14:19:48 +0200 | [diff] [blame] | 1255 | udelay(1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1256 | } |
| 1257 | |
| 1258 | return 0; |
| 1259 | } |
| 1260 | |
| 1261 | /* calculate clock rates using dividers in cinfo */ |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 1262 | static int dsi_calc_clock_rates(struct omap_dss_device *dssdev, |
| 1263 | struct dsi_clock_info *cinfo) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1264 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1265 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 1266 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1267 | |
| 1268 | if (cinfo->regn == 0 || cinfo->regn > dsi->regn_max) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1269 | return -EINVAL; |
| 1270 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1271 | if (cinfo->regm == 0 || cinfo->regm > dsi->regm_max) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1272 | return -EINVAL; |
| 1273 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1274 | if (cinfo->regm_dispc > dsi->regm_dispc_max) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1275 | return -EINVAL; |
| 1276 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1277 | if (cinfo->regm_dsi > dsi->regm_dsi_max) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1278 | return -EINVAL; |
| 1279 | |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1280 | if (cinfo->use_sys_clk) { |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1281 | cinfo->clkin = clk_get_rate(dsi->sys_clk); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1282 | /* XXX it is unclear if highfreq should be used |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1283 | * with DSS_SYS_CLK source also */ |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1284 | cinfo->highfreq = 0; |
| 1285 | } else { |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 1286 | cinfo->clkin = dispc_pclk_rate(dssdev->manager->id); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1287 | |
| 1288 | if (cinfo->clkin < 32000000) |
| 1289 | cinfo->highfreq = 0; |
| 1290 | else |
| 1291 | cinfo->highfreq = 1; |
| 1292 | } |
| 1293 | |
| 1294 | cinfo->fint = cinfo->clkin / (cinfo->regn * (cinfo->highfreq ? 2 : 1)); |
| 1295 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1296 | if (cinfo->fint > dsi->fint_max || cinfo->fint < dsi->fint_min) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1297 | return -EINVAL; |
| 1298 | |
| 1299 | cinfo->clkin4ddr = 2 * cinfo->regm * cinfo->fint; |
| 1300 | |
| 1301 | if (cinfo->clkin4ddr > 1800 * 1000 * 1000) |
| 1302 | return -EINVAL; |
| 1303 | |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1304 | if (cinfo->regm_dispc > 0) |
| 1305 | cinfo->dsi_pll_hsdiv_dispc_clk = |
| 1306 | cinfo->clkin4ddr / cinfo->regm_dispc; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1307 | else |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1308 | cinfo->dsi_pll_hsdiv_dispc_clk = 0; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1309 | |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1310 | if (cinfo->regm_dsi > 0) |
| 1311 | cinfo->dsi_pll_hsdiv_dsi_clk = |
| 1312 | cinfo->clkin4ddr / cinfo->regm_dsi; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1313 | else |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1314 | cinfo->dsi_pll_hsdiv_dsi_clk = 0; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1315 | |
| 1316 | return 0; |
| 1317 | } |
| 1318 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1319 | int dsi_pll_calc_clock_div_pck(struct platform_device *dsidev, bool is_tft, |
| 1320 | unsigned long req_pck, struct dsi_clock_info *dsi_cinfo, |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1321 | struct dispc_clock_info *dispc_cinfo) |
| 1322 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1323 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1324 | struct dsi_clock_info cur, best; |
| 1325 | struct dispc_clock_info best_dispc; |
| 1326 | int min_fck_per_pck; |
| 1327 | int match = 0; |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1328 | unsigned long dss_sys_clk, max_dss_fck; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1329 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1330 | dss_sys_clk = clk_get_rate(dsi->sys_clk); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1331 | |
Taneja, Archit | 31ef823 | 2011-03-14 23:28:22 -0500 | [diff] [blame] | 1332 | max_dss_fck = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK); |
Archit Taneja | 819d807 | 2011-03-01 11:54:00 +0530 | [diff] [blame] | 1333 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1334 | if (req_pck == dsi->cache_req_pck && |
| 1335 | dsi->cache_cinfo.clkin == dss_sys_clk) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1336 | DSSDBG("DSI clock info found from cache\n"); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1337 | *dsi_cinfo = dsi->cache_cinfo; |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1338 | dispc_find_clk_divs(is_tft, req_pck, |
| 1339 | dsi_cinfo->dsi_pll_hsdiv_dispc_clk, dispc_cinfo); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1340 | return 0; |
| 1341 | } |
| 1342 | |
| 1343 | min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK; |
| 1344 | |
| 1345 | if (min_fck_per_pck && |
Archit Taneja | 819d807 | 2011-03-01 11:54:00 +0530 | [diff] [blame] | 1346 | req_pck * min_fck_per_pck > max_dss_fck) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1347 | DSSERR("Requested pixel clock not possible with the current " |
| 1348 | "OMAP2_DSS_MIN_FCK_PER_PCK setting. Turning " |
| 1349 | "the constraint off.\n"); |
| 1350 | min_fck_per_pck = 0; |
| 1351 | } |
| 1352 | |
| 1353 | DSSDBG("dsi_pll_calc\n"); |
| 1354 | |
| 1355 | retry: |
| 1356 | memset(&best, 0, sizeof(best)); |
| 1357 | memset(&best_dispc, 0, sizeof(best_dispc)); |
| 1358 | |
| 1359 | memset(&cur, 0, sizeof(cur)); |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1360 | cur.clkin = dss_sys_clk; |
| 1361 | cur.use_sys_clk = 1; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1362 | cur.highfreq = 0; |
| 1363 | |
| 1364 | /* no highfreq: 0.75MHz < Fint = clkin / regn < 2.1MHz */ |
| 1365 | /* highfreq: 0.75MHz < Fint = clkin / (2*regn) < 2.1MHz */ |
| 1366 | /* To reduce PLL lock time, keep Fint high (around 2 MHz) */ |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1367 | for (cur.regn = 1; cur.regn < dsi->regn_max; ++cur.regn) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1368 | if (cur.highfreq == 0) |
| 1369 | cur.fint = cur.clkin / cur.regn; |
| 1370 | else |
| 1371 | cur.fint = cur.clkin / (2 * cur.regn); |
| 1372 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1373 | if (cur.fint > dsi->fint_max || cur.fint < dsi->fint_min) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1374 | continue; |
| 1375 | |
| 1376 | /* DSIPHY(MHz) = (2 * regm / regn) * (clkin / (highfreq + 1)) */ |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1377 | for (cur.regm = 1; cur.regm < dsi->regm_max; ++cur.regm) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1378 | unsigned long a, b; |
| 1379 | |
| 1380 | a = 2 * cur.regm * (cur.clkin/1000); |
| 1381 | b = cur.regn * (cur.highfreq + 1); |
| 1382 | cur.clkin4ddr = a / b * 1000; |
| 1383 | |
| 1384 | if (cur.clkin4ddr > 1800 * 1000 * 1000) |
| 1385 | break; |
| 1386 | |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1387 | /* dsi_pll_hsdiv_dispc_clk(MHz) = |
| 1388 | * DSIPHY(MHz) / regm_dispc < 173MHz/186Mhz */ |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1389 | for (cur.regm_dispc = 1; cur.regm_dispc < |
| 1390 | dsi->regm_dispc_max; ++cur.regm_dispc) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1391 | struct dispc_clock_info cur_dispc; |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1392 | cur.dsi_pll_hsdiv_dispc_clk = |
| 1393 | cur.clkin4ddr / cur.regm_dispc; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1394 | |
| 1395 | /* this will narrow down the search a bit, |
| 1396 | * but still give pixclocks below what was |
| 1397 | * requested */ |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1398 | if (cur.dsi_pll_hsdiv_dispc_clk < req_pck) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1399 | break; |
| 1400 | |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1401 | if (cur.dsi_pll_hsdiv_dispc_clk > max_dss_fck) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1402 | continue; |
| 1403 | |
| 1404 | if (min_fck_per_pck && |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1405 | cur.dsi_pll_hsdiv_dispc_clk < |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1406 | req_pck * min_fck_per_pck) |
| 1407 | continue; |
| 1408 | |
| 1409 | match = 1; |
| 1410 | |
| 1411 | dispc_find_clk_divs(is_tft, req_pck, |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1412 | cur.dsi_pll_hsdiv_dispc_clk, |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1413 | &cur_dispc); |
| 1414 | |
| 1415 | if (abs(cur_dispc.pck - req_pck) < |
| 1416 | abs(best_dispc.pck - req_pck)) { |
| 1417 | best = cur; |
| 1418 | best_dispc = cur_dispc; |
| 1419 | |
| 1420 | if (cur_dispc.pck == req_pck) |
| 1421 | goto found; |
| 1422 | } |
| 1423 | } |
| 1424 | } |
| 1425 | } |
| 1426 | found: |
| 1427 | if (!match) { |
| 1428 | if (min_fck_per_pck) { |
| 1429 | DSSERR("Could not find suitable clock settings.\n" |
| 1430 | "Turning FCK/PCK constraint off and" |
| 1431 | "trying again.\n"); |
| 1432 | min_fck_per_pck = 0; |
| 1433 | goto retry; |
| 1434 | } |
| 1435 | |
| 1436 | DSSERR("Could not find suitable clock settings.\n"); |
| 1437 | |
| 1438 | return -EINVAL; |
| 1439 | } |
| 1440 | |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1441 | /* dsi_pll_hsdiv_dsi_clk (regm_dsi) is not used */ |
| 1442 | best.regm_dsi = 0; |
| 1443 | best.dsi_pll_hsdiv_dsi_clk = 0; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1444 | |
| 1445 | if (dsi_cinfo) |
| 1446 | *dsi_cinfo = best; |
| 1447 | if (dispc_cinfo) |
| 1448 | *dispc_cinfo = best_dispc; |
| 1449 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1450 | dsi->cache_req_pck = req_pck; |
| 1451 | dsi->cache_clk_freq = 0; |
| 1452 | dsi->cache_cinfo = best; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1453 | |
| 1454 | return 0; |
| 1455 | } |
| 1456 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1457 | int dsi_pll_set_clock_div(struct platform_device *dsidev, |
| 1458 | struct dsi_clock_info *cinfo) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1459 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1460 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1461 | int r = 0; |
| 1462 | u32 l; |
Archit Taneja | 9613c02 | 2011-03-22 06:33:36 -0500 | [diff] [blame] | 1463 | int f = 0; |
Taneja, Archit | 4964111 | 2011-03-14 23:28:23 -0500 | [diff] [blame] | 1464 | u8 regn_start, regn_end, regm_start, regm_end; |
| 1465 | u8 regm_dispc_start, regm_dispc_end, regm_dsi_start, regm_dsi_end; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1466 | |
| 1467 | DSSDBGF(); |
| 1468 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1469 | dsi->current_cinfo.use_sys_clk = cinfo->use_sys_clk; |
| 1470 | dsi->current_cinfo.highfreq = cinfo->highfreq; |
Tomi Valkeinen | b276509 | 2011-04-07 15:28:47 +0300 | [diff] [blame] | 1471 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1472 | dsi->current_cinfo.fint = cinfo->fint; |
| 1473 | dsi->current_cinfo.clkin4ddr = cinfo->clkin4ddr; |
| 1474 | dsi->current_cinfo.dsi_pll_hsdiv_dispc_clk = |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1475 | cinfo->dsi_pll_hsdiv_dispc_clk; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1476 | dsi->current_cinfo.dsi_pll_hsdiv_dsi_clk = |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1477 | cinfo->dsi_pll_hsdiv_dsi_clk; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1478 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1479 | dsi->current_cinfo.regn = cinfo->regn; |
| 1480 | dsi->current_cinfo.regm = cinfo->regm; |
| 1481 | dsi->current_cinfo.regm_dispc = cinfo->regm_dispc; |
| 1482 | dsi->current_cinfo.regm_dsi = cinfo->regm_dsi; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1483 | |
| 1484 | DSSDBG("DSI Fint %ld\n", cinfo->fint); |
| 1485 | |
| 1486 | DSSDBG("clkin (%s) rate %ld, highfreq %d\n", |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1487 | cinfo->use_sys_clk ? "dss_sys_clk" : "pclkfree", |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1488 | cinfo->clkin, |
| 1489 | cinfo->highfreq); |
| 1490 | |
| 1491 | /* DSIPHY == CLKIN4DDR */ |
| 1492 | DSSDBG("CLKIN4DDR = 2 * %d / %d * %lu / %d = %lu\n", |
| 1493 | cinfo->regm, |
| 1494 | cinfo->regn, |
| 1495 | cinfo->clkin, |
| 1496 | cinfo->highfreq + 1, |
| 1497 | cinfo->clkin4ddr); |
| 1498 | |
| 1499 | DSSDBG("Data rate on 1 DSI lane %ld Mbps\n", |
| 1500 | cinfo->clkin4ddr / 1000 / 1000 / 2); |
| 1501 | |
| 1502 | DSSDBG("Clock lane freq %ld Hz\n", cinfo->clkin4ddr / 4); |
| 1503 | |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1504 | DSSDBG("regm_dispc = %d, %s (%s) = %lu\n", cinfo->regm_dispc, |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 1505 | dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC), |
| 1506 | dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC), |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1507 | cinfo->dsi_pll_hsdiv_dispc_clk); |
| 1508 | DSSDBG("regm_dsi = %d, %s (%s) = %lu\n", cinfo->regm_dsi, |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 1509 | dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI), |
| 1510 | dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI), |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1511 | cinfo->dsi_pll_hsdiv_dsi_clk); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1512 | |
Taneja, Archit | 4964111 | 2011-03-14 23:28:23 -0500 | [diff] [blame] | 1513 | dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGN, ®n_start, ®n_end); |
| 1514 | dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM, ®m_start, ®m_end); |
| 1515 | dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DISPC, ®m_dispc_start, |
| 1516 | ®m_dispc_end); |
| 1517 | dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DSI, ®m_dsi_start, |
| 1518 | ®m_dsi_end); |
| 1519 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1520 | /* DSI_PLL_AUTOMODE = manual */ |
| 1521 | REG_FLD_MOD(dsidev, DSI_PLL_CONTROL, 0, 0, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1522 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1523 | l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1524 | l = FLD_MOD(l, 1, 0, 0); /* DSI_PLL_STOPMODE */ |
Taneja, Archit | 4964111 | 2011-03-14 23:28:23 -0500 | [diff] [blame] | 1525 | /* DSI_PLL_REGN */ |
| 1526 | l = FLD_MOD(l, cinfo->regn - 1, regn_start, regn_end); |
| 1527 | /* DSI_PLL_REGM */ |
| 1528 | l = FLD_MOD(l, cinfo->regm, regm_start, regm_end); |
| 1529 | /* DSI_CLOCK_DIV */ |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1530 | l = FLD_MOD(l, cinfo->regm_dispc > 0 ? cinfo->regm_dispc - 1 : 0, |
Taneja, Archit | 4964111 | 2011-03-14 23:28:23 -0500 | [diff] [blame] | 1531 | regm_dispc_start, regm_dispc_end); |
| 1532 | /* DSIPROTO_CLOCK_DIV */ |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1533 | l = FLD_MOD(l, cinfo->regm_dsi > 0 ? cinfo->regm_dsi - 1 : 0, |
Taneja, Archit | 4964111 | 2011-03-14 23:28:23 -0500 | [diff] [blame] | 1534 | regm_dsi_start, regm_dsi_end); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1535 | dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION1, l); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1536 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1537 | BUG_ON(cinfo->fint < dsi->fint_min || cinfo->fint > dsi->fint_max); |
Archit Taneja | 9613c02 | 2011-03-22 06:33:36 -0500 | [diff] [blame] | 1538 | |
| 1539 | if (dss_has_feature(FEAT_DSI_PLL_FREQSEL)) { |
| 1540 | f = cinfo->fint < 1000000 ? 0x3 : |
| 1541 | cinfo->fint < 1250000 ? 0x4 : |
| 1542 | cinfo->fint < 1500000 ? 0x5 : |
| 1543 | cinfo->fint < 1750000 ? 0x6 : |
| 1544 | 0x7; |
| 1545 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1546 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1547 | l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION2); |
Archit Taneja | 9613c02 | 2011-03-22 06:33:36 -0500 | [diff] [blame] | 1548 | |
| 1549 | if (dss_has_feature(FEAT_DSI_PLL_FREQSEL)) |
| 1550 | l = FLD_MOD(l, f, 4, 1); /* DSI_PLL_FREQSEL */ |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1551 | l = FLD_MOD(l, cinfo->use_sys_clk ? 0 : 1, |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1552 | 11, 11); /* DSI_PLL_CLKSEL */ |
| 1553 | l = FLD_MOD(l, cinfo->highfreq, |
| 1554 | 12, 12); /* DSI_PLL_HIGHFREQ */ |
| 1555 | l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */ |
| 1556 | l = FLD_MOD(l, 0, 14, 14); /* DSIPHY_CLKINEN */ |
| 1557 | l = FLD_MOD(l, 1, 20, 20); /* DSI_HSDIVBYPASS */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1558 | dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION2, l); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1559 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1560 | REG_FLD_MOD(dsidev, DSI_PLL_GO, 1, 0, 0); /* DSI_PLL_GO */ |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1561 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1562 | if (wait_for_bit_change(dsidev, DSI_PLL_GO, 0, 0) != 0) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1563 | DSSERR("dsi pll go bit not going down.\n"); |
| 1564 | r = -EIO; |
| 1565 | goto err; |
| 1566 | } |
| 1567 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1568 | if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 1, 1) != 1) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1569 | DSSERR("cannot lock PLL\n"); |
| 1570 | r = -EIO; |
| 1571 | goto err; |
| 1572 | } |
| 1573 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1574 | dsi->pll_locked = 1; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1575 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1576 | l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION2); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1577 | l = FLD_MOD(l, 0, 0, 0); /* DSI_PLL_IDLE */ |
| 1578 | l = FLD_MOD(l, 0, 5, 5); /* DSI_PLL_PLLLPMODE */ |
| 1579 | l = FLD_MOD(l, 0, 6, 6); /* DSI_PLL_LOWCURRSTBY */ |
| 1580 | l = FLD_MOD(l, 0, 7, 7); /* DSI_PLL_TIGHTPHASELOCK */ |
| 1581 | l = FLD_MOD(l, 0, 8, 8); /* DSI_PLL_DRIFTGUARDEN */ |
| 1582 | l = FLD_MOD(l, 0, 10, 9); /* DSI_PLL_LOCKSEL */ |
| 1583 | l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */ |
| 1584 | l = FLD_MOD(l, 1, 14, 14); /* DSIPHY_CLKINEN */ |
| 1585 | l = FLD_MOD(l, 0, 15, 15); /* DSI_BYPASSEN */ |
| 1586 | l = FLD_MOD(l, 1, 16, 16); /* DSS_CLOCK_EN */ |
| 1587 | l = FLD_MOD(l, 0, 17, 17); /* DSS_CLOCK_PWDN */ |
| 1588 | l = FLD_MOD(l, 1, 18, 18); /* DSI_PROTO_CLOCK_EN */ |
| 1589 | l = FLD_MOD(l, 0, 19, 19); /* DSI_PROTO_CLOCK_PWDN */ |
| 1590 | l = FLD_MOD(l, 0, 20, 20); /* DSI_HSDIVBYPASS */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1591 | dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION2, l); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1592 | |
| 1593 | DSSDBG("PLL config done\n"); |
| 1594 | err: |
| 1595 | return r; |
| 1596 | } |
| 1597 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1598 | int dsi_pll_init(struct platform_device *dsidev, bool enable_hsclk, |
| 1599 | bool enable_hsdiv) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1600 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1601 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1602 | int r = 0; |
| 1603 | enum dsi_pll_power_state pwstate; |
| 1604 | |
| 1605 | DSSDBG("PLL init\n"); |
| 1606 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1607 | if (dsi->vdds_dsi_reg == NULL) { |
Tomi Valkeinen | f2988ab | 2011-03-02 10:06:48 +0200 | [diff] [blame] | 1608 | struct regulator *vdds_dsi; |
| 1609 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1610 | vdds_dsi = regulator_get(&dsi->pdev->dev, "vdds_dsi"); |
Tomi Valkeinen | f2988ab | 2011-03-02 10:06:48 +0200 | [diff] [blame] | 1611 | |
| 1612 | if (IS_ERR(vdds_dsi)) { |
| 1613 | DSSERR("can't get VDDS_DSI regulator\n"); |
| 1614 | return PTR_ERR(vdds_dsi); |
| 1615 | } |
| 1616 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1617 | dsi->vdds_dsi_reg = vdds_dsi; |
Tomi Valkeinen | f2988ab | 2011-03-02 10:06:48 +0200 | [diff] [blame] | 1618 | } |
Tomi Valkeinen | f2988ab | 2011-03-02 10:06:48 +0200 | [diff] [blame] | 1619 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1620 | dsi_enable_pll_clock(dsidev, 1); |
Tomi Valkeinen | 24c1ae4 | 2011-04-13 17:12:52 +0300 | [diff] [blame] | 1621 | /* |
| 1622 | * Note: SCP CLK is not required on OMAP3, but it is required on OMAP4. |
| 1623 | */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1624 | dsi_enable_scp_clk(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1625 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1626 | if (!dsi->vdds_dsi_enabled) { |
| 1627 | r = regulator_enable(dsi->vdds_dsi_reg); |
Tomi Valkeinen | 2a89dc1 | 2010-07-30 12:39:34 +0300 | [diff] [blame] | 1628 | if (r) |
| 1629 | goto err0; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1630 | dsi->vdds_dsi_enabled = true; |
Tomi Valkeinen | 2a89dc1 | 2010-07-30 12:39:34 +0300 | [diff] [blame] | 1631 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1632 | |
| 1633 | /* XXX PLL does not come out of reset without this... */ |
| 1634 | dispc_pck_free_enable(1); |
| 1635 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1636 | if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 0, 1) != 1) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1637 | DSSERR("PLL not coming out of reset.\n"); |
| 1638 | r = -ENODEV; |
Ville Syrjälä | 481dfa0 | 2010-04-22 22:50:04 +0200 | [diff] [blame] | 1639 | dispc_pck_free_enable(0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1640 | goto err1; |
| 1641 | } |
| 1642 | |
| 1643 | /* XXX ... but if left on, we get problems when planes do not |
| 1644 | * fill the whole display. No idea about this */ |
| 1645 | dispc_pck_free_enable(0); |
| 1646 | |
| 1647 | if (enable_hsclk && enable_hsdiv) |
| 1648 | pwstate = DSI_PLL_POWER_ON_ALL; |
| 1649 | else if (enable_hsclk) |
| 1650 | pwstate = DSI_PLL_POWER_ON_HSCLK; |
| 1651 | else if (enable_hsdiv) |
| 1652 | pwstate = DSI_PLL_POWER_ON_DIV; |
| 1653 | else |
| 1654 | pwstate = DSI_PLL_POWER_OFF; |
| 1655 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1656 | r = dsi_pll_power(dsidev, pwstate); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1657 | |
| 1658 | if (r) |
| 1659 | goto err1; |
| 1660 | |
| 1661 | DSSDBG("PLL init done\n"); |
| 1662 | |
| 1663 | return 0; |
| 1664 | err1: |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1665 | if (dsi->vdds_dsi_enabled) { |
| 1666 | regulator_disable(dsi->vdds_dsi_reg); |
| 1667 | dsi->vdds_dsi_enabled = false; |
Tomi Valkeinen | 2a89dc1 | 2010-07-30 12:39:34 +0300 | [diff] [blame] | 1668 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1669 | err0: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1670 | dsi_disable_scp_clk(dsidev); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1671 | dsi_enable_pll_clock(dsidev, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1672 | return r; |
| 1673 | } |
| 1674 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1675 | void dsi_pll_uninit(struct platform_device *dsidev, bool disconnect_lanes) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1676 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1677 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1678 | |
| 1679 | dsi->pll_locked = 0; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1680 | dsi_pll_power(dsidev, DSI_PLL_POWER_OFF); |
Tomi Valkeinen | 2a89dc1 | 2010-07-30 12:39:34 +0300 | [diff] [blame] | 1681 | if (disconnect_lanes) { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1682 | WARN_ON(!dsi->vdds_dsi_enabled); |
| 1683 | regulator_disable(dsi->vdds_dsi_reg); |
| 1684 | dsi->vdds_dsi_enabled = false; |
Tomi Valkeinen | 2a89dc1 | 2010-07-30 12:39:34 +0300 | [diff] [blame] | 1685 | } |
Tomi Valkeinen | 24c1ae4 | 2011-04-13 17:12:52 +0300 | [diff] [blame] | 1686 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1687 | dsi_disable_scp_clk(dsidev); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1688 | dsi_enable_pll_clock(dsidev, 0); |
Tomi Valkeinen | 24c1ae4 | 2011-04-13 17:12:52 +0300 | [diff] [blame] | 1689 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1690 | DSSDBG("PLL uninit done\n"); |
| 1691 | } |
| 1692 | |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 1693 | static void dsi_dump_dsidev_clocks(struct platform_device *dsidev, |
| 1694 | struct seq_file *s) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1695 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1696 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1697 | struct dsi_clock_info *cinfo = &dsi->current_cinfo; |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 1698 | enum omap_dss_clk_source dispc_clk_src, dsi_clk_src; |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 1699 | int dsi_module = dsi_get_dsidev_id(dsidev); |
Archit Taneja | 067a57e | 2011-03-02 11:57:25 +0530 | [diff] [blame] | 1700 | |
| 1701 | dispc_clk_src = dss_get_dispc_clk_source(); |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 1702 | dsi_clk_src = dss_get_dsi_clk_source(dsi_module); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1703 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1704 | if (dsi_runtime_get(dsidev)) |
| 1705 | return; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1706 | |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 1707 | seq_printf(s, "- DSI%d PLL -\n", dsi_module + 1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1708 | |
| 1709 | seq_printf(s, "dsi pll source = %s\n", |
Tomi Valkeinen | a9a6500 | 2011-04-04 10:02:53 +0300 | [diff] [blame] | 1710 | cinfo->use_sys_clk ? "dss_sys_clk" : "pclkfree"); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1711 | |
| 1712 | seq_printf(s, "Fint\t\t%-16luregn %u\n", cinfo->fint, cinfo->regn); |
| 1713 | |
| 1714 | seq_printf(s, "CLKIN4DDR\t%-16luregm %u\n", |
| 1715 | cinfo->clkin4ddr, cinfo->regm); |
| 1716 | |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1717 | seq_printf(s, "%s (%s)\t%-16luregm_dispc %u\t(%s)\n", |
Archit Taneja | 067a57e | 2011-03-02 11:57:25 +0530 | [diff] [blame] | 1718 | dss_get_generic_clk_source_name(dispc_clk_src), |
| 1719 | dss_feat_get_clk_source_name(dispc_clk_src), |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1720 | cinfo->dsi_pll_hsdiv_dispc_clk, |
| 1721 | cinfo->regm_dispc, |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 1722 | dispc_clk_src == OMAP_DSS_CLK_SRC_FCK ? |
Tomi Valkeinen | 63cf28a | 2010-02-23 17:40:00 +0200 | [diff] [blame] | 1723 | "off" : "on"); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1724 | |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1725 | seq_printf(s, "%s (%s)\t%-16luregm_dsi %u\t(%s)\n", |
Archit Taneja | 067a57e | 2011-03-02 11:57:25 +0530 | [diff] [blame] | 1726 | dss_get_generic_clk_source_name(dsi_clk_src), |
| 1727 | dss_feat_get_clk_source_name(dsi_clk_src), |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1728 | cinfo->dsi_pll_hsdiv_dsi_clk, |
| 1729 | cinfo->regm_dsi, |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 1730 | dsi_clk_src == OMAP_DSS_CLK_SRC_FCK ? |
Tomi Valkeinen | 63cf28a | 2010-02-23 17:40:00 +0200 | [diff] [blame] | 1731 | "off" : "on"); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1732 | |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 1733 | seq_printf(s, "- DSI%d -\n", dsi_module + 1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1734 | |
Archit Taneja | 067a57e | 2011-03-02 11:57:25 +0530 | [diff] [blame] | 1735 | seq_printf(s, "dsi fclk source = %s (%s)\n", |
| 1736 | dss_get_generic_clk_source_name(dsi_clk_src), |
| 1737 | dss_feat_get_clk_source_name(dsi_clk_src)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1738 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1739 | seq_printf(s, "DSI_FCLK\t%lu\n", dsi_fclk_rate(dsidev)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1740 | |
| 1741 | seq_printf(s, "DDR_CLK\t\t%lu\n", |
| 1742 | cinfo->clkin4ddr / 4); |
| 1743 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1744 | seq_printf(s, "TxByteClkHS\t%lu\n", dsi_get_txbyteclkhs(dsidev)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1745 | |
| 1746 | seq_printf(s, "LP_CLK\t\t%lu\n", cinfo->lp_clk); |
| 1747 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1748 | dsi_runtime_put(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1749 | } |
| 1750 | |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 1751 | void dsi_dump_clocks(struct seq_file *s) |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 1752 | { |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 1753 | struct platform_device *dsidev; |
| 1754 | int i; |
| 1755 | |
| 1756 | for (i = 0; i < MAX_NUM_DSI; i++) { |
| 1757 | dsidev = dsi_get_dsidev_from_id(i); |
| 1758 | if (dsidev) |
| 1759 | dsi_dump_dsidev_clocks(dsidev, s); |
| 1760 | } |
| 1761 | } |
| 1762 | |
| 1763 | #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS |
| 1764 | static void dsi_dump_dsidev_irqs(struct platform_device *dsidev, |
| 1765 | struct seq_file *s) |
| 1766 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1767 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 1768 | unsigned long flags; |
| 1769 | struct dsi_irq_stats stats; |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 1770 | int dsi_module = dsi_get_dsidev_id(dsidev); |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 1771 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1772 | spin_lock_irqsave(&dsi->irq_stats_lock, flags); |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 1773 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1774 | stats = dsi->irq_stats; |
| 1775 | memset(&dsi->irq_stats, 0, sizeof(dsi->irq_stats)); |
| 1776 | dsi->irq_stats.last_reset = jiffies; |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 1777 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1778 | spin_unlock_irqrestore(&dsi->irq_stats_lock, flags); |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 1779 | |
| 1780 | seq_printf(s, "period %u ms\n", |
| 1781 | jiffies_to_msecs(jiffies - stats.last_reset)); |
| 1782 | |
| 1783 | seq_printf(s, "irqs %d\n", stats.irq_count); |
| 1784 | #define PIS(x) \ |
| 1785 | seq_printf(s, "%-20s %10d\n", #x, stats.dsi_irqs[ffs(DSI_IRQ_##x)-1]); |
| 1786 | |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 1787 | seq_printf(s, "-- DSI%d interrupts --\n", dsi_module + 1); |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 1788 | PIS(VC0); |
| 1789 | PIS(VC1); |
| 1790 | PIS(VC2); |
| 1791 | PIS(VC3); |
| 1792 | PIS(WAKEUP); |
| 1793 | PIS(RESYNC); |
| 1794 | PIS(PLL_LOCK); |
| 1795 | PIS(PLL_UNLOCK); |
| 1796 | PIS(PLL_RECALL); |
| 1797 | PIS(COMPLEXIO_ERR); |
| 1798 | PIS(HS_TX_TIMEOUT); |
| 1799 | PIS(LP_RX_TIMEOUT); |
| 1800 | PIS(TE_TRIGGER); |
| 1801 | PIS(ACK_TRIGGER); |
| 1802 | PIS(SYNC_LOST); |
| 1803 | PIS(LDO_POWER_GOOD); |
| 1804 | PIS(TA_TIMEOUT); |
| 1805 | #undef PIS |
| 1806 | |
| 1807 | #define PIS(x) \ |
| 1808 | seq_printf(s, "%-20s %10d %10d %10d %10d\n", #x, \ |
| 1809 | stats.vc_irqs[0][ffs(DSI_VC_IRQ_##x)-1], \ |
| 1810 | stats.vc_irqs[1][ffs(DSI_VC_IRQ_##x)-1], \ |
| 1811 | stats.vc_irqs[2][ffs(DSI_VC_IRQ_##x)-1], \ |
| 1812 | stats.vc_irqs[3][ffs(DSI_VC_IRQ_##x)-1]); |
| 1813 | |
| 1814 | seq_printf(s, "-- VC interrupts --\n"); |
| 1815 | PIS(CS); |
| 1816 | PIS(ECC_CORR); |
| 1817 | PIS(PACKET_SENT); |
| 1818 | PIS(FIFO_TX_OVF); |
| 1819 | PIS(FIFO_RX_OVF); |
| 1820 | PIS(BTA); |
| 1821 | PIS(ECC_NO_CORR); |
| 1822 | PIS(FIFO_TX_UDF); |
| 1823 | PIS(PP_BUSY_CHANGE); |
| 1824 | #undef PIS |
| 1825 | |
| 1826 | #define PIS(x) \ |
| 1827 | seq_printf(s, "%-20s %10d\n", #x, \ |
| 1828 | stats.cio_irqs[ffs(DSI_CIO_IRQ_##x)-1]); |
| 1829 | |
| 1830 | seq_printf(s, "-- CIO interrupts --\n"); |
| 1831 | PIS(ERRSYNCESC1); |
| 1832 | PIS(ERRSYNCESC2); |
| 1833 | PIS(ERRSYNCESC3); |
| 1834 | PIS(ERRESC1); |
| 1835 | PIS(ERRESC2); |
| 1836 | PIS(ERRESC3); |
| 1837 | PIS(ERRCONTROL1); |
| 1838 | PIS(ERRCONTROL2); |
| 1839 | PIS(ERRCONTROL3); |
| 1840 | PIS(STATEULPS1); |
| 1841 | PIS(STATEULPS2); |
| 1842 | PIS(STATEULPS3); |
| 1843 | PIS(ERRCONTENTIONLP0_1); |
| 1844 | PIS(ERRCONTENTIONLP1_1); |
| 1845 | PIS(ERRCONTENTIONLP0_2); |
| 1846 | PIS(ERRCONTENTIONLP1_2); |
| 1847 | PIS(ERRCONTENTIONLP0_3); |
| 1848 | PIS(ERRCONTENTIONLP1_3); |
| 1849 | PIS(ULPSACTIVENOT_ALL0); |
| 1850 | PIS(ULPSACTIVENOT_ALL1); |
| 1851 | #undef PIS |
| 1852 | } |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 1853 | |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 1854 | static void dsi1_dump_irqs(struct seq_file *s) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1855 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1856 | struct platform_device *dsidev = dsi_get_dsidev_from_id(0); |
| 1857 | |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 1858 | dsi_dump_dsidev_irqs(dsidev, s); |
| 1859 | } |
| 1860 | |
| 1861 | static void dsi2_dump_irqs(struct seq_file *s) |
| 1862 | { |
| 1863 | struct platform_device *dsidev = dsi_get_dsidev_from_id(1); |
| 1864 | |
| 1865 | dsi_dump_dsidev_irqs(dsidev, s); |
| 1866 | } |
| 1867 | |
| 1868 | void dsi_create_debugfs_files_irq(struct dentry *debugfs_dir, |
| 1869 | const struct file_operations *debug_fops) |
| 1870 | { |
| 1871 | struct platform_device *dsidev; |
| 1872 | |
| 1873 | dsidev = dsi_get_dsidev_from_id(0); |
| 1874 | if (dsidev) |
| 1875 | debugfs_create_file("dsi1_irqs", S_IRUGO, debugfs_dir, |
| 1876 | &dsi1_dump_irqs, debug_fops); |
| 1877 | |
| 1878 | dsidev = dsi_get_dsidev_from_id(1); |
| 1879 | if (dsidev) |
| 1880 | debugfs_create_file("dsi2_irqs", S_IRUGO, debugfs_dir, |
| 1881 | &dsi2_dump_irqs, debug_fops); |
| 1882 | } |
| 1883 | #endif |
| 1884 | |
| 1885 | static void dsi_dump_dsidev_regs(struct platform_device *dsidev, |
| 1886 | struct seq_file *s) |
| 1887 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1888 | #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dsi_read_reg(dsidev, r)) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1889 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1890 | if (dsi_runtime_get(dsidev)) |
| 1891 | return; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1892 | dsi_enable_scp_clk(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1893 | |
| 1894 | DUMPREG(DSI_REVISION); |
| 1895 | DUMPREG(DSI_SYSCONFIG); |
| 1896 | DUMPREG(DSI_SYSSTATUS); |
| 1897 | DUMPREG(DSI_IRQSTATUS); |
| 1898 | DUMPREG(DSI_IRQENABLE); |
| 1899 | DUMPREG(DSI_CTRL); |
| 1900 | DUMPREG(DSI_COMPLEXIO_CFG1); |
| 1901 | DUMPREG(DSI_COMPLEXIO_IRQ_STATUS); |
| 1902 | DUMPREG(DSI_COMPLEXIO_IRQ_ENABLE); |
| 1903 | DUMPREG(DSI_CLK_CTRL); |
| 1904 | DUMPREG(DSI_TIMING1); |
| 1905 | DUMPREG(DSI_TIMING2); |
| 1906 | DUMPREG(DSI_VM_TIMING1); |
| 1907 | DUMPREG(DSI_VM_TIMING2); |
| 1908 | DUMPREG(DSI_VM_TIMING3); |
| 1909 | DUMPREG(DSI_CLK_TIMING); |
| 1910 | DUMPREG(DSI_TX_FIFO_VC_SIZE); |
| 1911 | DUMPREG(DSI_RX_FIFO_VC_SIZE); |
| 1912 | DUMPREG(DSI_COMPLEXIO_CFG2); |
| 1913 | DUMPREG(DSI_RX_FIFO_VC_FULLNESS); |
| 1914 | DUMPREG(DSI_VM_TIMING4); |
| 1915 | DUMPREG(DSI_TX_FIFO_VC_EMPTINESS); |
| 1916 | DUMPREG(DSI_VM_TIMING5); |
| 1917 | DUMPREG(DSI_VM_TIMING6); |
| 1918 | DUMPREG(DSI_VM_TIMING7); |
| 1919 | DUMPREG(DSI_STOPCLK_TIMING); |
| 1920 | |
| 1921 | DUMPREG(DSI_VC_CTRL(0)); |
| 1922 | DUMPREG(DSI_VC_TE(0)); |
| 1923 | DUMPREG(DSI_VC_LONG_PACKET_HEADER(0)); |
| 1924 | DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(0)); |
| 1925 | DUMPREG(DSI_VC_SHORT_PACKET_HEADER(0)); |
| 1926 | DUMPREG(DSI_VC_IRQSTATUS(0)); |
| 1927 | DUMPREG(DSI_VC_IRQENABLE(0)); |
| 1928 | |
| 1929 | DUMPREG(DSI_VC_CTRL(1)); |
| 1930 | DUMPREG(DSI_VC_TE(1)); |
| 1931 | DUMPREG(DSI_VC_LONG_PACKET_HEADER(1)); |
| 1932 | DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(1)); |
| 1933 | DUMPREG(DSI_VC_SHORT_PACKET_HEADER(1)); |
| 1934 | DUMPREG(DSI_VC_IRQSTATUS(1)); |
| 1935 | DUMPREG(DSI_VC_IRQENABLE(1)); |
| 1936 | |
| 1937 | DUMPREG(DSI_VC_CTRL(2)); |
| 1938 | DUMPREG(DSI_VC_TE(2)); |
| 1939 | DUMPREG(DSI_VC_LONG_PACKET_HEADER(2)); |
| 1940 | DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(2)); |
| 1941 | DUMPREG(DSI_VC_SHORT_PACKET_HEADER(2)); |
| 1942 | DUMPREG(DSI_VC_IRQSTATUS(2)); |
| 1943 | DUMPREG(DSI_VC_IRQENABLE(2)); |
| 1944 | |
| 1945 | DUMPREG(DSI_VC_CTRL(3)); |
| 1946 | DUMPREG(DSI_VC_TE(3)); |
| 1947 | DUMPREG(DSI_VC_LONG_PACKET_HEADER(3)); |
| 1948 | DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(3)); |
| 1949 | DUMPREG(DSI_VC_SHORT_PACKET_HEADER(3)); |
| 1950 | DUMPREG(DSI_VC_IRQSTATUS(3)); |
| 1951 | DUMPREG(DSI_VC_IRQENABLE(3)); |
| 1952 | |
| 1953 | DUMPREG(DSI_DSIPHY_CFG0); |
| 1954 | DUMPREG(DSI_DSIPHY_CFG1); |
| 1955 | DUMPREG(DSI_DSIPHY_CFG2); |
| 1956 | DUMPREG(DSI_DSIPHY_CFG5); |
| 1957 | |
| 1958 | DUMPREG(DSI_PLL_CONTROL); |
| 1959 | DUMPREG(DSI_PLL_STATUS); |
| 1960 | DUMPREG(DSI_PLL_GO); |
| 1961 | DUMPREG(DSI_PLL_CONFIGURATION1); |
| 1962 | DUMPREG(DSI_PLL_CONFIGURATION2); |
| 1963 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1964 | dsi_disable_scp_clk(dsidev); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1965 | dsi_runtime_put(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1966 | #undef DUMPREG |
| 1967 | } |
| 1968 | |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 1969 | static void dsi1_dump_regs(struct seq_file *s) |
| 1970 | { |
| 1971 | struct platform_device *dsidev = dsi_get_dsidev_from_id(0); |
| 1972 | |
| 1973 | dsi_dump_dsidev_regs(dsidev, s); |
| 1974 | } |
| 1975 | |
| 1976 | static void dsi2_dump_regs(struct seq_file *s) |
| 1977 | { |
| 1978 | struct platform_device *dsidev = dsi_get_dsidev_from_id(1); |
| 1979 | |
| 1980 | dsi_dump_dsidev_regs(dsidev, s); |
| 1981 | } |
| 1982 | |
| 1983 | void dsi_create_debugfs_files_reg(struct dentry *debugfs_dir, |
| 1984 | const struct file_operations *debug_fops) |
| 1985 | { |
| 1986 | struct platform_device *dsidev; |
| 1987 | |
| 1988 | dsidev = dsi_get_dsidev_from_id(0); |
| 1989 | if (dsidev) |
| 1990 | debugfs_create_file("dsi1_regs", S_IRUGO, debugfs_dir, |
| 1991 | &dsi1_dump_regs, debug_fops); |
| 1992 | |
| 1993 | dsidev = dsi_get_dsidev_from_id(1); |
| 1994 | if (dsidev) |
| 1995 | debugfs_create_file("dsi2_regs", S_IRUGO, debugfs_dir, |
| 1996 | &dsi2_dump_regs, debug_fops); |
| 1997 | } |
Tomi Valkeinen | cc5c185 | 2010-10-06 15:18:13 +0300 | [diff] [blame] | 1998 | enum dsi_cio_power_state { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1999 | DSI_COMPLEXIO_POWER_OFF = 0x0, |
| 2000 | DSI_COMPLEXIO_POWER_ON = 0x1, |
| 2001 | DSI_COMPLEXIO_POWER_ULPS = 0x2, |
| 2002 | }; |
| 2003 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2004 | static int dsi_cio_power(struct platform_device *dsidev, |
| 2005 | enum dsi_cio_power_state state) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2006 | { |
| 2007 | int t = 0; |
| 2008 | |
| 2009 | /* PWR_CMD */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2010 | REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG1, state, 28, 27); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2011 | |
| 2012 | /* PWR_STATUS */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2013 | while (FLD_GET(dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1), |
| 2014 | 26, 25) != state) { |
Tomi Valkeinen | 24be78b | 2010-01-07 14:19:48 +0200 | [diff] [blame] | 2015 | if (++t > 1000) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2016 | DSSERR("failed to set complexio power state to " |
| 2017 | "%d\n", state); |
| 2018 | return -ENODEV; |
| 2019 | } |
Tomi Valkeinen | 24be78b | 2010-01-07 14:19:48 +0200 | [diff] [blame] | 2020 | udelay(1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2021 | } |
| 2022 | |
| 2023 | return 0; |
| 2024 | } |
| 2025 | |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 2026 | /* Number of data lanes present on DSI interface */ |
| 2027 | static inline int dsi_get_num_data_lanes(struct platform_device *dsidev) |
| 2028 | { |
| 2029 | /* DSI on OMAP3 doesn't have register DSI_GNQ, set number |
| 2030 | * of data lanes as 2 by default */ |
| 2031 | if (dss_has_feature(FEAT_DSI_GNQ)) |
| 2032 | return REG_GET(dsidev, DSI_GNQ, 11, 9); /* NB_DATA_LANES */ |
| 2033 | else |
| 2034 | return 2; |
| 2035 | } |
| 2036 | |
| 2037 | /* Number of data lanes used by the dss device */ |
| 2038 | static inline int dsi_get_num_data_lanes_dssdev(struct omap_dss_device *dssdev) |
| 2039 | { |
| 2040 | int num_data_lanes = 0; |
| 2041 | |
| 2042 | if (dssdev->phy.dsi.data1_lane != 0) |
| 2043 | num_data_lanes++; |
| 2044 | if (dssdev->phy.dsi.data2_lane != 0) |
| 2045 | num_data_lanes++; |
| 2046 | if (dssdev->phy.dsi.data3_lane != 0) |
| 2047 | num_data_lanes++; |
| 2048 | if (dssdev->phy.dsi.data4_lane != 0) |
| 2049 | num_data_lanes++; |
| 2050 | |
| 2051 | return num_data_lanes; |
| 2052 | } |
| 2053 | |
Archit Taneja | 0c65622b | 2011-05-16 15:17:09 +0530 | [diff] [blame] | 2054 | static unsigned dsi_get_line_buf_size(struct platform_device *dsidev) |
| 2055 | { |
| 2056 | int val; |
| 2057 | |
| 2058 | /* line buffer on OMAP3 is 1024 x 24bits */ |
| 2059 | /* XXX: for some reason using full buffer size causes |
| 2060 | * considerable TX slowdown with update sizes that fill the |
| 2061 | * whole buffer */ |
| 2062 | if (!dss_has_feature(FEAT_DSI_GNQ)) |
| 2063 | return 1023 * 3; |
| 2064 | |
| 2065 | val = REG_GET(dsidev, DSI_GNQ, 14, 12); /* VP1_LINE_BUFFER_SIZE */ |
| 2066 | |
| 2067 | switch (val) { |
| 2068 | case 1: |
| 2069 | return 512 * 3; /* 512x24 bits */ |
| 2070 | case 2: |
| 2071 | return 682 * 3; /* 682x24 bits */ |
| 2072 | case 3: |
| 2073 | return 853 * 3; /* 853x24 bits */ |
| 2074 | case 4: |
| 2075 | return 1024 * 3; /* 1024x24 bits */ |
| 2076 | case 5: |
| 2077 | return 1194 * 3; /* 1194x24 bits */ |
| 2078 | case 6: |
| 2079 | return 1365 * 3; /* 1365x24 bits */ |
| 2080 | default: |
| 2081 | BUG(); |
| 2082 | } |
| 2083 | } |
| 2084 | |
Tomi Valkeinen | cc5c185 | 2010-10-06 15:18:13 +0300 | [diff] [blame] | 2085 | static void dsi_set_lane_config(struct omap_dss_device *dssdev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2086 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2087 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2088 | u32 r; |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 2089 | int num_data_lanes_dssdev = dsi_get_num_data_lanes_dssdev(dssdev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2090 | |
| 2091 | int clk_lane = dssdev->phy.dsi.clk_lane; |
| 2092 | int data1_lane = dssdev->phy.dsi.data1_lane; |
| 2093 | int data2_lane = dssdev->phy.dsi.data2_lane; |
| 2094 | int clk_pol = dssdev->phy.dsi.clk_pol; |
| 2095 | int data1_pol = dssdev->phy.dsi.data1_pol; |
| 2096 | int data2_pol = dssdev->phy.dsi.data2_pol; |
| 2097 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2098 | r = dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2099 | r = FLD_MOD(r, clk_lane, 2, 0); |
| 2100 | r = FLD_MOD(r, clk_pol, 3, 3); |
| 2101 | r = FLD_MOD(r, data1_lane, 6, 4); |
| 2102 | r = FLD_MOD(r, data1_pol, 7, 7); |
| 2103 | r = FLD_MOD(r, data2_lane, 10, 8); |
| 2104 | r = FLD_MOD(r, data2_pol, 11, 11); |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 2105 | if (num_data_lanes_dssdev > 2) { |
| 2106 | int data3_lane = dssdev->phy.dsi.data3_lane; |
| 2107 | int data3_pol = dssdev->phy.dsi.data3_pol; |
| 2108 | |
| 2109 | r = FLD_MOD(r, data3_lane, 14, 12); |
| 2110 | r = FLD_MOD(r, data3_pol, 15, 15); |
| 2111 | } |
| 2112 | if (num_data_lanes_dssdev > 3) { |
| 2113 | int data4_lane = dssdev->phy.dsi.data4_lane; |
| 2114 | int data4_pol = dssdev->phy.dsi.data4_pol; |
| 2115 | |
| 2116 | r = FLD_MOD(r, data4_lane, 18, 16); |
| 2117 | r = FLD_MOD(r, data4_pol, 19, 19); |
| 2118 | } |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2119 | dsi_write_reg(dsidev, DSI_COMPLEXIO_CFG1, r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2120 | |
| 2121 | /* The configuration of the DSI complex I/O (number of data lanes, |
| 2122 | position, differential order) should not be changed while |
| 2123 | DSS.DSI_CLK_CRTRL[20] LP_CLK_ENABLE bit is set to 1. In order for |
| 2124 | the hardware to take into account a new configuration of the complex |
| 2125 | I/O (done in DSS.DSI_COMPLEXIO_CFG1 register), it is recommended to |
| 2126 | follow this sequence: First set the DSS.DSI_CTRL[0] IF_EN bit to 1, |
| 2127 | then reset the DSS.DSI_CTRL[0] IF_EN to 0, then set |
| 2128 | DSS.DSI_CLK_CTRL[20] LP_CLK_ENABLE to 1 and finally set again the |
| 2129 | DSS.DSI_CTRL[0] IF_EN bit to 1. If the sequence is not followed, the |
| 2130 | DSI complex I/O configuration is unknown. */ |
| 2131 | |
| 2132 | /* |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2133 | REG_FLD_MOD(dsidev, DSI_CTRL, 1, 0, 0); |
| 2134 | REG_FLD_MOD(dsidev, DSI_CTRL, 0, 0, 0); |
| 2135 | REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 20, 20); |
| 2136 | REG_FLD_MOD(dsidev, DSI_CTRL, 1, 0, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2137 | */ |
| 2138 | } |
| 2139 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2140 | static inline unsigned ns2ddr(struct platform_device *dsidev, unsigned ns) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2141 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2142 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 2143 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2144 | /* convert time in ns to ddr ticks, rounding up */ |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2145 | unsigned long ddr_clk = dsi->current_cinfo.clkin4ddr / 4; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2146 | return (ns * (ddr_clk / 1000 / 1000) + 999) / 1000; |
| 2147 | } |
| 2148 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2149 | static inline unsigned ddr2ns(struct platform_device *dsidev, unsigned ddr) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2150 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2151 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 2152 | |
| 2153 | unsigned long ddr_clk = dsi->current_cinfo.clkin4ddr / 4; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2154 | return ddr * 1000 * 1000 / (ddr_clk / 1000); |
| 2155 | } |
| 2156 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2157 | static void dsi_cio_timings(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2158 | { |
| 2159 | u32 r; |
| 2160 | u32 ths_prepare, ths_prepare_ths_zero, ths_trail, ths_exit; |
| 2161 | u32 tlpx_half, tclk_trail, tclk_zero; |
| 2162 | u32 tclk_prepare; |
| 2163 | |
| 2164 | /* calculate timings */ |
| 2165 | |
| 2166 | /* 1 * DDR_CLK = 2 * UI */ |
| 2167 | |
| 2168 | /* min 40ns + 4*UI max 85ns + 6*UI */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2169 | ths_prepare = ns2ddr(dsidev, 70) + 2; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2170 | |
| 2171 | /* min 145ns + 10*UI */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2172 | ths_prepare_ths_zero = ns2ddr(dsidev, 175) + 2; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2173 | |
| 2174 | /* min max(8*UI, 60ns+4*UI) */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2175 | ths_trail = ns2ddr(dsidev, 60) + 5; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2176 | |
| 2177 | /* min 100ns */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2178 | ths_exit = ns2ddr(dsidev, 145); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2179 | |
| 2180 | /* tlpx min 50n */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2181 | tlpx_half = ns2ddr(dsidev, 25); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2182 | |
| 2183 | /* min 60ns */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2184 | tclk_trail = ns2ddr(dsidev, 60) + 2; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2185 | |
| 2186 | /* min 38ns, max 95ns */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2187 | tclk_prepare = ns2ddr(dsidev, 65); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2188 | |
| 2189 | /* min tclk-prepare + tclk-zero = 300ns */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2190 | tclk_zero = ns2ddr(dsidev, 260); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2191 | |
| 2192 | DSSDBG("ths_prepare %u (%uns), ths_prepare_ths_zero %u (%uns)\n", |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2193 | ths_prepare, ddr2ns(dsidev, ths_prepare), |
| 2194 | ths_prepare_ths_zero, ddr2ns(dsidev, ths_prepare_ths_zero)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2195 | DSSDBG("ths_trail %u (%uns), ths_exit %u (%uns)\n", |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2196 | ths_trail, ddr2ns(dsidev, ths_trail), |
| 2197 | ths_exit, ddr2ns(dsidev, ths_exit)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2198 | |
| 2199 | DSSDBG("tlpx_half %u (%uns), tclk_trail %u (%uns), " |
| 2200 | "tclk_zero %u (%uns)\n", |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2201 | tlpx_half, ddr2ns(dsidev, tlpx_half), |
| 2202 | tclk_trail, ddr2ns(dsidev, tclk_trail), |
| 2203 | tclk_zero, ddr2ns(dsidev, tclk_zero)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2204 | DSSDBG("tclk_prepare %u (%uns)\n", |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2205 | tclk_prepare, ddr2ns(dsidev, tclk_prepare)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2206 | |
| 2207 | /* program timings */ |
| 2208 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2209 | r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2210 | r = FLD_MOD(r, ths_prepare, 31, 24); |
| 2211 | r = FLD_MOD(r, ths_prepare_ths_zero, 23, 16); |
| 2212 | r = FLD_MOD(r, ths_trail, 15, 8); |
| 2213 | r = FLD_MOD(r, ths_exit, 7, 0); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2214 | dsi_write_reg(dsidev, DSI_DSIPHY_CFG0, r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2215 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2216 | r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2217 | r = FLD_MOD(r, tlpx_half, 22, 16); |
| 2218 | r = FLD_MOD(r, tclk_trail, 15, 8); |
| 2219 | r = FLD_MOD(r, tclk_zero, 7, 0); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2220 | dsi_write_reg(dsidev, DSI_DSIPHY_CFG1, r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2221 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2222 | r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG2); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2223 | r = FLD_MOD(r, tclk_prepare, 7, 0); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2224 | dsi_write_reg(dsidev, DSI_DSIPHY_CFG2, r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2225 | } |
| 2226 | |
Tomi Valkeinen | cc5c185 | 2010-10-06 15:18:13 +0300 | [diff] [blame] | 2227 | static void dsi_cio_enable_lane_override(struct omap_dss_device *dssdev, |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2228 | enum dsi_lane lanes) |
| 2229 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2230 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 2231 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2232 | int clk_lane = dssdev->phy.dsi.clk_lane; |
| 2233 | int data1_lane = dssdev->phy.dsi.data1_lane; |
| 2234 | int data2_lane = dssdev->phy.dsi.data2_lane; |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 2235 | int data3_lane = dssdev->phy.dsi.data3_lane; |
| 2236 | int data4_lane = dssdev->phy.dsi.data4_lane; |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2237 | int clk_pol = dssdev->phy.dsi.clk_pol; |
| 2238 | int data1_pol = dssdev->phy.dsi.data1_pol; |
| 2239 | int data2_pol = dssdev->phy.dsi.data2_pol; |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 2240 | int data3_pol = dssdev->phy.dsi.data3_pol; |
| 2241 | int data4_pol = dssdev->phy.dsi.data4_pol; |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2242 | |
| 2243 | u32 l = 0; |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 2244 | u8 lptxscp_start = dsi->num_data_lanes == 2 ? 22 : 26; |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2245 | |
| 2246 | if (lanes & DSI_CLK_P) |
| 2247 | l |= 1 << ((clk_lane - 1) * 2 + (clk_pol ? 0 : 1)); |
| 2248 | if (lanes & DSI_CLK_N) |
| 2249 | l |= 1 << ((clk_lane - 1) * 2 + (clk_pol ? 1 : 0)); |
| 2250 | |
| 2251 | if (lanes & DSI_DATA1_P) |
| 2252 | l |= 1 << ((data1_lane - 1) * 2 + (data1_pol ? 0 : 1)); |
| 2253 | if (lanes & DSI_DATA1_N) |
| 2254 | l |= 1 << ((data1_lane - 1) * 2 + (data1_pol ? 1 : 0)); |
| 2255 | |
| 2256 | if (lanes & DSI_DATA2_P) |
| 2257 | l |= 1 << ((data2_lane - 1) * 2 + (data2_pol ? 0 : 1)); |
| 2258 | if (lanes & DSI_DATA2_N) |
| 2259 | l |= 1 << ((data2_lane - 1) * 2 + (data2_pol ? 1 : 0)); |
| 2260 | |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 2261 | if (lanes & DSI_DATA3_P) |
| 2262 | l |= 1 << ((data3_lane - 1) * 2 + (data3_pol ? 0 : 1)); |
| 2263 | if (lanes & DSI_DATA3_N) |
| 2264 | l |= 1 << ((data3_lane - 1) * 2 + (data3_pol ? 1 : 0)); |
| 2265 | |
| 2266 | if (lanes & DSI_DATA4_P) |
| 2267 | l |= 1 << ((data4_lane - 1) * 2 + (data4_pol ? 0 : 1)); |
| 2268 | if (lanes & DSI_DATA4_N) |
| 2269 | l |= 1 << ((data4_lane - 1) * 2 + (data4_pol ? 1 : 0)); |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2270 | /* |
| 2271 | * Bits in REGLPTXSCPDAT4TO0DXDY: |
| 2272 | * 17: DY0 18: DX0 |
| 2273 | * 19: DY1 20: DX1 |
| 2274 | * 21: DY2 22: DX2 |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 2275 | * 23: DY3 24: DX3 |
| 2276 | * 25: DY4 26: DX4 |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2277 | */ |
| 2278 | |
| 2279 | /* Set the lane override configuration */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2280 | |
| 2281 | /* REGLPTXSCPDAT4TO0DXDY */ |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 2282 | REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, l, lptxscp_start, 17); |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2283 | |
| 2284 | /* Enable lane override */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2285 | |
| 2286 | /* ENLPTXSCPDAT */ |
| 2287 | REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 1, 27, 27); |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2288 | } |
| 2289 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2290 | static void dsi_cio_disable_lane_override(struct platform_device *dsidev) |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2291 | { |
| 2292 | /* Disable lane override */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2293 | REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 0, 27, 27); /* ENLPTXSCPDAT */ |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2294 | /* Reset the lane override configuration */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2295 | /* REGLPTXSCPDAT4TO0DXDY */ |
| 2296 | REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 0, 22, 17); |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2297 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2298 | |
Tomi Valkeinen | 03329ac | 2010-10-07 13:59:22 +0300 | [diff] [blame] | 2299 | static int dsi_cio_wait_tx_clk_esc_reset(struct omap_dss_device *dssdev) |
| 2300 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2301 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Tomi Valkeinen | 03329ac | 2010-10-07 13:59:22 +0300 | [diff] [blame] | 2302 | int t; |
| 2303 | int bits[3]; |
| 2304 | bool in_use[3]; |
| 2305 | |
| 2306 | if (dss_has_feature(FEAT_DSI_REVERSE_TXCLKESC)) { |
| 2307 | bits[0] = 28; |
| 2308 | bits[1] = 27; |
| 2309 | bits[2] = 26; |
| 2310 | } else { |
| 2311 | bits[0] = 24; |
| 2312 | bits[1] = 25; |
| 2313 | bits[2] = 26; |
| 2314 | } |
| 2315 | |
| 2316 | in_use[0] = false; |
| 2317 | in_use[1] = false; |
| 2318 | in_use[2] = false; |
| 2319 | |
| 2320 | if (dssdev->phy.dsi.clk_lane != 0) |
| 2321 | in_use[dssdev->phy.dsi.clk_lane - 1] = true; |
| 2322 | if (dssdev->phy.dsi.data1_lane != 0) |
| 2323 | in_use[dssdev->phy.dsi.data1_lane - 1] = true; |
| 2324 | if (dssdev->phy.dsi.data2_lane != 0) |
| 2325 | in_use[dssdev->phy.dsi.data2_lane - 1] = true; |
| 2326 | |
| 2327 | t = 100000; |
| 2328 | while (true) { |
| 2329 | u32 l; |
| 2330 | int i; |
| 2331 | int ok; |
| 2332 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2333 | l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5); |
Tomi Valkeinen | 03329ac | 2010-10-07 13:59:22 +0300 | [diff] [blame] | 2334 | |
| 2335 | ok = 0; |
| 2336 | for (i = 0; i < 3; ++i) { |
| 2337 | if (!in_use[i] || (l & (1 << bits[i]))) |
| 2338 | ok++; |
| 2339 | } |
| 2340 | |
| 2341 | if (ok == 3) |
| 2342 | break; |
| 2343 | |
| 2344 | if (--t == 0) { |
| 2345 | for (i = 0; i < 3; ++i) { |
| 2346 | if (!in_use[i] || (l & (1 << bits[i]))) |
| 2347 | continue; |
| 2348 | |
| 2349 | DSSERR("CIO TXCLKESC%d domain not coming " \ |
| 2350 | "out of reset\n", i); |
| 2351 | } |
| 2352 | return -EIO; |
| 2353 | } |
| 2354 | } |
| 2355 | |
| 2356 | return 0; |
| 2357 | } |
| 2358 | |
Tomi Valkeinen | 5bc416c | 2011-06-15 15:21:12 +0300 | [diff] [blame] | 2359 | static unsigned dsi_get_lane_mask(struct omap_dss_device *dssdev) |
| 2360 | { |
| 2361 | unsigned lanes = 0; |
| 2362 | |
| 2363 | if (dssdev->phy.dsi.clk_lane != 0) |
| 2364 | lanes |= 1 << (dssdev->phy.dsi.clk_lane - 1); |
| 2365 | if (dssdev->phy.dsi.data1_lane != 0) |
| 2366 | lanes |= 1 << (dssdev->phy.dsi.data1_lane - 1); |
| 2367 | if (dssdev->phy.dsi.data2_lane != 0) |
| 2368 | lanes |= 1 << (dssdev->phy.dsi.data2_lane - 1); |
| 2369 | if (dssdev->phy.dsi.data3_lane != 0) |
| 2370 | lanes |= 1 << (dssdev->phy.dsi.data3_lane - 1); |
| 2371 | if (dssdev->phy.dsi.data4_lane != 0) |
| 2372 | lanes |= 1 << (dssdev->phy.dsi.data4_lane - 1); |
| 2373 | |
| 2374 | return lanes; |
| 2375 | } |
| 2376 | |
Tomi Valkeinen | cc5c185 | 2010-10-06 15:18:13 +0300 | [diff] [blame] | 2377 | static int dsi_cio_init(struct omap_dss_device *dssdev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2378 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2379 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2380 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 65c62bb | 2011-04-15 11:58:41 +0300 | [diff] [blame] | 2381 | int r; |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 2382 | int num_data_lanes_dssdev = dsi_get_num_data_lanes_dssdev(dssdev); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 2383 | u32 l; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2384 | |
Tomi Valkeinen | cc5c185 | 2010-10-06 15:18:13 +0300 | [diff] [blame] | 2385 | DSSDBGF(); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2386 | |
Tomi Valkeinen | 5bc416c | 2011-06-15 15:21:12 +0300 | [diff] [blame] | 2387 | r = dsi->enable_pads(dsidev->id, dsi_get_lane_mask(dssdev)); |
| 2388 | if (r) |
| 2389 | return r; |
Tomi Valkeinen | d1f5857 | 2010-07-30 11:57:57 +0300 | [diff] [blame] | 2390 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2391 | dsi_enable_scp_clk(dsidev); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 2392 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2393 | /* A dummy read using the SCP interface to any DSIPHY register is |
| 2394 | * required after DSIPHY reset to complete the reset of the DSI complex |
| 2395 | * I/O. */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2396 | dsi_read_reg(dsidev, DSI_DSIPHY_CFG5); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2397 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2398 | if (wait_for_bit_change(dsidev, DSI_DSIPHY_CFG5, 30, 1) != 1) { |
Tomi Valkeinen | 65c62bb | 2011-04-15 11:58:41 +0300 | [diff] [blame] | 2399 | DSSERR("CIO SCP Clock domain not coming out of reset.\n"); |
| 2400 | r = -EIO; |
| 2401 | goto err_scp_clk_dom; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2402 | } |
| 2403 | |
Tomi Valkeinen | cc5c185 | 2010-10-06 15:18:13 +0300 | [diff] [blame] | 2404 | dsi_set_lane_config(dssdev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2405 | |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 2406 | /* set TX STOP MODE timer to maximum for this operation */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2407 | l = dsi_read_reg(dsidev, DSI_TIMING1); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 2408 | l = FLD_MOD(l, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */ |
| 2409 | l = FLD_MOD(l, 1, 14, 14); /* STOP_STATE_X16_IO */ |
| 2410 | l = FLD_MOD(l, 1, 13, 13); /* STOP_STATE_X4_IO */ |
| 2411 | l = FLD_MOD(l, 0x1fff, 12, 0); /* STOP_STATE_COUNTER_IO */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2412 | dsi_write_reg(dsidev, DSI_TIMING1, l); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 2413 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2414 | if (dsi->ulps_enabled) { |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 2415 | u32 lane_mask = DSI_CLK_P | DSI_DATA1_P | DSI_DATA2_P; |
| 2416 | |
Tomi Valkeinen | 65c62bb | 2011-04-15 11:58:41 +0300 | [diff] [blame] | 2417 | DSSDBG("manual ulps exit\n"); |
| 2418 | |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 2419 | /* ULPS is exited by Mark-1 state for 1ms, followed by |
| 2420 | * stop state. DSS HW cannot do this via the normal |
| 2421 | * ULPS exit sequence, as after reset the DSS HW thinks |
| 2422 | * that we are not in ULPS mode, and refuses to send the |
| 2423 | * sequence. So we need to send the ULPS exit sequence |
| 2424 | * manually. |
| 2425 | */ |
| 2426 | |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 2427 | if (num_data_lanes_dssdev > 2) |
| 2428 | lane_mask |= DSI_DATA3_P; |
| 2429 | |
| 2430 | if (num_data_lanes_dssdev > 3) |
| 2431 | lane_mask |= DSI_DATA4_P; |
| 2432 | |
| 2433 | dsi_cio_enable_lane_override(dssdev, lane_mask); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 2434 | } |
| 2435 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2436 | r = dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_ON); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2437 | if (r) |
Tomi Valkeinen | 65c62bb | 2011-04-15 11:58:41 +0300 | [diff] [blame] | 2438 | goto err_cio_pwr; |
| 2439 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2440 | if (wait_for_bit_change(dsidev, DSI_COMPLEXIO_CFG1, 29, 1) != 1) { |
Tomi Valkeinen | 65c62bb | 2011-04-15 11:58:41 +0300 | [diff] [blame] | 2441 | DSSERR("CIO PWR clock domain not coming out of reset.\n"); |
| 2442 | r = -ENODEV; |
| 2443 | goto err_cio_pwr_dom; |
| 2444 | } |
| 2445 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2446 | dsi_if_enable(dsidev, true); |
| 2447 | dsi_if_enable(dsidev, false); |
| 2448 | REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 20, 20); /* LP_CLK_ENABLE */ |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2449 | |
Tomi Valkeinen | 03329ac | 2010-10-07 13:59:22 +0300 | [diff] [blame] | 2450 | r = dsi_cio_wait_tx_clk_esc_reset(dssdev); |
| 2451 | if (r) |
| 2452 | goto err_tx_clk_esc_rst; |
| 2453 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2454 | if (dsi->ulps_enabled) { |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 2455 | /* Keep Mark-1 state for 1ms (as per DSI spec) */ |
| 2456 | ktime_t wait = ns_to_ktime(1000 * 1000); |
| 2457 | set_current_state(TASK_UNINTERRUPTIBLE); |
| 2458 | schedule_hrtimeout(&wait, HRTIMER_MODE_REL); |
| 2459 | |
| 2460 | /* Disable the override. The lanes should be set to Mark-11 |
| 2461 | * state by the HW */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2462 | dsi_cio_disable_lane_override(dsidev); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 2463 | } |
| 2464 | |
| 2465 | /* FORCE_TX_STOP_MODE_IO */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2466 | REG_FLD_MOD(dsidev, DSI_TIMING1, 0, 15, 15); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 2467 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2468 | dsi_cio_timings(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2469 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2470 | dsi->ulps_enabled = false; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2471 | |
| 2472 | DSSDBG("CIO init done\n"); |
Tomi Valkeinen | 65c62bb | 2011-04-15 11:58:41 +0300 | [diff] [blame] | 2473 | |
| 2474 | return 0; |
| 2475 | |
Tomi Valkeinen | 03329ac | 2010-10-07 13:59:22 +0300 | [diff] [blame] | 2476 | err_tx_clk_esc_rst: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2477 | REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 20, 20); /* LP_CLK_ENABLE */ |
Tomi Valkeinen | 65c62bb | 2011-04-15 11:58:41 +0300 | [diff] [blame] | 2478 | err_cio_pwr_dom: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2479 | dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF); |
Tomi Valkeinen | 65c62bb | 2011-04-15 11:58:41 +0300 | [diff] [blame] | 2480 | err_cio_pwr: |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2481 | if (dsi->ulps_enabled) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2482 | dsi_cio_disable_lane_override(dsidev); |
Tomi Valkeinen | 65c62bb | 2011-04-15 11:58:41 +0300 | [diff] [blame] | 2483 | err_scp_clk_dom: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2484 | dsi_disable_scp_clk(dsidev); |
Tomi Valkeinen | 5bc416c | 2011-06-15 15:21:12 +0300 | [diff] [blame] | 2485 | dsi->disable_pads(dsidev->id, dsi_get_lane_mask(dssdev)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2486 | return r; |
| 2487 | } |
| 2488 | |
Tomi Valkeinen | 5bc416c | 2011-06-15 15:21:12 +0300 | [diff] [blame] | 2489 | static void dsi_cio_uninit(struct omap_dss_device *dssdev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2490 | { |
Tomi Valkeinen | 5bc416c | 2011-06-15 15:21:12 +0300 | [diff] [blame] | 2491 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2492 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 2493 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2494 | dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF); |
| 2495 | dsi_disable_scp_clk(dsidev); |
Tomi Valkeinen | 5bc416c | 2011-06-15 15:21:12 +0300 | [diff] [blame] | 2496 | dsi->disable_pads(dsidev->id, dsi_get_lane_mask(dssdev)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2497 | } |
| 2498 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2499 | static void dsi_config_tx_fifo(struct platform_device *dsidev, |
| 2500 | enum fifo_size size1, enum fifo_size size2, |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2501 | enum fifo_size size3, enum fifo_size size4) |
| 2502 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2503 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2504 | u32 r = 0; |
| 2505 | int add = 0; |
| 2506 | int i; |
| 2507 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2508 | dsi->vc[0].fifo_size = size1; |
| 2509 | dsi->vc[1].fifo_size = size2; |
| 2510 | dsi->vc[2].fifo_size = size3; |
| 2511 | dsi->vc[3].fifo_size = size4; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2512 | |
| 2513 | for (i = 0; i < 4; i++) { |
| 2514 | u8 v; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2515 | int size = dsi->vc[i].fifo_size; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2516 | |
| 2517 | if (add + size > 4) { |
| 2518 | DSSERR("Illegal FIFO configuration\n"); |
| 2519 | BUG(); |
| 2520 | } |
| 2521 | |
| 2522 | v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4); |
| 2523 | r |= v << (8 * i); |
| 2524 | /*DSSDBG("TX FIFO vc %d: size %d, add %d\n", i, size, add); */ |
| 2525 | add += size; |
| 2526 | } |
| 2527 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2528 | dsi_write_reg(dsidev, DSI_TX_FIFO_VC_SIZE, r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2529 | } |
| 2530 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2531 | static void dsi_config_rx_fifo(struct platform_device *dsidev, |
| 2532 | enum fifo_size size1, enum fifo_size size2, |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2533 | enum fifo_size size3, enum fifo_size size4) |
| 2534 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2535 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2536 | u32 r = 0; |
| 2537 | int add = 0; |
| 2538 | int i; |
| 2539 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2540 | dsi->vc[0].fifo_size = size1; |
| 2541 | dsi->vc[1].fifo_size = size2; |
| 2542 | dsi->vc[2].fifo_size = size3; |
| 2543 | dsi->vc[3].fifo_size = size4; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2544 | |
| 2545 | for (i = 0; i < 4; i++) { |
| 2546 | u8 v; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2547 | int size = dsi->vc[i].fifo_size; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2548 | |
| 2549 | if (add + size > 4) { |
| 2550 | DSSERR("Illegal FIFO configuration\n"); |
| 2551 | BUG(); |
| 2552 | } |
| 2553 | |
| 2554 | v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4); |
| 2555 | r |= v << (8 * i); |
| 2556 | /*DSSDBG("RX FIFO vc %d: size %d, add %d\n", i, size, add); */ |
| 2557 | add += size; |
| 2558 | } |
| 2559 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2560 | dsi_write_reg(dsidev, DSI_RX_FIFO_VC_SIZE, r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2561 | } |
| 2562 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2563 | static int dsi_force_tx_stop_mode_io(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2564 | { |
| 2565 | u32 r; |
| 2566 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2567 | r = dsi_read_reg(dsidev, DSI_TIMING1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2568 | r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2569 | dsi_write_reg(dsidev, DSI_TIMING1, r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2570 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2571 | if (wait_for_bit_change(dsidev, DSI_TIMING1, 15, 0) != 0) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2572 | DSSERR("TX_STOP bit not going down\n"); |
| 2573 | return -EIO; |
| 2574 | } |
| 2575 | |
| 2576 | return 0; |
| 2577 | } |
| 2578 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2579 | static bool dsi_vc_is_enabled(struct platform_device *dsidev, int channel) |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2580 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2581 | return REG_GET(dsidev, DSI_VC_CTRL(channel), 0, 0); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2582 | } |
| 2583 | |
| 2584 | static void dsi_packet_sent_handler_vp(void *data, u32 mask) |
| 2585 | { |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2586 | struct dsi_packet_sent_handler_data *vp_data = |
| 2587 | (struct dsi_packet_sent_handler_data *) data; |
| 2588 | struct dsi_data *dsi = dsi_get_dsidrv_data(vp_data->dsidev); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2589 | const int channel = dsi->update_channel; |
| 2590 | u8 bit = dsi->te_enabled ? 30 : 31; |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2591 | |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2592 | if (REG_GET(vp_data->dsidev, DSI_VC_TE(channel), bit, bit) == 0) |
| 2593 | complete(vp_data->completion); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2594 | } |
| 2595 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2596 | static int dsi_sync_vc_vp(struct platform_device *dsidev, int channel) |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2597 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2598 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2599 | DECLARE_COMPLETION_ONSTACK(completion); |
| 2600 | struct dsi_packet_sent_handler_data vp_data = { dsidev, &completion }; |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2601 | int r = 0; |
| 2602 | u8 bit; |
| 2603 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2604 | bit = dsi->te_enabled ? 30 : 31; |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2605 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2606 | r = dsi_register_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp, |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2607 | &vp_data, DSI_VC_IRQ_PACKET_SENT); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2608 | if (r) |
| 2609 | goto err0; |
| 2610 | |
| 2611 | /* Wait for completion only if TE_EN/TE_START is still set */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2612 | if (REG_GET(dsidev, DSI_VC_TE(channel), bit, bit)) { |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2613 | if (wait_for_completion_timeout(&completion, |
| 2614 | msecs_to_jiffies(10)) == 0) { |
| 2615 | DSSERR("Failed to complete previous frame transfer\n"); |
| 2616 | r = -EIO; |
| 2617 | goto err1; |
| 2618 | } |
| 2619 | } |
| 2620 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2621 | dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp, |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2622 | &vp_data, DSI_VC_IRQ_PACKET_SENT); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2623 | |
| 2624 | return 0; |
| 2625 | err1: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2626 | dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp, |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2627 | &vp_data, DSI_VC_IRQ_PACKET_SENT); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2628 | err0: |
| 2629 | return r; |
| 2630 | } |
| 2631 | |
| 2632 | static void dsi_packet_sent_handler_l4(void *data, u32 mask) |
| 2633 | { |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2634 | struct dsi_packet_sent_handler_data *l4_data = |
| 2635 | (struct dsi_packet_sent_handler_data *) data; |
| 2636 | struct dsi_data *dsi = dsi_get_dsidrv_data(l4_data->dsidev); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2637 | const int channel = dsi->update_channel; |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2638 | |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2639 | if (REG_GET(l4_data->dsidev, DSI_VC_CTRL(channel), 5, 5) == 0) |
| 2640 | complete(l4_data->completion); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2641 | } |
| 2642 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2643 | static int dsi_sync_vc_l4(struct platform_device *dsidev, int channel) |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2644 | { |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2645 | DECLARE_COMPLETION_ONSTACK(completion); |
| 2646 | struct dsi_packet_sent_handler_data l4_data = { dsidev, &completion }; |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2647 | int r = 0; |
| 2648 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2649 | r = dsi_register_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4, |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2650 | &l4_data, DSI_VC_IRQ_PACKET_SENT); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2651 | if (r) |
| 2652 | goto err0; |
| 2653 | |
| 2654 | /* Wait for completion only if TX_FIFO_NOT_EMPTY is still set */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2655 | if (REG_GET(dsidev, DSI_VC_CTRL(channel), 5, 5)) { |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2656 | if (wait_for_completion_timeout(&completion, |
| 2657 | msecs_to_jiffies(10)) == 0) { |
| 2658 | DSSERR("Failed to complete previous l4 transfer\n"); |
| 2659 | r = -EIO; |
| 2660 | goto err1; |
| 2661 | } |
| 2662 | } |
| 2663 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2664 | dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4, |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2665 | &l4_data, DSI_VC_IRQ_PACKET_SENT); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2666 | |
| 2667 | return 0; |
| 2668 | err1: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2669 | dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4, |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2670 | &l4_data, DSI_VC_IRQ_PACKET_SENT); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2671 | err0: |
| 2672 | return r; |
| 2673 | } |
| 2674 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2675 | static int dsi_sync_vc(struct platform_device *dsidev, int channel) |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2676 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2677 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 2678 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2679 | WARN_ON(!dsi_bus_is_locked(dsidev)); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2680 | |
| 2681 | WARN_ON(in_interrupt()); |
| 2682 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2683 | if (!dsi_vc_is_enabled(dsidev, channel)) |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2684 | return 0; |
| 2685 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2686 | switch (dsi->vc[channel].mode) { |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2687 | case DSI_VC_MODE_VP: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2688 | return dsi_sync_vc_vp(dsidev, channel); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2689 | case DSI_VC_MODE_L4: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2690 | return dsi_sync_vc_l4(dsidev, channel); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2691 | default: |
| 2692 | BUG(); |
| 2693 | } |
| 2694 | } |
| 2695 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2696 | static int dsi_vc_enable(struct platform_device *dsidev, int channel, |
| 2697 | bool enable) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2698 | { |
Tomi Valkeinen | 446f7bf | 2010-01-11 16:12:31 +0200 | [diff] [blame] | 2699 | DSSDBG("dsi_vc_enable channel %d, enable %d\n", |
| 2700 | channel, enable); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2701 | |
| 2702 | enable = enable ? 1 : 0; |
| 2703 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2704 | REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 0, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2705 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2706 | if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel), |
| 2707 | 0, enable) != enable) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2708 | DSSERR("Failed to set dsi_vc_enable to %d\n", enable); |
| 2709 | return -EIO; |
| 2710 | } |
| 2711 | |
| 2712 | return 0; |
| 2713 | } |
| 2714 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2715 | static void dsi_vc_initial_config(struct platform_device *dsidev, int channel) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2716 | { |
| 2717 | u32 r; |
| 2718 | |
| 2719 | DSSDBGF("%d", channel); |
| 2720 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2721 | r = dsi_read_reg(dsidev, DSI_VC_CTRL(channel)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2722 | |
| 2723 | if (FLD_GET(r, 15, 15)) /* VC_BUSY */ |
| 2724 | DSSERR("VC(%d) busy when trying to configure it!\n", |
| 2725 | channel); |
| 2726 | |
| 2727 | r = FLD_MOD(r, 0, 1, 1); /* SOURCE, 0 = L4 */ |
| 2728 | r = FLD_MOD(r, 0, 2, 2); /* BTA_SHORT_EN */ |
| 2729 | r = FLD_MOD(r, 0, 3, 3); /* BTA_LONG_EN */ |
| 2730 | r = FLD_MOD(r, 0, 4, 4); /* MODE, 0 = command */ |
| 2731 | r = FLD_MOD(r, 1, 7, 7); /* CS_TX_EN */ |
| 2732 | r = FLD_MOD(r, 1, 8, 8); /* ECC_TX_EN */ |
| 2733 | r = FLD_MOD(r, 0, 9, 9); /* MODE_SPEED, high speed on/off */ |
Archit Taneja | 9613c02 | 2011-03-22 06:33:36 -0500 | [diff] [blame] | 2734 | if (dss_has_feature(FEAT_DSI_VC_OCP_WIDTH)) |
| 2735 | r = FLD_MOD(r, 3, 11, 10); /* OCP_WIDTH = 32 bit */ |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2736 | |
| 2737 | r = FLD_MOD(r, 4, 29, 27); /* DMA_RX_REQ_NB = no dma */ |
| 2738 | r = FLD_MOD(r, 4, 23, 21); /* DMA_TX_REQ_NB = no dma */ |
| 2739 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2740 | dsi_write_reg(dsidev, DSI_VC_CTRL(channel), r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2741 | } |
| 2742 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2743 | static int dsi_vc_config_l4(struct platform_device *dsidev, int channel) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2744 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2745 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 2746 | |
| 2747 | if (dsi->vc[channel].mode == DSI_VC_MODE_L4) |
Tomi Valkeinen | 9ecd968 | 2010-04-30 11:24:33 +0300 | [diff] [blame] | 2748 | return 0; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2749 | |
| 2750 | DSSDBGF("%d", channel); |
| 2751 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2752 | dsi_sync_vc(dsidev, channel); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2753 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2754 | dsi_vc_enable(dsidev, channel, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2755 | |
Tomi Valkeinen | 9ecd968 | 2010-04-30 11:24:33 +0300 | [diff] [blame] | 2756 | /* VC_BUSY */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2757 | if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel), 15, 0) != 0) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2758 | DSSERR("vc(%d) busy when trying to config for L4\n", channel); |
Tomi Valkeinen | 9ecd968 | 2010-04-30 11:24:33 +0300 | [diff] [blame] | 2759 | return -EIO; |
| 2760 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2761 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2762 | REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 0, 1, 1); /* SOURCE, 0 = L4 */ |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2763 | |
Archit Taneja | 9613c02 | 2011-03-22 06:33:36 -0500 | [diff] [blame] | 2764 | /* DCS_CMD_ENABLE */ |
| 2765 | if (dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC)) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2766 | REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 0, 30, 30); |
Archit Taneja | 9613c02 | 2011-03-22 06:33:36 -0500 | [diff] [blame] | 2767 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2768 | dsi_vc_enable(dsidev, channel, 1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2769 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2770 | dsi->vc[channel].mode = DSI_VC_MODE_L4; |
Tomi Valkeinen | 9ecd968 | 2010-04-30 11:24:33 +0300 | [diff] [blame] | 2771 | |
| 2772 | return 0; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2773 | } |
| 2774 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2775 | static int dsi_vc_config_vp(struct platform_device *dsidev, int channel) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2776 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2777 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 2778 | |
| 2779 | if (dsi->vc[channel].mode == DSI_VC_MODE_VP) |
Tomi Valkeinen | 9ecd968 | 2010-04-30 11:24:33 +0300 | [diff] [blame] | 2780 | return 0; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2781 | |
| 2782 | DSSDBGF("%d", channel); |
| 2783 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2784 | dsi_sync_vc(dsidev, channel); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2785 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2786 | dsi_vc_enable(dsidev, channel, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2787 | |
Tomi Valkeinen | 9ecd968 | 2010-04-30 11:24:33 +0300 | [diff] [blame] | 2788 | /* VC_BUSY */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2789 | if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel), 15, 0) != 0) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2790 | DSSERR("vc(%d) busy when trying to config for VP\n", channel); |
Tomi Valkeinen | 9ecd968 | 2010-04-30 11:24:33 +0300 | [diff] [blame] | 2791 | return -EIO; |
| 2792 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2793 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2794 | /* SOURCE, 1 = video port */ |
| 2795 | REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 1, 1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2796 | |
Archit Taneja | 9613c02 | 2011-03-22 06:33:36 -0500 | [diff] [blame] | 2797 | /* DCS_CMD_ENABLE */ |
| 2798 | if (dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC)) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2799 | REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 30, 30); |
Archit Taneja | 9613c02 | 2011-03-22 06:33:36 -0500 | [diff] [blame] | 2800 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2801 | dsi_vc_enable(dsidev, channel, 1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2802 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2803 | dsi->vc[channel].mode = DSI_VC_MODE_VP; |
Tomi Valkeinen | 9ecd968 | 2010-04-30 11:24:33 +0300 | [diff] [blame] | 2804 | |
| 2805 | return 0; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2806 | } |
| 2807 | |
| 2808 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 2809 | void omapdss_dsi_vc_enable_hs(struct omap_dss_device *dssdev, int channel, |
| 2810 | bool enable) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2811 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2812 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 2813 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2814 | DSSDBG("dsi_vc_enable_hs(%d, %d)\n", channel, enable); |
| 2815 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2816 | WARN_ON(!dsi_bus_is_locked(dsidev)); |
Tomi Valkeinen | 61140c9 | 2010-01-12 16:00:30 +0200 | [diff] [blame] | 2817 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2818 | dsi_vc_enable(dsidev, channel, 0); |
| 2819 | dsi_if_enable(dsidev, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2820 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2821 | REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 9, 9); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2822 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2823 | dsi_vc_enable(dsidev, channel, 1); |
| 2824 | dsi_if_enable(dsidev, 1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2825 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2826 | dsi_force_tx_stop_mode_io(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2827 | } |
Tomi Valkeinen | 61140c9 | 2010-01-12 16:00:30 +0200 | [diff] [blame] | 2828 | EXPORT_SYMBOL(omapdss_dsi_vc_enable_hs); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2829 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2830 | static void dsi_vc_flush_long_data(struct platform_device *dsidev, int channel) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2831 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2832 | while (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2833 | u32 val; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2834 | val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2835 | DSSDBG("\t\tb1 %#02x b2 %#02x b3 %#02x b4 %#02x\n", |
| 2836 | (val >> 0) & 0xff, |
| 2837 | (val >> 8) & 0xff, |
| 2838 | (val >> 16) & 0xff, |
| 2839 | (val >> 24) & 0xff); |
| 2840 | } |
| 2841 | } |
| 2842 | |
| 2843 | static void dsi_show_rx_ack_with_err(u16 err) |
| 2844 | { |
| 2845 | DSSERR("\tACK with ERROR (%#x):\n", err); |
| 2846 | if (err & (1 << 0)) |
| 2847 | DSSERR("\t\tSoT Error\n"); |
| 2848 | if (err & (1 << 1)) |
| 2849 | DSSERR("\t\tSoT Sync Error\n"); |
| 2850 | if (err & (1 << 2)) |
| 2851 | DSSERR("\t\tEoT Sync Error\n"); |
| 2852 | if (err & (1 << 3)) |
| 2853 | DSSERR("\t\tEscape Mode Entry Command Error\n"); |
| 2854 | if (err & (1 << 4)) |
| 2855 | DSSERR("\t\tLP Transmit Sync Error\n"); |
| 2856 | if (err & (1 << 5)) |
| 2857 | DSSERR("\t\tHS Receive Timeout Error\n"); |
| 2858 | if (err & (1 << 6)) |
| 2859 | DSSERR("\t\tFalse Control Error\n"); |
| 2860 | if (err & (1 << 7)) |
| 2861 | DSSERR("\t\t(reserved7)\n"); |
| 2862 | if (err & (1 << 8)) |
| 2863 | DSSERR("\t\tECC Error, single-bit (corrected)\n"); |
| 2864 | if (err & (1 << 9)) |
| 2865 | DSSERR("\t\tECC Error, multi-bit (not corrected)\n"); |
| 2866 | if (err & (1 << 10)) |
| 2867 | DSSERR("\t\tChecksum Error\n"); |
| 2868 | if (err & (1 << 11)) |
| 2869 | DSSERR("\t\tData type not recognized\n"); |
| 2870 | if (err & (1 << 12)) |
| 2871 | DSSERR("\t\tInvalid VC ID\n"); |
| 2872 | if (err & (1 << 13)) |
| 2873 | DSSERR("\t\tInvalid Transmission Length\n"); |
| 2874 | if (err & (1 << 14)) |
| 2875 | DSSERR("\t\t(reserved14)\n"); |
| 2876 | if (err & (1 << 15)) |
| 2877 | DSSERR("\t\tDSI Protocol Violation\n"); |
| 2878 | } |
| 2879 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2880 | static u16 dsi_vc_flush_receive_data(struct platform_device *dsidev, |
| 2881 | int channel) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2882 | { |
| 2883 | /* RX_FIFO_NOT_EMPTY */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2884 | while (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2885 | u32 val; |
| 2886 | u8 dt; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2887 | val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel)); |
Tomi Valkeinen | 86a7867 | 2010-03-16 16:19:06 +0200 | [diff] [blame] | 2888 | DSSERR("\trawval %#08x\n", val); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2889 | dt = FLD_GET(val, 5, 0); |
| 2890 | if (dt == DSI_DT_RX_ACK_WITH_ERR) { |
| 2891 | u16 err = FLD_GET(val, 23, 8); |
| 2892 | dsi_show_rx_ack_with_err(err); |
| 2893 | } else if (dt == DSI_DT_RX_SHORT_READ_1) { |
Tomi Valkeinen | 86a7867 | 2010-03-16 16:19:06 +0200 | [diff] [blame] | 2894 | DSSERR("\tDCS short response, 1 byte: %#x\n", |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2895 | FLD_GET(val, 23, 8)); |
| 2896 | } else if (dt == DSI_DT_RX_SHORT_READ_2) { |
Tomi Valkeinen | 86a7867 | 2010-03-16 16:19:06 +0200 | [diff] [blame] | 2897 | DSSERR("\tDCS short response, 2 byte: %#x\n", |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2898 | FLD_GET(val, 23, 8)); |
| 2899 | } else if (dt == DSI_DT_RX_DCS_LONG_READ) { |
Tomi Valkeinen | 86a7867 | 2010-03-16 16:19:06 +0200 | [diff] [blame] | 2900 | DSSERR("\tDCS long response, len %d\n", |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2901 | FLD_GET(val, 23, 8)); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2902 | dsi_vc_flush_long_data(dsidev, channel); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2903 | } else { |
| 2904 | DSSERR("\tunknown datatype 0x%02x\n", dt); |
| 2905 | } |
| 2906 | } |
| 2907 | return 0; |
| 2908 | } |
| 2909 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2910 | static int dsi_vc_send_bta(struct platform_device *dsidev, int channel) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2911 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2912 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 2913 | |
| 2914 | if (dsi->debug_write || dsi->debug_read) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2915 | DSSDBG("dsi_vc_send_bta %d\n", channel); |
| 2916 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2917 | WARN_ON(!dsi_bus_is_locked(dsidev)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2918 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2919 | /* RX_FIFO_NOT_EMPTY */ |
| 2920 | if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2921 | DSSERR("rx fifo not empty when sending BTA, dumping data:\n"); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2922 | dsi_vc_flush_receive_data(dsidev, channel); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2923 | } |
| 2924 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2925 | REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 6, 6); /* BTA_EN */ |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2926 | |
| 2927 | return 0; |
| 2928 | } |
| 2929 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 2930 | int dsi_vc_send_bta_sync(struct omap_dss_device *dssdev, int channel) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2931 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2932 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Tomi Valkeinen | f36a06e | 2011-03-02 14:48:41 +0200 | [diff] [blame] | 2933 | DECLARE_COMPLETION_ONSTACK(completion); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2934 | int r = 0; |
| 2935 | u32 err; |
| 2936 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2937 | r = dsi_register_isr_vc(dsidev, channel, dsi_completion_handler, |
Tomi Valkeinen | f36a06e | 2011-03-02 14:48:41 +0200 | [diff] [blame] | 2938 | &completion, DSI_VC_IRQ_BTA); |
| 2939 | if (r) |
| 2940 | goto err0; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2941 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2942 | r = dsi_register_isr(dsidev, dsi_completion_handler, &completion, |
Tomi Valkeinen | 773b30b | 2010-10-08 16:15:25 +0300 | [diff] [blame] | 2943 | DSI_IRQ_ERROR_MASK); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2944 | if (r) |
Tomi Valkeinen | f36a06e | 2011-03-02 14:48:41 +0200 | [diff] [blame] | 2945 | goto err1; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2946 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2947 | r = dsi_vc_send_bta(dsidev, channel); |
Tomi Valkeinen | 773b30b | 2010-10-08 16:15:25 +0300 | [diff] [blame] | 2948 | if (r) |
| 2949 | goto err2; |
| 2950 | |
Tomi Valkeinen | f36a06e | 2011-03-02 14:48:41 +0200 | [diff] [blame] | 2951 | if (wait_for_completion_timeout(&completion, |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2952 | msecs_to_jiffies(500)) == 0) { |
| 2953 | DSSERR("Failed to receive BTA\n"); |
| 2954 | r = -EIO; |
Tomi Valkeinen | 773b30b | 2010-10-08 16:15:25 +0300 | [diff] [blame] | 2955 | goto err2; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2956 | } |
| 2957 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2958 | err = dsi_get_errors(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2959 | if (err) { |
| 2960 | DSSERR("Error while sending BTA: %x\n", err); |
| 2961 | r = -EIO; |
Tomi Valkeinen | 773b30b | 2010-10-08 16:15:25 +0300 | [diff] [blame] | 2962 | goto err2; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2963 | } |
Tomi Valkeinen | 773b30b | 2010-10-08 16:15:25 +0300 | [diff] [blame] | 2964 | err2: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2965 | dsi_unregister_isr(dsidev, dsi_completion_handler, &completion, |
Tomi Valkeinen | 773b30b | 2010-10-08 16:15:25 +0300 | [diff] [blame] | 2966 | DSI_IRQ_ERROR_MASK); |
Tomi Valkeinen | f36a06e | 2011-03-02 14:48:41 +0200 | [diff] [blame] | 2967 | err1: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2968 | dsi_unregister_isr_vc(dsidev, channel, dsi_completion_handler, |
Tomi Valkeinen | f36a06e | 2011-03-02 14:48:41 +0200 | [diff] [blame] | 2969 | &completion, DSI_VC_IRQ_BTA); |
| 2970 | err0: |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2971 | return r; |
| 2972 | } |
| 2973 | EXPORT_SYMBOL(dsi_vc_send_bta_sync); |
| 2974 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2975 | static inline void dsi_vc_write_long_header(struct platform_device *dsidev, |
| 2976 | int channel, u8 data_type, u16 len, u8 ecc) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2977 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2978 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2979 | u32 val; |
| 2980 | u8 data_id; |
| 2981 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2982 | WARN_ON(!dsi_bus_is_locked(dsidev)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2983 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2984 | data_id = data_type | dsi->vc[channel].vc_id << 6; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2985 | |
| 2986 | val = FLD_VAL(data_id, 7, 0) | FLD_VAL(len, 23, 8) | |
| 2987 | FLD_VAL(ecc, 31, 24); |
| 2988 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2989 | dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_HEADER(channel), val); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2990 | } |
| 2991 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2992 | static inline void dsi_vc_write_long_payload(struct platform_device *dsidev, |
| 2993 | int channel, u8 b1, u8 b2, u8 b3, u8 b4) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2994 | { |
| 2995 | u32 val; |
| 2996 | |
| 2997 | val = b4 << 24 | b3 << 16 | b2 << 8 | b1 << 0; |
| 2998 | |
| 2999 | /* DSSDBG("\twriting %02x, %02x, %02x, %02x (%#010x)\n", |
| 3000 | b1, b2, b3, b4, val); */ |
| 3001 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3002 | dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_PAYLOAD(channel), val); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3003 | } |
| 3004 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3005 | static int dsi_vc_send_long(struct platform_device *dsidev, int channel, |
| 3006 | u8 data_type, u8 *data, u16 len, u8 ecc) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3007 | { |
| 3008 | /*u32 val; */ |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3009 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3010 | int i; |
| 3011 | u8 *p; |
| 3012 | int r = 0; |
| 3013 | u8 b1, b2, b3, b4; |
| 3014 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3015 | if (dsi->debug_write) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3016 | DSSDBG("dsi_vc_send_long, %d bytes\n", len); |
| 3017 | |
| 3018 | /* len + header */ |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3019 | if (dsi->vc[channel].fifo_size * 32 * 4 < len + 4) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3020 | DSSERR("unable to send long packet: packet too long.\n"); |
| 3021 | return -EINVAL; |
| 3022 | } |
| 3023 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3024 | dsi_vc_config_l4(dsidev, channel); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3025 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3026 | dsi_vc_write_long_header(dsidev, channel, data_type, len, ecc); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3027 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3028 | p = data; |
| 3029 | for (i = 0; i < len >> 2; i++) { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3030 | if (dsi->debug_write) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3031 | DSSDBG("\tsending full packet %d\n", i); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3032 | |
| 3033 | b1 = *p++; |
| 3034 | b2 = *p++; |
| 3035 | b3 = *p++; |
| 3036 | b4 = *p++; |
| 3037 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3038 | dsi_vc_write_long_payload(dsidev, channel, b1, b2, b3, b4); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3039 | } |
| 3040 | |
| 3041 | i = len % 4; |
| 3042 | if (i) { |
| 3043 | b1 = 0; b2 = 0; b3 = 0; |
| 3044 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3045 | if (dsi->debug_write) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3046 | DSSDBG("\tsending remainder bytes %d\n", i); |
| 3047 | |
| 3048 | switch (i) { |
| 3049 | case 3: |
| 3050 | b1 = *p++; |
| 3051 | b2 = *p++; |
| 3052 | b3 = *p++; |
| 3053 | break; |
| 3054 | case 2: |
| 3055 | b1 = *p++; |
| 3056 | b2 = *p++; |
| 3057 | break; |
| 3058 | case 1: |
| 3059 | b1 = *p++; |
| 3060 | break; |
| 3061 | } |
| 3062 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3063 | dsi_vc_write_long_payload(dsidev, channel, b1, b2, b3, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3064 | } |
| 3065 | |
| 3066 | return r; |
| 3067 | } |
| 3068 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3069 | static int dsi_vc_send_short(struct platform_device *dsidev, int channel, |
| 3070 | u8 data_type, u16 data, u8 ecc) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3071 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3072 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3073 | u32 r; |
| 3074 | u8 data_id; |
| 3075 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3076 | WARN_ON(!dsi_bus_is_locked(dsidev)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3077 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3078 | if (dsi->debug_write) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3079 | DSSDBG("dsi_vc_send_short(ch%d, dt %#x, b1 %#x, b2 %#x)\n", |
| 3080 | channel, |
| 3081 | data_type, data & 0xff, (data >> 8) & 0xff); |
| 3082 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3083 | dsi_vc_config_l4(dsidev, channel); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3084 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3085 | if (FLD_GET(dsi_read_reg(dsidev, DSI_VC_CTRL(channel)), 16, 16)) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3086 | DSSERR("ERROR FIFO FULL, aborting transfer\n"); |
| 3087 | return -EINVAL; |
| 3088 | } |
| 3089 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3090 | data_id = data_type | dsi->vc[channel].vc_id << 6; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3091 | |
| 3092 | r = (data_id << 0) | (data << 8) | (ecc << 24); |
| 3093 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3094 | dsi_write_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel), r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3095 | |
| 3096 | return 0; |
| 3097 | } |
| 3098 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 3099 | int dsi_vc_send_null(struct omap_dss_device *dssdev, int channel) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3100 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3101 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3102 | u8 nullpkg[] = {0, 0, 0, 0}; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3103 | |
| 3104 | return dsi_vc_send_long(dsidev, channel, DSI_DT_NULL_PACKET, nullpkg, |
| 3105 | 4, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3106 | } |
| 3107 | EXPORT_SYMBOL(dsi_vc_send_null); |
| 3108 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 3109 | int dsi_vc_dcs_write_nosync(struct omap_dss_device *dssdev, int channel, |
| 3110 | u8 *data, int len) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3111 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3112 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3113 | int r; |
| 3114 | |
| 3115 | BUG_ON(len == 0); |
| 3116 | |
| 3117 | if (len == 1) { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3118 | r = dsi_vc_send_short(dsidev, channel, DSI_DT_DCS_SHORT_WRITE_0, |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3119 | data[0], 0); |
| 3120 | } else if (len == 2) { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3121 | r = dsi_vc_send_short(dsidev, channel, DSI_DT_DCS_SHORT_WRITE_1, |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3122 | data[0] | (data[1] << 8), 0); |
| 3123 | } else { |
| 3124 | /* 0x39 = DCS Long Write */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3125 | r = dsi_vc_send_long(dsidev, channel, DSI_DT_DCS_LONG_WRITE, |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3126 | data, len, 0); |
| 3127 | } |
| 3128 | |
| 3129 | return r; |
| 3130 | } |
| 3131 | EXPORT_SYMBOL(dsi_vc_dcs_write_nosync); |
| 3132 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 3133 | int dsi_vc_dcs_write(struct omap_dss_device *dssdev, int channel, u8 *data, |
| 3134 | int len) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3135 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3136 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3137 | int r; |
| 3138 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 3139 | r = dsi_vc_dcs_write_nosync(dssdev, channel, data, len); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3140 | if (r) |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3141 | goto err; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3142 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 3143 | r = dsi_vc_send_bta_sync(dssdev, channel); |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3144 | if (r) |
| 3145 | goto err; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3146 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3147 | /* RX_FIFO_NOT_EMPTY */ |
| 3148 | if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) { |
Tomi Valkeinen | b63ac1e | 2010-04-09 13:20:57 +0300 | [diff] [blame] | 3149 | DSSERR("rx fifo not empty after write, dumping data:\n"); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3150 | dsi_vc_flush_receive_data(dsidev, channel); |
Tomi Valkeinen | b63ac1e | 2010-04-09 13:20:57 +0300 | [diff] [blame] | 3151 | r = -EIO; |
| 3152 | goto err; |
| 3153 | } |
| 3154 | |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3155 | return 0; |
| 3156 | err: |
| 3157 | DSSERR("dsi_vc_dcs_write(ch %d, cmd 0x%02x, len %d) failed\n", |
| 3158 | channel, data[0], len); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3159 | return r; |
| 3160 | } |
| 3161 | EXPORT_SYMBOL(dsi_vc_dcs_write); |
| 3162 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 3163 | int dsi_vc_dcs_write_0(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd) |
Tomi Valkeinen | 828c48f | 2009-12-16 14:53:15 +0200 | [diff] [blame] | 3164 | { |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 3165 | return dsi_vc_dcs_write(dssdev, channel, &dcs_cmd, 1); |
Tomi Valkeinen | 828c48f | 2009-12-16 14:53:15 +0200 | [diff] [blame] | 3166 | } |
| 3167 | EXPORT_SYMBOL(dsi_vc_dcs_write_0); |
| 3168 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 3169 | int dsi_vc_dcs_write_1(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd, |
| 3170 | u8 param) |
Tomi Valkeinen | 828c48f | 2009-12-16 14:53:15 +0200 | [diff] [blame] | 3171 | { |
| 3172 | u8 buf[2]; |
| 3173 | buf[0] = dcs_cmd; |
| 3174 | buf[1] = param; |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 3175 | return dsi_vc_dcs_write(dssdev, channel, buf, 2); |
Tomi Valkeinen | 828c48f | 2009-12-16 14:53:15 +0200 | [diff] [blame] | 3176 | } |
| 3177 | EXPORT_SYMBOL(dsi_vc_dcs_write_1); |
| 3178 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 3179 | int dsi_vc_dcs_read(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd, |
| 3180 | u8 *buf, int buflen) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3181 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3182 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3183 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3184 | u32 val; |
| 3185 | u8 dt; |
| 3186 | int r; |
| 3187 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3188 | if (dsi->debug_read) |
Tomi Valkeinen | ff90a34 | 2009-12-03 13:38:04 +0200 | [diff] [blame] | 3189 | DSSDBG("dsi_vc_dcs_read(ch%d, dcs_cmd %x)\n", channel, dcs_cmd); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3190 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3191 | r = dsi_vc_send_short(dsidev, channel, DSI_DT_DCS_READ, dcs_cmd, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3192 | if (r) |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3193 | goto err; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3194 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 3195 | r = dsi_vc_send_bta_sync(dssdev, channel); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3196 | if (r) |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3197 | goto err; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3198 | |
| 3199 | /* RX_FIFO_NOT_EMPTY */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3200 | if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20) == 0) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3201 | DSSERR("RX fifo empty when trying to read.\n"); |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3202 | r = -EIO; |
| 3203 | goto err; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3204 | } |
| 3205 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3206 | val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel)); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3207 | if (dsi->debug_read) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3208 | DSSDBG("\theader: %08x\n", val); |
| 3209 | dt = FLD_GET(val, 5, 0); |
| 3210 | if (dt == DSI_DT_RX_ACK_WITH_ERR) { |
| 3211 | u16 err = FLD_GET(val, 23, 8); |
| 3212 | dsi_show_rx_ack_with_err(err); |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3213 | r = -EIO; |
| 3214 | goto err; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3215 | |
| 3216 | } else if (dt == DSI_DT_RX_SHORT_READ_1) { |
| 3217 | u8 data = FLD_GET(val, 15, 8); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3218 | if (dsi->debug_read) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3219 | DSSDBG("\tDCS short response, 1 byte: %02x\n", data); |
| 3220 | |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3221 | if (buflen < 1) { |
| 3222 | r = -EIO; |
| 3223 | goto err; |
| 3224 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3225 | |
| 3226 | buf[0] = data; |
| 3227 | |
| 3228 | return 1; |
| 3229 | } else if (dt == DSI_DT_RX_SHORT_READ_2) { |
| 3230 | u16 data = FLD_GET(val, 23, 8); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3231 | if (dsi->debug_read) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3232 | DSSDBG("\tDCS short response, 2 byte: %04x\n", data); |
| 3233 | |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3234 | if (buflen < 2) { |
| 3235 | r = -EIO; |
| 3236 | goto err; |
| 3237 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3238 | |
| 3239 | buf[0] = data & 0xff; |
| 3240 | buf[1] = (data >> 8) & 0xff; |
| 3241 | |
| 3242 | return 2; |
| 3243 | } else if (dt == DSI_DT_RX_DCS_LONG_READ) { |
| 3244 | int w; |
| 3245 | int len = FLD_GET(val, 23, 8); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3246 | if (dsi->debug_read) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3247 | DSSDBG("\tDCS long response, len %d\n", len); |
| 3248 | |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3249 | if (len > buflen) { |
| 3250 | r = -EIO; |
| 3251 | goto err; |
| 3252 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3253 | |
| 3254 | /* two byte checksum ends the packet, not included in len */ |
| 3255 | for (w = 0; w < len + 2;) { |
| 3256 | int b; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3257 | val = dsi_read_reg(dsidev, |
| 3258 | DSI_VC_SHORT_PACKET_HEADER(channel)); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3259 | if (dsi->debug_read) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3260 | DSSDBG("\t\t%02x %02x %02x %02x\n", |
| 3261 | (val >> 0) & 0xff, |
| 3262 | (val >> 8) & 0xff, |
| 3263 | (val >> 16) & 0xff, |
| 3264 | (val >> 24) & 0xff); |
| 3265 | |
| 3266 | for (b = 0; b < 4; ++b) { |
| 3267 | if (w < len) |
| 3268 | buf[w] = (val >> (b * 8)) & 0xff; |
| 3269 | /* we discard the 2 byte checksum */ |
| 3270 | ++w; |
| 3271 | } |
| 3272 | } |
| 3273 | |
| 3274 | return len; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3275 | } else { |
| 3276 | DSSERR("\tunknown datatype 0x%02x\n", dt); |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3277 | r = -EIO; |
| 3278 | goto err; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3279 | } |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3280 | |
| 3281 | BUG(); |
| 3282 | err: |
| 3283 | DSSERR("dsi_vc_dcs_read(ch %d, cmd 0x%02x) failed\n", |
| 3284 | channel, dcs_cmd); |
| 3285 | return r; |
| 3286 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3287 | } |
| 3288 | EXPORT_SYMBOL(dsi_vc_dcs_read); |
| 3289 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 3290 | int dsi_vc_dcs_read_1(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd, |
| 3291 | u8 *data) |
Tomi Valkeinen | 828c48f | 2009-12-16 14:53:15 +0200 | [diff] [blame] | 3292 | { |
| 3293 | int r; |
| 3294 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 3295 | r = dsi_vc_dcs_read(dssdev, channel, dcs_cmd, data, 1); |
Tomi Valkeinen | 828c48f | 2009-12-16 14:53:15 +0200 | [diff] [blame] | 3296 | |
| 3297 | if (r < 0) |
| 3298 | return r; |
| 3299 | |
| 3300 | if (r != 1) |
| 3301 | return -EIO; |
| 3302 | |
| 3303 | return 0; |
| 3304 | } |
| 3305 | EXPORT_SYMBOL(dsi_vc_dcs_read_1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3306 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 3307 | int dsi_vc_dcs_read_2(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd, |
| 3308 | u8 *data1, u8 *data2) |
Tomi Valkeinen | 53055aa | 2010-02-25 11:38:13 +0200 | [diff] [blame] | 3309 | { |
Tomi Valkeinen | 0c244f7 | 2010-06-09 15:19:29 +0300 | [diff] [blame] | 3310 | u8 buf[2]; |
Tomi Valkeinen | 53055aa | 2010-02-25 11:38:13 +0200 | [diff] [blame] | 3311 | int r; |
| 3312 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 3313 | r = dsi_vc_dcs_read(dssdev, channel, dcs_cmd, buf, 2); |
Tomi Valkeinen | 53055aa | 2010-02-25 11:38:13 +0200 | [diff] [blame] | 3314 | |
| 3315 | if (r < 0) |
| 3316 | return r; |
| 3317 | |
| 3318 | if (r != 2) |
| 3319 | return -EIO; |
| 3320 | |
Tomi Valkeinen | 0c244f7 | 2010-06-09 15:19:29 +0300 | [diff] [blame] | 3321 | *data1 = buf[0]; |
| 3322 | *data2 = buf[1]; |
| 3323 | |
Tomi Valkeinen | 53055aa | 2010-02-25 11:38:13 +0200 | [diff] [blame] | 3324 | return 0; |
| 3325 | } |
| 3326 | EXPORT_SYMBOL(dsi_vc_dcs_read_2); |
| 3327 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 3328 | int dsi_vc_set_max_rx_packet_size(struct omap_dss_device *dssdev, int channel, |
| 3329 | u16 len) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3330 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3331 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 3332 | |
| 3333 | return dsi_vc_send_short(dsidev, channel, DSI_DT_SET_MAX_RET_PKG_SIZE, |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3334 | len, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3335 | } |
| 3336 | EXPORT_SYMBOL(dsi_vc_set_max_rx_packet_size); |
| 3337 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3338 | static int dsi_enter_ulps(struct platform_device *dsidev) |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3339 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3340 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3341 | DECLARE_COMPLETION_ONSTACK(completion); |
| 3342 | int r; |
| 3343 | |
| 3344 | DSSDBGF(); |
| 3345 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3346 | WARN_ON(!dsi_bus_is_locked(dsidev)); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3347 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3348 | WARN_ON(dsi->ulps_enabled); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3349 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3350 | if (dsi->ulps_enabled) |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3351 | return 0; |
| 3352 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3353 | if (REG_GET(dsidev, DSI_CLK_CTRL, 13, 13)) { |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3354 | DSSERR("DDR_CLK_ALWAYS_ON enabled when entering ULPS\n"); |
| 3355 | return -EIO; |
| 3356 | } |
| 3357 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3358 | dsi_sync_vc(dsidev, 0); |
| 3359 | dsi_sync_vc(dsidev, 1); |
| 3360 | dsi_sync_vc(dsidev, 2); |
| 3361 | dsi_sync_vc(dsidev, 3); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3362 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3363 | dsi_force_tx_stop_mode_io(dsidev); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3364 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3365 | dsi_vc_enable(dsidev, 0, false); |
| 3366 | dsi_vc_enable(dsidev, 1, false); |
| 3367 | dsi_vc_enable(dsidev, 2, false); |
| 3368 | dsi_vc_enable(dsidev, 3, false); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3369 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3370 | if (REG_GET(dsidev, DSI_COMPLEXIO_CFG2, 16, 16)) { /* HS_BUSY */ |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3371 | DSSERR("HS busy when enabling ULPS\n"); |
| 3372 | return -EIO; |
| 3373 | } |
| 3374 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3375 | if (REG_GET(dsidev, DSI_COMPLEXIO_CFG2, 17, 17)) { /* LP_BUSY */ |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3376 | DSSERR("LP busy when enabling ULPS\n"); |
| 3377 | return -EIO; |
| 3378 | } |
| 3379 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3380 | r = dsi_register_isr_cio(dsidev, dsi_completion_handler, &completion, |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3381 | DSI_CIO_IRQ_ULPSACTIVENOT_ALL0); |
| 3382 | if (r) |
| 3383 | return r; |
| 3384 | |
| 3385 | /* Assert TxRequestEsc for data lanes and TxUlpsClk for clk lane */ |
| 3386 | /* LANEx_ULPS_SIG2 */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3387 | REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG2, (1 << 0) | (1 << 1) | (1 << 2), |
| 3388 | 7, 5); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3389 | |
| 3390 | if (wait_for_completion_timeout(&completion, |
| 3391 | msecs_to_jiffies(1000)) == 0) { |
| 3392 | DSSERR("ULPS enable timeout\n"); |
| 3393 | r = -EIO; |
| 3394 | goto err; |
| 3395 | } |
| 3396 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3397 | dsi_unregister_isr_cio(dsidev, dsi_completion_handler, &completion, |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3398 | DSI_CIO_IRQ_ULPSACTIVENOT_ALL0); |
| 3399 | |
Tomi Valkeinen | 8ef0e61 | 2011-05-31 16:55:47 +0300 | [diff] [blame] | 3400 | /* Reset LANEx_ULPS_SIG2 */ |
| 3401 | REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG2, (0 << 0) | (0 << 1) | (0 << 2), |
| 3402 | 7, 5); |
| 3403 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3404 | dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_ULPS); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3405 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3406 | dsi_if_enable(dsidev, false); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3407 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3408 | dsi->ulps_enabled = true; |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3409 | |
| 3410 | return 0; |
| 3411 | |
| 3412 | err: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3413 | dsi_unregister_isr_cio(dsidev, dsi_completion_handler, &completion, |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3414 | DSI_CIO_IRQ_ULPSACTIVENOT_ALL0); |
| 3415 | return r; |
| 3416 | } |
| 3417 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3418 | static void dsi_set_lp_rx_timeout(struct platform_device *dsidev, |
| 3419 | unsigned ticks, bool x4, bool x16) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3420 | { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3421 | unsigned long fck; |
Tomi Valkeinen | 4ffa357 | 2010-04-12 10:40:12 +0300 | [diff] [blame] | 3422 | unsigned long total_ticks; |
| 3423 | u32 r; |
| 3424 | |
| 3425 | BUG_ON(ticks > 0x1fff); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3426 | |
| 3427 | /* ticks in DSI_FCK */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3428 | fck = dsi_fclk_rate(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3429 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3430 | r = dsi_read_reg(dsidev, DSI_TIMING2); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3431 | r = FLD_MOD(r, 1, 15, 15); /* LP_RX_TO */ |
Tomi Valkeinen | 4ffa357 | 2010-04-12 10:40:12 +0300 | [diff] [blame] | 3432 | r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* LP_RX_TO_X16 */ |
| 3433 | r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* LP_RX_TO_X4 */ |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3434 | r = FLD_MOD(r, ticks, 12, 0); /* LP_RX_COUNTER */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3435 | dsi_write_reg(dsidev, DSI_TIMING2, r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3436 | |
Tomi Valkeinen | 4ffa357 | 2010-04-12 10:40:12 +0300 | [diff] [blame] | 3437 | total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1); |
| 3438 | |
| 3439 | DSSDBG("LP_RX_TO %lu ticks (%#x%s%s) = %lu ns\n", |
| 3440 | total_ticks, |
| 3441 | ticks, x4 ? " x4" : "", x16 ? " x16" : "", |
| 3442 | (total_ticks * 1000) / (fck / 1000 / 1000)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3443 | } |
| 3444 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3445 | static void dsi_set_ta_timeout(struct platform_device *dsidev, unsigned ticks, |
| 3446 | bool x8, bool x16) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3447 | { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3448 | unsigned long fck; |
Tomi Valkeinen | 4ffa357 | 2010-04-12 10:40:12 +0300 | [diff] [blame] | 3449 | unsigned long total_ticks; |
| 3450 | u32 r; |
| 3451 | |
| 3452 | BUG_ON(ticks > 0x1fff); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3453 | |
| 3454 | /* ticks in DSI_FCK */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3455 | fck = dsi_fclk_rate(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3456 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3457 | r = dsi_read_reg(dsidev, DSI_TIMING1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3458 | r = FLD_MOD(r, 1, 31, 31); /* TA_TO */ |
Tomi Valkeinen | 4ffa357 | 2010-04-12 10:40:12 +0300 | [diff] [blame] | 3459 | r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* TA_TO_X16 */ |
| 3460 | r = FLD_MOD(r, x8 ? 1 : 0, 29, 29); /* TA_TO_X8 */ |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3461 | r = FLD_MOD(r, ticks, 28, 16); /* TA_TO_COUNTER */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3462 | dsi_write_reg(dsidev, DSI_TIMING1, r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3463 | |
Tomi Valkeinen | 4ffa357 | 2010-04-12 10:40:12 +0300 | [diff] [blame] | 3464 | total_ticks = ticks * (x16 ? 16 : 1) * (x8 ? 8 : 1); |
| 3465 | |
| 3466 | DSSDBG("TA_TO %lu ticks (%#x%s%s) = %lu ns\n", |
| 3467 | total_ticks, |
| 3468 | ticks, x8 ? " x8" : "", x16 ? " x16" : "", |
| 3469 | (total_ticks * 1000) / (fck / 1000 / 1000)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3470 | } |
| 3471 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3472 | static void dsi_set_stop_state_counter(struct platform_device *dsidev, |
| 3473 | unsigned ticks, bool x4, bool x16) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3474 | { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3475 | unsigned long fck; |
Tomi Valkeinen | 4ffa357 | 2010-04-12 10:40:12 +0300 | [diff] [blame] | 3476 | unsigned long total_ticks; |
| 3477 | u32 r; |
| 3478 | |
| 3479 | BUG_ON(ticks > 0x1fff); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3480 | |
| 3481 | /* ticks in DSI_FCK */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3482 | fck = dsi_fclk_rate(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3483 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3484 | r = dsi_read_reg(dsidev, DSI_TIMING1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3485 | r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */ |
Tomi Valkeinen | 4ffa357 | 2010-04-12 10:40:12 +0300 | [diff] [blame] | 3486 | r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* STOP_STATE_X16_IO */ |
| 3487 | r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* STOP_STATE_X4_IO */ |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3488 | r = FLD_MOD(r, ticks, 12, 0); /* STOP_STATE_COUNTER_IO */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3489 | dsi_write_reg(dsidev, DSI_TIMING1, r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3490 | |
Tomi Valkeinen | 4ffa357 | 2010-04-12 10:40:12 +0300 | [diff] [blame] | 3491 | total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1); |
| 3492 | |
| 3493 | DSSDBG("STOP_STATE_COUNTER %lu ticks (%#x%s%s) = %lu ns\n", |
| 3494 | total_ticks, |
| 3495 | ticks, x4 ? " x4" : "", x16 ? " x16" : "", |
| 3496 | (total_ticks * 1000) / (fck / 1000 / 1000)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3497 | } |
| 3498 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3499 | static void dsi_set_hs_tx_timeout(struct platform_device *dsidev, |
| 3500 | unsigned ticks, bool x4, bool x16) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3501 | { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3502 | unsigned long fck; |
Tomi Valkeinen | 4ffa357 | 2010-04-12 10:40:12 +0300 | [diff] [blame] | 3503 | unsigned long total_ticks; |
| 3504 | u32 r; |
| 3505 | |
| 3506 | BUG_ON(ticks > 0x1fff); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3507 | |
| 3508 | /* ticks in TxByteClkHS */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3509 | fck = dsi_get_txbyteclkhs(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3510 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3511 | r = dsi_read_reg(dsidev, DSI_TIMING2); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3512 | r = FLD_MOD(r, 1, 31, 31); /* HS_TX_TO */ |
Tomi Valkeinen | 4ffa357 | 2010-04-12 10:40:12 +0300 | [diff] [blame] | 3513 | r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* HS_TX_TO_X16 */ |
| 3514 | r = FLD_MOD(r, x4 ? 1 : 0, 29, 29); /* HS_TX_TO_X8 (4 really) */ |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3515 | r = FLD_MOD(r, ticks, 28, 16); /* HS_TX_TO_COUNTER */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3516 | dsi_write_reg(dsidev, DSI_TIMING2, r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3517 | |
Tomi Valkeinen | 4ffa357 | 2010-04-12 10:40:12 +0300 | [diff] [blame] | 3518 | total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1); |
| 3519 | |
| 3520 | DSSDBG("HS_TX_TO %lu ticks (%#x%s%s) = %lu ns\n", |
| 3521 | total_ticks, |
| 3522 | ticks, x4 ? " x4" : "", x16 ? " x16" : "", |
| 3523 | (total_ticks * 1000) / (fck / 1000 / 1000)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3524 | } |
| 3525 | static int dsi_proto_config(struct omap_dss_device *dssdev) |
| 3526 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3527 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3528 | u32 r; |
| 3529 | int buswidth = 0; |
| 3530 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3531 | dsi_config_tx_fifo(dsidev, DSI_FIFO_SIZE_32, |
Tomi Valkeinen | dd8079d | 2009-12-16 16:49:03 +0200 | [diff] [blame] | 3532 | DSI_FIFO_SIZE_32, |
| 3533 | DSI_FIFO_SIZE_32, |
| 3534 | DSI_FIFO_SIZE_32); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3535 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3536 | dsi_config_rx_fifo(dsidev, DSI_FIFO_SIZE_32, |
Tomi Valkeinen | dd8079d | 2009-12-16 16:49:03 +0200 | [diff] [blame] | 3537 | DSI_FIFO_SIZE_32, |
| 3538 | DSI_FIFO_SIZE_32, |
| 3539 | DSI_FIFO_SIZE_32); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3540 | |
| 3541 | /* XXX what values for the timeouts? */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3542 | dsi_set_stop_state_counter(dsidev, 0x1000, false, false); |
| 3543 | dsi_set_ta_timeout(dsidev, 0x1fff, true, true); |
| 3544 | dsi_set_lp_rx_timeout(dsidev, 0x1fff, true, true); |
| 3545 | dsi_set_hs_tx_timeout(dsidev, 0x1fff, true, true); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3546 | |
| 3547 | switch (dssdev->ctrl.pixel_size) { |
| 3548 | case 16: |
| 3549 | buswidth = 0; |
| 3550 | break; |
| 3551 | case 18: |
| 3552 | buswidth = 1; |
| 3553 | break; |
| 3554 | case 24: |
| 3555 | buswidth = 2; |
| 3556 | break; |
| 3557 | default: |
| 3558 | BUG(); |
| 3559 | } |
| 3560 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3561 | r = dsi_read_reg(dsidev, DSI_CTRL); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3562 | r = FLD_MOD(r, 1, 1, 1); /* CS_RX_EN */ |
| 3563 | r = FLD_MOD(r, 1, 2, 2); /* ECC_RX_EN */ |
| 3564 | r = FLD_MOD(r, 1, 3, 3); /* TX_FIFO_ARBITRATION */ |
| 3565 | r = FLD_MOD(r, 1, 4, 4); /* VP_CLK_RATIO, always 1, see errata*/ |
| 3566 | r = FLD_MOD(r, buswidth, 7, 6); /* VP_DATA_BUS_WIDTH */ |
| 3567 | r = FLD_MOD(r, 0, 8, 8); /* VP_CLK_POL */ |
| 3568 | r = FLD_MOD(r, 2, 13, 12); /* LINE_BUFFER, 2 lines */ |
| 3569 | r = FLD_MOD(r, 1, 14, 14); /* TRIGGER_RESET_MODE */ |
| 3570 | r = FLD_MOD(r, 1, 19, 19); /* EOT_ENABLE */ |
Archit Taneja | 9613c02 | 2011-03-22 06:33:36 -0500 | [diff] [blame] | 3571 | if (!dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC)) { |
| 3572 | r = FLD_MOD(r, 1, 24, 24); /* DCS_CMD_ENABLE */ |
| 3573 | /* DCS_CMD_CODE, 1=start, 0=continue */ |
| 3574 | r = FLD_MOD(r, 0, 25, 25); |
| 3575 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3576 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3577 | dsi_write_reg(dsidev, DSI_CTRL, r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3578 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3579 | dsi_vc_initial_config(dsidev, 0); |
| 3580 | dsi_vc_initial_config(dsidev, 1); |
| 3581 | dsi_vc_initial_config(dsidev, 2); |
| 3582 | dsi_vc_initial_config(dsidev, 3); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3583 | |
| 3584 | return 0; |
| 3585 | } |
| 3586 | |
| 3587 | static void dsi_proto_timings(struct omap_dss_device *dssdev) |
| 3588 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3589 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3590 | unsigned tlpx, tclk_zero, tclk_prepare, tclk_trail; |
| 3591 | unsigned tclk_pre, tclk_post; |
| 3592 | unsigned ths_prepare, ths_prepare_ths_zero, ths_zero; |
| 3593 | unsigned ths_trail, ths_exit; |
| 3594 | unsigned ddr_clk_pre, ddr_clk_post; |
| 3595 | unsigned enter_hs_mode_lat, exit_hs_mode_lat; |
| 3596 | unsigned ths_eot; |
| 3597 | u32 r; |
| 3598 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3599 | r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3600 | ths_prepare = FLD_GET(r, 31, 24); |
| 3601 | ths_prepare_ths_zero = FLD_GET(r, 23, 16); |
| 3602 | ths_zero = ths_prepare_ths_zero - ths_prepare; |
| 3603 | ths_trail = FLD_GET(r, 15, 8); |
| 3604 | ths_exit = FLD_GET(r, 7, 0); |
| 3605 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3606 | r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3607 | tlpx = FLD_GET(r, 22, 16) * 2; |
| 3608 | tclk_trail = FLD_GET(r, 15, 8); |
| 3609 | tclk_zero = FLD_GET(r, 7, 0); |
| 3610 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3611 | r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG2); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3612 | tclk_prepare = FLD_GET(r, 7, 0); |
| 3613 | |
| 3614 | /* min 8*UI */ |
| 3615 | tclk_pre = 20; |
| 3616 | /* min 60ns + 52*UI */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3617 | tclk_post = ns2ddr(dsidev, 60) + 26; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3618 | |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 3619 | ths_eot = DIV_ROUND_UP(4, dsi_get_num_data_lanes_dssdev(dssdev)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3620 | |
| 3621 | ddr_clk_pre = DIV_ROUND_UP(tclk_pre + tlpx + tclk_zero + tclk_prepare, |
| 3622 | 4); |
| 3623 | ddr_clk_post = DIV_ROUND_UP(tclk_post + ths_trail, 4) + ths_eot; |
| 3624 | |
| 3625 | BUG_ON(ddr_clk_pre == 0 || ddr_clk_pre > 255); |
| 3626 | BUG_ON(ddr_clk_post == 0 || ddr_clk_post > 255); |
| 3627 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3628 | r = dsi_read_reg(dsidev, DSI_CLK_TIMING); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3629 | r = FLD_MOD(r, ddr_clk_pre, 15, 8); |
| 3630 | r = FLD_MOD(r, ddr_clk_post, 7, 0); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3631 | dsi_write_reg(dsidev, DSI_CLK_TIMING, r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3632 | |
| 3633 | DSSDBG("ddr_clk_pre %u, ddr_clk_post %u\n", |
| 3634 | ddr_clk_pre, |
| 3635 | ddr_clk_post); |
| 3636 | |
| 3637 | enter_hs_mode_lat = 1 + DIV_ROUND_UP(tlpx, 4) + |
| 3638 | DIV_ROUND_UP(ths_prepare, 4) + |
| 3639 | DIV_ROUND_UP(ths_zero + 3, 4); |
| 3640 | |
| 3641 | exit_hs_mode_lat = DIV_ROUND_UP(ths_trail + ths_exit, 4) + 1 + ths_eot; |
| 3642 | |
| 3643 | r = FLD_VAL(enter_hs_mode_lat, 31, 16) | |
| 3644 | FLD_VAL(exit_hs_mode_lat, 15, 0); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3645 | dsi_write_reg(dsidev, DSI_VM_TIMING7, r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3646 | |
| 3647 | DSSDBG("enter_hs_mode_lat %u, exit_hs_mode_lat %u\n", |
| 3648 | enter_hs_mode_lat, exit_hs_mode_lat); |
| 3649 | } |
| 3650 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3651 | static void dsi_update_screen_dispc(struct omap_dss_device *dssdev, |
| 3652 | u16 x, u16 y, u16 w, u16 h) |
| 3653 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3654 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3655 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3656 | unsigned bytespp; |
| 3657 | unsigned bytespl; |
| 3658 | unsigned bytespf; |
| 3659 | unsigned total_len; |
| 3660 | unsigned packet_payload; |
| 3661 | unsigned packet_len; |
| 3662 | u32 l; |
Tomi Valkeinen | 0f16aa0 | 2010-04-12 09:57:19 +0300 | [diff] [blame] | 3663 | int r; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3664 | const unsigned channel = dsi->update_channel; |
Archit Taneja | 0c65622b | 2011-05-16 15:17:09 +0530 | [diff] [blame] | 3665 | const unsigned line_buf_size = dsi_get_line_buf_size(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3666 | |
Tomi Valkeinen | 446f7bf | 2010-01-11 16:12:31 +0200 | [diff] [blame] | 3667 | DSSDBG("dsi_update_screen_dispc(%d,%d %dx%d)\n", |
| 3668 | x, y, w, h); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3669 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3670 | dsi_vc_config_vp(dsidev, channel); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 3671 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3672 | bytespp = dssdev->ctrl.pixel_size / 8; |
| 3673 | bytespl = w * bytespp; |
| 3674 | bytespf = bytespl * h; |
| 3675 | |
| 3676 | /* NOTE: packet_payload has to be equal to N * bytespl, where N is |
| 3677 | * number of lines in a packet. See errata about VP_CLK_RATIO */ |
| 3678 | |
| 3679 | if (bytespf < line_buf_size) |
| 3680 | packet_payload = bytespf; |
| 3681 | else |
| 3682 | packet_payload = (line_buf_size) / bytespl * bytespl; |
| 3683 | |
| 3684 | packet_len = packet_payload + 1; /* 1 byte for DCS cmd */ |
| 3685 | total_len = (bytespf / packet_payload) * packet_len; |
| 3686 | |
| 3687 | if (bytespf % packet_payload) |
| 3688 | total_len += (bytespf % packet_payload) + 1; |
| 3689 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3690 | l = FLD_VAL(total_len, 23, 0); /* TE_SIZE */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3691 | dsi_write_reg(dsidev, DSI_VC_TE(channel), l); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3692 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3693 | dsi_vc_write_long_header(dsidev, channel, DSI_DT_DCS_LONG_WRITE, |
| 3694 | packet_len, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3695 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3696 | if (dsi->te_enabled) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3697 | l = FLD_MOD(l, 1, 30, 30); /* TE_EN */ |
| 3698 | else |
| 3699 | l = FLD_MOD(l, 1, 31, 31); /* TE_START */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3700 | dsi_write_reg(dsidev, DSI_VC_TE(channel), l); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3701 | |
| 3702 | /* We put SIDLEMODE to no-idle for the duration of the transfer, |
| 3703 | * because DSS interrupts are not capable of waking up the CPU and the |
| 3704 | * framedone interrupt could be delayed for quite a long time. I think |
| 3705 | * the same goes for any DSS interrupts, but for some reason I have not |
| 3706 | * seen the problem anywhere else than here. |
| 3707 | */ |
| 3708 | dispc_disable_sidle(); |
| 3709 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3710 | dsi_perf_mark_start(dsidev); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 3711 | |
Archit Taneja | 49dbf58 | 2011-05-16 15:17:07 +0530 | [diff] [blame] | 3712 | r = schedule_delayed_work(&dsi->framedone_timeout_work, |
| 3713 | msecs_to_jiffies(250)); |
Tomi Valkeinen | 0f16aa0 | 2010-04-12 09:57:19 +0300 | [diff] [blame] | 3714 | BUG_ON(r == 0); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 3715 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3716 | dss_start_update(dssdev); |
| 3717 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3718 | if (dsi->te_enabled) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3719 | /* disable LP_RX_TO, so that we can receive TE. Time to wait |
| 3720 | * for TE is longer than the timer allows */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3721 | REG_FLD_MOD(dsidev, DSI_TIMING2, 0, 15, 15); /* LP_RX_TO */ |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3722 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3723 | dsi_vc_send_bta(dsidev, channel); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3724 | |
| 3725 | #ifdef DSI_CATCH_MISSING_TE |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3726 | mod_timer(&dsi->te_timer, jiffies + msecs_to_jiffies(250)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3727 | #endif |
| 3728 | } |
| 3729 | } |
| 3730 | |
| 3731 | #ifdef DSI_CATCH_MISSING_TE |
| 3732 | static void dsi_te_timeout(unsigned long arg) |
| 3733 | { |
| 3734 | DSSERR("TE not received for 250ms!\n"); |
| 3735 | } |
| 3736 | #endif |
| 3737 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3738 | static void dsi_handle_framedone(struct platform_device *dsidev, int error) |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 3739 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3740 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 3741 | |
Tomi Valkeinen | ab83b14 | 2010-06-09 15:31:01 +0300 | [diff] [blame] | 3742 | /* SIDLEMODE back to smart-idle */ |
| 3743 | dispc_enable_sidle(); |
| 3744 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3745 | if (dsi->te_enabled) { |
Tomi Valkeinen | ab83b14 | 2010-06-09 15:31:01 +0300 | [diff] [blame] | 3746 | /* enable LP_RX_TO again after the TE */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3747 | REG_FLD_MOD(dsidev, DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */ |
Tomi Valkeinen | ab83b14 | 2010-06-09 15:31:01 +0300 | [diff] [blame] | 3748 | } |
| 3749 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3750 | dsi->framedone_callback(error, dsi->framedone_data); |
Tomi Valkeinen | ab83b14 | 2010-06-09 15:31:01 +0300 | [diff] [blame] | 3751 | |
| 3752 | if (!error) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3753 | dsi_perf_show(dsidev, "DISPC"); |
Tomi Valkeinen | ab83b14 | 2010-06-09 15:31:01 +0300 | [diff] [blame] | 3754 | } |
| 3755 | |
| 3756 | static void dsi_framedone_timeout_work_callback(struct work_struct *work) |
| 3757 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3758 | struct dsi_data *dsi = container_of(work, struct dsi_data, |
| 3759 | framedone_timeout_work.work); |
Tomi Valkeinen | 0f16aa0 | 2010-04-12 09:57:19 +0300 | [diff] [blame] | 3760 | /* XXX While extremely unlikely, we could get FRAMEDONE interrupt after |
| 3761 | * 250ms which would conflict with this timeout work. What should be |
| 3762 | * done is first cancel the transfer on the HW, and then cancel the |
Tomi Valkeinen | ab83b14 | 2010-06-09 15:31:01 +0300 | [diff] [blame] | 3763 | * possibly scheduled framedone work. However, cancelling the transfer |
| 3764 | * on the HW is buggy, and would probably require resetting the whole |
| 3765 | * DSI */ |
Tomi Valkeinen | 0f16aa0 | 2010-04-12 09:57:19 +0300 | [diff] [blame] | 3766 | |
Tomi Valkeinen | ab83b14 | 2010-06-09 15:31:01 +0300 | [diff] [blame] | 3767 | DSSERR("Framedone not received for 250ms!\n"); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 3768 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3769 | dsi_handle_framedone(dsi->pdev, -ETIMEDOUT); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 3770 | } |
| 3771 | |
Tomi Valkeinen | ab83b14 | 2010-06-09 15:31:01 +0300 | [diff] [blame] | 3772 | static void dsi_framedone_irq_callback(void *data, u32 mask) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3773 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3774 | struct omap_dss_device *dssdev = (struct omap_dss_device *) data; |
| 3775 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3776 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 3777 | |
Tomi Valkeinen | ab83b14 | 2010-06-09 15:31:01 +0300 | [diff] [blame] | 3778 | /* Note: We get FRAMEDONE when DISPC has finished sending pixels and |
| 3779 | * turns itself off. However, DSI still has the pixels in its buffers, |
| 3780 | * and is sending the data. |
| 3781 | */ |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3782 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3783 | __cancel_delayed_work(&dsi->framedone_timeout_work); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3784 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3785 | dsi_handle_framedone(dsidev, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3786 | |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 3787 | #ifdef CONFIG_OMAP2_DSS_FAKE_VSYNC |
| 3788 | dispc_fake_vsync_irq(); |
| 3789 | #endif |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 3790 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3791 | |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 3792 | int omap_dsi_prepare_update(struct omap_dss_device *dssdev, |
Tomi Valkeinen | 26a8c25 | 2010-06-09 15:31:34 +0300 | [diff] [blame] | 3793 | u16 *x, u16 *y, u16 *w, u16 *h, |
| 3794 | bool enlarge_update_area) |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 3795 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3796 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 3797 | u16 dw, dh; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3798 | |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 3799 | dssdev->driver->get_resolution(dssdev, &dw, &dh); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3800 | |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 3801 | if (*x > dw || *y > dh) |
| 3802 | return -EINVAL; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3803 | |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 3804 | if (*x + *w > dw) |
| 3805 | return -EINVAL; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3806 | |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 3807 | if (*y + *h > dh) |
| 3808 | return -EINVAL; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3809 | |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 3810 | if (*w == 1) |
| 3811 | return -EINVAL; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3812 | |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 3813 | if (*w == 0 || *h == 0) |
| 3814 | return -EINVAL; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3815 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3816 | dsi_perf_mark_setup(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3817 | |
Tomi Valkeinen | 4a9e78a | 2011-08-15 11:22:21 +0300 | [diff] [blame^] | 3818 | dss_setup_partial_planes(dssdev, x, y, w, h, |
| 3819 | enlarge_update_area); |
| 3820 | dispc_set_lcd_size(dssdev->manager->id, *w, *h); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3821 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3822 | return 0; |
| 3823 | } |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 3824 | EXPORT_SYMBOL(omap_dsi_prepare_update); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3825 | |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 3826 | int omap_dsi_update(struct omap_dss_device *dssdev, |
| 3827 | int channel, |
| 3828 | u16 x, u16 y, u16 w, u16 h, |
| 3829 | void (*callback)(int, void *), void *data) |
| 3830 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3831 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3832 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3833 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3834 | dsi->update_channel = channel; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3835 | |
Tomi Valkeinen | a602771 | 2010-05-25 17:01:28 +0300 | [diff] [blame] | 3836 | /* OMAP DSS cannot send updates of odd widths. |
| 3837 | * omap_dsi_prepare_update() makes the widths even, but add a BUG_ON |
| 3838 | * here to make sure we catch erroneous updates. Otherwise we'll only |
| 3839 | * see rather obscure HW error happening, as DSS halts. */ |
| 3840 | BUG_ON(x % 2 == 1); |
| 3841 | |
Tomi Valkeinen | 4a9e78a | 2011-08-15 11:22:21 +0300 | [diff] [blame^] | 3842 | dsi->framedone_callback = callback; |
| 3843 | dsi->framedone_data = data; |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 3844 | |
Tomi Valkeinen | 4a9e78a | 2011-08-15 11:22:21 +0300 | [diff] [blame^] | 3845 | dsi->update_region.x = x; |
| 3846 | dsi->update_region.y = y; |
| 3847 | dsi->update_region.w = w; |
| 3848 | dsi->update_region.h = h; |
| 3849 | dsi->update_region.device = dssdev; |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 3850 | |
Tomi Valkeinen | 4a9e78a | 2011-08-15 11:22:21 +0300 | [diff] [blame^] | 3851 | dsi_update_screen_dispc(dssdev, x, y, w, h); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 3852 | |
| 3853 | return 0; |
| 3854 | } |
| 3855 | EXPORT_SYMBOL(omap_dsi_update); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3856 | |
| 3857 | /* Display funcs */ |
| 3858 | |
| 3859 | static int dsi_display_init_dispc(struct omap_dss_device *dssdev) |
| 3860 | { |
| 3861 | int r; |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 3862 | u32 irq; |
| 3863 | |
| 3864 | irq = dssdev->manager->id == OMAP_DSS_CHANNEL_LCD ? |
| 3865 | DISPC_IRQ_FRAMEDONE : DISPC_IRQ_FRAMEDONE2; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3866 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3867 | r = omap_dispc_register_isr(dsi_framedone_irq_callback, (void *) dssdev, |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 3868 | irq); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3869 | if (r) { |
| 3870 | DSSERR("can't get FRAMEDONE irq\n"); |
| 3871 | return r; |
| 3872 | } |
| 3873 | |
Sumit Semwal | 64ba4f7 | 2010-12-02 11:27:10 +0000 | [diff] [blame] | 3874 | dispc_set_lcd_display_type(dssdev->manager->id, |
| 3875 | OMAP_DSS_LCD_DISPLAY_TFT); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3876 | |
Sumit Semwal | 64ba4f7 | 2010-12-02 11:27:10 +0000 | [diff] [blame] | 3877 | dispc_set_parallel_interface_mode(dssdev->manager->id, |
| 3878 | OMAP_DSS_PARALLELMODE_DSI); |
| 3879 | dispc_enable_fifohandcheck(dssdev->manager->id, 1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3880 | |
Sumit Semwal | 64ba4f7 | 2010-12-02 11:27:10 +0000 | [diff] [blame] | 3881 | dispc_set_tft_data_lines(dssdev->manager->id, dssdev->ctrl.pixel_size); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3882 | |
| 3883 | { |
| 3884 | struct omap_video_timings timings = { |
| 3885 | .hsw = 1, |
| 3886 | .hfp = 1, |
| 3887 | .hbp = 1, |
| 3888 | .vsw = 1, |
| 3889 | .vfp = 0, |
| 3890 | .vbp = 0, |
| 3891 | }; |
| 3892 | |
Sumit Semwal | 64ba4f7 | 2010-12-02 11:27:10 +0000 | [diff] [blame] | 3893 | dispc_set_lcd_timings(dssdev->manager->id, &timings); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3894 | } |
| 3895 | |
| 3896 | return 0; |
| 3897 | } |
| 3898 | |
| 3899 | static void dsi_display_uninit_dispc(struct omap_dss_device *dssdev) |
| 3900 | { |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 3901 | u32 irq; |
| 3902 | |
| 3903 | irq = dssdev->manager->id == OMAP_DSS_CHANNEL_LCD ? |
| 3904 | DISPC_IRQ_FRAMEDONE : DISPC_IRQ_FRAMEDONE2; |
| 3905 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3906 | omap_dispc_unregister_isr(dsi_framedone_irq_callback, (void *) dssdev, |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 3907 | irq); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3908 | } |
| 3909 | |
| 3910 | static int dsi_configure_dsi_clocks(struct omap_dss_device *dssdev) |
| 3911 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3912 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3913 | struct dsi_clock_info cinfo; |
| 3914 | int r; |
| 3915 | |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 3916 | /* we always use DSS_CLK_SYSCK as input clock */ |
| 3917 | cinfo.use_sys_clk = true; |
Tomi Valkeinen | c6940a3 | 2011-02-22 13:36:10 +0200 | [diff] [blame] | 3918 | cinfo.regn = dssdev->clocks.dsi.regn; |
| 3919 | cinfo.regm = dssdev->clocks.dsi.regm; |
| 3920 | cinfo.regm_dispc = dssdev->clocks.dsi.regm_dispc; |
| 3921 | cinfo.regm_dsi = dssdev->clocks.dsi.regm_dsi; |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 3922 | r = dsi_calc_clock_rates(dssdev, &cinfo); |
Ville Syrjälä | ebf0a3f | 2010-04-22 22:50:05 +0200 | [diff] [blame] | 3923 | if (r) { |
| 3924 | DSSERR("Failed to calc dsi clocks\n"); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3925 | return r; |
Ville Syrjälä | ebf0a3f | 2010-04-22 22:50:05 +0200 | [diff] [blame] | 3926 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3927 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3928 | r = dsi_pll_set_clock_div(dsidev, &cinfo); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3929 | if (r) { |
| 3930 | DSSERR("Failed to set dsi clocks\n"); |
| 3931 | return r; |
| 3932 | } |
| 3933 | |
| 3934 | return 0; |
| 3935 | } |
| 3936 | |
| 3937 | static int dsi_configure_dispc_clocks(struct omap_dss_device *dssdev) |
| 3938 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3939 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3940 | struct dispc_clock_info dispc_cinfo; |
| 3941 | int r; |
| 3942 | unsigned long long fck; |
| 3943 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3944 | fck = dsi_get_pll_hsdiv_dispc_rate(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3945 | |
Archit Taneja | e888166 | 2011-04-12 13:52:24 +0530 | [diff] [blame] | 3946 | dispc_cinfo.lck_div = dssdev->clocks.dispc.channel.lck_div; |
| 3947 | dispc_cinfo.pck_div = dssdev->clocks.dispc.channel.pck_div; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3948 | |
| 3949 | r = dispc_calc_clock_rates(fck, &dispc_cinfo); |
| 3950 | if (r) { |
| 3951 | DSSERR("Failed to calc dispc clocks\n"); |
| 3952 | return r; |
| 3953 | } |
| 3954 | |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 3955 | r = dispc_set_clock_div(dssdev->manager->id, &dispc_cinfo); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3956 | if (r) { |
| 3957 | DSSERR("Failed to set dispc clocks\n"); |
| 3958 | return r; |
| 3959 | } |
| 3960 | |
| 3961 | return 0; |
| 3962 | } |
| 3963 | |
| 3964 | static int dsi_display_init_dsi(struct omap_dss_device *dssdev) |
| 3965 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3966 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 3967 | int dsi_module = dsi_get_dsidev_id(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3968 | int r; |
| 3969 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3970 | r = dsi_pll_init(dsidev, true, true); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3971 | if (r) |
| 3972 | goto err0; |
| 3973 | |
| 3974 | r = dsi_configure_dsi_clocks(dssdev); |
| 3975 | if (r) |
| 3976 | goto err1; |
| 3977 | |
Archit Taneja | e888166 | 2011-04-12 13:52:24 +0530 | [diff] [blame] | 3978 | dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src); |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 3979 | dss_select_dsi_clk_source(dsi_module, dssdev->clocks.dsi.dsi_fclk_src); |
Archit Taneja | 9613c02 | 2011-03-22 06:33:36 -0500 | [diff] [blame] | 3980 | dss_select_lcd_clk_source(dssdev->manager->id, |
Archit Taneja | e888166 | 2011-04-12 13:52:24 +0530 | [diff] [blame] | 3981 | dssdev->clocks.dispc.channel.lcd_clk_src); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3982 | |
| 3983 | DSSDBG("PLL OK\n"); |
| 3984 | |
| 3985 | r = dsi_configure_dispc_clocks(dssdev); |
| 3986 | if (r) |
| 3987 | goto err2; |
| 3988 | |
Tomi Valkeinen | cc5c185 | 2010-10-06 15:18:13 +0300 | [diff] [blame] | 3989 | r = dsi_cio_init(dssdev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3990 | if (r) |
| 3991 | goto err2; |
| 3992 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3993 | _dsi_print_reset_status(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3994 | |
| 3995 | dsi_proto_timings(dssdev); |
| 3996 | dsi_set_lp_clk_divisor(dssdev); |
| 3997 | |
| 3998 | if (1) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3999 | _dsi_print_reset_status(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4000 | |
| 4001 | r = dsi_proto_config(dssdev); |
| 4002 | if (r) |
| 4003 | goto err3; |
| 4004 | |
| 4005 | /* enable interface */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4006 | dsi_vc_enable(dsidev, 0, 1); |
| 4007 | dsi_vc_enable(dsidev, 1, 1); |
| 4008 | dsi_vc_enable(dsidev, 2, 1); |
| 4009 | dsi_vc_enable(dsidev, 3, 1); |
| 4010 | dsi_if_enable(dsidev, 1); |
| 4011 | dsi_force_tx_stop_mode_io(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4012 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4013 | return 0; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4014 | err3: |
Tomi Valkeinen | 5bc416c | 2011-06-15 15:21:12 +0300 | [diff] [blame] | 4015 | dsi_cio_uninit(dssdev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4016 | err2: |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 4017 | dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK); |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 4018 | dss_select_dsi_clk_source(dsi_module, OMAP_DSS_CLK_SRC_FCK); |
Tomi Valkeinen | 5e78509 | 2011-08-10 11:25:36 +0300 | [diff] [blame] | 4019 | dss_select_lcd_clk_source(dssdev->manager->id, OMAP_DSS_CLK_SRC_FCK); |
| 4020 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4021 | err1: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4022 | dsi_pll_uninit(dsidev, true); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4023 | err0: |
| 4024 | return r; |
| 4025 | } |
| 4026 | |
Tomi Valkeinen | 2a89dc1 | 2010-07-30 12:39:34 +0300 | [diff] [blame] | 4027 | static void dsi_display_uninit_dsi(struct omap_dss_device *dssdev, |
Tomi Valkeinen | 22d6d67 | 2010-10-11 11:33:30 +0300 | [diff] [blame] | 4028 | bool disconnect_lanes, bool enter_ulps) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4029 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4030 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4031 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 4032 | int dsi_module = dsi_get_dsidev_id(dsidev); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4033 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4034 | if (enter_ulps && !dsi->ulps_enabled) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4035 | dsi_enter_ulps(dsidev); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 4036 | |
Ville Syrjälä | d737010 | 2010-04-22 22:50:09 +0200 | [diff] [blame] | 4037 | /* disable interface */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4038 | dsi_if_enable(dsidev, 0); |
| 4039 | dsi_vc_enable(dsidev, 0, 0); |
| 4040 | dsi_vc_enable(dsidev, 1, 0); |
| 4041 | dsi_vc_enable(dsidev, 2, 0); |
| 4042 | dsi_vc_enable(dsidev, 3, 0); |
Ville Syrjälä | d737010 | 2010-04-22 22:50:09 +0200 | [diff] [blame] | 4043 | |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 4044 | dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK); |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 4045 | dss_select_dsi_clk_source(dsi_module, OMAP_DSS_CLK_SRC_FCK); |
Tomi Valkeinen | 5e78509 | 2011-08-10 11:25:36 +0300 | [diff] [blame] | 4046 | dss_select_lcd_clk_source(dssdev->manager->id, OMAP_DSS_CLK_SRC_FCK); |
Tomi Valkeinen | 5bc416c | 2011-06-15 15:21:12 +0300 | [diff] [blame] | 4047 | dsi_cio_uninit(dssdev); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4048 | dsi_pll_uninit(dsidev, disconnect_lanes); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4049 | } |
| 4050 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 4051 | int omapdss_dsi_display_enable(struct omap_dss_device *dssdev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4052 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4053 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4054 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4055 | int r = 0; |
| 4056 | |
| 4057 | DSSDBG("dsi_display_enable\n"); |
| 4058 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4059 | WARN_ON(!dsi_bus_is_locked(dsidev)); |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 4060 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4061 | mutex_lock(&dsi->lock); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4062 | |
Tomi Valkeinen | 05e1d60 | 2011-06-23 16:38:21 +0300 | [diff] [blame] | 4063 | if (dssdev->manager == NULL) { |
| 4064 | DSSERR("failed to enable display: no manager\n"); |
| 4065 | r = -ENODEV; |
| 4066 | goto err_start_dev; |
| 4067 | } |
| 4068 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4069 | r = omap_dss_start_device(dssdev); |
| 4070 | if (r) { |
| 4071 | DSSERR("failed to start device\n"); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4072 | goto err_start_dev; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4073 | } |
| 4074 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4075 | r = dsi_runtime_get(dsidev); |
| 4076 | if (r) |
| 4077 | goto err_get_dsi; |
| 4078 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4079 | dsi_enable_pll_clock(dsidev, 1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4080 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4081 | _dsi_initialize_irq(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4082 | |
| 4083 | r = dsi_display_init_dispc(dssdev); |
| 4084 | if (r) |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4085 | goto err_init_dispc; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4086 | |
| 4087 | r = dsi_display_init_dsi(dssdev); |
| 4088 | if (r) |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4089 | goto err_init_dsi; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4090 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4091 | mutex_unlock(&dsi->lock); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4092 | |
| 4093 | return 0; |
| 4094 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4095 | err_init_dsi: |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 4096 | dsi_display_uninit_dispc(dssdev); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4097 | err_init_dispc: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4098 | dsi_enable_pll_clock(dsidev, 0); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4099 | dsi_runtime_put(dsidev); |
| 4100 | err_get_dsi: |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4101 | omap_dss_stop_device(dssdev); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4102 | err_start_dev: |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4103 | mutex_unlock(&dsi->lock); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4104 | DSSDBG("dsi_display_enable FAILED\n"); |
| 4105 | return r; |
| 4106 | } |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 4107 | EXPORT_SYMBOL(omapdss_dsi_display_enable); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4108 | |
Tomi Valkeinen | 2a89dc1 | 2010-07-30 12:39:34 +0300 | [diff] [blame] | 4109 | void omapdss_dsi_display_disable(struct omap_dss_device *dssdev, |
Tomi Valkeinen | 22d6d67 | 2010-10-11 11:33:30 +0300 | [diff] [blame] | 4110 | bool disconnect_lanes, bool enter_ulps) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4111 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4112 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4113 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4114 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4115 | DSSDBG("dsi_display_disable\n"); |
| 4116 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4117 | WARN_ON(!dsi_bus_is_locked(dsidev)); |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 4118 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4119 | mutex_lock(&dsi->lock); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4120 | |
Tomi Valkeinen | 15ffa1d | 2011-06-16 14:34:06 +0300 | [diff] [blame] | 4121 | dsi_sync_vc(dsidev, 0); |
| 4122 | dsi_sync_vc(dsidev, 1); |
| 4123 | dsi_sync_vc(dsidev, 2); |
| 4124 | dsi_sync_vc(dsidev, 3); |
| 4125 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4126 | dsi_display_uninit_dispc(dssdev); |
| 4127 | |
Tomi Valkeinen | 22d6d67 | 2010-10-11 11:33:30 +0300 | [diff] [blame] | 4128 | dsi_display_uninit_dsi(dssdev, disconnect_lanes, enter_ulps); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4129 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4130 | dsi_runtime_put(dsidev); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4131 | dsi_enable_pll_clock(dsidev, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4132 | |
| 4133 | omap_dss_stop_device(dssdev); |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 4134 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4135 | mutex_unlock(&dsi->lock); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4136 | } |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 4137 | EXPORT_SYMBOL(omapdss_dsi_display_disable); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4138 | |
Tomi Valkeinen | 225b650 | 2010-01-11 15:11:01 +0200 | [diff] [blame] | 4139 | int omapdss_dsi_enable_te(struct omap_dss_device *dssdev, bool enable) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4140 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4141 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 4142 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 4143 | |
| 4144 | dsi->te_enabled = enable; |
Tomi Valkeinen | 225b650 | 2010-01-11 15:11:01 +0200 | [diff] [blame] | 4145 | return 0; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4146 | } |
Tomi Valkeinen | 225b650 | 2010-01-11 15:11:01 +0200 | [diff] [blame] | 4147 | EXPORT_SYMBOL(omapdss_dsi_enable_te); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4148 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4149 | void dsi_get_overlay_fifo_thresholds(enum omap_plane plane, |
Tomi Valkeinen | 5ed8cf5 | 2011-06-21 09:35:36 +0300 | [diff] [blame] | 4150 | u32 fifo_size, u32 burst_size, |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4151 | u32 *fifo_low, u32 *fifo_high) |
| 4152 | { |
Tomi Valkeinen | 5ed8cf5 | 2011-06-21 09:35:36 +0300 | [diff] [blame] | 4153 | *fifo_high = fifo_size - burst_size; |
| 4154 | *fifo_low = fifo_size - burst_size * 2; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4155 | } |
| 4156 | |
| 4157 | int dsi_init_display(struct omap_dss_device *dssdev) |
| 4158 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4159 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 4160 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 4161 | int dsi_module = dsi_get_dsidev_id(dsidev); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4162 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4163 | DSSDBG("DSI init\n"); |
| 4164 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4165 | /* XXX these should be figured out dynamically */ |
| 4166 | dssdev->caps = OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE | |
| 4167 | OMAP_DSS_DISPLAY_CAP_TEAR_ELIM; |
| 4168 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4169 | if (dsi->vdds_dsi_reg == NULL) { |
Tomi Valkeinen | 5f42f2ce | 2011-02-22 15:53:46 +0200 | [diff] [blame] | 4170 | struct regulator *vdds_dsi; |
| 4171 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4172 | vdds_dsi = regulator_get(&dsi->pdev->dev, "vdds_dsi"); |
Tomi Valkeinen | 5f42f2ce | 2011-02-22 15:53:46 +0200 | [diff] [blame] | 4173 | |
| 4174 | if (IS_ERR(vdds_dsi)) { |
| 4175 | DSSERR("can't get VDDS_DSI regulator\n"); |
| 4176 | return PTR_ERR(vdds_dsi); |
| 4177 | } |
| 4178 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4179 | dsi->vdds_dsi_reg = vdds_dsi; |
Tomi Valkeinen | 5f42f2ce | 2011-02-22 15:53:46 +0200 | [diff] [blame] | 4180 | } |
| 4181 | |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 4182 | if (dsi_get_num_data_lanes_dssdev(dssdev) > dsi->num_data_lanes) { |
| 4183 | DSSERR("DSI%d can't support more than %d data lanes\n", |
| 4184 | dsi_module + 1, dsi->num_data_lanes); |
| 4185 | return -EINVAL; |
| 4186 | } |
| 4187 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4188 | return 0; |
| 4189 | } |
| 4190 | |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 4191 | int omap_dsi_request_vc(struct omap_dss_device *dssdev, int *channel) |
| 4192 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4193 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 4194 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 4195 | int i; |
| 4196 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4197 | for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) { |
| 4198 | if (!dsi->vc[i].dssdev) { |
| 4199 | dsi->vc[i].dssdev = dssdev; |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 4200 | *channel = i; |
| 4201 | return 0; |
| 4202 | } |
| 4203 | } |
| 4204 | |
| 4205 | DSSERR("cannot get VC for display %s", dssdev->name); |
| 4206 | return -ENOSPC; |
| 4207 | } |
| 4208 | EXPORT_SYMBOL(omap_dsi_request_vc); |
| 4209 | |
| 4210 | int omap_dsi_set_vc_id(struct omap_dss_device *dssdev, int channel, int vc_id) |
| 4211 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4212 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 4213 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 4214 | |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 4215 | if (vc_id < 0 || vc_id > 3) { |
| 4216 | DSSERR("VC ID out of range\n"); |
| 4217 | return -EINVAL; |
| 4218 | } |
| 4219 | |
| 4220 | if (channel < 0 || channel > 3) { |
| 4221 | DSSERR("Virtual Channel out of range\n"); |
| 4222 | return -EINVAL; |
| 4223 | } |
| 4224 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4225 | if (dsi->vc[channel].dssdev != dssdev) { |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 4226 | DSSERR("Virtual Channel not allocated to display %s\n", |
| 4227 | dssdev->name); |
| 4228 | return -EINVAL; |
| 4229 | } |
| 4230 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4231 | dsi->vc[channel].vc_id = vc_id; |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 4232 | |
| 4233 | return 0; |
| 4234 | } |
| 4235 | EXPORT_SYMBOL(omap_dsi_set_vc_id); |
| 4236 | |
| 4237 | void omap_dsi_release_vc(struct omap_dss_device *dssdev, int channel) |
| 4238 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4239 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 4240 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 4241 | |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 4242 | if ((channel >= 0 && channel <= 3) && |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4243 | dsi->vc[channel].dssdev == dssdev) { |
| 4244 | dsi->vc[channel].dssdev = NULL; |
| 4245 | dsi->vc[channel].vc_id = 0; |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 4246 | } |
| 4247 | } |
| 4248 | EXPORT_SYMBOL(omap_dsi_release_vc); |
| 4249 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4250 | void dsi_wait_pll_hsdiv_dispc_active(struct platform_device *dsidev) |
Tomi Valkeinen | e406f90 | 2010-06-09 15:28:12 +0300 | [diff] [blame] | 4251 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4252 | if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 7, 1) != 1) |
Archit Taneja | 067a57e | 2011-03-02 11:57:25 +0530 | [diff] [blame] | 4253 | DSSERR("%s (%s) not active\n", |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 4254 | dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC), |
| 4255 | dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC)); |
Tomi Valkeinen | e406f90 | 2010-06-09 15:28:12 +0300 | [diff] [blame] | 4256 | } |
| 4257 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4258 | void dsi_wait_pll_hsdiv_dsi_active(struct platform_device *dsidev) |
Tomi Valkeinen | e406f90 | 2010-06-09 15:28:12 +0300 | [diff] [blame] | 4259 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4260 | if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 8, 1) != 1) |
Archit Taneja | 067a57e | 2011-03-02 11:57:25 +0530 | [diff] [blame] | 4261 | DSSERR("%s (%s) not active\n", |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 4262 | dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI), |
| 4263 | dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI)); |
Tomi Valkeinen | e406f90 | 2010-06-09 15:28:12 +0300 | [diff] [blame] | 4264 | } |
| 4265 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4266 | static void dsi_calc_clock_param_ranges(struct platform_device *dsidev) |
Taneja, Archit | 4964111 | 2011-03-14 23:28:23 -0500 | [diff] [blame] | 4267 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4268 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 4269 | |
| 4270 | dsi->regn_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGN); |
| 4271 | dsi->regm_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM); |
| 4272 | dsi->regm_dispc_max = |
| 4273 | dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DISPC); |
| 4274 | dsi->regm_dsi_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DSI); |
| 4275 | dsi->fint_min = dss_feat_get_param_min(FEAT_PARAM_DSIPLL_FINT); |
| 4276 | dsi->fint_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_FINT); |
| 4277 | dsi->lpdiv_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_LPDIV); |
Taneja, Archit | 4964111 | 2011-03-14 23:28:23 -0500 | [diff] [blame] | 4278 | } |
| 4279 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4280 | static int dsi_get_clocks(struct platform_device *dsidev) |
| 4281 | { |
| 4282 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 4283 | struct clk *clk; |
| 4284 | |
| 4285 | clk = clk_get(&dsidev->dev, "fck"); |
| 4286 | if (IS_ERR(clk)) { |
| 4287 | DSSERR("can't get fck\n"); |
| 4288 | return PTR_ERR(clk); |
| 4289 | } |
| 4290 | |
| 4291 | dsi->dss_clk = clk; |
| 4292 | |
Tomi Valkeinen | bfe4f8d | 2011-08-04 11:22:54 +0300 | [diff] [blame] | 4293 | clk = clk_get(&dsidev->dev, "sys_clk"); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4294 | if (IS_ERR(clk)) { |
| 4295 | DSSERR("can't get sys_clk\n"); |
| 4296 | clk_put(dsi->dss_clk); |
| 4297 | dsi->dss_clk = NULL; |
| 4298 | return PTR_ERR(clk); |
| 4299 | } |
| 4300 | |
| 4301 | dsi->sys_clk = clk; |
| 4302 | |
| 4303 | return 0; |
| 4304 | } |
| 4305 | |
| 4306 | static void dsi_put_clocks(struct platform_device *dsidev) |
| 4307 | { |
| 4308 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 4309 | |
| 4310 | if (dsi->dss_clk) |
| 4311 | clk_put(dsi->dss_clk); |
| 4312 | if (dsi->sys_clk) |
| 4313 | clk_put(dsi->sys_clk); |
| 4314 | } |
| 4315 | |
Tomi Valkeinen | b98482e | 2011-05-16 13:52:51 +0300 | [diff] [blame] | 4316 | /* DSI1 HW IP initialisation */ |
Tomi Valkeinen | 7c68dd9 | 2011-08-03 14:00:57 +0300 | [diff] [blame] | 4317 | static int omap_dsihw_probe(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4318 | { |
Tomi Valkeinen | d1f5857 | 2010-07-30 11:57:57 +0300 | [diff] [blame] | 4319 | struct omap_display_platform_data *dss_plat_data; |
| 4320 | struct omap_dss_board_info *board_info; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4321 | u32 rev; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4322 | int r, i, dsi_module = dsi_get_dsidev_id(dsidev); |
Senthilvadivu Guruswamy | ea9da36 | 2011-01-24 06:22:04 +0000 | [diff] [blame] | 4323 | struct resource *dsi_mem; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4324 | struct dsi_data *dsi; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4325 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4326 | dsi = kzalloc(sizeof(*dsi), GFP_KERNEL); |
| 4327 | if (!dsi) { |
| 4328 | r = -ENOMEM; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4329 | goto err_alloc; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4330 | } |
| 4331 | |
| 4332 | dsi->pdev = dsidev; |
| 4333 | dsi_pdev_map[dsi_module] = dsidev; |
| 4334 | dev_set_drvdata(&dsidev->dev, dsi); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4335 | |
| 4336 | dss_plat_data = dsidev->dev.platform_data; |
Tomi Valkeinen | d1f5857 | 2010-07-30 11:57:57 +0300 | [diff] [blame] | 4337 | board_info = dss_plat_data->board_data; |
Tomi Valkeinen | 5bc416c | 2011-06-15 15:21:12 +0300 | [diff] [blame] | 4338 | dsi->enable_pads = board_info->dsi_enable_pads; |
| 4339 | dsi->disable_pads = board_info->dsi_disable_pads; |
Tomi Valkeinen | d1f5857 | 2010-07-30 11:57:57 +0300 | [diff] [blame] | 4340 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4341 | spin_lock_init(&dsi->irq_lock); |
| 4342 | spin_lock_init(&dsi->errors_lock); |
| 4343 | dsi->errors = 0; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4344 | |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 4345 | #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4346 | spin_lock_init(&dsi->irq_stats_lock); |
| 4347 | dsi->irq_stats.last_reset = jiffies; |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 4348 | #endif |
| 4349 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4350 | mutex_init(&dsi->lock); |
| 4351 | sema_init(&dsi->bus_lock, 1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4352 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4353 | r = dsi_get_clocks(dsidev); |
| 4354 | if (r) |
| 4355 | goto err_get_clk; |
| 4356 | |
| 4357 | pm_runtime_enable(&dsidev->dev); |
| 4358 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4359 | INIT_DELAYED_WORK_DEFERRABLE(&dsi->framedone_timeout_work, |
| 4360 | dsi_framedone_timeout_work_callback); |
| 4361 | |
| 4362 | #ifdef DSI_CATCH_MISSING_TE |
| 4363 | init_timer(&dsi->te_timer); |
| 4364 | dsi->te_timer.function = dsi_te_timeout; |
| 4365 | dsi->te_timer.data = 0; |
| 4366 | #endif |
| 4367 | dsi_mem = platform_get_resource(dsi->pdev, IORESOURCE_MEM, 0); |
| 4368 | if (!dsi_mem) { |
| 4369 | DSSERR("can't get IORESOURCE_MEM DSI\n"); |
| 4370 | r = -EINVAL; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4371 | goto err_ioremap; |
archit taneja | affe360 | 2011-02-23 08:41:03 +0000 | [diff] [blame] | 4372 | } |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4373 | dsi->base = ioremap(dsi_mem->start, resource_size(dsi_mem)); |
| 4374 | if (!dsi->base) { |
| 4375 | DSSERR("can't ioremap DSI\n"); |
| 4376 | r = -ENOMEM; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4377 | goto err_ioremap; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4378 | } |
| 4379 | dsi->irq = platform_get_irq(dsi->pdev, 0); |
| 4380 | if (dsi->irq < 0) { |
| 4381 | DSSERR("platform_get_irq failed\n"); |
| 4382 | r = -ENODEV; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4383 | goto err_get_irq; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4384 | } |
archit taneja | affe360 | 2011-02-23 08:41:03 +0000 | [diff] [blame] | 4385 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4386 | r = request_irq(dsi->irq, omap_dsi_irq_handler, IRQF_SHARED, |
| 4387 | dev_name(&dsidev->dev), dsi->pdev); |
archit taneja | affe360 | 2011-02-23 08:41:03 +0000 | [diff] [blame] | 4388 | if (r < 0) { |
| 4389 | DSSERR("request_irq failed\n"); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4390 | goto err_get_irq; |
archit taneja | affe360 | 2011-02-23 08:41:03 +0000 | [diff] [blame] | 4391 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4392 | |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 4393 | /* DSI VCs initialization */ |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4394 | for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) { |
| 4395 | dsi->vc[i].mode = DSI_VC_MODE_L4; |
| 4396 | dsi->vc[i].dssdev = NULL; |
| 4397 | dsi->vc[i].vc_id = 0; |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 4398 | } |
| 4399 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4400 | dsi_calc_clock_param_ranges(dsidev); |
Taneja, Archit | 4964111 | 2011-03-14 23:28:23 -0500 | [diff] [blame] | 4401 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4402 | r = dsi_runtime_get(dsidev); |
| 4403 | if (r) |
| 4404 | goto err_get_dsi; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4405 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4406 | rev = dsi_read_reg(dsidev, DSI_REVISION); |
| 4407 | dev_dbg(&dsidev->dev, "OMAP DSI rev %d.%d\n", |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4408 | FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0)); |
| 4409 | |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 4410 | dsi->num_data_lanes = dsi_get_num_data_lanes(dsidev); |
| 4411 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4412 | dsi_runtime_put(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4413 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4414 | return 0; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4415 | |
| 4416 | err_get_dsi: |
| 4417 | free_irq(dsi->irq, dsi->pdev); |
| 4418 | err_get_irq: |
Archit Taneja | 49dbf58 | 2011-05-16 15:17:07 +0530 | [diff] [blame] | 4419 | iounmap(dsi->base); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4420 | err_ioremap: |
| 4421 | pm_runtime_disable(&dsidev->dev); |
| 4422 | err_get_clk: |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4423 | kfree(dsi); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4424 | err_alloc: |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4425 | return r; |
| 4426 | } |
| 4427 | |
Tomi Valkeinen | 7c68dd9 | 2011-08-03 14:00:57 +0300 | [diff] [blame] | 4428 | static int omap_dsihw_remove(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4429 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4430 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 4431 | |
Tomi Valkeinen | b98482e | 2011-05-16 13:52:51 +0300 | [diff] [blame] | 4432 | WARN_ON(dsi->scp_clk_refcount > 0); |
| 4433 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4434 | pm_runtime_disable(&dsidev->dev); |
| 4435 | |
| 4436 | dsi_put_clocks(dsidev); |
| 4437 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4438 | if (dsi->vdds_dsi_reg != NULL) { |
| 4439 | if (dsi->vdds_dsi_enabled) { |
| 4440 | regulator_disable(dsi->vdds_dsi_reg); |
| 4441 | dsi->vdds_dsi_enabled = false; |
Tomi Valkeinen | 88257b2 | 2010-12-20 16:26:22 +0200 | [diff] [blame] | 4442 | } |
| 4443 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4444 | regulator_put(dsi->vdds_dsi_reg); |
| 4445 | dsi->vdds_dsi_reg = NULL; |
Senthilvadivu Guruswamy | c8aac01 | 2011-01-24 06:22:02 +0000 | [diff] [blame] | 4446 | } |
| 4447 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4448 | free_irq(dsi->irq, dsi->pdev); |
| 4449 | iounmap(dsi->base); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4450 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4451 | kfree(dsi); |
Tomi Valkeinen | 0f16aa0 | 2010-04-12 09:57:19 +0300 | [diff] [blame] | 4452 | |
Senthilvadivu Guruswamy | c8aac01 | 2011-01-24 06:22:02 +0000 | [diff] [blame] | 4453 | return 0; |
| 4454 | } |
| 4455 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4456 | static int dsi_runtime_suspend(struct device *dev) |
| 4457 | { |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4458 | dispc_runtime_put(); |
| 4459 | dss_runtime_put(); |
| 4460 | |
| 4461 | return 0; |
| 4462 | } |
| 4463 | |
| 4464 | static int dsi_runtime_resume(struct device *dev) |
| 4465 | { |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4466 | int r; |
| 4467 | |
| 4468 | r = dss_runtime_get(); |
| 4469 | if (r) |
| 4470 | goto err_get_dss; |
| 4471 | |
| 4472 | r = dispc_runtime_get(); |
| 4473 | if (r) |
| 4474 | goto err_get_dispc; |
| 4475 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4476 | return 0; |
| 4477 | |
| 4478 | err_get_dispc: |
| 4479 | dss_runtime_put(); |
| 4480 | err_get_dss: |
| 4481 | return r; |
| 4482 | } |
| 4483 | |
| 4484 | static const struct dev_pm_ops dsi_pm_ops = { |
| 4485 | .runtime_suspend = dsi_runtime_suspend, |
| 4486 | .runtime_resume = dsi_runtime_resume, |
| 4487 | }; |
| 4488 | |
Tomi Valkeinen | 7c68dd9 | 2011-08-03 14:00:57 +0300 | [diff] [blame] | 4489 | static struct platform_driver omap_dsihw_driver = { |
| 4490 | .probe = omap_dsihw_probe, |
| 4491 | .remove = omap_dsihw_remove, |
Senthilvadivu Guruswamy | c8aac01 | 2011-01-24 06:22:02 +0000 | [diff] [blame] | 4492 | .driver = { |
Tomi Valkeinen | 7c68dd9 | 2011-08-03 14:00:57 +0300 | [diff] [blame] | 4493 | .name = "omapdss_dsi", |
Senthilvadivu Guruswamy | c8aac01 | 2011-01-24 06:22:02 +0000 | [diff] [blame] | 4494 | .owner = THIS_MODULE, |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4495 | .pm = &dsi_pm_ops, |
Senthilvadivu Guruswamy | c8aac01 | 2011-01-24 06:22:02 +0000 | [diff] [blame] | 4496 | }, |
| 4497 | }; |
| 4498 | |
| 4499 | int dsi_init_platform_driver(void) |
| 4500 | { |
Tomi Valkeinen | 7c68dd9 | 2011-08-03 14:00:57 +0300 | [diff] [blame] | 4501 | return platform_driver_register(&omap_dsihw_driver); |
Senthilvadivu Guruswamy | c8aac01 | 2011-01-24 06:22:02 +0000 | [diff] [blame] | 4502 | } |
| 4503 | |
| 4504 | void dsi_uninit_platform_driver(void) |
| 4505 | { |
Tomi Valkeinen | 7c68dd9 | 2011-08-03 14:00:57 +0300 | [diff] [blame] | 4506 | return platform_driver_unregister(&omap_dsihw_driver); |
Senthilvadivu Guruswamy | c8aac01 | 2011-01-24 06:22:02 +0000 | [diff] [blame] | 4507 | } |