dvo_ivch.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  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. uint16_t save_VR01;
  137. uint16_t save_VR40;
  138. };
  139. static void ivch_dump_regs(struct intel_dvo_device *dvo);
  140. /**
  141. * Reads a register on the ivch.
  142. *
  143. * Each of the 256 registers are 16 bits long.
  144. */
  145. static bool ivch_read(struct intel_dvo_device *dvo, int addr, uint16_t *data)
  146. {
  147. struct ivch_priv *priv = dvo->dev_priv;
  148. struct i2c_adapter *adapter = dvo->i2c_bus;
  149. struct intel_i2c_chan *i2cbus = container_of(adapter, struct intel_i2c_chan, adapter);
  150. u8 out_buf[1];
  151. u8 in_buf[2];
  152. struct i2c_msg msgs[] = {
  153. {
  154. .addr = dvo->slave_addr,
  155. .flags = I2C_M_RD,
  156. .len = 0,
  157. },
  158. {
  159. .addr = 0,
  160. .flags = I2C_M_NOSTART,
  161. .len = 1,
  162. .buf = out_buf,
  163. },
  164. {
  165. .addr = dvo->slave_addr,
  166. .flags = I2C_M_RD | I2C_M_NOSTART,
  167. .len = 2,
  168. .buf = in_buf,
  169. }
  170. };
  171. out_buf[0] = addr;
  172. if (i2c_transfer(&i2cbus->adapter, msgs, 3) == 3) {
  173. *data = (in_buf[1] << 8) | in_buf[0];
  174. return true;
  175. };
  176. if (!priv->quiet) {
  177. DRM_DEBUG_KMS("Unable to read register 0x%02x from "
  178. "%s:%02x.\n",
  179. addr, i2cbus->adapter.name, dvo->slave_addr);
  180. }
  181. return false;
  182. }
  183. /** Writes a 16-bit register on the ivch */
  184. static bool ivch_write(struct intel_dvo_device *dvo, int addr, uint16_t data)
  185. {
  186. struct ivch_priv *priv = dvo->dev_priv;
  187. struct i2c_adapter *adapter = dvo->i2c_bus;
  188. struct intel_i2c_chan *i2cbus = container_of(adapter, struct intel_i2c_chan, adapter);
  189. u8 out_buf[3];
  190. struct i2c_msg msg = {
  191. .addr = dvo->slave_addr,
  192. .flags = 0,
  193. .len = 3,
  194. .buf = out_buf,
  195. };
  196. out_buf[0] = addr;
  197. out_buf[1] = data & 0xff;
  198. out_buf[2] = data >> 8;
  199. if (i2c_transfer(&i2cbus->adapter, &msg, 1) == 1)
  200. return true;
  201. if (!priv->quiet) {
  202. DRM_DEBUG_KMS("Unable to write register 0x%02x to %s:%d.\n",
  203. addr, i2cbus->adapter.name, dvo->slave_addr);
  204. }
  205. return false;
  206. }
  207. /** Probes the given bus and slave address for an ivch */
  208. static bool ivch_init(struct intel_dvo_device *dvo,
  209. struct i2c_adapter *adapter)
  210. {
  211. struct ivch_priv *priv;
  212. uint16_t temp;
  213. priv = kzalloc(sizeof(struct ivch_priv), GFP_KERNEL);
  214. if (priv == NULL)
  215. return false;
  216. dvo->i2c_bus = adapter;
  217. dvo->dev_priv = priv;
  218. priv->quiet = true;
  219. if (!ivch_read(dvo, VR00, &temp))
  220. goto out;
  221. priv->quiet = false;
  222. /* Since the identification bits are probably zeroes, which doesn't seem
  223. * very unique, check that the value in the base address field matches
  224. * the address it's responding on.
  225. */
  226. if ((temp & VR00_BASE_ADDRESS_MASK) != dvo->slave_addr) {
  227. DRM_DEBUG_KMS("ivch detect failed due to address mismatch "
  228. "(%d vs %d)\n",
  229. (temp & VR00_BASE_ADDRESS_MASK), dvo->slave_addr);
  230. goto out;
  231. }
  232. ivch_read(dvo, VR20, &priv->width);
  233. ivch_read(dvo, VR21, &priv->height);
  234. return true;
  235. out:
  236. kfree(priv);
  237. return false;
  238. }
  239. static enum drm_connector_status ivch_detect(struct intel_dvo_device *dvo)
  240. {
  241. return connector_status_connected;
  242. }
  243. static enum drm_mode_status ivch_mode_valid(struct intel_dvo_device *dvo,
  244. struct drm_display_mode *mode)
  245. {
  246. if (mode->clock > 112000)
  247. return MODE_CLOCK_HIGH;
  248. return MODE_OK;
  249. }
  250. /** Sets the power state of the panel connected to the ivch */
  251. static void ivch_dpms(struct intel_dvo_device *dvo, int mode)
  252. {
  253. int i;
  254. uint16_t vr01, vr30, backlight;
  255. /* Set the new power state of the panel. */
  256. if (!ivch_read(dvo, VR01, &vr01))
  257. return;
  258. if (mode == DRM_MODE_DPMS_ON)
  259. backlight = 1;
  260. else
  261. backlight = 0;
  262. ivch_write(dvo, VR80, backlight);
  263. if (mode == DRM_MODE_DPMS_ON)
  264. vr01 |= VR01_LCD_ENABLE | VR01_DVO_ENABLE;
  265. else
  266. vr01 &= ~(VR01_LCD_ENABLE | VR01_DVO_ENABLE);
  267. ivch_write(dvo, VR01, vr01);
  268. /* Wait for the panel to make its state transition */
  269. for (i = 0; i < 100; i++) {
  270. if (!ivch_read(dvo, VR30, &vr30))
  271. break;
  272. if (((vr30 & VR30_PANEL_ON) != 0) == (mode == DRM_MODE_DPMS_ON))
  273. break;
  274. udelay(1000);
  275. }
  276. /* wait some more; vch may fail to resync sometimes without this */
  277. udelay(16 * 1000);
  278. }
  279. static void ivch_mode_set(struct intel_dvo_device *dvo,
  280. struct drm_display_mode *mode,
  281. struct drm_display_mode *adjusted_mode)
  282. {
  283. uint16_t vr40 = 0;
  284. uint16_t vr01;
  285. vr01 = 0;
  286. vr40 = (VR40_STALL_ENABLE | VR40_VERTICAL_INTERP_ENABLE |
  287. VR40_HORIZONTAL_INTERP_ENABLE);
  288. if (mode->hdisplay != adjusted_mode->hdisplay ||
  289. mode->vdisplay != adjusted_mode->vdisplay) {
  290. uint16_t x_ratio, y_ratio;
  291. vr01 |= VR01_PANEL_FIT_ENABLE;
  292. vr40 |= VR40_CLOCK_GATING_ENABLE;
  293. x_ratio = (((mode->hdisplay - 1) << 16) /
  294. (adjusted_mode->hdisplay - 1)) >> 2;
  295. y_ratio = (((mode->vdisplay - 1) << 16) /
  296. (adjusted_mode->vdisplay - 1)) >> 2;
  297. ivch_write (dvo, VR42, x_ratio);
  298. ivch_write (dvo, VR41, y_ratio);
  299. } else {
  300. vr01 &= ~VR01_PANEL_FIT_ENABLE;
  301. vr40 &= ~VR40_CLOCK_GATING_ENABLE;
  302. }
  303. vr40 &= ~VR40_AUTO_RATIO_ENABLE;
  304. ivch_write(dvo, VR01, vr01);
  305. ivch_write(dvo, VR40, vr40);
  306. ivch_dump_regs(dvo);
  307. }
  308. static void ivch_dump_regs(struct intel_dvo_device *dvo)
  309. {
  310. uint16_t val;
  311. ivch_read(dvo, VR00, &val);
  312. DRM_LOG_KMS("VR00: 0x%04x\n", val);
  313. ivch_read(dvo, VR01, &val);
  314. DRM_LOG_KMS("VR01: 0x%04x\n", val);
  315. ivch_read(dvo, VR30, &val);
  316. DRM_LOG_KMS("VR30: 0x%04x\n", val);
  317. ivch_read(dvo, VR40, &val);
  318. DRM_LOG_KMS("VR40: 0x%04x\n", val);
  319. /* GPIO registers */
  320. ivch_read(dvo, VR80, &val);
  321. DRM_LOG_KMS("VR80: 0x%04x\n", val);
  322. ivch_read(dvo, VR81, &val);
  323. DRM_LOG_KMS("VR81: 0x%04x\n", val);
  324. ivch_read(dvo, VR82, &val);
  325. DRM_LOG_KMS("VR82: 0x%04x\n", val);
  326. ivch_read(dvo, VR83, &val);
  327. DRM_LOG_KMS("VR83: 0x%04x\n", val);
  328. ivch_read(dvo, VR84, &val);
  329. DRM_LOG_KMS("VR84: 0x%04x\n", val);
  330. ivch_read(dvo, VR85, &val);
  331. DRM_LOG_KMS("VR85: 0x%04x\n", val);
  332. ivch_read(dvo, VR86, &val);
  333. DRM_LOG_KMS("VR86: 0x%04x\n", val);
  334. ivch_read(dvo, VR87, &val);
  335. DRM_LOG_KMS("VR87: 0x%04x\n", val);
  336. ivch_read(dvo, VR88, &val);
  337. DRM_LOG_KMS("VR88: 0x%04x\n", val);
  338. /* Scratch register 0 - AIM Panel type */
  339. ivch_read(dvo, VR8E, &val);
  340. DRM_LOG_KMS("VR8E: 0x%04x\n", val);
  341. /* Scratch register 1 - Status register */
  342. ivch_read(dvo, VR8F, &val);
  343. DRM_LOG_KMS("VR8F: 0x%04x\n", val);
  344. }
  345. static void ivch_save(struct intel_dvo_device *dvo)
  346. {
  347. struct ivch_priv *priv = dvo->dev_priv;
  348. ivch_read(dvo, VR01, &priv->save_VR01);
  349. ivch_read(dvo, VR40, &priv->save_VR40);
  350. }
  351. static void ivch_restore(struct intel_dvo_device *dvo)
  352. {
  353. struct ivch_priv *priv = dvo->dev_priv;
  354. ivch_write(dvo, VR01, priv->save_VR01);
  355. ivch_write(dvo, VR40, priv->save_VR40);
  356. }
  357. static void ivch_destroy(struct intel_dvo_device *dvo)
  358. {
  359. struct ivch_priv *priv = dvo->dev_priv;
  360. if (priv) {
  361. kfree(priv);
  362. dvo->dev_priv = NULL;
  363. }
  364. }
  365. struct intel_dvo_dev_ops ivch_ops= {
  366. .init = ivch_init,
  367. .dpms = ivch_dpms,
  368. .save = ivch_save,
  369. .restore = ivch_restore,
  370. .mode_valid = ivch_mode_valid,
  371. .mode_set = ivch_mode_set,
  372. .detect = ivch_detect,
  373. .dump_regs = ivch_dump_regs,
  374. .destroy = ivch_destroy,
  375. };