/drivers/staging/msm/hdmi_sii9022.c

https://bitbucket.org/slukk/jb-tsm-kernel-4.2 · C · 248 lines · 188 code · 39 blank · 21 comment · 25 complexity · 254e6adb91c20f8e18e0fc188e236122 MD5 · raw file

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