tda8290.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /*
  2. * $Id: tda8290.c,v 1.15 2005/07/08 20:21:33 mchehab Exp $
  3. *
  4. * i2c tv tuner chip device driver
  5. * controls the philips tda8290+75 tuner chip combo.
  6. */
  7. #include <linux/i2c.h>
  8. #include <linux/videodev.h>
  9. #include <linux/delay.h>
  10. #include <media/tuner.h>
  11. /* ---------------------------------------------------------------------- */
  12. struct freq_entry {
  13. u16 freq;
  14. u8 value;
  15. };
  16. static struct freq_entry band_table[] = {
  17. { 0x2DF4, 0x1C },
  18. { 0x2574, 0x14 },
  19. { 0x22B4, 0x0C },
  20. { 0x20D4, 0x0B },
  21. { 0x1E74, 0x3B },
  22. { 0x1C34, 0x33 },
  23. { 0x16F4, 0x5B },
  24. { 0x1454, 0x53 },
  25. { 0x12D4, 0x52 },
  26. { 0x1034, 0x4A },
  27. { 0x0EE4, 0x7A },
  28. { 0x0D34, 0x72 },
  29. { 0x0B54, 0x9A },
  30. { 0x0914, 0x91 },
  31. { 0x07F4, 0x89 },
  32. { 0x0774, 0xB9 },
  33. { 0x067B, 0xB1 },
  34. { 0x0634, 0xD9 },
  35. { 0x05A4, 0xD8 }, // FM radio
  36. { 0x0494, 0xD0 },
  37. { 0x03BC, 0xC8 },
  38. { 0x0394, 0xF8 }, // 57250000 Hz
  39. { 0x0000, 0xF0 }, // 0
  40. };
  41. static struct freq_entry div_table[] = {
  42. { 0x1C34, 3 },
  43. { 0x0D34, 2 },
  44. { 0x067B, 1 },
  45. { 0x0000, 0 },
  46. };
  47. static struct freq_entry agc_table[] = {
  48. { 0x22B4, 0x8F },
  49. { 0x0B54, 0x9F },
  50. { 0x09A4, 0x8F },
  51. { 0x0554, 0x9F },
  52. { 0x0000, 0xBF },
  53. };
  54. static __u8 get_freq_entry( struct freq_entry* table, __u16 freq)
  55. {
  56. while(table->freq && table->freq > freq)
  57. table++;
  58. return table->value;
  59. }
  60. /* ---------------------------------------------------------------------- */
  61. static unsigned char i2c_enable_bridge[2] = { 0x21, 0xC0 };
  62. static unsigned char i2c_disable_bridge[2] = { 0x21, 0x80 };
  63. static unsigned char i2c_init_tda8275[14] = { 0x00, 0x00, 0x00, 0x00,
  64. 0xfC, 0x04, 0xA3, 0x3F,
  65. 0x2A, 0x04, 0xFF, 0x00,
  66. 0x00, 0x40 };
  67. static unsigned char i2c_set_VS[2] = { 0x30, 0x6F };
  68. static unsigned char i2c_set_GP01_CF[2] = { 0x20, 0x0B };
  69. static unsigned char i2c_tda8290_reset[2] = { 0x00, 0x00 };
  70. static unsigned char i2c_gainset_off[2] = { 0x28, 0x14 };
  71. static unsigned char i2c_gainset_on[2] = { 0x28, 0x54 };
  72. static unsigned char i2c_agc3_00[2] = { 0x80, 0x00 };
  73. static unsigned char i2c_agc2_BF[2] = { 0x60, 0xBF };
  74. static unsigned char i2c_cb1_D2[2] = { 0x30, 0xD2 };
  75. static unsigned char i2c_cb1_56[2] = { 0x30, 0x56 };
  76. static unsigned char i2c_cb1_52[2] = { 0x30, 0x52 };
  77. static unsigned char i2c_cb1_50[2] = { 0x30, 0x50 };
  78. static unsigned char i2c_agc2_7F[2] = { 0x60, 0x7F };
  79. static unsigned char i2c_agc3_08[2] = { 0x80, 0x08 };
  80. static struct i2c_msg i2c_msg_init[] = {
  81. { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_init_tda8275), i2c_init_tda8275 },
  82. { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_disable_bridge), i2c_disable_bridge },
  83. { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_set_VS), i2c_set_VS },
  84. { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_set_GP01_CF), i2c_set_GP01_CF },
  85. };
  86. static struct i2c_msg i2c_msg_prolog[] = {
  87. // { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_easy_mode), i2c_easy_mode },
  88. { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_gainset_off), i2c_gainset_off },
  89. { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_tda8290_reset), i2c_tda8290_reset },
  90. { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_enable_bridge), i2c_enable_bridge },
  91. };
  92. static struct i2c_msg i2c_msg_config[] = {
  93. // { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_set_freq), i2c_set_freq },
  94. { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_agc3_00), i2c_agc3_00 },
  95. { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_agc2_BF), i2c_agc2_BF },
  96. { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_cb1_D2), i2c_cb1_D2 },
  97. { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_cb1_56), i2c_cb1_56 },
  98. { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_cb1_52), i2c_cb1_52 },
  99. };
  100. static struct i2c_msg i2c_msg_epilog[] = {
  101. { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_cb1_50), i2c_cb1_50 },
  102. { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_agc2_7F), i2c_agc2_7F },
  103. { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_agc3_08), i2c_agc3_08 },
  104. { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_disable_bridge), i2c_disable_bridge },
  105. { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_gainset_on), i2c_gainset_on },
  106. };
  107. static int tda8290_tune(struct i2c_client *c)
  108. {
  109. struct tuner *t = i2c_get_clientdata(c);
  110. struct i2c_msg easy_mode =
  111. { I2C_ADDR_TDA8290, 0, 2, t->i2c_easy_mode };
  112. struct i2c_msg set_freq =
  113. { I2C_ADDR_TDA8275, 0, 8, t->i2c_set_freq };
  114. i2c_transfer(c->adapter, &easy_mode, 1);
  115. i2c_transfer(c->adapter, i2c_msg_prolog, ARRAY_SIZE(i2c_msg_prolog));
  116. i2c_transfer(c->adapter, &set_freq, 1);
  117. i2c_transfer(c->adapter, i2c_msg_config, ARRAY_SIZE(i2c_msg_config));
  118. msleep(550);
  119. i2c_transfer(c->adapter, i2c_msg_epilog, ARRAY_SIZE(i2c_msg_epilog));
  120. return 0;
  121. }
  122. static void set_frequency(struct tuner *t, u16 ifc, unsigned int freq)
  123. {
  124. u32 N;
  125. if (t->mode == V4L2_TUNER_RADIO)
  126. freq = freq / 1000;
  127. N = (((freq<<3)+ifc)&0x3fffc);
  128. N = N >> get_freq_entry(div_table, freq);
  129. t->i2c_set_freq[0] = 0;
  130. t->i2c_set_freq[1] = (unsigned char)(N>>8);
  131. t->i2c_set_freq[2] = (unsigned char) N;
  132. t->i2c_set_freq[3] = 0x40;
  133. t->i2c_set_freq[4] = 0x52;
  134. t->i2c_set_freq[5] = get_freq_entry(band_table, freq);
  135. t->i2c_set_freq[6] = get_freq_entry(agc_table, freq);
  136. t->i2c_set_freq[7] = 0x8f;
  137. }
  138. #define V4L2_STD_MN (V4L2_STD_PAL_M|V4L2_STD_PAL_N|V4L2_STD_PAL_Nc|V4L2_STD_NTSC)
  139. #define V4L2_STD_B (V4L2_STD_PAL_B|V4L2_STD_PAL_B1|V4L2_STD_SECAM_B)
  140. #define V4L2_STD_GH (V4L2_STD_PAL_G|V4L2_STD_PAL_H|V4L2_STD_SECAM_G|V4L2_STD_SECAM_H)
  141. #define V4L2_STD_DK (V4L2_STD_PAL_DK|V4L2_STD_SECAM_DK)
  142. static void set_audio(struct tuner *t)
  143. {
  144. t->i2c_easy_mode[0] = 0x01;
  145. if (t->std & V4L2_STD_MN)
  146. t->i2c_easy_mode[1] = 0x01;
  147. else if (t->std & V4L2_STD_B)
  148. t->i2c_easy_mode[1] = 0x02;
  149. else if (t->std & V4L2_STD_GH)
  150. t->i2c_easy_mode[1] = 0x04;
  151. else if (t->std & V4L2_STD_PAL_I)
  152. t->i2c_easy_mode[1] = 0x08;
  153. else if (t->std & V4L2_STD_DK)
  154. t->i2c_easy_mode[1] = 0x10;
  155. else if (t->std & V4L2_STD_SECAM_L)
  156. t->i2c_easy_mode[1] = 0x20;
  157. }
  158. static void set_tv_freq(struct i2c_client *c, unsigned int freq)
  159. {
  160. struct tuner *t = i2c_get_clientdata(c);
  161. set_audio(t);
  162. set_frequency(t, 864, freq);
  163. tda8290_tune(c);
  164. }
  165. static void set_radio_freq(struct i2c_client *c, unsigned int freq)
  166. {
  167. struct tuner *t = i2c_get_clientdata(c);
  168. set_frequency(t, 704, freq);
  169. tda8290_tune(c);
  170. }
  171. static int has_signal(struct i2c_client *c)
  172. {
  173. unsigned char i2c_get_afc[1] = { 0x1B };
  174. unsigned char afc = 0;
  175. i2c_master_send(c, i2c_get_afc, ARRAY_SIZE(i2c_get_afc));
  176. i2c_master_recv(c, &afc, 1);
  177. return (afc & 0x80)? 65535:0;
  178. }
  179. int tda8290_init(struct i2c_client *c)
  180. {
  181. struct tuner *t = i2c_get_clientdata(c);
  182. strlcpy(c->name, "tda8290+75", sizeof(c->name));
  183. tuner_info("tuner: type set to %s\n", c->name);
  184. t->tv_freq = set_tv_freq;
  185. t->radio_freq = set_radio_freq;
  186. t->has_signal = has_signal;
  187. i2c_master_send(c, i2c_enable_bridge, ARRAY_SIZE(i2c_enable_bridge));
  188. i2c_transfer(c->adapter, i2c_msg_init, ARRAY_SIZE(i2c_msg_init));
  189. return 0;
  190. }
  191. /*
  192. * Overrides for Emacs so that we follow Linus's tabbing style.
  193. * ---------------------------------------------------------------------------
  194. * Local variables:
  195. * c-basic-offset: 8
  196. * End:
  197. */