1caab277bSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 2f76ee892STomi Valkeinen /* 3f76ee892STomi Valkeinen * linux/drivers/video/omap2/dss/dsi.c 4f76ee892STomi Valkeinen * 5f76ee892STomi Valkeinen * Copyright (C) 2009 Nokia Corporation 6f76ee892STomi Valkeinen * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com> 7f76ee892STomi Valkeinen */ 8f76ee892STomi Valkeinen 9f76ee892STomi Valkeinen #define DSS_SUBSYS_NAME "DSI" 10f76ee892STomi Valkeinen 11f76ee892STomi Valkeinen #include <linux/kernel.h> 12f76ee892STomi Valkeinen #include <linux/io.h> 13f76ee892STomi Valkeinen #include <linux/clk.h> 14f76ee892STomi Valkeinen #include <linux/device.h> 15f76ee892STomi Valkeinen #include <linux/err.h> 16f76ee892STomi Valkeinen #include <linux/interrupt.h> 17f76ee892STomi Valkeinen #include <linux/delay.h> 18f76ee892STomi Valkeinen #include <linux/mutex.h> 19f76ee892STomi Valkeinen #include <linux/module.h> 20f76ee892STomi Valkeinen #include <linux/semaphore.h> 21f76ee892STomi Valkeinen #include <linux/seq_file.h> 22f76ee892STomi Valkeinen #include <linux/platform_device.h> 23f76ee892STomi Valkeinen #include <linux/regulator/consumer.h> 24f76ee892STomi Valkeinen #include <linux/wait.h> 25f76ee892STomi Valkeinen #include <linux/workqueue.h> 26f76ee892STomi Valkeinen #include <linux/sched.h> 27f76ee892STomi Valkeinen #include <linux/slab.h> 28f76ee892STomi Valkeinen #include <linux/debugfs.h> 29f76ee892STomi Valkeinen #include <linux/pm_runtime.h> 30f76ee892STomi Valkeinen #include <linux/of.h> 31f76ee892STomi Valkeinen #include <linux/of_platform.h> 32f76ee892STomi Valkeinen #include <linux/component.h> 33f76ee892STomi Valkeinen 3462d9e44eSPeter Ujfalusi #include <video/omapfb_dss.h> 35f76ee892STomi Valkeinen #include <video/mipi_display.h> 36f76ee892STomi Valkeinen 37f76ee892STomi Valkeinen #include "dss.h" 38f76ee892STomi Valkeinen #include "dss_features.h" 39f76ee892STomi Valkeinen 40f76ee892STomi Valkeinen #define DSI_CATCH_MISSING_TE 41f76ee892STomi Valkeinen 42f76ee892STomi Valkeinen struct dsi_reg { u16 module; u16 idx; }; 43f76ee892STomi Valkeinen 44f76ee892STomi Valkeinen #define DSI_REG(mod, idx) ((const struct dsi_reg) { mod, idx }) 45f76ee892STomi Valkeinen 46f76ee892STomi Valkeinen /* DSI Protocol Engine */ 47f76ee892STomi Valkeinen 48f76ee892STomi Valkeinen #define DSI_PROTO 0 49f76ee892STomi Valkeinen #define DSI_PROTO_SZ 0x200 50f76ee892STomi Valkeinen 51f76ee892STomi Valkeinen #define DSI_REVISION DSI_REG(DSI_PROTO, 0x0000) 52f76ee892STomi Valkeinen #define DSI_SYSCONFIG DSI_REG(DSI_PROTO, 0x0010) 53f76ee892STomi Valkeinen #define DSI_SYSSTATUS DSI_REG(DSI_PROTO, 0x0014) 54f76ee892STomi Valkeinen #define DSI_IRQSTATUS DSI_REG(DSI_PROTO, 0x0018) 55f76ee892STomi Valkeinen #define DSI_IRQENABLE DSI_REG(DSI_PROTO, 0x001C) 56f76ee892STomi Valkeinen #define DSI_CTRL DSI_REG(DSI_PROTO, 0x0040) 57f76ee892STomi Valkeinen #define DSI_GNQ DSI_REG(DSI_PROTO, 0x0044) 58f76ee892STomi Valkeinen #define DSI_COMPLEXIO_CFG1 DSI_REG(DSI_PROTO, 0x0048) 59f76ee892STomi Valkeinen #define DSI_COMPLEXIO_IRQ_STATUS DSI_REG(DSI_PROTO, 0x004C) 60f76ee892STomi Valkeinen #define DSI_COMPLEXIO_IRQ_ENABLE DSI_REG(DSI_PROTO, 0x0050) 61f76ee892STomi Valkeinen #define DSI_CLK_CTRL DSI_REG(DSI_PROTO, 0x0054) 62f76ee892STomi Valkeinen #define DSI_TIMING1 DSI_REG(DSI_PROTO, 0x0058) 63f76ee892STomi Valkeinen #define DSI_TIMING2 DSI_REG(DSI_PROTO, 0x005C) 64f76ee892STomi Valkeinen #define DSI_VM_TIMING1 DSI_REG(DSI_PROTO, 0x0060) 65f76ee892STomi Valkeinen #define DSI_VM_TIMING2 DSI_REG(DSI_PROTO, 0x0064) 66f76ee892STomi Valkeinen #define DSI_VM_TIMING3 DSI_REG(DSI_PROTO, 0x0068) 67f76ee892STomi Valkeinen #define DSI_CLK_TIMING DSI_REG(DSI_PROTO, 0x006C) 68f76ee892STomi Valkeinen #define DSI_TX_FIFO_VC_SIZE DSI_REG(DSI_PROTO, 0x0070) 69f76ee892STomi Valkeinen #define DSI_RX_FIFO_VC_SIZE DSI_REG(DSI_PROTO, 0x0074) 70f76ee892STomi Valkeinen #define DSI_COMPLEXIO_CFG2 DSI_REG(DSI_PROTO, 0x0078) 71f76ee892STomi Valkeinen #define DSI_RX_FIFO_VC_FULLNESS DSI_REG(DSI_PROTO, 0x007C) 72f76ee892STomi Valkeinen #define DSI_VM_TIMING4 DSI_REG(DSI_PROTO, 0x0080) 73f76ee892STomi Valkeinen #define DSI_TX_FIFO_VC_EMPTINESS DSI_REG(DSI_PROTO, 0x0084) 74f76ee892STomi Valkeinen #define DSI_VM_TIMING5 DSI_REG(DSI_PROTO, 0x0088) 75f76ee892STomi Valkeinen #define DSI_VM_TIMING6 DSI_REG(DSI_PROTO, 0x008C) 76f76ee892STomi Valkeinen #define DSI_VM_TIMING7 DSI_REG(DSI_PROTO, 0x0090) 77f76ee892STomi Valkeinen #define DSI_STOPCLK_TIMING DSI_REG(DSI_PROTO, 0x0094) 78f76ee892STomi Valkeinen #define DSI_VC_CTRL(n) DSI_REG(DSI_PROTO, 0x0100 + (n * 0x20)) 79f76ee892STomi Valkeinen #define DSI_VC_TE(n) DSI_REG(DSI_PROTO, 0x0104 + (n * 0x20)) 80f76ee892STomi Valkeinen #define DSI_VC_LONG_PACKET_HEADER(n) DSI_REG(DSI_PROTO, 0x0108 + (n * 0x20)) 81f76ee892STomi Valkeinen #define DSI_VC_LONG_PACKET_PAYLOAD(n) DSI_REG(DSI_PROTO, 0x010C + (n * 0x20)) 82f76ee892STomi Valkeinen #define DSI_VC_SHORT_PACKET_HEADER(n) DSI_REG(DSI_PROTO, 0x0110 + (n * 0x20)) 83f76ee892STomi Valkeinen #define DSI_VC_IRQSTATUS(n) DSI_REG(DSI_PROTO, 0x0118 + (n * 0x20)) 84f76ee892STomi Valkeinen #define DSI_VC_IRQENABLE(n) DSI_REG(DSI_PROTO, 0x011C + (n * 0x20)) 85f76ee892STomi Valkeinen 86f76ee892STomi Valkeinen /* DSIPHY_SCP */ 87f76ee892STomi Valkeinen 88f76ee892STomi Valkeinen #define DSI_PHY 1 89f76ee892STomi Valkeinen #define DSI_PHY_OFFSET 0x200 90f76ee892STomi Valkeinen #define DSI_PHY_SZ 0x40 91f76ee892STomi Valkeinen 92f76ee892STomi Valkeinen #define DSI_DSIPHY_CFG0 DSI_REG(DSI_PHY, 0x0000) 93f76ee892STomi Valkeinen #define DSI_DSIPHY_CFG1 DSI_REG(DSI_PHY, 0x0004) 94f76ee892STomi Valkeinen #define DSI_DSIPHY_CFG2 DSI_REG(DSI_PHY, 0x0008) 95f76ee892STomi Valkeinen #define DSI_DSIPHY_CFG5 DSI_REG(DSI_PHY, 0x0014) 96f76ee892STomi Valkeinen #define DSI_DSIPHY_CFG10 DSI_REG(DSI_PHY, 0x0028) 97f76ee892STomi Valkeinen 98f76ee892STomi Valkeinen /* DSI_PLL_CTRL_SCP */ 99f76ee892STomi Valkeinen 100f76ee892STomi Valkeinen #define DSI_PLL 2 101f76ee892STomi Valkeinen #define DSI_PLL_OFFSET 0x300 102f76ee892STomi Valkeinen #define DSI_PLL_SZ 0x20 103f76ee892STomi Valkeinen 104f76ee892STomi Valkeinen #define DSI_PLL_CONTROL DSI_REG(DSI_PLL, 0x0000) 105f76ee892STomi Valkeinen #define DSI_PLL_STATUS DSI_REG(DSI_PLL, 0x0004) 106f76ee892STomi Valkeinen #define DSI_PLL_GO DSI_REG(DSI_PLL, 0x0008) 107f76ee892STomi Valkeinen #define DSI_PLL_CONFIGURATION1 DSI_REG(DSI_PLL, 0x000C) 108f76ee892STomi Valkeinen #define DSI_PLL_CONFIGURATION2 DSI_REG(DSI_PLL, 0x0010) 109f76ee892STomi Valkeinen 110f76ee892STomi Valkeinen #define REG_GET(dsidev, idx, start, end) \ 111f76ee892STomi Valkeinen FLD_GET(dsi_read_reg(dsidev, idx), start, end) 112f76ee892STomi Valkeinen 113f76ee892STomi Valkeinen #define REG_FLD_MOD(dsidev, idx, val, start, end) \ 114f76ee892STomi Valkeinen dsi_write_reg(dsidev, idx, FLD_MOD(dsi_read_reg(dsidev, idx), val, start, end)) 115f76ee892STomi Valkeinen 116f76ee892STomi Valkeinen /* Global interrupts */ 117f76ee892STomi Valkeinen #define DSI_IRQ_VC0 (1 << 0) 118f76ee892STomi Valkeinen #define DSI_IRQ_VC1 (1 << 1) 119f76ee892STomi Valkeinen #define DSI_IRQ_VC2 (1 << 2) 120f76ee892STomi Valkeinen #define DSI_IRQ_VC3 (1 << 3) 121f76ee892STomi Valkeinen #define DSI_IRQ_WAKEUP (1 << 4) 122f76ee892STomi Valkeinen #define DSI_IRQ_RESYNC (1 << 5) 123f76ee892STomi Valkeinen #define DSI_IRQ_PLL_LOCK (1 << 7) 124f76ee892STomi Valkeinen #define DSI_IRQ_PLL_UNLOCK (1 << 8) 125f76ee892STomi Valkeinen #define DSI_IRQ_PLL_RECALL (1 << 9) 126f76ee892STomi Valkeinen #define DSI_IRQ_COMPLEXIO_ERR (1 << 10) 127f76ee892STomi Valkeinen #define DSI_IRQ_HS_TX_TIMEOUT (1 << 14) 128f76ee892STomi Valkeinen #define DSI_IRQ_LP_RX_TIMEOUT (1 << 15) 129f76ee892STomi Valkeinen #define DSI_IRQ_TE_TRIGGER (1 << 16) 130f76ee892STomi Valkeinen #define DSI_IRQ_ACK_TRIGGER (1 << 17) 131f76ee892STomi Valkeinen #define DSI_IRQ_SYNC_LOST (1 << 18) 132f76ee892STomi Valkeinen #define DSI_IRQ_LDO_POWER_GOOD (1 << 19) 133f76ee892STomi Valkeinen #define DSI_IRQ_TA_TIMEOUT (1 << 20) 134f76ee892STomi Valkeinen #define DSI_IRQ_ERROR_MASK \ 135f76ee892STomi Valkeinen (DSI_IRQ_HS_TX_TIMEOUT | DSI_IRQ_LP_RX_TIMEOUT | DSI_IRQ_SYNC_LOST | \ 136f76ee892STomi Valkeinen DSI_IRQ_TA_TIMEOUT) 137f76ee892STomi Valkeinen #define DSI_IRQ_CHANNEL_MASK 0xf 138f76ee892STomi Valkeinen 139f76ee892STomi Valkeinen /* Virtual channel interrupts */ 140f76ee892STomi Valkeinen #define DSI_VC_IRQ_CS (1 << 0) 141f76ee892STomi Valkeinen #define DSI_VC_IRQ_ECC_CORR (1 << 1) 142f76ee892STomi Valkeinen #define DSI_VC_IRQ_PACKET_SENT (1 << 2) 143f76ee892STomi Valkeinen #define DSI_VC_IRQ_FIFO_TX_OVF (1 << 3) 144f76ee892STomi Valkeinen #define DSI_VC_IRQ_FIFO_RX_OVF (1 << 4) 145f76ee892STomi Valkeinen #define DSI_VC_IRQ_BTA (1 << 5) 146f76ee892STomi Valkeinen #define DSI_VC_IRQ_ECC_NO_CORR (1 << 6) 147f76ee892STomi Valkeinen #define DSI_VC_IRQ_FIFO_TX_UDF (1 << 7) 148f76ee892STomi Valkeinen #define DSI_VC_IRQ_PP_BUSY_CHANGE (1 << 8) 149f76ee892STomi Valkeinen #define DSI_VC_IRQ_ERROR_MASK \ 150f76ee892STomi Valkeinen (DSI_VC_IRQ_CS | DSI_VC_IRQ_ECC_CORR | DSI_VC_IRQ_FIFO_TX_OVF | \ 151f76ee892STomi Valkeinen DSI_VC_IRQ_FIFO_RX_OVF | DSI_VC_IRQ_ECC_NO_CORR | \ 152f76ee892STomi Valkeinen DSI_VC_IRQ_FIFO_TX_UDF) 153f76ee892STomi Valkeinen 154f76ee892STomi Valkeinen /* ComplexIO interrupts */ 155f76ee892STomi Valkeinen #define DSI_CIO_IRQ_ERRSYNCESC1 (1 << 0) 156f76ee892STomi Valkeinen #define DSI_CIO_IRQ_ERRSYNCESC2 (1 << 1) 157f76ee892STomi Valkeinen #define DSI_CIO_IRQ_ERRSYNCESC3 (1 << 2) 158f76ee892STomi Valkeinen #define DSI_CIO_IRQ_ERRSYNCESC4 (1 << 3) 159f76ee892STomi Valkeinen #define DSI_CIO_IRQ_ERRSYNCESC5 (1 << 4) 160f76ee892STomi Valkeinen #define DSI_CIO_IRQ_ERRESC1 (1 << 5) 161f76ee892STomi Valkeinen #define DSI_CIO_IRQ_ERRESC2 (1 << 6) 162f76ee892STomi Valkeinen #define DSI_CIO_IRQ_ERRESC3 (1 << 7) 163f76ee892STomi Valkeinen #define DSI_CIO_IRQ_ERRESC4 (1 << 8) 164f76ee892STomi Valkeinen #define DSI_CIO_IRQ_ERRESC5 (1 << 9) 165f76ee892STomi Valkeinen #define DSI_CIO_IRQ_ERRCONTROL1 (1 << 10) 166f76ee892STomi Valkeinen #define DSI_CIO_IRQ_ERRCONTROL2 (1 << 11) 167f76ee892STomi Valkeinen #define DSI_CIO_IRQ_ERRCONTROL3 (1 << 12) 168f76ee892STomi Valkeinen #define DSI_CIO_IRQ_ERRCONTROL4 (1 << 13) 169f76ee892STomi Valkeinen #define DSI_CIO_IRQ_ERRCONTROL5 (1 << 14) 170f76ee892STomi Valkeinen #define DSI_CIO_IRQ_STATEULPS1 (1 << 15) 171f76ee892STomi Valkeinen #define DSI_CIO_IRQ_STATEULPS2 (1 << 16) 172f76ee892STomi Valkeinen #define DSI_CIO_IRQ_STATEULPS3 (1 << 17) 173f76ee892STomi Valkeinen #define DSI_CIO_IRQ_STATEULPS4 (1 << 18) 174f76ee892STomi Valkeinen #define DSI_CIO_IRQ_STATEULPS5 (1 << 19) 175f76ee892STomi Valkeinen #define DSI_CIO_IRQ_ERRCONTENTIONLP0_1 (1 << 20) 176f76ee892STomi Valkeinen #define DSI_CIO_IRQ_ERRCONTENTIONLP1_1 (1 << 21) 177f76ee892STomi Valkeinen #define DSI_CIO_IRQ_ERRCONTENTIONLP0_2 (1 << 22) 178f76ee892STomi Valkeinen #define DSI_CIO_IRQ_ERRCONTENTIONLP1_2 (1 << 23) 179f76ee892STomi Valkeinen #define DSI_CIO_IRQ_ERRCONTENTIONLP0_3 (1 << 24) 180f76ee892STomi Valkeinen #define DSI_CIO_IRQ_ERRCONTENTIONLP1_3 (1 << 25) 181f76ee892STomi Valkeinen #define DSI_CIO_IRQ_ERRCONTENTIONLP0_4 (1 << 26) 182f76ee892STomi Valkeinen #define DSI_CIO_IRQ_ERRCONTENTIONLP1_4 (1 << 27) 183f76ee892STomi Valkeinen #define DSI_CIO_IRQ_ERRCONTENTIONLP0_5 (1 << 28) 184f76ee892STomi Valkeinen #define DSI_CIO_IRQ_ERRCONTENTIONLP1_5 (1 << 29) 185f76ee892STomi Valkeinen #define DSI_CIO_IRQ_ULPSACTIVENOT_ALL0 (1 << 30) 186f76ee892STomi Valkeinen #define DSI_CIO_IRQ_ULPSACTIVENOT_ALL1 (1 << 31) 187f76ee892STomi Valkeinen #define DSI_CIO_IRQ_ERROR_MASK \ 188f76ee892STomi Valkeinen (DSI_CIO_IRQ_ERRSYNCESC1 | DSI_CIO_IRQ_ERRSYNCESC2 | \ 189f76ee892STomi Valkeinen DSI_CIO_IRQ_ERRSYNCESC3 | DSI_CIO_IRQ_ERRSYNCESC4 | \ 190f76ee892STomi Valkeinen DSI_CIO_IRQ_ERRSYNCESC5 | \ 191f76ee892STomi Valkeinen DSI_CIO_IRQ_ERRESC1 | DSI_CIO_IRQ_ERRESC2 | \ 192f76ee892STomi Valkeinen DSI_CIO_IRQ_ERRESC3 | DSI_CIO_IRQ_ERRESC4 | \ 193f76ee892STomi Valkeinen DSI_CIO_IRQ_ERRESC5 | \ 194f76ee892STomi Valkeinen DSI_CIO_IRQ_ERRCONTROL1 | DSI_CIO_IRQ_ERRCONTROL2 | \ 195f76ee892STomi Valkeinen DSI_CIO_IRQ_ERRCONTROL3 | DSI_CIO_IRQ_ERRCONTROL4 | \ 196f76ee892STomi Valkeinen DSI_CIO_IRQ_ERRCONTROL5 | \ 197f76ee892STomi Valkeinen DSI_CIO_IRQ_ERRCONTENTIONLP0_1 | DSI_CIO_IRQ_ERRCONTENTIONLP1_1 | \ 198f76ee892STomi Valkeinen DSI_CIO_IRQ_ERRCONTENTIONLP0_2 | DSI_CIO_IRQ_ERRCONTENTIONLP1_2 | \ 199f76ee892STomi Valkeinen DSI_CIO_IRQ_ERRCONTENTIONLP0_3 | DSI_CIO_IRQ_ERRCONTENTIONLP1_3 | \ 200f76ee892STomi Valkeinen DSI_CIO_IRQ_ERRCONTENTIONLP0_4 | DSI_CIO_IRQ_ERRCONTENTIONLP1_4 | \ 201f76ee892STomi Valkeinen DSI_CIO_IRQ_ERRCONTENTIONLP0_5 | DSI_CIO_IRQ_ERRCONTENTIONLP1_5) 202f76ee892STomi Valkeinen 203f76ee892STomi Valkeinen typedef void (*omap_dsi_isr_t) (void *arg, u32 mask); 204f76ee892STomi Valkeinen 205f76ee892STomi Valkeinen static int dsi_display_init_dispc(struct platform_device *dsidev, 206f76ee892STomi Valkeinen struct omap_overlay_manager *mgr); 207f76ee892STomi Valkeinen static void dsi_display_uninit_dispc(struct platform_device *dsidev, 208f76ee892STomi Valkeinen struct omap_overlay_manager *mgr); 209f76ee892STomi Valkeinen 210f76ee892STomi Valkeinen static int dsi_vc_send_null(struct omap_dss_device *dssdev, int channel); 211f76ee892STomi Valkeinen 212f76ee892STomi Valkeinen /* DSI PLL HSDIV indices */ 213f76ee892STomi Valkeinen #define HSDIV_DISPC 0 214f76ee892STomi Valkeinen #define HSDIV_DSI 1 215f76ee892STomi Valkeinen 216f76ee892STomi Valkeinen #define DSI_MAX_NR_ISRS 2 217f76ee892STomi Valkeinen #define DSI_MAX_NR_LANES 5 218f76ee892STomi Valkeinen 219f76ee892STomi Valkeinen enum dsi_lane_function { 220f76ee892STomi Valkeinen DSI_LANE_UNUSED = 0, 221f76ee892STomi Valkeinen DSI_LANE_CLK, 222f76ee892STomi Valkeinen DSI_LANE_DATA1, 223f76ee892STomi Valkeinen DSI_LANE_DATA2, 224f76ee892STomi Valkeinen DSI_LANE_DATA3, 225f76ee892STomi Valkeinen DSI_LANE_DATA4, 226f76ee892STomi Valkeinen }; 227f76ee892STomi Valkeinen 228f76ee892STomi Valkeinen struct dsi_lane_config { 229f76ee892STomi Valkeinen enum dsi_lane_function function; 230f76ee892STomi Valkeinen u8 polarity; 231f76ee892STomi Valkeinen }; 232f76ee892STomi Valkeinen 233f76ee892STomi Valkeinen struct dsi_isr_data { 234f76ee892STomi Valkeinen omap_dsi_isr_t isr; 235f76ee892STomi Valkeinen void *arg; 236f76ee892STomi Valkeinen u32 mask; 237f76ee892STomi Valkeinen }; 238f76ee892STomi Valkeinen 239f76ee892STomi Valkeinen enum fifo_size { 240f76ee892STomi Valkeinen DSI_FIFO_SIZE_0 = 0, 241f76ee892STomi Valkeinen DSI_FIFO_SIZE_32 = 1, 242f76ee892STomi Valkeinen DSI_FIFO_SIZE_64 = 2, 243f76ee892STomi Valkeinen DSI_FIFO_SIZE_96 = 3, 244f76ee892STomi Valkeinen DSI_FIFO_SIZE_128 = 4, 245f76ee892STomi Valkeinen }; 246f76ee892STomi Valkeinen 247f76ee892STomi Valkeinen enum dsi_vc_source { 248f76ee892STomi Valkeinen DSI_VC_SOURCE_L4 = 0, 249f76ee892STomi Valkeinen DSI_VC_SOURCE_VP, 250f76ee892STomi Valkeinen }; 251f76ee892STomi Valkeinen 252f76ee892STomi Valkeinen struct dsi_irq_stats { 253f76ee892STomi Valkeinen unsigned long last_reset; 254f76ee892STomi Valkeinen unsigned irq_count; 255f76ee892STomi Valkeinen unsigned dsi_irqs[32]; 256f76ee892STomi Valkeinen unsigned vc_irqs[4][32]; 257f76ee892STomi Valkeinen unsigned cio_irqs[32]; 258f76ee892STomi Valkeinen }; 259f76ee892STomi Valkeinen 260f76ee892STomi Valkeinen struct dsi_isr_tables { 261f76ee892STomi Valkeinen struct dsi_isr_data isr_table[DSI_MAX_NR_ISRS]; 262f76ee892STomi Valkeinen struct dsi_isr_data isr_table_vc[4][DSI_MAX_NR_ISRS]; 263f76ee892STomi Valkeinen struct dsi_isr_data isr_table_cio[DSI_MAX_NR_ISRS]; 264f76ee892STomi Valkeinen }; 265f76ee892STomi Valkeinen 266f76ee892STomi Valkeinen struct dsi_clk_calc_ctx { 267f76ee892STomi Valkeinen struct platform_device *dsidev; 268f76ee892STomi Valkeinen struct dss_pll *pll; 269f76ee892STomi Valkeinen 270f76ee892STomi Valkeinen /* inputs */ 271f76ee892STomi Valkeinen 272f76ee892STomi Valkeinen const struct omap_dss_dsi_config *config; 273f76ee892STomi Valkeinen 274f76ee892STomi Valkeinen unsigned long req_pck_min, req_pck_nom, req_pck_max; 275f76ee892STomi Valkeinen 276f76ee892STomi Valkeinen /* outputs */ 277f76ee892STomi Valkeinen 278f76ee892STomi Valkeinen struct dss_pll_clock_info dsi_cinfo; 279f76ee892STomi Valkeinen struct dispc_clock_info dispc_cinfo; 280f76ee892STomi Valkeinen 281f76ee892STomi Valkeinen struct omap_video_timings dispc_vm; 282f76ee892STomi Valkeinen struct omap_dss_dsi_videomode_timings dsi_vm; 283f76ee892STomi Valkeinen }; 284f76ee892STomi Valkeinen 285f76ee892STomi Valkeinen struct dsi_lp_clock_info { 286f76ee892STomi Valkeinen unsigned long lp_clk; 287f76ee892STomi Valkeinen u16 lp_clk_div; 288f76ee892STomi Valkeinen }; 289f76ee892STomi Valkeinen 290f76ee892STomi Valkeinen struct dsi_data { 291f76ee892STomi Valkeinen struct platform_device *pdev; 292f76ee892STomi Valkeinen void __iomem *proto_base; 293f76ee892STomi Valkeinen void __iomem *phy_base; 294f76ee892STomi Valkeinen void __iomem *pll_base; 295f76ee892STomi Valkeinen 296f76ee892STomi Valkeinen int module_id; 297f76ee892STomi Valkeinen 298f76ee892STomi Valkeinen int irq; 299f76ee892STomi Valkeinen 300f76ee892STomi Valkeinen bool is_enabled; 301f76ee892STomi Valkeinen 302f76ee892STomi Valkeinen struct clk *dss_clk; 303f76ee892STomi Valkeinen 304f76ee892STomi Valkeinen struct dispc_clock_info user_dispc_cinfo; 305f76ee892STomi Valkeinen struct dss_pll_clock_info user_dsi_cinfo; 306f76ee892STomi Valkeinen 307f76ee892STomi Valkeinen struct dsi_lp_clock_info user_lp_cinfo; 308f76ee892STomi Valkeinen struct dsi_lp_clock_info current_lp_cinfo; 309f76ee892STomi Valkeinen 310f76ee892STomi Valkeinen struct dss_pll pll; 311f76ee892STomi Valkeinen 312f76ee892STomi Valkeinen bool vdds_dsi_enabled; 313f76ee892STomi Valkeinen struct regulator *vdds_dsi_reg; 314f76ee892STomi Valkeinen 315f76ee892STomi Valkeinen struct { 316f76ee892STomi Valkeinen enum dsi_vc_source source; 317f76ee892STomi Valkeinen struct omap_dss_device *dssdev; 318f76ee892STomi Valkeinen enum fifo_size tx_fifo_size; 319f76ee892STomi Valkeinen enum fifo_size rx_fifo_size; 320f76ee892STomi Valkeinen int vc_id; 321f76ee892STomi Valkeinen } vc[4]; 322f76ee892STomi Valkeinen 323f76ee892STomi Valkeinen struct mutex lock; 324f76ee892STomi Valkeinen struct semaphore bus_lock; 325f76ee892STomi Valkeinen 326f76ee892STomi Valkeinen spinlock_t irq_lock; 327f76ee892STomi Valkeinen struct dsi_isr_tables isr_tables; 328f76ee892STomi Valkeinen /* space for a copy used by the interrupt handler */ 329f76ee892STomi Valkeinen struct dsi_isr_tables isr_tables_copy; 330f76ee892STomi Valkeinen 331f76ee892STomi Valkeinen int update_channel; 332f76ee892STomi Valkeinen #ifdef DSI_PERF_MEASURE 333f76ee892STomi Valkeinen unsigned update_bytes; 334f76ee892STomi Valkeinen #endif 335f76ee892STomi Valkeinen 336f76ee892STomi Valkeinen bool te_enabled; 337f76ee892STomi Valkeinen bool ulps_enabled; 338f76ee892STomi Valkeinen 339f76ee892STomi Valkeinen void (*framedone_callback)(int, void *); 340f76ee892STomi Valkeinen void *framedone_data; 341f76ee892STomi Valkeinen 342f76ee892STomi Valkeinen struct delayed_work framedone_timeout_work; 343f76ee892STomi Valkeinen 344f76ee892STomi Valkeinen #ifdef DSI_CATCH_MISSING_TE 345f76ee892STomi Valkeinen struct timer_list te_timer; 346f76ee892STomi Valkeinen #endif 347f76ee892STomi Valkeinen 348f76ee892STomi Valkeinen unsigned long cache_req_pck; 349f76ee892STomi Valkeinen unsigned long cache_clk_freq; 350f76ee892STomi Valkeinen struct dss_pll_clock_info cache_cinfo; 351f76ee892STomi Valkeinen 352f76ee892STomi Valkeinen u32 errors; 353f76ee892STomi Valkeinen spinlock_t errors_lock; 354f76ee892STomi Valkeinen #ifdef DSI_PERF_MEASURE 355f76ee892STomi Valkeinen ktime_t perf_setup_time; 356f76ee892STomi Valkeinen ktime_t perf_start_time; 357f76ee892STomi Valkeinen #endif 358f76ee892STomi Valkeinen int debug_read; 359f76ee892STomi Valkeinen int debug_write; 360f76ee892STomi Valkeinen 36135b522cfSTomi Valkeinen #ifdef CONFIG_FB_OMAP2_DSS_COLLECT_IRQ_STATS 362f76ee892STomi Valkeinen spinlock_t irq_stats_lock; 363f76ee892STomi Valkeinen struct dsi_irq_stats irq_stats; 364f76ee892STomi Valkeinen #endif 365f76ee892STomi Valkeinen 366f76ee892STomi Valkeinen unsigned num_lanes_supported; 367f76ee892STomi Valkeinen unsigned line_buffer_size; 368f76ee892STomi Valkeinen 369f76ee892STomi Valkeinen struct dsi_lane_config lanes[DSI_MAX_NR_LANES]; 370f76ee892STomi Valkeinen unsigned num_lanes_used; 371f76ee892STomi Valkeinen 372f76ee892STomi Valkeinen unsigned scp_clk_refcount; 373f76ee892STomi Valkeinen 374f76ee892STomi Valkeinen struct dss_lcd_mgr_config mgr_config; 375f76ee892STomi Valkeinen struct omap_video_timings timings; 376f76ee892STomi Valkeinen enum omap_dss_dsi_pixel_format pix_fmt; 377f76ee892STomi Valkeinen enum omap_dss_dsi_mode mode; 378f76ee892STomi Valkeinen struct omap_dss_dsi_videomode_timings vm_timings; 379f76ee892STomi Valkeinen 380f76ee892STomi Valkeinen struct omap_dss_device output; 381f76ee892STomi Valkeinen }; 382f76ee892STomi Valkeinen 383f76ee892STomi Valkeinen struct dsi_packet_sent_handler_data { 384f76ee892STomi Valkeinen struct platform_device *dsidev; 385f76ee892STomi Valkeinen struct completion *completion; 386f76ee892STomi Valkeinen }; 387f76ee892STomi Valkeinen 388f76ee892STomi Valkeinen struct dsi_module_id_data { 389f76ee892STomi Valkeinen u32 address; 390f76ee892STomi Valkeinen int id; 391f76ee892STomi Valkeinen }; 392f76ee892STomi Valkeinen 393f76ee892STomi Valkeinen static const struct of_device_id dsi_of_match[]; 394f76ee892STomi Valkeinen 395f76ee892STomi Valkeinen #ifdef DSI_PERF_MEASURE 396f76ee892STomi Valkeinen static bool dsi_perf; 397f76ee892STomi Valkeinen module_param(dsi_perf, bool, 0644); 398f76ee892STomi Valkeinen #endif 399f76ee892STomi Valkeinen 400f76ee892STomi Valkeinen static inline struct dsi_data *dsi_get_dsidrv_data(struct platform_device *dsidev) 401f76ee892STomi Valkeinen { 402f76ee892STomi Valkeinen return dev_get_drvdata(&dsidev->dev); 403f76ee892STomi Valkeinen } 404f76ee892STomi Valkeinen 405f76ee892STomi Valkeinen static inline struct platform_device *dsi_get_dsidev_from_dssdev(struct omap_dss_device *dssdev) 406f76ee892STomi Valkeinen { 407f76ee892STomi Valkeinen return to_platform_device(dssdev->dev); 408f76ee892STomi Valkeinen } 409f76ee892STomi Valkeinen 410f76ee892STomi Valkeinen static struct platform_device *dsi_get_dsidev_from_id(int module) 411f76ee892STomi Valkeinen { 412f76ee892STomi Valkeinen struct omap_dss_device *out; 413f76ee892STomi Valkeinen enum omap_dss_output_id id; 414f76ee892STomi Valkeinen 415f76ee892STomi Valkeinen switch (module) { 416f76ee892STomi Valkeinen case 0: 417f76ee892STomi Valkeinen id = OMAP_DSS_OUTPUT_DSI1; 418f76ee892STomi Valkeinen break; 419f76ee892STomi Valkeinen case 1: 420f76ee892STomi Valkeinen id = OMAP_DSS_OUTPUT_DSI2; 421f76ee892STomi Valkeinen break; 422f76ee892STomi Valkeinen default: 423f76ee892STomi Valkeinen return NULL; 424f76ee892STomi Valkeinen } 425f76ee892STomi Valkeinen 426f76ee892STomi Valkeinen out = omap_dss_get_output(id); 427f76ee892STomi Valkeinen 428f76ee892STomi Valkeinen return out ? to_platform_device(out->dev) : NULL; 429f76ee892STomi Valkeinen } 430f76ee892STomi Valkeinen 431f76ee892STomi Valkeinen static inline void dsi_write_reg(struct platform_device *dsidev, 432f76ee892STomi Valkeinen const struct dsi_reg idx, u32 val) 433f76ee892STomi Valkeinen { 434f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 435f76ee892STomi Valkeinen void __iomem *base; 436f76ee892STomi Valkeinen 437f76ee892STomi Valkeinen switch(idx.module) { 438f76ee892STomi Valkeinen case DSI_PROTO: base = dsi->proto_base; break; 439f76ee892STomi Valkeinen case DSI_PHY: base = dsi->phy_base; break; 440f76ee892STomi Valkeinen case DSI_PLL: base = dsi->pll_base; break; 441f76ee892STomi Valkeinen default: return; 442f76ee892STomi Valkeinen } 443f76ee892STomi Valkeinen 444f76ee892STomi Valkeinen __raw_writel(val, base + idx.idx); 445f76ee892STomi Valkeinen } 446f76ee892STomi Valkeinen 447f76ee892STomi Valkeinen static inline u32 dsi_read_reg(struct platform_device *dsidev, 448f76ee892STomi Valkeinen const struct dsi_reg idx) 449f76ee892STomi Valkeinen { 450f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 451f76ee892STomi Valkeinen void __iomem *base; 452f76ee892STomi Valkeinen 453f76ee892STomi Valkeinen switch(idx.module) { 454f76ee892STomi Valkeinen case DSI_PROTO: base = dsi->proto_base; break; 455f76ee892STomi Valkeinen case DSI_PHY: base = dsi->phy_base; break; 456f76ee892STomi Valkeinen case DSI_PLL: base = dsi->pll_base; break; 457f76ee892STomi Valkeinen default: return 0; 458f76ee892STomi Valkeinen } 459f76ee892STomi Valkeinen 460f76ee892STomi Valkeinen return __raw_readl(base + idx.idx); 461f76ee892STomi Valkeinen } 462f76ee892STomi Valkeinen 463f76ee892STomi Valkeinen static void dsi_bus_lock(struct omap_dss_device *dssdev) 464f76ee892STomi Valkeinen { 465f76ee892STomi Valkeinen struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); 466f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 467f76ee892STomi Valkeinen 468f76ee892STomi Valkeinen down(&dsi->bus_lock); 469f76ee892STomi Valkeinen } 470f76ee892STomi Valkeinen 471f76ee892STomi Valkeinen static void dsi_bus_unlock(struct omap_dss_device *dssdev) 472f76ee892STomi Valkeinen { 473f76ee892STomi Valkeinen struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); 474f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 475f76ee892STomi Valkeinen 476f76ee892STomi Valkeinen up(&dsi->bus_lock); 477f76ee892STomi Valkeinen } 478f76ee892STomi Valkeinen 479f76ee892STomi Valkeinen static bool dsi_bus_is_locked(struct platform_device *dsidev) 480f76ee892STomi Valkeinen { 481f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 482f76ee892STomi Valkeinen 483f76ee892STomi Valkeinen return dsi->bus_lock.count == 0; 484f76ee892STomi Valkeinen } 485f76ee892STomi Valkeinen 486f76ee892STomi Valkeinen static void dsi_completion_handler(void *data, u32 mask) 487f76ee892STomi Valkeinen { 488f76ee892STomi Valkeinen complete((struct completion *)data); 489f76ee892STomi Valkeinen } 490f76ee892STomi Valkeinen 491f76ee892STomi Valkeinen static inline int wait_for_bit_change(struct platform_device *dsidev, 492f76ee892STomi Valkeinen const struct dsi_reg idx, int bitnum, int value) 493f76ee892STomi Valkeinen { 494f76ee892STomi Valkeinen unsigned long timeout; 495f76ee892STomi Valkeinen ktime_t wait; 496f76ee892STomi Valkeinen int t; 497f76ee892STomi Valkeinen 498f76ee892STomi Valkeinen /* first busyloop to see if the bit changes right away */ 499f76ee892STomi Valkeinen t = 100; 500f76ee892STomi Valkeinen while (t-- > 0) { 501f76ee892STomi Valkeinen if (REG_GET(dsidev, idx, bitnum, bitnum) == value) 502f76ee892STomi Valkeinen return value; 503f76ee892STomi Valkeinen } 504f76ee892STomi Valkeinen 505f76ee892STomi Valkeinen /* then loop for 500ms, sleeping for 1ms in between */ 506f76ee892STomi Valkeinen timeout = jiffies + msecs_to_jiffies(500); 507f76ee892STomi Valkeinen while (time_before(jiffies, timeout)) { 508f76ee892STomi Valkeinen if (REG_GET(dsidev, idx, bitnum, bitnum) == value) 509f76ee892STomi Valkeinen return value; 510f76ee892STomi Valkeinen 511f76ee892STomi Valkeinen wait = ns_to_ktime(1000 * 1000); 512f76ee892STomi Valkeinen set_current_state(TASK_UNINTERRUPTIBLE); 513f76ee892STomi Valkeinen schedule_hrtimeout(&wait, HRTIMER_MODE_REL); 514f76ee892STomi Valkeinen } 515f76ee892STomi Valkeinen 516f76ee892STomi Valkeinen return !value; 517f76ee892STomi Valkeinen } 518f76ee892STomi Valkeinen 519f76ee892STomi Valkeinen u8 dsi_get_pixel_size(enum omap_dss_dsi_pixel_format fmt) 520f76ee892STomi Valkeinen { 521f76ee892STomi Valkeinen switch (fmt) { 522f76ee892STomi Valkeinen case OMAP_DSS_DSI_FMT_RGB888: 523f76ee892STomi Valkeinen case OMAP_DSS_DSI_FMT_RGB666: 524f76ee892STomi Valkeinen return 24; 525f76ee892STomi Valkeinen case OMAP_DSS_DSI_FMT_RGB666_PACKED: 526f76ee892STomi Valkeinen return 18; 527f76ee892STomi Valkeinen case OMAP_DSS_DSI_FMT_RGB565: 528f76ee892STomi Valkeinen return 16; 529f76ee892STomi Valkeinen default: 530f76ee892STomi Valkeinen BUG(); 531f76ee892STomi Valkeinen return 0; 532f76ee892STomi Valkeinen } 533f76ee892STomi Valkeinen } 534f76ee892STomi Valkeinen 535f76ee892STomi Valkeinen #ifdef DSI_PERF_MEASURE 536f76ee892STomi Valkeinen static void dsi_perf_mark_setup(struct platform_device *dsidev) 537f76ee892STomi Valkeinen { 538f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 539f76ee892STomi Valkeinen dsi->perf_setup_time = ktime_get(); 540f76ee892STomi Valkeinen } 541f76ee892STomi Valkeinen 542f76ee892STomi Valkeinen static void dsi_perf_mark_start(struct platform_device *dsidev) 543f76ee892STomi Valkeinen { 544f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 545f76ee892STomi Valkeinen dsi->perf_start_time = ktime_get(); 546f76ee892STomi Valkeinen } 547f76ee892STomi Valkeinen 548f76ee892STomi Valkeinen static void dsi_perf_show(struct platform_device *dsidev, const char *name) 549f76ee892STomi Valkeinen { 550f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 551f76ee892STomi Valkeinen ktime_t t, setup_time, trans_time; 552f76ee892STomi Valkeinen u32 total_bytes; 553f76ee892STomi Valkeinen u32 setup_us, trans_us, total_us; 554f76ee892STomi Valkeinen 555f76ee892STomi Valkeinen if (!dsi_perf) 556f76ee892STomi Valkeinen return; 557f76ee892STomi Valkeinen 558f76ee892STomi Valkeinen t = ktime_get(); 559f76ee892STomi Valkeinen 560f76ee892STomi Valkeinen setup_time = ktime_sub(dsi->perf_start_time, dsi->perf_setup_time); 561f76ee892STomi Valkeinen setup_us = (u32)ktime_to_us(setup_time); 562f76ee892STomi Valkeinen if (setup_us == 0) 563f76ee892STomi Valkeinen setup_us = 1; 564f76ee892STomi Valkeinen 565f76ee892STomi Valkeinen trans_time = ktime_sub(t, dsi->perf_start_time); 566f76ee892STomi Valkeinen trans_us = (u32)ktime_to_us(trans_time); 567f76ee892STomi Valkeinen if (trans_us == 0) 568f76ee892STomi Valkeinen trans_us = 1; 569f76ee892STomi Valkeinen 570f76ee892STomi Valkeinen total_us = setup_us + trans_us; 571f76ee892STomi Valkeinen 572f76ee892STomi Valkeinen total_bytes = dsi->update_bytes; 573f76ee892STomi Valkeinen 574f76ee892STomi Valkeinen printk(KERN_INFO "DSI(%s): %u us + %u us = %u us (%uHz), " 575f76ee892STomi Valkeinen "%u bytes, %u kbytes/sec\n", 576f76ee892STomi Valkeinen name, 577f76ee892STomi Valkeinen setup_us, 578f76ee892STomi Valkeinen trans_us, 579f76ee892STomi Valkeinen total_us, 580f76ee892STomi Valkeinen 1000*1000 / total_us, 581f76ee892STomi Valkeinen total_bytes, 582f76ee892STomi Valkeinen total_bytes * 1000 / total_us); 583f76ee892STomi Valkeinen } 584f76ee892STomi Valkeinen #else 585f76ee892STomi Valkeinen static inline void dsi_perf_mark_setup(struct platform_device *dsidev) 586f76ee892STomi Valkeinen { 587f76ee892STomi Valkeinen } 588f76ee892STomi Valkeinen 589f76ee892STomi Valkeinen static inline void dsi_perf_mark_start(struct platform_device *dsidev) 590f76ee892STomi Valkeinen { 591f76ee892STomi Valkeinen } 592f76ee892STomi Valkeinen 593f76ee892STomi Valkeinen static inline void dsi_perf_show(struct platform_device *dsidev, 594f76ee892STomi Valkeinen const char *name) 595f76ee892STomi Valkeinen { 596f76ee892STomi Valkeinen } 597f76ee892STomi Valkeinen #endif 598f76ee892STomi Valkeinen 599f76ee892STomi Valkeinen static int verbose_irq; 600f76ee892STomi Valkeinen 601f76ee892STomi Valkeinen static void print_irq_status(u32 status) 602f76ee892STomi Valkeinen { 603f76ee892STomi Valkeinen if (status == 0) 604f76ee892STomi Valkeinen return; 605f76ee892STomi Valkeinen 606f76ee892STomi Valkeinen if (!verbose_irq && (status & ~DSI_IRQ_CHANNEL_MASK) == 0) 607f76ee892STomi Valkeinen return; 608f76ee892STomi Valkeinen 609f76ee892STomi Valkeinen #define PIS(x) (status & DSI_IRQ_##x) ? (#x " ") : "" 610f76ee892STomi Valkeinen 611f76ee892STomi Valkeinen pr_debug("DSI IRQ: 0x%x: %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", 612f76ee892STomi Valkeinen status, 613f76ee892STomi Valkeinen verbose_irq ? PIS(VC0) : "", 614f76ee892STomi Valkeinen verbose_irq ? PIS(VC1) : "", 615f76ee892STomi Valkeinen verbose_irq ? PIS(VC2) : "", 616f76ee892STomi Valkeinen verbose_irq ? PIS(VC3) : "", 617f76ee892STomi Valkeinen PIS(WAKEUP), 618f76ee892STomi Valkeinen PIS(RESYNC), 619f76ee892STomi Valkeinen PIS(PLL_LOCK), 620f76ee892STomi Valkeinen PIS(PLL_UNLOCK), 621f76ee892STomi Valkeinen PIS(PLL_RECALL), 622f76ee892STomi Valkeinen PIS(COMPLEXIO_ERR), 623f76ee892STomi Valkeinen PIS(HS_TX_TIMEOUT), 624f76ee892STomi Valkeinen PIS(LP_RX_TIMEOUT), 625f76ee892STomi Valkeinen PIS(TE_TRIGGER), 626f76ee892STomi Valkeinen PIS(ACK_TRIGGER), 627f76ee892STomi Valkeinen PIS(SYNC_LOST), 628f76ee892STomi Valkeinen PIS(LDO_POWER_GOOD), 629f76ee892STomi Valkeinen PIS(TA_TIMEOUT)); 630f76ee892STomi Valkeinen #undef PIS 631f76ee892STomi Valkeinen } 632f76ee892STomi Valkeinen 633f76ee892STomi Valkeinen static void print_irq_status_vc(int channel, u32 status) 634f76ee892STomi Valkeinen { 635f76ee892STomi Valkeinen if (status == 0) 636f76ee892STomi Valkeinen return; 637f76ee892STomi Valkeinen 638f76ee892STomi Valkeinen if (!verbose_irq && (status & ~DSI_VC_IRQ_PACKET_SENT) == 0) 639f76ee892STomi Valkeinen return; 640f76ee892STomi Valkeinen 641f76ee892STomi Valkeinen #define PIS(x) (status & DSI_VC_IRQ_##x) ? (#x " ") : "" 642f76ee892STomi Valkeinen 643f76ee892STomi Valkeinen pr_debug("DSI VC(%d) IRQ 0x%x: %s%s%s%s%s%s%s%s%s\n", 644f76ee892STomi Valkeinen channel, 645f76ee892STomi Valkeinen status, 646f76ee892STomi Valkeinen PIS(CS), 647f76ee892STomi Valkeinen PIS(ECC_CORR), 648f76ee892STomi Valkeinen PIS(ECC_NO_CORR), 649f76ee892STomi Valkeinen verbose_irq ? PIS(PACKET_SENT) : "", 650f76ee892STomi Valkeinen PIS(BTA), 651f76ee892STomi Valkeinen PIS(FIFO_TX_OVF), 652f76ee892STomi Valkeinen PIS(FIFO_RX_OVF), 653f76ee892STomi Valkeinen PIS(FIFO_TX_UDF), 654f76ee892STomi Valkeinen PIS(PP_BUSY_CHANGE)); 655f76ee892STomi Valkeinen #undef PIS 656f76ee892STomi Valkeinen } 657f76ee892STomi Valkeinen 658f76ee892STomi Valkeinen static void print_irq_status_cio(u32 status) 659f76ee892STomi Valkeinen { 660f76ee892STomi Valkeinen if (status == 0) 661f76ee892STomi Valkeinen return; 662f76ee892STomi Valkeinen 663f76ee892STomi Valkeinen #define PIS(x) (status & DSI_CIO_IRQ_##x) ? (#x " ") : "" 664f76ee892STomi Valkeinen 665f76ee892STomi Valkeinen 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", 666f76ee892STomi Valkeinen status, 667f76ee892STomi Valkeinen PIS(ERRSYNCESC1), 668f76ee892STomi Valkeinen PIS(ERRSYNCESC2), 669f76ee892STomi Valkeinen PIS(ERRSYNCESC3), 670f76ee892STomi Valkeinen PIS(ERRESC1), 671f76ee892STomi Valkeinen PIS(ERRESC2), 672f76ee892STomi Valkeinen PIS(ERRESC3), 673f76ee892STomi Valkeinen PIS(ERRCONTROL1), 674f76ee892STomi Valkeinen PIS(ERRCONTROL2), 675f76ee892STomi Valkeinen PIS(ERRCONTROL3), 676f76ee892STomi Valkeinen PIS(STATEULPS1), 677f76ee892STomi Valkeinen PIS(STATEULPS2), 678f76ee892STomi Valkeinen PIS(STATEULPS3), 679f76ee892STomi Valkeinen PIS(ERRCONTENTIONLP0_1), 680f76ee892STomi Valkeinen PIS(ERRCONTENTIONLP1_1), 681f76ee892STomi Valkeinen PIS(ERRCONTENTIONLP0_2), 682f76ee892STomi Valkeinen PIS(ERRCONTENTIONLP1_2), 683f76ee892STomi Valkeinen PIS(ERRCONTENTIONLP0_3), 684f76ee892STomi Valkeinen PIS(ERRCONTENTIONLP1_3), 685f76ee892STomi Valkeinen PIS(ULPSACTIVENOT_ALL0), 686f76ee892STomi Valkeinen PIS(ULPSACTIVENOT_ALL1)); 687f76ee892STomi Valkeinen #undef PIS 688f76ee892STomi Valkeinen } 689f76ee892STomi Valkeinen 69035b522cfSTomi Valkeinen #ifdef CONFIG_FB_OMAP2_DSS_COLLECT_IRQ_STATS 691f76ee892STomi Valkeinen static void dsi_collect_irq_stats(struct platform_device *dsidev, u32 irqstatus, 692f76ee892STomi Valkeinen u32 *vcstatus, u32 ciostatus) 693f76ee892STomi Valkeinen { 694f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 695f76ee892STomi Valkeinen int i; 696f76ee892STomi Valkeinen 697f76ee892STomi Valkeinen spin_lock(&dsi->irq_stats_lock); 698f76ee892STomi Valkeinen 699f76ee892STomi Valkeinen dsi->irq_stats.irq_count++; 700f76ee892STomi Valkeinen dss_collect_irq_stats(irqstatus, dsi->irq_stats.dsi_irqs); 701f76ee892STomi Valkeinen 702f76ee892STomi Valkeinen for (i = 0; i < 4; ++i) 703f76ee892STomi Valkeinen dss_collect_irq_stats(vcstatus[i], dsi->irq_stats.vc_irqs[i]); 704f76ee892STomi Valkeinen 705f76ee892STomi Valkeinen dss_collect_irq_stats(ciostatus, dsi->irq_stats.cio_irqs); 706f76ee892STomi Valkeinen 707f76ee892STomi Valkeinen spin_unlock(&dsi->irq_stats_lock); 708f76ee892STomi Valkeinen } 709f76ee892STomi Valkeinen #else 710f76ee892STomi Valkeinen #define dsi_collect_irq_stats(dsidev, irqstatus, vcstatus, ciostatus) 711f76ee892STomi Valkeinen #endif 712f76ee892STomi Valkeinen 713f76ee892STomi Valkeinen static int debug_irq; 714f76ee892STomi Valkeinen 715f76ee892STomi Valkeinen static void dsi_handle_irq_errors(struct platform_device *dsidev, u32 irqstatus, 716f76ee892STomi Valkeinen u32 *vcstatus, u32 ciostatus) 717f76ee892STomi Valkeinen { 718f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 719f76ee892STomi Valkeinen int i; 720f76ee892STomi Valkeinen 721f76ee892STomi Valkeinen if (irqstatus & DSI_IRQ_ERROR_MASK) { 722f76ee892STomi Valkeinen DSSERR("DSI error, irqstatus %x\n", irqstatus); 723f76ee892STomi Valkeinen print_irq_status(irqstatus); 724f76ee892STomi Valkeinen spin_lock(&dsi->errors_lock); 725f76ee892STomi Valkeinen dsi->errors |= irqstatus & DSI_IRQ_ERROR_MASK; 726f76ee892STomi Valkeinen spin_unlock(&dsi->errors_lock); 727f76ee892STomi Valkeinen } else if (debug_irq) { 728f76ee892STomi Valkeinen print_irq_status(irqstatus); 729f76ee892STomi Valkeinen } 730f76ee892STomi Valkeinen 731f76ee892STomi Valkeinen for (i = 0; i < 4; ++i) { 732f76ee892STomi Valkeinen if (vcstatus[i] & DSI_VC_IRQ_ERROR_MASK) { 733f76ee892STomi Valkeinen DSSERR("DSI VC(%d) error, vc irqstatus %x\n", 734f76ee892STomi Valkeinen i, vcstatus[i]); 735f76ee892STomi Valkeinen print_irq_status_vc(i, vcstatus[i]); 736f76ee892STomi Valkeinen } else if (debug_irq) { 737f76ee892STomi Valkeinen print_irq_status_vc(i, vcstatus[i]); 738f76ee892STomi Valkeinen } 739f76ee892STomi Valkeinen } 740f76ee892STomi Valkeinen 741f76ee892STomi Valkeinen if (ciostatus & DSI_CIO_IRQ_ERROR_MASK) { 742f76ee892STomi Valkeinen DSSERR("DSI CIO error, cio irqstatus %x\n", ciostatus); 743f76ee892STomi Valkeinen print_irq_status_cio(ciostatus); 744f76ee892STomi Valkeinen } else if (debug_irq) { 745f76ee892STomi Valkeinen print_irq_status_cio(ciostatus); 746f76ee892STomi Valkeinen } 747f76ee892STomi Valkeinen } 748f76ee892STomi Valkeinen 749f76ee892STomi Valkeinen static void dsi_call_isrs(struct dsi_isr_data *isr_array, 750f76ee892STomi Valkeinen unsigned isr_array_size, u32 irqstatus) 751f76ee892STomi Valkeinen { 752f76ee892STomi Valkeinen struct dsi_isr_data *isr_data; 753f76ee892STomi Valkeinen int i; 754f76ee892STomi Valkeinen 755f76ee892STomi Valkeinen for (i = 0; i < isr_array_size; i++) { 756f76ee892STomi Valkeinen isr_data = &isr_array[i]; 757f76ee892STomi Valkeinen if (isr_data->isr && isr_data->mask & irqstatus) 758f76ee892STomi Valkeinen isr_data->isr(isr_data->arg, irqstatus); 759f76ee892STomi Valkeinen } 760f76ee892STomi Valkeinen } 761f76ee892STomi Valkeinen 762f76ee892STomi Valkeinen static void dsi_handle_isrs(struct dsi_isr_tables *isr_tables, 763f76ee892STomi Valkeinen u32 irqstatus, u32 *vcstatus, u32 ciostatus) 764f76ee892STomi Valkeinen { 765f76ee892STomi Valkeinen int i; 766f76ee892STomi Valkeinen 767f76ee892STomi Valkeinen dsi_call_isrs(isr_tables->isr_table, 768f76ee892STomi Valkeinen ARRAY_SIZE(isr_tables->isr_table), 769f76ee892STomi Valkeinen irqstatus); 770f76ee892STomi Valkeinen 771f76ee892STomi Valkeinen for (i = 0; i < 4; ++i) { 772f76ee892STomi Valkeinen if (vcstatus[i] == 0) 773f76ee892STomi Valkeinen continue; 774f76ee892STomi Valkeinen dsi_call_isrs(isr_tables->isr_table_vc[i], 775f76ee892STomi Valkeinen ARRAY_SIZE(isr_tables->isr_table_vc[i]), 776f76ee892STomi Valkeinen vcstatus[i]); 777f76ee892STomi Valkeinen } 778f76ee892STomi Valkeinen 779f76ee892STomi Valkeinen if (ciostatus != 0) 780f76ee892STomi Valkeinen dsi_call_isrs(isr_tables->isr_table_cio, 781f76ee892STomi Valkeinen ARRAY_SIZE(isr_tables->isr_table_cio), 782f76ee892STomi Valkeinen ciostatus); 783f76ee892STomi Valkeinen } 784f76ee892STomi Valkeinen 785f76ee892STomi Valkeinen static irqreturn_t omap_dsi_irq_handler(int irq, void *arg) 786f76ee892STomi Valkeinen { 787f76ee892STomi Valkeinen struct platform_device *dsidev; 788f76ee892STomi Valkeinen struct dsi_data *dsi; 789f76ee892STomi Valkeinen u32 irqstatus, vcstatus[4], ciostatus; 790f76ee892STomi Valkeinen int i; 791f76ee892STomi Valkeinen 792f76ee892STomi Valkeinen dsidev = (struct platform_device *) arg; 793f76ee892STomi Valkeinen dsi = dsi_get_dsidrv_data(dsidev); 794f76ee892STomi Valkeinen 795f76ee892STomi Valkeinen if (!dsi->is_enabled) 796f76ee892STomi Valkeinen return IRQ_NONE; 797f76ee892STomi Valkeinen 798f76ee892STomi Valkeinen spin_lock(&dsi->irq_lock); 799f76ee892STomi Valkeinen 800f76ee892STomi Valkeinen irqstatus = dsi_read_reg(dsidev, DSI_IRQSTATUS); 801f76ee892STomi Valkeinen 802f76ee892STomi Valkeinen /* IRQ is not for us */ 803f76ee892STomi Valkeinen if (!irqstatus) { 804f76ee892STomi Valkeinen spin_unlock(&dsi->irq_lock); 805f76ee892STomi Valkeinen return IRQ_NONE; 806f76ee892STomi Valkeinen } 807f76ee892STomi Valkeinen 808f76ee892STomi Valkeinen dsi_write_reg(dsidev, DSI_IRQSTATUS, irqstatus & ~DSI_IRQ_CHANNEL_MASK); 809f76ee892STomi Valkeinen /* flush posted write */ 810f76ee892STomi Valkeinen dsi_read_reg(dsidev, DSI_IRQSTATUS); 811f76ee892STomi Valkeinen 812f76ee892STomi Valkeinen for (i = 0; i < 4; ++i) { 813f76ee892STomi Valkeinen if ((irqstatus & (1 << i)) == 0) { 814f76ee892STomi Valkeinen vcstatus[i] = 0; 815f76ee892STomi Valkeinen continue; 816f76ee892STomi Valkeinen } 817f76ee892STomi Valkeinen 818f76ee892STomi Valkeinen vcstatus[i] = dsi_read_reg(dsidev, DSI_VC_IRQSTATUS(i)); 819f76ee892STomi Valkeinen 820f76ee892STomi Valkeinen dsi_write_reg(dsidev, DSI_VC_IRQSTATUS(i), vcstatus[i]); 821f76ee892STomi Valkeinen /* flush posted write */ 822f76ee892STomi Valkeinen dsi_read_reg(dsidev, DSI_VC_IRQSTATUS(i)); 823f76ee892STomi Valkeinen } 824f76ee892STomi Valkeinen 825f76ee892STomi Valkeinen if (irqstatus & DSI_IRQ_COMPLEXIO_ERR) { 826f76ee892STomi Valkeinen ciostatus = dsi_read_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS); 827f76ee892STomi Valkeinen 828f76ee892STomi Valkeinen dsi_write_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS, ciostatus); 829f76ee892STomi Valkeinen /* flush posted write */ 830f76ee892STomi Valkeinen dsi_read_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS); 831f76ee892STomi Valkeinen } else { 832f76ee892STomi Valkeinen ciostatus = 0; 833f76ee892STomi Valkeinen } 834f76ee892STomi Valkeinen 835f76ee892STomi Valkeinen #ifdef DSI_CATCH_MISSING_TE 836f76ee892STomi Valkeinen if (irqstatus & DSI_IRQ_TE_TRIGGER) 837f76ee892STomi Valkeinen del_timer(&dsi->te_timer); 838f76ee892STomi Valkeinen #endif 839f76ee892STomi Valkeinen 840f76ee892STomi Valkeinen /* make a copy and unlock, so that isrs can unregister 841f76ee892STomi Valkeinen * themselves */ 842f76ee892STomi Valkeinen memcpy(&dsi->isr_tables_copy, &dsi->isr_tables, 843f76ee892STomi Valkeinen sizeof(dsi->isr_tables)); 844f76ee892STomi Valkeinen 845f76ee892STomi Valkeinen spin_unlock(&dsi->irq_lock); 846f76ee892STomi Valkeinen 847f76ee892STomi Valkeinen dsi_handle_isrs(&dsi->isr_tables_copy, irqstatus, vcstatus, ciostatus); 848f76ee892STomi Valkeinen 849f76ee892STomi Valkeinen dsi_handle_irq_errors(dsidev, irqstatus, vcstatus, ciostatus); 850f76ee892STomi Valkeinen 851f76ee892STomi Valkeinen dsi_collect_irq_stats(dsidev, irqstatus, vcstatus, ciostatus); 852f76ee892STomi Valkeinen 853f76ee892STomi Valkeinen return IRQ_HANDLED; 854f76ee892STomi Valkeinen } 855f76ee892STomi Valkeinen 856f76ee892STomi Valkeinen /* dsi->irq_lock has to be locked by the caller */ 857f76ee892STomi Valkeinen static void _omap_dsi_configure_irqs(struct platform_device *dsidev, 858f76ee892STomi Valkeinen struct dsi_isr_data *isr_array, 859f76ee892STomi Valkeinen unsigned isr_array_size, u32 default_mask, 860f76ee892STomi Valkeinen const struct dsi_reg enable_reg, 861f76ee892STomi Valkeinen const struct dsi_reg status_reg) 862f76ee892STomi Valkeinen { 863f76ee892STomi Valkeinen struct dsi_isr_data *isr_data; 864f76ee892STomi Valkeinen u32 mask; 865f76ee892STomi Valkeinen u32 old_mask; 866f76ee892STomi Valkeinen int i; 867f76ee892STomi Valkeinen 868f76ee892STomi Valkeinen mask = default_mask; 869f76ee892STomi Valkeinen 870f76ee892STomi Valkeinen for (i = 0; i < isr_array_size; i++) { 871f76ee892STomi Valkeinen isr_data = &isr_array[i]; 872f76ee892STomi Valkeinen 873f76ee892STomi Valkeinen if (isr_data->isr == NULL) 874f76ee892STomi Valkeinen continue; 875f76ee892STomi Valkeinen 876f76ee892STomi Valkeinen mask |= isr_data->mask; 877f76ee892STomi Valkeinen } 878f76ee892STomi Valkeinen 879f76ee892STomi Valkeinen old_mask = dsi_read_reg(dsidev, enable_reg); 880f76ee892STomi Valkeinen /* clear the irqstatus for newly enabled irqs */ 881f76ee892STomi Valkeinen dsi_write_reg(dsidev, status_reg, (mask ^ old_mask) & mask); 882f76ee892STomi Valkeinen dsi_write_reg(dsidev, enable_reg, mask); 883f76ee892STomi Valkeinen 884f76ee892STomi Valkeinen /* flush posted writes */ 885f76ee892STomi Valkeinen dsi_read_reg(dsidev, enable_reg); 886f76ee892STomi Valkeinen dsi_read_reg(dsidev, status_reg); 887f76ee892STomi Valkeinen } 888f76ee892STomi Valkeinen 889f76ee892STomi Valkeinen /* dsi->irq_lock has to be locked by the caller */ 890f76ee892STomi Valkeinen static void _omap_dsi_set_irqs(struct platform_device *dsidev) 891f76ee892STomi Valkeinen { 892f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 893f76ee892STomi Valkeinen u32 mask = DSI_IRQ_ERROR_MASK; 894f76ee892STomi Valkeinen #ifdef DSI_CATCH_MISSING_TE 895f76ee892STomi Valkeinen mask |= DSI_IRQ_TE_TRIGGER; 896f76ee892STomi Valkeinen #endif 897f76ee892STomi Valkeinen _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table, 898f76ee892STomi Valkeinen ARRAY_SIZE(dsi->isr_tables.isr_table), mask, 899f76ee892STomi Valkeinen DSI_IRQENABLE, DSI_IRQSTATUS); 900f76ee892STomi Valkeinen } 901f76ee892STomi Valkeinen 902f76ee892STomi Valkeinen /* dsi->irq_lock has to be locked by the caller */ 903f76ee892STomi Valkeinen static void _omap_dsi_set_irqs_vc(struct platform_device *dsidev, int vc) 904f76ee892STomi Valkeinen { 905f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 906f76ee892STomi Valkeinen 907f76ee892STomi Valkeinen _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table_vc[vc], 908f76ee892STomi Valkeinen ARRAY_SIZE(dsi->isr_tables.isr_table_vc[vc]), 909f76ee892STomi Valkeinen DSI_VC_IRQ_ERROR_MASK, 910f76ee892STomi Valkeinen DSI_VC_IRQENABLE(vc), DSI_VC_IRQSTATUS(vc)); 911f76ee892STomi Valkeinen } 912f76ee892STomi Valkeinen 913f76ee892STomi Valkeinen /* dsi->irq_lock has to be locked by the caller */ 914f76ee892STomi Valkeinen static void _omap_dsi_set_irqs_cio(struct platform_device *dsidev) 915f76ee892STomi Valkeinen { 916f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 917f76ee892STomi Valkeinen 918f76ee892STomi Valkeinen _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table_cio, 919f76ee892STomi Valkeinen ARRAY_SIZE(dsi->isr_tables.isr_table_cio), 920f76ee892STomi Valkeinen DSI_CIO_IRQ_ERROR_MASK, 921f76ee892STomi Valkeinen DSI_COMPLEXIO_IRQ_ENABLE, DSI_COMPLEXIO_IRQ_STATUS); 922f76ee892STomi Valkeinen } 923f76ee892STomi Valkeinen 924f76ee892STomi Valkeinen static void _dsi_initialize_irq(struct platform_device *dsidev) 925f76ee892STomi Valkeinen { 926f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 927f76ee892STomi Valkeinen unsigned long flags; 928f76ee892STomi Valkeinen int vc; 929f76ee892STomi Valkeinen 930f76ee892STomi Valkeinen spin_lock_irqsave(&dsi->irq_lock, flags); 931f76ee892STomi Valkeinen 932f76ee892STomi Valkeinen memset(&dsi->isr_tables, 0, sizeof(dsi->isr_tables)); 933f76ee892STomi Valkeinen 934f76ee892STomi Valkeinen _omap_dsi_set_irqs(dsidev); 935f76ee892STomi Valkeinen for (vc = 0; vc < 4; ++vc) 936f76ee892STomi Valkeinen _omap_dsi_set_irqs_vc(dsidev, vc); 937f76ee892STomi Valkeinen _omap_dsi_set_irqs_cio(dsidev); 938f76ee892STomi Valkeinen 939f76ee892STomi Valkeinen spin_unlock_irqrestore(&dsi->irq_lock, flags); 940f76ee892STomi Valkeinen } 941f76ee892STomi Valkeinen 942f76ee892STomi Valkeinen static int _dsi_register_isr(omap_dsi_isr_t isr, void *arg, u32 mask, 943f76ee892STomi Valkeinen struct dsi_isr_data *isr_array, unsigned isr_array_size) 944f76ee892STomi Valkeinen { 945f76ee892STomi Valkeinen struct dsi_isr_data *isr_data; 946f76ee892STomi Valkeinen int free_idx; 947f76ee892STomi Valkeinen int i; 948f76ee892STomi Valkeinen 949f76ee892STomi Valkeinen BUG_ON(isr == NULL); 950f76ee892STomi Valkeinen 951f76ee892STomi Valkeinen /* check for duplicate entry and find a free slot */ 952f76ee892STomi Valkeinen free_idx = -1; 953f76ee892STomi Valkeinen for (i = 0; i < isr_array_size; i++) { 954f76ee892STomi Valkeinen isr_data = &isr_array[i]; 955f76ee892STomi Valkeinen 956f76ee892STomi Valkeinen if (isr_data->isr == isr && isr_data->arg == arg && 957f76ee892STomi Valkeinen isr_data->mask == mask) { 958f76ee892STomi Valkeinen return -EINVAL; 959f76ee892STomi Valkeinen } 960f76ee892STomi Valkeinen 961f76ee892STomi Valkeinen if (isr_data->isr == NULL && free_idx == -1) 962f76ee892STomi Valkeinen free_idx = i; 963f76ee892STomi Valkeinen } 964f76ee892STomi Valkeinen 965f76ee892STomi Valkeinen if (free_idx == -1) 966f76ee892STomi Valkeinen return -EBUSY; 967f76ee892STomi Valkeinen 968f76ee892STomi Valkeinen isr_data = &isr_array[free_idx]; 969f76ee892STomi Valkeinen isr_data->isr = isr; 970f76ee892STomi Valkeinen isr_data->arg = arg; 971f76ee892STomi Valkeinen isr_data->mask = mask; 972f76ee892STomi Valkeinen 973f76ee892STomi Valkeinen return 0; 974f76ee892STomi Valkeinen } 975f76ee892STomi Valkeinen 976f76ee892STomi Valkeinen static int _dsi_unregister_isr(omap_dsi_isr_t isr, void *arg, u32 mask, 977f76ee892STomi Valkeinen struct dsi_isr_data *isr_array, unsigned isr_array_size) 978f76ee892STomi Valkeinen { 979f76ee892STomi Valkeinen struct dsi_isr_data *isr_data; 980f76ee892STomi Valkeinen int i; 981f76ee892STomi Valkeinen 982f76ee892STomi Valkeinen for (i = 0; i < isr_array_size; i++) { 983f76ee892STomi Valkeinen isr_data = &isr_array[i]; 984f76ee892STomi Valkeinen if (isr_data->isr != isr || isr_data->arg != arg || 985f76ee892STomi Valkeinen isr_data->mask != mask) 986f76ee892STomi Valkeinen continue; 987f76ee892STomi Valkeinen 988f76ee892STomi Valkeinen isr_data->isr = NULL; 989f76ee892STomi Valkeinen isr_data->arg = NULL; 990f76ee892STomi Valkeinen isr_data->mask = 0; 991f76ee892STomi Valkeinen 992f76ee892STomi Valkeinen return 0; 993f76ee892STomi Valkeinen } 994f76ee892STomi Valkeinen 995f76ee892STomi Valkeinen return -EINVAL; 996f76ee892STomi Valkeinen } 997f76ee892STomi Valkeinen 998f76ee892STomi Valkeinen static int dsi_register_isr(struct platform_device *dsidev, omap_dsi_isr_t isr, 999f76ee892STomi Valkeinen void *arg, u32 mask) 1000f76ee892STomi Valkeinen { 1001f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 1002f76ee892STomi Valkeinen unsigned long flags; 1003f76ee892STomi Valkeinen int r; 1004f76ee892STomi Valkeinen 1005f76ee892STomi Valkeinen spin_lock_irqsave(&dsi->irq_lock, flags); 1006f76ee892STomi Valkeinen 1007f76ee892STomi Valkeinen r = _dsi_register_isr(isr, arg, mask, dsi->isr_tables.isr_table, 1008f76ee892STomi Valkeinen ARRAY_SIZE(dsi->isr_tables.isr_table)); 1009f76ee892STomi Valkeinen 1010f76ee892STomi Valkeinen if (r == 0) 1011f76ee892STomi Valkeinen _omap_dsi_set_irqs(dsidev); 1012f76ee892STomi Valkeinen 1013f76ee892STomi Valkeinen spin_unlock_irqrestore(&dsi->irq_lock, flags); 1014f76ee892STomi Valkeinen 1015f76ee892STomi Valkeinen return r; 1016f76ee892STomi Valkeinen } 1017f76ee892STomi Valkeinen 1018f76ee892STomi Valkeinen static int dsi_unregister_isr(struct platform_device *dsidev, 1019f76ee892STomi Valkeinen omap_dsi_isr_t isr, void *arg, u32 mask) 1020f76ee892STomi Valkeinen { 1021f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 1022f76ee892STomi Valkeinen unsigned long flags; 1023f76ee892STomi Valkeinen int r; 1024f76ee892STomi Valkeinen 1025f76ee892STomi Valkeinen spin_lock_irqsave(&dsi->irq_lock, flags); 1026f76ee892STomi Valkeinen 1027f76ee892STomi Valkeinen r = _dsi_unregister_isr(isr, arg, mask, dsi->isr_tables.isr_table, 1028f76ee892STomi Valkeinen ARRAY_SIZE(dsi->isr_tables.isr_table)); 1029f76ee892STomi Valkeinen 1030f76ee892STomi Valkeinen if (r == 0) 1031f76ee892STomi Valkeinen _omap_dsi_set_irqs(dsidev); 1032f76ee892STomi Valkeinen 1033f76ee892STomi Valkeinen spin_unlock_irqrestore(&dsi->irq_lock, flags); 1034f76ee892STomi Valkeinen 1035f76ee892STomi Valkeinen return r; 1036f76ee892STomi Valkeinen } 1037f76ee892STomi Valkeinen 1038f76ee892STomi Valkeinen static int dsi_register_isr_vc(struct platform_device *dsidev, int channel, 1039f76ee892STomi Valkeinen omap_dsi_isr_t isr, void *arg, u32 mask) 1040f76ee892STomi Valkeinen { 1041f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 1042f76ee892STomi Valkeinen unsigned long flags; 1043f76ee892STomi Valkeinen int r; 1044f76ee892STomi Valkeinen 1045f76ee892STomi Valkeinen spin_lock_irqsave(&dsi->irq_lock, flags); 1046f76ee892STomi Valkeinen 1047f76ee892STomi Valkeinen r = _dsi_register_isr(isr, arg, mask, 1048f76ee892STomi Valkeinen dsi->isr_tables.isr_table_vc[channel], 1049f76ee892STomi Valkeinen ARRAY_SIZE(dsi->isr_tables.isr_table_vc[channel])); 1050f76ee892STomi Valkeinen 1051f76ee892STomi Valkeinen if (r == 0) 1052f76ee892STomi Valkeinen _omap_dsi_set_irqs_vc(dsidev, channel); 1053f76ee892STomi Valkeinen 1054f76ee892STomi Valkeinen spin_unlock_irqrestore(&dsi->irq_lock, flags); 1055f76ee892STomi Valkeinen 1056f76ee892STomi Valkeinen return r; 1057f76ee892STomi Valkeinen } 1058f76ee892STomi Valkeinen 1059f76ee892STomi Valkeinen static int dsi_unregister_isr_vc(struct platform_device *dsidev, int channel, 1060f76ee892STomi Valkeinen omap_dsi_isr_t isr, void *arg, u32 mask) 1061f76ee892STomi Valkeinen { 1062f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 1063f76ee892STomi Valkeinen unsigned long flags; 1064f76ee892STomi Valkeinen int r; 1065f76ee892STomi Valkeinen 1066f76ee892STomi Valkeinen spin_lock_irqsave(&dsi->irq_lock, flags); 1067f76ee892STomi Valkeinen 1068f76ee892STomi Valkeinen r = _dsi_unregister_isr(isr, arg, mask, 1069f76ee892STomi Valkeinen dsi->isr_tables.isr_table_vc[channel], 1070f76ee892STomi Valkeinen ARRAY_SIZE(dsi->isr_tables.isr_table_vc[channel])); 1071f76ee892STomi Valkeinen 1072f76ee892STomi Valkeinen if (r == 0) 1073f76ee892STomi Valkeinen _omap_dsi_set_irqs_vc(dsidev, channel); 1074f76ee892STomi Valkeinen 1075f76ee892STomi Valkeinen spin_unlock_irqrestore(&dsi->irq_lock, flags); 1076f76ee892STomi Valkeinen 1077f76ee892STomi Valkeinen return r; 1078f76ee892STomi Valkeinen } 1079f76ee892STomi Valkeinen 1080f76ee892STomi Valkeinen static int dsi_register_isr_cio(struct platform_device *dsidev, 1081f76ee892STomi Valkeinen omap_dsi_isr_t isr, void *arg, u32 mask) 1082f76ee892STomi Valkeinen { 1083f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 1084f76ee892STomi Valkeinen unsigned long flags; 1085f76ee892STomi Valkeinen int r; 1086f76ee892STomi Valkeinen 1087f76ee892STomi Valkeinen spin_lock_irqsave(&dsi->irq_lock, flags); 1088f76ee892STomi Valkeinen 1089f76ee892STomi Valkeinen r = _dsi_register_isr(isr, arg, mask, dsi->isr_tables.isr_table_cio, 1090f76ee892STomi Valkeinen ARRAY_SIZE(dsi->isr_tables.isr_table_cio)); 1091f76ee892STomi Valkeinen 1092f76ee892STomi Valkeinen if (r == 0) 1093f76ee892STomi Valkeinen _omap_dsi_set_irqs_cio(dsidev); 1094f76ee892STomi Valkeinen 1095f76ee892STomi Valkeinen spin_unlock_irqrestore(&dsi->irq_lock, flags); 1096f76ee892STomi Valkeinen 1097f76ee892STomi Valkeinen return r; 1098f76ee892STomi Valkeinen } 1099f76ee892STomi Valkeinen 1100f76ee892STomi Valkeinen static int dsi_unregister_isr_cio(struct platform_device *dsidev, 1101f76ee892STomi Valkeinen omap_dsi_isr_t isr, void *arg, u32 mask) 1102f76ee892STomi Valkeinen { 1103f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 1104f76ee892STomi Valkeinen unsigned long flags; 1105f76ee892STomi Valkeinen int r; 1106f76ee892STomi Valkeinen 1107f76ee892STomi Valkeinen spin_lock_irqsave(&dsi->irq_lock, flags); 1108f76ee892STomi Valkeinen 1109f76ee892STomi Valkeinen r = _dsi_unregister_isr(isr, arg, mask, dsi->isr_tables.isr_table_cio, 1110f76ee892STomi Valkeinen ARRAY_SIZE(dsi->isr_tables.isr_table_cio)); 1111f76ee892STomi Valkeinen 1112f76ee892STomi Valkeinen if (r == 0) 1113f76ee892STomi Valkeinen _omap_dsi_set_irqs_cio(dsidev); 1114f76ee892STomi Valkeinen 1115f76ee892STomi Valkeinen spin_unlock_irqrestore(&dsi->irq_lock, flags); 1116f76ee892STomi Valkeinen 1117f76ee892STomi Valkeinen return r; 1118f76ee892STomi Valkeinen } 1119f76ee892STomi Valkeinen 1120f76ee892STomi Valkeinen static u32 dsi_get_errors(struct platform_device *dsidev) 1121f76ee892STomi Valkeinen { 1122f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 1123f76ee892STomi Valkeinen unsigned long flags; 1124f76ee892STomi Valkeinen u32 e; 1125f76ee892STomi Valkeinen spin_lock_irqsave(&dsi->errors_lock, flags); 1126f76ee892STomi Valkeinen e = dsi->errors; 1127f76ee892STomi Valkeinen dsi->errors = 0; 1128f76ee892STomi Valkeinen spin_unlock_irqrestore(&dsi->errors_lock, flags); 1129f76ee892STomi Valkeinen return e; 1130f76ee892STomi Valkeinen } 1131f76ee892STomi Valkeinen 1132f76ee892STomi Valkeinen static int dsi_runtime_get(struct platform_device *dsidev) 1133f76ee892STomi Valkeinen { 1134f76ee892STomi Valkeinen int r; 1135f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 1136f76ee892STomi Valkeinen 1137f76ee892STomi Valkeinen DSSDBG("dsi_runtime_get\n"); 1138f76ee892STomi Valkeinen 1139f76ee892STomi Valkeinen r = pm_runtime_get_sync(&dsi->pdev->dev); 114078c2ce9bSAditya Pakki if (WARN_ON(r < 0)) { 114178c2ce9bSAditya Pakki pm_runtime_put_sync(&dsi->pdev->dev); 114278c2ce9bSAditya Pakki return r; 114378c2ce9bSAditya Pakki } 114478c2ce9bSAditya Pakki return 0; 1145f76ee892STomi Valkeinen } 1146f76ee892STomi Valkeinen 1147f76ee892STomi Valkeinen static void dsi_runtime_put(struct platform_device *dsidev) 1148f76ee892STomi Valkeinen { 1149f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 1150f76ee892STomi Valkeinen int r; 1151f76ee892STomi Valkeinen 1152f76ee892STomi Valkeinen DSSDBG("dsi_runtime_put\n"); 1153f76ee892STomi Valkeinen 1154f76ee892STomi Valkeinen r = pm_runtime_put_sync(&dsi->pdev->dev); 1155f76ee892STomi Valkeinen WARN_ON(r < 0 && r != -ENOSYS); 1156f76ee892STomi Valkeinen } 1157f76ee892STomi Valkeinen 1158f76ee892STomi Valkeinen static int dsi_regulator_init(struct platform_device *dsidev) 1159f76ee892STomi Valkeinen { 1160f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 1161f76ee892STomi Valkeinen struct regulator *vdds_dsi; 1162f76ee892STomi Valkeinen 1163f76ee892STomi Valkeinen if (dsi->vdds_dsi_reg != NULL) 1164f76ee892STomi Valkeinen return 0; 1165f76ee892STomi Valkeinen 1166f76ee892STomi Valkeinen vdds_dsi = devm_regulator_get(&dsi->pdev->dev, "vdd"); 1167f76ee892STomi Valkeinen 1168f76ee892STomi Valkeinen if (IS_ERR(vdds_dsi)) { 1169f76ee892STomi Valkeinen if (PTR_ERR(vdds_dsi) != -EPROBE_DEFER) 1170f76ee892STomi Valkeinen DSSERR("can't get DSI VDD regulator\n"); 1171f76ee892STomi Valkeinen return PTR_ERR(vdds_dsi); 1172f76ee892STomi Valkeinen } 1173f76ee892STomi Valkeinen 1174f76ee892STomi Valkeinen dsi->vdds_dsi_reg = vdds_dsi; 1175f76ee892STomi Valkeinen 1176f76ee892STomi Valkeinen return 0; 1177f76ee892STomi Valkeinen } 1178f76ee892STomi Valkeinen 1179f76ee892STomi Valkeinen static void _dsi_print_reset_status(struct platform_device *dsidev) 1180f76ee892STomi Valkeinen { 1181f76ee892STomi Valkeinen int b0, b1, b2; 1182f76ee892STomi Valkeinen 1183f76ee892STomi Valkeinen /* A dummy read using the SCP interface to any DSIPHY register is 1184f76ee892STomi Valkeinen * required after DSIPHY reset to complete the reset of the DSI complex 1185f76ee892STomi Valkeinen * I/O. */ 1186*c96da175SSam Ravnborg dsi_read_reg(dsidev, DSI_DSIPHY_CFG5); 1187f76ee892STomi Valkeinen 1188f76ee892STomi Valkeinen if (dss_has_feature(FEAT_DSI_REVERSE_TXCLKESC)) { 1189f76ee892STomi Valkeinen b0 = 28; 1190f76ee892STomi Valkeinen b1 = 27; 1191f76ee892STomi Valkeinen b2 = 26; 1192f76ee892STomi Valkeinen } else { 1193f76ee892STomi Valkeinen b0 = 24; 1194f76ee892STomi Valkeinen b1 = 25; 1195f76ee892STomi Valkeinen b2 = 26; 1196f76ee892STomi Valkeinen } 1197f76ee892STomi Valkeinen 1198f76ee892STomi Valkeinen #define DSI_FLD_GET(fld, start, end)\ 1199f76ee892STomi Valkeinen FLD_GET(dsi_read_reg(dsidev, DSI_##fld), start, end) 1200f76ee892STomi Valkeinen 1201f76ee892STomi Valkeinen pr_debug("DSI resets: PLL (%d) CIO (%d) PHY (%x%x%x, %d, %d, %d)\n", 1202f76ee892STomi Valkeinen DSI_FLD_GET(PLL_STATUS, 0, 0), 1203f76ee892STomi Valkeinen DSI_FLD_GET(COMPLEXIO_CFG1, 29, 29), 1204f76ee892STomi Valkeinen DSI_FLD_GET(DSIPHY_CFG5, b0, b0), 1205f76ee892STomi Valkeinen DSI_FLD_GET(DSIPHY_CFG5, b1, b1), 1206f76ee892STomi Valkeinen DSI_FLD_GET(DSIPHY_CFG5, b2, b2), 1207f76ee892STomi Valkeinen DSI_FLD_GET(DSIPHY_CFG5, 29, 29), 1208f76ee892STomi Valkeinen DSI_FLD_GET(DSIPHY_CFG5, 30, 30), 1209f76ee892STomi Valkeinen DSI_FLD_GET(DSIPHY_CFG5, 31, 31)); 1210f76ee892STomi Valkeinen 1211f76ee892STomi Valkeinen #undef DSI_FLD_GET 1212f76ee892STomi Valkeinen } 1213f76ee892STomi Valkeinen 1214f76ee892STomi Valkeinen static inline int dsi_if_enable(struct platform_device *dsidev, bool enable) 1215f76ee892STomi Valkeinen { 1216f76ee892STomi Valkeinen DSSDBG("dsi_if_enable(%d)\n", enable); 1217f76ee892STomi Valkeinen 1218f76ee892STomi Valkeinen enable = enable ? 1 : 0; 1219f76ee892STomi Valkeinen REG_FLD_MOD(dsidev, DSI_CTRL, enable, 0, 0); /* IF_EN */ 1220f76ee892STomi Valkeinen 1221f76ee892STomi Valkeinen if (wait_for_bit_change(dsidev, DSI_CTRL, 0, enable) != enable) { 1222f76ee892STomi Valkeinen DSSERR("Failed to set dsi_if_enable to %d\n", enable); 1223f76ee892STomi Valkeinen return -EIO; 1224f76ee892STomi Valkeinen } 1225f76ee892STomi Valkeinen 1226f76ee892STomi Valkeinen return 0; 1227f76ee892STomi Valkeinen } 1228f76ee892STomi Valkeinen 1229f76ee892STomi Valkeinen static unsigned long dsi_get_pll_hsdiv_dispc_rate(struct platform_device *dsidev) 1230f76ee892STomi Valkeinen { 1231f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 1232f76ee892STomi Valkeinen 1233f76ee892STomi Valkeinen return dsi->pll.cinfo.clkout[HSDIV_DISPC]; 1234f76ee892STomi Valkeinen } 1235f76ee892STomi Valkeinen 1236f76ee892STomi Valkeinen static unsigned long dsi_get_pll_hsdiv_dsi_rate(struct platform_device *dsidev) 1237f76ee892STomi Valkeinen { 1238f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 1239f76ee892STomi Valkeinen 1240f76ee892STomi Valkeinen return dsi->pll.cinfo.clkout[HSDIV_DSI]; 1241f76ee892STomi Valkeinen } 1242f76ee892STomi Valkeinen 1243f76ee892STomi Valkeinen static unsigned long dsi_get_txbyteclkhs(struct platform_device *dsidev) 1244f76ee892STomi Valkeinen { 1245f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 1246f76ee892STomi Valkeinen 1247f76ee892STomi Valkeinen return dsi->pll.cinfo.clkdco / 16; 1248f76ee892STomi Valkeinen } 1249f76ee892STomi Valkeinen 1250f76ee892STomi Valkeinen static unsigned long dsi_fclk_rate(struct platform_device *dsidev) 1251f76ee892STomi Valkeinen { 1252f76ee892STomi Valkeinen unsigned long r; 1253f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 1254f76ee892STomi Valkeinen 1255f76ee892STomi Valkeinen if (dss_get_dsi_clk_source(dsi->module_id) == OMAP_DSS_CLK_SRC_FCK) { 1256f76ee892STomi Valkeinen /* DSI FCLK source is DSS_CLK_FCK */ 1257f76ee892STomi Valkeinen r = clk_get_rate(dsi->dss_clk); 1258f76ee892STomi Valkeinen } else { 1259f76ee892STomi Valkeinen /* DSI FCLK source is dsi_pll_hsdiv_dsi_clk */ 1260f76ee892STomi Valkeinen r = dsi_get_pll_hsdiv_dsi_rate(dsidev); 1261f76ee892STomi Valkeinen } 1262f76ee892STomi Valkeinen 1263f76ee892STomi Valkeinen return r; 1264f76ee892STomi Valkeinen } 1265f76ee892STomi Valkeinen 1266f76ee892STomi Valkeinen static int dsi_lp_clock_calc(unsigned long dsi_fclk, 1267f76ee892STomi Valkeinen unsigned long lp_clk_min, unsigned long lp_clk_max, 1268f76ee892STomi Valkeinen struct dsi_lp_clock_info *lp_cinfo) 1269f76ee892STomi Valkeinen { 1270f76ee892STomi Valkeinen unsigned lp_clk_div; 1271f76ee892STomi Valkeinen unsigned long lp_clk; 1272f76ee892STomi Valkeinen 1273f76ee892STomi Valkeinen lp_clk_div = DIV_ROUND_UP(dsi_fclk, lp_clk_max * 2); 1274f76ee892STomi Valkeinen lp_clk = dsi_fclk / 2 / lp_clk_div; 1275f76ee892STomi Valkeinen 1276f76ee892STomi Valkeinen if (lp_clk < lp_clk_min || lp_clk > lp_clk_max) 1277f76ee892STomi Valkeinen return -EINVAL; 1278f76ee892STomi Valkeinen 1279f76ee892STomi Valkeinen lp_cinfo->lp_clk_div = lp_clk_div; 1280f76ee892STomi Valkeinen lp_cinfo->lp_clk = lp_clk; 1281f76ee892STomi Valkeinen 1282f76ee892STomi Valkeinen return 0; 1283f76ee892STomi Valkeinen } 1284f76ee892STomi Valkeinen 1285f76ee892STomi Valkeinen static int dsi_set_lp_clk_divisor(struct platform_device *dsidev) 1286f76ee892STomi Valkeinen { 1287f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 1288f76ee892STomi Valkeinen unsigned long dsi_fclk; 1289f76ee892STomi Valkeinen unsigned lp_clk_div; 1290f76ee892STomi Valkeinen unsigned long lp_clk; 1291f76ee892STomi Valkeinen unsigned lpdiv_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_LPDIV); 1292f76ee892STomi Valkeinen 1293f76ee892STomi Valkeinen 1294f76ee892STomi Valkeinen lp_clk_div = dsi->user_lp_cinfo.lp_clk_div; 1295f76ee892STomi Valkeinen 1296f76ee892STomi Valkeinen if (lp_clk_div == 0 || lp_clk_div > lpdiv_max) 1297f76ee892STomi Valkeinen return -EINVAL; 1298f76ee892STomi Valkeinen 1299f76ee892STomi Valkeinen dsi_fclk = dsi_fclk_rate(dsidev); 1300f76ee892STomi Valkeinen 1301f76ee892STomi Valkeinen lp_clk = dsi_fclk / 2 / lp_clk_div; 1302f76ee892STomi Valkeinen 1303f76ee892STomi Valkeinen DSSDBG("LP_CLK_DIV %u, LP_CLK %lu\n", lp_clk_div, lp_clk); 1304f76ee892STomi Valkeinen dsi->current_lp_cinfo.lp_clk = lp_clk; 1305f76ee892STomi Valkeinen dsi->current_lp_cinfo.lp_clk_div = lp_clk_div; 1306f76ee892STomi Valkeinen 1307f76ee892STomi Valkeinen /* LP_CLK_DIVISOR */ 1308f76ee892STomi Valkeinen REG_FLD_MOD(dsidev, DSI_CLK_CTRL, lp_clk_div, 12, 0); 1309f76ee892STomi Valkeinen 1310f76ee892STomi Valkeinen /* LP_RX_SYNCHRO_ENABLE */ 1311f76ee892STomi Valkeinen REG_FLD_MOD(dsidev, DSI_CLK_CTRL, dsi_fclk > 30000000 ? 1 : 0, 21, 21); 1312f76ee892STomi Valkeinen 1313f76ee892STomi Valkeinen return 0; 1314f76ee892STomi Valkeinen } 1315f76ee892STomi Valkeinen 1316f76ee892STomi Valkeinen static void dsi_enable_scp_clk(struct platform_device *dsidev) 1317f76ee892STomi Valkeinen { 1318f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 1319f76ee892STomi Valkeinen 1320f76ee892STomi Valkeinen if (dsi->scp_clk_refcount++ == 0) 1321f76ee892STomi Valkeinen REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 14, 14); /* CIO_CLK_ICG */ 1322f76ee892STomi Valkeinen } 1323f76ee892STomi Valkeinen 1324f76ee892STomi Valkeinen static void dsi_disable_scp_clk(struct platform_device *dsidev) 1325f76ee892STomi Valkeinen { 1326f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 1327f76ee892STomi Valkeinen 1328f76ee892STomi Valkeinen WARN_ON(dsi->scp_clk_refcount == 0); 1329f76ee892STomi Valkeinen if (--dsi->scp_clk_refcount == 0) 1330f76ee892STomi Valkeinen REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 14, 14); /* CIO_CLK_ICG */ 1331f76ee892STomi Valkeinen } 1332f76ee892STomi Valkeinen 1333f76ee892STomi Valkeinen enum dsi_pll_power_state { 1334f76ee892STomi Valkeinen DSI_PLL_POWER_OFF = 0x0, 1335f76ee892STomi Valkeinen DSI_PLL_POWER_ON_HSCLK = 0x1, 1336f76ee892STomi Valkeinen DSI_PLL_POWER_ON_ALL = 0x2, 1337f76ee892STomi Valkeinen DSI_PLL_POWER_ON_DIV = 0x3, 1338f76ee892STomi Valkeinen }; 1339f76ee892STomi Valkeinen 1340f76ee892STomi Valkeinen static int dsi_pll_power(struct platform_device *dsidev, 1341f76ee892STomi Valkeinen enum dsi_pll_power_state state) 1342f76ee892STomi Valkeinen { 1343f76ee892STomi Valkeinen int t = 0; 1344f76ee892STomi Valkeinen 1345f76ee892STomi Valkeinen /* DSI-PLL power command 0x3 is not working */ 1346f76ee892STomi Valkeinen if (dss_has_feature(FEAT_DSI_PLL_PWR_BUG) && 1347f76ee892STomi Valkeinen state == DSI_PLL_POWER_ON_DIV) 1348f76ee892STomi Valkeinen state = DSI_PLL_POWER_ON_ALL; 1349f76ee892STomi Valkeinen 1350f76ee892STomi Valkeinen /* PLL_PWR_CMD */ 1351f76ee892STomi Valkeinen REG_FLD_MOD(dsidev, DSI_CLK_CTRL, state, 31, 30); 1352f76ee892STomi Valkeinen 1353f76ee892STomi Valkeinen /* PLL_PWR_STATUS */ 1354f76ee892STomi Valkeinen while (FLD_GET(dsi_read_reg(dsidev, DSI_CLK_CTRL), 29, 28) != state) { 1355f76ee892STomi Valkeinen if (++t > 1000) { 1356f76ee892STomi Valkeinen DSSERR("Failed to set DSI PLL power mode to %d\n", 1357f76ee892STomi Valkeinen state); 1358f76ee892STomi Valkeinen return -ENODEV; 1359f76ee892STomi Valkeinen } 1360f76ee892STomi Valkeinen udelay(1); 1361f76ee892STomi Valkeinen } 1362f76ee892STomi Valkeinen 1363f76ee892STomi Valkeinen return 0; 1364f76ee892STomi Valkeinen } 1365f76ee892STomi Valkeinen 1366f76ee892STomi Valkeinen 1367f76ee892STomi Valkeinen static void dsi_pll_calc_dsi_fck(struct dss_pll_clock_info *cinfo) 1368f76ee892STomi Valkeinen { 1369f76ee892STomi Valkeinen unsigned long max_dsi_fck; 1370f76ee892STomi Valkeinen 1371f76ee892STomi Valkeinen max_dsi_fck = dss_feat_get_param_max(FEAT_PARAM_DSI_FCK); 1372f76ee892STomi Valkeinen 1373f76ee892STomi Valkeinen cinfo->mX[HSDIV_DSI] = DIV_ROUND_UP(cinfo->clkdco, max_dsi_fck); 1374f76ee892STomi Valkeinen cinfo->clkout[HSDIV_DSI] = cinfo->clkdco / cinfo->mX[HSDIV_DSI]; 1375f76ee892STomi Valkeinen } 1376f76ee892STomi Valkeinen 1377f76ee892STomi Valkeinen static int dsi_pll_enable(struct dss_pll *pll) 1378f76ee892STomi Valkeinen { 1379f76ee892STomi Valkeinen struct dsi_data *dsi = container_of(pll, struct dsi_data, pll); 1380f76ee892STomi Valkeinen struct platform_device *dsidev = dsi->pdev; 1381f76ee892STomi Valkeinen int r = 0; 1382f76ee892STomi Valkeinen 1383f76ee892STomi Valkeinen DSSDBG("PLL init\n"); 1384f76ee892STomi Valkeinen 1385f76ee892STomi Valkeinen r = dsi_regulator_init(dsidev); 1386f76ee892STomi Valkeinen if (r) 1387f76ee892STomi Valkeinen return r; 1388f76ee892STomi Valkeinen 1389f76ee892STomi Valkeinen r = dsi_runtime_get(dsidev); 1390f76ee892STomi Valkeinen if (r) 1391f76ee892STomi Valkeinen return r; 1392f76ee892STomi Valkeinen 1393f76ee892STomi Valkeinen /* 1394f76ee892STomi Valkeinen * Note: SCP CLK is not required on OMAP3, but it is required on OMAP4. 1395f76ee892STomi Valkeinen */ 1396f76ee892STomi Valkeinen dsi_enable_scp_clk(dsidev); 1397f76ee892STomi Valkeinen 1398f76ee892STomi Valkeinen if (!dsi->vdds_dsi_enabled) { 1399f76ee892STomi Valkeinen r = regulator_enable(dsi->vdds_dsi_reg); 1400f76ee892STomi Valkeinen if (r) 1401f76ee892STomi Valkeinen goto err0; 1402f76ee892STomi Valkeinen dsi->vdds_dsi_enabled = true; 1403f76ee892STomi Valkeinen } 1404f76ee892STomi Valkeinen 1405f76ee892STomi Valkeinen /* XXX PLL does not come out of reset without this... */ 1406f76ee892STomi Valkeinen dispc_pck_free_enable(1); 1407f76ee892STomi Valkeinen 1408f76ee892STomi Valkeinen if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 0, 1) != 1) { 1409f76ee892STomi Valkeinen DSSERR("PLL not coming out of reset.\n"); 1410f76ee892STomi Valkeinen r = -ENODEV; 1411f76ee892STomi Valkeinen dispc_pck_free_enable(0); 1412f76ee892STomi Valkeinen goto err1; 1413f76ee892STomi Valkeinen } 1414f76ee892STomi Valkeinen 1415f76ee892STomi Valkeinen /* XXX ... but if left on, we get problems when planes do not 1416f76ee892STomi Valkeinen * fill the whole display. No idea about this */ 1417f76ee892STomi Valkeinen dispc_pck_free_enable(0); 1418f76ee892STomi Valkeinen 1419f76ee892STomi Valkeinen r = dsi_pll_power(dsidev, DSI_PLL_POWER_ON_ALL); 1420f76ee892STomi Valkeinen 1421f76ee892STomi Valkeinen if (r) 1422f76ee892STomi Valkeinen goto err1; 1423f76ee892STomi Valkeinen 1424f76ee892STomi Valkeinen DSSDBG("PLL init done\n"); 1425f76ee892STomi Valkeinen 1426f76ee892STomi Valkeinen return 0; 1427f76ee892STomi Valkeinen err1: 1428f76ee892STomi Valkeinen if (dsi->vdds_dsi_enabled) { 1429f76ee892STomi Valkeinen regulator_disable(dsi->vdds_dsi_reg); 1430f76ee892STomi Valkeinen dsi->vdds_dsi_enabled = false; 1431f76ee892STomi Valkeinen } 1432f76ee892STomi Valkeinen err0: 1433f76ee892STomi Valkeinen dsi_disable_scp_clk(dsidev); 1434f76ee892STomi Valkeinen dsi_runtime_put(dsidev); 1435f76ee892STomi Valkeinen return r; 1436f76ee892STomi Valkeinen } 1437f76ee892STomi Valkeinen 1438f76ee892STomi Valkeinen static void dsi_pll_uninit(struct platform_device *dsidev, bool disconnect_lanes) 1439f76ee892STomi Valkeinen { 1440f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 1441f76ee892STomi Valkeinen 1442f76ee892STomi Valkeinen dsi_pll_power(dsidev, DSI_PLL_POWER_OFF); 1443f76ee892STomi Valkeinen if (disconnect_lanes) { 1444f76ee892STomi Valkeinen WARN_ON(!dsi->vdds_dsi_enabled); 1445f76ee892STomi Valkeinen regulator_disable(dsi->vdds_dsi_reg); 1446f76ee892STomi Valkeinen dsi->vdds_dsi_enabled = false; 1447f76ee892STomi Valkeinen } 1448f76ee892STomi Valkeinen 1449f76ee892STomi Valkeinen dsi_disable_scp_clk(dsidev); 1450f76ee892STomi Valkeinen dsi_runtime_put(dsidev); 1451f76ee892STomi Valkeinen 1452f76ee892STomi Valkeinen DSSDBG("PLL uninit done\n"); 1453f76ee892STomi Valkeinen } 1454f76ee892STomi Valkeinen 1455f76ee892STomi Valkeinen static void dsi_pll_disable(struct dss_pll *pll) 1456f76ee892STomi Valkeinen { 1457f76ee892STomi Valkeinen struct dsi_data *dsi = container_of(pll, struct dsi_data, pll); 1458f76ee892STomi Valkeinen struct platform_device *dsidev = dsi->pdev; 1459f76ee892STomi Valkeinen 1460f76ee892STomi Valkeinen dsi_pll_uninit(dsidev, true); 1461f76ee892STomi Valkeinen } 1462f76ee892STomi Valkeinen 1463f76ee892STomi Valkeinen static void dsi_dump_dsidev_clocks(struct platform_device *dsidev, 1464f76ee892STomi Valkeinen struct seq_file *s) 1465f76ee892STomi Valkeinen { 1466f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 1467f76ee892STomi Valkeinen struct dss_pll_clock_info *cinfo = &dsi->pll.cinfo; 1468f76ee892STomi Valkeinen enum omap_dss_clk_source dispc_clk_src, dsi_clk_src; 1469f76ee892STomi Valkeinen int dsi_module = dsi->module_id; 1470f76ee892STomi Valkeinen struct dss_pll *pll = &dsi->pll; 1471f76ee892STomi Valkeinen 1472f76ee892STomi Valkeinen dispc_clk_src = dss_get_dispc_clk_source(); 1473f76ee892STomi Valkeinen dsi_clk_src = dss_get_dsi_clk_source(dsi_module); 1474f76ee892STomi Valkeinen 1475f76ee892STomi Valkeinen if (dsi_runtime_get(dsidev)) 1476f76ee892STomi Valkeinen return; 1477f76ee892STomi Valkeinen 1478f76ee892STomi Valkeinen seq_printf(s, "- DSI%d PLL -\n", dsi_module + 1); 1479f76ee892STomi Valkeinen 1480f76ee892STomi Valkeinen seq_printf(s, "dsi pll clkin\t%lu\n", clk_get_rate(pll->clkin)); 1481f76ee892STomi Valkeinen 1482f76ee892STomi Valkeinen seq_printf(s, "Fint\t\t%-16lun %u\n", cinfo->fint, cinfo->n); 1483f76ee892STomi Valkeinen 1484f76ee892STomi Valkeinen seq_printf(s, "CLKIN4DDR\t%-16lum %u\n", 1485f76ee892STomi Valkeinen cinfo->clkdco, cinfo->m); 1486f76ee892STomi Valkeinen 1487f76ee892STomi Valkeinen seq_printf(s, "DSI_PLL_HSDIV_DISPC (%s)\t%-16lum_dispc %u\t(%s)\n", 1488f76ee892STomi Valkeinen dss_feat_get_clk_source_name(dsi_module == 0 ? 1489f76ee892STomi Valkeinen OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC : 1490f76ee892STomi Valkeinen OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC), 1491f76ee892STomi Valkeinen cinfo->clkout[HSDIV_DISPC], 1492f76ee892STomi Valkeinen cinfo->mX[HSDIV_DISPC], 1493f76ee892STomi Valkeinen dispc_clk_src == OMAP_DSS_CLK_SRC_FCK ? 1494f76ee892STomi Valkeinen "off" : "on"); 1495f76ee892STomi Valkeinen 1496f76ee892STomi Valkeinen seq_printf(s, "DSI_PLL_HSDIV_DSI (%s)\t%-16lum_dsi %u\t(%s)\n", 1497f76ee892STomi Valkeinen dss_feat_get_clk_source_name(dsi_module == 0 ? 1498f76ee892STomi Valkeinen OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI : 1499f76ee892STomi Valkeinen OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI), 1500f76ee892STomi Valkeinen cinfo->clkout[HSDIV_DSI], 1501f76ee892STomi Valkeinen cinfo->mX[HSDIV_DSI], 1502f76ee892STomi Valkeinen dsi_clk_src == OMAP_DSS_CLK_SRC_FCK ? 1503f76ee892STomi Valkeinen "off" : "on"); 1504f76ee892STomi Valkeinen 1505f76ee892STomi Valkeinen seq_printf(s, "- DSI%d -\n", dsi_module + 1); 1506f76ee892STomi Valkeinen 1507f76ee892STomi Valkeinen seq_printf(s, "dsi fclk source = %s (%s)\n", 1508f76ee892STomi Valkeinen dss_get_generic_clk_source_name(dsi_clk_src), 1509f76ee892STomi Valkeinen dss_feat_get_clk_source_name(dsi_clk_src)); 1510f76ee892STomi Valkeinen 1511f76ee892STomi Valkeinen seq_printf(s, "DSI_FCLK\t%lu\n", dsi_fclk_rate(dsidev)); 1512f76ee892STomi Valkeinen 1513f76ee892STomi Valkeinen seq_printf(s, "DDR_CLK\t\t%lu\n", 1514f76ee892STomi Valkeinen cinfo->clkdco / 4); 1515f76ee892STomi Valkeinen 1516f76ee892STomi Valkeinen seq_printf(s, "TxByteClkHS\t%lu\n", dsi_get_txbyteclkhs(dsidev)); 1517f76ee892STomi Valkeinen 1518f76ee892STomi Valkeinen seq_printf(s, "LP_CLK\t\t%lu\n", dsi->current_lp_cinfo.lp_clk); 1519f76ee892STomi Valkeinen 1520f76ee892STomi Valkeinen dsi_runtime_put(dsidev); 1521f76ee892STomi Valkeinen } 1522f76ee892STomi Valkeinen 1523f76ee892STomi Valkeinen void dsi_dump_clocks(struct seq_file *s) 1524f76ee892STomi Valkeinen { 1525f76ee892STomi Valkeinen struct platform_device *dsidev; 1526f76ee892STomi Valkeinen int i; 1527f76ee892STomi Valkeinen 1528f76ee892STomi Valkeinen for (i = 0; i < MAX_NUM_DSI; i++) { 1529f76ee892STomi Valkeinen dsidev = dsi_get_dsidev_from_id(i); 1530f76ee892STomi Valkeinen if (dsidev) 1531f76ee892STomi Valkeinen dsi_dump_dsidev_clocks(dsidev, s); 1532f76ee892STomi Valkeinen } 1533f76ee892STomi Valkeinen } 1534f76ee892STomi Valkeinen 153535b522cfSTomi Valkeinen #ifdef CONFIG_FB_OMAP2_DSS_COLLECT_IRQ_STATS 1536f76ee892STomi Valkeinen static void dsi_dump_dsidev_irqs(struct platform_device *dsidev, 1537f76ee892STomi Valkeinen struct seq_file *s) 1538f76ee892STomi Valkeinen { 1539f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 1540f76ee892STomi Valkeinen unsigned long flags; 1541f76ee892STomi Valkeinen struct dsi_irq_stats stats; 1542f76ee892STomi Valkeinen 1543f76ee892STomi Valkeinen spin_lock_irqsave(&dsi->irq_stats_lock, flags); 1544f76ee892STomi Valkeinen 1545f76ee892STomi Valkeinen stats = dsi->irq_stats; 1546f76ee892STomi Valkeinen memset(&dsi->irq_stats, 0, sizeof(dsi->irq_stats)); 1547f76ee892STomi Valkeinen dsi->irq_stats.last_reset = jiffies; 1548f76ee892STomi Valkeinen 1549f76ee892STomi Valkeinen spin_unlock_irqrestore(&dsi->irq_stats_lock, flags); 1550f76ee892STomi Valkeinen 1551f76ee892STomi Valkeinen seq_printf(s, "period %u ms\n", 1552f76ee892STomi Valkeinen jiffies_to_msecs(jiffies - stats.last_reset)); 1553f76ee892STomi Valkeinen 1554f76ee892STomi Valkeinen seq_printf(s, "irqs %d\n", stats.irq_count); 1555f76ee892STomi Valkeinen #define PIS(x) \ 155695e22f8cSTom Rix seq_printf(s, "%-20s %10d\n", #x, stats.dsi_irqs[ffs(DSI_IRQ_##x)-1]) 1557f76ee892STomi Valkeinen 1558f76ee892STomi Valkeinen seq_printf(s, "-- DSI%d interrupts --\n", dsi->module_id + 1); 1559f76ee892STomi Valkeinen PIS(VC0); 1560f76ee892STomi Valkeinen PIS(VC1); 1561f76ee892STomi Valkeinen PIS(VC2); 1562f76ee892STomi Valkeinen PIS(VC3); 1563f76ee892STomi Valkeinen PIS(WAKEUP); 1564f76ee892STomi Valkeinen PIS(RESYNC); 1565f76ee892STomi Valkeinen PIS(PLL_LOCK); 1566f76ee892STomi Valkeinen PIS(PLL_UNLOCK); 1567f76ee892STomi Valkeinen PIS(PLL_RECALL); 1568f76ee892STomi Valkeinen PIS(COMPLEXIO_ERR); 1569f76ee892STomi Valkeinen PIS(HS_TX_TIMEOUT); 1570f76ee892STomi Valkeinen PIS(LP_RX_TIMEOUT); 1571f76ee892STomi Valkeinen PIS(TE_TRIGGER); 1572f76ee892STomi Valkeinen PIS(ACK_TRIGGER); 1573f76ee892STomi Valkeinen PIS(SYNC_LOST); 1574f76ee892STomi Valkeinen PIS(LDO_POWER_GOOD); 1575f76ee892STomi Valkeinen PIS(TA_TIMEOUT); 1576f76ee892STomi Valkeinen #undef PIS 1577f76ee892STomi Valkeinen 1578f76ee892STomi Valkeinen #define PIS(x) \ 1579f76ee892STomi Valkeinen seq_printf(s, "%-20s %10d %10d %10d %10d\n", #x, \ 1580f76ee892STomi Valkeinen stats.vc_irqs[0][ffs(DSI_VC_IRQ_##x)-1], \ 1581f76ee892STomi Valkeinen stats.vc_irqs[1][ffs(DSI_VC_IRQ_##x)-1], \ 1582f76ee892STomi Valkeinen stats.vc_irqs[2][ffs(DSI_VC_IRQ_##x)-1], \ 1583f76ee892STomi Valkeinen stats.vc_irqs[3][ffs(DSI_VC_IRQ_##x)-1]); 1584f76ee892STomi Valkeinen 1585f76ee892STomi Valkeinen seq_printf(s, "-- VC interrupts --\n"); 1586f76ee892STomi Valkeinen PIS(CS); 1587f76ee892STomi Valkeinen PIS(ECC_CORR); 1588f76ee892STomi Valkeinen PIS(PACKET_SENT); 1589f76ee892STomi Valkeinen PIS(FIFO_TX_OVF); 1590f76ee892STomi Valkeinen PIS(FIFO_RX_OVF); 1591f76ee892STomi Valkeinen PIS(BTA); 1592f76ee892STomi Valkeinen PIS(ECC_NO_CORR); 1593f76ee892STomi Valkeinen PIS(FIFO_TX_UDF); 1594f76ee892STomi Valkeinen PIS(PP_BUSY_CHANGE); 1595f76ee892STomi Valkeinen #undef PIS 1596f76ee892STomi Valkeinen 1597f76ee892STomi Valkeinen #define PIS(x) \ 1598f76ee892STomi Valkeinen seq_printf(s, "%-20s %10d\n", #x, \ 1599f76ee892STomi Valkeinen stats.cio_irqs[ffs(DSI_CIO_IRQ_##x)-1]); 1600f76ee892STomi Valkeinen 1601f76ee892STomi Valkeinen seq_printf(s, "-- CIO interrupts --\n"); 1602f76ee892STomi Valkeinen PIS(ERRSYNCESC1); 1603f76ee892STomi Valkeinen PIS(ERRSYNCESC2); 1604f76ee892STomi Valkeinen PIS(ERRSYNCESC3); 1605f76ee892STomi Valkeinen PIS(ERRESC1); 1606f76ee892STomi Valkeinen PIS(ERRESC2); 1607f76ee892STomi Valkeinen PIS(ERRESC3); 1608f76ee892STomi Valkeinen PIS(ERRCONTROL1); 1609f76ee892STomi Valkeinen PIS(ERRCONTROL2); 1610f76ee892STomi Valkeinen PIS(ERRCONTROL3); 1611f76ee892STomi Valkeinen PIS(STATEULPS1); 1612f76ee892STomi Valkeinen PIS(STATEULPS2); 1613f76ee892STomi Valkeinen PIS(STATEULPS3); 1614f76ee892STomi Valkeinen PIS(ERRCONTENTIONLP0_1); 1615f76ee892STomi Valkeinen PIS(ERRCONTENTIONLP1_1); 1616f76ee892STomi Valkeinen PIS(ERRCONTENTIONLP0_2); 1617f76ee892STomi Valkeinen PIS(ERRCONTENTIONLP1_2); 1618f76ee892STomi Valkeinen PIS(ERRCONTENTIONLP0_3); 1619f76ee892STomi Valkeinen PIS(ERRCONTENTIONLP1_3); 1620f76ee892STomi Valkeinen PIS(ULPSACTIVENOT_ALL0); 1621f76ee892STomi Valkeinen PIS(ULPSACTIVENOT_ALL1); 1622f76ee892STomi Valkeinen #undef PIS 1623f76ee892STomi Valkeinen } 1624f76ee892STomi Valkeinen 1625f76ee892STomi Valkeinen static void dsi1_dump_irqs(struct seq_file *s) 1626f76ee892STomi Valkeinen { 1627f76ee892STomi Valkeinen struct platform_device *dsidev = dsi_get_dsidev_from_id(0); 1628f76ee892STomi Valkeinen 1629f76ee892STomi Valkeinen dsi_dump_dsidev_irqs(dsidev, s); 1630f76ee892STomi Valkeinen } 1631f76ee892STomi Valkeinen 1632f76ee892STomi Valkeinen static void dsi2_dump_irqs(struct seq_file *s) 1633f76ee892STomi Valkeinen { 1634f76ee892STomi Valkeinen struct platform_device *dsidev = dsi_get_dsidev_from_id(1); 1635f76ee892STomi Valkeinen 1636f76ee892STomi Valkeinen dsi_dump_dsidev_irqs(dsidev, s); 1637f76ee892STomi Valkeinen } 1638f76ee892STomi Valkeinen #endif 1639f76ee892STomi Valkeinen 1640f76ee892STomi Valkeinen static void dsi_dump_dsidev_regs(struct platform_device *dsidev, 1641f76ee892STomi Valkeinen struct seq_file *s) 1642f76ee892STomi Valkeinen { 1643f76ee892STomi Valkeinen #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dsi_read_reg(dsidev, r)) 1644f76ee892STomi Valkeinen 1645f76ee892STomi Valkeinen if (dsi_runtime_get(dsidev)) 1646f76ee892STomi Valkeinen return; 1647f76ee892STomi Valkeinen dsi_enable_scp_clk(dsidev); 1648f76ee892STomi Valkeinen 1649f76ee892STomi Valkeinen DUMPREG(DSI_REVISION); 1650f76ee892STomi Valkeinen DUMPREG(DSI_SYSCONFIG); 1651f76ee892STomi Valkeinen DUMPREG(DSI_SYSSTATUS); 1652f76ee892STomi Valkeinen DUMPREG(DSI_IRQSTATUS); 1653f76ee892STomi Valkeinen DUMPREG(DSI_IRQENABLE); 1654f76ee892STomi Valkeinen DUMPREG(DSI_CTRL); 1655f76ee892STomi Valkeinen DUMPREG(DSI_COMPLEXIO_CFG1); 1656f76ee892STomi Valkeinen DUMPREG(DSI_COMPLEXIO_IRQ_STATUS); 1657f76ee892STomi Valkeinen DUMPREG(DSI_COMPLEXIO_IRQ_ENABLE); 1658f76ee892STomi Valkeinen DUMPREG(DSI_CLK_CTRL); 1659f76ee892STomi Valkeinen DUMPREG(DSI_TIMING1); 1660f76ee892STomi Valkeinen DUMPREG(DSI_TIMING2); 1661f76ee892STomi Valkeinen DUMPREG(DSI_VM_TIMING1); 1662f76ee892STomi Valkeinen DUMPREG(DSI_VM_TIMING2); 1663f76ee892STomi Valkeinen DUMPREG(DSI_VM_TIMING3); 1664f76ee892STomi Valkeinen DUMPREG(DSI_CLK_TIMING); 1665f76ee892STomi Valkeinen DUMPREG(DSI_TX_FIFO_VC_SIZE); 1666f76ee892STomi Valkeinen DUMPREG(DSI_RX_FIFO_VC_SIZE); 1667f76ee892STomi Valkeinen DUMPREG(DSI_COMPLEXIO_CFG2); 1668f76ee892STomi Valkeinen DUMPREG(DSI_RX_FIFO_VC_FULLNESS); 1669f76ee892STomi Valkeinen DUMPREG(DSI_VM_TIMING4); 1670f76ee892STomi Valkeinen DUMPREG(DSI_TX_FIFO_VC_EMPTINESS); 1671f76ee892STomi Valkeinen DUMPREG(DSI_VM_TIMING5); 1672f76ee892STomi Valkeinen DUMPREG(DSI_VM_TIMING6); 1673f76ee892STomi Valkeinen DUMPREG(DSI_VM_TIMING7); 1674f76ee892STomi Valkeinen DUMPREG(DSI_STOPCLK_TIMING); 1675f76ee892STomi Valkeinen 1676f76ee892STomi Valkeinen DUMPREG(DSI_VC_CTRL(0)); 1677f76ee892STomi Valkeinen DUMPREG(DSI_VC_TE(0)); 1678f76ee892STomi Valkeinen DUMPREG(DSI_VC_LONG_PACKET_HEADER(0)); 1679f76ee892STomi Valkeinen DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(0)); 1680f76ee892STomi Valkeinen DUMPREG(DSI_VC_SHORT_PACKET_HEADER(0)); 1681f76ee892STomi Valkeinen DUMPREG(DSI_VC_IRQSTATUS(0)); 1682f76ee892STomi Valkeinen DUMPREG(DSI_VC_IRQENABLE(0)); 1683f76ee892STomi Valkeinen 1684f76ee892STomi Valkeinen DUMPREG(DSI_VC_CTRL(1)); 1685f76ee892STomi Valkeinen DUMPREG(DSI_VC_TE(1)); 1686f76ee892STomi Valkeinen DUMPREG(DSI_VC_LONG_PACKET_HEADER(1)); 1687f76ee892STomi Valkeinen DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(1)); 1688f76ee892STomi Valkeinen DUMPREG(DSI_VC_SHORT_PACKET_HEADER(1)); 1689f76ee892STomi Valkeinen DUMPREG(DSI_VC_IRQSTATUS(1)); 1690f76ee892STomi Valkeinen DUMPREG(DSI_VC_IRQENABLE(1)); 1691f76ee892STomi Valkeinen 1692f76ee892STomi Valkeinen DUMPREG(DSI_VC_CTRL(2)); 1693f76ee892STomi Valkeinen DUMPREG(DSI_VC_TE(2)); 1694f76ee892STomi Valkeinen DUMPREG(DSI_VC_LONG_PACKET_HEADER(2)); 1695f76ee892STomi Valkeinen DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(2)); 1696f76ee892STomi Valkeinen DUMPREG(DSI_VC_SHORT_PACKET_HEADER(2)); 1697f76ee892STomi Valkeinen DUMPREG(DSI_VC_IRQSTATUS(2)); 1698f76ee892STomi Valkeinen DUMPREG(DSI_VC_IRQENABLE(2)); 1699f76ee892STomi Valkeinen 1700f76ee892STomi Valkeinen DUMPREG(DSI_VC_CTRL(3)); 1701f76ee892STomi Valkeinen DUMPREG(DSI_VC_TE(3)); 1702f76ee892STomi Valkeinen DUMPREG(DSI_VC_LONG_PACKET_HEADER(3)); 1703f76ee892STomi Valkeinen DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(3)); 1704f76ee892STomi Valkeinen DUMPREG(DSI_VC_SHORT_PACKET_HEADER(3)); 1705f76ee892STomi Valkeinen DUMPREG(DSI_VC_IRQSTATUS(3)); 1706f76ee892STomi Valkeinen DUMPREG(DSI_VC_IRQENABLE(3)); 1707f76ee892STomi Valkeinen 1708f76ee892STomi Valkeinen DUMPREG(DSI_DSIPHY_CFG0); 1709f76ee892STomi Valkeinen DUMPREG(DSI_DSIPHY_CFG1); 1710f76ee892STomi Valkeinen DUMPREG(DSI_DSIPHY_CFG2); 1711f76ee892STomi Valkeinen DUMPREG(DSI_DSIPHY_CFG5); 1712f76ee892STomi Valkeinen 1713f76ee892STomi Valkeinen DUMPREG(DSI_PLL_CONTROL); 1714f76ee892STomi Valkeinen DUMPREG(DSI_PLL_STATUS); 1715f76ee892STomi Valkeinen DUMPREG(DSI_PLL_GO); 1716f76ee892STomi Valkeinen DUMPREG(DSI_PLL_CONFIGURATION1); 1717f76ee892STomi Valkeinen DUMPREG(DSI_PLL_CONFIGURATION2); 1718f76ee892STomi Valkeinen 1719f76ee892STomi Valkeinen dsi_disable_scp_clk(dsidev); 1720f76ee892STomi Valkeinen dsi_runtime_put(dsidev); 1721f76ee892STomi Valkeinen #undef DUMPREG 1722f76ee892STomi Valkeinen } 1723f76ee892STomi Valkeinen 1724f76ee892STomi Valkeinen static void dsi1_dump_regs(struct seq_file *s) 1725f76ee892STomi Valkeinen { 1726f76ee892STomi Valkeinen struct platform_device *dsidev = dsi_get_dsidev_from_id(0); 1727f76ee892STomi Valkeinen 1728f76ee892STomi Valkeinen dsi_dump_dsidev_regs(dsidev, s); 1729f76ee892STomi Valkeinen } 1730f76ee892STomi Valkeinen 1731f76ee892STomi Valkeinen static void dsi2_dump_regs(struct seq_file *s) 1732f76ee892STomi Valkeinen { 1733f76ee892STomi Valkeinen struct platform_device *dsidev = dsi_get_dsidev_from_id(1); 1734f76ee892STomi Valkeinen 1735f76ee892STomi Valkeinen dsi_dump_dsidev_regs(dsidev, s); 1736f76ee892STomi Valkeinen } 1737f76ee892STomi Valkeinen 1738f76ee892STomi Valkeinen enum dsi_cio_power_state { 1739f76ee892STomi Valkeinen DSI_COMPLEXIO_POWER_OFF = 0x0, 1740f76ee892STomi Valkeinen DSI_COMPLEXIO_POWER_ON = 0x1, 1741f76ee892STomi Valkeinen DSI_COMPLEXIO_POWER_ULPS = 0x2, 1742f76ee892STomi Valkeinen }; 1743f76ee892STomi Valkeinen 1744f76ee892STomi Valkeinen static int dsi_cio_power(struct platform_device *dsidev, 1745f76ee892STomi Valkeinen enum dsi_cio_power_state state) 1746f76ee892STomi Valkeinen { 1747f76ee892STomi Valkeinen int t = 0; 1748f76ee892STomi Valkeinen 1749f76ee892STomi Valkeinen /* PWR_CMD */ 1750f76ee892STomi Valkeinen REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG1, state, 28, 27); 1751f76ee892STomi Valkeinen 1752f76ee892STomi Valkeinen /* PWR_STATUS */ 1753f76ee892STomi Valkeinen while (FLD_GET(dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1), 1754f76ee892STomi Valkeinen 26, 25) != state) { 1755f76ee892STomi Valkeinen if (++t > 1000) { 1756f76ee892STomi Valkeinen DSSERR("failed to set complexio power state to " 1757f76ee892STomi Valkeinen "%d\n", state); 1758f76ee892STomi Valkeinen return -ENODEV; 1759f76ee892STomi Valkeinen } 1760f76ee892STomi Valkeinen udelay(1); 1761f76ee892STomi Valkeinen } 1762f76ee892STomi Valkeinen 1763f76ee892STomi Valkeinen return 0; 1764f76ee892STomi Valkeinen } 1765f76ee892STomi Valkeinen 1766f76ee892STomi Valkeinen static unsigned dsi_get_line_buf_size(struct platform_device *dsidev) 1767f76ee892STomi Valkeinen { 1768f76ee892STomi Valkeinen int val; 1769f76ee892STomi Valkeinen 1770f76ee892STomi Valkeinen /* line buffer on OMAP3 is 1024 x 24bits */ 1771f76ee892STomi Valkeinen /* XXX: for some reason using full buffer size causes 1772f76ee892STomi Valkeinen * considerable TX slowdown with update sizes that fill the 1773f76ee892STomi Valkeinen * whole buffer */ 1774f76ee892STomi Valkeinen if (!dss_has_feature(FEAT_DSI_GNQ)) 1775f76ee892STomi Valkeinen return 1023 * 3; 1776f76ee892STomi Valkeinen 1777f76ee892STomi Valkeinen val = REG_GET(dsidev, DSI_GNQ, 14, 12); /* VP1_LINE_BUFFER_SIZE */ 1778f76ee892STomi Valkeinen 1779f76ee892STomi Valkeinen switch (val) { 1780f76ee892STomi Valkeinen case 1: 1781f76ee892STomi Valkeinen return 512 * 3; /* 512x24 bits */ 1782f76ee892STomi Valkeinen case 2: 1783f76ee892STomi Valkeinen return 682 * 3; /* 682x24 bits */ 1784f76ee892STomi Valkeinen case 3: 1785f76ee892STomi Valkeinen return 853 * 3; /* 853x24 bits */ 1786f76ee892STomi Valkeinen case 4: 1787f76ee892STomi Valkeinen return 1024 * 3; /* 1024x24 bits */ 1788f76ee892STomi Valkeinen case 5: 1789f76ee892STomi Valkeinen return 1194 * 3; /* 1194x24 bits */ 1790f76ee892STomi Valkeinen case 6: 1791f76ee892STomi Valkeinen return 1365 * 3; /* 1365x24 bits */ 1792f76ee892STomi Valkeinen case 7: 1793f76ee892STomi Valkeinen return 1920 * 3; /* 1920x24 bits */ 1794f76ee892STomi Valkeinen default: 1795f76ee892STomi Valkeinen BUG(); 1796f76ee892STomi Valkeinen return 0; 1797f76ee892STomi Valkeinen } 1798f76ee892STomi Valkeinen } 1799f76ee892STomi Valkeinen 1800f76ee892STomi Valkeinen static int dsi_set_lane_config(struct platform_device *dsidev) 1801f76ee892STomi Valkeinen { 1802f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 1803f76ee892STomi Valkeinen static const u8 offsets[] = { 0, 4, 8, 12, 16 }; 1804f76ee892STomi Valkeinen static const enum dsi_lane_function functions[] = { 1805f76ee892STomi Valkeinen DSI_LANE_CLK, 1806f76ee892STomi Valkeinen DSI_LANE_DATA1, 1807f76ee892STomi Valkeinen DSI_LANE_DATA2, 1808f76ee892STomi Valkeinen DSI_LANE_DATA3, 1809f76ee892STomi Valkeinen DSI_LANE_DATA4, 1810f76ee892STomi Valkeinen }; 1811f76ee892STomi Valkeinen u32 r; 1812f76ee892STomi Valkeinen int i; 1813f76ee892STomi Valkeinen 1814f76ee892STomi Valkeinen r = dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1); 1815f76ee892STomi Valkeinen 1816f76ee892STomi Valkeinen for (i = 0; i < dsi->num_lanes_used; ++i) { 1817f76ee892STomi Valkeinen unsigned offset = offsets[i]; 1818f76ee892STomi Valkeinen unsigned polarity, lane_number; 1819f76ee892STomi Valkeinen unsigned t; 1820f76ee892STomi Valkeinen 1821f76ee892STomi Valkeinen for (t = 0; t < dsi->num_lanes_supported; ++t) 1822f76ee892STomi Valkeinen if (dsi->lanes[t].function == functions[i]) 1823f76ee892STomi Valkeinen break; 1824f76ee892STomi Valkeinen 1825f76ee892STomi Valkeinen if (t == dsi->num_lanes_supported) 1826f76ee892STomi Valkeinen return -EINVAL; 1827f76ee892STomi Valkeinen 1828f76ee892STomi Valkeinen lane_number = t; 1829f76ee892STomi Valkeinen polarity = dsi->lanes[t].polarity; 1830f76ee892STomi Valkeinen 1831f76ee892STomi Valkeinen r = FLD_MOD(r, lane_number + 1, offset + 2, offset); 1832f76ee892STomi Valkeinen r = FLD_MOD(r, polarity, offset + 3, offset + 3); 1833f76ee892STomi Valkeinen } 1834f76ee892STomi Valkeinen 1835f76ee892STomi Valkeinen /* clear the unused lanes */ 1836f76ee892STomi Valkeinen for (; i < dsi->num_lanes_supported; ++i) { 1837f76ee892STomi Valkeinen unsigned offset = offsets[i]; 1838f76ee892STomi Valkeinen 1839f76ee892STomi Valkeinen r = FLD_MOD(r, 0, offset + 2, offset); 1840f76ee892STomi Valkeinen r = FLD_MOD(r, 0, offset + 3, offset + 3); 1841f76ee892STomi Valkeinen } 1842f76ee892STomi Valkeinen 1843f76ee892STomi Valkeinen dsi_write_reg(dsidev, DSI_COMPLEXIO_CFG1, r); 1844f76ee892STomi Valkeinen 1845f76ee892STomi Valkeinen return 0; 1846f76ee892STomi Valkeinen } 1847f76ee892STomi Valkeinen 1848f76ee892STomi Valkeinen static inline unsigned ns2ddr(struct platform_device *dsidev, unsigned ns) 1849f76ee892STomi Valkeinen { 1850f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 1851f76ee892STomi Valkeinen 1852f76ee892STomi Valkeinen /* convert time in ns to ddr ticks, rounding up */ 1853f76ee892STomi Valkeinen unsigned long ddr_clk = dsi->pll.cinfo.clkdco / 4; 1854f76ee892STomi Valkeinen return (ns * (ddr_clk / 1000 / 1000) + 999) / 1000; 1855f76ee892STomi Valkeinen } 1856f76ee892STomi Valkeinen 1857f76ee892STomi Valkeinen static inline unsigned ddr2ns(struct platform_device *dsidev, unsigned ddr) 1858f76ee892STomi Valkeinen { 1859f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 1860f76ee892STomi Valkeinen 1861f76ee892STomi Valkeinen unsigned long ddr_clk = dsi->pll.cinfo.clkdco / 4; 1862f76ee892STomi Valkeinen return ddr * 1000 * 1000 / (ddr_clk / 1000); 1863f76ee892STomi Valkeinen } 1864f76ee892STomi Valkeinen 1865f76ee892STomi Valkeinen static void dsi_cio_timings(struct platform_device *dsidev) 1866f76ee892STomi Valkeinen { 1867f76ee892STomi Valkeinen u32 r; 1868f76ee892STomi Valkeinen u32 ths_prepare, ths_prepare_ths_zero, ths_trail, ths_exit; 1869f76ee892STomi Valkeinen u32 tlpx_half, tclk_trail, tclk_zero; 1870f76ee892STomi Valkeinen u32 tclk_prepare; 1871f76ee892STomi Valkeinen 1872f76ee892STomi Valkeinen /* calculate timings */ 1873f76ee892STomi Valkeinen 1874f76ee892STomi Valkeinen /* 1 * DDR_CLK = 2 * UI */ 1875f76ee892STomi Valkeinen 1876f76ee892STomi Valkeinen /* min 40ns + 4*UI max 85ns + 6*UI */ 1877f76ee892STomi Valkeinen ths_prepare = ns2ddr(dsidev, 70) + 2; 1878f76ee892STomi Valkeinen 1879f76ee892STomi Valkeinen /* min 145ns + 10*UI */ 1880f76ee892STomi Valkeinen ths_prepare_ths_zero = ns2ddr(dsidev, 175) + 2; 1881f76ee892STomi Valkeinen 1882f76ee892STomi Valkeinen /* min max(8*UI, 60ns+4*UI) */ 1883f76ee892STomi Valkeinen ths_trail = ns2ddr(dsidev, 60) + 5; 1884f76ee892STomi Valkeinen 1885f76ee892STomi Valkeinen /* min 100ns */ 1886f76ee892STomi Valkeinen ths_exit = ns2ddr(dsidev, 145); 1887f76ee892STomi Valkeinen 1888f76ee892STomi Valkeinen /* tlpx min 50n */ 1889f76ee892STomi Valkeinen tlpx_half = ns2ddr(dsidev, 25); 1890f76ee892STomi Valkeinen 1891f76ee892STomi Valkeinen /* min 60ns */ 1892f76ee892STomi Valkeinen tclk_trail = ns2ddr(dsidev, 60) + 2; 1893f76ee892STomi Valkeinen 1894f76ee892STomi Valkeinen /* min 38ns, max 95ns */ 1895f76ee892STomi Valkeinen tclk_prepare = ns2ddr(dsidev, 65); 1896f76ee892STomi Valkeinen 1897f76ee892STomi Valkeinen /* min tclk-prepare + tclk-zero = 300ns */ 1898f76ee892STomi Valkeinen tclk_zero = ns2ddr(dsidev, 260); 1899f76ee892STomi Valkeinen 1900f76ee892STomi Valkeinen DSSDBG("ths_prepare %u (%uns), ths_prepare_ths_zero %u (%uns)\n", 1901f76ee892STomi Valkeinen ths_prepare, ddr2ns(dsidev, ths_prepare), 1902f76ee892STomi Valkeinen ths_prepare_ths_zero, ddr2ns(dsidev, ths_prepare_ths_zero)); 1903f76ee892STomi Valkeinen DSSDBG("ths_trail %u (%uns), ths_exit %u (%uns)\n", 1904f76ee892STomi Valkeinen ths_trail, ddr2ns(dsidev, ths_trail), 1905f76ee892STomi Valkeinen ths_exit, ddr2ns(dsidev, ths_exit)); 1906f76ee892STomi Valkeinen 1907f76ee892STomi Valkeinen DSSDBG("tlpx_half %u (%uns), tclk_trail %u (%uns), " 1908f76ee892STomi Valkeinen "tclk_zero %u (%uns)\n", 1909f76ee892STomi Valkeinen tlpx_half, ddr2ns(dsidev, tlpx_half), 1910f76ee892STomi Valkeinen tclk_trail, ddr2ns(dsidev, tclk_trail), 1911f76ee892STomi Valkeinen tclk_zero, ddr2ns(dsidev, tclk_zero)); 1912f76ee892STomi Valkeinen DSSDBG("tclk_prepare %u (%uns)\n", 1913f76ee892STomi Valkeinen tclk_prepare, ddr2ns(dsidev, tclk_prepare)); 1914f76ee892STomi Valkeinen 1915f76ee892STomi Valkeinen /* program timings */ 1916f76ee892STomi Valkeinen 1917f76ee892STomi Valkeinen r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0); 1918f76ee892STomi Valkeinen r = FLD_MOD(r, ths_prepare, 31, 24); 1919f76ee892STomi Valkeinen r = FLD_MOD(r, ths_prepare_ths_zero, 23, 16); 1920f76ee892STomi Valkeinen r = FLD_MOD(r, ths_trail, 15, 8); 1921f76ee892STomi Valkeinen r = FLD_MOD(r, ths_exit, 7, 0); 1922f76ee892STomi Valkeinen dsi_write_reg(dsidev, DSI_DSIPHY_CFG0, r); 1923f76ee892STomi Valkeinen 1924f76ee892STomi Valkeinen r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1); 1925f76ee892STomi Valkeinen r = FLD_MOD(r, tlpx_half, 20, 16); 1926f76ee892STomi Valkeinen r = FLD_MOD(r, tclk_trail, 15, 8); 1927f76ee892STomi Valkeinen r = FLD_MOD(r, tclk_zero, 7, 0); 1928f76ee892STomi Valkeinen 1929f76ee892STomi Valkeinen if (dss_has_feature(FEAT_DSI_PHY_DCC)) { 1930f76ee892STomi Valkeinen r = FLD_MOD(r, 0, 21, 21); /* DCCEN = disable */ 1931f76ee892STomi Valkeinen r = FLD_MOD(r, 1, 22, 22); /* CLKINP_DIVBY2EN = enable */ 1932f76ee892STomi Valkeinen r = FLD_MOD(r, 1, 23, 23); /* CLKINP_SEL = enable */ 1933f76ee892STomi Valkeinen } 1934f76ee892STomi Valkeinen 1935f76ee892STomi Valkeinen dsi_write_reg(dsidev, DSI_DSIPHY_CFG1, r); 1936f76ee892STomi Valkeinen 1937f76ee892STomi Valkeinen r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG2); 1938f76ee892STomi Valkeinen r = FLD_MOD(r, tclk_prepare, 7, 0); 1939f76ee892STomi Valkeinen dsi_write_reg(dsidev, DSI_DSIPHY_CFG2, r); 1940f76ee892STomi Valkeinen } 1941f76ee892STomi Valkeinen 1942f76ee892STomi Valkeinen /* lane masks have lane 0 at lsb. mask_p for positive lines, n for negative */ 1943f76ee892STomi Valkeinen static void dsi_cio_enable_lane_override(struct platform_device *dsidev, 1944f76ee892STomi Valkeinen unsigned mask_p, unsigned mask_n) 1945f76ee892STomi Valkeinen { 1946f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 1947f76ee892STomi Valkeinen int i; 1948f76ee892STomi Valkeinen u32 l; 1949f76ee892STomi Valkeinen u8 lptxscp_start = dsi->num_lanes_supported == 3 ? 22 : 26; 1950f76ee892STomi Valkeinen 1951f76ee892STomi Valkeinen l = 0; 1952f76ee892STomi Valkeinen 1953f76ee892STomi Valkeinen for (i = 0; i < dsi->num_lanes_supported; ++i) { 1954f76ee892STomi Valkeinen unsigned p = dsi->lanes[i].polarity; 1955f76ee892STomi Valkeinen 1956f76ee892STomi Valkeinen if (mask_p & (1 << i)) 1957f76ee892STomi Valkeinen l |= 1 << (i * 2 + (p ? 0 : 1)); 1958f76ee892STomi Valkeinen 1959f76ee892STomi Valkeinen if (mask_n & (1 << i)) 1960f76ee892STomi Valkeinen l |= 1 << (i * 2 + (p ? 1 : 0)); 1961f76ee892STomi Valkeinen } 1962f76ee892STomi Valkeinen 1963f76ee892STomi Valkeinen /* 1964f76ee892STomi Valkeinen * Bits in REGLPTXSCPDAT4TO0DXDY: 1965f76ee892STomi Valkeinen * 17: DY0 18: DX0 1966f76ee892STomi Valkeinen * 19: DY1 20: DX1 1967f76ee892STomi Valkeinen * 21: DY2 22: DX2 1968f76ee892STomi Valkeinen * 23: DY3 24: DX3 1969f76ee892STomi Valkeinen * 25: DY4 26: DX4 1970f76ee892STomi Valkeinen */ 1971f76ee892STomi Valkeinen 1972f76ee892STomi Valkeinen /* Set the lane override configuration */ 1973f76ee892STomi Valkeinen 1974f76ee892STomi Valkeinen /* REGLPTXSCPDAT4TO0DXDY */ 1975f76ee892STomi Valkeinen REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, l, lptxscp_start, 17); 1976f76ee892STomi Valkeinen 1977f76ee892STomi Valkeinen /* Enable lane override */ 1978f76ee892STomi Valkeinen 1979f76ee892STomi Valkeinen /* ENLPTXSCPDAT */ 1980f76ee892STomi Valkeinen REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 1, 27, 27); 1981f76ee892STomi Valkeinen } 1982f76ee892STomi Valkeinen 1983f76ee892STomi Valkeinen static void dsi_cio_disable_lane_override(struct platform_device *dsidev) 1984f76ee892STomi Valkeinen { 1985f76ee892STomi Valkeinen /* Disable lane override */ 1986f76ee892STomi Valkeinen REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 0, 27, 27); /* ENLPTXSCPDAT */ 1987f76ee892STomi Valkeinen /* Reset the lane override configuration */ 1988f76ee892STomi Valkeinen /* REGLPTXSCPDAT4TO0DXDY */ 1989f76ee892STomi Valkeinen REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 0, 22, 17); 1990f76ee892STomi Valkeinen } 1991f76ee892STomi Valkeinen 1992f76ee892STomi Valkeinen static int dsi_cio_wait_tx_clk_esc_reset(struct platform_device *dsidev) 1993f76ee892STomi Valkeinen { 1994f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 1995f76ee892STomi Valkeinen int t, i; 1996f76ee892STomi Valkeinen bool in_use[DSI_MAX_NR_LANES]; 1997f76ee892STomi Valkeinen static const u8 offsets_old[] = { 28, 27, 26 }; 1998f76ee892STomi Valkeinen static const u8 offsets_new[] = { 24, 25, 26, 27, 28 }; 1999f76ee892STomi Valkeinen const u8 *offsets; 2000f76ee892STomi Valkeinen 2001f76ee892STomi Valkeinen if (dss_has_feature(FEAT_DSI_REVERSE_TXCLKESC)) 2002f76ee892STomi Valkeinen offsets = offsets_old; 2003f76ee892STomi Valkeinen else 2004f76ee892STomi Valkeinen offsets = offsets_new; 2005f76ee892STomi Valkeinen 2006f76ee892STomi Valkeinen for (i = 0; i < dsi->num_lanes_supported; ++i) 2007f76ee892STomi Valkeinen in_use[i] = dsi->lanes[i].function != DSI_LANE_UNUSED; 2008f76ee892STomi Valkeinen 2009f76ee892STomi Valkeinen t = 100000; 2010f76ee892STomi Valkeinen while (true) { 2011f76ee892STomi Valkeinen u32 l; 2012f76ee892STomi Valkeinen int ok; 2013f76ee892STomi Valkeinen 2014f76ee892STomi Valkeinen l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5); 2015f76ee892STomi Valkeinen 2016f76ee892STomi Valkeinen ok = 0; 2017f76ee892STomi Valkeinen for (i = 0; i < dsi->num_lanes_supported; ++i) { 2018f76ee892STomi Valkeinen if (!in_use[i] || (l & (1 << offsets[i]))) 2019f76ee892STomi Valkeinen ok++; 2020f76ee892STomi Valkeinen } 2021f76ee892STomi Valkeinen 2022f76ee892STomi Valkeinen if (ok == dsi->num_lanes_supported) 2023f76ee892STomi Valkeinen break; 2024f76ee892STomi Valkeinen 2025f76ee892STomi Valkeinen if (--t == 0) { 2026f76ee892STomi Valkeinen for (i = 0; i < dsi->num_lanes_supported; ++i) { 2027f76ee892STomi Valkeinen if (!in_use[i] || (l & (1 << offsets[i]))) 2028f76ee892STomi Valkeinen continue; 2029f76ee892STomi Valkeinen 2030f76ee892STomi Valkeinen DSSERR("CIO TXCLKESC%d domain not coming " \ 2031f76ee892STomi Valkeinen "out of reset\n", i); 2032f76ee892STomi Valkeinen } 2033f76ee892STomi Valkeinen return -EIO; 2034f76ee892STomi Valkeinen } 2035f76ee892STomi Valkeinen } 2036f76ee892STomi Valkeinen 2037f76ee892STomi Valkeinen return 0; 2038f76ee892STomi Valkeinen } 2039f76ee892STomi Valkeinen 2040f76ee892STomi Valkeinen /* return bitmask of enabled lanes, lane0 being the lsb */ 2041f76ee892STomi Valkeinen static unsigned dsi_get_lane_mask(struct platform_device *dsidev) 2042f76ee892STomi Valkeinen { 2043f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 2044f76ee892STomi Valkeinen unsigned mask = 0; 2045f76ee892STomi Valkeinen int i; 2046f76ee892STomi Valkeinen 2047f76ee892STomi Valkeinen for (i = 0; i < dsi->num_lanes_supported; ++i) { 2048f76ee892STomi Valkeinen if (dsi->lanes[i].function != DSI_LANE_UNUSED) 2049f76ee892STomi Valkeinen mask |= 1 << i; 2050f76ee892STomi Valkeinen } 2051f76ee892STomi Valkeinen 2052f76ee892STomi Valkeinen return mask; 2053f76ee892STomi Valkeinen } 2054f76ee892STomi Valkeinen 2055f76ee892STomi Valkeinen static int dsi_cio_init(struct platform_device *dsidev) 2056f76ee892STomi Valkeinen { 2057f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 2058f76ee892STomi Valkeinen int r; 2059f76ee892STomi Valkeinen u32 l; 2060f76ee892STomi Valkeinen 2061f76ee892STomi Valkeinen DSSDBG("DSI CIO init starts"); 2062f76ee892STomi Valkeinen 2063f76ee892STomi Valkeinen r = dss_dsi_enable_pads(dsi->module_id, dsi_get_lane_mask(dsidev)); 2064f76ee892STomi Valkeinen if (r) 2065f76ee892STomi Valkeinen return r; 2066f76ee892STomi Valkeinen 2067f76ee892STomi Valkeinen dsi_enable_scp_clk(dsidev); 2068f76ee892STomi Valkeinen 2069f76ee892STomi Valkeinen /* A dummy read using the SCP interface to any DSIPHY register is 2070f76ee892STomi Valkeinen * required after DSIPHY reset to complete the reset of the DSI complex 2071f76ee892STomi Valkeinen * I/O. */ 2072f76ee892STomi Valkeinen dsi_read_reg(dsidev, DSI_DSIPHY_CFG5); 2073f76ee892STomi Valkeinen 2074f76ee892STomi Valkeinen if (wait_for_bit_change(dsidev, DSI_DSIPHY_CFG5, 30, 1) != 1) { 2075f76ee892STomi Valkeinen DSSERR("CIO SCP Clock domain not coming out of reset.\n"); 2076f76ee892STomi Valkeinen r = -EIO; 2077f76ee892STomi Valkeinen goto err_scp_clk_dom; 2078f76ee892STomi Valkeinen } 2079f76ee892STomi Valkeinen 2080f76ee892STomi Valkeinen r = dsi_set_lane_config(dsidev); 2081f76ee892STomi Valkeinen if (r) 2082f76ee892STomi Valkeinen goto err_scp_clk_dom; 2083f76ee892STomi Valkeinen 2084f76ee892STomi Valkeinen /* set TX STOP MODE timer to maximum for this operation */ 2085f76ee892STomi Valkeinen l = dsi_read_reg(dsidev, DSI_TIMING1); 2086f76ee892STomi Valkeinen l = FLD_MOD(l, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */ 2087f76ee892STomi Valkeinen l = FLD_MOD(l, 1, 14, 14); /* STOP_STATE_X16_IO */ 2088f76ee892STomi Valkeinen l = FLD_MOD(l, 1, 13, 13); /* STOP_STATE_X4_IO */ 2089f76ee892STomi Valkeinen l = FLD_MOD(l, 0x1fff, 12, 0); /* STOP_STATE_COUNTER_IO */ 2090f76ee892STomi Valkeinen dsi_write_reg(dsidev, DSI_TIMING1, l); 2091f76ee892STomi Valkeinen 2092f76ee892STomi Valkeinen if (dsi->ulps_enabled) { 2093f76ee892STomi Valkeinen unsigned mask_p; 2094f76ee892STomi Valkeinen int i; 2095f76ee892STomi Valkeinen 2096f76ee892STomi Valkeinen DSSDBG("manual ulps exit\n"); 2097f76ee892STomi Valkeinen 2098f76ee892STomi Valkeinen /* ULPS is exited by Mark-1 state for 1ms, followed by 2099f76ee892STomi Valkeinen * stop state. DSS HW cannot do this via the normal 2100f76ee892STomi Valkeinen * ULPS exit sequence, as after reset the DSS HW thinks 2101f76ee892STomi Valkeinen * that we are not in ULPS mode, and refuses to send the 2102f76ee892STomi Valkeinen * sequence. So we need to send the ULPS exit sequence 2103f76ee892STomi Valkeinen * manually by setting positive lines high and negative lines 2104f76ee892STomi Valkeinen * low for 1ms. 2105f76ee892STomi Valkeinen */ 2106f76ee892STomi Valkeinen 2107f76ee892STomi Valkeinen mask_p = 0; 2108f76ee892STomi Valkeinen 2109f76ee892STomi Valkeinen for (i = 0; i < dsi->num_lanes_supported; ++i) { 2110f76ee892STomi Valkeinen if (dsi->lanes[i].function == DSI_LANE_UNUSED) 2111f76ee892STomi Valkeinen continue; 2112f76ee892STomi Valkeinen mask_p |= 1 << i; 2113f76ee892STomi Valkeinen } 2114f76ee892STomi Valkeinen 2115f76ee892STomi Valkeinen dsi_cio_enable_lane_override(dsidev, mask_p, 0); 2116f76ee892STomi Valkeinen } 2117f76ee892STomi Valkeinen 2118f76ee892STomi Valkeinen r = dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_ON); 2119f76ee892STomi Valkeinen if (r) 2120f76ee892STomi Valkeinen goto err_cio_pwr; 2121f76ee892STomi Valkeinen 2122f76ee892STomi Valkeinen if (wait_for_bit_change(dsidev, DSI_COMPLEXIO_CFG1, 29, 1) != 1) { 2123f76ee892STomi Valkeinen DSSERR("CIO PWR clock domain not coming out of reset.\n"); 2124f76ee892STomi Valkeinen r = -ENODEV; 2125f76ee892STomi Valkeinen goto err_cio_pwr_dom; 2126f76ee892STomi Valkeinen } 2127f76ee892STomi Valkeinen 2128f76ee892STomi Valkeinen dsi_if_enable(dsidev, true); 2129f76ee892STomi Valkeinen dsi_if_enable(dsidev, false); 2130f76ee892STomi Valkeinen REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 20, 20); /* LP_CLK_ENABLE */ 2131f76ee892STomi Valkeinen 2132f76ee892STomi Valkeinen r = dsi_cio_wait_tx_clk_esc_reset(dsidev); 2133f76ee892STomi Valkeinen if (r) 2134f76ee892STomi Valkeinen goto err_tx_clk_esc_rst; 2135f76ee892STomi Valkeinen 2136f76ee892STomi Valkeinen if (dsi->ulps_enabled) { 2137f76ee892STomi Valkeinen /* Keep Mark-1 state for 1ms (as per DSI spec) */ 2138f76ee892STomi Valkeinen ktime_t wait = ns_to_ktime(1000 * 1000); 2139f76ee892STomi Valkeinen set_current_state(TASK_UNINTERRUPTIBLE); 2140f76ee892STomi Valkeinen schedule_hrtimeout(&wait, HRTIMER_MODE_REL); 2141f76ee892STomi Valkeinen 2142f76ee892STomi Valkeinen /* Disable the override. The lanes should be set to Mark-11 2143f76ee892STomi Valkeinen * state by the HW */ 2144f76ee892STomi Valkeinen dsi_cio_disable_lane_override(dsidev); 2145f76ee892STomi Valkeinen } 2146f76ee892STomi Valkeinen 2147f76ee892STomi Valkeinen /* FORCE_TX_STOP_MODE_IO */ 2148f76ee892STomi Valkeinen REG_FLD_MOD(dsidev, DSI_TIMING1, 0, 15, 15); 2149f76ee892STomi Valkeinen 2150f76ee892STomi Valkeinen dsi_cio_timings(dsidev); 2151f76ee892STomi Valkeinen 2152f76ee892STomi Valkeinen if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) { 2153f76ee892STomi Valkeinen /* DDR_CLK_ALWAYS_ON */ 2154f76ee892STomi Valkeinen REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 2155f76ee892STomi Valkeinen dsi->vm_timings.ddr_clk_always_on, 13, 13); 2156f76ee892STomi Valkeinen } 2157f76ee892STomi Valkeinen 2158f76ee892STomi Valkeinen dsi->ulps_enabled = false; 2159f76ee892STomi Valkeinen 2160f76ee892STomi Valkeinen DSSDBG("CIO init done\n"); 2161f76ee892STomi Valkeinen 2162f76ee892STomi Valkeinen return 0; 2163f76ee892STomi Valkeinen 2164f76ee892STomi Valkeinen err_tx_clk_esc_rst: 2165f76ee892STomi Valkeinen REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 20, 20); /* LP_CLK_ENABLE */ 2166f76ee892STomi Valkeinen err_cio_pwr_dom: 2167f76ee892STomi Valkeinen dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF); 2168f76ee892STomi Valkeinen err_cio_pwr: 2169f76ee892STomi Valkeinen if (dsi->ulps_enabled) 2170f76ee892STomi Valkeinen dsi_cio_disable_lane_override(dsidev); 2171f76ee892STomi Valkeinen err_scp_clk_dom: 2172f76ee892STomi Valkeinen dsi_disable_scp_clk(dsidev); 2173f76ee892STomi Valkeinen dss_dsi_disable_pads(dsi->module_id, dsi_get_lane_mask(dsidev)); 2174f76ee892STomi Valkeinen return r; 2175f76ee892STomi Valkeinen } 2176f76ee892STomi Valkeinen 2177f76ee892STomi Valkeinen static void dsi_cio_uninit(struct platform_device *dsidev) 2178f76ee892STomi Valkeinen { 2179f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 2180f76ee892STomi Valkeinen 2181f76ee892STomi Valkeinen /* DDR_CLK_ALWAYS_ON */ 2182f76ee892STomi Valkeinen REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 13, 13); 2183f76ee892STomi Valkeinen 2184f76ee892STomi Valkeinen dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF); 2185f76ee892STomi Valkeinen dsi_disable_scp_clk(dsidev); 2186f76ee892STomi Valkeinen dss_dsi_disable_pads(dsi->module_id, dsi_get_lane_mask(dsidev)); 2187f76ee892STomi Valkeinen } 2188f76ee892STomi Valkeinen 2189f76ee892STomi Valkeinen static void dsi_config_tx_fifo(struct platform_device *dsidev, 2190f76ee892STomi Valkeinen enum fifo_size size1, enum fifo_size size2, 2191f76ee892STomi Valkeinen enum fifo_size size3, enum fifo_size size4) 2192f76ee892STomi Valkeinen { 2193f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 2194f76ee892STomi Valkeinen u32 r = 0; 2195f76ee892STomi Valkeinen int add = 0; 2196f76ee892STomi Valkeinen int i; 2197f76ee892STomi Valkeinen 2198f76ee892STomi Valkeinen dsi->vc[0].tx_fifo_size = size1; 2199f76ee892STomi Valkeinen dsi->vc[1].tx_fifo_size = size2; 2200f76ee892STomi Valkeinen dsi->vc[2].tx_fifo_size = size3; 2201f76ee892STomi Valkeinen dsi->vc[3].tx_fifo_size = size4; 2202f76ee892STomi Valkeinen 2203f76ee892STomi Valkeinen for (i = 0; i < 4; i++) { 2204f76ee892STomi Valkeinen u8 v; 2205f76ee892STomi Valkeinen int size = dsi->vc[i].tx_fifo_size; 2206f76ee892STomi Valkeinen 2207f76ee892STomi Valkeinen if (add + size > 4) { 2208f76ee892STomi Valkeinen DSSERR("Illegal FIFO configuration\n"); 2209f76ee892STomi Valkeinen BUG(); 2210f76ee892STomi Valkeinen return; 2211f76ee892STomi Valkeinen } 2212f76ee892STomi Valkeinen 2213f76ee892STomi Valkeinen v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4); 2214f76ee892STomi Valkeinen r |= v << (8 * i); 2215f76ee892STomi Valkeinen /*DSSDBG("TX FIFO vc %d: size %d, add %d\n", i, size, add); */ 2216f76ee892STomi Valkeinen add += size; 2217f76ee892STomi Valkeinen } 2218f76ee892STomi Valkeinen 2219f76ee892STomi Valkeinen dsi_write_reg(dsidev, DSI_TX_FIFO_VC_SIZE, r); 2220f76ee892STomi Valkeinen } 2221f76ee892STomi Valkeinen 2222f76ee892STomi Valkeinen static void dsi_config_rx_fifo(struct platform_device *dsidev, 2223f76ee892STomi Valkeinen enum fifo_size size1, enum fifo_size size2, 2224f76ee892STomi Valkeinen enum fifo_size size3, enum fifo_size size4) 2225f76ee892STomi Valkeinen { 2226f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 2227f76ee892STomi Valkeinen u32 r = 0; 2228f76ee892STomi Valkeinen int add = 0; 2229f76ee892STomi Valkeinen int i; 2230f76ee892STomi Valkeinen 2231f76ee892STomi Valkeinen dsi->vc[0].rx_fifo_size = size1; 2232f76ee892STomi Valkeinen dsi->vc[1].rx_fifo_size = size2; 2233f76ee892STomi Valkeinen dsi->vc[2].rx_fifo_size = size3; 2234f76ee892STomi Valkeinen dsi->vc[3].rx_fifo_size = size4; 2235f76ee892STomi Valkeinen 2236f76ee892STomi Valkeinen for (i = 0; i < 4; i++) { 2237f76ee892STomi Valkeinen u8 v; 2238f76ee892STomi Valkeinen int size = dsi->vc[i].rx_fifo_size; 2239f76ee892STomi Valkeinen 2240f76ee892STomi Valkeinen if (add + size > 4) { 2241f76ee892STomi Valkeinen DSSERR("Illegal FIFO configuration\n"); 2242f76ee892STomi Valkeinen BUG(); 2243f76ee892STomi Valkeinen return; 2244f76ee892STomi Valkeinen } 2245f76ee892STomi Valkeinen 2246f76ee892STomi Valkeinen v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4); 2247f76ee892STomi Valkeinen r |= v << (8 * i); 2248f76ee892STomi Valkeinen /*DSSDBG("RX FIFO vc %d: size %d, add %d\n", i, size, add); */ 2249f76ee892STomi Valkeinen add += size; 2250f76ee892STomi Valkeinen } 2251f76ee892STomi Valkeinen 2252f76ee892STomi Valkeinen dsi_write_reg(dsidev, DSI_RX_FIFO_VC_SIZE, r); 2253f76ee892STomi Valkeinen } 2254f76ee892STomi Valkeinen 2255f76ee892STomi Valkeinen static int dsi_force_tx_stop_mode_io(struct platform_device *dsidev) 2256f76ee892STomi Valkeinen { 2257f76ee892STomi Valkeinen u32 r; 2258f76ee892STomi Valkeinen 2259f76ee892STomi Valkeinen r = dsi_read_reg(dsidev, DSI_TIMING1); 2260f76ee892STomi Valkeinen r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */ 2261f76ee892STomi Valkeinen dsi_write_reg(dsidev, DSI_TIMING1, r); 2262f76ee892STomi Valkeinen 2263f76ee892STomi Valkeinen if (wait_for_bit_change(dsidev, DSI_TIMING1, 15, 0) != 0) { 2264f76ee892STomi Valkeinen DSSERR("TX_STOP bit not going down\n"); 2265f76ee892STomi Valkeinen return -EIO; 2266f76ee892STomi Valkeinen } 2267f76ee892STomi Valkeinen 2268f76ee892STomi Valkeinen return 0; 2269f76ee892STomi Valkeinen } 2270f76ee892STomi Valkeinen 2271f76ee892STomi Valkeinen static bool dsi_vc_is_enabled(struct platform_device *dsidev, int channel) 2272f76ee892STomi Valkeinen { 2273f76ee892STomi Valkeinen return REG_GET(dsidev, DSI_VC_CTRL(channel), 0, 0); 2274f76ee892STomi Valkeinen } 2275f76ee892STomi Valkeinen 2276f76ee892STomi Valkeinen static void dsi_packet_sent_handler_vp(void *data, u32 mask) 2277f76ee892STomi Valkeinen { 2278f76ee892STomi Valkeinen struct dsi_packet_sent_handler_data *vp_data = 2279f76ee892STomi Valkeinen (struct dsi_packet_sent_handler_data *) data; 2280f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(vp_data->dsidev); 2281f76ee892STomi Valkeinen const int channel = dsi->update_channel; 2282f76ee892STomi Valkeinen u8 bit = dsi->te_enabled ? 30 : 31; 2283f76ee892STomi Valkeinen 2284f76ee892STomi Valkeinen if (REG_GET(vp_data->dsidev, DSI_VC_TE(channel), bit, bit) == 0) 2285f76ee892STomi Valkeinen complete(vp_data->completion); 2286f76ee892STomi Valkeinen } 2287f76ee892STomi Valkeinen 2288f76ee892STomi Valkeinen static int dsi_sync_vc_vp(struct platform_device *dsidev, int channel) 2289f76ee892STomi Valkeinen { 2290f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 2291f76ee892STomi Valkeinen DECLARE_COMPLETION_ONSTACK(completion); 2292f76ee892STomi Valkeinen struct dsi_packet_sent_handler_data vp_data = { 2293f76ee892STomi Valkeinen .dsidev = dsidev, 2294f76ee892STomi Valkeinen .completion = &completion 2295f76ee892STomi Valkeinen }; 2296f76ee892STomi Valkeinen int r = 0; 2297f76ee892STomi Valkeinen u8 bit; 2298f76ee892STomi Valkeinen 2299f76ee892STomi Valkeinen bit = dsi->te_enabled ? 30 : 31; 2300f76ee892STomi Valkeinen 2301f76ee892STomi Valkeinen r = dsi_register_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp, 2302f76ee892STomi Valkeinen &vp_data, DSI_VC_IRQ_PACKET_SENT); 2303f76ee892STomi Valkeinen if (r) 2304f76ee892STomi Valkeinen goto err0; 2305f76ee892STomi Valkeinen 2306f76ee892STomi Valkeinen /* Wait for completion only if TE_EN/TE_START is still set */ 2307f76ee892STomi Valkeinen if (REG_GET(dsidev, DSI_VC_TE(channel), bit, bit)) { 2308f76ee892STomi Valkeinen if (wait_for_completion_timeout(&completion, 2309f76ee892STomi Valkeinen msecs_to_jiffies(10)) == 0) { 2310f76ee892STomi Valkeinen DSSERR("Failed to complete previous frame transfer\n"); 2311f76ee892STomi Valkeinen r = -EIO; 2312f76ee892STomi Valkeinen goto err1; 2313f76ee892STomi Valkeinen } 2314f76ee892STomi Valkeinen } 2315f76ee892STomi Valkeinen 2316f76ee892STomi Valkeinen dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp, 2317f76ee892STomi Valkeinen &vp_data, DSI_VC_IRQ_PACKET_SENT); 2318f76ee892STomi Valkeinen 2319f76ee892STomi Valkeinen return 0; 2320f76ee892STomi Valkeinen err1: 2321f76ee892STomi Valkeinen dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp, 2322f76ee892STomi Valkeinen &vp_data, DSI_VC_IRQ_PACKET_SENT); 2323f76ee892STomi Valkeinen err0: 2324f76ee892STomi Valkeinen return r; 2325f76ee892STomi Valkeinen } 2326f76ee892STomi Valkeinen 2327f76ee892STomi Valkeinen static void dsi_packet_sent_handler_l4(void *data, u32 mask) 2328f76ee892STomi Valkeinen { 2329f76ee892STomi Valkeinen struct dsi_packet_sent_handler_data *l4_data = 2330f76ee892STomi Valkeinen (struct dsi_packet_sent_handler_data *) data; 2331f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(l4_data->dsidev); 2332f76ee892STomi Valkeinen const int channel = dsi->update_channel; 2333f76ee892STomi Valkeinen 2334f76ee892STomi Valkeinen if (REG_GET(l4_data->dsidev, DSI_VC_CTRL(channel), 5, 5) == 0) 2335f76ee892STomi Valkeinen complete(l4_data->completion); 2336f76ee892STomi Valkeinen } 2337f76ee892STomi Valkeinen 2338f76ee892STomi Valkeinen static int dsi_sync_vc_l4(struct platform_device *dsidev, int channel) 2339f76ee892STomi Valkeinen { 2340f76ee892STomi Valkeinen DECLARE_COMPLETION_ONSTACK(completion); 2341f76ee892STomi Valkeinen struct dsi_packet_sent_handler_data l4_data = { 2342f76ee892STomi Valkeinen .dsidev = dsidev, 2343f76ee892STomi Valkeinen .completion = &completion 2344f76ee892STomi Valkeinen }; 2345f76ee892STomi Valkeinen int r = 0; 2346f76ee892STomi Valkeinen 2347f76ee892STomi Valkeinen r = dsi_register_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4, 2348f76ee892STomi Valkeinen &l4_data, DSI_VC_IRQ_PACKET_SENT); 2349f76ee892STomi Valkeinen if (r) 2350f76ee892STomi Valkeinen goto err0; 2351f76ee892STomi Valkeinen 2352f76ee892STomi Valkeinen /* Wait for completion only if TX_FIFO_NOT_EMPTY is still set */ 2353f76ee892STomi Valkeinen if (REG_GET(dsidev, DSI_VC_CTRL(channel), 5, 5)) { 2354f76ee892STomi Valkeinen if (wait_for_completion_timeout(&completion, 2355f76ee892STomi Valkeinen msecs_to_jiffies(10)) == 0) { 2356f76ee892STomi Valkeinen DSSERR("Failed to complete previous l4 transfer\n"); 2357f76ee892STomi Valkeinen r = -EIO; 2358f76ee892STomi Valkeinen goto err1; 2359f76ee892STomi Valkeinen } 2360f76ee892STomi Valkeinen } 2361f76ee892STomi Valkeinen 2362f76ee892STomi Valkeinen dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4, 2363f76ee892STomi Valkeinen &l4_data, DSI_VC_IRQ_PACKET_SENT); 2364f76ee892STomi Valkeinen 2365f76ee892STomi Valkeinen return 0; 2366f76ee892STomi Valkeinen err1: 2367f76ee892STomi Valkeinen dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4, 2368f76ee892STomi Valkeinen &l4_data, DSI_VC_IRQ_PACKET_SENT); 2369f76ee892STomi Valkeinen err0: 2370f76ee892STomi Valkeinen return r; 2371f76ee892STomi Valkeinen } 2372f76ee892STomi Valkeinen 2373f76ee892STomi Valkeinen static int dsi_sync_vc(struct platform_device *dsidev, int channel) 2374f76ee892STomi Valkeinen { 2375f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 2376f76ee892STomi Valkeinen 2377f76ee892STomi Valkeinen WARN_ON(!dsi_bus_is_locked(dsidev)); 2378f76ee892STomi Valkeinen 2379f76ee892STomi Valkeinen WARN_ON(in_interrupt()); 2380f76ee892STomi Valkeinen 2381f76ee892STomi Valkeinen if (!dsi_vc_is_enabled(dsidev, channel)) 2382f76ee892STomi Valkeinen return 0; 2383f76ee892STomi Valkeinen 2384f76ee892STomi Valkeinen switch (dsi->vc[channel].source) { 2385f76ee892STomi Valkeinen case DSI_VC_SOURCE_VP: 2386f76ee892STomi Valkeinen return dsi_sync_vc_vp(dsidev, channel); 2387f76ee892STomi Valkeinen case DSI_VC_SOURCE_L4: 2388f76ee892STomi Valkeinen return dsi_sync_vc_l4(dsidev, channel); 2389f76ee892STomi Valkeinen default: 2390f76ee892STomi Valkeinen BUG(); 2391f76ee892STomi Valkeinen return -EINVAL; 2392f76ee892STomi Valkeinen } 2393f76ee892STomi Valkeinen } 2394f76ee892STomi Valkeinen 2395f76ee892STomi Valkeinen static int dsi_vc_enable(struct platform_device *dsidev, int channel, 2396f76ee892STomi Valkeinen bool enable) 2397f76ee892STomi Valkeinen { 2398f76ee892STomi Valkeinen DSSDBG("dsi_vc_enable channel %d, enable %d\n", 2399f76ee892STomi Valkeinen channel, enable); 2400f76ee892STomi Valkeinen 2401f76ee892STomi Valkeinen enable = enable ? 1 : 0; 2402f76ee892STomi Valkeinen 2403f76ee892STomi Valkeinen REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 0, 0); 2404f76ee892STomi Valkeinen 2405f76ee892STomi Valkeinen if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel), 2406f76ee892STomi Valkeinen 0, enable) != enable) { 2407f76ee892STomi Valkeinen DSSERR("Failed to set dsi_vc_enable to %d\n", enable); 2408f76ee892STomi Valkeinen return -EIO; 2409f76ee892STomi Valkeinen } 2410f76ee892STomi Valkeinen 2411f76ee892STomi Valkeinen return 0; 2412f76ee892STomi Valkeinen } 2413f76ee892STomi Valkeinen 2414f76ee892STomi Valkeinen static void dsi_vc_initial_config(struct platform_device *dsidev, int channel) 2415f76ee892STomi Valkeinen { 2416f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 2417f76ee892STomi Valkeinen u32 r; 2418f76ee892STomi Valkeinen 2419f76ee892STomi Valkeinen DSSDBG("Initial config of virtual channel %d", channel); 2420f76ee892STomi Valkeinen 2421f76ee892STomi Valkeinen r = dsi_read_reg(dsidev, DSI_VC_CTRL(channel)); 2422f76ee892STomi Valkeinen 2423f76ee892STomi Valkeinen if (FLD_GET(r, 15, 15)) /* VC_BUSY */ 2424f76ee892STomi Valkeinen DSSERR("VC(%d) busy when trying to configure it!\n", 2425f76ee892STomi Valkeinen channel); 2426f76ee892STomi Valkeinen 2427f76ee892STomi Valkeinen r = FLD_MOD(r, 0, 1, 1); /* SOURCE, 0 = L4 */ 2428f76ee892STomi Valkeinen r = FLD_MOD(r, 0, 2, 2); /* BTA_SHORT_EN */ 2429f76ee892STomi Valkeinen r = FLD_MOD(r, 0, 3, 3); /* BTA_LONG_EN */ 2430f76ee892STomi Valkeinen r = FLD_MOD(r, 0, 4, 4); /* MODE, 0 = command */ 2431f76ee892STomi Valkeinen r = FLD_MOD(r, 1, 7, 7); /* CS_TX_EN */ 2432f76ee892STomi Valkeinen r = FLD_MOD(r, 1, 8, 8); /* ECC_TX_EN */ 2433f76ee892STomi Valkeinen r = FLD_MOD(r, 0, 9, 9); /* MODE_SPEED, high speed on/off */ 2434f76ee892STomi Valkeinen if (dss_has_feature(FEAT_DSI_VC_OCP_WIDTH)) 2435f76ee892STomi Valkeinen r = FLD_MOD(r, 3, 11, 10); /* OCP_WIDTH = 32 bit */ 2436f76ee892STomi Valkeinen 2437f76ee892STomi Valkeinen r = FLD_MOD(r, 4, 29, 27); /* DMA_RX_REQ_NB = no dma */ 2438f76ee892STomi Valkeinen r = FLD_MOD(r, 4, 23, 21); /* DMA_TX_REQ_NB = no dma */ 2439f76ee892STomi Valkeinen 2440f76ee892STomi Valkeinen dsi_write_reg(dsidev, DSI_VC_CTRL(channel), r); 2441f76ee892STomi Valkeinen 2442f76ee892STomi Valkeinen dsi->vc[channel].source = DSI_VC_SOURCE_L4; 2443f76ee892STomi Valkeinen } 2444f76ee892STomi Valkeinen 2445f76ee892STomi Valkeinen static int dsi_vc_config_source(struct platform_device *dsidev, int channel, 2446f76ee892STomi Valkeinen enum dsi_vc_source source) 2447f76ee892STomi Valkeinen { 2448f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 2449f76ee892STomi Valkeinen 2450f76ee892STomi Valkeinen if (dsi->vc[channel].source == source) 2451f76ee892STomi Valkeinen return 0; 2452f76ee892STomi Valkeinen 2453f76ee892STomi Valkeinen DSSDBG("Source config of virtual channel %d", channel); 2454f76ee892STomi Valkeinen 2455f76ee892STomi Valkeinen dsi_sync_vc(dsidev, channel); 2456f76ee892STomi Valkeinen 2457f76ee892STomi Valkeinen dsi_vc_enable(dsidev, channel, 0); 2458f76ee892STomi Valkeinen 2459f76ee892STomi Valkeinen /* VC_BUSY */ 2460f76ee892STomi Valkeinen if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel), 15, 0) != 0) { 2461f76ee892STomi Valkeinen DSSERR("vc(%d) busy when trying to config for VP\n", channel); 2462f76ee892STomi Valkeinen return -EIO; 2463f76ee892STomi Valkeinen } 2464f76ee892STomi Valkeinen 2465f76ee892STomi Valkeinen /* SOURCE, 0 = L4, 1 = video port */ 2466f76ee892STomi Valkeinen REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), source, 1, 1); 2467f76ee892STomi Valkeinen 2468f76ee892STomi Valkeinen /* DCS_CMD_ENABLE */ 2469f76ee892STomi Valkeinen if (dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC)) { 2470f76ee892STomi Valkeinen bool enable = source == DSI_VC_SOURCE_VP; 2471f76ee892STomi Valkeinen REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 30, 30); 2472f76ee892STomi Valkeinen } 2473f76ee892STomi Valkeinen 2474f76ee892STomi Valkeinen dsi_vc_enable(dsidev, channel, 1); 2475f76ee892STomi Valkeinen 2476f76ee892STomi Valkeinen dsi->vc[channel].source = source; 2477f76ee892STomi Valkeinen 2478f76ee892STomi Valkeinen return 0; 2479f76ee892STomi Valkeinen } 2480f76ee892STomi Valkeinen 2481f76ee892STomi Valkeinen static void dsi_vc_enable_hs(struct omap_dss_device *dssdev, int channel, 2482f76ee892STomi Valkeinen bool enable) 2483f76ee892STomi Valkeinen { 2484f76ee892STomi Valkeinen struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); 2485f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 2486f76ee892STomi Valkeinen 2487f76ee892STomi Valkeinen DSSDBG("dsi_vc_enable_hs(%d, %d)\n", channel, enable); 2488f76ee892STomi Valkeinen 2489f76ee892STomi Valkeinen WARN_ON(!dsi_bus_is_locked(dsidev)); 2490f76ee892STomi Valkeinen 2491f76ee892STomi Valkeinen dsi_vc_enable(dsidev, channel, 0); 2492f76ee892STomi Valkeinen dsi_if_enable(dsidev, 0); 2493f76ee892STomi Valkeinen 2494f76ee892STomi Valkeinen REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 9, 9); 2495f76ee892STomi Valkeinen 2496f76ee892STomi Valkeinen dsi_vc_enable(dsidev, channel, 1); 2497f76ee892STomi Valkeinen dsi_if_enable(dsidev, 1); 2498f76ee892STomi Valkeinen 2499f76ee892STomi Valkeinen dsi_force_tx_stop_mode_io(dsidev); 2500f76ee892STomi Valkeinen 2501f76ee892STomi Valkeinen /* start the DDR clock by sending a NULL packet */ 2502f76ee892STomi Valkeinen if (dsi->vm_timings.ddr_clk_always_on && enable) 2503f76ee892STomi Valkeinen dsi_vc_send_null(dssdev, channel); 2504f76ee892STomi Valkeinen } 2505f76ee892STomi Valkeinen 2506f76ee892STomi Valkeinen static void dsi_vc_flush_long_data(struct platform_device *dsidev, int channel) 2507f76ee892STomi Valkeinen { 2508f76ee892STomi Valkeinen while (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) { 2509f76ee892STomi Valkeinen u32 val; 2510f76ee892STomi Valkeinen val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel)); 2511f76ee892STomi Valkeinen DSSDBG("\t\tb1 %#02x b2 %#02x b3 %#02x b4 %#02x\n", 2512f76ee892STomi Valkeinen (val >> 0) & 0xff, 2513f76ee892STomi Valkeinen (val >> 8) & 0xff, 2514f76ee892STomi Valkeinen (val >> 16) & 0xff, 2515f76ee892STomi Valkeinen (val >> 24) & 0xff); 2516f76ee892STomi Valkeinen } 2517f76ee892STomi Valkeinen } 2518f76ee892STomi Valkeinen 2519f76ee892STomi Valkeinen static void dsi_show_rx_ack_with_err(u16 err) 2520f76ee892STomi Valkeinen { 2521f76ee892STomi Valkeinen DSSERR("\tACK with ERROR (%#x):\n", err); 2522f76ee892STomi Valkeinen if (err & (1 << 0)) 2523f76ee892STomi Valkeinen DSSERR("\t\tSoT Error\n"); 2524f76ee892STomi Valkeinen if (err & (1 << 1)) 2525f76ee892STomi Valkeinen DSSERR("\t\tSoT Sync Error\n"); 2526f76ee892STomi Valkeinen if (err & (1 << 2)) 2527f76ee892STomi Valkeinen DSSERR("\t\tEoT Sync Error\n"); 2528f76ee892STomi Valkeinen if (err & (1 << 3)) 2529f76ee892STomi Valkeinen DSSERR("\t\tEscape Mode Entry Command Error\n"); 2530f76ee892STomi Valkeinen if (err & (1 << 4)) 2531f76ee892STomi Valkeinen DSSERR("\t\tLP Transmit Sync Error\n"); 2532f76ee892STomi Valkeinen if (err & (1 << 5)) 2533f76ee892STomi Valkeinen DSSERR("\t\tHS Receive Timeout Error\n"); 2534f76ee892STomi Valkeinen if (err & (1 << 6)) 2535f76ee892STomi Valkeinen DSSERR("\t\tFalse Control Error\n"); 2536f76ee892STomi Valkeinen if (err & (1 << 7)) 2537f76ee892STomi Valkeinen DSSERR("\t\t(reserved7)\n"); 2538f76ee892STomi Valkeinen if (err & (1 << 8)) 2539f76ee892STomi Valkeinen DSSERR("\t\tECC Error, single-bit (corrected)\n"); 2540f76ee892STomi Valkeinen if (err & (1 << 9)) 2541f76ee892STomi Valkeinen DSSERR("\t\tECC Error, multi-bit (not corrected)\n"); 2542f76ee892STomi Valkeinen if (err & (1 << 10)) 2543f76ee892STomi Valkeinen DSSERR("\t\tChecksum Error\n"); 2544f76ee892STomi Valkeinen if (err & (1 << 11)) 2545f76ee892STomi Valkeinen DSSERR("\t\tData type not recognized\n"); 2546f76ee892STomi Valkeinen if (err & (1 << 12)) 2547f76ee892STomi Valkeinen DSSERR("\t\tInvalid VC ID\n"); 2548f76ee892STomi Valkeinen if (err & (1 << 13)) 2549f76ee892STomi Valkeinen DSSERR("\t\tInvalid Transmission Length\n"); 2550f76ee892STomi Valkeinen if (err & (1 << 14)) 2551f76ee892STomi Valkeinen DSSERR("\t\t(reserved14)\n"); 2552f76ee892STomi Valkeinen if (err & (1 << 15)) 2553f76ee892STomi Valkeinen DSSERR("\t\tDSI Protocol Violation\n"); 2554f76ee892STomi Valkeinen } 2555f76ee892STomi Valkeinen 2556f76ee892STomi Valkeinen static u16 dsi_vc_flush_receive_data(struct platform_device *dsidev, 2557f76ee892STomi Valkeinen int channel) 2558f76ee892STomi Valkeinen { 2559f76ee892STomi Valkeinen /* RX_FIFO_NOT_EMPTY */ 2560f76ee892STomi Valkeinen while (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) { 2561f76ee892STomi Valkeinen u32 val; 2562f76ee892STomi Valkeinen u8 dt; 2563f76ee892STomi Valkeinen val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel)); 2564f76ee892STomi Valkeinen DSSERR("\trawval %#08x\n", val); 2565f76ee892STomi Valkeinen dt = FLD_GET(val, 5, 0); 2566f76ee892STomi Valkeinen if (dt == MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT) { 2567f76ee892STomi Valkeinen u16 err = FLD_GET(val, 23, 8); 2568f76ee892STomi Valkeinen dsi_show_rx_ack_with_err(err); 2569f76ee892STomi Valkeinen } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE) { 2570f76ee892STomi Valkeinen DSSERR("\tDCS short response, 1 byte: %#x\n", 2571f76ee892STomi Valkeinen FLD_GET(val, 23, 8)); 2572f76ee892STomi Valkeinen } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE) { 2573f76ee892STomi Valkeinen DSSERR("\tDCS short response, 2 byte: %#x\n", 2574f76ee892STomi Valkeinen FLD_GET(val, 23, 8)); 2575f76ee892STomi Valkeinen } else if (dt == MIPI_DSI_RX_DCS_LONG_READ_RESPONSE) { 2576f76ee892STomi Valkeinen DSSERR("\tDCS long response, len %d\n", 2577f76ee892STomi Valkeinen FLD_GET(val, 23, 8)); 2578f76ee892STomi Valkeinen dsi_vc_flush_long_data(dsidev, channel); 2579f76ee892STomi Valkeinen } else { 2580f76ee892STomi Valkeinen DSSERR("\tunknown datatype 0x%02x\n", dt); 2581f76ee892STomi Valkeinen } 2582f76ee892STomi Valkeinen } 2583f76ee892STomi Valkeinen return 0; 2584f76ee892STomi Valkeinen } 2585f76ee892STomi Valkeinen 2586f76ee892STomi Valkeinen static int dsi_vc_send_bta(struct platform_device *dsidev, int channel) 2587f76ee892STomi Valkeinen { 2588f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 2589f76ee892STomi Valkeinen 2590f76ee892STomi Valkeinen if (dsi->debug_write || dsi->debug_read) 2591f76ee892STomi Valkeinen DSSDBG("dsi_vc_send_bta %d\n", channel); 2592f76ee892STomi Valkeinen 2593f76ee892STomi Valkeinen WARN_ON(!dsi_bus_is_locked(dsidev)); 2594f76ee892STomi Valkeinen 2595f76ee892STomi Valkeinen /* RX_FIFO_NOT_EMPTY */ 2596f76ee892STomi Valkeinen if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) { 2597f76ee892STomi Valkeinen DSSERR("rx fifo not empty when sending BTA, dumping data:\n"); 2598f76ee892STomi Valkeinen dsi_vc_flush_receive_data(dsidev, channel); 2599f76ee892STomi Valkeinen } 2600f76ee892STomi Valkeinen 2601f76ee892STomi Valkeinen REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 6, 6); /* BTA_EN */ 2602f76ee892STomi Valkeinen 2603f76ee892STomi Valkeinen /* flush posted write */ 2604f76ee892STomi Valkeinen dsi_read_reg(dsidev, DSI_VC_CTRL(channel)); 2605f76ee892STomi Valkeinen 2606f76ee892STomi Valkeinen return 0; 2607f76ee892STomi Valkeinen } 2608f76ee892STomi Valkeinen 2609f76ee892STomi Valkeinen static int dsi_vc_send_bta_sync(struct omap_dss_device *dssdev, int channel) 2610f76ee892STomi Valkeinen { 2611f76ee892STomi Valkeinen struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); 2612f76ee892STomi Valkeinen DECLARE_COMPLETION_ONSTACK(completion); 2613f76ee892STomi Valkeinen int r = 0; 2614f76ee892STomi Valkeinen u32 err; 2615f76ee892STomi Valkeinen 2616f76ee892STomi Valkeinen r = dsi_register_isr_vc(dsidev, channel, dsi_completion_handler, 2617f76ee892STomi Valkeinen &completion, DSI_VC_IRQ_BTA); 2618f76ee892STomi Valkeinen if (r) 2619f76ee892STomi Valkeinen goto err0; 2620f76ee892STomi Valkeinen 2621f76ee892STomi Valkeinen r = dsi_register_isr(dsidev, dsi_completion_handler, &completion, 2622f76ee892STomi Valkeinen DSI_IRQ_ERROR_MASK); 2623f76ee892STomi Valkeinen if (r) 2624f76ee892STomi Valkeinen goto err1; 2625f76ee892STomi Valkeinen 2626f76ee892STomi Valkeinen r = dsi_vc_send_bta(dsidev, channel); 2627f76ee892STomi Valkeinen if (r) 2628f76ee892STomi Valkeinen goto err2; 2629f76ee892STomi Valkeinen 2630f76ee892STomi Valkeinen if (wait_for_completion_timeout(&completion, 2631f76ee892STomi Valkeinen msecs_to_jiffies(500)) == 0) { 2632f76ee892STomi Valkeinen DSSERR("Failed to receive BTA\n"); 2633f76ee892STomi Valkeinen r = -EIO; 2634f76ee892STomi Valkeinen goto err2; 2635f76ee892STomi Valkeinen } 2636f76ee892STomi Valkeinen 2637f76ee892STomi Valkeinen err = dsi_get_errors(dsidev); 2638f76ee892STomi Valkeinen if (err) { 2639f76ee892STomi Valkeinen DSSERR("Error while sending BTA: %x\n", err); 2640f76ee892STomi Valkeinen r = -EIO; 2641f76ee892STomi Valkeinen goto err2; 2642f76ee892STomi Valkeinen } 2643f76ee892STomi Valkeinen err2: 2644f76ee892STomi Valkeinen dsi_unregister_isr(dsidev, dsi_completion_handler, &completion, 2645f76ee892STomi Valkeinen DSI_IRQ_ERROR_MASK); 2646f76ee892STomi Valkeinen err1: 2647f76ee892STomi Valkeinen dsi_unregister_isr_vc(dsidev, channel, dsi_completion_handler, 2648f76ee892STomi Valkeinen &completion, DSI_VC_IRQ_BTA); 2649f76ee892STomi Valkeinen err0: 2650f76ee892STomi Valkeinen return r; 2651f76ee892STomi Valkeinen } 2652f76ee892STomi Valkeinen 2653f76ee892STomi Valkeinen static inline void dsi_vc_write_long_header(struct platform_device *dsidev, 2654f76ee892STomi Valkeinen int channel, u8 data_type, u16 len, u8 ecc) 2655f76ee892STomi Valkeinen { 2656f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 2657f76ee892STomi Valkeinen u32 val; 2658f76ee892STomi Valkeinen u8 data_id; 2659f76ee892STomi Valkeinen 2660f76ee892STomi Valkeinen WARN_ON(!dsi_bus_is_locked(dsidev)); 2661f76ee892STomi Valkeinen 2662f76ee892STomi Valkeinen data_id = data_type | dsi->vc[channel].vc_id << 6; 2663f76ee892STomi Valkeinen 2664f76ee892STomi Valkeinen val = FLD_VAL(data_id, 7, 0) | FLD_VAL(len, 23, 8) | 2665f76ee892STomi Valkeinen FLD_VAL(ecc, 31, 24); 2666f76ee892STomi Valkeinen 2667f76ee892STomi Valkeinen dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_HEADER(channel), val); 2668f76ee892STomi Valkeinen } 2669f76ee892STomi Valkeinen 2670f76ee892STomi Valkeinen static inline void dsi_vc_write_long_payload(struct platform_device *dsidev, 2671f76ee892STomi Valkeinen int channel, u8 b1, u8 b2, u8 b3, u8 b4) 2672f76ee892STomi Valkeinen { 2673f76ee892STomi Valkeinen u32 val; 2674f76ee892STomi Valkeinen 2675f76ee892STomi Valkeinen val = b4 << 24 | b3 << 16 | b2 << 8 | b1 << 0; 2676f76ee892STomi Valkeinen 2677f76ee892STomi Valkeinen /* DSSDBG("\twriting %02x, %02x, %02x, %02x (%#010x)\n", 2678f76ee892STomi Valkeinen b1, b2, b3, b4, val); */ 2679f76ee892STomi Valkeinen 2680f76ee892STomi Valkeinen dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_PAYLOAD(channel), val); 2681f76ee892STomi Valkeinen } 2682f76ee892STomi Valkeinen 2683f76ee892STomi Valkeinen static int dsi_vc_send_long(struct platform_device *dsidev, int channel, 2684f76ee892STomi Valkeinen u8 data_type, u8 *data, u16 len, u8 ecc) 2685f76ee892STomi Valkeinen { 2686f76ee892STomi Valkeinen /*u32 val; */ 2687f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 2688f76ee892STomi Valkeinen int i; 2689f76ee892STomi Valkeinen u8 *p; 2690f76ee892STomi Valkeinen int r = 0; 2691f76ee892STomi Valkeinen u8 b1, b2, b3, b4; 2692f76ee892STomi Valkeinen 2693f76ee892STomi Valkeinen if (dsi->debug_write) 2694f76ee892STomi Valkeinen DSSDBG("dsi_vc_send_long, %d bytes\n", len); 2695f76ee892STomi Valkeinen 2696f76ee892STomi Valkeinen /* len + header */ 2697f76ee892STomi Valkeinen if (dsi->vc[channel].tx_fifo_size * 32 * 4 < len + 4) { 2698f76ee892STomi Valkeinen DSSERR("unable to send long packet: packet too long.\n"); 2699f76ee892STomi Valkeinen return -EINVAL; 2700f76ee892STomi Valkeinen } 2701f76ee892STomi Valkeinen 2702f76ee892STomi Valkeinen dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_L4); 2703f76ee892STomi Valkeinen 2704f76ee892STomi Valkeinen dsi_vc_write_long_header(dsidev, channel, data_type, len, ecc); 2705f76ee892STomi Valkeinen 2706f76ee892STomi Valkeinen p = data; 2707f76ee892STomi Valkeinen for (i = 0; i < len >> 2; i++) { 2708f76ee892STomi Valkeinen if (dsi->debug_write) 2709f76ee892STomi Valkeinen DSSDBG("\tsending full packet %d\n", i); 2710f76ee892STomi Valkeinen 2711f76ee892STomi Valkeinen b1 = *p++; 2712f76ee892STomi Valkeinen b2 = *p++; 2713f76ee892STomi Valkeinen b3 = *p++; 2714f76ee892STomi Valkeinen b4 = *p++; 2715f76ee892STomi Valkeinen 2716f76ee892STomi Valkeinen dsi_vc_write_long_payload(dsidev, channel, b1, b2, b3, b4); 2717f76ee892STomi Valkeinen } 2718f76ee892STomi Valkeinen 2719f76ee892STomi Valkeinen i = len % 4; 2720f76ee892STomi Valkeinen if (i) { 2721f76ee892STomi Valkeinen b1 = 0; b2 = 0; b3 = 0; 2722f76ee892STomi Valkeinen 2723f76ee892STomi Valkeinen if (dsi->debug_write) 2724f76ee892STomi Valkeinen DSSDBG("\tsending remainder bytes %d\n", i); 2725f76ee892STomi Valkeinen 2726f76ee892STomi Valkeinen switch (i) { 2727f76ee892STomi Valkeinen case 3: 2728f76ee892STomi Valkeinen b1 = *p++; 2729f76ee892STomi Valkeinen b2 = *p++; 2730f76ee892STomi Valkeinen b3 = *p++; 2731f76ee892STomi Valkeinen break; 2732f76ee892STomi Valkeinen case 2: 2733f76ee892STomi Valkeinen b1 = *p++; 2734f76ee892STomi Valkeinen b2 = *p++; 2735f76ee892STomi Valkeinen break; 2736f76ee892STomi Valkeinen case 1: 2737f76ee892STomi Valkeinen b1 = *p++; 2738f76ee892STomi Valkeinen break; 2739f76ee892STomi Valkeinen } 2740f76ee892STomi Valkeinen 2741f76ee892STomi Valkeinen dsi_vc_write_long_payload(dsidev, channel, b1, b2, b3, 0); 2742f76ee892STomi Valkeinen } 2743f76ee892STomi Valkeinen 2744f76ee892STomi Valkeinen return r; 2745f76ee892STomi Valkeinen } 2746f76ee892STomi Valkeinen 2747f76ee892STomi Valkeinen static int dsi_vc_send_short(struct platform_device *dsidev, int channel, 2748f76ee892STomi Valkeinen u8 data_type, u16 data, u8 ecc) 2749f76ee892STomi Valkeinen { 2750f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 2751f76ee892STomi Valkeinen u32 r; 2752f76ee892STomi Valkeinen u8 data_id; 2753f76ee892STomi Valkeinen 2754f76ee892STomi Valkeinen WARN_ON(!dsi_bus_is_locked(dsidev)); 2755f76ee892STomi Valkeinen 2756f76ee892STomi Valkeinen if (dsi->debug_write) 2757f76ee892STomi Valkeinen DSSDBG("dsi_vc_send_short(ch%d, dt %#x, b1 %#x, b2 %#x)\n", 2758f76ee892STomi Valkeinen channel, 2759f76ee892STomi Valkeinen data_type, data & 0xff, (data >> 8) & 0xff); 2760f76ee892STomi Valkeinen 2761f76ee892STomi Valkeinen dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_L4); 2762f76ee892STomi Valkeinen 2763f76ee892STomi Valkeinen if (FLD_GET(dsi_read_reg(dsidev, DSI_VC_CTRL(channel)), 16, 16)) { 2764f76ee892STomi Valkeinen DSSERR("ERROR FIFO FULL, aborting transfer\n"); 2765f76ee892STomi Valkeinen return -EINVAL; 2766f76ee892STomi Valkeinen } 2767f76ee892STomi Valkeinen 2768f76ee892STomi Valkeinen data_id = data_type | dsi->vc[channel].vc_id << 6; 2769f76ee892STomi Valkeinen 2770f76ee892STomi Valkeinen r = (data_id << 0) | (data << 8) | (ecc << 24); 2771f76ee892STomi Valkeinen 2772f76ee892STomi Valkeinen dsi_write_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel), r); 2773f76ee892STomi Valkeinen 2774f76ee892STomi Valkeinen return 0; 2775f76ee892STomi Valkeinen } 2776f76ee892STomi Valkeinen 2777f76ee892STomi Valkeinen static int dsi_vc_send_null(struct omap_dss_device *dssdev, int channel) 2778f76ee892STomi Valkeinen { 2779f76ee892STomi Valkeinen struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); 2780f76ee892STomi Valkeinen 2781f76ee892STomi Valkeinen return dsi_vc_send_long(dsidev, channel, MIPI_DSI_NULL_PACKET, NULL, 2782f76ee892STomi Valkeinen 0, 0); 2783f76ee892STomi Valkeinen } 2784f76ee892STomi Valkeinen 2785f76ee892STomi Valkeinen static int dsi_vc_write_nosync_common(struct platform_device *dsidev, 2786f76ee892STomi Valkeinen int channel, u8 *data, int len, enum dss_dsi_content_type type) 2787f76ee892STomi Valkeinen { 2788f76ee892STomi Valkeinen int r; 2789f76ee892STomi Valkeinen 2790f76ee892STomi Valkeinen if (len == 0) { 2791f76ee892STomi Valkeinen BUG_ON(type == DSS_DSI_CONTENT_DCS); 2792f76ee892STomi Valkeinen r = dsi_vc_send_short(dsidev, channel, 2793f76ee892STomi Valkeinen MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM, 0, 0); 2794f76ee892STomi Valkeinen } else if (len == 1) { 2795f76ee892STomi Valkeinen r = dsi_vc_send_short(dsidev, channel, 2796f76ee892STomi Valkeinen type == DSS_DSI_CONTENT_GENERIC ? 2797f76ee892STomi Valkeinen MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM : 2798f76ee892STomi Valkeinen MIPI_DSI_DCS_SHORT_WRITE, data[0], 0); 2799f76ee892STomi Valkeinen } else if (len == 2) { 2800f76ee892STomi Valkeinen r = dsi_vc_send_short(dsidev, channel, 2801f76ee892STomi Valkeinen type == DSS_DSI_CONTENT_GENERIC ? 2802f76ee892STomi Valkeinen MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM : 2803f76ee892STomi Valkeinen MIPI_DSI_DCS_SHORT_WRITE_PARAM, 2804f76ee892STomi Valkeinen data[0] | (data[1] << 8), 0); 2805f76ee892STomi Valkeinen } else { 2806f76ee892STomi Valkeinen r = dsi_vc_send_long(dsidev, channel, 2807f76ee892STomi Valkeinen type == DSS_DSI_CONTENT_GENERIC ? 2808f76ee892STomi Valkeinen MIPI_DSI_GENERIC_LONG_WRITE : 2809f76ee892STomi Valkeinen MIPI_DSI_DCS_LONG_WRITE, data, len, 0); 2810f76ee892STomi Valkeinen } 2811f76ee892STomi Valkeinen 2812f76ee892STomi Valkeinen return r; 2813f76ee892STomi Valkeinen } 2814f76ee892STomi Valkeinen 2815f76ee892STomi Valkeinen static int dsi_vc_dcs_write_nosync(struct omap_dss_device *dssdev, int channel, 2816f76ee892STomi Valkeinen u8 *data, int len) 2817f76ee892STomi Valkeinen { 2818f76ee892STomi Valkeinen struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); 2819f76ee892STomi Valkeinen 2820f76ee892STomi Valkeinen return dsi_vc_write_nosync_common(dsidev, channel, data, len, 2821f76ee892STomi Valkeinen DSS_DSI_CONTENT_DCS); 2822f76ee892STomi Valkeinen } 2823f76ee892STomi Valkeinen 2824f76ee892STomi Valkeinen static int dsi_vc_generic_write_nosync(struct omap_dss_device *dssdev, int channel, 2825f76ee892STomi Valkeinen u8 *data, int len) 2826f76ee892STomi Valkeinen { 2827f76ee892STomi Valkeinen struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); 2828f76ee892STomi Valkeinen 2829f76ee892STomi Valkeinen return dsi_vc_write_nosync_common(dsidev, channel, data, len, 2830f76ee892STomi Valkeinen DSS_DSI_CONTENT_GENERIC); 2831f76ee892STomi Valkeinen } 2832f76ee892STomi Valkeinen 2833f76ee892STomi Valkeinen static int dsi_vc_write_common(struct omap_dss_device *dssdev, int channel, 2834f76ee892STomi Valkeinen u8 *data, int len, enum dss_dsi_content_type type) 2835f76ee892STomi Valkeinen { 2836f76ee892STomi Valkeinen struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); 2837f76ee892STomi Valkeinen int r; 2838f76ee892STomi Valkeinen 2839f76ee892STomi Valkeinen r = dsi_vc_write_nosync_common(dsidev, channel, data, len, type); 2840f76ee892STomi Valkeinen if (r) 2841f76ee892STomi Valkeinen goto err; 2842f76ee892STomi Valkeinen 2843f76ee892STomi Valkeinen r = dsi_vc_send_bta_sync(dssdev, channel); 2844f76ee892STomi Valkeinen if (r) 2845f76ee892STomi Valkeinen goto err; 2846f76ee892STomi Valkeinen 2847f76ee892STomi Valkeinen /* RX_FIFO_NOT_EMPTY */ 2848f76ee892STomi Valkeinen if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) { 2849f76ee892STomi Valkeinen DSSERR("rx fifo not empty after write, dumping data:\n"); 2850f76ee892STomi Valkeinen dsi_vc_flush_receive_data(dsidev, channel); 2851f76ee892STomi Valkeinen r = -EIO; 2852f76ee892STomi Valkeinen goto err; 2853f76ee892STomi Valkeinen } 2854f76ee892STomi Valkeinen 2855f76ee892STomi Valkeinen return 0; 2856f76ee892STomi Valkeinen err: 2857f76ee892STomi Valkeinen DSSERR("dsi_vc_write_common(ch %d, cmd 0x%02x, len %d) failed\n", 2858f76ee892STomi Valkeinen channel, data[0], len); 2859f76ee892STomi Valkeinen return r; 2860f76ee892STomi Valkeinen } 2861f76ee892STomi Valkeinen 2862f76ee892STomi Valkeinen static int dsi_vc_dcs_write(struct omap_dss_device *dssdev, int channel, u8 *data, 2863f76ee892STomi Valkeinen int len) 2864f76ee892STomi Valkeinen { 2865f76ee892STomi Valkeinen return dsi_vc_write_common(dssdev, channel, data, len, 2866f76ee892STomi Valkeinen DSS_DSI_CONTENT_DCS); 2867f76ee892STomi Valkeinen } 2868f76ee892STomi Valkeinen 2869f76ee892STomi Valkeinen static int dsi_vc_generic_write(struct omap_dss_device *dssdev, int channel, u8 *data, 2870f76ee892STomi Valkeinen int len) 2871f76ee892STomi Valkeinen { 2872f76ee892STomi Valkeinen return dsi_vc_write_common(dssdev, channel, data, len, 2873f76ee892STomi Valkeinen DSS_DSI_CONTENT_GENERIC); 2874f76ee892STomi Valkeinen } 2875f76ee892STomi Valkeinen 2876f76ee892STomi Valkeinen static int dsi_vc_dcs_send_read_request(struct platform_device *dsidev, 2877f76ee892STomi Valkeinen int channel, u8 dcs_cmd) 2878f76ee892STomi Valkeinen { 2879f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 2880f76ee892STomi Valkeinen int r; 2881f76ee892STomi Valkeinen 2882f76ee892STomi Valkeinen if (dsi->debug_read) 2883f76ee892STomi Valkeinen DSSDBG("dsi_vc_dcs_send_read_request(ch%d, dcs_cmd %x)\n", 2884f76ee892STomi Valkeinen channel, dcs_cmd); 2885f76ee892STomi Valkeinen 2886f76ee892STomi Valkeinen r = dsi_vc_send_short(dsidev, channel, MIPI_DSI_DCS_READ, dcs_cmd, 0); 2887f76ee892STomi Valkeinen if (r) { 2888f76ee892STomi Valkeinen DSSERR("dsi_vc_dcs_send_read_request(ch %d, cmd 0x%02x)" 2889f76ee892STomi Valkeinen " failed\n", channel, dcs_cmd); 2890f76ee892STomi Valkeinen return r; 2891f76ee892STomi Valkeinen } 2892f76ee892STomi Valkeinen 2893f76ee892STomi Valkeinen return 0; 2894f76ee892STomi Valkeinen } 2895f76ee892STomi Valkeinen 2896f76ee892STomi Valkeinen static int dsi_vc_generic_send_read_request(struct platform_device *dsidev, 2897f76ee892STomi Valkeinen int channel, u8 *reqdata, int reqlen) 2898f76ee892STomi Valkeinen { 2899f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 2900f76ee892STomi Valkeinen u16 data; 2901f76ee892STomi Valkeinen u8 data_type; 2902f76ee892STomi Valkeinen int r; 2903f76ee892STomi Valkeinen 2904f76ee892STomi Valkeinen if (dsi->debug_read) 2905f76ee892STomi Valkeinen DSSDBG("dsi_vc_generic_send_read_request(ch %d, reqlen %d)\n", 2906f76ee892STomi Valkeinen channel, reqlen); 2907f76ee892STomi Valkeinen 2908f76ee892STomi Valkeinen if (reqlen == 0) { 2909f76ee892STomi Valkeinen data_type = MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM; 2910f76ee892STomi Valkeinen data = 0; 2911f76ee892STomi Valkeinen } else if (reqlen == 1) { 2912f76ee892STomi Valkeinen data_type = MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM; 2913f76ee892STomi Valkeinen data = reqdata[0]; 2914f76ee892STomi Valkeinen } else if (reqlen == 2) { 2915f76ee892STomi Valkeinen data_type = MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM; 2916f76ee892STomi Valkeinen data = reqdata[0] | (reqdata[1] << 8); 2917f76ee892STomi Valkeinen } else { 2918f76ee892STomi Valkeinen BUG(); 2919f76ee892STomi Valkeinen return -EINVAL; 2920f76ee892STomi Valkeinen } 2921f76ee892STomi Valkeinen 2922f76ee892STomi Valkeinen r = dsi_vc_send_short(dsidev, channel, data_type, data, 0); 2923f76ee892STomi Valkeinen if (r) { 2924f76ee892STomi Valkeinen DSSERR("dsi_vc_generic_send_read_request(ch %d, reqlen %d)" 2925f76ee892STomi Valkeinen " failed\n", channel, reqlen); 2926f76ee892STomi Valkeinen return r; 2927f76ee892STomi Valkeinen } 2928f76ee892STomi Valkeinen 2929f76ee892STomi Valkeinen return 0; 2930f76ee892STomi Valkeinen } 2931f76ee892STomi Valkeinen 2932f76ee892STomi Valkeinen static int dsi_vc_read_rx_fifo(struct platform_device *dsidev, int channel, 2933f76ee892STomi Valkeinen u8 *buf, int buflen, enum dss_dsi_content_type type) 2934f76ee892STomi Valkeinen { 2935f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 2936f76ee892STomi Valkeinen u32 val; 2937f76ee892STomi Valkeinen u8 dt; 2938f76ee892STomi Valkeinen int r; 2939f76ee892STomi Valkeinen 2940f76ee892STomi Valkeinen /* RX_FIFO_NOT_EMPTY */ 2941f76ee892STomi Valkeinen if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20) == 0) { 2942f76ee892STomi Valkeinen DSSERR("RX fifo empty when trying to read.\n"); 2943f76ee892STomi Valkeinen r = -EIO; 2944f76ee892STomi Valkeinen goto err; 2945f76ee892STomi Valkeinen } 2946f76ee892STomi Valkeinen 2947f76ee892STomi Valkeinen val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel)); 2948f76ee892STomi Valkeinen if (dsi->debug_read) 2949f76ee892STomi Valkeinen DSSDBG("\theader: %08x\n", val); 2950f76ee892STomi Valkeinen dt = FLD_GET(val, 5, 0); 2951f76ee892STomi Valkeinen if (dt == MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT) { 2952f76ee892STomi Valkeinen u16 err = FLD_GET(val, 23, 8); 2953f76ee892STomi Valkeinen dsi_show_rx_ack_with_err(err); 2954f76ee892STomi Valkeinen r = -EIO; 2955f76ee892STomi Valkeinen goto err; 2956f76ee892STomi Valkeinen 2957f76ee892STomi Valkeinen } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ? 2958f76ee892STomi Valkeinen MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_1BYTE : 2959f76ee892STomi Valkeinen MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE)) { 2960f76ee892STomi Valkeinen u8 data = FLD_GET(val, 15, 8); 2961f76ee892STomi Valkeinen if (dsi->debug_read) 2962f76ee892STomi Valkeinen DSSDBG("\t%s short response, 1 byte: %02x\n", 2963f76ee892STomi Valkeinen type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" : 2964f76ee892STomi Valkeinen "DCS", data); 2965f76ee892STomi Valkeinen 2966f76ee892STomi Valkeinen if (buflen < 1) { 2967f76ee892STomi Valkeinen r = -EIO; 2968f76ee892STomi Valkeinen goto err; 2969f76ee892STomi Valkeinen } 2970f76ee892STomi Valkeinen 2971f76ee892STomi Valkeinen buf[0] = data; 2972f76ee892STomi Valkeinen 2973f76ee892STomi Valkeinen return 1; 2974f76ee892STomi Valkeinen } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ? 2975f76ee892STomi Valkeinen MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_2BYTE : 2976f76ee892STomi Valkeinen MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE)) { 2977f76ee892STomi Valkeinen u16 data = FLD_GET(val, 23, 8); 2978f76ee892STomi Valkeinen if (dsi->debug_read) 2979f76ee892STomi Valkeinen DSSDBG("\t%s short response, 2 byte: %04x\n", 2980f76ee892STomi Valkeinen type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" : 2981f76ee892STomi Valkeinen "DCS", data); 2982f76ee892STomi Valkeinen 2983f76ee892STomi Valkeinen if (buflen < 2) { 2984f76ee892STomi Valkeinen r = -EIO; 2985f76ee892STomi Valkeinen goto err; 2986f76ee892STomi Valkeinen } 2987f76ee892STomi Valkeinen 2988f76ee892STomi Valkeinen buf[0] = data & 0xff; 2989f76ee892STomi Valkeinen buf[1] = (data >> 8) & 0xff; 2990f76ee892STomi Valkeinen 2991f76ee892STomi Valkeinen return 2; 2992f76ee892STomi Valkeinen } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ? 2993f76ee892STomi Valkeinen MIPI_DSI_RX_GENERIC_LONG_READ_RESPONSE : 2994f76ee892STomi Valkeinen MIPI_DSI_RX_DCS_LONG_READ_RESPONSE)) { 2995f76ee892STomi Valkeinen int w; 2996f76ee892STomi Valkeinen int len = FLD_GET(val, 23, 8); 2997f76ee892STomi Valkeinen if (dsi->debug_read) 2998f76ee892STomi Valkeinen DSSDBG("\t%s long response, len %d\n", 2999f76ee892STomi Valkeinen type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" : 3000f76ee892STomi Valkeinen "DCS", len); 3001f76ee892STomi Valkeinen 3002f76ee892STomi Valkeinen if (len > buflen) { 3003f76ee892STomi Valkeinen r = -EIO; 3004f76ee892STomi Valkeinen goto err; 3005f76ee892STomi Valkeinen } 3006f76ee892STomi Valkeinen 3007f76ee892STomi Valkeinen /* two byte checksum ends the packet, not included in len */ 3008f76ee892STomi Valkeinen for (w = 0; w < len + 2;) { 3009f76ee892STomi Valkeinen int b; 3010f76ee892STomi Valkeinen val = dsi_read_reg(dsidev, 3011f76ee892STomi Valkeinen DSI_VC_SHORT_PACKET_HEADER(channel)); 3012f76ee892STomi Valkeinen if (dsi->debug_read) 3013f76ee892STomi Valkeinen DSSDBG("\t\t%02x %02x %02x %02x\n", 3014f76ee892STomi Valkeinen (val >> 0) & 0xff, 3015f76ee892STomi Valkeinen (val >> 8) & 0xff, 3016f76ee892STomi Valkeinen (val >> 16) & 0xff, 3017f76ee892STomi Valkeinen (val >> 24) & 0xff); 3018f76ee892STomi Valkeinen 3019f76ee892STomi Valkeinen for (b = 0; b < 4; ++b) { 3020f76ee892STomi Valkeinen if (w < len) 3021f76ee892STomi Valkeinen buf[w] = (val >> (b * 8)) & 0xff; 3022f76ee892STomi Valkeinen /* we discard the 2 byte checksum */ 3023f76ee892STomi Valkeinen ++w; 3024f76ee892STomi Valkeinen } 3025f76ee892STomi Valkeinen } 3026f76ee892STomi Valkeinen 3027f76ee892STomi Valkeinen return len; 3028f76ee892STomi Valkeinen } else { 3029f76ee892STomi Valkeinen DSSERR("\tunknown datatype 0x%02x\n", dt); 3030f76ee892STomi Valkeinen r = -EIO; 3031f76ee892STomi Valkeinen goto err; 3032f76ee892STomi Valkeinen } 3033f76ee892STomi Valkeinen 3034f76ee892STomi Valkeinen err: 3035f76ee892STomi Valkeinen DSSERR("dsi_vc_read_rx_fifo(ch %d type %s) failed\n", channel, 3036f76ee892STomi Valkeinen type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" : "DCS"); 3037f76ee892STomi Valkeinen 3038f76ee892STomi Valkeinen return r; 3039f76ee892STomi Valkeinen } 3040f76ee892STomi Valkeinen 3041f76ee892STomi Valkeinen static int dsi_vc_dcs_read(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd, 3042f76ee892STomi Valkeinen u8 *buf, int buflen) 3043f76ee892STomi Valkeinen { 3044f76ee892STomi Valkeinen struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); 3045f76ee892STomi Valkeinen int r; 3046f76ee892STomi Valkeinen 3047f76ee892STomi Valkeinen r = dsi_vc_dcs_send_read_request(dsidev, channel, dcs_cmd); 3048f76ee892STomi Valkeinen if (r) 3049f76ee892STomi Valkeinen goto err; 3050f76ee892STomi Valkeinen 3051f76ee892STomi Valkeinen r = dsi_vc_send_bta_sync(dssdev, channel); 3052f76ee892STomi Valkeinen if (r) 3053f76ee892STomi Valkeinen goto err; 3054f76ee892STomi Valkeinen 3055f76ee892STomi Valkeinen r = dsi_vc_read_rx_fifo(dsidev, channel, buf, buflen, 3056f76ee892STomi Valkeinen DSS_DSI_CONTENT_DCS); 3057f76ee892STomi Valkeinen if (r < 0) 3058f76ee892STomi Valkeinen goto err; 3059f76ee892STomi Valkeinen 3060f76ee892STomi Valkeinen if (r != buflen) { 3061f76ee892STomi Valkeinen r = -EIO; 3062f76ee892STomi Valkeinen goto err; 3063f76ee892STomi Valkeinen } 3064f76ee892STomi Valkeinen 3065f76ee892STomi Valkeinen return 0; 3066f76ee892STomi Valkeinen err: 3067f76ee892STomi Valkeinen DSSERR("dsi_vc_dcs_read(ch %d, cmd 0x%02x) failed\n", channel, dcs_cmd); 3068f76ee892STomi Valkeinen return r; 3069f76ee892STomi Valkeinen } 3070f76ee892STomi Valkeinen 3071f76ee892STomi Valkeinen static int dsi_vc_generic_read(struct omap_dss_device *dssdev, int channel, 3072f76ee892STomi Valkeinen u8 *reqdata, int reqlen, u8 *buf, int buflen) 3073f76ee892STomi Valkeinen { 3074f76ee892STomi Valkeinen struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); 3075f76ee892STomi Valkeinen int r; 3076f76ee892STomi Valkeinen 3077f76ee892STomi Valkeinen r = dsi_vc_generic_send_read_request(dsidev, channel, reqdata, reqlen); 3078f76ee892STomi Valkeinen if (r) 3079f76ee892STomi Valkeinen return r; 3080f76ee892STomi Valkeinen 3081f76ee892STomi Valkeinen r = dsi_vc_send_bta_sync(dssdev, channel); 3082f76ee892STomi Valkeinen if (r) 3083f76ee892STomi Valkeinen return r; 3084f76ee892STomi Valkeinen 3085f76ee892STomi Valkeinen r = dsi_vc_read_rx_fifo(dsidev, channel, buf, buflen, 3086f76ee892STomi Valkeinen DSS_DSI_CONTENT_GENERIC); 3087f76ee892STomi Valkeinen if (r < 0) 3088f76ee892STomi Valkeinen return r; 3089f76ee892STomi Valkeinen 3090f76ee892STomi Valkeinen if (r != buflen) { 3091f76ee892STomi Valkeinen r = -EIO; 3092f76ee892STomi Valkeinen return r; 3093f76ee892STomi Valkeinen } 3094f76ee892STomi Valkeinen 3095f76ee892STomi Valkeinen return 0; 3096f76ee892STomi Valkeinen } 3097f76ee892STomi Valkeinen 3098f76ee892STomi Valkeinen static int dsi_vc_set_max_rx_packet_size(struct omap_dss_device *dssdev, int channel, 3099f76ee892STomi Valkeinen u16 len) 3100f76ee892STomi Valkeinen { 3101f76ee892STomi Valkeinen struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); 3102f76ee892STomi Valkeinen 3103f76ee892STomi Valkeinen return dsi_vc_send_short(dsidev, channel, 3104f76ee892STomi Valkeinen MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE, len, 0); 3105f76ee892STomi Valkeinen } 3106f76ee892STomi Valkeinen 3107f76ee892STomi Valkeinen static int dsi_enter_ulps(struct platform_device *dsidev) 3108f76ee892STomi Valkeinen { 3109f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 3110f76ee892STomi Valkeinen DECLARE_COMPLETION_ONSTACK(completion); 3111f76ee892STomi Valkeinen int r, i; 3112f76ee892STomi Valkeinen unsigned mask; 3113f76ee892STomi Valkeinen 3114f76ee892STomi Valkeinen DSSDBG("Entering ULPS"); 3115f76ee892STomi Valkeinen 3116f76ee892STomi Valkeinen WARN_ON(!dsi_bus_is_locked(dsidev)); 3117f76ee892STomi Valkeinen 3118f76ee892STomi Valkeinen WARN_ON(dsi->ulps_enabled); 3119f76ee892STomi Valkeinen 3120f76ee892STomi Valkeinen if (dsi->ulps_enabled) 3121f76ee892STomi Valkeinen return 0; 3122f76ee892STomi Valkeinen 3123f76ee892STomi Valkeinen /* DDR_CLK_ALWAYS_ON */ 3124f76ee892STomi Valkeinen if (REG_GET(dsidev, DSI_CLK_CTRL, 13, 13)) { 3125f76ee892STomi Valkeinen dsi_if_enable(dsidev, 0); 3126f76ee892STomi Valkeinen REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 13, 13); 3127f76ee892STomi Valkeinen dsi_if_enable(dsidev, 1); 3128f76ee892STomi Valkeinen } 3129f76ee892STomi Valkeinen 3130f76ee892STomi Valkeinen dsi_sync_vc(dsidev, 0); 3131f76ee892STomi Valkeinen dsi_sync_vc(dsidev, 1); 3132f76ee892STomi Valkeinen dsi_sync_vc(dsidev, 2); 3133f76ee892STomi Valkeinen dsi_sync_vc(dsidev, 3); 3134f76ee892STomi Valkeinen 3135f76ee892STomi Valkeinen dsi_force_tx_stop_mode_io(dsidev); 3136f76ee892STomi Valkeinen 3137f76ee892STomi Valkeinen dsi_vc_enable(dsidev, 0, false); 3138f76ee892STomi Valkeinen dsi_vc_enable(dsidev, 1, false); 3139f76ee892STomi Valkeinen dsi_vc_enable(dsidev, 2, false); 3140f76ee892STomi Valkeinen dsi_vc_enable(dsidev, 3, false); 3141f76ee892STomi Valkeinen 3142f76ee892STomi Valkeinen if (REG_GET(dsidev, DSI_COMPLEXIO_CFG2, 16, 16)) { /* HS_BUSY */ 3143f76ee892STomi Valkeinen DSSERR("HS busy when enabling ULPS\n"); 3144f76ee892STomi Valkeinen return -EIO; 3145f76ee892STomi Valkeinen } 3146f76ee892STomi Valkeinen 3147f76ee892STomi Valkeinen if (REG_GET(dsidev, DSI_COMPLEXIO_CFG2, 17, 17)) { /* LP_BUSY */ 3148f76ee892STomi Valkeinen DSSERR("LP busy when enabling ULPS\n"); 3149f76ee892STomi Valkeinen return -EIO; 3150f76ee892STomi Valkeinen } 3151f76ee892STomi Valkeinen 3152f76ee892STomi Valkeinen r = dsi_register_isr_cio(dsidev, dsi_completion_handler, &completion, 3153f76ee892STomi Valkeinen DSI_CIO_IRQ_ULPSACTIVENOT_ALL0); 3154f76ee892STomi Valkeinen if (r) 3155f76ee892STomi Valkeinen return r; 3156f76ee892STomi Valkeinen 3157f76ee892STomi Valkeinen mask = 0; 3158f76ee892STomi Valkeinen 3159f76ee892STomi Valkeinen for (i = 0; i < dsi->num_lanes_supported; ++i) { 3160f76ee892STomi Valkeinen if (dsi->lanes[i].function == DSI_LANE_UNUSED) 3161f76ee892STomi Valkeinen continue; 3162f76ee892STomi Valkeinen mask |= 1 << i; 3163f76ee892STomi Valkeinen } 3164f76ee892STomi Valkeinen /* Assert TxRequestEsc for data lanes and TxUlpsClk for clk lane */ 3165f76ee892STomi Valkeinen /* LANEx_ULPS_SIG2 */ 3166f76ee892STomi Valkeinen REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG2, mask, 9, 5); 3167f76ee892STomi Valkeinen 3168f76ee892STomi Valkeinen /* flush posted write and wait for SCP interface to finish the write */ 3169f76ee892STomi Valkeinen dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG2); 3170f76ee892STomi Valkeinen 3171f76ee892STomi Valkeinen if (wait_for_completion_timeout(&completion, 3172f76ee892STomi Valkeinen msecs_to_jiffies(1000)) == 0) { 3173f76ee892STomi Valkeinen DSSERR("ULPS enable timeout\n"); 3174f76ee892STomi Valkeinen r = -EIO; 3175f76ee892STomi Valkeinen goto err; 3176f76ee892STomi Valkeinen } 3177f76ee892STomi Valkeinen 3178f76ee892STomi Valkeinen dsi_unregister_isr_cio(dsidev, dsi_completion_handler, &completion, 3179f76ee892STomi Valkeinen DSI_CIO_IRQ_ULPSACTIVENOT_ALL0); 3180f76ee892STomi Valkeinen 3181f76ee892STomi Valkeinen /* Reset LANEx_ULPS_SIG2 */ 3182f76ee892STomi Valkeinen REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG2, 0, 9, 5); 3183f76ee892STomi Valkeinen 3184f76ee892STomi Valkeinen /* flush posted write and wait for SCP interface to finish the write */ 3185f76ee892STomi Valkeinen dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG2); 3186f76ee892STomi Valkeinen 3187f76ee892STomi Valkeinen dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_ULPS); 3188f76ee892STomi Valkeinen 3189f76ee892STomi Valkeinen dsi_if_enable(dsidev, false); 3190f76ee892STomi Valkeinen 3191f76ee892STomi Valkeinen dsi->ulps_enabled = true; 3192f76ee892STomi Valkeinen 3193f76ee892STomi Valkeinen return 0; 3194f76ee892STomi Valkeinen 3195f76ee892STomi Valkeinen err: 3196f76ee892STomi Valkeinen dsi_unregister_isr_cio(dsidev, dsi_completion_handler, &completion, 3197f76ee892STomi Valkeinen DSI_CIO_IRQ_ULPSACTIVENOT_ALL0); 3198f76ee892STomi Valkeinen return r; 3199f76ee892STomi Valkeinen } 3200f76ee892STomi Valkeinen 3201f76ee892STomi Valkeinen static void dsi_set_lp_rx_timeout(struct platform_device *dsidev, 3202f76ee892STomi Valkeinen unsigned ticks, bool x4, bool x16) 3203f76ee892STomi Valkeinen { 3204f76ee892STomi Valkeinen unsigned long fck; 3205f76ee892STomi Valkeinen unsigned long total_ticks; 3206f76ee892STomi Valkeinen u32 r; 3207f76ee892STomi Valkeinen 3208f76ee892STomi Valkeinen BUG_ON(ticks > 0x1fff); 3209f76ee892STomi Valkeinen 3210f76ee892STomi Valkeinen /* ticks in DSI_FCK */ 3211f76ee892STomi Valkeinen fck = dsi_fclk_rate(dsidev); 3212f76ee892STomi Valkeinen 3213f76ee892STomi Valkeinen r = dsi_read_reg(dsidev, DSI_TIMING2); 3214f76ee892STomi Valkeinen r = FLD_MOD(r, 1, 15, 15); /* LP_RX_TO */ 3215f76ee892STomi Valkeinen r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* LP_RX_TO_X16 */ 3216f76ee892STomi Valkeinen r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* LP_RX_TO_X4 */ 3217f76ee892STomi Valkeinen r = FLD_MOD(r, ticks, 12, 0); /* LP_RX_COUNTER */ 3218f76ee892STomi Valkeinen dsi_write_reg(dsidev, DSI_TIMING2, r); 3219f76ee892STomi Valkeinen 3220f76ee892STomi Valkeinen total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1); 3221f76ee892STomi Valkeinen 3222f76ee892STomi Valkeinen DSSDBG("LP_RX_TO %lu ticks (%#x%s%s) = %lu ns\n", 3223f76ee892STomi Valkeinen total_ticks, 3224f76ee892STomi Valkeinen ticks, x4 ? " x4" : "", x16 ? " x16" : "", 3225f76ee892STomi Valkeinen (total_ticks * 1000) / (fck / 1000 / 1000)); 3226f76ee892STomi Valkeinen } 3227f76ee892STomi Valkeinen 3228f76ee892STomi Valkeinen static void dsi_set_ta_timeout(struct platform_device *dsidev, unsigned ticks, 3229f76ee892STomi Valkeinen bool x8, bool x16) 3230f76ee892STomi Valkeinen { 3231f76ee892STomi Valkeinen unsigned long fck; 3232f76ee892STomi Valkeinen unsigned long total_ticks; 3233f76ee892STomi Valkeinen u32 r; 3234f76ee892STomi Valkeinen 3235f76ee892STomi Valkeinen BUG_ON(ticks > 0x1fff); 3236f76ee892STomi Valkeinen 3237f76ee892STomi Valkeinen /* ticks in DSI_FCK */ 3238f76ee892STomi Valkeinen fck = dsi_fclk_rate(dsidev); 3239f76ee892STomi Valkeinen 3240f76ee892STomi Valkeinen r = dsi_read_reg(dsidev, DSI_TIMING1); 3241f76ee892STomi Valkeinen r = FLD_MOD(r, 1, 31, 31); /* TA_TO */ 3242f76ee892STomi Valkeinen r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* TA_TO_X16 */ 3243f76ee892STomi Valkeinen r = FLD_MOD(r, x8 ? 1 : 0, 29, 29); /* TA_TO_X8 */ 3244f76ee892STomi Valkeinen r = FLD_MOD(r, ticks, 28, 16); /* TA_TO_COUNTER */ 3245f76ee892STomi Valkeinen dsi_write_reg(dsidev, DSI_TIMING1, r); 3246f76ee892STomi Valkeinen 3247f76ee892STomi Valkeinen total_ticks = ticks * (x16 ? 16 : 1) * (x8 ? 8 : 1); 3248f76ee892STomi Valkeinen 3249f76ee892STomi Valkeinen DSSDBG("TA_TO %lu ticks (%#x%s%s) = %lu ns\n", 3250f76ee892STomi Valkeinen total_ticks, 3251f76ee892STomi Valkeinen ticks, x8 ? " x8" : "", x16 ? " x16" : "", 3252f76ee892STomi Valkeinen (total_ticks * 1000) / (fck / 1000 / 1000)); 3253f76ee892STomi Valkeinen } 3254f76ee892STomi Valkeinen 3255f76ee892STomi Valkeinen static void dsi_set_stop_state_counter(struct platform_device *dsidev, 3256f76ee892STomi Valkeinen unsigned ticks, bool x4, bool x16) 3257f76ee892STomi Valkeinen { 3258f76ee892STomi Valkeinen unsigned long fck; 3259f76ee892STomi Valkeinen unsigned long total_ticks; 3260f76ee892STomi Valkeinen u32 r; 3261f76ee892STomi Valkeinen 3262f76ee892STomi Valkeinen BUG_ON(ticks > 0x1fff); 3263f76ee892STomi Valkeinen 3264f76ee892STomi Valkeinen /* ticks in DSI_FCK */ 3265f76ee892STomi Valkeinen fck = dsi_fclk_rate(dsidev); 3266f76ee892STomi Valkeinen 3267f76ee892STomi Valkeinen r = dsi_read_reg(dsidev, DSI_TIMING1); 3268f76ee892STomi Valkeinen r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */ 3269f76ee892STomi Valkeinen r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* STOP_STATE_X16_IO */ 3270f76ee892STomi Valkeinen r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* STOP_STATE_X4_IO */ 3271f76ee892STomi Valkeinen r = FLD_MOD(r, ticks, 12, 0); /* STOP_STATE_COUNTER_IO */ 3272f76ee892STomi Valkeinen dsi_write_reg(dsidev, DSI_TIMING1, r); 3273f76ee892STomi Valkeinen 3274f76ee892STomi Valkeinen total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1); 3275f76ee892STomi Valkeinen 3276f76ee892STomi Valkeinen DSSDBG("STOP_STATE_COUNTER %lu ticks (%#x%s%s) = %lu ns\n", 3277f76ee892STomi Valkeinen total_ticks, 3278f76ee892STomi Valkeinen ticks, x4 ? " x4" : "", x16 ? " x16" : "", 3279f76ee892STomi Valkeinen (total_ticks * 1000) / (fck / 1000 / 1000)); 3280f76ee892STomi Valkeinen } 3281f76ee892STomi Valkeinen 3282f76ee892STomi Valkeinen static void dsi_set_hs_tx_timeout(struct platform_device *dsidev, 3283f76ee892STomi Valkeinen unsigned ticks, bool x4, bool x16) 3284f76ee892STomi Valkeinen { 3285f76ee892STomi Valkeinen unsigned long fck; 3286f76ee892STomi Valkeinen unsigned long total_ticks; 3287f76ee892STomi Valkeinen u32 r; 3288f76ee892STomi Valkeinen 3289f76ee892STomi Valkeinen BUG_ON(ticks > 0x1fff); 3290f76ee892STomi Valkeinen 3291f76ee892STomi Valkeinen /* ticks in TxByteClkHS */ 3292f76ee892STomi Valkeinen fck = dsi_get_txbyteclkhs(dsidev); 3293f76ee892STomi Valkeinen 3294f76ee892STomi Valkeinen r = dsi_read_reg(dsidev, DSI_TIMING2); 3295f76ee892STomi Valkeinen r = FLD_MOD(r, 1, 31, 31); /* HS_TX_TO */ 3296f76ee892STomi Valkeinen r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* HS_TX_TO_X16 */ 3297f76ee892STomi Valkeinen r = FLD_MOD(r, x4 ? 1 : 0, 29, 29); /* HS_TX_TO_X8 (4 really) */ 3298f76ee892STomi Valkeinen r = FLD_MOD(r, ticks, 28, 16); /* HS_TX_TO_COUNTER */ 3299f76ee892STomi Valkeinen dsi_write_reg(dsidev, DSI_TIMING2, r); 3300f76ee892STomi Valkeinen 3301f76ee892STomi Valkeinen total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1); 3302f76ee892STomi Valkeinen 3303f76ee892STomi Valkeinen DSSDBG("HS_TX_TO %lu ticks (%#x%s%s) = %lu ns\n", 3304f76ee892STomi Valkeinen total_ticks, 3305f76ee892STomi Valkeinen ticks, x4 ? " x4" : "", x16 ? " x16" : "", 3306f76ee892STomi Valkeinen (total_ticks * 1000) / (fck / 1000 / 1000)); 3307f76ee892STomi Valkeinen } 3308f76ee892STomi Valkeinen 3309f76ee892STomi Valkeinen static void dsi_config_vp_num_line_buffers(struct platform_device *dsidev) 3310f76ee892STomi Valkeinen { 3311f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 3312f76ee892STomi Valkeinen int num_line_buffers; 3313f76ee892STomi Valkeinen 3314f76ee892STomi Valkeinen if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) { 3315f76ee892STomi Valkeinen int bpp = dsi_get_pixel_size(dsi->pix_fmt); 3316f76ee892STomi Valkeinen struct omap_video_timings *timings = &dsi->timings; 3317f76ee892STomi Valkeinen /* 3318f76ee892STomi Valkeinen * Don't use line buffers if width is greater than the video 3319f76ee892STomi Valkeinen * port's line buffer size 3320f76ee892STomi Valkeinen */ 3321f76ee892STomi Valkeinen if (dsi->line_buffer_size <= timings->x_res * bpp / 8) 3322f76ee892STomi Valkeinen num_line_buffers = 0; 3323f76ee892STomi Valkeinen else 3324f76ee892STomi Valkeinen num_line_buffers = 2; 3325f76ee892STomi Valkeinen } else { 3326f76ee892STomi Valkeinen /* Use maximum number of line buffers in command mode */ 3327f76ee892STomi Valkeinen num_line_buffers = 2; 3328f76ee892STomi Valkeinen } 3329f76ee892STomi Valkeinen 3330f76ee892STomi Valkeinen /* LINE_BUFFER */ 3331f76ee892STomi Valkeinen REG_FLD_MOD(dsidev, DSI_CTRL, num_line_buffers, 13, 12); 3332f76ee892STomi Valkeinen } 3333f76ee892STomi Valkeinen 3334f76ee892STomi Valkeinen static void dsi_config_vp_sync_events(struct platform_device *dsidev) 3335f76ee892STomi Valkeinen { 3336f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 3337f76ee892STomi Valkeinen bool sync_end; 3338f76ee892STomi Valkeinen u32 r; 3339f76ee892STomi Valkeinen 3340f76ee892STomi Valkeinen if (dsi->vm_timings.trans_mode == OMAP_DSS_DSI_PULSE_MODE) 3341f76ee892STomi Valkeinen sync_end = true; 3342f76ee892STomi Valkeinen else 3343f76ee892STomi Valkeinen sync_end = false; 3344f76ee892STomi Valkeinen 3345f76ee892STomi Valkeinen r = dsi_read_reg(dsidev, DSI_CTRL); 3346f76ee892STomi Valkeinen r = FLD_MOD(r, 1, 9, 9); /* VP_DE_POL */ 3347f76ee892STomi Valkeinen r = FLD_MOD(r, 1, 10, 10); /* VP_HSYNC_POL */ 3348f76ee892STomi Valkeinen r = FLD_MOD(r, 1, 11, 11); /* VP_VSYNC_POL */ 3349f76ee892STomi Valkeinen r = FLD_MOD(r, 1, 15, 15); /* VP_VSYNC_START */ 3350f76ee892STomi Valkeinen r = FLD_MOD(r, sync_end, 16, 16); /* VP_VSYNC_END */ 3351f76ee892STomi Valkeinen r = FLD_MOD(r, 1, 17, 17); /* VP_HSYNC_START */ 3352f76ee892STomi Valkeinen r = FLD_MOD(r, sync_end, 18, 18); /* VP_HSYNC_END */ 3353f76ee892STomi Valkeinen dsi_write_reg(dsidev, DSI_CTRL, r); 3354f76ee892STomi Valkeinen } 3355f76ee892STomi Valkeinen 3356f76ee892STomi Valkeinen static void dsi_config_blanking_modes(struct platform_device *dsidev) 3357f76ee892STomi Valkeinen { 3358f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 3359f76ee892STomi Valkeinen int blanking_mode = dsi->vm_timings.blanking_mode; 3360f76ee892STomi Valkeinen int hfp_blanking_mode = dsi->vm_timings.hfp_blanking_mode; 3361f76ee892STomi Valkeinen int hbp_blanking_mode = dsi->vm_timings.hbp_blanking_mode; 3362f76ee892STomi Valkeinen int hsa_blanking_mode = dsi->vm_timings.hsa_blanking_mode; 3363f76ee892STomi Valkeinen u32 r; 3364f76ee892STomi Valkeinen 3365f76ee892STomi Valkeinen /* 3366f76ee892STomi Valkeinen * 0 = TX FIFO packets sent or LPS in corresponding blanking periods 3367f76ee892STomi Valkeinen * 1 = Long blanking packets are sent in corresponding blanking periods 3368f76ee892STomi Valkeinen */ 3369f76ee892STomi Valkeinen r = dsi_read_reg(dsidev, DSI_CTRL); 3370f76ee892STomi Valkeinen r = FLD_MOD(r, blanking_mode, 20, 20); /* BLANKING_MODE */ 3371f76ee892STomi Valkeinen r = FLD_MOD(r, hfp_blanking_mode, 21, 21); /* HFP_BLANKING */ 3372f76ee892STomi Valkeinen r = FLD_MOD(r, hbp_blanking_mode, 22, 22); /* HBP_BLANKING */ 3373f76ee892STomi Valkeinen r = FLD_MOD(r, hsa_blanking_mode, 23, 23); /* HSA_BLANKING */ 3374f76ee892STomi Valkeinen dsi_write_reg(dsidev, DSI_CTRL, r); 3375f76ee892STomi Valkeinen } 3376f76ee892STomi Valkeinen 3377f76ee892STomi Valkeinen /* 3378f76ee892STomi Valkeinen * According to section 'HS Command Mode Interleaving' in OMAP TRM, Scenario 3 3379f76ee892STomi Valkeinen * results in maximum transition time for data and clock lanes to enter and 3380f76ee892STomi Valkeinen * exit HS mode. Hence, this is the scenario where the least amount of command 3381f76ee892STomi Valkeinen * mode data can be interleaved. We program the minimum amount of TXBYTECLKHS 3382f76ee892STomi Valkeinen * clock cycles that can be used to interleave command mode data in HS so that 3383f76ee892STomi Valkeinen * all scenarios are satisfied. 3384f76ee892STomi Valkeinen */ 3385f76ee892STomi Valkeinen static int dsi_compute_interleave_hs(int blank, bool ddr_alwon, int enter_hs, 3386f76ee892STomi Valkeinen int exit_hs, int exiths_clk, int ddr_pre, int ddr_post) 3387f76ee892STomi Valkeinen { 3388f76ee892STomi Valkeinen int transition; 3389f76ee892STomi Valkeinen 3390f76ee892STomi Valkeinen /* 3391f76ee892STomi Valkeinen * If DDR_CLK_ALWAYS_ON is set, we need to consider HS mode transition 3392f76ee892STomi Valkeinen * time of data lanes only, if it isn't set, we need to consider HS 3393f76ee892STomi Valkeinen * transition time of both data and clock lanes. HS transition time 3394f76ee892STomi Valkeinen * of Scenario 3 is considered. 3395f76ee892STomi Valkeinen */ 3396f76ee892STomi Valkeinen if (ddr_alwon) { 3397f76ee892STomi Valkeinen transition = enter_hs + exit_hs + max(enter_hs, 2) + 1; 3398f76ee892STomi Valkeinen } else { 3399f76ee892STomi Valkeinen int trans1, trans2; 3400f76ee892STomi Valkeinen trans1 = ddr_pre + enter_hs + exit_hs + max(enter_hs, 2) + 1; 3401f76ee892STomi Valkeinen trans2 = ddr_pre + enter_hs + exiths_clk + ddr_post + ddr_pre + 3402f76ee892STomi Valkeinen enter_hs + 1; 3403f76ee892STomi Valkeinen transition = max(trans1, trans2); 3404f76ee892STomi Valkeinen } 3405f76ee892STomi Valkeinen 3406f76ee892STomi Valkeinen return blank > transition ? blank - transition : 0; 3407f76ee892STomi Valkeinen } 3408f76ee892STomi Valkeinen 3409f76ee892STomi Valkeinen /* 3410f76ee892STomi Valkeinen * According to section 'LP Command Mode Interleaving' in OMAP TRM, Scenario 1 3411f76ee892STomi Valkeinen * results in maximum transition time for data lanes to enter and exit LP mode. 3412f76ee892STomi Valkeinen * Hence, this is the scenario where the least amount of command mode data can 3413f76ee892STomi Valkeinen * be interleaved. We program the minimum amount of bytes that can be 3414f76ee892STomi Valkeinen * interleaved in LP so that all scenarios are satisfied. 3415f76ee892STomi Valkeinen */ 3416f76ee892STomi Valkeinen static int dsi_compute_interleave_lp(int blank, int enter_hs, int exit_hs, 3417f76ee892STomi Valkeinen int lp_clk_div, int tdsi_fclk) 3418f76ee892STomi Valkeinen { 3419f76ee892STomi Valkeinen int trans_lp; /* time required for a LP transition, in TXBYTECLKHS */ 3420f76ee892STomi Valkeinen int tlp_avail; /* time left for interleaving commands, in CLKIN4DDR */ 3421f76ee892STomi Valkeinen int ttxclkesc; /* period of LP transmit escape clock, in CLKIN4DDR */ 3422f76ee892STomi Valkeinen int thsbyte_clk = 16; /* Period of TXBYTECLKHS clock, in CLKIN4DDR */ 3423f76ee892STomi Valkeinen int lp_inter; /* cmd mode data that can be interleaved, in bytes */ 3424f76ee892STomi Valkeinen 3425f76ee892STomi Valkeinen /* maximum LP transition time according to Scenario 1 */ 3426f76ee892STomi Valkeinen trans_lp = exit_hs + max(enter_hs, 2) + 1; 3427f76ee892STomi Valkeinen 3428f76ee892STomi Valkeinen /* CLKIN4DDR = 16 * TXBYTECLKHS */ 3429f76ee892STomi Valkeinen tlp_avail = thsbyte_clk * (blank - trans_lp); 3430f76ee892STomi Valkeinen 3431f76ee892STomi Valkeinen ttxclkesc = tdsi_fclk * lp_clk_div; 3432f76ee892STomi Valkeinen 3433f76ee892STomi Valkeinen lp_inter = ((tlp_avail - 8 * thsbyte_clk - 5 * tdsi_fclk) / ttxclkesc - 3434f76ee892STomi Valkeinen 26) / 16; 3435f76ee892STomi Valkeinen 3436f76ee892STomi Valkeinen return max(lp_inter, 0); 3437f76ee892STomi Valkeinen } 3438f76ee892STomi Valkeinen 3439f76ee892STomi Valkeinen static void dsi_config_cmd_mode_interleaving(struct platform_device *dsidev) 3440f76ee892STomi Valkeinen { 3441f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 3442f76ee892STomi Valkeinen int blanking_mode; 3443f76ee892STomi Valkeinen int hfp_blanking_mode, hbp_blanking_mode, hsa_blanking_mode; 3444f76ee892STomi Valkeinen int hsa, hfp, hbp, width_bytes, bllp, lp_clk_div; 3445f76ee892STomi Valkeinen int ddr_clk_pre, ddr_clk_post, enter_hs_mode_lat, exit_hs_mode_lat; 3446f76ee892STomi Valkeinen int tclk_trail, ths_exit, exiths_clk; 3447f76ee892STomi Valkeinen bool ddr_alwon; 3448f76ee892STomi Valkeinen struct omap_video_timings *timings = &dsi->timings; 3449f76ee892STomi Valkeinen int bpp = dsi_get_pixel_size(dsi->pix_fmt); 3450f76ee892STomi Valkeinen int ndl = dsi->num_lanes_used - 1; 3451f76ee892STomi Valkeinen int dsi_fclk_hsdiv = dsi->user_dsi_cinfo.mX[HSDIV_DSI] + 1; 3452f76ee892STomi Valkeinen int hsa_interleave_hs = 0, hsa_interleave_lp = 0; 3453f76ee892STomi Valkeinen int hfp_interleave_hs = 0, hfp_interleave_lp = 0; 3454f76ee892STomi Valkeinen int hbp_interleave_hs = 0, hbp_interleave_lp = 0; 3455f76ee892STomi Valkeinen int bl_interleave_hs = 0, bl_interleave_lp = 0; 3456f76ee892STomi Valkeinen u32 r; 3457f76ee892STomi Valkeinen 3458f76ee892STomi Valkeinen r = dsi_read_reg(dsidev, DSI_CTRL); 3459f76ee892STomi Valkeinen blanking_mode = FLD_GET(r, 20, 20); 3460f76ee892STomi Valkeinen hfp_blanking_mode = FLD_GET(r, 21, 21); 3461f76ee892STomi Valkeinen hbp_blanking_mode = FLD_GET(r, 22, 22); 3462f76ee892STomi Valkeinen hsa_blanking_mode = FLD_GET(r, 23, 23); 3463f76ee892STomi Valkeinen 3464f76ee892STomi Valkeinen r = dsi_read_reg(dsidev, DSI_VM_TIMING1); 3465f76ee892STomi Valkeinen hbp = FLD_GET(r, 11, 0); 3466f76ee892STomi Valkeinen hfp = FLD_GET(r, 23, 12); 3467f76ee892STomi Valkeinen hsa = FLD_GET(r, 31, 24); 3468f76ee892STomi Valkeinen 3469f76ee892STomi Valkeinen r = dsi_read_reg(dsidev, DSI_CLK_TIMING); 3470f76ee892STomi Valkeinen ddr_clk_post = FLD_GET(r, 7, 0); 3471f76ee892STomi Valkeinen ddr_clk_pre = FLD_GET(r, 15, 8); 3472f76ee892STomi Valkeinen 3473f76ee892STomi Valkeinen r = dsi_read_reg(dsidev, DSI_VM_TIMING7); 3474f76ee892STomi Valkeinen exit_hs_mode_lat = FLD_GET(r, 15, 0); 3475f76ee892STomi Valkeinen enter_hs_mode_lat = FLD_GET(r, 31, 16); 3476f76ee892STomi Valkeinen 3477f76ee892STomi Valkeinen r = dsi_read_reg(dsidev, DSI_CLK_CTRL); 3478f76ee892STomi Valkeinen lp_clk_div = FLD_GET(r, 12, 0); 3479f76ee892STomi Valkeinen ddr_alwon = FLD_GET(r, 13, 13); 3480f76ee892STomi Valkeinen 3481f76ee892STomi Valkeinen r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0); 3482f76ee892STomi Valkeinen ths_exit = FLD_GET(r, 7, 0); 3483f76ee892STomi Valkeinen 3484f76ee892STomi Valkeinen r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1); 3485f76ee892STomi Valkeinen tclk_trail = FLD_GET(r, 15, 8); 3486f76ee892STomi Valkeinen 3487f76ee892STomi Valkeinen exiths_clk = ths_exit + tclk_trail; 3488f76ee892STomi Valkeinen 3489f76ee892STomi Valkeinen width_bytes = DIV_ROUND_UP(timings->x_res * bpp, 8); 3490f76ee892STomi Valkeinen bllp = hbp + hfp + hsa + DIV_ROUND_UP(width_bytes + 6, ndl); 3491f76ee892STomi Valkeinen 3492f76ee892STomi Valkeinen if (!hsa_blanking_mode) { 3493f76ee892STomi Valkeinen hsa_interleave_hs = dsi_compute_interleave_hs(hsa, ddr_alwon, 3494f76ee892STomi Valkeinen enter_hs_mode_lat, exit_hs_mode_lat, 3495f76ee892STomi Valkeinen exiths_clk, ddr_clk_pre, ddr_clk_post); 3496f76ee892STomi Valkeinen hsa_interleave_lp = dsi_compute_interleave_lp(hsa, 3497f76ee892STomi Valkeinen enter_hs_mode_lat, exit_hs_mode_lat, 3498f76ee892STomi Valkeinen lp_clk_div, dsi_fclk_hsdiv); 3499f76ee892STomi Valkeinen } 3500f76ee892STomi Valkeinen 3501f76ee892STomi Valkeinen if (!hfp_blanking_mode) { 3502f76ee892STomi Valkeinen hfp_interleave_hs = dsi_compute_interleave_hs(hfp, ddr_alwon, 3503f76ee892STomi Valkeinen enter_hs_mode_lat, exit_hs_mode_lat, 3504f76ee892STomi Valkeinen exiths_clk, ddr_clk_pre, ddr_clk_post); 3505f76ee892STomi Valkeinen hfp_interleave_lp = dsi_compute_interleave_lp(hfp, 3506f76ee892STomi Valkeinen enter_hs_mode_lat, exit_hs_mode_lat, 3507f76ee892STomi Valkeinen lp_clk_div, dsi_fclk_hsdiv); 3508f76ee892STomi Valkeinen } 3509f76ee892STomi Valkeinen 3510f76ee892STomi Valkeinen if (!hbp_blanking_mode) { 3511f76ee892STomi Valkeinen hbp_interleave_hs = dsi_compute_interleave_hs(hbp, ddr_alwon, 3512f76ee892STomi Valkeinen enter_hs_mode_lat, exit_hs_mode_lat, 3513f76ee892STomi Valkeinen exiths_clk, ddr_clk_pre, ddr_clk_post); 3514f76ee892STomi Valkeinen 3515f76ee892STomi Valkeinen hbp_interleave_lp = dsi_compute_interleave_lp(hbp, 3516f76ee892STomi Valkeinen enter_hs_mode_lat, exit_hs_mode_lat, 3517f76ee892STomi Valkeinen lp_clk_div, dsi_fclk_hsdiv); 3518f76ee892STomi Valkeinen } 3519f76ee892STomi Valkeinen 3520f76ee892STomi Valkeinen if (!blanking_mode) { 3521f76ee892STomi Valkeinen bl_interleave_hs = dsi_compute_interleave_hs(bllp, ddr_alwon, 3522f76ee892STomi Valkeinen enter_hs_mode_lat, exit_hs_mode_lat, 3523f76ee892STomi Valkeinen exiths_clk, ddr_clk_pre, ddr_clk_post); 3524f76ee892STomi Valkeinen 3525f76ee892STomi Valkeinen bl_interleave_lp = dsi_compute_interleave_lp(bllp, 3526f76ee892STomi Valkeinen enter_hs_mode_lat, exit_hs_mode_lat, 3527f76ee892STomi Valkeinen lp_clk_div, dsi_fclk_hsdiv); 3528f76ee892STomi Valkeinen } 3529f76ee892STomi Valkeinen 3530f76ee892STomi Valkeinen DSSDBG("DSI HS interleaving(TXBYTECLKHS) HSA %d, HFP %d, HBP %d, BLLP %d\n", 3531f76ee892STomi Valkeinen hsa_interleave_hs, hfp_interleave_hs, hbp_interleave_hs, 3532f76ee892STomi Valkeinen bl_interleave_hs); 3533f76ee892STomi Valkeinen 3534f76ee892STomi Valkeinen DSSDBG("DSI LP interleaving(bytes) HSA %d, HFP %d, HBP %d, BLLP %d\n", 3535f76ee892STomi Valkeinen hsa_interleave_lp, hfp_interleave_lp, hbp_interleave_lp, 3536f76ee892STomi Valkeinen bl_interleave_lp); 3537f76ee892STomi Valkeinen 3538f76ee892STomi Valkeinen r = dsi_read_reg(dsidev, DSI_VM_TIMING4); 3539f76ee892STomi Valkeinen r = FLD_MOD(r, hsa_interleave_hs, 23, 16); 3540f76ee892STomi Valkeinen r = FLD_MOD(r, hfp_interleave_hs, 15, 8); 3541f76ee892STomi Valkeinen r = FLD_MOD(r, hbp_interleave_hs, 7, 0); 3542f76ee892STomi Valkeinen dsi_write_reg(dsidev, DSI_VM_TIMING4, r); 3543f76ee892STomi Valkeinen 3544f76ee892STomi Valkeinen r = dsi_read_reg(dsidev, DSI_VM_TIMING5); 3545f76ee892STomi Valkeinen r = FLD_MOD(r, hsa_interleave_lp, 23, 16); 3546f76ee892STomi Valkeinen r = FLD_MOD(r, hfp_interleave_lp, 15, 8); 3547f76ee892STomi Valkeinen r = FLD_MOD(r, hbp_interleave_lp, 7, 0); 3548f76ee892STomi Valkeinen dsi_write_reg(dsidev, DSI_VM_TIMING5, r); 3549f76ee892STomi Valkeinen 3550f76ee892STomi Valkeinen r = dsi_read_reg(dsidev, DSI_VM_TIMING6); 3551f76ee892STomi Valkeinen r = FLD_MOD(r, bl_interleave_hs, 31, 15); 3552f76ee892STomi Valkeinen r = FLD_MOD(r, bl_interleave_lp, 16, 0); 3553f76ee892STomi Valkeinen dsi_write_reg(dsidev, DSI_VM_TIMING6, r); 3554f76ee892STomi Valkeinen } 3555f76ee892STomi Valkeinen 3556f76ee892STomi Valkeinen static int dsi_proto_config(struct platform_device *dsidev) 3557f76ee892STomi Valkeinen { 3558f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 3559f76ee892STomi Valkeinen u32 r; 3560f76ee892STomi Valkeinen int buswidth = 0; 3561f76ee892STomi Valkeinen 3562f76ee892STomi Valkeinen dsi_config_tx_fifo(dsidev, DSI_FIFO_SIZE_32, 3563f76ee892STomi Valkeinen DSI_FIFO_SIZE_32, 3564f76ee892STomi Valkeinen DSI_FIFO_SIZE_32, 3565f76ee892STomi Valkeinen DSI_FIFO_SIZE_32); 3566f76ee892STomi Valkeinen 3567f76ee892STomi Valkeinen dsi_config_rx_fifo(dsidev, DSI_FIFO_SIZE_32, 3568f76ee892STomi Valkeinen DSI_FIFO_SIZE_32, 3569f76ee892STomi Valkeinen DSI_FIFO_SIZE_32, 3570f76ee892STomi Valkeinen DSI_FIFO_SIZE_32); 3571f76ee892STomi Valkeinen 3572f76ee892STomi Valkeinen /* XXX what values for the timeouts? */ 3573f76ee892STomi Valkeinen dsi_set_stop_state_counter(dsidev, 0x1000, false, false); 3574f76ee892STomi Valkeinen dsi_set_ta_timeout(dsidev, 0x1fff, true, true); 3575f76ee892STomi Valkeinen dsi_set_lp_rx_timeout(dsidev, 0x1fff, true, true); 3576f76ee892STomi Valkeinen dsi_set_hs_tx_timeout(dsidev, 0x1fff, true, true); 3577f76ee892STomi Valkeinen 3578f76ee892STomi Valkeinen switch (dsi_get_pixel_size(dsi->pix_fmt)) { 3579f76ee892STomi Valkeinen case 16: 3580f76ee892STomi Valkeinen buswidth = 0; 3581f76ee892STomi Valkeinen break; 3582f76ee892STomi Valkeinen case 18: 3583f76ee892STomi Valkeinen buswidth = 1; 3584f76ee892STomi Valkeinen break; 3585f76ee892STomi Valkeinen case 24: 3586f76ee892STomi Valkeinen buswidth = 2; 3587f76ee892STomi Valkeinen break; 3588f76ee892STomi Valkeinen default: 3589f76ee892STomi Valkeinen BUG(); 3590f76ee892STomi Valkeinen return -EINVAL; 3591f76ee892STomi Valkeinen } 3592f76ee892STomi Valkeinen 3593f76ee892STomi Valkeinen r = dsi_read_reg(dsidev, DSI_CTRL); 3594f76ee892STomi Valkeinen r = FLD_MOD(r, 1, 1, 1); /* CS_RX_EN */ 3595f76ee892STomi Valkeinen r = FLD_MOD(r, 1, 2, 2); /* ECC_RX_EN */ 3596f76ee892STomi Valkeinen r = FLD_MOD(r, 1, 3, 3); /* TX_FIFO_ARBITRATION */ 3597f76ee892STomi Valkeinen r = FLD_MOD(r, 1, 4, 4); /* VP_CLK_RATIO, always 1, see errata*/ 3598f76ee892STomi Valkeinen r = FLD_MOD(r, buswidth, 7, 6); /* VP_DATA_BUS_WIDTH */ 3599f76ee892STomi Valkeinen r = FLD_MOD(r, 0, 8, 8); /* VP_CLK_POL */ 3600f76ee892STomi Valkeinen r = FLD_MOD(r, 1, 14, 14); /* TRIGGER_RESET_MODE */ 3601f76ee892STomi Valkeinen r = FLD_MOD(r, 1, 19, 19); /* EOT_ENABLE */ 3602f76ee892STomi Valkeinen if (!dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC)) { 3603f76ee892STomi Valkeinen r = FLD_MOD(r, 1, 24, 24); /* DCS_CMD_ENABLE */ 3604f76ee892STomi Valkeinen /* DCS_CMD_CODE, 1=start, 0=continue */ 3605f76ee892STomi Valkeinen r = FLD_MOD(r, 0, 25, 25); 3606f76ee892STomi Valkeinen } 3607f76ee892STomi Valkeinen 3608f76ee892STomi Valkeinen dsi_write_reg(dsidev, DSI_CTRL, r); 3609f76ee892STomi Valkeinen 3610f76ee892STomi Valkeinen dsi_config_vp_num_line_buffers(dsidev); 3611f76ee892STomi Valkeinen 3612f76ee892STomi Valkeinen if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) { 3613f76ee892STomi Valkeinen dsi_config_vp_sync_events(dsidev); 3614f76ee892STomi Valkeinen dsi_config_blanking_modes(dsidev); 3615f76ee892STomi Valkeinen dsi_config_cmd_mode_interleaving(dsidev); 3616f76ee892STomi Valkeinen } 3617f76ee892STomi Valkeinen 3618f76ee892STomi Valkeinen dsi_vc_initial_config(dsidev, 0); 3619f76ee892STomi Valkeinen dsi_vc_initial_config(dsidev, 1); 3620f76ee892STomi Valkeinen dsi_vc_initial_config(dsidev, 2); 3621f76ee892STomi Valkeinen dsi_vc_initial_config(dsidev, 3); 3622f76ee892STomi Valkeinen 3623f76ee892STomi Valkeinen return 0; 3624f76ee892STomi Valkeinen } 3625f76ee892STomi Valkeinen 3626f76ee892STomi Valkeinen static void dsi_proto_timings(struct platform_device *dsidev) 3627f76ee892STomi Valkeinen { 3628f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 3629*c96da175SSam Ravnborg unsigned tlpx, tclk_zero, tclk_prepare; 3630f76ee892STomi Valkeinen unsigned tclk_pre, tclk_post; 3631f76ee892STomi Valkeinen unsigned ths_prepare, ths_prepare_ths_zero, ths_zero; 3632f76ee892STomi Valkeinen unsigned ths_trail, ths_exit; 3633f76ee892STomi Valkeinen unsigned ddr_clk_pre, ddr_clk_post; 3634f76ee892STomi Valkeinen unsigned enter_hs_mode_lat, exit_hs_mode_lat; 3635f76ee892STomi Valkeinen unsigned ths_eot; 3636f76ee892STomi Valkeinen int ndl = dsi->num_lanes_used - 1; 3637f76ee892STomi Valkeinen u32 r; 3638f76ee892STomi Valkeinen 3639f76ee892STomi Valkeinen r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0); 3640f76ee892STomi Valkeinen ths_prepare = FLD_GET(r, 31, 24); 3641f76ee892STomi Valkeinen ths_prepare_ths_zero = FLD_GET(r, 23, 16); 3642f76ee892STomi Valkeinen ths_zero = ths_prepare_ths_zero - ths_prepare; 3643f76ee892STomi Valkeinen ths_trail = FLD_GET(r, 15, 8); 3644f76ee892STomi Valkeinen ths_exit = FLD_GET(r, 7, 0); 3645f76ee892STomi Valkeinen 3646f76ee892STomi Valkeinen r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1); 3647f76ee892STomi Valkeinen tlpx = FLD_GET(r, 20, 16) * 2; 3648f76ee892STomi Valkeinen tclk_zero = FLD_GET(r, 7, 0); 3649f76ee892STomi Valkeinen 3650f76ee892STomi Valkeinen r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG2); 3651f76ee892STomi Valkeinen tclk_prepare = FLD_GET(r, 7, 0); 3652f76ee892STomi Valkeinen 3653f76ee892STomi Valkeinen /* min 8*UI */ 3654f76ee892STomi Valkeinen tclk_pre = 20; 3655f76ee892STomi Valkeinen /* min 60ns + 52*UI */ 3656f76ee892STomi Valkeinen tclk_post = ns2ddr(dsidev, 60) + 26; 3657f76ee892STomi Valkeinen 3658f76ee892STomi Valkeinen ths_eot = DIV_ROUND_UP(4, ndl); 3659f76ee892STomi Valkeinen 3660f76ee892STomi Valkeinen ddr_clk_pre = DIV_ROUND_UP(tclk_pre + tlpx + tclk_zero + tclk_prepare, 3661f76ee892STomi Valkeinen 4); 3662f76ee892STomi Valkeinen ddr_clk_post = DIV_ROUND_UP(tclk_post + ths_trail, 4) + ths_eot; 3663f76ee892STomi Valkeinen 3664f76ee892STomi Valkeinen BUG_ON(ddr_clk_pre == 0 || ddr_clk_pre > 255); 3665f76ee892STomi Valkeinen BUG_ON(ddr_clk_post == 0 || ddr_clk_post > 255); 3666f76ee892STomi Valkeinen 3667f76ee892STomi Valkeinen r = dsi_read_reg(dsidev, DSI_CLK_TIMING); 3668f76ee892STomi Valkeinen r = FLD_MOD(r, ddr_clk_pre, 15, 8); 3669f76ee892STomi Valkeinen r = FLD_MOD(r, ddr_clk_post, 7, 0); 3670f76ee892STomi Valkeinen dsi_write_reg(dsidev, DSI_CLK_TIMING, r); 3671f76ee892STomi Valkeinen 3672f76ee892STomi Valkeinen DSSDBG("ddr_clk_pre %u, ddr_clk_post %u\n", 3673f76ee892STomi Valkeinen ddr_clk_pre, 3674f76ee892STomi Valkeinen ddr_clk_post); 3675f76ee892STomi Valkeinen 3676f76ee892STomi Valkeinen enter_hs_mode_lat = 1 + DIV_ROUND_UP(tlpx, 4) + 3677f76ee892STomi Valkeinen DIV_ROUND_UP(ths_prepare, 4) + 3678f76ee892STomi Valkeinen DIV_ROUND_UP(ths_zero + 3, 4); 3679f76ee892STomi Valkeinen 3680f76ee892STomi Valkeinen exit_hs_mode_lat = DIV_ROUND_UP(ths_trail + ths_exit, 4) + 1 + ths_eot; 3681f76ee892STomi Valkeinen 3682f76ee892STomi Valkeinen r = FLD_VAL(enter_hs_mode_lat, 31, 16) | 3683f76ee892STomi Valkeinen FLD_VAL(exit_hs_mode_lat, 15, 0); 3684f76ee892STomi Valkeinen dsi_write_reg(dsidev, DSI_VM_TIMING7, r); 3685f76ee892STomi Valkeinen 3686f76ee892STomi Valkeinen DSSDBG("enter_hs_mode_lat %u, exit_hs_mode_lat %u\n", 3687f76ee892STomi Valkeinen enter_hs_mode_lat, exit_hs_mode_lat); 3688f76ee892STomi Valkeinen 3689f76ee892STomi Valkeinen if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) { 3690f76ee892STomi Valkeinen /* TODO: Implement a video mode check_timings function */ 3691f76ee892STomi Valkeinen int hsa = dsi->vm_timings.hsa; 3692f76ee892STomi Valkeinen int hfp = dsi->vm_timings.hfp; 3693f76ee892STomi Valkeinen int hbp = dsi->vm_timings.hbp; 3694f76ee892STomi Valkeinen int vsa = dsi->vm_timings.vsa; 3695f76ee892STomi Valkeinen int vfp = dsi->vm_timings.vfp; 3696f76ee892STomi Valkeinen int vbp = dsi->vm_timings.vbp; 3697f76ee892STomi Valkeinen int window_sync = dsi->vm_timings.window_sync; 3698f76ee892STomi Valkeinen bool hsync_end; 3699f76ee892STomi Valkeinen struct omap_video_timings *timings = &dsi->timings; 3700f76ee892STomi Valkeinen int bpp = dsi_get_pixel_size(dsi->pix_fmt); 3701f76ee892STomi Valkeinen int tl, t_he, width_bytes; 3702f76ee892STomi Valkeinen 3703f76ee892STomi Valkeinen hsync_end = dsi->vm_timings.trans_mode == OMAP_DSS_DSI_PULSE_MODE; 3704f76ee892STomi Valkeinen t_he = hsync_end ? 3705f76ee892STomi Valkeinen ((hsa == 0 && ndl == 3) ? 1 : DIV_ROUND_UP(4, ndl)) : 0; 3706f76ee892STomi Valkeinen 3707f76ee892STomi Valkeinen width_bytes = DIV_ROUND_UP(timings->x_res * bpp, 8); 3708f76ee892STomi Valkeinen 3709f76ee892STomi Valkeinen /* TL = t_HS + HSA + t_HE + HFP + ceil((WC + 6) / NDL) + HBP */ 3710f76ee892STomi Valkeinen tl = DIV_ROUND_UP(4, ndl) + (hsync_end ? hsa : 0) + t_he + hfp + 3711f76ee892STomi Valkeinen DIV_ROUND_UP(width_bytes + 6, ndl) + hbp; 3712f76ee892STomi Valkeinen 3713f76ee892STomi Valkeinen DSSDBG("HBP: %d, HFP: %d, HSA: %d, TL: %d TXBYTECLKHS\n", hbp, 3714f76ee892STomi Valkeinen hfp, hsync_end ? hsa : 0, tl); 3715f76ee892STomi Valkeinen DSSDBG("VBP: %d, VFP: %d, VSA: %d, VACT: %d lines\n", vbp, vfp, 3716f76ee892STomi Valkeinen vsa, timings->y_res); 3717f76ee892STomi Valkeinen 3718f76ee892STomi Valkeinen r = dsi_read_reg(dsidev, DSI_VM_TIMING1); 3719f76ee892STomi Valkeinen r = FLD_MOD(r, hbp, 11, 0); /* HBP */ 3720f76ee892STomi Valkeinen r = FLD_MOD(r, hfp, 23, 12); /* HFP */ 3721f76ee892STomi Valkeinen r = FLD_MOD(r, hsync_end ? hsa : 0, 31, 24); /* HSA */ 3722f76ee892STomi Valkeinen dsi_write_reg(dsidev, DSI_VM_TIMING1, r); 3723f76ee892STomi Valkeinen 3724f76ee892STomi Valkeinen r = dsi_read_reg(dsidev, DSI_VM_TIMING2); 3725f76ee892STomi Valkeinen r = FLD_MOD(r, vbp, 7, 0); /* VBP */ 3726f76ee892STomi Valkeinen r = FLD_MOD(r, vfp, 15, 8); /* VFP */ 3727f76ee892STomi Valkeinen r = FLD_MOD(r, vsa, 23, 16); /* VSA */ 3728f76ee892STomi Valkeinen r = FLD_MOD(r, window_sync, 27, 24); /* WINDOW_SYNC */ 3729f76ee892STomi Valkeinen dsi_write_reg(dsidev, DSI_VM_TIMING2, r); 3730f76ee892STomi Valkeinen 3731f76ee892STomi Valkeinen r = dsi_read_reg(dsidev, DSI_VM_TIMING3); 3732f76ee892STomi Valkeinen r = FLD_MOD(r, timings->y_res, 14, 0); /* VACT */ 3733f76ee892STomi Valkeinen r = FLD_MOD(r, tl, 31, 16); /* TL */ 3734f76ee892STomi Valkeinen dsi_write_reg(dsidev, DSI_VM_TIMING3, r); 3735f76ee892STomi Valkeinen } 3736f76ee892STomi Valkeinen } 3737f76ee892STomi Valkeinen 3738f76ee892STomi Valkeinen static int dsi_configure_pins(struct omap_dss_device *dssdev, 3739f76ee892STomi Valkeinen const struct omap_dsi_pin_config *pin_cfg) 3740f76ee892STomi Valkeinen { 3741f76ee892STomi Valkeinen struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); 3742f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 3743f76ee892STomi Valkeinen int num_pins; 3744f76ee892STomi Valkeinen const int *pins; 3745f76ee892STomi Valkeinen struct dsi_lane_config lanes[DSI_MAX_NR_LANES]; 3746f76ee892STomi Valkeinen int num_lanes; 3747f76ee892STomi Valkeinen int i; 3748f76ee892STomi Valkeinen 3749f76ee892STomi Valkeinen static const enum dsi_lane_function functions[] = { 3750f76ee892STomi Valkeinen DSI_LANE_CLK, 3751f76ee892STomi Valkeinen DSI_LANE_DATA1, 3752f76ee892STomi Valkeinen DSI_LANE_DATA2, 3753f76ee892STomi Valkeinen DSI_LANE_DATA3, 3754f76ee892STomi Valkeinen DSI_LANE_DATA4, 3755f76ee892STomi Valkeinen }; 3756f76ee892STomi Valkeinen 3757f76ee892STomi Valkeinen num_pins = pin_cfg->num_pins; 3758f76ee892STomi Valkeinen pins = pin_cfg->pins; 3759f76ee892STomi Valkeinen 3760f76ee892STomi Valkeinen if (num_pins < 4 || num_pins > dsi->num_lanes_supported * 2 3761f76ee892STomi Valkeinen || num_pins % 2 != 0) 3762f76ee892STomi Valkeinen return -EINVAL; 3763f76ee892STomi Valkeinen 3764f76ee892STomi Valkeinen for (i = 0; i < DSI_MAX_NR_LANES; ++i) 3765f76ee892STomi Valkeinen lanes[i].function = DSI_LANE_UNUSED; 3766f76ee892STomi Valkeinen 3767f76ee892STomi Valkeinen num_lanes = 0; 3768f76ee892STomi Valkeinen 3769f76ee892STomi Valkeinen for (i = 0; i < num_pins; i += 2) { 3770f76ee892STomi Valkeinen u8 lane, pol; 3771f76ee892STomi Valkeinen int dx, dy; 3772f76ee892STomi Valkeinen 3773f76ee892STomi Valkeinen dx = pins[i]; 3774f76ee892STomi Valkeinen dy = pins[i + 1]; 3775f76ee892STomi Valkeinen 3776f76ee892STomi Valkeinen if (dx < 0 || dx >= dsi->num_lanes_supported * 2) 3777f76ee892STomi Valkeinen return -EINVAL; 3778f76ee892STomi Valkeinen 3779f76ee892STomi Valkeinen if (dy < 0 || dy >= dsi->num_lanes_supported * 2) 3780f76ee892STomi Valkeinen return -EINVAL; 3781f76ee892STomi Valkeinen 3782f76ee892STomi Valkeinen if (dx & 1) { 3783f76ee892STomi Valkeinen if (dy != dx - 1) 3784f76ee892STomi Valkeinen return -EINVAL; 3785f76ee892STomi Valkeinen pol = 1; 3786f76ee892STomi Valkeinen } else { 3787f76ee892STomi Valkeinen if (dy != dx + 1) 3788f76ee892STomi Valkeinen return -EINVAL; 3789f76ee892STomi Valkeinen pol = 0; 3790f76ee892STomi Valkeinen } 3791f76ee892STomi Valkeinen 3792f76ee892STomi Valkeinen lane = dx / 2; 3793f76ee892STomi Valkeinen 3794f76ee892STomi Valkeinen lanes[lane].function = functions[i / 2]; 3795f76ee892STomi Valkeinen lanes[lane].polarity = pol; 3796f76ee892STomi Valkeinen num_lanes++; 3797f76ee892STomi Valkeinen } 3798f76ee892STomi Valkeinen 3799f76ee892STomi Valkeinen memcpy(dsi->lanes, lanes, sizeof(dsi->lanes)); 3800f76ee892STomi Valkeinen dsi->num_lanes_used = num_lanes; 3801f76ee892STomi Valkeinen 3802f76ee892STomi Valkeinen return 0; 3803f76ee892STomi Valkeinen } 3804f76ee892STomi Valkeinen 3805f76ee892STomi Valkeinen static int dsi_enable_video_output(struct omap_dss_device *dssdev, int channel) 3806f76ee892STomi Valkeinen { 3807f76ee892STomi Valkeinen struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); 3808f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 3809f76ee892STomi Valkeinen struct omap_overlay_manager *mgr = dsi->output.manager; 3810f76ee892STomi Valkeinen int bpp = dsi_get_pixel_size(dsi->pix_fmt); 3811f76ee892STomi Valkeinen struct omap_dss_device *out = &dsi->output; 3812f76ee892STomi Valkeinen u8 data_type; 3813f76ee892STomi Valkeinen u16 word_count; 3814f76ee892STomi Valkeinen int r; 3815f76ee892STomi Valkeinen 3816f76ee892STomi Valkeinen if (out->manager == NULL) { 3817f76ee892STomi Valkeinen DSSERR("failed to enable display: no output/manager\n"); 3818f76ee892STomi Valkeinen return -ENODEV; 3819f76ee892STomi Valkeinen } 3820f76ee892STomi Valkeinen 3821f76ee892STomi Valkeinen r = dsi_display_init_dispc(dsidev, mgr); 3822f76ee892STomi Valkeinen if (r) 3823f76ee892STomi Valkeinen goto err_init_dispc; 3824f76ee892STomi Valkeinen 3825f76ee892STomi Valkeinen if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) { 3826f76ee892STomi Valkeinen switch (dsi->pix_fmt) { 3827f76ee892STomi Valkeinen case OMAP_DSS_DSI_FMT_RGB888: 3828f76ee892STomi Valkeinen data_type = MIPI_DSI_PACKED_PIXEL_STREAM_24; 3829f76ee892STomi Valkeinen break; 3830f76ee892STomi Valkeinen case OMAP_DSS_DSI_FMT_RGB666: 3831f76ee892STomi Valkeinen data_type = MIPI_DSI_PIXEL_STREAM_3BYTE_18; 3832f76ee892STomi Valkeinen break; 3833f76ee892STomi Valkeinen case OMAP_DSS_DSI_FMT_RGB666_PACKED: 3834f76ee892STomi Valkeinen data_type = MIPI_DSI_PACKED_PIXEL_STREAM_18; 3835f76ee892STomi Valkeinen break; 3836f76ee892STomi Valkeinen case OMAP_DSS_DSI_FMT_RGB565: 3837f76ee892STomi Valkeinen data_type = MIPI_DSI_PACKED_PIXEL_STREAM_16; 3838f76ee892STomi Valkeinen break; 3839f76ee892STomi Valkeinen default: 3840f76ee892STomi Valkeinen r = -EINVAL; 3841f76ee892STomi Valkeinen goto err_pix_fmt; 3842f76ee892STomi Valkeinen } 3843f76ee892STomi Valkeinen 3844f76ee892STomi Valkeinen dsi_if_enable(dsidev, false); 3845f76ee892STomi Valkeinen dsi_vc_enable(dsidev, channel, false); 3846f76ee892STomi Valkeinen 3847f76ee892STomi Valkeinen /* MODE, 1 = video mode */ 3848f76ee892STomi Valkeinen REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 4, 4); 3849f76ee892STomi Valkeinen 3850f76ee892STomi Valkeinen word_count = DIV_ROUND_UP(dsi->timings.x_res * bpp, 8); 3851f76ee892STomi Valkeinen 3852f76ee892STomi Valkeinen dsi_vc_write_long_header(dsidev, channel, data_type, 3853f76ee892STomi Valkeinen word_count, 0); 3854f76ee892STomi Valkeinen 3855f76ee892STomi Valkeinen dsi_vc_enable(dsidev, channel, true); 3856f76ee892STomi Valkeinen dsi_if_enable(dsidev, true); 3857f76ee892STomi Valkeinen } 3858f76ee892STomi Valkeinen 3859f76ee892STomi Valkeinen r = dss_mgr_enable(mgr); 3860f76ee892STomi Valkeinen if (r) 3861f76ee892STomi Valkeinen goto err_mgr_enable; 3862f76ee892STomi Valkeinen 3863f76ee892STomi Valkeinen return 0; 3864f76ee892STomi Valkeinen 3865f76ee892STomi Valkeinen err_mgr_enable: 3866f76ee892STomi Valkeinen if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) { 3867f76ee892STomi Valkeinen dsi_if_enable(dsidev, false); 3868f76ee892STomi Valkeinen dsi_vc_enable(dsidev, channel, false); 3869f76ee892STomi Valkeinen } 3870f76ee892STomi Valkeinen err_pix_fmt: 3871f76ee892STomi Valkeinen dsi_display_uninit_dispc(dsidev, mgr); 3872f76ee892STomi Valkeinen err_init_dispc: 3873f76ee892STomi Valkeinen return r; 3874f76ee892STomi Valkeinen } 3875f76ee892STomi Valkeinen 3876f76ee892STomi Valkeinen static void dsi_disable_video_output(struct omap_dss_device *dssdev, int channel) 3877f76ee892STomi Valkeinen { 3878f76ee892STomi Valkeinen struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); 3879f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 3880f76ee892STomi Valkeinen struct omap_overlay_manager *mgr = dsi->output.manager; 3881f76ee892STomi Valkeinen 3882f76ee892STomi Valkeinen if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) { 3883f76ee892STomi Valkeinen dsi_if_enable(dsidev, false); 3884f76ee892STomi Valkeinen dsi_vc_enable(dsidev, channel, false); 3885f76ee892STomi Valkeinen 3886f76ee892STomi Valkeinen /* MODE, 0 = command mode */ 3887f76ee892STomi Valkeinen REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 0, 4, 4); 3888f76ee892STomi Valkeinen 3889f76ee892STomi Valkeinen dsi_vc_enable(dsidev, channel, true); 3890f76ee892STomi Valkeinen dsi_if_enable(dsidev, true); 3891f76ee892STomi Valkeinen } 3892f76ee892STomi Valkeinen 3893f76ee892STomi Valkeinen dss_mgr_disable(mgr); 3894f76ee892STomi Valkeinen 3895f76ee892STomi Valkeinen dsi_display_uninit_dispc(dsidev, mgr); 3896f76ee892STomi Valkeinen } 3897f76ee892STomi Valkeinen 3898f76ee892STomi Valkeinen static void dsi_update_screen_dispc(struct platform_device *dsidev) 3899f76ee892STomi Valkeinen { 3900f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 3901f76ee892STomi Valkeinen struct omap_overlay_manager *mgr = dsi->output.manager; 3902f76ee892STomi Valkeinen unsigned bytespp; 3903f76ee892STomi Valkeinen unsigned bytespl; 3904f76ee892STomi Valkeinen unsigned bytespf; 3905f76ee892STomi Valkeinen unsigned total_len; 3906f76ee892STomi Valkeinen unsigned packet_payload; 3907f76ee892STomi Valkeinen unsigned packet_len; 3908f76ee892STomi Valkeinen u32 l; 3909f76ee892STomi Valkeinen int r; 3910f76ee892STomi Valkeinen const unsigned channel = dsi->update_channel; 3911f76ee892STomi Valkeinen const unsigned line_buf_size = dsi->line_buffer_size; 3912f76ee892STomi Valkeinen u16 w = dsi->timings.x_res; 3913f76ee892STomi Valkeinen u16 h = dsi->timings.y_res; 3914f76ee892STomi Valkeinen 3915f76ee892STomi Valkeinen DSSDBG("dsi_update_screen_dispc(%dx%d)\n", w, h); 3916f76ee892STomi Valkeinen 3917f76ee892STomi Valkeinen dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_VP); 3918f76ee892STomi Valkeinen 3919f76ee892STomi Valkeinen bytespp = dsi_get_pixel_size(dsi->pix_fmt) / 8; 3920f76ee892STomi Valkeinen bytespl = w * bytespp; 3921f76ee892STomi Valkeinen bytespf = bytespl * h; 3922f76ee892STomi Valkeinen 3923f76ee892STomi Valkeinen /* NOTE: packet_payload has to be equal to N * bytespl, where N is 3924f76ee892STomi Valkeinen * number of lines in a packet. See errata about VP_CLK_RATIO */ 3925f76ee892STomi Valkeinen 3926f76ee892STomi Valkeinen if (bytespf < line_buf_size) 3927f76ee892STomi Valkeinen packet_payload = bytespf; 3928f76ee892STomi Valkeinen else 3929f76ee892STomi Valkeinen packet_payload = (line_buf_size) / bytespl * bytespl; 3930f76ee892STomi Valkeinen 3931f76ee892STomi Valkeinen packet_len = packet_payload + 1; /* 1 byte for DCS cmd */ 3932f76ee892STomi Valkeinen total_len = (bytespf / packet_payload) * packet_len; 3933f76ee892STomi Valkeinen 3934f76ee892STomi Valkeinen if (bytespf % packet_payload) 3935f76ee892STomi Valkeinen total_len += (bytespf % packet_payload) + 1; 3936f76ee892STomi Valkeinen 3937f76ee892STomi Valkeinen l = FLD_VAL(total_len, 23, 0); /* TE_SIZE */ 3938f76ee892STomi Valkeinen dsi_write_reg(dsidev, DSI_VC_TE(channel), l); 3939f76ee892STomi Valkeinen 3940f76ee892STomi Valkeinen dsi_vc_write_long_header(dsidev, channel, MIPI_DSI_DCS_LONG_WRITE, 3941f76ee892STomi Valkeinen packet_len, 0); 3942f76ee892STomi Valkeinen 3943f76ee892STomi Valkeinen if (dsi->te_enabled) 3944f76ee892STomi Valkeinen l = FLD_MOD(l, 1, 30, 30); /* TE_EN */ 3945f76ee892STomi Valkeinen else 3946f76ee892STomi Valkeinen l = FLD_MOD(l, 1, 31, 31); /* TE_START */ 3947f76ee892STomi Valkeinen dsi_write_reg(dsidev, DSI_VC_TE(channel), l); 3948f76ee892STomi Valkeinen 3949f76ee892STomi Valkeinen /* We put SIDLEMODE to no-idle for the duration of the transfer, 3950f76ee892STomi Valkeinen * because DSS interrupts are not capable of waking up the CPU and the 3951f76ee892STomi Valkeinen * framedone interrupt could be delayed for quite a long time. I think 3952f76ee892STomi Valkeinen * the same goes for any DSS interrupts, but for some reason I have not 3953f76ee892STomi Valkeinen * seen the problem anywhere else than here. 3954f76ee892STomi Valkeinen */ 3955f76ee892STomi Valkeinen dispc_disable_sidle(); 3956f76ee892STomi Valkeinen 3957f76ee892STomi Valkeinen dsi_perf_mark_start(dsidev); 3958f76ee892STomi Valkeinen 3959f76ee892STomi Valkeinen r = schedule_delayed_work(&dsi->framedone_timeout_work, 3960f76ee892STomi Valkeinen msecs_to_jiffies(250)); 3961f76ee892STomi Valkeinen BUG_ON(r == 0); 3962f76ee892STomi Valkeinen 3963f76ee892STomi Valkeinen dss_mgr_set_timings(mgr, &dsi->timings); 3964f76ee892STomi Valkeinen 3965f76ee892STomi Valkeinen dss_mgr_start_update(mgr); 3966f76ee892STomi Valkeinen 3967f76ee892STomi Valkeinen if (dsi->te_enabled) { 3968f76ee892STomi Valkeinen /* disable LP_RX_TO, so that we can receive TE. Time to wait 3969f76ee892STomi Valkeinen * for TE is longer than the timer allows */ 3970f76ee892STomi Valkeinen REG_FLD_MOD(dsidev, DSI_TIMING2, 0, 15, 15); /* LP_RX_TO */ 3971f76ee892STomi Valkeinen 3972f76ee892STomi Valkeinen dsi_vc_send_bta(dsidev, channel); 3973f76ee892STomi Valkeinen 3974f76ee892STomi Valkeinen #ifdef DSI_CATCH_MISSING_TE 3975f76ee892STomi Valkeinen mod_timer(&dsi->te_timer, jiffies + msecs_to_jiffies(250)); 3976f76ee892STomi Valkeinen #endif 3977f76ee892STomi Valkeinen } 3978f76ee892STomi Valkeinen } 3979f76ee892STomi Valkeinen 3980f76ee892STomi Valkeinen #ifdef DSI_CATCH_MISSING_TE 39816c789357SKees Cook static void dsi_te_timeout(struct timer_list *unused) 3982f76ee892STomi Valkeinen { 3983f76ee892STomi Valkeinen DSSERR("TE not received for 250ms!\n"); 3984f76ee892STomi Valkeinen } 3985f76ee892STomi Valkeinen #endif 3986f76ee892STomi Valkeinen 3987f76ee892STomi Valkeinen static void dsi_handle_framedone(struct platform_device *dsidev, int error) 3988f76ee892STomi Valkeinen { 3989f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 3990f76ee892STomi Valkeinen 3991f76ee892STomi Valkeinen /* SIDLEMODE back to smart-idle */ 3992f76ee892STomi Valkeinen dispc_enable_sidle(); 3993f76ee892STomi Valkeinen 3994f76ee892STomi Valkeinen if (dsi->te_enabled) { 3995f76ee892STomi Valkeinen /* enable LP_RX_TO again after the TE */ 3996f76ee892STomi Valkeinen REG_FLD_MOD(dsidev, DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */ 3997f76ee892STomi Valkeinen } 3998f76ee892STomi Valkeinen 3999f76ee892STomi Valkeinen dsi->framedone_callback(error, dsi->framedone_data); 4000f76ee892STomi Valkeinen 4001f76ee892STomi Valkeinen if (!error) 4002f76ee892STomi Valkeinen dsi_perf_show(dsidev, "DISPC"); 4003f76ee892STomi Valkeinen } 4004f76ee892STomi Valkeinen 4005f76ee892STomi Valkeinen static void dsi_framedone_timeout_work_callback(struct work_struct *work) 4006f76ee892STomi Valkeinen { 4007f76ee892STomi Valkeinen struct dsi_data *dsi = container_of(work, struct dsi_data, 4008f76ee892STomi Valkeinen framedone_timeout_work.work); 4009f76ee892STomi Valkeinen /* XXX While extremely unlikely, we could get FRAMEDONE interrupt after 4010f76ee892STomi Valkeinen * 250ms which would conflict with this timeout work. What should be 4011f76ee892STomi Valkeinen * done is first cancel the transfer on the HW, and then cancel the 4012f76ee892STomi Valkeinen * possibly scheduled framedone work. However, cancelling the transfer 4013f76ee892STomi Valkeinen * on the HW is buggy, and would probably require resetting the whole 4014f76ee892STomi Valkeinen * DSI */ 4015f76ee892STomi Valkeinen 4016f76ee892STomi Valkeinen DSSERR("Framedone not received for 250ms!\n"); 4017f76ee892STomi Valkeinen 4018f76ee892STomi Valkeinen dsi_handle_framedone(dsi->pdev, -ETIMEDOUT); 4019f76ee892STomi Valkeinen } 4020f76ee892STomi Valkeinen 4021f76ee892STomi Valkeinen static void dsi_framedone_irq_callback(void *data) 4022f76ee892STomi Valkeinen { 4023f76ee892STomi Valkeinen struct platform_device *dsidev = (struct platform_device *) data; 4024f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 4025f76ee892STomi Valkeinen 4026f76ee892STomi Valkeinen /* Note: We get FRAMEDONE when DISPC has finished sending pixels and 4027f76ee892STomi Valkeinen * turns itself off. However, DSI still has the pixels in its buffers, 4028f76ee892STomi Valkeinen * and is sending the data. 4029f76ee892STomi Valkeinen */ 4030f76ee892STomi Valkeinen 4031f76ee892STomi Valkeinen cancel_delayed_work(&dsi->framedone_timeout_work); 4032f76ee892STomi Valkeinen 4033f76ee892STomi Valkeinen dsi_handle_framedone(dsidev, 0); 4034f76ee892STomi Valkeinen } 4035f76ee892STomi Valkeinen 4036f76ee892STomi Valkeinen static int dsi_update(struct omap_dss_device *dssdev, int channel, 4037f76ee892STomi Valkeinen void (*callback)(int, void *), void *data) 4038f76ee892STomi Valkeinen { 4039f76ee892STomi Valkeinen struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); 4040f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 4041f76ee892STomi Valkeinen 4042f76ee892STomi Valkeinen dsi_perf_mark_setup(dsidev); 4043f76ee892STomi Valkeinen 4044f76ee892STomi Valkeinen dsi->update_channel = channel; 4045f76ee892STomi Valkeinen 4046f76ee892STomi Valkeinen dsi->framedone_callback = callback; 4047f76ee892STomi Valkeinen dsi->framedone_data = data; 4048f76ee892STomi Valkeinen 4049f76ee892STomi Valkeinen #ifdef DSI_PERF_MEASURE 4050*c96da175SSam Ravnborg dsi->update_bytes = dsi->timings.x_res * dsi->timings.y_res * 4051f76ee892STomi Valkeinen dsi_get_pixel_size(dsi->pix_fmt) / 8; 4052f76ee892STomi Valkeinen #endif 4053f76ee892STomi Valkeinen dsi_update_screen_dispc(dsidev); 4054f76ee892STomi Valkeinen 4055f76ee892STomi Valkeinen return 0; 4056f76ee892STomi Valkeinen } 4057f76ee892STomi Valkeinen 4058f76ee892STomi Valkeinen /* Display funcs */ 4059f76ee892STomi Valkeinen 4060f76ee892STomi Valkeinen static int dsi_configure_dispc_clocks(struct platform_device *dsidev) 4061f76ee892STomi Valkeinen { 4062f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 4063f76ee892STomi Valkeinen struct dispc_clock_info dispc_cinfo; 4064f76ee892STomi Valkeinen int r; 4065f76ee892STomi Valkeinen unsigned long fck; 4066f76ee892STomi Valkeinen 4067f76ee892STomi Valkeinen fck = dsi_get_pll_hsdiv_dispc_rate(dsidev); 4068f76ee892STomi Valkeinen 4069f76ee892STomi Valkeinen dispc_cinfo.lck_div = dsi->user_dispc_cinfo.lck_div; 4070f76ee892STomi Valkeinen dispc_cinfo.pck_div = dsi->user_dispc_cinfo.pck_div; 4071f76ee892STomi Valkeinen 4072f76ee892STomi Valkeinen r = dispc_calc_clock_rates(fck, &dispc_cinfo); 4073f76ee892STomi Valkeinen if (r) { 4074f76ee892STomi Valkeinen DSSERR("Failed to calc dispc clocks\n"); 4075f76ee892STomi Valkeinen return r; 4076f76ee892STomi Valkeinen } 4077f76ee892STomi Valkeinen 4078f76ee892STomi Valkeinen dsi->mgr_config.clock_info = dispc_cinfo; 4079f76ee892STomi Valkeinen 4080f76ee892STomi Valkeinen return 0; 4081f76ee892STomi Valkeinen } 4082f76ee892STomi Valkeinen 4083f76ee892STomi Valkeinen static int dsi_display_init_dispc(struct platform_device *dsidev, 4084f76ee892STomi Valkeinen struct omap_overlay_manager *mgr) 4085f76ee892STomi Valkeinen { 4086f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 4087f76ee892STomi Valkeinen int r; 4088f76ee892STomi Valkeinen 4089f76ee892STomi Valkeinen dss_select_lcd_clk_source(mgr->id, dsi->module_id == 0 ? 4090f76ee892STomi Valkeinen OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC : 4091f76ee892STomi Valkeinen OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC); 4092f76ee892STomi Valkeinen 4093f76ee892STomi Valkeinen if (dsi->mode == OMAP_DSS_DSI_CMD_MODE) { 4094f76ee892STomi Valkeinen r = dss_mgr_register_framedone_handler(mgr, 4095f76ee892STomi Valkeinen dsi_framedone_irq_callback, dsidev); 4096f76ee892STomi Valkeinen if (r) { 4097f76ee892STomi Valkeinen DSSERR("can't register FRAMEDONE handler\n"); 4098f76ee892STomi Valkeinen goto err; 4099f76ee892STomi Valkeinen } 4100f76ee892STomi Valkeinen 4101f76ee892STomi Valkeinen dsi->mgr_config.stallmode = true; 4102f76ee892STomi Valkeinen dsi->mgr_config.fifohandcheck = true; 4103f76ee892STomi Valkeinen } else { 4104f76ee892STomi Valkeinen dsi->mgr_config.stallmode = false; 4105f76ee892STomi Valkeinen dsi->mgr_config.fifohandcheck = false; 4106f76ee892STomi Valkeinen } 4107f76ee892STomi Valkeinen 4108f76ee892STomi Valkeinen /* 4109f76ee892STomi Valkeinen * override interlace, logic level and edge related parameters in 4110f76ee892STomi Valkeinen * omap_video_timings with default values 4111f76ee892STomi Valkeinen */ 4112f76ee892STomi Valkeinen dsi->timings.interlace = false; 4113f76ee892STomi Valkeinen dsi->timings.hsync_level = OMAPDSS_SIG_ACTIVE_HIGH; 4114f76ee892STomi Valkeinen dsi->timings.vsync_level = OMAPDSS_SIG_ACTIVE_HIGH; 4115f76ee892STomi Valkeinen dsi->timings.data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE; 4116f76ee892STomi Valkeinen dsi->timings.de_level = OMAPDSS_SIG_ACTIVE_HIGH; 4117f76ee892STomi Valkeinen dsi->timings.sync_pclk_edge = OMAPDSS_DRIVE_SIG_FALLING_EDGE; 4118f76ee892STomi Valkeinen 4119f76ee892STomi Valkeinen dss_mgr_set_timings(mgr, &dsi->timings); 4120f76ee892STomi Valkeinen 4121f76ee892STomi Valkeinen r = dsi_configure_dispc_clocks(dsidev); 4122f76ee892STomi Valkeinen if (r) 4123f76ee892STomi Valkeinen goto err1; 4124f76ee892STomi Valkeinen 4125f76ee892STomi Valkeinen dsi->mgr_config.io_pad_mode = DSS_IO_PAD_MODE_BYPASS; 4126f76ee892STomi Valkeinen dsi->mgr_config.video_port_width = 4127f76ee892STomi Valkeinen dsi_get_pixel_size(dsi->pix_fmt); 4128f76ee892STomi Valkeinen dsi->mgr_config.lcden_sig_polarity = 0; 4129f76ee892STomi Valkeinen 4130f76ee892STomi Valkeinen dss_mgr_set_lcd_config(mgr, &dsi->mgr_config); 4131f76ee892STomi Valkeinen 4132f76ee892STomi Valkeinen return 0; 4133f76ee892STomi Valkeinen err1: 4134f76ee892STomi Valkeinen if (dsi->mode == OMAP_DSS_DSI_CMD_MODE) 4135f76ee892STomi Valkeinen dss_mgr_unregister_framedone_handler(mgr, 4136f76ee892STomi Valkeinen dsi_framedone_irq_callback, dsidev); 4137f76ee892STomi Valkeinen err: 4138f76ee892STomi Valkeinen dss_select_lcd_clk_source(mgr->id, OMAP_DSS_CLK_SRC_FCK); 4139f76ee892STomi Valkeinen return r; 4140f76ee892STomi Valkeinen } 4141f76ee892STomi Valkeinen 4142f76ee892STomi Valkeinen static void dsi_display_uninit_dispc(struct platform_device *dsidev, 4143f76ee892STomi Valkeinen struct omap_overlay_manager *mgr) 4144f76ee892STomi Valkeinen { 4145f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 4146f76ee892STomi Valkeinen 4147f76ee892STomi Valkeinen if (dsi->mode == OMAP_DSS_DSI_CMD_MODE) 4148f76ee892STomi Valkeinen dss_mgr_unregister_framedone_handler(mgr, 4149f76ee892STomi Valkeinen dsi_framedone_irq_callback, dsidev); 4150f76ee892STomi Valkeinen 4151f76ee892STomi Valkeinen dss_select_lcd_clk_source(mgr->id, OMAP_DSS_CLK_SRC_FCK); 4152f76ee892STomi Valkeinen } 4153f76ee892STomi Valkeinen 4154f76ee892STomi Valkeinen static int dsi_configure_dsi_clocks(struct platform_device *dsidev) 4155f76ee892STomi Valkeinen { 4156f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 4157f76ee892STomi Valkeinen struct dss_pll_clock_info cinfo; 4158f76ee892STomi Valkeinen int r; 4159f76ee892STomi Valkeinen 4160f76ee892STomi Valkeinen cinfo = dsi->user_dsi_cinfo; 4161f76ee892STomi Valkeinen 4162f76ee892STomi Valkeinen r = dss_pll_set_config(&dsi->pll, &cinfo); 4163f76ee892STomi Valkeinen if (r) { 4164f76ee892STomi Valkeinen DSSERR("Failed to set dsi clocks\n"); 4165f76ee892STomi Valkeinen return r; 4166f76ee892STomi Valkeinen } 4167f76ee892STomi Valkeinen 4168f76ee892STomi Valkeinen return 0; 4169f76ee892STomi Valkeinen } 4170f76ee892STomi Valkeinen 4171f76ee892STomi Valkeinen static int dsi_display_init_dsi(struct platform_device *dsidev) 4172f76ee892STomi Valkeinen { 4173f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 4174f76ee892STomi Valkeinen int r; 4175f76ee892STomi Valkeinen 4176f76ee892STomi Valkeinen r = dss_pll_enable(&dsi->pll); 4177f76ee892STomi Valkeinen if (r) 4178f76ee892STomi Valkeinen goto err0; 4179f76ee892STomi Valkeinen 4180f76ee892STomi Valkeinen r = dsi_configure_dsi_clocks(dsidev); 4181f76ee892STomi Valkeinen if (r) 4182f76ee892STomi Valkeinen goto err1; 4183f76ee892STomi Valkeinen 4184f76ee892STomi Valkeinen dss_select_dsi_clk_source(dsi->module_id, dsi->module_id == 0 ? 4185f76ee892STomi Valkeinen OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI : 4186f76ee892STomi Valkeinen OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI); 4187f76ee892STomi Valkeinen 4188f76ee892STomi Valkeinen DSSDBG("PLL OK\n"); 4189f76ee892STomi Valkeinen 4190f76ee892STomi Valkeinen r = dsi_cio_init(dsidev); 4191f76ee892STomi Valkeinen if (r) 4192f76ee892STomi Valkeinen goto err2; 4193f76ee892STomi Valkeinen 4194f76ee892STomi Valkeinen _dsi_print_reset_status(dsidev); 4195f76ee892STomi Valkeinen 4196f76ee892STomi Valkeinen dsi_proto_timings(dsidev); 4197f76ee892STomi Valkeinen dsi_set_lp_clk_divisor(dsidev); 4198f76ee892STomi Valkeinen 4199f76ee892STomi Valkeinen if (1) 4200f76ee892STomi Valkeinen _dsi_print_reset_status(dsidev); 4201f76ee892STomi Valkeinen 4202f76ee892STomi Valkeinen r = dsi_proto_config(dsidev); 4203f76ee892STomi Valkeinen if (r) 4204f76ee892STomi Valkeinen goto err3; 4205f76ee892STomi Valkeinen 4206f76ee892STomi Valkeinen /* enable interface */ 4207f76ee892STomi Valkeinen dsi_vc_enable(dsidev, 0, 1); 4208f76ee892STomi Valkeinen dsi_vc_enable(dsidev, 1, 1); 4209f76ee892STomi Valkeinen dsi_vc_enable(dsidev, 2, 1); 4210f76ee892STomi Valkeinen dsi_vc_enable(dsidev, 3, 1); 4211f76ee892STomi Valkeinen dsi_if_enable(dsidev, 1); 4212f76ee892STomi Valkeinen dsi_force_tx_stop_mode_io(dsidev); 4213f76ee892STomi Valkeinen 4214f76ee892STomi Valkeinen return 0; 4215f76ee892STomi Valkeinen err3: 4216f76ee892STomi Valkeinen dsi_cio_uninit(dsidev); 4217f76ee892STomi Valkeinen err2: 4218f76ee892STomi Valkeinen dss_select_dsi_clk_source(dsi->module_id, OMAP_DSS_CLK_SRC_FCK); 4219f76ee892STomi Valkeinen err1: 4220f76ee892STomi Valkeinen dss_pll_disable(&dsi->pll); 4221f76ee892STomi Valkeinen err0: 4222f76ee892STomi Valkeinen return r; 4223f76ee892STomi Valkeinen } 4224f76ee892STomi Valkeinen 4225f76ee892STomi Valkeinen static void dsi_display_uninit_dsi(struct platform_device *dsidev, 4226f76ee892STomi Valkeinen bool disconnect_lanes, bool enter_ulps) 4227f76ee892STomi Valkeinen { 4228f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 4229f76ee892STomi Valkeinen 4230f76ee892STomi Valkeinen if (enter_ulps && !dsi->ulps_enabled) 4231f76ee892STomi Valkeinen dsi_enter_ulps(dsidev); 4232f76ee892STomi Valkeinen 4233f76ee892STomi Valkeinen /* disable interface */ 4234f76ee892STomi Valkeinen dsi_if_enable(dsidev, 0); 4235f76ee892STomi Valkeinen dsi_vc_enable(dsidev, 0, 0); 4236f76ee892STomi Valkeinen dsi_vc_enable(dsidev, 1, 0); 4237f76ee892STomi Valkeinen dsi_vc_enable(dsidev, 2, 0); 4238f76ee892STomi Valkeinen dsi_vc_enable(dsidev, 3, 0); 4239f76ee892STomi Valkeinen 4240f76ee892STomi Valkeinen dss_select_dsi_clk_source(dsi->module_id, OMAP_DSS_CLK_SRC_FCK); 4241f76ee892STomi Valkeinen dsi_cio_uninit(dsidev); 4242f76ee892STomi Valkeinen dsi_pll_uninit(dsidev, disconnect_lanes); 4243f76ee892STomi Valkeinen } 4244f76ee892STomi Valkeinen 4245f76ee892STomi Valkeinen static int dsi_display_enable(struct omap_dss_device *dssdev) 4246f76ee892STomi Valkeinen { 4247f76ee892STomi Valkeinen struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); 4248f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 4249f76ee892STomi Valkeinen int r = 0; 4250f76ee892STomi Valkeinen 4251f76ee892STomi Valkeinen DSSDBG("dsi_display_enable\n"); 4252f76ee892STomi Valkeinen 4253f76ee892STomi Valkeinen WARN_ON(!dsi_bus_is_locked(dsidev)); 4254f76ee892STomi Valkeinen 4255f76ee892STomi Valkeinen mutex_lock(&dsi->lock); 4256f76ee892STomi Valkeinen 4257f76ee892STomi Valkeinen r = dsi_runtime_get(dsidev); 4258f76ee892STomi Valkeinen if (r) 4259f76ee892STomi Valkeinen goto err_get_dsi; 4260f76ee892STomi Valkeinen 4261f76ee892STomi Valkeinen _dsi_initialize_irq(dsidev); 4262f76ee892STomi Valkeinen 4263f76ee892STomi Valkeinen r = dsi_display_init_dsi(dsidev); 4264f76ee892STomi Valkeinen if (r) 4265f76ee892STomi Valkeinen goto err_init_dsi; 4266f76ee892STomi Valkeinen 4267f76ee892STomi Valkeinen mutex_unlock(&dsi->lock); 4268f76ee892STomi Valkeinen 4269f76ee892STomi Valkeinen return 0; 4270f76ee892STomi Valkeinen 4271f76ee892STomi Valkeinen err_init_dsi: 4272f76ee892STomi Valkeinen dsi_runtime_put(dsidev); 4273f76ee892STomi Valkeinen err_get_dsi: 4274f76ee892STomi Valkeinen mutex_unlock(&dsi->lock); 4275f76ee892STomi Valkeinen DSSDBG("dsi_display_enable FAILED\n"); 4276f76ee892STomi Valkeinen return r; 4277f76ee892STomi Valkeinen } 4278f76ee892STomi Valkeinen 4279f76ee892STomi Valkeinen static void dsi_display_disable(struct omap_dss_device *dssdev, 4280f76ee892STomi Valkeinen bool disconnect_lanes, bool enter_ulps) 4281f76ee892STomi Valkeinen { 4282f76ee892STomi Valkeinen struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); 4283f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 4284f76ee892STomi Valkeinen 4285f76ee892STomi Valkeinen DSSDBG("dsi_display_disable\n"); 4286f76ee892STomi Valkeinen 4287f76ee892STomi Valkeinen WARN_ON(!dsi_bus_is_locked(dsidev)); 4288f76ee892STomi Valkeinen 4289f76ee892STomi Valkeinen mutex_lock(&dsi->lock); 4290f76ee892STomi Valkeinen 4291f76ee892STomi Valkeinen dsi_sync_vc(dsidev, 0); 4292f76ee892STomi Valkeinen dsi_sync_vc(dsidev, 1); 4293f76ee892STomi Valkeinen dsi_sync_vc(dsidev, 2); 4294f76ee892STomi Valkeinen dsi_sync_vc(dsidev, 3); 4295f76ee892STomi Valkeinen 4296f76ee892STomi Valkeinen dsi_display_uninit_dsi(dsidev, disconnect_lanes, enter_ulps); 4297f76ee892STomi Valkeinen 4298f76ee892STomi Valkeinen dsi_runtime_put(dsidev); 4299f76ee892STomi Valkeinen 4300f76ee892STomi Valkeinen mutex_unlock(&dsi->lock); 4301f76ee892STomi Valkeinen } 4302f76ee892STomi Valkeinen 4303f76ee892STomi Valkeinen static int dsi_enable_te(struct omap_dss_device *dssdev, bool enable) 4304f76ee892STomi Valkeinen { 4305f76ee892STomi Valkeinen struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); 4306f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 4307f76ee892STomi Valkeinen 4308f76ee892STomi Valkeinen dsi->te_enabled = enable; 4309f76ee892STomi Valkeinen return 0; 4310f76ee892STomi Valkeinen } 4311f76ee892STomi Valkeinen 4312f76ee892STomi Valkeinen #ifdef PRINT_VERBOSE_VM_TIMINGS 4313f76ee892STomi Valkeinen static void print_dsi_vm(const char *str, 4314f76ee892STomi Valkeinen const struct omap_dss_dsi_videomode_timings *t) 4315f76ee892STomi Valkeinen { 4316f76ee892STomi Valkeinen unsigned long byteclk = t->hsclk / 4; 4317f76ee892STomi Valkeinen int bl, wc, pps, tot; 4318f76ee892STomi Valkeinen 4319f76ee892STomi Valkeinen wc = DIV_ROUND_UP(t->hact * t->bitspp, 8); 4320f76ee892STomi Valkeinen pps = DIV_ROUND_UP(wc + 6, t->ndl); /* pixel packet size */ 4321f76ee892STomi Valkeinen bl = t->hss + t->hsa + t->hse + t->hbp + t->hfp; 4322f76ee892STomi Valkeinen tot = bl + pps; 4323f76ee892STomi Valkeinen 4324f76ee892STomi Valkeinen #define TO_DSI_T(x) ((u32)div64_u64((u64)x * 1000000000llu, byteclk)) 4325f76ee892STomi Valkeinen 4326f76ee892STomi Valkeinen pr_debug("%s bck %lu, %u/%u/%u/%u/%u/%u = %u+%u = %u, " 4327f76ee892STomi Valkeinen "%u/%u/%u/%u/%u/%u = %u + %u = %u\n", 4328f76ee892STomi Valkeinen str, 4329f76ee892STomi Valkeinen byteclk, 4330f76ee892STomi Valkeinen t->hss, t->hsa, t->hse, t->hbp, pps, t->hfp, 4331f76ee892STomi Valkeinen bl, pps, tot, 4332f76ee892STomi Valkeinen TO_DSI_T(t->hss), 4333f76ee892STomi Valkeinen TO_DSI_T(t->hsa), 4334f76ee892STomi Valkeinen TO_DSI_T(t->hse), 4335f76ee892STomi Valkeinen TO_DSI_T(t->hbp), 4336f76ee892STomi Valkeinen TO_DSI_T(pps), 4337f76ee892STomi Valkeinen TO_DSI_T(t->hfp), 4338f76ee892STomi Valkeinen 4339f76ee892STomi Valkeinen TO_DSI_T(bl), 4340f76ee892STomi Valkeinen TO_DSI_T(pps), 4341f76ee892STomi Valkeinen 4342f76ee892STomi Valkeinen TO_DSI_T(tot)); 4343f76ee892STomi Valkeinen #undef TO_DSI_T 4344f76ee892STomi Valkeinen } 4345f76ee892STomi Valkeinen 4346f76ee892STomi Valkeinen static void print_dispc_vm(const char *str, const struct omap_video_timings *t) 4347f76ee892STomi Valkeinen { 4348f76ee892STomi Valkeinen unsigned long pck = t->pixelclock; 4349f76ee892STomi Valkeinen int hact, bl, tot; 4350f76ee892STomi Valkeinen 4351f76ee892STomi Valkeinen hact = t->x_res; 4352f76ee892STomi Valkeinen bl = t->hsw + t->hbp + t->hfp; 4353f76ee892STomi Valkeinen tot = hact + bl; 4354f76ee892STomi Valkeinen 4355f76ee892STomi Valkeinen #define TO_DISPC_T(x) ((u32)div64_u64((u64)x * 1000000000llu, pck)) 4356f76ee892STomi Valkeinen 4357f76ee892STomi Valkeinen pr_debug("%s pck %lu, %u/%u/%u/%u = %u+%u = %u, " 4358f76ee892STomi Valkeinen "%u/%u/%u/%u = %u + %u = %u\n", 4359f76ee892STomi Valkeinen str, 4360f76ee892STomi Valkeinen pck, 4361f76ee892STomi Valkeinen t->hsw, t->hbp, hact, t->hfp, 4362f76ee892STomi Valkeinen bl, hact, tot, 4363f76ee892STomi Valkeinen TO_DISPC_T(t->hsw), 4364f76ee892STomi Valkeinen TO_DISPC_T(t->hbp), 4365f76ee892STomi Valkeinen TO_DISPC_T(hact), 4366f76ee892STomi Valkeinen TO_DISPC_T(t->hfp), 4367f76ee892STomi Valkeinen TO_DISPC_T(bl), 4368f76ee892STomi Valkeinen TO_DISPC_T(hact), 4369f76ee892STomi Valkeinen TO_DISPC_T(tot)); 4370f76ee892STomi Valkeinen #undef TO_DISPC_T 4371f76ee892STomi Valkeinen } 4372f76ee892STomi Valkeinen 4373f76ee892STomi Valkeinen /* note: this is not quite accurate */ 4374f76ee892STomi Valkeinen static void print_dsi_dispc_vm(const char *str, 4375f76ee892STomi Valkeinen const struct omap_dss_dsi_videomode_timings *t) 4376f76ee892STomi Valkeinen { 4377f76ee892STomi Valkeinen struct omap_video_timings vm = { 0 }; 4378f76ee892STomi Valkeinen unsigned long byteclk = t->hsclk / 4; 4379f76ee892STomi Valkeinen unsigned long pck; 4380f76ee892STomi Valkeinen u64 dsi_tput; 4381f76ee892STomi Valkeinen int dsi_hact, dsi_htot; 4382f76ee892STomi Valkeinen 4383f76ee892STomi Valkeinen dsi_tput = (u64)byteclk * t->ndl * 8; 4384f76ee892STomi Valkeinen pck = (u32)div64_u64(dsi_tput, t->bitspp); 4385f76ee892STomi Valkeinen dsi_hact = DIV_ROUND_UP(DIV_ROUND_UP(t->hact * t->bitspp, 8) + 6, t->ndl); 4386f76ee892STomi Valkeinen dsi_htot = t->hss + t->hsa + t->hse + t->hbp + dsi_hact + t->hfp; 4387f76ee892STomi Valkeinen 4388f76ee892STomi Valkeinen vm.pixelclock = pck; 4389f76ee892STomi Valkeinen vm.hsw = div64_u64((u64)(t->hsa + t->hse) * pck, byteclk); 4390f76ee892STomi Valkeinen vm.hbp = div64_u64((u64)t->hbp * pck, byteclk); 4391f76ee892STomi Valkeinen vm.hfp = div64_u64((u64)t->hfp * pck, byteclk); 4392f76ee892STomi Valkeinen vm.x_res = t->hact; 4393f76ee892STomi Valkeinen 4394f76ee892STomi Valkeinen print_dispc_vm(str, &vm); 4395f76ee892STomi Valkeinen } 4396f76ee892STomi Valkeinen #endif /* PRINT_VERBOSE_VM_TIMINGS */ 4397f76ee892STomi Valkeinen 4398f76ee892STomi Valkeinen static bool dsi_cm_calc_dispc_cb(int lckd, int pckd, unsigned long lck, 4399f76ee892STomi Valkeinen unsigned long pck, void *data) 4400f76ee892STomi Valkeinen { 4401f76ee892STomi Valkeinen struct dsi_clk_calc_ctx *ctx = data; 4402f76ee892STomi Valkeinen struct omap_video_timings *t = &ctx->dispc_vm; 4403f76ee892STomi Valkeinen 4404f76ee892STomi Valkeinen ctx->dispc_cinfo.lck_div = lckd; 4405f76ee892STomi Valkeinen ctx->dispc_cinfo.pck_div = pckd; 4406f76ee892STomi Valkeinen ctx->dispc_cinfo.lck = lck; 4407f76ee892STomi Valkeinen ctx->dispc_cinfo.pck = pck; 4408f76ee892STomi Valkeinen 4409f76ee892STomi Valkeinen *t = *ctx->config->timings; 4410f76ee892STomi Valkeinen t->pixelclock = pck; 4411f76ee892STomi Valkeinen t->x_res = ctx->config->timings->x_res; 4412f76ee892STomi Valkeinen t->y_res = ctx->config->timings->y_res; 4413f76ee892STomi Valkeinen t->hsw = t->hfp = t->hbp = t->vsw = 1; 4414f76ee892STomi Valkeinen t->vfp = t->vbp = 0; 4415f76ee892STomi Valkeinen 4416f76ee892STomi Valkeinen return true; 4417f76ee892STomi Valkeinen } 4418f76ee892STomi Valkeinen 4419f76ee892STomi Valkeinen static bool dsi_cm_calc_hsdiv_cb(int m_dispc, unsigned long dispc, 4420f76ee892STomi Valkeinen void *data) 4421f76ee892STomi Valkeinen { 4422f76ee892STomi Valkeinen struct dsi_clk_calc_ctx *ctx = data; 4423f76ee892STomi Valkeinen 4424f76ee892STomi Valkeinen ctx->dsi_cinfo.mX[HSDIV_DISPC] = m_dispc; 4425f76ee892STomi Valkeinen ctx->dsi_cinfo.clkout[HSDIV_DISPC] = dispc; 4426f76ee892STomi Valkeinen 4427f76ee892STomi Valkeinen return dispc_div_calc(dispc, ctx->req_pck_min, ctx->req_pck_max, 4428f76ee892STomi Valkeinen dsi_cm_calc_dispc_cb, ctx); 4429f76ee892STomi Valkeinen } 4430f76ee892STomi Valkeinen 4431f76ee892STomi Valkeinen static bool dsi_cm_calc_pll_cb(int n, int m, unsigned long fint, 4432f76ee892STomi Valkeinen unsigned long clkdco, void *data) 4433f76ee892STomi Valkeinen { 4434f76ee892STomi Valkeinen struct dsi_clk_calc_ctx *ctx = data; 4435f76ee892STomi Valkeinen 4436f76ee892STomi Valkeinen ctx->dsi_cinfo.n = n; 4437f76ee892STomi Valkeinen ctx->dsi_cinfo.m = m; 4438f76ee892STomi Valkeinen ctx->dsi_cinfo.fint = fint; 4439f76ee892STomi Valkeinen ctx->dsi_cinfo.clkdco = clkdco; 4440f76ee892STomi Valkeinen 4441f76ee892STomi Valkeinen return dss_pll_hsdiv_calc(ctx->pll, clkdco, ctx->req_pck_min, 4442f76ee892STomi Valkeinen dss_feat_get_param_max(FEAT_PARAM_DSS_FCK), 4443f76ee892STomi Valkeinen dsi_cm_calc_hsdiv_cb, ctx); 4444f76ee892STomi Valkeinen } 4445f76ee892STomi Valkeinen 4446f76ee892STomi Valkeinen static bool dsi_cm_calc(struct dsi_data *dsi, 4447f76ee892STomi Valkeinen const struct omap_dss_dsi_config *cfg, 4448f76ee892STomi Valkeinen struct dsi_clk_calc_ctx *ctx) 4449f76ee892STomi Valkeinen { 4450f76ee892STomi Valkeinen unsigned long clkin; 4451f76ee892STomi Valkeinen int bitspp, ndl; 4452f76ee892STomi Valkeinen unsigned long pll_min, pll_max; 4453f76ee892STomi Valkeinen unsigned long pck, txbyteclk; 4454f76ee892STomi Valkeinen 4455f76ee892STomi Valkeinen clkin = clk_get_rate(dsi->pll.clkin); 4456f76ee892STomi Valkeinen bitspp = dsi_get_pixel_size(cfg->pixel_format); 4457f76ee892STomi Valkeinen ndl = dsi->num_lanes_used - 1; 4458f76ee892STomi Valkeinen 4459f76ee892STomi Valkeinen /* 4460f76ee892STomi Valkeinen * Here we should calculate minimum txbyteclk to be able to send the 4461f76ee892STomi Valkeinen * frame in time, and also to handle TE. That's not very simple, though, 4462f76ee892STomi Valkeinen * especially as we go to LP between each pixel packet due to HW 4463f76ee892STomi Valkeinen * "feature". So let's just estimate very roughly and multiply by 1.5. 4464f76ee892STomi Valkeinen */ 4465f76ee892STomi Valkeinen pck = cfg->timings->pixelclock; 4466f76ee892STomi Valkeinen pck = pck * 3 / 2; 4467f76ee892STomi Valkeinen txbyteclk = pck * bitspp / 8 / ndl; 4468f76ee892STomi Valkeinen 4469f76ee892STomi Valkeinen memset(ctx, 0, sizeof(*ctx)); 4470f76ee892STomi Valkeinen ctx->dsidev = dsi->pdev; 4471f76ee892STomi Valkeinen ctx->pll = &dsi->pll; 4472f76ee892STomi Valkeinen ctx->config = cfg; 4473f76ee892STomi Valkeinen ctx->req_pck_min = pck; 4474f76ee892STomi Valkeinen ctx->req_pck_nom = pck; 4475f76ee892STomi Valkeinen ctx->req_pck_max = pck * 3 / 2; 4476f76ee892STomi Valkeinen 4477f76ee892STomi Valkeinen pll_min = max(cfg->hs_clk_min * 4, txbyteclk * 4 * 4); 4478f76ee892STomi Valkeinen pll_max = cfg->hs_clk_max * 4; 4479f76ee892STomi Valkeinen 4480f76ee892STomi Valkeinen return dss_pll_calc(ctx->pll, clkin, 4481f76ee892STomi Valkeinen pll_min, pll_max, 4482f76ee892STomi Valkeinen dsi_cm_calc_pll_cb, ctx); 4483f76ee892STomi Valkeinen } 4484f76ee892STomi Valkeinen 4485f76ee892STomi Valkeinen static bool dsi_vm_calc_blanking(struct dsi_clk_calc_ctx *ctx) 4486f76ee892STomi Valkeinen { 4487f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(ctx->dsidev); 4488f76ee892STomi Valkeinen const struct omap_dss_dsi_config *cfg = ctx->config; 4489f76ee892STomi Valkeinen int bitspp = dsi_get_pixel_size(cfg->pixel_format); 4490f76ee892STomi Valkeinen int ndl = dsi->num_lanes_used - 1; 4491f76ee892STomi Valkeinen unsigned long hsclk = ctx->dsi_cinfo.clkdco / 4; 4492f76ee892STomi Valkeinen unsigned long byteclk = hsclk / 4; 4493f76ee892STomi Valkeinen 4494f76ee892STomi Valkeinen unsigned long dispc_pck, req_pck_min, req_pck_nom, req_pck_max; 4495f76ee892STomi Valkeinen int xres; 4496f76ee892STomi Valkeinen int panel_htot, panel_hbl; /* pixels */ 4497f76ee892STomi Valkeinen int dispc_htot, dispc_hbl; /* pixels */ 4498f76ee892STomi Valkeinen int dsi_htot, dsi_hact, dsi_hbl, hss, hse; /* byteclks */ 4499f76ee892STomi Valkeinen int hfp, hsa, hbp; 4500f76ee892STomi Valkeinen const struct omap_video_timings *req_vm; 4501f76ee892STomi Valkeinen struct omap_video_timings *dispc_vm; 4502f76ee892STomi Valkeinen struct omap_dss_dsi_videomode_timings *dsi_vm; 4503f76ee892STomi Valkeinen u64 dsi_tput, dispc_tput; 4504f76ee892STomi Valkeinen 4505f76ee892STomi Valkeinen dsi_tput = (u64)byteclk * ndl * 8; 4506f76ee892STomi Valkeinen 4507f76ee892STomi Valkeinen req_vm = cfg->timings; 4508f76ee892STomi Valkeinen req_pck_min = ctx->req_pck_min; 4509f76ee892STomi Valkeinen req_pck_max = ctx->req_pck_max; 4510f76ee892STomi Valkeinen req_pck_nom = ctx->req_pck_nom; 4511f76ee892STomi Valkeinen 4512f76ee892STomi Valkeinen dispc_pck = ctx->dispc_cinfo.pck; 4513f76ee892STomi Valkeinen dispc_tput = (u64)dispc_pck * bitspp; 4514f76ee892STomi Valkeinen 4515f76ee892STomi Valkeinen xres = req_vm->x_res; 4516f76ee892STomi Valkeinen 4517f76ee892STomi Valkeinen panel_hbl = req_vm->hfp + req_vm->hbp + req_vm->hsw; 4518f76ee892STomi Valkeinen panel_htot = xres + panel_hbl; 4519f76ee892STomi Valkeinen 4520f76ee892STomi Valkeinen dsi_hact = DIV_ROUND_UP(DIV_ROUND_UP(xres * bitspp, 8) + 6, ndl); 4521f76ee892STomi Valkeinen 4522f76ee892STomi Valkeinen /* 4523f76ee892STomi Valkeinen * When there are no line buffers, DISPC and DSI must have the 4524f76ee892STomi Valkeinen * same tput. Otherwise DISPC tput needs to be higher than DSI's. 4525f76ee892STomi Valkeinen */ 4526f76ee892STomi Valkeinen if (dsi->line_buffer_size < xres * bitspp / 8) { 4527f76ee892STomi Valkeinen if (dispc_tput != dsi_tput) 4528f76ee892STomi Valkeinen return false; 4529f76ee892STomi Valkeinen } else { 4530f76ee892STomi Valkeinen if (dispc_tput < dsi_tput) 4531f76ee892STomi Valkeinen return false; 4532f76ee892STomi Valkeinen } 4533f76ee892STomi Valkeinen 4534f76ee892STomi Valkeinen /* DSI tput must be over the min requirement */ 4535f76ee892STomi Valkeinen if (dsi_tput < (u64)bitspp * req_pck_min) 4536f76ee892STomi Valkeinen return false; 4537f76ee892STomi Valkeinen 4538f76ee892STomi Valkeinen /* When non-burst mode, DSI tput must be below max requirement. */ 4539f76ee892STomi Valkeinen if (cfg->trans_mode != OMAP_DSS_DSI_BURST_MODE) { 4540f76ee892STomi Valkeinen if (dsi_tput > (u64)bitspp * req_pck_max) 4541f76ee892STomi Valkeinen return false; 4542f76ee892STomi Valkeinen } 4543f76ee892STomi Valkeinen 4544f76ee892STomi Valkeinen hss = DIV_ROUND_UP(4, ndl); 4545f76ee892STomi Valkeinen 4546f76ee892STomi Valkeinen if (cfg->trans_mode == OMAP_DSS_DSI_PULSE_MODE) { 4547f76ee892STomi Valkeinen if (ndl == 3 && req_vm->hsw == 0) 4548f76ee892STomi Valkeinen hse = 1; 4549f76ee892STomi Valkeinen else 4550f76ee892STomi Valkeinen hse = DIV_ROUND_UP(4, ndl); 4551f76ee892STomi Valkeinen } else { 4552f76ee892STomi Valkeinen hse = 0; 4553f76ee892STomi Valkeinen } 4554f76ee892STomi Valkeinen 4555f76ee892STomi Valkeinen /* DSI htot to match the panel's nominal pck */ 4556f76ee892STomi Valkeinen dsi_htot = div64_u64((u64)panel_htot * byteclk, req_pck_nom); 4557f76ee892STomi Valkeinen 4558f76ee892STomi Valkeinen /* fail if there would be no time for blanking */ 4559f76ee892STomi Valkeinen if (dsi_htot < hss + hse + dsi_hact) 4560f76ee892STomi Valkeinen return false; 4561f76ee892STomi Valkeinen 4562f76ee892STomi Valkeinen /* total DSI blanking needed to achieve panel's TL */ 4563f76ee892STomi Valkeinen dsi_hbl = dsi_htot - dsi_hact; 4564f76ee892STomi Valkeinen 4565f76ee892STomi Valkeinen /* DISPC htot to match the DSI TL */ 4566f76ee892STomi Valkeinen dispc_htot = div64_u64((u64)dsi_htot * dispc_pck, byteclk); 4567f76ee892STomi Valkeinen 4568f76ee892STomi Valkeinen /* verify that the DSI and DISPC TLs are the same */ 4569f76ee892STomi Valkeinen if ((u64)dsi_htot * dispc_pck != (u64)dispc_htot * byteclk) 4570f76ee892STomi Valkeinen return false; 4571f76ee892STomi Valkeinen 4572f76ee892STomi Valkeinen dispc_hbl = dispc_htot - xres; 4573f76ee892STomi Valkeinen 4574f76ee892STomi Valkeinen /* setup DSI videomode */ 4575f76ee892STomi Valkeinen 4576f76ee892STomi Valkeinen dsi_vm = &ctx->dsi_vm; 4577f76ee892STomi Valkeinen memset(dsi_vm, 0, sizeof(*dsi_vm)); 4578f76ee892STomi Valkeinen 4579f76ee892STomi Valkeinen dsi_vm->hsclk = hsclk; 4580f76ee892STomi Valkeinen 4581f76ee892STomi Valkeinen dsi_vm->ndl = ndl; 4582f76ee892STomi Valkeinen dsi_vm->bitspp = bitspp; 4583f76ee892STomi Valkeinen 4584f76ee892STomi Valkeinen if (cfg->trans_mode != OMAP_DSS_DSI_PULSE_MODE) { 4585f76ee892STomi Valkeinen hsa = 0; 4586f76ee892STomi Valkeinen } else if (ndl == 3 && req_vm->hsw == 0) { 4587f76ee892STomi Valkeinen hsa = 0; 4588f76ee892STomi Valkeinen } else { 4589f76ee892STomi Valkeinen hsa = div64_u64((u64)req_vm->hsw * byteclk, req_pck_nom); 4590f76ee892STomi Valkeinen hsa = max(hsa - hse, 1); 4591f76ee892STomi Valkeinen } 4592f76ee892STomi Valkeinen 4593f76ee892STomi Valkeinen hbp = div64_u64((u64)req_vm->hbp * byteclk, req_pck_nom); 4594f76ee892STomi Valkeinen hbp = max(hbp, 1); 4595f76ee892STomi Valkeinen 4596f76ee892STomi Valkeinen hfp = dsi_hbl - (hss + hsa + hse + hbp); 4597f76ee892STomi Valkeinen if (hfp < 1) { 4598f76ee892STomi Valkeinen int t; 4599f76ee892STomi Valkeinen /* we need to take cycles from hbp */ 4600f76ee892STomi Valkeinen 4601f76ee892STomi Valkeinen t = 1 - hfp; 4602f76ee892STomi Valkeinen hbp = max(hbp - t, 1); 4603f76ee892STomi Valkeinen hfp = dsi_hbl - (hss + hsa + hse + hbp); 4604f76ee892STomi Valkeinen 4605f76ee892STomi Valkeinen if (hfp < 1 && hsa > 0) { 4606f76ee892STomi Valkeinen /* we need to take cycles from hsa */ 4607f76ee892STomi Valkeinen t = 1 - hfp; 4608f76ee892STomi Valkeinen hsa = max(hsa - t, 1); 4609f76ee892STomi Valkeinen hfp = dsi_hbl - (hss + hsa + hse + hbp); 4610f76ee892STomi Valkeinen } 4611f76ee892STomi Valkeinen } 4612f76ee892STomi Valkeinen 4613f76ee892STomi Valkeinen if (hfp < 1) 4614f76ee892STomi Valkeinen return false; 4615f76ee892STomi Valkeinen 4616f76ee892STomi Valkeinen dsi_vm->hss = hss; 4617f76ee892STomi Valkeinen dsi_vm->hsa = hsa; 4618f76ee892STomi Valkeinen dsi_vm->hse = hse; 4619f76ee892STomi Valkeinen dsi_vm->hbp = hbp; 4620f76ee892STomi Valkeinen dsi_vm->hact = xres; 4621f76ee892STomi Valkeinen dsi_vm->hfp = hfp; 4622f76ee892STomi Valkeinen 4623f76ee892STomi Valkeinen dsi_vm->vsa = req_vm->vsw; 4624f76ee892STomi Valkeinen dsi_vm->vbp = req_vm->vbp; 4625f76ee892STomi Valkeinen dsi_vm->vact = req_vm->y_res; 4626f76ee892STomi Valkeinen dsi_vm->vfp = req_vm->vfp; 4627f76ee892STomi Valkeinen 4628f76ee892STomi Valkeinen dsi_vm->trans_mode = cfg->trans_mode; 4629f76ee892STomi Valkeinen 4630f76ee892STomi Valkeinen dsi_vm->blanking_mode = 0; 4631f76ee892STomi Valkeinen dsi_vm->hsa_blanking_mode = 1; 4632f76ee892STomi Valkeinen dsi_vm->hfp_blanking_mode = 1; 4633f76ee892STomi Valkeinen dsi_vm->hbp_blanking_mode = 1; 4634f76ee892STomi Valkeinen 4635f76ee892STomi Valkeinen dsi_vm->ddr_clk_always_on = cfg->ddr_clk_always_on; 4636f76ee892STomi Valkeinen dsi_vm->window_sync = 4; 4637f76ee892STomi Valkeinen 4638f76ee892STomi Valkeinen /* setup DISPC videomode */ 4639f76ee892STomi Valkeinen 4640f76ee892STomi Valkeinen dispc_vm = &ctx->dispc_vm; 4641f76ee892STomi Valkeinen *dispc_vm = *req_vm; 4642f76ee892STomi Valkeinen dispc_vm->pixelclock = dispc_pck; 4643f76ee892STomi Valkeinen 4644f76ee892STomi Valkeinen if (cfg->trans_mode == OMAP_DSS_DSI_PULSE_MODE) { 4645f76ee892STomi Valkeinen hsa = div64_u64((u64)req_vm->hsw * dispc_pck, 4646f76ee892STomi Valkeinen req_pck_nom); 4647f76ee892STomi Valkeinen hsa = max(hsa, 1); 4648f76ee892STomi Valkeinen } else { 4649f76ee892STomi Valkeinen hsa = 1; 4650f76ee892STomi Valkeinen } 4651f76ee892STomi Valkeinen 4652f76ee892STomi Valkeinen hbp = div64_u64((u64)req_vm->hbp * dispc_pck, req_pck_nom); 4653f76ee892STomi Valkeinen hbp = max(hbp, 1); 4654f76ee892STomi Valkeinen 4655f76ee892STomi Valkeinen hfp = dispc_hbl - hsa - hbp; 4656f76ee892STomi Valkeinen if (hfp < 1) { 4657f76ee892STomi Valkeinen int t; 4658f76ee892STomi Valkeinen /* we need to take cycles from hbp */ 4659f76ee892STomi Valkeinen 4660f76ee892STomi Valkeinen t = 1 - hfp; 4661f76ee892STomi Valkeinen hbp = max(hbp - t, 1); 4662f76ee892STomi Valkeinen hfp = dispc_hbl - hsa - hbp; 4663f76ee892STomi Valkeinen 4664f76ee892STomi Valkeinen if (hfp < 1) { 4665f76ee892STomi Valkeinen /* we need to take cycles from hsa */ 4666f76ee892STomi Valkeinen t = 1 - hfp; 4667f76ee892STomi Valkeinen hsa = max(hsa - t, 1); 4668f76ee892STomi Valkeinen hfp = dispc_hbl - hsa - hbp; 4669f76ee892STomi Valkeinen } 4670f76ee892STomi Valkeinen } 4671f76ee892STomi Valkeinen 4672f76ee892STomi Valkeinen if (hfp < 1) 4673f76ee892STomi Valkeinen return false; 4674f76ee892STomi Valkeinen 4675f76ee892STomi Valkeinen dispc_vm->hfp = hfp; 4676f76ee892STomi Valkeinen dispc_vm->hsw = hsa; 4677f76ee892STomi Valkeinen dispc_vm->hbp = hbp; 4678f76ee892STomi Valkeinen 4679f76ee892STomi Valkeinen return true; 4680f76ee892STomi Valkeinen } 4681f76ee892STomi Valkeinen 4682f76ee892STomi Valkeinen 4683f76ee892STomi Valkeinen static bool dsi_vm_calc_dispc_cb(int lckd, int pckd, unsigned long lck, 4684f76ee892STomi Valkeinen unsigned long pck, void *data) 4685f76ee892STomi Valkeinen { 4686f76ee892STomi Valkeinen struct dsi_clk_calc_ctx *ctx = data; 4687f76ee892STomi Valkeinen 4688f76ee892STomi Valkeinen ctx->dispc_cinfo.lck_div = lckd; 4689f76ee892STomi Valkeinen ctx->dispc_cinfo.pck_div = pckd; 4690f76ee892STomi Valkeinen ctx->dispc_cinfo.lck = lck; 4691f76ee892STomi Valkeinen ctx->dispc_cinfo.pck = pck; 4692f76ee892STomi Valkeinen 4693f76ee892STomi Valkeinen if (dsi_vm_calc_blanking(ctx) == false) 4694f76ee892STomi Valkeinen return false; 4695f76ee892STomi Valkeinen 4696f76ee892STomi Valkeinen #ifdef PRINT_VERBOSE_VM_TIMINGS 4697f76ee892STomi Valkeinen print_dispc_vm("dispc", &ctx->dispc_vm); 4698f76ee892STomi Valkeinen print_dsi_vm("dsi ", &ctx->dsi_vm); 4699f76ee892STomi Valkeinen print_dispc_vm("req ", ctx->config->timings); 4700f76ee892STomi Valkeinen print_dsi_dispc_vm("act ", &ctx->dsi_vm); 4701f76ee892STomi Valkeinen #endif 4702f76ee892STomi Valkeinen 4703f76ee892STomi Valkeinen return true; 4704f76ee892STomi Valkeinen } 4705f76ee892STomi Valkeinen 4706f76ee892STomi Valkeinen static bool dsi_vm_calc_hsdiv_cb(int m_dispc, unsigned long dispc, 4707f76ee892STomi Valkeinen void *data) 4708f76ee892STomi Valkeinen { 4709f76ee892STomi Valkeinen struct dsi_clk_calc_ctx *ctx = data; 4710f76ee892STomi Valkeinen unsigned long pck_max; 4711f76ee892STomi Valkeinen 4712f76ee892STomi Valkeinen ctx->dsi_cinfo.mX[HSDIV_DISPC] = m_dispc; 4713f76ee892STomi Valkeinen ctx->dsi_cinfo.clkout[HSDIV_DISPC] = dispc; 4714f76ee892STomi Valkeinen 4715f76ee892STomi Valkeinen /* 4716f76ee892STomi Valkeinen * In burst mode we can let the dispc pck be arbitrarily high, but it 4717f76ee892STomi Valkeinen * limits our scaling abilities. So for now, don't aim too high. 4718f76ee892STomi Valkeinen */ 4719f76ee892STomi Valkeinen 4720f76ee892STomi Valkeinen if (ctx->config->trans_mode == OMAP_DSS_DSI_BURST_MODE) 4721f76ee892STomi Valkeinen pck_max = ctx->req_pck_max + 10000000; 4722f76ee892STomi Valkeinen else 4723f76ee892STomi Valkeinen pck_max = ctx->req_pck_max; 4724f76ee892STomi Valkeinen 4725f76ee892STomi Valkeinen return dispc_div_calc(dispc, ctx->req_pck_min, pck_max, 4726f76ee892STomi Valkeinen dsi_vm_calc_dispc_cb, ctx); 4727f76ee892STomi Valkeinen } 4728f76ee892STomi Valkeinen 4729f76ee892STomi Valkeinen static bool dsi_vm_calc_pll_cb(int n, int m, unsigned long fint, 4730f76ee892STomi Valkeinen unsigned long clkdco, void *data) 4731f76ee892STomi Valkeinen { 4732f76ee892STomi Valkeinen struct dsi_clk_calc_ctx *ctx = data; 4733f76ee892STomi Valkeinen 4734f76ee892STomi Valkeinen ctx->dsi_cinfo.n = n; 4735f76ee892STomi Valkeinen ctx->dsi_cinfo.m = m; 4736f76ee892STomi Valkeinen ctx->dsi_cinfo.fint = fint; 4737f76ee892STomi Valkeinen ctx->dsi_cinfo.clkdco = clkdco; 4738f76ee892STomi Valkeinen 4739f76ee892STomi Valkeinen return dss_pll_hsdiv_calc(ctx->pll, clkdco, ctx->req_pck_min, 4740f76ee892STomi Valkeinen dss_feat_get_param_max(FEAT_PARAM_DSS_FCK), 4741f76ee892STomi Valkeinen dsi_vm_calc_hsdiv_cb, ctx); 4742f76ee892STomi Valkeinen } 4743f76ee892STomi Valkeinen 4744f76ee892STomi Valkeinen static bool dsi_vm_calc(struct dsi_data *dsi, 4745f76ee892STomi Valkeinen const struct omap_dss_dsi_config *cfg, 4746f76ee892STomi Valkeinen struct dsi_clk_calc_ctx *ctx) 4747f76ee892STomi Valkeinen { 4748f76ee892STomi Valkeinen const struct omap_video_timings *t = cfg->timings; 4749f76ee892STomi Valkeinen unsigned long clkin; 4750f76ee892STomi Valkeinen unsigned long pll_min; 4751f76ee892STomi Valkeinen unsigned long pll_max; 4752f76ee892STomi Valkeinen int ndl = dsi->num_lanes_used - 1; 4753f76ee892STomi Valkeinen int bitspp = dsi_get_pixel_size(cfg->pixel_format); 4754f76ee892STomi Valkeinen unsigned long byteclk_min; 4755f76ee892STomi Valkeinen 4756f76ee892STomi Valkeinen clkin = clk_get_rate(dsi->pll.clkin); 4757f76ee892STomi Valkeinen 4758f76ee892STomi Valkeinen memset(ctx, 0, sizeof(*ctx)); 4759f76ee892STomi Valkeinen ctx->dsidev = dsi->pdev; 4760f76ee892STomi Valkeinen ctx->pll = &dsi->pll; 4761f76ee892STomi Valkeinen ctx->config = cfg; 4762f76ee892STomi Valkeinen 4763f76ee892STomi Valkeinen /* these limits should come from the panel driver */ 4764f76ee892STomi Valkeinen ctx->req_pck_min = t->pixelclock - 1000; 4765f76ee892STomi Valkeinen ctx->req_pck_nom = t->pixelclock; 4766f76ee892STomi Valkeinen ctx->req_pck_max = t->pixelclock + 1000; 4767f76ee892STomi Valkeinen 4768f76ee892STomi Valkeinen byteclk_min = div64_u64((u64)ctx->req_pck_min * bitspp, ndl * 8); 4769f76ee892STomi Valkeinen pll_min = max(cfg->hs_clk_min * 4, byteclk_min * 4 * 4); 4770f76ee892STomi Valkeinen 4771f76ee892STomi Valkeinen if (cfg->trans_mode == OMAP_DSS_DSI_BURST_MODE) { 4772f76ee892STomi Valkeinen pll_max = cfg->hs_clk_max * 4; 4773f76ee892STomi Valkeinen } else { 4774f76ee892STomi Valkeinen unsigned long byteclk_max; 4775f76ee892STomi Valkeinen byteclk_max = div64_u64((u64)ctx->req_pck_max * bitspp, 4776f76ee892STomi Valkeinen ndl * 8); 4777f76ee892STomi Valkeinen 4778f76ee892STomi Valkeinen pll_max = byteclk_max * 4 * 4; 4779f76ee892STomi Valkeinen } 4780f76ee892STomi Valkeinen 4781f76ee892STomi Valkeinen return dss_pll_calc(ctx->pll, clkin, 4782f76ee892STomi Valkeinen pll_min, pll_max, 4783f76ee892STomi Valkeinen dsi_vm_calc_pll_cb, ctx); 4784f76ee892STomi Valkeinen } 4785f76ee892STomi Valkeinen 4786f76ee892STomi Valkeinen static int dsi_set_config(struct omap_dss_device *dssdev, 4787f76ee892STomi Valkeinen const struct omap_dss_dsi_config *config) 4788f76ee892STomi Valkeinen { 4789f76ee892STomi Valkeinen struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); 4790f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 4791f76ee892STomi Valkeinen struct dsi_clk_calc_ctx ctx; 4792f76ee892STomi Valkeinen bool ok; 4793f76ee892STomi Valkeinen int r; 4794f76ee892STomi Valkeinen 4795f76ee892STomi Valkeinen mutex_lock(&dsi->lock); 4796f76ee892STomi Valkeinen 4797f76ee892STomi Valkeinen dsi->pix_fmt = config->pixel_format; 4798f76ee892STomi Valkeinen dsi->mode = config->mode; 4799f76ee892STomi Valkeinen 4800f76ee892STomi Valkeinen if (config->mode == OMAP_DSS_DSI_VIDEO_MODE) 4801f76ee892STomi Valkeinen ok = dsi_vm_calc(dsi, config, &ctx); 4802f76ee892STomi Valkeinen else 4803f76ee892STomi Valkeinen ok = dsi_cm_calc(dsi, config, &ctx); 4804f76ee892STomi Valkeinen 4805f76ee892STomi Valkeinen if (!ok) { 4806f76ee892STomi Valkeinen DSSERR("failed to find suitable DSI clock settings\n"); 4807f76ee892STomi Valkeinen r = -EINVAL; 4808f76ee892STomi Valkeinen goto err; 4809f76ee892STomi Valkeinen } 4810f76ee892STomi Valkeinen 4811f76ee892STomi Valkeinen dsi_pll_calc_dsi_fck(&ctx.dsi_cinfo); 4812f76ee892STomi Valkeinen 4813f76ee892STomi Valkeinen r = dsi_lp_clock_calc(ctx.dsi_cinfo.clkout[HSDIV_DSI], 4814f76ee892STomi Valkeinen config->lp_clk_min, config->lp_clk_max, &dsi->user_lp_cinfo); 4815f76ee892STomi Valkeinen if (r) { 4816f76ee892STomi Valkeinen DSSERR("failed to find suitable DSI LP clock settings\n"); 4817f76ee892STomi Valkeinen goto err; 4818f76ee892STomi Valkeinen } 4819f76ee892STomi Valkeinen 4820f76ee892STomi Valkeinen dsi->user_dsi_cinfo = ctx.dsi_cinfo; 4821f76ee892STomi Valkeinen dsi->user_dispc_cinfo = ctx.dispc_cinfo; 4822f76ee892STomi Valkeinen 4823f76ee892STomi Valkeinen dsi->timings = ctx.dispc_vm; 4824f76ee892STomi Valkeinen dsi->vm_timings = ctx.dsi_vm; 4825f76ee892STomi Valkeinen 4826f76ee892STomi Valkeinen mutex_unlock(&dsi->lock); 4827f76ee892STomi Valkeinen 4828f76ee892STomi Valkeinen return 0; 4829f76ee892STomi Valkeinen err: 4830f76ee892STomi Valkeinen mutex_unlock(&dsi->lock); 4831f76ee892STomi Valkeinen 4832f76ee892STomi Valkeinen return r; 4833f76ee892STomi Valkeinen } 4834f76ee892STomi Valkeinen 4835f76ee892STomi Valkeinen /* 4836f76ee892STomi Valkeinen * Return a hardcoded channel for the DSI output. This should work for 4837f76ee892STomi Valkeinen * current use cases, but this can be later expanded to either resolve 4838f76ee892STomi Valkeinen * the channel in some more dynamic manner, or get the channel as a user 4839f76ee892STomi Valkeinen * parameter. 4840f76ee892STomi Valkeinen */ 4841f76ee892STomi Valkeinen static enum omap_channel dsi_get_channel(int module_id) 4842f76ee892STomi Valkeinen { 4843f76ee892STomi Valkeinen switch (omapdss_get_version()) { 4844f76ee892STomi Valkeinen case OMAPDSS_VER_OMAP24xx: 4845f76ee892STomi Valkeinen case OMAPDSS_VER_AM43xx: 4846f76ee892STomi Valkeinen DSSWARN("DSI not supported\n"); 4847f76ee892STomi Valkeinen return OMAP_DSS_CHANNEL_LCD; 4848f76ee892STomi Valkeinen 4849f76ee892STomi Valkeinen case OMAPDSS_VER_OMAP34xx_ES1: 4850f76ee892STomi Valkeinen case OMAPDSS_VER_OMAP34xx_ES3: 4851f76ee892STomi Valkeinen case OMAPDSS_VER_OMAP3630: 4852f76ee892STomi Valkeinen case OMAPDSS_VER_AM35xx: 4853f76ee892STomi Valkeinen return OMAP_DSS_CHANNEL_LCD; 4854f76ee892STomi Valkeinen 4855f76ee892STomi Valkeinen case OMAPDSS_VER_OMAP4430_ES1: 4856f76ee892STomi Valkeinen case OMAPDSS_VER_OMAP4430_ES2: 4857f76ee892STomi Valkeinen case OMAPDSS_VER_OMAP4: 4858f76ee892STomi Valkeinen switch (module_id) { 4859f76ee892STomi Valkeinen case 0: 4860f76ee892STomi Valkeinen return OMAP_DSS_CHANNEL_LCD; 4861f76ee892STomi Valkeinen case 1: 4862f76ee892STomi Valkeinen return OMAP_DSS_CHANNEL_LCD2; 4863f76ee892STomi Valkeinen default: 4864f76ee892STomi Valkeinen DSSWARN("unsupported module id\n"); 4865f76ee892STomi Valkeinen return OMAP_DSS_CHANNEL_LCD; 4866f76ee892STomi Valkeinen } 4867f76ee892STomi Valkeinen 4868f76ee892STomi Valkeinen case OMAPDSS_VER_OMAP5: 4869f76ee892STomi Valkeinen switch (module_id) { 4870f76ee892STomi Valkeinen case 0: 4871f76ee892STomi Valkeinen return OMAP_DSS_CHANNEL_LCD; 4872f76ee892STomi Valkeinen case 1: 4873f76ee892STomi Valkeinen return OMAP_DSS_CHANNEL_LCD3; 4874f76ee892STomi Valkeinen default: 4875f76ee892STomi Valkeinen DSSWARN("unsupported module id\n"); 4876f76ee892STomi Valkeinen return OMAP_DSS_CHANNEL_LCD; 4877f76ee892STomi Valkeinen } 4878f76ee892STomi Valkeinen 4879f76ee892STomi Valkeinen default: 4880f76ee892STomi Valkeinen DSSWARN("unsupported DSS version\n"); 4881f76ee892STomi Valkeinen return OMAP_DSS_CHANNEL_LCD; 4882f76ee892STomi Valkeinen } 4883f76ee892STomi Valkeinen } 4884f76ee892STomi Valkeinen 4885f76ee892STomi Valkeinen static int dsi_request_vc(struct omap_dss_device *dssdev, int *channel) 4886f76ee892STomi Valkeinen { 4887f76ee892STomi Valkeinen struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); 4888f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 4889f76ee892STomi Valkeinen int i; 4890f76ee892STomi Valkeinen 4891f76ee892STomi Valkeinen for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) { 4892f76ee892STomi Valkeinen if (!dsi->vc[i].dssdev) { 4893f76ee892STomi Valkeinen dsi->vc[i].dssdev = dssdev; 4894f76ee892STomi Valkeinen *channel = i; 4895f76ee892STomi Valkeinen return 0; 4896f76ee892STomi Valkeinen } 4897f76ee892STomi Valkeinen } 4898f76ee892STomi Valkeinen 4899f76ee892STomi Valkeinen DSSERR("cannot get VC for display %s", dssdev->name); 4900f76ee892STomi Valkeinen return -ENOSPC; 4901f76ee892STomi Valkeinen } 4902f76ee892STomi Valkeinen 4903f76ee892STomi Valkeinen static int dsi_set_vc_id(struct omap_dss_device *dssdev, int channel, int vc_id) 4904f76ee892STomi Valkeinen { 4905f76ee892STomi Valkeinen struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); 4906f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 4907f76ee892STomi Valkeinen 4908f76ee892STomi Valkeinen if (vc_id < 0 || vc_id > 3) { 4909f76ee892STomi Valkeinen DSSERR("VC ID out of range\n"); 4910f76ee892STomi Valkeinen return -EINVAL; 4911f76ee892STomi Valkeinen } 4912f76ee892STomi Valkeinen 4913f76ee892STomi Valkeinen if (channel < 0 || channel > 3) { 4914f76ee892STomi Valkeinen DSSERR("Virtual Channel out of range\n"); 4915f76ee892STomi Valkeinen return -EINVAL; 4916f76ee892STomi Valkeinen } 4917f76ee892STomi Valkeinen 4918f76ee892STomi Valkeinen if (dsi->vc[channel].dssdev != dssdev) { 4919f76ee892STomi Valkeinen DSSERR("Virtual Channel not allocated to display %s\n", 4920f76ee892STomi Valkeinen dssdev->name); 4921f76ee892STomi Valkeinen return -EINVAL; 4922f76ee892STomi Valkeinen } 4923f76ee892STomi Valkeinen 4924f76ee892STomi Valkeinen dsi->vc[channel].vc_id = vc_id; 4925f76ee892STomi Valkeinen 4926f76ee892STomi Valkeinen return 0; 4927f76ee892STomi Valkeinen } 4928f76ee892STomi Valkeinen 4929f76ee892STomi Valkeinen static void dsi_release_vc(struct omap_dss_device *dssdev, int channel) 4930f76ee892STomi Valkeinen { 4931f76ee892STomi Valkeinen struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); 4932f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 4933f76ee892STomi Valkeinen 4934f76ee892STomi Valkeinen if ((channel >= 0 && channel <= 3) && 4935f76ee892STomi Valkeinen dsi->vc[channel].dssdev == dssdev) { 4936f76ee892STomi Valkeinen dsi->vc[channel].dssdev = NULL; 4937f76ee892STomi Valkeinen dsi->vc[channel].vc_id = 0; 4938f76ee892STomi Valkeinen } 4939f76ee892STomi Valkeinen } 4940f76ee892STomi Valkeinen 4941f76ee892STomi Valkeinen 4942f76ee892STomi Valkeinen static int dsi_get_clocks(struct platform_device *dsidev) 4943f76ee892STomi Valkeinen { 4944f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 4945f76ee892STomi Valkeinen struct clk *clk; 4946f76ee892STomi Valkeinen 4947f76ee892STomi Valkeinen clk = devm_clk_get(&dsidev->dev, "fck"); 4948f76ee892STomi Valkeinen if (IS_ERR(clk)) { 4949f76ee892STomi Valkeinen DSSERR("can't get fck\n"); 4950f76ee892STomi Valkeinen return PTR_ERR(clk); 4951f76ee892STomi Valkeinen } 4952f76ee892STomi Valkeinen 4953f76ee892STomi Valkeinen dsi->dss_clk = clk; 4954f76ee892STomi Valkeinen 4955f76ee892STomi Valkeinen return 0; 4956f76ee892STomi Valkeinen } 4957f76ee892STomi Valkeinen 4958f76ee892STomi Valkeinen static int dsi_connect(struct omap_dss_device *dssdev, 4959f76ee892STomi Valkeinen struct omap_dss_device *dst) 4960f76ee892STomi Valkeinen { 4961f76ee892STomi Valkeinen struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); 4962f76ee892STomi Valkeinen struct omap_overlay_manager *mgr; 4963f76ee892STomi Valkeinen int r; 4964f76ee892STomi Valkeinen 4965f76ee892STomi Valkeinen r = dsi_regulator_init(dsidev); 4966f76ee892STomi Valkeinen if (r) 4967f76ee892STomi Valkeinen return r; 4968f76ee892STomi Valkeinen 4969f76ee892STomi Valkeinen mgr = omap_dss_get_overlay_manager(dssdev->dispc_channel); 4970f76ee892STomi Valkeinen if (!mgr) 4971f76ee892STomi Valkeinen return -ENODEV; 4972f76ee892STomi Valkeinen 4973f76ee892STomi Valkeinen r = dss_mgr_connect(mgr, dssdev); 4974f76ee892STomi Valkeinen if (r) 4975f76ee892STomi Valkeinen return r; 4976f76ee892STomi Valkeinen 4977f76ee892STomi Valkeinen r = omapdss_output_set_device(dssdev, dst); 4978f76ee892STomi Valkeinen if (r) { 4979f76ee892STomi Valkeinen DSSERR("failed to connect output to new device: %s\n", 4980f76ee892STomi Valkeinen dssdev->name); 4981f76ee892STomi Valkeinen dss_mgr_disconnect(mgr, dssdev); 4982f76ee892STomi Valkeinen return r; 4983f76ee892STomi Valkeinen } 4984f76ee892STomi Valkeinen 4985f76ee892STomi Valkeinen return 0; 4986f76ee892STomi Valkeinen } 4987f76ee892STomi Valkeinen 4988f76ee892STomi Valkeinen static void dsi_disconnect(struct omap_dss_device *dssdev, 4989f76ee892STomi Valkeinen struct omap_dss_device *dst) 4990f76ee892STomi Valkeinen { 4991f76ee892STomi Valkeinen WARN_ON(dst != dssdev->dst); 4992f76ee892STomi Valkeinen 4993f76ee892STomi Valkeinen if (dst != dssdev->dst) 4994f76ee892STomi Valkeinen return; 4995f76ee892STomi Valkeinen 4996f76ee892STomi Valkeinen omapdss_output_unset_device(dssdev); 4997f76ee892STomi Valkeinen 4998f76ee892STomi Valkeinen if (dssdev->manager) 4999f76ee892STomi Valkeinen dss_mgr_disconnect(dssdev->manager, dssdev); 5000f76ee892STomi Valkeinen } 5001f76ee892STomi Valkeinen 5002f76ee892STomi Valkeinen static const struct omapdss_dsi_ops dsi_ops = { 5003f76ee892STomi Valkeinen .connect = dsi_connect, 5004f76ee892STomi Valkeinen .disconnect = dsi_disconnect, 5005f76ee892STomi Valkeinen 5006f76ee892STomi Valkeinen .bus_lock = dsi_bus_lock, 5007f76ee892STomi Valkeinen .bus_unlock = dsi_bus_unlock, 5008f76ee892STomi Valkeinen 5009f76ee892STomi Valkeinen .enable = dsi_display_enable, 5010f76ee892STomi Valkeinen .disable = dsi_display_disable, 5011f76ee892STomi Valkeinen 5012f76ee892STomi Valkeinen .enable_hs = dsi_vc_enable_hs, 5013f76ee892STomi Valkeinen 5014f76ee892STomi Valkeinen .configure_pins = dsi_configure_pins, 5015f76ee892STomi Valkeinen .set_config = dsi_set_config, 5016f76ee892STomi Valkeinen 5017f76ee892STomi Valkeinen .enable_video_output = dsi_enable_video_output, 5018f76ee892STomi Valkeinen .disable_video_output = dsi_disable_video_output, 5019f76ee892STomi Valkeinen 5020f76ee892STomi Valkeinen .update = dsi_update, 5021f76ee892STomi Valkeinen 5022f76ee892STomi Valkeinen .enable_te = dsi_enable_te, 5023f76ee892STomi Valkeinen 5024f76ee892STomi Valkeinen .request_vc = dsi_request_vc, 5025f76ee892STomi Valkeinen .set_vc_id = dsi_set_vc_id, 5026f76ee892STomi Valkeinen .release_vc = dsi_release_vc, 5027f76ee892STomi Valkeinen 5028f76ee892STomi Valkeinen .dcs_write = dsi_vc_dcs_write, 5029f76ee892STomi Valkeinen .dcs_write_nosync = dsi_vc_dcs_write_nosync, 5030f76ee892STomi Valkeinen .dcs_read = dsi_vc_dcs_read, 5031f76ee892STomi Valkeinen 5032f76ee892STomi Valkeinen .gen_write = dsi_vc_generic_write, 5033f76ee892STomi Valkeinen .gen_write_nosync = dsi_vc_generic_write_nosync, 5034f76ee892STomi Valkeinen .gen_read = dsi_vc_generic_read, 5035f76ee892STomi Valkeinen 5036f76ee892STomi Valkeinen .bta_sync = dsi_vc_send_bta_sync, 5037f76ee892STomi Valkeinen 5038f76ee892STomi Valkeinen .set_max_rx_packet_size = dsi_vc_set_max_rx_packet_size, 5039f76ee892STomi Valkeinen }; 5040f76ee892STomi Valkeinen 5041f76ee892STomi Valkeinen static void dsi_init_output(struct platform_device *dsidev) 5042f76ee892STomi Valkeinen { 5043f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 5044f76ee892STomi Valkeinen struct omap_dss_device *out = &dsi->output; 5045f76ee892STomi Valkeinen 5046f76ee892STomi Valkeinen out->dev = &dsidev->dev; 5047f76ee892STomi Valkeinen out->id = dsi->module_id == 0 ? 5048f76ee892STomi Valkeinen OMAP_DSS_OUTPUT_DSI1 : OMAP_DSS_OUTPUT_DSI2; 5049f76ee892STomi Valkeinen 5050f76ee892STomi Valkeinen out->output_type = OMAP_DISPLAY_TYPE_DSI; 5051f76ee892STomi Valkeinen out->name = dsi->module_id == 0 ? "dsi.0" : "dsi.1"; 5052f76ee892STomi Valkeinen out->dispc_channel = dsi_get_channel(dsi->module_id); 5053f76ee892STomi Valkeinen out->ops.dsi = &dsi_ops; 5054f76ee892STomi Valkeinen out->owner = THIS_MODULE; 5055f76ee892STomi Valkeinen 5056f76ee892STomi Valkeinen omapdss_register_output(out); 5057f76ee892STomi Valkeinen } 5058f76ee892STomi Valkeinen 5059f76ee892STomi Valkeinen static void dsi_uninit_output(struct platform_device *dsidev) 5060f76ee892STomi Valkeinen { 5061f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 5062f76ee892STomi Valkeinen struct omap_dss_device *out = &dsi->output; 5063f76ee892STomi Valkeinen 5064f76ee892STomi Valkeinen omapdss_unregister_output(out); 5065f76ee892STomi Valkeinen } 5066f76ee892STomi Valkeinen 5067f76ee892STomi Valkeinen static int dsi_probe_of(struct platform_device *pdev) 5068f76ee892STomi Valkeinen { 5069f76ee892STomi Valkeinen struct device_node *node = pdev->dev.of_node; 5070f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(pdev); 5071f76ee892STomi Valkeinen struct property *prop; 5072f76ee892STomi Valkeinen u32 lane_arr[10]; 5073f76ee892STomi Valkeinen int len, num_pins; 5074f76ee892STomi Valkeinen int r, i; 5075f76ee892STomi Valkeinen struct device_node *ep; 5076f76ee892STomi Valkeinen struct omap_dsi_pin_config pin_cfg; 5077f76ee892STomi Valkeinen 5078f76ee892STomi Valkeinen ep = omapdss_of_get_first_endpoint(node); 5079f76ee892STomi Valkeinen if (!ep) 5080f76ee892STomi Valkeinen return 0; 5081f76ee892STomi Valkeinen 5082f76ee892STomi Valkeinen prop = of_find_property(ep, "lanes", &len); 5083f76ee892STomi Valkeinen if (prop == NULL) { 5084f76ee892STomi Valkeinen dev_err(&pdev->dev, "failed to find lane data\n"); 5085f76ee892STomi Valkeinen r = -EINVAL; 5086f76ee892STomi Valkeinen goto err; 5087f76ee892STomi Valkeinen } 5088f76ee892STomi Valkeinen 5089f76ee892STomi Valkeinen num_pins = len / sizeof(u32); 5090f76ee892STomi Valkeinen 5091f76ee892STomi Valkeinen if (num_pins < 4 || num_pins % 2 != 0 || 5092f76ee892STomi Valkeinen num_pins > dsi->num_lanes_supported * 2) { 5093f76ee892STomi Valkeinen dev_err(&pdev->dev, "bad number of lanes\n"); 5094f76ee892STomi Valkeinen r = -EINVAL; 5095f76ee892STomi Valkeinen goto err; 5096f76ee892STomi Valkeinen } 5097f76ee892STomi Valkeinen 5098f76ee892STomi Valkeinen r = of_property_read_u32_array(ep, "lanes", lane_arr, num_pins); 5099f76ee892STomi Valkeinen if (r) { 5100f76ee892STomi Valkeinen dev_err(&pdev->dev, "failed to read lane data\n"); 5101f76ee892STomi Valkeinen goto err; 5102f76ee892STomi Valkeinen } 5103f76ee892STomi Valkeinen 5104f76ee892STomi Valkeinen pin_cfg.num_pins = num_pins; 5105f76ee892STomi Valkeinen for (i = 0; i < num_pins; ++i) 5106f76ee892STomi Valkeinen pin_cfg.pins[i] = (int)lane_arr[i]; 5107f76ee892STomi Valkeinen 5108f76ee892STomi Valkeinen r = dsi_configure_pins(&dsi->output, &pin_cfg); 5109f76ee892STomi Valkeinen if (r) { 5110f76ee892STomi Valkeinen dev_err(&pdev->dev, "failed to configure pins"); 5111f76ee892STomi Valkeinen goto err; 5112f76ee892STomi Valkeinen } 5113f76ee892STomi Valkeinen 5114f76ee892STomi Valkeinen of_node_put(ep); 5115f76ee892STomi Valkeinen 5116f76ee892STomi Valkeinen return 0; 5117f76ee892STomi Valkeinen 5118f76ee892STomi Valkeinen err: 5119f76ee892STomi Valkeinen of_node_put(ep); 5120f76ee892STomi Valkeinen return r; 5121f76ee892STomi Valkeinen } 5122f76ee892STomi Valkeinen 5123f76ee892STomi Valkeinen static const struct dss_pll_ops dsi_pll_ops = { 5124f76ee892STomi Valkeinen .enable = dsi_pll_enable, 5125f76ee892STomi Valkeinen .disable = dsi_pll_disable, 5126f76ee892STomi Valkeinen .set_config = dss_pll_write_config_type_a, 5127f76ee892STomi Valkeinen }; 5128f76ee892STomi Valkeinen 5129f76ee892STomi Valkeinen static const struct dss_pll_hw dss_omap3_dsi_pll_hw = { 5130f76ee892STomi Valkeinen .n_max = (1 << 7) - 1, 5131f76ee892STomi Valkeinen .m_max = (1 << 11) - 1, 5132f76ee892STomi Valkeinen .mX_max = (1 << 4) - 1, 5133f76ee892STomi Valkeinen .fint_min = 750000, 5134f76ee892STomi Valkeinen .fint_max = 2100000, 5135f76ee892STomi Valkeinen .clkdco_low = 1000000000, 5136f76ee892STomi Valkeinen .clkdco_max = 1800000000, 5137f76ee892STomi Valkeinen 5138f76ee892STomi Valkeinen .n_msb = 7, 5139f76ee892STomi Valkeinen .n_lsb = 1, 5140f76ee892STomi Valkeinen .m_msb = 18, 5141f76ee892STomi Valkeinen .m_lsb = 8, 5142f76ee892STomi Valkeinen 5143f76ee892STomi Valkeinen .mX_msb[0] = 22, 5144f76ee892STomi Valkeinen .mX_lsb[0] = 19, 5145f76ee892STomi Valkeinen .mX_msb[1] = 26, 5146f76ee892STomi Valkeinen .mX_lsb[1] = 23, 5147f76ee892STomi Valkeinen 5148f76ee892STomi Valkeinen .has_stopmode = true, 5149f76ee892STomi Valkeinen .has_freqsel = true, 5150f76ee892STomi Valkeinen .has_selfreqdco = false, 5151f76ee892STomi Valkeinen .has_refsel = false, 5152f76ee892STomi Valkeinen }; 5153f76ee892STomi Valkeinen 5154f76ee892STomi Valkeinen static const struct dss_pll_hw dss_omap4_dsi_pll_hw = { 5155f76ee892STomi Valkeinen .n_max = (1 << 8) - 1, 5156f76ee892STomi Valkeinen .m_max = (1 << 12) - 1, 5157f76ee892STomi Valkeinen .mX_max = (1 << 5) - 1, 5158f76ee892STomi Valkeinen .fint_min = 500000, 5159f76ee892STomi Valkeinen .fint_max = 2500000, 5160f76ee892STomi Valkeinen .clkdco_low = 1000000000, 5161f76ee892STomi Valkeinen .clkdco_max = 1800000000, 5162f76ee892STomi Valkeinen 5163f76ee892STomi Valkeinen .n_msb = 8, 5164f76ee892STomi Valkeinen .n_lsb = 1, 5165f76ee892STomi Valkeinen .m_msb = 20, 5166f76ee892STomi Valkeinen .m_lsb = 9, 5167f76ee892STomi Valkeinen 5168f76ee892STomi Valkeinen .mX_msb[0] = 25, 5169f76ee892STomi Valkeinen .mX_lsb[0] = 21, 5170f76ee892STomi Valkeinen .mX_msb[1] = 30, 5171f76ee892STomi Valkeinen .mX_lsb[1] = 26, 5172f76ee892STomi Valkeinen 5173f76ee892STomi Valkeinen .has_stopmode = true, 5174f76ee892STomi Valkeinen .has_freqsel = false, 5175f76ee892STomi Valkeinen .has_selfreqdco = false, 5176f76ee892STomi Valkeinen .has_refsel = false, 5177f76ee892STomi Valkeinen }; 5178f76ee892STomi Valkeinen 5179f76ee892STomi Valkeinen static const struct dss_pll_hw dss_omap5_dsi_pll_hw = { 5180f76ee892STomi Valkeinen .n_max = (1 << 8) - 1, 5181f76ee892STomi Valkeinen .m_max = (1 << 12) - 1, 5182f76ee892STomi Valkeinen .mX_max = (1 << 5) - 1, 5183f76ee892STomi Valkeinen .fint_min = 150000, 5184f76ee892STomi Valkeinen .fint_max = 52000000, 5185f76ee892STomi Valkeinen .clkdco_low = 1000000000, 5186f76ee892STomi Valkeinen .clkdco_max = 1800000000, 5187f76ee892STomi Valkeinen 5188f76ee892STomi Valkeinen .n_msb = 8, 5189f76ee892STomi Valkeinen .n_lsb = 1, 5190f76ee892STomi Valkeinen .m_msb = 20, 5191f76ee892STomi Valkeinen .m_lsb = 9, 5192f76ee892STomi Valkeinen 5193f76ee892STomi Valkeinen .mX_msb[0] = 25, 5194f76ee892STomi Valkeinen .mX_lsb[0] = 21, 5195f76ee892STomi Valkeinen .mX_msb[1] = 30, 5196f76ee892STomi Valkeinen .mX_lsb[1] = 26, 5197f76ee892STomi Valkeinen 5198f76ee892STomi Valkeinen .has_stopmode = true, 5199f76ee892STomi Valkeinen .has_freqsel = false, 5200f76ee892STomi Valkeinen .has_selfreqdco = true, 5201f76ee892STomi Valkeinen .has_refsel = true, 5202f76ee892STomi Valkeinen }; 5203f76ee892STomi Valkeinen 5204f76ee892STomi Valkeinen static int dsi_init_pll_data(struct platform_device *dsidev) 5205f76ee892STomi Valkeinen { 5206f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 5207f76ee892STomi Valkeinen struct dss_pll *pll = &dsi->pll; 5208f76ee892STomi Valkeinen struct clk *clk; 5209f76ee892STomi Valkeinen int r; 5210f76ee892STomi Valkeinen 5211f76ee892STomi Valkeinen clk = devm_clk_get(&dsidev->dev, "sys_clk"); 5212f76ee892STomi Valkeinen if (IS_ERR(clk)) { 5213f76ee892STomi Valkeinen DSSERR("can't get sys_clk\n"); 5214f76ee892STomi Valkeinen return PTR_ERR(clk); 5215f76ee892STomi Valkeinen } 5216f76ee892STomi Valkeinen 5217f76ee892STomi Valkeinen pll->name = dsi->module_id == 0 ? "dsi0" : "dsi1"; 5218f76ee892STomi Valkeinen pll->id = dsi->module_id == 0 ? DSS_PLL_DSI1 : DSS_PLL_DSI2; 5219f76ee892STomi Valkeinen pll->clkin = clk; 5220f76ee892STomi Valkeinen pll->base = dsi->pll_base; 5221f76ee892STomi Valkeinen 5222f76ee892STomi Valkeinen switch (omapdss_get_version()) { 5223f76ee892STomi Valkeinen case OMAPDSS_VER_OMAP34xx_ES1: 5224f76ee892STomi Valkeinen case OMAPDSS_VER_OMAP34xx_ES3: 5225f76ee892STomi Valkeinen case OMAPDSS_VER_OMAP3630: 5226f76ee892STomi Valkeinen case OMAPDSS_VER_AM35xx: 5227f76ee892STomi Valkeinen pll->hw = &dss_omap3_dsi_pll_hw; 5228f76ee892STomi Valkeinen break; 5229f76ee892STomi Valkeinen 5230f76ee892STomi Valkeinen case OMAPDSS_VER_OMAP4430_ES1: 5231f76ee892STomi Valkeinen case OMAPDSS_VER_OMAP4430_ES2: 5232f76ee892STomi Valkeinen case OMAPDSS_VER_OMAP4: 5233f76ee892STomi Valkeinen pll->hw = &dss_omap4_dsi_pll_hw; 5234f76ee892STomi Valkeinen break; 5235f76ee892STomi Valkeinen 5236f76ee892STomi Valkeinen case OMAPDSS_VER_OMAP5: 5237f76ee892STomi Valkeinen pll->hw = &dss_omap5_dsi_pll_hw; 5238f76ee892STomi Valkeinen break; 5239f76ee892STomi Valkeinen 5240f76ee892STomi Valkeinen default: 5241f76ee892STomi Valkeinen return -ENODEV; 5242f76ee892STomi Valkeinen } 5243f76ee892STomi Valkeinen 5244f76ee892STomi Valkeinen pll->ops = &dsi_pll_ops; 5245f76ee892STomi Valkeinen 5246f76ee892STomi Valkeinen r = dss_pll_register(pll); 5247f76ee892STomi Valkeinen if (r) 5248f76ee892STomi Valkeinen return r; 5249f76ee892STomi Valkeinen 5250f76ee892STomi Valkeinen return 0; 5251f76ee892STomi Valkeinen } 5252f76ee892STomi Valkeinen 5253f76ee892STomi Valkeinen /* DSI1 HW IP initialisation */ 5254f76ee892STomi Valkeinen static int dsi_bind(struct device *dev, struct device *master, void *data) 5255f76ee892STomi Valkeinen { 5256f76ee892STomi Valkeinen struct platform_device *dsidev = to_platform_device(dev); 5257f76ee892STomi Valkeinen u32 rev; 5258f76ee892STomi Valkeinen int r, i; 5259f76ee892STomi Valkeinen struct dsi_data *dsi; 5260f76ee892STomi Valkeinen struct resource *dsi_mem; 5261f76ee892STomi Valkeinen struct resource *res; 5262f76ee892STomi Valkeinen struct resource temp_res; 5263f76ee892STomi Valkeinen 5264f76ee892STomi Valkeinen dsi = devm_kzalloc(&dsidev->dev, sizeof(*dsi), GFP_KERNEL); 5265f76ee892STomi Valkeinen if (!dsi) 5266f76ee892STomi Valkeinen return -ENOMEM; 5267f76ee892STomi Valkeinen 5268f76ee892STomi Valkeinen dsi->pdev = dsidev; 5269f76ee892STomi Valkeinen dev_set_drvdata(&dsidev->dev, dsi); 5270f76ee892STomi Valkeinen 5271f76ee892STomi Valkeinen spin_lock_init(&dsi->irq_lock); 5272f76ee892STomi Valkeinen spin_lock_init(&dsi->errors_lock); 5273f76ee892STomi Valkeinen dsi->errors = 0; 5274f76ee892STomi Valkeinen 527535b522cfSTomi Valkeinen #ifdef CONFIG_FB_OMAP2_DSS_COLLECT_IRQ_STATS 5276f76ee892STomi Valkeinen spin_lock_init(&dsi->irq_stats_lock); 5277f76ee892STomi Valkeinen dsi->irq_stats.last_reset = jiffies; 5278f76ee892STomi Valkeinen #endif 5279f76ee892STomi Valkeinen 5280f76ee892STomi Valkeinen mutex_init(&dsi->lock); 5281f76ee892STomi Valkeinen sema_init(&dsi->bus_lock, 1); 5282f76ee892STomi Valkeinen 5283f76ee892STomi Valkeinen INIT_DEFERRABLE_WORK(&dsi->framedone_timeout_work, 5284f76ee892STomi Valkeinen dsi_framedone_timeout_work_callback); 5285f76ee892STomi Valkeinen 5286f76ee892STomi Valkeinen #ifdef DSI_CATCH_MISSING_TE 52876c789357SKees Cook timer_setup(&dsi->te_timer, dsi_te_timeout, 0); 5288f76ee892STomi Valkeinen #endif 5289f76ee892STomi Valkeinen 5290f76ee892STomi Valkeinen res = platform_get_resource_byname(dsidev, IORESOURCE_MEM, "proto"); 5291f76ee892STomi Valkeinen if (!res) { 5292f76ee892STomi Valkeinen res = platform_get_resource(dsidev, IORESOURCE_MEM, 0); 5293f76ee892STomi Valkeinen if (!res) { 5294f76ee892STomi Valkeinen DSSERR("can't get IORESOURCE_MEM DSI\n"); 5295f76ee892STomi Valkeinen return -EINVAL; 5296f76ee892STomi Valkeinen } 5297f76ee892STomi Valkeinen 5298f76ee892STomi Valkeinen temp_res.start = res->start; 5299f76ee892STomi Valkeinen temp_res.end = temp_res.start + DSI_PROTO_SZ - 1; 5300f76ee892STomi Valkeinen res = &temp_res; 5301f76ee892STomi Valkeinen } 5302f76ee892STomi Valkeinen 5303f76ee892STomi Valkeinen dsi_mem = res; 5304f76ee892STomi Valkeinen 5305f76ee892STomi Valkeinen dsi->proto_base = devm_ioremap(&dsidev->dev, res->start, 5306f76ee892STomi Valkeinen resource_size(res)); 5307f76ee892STomi Valkeinen if (!dsi->proto_base) { 5308f76ee892STomi Valkeinen DSSERR("can't ioremap DSI protocol engine\n"); 5309f76ee892STomi Valkeinen return -ENOMEM; 5310f76ee892STomi Valkeinen } 5311f76ee892STomi Valkeinen 5312f76ee892STomi Valkeinen res = platform_get_resource_byname(dsidev, IORESOURCE_MEM, "phy"); 5313f76ee892STomi Valkeinen if (!res) { 5314f76ee892STomi Valkeinen res = platform_get_resource(dsidev, IORESOURCE_MEM, 0); 5315f76ee892STomi Valkeinen if (!res) { 5316f76ee892STomi Valkeinen DSSERR("can't get IORESOURCE_MEM DSI\n"); 5317f76ee892STomi Valkeinen return -EINVAL; 5318f76ee892STomi Valkeinen } 5319f76ee892STomi Valkeinen 5320f76ee892STomi Valkeinen temp_res.start = res->start + DSI_PHY_OFFSET; 5321f76ee892STomi Valkeinen temp_res.end = temp_res.start + DSI_PHY_SZ - 1; 5322f76ee892STomi Valkeinen res = &temp_res; 5323f76ee892STomi Valkeinen } 5324f76ee892STomi Valkeinen 5325f76ee892STomi Valkeinen dsi->phy_base = devm_ioremap(&dsidev->dev, res->start, 5326f76ee892STomi Valkeinen resource_size(res)); 532743da7575SWei Yongjun if (!dsi->phy_base) { 5328f76ee892STomi Valkeinen DSSERR("can't ioremap DSI PHY\n"); 5329f76ee892STomi Valkeinen return -ENOMEM; 5330f76ee892STomi Valkeinen } 5331f76ee892STomi Valkeinen 5332f76ee892STomi Valkeinen res = platform_get_resource_byname(dsidev, IORESOURCE_MEM, "pll"); 5333f76ee892STomi Valkeinen if (!res) { 5334f76ee892STomi Valkeinen res = platform_get_resource(dsidev, IORESOURCE_MEM, 0); 5335f76ee892STomi Valkeinen if (!res) { 5336f76ee892STomi Valkeinen DSSERR("can't get IORESOURCE_MEM DSI\n"); 5337f76ee892STomi Valkeinen return -EINVAL; 5338f76ee892STomi Valkeinen } 5339f76ee892STomi Valkeinen 5340f76ee892STomi Valkeinen temp_res.start = res->start + DSI_PLL_OFFSET; 5341f76ee892STomi Valkeinen temp_res.end = temp_res.start + DSI_PLL_SZ - 1; 5342f76ee892STomi Valkeinen res = &temp_res; 5343f76ee892STomi Valkeinen } 5344f76ee892STomi Valkeinen 5345f76ee892STomi Valkeinen dsi->pll_base = devm_ioremap(&dsidev->dev, res->start, 5346f76ee892STomi Valkeinen resource_size(res)); 534743da7575SWei Yongjun if (!dsi->pll_base) { 5348f76ee892STomi Valkeinen DSSERR("can't ioremap DSI PLL\n"); 5349f76ee892STomi Valkeinen return -ENOMEM; 5350f76ee892STomi Valkeinen } 5351f76ee892STomi Valkeinen 5352f76ee892STomi Valkeinen dsi->irq = platform_get_irq(dsi->pdev, 0); 5353f76ee892STomi Valkeinen if (dsi->irq < 0) { 5354f76ee892STomi Valkeinen DSSERR("platform_get_irq failed\n"); 5355f76ee892STomi Valkeinen return -ENODEV; 5356f76ee892STomi Valkeinen } 5357f76ee892STomi Valkeinen 5358f76ee892STomi Valkeinen r = devm_request_irq(&dsidev->dev, dsi->irq, omap_dsi_irq_handler, 5359f76ee892STomi Valkeinen IRQF_SHARED, dev_name(&dsidev->dev), dsi->pdev); 5360f76ee892STomi Valkeinen if (r < 0) { 5361f76ee892STomi Valkeinen DSSERR("request_irq failed\n"); 5362f76ee892STomi Valkeinen return r; 5363f76ee892STomi Valkeinen } 5364f76ee892STomi Valkeinen 5365f76ee892STomi Valkeinen if (dsidev->dev.of_node) { 5366f76ee892STomi Valkeinen const struct of_device_id *match; 5367f76ee892STomi Valkeinen const struct dsi_module_id_data *d; 5368f76ee892STomi Valkeinen 5369f76ee892STomi Valkeinen match = of_match_node(dsi_of_match, dsidev->dev.of_node); 5370f76ee892STomi Valkeinen if (!match) { 5371f76ee892STomi Valkeinen DSSERR("unsupported DSI module\n"); 5372f76ee892STomi Valkeinen return -ENODEV; 5373f76ee892STomi Valkeinen } 5374f76ee892STomi Valkeinen 5375f76ee892STomi Valkeinen d = match->data; 5376f76ee892STomi Valkeinen 5377f76ee892STomi Valkeinen while (d->address != 0 && d->address != dsi_mem->start) 5378f76ee892STomi Valkeinen d++; 5379f76ee892STomi Valkeinen 5380f76ee892STomi Valkeinen if (d->address == 0) { 5381f76ee892STomi Valkeinen DSSERR("unsupported DSI module\n"); 5382f76ee892STomi Valkeinen return -ENODEV; 5383f76ee892STomi Valkeinen } 5384f76ee892STomi Valkeinen 5385f76ee892STomi Valkeinen dsi->module_id = d->id; 5386f76ee892STomi Valkeinen } else { 5387f76ee892STomi Valkeinen dsi->module_id = dsidev->id; 5388f76ee892STomi Valkeinen } 5389f76ee892STomi Valkeinen 5390f76ee892STomi Valkeinen /* DSI VCs initialization */ 5391f76ee892STomi Valkeinen for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) { 5392f76ee892STomi Valkeinen dsi->vc[i].source = DSI_VC_SOURCE_L4; 5393f76ee892STomi Valkeinen dsi->vc[i].dssdev = NULL; 5394f76ee892STomi Valkeinen dsi->vc[i].vc_id = 0; 5395f76ee892STomi Valkeinen } 5396f76ee892STomi Valkeinen 5397f76ee892STomi Valkeinen r = dsi_get_clocks(dsidev); 5398f76ee892STomi Valkeinen if (r) 5399f76ee892STomi Valkeinen return r; 5400f76ee892STomi Valkeinen 5401f76ee892STomi Valkeinen dsi_init_pll_data(dsidev); 5402f76ee892STomi Valkeinen 5403f76ee892STomi Valkeinen pm_runtime_enable(&dsidev->dev); 5404f76ee892STomi Valkeinen 5405f76ee892STomi Valkeinen r = dsi_runtime_get(dsidev); 5406f76ee892STomi Valkeinen if (r) 5407f76ee892STomi Valkeinen goto err_runtime_get; 5408f76ee892STomi Valkeinen 5409f76ee892STomi Valkeinen rev = dsi_read_reg(dsidev, DSI_REVISION); 5410f76ee892STomi Valkeinen dev_dbg(&dsidev->dev, "OMAP DSI rev %d.%d\n", 5411f76ee892STomi Valkeinen FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0)); 5412f76ee892STomi Valkeinen 5413f76ee892STomi Valkeinen /* DSI on OMAP3 doesn't have register DSI_GNQ, set number 5414f76ee892STomi Valkeinen * of data to 3 by default */ 5415f76ee892STomi Valkeinen if (dss_has_feature(FEAT_DSI_GNQ)) 5416f76ee892STomi Valkeinen /* NB_DATA_LANES */ 5417f76ee892STomi Valkeinen dsi->num_lanes_supported = 1 + REG_GET(dsidev, DSI_GNQ, 11, 9); 5418f76ee892STomi Valkeinen else 5419f76ee892STomi Valkeinen dsi->num_lanes_supported = 3; 5420f76ee892STomi Valkeinen 5421f76ee892STomi Valkeinen dsi->line_buffer_size = dsi_get_line_buf_size(dsidev); 5422f76ee892STomi Valkeinen 5423f76ee892STomi Valkeinen dsi_init_output(dsidev); 5424f76ee892STomi Valkeinen 5425f76ee892STomi Valkeinen if (dsidev->dev.of_node) { 5426f76ee892STomi Valkeinen r = dsi_probe_of(dsidev); 5427f76ee892STomi Valkeinen if (r) { 5428f76ee892STomi Valkeinen DSSERR("Invalid DSI DT data\n"); 5429f76ee892STomi Valkeinen goto err_probe_of; 5430f76ee892STomi Valkeinen } 5431f76ee892STomi Valkeinen 5432f76ee892STomi Valkeinen r = of_platform_populate(dsidev->dev.of_node, NULL, NULL, 5433f76ee892STomi Valkeinen &dsidev->dev); 5434f76ee892STomi Valkeinen if (r) 5435f76ee892STomi Valkeinen DSSERR("Failed to populate DSI child devices: %d\n", r); 5436f76ee892STomi Valkeinen } 5437f76ee892STomi Valkeinen 5438f76ee892STomi Valkeinen dsi_runtime_put(dsidev); 5439f76ee892STomi Valkeinen 5440f76ee892STomi Valkeinen if (dsi->module_id == 0) 5441f76ee892STomi Valkeinen dss_debugfs_create_file("dsi1_regs", dsi1_dump_regs); 5442f76ee892STomi Valkeinen else if (dsi->module_id == 1) 5443f76ee892STomi Valkeinen dss_debugfs_create_file("dsi2_regs", dsi2_dump_regs); 5444f76ee892STomi Valkeinen 544535b522cfSTomi Valkeinen #ifdef CONFIG_FB_OMAP2_DSS_COLLECT_IRQ_STATS 5446f76ee892STomi Valkeinen if (dsi->module_id == 0) 5447f76ee892STomi Valkeinen dss_debugfs_create_file("dsi1_irqs", dsi1_dump_irqs); 5448f76ee892STomi Valkeinen else if (dsi->module_id == 1) 5449f76ee892STomi Valkeinen dss_debugfs_create_file("dsi2_irqs", dsi2_dump_irqs); 5450f76ee892STomi Valkeinen #endif 5451f76ee892STomi Valkeinen 5452f76ee892STomi Valkeinen return 0; 5453f76ee892STomi Valkeinen 5454f76ee892STomi Valkeinen err_probe_of: 5455f76ee892STomi Valkeinen dsi_uninit_output(dsidev); 5456f76ee892STomi Valkeinen dsi_runtime_put(dsidev); 5457f76ee892STomi Valkeinen 5458f76ee892STomi Valkeinen err_runtime_get: 5459f76ee892STomi Valkeinen pm_runtime_disable(&dsidev->dev); 5460f76ee892STomi Valkeinen return r; 5461f76ee892STomi Valkeinen } 5462f76ee892STomi Valkeinen 5463f76ee892STomi Valkeinen static void dsi_unbind(struct device *dev, struct device *master, void *data) 5464f76ee892STomi Valkeinen { 5465f76ee892STomi Valkeinen struct platform_device *dsidev = to_platform_device(dev); 5466f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 5467f76ee892STomi Valkeinen 5468f76ee892STomi Valkeinen of_platform_depopulate(&dsidev->dev); 5469f76ee892STomi Valkeinen 5470f76ee892STomi Valkeinen WARN_ON(dsi->scp_clk_refcount > 0); 5471f76ee892STomi Valkeinen 5472f76ee892STomi Valkeinen dss_pll_unregister(&dsi->pll); 5473f76ee892STomi Valkeinen 5474f76ee892STomi Valkeinen dsi_uninit_output(dsidev); 5475f76ee892STomi Valkeinen 5476f76ee892STomi Valkeinen pm_runtime_disable(&dsidev->dev); 5477f76ee892STomi Valkeinen 5478f76ee892STomi Valkeinen if (dsi->vdds_dsi_reg != NULL && dsi->vdds_dsi_enabled) { 5479f76ee892STomi Valkeinen regulator_disable(dsi->vdds_dsi_reg); 5480f76ee892STomi Valkeinen dsi->vdds_dsi_enabled = false; 5481f76ee892STomi Valkeinen } 5482f76ee892STomi Valkeinen } 5483f76ee892STomi Valkeinen 5484f76ee892STomi Valkeinen static const struct component_ops dsi_component_ops = { 5485f76ee892STomi Valkeinen .bind = dsi_bind, 5486f76ee892STomi Valkeinen .unbind = dsi_unbind, 5487f76ee892STomi Valkeinen }; 5488f76ee892STomi Valkeinen 5489f76ee892STomi Valkeinen static int dsi_probe(struct platform_device *pdev) 5490f76ee892STomi Valkeinen { 5491f76ee892STomi Valkeinen return component_add(&pdev->dev, &dsi_component_ops); 5492f76ee892STomi Valkeinen } 5493f76ee892STomi Valkeinen 5494f76ee892STomi Valkeinen static int dsi_remove(struct platform_device *pdev) 5495f76ee892STomi Valkeinen { 5496f76ee892STomi Valkeinen component_del(&pdev->dev, &dsi_component_ops); 5497f76ee892STomi Valkeinen return 0; 5498f76ee892STomi Valkeinen } 5499f76ee892STomi Valkeinen 5500f76ee892STomi Valkeinen static int dsi_runtime_suspend(struct device *dev) 5501f76ee892STomi Valkeinen { 5502f76ee892STomi Valkeinen struct platform_device *pdev = to_platform_device(dev); 5503f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(pdev); 5504f76ee892STomi Valkeinen 5505f76ee892STomi Valkeinen dsi->is_enabled = false; 5506f76ee892STomi Valkeinen /* ensure the irq handler sees the is_enabled value */ 5507f76ee892STomi Valkeinen smp_wmb(); 5508f76ee892STomi Valkeinen /* wait for current handler to finish before turning the DSI off */ 5509f76ee892STomi Valkeinen synchronize_irq(dsi->irq); 5510f76ee892STomi Valkeinen 5511f76ee892STomi Valkeinen dispc_runtime_put(); 5512f76ee892STomi Valkeinen 5513f76ee892STomi Valkeinen return 0; 5514f76ee892STomi Valkeinen } 5515f76ee892STomi Valkeinen 5516f76ee892STomi Valkeinen static int dsi_runtime_resume(struct device *dev) 5517f76ee892STomi Valkeinen { 5518f76ee892STomi Valkeinen struct platform_device *pdev = to_platform_device(dev); 5519f76ee892STomi Valkeinen struct dsi_data *dsi = dsi_get_dsidrv_data(pdev); 5520f76ee892STomi Valkeinen int r; 5521f76ee892STomi Valkeinen 5522f76ee892STomi Valkeinen r = dispc_runtime_get(); 5523f76ee892STomi Valkeinen if (r) 5524f76ee892STomi Valkeinen return r; 5525f76ee892STomi Valkeinen 5526f76ee892STomi Valkeinen dsi->is_enabled = true; 5527f76ee892STomi Valkeinen /* ensure the irq handler sees the is_enabled value */ 5528f76ee892STomi Valkeinen smp_wmb(); 5529f76ee892STomi Valkeinen 5530f76ee892STomi Valkeinen return 0; 5531f76ee892STomi Valkeinen } 5532f76ee892STomi Valkeinen 5533f76ee892STomi Valkeinen static const struct dev_pm_ops dsi_pm_ops = { 5534f76ee892STomi Valkeinen .runtime_suspend = dsi_runtime_suspend, 5535f76ee892STomi Valkeinen .runtime_resume = dsi_runtime_resume, 5536f76ee892STomi Valkeinen }; 5537f76ee892STomi Valkeinen 5538f76ee892STomi Valkeinen static const struct dsi_module_id_data dsi_of_data_omap3[] = { 5539f76ee892STomi Valkeinen { .address = 0x4804fc00, .id = 0, }, 5540f76ee892STomi Valkeinen { }, 5541f76ee892STomi Valkeinen }; 5542f76ee892STomi Valkeinen 5543f76ee892STomi Valkeinen static const struct dsi_module_id_data dsi_of_data_omap4[] = { 5544f76ee892STomi Valkeinen { .address = 0x58004000, .id = 0, }, 5545f76ee892STomi Valkeinen { .address = 0x58005000, .id = 1, }, 5546f76ee892STomi Valkeinen { }, 5547f76ee892STomi Valkeinen }; 5548f76ee892STomi Valkeinen 5549f76ee892STomi Valkeinen static const struct dsi_module_id_data dsi_of_data_omap5[] = { 5550f76ee892STomi Valkeinen { .address = 0x58004000, .id = 0, }, 5551f76ee892STomi Valkeinen { .address = 0x58009000, .id = 1, }, 5552f76ee892STomi Valkeinen { }, 5553f76ee892STomi Valkeinen }; 5554f76ee892STomi Valkeinen 5555f76ee892STomi Valkeinen static const struct of_device_id dsi_of_match[] = { 5556f76ee892STomi Valkeinen { .compatible = "ti,omap3-dsi", .data = dsi_of_data_omap3, }, 5557f76ee892STomi Valkeinen { .compatible = "ti,omap4-dsi", .data = dsi_of_data_omap4, }, 5558f76ee892STomi Valkeinen { .compatible = "ti,omap5-dsi", .data = dsi_of_data_omap5, }, 5559f76ee892STomi Valkeinen {}, 5560f76ee892STomi Valkeinen }; 5561f76ee892STomi Valkeinen 5562f76ee892STomi Valkeinen static struct platform_driver omap_dsihw_driver = { 5563f76ee892STomi Valkeinen .probe = dsi_probe, 5564f76ee892STomi Valkeinen .remove = dsi_remove, 5565f76ee892STomi Valkeinen .driver = { 5566f76ee892STomi Valkeinen .name = "omapdss_dsi", 5567f76ee892STomi Valkeinen .pm = &dsi_pm_ops, 5568f76ee892STomi Valkeinen .of_match_table = dsi_of_match, 5569f76ee892STomi Valkeinen .suppress_bind_attrs = true, 5570f76ee892STomi Valkeinen }, 5571f76ee892STomi Valkeinen }; 5572f76ee892STomi Valkeinen 5573f76ee892STomi Valkeinen int __init dsi_init_platform_driver(void) 5574f76ee892STomi Valkeinen { 5575f76ee892STomi Valkeinen return platform_driver_register(&omap_dsihw_driver); 5576f76ee892STomi Valkeinen } 5577f76ee892STomi Valkeinen 5578f76ee892STomi Valkeinen void dsi_uninit_platform_driver(void) 5579f76ee892STomi Valkeinen { 5580f76ee892STomi Valkeinen platform_driver_unregister(&omap_dsihw_driver); 5581f76ee892STomi Valkeinen } 5582