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 | 6274a61 | 2012-08-21 15:35:42 +0300 | [diff] [blame] | 41 | #include <linux/of.h> |
| 42 | #include <linux/of_platform.h> |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 43 | |
Tomi Valkeinen | a0b38cc | 2011-05-11 14:05:07 +0300 | [diff] [blame] | 44 | #include <video/omapdss.h> |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 45 | #include <video/mipi_display.h> |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 46 | |
| 47 | #include "dss.h" |
Archit Taneja | 819d807 | 2011-03-01 11:54:00 +0530 | [diff] [blame] | 48 | #include "dss_features.h" |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 49 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 50 | #define DSI_CATCH_MISSING_TE |
| 51 | |
Tomi Valkeinen | 6810446 | 2013-12-17 13:53:28 +0200 | [diff] [blame] | 52 | struct dsi_reg { u16 module; u16 idx; }; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 53 | |
Tomi Valkeinen | 6810446 | 2013-12-17 13:53:28 +0200 | [diff] [blame] | 54 | #define DSI_REG(mod, idx) ((const struct dsi_reg) { mod, idx }) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 55 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 56 | /* DSI Protocol Engine */ |
| 57 | |
Tomi Valkeinen | 6810446 | 2013-12-17 13:53:28 +0200 | [diff] [blame] | 58 | #define DSI_PROTO 0 |
| 59 | #define DSI_PROTO_SZ 0x200 |
| 60 | |
| 61 | #define DSI_REVISION DSI_REG(DSI_PROTO, 0x0000) |
| 62 | #define DSI_SYSCONFIG DSI_REG(DSI_PROTO, 0x0010) |
| 63 | #define DSI_SYSSTATUS DSI_REG(DSI_PROTO, 0x0014) |
| 64 | #define DSI_IRQSTATUS DSI_REG(DSI_PROTO, 0x0018) |
| 65 | #define DSI_IRQENABLE DSI_REG(DSI_PROTO, 0x001C) |
| 66 | #define DSI_CTRL DSI_REG(DSI_PROTO, 0x0040) |
| 67 | #define DSI_GNQ DSI_REG(DSI_PROTO, 0x0044) |
| 68 | #define DSI_COMPLEXIO_CFG1 DSI_REG(DSI_PROTO, 0x0048) |
| 69 | #define DSI_COMPLEXIO_IRQ_STATUS DSI_REG(DSI_PROTO, 0x004C) |
| 70 | #define DSI_COMPLEXIO_IRQ_ENABLE DSI_REG(DSI_PROTO, 0x0050) |
| 71 | #define DSI_CLK_CTRL DSI_REG(DSI_PROTO, 0x0054) |
| 72 | #define DSI_TIMING1 DSI_REG(DSI_PROTO, 0x0058) |
| 73 | #define DSI_TIMING2 DSI_REG(DSI_PROTO, 0x005C) |
| 74 | #define DSI_VM_TIMING1 DSI_REG(DSI_PROTO, 0x0060) |
| 75 | #define DSI_VM_TIMING2 DSI_REG(DSI_PROTO, 0x0064) |
| 76 | #define DSI_VM_TIMING3 DSI_REG(DSI_PROTO, 0x0068) |
| 77 | #define DSI_CLK_TIMING DSI_REG(DSI_PROTO, 0x006C) |
| 78 | #define DSI_TX_FIFO_VC_SIZE DSI_REG(DSI_PROTO, 0x0070) |
| 79 | #define DSI_RX_FIFO_VC_SIZE DSI_REG(DSI_PROTO, 0x0074) |
| 80 | #define DSI_COMPLEXIO_CFG2 DSI_REG(DSI_PROTO, 0x0078) |
| 81 | #define DSI_RX_FIFO_VC_FULLNESS DSI_REG(DSI_PROTO, 0x007C) |
| 82 | #define DSI_VM_TIMING4 DSI_REG(DSI_PROTO, 0x0080) |
| 83 | #define DSI_TX_FIFO_VC_EMPTINESS DSI_REG(DSI_PROTO, 0x0084) |
| 84 | #define DSI_VM_TIMING5 DSI_REG(DSI_PROTO, 0x0088) |
| 85 | #define DSI_VM_TIMING6 DSI_REG(DSI_PROTO, 0x008C) |
| 86 | #define DSI_VM_TIMING7 DSI_REG(DSI_PROTO, 0x0090) |
| 87 | #define DSI_STOPCLK_TIMING DSI_REG(DSI_PROTO, 0x0094) |
| 88 | #define DSI_VC_CTRL(n) DSI_REG(DSI_PROTO, 0x0100 + (n * 0x20)) |
| 89 | #define DSI_VC_TE(n) DSI_REG(DSI_PROTO, 0x0104 + (n * 0x20)) |
| 90 | #define DSI_VC_LONG_PACKET_HEADER(n) DSI_REG(DSI_PROTO, 0x0108 + (n * 0x20)) |
| 91 | #define DSI_VC_LONG_PACKET_PAYLOAD(n) DSI_REG(DSI_PROTO, 0x010C + (n * 0x20)) |
| 92 | #define DSI_VC_SHORT_PACKET_HEADER(n) DSI_REG(DSI_PROTO, 0x0110 + (n * 0x20)) |
| 93 | #define DSI_VC_IRQSTATUS(n) DSI_REG(DSI_PROTO, 0x0118 + (n * 0x20)) |
| 94 | #define DSI_VC_IRQENABLE(n) DSI_REG(DSI_PROTO, 0x011C + (n * 0x20)) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 95 | |
| 96 | /* DSIPHY_SCP */ |
| 97 | |
Tomi Valkeinen | 6810446 | 2013-12-17 13:53:28 +0200 | [diff] [blame] | 98 | #define DSI_PHY 1 |
| 99 | #define DSI_PHY_OFFSET 0x200 |
| 100 | #define DSI_PHY_SZ 0x40 |
| 101 | |
| 102 | #define DSI_DSIPHY_CFG0 DSI_REG(DSI_PHY, 0x0000) |
| 103 | #define DSI_DSIPHY_CFG1 DSI_REG(DSI_PHY, 0x0004) |
| 104 | #define DSI_DSIPHY_CFG2 DSI_REG(DSI_PHY, 0x0008) |
| 105 | #define DSI_DSIPHY_CFG5 DSI_REG(DSI_PHY, 0x0014) |
| 106 | #define DSI_DSIPHY_CFG10 DSI_REG(DSI_PHY, 0x0028) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 107 | |
| 108 | /* DSI_PLL_CTRL_SCP */ |
| 109 | |
Tomi Valkeinen | 6810446 | 2013-12-17 13:53:28 +0200 | [diff] [blame] | 110 | #define DSI_PLL 2 |
| 111 | #define DSI_PLL_OFFSET 0x300 |
| 112 | #define DSI_PLL_SZ 0x20 |
| 113 | |
| 114 | #define DSI_PLL_CONTROL DSI_REG(DSI_PLL, 0x0000) |
| 115 | #define DSI_PLL_STATUS DSI_REG(DSI_PLL, 0x0004) |
| 116 | #define DSI_PLL_GO DSI_REG(DSI_PLL, 0x0008) |
| 117 | #define DSI_PLL_CONFIGURATION1 DSI_REG(DSI_PLL, 0x000C) |
| 118 | #define DSI_PLL_CONFIGURATION2 DSI_REG(DSI_PLL, 0x0010) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 119 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 120 | #define REG_GET(dsidev, idx, start, end) \ |
| 121 | FLD_GET(dsi_read_reg(dsidev, idx), start, end) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 122 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 123 | #define REG_FLD_MOD(dsidev, idx, val, start, end) \ |
| 124 | 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] | 125 | |
| 126 | /* Global interrupts */ |
| 127 | #define DSI_IRQ_VC0 (1 << 0) |
| 128 | #define DSI_IRQ_VC1 (1 << 1) |
| 129 | #define DSI_IRQ_VC2 (1 << 2) |
| 130 | #define DSI_IRQ_VC3 (1 << 3) |
| 131 | #define DSI_IRQ_WAKEUP (1 << 4) |
| 132 | #define DSI_IRQ_RESYNC (1 << 5) |
| 133 | #define DSI_IRQ_PLL_LOCK (1 << 7) |
| 134 | #define DSI_IRQ_PLL_UNLOCK (1 << 8) |
| 135 | #define DSI_IRQ_PLL_RECALL (1 << 9) |
| 136 | #define DSI_IRQ_COMPLEXIO_ERR (1 << 10) |
| 137 | #define DSI_IRQ_HS_TX_TIMEOUT (1 << 14) |
| 138 | #define DSI_IRQ_LP_RX_TIMEOUT (1 << 15) |
| 139 | #define DSI_IRQ_TE_TRIGGER (1 << 16) |
| 140 | #define DSI_IRQ_ACK_TRIGGER (1 << 17) |
| 141 | #define DSI_IRQ_SYNC_LOST (1 << 18) |
| 142 | #define DSI_IRQ_LDO_POWER_GOOD (1 << 19) |
| 143 | #define DSI_IRQ_TA_TIMEOUT (1 << 20) |
| 144 | #define DSI_IRQ_ERROR_MASK \ |
| 145 | (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] | 146 | DSI_IRQ_TA_TIMEOUT | DSI_IRQ_SYNC_LOST) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 147 | #define DSI_IRQ_CHANNEL_MASK 0xf |
| 148 | |
| 149 | /* Virtual channel interrupts */ |
| 150 | #define DSI_VC_IRQ_CS (1 << 0) |
| 151 | #define DSI_VC_IRQ_ECC_CORR (1 << 1) |
| 152 | #define DSI_VC_IRQ_PACKET_SENT (1 << 2) |
| 153 | #define DSI_VC_IRQ_FIFO_TX_OVF (1 << 3) |
| 154 | #define DSI_VC_IRQ_FIFO_RX_OVF (1 << 4) |
| 155 | #define DSI_VC_IRQ_BTA (1 << 5) |
| 156 | #define DSI_VC_IRQ_ECC_NO_CORR (1 << 6) |
| 157 | #define DSI_VC_IRQ_FIFO_TX_UDF (1 << 7) |
| 158 | #define DSI_VC_IRQ_PP_BUSY_CHANGE (1 << 8) |
| 159 | #define DSI_VC_IRQ_ERROR_MASK \ |
| 160 | (DSI_VC_IRQ_CS | DSI_VC_IRQ_ECC_CORR | DSI_VC_IRQ_FIFO_TX_OVF | \ |
| 161 | DSI_VC_IRQ_FIFO_RX_OVF | DSI_VC_IRQ_ECC_NO_CORR | \ |
| 162 | DSI_VC_IRQ_FIFO_TX_UDF) |
| 163 | |
| 164 | /* ComplexIO interrupts */ |
| 165 | #define DSI_CIO_IRQ_ERRSYNCESC1 (1 << 0) |
| 166 | #define DSI_CIO_IRQ_ERRSYNCESC2 (1 << 1) |
| 167 | #define DSI_CIO_IRQ_ERRSYNCESC3 (1 << 2) |
Tomi Valkeinen | 6705615 | 2011-03-24 16:30:17 +0200 | [diff] [blame] | 168 | #define DSI_CIO_IRQ_ERRSYNCESC4 (1 << 3) |
| 169 | #define DSI_CIO_IRQ_ERRSYNCESC5 (1 << 4) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 170 | #define DSI_CIO_IRQ_ERRESC1 (1 << 5) |
| 171 | #define DSI_CIO_IRQ_ERRESC2 (1 << 6) |
| 172 | #define DSI_CIO_IRQ_ERRESC3 (1 << 7) |
Tomi Valkeinen | 6705615 | 2011-03-24 16:30:17 +0200 | [diff] [blame] | 173 | #define DSI_CIO_IRQ_ERRESC4 (1 << 8) |
| 174 | #define DSI_CIO_IRQ_ERRESC5 (1 << 9) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 175 | #define DSI_CIO_IRQ_ERRCONTROL1 (1 << 10) |
| 176 | #define DSI_CIO_IRQ_ERRCONTROL2 (1 << 11) |
| 177 | #define DSI_CIO_IRQ_ERRCONTROL3 (1 << 12) |
Tomi Valkeinen | 6705615 | 2011-03-24 16:30:17 +0200 | [diff] [blame] | 178 | #define DSI_CIO_IRQ_ERRCONTROL4 (1 << 13) |
| 179 | #define DSI_CIO_IRQ_ERRCONTROL5 (1 << 14) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 180 | #define DSI_CIO_IRQ_STATEULPS1 (1 << 15) |
| 181 | #define DSI_CIO_IRQ_STATEULPS2 (1 << 16) |
| 182 | #define DSI_CIO_IRQ_STATEULPS3 (1 << 17) |
Tomi Valkeinen | 6705615 | 2011-03-24 16:30:17 +0200 | [diff] [blame] | 183 | #define DSI_CIO_IRQ_STATEULPS4 (1 << 18) |
| 184 | #define DSI_CIO_IRQ_STATEULPS5 (1 << 19) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 185 | #define DSI_CIO_IRQ_ERRCONTENTIONLP0_1 (1 << 20) |
| 186 | #define DSI_CIO_IRQ_ERRCONTENTIONLP1_1 (1 << 21) |
| 187 | #define DSI_CIO_IRQ_ERRCONTENTIONLP0_2 (1 << 22) |
| 188 | #define DSI_CIO_IRQ_ERRCONTENTIONLP1_2 (1 << 23) |
| 189 | #define DSI_CIO_IRQ_ERRCONTENTIONLP0_3 (1 << 24) |
| 190 | #define DSI_CIO_IRQ_ERRCONTENTIONLP1_3 (1 << 25) |
Tomi Valkeinen | 6705615 | 2011-03-24 16:30:17 +0200 | [diff] [blame] | 191 | #define DSI_CIO_IRQ_ERRCONTENTIONLP0_4 (1 << 26) |
| 192 | #define DSI_CIO_IRQ_ERRCONTENTIONLP1_4 (1 << 27) |
| 193 | #define DSI_CIO_IRQ_ERRCONTENTIONLP0_5 (1 << 28) |
| 194 | #define DSI_CIO_IRQ_ERRCONTENTIONLP1_5 (1 << 29) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 195 | #define DSI_CIO_IRQ_ULPSACTIVENOT_ALL0 (1 << 30) |
| 196 | #define DSI_CIO_IRQ_ULPSACTIVENOT_ALL1 (1 << 31) |
Tomi Valkeinen | bbecb50 | 2010-05-10 14:35:33 +0300 | [diff] [blame] | 197 | #define DSI_CIO_IRQ_ERROR_MASK \ |
| 198 | (DSI_CIO_IRQ_ERRSYNCESC1 | DSI_CIO_IRQ_ERRSYNCESC2 | \ |
Tomi Valkeinen | 6705615 | 2011-03-24 16:30:17 +0200 | [diff] [blame] | 199 | DSI_CIO_IRQ_ERRSYNCESC3 | DSI_CIO_IRQ_ERRSYNCESC4 | \ |
| 200 | DSI_CIO_IRQ_ERRSYNCESC5 | \ |
| 201 | DSI_CIO_IRQ_ERRESC1 | DSI_CIO_IRQ_ERRESC2 | \ |
| 202 | DSI_CIO_IRQ_ERRESC3 | DSI_CIO_IRQ_ERRESC4 | \ |
| 203 | DSI_CIO_IRQ_ERRESC5 | \ |
| 204 | DSI_CIO_IRQ_ERRCONTROL1 | DSI_CIO_IRQ_ERRCONTROL2 | \ |
| 205 | DSI_CIO_IRQ_ERRCONTROL3 | DSI_CIO_IRQ_ERRCONTROL4 | \ |
| 206 | DSI_CIO_IRQ_ERRCONTROL5 | \ |
Tomi Valkeinen | bbecb50 | 2010-05-10 14:35:33 +0300 | [diff] [blame] | 207 | DSI_CIO_IRQ_ERRCONTENTIONLP0_1 | DSI_CIO_IRQ_ERRCONTENTIONLP1_1 | \ |
| 208 | DSI_CIO_IRQ_ERRCONTENTIONLP0_2 | DSI_CIO_IRQ_ERRCONTENTIONLP1_2 | \ |
Tomi Valkeinen | 6705615 | 2011-03-24 16:30:17 +0200 | [diff] [blame] | 209 | DSI_CIO_IRQ_ERRCONTENTIONLP0_3 | DSI_CIO_IRQ_ERRCONTENTIONLP1_3 | \ |
| 210 | DSI_CIO_IRQ_ERRCONTENTIONLP0_4 | DSI_CIO_IRQ_ERRCONTENTIONLP1_4 | \ |
| 211 | DSI_CIO_IRQ_ERRCONTENTIONLP0_5 | DSI_CIO_IRQ_ERRCONTENTIONLP1_5) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 212 | |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 213 | typedef void (*omap_dsi_isr_t) (void *arg, u32 mask); |
| 214 | |
Tomi Valkeinen | b7dec9b | 2013-02-22 12:58:35 +0200 | [diff] [blame] | 215 | static int dsi_display_init_dispc(struct platform_device *dsidev, |
| 216 | struct omap_overlay_manager *mgr); |
| 217 | static void dsi_display_uninit_dispc(struct platform_device *dsidev, |
| 218 | struct omap_overlay_manager *mgr); |
| 219 | |
Tomi Valkeinen | 5cfc1c3 | 2013-05-15 11:24:30 +0300 | [diff] [blame] | 220 | static int dsi_vc_send_null(struct omap_dss_device *dssdev, int channel); |
| 221 | |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 222 | #define DSI_MAX_NR_ISRS 2 |
Tomi Valkeinen | 739a7f4 | 2011-10-13 11:22:06 +0300 | [diff] [blame] | 223 | #define DSI_MAX_NR_LANES 5 |
| 224 | |
| 225 | enum dsi_lane_function { |
| 226 | DSI_LANE_UNUSED = 0, |
| 227 | DSI_LANE_CLK, |
| 228 | DSI_LANE_DATA1, |
| 229 | DSI_LANE_DATA2, |
| 230 | DSI_LANE_DATA3, |
| 231 | DSI_LANE_DATA4, |
| 232 | }; |
| 233 | |
| 234 | struct dsi_lane_config { |
| 235 | enum dsi_lane_function function; |
| 236 | u8 polarity; |
| 237 | }; |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 238 | |
| 239 | struct dsi_isr_data { |
| 240 | omap_dsi_isr_t isr; |
| 241 | void *arg; |
| 242 | u32 mask; |
| 243 | }; |
| 244 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 245 | enum fifo_size { |
| 246 | DSI_FIFO_SIZE_0 = 0, |
| 247 | DSI_FIFO_SIZE_32 = 1, |
| 248 | DSI_FIFO_SIZE_64 = 2, |
| 249 | DSI_FIFO_SIZE_96 = 3, |
| 250 | DSI_FIFO_SIZE_128 = 4, |
| 251 | }; |
| 252 | |
Archit Taneja | d604914 | 2011-08-22 11:58:08 +0530 | [diff] [blame] | 253 | enum dsi_vc_source { |
| 254 | DSI_VC_SOURCE_L4 = 0, |
| 255 | DSI_VC_SOURCE_VP, |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 256 | }; |
| 257 | |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 258 | struct dsi_irq_stats { |
| 259 | unsigned long last_reset; |
| 260 | unsigned irq_count; |
| 261 | unsigned dsi_irqs[32]; |
| 262 | unsigned vc_irqs[4][32]; |
| 263 | unsigned cio_irqs[32]; |
| 264 | }; |
| 265 | |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 266 | struct dsi_isr_tables { |
| 267 | struct dsi_isr_data isr_table[DSI_MAX_NR_ISRS]; |
| 268 | struct dsi_isr_data isr_table_vc[4][DSI_MAX_NR_ISRS]; |
| 269 | struct dsi_isr_data isr_table_cio[DSI_MAX_NR_ISRS]; |
| 270 | }; |
| 271 | |
Tomi Valkeinen | f1e0001 | 2013-03-05 17:21:35 +0200 | [diff] [blame] | 272 | struct dsi_clk_calc_ctx { |
| 273 | struct platform_device *dsidev; |
| 274 | |
| 275 | /* inputs */ |
| 276 | |
| 277 | const struct omap_dss_dsi_config *config; |
| 278 | |
| 279 | unsigned long req_pck_min, req_pck_nom, req_pck_max; |
| 280 | |
| 281 | /* outputs */ |
| 282 | |
| 283 | struct dsi_clock_info dsi_cinfo; |
| 284 | struct dispc_clock_info dispc_cinfo; |
| 285 | |
| 286 | struct omap_video_timings dispc_vm; |
| 287 | struct omap_dss_dsi_videomode_timings dsi_vm; |
| 288 | }; |
| 289 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 290 | struct dsi_data { |
Senthilvadivu Guruswamy | c8aac01 | 2011-01-24 06:22:02 +0000 | [diff] [blame] | 291 | struct platform_device *pdev; |
Tomi Valkeinen | 6810446 | 2013-12-17 13:53:28 +0200 | [diff] [blame] | 292 | void __iomem *proto_base; |
| 293 | void __iomem *phy_base; |
| 294 | void __iomem *pll_base; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 295 | |
Tomi Valkeinen | 11ee960 | 2012-03-09 16:07:39 +0200 | [diff] [blame] | 296 | int module_id; |
| 297 | |
archit taneja | affe360 | 2011-02-23 08:41:03 +0000 | [diff] [blame] | 298 | int irq; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 299 | |
Tomi Valkeinen | 0925afc | 2014-04-11 13:49:55 +0300 | [diff] [blame] | 300 | bool is_enabled; |
| 301 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 302 | struct clk *dss_clk; |
| 303 | struct clk *sys_clk; |
| 304 | |
Tomi Valkeinen | a0d269e | 2012-11-27 17:05:54 +0200 | [diff] [blame] | 305 | struct dispc_clock_info user_dispc_cinfo; |
| 306 | struct dsi_clock_info user_dsi_cinfo; |
| 307 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 308 | struct dsi_clock_info current_cinfo; |
| 309 | |
Tomi Valkeinen | 2a89dc1 | 2010-07-30 12:39:34 +0300 | [diff] [blame] | 310 | bool vdds_dsi_enabled; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 311 | struct regulator *vdds_dsi_reg; |
| 312 | |
| 313 | struct { |
Archit Taneja | d604914 | 2011-08-22 11:58:08 +0530 | [diff] [blame] | 314 | enum dsi_vc_source source; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 315 | struct omap_dss_device *dssdev; |
Tomi Valkeinen | 558c73e | 2013-09-25 14:40:06 +0300 | [diff] [blame] | 316 | enum fifo_size tx_fifo_size; |
| 317 | enum fifo_size rx_fifo_size; |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 318 | int vc_id; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 319 | } vc[4]; |
| 320 | |
| 321 | struct mutex lock; |
Tomi Valkeinen | b9eb5d7 | 2010-01-11 16:33:56 +0200 | [diff] [blame] | 322 | struct semaphore bus_lock; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 323 | |
| 324 | unsigned pll_locked; |
| 325 | |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 326 | spinlock_t irq_lock; |
| 327 | struct dsi_isr_tables isr_tables; |
| 328 | /* space for a copy used by the interrupt handler */ |
| 329 | struct dsi_isr_tables isr_tables_copy; |
| 330 | |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 331 | int update_channel; |
Tomi Valkeinen | 477fed7 | 2013-10-02 14:41:24 +0300 | [diff] [blame] | 332 | #ifdef DSI_PERF_MEASURE |
Tomi Valkeinen | 5476e74 | 2011-11-03 16:34:20 +0200 | [diff] [blame] | 333 | unsigned update_bytes; |
| 334 | #endif |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 335 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 336 | bool te_enabled; |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 337 | bool ulps_enabled; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 338 | |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 339 | void (*framedone_callback)(int, void *); |
| 340 | void *framedone_data; |
| 341 | |
| 342 | struct delayed_work framedone_timeout_work; |
| 343 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 344 | #ifdef DSI_CATCH_MISSING_TE |
| 345 | struct timer_list te_timer; |
| 346 | #endif |
| 347 | |
| 348 | unsigned long cache_req_pck; |
| 349 | unsigned long cache_clk_freq; |
| 350 | struct dsi_clock_info cache_cinfo; |
| 351 | |
| 352 | u32 errors; |
| 353 | spinlock_t errors_lock; |
Tomi Valkeinen | 477fed7 | 2013-10-02 14:41:24 +0300 | [diff] [blame] | 354 | #ifdef DSI_PERF_MEASURE |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 355 | ktime_t perf_setup_time; |
| 356 | ktime_t perf_start_time; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 357 | #endif |
| 358 | int debug_read; |
| 359 | int debug_write; |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 360 | |
| 361 | #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS |
| 362 | spinlock_t irq_stats_lock; |
| 363 | struct dsi_irq_stats irq_stats; |
| 364 | #endif |
Taneja, Archit | 4964111 | 2011-03-14 23:28:23 -0500 | [diff] [blame] | 365 | /* DSI PLL Parameter Ranges */ |
| 366 | unsigned long regm_max, regn_max; |
| 367 | unsigned long regm_dispc_max, regm_dsi_max; |
| 368 | unsigned long fint_min, fint_max; |
| 369 | unsigned long lpdiv_max; |
Tomi Valkeinen | 24c1ae4 | 2011-04-13 17:12:52 +0300 | [diff] [blame] | 370 | |
Tomi Valkeinen | d982085 | 2011-10-12 15:05:59 +0300 | [diff] [blame] | 371 | unsigned num_lanes_supported; |
Tomi Valkeinen | 9932257 | 2013-03-05 10:37:02 +0200 | [diff] [blame] | 372 | unsigned line_buffer_size; |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 373 | |
Tomi Valkeinen | 739a7f4 | 2011-10-13 11:22:06 +0300 | [diff] [blame] | 374 | struct dsi_lane_config lanes[DSI_MAX_NR_LANES]; |
| 375 | unsigned num_lanes_used; |
Tomi Valkeinen | 24c1ae4 | 2011-04-13 17:12:52 +0300 | [diff] [blame] | 376 | |
| 377 | unsigned scp_clk_refcount; |
Archit Taneja | 7d2572f | 2012-06-29 14:31:07 +0530 | [diff] [blame] | 378 | |
| 379 | struct dss_lcd_mgr_config mgr_config; |
Archit Taneja | e67458a | 2012-08-13 14:17:30 +0530 | [diff] [blame] | 380 | struct omap_video_timings timings; |
Archit Taneja | 02c3960 | 2012-08-10 15:01:33 +0530 | [diff] [blame] | 381 | enum omap_dss_dsi_pixel_format pix_fmt; |
Archit Taneja | dca2b15 | 2012-08-16 18:02:00 +0530 | [diff] [blame] | 382 | enum omap_dss_dsi_mode mode; |
Archit Taneja | 0b3ffe3 | 2012-08-13 22:13:39 +0530 | [diff] [blame] | 383 | struct omap_dss_dsi_videomode_timings vm_timings; |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 384 | |
Tomi Valkeinen | 1f68d9c | 2013-04-19 15:09:34 +0300 | [diff] [blame] | 385 | struct omap_dss_device output; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 386 | }; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 387 | |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 388 | struct dsi_packet_sent_handler_data { |
| 389 | struct platform_device *dsidev; |
| 390 | struct completion *completion; |
| 391 | }; |
| 392 | |
Tomi Valkeinen | 6274a61 | 2012-08-21 15:35:42 +0300 | [diff] [blame] | 393 | struct dsi_module_id_data { |
| 394 | u32 address; |
| 395 | int id; |
| 396 | }; |
| 397 | |
| 398 | static const struct of_device_id dsi_of_match[]; |
| 399 | |
Tomi Valkeinen | 477fed7 | 2013-10-02 14:41:24 +0300 | [diff] [blame] | 400 | #ifdef DSI_PERF_MEASURE |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 401 | static bool dsi_perf; |
| 402 | module_param(dsi_perf, bool, 0644); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 403 | #endif |
| 404 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 405 | static inline struct dsi_data *dsi_get_dsidrv_data(struct platform_device *dsidev) |
| 406 | { |
| 407 | return dev_get_drvdata(&dsidev->dev); |
| 408 | } |
| 409 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 410 | static inline struct platform_device *dsi_get_dsidev_from_dssdev(struct omap_dss_device *dssdev) |
| 411 | { |
Tomi Valkeinen | 5cfc1c3 | 2013-05-15 11:24:30 +0300 | [diff] [blame] | 412 | return to_platform_device(dssdev->dev); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | struct platform_device *dsi_get_dsidev_from_id(int module) |
| 416 | { |
Tomi Valkeinen | 1f68d9c | 2013-04-19 15:09:34 +0300 | [diff] [blame] | 417 | struct omap_dss_device *out; |
Archit Taneja | 400e65d | 2012-07-04 13:48:34 +0530 | [diff] [blame] | 418 | enum omap_dss_output_id id; |
| 419 | |
Tomi Valkeinen | 78e7f25 | 2012-10-15 12:48:11 +0300 | [diff] [blame] | 420 | switch (module) { |
| 421 | case 0: |
| 422 | id = OMAP_DSS_OUTPUT_DSI1; |
| 423 | break; |
| 424 | case 1: |
| 425 | id = OMAP_DSS_OUTPUT_DSI2; |
| 426 | break; |
| 427 | default: |
| 428 | return NULL; |
| 429 | } |
Archit Taneja | 400e65d | 2012-07-04 13:48:34 +0530 | [diff] [blame] | 430 | |
| 431 | out = omap_dss_get_output(id); |
| 432 | |
Tomi Valkeinen | 1f68d9c | 2013-04-19 15:09:34 +0300 | [diff] [blame] | 433 | return out ? to_platform_device(out->dev) : NULL; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | static inline void dsi_write_reg(struct platform_device *dsidev, |
| 437 | const struct dsi_reg idx, u32 val) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 438 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 439 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 6810446 | 2013-12-17 13:53:28 +0200 | [diff] [blame] | 440 | void __iomem *base; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 441 | |
Tomi Valkeinen | 6810446 | 2013-12-17 13:53:28 +0200 | [diff] [blame] | 442 | switch(idx.module) { |
| 443 | case DSI_PROTO: base = dsi->proto_base; break; |
| 444 | case DSI_PHY: base = dsi->phy_base; break; |
| 445 | case DSI_PLL: base = dsi->pll_base; break; |
| 446 | default: return; |
| 447 | } |
| 448 | |
| 449 | __raw_writel(val, base + idx.idx); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 450 | } |
| 451 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 452 | static inline u32 dsi_read_reg(struct platform_device *dsidev, |
| 453 | const struct dsi_reg idx) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +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); |
Tomi Valkeinen | 6810446 | 2013-12-17 13:53:28 +0200 | [diff] [blame] | 456 | void __iomem *base; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 457 | |
Tomi Valkeinen | 6810446 | 2013-12-17 13:53:28 +0200 | [diff] [blame] | 458 | switch(idx.module) { |
| 459 | case DSI_PROTO: base = dsi->proto_base; break; |
| 460 | case DSI_PHY: base = dsi->phy_base; break; |
| 461 | case DSI_PLL: base = dsi->pll_base; break; |
| 462 | default: return 0; |
| 463 | } |
| 464 | |
| 465 | return __raw_readl(base + idx.idx); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 466 | } |
| 467 | |
Tomi Valkeinen | 5cfc1c3 | 2013-05-15 11:24:30 +0300 | [diff] [blame] | 468 | static void dsi_bus_lock(struct omap_dss_device *dssdev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 469 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 470 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 471 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 472 | |
| 473 | down(&dsi->bus_lock); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 474 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 475 | |
Tomi Valkeinen | 5cfc1c3 | 2013-05-15 11:24:30 +0300 | [diff] [blame] | 476 | static void dsi_bus_unlock(struct omap_dss_device *dssdev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 477 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 478 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 479 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 480 | |
| 481 | up(&dsi->bus_lock); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 482 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 483 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 484 | static bool dsi_bus_is_locked(struct platform_device *dsidev) |
Tomi Valkeinen | 4f76502 | 2010-01-18 16:27:52 +0200 | [diff] [blame] | 485 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 486 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 487 | |
| 488 | return dsi->bus_lock.count == 0; |
Tomi Valkeinen | 4f76502 | 2010-01-18 16:27:52 +0200 | [diff] [blame] | 489 | } |
| 490 | |
Tomi Valkeinen | f36a06e | 2011-03-02 14:48:41 +0200 | [diff] [blame] | 491 | static void dsi_completion_handler(void *data, u32 mask) |
| 492 | { |
| 493 | complete((struct completion *)data); |
| 494 | } |
| 495 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 496 | static inline int wait_for_bit_change(struct platform_device *dsidev, |
| 497 | const struct dsi_reg idx, int bitnum, int value) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 498 | { |
Tomi Valkeinen | 3b98409 | 2011-10-13 19:06:49 +0300 | [diff] [blame] | 499 | unsigned long timeout; |
| 500 | ktime_t wait; |
| 501 | int t; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 502 | |
Tomi Valkeinen | 3b98409 | 2011-10-13 19:06:49 +0300 | [diff] [blame] | 503 | /* first busyloop to see if the bit changes right away */ |
| 504 | t = 100; |
| 505 | while (t-- > 0) { |
| 506 | if (REG_GET(dsidev, idx, bitnum, bitnum) == value) |
| 507 | return value; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 508 | } |
| 509 | |
Tomi Valkeinen | 3b98409 | 2011-10-13 19:06:49 +0300 | [diff] [blame] | 510 | /* then loop for 500ms, sleeping for 1ms in between */ |
| 511 | timeout = jiffies + msecs_to_jiffies(500); |
| 512 | while (time_before(jiffies, timeout)) { |
| 513 | if (REG_GET(dsidev, idx, bitnum, bitnum) == value) |
| 514 | return value; |
| 515 | |
| 516 | wait = ns_to_ktime(1000 * 1000); |
| 517 | set_current_state(TASK_UNINTERRUPTIBLE); |
| 518 | schedule_hrtimeout(&wait, HRTIMER_MODE_REL); |
| 519 | } |
| 520 | |
| 521 | return !value; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 522 | } |
| 523 | |
Archit Taneja | a3b3cc2 | 2011-09-08 18:42:16 +0530 | [diff] [blame] | 524 | u8 dsi_get_pixel_size(enum omap_dss_dsi_pixel_format fmt) |
| 525 | { |
| 526 | switch (fmt) { |
| 527 | case OMAP_DSS_DSI_FMT_RGB888: |
| 528 | case OMAP_DSS_DSI_FMT_RGB666: |
| 529 | return 24; |
| 530 | case OMAP_DSS_DSI_FMT_RGB666_PACKED: |
| 531 | return 18; |
| 532 | case OMAP_DSS_DSI_FMT_RGB565: |
| 533 | return 16; |
| 534 | default: |
| 535 | BUG(); |
Tomi Valkeinen | c6eee96 | 2012-05-18 11:47:02 +0300 | [diff] [blame] | 536 | return 0; |
Archit Taneja | a3b3cc2 | 2011-09-08 18:42:16 +0530 | [diff] [blame] | 537 | } |
| 538 | } |
| 539 | |
Tomi Valkeinen | 477fed7 | 2013-10-02 14:41:24 +0300 | [diff] [blame] | 540 | #ifdef DSI_PERF_MEASURE |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 541 | static void dsi_perf_mark_setup(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 542 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 543 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 544 | dsi->perf_setup_time = ktime_get(); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 545 | } |
| 546 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 547 | static void dsi_perf_mark_start(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 548 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 549 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 550 | dsi->perf_start_time = ktime_get(); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 551 | } |
| 552 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 553 | static void dsi_perf_show(struct platform_device *dsidev, const char *name) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 554 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 555 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 556 | ktime_t t, setup_time, trans_time; |
| 557 | u32 total_bytes; |
| 558 | u32 setup_us, trans_us, total_us; |
| 559 | |
| 560 | if (!dsi_perf) |
| 561 | return; |
| 562 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 563 | t = ktime_get(); |
| 564 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 565 | setup_time = ktime_sub(dsi->perf_start_time, dsi->perf_setup_time); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 566 | setup_us = (u32)ktime_to_us(setup_time); |
| 567 | if (setup_us == 0) |
| 568 | setup_us = 1; |
| 569 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 570 | trans_time = ktime_sub(t, dsi->perf_start_time); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 571 | trans_us = (u32)ktime_to_us(trans_time); |
| 572 | if (trans_us == 0) |
| 573 | trans_us = 1; |
| 574 | |
| 575 | total_us = setup_us + trans_us; |
| 576 | |
Tomi Valkeinen | 5476e74 | 2011-11-03 16:34:20 +0200 | [diff] [blame] | 577 | total_bytes = dsi->update_bytes; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 578 | |
Tomi Valkeinen | 1bbb275 | 2010-01-11 16:41:10 +0200 | [diff] [blame] | 579 | printk(KERN_INFO "DSI(%s): %u us + %u us = %u us (%uHz), " |
| 580 | "%u bytes, %u kbytes/sec\n", |
| 581 | name, |
| 582 | setup_us, |
| 583 | trans_us, |
| 584 | total_us, |
| 585 | 1000*1000 / total_us, |
| 586 | total_bytes, |
| 587 | total_bytes * 1000 / total_us); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 588 | } |
| 589 | #else |
Tomi Valkeinen | 4a9a5e3 | 2011-05-23 16:36:09 +0300 | [diff] [blame] | 590 | static inline void dsi_perf_mark_setup(struct platform_device *dsidev) |
| 591 | { |
| 592 | } |
| 593 | |
| 594 | static inline void dsi_perf_mark_start(struct platform_device *dsidev) |
| 595 | { |
| 596 | } |
| 597 | |
| 598 | static inline void dsi_perf_show(struct platform_device *dsidev, |
| 599 | const char *name) |
| 600 | { |
| 601 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 602 | #endif |
| 603 | |
Chandrabhanu Mahapatra | f30be7d | 2012-09-29 12:33:05 +0530 | [diff] [blame] | 604 | static int verbose_irq; |
| 605 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 606 | static void print_irq_status(u32 status) |
| 607 | { |
Tomi Valkeinen | d80d499 | 2011-03-02 15:53:07 +0200 | [diff] [blame] | 608 | if (status == 0) |
| 609 | return; |
| 610 | |
Chandrabhanu Mahapatra | f30be7d | 2012-09-29 12:33:05 +0530 | [diff] [blame] | 611 | if (!verbose_irq && (status & ~DSI_IRQ_CHANNEL_MASK) == 0) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 612 | return; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 613 | |
Chandrabhanu Mahapatra | f30be7d | 2012-09-29 12:33:05 +0530 | [diff] [blame] | 614 | #define PIS(x) (status & DSI_IRQ_##x) ? (#x " ") : "" |
| 615 | |
| 616 | pr_debug("DSI IRQ: 0x%x: %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", |
| 617 | status, |
| 618 | verbose_irq ? PIS(VC0) : "", |
| 619 | verbose_irq ? PIS(VC1) : "", |
| 620 | verbose_irq ? PIS(VC2) : "", |
| 621 | verbose_irq ? PIS(VC3) : "", |
| 622 | PIS(WAKEUP), |
| 623 | PIS(RESYNC), |
| 624 | PIS(PLL_LOCK), |
| 625 | PIS(PLL_UNLOCK), |
| 626 | PIS(PLL_RECALL), |
| 627 | PIS(COMPLEXIO_ERR), |
| 628 | PIS(HS_TX_TIMEOUT), |
| 629 | PIS(LP_RX_TIMEOUT), |
| 630 | PIS(TE_TRIGGER), |
| 631 | PIS(ACK_TRIGGER), |
| 632 | PIS(SYNC_LOST), |
| 633 | PIS(LDO_POWER_GOOD), |
| 634 | PIS(TA_TIMEOUT)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 635 | #undef PIS |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | static void print_irq_status_vc(int channel, u32 status) |
| 639 | { |
Tomi Valkeinen | d80d499 | 2011-03-02 15:53:07 +0200 | [diff] [blame] | 640 | if (status == 0) |
| 641 | return; |
| 642 | |
Chandrabhanu Mahapatra | f30be7d | 2012-09-29 12:33:05 +0530 | [diff] [blame] | 643 | if (!verbose_irq && (status & ~DSI_VC_IRQ_PACKET_SENT) == 0) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 644 | return; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 645 | |
Chandrabhanu Mahapatra | f30be7d | 2012-09-29 12:33:05 +0530 | [diff] [blame] | 646 | #define PIS(x) (status & DSI_VC_IRQ_##x) ? (#x " ") : "" |
| 647 | |
| 648 | pr_debug("DSI VC(%d) IRQ 0x%x: %s%s%s%s%s%s%s%s%s\n", |
| 649 | channel, |
| 650 | status, |
| 651 | PIS(CS), |
| 652 | PIS(ECC_CORR), |
| 653 | PIS(ECC_NO_CORR), |
| 654 | verbose_irq ? PIS(PACKET_SENT) : "", |
| 655 | PIS(BTA), |
| 656 | PIS(FIFO_TX_OVF), |
| 657 | PIS(FIFO_RX_OVF), |
| 658 | PIS(FIFO_TX_UDF), |
| 659 | PIS(PP_BUSY_CHANGE)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 660 | #undef PIS |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | static void print_irq_status_cio(u32 status) |
| 664 | { |
Tomi Valkeinen | d80d499 | 2011-03-02 15:53:07 +0200 | [diff] [blame] | 665 | if (status == 0) |
| 666 | return; |
| 667 | |
Chandrabhanu Mahapatra | f30be7d | 2012-09-29 12:33:05 +0530 | [diff] [blame] | 668 | #define PIS(x) (status & DSI_CIO_IRQ_##x) ? (#x " ") : "" |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 669 | |
Chandrabhanu Mahapatra | f30be7d | 2012-09-29 12:33:05 +0530 | [diff] [blame] | 670 | 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", |
| 671 | status, |
| 672 | PIS(ERRSYNCESC1), |
| 673 | PIS(ERRSYNCESC2), |
| 674 | PIS(ERRSYNCESC3), |
| 675 | PIS(ERRESC1), |
| 676 | PIS(ERRESC2), |
| 677 | PIS(ERRESC3), |
| 678 | PIS(ERRCONTROL1), |
| 679 | PIS(ERRCONTROL2), |
| 680 | PIS(ERRCONTROL3), |
| 681 | PIS(STATEULPS1), |
| 682 | PIS(STATEULPS2), |
| 683 | PIS(STATEULPS3), |
| 684 | PIS(ERRCONTENTIONLP0_1), |
| 685 | PIS(ERRCONTENTIONLP1_1), |
| 686 | PIS(ERRCONTENTIONLP0_2), |
| 687 | PIS(ERRCONTENTIONLP1_2), |
| 688 | PIS(ERRCONTENTIONLP0_3), |
| 689 | PIS(ERRCONTENTIONLP1_3), |
| 690 | PIS(ULPSACTIVENOT_ALL0), |
| 691 | PIS(ULPSACTIVENOT_ALL1)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 692 | #undef PIS |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 693 | } |
| 694 | |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 695 | #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 696 | static void dsi_collect_irq_stats(struct platform_device *dsidev, u32 irqstatus, |
| 697 | u32 *vcstatus, u32 ciostatus) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 698 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 699 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 700 | int i; |
| 701 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 702 | spin_lock(&dsi->irq_stats_lock); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 703 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 704 | dsi->irq_stats.irq_count++; |
| 705 | dss_collect_irq_stats(irqstatus, dsi->irq_stats.dsi_irqs); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 706 | |
| 707 | for (i = 0; i < 4; ++i) |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 708 | dss_collect_irq_stats(vcstatus[i], dsi->irq_stats.vc_irqs[i]); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 709 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 710 | dss_collect_irq_stats(ciostatus, dsi->irq_stats.cio_irqs); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 711 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 712 | spin_unlock(&dsi->irq_stats_lock); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 713 | } |
| 714 | #else |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 715 | #define dsi_collect_irq_stats(dsidev, irqstatus, vcstatus, ciostatus) |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 716 | #endif |
| 717 | |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 718 | static int debug_irq; |
| 719 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 720 | static void dsi_handle_irq_errors(struct platform_device *dsidev, u32 irqstatus, |
| 721 | u32 *vcstatus, u32 ciostatus) |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 722 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 723 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 724 | int i; |
| 725 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 726 | if (irqstatus & DSI_IRQ_ERROR_MASK) { |
| 727 | DSSERR("DSI error, irqstatus %x\n", irqstatus); |
| 728 | print_irq_status(irqstatus); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 729 | spin_lock(&dsi->errors_lock); |
| 730 | dsi->errors |= irqstatus & DSI_IRQ_ERROR_MASK; |
| 731 | spin_unlock(&dsi->errors_lock); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 732 | } else if (debug_irq) { |
| 733 | print_irq_status(irqstatus); |
| 734 | } |
| 735 | |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 736 | for (i = 0; i < 4; ++i) { |
| 737 | if (vcstatus[i] & DSI_VC_IRQ_ERROR_MASK) { |
| 738 | DSSERR("DSI VC(%d) error, vc irqstatus %x\n", |
| 739 | i, vcstatus[i]); |
| 740 | print_irq_status_vc(i, vcstatus[i]); |
| 741 | } else if (debug_irq) { |
| 742 | print_irq_status_vc(i, vcstatus[i]); |
| 743 | } |
| 744 | } |
| 745 | |
| 746 | if (ciostatus & DSI_CIO_IRQ_ERROR_MASK) { |
| 747 | DSSERR("DSI CIO error, cio irqstatus %x\n", ciostatus); |
| 748 | print_irq_status_cio(ciostatus); |
| 749 | } else if (debug_irq) { |
| 750 | print_irq_status_cio(ciostatus); |
| 751 | } |
| 752 | } |
| 753 | |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 754 | static void dsi_call_isrs(struct dsi_isr_data *isr_array, |
| 755 | unsigned isr_array_size, u32 irqstatus) |
| 756 | { |
| 757 | struct dsi_isr_data *isr_data; |
| 758 | int i; |
| 759 | |
| 760 | for (i = 0; i < isr_array_size; i++) { |
| 761 | isr_data = &isr_array[i]; |
| 762 | if (isr_data->isr && isr_data->mask & irqstatus) |
| 763 | isr_data->isr(isr_data->arg, irqstatus); |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | static void dsi_handle_isrs(struct dsi_isr_tables *isr_tables, |
| 768 | u32 irqstatus, u32 *vcstatus, u32 ciostatus) |
| 769 | { |
| 770 | int i; |
| 771 | |
| 772 | dsi_call_isrs(isr_tables->isr_table, |
| 773 | ARRAY_SIZE(isr_tables->isr_table), |
| 774 | irqstatus); |
| 775 | |
| 776 | for (i = 0; i < 4; ++i) { |
| 777 | if (vcstatus[i] == 0) |
| 778 | continue; |
| 779 | dsi_call_isrs(isr_tables->isr_table_vc[i], |
| 780 | ARRAY_SIZE(isr_tables->isr_table_vc[i]), |
| 781 | vcstatus[i]); |
| 782 | } |
| 783 | |
| 784 | if (ciostatus != 0) |
| 785 | dsi_call_isrs(isr_tables->isr_table_cio, |
| 786 | ARRAY_SIZE(isr_tables->isr_table_cio), |
| 787 | ciostatus); |
| 788 | } |
| 789 | |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 790 | static irqreturn_t omap_dsi_irq_handler(int irq, void *arg) |
| 791 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 792 | struct platform_device *dsidev; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 793 | struct dsi_data *dsi; |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 794 | u32 irqstatus, vcstatus[4], ciostatus; |
| 795 | int i; |
| 796 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 797 | dsidev = (struct platform_device *) arg; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 798 | dsi = dsi_get_dsidrv_data(dsidev); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 799 | |
Tomi Valkeinen | 0925afc | 2014-04-11 13:49:55 +0300 | [diff] [blame] | 800 | if (!dsi->is_enabled) |
| 801 | return IRQ_NONE; |
| 802 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 803 | spin_lock(&dsi->irq_lock); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 804 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 805 | irqstatus = dsi_read_reg(dsidev, DSI_IRQSTATUS); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 806 | |
| 807 | /* IRQ is not for us */ |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 808 | if (!irqstatus) { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 809 | spin_unlock(&dsi->irq_lock); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 810 | return IRQ_NONE; |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 811 | } |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 812 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 813 | dsi_write_reg(dsidev, DSI_IRQSTATUS, irqstatus & ~DSI_IRQ_CHANNEL_MASK); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 814 | /* flush posted write */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 815 | dsi_read_reg(dsidev, DSI_IRQSTATUS); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 816 | |
| 817 | for (i = 0; i < 4; ++i) { |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 818 | if ((irqstatus & (1 << i)) == 0) { |
| 819 | vcstatus[i] = 0; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 820 | continue; |
Tomi Valkeinen | ab83b14 | 2010-06-09 15:31:01 +0300 | [diff] [blame] | 821 | } |
| 822 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 823 | vcstatus[i] = dsi_read_reg(dsidev, DSI_VC_IRQSTATUS(i)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 824 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 825 | dsi_write_reg(dsidev, DSI_VC_IRQSTATUS(i), vcstatus[i]); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 826 | /* flush posted write */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 827 | dsi_read_reg(dsidev, DSI_VC_IRQSTATUS(i)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | if (irqstatus & DSI_IRQ_COMPLEXIO_ERR) { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 831 | ciostatus = dsi_read_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 832 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 833 | dsi_write_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS, ciostatus); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 834 | /* flush posted write */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 835 | dsi_read_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 836 | } else { |
| 837 | ciostatus = 0; |
| 838 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 839 | |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 840 | #ifdef DSI_CATCH_MISSING_TE |
| 841 | if (irqstatus & DSI_IRQ_TE_TRIGGER) |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 842 | del_timer(&dsi->te_timer); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 843 | #endif |
| 844 | |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 845 | /* make a copy and unlock, so that isrs can unregister |
| 846 | * themselves */ |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 847 | memcpy(&dsi->isr_tables_copy, &dsi->isr_tables, |
| 848 | sizeof(dsi->isr_tables)); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 849 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 850 | spin_unlock(&dsi->irq_lock); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 851 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 852 | dsi_handle_isrs(&dsi->isr_tables_copy, irqstatus, vcstatus, ciostatus); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 853 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 854 | dsi_handle_irq_errors(dsidev, irqstatus, vcstatus, ciostatus); |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 855 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 856 | dsi_collect_irq_stats(dsidev, irqstatus, vcstatus, ciostatus); |
Tomi Valkeinen | 69b281a | 2011-03-02 14:44:27 +0200 | [diff] [blame] | 857 | |
archit taneja | affe360 | 2011-02-23 08:41:03 +0000 | [diff] [blame] | 858 | return IRQ_HANDLED; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 859 | } |
| 860 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 861 | /* dsi->irq_lock has to be locked by the caller */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 862 | static void _omap_dsi_configure_irqs(struct platform_device *dsidev, |
| 863 | struct dsi_isr_data *isr_array, |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 864 | unsigned isr_array_size, u32 default_mask, |
| 865 | const struct dsi_reg enable_reg, |
| 866 | const struct dsi_reg status_reg) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 867 | { |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 868 | struct dsi_isr_data *isr_data; |
| 869 | u32 mask; |
| 870 | u32 old_mask; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 871 | int i; |
| 872 | |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 873 | mask = default_mask; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 874 | |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 875 | for (i = 0; i < isr_array_size; i++) { |
| 876 | isr_data = &isr_array[i]; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 877 | |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 878 | if (isr_data->isr == NULL) |
| 879 | continue; |
| 880 | |
| 881 | mask |= isr_data->mask; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 882 | } |
| 883 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 884 | old_mask = dsi_read_reg(dsidev, enable_reg); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 885 | /* clear the irqstatus for newly enabled irqs */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 886 | dsi_write_reg(dsidev, status_reg, (mask ^ old_mask) & mask); |
| 887 | dsi_write_reg(dsidev, enable_reg, mask); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 888 | |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 889 | /* flush posted writes */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 890 | dsi_read_reg(dsidev, enable_reg); |
| 891 | dsi_read_reg(dsidev, status_reg); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 892 | } |
| 893 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 894 | /* dsi->irq_lock has to be locked by the caller */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 895 | static void _omap_dsi_set_irqs(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 | u32 mask = DSI_IRQ_ERROR_MASK; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 899 | #ifdef DSI_CATCH_MISSING_TE |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 900 | mask |= DSI_IRQ_TE_TRIGGER; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 901 | #endif |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 902 | _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table, |
| 903 | ARRAY_SIZE(dsi->isr_tables.isr_table), mask, |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 904 | DSI_IRQENABLE, DSI_IRQSTATUS); |
| 905 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 906 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 907 | /* dsi->irq_lock has to be locked by the caller */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 908 | 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] | 909 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 910 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 911 | |
| 912 | _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table_vc[vc], |
| 913 | ARRAY_SIZE(dsi->isr_tables.isr_table_vc[vc]), |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 914 | DSI_VC_IRQ_ERROR_MASK, |
| 915 | DSI_VC_IRQENABLE(vc), DSI_VC_IRQSTATUS(vc)); |
| 916 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 917 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 918 | /* dsi->irq_lock has to be locked by the caller */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 919 | static void _omap_dsi_set_irqs_cio(struct platform_device *dsidev) |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 920 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 921 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 922 | |
| 923 | _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table_cio, |
| 924 | ARRAY_SIZE(dsi->isr_tables.isr_table_cio), |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 925 | DSI_CIO_IRQ_ERROR_MASK, |
| 926 | DSI_COMPLEXIO_IRQ_ENABLE, DSI_COMPLEXIO_IRQ_STATUS); |
| 927 | } |
| 928 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 929 | static void _dsi_initialize_irq(struct platform_device *dsidev) |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 930 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 931 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 932 | unsigned long flags; |
| 933 | int vc; |
| 934 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 935 | spin_lock_irqsave(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 936 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 937 | memset(&dsi->isr_tables, 0, sizeof(dsi->isr_tables)); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 938 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 939 | _omap_dsi_set_irqs(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 940 | for (vc = 0; vc < 4; ++vc) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 941 | _omap_dsi_set_irqs_vc(dsidev, vc); |
| 942 | _omap_dsi_set_irqs_cio(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 943 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 944 | spin_unlock_irqrestore(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | static int _dsi_register_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 free_idx; |
| 952 | int i; |
| 953 | |
| 954 | BUG_ON(isr == NULL); |
| 955 | |
| 956 | /* check for duplicate entry and find a free slot */ |
| 957 | free_idx = -1; |
| 958 | for (i = 0; i < isr_array_size; i++) { |
| 959 | isr_data = &isr_array[i]; |
| 960 | |
| 961 | if (isr_data->isr == isr && isr_data->arg == arg && |
| 962 | isr_data->mask == mask) { |
| 963 | return -EINVAL; |
| 964 | } |
| 965 | |
| 966 | if (isr_data->isr == NULL && free_idx == -1) |
| 967 | free_idx = i; |
| 968 | } |
| 969 | |
| 970 | if (free_idx == -1) |
| 971 | return -EBUSY; |
| 972 | |
| 973 | isr_data = &isr_array[free_idx]; |
| 974 | isr_data->isr = isr; |
| 975 | isr_data->arg = arg; |
| 976 | isr_data->mask = mask; |
| 977 | |
| 978 | return 0; |
| 979 | } |
| 980 | |
| 981 | static int _dsi_unregister_isr(omap_dsi_isr_t isr, void *arg, u32 mask, |
| 982 | struct dsi_isr_data *isr_array, unsigned isr_array_size) |
| 983 | { |
| 984 | struct dsi_isr_data *isr_data; |
| 985 | int i; |
| 986 | |
| 987 | for (i = 0; i < isr_array_size; i++) { |
| 988 | isr_data = &isr_array[i]; |
| 989 | if (isr_data->isr != isr || isr_data->arg != arg || |
| 990 | isr_data->mask != mask) |
| 991 | continue; |
| 992 | |
| 993 | isr_data->isr = NULL; |
| 994 | isr_data->arg = NULL; |
| 995 | isr_data->mask = 0; |
| 996 | |
| 997 | return 0; |
| 998 | } |
| 999 | |
| 1000 | return -EINVAL; |
| 1001 | } |
| 1002 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1003 | static int dsi_register_isr(struct platform_device *dsidev, omap_dsi_isr_t isr, |
| 1004 | void *arg, u32 mask) |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1005 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1006 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1007 | unsigned long flags; |
| 1008 | int r; |
| 1009 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1010 | spin_lock_irqsave(&dsi->irq_lock, flags); |
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 | r = _dsi_register_isr(isr, arg, mask, dsi->isr_tables.isr_table, |
| 1013 | ARRAY_SIZE(dsi->isr_tables.isr_table)); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1014 | |
| 1015 | if (r == 0) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1016 | _omap_dsi_set_irqs(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1017 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1018 | spin_unlock_irqrestore(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1019 | |
| 1020 | return r; |
| 1021 | } |
| 1022 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1023 | static int dsi_unregister_isr(struct platform_device *dsidev, |
| 1024 | omap_dsi_isr_t isr, void *arg, u32 mask) |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1025 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1026 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1027 | unsigned long flags; |
| 1028 | int r; |
| 1029 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1030 | spin_lock_irqsave(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1031 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1032 | r = _dsi_unregister_isr(isr, arg, mask, dsi->isr_tables.isr_table, |
| 1033 | ARRAY_SIZE(dsi->isr_tables.isr_table)); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1034 | |
| 1035 | if (r == 0) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1036 | _omap_dsi_set_irqs(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1037 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1038 | spin_unlock_irqrestore(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1039 | |
| 1040 | return r; |
| 1041 | } |
| 1042 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1043 | static int dsi_register_isr_vc(struct platform_device *dsidev, int channel, |
| 1044 | omap_dsi_isr_t isr, void *arg, u32 mask) |
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 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1047 | unsigned long flags; |
| 1048 | int r; |
| 1049 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1050 | spin_lock_irqsave(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1051 | |
| 1052 | r = _dsi_register_isr(isr, arg, mask, |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1053 | dsi->isr_tables.isr_table_vc[channel], |
| 1054 | ARRAY_SIZE(dsi->isr_tables.isr_table_vc[channel])); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1055 | |
| 1056 | if (r == 0) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1057 | _omap_dsi_set_irqs_vc(dsidev, channel); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1058 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1059 | spin_unlock_irqrestore(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1060 | |
| 1061 | return r; |
| 1062 | } |
| 1063 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1064 | static int dsi_unregister_isr_vc(struct platform_device *dsidev, int channel, |
| 1065 | omap_dsi_isr_t isr, void *arg, u32 mask) |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1066 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1067 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1068 | unsigned long flags; |
| 1069 | int r; |
| 1070 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1071 | spin_lock_irqsave(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1072 | |
| 1073 | r = _dsi_unregister_isr(isr, arg, mask, |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1074 | dsi->isr_tables.isr_table_vc[channel], |
| 1075 | ARRAY_SIZE(dsi->isr_tables.isr_table_vc[channel])); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1076 | |
| 1077 | if (r == 0) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1078 | _omap_dsi_set_irqs_vc(dsidev, channel); |
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 | spin_unlock_irqrestore(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1081 | |
| 1082 | return r; |
| 1083 | } |
| 1084 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1085 | static int dsi_register_isr_cio(struct platform_device *dsidev, |
| 1086 | omap_dsi_isr_t isr, void *arg, u32 mask) |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1087 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1088 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1089 | unsigned long flags; |
| 1090 | int r; |
| 1091 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1092 | spin_lock_irqsave(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1093 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1094 | r = _dsi_register_isr(isr, arg, mask, dsi->isr_tables.isr_table_cio, |
| 1095 | ARRAY_SIZE(dsi->isr_tables.isr_table_cio)); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1096 | |
| 1097 | if (r == 0) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1098 | _omap_dsi_set_irqs_cio(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1099 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1100 | spin_unlock_irqrestore(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1101 | |
| 1102 | return r; |
| 1103 | } |
| 1104 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1105 | static int dsi_unregister_isr_cio(struct platform_device *dsidev, |
| 1106 | omap_dsi_isr_t isr, void *arg, u32 mask) |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1107 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1108 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1109 | unsigned long flags; |
| 1110 | int r; |
| 1111 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1112 | spin_lock_irqsave(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1113 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1114 | r = _dsi_unregister_isr(isr, arg, mask, dsi->isr_tables.isr_table_cio, |
| 1115 | ARRAY_SIZE(dsi->isr_tables.isr_table_cio)); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1116 | |
| 1117 | if (r == 0) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1118 | _omap_dsi_set_irqs_cio(dsidev); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1119 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1120 | spin_unlock_irqrestore(&dsi->irq_lock, flags); |
Tomi Valkeinen | 4ae2ddd | 2011-03-02 14:47:04 +0200 | [diff] [blame] | 1121 | |
| 1122 | return r; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1123 | } |
| 1124 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1125 | static u32 dsi_get_errors(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1126 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1127 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1128 | unsigned long flags; |
| 1129 | u32 e; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1130 | spin_lock_irqsave(&dsi->errors_lock, flags); |
| 1131 | e = dsi->errors; |
| 1132 | dsi->errors = 0; |
| 1133 | spin_unlock_irqrestore(&dsi->errors_lock, flags); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1134 | return e; |
| 1135 | } |
| 1136 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1137 | int dsi_runtime_get(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1138 | { |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1139 | int r; |
| 1140 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1141 | |
| 1142 | DSSDBG("dsi_runtime_get\n"); |
| 1143 | |
| 1144 | r = pm_runtime_get_sync(&dsi->pdev->dev); |
| 1145 | WARN_ON(r < 0); |
| 1146 | return r < 0 ? r : 0; |
| 1147 | } |
| 1148 | |
| 1149 | void dsi_runtime_put(struct platform_device *dsidev) |
| 1150 | { |
| 1151 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1152 | int r; |
| 1153 | |
| 1154 | DSSDBG("dsi_runtime_put\n"); |
| 1155 | |
Tomi Valkeinen | 0eaf9f5 | 2012-01-23 13:23:08 +0200 | [diff] [blame] | 1156 | r = pm_runtime_put_sync(&dsi->pdev->dev); |
Tomi Valkeinen | 5be3aeb | 2012-06-27 16:37:18 +0300 | [diff] [blame] | 1157 | WARN_ON(r < 0 && r != -ENOSYS); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1158 | } |
| 1159 | |
Tomi Valkeinen | b2541c4 | 2013-05-03 13:42:24 +0300 | [diff] [blame] | 1160 | static int dsi_regulator_init(struct platform_device *dsidev) |
| 1161 | { |
| 1162 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1163 | struct regulator *vdds_dsi; |
Tomi Valkeinen | 02b7a32 | 2014-03-13 14:33:03 +0200 | [diff] [blame] | 1164 | int r; |
Tomi Valkeinen | b2541c4 | 2013-05-03 13:42:24 +0300 | [diff] [blame] | 1165 | |
| 1166 | if (dsi->vdds_dsi_reg != NULL) |
| 1167 | return 0; |
| 1168 | |
Tomi Valkeinen | 931d4bd | 2013-06-10 14:05:10 +0300 | [diff] [blame] | 1169 | vdds_dsi = devm_regulator_get(&dsi->pdev->dev, "vdd"); |
Tomi Valkeinen | b2541c4 | 2013-05-03 13:42:24 +0300 | [diff] [blame] | 1170 | |
| 1171 | if (IS_ERR(vdds_dsi)) { |
Tomi Valkeinen | 40359a9 | 2013-12-19 16:15:34 +0200 | [diff] [blame] | 1172 | if (PTR_ERR(vdds_dsi) != -EPROBE_DEFER) |
Tomi Valkeinen | 931d4bd | 2013-06-10 14:05:10 +0300 | [diff] [blame] | 1173 | DSSERR("can't get DSI VDD regulator\n"); |
Tomi Valkeinen | b2541c4 | 2013-05-03 13:42:24 +0300 | [diff] [blame] | 1174 | return PTR_ERR(vdds_dsi); |
| 1175 | } |
| 1176 | |
Tomi Valkeinen | 02b7a32 | 2014-03-13 14:33:03 +0200 | [diff] [blame] | 1177 | if (regulator_can_change_voltage(vdds_dsi)) { |
| 1178 | r = regulator_set_voltage(vdds_dsi, 1800000, 1800000); |
| 1179 | if (r) { |
| 1180 | devm_regulator_put(vdds_dsi); |
| 1181 | DSSERR("can't set the DSI regulator voltage\n"); |
| 1182 | return r; |
| 1183 | } |
| 1184 | } |
| 1185 | |
Tomi Valkeinen | b2541c4 | 2013-05-03 13:42:24 +0300 | [diff] [blame] | 1186 | dsi->vdds_dsi_reg = vdds_dsi; |
| 1187 | |
| 1188 | return 0; |
| 1189 | } |
| 1190 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1191 | /* source clock for DSI PLL. this could also be PCLKFREE */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1192 | static inline void dsi_enable_pll_clock(struct platform_device *dsidev, |
| 1193 | bool enable) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1194 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1195 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1196 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1197 | if (enable) |
Rajendra Nayak | f11766d | 2012-06-27 14:21:26 +0530 | [diff] [blame] | 1198 | clk_prepare_enable(dsi->sys_clk); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1199 | else |
Rajendra Nayak | f11766d | 2012-06-27 14:21:26 +0530 | [diff] [blame] | 1200 | clk_disable_unprepare(dsi->sys_clk); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1201 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1202 | if (enable && dsi->pll_locked) { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1203 | if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 1, 1) != 1) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1204 | DSSERR("cannot lock PLL when enabling clocks\n"); |
| 1205 | } |
| 1206 | } |
| 1207 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1208 | static void _dsi_print_reset_status(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1209 | { |
| 1210 | u32 l; |
Tomi Valkeinen | c335cbf | 2010-10-07 13:27:42 +0300 | [diff] [blame] | 1211 | int b0, b1, b2; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1212 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1213 | /* A dummy read using the SCP interface to any DSIPHY register is |
| 1214 | * required after DSIPHY reset to complete the reset of the DSI complex |
| 1215 | * I/O. */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1216 | l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1217 | |
Tomi Valkeinen | c335cbf | 2010-10-07 13:27:42 +0300 | [diff] [blame] | 1218 | if (dss_has_feature(FEAT_DSI_REVERSE_TXCLKESC)) { |
| 1219 | b0 = 28; |
| 1220 | b1 = 27; |
| 1221 | b2 = 26; |
| 1222 | } else { |
| 1223 | b0 = 24; |
| 1224 | b1 = 25; |
| 1225 | b2 = 26; |
| 1226 | } |
| 1227 | |
Chandrabhanu Mahapatra | f30be7d | 2012-09-29 12:33:05 +0530 | [diff] [blame] | 1228 | #define DSI_FLD_GET(fld, start, end)\ |
| 1229 | FLD_GET(dsi_read_reg(dsidev, DSI_##fld), start, end) |
| 1230 | |
| 1231 | pr_debug("DSI resets: PLL (%d) CIO (%d) PHY (%x%x%x, %d, %d, %d)\n", |
| 1232 | DSI_FLD_GET(PLL_STATUS, 0, 0), |
| 1233 | DSI_FLD_GET(COMPLEXIO_CFG1, 29, 29), |
| 1234 | DSI_FLD_GET(DSIPHY_CFG5, b0, b0), |
| 1235 | DSI_FLD_GET(DSIPHY_CFG5, b1, b1), |
| 1236 | DSI_FLD_GET(DSIPHY_CFG5, b2, b2), |
| 1237 | DSI_FLD_GET(DSIPHY_CFG5, 29, 29), |
| 1238 | DSI_FLD_GET(DSIPHY_CFG5, 30, 30), |
| 1239 | DSI_FLD_GET(DSIPHY_CFG5, 31, 31)); |
| 1240 | |
| 1241 | #undef DSI_FLD_GET |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1242 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1243 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1244 | static inline int dsi_if_enable(struct platform_device *dsidev, bool enable) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1245 | { |
| 1246 | DSSDBG("dsi_if_enable(%d)\n", enable); |
| 1247 | |
| 1248 | enable = enable ? 1 : 0; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1249 | REG_FLD_MOD(dsidev, DSI_CTRL, enable, 0, 0); /* IF_EN */ |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1250 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1251 | if (wait_for_bit_change(dsidev, DSI_CTRL, 0, enable) != enable) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1252 | DSSERR("Failed to set dsi_if_enable to %d\n", enable); |
| 1253 | return -EIO; |
| 1254 | } |
| 1255 | |
| 1256 | return 0; |
| 1257 | } |
| 1258 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1259 | unsigned long dsi_get_pll_hsdiv_dispc_rate(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1260 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1261 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1262 | |
| 1263 | return dsi->current_cinfo.dsi_pll_hsdiv_dispc_clk; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1264 | } |
| 1265 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1266 | 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] | 1267 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1268 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1269 | |
| 1270 | return dsi->current_cinfo.dsi_pll_hsdiv_dsi_clk; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1271 | } |
| 1272 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1273 | static unsigned long dsi_get_txbyteclkhs(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1274 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1275 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1276 | |
| 1277 | return dsi->current_cinfo.clkin4ddr / 16; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1278 | } |
| 1279 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1280 | static unsigned long dsi_fclk_rate(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1281 | { |
| 1282 | unsigned long r; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1283 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1284 | |
Tomi Valkeinen | 11ee960 | 2012-03-09 16:07:39 +0200 | [diff] [blame] | 1285 | 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] | 1286 | /* DSI FCLK source is DSS_CLK_FCK */ |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1287 | r = clk_get_rate(dsi->dss_clk); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1288 | } else { |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1289 | /* DSI FCLK source is dsi_pll_hsdiv_dsi_clk */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1290 | r = dsi_get_pll_hsdiv_dsi_rate(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1291 | } |
| 1292 | |
| 1293 | return r; |
| 1294 | } |
| 1295 | |
Tomi Valkeinen | f1e0001 | 2013-03-05 17:21:35 +0200 | [diff] [blame] | 1296 | static int dsi_lp_clock_calc(struct dsi_clock_info *cinfo, |
| 1297 | unsigned long lp_clk_min, unsigned long lp_clk_max) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1298 | { |
Tomi Valkeinen | f1e0001 | 2013-03-05 17:21:35 +0200 | [diff] [blame] | 1299 | unsigned long dsi_fclk = cinfo->dsi_pll_hsdiv_dsi_clk; |
| 1300 | unsigned lp_clk_div; |
| 1301 | unsigned long lp_clk; |
| 1302 | |
| 1303 | lp_clk_div = DIV_ROUND_UP(dsi_fclk, lp_clk_max * 2); |
| 1304 | lp_clk = dsi_fclk / 2 / lp_clk_div; |
| 1305 | |
| 1306 | if (lp_clk < lp_clk_min || lp_clk > lp_clk_max) |
| 1307 | return -EINVAL; |
| 1308 | |
| 1309 | cinfo->lp_clk_div = lp_clk_div; |
| 1310 | cinfo->lp_clk = lp_clk; |
| 1311 | |
| 1312 | return 0; |
| 1313 | } |
| 1314 | |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 1315 | static int dsi_set_lp_clk_divisor(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1316 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1317 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1318 | unsigned long dsi_fclk; |
| 1319 | unsigned lp_clk_div; |
| 1320 | unsigned long lp_clk; |
| 1321 | |
Tomi Valkeinen | a0d269e | 2012-11-27 17:05:54 +0200 | [diff] [blame] | 1322 | lp_clk_div = dsi->user_dsi_cinfo.lp_clk_div; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1323 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1324 | if (lp_clk_div == 0 || lp_clk_div > dsi->lpdiv_max) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1325 | return -EINVAL; |
| 1326 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1327 | dsi_fclk = dsi_fclk_rate(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1328 | |
| 1329 | lp_clk = dsi_fclk / 2 / lp_clk_div; |
| 1330 | |
| 1331 | 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] | 1332 | dsi->current_cinfo.lp_clk = lp_clk; |
| 1333 | dsi->current_cinfo.lp_clk_div = lp_clk_div; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1334 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1335 | /* LP_CLK_DIVISOR */ |
| 1336 | REG_FLD_MOD(dsidev, DSI_CLK_CTRL, lp_clk_div, 12, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1337 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1338 | /* LP_RX_SYNCHRO_ENABLE */ |
| 1339 | 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] | 1340 | |
| 1341 | return 0; |
| 1342 | } |
| 1343 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1344 | static void dsi_enable_scp_clk(struct platform_device *dsidev) |
Tomi Valkeinen | 24c1ae4 | 2011-04-13 17:12:52 +0300 | [diff] [blame] | 1345 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1346 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1347 | |
| 1348 | if (dsi->scp_clk_refcount++ == 0) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1349 | 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] | 1350 | } |
| 1351 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1352 | static void dsi_disable_scp_clk(struct platform_device *dsidev) |
Tomi Valkeinen | 24c1ae4 | 2011-04-13 17:12:52 +0300 | [diff] [blame] | 1353 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1354 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1355 | |
| 1356 | WARN_ON(dsi->scp_clk_refcount == 0); |
| 1357 | if (--dsi->scp_clk_refcount == 0) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1358 | 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] | 1359 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1360 | |
| 1361 | enum dsi_pll_power_state { |
| 1362 | DSI_PLL_POWER_OFF = 0x0, |
| 1363 | DSI_PLL_POWER_ON_HSCLK = 0x1, |
| 1364 | DSI_PLL_POWER_ON_ALL = 0x2, |
| 1365 | DSI_PLL_POWER_ON_DIV = 0x3, |
| 1366 | }; |
| 1367 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1368 | static int dsi_pll_power(struct platform_device *dsidev, |
| 1369 | enum dsi_pll_power_state state) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1370 | { |
| 1371 | int t = 0; |
| 1372 | |
Tomi Valkeinen | c94dfe0 | 2011-04-15 10:42:59 +0300 | [diff] [blame] | 1373 | /* DSI-PLL power command 0x3 is not working */ |
| 1374 | if (dss_has_feature(FEAT_DSI_PLL_PWR_BUG) && |
| 1375 | state == DSI_PLL_POWER_ON_DIV) |
| 1376 | state = DSI_PLL_POWER_ON_ALL; |
| 1377 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1378 | /* PLL_PWR_CMD */ |
| 1379 | REG_FLD_MOD(dsidev, DSI_CLK_CTRL, state, 31, 30); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1380 | |
| 1381 | /* PLL_PWR_STATUS */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1382 | 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] | 1383 | if (++t > 1000) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1384 | DSSERR("Failed to set DSI PLL power mode to %d\n", |
| 1385 | state); |
| 1386 | return -ENODEV; |
| 1387 | } |
Tomi Valkeinen | 24be78b | 2010-01-07 14:19:48 +0200 | [diff] [blame] | 1388 | udelay(1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1389 | } |
| 1390 | |
| 1391 | return 0; |
| 1392 | } |
| 1393 | |
Tomi Valkeinen | 72658f0 | 2013-03-05 16:39:00 +0200 | [diff] [blame] | 1394 | unsigned long dsi_get_pll_clkin(struct platform_device *dsidev) |
| 1395 | { |
| 1396 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1397 | return clk_get_rate(dsi->sys_clk); |
| 1398 | } |
| 1399 | |
| 1400 | bool dsi_hsdiv_calc(struct platform_device *dsidev, unsigned long pll, |
| 1401 | unsigned long out_min, dsi_hsdiv_calc_func func, void *data) |
| 1402 | { |
| 1403 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1404 | int regm, regm_start, regm_stop; |
| 1405 | unsigned long out_max; |
| 1406 | unsigned long out; |
| 1407 | |
| 1408 | out_min = out_min ? out_min : 1; |
| 1409 | out_max = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK); |
| 1410 | |
| 1411 | regm_start = max(DIV_ROUND_UP(pll, out_max), 1ul); |
| 1412 | regm_stop = min(pll / out_min, dsi->regm_dispc_max); |
| 1413 | |
| 1414 | for (regm = regm_start; regm <= regm_stop; ++regm) { |
| 1415 | out = pll / regm; |
| 1416 | |
| 1417 | if (func(regm, out, data)) |
| 1418 | return true; |
| 1419 | } |
| 1420 | |
| 1421 | return false; |
| 1422 | } |
| 1423 | |
| 1424 | bool dsi_pll_calc(struct platform_device *dsidev, unsigned long clkin, |
| 1425 | unsigned long pll_min, unsigned long pll_max, |
| 1426 | dsi_pll_calc_func func, void *data) |
| 1427 | { |
| 1428 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1429 | int regn, regn_start, regn_stop; |
| 1430 | int regm, regm_start, regm_stop; |
| 1431 | unsigned long fint, pll; |
| 1432 | const unsigned long pll_hw_max = 1800000000; |
| 1433 | unsigned long fint_hw_min, fint_hw_max; |
| 1434 | |
| 1435 | fint_hw_min = dsi->fint_min; |
| 1436 | fint_hw_max = dsi->fint_max; |
| 1437 | |
| 1438 | regn_start = max(DIV_ROUND_UP(clkin, fint_hw_max), 1ul); |
| 1439 | regn_stop = min(clkin / fint_hw_min, dsi->regn_max); |
| 1440 | |
| 1441 | pll_max = pll_max ? pll_max : ULONG_MAX; |
| 1442 | |
| 1443 | for (regn = regn_start; regn <= regn_stop; ++regn) { |
| 1444 | fint = clkin / regn; |
| 1445 | |
| 1446 | regm_start = max(DIV_ROUND_UP(DIV_ROUND_UP(pll_min, fint), 2), |
| 1447 | 1ul); |
| 1448 | regm_stop = min3(pll_max / fint / 2, |
| 1449 | pll_hw_max / fint / 2, |
| 1450 | dsi->regm_max); |
| 1451 | |
| 1452 | for (regm = regm_start; regm <= regm_stop; ++regm) { |
| 1453 | pll = 2 * regm * fint; |
| 1454 | |
| 1455 | if (func(regn, regm, fint, pll, data)) |
| 1456 | return true; |
| 1457 | } |
| 1458 | } |
| 1459 | |
| 1460 | return false; |
| 1461 | } |
| 1462 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1463 | /* calculate clock rates using dividers in cinfo */ |
Tomi Valkeinen | b6e695a | 2012-03-15 15:22:58 +0200 | [diff] [blame] | 1464 | static int dsi_calc_clock_rates(struct platform_device *dsidev, |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 1465 | struct dsi_clock_info *cinfo) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1466 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1467 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1468 | |
| 1469 | if (cinfo->regn == 0 || cinfo->regn > dsi->regn_max) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1470 | return -EINVAL; |
| 1471 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1472 | if (cinfo->regm == 0 || cinfo->regm > dsi->regm_max) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1473 | return -EINVAL; |
| 1474 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1475 | if (cinfo->regm_dispc > dsi->regm_dispc_max) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1476 | return -EINVAL; |
| 1477 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1478 | if (cinfo->regm_dsi > dsi->regm_dsi_max) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1479 | return -EINVAL; |
| 1480 | |
Tomi Valkeinen | b6e695a | 2012-03-15 15:22:58 +0200 | [diff] [blame] | 1481 | cinfo->clkin = clk_get_rate(dsi->sys_clk); |
| 1482 | cinfo->fint = cinfo->clkin / cinfo->regn; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1483 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1484 | if (cinfo->fint > dsi->fint_max || cinfo->fint < dsi->fint_min) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1485 | return -EINVAL; |
| 1486 | |
| 1487 | cinfo->clkin4ddr = 2 * cinfo->regm * cinfo->fint; |
| 1488 | |
| 1489 | if (cinfo->clkin4ddr > 1800 * 1000 * 1000) |
| 1490 | return -EINVAL; |
| 1491 | |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1492 | if (cinfo->regm_dispc > 0) |
| 1493 | cinfo->dsi_pll_hsdiv_dispc_clk = |
| 1494 | cinfo->clkin4ddr / cinfo->regm_dispc; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1495 | else |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1496 | cinfo->dsi_pll_hsdiv_dispc_clk = 0; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1497 | |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1498 | if (cinfo->regm_dsi > 0) |
| 1499 | cinfo->dsi_pll_hsdiv_dsi_clk = |
| 1500 | cinfo->clkin4ddr / cinfo->regm_dsi; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1501 | else |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1502 | cinfo->dsi_pll_hsdiv_dsi_clk = 0; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1503 | |
| 1504 | return 0; |
| 1505 | } |
| 1506 | |
Tomi Valkeinen | f1e0001 | 2013-03-05 17:21:35 +0200 | [diff] [blame] | 1507 | static void dsi_pll_calc_dsi_fck(struct dsi_clock_info *cinfo) |
Tomi Valkeinen | d66b158 | 2012-09-24 15:15:06 +0300 | [diff] [blame] | 1508 | { |
| 1509 | unsigned long max_dsi_fck; |
| 1510 | |
| 1511 | max_dsi_fck = dss_feat_get_param_max(FEAT_PARAM_DSI_FCK); |
| 1512 | |
| 1513 | cinfo->regm_dsi = DIV_ROUND_UP(cinfo->clkin4ddr, max_dsi_fck); |
| 1514 | cinfo->dsi_pll_hsdiv_dsi_clk = cinfo->clkin4ddr / cinfo->regm_dsi; |
| 1515 | } |
| 1516 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1517 | int dsi_pll_set_clock_div(struct platform_device *dsidev, |
| 1518 | struct dsi_clock_info *cinfo) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1519 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1520 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1521 | int r = 0; |
| 1522 | u32 l; |
Archit Taneja | 9613c02 | 2011-03-22 06:33:36 -0500 | [diff] [blame] | 1523 | int f = 0; |
Taneja, Archit | 4964111 | 2011-03-14 23:28:23 -0500 | [diff] [blame] | 1524 | u8 regn_start, regn_end, regm_start, regm_end; |
| 1525 | 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] | 1526 | |
Chandrabhanu Mahapatra | 702d267 | 2012-09-24 17:12:58 +0530 | [diff] [blame] | 1527 | DSSDBG("DSI PLL clock config starts"); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1528 | |
Tomi Valkeinen | b6e695a | 2012-03-15 15:22:58 +0200 | [diff] [blame] | 1529 | dsi->current_cinfo.clkin = cinfo->clkin; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1530 | dsi->current_cinfo.fint = cinfo->fint; |
| 1531 | dsi->current_cinfo.clkin4ddr = cinfo->clkin4ddr; |
| 1532 | dsi->current_cinfo.dsi_pll_hsdiv_dispc_clk = |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1533 | cinfo->dsi_pll_hsdiv_dispc_clk; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1534 | dsi->current_cinfo.dsi_pll_hsdiv_dsi_clk = |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1535 | cinfo->dsi_pll_hsdiv_dsi_clk; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1536 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1537 | dsi->current_cinfo.regn = cinfo->regn; |
| 1538 | dsi->current_cinfo.regm = cinfo->regm; |
| 1539 | dsi->current_cinfo.regm_dispc = cinfo->regm_dispc; |
| 1540 | dsi->current_cinfo.regm_dsi = cinfo->regm_dsi; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1541 | |
| 1542 | DSSDBG("DSI Fint %ld\n", cinfo->fint); |
| 1543 | |
Tomi Valkeinen | b6e695a | 2012-03-15 15:22:58 +0200 | [diff] [blame] | 1544 | DSSDBG("clkin rate %ld\n", cinfo->clkin); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1545 | |
| 1546 | /* DSIPHY == CLKIN4DDR */ |
Tomi Valkeinen | b6e695a | 2012-03-15 15:22:58 +0200 | [diff] [blame] | 1547 | DSSDBG("CLKIN4DDR = 2 * %d / %d * %lu = %lu\n", |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1548 | cinfo->regm, |
| 1549 | cinfo->regn, |
| 1550 | cinfo->clkin, |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1551 | cinfo->clkin4ddr); |
| 1552 | |
| 1553 | DSSDBG("Data rate on 1 DSI lane %ld Mbps\n", |
| 1554 | cinfo->clkin4ddr / 1000 / 1000 / 2); |
| 1555 | |
| 1556 | DSSDBG("Clock lane freq %ld Hz\n", cinfo->clkin4ddr / 4); |
| 1557 | |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1558 | DSSDBG("regm_dispc = %d, %s (%s) = %lu\n", cinfo->regm_dispc, |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 1559 | dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC), |
| 1560 | 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] | 1561 | cinfo->dsi_pll_hsdiv_dispc_clk); |
| 1562 | DSSDBG("regm_dsi = %d, %s (%s) = %lu\n", cinfo->regm_dsi, |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 1563 | dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI), |
| 1564 | 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] | 1565 | cinfo->dsi_pll_hsdiv_dsi_clk); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1566 | |
Taneja, Archit | 4964111 | 2011-03-14 23:28:23 -0500 | [diff] [blame] | 1567 | dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGN, ®n_start, ®n_end); |
| 1568 | dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM, ®m_start, ®m_end); |
| 1569 | dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DISPC, ®m_dispc_start, |
| 1570 | ®m_dispc_end); |
| 1571 | dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DSI, ®m_dsi_start, |
| 1572 | ®m_dsi_end); |
| 1573 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1574 | /* DSI_PLL_AUTOMODE = manual */ |
| 1575 | REG_FLD_MOD(dsidev, DSI_PLL_CONTROL, 0, 0, 0); |
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 | l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1578 | l = FLD_MOD(l, 1, 0, 0); /* DSI_PLL_STOPMODE */ |
Taneja, Archit | 4964111 | 2011-03-14 23:28:23 -0500 | [diff] [blame] | 1579 | /* DSI_PLL_REGN */ |
| 1580 | l = FLD_MOD(l, cinfo->regn - 1, regn_start, regn_end); |
| 1581 | /* DSI_PLL_REGM */ |
| 1582 | l = FLD_MOD(l, cinfo->regm, regm_start, regm_end); |
| 1583 | /* DSI_CLOCK_DIV */ |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1584 | 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] | 1585 | regm_dispc_start, regm_dispc_end); |
| 1586 | /* DSIPROTO_CLOCK_DIV */ |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1587 | 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] | 1588 | regm_dsi_start, regm_dsi_end); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1589 | dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION1, l); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1590 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1591 | BUG_ON(cinfo->fint < dsi->fint_min || cinfo->fint > dsi->fint_max); |
Archit Taneja | 9613c02 | 2011-03-22 06:33:36 -0500 | [diff] [blame] | 1592 | |
Tomi Valkeinen | f8ef3d6 | 2012-08-22 16:00:31 +0300 | [diff] [blame] | 1593 | l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION2); |
| 1594 | |
Archit Taneja | 9613c02 | 2011-03-22 06:33:36 -0500 | [diff] [blame] | 1595 | if (dss_has_feature(FEAT_DSI_PLL_FREQSEL)) { |
| 1596 | f = cinfo->fint < 1000000 ? 0x3 : |
| 1597 | cinfo->fint < 1250000 ? 0x4 : |
| 1598 | cinfo->fint < 1500000 ? 0x5 : |
| 1599 | cinfo->fint < 1750000 ? 0x6 : |
| 1600 | 0x7; |
Tomi Valkeinen | f8ef3d6 | 2012-08-22 16:00:31 +0300 | [diff] [blame] | 1601 | |
| 1602 | l = FLD_MOD(l, f, 4, 1); /* DSI_PLL_FREQSEL */ |
| 1603 | } else if (dss_has_feature(FEAT_DSI_PLL_SELFREQDCO)) { |
| 1604 | f = cinfo->clkin4ddr < 1000000000 ? 0x2 : 0x4; |
| 1605 | |
| 1606 | l = FLD_MOD(l, f, 4, 1); /* PLL_SELFREQDCO */ |
Archit Taneja | 9613c02 | 2011-03-22 06:33:36 -0500 | [diff] [blame] | 1607 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1608 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1609 | l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */ |
| 1610 | l = FLD_MOD(l, 0, 14, 14); /* DSIPHY_CLKINEN */ |
| 1611 | l = FLD_MOD(l, 1, 20, 20); /* DSI_HSDIVBYPASS */ |
Tomi Valkeinen | 6d44610 | 2012-08-22 16:00:40 +0300 | [diff] [blame] | 1612 | if (dss_has_feature(FEAT_DSI_PLL_REFSEL)) |
| 1613 | l = FLD_MOD(l, 3, 22, 21); /* REF_SYSCLK = sysclk */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1614 | dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION2, l); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1615 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1616 | 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] | 1617 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1618 | if (wait_for_bit_change(dsidev, DSI_PLL_GO, 0, 0) != 0) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1619 | DSSERR("dsi pll go bit not going down.\n"); |
| 1620 | r = -EIO; |
| 1621 | goto err; |
| 1622 | } |
| 1623 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1624 | if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 1, 1) != 1) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1625 | DSSERR("cannot lock PLL\n"); |
| 1626 | r = -EIO; |
| 1627 | goto err; |
| 1628 | } |
| 1629 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1630 | dsi->pll_locked = 1; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1631 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1632 | l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION2); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1633 | l = FLD_MOD(l, 0, 0, 0); /* DSI_PLL_IDLE */ |
| 1634 | l = FLD_MOD(l, 0, 5, 5); /* DSI_PLL_PLLLPMODE */ |
| 1635 | l = FLD_MOD(l, 0, 6, 6); /* DSI_PLL_LOWCURRSTBY */ |
| 1636 | l = FLD_MOD(l, 0, 7, 7); /* DSI_PLL_TIGHTPHASELOCK */ |
| 1637 | l = FLD_MOD(l, 0, 8, 8); /* DSI_PLL_DRIFTGUARDEN */ |
| 1638 | l = FLD_MOD(l, 0, 10, 9); /* DSI_PLL_LOCKSEL */ |
| 1639 | l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */ |
| 1640 | l = FLD_MOD(l, 1, 14, 14); /* DSIPHY_CLKINEN */ |
| 1641 | l = FLD_MOD(l, 0, 15, 15); /* DSI_BYPASSEN */ |
| 1642 | l = FLD_MOD(l, 1, 16, 16); /* DSS_CLOCK_EN */ |
| 1643 | l = FLD_MOD(l, 0, 17, 17); /* DSS_CLOCK_PWDN */ |
| 1644 | l = FLD_MOD(l, 1, 18, 18); /* DSI_PROTO_CLOCK_EN */ |
| 1645 | l = FLD_MOD(l, 0, 19, 19); /* DSI_PROTO_CLOCK_PWDN */ |
| 1646 | l = FLD_MOD(l, 0, 20, 20); /* DSI_HSDIVBYPASS */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1647 | dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION2, l); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1648 | |
| 1649 | DSSDBG("PLL config done\n"); |
| 1650 | err: |
| 1651 | return r; |
| 1652 | } |
| 1653 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1654 | int dsi_pll_init(struct platform_device *dsidev, bool enable_hsclk, |
| 1655 | bool enable_hsdiv) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1656 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1657 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1658 | int r = 0; |
| 1659 | enum dsi_pll_power_state pwstate; |
| 1660 | |
| 1661 | DSSDBG("PLL init\n"); |
| 1662 | |
Tomi Valkeinen | 7a98786 | 2012-10-12 16:27:28 +0300 | [diff] [blame] | 1663 | /* |
| 1664 | * It seems that on many OMAPs we need to enable both to have a |
| 1665 | * functional HSDivider. |
| 1666 | */ |
| 1667 | enable_hsclk = enable_hsdiv = true; |
| 1668 | |
Tomi Valkeinen | b2541c4 | 2013-05-03 13:42:24 +0300 | [diff] [blame] | 1669 | r = dsi_regulator_init(dsidev); |
| 1670 | if (r) |
| 1671 | return r; |
Tomi Valkeinen | f2988ab | 2011-03-02 10:06:48 +0200 | [diff] [blame] | 1672 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1673 | dsi_enable_pll_clock(dsidev, 1); |
Tomi Valkeinen | 24c1ae4 | 2011-04-13 17:12:52 +0300 | [diff] [blame] | 1674 | /* |
| 1675 | * Note: SCP CLK is not required on OMAP3, but it is required on OMAP4. |
| 1676 | */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1677 | dsi_enable_scp_clk(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1678 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1679 | if (!dsi->vdds_dsi_enabled) { |
| 1680 | r = regulator_enable(dsi->vdds_dsi_reg); |
Tomi Valkeinen | 2a89dc1 | 2010-07-30 12:39:34 +0300 | [diff] [blame] | 1681 | if (r) |
| 1682 | goto err0; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1683 | dsi->vdds_dsi_enabled = true; |
Tomi Valkeinen | 2a89dc1 | 2010-07-30 12:39:34 +0300 | [diff] [blame] | 1684 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1685 | |
| 1686 | /* XXX PLL does not come out of reset without this... */ |
| 1687 | dispc_pck_free_enable(1); |
| 1688 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1689 | if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 0, 1) != 1) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1690 | DSSERR("PLL not coming out of reset.\n"); |
| 1691 | r = -ENODEV; |
Ville Syrjälä | 481dfa0 | 2010-04-22 22:50:04 +0200 | [diff] [blame] | 1692 | dispc_pck_free_enable(0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1693 | goto err1; |
| 1694 | } |
| 1695 | |
| 1696 | /* XXX ... but if left on, we get problems when planes do not |
| 1697 | * fill the whole display. No idea about this */ |
| 1698 | dispc_pck_free_enable(0); |
| 1699 | |
| 1700 | if (enable_hsclk && enable_hsdiv) |
| 1701 | pwstate = DSI_PLL_POWER_ON_ALL; |
| 1702 | else if (enable_hsclk) |
| 1703 | pwstate = DSI_PLL_POWER_ON_HSCLK; |
| 1704 | else if (enable_hsdiv) |
| 1705 | pwstate = DSI_PLL_POWER_ON_DIV; |
| 1706 | else |
| 1707 | pwstate = DSI_PLL_POWER_OFF; |
| 1708 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1709 | r = dsi_pll_power(dsidev, pwstate); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1710 | |
| 1711 | if (r) |
| 1712 | goto err1; |
| 1713 | |
| 1714 | DSSDBG("PLL init done\n"); |
| 1715 | |
| 1716 | return 0; |
| 1717 | err1: |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1718 | if (dsi->vdds_dsi_enabled) { |
| 1719 | regulator_disable(dsi->vdds_dsi_reg); |
| 1720 | dsi->vdds_dsi_enabled = false; |
Tomi Valkeinen | 2a89dc1 | 2010-07-30 12:39:34 +0300 | [diff] [blame] | 1721 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1722 | err0: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1723 | dsi_disable_scp_clk(dsidev); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1724 | dsi_enable_pll_clock(dsidev, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1725 | return r; |
| 1726 | } |
| 1727 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1728 | void dsi_pll_uninit(struct platform_device *dsidev, bool disconnect_lanes) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1729 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1730 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1731 | |
| 1732 | dsi->pll_locked = 0; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1733 | dsi_pll_power(dsidev, DSI_PLL_POWER_OFF); |
Tomi Valkeinen | 2a89dc1 | 2010-07-30 12:39:34 +0300 | [diff] [blame] | 1734 | if (disconnect_lanes) { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1735 | WARN_ON(!dsi->vdds_dsi_enabled); |
| 1736 | regulator_disable(dsi->vdds_dsi_reg); |
| 1737 | dsi->vdds_dsi_enabled = false; |
Tomi Valkeinen | 2a89dc1 | 2010-07-30 12:39:34 +0300 | [diff] [blame] | 1738 | } |
Tomi Valkeinen | 24c1ae4 | 2011-04-13 17:12:52 +0300 | [diff] [blame] | 1739 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1740 | dsi_disable_scp_clk(dsidev); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1741 | dsi_enable_pll_clock(dsidev, 0); |
Tomi Valkeinen | 24c1ae4 | 2011-04-13 17:12:52 +0300 | [diff] [blame] | 1742 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1743 | DSSDBG("PLL uninit done\n"); |
| 1744 | } |
| 1745 | |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 1746 | static void dsi_dump_dsidev_clocks(struct platform_device *dsidev, |
| 1747 | struct seq_file *s) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1748 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1749 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 1750 | struct dsi_clock_info *cinfo = &dsi->current_cinfo; |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 1751 | enum omap_dss_clk_source dispc_clk_src, dsi_clk_src; |
Tomi Valkeinen | 11ee960 | 2012-03-09 16:07:39 +0200 | [diff] [blame] | 1752 | int dsi_module = dsi->module_id; |
Archit Taneja | 067a57e | 2011-03-02 11:57:25 +0530 | [diff] [blame] | 1753 | |
| 1754 | dispc_clk_src = dss_get_dispc_clk_source(); |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 1755 | dsi_clk_src = dss_get_dsi_clk_source(dsi_module); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1756 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1757 | if (dsi_runtime_get(dsidev)) |
| 1758 | return; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1759 | |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 1760 | seq_printf(s, "- DSI%d PLL -\n", dsi_module + 1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1761 | |
Tomi Valkeinen | b6e695a | 2012-03-15 15:22:58 +0200 | [diff] [blame] | 1762 | seq_printf(s, "dsi pll clkin\t%lu\n", cinfo->clkin); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1763 | |
| 1764 | seq_printf(s, "Fint\t\t%-16luregn %u\n", cinfo->fint, cinfo->regn); |
| 1765 | |
| 1766 | seq_printf(s, "CLKIN4DDR\t%-16luregm %u\n", |
| 1767 | cinfo->clkin4ddr, cinfo->regm); |
| 1768 | |
Archit Taneja | 84309f1 | 2011-12-12 11:47:41 +0530 | [diff] [blame] | 1769 | seq_printf(s, "DSI_PLL_HSDIV_DISPC (%s)\t%-16luregm_dispc %u\t(%s)\n", |
| 1770 | dss_feat_get_clk_source_name(dsi_module == 0 ? |
| 1771 | OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC : |
| 1772 | OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC), |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1773 | cinfo->dsi_pll_hsdiv_dispc_clk, |
| 1774 | cinfo->regm_dispc, |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 1775 | dispc_clk_src == OMAP_DSS_CLK_SRC_FCK ? |
Tomi Valkeinen | 63cf28a | 2010-02-23 17:40:00 +0200 | [diff] [blame] | 1776 | "off" : "on"); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1777 | |
Archit Taneja | 84309f1 | 2011-12-12 11:47:41 +0530 | [diff] [blame] | 1778 | seq_printf(s, "DSI_PLL_HSDIV_DSI (%s)\t%-16luregm_dsi %u\t(%s)\n", |
| 1779 | dss_feat_get_clk_source_name(dsi_module == 0 ? |
| 1780 | OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI : |
| 1781 | OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI), |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 1782 | cinfo->dsi_pll_hsdiv_dsi_clk, |
| 1783 | cinfo->regm_dsi, |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 1784 | dsi_clk_src == OMAP_DSS_CLK_SRC_FCK ? |
Tomi Valkeinen | 63cf28a | 2010-02-23 17:40:00 +0200 | [diff] [blame] | 1785 | "off" : "on"); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1786 | |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 1787 | seq_printf(s, "- DSI%d -\n", dsi_module + 1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1788 | |
Archit Taneja | 067a57e | 2011-03-02 11:57:25 +0530 | [diff] [blame] | 1789 | seq_printf(s, "dsi fclk source = %s (%s)\n", |
| 1790 | dss_get_generic_clk_source_name(dsi_clk_src), |
| 1791 | dss_feat_get_clk_source_name(dsi_clk_src)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1792 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1793 | seq_printf(s, "DSI_FCLK\t%lu\n", dsi_fclk_rate(dsidev)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1794 | |
| 1795 | seq_printf(s, "DDR_CLK\t\t%lu\n", |
| 1796 | cinfo->clkin4ddr / 4); |
| 1797 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1798 | seq_printf(s, "TxByteClkHS\t%lu\n", dsi_get_txbyteclkhs(dsidev)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1799 | |
| 1800 | seq_printf(s, "LP_CLK\t\t%lu\n", cinfo->lp_clk); |
| 1801 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1802 | dsi_runtime_put(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1803 | } |
| 1804 | |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 1805 | void dsi_dump_clocks(struct seq_file *s) |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 1806 | { |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 1807 | struct platform_device *dsidev; |
| 1808 | int i; |
| 1809 | |
| 1810 | for (i = 0; i < MAX_NUM_DSI; i++) { |
| 1811 | dsidev = dsi_get_dsidev_from_id(i); |
| 1812 | if (dsidev) |
| 1813 | dsi_dump_dsidev_clocks(dsidev, s); |
| 1814 | } |
| 1815 | } |
| 1816 | |
| 1817 | #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS |
| 1818 | static void dsi_dump_dsidev_irqs(struct platform_device *dsidev, |
| 1819 | struct seq_file *s) |
| 1820 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1821 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 1822 | unsigned long flags; |
| 1823 | struct dsi_irq_stats stats; |
| 1824 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1825 | spin_lock_irqsave(&dsi->irq_stats_lock, flags); |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 1826 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1827 | stats = dsi->irq_stats; |
| 1828 | memset(&dsi->irq_stats, 0, sizeof(dsi->irq_stats)); |
| 1829 | dsi->irq_stats.last_reset = jiffies; |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 1830 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 1831 | spin_unlock_irqrestore(&dsi->irq_stats_lock, flags); |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 1832 | |
| 1833 | seq_printf(s, "period %u ms\n", |
| 1834 | jiffies_to_msecs(jiffies - stats.last_reset)); |
| 1835 | |
| 1836 | seq_printf(s, "irqs %d\n", stats.irq_count); |
| 1837 | #define PIS(x) \ |
| 1838 | seq_printf(s, "%-20s %10d\n", #x, stats.dsi_irqs[ffs(DSI_IRQ_##x)-1]); |
| 1839 | |
Tomi Valkeinen | 11ee960 | 2012-03-09 16:07:39 +0200 | [diff] [blame] | 1840 | seq_printf(s, "-- DSI%d interrupts --\n", dsi->module_id + 1); |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 1841 | PIS(VC0); |
| 1842 | PIS(VC1); |
| 1843 | PIS(VC2); |
| 1844 | PIS(VC3); |
| 1845 | PIS(WAKEUP); |
| 1846 | PIS(RESYNC); |
| 1847 | PIS(PLL_LOCK); |
| 1848 | PIS(PLL_UNLOCK); |
| 1849 | PIS(PLL_RECALL); |
| 1850 | PIS(COMPLEXIO_ERR); |
| 1851 | PIS(HS_TX_TIMEOUT); |
| 1852 | PIS(LP_RX_TIMEOUT); |
| 1853 | PIS(TE_TRIGGER); |
| 1854 | PIS(ACK_TRIGGER); |
| 1855 | PIS(SYNC_LOST); |
| 1856 | PIS(LDO_POWER_GOOD); |
| 1857 | PIS(TA_TIMEOUT); |
| 1858 | #undef PIS |
| 1859 | |
| 1860 | #define PIS(x) \ |
| 1861 | seq_printf(s, "%-20s %10d %10d %10d %10d\n", #x, \ |
| 1862 | stats.vc_irqs[0][ffs(DSI_VC_IRQ_##x)-1], \ |
| 1863 | stats.vc_irqs[1][ffs(DSI_VC_IRQ_##x)-1], \ |
| 1864 | stats.vc_irqs[2][ffs(DSI_VC_IRQ_##x)-1], \ |
| 1865 | stats.vc_irqs[3][ffs(DSI_VC_IRQ_##x)-1]); |
| 1866 | |
| 1867 | seq_printf(s, "-- VC interrupts --\n"); |
| 1868 | PIS(CS); |
| 1869 | PIS(ECC_CORR); |
| 1870 | PIS(PACKET_SENT); |
| 1871 | PIS(FIFO_TX_OVF); |
| 1872 | PIS(FIFO_RX_OVF); |
| 1873 | PIS(BTA); |
| 1874 | PIS(ECC_NO_CORR); |
| 1875 | PIS(FIFO_TX_UDF); |
| 1876 | PIS(PP_BUSY_CHANGE); |
| 1877 | #undef PIS |
| 1878 | |
| 1879 | #define PIS(x) \ |
| 1880 | seq_printf(s, "%-20s %10d\n", #x, \ |
| 1881 | stats.cio_irqs[ffs(DSI_CIO_IRQ_##x)-1]); |
| 1882 | |
| 1883 | seq_printf(s, "-- CIO interrupts --\n"); |
| 1884 | PIS(ERRSYNCESC1); |
| 1885 | PIS(ERRSYNCESC2); |
| 1886 | PIS(ERRSYNCESC3); |
| 1887 | PIS(ERRESC1); |
| 1888 | PIS(ERRESC2); |
| 1889 | PIS(ERRESC3); |
| 1890 | PIS(ERRCONTROL1); |
| 1891 | PIS(ERRCONTROL2); |
| 1892 | PIS(ERRCONTROL3); |
| 1893 | PIS(STATEULPS1); |
| 1894 | PIS(STATEULPS2); |
| 1895 | PIS(STATEULPS3); |
| 1896 | PIS(ERRCONTENTIONLP0_1); |
| 1897 | PIS(ERRCONTENTIONLP1_1); |
| 1898 | PIS(ERRCONTENTIONLP0_2); |
| 1899 | PIS(ERRCONTENTIONLP1_2); |
| 1900 | PIS(ERRCONTENTIONLP0_3); |
| 1901 | PIS(ERRCONTENTIONLP1_3); |
| 1902 | PIS(ULPSACTIVENOT_ALL0); |
| 1903 | PIS(ULPSACTIVENOT_ALL1); |
| 1904 | #undef PIS |
| 1905 | } |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 1906 | |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 1907 | static void dsi1_dump_irqs(struct seq_file *s) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1908 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1909 | struct platform_device *dsidev = dsi_get_dsidev_from_id(0); |
| 1910 | |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 1911 | dsi_dump_dsidev_irqs(dsidev, s); |
| 1912 | } |
| 1913 | |
| 1914 | static void dsi2_dump_irqs(struct seq_file *s) |
| 1915 | { |
| 1916 | struct platform_device *dsidev = dsi_get_dsidev_from_id(1); |
| 1917 | |
| 1918 | dsi_dump_dsidev_irqs(dsidev, s); |
| 1919 | } |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 1920 | #endif |
| 1921 | |
| 1922 | static void dsi_dump_dsidev_regs(struct platform_device *dsidev, |
| 1923 | struct seq_file *s) |
| 1924 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1925 | #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] | 1926 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1927 | if (dsi_runtime_get(dsidev)) |
| 1928 | return; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 1929 | dsi_enable_scp_clk(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 1930 | |
| 1931 | DUMPREG(DSI_REVISION); |
| 1932 | DUMPREG(DSI_SYSCONFIG); |
| 1933 | DUMPREG(DSI_SYSSTATUS); |
| 1934 | DUMPREG(DSI_IRQSTATUS); |
| 1935 | DUMPREG(DSI_IRQENABLE); |
| 1936 | DUMPREG(DSI_CTRL); |
| 1937 | DUMPREG(DSI_COMPLEXIO_CFG1); |
| 1938 | DUMPREG(DSI_COMPLEXIO_IRQ_STATUS); |
| 1939 | DUMPREG(DSI_COMPLEXIO_IRQ_ENABLE); |
| 1940 | DUMPREG(DSI_CLK_CTRL); |
| 1941 | DUMPREG(DSI_TIMING1); |
| 1942 | DUMPREG(DSI_TIMING2); |
| 1943 | DUMPREG(DSI_VM_TIMING1); |
| 1944 | DUMPREG(DSI_VM_TIMING2); |
| 1945 | DUMPREG(DSI_VM_TIMING3); |
| 1946 | DUMPREG(DSI_CLK_TIMING); |
| 1947 | DUMPREG(DSI_TX_FIFO_VC_SIZE); |
| 1948 | DUMPREG(DSI_RX_FIFO_VC_SIZE); |
| 1949 | DUMPREG(DSI_COMPLEXIO_CFG2); |
| 1950 | DUMPREG(DSI_RX_FIFO_VC_FULLNESS); |
| 1951 | DUMPREG(DSI_VM_TIMING4); |
| 1952 | DUMPREG(DSI_TX_FIFO_VC_EMPTINESS); |
| 1953 | DUMPREG(DSI_VM_TIMING5); |
| 1954 | DUMPREG(DSI_VM_TIMING6); |
| 1955 | DUMPREG(DSI_VM_TIMING7); |
| 1956 | DUMPREG(DSI_STOPCLK_TIMING); |
| 1957 | |
| 1958 | DUMPREG(DSI_VC_CTRL(0)); |
| 1959 | DUMPREG(DSI_VC_TE(0)); |
| 1960 | DUMPREG(DSI_VC_LONG_PACKET_HEADER(0)); |
| 1961 | DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(0)); |
| 1962 | DUMPREG(DSI_VC_SHORT_PACKET_HEADER(0)); |
| 1963 | DUMPREG(DSI_VC_IRQSTATUS(0)); |
| 1964 | DUMPREG(DSI_VC_IRQENABLE(0)); |
| 1965 | |
| 1966 | DUMPREG(DSI_VC_CTRL(1)); |
| 1967 | DUMPREG(DSI_VC_TE(1)); |
| 1968 | DUMPREG(DSI_VC_LONG_PACKET_HEADER(1)); |
| 1969 | DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(1)); |
| 1970 | DUMPREG(DSI_VC_SHORT_PACKET_HEADER(1)); |
| 1971 | DUMPREG(DSI_VC_IRQSTATUS(1)); |
| 1972 | DUMPREG(DSI_VC_IRQENABLE(1)); |
| 1973 | |
| 1974 | DUMPREG(DSI_VC_CTRL(2)); |
| 1975 | DUMPREG(DSI_VC_TE(2)); |
| 1976 | DUMPREG(DSI_VC_LONG_PACKET_HEADER(2)); |
| 1977 | DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(2)); |
| 1978 | DUMPREG(DSI_VC_SHORT_PACKET_HEADER(2)); |
| 1979 | DUMPREG(DSI_VC_IRQSTATUS(2)); |
| 1980 | DUMPREG(DSI_VC_IRQENABLE(2)); |
| 1981 | |
| 1982 | DUMPREG(DSI_VC_CTRL(3)); |
| 1983 | DUMPREG(DSI_VC_TE(3)); |
| 1984 | DUMPREG(DSI_VC_LONG_PACKET_HEADER(3)); |
| 1985 | DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(3)); |
| 1986 | DUMPREG(DSI_VC_SHORT_PACKET_HEADER(3)); |
| 1987 | DUMPREG(DSI_VC_IRQSTATUS(3)); |
| 1988 | DUMPREG(DSI_VC_IRQENABLE(3)); |
| 1989 | |
| 1990 | DUMPREG(DSI_DSIPHY_CFG0); |
| 1991 | DUMPREG(DSI_DSIPHY_CFG1); |
| 1992 | DUMPREG(DSI_DSIPHY_CFG2); |
| 1993 | DUMPREG(DSI_DSIPHY_CFG5); |
| 1994 | |
| 1995 | DUMPREG(DSI_PLL_CONTROL); |
| 1996 | DUMPREG(DSI_PLL_STATUS); |
| 1997 | DUMPREG(DSI_PLL_GO); |
| 1998 | DUMPREG(DSI_PLL_CONFIGURATION1); |
| 1999 | DUMPREG(DSI_PLL_CONFIGURATION2); |
| 2000 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2001 | dsi_disable_scp_clk(dsidev); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 2002 | dsi_runtime_put(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2003 | #undef DUMPREG |
| 2004 | } |
| 2005 | |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 2006 | static void dsi1_dump_regs(struct seq_file *s) |
| 2007 | { |
| 2008 | struct platform_device *dsidev = dsi_get_dsidev_from_id(0); |
| 2009 | |
| 2010 | dsi_dump_dsidev_regs(dsidev, s); |
| 2011 | } |
| 2012 | |
| 2013 | static void dsi2_dump_regs(struct seq_file *s) |
| 2014 | { |
| 2015 | struct platform_device *dsidev = dsi_get_dsidev_from_id(1); |
| 2016 | |
| 2017 | dsi_dump_dsidev_regs(dsidev, s); |
| 2018 | } |
| 2019 | |
Tomi Valkeinen | cc5c185 | 2010-10-06 15:18:13 +0300 | [diff] [blame] | 2020 | enum dsi_cio_power_state { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2021 | DSI_COMPLEXIO_POWER_OFF = 0x0, |
| 2022 | DSI_COMPLEXIO_POWER_ON = 0x1, |
| 2023 | DSI_COMPLEXIO_POWER_ULPS = 0x2, |
| 2024 | }; |
| 2025 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2026 | static int dsi_cio_power(struct platform_device *dsidev, |
| 2027 | enum dsi_cio_power_state state) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2028 | { |
| 2029 | int t = 0; |
| 2030 | |
| 2031 | /* PWR_CMD */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2032 | REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG1, state, 28, 27); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2033 | |
| 2034 | /* PWR_STATUS */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2035 | while (FLD_GET(dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1), |
| 2036 | 26, 25) != state) { |
Tomi Valkeinen | 24be78b | 2010-01-07 14:19:48 +0200 | [diff] [blame] | 2037 | if (++t > 1000) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2038 | DSSERR("failed to set complexio power state to " |
| 2039 | "%d\n", state); |
| 2040 | return -ENODEV; |
| 2041 | } |
Tomi Valkeinen | 24be78b | 2010-01-07 14:19:48 +0200 | [diff] [blame] | 2042 | udelay(1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2043 | } |
| 2044 | |
| 2045 | return 0; |
| 2046 | } |
| 2047 | |
Archit Taneja | 0c65622 | 2011-05-16 15:17:09 +0530 | [diff] [blame] | 2048 | static unsigned dsi_get_line_buf_size(struct platform_device *dsidev) |
| 2049 | { |
| 2050 | int val; |
| 2051 | |
| 2052 | /* line buffer on OMAP3 is 1024 x 24bits */ |
| 2053 | /* XXX: for some reason using full buffer size causes |
| 2054 | * considerable TX slowdown with update sizes that fill the |
| 2055 | * whole buffer */ |
| 2056 | if (!dss_has_feature(FEAT_DSI_GNQ)) |
| 2057 | return 1023 * 3; |
| 2058 | |
| 2059 | val = REG_GET(dsidev, DSI_GNQ, 14, 12); /* VP1_LINE_BUFFER_SIZE */ |
| 2060 | |
| 2061 | switch (val) { |
| 2062 | case 1: |
| 2063 | return 512 * 3; /* 512x24 bits */ |
| 2064 | case 2: |
| 2065 | return 682 * 3; /* 682x24 bits */ |
| 2066 | case 3: |
| 2067 | return 853 * 3; /* 853x24 bits */ |
| 2068 | case 4: |
| 2069 | return 1024 * 3; /* 1024x24 bits */ |
| 2070 | case 5: |
| 2071 | return 1194 * 3; /* 1194x24 bits */ |
| 2072 | case 6: |
| 2073 | return 1365 * 3; /* 1365x24 bits */ |
Tomi Valkeinen | 2ac80fb | 2012-08-22 16:00:47 +0300 | [diff] [blame] | 2074 | case 7: |
| 2075 | return 1920 * 3; /* 1920x24 bits */ |
Archit Taneja | 0c65622 | 2011-05-16 15:17:09 +0530 | [diff] [blame] | 2076 | default: |
| 2077 | BUG(); |
Tomi Valkeinen | c6eee96 | 2012-05-18 11:47:02 +0300 | [diff] [blame] | 2078 | return 0; |
Archit Taneja | 0c65622 | 2011-05-16 15:17:09 +0530 | [diff] [blame] | 2079 | } |
| 2080 | } |
| 2081 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 2082 | static int dsi_set_lane_config(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2083 | { |
Tomi Valkeinen | 4836839 | 2011-10-13 11:22:39 +0300 | [diff] [blame] | 2084 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 2085 | static const u8 offsets[] = { 0, 4, 8, 12, 16 }; |
| 2086 | static const enum dsi_lane_function functions[] = { |
| 2087 | DSI_LANE_CLK, |
| 2088 | DSI_LANE_DATA1, |
| 2089 | DSI_LANE_DATA2, |
| 2090 | DSI_LANE_DATA3, |
| 2091 | DSI_LANE_DATA4, |
| 2092 | }; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2093 | u32 r; |
Tomi Valkeinen | 4836839 | 2011-10-13 11:22:39 +0300 | [diff] [blame] | 2094 | int i; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2095 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2096 | r = dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1); |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 2097 | |
Tomi Valkeinen | 4836839 | 2011-10-13 11:22:39 +0300 | [diff] [blame] | 2098 | for (i = 0; i < dsi->num_lanes_used; ++i) { |
| 2099 | unsigned offset = offsets[i]; |
| 2100 | unsigned polarity, lane_number; |
| 2101 | unsigned t; |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 2102 | |
Tomi Valkeinen | 4836839 | 2011-10-13 11:22:39 +0300 | [diff] [blame] | 2103 | for (t = 0; t < dsi->num_lanes_supported; ++t) |
| 2104 | if (dsi->lanes[t].function == functions[i]) |
| 2105 | break; |
| 2106 | |
| 2107 | if (t == dsi->num_lanes_supported) |
| 2108 | return -EINVAL; |
| 2109 | |
| 2110 | lane_number = t; |
| 2111 | polarity = dsi->lanes[t].polarity; |
| 2112 | |
| 2113 | r = FLD_MOD(r, lane_number + 1, offset + 2, offset); |
| 2114 | r = FLD_MOD(r, polarity, offset + 3, offset + 3); |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 2115 | } |
Tomi Valkeinen | 4836839 | 2011-10-13 11:22:39 +0300 | [diff] [blame] | 2116 | |
| 2117 | /* clear the unused lanes */ |
| 2118 | for (; i < dsi->num_lanes_supported; ++i) { |
| 2119 | unsigned offset = offsets[i]; |
| 2120 | |
| 2121 | r = FLD_MOD(r, 0, offset + 2, offset); |
| 2122 | r = FLD_MOD(r, 0, offset + 3, offset + 3); |
| 2123 | } |
| 2124 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2125 | dsi_write_reg(dsidev, DSI_COMPLEXIO_CFG1, r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2126 | |
Tomi Valkeinen | 4836839 | 2011-10-13 11:22:39 +0300 | [diff] [blame] | 2127 | return 0; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2128 | } |
| 2129 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2130 | static inline unsigned ns2ddr(struct platform_device *dsidev, unsigned ns) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2131 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2132 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 2133 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2134 | /* convert time in ns to ddr ticks, rounding up */ |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2135 | unsigned long ddr_clk = dsi->current_cinfo.clkin4ddr / 4; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2136 | return (ns * (ddr_clk / 1000 / 1000) + 999) / 1000; |
| 2137 | } |
| 2138 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2139 | static inline unsigned ddr2ns(struct platform_device *dsidev, unsigned ddr) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2140 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2141 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 2142 | |
| 2143 | unsigned long ddr_clk = dsi->current_cinfo.clkin4ddr / 4; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2144 | return ddr * 1000 * 1000 / (ddr_clk / 1000); |
| 2145 | } |
| 2146 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2147 | static void dsi_cio_timings(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2148 | { |
| 2149 | u32 r; |
| 2150 | u32 ths_prepare, ths_prepare_ths_zero, ths_trail, ths_exit; |
| 2151 | u32 tlpx_half, tclk_trail, tclk_zero; |
| 2152 | u32 tclk_prepare; |
| 2153 | |
| 2154 | /* calculate timings */ |
| 2155 | |
| 2156 | /* 1 * DDR_CLK = 2 * UI */ |
| 2157 | |
| 2158 | /* min 40ns + 4*UI max 85ns + 6*UI */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2159 | ths_prepare = ns2ddr(dsidev, 70) + 2; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2160 | |
| 2161 | /* min 145ns + 10*UI */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2162 | ths_prepare_ths_zero = ns2ddr(dsidev, 175) + 2; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2163 | |
| 2164 | /* min max(8*UI, 60ns+4*UI) */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2165 | ths_trail = ns2ddr(dsidev, 60) + 5; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2166 | |
| 2167 | /* min 100ns */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2168 | ths_exit = ns2ddr(dsidev, 145); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2169 | |
| 2170 | /* tlpx min 50n */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2171 | tlpx_half = ns2ddr(dsidev, 25); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2172 | |
| 2173 | /* min 60ns */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2174 | tclk_trail = ns2ddr(dsidev, 60) + 2; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2175 | |
| 2176 | /* min 38ns, max 95ns */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2177 | tclk_prepare = ns2ddr(dsidev, 65); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2178 | |
| 2179 | /* min tclk-prepare + tclk-zero = 300ns */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2180 | tclk_zero = ns2ddr(dsidev, 260); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2181 | |
| 2182 | DSSDBG("ths_prepare %u (%uns), ths_prepare_ths_zero %u (%uns)\n", |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2183 | ths_prepare, ddr2ns(dsidev, ths_prepare), |
| 2184 | ths_prepare_ths_zero, ddr2ns(dsidev, ths_prepare_ths_zero)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2185 | DSSDBG("ths_trail %u (%uns), ths_exit %u (%uns)\n", |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2186 | ths_trail, ddr2ns(dsidev, ths_trail), |
| 2187 | ths_exit, ddr2ns(dsidev, ths_exit)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2188 | |
| 2189 | DSSDBG("tlpx_half %u (%uns), tclk_trail %u (%uns), " |
| 2190 | "tclk_zero %u (%uns)\n", |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2191 | tlpx_half, ddr2ns(dsidev, tlpx_half), |
| 2192 | tclk_trail, ddr2ns(dsidev, tclk_trail), |
| 2193 | tclk_zero, ddr2ns(dsidev, tclk_zero)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2194 | DSSDBG("tclk_prepare %u (%uns)\n", |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2195 | tclk_prepare, ddr2ns(dsidev, tclk_prepare)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2196 | |
| 2197 | /* program timings */ |
| 2198 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2199 | r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2200 | r = FLD_MOD(r, ths_prepare, 31, 24); |
| 2201 | r = FLD_MOD(r, ths_prepare_ths_zero, 23, 16); |
| 2202 | r = FLD_MOD(r, ths_trail, 15, 8); |
| 2203 | r = FLD_MOD(r, ths_exit, 7, 0); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2204 | dsi_write_reg(dsidev, DSI_DSIPHY_CFG0, r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2205 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2206 | r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1); |
Tomi Valkeinen | e84dc1c | 2012-09-24 09:34:52 +0300 | [diff] [blame] | 2207 | r = FLD_MOD(r, tlpx_half, 20, 16); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2208 | r = FLD_MOD(r, tclk_trail, 15, 8); |
| 2209 | r = FLD_MOD(r, tclk_zero, 7, 0); |
Tomi Valkeinen | 77ccbfb | 2012-09-24 15:15:57 +0300 | [diff] [blame] | 2210 | |
| 2211 | if (dss_has_feature(FEAT_DSI_PHY_DCC)) { |
| 2212 | r = FLD_MOD(r, 0, 21, 21); /* DCCEN = disable */ |
| 2213 | r = FLD_MOD(r, 1, 22, 22); /* CLKINP_DIVBY2EN = enable */ |
| 2214 | r = FLD_MOD(r, 1, 23, 23); /* CLKINP_SEL = enable */ |
| 2215 | } |
| 2216 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2217 | dsi_write_reg(dsidev, DSI_DSIPHY_CFG1, r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2218 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2219 | r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG2); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2220 | r = FLD_MOD(r, tclk_prepare, 7, 0); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2221 | dsi_write_reg(dsidev, DSI_DSIPHY_CFG2, r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2222 | } |
| 2223 | |
Tomi Valkeinen | 9b4362f | 2011-10-13 16:06:43 +0300 | [diff] [blame] | 2224 | /* 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] | 2225 | static void dsi_cio_enable_lane_override(struct platform_device *dsidev, |
Tomi Valkeinen | 9b4362f | 2011-10-13 16:06:43 +0300 | [diff] [blame] | 2226 | unsigned mask_p, unsigned mask_n) |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2227 | { |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 2228 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 9b4362f | 2011-10-13 16:06:43 +0300 | [diff] [blame] | 2229 | int i; |
| 2230 | u32 l; |
Tomi Valkeinen | d982085 | 2011-10-12 15:05:59 +0300 | [diff] [blame] | 2231 | u8 lptxscp_start = dsi->num_lanes_supported == 3 ? 22 : 26; |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2232 | |
Tomi Valkeinen | 9b4362f | 2011-10-13 16:06:43 +0300 | [diff] [blame] | 2233 | l = 0; |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2234 | |
Tomi Valkeinen | 9b4362f | 2011-10-13 16:06:43 +0300 | [diff] [blame] | 2235 | for (i = 0; i < dsi->num_lanes_supported; ++i) { |
| 2236 | unsigned p = dsi->lanes[i].polarity; |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2237 | |
Tomi Valkeinen | 9b4362f | 2011-10-13 16:06:43 +0300 | [diff] [blame] | 2238 | if (mask_p & (1 << i)) |
| 2239 | l |= 1 << (i * 2 + (p ? 0 : 1)); |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2240 | |
Tomi Valkeinen | 9b4362f | 2011-10-13 16:06:43 +0300 | [diff] [blame] | 2241 | if (mask_n & (1 << i)) |
| 2242 | l |= 1 << (i * 2 + (p ? 1 : 0)); |
| 2243 | } |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2244 | |
| 2245 | /* |
| 2246 | * Bits in REGLPTXSCPDAT4TO0DXDY: |
| 2247 | * 17: DY0 18: DX0 |
| 2248 | * 19: DY1 20: DX1 |
| 2249 | * 21: DY2 22: DX2 |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 2250 | * 23: DY3 24: DX3 |
| 2251 | * 25: DY4 26: DX4 |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2252 | */ |
| 2253 | |
| 2254 | /* Set the lane override configuration */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2255 | |
| 2256 | /* REGLPTXSCPDAT4TO0DXDY */ |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 2257 | REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, l, lptxscp_start, 17); |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2258 | |
| 2259 | /* Enable lane override */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2260 | |
| 2261 | /* ENLPTXSCPDAT */ |
| 2262 | REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 1, 27, 27); |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2263 | } |
| 2264 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2265 | static void dsi_cio_disable_lane_override(struct platform_device *dsidev) |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2266 | { |
| 2267 | /* Disable lane override */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2268 | REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 0, 27, 27); /* ENLPTXSCPDAT */ |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2269 | /* Reset the lane override configuration */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2270 | /* REGLPTXSCPDAT4TO0DXDY */ |
| 2271 | REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 0, 22, 17); |
Tomi Valkeinen | 0a0ee46 | 2010-07-27 11:11:48 +0300 | [diff] [blame] | 2272 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2273 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 2274 | 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] | 2275 | { |
Tomi Valkeinen | 8dc0766 | 2011-10-13 15:26:50 +0300 | [diff] [blame] | 2276 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 2277 | int t, i; |
| 2278 | bool in_use[DSI_MAX_NR_LANES]; |
| 2279 | static const u8 offsets_old[] = { 28, 27, 26 }; |
| 2280 | static const u8 offsets_new[] = { 24, 25, 26, 27, 28 }; |
| 2281 | const u8 *offsets; |
Tomi Valkeinen | 03329ac | 2010-10-07 13:59:22 +0300 | [diff] [blame] | 2282 | |
Tomi Valkeinen | 8dc0766 | 2011-10-13 15:26:50 +0300 | [diff] [blame] | 2283 | if (dss_has_feature(FEAT_DSI_REVERSE_TXCLKESC)) |
| 2284 | offsets = offsets_old; |
| 2285 | else |
| 2286 | offsets = offsets_new; |
Tomi Valkeinen | 03329ac | 2010-10-07 13:59:22 +0300 | [diff] [blame] | 2287 | |
Tomi Valkeinen | 8dc0766 | 2011-10-13 15:26:50 +0300 | [diff] [blame] | 2288 | for (i = 0; i < dsi->num_lanes_supported; ++i) |
| 2289 | in_use[i] = dsi->lanes[i].function != DSI_LANE_UNUSED; |
Tomi Valkeinen | 03329ac | 2010-10-07 13:59:22 +0300 | [diff] [blame] | 2290 | |
| 2291 | t = 100000; |
| 2292 | while (true) { |
| 2293 | u32 l; |
Tomi Valkeinen | 03329ac | 2010-10-07 13:59:22 +0300 | [diff] [blame] | 2294 | int ok; |
| 2295 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2296 | l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5); |
Tomi Valkeinen | 03329ac | 2010-10-07 13:59:22 +0300 | [diff] [blame] | 2297 | |
| 2298 | ok = 0; |
Tomi Valkeinen | 8dc0766 | 2011-10-13 15:26:50 +0300 | [diff] [blame] | 2299 | for (i = 0; i < dsi->num_lanes_supported; ++i) { |
| 2300 | if (!in_use[i] || (l & (1 << offsets[i]))) |
Tomi Valkeinen | 03329ac | 2010-10-07 13:59:22 +0300 | [diff] [blame] | 2301 | ok++; |
| 2302 | } |
| 2303 | |
Tomi Valkeinen | 8dc0766 | 2011-10-13 15:26:50 +0300 | [diff] [blame] | 2304 | if (ok == dsi->num_lanes_supported) |
Tomi Valkeinen | 03329ac | 2010-10-07 13:59:22 +0300 | [diff] [blame] | 2305 | break; |
| 2306 | |
| 2307 | if (--t == 0) { |
Tomi Valkeinen | 8dc0766 | 2011-10-13 15:26:50 +0300 | [diff] [blame] | 2308 | for (i = 0; i < dsi->num_lanes_supported; ++i) { |
| 2309 | if (!in_use[i] || (l & (1 << offsets[i]))) |
Tomi Valkeinen | 03329ac | 2010-10-07 13:59:22 +0300 | [diff] [blame] | 2310 | continue; |
| 2311 | |
| 2312 | DSSERR("CIO TXCLKESC%d domain not coming " \ |
| 2313 | "out of reset\n", i); |
| 2314 | } |
| 2315 | return -EIO; |
| 2316 | } |
| 2317 | } |
| 2318 | |
| 2319 | return 0; |
| 2320 | } |
| 2321 | |
Tomi Valkeinen | 85f17e8 | 2011-10-13 15:12:23 +0300 | [diff] [blame] | 2322 | /* return bitmask of enabled lanes, lane0 being the lsb */ |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 2323 | static unsigned dsi_get_lane_mask(struct platform_device *dsidev) |
Tomi Valkeinen | 5bc416c | 2011-06-15 15:21:12 +0300 | [diff] [blame] | 2324 | { |
Tomi Valkeinen | 85f17e8 | 2011-10-13 15:12:23 +0300 | [diff] [blame] | 2325 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 2326 | unsigned mask = 0; |
| 2327 | int i; |
Tomi Valkeinen | 5bc416c | 2011-06-15 15:21:12 +0300 | [diff] [blame] | 2328 | |
Tomi Valkeinen | 85f17e8 | 2011-10-13 15:12:23 +0300 | [diff] [blame] | 2329 | for (i = 0; i < dsi->num_lanes_supported; ++i) { |
| 2330 | if (dsi->lanes[i].function != DSI_LANE_UNUSED) |
| 2331 | mask |= 1 << i; |
| 2332 | } |
Tomi Valkeinen | 5bc416c | 2011-06-15 15:21:12 +0300 | [diff] [blame] | 2333 | |
Tomi Valkeinen | 85f17e8 | 2011-10-13 15:12:23 +0300 | [diff] [blame] | 2334 | return mask; |
Tomi Valkeinen | 5bc416c | 2011-06-15 15:21:12 +0300 | [diff] [blame] | 2335 | } |
| 2336 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 2337 | static int dsi_cio_init(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2338 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2339 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 65c62bb | 2011-04-15 11:58:41 +0300 | [diff] [blame] | 2340 | int r; |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 2341 | u32 l; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2342 | |
Chandrabhanu Mahapatra | 702d267 | 2012-09-24 17:12:58 +0530 | [diff] [blame] | 2343 | DSSDBG("DSI CIO init starts"); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2344 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 2345 | 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] | 2346 | if (r) |
| 2347 | return r; |
Tomi Valkeinen | d1f5857 | 2010-07-30 11:57:57 +0300 | [diff] [blame] | 2348 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2349 | dsi_enable_scp_clk(dsidev); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 2350 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2351 | /* A dummy read using the SCP interface to any DSIPHY register is |
| 2352 | * required after DSIPHY reset to complete the reset of the DSI complex |
| 2353 | * I/O. */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2354 | dsi_read_reg(dsidev, DSI_DSIPHY_CFG5); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2355 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2356 | if (wait_for_bit_change(dsidev, DSI_DSIPHY_CFG5, 30, 1) != 1) { |
Tomi Valkeinen | 65c62bb | 2011-04-15 11:58:41 +0300 | [diff] [blame] | 2357 | DSSERR("CIO SCP Clock domain not coming out of reset.\n"); |
| 2358 | r = -EIO; |
| 2359 | goto err_scp_clk_dom; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2360 | } |
| 2361 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 2362 | r = dsi_set_lane_config(dsidev); |
Tomi Valkeinen | 4836839 | 2011-10-13 11:22:39 +0300 | [diff] [blame] | 2363 | if (r) |
| 2364 | goto err_scp_clk_dom; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2365 | |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 2366 | /* set TX STOP MODE timer to maximum for this operation */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2367 | l = dsi_read_reg(dsidev, DSI_TIMING1); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 2368 | l = FLD_MOD(l, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */ |
| 2369 | l = FLD_MOD(l, 1, 14, 14); /* STOP_STATE_X16_IO */ |
| 2370 | l = FLD_MOD(l, 1, 13, 13); /* STOP_STATE_X4_IO */ |
| 2371 | l = FLD_MOD(l, 0x1fff, 12, 0); /* STOP_STATE_COUNTER_IO */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2372 | dsi_write_reg(dsidev, DSI_TIMING1, l); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 2373 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2374 | if (dsi->ulps_enabled) { |
Tomi Valkeinen | 9b4362f | 2011-10-13 16:06:43 +0300 | [diff] [blame] | 2375 | unsigned mask_p; |
| 2376 | int i; |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 2377 | |
Tomi Valkeinen | 65c62bb | 2011-04-15 11:58:41 +0300 | [diff] [blame] | 2378 | DSSDBG("manual ulps exit\n"); |
| 2379 | |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 2380 | /* ULPS is exited by Mark-1 state for 1ms, followed by |
| 2381 | * stop state. DSS HW cannot do this via the normal |
| 2382 | * ULPS exit sequence, as after reset the DSS HW thinks |
| 2383 | * that we are not in ULPS mode, and refuses to send the |
| 2384 | * sequence. So we need to send the ULPS exit sequence |
Tomi Valkeinen | 9b4362f | 2011-10-13 16:06:43 +0300 | [diff] [blame] | 2385 | * manually by setting positive lines high and negative lines |
| 2386 | * low for 1ms. |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 2387 | */ |
| 2388 | |
Tomi Valkeinen | 9b4362f | 2011-10-13 16:06:43 +0300 | [diff] [blame] | 2389 | mask_p = 0; |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 2390 | |
Tomi Valkeinen | 9b4362f | 2011-10-13 16:06:43 +0300 | [diff] [blame] | 2391 | for (i = 0; i < dsi->num_lanes_supported; ++i) { |
| 2392 | if (dsi->lanes[i].function == DSI_LANE_UNUSED) |
| 2393 | continue; |
| 2394 | mask_p |= 1 << i; |
| 2395 | } |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 2396 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 2397 | dsi_cio_enable_lane_override(dsidev, mask_p, 0); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 2398 | } |
| 2399 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2400 | r = dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_ON); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2401 | if (r) |
Tomi Valkeinen | 65c62bb | 2011-04-15 11:58:41 +0300 | [diff] [blame] | 2402 | goto err_cio_pwr; |
| 2403 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2404 | if (wait_for_bit_change(dsidev, DSI_COMPLEXIO_CFG1, 29, 1) != 1) { |
Tomi Valkeinen | 65c62bb | 2011-04-15 11:58:41 +0300 | [diff] [blame] | 2405 | DSSERR("CIO PWR clock domain not coming out of reset.\n"); |
| 2406 | r = -ENODEV; |
| 2407 | goto err_cio_pwr_dom; |
| 2408 | } |
| 2409 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2410 | dsi_if_enable(dsidev, true); |
| 2411 | dsi_if_enable(dsidev, false); |
| 2412 | 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] | 2413 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 2414 | r = dsi_cio_wait_tx_clk_esc_reset(dsidev); |
Tomi Valkeinen | 03329ac | 2010-10-07 13:59:22 +0300 | [diff] [blame] | 2415 | if (r) |
| 2416 | goto err_tx_clk_esc_rst; |
| 2417 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2418 | if (dsi->ulps_enabled) { |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 2419 | /* Keep Mark-1 state for 1ms (as per DSI spec) */ |
| 2420 | ktime_t wait = ns_to_ktime(1000 * 1000); |
| 2421 | set_current_state(TASK_UNINTERRUPTIBLE); |
| 2422 | schedule_hrtimeout(&wait, HRTIMER_MODE_REL); |
| 2423 | |
| 2424 | /* Disable the override. The lanes should be set to Mark-11 |
| 2425 | * state by the HW */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2426 | dsi_cio_disable_lane_override(dsidev); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 2427 | } |
| 2428 | |
| 2429 | /* FORCE_TX_STOP_MODE_IO */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2430 | REG_FLD_MOD(dsidev, DSI_TIMING1, 0, 15, 15); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 2431 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2432 | dsi_cio_timings(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2433 | |
Archit Taneja | dca2b15 | 2012-08-16 18:02:00 +0530 | [diff] [blame] | 2434 | if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) { |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 2435 | /* DDR_CLK_ALWAYS_ON */ |
| 2436 | REG_FLD_MOD(dsidev, DSI_CLK_CTRL, |
Archit Taneja | 0b3ffe3 | 2012-08-13 22:13:39 +0530 | [diff] [blame] | 2437 | dsi->vm_timings.ddr_clk_always_on, 13, 13); |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 2438 | } |
| 2439 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2440 | dsi->ulps_enabled = false; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2441 | |
| 2442 | DSSDBG("CIO init done\n"); |
Tomi Valkeinen | 65c62bb | 2011-04-15 11:58:41 +0300 | [diff] [blame] | 2443 | |
| 2444 | return 0; |
| 2445 | |
Tomi Valkeinen | 03329ac | 2010-10-07 13:59:22 +0300 | [diff] [blame] | 2446 | err_tx_clk_esc_rst: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2447 | 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] | 2448 | err_cio_pwr_dom: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2449 | dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF); |
Tomi Valkeinen | 65c62bb | 2011-04-15 11:58:41 +0300 | [diff] [blame] | 2450 | err_cio_pwr: |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2451 | if (dsi->ulps_enabled) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2452 | dsi_cio_disable_lane_override(dsidev); |
Tomi Valkeinen | 65c62bb | 2011-04-15 11:58:41 +0300 | [diff] [blame] | 2453 | err_scp_clk_dom: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2454 | dsi_disable_scp_clk(dsidev); |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 2455 | dss_dsi_disable_pads(dsi->module_id, dsi_get_lane_mask(dsidev)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2456 | return r; |
| 2457 | } |
| 2458 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 2459 | static void dsi_cio_uninit(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2460 | { |
Tomi Valkeinen | 11ee960 | 2012-03-09 16:07:39 +0200 | [diff] [blame] | 2461 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2462 | |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 2463 | /* DDR_CLK_ALWAYS_ON */ |
| 2464 | REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 13, 13); |
| 2465 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2466 | dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF); |
| 2467 | dsi_disable_scp_clk(dsidev); |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 2468 | dss_dsi_disable_pads(dsi->module_id, dsi_get_lane_mask(dsidev)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2469 | } |
| 2470 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2471 | static void dsi_config_tx_fifo(struct platform_device *dsidev, |
| 2472 | enum fifo_size size1, enum fifo_size size2, |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2473 | enum fifo_size size3, enum fifo_size size4) |
| 2474 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2475 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2476 | u32 r = 0; |
| 2477 | int add = 0; |
| 2478 | int i; |
| 2479 | |
Tomi Valkeinen | 558c73e | 2013-09-25 14:40:06 +0300 | [diff] [blame] | 2480 | dsi->vc[0].tx_fifo_size = size1; |
| 2481 | dsi->vc[1].tx_fifo_size = size2; |
| 2482 | dsi->vc[2].tx_fifo_size = size3; |
| 2483 | dsi->vc[3].tx_fifo_size = size4; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2484 | |
| 2485 | for (i = 0; i < 4; i++) { |
| 2486 | u8 v; |
Tomi Valkeinen | 558c73e | 2013-09-25 14:40:06 +0300 | [diff] [blame] | 2487 | int size = dsi->vc[i].tx_fifo_size; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2488 | |
| 2489 | if (add + size > 4) { |
| 2490 | DSSERR("Illegal FIFO configuration\n"); |
| 2491 | BUG(); |
Tomi Valkeinen | c6eee96 | 2012-05-18 11:47:02 +0300 | [diff] [blame] | 2492 | return; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2493 | } |
| 2494 | |
| 2495 | v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4); |
| 2496 | r |= v << (8 * i); |
| 2497 | /*DSSDBG("TX FIFO vc %d: size %d, add %d\n", i, size, add); */ |
| 2498 | add += size; |
| 2499 | } |
| 2500 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2501 | dsi_write_reg(dsidev, DSI_TX_FIFO_VC_SIZE, r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2502 | } |
| 2503 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2504 | static void dsi_config_rx_fifo(struct platform_device *dsidev, |
| 2505 | enum fifo_size size1, enum fifo_size size2, |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2506 | enum fifo_size size3, enum fifo_size size4) |
| 2507 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2508 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2509 | u32 r = 0; |
| 2510 | int add = 0; |
| 2511 | int i; |
| 2512 | |
Tomi Valkeinen | 558c73e | 2013-09-25 14:40:06 +0300 | [diff] [blame] | 2513 | dsi->vc[0].rx_fifo_size = size1; |
| 2514 | dsi->vc[1].rx_fifo_size = size2; |
| 2515 | dsi->vc[2].rx_fifo_size = size3; |
| 2516 | dsi->vc[3].rx_fifo_size = size4; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2517 | |
| 2518 | for (i = 0; i < 4; i++) { |
| 2519 | u8 v; |
Tomi Valkeinen | 558c73e | 2013-09-25 14:40:06 +0300 | [diff] [blame] | 2520 | int size = dsi->vc[i].rx_fifo_size; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2521 | |
| 2522 | if (add + size > 4) { |
| 2523 | DSSERR("Illegal FIFO configuration\n"); |
| 2524 | BUG(); |
Tomi Valkeinen | c6eee96 | 2012-05-18 11:47:02 +0300 | [diff] [blame] | 2525 | return; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2526 | } |
| 2527 | |
| 2528 | v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4); |
| 2529 | r |= v << (8 * i); |
| 2530 | /*DSSDBG("RX FIFO vc %d: size %d, add %d\n", i, size, add); */ |
| 2531 | add += size; |
| 2532 | } |
| 2533 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2534 | dsi_write_reg(dsidev, DSI_RX_FIFO_VC_SIZE, r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2535 | } |
| 2536 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2537 | static int dsi_force_tx_stop_mode_io(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2538 | { |
| 2539 | u32 r; |
| 2540 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2541 | r = dsi_read_reg(dsidev, DSI_TIMING1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2542 | r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2543 | dsi_write_reg(dsidev, DSI_TIMING1, r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2544 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2545 | if (wait_for_bit_change(dsidev, DSI_TIMING1, 15, 0) != 0) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2546 | DSSERR("TX_STOP bit not going down\n"); |
| 2547 | return -EIO; |
| 2548 | } |
| 2549 | |
| 2550 | return 0; |
| 2551 | } |
| 2552 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2553 | static bool dsi_vc_is_enabled(struct platform_device *dsidev, int channel) |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2554 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2555 | return REG_GET(dsidev, DSI_VC_CTRL(channel), 0, 0); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2556 | } |
| 2557 | |
| 2558 | static void dsi_packet_sent_handler_vp(void *data, u32 mask) |
| 2559 | { |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2560 | struct dsi_packet_sent_handler_data *vp_data = |
| 2561 | (struct dsi_packet_sent_handler_data *) data; |
| 2562 | struct dsi_data *dsi = dsi_get_dsidrv_data(vp_data->dsidev); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2563 | const int channel = dsi->update_channel; |
| 2564 | u8 bit = dsi->te_enabled ? 30 : 31; |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2565 | |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2566 | if (REG_GET(vp_data->dsidev, DSI_VC_TE(channel), bit, bit) == 0) |
| 2567 | complete(vp_data->completion); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2568 | } |
| 2569 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2570 | static int dsi_sync_vc_vp(struct platform_device *dsidev, int channel) |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2571 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2572 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2573 | DECLARE_COMPLETION_ONSTACK(completion); |
Julia Lawall | 39917f0 | 2014-08-23 13:20:29 +0200 | [diff] [blame^] | 2574 | struct dsi_packet_sent_handler_data vp_data = { |
| 2575 | .dsidev = dsidev, |
| 2576 | .completion = &completion |
| 2577 | }; |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2578 | int r = 0; |
| 2579 | u8 bit; |
| 2580 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2581 | bit = dsi->te_enabled ? 30 : 31; |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2582 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2583 | r = dsi_register_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp, |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2584 | &vp_data, DSI_VC_IRQ_PACKET_SENT); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2585 | if (r) |
| 2586 | goto err0; |
| 2587 | |
| 2588 | /* Wait for completion only if TE_EN/TE_START is still set */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2589 | if (REG_GET(dsidev, DSI_VC_TE(channel), bit, bit)) { |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2590 | if (wait_for_completion_timeout(&completion, |
| 2591 | msecs_to_jiffies(10)) == 0) { |
| 2592 | DSSERR("Failed to complete previous frame transfer\n"); |
| 2593 | r = -EIO; |
| 2594 | goto err1; |
| 2595 | } |
| 2596 | } |
| 2597 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2598 | dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp, |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2599 | &vp_data, DSI_VC_IRQ_PACKET_SENT); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2600 | |
| 2601 | return 0; |
| 2602 | err1: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2603 | dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp, |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2604 | &vp_data, DSI_VC_IRQ_PACKET_SENT); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2605 | err0: |
| 2606 | return r; |
| 2607 | } |
| 2608 | |
| 2609 | static void dsi_packet_sent_handler_l4(void *data, u32 mask) |
| 2610 | { |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2611 | struct dsi_packet_sent_handler_data *l4_data = |
| 2612 | (struct dsi_packet_sent_handler_data *) data; |
| 2613 | struct dsi_data *dsi = dsi_get_dsidrv_data(l4_data->dsidev); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2614 | const int channel = dsi->update_channel; |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2615 | |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2616 | if (REG_GET(l4_data->dsidev, DSI_VC_CTRL(channel), 5, 5) == 0) |
| 2617 | complete(l4_data->completion); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2618 | } |
| 2619 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2620 | static int dsi_sync_vc_l4(struct platform_device *dsidev, int channel) |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2621 | { |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2622 | DECLARE_COMPLETION_ONSTACK(completion); |
Julia Lawall | 39917f0 | 2014-08-23 13:20:29 +0200 | [diff] [blame^] | 2623 | struct dsi_packet_sent_handler_data l4_data = { |
| 2624 | .dsidev = dsidev, |
| 2625 | .completion = &completion |
| 2626 | }; |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2627 | int r = 0; |
| 2628 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2629 | r = dsi_register_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4, |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2630 | &l4_data, DSI_VC_IRQ_PACKET_SENT); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2631 | if (r) |
| 2632 | goto err0; |
| 2633 | |
| 2634 | /* Wait for completion only if TX_FIFO_NOT_EMPTY is still set */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2635 | if (REG_GET(dsidev, DSI_VC_CTRL(channel), 5, 5)) { |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2636 | if (wait_for_completion_timeout(&completion, |
| 2637 | msecs_to_jiffies(10)) == 0) { |
| 2638 | DSSERR("Failed to complete previous l4 transfer\n"); |
| 2639 | r = -EIO; |
| 2640 | goto err1; |
| 2641 | } |
| 2642 | } |
| 2643 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2644 | dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4, |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2645 | &l4_data, DSI_VC_IRQ_PACKET_SENT); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2646 | |
| 2647 | return 0; |
| 2648 | err1: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2649 | dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4, |
Archit Taneja | 2e868db | 2011-05-12 17:26:28 +0530 | [diff] [blame] | 2650 | &l4_data, DSI_VC_IRQ_PACKET_SENT); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2651 | err0: |
| 2652 | return r; |
| 2653 | } |
| 2654 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2655 | static int dsi_sync_vc(struct platform_device *dsidev, int channel) |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2656 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2657 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 2658 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2659 | WARN_ON(!dsi_bus_is_locked(dsidev)); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2660 | |
| 2661 | WARN_ON(in_interrupt()); |
| 2662 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2663 | if (!dsi_vc_is_enabled(dsidev, channel)) |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2664 | return 0; |
| 2665 | |
Archit Taneja | d604914 | 2011-08-22 11:58:08 +0530 | [diff] [blame] | 2666 | switch (dsi->vc[channel].source) { |
| 2667 | case DSI_VC_SOURCE_VP: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2668 | return dsi_sync_vc_vp(dsidev, channel); |
Archit Taneja | d604914 | 2011-08-22 11:58:08 +0530 | [diff] [blame] | 2669 | case DSI_VC_SOURCE_L4: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2670 | return dsi_sync_vc_l4(dsidev, channel); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2671 | default: |
| 2672 | BUG(); |
Tomi Valkeinen | c6eee96 | 2012-05-18 11:47:02 +0300 | [diff] [blame] | 2673 | return -EINVAL; |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2674 | } |
| 2675 | } |
| 2676 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2677 | static int dsi_vc_enable(struct platform_device *dsidev, int channel, |
| 2678 | bool enable) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2679 | { |
Tomi Valkeinen | 446f7bf | 2010-01-11 16:12:31 +0200 | [diff] [blame] | 2680 | DSSDBG("dsi_vc_enable channel %d, enable %d\n", |
| 2681 | channel, enable); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2682 | |
| 2683 | enable = enable ? 1 : 0; |
| 2684 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2685 | REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 0, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2686 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2687 | if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel), |
| 2688 | 0, enable) != enable) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2689 | DSSERR("Failed to set dsi_vc_enable to %d\n", enable); |
| 2690 | return -EIO; |
| 2691 | } |
| 2692 | |
| 2693 | return 0; |
| 2694 | } |
| 2695 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2696 | static void dsi_vc_initial_config(struct platform_device *dsidev, int channel) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2697 | { |
Tomi Valkeinen | 2c1a3ea | 2013-02-22 13:42:59 +0200 | [diff] [blame] | 2698 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2699 | u32 r; |
| 2700 | |
Chandrabhanu Mahapatra | 702d267 | 2012-09-24 17:12:58 +0530 | [diff] [blame] | 2701 | DSSDBG("Initial config of virtual channel %d", channel); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2702 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2703 | r = dsi_read_reg(dsidev, DSI_VC_CTRL(channel)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2704 | |
| 2705 | if (FLD_GET(r, 15, 15)) /* VC_BUSY */ |
| 2706 | DSSERR("VC(%d) busy when trying to configure it!\n", |
| 2707 | channel); |
| 2708 | |
| 2709 | r = FLD_MOD(r, 0, 1, 1); /* SOURCE, 0 = L4 */ |
| 2710 | r = FLD_MOD(r, 0, 2, 2); /* BTA_SHORT_EN */ |
| 2711 | r = FLD_MOD(r, 0, 3, 3); /* BTA_LONG_EN */ |
| 2712 | r = FLD_MOD(r, 0, 4, 4); /* MODE, 0 = command */ |
| 2713 | r = FLD_MOD(r, 1, 7, 7); /* CS_TX_EN */ |
| 2714 | r = FLD_MOD(r, 1, 8, 8); /* ECC_TX_EN */ |
| 2715 | 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] | 2716 | if (dss_has_feature(FEAT_DSI_VC_OCP_WIDTH)) |
| 2717 | r = FLD_MOD(r, 3, 11, 10); /* OCP_WIDTH = 32 bit */ |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2718 | |
| 2719 | r = FLD_MOD(r, 4, 29, 27); /* DMA_RX_REQ_NB = no dma */ |
| 2720 | r = FLD_MOD(r, 4, 23, 21); /* DMA_TX_REQ_NB = no dma */ |
| 2721 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2722 | dsi_write_reg(dsidev, DSI_VC_CTRL(channel), r); |
Tomi Valkeinen | 2c1a3ea | 2013-02-22 13:42:59 +0200 | [diff] [blame] | 2723 | |
| 2724 | dsi->vc[channel].source = DSI_VC_SOURCE_L4; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2725 | } |
| 2726 | |
Archit Taneja | d604914 | 2011-08-22 11:58:08 +0530 | [diff] [blame] | 2727 | static int dsi_vc_config_source(struct platform_device *dsidev, int channel, |
| 2728 | enum dsi_vc_source source) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2729 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2730 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 2731 | |
Archit Taneja | d604914 | 2011-08-22 11:58:08 +0530 | [diff] [blame] | 2732 | if (dsi->vc[channel].source == source) |
Tomi Valkeinen | 9ecd968 | 2010-04-30 11:24:33 +0300 | [diff] [blame] | 2733 | return 0; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2734 | |
Chandrabhanu Mahapatra | 702d267 | 2012-09-24 17:12:58 +0530 | [diff] [blame] | 2735 | DSSDBG("Source config of virtual channel %d", channel); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2736 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2737 | dsi_sync_vc(dsidev, channel); |
Archit Taneja | cf398fb | 2011-03-23 09:59:34 +0000 | [diff] [blame] | 2738 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2739 | dsi_vc_enable(dsidev, channel, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2740 | |
Tomi Valkeinen | 9ecd968 | 2010-04-30 11:24:33 +0300 | [diff] [blame] | 2741 | /* VC_BUSY */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2742 | 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] | 2743 | DSSERR("vc(%d) busy when trying to config for VP\n", channel); |
Tomi Valkeinen | 9ecd968 | 2010-04-30 11:24:33 +0300 | [diff] [blame] | 2744 | return -EIO; |
| 2745 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2746 | |
Archit Taneja | d604914 | 2011-08-22 11:58:08 +0530 | [diff] [blame] | 2747 | /* SOURCE, 0 = L4, 1 = video port */ |
| 2748 | REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), source, 1, 1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2749 | |
Archit Taneja | 9613c02 | 2011-03-22 06:33:36 -0500 | [diff] [blame] | 2750 | /* DCS_CMD_ENABLE */ |
Archit Taneja | d604914 | 2011-08-22 11:58:08 +0530 | [diff] [blame] | 2751 | if (dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC)) { |
| 2752 | bool enable = source == DSI_VC_SOURCE_VP; |
| 2753 | REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 30, 30); |
| 2754 | } |
Archit Taneja | 9613c02 | 2011-03-22 06:33:36 -0500 | [diff] [blame] | 2755 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2756 | dsi_vc_enable(dsidev, channel, 1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2757 | |
Archit Taneja | d604914 | 2011-08-22 11:58:08 +0530 | [diff] [blame] | 2758 | dsi->vc[channel].source = source; |
Tomi Valkeinen | 9ecd968 | 2010-04-30 11:24:33 +0300 | [diff] [blame] | 2759 | |
| 2760 | return 0; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2761 | } |
| 2762 | |
Tomi Valkeinen | 5cfc1c3 | 2013-05-15 11:24:30 +0300 | [diff] [blame] | 2763 | static void dsi_vc_enable_hs(struct omap_dss_device *dssdev, int channel, |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 2764 | bool enable) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2765 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2766 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Archit Taneja | 0b3ffe3 | 2012-08-13 22:13:39 +0530 | [diff] [blame] | 2767 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2768 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2769 | DSSDBG("dsi_vc_enable_hs(%d, %d)\n", channel, enable); |
| 2770 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2771 | WARN_ON(!dsi_bus_is_locked(dsidev)); |
Tomi Valkeinen | 61140c9 | 2010-01-12 16:00:30 +0200 | [diff] [blame] | 2772 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2773 | dsi_vc_enable(dsidev, channel, 0); |
| 2774 | dsi_if_enable(dsidev, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2775 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2776 | REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 9, 9); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2777 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2778 | dsi_vc_enable(dsidev, channel, 1); |
| 2779 | dsi_if_enable(dsidev, 1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2780 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2781 | dsi_force_tx_stop_mode_io(dsidev); |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 2782 | |
| 2783 | /* start the DDR clock by sending a NULL packet */ |
Archit Taneja | 0b3ffe3 | 2012-08-13 22:13:39 +0530 | [diff] [blame] | 2784 | if (dsi->vm_timings.ddr_clk_always_on && enable) |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 2785 | dsi_vc_send_null(dssdev, channel); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2786 | } |
| 2787 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2788 | 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] | 2789 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2790 | while (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2791 | u32 val; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2792 | val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2793 | DSSDBG("\t\tb1 %#02x b2 %#02x b3 %#02x b4 %#02x\n", |
| 2794 | (val >> 0) & 0xff, |
| 2795 | (val >> 8) & 0xff, |
| 2796 | (val >> 16) & 0xff, |
| 2797 | (val >> 24) & 0xff); |
| 2798 | } |
| 2799 | } |
| 2800 | |
| 2801 | static void dsi_show_rx_ack_with_err(u16 err) |
| 2802 | { |
| 2803 | DSSERR("\tACK with ERROR (%#x):\n", err); |
| 2804 | if (err & (1 << 0)) |
| 2805 | DSSERR("\t\tSoT Error\n"); |
| 2806 | if (err & (1 << 1)) |
| 2807 | DSSERR("\t\tSoT Sync Error\n"); |
| 2808 | if (err & (1 << 2)) |
| 2809 | DSSERR("\t\tEoT Sync Error\n"); |
| 2810 | if (err & (1 << 3)) |
| 2811 | DSSERR("\t\tEscape Mode Entry Command Error\n"); |
| 2812 | if (err & (1 << 4)) |
| 2813 | DSSERR("\t\tLP Transmit Sync Error\n"); |
| 2814 | if (err & (1 << 5)) |
| 2815 | DSSERR("\t\tHS Receive Timeout Error\n"); |
| 2816 | if (err & (1 << 6)) |
| 2817 | DSSERR("\t\tFalse Control Error\n"); |
| 2818 | if (err & (1 << 7)) |
| 2819 | DSSERR("\t\t(reserved7)\n"); |
| 2820 | if (err & (1 << 8)) |
| 2821 | DSSERR("\t\tECC Error, single-bit (corrected)\n"); |
| 2822 | if (err & (1 << 9)) |
| 2823 | DSSERR("\t\tECC Error, multi-bit (not corrected)\n"); |
| 2824 | if (err & (1 << 10)) |
| 2825 | DSSERR("\t\tChecksum Error\n"); |
| 2826 | if (err & (1 << 11)) |
| 2827 | DSSERR("\t\tData type not recognized\n"); |
| 2828 | if (err & (1 << 12)) |
| 2829 | DSSERR("\t\tInvalid VC ID\n"); |
| 2830 | if (err & (1 << 13)) |
| 2831 | DSSERR("\t\tInvalid Transmission Length\n"); |
| 2832 | if (err & (1 << 14)) |
| 2833 | DSSERR("\t\t(reserved14)\n"); |
| 2834 | if (err & (1 << 15)) |
| 2835 | DSSERR("\t\tDSI Protocol Violation\n"); |
| 2836 | } |
| 2837 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2838 | static u16 dsi_vc_flush_receive_data(struct platform_device *dsidev, |
| 2839 | int channel) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2840 | { |
| 2841 | /* RX_FIFO_NOT_EMPTY */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2842 | while (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2843 | u32 val; |
| 2844 | u8 dt; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2845 | val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel)); |
Tomi Valkeinen | 86a7867 | 2010-03-16 16:19:06 +0200 | [diff] [blame] | 2846 | DSSERR("\trawval %#08x\n", val); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2847 | dt = FLD_GET(val, 5, 0); |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 2848 | if (dt == MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2849 | u16 err = FLD_GET(val, 23, 8); |
| 2850 | dsi_show_rx_ack_with_err(err); |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 2851 | } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE) { |
Tomi Valkeinen | 86a7867 | 2010-03-16 16:19:06 +0200 | [diff] [blame] | 2852 | DSSERR("\tDCS short response, 1 byte: %#x\n", |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2853 | FLD_GET(val, 23, 8)); |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 2854 | } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE) { |
Tomi Valkeinen | 86a7867 | 2010-03-16 16:19:06 +0200 | [diff] [blame] | 2855 | DSSERR("\tDCS short response, 2 byte: %#x\n", |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2856 | FLD_GET(val, 23, 8)); |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 2857 | } else if (dt == MIPI_DSI_RX_DCS_LONG_READ_RESPONSE) { |
Tomi Valkeinen | 86a7867 | 2010-03-16 16:19:06 +0200 | [diff] [blame] | 2858 | DSSERR("\tDCS long response, len %d\n", |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2859 | FLD_GET(val, 23, 8)); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2860 | dsi_vc_flush_long_data(dsidev, channel); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2861 | } else { |
| 2862 | DSSERR("\tunknown datatype 0x%02x\n", dt); |
| 2863 | } |
| 2864 | } |
| 2865 | return 0; |
| 2866 | } |
| 2867 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2868 | static int dsi_vc_send_bta(struct platform_device *dsidev, int channel) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2869 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2870 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 2871 | |
| 2872 | if (dsi->debug_write || dsi->debug_read) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2873 | DSSDBG("dsi_vc_send_bta %d\n", channel); |
| 2874 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2875 | WARN_ON(!dsi_bus_is_locked(dsidev)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2876 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2877 | /* RX_FIFO_NOT_EMPTY */ |
| 2878 | if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2879 | DSSERR("rx fifo not empty when sending BTA, dumping data:\n"); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2880 | dsi_vc_flush_receive_data(dsidev, channel); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2881 | } |
| 2882 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2883 | 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] | 2884 | |
Tomi Valkeinen | 968f8e9 | 2011-10-12 10:13:14 +0300 | [diff] [blame] | 2885 | /* flush posted write */ |
| 2886 | dsi_read_reg(dsidev, DSI_VC_CTRL(channel)); |
| 2887 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2888 | return 0; |
| 2889 | } |
| 2890 | |
Tomi Valkeinen | 5cfc1c3 | 2013-05-15 11:24:30 +0300 | [diff] [blame] | 2891 | static 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] | 2892 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2893 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Tomi Valkeinen | f36a06e | 2011-03-02 14:48:41 +0200 | [diff] [blame] | 2894 | DECLARE_COMPLETION_ONSTACK(completion); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2895 | int r = 0; |
| 2896 | u32 err; |
| 2897 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2898 | r = dsi_register_isr_vc(dsidev, channel, dsi_completion_handler, |
Tomi Valkeinen | f36a06e | 2011-03-02 14:48:41 +0200 | [diff] [blame] | 2899 | &completion, DSI_VC_IRQ_BTA); |
| 2900 | if (r) |
| 2901 | goto err0; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2902 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2903 | r = dsi_register_isr(dsidev, dsi_completion_handler, &completion, |
Tomi Valkeinen | 773b30b | 2010-10-08 16:15:25 +0300 | [diff] [blame] | 2904 | DSI_IRQ_ERROR_MASK); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2905 | if (r) |
Tomi Valkeinen | f36a06e | 2011-03-02 14:48:41 +0200 | [diff] [blame] | 2906 | goto err1; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2907 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2908 | r = dsi_vc_send_bta(dsidev, channel); |
Tomi Valkeinen | 773b30b | 2010-10-08 16:15:25 +0300 | [diff] [blame] | 2909 | if (r) |
| 2910 | goto err2; |
| 2911 | |
Tomi Valkeinen | f36a06e | 2011-03-02 14:48:41 +0200 | [diff] [blame] | 2912 | if (wait_for_completion_timeout(&completion, |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2913 | msecs_to_jiffies(500)) == 0) { |
| 2914 | DSSERR("Failed to receive BTA\n"); |
| 2915 | r = -EIO; |
Tomi Valkeinen | 773b30b | 2010-10-08 16:15:25 +0300 | [diff] [blame] | 2916 | goto err2; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2917 | } |
| 2918 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2919 | err = dsi_get_errors(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2920 | if (err) { |
| 2921 | DSSERR("Error while sending BTA: %x\n", err); |
| 2922 | r = -EIO; |
Tomi Valkeinen | 773b30b | 2010-10-08 16:15:25 +0300 | [diff] [blame] | 2923 | goto err2; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2924 | } |
Tomi Valkeinen | 773b30b | 2010-10-08 16:15:25 +0300 | [diff] [blame] | 2925 | err2: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2926 | dsi_unregister_isr(dsidev, dsi_completion_handler, &completion, |
Tomi Valkeinen | 773b30b | 2010-10-08 16:15:25 +0300 | [diff] [blame] | 2927 | DSI_IRQ_ERROR_MASK); |
Tomi Valkeinen | f36a06e | 2011-03-02 14:48:41 +0200 | [diff] [blame] | 2928 | err1: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2929 | dsi_unregister_isr_vc(dsidev, channel, dsi_completion_handler, |
Tomi Valkeinen | f36a06e | 2011-03-02 14:48:41 +0200 | [diff] [blame] | 2930 | &completion, DSI_VC_IRQ_BTA); |
| 2931 | err0: |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2932 | return r; |
| 2933 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2934 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2935 | static inline void dsi_vc_write_long_header(struct platform_device *dsidev, |
| 2936 | int channel, u8 data_type, u16 len, u8 ecc) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2937 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2938 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2939 | u32 val; |
| 2940 | u8 data_id; |
| 2941 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2942 | WARN_ON(!dsi_bus_is_locked(dsidev)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2943 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2944 | data_id = data_type | dsi->vc[channel].vc_id << 6; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2945 | |
| 2946 | val = FLD_VAL(data_id, 7, 0) | FLD_VAL(len, 23, 8) | |
| 2947 | FLD_VAL(ecc, 31, 24); |
| 2948 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2949 | dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_HEADER(channel), val); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2950 | } |
| 2951 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2952 | static inline void dsi_vc_write_long_payload(struct platform_device *dsidev, |
| 2953 | int channel, u8 b1, u8 b2, u8 b3, u8 b4) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2954 | { |
| 2955 | u32 val; |
| 2956 | |
| 2957 | val = b4 << 24 | b3 << 16 | b2 << 8 | b1 << 0; |
| 2958 | |
| 2959 | /* DSSDBG("\twriting %02x, %02x, %02x, %02x (%#010x)\n", |
| 2960 | b1, b2, b3, b4, val); */ |
| 2961 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2962 | dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_PAYLOAD(channel), val); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2963 | } |
| 2964 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2965 | static int dsi_vc_send_long(struct platform_device *dsidev, int channel, |
| 2966 | u8 data_type, u8 *data, u16 len, u8 ecc) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2967 | { |
| 2968 | /*u32 val; */ |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2969 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2970 | int i; |
| 2971 | u8 *p; |
| 2972 | int r = 0; |
| 2973 | u8 b1, b2, b3, b4; |
| 2974 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2975 | if (dsi->debug_write) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2976 | DSSDBG("dsi_vc_send_long, %d bytes\n", len); |
| 2977 | |
| 2978 | /* len + header */ |
Tomi Valkeinen | 558c73e | 2013-09-25 14:40:06 +0300 | [diff] [blame] | 2979 | if (dsi->vc[channel].tx_fifo_size * 32 * 4 < len + 4) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2980 | DSSERR("unable to send long packet: packet too long.\n"); |
| 2981 | return -EINVAL; |
| 2982 | } |
| 2983 | |
Archit Taneja | d604914 | 2011-08-22 11:58:08 +0530 | [diff] [blame] | 2984 | dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_L4); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2985 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2986 | dsi_vc_write_long_header(dsidev, channel, data_type, len, ecc); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2987 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2988 | p = data; |
| 2989 | for (i = 0; i < len >> 2; i++) { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 2990 | if (dsi->debug_write) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2991 | DSSDBG("\tsending full packet %d\n", i); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2992 | |
| 2993 | b1 = *p++; |
| 2994 | b2 = *p++; |
| 2995 | b3 = *p++; |
| 2996 | b4 = *p++; |
| 2997 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 2998 | dsi_vc_write_long_payload(dsidev, channel, b1, b2, b3, b4); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 2999 | } |
| 3000 | |
| 3001 | i = len % 4; |
| 3002 | if (i) { |
| 3003 | b1 = 0; b2 = 0; b3 = 0; |
| 3004 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3005 | if (dsi->debug_write) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3006 | DSSDBG("\tsending remainder bytes %d\n", i); |
| 3007 | |
| 3008 | switch (i) { |
| 3009 | case 3: |
| 3010 | b1 = *p++; |
| 3011 | b2 = *p++; |
| 3012 | b3 = *p++; |
| 3013 | break; |
| 3014 | case 2: |
| 3015 | b1 = *p++; |
| 3016 | b2 = *p++; |
| 3017 | break; |
| 3018 | case 1: |
| 3019 | b1 = *p++; |
| 3020 | break; |
| 3021 | } |
| 3022 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3023 | dsi_vc_write_long_payload(dsidev, channel, b1, b2, b3, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3024 | } |
| 3025 | |
| 3026 | return r; |
| 3027 | } |
| 3028 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3029 | static int dsi_vc_send_short(struct platform_device *dsidev, int channel, |
| 3030 | u8 data_type, u16 data, u8 ecc) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3031 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3032 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3033 | u32 r; |
| 3034 | u8 data_id; |
| 3035 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3036 | WARN_ON(!dsi_bus_is_locked(dsidev)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3037 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3038 | if (dsi->debug_write) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3039 | DSSDBG("dsi_vc_send_short(ch%d, dt %#x, b1 %#x, b2 %#x)\n", |
| 3040 | channel, |
| 3041 | data_type, data & 0xff, (data >> 8) & 0xff); |
| 3042 | |
Archit Taneja | d604914 | 2011-08-22 11:58:08 +0530 | [diff] [blame] | 3043 | dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_L4); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3044 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3045 | 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] | 3046 | DSSERR("ERROR FIFO FULL, aborting transfer\n"); |
| 3047 | return -EINVAL; |
| 3048 | } |
| 3049 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3050 | data_id = data_type | dsi->vc[channel].vc_id << 6; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3051 | |
| 3052 | r = (data_id << 0) | (data << 8) | (ecc << 24); |
| 3053 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3054 | dsi_write_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel), r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3055 | |
| 3056 | return 0; |
| 3057 | } |
| 3058 | |
Tomi Valkeinen | 5cfc1c3 | 2013-05-15 11:24:30 +0300 | [diff] [blame] | 3059 | static int dsi_vc_send_null(struct omap_dss_device *dssdev, int channel) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3060 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3061 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3062 | |
Archit Taneja | 18b7d09 | 2011-09-05 17:01:08 +0530 | [diff] [blame] | 3063 | return dsi_vc_send_long(dsidev, channel, MIPI_DSI_NULL_PACKET, NULL, |
| 3064 | 0, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3065 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3066 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 3067 | static int dsi_vc_write_nosync_common(struct platform_device *dsidev, |
Archit Taneja | 6ff8aa3 | 2011-08-25 18:35:58 +0530 | [diff] [blame] | 3068 | int channel, u8 *data, int len, enum dss_dsi_content_type type) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3069 | { |
| 3070 | int r; |
| 3071 | |
Archit Taneja | 6ff8aa3 | 2011-08-25 18:35:58 +0530 | [diff] [blame] | 3072 | if (len == 0) { |
| 3073 | BUG_ON(type == DSS_DSI_CONTENT_DCS); |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 3074 | r = dsi_vc_send_short(dsidev, channel, |
Archit Taneja | 6ff8aa3 | 2011-08-25 18:35:58 +0530 | [diff] [blame] | 3075 | MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM, 0, 0); |
| 3076 | } else if (len == 1) { |
| 3077 | r = dsi_vc_send_short(dsidev, channel, |
| 3078 | type == DSS_DSI_CONTENT_GENERIC ? |
| 3079 | MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM : |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 3080 | MIPI_DSI_DCS_SHORT_WRITE, data[0], 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3081 | } else if (len == 2) { |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 3082 | r = dsi_vc_send_short(dsidev, channel, |
Archit Taneja | 6ff8aa3 | 2011-08-25 18:35:58 +0530 | [diff] [blame] | 3083 | type == DSS_DSI_CONTENT_GENERIC ? |
| 3084 | MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM : |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 3085 | MIPI_DSI_DCS_SHORT_WRITE_PARAM, |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3086 | data[0] | (data[1] << 8), 0); |
| 3087 | } else { |
Archit Taneja | 6ff8aa3 | 2011-08-25 18:35:58 +0530 | [diff] [blame] | 3088 | r = dsi_vc_send_long(dsidev, channel, |
| 3089 | type == DSS_DSI_CONTENT_GENERIC ? |
| 3090 | MIPI_DSI_GENERIC_LONG_WRITE : |
| 3091 | MIPI_DSI_DCS_LONG_WRITE, data, len, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3092 | } |
| 3093 | |
| 3094 | return r; |
| 3095 | } |
Archit Taneja | 6ff8aa3 | 2011-08-25 18:35:58 +0530 | [diff] [blame] | 3096 | |
Tomi Valkeinen | 5cfc1c3 | 2013-05-15 11:24:30 +0300 | [diff] [blame] | 3097 | static int dsi_vc_dcs_write_nosync(struct omap_dss_device *dssdev, int channel, |
Archit Taneja | 6ff8aa3 | 2011-08-25 18:35:58 +0530 | [diff] [blame] | 3098 | u8 *data, int len) |
| 3099 | { |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 3100 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 3101 | |
| 3102 | return dsi_vc_write_nosync_common(dsidev, channel, data, len, |
Archit Taneja | 6ff8aa3 | 2011-08-25 18:35:58 +0530 | [diff] [blame] | 3103 | DSS_DSI_CONTENT_DCS); |
| 3104 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3105 | |
Tomi Valkeinen | 5cfc1c3 | 2013-05-15 11:24:30 +0300 | [diff] [blame] | 3106 | static int dsi_vc_generic_write_nosync(struct omap_dss_device *dssdev, int channel, |
Archit Taneja | 6ff8aa3 | 2011-08-25 18:35:58 +0530 | [diff] [blame] | 3107 | u8 *data, int len) |
| 3108 | { |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 3109 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 3110 | |
| 3111 | return dsi_vc_write_nosync_common(dsidev, channel, data, len, |
Archit Taneja | 6ff8aa3 | 2011-08-25 18:35:58 +0530 | [diff] [blame] | 3112 | DSS_DSI_CONTENT_GENERIC); |
| 3113 | } |
Archit Taneja | 6ff8aa3 | 2011-08-25 18:35:58 +0530 | [diff] [blame] | 3114 | |
| 3115 | static int dsi_vc_write_common(struct omap_dss_device *dssdev, int channel, |
| 3116 | u8 *data, int len, enum dss_dsi_content_type type) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3117 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3118 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3119 | int r; |
| 3120 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 3121 | r = dsi_vc_write_nosync_common(dsidev, channel, data, len, type); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3122 | if (r) |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3123 | goto err; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3124 | |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 3125 | r = dsi_vc_send_bta_sync(dssdev, channel); |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3126 | if (r) |
| 3127 | goto err; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3128 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3129 | /* RX_FIFO_NOT_EMPTY */ |
| 3130 | if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) { |
Tomi Valkeinen | b63ac1e | 2010-04-09 13:20:57 +0300 | [diff] [blame] | 3131 | DSSERR("rx fifo not empty after write, dumping data:\n"); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3132 | dsi_vc_flush_receive_data(dsidev, channel); |
Tomi Valkeinen | b63ac1e | 2010-04-09 13:20:57 +0300 | [diff] [blame] | 3133 | r = -EIO; |
| 3134 | goto err; |
| 3135 | } |
| 3136 | |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3137 | return 0; |
| 3138 | err: |
Archit Taneja | 6ff8aa3 | 2011-08-25 18:35:58 +0530 | [diff] [blame] | 3139 | 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] | 3140 | channel, data[0], len); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3141 | return r; |
| 3142 | } |
Archit Taneja | 6ff8aa3 | 2011-08-25 18:35:58 +0530 | [diff] [blame] | 3143 | |
Tomi Valkeinen | 5cfc1c3 | 2013-05-15 11:24:30 +0300 | [diff] [blame] | 3144 | static int dsi_vc_dcs_write(struct omap_dss_device *dssdev, int channel, u8 *data, |
Archit Taneja | 6ff8aa3 | 2011-08-25 18:35:58 +0530 | [diff] [blame] | 3145 | int len) |
| 3146 | { |
| 3147 | return dsi_vc_write_common(dssdev, channel, data, len, |
| 3148 | DSS_DSI_CONTENT_DCS); |
| 3149 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3150 | |
Tomi Valkeinen | 5cfc1c3 | 2013-05-15 11:24:30 +0300 | [diff] [blame] | 3151 | static int dsi_vc_generic_write(struct omap_dss_device *dssdev, int channel, u8 *data, |
Archit Taneja | 6ff8aa3 | 2011-08-25 18:35:58 +0530 | [diff] [blame] | 3152 | int len) |
| 3153 | { |
| 3154 | return dsi_vc_write_common(dssdev, channel, data, len, |
| 3155 | DSS_DSI_CONTENT_GENERIC); |
| 3156 | } |
Archit Taneja | 6ff8aa3 | 2011-08-25 18:35:58 +0530 | [diff] [blame] | 3157 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 3158 | static int dsi_vc_dcs_send_read_request(struct platform_device *dsidev, |
Archit Taneja | b850975 | 2011-08-30 15:48:23 +0530 | [diff] [blame] | 3159 | int channel, u8 dcs_cmd) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3160 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3161 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Archit Taneja | b850975 | 2011-08-30 15:48:23 +0530 | [diff] [blame] | 3162 | int r; |
| 3163 | |
| 3164 | if (dsi->debug_read) |
| 3165 | DSSDBG("dsi_vc_dcs_send_read_request(ch%d, dcs_cmd %x)\n", |
| 3166 | channel, dcs_cmd); |
| 3167 | |
| 3168 | r = dsi_vc_send_short(dsidev, channel, MIPI_DSI_DCS_READ, dcs_cmd, 0); |
| 3169 | if (r) { |
| 3170 | DSSERR("dsi_vc_dcs_send_read_request(ch %d, cmd 0x%02x)" |
| 3171 | " failed\n", channel, dcs_cmd); |
| 3172 | return r; |
| 3173 | } |
| 3174 | |
| 3175 | return 0; |
| 3176 | } |
| 3177 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 3178 | static int dsi_vc_generic_send_read_request(struct platform_device *dsidev, |
Archit Taneja | b3b89c0 | 2011-08-30 16:07:39 +0530 | [diff] [blame] | 3179 | int channel, u8 *reqdata, int reqlen) |
| 3180 | { |
Archit Taneja | b3b89c0 | 2011-08-30 16:07:39 +0530 | [diff] [blame] | 3181 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 3182 | u16 data; |
| 3183 | u8 data_type; |
| 3184 | int r; |
| 3185 | |
| 3186 | if (dsi->debug_read) |
| 3187 | DSSDBG("dsi_vc_generic_send_read_request(ch %d, reqlen %d)\n", |
| 3188 | channel, reqlen); |
| 3189 | |
| 3190 | if (reqlen == 0) { |
| 3191 | data_type = MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM; |
| 3192 | data = 0; |
| 3193 | } else if (reqlen == 1) { |
| 3194 | data_type = MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM; |
| 3195 | data = reqdata[0]; |
| 3196 | } else if (reqlen == 2) { |
| 3197 | data_type = MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM; |
| 3198 | data = reqdata[0] | (reqdata[1] << 8); |
| 3199 | } else { |
| 3200 | BUG(); |
Tomi Valkeinen | c6eee96 | 2012-05-18 11:47:02 +0300 | [diff] [blame] | 3201 | return -EINVAL; |
Archit Taneja | b3b89c0 | 2011-08-30 16:07:39 +0530 | [diff] [blame] | 3202 | } |
| 3203 | |
| 3204 | r = dsi_vc_send_short(dsidev, channel, data_type, data, 0); |
| 3205 | if (r) { |
| 3206 | DSSERR("dsi_vc_generic_send_read_request(ch %d, reqlen %d)" |
| 3207 | " failed\n", channel, reqlen); |
| 3208 | return r; |
| 3209 | } |
| 3210 | |
| 3211 | return 0; |
| 3212 | } |
| 3213 | |
| 3214 | static int dsi_vc_read_rx_fifo(struct platform_device *dsidev, int channel, |
| 3215 | u8 *buf, int buflen, enum dss_dsi_content_type type) |
Archit Taneja | b850975 | 2011-08-30 15:48:23 +0530 | [diff] [blame] | 3216 | { |
| 3217 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3218 | u32 val; |
| 3219 | u8 dt; |
| 3220 | int r; |
| 3221 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3222 | /* RX_FIFO_NOT_EMPTY */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3223 | if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20) == 0) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3224 | DSSERR("RX fifo empty when trying to read.\n"); |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3225 | r = -EIO; |
| 3226 | goto err; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3227 | } |
| 3228 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3229 | val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel)); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3230 | if (dsi->debug_read) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3231 | DSSDBG("\theader: %08x\n", val); |
| 3232 | dt = FLD_GET(val, 5, 0); |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 3233 | if (dt == MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3234 | u16 err = FLD_GET(val, 23, 8); |
| 3235 | dsi_show_rx_ack_with_err(err); |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3236 | r = -EIO; |
| 3237 | goto err; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3238 | |
Archit Taneja | b3b89c0 | 2011-08-30 16:07:39 +0530 | [diff] [blame] | 3239 | } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ? |
| 3240 | MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_1BYTE : |
| 3241 | MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE)) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3242 | u8 data = FLD_GET(val, 15, 8); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3243 | if (dsi->debug_read) |
Archit Taneja | b3b89c0 | 2011-08-30 16:07:39 +0530 | [diff] [blame] | 3244 | DSSDBG("\t%s short response, 1 byte: %02x\n", |
| 3245 | type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" : |
| 3246 | "DCS", data); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3247 | |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3248 | if (buflen < 1) { |
| 3249 | r = -EIO; |
| 3250 | goto err; |
| 3251 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3252 | |
| 3253 | buf[0] = data; |
| 3254 | |
| 3255 | return 1; |
Archit Taneja | b3b89c0 | 2011-08-30 16:07:39 +0530 | [diff] [blame] | 3256 | } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ? |
| 3257 | MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_2BYTE : |
| 3258 | MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE)) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3259 | u16 data = FLD_GET(val, 23, 8); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3260 | if (dsi->debug_read) |
Archit Taneja | b3b89c0 | 2011-08-30 16:07:39 +0530 | [diff] [blame] | 3261 | DSSDBG("\t%s short response, 2 byte: %04x\n", |
| 3262 | type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" : |
| 3263 | "DCS", data); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3264 | |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3265 | if (buflen < 2) { |
| 3266 | r = -EIO; |
| 3267 | goto err; |
| 3268 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3269 | |
| 3270 | buf[0] = data & 0xff; |
| 3271 | buf[1] = (data >> 8) & 0xff; |
| 3272 | |
| 3273 | return 2; |
Archit Taneja | b3b89c0 | 2011-08-30 16:07:39 +0530 | [diff] [blame] | 3274 | } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ? |
| 3275 | MIPI_DSI_RX_GENERIC_LONG_READ_RESPONSE : |
| 3276 | MIPI_DSI_RX_DCS_LONG_READ_RESPONSE)) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3277 | int w; |
| 3278 | int len = FLD_GET(val, 23, 8); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3279 | if (dsi->debug_read) |
Archit Taneja | b3b89c0 | 2011-08-30 16:07:39 +0530 | [diff] [blame] | 3280 | DSSDBG("\t%s long response, len %d\n", |
| 3281 | type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" : |
| 3282 | "DCS", len); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3283 | |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3284 | if (len > buflen) { |
| 3285 | r = -EIO; |
| 3286 | goto err; |
| 3287 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3288 | |
| 3289 | /* two byte checksum ends the packet, not included in len */ |
| 3290 | for (w = 0; w < len + 2;) { |
| 3291 | int b; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3292 | val = dsi_read_reg(dsidev, |
| 3293 | DSI_VC_SHORT_PACKET_HEADER(channel)); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3294 | if (dsi->debug_read) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3295 | DSSDBG("\t\t%02x %02x %02x %02x\n", |
| 3296 | (val >> 0) & 0xff, |
| 3297 | (val >> 8) & 0xff, |
| 3298 | (val >> 16) & 0xff, |
| 3299 | (val >> 24) & 0xff); |
| 3300 | |
| 3301 | for (b = 0; b < 4; ++b) { |
| 3302 | if (w < len) |
| 3303 | buf[w] = (val >> (b * 8)) & 0xff; |
| 3304 | /* we discard the 2 byte checksum */ |
| 3305 | ++w; |
| 3306 | } |
| 3307 | } |
| 3308 | |
| 3309 | return len; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3310 | } else { |
| 3311 | DSSERR("\tunknown datatype 0x%02x\n", dt); |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3312 | r = -EIO; |
| 3313 | goto err; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3314 | } |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3315 | |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3316 | err: |
Archit Taneja | b3b89c0 | 2011-08-30 16:07:39 +0530 | [diff] [blame] | 3317 | DSSERR("dsi_vc_read_rx_fifo(ch %d type %s) failed\n", channel, |
| 3318 | type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" : "DCS"); |
Tomi Valkeinen | 5d68e03 | 2010-02-26 11:32:56 +0200 | [diff] [blame] | 3319 | |
Archit Taneja | b850975 | 2011-08-30 15:48:23 +0530 | [diff] [blame] | 3320 | return r; |
| 3321 | } |
| 3322 | |
Tomi Valkeinen | 5cfc1c3 | 2013-05-15 11:24:30 +0300 | [diff] [blame] | 3323 | static int dsi_vc_dcs_read(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd, |
Archit Taneja | b850975 | 2011-08-30 15:48:23 +0530 | [diff] [blame] | 3324 | u8 *buf, int buflen) |
| 3325 | { |
| 3326 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 3327 | int r; |
| 3328 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 3329 | r = dsi_vc_dcs_send_read_request(dsidev, channel, dcs_cmd); |
Archit Taneja | b850975 | 2011-08-30 15:48:23 +0530 | [diff] [blame] | 3330 | if (r) |
| 3331 | goto err; |
| 3332 | |
| 3333 | r = dsi_vc_send_bta_sync(dssdev, channel); |
| 3334 | if (r) |
| 3335 | goto err; |
| 3336 | |
Archit Taneja | b3b89c0 | 2011-08-30 16:07:39 +0530 | [diff] [blame] | 3337 | r = dsi_vc_read_rx_fifo(dsidev, channel, buf, buflen, |
| 3338 | DSS_DSI_CONTENT_DCS); |
Archit Taneja | b850975 | 2011-08-30 15:48:23 +0530 | [diff] [blame] | 3339 | if (r < 0) |
| 3340 | goto err; |
| 3341 | |
| 3342 | if (r != buflen) { |
| 3343 | r = -EIO; |
| 3344 | goto err; |
| 3345 | } |
| 3346 | |
| 3347 | return 0; |
| 3348 | err: |
| 3349 | DSSERR("dsi_vc_dcs_read(ch %d, cmd 0x%02x) failed\n", channel, dcs_cmd); |
| 3350 | return r; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3351 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 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 | |
Tomi Valkeinen | 5cfc1c3 | 2013-05-15 11:24:30 +0300 | [diff] [blame] | 3380 | static int dsi_vc_set_max_rx_packet_size(struct omap_dss_device *dssdev, int channel, |
Archit Taneja | 1ffefe7 | 2011-05-12 17:26:24 +0530 | [diff] [blame] | 3381 | u16 len) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3382 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3383 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 3384 | |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 3385 | return dsi_vc_send_short(dsidev, channel, |
| 3386 | MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE, len, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3387 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3388 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3389 | static int dsi_enter_ulps(struct platform_device *dsidev) |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3390 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3391 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3392 | DECLARE_COMPLETION_ONSTACK(completion); |
Tomi Valkeinen | 522a0c2 | 2011-10-13 16:18:52 +0300 | [diff] [blame] | 3393 | int r, i; |
| 3394 | unsigned mask; |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3395 | |
Chandrabhanu Mahapatra | 702d267 | 2012-09-24 17:12:58 +0530 | [diff] [blame] | 3396 | DSSDBG("Entering ULPS"); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3397 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3398 | WARN_ON(!dsi_bus_is_locked(dsidev)); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3399 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3400 | WARN_ON(dsi->ulps_enabled); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3401 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3402 | if (dsi->ulps_enabled) |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3403 | return 0; |
| 3404 | |
Tomi Valkeinen | 6cc78aa | 2011-10-13 19:22:43 +0300 | [diff] [blame] | 3405 | /* DDR_CLK_ALWAYS_ON */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3406 | if (REG_GET(dsidev, DSI_CLK_CTRL, 13, 13)) { |
Tomi Valkeinen | 6cc78aa | 2011-10-13 19:22:43 +0300 | [diff] [blame] | 3407 | dsi_if_enable(dsidev, 0); |
| 3408 | REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 13, 13); |
| 3409 | dsi_if_enable(dsidev, 1); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3410 | } |
| 3411 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3412 | dsi_sync_vc(dsidev, 0); |
| 3413 | dsi_sync_vc(dsidev, 1); |
| 3414 | dsi_sync_vc(dsidev, 2); |
| 3415 | dsi_sync_vc(dsidev, 3); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3416 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3417 | dsi_force_tx_stop_mode_io(dsidev); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3418 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3419 | dsi_vc_enable(dsidev, 0, false); |
| 3420 | dsi_vc_enable(dsidev, 1, false); |
| 3421 | dsi_vc_enable(dsidev, 2, false); |
| 3422 | dsi_vc_enable(dsidev, 3, false); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3423 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3424 | if (REG_GET(dsidev, DSI_COMPLEXIO_CFG2, 16, 16)) { /* HS_BUSY */ |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3425 | DSSERR("HS busy when enabling ULPS\n"); |
| 3426 | return -EIO; |
| 3427 | } |
| 3428 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3429 | if (REG_GET(dsidev, DSI_COMPLEXIO_CFG2, 17, 17)) { /* LP_BUSY */ |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3430 | DSSERR("LP busy when enabling ULPS\n"); |
| 3431 | return -EIO; |
| 3432 | } |
| 3433 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3434 | r = dsi_register_isr_cio(dsidev, dsi_completion_handler, &completion, |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3435 | DSI_CIO_IRQ_ULPSACTIVENOT_ALL0); |
| 3436 | if (r) |
| 3437 | return r; |
| 3438 | |
Tomi Valkeinen | 522a0c2 | 2011-10-13 16:18:52 +0300 | [diff] [blame] | 3439 | mask = 0; |
| 3440 | |
| 3441 | for (i = 0; i < dsi->num_lanes_supported; ++i) { |
| 3442 | if (dsi->lanes[i].function == DSI_LANE_UNUSED) |
| 3443 | continue; |
| 3444 | mask |= 1 << i; |
| 3445 | } |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3446 | /* Assert TxRequestEsc for data lanes and TxUlpsClk for clk lane */ |
| 3447 | /* LANEx_ULPS_SIG2 */ |
Tomi Valkeinen | 522a0c2 | 2011-10-13 16:18:52 +0300 | [diff] [blame] | 3448 | REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG2, mask, 9, 5); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3449 | |
Tomi Valkeinen | a702c85 | 2011-10-12 10:10:21 +0300 | [diff] [blame] | 3450 | /* flush posted write and wait for SCP interface to finish the write */ |
| 3451 | dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG2); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3452 | |
| 3453 | if (wait_for_completion_timeout(&completion, |
| 3454 | msecs_to_jiffies(1000)) == 0) { |
| 3455 | DSSERR("ULPS enable timeout\n"); |
| 3456 | r = -EIO; |
| 3457 | goto err; |
| 3458 | } |
| 3459 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3460 | dsi_unregister_isr_cio(dsidev, dsi_completion_handler, &completion, |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3461 | DSI_CIO_IRQ_ULPSACTIVENOT_ALL0); |
| 3462 | |
Tomi Valkeinen | 8ef0e61 | 2011-05-31 16:55:47 +0300 | [diff] [blame] | 3463 | /* Reset LANEx_ULPS_SIG2 */ |
Tomi Valkeinen | 522a0c2 | 2011-10-13 16:18:52 +0300 | [diff] [blame] | 3464 | REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG2, 0, 9, 5); |
Tomi Valkeinen | 8ef0e61 | 2011-05-31 16:55:47 +0300 | [diff] [blame] | 3465 | |
Tomi Valkeinen | a702c85 | 2011-10-12 10:10:21 +0300 | [diff] [blame] | 3466 | /* flush posted write and wait for SCP interface to finish the write */ |
| 3467 | dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG2); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3468 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 3469 | dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_ULPS); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3470 | |
| 3471 | dsi_if_enable(dsidev, false); |
| 3472 | |
| 3473 | dsi->ulps_enabled = true; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3474 | |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 3475 | return 0; |
| 3476 | |
| 3477 | err: |
| 3478 | dsi_unregister_isr_cio(dsidev, dsi_completion_handler, &completion, |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3479 | DSI_CIO_IRQ_ULPSACTIVENOT_ALL0); |
| 3480 | return r; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3481 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3482 | |
Tomi Valkeinen | 4ffa357 | 2010-04-12 10:40:12 +0300 | [diff] [blame] | 3483 | static void dsi_set_lp_rx_timeout(struct platform_device *dsidev, |
| 3484 | unsigned ticks, bool x4, bool x16) |
| 3485 | { |
| 3486 | unsigned long fck; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3487 | unsigned long total_ticks; |
| 3488 | u32 r; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3489 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3490 | BUG_ON(ticks > 0x1fff); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3491 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3492 | /* ticks in DSI_FCK */ |
Tomi Valkeinen | 4ffa357 | 2010-04-12 10:40:12 +0300 | [diff] [blame] | 3493 | fck = dsi_fclk_rate(dsidev); |
| 3494 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3495 | r = dsi_read_reg(dsidev, DSI_TIMING2); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3496 | r = FLD_MOD(r, 1, 15, 15); /* LP_RX_TO */ |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3497 | 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] | 3498 | r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* LP_RX_TO_X4 */ |
| 3499 | r = FLD_MOD(r, ticks, 12, 0); /* LP_RX_COUNTER */ |
| 3500 | dsi_write_reg(dsidev, DSI_TIMING2, r); |
| 3501 | |
| 3502 | total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1); |
| 3503 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3504 | DSSDBG("LP_RX_TO %lu ticks (%#x%s%s) = %lu ns\n", |
| 3505 | total_ticks, |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3506 | ticks, x4 ? " x4" : "", x16 ? " x16" : "", |
| 3507 | (total_ticks * 1000) / (fck / 1000 / 1000)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3508 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3509 | |
Tomi Valkeinen | 4ffa357 | 2010-04-12 10:40:12 +0300 | [diff] [blame] | 3510 | static void dsi_set_ta_timeout(struct platform_device *dsidev, unsigned ticks, |
| 3511 | bool x8, bool x16) |
| 3512 | { |
| 3513 | unsigned long fck; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3514 | unsigned long total_ticks; |
| 3515 | u32 r; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3516 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3517 | BUG_ON(ticks > 0x1fff); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3518 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3519 | /* ticks in DSI_FCK */ |
Tomi Valkeinen | 4ffa357 | 2010-04-12 10:40:12 +0300 | [diff] [blame] | 3520 | fck = dsi_fclk_rate(dsidev); |
| 3521 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3522 | r = dsi_read_reg(dsidev, DSI_TIMING1); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3523 | r = FLD_MOD(r, 1, 31, 31); /* TA_TO */ |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3524 | r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* TA_TO_X16 */ |
Tomi Valkeinen | 4ffa357 | 2010-04-12 10:40:12 +0300 | [diff] [blame] | 3525 | r = FLD_MOD(r, x8 ? 1 : 0, 29, 29); /* TA_TO_X8 */ |
| 3526 | r = FLD_MOD(r, ticks, 28, 16); /* TA_TO_COUNTER */ |
| 3527 | dsi_write_reg(dsidev, DSI_TIMING1, r); |
| 3528 | |
| 3529 | total_ticks = ticks * (x16 ? 16 : 1) * (x8 ? 8 : 1); |
| 3530 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3531 | DSSDBG("TA_TO %lu ticks (%#x%s%s) = %lu ns\n", |
| 3532 | total_ticks, |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3533 | ticks, x8 ? " x8" : "", x16 ? " x16" : "", |
| 3534 | (total_ticks * 1000) / (fck / 1000 / 1000)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3535 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3536 | |
Tomi Valkeinen | 4ffa357 | 2010-04-12 10:40:12 +0300 | [diff] [blame] | 3537 | static void dsi_set_stop_state_counter(struct platform_device *dsidev, |
| 3538 | unsigned ticks, bool x4, bool x16) |
| 3539 | { |
| 3540 | unsigned long fck; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3541 | unsigned long total_ticks; |
| 3542 | u32 r; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3543 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3544 | BUG_ON(ticks > 0x1fff); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3545 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3546 | /* ticks in DSI_FCK */ |
Tomi Valkeinen | 4ffa357 | 2010-04-12 10:40:12 +0300 | [diff] [blame] | 3547 | fck = dsi_fclk_rate(dsidev); |
| 3548 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3549 | r = dsi_read_reg(dsidev, DSI_TIMING1); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3550 | r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */ |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3551 | 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] | 3552 | r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* STOP_STATE_X4_IO */ |
| 3553 | r = FLD_MOD(r, ticks, 12, 0); /* STOP_STATE_COUNTER_IO */ |
| 3554 | dsi_write_reg(dsidev, DSI_TIMING1, r); |
| 3555 | |
| 3556 | total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1); |
| 3557 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3558 | DSSDBG("STOP_STATE_COUNTER %lu ticks (%#x%s%s) = %lu ns\n", |
| 3559 | total_ticks, |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3560 | ticks, x4 ? " x4" : "", x16 ? " x16" : "", |
| 3561 | (total_ticks * 1000) / (fck / 1000 / 1000)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3562 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3563 | |
Tomi Valkeinen | 4ffa357 | 2010-04-12 10:40:12 +0300 | [diff] [blame] | 3564 | static void dsi_set_hs_tx_timeout(struct platform_device *dsidev, |
| 3565 | unsigned ticks, bool x4, bool x16) |
| 3566 | { |
| 3567 | unsigned long fck; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3568 | unsigned long total_ticks; |
| 3569 | u32 r; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3570 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3571 | BUG_ON(ticks > 0x1fff); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3572 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3573 | /* ticks in TxByteClkHS */ |
Tomi Valkeinen | 4ffa357 | 2010-04-12 10:40:12 +0300 | [diff] [blame] | 3574 | fck = dsi_get_txbyteclkhs(dsidev); |
| 3575 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3576 | r = dsi_read_reg(dsidev, DSI_TIMING2); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3577 | r = FLD_MOD(r, 1, 31, 31); /* HS_TX_TO */ |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3578 | 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] | 3579 | r = FLD_MOD(r, x4 ? 1 : 0, 29, 29); /* HS_TX_TO_X8 (4 really) */ |
| 3580 | r = FLD_MOD(r, ticks, 28, 16); /* HS_TX_TO_COUNTER */ |
| 3581 | dsi_write_reg(dsidev, DSI_TIMING2, r); |
| 3582 | |
| 3583 | total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1); |
| 3584 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3585 | DSSDBG("HS_TX_TO %lu ticks (%#x%s%s) = %lu ns\n", |
| 3586 | total_ticks, |
| 3587 | ticks, x4 ? " x4" : "", x16 ? " x16" : "", |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3588 | (total_ticks * 1000) / (fck / 1000 / 1000)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3589 | } |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3590 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 3591 | static void dsi_config_vp_num_line_buffers(struct platform_device *dsidev) |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3592 | { |
Archit Taneja | dca2b15 | 2012-08-16 18:02:00 +0530 | [diff] [blame] | 3593 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3594 | int num_line_buffers; |
| 3595 | |
Archit Taneja | dca2b15 | 2012-08-16 18:02:00 +0530 | [diff] [blame] | 3596 | if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) { |
Archit Taneja | 02c3960 | 2012-08-10 15:01:33 +0530 | [diff] [blame] | 3597 | int bpp = dsi_get_pixel_size(dsi->pix_fmt); |
Archit Taneja | e67458a | 2012-08-13 14:17:30 +0530 | [diff] [blame] | 3598 | struct omap_video_timings *timings = &dsi->timings; |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3599 | /* |
| 3600 | * Don't use line buffers if width is greater than the video |
| 3601 | * port's line buffer size |
| 3602 | */ |
Tomi Valkeinen | 9932257 | 2013-03-05 10:37:02 +0200 | [diff] [blame] | 3603 | if (dsi->line_buffer_size <= timings->x_res * bpp / 8) |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3604 | num_line_buffers = 0; |
| 3605 | else |
| 3606 | num_line_buffers = 2; |
| 3607 | } else { |
| 3608 | /* Use maximum number of line buffers in command mode */ |
| 3609 | num_line_buffers = 2; |
| 3610 | } |
| 3611 | |
| 3612 | /* LINE_BUFFER */ |
| 3613 | REG_FLD_MOD(dsidev, DSI_CTRL, num_line_buffers, 13, 12); |
| 3614 | } |
| 3615 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 3616 | static void dsi_config_vp_sync_events(struct platform_device *dsidev) |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3617 | { |
Archit Taneja | 0b3ffe3 | 2012-08-13 22:13:39 +0530 | [diff] [blame] | 3618 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 478d7df | 2013-03-05 16:29:36 +0200 | [diff] [blame] | 3619 | bool sync_end; |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3620 | u32 r; |
| 3621 | |
Tomi Valkeinen | 478d7df | 2013-03-05 16:29:36 +0200 | [diff] [blame] | 3622 | if (dsi->vm_timings.trans_mode == OMAP_DSS_DSI_PULSE_MODE) |
| 3623 | sync_end = true; |
| 3624 | else |
| 3625 | sync_end = false; |
| 3626 | |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3627 | r = dsi_read_reg(dsidev, DSI_CTRL); |
Archit Taneja | bd5a7b1 | 2012-06-26 12:38:31 +0530 | [diff] [blame] | 3628 | r = FLD_MOD(r, 1, 9, 9); /* VP_DE_POL */ |
| 3629 | r = FLD_MOD(r, 1, 10, 10); /* VP_HSYNC_POL */ |
| 3630 | r = FLD_MOD(r, 1, 11, 11); /* VP_VSYNC_POL */ |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3631 | r = FLD_MOD(r, 1, 15, 15); /* VP_VSYNC_START */ |
Tomi Valkeinen | 478d7df | 2013-03-05 16:29:36 +0200 | [diff] [blame] | 3632 | r = FLD_MOD(r, sync_end, 16, 16); /* VP_VSYNC_END */ |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3633 | r = FLD_MOD(r, 1, 17, 17); /* VP_HSYNC_START */ |
Tomi Valkeinen | 478d7df | 2013-03-05 16:29:36 +0200 | [diff] [blame] | 3634 | r = FLD_MOD(r, sync_end, 18, 18); /* VP_HSYNC_END */ |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3635 | dsi_write_reg(dsidev, DSI_CTRL, r); |
| 3636 | } |
| 3637 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 3638 | static void dsi_config_blanking_modes(struct platform_device *dsidev) |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3639 | { |
Archit Taneja | 0b3ffe3 | 2012-08-13 22:13:39 +0530 | [diff] [blame] | 3640 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 3641 | int blanking_mode = dsi->vm_timings.blanking_mode; |
| 3642 | int hfp_blanking_mode = dsi->vm_timings.hfp_blanking_mode; |
| 3643 | int hbp_blanking_mode = dsi->vm_timings.hbp_blanking_mode; |
| 3644 | int hsa_blanking_mode = dsi->vm_timings.hsa_blanking_mode; |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3645 | u32 r; |
| 3646 | |
| 3647 | /* |
| 3648 | * 0 = TX FIFO packets sent or LPS in corresponding blanking periods |
| 3649 | * 1 = Long blanking packets are sent in corresponding blanking periods |
| 3650 | */ |
| 3651 | r = dsi_read_reg(dsidev, DSI_CTRL); |
| 3652 | r = FLD_MOD(r, blanking_mode, 20, 20); /* BLANKING_MODE */ |
| 3653 | r = FLD_MOD(r, hfp_blanking_mode, 21, 21); /* HFP_BLANKING */ |
| 3654 | r = FLD_MOD(r, hbp_blanking_mode, 22, 22); /* HBP_BLANKING */ |
| 3655 | r = FLD_MOD(r, hsa_blanking_mode, 23, 23); /* HSA_BLANKING */ |
| 3656 | dsi_write_reg(dsidev, DSI_CTRL, r); |
| 3657 | } |
| 3658 | |
Archit Taneja | 6f28c29 | 2012-05-15 11:32:18 +0530 | [diff] [blame] | 3659 | /* |
| 3660 | * According to section 'HS Command Mode Interleaving' in OMAP TRM, Scenario 3 |
| 3661 | * results in maximum transition time for data and clock lanes to enter and |
| 3662 | * exit HS mode. Hence, this is the scenario where the least amount of command |
| 3663 | * mode data can be interleaved. We program the minimum amount of TXBYTECLKHS |
| 3664 | * clock cycles that can be used to interleave command mode data in HS so that |
| 3665 | * all scenarios are satisfied. |
| 3666 | */ |
| 3667 | static int dsi_compute_interleave_hs(int blank, bool ddr_alwon, int enter_hs, |
| 3668 | int exit_hs, int exiths_clk, int ddr_pre, int ddr_post) |
| 3669 | { |
| 3670 | int transition; |
| 3671 | |
| 3672 | /* |
| 3673 | * If DDR_CLK_ALWAYS_ON is set, we need to consider HS mode transition |
| 3674 | * time of data lanes only, if it isn't set, we need to consider HS |
| 3675 | * transition time of both data and clock lanes. HS transition time |
| 3676 | * of Scenario 3 is considered. |
| 3677 | */ |
| 3678 | if (ddr_alwon) { |
| 3679 | transition = enter_hs + exit_hs + max(enter_hs, 2) + 1; |
| 3680 | } else { |
| 3681 | int trans1, trans2; |
| 3682 | trans1 = ddr_pre + enter_hs + exit_hs + max(enter_hs, 2) + 1; |
| 3683 | trans2 = ddr_pre + enter_hs + exiths_clk + ddr_post + ddr_pre + |
| 3684 | enter_hs + 1; |
| 3685 | transition = max(trans1, trans2); |
| 3686 | } |
| 3687 | |
| 3688 | return blank > transition ? blank - transition : 0; |
| 3689 | } |
| 3690 | |
| 3691 | /* |
| 3692 | * According to section 'LP Command Mode Interleaving' in OMAP TRM, Scenario 1 |
| 3693 | * results in maximum transition time for data lanes to enter and exit LP mode. |
| 3694 | * Hence, this is the scenario where the least amount of command mode data can |
| 3695 | * be interleaved. We program the minimum amount of bytes that can be |
| 3696 | * interleaved in LP so that all scenarios are satisfied. |
| 3697 | */ |
| 3698 | static int dsi_compute_interleave_lp(int blank, int enter_hs, int exit_hs, |
| 3699 | int lp_clk_div, int tdsi_fclk) |
| 3700 | { |
| 3701 | int trans_lp; /* time required for a LP transition, in TXBYTECLKHS */ |
| 3702 | int tlp_avail; /* time left for interleaving commands, in CLKIN4DDR */ |
| 3703 | int ttxclkesc; /* period of LP transmit escape clock, in CLKIN4DDR */ |
| 3704 | int thsbyte_clk = 16; /* Period of TXBYTECLKHS clock, in CLKIN4DDR */ |
| 3705 | int lp_inter; /* cmd mode data that can be interleaved, in bytes */ |
| 3706 | |
| 3707 | /* maximum LP transition time according to Scenario 1 */ |
| 3708 | trans_lp = exit_hs + max(enter_hs, 2) + 1; |
| 3709 | |
| 3710 | /* CLKIN4DDR = 16 * TXBYTECLKHS */ |
| 3711 | tlp_avail = thsbyte_clk * (blank - trans_lp); |
| 3712 | |
Archit Taneja | 2e063c3 | 2012-06-04 13:36:34 +0530 | [diff] [blame] | 3713 | ttxclkesc = tdsi_fclk * lp_clk_div; |
Archit Taneja | 6f28c29 | 2012-05-15 11:32:18 +0530 | [diff] [blame] | 3714 | |
| 3715 | lp_inter = ((tlp_avail - 8 * thsbyte_clk - 5 * tdsi_fclk) / ttxclkesc - |
| 3716 | 26) / 16; |
| 3717 | |
| 3718 | return max(lp_inter, 0); |
| 3719 | } |
| 3720 | |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 3721 | static void dsi_config_cmd_mode_interleaving(struct platform_device *dsidev) |
Archit Taneja | 6f28c29 | 2012-05-15 11:32:18 +0530 | [diff] [blame] | 3722 | { |
Archit Taneja | 6f28c29 | 2012-05-15 11:32:18 +0530 | [diff] [blame] | 3723 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 3724 | int blanking_mode; |
| 3725 | int hfp_blanking_mode, hbp_blanking_mode, hsa_blanking_mode; |
| 3726 | int hsa, hfp, hbp, width_bytes, bllp, lp_clk_div; |
| 3727 | int ddr_clk_pre, ddr_clk_post, enter_hs_mode_lat, exit_hs_mode_lat; |
| 3728 | int tclk_trail, ths_exit, exiths_clk; |
| 3729 | bool ddr_alwon; |
Archit Taneja | e67458a | 2012-08-13 14:17:30 +0530 | [diff] [blame] | 3730 | struct omap_video_timings *timings = &dsi->timings; |
Archit Taneja | 02c3960 | 2012-08-10 15:01:33 +0530 | [diff] [blame] | 3731 | int bpp = dsi_get_pixel_size(dsi->pix_fmt); |
Archit Taneja | 6f28c29 | 2012-05-15 11:32:18 +0530 | [diff] [blame] | 3732 | int ndl = dsi->num_lanes_used - 1; |
Tomi Valkeinen | a0d269e | 2012-11-27 17:05:54 +0200 | [diff] [blame] | 3733 | int dsi_fclk_hsdiv = dsi->user_dsi_cinfo.regm_dsi + 1; |
Archit Taneja | 6f28c29 | 2012-05-15 11:32:18 +0530 | [diff] [blame] | 3734 | int hsa_interleave_hs = 0, hsa_interleave_lp = 0; |
| 3735 | int hfp_interleave_hs = 0, hfp_interleave_lp = 0; |
| 3736 | int hbp_interleave_hs = 0, hbp_interleave_lp = 0; |
| 3737 | int bl_interleave_hs = 0, bl_interleave_lp = 0; |
| 3738 | u32 r; |
| 3739 | |
| 3740 | r = dsi_read_reg(dsidev, DSI_CTRL); |
| 3741 | blanking_mode = FLD_GET(r, 20, 20); |
| 3742 | hfp_blanking_mode = FLD_GET(r, 21, 21); |
| 3743 | hbp_blanking_mode = FLD_GET(r, 22, 22); |
| 3744 | hsa_blanking_mode = FLD_GET(r, 23, 23); |
| 3745 | |
| 3746 | r = dsi_read_reg(dsidev, DSI_VM_TIMING1); |
| 3747 | hbp = FLD_GET(r, 11, 0); |
| 3748 | hfp = FLD_GET(r, 23, 12); |
| 3749 | hsa = FLD_GET(r, 31, 24); |
| 3750 | |
| 3751 | r = dsi_read_reg(dsidev, DSI_CLK_TIMING); |
| 3752 | ddr_clk_post = FLD_GET(r, 7, 0); |
| 3753 | ddr_clk_pre = FLD_GET(r, 15, 8); |
| 3754 | |
| 3755 | r = dsi_read_reg(dsidev, DSI_VM_TIMING7); |
| 3756 | exit_hs_mode_lat = FLD_GET(r, 15, 0); |
| 3757 | enter_hs_mode_lat = FLD_GET(r, 31, 16); |
| 3758 | |
| 3759 | r = dsi_read_reg(dsidev, DSI_CLK_CTRL); |
| 3760 | lp_clk_div = FLD_GET(r, 12, 0); |
| 3761 | ddr_alwon = FLD_GET(r, 13, 13); |
| 3762 | |
| 3763 | r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0); |
| 3764 | ths_exit = FLD_GET(r, 7, 0); |
| 3765 | |
| 3766 | r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1); |
| 3767 | tclk_trail = FLD_GET(r, 15, 8); |
| 3768 | |
| 3769 | exiths_clk = ths_exit + tclk_trail; |
| 3770 | |
| 3771 | width_bytes = DIV_ROUND_UP(timings->x_res * bpp, 8); |
| 3772 | bllp = hbp + hfp + hsa + DIV_ROUND_UP(width_bytes + 6, ndl); |
| 3773 | |
| 3774 | if (!hsa_blanking_mode) { |
| 3775 | hsa_interleave_hs = dsi_compute_interleave_hs(hsa, ddr_alwon, |
| 3776 | enter_hs_mode_lat, exit_hs_mode_lat, |
| 3777 | exiths_clk, ddr_clk_pre, ddr_clk_post); |
| 3778 | hsa_interleave_lp = dsi_compute_interleave_lp(hsa, |
| 3779 | enter_hs_mode_lat, exit_hs_mode_lat, |
| 3780 | lp_clk_div, dsi_fclk_hsdiv); |
| 3781 | } |
| 3782 | |
| 3783 | if (!hfp_blanking_mode) { |
| 3784 | hfp_interleave_hs = dsi_compute_interleave_hs(hfp, ddr_alwon, |
| 3785 | enter_hs_mode_lat, exit_hs_mode_lat, |
| 3786 | exiths_clk, ddr_clk_pre, ddr_clk_post); |
| 3787 | hfp_interleave_lp = dsi_compute_interleave_lp(hfp, |
| 3788 | enter_hs_mode_lat, exit_hs_mode_lat, |
| 3789 | lp_clk_div, dsi_fclk_hsdiv); |
| 3790 | } |
| 3791 | |
| 3792 | if (!hbp_blanking_mode) { |
| 3793 | hbp_interleave_hs = dsi_compute_interleave_hs(hbp, ddr_alwon, |
| 3794 | enter_hs_mode_lat, exit_hs_mode_lat, |
| 3795 | exiths_clk, ddr_clk_pre, ddr_clk_post); |
| 3796 | |
| 3797 | hbp_interleave_lp = dsi_compute_interleave_lp(hbp, |
| 3798 | enter_hs_mode_lat, exit_hs_mode_lat, |
| 3799 | lp_clk_div, dsi_fclk_hsdiv); |
| 3800 | } |
| 3801 | |
| 3802 | if (!blanking_mode) { |
| 3803 | bl_interleave_hs = dsi_compute_interleave_hs(bllp, ddr_alwon, |
| 3804 | enter_hs_mode_lat, exit_hs_mode_lat, |
| 3805 | exiths_clk, ddr_clk_pre, ddr_clk_post); |
| 3806 | |
| 3807 | bl_interleave_lp = dsi_compute_interleave_lp(bllp, |
| 3808 | enter_hs_mode_lat, exit_hs_mode_lat, |
| 3809 | lp_clk_div, dsi_fclk_hsdiv); |
| 3810 | } |
| 3811 | |
| 3812 | DSSDBG("DSI HS interleaving(TXBYTECLKHS) HSA %d, HFP %d, HBP %d, BLLP %d\n", |
| 3813 | hsa_interleave_hs, hfp_interleave_hs, hbp_interleave_hs, |
| 3814 | bl_interleave_hs); |
| 3815 | |
| 3816 | DSSDBG("DSI LP interleaving(bytes) HSA %d, HFP %d, HBP %d, BLLP %d\n", |
| 3817 | hsa_interleave_lp, hfp_interleave_lp, hbp_interleave_lp, |
| 3818 | bl_interleave_lp); |
| 3819 | |
| 3820 | r = dsi_read_reg(dsidev, DSI_VM_TIMING4); |
| 3821 | r = FLD_MOD(r, hsa_interleave_hs, 23, 16); |
| 3822 | r = FLD_MOD(r, hfp_interleave_hs, 15, 8); |
| 3823 | r = FLD_MOD(r, hbp_interleave_hs, 7, 0); |
| 3824 | dsi_write_reg(dsidev, DSI_VM_TIMING4, r); |
| 3825 | |
| 3826 | r = dsi_read_reg(dsidev, DSI_VM_TIMING5); |
| 3827 | r = FLD_MOD(r, hsa_interleave_lp, 23, 16); |
| 3828 | r = FLD_MOD(r, hfp_interleave_lp, 15, 8); |
| 3829 | r = FLD_MOD(r, hbp_interleave_lp, 7, 0); |
| 3830 | dsi_write_reg(dsidev, DSI_VM_TIMING5, r); |
| 3831 | |
| 3832 | r = dsi_read_reg(dsidev, DSI_VM_TIMING6); |
| 3833 | r = FLD_MOD(r, bl_interleave_hs, 31, 15); |
| 3834 | r = FLD_MOD(r, bl_interleave_lp, 16, 0); |
| 3835 | dsi_write_reg(dsidev, DSI_VM_TIMING6, r); |
| 3836 | } |
| 3837 | |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 3838 | static int dsi_proto_config(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3839 | { |
Archit Taneja | 02c3960 | 2012-08-10 15:01:33 +0530 | [diff] [blame] | 3840 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3841 | u32 r; |
| 3842 | int buswidth = 0; |
| 3843 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3844 | dsi_config_tx_fifo(dsidev, DSI_FIFO_SIZE_32, |
Tomi Valkeinen | dd8079d | 2009-12-16 16:49:03 +0200 | [diff] [blame] | 3845 | DSI_FIFO_SIZE_32, |
| 3846 | DSI_FIFO_SIZE_32, |
| 3847 | DSI_FIFO_SIZE_32); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3848 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3849 | dsi_config_rx_fifo(dsidev, DSI_FIFO_SIZE_32, |
Tomi Valkeinen | dd8079d | 2009-12-16 16:49:03 +0200 | [diff] [blame] | 3850 | DSI_FIFO_SIZE_32, |
| 3851 | DSI_FIFO_SIZE_32, |
| 3852 | DSI_FIFO_SIZE_32); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3853 | |
| 3854 | /* XXX what values for the timeouts? */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3855 | dsi_set_stop_state_counter(dsidev, 0x1000, false, false); |
| 3856 | dsi_set_ta_timeout(dsidev, 0x1fff, true, true); |
| 3857 | dsi_set_lp_rx_timeout(dsidev, 0x1fff, true, true); |
| 3858 | dsi_set_hs_tx_timeout(dsidev, 0x1fff, true, true); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3859 | |
Archit Taneja | 02c3960 | 2012-08-10 15:01:33 +0530 | [diff] [blame] | 3860 | switch (dsi_get_pixel_size(dsi->pix_fmt)) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3861 | case 16: |
| 3862 | buswidth = 0; |
| 3863 | break; |
| 3864 | case 18: |
| 3865 | buswidth = 1; |
| 3866 | break; |
| 3867 | case 24: |
| 3868 | buswidth = 2; |
| 3869 | break; |
| 3870 | default: |
| 3871 | BUG(); |
Tomi Valkeinen | c6eee96 | 2012-05-18 11:47:02 +0300 | [diff] [blame] | 3872 | return -EINVAL; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3873 | } |
| 3874 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3875 | r = dsi_read_reg(dsidev, DSI_CTRL); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3876 | r = FLD_MOD(r, 1, 1, 1); /* CS_RX_EN */ |
| 3877 | r = FLD_MOD(r, 1, 2, 2); /* ECC_RX_EN */ |
| 3878 | r = FLD_MOD(r, 1, 3, 3); /* TX_FIFO_ARBITRATION */ |
| 3879 | r = FLD_MOD(r, 1, 4, 4); /* VP_CLK_RATIO, always 1, see errata*/ |
| 3880 | r = FLD_MOD(r, buswidth, 7, 6); /* VP_DATA_BUS_WIDTH */ |
| 3881 | r = FLD_MOD(r, 0, 8, 8); /* VP_CLK_POL */ |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3882 | r = FLD_MOD(r, 1, 14, 14); /* TRIGGER_RESET_MODE */ |
| 3883 | r = FLD_MOD(r, 1, 19, 19); /* EOT_ENABLE */ |
Archit Taneja | 9613c02 | 2011-03-22 06:33:36 -0500 | [diff] [blame] | 3884 | if (!dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC)) { |
| 3885 | r = FLD_MOD(r, 1, 24, 24); /* DCS_CMD_ENABLE */ |
| 3886 | /* DCS_CMD_CODE, 1=start, 0=continue */ |
| 3887 | r = FLD_MOD(r, 0, 25, 25); |
| 3888 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3889 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3890 | dsi_write_reg(dsidev, DSI_CTRL, r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3891 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 3892 | dsi_config_vp_num_line_buffers(dsidev); |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3893 | |
Archit Taneja | dca2b15 | 2012-08-16 18:02:00 +0530 | [diff] [blame] | 3894 | if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) { |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 3895 | dsi_config_vp_sync_events(dsidev); |
| 3896 | dsi_config_blanking_modes(dsidev); |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 3897 | dsi_config_cmd_mode_interleaving(dsidev); |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3898 | } |
| 3899 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3900 | dsi_vc_initial_config(dsidev, 0); |
| 3901 | dsi_vc_initial_config(dsidev, 1); |
| 3902 | dsi_vc_initial_config(dsidev, 2); |
| 3903 | dsi_vc_initial_config(dsidev, 3); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3904 | |
| 3905 | return 0; |
| 3906 | } |
| 3907 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 3908 | static void dsi_proto_timings(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3909 | { |
Tomi Valkeinen | db18644 | 2011-10-13 16:12:29 +0300 | [diff] [blame] | 3910 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3911 | unsigned tlpx, tclk_zero, tclk_prepare, tclk_trail; |
| 3912 | unsigned tclk_pre, tclk_post; |
| 3913 | unsigned ths_prepare, ths_prepare_ths_zero, ths_zero; |
| 3914 | unsigned ths_trail, ths_exit; |
| 3915 | unsigned ddr_clk_pre, ddr_clk_post; |
| 3916 | unsigned enter_hs_mode_lat, exit_hs_mode_lat; |
| 3917 | unsigned ths_eot; |
Tomi Valkeinen | db18644 | 2011-10-13 16:12:29 +0300 | [diff] [blame] | 3918 | int ndl = dsi->num_lanes_used - 1; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3919 | u32 r; |
| 3920 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3921 | r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3922 | ths_prepare = FLD_GET(r, 31, 24); |
| 3923 | ths_prepare_ths_zero = FLD_GET(r, 23, 16); |
| 3924 | ths_zero = ths_prepare_ths_zero - ths_prepare; |
| 3925 | ths_trail = FLD_GET(r, 15, 8); |
| 3926 | ths_exit = FLD_GET(r, 7, 0); |
| 3927 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3928 | r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1); |
Tomi Valkeinen | e84dc1c | 2012-09-24 09:34:52 +0300 | [diff] [blame] | 3929 | tlpx = FLD_GET(r, 20, 16) * 2; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3930 | tclk_trail = FLD_GET(r, 15, 8); |
| 3931 | tclk_zero = FLD_GET(r, 7, 0); |
| 3932 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3933 | r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG2); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3934 | tclk_prepare = FLD_GET(r, 7, 0); |
| 3935 | |
| 3936 | /* min 8*UI */ |
| 3937 | tclk_pre = 20; |
| 3938 | /* min 60ns + 52*UI */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3939 | tclk_post = ns2ddr(dsidev, 60) + 26; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3940 | |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3941 | ths_eot = DIV_ROUND_UP(4, ndl); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3942 | |
| 3943 | ddr_clk_pre = DIV_ROUND_UP(tclk_pre + tlpx + tclk_zero + tclk_prepare, |
| 3944 | 4); |
| 3945 | ddr_clk_post = DIV_ROUND_UP(tclk_post + ths_trail, 4) + ths_eot; |
| 3946 | |
| 3947 | BUG_ON(ddr_clk_pre == 0 || ddr_clk_pre > 255); |
| 3948 | BUG_ON(ddr_clk_post == 0 || ddr_clk_post > 255); |
| 3949 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3950 | r = dsi_read_reg(dsidev, DSI_CLK_TIMING); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3951 | r = FLD_MOD(r, ddr_clk_pre, 15, 8); |
| 3952 | r = FLD_MOD(r, ddr_clk_post, 7, 0); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3953 | dsi_write_reg(dsidev, DSI_CLK_TIMING, r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3954 | |
| 3955 | DSSDBG("ddr_clk_pre %u, ddr_clk_post %u\n", |
| 3956 | ddr_clk_pre, |
| 3957 | ddr_clk_post); |
| 3958 | |
| 3959 | enter_hs_mode_lat = 1 + DIV_ROUND_UP(tlpx, 4) + |
| 3960 | DIV_ROUND_UP(ths_prepare, 4) + |
| 3961 | DIV_ROUND_UP(ths_zero + 3, 4); |
| 3962 | |
| 3963 | exit_hs_mode_lat = DIV_ROUND_UP(ths_trail + ths_exit, 4) + 1 + ths_eot; |
| 3964 | |
| 3965 | r = FLD_VAL(enter_hs_mode_lat, 31, 16) | |
| 3966 | FLD_VAL(exit_hs_mode_lat, 15, 0); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 3967 | dsi_write_reg(dsidev, DSI_VM_TIMING7, r); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 3968 | |
| 3969 | DSSDBG("enter_hs_mode_lat %u, exit_hs_mode_lat %u\n", |
| 3970 | enter_hs_mode_lat, exit_hs_mode_lat); |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3971 | |
Archit Taneja | dca2b15 | 2012-08-16 18:02:00 +0530 | [diff] [blame] | 3972 | if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) { |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3973 | /* TODO: Implement a video mode check_timings function */ |
Archit Taneja | 0b3ffe3 | 2012-08-13 22:13:39 +0530 | [diff] [blame] | 3974 | int hsa = dsi->vm_timings.hsa; |
| 3975 | int hfp = dsi->vm_timings.hfp; |
| 3976 | int hbp = dsi->vm_timings.hbp; |
| 3977 | int vsa = dsi->vm_timings.vsa; |
| 3978 | int vfp = dsi->vm_timings.vfp; |
| 3979 | int vbp = dsi->vm_timings.vbp; |
| 3980 | int window_sync = dsi->vm_timings.window_sync; |
Tomi Valkeinen | 478d7df | 2013-03-05 16:29:36 +0200 | [diff] [blame] | 3981 | bool hsync_end; |
Archit Taneja | e67458a | 2012-08-13 14:17:30 +0530 | [diff] [blame] | 3982 | struct omap_video_timings *timings = &dsi->timings; |
Archit Taneja | 02c3960 | 2012-08-10 15:01:33 +0530 | [diff] [blame] | 3983 | int bpp = dsi_get_pixel_size(dsi->pix_fmt); |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3984 | int tl, t_he, width_bytes; |
| 3985 | |
Tomi Valkeinen | 478d7df | 2013-03-05 16:29:36 +0200 | [diff] [blame] | 3986 | hsync_end = dsi->vm_timings.trans_mode == OMAP_DSS_DSI_PULSE_MODE; |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 3987 | t_he = hsync_end ? |
| 3988 | ((hsa == 0 && ndl == 3) ? 1 : DIV_ROUND_UP(4, ndl)) : 0; |
| 3989 | |
| 3990 | width_bytes = DIV_ROUND_UP(timings->x_res * bpp, 8); |
| 3991 | |
| 3992 | /* TL = t_HS + HSA + t_HE + HFP + ceil((WC + 6) / NDL) + HBP */ |
| 3993 | tl = DIV_ROUND_UP(4, ndl) + (hsync_end ? hsa : 0) + t_he + hfp + |
| 3994 | DIV_ROUND_UP(width_bytes + 6, ndl) + hbp; |
| 3995 | |
| 3996 | DSSDBG("HBP: %d, HFP: %d, HSA: %d, TL: %d TXBYTECLKHS\n", hbp, |
| 3997 | hfp, hsync_end ? hsa : 0, tl); |
| 3998 | DSSDBG("VBP: %d, VFP: %d, VSA: %d, VACT: %d lines\n", vbp, vfp, |
| 3999 | vsa, timings->y_res); |
| 4000 | |
| 4001 | r = dsi_read_reg(dsidev, DSI_VM_TIMING1); |
| 4002 | r = FLD_MOD(r, hbp, 11, 0); /* HBP */ |
| 4003 | r = FLD_MOD(r, hfp, 23, 12); /* HFP */ |
| 4004 | r = FLD_MOD(r, hsync_end ? hsa : 0, 31, 24); /* HSA */ |
| 4005 | dsi_write_reg(dsidev, DSI_VM_TIMING1, r); |
| 4006 | |
| 4007 | r = dsi_read_reg(dsidev, DSI_VM_TIMING2); |
| 4008 | r = FLD_MOD(r, vbp, 7, 0); /* VBP */ |
| 4009 | r = FLD_MOD(r, vfp, 15, 8); /* VFP */ |
| 4010 | r = FLD_MOD(r, vsa, 23, 16); /* VSA */ |
| 4011 | r = FLD_MOD(r, window_sync, 27, 24); /* WINDOW_SYNC */ |
| 4012 | dsi_write_reg(dsidev, DSI_VM_TIMING2, r); |
| 4013 | |
| 4014 | r = dsi_read_reg(dsidev, DSI_VM_TIMING3); |
| 4015 | r = FLD_MOD(r, timings->y_res, 14, 0); /* VACT */ |
| 4016 | r = FLD_MOD(r, tl, 31, 16); /* TL */ |
| 4017 | dsi_write_reg(dsidev, DSI_VM_TIMING3, r); |
| 4018 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4019 | } |
| 4020 | |
Tomi Valkeinen | 5cfc1c3 | 2013-05-15 11:24:30 +0300 | [diff] [blame] | 4021 | static int dsi_configure_pins(struct omap_dss_device *dssdev, |
Tomi Valkeinen | e4a9e94 | 2012-03-28 15:58:56 +0300 | [diff] [blame] | 4022 | const struct omap_dsi_pin_config *pin_cfg) |
| 4023 | { |
| 4024 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 4025 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 4026 | int num_pins; |
| 4027 | const int *pins; |
| 4028 | struct dsi_lane_config lanes[DSI_MAX_NR_LANES]; |
| 4029 | int num_lanes; |
| 4030 | int i; |
| 4031 | |
| 4032 | static const enum dsi_lane_function functions[] = { |
| 4033 | DSI_LANE_CLK, |
| 4034 | DSI_LANE_DATA1, |
| 4035 | DSI_LANE_DATA2, |
| 4036 | DSI_LANE_DATA3, |
| 4037 | DSI_LANE_DATA4, |
| 4038 | }; |
| 4039 | |
| 4040 | num_pins = pin_cfg->num_pins; |
| 4041 | pins = pin_cfg->pins; |
| 4042 | |
| 4043 | if (num_pins < 4 || num_pins > dsi->num_lanes_supported * 2 |
| 4044 | || num_pins % 2 != 0) |
| 4045 | return -EINVAL; |
| 4046 | |
| 4047 | for (i = 0; i < DSI_MAX_NR_LANES; ++i) |
| 4048 | lanes[i].function = DSI_LANE_UNUSED; |
| 4049 | |
| 4050 | num_lanes = 0; |
| 4051 | |
| 4052 | for (i = 0; i < num_pins; i += 2) { |
| 4053 | u8 lane, pol; |
| 4054 | int dx, dy; |
| 4055 | |
| 4056 | dx = pins[i]; |
| 4057 | dy = pins[i + 1]; |
| 4058 | |
| 4059 | if (dx < 0 || dx >= dsi->num_lanes_supported * 2) |
| 4060 | return -EINVAL; |
| 4061 | |
| 4062 | if (dy < 0 || dy >= dsi->num_lanes_supported * 2) |
| 4063 | return -EINVAL; |
| 4064 | |
| 4065 | if (dx & 1) { |
| 4066 | if (dy != dx - 1) |
| 4067 | return -EINVAL; |
| 4068 | pol = 1; |
| 4069 | } else { |
| 4070 | if (dy != dx + 1) |
| 4071 | return -EINVAL; |
| 4072 | pol = 0; |
| 4073 | } |
| 4074 | |
| 4075 | lane = dx / 2; |
| 4076 | |
| 4077 | lanes[lane].function = functions[i / 2]; |
| 4078 | lanes[lane].polarity = pol; |
| 4079 | num_lanes++; |
| 4080 | } |
| 4081 | |
| 4082 | memcpy(dsi->lanes, lanes, sizeof(dsi->lanes)); |
| 4083 | dsi->num_lanes_used = num_lanes; |
| 4084 | |
| 4085 | return 0; |
| 4086 | } |
Tomi Valkeinen | e4a9e94 | 2012-03-28 15:58:56 +0300 | [diff] [blame] | 4087 | |
Tomi Valkeinen | 5cfc1c3 | 2013-05-15 11:24:30 +0300 | [diff] [blame] | 4088 | static int dsi_enable_video_output(struct omap_dss_device *dssdev, int channel) |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4089 | { |
| 4090 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Archit Taneja | e67458a | 2012-08-13 14:17:30 +0530 | [diff] [blame] | 4091 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 4092 | struct omap_overlay_manager *mgr = dsi->output.manager; |
Archit Taneja | 02c3960 | 2012-08-10 15:01:33 +0530 | [diff] [blame] | 4093 | int bpp = dsi_get_pixel_size(dsi->pix_fmt); |
Tomi Valkeinen | 1f68d9c | 2013-04-19 15:09:34 +0300 | [diff] [blame] | 4094 | struct omap_dss_device *out = &dsi->output; |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4095 | u8 data_type; |
| 4096 | u16 word_count; |
Tomi Valkeinen | 33ca237 | 2011-11-21 13:42:58 +0200 | [diff] [blame] | 4097 | int r; |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4098 | |
Tomi Valkeinen | b7dec9b | 2013-02-22 12:58:35 +0200 | [diff] [blame] | 4099 | if (out == NULL || out->manager == NULL) { |
| 4100 | DSSERR("failed to enable display: no output/manager\n"); |
| 4101 | return -ENODEV; |
| 4102 | } |
| 4103 | |
| 4104 | r = dsi_display_init_dispc(dsidev, mgr); |
| 4105 | if (r) |
| 4106 | goto err_init_dispc; |
| 4107 | |
Archit Taneja | dca2b15 | 2012-08-16 18:02:00 +0530 | [diff] [blame] | 4108 | if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) { |
Archit Taneja | 02c3960 | 2012-08-10 15:01:33 +0530 | [diff] [blame] | 4109 | switch (dsi->pix_fmt) { |
Tomi Valkeinen | 9a147a6 | 2011-11-09 15:30:11 +0200 | [diff] [blame] | 4110 | case OMAP_DSS_DSI_FMT_RGB888: |
| 4111 | data_type = MIPI_DSI_PACKED_PIXEL_STREAM_24; |
| 4112 | break; |
| 4113 | case OMAP_DSS_DSI_FMT_RGB666: |
| 4114 | data_type = MIPI_DSI_PIXEL_STREAM_3BYTE_18; |
| 4115 | break; |
| 4116 | case OMAP_DSS_DSI_FMT_RGB666_PACKED: |
| 4117 | data_type = MIPI_DSI_PACKED_PIXEL_STREAM_18; |
| 4118 | break; |
| 4119 | case OMAP_DSS_DSI_FMT_RGB565: |
| 4120 | data_type = MIPI_DSI_PACKED_PIXEL_STREAM_16; |
| 4121 | break; |
| 4122 | default: |
Tomi Valkeinen | b7dec9b | 2013-02-22 12:58:35 +0200 | [diff] [blame] | 4123 | r = -EINVAL; |
| 4124 | goto err_pix_fmt; |
Joe Perches | cf6ac4ce | 2013-10-08 16:23:24 -0700 | [diff] [blame] | 4125 | } |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4126 | |
Tomi Valkeinen | 9a147a6 | 2011-11-09 15:30:11 +0200 | [diff] [blame] | 4127 | dsi_if_enable(dsidev, false); |
| 4128 | dsi_vc_enable(dsidev, channel, false); |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4129 | |
Tomi Valkeinen | 9a147a6 | 2011-11-09 15:30:11 +0200 | [diff] [blame] | 4130 | /* MODE, 1 = video mode */ |
| 4131 | REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 4, 4); |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4132 | |
Archit Taneja | e67458a | 2012-08-13 14:17:30 +0530 | [diff] [blame] | 4133 | word_count = DIV_ROUND_UP(dsi->timings.x_res * bpp, 8); |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4134 | |
Tomi Valkeinen | 9a147a6 | 2011-11-09 15:30:11 +0200 | [diff] [blame] | 4135 | dsi_vc_write_long_header(dsidev, channel, data_type, |
| 4136 | word_count, 0); |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4137 | |
Tomi Valkeinen | 9a147a6 | 2011-11-09 15:30:11 +0200 | [diff] [blame] | 4138 | dsi_vc_enable(dsidev, channel, true); |
| 4139 | dsi_if_enable(dsidev, true); |
| 4140 | } |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4141 | |
Archit Taneja | eea8340 | 2012-09-04 11:42:36 +0530 | [diff] [blame] | 4142 | r = dss_mgr_enable(mgr); |
Tomi Valkeinen | b7dec9b | 2013-02-22 12:58:35 +0200 | [diff] [blame] | 4143 | if (r) |
| 4144 | goto err_mgr_enable; |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4145 | |
| 4146 | return 0; |
Tomi Valkeinen | b7dec9b | 2013-02-22 12:58:35 +0200 | [diff] [blame] | 4147 | |
| 4148 | err_mgr_enable: |
| 4149 | if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) { |
| 4150 | dsi_if_enable(dsidev, false); |
| 4151 | dsi_vc_enable(dsidev, channel, false); |
| 4152 | } |
| 4153 | err_pix_fmt: |
| 4154 | dsi_display_uninit_dispc(dsidev, mgr); |
| 4155 | err_init_dispc: |
| 4156 | return r; |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4157 | } |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4158 | |
Tomi Valkeinen | 5cfc1c3 | 2013-05-15 11:24:30 +0300 | [diff] [blame] | 4159 | static void dsi_disable_video_output(struct omap_dss_device *dssdev, int channel) |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4160 | { |
| 4161 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Archit Taneja | dca2b15 | 2012-08-16 18:02:00 +0530 | [diff] [blame] | 4162 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 4163 | struct omap_overlay_manager *mgr = dsi->output.manager; |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4164 | |
Archit Taneja | dca2b15 | 2012-08-16 18:02:00 +0530 | [diff] [blame] | 4165 | if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) { |
Tomi Valkeinen | 9a147a6 | 2011-11-09 15:30:11 +0200 | [diff] [blame] | 4166 | dsi_if_enable(dsidev, false); |
| 4167 | dsi_vc_enable(dsidev, channel, false); |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4168 | |
Tomi Valkeinen | 9a147a6 | 2011-11-09 15:30:11 +0200 | [diff] [blame] | 4169 | /* MODE, 0 = command mode */ |
| 4170 | REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 0, 4, 4); |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4171 | |
Tomi Valkeinen | 9a147a6 | 2011-11-09 15:30:11 +0200 | [diff] [blame] | 4172 | dsi_vc_enable(dsidev, channel, true); |
| 4173 | dsi_if_enable(dsidev, true); |
| 4174 | } |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4175 | |
Archit Taneja | eea8340 | 2012-09-04 11:42:36 +0530 | [diff] [blame] | 4176 | dss_mgr_disable(mgr); |
Tomi Valkeinen | b7dec9b | 2013-02-22 12:58:35 +0200 | [diff] [blame] | 4177 | |
| 4178 | dsi_display_uninit_dispc(dsidev, mgr); |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4179 | } |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4180 | |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 4181 | static void dsi_update_screen_dispc(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4182 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4183 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 4184 | struct omap_overlay_manager *mgr = dsi->output.manager; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4185 | unsigned bytespp; |
| 4186 | unsigned bytespl; |
| 4187 | unsigned bytespf; |
| 4188 | unsigned total_len; |
| 4189 | unsigned packet_payload; |
| 4190 | unsigned packet_len; |
| 4191 | u32 l; |
Tomi Valkeinen | 0f16aa0 | 2010-04-12 09:57:19 +0300 | [diff] [blame] | 4192 | int r; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4193 | const unsigned channel = dsi->update_channel; |
Tomi Valkeinen | 9932257 | 2013-03-05 10:37:02 +0200 | [diff] [blame] | 4194 | const unsigned line_buf_size = dsi->line_buffer_size; |
Archit Taneja | 55cd63a | 2012-08-09 15:41:13 +0530 | [diff] [blame] | 4195 | u16 w = dsi->timings.x_res; |
| 4196 | u16 h = dsi->timings.y_res; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4197 | |
Tomi Valkeinen | 5476e74 | 2011-11-03 16:34:20 +0200 | [diff] [blame] | 4198 | DSSDBG("dsi_update_screen_dispc(%dx%d)\n", w, h); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4199 | |
Archit Taneja | d604914 | 2011-08-22 11:58:08 +0530 | [diff] [blame] | 4200 | dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_VP); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 4201 | |
Archit Taneja | 02c3960 | 2012-08-10 15:01:33 +0530 | [diff] [blame] | 4202 | bytespp = dsi_get_pixel_size(dsi->pix_fmt) / 8; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4203 | bytespl = w * bytespp; |
| 4204 | bytespf = bytespl * h; |
| 4205 | |
| 4206 | /* NOTE: packet_payload has to be equal to N * bytespl, where N is |
| 4207 | * number of lines in a packet. See errata about VP_CLK_RATIO */ |
| 4208 | |
| 4209 | if (bytespf < line_buf_size) |
| 4210 | packet_payload = bytespf; |
| 4211 | else |
| 4212 | packet_payload = (line_buf_size) / bytespl * bytespl; |
| 4213 | |
| 4214 | packet_len = packet_payload + 1; /* 1 byte for DCS cmd */ |
| 4215 | total_len = (bytespf / packet_payload) * packet_len; |
| 4216 | |
| 4217 | if (bytespf % packet_payload) |
| 4218 | total_len += (bytespf % packet_payload) + 1; |
| 4219 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4220 | l = FLD_VAL(total_len, 23, 0); /* TE_SIZE */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4221 | dsi_write_reg(dsidev, DSI_VC_TE(channel), l); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4222 | |
Archit Taneja | 7a7c48f | 2011-08-25 18:25:03 +0530 | [diff] [blame] | 4223 | dsi_vc_write_long_header(dsidev, channel, MIPI_DSI_DCS_LONG_WRITE, |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4224 | packet_len, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4225 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4226 | if (dsi->te_enabled) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4227 | l = FLD_MOD(l, 1, 30, 30); /* TE_EN */ |
| 4228 | else |
| 4229 | l = FLD_MOD(l, 1, 31, 31); /* TE_START */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4230 | dsi_write_reg(dsidev, DSI_VC_TE(channel), l); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4231 | |
| 4232 | /* We put SIDLEMODE to no-idle for the duration of the transfer, |
| 4233 | * because DSS interrupts are not capable of waking up the CPU and the |
| 4234 | * framedone interrupt could be delayed for quite a long time. I think |
| 4235 | * the same goes for any DSS interrupts, but for some reason I have not |
| 4236 | * seen the problem anywhere else than here. |
| 4237 | */ |
| 4238 | dispc_disable_sidle(); |
| 4239 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4240 | dsi_perf_mark_start(dsidev); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 4241 | |
Archit Taneja | 49dbf58 | 2011-05-16 15:17:07 +0530 | [diff] [blame] | 4242 | r = schedule_delayed_work(&dsi->framedone_timeout_work, |
| 4243 | msecs_to_jiffies(250)); |
Tomi Valkeinen | 0f16aa0 | 2010-04-12 09:57:19 +0300 | [diff] [blame] | 4244 | BUG_ON(r == 0); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 4245 | |
Archit Taneja | eea8340 | 2012-09-04 11:42:36 +0530 | [diff] [blame] | 4246 | dss_mgr_set_timings(mgr, &dsi->timings); |
Archit Taneja | 55cd63a | 2012-08-09 15:41:13 +0530 | [diff] [blame] | 4247 | |
Archit Taneja | eea8340 | 2012-09-04 11:42:36 +0530 | [diff] [blame] | 4248 | dss_mgr_start_update(mgr); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4249 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4250 | if (dsi->te_enabled) { |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4251 | /* disable LP_RX_TO, so that we can receive TE. Time to wait |
| 4252 | * for TE is longer than the timer allows */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4253 | REG_FLD_MOD(dsidev, DSI_TIMING2, 0, 15, 15); /* LP_RX_TO */ |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4254 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4255 | dsi_vc_send_bta(dsidev, channel); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4256 | |
| 4257 | #ifdef DSI_CATCH_MISSING_TE |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4258 | mod_timer(&dsi->te_timer, jiffies + msecs_to_jiffies(250)); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4259 | #endif |
| 4260 | } |
| 4261 | } |
| 4262 | |
| 4263 | #ifdef DSI_CATCH_MISSING_TE |
| 4264 | static void dsi_te_timeout(unsigned long arg) |
| 4265 | { |
| 4266 | DSSERR("TE not received for 250ms!\n"); |
| 4267 | } |
| 4268 | #endif |
| 4269 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4270 | static void dsi_handle_framedone(struct platform_device *dsidev, int error) |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 4271 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4272 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 4273 | |
Tomi Valkeinen | ab83b14 | 2010-06-09 15:31:01 +0300 | [diff] [blame] | 4274 | /* SIDLEMODE back to smart-idle */ |
| 4275 | dispc_enable_sidle(); |
| 4276 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4277 | if (dsi->te_enabled) { |
Tomi Valkeinen | ab83b14 | 2010-06-09 15:31:01 +0300 | [diff] [blame] | 4278 | /* enable LP_RX_TO again after the TE */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4279 | REG_FLD_MOD(dsidev, DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */ |
Tomi Valkeinen | ab83b14 | 2010-06-09 15:31:01 +0300 | [diff] [blame] | 4280 | } |
| 4281 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4282 | dsi->framedone_callback(error, dsi->framedone_data); |
Tomi Valkeinen | ab83b14 | 2010-06-09 15:31:01 +0300 | [diff] [blame] | 4283 | |
| 4284 | if (!error) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4285 | dsi_perf_show(dsidev, "DISPC"); |
Tomi Valkeinen | ab83b14 | 2010-06-09 15:31:01 +0300 | [diff] [blame] | 4286 | } |
| 4287 | |
| 4288 | static void dsi_framedone_timeout_work_callback(struct work_struct *work) |
| 4289 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4290 | struct dsi_data *dsi = container_of(work, struct dsi_data, |
| 4291 | framedone_timeout_work.work); |
Tomi Valkeinen | 0f16aa0 | 2010-04-12 09:57:19 +0300 | [diff] [blame] | 4292 | /* XXX While extremely unlikely, we could get FRAMEDONE interrupt after |
| 4293 | * 250ms which would conflict with this timeout work. What should be |
| 4294 | * 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] | 4295 | * possibly scheduled framedone work. However, cancelling the transfer |
| 4296 | * on the HW is buggy, and would probably require resetting the whole |
| 4297 | * DSI */ |
Tomi Valkeinen | 0f16aa0 | 2010-04-12 09:57:19 +0300 | [diff] [blame] | 4298 | |
Tomi Valkeinen | ab83b14 | 2010-06-09 15:31:01 +0300 | [diff] [blame] | 4299 | DSSERR("Framedone not received for 250ms!\n"); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 4300 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4301 | dsi_handle_framedone(dsi->pdev, -ETIMEDOUT); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 4302 | } |
| 4303 | |
Tomi Valkeinen | 1550202 | 2012-10-10 13:59:07 +0300 | [diff] [blame] | 4304 | static void dsi_framedone_irq_callback(void *data) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4305 | { |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 4306 | struct platform_device *dsidev = (struct platform_device *) data; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4307 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 4308 | |
Tomi Valkeinen | ab83b14 | 2010-06-09 15:31:01 +0300 | [diff] [blame] | 4309 | /* Note: We get FRAMEDONE when DISPC has finished sending pixels and |
| 4310 | * turns itself off. However, DSI still has the pixels in its buffers, |
| 4311 | * and is sending the data. |
| 4312 | */ |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4313 | |
Tejun Heo | 136b572 | 2012-08-21 13:18:24 -0700 | [diff] [blame] | 4314 | cancel_delayed_work(&dsi->framedone_timeout_work); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4315 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4316 | dsi_handle_framedone(dsidev, 0); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 4317 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4318 | |
Tomi Valkeinen | 5cfc1c3 | 2013-05-15 11:24:30 +0300 | [diff] [blame] | 4319 | static int dsi_update(struct omap_dss_device *dssdev, int channel, |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 4320 | void (*callback)(int, void *), void *data) |
| 4321 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4322 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4323 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 5476e74 | 2011-11-03 16:34:20 +0200 | [diff] [blame] | 4324 | u16 dw, dh; |
| 4325 | |
| 4326 | dsi_perf_mark_setup(dsidev); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4327 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4328 | dsi->update_channel = channel; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4329 | |
Tomi Valkeinen | 4a9e78a | 2011-08-15 11:22:21 +0300 | [diff] [blame] | 4330 | dsi->framedone_callback = callback; |
| 4331 | dsi->framedone_data = data; |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 4332 | |
Archit Taneja | e352574 | 2012-08-09 15:23:43 +0530 | [diff] [blame] | 4333 | dw = dsi->timings.x_res; |
| 4334 | dh = dsi->timings.y_res; |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 4335 | |
Tomi Valkeinen | 477fed7 | 2013-10-02 14:41:24 +0300 | [diff] [blame] | 4336 | #ifdef DSI_PERF_MEASURE |
Tomi Valkeinen | 5476e74 | 2011-11-03 16:34:20 +0200 | [diff] [blame] | 4337 | dsi->update_bytes = dw * dh * |
Archit Taneja | 02c3960 | 2012-08-10 15:01:33 +0530 | [diff] [blame] | 4338 | dsi_get_pixel_size(dsi->pix_fmt) / 8; |
Tomi Valkeinen | 5476e74 | 2011-11-03 16:34:20 +0200 | [diff] [blame] | 4339 | #endif |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 4340 | dsi_update_screen_dispc(dsidev); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 4341 | |
| 4342 | return 0; |
| 4343 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4344 | |
| 4345 | /* Display funcs */ |
| 4346 | |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 4347 | static int dsi_configure_dispc_clocks(struct platform_device *dsidev) |
Archit Taneja | 7d2572f | 2012-06-29 14:31:07 +0530 | [diff] [blame] | 4348 | { |
Archit Taneja | 7d2572f | 2012-06-29 14:31:07 +0530 | [diff] [blame] | 4349 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 4350 | struct dispc_clock_info dispc_cinfo; |
| 4351 | int r; |
Tomi Valkeinen | 1751818 | 2013-03-07 11:21:45 +0200 | [diff] [blame] | 4352 | unsigned long fck; |
Archit Taneja | 7d2572f | 2012-06-29 14:31:07 +0530 | [diff] [blame] | 4353 | |
| 4354 | fck = dsi_get_pll_hsdiv_dispc_rate(dsidev); |
| 4355 | |
Tomi Valkeinen | a0d269e | 2012-11-27 17:05:54 +0200 | [diff] [blame] | 4356 | dispc_cinfo.lck_div = dsi->user_dispc_cinfo.lck_div; |
| 4357 | dispc_cinfo.pck_div = dsi->user_dispc_cinfo.pck_div; |
Archit Taneja | 7d2572f | 2012-06-29 14:31:07 +0530 | [diff] [blame] | 4358 | |
| 4359 | r = dispc_calc_clock_rates(fck, &dispc_cinfo); |
| 4360 | if (r) { |
| 4361 | DSSERR("Failed to calc dispc clocks\n"); |
| 4362 | return r; |
| 4363 | } |
| 4364 | |
| 4365 | dsi->mgr_config.clock_info = dispc_cinfo; |
| 4366 | |
| 4367 | return 0; |
| 4368 | } |
| 4369 | |
Tomi Valkeinen | b7dec9b | 2013-02-22 12:58:35 +0200 | [diff] [blame] | 4370 | static int dsi_display_init_dispc(struct platform_device *dsidev, |
| 4371 | struct omap_overlay_manager *mgr) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4372 | { |
Archit Taneja | 7d2572f | 2012-06-29 14:31:07 +0530 | [diff] [blame] | 4373 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Archit Taneja | 7d2572f | 2012-06-29 14:31:07 +0530 | [diff] [blame] | 4374 | int r; |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 4375 | |
Tomi Valkeinen | 4ce9e33 | 2013-03-05 17:11:16 +0200 | [diff] [blame] | 4376 | dss_select_lcd_clk_source(mgr->id, dsi->module_id == 0 ? |
| 4377 | OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC : |
| 4378 | OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC); |
Tomi Valkeinen | 5476e74 | 2011-11-03 16:34:20 +0200 | [diff] [blame] | 4379 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4380 | if (dsi->mode == OMAP_DSS_DSI_CMD_MODE) { |
Tomi Valkeinen | 1550202 | 2012-10-10 13:59:07 +0300 | [diff] [blame] | 4381 | r = dss_mgr_register_framedone_handler(mgr, |
| 4382 | dsi_framedone_irq_callback, dsidev); |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4383 | if (r) { |
Tomi Valkeinen | 1550202 | 2012-10-10 13:59:07 +0300 | [diff] [blame] | 4384 | DSSERR("can't register FRAMEDONE handler\n"); |
Archit Taneja | 7d2572f | 2012-06-29 14:31:07 +0530 | [diff] [blame] | 4385 | goto err; |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4386 | } |
| 4387 | |
Archit Taneja | 7d2572f | 2012-06-29 14:31:07 +0530 | [diff] [blame] | 4388 | dsi->mgr_config.stallmode = true; |
| 4389 | dsi->mgr_config.fifohandcheck = true; |
Archit Taneja | 8af6ff0 | 2011-09-05 16:48:27 +0530 | [diff] [blame] | 4390 | } else { |
Archit Taneja | 7d2572f | 2012-06-29 14:31:07 +0530 | [diff] [blame] | 4391 | dsi->mgr_config.stallmode = false; |
| 4392 | dsi->mgr_config.fifohandcheck = false; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4393 | } |
| 4394 | |
Archit Taneja | bd5a7b1 | 2012-06-26 12:38:31 +0530 | [diff] [blame] | 4395 | /* |
| 4396 | * override interlace, logic level and edge related parameters in |
| 4397 | * omap_video_timings with default values |
| 4398 | */ |
Archit Taneja | e67458a | 2012-08-13 14:17:30 +0530 | [diff] [blame] | 4399 | dsi->timings.interlace = false; |
| 4400 | dsi->timings.hsync_level = OMAPDSS_SIG_ACTIVE_HIGH; |
| 4401 | dsi->timings.vsync_level = OMAPDSS_SIG_ACTIVE_HIGH; |
| 4402 | dsi->timings.data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE; |
| 4403 | dsi->timings.de_level = OMAPDSS_SIG_ACTIVE_HIGH; |
| 4404 | dsi->timings.sync_pclk_edge = OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES; |
Archit Taneja | bd5a7b1 | 2012-06-26 12:38:31 +0530 | [diff] [blame] | 4405 | |
Archit Taneja | eea8340 | 2012-09-04 11:42:36 +0530 | [diff] [blame] | 4406 | dss_mgr_set_timings(mgr, &dsi->timings); |
Archit Taneja | bd5a7b1 | 2012-06-26 12:38:31 +0530 | [diff] [blame] | 4407 | |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 4408 | r = dsi_configure_dispc_clocks(dsidev); |
Archit Taneja | 7d2572f | 2012-06-29 14:31:07 +0530 | [diff] [blame] | 4409 | if (r) |
| 4410 | goto err1; |
| 4411 | |
| 4412 | dsi->mgr_config.io_pad_mode = DSS_IO_PAD_MODE_BYPASS; |
| 4413 | dsi->mgr_config.video_port_width = |
Archit Taneja | 02c3960 | 2012-08-10 15:01:33 +0530 | [diff] [blame] | 4414 | dsi_get_pixel_size(dsi->pix_fmt); |
Archit Taneja | 7d2572f | 2012-06-29 14:31:07 +0530 | [diff] [blame] | 4415 | dsi->mgr_config.lcden_sig_polarity = 0; |
| 4416 | |
Archit Taneja | eea8340 | 2012-09-04 11:42:36 +0530 | [diff] [blame] | 4417 | dss_mgr_set_lcd_config(mgr, &dsi->mgr_config); |
Archit Taneja | d21f43b | 2012-06-21 09:45:11 +0530 | [diff] [blame] | 4418 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4419 | return 0; |
Archit Taneja | 7d2572f | 2012-06-29 14:31:07 +0530 | [diff] [blame] | 4420 | err1: |
Archit Taneja | dca2b15 | 2012-08-16 18:02:00 +0530 | [diff] [blame] | 4421 | if (dsi->mode == OMAP_DSS_DSI_CMD_MODE) |
Tomi Valkeinen | 1550202 | 2012-10-10 13:59:07 +0300 | [diff] [blame] | 4422 | dss_mgr_unregister_framedone_handler(mgr, |
| 4423 | dsi_framedone_irq_callback, dsidev); |
Archit Taneja | 7d2572f | 2012-06-29 14:31:07 +0530 | [diff] [blame] | 4424 | err: |
Tomi Valkeinen | b7dec9b | 2013-02-22 12:58:35 +0200 | [diff] [blame] | 4425 | dss_select_lcd_clk_source(mgr->id, OMAP_DSS_CLK_SRC_FCK); |
Archit Taneja | 7d2572f | 2012-06-29 14:31:07 +0530 | [diff] [blame] | 4426 | return r; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4427 | } |
| 4428 | |
Tomi Valkeinen | b7dec9b | 2013-02-22 12:58:35 +0200 | [diff] [blame] | 4429 | static void dsi_display_uninit_dispc(struct platform_device *dsidev, |
| 4430 | struct omap_overlay_manager *mgr) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4431 | { |
Archit Taneja | dca2b15 | 2012-08-16 18:02:00 +0530 | [diff] [blame] | 4432 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 4433 | |
Tomi Valkeinen | 1550202 | 2012-10-10 13:59:07 +0300 | [diff] [blame] | 4434 | if (dsi->mode == OMAP_DSS_DSI_CMD_MODE) |
| 4435 | dss_mgr_unregister_framedone_handler(mgr, |
| 4436 | dsi_framedone_irq_callback, dsidev); |
Tomi Valkeinen | b7dec9b | 2013-02-22 12:58:35 +0200 | [diff] [blame] | 4437 | |
| 4438 | dss_select_lcd_clk_source(mgr->id, OMAP_DSS_CLK_SRC_FCK); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4439 | } |
| 4440 | |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 4441 | static int dsi_configure_dsi_clocks(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4442 | { |
Tomi Valkeinen | a0d269e | 2012-11-27 17:05:54 +0200 | [diff] [blame] | 4443 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4444 | struct dsi_clock_info cinfo; |
| 4445 | int r; |
| 4446 | |
Tomi Valkeinen | a0d269e | 2012-11-27 17:05:54 +0200 | [diff] [blame] | 4447 | cinfo = dsi->user_dsi_cinfo; |
| 4448 | |
Tomi Valkeinen | b6e695a | 2012-03-15 15:22:58 +0200 | [diff] [blame] | 4449 | r = dsi_calc_clock_rates(dsidev, &cinfo); |
Ville Syrjälä | ebf0a3f | 2010-04-22 22:50:05 +0200 | [diff] [blame] | 4450 | if (r) { |
| 4451 | DSSERR("Failed to calc dsi clocks\n"); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4452 | return r; |
Ville Syrjälä | ebf0a3f | 2010-04-22 22:50:05 +0200 | [diff] [blame] | 4453 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4454 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4455 | r = dsi_pll_set_clock_div(dsidev, &cinfo); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4456 | if (r) { |
| 4457 | DSSERR("Failed to set dsi clocks\n"); |
| 4458 | return r; |
| 4459 | } |
| 4460 | |
| 4461 | return 0; |
| 4462 | } |
| 4463 | |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 4464 | static int dsi_display_init_dsi(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4465 | { |
Tomi Valkeinen | 11ee960 | 2012-03-09 16:07:39 +0200 | [diff] [blame] | 4466 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4467 | int r; |
| 4468 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4469 | r = dsi_pll_init(dsidev, true, true); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4470 | if (r) |
| 4471 | goto err0; |
| 4472 | |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 4473 | r = dsi_configure_dsi_clocks(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4474 | if (r) |
| 4475 | goto err1; |
| 4476 | |
Tomi Valkeinen | 4ce9e33 | 2013-03-05 17:11:16 +0200 | [diff] [blame] | 4477 | dss_select_dsi_clk_source(dsi->module_id, dsi->module_id == 0 ? |
| 4478 | OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI : |
| 4479 | OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4480 | |
| 4481 | DSSDBG("PLL OK\n"); |
| 4482 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 4483 | r = dsi_cio_init(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4484 | if (r) |
| 4485 | goto err2; |
| 4486 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4487 | _dsi_print_reset_status(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4488 | |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 4489 | dsi_proto_timings(dsidev); |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 4490 | dsi_set_lp_clk_divisor(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4491 | |
| 4492 | if (1) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4493 | _dsi_print_reset_status(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4494 | |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 4495 | r = dsi_proto_config(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4496 | if (r) |
| 4497 | goto err3; |
| 4498 | |
| 4499 | /* enable interface */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4500 | dsi_vc_enable(dsidev, 0, 1); |
| 4501 | dsi_vc_enable(dsidev, 1, 1); |
| 4502 | dsi_vc_enable(dsidev, 2, 1); |
| 4503 | dsi_vc_enable(dsidev, 3, 1); |
| 4504 | dsi_if_enable(dsidev, 1); |
| 4505 | dsi_force_tx_stop_mode_io(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4506 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4507 | return 0; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4508 | err3: |
Archit Taneja | 9e7e937 | 2012-08-14 12:29:22 +0530 | [diff] [blame] | 4509 | dsi_cio_uninit(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4510 | err2: |
Tomi Valkeinen | 11ee960 | 2012-03-09 16:07:39 +0200 | [diff] [blame] | 4511 | 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] | 4512 | err1: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4513 | dsi_pll_uninit(dsidev, true); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4514 | err0: |
| 4515 | return r; |
| 4516 | } |
| 4517 | |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 4518 | static void dsi_display_uninit_dsi(struct platform_device *dsidev, |
Tomi Valkeinen | 22d6d67 | 2010-10-11 11:33:30 +0300 | [diff] [blame] | 4519 | bool disconnect_lanes, bool enter_ulps) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4520 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4521 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4522 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4523 | if (enter_ulps && !dsi->ulps_enabled) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4524 | dsi_enter_ulps(dsidev); |
Tomi Valkeinen | 40885ab | 2010-07-28 15:53:38 +0300 | [diff] [blame] | 4525 | |
Ville Syrjälä | d737010 | 2010-04-22 22:50:09 +0200 | [diff] [blame] | 4526 | /* disable interface */ |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4527 | dsi_if_enable(dsidev, 0); |
| 4528 | dsi_vc_enable(dsidev, 0, 0); |
| 4529 | dsi_vc_enable(dsidev, 1, 0); |
| 4530 | dsi_vc_enable(dsidev, 2, 0); |
| 4531 | dsi_vc_enable(dsidev, 3, 0); |
Ville Syrjälä | d737010 | 2010-04-22 22:50:09 +0200 | [diff] [blame] | 4532 | |
Tomi Valkeinen | 11ee960 | 2012-03-09 16:07:39 +0200 | [diff] [blame] | 4533 | 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] | 4534 | dsi_cio_uninit(dsidev); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4535 | dsi_pll_uninit(dsidev, disconnect_lanes); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4536 | } |
| 4537 | |
Tomi Valkeinen | 5cfc1c3 | 2013-05-15 11:24:30 +0300 | [diff] [blame] | 4538 | static int dsi_display_enable(struct omap_dss_device *dssdev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4539 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4540 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4541 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4542 | int r = 0; |
| 4543 | |
| 4544 | DSSDBG("dsi_display_enable\n"); |
| 4545 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4546 | WARN_ON(!dsi_bus_is_locked(dsidev)); |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 4547 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4548 | mutex_lock(&dsi->lock); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4549 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4550 | r = dsi_runtime_get(dsidev); |
| 4551 | if (r) |
| 4552 | goto err_get_dsi; |
| 4553 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4554 | dsi_enable_pll_clock(dsidev, 1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4555 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4556 | _dsi_initialize_irq(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4557 | |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 4558 | r = dsi_display_init_dsi(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4559 | if (r) |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4560 | goto err_init_dsi; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4561 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4562 | mutex_unlock(&dsi->lock); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4563 | |
| 4564 | return 0; |
| 4565 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4566 | err_init_dsi: |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4567 | dsi_enable_pll_clock(dsidev, 0); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4568 | dsi_runtime_put(dsidev); |
| 4569 | err_get_dsi: |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4570 | mutex_unlock(&dsi->lock); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4571 | DSSDBG("dsi_display_enable FAILED\n"); |
| 4572 | return r; |
| 4573 | } |
| 4574 | |
Tomi Valkeinen | 5cfc1c3 | 2013-05-15 11:24:30 +0300 | [diff] [blame] | 4575 | static void dsi_display_disable(struct omap_dss_device *dssdev, |
Tomi Valkeinen | 22d6d67 | 2010-10-11 11:33:30 +0300 | [diff] [blame] | 4576 | bool disconnect_lanes, bool enter_ulps) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4577 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4578 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4579 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4580 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4581 | DSSDBG("dsi_display_disable\n"); |
| 4582 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4583 | WARN_ON(!dsi_bus_is_locked(dsidev)); |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 4584 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4585 | mutex_lock(&dsi->lock); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4586 | |
Tomi Valkeinen | 15ffa1d | 2011-06-16 14:34:06 +0300 | [diff] [blame] | 4587 | dsi_sync_vc(dsidev, 0); |
| 4588 | dsi_sync_vc(dsidev, 1); |
| 4589 | dsi_sync_vc(dsidev, 2); |
| 4590 | dsi_sync_vc(dsidev, 3); |
| 4591 | |
Tomi Valkeinen | 5761217 | 2012-11-27 17:32:36 +0200 | [diff] [blame] | 4592 | dsi_display_uninit_dsi(dsidev, disconnect_lanes, enter_ulps); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4593 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4594 | dsi_runtime_put(dsidev); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 4595 | dsi_enable_pll_clock(dsidev, 0); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4596 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4597 | mutex_unlock(&dsi->lock); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4598 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4599 | |
Tomi Valkeinen | 5cfc1c3 | 2013-05-15 11:24:30 +0300 | [diff] [blame] | 4600 | static int dsi_enable_te(struct omap_dss_device *dssdev, bool enable) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4601 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 4602 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 4603 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 4604 | |
| 4605 | dsi->te_enabled = enable; |
Tomi Valkeinen | 225b650 | 2010-01-11 15:11:01 +0200 | [diff] [blame] | 4606 | return 0; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4607 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 4608 | |
Tomi Valkeinen | f1e0001 | 2013-03-05 17:21:35 +0200 | [diff] [blame] | 4609 | #ifdef PRINT_VERBOSE_VM_TIMINGS |
| 4610 | static void print_dsi_vm(const char *str, |
| 4611 | const struct omap_dss_dsi_videomode_timings *t) |
| 4612 | { |
| 4613 | unsigned long byteclk = t->hsclk / 4; |
| 4614 | int bl, wc, pps, tot; |
| 4615 | |
| 4616 | wc = DIV_ROUND_UP(t->hact * t->bitspp, 8); |
| 4617 | pps = DIV_ROUND_UP(wc + 6, t->ndl); /* pixel packet size */ |
| 4618 | bl = t->hss + t->hsa + t->hse + t->hbp + t->hfp; |
| 4619 | tot = bl + pps; |
| 4620 | |
| 4621 | #define TO_DSI_T(x) ((u32)div64_u64((u64)x * 1000000000llu, byteclk)) |
| 4622 | |
| 4623 | pr_debug("%s bck %lu, %u/%u/%u/%u/%u/%u = %u+%u = %u, " |
| 4624 | "%u/%u/%u/%u/%u/%u = %u + %u = %u\n", |
| 4625 | str, |
| 4626 | byteclk, |
| 4627 | t->hss, t->hsa, t->hse, t->hbp, pps, t->hfp, |
| 4628 | bl, pps, tot, |
| 4629 | TO_DSI_T(t->hss), |
| 4630 | TO_DSI_T(t->hsa), |
| 4631 | TO_DSI_T(t->hse), |
| 4632 | TO_DSI_T(t->hbp), |
| 4633 | TO_DSI_T(pps), |
| 4634 | TO_DSI_T(t->hfp), |
| 4635 | |
| 4636 | TO_DSI_T(bl), |
| 4637 | TO_DSI_T(pps), |
| 4638 | |
| 4639 | TO_DSI_T(tot)); |
| 4640 | #undef TO_DSI_T |
| 4641 | } |
| 4642 | |
| 4643 | static void print_dispc_vm(const char *str, const struct omap_video_timings *t) |
| 4644 | { |
Tomi Valkeinen | d8d78941 | 2013-04-10 14:12:14 +0300 | [diff] [blame] | 4645 | unsigned long pck = t->pixelclock; |
Tomi Valkeinen | f1e0001 | 2013-03-05 17:21:35 +0200 | [diff] [blame] | 4646 | int hact, bl, tot; |
| 4647 | |
| 4648 | hact = t->x_res; |
| 4649 | bl = t->hsw + t->hbp + t->hfp; |
| 4650 | tot = hact + bl; |
| 4651 | |
| 4652 | #define TO_DISPC_T(x) ((u32)div64_u64((u64)x * 1000000000llu, pck)) |
| 4653 | |
| 4654 | pr_debug("%s pck %lu, %u/%u/%u/%u = %u+%u = %u, " |
| 4655 | "%u/%u/%u/%u = %u + %u = %u\n", |
| 4656 | str, |
| 4657 | pck, |
| 4658 | t->hsw, t->hbp, hact, t->hfp, |
| 4659 | bl, hact, tot, |
| 4660 | TO_DISPC_T(t->hsw), |
| 4661 | TO_DISPC_T(t->hbp), |
| 4662 | TO_DISPC_T(hact), |
| 4663 | TO_DISPC_T(t->hfp), |
| 4664 | TO_DISPC_T(bl), |
| 4665 | TO_DISPC_T(hact), |
| 4666 | TO_DISPC_T(tot)); |
| 4667 | #undef TO_DISPC_T |
| 4668 | } |
| 4669 | |
| 4670 | /* note: this is not quite accurate */ |
| 4671 | static void print_dsi_dispc_vm(const char *str, |
| 4672 | const struct omap_dss_dsi_videomode_timings *t) |
| 4673 | { |
| 4674 | struct omap_video_timings vm = { 0 }; |
| 4675 | unsigned long byteclk = t->hsclk / 4; |
| 4676 | unsigned long pck; |
| 4677 | u64 dsi_tput; |
| 4678 | int dsi_hact, dsi_htot; |
| 4679 | |
| 4680 | dsi_tput = (u64)byteclk * t->ndl * 8; |
| 4681 | pck = (u32)div64_u64(dsi_tput, t->bitspp); |
| 4682 | dsi_hact = DIV_ROUND_UP(DIV_ROUND_UP(t->hact * t->bitspp, 8) + 6, t->ndl); |
| 4683 | dsi_htot = t->hss + t->hsa + t->hse + t->hbp + dsi_hact + t->hfp; |
| 4684 | |
Tomi Valkeinen | d8d78941 | 2013-04-10 14:12:14 +0300 | [diff] [blame] | 4685 | vm.pixelclock = pck; |
Tomi Valkeinen | f1e0001 | 2013-03-05 17:21:35 +0200 | [diff] [blame] | 4686 | vm.hsw = div64_u64((u64)(t->hsa + t->hse) * pck, byteclk); |
| 4687 | vm.hbp = div64_u64((u64)t->hbp * pck, byteclk); |
| 4688 | vm.hfp = div64_u64((u64)t->hfp * pck, byteclk); |
| 4689 | vm.x_res = t->hact; |
| 4690 | |
| 4691 | print_dispc_vm(str, &vm); |
| 4692 | } |
| 4693 | #endif /* PRINT_VERBOSE_VM_TIMINGS */ |
| 4694 | |
| 4695 | static bool dsi_cm_calc_dispc_cb(int lckd, int pckd, unsigned long lck, |
| 4696 | unsigned long pck, void *data) |
| 4697 | { |
| 4698 | struct dsi_clk_calc_ctx *ctx = data; |
| 4699 | struct omap_video_timings *t = &ctx->dispc_vm; |
| 4700 | |
| 4701 | ctx->dispc_cinfo.lck_div = lckd; |
| 4702 | ctx->dispc_cinfo.pck_div = pckd; |
| 4703 | ctx->dispc_cinfo.lck = lck; |
| 4704 | ctx->dispc_cinfo.pck = pck; |
| 4705 | |
| 4706 | *t = *ctx->config->timings; |
Tomi Valkeinen | d8d78941 | 2013-04-10 14:12:14 +0300 | [diff] [blame] | 4707 | t->pixelclock = pck; |
Tomi Valkeinen | f1e0001 | 2013-03-05 17:21:35 +0200 | [diff] [blame] | 4708 | t->x_res = ctx->config->timings->x_res; |
| 4709 | t->y_res = ctx->config->timings->y_res; |
| 4710 | t->hsw = t->hfp = t->hbp = t->vsw = 1; |
| 4711 | t->vfp = t->vbp = 0; |
| 4712 | |
| 4713 | return true; |
| 4714 | } |
| 4715 | |
| 4716 | static bool dsi_cm_calc_hsdiv_cb(int regm_dispc, unsigned long dispc, |
| 4717 | void *data) |
| 4718 | { |
| 4719 | struct dsi_clk_calc_ctx *ctx = data; |
| 4720 | |
| 4721 | ctx->dsi_cinfo.regm_dispc = regm_dispc; |
| 4722 | ctx->dsi_cinfo.dsi_pll_hsdiv_dispc_clk = dispc; |
| 4723 | |
| 4724 | return dispc_div_calc(dispc, ctx->req_pck_min, ctx->req_pck_max, |
| 4725 | dsi_cm_calc_dispc_cb, ctx); |
| 4726 | } |
| 4727 | |
| 4728 | static bool dsi_cm_calc_pll_cb(int regn, int regm, unsigned long fint, |
| 4729 | unsigned long pll, void *data) |
| 4730 | { |
| 4731 | struct dsi_clk_calc_ctx *ctx = data; |
| 4732 | |
| 4733 | ctx->dsi_cinfo.regn = regn; |
| 4734 | ctx->dsi_cinfo.regm = regm; |
| 4735 | ctx->dsi_cinfo.fint = fint; |
| 4736 | ctx->dsi_cinfo.clkin4ddr = pll; |
| 4737 | |
| 4738 | return dsi_hsdiv_calc(ctx->dsidev, pll, ctx->req_pck_min, |
| 4739 | dsi_cm_calc_hsdiv_cb, ctx); |
| 4740 | } |
| 4741 | |
| 4742 | static bool dsi_cm_calc(struct dsi_data *dsi, |
| 4743 | const struct omap_dss_dsi_config *cfg, |
| 4744 | struct dsi_clk_calc_ctx *ctx) |
| 4745 | { |
| 4746 | unsigned long clkin; |
| 4747 | int bitspp, ndl; |
| 4748 | unsigned long pll_min, pll_max; |
| 4749 | unsigned long pck, txbyteclk; |
| 4750 | |
| 4751 | clkin = clk_get_rate(dsi->sys_clk); |
| 4752 | bitspp = dsi_get_pixel_size(cfg->pixel_format); |
| 4753 | ndl = dsi->num_lanes_used - 1; |
| 4754 | |
| 4755 | /* |
| 4756 | * Here we should calculate minimum txbyteclk to be able to send the |
| 4757 | * frame in time, and also to handle TE. That's not very simple, though, |
| 4758 | * especially as we go to LP between each pixel packet due to HW |
| 4759 | * "feature". So let's just estimate very roughly and multiply by 1.5. |
| 4760 | */ |
Tomi Valkeinen | d8d78941 | 2013-04-10 14:12:14 +0300 | [diff] [blame] | 4761 | pck = cfg->timings->pixelclock; |
Tomi Valkeinen | f1e0001 | 2013-03-05 17:21:35 +0200 | [diff] [blame] | 4762 | pck = pck * 3 / 2; |
| 4763 | txbyteclk = pck * bitspp / 8 / ndl; |
| 4764 | |
| 4765 | memset(ctx, 0, sizeof(*ctx)); |
| 4766 | ctx->dsidev = dsi->pdev; |
| 4767 | ctx->config = cfg; |
| 4768 | ctx->req_pck_min = pck; |
| 4769 | ctx->req_pck_nom = pck; |
| 4770 | ctx->req_pck_max = pck * 3 / 2; |
| 4771 | ctx->dsi_cinfo.clkin = clkin; |
| 4772 | |
| 4773 | pll_min = max(cfg->hs_clk_min * 4, txbyteclk * 4 * 4); |
| 4774 | pll_max = cfg->hs_clk_max * 4; |
| 4775 | |
| 4776 | return dsi_pll_calc(dsi->pdev, clkin, |
| 4777 | pll_min, pll_max, |
| 4778 | dsi_cm_calc_pll_cb, ctx); |
| 4779 | } |
| 4780 | |
| 4781 | static bool dsi_vm_calc_blanking(struct dsi_clk_calc_ctx *ctx) |
| 4782 | { |
| 4783 | struct dsi_data *dsi = dsi_get_dsidrv_data(ctx->dsidev); |
| 4784 | const struct omap_dss_dsi_config *cfg = ctx->config; |
| 4785 | int bitspp = dsi_get_pixel_size(cfg->pixel_format); |
| 4786 | int ndl = dsi->num_lanes_used - 1; |
| 4787 | unsigned long hsclk = ctx->dsi_cinfo.clkin4ddr / 4; |
| 4788 | unsigned long byteclk = hsclk / 4; |
| 4789 | |
| 4790 | unsigned long dispc_pck, req_pck_min, req_pck_nom, req_pck_max; |
| 4791 | int xres; |
| 4792 | int panel_htot, panel_hbl; /* pixels */ |
| 4793 | int dispc_htot, dispc_hbl; /* pixels */ |
| 4794 | int dsi_htot, dsi_hact, dsi_hbl, hss, hse; /* byteclks */ |
| 4795 | int hfp, hsa, hbp; |
| 4796 | const struct omap_video_timings *req_vm; |
| 4797 | struct omap_video_timings *dispc_vm; |
| 4798 | struct omap_dss_dsi_videomode_timings *dsi_vm; |
| 4799 | u64 dsi_tput, dispc_tput; |
| 4800 | |
| 4801 | dsi_tput = (u64)byteclk * ndl * 8; |
| 4802 | |
| 4803 | req_vm = cfg->timings; |
| 4804 | req_pck_min = ctx->req_pck_min; |
| 4805 | req_pck_max = ctx->req_pck_max; |
| 4806 | req_pck_nom = ctx->req_pck_nom; |
| 4807 | |
| 4808 | dispc_pck = ctx->dispc_cinfo.pck; |
| 4809 | dispc_tput = (u64)dispc_pck * bitspp; |
| 4810 | |
| 4811 | xres = req_vm->x_res; |
| 4812 | |
| 4813 | panel_hbl = req_vm->hfp + req_vm->hbp + req_vm->hsw; |
| 4814 | panel_htot = xres + panel_hbl; |
| 4815 | |
| 4816 | dsi_hact = DIV_ROUND_UP(DIV_ROUND_UP(xres * bitspp, 8) + 6, ndl); |
| 4817 | |
| 4818 | /* |
| 4819 | * When there are no line buffers, DISPC and DSI must have the |
| 4820 | * same tput. Otherwise DISPC tput needs to be higher than DSI's. |
| 4821 | */ |
| 4822 | if (dsi->line_buffer_size < xres * bitspp / 8) { |
| 4823 | if (dispc_tput != dsi_tput) |
| 4824 | return false; |
| 4825 | } else { |
| 4826 | if (dispc_tput < dsi_tput) |
| 4827 | return false; |
| 4828 | } |
| 4829 | |
| 4830 | /* DSI tput must be over the min requirement */ |
| 4831 | if (dsi_tput < (u64)bitspp * req_pck_min) |
| 4832 | return false; |
| 4833 | |
| 4834 | /* When non-burst mode, DSI tput must be below max requirement. */ |
| 4835 | if (cfg->trans_mode != OMAP_DSS_DSI_BURST_MODE) { |
| 4836 | if (dsi_tput > (u64)bitspp * req_pck_max) |
| 4837 | return false; |
| 4838 | } |
| 4839 | |
| 4840 | hss = DIV_ROUND_UP(4, ndl); |
| 4841 | |
| 4842 | if (cfg->trans_mode == OMAP_DSS_DSI_PULSE_MODE) { |
| 4843 | if (ndl == 3 && req_vm->hsw == 0) |
| 4844 | hse = 1; |
| 4845 | else |
| 4846 | hse = DIV_ROUND_UP(4, ndl); |
| 4847 | } else { |
| 4848 | hse = 0; |
| 4849 | } |
| 4850 | |
| 4851 | /* DSI htot to match the panel's nominal pck */ |
| 4852 | dsi_htot = div64_u64((u64)panel_htot * byteclk, req_pck_nom); |
| 4853 | |
| 4854 | /* fail if there would be no time for blanking */ |
| 4855 | if (dsi_htot < hss + hse + dsi_hact) |
| 4856 | return false; |
| 4857 | |
| 4858 | /* total DSI blanking needed to achieve panel's TL */ |
| 4859 | dsi_hbl = dsi_htot - dsi_hact; |
| 4860 | |
| 4861 | /* DISPC htot to match the DSI TL */ |
| 4862 | dispc_htot = div64_u64((u64)dsi_htot * dispc_pck, byteclk); |
| 4863 | |
| 4864 | /* verify that the DSI and DISPC TLs are the same */ |
| 4865 | if ((u64)dsi_htot * dispc_pck != (u64)dispc_htot * byteclk) |
| 4866 | return false; |
| 4867 | |
| 4868 | dispc_hbl = dispc_htot - xres; |
| 4869 | |
| 4870 | /* setup DSI videomode */ |
| 4871 | |
| 4872 | dsi_vm = &ctx->dsi_vm; |
| 4873 | memset(dsi_vm, 0, sizeof(*dsi_vm)); |
| 4874 | |
| 4875 | dsi_vm->hsclk = hsclk; |
| 4876 | |
| 4877 | dsi_vm->ndl = ndl; |
| 4878 | dsi_vm->bitspp = bitspp; |
| 4879 | |
| 4880 | if (cfg->trans_mode != OMAP_DSS_DSI_PULSE_MODE) { |
| 4881 | hsa = 0; |
| 4882 | } else if (ndl == 3 && req_vm->hsw == 0) { |
| 4883 | hsa = 0; |
| 4884 | } else { |
| 4885 | hsa = div64_u64((u64)req_vm->hsw * byteclk, req_pck_nom); |
| 4886 | hsa = max(hsa - hse, 1); |
| 4887 | } |
| 4888 | |
| 4889 | hbp = div64_u64((u64)req_vm->hbp * byteclk, req_pck_nom); |
| 4890 | hbp = max(hbp, 1); |
| 4891 | |
| 4892 | hfp = dsi_hbl - (hss + hsa + hse + hbp); |
| 4893 | if (hfp < 1) { |
| 4894 | int t; |
| 4895 | /* we need to take cycles from hbp */ |
| 4896 | |
| 4897 | t = 1 - hfp; |
| 4898 | hbp = max(hbp - t, 1); |
| 4899 | hfp = dsi_hbl - (hss + hsa + hse + hbp); |
| 4900 | |
| 4901 | if (hfp < 1 && hsa > 0) { |
| 4902 | /* we need to take cycles from hsa */ |
| 4903 | t = 1 - hfp; |
| 4904 | hsa = max(hsa - t, 1); |
| 4905 | hfp = dsi_hbl - (hss + hsa + hse + hbp); |
| 4906 | } |
| 4907 | } |
| 4908 | |
| 4909 | if (hfp < 1) |
| 4910 | return false; |
| 4911 | |
| 4912 | dsi_vm->hss = hss; |
| 4913 | dsi_vm->hsa = hsa; |
| 4914 | dsi_vm->hse = hse; |
| 4915 | dsi_vm->hbp = hbp; |
| 4916 | dsi_vm->hact = xres; |
| 4917 | dsi_vm->hfp = hfp; |
| 4918 | |
| 4919 | dsi_vm->vsa = req_vm->vsw; |
| 4920 | dsi_vm->vbp = req_vm->vbp; |
| 4921 | dsi_vm->vact = req_vm->y_res; |
| 4922 | dsi_vm->vfp = req_vm->vfp; |
| 4923 | |
| 4924 | dsi_vm->trans_mode = cfg->trans_mode; |
| 4925 | |
| 4926 | dsi_vm->blanking_mode = 0; |
| 4927 | dsi_vm->hsa_blanking_mode = 1; |
| 4928 | dsi_vm->hfp_blanking_mode = 1; |
| 4929 | dsi_vm->hbp_blanking_mode = 1; |
| 4930 | |
| 4931 | dsi_vm->ddr_clk_always_on = cfg->ddr_clk_always_on; |
| 4932 | dsi_vm->window_sync = 4; |
| 4933 | |
| 4934 | /* setup DISPC videomode */ |
| 4935 | |
| 4936 | dispc_vm = &ctx->dispc_vm; |
| 4937 | *dispc_vm = *req_vm; |
Tomi Valkeinen | d8d78941 | 2013-04-10 14:12:14 +0300 | [diff] [blame] | 4938 | dispc_vm->pixelclock = dispc_pck; |
Tomi Valkeinen | f1e0001 | 2013-03-05 17:21:35 +0200 | [diff] [blame] | 4939 | |
| 4940 | if (cfg->trans_mode == OMAP_DSS_DSI_PULSE_MODE) { |
| 4941 | hsa = div64_u64((u64)req_vm->hsw * dispc_pck, |
| 4942 | req_pck_nom); |
| 4943 | hsa = max(hsa, 1); |
| 4944 | } else { |
| 4945 | hsa = 1; |
| 4946 | } |
| 4947 | |
| 4948 | hbp = div64_u64((u64)req_vm->hbp * dispc_pck, req_pck_nom); |
| 4949 | hbp = max(hbp, 1); |
| 4950 | |
| 4951 | hfp = dispc_hbl - hsa - hbp; |
| 4952 | if (hfp < 1) { |
| 4953 | int t; |
| 4954 | /* we need to take cycles from hbp */ |
| 4955 | |
| 4956 | t = 1 - hfp; |
| 4957 | hbp = max(hbp - t, 1); |
| 4958 | hfp = dispc_hbl - hsa - hbp; |
| 4959 | |
| 4960 | if (hfp < 1) { |
| 4961 | /* we need to take cycles from hsa */ |
| 4962 | t = 1 - hfp; |
| 4963 | hsa = max(hsa - t, 1); |
| 4964 | hfp = dispc_hbl - hsa - hbp; |
| 4965 | } |
| 4966 | } |
| 4967 | |
| 4968 | if (hfp < 1) |
| 4969 | return false; |
| 4970 | |
| 4971 | dispc_vm->hfp = hfp; |
| 4972 | dispc_vm->hsw = hsa; |
| 4973 | dispc_vm->hbp = hbp; |
| 4974 | |
| 4975 | return true; |
| 4976 | } |
| 4977 | |
| 4978 | |
| 4979 | static bool dsi_vm_calc_dispc_cb(int lckd, int pckd, unsigned long lck, |
| 4980 | unsigned long pck, void *data) |
| 4981 | { |
| 4982 | struct dsi_clk_calc_ctx *ctx = data; |
| 4983 | |
| 4984 | ctx->dispc_cinfo.lck_div = lckd; |
| 4985 | ctx->dispc_cinfo.pck_div = pckd; |
| 4986 | ctx->dispc_cinfo.lck = lck; |
| 4987 | ctx->dispc_cinfo.pck = pck; |
| 4988 | |
| 4989 | if (dsi_vm_calc_blanking(ctx) == false) |
| 4990 | return false; |
| 4991 | |
| 4992 | #ifdef PRINT_VERBOSE_VM_TIMINGS |
| 4993 | print_dispc_vm("dispc", &ctx->dispc_vm); |
| 4994 | print_dsi_vm("dsi ", &ctx->dsi_vm); |
| 4995 | print_dispc_vm("req ", ctx->config->timings); |
| 4996 | print_dsi_dispc_vm("act ", &ctx->dsi_vm); |
| 4997 | #endif |
| 4998 | |
| 4999 | return true; |
| 5000 | } |
| 5001 | |
| 5002 | static bool dsi_vm_calc_hsdiv_cb(int regm_dispc, unsigned long dispc, |
| 5003 | void *data) |
| 5004 | { |
| 5005 | struct dsi_clk_calc_ctx *ctx = data; |
| 5006 | unsigned long pck_max; |
| 5007 | |
| 5008 | ctx->dsi_cinfo.regm_dispc = regm_dispc; |
| 5009 | ctx->dsi_cinfo.dsi_pll_hsdiv_dispc_clk = dispc; |
| 5010 | |
| 5011 | /* |
| 5012 | * In burst mode we can let the dispc pck be arbitrarily high, but it |
| 5013 | * limits our scaling abilities. So for now, don't aim too high. |
| 5014 | */ |
| 5015 | |
| 5016 | if (ctx->config->trans_mode == OMAP_DSS_DSI_BURST_MODE) |
| 5017 | pck_max = ctx->req_pck_max + 10000000; |
| 5018 | else |
| 5019 | pck_max = ctx->req_pck_max; |
| 5020 | |
| 5021 | return dispc_div_calc(dispc, ctx->req_pck_min, pck_max, |
| 5022 | dsi_vm_calc_dispc_cb, ctx); |
| 5023 | } |
| 5024 | |
| 5025 | static bool dsi_vm_calc_pll_cb(int regn, int regm, unsigned long fint, |
| 5026 | unsigned long pll, void *data) |
| 5027 | { |
| 5028 | struct dsi_clk_calc_ctx *ctx = data; |
| 5029 | |
| 5030 | ctx->dsi_cinfo.regn = regn; |
| 5031 | ctx->dsi_cinfo.regm = regm; |
| 5032 | ctx->dsi_cinfo.fint = fint; |
| 5033 | ctx->dsi_cinfo.clkin4ddr = pll; |
| 5034 | |
| 5035 | return dsi_hsdiv_calc(ctx->dsidev, pll, ctx->req_pck_min, |
| 5036 | dsi_vm_calc_hsdiv_cb, ctx); |
| 5037 | } |
| 5038 | |
| 5039 | static bool dsi_vm_calc(struct dsi_data *dsi, |
| 5040 | const struct omap_dss_dsi_config *cfg, |
| 5041 | struct dsi_clk_calc_ctx *ctx) |
| 5042 | { |
| 5043 | const struct omap_video_timings *t = cfg->timings; |
| 5044 | unsigned long clkin; |
| 5045 | unsigned long pll_min; |
| 5046 | unsigned long pll_max; |
| 5047 | int ndl = dsi->num_lanes_used - 1; |
| 5048 | int bitspp = dsi_get_pixel_size(cfg->pixel_format); |
| 5049 | unsigned long byteclk_min; |
| 5050 | |
| 5051 | clkin = clk_get_rate(dsi->sys_clk); |
| 5052 | |
| 5053 | memset(ctx, 0, sizeof(*ctx)); |
| 5054 | ctx->dsidev = dsi->pdev; |
| 5055 | ctx->config = cfg; |
| 5056 | |
| 5057 | ctx->dsi_cinfo.clkin = clkin; |
| 5058 | |
| 5059 | /* these limits should come from the panel driver */ |
Tomi Valkeinen | d8d78941 | 2013-04-10 14:12:14 +0300 | [diff] [blame] | 5060 | ctx->req_pck_min = t->pixelclock - 1000; |
| 5061 | ctx->req_pck_nom = t->pixelclock; |
| 5062 | ctx->req_pck_max = t->pixelclock + 1000; |
Tomi Valkeinen | f1e0001 | 2013-03-05 17:21:35 +0200 | [diff] [blame] | 5063 | |
| 5064 | byteclk_min = div64_u64((u64)ctx->req_pck_min * bitspp, ndl * 8); |
| 5065 | pll_min = max(cfg->hs_clk_min * 4, byteclk_min * 4 * 4); |
| 5066 | |
| 5067 | if (cfg->trans_mode == OMAP_DSS_DSI_BURST_MODE) { |
| 5068 | pll_max = cfg->hs_clk_max * 4; |
| 5069 | } else { |
| 5070 | unsigned long byteclk_max; |
| 5071 | byteclk_max = div64_u64((u64)ctx->req_pck_max * bitspp, |
| 5072 | ndl * 8); |
| 5073 | |
| 5074 | pll_max = byteclk_max * 4 * 4; |
| 5075 | } |
| 5076 | |
| 5077 | return dsi_pll_calc(dsi->pdev, clkin, |
| 5078 | pll_min, pll_max, |
| 5079 | dsi_vm_calc_pll_cb, ctx); |
| 5080 | } |
| 5081 | |
Tomi Valkeinen | 5cfc1c3 | 2013-05-15 11:24:30 +0300 | [diff] [blame] | 5082 | static int dsi_set_config(struct omap_dss_device *dssdev, |
Tomi Valkeinen | 777f05c | 2013-03-06 11:10:29 +0200 | [diff] [blame] | 5083 | const struct omap_dss_dsi_config *config) |
Archit Taneja | e67458a | 2012-08-13 14:17:30 +0530 | [diff] [blame] | 5084 | { |
| 5085 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 5086 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | f1e0001 | 2013-03-05 17:21:35 +0200 | [diff] [blame] | 5087 | struct dsi_clk_calc_ctx ctx; |
| 5088 | bool ok; |
| 5089 | int r; |
Archit Taneja | e67458a | 2012-08-13 14:17:30 +0530 | [diff] [blame] | 5090 | |
| 5091 | mutex_lock(&dsi->lock); |
| 5092 | |
Tomi Valkeinen | 777f05c | 2013-03-06 11:10:29 +0200 | [diff] [blame] | 5093 | dsi->pix_fmt = config->pixel_format; |
| 5094 | dsi->mode = config->mode; |
| 5095 | |
Tomi Valkeinen | f1e0001 | 2013-03-05 17:21:35 +0200 | [diff] [blame] | 5096 | if (config->mode == OMAP_DSS_DSI_VIDEO_MODE) |
| 5097 | ok = dsi_vm_calc(dsi, config, &ctx); |
| 5098 | else |
| 5099 | ok = dsi_cm_calc(dsi, config, &ctx); |
| 5100 | |
| 5101 | if (!ok) { |
| 5102 | DSSERR("failed to find suitable DSI clock settings\n"); |
| 5103 | r = -EINVAL; |
| 5104 | goto err; |
| 5105 | } |
| 5106 | |
| 5107 | dsi_pll_calc_dsi_fck(&ctx.dsi_cinfo); |
| 5108 | |
| 5109 | r = dsi_lp_clock_calc(&ctx.dsi_cinfo, config->lp_clk_min, |
| 5110 | config->lp_clk_max); |
| 5111 | if (r) { |
| 5112 | DSSERR("failed to find suitable DSI LP clock settings\n"); |
| 5113 | goto err; |
| 5114 | } |
| 5115 | |
| 5116 | dsi->user_dsi_cinfo = ctx.dsi_cinfo; |
| 5117 | dsi->user_dispc_cinfo = ctx.dispc_cinfo; |
| 5118 | |
| 5119 | dsi->timings = ctx.dispc_vm; |
| 5120 | dsi->vm_timings = ctx.dsi_vm; |
Archit Taneja | e67458a | 2012-08-13 14:17:30 +0530 | [diff] [blame] | 5121 | |
| 5122 | mutex_unlock(&dsi->lock); |
Archit Taneja | e67458a | 2012-08-13 14:17:30 +0530 | [diff] [blame] | 5123 | |
Tomi Valkeinen | 777f05c | 2013-03-06 11:10:29 +0200 | [diff] [blame] | 5124 | return 0; |
Tomi Valkeinen | f1e0001 | 2013-03-05 17:21:35 +0200 | [diff] [blame] | 5125 | err: |
| 5126 | mutex_unlock(&dsi->lock); |
| 5127 | |
| 5128 | return r; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 5129 | } |
Archit Taneja | 0b3ffe3 | 2012-08-13 22:13:39 +0530 | [diff] [blame] | 5130 | |
Tomi Valkeinen | 2eea5ae | 2013-02-13 11:23:54 +0200 | [diff] [blame] | 5131 | /* |
| 5132 | * Return a hardcoded channel for the DSI output. This should work for |
| 5133 | * current use cases, but this can be later expanded to either resolve |
| 5134 | * the channel in some more dynamic manner, or get the channel as a user |
| 5135 | * parameter. |
| 5136 | */ |
| 5137 | static enum omap_channel dsi_get_channel(int module_id) |
Archit Taneja | e352574 | 2012-08-09 15:23:43 +0530 | [diff] [blame] | 5138 | { |
Tomi Valkeinen | 2eea5ae | 2013-02-13 11:23:54 +0200 | [diff] [blame] | 5139 | switch (omapdss_get_version()) { |
| 5140 | case OMAPDSS_VER_OMAP24xx: |
Sathya Prakash M R | d6279d4 | 2014-03-24 16:31:51 +0530 | [diff] [blame] | 5141 | case OMAPDSS_VER_AM43xx: |
Tomi Valkeinen | 2eea5ae | 2013-02-13 11:23:54 +0200 | [diff] [blame] | 5142 | DSSWARN("DSI not supported\n"); |
| 5143 | return OMAP_DSS_CHANNEL_LCD; |
Archit Taneja | e352574 | 2012-08-09 15:23:43 +0530 | [diff] [blame] | 5144 | |
Tomi Valkeinen | 2eea5ae | 2013-02-13 11:23:54 +0200 | [diff] [blame] | 5145 | case OMAPDSS_VER_OMAP34xx_ES1: |
| 5146 | case OMAPDSS_VER_OMAP34xx_ES3: |
| 5147 | case OMAPDSS_VER_OMAP3630: |
| 5148 | case OMAPDSS_VER_AM35xx: |
| 5149 | return OMAP_DSS_CHANNEL_LCD; |
Archit Taneja | e352574 | 2012-08-09 15:23:43 +0530 | [diff] [blame] | 5150 | |
Tomi Valkeinen | 2eea5ae | 2013-02-13 11:23:54 +0200 | [diff] [blame] | 5151 | case OMAPDSS_VER_OMAP4430_ES1: |
| 5152 | case OMAPDSS_VER_OMAP4430_ES2: |
| 5153 | case OMAPDSS_VER_OMAP4: |
| 5154 | switch (module_id) { |
| 5155 | case 0: |
| 5156 | return OMAP_DSS_CHANNEL_LCD; |
| 5157 | case 1: |
| 5158 | return OMAP_DSS_CHANNEL_LCD2; |
| 5159 | default: |
| 5160 | DSSWARN("unsupported module id\n"); |
| 5161 | return OMAP_DSS_CHANNEL_LCD; |
| 5162 | } |
Archit Taneja | e352574 | 2012-08-09 15:23:43 +0530 | [diff] [blame] | 5163 | |
Tomi Valkeinen | 2eea5ae | 2013-02-13 11:23:54 +0200 | [diff] [blame] | 5164 | case OMAPDSS_VER_OMAP5: |
| 5165 | switch (module_id) { |
| 5166 | case 0: |
| 5167 | return OMAP_DSS_CHANNEL_LCD; |
| 5168 | case 1: |
| 5169 | return OMAP_DSS_CHANNEL_LCD3; |
| 5170 | default: |
| 5171 | DSSWARN("unsupported module id\n"); |
| 5172 | return OMAP_DSS_CHANNEL_LCD; |
| 5173 | } |
| 5174 | |
| 5175 | default: |
| 5176 | DSSWARN("unsupported DSS version\n"); |
| 5177 | return OMAP_DSS_CHANNEL_LCD; |
| 5178 | } |
Archit Taneja | 02c3960 | 2012-08-10 15:01:33 +0530 | [diff] [blame] | 5179 | } |
Tomi Valkeinen | 5f42f2c | 2011-02-22 15:53:46 +0200 | [diff] [blame] | 5180 | |
Tomi Valkeinen | 5cfc1c3 | 2013-05-15 11:24:30 +0300 | [diff] [blame] | 5181 | static int dsi_request_vc(struct omap_dss_device *dssdev, int *channel) |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 5182 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5183 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 5184 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 5185 | int i; |
| 5186 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5187 | for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) { |
| 5188 | if (!dsi->vc[i].dssdev) { |
| 5189 | dsi->vc[i].dssdev = dssdev; |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 5190 | *channel = i; |
| 5191 | return 0; |
| 5192 | } |
| 5193 | } |
| 5194 | |
| 5195 | DSSERR("cannot get VC for display %s", dssdev->name); |
| 5196 | return -ENOSPC; |
| 5197 | } |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 5198 | |
Tomi Valkeinen | 5cfc1c3 | 2013-05-15 11:24:30 +0300 | [diff] [blame] | 5199 | static int dsi_set_vc_id(struct omap_dss_device *dssdev, int channel, int vc_id) |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 5200 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5201 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 5202 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 5203 | |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 5204 | if (vc_id < 0 || vc_id > 3) { |
| 5205 | DSSERR("VC ID out of range\n"); |
| 5206 | return -EINVAL; |
| 5207 | } |
| 5208 | |
| 5209 | if (channel < 0 || channel > 3) { |
| 5210 | DSSERR("Virtual Channel out of range\n"); |
| 5211 | return -EINVAL; |
| 5212 | } |
| 5213 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5214 | if (dsi->vc[channel].dssdev != dssdev) { |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 5215 | DSSERR("Virtual Channel not allocated to display %s\n", |
| 5216 | dssdev->name); |
| 5217 | return -EINVAL; |
| 5218 | } |
| 5219 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5220 | dsi->vc[channel].vc_id = vc_id; |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 5221 | |
| 5222 | return 0; |
| 5223 | } |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 5224 | |
Tomi Valkeinen | 5cfc1c3 | 2013-05-15 11:24:30 +0300 | [diff] [blame] | 5225 | static void dsi_release_vc(struct omap_dss_device *dssdev, int channel) |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 5226 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5227 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 5228 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 5229 | |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 5230 | if ((channel >= 0 && channel <= 3) && |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5231 | dsi->vc[channel].dssdev == dssdev) { |
| 5232 | dsi->vc[channel].dssdev = NULL; |
| 5233 | dsi->vc[channel].vc_id = 0; |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 5234 | } |
| 5235 | } |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 5236 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 5237 | void dsi_wait_pll_hsdiv_dispc_active(struct platform_device *dsidev) |
Tomi Valkeinen | e406f90 | 2010-06-09 15:28:12 +0300 | [diff] [blame] | 5238 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 5239 | if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 7, 1) != 1) |
Archit Taneja | 067a57e | 2011-03-02 11:57:25 +0530 | [diff] [blame] | 5240 | DSSERR("%s (%s) not active\n", |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 5241 | dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC), |
| 5242 | 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] | 5243 | } |
| 5244 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 5245 | void dsi_wait_pll_hsdiv_dsi_active(struct platform_device *dsidev) |
Tomi Valkeinen | e406f90 | 2010-06-09 15:28:12 +0300 | [diff] [blame] | 5246 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 5247 | if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 8, 1) != 1) |
Archit Taneja | 067a57e | 2011-03-02 11:57:25 +0530 | [diff] [blame] | 5248 | DSSERR("%s (%s) not active\n", |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 5249 | dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI), |
| 5250 | 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] | 5251 | } |
| 5252 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 5253 | static void dsi_calc_clock_param_ranges(struct platform_device *dsidev) |
Taneja, Archit | 4964111 | 2011-03-14 23:28:23 -0500 | [diff] [blame] | 5254 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5255 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 5256 | |
| 5257 | dsi->regn_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGN); |
| 5258 | dsi->regm_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM); |
| 5259 | dsi->regm_dispc_max = |
| 5260 | dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DISPC); |
| 5261 | dsi->regm_dsi_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DSI); |
| 5262 | dsi->fint_min = dss_feat_get_param_min(FEAT_PARAM_DSIPLL_FINT); |
| 5263 | dsi->fint_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_FINT); |
| 5264 | dsi->lpdiv_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_LPDIV); |
Taneja, Archit | 4964111 | 2011-03-14 23:28:23 -0500 | [diff] [blame] | 5265 | } |
| 5266 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5267 | static int dsi_get_clocks(struct platform_device *dsidev) |
| 5268 | { |
| 5269 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 5270 | struct clk *clk; |
| 5271 | |
Sachin Kamat | 5303b3a | 2013-04-02 14:33:00 +0300 | [diff] [blame] | 5272 | clk = devm_clk_get(&dsidev->dev, "fck"); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5273 | if (IS_ERR(clk)) { |
| 5274 | DSSERR("can't get fck\n"); |
| 5275 | return PTR_ERR(clk); |
| 5276 | } |
| 5277 | |
| 5278 | dsi->dss_clk = clk; |
| 5279 | |
Sachin Kamat | 5303b3a | 2013-04-02 14:33:00 +0300 | [diff] [blame] | 5280 | clk = devm_clk_get(&dsidev->dev, "sys_clk"); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5281 | if (IS_ERR(clk)) { |
| 5282 | DSSERR("can't get sys_clk\n"); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5283 | return PTR_ERR(clk); |
| 5284 | } |
| 5285 | |
| 5286 | dsi->sys_clk = clk; |
| 5287 | |
| 5288 | return 0; |
| 5289 | } |
| 5290 | |
Tomi Valkeinen | deb16df | 2013-05-24 13:20:27 +0300 | [diff] [blame] | 5291 | static int dsi_connect(struct omap_dss_device *dssdev, |
| 5292 | struct omap_dss_device *dst) |
| 5293 | { |
| 5294 | struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); |
| 5295 | struct omap_overlay_manager *mgr; |
| 5296 | int r; |
| 5297 | |
| 5298 | r = dsi_regulator_init(dsidev); |
| 5299 | if (r) |
| 5300 | return r; |
| 5301 | |
| 5302 | mgr = omap_dss_get_overlay_manager(dssdev->dispc_channel); |
| 5303 | if (!mgr) |
| 5304 | return -ENODEV; |
| 5305 | |
| 5306 | r = dss_mgr_connect(mgr, dssdev); |
| 5307 | if (r) |
| 5308 | return r; |
| 5309 | |
| 5310 | r = omapdss_output_set_device(dssdev, dst); |
| 5311 | if (r) { |
| 5312 | DSSERR("failed to connect output to new device: %s\n", |
| 5313 | dssdev->name); |
| 5314 | dss_mgr_disconnect(mgr, dssdev); |
| 5315 | return r; |
| 5316 | } |
| 5317 | |
| 5318 | return 0; |
| 5319 | } |
| 5320 | |
| 5321 | static void dsi_disconnect(struct omap_dss_device *dssdev, |
| 5322 | struct omap_dss_device *dst) |
| 5323 | { |
Tomi Valkeinen | 9560dc10 | 2013-07-24 13:06:54 +0300 | [diff] [blame] | 5324 | WARN_ON(dst != dssdev->dst); |
Tomi Valkeinen | deb16df | 2013-05-24 13:20:27 +0300 | [diff] [blame] | 5325 | |
Tomi Valkeinen | 9560dc10 | 2013-07-24 13:06:54 +0300 | [diff] [blame] | 5326 | if (dst != dssdev->dst) |
Tomi Valkeinen | deb16df | 2013-05-24 13:20:27 +0300 | [diff] [blame] | 5327 | return; |
| 5328 | |
| 5329 | omapdss_output_unset_device(dssdev); |
| 5330 | |
| 5331 | if (dssdev->manager) |
| 5332 | dss_mgr_disconnect(dssdev->manager, dssdev); |
| 5333 | } |
| 5334 | |
| 5335 | static const struct omapdss_dsi_ops dsi_ops = { |
| 5336 | .connect = dsi_connect, |
| 5337 | .disconnect = dsi_disconnect, |
| 5338 | |
| 5339 | .bus_lock = dsi_bus_lock, |
| 5340 | .bus_unlock = dsi_bus_unlock, |
| 5341 | |
Tomi Valkeinen | 5cfc1c3 | 2013-05-15 11:24:30 +0300 | [diff] [blame] | 5342 | .enable = dsi_display_enable, |
| 5343 | .disable = dsi_display_disable, |
Tomi Valkeinen | deb16df | 2013-05-24 13:20:27 +0300 | [diff] [blame] | 5344 | |
Tomi Valkeinen | 5cfc1c3 | 2013-05-15 11:24:30 +0300 | [diff] [blame] | 5345 | .enable_hs = dsi_vc_enable_hs, |
Tomi Valkeinen | deb16df | 2013-05-24 13:20:27 +0300 | [diff] [blame] | 5346 | |
Tomi Valkeinen | 5cfc1c3 | 2013-05-15 11:24:30 +0300 | [diff] [blame] | 5347 | .configure_pins = dsi_configure_pins, |
| 5348 | .set_config = dsi_set_config, |
Tomi Valkeinen | deb16df | 2013-05-24 13:20:27 +0300 | [diff] [blame] | 5349 | |
| 5350 | .enable_video_output = dsi_enable_video_output, |
| 5351 | .disable_video_output = dsi_disable_video_output, |
| 5352 | |
Tomi Valkeinen | 5cfc1c3 | 2013-05-15 11:24:30 +0300 | [diff] [blame] | 5353 | .update = dsi_update, |
Tomi Valkeinen | deb16df | 2013-05-24 13:20:27 +0300 | [diff] [blame] | 5354 | |
Tomi Valkeinen | 5cfc1c3 | 2013-05-15 11:24:30 +0300 | [diff] [blame] | 5355 | .enable_te = dsi_enable_te, |
Tomi Valkeinen | deb16df | 2013-05-24 13:20:27 +0300 | [diff] [blame] | 5356 | |
Tomi Valkeinen | 5cfc1c3 | 2013-05-15 11:24:30 +0300 | [diff] [blame] | 5357 | .request_vc = dsi_request_vc, |
| 5358 | .set_vc_id = dsi_set_vc_id, |
| 5359 | .release_vc = dsi_release_vc, |
Tomi Valkeinen | deb16df | 2013-05-24 13:20:27 +0300 | [diff] [blame] | 5360 | |
| 5361 | .dcs_write = dsi_vc_dcs_write, |
| 5362 | .dcs_write_nosync = dsi_vc_dcs_write_nosync, |
| 5363 | .dcs_read = dsi_vc_dcs_read, |
| 5364 | |
| 5365 | .gen_write = dsi_vc_generic_write, |
| 5366 | .gen_write_nosync = dsi_vc_generic_write_nosync, |
| 5367 | .gen_read = dsi_vc_generic_read, |
| 5368 | |
| 5369 | .bta_sync = dsi_vc_send_bta_sync, |
| 5370 | |
| 5371 | .set_max_rx_packet_size = dsi_vc_set_max_rx_packet_size, |
| 5372 | }; |
| 5373 | |
Tomi Valkeinen | ee4a24e | 2013-04-26 13:47:06 +0300 | [diff] [blame] | 5374 | static void dsi_init_output(struct platform_device *dsidev) |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 5375 | { |
| 5376 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 1f68d9c | 2013-04-19 15:09:34 +0300 | [diff] [blame] | 5377 | struct omap_dss_device *out = &dsi->output; |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 5378 | |
Tomi Valkeinen | 1f68d9c | 2013-04-19 15:09:34 +0300 | [diff] [blame] | 5379 | out->dev = &dsidev->dev; |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 5380 | out->id = dsi->module_id == 0 ? |
| 5381 | OMAP_DSS_OUTPUT_DSI1 : OMAP_DSS_OUTPUT_DSI2; |
| 5382 | |
Tomi Valkeinen | 1f68d9c | 2013-04-19 15:09:34 +0300 | [diff] [blame] | 5383 | out->output_type = OMAP_DISPLAY_TYPE_DSI; |
Tomi Valkeinen | 7286a08 | 2013-02-18 13:06:01 +0200 | [diff] [blame] | 5384 | out->name = dsi->module_id == 0 ? "dsi.0" : "dsi.1"; |
Tomi Valkeinen | 2eea5ae | 2013-02-13 11:23:54 +0200 | [diff] [blame] | 5385 | out->dispc_channel = dsi_get_channel(dsi->module_id); |
Tomi Valkeinen | deb16df | 2013-05-24 13:20:27 +0300 | [diff] [blame] | 5386 | out->ops.dsi = &dsi_ops; |
Tomi Valkeinen | b7328e1 | 2013-05-03 11:42:18 +0300 | [diff] [blame] | 5387 | out->owner = THIS_MODULE; |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 5388 | |
Tomi Valkeinen | 5d47dbc | 2013-04-24 13:32:51 +0300 | [diff] [blame] | 5389 | omapdss_register_output(out); |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 5390 | } |
| 5391 | |
Tomi Valkeinen | d1890a6 | 2013-04-26 13:47:41 +0300 | [diff] [blame] | 5392 | static void dsi_uninit_output(struct platform_device *dsidev) |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 5393 | { |
| 5394 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
Tomi Valkeinen | 1f68d9c | 2013-04-19 15:09:34 +0300 | [diff] [blame] | 5395 | struct omap_dss_device *out = &dsi->output; |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 5396 | |
Tomi Valkeinen | 5d47dbc | 2013-04-24 13:32:51 +0300 | [diff] [blame] | 5397 | omapdss_unregister_output(out); |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 5398 | } |
| 5399 | |
Tomi Valkeinen | 6274a61 | 2012-08-21 15:35:42 +0300 | [diff] [blame] | 5400 | static int dsi_probe_of(struct platform_device *pdev) |
| 5401 | { |
| 5402 | struct device_node *node = pdev->dev.of_node; |
| 5403 | struct dsi_data *dsi = dsi_get_dsidrv_data(pdev); |
| 5404 | struct property *prop; |
| 5405 | u32 lane_arr[10]; |
| 5406 | int len, num_pins; |
| 5407 | int r, i; |
| 5408 | struct device_node *ep; |
| 5409 | struct omap_dsi_pin_config pin_cfg; |
| 5410 | |
| 5411 | ep = omapdss_of_get_first_endpoint(node); |
| 5412 | if (!ep) |
| 5413 | return 0; |
| 5414 | |
| 5415 | prop = of_find_property(ep, "lanes", &len); |
| 5416 | if (prop == NULL) { |
| 5417 | dev_err(&pdev->dev, "failed to find lane data\n"); |
| 5418 | r = -EINVAL; |
| 5419 | goto err; |
| 5420 | } |
| 5421 | |
| 5422 | num_pins = len / sizeof(u32); |
| 5423 | |
| 5424 | if (num_pins < 4 || num_pins % 2 != 0 || |
| 5425 | num_pins > dsi->num_lanes_supported * 2) { |
| 5426 | dev_err(&pdev->dev, "bad number of lanes\n"); |
| 5427 | r = -EINVAL; |
| 5428 | goto err; |
| 5429 | } |
| 5430 | |
| 5431 | r = of_property_read_u32_array(ep, "lanes", lane_arr, num_pins); |
| 5432 | if (r) { |
| 5433 | dev_err(&pdev->dev, "failed to read lane data\n"); |
| 5434 | goto err; |
| 5435 | } |
| 5436 | |
| 5437 | pin_cfg.num_pins = num_pins; |
| 5438 | for (i = 0; i < num_pins; ++i) |
| 5439 | pin_cfg.pins[i] = (int)lane_arr[i]; |
| 5440 | |
| 5441 | r = dsi_configure_pins(&dsi->output, &pin_cfg); |
| 5442 | if (r) { |
| 5443 | dev_err(&pdev->dev, "failed to configure pins"); |
| 5444 | goto err; |
| 5445 | } |
| 5446 | |
| 5447 | of_node_put(ep); |
| 5448 | |
| 5449 | return 0; |
| 5450 | |
| 5451 | err: |
| 5452 | of_node_put(ep); |
| 5453 | return r; |
| 5454 | } |
| 5455 | |
Tomi Valkeinen | b98482e | 2011-05-16 13:52:51 +0300 | [diff] [blame] | 5456 | /* DSI1 HW IP initialisation */ |
Tomi Valkeinen | ee4a24e | 2013-04-26 13:47:06 +0300 | [diff] [blame] | 5457 | static int omap_dsihw_probe(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 5458 | { |
| 5459 | u32 rev; |
Tomi Valkeinen | 11ee960 | 2012-03-09 16:07:39 +0200 | [diff] [blame] | 5460 | int r, i; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5461 | struct dsi_data *dsi; |
Tomi Valkeinen | 6274a61 | 2012-08-21 15:35:42 +0300 | [diff] [blame] | 5462 | struct resource *dsi_mem; |
Tomi Valkeinen | 6810446 | 2013-12-17 13:53:28 +0200 | [diff] [blame] | 5463 | struct resource *res; |
| 5464 | struct resource temp_res; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 5465 | |
Julia Lawall | 6e2a14d | 2012-01-24 14:00:45 +0100 | [diff] [blame] | 5466 | dsi = devm_kzalloc(&dsidev->dev, sizeof(*dsi), GFP_KERNEL); |
Tomi Valkeinen | cd3b344 | 2012-01-25 13:31:04 +0200 | [diff] [blame] | 5467 | if (!dsi) |
| 5468 | return -ENOMEM; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5469 | |
| 5470 | dsi->pdev = dsidev; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5471 | dev_set_drvdata(&dsidev->dev, dsi); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 5472 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5473 | spin_lock_init(&dsi->irq_lock); |
| 5474 | spin_lock_init(&dsi->errors_lock); |
| 5475 | dsi->errors = 0; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 5476 | |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 5477 | #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5478 | spin_lock_init(&dsi->irq_stats_lock); |
| 5479 | dsi->irq_stats.last_reset = jiffies; |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 5480 | #endif |
| 5481 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5482 | mutex_init(&dsi->lock); |
| 5483 | sema_init(&dsi->bus_lock, 1); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 5484 | |
Tejun Heo | 203b42f | 2012-08-21 13:18:23 -0700 | [diff] [blame] | 5485 | INIT_DEFERRABLE_WORK(&dsi->framedone_timeout_work, |
| 5486 | dsi_framedone_timeout_work_callback); |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5487 | |
| 5488 | #ifdef DSI_CATCH_MISSING_TE |
| 5489 | init_timer(&dsi->te_timer); |
| 5490 | dsi->te_timer.function = dsi_te_timeout; |
| 5491 | dsi->te_timer.data = 0; |
| 5492 | #endif |
Tomi Valkeinen | 6810446 | 2013-12-17 13:53:28 +0200 | [diff] [blame] | 5493 | |
| 5494 | res = platform_get_resource_byname(dsidev, IORESOURCE_MEM, "proto"); |
| 5495 | if (!res) { |
| 5496 | res = platform_get_resource(dsidev, IORESOURCE_MEM, 0); |
| 5497 | if (!res) { |
| 5498 | DSSERR("can't get IORESOURCE_MEM DSI\n"); |
| 5499 | return -EINVAL; |
| 5500 | } |
| 5501 | |
| 5502 | temp_res.start = res->start; |
| 5503 | temp_res.end = temp_res.start + DSI_PROTO_SZ - 1; |
| 5504 | res = &temp_res; |
archit taneja | affe360 | 2011-02-23 08:41:03 +0000 | [diff] [blame] | 5505 | } |
Tomi Valkeinen | cd3b344 | 2012-01-25 13:31:04 +0200 | [diff] [blame] | 5506 | |
Tomi Valkeinen | 6274a61 | 2012-08-21 15:35:42 +0300 | [diff] [blame] | 5507 | dsi_mem = res; |
| 5508 | |
Tomi Valkeinen | 6810446 | 2013-12-17 13:53:28 +0200 | [diff] [blame] | 5509 | dsi->proto_base = devm_ioremap(&dsidev->dev, res->start, |
| 5510 | resource_size(res)); |
| 5511 | if (!dsi->proto_base) { |
| 5512 | DSSERR("can't ioremap DSI protocol engine\n"); |
| 5513 | return -ENOMEM; |
| 5514 | } |
| 5515 | |
| 5516 | res = platform_get_resource_byname(dsidev, IORESOURCE_MEM, "phy"); |
| 5517 | if (!res) { |
| 5518 | res = platform_get_resource(dsidev, IORESOURCE_MEM, 0); |
| 5519 | if (!res) { |
| 5520 | DSSERR("can't get IORESOURCE_MEM DSI\n"); |
| 5521 | return -EINVAL; |
| 5522 | } |
| 5523 | |
| 5524 | temp_res.start = res->start + DSI_PHY_OFFSET; |
| 5525 | temp_res.end = temp_res.start + DSI_PHY_SZ - 1; |
| 5526 | res = &temp_res; |
| 5527 | } |
| 5528 | |
| 5529 | dsi->phy_base = devm_ioremap(&dsidev->dev, res->start, |
| 5530 | resource_size(res)); |
| 5531 | if (!dsi->proto_base) { |
| 5532 | DSSERR("can't ioremap DSI PHY\n"); |
| 5533 | return -ENOMEM; |
| 5534 | } |
| 5535 | |
| 5536 | res = platform_get_resource_byname(dsidev, IORESOURCE_MEM, "pll"); |
| 5537 | if (!res) { |
| 5538 | res = platform_get_resource(dsidev, IORESOURCE_MEM, 0); |
| 5539 | if (!res) { |
| 5540 | DSSERR("can't get IORESOURCE_MEM DSI\n"); |
| 5541 | return -EINVAL; |
| 5542 | } |
| 5543 | |
| 5544 | temp_res.start = res->start + DSI_PLL_OFFSET; |
| 5545 | temp_res.end = temp_res.start + DSI_PLL_SZ - 1; |
| 5546 | res = &temp_res; |
| 5547 | } |
| 5548 | |
| 5549 | dsi->pll_base = devm_ioremap(&dsidev->dev, res->start, |
| 5550 | resource_size(res)); |
| 5551 | if (!dsi->proto_base) { |
| 5552 | DSSERR("can't ioremap DSI PLL\n"); |
Tomi Valkeinen | cd3b344 | 2012-01-25 13:31:04 +0200 | [diff] [blame] | 5553 | return -ENOMEM; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5554 | } |
Tomi Valkeinen | cd3b344 | 2012-01-25 13:31:04 +0200 | [diff] [blame] | 5555 | |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5556 | dsi->irq = platform_get_irq(dsi->pdev, 0); |
| 5557 | if (dsi->irq < 0) { |
| 5558 | DSSERR("platform_get_irq failed\n"); |
Tomi Valkeinen | cd3b344 | 2012-01-25 13:31:04 +0200 | [diff] [blame] | 5559 | return -ENODEV; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5560 | } |
archit taneja | affe360 | 2011-02-23 08:41:03 +0000 | [diff] [blame] | 5561 | |
Julia Lawall | 6e2a14d | 2012-01-24 14:00:45 +0100 | [diff] [blame] | 5562 | r = devm_request_irq(&dsidev->dev, dsi->irq, omap_dsi_irq_handler, |
| 5563 | IRQF_SHARED, dev_name(&dsidev->dev), dsi->pdev); |
archit taneja | affe360 | 2011-02-23 08:41:03 +0000 | [diff] [blame] | 5564 | if (r < 0) { |
| 5565 | DSSERR("request_irq failed\n"); |
Tomi Valkeinen | cd3b344 | 2012-01-25 13:31:04 +0200 | [diff] [blame] | 5566 | return r; |
archit taneja | affe360 | 2011-02-23 08:41:03 +0000 | [diff] [blame] | 5567 | } |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 5568 | |
Tomi Valkeinen | 6274a61 | 2012-08-21 15:35:42 +0300 | [diff] [blame] | 5569 | if (dsidev->dev.of_node) { |
| 5570 | const struct of_device_id *match; |
| 5571 | const struct dsi_module_id_data *d; |
| 5572 | |
| 5573 | match = of_match_node(dsi_of_match, dsidev->dev.of_node); |
| 5574 | if (!match) { |
| 5575 | DSSERR("unsupported DSI module\n"); |
| 5576 | return -ENODEV; |
| 5577 | } |
| 5578 | |
| 5579 | d = match->data; |
| 5580 | |
| 5581 | while (d->address != 0 && d->address != dsi_mem->start) |
| 5582 | d++; |
| 5583 | |
| 5584 | if (d->address == 0) { |
| 5585 | DSSERR("unsupported DSI module\n"); |
| 5586 | return -ENODEV; |
| 5587 | } |
| 5588 | |
| 5589 | dsi->module_id = d->id; |
| 5590 | } else { |
| 5591 | dsi->module_id = dsidev->id; |
| 5592 | } |
| 5593 | |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 5594 | /* DSI VCs initialization */ |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5595 | for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) { |
Archit Taneja | d604914 | 2011-08-22 11:58:08 +0530 | [diff] [blame] | 5596 | dsi->vc[i].source = DSI_VC_SOURCE_L4; |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5597 | dsi->vc[i].dssdev = NULL; |
| 5598 | dsi->vc[i].vc_id = 0; |
Archit Taneja | 5ee3c14 | 2011-03-02 12:35:53 +0530 | [diff] [blame] | 5599 | } |
| 5600 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 5601 | dsi_calc_clock_param_ranges(dsidev); |
Taneja, Archit | 4964111 | 2011-03-14 23:28:23 -0500 | [diff] [blame] | 5602 | |
Tomi Valkeinen | cd3b344 | 2012-01-25 13:31:04 +0200 | [diff] [blame] | 5603 | r = dsi_get_clocks(dsidev); |
| 5604 | if (r) |
| 5605 | return r; |
| 5606 | |
| 5607 | pm_runtime_enable(&dsidev->dev); |
| 5608 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5609 | r = dsi_runtime_get(dsidev); |
| 5610 | if (r) |
Tomi Valkeinen | cd3b344 | 2012-01-25 13:31:04 +0200 | [diff] [blame] | 5611 | goto err_runtime_get; |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 5612 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 5613 | rev = dsi_read_reg(dsidev, DSI_REVISION); |
| 5614 | dev_dbg(&dsidev->dev, "OMAP DSI rev %d.%d\n", |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 5615 | FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0)); |
| 5616 | |
Tomi Valkeinen | d982085 | 2011-10-12 15:05:59 +0300 | [diff] [blame] | 5617 | /* DSI on OMAP3 doesn't have register DSI_GNQ, set number |
| 5618 | * of data to 3 by default */ |
| 5619 | if (dss_has_feature(FEAT_DSI_GNQ)) |
| 5620 | /* NB_DATA_LANES */ |
| 5621 | dsi->num_lanes_supported = 1 + REG_GET(dsidev, DSI_GNQ, 11, 9); |
| 5622 | else |
| 5623 | dsi->num_lanes_supported = 3; |
Archit Taneja | 75d7247 | 2011-05-16 15:17:08 +0530 | [diff] [blame] | 5624 | |
Tomi Valkeinen | 9932257 | 2013-03-05 10:37:02 +0200 | [diff] [blame] | 5625 | dsi->line_buffer_size = dsi_get_line_buf_size(dsidev); |
| 5626 | |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 5627 | dsi_init_output(dsidev); |
| 5628 | |
Tomi Valkeinen | 6274a61 | 2012-08-21 15:35:42 +0300 | [diff] [blame] | 5629 | if (dsidev->dev.of_node) { |
| 5630 | r = dsi_probe_of(dsidev); |
| 5631 | if (r) { |
| 5632 | DSSERR("Invalid DSI DT data\n"); |
| 5633 | goto err_probe_of; |
| 5634 | } |
| 5635 | |
| 5636 | r = of_platform_populate(dsidev->dev.of_node, NULL, NULL, |
| 5637 | &dsidev->dev); |
| 5638 | if (r) |
| 5639 | DSSERR("Failed to populate DSI child devices: %d\n", r); |
| 5640 | } |
| 5641 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5642 | dsi_runtime_put(dsidev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 5643 | |
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_regs", dsi1_dump_regs); |
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_regs", dsi2_dump_regs); |
| 5648 | |
| 5649 | #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS |
Tomi Valkeinen | 11ee960 | 2012-03-09 16:07:39 +0200 | [diff] [blame] | 5650 | if (dsi->module_id == 0) |
Tomi Valkeinen | e40402c | 2012-03-02 18:01:07 +0200 | [diff] [blame] | 5651 | dss_debugfs_create_file("dsi1_irqs", dsi1_dump_irqs); |
Tomi Valkeinen | 11ee960 | 2012-03-09 16:07:39 +0200 | [diff] [blame] | 5652 | else if (dsi->module_id == 1) |
Tomi Valkeinen | e40402c | 2012-03-02 18:01:07 +0200 | [diff] [blame] | 5653 | dss_debugfs_create_file("dsi2_irqs", dsi2_dump_irqs); |
| 5654 | #endif |
Tomi Valkeinen | 6274a61 | 2012-08-21 15:35:42 +0300 | [diff] [blame] | 5655 | |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 5656 | return 0; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5657 | |
Tomi Valkeinen | 6274a61 | 2012-08-21 15:35:42 +0300 | [diff] [blame] | 5658 | err_probe_of: |
| 5659 | dsi_uninit_output(dsidev); |
| 5660 | dsi_runtime_put(dsidev); |
| 5661 | |
Tomi Valkeinen | cd3b344 | 2012-01-25 13:31:04 +0200 | [diff] [blame] | 5662 | err_runtime_get: |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5663 | pm_runtime_disable(&dsidev->dev); |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 5664 | return r; |
| 5665 | } |
| 5666 | |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 5667 | static int __exit omap_dsihw_remove(struct platform_device *dsidev) |
Tomi Valkeinen | 3de7a1d | 2009-10-28 11:59:56 +0200 | [diff] [blame] | 5668 | { |
Archit Taneja | f1da39d | 2011-05-12 17:26:27 +0530 | [diff] [blame] | 5669 | struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); |
| 5670 | |
Tomi Valkeinen | e4e42b8 | 2014-07-31 16:15:39 +0300 | [diff] [blame] | 5671 | of_platform_depopulate(&dsidev->dev); |
Tomi Valkeinen | 6274a61 | 2012-08-21 15:35:42 +0300 | [diff] [blame] | 5672 | |
Tomi Valkeinen | b98482e | 2011-05-16 13:52:51 +0300 | [diff] [blame] | 5673 | WARN_ON(dsi->scp_clk_refcount > 0); |
| 5674 | |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 5675 | dsi_uninit_output(dsidev); |
| 5676 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5677 | pm_runtime_disable(&dsidev->dev); |
| 5678 | |
Tomi Valkeinen | b2541c4 | 2013-05-03 13:42:24 +0300 | [diff] [blame] | 5679 | if (dsi->vdds_dsi_reg != NULL && dsi->vdds_dsi_enabled) { |
| 5680 | regulator_disable(dsi->vdds_dsi_reg); |
| 5681 | dsi->vdds_dsi_enabled = false; |
Senthilvadivu Guruswamy | c8aac01 | 2011-01-24 06:22:02 +0000 | [diff] [blame] | 5682 | } |
| 5683 | |
Senthilvadivu Guruswamy | c8aac01 | 2011-01-24 06:22:02 +0000 | [diff] [blame] | 5684 | return 0; |
| 5685 | } |
| 5686 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5687 | static int dsi_runtime_suspend(struct device *dev) |
| 5688 | { |
Tomi Valkeinen | 0925afc | 2014-04-11 13:49:55 +0300 | [diff] [blame] | 5689 | struct platform_device *pdev = to_platform_device(dev); |
| 5690 | struct dsi_data *dsi = dsi_get_dsidrv_data(pdev); |
| 5691 | |
| 5692 | dsi->is_enabled = false; |
| 5693 | /* ensure the irq handler sees the is_enabled value */ |
| 5694 | smp_wmb(); |
| 5695 | /* wait for current handler to finish before turning the DSI off */ |
| 5696 | synchronize_irq(dsi->irq); |
| 5697 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5698 | dispc_runtime_put(); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5699 | |
| 5700 | return 0; |
| 5701 | } |
| 5702 | |
| 5703 | static int dsi_runtime_resume(struct device *dev) |
| 5704 | { |
Tomi Valkeinen | 0925afc | 2014-04-11 13:49:55 +0300 | [diff] [blame] | 5705 | struct platform_device *pdev = to_platform_device(dev); |
| 5706 | struct dsi_data *dsi = dsi_get_dsidrv_data(pdev); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5707 | int r; |
| 5708 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5709 | r = dispc_runtime_get(); |
| 5710 | if (r) |
Tomi Valkeinen | 852f083 | 2012-02-17 17:58:04 +0200 | [diff] [blame] | 5711 | return r; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5712 | |
Tomi Valkeinen | 0925afc | 2014-04-11 13:49:55 +0300 | [diff] [blame] | 5713 | dsi->is_enabled = true; |
| 5714 | /* ensure the irq handler sees the is_enabled value */ |
| 5715 | smp_wmb(); |
| 5716 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5717 | return 0; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5718 | } |
| 5719 | |
| 5720 | static const struct dev_pm_ops dsi_pm_ops = { |
| 5721 | .runtime_suspend = dsi_runtime_suspend, |
| 5722 | .runtime_resume = dsi_runtime_resume, |
| 5723 | }; |
| 5724 | |
Tomi Valkeinen | 6274a61 | 2012-08-21 15:35:42 +0300 | [diff] [blame] | 5725 | static const struct dsi_module_id_data dsi_of_data_omap3[] = { |
| 5726 | { .address = 0x4804fc00, .id = 0, }, |
| 5727 | { }, |
| 5728 | }; |
| 5729 | |
| 5730 | static const struct dsi_module_id_data dsi_of_data_omap4[] = { |
| 5731 | { .address = 0x58004000, .id = 0, }, |
| 5732 | { .address = 0x58005000, .id = 1, }, |
| 5733 | { }, |
| 5734 | }; |
| 5735 | |
Tomi Valkeinen | bd3ad6a | 2014-03-07 12:44:24 +0200 | [diff] [blame] | 5736 | static const struct dsi_module_id_data dsi_of_data_omap5[] = { |
| 5737 | { .address = 0x58004000, .id = 0, }, |
| 5738 | { .address = 0x58009000, .id = 1, }, |
| 5739 | { }, |
| 5740 | }; |
| 5741 | |
Tomi Valkeinen | 6274a61 | 2012-08-21 15:35:42 +0300 | [diff] [blame] | 5742 | static const struct of_device_id dsi_of_match[] = { |
| 5743 | { .compatible = "ti,omap3-dsi", .data = dsi_of_data_omap3, }, |
| 5744 | { .compatible = "ti,omap4-dsi", .data = dsi_of_data_omap4, }, |
Tomi Valkeinen | bd3ad6a | 2014-03-07 12:44:24 +0200 | [diff] [blame] | 5745 | { .compatible = "ti,omap5-dsi", .data = dsi_of_data_omap5, }, |
Tomi Valkeinen | 6274a61 | 2012-08-21 15:35:42 +0300 | [diff] [blame] | 5746 | {}, |
| 5747 | }; |
| 5748 | |
Tomi Valkeinen | 7c68dd9 | 2011-08-03 14:00:57 +0300 | [diff] [blame] | 5749 | static struct platform_driver omap_dsihw_driver = { |
Tomi Valkeinen | ee4a24e | 2013-04-26 13:47:06 +0300 | [diff] [blame] | 5750 | .probe = omap_dsihw_probe, |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 5751 | .remove = __exit_p(omap_dsihw_remove), |
Senthilvadivu Guruswamy | c8aac01 | 2011-01-24 06:22:02 +0000 | [diff] [blame] | 5752 | .driver = { |
Tomi Valkeinen | 7c68dd9 | 2011-08-03 14:00:57 +0300 | [diff] [blame] | 5753 | .name = "omapdss_dsi", |
Senthilvadivu Guruswamy | c8aac01 | 2011-01-24 06:22:02 +0000 | [diff] [blame] | 5754 | .owner = THIS_MODULE, |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 5755 | .pm = &dsi_pm_ops, |
Tomi Valkeinen | 6274a61 | 2012-08-21 15:35:42 +0300 | [diff] [blame] | 5756 | .of_match_table = dsi_of_match, |
Senthilvadivu Guruswamy | c8aac01 | 2011-01-24 06:22:02 +0000 | [diff] [blame] | 5757 | }, |
| 5758 | }; |
| 5759 | |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 5760 | int __init dsi_init_platform_driver(void) |
Senthilvadivu Guruswamy | c8aac01 | 2011-01-24 06:22:02 +0000 | [diff] [blame] | 5761 | { |
Tomi Valkeinen | ee4a24e | 2013-04-26 13:47:06 +0300 | [diff] [blame] | 5762 | return platform_driver_register(&omap_dsihw_driver); |
Senthilvadivu Guruswamy | c8aac01 | 2011-01-24 06:22:02 +0000 | [diff] [blame] | 5763 | } |
| 5764 | |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 5765 | void __exit dsi_uninit_platform_driver(void) |
Senthilvadivu Guruswamy | c8aac01 | 2011-01-24 06:22:02 +0000 | [diff] [blame] | 5766 | { |
Tomi Valkeinen | 04c742c | 2012-02-23 15:32:37 +0200 | [diff] [blame] | 5767 | platform_driver_unregister(&omap_dsihw_driver); |
Senthilvadivu Guruswamy | c8aac01 | 2011-01-24 06:22:02 +0000 | [diff] [blame] | 5768 | } |