ch7006_priv.h 10 KB

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