dvo_sil164.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /**************************************************************************
  2. Copyright © 2006 Dave Airlie
  3. All Rights Reserved.
  4. Permission is hereby granted, free of charge, to any person obtaining a
  5. copy of this software and associated documentation files (the
  6. "Software"), to deal in the Software without restriction, including
  7. without limitation the rights to use, copy, modify, merge, publish,
  8. distribute, sub license, and/or sell copies of the Software, and to
  9. permit persons to whom the Software is furnished to do so, subject to
  10. the following conditions:
  11. The above copyright notice and this permission notice (including the
  12. next paragraph) shall be included in all copies or substantial portions
  13. of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  15. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  17. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  18. ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  19. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  20. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. **************************************************************************/
  22. #include "dvo.h"
  23. #define SIL164_VID 0x0001
  24. #define SIL164_DID 0x0006
  25. #define SIL164_VID_LO 0x00
  26. #define SIL164_VID_HI 0x01
  27. #define SIL164_DID_LO 0x02
  28. #define SIL164_DID_HI 0x03
  29. #define SIL164_REV 0x04
  30. #define SIL164_RSVD 0x05
  31. #define SIL164_FREQ_LO 0x06
  32. #define SIL164_FREQ_HI 0x07
  33. #define SIL164_REG8 0x08
  34. #define SIL164_8_VEN (1<<5)
  35. #define SIL164_8_HEN (1<<4)
  36. #define SIL164_8_DSEL (1<<3)
  37. #define SIL164_8_BSEL (1<<2)
  38. #define SIL164_8_EDGE (1<<1)
  39. #define SIL164_8_PD (1<<0)
  40. #define SIL164_REG9 0x09
  41. #define SIL164_9_VLOW (1<<7)
  42. #define SIL164_9_MSEL_MASK (0x7<<4)
  43. #define SIL164_9_TSEL (1<<3)
  44. #define SIL164_9_RSEN (1<<2)
  45. #define SIL164_9_HTPLG (1<<1)
  46. #define SIL164_9_MDI (1<<0)
  47. #define SIL164_REGC 0x0c
  48. struct sil164_priv {
  49. //I2CDevRec d;
  50. bool quiet;
  51. };
  52. #define SILPTR(d) ((SIL164Ptr)(d->DriverPrivate.ptr))
  53. static bool sil164_readb(struct intel_dvo_device *dvo, int addr, uint8_t *ch)
  54. {
  55. struct sil164_priv *sil = dvo->dev_priv;
  56. struct i2c_adapter *adapter = dvo->i2c_bus;
  57. u8 out_buf[2];
  58. u8 in_buf[2];
  59. struct i2c_msg msgs[] = {
  60. {
  61. .addr = dvo->slave_addr,
  62. .flags = 0,
  63. .len = 1,
  64. .buf = out_buf,
  65. },
  66. {
  67. .addr = dvo->slave_addr,
  68. .flags = I2C_M_RD,
  69. .len = 1,
  70. .buf = in_buf,
  71. }
  72. };
  73. out_buf[0] = addr;
  74. out_buf[1] = 0;
  75. if (i2c_transfer(adapter, msgs, 2) == 2) {
  76. *ch = in_buf[0];
  77. return true;
  78. }
  79. if (!sil->quiet) {
  80. DRM_DEBUG_KMS("Unable to read register 0x%02x from %s:%02x.\n",
  81. addr, adapter->name, dvo->slave_addr);
  82. }
  83. return false;
  84. }
  85. static bool sil164_writeb(struct intel_dvo_device *dvo, int addr, uint8_t ch)
  86. {
  87. struct sil164_priv *sil = dvo->dev_priv;
  88. struct i2c_adapter *adapter = dvo->i2c_bus;
  89. uint8_t out_buf[2];
  90. struct i2c_msg msg = {
  91. .addr = dvo->slave_addr,
  92. .flags = 0,
  93. .len = 2,
  94. .buf = out_buf,
  95. };
  96. out_buf[0] = addr;
  97. out_buf[1] = ch;
  98. if (i2c_transfer(adapter, &msg, 1) == 1)
  99. return true;
  100. if (!sil->quiet) {
  101. DRM_DEBUG_KMS("Unable to write register 0x%02x to %s:%d.\n",
  102. addr, adapter->name, dvo->slave_addr);
  103. }
  104. return false;
  105. }
  106. /* Silicon Image 164 driver for chip on i2c bus */
  107. static bool sil164_init(struct intel_dvo_device *dvo,
  108. struct i2c_adapter *adapter)
  109. {
  110. /* this will detect the SIL164 chip on the specified i2c bus */
  111. struct sil164_priv *sil;
  112. unsigned char ch;
  113. sil = kzalloc(sizeof(struct sil164_priv), GFP_KERNEL);
  114. if (sil == NULL)
  115. return false;
  116. dvo->i2c_bus = adapter;
  117. dvo->dev_priv = sil;
  118. sil->quiet = true;
  119. if (!sil164_readb(dvo, SIL164_VID_LO, &ch))
  120. goto out;
  121. if (ch != (SIL164_VID & 0xff)) {
  122. DRM_DEBUG_KMS("sil164 not detected got %d: from %s Slave %d.\n",
  123. ch, adapter->name, dvo->slave_addr);
  124. goto out;
  125. }
  126. if (!sil164_readb(dvo, SIL164_DID_LO, &ch))
  127. goto out;
  128. if (ch != (SIL164_DID & 0xff)) {
  129. DRM_DEBUG_KMS("sil164 not detected got %d: from %s Slave %d.\n",
  130. ch, adapter->name, dvo->slave_addr);
  131. goto out;
  132. }
  133. sil->quiet = false;
  134. DRM_DEBUG_KMS("init sil164 dvo controller successfully!\n");
  135. return true;
  136. out:
  137. kfree(sil);
  138. return false;
  139. }
  140. static enum drm_connector_status sil164_detect(struct intel_dvo_device *dvo)
  141. {
  142. uint8_t reg9;
  143. sil164_readb(dvo, SIL164_REG9, &reg9);
  144. if (reg9 & SIL164_9_HTPLG)
  145. return connector_status_connected;
  146. else
  147. return connector_status_disconnected;
  148. }
  149. static enum drm_mode_status sil164_mode_valid(struct intel_dvo_device *dvo,
  150. struct drm_display_mode *mode)
  151. {
  152. return MODE_OK;
  153. }
  154. static void sil164_mode_set(struct intel_dvo_device *dvo,
  155. const struct drm_display_mode *mode,
  156. const struct drm_display_mode *adjusted_mode)
  157. {
  158. /* As long as the basics are set up, since we don't have clock
  159. * dependencies in the mode setup, we can just leave the
  160. * registers alone and everything will work fine.
  161. */
  162. /* recommended programming sequence from doc */
  163. /*sil164_writeb(sil, 0x08, 0x30);
  164. sil164_writeb(sil, 0x09, 0x00);
  165. sil164_writeb(sil, 0x0a, 0x90);
  166. sil164_writeb(sil, 0x0c, 0x89);
  167. sil164_writeb(sil, 0x08, 0x31);*/
  168. /* don't do much */
  169. return;
  170. }
  171. /* set the SIL164 power state */
  172. static void sil164_dpms(struct intel_dvo_device *dvo, bool enable)
  173. {
  174. int ret;
  175. unsigned char ch;
  176. ret = sil164_readb(dvo, SIL164_REG8, &ch);
  177. if (ret == false)
  178. return;
  179. if (enable)
  180. ch |= SIL164_8_PD;
  181. else
  182. ch &= ~SIL164_8_PD;
  183. sil164_writeb(dvo, SIL164_REG8, ch);
  184. return;
  185. }
  186. static bool sil164_get_hw_state(struct intel_dvo_device *dvo)
  187. {
  188. int ret;
  189. unsigned char ch;
  190. ret = sil164_readb(dvo, SIL164_REG8, &ch);
  191. if (ret == false)
  192. return false;
  193. if (ch & SIL164_8_PD)
  194. return true;
  195. else
  196. return false;
  197. }
  198. static void sil164_dump_regs(struct intel_dvo_device *dvo)
  199. {
  200. uint8_t val;
  201. sil164_readb(dvo, SIL164_FREQ_LO, &val);
  202. DRM_DEBUG_KMS("SIL164_FREQ_LO: 0x%02x\n", val);
  203. sil164_readb(dvo, SIL164_FREQ_HI, &val);
  204. DRM_DEBUG_KMS("SIL164_FREQ_HI: 0x%02x\n", val);
  205. sil164_readb(dvo, SIL164_REG8, &val);
  206. DRM_DEBUG_KMS("SIL164_REG8: 0x%02x\n", val);
  207. sil164_readb(dvo, SIL164_REG9, &val);
  208. DRM_DEBUG_KMS("SIL164_REG9: 0x%02x\n", val);
  209. sil164_readb(dvo, SIL164_REGC, &val);
  210. DRM_DEBUG_KMS("SIL164_REGC: 0x%02x\n", val);
  211. }
  212. static void sil164_destroy(struct intel_dvo_device *dvo)
  213. {
  214. struct sil164_priv *sil = dvo->dev_priv;
  215. if (sil) {
  216. kfree(sil);
  217. dvo->dev_priv = NULL;
  218. }
  219. }
  220. struct intel_dvo_dev_ops sil164_ops = {
  221. .init = sil164_init,
  222. .detect = sil164_detect,
  223. .mode_valid = sil164_mode_valid,
  224. .mode_set = sil164_mode_set,
  225. .dpms = sil164_dpms,
  226. .get_hw_state = sil164_get_hw_state,
  227. .dump_regs = sil164_dump_regs,
  228. .destroy = sil164_destroy,
  229. };