hdmiphy_drv.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * Samsung HDMI Physical interface driver
  3. *
  4. * Copyright (C) 2010-2011 Samsung Electronics Co.Ltd
  5. * Author: Tomasz Stanislawski <t.stanislaws@samsung.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/i2c.h>
  14. #include <linux/slab.h>
  15. #include <linux/clk.h>
  16. #include <linux/io.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/irq.h>
  19. #include <linux/err.h>
  20. #include <media/v4l2-subdev.h>
  21. MODULE_AUTHOR("Tomasz Stanislawski <t.stanislaws@samsung.com>");
  22. MODULE_DESCRIPTION("Samsung HDMI Physical interface driver");
  23. MODULE_LICENSE("GPL");
  24. struct hdmiphy_conf {
  25. u32 preset;
  26. const u8 *data;
  27. };
  28. static const u8 hdmiphy_conf27[32] = {
  29. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x1C, 0x30, 0x40,
  30. 0x6B, 0x10, 0x02, 0x51, 0xDf, 0xF2, 0x54, 0x87,
  31. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  32. 0x22, 0x40, 0xe3, 0x26, 0x00, 0x00, 0x00, 0x00,
  33. };
  34. static const u8 hdmiphy_conf74_175[32] = {
  35. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x9C, 0xef, 0x5B,
  36. 0x6D, 0x10, 0x01, 0x51, 0xef, 0xF3, 0x54, 0xb9,
  37. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  38. 0x22, 0x40, 0xa5, 0x26, 0x01, 0x00, 0x00, 0x00,
  39. };
  40. static const u8 hdmiphy_conf74_25[32] = {
  41. 0x01, 0x05, 0x00, 0xd8, 0x10, 0x9c, 0xf8, 0x40,
  42. 0x6a, 0x10, 0x01, 0x51, 0xff, 0xf1, 0x54, 0xba,
  43. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xe0,
  44. 0x22, 0x40, 0xa4, 0x26, 0x01, 0x00, 0x00, 0x00,
  45. };
  46. static const u8 hdmiphy_conf148_5[32] = {
  47. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x9C, 0xf8, 0x40,
  48. 0x6A, 0x18, 0x00, 0x51, 0xff, 0xF1, 0x54, 0xba,
  49. 0x84, 0x00, 0x10, 0x38, 0x00, 0x08, 0x10, 0xE0,
  50. 0x22, 0x40, 0xa4, 0x26, 0x02, 0x00, 0x00, 0x00,
  51. };
  52. static const struct hdmiphy_conf hdmiphy_conf[] = {
  53. { V4L2_DV_480P59_94, hdmiphy_conf27 },
  54. { V4L2_DV_1080P30, hdmiphy_conf74_175 },
  55. { V4L2_DV_720P59_94, hdmiphy_conf74_175 },
  56. { V4L2_DV_720P60, hdmiphy_conf74_25 },
  57. { V4L2_DV_1080P50, hdmiphy_conf148_5 },
  58. { V4L2_DV_1080P60, hdmiphy_conf148_5 },
  59. };
  60. const u8 *hdmiphy_preset2conf(u32 preset)
  61. {
  62. int i;
  63. for (i = 0; i < ARRAY_SIZE(hdmiphy_conf); ++i)
  64. if (hdmiphy_conf[i].preset == preset)
  65. return hdmiphy_conf[i].data;
  66. return NULL;
  67. }
  68. static int hdmiphy_s_power(struct v4l2_subdev *sd, int on)
  69. {
  70. /* to be implemented */
  71. return 0;
  72. }
  73. static int hdmiphy_s_dv_preset(struct v4l2_subdev *sd,
  74. struct v4l2_dv_preset *preset)
  75. {
  76. const u8 *data;
  77. u8 buffer[32];
  78. int ret;
  79. struct i2c_client *client = v4l2_get_subdevdata(sd);
  80. struct device *dev = &client->dev;
  81. dev_info(dev, "s_dv_preset(preset = %d)\n", preset->preset);
  82. data = hdmiphy_preset2conf(preset->preset);
  83. if (!data) {
  84. dev_err(dev, "format not supported\n");
  85. return -EINVAL;
  86. }
  87. /* storing configuration to the device */
  88. memcpy(buffer, data, 32);
  89. ret = i2c_master_send(client, buffer, 32);
  90. if (ret != 32) {
  91. dev_err(dev, "failed to configure HDMIPHY via I2C\n");
  92. return -EIO;
  93. }
  94. return 0;
  95. }
  96. static int hdmiphy_s_stream(struct v4l2_subdev *sd, int enable)
  97. {
  98. struct i2c_client *client = v4l2_get_subdevdata(sd);
  99. struct device *dev = &client->dev;
  100. u8 buffer[2];
  101. int ret;
  102. dev_info(dev, "s_stream(%d)\n", enable);
  103. /* going to/from configuration from/to operation mode */
  104. buffer[0] = 0x1f;
  105. buffer[1] = enable ? 0x80 : 0x00;
  106. ret = i2c_master_send(client, buffer, 2);
  107. if (ret != 2) {
  108. dev_err(dev, "stream (%d) failed\n", enable);
  109. return -EIO;
  110. }
  111. return 0;
  112. }
  113. static const struct v4l2_subdev_core_ops hdmiphy_core_ops = {
  114. .s_power = hdmiphy_s_power,
  115. };
  116. static const struct v4l2_subdev_video_ops hdmiphy_video_ops = {
  117. .s_dv_preset = hdmiphy_s_dv_preset,
  118. .s_stream = hdmiphy_s_stream,
  119. };
  120. static const struct v4l2_subdev_ops hdmiphy_ops = {
  121. .core = &hdmiphy_core_ops,
  122. .video = &hdmiphy_video_ops,
  123. };
  124. static int __devinit hdmiphy_probe(struct i2c_client *client,
  125. const struct i2c_device_id *id)
  126. {
  127. static struct v4l2_subdev sd;
  128. v4l2_i2c_subdev_init(&sd, client, &hdmiphy_ops);
  129. dev_info(&client->dev, "probe successful\n");
  130. return 0;
  131. }
  132. static int __devexit hdmiphy_remove(struct i2c_client *client)
  133. {
  134. dev_info(&client->dev, "remove successful\n");
  135. return 0;
  136. }
  137. static const struct i2c_device_id hdmiphy_id[] = {
  138. { "hdmiphy", 0 },
  139. { },
  140. };
  141. MODULE_DEVICE_TABLE(i2c, hdmiphy_id);
  142. static struct i2c_driver hdmiphy_driver = {
  143. .driver = {
  144. .name = "s5p-hdmiphy",
  145. .owner = THIS_MODULE,
  146. },
  147. .probe = hdmiphy_probe,
  148. .remove = __devexit_p(hdmiphy_remove),
  149. .id_table = hdmiphy_id,
  150. };
  151. module_i2c_driver(hdmiphy_driver);