hdmi_sii9022.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /* Copyright (c) 2009-2010, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. */
  13. #include <linux/i2c.h>
  14. #include <linux/delay.h>
  15. #include "msm_fb.h"
  16. #define DEVICE_NAME "sii9022"
  17. #define SII9022_DEVICE_ID 0xB0
  18. struct sii9022_i2c_addr_data{
  19. u8 addr;
  20. u8 data;
  21. };
  22. /* video mode data */
  23. static u8 video_mode_data[] = {
  24. 0x00,
  25. 0xF9, 0x1C, 0x70, 0x17, 0x72, 0x06, 0xEE, 0x02,
  26. };
  27. static u8 avi_io_format[] = {
  28. 0x09,
  29. 0x00, 0x00,
  30. };
  31. /* power state */
  32. static struct sii9022_i2c_addr_data regset0[] = {
  33. { 0x60, 0x04 },
  34. { 0x63, 0x00 },
  35. { 0x1E, 0x00 },
  36. };
  37. static u8 video_infoframe[] = {
  38. 0x0C,
  39. 0xF0, 0x00, 0x68, 0x00, 0x04, 0x00, 0x19, 0x00,
  40. 0xE9, 0x02, 0x04, 0x01, 0x04, 0x06,
  41. };
  42. /* configure audio */
  43. static struct sii9022_i2c_addr_data regset1[] = {
  44. { 0x26, 0x90 },
  45. { 0x20, 0x90 },
  46. { 0x1F, 0x80 },
  47. { 0x26, 0x80 },
  48. { 0x24, 0x02 },
  49. { 0x25, 0x0B },
  50. { 0xBC, 0x02 },
  51. { 0xBD, 0x24 },
  52. { 0xBE, 0x02 },
  53. };
  54. /* enable audio */
  55. static u8 misc_infoframe[] = {
  56. 0xBF,
  57. 0xC2, 0x84, 0x01, 0x0A, 0x6F, 0x02, 0x00, 0x00,
  58. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  59. };
  60. /* set HDMI, active */
  61. static struct sii9022_i2c_addr_data regset2[] = {
  62. { 0x1A, 0x01 },
  63. { 0x3D, 0x00 },
  64. };
  65. static int send_i2c_data(struct i2c_client *client,
  66. struct sii9022_i2c_addr_data *regset,
  67. int size)
  68. {
  69. int i;
  70. int rc = 0;
  71. for (i = 0; i < size; i++) {
  72. rc = i2c_smbus_write_byte_data(
  73. client,
  74. regset[i].addr, regset[i].data);
  75. if (rc)
  76. break;
  77. }
  78. return rc;
  79. }
  80. static int hdmi_sii_enable(struct i2c_client *client)
  81. {
  82. int rc;
  83. int retries = 10;
  84. int count;
  85. rc = i2c_smbus_write_byte_data(client, 0xC7, 0x00);
  86. if (rc)
  87. goto enable_exit;
  88. do {
  89. msleep(1);
  90. rc = i2c_smbus_read_byte_data(client, 0x1B);
  91. } while ((rc != SII9022_DEVICE_ID) && retries--);
  92. if (rc != SII9022_DEVICE_ID)
  93. return -ENODEV;
  94. rc = i2c_smbus_write_byte_data(client, 0x1A, 0x11);
  95. if (rc)
  96. goto enable_exit;
  97. count = ARRAY_SIZE(video_mode_data);
  98. rc = i2c_master_send(client, video_mode_data, count);
  99. if (rc != count) {
  100. rc = -EIO;
  101. goto enable_exit;
  102. }
  103. rc = i2c_smbus_write_byte_data(client, 0x08, 0x20);
  104. if (rc)
  105. goto enable_exit;
  106. count = ARRAY_SIZE(avi_io_format);
  107. rc = i2c_master_send(client, avi_io_format, count);
  108. if (rc != count) {
  109. rc = -EIO;
  110. goto enable_exit;
  111. }
  112. rc = send_i2c_data(client, regset0, ARRAY_SIZE(regset0));
  113. if (rc)
  114. goto enable_exit;
  115. count = ARRAY_SIZE(video_infoframe);
  116. rc = i2c_master_send(client, video_infoframe, count);
  117. if (rc != count) {
  118. rc = -EIO;
  119. goto enable_exit;
  120. }
  121. rc = send_i2c_data(client, regset1, ARRAY_SIZE(regset1));
  122. if (rc)
  123. goto enable_exit;
  124. count = ARRAY_SIZE(misc_infoframe);
  125. rc = i2c_master_send(client, misc_infoframe, count);
  126. if (rc != count) {
  127. rc = -EIO;
  128. goto enable_exit;
  129. }
  130. rc = send_i2c_data(client, regset2, ARRAY_SIZE(regset2));
  131. if (rc)
  132. goto enable_exit;
  133. return 0;
  134. enable_exit:
  135. printk(KERN_ERR "%s: exited rc=%d\n", __func__, rc);
  136. return rc;
  137. }
  138. static const struct i2c_device_id hmdi_sii_id[] = {
  139. { DEVICE_NAME, 0 },
  140. { }
  141. };
  142. static int hdmi_sii_probe(struct i2c_client *client,
  143. const struct i2c_device_id *id)
  144. {
  145. int rc;
  146. if (!i2c_check_functionality(client->adapter,
  147. I2C_FUNC_SMBUS_BYTE | I2C_FUNC_I2C))
  148. return -ENODEV;
  149. rc = hdmi_sii_enable(client);
  150. return rc;
  151. }
  152. static struct i2c_driver hdmi_sii_i2c_driver = {
  153. .driver = {
  154. .name = DEVICE_NAME,
  155. .owner = THIS_MODULE,
  156. },
  157. .probe = hdmi_sii_probe,
  158. .remove = __exit_p(hdmi_sii_remove),
  159. .id_table = hmdi_sii_id,
  160. };
  161. static int __init hdmi_sii_init(void)
  162. {
  163. int ret;
  164. struct msm_panel_info pinfo;
  165. if (msm_fb_detect_client("hdmi_sii9022"))
  166. return 0;
  167. pinfo.xres = 1280;
  168. pinfo.yres = 720;
  169. MSM_FB_SINGLE_MODE_PANEL(&pinfo);
  170. pinfo.type = HDMI_PANEL;
  171. pinfo.pdest = DISPLAY_1;
  172. pinfo.wait_cycle = 0;
  173. pinfo.bpp = 18;
  174. pinfo.fb_num = 2;
  175. pinfo.clk_rate = 74250000;
  176. pinfo.lcdc.h_back_porch = 124;
  177. pinfo.lcdc.h_front_porch = 110;
  178. pinfo.lcdc.h_pulse_width = 136;
  179. pinfo.lcdc.v_back_porch = 19;
  180. pinfo.lcdc.v_front_porch = 5;
  181. pinfo.lcdc.v_pulse_width = 6;
  182. pinfo.lcdc.border_clr = 0;
  183. pinfo.lcdc.underflow_clr = 0xff;
  184. pinfo.lcdc.hsync_skew = 0;
  185. ret = lcdc_device_register(&pinfo);
  186. if (ret) {
  187. printk(KERN_ERR "%s: failed to register device\n", __func__);
  188. goto init_exit;
  189. }
  190. ret = i2c_add_driver(&hdmi_sii_i2c_driver);
  191. if (ret)
  192. printk(KERN_ERR "%s: failed to add i2c driver\n", __func__);
  193. init_exit:
  194. return ret;
  195. }
  196. static void __exit hdmi_sii_exit(void)
  197. {
  198. i2c_del_driver(&hdmi_sii_i2c_driver);
  199. }
  200. module_init(hdmi_sii_init);
  201. module_exit(hdmi_sii_exit);
  202. MODULE_LICENSE("GPL v2");
  203. MODULE_VERSION("0.1");
  204. MODULE_AUTHOR("Qualcomm Innovation Center, Inc.");
  205. MODULE_DESCRIPTION("SiI9022 HDMI driver");
  206. MODULE_ALIAS("platform:hdmi-sii9022");