Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Texas Instruments |
| 3 | * Author: Rob Clark <robdclark@gmail.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 as published by |
| 7 | * the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | */ |
| 17 | |
| 18 | |
| 19 | |
Russell King | 893c3e5 | 2013-08-27 01:27:42 +0100 | [diff] [blame] | 20 | #include <linux/hdmi.h> |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 21 | #include <linux/module.h> |
Jean-Francois Moine | f0b33b2 | 2014-01-25 18:14:39 +0100 | [diff] [blame^] | 22 | #include <sound/asoundef.h> |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 23 | |
| 24 | #include <drm/drmP.h> |
| 25 | #include <drm/drm_crtc_helper.h> |
| 26 | #include <drm/drm_encoder_slave.h> |
| 27 | #include <drm/drm_edid.h> |
Russell King | c4c11dd | 2013-08-14 21:43:30 +0200 | [diff] [blame] | 28 | #include <drm/i2c/tda998x.h> |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 29 | |
| 30 | #define DBG(fmt, ...) DRM_DEBUG(fmt"\n", ##__VA_ARGS__) |
| 31 | |
| 32 | struct tda998x_priv { |
| 33 | struct i2c_client *cec; |
| 34 | uint16_t rev; |
| 35 | uint8_t current_page; |
| 36 | int dpms; |
Russell King | c4c11dd | 2013-08-14 21:43:30 +0200 | [diff] [blame] | 37 | bool is_hdmi_sink; |
Russell King | 5e74c22 | 2013-08-14 21:43:29 +0200 | [diff] [blame] | 38 | u8 vip_cntrl_0; |
| 39 | u8 vip_cntrl_1; |
| 40 | u8 vip_cntrl_2; |
Russell King | c4c11dd | 2013-08-14 21:43:30 +0200 | [diff] [blame] | 41 | struct tda998x_encoder_params params; |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | #define to_tda998x_priv(x) ((struct tda998x_priv *)to_encoder_slave(x)->slave_priv) |
| 45 | |
| 46 | /* The TDA9988 series of devices use a paged register scheme.. to simplify |
| 47 | * things we encode the page # in upper bits of the register #. To read/ |
| 48 | * write a given register, we need to make sure CURPAGE register is set |
| 49 | * appropriately. Which implies reads/writes are not atomic. Fun! |
| 50 | */ |
| 51 | |
| 52 | #define REG(page, addr) (((page) << 8) | (addr)) |
| 53 | #define REG2ADDR(reg) ((reg) & 0xff) |
| 54 | #define REG2PAGE(reg) (((reg) >> 8) & 0xff) |
| 55 | |
| 56 | #define REG_CURPAGE 0xff /* write */ |
| 57 | |
| 58 | |
| 59 | /* Page 00h: General Control */ |
| 60 | #define REG_VERSION_LSB REG(0x00, 0x00) /* read */ |
| 61 | #define REG_MAIN_CNTRL0 REG(0x00, 0x01) /* read/write */ |
| 62 | # define MAIN_CNTRL0_SR (1 << 0) |
| 63 | # define MAIN_CNTRL0_DECS (1 << 1) |
| 64 | # define MAIN_CNTRL0_DEHS (1 << 2) |
| 65 | # define MAIN_CNTRL0_CECS (1 << 3) |
| 66 | # define MAIN_CNTRL0_CEHS (1 << 4) |
| 67 | # define MAIN_CNTRL0_SCALER (1 << 7) |
| 68 | #define REG_VERSION_MSB REG(0x00, 0x02) /* read */ |
| 69 | #define REG_SOFTRESET REG(0x00, 0x0a) /* write */ |
| 70 | # define SOFTRESET_AUDIO (1 << 0) |
| 71 | # define SOFTRESET_I2C_MASTER (1 << 1) |
| 72 | #define REG_DDC_DISABLE REG(0x00, 0x0b) /* read/write */ |
| 73 | #define REG_CCLK_ON REG(0x00, 0x0c) /* read/write */ |
| 74 | #define REG_I2C_MASTER REG(0x00, 0x0d) /* read/write */ |
| 75 | # define I2C_MASTER_DIS_MM (1 << 0) |
| 76 | # define I2C_MASTER_DIS_FILT (1 << 1) |
| 77 | # define I2C_MASTER_APP_STRT_LAT (1 << 2) |
Russell King | c4c11dd | 2013-08-14 21:43:30 +0200 | [diff] [blame] | 78 | #define REG_FEAT_POWERDOWN REG(0x00, 0x0e) /* read/write */ |
| 79 | # define FEAT_POWERDOWN_SPDIF (1 << 3) |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 80 | #define REG_INT_FLAGS_0 REG(0x00, 0x0f) /* read/write */ |
| 81 | #define REG_INT_FLAGS_1 REG(0x00, 0x10) /* read/write */ |
| 82 | #define REG_INT_FLAGS_2 REG(0x00, 0x11) /* read/write */ |
| 83 | # define INT_FLAGS_2_EDID_BLK_RD (1 << 1) |
Russell King | c4c11dd | 2013-08-14 21:43:30 +0200 | [diff] [blame] | 84 | #define REG_ENA_ACLK REG(0x00, 0x16) /* read/write */ |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 85 | #define REG_ENA_VP_0 REG(0x00, 0x18) /* read/write */ |
| 86 | #define REG_ENA_VP_1 REG(0x00, 0x19) /* read/write */ |
| 87 | #define REG_ENA_VP_2 REG(0x00, 0x1a) /* read/write */ |
| 88 | #define REG_ENA_AP REG(0x00, 0x1e) /* read/write */ |
| 89 | #define REG_VIP_CNTRL_0 REG(0x00, 0x20) /* write */ |
| 90 | # define VIP_CNTRL_0_MIRR_A (1 << 7) |
| 91 | # define VIP_CNTRL_0_SWAP_A(x) (((x) & 7) << 4) |
| 92 | # define VIP_CNTRL_0_MIRR_B (1 << 3) |
| 93 | # define VIP_CNTRL_0_SWAP_B(x) (((x) & 7) << 0) |
| 94 | #define REG_VIP_CNTRL_1 REG(0x00, 0x21) /* write */ |
| 95 | # define VIP_CNTRL_1_MIRR_C (1 << 7) |
| 96 | # define VIP_CNTRL_1_SWAP_C(x) (((x) & 7) << 4) |
| 97 | # define VIP_CNTRL_1_MIRR_D (1 << 3) |
| 98 | # define VIP_CNTRL_1_SWAP_D(x) (((x) & 7) << 0) |
| 99 | #define REG_VIP_CNTRL_2 REG(0x00, 0x22) /* write */ |
| 100 | # define VIP_CNTRL_2_MIRR_E (1 << 7) |
| 101 | # define VIP_CNTRL_2_SWAP_E(x) (((x) & 7) << 4) |
| 102 | # define VIP_CNTRL_2_MIRR_F (1 << 3) |
| 103 | # define VIP_CNTRL_2_SWAP_F(x) (((x) & 7) << 0) |
| 104 | #define REG_VIP_CNTRL_3 REG(0x00, 0x23) /* write */ |
| 105 | # define VIP_CNTRL_3_X_TGL (1 << 0) |
| 106 | # define VIP_CNTRL_3_H_TGL (1 << 1) |
| 107 | # define VIP_CNTRL_3_V_TGL (1 << 2) |
| 108 | # define VIP_CNTRL_3_EMB (1 << 3) |
| 109 | # define VIP_CNTRL_3_SYNC_DE (1 << 4) |
| 110 | # define VIP_CNTRL_3_SYNC_HS (1 << 5) |
| 111 | # define VIP_CNTRL_3_DE_INT (1 << 6) |
| 112 | # define VIP_CNTRL_3_EDGE (1 << 7) |
| 113 | #define REG_VIP_CNTRL_4 REG(0x00, 0x24) /* write */ |
| 114 | # define VIP_CNTRL_4_BLC(x) (((x) & 3) << 0) |
| 115 | # define VIP_CNTRL_4_BLANKIT(x) (((x) & 3) << 2) |
| 116 | # define VIP_CNTRL_4_CCIR656 (1 << 4) |
| 117 | # define VIP_CNTRL_4_656_ALT (1 << 5) |
| 118 | # define VIP_CNTRL_4_TST_656 (1 << 6) |
| 119 | # define VIP_CNTRL_4_TST_PAT (1 << 7) |
| 120 | #define REG_VIP_CNTRL_5 REG(0x00, 0x25) /* write */ |
| 121 | # define VIP_CNTRL_5_CKCASE (1 << 0) |
| 122 | # define VIP_CNTRL_5_SP_CNT(x) (((x) & 3) << 1) |
Russell King | c4c11dd | 2013-08-14 21:43:30 +0200 | [diff] [blame] | 123 | #define REG_MUX_AP REG(0x00, 0x26) /* read/write */ |
Russell King | bcb2481 | 2013-08-14 21:43:27 +0200 | [diff] [blame] | 124 | #define REG_MUX_VP_VIP_OUT REG(0x00, 0x27) /* read/write */ |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 125 | #define REG_MAT_CONTRL REG(0x00, 0x80) /* write */ |
| 126 | # define MAT_CONTRL_MAT_SC(x) (((x) & 3) << 0) |
| 127 | # define MAT_CONTRL_MAT_BP (1 << 2) |
| 128 | #define REG_VIDFORMAT REG(0x00, 0xa0) /* write */ |
| 129 | #define REG_REFPIX_MSB REG(0x00, 0xa1) /* write */ |
| 130 | #define REG_REFPIX_LSB REG(0x00, 0xa2) /* write */ |
| 131 | #define REG_REFLINE_MSB REG(0x00, 0xa3) /* write */ |
| 132 | #define REG_REFLINE_LSB REG(0x00, 0xa4) /* write */ |
| 133 | #define REG_NPIX_MSB REG(0x00, 0xa5) /* write */ |
| 134 | #define REG_NPIX_LSB REG(0x00, 0xa6) /* write */ |
| 135 | #define REG_NLINE_MSB REG(0x00, 0xa7) /* write */ |
| 136 | #define REG_NLINE_LSB REG(0x00, 0xa8) /* write */ |
| 137 | #define REG_VS_LINE_STRT_1_MSB REG(0x00, 0xa9) /* write */ |
| 138 | #define REG_VS_LINE_STRT_1_LSB REG(0x00, 0xaa) /* write */ |
| 139 | #define REG_VS_PIX_STRT_1_MSB REG(0x00, 0xab) /* write */ |
| 140 | #define REG_VS_PIX_STRT_1_LSB REG(0x00, 0xac) /* write */ |
| 141 | #define REG_VS_LINE_END_1_MSB REG(0x00, 0xad) /* write */ |
| 142 | #define REG_VS_LINE_END_1_LSB REG(0x00, 0xae) /* write */ |
| 143 | #define REG_VS_PIX_END_1_MSB REG(0x00, 0xaf) /* write */ |
| 144 | #define REG_VS_PIX_END_1_LSB REG(0x00, 0xb0) /* write */ |
Sebastian Hesselbarth | 088d61d | 2013-08-14 21:43:31 +0200 | [diff] [blame] | 145 | #define REG_VS_LINE_STRT_2_MSB REG(0x00, 0xb1) /* write */ |
| 146 | #define REG_VS_LINE_STRT_2_LSB REG(0x00, 0xb2) /* write */ |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 147 | #define REG_VS_PIX_STRT_2_MSB REG(0x00, 0xb3) /* write */ |
| 148 | #define REG_VS_PIX_STRT_2_LSB REG(0x00, 0xb4) /* write */ |
Sebastian Hesselbarth | 088d61d | 2013-08-14 21:43:31 +0200 | [diff] [blame] | 149 | #define REG_VS_LINE_END_2_MSB REG(0x00, 0xb5) /* write */ |
| 150 | #define REG_VS_LINE_END_2_LSB REG(0x00, 0xb6) /* write */ |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 151 | #define REG_VS_PIX_END_2_MSB REG(0x00, 0xb7) /* write */ |
| 152 | #define REG_VS_PIX_END_2_LSB REG(0x00, 0xb8) /* write */ |
| 153 | #define REG_HS_PIX_START_MSB REG(0x00, 0xb9) /* write */ |
| 154 | #define REG_HS_PIX_START_LSB REG(0x00, 0xba) /* write */ |
| 155 | #define REG_HS_PIX_STOP_MSB REG(0x00, 0xbb) /* write */ |
| 156 | #define REG_HS_PIX_STOP_LSB REG(0x00, 0xbc) /* write */ |
| 157 | #define REG_VWIN_START_1_MSB REG(0x00, 0xbd) /* write */ |
| 158 | #define REG_VWIN_START_1_LSB REG(0x00, 0xbe) /* write */ |
| 159 | #define REG_VWIN_END_1_MSB REG(0x00, 0xbf) /* write */ |
| 160 | #define REG_VWIN_END_1_LSB REG(0x00, 0xc0) /* write */ |
Sebastian Hesselbarth | 088d61d | 2013-08-14 21:43:31 +0200 | [diff] [blame] | 161 | #define REG_VWIN_START_2_MSB REG(0x00, 0xc1) /* write */ |
| 162 | #define REG_VWIN_START_2_LSB REG(0x00, 0xc2) /* write */ |
| 163 | #define REG_VWIN_END_2_MSB REG(0x00, 0xc3) /* write */ |
| 164 | #define REG_VWIN_END_2_LSB REG(0x00, 0xc4) /* write */ |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 165 | #define REG_DE_START_MSB REG(0x00, 0xc5) /* write */ |
| 166 | #define REG_DE_START_LSB REG(0x00, 0xc6) /* write */ |
| 167 | #define REG_DE_STOP_MSB REG(0x00, 0xc7) /* write */ |
| 168 | #define REG_DE_STOP_LSB REG(0x00, 0xc8) /* write */ |
| 169 | #define REG_TBG_CNTRL_0 REG(0x00, 0xca) /* write */ |
Sebastian Hesselbarth | 088d61d | 2013-08-14 21:43:31 +0200 | [diff] [blame] | 170 | # define TBG_CNTRL_0_TOP_TGL (1 << 0) |
| 171 | # define TBG_CNTRL_0_TOP_SEL (1 << 1) |
| 172 | # define TBG_CNTRL_0_DE_EXT (1 << 2) |
| 173 | # define TBG_CNTRL_0_TOP_EXT (1 << 3) |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 174 | # define TBG_CNTRL_0_FRAME_DIS (1 << 5) |
| 175 | # define TBG_CNTRL_0_SYNC_MTHD (1 << 6) |
| 176 | # define TBG_CNTRL_0_SYNC_ONCE (1 << 7) |
| 177 | #define REG_TBG_CNTRL_1 REG(0x00, 0xcb) /* write */ |
Sebastian Hesselbarth | 088d61d | 2013-08-14 21:43:31 +0200 | [diff] [blame] | 178 | # define TBG_CNTRL_1_H_TGL (1 << 0) |
| 179 | # define TBG_CNTRL_1_V_TGL (1 << 1) |
| 180 | # define TBG_CNTRL_1_TGL_EN (1 << 2) |
| 181 | # define TBG_CNTRL_1_X_EXT (1 << 3) |
| 182 | # define TBG_CNTRL_1_H_EXT (1 << 4) |
| 183 | # define TBG_CNTRL_1_V_EXT (1 << 5) |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 184 | # define TBG_CNTRL_1_DWIN_DIS (1 << 6) |
| 185 | #define REG_ENABLE_SPACE REG(0x00, 0xd6) /* write */ |
| 186 | #define REG_HVF_CNTRL_0 REG(0x00, 0xe4) /* write */ |
| 187 | # define HVF_CNTRL_0_SM (1 << 7) |
| 188 | # define HVF_CNTRL_0_RWB (1 << 6) |
| 189 | # define HVF_CNTRL_0_PREFIL(x) (((x) & 3) << 2) |
| 190 | # define HVF_CNTRL_0_INTPOL(x) (((x) & 3) << 0) |
| 191 | #define REG_HVF_CNTRL_1 REG(0x00, 0xe5) /* write */ |
| 192 | # define HVF_CNTRL_1_FOR (1 << 0) |
| 193 | # define HVF_CNTRL_1_YUVBLK (1 << 1) |
| 194 | # define HVF_CNTRL_1_VQR(x) (((x) & 3) << 2) |
| 195 | # define HVF_CNTRL_1_PAD(x) (((x) & 3) << 4) |
| 196 | # define HVF_CNTRL_1_SEMI_PLANAR (1 << 6) |
| 197 | #define REG_RPT_CNTRL REG(0x00, 0xf0) /* write */ |
Russell King | c4c11dd | 2013-08-14 21:43:30 +0200 | [diff] [blame] | 198 | #define REG_I2S_FORMAT REG(0x00, 0xfc) /* read/write */ |
| 199 | # define I2S_FORMAT(x) (((x) & 3) << 0) |
| 200 | #define REG_AIP_CLKSEL REG(0x00, 0xfd) /* write */ |
| 201 | # define AIP_CLKSEL_FS(x) (((x) & 3) << 0) |
| 202 | # define AIP_CLKSEL_CLK_POL(x) (((x) & 1) << 2) |
| 203 | # define AIP_CLKSEL_AIP(x) (((x) & 7) << 3) |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 204 | |
| 205 | |
| 206 | /* Page 02h: PLL settings */ |
| 207 | #define REG_PLL_SERIAL_1 REG(0x02, 0x00) /* read/write */ |
| 208 | # define PLL_SERIAL_1_SRL_FDN (1 << 0) |
| 209 | # define PLL_SERIAL_1_SRL_IZ(x) (((x) & 3) << 1) |
| 210 | # define PLL_SERIAL_1_SRL_MAN_IZ (1 << 6) |
| 211 | #define REG_PLL_SERIAL_2 REG(0x02, 0x01) /* read/write */ |
Jean-Francois Moine | 3ae471f | 2014-01-25 18:14:36 +0100 | [diff] [blame] | 212 | # define PLL_SERIAL_2_SRL_NOSC(x) ((x) << 0) |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 213 | # define PLL_SERIAL_2_SRL_PR(x) (((x) & 0xf) << 4) |
| 214 | #define REG_PLL_SERIAL_3 REG(0x02, 0x02) /* read/write */ |
| 215 | # define PLL_SERIAL_3_SRL_CCIR (1 << 0) |
| 216 | # define PLL_SERIAL_3_SRL_DE (1 << 2) |
| 217 | # define PLL_SERIAL_3_SRL_PXIN_SEL (1 << 4) |
| 218 | #define REG_SERIALIZER REG(0x02, 0x03) /* read/write */ |
| 219 | #define REG_BUFFER_OUT REG(0x02, 0x04) /* read/write */ |
| 220 | #define REG_PLL_SCG1 REG(0x02, 0x05) /* read/write */ |
| 221 | #define REG_PLL_SCG2 REG(0x02, 0x06) /* read/write */ |
| 222 | #define REG_PLL_SCGN1 REG(0x02, 0x07) /* read/write */ |
| 223 | #define REG_PLL_SCGN2 REG(0x02, 0x08) /* read/write */ |
| 224 | #define REG_PLL_SCGR1 REG(0x02, 0x09) /* read/write */ |
| 225 | #define REG_PLL_SCGR2 REG(0x02, 0x0a) /* read/write */ |
| 226 | #define REG_AUDIO_DIV REG(0x02, 0x0e) /* read/write */ |
Russell King | c4c11dd | 2013-08-14 21:43:30 +0200 | [diff] [blame] | 227 | # define AUDIO_DIV_SERCLK_1 0 |
| 228 | # define AUDIO_DIV_SERCLK_2 1 |
| 229 | # define AUDIO_DIV_SERCLK_4 2 |
| 230 | # define AUDIO_DIV_SERCLK_8 3 |
| 231 | # define AUDIO_DIV_SERCLK_16 4 |
| 232 | # define AUDIO_DIV_SERCLK_32 5 |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 233 | #define REG_SEL_CLK REG(0x02, 0x11) /* read/write */ |
| 234 | # define SEL_CLK_SEL_CLK1 (1 << 0) |
| 235 | # define SEL_CLK_SEL_VRF_CLK(x) (((x) & 3) << 1) |
| 236 | # define SEL_CLK_ENA_SC_CLK (1 << 3) |
| 237 | #define REG_ANA_GENERAL REG(0x02, 0x12) /* read/write */ |
| 238 | |
| 239 | |
| 240 | /* Page 09h: EDID Control */ |
| 241 | #define REG_EDID_DATA_0 REG(0x09, 0x00) /* read */ |
| 242 | /* next 127 successive registers are the EDID block */ |
| 243 | #define REG_EDID_CTRL REG(0x09, 0xfa) /* read/write */ |
| 244 | #define REG_DDC_ADDR REG(0x09, 0xfb) /* read/write */ |
| 245 | #define REG_DDC_OFFS REG(0x09, 0xfc) /* read/write */ |
| 246 | #define REG_DDC_SEGM_ADDR REG(0x09, 0xfd) /* read/write */ |
| 247 | #define REG_DDC_SEGM REG(0x09, 0xfe) /* read/write */ |
| 248 | |
| 249 | |
| 250 | /* Page 10h: information frames and packets */ |
Russell King | c4c11dd | 2013-08-14 21:43:30 +0200 | [diff] [blame] | 251 | #define REG_IF1_HB0 REG(0x10, 0x20) /* read/write */ |
| 252 | #define REG_IF2_HB0 REG(0x10, 0x40) /* read/write */ |
| 253 | #define REG_IF3_HB0 REG(0x10, 0x60) /* read/write */ |
| 254 | #define REG_IF4_HB0 REG(0x10, 0x80) /* read/write */ |
| 255 | #define REG_IF5_HB0 REG(0x10, 0xa0) /* read/write */ |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 256 | |
| 257 | |
| 258 | /* Page 11h: audio settings and content info packets */ |
| 259 | #define REG_AIP_CNTRL_0 REG(0x11, 0x00) /* read/write */ |
| 260 | # define AIP_CNTRL_0_RST_FIFO (1 << 0) |
| 261 | # define AIP_CNTRL_0_SWAP (1 << 1) |
| 262 | # define AIP_CNTRL_0_LAYOUT (1 << 2) |
| 263 | # define AIP_CNTRL_0_ACR_MAN (1 << 5) |
| 264 | # define AIP_CNTRL_0_RST_CTS (1 << 6) |
Russell King | c4c11dd | 2013-08-14 21:43:30 +0200 | [diff] [blame] | 265 | #define REG_CA_I2S REG(0x11, 0x01) /* read/write */ |
| 266 | # define CA_I2S_CA_I2S(x) (((x) & 31) << 0) |
| 267 | # define CA_I2S_HBR_CHSTAT (1 << 6) |
| 268 | #define REG_LATENCY_RD REG(0x11, 0x04) /* read/write */ |
| 269 | #define REG_ACR_CTS_0 REG(0x11, 0x05) /* read/write */ |
| 270 | #define REG_ACR_CTS_1 REG(0x11, 0x06) /* read/write */ |
| 271 | #define REG_ACR_CTS_2 REG(0x11, 0x07) /* read/write */ |
| 272 | #define REG_ACR_N_0 REG(0x11, 0x08) /* read/write */ |
| 273 | #define REG_ACR_N_1 REG(0x11, 0x09) /* read/write */ |
| 274 | #define REG_ACR_N_2 REG(0x11, 0x0a) /* read/write */ |
| 275 | #define REG_CTS_N REG(0x11, 0x0c) /* read/write */ |
| 276 | # define CTS_N_K(x) (((x) & 7) << 0) |
| 277 | # define CTS_N_M(x) (((x) & 3) << 4) |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 278 | #define REG_ENC_CNTRL REG(0x11, 0x0d) /* read/write */ |
| 279 | # define ENC_CNTRL_RST_ENC (1 << 0) |
| 280 | # define ENC_CNTRL_RST_SEL (1 << 1) |
| 281 | # define ENC_CNTRL_CTL_CODE(x) (((x) & 3) << 2) |
Russell King | c4c11dd | 2013-08-14 21:43:30 +0200 | [diff] [blame] | 282 | #define REG_DIP_FLAGS REG(0x11, 0x0e) /* read/write */ |
| 283 | # define DIP_FLAGS_ACR (1 << 0) |
| 284 | # define DIP_FLAGS_GC (1 << 1) |
| 285 | #define REG_DIP_IF_FLAGS REG(0x11, 0x0f) /* read/write */ |
| 286 | # define DIP_IF_FLAGS_IF1 (1 << 1) |
| 287 | # define DIP_IF_FLAGS_IF2 (1 << 2) |
| 288 | # define DIP_IF_FLAGS_IF3 (1 << 3) |
| 289 | # define DIP_IF_FLAGS_IF4 (1 << 4) |
| 290 | # define DIP_IF_FLAGS_IF5 (1 << 5) |
| 291 | #define REG_CH_STAT_B(x) REG(0x11, 0x14 + (x)) /* read/write */ |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 292 | |
| 293 | |
| 294 | /* Page 12h: HDCP and OTP */ |
| 295 | #define REG_TX3 REG(0x12, 0x9a) /* read/write */ |
Russell King | 063b472 | 2013-08-14 21:43:26 +0200 | [diff] [blame] | 296 | #define REG_TX4 REG(0x12, 0x9b) /* read/write */ |
| 297 | # define TX4_PD_RAM (1 << 1) |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 298 | #define REG_TX33 REG(0x12, 0xb8) /* read/write */ |
| 299 | # define TX33_HDMI (1 << 1) |
| 300 | |
| 301 | |
| 302 | /* Page 13h: Gamut related metadata packets */ |
| 303 | |
| 304 | |
| 305 | |
| 306 | /* CEC registers: (not paged) |
| 307 | */ |
| 308 | #define REG_CEC_FRO_IM_CLK_CTRL 0xfb /* read/write */ |
| 309 | # define CEC_FRO_IM_CLK_CTRL_GHOST_DIS (1 << 7) |
| 310 | # define CEC_FRO_IM_CLK_CTRL_ENA_OTP (1 << 6) |
| 311 | # define CEC_FRO_IM_CLK_CTRL_IMCLK_SEL (1 << 1) |
| 312 | # define CEC_FRO_IM_CLK_CTRL_FRO_DIV (1 << 0) |
| 313 | #define REG_CEC_RXSHPDLEV 0xfe /* read */ |
| 314 | # define CEC_RXSHPDLEV_RXSENS (1 << 0) |
| 315 | # define CEC_RXSHPDLEV_HPD (1 << 1) |
| 316 | |
| 317 | #define REG_CEC_ENAMODS 0xff /* read/write */ |
| 318 | # define CEC_ENAMODS_DIS_FRO (1 << 6) |
| 319 | # define CEC_ENAMODS_DIS_CCLK (1 << 5) |
| 320 | # define CEC_ENAMODS_EN_RXSENS (1 << 2) |
| 321 | # define CEC_ENAMODS_EN_HDMI (1 << 1) |
| 322 | # define CEC_ENAMODS_EN_CEC (1 << 0) |
| 323 | |
| 324 | |
| 325 | /* Device versions: */ |
| 326 | #define TDA9989N2 0x0101 |
| 327 | #define TDA19989 0x0201 |
| 328 | #define TDA19989N2 0x0202 |
| 329 | #define TDA19988 0x0301 |
| 330 | |
| 331 | static void |
| 332 | cec_write(struct drm_encoder *encoder, uint16_t addr, uint8_t val) |
| 333 | { |
| 334 | struct i2c_client *client = to_tda998x_priv(encoder)->cec; |
| 335 | uint8_t buf[] = {addr, val}; |
| 336 | int ret; |
| 337 | |
| 338 | ret = i2c_master_send(client, buf, ARRAY_SIZE(buf)); |
| 339 | if (ret < 0) |
| 340 | dev_err(&client->dev, "Error %d writing to cec:0x%x\n", ret, addr); |
| 341 | } |
| 342 | |
| 343 | static uint8_t |
| 344 | cec_read(struct drm_encoder *encoder, uint8_t addr) |
| 345 | { |
| 346 | struct i2c_client *client = to_tda998x_priv(encoder)->cec; |
| 347 | uint8_t val; |
| 348 | int ret; |
| 349 | |
| 350 | ret = i2c_master_send(client, &addr, sizeof(addr)); |
| 351 | if (ret < 0) |
| 352 | goto fail; |
| 353 | |
| 354 | ret = i2c_master_recv(client, &val, sizeof(val)); |
| 355 | if (ret < 0) |
| 356 | goto fail; |
| 357 | |
| 358 | return val; |
| 359 | |
| 360 | fail: |
| 361 | dev_err(&client->dev, "Error %d reading from cec:0x%x\n", ret, addr); |
| 362 | return 0; |
| 363 | } |
| 364 | |
| 365 | static void |
| 366 | set_page(struct drm_encoder *encoder, uint16_t reg) |
| 367 | { |
| 368 | struct tda998x_priv *priv = to_tda998x_priv(encoder); |
| 369 | |
| 370 | if (REG2PAGE(reg) != priv->current_page) { |
| 371 | struct i2c_client *client = drm_i2c_encoder_get_client(encoder); |
| 372 | uint8_t buf[] = { |
| 373 | REG_CURPAGE, REG2PAGE(reg) |
| 374 | }; |
| 375 | int ret = i2c_master_send(client, buf, sizeof(buf)); |
| 376 | if (ret < 0) |
| 377 | dev_err(&client->dev, "Error %d writing to REG_CURPAGE\n", ret); |
| 378 | |
| 379 | priv->current_page = REG2PAGE(reg); |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | static int |
| 384 | reg_read_range(struct drm_encoder *encoder, uint16_t reg, char *buf, int cnt) |
| 385 | { |
| 386 | struct i2c_client *client = drm_i2c_encoder_get_client(encoder); |
| 387 | uint8_t addr = REG2ADDR(reg); |
| 388 | int ret; |
| 389 | |
| 390 | set_page(encoder, reg); |
| 391 | |
| 392 | ret = i2c_master_send(client, &addr, sizeof(addr)); |
| 393 | if (ret < 0) |
| 394 | goto fail; |
| 395 | |
| 396 | ret = i2c_master_recv(client, buf, cnt); |
| 397 | if (ret < 0) |
| 398 | goto fail; |
| 399 | |
| 400 | return ret; |
| 401 | |
| 402 | fail: |
| 403 | dev_err(&client->dev, "Error %d reading from 0x%x\n", ret, reg); |
| 404 | return ret; |
| 405 | } |
| 406 | |
Russell King | c4c11dd | 2013-08-14 21:43:30 +0200 | [diff] [blame] | 407 | static void |
| 408 | reg_write_range(struct drm_encoder *encoder, uint16_t reg, uint8_t *p, int cnt) |
| 409 | { |
| 410 | struct i2c_client *client = drm_i2c_encoder_get_client(encoder); |
| 411 | uint8_t buf[cnt+1]; |
| 412 | int ret; |
| 413 | |
| 414 | buf[0] = REG2ADDR(reg); |
| 415 | memcpy(&buf[1], p, cnt); |
| 416 | |
| 417 | set_page(encoder, reg); |
| 418 | |
| 419 | ret = i2c_master_send(client, buf, cnt + 1); |
| 420 | if (ret < 0) |
| 421 | dev_err(&client->dev, "Error %d writing to 0x%x\n", ret, reg); |
| 422 | } |
| 423 | |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 424 | static uint8_t |
| 425 | reg_read(struct drm_encoder *encoder, uint16_t reg) |
| 426 | { |
| 427 | uint8_t val = 0; |
| 428 | reg_read_range(encoder, reg, &val, sizeof(val)); |
| 429 | return val; |
| 430 | } |
| 431 | |
| 432 | static void |
| 433 | reg_write(struct drm_encoder *encoder, uint16_t reg, uint8_t val) |
| 434 | { |
| 435 | struct i2c_client *client = drm_i2c_encoder_get_client(encoder); |
| 436 | uint8_t buf[] = {REG2ADDR(reg), val}; |
| 437 | int ret; |
| 438 | |
| 439 | set_page(encoder, reg); |
| 440 | |
| 441 | ret = i2c_master_send(client, buf, ARRAY_SIZE(buf)); |
| 442 | if (ret < 0) |
| 443 | dev_err(&client->dev, "Error %d writing to 0x%x\n", ret, reg); |
| 444 | } |
| 445 | |
| 446 | static void |
| 447 | reg_write16(struct drm_encoder *encoder, uint16_t reg, uint16_t val) |
| 448 | { |
| 449 | struct i2c_client *client = drm_i2c_encoder_get_client(encoder); |
| 450 | uint8_t buf[] = {REG2ADDR(reg), val >> 8, val}; |
| 451 | int ret; |
| 452 | |
| 453 | set_page(encoder, reg); |
| 454 | |
| 455 | ret = i2c_master_send(client, buf, ARRAY_SIZE(buf)); |
| 456 | if (ret < 0) |
| 457 | dev_err(&client->dev, "Error %d writing to 0x%x\n", ret, reg); |
| 458 | } |
| 459 | |
| 460 | static void |
| 461 | reg_set(struct drm_encoder *encoder, uint16_t reg, uint8_t val) |
| 462 | { |
| 463 | reg_write(encoder, reg, reg_read(encoder, reg) | val); |
| 464 | } |
| 465 | |
| 466 | static void |
| 467 | reg_clear(struct drm_encoder *encoder, uint16_t reg, uint8_t val) |
| 468 | { |
| 469 | reg_write(encoder, reg, reg_read(encoder, reg) & ~val); |
| 470 | } |
| 471 | |
| 472 | static void |
| 473 | tda998x_reset(struct drm_encoder *encoder) |
| 474 | { |
| 475 | /* reset audio and i2c master: */ |
| 476 | reg_set(encoder, REG_SOFTRESET, SOFTRESET_AUDIO | SOFTRESET_I2C_MASTER); |
| 477 | msleep(50); |
| 478 | reg_clear(encoder, REG_SOFTRESET, SOFTRESET_AUDIO | SOFTRESET_I2C_MASTER); |
| 479 | msleep(50); |
| 480 | |
| 481 | /* reset transmitter: */ |
| 482 | reg_set(encoder, REG_MAIN_CNTRL0, MAIN_CNTRL0_SR); |
| 483 | reg_clear(encoder, REG_MAIN_CNTRL0, MAIN_CNTRL0_SR); |
| 484 | |
| 485 | /* PLL registers common configuration */ |
| 486 | reg_write(encoder, REG_PLL_SERIAL_1, 0x00); |
| 487 | reg_write(encoder, REG_PLL_SERIAL_2, PLL_SERIAL_2_SRL_NOSC(1)); |
| 488 | reg_write(encoder, REG_PLL_SERIAL_3, 0x00); |
| 489 | reg_write(encoder, REG_SERIALIZER, 0x00); |
| 490 | reg_write(encoder, REG_BUFFER_OUT, 0x00); |
| 491 | reg_write(encoder, REG_PLL_SCG1, 0x00); |
Russell King | c4c11dd | 2013-08-14 21:43:30 +0200 | [diff] [blame] | 492 | reg_write(encoder, REG_AUDIO_DIV, AUDIO_DIV_SERCLK_8); |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 493 | reg_write(encoder, REG_SEL_CLK, SEL_CLK_SEL_CLK1 | SEL_CLK_ENA_SC_CLK); |
| 494 | reg_write(encoder, REG_PLL_SCGN1, 0xfa); |
| 495 | reg_write(encoder, REG_PLL_SCGN2, 0x00); |
| 496 | reg_write(encoder, REG_PLL_SCGR1, 0x5b); |
| 497 | reg_write(encoder, REG_PLL_SCGR2, 0x00); |
| 498 | reg_write(encoder, REG_PLL_SCG2, 0x10); |
Russell King | bcb2481 | 2013-08-14 21:43:27 +0200 | [diff] [blame] | 499 | |
| 500 | /* Write the default value MUX register */ |
| 501 | reg_write(encoder, REG_MUX_VP_VIP_OUT, 0x24); |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 502 | } |
| 503 | |
Russell King | c4c11dd | 2013-08-14 21:43:30 +0200 | [diff] [blame] | 504 | static uint8_t tda998x_cksum(uint8_t *buf, size_t bytes) |
| 505 | { |
| 506 | uint8_t sum = 0; |
| 507 | |
| 508 | while (bytes--) |
| 509 | sum += *buf++; |
| 510 | return (255 - sum) + 1; |
| 511 | } |
| 512 | |
| 513 | #define HB(x) (x) |
| 514 | #define PB(x) (HB(2) + 1 + (x)) |
| 515 | |
| 516 | static void |
| 517 | tda998x_write_if(struct drm_encoder *encoder, uint8_t bit, uint16_t addr, |
| 518 | uint8_t *buf, size_t size) |
| 519 | { |
| 520 | buf[PB(0)] = tda998x_cksum(buf, size); |
| 521 | |
| 522 | reg_clear(encoder, REG_DIP_IF_FLAGS, bit); |
| 523 | reg_write_range(encoder, addr, buf, size); |
| 524 | reg_set(encoder, REG_DIP_IF_FLAGS, bit); |
| 525 | } |
| 526 | |
| 527 | static void |
| 528 | tda998x_write_aif(struct drm_encoder *encoder, struct tda998x_encoder_params *p) |
| 529 | { |
Jean-Francois Moine | 9e54146 | 2014-01-25 18:14:41 +0100 | [diff] [blame] | 530 | u8 buf[PB(HDMI_AUDIO_INFOFRAME_SIZE) + 1]; |
Russell King | c4c11dd | 2013-08-14 21:43:30 +0200 | [diff] [blame] | 531 | |
Jean-Francois Moine | 7288ca0 | 2014-01-25 18:14:44 +0100 | [diff] [blame] | 532 | memset(buf, 0, sizeof(buf)); |
Jean-Francois Moine | 9e54146 | 2014-01-25 18:14:41 +0100 | [diff] [blame] | 533 | buf[HB(0)] = HDMI_INFOFRAME_TYPE_AUDIO; |
Russell King | c4c11dd | 2013-08-14 21:43:30 +0200 | [diff] [blame] | 534 | buf[HB(1)] = 0x01; |
Jean-Francois Moine | 9e54146 | 2014-01-25 18:14:41 +0100 | [diff] [blame] | 535 | buf[HB(2)] = HDMI_AUDIO_INFOFRAME_SIZE; |
Russell King | c4c11dd | 2013-08-14 21:43:30 +0200 | [diff] [blame] | 536 | buf[PB(1)] = p->audio_frame[1] & 0x07; /* CC */ |
| 537 | buf[PB(2)] = p->audio_frame[2] & 0x1c; /* SF */ |
| 538 | buf[PB(4)] = p->audio_frame[4]; |
| 539 | buf[PB(5)] = p->audio_frame[5] & 0xf8; /* DM_INH + LSV */ |
| 540 | |
| 541 | tda998x_write_if(encoder, DIP_IF_FLAGS_IF4, REG_IF4_HB0, buf, |
| 542 | sizeof(buf)); |
| 543 | } |
| 544 | |
| 545 | static void |
| 546 | tda998x_write_avi(struct drm_encoder *encoder, struct drm_display_mode *mode) |
| 547 | { |
Jean-Francois Moine | 9e54146 | 2014-01-25 18:14:41 +0100 | [diff] [blame] | 548 | u8 buf[PB(HDMI_AVI_INFOFRAME_SIZE) + 1]; |
Russell King | c4c11dd | 2013-08-14 21:43:30 +0200 | [diff] [blame] | 549 | |
| 550 | memset(buf, 0, sizeof(buf)); |
Jean-Francois Moine | 9e54146 | 2014-01-25 18:14:41 +0100 | [diff] [blame] | 551 | buf[HB(0)] = HDMI_INFOFRAME_TYPE_AVI; |
Russell King | c4c11dd | 2013-08-14 21:43:30 +0200 | [diff] [blame] | 552 | buf[HB(1)] = 0x02; |
Jean-Francois Moine | 9e54146 | 2014-01-25 18:14:41 +0100 | [diff] [blame] | 553 | buf[HB(2)] = HDMI_AVI_INFOFRAME_SIZE; |
Russell King | 893c3e5 | 2013-08-27 01:27:42 +0100 | [diff] [blame] | 554 | buf[PB(1)] = HDMI_SCAN_MODE_UNDERSCAN; |
Jean-Francois Moine | bdf6345 | 2014-01-25 18:14:40 +0100 | [diff] [blame] | 555 | buf[PB(2)] = HDMI_ACTIVE_ASPECT_PICTURE; |
Russell King | 893c3e5 | 2013-08-27 01:27:42 +0100 | [diff] [blame] | 556 | buf[PB(3)] = HDMI_QUANTIZATION_RANGE_FULL << 2; |
Russell King | c4c11dd | 2013-08-14 21:43:30 +0200 | [diff] [blame] | 557 | buf[PB(4)] = drm_match_cea_mode(mode); |
| 558 | |
| 559 | tda998x_write_if(encoder, DIP_IF_FLAGS_IF2, REG_IF2_HB0, buf, |
| 560 | sizeof(buf)); |
| 561 | } |
| 562 | |
| 563 | static void tda998x_audio_mute(struct drm_encoder *encoder, bool on) |
| 564 | { |
| 565 | if (on) { |
| 566 | reg_set(encoder, REG_SOFTRESET, SOFTRESET_AUDIO); |
| 567 | reg_clear(encoder, REG_SOFTRESET, SOFTRESET_AUDIO); |
| 568 | reg_set(encoder, REG_AIP_CNTRL_0, AIP_CNTRL_0_RST_FIFO); |
| 569 | } else { |
| 570 | reg_clear(encoder, REG_AIP_CNTRL_0, AIP_CNTRL_0_RST_FIFO); |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | static void |
| 575 | tda998x_configure_audio(struct drm_encoder *encoder, |
| 576 | struct drm_display_mode *mode, struct tda998x_encoder_params *p) |
| 577 | { |
| 578 | uint8_t buf[6], clksel_aip, clksel_fs, ca_i2s, cts_n, adiv; |
| 579 | uint32_t n; |
| 580 | |
| 581 | /* Enable audio ports */ |
| 582 | reg_write(encoder, REG_ENA_AP, p->audio_cfg); |
| 583 | reg_write(encoder, REG_ENA_ACLK, p->audio_clk_cfg); |
| 584 | |
| 585 | /* Set audio input source */ |
| 586 | switch (p->audio_format) { |
| 587 | case AFMT_SPDIF: |
| 588 | reg_write(encoder, REG_MUX_AP, 0x40); |
| 589 | clksel_aip = AIP_CLKSEL_AIP(0); |
| 590 | /* FS64SPDIF */ |
| 591 | clksel_fs = AIP_CLKSEL_FS(2); |
| 592 | cts_n = CTS_N_M(3) | CTS_N_K(3); |
| 593 | ca_i2s = 0; |
| 594 | break; |
| 595 | |
| 596 | case AFMT_I2S: |
| 597 | reg_write(encoder, REG_MUX_AP, 0x64); |
| 598 | clksel_aip = AIP_CLKSEL_AIP(1); |
| 599 | /* ACLK */ |
| 600 | clksel_fs = AIP_CLKSEL_FS(0); |
| 601 | cts_n = CTS_N_M(3) | CTS_N_K(3); |
| 602 | ca_i2s = CA_I2S_CA_I2S(0); |
| 603 | break; |
David Herrmann | 3b28802 | 2013-09-01 15:23:04 +0200 | [diff] [blame] | 604 | |
| 605 | default: |
| 606 | BUG(); |
| 607 | return; |
Russell King | c4c11dd | 2013-08-14 21:43:30 +0200 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | reg_write(encoder, REG_AIP_CLKSEL, clksel_aip); |
| 611 | reg_clear(encoder, REG_AIP_CNTRL_0, AIP_CNTRL_0_LAYOUT); |
| 612 | |
| 613 | /* Enable automatic CTS generation */ |
| 614 | reg_clear(encoder, REG_AIP_CNTRL_0, AIP_CNTRL_0_ACR_MAN); |
| 615 | reg_write(encoder, REG_CTS_N, cts_n); |
| 616 | |
| 617 | /* |
| 618 | * Audio input somehow depends on HDMI line rate which is |
| 619 | * related to pixclk. Testing showed that modes with pixclk |
| 620 | * >100MHz need a larger divider while <40MHz need the default. |
| 621 | * There is no detailed info in the datasheet, so we just |
| 622 | * assume 100MHz requires larger divider. |
| 623 | */ |
| 624 | if (mode->clock > 100000) |
| 625 | adiv = AUDIO_DIV_SERCLK_16; |
| 626 | else |
| 627 | adiv = AUDIO_DIV_SERCLK_8; |
| 628 | reg_write(encoder, REG_AUDIO_DIV, adiv); |
| 629 | |
| 630 | /* |
| 631 | * This is the approximate value of N, which happens to be |
| 632 | * the recommended values for non-coherent clocks. |
| 633 | */ |
| 634 | n = 128 * p->audio_sample_rate / 1000; |
| 635 | |
| 636 | /* Write the CTS and N values */ |
| 637 | buf[0] = 0x44; |
| 638 | buf[1] = 0x42; |
| 639 | buf[2] = 0x01; |
| 640 | buf[3] = n; |
| 641 | buf[4] = n >> 8; |
| 642 | buf[5] = n >> 16; |
| 643 | reg_write_range(encoder, REG_ACR_CTS_0, buf, 6); |
| 644 | |
| 645 | /* Set CTS clock reference */ |
| 646 | reg_write(encoder, REG_AIP_CLKSEL, clksel_aip | clksel_fs); |
| 647 | |
| 648 | /* Reset CTS generator */ |
| 649 | reg_set(encoder, REG_AIP_CNTRL_0, AIP_CNTRL_0_RST_CTS); |
| 650 | reg_clear(encoder, REG_AIP_CNTRL_0, AIP_CNTRL_0_RST_CTS); |
| 651 | |
| 652 | /* Write the channel status */ |
Jean-Francois Moine | f0b33b2 | 2014-01-25 18:14:39 +0100 | [diff] [blame^] | 653 | buf[0] = IEC958_AES0_CON_NOT_COPYRIGHT; |
Russell King | c4c11dd | 2013-08-14 21:43:30 +0200 | [diff] [blame] | 654 | buf[1] = 0x00; |
Jean-Francois Moine | f0b33b2 | 2014-01-25 18:14:39 +0100 | [diff] [blame^] | 655 | buf[2] = IEC958_AES3_CON_FS_NOTID; |
| 656 | buf[3] = IEC958_AES4_CON_ORIGFS_NOTID | |
| 657 | IEC958_AES4_CON_MAX_WORDLEN_24; |
Russell King | c4c11dd | 2013-08-14 21:43:30 +0200 | [diff] [blame] | 658 | reg_write_range(encoder, REG_CH_STAT_B(0), buf, 4); |
| 659 | |
| 660 | tda998x_audio_mute(encoder, true); |
| 661 | mdelay(20); |
| 662 | tda998x_audio_mute(encoder, false); |
| 663 | |
| 664 | /* Write the audio information packet */ |
| 665 | tda998x_write_aif(encoder, p); |
| 666 | } |
| 667 | |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 668 | /* DRM encoder functions */ |
| 669 | |
| 670 | static void |
| 671 | tda998x_encoder_set_config(struct drm_encoder *encoder, void *params) |
| 672 | { |
Russell King | c4c11dd | 2013-08-14 21:43:30 +0200 | [diff] [blame] | 673 | struct tda998x_priv *priv = to_tda998x_priv(encoder); |
| 674 | struct tda998x_encoder_params *p = params; |
| 675 | |
| 676 | priv->vip_cntrl_0 = VIP_CNTRL_0_SWAP_A(p->swap_a) | |
| 677 | (p->mirr_a ? VIP_CNTRL_0_MIRR_A : 0) | |
| 678 | VIP_CNTRL_0_SWAP_B(p->swap_b) | |
| 679 | (p->mirr_b ? VIP_CNTRL_0_MIRR_B : 0); |
| 680 | priv->vip_cntrl_1 = VIP_CNTRL_1_SWAP_C(p->swap_c) | |
| 681 | (p->mirr_c ? VIP_CNTRL_1_MIRR_C : 0) | |
| 682 | VIP_CNTRL_1_SWAP_D(p->swap_d) | |
| 683 | (p->mirr_d ? VIP_CNTRL_1_MIRR_D : 0); |
| 684 | priv->vip_cntrl_2 = VIP_CNTRL_2_SWAP_E(p->swap_e) | |
| 685 | (p->mirr_e ? VIP_CNTRL_2_MIRR_E : 0) | |
| 686 | VIP_CNTRL_2_SWAP_F(p->swap_f) | |
| 687 | (p->mirr_f ? VIP_CNTRL_2_MIRR_F : 0); |
| 688 | |
| 689 | priv->params = *p; |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | static void |
| 693 | tda998x_encoder_dpms(struct drm_encoder *encoder, int mode) |
| 694 | { |
| 695 | struct tda998x_priv *priv = to_tda998x_priv(encoder); |
| 696 | |
| 697 | /* we only care about on or off: */ |
| 698 | if (mode != DRM_MODE_DPMS_ON) |
| 699 | mode = DRM_MODE_DPMS_OFF; |
| 700 | |
| 701 | if (mode == priv->dpms) |
| 702 | return; |
| 703 | |
| 704 | switch (mode) { |
| 705 | case DRM_MODE_DPMS_ON: |
Russell King | c4c11dd | 2013-08-14 21:43:30 +0200 | [diff] [blame] | 706 | /* enable video ports, audio will be enabled later */ |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 707 | reg_write(encoder, REG_ENA_VP_0, 0xff); |
| 708 | reg_write(encoder, REG_ENA_VP_1, 0xff); |
| 709 | reg_write(encoder, REG_ENA_VP_2, 0xff); |
| 710 | /* set muxing after enabling ports: */ |
Russell King | 5e74c22 | 2013-08-14 21:43:29 +0200 | [diff] [blame] | 711 | reg_write(encoder, REG_VIP_CNTRL_0, priv->vip_cntrl_0); |
| 712 | reg_write(encoder, REG_VIP_CNTRL_1, priv->vip_cntrl_1); |
| 713 | reg_write(encoder, REG_VIP_CNTRL_2, priv->vip_cntrl_2); |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 714 | break; |
| 715 | case DRM_MODE_DPMS_OFF: |
Russell King | db6aaf4 | 2013-09-24 10:37:13 +0100 | [diff] [blame] | 716 | /* disable video ports */ |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 717 | reg_write(encoder, REG_ENA_VP_0, 0x00); |
| 718 | reg_write(encoder, REG_ENA_VP_1, 0x00); |
| 719 | reg_write(encoder, REG_ENA_VP_2, 0x00); |
| 720 | break; |
| 721 | } |
| 722 | |
| 723 | priv->dpms = mode; |
| 724 | } |
| 725 | |
| 726 | static void |
| 727 | tda998x_encoder_save(struct drm_encoder *encoder) |
| 728 | { |
| 729 | DBG(""); |
| 730 | } |
| 731 | |
| 732 | static void |
| 733 | tda998x_encoder_restore(struct drm_encoder *encoder) |
| 734 | { |
| 735 | DBG(""); |
| 736 | } |
| 737 | |
| 738 | static bool |
| 739 | tda998x_encoder_mode_fixup(struct drm_encoder *encoder, |
| 740 | const struct drm_display_mode *mode, |
| 741 | struct drm_display_mode *adjusted_mode) |
| 742 | { |
| 743 | return true; |
| 744 | } |
| 745 | |
| 746 | static int |
| 747 | tda998x_encoder_mode_valid(struct drm_encoder *encoder, |
| 748 | struct drm_display_mode *mode) |
| 749 | { |
| 750 | return MODE_OK; |
| 751 | } |
| 752 | |
| 753 | static void |
| 754 | tda998x_encoder_mode_set(struct drm_encoder *encoder, |
| 755 | struct drm_display_mode *mode, |
| 756 | struct drm_display_mode *adjusted_mode) |
| 757 | { |
| 758 | struct tda998x_priv *priv = to_tda998x_priv(encoder); |
Sebastian Hesselbarth | 088d61d | 2013-08-14 21:43:31 +0200 | [diff] [blame] | 759 | uint16_t ref_pix, ref_line, n_pix, n_line; |
| 760 | uint16_t hs_pix_s, hs_pix_e; |
| 761 | uint16_t vs1_pix_s, vs1_pix_e, vs1_line_s, vs1_line_e; |
| 762 | uint16_t vs2_pix_s, vs2_pix_e, vs2_line_s, vs2_line_e; |
| 763 | uint16_t vwin1_line_s, vwin1_line_e; |
| 764 | uint16_t vwin2_line_s, vwin2_line_e; |
| 765 | uint16_t de_pix_s, de_pix_e; |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 766 | uint8_t reg, div, rep; |
| 767 | |
Sebastian Hesselbarth | 088d61d | 2013-08-14 21:43:31 +0200 | [diff] [blame] | 768 | /* |
| 769 | * Internally TDA998x is using ITU-R BT.656 style sync but |
| 770 | * we get VESA style sync. TDA998x is using a reference pixel |
| 771 | * relative to ITU to sync to the input frame and for output |
| 772 | * sync generation. Currently, we are using reference detection |
| 773 | * from HS/VS, i.e. REFPIX/REFLINE denote frame start sync point |
| 774 | * which is position of rising VS with coincident rising HS. |
| 775 | * |
| 776 | * Now there is some issues to take care of: |
| 777 | * - HDMI data islands require sync-before-active |
| 778 | * - TDA998x register values must be > 0 to be enabled |
| 779 | * - REFLINE needs an additional offset of +1 |
| 780 | * - REFPIX needs an addtional offset of +1 for UYUV and +3 for RGB |
| 781 | * |
| 782 | * So we add +1 to all horizontal and vertical register values, |
| 783 | * plus an additional +3 for REFPIX as we are using RGB input only. |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 784 | */ |
Sebastian Hesselbarth | 088d61d | 2013-08-14 21:43:31 +0200 | [diff] [blame] | 785 | n_pix = mode->htotal; |
| 786 | n_line = mode->vtotal; |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 787 | |
Sebastian Hesselbarth | 088d61d | 2013-08-14 21:43:31 +0200 | [diff] [blame] | 788 | hs_pix_e = mode->hsync_end - mode->hdisplay; |
| 789 | hs_pix_s = mode->hsync_start - mode->hdisplay; |
| 790 | de_pix_e = mode->htotal; |
| 791 | de_pix_s = mode->htotal - mode->hdisplay; |
| 792 | ref_pix = 3 + hs_pix_s; |
| 793 | |
Sebastian Hesselbarth | 179f1aa | 2013-08-14 21:43:32 +0200 | [diff] [blame] | 794 | /* |
| 795 | * Attached LCD controllers may generate broken sync. Allow |
| 796 | * those to adjust the position of the rising VS edge by adding |
| 797 | * HSKEW to ref_pix. |
| 798 | */ |
| 799 | if (adjusted_mode->flags & DRM_MODE_FLAG_HSKEW) |
| 800 | ref_pix += adjusted_mode->hskew; |
| 801 | |
Sebastian Hesselbarth | 088d61d | 2013-08-14 21:43:31 +0200 | [diff] [blame] | 802 | if ((mode->flags & DRM_MODE_FLAG_INTERLACE) == 0) { |
| 803 | ref_line = 1 + mode->vsync_start - mode->vdisplay; |
| 804 | vwin1_line_s = mode->vtotal - mode->vdisplay - 1; |
| 805 | vwin1_line_e = vwin1_line_s + mode->vdisplay; |
| 806 | vs1_pix_s = vs1_pix_e = hs_pix_s; |
| 807 | vs1_line_s = mode->vsync_start - mode->vdisplay; |
| 808 | vs1_line_e = vs1_line_s + |
| 809 | mode->vsync_end - mode->vsync_start; |
| 810 | vwin2_line_s = vwin2_line_e = 0; |
| 811 | vs2_pix_s = vs2_pix_e = 0; |
| 812 | vs2_line_s = vs2_line_e = 0; |
| 813 | } else { |
| 814 | ref_line = 1 + (mode->vsync_start - mode->vdisplay)/2; |
| 815 | vwin1_line_s = (mode->vtotal - mode->vdisplay)/2; |
| 816 | vwin1_line_e = vwin1_line_s + mode->vdisplay/2; |
| 817 | vs1_pix_s = vs1_pix_e = hs_pix_s; |
| 818 | vs1_line_s = (mode->vsync_start - mode->vdisplay)/2; |
| 819 | vs1_line_e = vs1_line_s + |
| 820 | (mode->vsync_end - mode->vsync_start)/2; |
| 821 | vwin2_line_s = vwin1_line_s + mode->vtotal/2; |
| 822 | vwin2_line_e = vwin2_line_s + mode->vdisplay/2; |
| 823 | vs2_pix_s = vs2_pix_e = hs_pix_s + mode->htotal/2; |
| 824 | vs2_line_s = vs1_line_s + mode->vtotal/2 ; |
| 825 | vs2_line_e = vs2_line_s + |
| 826 | (mode->vsync_end - mode->vsync_start)/2; |
| 827 | } |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 828 | |
| 829 | div = 148500 / mode->clock; |
Jean-Francois Moine | 3ae471f | 2014-01-25 18:14:36 +0100 | [diff] [blame] | 830 | if (div != 0) { |
| 831 | div--; |
| 832 | if (div > 3) |
| 833 | div = 3; |
| 834 | } |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 835 | |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 836 | /* mute the audio FIFO: */ |
| 837 | reg_set(encoder, REG_AIP_CNTRL_0, AIP_CNTRL_0_RST_FIFO); |
| 838 | |
| 839 | /* set HDMI HDCP mode off: */ |
| 840 | reg_set(encoder, REG_TBG_CNTRL_1, TBG_CNTRL_1_DWIN_DIS); |
| 841 | reg_clear(encoder, REG_TX33, TX33_HDMI); |
| 842 | |
| 843 | reg_write(encoder, REG_ENC_CNTRL, ENC_CNTRL_CTL_CODE(0)); |
| 844 | /* no pre-filter or interpolator: */ |
| 845 | reg_write(encoder, REG_HVF_CNTRL_0, HVF_CNTRL_0_PREFIL(0) | |
| 846 | HVF_CNTRL_0_INTPOL(0)); |
| 847 | reg_write(encoder, REG_VIP_CNTRL_5, VIP_CNTRL_5_SP_CNT(0)); |
| 848 | reg_write(encoder, REG_VIP_CNTRL_4, VIP_CNTRL_4_BLANKIT(0) | |
| 849 | VIP_CNTRL_4_BLC(0)); |
| 850 | reg_clear(encoder, REG_PLL_SERIAL_3, PLL_SERIAL_3_SRL_CCIR); |
| 851 | |
| 852 | reg_clear(encoder, REG_PLL_SERIAL_1, PLL_SERIAL_1_SRL_MAN_IZ); |
| 853 | reg_clear(encoder, REG_PLL_SERIAL_3, PLL_SERIAL_3_SRL_DE); |
| 854 | reg_write(encoder, REG_SERIALIZER, 0); |
| 855 | reg_write(encoder, REG_HVF_CNTRL_1, HVF_CNTRL_1_VQR(0)); |
| 856 | |
| 857 | /* TODO enable pixel repeat for pixel rates less than 25Msamp/s */ |
| 858 | rep = 0; |
| 859 | reg_write(encoder, REG_RPT_CNTRL, 0); |
| 860 | reg_write(encoder, REG_SEL_CLK, SEL_CLK_SEL_VRF_CLK(0) | |
| 861 | SEL_CLK_SEL_CLK1 | SEL_CLK_ENA_SC_CLK); |
| 862 | |
| 863 | reg_write(encoder, REG_PLL_SERIAL_2, PLL_SERIAL_2_SRL_NOSC(div) | |
| 864 | PLL_SERIAL_2_SRL_PR(rep)); |
| 865 | |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 866 | /* set color matrix bypass flag: */ |
| 867 | reg_set(encoder, REG_MAT_CONTRL, MAT_CONTRL_MAT_BP); |
| 868 | |
| 869 | /* set BIAS tmds value: */ |
| 870 | reg_write(encoder, REG_ANA_GENERAL, 0x09); |
| 871 | |
| 872 | reg_clear(encoder, REG_TBG_CNTRL_0, TBG_CNTRL_0_SYNC_MTHD); |
| 873 | |
Sebastian Hesselbarth | 088d61d | 2013-08-14 21:43:31 +0200 | [diff] [blame] | 874 | /* |
| 875 | * Sync on rising HSYNC/VSYNC |
| 876 | */ |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 877 | reg_write(encoder, REG_VIP_CNTRL_3, 0); |
| 878 | reg_set(encoder, REG_VIP_CNTRL_3, VIP_CNTRL_3_SYNC_HS); |
Sebastian Hesselbarth | 088d61d | 2013-08-14 21:43:31 +0200 | [diff] [blame] | 879 | |
| 880 | /* |
| 881 | * TDA19988 requires high-active sync at input stage, |
| 882 | * so invert low-active sync provided by master encoder here |
| 883 | */ |
| 884 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) |
| 885 | reg_set(encoder, REG_VIP_CNTRL_3, VIP_CNTRL_3_H_TGL); |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 886 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 887 | reg_set(encoder, REG_VIP_CNTRL_3, VIP_CNTRL_3_V_TGL); |
| 888 | |
Sebastian Hesselbarth | 088d61d | 2013-08-14 21:43:31 +0200 | [diff] [blame] | 889 | /* |
| 890 | * Always generate sync polarity relative to input sync and |
| 891 | * revert input stage toggled sync at output stage |
| 892 | */ |
| 893 | reg = TBG_CNTRL_1_TGL_EN; |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 894 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) |
Sebastian Hesselbarth | 088d61d | 2013-08-14 21:43:31 +0200 | [diff] [blame] | 895 | reg |= TBG_CNTRL_1_H_TGL; |
| 896 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 897 | reg |= TBG_CNTRL_1_V_TGL; |
| 898 | reg_write(encoder, REG_TBG_CNTRL_1, reg); |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 899 | |
| 900 | reg_write(encoder, REG_VIDFORMAT, 0x00); |
Sebastian Hesselbarth | 088d61d | 2013-08-14 21:43:31 +0200 | [diff] [blame] | 901 | reg_write16(encoder, REG_REFPIX_MSB, ref_pix); |
| 902 | reg_write16(encoder, REG_REFLINE_MSB, ref_line); |
| 903 | reg_write16(encoder, REG_NPIX_MSB, n_pix); |
| 904 | reg_write16(encoder, REG_NLINE_MSB, n_line); |
| 905 | reg_write16(encoder, REG_VS_LINE_STRT_1_MSB, vs1_line_s); |
| 906 | reg_write16(encoder, REG_VS_PIX_STRT_1_MSB, vs1_pix_s); |
| 907 | reg_write16(encoder, REG_VS_LINE_END_1_MSB, vs1_line_e); |
| 908 | reg_write16(encoder, REG_VS_PIX_END_1_MSB, vs1_pix_e); |
| 909 | reg_write16(encoder, REG_VS_LINE_STRT_2_MSB, vs2_line_s); |
| 910 | reg_write16(encoder, REG_VS_PIX_STRT_2_MSB, vs2_pix_s); |
| 911 | reg_write16(encoder, REG_VS_LINE_END_2_MSB, vs2_line_e); |
| 912 | reg_write16(encoder, REG_VS_PIX_END_2_MSB, vs2_pix_e); |
| 913 | reg_write16(encoder, REG_HS_PIX_START_MSB, hs_pix_s); |
| 914 | reg_write16(encoder, REG_HS_PIX_STOP_MSB, hs_pix_e); |
| 915 | reg_write16(encoder, REG_VWIN_START_1_MSB, vwin1_line_s); |
| 916 | reg_write16(encoder, REG_VWIN_END_1_MSB, vwin1_line_e); |
| 917 | reg_write16(encoder, REG_VWIN_START_2_MSB, vwin2_line_s); |
| 918 | reg_write16(encoder, REG_VWIN_END_2_MSB, vwin2_line_e); |
| 919 | reg_write16(encoder, REG_DE_START_MSB, de_pix_s); |
| 920 | reg_write16(encoder, REG_DE_STOP_MSB, de_pix_e); |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 921 | |
| 922 | if (priv->rev == TDA19988) { |
| 923 | /* let incoming pixels fill the active space (if any) */ |
Jean-Francois Moine | 2e9a3fc | 2014-01-25 18:14:37 +0100 | [diff] [blame] | 924 | reg_write(encoder, REG_ENABLE_SPACE, 0x00); |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 925 | } |
| 926 | |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 927 | /* must be last register set: */ |
| 928 | reg_clear(encoder, REG_TBG_CNTRL_0, TBG_CNTRL_0_SYNC_ONCE); |
Russell King | c4c11dd | 2013-08-14 21:43:30 +0200 | [diff] [blame] | 929 | |
| 930 | /* Only setup the info frames if the sink is HDMI */ |
| 931 | if (priv->is_hdmi_sink) { |
| 932 | /* We need to turn HDMI HDCP stuff on to get audio through */ |
| 933 | reg_clear(encoder, REG_TBG_CNTRL_1, TBG_CNTRL_1_DWIN_DIS); |
| 934 | reg_write(encoder, REG_ENC_CNTRL, ENC_CNTRL_CTL_CODE(1)); |
| 935 | reg_set(encoder, REG_TX33, TX33_HDMI); |
| 936 | |
| 937 | tda998x_write_avi(encoder, adjusted_mode); |
| 938 | |
| 939 | if (priv->params.audio_cfg) |
| 940 | tda998x_configure_audio(encoder, adjusted_mode, |
| 941 | &priv->params); |
| 942 | } |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | static enum drm_connector_status |
| 946 | tda998x_encoder_detect(struct drm_encoder *encoder, |
| 947 | struct drm_connector *connector) |
| 948 | { |
| 949 | uint8_t val = cec_read(encoder, REG_CEC_RXSHPDLEV); |
| 950 | return (val & CEC_RXSHPDLEV_HPD) ? connector_status_connected : |
| 951 | connector_status_disconnected; |
| 952 | } |
| 953 | |
| 954 | static int |
| 955 | read_edid_block(struct drm_encoder *encoder, uint8_t *buf, int blk) |
| 956 | { |
| 957 | uint8_t offset, segptr; |
| 958 | int ret, i; |
| 959 | |
| 960 | /* enable EDID read irq: */ |
| 961 | reg_set(encoder, REG_INT_FLAGS_2, INT_FLAGS_2_EDID_BLK_RD); |
| 962 | |
| 963 | offset = (blk & 1) ? 128 : 0; |
| 964 | segptr = blk / 2; |
| 965 | |
| 966 | reg_write(encoder, REG_DDC_ADDR, 0xa0); |
| 967 | reg_write(encoder, REG_DDC_OFFS, offset); |
| 968 | reg_write(encoder, REG_DDC_SEGM_ADDR, 0x60); |
| 969 | reg_write(encoder, REG_DDC_SEGM, segptr); |
| 970 | |
| 971 | /* enable reading EDID: */ |
| 972 | reg_write(encoder, REG_EDID_CTRL, 0x1); |
| 973 | |
| 974 | /* flag must be cleared by sw: */ |
| 975 | reg_write(encoder, REG_EDID_CTRL, 0x0); |
| 976 | |
| 977 | /* wait for block read to complete: */ |
| 978 | for (i = 100; i > 0; i--) { |
| 979 | uint8_t val = reg_read(encoder, REG_INT_FLAGS_2); |
| 980 | if (val & INT_FLAGS_2_EDID_BLK_RD) |
| 981 | break; |
| 982 | msleep(1); |
| 983 | } |
| 984 | |
| 985 | if (i == 0) |
| 986 | return -ETIMEDOUT; |
| 987 | |
| 988 | ret = reg_read_range(encoder, REG_EDID_DATA_0, buf, EDID_LENGTH); |
| 989 | if (ret != EDID_LENGTH) { |
| 990 | dev_err(encoder->dev->dev, "failed to read edid block %d: %d", |
| 991 | blk, ret); |
| 992 | return ret; |
| 993 | } |
| 994 | |
| 995 | reg_clear(encoder, REG_INT_FLAGS_2, INT_FLAGS_2_EDID_BLK_RD); |
| 996 | |
| 997 | return 0; |
| 998 | } |
| 999 | |
| 1000 | static uint8_t * |
| 1001 | do_get_edid(struct drm_encoder *encoder) |
| 1002 | { |
Russell King | 063b472 | 2013-08-14 21:43:26 +0200 | [diff] [blame] | 1003 | struct tda998x_priv *priv = to_tda998x_priv(encoder); |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 1004 | int j = 0, valid_extensions = 0; |
| 1005 | uint8_t *block, *new; |
| 1006 | bool print_bad_edid = drm_debug & DRM_UT_KMS; |
| 1007 | |
| 1008 | if ((block = kmalloc(EDID_LENGTH, GFP_KERNEL)) == NULL) |
| 1009 | return NULL; |
| 1010 | |
Russell King | 063b472 | 2013-08-14 21:43:26 +0200 | [diff] [blame] | 1011 | if (priv->rev == TDA19988) |
| 1012 | reg_clear(encoder, REG_TX4, TX4_PD_RAM); |
| 1013 | |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 1014 | /* base block fetch */ |
| 1015 | if (read_edid_block(encoder, block, 0)) |
| 1016 | goto fail; |
| 1017 | |
| 1018 | if (!drm_edid_block_valid(block, 0, print_bad_edid)) |
| 1019 | goto fail; |
| 1020 | |
| 1021 | /* if there's no extensions, we're done */ |
| 1022 | if (block[0x7e] == 0) |
Russell King | 063b472 | 2013-08-14 21:43:26 +0200 | [diff] [blame] | 1023 | goto done; |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 1024 | |
| 1025 | new = krealloc(block, (block[0x7e] + 1) * EDID_LENGTH, GFP_KERNEL); |
| 1026 | if (!new) |
| 1027 | goto fail; |
| 1028 | block = new; |
| 1029 | |
| 1030 | for (j = 1; j <= block[0x7e]; j++) { |
| 1031 | uint8_t *ext_block = block + (valid_extensions + 1) * EDID_LENGTH; |
| 1032 | if (read_edid_block(encoder, ext_block, j)) |
| 1033 | goto fail; |
| 1034 | |
| 1035 | if (!drm_edid_block_valid(ext_block, j, print_bad_edid)) |
| 1036 | goto fail; |
| 1037 | |
| 1038 | valid_extensions++; |
| 1039 | } |
| 1040 | |
| 1041 | if (valid_extensions != block[0x7e]) { |
| 1042 | block[EDID_LENGTH-1] += block[0x7e] - valid_extensions; |
| 1043 | block[0x7e] = valid_extensions; |
| 1044 | new = krealloc(block, (valid_extensions + 1) * EDID_LENGTH, GFP_KERNEL); |
| 1045 | if (!new) |
| 1046 | goto fail; |
| 1047 | block = new; |
| 1048 | } |
| 1049 | |
Russell King | 063b472 | 2013-08-14 21:43:26 +0200 | [diff] [blame] | 1050 | done: |
| 1051 | if (priv->rev == TDA19988) |
| 1052 | reg_set(encoder, REG_TX4, TX4_PD_RAM); |
| 1053 | |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 1054 | return block; |
| 1055 | |
| 1056 | fail: |
Russell King | 063b472 | 2013-08-14 21:43:26 +0200 | [diff] [blame] | 1057 | if (priv->rev == TDA19988) |
| 1058 | reg_set(encoder, REG_TX4, TX4_PD_RAM); |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 1059 | dev_warn(encoder->dev->dev, "failed to read EDID\n"); |
| 1060 | kfree(block); |
| 1061 | return NULL; |
| 1062 | } |
| 1063 | |
| 1064 | static int |
| 1065 | tda998x_encoder_get_modes(struct drm_encoder *encoder, |
| 1066 | struct drm_connector *connector) |
| 1067 | { |
Russell King | c4c11dd | 2013-08-14 21:43:30 +0200 | [diff] [blame] | 1068 | struct tda998x_priv *priv = to_tda998x_priv(encoder); |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 1069 | struct edid *edid = (struct edid *)do_get_edid(encoder); |
| 1070 | int n = 0; |
| 1071 | |
| 1072 | if (edid) { |
| 1073 | drm_mode_connector_update_edid_property(connector, edid); |
| 1074 | n = drm_add_edid_modes(connector, edid); |
Russell King | c4c11dd | 2013-08-14 21:43:30 +0200 | [diff] [blame] | 1075 | priv->is_hdmi_sink = drm_detect_hdmi_monitor(edid); |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 1076 | kfree(edid); |
| 1077 | } |
| 1078 | |
| 1079 | return n; |
| 1080 | } |
| 1081 | |
| 1082 | static int |
| 1083 | tda998x_encoder_create_resources(struct drm_encoder *encoder, |
| 1084 | struct drm_connector *connector) |
| 1085 | { |
| 1086 | DBG(""); |
| 1087 | return 0; |
| 1088 | } |
| 1089 | |
| 1090 | static int |
| 1091 | tda998x_encoder_set_property(struct drm_encoder *encoder, |
| 1092 | struct drm_connector *connector, |
| 1093 | struct drm_property *property, |
| 1094 | uint64_t val) |
| 1095 | { |
| 1096 | DBG(""); |
| 1097 | return 0; |
| 1098 | } |
| 1099 | |
| 1100 | static void |
| 1101 | tda998x_encoder_destroy(struct drm_encoder *encoder) |
| 1102 | { |
| 1103 | struct tda998x_priv *priv = to_tda998x_priv(encoder); |
| 1104 | drm_i2c_encoder_destroy(encoder); |
Jean-Francois Moine | fc275a7 | 2014-01-25 18:14:42 +0100 | [diff] [blame] | 1105 | if (priv->cec) |
| 1106 | i2c_unregister_device(priv->cec); |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 1107 | kfree(priv); |
| 1108 | } |
| 1109 | |
| 1110 | static struct drm_encoder_slave_funcs tda998x_encoder_funcs = { |
| 1111 | .set_config = tda998x_encoder_set_config, |
| 1112 | .destroy = tda998x_encoder_destroy, |
| 1113 | .dpms = tda998x_encoder_dpms, |
| 1114 | .save = tda998x_encoder_save, |
| 1115 | .restore = tda998x_encoder_restore, |
| 1116 | .mode_fixup = tda998x_encoder_mode_fixup, |
| 1117 | .mode_valid = tda998x_encoder_mode_valid, |
| 1118 | .mode_set = tda998x_encoder_mode_set, |
| 1119 | .detect = tda998x_encoder_detect, |
| 1120 | .get_modes = tda998x_encoder_get_modes, |
| 1121 | .create_resources = tda998x_encoder_create_resources, |
| 1122 | .set_property = tda998x_encoder_set_property, |
| 1123 | }; |
| 1124 | |
| 1125 | /* I2C driver functions */ |
| 1126 | |
| 1127 | static int |
| 1128 | tda998x_probe(struct i2c_client *client, const struct i2c_device_id *id) |
| 1129 | { |
| 1130 | return 0; |
| 1131 | } |
| 1132 | |
| 1133 | static int |
| 1134 | tda998x_remove(struct i2c_client *client) |
| 1135 | { |
| 1136 | return 0; |
| 1137 | } |
| 1138 | |
| 1139 | static int |
| 1140 | tda998x_encoder_init(struct i2c_client *client, |
| 1141 | struct drm_device *dev, |
| 1142 | struct drm_encoder_slave *encoder_slave) |
| 1143 | { |
| 1144 | struct drm_encoder *encoder = &encoder_slave->base; |
| 1145 | struct tda998x_priv *priv; |
| 1146 | |
| 1147 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
| 1148 | if (!priv) |
| 1149 | return -ENOMEM; |
| 1150 | |
Russell King | 5e74c22 | 2013-08-14 21:43:29 +0200 | [diff] [blame] | 1151 | priv->vip_cntrl_0 = VIP_CNTRL_0_SWAP_A(2) | VIP_CNTRL_0_SWAP_B(3); |
| 1152 | priv->vip_cntrl_1 = VIP_CNTRL_1_SWAP_C(0) | VIP_CNTRL_1_SWAP_D(1); |
| 1153 | priv->vip_cntrl_2 = VIP_CNTRL_2_SWAP_E(4) | VIP_CNTRL_2_SWAP_F(5); |
| 1154 | |
Jean-Francois Moine | 2eb4c7b | 2014-01-25 18:14:45 +0100 | [diff] [blame] | 1155 | priv->current_page = 0xff; |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 1156 | priv->cec = i2c_new_dummy(client->adapter, 0x34); |
Dave Jones | 71c68c4 | 2014-02-12 22:47:51 -0500 | [diff] [blame] | 1157 | if (!priv->cec) { |
| 1158 | kfree(priv); |
Jean-Francois Moine | 6ae668c | 2014-01-25 18:14:43 +0100 | [diff] [blame] | 1159 | return -ENODEV; |
Dave Jones | 71c68c4 | 2014-02-12 22:47:51 -0500 | [diff] [blame] | 1160 | } |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 1161 | priv->dpms = DRM_MODE_DPMS_OFF; |
| 1162 | |
| 1163 | encoder_slave->slave_priv = priv; |
| 1164 | encoder_slave->slave_funcs = &tda998x_encoder_funcs; |
| 1165 | |
| 1166 | /* wake up the device: */ |
| 1167 | cec_write(encoder, REG_CEC_ENAMODS, |
| 1168 | CEC_ENAMODS_EN_RXSENS | CEC_ENAMODS_EN_HDMI); |
| 1169 | |
| 1170 | tda998x_reset(encoder); |
| 1171 | |
| 1172 | /* read version: */ |
| 1173 | priv->rev = reg_read(encoder, REG_VERSION_LSB) | |
| 1174 | reg_read(encoder, REG_VERSION_MSB) << 8; |
| 1175 | |
| 1176 | /* mask off feature bits: */ |
| 1177 | priv->rev &= ~0x30; /* not-hdcp and not-scalar bit */ |
| 1178 | |
| 1179 | switch (priv->rev) { |
| 1180 | case TDA9989N2: dev_info(dev->dev, "found TDA9989 n2"); break; |
| 1181 | case TDA19989: dev_info(dev->dev, "found TDA19989"); break; |
| 1182 | case TDA19989N2: dev_info(dev->dev, "found TDA19989 n2"); break; |
| 1183 | case TDA19988: dev_info(dev->dev, "found TDA19988"); break; |
| 1184 | default: |
| 1185 | DBG("found unsupported device: %04x", priv->rev); |
| 1186 | goto fail; |
| 1187 | } |
| 1188 | |
| 1189 | /* after reset, enable DDC: */ |
| 1190 | reg_write(encoder, REG_DDC_DISABLE, 0x00); |
| 1191 | |
| 1192 | /* set clock on DDC channel: */ |
| 1193 | reg_write(encoder, REG_TX3, 39); |
| 1194 | |
| 1195 | /* if necessary, disable multi-master: */ |
| 1196 | if (priv->rev == TDA19989) |
| 1197 | reg_set(encoder, REG_I2C_MASTER, I2C_MASTER_DIS_MM); |
| 1198 | |
| 1199 | cec_write(encoder, REG_CEC_FRO_IM_CLK_CTRL, |
| 1200 | CEC_FRO_IM_CLK_CTRL_GHOST_DIS | CEC_FRO_IM_CLK_CTRL_IMCLK_SEL); |
| 1201 | |
| 1202 | return 0; |
| 1203 | |
| 1204 | fail: |
| 1205 | /* if encoder_init fails, the encoder slave is never registered, |
| 1206 | * so cleanup here: |
| 1207 | */ |
| 1208 | if (priv->cec) |
| 1209 | i2c_unregister_device(priv->cec); |
| 1210 | kfree(priv); |
| 1211 | encoder_slave->slave_priv = NULL; |
| 1212 | encoder_slave->slave_funcs = NULL; |
| 1213 | return -ENXIO; |
| 1214 | } |
| 1215 | |
| 1216 | static struct i2c_device_id tda998x_ids[] = { |
| 1217 | { "tda998x", 0 }, |
| 1218 | { } |
| 1219 | }; |
| 1220 | MODULE_DEVICE_TABLE(i2c, tda998x_ids); |
| 1221 | |
| 1222 | static struct drm_i2c_encoder_driver tda998x_driver = { |
| 1223 | .i2c_driver = { |
| 1224 | .probe = tda998x_probe, |
| 1225 | .remove = tda998x_remove, |
| 1226 | .driver = { |
| 1227 | .name = "tda998x", |
| 1228 | }, |
| 1229 | .id_table = tda998x_ids, |
| 1230 | }, |
| 1231 | .encoder_init = tda998x_encoder_init, |
| 1232 | }; |
| 1233 | |
| 1234 | /* Module initialization */ |
| 1235 | |
| 1236 | static int __init |
| 1237 | tda998x_init(void) |
| 1238 | { |
| 1239 | DBG(""); |
| 1240 | return drm_i2c_encoder_register(THIS_MODULE, &tda998x_driver); |
| 1241 | } |
| 1242 | |
| 1243 | static void __exit |
| 1244 | tda998x_exit(void) |
| 1245 | { |
| 1246 | DBG(""); |
| 1247 | drm_i2c_encoder_unregister(&tda998x_driver); |
| 1248 | } |
| 1249 | |
| 1250 | MODULE_AUTHOR("Rob Clark <robdclark@gmail.com"); |
| 1251 | MODULE_DESCRIPTION("NXP Semiconductors TDA998X HDMI Encoder"); |
| 1252 | MODULE_LICENSE("GPL"); |
| 1253 | |
| 1254 | module_init(tda998x_init); |
| 1255 | module_exit(tda998x_exit); |