1 1.3 riastrad /* $NetBSD: ch7006_priv.h,v 1.3 2021/12/18 23:45:27 riastradh Exp $ */ 2 1.3 riastrad 3 1.1 riastrad /* 4 1.1 riastrad * Copyright (C) 2009 Francisco Jerez. 5 1.1 riastrad * All Rights Reserved. 6 1.1 riastrad * 7 1.1 riastrad * Permission is hereby granted, free of charge, to any person obtaining 8 1.1 riastrad * a copy of this software and associated documentation files (the 9 1.1 riastrad * "Software"), to deal in the Software without restriction, including 10 1.1 riastrad * without limitation the rights to use, copy, modify, merge, publish, 11 1.1 riastrad * distribute, sublicense, and/or sell copies of the Software, and to 12 1.1 riastrad * permit persons to whom the Software is furnished to do so, subject to 13 1.1 riastrad * the following conditions: 14 1.1 riastrad * 15 1.1 riastrad * The above copyright notice and this permission notice (including the 16 1.1 riastrad * next paragraph) shall be included in all copies or substantial 17 1.1 riastrad * portions of the Software. 18 1.1 riastrad * 19 1.1 riastrad * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 1.1 riastrad * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 1.1 riastrad * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 22 1.1 riastrad * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE 23 1.1 riastrad * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24 1.1 riastrad * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 25 1.1 riastrad * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 1.1 riastrad * 27 1.1 riastrad */ 28 1.1 riastrad 29 1.1 riastrad #ifndef __DRM_I2C_CH7006_PRIV_H__ 30 1.1 riastrad #define __DRM_I2C_CH7006_PRIV_H__ 31 1.1 riastrad 32 1.1 riastrad #include <drm/drm_crtc_helper.h> 33 1.1 riastrad #include <drm/drm_encoder_slave.h> 34 1.3 riastrad #include <drm/drm_probe_helper.h> 35 1.1 riastrad #include <drm/i2c/ch7006.h> 36 1.1 riastrad 37 1.1 riastrad typedef int64_t fixed; 38 1.1 riastrad #define fixed1 (1LL << 32) 39 1.1 riastrad 40 1.1 riastrad enum ch7006_tv_norm { 41 1.1 riastrad TV_NORM_PAL, 42 1.1 riastrad TV_NORM_PAL_M, 43 1.1 riastrad TV_NORM_PAL_N, 44 1.1 riastrad TV_NORM_PAL_NC, 45 1.1 riastrad TV_NORM_PAL_60, 46 1.1 riastrad TV_NORM_NTSC_M, 47 1.1 riastrad TV_NORM_NTSC_J, 48 1.1 riastrad NUM_TV_NORMS 49 1.1 riastrad }; 50 1.1 riastrad 51 1.1 riastrad struct ch7006_tv_norm_info { 52 1.1 riastrad fixed vrefresh; 53 1.1 riastrad int vdisplay; 54 1.1 riastrad int vtotal; 55 1.1 riastrad int hvirtual; 56 1.1 riastrad 57 1.1 riastrad fixed subc_freq; 58 1.1 riastrad fixed black_level; 59 1.1 riastrad 60 1.1 riastrad uint32_t dispmode; 61 1.1 riastrad int voffset; 62 1.1 riastrad }; 63 1.1 riastrad 64 1.1 riastrad struct ch7006_mode { 65 1.1 riastrad struct drm_display_mode mode; 66 1.1 riastrad 67 1.1 riastrad int enc_hdisp; 68 1.1 riastrad int enc_vdisp; 69 1.1 riastrad 70 1.1 riastrad fixed subc_coeff; 71 1.1 riastrad uint32_t dispmode; 72 1.1 riastrad 73 1.1 riastrad uint32_t valid_scales; 74 1.1 riastrad uint32_t valid_norms; 75 1.1 riastrad }; 76 1.1 riastrad 77 1.1 riastrad struct ch7006_state { 78 1.1 riastrad uint8_t regs[0x26]; 79 1.1 riastrad }; 80 1.1 riastrad 81 1.1 riastrad struct ch7006_priv { 82 1.1 riastrad struct ch7006_encoder_params params; 83 1.3 riastrad const struct ch7006_mode *mode; 84 1.1 riastrad 85 1.1 riastrad struct ch7006_state state; 86 1.1 riastrad struct ch7006_state saved_state; 87 1.1 riastrad 88 1.1 riastrad struct drm_property *scale_property; 89 1.1 riastrad 90 1.1 riastrad int select_subconnector; 91 1.1 riastrad int subconnector; 92 1.1 riastrad int hmargin; 93 1.1 riastrad int vmargin; 94 1.1 riastrad enum ch7006_tv_norm norm; 95 1.1 riastrad int brightness; 96 1.1 riastrad int contrast; 97 1.1 riastrad int flicker; 98 1.1 riastrad int scale; 99 1.1 riastrad 100 1.1 riastrad int chip_version; 101 1.1 riastrad int last_dpms; 102 1.1 riastrad }; 103 1.1 riastrad 104 1.1 riastrad #define to_ch7006_priv(x) \ 105 1.1 riastrad ((struct ch7006_priv *)to_encoder_slave(x)->slave_priv) 106 1.1 riastrad 107 1.1 riastrad extern int ch7006_debug; 108 1.1 riastrad extern char *ch7006_tv_norm; 109 1.1 riastrad extern int ch7006_scale; 110 1.1 riastrad 111 1.3 riastrad extern const char * const ch7006_tv_norm_names[]; 112 1.3 riastrad extern const struct ch7006_tv_norm_info ch7006_tv_norms[]; 113 1.3 riastrad extern const struct ch7006_mode ch7006_modes[]; 114 1.1 riastrad 115 1.3 riastrad const struct ch7006_mode *ch7006_lookup_mode(struct drm_encoder *encoder, 116 1.3 riastrad const struct drm_display_mode *drm_mode); 117 1.1 riastrad 118 1.1 riastrad void ch7006_setup_levels(struct drm_encoder *encoder); 119 1.1 riastrad void ch7006_setup_subcarrier(struct drm_encoder *encoder); 120 1.1 riastrad void ch7006_setup_pll(struct drm_encoder *encoder); 121 1.1 riastrad void ch7006_setup_power_state(struct drm_encoder *encoder); 122 1.1 riastrad void ch7006_setup_properties(struct drm_encoder *encoder); 123 1.1 riastrad 124 1.1 riastrad void ch7006_write(struct i2c_client *client, uint8_t addr, uint8_t val); 125 1.1 riastrad uint8_t ch7006_read(struct i2c_client *client, uint8_t addr); 126 1.1 riastrad 127 1.1 riastrad void ch7006_state_load(struct i2c_client *client, 128 1.1 riastrad struct ch7006_state *state); 129 1.1 riastrad void ch7006_state_save(struct i2c_client *client, 130 1.1 riastrad struct ch7006_state *state); 131 1.1 riastrad 132 1.1 riastrad /* Some helper macros */ 133 1.1 riastrad 134 1.1 riastrad #define ch7006_dbg(client, format, ...) do { \ 135 1.1 riastrad if (ch7006_debug) \ 136 1.1 riastrad dev_printk(KERN_DEBUG, &client->dev, \ 137 1.1 riastrad "%s: " format, __func__, ## __VA_ARGS__); \ 138 1.1 riastrad } while (0) 139 1.1 riastrad #define ch7006_info(client, format, ...) \ 140 1.1 riastrad dev_info(&client->dev, format, __VA_ARGS__) 141 1.1 riastrad #define ch7006_err(client, format, ...) \ 142 1.1 riastrad dev_err(&client->dev, format, __VA_ARGS__) 143 1.1 riastrad 144 1.1 riastrad #define __mask(src, bitfield) \ 145 1.1 riastrad (((2 << (1 ? bitfield)) - 1) & ~((1 << (0 ? bitfield)) - 1)) 146 1.1 riastrad #define mask(bitfield) __mask(bitfield) 147 1.1 riastrad 148 1.1 riastrad #define __bitf(src, bitfield, x) \ 149 1.1 riastrad (((x) >> (src) << (0 ? bitfield)) & __mask(src, bitfield)) 150 1.1 riastrad #define bitf(bitfield, x) __bitf(bitfield, x) 151 1.1 riastrad #define bitfs(bitfield, s) __bitf(bitfield, bitfield##_##s) 152 1.1 riastrad #define setbitf(state, reg, bitfield, x) \ 153 1.1 riastrad state->regs[reg] = (state->regs[reg] & ~mask(reg##_##bitfield)) \ 154 1.1 riastrad | bitf(reg##_##bitfield, x) 155 1.1 riastrad 156 1.1 riastrad #define __unbitf(src, bitfield, x) \ 157 1.1 riastrad ((x & __mask(src, bitfield)) >> (0 ? bitfield) << (src)) 158 1.1 riastrad #define unbitf(bitfield, x) __unbitf(bitfield, x) 159 1.1 riastrad 160 1.1 riastrad static inline int interpolate(int y0, int y1, int y2, int x) 161 1.1 riastrad { 162 1.1 riastrad return y1 + (x < 50 ? y1 - y0 : y2 - y1) * (x - 50) / 50; 163 1.1 riastrad } 164 1.1 riastrad 165 1.1 riastrad static inline int32_t round_fixed(fixed x) 166 1.1 riastrad { 167 1.1 riastrad return (x + fixed1/2) >> 32; 168 1.1 riastrad } 169 1.1 riastrad 170 1.1 riastrad #define ch7006_load_reg(client, state, reg) ch7006_write(client, reg, state->regs[reg]) 171 1.1 riastrad #define ch7006_save_reg(client, state, reg) state->regs[reg] = ch7006_read(client, reg) 172 1.1 riastrad 173 1.1 riastrad /* Fixed hardware specs */ 174 1.1 riastrad 175 1.1 riastrad #define CH7006_FREQ0 14318 176 1.1 riastrad #define CH7006_MAXN 650 177 1.1 riastrad #define CH7006_MAXM 315 178 1.1 riastrad 179 1.1 riastrad /* Register definitions */ 180 1.1 riastrad 181 1.1 riastrad #define CH7006_DISPMODE 0x00 182 1.1 riastrad #define CH7006_DISPMODE_INPUT_RES 0, 7:5 183 1.1 riastrad #define CH7006_DISPMODE_INPUT_RES_512x384 0x0 184 1.1 riastrad #define CH7006_DISPMODE_INPUT_RES_720x400 0x1 185 1.1 riastrad #define CH7006_DISPMODE_INPUT_RES_640x400 0x2 186 1.1 riastrad #define CH7006_DISPMODE_INPUT_RES_640x480 0x3 187 1.1 riastrad #define CH7006_DISPMODE_INPUT_RES_800x600 0x4 188 1.1 riastrad #define CH7006_DISPMODE_INPUT_RES_NATIVE 0x5 189 1.1 riastrad #define CH7006_DISPMODE_OUTPUT_STD 0, 4:3 190 1.1 riastrad #define CH7006_DISPMODE_OUTPUT_STD_PAL 0x0 191 1.1 riastrad #define CH7006_DISPMODE_OUTPUT_STD_NTSC 0x1 192 1.1 riastrad #define CH7006_DISPMODE_OUTPUT_STD_PAL_M 0x2 193 1.1 riastrad #define CH7006_DISPMODE_OUTPUT_STD_NTSC_J 0x3 194 1.1 riastrad #define CH7006_DISPMODE_SCALING_RATIO 0, 2:0 195 1.1 riastrad #define CH7006_DISPMODE_SCALING_RATIO_5_4 0x0 196 1.1 riastrad #define CH7006_DISPMODE_SCALING_RATIO_1_1 0x1 197 1.1 riastrad #define CH7006_DISPMODE_SCALING_RATIO_7_8 0x2 198 1.1 riastrad #define CH7006_DISPMODE_SCALING_RATIO_5_6 0x3 199 1.1 riastrad #define CH7006_DISPMODE_SCALING_RATIO_3_4 0x4 200 1.1 riastrad #define CH7006_DISPMODE_SCALING_RATIO_7_10 0x5 201 1.1 riastrad 202 1.1 riastrad #define CH7006_FFILTER 0x01 203 1.1 riastrad #define CH7006_FFILTER_TEXT 0, 5:4 204 1.1 riastrad #define CH7006_FFILTER_LUMA 0, 3:2 205 1.1 riastrad #define CH7006_FFILTER_CHROMA 0, 1:0 206 1.1 riastrad #define CH7006_FFILTER_CHROMA_NO_DCRAWL 0x3 207 1.1 riastrad 208 1.1 riastrad #define CH7006_BWIDTH 0x03 209 1.1 riastrad #define CH7006_BWIDTH_5L_FFILER (1 << 7) 210 1.1 riastrad #define CH7006_BWIDTH_CVBS_NO_CHROMA (1 << 6) 211 1.1 riastrad #define CH7006_BWIDTH_CHROMA 0, 5:4 212 1.1 riastrad #define CH7006_BWIDTH_SVIDEO_YPEAK (1 << 3) 213 1.1 riastrad #define CH7006_BWIDTH_SVIDEO_LUMA 0, 2:1 214 1.1 riastrad #define CH7006_BWIDTH_CVBS_LUMA 0, 0:0 215 1.1 riastrad 216 1.1 riastrad #define CH7006_INPUT_FORMAT 0x04 217 1.1 riastrad #define CH7006_INPUT_FORMAT_DAC_GAIN (1 << 6) 218 1.1 riastrad #define CH7006_INPUT_FORMAT_RGB_PASS_THROUGH (1 << 5) 219 1.1 riastrad #define CH7006_INPUT_FORMAT_FORMAT 0, 3:0 220 1.1 riastrad #define CH7006_INPUT_FORMAT_FORMAT_RGB16 0x0 221 1.1 riastrad #define CH7006_INPUT_FORMAT_FORMAT_YCrCb24m16 0x1 222 1.1 riastrad #define CH7006_INPUT_FORMAT_FORMAT_RGB24m16 0x2 223 1.1 riastrad #define CH7006_INPUT_FORMAT_FORMAT_RGB15 0x3 224 1.1 riastrad #define CH7006_INPUT_FORMAT_FORMAT_RGB24m12C 0x4 225 1.1 riastrad #define CH7006_INPUT_FORMAT_FORMAT_RGB24m12I 0x5 226 1.1 riastrad #define CH7006_INPUT_FORMAT_FORMAT_RGB24m8 0x6 227 1.1 riastrad #define CH7006_INPUT_FORMAT_FORMAT_RGB16m8 0x7 228 1.1 riastrad #define CH7006_INPUT_FORMAT_FORMAT_RGB15m8 0x8 229 1.1 riastrad #define CH7006_INPUT_FORMAT_FORMAT_YCrCb24m8 0x9 230 1.1 riastrad 231 1.1 riastrad #define CH7006_CLKMODE 0x06 232 1.1 riastrad #define CH7006_CLKMODE_SUBC_LOCK (1 << 7) 233 1.1 riastrad #define CH7006_CLKMODE_MASTER (1 << 6) 234 1.1 riastrad #define CH7006_CLKMODE_POS_EDGE (1 << 4) 235 1.1 riastrad #define CH7006_CLKMODE_XCM 0, 3:2 236 1.1 riastrad #define CH7006_CLKMODE_PCM 0, 1:0 237 1.1 riastrad 238 1.1 riastrad #define CH7006_START_ACTIVE 0x07 239 1.1 riastrad #define CH7006_START_ACTIVE_0 0, 7:0 240 1.1 riastrad 241 1.1 riastrad #define CH7006_POV 0x08 242 1.1 riastrad #define CH7006_POV_START_ACTIVE_8 8, 2:2 243 1.1 riastrad #define CH7006_POV_HPOS_8 8, 1:1 244 1.1 riastrad #define CH7006_POV_VPOS_8 8, 0:0 245 1.1 riastrad 246 1.1 riastrad #define CH7006_BLACK_LEVEL 0x09 247 1.1 riastrad #define CH7006_BLACK_LEVEL_0 0, 7:0 248 1.1 riastrad 249 1.1 riastrad #define CH7006_HPOS 0x0a 250 1.1 riastrad #define CH7006_HPOS_0 0, 7:0 251 1.1 riastrad 252 1.1 riastrad #define CH7006_VPOS 0x0b 253 1.1 riastrad #define CH7006_VPOS_0 0, 7:0 254 1.1 riastrad 255 1.1 riastrad #define CH7006_INPUT_SYNC 0x0d 256 1.1 riastrad #define CH7006_INPUT_SYNC_EMBEDDED (1 << 3) 257 1.1 riastrad #define CH7006_INPUT_SYNC_OUTPUT (1 << 2) 258 1.1 riastrad #define CH7006_INPUT_SYNC_PVSYNC (1 << 1) 259 1.1 riastrad #define CH7006_INPUT_SYNC_PHSYNC (1 << 0) 260 1.1 riastrad 261 1.1 riastrad #define CH7006_POWER 0x0e 262 1.1 riastrad #define CH7006_POWER_SCART (1 << 4) 263 1.1 riastrad #define CH7006_POWER_RESET (1 << 3) 264 1.1 riastrad #define CH7006_POWER_LEVEL 0, 2:0 265 1.1 riastrad #define CH7006_POWER_LEVEL_CVBS_OFF 0x0 266 1.1 riastrad #define CH7006_POWER_LEVEL_POWER_OFF 0x1 267 1.1 riastrad #define CH7006_POWER_LEVEL_SVIDEO_OFF 0x2 268 1.1 riastrad #define CH7006_POWER_LEVEL_NORMAL 0x3 269 1.1 riastrad #define CH7006_POWER_LEVEL_FULL_POWER_OFF 0x4 270 1.1 riastrad 271 1.1 riastrad #define CH7006_DETECT 0x10 272 1.1 riastrad #define CH7006_DETECT_SVIDEO_Y_TEST (1 << 3) 273 1.1 riastrad #define CH7006_DETECT_SVIDEO_C_TEST (1 << 2) 274 1.1 riastrad #define CH7006_DETECT_CVBS_TEST (1 << 1) 275 1.1 riastrad #define CH7006_DETECT_SENSE (1 << 0) 276 1.1 riastrad 277 1.1 riastrad #define CH7006_CONTRAST 0x11 278 1.1 riastrad #define CH7006_CONTRAST_0 0, 2:0 279 1.1 riastrad 280 1.1 riastrad #define CH7006_PLLOV 0x13 281 1.1 riastrad #define CH7006_PLLOV_N_8 8, 2:1 282 1.1 riastrad #define CH7006_PLLOV_M_8 8, 0:0 283 1.1 riastrad 284 1.1 riastrad #define CH7006_PLLM 0x14 285 1.1 riastrad #define CH7006_PLLM_0 0, 7:0 286 1.1 riastrad 287 1.1 riastrad #define CH7006_PLLN 0x15 288 1.1 riastrad #define CH7006_PLLN_0 0, 7:0 289 1.1 riastrad 290 1.1 riastrad #define CH7006_BCLKOUT 0x17 291 1.1 riastrad 292 1.1 riastrad #define CH7006_SUBC_INC0 0x18 293 1.1 riastrad #define CH7006_SUBC_INC0_28 28, 3:0 294 1.1 riastrad 295 1.1 riastrad #define CH7006_SUBC_INC1 0x19 296 1.1 riastrad #define CH7006_SUBC_INC1_24 24, 3:0 297 1.1 riastrad 298 1.1 riastrad #define CH7006_SUBC_INC2 0x1a 299 1.1 riastrad #define CH7006_SUBC_INC2_20 20, 3:0 300 1.1 riastrad 301 1.1 riastrad #define CH7006_SUBC_INC3 0x1b 302 1.1 riastrad #define CH7006_SUBC_INC3_GPIO1_VAL (1 << 7) 303 1.1 riastrad #define CH7006_SUBC_INC3_GPIO0_VAL (1 << 6) 304 1.1 riastrad #define CH7006_SUBC_INC3_POUT_3_3V (1 << 5) 305 1.1 riastrad #define CH7006_SUBC_INC3_POUT_INV (1 << 4) 306 1.1 riastrad #define CH7006_SUBC_INC3_16 16, 3:0 307 1.1 riastrad 308 1.1 riastrad #define CH7006_SUBC_INC4 0x1c 309 1.1 riastrad #define CH7006_SUBC_INC4_GPIO1_IN (1 << 7) 310 1.1 riastrad #define CH7006_SUBC_INC4_GPIO0_IN (1 << 6) 311 1.1 riastrad #define CH7006_SUBC_INC4_DS_INPUT (1 << 4) 312 1.1 riastrad #define CH7006_SUBC_INC4_12 12, 3:0 313 1.1 riastrad 314 1.1 riastrad #define CH7006_SUBC_INC5 0x1d 315 1.1 riastrad #define CH7006_SUBC_INC5_8 8, 3:0 316 1.1 riastrad 317 1.1 riastrad #define CH7006_SUBC_INC6 0x1e 318 1.1 riastrad #define CH7006_SUBC_INC6_4 4, 3:0 319 1.1 riastrad 320 1.1 riastrad #define CH7006_SUBC_INC7 0x1f 321 1.1 riastrad #define CH7006_SUBC_INC7_0 0, 3:0 322 1.1 riastrad 323 1.1 riastrad #define CH7006_PLL_CONTROL 0x20 324 1.1 riastrad #define CH7006_PLL_CONTROL_CPI (1 << 5) 325 1.1 riastrad #define CH7006_PLL_CONTROL_CAPACITOR (1 << 4) 326 1.1 riastrad #define CH7006_PLL_CONTROL_7STAGES (1 << 3) 327 1.1 riastrad #define CH7006_PLL_CONTROL_DIGITAL_5V (1 << 2) 328 1.1 riastrad #define CH7006_PLL_CONTROL_ANALOG_5V (1 << 1) 329 1.1 riastrad #define CH7006_PLL_CONTROL_MEMORY_5V (1 << 0) 330 1.1 riastrad 331 1.1 riastrad #define CH7006_CALC_SUBC_INC0 0x21 332 1.1 riastrad #define CH7006_CALC_SUBC_INC0_24 24, 4:3 333 1.1 riastrad #define CH7006_CALC_SUBC_INC0_HYST 0, 2:1 334 1.1 riastrad #define CH7006_CALC_SUBC_INC0_AUTO (1 << 0) 335 1.1 riastrad 336 1.1 riastrad #define CH7006_CALC_SUBC_INC1 0x22 337 1.1 riastrad #define CH7006_CALC_SUBC_INC1_16 16, 7:0 338 1.1 riastrad 339 1.1 riastrad #define CH7006_CALC_SUBC_INC2 0x23 340 1.1 riastrad #define CH7006_CALC_SUBC_INC2_8 8, 7:0 341 1.1 riastrad 342 1.1 riastrad #define CH7006_CALC_SUBC_INC3 0x24 343 1.1 riastrad #define CH7006_CALC_SUBC_INC3_0 0, 7:0 344 1.1 riastrad 345 1.1 riastrad #define CH7006_VERSION_ID 0x25 346 1.1 riastrad 347 1.1 riastrad #endif 348