dvo_ivch.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  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. /*
  29. * register definitions for the i82807aa.
  30. *
  31. * Documentation on this chipset can be found in datasheet #29069001 at
  32. * intel.com.
  33. */
  34. /*
  35. * VCH Revision & GMBus Base Addr
  36. */
  37. #define VR00 0x00
  38. # define VR00_BASE_ADDRESS_MASK 0x007f
  39. /*
  40. * Functionality Enable
  41. */
  42. #define VR01 0x01
  43. /*
  44. * Enable the panel fitter
  45. */
  46. # define VR01_PANEL_FIT_ENABLE (1 << 3)
  47. /*
  48. * Enables the LCD display.
  49. *
  50. * This must not be set while VR01_DVO_BYPASS_ENABLE is set.
  51. */
  52. # define VR01_LCD_ENABLE (1 << 2)
  53. /** Enables the DVO repeater. */
  54. # define VR01_DVO_BYPASS_ENABLE (1 << 1)
  55. /** Enables the DVO clock */
  56. # define VR01_DVO_ENABLE (1 << 0)
  57. /*
  58. * LCD Interface Format
  59. */
  60. #define VR10 0x10
  61. /** Enables LVDS output instead of CMOS */
  62. # define VR10_LVDS_ENABLE (1 << 4)
  63. /** Enables 18-bit LVDS output. */
  64. # define VR10_INTERFACE_1X18 (0 << 2)
  65. /** Enables 24-bit LVDS or CMOS output */
  66. # define VR10_INTERFACE_1X24 (1 << 2)
  67. /** Enables 2x18-bit LVDS or CMOS output. */
  68. # define VR10_INTERFACE_2X18 (2 << 2)
  69. /** Enables 2x24-bit LVDS output */
  70. # define VR10_INTERFACE_2X24 (3 << 2)
  71. /*
  72. * VR20 LCD Horizontal Display Size
  73. */
  74. #define VR20 0x20
  75. /*
  76. * LCD Vertical Display Size
  77. */
  78. #define VR21 0x20
  79. /*
  80. * Panel power down status
  81. */
  82. #define VR30 0x30
  83. /** Read only bit indicating that the panel is not in a safe poweroff state. */
  84. # define VR30_PANEL_ON (1 << 15)
  85. #define VR40 0x40
  86. # define VR40_STALL_ENABLE (1 << 13)
  87. # define VR40_VERTICAL_INTERP_ENABLE (1 << 12)
  88. # define VR40_ENHANCED_PANEL_FITTING (1 << 11)
  89. # define VR40_HORIZONTAL_INTERP_ENABLE (1 << 10)
  90. # define VR40_AUTO_RATIO_ENABLE (1 << 9)
  91. # define VR40_CLOCK_GATING_ENABLE (1 << 8)
  92. /*
  93. * Panel Fitting Vertical Ratio
  94. * (((image_height - 1) << 16) / ((panel_height - 1))) >> 2
  95. */
  96. #define VR41 0x41
  97. /*
  98. * Panel Fitting Horizontal Ratio
  99. * (((image_width - 1) << 16) / ((panel_width - 1))) >> 2
  100. */
  101. #define VR42 0x42
  102. /*
  103. * Horizontal Image Size
  104. */
  105. #define VR43 0x43
  106. /* VR80 GPIO 0
  107. */
  108. #define VR80 0x80
  109. #define VR81 0x81
  110. #define VR82 0x82
  111. #define VR83 0x83
  112. #define VR84 0x84
  113. #define VR85 0x85
  114. #define VR86 0x86
  115. #define VR87 0x87
  116. /* VR88 GPIO 8
  117. */
  118. #define VR88 0x88
  119. /* Graphics BIOS scratch 0
  120. */
  121. #define VR8E 0x8E
  122. # define VR8E_PANEL_TYPE_MASK (0xf << 0)
  123. # define VR8E_PANEL_INTERFACE_CMOS (0 << 4)
  124. # define VR8E_PANEL_INTERFACE_LVDS (1 << 4)
  125. # define VR8E_FORCE_DEFAULT_PANEL (1 << 5)
  126. /* Graphics BIOS scratch 1
  127. */
  128. #define VR8F 0x8F
  129. # define VR8F_VCH_PRESENT (1 << 0)
  130. # define VR8F_DISPLAY_CONN (1 << 1)
  131. # define VR8F_POWER_MASK (0x3c)
  132. # define VR8F_POWER_POS (2)
  133. struct ivch_priv {
  134. bool quiet;
  135. uint16_t width, height;
  136. };
  137. static void ivch_dump_regs(struct intel_dvo_device *dvo);
  138. /**
  139. * Reads a register on the ivch.
  140. *
  141. * Each of the 256 registers are 16 bits long.
  142. */
  143. static bool ivch_read(struct intel_dvo_device *dvo, int addr, uint16_t *data)
  144. {
  145. struct ivch_priv *priv = dvo->dev_priv;
  146. struct i2c_adapter *adapter = dvo->i2c_bus;
  147. u8 out_buf[1];
  148. u8 in_buf[2];
  149. struct i2c_msg msgs[] = {
  150. {
  151. .addr = dvo->slave_addr,
  152. .flags = I2C_M_RD,
  153. .len = 0,
  154. },
  155. {
  156. .addr = 0,
  157. .flags = I2C_M_NOSTART,
  158. .len = 1,
  159. .buf = out_buf,
  160. },
  161. {
  162. .addr = dvo->slave_addr,
  163. .flags = I2C_M_RD | I2C_M_NOSTART,
  164. .len = 2,
  165. .buf = in_buf,
  166. }
  167. };
  168. out_buf[0] = addr;
  169. if (i2c_transfer(adapter, msgs, 3) == 3) {
  170. *data = (in_buf[1] << 8) | in_buf[0];
  171. return true;
  172. };
  173. if (!priv->quiet) {
  174. DRM_DEBUG_KMS("Unable to read register 0x%02x from "
  175. "%s:%02x.\n",
  176. addr, adapter->name, dvo->slave_addr);
  177. }
  178. return false;
  179. }
  180. /** Writes a 16-bit register on the ivch */
  181. static bool ivch_write(struct intel_dvo_device *dvo, int addr, uint16_t data)
  182. {
  183. struct ivch_priv *priv = dvo->dev_priv;
  184. struct i2c_adapter *adapter = dvo->i2c_bus;
  185. u8 out_buf[3];
  186. struct i2c_msg msg = {
  187. .addr = dvo->slave_addr,
  188. .flags = 0,
  189. .len = 3,
  190. .buf = out_buf,
  191. };
  192. out_buf[0] = addr;
  193. out_buf[1] = data & 0xff;
  194. out_buf[2] = data >> 8;
  195. if (i2c_transfer(adapter, &msg, 1) == 1)
  196. return true;
  197. if (!priv->quiet) {
  198. DRM_DEBUG_KMS("Unable to write register 0x%02x to %s:%d.\n",
  199. addr, adapter->name, dvo->slave_addr);
  200. }
  201. return false;
  202. }
  203. /** Probes the given bus and slave address for an ivch */
  204. static bool ivch_init(struct intel_dvo_device *dvo,
  205. struct i2c_adapter *adapter)
  206. {
  207. struct ivch_priv *priv;
  208. uint16_t temp;
  209. priv = kzalloc(sizeof(struct ivch_priv), GFP_KERNEL);
  210. if (priv == NULL)
  211. return false;
  212. dvo->i2c_bus = adapter;
  213. dvo->dev_priv = priv;
  214. priv->quiet = true;
  215. if (!ivch_read(dvo, VR00, &temp))
  216. goto out;
  217. priv->quiet = false;
  218. /* Since the identification bits are probably zeroes, which doesn't seem
  219. * very unique, check that the value in the base address field matches
  220. * the address it's responding on.
  221. */
  222. if ((temp & VR00_BASE_ADDRESS_MASK) != dvo->slave_addr) {
  223. DRM_DEBUG_KMS("ivch detect failed due to address mismatch "
  224. "(%d vs %d)\n",
  225. (temp & VR00_BASE_ADDRESS_MASK), dvo->slave_addr);
  226. goto out;
  227. }
  228. ivch_read(dvo, VR20, &priv->width);
  229. ivch_read(dvo, VR21, &priv->height);
  230. return true;
  231. out:
  232. kfree(priv);
  233. return false;
  234. }
  235. static enum drm_connector_status ivch_detect(struct intel_dvo_device *dvo)
  236. {
  237. return connector_status_connected;
  238. }
  239. static enum drm_mode_status ivch_mode_valid(struct intel_dvo_device *dvo,
  240. struct drm_display_mode *mode)
  241. {
  242. if (mode->clock > 112000)
  243. return MODE_CLOCK_HIGH;
  244. return MODE_OK;
  245. }
  246. /** Sets the power state of the panel connected to the ivch */
  247. static void ivch_dpms(struct intel_dvo_device *dvo, int mode)
  248. {
  249. int i;
  250. uint16_t vr01, vr30, backlight;
  251. /* Set the new power state of the panel. */
  252. if (!ivch_read(dvo, VR01, &vr01))
  253. return;
  254. if (mode == DRM_MODE_DPMS_ON)
  255. backlight = 1;
  256. else
  257. backlight = 0;
  258. ivch_write(dvo, VR80, backlight);
  259. if (mode == DRM_MODE_DPMS_ON)
  260. vr01 |= VR01_LCD_ENABLE | VR01_DVO_ENABLE;
  261. else
  262. vr01 &= ~(VR01_LCD_ENABLE | VR01_DVO_ENABLE);
  263. ivch_write(dvo, VR01, vr01);
  264. /* Wait for the panel to make its state transition */
  265. for (i = 0; i < 100; i++) {
  266. if (!ivch_read(dvo, VR30, &vr30))
  267. break;
  268. if (((vr30 & VR30_PANEL_ON) != 0) == (mode == DRM_MODE_DPMS_ON))
  269. break;
  270. udelay(1000);
  271. }
  272. /* wait some more; vch may fail to resync sometimes without this */
  273. udelay(16 * 1000);
  274. }
  275. static void ivch_mode_set(struct intel_dvo_device *dvo,
  276. struct drm_display_mode *mode,
  277. struct drm_display_mode *adjusted_mode)
  278. {
  279. uint16_t vr40 = 0;
  280. uint16_t vr01;
  281. vr01 = 0;
  282. vr40 = (VR40_STALL_ENABLE | VR40_VERTICAL_INTERP_ENABLE |
  283. VR40_HORIZONTAL_INTERP_ENABLE);
  284. if (mode->hdisplay != adjusted_mode->hdisplay ||
  285. mode->vdisplay != adjusted_mode->vdisplay) {
  286. uint16_t x_ratio, y_ratio;
  287. vr01 |= VR01_PANEL_FIT_ENABLE;
  288. vr40 |= VR40_CLOCK_GATING_ENABLE;
  289. x_ratio = (((mode->hdisplay - 1) << 16) /
  290. (adjusted_mode->hdisplay - 1)) >> 2;
  291. y_ratio = (((mode->vdisplay - 1) << 16) /
  292. (adjusted_mode->vdisplay - 1)) >> 2;
  293. ivch_write(dvo, VR42, x_ratio);
  294. ivch_write(dvo, VR41, y_ratio);
  295. } else {
  296. vr01 &= ~VR01_PANEL_FIT_ENABLE;
  297. vr40 &= ~VR40_CLOCK_GATING_ENABLE;
  298. }
  299. vr40 &= ~VR40_AUTO_RATIO_ENABLE;
  300. ivch_write(dvo, VR01, vr01);
  301. ivch_write(dvo, VR40, vr40);
  302. ivch_dump_regs(dvo);
  303. }
  304. static void ivch_dump_regs(struct intel_dvo_device *dvo)
  305. {
  306. uint16_t val;
  307. ivch_read(dvo, VR00, &val);
  308. DRM_LOG_KMS("VR00: 0x%04x\n", val);
  309. ivch_read(dvo, VR01, &val);
  310. DRM_LOG_KMS("VR01: 0x%04x\n", val);
  311. ivch_read(dvo, VR30, &val);
  312. DRM_LOG_KMS("VR30: 0x%04x\n", val);
  313. ivch_read(dvo, VR40, &val);
  314. DRM_LOG_KMS("VR40: 0x%04x\n", val);
  315. /* GPIO registers */
  316. ivch_read(dvo, VR80, &val);
  317. DRM_LOG_KMS("VR80: 0x%04x\n", val);
  318. ivch_read(dvo, VR81, &val);
  319. DRM_LOG_KMS("VR81: 0x%04x\n", val);
  320. ivch_read(dvo, VR82, &val);
  321. DRM_LOG_KMS("VR82: 0x%04x\n", val);
  322. ivch_read(dvo, VR83, &val);
  323. DRM_LOG_KMS("VR83: 0x%04x\n", val);
  324. ivch_read(dvo, VR84, &val);
  325. DRM_LOG_KMS("VR84: 0x%04x\n", val);
  326. ivch_read(dvo, VR85, &val);
  327. DRM_LOG_KMS("VR85: 0x%04x\n", val);
  328. ivch_read(dvo, VR86, &val);
  329. DRM_LOG_KMS("VR86: 0x%04x\n", val);
  330. ivch_read(dvo, VR87, &val);
  331. DRM_LOG_KMS("VR87: 0x%04x\n", val);
  332. ivch_read(dvo, VR88, &val);
  333. DRM_LOG_KMS("VR88: 0x%04x\n", val);
  334. /* Scratch register 0 - AIM Panel type */
  335. ivch_read(dvo, VR8E, &val);
  336. DRM_LOG_KMS("VR8E: 0x%04x\n", val);
  337. /* Scratch register 1 - Status register */
  338. ivch_read(dvo, VR8F, &val);
  339. DRM_LOG_KMS("VR8F: 0x%04x\n", val);
  340. }
  341. static void ivch_destroy(struct intel_dvo_device *dvo)
  342. {
  343. struct ivch_priv *priv = dvo->dev_priv;
  344. if (priv) {
  345. kfree(priv);
  346. dvo->dev_priv = NULL;
  347. }
  348. }
  349. struct intel_dvo_dev_ops ivch_ops = {
  350. .init = ivch_init,
  351. .dpms = ivch_dpms,
  352. .mode_valid = ivch_mode_valid,
  353. .mode_set = ivch_mode_set,
  354. .detect = ivch_detect,
  355. .dump_regs = ivch_dump_regs,
  356. .destroy = ivch_destroy,
  357. };