solo6x10-tw28.c 26 KB

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