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> |
Paul Gortmaker | 355b200 | 2011-07-03 16:17:28 -0400 | [diff] [blame] | 30 | #include <linux/module.h> |
Tomi Valkeinen | b9eb5d7 | 2010-01-11 16:33:56 +0200 | [diff] [blame] | 31 | #include <linux/semaphore.h> |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 32 | #include <linux/seq_file.h> |
| 33 | #include <linux/platform_device.h> |
| 34 | #include <linux/regulator/consumer.h> |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 35 | #include <linux/wait.h> |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 36 | #include <linux/workqueue.h> |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 37 | #include <linux/sched.h> |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 38 | #include <linux/slab.h> |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 39 | #include <linux/debugfs.h> |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 40 | #include <linux/pm_runtime.h> |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 41 | |
Tomi Valkeinen | a0b38cc | 2011-05-11 14:05:07 +0300 | [diff] [blame] | 42 | #include <video/omapdss.h> |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 43 | #include <video/mipi_display.h> |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 44 | |
| 45 | #include "dss.h" |
Archit Taneja | 819d807 | 2011-03-01 11:54:00 +0530 | [diff] [blame] | 46 | #include "dss_features.h" |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 47 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 48 | #define DSI_CATCH_MISSING_TE |
| 49 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 50 | struct dsi_reg { u16 idx; }; |
| 51 | |
| 52 | #define DSI_REG(idx) ((const struct dsi_reg) { idx }) |
| 53 | |
| 54 | #define DSI_SZ_REGS SZ_1K |
| 55 | /* DSI Protocol Engine */ |
| 56 | |
| 57 | #define DSI_REVISION DSI_REG(0x0000) |
| 58 | #define DSI_SYSCONFIG DSI_REG(0x0010) |
| 59 | #define DSI_SYSSTATUS DSI_REG(0x0014) |
| 60 | #define DSI_IRQSTATUS DSI_REG(0x0018) |
| 61 | #define DSI_IRQENABLE DSI_REG(0x001C) |
| 62 | #define DSI_CTRL DSI_REG(0x0040) |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 63 | #define DSI_GNQ DSI_REG(0x0044) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 64 | #define DSI_COMPLEXIO_CFG1 DSI_REG(0x0048) |
| 65 | #define DSI_COMPLEXIO_IRQ_STATUS DSI_REG(0x004C) |
| 66 | #define DSI_COMPLEXIO_IRQ_ENABLE DSI_REG(0x0050) |
| 67 | #define DSI_CLK_CTRL DSI_REG(0x0054) |
| 68 | #define DSI_TIMING1 DSI_REG(0x0058) |
| 69 | #define DSI_TIMING2 DSI_REG(0x005C) |
| 70 | #define DSI_VM_TIMING1 DSI_REG(0x0060) |
| 71 | #define DSI_VM_TIMING2 DSI_REG(0x0064) |
| 72 | #define DSI_VM_TIMING3 DSI_REG(0x0068) |
| 73 | #define DSI_CLK_TIMING DSI_REG(0x006C) |
| 74 | #define DSI_TX_FIFO_VC_SIZE DSI_REG(0x0070) |
| 75 | #define DSI_RX_FIFO_VC_SIZE DSI_REG(0x0074) |
| 76 | #define DSI_COMPLEXIO_CFG2 DSI_REG(0x0078) |
| 77 | #define DSI_RX_FIFO_VC_FULLNESS DSI_REG(0x007C) |
| 78 | #define DSI_VM_TIMING4 DSI_REG(0x0080) |
| 79 | #define DSI_TX_FIFO_VC_EMPTINESS DSI_REG(0x0084) |
| 80 | #define DSI_VM_TIMING5 DSI_REG(0x0088) |
| 81 | #define DSI_VM_TIMING6 DSI_REG(0x008C) |
| 82 | #define DSI_VM_TIMING7 DSI_REG(0x0090) |
| 83 | #define DSI_STOPCLK_TIMING DSI_REG(0x0094) |
| 84 | #define DSI_VC_CTRL(n) DSI_REG(0x0100 + (n * 0x20)) |
| 85 | #define DSI_VC_TE(n) DSI_REG(0x0104 + (n * 0x20)) |
| 86 | #define DSI_VC_LONG_PACKET_HEADER(n) DSI_REG(0x0108 + (n * 0x20)) |
| 87 | #define DSI_VC_LONG_PACKET_PAYLOAD(n) DSI_REG(0x010C + (n * 0x20)) |
| 88 | #define DSI_VC_SHORT_PACKET_HEADER(n) DSI_REG(0x0110 + (n * 0x20)) |
| 89 | #define DSI_VC_IRQSTATUS(n) DSI_REG(0x0118 + (n * 0x20)) |
| 90 | #define DSI_VC_IRQENABLE(n) DSI_REG(0x011C + (n * 0x20)) |
| 91 | |
| 92 | /* DSIPHY_SCP */ |
| 93 | |
| 94 | #define DSI_DSIPHY_CFG0 DSI_REG(0x200 + 0x0000) |
| 95 | #define DSI_DSIPHY_CFG1 DSI_REG(0x200 + 0x0004) |
| 96 | #define DSI_DSIPHY_CFG2 DSI_REG(0x200 + 0x0008) |
| 97 | #define DSI_DSIPHY_CFG5 DSI_REG(0x200 + 0x0014) |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 98 | #define DSI_DSIPHY_CFG10 DSI_REG(0x200 + 0x0028) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 99 | |
| 100 | /* DSI_PLL_CTRL_SCP */ |
| 101 | |
| 102 | #define DSI_PLL_CONTROL DSI_REG(0x300 + 0x0000) |
| 103 | #define DSI_PLL_STATUS DSI_REG(0x300 + 0x0004) |
| 104 | #define DSI_PLL_GO DSI_REG(0x300 + 0x0008) |
| 105 | #define DSI_PLL_CONFIGURATION1 DSI_REG(0x300 + 0x000C) |
| 106 | #define DSI_PLL_CONFIGURATION2 DSI_REG(0x300 + 0x0010) |
| 107 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 108 | #define REG_GET(dsidev, idx, start, end) \ |
| 109 | FLD_GET(dsi_read_reg(dsidev, idx), start, end) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 110 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 111 | #define REG_FLD_MOD(dsidev, idx, val, start, end) \ |
| 112 | dsi_write_reg(dsidev, idx, FLD_MOD(dsi_read_reg(dsidev, idx), val, start, end)) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 113 | |
| 114 | /* Global interrupts */ |
| 115 | #define DSI_IRQ_VC0 (1 << 0) |
| 116 | #define DSI_IRQ_VC1 (1 << 1) |
| 117 | #define DSI_IRQ_VC2 (1 << 2) |
| 118 | #define DSI_IRQ_VC3 (1 << 3) |
| 119 | #define DSI_IRQ_WAKEUP (1 << 4) |
| 120 | #define DSI_IRQ_RESYNC (1 << 5) |
| 121 | #define DSI_IRQ_PLL_LOCK (1 << 7) |
| 122 | #define DSI_IRQ_PLL_UNLOCK (1 << 8) |
| 123 | #define DSI_IRQ_PLL_RECALL (1 << 9) |
| 124 | #define DSI_IRQ_COMPLEXIO_ERR (1 << 10) |
| 125 | #define DSI_IRQ_HS_TX_TIMEOUT (1 << 14) |
| 126 | #define DSI_IRQ_LP_RX_TIMEOUT (1 << 15) |
| 127 | #define DSI_IRQ_TE_TRIGGER (1 << 16) |
| 128 | #define DSI_IRQ_ACK_TRIGGER (1 << 17) |
| 129 | #define DSI_IRQ_SYNC_LOST (1 << 18) |
| 130 | #define DSI_IRQ_LDO_POWER_GOOD (1 << 19) |
| 131 | #define DSI_IRQ_TA_TIMEOUT (1 << 20) |
| 132 | #define DSI_IRQ_ERROR_MASK \ |
| 133 | (DSI_IRQ_HS_TX_TIMEOUT | DSI_IRQ_LP_RX_TIMEOUT | DSI_IRQ_SYNC_LOST | \ |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 134 | DSI_IRQ_TA_TIMEOUT | DSI_IRQ_SYNC_LOST) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 135 | #define DSI_IRQ_CHANNEL_MASK 0xf |
| 136 | |
| 137 | /* Virtual channel interrupts */ |
| 138 | #define DSI_VC_IRQ_CS (1 << 0) |
| 139 | #define DSI_VC_IRQ_ECC_CORR (1 << 1) |
| 140 | #define DSI_VC_IRQ_PACKET_SENT (1 << 2) |
| 141 | #define DSI_VC_IRQ_FIFO_TX_OVF (1 << 3) |
| 142 | #define DSI_VC_IRQ_FIFO_RX_OVF (1 << 4) |
| 143 | #define DSI_VC_IRQ_BTA (1 << 5) |
| 144 | #define DSI_VC_IRQ_ECC_NO_CORR (1 << 6) |
| 145 | #define DSI_VC_IRQ_FIFO_TX_UDF (1 << 7) |
| 146 | #define DSI_VC_IRQ_PP_BUSY_CHANGE (1 << 8) |
| 147 | #define DSI_VC_IRQ_ERROR_MASK \ |
| 148 | (DSI_VC_IRQ_CS | DSI_VC_IRQ_ECC_CORR | DSI_VC_IRQ_FIFO_TX_OVF | \ |
| 149 | DSI_VC_IRQ_FIFO_RX_OVF | DSI_VC_IRQ_ECC_NO_CORR | \ |
| 150 | DSI_VC_IRQ_FIFO_TX_UDF) |
| 151 | |
| 152 | /* ComplexIO interrupts */ |
| 153 | #define DSI_CIO_IRQ_ERRSYNCESC1 (1 << 0) |
| 154 | #define DSI_CIO_IRQ_ERRSYNCESC2 (1 << 1) |
| 155 | #define DSI_CIO_IRQ_ERRSYNCESC3 (1 << 2) |
Tomi Valkeinen | 6705615 | 2011-03-24 16:30:17 +0200 | [diff] [blame] | 156 | #define DSI_CIO_IRQ_ERRSYNCESC4 (1 << 3) |
| 157 | #define DSI_CIO_IRQ_ERRSYNCESC5 (1 << 4) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 158 | #define DSI_CIO_IRQ_ERRESC1 (1 << 5) |
| 159 | #define DSI_CIO_IRQ_ERRESC2 (1 << 6) |
| 160 | #define DSI_CIO_IRQ_ERRESC3 (1 << 7) |
Tomi Valkeinen | 6705615 | 2011-03-24 16:30:17 +0200 | [diff] [blame] | 161 | #define DSI_CIO_IRQ_ERRESC4 (1 << 8) |
| 162 | #define DSI_CIO_IRQ_ERRESC5 (1 << 9) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 163 | #define DSI_CIO_IRQ_ERRCONTROL1 (1 << 10) |
| 164 | #define DSI_CIO_IRQ_ERRCONTROL2 (1 << 11) |
| 165 | #define DSI_CIO_IRQ_ERRCONTROL3 (1 << 12) |
Tomi Valkeinen | 6705615 | 2011-03-24 16:30:17 +0200 | [diff] [blame] | 166 | #define DSI_CIO_IRQ_ERRCONTROL4 (1 << 13) |
| 167 | #define DSI_CIO_IRQ_ERRCONTROL5 (1 << 14) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 168 | #define DSI_CIO_IRQ_STATEULPS1 (1 << 15) |
| 169 | #define DSI_CIO_IRQ_STATEULPS2 (1 << 16) |
| 170 | #define DSI_CIO_IRQ_STATEULPS3 (1 << 17) |
Tomi Valkeinen | 6705615 | 2011-03-24 16:30:17 +0200 | [diff] [blame] | 171 | #define DSI_CIO_IRQ_STATEULPS4 (1 << 18) |
| 172 | #define DSI_CIO_IRQ_STATEULPS5 (1 << 19) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 173 | #define DSI_CIO_IRQ_ERRCONTENTIONLP0_1 (1 << 20) |
| 174 | #define DSI_CIO_IRQ_ERRCONTENTIONLP1_1 (1 << 21) |
| 175 | #define DSI_CIO_IRQ_ERRCONTENTIONLP0_2 (1 << 22) |
| 176 | #define DSI_CIO_IRQ_ERRCONTENTIONLP1_2 (1 << 23) |
| 177 | #define DSI_CIO_IRQ_ERRCONTENTIONLP0_3 (1 << 24) |
| 178 | #define DSI_CIO_IRQ_ERRCONTENTIONLP1_3 (1 << 25) |
Tomi Valkeinen | 6705615 | 2011-03-24 16:30:17 +0200 | [diff] [blame] | 179 | #define DSI_CIO_IRQ_ERRCONTENTIONLP0_4 (1 << 26) |
| 180 | #define DSI_CIO_IRQ_ERRCONTENTIONLP1_4 (1 << 27) |
| 181 | #define DSI_CIO_IRQ_ERRCONTENTIONLP0_5 (1 << 28) |
| 182 | #define DSI_CIO_IRQ_ERRCONTENTIONLP1_5 (1 << 29) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 183 | #define DSI_CIO_IRQ_ULPSACTIVENOT_ALL0 (1 << 30) |
| 184 | #define DSI_CIO_IRQ_ULPSACTIVENOT_ALL1 (1 << 31) |
Tomi Valkeinen | bbecb50 | 2010-05-10 14:35:33 +0300 | [diff] [blame] | 185 | #define DSI_CIO_IRQ_ERROR_MASK \ |
| 186 | (DSI_CIO_IRQ_ERRSYNCESC1 | DSI_CIO_IRQ_ERRSYNCESC2 | \ |
Tomi Valkeinen | 6705615 | 2011-03-24 16:30:17 +0200 | [diff] [blame] | 187 | DSI_CIO_IRQ_ERRSYNCESC3 | DSI_CIO_IRQ_ERRSYNCESC4 | \ |
| 188 | DSI_CIO_IRQ_ERRSYNCESC5 | \ |
| 189 | DSI_CIO_IRQ_ERRESC1 | DSI_CIO_IRQ_ERRESC2 | \ |
| 190 | DSI_CIO_IRQ_ERRESC3 | DSI_CIO_IRQ_ERRESC4 | \ |
| 191 | DSI_CIO_IRQ_ERRESC5 | \ |
| 192 | DSI_CIO_IRQ_ERRCONTROL1 | DSI_CIO_IRQ_ERRCONTROL2 | \ |
| 193 | DSI_CIO_IRQ_ERRCONTROL3 | DSI_CIO_IRQ_ERRCONTROL4 | \ |
| 194 | DSI_CIO_IRQ_ERRCONTROL5 | \ |
Tomi Valkeinen | bbecb50 | 2010-05-10 14:35:33 +0300 | [diff] [blame] | 195 | DSI_CIO_IRQ_ERRCONTENTIONLP0_1 | DSI_CIO_IRQ_ERRCONTENTIONLP1_1 | \ |
| 196 | DSI_CIO_IRQ_ERRCONTENTIONLP0_2 | DSI_CIO_IRQ_ERRCONTENTIONLP1_2 | \ |
Tomi Valkeinen | 6705615 | 2011-03-24 16:30:17 +0200 | [diff] [blame] | 197 | DSI_CIO_IRQ_ERRCONTENTIONLP0_3 | DSI_CIO_IRQ_ERRCONTENTIONLP1_3 | \ |
| 198 | DSI_CIO_IRQ_ERRCONTENTIONLP0_4 | DSI_CIO_IRQ_ERRCONTENTIONLP1_4 | \ |
| 199 | DSI_CIO_IRQ_ERRCONTENTIONLP0_5 | DSI_CIO_IRQ_ERRCONTENTIONLP1_5) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 200 | |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 201 | typedef void (*omap_dsi_isr_t) (void *arg, u32 mask); |
| 202 | |
Tomi Valkeinen | b7dec9b | 2013-02-22 12:58:35 +0200 | [diff] [blame] | 203 | static int dsi_display_init_dispc(struct platform_device *dsidev, |
| 204 | struct omap_overlay_manager *mgr); |
| 205 | static void dsi_display_uninit_dispc(struct platform_device *dsidev, |
| 206 | struct omap_overlay_manager *mgr); |
| 207 | |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 208 | #define DSI_MAX_NR_ISRS 2 |
Tomi Valkeinen | 739a7f4 | 2011-10-13 11:22:06 +0300 | [diff] [blame] | 209 | #define DSI_MAX_NR_LANES 5 |
| 210 | |
| 211 | enum dsi_lane_function { |
| 212 | DSI_LANE_UNUSED = 0, |
| 213 | DSI_LANE_CLK, |
| 214 | DSI_LANE_DATA1, |
| 215 | DSI_LANE_DATA2, |
| 216 | DSI_LANE_DATA3, |
| 217 | DSI_LANE_DATA4, |
| 218 | }; |
| 219 | |
| 220 | struct dsi_lane_config { |
| 221 | enum dsi_lane_function function; |
| 222 | u8 polarity; |
| 223 | }; |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 224 | |
| 225 | struct dsi_isr_data { |
| 226 | omap_dsi_isr_t isr; |
| 227 | void *arg; |
| 228 | u32 mask; |
| 229 | }; |
| 230 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 231 | enum fifo_size { |
| 232 | DSI_FIFO_SIZE_0 = 0, |
| 233 | DSI_FIFO_SIZE_32 = 1, |
| 234 | DSI_FIFO_SIZE_64 = 2, |
| 235 | DSI_FIFO_SIZE_96 = 3, |
| 236 | DSI_FIFO_SIZE_128 = 4, |
| 237 | }; |
| 238 | |
Archit Taneja | d604914 | 2011-08-22 11:58:08 +0530 | [diff] [blame] | 239 | enum dsi_vc_source { |
| 240 | DSI_VC_SOURCE_L4 = 0, |
| 241 | DSI_VC_SOURCE_VP, |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 242 | }; |
| 243 | |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 244 | struct dsi_irq_stats { |
| 245 | unsigned long last_reset; |
| 246 | unsigned irq_count; |
| 247 | unsigned dsi_irqs[32]; |
| 248 | unsigned vc_irqs[4][32]; |
| 249 | unsigned cio_irqs[32]; |
| 250 | }; |
| 251 | |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 252 | struct dsi_isr_tables { |
| 253 | struct dsi_isr_data isr_table[DSI_MAX_NR_ISRS]; |
| 254 | struct dsi_isr_data isr_table_vc[4][DSI_MAX_NR_ISRS]; |
| 255 | struct dsi_isr_data isr_table_cio[DSI_MAX_NR_ISRS]; |
| 256 | }; |
| 257 | |
Tomi Valkeinen | f1e0001 | 2013-03-05 17:21:35 +0200 | [diff] [blame] | 258 | struct dsi_clk_calc_ctx { |
| 259 | struct platform_device *dsidev; |
| 260 | |
| 261 | /* inputs */ |
| 262 | |
| 263 | const struct omap_dss_dsi_config *config; |
| 264 | |
| 265 | unsigned long req_pck_min, req_pck_nom, req_pck_max; |
| 266 | |
| 267 | /* outputs */ |
| 268 | |
| 269 | struct dsi_clock_info dsi_cinfo; |
| 270 | struct dispc_clock_info dispc_cinfo; |
| 271 | |
| 272 | struct omap_video_timings dispc_vm; |
| 273 | struct omap_dss_dsi_videomode_timings dsi_vm; |
| 274 | }; |
| 275 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 276 | struct dsi_data { |
Senthilvadivu Guruswamy | c8aac01 | 2011-01-24 06:22:02 +0000 | [diff] [blame] | 277 | struct platform_device *pdev; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 278 | void __iomem *base; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 279 | |
Tomi Valkeinen | 11ee960 | 2012-03-09 16:07:39 +0200 | [diff] [blame] | 280 | int module_id; |
| 281 | |
archit taneja | affe360 | 2011-02-23 08:41:03 +0000 | [diff] [blame] | 282 | int irq; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 283 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 284 | struct clk *dss_clk; |
| 285 | struct clk *sys_clk; |
| 286 | |
Tomi Valkeinen | a0d269e | 2012-11-27 17:05:54 +0200 | [diff] [blame] | 287 | struct dispc_clock_info user_dispc_cinfo; |
| 288 | struct dsi_clock_info user_dsi_cinfo; |
| 289 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 290 | struct dsi_clock_info current_cinfo; |
| 291 | |
Tomi Valkeinen | 2a89dc1 | 2010-07-30 12:39:34 +0300 | [diff] [blame] | 292 | bool vdds_dsi_enabled; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 293 | struct regulator *vdds_dsi_reg; |
| 294 | |
| 295 | struct { |
Archit Taneja | d604914 | 2011-08-22 11:58:08 +0530 | [diff] [blame] | 296 | enum dsi_vc_source source; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 297 | struct omap_dss_device *dssdev; |
| 298 | enum fifo_size fifo_size; |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 299 | int vc_id; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 300 | } vc[4]; |
| 301 | |
| 302 | struct mutex lock; |
Tomi Valkeinen | b9eb5d7 | 2010-01-11 16:33:56 +0200 | [diff] [blame] | 303 | struct semaphore bus_lock; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 304 | |
| 305 | unsigned pll_locked; |
| 306 | |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 307 | spinlock_t irq_lock; |
| 308 | struct dsi_isr_tables isr_tables; |
| 309 | /* space for a copy used by the interrupt handler */ |
| 310 | struct dsi_isr_tables isr_tables_copy; |
| 311 | |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 312 | int update_channel; |
Tomi Valkeinen | 5476e74 | 2011-11-03 16:34:20 +0200 | [diff] [blame] | 313 | #ifdef DEBUG |
| 314 | unsigned update_bytes; |
| 315 | #endif |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 316 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 317 | bool te_enabled; |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 318 | bool ulps_enabled; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 319 | |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 320 | void (*framedone_callback)(int, void *); |
| 321 | void *framedone_data; |
| 322 | |
| 323 | struct delayed_work framedone_timeout_work; |
| 324 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 325 | #ifdef DSI_CATCH_MISSING_TE |
| 326 | struct timer_list te_timer; |
| 327 | #endif |
| 328 | |
| 329 | unsigned long cache_req_pck; |
| 330 | unsigned long cache_clk_freq; |
| 331 | struct dsi_clock_info cache_cinfo; |
| 332 | |
| 333 | u32 errors; |
| 334 | spinlock_t errors_lock; |
| 335 | #ifdef DEBUG |
| 336 | ktime_t perf_setup_time; |
| 337 | ktime_t perf_start_time; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 338 | #endif |
| 339 | int debug_read; |
| 340 | int debug_write; |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 341 | |
| 342 | #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS |
| 343 | spinlock_t irq_stats_lock; |
| 344 | struct dsi_irq_stats irq_stats; |
| 345 | #endif |
Taneja, Archit | 4964111 | 2011-03-14 23:28:23 -0500 | [diff] [blame] | 346 | /* DSI PLL Parameter Ranges */ |
| 347 | unsigned long regm_max, regn_max; |
| 348 | unsigned long regm_dispc_max, regm_dsi_max; |
| 349 | unsigned long fint_min, fint_max; |
| 350 | unsigned long lpdiv_max; |
Tomi Valkeinen | 24c1ae4 | 2011-04-13 17:12:52 +0300 | [diff] [blame] | 351 | |
Tomi Valkeinen | d982085 | 2011-10-12 15:05:59 +0300 | [diff] [blame] | 352 | unsigned num_lanes_supported; |
Tomi Valkeinen | 9932257 | 2013-03-05 10:37:02 +0200 | [diff] [blame] | 353 | unsigned line_buffer_size; |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 354 | |
Tomi Valkeinen | 739a7f4 | 2011-10-13 11:22:06 +0300 | [diff] [blame] | 355 | struct dsi_lane_config lanes[DSI_MAX_NR_LANES]; |
| 356 | unsigned num_lanes_used; |
Tomi Valkeinen | 24c1ae4 | 2011-04-13 17:12:52 +0300 | [diff] [blame] | 357 | |
| 358 | unsigned scp_clk_refcount; |
Archit Taneja | 7d2572f | 2012-06-29 14:31:07 +0530 | [diff] [blame] | 359 | |
| 360 | struct dss_lcd_mgr_config mgr_config; |
Archit Taneja | e67458a | 2012-08-13 14:17:30 +0530 | [diff] [blame] | 361 | struct omap_video_timings timings; |
Archit Taneja | 02c3960 | 2012-08-10 15:01:33 +0530 | [diff] [blame] | 362 | enum omap_dss_dsi_pixel_format pix_fmt; |
Archit Taneja | dca2b15 | 2012-08-16 18:02:00 +0530 | [diff] [blame] | 363 | enum omap_dss_dsi_mode mode; |
Archit Taneja | 0b3ffe3 | 2012-08-13 22:13:39 +0530 | [diff] [blame] | 364 | struct omap_dss_dsi_videomode_timings vm_timings; |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 365 | |
Tomi Valkeinen | 1f68d9c | 2013-04-19 15:09:34 +0300 | [diff] [blame] | 366 | struct omap_dss_device output; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 367 | }; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 368 | |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 369 | struct dsi_packet_sent_handler_data { |
| 370 | struct platform_device *dsidev; |
| 371 | struct completion *completion; |
| 372 | }; |
| 373 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 374 | #ifdef DEBUG |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 375 | static bool dsi_perf; |
| 376 | module_param(dsi_perf, bool, 0644); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 377 | #endif |
| 378 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 379 | static inline struct dsi_data *dsi_get_dsidrv_data(struct platform_device *dsidev) |
| 380 | { |
| 381 | return dev_get_drvdata(&dsidev->dev); |
| 382 | } |
| 383 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 384 | static inline struct platform_device *dsi_get_dsidev_from_dssdev(struct omap_dss_device *dssdev) |
| 385 | { |
Tomi Valkeinen | deb16df | 2013-05-24 13:20:27 +0300 | [diff] [blame^] | 386 | /* HACK: dssdev can be either the panel device, when using old API, or |
| 387 | * the dsi device itself, when using the new API. So we solve this for |
| 388 | * now by checking the dssdev->id. This will be removed when the old API |
| 389 | * is removed. |
| 390 | */ |
| 391 | if (dssdev->id == OMAP_DSS_OUTPUT_DSI1 || |
| 392 | dssdev->id == OMAP_DSS_OUTPUT_DSI2) |
| 393 | return to_platform_device(dssdev->dev); |
| 394 | |
Tomi Valkeinen | 1f68d9c | 2013-04-19 15:09:34 +0300 | [diff] [blame] | 395 | return to_platform_device(dssdev->output->dev); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | struct platform_device *dsi_get_dsidev_from_id(int module) |
| 399 | { |
Tomi Valkeinen | 1f68d9c | 2013-04-19 15:09:34 +0300 | [diff] [blame] | 400 | struct omap_dss_device *out; |
Archit Taneja | 400e65d | 2012-07-04 13:48:34 +0530 | [diff] [blame] | 401 | enum omap_dss_output_id id; |
| 402 | |
Tomi Valkeinen | 78e7f25 | 2012-10-15 12:48:11 +0300 | [diff] [blame] | 403 | switch (module) { |
| 404 | case 0: |
| 405 | id = OMAP_DSS_OUTPUT_DSI1; |
| 406 | break; |
| 407 | case 1: |
| 408 | id = OMAP_DSS_OUTPUT_DSI2; |
| 409 | break; |
| 410 | default: |
| 411 | return NULL; |
| 412 | } |
Archit Taneja | 400e65d | 2012-07-04 13:48:34 +0530 | [diff] [blame] | 413 | |
| 414 | out = omap_dss_get_output(id); |
| 415 | |
Tomi Valkeinen | 1f68d9c | 2013-04-19 15:09:34 +0300 | [diff] [blame] | 416 | return out ? to_platform_device(out->dev) : NULL; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | static inline void dsi_write_reg(struct platform_device *dsidev, |
| 420 | const struct dsi_reg idx, u32 val) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 421 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 422 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 423 | |
| 424 | __raw_writel(val, dsi->base + idx.idx); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 425 | } |
| 426 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 427 | static inline u32 dsi_read_reg(struct platform_device *dsidev, |
| 428 | const struct dsi_reg idx) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 429 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 430 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 431 | |
| 432 | return __raw_readl(dsi->base + idx.idx); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 433 | } |
| 434 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 435 | void dsi_bus_lock(struct omap_dss_device *dssdev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 436 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 437 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 438 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 439 | |
| 440 | down(&dsi->bus_lock); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 441 | } |
| 442 | EXPORT_SYMBOL(dsi_bus_lock); |
| 443 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 444 | void dsi_bus_unlock(struct omap_dss_device *dssdev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 445 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 446 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 447 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 448 | |
| 449 | up(&dsi->bus_lock); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 450 | } |
| 451 | EXPORT_SYMBOL(dsi_bus_unlock); |
| 452 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 453 | static bool dsi_bus_is_locked(struct platform_device *dsidev) |
Tomi Valkeinen | 4f76502 | 2010-01-18 16:27:52 +0200 | [diff] [blame] | 454 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 455 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 456 | |
| 457 | return dsi->bus_lock.count == 0; |
Tomi Valkeinen | 4f76502 | 2010-01-18 16:27:52 +0200 | [diff] [blame] | 458 | } |
| 459 | |
Tomi Valkeinen | f36a06e | 2011-03-02 14:48:41 +0200 | [diff] [blame] | 460 | static void dsi_completion_handler(void *data, u32 mask) |
| 461 | { |
| 462 | complete((struct completion *)data); |
| 463 | } |
| 464 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 465 | static inline int wait_for_bit_change(struct platform_device *dsidev, |
| 466 | const struct dsi_reg idx, int bitnum, int value) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 467 | { |
Tomi Valkeinen | 3b98409 | 2011-10-13 19:06:49 +0300 | [diff] [blame] | 468 | unsigned long timeout; |
| 469 | ktime_t wait; |
| 470 | int t; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 471 | |
Tomi Valkeinen | 3b98409 | 2011-10-13 19:06:49 +0300 | [diff] [blame] | 472 | /* first busyloop to see if the bit changes right away */ |
| 473 | t = 100; |
| 474 | while (t-- > 0) { |
| 475 | if (REG_GET(dsidev, idx, bitnum, bitnum) == value) |
| 476 | return value; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 477 | } |
| 478 | |
Tomi Valkeinen | 3b98409 | 2011-10-13 19:06:49 +0300 | [diff] [blame] | 479 | /* then loop for 500ms, sleeping for 1ms in between */ |
| 480 | timeout = jiffies + msecs_to_jiffies(500); |
| 481 | while (time_before(jiffies, timeout)) { |
| 482 | if (REG_GET(dsidev, idx, bitnum, bitnum) == value) |
| 483 | return value; |
| 484 | |
| 485 | wait = ns_to_ktime(1000 * 1000); |
| 486 | set_current_state(TASK_UNINTERRUPTIBLE); |
| 487 | schedule_hrtimeout(&wait, HRTIMER_MODE_REL); |
| 488 | } |
| 489 | |
| 490 | return !value; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 491 | } |
| 492 | |
Archit Taneja | a3b3cc2 | 2011-09-08 18:42:16 +0530 | [diff] [blame] | 493 | u8 dsi_get_pixel_size(enum omap_dss_dsi_pixel_format fmt) |
| 494 | { |
| 495 | switch (fmt) { |
| 496 | case OMAP_DSS_DSI_FMT_RGB888: |
| 497 | case OMAP_DSS_DSI_FMT_RGB666: |
| 498 | return 24; |
| 499 | case OMAP_DSS_DSI_FMT_RGB666_PACKED: |
| 500 | return 18; |
| 501 | case OMAP_DSS_DSI_FMT_RGB565: |
| 502 | return 16; |
| 503 | default: |
| 504 | BUG(); |
Tomi Valkeinen | c6eee96 | 2012-05-18 11:47:02 +0300 | [diff] [blame] | 505 | return 0; |
Archit Taneja | a3b3cc2 | 2011-09-08 18:42:16 +0530 | [diff] [blame] | 506 | } |
| 507 | } |
| 508 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 509 | #ifdef DEBUG |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 510 | static void dsi_perf_mark_setup(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 511 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 512 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 513 | dsi->perf_setup_time = ktime_get(); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 514 | } |
| 515 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 516 | static void dsi_perf_mark_start(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 517 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 518 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 519 | dsi->perf_start_time = ktime_get(); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 520 | } |
| 521 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 522 | static void dsi_perf_show(struct platform_device *dsidev, const char *name) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 523 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 524 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 525 | ktime_t t, setup_time, trans_time; |
| 526 | u32 total_bytes; |
| 527 | u32 setup_us, trans_us, total_us; |
| 528 | |
| 529 | if (!dsi_perf) |
| 530 | return; |
| 531 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 532 | t = ktime_get(); |
| 533 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 534 | setup_time = ktime_sub(dsi->perf_start_time, dsi->perf_setup_time); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 535 | setup_us = (u32)ktime_to_us(setup_time); |
| 536 | if (setup_us == 0) |
| 537 | setup_us = 1; |
| 538 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 539 | trans_time = ktime_sub(t, dsi->perf_start_time); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 540 | trans_us = (u32)ktime_to_us(trans_time); |
| 541 | if (trans_us == 0) |
| 542 | trans_us = 1; |
| 543 | |
| 544 | total_us = setup_us + trans_us; |
| 545 | |
Tomi Valkeinen | 5476e74 | 2011-11-03 16:34:20 +0200 | [diff] [blame] | 546 | total_bytes = dsi->update_bytes; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 547 | |
Tomi Valkeinen | 1bbb275 | 2010-01-11 16:41:10 +0200 | [diff] [blame] | 548 | printk(KERN_INFO "DSI(%s): %u us + %u us = %u us (%uHz), " |
| 549 | "%u bytes, %u kbytes/sec\n", |
| 550 | name, |
| 551 | setup_us, |
| 552 | trans_us, |
| 553 | total_us, |
| 554 | 1000*1000 / total_us, |
| 555 | total_bytes, |
| 556 | total_bytes * 1000 / total_us); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 557 | } |
| 558 | #else |
Tomi Valkeinen | 4a9a5e3 | 2011-05-23 16:36:09 +0300 | [diff] [blame] | 559 | static inline void dsi_perf_mark_setup(struct platform_device *dsidev) |
| 560 | { |
| 561 | } |
| 562 | |
| 563 | static inline void dsi_perf_mark_start(struct platform_device *dsidev) |
| 564 | { |
| 565 | } |
| 566 | |
| 567 | static inline void dsi_perf_show(struct platform_device *dsidev, |
| 568 | const char *name) |
| 569 | { |
| 570 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 571 | #endif |
| 572 | |
Chandrabhanu Mahapatra | f30be7d | 2012-09-29 12:33:05 +0530 | [diff] [blame] | 573 | static int verbose_irq; |
| 574 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 575 | static void print_irq_status(u32 status) |
| 576 | { |
Tomi Valkeinen | d80d499 | 2011-03-02 15:53:07 +0200 | [diff] [blame] | 577 | if (status == 0) |
| 578 | return; |
| 579 | |
Chandrabhanu Mahapatra | f30be7d | 2012-09-29 12:33:05 +0530 | [diff] [blame] | 580 | if (!verbose_irq && (status & ~DSI_IRQ_CHANNEL_MASK) == 0) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 581 | return; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 582 | |
Chandrabhanu Mahapatra | f30be7d | 2012-09-29 12:33:05 +0530 | [diff] [blame] | 583 | #define PIS(x) (status & DSI_IRQ_##x) ? (#x " ") : "" |
| 584 | |
| 585 | pr_debug("DSI IRQ: 0x%x: %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", |
| 586 | status, |
| 587 | verbose_irq ? PIS(VC0) : "", |
| 588 | verbose_irq ? PIS(VC1) : "", |
| 589 | verbose_irq ? PIS(VC2) : "", |
| 590 | verbose_irq ? PIS(VC3) : "", |
| 591 | PIS(WAKEUP), |
| 592 | PIS(RESYNC), |
| 593 | PIS(PLL_LOCK), |
| 594 | PIS(PLL_UNLOCK), |
| 595 | PIS(PLL_RECALL), |
| 596 | PIS(COMPLEXIO_ERR), |
| 597 | PIS(HS_TX_TIMEOUT), |
| 598 | PIS(LP_RX_TIMEOUT), |
| 599 | PIS(TE_TRIGGER), |
| 600 | PIS(ACK_TRIGGER), |
| 601 | PIS(SYNC_LOST), |
| 602 | PIS(LDO_POWER_GOOD), |
| 603 | PIS(TA_TIMEOUT)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 604 | #undef PIS |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | static void print_irq_status_vc(int channel, u32 status) |
| 608 | { |
Tomi Valkeinen | d80d499 | 2011-03-02 15:53:07 +0200 | [diff] [blame] | 609 | if (status == 0) |
| 610 | return; |
| 611 | |
Chandrabhanu Mahapatra | f30be7d | 2012-09-29 12:33:05 +0530 | [diff] [blame] | 612 | if (!verbose_irq && (status & ~DSI_VC_IRQ_PACKET_SENT) == 0) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 613 | return; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 614 | |
Chandrabhanu Mahapatra | f30be7d | 2012-09-29 12:33:05 +0530 | [diff] [blame] | 615 | #define PIS(x) (status & DSI_VC_IRQ_##x) ? (#x " ") : "" |
| 616 | |
| 617 | pr_debug("DSI VC(%d) IRQ 0x%x: %s%s%s%s%s%s%s%s%s\n", |
| 618 | channel, |
| 619 | status, |
| 620 | PIS(CS), |
| 621 | PIS(ECC_CORR), |
| 622 | PIS(ECC_NO_CORR), |
| 623 | verbose_irq ? PIS(PACKET_SENT) : "", |
| 624 | PIS(BTA), |
| 625 | PIS(FIFO_TX_OVF), |
| 626 | PIS(FIFO_RX_OVF), |
| 627 | PIS(FIFO_TX_UDF), |
| 628 | PIS(PP_BUSY_CHANGE)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 629 | #undef PIS |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | static void print_irq_status_cio(u32 status) |
| 633 | { |
Tomi Valkeinen | d80d499 | 2011-03-02 15:53:07 +0200 | [diff] [blame] | 634 | if (status == 0) |
| 635 | return; |
| 636 | |
Chandrabhanu Mahapatra | f30be7d | 2012-09-29 12:33:05 +0530 | [diff] [blame] | 637 | #define PIS(x) (status & DSI_CIO_IRQ_##x) ? (#x " ") : "" |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 638 | |
Chandrabhanu Mahapatra | f30be7d | 2012-09-29 12:33:05 +0530 | [diff] [blame] | 639 | pr_debug("DSI CIO IRQ 0x%x: %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", |
| 640 | status, |
| 641 | PIS(ERRSYNCESC1), |
| 642 | PIS(ERRSYNCESC2), |
| 643 | PIS(ERRSYNCESC3), |
| 644 | PIS(ERRESC1), |
| 645 | PIS(ERRESC2), |
| 646 | PIS(ERRESC3), |
| 647 | PIS(ERRCONTROL1), |
| 648 | PIS(ERRCONTROL2), |
| 649 | PIS(ERRCONTROL3), |
| 650 | PIS(STATEULPS1), |
| 651 | PIS(STATEULPS2), |
| 652 | PIS(STATEULPS3), |
| 653 | PIS(ERRCONTENTIONLP0_1), |
| 654 | PIS(ERRCONTENTIONLP1_1), |
| 655 | PIS(ERRCONTENTIONLP0_2), |
| 656 | PIS(ERRCONTENTIONLP1_2), |
| 657 | PIS(ERRCONTENTIONLP0_3), |
| 658 | PIS(ERRCONTENTIONLP1_3), |
| 659 | PIS(ULPSACTIVENOT_ALL0), |
| 660 | PIS(ULPSACTIVENOT_ALL1)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 661 | #undef PIS |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 662 | } |
| 663 | |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 664 | #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 665 | static void dsi_collect_irq_stats(struct platform_device *dsidev, u32 irqstatus, |
| 666 | u32 *vcstatus, u32 ciostatus) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 667 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 668 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 669 | int i; |
| 670 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 671 | spin_lock(&dsi->irq_stats_lock); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 672 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 673 | dsi->irq_stats.irq_count++; |
| 674 | dss_collect_irq_stats(irqstatus, dsi->irq_stats.dsi_irqs); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 675 | |
| 676 | for (i = 0; i < 4; ++i) |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 677 | dss_collect_irq_stats(vcstatus[i], dsi->irq_stats.vc_irqs[i]); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 678 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 679 | dss_collect_irq_stats(ciostatus, dsi->irq_stats.cio_irqs); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 680 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 681 | spin_unlock(&dsi->irq_stats_lock); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 682 | } |
| 683 | #else |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 684 | #define dsi_collect_irq_stats(dsidev, irqstatus, vcstatus, ciostatus) |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 685 | #endif |
| 686 | |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 687 | static int debug_irq; |
| 688 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 689 | static void dsi_handle_irq_errors(struct platform_device *dsidev, u32 irqstatus, |
| 690 | u32 *vcstatus, u32 ciostatus) |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 691 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 692 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 693 | int i; |
| 694 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 695 | if (irqstatus & DSI_IRQ_ERROR_MASK) { |
| 696 | DSSERR("DSI error, irqstatus %x\n", irqstatus); |
| 697 | print_irq_status(irqstatus); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 698 | spin_lock(&dsi->errors_lock); |
| 699 | dsi->errors |= irqstatus & DSI_IRQ_ERROR_MASK; |
| 700 | spin_unlock(&dsi->errors_lock); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 701 | } else if (debug_irq) { |
| 702 | print_irq_status(irqstatus); |
| 703 | } |
| 704 | |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 705 | for (i = 0; i < 4; ++i) { |
| 706 | if (vcstatus[i] & DSI_VC_IRQ_ERROR_MASK) { |
| 707 | DSSERR("DSI VC(%d) error, vc irqstatus %x\n", |
| 708 | i, vcstatus[i]); |
| 709 | print_irq_status_vc(i, vcstatus[i]); |
| 710 | } else if (debug_irq) { |
| 711 | print_irq_status_vc(i, vcstatus[i]); |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | if (ciostatus & DSI_CIO_IRQ_ERROR_MASK) { |
| 716 | DSSERR("DSI CIO error, cio irqstatus %x\n", ciostatus); |
| 717 | print_irq_status_cio(ciostatus); |
| 718 | } else if (debug_irq) { |
| 719 | print_irq_status_cio(ciostatus); |
| 720 | } |
| 721 | } |
| 722 | |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 723 | static void dsi_call_isrs(struct dsi_isr_data *isr_array, |
| 724 | unsigned isr_array_size, u32 irqstatus) |
| 725 | { |
| 726 | struct dsi_isr_data *isr_data; |
| 727 | int i; |
| 728 | |
| 729 | for (i = 0; i < isr_array_size; i++) { |
| 730 | isr_data = &isr_array[i]; |
| 731 | if (isr_data->isr && isr_data->mask & irqstatus) |
| 732 | isr_data->isr(isr_data->arg, irqstatus); |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | static void dsi_handle_isrs(struct dsi_isr_tables *isr_tables, |
| 737 | u32 irqstatus, u32 *vcstatus, u32 ciostatus) |
| 738 | { |
| 739 | int i; |
| 740 | |
| 741 | dsi_call_isrs(isr_tables->isr_table, |
| 742 | ARRAY_SIZE(isr_tables->isr_table), |
| 743 | irqstatus); |
| 744 | |
| 745 | for (i = 0; i < 4; ++i) { |
| 746 | if (vcstatus[i] == 0) |
| 747 | continue; |
| 748 | dsi_call_isrs(isr_tables->isr_table_vc[i], |
| 749 | ARRAY_SIZE(isr_tables->isr_table_vc[i]), |
| 750 | vcstatus[i]); |
| 751 | } |
| 752 | |
| 753 | if (ciostatus != 0) |
| 754 | dsi_call_isrs(isr_tables->isr_table_cio, |
| 755 | ARRAY_SIZE(isr_tables->isr_table_cio), |
| 756 | ciostatus); |
| 757 | } |
| 758 | |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 759 | static irqreturn_t omap_dsi_irq_handler(int irq, void *arg) |
| 760 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 761 | struct platform_device *dsidev; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 762 | struct dsi_data *dsi; |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 763 | u32 irqstatus, vcstatus[4], ciostatus; |
| 764 | int i; |
| 765 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 766 | dsidev = (struct platform_device *) arg; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 767 | dsi = dsi_get_dsidrv_data(dsidev); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 768 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 769 | spin_lock(&dsi->irq_lock); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 770 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 771 | irqstatus = dsi_read_reg(dsidev, DSI_IRQSTATUS); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 772 | |
| 773 | /* IRQ is not for us */ |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 774 | if (!irqstatus) { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 775 | spin_unlock(&dsi->irq_lock); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 776 | return IRQ_NONE; |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 777 | } |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 778 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 779 | dsi_write_reg(dsidev, DSI_IRQSTATUS, irqstatus & ~DSI_IRQ_CHANNEL_MASK); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 780 | /* flush posted write */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 781 | dsi_read_reg(dsidev, DSI_IRQSTATUS); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 782 | |
| 783 | for (i = 0; i < 4; ++i) { |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 784 | if ((irqstatus & (1 << i)) == 0) { |
| 785 | vcstatus[i] = 0; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 786 | continue; |
Tomi Valkeinen | ab83b14 | 2010-06-09 15:31:01 +0300 | [diff] [blame] | 787 | } |
| 788 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 789 | vcstatus[i] = dsi_read_reg(dsidev, DSI_VC_IRQSTATUS(i)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 790 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 791 | dsi_write_reg(dsidev, DSI_VC_IRQSTATUS(i), vcstatus[i]); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 792 | /* flush posted write */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 793 | dsi_read_reg(dsidev, DSI_VC_IRQSTATUS(i)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | if (irqstatus & DSI_IRQ_COMPLEXIO_ERR) { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 797 | ciostatus = dsi_read_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 798 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 799 | dsi_write_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS, ciostatus); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 800 | /* flush posted write */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 801 | dsi_read_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 802 | } else { |
| 803 | ciostatus = 0; |
| 804 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 805 | |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 806 | #ifdef DSI_CATCH_MISSING_TE |
| 807 | if (irqstatus & DSI_IRQ_TE_TRIGGER) |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 808 | del_timer(&dsi->te_timer); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 809 | #endif |
| 810 | |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 811 | /* make a copy and unlock, so that isrs can unregister |
| 812 | * themselves */ |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 813 | memcpy(&dsi->isr_tables_copy, &dsi->isr_tables, |
| 814 | sizeof(dsi->isr_tables)); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 815 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 816 | spin_unlock(&dsi->irq_lock); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 817 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 818 | dsi_handle_isrs(&dsi->isr_tables_copy, irqstatus, vcstatus, ciostatus); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 819 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 820 | dsi_handle_irq_errors(dsidev, irqstatus, vcstatus, ciostatus); |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 821 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 822 | dsi_collect_irq_stats(dsidev, irqstatus, vcstatus, ciostatus); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 823 | |
archit taneja | affe360 | 2011-02-23 08:41:03 +0000 | [diff] [blame] | 824 | return IRQ_HANDLED; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 825 | } |
| 826 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 827 | /* dsi->irq_lock has to be locked by the caller */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 828 | static void _omap_dsi_configure_irqs(struct platform_device *dsidev, |
| 829 | struct dsi_isr_data *isr_array, |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 830 | unsigned isr_array_size, u32 default_mask, |
| 831 | const struct dsi_reg enable_reg, |
| 832 | const struct dsi_reg status_reg) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 833 | { |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 834 | struct dsi_isr_data *isr_data; |
| 835 | u32 mask; |
| 836 | u32 old_mask; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 837 | int i; |
| 838 | |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 839 | mask = default_mask; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 840 | |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 841 | for (i = 0; i < isr_array_size; i++) { |
| 842 | isr_data = &isr_array[i]; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 843 | |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 844 | if (isr_data->isr == NULL) |
| 845 | continue; |
| 846 | |
| 847 | mask |= isr_data->mask; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 848 | } |
| 849 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 850 | old_mask = dsi_read_reg(dsidev, enable_reg); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 851 | /* clear the irqstatus for newly enabled irqs */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 852 | dsi_write_reg(dsidev, status_reg, (mask ^ old_mask) & mask); |
| 853 | dsi_write_reg(dsidev, enable_reg, mask); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 854 | |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 855 | /* flush posted writes */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 856 | dsi_read_reg(dsidev, enable_reg); |
| 857 | dsi_read_reg(dsidev, status_reg); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 858 | } |
| 859 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 860 | /* dsi->irq_lock has to be locked by the caller */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 861 | static void _omap_dsi_set_irqs(struct platform_device *dsidev) |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 862 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 863 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 864 | u32 mask = DSI_IRQ_ERROR_MASK; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 865 | #ifdef DSI_CATCH_MISSING_TE |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 866 | mask |= DSI_IRQ_TE_TRIGGER; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 867 | #endif |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 868 | _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table, |
| 869 | ARRAY_SIZE(dsi->isr_tables.isr_table), mask, |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 870 | DSI_IRQENABLE, DSI_IRQSTATUS); |
| 871 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 872 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 873 | /* dsi->irq_lock has to be locked by the caller */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 874 | static void _omap_dsi_set_irqs_vc(struct platform_device *dsidev, int vc) |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 875 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 876 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 877 | |
| 878 | _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table_vc[vc], |
| 879 | ARRAY_SIZE(dsi->isr_tables.isr_table_vc[vc]), |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 880 | DSI_VC_IRQ_ERROR_MASK, |
| 881 | DSI_VC_IRQENABLE(vc), DSI_VC_IRQSTATUS(vc)); |
| 882 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 883 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 884 | /* dsi->irq_lock has to be locked by the caller */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 885 | static void _omap_dsi_set_irqs_cio(struct platform_device *dsidev) |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 886 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 887 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 888 | |
| 889 | _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table_cio, |
| 890 | ARRAY_SIZE(dsi->isr_tables.isr_table_cio), |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 891 | DSI_CIO_IRQ_ERROR_MASK, |
| 892 | DSI_COMPLEXIO_IRQ_ENABLE, DSI_COMPLEXIO_IRQ_STATUS); |
| 893 | } |
| 894 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 895 | static void _dsi_initialize_irq(struct platform_device *dsidev) |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 896 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 897 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 898 | unsigned long flags; |
| 899 | int vc; |
| 900 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 901 | spin_lock_irqsave(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 902 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 903 | memset(&dsi->isr_tables, 0, sizeof(dsi->isr_tables)); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 904 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 905 | _omap_dsi_set_irqs(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 906 | for (vc = 0; vc < 4; ++vc) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 907 | _omap_dsi_set_irqs_vc(dsidev, vc); |
| 908 | _omap_dsi_set_irqs_cio(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 909 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 910 | spin_unlock_irqrestore(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | static int _dsi_register_isr(omap_dsi_isr_t isr, void *arg, u32 mask, |
| 914 | struct dsi_isr_data *isr_array, unsigned isr_array_size) |
| 915 | { |
| 916 | struct dsi_isr_data *isr_data; |
| 917 | int free_idx; |
| 918 | int i; |
| 919 | |
| 920 | BUG_ON(isr == NULL); |
| 921 | |
| 922 | /* check for duplicate entry and find a free slot */ |
| 923 | free_idx = -1; |
| 924 | for (i = 0; i < isr_array_size; i++) { |
| 925 | isr_data = &isr_array[i]; |
| 926 | |
| 927 | if (isr_data->isr == isr && isr_data->arg == arg && |
| 928 | isr_data->mask == mask) { |
| 929 | return -EINVAL; |
| 930 | } |
| 931 | |
| 932 | if (isr_data->isr == NULL && free_idx == -1) |
| 933 | free_idx = i; |
| 934 | } |
| 935 | |
| 936 | if (free_idx == -1) |
| 937 | return -EBUSY; |
| 938 | |
| 939 | isr_data = &isr_array[free_idx]; |
| 940 | isr_data->isr = isr; |
| 941 | isr_data->arg = arg; |
| 942 | isr_data->mask = mask; |
| 943 | |
| 944 | return 0; |
| 945 | } |
| 946 | |
| 947 | static int _dsi_unregister_isr(omap_dsi_isr_t isr, void *arg, u32 mask, |
| 948 | struct dsi_isr_data *isr_array, unsigned isr_array_size) |
| 949 | { |
| 950 | struct dsi_isr_data *isr_data; |
| 951 | int i; |
| 952 | |
| 953 | for (i = 0; i < isr_array_size; i++) { |
| 954 | isr_data = &isr_array[i]; |
| 955 | if (isr_data->isr != isr || isr_data->arg != arg || |
| 956 | isr_data->mask != mask) |
| 957 | continue; |
| 958 | |
| 959 | isr_data->isr = NULL; |
| 960 | isr_data->arg = NULL; |
| 961 | isr_data->mask = 0; |
| 962 | |
| 963 | return 0; |
| 964 | } |
| 965 | |
| 966 | return -EINVAL; |
| 967 | } |
| 968 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 969 | static int dsi_register_isr(struct platform_device *dsidev, omap_dsi_isr_t isr, |
| 970 | void *arg, u32 mask) |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 971 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 972 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 973 | unsigned long flags; |
| 974 | int r; |
| 975 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 976 | spin_lock_irqsave(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 977 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 978 | r = _dsi_register_isr(isr, arg, mask, dsi->isr_tables.isr_table, |
| 979 | ARRAY_SIZE(dsi->isr_tables.isr_table)); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 980 | |
| 981 | if (r == 0) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 982 | _omap_dsi_set_irqs(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 983 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 984 | spin_unlock_irqrestore(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 985 | |
| 986 | return r; |
| 987 | } |
| 988 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 989 | static int dsi_unregister_isr(struct platform_device *dsidev, |
| 990 | omap_dsi_isr_t isr, void *arg, u32 mask) |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 991 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 992 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 993 | unsigned long flags; |
| 994 | int r; |
| 995 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 996 | spin_lock_irqsave(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 997 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 998 | r = _dsi_unregister_isr(isr, arg, mask, dsi->isr_tables.isr_table, |
| 999 | ARRAY_SIZE(dsi->isr_tables.isr_table)); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1000 | |
| 1001 | if (r == 0) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1002 | _omap_dsi_set_irqs(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1003 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1004 | spin_unlock_irqrestore(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1005 | |
| 1006 | return r; |
| 1007 | } |
| 1008 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1009 | static int dsi_register_isr_vc(struct platform_device *dsidev, int channel, |
| 1010 | omap_dsi_isr_t isr, void *arg, u32 mask) |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1011 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1012 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1013 | unsigned long flags; |
| 1014 | int r; |
| 1015 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1016 | spin_lock_irqsave(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1017 | |
| 1018 | r = _dsi_register_isr(isr, arg, mask, |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1019 | dsi->isr_tables.isr_table_vc[channel], |
| 1020 | ARRAY_SIZE(dsi->isr_tables.isr_table_vc[channel])); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1021 | |
| 1022 | if (r == 0) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1023 | _omap_dsi_set_irqs_vc(dsidev, channel); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1024 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1025 | spin_unlock_irqrestore(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1026 | |
| 1027 | return r; |
| 1028 | } |
| 1029 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1030 | static int dsi_unregister_isr_vc(struct platform_device *dsidev, int channel, |
| 1031 | omap_dsi_isr_t isr, void *arg, u32 mask) |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1032 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1033 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1034 | unsigned long flags; |
| 1035 | int r; |
| 1036 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1037 | spin_lock_irqsave(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1038 | |
| 1039 | r = _dsi_unregister_isr(isr, arg, mask, |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1040 | dsi->isr_tables.isr_table_vc[channel], |
| 1041 | ARRAY_SIZE(dsi->isr_tables.isr_table_vc[channel])); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1042 | |
| 1043 | if (r == 0) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1044 | _omap_dsi_set_irqs_vc(dsidev, channel); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1045 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1046 | spin_unlock_irqrestore(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1047 | |
| 1048 | return r; |
| 1049 | } |
| 1050 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1051 | static int dsi_register_isr_cio(struct platform_device *dsidev, |
| 1052 | omap_dsi_isr_t isr, void *arg, u32 mask) |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1053 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1054 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1055 | unsigned long flags; |
| 1056 | int r; |
| 1057 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1058 | spin_lock_irqsave(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1059 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1060 | r = _dsi_register_isr(isr, arg, mask, dsi->isr_tables.isr_table_cio, |
| 1061 | ARRAY_SIZE(dsi->isr_tables.isr_table_cio)); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1062 | |
| 1063 | if (r == 0) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1064 | _omap_dsi_set_irqs_cio(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1065 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1066 | spin_unlock_irqrestore(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1067 | |
| 1068 | return r; |
| 1069 | } |
| 1070 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1071 | static int dsi_unregister_isr_cio(struct platform_device *dsidev, |
| 1072 | omap_dsi_isr_t isr, void *arg, u32 mask) |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1073 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1074 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1075 | unsigned long flags; |
| 1076 | int r; |
| 1077 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1078 | spin_lock_irqsave(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1079 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1080 | r = _dsi_unregister_isr(isr, arg, mask, dsi->isr_tables.isr_table_cio, |
| 1081 | ARRAY_SIZE(dsi->isr_tables.isr_table_cio)); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1082 | |
| 1083 | if (r == 0) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1084 | _omap_dsi_set_irqs_cio(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1085 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1086 | spin_unlock_irqrestore(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1087 | |
| 1088 | return r; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1089 | } |
| 1090 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1091 | static u32 dsi_get_errors(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1092 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1093 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1094 | unsigned long flags; |
| 1095 | u32 e; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1096 | spin_lock_irqsave(&dsi->errors_lock, flags); |
| 1097 | e = dsi->errors; |
| 1098 | dsi->errors = 0; |
| 1099 | spin_unlock_irqrestore(&dsi->errors_lock, flags); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1100 | return e; |
| 1101 | } |
| 1102 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1103 | int dsi_runtime_get(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1104 | { |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1105 | int r; |
| 1106 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1107 | |
| 1108 | DSSDBG("dsi_runtime_get\n"); |
| 1109 | |
| 1110 | r = pm_runtime_get_sync(&dsi->pdev->dev); |
| 1111 | WARN_ON(r < 0); |
| 1112 | return r < 0 ? r : 0; |
| 1113 | } |
| 1114 | |
| 1115 | void dsi_runtime_put(struct platform_device *dsidev) |
| 1116 | { |
| 1117 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1118 | int r; |
| 1119 | |
| 1120 | DSSDBG("dsi_runtime_put\n"); |
| 1121 | |
Tomi Valkeinen | 0eaf9f5 | 2012-01-23 13:23:08 +0200 | [diff] [blame] | 1122 | r = pm_runtime_put_sync(&dsi->pdev->dev); |
Tomi Valkeinen | 5be3aeb | 2012-06-27 16:37:18 +0300 | [diff] [blame] | 1123 | WARN_ON(r < 0 && r != -ENOSYS); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1124 | } |
| 1125 | |
Tomi Valkeinen | b2541c4 | 2013-05-03 13:42:24 +0300 | [diff] [blame] | 1126 | static int dsi_regulator_init(struct platform_device *dsidev) |
| 1127 | { |
| 1128 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1129 | struct regulator *vdds_dsi; |
| 1130 | |
| 1131 | if (dsi->vdds_dsi_reg != NULL) |
| 1132 | return 0; |
| 1133 | |
| 1134 | vdds_dsi = devm_regulator_get(&dsi->pdev->dev, "vdds_dsi"); |
| 1135 | |
| 1136 | /* DT HACK: try VCXIO to make omapdss work for o4 sdp/panda */ |
| 1137 | if (IS_ERR(vdds_dsi)) |
| 1138 | vdds_dsi = devm_regulator_get(&dsi->pdev->dev, "VCXIO"); |
| 1139 | |
| 1140 | if (IS_ERR(vdds_dsi)) { |
| 1141 | DSSERR("can't get VDDS_DSI regulator\n"); |
| 1142 | return PTR_ERR(vdds_dsi); |
| 1143 | } |
| 1144 | |
| 1145 | dsi->vdds_dsi_reg = vdds_dsi; |
| 1146 | |
| 1147 | return 0; |
| 1148 | } |
| 1149 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1150 | /* source clock for DSI PLL. this could also be PCLKFREE */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1151 | static inline void dsi_enable_pll_clock(struct platform_device *dsidev, |
| 1152 | bool enable) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1153 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1154 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1155 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1156 | if (enable) |
Rajendra Nayak | f11766d | 2012-06-27 14:21:26 +0530 | [diff] [blame] | 1157 | clk_prepare_enable(dsi->sys_clk); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1158 | else |
Rajendra Nayak | f11766d | 2012-06-27 14:21:26 +0530 | [diff] [blame] | 1159 | clk_disable_unprepare(dsi->sys_clk); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1160 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1161 | if (enable && dsi->pll_locked) { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1162 | if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 1, 1) != 1) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1163 | DSSERR("cannot lock PLL when enabling clocks\n"); |
| 1164 | } |
| 1165 | } |
| 1166 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1167 | static void _dsi_print_reset_status(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1168 | { |
| 1169 | u32 l; |
Tomi Valkeinen | c335cbf | 2010-10-07 13:27:42 +0300 | [diff] [blame] | 1170 | int b0, b1, b2; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1171 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1172 | /* A dummy read using the SCP interface to any DSIPHY register is |
| 1173 | * required after DSIPHY reset to complete the reset of the DSI complex |
| 1174 | * I/O. */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1175 | l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1176 | |
Tomi Valkeinen | c335cbf | 2010-10-07 13:27:42 +0300 | [diff] [blame] | 1177 | if (dss_has_feature(FEAT_DSI_REVERSE_TXCLKESC)) { |
| 1178 | b0 = 28; |
| 1179 | b1 = 27; |
| 1180 | b2 = 26; |
| 1181 | } else { |
| 1182 | b0 = 24; |
| 1183 | b1 = 25; |
| 1184 | b2 = 26; |
| 1185 | } |
| 1186 | |
Chandrabhanu Mahapatra | f30be7d | 2012-09-29 12:33:05 +0530 | [diff] [blame] | 1187 | #define DSI_FLD_GET(fld, start, end)\ |
| 1188 | FLD_GET(dsi_read_reg(dsidev, DSI_##fld), start, end) |
| 1189 | |
| 1190 | pr_debug("DSI resets: PLL (%d) CIO (%d) PHY (%x%x%x, %d, %d, %d)\n", |
| 1191 | DSI_FLD_GET(PLL_STATUS, 0, 0), |
| 1192 | DSI_FLD_GET(COMPLEXIO_CFG1, 29, 29), |
| 1193 | DSI_FLD_GET(DSIPHY_CFG5, b0, b0), |
| 1194 | DSI_FLD_GET(DSIPHY_CFG5, b1, b1), |
| 1195 | DSI_FLD_GET(DSIPHY_CFG5, b2, b2), |
| 1196 | DSI_FLD_GET(DSIPHY_CFG5, 29, 29), |
| 1197 | DSI_FLD_GET(DSIPHY_CFG5, 30, 30), |
| 1198 | DSI_FLD_GET(DSIPHY_CFG5, 31, 31)); |
| 1199 | |
| 1200 | #undef DSI_FLD_GET |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1201 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1202 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1203 | static inline int dsi_if_enable(struct platform_device *dsidev, bool enable) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1204 | { |
| 1205 | DSSDBG("dsi_if_enable(%d)\n", enable); |
| 1206 | |
| 1207 | enable = enable ? 1 : 0; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1208 | REG_FLD_MOD(dsidev, DSI_CTRL, enable, 0, 0); /* IF_EN */ |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1209 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1210 | if (wait_for_bit_change(dsidev, DSI_CTRL, 0, enable) != enable) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1211 | DSSERR("Failed to set dsi_if_enable to %d\n", enable); |
| 1212 | return -EIO; |
| 1213 | } |
| 1214 | |
| 1215 | return 0; |
| 1216 | } |
| 1217 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1218 | unsigned long dsi_get_pll_hsdiv_dispc_rate(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1219 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1220 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1221 | |
| 1222 | return dsi->current_cinfo.dsi_pll_hsdiv_dispc_clk; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1223 | } |
| 1224 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1225 | static unsigned long dsi_get_pll_hsdiv_dsi_rate(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1226 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1227 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1228 | |
| 1229 | return dsi->current_cinfo.dsi_pll_hsdiv_dsi_clk; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1230 | } |
| 1231 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1232 | static unsigned long dsi_get_txbyteclkhs(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1233 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1234 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1235 | |
| 1236 | return dsi->current_cinfo.clkin4ddr / 16; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1237 | } |
| 1238 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1239 | static unsigned long dsi_fclk_rate(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1240 | { |
| 1241 | unsigned long r; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1242 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1243 | |
Tomi Valkeinen | 11ee960 | 2012-03-09 16:07:39 +0200 | [diff] [blame] | 1244 | if (dss_get_dsi_clk_source(dsi->module_id) == OMAP_DSS_CLK_SRC_FCK) { |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1245 | /* DSI FCLK source is DSS_CLK_FCK */ |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1246 | r = clk_get_rate(dsi->dss_clk); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1247 | } else { |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1248 | /* DSI FCLK source is dsi_pll_hsdiv_dsi_clk */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1249 | r = dsi_get_pll_hsdiv_dsi_rate(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1250 | } |
| 1251 | |
| 1252 | return r; |
| 1253 | } |
| 1254 | |
Tomi Valkeinen | f1e0001 | 2013-03-05 17:21:35 +0200 | [diff] [blame] | 1255 | static int dsi_lp_clock_calc(struct dsi_clock_info *cinfo, |
| 1256 | unsigned long lp_clk_min, unsigned long lp_clk_max) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1257 | { |
Tomi Valkeinen | f1e0001 | 2013-03-05 17:21:35 +0200 | [diff] [blame] | 1258 | unsigned long dsi_fclk = cinfo->dsi_pll_hsdiv_dsi_clk; |
| 1259 | unsigned lp_clk_div; |
| 1260 | unsigned long lp_clk; |
| 1261 | |
| 1262 | lp_clk_div = DIV_ROUND_UP(dsi_fclk, lp_clk_max * 2); |
| 1263 | lp_clk = dsi_fclk / 2 / lp_clk_div; |
| 1264 | |
| 1265 | if (lp_clk < lp_clk_min || lp_clk > lp_clk_max) |
| 1266 | return -EINVAL; |
| 1267 | |
| 1268 | cinfo->lp_clk_div = lp_clk_div; |
| 1269 | cinfo->lp_clk = lp_clk; |
| 1270 | |
| 1271 | return 0; |
| 1272 | } |
| 1273 | |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 1274 | static int dsi_set_lp_clk_divisor(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1275 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1276 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1277 | unsigned long dsi_fclk; |
| 1278 | unsigned lp_clk_div; |
| 1279 | unsigned long lp_clk; |
| 1280 | |
Tomi Valkeinen | a0d269e | 2012-11-27 17:05:54 +0200 | [diff] [blame] | 1281 | lp_clk_div = dsi->user_dsi_cinfo.lp_clk_div; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1282 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1283 | if (lp_clk_div == 0 || lp_clk_div > dsi->lpdiv_max) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1284 | return -EINVAL; |
| 1285 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1286 | dsi_fclk = dsi_fclk_rate(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1287 | |
| 1288 | lp_clk = dsi_fclk / 2 / lp_clk_div; |
| 1289 | |
| 1290 | DSSDBG("LP_CLK_DIV %u, LP_CLK %lu\n", lp_clk_div, lp_clk); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1291 | dsi->current_cinfo.lp_clk = lp_clk; |
| 1292 | dsi->current_cinfo.lp_clk_div = lp_clk_div; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1293 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1294 | /* LP_CLK_DIVISOR */ |
| 1295 | REG_FLD_MOD(dsidev, DSI_CLK_CTRL, lp_clk_div, 12, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1296 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1297 | /* LP_RX_SYNCHRO_ENABLE */ |
| 1298 | REG_FLD_MOD(dsidev, DSI_CLK_CTRL, dsi_fclk > 30000000 ? 1 : 0, 21, 21); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1299 | |
| 1300 | return 0; |
| 1301 | } |
| 1302 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1303 | static void dsi_enable_scp_clk(struct platform_device *dsidev) |
Tomi Valkeinen | 24c1ae4 | 2011-04-13 17:12:52 +0300 | [diff] [blame] | 1304 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1305 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1306 | |
| 1307 | if (dsi->scp_clk_refcount++ == 0) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1308 | REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 14, 14); /* CIO_CLK_ICG */ |
Tomi Valkeinen | 24c1ae4 | 2011-04-13 17:12:52 +0300 | [diff] [blame] | 1309 | } |
| 1310 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1311 | static void dsi_disable_scp_clk(struct platform_device *dsidev) |
Tomi Valkeinen | 24c1ae4 | 2011-04-13 17:12:52 +0300 | [diff] [blame] | 1312 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1313 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1314 | |
| 1315 | WARN_ON(dsi->scp_clk_refcount == 0); |
| 1316 | if (--dsi->scp_clk_refcount == 0) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1317 | REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 14, 14); /* CIO_CLK_ICG */ |
Tomi Valkeinen | 24c1ae4 | 2011-04-13 17:12:52 +0300 | [diff] [blame] | 1318 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1319 | |
| 1320 | enum dsi_pll_power_state { |
| 1321 | DSI_PLL_POWER_OFF = 0x0, |
| 1322 | DSI_PLL_POWER_ON_HSCLK = 0x1, |
| 1323 | DSI_PLL_POWER_ON_ALL = 0x2, |
| 1324 | DSI_PLL_POWER_ON_DIV = 0x3, |
| 1325 | }; |
| 1326 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1327 | static int dsi_pll_power(struct platform_device *dsidev, |
| 1328 | enum dsi_pll_power_state state) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1329 | { |
| 1330 | int t = 0; |
| 1331 | |
Tomi Valkeinen | c94dfe0 | 2011-04-15 10:42:59 +0300 | [diff] [blame] | 1332 | /* DSI-PLL power command 0x3 is not working */ |
| 1333 | if (dss_has_feature(FEAT_DSI_PLL_PWR_BUG) && |
| 1334 | state == DSI_PLL_POWER_ON_DIV) |
| 1335 | state = DSI_PLL_POWER_ON_ALL; |
| 1336 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1337 | /* PLL_PWR_CMD */ |
| 1338 | REG_FLD_MOD(dsidev, DSI_CLK_CTRL, state, 31, 30); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1339 | |
| 1340 | /* PLL_PWR_STATUS */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1341 | while (FLD_GET(dsi_read_reg(dsidev, DSI_CLK_CTRL), 29, 28) != state) { |
Tomi Valkeinen | 24be78b | 2010-01-07 14:19:48 +0200 | [diff] [blame] | 1342 | if (++t > 1000) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1343 | DSSERR("Failed to set DSI PLL power mode to %d\n", |
| 1344 | state); |
| 1345 | return -ENODEV; |
| 1346 | } |
Tomi Valkeinen | 24be78b | 2010-01-07 14:19:48 +0200 | [diff] [blame] | 1347 | udelay(1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | return 0; |
| 1351 | } |
| 1352 | |
Tomi Valkeinen | 72658f0 | 2013-03-05 16:39:00 +0200 | [diff] [blame] | 1353 | unsigned long dsi_get_pll_clkin(struct platform_device *dsidev) |
| 1354 | { |
| 1355 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1356 | return clk_get_rate(dsi->sys_clk); |
| 1357 | } |
| 1358 | |
| 1359 | bool dsi_hsdiv_calc(struct platform_device *dsidev, unsigned long pll, |
| 1360 | unsigned long out_min, dsi_hsdiv_calc_func func, void *data) |
| 1361 | { |
| 1362 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1363 | int regm, regm_start, regm_stop; |
| 1364 | unsigned long out_max; |
| 1365 | unsigned long out; |
| 1366 | |
| 1367 | out_min = out_min ? out_min : 1; |
| 1368 | out_max = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK); |
| 1369 | |
| 1370 | regm_start = max(DIV_ROUND_UP(pll, out_max), 1ul); |
| 1371 | regm_stop = min(pll / out_min, dsi->regm_dispc_max); |
| 1372 | |
| 1373 | for (regm = regm_start; regm <= regm_stop; ++regm) { |
| 1374 | out = pll / regm; |
| 1375 | |
| 1376 | if (func(regm, out, data)) |
| 1377 | return true; |
| 1378 | } |
| 1379 | |
| 1380 | return false; |
| 1381 | } |
| 1382 | |
| 1383 | bool dsi_pll_calc(struct platform_device *dsidev, unsigned long clkin, |
| 1384 | unsigned long pll_min, unsigned long pll_max, |
| 1385 | dsi_pll_calc_func func, void *data) |
| 1386 | { |
| 1387 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1388 | int regn, regn_start, regn_stop; |
| 1389 | int regm, regm_start, regm_stop; |
| 1390 | unsigned long fint, pll; |
| 1391 | const unsigned long pll_hw_max = 1800000000; |
| 1392 | unsigned long fint_hw_min, fint_hw_max; |
| 1393 | |
| 1394 | fint_hw_min = dsi->fint_min; |
| 1395 | fint_hw_max = dsi->fint_max; |
| 1396 | |
| 1397 | regn_start = max(DIV_ROUND_UP(clkin, fint_hw_max), 1ul); |
| 1398 | regn_stop = min(clkin / fint_hw_min, dsi->regn_max); |
| 1399 | |
| 1400 | pll_max = pll_max ? pll_max : ULONG_MAX; |
| 1401 | |
| 1402 | for (regn = regn_start; regn <= regn_stop; ++regn) { |
| 1403 | fint = clkin / regn; |
| 1404 | |
| 1405 | regm_start = max(DIV_ROUND_UP(DIV_ROUND_UP(pll_min, fint), 2), |
| 1406 | 1ul); |
| 1407 | regm_stop = min3(pll_max / fint / 2, |
| 1408 | pll_hw_max / fint / 2, |
| 1409 | dsi->regm_max); |
| 1410 | |
| 1411 | for (regm = regm_start; regm <= regm_stop; ++regm) { |
| 1412 | pll = 2 * regm * fint; |
| 1413 | |
| 1414 | if (func(regn, regm, fint, pll, data)) |
| 1415 | return true; |
| 1416 | } |
| 1417 | } |
| 1418 | |
| 1419 | return false; |
| 1420 | } |
| 1421 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1422 | /* calculate clock rates using dividers in cinfo */ |
Tomi Valkeinen | b6e695a | 2012-03-15 15:22:58 +0200 | [diff] [blame] | 1423 | static int dsi_calc_clock_rates(struct platform_device *dsidev, |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 1424 | struct dsi_clock_info *cinfo) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1425 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1426 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1427 | |
| 1428 | if (cinfo->regn == 0 || cinfo->regn > dsi->regn_max) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1429 | return -EINVAL; |
| 1430 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1431 | if (cinfo->regm == 0 || cinfo->regm > dsi->regm_max) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1432 | return -EINVAL; |
| 1433 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1434 | if (cinfo->regm_dispc > dsi->regm_dispc_max) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1435 | return -EINVAL; |
| 1436 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1437 | if (cinfo->regm_dsi > dsi->regm_dsi_max) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1438 | return -EINVAL; |
| 1439 | |
Tomi Valkeinen | b6e695a | 2012-03-15 15:22:58 +0200 | [diff] [blame] | 1440 | cinfo->clkin = clk_get_rate(dsi->sys_clk); |
| 1441 | cinfo->fint = cinfo->clkin / cinfo->regn; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1442 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1443 | if (cinfo->fint > dsi->fint_max || cinfo->fint < dsi->fint_min) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1444 | return -EINVAL; |
| 1445 | |
| 1446 | cinfo->clkin4ddr = 2 * cinfo->regm * cinfo->fint; |
| 1447 | |
| 1448 | if (cinfo->clkin4ddr > 1800 * 1000 * 1000) |
| 1449 | return -EINVAL; |
| 1450 | |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1451 | if (cinfo->regm_dispc > 0) |
| 1452 | cinfo->dsi_pll_hsdiv_dispc_clk = |
| 1453 | cinfo->clkin4ddr / cinfo->regm_dispc; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1454 | else |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1455 | cinfo->dsi_pll_hsdiv_dispc_clk = 0; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1456 | |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1457 | if (cinfo->regm_dsi > 0) |
| 1458 | cinfo->dsi_pll_hsdiv_dsi_clk = |
| 1459 | cinfo->clkin4ddr / cinfo->regm_dsi; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1460 | else |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1461 | cinfo->dsi_pll_hsdiv_dsi_clk = 0; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1462 | |
| 1463 | return 0; |
| 1464 | } |
| 1465 | |
Tomi Valkeinen | f1e0001 | 2013-03-05 17:21:35 +0200 | [diff] [blame] | 1466 | static void dsi_pll_calc_dsi_fck(struct dsi_clock_info *cinfo) |
Tomi Valkeinen | d66b158 | 2012-09-24 15:15:06 +0300 | [diff] [blame] | 1467 | { |
| 1468 | unsigned long max_dsi_fck; |
| 1469 | |
| 1470 | max_dsi_fck = dss_feat_get_param_max(FEAT_PARAM_DSI_FCK); |
| 1471 | |
| 1472 | cinfo->regm_dsi = DIV_ROUND_UP(cinfo->clkin4ddr, max_dsi_fck); |
| 1473 | cinfo->dsi_pll_hsdiv_dsi_clk = cinfo->clkin4ddr / cinfo->regm_dsi; |
| 1474 | } |
| 1475 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1476 | int dsi_pll_set_clock_div(struct platform_device *dsidev, |
| 1477 | struct dsi_clock_info *cinfo) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1478 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1479 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1480 | int r = 0; |
| 1481 | u32 l; |
Archit Taneja | 9613c02 | 2011-03-22 06:33:36 -0500 | [diff] [blame] | 1482 | int f = 0; |
Taneja, Archit | 4964111 | 2011-03-14 23:28:23 -0500 | [diff] [blame] | 1483 | u8 regn_start, regn_end, regm_start, regm_end; |
| 1484 | 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] | 1485 | |
Chandrabhanu Mahapatra | 702d267 | 2012-09-24 17:12:58 +0530 | [diff] [blame] | 1486 | DSSDBG("DSI PLL clock config starts"); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1487 | |
Tomi Valkeinen | b6e695a | 2012-03-15 15:22:58 +0200 | [diff] [blame] | 1488 | dsi->current_cinfo.clkin = cinfo->clkin; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1489 | dsi->current_cinfo.fint = cinfo->fint; |
| 1490 | dsi->current_cinfo.clkin4ddr = cinfo->clkin4ddr; |
| 1491 | dsi->current_cinfo.dsi_pll_hsdiv_dispc_clk = |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1492 | cinfo->dsi_pll_hsdiv_dispc_clk; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1493 | dsi->current_cinfo.dsi_pll_hsdiv_dsi_clk = |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1494 | cinfo->dsi_pll_hsdiv_dsi_clk; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1495 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1496 | dsi->current_cinfo.regn = cinfo->regn; |
| 1497 | dsi->current_cinfo.regm = cinfo->regm; |
| 1498 | dsi->current_cinfo.regm_dispc = cinfo->regm_dispc; |
| 1499 | dsi->current_cinfo.regm_dsi = cinfo->regm_dsi; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1500 | |
| 1501 | DSSDBG("DSI Fint %ld\n", cinfo->fint); |
| 1502 | |
Tomi Valkeinen | b6e695a | 2012-03-15 15:22:58 +0200 | [diff] [blame] | 1503 | DSSDBG("clkin rate %ld\n", cinfo->clkin); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1504 | |
| 1505 | /* DSIPHY == CLKIN4DDR */ |
Tomi Valkeinen | b6e695a | 2012-03-15 15:22:58 +0200 | [diff] [blame] | 1506 | DSSDBG("CLKIN4DDR = 2 * %d / %d * %lu = %lu\n", |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1507 | cinfo->regm, |
| 1508 | cinfo->regn, |
| 1509 | cinfo->clkin, |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1510 | cinfo->clkin4ddr); |
| 1511 | |
| 1512 | DSSDBG("Data rate on 1 DSI lane %ld Mbps\n", |
| 1513 | cinfo->clkin4ddr / 1000 / 1000 / 2); |
| 1514 | |
| 1515 | DSSDBG("Clock lane freq %ld Hz\n", cinfo->clkin4ddr / 4); |
| 1516 | |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1517 | DSSDBG("regm_dispc = %d, %s (%s) = %lu\n", cinfo->regm_dispc, |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 1518 | dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC), |
| 1519 | 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] | 1520 | cinfo->dsi_pll_hsdiv_dispc_clk); |
| 1521 | DSSDBG("regm_dsi = %d, %s (%s) = %lu\n", cinfo->regm_dsi, |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 1522 | dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI), |
| 1523 | 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] | 1524 | cinfo->dsi_pll_hsdiv_dsi_clk); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1525 | |
Taneja, Archit | 4964111 | 2011-03-14 23:28:23 -0500 | [diff] [blame] | 1526 | dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGN, ®n_start, ®n_end); |
| 1527 | dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM, ®m_start, ®m_end); |
| 1528 | dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DISPC, ®m_dispc_start, |
| 1529 | ®m_dispc_end); |
| 1530 | dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DSI, ®m_dsi_start, |
| 1531 | ®m_dsi_end); |
| 1532 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1533 | /* DSI_PLL_AUTOMODE = manual */ |
| 1534 | REG_FLD_MOD(dsidev, DSI_PLL_CONTROL, 0, 0, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1535 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1536 | l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1537 | l = FLD_MOD(l, 1, 0, 0); /* DSI_PLL_STOPMODE */ |
Taneja, Archit | 4964111 | 2011-03-14 23:28:23 -0500 | [diff] [blame] | 1538 | /* DSI_PLL_REGN */ |
| 1539 | l = FLD_MOD(l, cinfo->regn - 1, regn_start, regn_end); |
| 1540 | /* DSI_PLL_REGM */ |
| 1541 | l = FLD_MOD(l, cinfo->regm, regm_start, regm_end); |
| 1542 | /* DSI_CLOCK_DIV */ |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1543 | 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] | 1544 | regm_dispc_start, regm_dispc_end); |
| 1545 | /* DSIPROTO_CLOCK_DIV */ |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1546 | 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] | 1547 | regm_dsi_start, regm_dsi_end); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1548 | dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION1, l); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1549 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1550 | BUG_ON(cinfo->fint < dsi->fint_min || cinfo->fint > dsi->fint_max); |
Archit Taneja | 9613c02 | 2011-03-22 06:33:36 -0500 | [diff] [blame] | 1551 | |
Tomi Valkeinen | f8ef3d6 | 2012-08-22 16:00:31 +0300 | [diff] [blame] | 1552 | l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION2); |
| 1553 | |
Archit Taneja | 9613c02 | 2011-03-22 06:33:36 -0500 | [diff] [blame] | 1554 | if (dss_has_feature(FEAT_DSI_PLL_FREQSEL)) { |
| 1555 | f = cinfo->fint < 1000000 ? 0x3 : |
| 1556 | cinfo->fint < 1250000 ? 0x4 : |
| 1557 | cinfo->fint < 1500000 ? 0x5 : |
| 1558 | cinfo->fint < 1750000 ? 0x6 : |
| 1559 | 0x7; |
Tomi Valkeinen | f8ef3d6 | 2012-08-22 16:00:31 +0300 | [diff] [blame] | 1560 | |
| 1561 | l = FLD_MOD(l, f, 4, 1); /* DSI_PLL_FREQSEL */ |
| 1562 | } else if (dss_has_feature(FEAT_DSI_PLL_SELFREQDCO)) { |
| 1563 | f = cinfo->clkin4ddr < 1000000000 ? 0x2 : 0x4; |
| 1564 | |
| 1565 | l = FLD_MOD(l, f, 4, 1); /* PLL_SELFREQDCO */ |
Archit Taneja | 9613c02 | 2011-03-22 06:33:36 -0500 | [diff] [blame] | 1566 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1567 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1568 | l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */ |
| 1569 | l = FLD_MOD(l, 0, 14, 14); /* DSIPHY_CLKINEN */ |
| 1570 | l = FLD_MOD(l, 1, 20, 20); /* DSI_HSDIVBYPASS */ |
Tomi Valkeinen | 6d44610 | 2012-08-22 16:00:40 +0300 | [diff] [blame] | 1571 | if (dss_has_feature(FEAT_DSI_PLL_REFSEL)) |
| 1572 | l = FLD_MOD(l, 3, 22, 21); /* REF_SYSCLK = sysclk */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1573 | dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION2, l); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1574 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1575 | REG_FLD_MOD(dsidev, DSI_PLL_GO, 1, 0, 0); /* DSI_PLL_GO */ |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1576 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1577 | if (wait_for_bit_change(dsidev, DSI_PLL_GO, 0, 0) != 0) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1578 | DSSERR("dsi pll go bit not going down.\n"); |
| 1579 | r = -EIO; |
| 1580 | goto err; |
| 1581 | } |
| 1582 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1583 | if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 1, 1) != 1) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1584 | DSSERR("cannot lock PLL\n"); |
| 1585 | r = -EIO; |
| 1586 | goto err; |
| 1587 | } |
| 1588 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1589 | dsi->pll_locked = 1; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1590 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1591 | l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION2); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1592 | l = FLD_MOD(l, 0, 0, 0); /* DSI_PLL_IDLE */ |
| 1593 | l = FLD_MOD(l, 0, 5, 5); /* DSI_PLL_PLLLPMODE */ |
| 1594 | l = FLD_MOD(l, 0, 6, 6); /* DSI_PLL_LOWCURRSTBY */ |
| 1595 | l = FLD_MOD(l, 0, 7, 7); /* DSI_PLL_TIGHTPHASELOCK */ |
| 1596 | l = FLD_MOD(l, 0, 8, 8); /* DSI_PLL_DRIFTGUARDEN */ |
| 1597 | l = FLD_MOD(l, 0, 10, 9); /* DSI_PLL_LOCKSEL */ |
| 1598 | l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */ |
| 1599 | l = FLD_MOD(l, 1, 14, 14); /* DSIPHY_CLKINEN */ |
| 1600 | l = FLD_MOD(l, 0, 15, 15); /* DSI_BYPASSEN */ |
| 1601 | l = FLD_MOD(l, 1, 16, 16); /* DSS_CLOCK_EN */ |
| 1602 | l = FLD_MOD(l, 0, 17, 17); /* DSS_CLOCK_PWDN */ |
| 1603 | l = FLD_MOD(l, 1, 18, 18); /* DSI_PROTO_CLOCK_EN */ |
| 1604 | l = FLD_MOD(l, 0, 19, 19); /* DSI_PROTO_CLOCK_PWDN */ |
| 1605 | l = FLD_MOD(l, 0, 20, 20); /* DSI_HSDIVBYPASS */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1606 | dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION2, l); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1607 | |
| 1608 | DSSDBG("PLL config done\n"); |
| 1609 | err: |
| 1610 | return r; |
| 1611 | } |
| 1612 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1613 | int dsi_pll_init(struct platform_device *dsidev, bool enable_hsclk, |
| 1614 | bool enable_hsdiv) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1615 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1616 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1617 | int r = 0; |
| 1618 | enum dsi_pll_power_state pwstate; |
| 1619 | |
| 1620 | DSSDBG("PLL init\n"); |
| 1621 | |
Tomi Valkeinen | 7a98786 | 2012-10-12 16:27:28 +0300 | [diff] [blame] | 1622 | /* |
| 1623 | * It seems that on many OMAPs we need to enable both to have a |
| 1624 | * functional HSDivider. |
| 1625 | */ |
| 1626 | enable_hsclk = enable_hsdiv = true; |
| 1627 | |
Tomi Valkeinen | b2541c4 | 2013-05-03 13:42:24 +0300 | [diff] [blame] | 1628 | r = dsi_regulator_init(dsidev); |
| 1629 | if (r) |
| 1630 | return r; |
Tomi Valkeinen | f2988ab | 2011-03-02 10:06:48 +0200 | [diff] [blame] | 1631 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1632 | dsi_enable_pll_clock(dsidev, 1); |
Tomi Valkeinen | 24c1ae4 | 2011-04-13 17:12:52 +0300 | [diff] [blame] | 1633 | /* |
| 1634 | * Note: SCP CLK is not required on OMAP3, but it is required on OMAP4. |
| 1635 | */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1636 | dsi_enable_scp_clk(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1637 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1638 | if (!dsi->vdds_dsi_enabled) { |
| 1639 | r = regulator_enable(dsi->vdds_dsi_reg); |
Tomi Valkeinen | 2a89dc1 | 2010-07-30 12:39:34 +0300 | [diff] [blame] | 1640 | if (r) |
| 1641 | goto err0; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1642 | dsi->vdds_dsi_enabled = true; |
Tomi Valkeinen | 2a89dc1 | 2010-07-30 12:39:34 +0300 | [diff] [blame] | 1643 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1644 | |
| 1645 | /* XXX PLL does not come out of reset without this... */ |
| 1646 | dispc_pck_free_enable(1); |
| 1647 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1648 | if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 0, 1) != 1) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1649 | DSSERR("PLL not coming out of reset.\n"); |
| 1650 | r = -ENODEV; |
Ville Syrjälä | 481dfa0 | 2010-04-22 22:50:04 +0200 | [diff] [blame] | 1651 | dispc_pck_free_enable(0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1652 | goto err1; |
| 1653 | } |
| 1654 | |
| 1655 | /* XXX ... but if left on, we get problems when planes do not |
| 1656 | * fill the whole display. No idea about this */ |
| 1657 | dispc_pck_free_enable(0); |
| 1658 | |
| 1659 | if (enable_hsclk && enable_hsdiv) |
| 1660 | pwstate = DSI_PLL_POWER_ON_ALL; |
| 1661 | else if (enable_hsclk) |
| 1662 | pwstate = DSI_PLL_POWER_ON_HSCLK; |
| 1663 | else if (enable_hsdiv) |
| 1664 | pwstate = DSI_PLL_POWER_ON_DIV; |
| 1665 | else |
| 1666 | pwstate = DSI_PLL_POWER_OFF; |
| 1667 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1668 | r = dsi_pll_power(dsidev, pwstate); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1669 | |
| 1670 | if (r) |
| 1671 | goto err1; |
| 1672 | |
| 1673 | DSSDBG("PLL init done\n"); |
| 1674 | |
| 1675 | return 0; |
| 1676 | err1: |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1677 | if (dsi->vdds_dsi_enabled) { |
| 1678 | regulator_disable(dsi->vdds_dsi_reg); |
| 1679 | dsi->vdds_dsi_enabled = false; |
Tomi Valkeinen | 2a89dc1 | 2010-07-30 12:39:34 +0300 | [diff] [blame] | 1680 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1681 | err0: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1682 | dsi_disable_scp_clk(dsidev); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1683 | dsi_enable_pll_clock(dsidev, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1684 | return r; |
| 1685 | } |
| 1686 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1687 | void dsi_pll_uninit(struct platform_device *dsidev, bool disconnect_lanes) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1688 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1689 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1690 | |
| 1691 | dsi->pll_locked = 0; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1692 | dsi_pll_power(dsidev, DSI_PLL_POWER_OFF); |
Tomi Valkeinen | 2a89dc1 | 2010-07-30 12:39:34 +0300 | [diff] [blame] | 1693 | if (disconnect_lanes) { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1694 | WARN_ON(!dsi->vdds_dsi_enabled); |
| 1695 | regulator_disable(dsi->vdds_dsi_reg); |
| 1696 | dsi->vdds_dsi_enabled = false; |
Tomi Valkeinen | 2a89dc1 | 2010-07-30 12:39:34 +0300 | [diff] [blame] | 1697 | } |
Tomi Valkeinen | 24c1ae4 | 2011-04-13 17:12:52 +0300 | [diff] [blame] | 1698 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1699 | dsi_disable_scp_clk(dsidev); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1700 | dsi_enable_pll_clock(dsidev, 0); |
Tomi Valkeinen | 24c1ae4 | 2011-04-13 17:12:52 +0300 | [diff] [blame] | 1701 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1702 | DSSDBG("PLL uninit done\n"); |
| 1703 | } |
| 1704 | |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 1705 | static void dsi_dump_dsidev_clocks(struct platform_device *dsidev, |
| 1706 | struct seq_file *s) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1707 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1708 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1709 | struct dsi_clock_info *cinfo = &dsi->current_cinfo; |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 1710 | enum omap_dss_clk_source dispc_clk_src, dsi_clk_src; |
Tomi Valkeinen | 11ee960 | 2012-03-09 16:07:39 +0200 | [diff] [blame] | 1711 | int dsi_module = dsi->module_id; |
Archit Taneja | 067a57e | 2011-03-02 11:57:25 +0530 | [diff] [blame] | 1712 | |
| 1713 | dispc_clk_src = dss_get_dispc_clk_source(); |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 1714 | dsi_clk_src = dss_get_dsi_clk_source(dsi_module); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1715 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1716 | if (dsi_runtime_get(dsidev)) |
| 1717 | return; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1718 | |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 1719 | seq_printf(s, "- DSI%d PLL -\n", dsi_module + 1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1720 | |
Tomi Valkeinen | b6e695a | 2012-03-15 15:22:58 +0200 | [diff] [blame] | 1721 | seq_printf(s, "dsi pll clkin\t%lu\n", cinfo->clkin); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1722 | |
| 1723 | seq_printf(s, "Fint\t\t%-16luregn %u\n", cinfo->fint, cinfo->regn); |
| 1724 | |
| 1725 | seq_printf(s, "CLKIN4DDR\t%-16luregm %u\n", |
| 1726 | cinfo->clkin4ddr, cinfo->regm); |
| 1727 | |
Archit Taneja | 84309f1 | 2011-12-12 11:47:41 +0530 | [diff] [blame] | 1728 | seq_printf(s, "DSI_PLL_HSDIV_DISPC (%s)\t%-16luregm_dispc %u\t(%s)\n", |
| 1729 | dss_feat_get_clk_source_name(dsi_module == 0 ? |
| 1730 | OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC : |
| 1731 | OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC), |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1732 | cinfo->dsi_pll_hsdiv_dispc_clk, |
| 1733 | cinfo->regm_dispc, |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 1734 | dispc_clk_src == OMAP_DSS_CLK_SRC_FCK ? |
Tomi Valkeinen | 63cf28a | 2010-02-23 17:40:00 +0200 | [diff] [blame] | 1735 | "off" : "on"); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1736 | |
Archit Taneja | 84309f1 | 2011-12-12 11:47:41 +0530 | [diff] [blame] | 1737 | seq_printf(s, "DSI_PLL_HSDIV_DSI (%s)\t%-16luregm_dsi %u\t(%s)\n", |
| 1738 | dss_feat_get_clk_source_name(dsi_module == 0 ? |
| 1739 | OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI : |
| 1740 | OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI), |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1741 | cinfo->dsi_pll_hsdiv_dsi_clk, |
| 1742 | cinfo->regm_dsi, |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 1743 | dsi_clk_src == OMAP_DSS_CLK_SRC_FCK ? |
Tomi Valkeinen | 63cf28a | 2010-02-23 17:40:00 +0200 | [diff] [blame] | 1744 | "off" : "on"); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1745 | |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 1746 | seq_printf(s, "- DSI%d -\n", dsi_module + 1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1747 | |
Archit Taneja | 067a57e | 2011-03-02 11:57:25 +0530 | [diff] [blame] | 1748 | seq_printf(s, "dsi fclk source = %s (%s)\n", |
| 1749 | dss_get_generic_clk_source_name(dsi_clk_src), |
| 1750 | dss_feat_get_clk_source_name(dsi_clk_src)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1751 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1752 | seq_printf(s, "DSI_FCLK\t%lu\n", dsi_fclk_rate(dsidev)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1753 | |
| 1754 | seq_printf(s, "DDR_CLK\t\t%lu\n", |
| 1755 | cinfo->clkin4ddr / 4); |
| 1756 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1757 | seq_printf(s, "TxByteClkHS\t%lu\n", dsi_get_txbyteclkhs(dsidev)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1758 | |
| 1759 | seq_printf(s, "LP_CLK\t\t%lu\n", cinfo->lp_clk); |
| 1760 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1761 | dsi_runtime_put(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1762 | } |
| 1763 | |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 1764 | void dsi_dump_clocks(struct seq_file *s) |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 1765 | { |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 1766 | struct platform_device *dsidev; |
| 1767 | int i; |
| 1768 | |
| 1769 | for (i = 0; i < MAX_NUM_DSI; i++) { |
| 1770 | dsidev = dsi_get_dsidev_from_id(i); |
| 1771 | if (dsidev) |
| 1772 | dsi_dump_dsidev_clocks(dsidev, s); |
| 1773 | } |
| 1774 | } |
| 1775 | |
| 1776 | #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS |
| 1777 | static void dsi_dump_dsidev_irqs(struct platform_device *dsidev, |
| 1778 | struct seq_file *s) |
| 1779 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1780 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 1781 | unsigned long flags; |
| 1782 | struct dsi_irq_stats stats; |
| 1783 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1784 | spin_lock_irqsave(&dsi->irq_stats_lock, flags); |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 1785 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1786 | stats = dsi->irq_stats; |
| 1787 | memset(&dsi->irq_stats, 0, sizeof(dsi->irq_stats)); |
| 1788 | dsi->irq_stats.last_reset = jiffies; |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 1789 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1790 | spin_unlock_irqrestore(&dsi->irq_stats_lock, flags); |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 1791 | |
| 1792 | seq_printf(s, "period %u ms\n", |
| 1793 | jiffies_to_msecs(jiffies - stats.last_reset)); |
| 1794 | |
| 1795 | seq_printf(s, "irqs %d\n", stats.irq_count); |
| 1796 | #define PIS(x) \ |
| 1797 | seq_printf(s, "%-20s %10d\n", #x, stats.dsi_irqs[ffs(DSI_IRQ_##x)-1]); |
| 1798 | |
Tomi Valkeinen | 11ee960 | 2012-03-09 16:07:39 +0200 | [diff] [blame] | 1799 | seq_printf(s, "-- DSI%d interrupts --\n", dsi->module_id + 1); |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 1800 | PIS(VC0); |
| 1801 | PIS(VC1); |
| 1802 | PIS(VC2); |
| 1803 | PIS(VC3); |
| 1804 | PIS(WAKEUP); |
| 1805 | PIS(RESYNC); |
| 1806 | PIS(PLL_LOCK); |
| 1807 | PIS(PLL_UNLOCK); |
| 1808 | PIS(PLL_RECALL); |
| 1809 | PIS(COMPLEXIO_ERR); |
| 1810 | PIS(HS_TX_TIMEOUT); |
| 1811 | PIS(LP_RX_TIMEOUT); |
| 1812 | PIS(TE_TRIGGER); |
| 1813 | PIS(ACK_TRIGGER); |
| 1814 | PIS(SYNC_LOST); |
| 1815 | PIS(LDO_POWER_GOOD); |
| 1816 | PIS(TA_TIMEOUT); |
| 1817 | #undef PIS |
| 1818 | |
| 1819 | #define PIS(x) \ |
| 1820 | seq_printf(s, "%-20s %10d %10d %10d %10d\n", #x, \ |
| 1821 | stats.vc_irqs[0][ffs(DSI_VC_IRQ_##x)-1], \ |
| 1822 | stats.vc_irqs[1][ffs(DSI_VC_IRQ_##x)-1], \ |
| 1823 | stats.vc_irqs[2][ffs(DSI_VC_IRQ_##x)-1], \ |
| 1824 | stats.vc_irqs[3][ffs(DSI_VC_IRQ_##x)-1]); |
| 1825 | |
| 1826 | seq_printf(s, "-- VC interrupts --\n"); |
| 1827 | PIS(CS); |
| 1828 | PIS(ECC_CORR); |
| 1829 | PIS(PACKET_SENT); |
| 1830 | PIS(FIFO_TX_OVF); |
| 1831 | PIS(FIFO_RX_OVF); |
| 1832 | PIS(BTA); |
| 1833 | PIS(ECC_NO_CORR); |
| 1834 | PIS(FIFO_TX_UDF); |
| 1835 | PIS(PP_BUSY_CHANGE); |
| 1836 | #undef PIS |
| 1837 | |
| 1838 | #define PIS(x) \ |
| 1839 | seq_printf(s, "%-20s %10d\n", #x, \ |
| 1840 | stats.cio_irqs[ffs(DSI_CIO_IRQ_##x)-1]); |
| 1841 | |
| 1842 | seq_printf(s, "-- CIO interrupts --\n"); |
| 1843 | PIS(ERRSYNCESC1); |
| 1844 | PIS(ERRSYNCESC2); |
| 1845 | PIS(ERRSYNCESC3); |
| 1846 | PIS(ERRESC1); |
| 1847 | PIS(ERRESC2); |
| 1848 | PIS(ERRESC3); |
| 1849 | PIS(ERRCONTROL1); |
| 1850 | PIS(ERRCONTROL2); |
| 1851 | PIS(ERRCONTROL3); |
| 1852 | PIS(STATEULPS1); |
| 1853 | PIS(STATEULPS2); |
| 1854 | PIS(STATEULPS3); |
| 1855 | PIS(ERRCONTENTIONLP0_1); |
| 1856 | PIS(ERRCONTENTIONLP1_1); |
| 1857 | PIS(ERRCONTENTIONLP0_2); |
| 1858 | PIS(ERRCONTENTIONLP1_2); |
| 1859 | PIS(ERRCONTENTIONLP0_3); |
| 1860 | PIS(ERRCONTENTIONLP1_3); |
| 1861 | PIS(ULPSACTIVENOT_ALL0); |
| 1862 | PIS(ULPSACTIVENOT_ALL1); |
| 1863 | #undef PIS |
| 1864 | } |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 1865 | |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 1866 | static void dsi1_dump_irqs(struct seq_file *s) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1867 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1868 | struct platform_device *dsidev = dsi_get_dsidev_from_id(0); |
| 1869 | |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 1870 | dsi_dump_dsidev_irqs(dsidev, s); |
| 1871 | } |
| 1872 | |
| 1873 | static void dsi2_dump_irqs(struct seq_file *s) |
| 1874 | { |
| 1875 | struct platform_device *dsidev = dsi_get_dsidev_from_id(1); |
| 1876 | |
| 1877 | dsi_dump_dsidev_irqs(dsidev, s); |
| 1878 | } |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 1879 | #endif |
| 1880 | |
| 1881 | static void dsi_dump_dsidev_regs(struct platform_device *dsidev, |
| 1882 | struct seq_file *s) |
| 1883 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1884 | #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dsi_read_reg(dsidev, r)) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1885 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1886 | if (dsi_runtime_get(dsidev)) |
| 1887 | return; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1888 | dsi_enable_scp_clk(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1889 | |
| 1890 | DUMPREG(DSI_REVISION); |
| 1891 | DUMPREG(DSI_SYSCONFIG); |
| 1892 | DUMPREG(DSI_SYSSTATUS); |
| 1893 | DUMPREG(DSI_IRQSTATUS); |
| 1894 | DUMPREG(DSI_IRQENABLE); |
| 1895 | DUMPREG(DSI_CTRL); |
| 1896 | DUMPREG(DSI_COMPLEXIO_CFG1); |
| 1897 | DUMPREG(DSI_COMPLEXIO_IRQ_STATUS); |
| 1898 | DUMPREG(DSI_COMPLEXIO_IRQ_ENABLE); |
| 1899 | DUMPREG(DSI_CLK_CTRL); |
| 1900 | DUMPREG(DSI_TIMING1); |
| 1901 | DUMPREG(DSI_TIMING2); |
| 1902 | DUMPREG(DSI_VM_TIMING1); |
| 1903 | DUMPREG(DSI_VM_TIMING2); |
| 1904 | DUMPREG(DSI_VM_TIMING3); |
| 1905 | DUMPREG(DSI_CLK_TIMING); |
| 1906 | DUMPREG(DSI_TX_FIFO_VC_SIZE); |
| 1907 | DUMPREG(DSI_RX_FIFO_VC_SIZE); |
| 1908 | DUMPREG(DSI_COMPLEXIO_CFG2); |
| 1909 | DUMPREG(DSI_RX_FIFO_VC_FULLNESS); |
| 1910 | DUMPREG(DSI_VM_TIMING4); |
| 1911 | DUMPREG(DSI_TX_FIFO_VC_EMPTINESS); |
| 1912 | DUMPREG(DSI_VM_TIMING5); |
| 1913 | DUMPREG(DSI_VM_TIMING6); |
| 1914 | DUMPREG(DSI_VM_TIMING7); |
| 1915 | DUMPREG(DSI_STOPCLK_TIMING); |
| 1916 | |
| 1917 | DUMPREG(DSI_VC_CTRL(0)); |
| 1918 | DUMPREG(DSI_VC_TE(0)); |
| 1919 | DUMPREG(DSI_VC_LONG_PACKET_HEADER(0)); |
| 1920 | DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(0)); |
| 1921 | DUMPREG(DSI_VC_SHORT_PACKET_HEADER(0)); |
| 1922 | DUMPREG(DSI_VC_IRQSTATUS(0)); |
| 1923 | DUMPREG(DSI_VC_IRQENABLE(0)); |
| 1924 | |
| 1925 | DUMPREG(DSI_VC_CTRL(1)); |
| 1926 | DUMPREG(DSI_VC_TE(1)); |
| 1927 | DUMPREG(DSI_VC_LONG_PACKET_HEADER(1)); |
| 1928 | DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(1)); |
| 1929 | DUMPREG(DSI_VC_SHORT_PACKET_HEADER(1)); |
| 1930 | DUMPREG(DSI_VC_IRQSTATUS(1)); |
| 1931 | DUMPREG(DSI_VC_IRQENABLE(1)); |
| 1932 | |
| 1933 | DUMPREG(DSI_VC_CTRL(2)); |
| 1934 | DUMPREG(DSI_VC_TE(2)); |
| 1935 | DUMPREG(DSI_VC_LONG_PACKET_HEADER(2)); |
| 1936 | DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(2)); |
| 1937 | DUMPREG(DSI_VC_SHORT_PACKET_HEADER(2)); |
| 1938 | DUMPREG(DSI_VC_IRQSTATUS(2)); |
| 1939 | DUMPREG(DSI_VC_IRQENABLE(2)); |
| 1940 | |
| 1941 | DUMPREG(DSI_VC_CTRL(3)); |
| 1942 | DUMPREG(DSI_VC_TE(3)); |
| 1943 | DUMPREG(DSI_VC_LONG_PACKET_HEADER(3)); |
| 1944 | DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(3)); |
| 1945 | DUMPREG(DSI_VC_SHORT_PACKET_HEADER(3)); |
| 1946 | DUMPREG(DSI_VC_IRQSTATUS(3)); |
| 1947 | DUMPREG(DSI_VC_IRQENABLE(3)); |
| 1948 | |
| 1949 | DUMPREG(DSI_DSIPHY_CFG0); |
| 1950 | DUMPREG(DSI_DSIPHY_CFG1); |
| 1951 | DUMPREG(DSI_DSIPHY_CFG2); |
| 1952 | DUMPREG(DSI_DSIPHY_CFG5); |
| 1953 | |
| 1954 | DUMPREG(DSI_PLL_CONTROL); |
| 1955 | DUMPREG(DSI_PLL_STATUS); |
| 1956 | DUMPREG(DSI_PLL_GO); |
| 1957 | DUMPREG(DSI_PLL_CONFIGURATION1); |
| 1958 | DUMPREG(DSI_PLL_CONFIGURATION2); |
| 1959 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1960 | dsi_disable_scp_clk(dsidev); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1961 | dsi_runtime_put(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1962 | #undef DUMPREG |
| 1963 | } |
| 1964 | |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 1965 | static void dsi1_dump_regs(struct seq_file *s) |
| 1966 | { |
| 1967 | struct platform_device *dsidev = dsi_get_dsidev_from_id(0); |
| 1968 | |
| 1969 | dsi_dump_dsidev_regs(dsidev, s); |
| 1970 | } |
| 1971 | |
| 1972 | static void dsi2_dump_regs(struct seq_file *s) |
| 1973 | { |
| 1974 | struct platform_device *dsidev = dsi_get_dsidev_from_id(1); |
| 1975 | |
| 1976 | dsi_dump_dsidev_regs(dsidev, s); |
| 1977 | } |
| 1978 | |
Tomi Valkeinen | cc5c185 | 2010-10-06 15:18:13 +0300 | [diff] [blame] | 1979 | enum dsi_cio_power_state { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1980 | DSI_COMPLEXIO_POWER_OFF = 0x0, |
| 1981 | DSI_COMPLEXIO_POWER_ON = 0x1, |
| 1982 | DSI_COMPLEXIO_POWER_ULPS = 0x2, |
| 1983 | }; |
| 1984 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1985 | static int dsi_cio_power(struct platform_device *dsidev, |
| 1986 | enum dsi_cio_power_state state) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1987 | { |
| 1988 | int t = 0; |
| 1989 | |
| 1990 | /* PWR_CMD */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1991 | REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG1, state, 28, 27); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1992 | |
| 1993 | /* PWR_STATUS */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1994 | while (FLD_GET(dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1), |
| 1995 | 26, 25) != state) { |
Tomi Valkeinen | 24be78b | 2010-01-07 14:19:48 +0200 | [diff] [blame] | 1996 | if (++t > 1000) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1997 | DSSERR("failed to set complexio power state to " |
| 1998 | "%d\n", state); |
| 1999 | return -ENODEV; |
| 2000 | } |
Tomi Valkeinen | 24be78b | 2010-01-07 14:19:48 +0200 | [diff] [blame] | 2001 | udelay(1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2002 | } |
| 2003 | |
| 2004 | return 0; |
| 2005 | } |
| 2006 | |
Archit Taneja | 0c65622 | 2011-05-16 15:17:09 +0530 | [diff] [blame] | 2007 | static unsigned dsi_get_line_buf_size(struct platform_device *dsidev) |
| 2008 | { |
| 2009 | int val; |
| 2010 | |
| 2011 | /* line buffer on OMAP3 is 1024 x 24bits */ |
| 2012 | /* XXX: for some reason using full buffer size causes |
| 2013 | * considerable TX slowdown with update sizes that fill the |
| 2014 | * whole buffer */ |
| 2015 | if (!dss_has_feature(FEAT_DSI_GNQ)) |
| 2016 | return 1023 * 3; |
| 2017 | |
| 2018 | val = REG_GET(dsidev, DSI_GNQ, 14, 12); /* VP1_LINE_BUFFER_SIZE */ |
| 2019 | |
| 2020 | switch (val) { |
| 2021 | case 1: |
| 2022 | return 512 * 3; /* 512x24 bits */ |
| 2023 | case 2: |
| 2024 | return 682 * 3; /* 682x24 bits */ |
| 2025 | case 3: |
| 2026 | return 853 * 3; /* 853x24 bits */ |
| 2027 | case 4: |
| 2028 | return 1024 * 3; /* 1024x24 bits */ |
| 2029 | case 5: |
| 2030 | return 1194 * 3; /* 1194x24 bits */ |
| 2031 | case 6: |
| 2032 | return 1365 * 3; /* 1365x24 bits */ |
Tomi Valkeinen | 2ac80fb | 2012-08-22 16:00:47 +0300 | [diff] [blame] | 2033 | case 7: |
| 2034 | return 1920 * 3; /* 1920x24 bits */ |
Archit Taneja | 0c65622 | 2011-05-16 15:17:09 +0530 | [diff] [blame] | 2035 | default: |
| 2036 | BUG(); |
Tomi Valkeinen | c6eee96 | 2012-05-18 11:47:02 +0300 | [diff] [blame] | 2037 | return 0; |
Archit Taneja | 0c65622 | 2011-05-16 15:17:09 +0530 | [diff] [blame] | 2038 | } |
| 2039 | } |
| 2040 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 2041 | static int dsi_set_lane_config(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2042 | { |
Tomi Valkeinen | 4836839 | 2011-10-13 11:22:39 +0300 | [diff] [blame] | 2043 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 2044 | static const u8 offsets[] = { 0, 4, 8, 12, 16 }; |
| 2045 | static const enum dsi_lane_function functions[] = { |
| 2046 | DSI_LANE_CLK, |
| 2047 | DSI_LANE_DATA1, |
| 2048 | DSI_LANE_DATA2, |
| 2049 | DSI_LANE_DATA3, |
| 2050 | DSI_LANE_DATA4, |
| 2051 | }; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2052 | u32 r; |
Tomi Valkeinen | 4836839 | 2011-10-13 11:22:39 +0300 | [diff] [blame] | 2053 | int i; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2054 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2055 | r = dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1); |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 2056 | |
Tomi Valkeinen | 4836839 | 2011-10-13 11:22:39 +0300 | [diff] [blame] | 2057 | for (i = 0; i < dsi->num_lanes_used; ++i) { |
| 2058 | unsigned offset = offsets[i]; |
| 2059 | unsigned polarity, lane_number; |
| 2060 | unsigned t; |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 2061 | |
Tomi Valkeinen | 4836839 | 2011-10-13 11:22:39 +0300 | [diff] [blame] | 2062 | for (t = 0; t < dsi->num_lanes_supported; ++t) |
| 2063 | if (dsi->lanes[t].function == functions[i]) |
| 2064 | break; |
| 2065 | |
| 2066 | if (t == dsi->num_lanes_supported) |
| 2067 | return -EINVAL; |
| 2068 | |
| 2069 | lane_number = t; |
| 2070 | polarity = dsi->lanes[t].polarity; |
| 2071 | |
| 2072 | r = FLD_MOD(r, lane_number + 1, offset + 2, offset); |
| 2073 | r = FLD_MOD(r, polarity, offset + 3, offset + 3); |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 2074 | } |
Tomi Valkeinen | 4836839 | 2011-10-13 11:22:39 +0300 | [diff] [blame] | 2075 | |
| 2076 | /* clear the unused lanes */ |
| 2077 | for (; i < dsi->num_lanes_supported; ++i) { |
| 2078 | unsigned offset = offsets[i]; |
| 2079 | |
| 2080 | r = FLD_MOD(r, 0, offset + 2, offset); |
| 2081 | r = FLD_MOD(r, 0, offset + 3, offset + 3); |
| 2082 | } |
| 2083 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2084 | dsi_write_reg(dsidev, DSI_COMPLEXIO_CFG1, r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2085 | |
Tomi Valkeinen | 4836839 | 2011-10-13 11:22:39 +0300 | [diff] [blame] | 2086 | return 0; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2087 | } |
| 2088 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2089 | static inline unsigned ns2ddr(struct platform_device *dsidev, unsigned ns) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2090 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2091 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 2092 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2093 | /* convert time in ns to ddr ticks, rounding up */ |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2094 | unsigned long ddr_clk = dsi->current_cinfo.clkin4ddr / 4; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2095 | return (ns * (ddr_clk / 1000 / 1000) + 999) / 1000; |
| 2096 | } |
| 2097 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2098 | static inline unsigned ddr2ns(struct platform_device *dsidev, unsigned ddr) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2099 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2100 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 2101 | |
| 2102 | unsigned long ddr_clk = dsi->current_cinfo.clkin4ddr / 4; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2103 | return ddr * 1000 * 1000 / (ddr_clk / 1000); |
| 2104 | } |
| 2105 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2106 | static void dsi_cio_timings(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2107 | { |
| 2108 | u32 r; |
| 2109 | u32 ths_prepare, ths_prepare_ths_zero, ths_trail, ths_exit; |
| 2110 | u32 tlpx_half, tclk_trail, tclk_zero; |
| 2111 | u32 tclk_prepare; |
| 2112 | |
| 2113 | /* calculate timings */ |
| 2114 | |
| 2115 | /* 1 * DDR_CLK = 2 * UI */ |
| 2116 | |
| 2117 | /* min 40ns + 4*UI max 85ns + 6*UI */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2118 | ths_prepare = ns2ddr(dsidev, 70) + 2; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2119 | |
| 2120 | /* min 145ns + 10*UI */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2121 | ths_prepare_ths_zero = ns2ddr(dsidev, 175) + 2; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2122 | |
| 2123 | /* min max(8*UI, 60ns+4*UI) */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2124 | ths_trail = ns2ddr(dsidev, 60) + 5; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2125 | |
| 2126 | /* min 100ns */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2127 | ths_exit = ns2ddr(dsidev, 145); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2128 | |
| 2129 | /* tlpx min 50n */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2130 | tlpx_half = ns2ddr(dsidev, 25); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2131 | |
| 2132 | /* min 60ns */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2133 | tclk_trail = ns2ddr(dsidev, 60) + 2; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2134 | |
| 2135 | /* min 38ns, max 95ns */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2136 | tclk_prepare = ns2ddr(dsidev, 65); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2137 | |
| 2138 | /* min tclk-prepare + tclk-zero = 300ns */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2139 | tclk_zero = ns2ddr(dsidev, 260); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2140 | |
| 2141 | DSSDBG("ths_prepare %u (%uns), ths_prepare_ths_zero %u (%uns)\n", |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2142 | ths_prepare, ddr2ns(dsidev, ths_prepare), |
| 2143 | ths_prepare_ths_zero, ddr2ns(dsidev, ths_prepare_ths_zero)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2144 | DSSDBG("ths_trail %u (%uns), ths_exit %u (%uns)\n", |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2145 | ths_trail, ddr2ns(dsidev, ths_trail), |
| 2146 | ths_exit, ddr2ns(dsidev, ths_exit)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2147 | |
| 2148 | DSSDBG("tlpx_half %u (%uns), tclk_trail %u (%uns), " |
| 2149 | "tclk_zero %u (%uns)\n", |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2150 | tlpx_half, ddr2ns(dsidev, tlpx_half), |
| 2151 | tclk_trail, ddr2ns(dsidev, tclk_trail), |
| 2152 | tclk_zero, ddr2ns(dsidev, tclk_zero)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2153 | DSSDBG("tclk_prepare %u (%uns)\n", |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2154 | tclk_prepare, ddr2ns(dsidev, tclk_prepare)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2155 | |
| 2156 | /* program timings */ |
| 2157 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2158 | r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2159 | r = FLD_MOD(r, ths_prepare, 31, 24); |
| 2160 | r = FLD_MOD(r, ths_prepare_ths_zero, 23, 16); |
| 2161 | r = FLD_MOD(r, ths_trail, 15, 8); |
| 2162 | r = FLD_MOD(r, ths_exit, 7, 0); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2163 | dsi_write_reg(dsidev, DSI_DSIPHY_CFG0, r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2164 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2165 | r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1); |
Tomi Valkeinen | e84dc1c | 2012-09-24 09:34:52 +0300 | [diff] [blame] | 2166 | r = FLD_MOD(r, tlpx_half, 20, 16); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2167 | r = FLD_MOD(r, tclk_trail, 15, 8); |
| 2168 | r = FLD_MOD(r, tclk_zero, 7, 0); |
Tomi Valkeinen | 77ccbfb | 2012-09-24 15:15:57 +0300 | [diff] [blame] | 2169 | |
| 2170 | if (dss_has_feature(FEAT_DSI_PHY_DCC)) { |
| 2171 | r = FLD_MOD(r, 0, 21, 21); /* DCCEN = disable */ |
| 2172 | r = FLD_MOD(r, 1, 22, 22); /* CLKINP_DIVBY2EN = enable */ |
| 2173 | r = FLD_MOD(r, 1, 23, 23); /* CLKINP_SEL = enable */ |
| 2174 | } |
| 2175 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2176 | dsi_write_reg(dsidev, DSI_DSIPHY_CFG1, r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2177 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2178 | r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG2); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2179 | r = FLD_MOD(r, tclk_prepare, 7, 0); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2180 | dsi_write_reg(dsidev, DSI_DSIPHY_CFG2, r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2181 | } |
| 2182 | |
Tomi Valkeinen | 9b4362f | 2011-10-13 16:06:43 +0300 | [diff] [blame] | 2183 | /* lane masks have lane 0 at lsb. mask_p for positive lines, n for negative */ |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 2184 | static void dsi_cio_enable_lane_override(struct platform_device *dsidev, |
Tomi Valkeinen | 9b4362f | 2011-10-13 16:06:43 +0300 | [diff] [blame] | 2185 | unsigned mask_p, unsigned mask_n) |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2186 | { |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 2187 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 9b4362f | 2011-10-13 16:06:43 +0300 | [diff] [blame] | 2188 | int i; |
| 2189 | u32 l; |
Tomi Valkeinen | d982085 | 2011-10-12 15:05:59 +0300 | [diff] [blame] | 2190 | u8 lptxscp_start = dsi->num_lanes_supported == 3 ? 22 : 26; |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2191 | |
Tomi Valkeinen | 9b4362f | 2011-10-13 16:06:43 +0300 | [diff] [blame] | 2192 | l = 0; |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2193 | |
Tomi Valkeinen | 9b4362f | 2011-10-13 16:06:43 +0300 | [diff] [blame] | 2194 | for (i = 0; i < dsi->num_lanes_supported; ++i) { |
| 2195 | unsigned p = dsi->lanes[i].polarity; |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2196 | |
Tomi Valkeinen | 9b4362f | 2011-10-13 16:06:43 +0300 | [diff] [blame] | 2197 | if (mask_p & (1 << i)) |
| 2198 | l |= 1 << (i * 2 + (p ? 0 : 1)); |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2199 | |
Tomi Valkeinen | 9b4362f | 2011-10-13 16:06:43 +0300 | [diff] [blame] | 2200 | if (mask_n & (1 << i)) |
| 2201 | l |= 1 << (i * 2 + (p ? 1 : 0)); |
| 2202 | } |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2203 | |
| 2204 | /* |
| 2205 | * Bits in REGLPTXSCPDAT4TO0DXDY: |
| 2206 | * 17: DY0 18: DX0 |
| 2207 | * 19: DY1 20: DX1 |
| 2208 | * 21: DY2 22: DX2 |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 2209 | * 23: DY3 24: DX3 |
| 2210 | * 25: DY4 26: DX4 |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2211 | */ |
| 2212 | |
| 2213 | /* Set the lane override configuration */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2214 | |
| 2215 | /* REGLPTXSCPDAT4TO0DXDY */ |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 2216 | REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, l, lptxscp_start, 17); |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2217 | |
| 2218 | /* Enable lane override */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2219 | |
| 2220 | /* ENLPTXSCPDAT */ |
| 2221 | REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 1, 27, 27); |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2222 | } |
| 2223 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2224 | static void dsi_cio_disable_lane_override(struct platform_device *dsidev) |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2225 | { |
| 2226 | /* Disable lane override */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2227 | REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 0, 27, 27); /* ENLPTXSCPDAT */ |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2228 | /* Reset the lane override configuration */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2229 | /* REGLPTXSCPDAT4TO0DXDY */ |
| 2230 | REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 0, 22, 17); |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2231 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2232 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 2233 | static int dsi_cio_wait_tx_clk_esc_reset(struct platform_device *dsidev) |
Tomi Valkeinen | 03329ac | 2010-10-07 13:59:22 +0300 | [diff] [blame] | 2234 | { |
Tomi Valkeinen | 8dc0766 | 2011-10-13 15:26:50 +0300 | [diff] [blame] | 2235 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 2236 | int t, i; |
| 2237 | bool in_use[DSI_MAX_NR_LANES]; |
| 2238 | static const u8 offsets_old[] = { 28, 27, 26 }; |
| 2239 | static const u8 offsets_new[] = { 24, 25, 26, 27, 28 }; |
| 2240 | const u8 *offsets; |
Tomi Valkeinen | 03329ac | 2010-10-07 13:59:22 +0300 | [diff] [blame] | 2241 | |
Tomi Valkeinen | 8dc0766 | 2011-10-13 15:26:50 +0300 | [diff] [blame] | 2242 | if (dss_has_feature(FEAT_DSI_REVERSE_TXCLKESC)) |
| 2243 | offsets = offsets_old; |
| 2244 | else |
| 2245 | offsets = offsets_new; |
Tomi Valkeinen | 03329ac | 2010-10-07 13:59:22 +0300 | [diff] [blame] | 2246 | |
Tomi Valkeinen | 8dc0766 | 2011-10-13 15:26:50 +0300 | [diff] [blame] | 2247 | for (i = 0; i < dsi->num_lanes_supported; ++i) |
| 2248 | in_use[i] = dsi->lanes[i].function != DSI_LANE_UNUSED; |
Tomi Valkeinen | 03329ac | 2010-10-07 13:59:22 +0300 | [diff] [blame] | 2249 | |
| 2250 | t = 100000; |
| 2251 | while (true) { |
| 2252 | u32 l; |
Tomi Valkeinen | 03329ac | 2010-10-07 13:59:22 +0300 | [diff] [blame] | 2253 | int ok; |
| 2254 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2255 | l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5); |
Tomi Valkeinen | 03329ac | 2010-10-07 13:59:22 +0300 | [diff] [blame] | 2256 | |
| 2257 | ok = 0; |
Tomi Valkeinen | 8dc0766 | 2011-10-13 15:26:50 +0300 | [diff] [blame] | 2258 | for (i = 0; i < dsi->num_lanes_supported; ++i) { |
| 2259 | if (!in_use[i] || (l & (1 << offsets[i]))) |
Tomi Valkeinen | 03329ac | 2010-10-07 13:59:22 +0300 | [diff] [blame] | 2260 | ok++; |
| 2261 | } |
| 2262 | |
Tomi Valkeinen | 8dc0766 | 2011-10-13 15:26:50 +0300 | [diff] [blame] | 2263 | if (ok == dsi->num_lanes_supported) |
Tomi Valkeinen | 03329ac | 2010-10-07 13:59:22 +0300 | [diff] [blame] | 2264 | break; |
| 2265 | |
| 2266 | if (--t == 0) { |
Tomi Valkeinen | 8dc0766 | 2011-10-13 15:26:50 +0300 | [diff] [blame] | 2267 | for (i = 0; i < dsi->num_lanes_supported; ++i) { |
| 2268 | if (!in_use[i] || (l & (1 << offsets[i]))) |
Tomi Valkeinen | 03329ac | 2010-10-07 13:59:22 +0300 | [diff] [blame] | 2269 | continue; |
| 2270 | |
| 2271 | DSSERR("CIO TXCLKESC%d domain not coming " \ |
| 2272 | "out of reset\n", i); |
| 2273 | } |
| 2274 | return -EIO; |
| 2275 | } |
| 2276 | } |
| 2277 | |
| 2278 | return 0; |
| 2279 | } |
| 2280 | |
Tomi Valkeinen | 85f17e8 | 2011-10-13 15:12:23 +0300 | [diff] [blame] | 2281 | /* return bitmask of enabled lanes, lane0 being the lsb */ |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 2282 | static unsigned dsi_get_lane_mask(struct platform_device *dsidev) |
Tomi Valkeinen | 5bc416c | 2011-06-15 15:21:12 +0300 | [diff] [blame] | 2283 | { |
Tomi Valkeinen | 85f17e8 | 2011-10-13 15:12:23 +0300 | [diff] [blame] | 2284 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 2285 | unsigned mask = 0; |
| 2286 | int i; |
Tomi Valkeinen | 5bc416c | 2011-06-15 15:21:12 +0300 | [diff] [blame] | 2287 | |
Tomi Valkeinen | 85f17e8 | 2011-10-13 15:12:23 +0300 | [diff] [blame] | 2288 | for (i = 0; i < dsi->num_lanes_supported; ++i) { |
| 2289 | if (dsi->lanes[i].function != DSI_LANE_UNUSED) |
| 2290 | mask |= 1 << i; |
| 2291 | } |
Tomi Valkeinen | 5bc416c | 2011-06-15 15:21:12 +0300 | [diff] [blame] | 2292 | |
Tomi Valkeinen | 85f17e8 | 2011-10-13 15:12:23 +0300 | [diff] [blame] | 2293 | return mask; |
Tomi Valkeinen | 5bc416c | 2011-06-15 15:21:12 +0300 | [diff] [blame] | 2294 | } |
| 2295 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 2296 | static int dsi_cio_init(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2297 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2298 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 65c62bb | 2011-04-15 11:58:41 +0300 | [diff] [blame] | 2299 | int r; |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 2300 | u32 l; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2301 | |
Chandrabhanu Mahapatra | 702d267 | 2012-09-24 17:12:58 +0530 | [diff] [blame] | 2302 | DSSDBG("DSI CIO init starts"); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2303 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 2304 | r = dss_dsi_enable_pads(dsi->module_id, dsi_get_lane_mask(dsidev)); |
Tomi Valkeinen | 5bc416c | 2011-06-15 15:21:12 +0300 | [diff] [blame] | 2305 | if (r) |
| 2306 | return r; |
Tomi Valkeinen | d1f5857 | 2010-07-30 11:57:57 +0300 | [diff] [blame] | 2307 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2308 | dsi_enable_scp_clk(dsidev); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 2309 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2310 | /* A dummy read using the SCP interface to any DSIPHY register is |
| 2311 | * required after DSIPHY reset to complete the reset of the DSI complex |
| 2312 | * I/O. */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2313 | dsi_read_reg(dsidev, DSI_DSIPHY_CFG5); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2314 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2315 | if (wait_for_bit_change(dsidev, DSI_DSIPHY_CFG5, 30, 1) != 1) { |
Tomi Valkeinen | 65c62bb | 2011-04-15 11:58:41 +0300 | [diff] [blame] | 2316 | DSSERR("CIO SCP Clock domain not coming out of reset.\n"); |
| 2317 | r = -EIO; |
| 2318 | goto err_scp_clk_dom; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2319 | } |
| 2320 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 2321 | r = dsi_set_lane_config(dsidev); |
Tomi Valkeinen | 4836839 | 2011-10-13 11:22:39 +0300 | [diff] [blame] | 2322 | if (r) |
| 2323 | goto err_scp_clk_dom; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2324 | |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 2325 | /* set TX STOP MODE timer to maximum for this operation */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2326 | l = dsi_read_reg(dsidev, DSI_TIMING1); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 2327 | l = FLD_MOD(l, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */ |
| 2328 | l = FLD_MOD(l, 1, 14, 14); /* STOP_STATE_X16_IO */ |
| 2329 | l = FLD_MOD(l, 1, 13, 13); /* STOP_STATE_X4_IO */ |
| 2330 | l = FLD_MOD(l, 0x1fff, 12, 0); /* STOP_STATE_COUNTER_IO */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2331 | dsi_write_reg(dsidev, DSI_TIMING1, l); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 2332 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2333 | if (dsi->ulps_enabled) { |
Tomi Valkeinen | 9b4362f | 2011-10-13 16:06:43 +0300 | [diff] [blame] | 2334 | unsigned mask_p; |
| 2335 | int i; |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 2336 | |
Tomi Valkeinen | 65c62bb | 2011-04-15 11:58:41 +0300 | [diff] [blame] | 2337 | DSSDBG("manual ulps exit\n"); |
| 2338 | |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 2339 | /* ULPS is exited by Mark-1 state for 1ms, followed by |
| 2340 | * stop state. DSS HW cannot do this via the normal |
| 2341 | * ULPS exit sequence, as after reset the DSS HW thinks |
| 2342 | * that we are not in ULPS mode, and refuses to send the |
| 2343 | * sequence. So we need to send the ULPS exit sequence |
Tomi Valkeinen | 9b4362f | 2011-10-13 16:06:43 +0300 | [diff] [blame] | 2344 | * manually by setting positive lines high and negative lines |
| 2345 | * low for 1ms. |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 2346 | */ |
| 2347 | |
Tomi Valkeinen | 9b4362f | 2011-10-13 16:06:43 +0300 | [diff] [blame] | 2348 | mask_p = 0; |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 2349 | |
Tomi Valkeinen | 9b4362f | 2011-10-13 16:06:43 +0300 | [diff] [blame] | 2350 | for (i = 0; i < dsi->num_lanes_supported; ++i) { |
| 2351 | if (dsi->lanes[i].function == DSI_LANE_UNUSED) |
| 2352 | continue; |
| 2353 | mask_p |= 1 << i; |
| 2354 | } |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 2355 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 2356 | dsi_cio_enable_lane_override(dsidev, mask_p, 0); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 2357 | } |
| 2358 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2359 | r = dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_ON); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2360 | if (r) |
Tomi Valkeinen | 65c62bb | 2011-04-15 11:58:41 +0300 | [diff] [blame] | 2361 | goto err_cio_pwr; |
| 2362 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2363 | if (wait_for_bit_change(dsidev, DSI_COMPLEXIO_CFG1, 29, 1) != 1) { |
Tomi Valkeinen | 65c62bb | 2011-04-15 11:58:41 +0300 | [diff] [blame] | 2364 | DSSERR("CIO PWR clock domain not coming out of reset.\n"); |
| 2365 | r = -ENODEV; |
| 2366 | goto err_cio_pwr_dom; |
| 2367 | } |
| 2368 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2369 | dsi_if_enable(dsidev, true); |
| 2370 | dsi_if_enable(dsidev, false); |
| 2371 | REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 20, 20); /* LP_CLK_ENABLE */ |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2372 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 2373 | r = dsi_cio_wait_tx_clk_esc_reset(dsidev); |
Tomi Valkeinen | 03329ac | 2010-10-07 13:59:22 +0300 | [diff] [blame] | 2374 | if (r) |
| 2375 | goto err_tx_clk_esc_rst; |
| 2376 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2377 | if (dsi->ulps_enabled) { |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 2378 | /* Keep Mark-1 state for 1ms (as per DSI spec) */ |
| 2379 | ktime_t wait = ns_to_ktime(1000 * 1000); |
| 2380 | set_current_state(TASK_UNINTERRUPTIBLE); |
| 2381 | schedule_hrtimeout(&wait, HRTIMER_MODE_REL); |
| 2382 | |
| 2383 | /* Disable the override. The lanes should be set to Mark-11 |
| 2384 | * state by the HW */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2385 | dsi_cio_disable_lane_override(dsidev); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 2386 | } |
| 2387 | |
| 2388 | /* FORCE_TX_STOP_MODE_IO */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2389 | REG_FLD_MOD(dsidev, DSI_TIMING1, 0, 15, 15); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 2390 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2391 | dsi_cio_timings(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2392 | |
Archit Taneja | dca2b15 | 2012-08-16 18:02:00 +0530 | [diff] [blame] | 2393 | if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) { |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 2394 | /* DDR_CLK_ALWAYS_ON */ |
| 2395 | REG_FLD_MOD(dsidev, DSI_CLK_CTRL, |
Archit Taneja | 0b3ffe3 | 2012-08-13 22:13:39 +0530 | [diff] [blame] | 2396 | dsi->vm_timings.ddr_clk_always_on, 13, 13); |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 2397 | } |
| 2398 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2399 | dsi->ulps_enabled = false; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2400 | |
| 2401 | DSSDBG("CIO init done\n"); |
Tomi Valkeinen | 65c62bb | 2011-04-15 11:58:41 +0300 | [diff] [blame] | 2402 | |
| 2403 | return 0; |
| 2404 | |
Tomi Valkeinen | 03329ac | 2010-10-07 13:59:22 +0300 | [diff] [blame] | 2405 | err_tx_clk_esc_rst: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2406 | REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 20, 20); /* LP_CLK_ENABLE */ |
Tomi Valkeinen | 65c62bb | 2011-04-15 11:58:41 +0300 | [diff] [blame] | 2407 | err_cio_pwr_dom: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2408 | dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF); |
Tomi Valkeinen | 65c62bb | 2011-04-15 11:58:41 +0300 | [diff] [blame] | 2409 | err_cio_pwr: |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2410 | if (dsi->ulps_enabled) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2411 | dsi_cio_disable_lane_override(dsidev); |
Tomi Valkeinen | 65c62bb | 2011-04-15 11:58:41 +0300 | [diff] [blame] | 2412 | err_scp_clk_dom: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2413 | dsi_disable_scp_clk(dsidev); |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 2414 | dss_dsi_disable_pads(dsi->module_id, dsi_get_lane_mask(dsidev)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2415 | return r; |
| 2416 | } |
| 2417 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 2418 | static void dsi_cio_uninit(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2419 | { |
Tomi Valkeinen | 11ee960 | 2012-03-09 16:07:39 +0200 | [diff] [blame] | 2420 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2421 | |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 2422 | /* DDR_CLK_ALWAYS_ON */ |
| 2423 | REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 13, 13); |
| 2424 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2425 | dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF); |
| 2426 | dsi_disable_scp_clk(dsidev); |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 2427 | dss_dsi_disable_pads(dsi->module_id, dsi_get_lane_mask(dsidev)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2428 | } |
| 2429 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2430 | static void dsi_config_tx_fifo(struct platform_device *dsidev, |
| 2431 | enum fifo_size size1, enum fifo_size size2, |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2432 | enum fifo_size size3, enum fifo_size size4) |
| 2433 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2434 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2435 | u32 r = 0; |
| 2436 | int add = 0; |
| 2437 | int i; |
| 2438 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2439 | dsi->vc[0].fifo_size = size1; |
| 2440 | dsi->vc[1].fifo_size = size2; |
| 2441 | dsi->vc[2].fifo_size = size3; |
| 2442 | dsi->vc[3].fifo_size = size4; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2443 | |
| 2444 | for (i = 0; i < 4; i++) { |
| 2445 | u8 v; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2446 | int size = dsi->vc[i].fifo_size; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2447 | |
| 2448 | if (add + size > 4) { |
| 2449 | DSSERR("Illegal FIFO configuration\n"); |
| 2450 | BUG(); |
Tomi Valkeinen | c6eee96 | 2012-05-18 11:47:02 +0300 | [diff] [blame] | 2451 | return; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2452 | } |
| 2453 | |
| 2454 | v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4); |
| 2455 | r |= v << (8 * i); |
| 2456 | /*DSSDBG("TX FIFO vc %d: size %d, add %d\n", i, size, add); */ |
| 2457 | add += size; |
| 2458 | } |
| 2459 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2460 | dsi_write_reg(dsidev, DSI_TX_FIFO_VC_SIZE, r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2461 | } |
| 2462 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2463 | static void dsi_config_rx_fifo(struct platform_device *dsidev, |
| 2464 | enum fifo_size size1, enum fifo_size size2, |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2465 | enum fifo_size size3, enum fifo_size size4) |
| 2466 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2467 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2468 | u32 r = 0; |
| 2469 | int add = 0; |
| 2470 | int i; |
| 2471 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2472 | dsi->vc[0].fifo_size = size1; |
| 2473 | dsi->vc[1].fifo_size = size2; |
| 2474 | dsi->vc[2].fifo_size = size3; |
| 2475 | dsi->vc[3].fifo_size = size4; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2476 | |
| 2477 | for (i = 0; i < 4; i++) { |
| 2478 | u8 v; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2479 | int size = dsi->vc[i].fifo_size; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2480 | |
| 2481 | if (add + size > 4) { |
| 2482 | DSSERR("Illegal FIFO configuration\n"); |
| 2483 | BUG(); |
Tomi Valkeinen | c6eee96 | 2012-05-18 11:47:02 +0300 | [diff] [blame] | 2484 | return; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2485 | } |
| 2486 | |
| 2487 | v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4); |
| 2488 | r |= v << (8 * i); |
| 2489 | /*DSSDBG("RX FIFO vc %d: size %d, add %d\n", i, size, add); */ |
| 2490 | add += size; |
| 2491 | } |
| 2492 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2493 | dsi_write_reg(dsidev, DSI_RX_FIFO_VC_SIZE, r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2494 | } |
| 2495 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2496 | static int dsi_force_tx_stop_mode_io(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2497 | { |
| 2498 | u32 r; |
| 2499 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2500 | r = dsi_read_reg(dsidev, DSI_TIMING1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2501 | r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2502 | dsi_write_reg(dsidev, DSI_TIMING1, r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2503 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2504 | if (wait_for_bit_change(dsidev, DSI_TIMING1, 15, 0) != 0) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2505 | DSSERR("TX_STOP bit not going down\n"); |
| 2506 | return -EIO; |
| 2507 | } |
| 2508 | |
| 2509 | return 0; |
| 2510 | } |
| 2511 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2512 | static bool dsi_vc_is_enabled(struct platform_device *dsidev, int channel) |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2513 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2514 | return REG_GET(dsidev, DSI_VC_CTRL(channel), 0, 0); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2515 | } |
| 2516 | |
| 2517 | static void dsi_packet_sent_handler_vp(void *data, u32 mask) |
| 2518 | { |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2519 | struct dsi_packet_sent_handler_data *vp_data = |
| 2520 | (struct dsi_packet_sent_handler_data *) data; |
| 2521 | struct dsi_data *dsi = dsi_get_dsidrv_data(vp_data->dsidev); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2522 | const int channel = dsi->update_channel; |
| 2523 | u8 bit = dsi->te_enabled ? 30 : 31; |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2524 | |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2525 | if (REG_GET(vp_data->dsidev, DSI_VC_TE(channel), bit, bit) == 0) |
| 2526 | complete(vp_data->completion); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2527 | } |
| 2528 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2529 | static int dsi_sync_vc_vp(struct platform_device *dsidev, int channel) |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2530 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2531 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2532 | DECLARE_COMPLETION_ONSTACK(completion); |
| 2533 | struct dsi_packet_sent_handler_data vp_data = { dsidev, &completion }; |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2534 | int r = 0; |
| 2535 | u8 bit; |
| 2536 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2537 | bit = dsi->te_enabled ? 30 : 31; |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2538 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2539 | r = dsi_register_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp, |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2540 | &vp_data, DSI_VC_IRQ_PACKET_SENT); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2541 | if (r) |
| 2542 | goto err0; |
| 2543 | |
| 2544 | /* Wait for completion only if TE_EN/TE_START is still set */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2545 | if (REG_GET(dsidev, DSI_VC_TE(channel), bit, bit)) { |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2546 | if (wait_for_completion_timeout(&completion, |
| 2547 | msecs_to_jiffies(10)) == 0) { |
| 2548 | DSSERR("Failed to complete previous frame transfer\n"); |
| 2549 | r = -EIO; |
| 2550 | goto err1; |
| 2551 | } |
| 2552 | } |
| 2553 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2554 | dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp, |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2555 | &vp_data, DSI_VC_IRQ_PACKET_SENT); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2556 | |
| 2557 | return 0; |
| 2558 | err1: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2559 | dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp, |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2560 | &vp_data, DSI_VC_IRQ_PACKET_SENT); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2561 | err0: |
| 2562 | return r; |
| 2563 | } |
| 2564 | |
| 2565 | static void dsi_packet_sent_handler_l4(void *data, u32 mask) |
| 2566 | { |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2567 | struct dsi_packet_sent_handler_data *l4_data = |
| 2568 | (struct dsi_packet_sent_handler_data *) data; |
| 2569 | struct dsi_data *dsi = dsi_get_dsidrv_data(l4_data->dsidev); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2570 | const int channel = dsi->update_channel; |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2571 | |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2572 | if (REG_GET(l4_data->dsidev, DSI_VC_CTRL(channel), 5, 5) == 0) |
| 2573 | complete(l4_data->completion); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2574 | } |
| 2575 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2576 | static int dsi_sync_vc_l4(struct platform_device *dsidev, int channel) |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2577 | { |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2578 | DECLARE_COMPLETION_ONSTACK(completion); |
| 2579 | struct dsi_packet_sent_handler_data l4_data = { dsidev, &completion }; |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2580 | int r = 0; |
| 2581 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2582 | r = dsi_register_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4, |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2583 | &l4_data, DSI_VC_IRQ_PACKET_SENT); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2584 | if (r) |
| 2585 | goto err0; |
| 2586 | |
| 2587 | /* Wait for completion only if TX_FIFO_NOT_EMPTY is still set */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2588 | if (REG_GET(dsidev, DSI_VC_CTRL(channel), 5, 5)) { |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2589 | if (wait_for_completion_timeout(&completion, |
| 2590 | msecs_to_jiffies(10)) == 0) { |
| 2591 | DSSERR("Failed to complete previous l4 transfer\n"); |
| 2592 | r = -EIO; |
| 2593 | goto err1; |
| 2594 | } |
| 2595 | } |
| 2596 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2597 | dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4, |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2598 | &l4_data, DSI_VC_IRQ_PACKET_SENT); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2599 | |
| 2600 | return 0; |
| 2601 | err1: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2602 | dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4, |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2603 | &l4_data, DSI_VC_IRQ_PACKET_SENT); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2604 | err0: |
| 2605 | return r; |
| 2606 | } |
| 2607 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2608 | static int dsi_sync_vc(struct platform_device *dsidev, int channel) |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2609 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2610 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 2611 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2612 | WARN_ON(!dsi_bus_is_locked(dsidev)); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2613 | |
| 2614 | WARN_ON(in_interrupt()); |
| 2615 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2616 | if (!dsi_vc_is_enabled(dsidev, channel)) |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2617 | return 0; |
| 2618 | |
Archit Taneja | d604914 | 2011-08-22 11:58:08 +0530 | [diff] [blame] | 2619 | switch (dsi->vc[channel].source) { |
| 2620 | case DSI_VC_SOURCE_VP: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2621 | return dsi_sync_vc_vp(dsidev, channel); |
Archit Taneja | d604914 | 2011-08-22 11:58:08 +0530 | [diff] [blame] | 2622 | case DSI_VC_SOURCE_L4: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2623 | return dsi_sync_vc_l4(dsidev, channel); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2624 | default: |
| 2625 | BUG(); |
Tomi Valkeinen | c6eee96 | 2012-05-18 11:47:02 +0300 | [diff] [blame] | 2626 | return -EINVAL; |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2627 | } |
| 2628 | } |
| 2629 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2630 | static int dsi_vc_enable(struct platform_device *dsidev, int channel, |
| 2631 | bool enable) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2632 | { |
Tomi Valkeinen | 446f7bf | 2010-01-11 16:12:31 +0200 | [diff] [blame] | 2633 | DSSDBG("dsi_vc_enable channel %d, enable %d\n", |
| 2634 | channel, enable); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2635 | |
| 2636 | enable = enable ? 1 : 0; |
| 2637 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2638 | REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 0, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2639 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2640 | if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel), |
| 2641 | 0, enable) != enable) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2642 | DSSERR("Failed to set dsi_vc_enable to %d\n", enable); |
| 2643 | return -EIO; |
| 2644 | } |
| 2645 | |
| 2646 | return 0; |
| 2647 | } |
| 2648 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2649 | static void dsi_vc_initial_config(struct platform_device *dsidev, int channel) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2650 | { |
Tomi Valkeinen | 2c1a3ea | 2013-02-22 13:42:59 +0200 | [diff] [blame] | 2651 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2652 | u32 r; |
| 2653 | |
Chandrabhanu Mahapatra | 702d267 | 2012-09-24 17:12:58 +0530 | [diff] [blame] | 2654 | DSSDBG("Initial config of virtual channel %d", channel); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2655 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2656 | r = dsi_read_reg(dsidev, DSI_VC_CTRL(channel)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2657 | |
| 2658 | if (FLD_GET(r, 15, 15)) /* VC_BUSY */ |
| 2659 | DSSERR("VC(%d) busy when trying to configure it!\n", |
| 2660 | channel); |
| 2661 | |
| 2662 | r = FLD_MOD(r, 0, 1, 1); /* SOURCE, 0 = L4 */ |
| 2663 | r = FLD_MOD(r, 0, 2, 2); /* BTA_SHORT_EN */ |
| 2664 | r = FLD_MOD(r, 0, 3, 3); /* BTA_LONG_EN */ |
| 2665 | r = FLD_MOD(r, 0, 4, 4); /* MODE, 0 = command */ |
| 2666 | r = FLD_MOD(r, 1, 7, 7); /* CS_TX_EN */ |
| 2667 | r = FLD_MOD(r, 1, 8, 8); /* ECC_TX_EN */ |
| 2668 | 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] | 2669 | if (dss_has_feature(FEAT_DSI_VC_OCP_WIDTH)) |
| 2670 | r = FLD_MOD(r, 3, 11, 10); /* OCP_WIDTH = 32 bit */ |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2671 | |
| 2672 | r = FLD_MOD(r, 4, 29, 27); /* DMA_RX_REQ_NB = no dma */ |
| 2673 | r = FLD_MOD(r, 4, 23, 21); /* DMA_TX_REQ_NB = no dma */ |
| 2674 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2675 | dsi_write_reg(dsidev, DSI_VC_CTRL(channel), r); |
Tomi Valkeinen | 2c1a3ea | 2013-02-22 13:42:59 +0200 | [diff] [blame] | 2676 | |
| 2677 | dsi->vc[channel].source = DSI_VC_SOURCE_L4; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2678 | } |
| 2679 | |
Archit Taneja | d604914 | 2011-08-22 11:58:08 +0530 | [diff] [blame] | 2680 | static int dsi_vc_config_source(struct platform_device *dsidev, int channel, |
| 2681 | enum dsi_vc_source source) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2682 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2683 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 2684 | |
Archit Taneja | d604914 | 2011-08-22 11:58:08 +0530 | [diff] [blame] | 2685 | if (dsi->vc[channel].source == source) |
Tomi Valkeinen | 9ecd968 | 2010-04-30 11:24:33 +0300 | [diff] [blame] | 2686 | return 0; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2687 | |
Chandrabhanu Mahapatra | 702d267 | 2012-09-24 17:12:58 +0530 | [diff] [blame] | 2688 | DSSDBG("Source config of virtual channel %d", channel); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2689 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2690 | dsi_sync_vc(dsidev, channel); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2691 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2692 | dsi_vc_enable(dsidev, channel, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2693 | |
Tomi Valkeinen | 9ecd968 | 2010-04-30 11:24:33 +0300 | [diff] [blame] | 2694 | /* VC_BUSY */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2695 | if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel), 15, 0) != 0) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2696 | DSSERR("vc(%d) busy when trying to config for VP\n", channel); |
Tomi Valkeinen | 9ecd968 | 2010-04-30 11:24:33 +0300 | [diff] [blame] | 2697 | return -EIO; |
| 2698 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2699 | |
Archit Taneja | d604914 | 2011-08-22 11:58:08 +0530 | [diff] [blame] | 2700 | /* SOURCE, 0 = L4, 1 = video port */ |
| 2701 | REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), source, 1, 1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2702 | |
Archit Taneja | 9613c02 | 2011-03-22 06:33:36 -0500 | [diff] [blame] | 2703 | /* DCS_CMD_ENABLE */ |
Archit Taneja | d604914 | 2011-08-22 11:58:08 +0530 | [diff] [blame] | 2704 | if (dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC)) { |
| 2705 | bool enable = source == DSI_VC_SOURCE_VP; |
| 2706 | REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 30, 30); |
| 2707 | } |
Archit Taneja | 9613c02 | 2011-03-22 06:33:36 -0500 | [diff] [blame] | 2708 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2709 | dsi_vc_enable(dsidev, channel, 1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2710 | |
Archit Taneja | d604914 | 2011-08-22 11:58:08 +0530 | [diff] [blame] | 2711 | dsi->vc[channel].source = source; |
Tomi Valkeinen | 9ecd968 | 2010-04-30 11:24:33 +0300 | [diff] [blame] | 2712 | |
| 2713 | return 0; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2714 | } |
| 2715 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 2716 | void omapdss_dsi_vc_enable_hs(struct omap_dss_device *dssdev, int channel, |
| 2717 | bool enable) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2718 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2719 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Archit Taneja | 0b3ffe3 | 2012-08-13 22:13:39 +0530 | [diff] [blame] | 2720 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2721 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2722 | DSSDBG("dsi_vc_enable_hs(%d, %d)\n", channel, enable); |
| 2723 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2724 | WARN_ON(!dsi_bus_is_locked(dsidev)); |
Tomi Valkeinen | 61140c9 | 2010-01-12 16:00:30 +0200 | [diff] [blame] | 2725 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2726 | dsi_vc_enable(dsidev, channel, 0); |
| 2727 | dsi_if_enable(dsidev, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2728 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2729 | REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 9, 9); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2730 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2731 | dsi_vc_enable(dsidev, channel, 1); |
| 2732 | dsi_if_enable(dsidev, 1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2733 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2734 | dsi_force_tx_stop_mode_io(dsidev); |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 2735 | |
| 2736 | /* start the DDR clock by sending a NULL packet */ |
Archit Taneja | 0b3ffe3 | 2012-08-13 22:13:39 +0530 | [diff] [blame] | 2737 | if (dsi->vm_timings.ddr_clk_always_on && enable) |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 2738 | dsi_vc_send_null(dssdev, channel); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2739 | } |
Tomi Valkeinen | 61140c9 | 2010-01-12 16:00:30 +0200 | [diff] [blame] | 2740 | EXPORT_SYMBOL(omapdss_dsi_vc_enable_hs); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2741 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2742 | static void dsi_vc_flush_long_data(struct platform_device *dsidev, int channel) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2743 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2744 | while (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2745 | u32 val; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2746 | val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2747 | DSSDBG("\t\tb1 %#02x b2 %#02x b3 %#02x b4 %#02x\n", |
| 2748 | (val >> 0) & 0xff, |
| 2749 | (val >> 8) & 0xff, |
| 2750 | (val >> 16) & 0xff, |
| 2751 | (val >> 24) & 0xff); |
| 2752 | } |
| 2753 | } |
| 2754 | |
| 2755 | static void dsi_show_rx_ack_with_err(u16 err) |
| 2756 | { |
| 2757 | DSSERR("\tACK with ERROR (%#x):\n", err); |
| 2758 | if (err & (1 << 0)) |
| 2759 | DSSERR("\t\tSoT Error\n"); |
| 2760 | if (err & (1 << 1)) |
| 2761 | DSSERR("\t\tSoT Sync Error\n"); |
| 2762 | if (err & (1 << 2)) |
| 2763 | DSSERR("\t\tEoT Sync Error\n"); |
| 2764 | if (err & (1 << 3)) |
| 2765 | DSSERR("\t\tEscape Mode Entry Command Error\n"); |
| 2766 | if (err & (1 << 4)) |
| 2767 | DSSERR("\t\tLP Transmit Sync Error\n"); |
| 2768 | if (err & (1 << 5)) |
| 2769 | DSSERR("\t\tHS Receive Timeout Error\n"); |
| 2770 | if (err & (1 << 6)) |
| 2771 | DSSERR("\t\tFalse Control Error\n"); |
| 2772 | if (err & (1 << 7)) |
| 2773 | DSSERR("\t\t(reserved7)\n"); |
| 2774 | if (err & (1 << 8)) |
| 2775 | DSSERR("\t\tECC Error, single-bit (corrected)\n"); |
| 2776 | if (err & (1 << 9)) |
| 2777 | DSSERR("\t\tECC Error, multi-bit (not corrected)\n"); |
| 2778 | if (err & (1 << 10)) |
| 2779 | DSSERR("\t\tChecksum Error\n"); |
| 2780 | if (err & (1 << 11)) |
| 2781 | DSSERR("\t\tData type not recognized\n"); |
| 2782 | if (err & (1 << 12)) |
| 2783 | DSSERR("\t\tInvalid VC ID\n"); |
| 2784 | if (err & (1 << 13)) |
| 2785 | DSSERR("\t\tInvalid Transmission Length\n"); |
| 2786 | if (err & (1 << 14)) |
| 2787 | DSSERR("\t\t(reserved14)\n"); |
| 2788 | if (err & (1 << 15)) |
| 2789 | DSSERR("\t\tDSI Protocol Violation\n"); |
| 2790 | } |
| 2791 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2792 | static u16 dsi_vc_flush_receive_data(struct platform_device *dsidev, |
| 2793 | int channel) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2794 | { |
| 2795 | /* RX_FIFO_NOT_EMPTY */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2796 | while (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2797 | u32 val; |
| 2798 | u8 dt; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2799 | val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel)); |
Tomi Valkeinen | 86a7867 | 2010-03-16 16:19:06 +0200 | [diff] [blame] | 2800 | DSSERR("\trawval %#08x\n", val); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2801 | dt = FLD_GET(val, 5, 0); |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 2802 | if (dt == MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2803 | u16 err = FLD_GET(val, 23, 8); |
| 2804 | dsi_show_rx_ack_with_err(err); |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 2805 | } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE) { |
Tomi Valkeinen | 86a7867 | 2010-03-16 16:19:06 +0200 | [diff] [blame] | 2806 | DSSERR("\tDCS short response, 1 byte: %#x\n", |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2807 | FLD_GET(val, 23, 8)); |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 2808 | } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE) { |
Tomi Valkeinen | 86a7867 | 2010-03-16 16:19:06 +0200 | [diff] [blame] | 2809 | DSSERR("\tDCS short response, 2 byte: %#x\n", |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2810 | FLD_GET(val, 23, 8)); |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 2811 | } else if (dt == MIPI_DSI_RX_DCS_LONG_READ_RESPONSE) { |
Tomi Valkeinen | 86a7867 | 2010-03-16 16:19:06 +0200 | [diff] [blame] | 2812 | DSSERR("\tDCS long response, len %d\n", |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2813 | FLD_GET(val, 23, 8)); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2814 | dsi_vc_flush_long_data(dsidev, channel); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2815 | } else { |
| 2816 | DSSERR("\tunknown datatype 0x%02x\n", dt); |
| 2817 | } |
| 2818 | } |
| 2819 | return 0; |
| 2820 | } |
| 2821 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2822 | static int dsi_vc_send_bta(struct platform_device *dsidev, int channel) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2823 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2824 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 2825 | |
| 2826 | if (dsi->debug_write || dsi->debug_read) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2827 | DSSDBG("dsi_vc_send_bta %d\n", channel); |
| 2828 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2829 | WARN_ON(!dsi_bus_is_locked(dsidev)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2830 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2831 | /* RX_FIFO_NOT_EMPTY */ |
| 2832 | if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2833 | DSSERR("rx fifo not empty when sending BTA, dumping data:\n"); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2834 | dsi_vc_flush_receive_data(dsidev, channel); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2835 | } |
| 2836 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2837 | REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 6, 6); /* BTA_EN */ |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2838 | |
Tomi Valkeinen | 968f8e9 | 2011-10-12 10:13:14 +0300 | [diff] [blame] | 2839 | /* flush posted write */ |
| 2840 | dsi_read_reg(dsidev, DSI_VC_CTRL(channel)); |
| 2841 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2842 | return 0; |
| 2843 | } |
| 2844 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 2845 | int dsi_vc_send_bta_sync(struct omap_dss_device *dssdev, int channel) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2846 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2847 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Tomi Valkeinen | f36a06e | 2011-03-02 14:48:41 +0200 | [diff] [blame] | 2848 | DECLARE_COMPLETION_ONSTACK(completion); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2849 | int r = 0; |
| 2850 | u32 err; |
| 2851 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2852 | r = dsi_register_isr_vc(dsidev, channel, dsi_completion_handler, |
Tomi Valkeinen | f36a06e | 2011-03-02 14:48:41 +0200 | [diff] [blame] | 2853 | &completion, DSI_VC_IRQ_BTA); |
| 2854 | if (r) |
| 2855 | goto err0; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2856 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2857 | r = dsi_register_isr(dsidev, dsi_completion_handler, &completion, |
Tomi Valkeinen | 773b30b | 2010-10-08 16:15:25 +0300 | [diff] [blame] | 2858 | DSI_IRQ_ERROR_MASK); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2859 | if (r) |
Tomi Valkeinen | f36a06e | 2011-03-02 14:48:41 +0200 | [diff] [blame] | 2860 | goto err1; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2861 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2862 | r = dsi_vc_send_bta(dsidev, channel); |
Tomi Valkeinen | 773b30b | 2010-10-08 16:15:25 +0300 | [diff] [blame] | 2863 | if (r) |
| 2864 | goto err2; |
| 2865 | |
Tomi Valkeinen | f36a06e | 2011-03-02 14:48:41 +0200 | [diff] [blame] | 2866 | if (wait_for_completion_timeout(&completion, |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2867 | msecs_to_jiffies(500)) == 0) { |
| 2868 | DSSERR("Failed to receive BTA\n"); |
| 2869 | r = -EIO; |
Tomi Valkeinen | 773b30b | 2010-10-08 16:15:25 +0300 | [diff] [blame] | 2870 | goto err2; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2871 | } |
| 2872 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2873 | err = dsi_get_errors(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2874 | if (err) { |
| 2875 | DSSERR("Error while sending BTA: %x\n", err); |
| 2876 | r = -EIO; |
Tomi Valkeinen | 773b30b | 2010-10-08 16:15:25 +0300 | [diff] [blame] | 2877 | goto err2; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2878 | } |
Tomi Valkeinen | 773b30b | 2010-10-08 16:15:25 +0300 | [diff] [blame] | 2879 | err2: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2880 | dsi_unregister_isr(dsidev, dsi_completion_handler, &completion, |
Tomi Valkeinen | 773b30b | 2010-10-08 16:15:25 +0300 | [diff] [blame] | 2881 | DSI_IRQ_ERROR_MASK); |
Tomi Valkeinen | f36a06e | 2011-03-02 14:48:41 +0200 | [diff] [blame] | 2882 | err1: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2883 | dsi_unregister_isr_vc(dsidev, channel, dsi_completion_handler, |
Tomi Valkeinen | f36a06e | 2011-03-02 14:48:41 +0200 | [diff] [blame] | 2884 | &completion, DSI_VC_IRQ_BTA); |
| 2885 | err0: |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2886 | return r; |
| 2887 | } |
| 2888 | EXPORT_SYMBOL(dsi_vc_send_bta_sync); |
| 2889 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2890 | static inline void dsi_vc_write_long_header(struct platform_device *dsidev, |
| 2891 | int channel, u8 data_type, u16 len, u8 ecc) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2892 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2893 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2894 | u32 val; |
| 2895 | u8 data_id; |
| 2896 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2897 | WARN_ON(!dsi_bus_is_locked(dsidev)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2898 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2899 | data_id = data_type | dsi->vc[channel].vc_id << 6; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2900 | |
| 2901 | val = FLD_VAL(data_id, 7, 0) | FLD_VAL(len, 23, 8) | |
| 2902 | FLD_VAL(ecc, 31, 24); |
| 2903 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2904 | dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_HEADER(channel), val); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2905 | } |
| 2906 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2907 | static inline void dsi_vc_write_long_payload(struct platform_device *dsidev, |
| 2908 | int channel, u8 b1, u8 b2, u8 b3, u8 b4) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2909 | { |
| 2910 | u32 val; |
| 2911 | |
| 2912 | val = b4 << 24 | b3 << 16 | b2 << 8 | b1 << 0; |
| 2913 | |
| 2914 | /* DSSDBG("\twriting %02x, %02x, %02x, %02x (%#010x)\n", |
| 2915 | b1, b2, b3, b4, val); */ |
| 2916 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2917 | dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_PAYLOAD(channel), val); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2918 | } |
| 2919 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2920 | static int dsi_vc_send_long(struct platform_device *dsidev, int channel, |
| 2921 | u8 data_type, u8 *data, u16 len, u8 ecc) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2922 | { |
| 2923 | /*u32 val; */ |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2924 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2925 | int i; |
| 2926 | u8 *p; |
| 2927 | int r = 0; |
| 2928 | u8 b1, b2, b3, b4; |
| 2929 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2930 | if (dsi->debug_write) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2931 | DSSDBG("dsi_vc_send_long, %d bytes\n", len); |
| 2932 | |
| 2933 | /* len + header */ |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2934 | if (dsi->vc[channel].fifo_size * 32 * 4 < len + 4) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2935 | DSSERR("unable to send long packet: packet too long.\n"); |
| 2936 | return -EINVAL; |
| 2937 | } |
| 2938 | |
Archit Taneja | d604914 | 2011-08-22 11:58:08 +0530 | [diff] [blame] | 2939 | dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_L4); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2940 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2941 | dsi_vc_write_long_header(dsidev, channel, data_type, len, ecc); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2942 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2943 | p = data; |
| 2944 | for (i = 0; i < len >> 2; i++) { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2945 | if (dsi->debug_write) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2946 | DSSDBG("\tsending full packet %d\n", i); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2947 | |
| 2948 | b1 = *p++; |
| 2949 | b2 = *p++; |
| 2950 | b3 = *p++; |
| 2951 | b4 = *p++; |
| 2952 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2953 | dsi_vc_write_long_payload(dsidev, channel, b1, b2, b3, b4); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2954 | } |
| 2955 | |
| 2956 | i = len % 4; |
| 2957 | if (i) { |
| 2958 | b1 = 0; b2 = 0; b3 = 0; |
| 2959 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2960 | if (dsi->debug_write) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2961 | DSSDBG("\tsending remainder bytes %d\n", i); |
| 2962 | |
| 2963 | switch (i) { |
| 2964 | case 3: |
| 2965 | b1 = *p++; |
| 2966 | b2 = *p++; |
| 2967 | b3 = *p++; |
| 2968 | break; |
| 2969 | case 2: |
| 2970 | b1 = *p++; |
| 2971 | b2 = *p++; |
| 2972 | break; |
| 2973 | case 1: |
| 2974 | b1 = *p++; |
| 2975 | break; |
| 2976 | } |
| 2977 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2978 | dsi_vc_write_long_payload(dsidev, channel, b1, b2, b3, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2979 | } |
| 2980 | |
| 2981 | return r; |
| 2982 | } |
| 2983 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2984 | static int dsi_vc_send_short(struct platform_device *dsidev, int channel, |
| 2985 | u8 data_type, u16 data, u8 ecc) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2986 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2987 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2988 | u32 r; |
| 2989 | u8 data_id; |
| 2990 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2991 | WARN_ON(!dsi_bus_is_locked(dsidev)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2992 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2993 | if (dsi->debug_write) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2994 | DSSDBG("dsi_vc_send_short(ch%d, dt %#x, b1 %#x, b2 %#x)\n", |
| 2995 | channel, |
| 2996 | data_type, data & 0xff, (data >> 8) & 0xff); |
| 2997 | |
Archit Taneja | d604914 | 2011-08-22 11:58:08 +0530 | [diff] [blame] | 2998 | dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_L4); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2999 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3000 | if (FLD_GET(dsi_read_reg(dsidev, DSI_VC_CTRL(channel)), 16, 16)) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3001 | DSSERR("ERROR FIFO FULL, aborting transfer\n"); |
| 3002 | return -EINVAL; |
| 3003 | } |
| 3004 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3005 | data_id = data_type | dsi->vc[channel].vc_id << 6; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3006 | |
| 3007 | r = (data_id << 0) | (data << 8) | (ecc << 24); |
| 3008 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3009 | dsi_write_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel), r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3010 | |
| 3011 | return 0; |
| 3012 | } |
| 3013 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 3014 | int dsi_vc_send_null(struct omap_dss_device *dssdev, int channel) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3015 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3016 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3017 | |
Archit Taneja | 18b7d09 | 2011-09-05 17:01:08 +0530 | [diff] [blame] | 3018 | return dsi_vc_send_long(dsidev, channel, MIPI_DSI_NULL_PACKET, NULL, |
| 3019 | 0, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3020 | } |
| 3021 | EXPORT_SYMBOL(dsi_vc_send_null); |
| 3022 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 3023 | static int dsi_vc_write_nosync_common(struct platform_device *dsidev, |
Archit Taneja | 6ff8aa3 | 2011-08-25 18:35:58 +0530 | [diff] [blame] | 3024 | int channel, u8 *data, int len, enum dss_dsi_content_type type) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3025 | { |
| 3026 | int r; |
| 3027 | |
Archit Taneja | 6ff8aa3 | 2011-08-25 18:35:58 +0530 | [diff] [blame] | 3028 | if (len == 0) { |
| 3029 | BUG_ON(type == DSS_DSI_CONTENT_DCS); |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 3030 | r = dsi_vc_send_short(dsidev, channel, |
Archit Taneja | 6ff8aa3 | 2011-08-25 18:35:58 +0530 | [diff] [blame] | 3031 | MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM, 0, 0); |
| 3032 | } else if (len == 1) { |
| 3033 | r = dsi_vc_send_short(dsidev, channel, |
| 3034 | type == DSS_DSI_CONTENT_GENERIC ? |
| 3035 | MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM : |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 3036 | MIPI_DSI_DCS_SHORT_WRITE, data[0], 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3037 | } else if (len == 2) { |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 3038 | r = dsi_vc_send_short(dsidev, channel, |
Archit Taneja | 6ff8aa3 | 2011-08-25 18:35:58 +0530 | [diff] [blame] | 3039 | type == DSS_DSI_CONTENT_GENERIC ? |
| 3040 | MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM : |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 3041 | MIPI_DSI_DCS_SHORT_WRITE_PARAM, |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3042 | data[0] | (data[1] << 8), 0); |
| 3043 | } else { |
Archit Taneja | 6ff8aa3 | 2011-08-25 18:35:58 +0530 | [diff] [blame] | 3044 | r = dsi_vc_send_long(dsidev, channel, |
| 3045 | type == DSS_DSI_CONTENT_GENERIC ? |
| 3046 | MIPI_DSI_GENERIC_LONG_WRITE : |
| 3047 | MIPI_DSI_DCS_LONG_WRITE, data, len, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3048 | } |
| 3049 | |
| 3050 | return r; |
| 3051 | } |
Archit Taneja | 6ff8aa3 | 2011-08-25 18:35:58 +0530 | [diff] [blame] | 3052 | |
| 3053 | int dsi_vc_dcs_write_nosync(struct omap_dss_device *dssdev, int channel, |
| 3054 | u8 *data, int len) |
| 3055 | { |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 3056 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 3057 | |
| 3058 | return dsi_vc_write_nosync_common(dsidev, channel, data, len, |
Archit Taneja | 6ff8aa3 | 2011-08-25 18:35:58 +0530 | [diff] [blame] | 3059 | DSS_DSI_CONTENT_DCS); |
| 3060 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3061 | EXPORT_SYMBOL(dsi_vc_dcs_write_nosync); |
| 3062 | |
Archit Taneja | 6ff8aa3 | 2011-08-25 18:35:58 +0530 | [diff] [blame] | 3063 | int dsi_vc_generic_write_nosync(struct omap_dss_device *dssdev, int channel, |
| 3064 | u8 *data, int len) |
| 3065 | { |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 3066 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 3067 | |
| 3068 | return dsi_vc_write_nosync_common(dsidev, channel, data, len, |
Archit Taneja | 6ff8aa3 | 2011-08-25 18:35:58 +0530 | [diff] [blame] | 3069 | DSS_DSI_CONTENT_GENERIC); |
| 3070 | } |
| 3071 | EXPORT_SYMBOL(dsi_vc_generic_write_nosync); |
| 3072 | |
| 3073 | static int dsi_vc_write_common(struct omap_dss_device *dssdev, int channel, |
| 3074 | u8 *data, int len, enum dss_dsi_content_type type) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3075 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3076 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3077 | int r; |
| 3078 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 3079 | r = dsi_vc_write_nosync_common(dsidev, channel, data, len, type); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3080 | if (r) |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3081 | goto err; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3082 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 3083 | r = dsi_vc_send_bta_sync(dssdev, channel); |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3084 | if (r) |
| 3085 | goto err; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3086 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3087 | /* RX_FIFO_NOT_EMPTY */ |
| 3088 | if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) { |
Tomi Valkeinen | b63ac1e | 2010-04-09 13:20:57 +0300 | [diff] [blame] | 3089 | DSSERR("rx fifo not empty after write, dumping data:\n"); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3090 | dsi_vc_flush_receive_data(dsidev, channel); |
Tomi Valkeinen | b63ac1e | 2010-04-09 13:20:57 +0300 | [diff] [blame] | 3091 | r = -EIO; |
| 3092 | goto err; |
| 3093 | } |
| 3094 | |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3095 | return 0; |
| 3096 | err: |
Archit Taneja | 6ff8aa3 | 2011-08-25 18:35:58 +0530 | [diff] [blame] | 3097 | DSSERR("dsi_vc_write_common(ch %d, cmd 0x%02x, len %d) failed\n", |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3098 | channel, data[0], len); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3099 | return r; |
| 3100 | } |
Archit Taneja | 6ff8aa3 | 2011-08-25 18:35:58 +0530 | [diff] [blame] | 3101 | |
| 3102 | int dsi_vc_dcs_write(struct omap_dss_device *dssdev, int channel, u8 *data, |
| 3103 | int len) |
| 3104 | { |
| 3105 | return dsi_vc_write_common(dssdev, channel, data, len, |
| 3106 | DSS_DSI_CONTENT_DCS); |
| 3107 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3108 | EXPORT_SYMBOL(dsi_vc_dcs_write); |
| 3109 | |
Archit Taneja | 6ff8aa3 | 2011-08-25 18:35:58 +0530 | [diff] [blame] | 3110 | int dsi_vc_generic_write(struct omap_dss_device *dssdev, int channel, u8 *data, |
| 3111 | int len) |
| 3112 | { |
| 3113 | return dsi_vc_write_common(dssdev, channel, data, len, |
| 3114 | DSS_DSI_CONTENT_GENERIC); |
| 3115 | } |
| 3116 | EXPORT_SYMBOL(dsi_vc_generic_write); |
| 3117 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 3118 | int dsi_vc_dcs_write_0(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd) |
Tomi Valkeinen | 828c48f | 2009-12-16 14:53:15 +0200 | [diff] [blame] | 3119 | { |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 3120 | return dsi_vc_dcs_write(dssdev, channel, &dcs_cmd, 1); |
Tomi Valkeinen | 828c48f | 2009-12-16 14:53:15 +0200 | [diff] [blame] | 3121 | } |
| 3122 | EXPORT_SYMBOL(dsi_vc_dcs_write_0); |
| 3123 | |
Archit Taneja | 6ff8aa3 | 2011-08-25 18:35:58 +0530 | [diff] [blame] | 3124 | int dsi_vc_generic_write_0(struct omap_dss_device *dssdev, int channel) |
| 3125 | { |
| 3126 | return dsi_vc_generic_write(dssdev, channel, NULL, 0); |
| 3127 | } |
| 3128 | EXPORT_SYMBOL(dsi_vc_generic_write_0); |
| 3129 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 3130 | int dsi_vc_dcs_write_1(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd, |
| 3131 | u8 param) |
Tomi Valkeinen | 828c48f | 2009-12-16 14:53:15 +0200 | [diff] [blame] | 3132 | { |
| 3133 | u8 buf[2]; |
| 3134 | buf[0] = dcs_cmd; |
| 3135 | buf[1] = param; |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 3136 | return dsi_vc_dcs_write(dssdev, channel, buf, 2); |
Tomi Valkeinen | 828c48f | 2009-12-16 14:53:15 +0200 | [diff] [blame] | 3137 | } |
| 3138 | EXPORT_SYMBOL(dsi_vc_dcs_write_1); |
| 3139 | |
Archit Taneja | 6ff8aa3 | 2011-08-25 18:35:58 +0530 | [diff] [blame] | 3140 | int dsi_vc_generic_write_1(struct omap_dss_device *dssdev, int channel, |
| 3141 | u8 param) |
| 3142 | { |
| 3143 | return dsi_vc_generic_write(dssdev, channel, ¶m, 1); |
| 3144 | } |
| 3145 | EXPORT_SYMBOL(dsi_vc_generic_write_1); |
| 3146 | |
| 3147 | int dsi_vc_generic_write_2(struct omap_dss_device *dssdev, int channel, |
| 3148 | u8 param1, u8 param2) |
| 3149 | { |
| 3150 | u8 buf[2]; |
| 3151 | buf[0] = param1; |
| 3152 | buf[1] = param2; |
| 3153 | return dsi_vc_generic_write(dssdev, channel, buf, 2); |
| 3154 | } |
| 3155 | EXPORT_SYMBOL(dsi_vc_generic_write_2); |
| 3156 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 3157 | static int dsi_vc_dcs_send_read_request(struct platform_device *dsidev, |
Archit Taneja | b850975 | 2011-08-30 15:48:23 +0530 | [diff] [blame] | 3158 | int channel, u8 dcs_cmd) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3159 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3160 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Archit Taneja | b850975 | 2011-08-30 15:48:23 +0530 | [diff] [blame] | 3161 | int r; |
| 3162 | |
| 3163 | if (dsi->debug_read) |
| 3164 | DSSDBG("dsi_vc_dcs_send_read_request(ch%d, dcs_cmd %x)\n", |
| 3165 | channel, dcs_cmd); |
| 3166 | |
| 3167 | r = dsi_vc_send_short(dsidev, channel, MIPI_DSI_DCS_READ, dcs_cmd, 0); |
| 3168 | if (r) { |
| 3169 | DSSERR("dsi_vc_dcs_send_read_request(ch %d, cmd 0x%02x)" |
| 3170 | " failed\n", channel, dcs_cmd); |
| 3171 | return r; |
| 3172 | } |
| 3173 | |
| 3174 | return 0; |
| 3175 | } |
| 3176 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 3177 | static int dsi_vc_generic_send_read_request(struct platform_device *dsidev, |
Archit Taneja | b3b89c0 | 2011-08-30 16:07:39 +0530 | [diff] [blame] | 3178 | int channel, u8 *reqdata, int reqlen) |
| 3179 | { |
Archit Taneja | b3b89c0 | 2011-08-30 16:07:39 +0530 | [diff] [blame] | 3180 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 3181 | u16 data; |
| 3182 | u8 data_type; |
| 3183 | int r; |
| 3184 | |
| 3185 | if (dsi->debug_read) |
| 3186 | DSSDBG("dsi_vc_generic_send_read_request(ch %d, reqlen %d)\n", |
| 3187 | channel, reqlen); |
| 3188 | |
| 3189 | if (reqlen == 0) { |
| 3190 | data_type = MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM; |
| 3191 | data = 0; |
| 3192 | } else if (reqlen == 1) { |
| 3193 | data_type = MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM; |
| 3194 | data = reqdata[0]; |
| 3195 | } else if (reqlen == 2) { |
| 3196 | data_type = MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM; |
| 3197 | data = reqdata[0] | (reqdata[1] << 8); |
| 3198 | } else { |
| 3199 | BUG(); |
Tomi Valkeinen | c6eee96 | 2012-05-18 11:47:02 +0300 | [diff] [blame] | 3200 | return -EINVAL; |
Archit Taneja | b3b89c0 | 2011-08-30 16:07:39 +0530 | [diff] [blame] | 3201 | } |
| 3202 | |
| 3203 | r = dsi_vc_send_short(dsidev, channel, data_type, data, 0); |
| 3204 | if (r) { |
| 3205 | DSSERR("dsi_vc_generic_send_read_request(ch %d, reqlen %d)" |
| 3206 | " failed\n", channel, reqlen); |
| 3207 | return r; |
| 3208 | } |
| 3209 | |
| 3210 | return 0; |
| 3211 | } |
| 3212 | |
| 3213 | static int dsi_vc_read_rx_fifo(struct platform_device *dsidev, int channel, |
| 3214 | u8 *buf, int buflen, enum dss_dsi_content_type type) |
Archit Taneja | b850975 | 2011-08-30 15:48:23 +0530 | [diff] [blame] | 3215 | { |
| 3216 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3217 | u32 val; |
| 3218 | u8 dt; |
| 3219 | int r; |
| 3220 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3221 | /* RX_FIFO_NOT_EMPTY */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3222 | if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20) == 0) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3223 | DSSERR("RX fifo empty when trying to read.\n"); |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3224 | r = -EIO; |
| 3225 | goto err; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3226 | } |
| 3227 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3228 | val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel)); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3229 | if (dsi->debug_read) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3230 | DSSDBG("\theader: %08x\n", val); |
| 3231 | dt = FLD_GET(val, 5, 0); |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 3232 | if (dt == MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3233 | u16 err = FLD_GET(val, 23, 8); |
| 3234 | dsi_show_rx_ack_with_err(err); |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3235 | r = -EIO; |
| 3236 | goto err; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3237 | |
Archit Taneja | b3b89c0 | 2011-08-30 16:07:39 +0530 | [diff] [blame] | 3238 | } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ? |
| 3239 | MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_1BYTE : |
| 3240 | MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE)) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3241 | u8 data = FLD_GET(val, 15, 8); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3242 | if (dsi->debug_read) |
Archit Taneja | b3b89c0 | 2011-08-30 16:07:39 +0530 | [diff] [blame] | 3243 | DSSDBG("\t%s short response, 1 byte: %02x\n", |
| 3244 | type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" : |
| 3245 | "DCS", data); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3246 | |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3247 | if (buflen < 1) { |
| 3248 | r = -EIO; |
| 3249 | goto err; |
| 3250 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3251 | |
| 3252 | buf[0] = data; |
| 3253 | |
| 3254 | return 1; |
Archit Taneja | b3b89c0 | 2011-08-30 16:07:39 +0530 | [diff] [blame] | 3255 | } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ? |
| 3256 | MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_2BYTE : |
| 3257 | MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE)) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3258 | u16 data = FLD_GET(val, 23, 8); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3259 | if (dsi->debug_read) |
Archit Taneja | b3b89c0 | 2011-08-30 16:07:39 +0530 | [diff] [blame] | 3260 | DSSDBG("\t%s short response, 2 byte: %04x\n", |
| 3261 | type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" : |
| 3262 | "DCS", data); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3263 | |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3264 | if (buflen < 2) { |
| 3265 | r = -EIO; |
| 3266 | goto err; |
| 3267 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3268 | |
| 3269 | buf[0] = data & 0xff; |
| 3270 | buf[1] = (data >> 8) & 0xff; |
| 3271 | |
| 3272 | return 2; |
Archit Taneja | b3b89c0 | 2011-08-30 16:07:39 +0530 | [diff] [blame] | 3273 | } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ? |
| 3274 | MIPI_DSI_RX_GENERIC_LONG_READ_RESPONSE : |
| 3275 | MIPI_DSI_RX_DCS_LONG_READ_RESPONSE)) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3276 | int w; |
| 3277 | int len = FLD_GET(val, 23, 8); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3278 | if (dsi->debug_read) |
Archit Taneja | b3b89c0 | 2011-08-30 16:07:39 +0530 | [diff] [blame] | 3279 | DSSDBG("\t%s long response, len %d\n", |
| 3280 | type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" : |
| 3281 | "DCS", len); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3282 | |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3283 | if (len > buflen) { |
| 3284 | r = -EIO; |
| 3285 | goto err; |
| 3286 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3287 | |
| 3288 | /* two byte checksum ends the packet, not included in len */ |
| 3289 | for (w = 0; w < len + 2;) { |
| 3290 | int b; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3291 | val = dsi_read_reg(dsidev, |
| 3292 | DSI_VC_SHORT_PACKET_HEADER(channel)); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3293 | if (dsi->debug_read) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3294 | DSSDBG("\t\t%02x %02x %02x %02x\n", |
| 3295 | (val >> 0) & 0xff, |
| 3296 | (val >> 8) & 0xff, |
| 3297 | (val >> 16) & 0xff, |
| 3298 | (val >> 24) & 0xff); |
| 3299 | |
| 3300 | for (b = 0; b < 4; ++b) { |
| 3301 | if (w < len) |
| 3302 | buf[w] = (val >> (b * 8)) & 0xff; |
| 3303 | /* we discard the 2 byte checksum */ |
| 3304 | ++w; |
| 3305 | } |
| 3306 | } |
| 3307 | |
| 3308 | return len; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3309 | } else { |
| 3310 | DSSERR("\tunknown datatype 0x%02x\n", dt); |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3311 | r = -EIO; |
| 3312 | goto err; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3313 | } |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3314 | |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3315 | err: |
Archit Taneja | b3b89c0 | 2011-08-30 16:07:39 +0530 | [diff] [blame] | 3316 | DSSERR("dsi_vc_read_rx_fifo(ch %d type %s) failed\n", channel, |
| 3317 | type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" : "DCS"); |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3318 | |
Archit Taneja | b850975 | 2011-08-30 15:48:23 +0530 | [diff] [blame] | 3319 | return r; |
| 3320 | } |
| 3321 | |
| 3322 | int dsi_vc_dcs_read(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd, |
| 3323 | u8 *buf, int buflen) |
| 3324 | { |
| 3325 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 3326 | int r; |
| 3327 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 3328 | r = dsi_vc_dcs_send_read_request(dsidev, channel, dcs_cmd); |
Archit Taneja | b850975 | 2011-08-30 15:48:23 +0530 | [diff] [blame] | 3329 | if (r) |
| 3330 | goto err; |
| 3331 | |
| 3332 | r = dsi_vc_send_bta_sync(dssdev, channel); |
| 3333 | if (r) |
| 3334 | goto err; |
| 3335 | |
Archit Taneja | b3b89c0 | 2011-08-30 16:07:39 +0530 | [diff] [blame] | 3336 | r = dsi_vc_read_rx_fifo(dsidev, channel, buf, buflen, |
| 3337 | DSS_DSI_CONTENT_DCS); |
Archit Taneja | b850975 | 2011-08-30 15:48:23 +0530 | [diff] [blame] | 3338 | if (r < 0) |
| 3339 | goto err; |
| 3340 | |
| 3341 | if (r != buflen) { |
| 3342 | r = -EIO; |
| 3343 | goto err; |
| 3344 | } |
| 3345 | |
| 3346 | return 0; |
| 3347 | err: |
| 3348 | DSSERR("dsi_vc_dcs_read(ch %d, cmd 0x%02x) failed\n", channel, dcs_cmd); |
| 3349 | return r; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3350 | } |
| 3351 | EXPORT_SYMBOL(dsi_vc_dcs_read); |
| 3352 | |
Archit Taneja | b3b89c0 | 2011-08-30 16:07:39 +0530 | [diff] [blame] | 3353 | static int dsi_vc_generic_read(struct omap_dss_device *dssdev, int channel, |
| 3354 | u8 *reqdata, int reqlen, u8 *buf, int buflen) |
| 3355 | { |
| 3356 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 3357 | int r; |
| 3358 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 3359 | r = dsi_vc_generic_send_read_request(dsidev, channel, reqdata, reqlen); |
Archit Taneja | b3b89c0 | 2011-08-30 16:07:39 +0530 | [diff] [blame] | 3360 | if (r) |
| 3361 | return r; |
| 3362 | |
| 3363 | r = dsi_vc_send_bta_sync(dssdev, channel); |
| 3364 | if (r) |
| 3365 | return r; |
| 3366 | |
| 3367 | r = dsi_vc_read_rx_fifo(dsidev, channel, buf, buflen, |
| 3368 | DSS_DSI_CONTENT_GENERIC); |
| 3369 | if (r < 0) |
| 3370 | return r; |
| 3371 | |
| 3372 | if (r != buflen) { |
| 3373 | r = -EIO; |
| 3374 | return r; |
| 3375 | } |
| 3376 | |
| 3377 | return 0; |
| 3378 | } |
| 3379 | |
| 3380 | int dsi_vc_generic_read_0(struct omap_dss_device *dssdev, int channel, u8 *buf, |
| 3381 | int buflen) |
| 3382 | { |
| 3383 | int r; |
| 3384 | |
| 3385 | r = dsi_vc_generic_read(dssdev, channel, NULL, 0, buf, buflen); |
| 3386 | if (r) { |
| 3387 | DSSERR("dsi_vc_generic_read_0(ch %d) failed\n", channel); |
| 3388 | return r; |
| 3389 | } |
| 3390 | |
| 3391 | return 0; |
| 3392 | } |
| 3393 | EXPORT_SYMBOL(dsi_vc_generic_read_0); |
| 3394 | |
| 3395 | int dsi_vc_generic_read_1(struct omap_dss_device *dssdev, int channel, u8 param, |
| 3396 | u8 *buf, int buflen) |
| 3397 | { |
| 3398 | int r; |
| 3399 | |
| 3400 | r = dsi_vc_generic_read(dssdev, channel, ¶m, 1, buf, buflen); |
| 3401 | if (r) { |
| 3402 | DSSERR("dsi_vc_generic_read_1(ch %d) failed\n", channel); |
| 3403 | return r; |
| 3404 | } |
| 3405 | |
| 3406 | return 0; |
| 3407 | } |
| 3408 | EXPORT_SYMBOL(dsi_vc_generic_read_1); |
| 3409 | |
| 3410 | int dsi_vc_generic_read_2(struct omap_dss_device *dssdev, int channel, |
| 3411 | u8 param1, u8 param2, u8 *buf, int buflen) |
| 3412 | { |
| 3413 | int r; |
| 3414 | u8 reqdata[2]; |
| 3415 | |
| 3416 | reqdata[0] = param1; |
| 3417 | reqdata[1] = param2; |
| 3418 | |
| 3419 | r = dsi_vc_generic_read(dssdev, channel, reqdata, 2, buf, buflen); |
| 3420 | if (r) { |
| 3421 | DSSERR("dsi_vc_generic_read_2(ch %d) failed\n", channel); |
| 3422 | return r; |
| 3423 | } |
| 3424 | |
| 3425 | return 0; |
| 3426 | } |
| 3427 | EXPORT_SYMBOL(dsi_vc_generic_read_2); |
| 3428 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 3429 | int dsi_vc_set_max_rx_packet_size(struct omap_dss_device *dssdev, int channel, |
| 3430 | u16 len) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3431 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3432 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 3433 | |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 3434 | return dsi_vc_send_short(dsidev, channel, |
| 3435 | MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE, len, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3436 | } |
| 3437 | EXPORT_SYMBOL(dsi_vc_set_max_rx_packet_size); |
| 3438 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3439 | static int dsi_enter_ulps(struct platform_device *dsidev) |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3440 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3441 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3442 | DECLARE_COMPLETION_ONSTACK(completion); |
Tomi Valkeinen | 522a0c2 | 2011-10-13 16:18:52 +0300 | [diff] [blame] | 3443 | int r, i; |
| 3444 | unsigned mask; |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3445 | |
Chandrabhanu Mahapatra | 702d267 | 2012-09-24 17:12:58 +0530 | [diff] [blame] | 3446 | DSSDBG("Entering ULPS"); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3447 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3448 | WARN_ON(!dsi_bus_is_locked(dsidev)); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3449 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3450 | WARN_ON(dsi->ulps_enabled); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3451 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3452 | if (dsi->ulps_enabled) |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3453 | return 0; |
| 3454 | |
Tomi Valkeinen | 6cc78aa | 2011-10-13 19:22:43 +0300 | [diff] [blame] | 3455 | /* DDR_CLK_ALWAYS_ON */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3456 | if (REG_GET(dsidev, DSI_CLK_CTRL, 13, 13)) { |
Tomi Valkeinen | 6cc78aa | 2011-10-13 19:22:43 +0300 | [diff] [blame] | 3457 | dsi_if_enable(dsidev, 0); |
| 3458 | REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 13, 13); |
| 3459 | dsi_if_enable(dsidev, 1); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3460 | } |
| 3461 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3462 | dsi_sync_vc(dsidev, 0); |
| 3463 | dsi_sync_vc(dsidev, 1); |
| 3464 | dsi_sync_vc(dsidev, 2); |
| 3465 | dsi_sync_vc(dsidev, 3); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3466 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3467 | dsi_force_tx_stop_mode_io(dsidev); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3468 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3469 | dsi_vc_enable(dsidev, 0, false); |
| 3470 | dsi_vc_enable(dsidev, 1, false); |
| 3471 | dsi_vc_enable(dsidev, 2, false); |
| 3472 | dsi_vc_enable(dsidev, 3, false); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3473 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3474 | if (REG_GET(dsidev, DSI_COMPLEXIO_CFG2, 16, 16)) { /* HS_BUSY */ |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3475 | DSSERR("HS busy when enabling ULPS\n"); |
| 3476 | return -EIO; |
| 3477 | } |
| 3478 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3479 | if (REG_GET(dsidev, DSI_COMPLEXIO_CFG2, 17, 17)) { /* LP_BUSY */ |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3480 | DSSERR("LP busy when enabling ULPS\n"); |
| 3481 | return -EIO; |
| 3482 | } |
| 3483 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3484 | r = dsi_register_isr_cio(dsidev, dsi_completion_handler, &completion, |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3485 | DSI_CIO_IRQ_ULPSACTIVENOT_ALL0); |
| 3486 | if (r) |
| 3487 | return r; |
| 3488 | |
Tomi Valkeinen | 522a0c2 | 2011-10-13 16:18:52 +0300 | [diff] [blame] | 3489 | mask = 0; |
| 3490 | |
| 3491 | for (i = 0; i < dsi->num_lanes_supported; ++i) { |
| 3492 | if (dsi->lanes[i].function == DSI_LANE_UNUSED) |
| 3493 | continue; |
| 3494 | mask |= 1 << i; |
| 3495 | } |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3496 | /* Assert TxRequestEsc for data lanes and TxUlpsClk for clk lane */ |
| 3497 | /* LANEx_ULPS_SIG2 */ |
Tomi Valkeinen | 522a0c2 | 2011-10-13 16:18:52 +0300 | [diff] [blame] | 3498 | REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG2, mask, 9, 5); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3499 | |
Tomi Valkeinen | a702c85 | 2011-10-12 10:10:21 +0300 | [diff] [blame] | 3500 | /* flush posted write and wait for SCP interface to finish the write */ |
| 3501 | dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG2); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3502 | |
| 3503 | if (wait_for_completion_timeout(&completion, |
| 3504 | msecs_to_jiffies(1000)) == 0) { |
| 3505 | DSSERR("ULPS enable timeout\n"); |
| 3506 | r = -EIO; |
| 3507 | goto err; |
| 3508 | } |
| 3509 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3510 | dsi_unregister_isr_cio(dsidev, dsi_completion_handler, &completion, |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3511 | DSI_CIO_IRQ_ULPSACTIVENOT_ALL0); |
| 3512 | |
Tomi Valkeinen | 8ef0e61 | 2011-05-31 16:55:47 +0300 | [diff] [blame] | 3513 | /* Reset LANEx_ULPS_SIG2 */ |
Tomi Valkeinen | 522a0c2 | 2011-10-13 16:18:52 +0300 | [diff] [blame] | 3514 | REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG2, 0, 9, 5); |
Tomi Valkeinen | 8ef0e61 | 2011-05-31 16:55:47 +0300 | [diff] [blame] | 3515 | |
Tomi Valkeinen | a702c85 | 2011-10-12 10:10:21 +0300 | [diff] [blame] | 3516 | /* flush posted write and wait for SCP interface to finish the write */ |
| 3517 | dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG2); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3518 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3519 | dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_ULPS); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3520 | |
| 3521 | dsi_if_enable(dsidev, false); |
| 3522 | |
| 3523 | dsi->ulps_enabled = true; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3524 | |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3525 | return 0; |
| 3526 | |
| 3527 | err: |
| 3528 | dsi_unregister_isr_cio(dsidev, dsi_completion_handler, &completion, |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3529 | DSI_CIO_IRQ_ULPSACTIVENOT_ALL0); |
| 3530 | return r; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3531 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3532 | |
Tomi Valkeinen | 4ffa357 | 2010-04-12 10:40:12 +0300 | [diff] [blame] | 3533 | static void dsi_set_lp_rx_timeout(struct platform_device *dsidev, |
| 3534 | unsigned ticks, bool x4, bool x16) |
| 3535 | { |
| 3536 | unsigned long fck; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3537 | unsigned long total_ticks; |
| 3538 | u32 r; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3539 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3540 | BUG_ON(ticks > 0x1fff); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3541 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3542 | /* ticks in DSI_FCK */ |
Tomi Valkeinen | 4ffa357 | 2010-04-12 10:40:12 +0300 | [diff] [blame] | 3543 | fck = dsi_fclk_rate(dsidev); |
| 3544 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3545 | r = dsi_read_reg(dsidev, DSI_TIMING2); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3546 | r = FLD_MOD(r, 1, 15, 15); /* LP_RX_TO */ |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3547 | r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* LP_RX_TO_X16 */ |
Tomi Valkeinen | 4ffa357 | 2010-04-12 10:40:12 +0300 | [diff] [blame] | 3548 | r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* LP_RX_TO_X4 */ |
| 3549 | r = FLD_MOD(r, ticks, 12, 0); /* LP_RX_COUNTER */ |
| 3550 | dsi_write_reg(dsidev, DSI_TIMING2, r); |
| 3551 | |
| 3552 | total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1); |
| 3553 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3554 | DSSDBG("LP_RX_TO %lu ticks (%#x%s%s) = %lu ns\n", |
| 3555 | total_ticks, |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3556 | ticks, x4 ? " x4" : "", x16 ? " x16" : "", |
| 3557 | (total_ticks * 1000) / (fck / 1000 / 1000)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3558 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3559 | |
Tomi Valkeinen | 4ffa357 | 2010-04-12 10:40:12 +0300 | [diff] [blame] | 3560 | static void dsi_set_ta_timeout(struct platform_device *dsidev, unsigned ticks, |
| 3561 | bool x8, bool x16) |
| 3562 | { |
| 3563 | unsigned long fck; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3564 | unsigned long total_ticks; |
| 3565 | u32 r; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3566 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3567 | BUG_ON(ticks > 0x1fff); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3568 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3569 | /* ticks in DSI_FCK */ |
Tomi Valkeinen | 4ffa357 | 2010-04-12 10:40:12 +0300 | [diff] [blame] | 3570 | fck = dsi_fclk_rate(dsidev); |
| 3571 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3572 | r = dsi_read_reg(dsidev, DSI_TIMING1); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3573 | r = FLD_MOD(r, 1, 31, 31); /* TA_TO */ |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3574 | r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* TA_TO_X16 */ |
Tomi Valkeinen | 4ffa357 | 2010-04-12 10:40:12 +0300 | [diff] [blame] | 3575 | r = FLD_MOD(r, x8 ? 1 : 0, 29, 29); /* TA_TO_X8 */ |
| 3576 | r = FLD_MOD(r, ticks, 28, 16); /* TA_TO_COUNTER */ |
| 3577 | dsi_write_reg(dsidev, DSI_TIMING1, r); |
| 3578 | |
| 3579 | total_ticks = ticks * (x16 ? 16 : 1) * (x8 ? 8 : 1); |
| 3580 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3581 | DSSDBG("TA_TO %lu ticks (%#x%s%s) = %lu ns\n", |
| 3582 | total_ticks, |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3583 | ticks, x8 ? " x8" : "", x16 ? " x16" : "", |
| 3584 | (total_ticks * 1000) / (fck / 1000 / 1000)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3585 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3586 | |
Tomi Valkeinen | 4ffa357 | 2010-04-12 10:40:12 +0300 | [diff] [blame] | 3587 | static void dsi_set_stop_state_counter(struct platform_device *dsidev, |
| 3588 | unsigned ticks, bool x4, bool x16) |
| 3589 | { |
| 3590 | unsigned long fck; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3591 | unsigned long total_ticks; |
| 3592 | u32 r; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3593 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3594 | BUG_ON(ticks > 0x1fff); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3595 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3596 | /* ticks in DSI_FCK */ |
Tomi Valkeinen | 4ffa357 | 2010-04-12 10:40:12 +0300 | [diff] [blame] | 3597 | fck = dsi_fclk_rate(dsidev); |
| 3598 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3599 | r = dsi_read_reg(dsidev, DSI_TIMING1); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3600 | r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */ |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3601 | r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* STOP_STATE_X16_IO */ |
Tomi Valkeinen | 4ffa357 | 2010-04-12 10:40:12 +0300 | [diff] [blame] | 3602 | r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* STOP_STATE_X4_IO */ |
| 3603 | r = FLD_MOD(r, ticks, 12, 0); /* STOP_STATE_COUNTER_IO */ |
| 3604 | dsi_write_reg(dsidev, DSI_TIMING1, r); |
| 3605 | |
| 3606 | total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1); |
| 3607 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3608 | DSSDBG("STOP_STATE_COUNTER %lu ticks (%#x%s%s) = %lu ns\n", |
| 3609 | total_ticks, |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3610 | ticks, x4 ? " x4" : "", x16 ? " x16" : "", |
| 3611 | (total_ticks * 1000) / (fck / 1000 / 1000)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3612 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3613 | |
Tomi Valkeinen | 4ffa357 | 2010-04-12 10:40:12 +0300 | [diff] [blame] | 3614 | static void dsi_set_hs_tx_timeout(struct platform_device *dsidev, |
| 3615 | unsigned ticks, bool x4, bool x16) |
| 3616 | { |
| 3617 | unsigned long fck; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3618 | unsigned long total_ticks; |
| 3619 | u32 r; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3620 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3621 | BUG_ON(ticks > 0x1fff); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3622 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3623 | /* ticks in TxByteClkHS */ |
Tomi Valkeinen | 4ffa357 | 2010-04-12 10:40:12 +0300 | [diff] [blame] | 3624 | fck = dsi_get_txbyteclkhs(dsidev); |
| 3625 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3626 | r = dsi_read_reg(dsidev, DSI_TIMING2); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3627 | r = FLD_MOD(r, 1, 31, 31); /* HS_TX_TO */ |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3628 | r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* HS_TX_TO_X16 */ |
Tomi Valkeinen | 4ffa357 | 2010-04-12 10:40:12 +0300 | [diff] [blame] | 3629 | r = FLD_MOD(r, x4 ? 1 : 0, 29, 29); /* HS_TX_TO_X8 (4 really) */ |
| 3630 | r = FLD_MOD(r, ticks, 28, 16); /* HS_TX_TO_COUNTER */ |
| 3631 | dsi_write_reg(dsidev, DSI_TIMING2, r); |
| 3632 | |
| 3633 | total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1); |
| 3634 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3635 | DSSDBG("HS_TX_TO %lu ticks (%#x%s%s) = %lu ns\n", |
| 3636 | total_ticks, |
| 3637 | ticks, x4 ? " x4" : "", x16 ? " x16" : "", |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3638 | (total_ticks * 1000) / (fck / 1000 / 1000)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3639 | } |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3640 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 3641 | static void dsi_config_vp_num_line_buffers(struct platform_device *dsidev) |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3642 | { |
Archit Taneja | dca2b15 | 2012-08-16 18:02:00 +0530 | [diff] [blame] | 3643 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3644 | int num_line_buffers; |
| 3645 | |
Archit Taneja | dca2b15 | 2012-08-16 18:02:00 +0530 | [diff] [blame] | 3646 | if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) { |
Archit Taneja | 02c3960 | 2012-08-10 15:01:33 +0530 | [diff] [blame] | 3647 | int bpp = dsi_get_pixel_size(dsi->pix_fmt); |
Archit Taneja | e67458a | 2012-08-13 14:17:30 +0530 | [diff] [blame] | 3648 | struct omap_video_timings *timings = &dsi->timings; |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3649 | /* |
| 3650 | * Don't use line buffers if width is greater than the video |
| 3651 | * port's line buffer size |
| 3652 | */ |
Tomi Valkeinen | 9932257 | 2013-03-05 10:37:02 +0200 | [diff] [blame] | 3653 | if (dsi->line_buffer_size <= timings->x_res * bpp / 8) |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3654 | num_line_buffers = 0; |
| 3655 | else |
| 3656 | num_line_buffers = 2; |
| 3657 | } else { |
| 3658 | /* Use maximum number of line buffers in command mode */ |
| 3659 | num_line_buffers = 2; |
| 3660 | } |
| 3661 | |
| 3662 | /* LINE_BUFFER */ |
| 3663 | REG_FLD_MOD(dsidev, DSI_CTRL, num_line_buffers, 13, 12); |
| 3664 | } |
| 3665 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 3666 | static void dsi_config_vp_sync_events(struct platform_device *dsidev) |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3667 | { |
Archit Taneja | 0b3ffe3 | 2012-08-13 22:13:39 +0530 | [diff] [blame] | 3668 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 478d7df | 2013-03-05 16:29:36 +0200 | [diff] [blame] | 3669 | bool sync_end; |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3670 | u32 r; |
| 3671 | |
Tomi Valkeinen | 478d7df | 2013-03-05 16:29:36 +0200 | [diff] [blame] | 3672 | if (dsi->vm_timings.trans_mode == OMAP_DSS_DSI_PULSE_MODE) |
| 3673 | sync_end = true; |
| 3674 | else |
| 3675 | sync_end = false; |
| 3676 | |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3677 | r = dsi_read_reg(dsidev, DSI_CTRL); |
Archit Taneja | bd5a7b1 | 2012-06-26 12:38:31 +0530 | [diff] [blame] | 3678 | r = FLD_MOD(r, 1, 9, 9); /* VP_DE_POL */ |
| 3679 | r = FLD_MOD(r, 1, 10, 10); /* VP_HSYNC_POL */ |
| 3680 | r = FLD_MOD(r, 1, 11, 11); /* VP_VSYNC_POL */ |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3681 | r = FLD_MOD(r, 1, 15, 15); /* VP_VSYNC_START */ |
Tomi Valkeinen | 478d7df | 2013-03-05 16:29:36 +0200 | [diff] [blame] | 3682 | r = FLD_MOD(r, sync_end, 16, 16); /* VP_VSYNC_END */ |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3683 | r = FLD_MOD(r, 1, 17, 17); /* VP_HSYNC_START */ |
Tomi Valkeinen | 478d7df | 2013-03-05 16:29:36 +0200 | [diff] [blame] | 3684 | r = FLD_MOD(r, sync_end, 18, 18); /* VP_HSYNC_END */ |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3685 | dsi_write_reg(dsidev, DSI_CTRL, r); |
| 3686 | } |
| 3687 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 3688 | static void dsi_config_blanking_modes(struct platform_device *dsidev) |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3689 | { |
Archit Taneja | 0b3ffe3 | 2012-08-13 22:13:39 +0530 | [diff] [blame] | 3690 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 3691 | int blanking_mode = dsi->vm_timings.blanking_mode; |
| 3692 | int hfp_blanking_mode = dsi->vm_timings.hfp_blanking_mode; |
| 3693 | int hbp_blanking_mode = dsi->vm_timings.hbp_blanking_mode; |
| 3694 | int hsa_blanking_mode = dsi->vm_timings.hsa_blanking_mode; |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3695 | u32 r; |
| 3696 | |
| 3697 | /* |
| 3698 | * 0 = TX FIFO packets sent or LPS in corresponding blanking periods |
| 3699 | * 1 = Long blanking packets are sent in corresponding blanking periods |
| 3700 | */ |
| 3701 | r = dsi_read_reg(dsidev, DSI_CTRL); |
| 3702 | r = FLD_MOD(r, blanking_mode, 20, 20); /* BLANKING_MODE */ |
| 3703 | r = FLD_MOD(r, hfp_blanking_mode, 21, 21); /* HFP_BLANKING */ |
| 3704 | r = FLD_MOD(r, hbp_blanking_mode, 22, 22); /* HBP_BLANKING */ |
| 3705 | r = FLD_MOD(r, hsa_blanking_mode, 23, 23); /* HSA_BLANKING */ |
| 3706 | dsi_write_reg(dsidev, DSI_CTRL, r); |
| 3707 | } |
| 3708 | |
Archit Taneja | 6f28c29 | 2012-05-15 11:32:18 +0530 | [diff] [blame] | 3709 | /* |
| 3710 | * According to section 'HS Command Mode Interleaving' in OMAP TRM, Scenario 3 |
| 3711 | * results in maximum transition time for data and clock lanes to enter and |
| 3712 | * exit HS mode. Hence, this is the scenario where the least amount of command |
| 3713 | * mode data can be interleaved. We program the minimum amount of TXBYTECLKHS |
| 3714 | * clock cycles that can be used to interleave command mode data in HS so that |
| 3715 | * all scenarios are satisfied. |
| 3716 | */ |
| 3717 | static int dsi_compute_interleave_hs(int blank, bool ddr_alwon, int enter_hs, |
| 3718 | int exit_hs, int exiths_clk, int ddr_pre, int ddr_post) |
| 3719 | { |
| 3720 | int transition; |
| 3721 | |
| 3722 | /* |
| 3723 | * If DDR_CLK_ALWAYS_ON is set, we need to consider HS mode transition |
| 3724 | * time of data lanes only, if it isn't set, we need to consider HS |
| 3725 | * transition time of both data and clock lanes. HS transition time |
| 3726 | * of Scenario 3 is considered. |
| 3727 | */ |
| 3728 | if (ddr_alwon) { |
| 3729 | transition = enter_hs + exit_hs + max(enter_hs, 2) + 1; |
| 3730 | } else { |
| 3731 | int trans1, trans2; |
| 3732 | trans1 = ddr_pre + enter_hs + exit_hs + max(enter_hs, 2) + 1; |
| 3733 | trans2 = ddr_pre + enter_hs + exiths_clk + ddr_post + ddr_pre + |
| 3734 | enter_hs + 1; |
| 3735 | transition = max(trans1, trans2); |
| 3736 | } |
| 3737 | |
| 3738 | return blank > transition ? blank - transition : 0; |
| 3739 | } |
| 3740 | |
| 3741 | /* |
| 3742 | * According to section 'LP Command Mode Interleaving' in OMAP TRM, Scenario 1 |
| 3743 | * results in maximum transition time for data lanes to enter and exit LP mode. |
| 3744 | * Hence, this is the scenario where the least amount of command mode data can |
| 3745 | * be interleaved. We program the minimum amount of bytes that can be |
| 3746 | * interleaved in LP so that all scenarios are satisfied. |
| 3747 | */ |
| 3748 | static int dsi_compute_interleave_lp(int blank, int enter_hs, int exit_hs, |
| 3749 | int lp_clk_div, int tdsi_fclk) |
| 3750 | { |
| 3751 | int trans_lp; /* time required for a LP transition, in TXBYTECLKHS */ |
| 3752 | int tlp_avail; /* time left for interleaving commands, in CLKIN4DDR */ |
| 3753 | int ttxclkesc; /* period of LP transmit escape clock, in CLKIN4DDR */ |
| 3754 | int thsbyte_clk = 16; /* Period of TXBYTECLKHS clock, in CLKIN4DDR */ |
| 3755 | int lp_inter; /* cmd mode data that can be interleaved, in bytes */ |
| 3756 | |
| 3757 | /* maximum LP transition time according to Scenario 1 */ |
| 3758 | trans_lp = exit_hs + max(enter_hs, 2) + 1; |
| 3759 | |
| 3760 | /* CLKIN4DDR = 16 * TXBYTECLKHS */ |
| 3761 | tlp_avail = thsbyte_clk * (blank - trans_lp); |
| 3762 | |
Archit Taneja | 2e063c3 | 2012-06-04 13:36:34 +0530 | [diff] [blame] | 3763 | ttxclkesc = tdsi_fclk * lp_clk_div; |
Archit Taneja | 6f28c29 | 2012-05-15 11:32:18 +0530 | [diff] [blame] | 3764 | |
| 3765 | lp_inter = ((tlp_avail - 8 * thsbyte_clk - 5 * tdsi_fclk) / ttxclkesc - |
| 3766 | 26) / 16; |
| 3767 | |
| 3768 | return max(lp_inter, 0); |
| 3769 | } |
| 3770 | |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 3771 | static void dsi_config_cmd_mode_interleaving(struct platform_device *dsidev) |
Archit Taneja | 6f28c29 | 2012-05-15 11:32:18 +0530 | [diff] [blame] | 3772 | { |
Archit Taneja | 6f28c29 | 2012-05-15 11:32:18 +0530 | [diff] [blame] | 3773 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 3774 | int blanking_mode; |
| 3775 | int hfp_blanking_mode, hbp_blanking_mode, hsa_blanking_mode; |
| 3776 | int hsa, hfp, hbp, width_bytes, bllp, lp_clk_div; |
| 3777 | int ddr_clk_pre, ddr_clk_post, enter_hs_mode_lat, exit_hs_mode_lat; |
| 3778 | int tclk_trail, ths_exit, exiths_clk; |
| 3779 | bool ddr_alwon; |
Archit Taneja | e67458a | 2012-08-13 14:17:30 +0530 | [diff] [blame] | 3780 | struct omap_video_timings *timings = &dsi->timings; |
Archit Taneja | 02c3960 | 2012-08-10 15:01:33 +0530 | [diff] [blame] | 3781 | int bpp = dsi_get_pixel_size(dsi->pix_fmt); |
Archit Taneja | 6f28c29 | 2012-05-15 11:32:18 +0530 | [diff] [blame] | 3782 | int ndl = dsi->num_lanes_used - 1; |
Tomi Valkeinen | a0d269e | 2012-11-27 17:05:54 +0200 | [diff] [blame] | 3783 | int dsi_fclk_hsdiv = dsi->user_dsi_cinfo.regm_dsi + 1; |
Archit Taneja | 6f28c29 | 2012-05-15 11:32:18 +0530 | [diff] [blame] | 3784 | int hsa_interleave_hs = 0, hsa_interleave_lp = 0; |
| 3785 | int hfp_interleave_hs = 0, hfp_interleave_lp = 0; |
| 3786 | int hbp_interleave_hs = 0, hbp_interleave_lp = 0; |
| 3787 | int bl_interleave_hs = 0, bl_interleave_lp = 0; |
| 3788 | u32 r; |
| 3789 | |
| 3790 | r = dsi_read_reg(dsidev, DSI_CTRL); |
| 3791 | blanking_mode = FLD_GET(r, 20, 20); |
| 3792 | hfp_blanking_mode = FLD_GET(r, 21, 21); |
| 3793 | hbp_blanking_mode = FLD_GET(r, 22, 22); |
| 3794 | hsa_blanking_mode = FLD_GET(r, 23, 23); |
| 3795 | |
| 3796 | r = dsi_read_reg(dsidev, DSI_VM_TIMING1); |
| 3797 | hbp = FLD_GET(r, 11, 0); |
| 3798 | hfp = FLD_GET(r, 23, 12); |
| 3799 | hsa = FLD_GET(r, 31, 24); |
| 3800 | |
| 3801 | r = dsi_read_reg(dsidev, DSI_CLK_TIMING); |
| 3802 | ddr_clk_post = FLD_GET(r, 7, 0); |
| 3803 | ddr_clk_pre = FLD_GET(r, 15, 8); |
| 3804 | |
| 3805 | r = dsi_read_reg(dsidev, DSI_VM_TIMING7); |
| 3806 | exit_hs_mode_lat = FLD_GET(r, 15, 0); |
| 3807 | enter_hs_mode_lat = FLD_GET(r, 31, 16); |
| 3808 | |
| 3809 | r = dsi_read_reg(dsidev, DSI_CLK_CTRL); |
| 3810 | lp_clk_div = FLD_GET(r, 12, 0); |
| 3811 | ddr_alwon = FLD_GET(r, 13, 13); |
| 3812 | |
| 3813 | r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0); |
| 3814 | ths_exit = FLD_GET(r, 7, 0); |
| 3815 | |
| 3816 | r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1); |
| 3817 | tclk_trail = FLD_GET(r, 15, 8); |
| 3818 | |
| 3819 | exiths_clk = ths_exit + tclk_trail; |
| 3820 | |
| 3821 | width_bytes = DIV_ROUND_UP(timings->x_res * bpp, 8); |
| 3822 | bllp = hbp + hfp + hsa + DIV_ROUND_UP(width_bytes + 6, ndl); |
| 3823 | |
| 3824 | if (!hsa_blanking_mode) { |
| 3825 | hsa_interleave_hs = dsi_compute_interleave_hs(hsa, ddr_alwon, |
| 3826 | enter_hs_mode_lat, exit_hs_mode_lat, |
| 3827 | exiths_clk, ddr_clk_pre, ddr_clk_post); |
| 3828 | hsa_interleave_lp = dsi_compute_interleave_lp(hsa, |
| 3829 | enter_hs_mode_lat, exit_hs_mode_lat, |
| 3830 | lp_clk_div, dsi_fclk_hsdiv); |
| 3831 | } |
| 3832 | |
| 3833 | if (!hfp_blanking_mode) { |
| 3834 | hfp_interleave_hs = dsi_compute_interleave_hs(hfp, ddr_alwon, |
| 3835 | enter_hs_mode_lat, exit_hs_mode_lat, |
| 3836 | exiths_clk, ddr_clk_pre, ddr_clk_post); |
| 3837 | hfp_interleave_lp = dsi_compute_interleave_lp(hfp, |
| 3838 | enter_hs_mode_lat, exit_hs_mode_lat, |
| 3839 | lp_clk_div, dsi_fclk_hsdiv); |
| 3840 | } |
| 3841 | |
| 3842 | if (!hbp_blanking_mode) { |
| 3843 | hbp_interleave_hs = dsi_compute_interleave_hs(hbp, ddr_alwon, |
| 3844 | enter_hs_mode_lat, exit_hs_mode_lat, |
| 3845 | exiths_clk, ddr_clk_pre, ddr_clk_post); |
| 3846 | |
| 3847 | hbp_interleave_lp = dsi_compute_interleave_lp(hbp, |
| 3848 | enter_hs_mode_lat, exit_hs_mode_lat, |
| 3849 | lp_clk_div, dsi_fclk_hsdiv); |
| 3850 | } |
| 3851 | |
| 3852 | if (!blanking_mode) { |
| 3853 | bl_interleave_hs = dsi_compute_interleave_hs(bllp, ddr_alwon, |
| 3854 | enter_hs_mode_lat, exit_hs_mode_lat, |
| 3855 | exiths_clk, ddr_clk_pre, ddr_clk_post); |
| 3856 | |
| 3857 | bl_interleave_lp = dsi_compute_interleave_lp(bllp, |
| 3858 | enter_hs_mode_lat, exit_hs_mode_lat, |
| 3859 | lp_clk_div, dsi_fclk_hsdiv); |
| 3860 | } |
| 3861 | |
| 3862 | DSSDBG("DSI HS interleaving(TXBYTECLKHS) HSA %d, HFP %d, HBP %d, BLLP %d\n", |
| 3863 | hsa_interleave_hs, hfp_interleave_hs, hbp_interleave_hs, |
| 3864 | bl_interleave_hs); |
| 3865 | |
| 3866 | DSSDBG("DSI LP interleaving(bytes) HSA %d, HFP %d, HBP %d, BLLP %d\n", |
| 3867 | hsa_interleave_lp, hfp_interleave_lp, hbp_interleave_lp, |
| 3868 | bl_interleave_lp); |
| 3869 | |
| 3870 | r = dsi_read_reg(dsidev, DSI_VM_TIMING4); |
| 3871 | r = FLD_MOD(r, hsa_interleave_hs, 23, 16); |
| 3872 | r = FLD_MOD(r, hfp_interleave_hs, 15, 8); |
| 3873 | r = FLD_MOD(r, hbp_interleave_hs, 7, 0); |
| 3874 | dsi_write_reg(dsidev, DSI_VM_TIMING4, r); |
| 3875 | |
| 3876 | r = dsi_read_reg(dsidev, DSI_VM_TIMING5); |
| 3877 | r = FLD_MOD(r, hsa_interleave_lp, 23, 16); |
| 3878 | r = FLD_MOD(r, hfp_interleave_lp, 15, 8); |
| 3879 | r = FLD_MOD(r, hbp_interleave_lp, 7, 0); |
| 3880 | dsi_write_reg(dsidev, DSI_VM_TIMING5, r); |
| 3881 | |
| 3882 | r = dsi_read_reg(dsidev, DSI_VM_TIMING6); |
| 3883 | r = FLD_MOD(r, bl_interleave_hs, 31, 15); |
| 3884 | r = FLD_MOD(r, bl_interleave_lp, 16, 0); |
| 3885 | dsi_write_reg(dsidev, DSI_VM_TIMING6, r); |
| 3886 | } |
| 3887 | |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 3888 | static int dsi_proto_config(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3889 | { |
Archit Taneja | 02c3960 | 2012-08-10 15:01:33 +0530 | [diff] [blame] | 3890 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3891 | u32 r; |
| 3892 | int buswidth = 0; |
| 3893 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3894 | dsi_config_tx_fifo(dsidev, DSI_FIFO_SIZE_32, |
Tomi Valkeinen | dd8079d | 2009-12-16 16:49:03 +0200 | [diff] [blame] | 3895 | DSI_FIFO_SIZE_32, |
| 3896 | DSI_FIFO_SIZE_32, |
| 3897 | DSI_FIFO_SIZE_32); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3898 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3899 | dsi_config_rx_fifo(dsidev, DSI_FIFO_SIZE_32, |
Tomi Valkeinen | dd8079d | 2009-12-16 16:49:03 +0200 | [diff] [blame] | 3900 | DSI_FIFO_SIZE_32, |
| 3901 | DSI_FIFO_SIZE_32, |
| 3902 | DSI_FIFO_SIZE_32); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3903 | |
| 3904 | /* XXX what values for the timeouts? */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3905 | dsi_set_stop_state_counter(dsidev, 0x1000, false, false); |
| 3906 | dsi_set_ta_timeout(dsidev, 0x1fff, true, true); |
| 3907 | dsi_set_lp_rx_timeout(dsidev, 0x1fff, true, true); |
| 3908 | dsi_set_hs_tx_timeout(dsidev, 0x1fff, true, true); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3909 | |
Archit Taneja | 02c3960 | 2012-08-10 15:01:33 +0530 | [diff] [blame] | 3910 | switch (dsi_get_pixel_size(dsi->pix_fmt)) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3911 | case 16: |
| 3912 | buswidth = 0; |
| 3913 | break; |
| 3914 | case 18: |
| 3915 | buswidth = 1; |
| 3916 | break; |
| 3917 | case 24: |
| 3918 | buswidth = 2; |
| 3919 | break; |
| 3920 | default: |
| 3921 | BUG(); |
Tomi Valkeinen | c6eee96 | 2012-05-18 11:47:02 +0300 | [diff] [blame] | 3922 | return -EINVAL; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3923 | } |
| 3924 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3925 | r = dsi_read_reg(dsidev, DSI_CTRL); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3926 | r = FLD_MOD(r, 1, 1, 1); /* CS_RX_EN */ |
| 3927 | r = FLD_MOD(r, 1, 2, 2); /* ECC_RX_EN */ |
| 3928 | r = FLD_MOD(r, 1, 3, 3); /* TX_FIFO_ARBITRATION */ |
| 3929 | r = FLD_MOD(r, 1, 4, 4); /* VP_CLK_RATIO, always 1, see errata*/ |
| 3930 | r = FLD_MOD(r, buswidth, 7, 6); /* VP_DATA_BUS_WIDTH */ |
| 3931 | r = FLD_MOD(r, 0, 8, 8); /* VP_CLK_POL */ |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3932 | r = FLD_MOD(r, 1, 14, 14); /* TRIGGER_RESET_MODE */ |
| 3933 | r = FLD_MOD(r, 1, 19, 19); /* EOT_ENABLE */ |
Archit Taneja | 9613c02 | 2011-03-22 06:33:36 -0500 | [diff] [blame] | 3934 | if (!dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC)) { |
| 3935 | r = FLD_MOD(r, 1, 24, 24); /* DCS_CMD_ENABLE */ |
| 3936 | /* DCS_CMD_CODE, 1=start, 0=continue */ |
| 3937 | r = FLD_MOD(r, 0, 25, 25); |
| 3938 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3939 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3940 | dsi_write_reg(dsidev, DSI_CTRL, r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3941 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 3942 | dsi_config_vp_num_line_buffers(dsidev); |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3943 | |
Archit Taneja | dca2b15 | 2012-08-16 18:02:00 +0530 | [diff] [blame] | 3944 | if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) { |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 3945 | dsi_config_vp_sync_events(dsidev); |
| 3946 | dsi_config_blanking_modes(dsidev); |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 3947 | dsi_config_cmd_mode_interleaving(dsidev); |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3948 | } |
| 3949 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3950 | dsi_vc_initial_config(dsidev, 0); |
| 3951 | dsi_vc_initial_config(dsidev, 1); |
| 3952 | dsi_vc_initial_config(dsidev, 2); |
| 3953 | dsi_vc_initial_config(dsidev, 3); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3954 | |
| 3955 | return 0; |
| 3956 | } |
| 3957 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 3958 | static void dsi_proto_timings(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3959 | { |
Tomi Valkeinen | db18644 | 2011-10-13 16:12:29 +0300 | [diff] [blame] | 3960 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3961 | unsigned tlpx, tclk_zero, tclk_prepare, tclk_trail; |
| 3962 | unsigned tclk_pre, tclk_post; |
| 3963 | unsigned ths_prepare, ths_prepare_ths_zero, ths_zero; |
| 3964 | unsigned ths_trail, ths_exit; |
| 3965 | unsigned ddr_clk_pre, ddr_clk_post; |
| 3966 | unsigned enter_hs_mode_lat, exit_hs_mode_lat; |
| 3967 | unsigned ths_eot; |
Tomi Valkeinen | db18644 | 2011-10-13 16:12:29 +0300 | [diff] [blame] | 3968 | int ndl = dsi->num_lanes_used - 1; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3969 | u32 r; |
| 3970 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3971 | r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3972 | ths_prepare = FLD_GET(r, 31, 24); |
| 3973 | ths_prepare_ths_zero = FLD_GET(r, 23, 16); |
| 3974 | ths_zero = ths_prepare_ths_zero - ths_prepare; |
| 3975 | ths_trail = FLD_GET(r, 15, 8); |
| 3976 | ths_exit = FLD_GET(r, 7, 0); |
| 3977 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3978 | r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1); |
Tomi Valkeinen | e84dc1c | 2012-09-24 09:34:52 +0300 | [diff] [blame] | 3979 | tlpx = FLD_GET(r, 20, 16) * 2; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3980 | tclk_trail = FLD_GET(r, 15, 8); |
| 3981 | tclk_zero = FLD_GET(r, 7, 0); |
| 3982 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3983 | r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG2); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3984 | tclk_prepare = FLD_GET(r, 7, 0); |
| 3985 | |
| 3986 | /* min 8*UI */ |
| 3987 | tclk_pre = 20; |
| 3988 | /* min 60ns + 52*UI */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3989 | tclk_post = ns2ddr(dsidev, 60) + 26; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3990 | |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3991 | ths_eot = DIV_ROUND_UP(4, ndl); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3992 | |
| 3993 | ddr_clk_pre = DIV_ROUND_UP(tclk_pre + tlpx + tclk_zero + tclk_prepare, |
| 3994 | 4); |
| 3995 | ddr_clk_post = DIV_ROUND_UP(tclk_post + ths_trail, 4) + ths_eot; |
| 3996 | |
| 3997 | BUG_ON(ddr_clk_pre == 0 || ddr_clk_pre > 255); |
| 3998 | BUG_ON(ddr_clk_post == 0 || ddr_clk_post > 255); |
| 3999 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4000 | r = dsi_read_reg(dsidev, DSI_CLK_TIMING); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4001 | r = FLD_MOD(r, ddr_clk_pre, 15, 8); |
| 4002 | r = FLD_MOD(r, ddr_clk_post, 7, 0); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4003 | dsi_write_reg(dsidev, DSI_CLK_TIMING, r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4004 | |
| 4005 | DSSDBG("ddr_clk_pre %u, ddr_clk_post %u\n", |
| 4006 | ddr_clk_pre, |
| 4007 | ddr_clk_post); |
| 4008 | |
| 4009 | enter_hs_mode_lat = 1 + DIV_ROUND_UP(tlpx, 4) + |
| 4010 | DIV_ROUND_UP(ths_prepare, 4) + |
| 4011 | DIV_ROUND_UP(ths_zero + 3, 4); |
| 4012 | |
| 4013 | exit_hs_mode_lat = DIV_ROUND_UP(ths_trail + ths_exit, 4) + 1 + ths_eot; |
| 4014 | |
| 4015 | r = FLD_VAL(enter_hs_mode_lat, 31, 16) | |
| 4016 | FLD_VAL(exit_hs_mode_lat, 15, 0); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4017 | dsi_write_reg(dsidev, DSI_VM_TIMING7, r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4018 | |
| 4019 | DSSDBG("enter_hs_mode_lat %u, exit_hs_mode_lat %u\n", |
| 4020 | enter_hs_mode_lat, exit_hs_mode_lat); |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4021 | |
Archit Taneja | dca2b15 | 2012-08-16 18:02:00 +0530 | [diff] [blame] | 4022 | if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) { |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4023 | /* TODO: Implement a video mode check_timings function */ |
Archit Taneja | 0b3ffe3 | 2012-08-13 22:13:39 +0530 | [diff] [blame] | 4024 | int hsa = dsi->vm_timings.hsa; |
| 4025 | int hfp = dsi->vm_timings.hfp; |
| 4026 | int hbp = dsi->vm_timings.hbp; |
| 4027 | int vsa = dsi->vm_timings.vsa; |
| 4028 | int vfp = dsi->vm_timings.vfp; |
| 4029 | int vbp = dsi->vm_timings.vbp; |
| 4030 | int window_sync = dsi->vm_timings.window_sync; |
Tomi Valkeinen | 478d7df | 2013-03-05 16:29:36 +0200 | [diff] [blame] | 4031 | bool hsync_end; |
Archit Taneja | e67458a | 2012-08-13 14:17:30 +0530 | [diff] [blame] | 4032 | struct omap_video_timings *timings = &dsi->timings; |
Archit Taneja | 02c3960 | 2012-08-10 15:01:33 +0530 | [diff] [blame] | 4033 | int bpp = dsi_get_pixel_size(dsi->pix_fmt); |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4034 | int tl, t_he, width_bytes; |
| 4035 | |
Tomi Valkeinen | 478d7df | 2013-03-05 16:29:36 +0200 | [diff] [blame] | 4036 | hsync_end = dsi->vm_timings.trans_mode == OMAP_DSS_DSI_PULSE_MODE; |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4037 | t_he = hsync_end ? |
| 4038 | ((hsa == 0 && ndl == 3) ? 1 : DIV_ROUND_UP(4, ndl)) : 0; |
| 4039 | |
| 4040 | width_bytes = DIV_ROUND_UP(timings->x_res * bpp, 8); |
| 4041 | |
| 4042 | /* TL = t_HS + HSA + t_HE + HFP + ceil((WC + 6) / NDL) + HBP */ |
| 4043 | tl = DIV_ROUND_UP(4, ndl) + (hsync_end ? hsa : 0) + t_he + hfp + |
| 4044 | DIV_ROUND_UP(width_bytes + 6, ndl) + hbp; |
| 4045 | |
| 4046 | DSSDBG("HBP: %d, HFP: %d, HSA: %d, TL: %d TXBYTECLKHS\n", hbp, |
| 4047 | hfp, hsync_end ? hsa : 0, tl); |
| 4048 | DSSDBG("VBP: %d, VFP: %d, VSA: %d, VACT: %d lines\n", vbp, vfp, |
| 4049 | vsa, timings->y_res); |
| 4050 | |
| 4051 | r = dsi_read_reg(dsidev, DSI_VM_TIMING1); |
| 4052 | r = FLD_MOD(r, hbp, 11, 0); /* HBP */ |
| 4053 | r = FLD_MOD(r, hfp, 23, 12); /* HFP */ |
| 4054 | r = FLD_MOD(r, hsync_end ? hsa : 0, 31, 24); /* HSA */ |
| 4055 | dsi_write_reg(dsidev, DSI_VM_TIMING1, r); |
| 4056 | |
| 4057 | r = dsi_read_reg(dsidev, DSI_VM_TIMING2); |
| 4058 | r = FLD_MOD(r, vbp, 7, 0); /* VBP */ |
| 4059 | r = FLD_MOD(r, vfp, 15, 8); /* VFP */ |
| 4060 | r = FLD_MOD(r, vsa, 23, 16); /* VSA */ |
| 4061 | r = FLD_MOD(r, window_sync, 27, 24); /* WINDOW_SYNC */ |
| 4062 | dsi_write_reg(dsidev, DSI_VM_TIMING2, r); |
| 4063 | |
| 4064 | r = dsi_read_reg(dsidev, DSI_VM_TIMING3); |
| 4065 | r = FLD_MOD(r, timings->y_res, 14, 0); /* VACT */ |
| 4066 | r = FLD_MOD(r, tl, 31, 16); /* TL */ |
| 4067 | dsi_write_reg(dsidev, DSI_VM_TIMING3, r); |
| 4068 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4069 | } |
| 4070 | |
Tomi Valkeinen | e4a9e94 | 2012-03-28 15:58:56 +0300 | [diff] [blame] | 4071 | int omapdss_dsi_configure_pins(struct omap_dss_device *dssdev, |
| 4072 | const struct omap_dsi_pin_config *pin_cfg) |
| 4073 | { |
| 4074 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 4075 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 4076 | int num_pins; |
| 4077 | const int *pins; |
| 4078 | struct dsi_lane_config lanes[DSI_MAX_NR_LANES]; |
| 4079 | int num_lanes; |
| 4080 | int i; |
| 4081 | |
| 4082 | static const enum dsi_lane_function functions[] = { |
| 4083 | DSI_LANE_CLK, |
| 4084 | DSI_LANE_DATA1, |
| 4085 | DSI_LANE_DATA2, |
| 4086 | DSI_LANE_DATA3, |
| 4087 | DSI_LANE_DATA4, |
| 4088 | }; |
| 4089 | |
| 4090 | num_pins = pin_cfg->num_pins; |
| 4091 | pins = pin_cfg->pins; |
| 4092 | |
| 4093 | if (num_pins < 4 || num_pins > dsi->num_lanes_supported * 2 |
| 4094 | || num_pins % 2 != 0) |
| 4095 | return -EINVAL; |
| 4096 | |
| 4097 | for (i = 0; i < DSI_MAX_NR_LANES; ++i) |
| 4098 | lanes[i].function = DSI_LANE_UNUSED; |
| 4099 | |
| 4100 | num_lanes = 0; |
| 4101 | |
| 4102 | for (i = 0; i < num_pins; i += 2) { |
| 4103 | u8 lane, pol; |
| 4104 | int dx, dy; |
| 4105 | |
| 4106 | dx = pins[i]; |
| 4107 | dy = pins[i + 1]; |
| 4108 | |
| 4109 | if (dx < 0 || dx >= dsi->num_lanes_supported * 2) |
| 4110 | return -EINVAL; |
| 4111 | |
| 4112 | if (dy < 0 || dy >= dsi->num_lanes_supported * 2) |
| 4113 | return -EINVAL; |
| 4114 | |
| 4115 | if (dx & 1) { |
| 4116 | if (dy != dx - 1) |
| 4117 | return -EINVAL; |
| 4118 | pol = 1; |
| 4119 | } else { |
| 4120 | if (dy != dx + 1) |
| 4121 | return -EINVAL; |
| 4122 | pol = 0; |
| 4123 | } |
| 4124 | |
| 4125 | lane = dx / 2; |
| 4126 | |
| 4127 | lanes[lane].function = functions[i / 2]; |
| 4128 | lanes[lane].polarity = pol; |
| 4129 | num_lanes++; |
| 4130 | } |
| 4131 | |
| 4132 | memcpy(dsi->lanes, lanes, sizeof(dsi->lanes)); |
| 4133 | dsi->num_lanes_used = num_lanes; |
| 4134 | |
| 4135 | return 0; |
| 4136 | } |
| 4137 | EXPORT_SYMBOL(omapdss_dsi_configure_pins); |
| 4138 | |
Tomi Valkeinen | 9a147a6 | 2011-11-09 15:30:11 +0200 | [diff] [blame] | 4139 | int dsi_enable_video_output(struct omap_dss_device *dssdev, int channel) |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4140 | { |
| 4141 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Archit Taneja | e67458a | 2012-08-13 14:17:30 +0530 | [diff] [blame] | 4142 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 4143 | struct omap_overlay_manager *mgr = dsi->output.manager; |
Archit Taneja | 02c3960 | 2012-08-10 15:01:33 +0530 | [diff] [blame] | 4144 | int bpp = dsi_get_pixel_size(dsi->pix_fmt); |
Tomi Valkeinen | 1f68d9c | 2013-04-19 15:09:34 +0300 | [diff] [blame] | 4145 | struct omap_dss_device *out = &dsi->output; |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4146 | u8 data_type; |
| 4147 | u16 word_count; |
Tomi Valkeinen | 33ca237 | 2011-11-21 13:42:58 +0200 | [diff] [blame] | 4148 | int r; |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4149 | |
Tomi Valkeinen | b7dec9b | 2013-02-22 12:58:35 +0200 | [diff] [blame] | 4150 | if (out == NULL || out->manager == NULL) { |
| 4151 | DSSERR("failed to enable display: no output/manager\n"); |
| 4152 | return -ENODEV; |
| 4153 | } |
| 4154 | |
| 4155 | r = dsi_display_init_dispc(dsidev, mgr); |
| 4156 | if (r) |
| 4157 | goto err_init_dispc; |
| 4158 | |
Archit Taneja | dca2b15 | 2012-08-16 18:02:00 +0530 | [diff] [blame] | 4159 | if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) { |
Archit Taneja | 02c3960 | 2012-08-10 15:01:33 +0530 | [diff] [blame] | 4160 | switch (dsi->pix_fmt) { |
Tomi Valkeinen | 9a147a6 | 2011-11-09 15:30:11 +0200 | [diff] [blame] | 4161 | case OMAP_DSS_DSI_FMT_RGB888: |
| 4162 | data_type = MIPI_DSI_PACKED_PIXEL_STREAM_24; |
| 4163 | break; |
| 4164 | case OMAP_DSS_DSI_FMT_RGB666: |
| 4165 | data_type = MIPI_DSI_PIXEL_STREAM_3BYTE_18; |
| 4166 | break; |
| 4167 | case OMAP_DSS_DSI_FMT_RGB666_PACKED: |
| 4168 | data_type = MIPI_DSI_PACKED_PIXEL_STREAM_18; |
| 4169 | break; |
| 4170 | case OMAP_DSS_DSI_FMT_RGB565: |
| 4171 | data_type = MIPI_DSI_PACKED_PIXEL_STREAM_16; |
| 4172 | break; |
| 4173 | default: |
Tomi Valkeinen | b7dec9b | 2013-02-22 12:58:35 +0200 | [diff] [blame] | 4174 | r = -EINVAL; |
| 4175 | goto err_pix_fmt; |
Tomi Valkeinen | 9a147a6 | 2011-11-09 15:30:11 +0200 | [diff] [blame] | 4176 | }; |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4177 | |
Tomi Valkeinen | 9a147a6 | 2011-11-09 15:30:11 +0200 | [diff] [blame] | 4178 | dsi_if_enable(dsidev, false); |
| 4179 | dsi_vc_enable(dsidev, channel, false); |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4180 | |
Tomi Valkeinen | 9a147a6 | 2011-11-09 15:30:11 +0200 | [diff] [blame] | 4181 | /* MODE, 1 = video mode */ |
| 4182 | REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 4, 4); |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4183 | |
Archit Taneja | e67458a | 2012-08-13 14:17:30 +0530 | [diff] [blame] | 4184 | word_count = DIV_ROUND_UP(dsi->timings.x_res * bpp, 8); |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4185 | |
Tomi Valkeinen | 9a147a6 | 2011-11-09 15:30:11 +0200 | [diff] [blame] | 4186 | dsi_vc_write_long_header(dsidev, channel, data_type, |
| 4187 | word_count, 0); |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4188 | |
Tomi Valkeinen | 9a147a6 | 2011-11-09 15:30:11 +0200 | [diff] [blame] | 4189 | dsi_vc_enable(dsidev, channel, true); |
| 4190 | dsi_if_enable(dsidev, true); |
| 4191 | } |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4192 | |
Archit Taneja | eea8340 | 2012-09-04 11:42:36 +0530 | [diff] [blame] | 4193 | r = dss_mgr_enable(mgr); |
Tomi Valkeinen | b7dec9b | 2013-02-22 12:58:35 +0200 | [diff] [blame] | 4194 | if (r) |
| 4195 | goto err_mgr_enable; |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4196 | |
| 4197 | return 0; |
Tomi Valkeinen | b7dec9b | 2013-02-22 12:58:35 +0200 | [diff] [blame] | 4198 | |
| 4199 | err_mgr_enable: |
| 4200 | if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) { |
| 4201 | dsi_if_enable(dsidev, false); |
| 4202 | dsi_vc_enable(dsidev, channel, false); |
| 4203 | } |
| 4204 | err_pix_fmt: |
| 4205 | dsi_display_uninit_dispc(dsidev, mgr); |
| 4206 | err_init_dispc: |
| 4207 | return r; |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4208 | } |
Tomi Valkeinen | 9a147a6 | 2011-11-09 15:30:11 +0200 | [diff] [blame] | 4209 | EXPORT_SYMBOL(dsi_enable_video_output); |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4210 | |
Tomi Valkeinen | 9a147a6 | 2011-11-09 15:30:11 +0200 | [diff] [blame] | 4211 | void dsi_disable_video_output(struct omap_dss_device *dssdev, int channel) |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4212 | { |
| 4213 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Archit Taneja | dca2b15 | 2012-08-16 18:02:00 +0530 | [diff] [blame] | 4214 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 4215 | struct omap_overlay_manager *mgr = dsi->output.manager; |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4216 | |
Archit Taneja | dca2b15 | 2012-08-16 18:02:00 +0530 | [diff] [blame] | 4217 | if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) { |
Tomi Valkeinen | 9a147a6 | 2011-11-09 15:30:11 +0200 | [diff] [blame] | 4218 | dsi_if_enable(dsidev, false); |
| 4219 | dsi_vc_enable(dsidev, channel, false); |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4220 | |
Tomi Valkeinen | 9a147a6 | 2011-11-09 15:30:11 +0200 | [diff] [blame] | 4221 | /* MODE, 0 = command mode */ |
| 4222 | REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 0, 4, 4); |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4223 | |
Tomi Valkeinen | 9a147a6 | 2011-11-09 15:30:11 +0200 | [diff] [blame] | 4224 | dsi_vc_enable(dsidev, channel, true); |
| 4225 | dsi_if_enable(dsidev, true); |
| 4226 | } |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4227 | |
Archit Taneja | eea8340 | 2012-09-04 11:42:36 +0530 | [diff] [blame] | 4228 | dss_mgr_disable(mgr); |
Tomi Valkeinen | b7dec9b | 2013-02-22 12:58:35 +0200 | [diff] [blame] | 4229 | |
| 4230 | dsi_display_uninit_dispc(dsidev, mgr); |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4231 | } |
Tomi Valkeinen | 9a147a6 | 2011-11-09 15:30:11 +0200 | [diff] [blame] | 4232 | EXPORT_SYMBOL(dsi_disable_video_output); |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4233 | |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 4234 | static void dsi_update_screen_dispc(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4235 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4236 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 4237 | struct omap_overlay_manager *mgr = dsi->output.manager; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4238 | unsigned bytespp; |
| 4239 | unsigned bytespl; |
| 4240 | unsigned bytespf; |
| 4241 | unsigned total_len; |
| 4242 | unsigned packet_payload; |
| 4243 | unsigned packet_len; |
| 4244 | u32 l; |
Tomi Valkeinen | 0f16aa0 | 2010-04-12 09:57:19 +0300 | [diff] [blame] | 4245 | int r; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4246 | const unsigned channel = dsi->update_channel; |
Tomi Valkeinen | 9932257 | 2013-03-05 10:37:02 +0200 | [diff] [blame] | 4247 | const unsigned line_buf_size = dsi->line_buffer_size; |
Archit Taneja | 55cd63a | 2012-08-09 15:41:13 +0530 | [diff] [blame] | 4248 | u16 w = dsi->timings.x_res; |
| 4249 | u16 h = dsi->timings.y_res; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4250 | |
Tomi Valkeinen | 5476e74 | 2011-11-03 16:34:20 +0200 | [diff] [blame] | 4251 | DSSDBG("dsi_update_screen_dispc(%dx%d)\n", w, h); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4252 | |
Archit Taneja | d604914 | 2011-08-22 11:58:08 +0530 | [diff] [blame] | 4253 | dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_VP); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 4254 | |
Archit Taneja | 02c3960 | 2012-08-10 15:01:33 +0530 | [diff] [blame] | 4255 | bytespp = dsi_get_pixel_size(dsi->pix_fmt) / 8; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4256 | bytespl = w * bytespp; |
| 4257 | bytespf = bytespl * h; |
| 4258 | |
| 4259 | /* NOTE: packet_payload has to be equal to N * bytespl, where N is |
| 4260 | * number of lines in a packet. See errata about VP_CLK_RATIO */ |
| 4261 | |
| 4262 | if (bytespf < line_buf_size) |
| 4263 | packet_payload = bytespf; |
| 4264 | else |
| 4265 | packet_payload = (line_buf_size) / bytespl * bytespl; |
| 4266 | |
| 4267 | packet_len = packet_payload + 1; /* 1 byte for DCS cmd */ |
| 4268 | total_len = (bytespf / packet_payload) * packet_len; |
| 4269 | |
| 4270 | if (bytespf % packet_payload) |
| 4271 | total_len += (bytespf % packet_payload) + 1; |
| 4272 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4273 | l = FLD_VAL(total_len, 23, 0); /* TE_SIZE */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4274 | dsi_write_reg(dsidev, DSI_VC_TE(channel), l); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4275 | |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 4276 | dsi_vc_write_long_header(dsidev, channel, MIPI_DSI_DCS_LONG_WRITE, |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4277 | packet_len, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4278 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4279 | if (dsi->te_enabled) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4280 | l = FLD_MOD(l, 1, 30, 30); /* TE_EN */ |
| 4281 | else |
| 4282 | l = FLD_MOD(l, 1, 31, 31); /* TE_START */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4283 | dsi_write_reg(dsidev, DSI_VC_TE(channel), l); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4284 | |
| 4285 | /* We put SIDLEMODE to no-idle for the duration of the transfer, |
| 4286 | * because DSS interrupts are not capable of waking up the CPU and the |
| 4287 | * framedone interrupt could be delayed for quite a long time. I think |
| 4288 | * the same goes for any DSS interrupts, but for some reason I have not |
| 4289 | * seen the problem anywhere else than here. |
| 4290 | */ |
| 4291 | dispc_disable_sidle(); |
| 4292 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4293 | dsi_perf_mark_start(dsidev); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 4294 | |
Archit Taneja | 49dbf58 | 2011-05-16 15:17:07 +0530 | [diff] [blame] | 4295 | r = schedule_delayed_work(&dsi->framedone_timeout_work, |
| 4296 | msecs_to_jiffies(250)); |
Tomi Valkeinen | 0f16aa0 | 2010-04-12 09:57:19 +0300 | [diff] [blame] | 4297 | BUG_ON(r == 0); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 4298 | |
Archit Taneja | eea8340 | 2012-09-04 11:42:36 +0530 | [diff] [blame] | 4299 | dss_mgr_set_timings(mgr, &dsi->timings); |
Archit Taneja | 55cd63a | 2012-08-09 15:41:13 +0530 | [diff] [blame] | 4300 | |
Archit Taneja | eea8340 | 2012-09-04 11:42:36 +0530 | [diff] [blame] | 4301 | dss_mgr_start_update(mgr); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4302 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4303 | if (dsi->te_enabled) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4304 | /* disable LP_RX_TO, so that we can receive TE. Time to wait |
| 4305 | * for TE is longer than the timer allows */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4306 | REG_FLD_MOD(dsidev, DSI_TIMING2, 0, 15, 15); /* LP_RX_TO */ |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4307 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4308 | dsi_vc_send_bta(dsidev, channel); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4309 | |
| 4310 | #ifdef DSI_CATCH_MISSING_TE |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4311 | mod_timer(&dsi->te_timer, jiffies + msecs_to_jiffies(250)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4312 | #endif |
| 4313 | } |
| 4314 | } |
| 4315 | |
| 4316 | #ifdef DSI_CATCH_MISSING_TE |
| 4317 | static void dsi_te_timeout(unsigned long arg) |
| 4318 | { |
| 4319 | DSSERR("TE not received for 250ms!\n"); |
| 4320 | } |
| 4321 | #endif |
| 4322 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4323 | static void dsi_handle_framedone(struct platform_device *dsidev, int error) |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 4324 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4325 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 4326 | |
Tomi Valkeinen | ab83b14 | 2010-06-09 15:31:01 +0300 | [diff] [blame] | 4327 | /* SIDLEMODE back to smart-idle */ |
| 4328 | dispc_enable_sidle(); |
| 4329 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4330 | if (dsi->te_enabled) { |
Tomi Valkeinen | ab83b14 | 2010-06-09 15:31:01 +0300 | [diff] [blame] | 4331 | /* enable LP_RX_TO again after the TE */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4332 | REG_FLD_MOD(dsidev, DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */ |
Tomi Valkeinen | ab83b14 | 2010-06-09 15:31:01 +0300 | [diff] [blame] | 4333 | } |
| 4334 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4335 | dsi->framedone_callback(error, dsi->framedone_data); |
Tomi Valkeinen | ab83b14 | 2010-06-09 15:31:01 +0300 | [diff] [blame] | 4336 | |
| 4337 | if (!error) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4338 | dsi_perf_show(dsidev, "DISPC"); |
Tomi Valkeinen | ab83b14 | 2010-06-09 15:31:01 +0300 | [diff] [blame] | 4339 | } |
| 4340 | |
| 4341 | static void dsi_framedone_timeout_work_callback(struct work_struct *work) |
| 4342 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4343 | struct dsi_data *dsi = container_of(work, struct dsi_data, |
| 4344 | framedone_timeout_work.work); |
Tomi Valkeinen | 0f16aa0 | 2010-04-12 09:57:19 +0300 | [diff] [blame] | 4345 | /* XXX While extremely unlikely, we could get FRAMEDONE interrupt after |
| 4346 | * 250ms which would conflict with this timeout work. What should be |
| 4347 | * 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] | 4348 | * possibly scheduled framedone work. However, cancelling the transfer |
| 4349 | * on the HW is buggy, and would probably require resetting the whole |
| 4350 | * DSI */ |
Tomi Valkeinen | 0f16aa0 | 2010-04-12 09:57:19 +0300 | [diff] [blame] | 4351 | |
Tomi Valkeinen | ab83b14 | 2010-06-09 15:31:01 +0300 | [diff] [blame] | 4352 | DSSERR("Framedone not received for 250ms!\n"); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 4353 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4354 | dsi_handle_framedone(dsi->pdev, -ETIMEDOUT); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 4355 | } |
| 4356 | |
Tomi Valkeinen | 1550202 | 2012-10-10 13:59:07 +0300 | [diff] [blame] | 4357 | static void dsi_framedone_irq_callback(void *data) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4358 | { |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 4359 | struct platform_device *dsidev = (struct platform_device *) data; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4360 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 4361 | |
Tomi Valkeinen | ab83b14 | 2010-06-09 15:31:01 +0300 | [diff] [blame] | 4362 | /* Note: We get FRAMEDONE when DISPC has finished sending pixels and |
| 4363 | * turns itself off. However, DSI still has the pixels in its buffers, |
| 4364 | * and is sending the data. |
| 4365 | */ |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4366 | |
Tejun Heo | 136b572 | 2012-08-21 13:18:24 -0700 | [diff] [blame] | 4367 | cancel_delayed_work(&dsi->framedone_timeout_work); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4368 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4369 | dsi_handle_framedone(dsidev, 0); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 4370 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4371 | |
Tomi Valkeinen | 5476e74 | 2011-11-03 16:34:20 +0200 | [diff] [blame] | 4372 | int omap_dsi_update(struct omap_dss_device *dssdev, int channel, |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 4373 | void (*callback)(int, void *), void *data) |
| 4374 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4375 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4376 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 5476e74 | 2011-11-03 16:34:20 +0200 | [diff] [blame] | 4377 | u16 dw, dh; |
| 4378 | |
| 4379 | dsi_perf_mark_setup(dsidev); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4380 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4381 | dsi->update_channel = channel; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4382 | |
Tomi Valkeinen | 4a9e78a | 2011-08-15 11:22:21 +0300 | [diff] [blame] | 4383 | dsi->framedone_callback = callback; |
| 4384 | dsi->framedone_data = data; |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 4385 | |
Archit Taneja | e352574 | 2012-08-09 15:23:43 +0530 | [diff] [blame] | 4386 | dw = dsi->timings.x_res; |
| 4387 | dh = dsi->timings.y_res; |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 4388 | |
Tomi Valkeinen | 5476e74 | 2011-11-03 16:34:20 +0200 | [diff] [blame] | 4389 | #ifdef DEBUG |
| 4390 | dsi->update_bytes = dw * dh * |
Archit Taneja | 02c3960 | 2012-08-10 15:01:33 +0530 | [diff] [blame] | 4391 | dsi_get_pixel_size(dsi->pix_fmt) / 8; |
Tomi Valkeinen | 5476e74 | 2011-11-03 16:34:20 +0200 | [diff] [blame] | 4392 | #endif |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 4393 | dsi_update_screen_dispc(dsidev); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 4394 | |
| 4395 | return 0; |
| 4396 | } |
| 4397 | EXPORT_SYMBOL(omap_dsi_update); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4398 | |
| 4399 | /* Display funcs */ |
| 4400 | |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 4401 | static int dsi_configure_dispc_clocks(struct platform_device *dsidev) |
Archit Taneja | 7d2572f | 2012-06-29 14:31:07 +0530 | [diff] [blame] | 4402 | { |
Archit Taneja | 7d2572f | 2012-06-29 14:31:07 +0530 | [diff] [blame] | 4403 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 4404 | struct dispc_clock_info dispc_cinfo; |
| 4405 | int r; |
Tomi Valkeinen | 1751818 | 2013-03-07 11:21:45 +0200 | [diff] [blame] | 4406 | unsigned long fck; |
Archit Taneja | 7d2572f | 2012-06-29 14:31:07 +0530 | [diff] [blame] | 4407 | |
| 4408 | fck = dsi_get_pll_hsdiv_dispc_rate(dsidev); |
| 4409 | |
Tomi Valkeinen | a0d269e | 2012-11-27 17:05:54 +0200 | [diff] [blame] | 4410 | dispc_cinfo.lck_div = dsi->user_dispc_cinfo.lck_div; |
| 4411 | dispc_cinfo.pck_div = dsi->user_dispc_cinfo.pck_div; |
Archit Taneja | 7d2572f | 2012-06-29 14:31:07 +0530 | [diff] [blame] | 4412 | |
| 4413 | r = dispc_calc_clock_rates(fck, &dispc_cinfo); |
| 4414 | if (r) { |
| 4415 | DSSERR("Failed to calc dispc clocks\n"); |
| 4416 | return r; |
| 4417 | } |
| 4418 | |
| 4419 | dsi->mgr_config.clock_info = dispc_cinfo; |
| 4420 | |
| 4421 | return 0; |
| 4422 | } |
| 4423 | |
Tomi Valkeinen | b7dec9b | 2013-02-22 12:58:35 +0200 | [diff] [blame] | 4424 | static int dsi_display_init_dispc(struct platform_device *dsidev, |
| 4425 | struct omap_overlay_manager *mgr) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4426 | { |
Archit Taneja | 7d2572f | 2012-06-29 14:31:07 +0530 | [diff] [blame] | 4427 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Archit Taneja | 7d2572f | 2012-06-29 14:31:07 +0530 | [diff] [blame] | 4428 | int r; |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 4429 | |
Tomi Valkeinen | 4ce9e33 | 2013-03-05 17:11:16 +0200 | [diff] [blame] | 4430 | dss_select_lcd_clk_source(mgr->id, dsi->module_id == 0 ? |
| 4431 | OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC : |
| 4432 | OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC); |
Tomi Valkeinen | 5476e74 | 2011-11-03 16:34:20 +0200 | [diff] [blame] | 4433 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4434 | if (dsi->mode == OMAP_DSS_DSI_CMD_MODE) { |
Tomi Valkeinen | 1550202 | 2012-10-10 13:59:07 +0300 | [diff] [blame] | 4435 | r = dss_mgr_register_framedone_handler(mgr, |
| 4436 | dsi_framedone_irq_callback, dsidev); |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4437 | if (r) { |
Tomi Valkeinen | 1550202 | 2012-10-10 13:59:07 +0300 | [diff] [blame] | 4438 | DSSERR("can't register FRAMEDONE handler\n"); |
Archit Taneja | 7d2572f | 2012-06-29 14:31:07 +0530 | [diff] [blame] | 4439 | goto err; |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4440 | } |
| 4441 | |
Archit Taneja | 7d2572f | 2012-06-29 14:31:07 +0530 | [diff] [blame] | 4442 | dsi->mgr_config.stallmode = true; |
| 4443 | dsi->mgr_config.fifohandcheck = true; |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4444 | } else { |
Archit Taneja | 7d2572f | 2012-06-29 14:31:07 +0530 | [diff] [blame] | 4445 | dsi->mgr_config.stallmode = false; |
| 4446 | dsi->mgr_config.fifohandcheck = false; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4447 | } |
| 4448 | |
Archit Taneja | bd5a7b1 | 2012-06-26 12:38:31 +0530 | [diff] [blame] | 4449 | /* |
| 4450 | * override interlace, logic level and edge related parameters in |
| 4451 | * omap_video_timings with default values |
| 4452 | */ |
Archit Taneja | e67458a | 2012-08-13 14:17:30 +0530 | [diff] [blame] | 4453 | dsi->timings.interlace = false; |
| 4454 | dsi->timings.hsync_level = OMAPDSS_SIG_ACTIVE_HIGH; |
| 4455 | dsi->timings.vsync_level = OMAPDSS_SIG_ACTIVE_HIGH; |
| 4456 | dsi->timings.data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE; |
| 4457 | dsi->timings.de_level = OMAPDSS_SIG_ACTIVE_HIGH; |
| 4458 | dsi->timings.sync_pclk_edge = OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES; |
Archit Taneja | bd5a7b1 | 2012-06-26 12:38:31 +0530 | [diff] [blame] | 4459 | |
Archit Taneja | eea8340 | 2012-09-04 11:42:36 +0530 | [diff] [blame] | 4460 | dss_mgr_set_timings(mgr, &dsi->timings); |
Archit Taneja | bd5a7b1 | 2012-06-26 12:38:31 +0530 | [diff] [blame] | 4461 | |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 4462 | r = dsi_configure_dispc_clocks(dsidev); |
Archit Taneja | 7d2572f | 2012-06-29 14:31:07 +0530 | [diff] [blame] | 4463 | if (r) |
| 4464 | goto err1; |
| 4465 | |
| 4466 | dsi->mgr_config.io_pad_mode = DSS_IO_PAD_MODE_BYPASS; |
| 4467 | dsi->mgr_config.video_port_width = |
Archit Taneja | 02c3960 | 2012-08-10 15:01:33 +0530 | [diff] [blame] | 4468 | dsi_get_pixel_size(dsi->pix_fmt); |
Archit Taneja | 7d2572f | 2012-06-29 14:31:07 +0530 | [diff] [blame] | 4469 | dsi->mgr_config.lcden_sig_polarity = 0; |
| 4470 | |
Archit Taneja | eea8340 | 2012-09-04 11:42:36 +0530 | [diff] [blame] | 4471 | dss_mgr_set_lcd_config(mgr, &dsi->mgr_config); |
Archit Taneja | d21f43b | 2012-06-21 09:45:11 +0530 | [diff] [blame] | 4472 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4473 | return 0; |
Archit Taneja | 7d2572f | 2012-06-29 14:31:07 +0530 | [diff] [blame] | 4474 | err1: |
Archit Taneja | dca2b15 | 2012-08-16 18:02:00 +0530 | [diff] [blame] | 4475 | if (dsi->mode == OMAP_DSS_DSI_CMD_MODE) |
Tomi Valkeinen | 1550202 | 2012-10-10 13:59:07 +0300 | [diff] [blame] | 4476 | dss_mgr_unregister_framedone_handler(mgr, |
| 4477 | dsi_framedone_irq_callback, dsidev); |
Archit Taneja | 7d2572f | 2012-06-29 14:31:07 +0530 | [diff] [blame] | 4478 | err: |
Tomi Valkeinen | b7dec9b | 2013-02-22 12:58:35 +0200 | [diff] [blame] | 4479 | dss_select_lcd_clk_source(mgr->id, OMAP_DSS_CLK_SRC_FCK); |
Archit Taneja | 7d2572f | 2012-06-29 14:31:07 +0530 | [diff] [blame] | 4480 | return r; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4481 | } |
| 4482 | |
Tomi Valkeinen | b7dec9b | 2013-02-22 12:58:35 +0200 | [diff] [blame] | 4483 | static void dsi_display_uninit_dispc(struct platform_device *dsidev, |
| 4484 | struct omap_overlay_manager *mgr) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4485 | { |
Archit Taneja | dca2b15 | 2012-08-16 18:02:00 +0530 | [diff] [blame] | 4486 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 4487 | |
Tomi Valkeinen | 1550202 | 2012-10-10 13:59:07 +0300 | [diff] [blame] | 4488 | if (dsi->mode == OMAP_DSS_DSI_CMD_MODE) |
| 4489 | dss_mgr_unregister_framedone_handler(mgr, |
| 4490 | dsi_framedone_irq_callback, dsidev); |
Tomi Valkeinen | b7dec9b | 2013-02-22 12:58:35 +0200 | [diff] [blame] | 4491 | |
| 4492 | dss_select_lcd_clk_source(mgr->id, OMAP_DSS_CLK_SRC_FCK); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4493 | } |
| 4494 | |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 4495 | static int dsi_configure_dsi_clocks(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4496 | { |
Tomi Valkeinen | a0d269e | 2012-11-27 17:05:54 +0200 | [diff] [blame] | 4497 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4498 | struct dsi_clock_info cinfo; |
| 4499 | int r; |
| 4500 | |
Tomi Valkeinen | a0d269e | 2012-11-27 17:05:54 +0200 | [diff] [blame] | 4501 | cinfo = dsi->user_dsi_cinfo; |
| 4502 | |
Tomi Valkeinen | b6e695a | 2012-03-15 15:22:58 +0200 | [diff] [blame] | 4503 | r = dsi_calc_clock_rates(dsidev, &cinfo); |
Ville Syrjälä | ebf0a3f | 2010-04-22 22:50:05 +0200 | [diff] [blame] | 4504 | if (r) { |
| 4505 | DSSERR("Failed to calc dsi clocks\n"); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4506 | return r; |
Ville Syrjälä | ebf0a3f | 2010-04-22 22:50:05 +0200 | [diff] [blame] | 4507 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4508 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4509 | r = dsi_pll_set_clock_div(dsidev, &cinfo); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4510 | if (r) { |
| 4511 | DSSERR("Failed to set dsi clocks\n"); |
| 4512 | return r; |
| 4513 | } |
| 4514 | |
| 4515 | return 0; |
| 4516 | } |
| 4517 | |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 4518 | static int dsi_display_init_dsi(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4519 | { |
Tomi Valkeinen | 11ee960 | 2012-03-09 16:07:39 +0200 | [diff] [blame] | 4520 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4521 | int r; |
| 4522 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4523 | r = dsi_pll_init(dsidev, true, true); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4524 | if (r) |
| 4525 | goto err0; |
| 4526 | |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 4527 | r = dsi_configure_dsi_clocks(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4528 | if (r) |
| 4529 | goto err1; |
| 4530 | |
Tomi Valkeinen | 4ce9e33 | 2013-03-05 17:11:16 +0200 | [diff] [blame] | 4531 | dss_select_dsi_clk_source(dsi->module_id, dsi->module_id == 0 ? |
| 4532 | OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI : |
| 4533 | OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4534 | |
| 4535 | DSSDBG("PLL OK\n"); |
| 4536 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 4537 | r = dsi_cio_init(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4538 | if (r) |
| 4539 | goto err2; |
| 4540 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4541 | _dsi_print_reset_status(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4542 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 4543 | dsi_proto_timings(dsidev); |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 4544 | dsi_set_lp_clk_divisor(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4545 | |
| 4546 | if (1) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4547 | _dsi_print_reset_status(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4548 | |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 4549 | r = dsi_proto_config(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4550 | if (r) |
| 4551 | goto err3; |
| 4552 | |
| 4553 | /* enable interface */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4554 | dsi_vc_enable(dsidev, 0, 1); |
| 4555 | dsi_vc_enable(dsidev, 1, 1); |
| 4556 | dsi_vc_enable(dsidev, 2, 1); |
| 4557 | dsi_vc_enable(dsidev, 3, 1); |
| 4558 | dsi_if_enable(dsidev, 1); |
| 4559 | dsi_force_tx_stop_mode_io(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4560 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4561 | return 0; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4562 | err3: |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 4563 | dsi_cio_uninit(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4564 | err2: |
Tomi Valkeinen | 11ee960 | 2012-03-09 16:07:39 +0200 | [diff] [blame] | 4565 | dss_select_dsi_clk_source(dsi->module_id, OMAP_DSS_CLK_SRC_FCK); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4566 | err1: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4567 | dsi_pll_uninit(dsidev, true); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4568 | err0: |
| 4569 | return r; |
| 4570 | } |
| 4571 | |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 4572 | static void dsi_display_uninit_dsi(struct platform_device *dsidev, |
Tomi Valkeinen | 22d6d67 | 2010-10-11 11:33:30 +0300 | [diff] [blame] | 4573 | bool disconnect_lanes, bool enter_ulps) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4574 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4575 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4576 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4577 | if (enter_ulps && !dsi->ulps_enabled) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4578 | dsi_enter_ulps(dsidev); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 4579 | |
Ville Syrjälä | d737010 | 2010-04-22 22:50:09 +0200 | [diff] [blame] | 4580 | /* disable interface */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4581 | dsi_if_enable(dsidev, 0); |
| 4582 | dsi_vc_enable(dsidev, 0, 0); |
| 4583 | dsi_vc_enable(dsidev, 1, 0); |
| 4584 | dsi_vc_enable(dsidev, 2, 0); |
| 4585 | dsi_vc_enable(dsidev, 3, 0); |
Ville Syrjälä | d737010 | 2010-04-22 22:50:09 +0200 | [diff] [blame] | 4586 | |
Tomi Valkeinen | 11ee960 | 2012-03-09 16:07:39 +0200 | [diff] [blame] | 4587 | dss_select_dsi_clk_source(dsi->module_id, OMAP_DSS_CLK_SRC_FCK); |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 4588 | dsi_cio_uninit(dsidev); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4589 | dsi_pll_uninit(dsidev, disconnect_lanes); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4590 | } |
| 4591 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 4592 | int omapdss_dsi_display_enable(struct omap_dss_device *dssdev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4593 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4594 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4595 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4596 | int r = 0; |
| 4597 | |
| 4598 | DSSDBG("dsi_display_enable\n"); |
| 4599 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4600 | WARN_ON(!dsi_bus_is_locked(dsidev)); |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 4601 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4602 | mutex_lock(&dsi->lock); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4603 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4604 | r = dsi_runtime_get(dsidev); |
| 4605 | if (r) |
| 4606 | goto err_get_dsi; |
| 4607 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4608 | dsi_enable_pll_clock(dsidev, 1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4609 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4610 | _dsi_initialize_irq(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4611 | |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 4612 | r = dsi_display_init_dsi(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4613 | if (r) |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4614 | goto err_init_dsi; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4615 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4616 | mutex_unlock(&dsi->lock); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4617 | |
| 4618 | return 0; |
| 4619 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4620 | err_init_dsi: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4621 | dsi_enable_pll_clock(dsidev, 0); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4622 | dsi_runtime_put(dsidev); |
| 4623 | err_get_dsi: |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4624 | mutex_unlock(&dsi->lock); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4625 | DSSDBG("dsi_display_enable FAILED\n"); |
| 4626 | return r; |
| 4627 | } |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 4628 | EXPORT_SYMBOL(omapdss_dsi_display_enable); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4629 | |
Tomi Valkeinen | 2a89dc1 | 2010-07-30 12:39:34 +0300 | [diff] [blame] | 4630 | void omapdss_dsi_display_disable(struct omap_dss_device *dssdev, |
Tomi Valkeinen | 22d6d67 | 2010-10-11 11:33:30 +0300 | [diff] [blame] | 4631 | bool disconnect_lanes, bool enter_ulps) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4632 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4633 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4634 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4635 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4636 | DSSDBG("dsi_display_disable\n"); |
| 4637 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4638 | WARN_ON(!dsi_bus_is_locked(dsidev)); |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 4639 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4640 | mutex_lock(&dsi->lock); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4641 | |
Tomi Valkeinen | 15ffa1d | 2011-06-16 14:34:06 +0300 | [diff] [blame] | 4642 | dsi_sync_vc(dsidev, 0); |
| 4643 | dsi_sync_vc(dsidev, 1); |
| 4644 | dsi_sync_vc(dsidev, 2); |
| 4645 | dsi_sync_vc(dsidev, 3); |
| 4646 | |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 4647 | dsi_display_uninit_dsi(dsidev, disconnect_lanes, enter_ulps); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4648 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4649 | dsi_runtime_put(dsidev); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4650 | dsi_enable_pll_clock(dsidev, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4651 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4652 | mutex_unlock(&dsi->lock); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4653 | } |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 4654 | EXPORT_SYMBOL(omapdss_dsi_display_disable); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4655 | |
Tomi Valkeinen | 225b650 | 2010-01-11 15:11:01 +0200 | [diff] [blame] | 4656 | int omapdss_dsi_enable_te(struct omap_dss_device *dssdev, bool enable) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4657 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4658 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 4659 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 4660 | |
| 4661 | dsi->te_enabled = enable; |
Tomi Valkeinen | 225b650 | 2010-01-11 15:11:01 +0200 | [diff] [blame] | 4662 | return 0; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4663 | } |
Tomi Valkeinen | 225b650 | 2010-01-11 15:11:01 +0200 | [diff] [blame] | 4664 | EXPORT_SYMBOL(omapdss_dsi_enable_te); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4665 | |
Tomi Valkeinen | f1e0001 | 2013-03-05 17:21:35 +0200 | [diff] [blame] | 4666 | #ifdef PRINT_VERBOSE_VM_TIMINGS |
| 4667 | static void print_dsi_vm(const char *str, |
| 4668 | const struct omap_dss_dsi_videomode_timings *t) |
| 4669 | { |
| 4670 | unsigned long byteclk = t->hsclk / 4; |
| 4671 | int bl, wc, pps, tot; |
| 4672 | |
| 4673 | wc = DIV_ROUND_UP(t->hact * t->bitspp, 8); |
| 4674 | pps = DIV_ROUND_UP(wc + 6, t->ndl); /* pixel packet size */ |
| 4675 | bl = t->hss + t->hsa + t->hse + t->hbp + t->hfp; |
| 4676 | tot = bl + pps; |
| 4677 | |
| 4678 | #define TO_DSI_T(x) ((u32)div64_u64((u64)x * 1000000000llu, byteclk)) |
| 4679 | |
| 4680 | pr_debug("%s bck %lu, %u/%u/%u/%u/%u/%u = %u+%u = %u, " |
| 4681 | "%u/%u/%u/%u/%u/%u = %u + %u = %u\n", |
| 4682 | str, |
| 4683 | byteclk, |
| 4684 | t->hss, t->hsa, t->hse, t->hbp, pps, t->hfp, |
| 4685 | bl, pps, tot, |
| 4686 | TO_DSI_T(t->hss), |
| 4687 | TO_DSI_T(t->hsa), |
| 4688 | TO_DSI_T(t->hse), |
| 4689 | TO_DSI_T(t->hbp), |
| 4690 | TO_DSI_T(pps), |
| 4691 | TO_DSI_T(t->hfp), |
| 4692 | |
| 4693 | TO_DSI_T(bl), |
| 4694 | TO_DSI_T(pps), |
| 4695 | |
| 4696 | TO_DSI_T(tot)); |
| 4697 | #undef TO_DSI_T |
| 4698 | } |
| 4699 | |
| 4700 | static void print_dispc_vm(const char *str, const struct omap_video_timings *t) |
| 4701 | { |
| 4702 | unsigned long pck = t->pixel_clock * 1000; |
| 4703 | int hact, bl, tot; |
| 4704 | |
| 4705 | hact = t->x_res; |
| 4706 | bl = t->hsw + t->hbp + t->hfp; |
| 4707 | tot = hact + bl; |
| 4708 | |
| 4709 | #define TO_DISPC_T(x) ((u32)div64_u64((u64)x * 1000000000llu, pck)) |
| 4710 | |
| 4711 | pr_debug("%s pck %lu, %u/%u/%u/%u = %u+%u = %u, " |
| 4712 | "%u/%u/%u/%u = %u + %u = %u\n", |
| 4713 | str, |
| 4714 | pck, |
| 4715 | t->hsw, t->hbp, hact, t->hfp, |
| 4716 | bl, hact, tot, |
| 4717 | TO_DISPC_T(t->hsw), |
| 4718 | TO_DISPC_T(t->hbp), |
| 4719 | TO_DISPC_T(hact), |
| 4720 | TO_DISPC_T(t->hfp), |
| 4721 | TO_DISPC_T(bl), |
| 4722 | TO_DISPC_T(hact), |
| 4723 | TO_DISPC_T(tot)); |
| 4724 | #undef TO_DISPC_T |
| 4725 | } |
| 4726 | |
| 4727 | /* note: this is not quite accurate */ |
| 4728 | static void print_dsi_dispc_vm(const char *str, |
| 4729 | const struct omap_dss_dsi_videomode_timings *t) |
| 4730 | { |
| 4731 | struct omap_video_timings vm = { 0 }; |
| 4732 | unsigned long byteclk = t->hsclk / 4; |
| 4733 | unsigned long pck; |
| 4734 | u64 dsi_tput; |
| 4735 | int dsi_hact, dsi_htot; |
| 4736 | |
| 4737 | dsi_tput = (u64)byteclk * t->ndl * 8; |
| 4738 | pck = (u32)div64_u64(dsi_tput, t->bitspp); |
| 4739 | dsi_hact = DIV_ROUND_UP(DIV_ROUND_UP(t->hact * t->bitspp, 8) + 6, t->ndl); |
| 4740 | dsi_htot = t->hss + t->hsa + t->hse + t->hbp + dsi_hact + t->hfp; |
| 4741 | |
| 4742 | vm.pixel_clock = pck / 1000; |
| 4743 | vm.hsw = div64_u64((u64)(t->hsa + t->hse) * pck, byteclk); |
| 4744 | vm.hbp = div64_u64((u64)t->hbp * pck, byteclk); |
| 4745 | vm.hfp = div64_u64((u64)t->hfp * pck, byteclk); |
| 4746 | vm.x_res = t->hact; |
| 4747 | |
| 4748 | print_dispc_vm(str, &vm); |
| 4749 | } |
| 4750 | #endif /* PRINT_VERBOSE_VM_TIMINGS */ |
| 4751 | |
| 4752 | static bool dsi_cm_calc_dispc_cb(int lckd, int pckd, unsigned long lck, |
| 4753 | unsigned long pck, void *data) |
| 4754 | { |
| 4755 | struct dsi_clk_calc_ctx *ctx = data; |
| 4756 | struct omap_video_timings *t = &ctx->dispc_vm; |
| 4757 | |
| 4758 | ctx->dispc_cinfo.lck_div = lckd; |
| 4759 | ctx->dispc_cinfo.pck_div = pckd; |
| 4760 | ctx->dispc_cinfo.lck = lck; |
| 4761 | ctx->dispc_cinfo.pck = pck; |
| 4762 | |
| 4763 | *t = *ctx->config->timings; |
| 4764 | t->pixel_clock = pck / 1000; |
| 4765 | t->x_res = ctx->config->timings->x_res; |
| 4766 | t->y_res = ctx->config->timings->y_res; |
| 4767 | t->hsw = t->hfp = t->hbp = t->vsw = 1; |
| 4768 | t->vfp = t->vbp = 0; |
| 4769 | |
| 4770 | return true; |
| 4771 | } |
| 4772 | |
| 4773 | static bool dsi_cm_calc_hsdiv_cb(int regm_dispc, unsigned long dispc, |
| 4774 | void *data) |
| 4775 | { |
| 4776 | struct dsi_clk_calc_ctx *ctx = data; |
| 4777 | |
| 4778 | ctx->dsi_cinfo.regm_dispc = regm_dispc; |
| 4779 | ctx->dsi_cinfo.dsi_pll_hsdiv_dispc_clk = dispc; |
| 4780 | |
| 4781 | return dispc_div_calc(dispc, ctx->req_pck_min, ctx->req_pck_max, |
| 4782 | dsi_cm_calc_dispc_cb, ctx); |
| 4783 | } |
| 4784 | |
| 4785 | static bool dsi_cm_calc_pll_cb(int regn, int regm, unsigned long fint, |
| 4786 | unsigned long pll, void *data) |
| 4787 | { |
| 4788 | struct dsi_clk_calc_ctx *ctx = data; |
| 4789 | |
| 4790 | ctx->dsi_cinfo.regn = regn; |
| 4791 | ctx->dsi_cinfo.regm = regm; |
| 4792 | ctx->dsi_cinfo.fint = fint; |
| 4793 | ctx->dsi_cinfo.clkin4ddr = pll; |
| 4794 | |
| 4795 | return dsi_hsdiv_calc(ctx->dsidev, pll, ctx->req_pck_min, |
| 4796 | dsi_cm_calc_hsdiv_cb, ctx); |
| 4797 | } |
| 4798 | |
| 4799 | static bool dsi_cm_calc(struct dsi_data *dsi, |
| 4800 | const struct omap_dss_dsi_config *cfg, |
| 4801 | struct dsi_clk_calc_ctx *ctx) |
| 4802 | { |
| 4803 | unsigned long clkin; |
| 4804 | int bitspp, ndl; |
| 4805 | unsigned long pll_min, pll_max; |
| 4806 | unsigned long pck, txbyteclk; |
| 4807 | |
| 4808 | clkin = clk_get_rate(dsi->sys_clk); |
| 4809 | bitspp = dsi_get_pixel_size(cfg->pixel_format); |
| 4810 | ndl = dsi->num_lanes_used - 1; |
| 4811 | |
| 4812 | /* |
| 4813 | * Here we should calculate minimum txbyteclk to be able to send the |
| 4814 | * frame in time, and also to handle TE. That's not very simple, though, |
| 4815 | * especially as we go to LP between each pixel packet due to HW |
| 4816 | * "feature". So let's just estimate very roughly and multiply by 1.5. |
| 4817 | */ |
| 4818 | pck = cfg->timings->pixel_clock * 1000; |
| 4819 | pck = pck * 3 / 2; |
| 4820 | txbyteclk = pck * bitspp / 8 / ndl; |
| 4821 | |
| 4822 | memset(ctx, 0, sizeof(*ctx)); |
| 4823 | ctx->dsidev = dsi->pdev; |
| 4824 | ctx->config = cfg; |
| 4825 | ctx->req_pck_min = pck; |
| 4826 | ctx->req_pck_nom = pck; |
| 4827 | ctx->req_pck_max = pck * 3 / 2; |
| 4828 | ctx->dsi_cinfo.clkin = clkin; |
| 4829 | |
| 4830 | pll_min = max(cfg->hs_clk_min * 4, txbyteclk * 4 * 4); |
| 4831 | pll_max = cfg->hs_clk_max * 4; |
| 4832 | |
| 4833 | return dsi_pll_calc(dsi->pdev, clkin, |
| 4834 | pll_min, pll_max, |
| 4835 | dsi_cm_calc_pll_cb, ctx); |
| 4836 | } |
| 4837 | |
| 4838 | static bool dsi_vm_calc_blanking(struct dsi_clk_calc_ctx *ctx) |
| 4839 | { |
| 4840 | struct dsi_data *dsi = dsi_get_dsidrv_data(ctx->dsidev); |
| 4841 | const struct omap_dss_dsi_config *cfg = ctx->config; |
| 4842 | int bitspp = dsi_get_pixel_size(cfg->pixel_format); |
| 4843 | int ndl = dsi->num_lanes_used - 1; |
| 4844 | unsigned long hsclk = ctx->dsi_cinfo.clkin4ddr / 4; |
| 4845 | unsigned long byteclk = hsclk / 4; |
| 4846 | |
| 4847 | unsigned long dispc_pck, req_pck_min, req_pck_nom, req_pck_max; |
| 4848 | int xres; |
| 4849 | int panel_htot, panel_hbl; /* pixels */ |
| 4850 | int dispc_htot, dispc_hbl; /* pixels */ |
| 4851 | int dsi_htot, dsi_hact, dsi_hbl, hss, hse; /* byteclks */ |
| 4852 | int hfp, hsa, hbp; |
| 4853 | const struct omap_video_timings *req_vm; |
| 4854 | struct omap_video_timings *dispc_vm; |
| 4855 | struct omap_dss_dsi_videomode_timings *dsi_vm; |
| 4856 | u64 dsi_tput, dispc_tput; |
| 4857 | |
| 4858 | dsi_tput = (u64)byteclk * ndl * 8; |
| 4859 | |
| 4860 | req_vm = cfg->timings; |
| 4861 | req_pck_min = ctx->req_pck_min; |
| 4862 | req_pck_max = ctx->req_pck_max; |
| 4863 | req_pck_nom = ctx->req_pck_nom; |
| 4864 | |
| 4865 | dispc_pck = ctx->dispc_cinfo.pck; |
| 4866 | dispc_tput = (u64)dispc_pck * bitspp; |
| 4867 | |
| 4868 | xres = req_vm->x_res; |
| 4869 | |
| 4870 | panel_hbl = req_vm->hfp + req_vm->hbp + req_vm->hsw; |
| 4871 | panel_htot = xres + panel_hbl; |
| 4872 | |
| 4873 | dsi_hact = DIV_ROUND_UP(DIV_ROUND_UP(xres * bitspp, 8) + 6, ndl); |
| 4874 | |
| 4875 | /* |
| 4876 | * When there are no line buffers, DISPC and DSI must have the |
| 4877 | * same tput. Otherwise DISPC tput needs to be higher than DSI's. |
| 4878 | */ |
| 4879 | if (dsi->line_buffer_size < xres * bitspp / 8) { |
| 4880 | if (dispc_tput != dsi_tput) |
| 4881 | return false; |
| 4882 | } else { |
| 4883 | if (dispc_tput < dsi_tput) |
| 4884 | return false; |
| 4885 | } |
| 4886 | |
| 4887 | /* DSI tput must be over the min requirement */ |
| 4888 | if (dsi_tput < (u64)bitspp * req_pck_min) |
| 4889 | return false; |
| 4890 | |
| 4891 | /* When non-burst mode, DSI tput must be below max requirement. */ |
| 4892 | if (cfg->trans_mode != OMAP_DSS_DSI_BURST_MODE) { |
| 4893 | if (dsi_tput > (u64)bitspp * req_pck_max) |
| 4894 | return false; |
| 4895 | } |
| 4896 | |
| 4897 | hss = DIV_ROUND_UP(4, ndl); |
| 4898 | |
| 4899 | if (cfg->trans_mode == OMAP_DSS_DSI_PULSE_MODE) { |
| 4900 | if (ndl == 3 && req_vm->hsw == 0) |
| 4901 | hse = 1; |
| 4902 | else |
| 4903 | hse = DIV_ROUND_UP(4, ndl); |
| 4904 | } else { |
| 4905 | hse = 0; |
| 4906 | } |
| 4907 | |
| 4908 | /* DSI htot to match the panel's nominal pck */ |
| 4909 | dsi_htot = div64_u64((u64)panel_htot * byteclk, req_pck_nom); |
| 4910 | |
| 4911 | /* fail if there would be no time for blanking */ |
| 4912 | if (dsi_htot < hss + hse + dsi_hact) |
| 4913 | return false; |
| 4914 | |
| 4915 | /* total DSI blanking needed to achieve panel's TL */ |
| 4916 | dsi_hbl = dsi_htot - dsi_hact; |
| 4917 | |
| 4918 | /* DISPC htot to match the DSI TL */ |
| 4919 | dispc_htot = div64_u64((u64)dsi_htot * dispc_pck, byteclk); |
| 4920 | |
| 4921 | /* verify that the DSI and DISPC TLs are the same */ |
| 4922 | if ((u64)dsi_htot * dispc_pck != (u64)dispc_htot * byteclk) |
| 4923 | return false; |
| 4924 | |
| 4925 | dispc_hbl = dispc_htot - xres; |
| 4926 | |
| 4927 | /* setup DSI videomode */ |
| 4928 | |
| 4929 | dsi_vm = &ctx->dsi_vm; |
| 4930 | memset(dsi_vm, 0, sizeof(*dsi_vm)); |
| 4931 | |
| 4932 | dsi_vm->hsclk = hsclk; |
| 4933 | |
| 4934 | dsi_vm->ndl = ndl; |
| 4935 | dsi_vm->bitspp = bitspp; |
| 4936 | |
| 4937 | if (cfg->trans_mode != OMAP_DSS_DSI_PULSE_MODE) { |
| 4938 | hsa = 0; |
| 4939 | } else if (ndl == 3 && req_vm->hsw == 0) { |
| 4940 | hsa = 0; |
| 4941 | } else { |
| 4942 | hsa = div64_u64((u64)req_vm->hsw * byteclk, req_pck_nom); |
| 4943 | hsa = max(hsa - hse, 1); |
| 4944 | } |
| 4945 | |
| 4946 | hbp = div64_u64((u64)req_vm->hbp * byteclk, req_pck_nom); |
| 4947 | hbp = max(hbp, 1); |
| 4948 | |
| 4949 | hfp = dsi_hbl - (hss + hsa + hse + hbp); |
| 4950 | if (hfp < 1) { |
| 4951 | int t; |
| 4952 | /* we need to take cycles from hbp */ |
| 4953 | |
| 4954 | t = 1 - hfp; |
| 4955 | hbp = max(hbp - t, 1); |
| 4956 | hfp = dsi_hbl - (hss + hsa + hse + hbp); |
| 4957 | |
| 4958 | if (hfp < 1 && hsa > 0) { |
| 4959 | /* we need to take cycles from hsa */ |
| 4960 | t = 1 - hfp; |
| 4961 | hsa = max(hsa - t, 1); |
| 4962 | hfp = dsi_hbl - (hss + hsa + hse + hbp); |
| 4963 | } |
| 4964 | } |
| 4965 | |
| 4966 | if (hfp < 1) |
| 4967 | return false; |
| 4968 | |
| 4969 | dsi_vm->hss = hss; |
| 4970 | dsi_vm->hsa = hsa; |
| 4971 | dsi_vm->hse = hse; |
| 4972 | dsi_vm->hbp = hbp; |
| 4973 | dsi_vm->hact = xres; |
| 4974 | dsi_vm->hfp = hfp; |
| 4975 | |
| 4976 | dsi_vm->vsa = req_vm->vsw; |
| 4977 | dsi_vm->vbp = req_vm->vbp; |
| 4978 | dsi_vm->vact = req_vm->y_res; |
| 4979 | dsi_vm->vfp = req_vm->vfp; |
| 4980 | |
| 4981 | dsi_vm->trans_mode = cfg->trans_mode; |
| 4982 | |
| 4983 | dsi_vm->blanking_mode = 0; |
| 4984 | dsi_vm->hsa_blanking_mode = 1; |
| 4985 | dsi_vm->hfp_blanking_mode = 1; |
| 4986 | dsi_vm->hbp_blanking_mode = 1; |
| 4987 | |
| 4988 | dsi_vm->ddr_clk_always_on = cfg->ddr_clk_always_on; |
| 4989 | dsi_vm->window_sync = 4; |
| 4990 | |
| 4991 | /* setup DISPC videomode */ |
| 4992 | |
| 4993 | dispc_vm = &ctx->dispc_vm; |
| 4994 | *dispc_vm = *req_vm; |
| 4995 | dispc_vm->pixel_clock = dispc_pck / 1000; |
| 4996 | |
| 4997 | if (cfg->trans_mode == OMAP_DSS_DSI_PULSE_MODE) { |
| 4998 | hsa = div64_u64((u64)req_vm->hsw * dispc_pck, |
| 4999 | req_pck_nom); |
| 5000 | hsa = max(hsa, 1); |
| 5001 | } else { |
| 5002 | hsa = 1; |
| 5003 | } |
| 5004 | |
| 5005 | hbp = div64_u64((u64)req_vm->hbp * dispc_pck, req_pck_nom); |
| 5006 | hbp = max(hbp, 1); |
| 5007 | |
| 5008 | hfp = dispc_hbl - hsa - hbp; |
| 5009 | if (hfp < 1) { |
| 5010 | int t; |
| 5011 | /* we need to take cycles from hbp */ |
| 5012 | |
| 5013 | t = 1 - hfp; |
| 5014 | hbp = max(hbp - t, 1); |
| 5015 | hfp = dispc_hbl - hsa - hbp; |
| 5016 | |
| 5017 | if (hfp < 1) { |
| 5018 | /* we need to take cycles from hsa */ |
| 5019 | t = 1 - hfp; |
| 5020 | hsa = max(hsa - t, 1); |
| 5021 | hfp = dispc_hbl - hsa - hbp; |
| 5022 | } |
| 5023 | } |
| 5024 | |
| 5025 | if (hfp < 1) |
| 5026 | return false; |
| 5027 | |
| 5028 | dispc_vm->hfp = hfp; |
| 5029 | dispc_vm->hsw = hsa; |
| 5030 | dispc_vm->hbp = hbp; |
| 5031 | |
| 5032 | return true; |
| 5033 | } |
| 5034 | |
| 5035 | |
| 5036 | static bool dsi_vm_calc_dispc_cb(int lckd, int pckd, unsigned long lck, |
| 5037 | unsigned long pck, void *data) |
| 5038 | { |
| 5039 | struct dsi_clk_calc_ctx *ctx = data; |
| 5040 | |
| 5041 | ctx->dispc_cinfo.lck_div = lckd; |
| 5042 | ctx->dispc_cinfo.pck_div = pckd; |
| 5043 | ctx->dispc_cinfo.lck = lck; |
| 5044 | ctx->dispc_cinfo.pck = pck; |
| 5045 | |
| 5046 | if (dsi_vm_calc_blanking(ctx) == false) |
| 5047 | return false; |
| 5048 | |
| 5049 | #ifdef PRINT_VERBOSE_VM_TIMINGS |
| 5050 | print_dispc_vm("dispc", &ctx->dispc_vm); |
| 5051 | print_dsi_vm("dsi ", &ctx->dsi_vm); |
| 5052 | print_dispc_vm("req ", ctx->config->timings); |
| 5053 | print_dsi_dispc_vm("act ", &ctx->dsi_vm); |
| 5054 | #endif |
| 5055 | |
| 5056 | return true; |
| 5057 | } |
| 5058 | |
| 5059 | static bool dsi_vm_calc_hsdiv_cb(int regm_dispc, unsigned long dispc, |
| 5060 | void *data) |
| 5061 | { |
| 5062 | struct dsi_clk_calc_ctx *ctx = data; |
| 5063 | unsigned long pck_max; |
| 5064 | |
| 5065 | ctx->dsi_cinfo.regm_dispc = regm_dispc; |
| 5066 | ctx->dsi_cinfo.dsi_pll_hsdiv_dispc_clk = dispc; |
| 5067 | |
| 5068 | /* |
| 5069 | * In burst mode we can let the dispc pck be arbitrarily high, but it |
| 5070 | * limits our scaling abilities. So for now, don't aim too high. |
| 5071 | */ |
| 5072 | |
| 5073 | if (ctx->config->trans_mode == OMAP_DSS_DSI_BURST_MODE) |
| 5074 | pck_max = ctx->req_pck_max + 10000000; |
| 5075 | else |
| 5076 | pck_max = ctx->req_pck_max; |
| 5077 | |
| 5078 | return dispc_div_calc(dispc, ctx->req_pck_min, pck_max, |
| 5079 | dsi_vm_calc_dispc_cb, ctx); |
| 5080 | } |
| 5081 | |
| 5082 | static bool dsi_vm_calc_pll_cb(int regn, int regm, unsigned long fint, |
| 5083 | unsigned long pll, void *data) |
| 5084 | { |
| 5085 | struct dsi_clk_calc_ctx *ctx = data; |
| 5086 | |
| 5087 | ctx->dsi_cinfo.regn = regn; |
| 5088 | ctx->dsi_cinfo.regm = regm; |
| 5089 | ctx->dsi_cinfo.fint = fint; |
| 5090 | ctx->dsi_cinfo.clkin4ddr = pll; |
| 5091 | |
| 5092 | return dsi_hsdiv_calc(ctx->dsidev, pll, ctx->req_pck_min, |
| 5093 | dsi_vm_calc_hsdiv_cb, ctx); |
| 5094 | } |
| 5095 | |
| 5096 | static bool dsi_vm_calc(struct dsi_data *dsi, |
| 5097 | const struct omap_dss_dsi_config *cfg, |
| 5098 | struct dsi_clk_calc_ctx *ctx) |
| 5099 | { |
| 5100 | const struct omap_video_timings *t = cfg->timings; |
| 5101 | unsigned long clkin; |
| 5102 | unsigned long pll_min; |
| 5103 | unsigned long pll_max; |
| 5104 | int ndl = dsi->num_lanes_used - 1; |
| 5105 | int bitspp = dsi_get_pixel_size(cfg->pixel_format); |
| 5106 | unsigned long byteclk_min; |
| 5107 | |
| 5108 | clkin = clk_get_rate(dsi->sys_clk); |
| 5109 | |
| 5110 | memset(ctx, 0, sizeof(*ctx)); |
| 5111 | ctx->dsidev = dsi->pdev; |
| 5112 | ctx->config = cfg; |
| 5113 | |
| 5114 | ctx->dsi_cinfo.clkin = clkin; |
| 5115 | |
| 5116 | /* these limits should come from the panel driver */ |
| 5117 | ctx->req_pck_min = t->pixel_clock * 1000 - 1000; |
| 5118 | ctx->req_pck_nom = t->pixel_clock * 1000; |
| 5119 | ctx->req_pck_max = t->pixel_clock * 1000 + 1000; |
| 5120 | |
| 5121 | byteclk_min = div64_u64((u64)ctx->req_pck_min * bitspp, ndl * 8); |
| 5122 | pll_min = max(cfg->hs_clk_min * 4, byteclk_min * 4 * 4); |
| 5123 | |
| 5124 | if (cfg->trans_mode == OMAP_DSS_DSI_BURST_MODE) { |
| 5125 | pll_max = cfg->hs_clk_max * 4; |
| 5126 | } else { |
| 5127 | unsigned long byteclk_max; |
| 5128 | byteclk_max = div64_u64((u64)ctx->req_pck_max * bitspp, |
| 5129 | ndl * 8); |
| 5130 | |
| 5131 | pll_max = byteclk_max * 4 * 4; |
| 5132 | } |
| 5133 | |
| 5134 | return dsi_pll_calc(dsi->pdev, clkin, |
| 5135 | pll_min, pll_max, |
| 5136 | dsi_vm_calc_pll_cb, ctx); |
| 5137 | } |
| 5138 | |
Tomi Valkeinen | 777f05c | 2013-03-06 11:10:29 +0200 | [diff] [blame] | 5139 | int omapdss_dsi_set_config(struct omap_dss_device *dssdev, |
| 5140 | const struct omap_dss_dsi_config *config) |
Archit Taneja | e67458a | 2012-08-13 14:17:30 +0530 | [diff] [blame] | 5141 | { |
| 5142 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 5143 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | f1e0001 | 2013-03-05 17:21:35 +0200 | [diff] [blame] | 5144 | struct dsi_clk_calc_ctx ctx; |
| 5145 | bool ok; |
| 5146 | int r; |
Archit Taneja | e67458a | 2012-08-13 14:17:30 +0530 | [diff] [blame] | 5147 | |
| 5148 | mutex_lock(&dsi->lock); |
| 5149 | |
Tomi Valkeinen | 777f05c | 2013-03-06 11:10:29 +0200 | [diff] [blame] | 5150 | dsi->pix_fmt = config->pixel_format; |
| 5151 | dsi->mode = config->mode; |
| 5152 | |
Tomi Valkeinen | f1e0001 | 2013-03-05 17:21:35 +0200 | [diff] [blame] | 5153 | if (config->mode == OMAP_DSS_DSI_VIDEO_MODE) |
| 5154 | ok = dsi_vm_calc(dsi, config, &ctx); |
| 5155 | else |
| 5156 | ok = dsi_cm_calc(dsi, config, &ctx); |
| 5157 | |
| 5158 | if (!ok) { |
| 5159 | DSSERR("failed to find suitable DSI clock settings\n"); |
| 5160 | r = -EINVAL; |
| 5161 | goto err; |
| 5162 | } |
| 5163 | |
| 5164 | dsi_pll_calc_dsi_fck(&ctx.dsi_cinfo); |
| 5165 | |
| 5166 | r = dsi_lp_clock_calc(&ctx.dsi_cinfo, config->lp_clk_min, |
| 5167 | config->lp_clk_max); |
| 5168 | if (r) { |
| 5169 | DSSERR("failed to find suitable DSI LP clock settings\n"); |
| 5170 | goto err; |
| 5171 | } |
| 5172 | |
| 5173 | dsi->user_dsi_cinfo = ctx.dsi_cinfo; |
| 5174 | dsi->user_dispc_cinfo = ctx.dispc_cinfo; |
| 5175 | |
| 5176 | dsi->timings = ctx.dispc_vm; |
| 5177 | dsi->vm_timings = ctx.dsi_vm; |
Archit Taneja | e67458a | 2012-08-13 14:17:30 +0530 | [diff] [blame] | 5178 | |
| 5179 | mutex_unlock(&dsi->lock); |
Archit Taneja | e67458a | 2012-08-13 14:17:30 +0530 | [diff] [blame] | 5180 | |
Tomi Valkeinen | 777f05c | 2013-03-06 11:10:29 +0200 | [diff] [blame] | 5181 | return 0; |
Tomi Valkeinen | f1e0001 | 2013-03-05 17:21:35 +0200 | [diff] [blame] | 5182 | err: |
| 5183 | mutex_unlock(&dsi->lock); |
| 5184 | |
| 5185 | return r; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 5186 | } |
Tomi Valkeinen | 777f05c | 2013-03-06 11:10:29 +0200 | [diff] [blame] | 5187 | EXPORT_SYMBOL(omapdss_dsi_set_config); |
Archit Taneja | 0b3ffe3 | 2012-08-13 22:13:39 +0530 | [diff] [blame] | 5188 | |
Tomi Valkeinen | 2eea5ae | 2013-02-13 11:23:54 +0200 | [diff] [blame] | 5189 | /* |
| 5190 | * Return a hardcoded channel for the DSI output. This should work for |
| 5191 | * current use cases, but this can be later expanded to either resolve |
| 5192 | * the channel in some more dynamic manner, or get the channel as a user |
| 5193 | * parameter. |
| 5194 | */ |
| 5195 | static enum omap_channel dsi_get_channel(int module_id) |
Archit Taneja | e352574 | 2012-08-09 15:23:43 +0530 | [diff] [blame] | 5196 | { |
Tomi Valkeinen | 2eea5ae | 2013-02-13 11:23:54 +0200 | [diff] [blame] | 5197 | switch (omapdss_get_version()) { |
| 5198 | case OMAPDSS_VER_OMAP24xx: |
| 5199 | DSSWARN("DSI not supported\n"); |
| 5200 | return OMAP_DSS_CHANNEL_LCD; |
Archit Taneja | e352574 | 2012-08-09 15:23:43 +0530 | [diff] [blame] | 5201 | |
Tomi Valkeinen | 2eea5ae | 2013-02-13 11:23:54 +0200 | [diff] [blame] | 5202 | case OMAPDSS_VER_OMAP34xx_ES1: |
| 5203 | case OMAPDSS_VER_OMAP34xx_ES3: |
| 5204 | case OMAPDSS_VER_OMAP3630: |
| 5205 | case OMAPDSS_VER_AM35xx: |
| 5206 | return OMAP_DSS_CHANNEL_LCD; |
Archit Taneja | e352574 | 2012-08-09 15:23:43 +0530 | [diff] [blame] | 5207 | |
Tomi Valkeinen | 2eea5ae | 2013-02-13 11:23:54 +0200 | [diff] [blame] | 5208 | case OMAPDSS_VER_OMAP4430_ES1: |
| 5209 | case OMAPDSS_VER_OMAP4430_ES2: |
| 5210 | case OMAPDSS_VER_OMAP4: |
| 5211 | switch (module_id) { |
| 5212 | case 0: |
| 5213 | return OMAP_DSS_CHANNEL_LCD; |
| 5214 | case 1: |
| 5215 | return OMAP_DSS_CHANNEL_LCD2; |
| 5216 | default: |
| 5217 | DSSWARN("unsupported module id\n"); |
| 5218 | return OMAP_DSS_CHANNEL_LCD; |
| 5219 | } |
Archit Taneja | e352574 | 2012-08-09 15:23:43 +0530 | [diff] [blame] | 5220 | |
Tomi Valkeinen | 2eea5ae | 2013-02-13 11:23:54 +0200 | [diff] [blame] | 5221 | case OMAPDSS_VER_OMAP5: |
| 5222 | switch (module_id) { |
| 5223 | case 0: |
| 5224 | return OMAP_DSS_CHANNEL_LCD; |
| 5225 | case 1: |
| 5226 | return OMAP_DSS_CHANNEL_LCD3; |
| 5227 | default: |
| 5228 | DSSWARN("unsupported module id\n"); |
| 5229 | return OMAP_DSS_CHANNEL_LCD; |
| 5230 | } |
| 5231 | |
| 5232 | default: |
| 5233 | DSSWARN("unsupported DSS version\n"); |
| 5234 | return OMAP_DSS_CHANNEL_LCD; |
| 5235 | } |
Archit Taneja | 02c3960 | 2012-08-10 15:01:33 +0530 | [diff] [blame] | 5236 | } |
Tomi Valkeinen | 5f42f2c | 2011-02-22 15:53:46 +0200 | [diff] [blame] | 5237 | |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 5238 | int omap_dsi_request_vc(struct omap_dss_device *dssdev, int *channel) |
| 5239 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5240 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 5241 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 5242 | int i; |
| 5243 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5244 | for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) { |
| 5245 | if (!dsi->vc[i].dssdev) { |
| 5246 | dsi->vc[i].dssdev = dssdev; |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 5247 | *channel = i; |
| 5248 | return 0; |
| 5249 | } |
| 5250 | } |
| 5251 | |
| 5252 | DSSERR("cannot get VC for display %s", dssdev->name); |
| 5253 | return -ENOSPC; |
| 5254 | } |
| 5255 | EXPORT_SYMBOL(omap_dsi_request_vc); |
| 5256 | |
| 5257 | int omap_dsi_set_vc_id(struct omap_dss_device *dssdev, int channel, int vc_id) |
| 5258 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5259 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 5260 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 5261 | |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 5262 | if (vc_id < 0 || vc_id > 3) { |
| 5263 | DSSERR("VC ID out of range\n"); |
| 5264 | return -EINVAL; |
| 5265 | } |
| 5266 | |
| 5267 | if (channel < 0 || channel > 3) { |
| 5268 | DSSERR("Virtual Channel out of range\n"); |
| 5269 | return -EINVAL; |
| 5270 | } |
| 5271 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5272 | if (dsi->vc[channel].dssdev != dssdev) { |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 5273 | DSSERR("Virtual Channel not allocated to display %s\n", |
| 5274 | dssdev->name); |
| 5275 | return -EINVAL; |
| 5276 | } |
| 5277 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5278 | dsi->vc[channel].vc_id = vc_id; |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 5279 | |
| 5280 | return 0; |
| 5281 | } |
| 5282 | EXPORT_SYMBOL(omap_dsi_set_vc_id); |
| 5283 | |
| 5284 | void omap_dsi_release_vc(struct omap_dss_device *dssdev, int channel) |
| 5285 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5286 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 5287 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 5288 | |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 5289 | if ((channel >= 0 && channel <= 3) && |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5290 | dsi->vc[channel].dssdev == dssdev) { |
| 5291 | dsi->vc[channel].dssdev = NULL; |
| 5292 | dsi->vc[channel].vc_id = 0; |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 5293 | } |
| 5294 | } |
| 5295 | EXPORT_SYMBOL(omap_dsi_release_vc); |
| 5296 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 5297 | void dsi_wait_pll_hsdiv_dispc_active(struct platform_device *dsidev) |
Tomi Valkeinen | e406f90 | 2010-06-09 15:28:12 +0300 | [diff] [blame] | 5298 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 5299 | if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 7, 1) != 1) |
Archit Taneja | 067a57e | 2011-03-02 11:57:25 +0530 | [diff] [blame] | 5300 | DSSERR("%s (%s) not active\n", |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 5301 | dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC), |
| 5302 | 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] | 5303 | } |
| 5304 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 5305 | void dsi_wait_pll_hsdiv_dsi_active(struct platform_device *dsidev) |
Tomi Valkeinen | e406f90 | 2010-06-09 15:28:12 +0300 | [diff] [blame] | 5306 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 5307 | if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 8, 1) != 1) |
Archit Taneja | 067a57e | 2011-03-02 11:57:25 +0530 | [diff] [blame] | 5308 | DSSERR("%s (%s) not active\n", |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 5309 | dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI), |
| 5310 | 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] | 5311 | } |
| 5312 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 5313 | static void dsi_calc_clock_param_ranges(struct platform_device *dsidev) |
Taneja, Archit | 4964111 | 2011-03-14 23:28:23 -0500 | [diff] [blame] | 5314 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5315 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 5316 | |
| 5317 | dsi->regn_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGN); |
| 5318 | dsi->regm_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM); |
| 5319 | dsi->regm_dispc_max = |
| 5320 | dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DISPC); |
| 5321 | dsi->regm_dsi_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DSI); |
| 5322 | dsi->fint_min = dss_feat_get_param_min(FEAT_PARAM_DSIPLL_FINT); |
| 5323 | dsi->fint_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_FINT); |
| 5324 | dsi->lpdiv_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_LPDIV); |
Taneja, Archit | 4964111 | 2011-03-14 23:28:23 -0500 | [diff] [blame] | 5325 | } |
| 5326 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5327 | static int dsi_get_clocks(struct platform_device *dsidev) |
| 5328 | { |
| 5329 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 5330 | struct clk *clk; |
| 5331 | |
Sachin Kamat | 5303b3a | 2013-04-02 14:33:00 +0300 | [diff] [blame] | 5332 | clk = devm_clk_get(&dsidev->dev, "fck"); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5333 | if (IS_ERR(clk)) { |
| 5334 | DSSERR("can't get fck\n"); |
| 5335 | return PTR_ERR(clk); |
| 5336 | } |
| 5337 | |
| 5338 | dsi->dss_clk = clk; |
| 5339 | |
Sachin Kamat | 5303b3a | 2013-04-02 14:33:00 +0300 | [diff] [blame] | 5340 | clk = devm_clk_get(&dsidev->dev, "sys_clk"); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5341 | if (IS_ERR(clk)) { |
| 5342 | DSSERR("can't get sys_clk\n"); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5343 | return PTR_ERR(clk); |
| 5344 | } |
| 5345 | |
| 5346 | dsi->sys_clk = clk; |
| 5347 | |
| 5348 | return 0; |
| 5349 | } |
| 5350 | |
Tomi Valkeinen | ee4a24e | 2013-04-26 13:47:06 +0300 | [diff] [blame] | 5351 | static struct omap_dss_device *dsi_find_dssdev(struct platform_device *pdev) |
Tomi Valkeinen | 38f3daf | 2012-05-02 14:55:12 +0300 | [diff] [blame] | 5352 | { |
Tomi Valkeinen | 1521653 | 2012-09-06 14:29:31 +0300 | [diff] [blame] | 5353 | struct omap_dss_board_info *pdata = pdev->dev.platform_data; |
| 5354 | struct dsi_data *dsi = dsi_get_dsidrv_data(pdev); |
Tomi Valkeinen | 2bbcce5 | 2012-10-29 12:40:46 +0200 | [diff] [blame] | 5355 | const char *def_disp_name = omapdss_get_default_display_name(); |
Tomi Valkeinen | 1521653 | 2012-09-06 14:29:31 +0300 | [diff] [blame] | 5356 | struct omap_dss_device *def_dssdev; |
| 5357 | int i; |
| 5358 | |
| 5359 | def_dssdev = NULL; |
Tomi Valkeinen | 38f3daf | 2012-05-02 14:55:12 +0300 | [diff] [blame] | 5360 | |
| 5361 | for (i = 0; i < pdata->num_devices; ++i) { |
| 5362 | struct omap_dss_device *dssdev = pdata->devices[i]; |
| 5363 | |
| 5364 | if (dssdev->type != OMAP_DISPLAY_TYPE_DSI) |
| 5365 | continue; |
| 5366 | |
| 5367 | if (dssdev->phy.dsi.module != dsi->module_id) |
| 5368 | continue; |
| 5369 | |
Tomi Valkeinen | 1521653 | 2012-09-06 14:29:31 +0300 | [diff] [blame] | 5370 | if (def_dssdev == NULL) |
| 5371 | def_dssdev = dssdev; |
Tomi Valkeinen | 38f3daf | 2012-05-02 14:55:12 +0300 | [diff] [blame] | 5372 | |
Tomi Valkeinen | 1521653 | 2012-09-06 14:29:31 +0300 | [diff] [blame] | 5373 | if (def_disp_name != NULL && |
| 5374 | strcmp(dssdev->name, def_disp_name) == 0) { |
| 5375 | def_dssdev = dssdev; |
| 5376 | break; |
| 5377 | } |
| 5378 | } |
| 5379 | |
| 5380 | return def_dssdev; |
| 5381 | } |
| 5382 | |
Tomi Valkeinen | d1890a6 | 2013-04-26 13:47:41 +0300 | [diff] [blame] | 5383 | static int dsi_probe_pdata(struct platform_device *dsidev) |
Tomi Valkeinen | 1521653 | 2012-09-06 14:29:31 +0300 | [diff] [blame] | 5384 | { |
Tomi Valkeinen | 486c0e1 | 2012-12-07 12:50:08 +0200 | [diff] [blame] | 5385 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 5274484 | 2012-09-10 13:58:29 +0300 | [diff] [blame] | 5386 | struct omap_dss_device *plat_dssdev; |
Tomi Valkeinen | 1521653 | 2012-09-06 14:29:31 +0300 | [diff] [blame] | 5387 | struct omap_dss_device *dssdev; |
| 5388 | int r; |
| 5389 | |
Tomi Valkeinen | 5274484 | 2012-09-10 13:58:29 +0300 | [diff] [blame] | 5390 | plat_dssdev = dsi_find_dssdev(dsidev); |
Tomi Valkeinen | 1521653 | 2012-09-06 14:29:31 +0300 | [diff] [blame] | 5391 | |
Tomi Valkeinen | 5274484 | 2012-09-10 13:58:29 +0300 | [diff] [blame] | 5392 | if (!plat_dssdev) |
Tomi Valkeinen | d1890a6 | 2013-04-26 13:47:41 +0300 | [diff] [blame] | 5393 | return 0; |
Tomi Valkeinen | 5274484 | 2012-09-10 13:58:29 +0300 | [diff] [blame] | 5394 | |
Tomi Valkeinen | b2541c4 | 2013-05-03 13:42:24 +0300 | [diff] [blame] | 5395 | r = dsi_regulator_init(dsidev); |
| 5396 | if (r) |
| 5397 | return r; |
| 5398 | |
Tomi Valkeinen | 5274484 | 2012-09-10 13:58:29 +0300 | [diff] [blame] | 5399 | dssdev = dss_alloc_and_init_device(&dsidev->dev); |
Tomi Valkeinen | 1521653 | 2012-09-06 14:29:31 +0300 | [diff] [blame] | 5400 | if (!dssdev) |
Tomi Valkeinen | d1890a6 | 2013-04-26 13:47:41 +0300 | [diff] [blame] | 5401 | return -ENOMEM; |
Tomi Valkeinen | 1521653 | 2012-09-06 14:29:31 +0300 | [diff] [blame] | 5402 | |
Tomi Valkeinen | 5274484 | 2012-09-10 13:58:29 +0300 | [diff] [blame] | 5403 | dss_copy_device_pdata(dssdev, plat_dssdev); |
| 5404 | |
Tomi Valkeinen | 486c0e1 | 2012-12-07 12:50:08 +0200 | [diff] [blame] | 5405 | r = omapdss_output_set_device(&dsi->output, dssdev); |
| 5406 | if (r) { |
| 5407 | DSSERR("failed to connect output to new device: %s\n", |
| 5408 | dssdev->name); |
| 5409 | dss_put_device(dssdev); |
Tomi Valkeinen | d1890a6 | 2013-04-26 13:47:41 +0300 | [diff] [blame] | 5410 | return r; |
Tomi Valkeinen | 486c0e1 | 2012-12-07 12:50:08 +0200 | [diff] [blame] | 5411 | } |
| 5412 | |
Tomi Valkeinen | 5274484 | 2012-09-10 13:58:29 +0300 | [diff] [blame] | 5413 | r = dss_add_device(dssdev); |
Tomi Valkeinen | 1521653 | 2012-09-06 14:29:31 +0300 | [diff] [blame] | 5414 | if (r) { |
| 5415 | DSSERR("device %s register failed: %d\n", dssdev->name, r); |
Tomi Valkeinen | 486c0e1 | 2012-12-07 12:50:08 +0200 | [diff] [blame] | 5416 | omapdss_output_unset_device(&dsi->output); |
Tomi Valkeinen | 5274484 | 2012-09-10 13:58:29 +0300 | [diff] [blame] | 5417 | dss_put_device(dssdev); |
Tomi Valkeinen | ee4a24e | 2013-04-26 13:47:06 +0300 | [diff] [blame] | 5418 | return r; |
Tomi Valkeinen | 38f3daf | 2012-05-02 14:55:12 +0300 | [diff] [blame] | 5419 | } |
Tomi Valkeinen | ee4a24e | 2013-04-26 13:47:06 +0300 | [diff] [blame] | 5420 | |
| 5421 | return 0; |
Tomi Valkeinen | 38f3daf | 2012-05-02 14:55:12 +0300 | [diff] [blame] | 5422 | } |
| 5423 | |
Tomi Valkeinen | deb16df | 2013-05-24 13:20:27 +0300 | [diff] [blame^] | 5424 | static int dsi_connect(struct omap_dss_device *dssdev, |
| 5425 | struct omap_dss_device *dst) |
| 5426 | { |
| 5427 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 5428 | struct omap_overlay_manager *mgr; |
| 5429 | int r; |
| 5430 | |
| 5431 | r = dsi_regulator_init(dsidev); |
| 5432 | if (r) |
| 5433 | return r; |
| 5434 | |
| 5435 | mgr = omap_dss_get_overlay_manager(dssdev->dispc_channel); |
| 5436 | if (!mgr) |
| 5437 | return -ENODEV; |
| 5438 | |
| 5439 | r = dss_mgr_connect(mgr, dssdev); |
| 5440 | if (r) |
| 5441 | return r; |
| 5442 | |
| 5443 | r = omapdss_output_set_device(dssdev, dst); |
| 5444 | if (r) { |
| 5445 | DSSERR("failed to connect output to new device: %s\n", |
| 5446 | dssdev->name); |
| 5447 | dss_mgr_disconnect(mgr, dssdev); |
| 5448 | return r; |
| 5449 | } |
| 5450 | |
| 5451 | return 0; |
| 5452 | } |
| 5453 | |
| 5454 | static void dsi_disconnect(struct omap_dss_device *dssdev, |
| 5455 | struct omap_dss_device *dst) |
| 5456 | { |
| 5457 | WARN_ON(dst != dssdev->device); |
| 5458 | |
| 5459 | if (dst != dssdev->device) |
| 5460 | return; |
| 5461 | |
| 5462 | omapdss_output_unset_device(dssdev); |
| 5463 | |
| 5464 | if (dssdev->manager) |
| 5465 | dss_mgr_disconnect(dssdev->manager, dssdev); |
| 5466 | } |
| 5467 | |
| 5468 | static const struct omapdss_dsi_ops dsi_ops = { |
| 5469 | .connect = dsi_connect, |
| 5470 | .disconnect = dsi_disconnect, |
| 5471 | |
| 5472 | .bus_lock = dsi_bus_lock, |
| 5473 | .bus_unlock = dsi_bus_unlock, |
| 5474 | |
| 5475 | .enable = omapdss_dsi_display_enable, |
| 5476 | .disable = omapdss_dsi_display_disable, |
| 5477 | |
| 5478 | .enable_hs = omapdss_dsi_vc_enable_hs, |
| 5479 | |
| 5480 | .configure_pins = omapdss_dsi_configure_pins, |
| 5481 | .set_config = omapdss_dsi_set_config, |
| 5482 | |
| 5483 | .enable_video_output = dsi_enable_video_output, |
| 5484 | .disable_video_output = dsi_disable_video_output, |
| 5485 | |
| 5486 | .update = omap_dsi_update, |
| 5487 | |
| 5488 | .enable_te = omapdss_dsi_enable_te, |
| 5489 | |
| 5490 | .request_vc = omap_dsi_request_vc, |
| 5491 | .set_vc_id = omap_dsi_set_vc_id, |
| 5492 | .release_vc = omap_dsi_release_vc, |
| 5493 | |
| 5494 | .dcs_write = dsi_vc_dcs_write, |
| 5495 | .dcs_write_nosync = dsi_vc_dcs_write_nosync, |
| 5496 | .dcs_read = dsi_vc_dcs_read, |
| 5497 | |
| 5498 | .gen_write = dsi_vc_generic_write, |
| 5499 | .gen_write_nosync = dsi_vc_generic_write_nosync, |
| 5500 | .gen_read = dsi_vc_generic_read, |
| 5501 | |
| 5502 | .bta_sync = dsi_vc_send_bta_sync, |
| 5503 | |
| 5504 | .set_max_rx_packet_size = dsi_vc_set_max_rx_packet_size, |
| 5505 | }; |
| 5506 | |
Tomi Valkeinen | ee4a24e | 2013-04-26 13:47:06 +0300 | [diff] [blame] | 5507 | static void dsi_init_output(struct platform_device *dsidev) |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 5508 | { |
| 5509 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 1f68d9c | 2013-04-19 15:09:34 +0300 | [diff] [blame] | 5510 | struct omap_dss_device *out = &dsi->output; |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 5511 | |
Tomi Valkeinen | 1f68d9c | 2013-04-19 15:09:34 +0300 | [diff] [blame] | 5512 | out->dev = &dsidev->dev; |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 5513 | out->id = dsi->module_id == 0 ? |
| 5514 | OMAP_DSS_OUTPUT_DSI1 : OMAP_DSS_OUTPUT_DSI2; |
| 5515 | |
Tomi Valkeinen | 1f68d9c | 2013-04-19 15:09:34 +0300 | [diff] [blame] | 5516 | out->output_type = OMAP_DISPLAY_TYPE_DSI; |
Tomi Valkeinen | 7286a08 | 2013-02-18 13:06:01 +0200 | [diff] [blame] | 5517 | out->name = dsi->module_id == 0 ? "dsi.0" : "dsi.1"; |
Tomi Valkeinen | 2eea5ae | 2013-02-13 11:23:54 +0200 | [diff] [blame] | 5518 | out->dispc_channel = dsi_get_channel(dsi->module_id); |
Tomi Valkeinen | deb16df | 2013-05-24 13:20:27 +0300 | [diff] [blame^] | 5519 | out->ops.dsi = &dsi_ops; |
Tomi Valkeinen | b7328e1 | 2013-05-03 11:42:18 +0300 | [diff] [blame] | 5520 | out->owner = THIS_MODULE; |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 5521 | |
Tomi Valkeinen | 5d47dbc | 2013-04-24 13:32:51 +0300 | [diff] [blame] | 5522 | omapdss_register_output(out); |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 5523 | } |
| 5524 | |
Tomi Valkeinen | d1890a6 | 2013-04-26 13:47:41 +0300 | [diff] [blame] | 5525 | static void dsi_uninit_output(struct platform_device *dsidev) |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 5526 | { |
| 5527 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 1f68d9c | 2013-04-19 15:09:34 +0300 | [diff] [blame] | 5528 | struct omap_dss_device *out = &dsi->output; |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 5529 | |
Tomi Valkeinen | 5d47dbc | 2013-04-24 13:32:51 +0300 | [diff] [blame] | 5530 | omapdss_unregister_output(out); |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 5531 | } |
| 5532 | |
Tomi Valkeinen | b98482e | 2011-05-16 13:52:51 +0300 | [diff] [blame] | 5533 | /* DSI1 HW IP initialisation */ |
Tomi Valkeinen | ee4a24e | 2013-04-26 13:47:06 +0300 | [diff] [blame] | 5534 | static int omap_dsihw_probe(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 5535 | { |
| 5536 | u32 rev; |
Tomi Valkeinen | 11ee960 | 2012-03-09 16:07:39 +0200 | [diff] [blame] | 5537 | int r, i; |
Senthilvadivu Guruswamy | ea9da36 | 2011-01-24 06:22:04 +0000 | [diff] [blame] | 5538 | struct resource *dsi_mem; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5539 | struct dsi_data *dsi; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 5540 | |
Julia Lawall | 6e2a14d | 2012-01-24 14:00:45 +0100 | [diff] [blame] | 5541 | dsi = devm_kzalloc(&dsidev->dev, sizeof(*dsi), GFP_KERNEL); |
Tomi Valkeinen | cd3b344 | 2012-01-25 13:31:04 +0200 | [diff] [blame] | 5542 | if (!dsi) |
| 5543 | return -ENOMEM; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5544 | |
Tomi Valkeinen | 11ee960 | 2012-03-09 16:07:39 +0200 | [diff] [blame] | 5545 | dsi->module_id = dsidev->id; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5546 | dsi->pdev = dsidev; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5547 | dev_set_drvdata(&dsidev->dev, dsi); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 5548 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5549 | spin_lock_init(&dsi->irq_lock); |
| 5550 | spin_lock_init(&dsi->errors_lock); |
| 5551 | dsi->errors = 0; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 5552 | |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 5553 | #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5554 | spin_lock_init(&dsi->irq_stats_lock); |
| 5555 | dsi->irq_stats.last_reset = jiffies; |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 5556 | #endif |
| 5557 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5558 | mutex_init(&dsi->lock); |
| 5559 | sema_init(&dsi->bus_lock, 1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 5560 | |
Tejun Heo | 203b42f | 2012-08-21 13:18:23 -0700 | [diff] [blame] | 5561 | INIT_DEFERRABLE_WORK(&dsi->framedone_timeout_work, |
| 5562 | dsi_framedone_timeout_work_callback); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5563 | |
| 5564 | #ifdef DSI_CATCH_MISSING_TE |
| 5565 | init_timer(&dsi->te_timer); |
| 5566 | dsi->te_timer.function = dsi_te_timeout; |
| 5567 | dsi->te_timer.data = 0; |
| 5568 | #endif |
| 5569 | dsi_mem = platform_get_resource(dsi->pdev, IORESOURCE_MEM, 0); |
| 5570 | if (!dsi_mem) { |
| 5571 | DSSERR("can't get IORESOURCE_MEM DSI\n"); |
Tomi Valkeinen | cd3b344 | 2012-01-25 13:31:04 +0200 | [diff] [blame] | 5572 | return -EINVAL; |
archit taneja | affe360 | 2011-02-23 08:41:03 +0000 | [diff] [blame] | 5573 | } |
Tomi Valkeinen | cd3b344 | 2012-01-25 13:31:04 +0200 | [diff] [blame] | 5574 | |
Julia Lawall | 6e2a14d | 2012-01-24 14:00:45 +0100 | [diff] [blame] | 5575 | dsi->base = devm_ioremap(&dsidev->dev, dsi_mem->start, |
| 5576 | resource_size(dsi_mem)); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5577 | if (!dsi->base) { |
| 5578 | DSSERR("can't ioremap DSI\n"); |
Tomi Valkeinen | cd3b344 | 2012-01-25 13:31:04 +0200 | [diff] [blame] | 5579 | return -ENOMEM; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5580 | } |
Tomi Valkeinen | cd3b344 | 2012-01-25 13:31:04 +0200 | [diff] [blame] | 5581 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5582 | dsi->irq = platform_get_irq(dsi->pdev, 0); |
| 5583 | if (dsi->irq < 0) { |
| 5584 | DSSERR("platform_get_irq failed\n"); |
Tomi Valkeinen | cd3b344 | 2012-01-25 13:31:04 +0200 | [diff] [blame] | 5585 | return -ENODEV; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5586 | } |
archit taneja | affe360 | 2011-02-23 08:41:03 +0000 | [diff] [blame] | 5587 | |
Julia Lawall | 6e2a14d | 2012-01-24 14:00:45 +0100 | [diff] [blame] | 5588 | r = devm_request_irq(&dsidev->dev, dsi->irq, omap_dsi_irq_handler, |
| 5589 | IRQF_SHARED, dev_name(&dsidev->dev), dsi->pdev); |
archit taneja | affe360 | 2011-02-23 08:41:03 +0000 | [diff] [blame] | 5590 | if (r < 0) { |
| 5591 | DSSERR("request_irq failed\n"); |
Tomi Valkeinen | cd3b344 | 2012-01-25 13:31:04 +0200 | [diff] [blame] | 5592 | return r; |
archit taneja | affe360 | 2011-02-23 08:41:03 +0000 | [diff] [blame] | 5593 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 5594 | |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 5595 | /* DSI VCs initialization */ |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5596 | for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) { |
Archit Taneja | d604914 | 2011-08-22 11:58:08 +0530 | [diff] [blame] | 5597 | dsi->vc[i].source = DSI_VC_SOURCE_L4; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5598 | dsi->vc[i].dssdev = NULL; |
| 5599 | dsi->vc[i].vc_id = 0; |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 5600 | } |
| 5601 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 5602 | dsi_calc_clock_param_ranges(dsidev); |
Taneja, Archit | 4964111 | 2011-03-14 23:28:23 -0500 | [diff] [blame] | 5603 | |
Tomi Valkeinen | cd3b344 | 2012-01-25 13:31:04 +0200 | [diff] [blame] | 5604 | r = dsi_get_clocks(dsidev); |
| 5605 | if (r) |
| 5606 | return r; |
| 5607 | |
| 5608 | pm_runtime_enable(&dsidev->dev); |
| 5609 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5610 | r = dsi_runtime_get(dsidev); |
| 5611 | if (r) |
Tomi Valkeinen | cd3b344 | 2012-01-25 13:31:04 +0200 | [diff] [blame] | 5612 | goto err_runtime_get; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 5613 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 5614 | rev = dsi_read_reg(dsidev, DSI_REVISION); |
| 5615 | dev_dbg(&dsidev->dev, "OMAP DSI rev %d.%d\n", |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 5616 | FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0)); |
| 5617 | |
Tomi Valkeinen | d982085 | 2011-10-12 15:05:59 +0300 | [diff] [blame] | 5618 | /* DSI on OMAP3 doesn't have register DSI_GNQ, set number |
| 5619 | * of data to 3 by default */ |
| 5620 | if (dss_has_feature(FEAT_DSI_GNQ)) |
| 5621 | /* NB_DATA_LANES */ |
| 5622 | dsi->num_lanes_supported = 1 + REG_GET(dsidev, DSI_GNQ, 11, 9); |
| 5623 | else |
| 5624 | dsi->num_lanes_supported = 3; |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 5625 | |
Tomi Valkeinen | 9932257 | 2013-03-05 10:37:02 +0200 | [diff] [blame] | 5626 | dsi->line_buffer_size = dsi_get_line_buf_size(dsidev); |
| 5627 | |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 5628 | dsi_init_output(dsidev); |
| 5629 | |
Tomi Valkeinen | c6ca5b2 | 2013-03-14 15:47:29 +0200 | [diff] [blame] | 5630 | if (dsidev->dev.platform_data) { |
| 5631 | r = dsi_probe_pdata(dsidev); |
| 5632 | if (r) |
| 5633 | goto err_probe; |
Tomi Valkeinen | d1890a6 | 2013-04-26 13:47:41 +0300 | [diff] [blame] | 5634 | } |
Tomi Valkeinen | 35deca3 | 2012-03-01 15:45:53 +0200 | [diff] [blame] | 5635 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5636 | dsi_runtime_put(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 5637 | |
Tomi Valkeinen | 11ee960 | 2012-03-09 16:07:39 +0200 | [diff] [blame] | 5638 | if (dsi->module_id == 0) |
Tomi Valkeinen | e40402c | 2012-03-02 18:01:07 +0200 | [diff] [blame] | 5639 | dss_debugfs_create_file("dsi1_regs", dsi1_dump_regs); |
Tomi Valkeinen | 11ee960 | 2012-03-09 16:07:39 +0200 | [diff] [blame] | 5640 | else if (dsi->module_id == 1) |
Tomi Valkeinen | e40402c | 2012-03-02 18:01:07 +0200 | [diff] [blame] | 5641 | dss_debugfs_create_file("dsi2_regs", dsi2_dump_regs); |
| 5642 | |
| 5643 | #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS |
Tomi Valkeinen | 11ee960 | 2012-03-09 16:07:39 +0200 | [diff] [blame] | 5644 | if (dsi->module_id == 0) |
Tomi Valkeinen | e40402c | 2012-03-02 18:01:07 +0200 | [diff] [blame] | 5645 | dss_debugfs_create_file("dsi1_irqs", dsi1_dump_irqs); |
Tomi Valkeinen | 11ee960 | 2012-03-09 16:07:39 +0200 | [diff] [blame] | 5646 | else if (dsi->module_id == 1) |
Tomi Valkeinen | e40402c | 2012-03-02 18:01:07 +0200 | [diff] [blame] | 5647 | dss_debugfs_create_file("dsi2_irqs", dsi2_dump_irqs); |
| 5648 | #endif |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 5649 | return 0; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5650 | |
Tomi Valkeinen | c6ca5b2 | 2013-03-14 15:47:29 +0200 | [diff] [blame] | 5651 | err_probe: |
| 5652 | dsi_runtime_put(dsidev); |
| 5653 | dsi_uninit_output(dsidev); |
Tomi Valkeinen | cd3b344 | 2012-01-25 13:31:04 +0200 | [diff] [blame] | 5654 | err_runtime_get: |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5655 | pm_runtime_disable(&dsidev->dev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 5656 | return r; |
| 5657 | } |
| 5658 | |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 5659 | static int __exit omap_dsihw_remove(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 5660 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5661 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 5662 | |
Tomi Valkeinen | b98482e | 2011-05-16 13:52:51 +0300 | [diff] [blame] | 5663 | WARN_ON(dsi->scp_clk_refcount > 0); |
| 5664 | |
Tomi Valkeinen | 5274484 | 2012-09-10 13:58:29 +0300 | [diff] [blame] | 5665 | dss_unregister_child_devices(&dsidev->dev); |
Tomi Valkeinen | 35deca3 | 2012-03-01 15:45:53 +0200 | [diff] [blame] | 5666 | |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 5667 | dsi_uninit_output(dsidev); |
| 5668 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5669 | pm_runtime_disable(&dsidev->dev); |
| 5670 | |
Tomi Valkeinen | b2541c4 | 2013-05-03 13:42:24 +0300 | [diff] [blame] | 5671 | if (dsi->vdds_dsi_reg != NULL && dsi->vdds_dsi_enabled) { |
| 5672 | regulator_disable(dsi->vdds_dsi_reg); |
| 5673 | dsi->vdds_dsi_enabled = false; |
Senthilvadivu Guruswamy | c8aac01 | 2011-01-24 06:22:02 +0000 | [diff] [blame] | 5674 | } |
| 5675 | |
Senthilvadivu Guruswamy | c8aac01 | 2011-01-24 06:22:02 +0000 | [diff] [blame] | 5676 | return 0; |
| 5677 | } |
| 5678 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5679 | static int dsi_runtime_suspend(struct device *dev) |
| 5680 | { |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5681 | dispc_runtime_put(); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5682 | |
| 5683 | return 0; |
| 5684 | } |
| 5685 | |
| 5686 | static int dsi_runtime_resume(struct device *dev) |
| 5687 | { |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5688 | int r; |
| 5689 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5690 | r = dispc_runtime_get(); |
| 5691 | if (r) |
Tomi Valkeinen | 852f083 | 2012-02-17 17:58:04 +0200 | [diff] [blame] | 5692 | return r; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5693 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5694 | return 0; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5695 | } |
| 5696 | |
| 5697 | static const struct dev_pm_ops dsi_pm_ops = { |
| 5698 | .runtime_suspend = dsi_runtime_suspend, |
| 5699 | .runtime_resume = dsi_runtime_resume, |
| 5700 | }; |
| 5701 | |
Tomi Valkeinen | 7c68dd9 | 2011-08-03 14:00:57 +0300 | [diff] [blame] | 5702 | static struct platform_driver omap_dsihw_driver = { |
Tomi Valkeinen | ee4a24e | 2013-04-26 13:47:06 +0300 | [diff] [blame] | 5703 | .probe = omap_dsihw_probe, |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 5704 | .remove = __exit_p(omap_dsihw_remove), |
Senthilvadivu Guruswamy | c8aac01 | 2011-01-24 06:22:02 +0000 | [diff] [blame] | 5705 | .driver = { |
Tomi Valkeinen | 7c68dd9 | 2011-08-03 14:00:57 +0300 | [diff] [blame] | 5706 | .name = "omapdss_dsi", |
Senthilvadivu Guruswamy | c8aac01 | 2011-01-24 06:22:02 +0000 | [diff] [blame] | 5707 | .owner = THIS_MODULE, |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5708 | .pm = &dsi_pm_ops, |
Senthilvadivu Guruswamy | c8aac01 | 2011-01-24 06:22:02 +0000 | [diff] [blame] | 5709 | }, |
| 5710 | }; |
| 5711 | |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 5712 | int __init dsi_init_platform_driver(void) |
Senthilvadivu Guruswamy | c8aac01 | 2011-01-24 06:22:02 +0000 | [diff] [blame] | 5713 | { |
Tomi Valkeinen | ee4a24e | 2013-04-26 13:47:06 +0300 | [diff] [blame] | 5714 | return platform_driver_register(&omap_dsihw_driver); |
Senthilvadivu Guruswamy | c8aac01 | 2011-01-24 06:22:02 +0000 | [diff] [blame] | 5715 | } |
| 5716 | |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 5717 | void __exit dsi_uninit_platform_driver(void) |
Senthilvadivu Guruswamy | c8aac01 | 2011-01-24 06:22:02 +0000 | [diff] [blame] | 5718 | { |
Tomi Valkeinen | 04c742c | 2012-02-23 15:32:37 +0200 | [diff] [blame] | 5719 | platform_driver_unregister(&omap_dsihw_driver); |
Senthilvadivu Guruswamy | c8aac01 | 2011-01-24 06:22:02 +0000 | [diff] [blame] | 5720 | } |