ths7303.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * ths7303- THS7303 Video Amplifier driver
  3. *
  4. * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation version 2.
  9. *
  10. * This program is distributed .as is. WITHOUT ANY WARRANTY of any
  11. * kind, whether express or implied; without even the implied warranty
  12. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/init.h>
  17. #include <linux/ctype.h>
  18. #include <linux/slab.h>
  19. #include <linux/i2c.h>
  20. #include <linux/device.h>
  21. #include <linux/delay.h>
  22. #include <linux/module.h>
  23. #include <linux/uaccess.h>
  24. #include <linux/videodev2.h>
  25. #include <media/v4l2-device.h>
  26. #include <media/v4l2-subdev.h>
  27. #include <media/v4l2-chip-ident.h>
  28. #define THS7303_CHANNEL_1 1
  29. #define THS7303_CHANNEL_2 2
  30. #define THS7303_CHANNEL_3 3
  31. enum ths7303_filter_mode {
  32. THS7303_FILTER_MODE_480I_576I,
  33. THS7303_FILTER_MODE_480P_576P,
  34. THS7303_FILTER_MODE_720P_1080I,
  35. THS7303_FILTER_MODE_1080P,
  36. THS7303_FILTER_MODE_DISABLE
  37. };
  38. MODULE_DESCRIPTION("TI THS7303 video amplifier driver");
  39. MODULE_AUTHOR("Chaithrika U S");
  40. MODULE_LICENSE("GPL");
  41. static int debug;
  42. module_param(debug, int, 0644);
  43. MODULE_PARM_DESC(debug, "Debug level 0-1");
  44. /* following function is used to set ths7303 */
  45. int ths7303_setval(struct v4l2_subdev *sd, enum ths7303_filter_mode mode)
  46. {
  47. u8 input_bias_chroma = 3;
  48. u8 input_bias_luma = 3;
  49. int disable = 0;
  50. int err = 0;
  51. u8 val = 0;
  52. u8 temp;
  53. struct i2c_client *client = v4l2_get_subdevdata(sd);
  54. if (!client)
  55. return -EINVAL;
  56. switch (mode) {
  57. case THS7303_FILTER_MODE_1080P:
  58. val = (3 << 6);
  59. val |= (3 << 3);
  60. break;
  61. case THS7303_FILTER_MODE_720P_1080I:
  62. val = (2 << 6);
  63. val |= (2 << 3);
  64. break;
  65. case THS7303_FILTER_MODE_480P_576P:
  66. val = (1 << 6);
  67. val |= (1 << 3);
  68. break;
  69. case THS7303_FILTER_MODE_480I_576I:
  70. break;
  71. case THS7303_FILTER_MODE_DISABLE:
  72. pr_info("mode disabled\n");
  73. /* disable all channels */
  74. disable = 1;
  75. default:
  76. /* disable all channels */
  77. disable = 1;
  78. }
  79. /* Setup channel 2 - Luma - Green */
  80. temp = val;
  81. if (!disable)
  82. val |= input_bias_luma;
  83. err = i2c_smbus_write_byte_data(client, THS7303_CHANNEL_2, val);
  84. if (err)
  85. goto out;
  86. /* setup two chroma channels */
  87. if (!disable)
  88. temp |= input_bias_chroma;
  89. err = i2c_smbus_write_byte_data(client, THS7303_CHANNEL_1, temp);
  90. if (err)
  91. goto out;
  92. err = i2c_smbus_write_byte_data(client, THS7303_CHANNEL_3, temp);
  93. if (err)
  94. goto out;
  95. return err;
  96. out:
  97. pr_info("write byte data failed\n");
  98. return err;
  99. }
  100. static int ths7303_s_std_output(struct v4l2_subdev *sd, v4l2_std_id norm)
  101. {
  102. if (norm & (V4L2_STD_ALL & ~V4L2_STD_SECAM))
  103. return ths7303_setval(sd, THS7303_FILTER_MODE_480I_576I);
  104. else
  105. return ths7303_setval(sd, THS7303_FILTER_MODE_DISABLE);
  106. }
  107. /* for setting filter for HD output */
  108. static int ths7303_s_dv_timings(struct v4l2_subdev *sd,
  109. struct v4l2_dv_timings *dv_timings)
  110. {
  111. u32 height = dv_timings->bt.height;
  112. int interlaced = dv_timings->bt.interlaced;
  113. int res = 0;
  114. if (height == 1080 && !interlaced)
  115. res = ths7303_setval(sd, THS7303_FILTER_MODE_1080P);
  116. else if ((height == 720 && !interlaced) ||
  117. (height == 1080 && interlaced))
  118. res = ths7303_setval(sd, THS7303_FILTER_MODE_720P_1080I);
  119. else if ((height == 480 || height == 576) && !interlaced)
  120. res = ths7303_setval(sd, THS7303_FILTER_MODE_480P_576P);
  121. else
  122. /* disable all channels */
  123. res = ths7303_setval(sd, THS7303_FILTER_MODE_DISABLE);
  124. return res;
  125. }
  126. static int ths7303_g_chip_ident(struct v4l2_subdev *sd,
  127. struct v4l2_dbg_chip_ident *chip)
  128. {
  129. struct i2c_client *client = v4l2_get_subdevdata(sd);
  130. return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_THS7303, 0);
  131. }
  132. static const struct v4l2_subdev_video_ops ths7303_video_ops = {
  133. .s_std_output = ths7303_s_std_output,
  134. .s_dv_timings = ths7303_s_dv_timings,
  135. };
  136. static const struct v4l2_subdev_core_ops ths7303_core_ops = {
  137. .g_chip_ident = ths7303_g_chip_ident,
  138. };
  139. static const struct v4l2_subdev_ops ths7303_ops = {
  140. .core = &ths7303_core_ops,
  141. .video = &ths7303_video_ops,
  142. };
  143. static int ths7303_probe(struct i2c_client *client,
  144. const struct i2c_device_id *id)
  145. {
  146. struct v4l2_subdev *sd;
  147. v4l2_std_id std_id = V4L2_STD_NTSC;
  148. if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
  149. return -ENODEV;
  150. v4l_info(client, "chip found @ 0x%x (%s)\n",
  151. client->addr << 1, client->adapter->name);
  152. sd = devm_kzalloc(&client->dev, sizeof(struct v4l2_subdev), GFP_KERNEL);
  153. if (sd == NULL)
  154. return -ENOMEM;
  155. v4l2_i2c_subdev_init(sd, client, &ths7303_ops);
  156. return ths7303_s_std_output(sd, std_id);
  157. }
  158. static int ths7303_remove(struct i2c_client *client)
  159. {
  160. struct v4l2_subdev *sd = i2c_get_clientdata(client);
  161. v4l2_device_unregister_subdev(sd);
  162. return 0;
  163. }
  164. static const struct i2c_device_id ths7303_id[] = {
  165. {"ths7303", 0},
  166. {},
  167. };
  168. MODULE_DEVICE_TABLE(i2c, ths7303_id);
  169. static struct i2c_driver ths7303_driver = {
  170. .driver = {
  171. .owner = THIS_MODULE,
  172. .name = "ths7303",
  173. },
  174. .probe = ths7303_probe,
  175. .remove = ths7303_remove,
  176. .id_table = ths7303_id,
  177. };
  178. module_i2c_driver(ths7303_driver);