bt856.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /*
  2. * bt856 - BT856A Digital Video Encoder (Rockwell Part)
  3. *
  4. * Copyright (C) 1999 Mike Bernson <mike@mlb.org>
  5. * Copyright (C) 1998 Dave Perks <dperks@ibm.net>
  6. *
  7. * Modifications for LML33/DC10plus unified driver
  8. * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
  9. *
  10. * This code was modify/ported from the saa7111 driver written
  11. * by Dave Perks.
  12. *
  13. * Changes by Ronald Bultje <rbultje@ronald.bitfreak.net>
  14. * - moved over to linux>=2.4.x i2c protocol (9/9/2002)
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 2 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  29. */
  30. #include <linux/module.h>
  31. #include <linux/types.h>
  32. #include <linux/ioctl.h>
  33. #include <asm/uaccess.h>
  34. #include <linux/i2c.h>
  35. #include <linux/i2c-id.h>
  36. #include <linux/videodev.h>
  37. #include <linux/video_encoder.h>
  38. #include <media/v4l2-common.h>
  39. #include <media/v4l2-i2c-drv-legacy.h>
  40. MODULE_DESCRIPTION("Brooktree-856A video encoder driver");
  41. MODULE_AUTHOR("Mike Bernson & Dave Perks");
  42. MODULE_LICENSE("GPL");
  43. static int debug;
  44. module_param(debug, int, 0);
  45. MODULE_PARM_DESC(debug, "Debug level (0-1)");
  46. /* ----------------------------------------------------------------------- */
  47. #define BT856_REG_OFFSET 0xDA
  48. #define BT856_NR_REG 6
  49. struct bt856 {
  50. unsigned char reg[BT856_NR_REG];
  51. v4l2_std_id norm;
  52. };
  53. /* ----------------------------------------------------------------------- */
  54. static inline int bt856_write(struct i2c_client *client, u8 reg, u8 value)
  55. {
  56. struct bt856 *encoder = i2c_get_clientdata(client);
  57. encoder->reg[reg - BT856_REG_OFFSET] = value;
  58. return i2c_smbus_write_byte_data(client, reg, value);
  59. }
  60. static inline int bt856_setbit(struct i2c_client *client, u8 reg, u8 bit, u8 value)
  61. {
  62. struct bt856 *encoder = i2c_get_clientdata(client);
  63. return bt856_write(client, reg,
  64. (encoder->reg[reg - BT856_REG_OFFSET] & ~(1 << bit)) |
  65. (value ? (1 << bit) : 0));
  66. }
  67. static void bt856_dump(struct i2c_client *client)
  68. {
  69. int i;
  70. struct bt856 *encoder = i2c_get_clientdata(client);
  71. v4l_info(client, "register dump:\n");
  72. for (i = 0; i < BT856_NR_REG; i += 2)
  73. printk(KERN_CONT " %02x", encoder->reg[i]);
  74. printk(KERN_CONT "\n");
  75. }
  76. /* ----------------------------------------------------------------------- */
  77. static int bt856_command(struct i2c_client *client, unsigned cmd, void *arg)
  78. {
  79. struct bt856 *encoder = i2c_get_clientdata(client);
  80. switch (cmd) {
  81. case VIDIOC_INT_INIT:
  82. /* This is just for testing!!! */
  83. v4l_dbg(1, debug, client, "init\n");
  84. bt856_write(client, 0xdc, 0x18);
  85. bt856_write(client, 0xda, 0);
  86. bt856_write(client, 0xde, 0);
  87. bt856_setbit(client, 0xdc, 3, 1);
  88. //bt856_setbit(client, 0xdc, 6, 0);
  89. bt856_setbit(client, 0xdc, 4, 1);
  90. if (encoder->norm & V4L2_STD_NTSC)
  91. bt856_setbit(client, 0xdc, 2, 0);
  92. else
  93. bt856_setbit(client, 0xdc, 2, 1);
  94. bt856_setbit(client, 0xdc, 1, 1);
  95. bt856_setbit(client, 0xde, 4, 0);
  96. bt856_setbit(client, 0xde, 3, 1);
  97. if (debug != 0)
  98. bt856_dump(client);
  99. break;
  100. case VIDIOC_INT_S_STD_OUTPUT:
  101. {
  102. v4l2_std_id *iarg = arg;
  103. v4l_dbg(1, debug, client, "set norm %llx\n", *iarg);
  104. if (*iarg & V4L2_STD_NTSC) {
  105. bt856_setbit(client, 0xdc, 2, 0);
  106. } else if (*iarg & V4L2_STD_PAL) {
  107. bt856_setbit(client, 0xdc, 2, 1);
  108. bt856_setbit(client, 0xda, 0, 0);
  109. //bt856_setbit(client, 0xda, 0, 1);
  110. } else {
  111. return -EINVAL;
  112. }
  113. encoder->norm = *iarg;
  114. if (debug != 0)
  115. bt856_dump(client);
  116. break;
  117. }
  118. case VIDIOC_INT_S_VIDEO_ROUTING:
  119. {
  120. struct v4l2_routing *route = arg;
  121. v4l_dbg(1, debug, client, "set input %d\n", route->input);
  122. /* We only have video bus.
  123. * route->input= 0: input is from bt819
  124. * route->input= 1: input is from ZR36060 */
  125. switch (route->input) {
  126. case 0:
  127. bt856_setbit(client, 0xde, 4, 0);
  128. bt856_setbit(client, 0xde, 3, 1);
  129. bt856_setbit(client, 0xdc, 3, 1);
  130. bt856_setbit(client, 0xdc, 6, 0);
  131. break;
  132. case 1:
  133. bt856_setbit(client, 0xde, 4, 0);
  134. bt856_setbit(client, 0xde, 3, 1);
  135. bt856_setbit(client, 0xdc, 3, 1);
  136. bt856_setbit(client, 0xdc, 6, 1);
  137. break;
  138. case 2: // Color bar
  139. bt856_setbit(client, 0xdc, 3, 0);
  140. bt856_setbit(client, 0xde, 4, 1);
  141. break;
  142. default:
  143. return -EINVAL;
  144. }
  145. if (debug != 0)
  146. bt856_dump(client);
  147. break;
  148. }
  149. default:
  150. return -EINVAL;
  151. }
  152. return 0;
  153. }
  154. /* ----------------------------------------------------------------------- */
  155. static unsigned short normal_i2c[] = { 0x88 >> 1, I2C_CLIENT_END };
  156. I2C_CLIENT_INSMOD;
  157. static int bt856_probe(struct i2c_client *client,
  158. const struct i2c_device_id *id)
  159. {
  160. struct bt856 *encoder;
  161. /* Check if the adapter supports the needed features */
  162. if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
  163. return -ENODEV;
  164. v4l_info(client, "chip found @ 0x%x (%s)\n",
  165. client->addr << 1, client->adapter->name);
  166. encoder = kzalloc(sizeof(struct bt856), GFP_KERNEL);
  167. if (encoder == NULL)
  168. return -ENOMEM;
  169. encoder->norm = V4L2_STD_NTSC;
  170. i2c_set_clientdata(client, encoder);
  171. bt856_write(client, 0xdc, 0x18);
  172. bt856_write(client, 0xda, 0);
  173. bt856_write(client, 0xde, 0);
  174. bt856_setbit(client, 0xdc, 3, 1);
  175. //bt856_setbit(client, 0xdc, 6, 0);
  176. bt856_setbit(client, 0xdc, 4, 1);
  177. if (encoder->norm & V4L2_STD_NTSC)
  178. bt856_setbit(client, 0xdc, 2, 0);
  179. else
  180. bt856_setbit(client, 0xdc, 2, 1);
  181. bt856_setbit(client, 0xdc, 1, 1);
  182. bt856_setbit(client, 0xde, 4, 0);
  183. bt856_setbit(client, 0xde, 3, 1);
  184. if (debug != 0)
  185. bt856_dump(client);
  186. return 0;
  187. }
  188. static int bt856_remove(struct i2c_client *client)
  189. {
  190. kfree(i2c_get_clientdata(client));
  191. return 0;
  192. }
  193. static const struct i2c_device_id bt856_id[] = {
  194. { "bt856", 0 },
  195. { }
  196. };
  197. MODULE_DEVICE_TABLE(i2c, bt856_id);
  198. static struct v4l2_i2c_driver_data v4l2_i2c_data = {
  199. .name = "bt856",
  200. .driverid = I2C_DRIVERID_BT856,
  201. .command = bt856_command,
  202. .probe = bt856_probe,
  203. .remove = bt856_remove,
  204. .id_table = bt856_id,
  205. };