dvo_tfp410.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. /*
  2. * Copyright © 2007 Dave Mueller
  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 DEALINGS
  21. * IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Dave Mueller <dave.mueller@gmx.ch>
  25. *
  26. */
  27. #include "dvo.h"
  28. /* register definitions according to the TFP410 data sheet */
  29. #define TFP410_VID 0x014C
  30. #define TFP410_DID 0x0410
  31. #define TFP410_VID_LO 0x00
  32. #define TFP410_VID_HI 0x01
  33. #define TFP410_DID_LO 0x02
  34. #define TFP410_DID_HI 0x03
  35. #define TFP410_REV 0x04
  36. #define TFP410_CTL_1 0x08
  37. #define TFP410_CTL_1_TDIS (1<<6)
  38. #define TFP410_CTL_1_VEN (1<<5)
  39. #define TFP410_CTL_1_HEN (1<<4)
  40. #define TFP410_CTL_1_DSEL (1<<3)
  41. #define TFP410_CTL_1_BSEL (1<<2)
  42. #define TFP410_CTL_1_EDGE (1<<1)
  43. #define TFP410_CTL_1_PD (1<<0)
  44. #define TFP410_CTL_2 0x09
  45. #define TFP410_CTL_2_VLOW (1<<7)
  46. #define TFP410_CTL_2_MSEL_MASK (0x7<<4)
  47. #define TFP410_CTL_2_MSEL (1<<4)
  48. #define TFP410_CTL_2_TSEL (1<<3)
  49. #define TFP410_CTL_2_RSEN (1<<2)
  50. #define TFP410_CTL_2_HTPLG (1<<1)
  51. #define TFP410_CTL_2_MDI (1<<0)
  52. #define TFP410_CTL_3 0x0A
  53. #define TFP410_CTL_3_DK_MASK (0x7<<5)
  54. #define TFP410_CTL_3_DK (1<<5)
  55. #define TFP410_CTL_3_DKEN (1<<4)
  56. #define TFP410_CTL_3_CTL_MASK (0x7<<1)
  57. #define TFP410_CTL_3_CTL (1<<1)
  58. #define TFP410_USERCFG 0x0B
  59. #define TFP410_DE_DLY 0x32
  60. #define TFP410_DE_CTL 0x33
  61. #define TFP410_DE_CTL_DEGEN (1<<6)
  62. #define TFP410_DE_CTL_VSPOL (1<<5)
  63. #define TFP410_DE_CTL_HSPOL (1<<4)
  64. #define TFP410_DE_CTL_DEDLY8 (1<<0)
  65. #define TFP410_DE_TOP 0x34
  66. #define TFP410_DE_CNT_LO 0x36
  67. #define TFP410_DE_CNT_HI 0x37
  68. #define TFP410_DE_LIN_LO 0x38
  69. #define TFP410_DE_LIN_HI 0x39
  70. #define TFP410_H_RES_LO 0x3A
  71. #define TFP410_H_RES_HI 0x3B
  72. #define TFP410_V_RES_LO 0x3C
  73. #define TFP410_V_RES_HI 0x3D
  74. struct tfp410_priv {
  75. bool quiet;
  76. };
  77. static bool tfp410_readb(struct intel_dvo_device *dvo, int addr, uint8_t *ch)
  78. {
  79. struct tfp410_priv *tfp = dvo->dev_priv;
  80. struct i2c_adapter *adapter = dvo->i2c_bus;
  81. u8 out_buf[2];
  82. u8 in_buf[2];
  83. struct i2c_msg msgs[] = {
  84. {
  85. .addr = dvo->slave_addr,
  86. .flags = 0,
  87. .len = 1,
  88. .buf = out_buf,
  89. },
  90. {
  91. .addr = dvo->slave_addr,
  92. .flags = I2C_M_RD,
  93. .len = 1,
  94. .buf = in_buf,
  95. }
  96. };
  97. out_buf[0] = addr;
  98. out_buf[1] = 0;
  99. if (i2c_transfer(adapter, msgs, 2) == 2) {
  100. *ch = in_buf[0];
  101. return true;
  102. }
  103. if (!tfp->quiet) {
  104. DRM_DEBUG_KMS("Unable to read register 0x%02x from %s:%02x.\n",
  105. addr, adapter->name, dvo->slave_addr);
  106. }
  107. return false;
  108. }
  109. static bool tfp410_writeb(struct intel_dvo_device *dvo, int addr, uint8_t ch)
  110. {
  111. struct tfp410_priv *tfp = dvo->dev_priv;
  112. struct i2c_adapter *adapter = dvo->i2c_bus;
  113. uint8_t out_buf[2];
  114. struct i2c_msg msg = {
  115. .addr = dvo->slave_addr,
  116. .flags = 0,
  117. .len = 2,
  118. .buf = out_buf,
  119. };
  120. out_buf[0] = addr;
  121. out_buf[1] = ch;
  122. if (i2c_transfer(adapter, &msg, 1) == 1)
  123. return true;
  124. if (!tfp->quiet) {
  125. DRM_DEBUG_KMS("Unable to write register 0x%02x to %s:%d.\n",
  126. addr, adapter->name, dvo->slave_addr);
  127. }
  128. return false;
  129. }
  130. static int tfp410_getid(struct intel_dvo_device *dvo, int addr)
  131. {
  132. uint8_t ch1, ch2;
  133. if (tfp410_readb(dvo, addr+0, &ch1) &&
  134. tfp410_readb(dvo, addr+1, &ch2))
  135. return ((ch2 << 8) & 0xFF00) | (ch1 & 0x00FF);
  136. return -1;
  137. }
  138. /* Ti TFP410 driver for chip on i2c bus */
  139. static bool tfp410_init(struct intel_dvo_device *dvo,
  140. struct i2c_adapter *adapter)
  141. {
  142. /* this will detect the tfp410 chip on the specified i2c bus */
  143. struct tfp410_priv *tfp;
  144. int id;
  145. tfp = kzalloc(sizeof(struct tfp410_priv), GFP_KERNEL);
  146. if (tfp == NULL)
  147. return false;
  148. dvo->i2c_bus = adapter;
  149. dvo->dev_priv = tfp;
  150. tfp->quiet = true;
  151. if ((id = tfp410_getid(dvo, TFP410_VID_LO)) != TFP410_VID) {
  152. DRM_DEBUG_KMS("tfp410 not detected got VID %X: from %s "
  153. "Slave %d.\n",
  154. id, adapter->name, dvo->slave_addr);
  155. goto out;
  156. }
  157. if ((id = tfp410_getid(dvo, TFP410_DID_LO)) != TFP410_DID) {
  158. DRM_DEBUG_KMS("tfp410 not detected got DID %X: from %s "
  159. "Slave %d.\n",
  160. id, adapter->name, dvo->slave_addr);
  161. goto out;
  162. }
  163. tfp->quiet = false;
  164. return true;
  165. out:
  166. kfree(tfp);
  167. return false;
  168. }
  169. static enum drm_connector_status tfp410_detect(struct intel_dvo_device *dvo)
  170. {
  171. enum drm_connector_status ret = connector_status_disconnected;
  172. uint8_t ctl2;
  173. if (tfp410_readb(dvo, TFP410_CTL_2, &ctl2)) {
  174. if (ctl2 & TFP410_CTL_2_RSEN)
  175. ret = connector_status_connected;
  176. else
  177. ret = connector_status_disconnected;
  178. }
  179. return ret;
  180. }
  181. static enum drm_mode_status tfp410_mode_valid(struct intel_dvo_device *dvo,
  182. struct drm_display_mode *mode)
  183. {
  184. return MODE_OK;
  185. }
  186. static void tfp410_mode_set(struct intel_dvo_device *dvo,
  187. const struct drm_display_mode *mode,
  188. const struct drm_display_mode *adjusted_mode)
  189. {
  190. /* As long as the basics are set up, since we don't have clock dependencies
  191. * in the mode setup, we can just leave the registers alone and everything
  192. * will work fine.
  193. */
  194. /* don't do much */
  195. return;
  196. }
  197. /* set the tfp410 power state */
  198. static void tfp410_dpms(struct intel_dvo_device *dvo, bool enable)
  199. {
  200. uint8_t ctl1;
  201. if (!tfp410_readb(dvo, TFP410_CTL_1, &ctl1))
  202. return;
  203. if (enable)
  204. ctl1 |= TFP410_CTL_1_PD;
  205. else
  206. ctl1 &= ~TFP410_CTL_1_PD;
  207. tfp410_writeb(dvo, TFP410_CTL_1, ctl1);
  208. }
  209. static bool tfp410_get_hw_state(struct intel_dvo_device *dvo)
  210. {
  211. uint8_t ctl1;
  212. if (!tfp410_readb(dvo, TFP410_CTL_1, &ctl1))
  213. return false;
  214. if (ctl1 & TFP410_CTL_1_PD)
  215. return true;
  216. else
  217. return false;
  218. }
  219. static void tfp410_dump_regs(struct intel_dvo_device *dvo)
  220. {
  221. uint8_t val, val2;
  222. tfp410_readb(dvo, TFP410_REV, &val);
  223. DRM_DEBUG_KMS("TFP410_REV: 0x%02X\n", val);
  224. tfp410_readb(dvo, TFP410_CTL_1, &val);
  225. DRM_DEBUG_KMS("TFP410_CTL1: 0x%02X\n", val);
  226. tfp410_readb(dvo, TFP410_CTL_2, &val);
  227. DRM_DEBUG_KMS("TFP410_CTL2: 0x%02X\n", val);
  228. tfp410_readb(dvo, TFP410_CTL_3, &val);
  229. DRM_DEBUG_KMS("TFP410_CTL3: 0x%02X\n", val);
  230. tfp410_readb(dvo, TFP410_USERCFG, &val);
  231. DRM_DEBUG_KMS("TFP410_USERCFG: 0x%02X\n", val);
  232. tfp410_readb(dvo, TFP410_DE_DLY, &val);
  233. DRM_DEBUG_KMS("TFP410_DE_DLY: 0x%02X\n", val);
  234. tfp410_readb(dvo, TFP410_DE_CTL, &val);
  235. DRM_DEBUG_KMS("TFP410_DE_CTL: 0x%02X\n", val);
  236. tfp410_readb(dvo, TFP410_DE_TOP, &val);
  237. DRM_DEBUG_KMS("TFP410_DE_TOP: 0x%02X\n", val);
  238. tfp410_readb(dvo, TFP410_DE_CNT_LO, &val);
  239. tfp410_readb(dvo, TFP410_DE_CNT_HI, &val2);
  240. DRM_DEBUG_KMS("TFP410_DE_CNT: 0x%02X%02X\n", val2, val);
  241. tfp410_readb(dvo, TFP410_DE_LIN_LO, &val);
  242. tfp410_readb(dvo, TFP410_DE_LIN_HI, &val2);
  243. DRM_DEBUG_KMS("TFP410_DE_LIN: 0x%02X%02X\n", val2, val);
  244. tfp410_readb(dvo, TFP410_H_RES_LO, &val);
  245. tfp410_readb(dvo, TFP410_H_RES_HI, &val2);
  246. DRM_DEBUG_KMS("TFP410_H_RES: 0x%02X%02X\n", val2, val);
  247. tfp410_readb(dvo, TFP410_V_RES_LO, &val);
  248. tfp410_readb(dvo, TFP410_V_RES_HI, &val2);
  249. DRM_DEBUG_KMS("TFP410_V_RES: 0x%02X%02X\n", val2, val);
  250. }
  251. static void tfp410_destroy(struct intel_dvo_device *dvo)
  252. {
  253. struct tfp410_priv *tfp = dvo->dev_priv;
  254. if (tfp) {
  255. kfree(tfp);
  256. dvo->dev_priv = NULL;
  257. }
  258. }
  259. struct intel_dvo_dev_ops tfp410_ops = {
  260. .init = tfp410_init,
  261. .detect = tfp410_detect,
  262. .mode_valid = tfp410_mode_valid,
  263. .mode_set = tfp410_mode_set,
  264. .dpms = tfp410_dpms,
  265. .get_hw_state = tfp410_get_hw_state,
  266. .dump_regs = tfp410_dump_regs,
  267. .destroy = tfp410_destroy,
  268. };