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 | |
| 20 | #include <linux/module.h> |
| 21 | |
| 22 | #include <drm/drmP.h> |
| 23 | #include <drm/drm_crtc_helper.h> |
| 24 | #include <drm/drm_encoder_slave.h> |
| 25 | #include <drm/drm_edid.h> |
| 26 | |
| 27 | |
| 28 | #define DBG(fmt, ...) DRM_DEBUG(fmt"\n", ##__VA_ARGS__) |
| 29 | |
| 30 | struct tda998x_priv { |
| 31 | struct i2c_client *cec; |
| 32 | uint16_t rev; |
| 33 | uint8_t current_page; |
| 34 | int dpms; |
| 35 | }; |
| 36 | |
| 37 | #define to_tda998x_priv(x) ((struct tda998x_priv *)to_encoder_slave(x)->slave_priv) |
| 38 | |
| 39 | /* The TDA9988 series of devices use a paged register scheme.. to simplify |
| 40 | * things we encode the page # in upper bits of the register #. To read/ |
| 41 | * write a given register, we need to make sure CURPAGE register is set |
| 42 | * appropriately. Which implies reads/writes are not atomic. Fun! |
| 43 | */ |
| 44 | |
| 45 | #define REG(page, addr) (((page) << 8) | (addr)) |
| 46 | #define REG2ADDR(reg) ((reg) & 0xff) |
| 47 | #define REG2PAGE(reg) (((reg) >> 8) & 0xff) |
| 48 | |
| 49 | #define REG_CURPAGE 0xff /* write */ |
| 50 | |
| 51 | |
| 52 | /* Page 00h: General Control */ |
| 53 | #define REG_VERSION_LSB REG(0x00, 0x00) /* read */ |
| 54 | #define REG_MAIN_CNTRL0 REG(0x00, 0x01) /* read/write */ |
| 55 | # define MAIN_CNTRL0_SR (1 << 0) |
| 56 | # define MAIN_CNTRL0_DECS (1 << 1) |
| 57 | # define MAIN_CNTRL0_DEHS (1 << 2) |
| 58 | # define MAIN_CNTRL0_CECS (1 << 3) |
| 59 | # define MAIN_CNTRL0_CEHS (1 << 4) |
| 60 | # define MAIN_CNTRL0_SCALER (1 << 7) |
| 61 | #define REG_VERSION_MSB REG(0x00, 0x02) /* read */ |
| 62 | #define REG_SOFTRESET REG(0x00, 0x0a) /* write */ |
| 63 | # define SOFTRESET_AUDIO (1 << 0) |
| 64 | # define SOFTRESET_I2C_MASTER (1 << 1) |
| 65 | #define REG_DDC_DISABLE REG(0x00, 0x0b) /* read/write */ |
| 66 | #define REG_CCLK_ON REG(0x00, 0x0c) /* read/write */ |
| 67 | #define REG_I2C_MASTER REG(0x00, 0x0d) /* read/write */ |
| 68 | # define I2C_MASTER_DIS_MM (1 << 0) |
| 69 | # define I2C_MASTER_DIS_FILT (1 << 1) |
| 70 | # define I2C_MASTER_APP_STRT_LAT (1 << 2) |
| 71 | #define REG_INT_FLAGS_0 REG(0x00, 0x0f) /* read/write */ |
| 72 | #define REG_INT_FLAGS_1 REG(0x00, 0x10) /* read/write */ |
| 73 | #define REG_INT_FLAGS_2 REG(0x00, 0x11) /* read/write */ |
| 74 | # define INT_FLAGS_2_EDID_BLK_RD (1 << 1) |
| 75 | #define REG_ENA_VP_0 REG(0x00, 0x18) /* read/write */ |
| 76 | #define REG_ENA_VP_1 REG(0x00, 0x19) /* read/write */ |
| 77 | #define REG_ENA_VP_2 REG(0x00, 0x1a) /* read/write */ |
| 78 | #define REG_ENA_AP REG(0x00, 0x1e) /* read/write */ |
| 79 | #define REG_VIP_CNTRL_0 REG(0x00, 0x20) /* write */ |
| 80 | # define VIP_CNTRL_0_MIRR_A (1 << 7) |
| 81 | # define VIP_CNTRL_0_SWAP_A(x) (((x) & 7) << 4) |
| 82 | # define VIP_CNTRL_0_MIRR_B (1 << 3) |
| 83 | # define VIP_CNTRL_0_SWAP_B(x) (((x) & 7) << 0) |
| 84 | #define REG_VIP_CNTRL_1 REG(0x00, 0x21) /* write */ |
| 85 | # define VIP_CNTRL_1_MIRR_C (1 << 7) |
| 86 | # define VIP_CNTRL_1_SWAP_C(x) (((x) & 7) << 4) |
| 87 | # define VIP_CNTRL_1_MIRR_D (1 << 3) |
| 88 | # define VIP_CNTRL_1_SWAP_D(x) (((x) & 7) << 0) |
| 89 | #define REG_VIP_CNTRL_2 REG(0x00, 0x22) /* write */ |
| 90 | # define VIP_CNTRL_2_MIRR_E (1 << 7) |
| 91 | # define VIP_CNTRL_2_SWAP_E(x) (((x) & 7) << 4) |
| 92 | # define VIP_CNTRL_2_MIRR_F (1 << 3) |
| 93 | # define VIP_CNTRL_2_SWAP_F(x) (((x) & 7) << 0) |
| 94 | #define REG_VIP_CNTRL_3 REG(0x00, 0x23) /* write */ |
| 95 | # define VIP_CNTRL_3_X_TGL (1 << 0) |
| 96 | # define VIP_CNTRL_3_H_TGL (1 << 1) |
| 97 | # define VIP_CNTRL_3_V_TGL (1 << 2) |
| 98 | # define VIP_CNTRL_3_EMB (1 << 3) |
| 99 | # define VIP_CNTRL_3_SYNC_DE (1 << 4) |
| 100 | # define VIP_CNTRL_3_SYNC_HS (1 << 5) |
| 101 | # define VIP_CNTRL_3_DE_INT (1 << 6) |
| 102 | # define VIP_CNTRL_3_EDGE (1 << 7) |
| 103 | #define REG_VIP_CNTRL_4 REG(0x00, 0x24) /* write */ |
| 104 | # define VIP_CNTRL_4_BLC(x) (((x) & 3) << 0) |
| 105 | # define VIP_CNTRL_4_BLANKIT(x) (((x) & 3) << 2) |
| 106 | # define VIP_CNTRL_4_CCIR656 (1 << 4) |
| 107 | # define VIP_CNTRL_4_656_ALT (1 << 5) |
| 108 | # define VIP_CNTRL_4_TST_656 (1 << 6) |
| 109 | # define VIP_CNTRL_4_TST_PAT (1 << 7) |
| 110 | #define REG_VIP_CNTRL_5 REG(0x00, 0x25) /* write */ |
| 111 | # define VIP_CNTRL_5_CKCASE (1 << 0) |
| 112 | # define VIP_CNTRL_5_SP_CNT(x) (((x) & 3) << 1) |
Russell King | bcb2481 | 2013-08-14 21:43:27 +0200 | [diff] [blame] | 113 | #define REG_MUX_VP_VIP_OUT REG(0x00, 0x27) /* read/write */ |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 114 | #define REG_MAT_CONTRL REG(0x00, 0x80) /* write */ |
| 115 | # define MAT_CONTRL_MAT_SC(x) (((x) & 3) << 0) |
| 116 | # define MAT_CONTRL_MAT_BP (1 << 2) |
| 117 | #define REG_VIDFORMAT REG(0x00, 0xa0) /* write */ |
| 118 | #define REG_REFPIX_MSB REG(0x00, 0xa1) /* write */ |
| 119 | #define REG_REFPIX_LSB REG(0x00, 0xa2) /* write */ |
| 120 | #define REG_REFLINE_MSB REG(0x00, 0xa3) /* write */ |
| 121 | #define REG_REFLINE_LSB REG(0x00, 0xa4) /* write */ |
| 122 | #define REG_NPIX_MSB REG(0x00, 0xa5) /* write */ |
| 123 | #define REG_NPIX_LSB REG(0x00, 0xa6) /* write */ |
| 124 | #define REG_NLINE_MSB REG(0x00, 0xa7) /* write */ |
| 125 | #define REG_NLINE_LSB REG(0x00, 0xa8) /* write */ |
| 126 | #define REG_VS_LINE_STRT_1_MSB REG(0x00, 0xa9) /* write */ |
| 127 | #define REG_VS_LINE_STRT_1_LSB REG(0x00, 0xaa) /* write */ |
| 128 | #define REG_VS_PIX_STRT_1_MSB REG(0x00, 0xab) /* write */ |
| 129 | #define REG_VS_PIX_STRT_1_LSB REG(0x00, 0xac) /* write */ |
| 130 | #define REG_VS_LINE_END_1_MSB REG(0x00, 0xad) /* write */ |
| 131 | #define REG_VS_LINE_END_1_LSB REG(0x00, 0xae) /* write */ |
| 132 | #define REG_VS_PIX_END_1_MSB REG(0x00, 0xaf) /* write */ |
| 133 | #define REG_VS_PIX_END_1_LSB REG(0x00, 0xb0) /* write */ |
| 134 | #define REG_VS_PIX_STRT_2_MSB REG(0x00, 0xb3) /* write */ |
| 135 | #define REG_VS_PIX_STRT_2_LSB REG(0x00, 0xb4) /* write */ |
| 136 | #define REG_VS_PIX_END_2_MSB REG(0x00, 0xb7) /* write */ |
| 137 | #define REG_VS_PIX_END_2_LSB REG(0x00, 0xb8) /* write */ |
| 138 | #define REG_HS_PIX_START_MSB REG(0x00, 0xb9) /* write */ |
| 139 | #define REG_HS_PIX_START_LSB REG(0x00, 0xba) /* write */ |
| 140 | #define REG_HS_PIX_STOP_MSB REG(0x00, 0xbb) /* write */ |
| 141 | #define REG_HS_PIX_STOP_LSB REG(0x00, 0xbc) /* write */ |
| 142 | #define REG_VWIN_START_1_MSB REG(0x00, 0xbd) /* write */ |
| 143 | #define REG_VWIN_START_1_LSB REG(0x00, 0xbe) /* write */ |
| 144 | #define REG_VWIN_END_1_MSB REG(0x00, 0xbf) /* write */ |
| 145 | #define REG_VWIN_END_1_LSB REG(0x00, 0xc0) /* write */ |
| 146 | #define REG_DE_START_MSB REG(0x00, 0xc5) /* write */ |
| 147 | #define REG_DE_START_LSB REG(0x00, 0xc6) /* write */ |
| 148 | #define REG_DE_STOP_MSB REG(0x00, 0xc7) /* write */ |
| 149 | #define REG_DE_STOP_LSB REG(0x00, 0xc8) /* write */ |
| 150 | #define REG_TBG_CNTRL_0 REG(0x00, 0xca) /* write */ |
| 151 | # define TBG_CNTRL_0_FRAME_DIS (1 << 5) |
| 152 | # define TBG_CNTRL_0_SYNC_MTHD (1 << 6) |
| 153 | # define TBG_CNTRL_0_SYNC_ONCE (1 << 7) |
| 154 | #define REG_TBG_CNTRL_1 REG(0x00, 0xcb) /* write */ |
| 155 | # define TBG_CNTRL_1_VH_TGL_0 (1 << 0) |
| 156 | # define TBG_CNTRL_1_VH_TGL_1 (1 << 1) |
| 157 | # define TBG_CNTRL_1_VH_TGL_2 (1 << 2) |
| 158 | # define TBG_CNTRL_1_VHX_EXT_DE (1 << 3) |
| 159 | # define TBG_CNTRL_1_VHX_EXT_HS (1 << 4) |
| 160 | # define TBG_CNTRL_1_VHX_EXT_VS (1 << 5) |
| 161 | # define TBG_CNTRL_1_DWIN_DIS (1 << 6) |
| 162 | #define REG_ENABLE_SPACE REG(0x00, 0xd6) /* write */ |
| 163 | #define REG_HVF_CNTRL_0 REG(0x00, 0xe4) /* write */ |
| 164 | # define HVF_CNTRL_0_SM (1 << 7) |
| 165 | # define HVF_CNTRL_0_RWB (1 << 6) |
| 166 | # define HVF_CNTRL_0_PREFIL(x) (((x) & 3) << 2) |
| 167 | # define HVF_CNTRL_0_INTPOL(x) (((x) & 3) << 0) |
| 168 | #define REG_HVF_CNTRL_1 REG(0x00, 0xe5) /* write */ |
| 169 | # define HVF_CNTRL_1_FOR (1 << 0) |
| 170 | # define HVF_CNTRL_1_YUVBLK (1 << 1) |
| 171 | # define HVF_CNTRL_1_VQR(x) (((x) & 3) << 2) |
| 172 | # define HVF_CNTRL_1_PAD(x) (((x) & 3) << 4) |
| 173 | # define HVF_CNTRL_1_SEMI_PLANAR (1 << 6) |
| 174 | #define REG_RPT_CNTRL REG(0x00, 0xf0) /* write */ |
| 175 | |
| 176 | |
| 177 | /* Page 02h: PLL settings */ |
| 178 | #define REG_PLL_SERIAL_1 REG(0x02, 0x00) /* read/write */ |
| 179 | # define PLL_SERIAL_1_SRL_FDN (1 << 0) |
| 180 | # define PLL_SERIAL_1_SRL_IZ(x) (((x) & 3) << 1) |
| 181 | # define PLL_SERIAL_1_SRL_MAN_IZ (1 << 6) |
| 182 | #define REG_PLL_SERIAL_2 REG(0x02, 0x01) /* read/write */ |
| 183 | # define PLL_SERIAL_2_SRL_NOSC(x) (((x) & 3) << 0) |
| 184 | # define PLL_SERIAL_2_SRL_PR(x) (((x) & 0xf) << 4) |
| 185 | #define REG_PLL_SERIAL_3 REG(0x02, 0x02) /* read/write */ |
| 186 | # define PLL_SERIAL_3_SRL_CCIR (1 << 0) |
| 187 | # define PLL_SERIAL_3_SRL_DE (1 << 2) |
| 188 | # define PLL_SERIAL_3_SRL_PXIN_SEL (1 << 4) |
| 189 | #define REG_SERIALIZER REG(0x02, 0x03) /* read/write */ |
| 190 | #define REG_BUFFER_OUT REG(0x02, 0x04) /* read/write */ |
| 191 | #define REG_PLL_SCG1 REG(0x02, 0x05) /* read/write */ |
| 192 | #define REG_PLL_SCG2 REG(0x02, 0x06) /* read/write */ |
| 193 | #define REG_PLL_SCGN1 REG(0x02, 0x07) /* read/write */ |
| 194 | #define REG_PLL_SCGN2 REG(0x02, 0x08) /* read/write */ |
| 195 | #define REG_PLL_SCGR1 REG(0x02, 0x09) /* read/write */ |
| 196 | #define REG_PLL_SCGR2 REG(0x02, 0x0a) /* read/write */ |
| 197 | #define REG_AUDIO_DIV REG(0x02, 0x0e) /* read/write */ |
| 198 | #define REG_SEL_CLK REG(0x02, 0x11) /* read/write */ |
| 199 | # define SEL_CLK_SEL_CLK1 (1 << 0) |
| 200 | # define SEL_CLK_SEL_VRF_CLK(x) (((x) & 3) << 1) |
| 201 | # define SEL_CLK_ENA_SC_CLK (1 << 3) |
| 202 | #define REG_ANA_GENERAL REG(0x02, 0x12) /* read/write */ |
| 203 | |
| 204 | |
| 205 | /* Page 09h: EDID Control */ |
| 206 | #define REG_EDID_DATA_0 REG(0x09, 0x00) /* read */ |
| 207 | /* next 127 successive registers are the EDID block */ |
| 208 | #define REG_EDID_CTRL REG(0x09, 0xfa) /* read/write */ |
| 209 | #define REG_DDC_ADDR REG(0x09, 0xfb) /* read/write */ |
| 210 | #define REG_DDC_OFFS REG(0x09, 0xfc) /* read/write */ |
| 211 | #define REG_DDC_SEGM_ADDR REG(0x09, 0xfd) /* read/write */ |
| 212 | #define REG_DDC_SEGM REG(0x09, 0xfe) /* read/write */ |
| 213 | |
| 214 | |
| 215 | /* Page 10h: information frames and packets */ |
| 216 | |
| 217 | |
| 218 | /* Page 11h: audio settings and content info packets */ |
| 219 | #define REG_AIP_CNTRL_0 REG(0x11, 0x00) /* read/write */ |
| 220 | # define AIP_CNTRL_0_RST_FIFO (1 << 0) |
| 221 | # define AIP_CNTRL_0_SWAP (1 << 1) |
| 222 | # define AIP_CNTRL_0_LAYOUT (1 << 2) |
| 223 | # define AIP_CNTRL_0_ACR_MAN (1 << 5) |
| 224 | # define AIP_CNTRL_0_RST_CTS (1 << 6) |
| 225 | #define REG_ENC_CNTRL REG(0x11, 0x0d) /* read/write */ |
| 226 | # define ENC_CNTRL_RST_ENC (1 << 0) |
| 227 | # define ENC_CNTRL_RST_SEL (1 << 1) |
| 228 | # define ENC_CNTRL_CTL_CODE(x) (((x) & 3) << 2) |
| 229 | |
| 230 | |
| 231 | /* Page 12h: HDCP and OTP */ |
| 232 | #define REG_TX3 REG(0x12, 0x9a) /* read/write */ |
Russell King | 063b472 | 2013-08-14 21:43:26 +0200 | [diff] [blame] | 233 | #define REG_TX4 REG(0x12, 0x9b) /* read/write */ |
| 234 | # define TX4_PD_RAM (1 << 1) |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 235 | #define REG_TX33 REG(0x12, 0xb8) /* read/write */ |
| 236 | # define TX33_HDMI (1 << 1) |
| 237 | |
| 238 | |
| 239 | /* Page 13h: Gamut related metadata packets */ |
| 240 | |
| 241 | |
| 242 | |
| 243 | /* CEC registers: (not paged) |
| 244 | */ |
| 245 | #define REG_CEC_FRO_IM_CLK_CTRL 0xfb /* read/write */ |
| 246 | # define CEC_FRO_IM_CLK_CTRL_GHOST_DIS (1 << 7) |
| 247 | # define CEC_FRO_IM_CLK_CTRL_ENA_OTP (1 << 6) |
| 248 | # define CEC_FRO_IM_CLK_CTRL_IMCLK_SEL (1 << 1) |
| 249 | # define CEC_FRO_IM_CLK_CTRL_FRO_DIV (1 << 0) |
| 250 | #define REG_CEC_RXSHPDLEV 0xfe /* read */ |
| 251 | # define CEC_RXSHPDLEV_RXSENS (1 << 0) |
| 252 | # define CEC_RXSHPDLEV_HPD (1 << 1) |
| 253 | |
| 254 | #define REG_CEC_ENAMODS 0xff /* read/write */ |
| 255 | # define CEC_ENAMODS_DIS_FRO (1 << 6) |
| 256 | # define CEC_ENAMODS_DIS_CCLK (1 << 5) |
| 257 | # define CEC_ENAMODS_EN_RXSENS (1 << 2) |
| 258 | # define CEC_ENAMODS_EN_HDMI (1 << 1) |
| 259 | # define CEC_ENAMODS_EN_CEC (1 << 0) |
| 260 | |
| 261 | |
| 262 | /* Device versions: */ |
| 263 | #define TDA9989N2 0x0101 |
| 264 | #define TDA19989 0x0201 |
| 265 | #define TDA19989N2 0x0202 |
| 266 | #define TDA19988 0x0301 |
| 267 | |
| 268 | static void |
| 269 | cec_write(struct drm_encoder *encoder, uint16_t addr, uint8_t val) |
| 270 | { |
| 271 | struct i2c_client *client = to_tda998x_priv(encoder)->cec; |
| 272 | uint8_t buf[] = {addr, val}; |
| 273 | int ret; |
| 274 | |
| 275 | ret = i2c_master_send(client, buf, ARRAY_SIZE(buf)); |
| 276 | if (ret < 0) |
| 277 | dev_err(&client->dev, "Error %d writing to cec:0x%x\n", ret, addr); |
| 278 | } |
| 279 | |
| 280 | static uint8_t |
| 281 | cec_read(struct drm_encoder *encoder, uint8_t addr) |
| 282 | { |
| 283 | struct i2c_client *client = to_tda998x_priv(encoder)->cec; |
| 284 | uint8_t val; |
| 285 | int ret; |
| 286 | |
| 287 | ret = i2c_master_send(client, &addr, sizeof(addr)); |
| 288 | if (ret < 0) |
| 289 | goto fail; |
| 290 | |
| 291 | ret = i2c_master_recv(client, &val, sizeof(val)); |
| 292 | if (ret < 0) |
| 293 | goto fail; |
| 294 | |
| 295 | return val; |
| 296 | |
| 297 | fail: |
| 298 | dev_err(&client->dev, "Error %d reading from cec:0x%x\n", ret, addr); |
| 299 | return 0; |
| 300 | } |
| 301 | |
| 302 | static void |
| 303 | set_page(struct drm_encoder *encoder, uint16_t reg) |
| 304 | { |
| 305 | struct tda998x_priv *priv = to_tda998x_priv(encoder); |
| 306 | |
| 307 | if (REG2PAGE(reg) != priv->current_page) { |
| 308 | struct i2c_client *client = drm_i2c_encoder_get_client(encoder); |
| 309 | uint8_t buf[] = { |
| 310 | REG_CURPAGE, REG2PAGE(reg) |
| 311 | }; |
| 312 | int ret = i2c_master_send(client, buf, sizeof(buf)); |
| 313 | if (ret < 0) |
| 314 | dev_err(&client->dev, "Error %d writing to REG_CURPAGE\n", ret); |
| 315 | |
| 316 | priv->current_page = REG2PAGE(reg); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | static int |
| 321 | reg_read_range(struct drm_encoder *encoder, uint16_t reg, char *buf, int cnt) |
| 322 | { |
| 323 | struct i2c_client *client = drm_i2c_encoder_get_client(encoder); |
| 324 | uint8_t addr = REG2ADDR(reg); |
| 325 | int ret; |
| 326 | |
| 327 | set_page(encoder, reg); |
| 328 | |
| 329 | ret = i2c_master_send(client, &addr, sizeof(addr)); |
| 330 | if (ret < 0) |
| 331 | goto fail; |
| 332 | |
| 333 | ret = i2c_master_recv(client, buf, cnt); |
| 334 | if (ret < 0) |
| 335 | goto fail; |
| 336 | |
| 337 | return ret; |
| 338 | |
| 339 | fail: |
| 340 | dev_err(&client->dev, "Error %d reading from 0x%x\n", ret, reg); |
| 341 | return ret; |
| 342 | } |
| 343 | |
| 344 | static uint8_t |
| 345 | reg_read(struct drm_encoder *encoder, uint16_t reg) |
| 346 | { |
| 347 | uint8_t val = 0; |
| 348 | reg_read_range(encoder, reg, &val, sizeof(val)); |
| 349 | return val; |
| 350 | } |
| 351 | |
| 352 | static void |
| 353 | reg_write(struct drm_encoder *encoder, uint16_t reg, uint8_t val) |
| 354 | { |
| 355 | struct i2c_client *client = drm_i2c_encoder_get_client(encoder); |
| 356 | uint8_t buf[] = {REG2ADDR(reg), val}; |
| 357 | int ret; |
| 358 | |
| 359 | set_page(encoder, reg); |
| 360 | |
| 361 | ret = i2c_master_send(client, buf, ARRAY_SIZE(buf)); |
| 362 | if (ret < 0) |
| 363 | dev_err(&client->dev, "Error %d writing to 0x%x\n", ret, reg); |
| 364 | } |
| 365 | |
| 366 | static void |
| 367 | reg_write16(struct drm_encoder *encoder, uint16_t reg, uint16_t val) |
| 368 | { |
| 369 | struct i2c_client *client = drm_i2c_encoder_get_client(encoder); |
| 370 | uint8_t buf[] = {REG2ADDR(reg), val >> 8, val}; |
| 371 | int ret; |
| 372 | |
| 373 | set_page(encoder, reg); |
| 374 | |
| 375 | ret = i2c_master_send(client, buf, ARRAY_SIZE(buf)); |
| 376 | if (ret < 0) |
| 377 | dev_err(&client->dev, "Error %d writing to 0x%x\n", ret, reg); |
| 378 | } |
| 379 | |
| 380 | static void |
| 381 | reg_set(struct drm_encoder *encoder, uint16_t reg, uint8_t val) |
| 382 | { |
| 383 | reg_write(encoder, reg, reg_read(encoder, reg) | val); |
| 384 | } |
| 385 | |
| 386 | static void |
| 387 | reg_clear(struct drm_encoder *encoder, uint16_t reg, uint8_t val) |
| 388 | { |
| 389 | reg_write(encoder, reg, reg_read(encoder, reg) & ~val); |
| 390 | } |
| 391 | |
| 392 | static void |
| 393 | tda998x_reset(struct drm_encoder *encoder) |
| 394 | { |
| 395 | /* reset audio and i2c master: */ |
| 396 | reg_set(encoder, REG_SOFTRESET, SOFTRESET_AUDIO | SOFTRESET_I2C_MASTER); |
| 397 | msleep(50); |
| 398 | reg_clear(encoder, REG_SOFTRESET, SOFTRESET_AUDIO | SOFTRESET_I2C_MASTER); |
| 399 | msleep(50); |
| 400 | |
| 401 | /* reset transmitter: */ |
| 402 | reg_set(encoder, REG_MAIN_CNTRL0, MAIN_CNTRL0_SR); |
| 403 | reg_clear(encoder, REG_MAIN_CNTRL0, MAIN_CNTRL0_SR); |
| 404 | |
| 405 | /* PLL registers common configuration */ |
| 406 | reg_write(encoder, REG_PLL_SERIAL_1, 0x00); |
| 407 | reg_write(encoder, REG_PLL_SERIAL_2, PLL_SERIAL_2_SRL_NOSC(1)); |
| 408 | reg_write(encoder, REG_PLL_SERIAL_3, 0x00); |
| 409 | reg_write(encoder, REG_SERIALIZER, 0x00); |
| 410 | reg_write(encoder, REG_BUFFER_OUT, 0x00); |
| 411 | reg_write(encoder, REG_PLL_SCG1, 0x00); |
| 412 | reg_write(encoder, REG_AUDIO_DIV, 0x03); |
| 413 | reg_write(encoder, REG_SEL_CLK, SEL_CLK_SEL_CLK1 | SEL_CLK_ENA_SC_CLK); |
| 414 | reg_write(encoder, REG_PLL_SCGN1, 0xfa); |
| 415 | reg_write(encoder, REG_PLL_SCGN2, 0x00); |
| 416 | reg_write(encoder, REG_PLL_SCGR1, 0x5b); |
| 417 | reg_write(encoder, REG_PLL_SCGR2, 0x00); |
| 418 | reg_write(encoder, REG_PLL_SCG2, 0x10); |
Russell King | bcb2481 | 2013-08-14 21:43:27 +0200 | [diff] [blame] | 419 | |
| 420 | /* Write the default value MUX register */ |
| 421 | reg_write(encoder, REG_MUX_VP_VIP_OUT, 0x24); |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | /* DRM encoder functions */ |
| 425 | |
| 426 | static void |
| 427 | tda998x_encoder_set_config(struct drm_encoder *encoder, void *params) |
| 428 | { |
| 429 | } |
| 430 | |
| 431 | static void |
| 432 | tda998x_encoder_dpms(struct drm_encoder *encoder, int mode) |
| 433 | { |
| 434 | struct tda998x_priv *priv = to_tda998x_priv(encoder); |
| 435 | |
| 436 | /* we only care about on or off: */ |
| 437 | if (mode != DRM_MODE_DPMS_ON) |
| 438 | mode = DRM_MODE_DPMS_OFF; |
| 439 | |
| 440 | if (mode == priv->dpms) |
| 441 | return; |
| 442 | |
| 443 | switch (mode) { |
| 444 | case DRM_MODE_DPMS_ON: |
| 445 | /* enable audio and video ports */ |
| 446 | reg_write(encoder, REG_ENA_AP, 0xff); |
| 447 | reg_write(encoder, REG_ENA_VP_0, 0xff); |
| 448 | reg_write(encoder, REG_ENA_VP_1, 0xff); |
| 449 | reg_write(encoder, REG_ENA_VP_2, 0xff); |
| 450 | /* set muxing after enabling ports: */ |
| 451 | reg_write(encoder, REG_VIP_CNTRL_0, |
| 452 | VIP_CNTRL_0_SWAP_A(2) | VIP_CNTRL_0_SWAP_B(3)); |
| 453 | reg_write(encoder, REG_VIP_CNTRL_1, |
| 454 | VIP_CNTRL_1_SWAP_C(0) | VIP_CNTRL_1_SWAP_D(1)); |
| 455 | reg_write(encoder, REG_VIP_CNTRL_2, |
| 456 | VIP_CNTRL_2_SWAP_E(4) | VIP_CNTRL_2_SWAP_F(5)); |
| 457 | break; |
| 458 | case DRM_MODE_DPMS_OFF: |
| 459 | /* disable audio and video ports */ |
| 460 | reg_write(encoder, REG_ENA_AP, 0x00); |
| 461 | reg_write(encoder, REG_ENA_VP_0, 0x00); |
| 462 | reg_write(encoder, REG_ENA_VP_1, 0x00); |
| 463 | reg_write(encoder, REG_ENA_VP_2, 0x00); |
| 464 | break; |
| 465 | } |
| 466 | |
| 467 | priv->dpms = mode; |
| 468 | } |
| 469 | |
| 470 | static void |
| 471 | tda998x_encoder_save(struct drm_encoder *encoder) |
| 472 | { |
| 473 | DBG(""); |
| 474 | } |
| 475 | |
| 476 | static void |
| 477 | tda998x_encoder_restore(struct drm_encoder *encoder) |
| 478 | { |
| 479 | DBG(""); |
| 480 | } |
| 481 | |
| 482 | static bool |
| 483 | tda998x_encoder_mode_fixup(struct drm_encoder *encoder, |
| 484 | const struct drm_display_mode *mode, |
| 485 | struct drm_display_mode *adjusted_mode) |
| 486 | { |
| 487 | return true; |
| 488 | } |
| 489 | |
| 490 | static int |
| 491 | tda998x_encoder_mode_valid(struct drm_encoder *encoder, |
| 492 | struct drm_display_mode *mode) |
| 493 | { |
| 494 | return MODE_OK; |
| 495 | } |
| 496 | |
| 497 | static void |
| 498 | tda998x_encoder_mode_set(struct drm_encoder *encoder, |
| 499 | struct drm_display_mode *mode, |
| 500 | struct drm_display_mode *adjusted_mode) |
| 501 | { |
| 502 | struct tda998x_priv *priv = to_tda998x_priv(encoder); |
| 503 | uint16_t hs_start, hs_end, line_start, line_end; |
| 504 | uint16_t vwin_start, vwin_end, de_start, de_end; |
| 505 | uint16_t ref_pix, ref_line, pix_start2; |
| 506 | uint8_t reg, div, rep; |
| 507 | |
| 508 | hs_start = mode->hsync_start - mode->hdisplay; |
| 509 | hs_end = mode->hsync_end - mode->hdisplay; |
| 510 | line_start = 1; |
| 511 | line_end = 1 + mode->vsync_end - mode->vsync_start; |
| 512 | vwin_start = mode->vtotal - mode->vsync_start; |
| 513 | vwin_end = vwin_start + mode->vdisplay; |
| 514 | de_start = mode->htotal - mode->hdisplay; |
| 515 | de_end = mode->htotal; |
| 516 | |
| 517 | pix_start2 = 0; |
| 518 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 519 | pix_start2 = (mode->htotal / 2) + hs_start; |
| 520 | |
| 521 | /* TODO how is this value calculated? It is 2 for all common |
| 522 | * formats in the tables in out of tree nxp driver (assuming |
| 523 | * I've properly deciphered their byzantine table system) |
| 524 | */ |
| 525 | ref_line = 2; |
| 526 | |
| 527 | /* this might changes for other color formats from the CRTC: */ |
| 528 | ref_pix = 3 + hs_start; |
| 529 | |
| 530 | div = 148500 / mode->clock; |
| 531 | |
| 532 | DBG("clock=%d, div=%u", mode->clock, div); |
| 533 | DBG("hs_start=%u, hs_end=%u, line_start=%u, line_end=%u", |
| 534 | hs_start, hs_end, line_start, line_end); |
| 535 | DBG("vwin_start=%u, vwin_end=%u, de_start=%u, de_end=%u", |
| 536 | vwin_start, vwin_end, de_start, de_end); |
| 537 | DBG("ref_line=%u, ref_pix=%u, pix_start2=%u", |
| 538 | ref_line, ref_pix, pix_start2); |
| 539 | |
| 540 | /* mute the audio FIFO: */ |
| 541 | reg_set(encoder, REG_AIP_CNTRL_0, AIP_CNTRL_0_RST_FIFO); |
| 542 | |
| 543 | /* set HDMI HDCP mode off: */ |
| 544 | reg_set(encoder, REG_TBG_CNTRL_1, TBG_CNTRL_1_DWIN_DIS); |
| 545 | reg_clear(encoder, REG_TX33, TX33_HDMI); |
| 546 | |
| 547 | reg_write(encoder, REG_ENC_CNTRL, ENC_CNTRL_CTL_CODE(0)); |
| 548 | /* no pre-filter or interpolator: */ |
| 549 | reg_write(encoder, REG_HVF_CNTRL_0, HVF_CNTRL_0_PREFIL(0) | |
| 550 | HVF_CNTRL_0_INTPOL(0)); |
| 551 | reg_write(encoder, REG_VIP_CNTRL_5, VIP_CNTRL_5_SP_CNT(0)); |
| 552 | reg_write(encoder, REG_VIP_CNTRL_4, VIP_CNTRL_4_BLANKIT(0) | |
| 553 | VIP_CNTRL_4_BLC(0)); |
| 554 | reg_clear(encoder, REG_PLL_SERIAL_3, PLL_SERIAL_3_SRL_CCIR); |
| 555 | |
| 556 | reg_clear(encoder, REG_PLL_SERIAL_1, PLL_SERIAL_1_SRL_MAN_IZ); |
| 557 | reg_clear(encoder, REG_PLL_SERIAL_3, PLL_SERIAL_3_SRL_DE); |
| 558 | reg_write(encoder, REG_SERIALIZER, 0); |
| 559 | reg_write(encoder, REG_HVF_CNTRL_1, HVF_CNTRL_1_VQR(0)); |
| 560 | |
| 561 | /* TODO enable pixel repeat for pixel rates less than 25Msamp/s */ |
| 562 | rep = 0; |
| 563 | reg_write(encoder, REG_RPT_CNTRL, 0); |
| 564 | reg_write(encoder, REG_SEL_CLK, SEL_CLK_SEL_VRF_CLK(0) | |
| 565 | SEL_CLK_SEL_CLK1 | SEL_CLK_ENA_SC_CLK); |
| 566 | |
| 567 | reg_write(encoder, REG_PLL_SERIAL_2, PLL_SERIAL_2_SRL_NOSC(div) | |
| 568 | PLL_SERIAL_2_SRL_PR(rep)); |
| 569 | |
| 570 | reg_write16(encoder, REG_VS_PIX_STRT_2_MSB, pix_start2); |
| 571 | reg_write16(encoder, REG_VS_PIX_END_2_MSB, pix_start2); |
| 572 | |
| 573 | /* set color matrix bypass flag: */ |
| 574 | reg_set(encoder, REG_MAT_CONTRL, MAT_CONTRL_MAT_BP); |
| 575 | |
| 576 | /* set BIAS tmds value: */ |
| 577 | reg_write(encoder, REG_ANA_GENERAL, 0x09); |
| 578 | |
| 579 | reg_clear(encoder, REG_TBG_CNTRL_0, TBG_CNTRL_0_SYNC_MTHD); |
| 580 | |
| 581 | reg_write(encoder, REG_VIP_CNTRL_3, 0); |
| 582 | reg_set(encoder, REG_VIP_CNTRL_3, VIP_CNTRL_3_SYNC_HS); |
| 583 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 584 | reg_set(encoder, REG_VIP_CNTRL_3, VIP_CNTRL_3_V_TGL); |
| 585 | |
| 586 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) |
| 587 | reg_set(encoder, REG_VIP_CNTRL_3, VIP_CNTRL_3_H_TGL); |
| 588 | |
| 589 | reg_write(encoder, REG_VIDFORMAT, 0x00); |
Russell King | 20c1767 | 2013-08-14 21:43:28 +0200 | [diff] [blame^] | 590 | reg_write16(encoder, REG_NPIX_MSB, mode->htotal); |
| 591 | reg_write16(encoder, REG_NLINE_MSB, mode->vtotal); |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 592 | reg_write16(encoder, REG_VS_LINE_STRT_1_MSB, line_start); |
| 593 | reg_write16(encoder, REG_VS_LINE_END_1_MSB, line_end); |
| 594 | reg_write16(encoder, REG_VS_PIX_STRT_1_MSB, hs_start); |
| 595 | reg_write16(encoder, REG_VS_PIX_END_1_MSB, hs_start); |
| 596 | reg_write16(encoder, REG_HS_PIX_START_MSB, hs_start); |
| 597 | reg_write16(encoder, REG_HS_PIX_STOP_MSB, hs_end); |
| 598 | reg_write16(encoder, REG_VWIN_START_1_MSB, vwin_start); |
| 599 | reg_write16(encoder, REG_VWIN_END_1_MSB, vwin_end); |
| 600 | reg_write16(encoder, REG_DE_START_MSB, de_start); |
| 601 | reg_write16(encoder, REG_DE_STOP_MSB, de_end); |
| 602 | |
| 603 | if (priv->rev == TDA19988) { |
| 604 | /* let incoming pixels fill the active space (if any) */ |
| 605 | reg_write(encoder, REG_ENABLE_SPACE, 0x01); |
| 606 | } |
| 607 | |
| 608 | reg_write16(encoder, REG_REFPIX_MSB, ref_pix); |
| 609 | reg_write16(encoder, REG_REFLINE_MSB, ref_line); |
| 610 | |
| 611 | reg = TBG_CNTRL_1_VHX_EXT_DE | |
| 612 | TBG_CNTRL_1_VHX_EXT_HS | |
| 613 | TBG_CNTRL_1_VHX_EXT_VS | |
| 614 | TBG_CNTRL_1_DWIN_DIS | /* HDCP off */ |
| 615 | TBG_CNTRL_1_VH_TGL_2; |
| 616 | if (mode->flags & (DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC)) |
| 617 | reg |= TBG_CNTRL_1_VH_TGL_0; |
| 618 | reg_set(encoder, REG_TBG_CNTRL_1, reg); |
| 619 | |
| 620 | /* must be last register set: */ |
| 621 | reg_clear(encoder, REG_TBG_CNTRL_0, TBG_CNTRL_0_SYNC_ONCE); |
| 622 | } |
| 623 | |
| 624 | static enum drm_connector_status |
| 625 | tda998x_encoder_detect(struct drm_encoder *encoder, |
| 626 | struct drm_connector *connector) |
| 627 | { |
| 628 | uint8_t val = cec_read(encoder, REG_CEC_RXSHPDLEV); |
| 629 | return (val & CEC_RXSHPDLEV_HPD) ? connector_status_connected : |
| 630 | connector_status_disconnected; |
| 631 | } |
| 632 | |
| 633 | static int |
| 634 | read_edid_block(struct drm_encoder *encoder, uint8_t *buf, int blk) |
| 635 | { |
| 636 | uint8_t offset, segptr; |
| 637 | int ret, i; |
| 638 | |
| 639 | /* enable EDID read irq: */ |
| 640 | reg_set(encoder, REG_INT_FLAGS_2, INT_FLAGS_2_EDID_BLK_RD); |
| 641 | |
| 642 | offset = (blk & 1) ? 128 : 0; |
| 643 | segptr = blk / 2; |
| 644 | |
| 645 | reg_write(encoder, REG_DDC_ADDR, 0xa0); |
| 646 | reg_write(encoder, REG_DDC_OFFS, offset); |
| 647 | reg_write(encoder, REG_DDC_SEGM_ADDR, 0x60); |
| 648 | reg_write(encoder, REG_DDC_SEGM, segptr); |
| 649 | |
| 650 | /* enable reading EDID: */ |
| 651 | reg_write(encoder, REG_EDID_CTRL, 0x1); |
| 652 | |
| 653 | /* flag must be cleared by sw: */ |
| 654 | reg_write(encoder, REG_EDID_CTRL, 0x0); |
| 655 | |
| 656 | /* wait for block read to complete: */ |
| 657 | for (i = 100; i > 0; i--) { |
| 658 | uint8_t val = reg_read(encoder, REG_INT_FLAGS_2); |
| 659 | if (val & INT_FLAGS_2_EDID_BLK_RD) |
| 660 | break; |
| 661 | msleep(1); |
| 662 | } |
| 663 | |
| 664 | if (i == 0) |
| 665 | return -ETIMEDOUT; |
| 666 | |
| 667 | ret = reg_read_range(encoder, REG_EDID_DATA_0, buf, EDID_LENGTH); |
| 668 | if (ret != EDID_LENGTH) { |
| 669 | dev_err(encoder->dev->dev, "failed to read edid block %d: %d", |
| 670 | blk, ret); |
| 671 | return ret; |
| 672 | } |
| 673 | |
| 674 | reg_clear(encoder, REG_INT_FLAGS_2, INT_FLAGS_2_EDID_BLK_RD); |
| 675 | |
| 676 | return 0; |
| 677 | } |
| 678 | |
| 679 | static uint8_t * |
| 680 | do_get_edid(struct drm_encoder *encoder) |
| 681 | { |
Russell King | 063b472 | 2013-08-14 21:43:26 +0200 | [diff] [blame] | 682 | struct tda998x_priv *priv = to_tda998x_priv(encoder); |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 683 | int j = 0, valid_extensions = 0; |
| 684 | uint8_t *block, *new; |
| 685 | bool print_bad_edid = drm_debug & DRM_UT_KMS; |
| 686 | |
| 687 | if ((block = kmalloc(EDID_LENGTH, GFP_KERNEL)) == NULL) |
| 688 | return NULL; |
| 689 | |
Russell King | 063b472 | 2013-08-14 21:43:26 +0200 | [diff] [blame] | 690 | if (priv->rev == TDA19988) |
| 691 | reg_clear(encoder, REG_TX4, TX4_PD_RAM); |
| 692 | |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 693 | /* base block fetch */ |
| 694 | if (read_edid_block(encoder, block, 0)) |
| 695 | goto fail; |
| 696 | |
| 697 | if (!drm_edid_block_valid(block, 0, print_bad_edid)) |
| 698 | goto fail; |
| 699 | |
| 700 | /* if there's no extensions, we're done */ |
| 701 | if (block[0x7e] == 0) |
Russell King | 063b472 | 2013-08-14 21:43:26 +0200 | [diff] [blame] | 702 | goto done; |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 703 | |
| 704 | new = krealloc(block, (block[0x7e] + 1) * EDID_LENGTH, GFP_KERNEL); |
| 705 | if (!new) |
| 706 | goto fail; |
| 707 | block = new; |
| 708 | |
| 709 | for (j = 1; j <= block[0x7e]; j++) { |
| 710 | uint8_t *ext_block = block + (valid_extensions + 1) * EDID_LENGTH; |
| 711 | if (read_edid_block(encoder, ext_block, j)) |
| 712 | goto fail; |
| 713 | |
| 714 | if (!drm_edid_block_valid(ext_block, j, print_bad_edid)) |
| 715 | goto fail; |
| 716 | |
| 717 | valid_extensions++; |
| 718 | } |
| 719 | |
| 720 | if (valid_extensions != block[0x7e]) { |
| 721 | block[EDID_LENGTH-1] += block[0x7e] - valid_extensions; |
| 722 | block[0x7e] = valid_extensions; |
| 723 | new = krealloc(block, (valid_extensions + 1) * EDID_LENGTH, GFP_KERNEL); |
| 724 | if (!new) |
| 725 | goto fail; |
| 726 | block = new; |
| 727 | } |
| 728 | |
Russell King | 063b472 | 2013-08-14 21:43:26 +0200 | [diff] [blame] | 729 | done: |
| 730 | if (priv->rev == TDA19988) |
| 731 | reg_set(encoder, REG_TX4, TX4_PD_RAM); |
| 732 | |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 733 | return block; |
| 734 | |
| 735 | fail: |
Russell King | 063b472 | 2013-08-14 21:43:26 +0200 | [diff] [blame] | 736 | if (priv->rev == TDA19988) |
| 737 | reg_set(encoder, REG_TX4, TX4_PD_RAM); |
Rob Clark | e7792ce | 2013-01-08 19:21:02 -0600 | [diff] [blame] | 738 | dev_warn(encoder->dev->dev, "failed to read EDID\n"); |
| 739 | kfree(block); |
| 740 | return NULL; |
| 741 | } |
| 742 | |
| 743 | static int |
| 744 | tda998x_encoder_get_modes(struct drm_encoder *encoder, |
| 745 | struct drm_connector *connector) |
| 746 | { |
| 747 | struct edid *edid = (struct edid *)do_get_edid(encoder); |
| 748 | int n = 0; |
| 749 | |
| 750 | if (edid) { |
| 751 | drm_mode_connector_update_edid_property(connector, edid); |
| 752 | n = drm_add_edid_modes(connector, edid); |
| 753 | kfree(edid); |
| 754 | } |
| 755 | |
| 756 | return n; |
| 757 | } |
| 758 | |
| 759 | static int |
| 760 | tda998x_encoder_create_resources(struct drm_encoder *encoder, |
| 761 | struct drm_connector *connector) |
| 762 | { |
| 763 | DBG(""); |
| 764 | return 0; |
| 765 | } |
| 766 | |
| 767 | static int |
| 768 | tda998x_encoder_set_property(struct drm_encoder *encoder, |
| 769 | struct drm_connector *connector, |
| 770 | struct drm_property *property, |
| 771 | uint64_t val) |
| 772 | { |
| 773 | DBG(""); |
| 774 | return 0; |
| 775 | } |
| 776 | |
| 777 | static void |
| 778 | tda998x_encoder_destroy(struct drm_encoder *encoder) |
| 779 | { |
| 780 | struct tda998x_priv *priv = to_tda998x_priv(encoder); |
| 781 | drm_i2c_encoder_destroy(encoder); |
| 782 | kfree(priv); |
| 783 | } |
| 784 | |
| 785 | static struct drm_encoder_slave_funcs tda998x_encoder_funcs = { |
| 786 | .set_config = tda998x_encoder_set_config, |
| 787 | .destroy = tda998x_encoder_destroy, |
| 788 | .dpms = tda998x_encoder_dpms, |
| 789 | .save = tda998x_encoder_save, |
| 790 | .restore = tda998x_encoder_restore, |
| 791 | .mode_fixup = tda998x_encoder_mode_fixup, |
| 792 | .mode_valid = tda998x_encoder_mode_valid, |
| 793 | .mode_set = tda998x_encoder_mode_set, |
| 794 | .detect = tda998x_encoder_detect, |
| 795 | .get_modes = tda998x_encoder_get_modes, |
| 796 | .create_resources = tda998x_encoder_create_resources, |
| 797 | .set_property = tda998x_encoder_set_property, |
| 798 | }; |
| 799 | |
| 800 | /* I2C driver functions */ |
| 801 | |
| 802 | static int |
| 803 | tda998x_probe(struct i2c_client *client, const struct i2c_device_id *id) |
| 804 | { |
| 805 | return 0; |
| 806 | } |
| 807 | |
| 808 | static int |
| 809 | tda998x_remove(struct i2c_client *client) |
| 810 | { |
| 811 | return 0; |
| 812 | } |
| 813 | |
| 814 | static int |
| 815 | tda998x_encoder_init(struct i2c_client *client, |
| 816 | struct drm_device *dev, |
| 817 | struct drm_encoder_slave *encoder_slave) |
| 818 | { |
| 819 | struct drm_encoder *encoder = &encoder_slave->base; |
| 820 | struct tda998x_priv *priv; |
| 821 | |
| 822 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
| 823 | if (!priv) |
| 824 | return -ENOMEM; |
| 825 | |
| 826 | priv->current_page = 0; |
| 827 | priv->cec = i2c_new_dummy(client->adapter, 0x34); |
| 828 | priv->dpms = DRM_MODE_DPMS_OFF; |
| 829 | |
| 830 | encoder_slave->slave_priv = priv; |
| 831 | encoder_slave->slave_funcs = &tda998x_encoder_funcs; |
| 832 | |
| 833 | /* wake up the device: */ |
| 834 | cec_write(encoder, REG_CEC_ENAMODS, |
| 835 | CEC_ENAMODS_EN_RXSENS | CEC_ENAMODS_EN_HDMI); |
| 836 | |
| 837 | tda998x_reset(encoder); |
| 838 | |
| 839 | /* read version: */ |
| 840 | priv->rev = reg_read(encoder, REG_VERSION_LSB) | |
| 841 | reg_read(encoder, REG_VERSION_MSB) << 8; |
| 842 | |
| 843 | /* mask off feature bits: */ |
| 844 | priv->rev &= ~0x30; /* not-hdcp and not-scalar bit */ |
| 845 | |
| 846 | switch (priv->rev) { |
| 847 | case TDA9989N2: dev_info(dev->dev, "found TDA9989 n2"); break; |
| 848 | case TDA19989: dev_info(dev->dev, "found TDA19989"); break; |
| 849 | case TDA19989N2: dev_info(dev->dev, "found TDA19989 n2"); break; |
| 850 | case TDA19988: dev_info(dev->dev, "found TDA19988"); break; |
| 851 | default: |
| 852 | DBG("found unsupported device: %04x", priv->rev); |
| 853 | goto fail; |
| 854 | } |
| 855 | |
| 856 | /* after reset, enable DDC: */ |
| 857 | reg_write(encoder, REG_DDC_DISABLE, 0x00); |
| 858 | |
| 859 | /* set clock on DDC channel: */ |
| 860 | reg_write(encoder, REG_TX3, 39); |
| 861 | |
| 862 | /* if necessary, disable multi-master: */ |
| 863 | if (priv->rev == TDA19989) |
| 864 | reg_set(encoder, REG_I2C_MASTER, I2C_MASTER_DIS_MM); |
| 865 | |
| 866 | cec_write(encoder, REG_CEC_FRO_IM_CLK_CTRL, |
| 867 | CEC_FRO_IM_CLK_CTRL_GHOST_DIS | CEC_FRO_IM_CLK_CTRL_IMCLK_SEL); |
| 868 | |
| 869 | return 0; |
| 870 | |
| 871 | fail: |
| 872 | /* if encoder_init fails, the encoder slave is never registered, |
| 873 | * so cleanup here: |
| 874 | */ |
| 875 | if (priv->cec) |
| 876 | i2c_unregister_device(priv->cec); |
| 877 | kfree(priv); |
| 878 | encoder_slave->slave_priv = NULL; |
| 879 | encoder_slave->slave_funcs = NULL; |
| 880 | return -ENXIO; |
| 881 | } |
| 882 | |
| 883 | static struct i2c_device_id tda998x_ids[] = { |
| 884 | { "tda998x", 0 }, |
| 885 | { } |
| 886 | }; |
| 887 | MODULE_DEVICE_TABLE(i2c, tda998x_ids); |
| 888 | |
| 889 | static struct drm_i2c_encoder_driver tda998x_driver = { |
| 890 | .i2c_driver = { |
| 891 | .probe = tda998x_probe, |
| 892 | .remove = tda998x_remove, |
| 893 | .driver = { |
| 894 | .name = "tda998x", |
| 895 | }, |
| 896 | .id_table = tda998x_ids, |
| 897 | }, |
| 898 | .encoder_init = tda998x_encoder_init, |
| 899 | }; |
| 900 | |
| 901 | /* Module initialization */ |
| 902 | |
| 903 | static int __init |
| 904 | tda998x_init(void) |
| 905 | { |
| 906 | DBG(""); |
| 907 | return drm_i2c_encoder_register(THIS_MODULE, &tda998x_driver); |
| 908 | } |
| 909 | |
| 910 | static void __exit |
| 911 | tda998x_exit(void) |
| 912 | { |
| 913 | DBG(""); |
| 914 | drm_i2c_encoder_unregister(&tda998x_driver); |
| 915 | } |
| 916 | |
| 917 | MODULE_AUTHOR("Rob Clark <robdclark@gmail.com"); |
| 918 | MODULE_DESCRIPTION("NXP Semiconductors TDA998X HDMI Encoder"); |
| 919 | MODULE_LICENSE("GPL"); |
| 920 | |
| 921 | module_init(tda998x_init); |
| 922 | module_exit(tda998x_exit); |