ths7303.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. MODULE_DESCRIPTION("TI THS7303 video amplifier driver");
  29. MODULE_AUTHOR("Chaithrika U S");
  30. MODULE_LICENSE("GPL");
  31. static int debug;
  32. module_param(debug, int, 0644);
  33. MODULE_PARM_DESC(debug, "Debug level 0-1");
  34. /* following function is used to set ths7303 */
  35. static int ths7303_setvalue(struct v4l2_subdev *sd, v4l2_std_id std)
  36. {
  37. int err = 0;
  38. u8 val;
  39. struct i2c_client *client;
  40. client = v4l2_get_subdevdata(sd);
  41. if (std & (V4L2_STD_ALL & ~V4L2_STD_SECAM)) {
  42. val = 0x02;
  43. v4l2_dbg(1, debug, sd, "setting value for SDTV format\n");
  44. } else {
  45. val = 0x00;
  46. v4l2_dbg(1, debug, sd, "disabling all channels\n");
  47. }
  48. err |= i2c_smbus_write_byte_data(client, 0x01, val);
  49. err |= i2c_smbus_write_byte_data(client, 0x02, val);
  50. err |= i2c_smbus_write_byte_data(client, 0x03, val);
  51. if (err)
  52. v4l2_err(sd, "write failed\n");
  53. return err;
  54. }
  55. static int ths7303_s_std_output(struct v4l2_subdev *sd, v4l2_std_id norm)
  56. {
  57. return ths7303_setvalue(sd, norm);
  58. }
  59. static int ths7303_g_chip_ident(struct v4l2_subdev *sd,
  60. struct v4l2_dbg_chip_ident *chip)
  61. {
  62. struct i2c_client *client = v4l2_get_subdevdata(sd);
  63. return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_THS7303, 0);
  64. }
  65. static const struct v4l2_subdev_video_ops ths7303_video_ops = {
  66. .s_std_output = ths7303_s_std_output,
  67. };
  68. static const struct v4l2_subdev_core_ops ths7303_core_ops = {
  69. .g_chip_ident = ths7303_g_chip_ident,
  70. };
  71. static const struct v4l2_subdev_ops ths7303_ops = {
  72. .core = &ths7303_core_ops,
  73. .video = &ths7303_video_ops,
  74. };
  75. static int ths7303_probe(struct i2c_client *client,
  76. const struct i2c_device_id *id)
  77. {
  78. struct v4l2_subdev *sd;
  79. v4l2_std_id std_id = V4L2_STD_NTSC;
  80. if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
  81. return -ENODEV;
  82. v4l_info(client, "chip found @ 0x%x (%s)\n",
  83. client->addr << 1, client->adapter->name);
  84. sd = kzalloc(sizeof(struct v4l2_subdev), GFP_KERNEL);
  85. if (sd == NULL)
  86. return -ENOMEM;
  87. v4l2_i2c_subdev_init(sd, client, &ths7303_ops);
  88. return ths7303_setvalue(sd, std_id);
  89. }
  90. static int ths7303_remove(struct i2c_client *client)
  91. {
  92. struct v4l2_subdev *sd = i2c_get_clientdata(client);
  93. v4l2_device_unregister_subdev(sd);
  94. kfree(sd);
  95. return 0;
  96. }
  97. static const struct i2c_device_id ths7303_id[] = {
  98. {"ths7303", 0},
  99. {},
  100. };
  101. MODULE_DEVICE_TABLE(i2c, ths7303_id);
  102. static struct i2c_driver ths7303_driver = {
  103. .driver = {
  104. .owner = THIS_MODULE,
  105. .name = "ths7303",
  106. },
  107. .probe = ths7303_probe,
  108. .remove = ths7303_remove,
  109. .id_table = ths7303_id,
  110. };
  111. module_i2c_driver(ths7303_driver);