tw28.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  1. /*
  2. * Copyright (C) 2010 Bluecherry, LLC www.bluecherrydvr.com
  3. * Copyright (C) 2010 Ben Collins <bcollins@bluecherry.net>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. #include <linux/kernel.h>
  20. #include "solo6x10.h"
  21. #include "tw28.h"
  22. /* XXX: Some of these values are masked into an 8-bit regs, and shifted
  23. * around for other 8-bit regs. What are the magic bits in these values? */
  24. #define DEFAULT_HDELAY_NTSC (32 - 4)
  25. #define DEFAULT_HACTIVE_NTSC (720 + 16)
  26. #define DEFAULT_VDELAY_NTSC (7 - 2)
  27. #define DEFAULT_VACTIVE_NTSC (240 + 4)
  28. #define DEFAULT_HDELAY_PAL (32 + 4)
  29. #define DEFAULT_HACTIVE_PAL (864-DEFAULT_HDELAY_PAL)
  30. #define DEFAULT_VDELAY_PAL (6)
  31. #define DEFAULT_VACTIVE_PAL (312-DEFAULT_VDELAY_PAL)
  32. static u8 tbl_tw2864_template[] = {
  33. 0x00, 0x00, 0x80, 0x10, 0x80, 0x80, 0x00, 0x02, /* 0x00 */
  34. 0x12, 0xf5, 0x09, 0xd0, 0x00, 0x00, 0x00, 0x7f,
  35. 0x00, 0x00, 0x80, 0x10, 0x80, 0x80, 0x00, 0x02, /* 0x10 */
  36. 0x12, 0xf5, 0x09, 0xd0, 0x00, 0x00, 0x00, 0x7f,
  37. 0x00, 0x00, 0x80, 0x10, 0x80, 0x80, 0x00, 0x02, /* 0x20 */
  38. 0x12, 0xf5, 0x09, 0xd0, 0x00, 0x00, 0x00, 0x7f,
  39. 0x00, 0x00, 0x80, 0x10, 0x80, 0x80, 0x00, 0x02, /* 0x30 */
  40. 0x12, 0xf5, 0x09, 0xd0, 0x00, 0x00, 0x00, 0x7f,
  41. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40 */
  42. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  43. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50 */
  44. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  45. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60 */
  46. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  47. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70 */
  48. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA3, 0x00,
  49. 0x00, 0x02, 0x00, 0xcc, 0x00, 0x80, 0x44, 0x50, /* 0x80 */
  50. 0x22, 0x01, 0xd8, 0xbc, 0xb8, 0x44, 0x38, 0x00,
  51. 0x00, 0x78, 0x72, 0x3e, 0x14, 0xa5, 0xe4, 0x05, /* 0x90 */
  52. 0x00, 0x28, 0x44, 0x44, 0xa0, 0x88, 0x5a, 0x01,
  53. 0x08, 0x08, 0x08, 0x08, 0x1a, 0x1a, 0x1a, 0x1a, /* 0xa0 */
  54. 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0, 0x44,
  55. 0x44, 0x0a, 0x00, 0xff, 0xef, 0xef, 0xef, 0xef, /* 0xb0 */
  56. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  57. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0 */
  58. 0x00, 0x00, 0x55, 0x00, 0xb1, 0xe4, 0x40, 0x00,
  59. 0x77, 0x77, 0x01, 0x13, 0x57, 0x9b, 0xdf, 0x20, /* 0xd0 */
  60. 0x64, 0xa8, 0xec, 0xd1, 0x0f, 0x11, 0x11, 0x81,
  61. 0x10, 0xe0, 0xbb, 0xbb, 0x00, 0x11, 0x00, 0x00, /* 0xe0 */
  62. 0x11, 0x00, 0x00, 0x11, 0x00, 0x00, 0x11, 0x00,
  63. 0x83, 0xb5, 0x09, 0x78, 0x85, 0x00, 0x01, 0x20, /* 0xf0 */
  64. 0x64, 0x11, 0x40, 0xaf, 0xff, 0x00, 0x00, 0x00,
  65. };
  66. static u8 tbl_tw2865_ntsc_template[] = {
  67. 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x02, /* 0x00 */
  68. 0x12, 0xff, 0x09, 0xd0, 0x00, 0x00, 0x00, 0x7f,
  69. 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x02, /* 0x10 */
  70. 0x12, 0xff, 0x09, 0xd0, 0x00, 0x00, 0x00, 0x7f,
  71. 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x02, /* 0x20 */
  72. 0x12, 0xff, 0x09, 0xd0, 0x00, 0x00, 0x00, 0x7f,
  73. 0x00, 0xf0, 0x70, 0x48, 0x80, 0x80, 0x00, 0x02, /* 0x30 */
  74. 0x12, 0xff, 0x09, 0xd0, 0x00, 0x00, 0x00, 0x7f,
  75. 0x00, 0x00, 0x90, 0x68, 0x00, 0x38, 0x80, 0x80, /* 0x40 */
  76. 0x80, 0x80, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00,
  77. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50 */
  78. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  79. 0x45, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60 */
  80. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x43,
  81. 0x08, 0x00, 0x00, 0x01, 0xf1, 0x03, 0xEF, 0x03, /* 0x70 */
  82. 0xE9, 0x03, 0xD9, 0x15, 0x15, 0xE4, 0xA3, 0x80,
  83. 0x00, 0x02, 0x00, 0xCC, 0x00, 0x80, 0x44, 0x50, /* 0x80 */
  84. 0x22, 0x01, 0xD8, 0xBC, 0xB8, 0x44, 0x38, 0x00,
  85. 0x00, 0x78, 0x44, 0x3D, 0x14, 0xA5, 0xE0, 0x05, /* 0x90 */
  86. 0x00, 0x28, 0x44, 0x44, 0xA0, 0x90, 0x52, 0x13,
  87. 0x08, 0x08, 0x08, 0x08, 0x1A, 0x1A, 0x1B, 0x1A, /* 0xa0 */
  88. 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0x44,
  89. 0x44, 0x4A, 0x00, 0xFF, 0xEF, 0xEF, 0xEF, 0xEF, /* 0xb0 */
  90. 0xFF, 0xE7, 0xE9, 0xE9, 0xEB, 0xFF, 0xD6, 0xD8,
  91. 0xD8, 0xD7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0 */
  92. 0x00, 0x00, 0x55, 0x00, 0xE4, 0x39, 0x00, 0x80,
  93. 0x77, 0x77, 0x03, 0x20, 0x57, 0x9b, 0xdf, 0x31, /* 0xd0 */
  94. 0x64, 0xa8, 0xec, 0xd1, 0x0f, 0x11, 0x11, 0x81,
  95. 0x10, 0xC0, 0xAA, 0xAA, 0x00, 0x11, 0x00, 0x00, /* 0xe0 */
  96. 0x11, 0x00, 0x00, 0x11, 0x00, 0x00, 0x11, 0x00,
  97. 0x83, 0xB5, 0x09, 0x78, 0x85, 0x00, 0x01, 0x20, /* 0xf0 */
  98. 0x64, 0x51, 0x40, 0xaf, 0xFF, 0xF0, 0x00, 0xC0,
  99. };
  100. static u8 tbl_tw2865_pal_template[] = {
  101. 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x12, /* 0x00 */
  102. 0x11, 0xff, 0x01, 0xc3, 0x00, 0x00, 0x01, 0x7f,
  103. 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x12, /* 0x10 */
  104. 0x11, 0xff, 0x01, 0xc3, 0x00, 0x00, 0x01, 0x7f,
  105. 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x12, /* 0x20 */
  106. 0x11, 0xff, 0x01, 0xc3, 0x00, 0x00, 0x01, 0x7f,
  107. 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x12, /* 0x30 */
  108. 0x11, 0xff, 0x01, 0xc3, 0x00, 0x00, 0x01, 0x7f,
  109. 0x00, 0x94, 0x90, 0x48, 0x00, 0x38, 0x7F, 0x80, /* 0x40 */
  110. 0x80, 0x80, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00,
  111. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50 */
  112. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  113. 0x45, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60 */
  114. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x43,
  115. 0x08, 0x00, 0x00, 0x01, 0xf1, 0x03, 0xEF, 0x03, /* 0x70 */
  116. 0xEA, 0x03, 0xD9, 0x15, 0x15, 0xE4, 0xA3, 0x80,
  117. 0x00, 0x02, 0x00, 0xCC, 0x00, 0x80, 0x44, 0x50, /* 0x80 */
  118. 0x22, 0x01, 0xD8, 0xBC, 0xB8, 0x44, 0x38, 0x00,
  119. 0x00, 0x78, 0x44, 0x3D, 0x14, 0xA5, 0xE0, 0x05, /* 0x90 */
  120. 0x00, 0x28, 0x44, 0x44, 0xA0, 0x90, 0x52, 0x13,
  121. 0x08, 0x08, 0x08, 0x08, 0x1A, 0x1A, 0x1A, 0x1A, /* 0xa0 */
  122. 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0x44,
  123. 0x44, 0x4A, 0x00, 0xFF, 0xEF, 0xEF, 0xEF, 0xEF, /* 0xb0 */
  124. 0xFF, 0xE7, 0xE9, 0xE9, 0xE9, 0xFF, 0xD7, 0xD8,
  125. 0xD9, 0xD8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0 */
  126. 0x00, 0x00, 0x55, 0x00, 0xE4, 0x39, 0x00, 0x80,
  127. 0x77, 0x77, 0x03, 0x20, 0x57, 0x9b, 0xdf, 0x31, /* 0xd0 */
  128. 0x64, 0xa8, 0xec, 0xd1, 0x0f, 0x11, 0x11, 0x81,
  129. 0x10, 0xC0, 0xAA, 0xAA, 0x00, 0x11, 0x00, 0x00, /* 0xe0 */
  130. 0x11, 0x00, 0x00, 0x11, 0x00, 0x00, 0x11, 0x00,
  131. 0x83, 0xB5, 0x09, 0x00, 0xA0, 0x00, 0x01, 0x20, /* 0xf0 */
  132. 0x64, 0x51, 0x40, 0xaf, 0xFF, 0xF0, 0x00, 0xC0,
  133. };
  134. #define is_tw286x(__solo, __id) (!(__solo->tw2815 & (1 << __id)))
  135. static u8 tw_readbyte(struct solo_dev *solo_dev, int chip_id, u8 tw6x_off,
  136. u8 tw_off)
  137. {
  138. if (is_tw286x(solo_dev, chip_id))
  139. return solo_i2c_readbyte(solo_dev, SOLO_I2C_TW,
  140. TW_CHIP_OFFSET_ADDR(chip_id),
  141. tw6x_off);
  142. else
  143. return solo_i2c_readbyte(solo_dev, SOLO_I2C_TW,
  144. TW_CHIP_OFFSET_ADDR(chip_id),
  145. tw_off);
  146. }
  147. static void tw_writebyte(struct solo_dev *solo_dev, int chip_id,
  148. u8 tw6x_off, u8 tw_off, u8 val)
  149. {
  150. if (is_tw286x(solo_dev, chip_id))
  151. solo_i2c_writebyte(solo_dev, SOLO_I2C_TW,
  152. TW_CHIP_OFFSET_ADDR(chip_id),
  153. tw6x_off, val);
  154. else
  155. solo_i2c_writebyte(solo_dev, SOLO_I2C_TW,
  156. TW_CHIP_OFFSET_ADDR(chip_id),
  157. tw_off, val);
  158. }
  159. static void tw_write_and_verify(struct solo_dev *solo_dev, u8 addr, u8 off,
  160. u8 val)
  161. {
  162. int i;
  163. for (i = 0; i < 5; i++) {
  164. u8 rval = solo_i2c_readbyte(solo_dev, SOLO_I2C_TW, addr, off);
  165. if (rval == val)
  166. return;
  167. solo_i2c_writebyte(solo_dev, SOLO_I2C_TW, addr, off, val);
  168. msleep_interruptible(1);
  169. }
  170. /* printk("solo6x10/tw28: Error writing register: %02x->%02x [%02x]\n",
  171. addr, off, val); */
  172. }
  173. static int tw2865_setup(struct solo_dev *solo_dev, u8 dev_addr)
  174. {
  175. u8 tbl_tw2865_common[256];
  176. int i;
  177. if (solo_dev->video_type == SOLO_VO_FMT_TYPE_PAL)
  178. memcpy(tbl_tw2865_common, tbl_tw2865_pal_template,
  179. sizeof(tbl_tw2865_common));
  180. else
  181. memcpy(tbl_tw2865_common, tbl_tw2865_ntsc_template,
  182. sizeof(tbl_tw2865_common));
  183. /* ALINK Mode */
  184. if (solo_dev->nr_chans == 4) {
  185. tbl_tw2865_common[0xd2] = 0x01;
  186. tbl_tw2865_common[0xcf] = 0x00;
  187. } else if (solo_dev->nr_chans == 8) {
  188. tbl_tw2865_common[0xd2] = 0x02;
  189. if (dev_addr == TW_CHIP_OFFSET_ADDR(1))
  190. tbl_tw2865_common[0xcf] = 0x80;
  191. } else if (solo_dev->nr_chans == 16) {
  192. tbl_tw2865_common[0xd2] = 0x03;
  193. if (dev_addr == TW_CHIP_OFFSET_ADDR(1))
  194. tbl_tw2865_common[0xcf] = 0x83;
  195. else if (dev_addr == TW_CHIP_OFFSET_ADDR(2))
  196. tbl_tw2865_common[0xcf] = 0x83;
  197. else if (dev_addr == TW_CHIP_OFFSET_ADDR(3))
  198. tbl_tw2865_common[0xcf] = 0x80;
  199. }
  200. for (i = 0; i < 0xff; i++) {
  201. /* Skip read only registers */
  202. if (i >= 0xb8 && i <= 0xc1)
  203. continue;
  204. if ((i & ~0x30) == 0x00 ||
  205. (i & ~0x30) == 0x0c ||
  206. (i & ~0x30) == 0x0d)
  207. continue;
  208. if (i >= 0xc4 && i <= 0xc7)
  209. continue;
  210. if (i == 0xfd)
  211. continue;
  212. tw_write_and_verify(solo_dev, dev_addr, i,
  213. tbl_tw2865_common[i]);
  214. }
  215. return 0;
  216. }
  217. static int tw2864_setup(struct solo_dev *solo_dev, u8 dev_addr)
  218. {
  219. u8 tbl_tw2864_common[sizeof(tbl_tw2864_template)];
  220. int i;
  221. memcpy(tbl_tw2864_common, tbl_tw2864_template,
  222. sizeof(tbl_tw2864_common));
  223. if (solo_dev->tw2865 == 0) {
  224. /* IRQ Mode */
  225. if (solo_dev->nr_chans == 4) {
  226. tbl_tw2864_common[0xd2] = 0x01;
  227. tbl_tw2864_common[0xcf] = 0x00;
  228. } else if (solo_dev->nr_chans == 8) {
  229. tbl_tw2864_common[0xd2] = 0x02;
  230. if (dev_addr == TW_CHIP_OFFSET_ADDR(0))
  231. tbl_tw2864_common[0xcf] = 0x43;
  232. else if (dev_addr == TW_CHIP_OFFSET_ADDR(1))
  233. tbl_tw2864_common[0xcf] = 0x40;
  234. } else if (solo_dev->nr_chans == 16) {
  235. tbl_tw2864_common[0xd2] = 0x03;
  236. if (dev_addr == TW_CHIP_OFFSET_ADDR(0))
  237. tbl_tw2864_common[0xcf] = 0x43;
  238. else if (dev_addr == TW_CHIP_OFFSET_ADDR(1))
  239. tbl_tw2864_common[0xcf] = 0x43;
  240. else if (dev_addr == TW_CHIP_OFFSET_ADDR(2))
  241. tbl_tw2864_common[0xcf] = 0x43;
  242. else if (dev_addr == TW_CHIP_OFFSET_ADDR(3))
  243. tbl_tw2864_common[0xcf] = 0x40;
  244. }
  245. } else {
  246. /* ALINK Mode. Assumes that the first tw28xx is a
  247. * 2865 and these are in cascade. */
  248. for (i = 0; i <= 4; i++)
  249. tbl_tw2864_common[0x08 | i << 4] = 0x12;
  250. if (solo_dev->nr_chans == 8) {
  251. tbl_tw2864_common[0xd2] = 0x02;
  252. if (dev_addr == TW_CHIP_OFFSET_ADDR(1))
  253. tbl_tw2864_common[0xcf] = 0x80;
  254. } else if (solo_dev->nr_chans == 16) {
  255. tbl_tw2864_common[0xd2] = 0x03;
  256. if (dev_addr == TW_CHIP_OFFSET_ADDR(1))
  257. tbl_tw2864_common[0xcf] = 0x83;
  258. else if (dev_addr == TW_CHIP_OFFSET_ADDR(2))
  259. tbl_tw2864_common[0xcf] = 0x83;
  260. else if (dev_addr == TW_CHIP_OFFSET_ADDR(3))
  261. tbl_tw2864_common[0xcf] = 0x80;
  262. }
  263. }
  264. /* NTSC or PAL */
  265. if (solo_dev->video_type == SOLO_VO_FMT_TYPE_PAL) {
  266. for (i = 0; i < 4; i++) {
  267. tbl_tw2864_common[0x07 | (i << 4)] |= 0x10;
  268. tbl_tw2864_common[0x08 | (i << 4)] |= 0x06;
  269. tbl_tw2864_common[0x0a | (i << 4)] |= 0x08;
  270. tbl_tw2864_common[0x0b | (i << 4)] |= 0x13;
  271. tbl_tw2864_common[0x0e | (i << 4)] |= 0x01;
  272. }
  273. tbl_tw2864_common[0x9d] = 0x90;
  274. tbl_tw2864_common[0xf3] = 0x00;
  275. tbl_tw2864_common[0xf4] = 0xa0;
  276. }
  277. for (i = 0; i < 0xff; i++) {
  278. /* Skip read only registers */
  279. if (i >= 0xb8 && i <= 0xc1)
  280. continue;
  281. if ((i & ~0x30) == 0x00 ||
  282. (i & ~0x30) == 0x0c ||
  283. (i & ~0x30) == 0x0d)
  284. continue;
  285. if (i == 0x74 || i == 0x77 || i == 0x78 ||
  286. i == 0x79 || i == 0x7a)
  287. continue;
  288. if (i == 0xfd)
  289. continue;
  290. tw_write_and_verify(solo_dev, dev_addr, i,
  291. tbl_tw2864_common[i]);
  292. }
  293. return 0;
  294. }
  295. static int tw2815_setup(struct solo_dev *solo_dev, u8 dev_addr)
  296. {
  297. u8 tbl_ntsc_tw2815_common[] = {
  298. 0x00, 0xc8, 0x20, 0xd0, 0x06, 0xf0, 0x08, 0x80,
  299. 0x80, 0x80, 0x80, 0x02, 0x06, 0x00, 0x11,
  300. };
  301. u8 tbl_pal_tw2815_common[] = {
  302. 0x00, 0x88, 0x20, 0xd0, 0x05, 0x20, 0x28, 0x80,
  303. 0x80, 0x80, 0x80, 0x82, 0x06, 0x00, 0x11,
  304. };
  305. u8 tbl_tw2815_sfr[] = {
  306. 0x00, 0x00, 0x00, 0xc0, 0x45, 0xa0, 0xd0, 0x2f, /* 0x00 */
  307. 0x64, 0x80, 0x80, 0x82, 0x82, 0x00, 0x00, 0x00,
  308. 0x00, 0x0f, 0x05, 0x00, 0x00, 0x80, 0x06, 0x00, /* 0x10 */
  309. 0x00, 0x00, 0x00, 0xff, 0x8f, 0x00, 0x00, 0x00,
  310. 0x88, 0x88, 0xc0, 0x00, 0x20, 0x64, 0xa8, 0xec, /* 0x20 */
  311. 0x31, 0x75, 0xb9, 0xfd, 0x00, 0x00, 0x88, 0x88,
  312. 0x88, 0x11, 0x00, 0x88, 0x88, 0x00, /* 0x30 */
  313. };
  314. u8 *tbl_tw2815_common;
  315. int i;
  316. int ch;
  317. tbl_ntsc_tw2815_common[0x06] = 0;
  318. /* Horizontal Delay Control */
  319. tbl_ntsc_tw2815_common[0x02] = DEFAULT_HDELAY_NTSC & 0xff;
  320. tbl_ntsc_tw2815_common[0x06] |= 0x03 & (DEFAULT_HDELAY_NTSC >> 8);
  321. /* Horizontal Active Control */
  322. tbl_ntsc_tw2815_common[0x03] = DEFAULT_HACTIVE_NTSC & 0xff;
  323. tbl_ntsc_tw2815_common[0x06] |=
  324. ((0x03 & (DEFAULT_HACTIVE_NTSC >> 8)) << 2);
  325. /* Vertical Delay Control */
  326. tbl_ntsc_tw2815_common[0x04] = DEFAULT_VDELAY_NTSC & 0xff;
  327. tbl_ntsc_tw2815_common[0x06] |=
  328. ((0x01 & (DEFAULT_VDELAY_NTSC >> 8)) << 4);
  329. /* Vertical Active Control */
  330. tbl_ntsc_tw2815_common[0x05] = DEFAULT_VACTIVE_NTSC & 0xff;
  331. tbl_ntsc_tw2815_common[0x06] |=
  332. ((0x01 & (DEFAULT_VACTIVE_NTSC >> 8)) << 5);
  333. tbl_pal_tw2815_common[0x06] = 0;
  334. /* Horizontal Delay Control */
  335. tbl_pal_tw2815_common[0x02] = DEFAULT_HDELAY_PAL & 0xff;
  336. tbl_pal_tw2815_common[0x06] |= 0x03 & (DEFAULT_HDELAY_PAL >> 8);
  337. /* Horizontal Active Control */
  338. tbl_pal_tw2815_common[0x03] = DEFAULT_HACTIVE_PAL & 0xff;
  339. tbl_pal_tw2815_common[0x06] |=
  340. ((0x03 & (DEFAULT_HACTIVE_PAL >> 8)) << 2);
  341. /* Vertical Delay Control */
  342. tbl_pal_tw2815_common[0x04] = DEFAULT_VDELAY_PAL & 0xff;
  343. tbl_pal_tw2815_common[0x06] |=
  344. ((0x01 & (DEFAULT_VDELAY_PAL >> 8)) << 4);
  345. /* Vertical Active Control */
  346. tbl_pal_tw2815_common[0x05] = DEFAULT_VACTIVE_PAL & 0xff;
  347. tbl_pal_tw2815_common[0x06] |=
  348. ((0x01 & (DEFAULT_VACTIVE_PAL >> 8)) << 5);
  349. tbl_tw2815_common =
  350. (solo_dev->video_type == SOLO_VO_FMT_TYPE_NTSC) ?
  351. tbl_ntsc_tw2815_common : tbl_pal_tw2815_common;
  352. /* Dual ITU-R BT.656 format */
  353. tbl_tw2815_common[0x0d] |= 0x04;
  354. /* Audio configuration */
  355. tbl_tw2815_sfr[0x62 - 0x40] &= ~(3 << 6);
  356. if (solo_dev->nr_chans == 4) {
  357. tbl_tw2815_sfr[0x63 - 0x40] |= 1;
  358. tbl_tw2815_sfr[0x62 - 0x40] |= 3 << 6;
  359. } else if (solo_dev->nr_chans == 8) {
  360. tbl_tw2815_sfr[0x63 - 0x40] |= 2;
  361. if (dev_addr == TW_CHIP_OFFSET_ADDR(0))
  362. tbl_tw2815_sfr[0x62 - 0x40] |= 1 << 6;
  363. else if (dev_addr == TW_CHIP_OFFSET_ADDR(1))
  364. tbl_tw2815_sfr[0x62 - 0x40] |= 2 << 6;
  365. } else if (solo_dev->nr_chans == 16) {
  366. tbl_tw2815_sfr[0x63 - 0x40] |= 3;
  367. if (dev_addr == TW_CHIP_OFFSET_ADDR(0))
  368. tbl_tw2815_sfr[0x62 - 0x40] |= 1 << 6;
  369. else if (dev_addr == TW_CHIP_OFFSET_ADDR(1))
  370. tbl_tw2815_sfr[0x62 - 0x40] |= 0 << 6;
  371. else if (dev_addr == TW_CHIP_OFFSET_ADDR(2))
  372. tbl_tw2815_sfr[0x62 - 0x40] |= 0 << 6;
  373. else if (dev_addr == TW_CHIP_OFFSET_ADDR(3))
  374. tbl_tw2815_sfr[0x62 - 0x40] |= 2 << 6;
  375. }
  376. /* Output mode of R_ADATM pin (0 mixing, 1 record) */
  377. /* tbl_tw2815_sfr[0x63 - 0x40] |= 0 << 2; */
  378. /* 8KHz, used to be 16KHz, but changed for remote client compat */
  379. tbl_tw2815_sfr[0x62 - 0x40] |= 0 << 2;
  380. tbl_tw2815_sfr[0x6c - 0x40] |= 0 << 2;
  381. /* Playback of right channel */
  382. tbl_tw2815_sfr[0x6c - 0x40] |= 1 << 5;
  383. /* Reserved value (XXX ??) */
  384. tbl_tw2815_sfr[0x5c - 0x40] |= 1 << 5;
  385. /* Analog output gain and mix ratio playback on full */
  386. tbl_tw2815_sfr[0x70 - 0x40] |= 0xff;
  387. /* Select playback audio and mute all except */
  388. tbl_tw2815_sfr[0x71 - 0x40] |= 0x10;
  389. tbl_tw2815_sfr[0x6d - 0x40] |= 0x0f;
  390. /* End of audio configuration */
  391. for (ch = 0; ch < 4; ch++) {
  392. tbl_tw2815_common[0x0d] &= ~3;
  393. switch (ch) {
  394. case 0:
  395. tbl_tw2815_common[0x0d] |= 0x21;
  396. break;
  397. case 1:
  398. tbl_tw2815_common[0x0d] |= 0x20;
  399. break;
  400. case 2:
  401. tbl_tw2815_common[0x0d] |= 0x23;
  402. break;
  403. case 3:
  404. tbl_tw2815_common[0x0d] |= 0x22;
  405. break;
  406. }
  407. for (i = 0; i < 0x0f; i++) {
  408. if (i == 0x00)
  409. continue; /* read-only */
  410. solo_i2c_writebyte(solo_dev, SOLO_I2C_TW,
  411. dev_addr, (ch * 0x10) + i,
  412. tbl_tw2815_common[i]);
  413. }
  414. }
  415. for (i = 0x40; i < 0x76; i++) {
  416. /* Skip read-only and nop registers */
  417. if (i == 0x40 || i == 0x59 || i == 0x5a ||
  418. i == 0x5d || i == 0x5e || i == 0x5f)
  419. continue;
  420. solo_i2c_writebyte(solo_dev, SOLO_I2C_TW, dev_addr, i,
  421. tbl_tw2815_sfr[i - 0x40]);
  422. }
  423. return 0;
  424. }
  425. #define FIRST_ACTIVE_LINE 0x0008
  426. #define LAST_ACTIVE_LINE 0x0102
  427. static void saa7128_setup(struct solo_dev *solo_dev)
  428. {
  429. int i;
  430. unsigned char regs[128] = {
  431. 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00,
  432. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  433. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  434. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  435. 0x1C, 0x2B, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x00,
  436. 0x59, 0x1d, 0x75, 0x3f, 0x06, 0x3f, 0x00, 0x00,
  437. 0x1c, 0x33, 0x00, 0x3f, 0x00, 0x00, 0x3f, 0x00,
  438. 0x1a, 0x1a, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00,
  439. 0x00, 0x00, 0x00, 0x68, 0x10, 0x97, 0x4c, 0x18,
  440. 0x9b, 0x93, 0x9f, 0xff, 0x7c, 0x34, 0x3f, 0x3f,
  441. 0x3f, 0x83, 0x83, 0x80, 0x0d, 0x0f, 0xc3, 0x06,
  442. 0x02, 0x80, 0x71, 0x77, 0xa7, 0x67, 0x66, 0x2e,
  443. 0x7b, 0x11, 0x4f, 0x1f, 0x7c, 0xf0, 0x21, 0x77,
  444. 0x41, 0x88, 0x41, 0x12, 0xed, 0x10, 0x10, 0x00,
  445. 0x41, 0xc3, 0x00, 0x3e, 0xb8, 0x02, 0x00, 0x00,
  446. 0x00, 0x00, 0x08, 0xff, 0x80, 0x00, 0xff, 0xff,
  447. };
  448. regs[0x7A] = FIRST_ACTIVE_LINE & 0xff;
  449. regs[0x7B] = LAST_ACTIVE_LINE & 0xff;
  450. regs[0x7C] = ((1 << 7) |
  451. (((LAST_ACTIVE_LINE >> 8) & 1) << 6) |
  452. (((FIRST_ACTIVE_LINE >> 8) & 1) << 4));
  453. /* PAL: XXX: We could do a second set of regs to avoid this */
  454. if (solo_dev->video_type != SOLO_VO_FMT_TYPE_NTSC) {
  455. regs[0x28] = 0xE1;
  456. regs[0x5A] = 0x0F;
  457. regs[0x61] = 0x02;
  458. regs[0x62] = 0x35;
  459. regs[0x63] = 0xCB;
  460. regs[0x64] = 0x8A;
  461. regs[0x65] = 0x09;
  462. regs[0x66] = 0x2A;
  463. regs[0x6C] = 0xf1;
  464. regs[0x6E] = 0x20;
  465. regs[0x7A] = 0x06 + 12;
  466. regs[0x7b] = 0x24 + 12;
  467. regs[0x7c] |= 1 << 6;
  468. }
  469. /* First 0x25 bytes are read-only? */
  470. for (i = 0x26; i < 128; i++) {
  471. if (i == 0x60 || i == 0x7D)
  472. continue;
  473. solo_i2c_writebyte(solo_dev, SOLO_I2C_SAA, 0x46, i, regs[i]);
  474. }
  475. return;
  476. }
  477. int solo_tw28_init(struct solo_dev *solo_dev)
  478. {
  479. int i;
  480. u8 value;
  481. /* Detect techwell chip type */
  482. for (i = 0; i < TW_NUM_CHIP; i++) {
  483. value = solo_i2c_readbyte(solo_dev, SOLO_I2C_TW,
  484. TW_CHIP_OFFSET_ADDR(i), 0xFF);
  485. switch (value >> 3) {
  486. case 0x18:
  487. solo_dev->tw2865 |= 1 << i;
  488. solo_dev->tw28_cnt++;
  489. break;
  490. case 0x0c:
  491. solo_dev->tw2864 |= 1 << i;
  492. solo_dev->tw28_cnt++;
  493. break;
  494. default:
  495. value = solo_i2c_readbyte(solo_dev, SOLO_I2C_TW,
  496. TW_CHIP_OFFSET_ADDR(i), 0x59);
  497. if ((value >> 3) == 0x04) {
  498. solo_dev->tw2815 |= 1 << i;
  499. solo_dev->tw28_cnt++;
  500. }
  501. }
  502. }
  503. if (!solo_dev->tw28_cnt)
  504. return -EINVAL;
  505. saa7128_setup(solo_dev);
  506. for (i = 0; i < solo_dev->tw28_cnt; i++) {
  507. if ((solo_dev->tw2865 & (1 << i)))
  508. tw2865_setup(solo_dev, TW_CHIP_OFFSET_ADDR(i));
  509. else if ((solo_dev->tw2864 & (1 << i)))
  510. tw2864_setup(solo_dev, TW_CHIP_OFFSET_ADDR(i));
  511. else
  512. tw2815_setup(solo_dev, TW_CHIP_OFFSET_ADDR(i));
  513. }
  514. dev_info(&solo_dev->pdev->dev, "Initialized %d tw28xx chip%s:",
  515. solo_dev->tw28_cnt, solo_dev->tw28_cnt == 1 ? "" : "s");
  516. if (solo_dev->tw2865)
  517. printk(" tw2865[%d]", hweight32(solo_dev->tw2865));
  518. if (solo_dev->tw2864)
  519. printk(" tw2864[%d]", hweight32(solo_dev->tw2864));
  520. if (solo_dev->tw2815)
  521. printk(" tw2815[%d]", hweight32(solo_dev->tw2815));
  522. printk("\n");
  523. return 0;
  524. }
  525. /*
  526. * We accessed the video status signal in the Techwell chip through
  527. * iic/i2c because the video status reported by register REG_VI_STATUS1
  528. * (address 0x012C) of the SOLO6010 chip doesn't give the correct video
  529. * status signal values.
  530. */
  531. int tw28_get_video_status(struct solo_dev *solo_dev, u8 ch)
  532. {
  533. u8 val, chip_num;
  534. /* Get the right chip and on-chip channel */
  535. chip_num = ch / 4;
  536. ch %= 4;
  537. val = tw_readbyte(solo_dev, chip_num, TW286X_AV_STAT_ADDR,
  538. TW_AV_STAT_ADDR) & 0x0f;
  539. return val & (1 << ch) ? 1 : 0;
  540. }
  541. #if 0
  542. /* Status of audio from up to 4 techwell chips are combined into 1 variable.
  543. * See techwell datasheet for details. */
  544. u16 tw28_get_audio_status(struct solo_dev *solo_dev)
  545. {
  546. u8 val;
  547. u16 status = 0;
  548. int i;
  549. for (i = 0; i < solo_dev->tw28_cnt; i++) {
  550. val = (tw_readbyte(solo_dev, i, TW286X_AV_STAT_ADDR,
  551. TW_AV_STAT_ADDR) & 0xf0) >> 4;
  552. status |= val << (i * 4);
  553. }
  554. return status;
  555. }
  556. #endif
  557. int tw28_set_ctrl_val(struct solo_dev *solo_dev, u32 ctrl, u8 ch, s32 val)
  558. {
  559. char sval;
  560. u8 chip_num;
  561. /* Get the right chip and on-chip channel */
  562. chip_num = ch / 4;
  563. ch %= 4;
  564. if (val > 255 || val < 0)
  565. return -ERANGE;
  566. switch (ctrl) {
  567. case V4L2_CID_SHARPNESS:
  568. /* Only 286x has sharpness */
  569. if (val > 0x0f || val < 0)
  570. return -ERANGE;
  571. if (is_tw286x(solo_dev, chip_num)) {
  572. u8 v = solo_i2c_readbyte(solo_dev, SOLO_I2C_TW,
  573. TW_CHIP_OFFSET_ADDR(chip_num),
  574. TW286x_SHARPNESS(chip_num));
  575. v &= 0xf0;
  576. v |= val;
  577. solo_i2c_writebyte(solo_dev, SOLO_I2C_TW,
  578. TW_CHIP_OFFSET_ADDR(chip_num),
  579. TW286x_SHARPNESS(chip_num), v);
  580. } else if (val != 0)
  581. return -ERANGE;
  582. break;
  583. case V4L2_CID_HUE:
  584. if (is_tw286x(solo_dev, chip_num))
  585. sval = val - 128;
  586. else
  587. sval = (char)val;
  588. tw_writebyte(solo_dev, chip_num, TW286x_HUE_ADDR(ch),
  589. TW_HUE_ADDR(ch), sval);
  590. break;
  591. case V4L2_CID_SATURATION:
  592. if (is_tw286x(solo_dev, chip_num)) {
  593. solo_i2c_writebyte(solo_dev, SOLO_I2C_TW,
  594. TW_CHIP_OFFSET_ADDR(chip_num),
  595. TW286x_SATURATIONU_ADDR(ch), val);
  596. }
  597. tw_writebyte(solo_dev, chip_num, TW286x_SATURATIONV_ADDR(ch),
  598. TW_SATURATION_ADDR(ch), val);
  599. break;
  600. case V4L2_CID_CONTRAST:
  601. tw_writebyte(solo_dev, chip_num, TW286x_CONTRAST_ADDR(ch),
  602. TW_CONTRAST_ADDR(ch), val);
  603. break;
  604. case V4L2_CID_BRIGHTNESS:
  605. if (is_tw286x(solo_dev, chip_num))
  606. sval = val - 128;
  607. else
  608. sval = (char)val;
  609. tw_writebyte(solo_dev, chip_num, TW286x_BRIGHTNESS_ADDR(ch),
  610. TW_BRIGHTNESS_ADDR(ch), sval);
  611. break;
  612. default:
  613. return -EINVAL;
  614. }
  615. return 0;
  616. }
  617. int tw28_get_ctrl_val(struct solo_dev *solo_dev, u32 ctrl, u8 ch,
  618. s32 *val)
  619. {
  620. u8 rval, chip_num;
  621. /* Get the right chip and on-chip channel */
  622. chip_num = ch / 4;
  623. ch %= 4;
  624. switch (ctrl) {
  625. case V4L2_CID_SHARPNESS:
  626. /* Only 286x has sharpness */
  627. if (is_tw286x(solo_dev, chip_num)) {
  628. rval = solo_i2c_readbyte(solo_dev, SOLO_I2C_TW,
  629. TW_CHIP_OFFSET_ADDR(chip_num),
  630. TW286x_SHARPNESS(chip_num));
  631. *val = rval & 0x0f;
  632. } else
  633. *val = 0;
  634. break;
  635. case V4L2_CID_HUE:
  636. rval = tw_readbyte(solo_dev, chip_num, TW286x_HUE_ADDR(ch),
  637. TW_HUE_ADDR(ch));
  638. if (is_tw286x(solo_dev, chip_num))
  639. *val = (s32)((char)rval) + 128;
  640. else
  641. *val = rval;
  642. break;
  643. case V4L2_CID_SATURATION:
  644. *val = tw_readbyte(solo_dev, chip_num,
  645. TW286x_SATURATIONU_ADDR(ch),
  646. TW_SATURATION_ADDR(ch));
  647. break;
  648. case V4L2_CID_CONTRAST:
  649. *val = tw_readbyte(solo_dev, chip_num,
  650. TW286x_CONTRAST_ADDR(ch),
  651. TW_CONTRAST_ADDR(ch));
  652. break;
  653. case V4L2_CID_BRIGHTNESS:
  654. rval = tw_readbyte(solo_dev, chip_num,
  655. TW286x_BRIGHTNESS_ADDR(ch),
  656. TW_BRIGHTNESS_ADDR(ch));
  657. if (is_tw286x(solo_dev, chip_num))
  658. *val = (s32)((char)rval) + 128;
  659. else
  660. *val = rval;
  661. break;
  662. default:
  663. return -EINVAL;
  664. }
  665. return 0;
  666. }
  667. #if 0
  668. /*
  669. * For audio output volume, the output channel is only 1. In this case we
  670. * don't need to offset TW_CHIP_OFFSET_ADDR. The TW_CHIP_OFFSET_ADDR used
  671. * is the base address of the techwell chip.
  672. */
  673. void tw2815_Set_AudioOutVol(struct solo_dev *solo_dev, unsigned int u_val)
  674. {
  675. unsigned int val;
  676. unsigned int chip_num;
  677. chip_num = (solo_dev->nr_chans - 1) / 4;
  678. val = tw_readbyte(solo_dev, chip_num, TW286x_AUDIO_OUTPUT_VOL_ADDR,
  679. TW_AUDIO_OUTPUT_VOL_ADDR);
  680. u_val = (val & 0x0f) | (u_val << 4);
  681. tw_writebyte(solo_dev, chip_num, TW286x_AUDIO_OUTPUT_VOL_ADDR,
  682. TW_AUDIO_OUTPUT_VOL_ADDR, u_val);
  683. }
  684. #endif
  685. u8 tw28_get_audio_gain(struct solo_dev *solo_dev, u8 ch)
  686. {
  687. u8 val;
  688. u8 chip_num;
  689. /* Get the right chip and on-chip channel */
  690. chip_num = ch / 4;
  691. ch %= 4;
  692. val = tw_readbyte(solo_dev, chip_num,
  693. TW286x_AUDIO_INPUT_GAIN_ADDR(ch),
  694. TW_AUDIO_INPUT_GAIN_ADDR(ch));
  695. return (ch % 2) ? (val >> 4) : (val & 0x0f);
  696. }
  697. void tw28_set_audio_gain(struct solo_dev *solo_dev, u8 ch, u8 val)
  698. {
  699. u8 old_val;
  700. u8 chip_num;
  701. /* Get the right chip and on-chip channel */
  702. chip_num = ch / 4;
  703. ch %= 4;
  704. old_val = tw_readbyte(solo_dev, chip_num,
  705. TW286x_AUDIO_INPUT_GAIN_ADDR(ch),
  706. TW_AUDIO_INPUT_GAIN_ADDR(ch));
  707. val = (old_val & ((ch % 2) ? 0x0f : 0xf0)) |
  708. ((ch % 2) ? (val << 4) : val);
  709. tw_writebyte(solo_dev, chip_num, TW286x_AUDIO_INPUT_GAIN_ADDR(ch),
  710. TW_AUDIO_INPUT_GAIN_ADDR(ch), val);
  711. }