dvo_ch7017.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. /*
  2. * Copyright © 2006 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. * DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Eric Anholt <eric@anholt.net>
  25. *
  26. */
  27. #include "dvo.h"
  28. #define CH7017_TV_DISPLAY_MODE 0x00
  29. #define CH7017_FLICKER_FILTER 0x01
  30. #define CH7017_VIDEO_BANDWIDTH 0x02
  31. #define CH7017_TEXT_ENHANCEMENT 0x03
  32. #define CH7017_START_ACTIVE_VIDEO 0x04
  33. #define CH7017_HORIZONTAL_POSITION 0x05
  34. #define CH7017_VERTICAL_POSITION 0x06
  35. #define CH7017_BLACK_LEVEL 0x07
  36. #define CH7017_CONTRAST_ENHANCEMENT 0x08
  37. #define CH7017_TV_PLL 0x09
  38. #define CH7017_TV_PLL_M 0x0a
  39. #define CH7017_TV_PLL_N 0x0b
  40. #define CH7017_SUB_CARRIER_0 0x0c
  41. #define CH7017_CIV_CONTROL 0x10
  42. #define CH7017_CIV_0 0x11
  43. #define CH7017_CHROMA_BOOST 0x14
  44. #define CH7017_CLOCK_MODE 0x1c
  45. #define CH7017_INPUT_CLOCK 0x1d
  46. #define CH7017_GPIO_CONTROL 0x1e
  47. #define CH7017_INPUT_DATA_FORMAT 0x1f
  48. #define CH7017_CONNECTION_DETECT 0x20
  49. #define CH7017_DAC_CONTROL 0x21
  50. #define CH7017_BUFFERED_CLOCK_OUTPUT 0x22
  51. #define CH7017_DEFEAT_VSYNC 0x47
  52. #define CH7017_TEST_PATTERN 0x48
  53. #define CH7017_POWER_MANAGEMENT 0x49
  54. /** Enables the TV output path. */
  55. #define CH7017_TV_EN (1 << 0)
  56. #define CH7017_DAC0_POWER_DOWN (1 << 1)
  57. #define CH7017_DAC1_POWER_DOWN (1 << 2)
  58. #define CH7017_DAC2_POWER_DOWN (1 << 3)
  59. #define CH7017_DAC3_POWER_DOWN (1 << 4)
  60. /** Powers down the TV out block, and DAC0-3 */
  61. #define CH7017_TV_POWER_DOWN_EN (1 << 5)
  62. #define CH7017_VERSION_ID 0x4a
  63. #define CH7017_DEVICE_ID 0x4b
  64. #define CH7017_DEVICE_ID_VALUE 0x1b
  65. #define CH7018_DEVICE_ID_VALUE 0x1a
  66. #define CH7019_DEVICE_ID_VALUE 0x19
  67. #define CH7017_XCLK_D2_ADJUST 0x53
  68. #define CH7017_UP_SCALER_COEFF_0 0x55
  69. #define CH7017_UP_SCALER_COEFF_1 0x56
  70. #define CH7017_UP_SCALER_COEFF_2 0x57
  71. #define CH7017_UP_SCALER_COEFF_3 0x58
  72. #define CH7017_UP_SCALER_COEFF_4 0x59
  73. #define CH7017_UP_SCALER_VERTICAL_INC_0 0x5a
  74. #define CH7017_UP_SCALER_VERTICAL_INC_1 0x5b
  75. #define CH7017_GPIO_INVERT 0x5c
  76. #define CH7017_UP_SCALER_HORIZONTAL_INC_0 0x5d
  77. #define CH7017_UP_SCALER_HORIZONTAL_INC_1 0x5e
  78. #define CH7017_HORIZONTAL_ACTIVE_PIXEL_INPUT 0x5f
  79. /**< Low bits of horizontal active pixel input */
  80. #define CH7017_ACTIVE_INPUT_LINE_OUTPUT 0x60
  81. /** High bits of horizontal active pixel input */
  82. #define CH7017_LVDS_HAP_INPUT_MASK (0x7 << 0)
  83. /** High bits of vertical active line output */
  84. #define CH7017_LVDS_VAL_HIGH_MASK (0x7 << 3)
  85. #define CH7017_VERTICAL_ACTIVE_LINE_OUTPUT 0x61
  86. /**< Low bits of vertical active line output */
  87. #define CH7017_HORIZONTAL_ACTIVE_PIXEL_OUTPUT 0x62
  88. /**< Low bits of horizontal active pixel output */
  89. #define CH7017_LVDS_POWER_DOWN 0x63
  90. /** High bits of horizontal active pixel output */
  91. #define CH7017_LVDS_HAP_HIGH_MASK (0x7 << 0)
  92. /** Enables the LVDS power down state transition */
  93. #define CH7017_LVDS_POWER_DOWN_EN (1 << 6)
  94. /** Enables the LVDS upscaler */
  95. #define CH7017_LVDS_UPSCALER_EN (1 << 7)
  96. #define CH7017_LVDS_POWER_DOWN_DEFAULT_RESERVED 0x08
  97. #define CH7017_LVDS_ENCODING 0x64
  98. #define CH7017_LVDS_DITHER_2D (1 << 2)
  99. #define CH7017_LVDS_DITHER_DIS (1 << 3)
  100. #define CH7017_LVDS_DUAL_CHANNEL_EN (1 << 4)
  101. #define CH7017_LVDS_24_BIT (1 << 5)
  102. #define CH7017_LVDS_ENCODING_2 0x65
  103. #define CH7017_LVDS_PLL_CONTROL 0x66
  104. /** Enables the LVDS panel output path */
  105. #define CH7017_LVDS_PANEN (1 << 0)
  106. /** Enables the LVDS panel backlight */
  107. #define CH7017_LVDS_BKLEN (1 << 3)
  108. #define CH7017_POWER_SEQUENCING_T1 0x67
  109. #define CH7017_POWER_SEQUENCING_T2 0x68
  110. #define CH7017_POWER_SEQUENCING_T3 0x69
  111. #define CH7017_POWER_SEQUENCING_T4 0x6a
  112. #define CH7017_POWER_SEQUENCING_T5 0x6b
  113. #define CH7017_GPIO_DRIVER_TYPE 0x6c
  114. #define CH7017_GPIO_DATA 0x6d
  115. #define CH7017_GPIO_DIRECTION_CONTROL 0x6e
  116. #define CH7017_LVDS_PLL_FEEDBACK_DIV 0x71
  117. # define CH7017_LVDS_PLL_FEED_BACK_DIVIDER_SHIFT 4
  118. # define CH7017_LVDS_PLL_FEED_FORWARD_DIVIDER_SHIFT 0
  119. # define CH7017_LVDS_PLL_FEEDBACK_DEFAULT_RESERVED 0x80
  120. #define CH7017_LVDS_PLL_VCO_CONTROL 0x72
  121. # define CH7017_LVDS_PLL_VCO_DEFAULT_RESERVED 0x80
  122. # define CH7017_LVDS_PLL_VCO_SHIFT 4
  123. # define CH7017_LVDS_PLL_POST_SCALE_DIV_SHIFT 0
  124. #define CH7017_OUTPUTS_ENABLE 0x73
  125. # define CH7017_CHARGE_PUMP_LOW 0x0
  126. # define CH7017_CHARGE_PUMP_HIGH 0x3
  127. # define CH7017_LVDS_CHANNEL_A (1 << 3)
  128. # define CH7017_LVDS_CHANNEL_B (1 << 4)
  129. # define CH7017_TV_DAC_A (1 << 5)
  130. # define CH7017_TV_DAC_B (1 << 6)
  131. # define CH7017_DDC_SELECT_DC2 (1 << 7)
  132. #define CH7017_LVDS_OUTPUT_AMPLITUDE 0x74
  133. #define CH7017_LVDS_PLL_EMI_REDUCTION 0x75
  134. #define CH7017_LVDS_POWER_DOWN_FLICKER 0x76
  135. #define CH7017_LVDS_CONTROL_2 0x78
  136. # define CH7017_LOOP_FILTER_SHIFT 5
  137. # define CH7017_PHASE_DETECTOR_SHIFT 0
  138. #define CH7017_BANG_LIMIT_CONTROL 0x7f
  139. struct ch7017_priv {
  140. uint8_t dummy;
  141. };
  142. static void ch7017_dump_regs(struct intel_dvo_device *dvo);
  143. static void ch7017_dpms(struct intel_dvo_device *dvo, int mode);
  144. static bool ch7017_read(struct intel_dvo_device *dvo, int addr, uint8_t *val)
  145. {
  146. struct i2c_adapter *adapter = dvo->i2c_bus;
  147. struct intel_i2c_chan *i2cbus = container_of(adapter, struct intel_i2c_chan, adapter);
  148. u8 out_buf[2];
  149. u8 in_buf[2];
  150. struct i2c_msg msgs[] = {
  151. {
  152. .addr = dvo->slave_addr,
  153. .flags = 0,
  154. .len = 1,
  155. .buf = out_buf,
  156. },
  157. {
  158. .addr = dvo->slave_addr,
  159. .flags = I2C_M_RD,
  160. .len = 1,
  161. .buf = in_buf,
  162. }
  163. };
  164. out_buf[0] = addr;
  165. out_buf[1] = 0;
  166. if (i2c_transfer(&i2cbus->adapter, msgs, 2) == 2) {
  167. *val= in_buf[0];
  168. return true;
  169. };
  170. return false;
  171. }
  172. static bool ch7017_write(struct intel_dvo_device *dvo, int addr, uint8_t val)
  173. {
  174. struct i2c_adapter *adapter = dvo->i2c_bus;
  175. struct intel_i2c_chan *i2cbus = container_of(adapter, struct intel_i2c_chan, adapter);
  176. uint8_t out_buf[2];
  177. struct i2c_msg msg = {
  178. .addr = dvo->slave_addr,
  179. .flags = 0,
  180. .len = 2,
  181. .buf = out_buf,
  182. };
  183. out_buf[0] = addr;
  184. out_buf[1] = val;
  185. if (i2c_transfer(&i2cbus->adapter, &msg, 1) == 1)
  186. return true;
  187. return false;
  188. }
  189. /** Probes for a CH7017 on the given bus and slave address. */
  190. static bool ch7017_init(struct intel_dvo_device *dvo,
  191. struct i2c_adapter *adapter)
  192. {
  193. struct intel_i2c_chan *i2cbus = container_of(adapter, struct intel_i2c_chan, adapter);
  194. struct ch7017_priv *priv;
  195. uint8_t val;
  196. priv = kzalloc(sizeof(struct ch7017_priv), GFP_KERNEL);
  197. if (priv == NULL)
  198. return false;
  199. dvo->i2c_bus = adapter;
  200. dvo->dev_priv = priv;
  201. if (!ch7017_read(dvo, CH7017_DEVICE_ID, &val))
  202. goto fail;
  203. if (val != CH7017_DEVICE_ID_VALUE &&
  204. val != CH7018_DEVICE_ID_VALUE &&
  205. val != CH7019_DEVICE_ID_VALUE) {
  206. DRM_DEBUG_KMS("ch701x not detected, got %d: from %s "
  207. "Slave %d.\n",
  208. val, i2cbus->adapter.name,dvo->slave_addr);
  209. goto fail;
  210. }
  211. return true;
  212. fail:
  213. kfree(priv);
  214. return false;
  215. }
  216. static enum drm_connector_status ch7017_detect(struct intel_dvo_device *dvo)
  217. {
  218. return connector_status_unknown;
  219. }
  220. static enum drm_mode_status ch7017_mode_valid(struct intel_dvo_device *dvo,
  221. struct drm_display_mode *mode)
  222. {
  223. if (mode->clock > 160000)
  224. return MODE_CLOCK_HIGH;
  225. return MODE_OK;
  226. }
  227. static void ch7017_mode_set(struct intel_dvo_device *dvo,
  228. struct drm_display_mode *mode,
  229. struct drm_display_mode *adjusted_mode)
  230. {
  231. uint8_t lvds_pll_feedback_div, lvds_pll_vco_control;
  232. uint8_t outputs_enable, lvds_control_2, lvds_power_down;
  233. uint8_t horizontal_active_pixel_input;
  234. uint8_t horizontal_active_pixel_output, vertical_active_line_output;
  235. uint8_t active_input_line_output;
  236. DRM_DEBUG_KMS("Registers before mode setting\n");
  237. ch7017_dump_regs(dvo);
  238. /* LVDS PLL settings from page 75 of 7017-7017ds.pdf*/
  239. if (mode->clock < 100000) {
  240. outputs_enable = CH7017_LVDS_CHANNEL_A | CH7017_CHARGE_PUMP_LOW;
  241. lvds_pll_feedback_div = CH7017_LVDS_PLL_FEEDBACK_DEFAULT_RESERVED |
  242. (2 << CH7017_LVDS_PLL_FEED_BACK_DIVIDER_SHIFT) |
  243. (13 << CH7017_LVDS_PLL_FEED_FORWARD_DIVIDER_SHIFT);
  244. lvds_pll_vco_control = CH7017_LVDS_PLL_VCO_DEFAULT_RESERVED |
  245. (2 << CH7017_LVDS_PLL_VCO_SHIFT) |
  246. (3 << CH7017_LVDS_PLL_POST_SCALE_DIV_SHIFT);
  247. lvds_control_2 = (1 << CH7017_LOOP_FILTER_SHIFT) |
  248. (0 << CH7017_PHASE_DETECTOR_SHIFT);
  249. } else {
  250. outputs_enable = CH7017_LVDS_CHANNEL_A | CH7017_CHARGE_PUMP_HIGH;
  251. lvds_pll_feedback_div = CH7017_LVDS_PLL_FEEDBACK_DEFAULT_RESERVED |
  252. (2 << CH7017_LVDS_PLL_FEED_BACK_DIVIDER_SHIFT) |
  253. (3 << CH7017_LVDS_PLL_FEED_FORWARD_DIVIDER_SHIFT);
  254. lvds_pll_feedback_div = 35;
  255. lvds_control_2 = (3 << CH7017_LOOP_FILTER_SHIFT) |
  256. (0 << CH7017_PHASE_DETECTOR_SHIFT);
  257. if (1) { /* XXX: dual channel panel detection. Assume yes for now. */
  258. outputs_enable |= CH7017_LVDS_CHANNEL_B;
  259. lvds_pll_vco_control = CH7017_LVDS_PLL_VCO_DEFAULT_RESERVED |
  260. (2 << CH7017_LVDS_PLL_VCO_SHIFT) |
  261. (13 << CH7017_LVDS_PLL_POST_SCALE_DIV_SHIFT);
  262. } else {
  263. lvds_pll_vco_control = CH7017_LVDS_PLL_VCO_DEFAULT_RESERVED |
  264. (1 << CH7017_LVDS_PLL_VCO_SHIFT) |
  265. (13 << CH7017_LVDS_PLL_POST_SCALE_DIV_SHIFT);
  266. }
  267. }
  268. horizontal_active_pixel_input = mode->hdisplay & 0x00ff;
  269. vertical_active_line_output = mode->vdisplay & 0x00ff;
  270. horizontal_active_pixel_output = mode->hdisplay & 0x00ff;
  271. active_input_line_output = ((mode->hdisplay & 0x0700) >> 8) |
  272. (((mode->vdisplay & 0x0700) >> 8) << 3);
  273. lvds_power_down = CH7017_LVDS_POWER_DOWN_DEFAULT_RESERVED |
  274. (mode->hdisplay & 0x0700) >> 8;
  275. ch7017_dpms(dvo, DRM_MODE_DPMS_OFF);
  276. ch7017_write(dvo, CH7017_HORIZONTAL_ACTIVE_PIXEL_INPUT,
  277. horizontal_active_pixel_input);
  278. ch7017_write(dvo, CH7017_HORIZONTAL_ACTIVE_PIXEL_OUTPUT,
  279. horizontal_active_pixel_output);
  280. ch7017_write(dvo, CH7017_VERTICAL_ACTIVE_LINE_OUTPUT,
  281. vertical_active_line_output);
  282. ch7017_write(dvo, CH7017_ACTIVE_INPUT_LINE_OUTPUT,
  283. active_input_line_output);
  284. ch7017_write(dvo, CH7017_LVDS_PLL_VCO_CONTROL, lvds_pll_vco_control);
  285. ch7017_write(dvo, CH7017_LVDS_PLL_FEEDBACK_DIV, lvds_pll_feedback_div);
  286. ch7017_write(dvo, CH7017_LVDS_CONTROL_2, lvds_control_2);
  287. ch7017_write(dvo, CH7017_OUTPUTS_ENABLE, outputs_enable);
  288. /* Turn the LVDS back on with new settings. */
  289. ch7017_write(dvo, CH7017_LVDS_POWER_DOWN, lvds_power_down);
  290. DRM_DEBUG_KMS("Registers after mode setting\n");
  291. ch7017_dump_regs(dvo);
  292. }
  293. /* set the CH7017 power state */
  294. static void ch7017_dpms(struct intel_dvo_device *dvo, int mode)
  295. {
  296. uint8_t val;
  297. ch7017_read(dvo, CH7017_LVDS_POWER_DOWN, &val);
  298. /* Turn off TV/VGA, and never turn it on since we don't support it. */
  299. ch7017_write(dvo, CH7017_POWER_MANAGEMENT,
  300. CH7017_DAC0_POWER_DOWN |
  301. CH7017_DAC1_POWER_DOWN |
  302. CH7017_DAC2_POWER_DOWN |
  303. CH7017_DAC3_POWER_DOWN |
  304. CH7017_TV_POWER_DOWN_EN);
  305. if (mode == DRM_MODE_DPMS_ON) {
  306. /* Turn on the LVDS */
  307. ch7017_write(dvo, CH7017_LVDS_POWER_DOWN,
  308. val & ~CH7017_LVDS_POWER_DOWN_EN);
  309. } else {
  310. /* Turn off the LVDS */
  311. ch7017_write(dvo, CH7017_LVDS_POWER_DOWN,
  312. val | CH7017_LVDS_POWER_DOWN_EN);
  313. }
  314. /* XXX: Should actually wait for update power status somehow */
  315. udelay(20000);
  316. }
  317. static void ch7017_dump_regs(struct intel_dvo_device *dvo)
  318. {
  319. uint8_t val;
  320. #define DUMP(reg) \
  321. do { \
  322. ch7017_read(dvo, reg, &val); \
  323. DRM_DEBUG_KMS(#reg ": %02x\n", val); \
  324. } while (0)
  325. DUMP(CH7017_HORIZONTAL_ACTIVE_PIXEL_INPUT);
  326. DUMP(CH7017_HORIZONTAL_ACTIVE_PIXEL_OUTPUT);
  327. DUMP(CH7017_VERTICAL_ACTIVE_LINE_OUTPUT);
  328. DUMP(CH7017_ACTIVE_INPUT_LINE_OUTPUT);
  329. DUMP(CH7017_LVDS_PLL_VCO_CONTROL);
  330. DUMP(CH7017_LVDS_PLL_FEEDBACK_DIV);
  331. DUMP(CH7017_LVDS_CONTROL_2);
  332. DUMP(CH7017_OUTPUTS_ENABLE);
  333. DUMP(CH7017_LVDS_POWER_DOWN);
  334. }
  335. static void ch7017_destroy(struct intel_dvo_device *dvo)
  336. {
  337. struct ch7017_priv *priv = dvo->dev_priv;
  338. if (priv) {
  339. kfree(priv);
  340. dvo->dev_priv = NULL;
  341. }
  342. }
  343. struct intel_dvo_dev_ops ch7017_ops = {
  344. .init = ch7017_init,
  345. .detect = ch7017_detect,
  346. .mode_valid = ch7017_mode_valid,
  347. .mode_set = ch7017_mode_set,
  348. .dpms = ch7017_dpms,
  349. .dump_regs = ch7017_dump_regs,
  350. .destroy = ch7017_destroy,
  351. };