m5602_bridge.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * USB Driver for ALi m5602 based webcams
  3. *
  4. * Copyright (C) 2008 Erik Andrén
  5. * Copyright (C) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project.
  6. * Copyright (C) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br>
  7. *
  8. * Portions of code to USB interface and ALi driver software,
  9. * Copyright (c) 2006 Willem Duinker
  10. * v4l2 interface modeled after the V4L2 driver
  11. * for SN9C10x PC Camera Controllers
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License as
  15. * published by the Free Software Foundation, version 2.
  16. *
  17. */
  18. #ifndef M5602_BRIDGE_H_
  19. #define M5602_BRIDGE_H_
  20. #include <linux/slab.h>
  21. #include "gspca.h"
  22. #define MODULE_NAME "ALi m5602"
  23. /*****************************************************************************/
  24. #define M5602_XB_SENSOR_TYPE 0x00
  25. #define M5602_XB_SENSOR_CTRL 0x01
  26. #define M5602_XB_LINE_OF_FRAME_H 0x02
  27. #define M5602_XB_LINE_OF_FRAME_L 0x03
  28. #define M5602_XB_PIX_OF_LINE_H 0x04
  29. #define M5602_XB_PIX_OF_LINE_L 0x05
  30. #define M5602_XB_VSYNC_PARA 0x06
  31. #define M5602_XB_HSYNC_PARA 0x07
  32. #define M5602_XB_TEST_MODE_1 0x08
  33. #define M5602_XB_TEST_MODE_2 0x09
  34. #define M5602_XB_SIG_INI 0x0a
  35. #define M5602_XB_DS_PARA 0x0e
  36. #define M5602_XB_TRIG_PARA 0x0f
  37. #define M5602_XB_CLK_PD 0x10
  38. #define M5602_XB_MCU_CLK_CTRL 0x12
  39. #define M5602_XB_MCU_CLK_DIV 0x13
  40. #define M5602_XB_SEN_CLK_CTRL 0x14
  41. #define M5602_XB_SEN_CLK_DIV 0x15
  42. #define M5602_XB_AUD_CLK_CTRL 0x16
  43. #define M5602_XB_AUD_CLK_DIV 0x17
  44. #define M5602_OB_AC_LINK_STATE 0x22
  45. #define M5602_OB_PCM_SLOT_INDEX 0x24
  46. #define M5602_OB_GPIO_SLOT_INDEX 0x25
  47. #define M5602_OB_ACRX_STATUS_ADDRESS_H 0x28
  48. #define M5602_OB_ACRX_STATUS_DATA_L 0x29
  49. #define M5602_OB_ACRX_STATUS_DATA_H 0x2a
  50. #define M5602_OB_ACTX_COMMAND_ADDRESS 0x31
  51. #define M5602_OB_ACRX_COMMAND_DATA_L 0x32
  52. #define M5602_OB_ACTX_COMMAND_DATA_H 0X33
  53. #define M5602_XB_DEVCTR1 0x41
  54. #define M5602_XB_EPSETR0 0x42
  55. #define M5602_XB_EPAFCTR 0x47
  56. #define M5602_XB_EPBFCTR 0x49
  57. #define M5602_XB_EPEFCTR 0x4f
  58. #define M5602_XB_TEST_REG 0x53
  59. #define M5602_XB_ALT2SIZE 0x54
  60. #define M5602_XB_ALT3SIZE 0x55
  61. #define M5602_XB_OBSFRAME 0x56
  62. #define M5602_XB_PWR_CTL 0x59
  63. #define M5602_XB_ADC_CTRL 0x60
  64. #define M5602_XB_ADC_DATA 0x61
  65. #define M5602_XB_MISC_CTRL 0x62
  66. #define M5602_XB_SNAPSHOT 0x63
  67. #define M5602_XB_SCRATCH_1 0x64
  68. #define M5602_XB_SCRATCH_2 0x65
  69. #define M5602_XB_SCRATCH_3 0x66
  70. #define M5602_XB_SCRATCH_4 0x67
  71. #define M5602_XB_I2C_CTRL 0x68
  72. #define M5602_XB_I2C_CLK_DIV 0x69
  73. #define M5602_XB_I2C_DEV_ADDR 0x6a
  74. #define M5602_XB_I2C_REG_ADDR 0x6b
  75. #define M5602_XB_I2C_DATA 0x6c
  76. #define M5602_XB_I2C_STATUS 0x6d
  77. #define M5602_XB_GPIO_DAT_H 0x70
  78. #define M5602_XB_GPIO_DAT_L 0x71
  79. #define M5602_XB_GPIO_DIR_H 0x72
  80. #define M5602_XB_GPIO_DIR_L 0x73
  81. #define M5602_XB_GPIO_EN_H 0x74
  82. #define M5602_XB_GPIO_EN_L 0x75
  83. #define M5602_XB_GPIO_DAT 0x76
  84. #define M5602_XB_GPIO_DIR 0x77
  85. #define M5602_XB_SEN_CLK_CONTROL 0x80
  86. #define M5602_XB_SEN_CLK_DIVISION 0x81
  87. #define M5602_XB_CPR_CLK_CONTROL 0x82
  88. #define M5602_XB_CPR_CLK_DIVISION 0x83
  89. #define M5602_XB_MCU_CLK_CONTROL 0x84
  90. #define M5602_XB_MCU_CLK_DIVISION 0x85
  91. #define M5602_XB_DCT_CLK_CONTROL 0x86
  92. #define M5602_XB_DCT_CLK_DIVISION 0x87
  93. #define M5602_XB_EC_CLK_CONTROL 0x88
  94. #define M5602_XB_EC_CLK_DIVISION 0x89
  95. #define M5602_XB_LBUF_CLK_CONTROL 0x8a
  96. #define M5602_XB_LBUF_CLK_DIVISION 0x8b
  97. #define I2C_BUSY 0x80
  98. /*****************************************************************************/
  99. /* Driver info */
  100. #define DRIVER_AUTHOR "ALi m5602 Linux Driver Project"
  101. #define DRIVER_DESC "ALi m5602 webcam driver"
  102. #define M5602_ISOC_ENDPOINT_ADDR 0x81
  103. #define M5602_INTR_ENDPOINT_ADDR 0x82
  104. #define M5602_URB_MSG_TIMEOUT 5000
  105. /*****************************************************************************/
  106. /* A skeleton used for sending messages to the m5602 bridge */
  107. static const unsigned char bridge_urb_skeleton[] = {
  108. 0x13, 0x00, 0x81, 0x00
  109. };
  110. /* A skeleton used for sending messages to the sensor */
  111. static const unsigned char sensor_urb_skeleton[] = {
  112. 0x23, M5602_XB_GPIO_EN_H, 0x81, 0x06,
  113. 0x23, M5602_XB_MISC_CTRL, 0x81, 0x80,
  114. 0x13, M5602_XB_I2C_DEV_ADDR, 0x81, 0x00,
  115. 0x13, M5602_XB_I2C_REG_ADDR, 0x81, 0x00,
  116. 0x13, M5602_XB_I2C_DATA, 0x81, 0x00,
  117. 0x13, M5602_XB_I2C_CTRL, 0x81, 0x11
  118. };
  119. struct sd {
  120. struct gspca_dev gspca_dev;
  121. /* A pointer to the currently connected sensor */
  122. const struct m5602_sensor *sensor;
  123. /* The current frame's id, used to detect frame boundaries */
  124. u8 frame_id;
  125. /* The current frame count */
  126. u32 frame_count;
  127. /* Camera rotation polling thread for "flipable" cams */
  128. struct task_struct *rotation_thread;
  129. struct { /* auto-white-bal + green/red/blue balance control cluster */
  130. struct v4l2_ctrl *auto_white_bal;
  131. struct v4l2_ctrl *red_bal;
  132. struct v4l2_ctrl *blue_bal;
  133. struct v4l2_ctrl *green_bal;
  134. };
  135. struct { /* autoexpo / expo cluster */
  136. struct v4l2_ctrl *autoexpo;
  137. struct v4l2_ctrl *expo;
  138. };
  139. struct { /* autogain / gain cluster */
  140. struct v4l2_ctrl *autogain;
  141. struct v4l2_ctrl *gain;
  142. };
  143. struct { /* hflip/vflip cluster */
  144. struct v4l2_ctrl *hflip;
  145. struct v4l2_ctrl *vflip;
  146. };
  147. };
  148. int m5602_read_bridge(
  149. struct sd *sd, const u8 address, u8 *i2c_data);
  150. int m5602_write_bridge(
  151. struct sd *sd, const u8 address, const u8 i2c_data);
  152. int m5602_write_sensor(struct sd *sd, const u8 address,
  153. u8 *i2c_data, const u8 len);
  154. int m5602_read_sensor(struct sd *sd, const u8 address,
  155. u8 *i2c_data, const u8 len);
  156. #endif