m5602_s5k4aa.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /*
  2. * Driver for the s5k4aa sensor
  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_S5K4AA_H_
  19. #define M5602_S5K4AA_H_
  20. #include <linux/dmi.h>
  21. #include "m5602_sensor.h"
  22. /*****************************************************************************/
  23. #define S5K4AA_PAGE_MAP 0xec
  24. #define S5K4AA_PAGE_MAP_0 0x00
  25. #define S5K4AA_PAGE_MAP_1 0x01
  26. #define S5K4AA_PAGE_MAP_2 0x02
  27. /* Sensor register definitions for page 0x02 */
  28. #define S5K4AA_READ_MODE 0x03
  29. #define S5K4AA_ROWSTART_HI 0x04
  30. #define S5K4AA_ROWSTART_LO 0x05
  31. #define S5K4AA_COLSTART_HI 0x06
  32. #define S5K4AA_COLSTART_LO 0x07
  33. #define S5K4AA_WINDOW_HEIGHT_HI 0x08
  34. #define S5K4AA_WINDOW_HEIGHT_LO 0x09
  35. #define S5K4AA_WINDOW_WIDTH_HI 0x0a
  36. #define S5K4AA_WINDOW_WIDTH_LO 0x0b
  37. #define S5K4AA_GLOBAL_GAIN__ 0x0f
  38. /* sync lost, if too low, reduces frame rate if too high */
  39. #define S5K4AA_H_BLANK_HI__ 0x1d
  40. #define S5K4AA_H_BLANK_LO__ 0x1e
  41. #define S5K4AA_EXPOSURE_HI 0x17
  42. #define S5K4AA_EXPOSURE_LO 0x18
  43. #define S5K4AA_BRIGHTNESS 0x1f /* (digital?) gain : 5 bits */
  44. #define S5K4AA_GAIN 0x20 /* (analogue?) gain : 7 bits */
  45. #define S5K4AA_NOISE_SUPP 0x37
  46. #define S5K4AA_RM_ROW_SKIP_4X 0x08
  47. #define S5K4AA_RM_ROW_SKIP_2X 0x04
  48. #define S5K4AA_RM_COL_SKIP_4X 0x02
  49. #define S5K4AA_RM_COL_SKIP_2X 0x01
  50. #define S5K4AA_RM_H_FLIP 0x40
  51. #define S5K4AA_RM_V_FLIP 0x80
  52. #define S5K4AA_DEFAULT_GAIN 0x5f
  53. #define S5K4AA_DEFAULT_BRIGHTNESS 0x10
  54. /*****************************************************************************/
  55. /* Kernel module parameters */
  56. extern int force_sensor;
  57. extern bool dump_sensor;
  58. int s5k4aa_probe(struct sd *sd);
  59. int s5k4aa_init(struct sd *sd);
  60. int s5k4aa_init_controls(struct sd *sd);
  61. int s5k4aa_start(struct sd *sd);
  62. void s5k4aa_disconnect(struct sd *sd);
  63. static const struct m5602_sensor s5k4aa = {
  64. .name = "S5K4AA",
  65. .i2c_slave_id = 0x5a,
  66. .i2c_regW = 2,
  67. .probe = s5k4aa_probe,
  68. .init = s5k4aa_init,
  69. .init_controls = s5k4aa_init_controls,
  70. .start = s5k4aa_start,
  71. .disconnect = s5k4aa_disconnect,
  72. };
  73. static const unsigned char preinit_s5k4aa[][4] = {
  74. {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
  75. {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
  76. {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
  77. {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
  78. {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
  79. {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0d, 0x00},
  80. {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00, 0x00},
  81. {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
  82. {BRIDGE, M5602_XB_GPIO_DAT, 0x08, 0x00},
  83. {BRIDGE, M5602_XB_SEN_CLK_DIV, 0xb0, 0x00},
  84. {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0x80, 0x00},
  85. {BRIDGE, M5602_XB_GPIO_EN_H, 0x3f, 0x00},
  86. {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3f, 0x00},
  87. {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
  88. {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
  89. {BRIDGE, M5602_XB_GPIO_DAT, 0x00, 0x00},
  90. {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
  91. {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
  92. {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
  93. {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
  94. {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
  95. {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
  96. {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08, 0x00},
  97. {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
  98. {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
  99. {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
  100. {BRIDGE, M5602_XB_GPIO_DAT, 0x14, 0x00},
  101. {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
  102. {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xf0, 0x00},
  103. {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
  104. {BRIDGE, M5602_XB_GPIO_DAT, 0x1c, 0x00},
  105. {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
  106. {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06, 0x00},
  107. {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
  108. {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
  109. {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x20, 0x00},
  110. {SENSOR, S5K4AA_PAGE_MAP, 0x00, 0x00}
  111. };
  112. static const unsigned char init_s5k4aa[][4] = {
  113. {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
  114. {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
  115. {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
  116. {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
  117. {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
  118. {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0d, 0x00},
  119. {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00, 0x00},
  120. {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
  121. {BRIDGE, M5602_XB_GPIO_DAT, 0x08, 0x00},
  122. {BRIDGE, M5602_XB_SEN_CLK_DIV, 0xb0, 0x00},
  123. {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0x80, 0x00},
  124. {BRIDGE, M5602_XB_GPIO_EN_H, 0x3f, 0x00},
  125. {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3f, 0x00},
  126. {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
  127. {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
  128. {BRIDGE, M5602_XB_GPIO_DAT, 0x00, 0x00},
  129. {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
  130. {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
  131. {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
  132. {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
  133. {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
  134. {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
  135. {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08, 0x00},
  136. {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
  137. {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
  138. {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
  139. {BRIDGE, M5602_XB_GPIO_DAT, 0x14, 0x00},
  140. {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
  141. {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xf0, 0x00},
  142. {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
  143. {BRIDGE, M5602_XB_GPIO_DAT, 0x1c, 0x00},
  144. {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
  145. {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06, 0x00},
  146. {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
  147. {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
  148. {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x20, 0x00},
  149. {SENSOR, S5K4AA_PAGE_MAP, 0x07, 0x00},
  150. {SENSOR, 0x36, 0x01, 0x00},
  151. {SENSOR, S5K4AA_PAGE_MAP, 0x00, 0x00},
  152. {SENSOR, 0x7b, 0xff, 0x00},
  153. {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
  154. {SENSOR, 0x0c, 0x05, 0x00},
  155. {SENSOR, 0x02, 0x0e, 0x00},
  156. {SENSOR, S5K4AA_READ_MODE, 0xa0, 0x00},
  157. {SENSOR, 0x37, 0x00, 0x00},
  158. };
  159. static const unsigned char VGA_s5k4aa[][4] = {
  160. {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 0x00},
  161. {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
  162. {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
  163. {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08, 0x00},
  164. {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00},
  165. {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00},
  166. {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00},
  167. {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
  168. {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
  169. {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
  170. {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
  171. /* VSYNC_PARA, VSYNC_PARA : img height 480 = 0x01e0 */
  172. {BRIDGE, M5602_XB_VSYNC_PARA, 0x01, 0x00},
  173. {BRIDGE, M5602_XB_VSYNC_PARA, 0xe0, 0x00},
  174. {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
  175. {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
  176. {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
  177. {BRIDGE, M5602_XB_SIG_INI, 0x02, 0x00},
  178. {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
  179. {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
  180. /* HSYNC_PARA, HSYNC_PARA : img width 640 = 0x0280 */
  181. {BRIDGE, M5602_XB_HSYNC_PARA, 0x02, 0x00},
  182. {BRIDGE, M5602_XB_HSYNC_PARA, 0x80, 0x00},
  183. {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
  184. {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
  185. {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xa0, 0x00}, /* 48 MHz */
  186. {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
  187. {SENSOR, S5K4AA_READ_MODE, S5K4AA_RM_H_FLIP | S5K4AA_RM_ROW_SKIP_2X
  188. | S5K4AA_RM_COL_SKIP_2X, 0x00},
  189. /* 0x37 : Fix image stability when light is too bright and improves
  190. * image quality in 640x480, but worsens it in 1280x1024 */
  191. {SENSOR, 0x37, 0x01, 0x00},
  192. /* ROWSTART_HI, ROWSTART_LO : 10 + (1024-960)/2 = 42 = 0x002a */
  193. {SENSOR, S5K4AA_ROWSTART_HI, 0x00, 0x00},
  194. {SENSOR, S5K4AA_ROWSTART_LO, 0x29, 0x00},
  195. {SENSOR, S5K4AA_COLSTART_HI, 0x00, 0x00},
  196. {SENSOR, S5K4AA_COLSTART_LO, 0x0c, 0x00},
  197. /* window_height_hi, window_height_lo : 960 = 0x03c0 */
  198. {SENSOR, S5K4AA_WINDOW_HEIGHT_HI, 0x03, 0x00},
  199. {SENSOR, S5K4AA_WINDOW_HEIGHT_LO, 0xc0, 0x00},
  200. /* window_width_hi, window_width_lo : 1280 = 0x0500 */
  201. {SENSOR, S5K4AA_WINDOW_WIDTH_HI, 0x05, 0x00},
  202. {SENSOR, S5K4AA_WINDOW_WIDTH_LO, 0x00, 0x00},
  203. {SENSOR, S5K4AA_H_BLANK_HI__, 0x00, 0x00},
  204. {SENSOR, S5K4AA_H_BLANK_LO__, 0xa8, 0x00}, /* helps to sync... */
  205. {SENSOR, S5K4AA_EXPOSURE_HI, 0x01, 0x00},
  206. {SENSOR, S5K4AA_EXPOSURE_LO, 0x00, 0x00},
  207. {SENSOR, 0x11, 0x04, 0x00},
  208. {SENSOR, 0x12, 0xc3, 0x00},
  209. {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
  210. {SENSOR, 0x02, 0x0e, 0x00},
  211. };
  212. static const unsigned char SXGA_s5k4aa[][4] = {
  213. {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 0x00},
  214. {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
  215. {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
  216. {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08, 0x00},
  217. {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00},
  218. {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00},
  219. {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00},
  220. {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
  221. {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
  222. {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
  223. {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
  224. /* VSYNC_PARA, VSYNC_PARA : img height 1024 = 0x0400 */
  225. {BRIDGE, M5602_XB_VSYNC_PARA, 0x04, 0x00},
  226. {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
  227. {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
  228. {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
  229. {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
  230. {BRIDGE, M5602_XB_SIG_INI, 0x02, 0x00},
  231. {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
  232. {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
  233. /* HSYNC_PARA, HSYNC_PARA : img width 1280 = 0x0500 */
  234. {BRIDGE, M5602_XB_HSYNC_PARA, 0x05, 0x00},
  235. {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
  236. {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
  237. {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
  238. {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xa0, 0x00}, /* 48 MHz */
  239. {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
  240. {SENSOR, S5K4AA_READ_MODE, S5K4AA_RM_H_FLIP, 0x00},
  241. {SENSOR, 0x37, 0x01, 0x00},
  242. {SENSOR, S5K4AA_ROWSTART_HI, 0x00, 0x00},
  243. {SENSOR, S5K4AA_ROWSTART_LO, 0x09, 0x00},
  244. {SENSOR, S5K4AA_COLSTART_HI, 0x00, 0x00},
  245. {SENSOR, S5K4AA_COLSTART_LO, 0x0a, 0x00},
  246. {SENSOR, S5K4AA_WINDOW_HEIGHT_HI, 0x04, 0x00},
  247. {SENSOR, S5K4AA_WINDOW_HEIGHT_LO, 0x00, 0x00},
  248. {SENSOR, S5K4AA_WINDOW_WIDTH_HI, 0x05, 0x00},
  249. {SENSOR, S5K4AA_WINDOW_WIDTH_LO, 0x00, 0x00},
  250. {SENSOR, S5K4AA_H_BLANK_HI__, 0x01, 0x00},
  251. {SENSOR, S5K4AA_H_BLANK_LO__, 0xa8, 0x00},
  252. {SENSOR, S5K4AA_EXPOSURE_HI, 0x01, 0x00},
  253. {SENSOR, S5K4AA_EXPOSURE_LO, 0x00, 0x00},
  254. {SENSOR, 0x11, 0x04, 0x00},
  255. {SENSOR, 0x12, 0xc3, 0x00},
  256. {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
  257. {SENSOR, 0x02, 0x0e, 0x00},
  258. };
  259. #endif