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