dvo_ivch.c 10 KB

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