tm6000-stds.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. /*
  2. * tm6000-stds.c - driver for TM5600/TM6000/TM6010 USB video capture devices
  3. *
  4. * Copyright (C) 2007 Mauro Carvalho Chehab
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation version 2
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19. #include <linux/module.h>
  20. #include <linux/kernel.h>
  21. #include "tm6000.h"
  22. #include "tm6000-regs.h"
  23. static unsigned int tm6010_a_mode;
  24. module_param(tm6010_a_mode, int, 0644);
  25. MODULE_PARM_DESC(tm6010_a_mode, "set tm6010 sif audio mode");
  26. struct tm6000_reg_settings {
  27. unsigned char req;
  28. unsigned char reg;
  29. unsigned char value;
  30. };
  31. struct tm6000_std_settings {
  32. v4l2_std_id id;
  33. struct tm6000_reg_settings *common;
  34. };
  35. static struct tm6000_reg_settings composite_pal_m[] = {
  36. { TM6010_REQ07_R3F_RESET, 0x01 },
  37. { TM6010_REQ07_R00_VIDEO_CONTROL0, 0x04 },
  38. { TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e },
  39. { TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f },
  40. { TM6010_REQ07_R03_YC_SEP_CONTROL, 0x00 },
  41. { TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31 },
  42. { TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e },
  43. { TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x83 },
  44. { TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x0a },
  45. { TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0xe0 },
  46. { TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c },
  47. { TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc },
  48. { TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc },
  49. { TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd },
  50. { TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x88 },
  51. { TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x20 },
  52. { TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0x61 },
  53. { TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x0c },
  54. { TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c },
  55. { TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x52 },
  56. { TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6f },
  57. { TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdc },
  58. { TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07 },
  59. { TM6010_REQ07_R3F_RESET, 0x00 },
  60. { 0, 0, 0 }
  61. };
  62. static struct tm6000_reg_settings composite_pal_nc[] = {
  63. { TM6010_REQ07_R3F_RESET, 0x01 },
  64. { TM6010_REQ07_R00_VIDEO_CONTROL0, 0x36 },
  65. { TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e },
  66. { TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f },
  67. { TM6010_REQ07_R03_YC_SEP_CONTROL, 0x02 },
  68. { TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31 },
  69. { TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e },
  70. { TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x91 },
  71. { TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x1f },
  72. { TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0x0c },
  73. { TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c },
  74. { TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc },
  75. { TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc },
  76. { TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd },
  77. { TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x8c },
  78. { TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x2c },
  79. { TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0xc1 },
  80. { TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x0c },
  81. { TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c },
  82. { TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x52 },
  83. { TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6f },
  84. { TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdc },
  85. { TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07 },
  86. { TM6010_REQ07_R3F_RESET, 0x00 },
  87. { 0, 0, 0 }
  88. };
  89. static struct tm6000_reg_settings composite_pal[] = {
  90. { TM6010_REQ07_R3F_RESET, 0x01 },
  91. { TM6010_REQ07_R00_VIDEO_CONTROL0, 0x32 },
  92. { TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e },
  93. { TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f },
  94. { TM6010_REQ07_R03_YC_SEP_CONTROL, 0x02 },
  95. { TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31 },
  96. { TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x25 },
  97. { TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0xd5 },
  98. { TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x63 },
  99. { TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0x50 },
  100. { TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c },
  101. { TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc },
  102. { TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc },
  103. { TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd },
  104. { TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x8c },
  105. { TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x2c },
  106. { TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0xc1 },
  107. { TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x0c },
  108. { TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c },
  109. { TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x52 },
  110. { TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6f },
  111. { TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdc },
  112. { TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07 },
  113. { TM6010_REQ07_R3F_RESET, 0x00 },
  114. { 0, 0, 0 }
  115. };
  116. static struct tm6000_reg_settings composite_secam[] = {
  117. { TM6010_REQ07_R3F_RESET, 0x01 },
  118. { TM6010_REQ07_R00_VIDEO_CONTROL0, 0x38 },
  119. { TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e },
  120. { TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f },
  121. { TM6010_REQ07_R03_YC_SEP_CONTROL, 0x02 },
  122. { TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31 },
  123. { TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x24 },
  124. { TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x92 },
  125. { TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0xe8 },
  126. { TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0xed },
  127. { TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c },
  128. { TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc },
  129. { TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc },
  130. { TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd },
  131. { TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x8c },
  132. { TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x2c },
  133. { TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0xc1 },
  134. { TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x2c },
  135. { TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x18 },
  136. { TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x42 },
  137. { TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0xff },
  138. { TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07 },
  139. { TM6010_REQ07_R3F_RESET, 0x00 },
  140. { 0, 0, 0 }
  141. };
  142. static struct tm6000_reg_settings composite_ntsc[] = {
  143. { TM6010_REQ07_R3F_RESET, 0x01 },
  144. { TM6010_REQ07_R00_VIDEO_CONTROL0, 0x00 },
  145. { TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0f },
  146. { TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f },
  147. { TM6010_REQ07_R03_YC_SEP_CONTROL, 0x00 },
  148. { TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31 },
  149. { TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e },
  150. { TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x8b },
  151. { TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0xa2 },
  152. { TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0xe9 },
  153. { TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c },
  154. { TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc },
  155. { TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc },
  156. { TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd },
  157. { TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x88 },
  158. { TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x22 },
  159. { TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0x61 },
  160. { TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x1c },
  161. { TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c },
  162. { TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x42 },
  163. { TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6f },
  164. { TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdd },
  165. { TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07 },
  166. { TM6010_REQ07_R3F_RESET, 0x00 },
  167. { 0, 0, 0 }
  168. };
  169. static struct tm6000_std_settings composite_stds[] = {
  170. { .id = V4L2_STD_PAL_M, .common = composite_pal_m, },
  171. { .id = V4L2_STD_PAL_Nc, .common = composite_pal_nc, },
  172. { .id = V4L2_STD_PAL, .common = composite_pal, },
  173. { .id = V4L2_STD_SECAM, .common = composite_secam, },
  174. { .id = V4L2_STD_NTSC, .common = composite_ntsc, },
  175. };
  176. static struct tm6000_reg_settings svideo_pal_m[] = {
  177. { TM6010_REQ07_R3F_RESET, 0x01 },
  178. { TM6010_REQ07_R00_VIDEO_CONTROL0, 0x05 },
  179. { TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e },
  180. { TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f },
  181. { TM6010_REQ07_R03_YC_SEP_CONTROL, 0x04 },
  182. { TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31 },
  183. { TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e },
  184. { TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x83 },
  185. { TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x0a },
  186. { TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0xe0 },
  187. { TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c },
  188. { TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc },
  189. { TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc },
  190. { TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd },
  191. { TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x88 },
  192. { TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x22 },
  193. { TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0x61 },
  194. { TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x0c },
  195. { TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c },
  196. { TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x52 },
  197. { TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6f },
  198. { TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdc },
  199. { TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07 },
  200. { TM6010_REQ07_R3F_RESET, 0x00 },
  201. { 0, 0, 0 }
  202. };
  203. static struct tm6000_reg_settings svideo_pal_nc[] = {
  204. { TM6010_REQ07_R3F_RESET, 0x01 },
  205. { TM6010_REQ07_R00_VIDEO_CONTROL0, 0x37 },
  206. { TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e },
  207. { TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f },
  208. { TM6010_REQ07_R03_YC_SEP_CONTROL, 0x04 },
  209. { TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31 },
  210. { TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e },
  211. { TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x91 },
  212. { TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x1f },
  213. { TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0x0c },
  214. { TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c },
  215. { TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc },
  216. { TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc },
  217. { TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd },
  218. { TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x88 },
  219. { TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x22 },
  220. { TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0xc1 },
  221. { TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x0c },
  222. { TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c },
  223. { TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x52 },
  224. { TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6f },
  225. { TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdc },
  226. { TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07 },
  227. { TM6010_REQ07_R3F_RESET, 0x00 },
  228. { 0, 0, 0 }
  229. };
  230. static struct tm6000_reg_settings svideo_pal[] = {
  231. { TM6010_REQ07_R3F_RESET, 0x01 },
  232. { TM6010_REQ07_R00_VIDEO_CONTROL0, 0x33 },
  233. { TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e },
  234. { TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f },
  235. { TM6010_REQ07_R03_YC_SEP_CONTROL, 0x04 },
  236. { TM6010_REQ07_R07_OUTPUT_CONTROL, 0x30 },
  237. { TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x25 },
  238. { TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0xd5 },
  239. { TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x63 },
  240. { TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0x50 },
  241. { TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c },
  242. { TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc },
  243. { TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc },
  244. { TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd },
  245. { TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x8c },
  246. { TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x2a },
  247. { TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0xc1 },
  248. { TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x0c },
  249. { TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c },
  250. { TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x52 },
  251. { TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6f },
  252. { TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdc },
  253. { TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07 },
  254. { TM6010_REQ07_R3F_RESET, 0x00 },
  255. { 0, 0, 0 }
  256. };
  257. static struct tm6000_reg_settings svideo_secam[] = {
  258. { TM6010_REQ07_R3F_RESET, 0x01 },
  259. { TM6010_REQ07_R00_VIDEO_CONTROL0, 0x39 },
  260. { TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e },
  261. { TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f },
  262. { TM6010_REQ07_R03_YC_SEP_CONTROL, 0x03 },
  263. { TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31 },
  264. { TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x24 },
  265. { TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x92 },
  266. { TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0xe8 },
  267. { TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0xed },
  268. { TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c },
  269. { TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc },
  270. { TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc },
  271. { TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd },
  272. { TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x8c },
  273. { TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x2a },
  274. { TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0xc1 },
  275. { TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x2c },
  276. { TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x18 },
  277. { TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x42 },
  278. { TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0xff },
  279. { TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07 },
  280. { TM6010_REQ07_R3F_RESET, 0x00 },
  281. { 0, 0, 0 }
  282. };
  283. static struct tm6000_reg_settings svideo_ntsc[] = {
  284. { TM6010_REQ07_R3F_RESET, 0x01 },
  285. { TM6010_REQ07_R00_VIDEO_CONTROL0, 0x01 },
  286. { TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0f },
  287. { TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f },
  288. { TM6010_REQ07_R03_YC_SEP_CONTROL, 0x03 },
  289. { TM6010_REQ07_R07_OUTPUT_CONTROL, 0x30 },
  290. { TM6010_REQ07_R17_HLOOP_MAXSTATE, 0x8b },
  291. { TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e },
  292. { TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x8b },
  293. { TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0xa2 },
  294. { TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0xe9 },
  295. { TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c },
  296. { TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc },
  297. { TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc },
  298. { TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd },
  299. { TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x88 },
  300. { TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x22 },
  301. { TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0x61 },
  302. { TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x1c },
  303. { TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c },
  304. { TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x42 },
  305. { TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6f },
  306. { TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdd },
  307. { TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07 },
  308. { TM6010_REQ07_R3F_RESET, 0x00 },
  309. { 0, 0, 0 }
  310. };
  311. static struct tm6000_std_settings svideo_stds[] = {
  312. { .id = V4L2_STD_PAL_M, .common = svideo_pal_m, },
  313. { .id = V4L2_STD_PAL_Nc, .common = svideo_pal_nc, },
  314. { .id = V4L2_STD_PAL, .common = svideo_pal, },
  315. { .id = V4L2_STD_SECAM, .common = svideo_secam, },
  316. { .id = V4L2_STD_NTSC, .common = svideo_ntsc, },
  317. };
  318. static int tm6000_set_audio_std(struct tm6000_core *dev)
  319. {
  320. uint8_t areg_02 = 0x04; /* GC1 Fixed gain 0dB */
  321. uint8_t areg_05 = 0x01; /* Auto 4.5 = M Japan, Auto 6.5 = DK */
  322. uint8_t areg_06 = 0x02; /* Auto de-emphasis, mannual channel mode */
  323. if (dev->radio) {
  324. tm6000_set_reg(dev, TM6010_REQ08_R01_A_INIT, 0x00);
  325. tm6000_set_reg(dev, TM6010_REQ08_R02_A_FIX_GAIN_CTRL, 0x04);
  326. tm6000_set_reg(dev, TM6010_REQ08_R03_A_AUTO_GAIN_CTRL, 0x00);
  327. tm6000_set_reg(dev, TM6010_REQ08_R04_A_SIF_AMP_CTRL, 0x80);
  328. tm6000_set_reg(dev, TM6010_REQ08_R05_A_STANDARD_MOD, 0x0c);
  329. /* set mono or stereo */
  330. if (dev->amode == V4L2_TUNER_MODE_MONO)
  331. tm6000_set_reg(dev, TM6010_REQ08_R06_A_SOUND_MOD, 0x00);
  332. else if (dev->amode == V4L2_TUNER_MODE_STEREO)
  333. tm6000_set_reg(dev, TM6010_REQ08_R06_A_SOUND_MOD, 0x02);
  334. tm6000_set_reg(dev, TM6010_REQ08_R09_A_MAIN_VOL, 0x18);
  335. tm6000_set_reg(dev, TM6010_REQ08_R0C_A_ASD_THRES2, 0x0a);
  336. tm6000_set_reg(dev, TM6010_REQ08_R0D_A_AMD_THRES, 0x40);
  337. tm6000_set_reg(dev, TM6010_REQ08_RF1_AADC_POWER_DOWN, 0xfe);
  338. tm6000_set_reg(dev, TM6010_REQ08_R1E_A_GAIN_DEEMPH_OUT, 0x13);
  339. tm6000_set_reg(dev, TM6010_REQ08_R01_A_INIT, 0x80);
  340. tm6000_set_reg(dev, TM6010_REQ07_RFE_POWER_DOWN, 0xff);
  341. return 0;
  342. }
  343. /*
  344. * STD/MN shouldn't be affected by tm6010_a_mode, as there's just one
  345. * audio standard for each V4L2_STD type.
  346. */
  347. if ((dev->norm & V4L2_STD_NTSC) == V4L2_STD_NTSC_M_KR) {
  348. areg_05 |= 0x04;
  349. } else if ((dev->norm & V4L2_STD_NTSC) == V4L2_STD_NTSC_M_JP) {
  350. areg_05 |= 0x43;
  351. } else if (dev->norm & V4L2_STD_MN) {
  352. areg_05 |= 0x22;
  353. } else switch (tm6010_a_mode) {
  354. /* auto */
  355. case 0:
  356. if ((dev->norm & V4L2_STD_SECAM) == V4L2_STD_SECAM_L)
  357. areg_05 |= 0x00;
  358. else /* Other PAL/SECAM standards */
  359. areg_05 |= 0x10;
  360. break;
  361. /* A2 */
  362. case 1:
  363. if (dev->norm & V4L2_STD_DK)
  364. areg_05 = 0x09;
  365. else
  366. areg_05 = 0x05;
  367. break;
  368. /* NICAM */
  369. case 2:
  370. if (dev->norm & V4L2_STD_DK) {
  371. areg_05 = 0x06;
  372. } else if (dev->norm & V4L2_STD_PAL_I) {
  373. areg_05 = 0x08;
  374. } else if (dev->norm & V4L2_STD_SECAM_L) {
  375. areg_05 = 0x0a;
  376. areg_02 = 0x02;
  377. } else {
  378. areg_05 = 0x07;
  379. }
  380. break;
  381. /* other */
  382. case 3:
  383. if (dev->norm & V4L2_STD_DK) {
  384. areg_05 = 0x0b;
  385. } else {
  386. areg_05 = 0x02;
  387. }
  388. break;
  389. }
  390. tm6000_set_reg(dev, TM6010_REQ08_R01_A_INIT, 0x00);
  391. tm6000_set_reg(dev, TM6010_REQ08_R02_A_FIX_GAIN_CTRL, areg_02);
  392. tm6000_set_reg(dev, TM6010_REQ08_R03_A_AUTO_GAIN_CTRL, 0x00);
  393. tm6000_set_reg(dev, TM6010_REQ08_R04_A_SIF_AMP_CTRL, 0xa0);
  394. tm6000_set_reg(dev, TM6010_REQ08_R05_A_STANDARD_MOD, areg_05);
  395. tm6000_set_reg(dev, TM6010_REQ08_R06_A_SOUND_MOD, areg_06);
  396. tm6000_set_reg(dev, TM6010_REQ08_R07_A_LEFT_VOL, 0x00);
  397. tm6000_set_reg(dev, TM6010_REQ08_R08_A_RIGHT_VOL, 0x00);
  398. tm6000_set_reg(dev, TM6010_REQ08_R09_A_MAIN_VOL, 0x08);
  399. tm6000_set_reg(dev, TM6010_REQ08_R0A_A_I2S_MOD, 0x91);
  400. tm6000_set_reg(dev, TM6010_REQ08_R0B_A_ASD_THRES1, 0x20);
  401. tm6000_set_reg(dev, TM6010_REQ08_R0C_A_ASD_THRES2, 0x12);
  402. tm6000_set_reg(dev, TM6010_REQ08_R0D_A_AMD_THRES, 0x20);
  403. tm6000_set_reg(dev, TM6010_REQ08_R0E_A_MONO_THRES1, 0xf0);
  404. tm6000_set_reg(dev, TM6010_REQ08_R0F_A_MONO_THRES2, 0x80);
  405. tm6000_set_reg(dev, TM6010_REQ08_R10_A_MUTE_THRES1, 0xc0);
  406. tm6000_set_reg(dev, TM6010_REQ08_R11_A_MUTE_THRES2, 0x80);
  407. tm6000_set_reg(dev, TM6010_REQ08_R12_A_AGC_U, 0x12);
  408. tm6000_set_reg(dev, TM6010_REQ08_R13_A_AGC_ERR_T, 0xfe);
  409. tm6000_set_reg(dev, TM6010_REQ08_R14_A_AGC_GAIN_INIT, 0x20);
  410. tm6000_set_reg(dev, TM6010_REQ08_R15_A_AGC_STEP_THR, 0x14);
  411. tm6000_set_reg(dev, TM6010_REQ08_R16_A_AGC_GAIN_MAX, 0xfe);
  412. tm6000_set_reg(dev, TM6010_REQ08_R17_A_AGC_GAIN_MIN, 0x01);
  413. tm6000_set_reg(dev, TM6010_REQ08_R18_A_TR_CTRL, 0xa0);
  414. tm6000_set_reg(dev, TM6010_REQ08_R19_A_FH_2FH_GAIN, 0x32);
  415. tm6000_set_reg(dev, TM6010_REQ08_R1A_A_NICAM_SER_MAX, 0x64);
  416. tm6000_set_reg(dev, TM6010_REQ08_R1B_A_NICAM_SER_MIN, 0x20);
  417. tm6000_set_reg(dev, REQ_08_SET_GET_AVREG_BIT, 0x1c, 0x00);
  418. tm6000_set_reg(dev, REQ_08_SET_GET_AVREG_BIT, 0x1d, 0x00);
  419. tm6000_set_reg(dev, TM6010_REQ08_R1E_A_GAIN_DEEMPH_OUT, 0x13);
  420. tm6000_set_reg(dev, TM6010_REQ08_R1F_A_TEST_INTF_SEL, 0x00);
  421. tm6000_set_reg(dev, TM6010_REQ08_R20_A_TEST_PIN_SEL, 0x00);
  422. tm6000_set_reg(dev, TM6010_REQ08_R01_A_INIT, 0x80);
  423. return 0;
  424. }
  425. void tm6000_get_std_res(struct tm6000_core *dev)
  426. {
  427. /* Currently, those are the only supported resoltions */
  428. if (dev->norm & V4L2_STD_525_60)
  429. dev->height = 480;
  430. else
  431. dev->height = 576;
  432. dev->width = 720;
  433. }
  434. static int tm6000_load_std(struct tm6000_core *dev, struct tm6000_reg_settings *set)
  435. {
  436. int i, rc;
  437. /* Load board's initialization table */
  438. for (i = 0; set[i].req; i++) {
  439. rc = tm6000_set_reg(dev, set[i].req, set[i].reg, set[i].value);
  440. if (rc < 0) {
  441. printk(KERN_ERR "Error %i while setting "
  442. "req %d, reg %d to value %d\n",
  443. rc, set[i].req, set[i].reg, set[i].value);
  444. return rc;
  445. }
  446. }
  447. return 0;
  448. }
  449. int tm6000_set_standard(struct tm6000_core *dev)
  450. {
  451. struct tm6000_input *input;
  452. int i, rc = 0;
  453. u8 reg_07_fe = 0x8a;
  454. u8 reg_08_f1 = 0xfc;
  455. u8 reg_08_e2 = 0xf0;
  456. u8 reg_08_e6 = 0x0f;
  457. tm6000_get_std_res(dev);
  458. if (!dev->radio)
  459. input = &dev->vinput[dev->input];
  460. else
  461. input = &dev->rinput;
  462. if (dev->dev_type == TM6010) {
  463. switch (input->vmux) {
  464. case TM6000_VMUX_VIDEO_A:
  465. tm6000_set_reg(dev, TM6010_REQ08_RE3_ADC_IN1_SEL, 0xf4);
  466. tm6000_set_reg(dev, TM6010_REQ08_REA_BUFF_DRV_CTRL, 0xf1);
  467. tm6000_set_reg(dev, TM6010_REQ08_REB_SIF_GAIN_CTRL, 0xe0);
  468. tm6000_set_reg(dev, TM6010_REQ08_REC_REVERSE_YC_CTRL, 0xc2);
  469. tm6000_set_reg(dev, TM6010_REQ08_RED_GAIN_SEL, 0xe8);
  470. reg_07_fe |= 0x01;
  471. break;
  472. case TM6000_VMUX_VIDEO_B:
  473. tm6000_set_reg(dev, TM6010_REQ08_RE3_ADC_IN1_SEL, 0xf8);
  474. tm6000_set_reg(dev, TM6010_REQ08_REA_BUFF_DRV_CTRL, 0xf1);
  475. tm6000_set_reg(dev, TM6010_REQ08_REB_SIF_GAIN_CTRL, 0xe0);
  476. tm6000_set_reg(dev, TM6010_REQ08_REC_REVERSE_YC_CTRL, 0xc2);
  477. tm6000_set_reg(dev, TM6010_REQ08_RED_GAIN_SEL, 0xe8);
  478. reg_07_fe |= 0x01;
  479. break;
  480. case TM6000_VMUX_VIDEO_AB:
  481. tm6000_set_reg(dev, TM6010_REQ08_RE3_ADC_IN1_SEL, 0xfc);
  482. tm6000_set_reg(dev, TM6010_REQ08_RE4_ADC_IN2_SEL, 0xf8);
  483. reg_08_e6 = 0x00;
  484. tm6000_set_reg(dev, TM6010_REQ08_REA_BUFF_DRV_CTRL, 0xf2);
  485. tm6000_set_reg(dev, TM6010_REQ08_REB_SIF_GAIN_CTRL, 0xf0);
  486. tm6000_set_reg(dev, TM6010_REQ08_REC_REVERSE_YC_CTRL, 0xc2);
  487. tm6000_set_reg(dev, TM6010_REQ08_RED_GAIN_SEL, 0xe0);
  488. break;
  489. default:
  490. break;
  491. }
  492. switch (input->amux) {
  493. case TM6000_AMUX_ADC1:
  494. tm6000_set_reg_mask(dev, TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG,
  495. 0x00, 0x0f);
  496. /* Mux overflow workaround */
  497. tm6000_set_reg_mask(dev, TM6010_REQ07_R07_OUTPUT_CONTROL,
  498. 0x10, 0xf0);
  499. break;
  500. case TM6000_AMUX_ADC2:
  501. tm6000_set_reg_mask(dev, TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG,
  502. 0x08, 0x0f);
  503. /* Mux overflow workaround */
  504. tm6000_set_reg_mask(dev, TM6010_REQ07_R07_OUTPUT_CONTROL,
  505. 0x10, 0xf0);
  506. break;
  507. case TM6000_AMUX_SIF1:
  508. reg_08_e2 |= 0x02;
  509. reg_08_e6 = 0x08;
  510. reg_07_fe |= 0x40;
  511. reg_08_f1 |= 0x02;
  512. tm6000_set_reg(dev, TM6010_REQ08_RE4_ADC_IN2_SEL, 0xf3);
  513. tm6000_set_reg_mask(dev, TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG,
  514. 0x02, 0x0f);
  515. /* Mux overflow workaround */
  516. tm6000_set_reg_mask(dev, TM6010_REQ07_R07_OUTPUT_CONTROL,
  517. 0x30, 0xf0);
  518. break;
  519. case TM6000_AMUX_SIF2:
  520. reg_08_e2 |= 0x02;
  521. reg_08_e6 = 0x08;
  522. reg_07_fe |= 0x40;
  523. reg_08_f1 |= 0x02;
  524. tm6000_set_reg(dev, TM6010_REQ08_RE4_ADC_IN2_SEL, 0xf7);
  525. tm6000_set_reg_mask(dev, TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG,
  526. 0x02, 0x0f);
  527. /* Mux overflow workaround */
  528. tm6000_set_reg_mask(dev, TM6010_REQ07_R07_OUTPUT_CONTROL,
  529. 0x30, 0xf0);
  530. break;
  531. default:
  532. break;
  533. }
  534. tm6000_set_reg(dev, TM6010_REQ08_RE2_POWER_DOWN_CTRL1, reg_08_e2);
  535. tm6000_set_reg(dev, TM6010_REQ08_RE6_POWER_DOWN_CTRL2, reg_08_e6);
  536. tm6000_set_reg(dev, TM6010_REQ08_RF1_AADC_POWER_DOWN, reg_08_f1);
  537. tm6000_set_reg(dev, TM6010_REQ07_RFE_POWER_DOWN, reg_07_fe);
  538. } else {
  539. switch (input->vmux) {
  540. case TM6000_VMUX_VIDEO_A:
  541. tm6000_set_reg(dev, TM6000_REQ07_RE3_VADC_INP_LPF_SEL1, 0x10);
  542. tm6000_set_reg(dev, TM6000_REQ07_RE5_VADC_INP_LPF_SEL2, 0x00);
  543. tm6000_set_reg(dev, TM6000_REQ07_RE8_VADC_PWDOWN_CTL, 0x0f);
  544. tm6000_set_reg(dev,
  545. REQ_03_SET_GET_MCU_PIN, input->v_gpio, 0);
  546. break;
  547. case TM6000_VMUX_VIDEO_B:
  548. tm6000_set_reg(dev, TM6000_REQ07_RE3_VADC_INP_LPF_SEL1, 0x00);
  549. tm6000_set_reg(dev, TM6000_REQ07_RE5_VADC_INP_LPF_SEL2, 0x00);
  550. tm6000_set_reg(dev, TM6000_REQ07_RE8_VADC_PWDOWN_CTL, 0x0f);
  551. tm6000_set_reg(dev,
  552. REQ_03_SET_GET_MCU_PIN, input->v_gpio, 0);
  553. break;
  554. case TM6000_VMUX_VIDEO_AB:
  555. tm6000_set_reg(dev, TM6000_REQ07_RE3_VADC_INP_LPF_SEL1, 0x10);
  556. tm6000_set_reg(dev, TM6000_REQ07_RE5_VADC_INP_LPF_SEL2, 0x10);
  557. tm6000_set_reg(dev, TM6000_REQ07_RE8_VADC_PWDOWN_CTL, 0x00);
  558. tm6000_set_reg(dev,
  559. REQ_03_SET_GET_MCU_PIN, input->v_gpio, 1);
  560. break;
  561. default:
  562. break;
  563. }
  564. switch (input->amux) {
  565. case TM6000_AMUX_ADC1:
  566. tm6000_set_reg_mask(dev,
  567. TM6000_REQ07_REB_VADC_AADC_MODE, 0x00, 0x0f);
  568. break;
  569. case TM6000_AMUX_ADC2:
  570. tm6000_set_reg_mask(dev,
  571. TM6000_REQ07_REB_VADC_AADC_MODE, 0x04, 0x0f);
  572. break;
  573. default:
  574. break;
  575. }
  576. }
  577. if (input->type == TM6000_INPUT_SVIDEO) {
  578. for (i = 0; i < ARRAY_SIZE(svideo_stds); i++) {
  579. if (dev->norm & svideo_stds[i].id) {
  580. rc = tm6000_load_std(dev, svideo_stds[i].common);
  581. goto ret;
  582. }
  583. }
  584. return -EINVAL;
  585. } else {
  586. for (i = 0; i < ARRAY_SIZE(composite_stds); i++) {
  587. if (dev->norm & composite_stds[i].id) {
  588. rc = tm6000_load_std(dev, composite_stds[i].common);
  589. goto ret;
  590. }
  591. }
  592. return -EINVAL;
  593. }
  594. ret:
  595. if (rc < 0)
  596. return rc;
  597. if ((dev->dev_type == TM6010) &&
  598. ((input->amux == TM6000_AMUX_SIF1) ||
  599. (input->amux == TM6000_AMUX_SIF2)))
  600. tm6000_set_audio_std(dev);
  601. msleep(40);
  602. return 0;
  603. }