tuner-core.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. /*
  2. *
  3. * i2c tv tuner chip device driver
  4. * core core, i.e. kernel interfaces, registering and so on
  5. */
  6. #include <linux/module.h>
  7. #include <linux/moduleparam.h>
  8. #include <linux/kernel.h>
  9. #include <linux/sched.h>
  10. #include <linux/string.h>
  11. #include <linux/timer.h>
  12. #include <linux/delay.h>
  13. #include <linux/errno.h>
  14. #include <linux/slab.h>
  15. #include <linux/poll.h>
  16. #include <linux/i2c.h>
  17. #include <linux/types.h>
  18. #include <linux/videodev.h>
  19. #include <linux/init.h>
  20. #include <media/tuner.h>
  21. #include <media/audiochip.h>
  22. #include "msp3400.h"
  23. #define UNSET (-1U)
  24. /* standard i2c insmod options */
  25. static unsigned short normal_i2c[] = {
  26. 0x4b, /* tda8290 */
  27. 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
  28. 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
  29. I2C_CLIENT_END
  30. };
  31. I2C_CLIENT_INSMOD;
  32. /* insmod options used at init time => read/only */
  33. static unsigned int addr = 0;
  34. module_param(addr, int, 0444);
  35. static unsigned int no_autodetect = 0;
  36. module_param(no_autodetect, int, 0444);
  37. static unsigned int show_i2c = 0;
  38. module_param(show_i2c, int, 0444);
  39. /* insmod options used at runtime => read/write */
  40. unsigned int tuner_debug = 0;
  41. module_param(tuner_debug, int, 0644);
  42. static unsigned int tv_range[2] = { 44, 958 };
  43. static unsigned int radio_range[2] = { 65, 108 };
  44. module_param_array(tv_range, int, NULL, 0644);
  45. module_param_array(radio_range, int, NULL, 0644);
  46. MODULE_DESCRIPTION("device driver for various TV and TV+FM radio tuners");
  47. MODULE_AUTHOR("Ralph Metzler, Gerd Knorr, Gunther Mayer");
  48. MODULE_LICENSE("GPL");
  49. static struct i2c_driver driver;
  50. static struct i2c_client client_template;
  51. /* ---------------------------------------------------------------------- */
  52. /* Set tuner frequency, freq in Units of 62.5kHz = 1/16MHz */
  53. static void set_tv_freq(struct i2c_client *c, unsigned int freq)
  54. {
  55. struct tuner *t = i2c_get_clientdata(c);
  56. if (t->type == UNSET) {
  57. tuner_warn ("tuner type not set\n");
  58. return;
  59. }
  60. if (NULL == t->tv_freq) {
  61. tuner_warn ("Tuner has no way to set tv freq\n");
  62. return;
  63. }
  64. if (freq < tv_range[0] * 16 || freq > tv_range[1] * 16) {
  65. tuner_dbg ("TV freq (%d.%02d) out of range (%d-%d)\n",
  66. freq / 16, freq % 16 * 100 / 16, tv_range[0],
  67. tv_range[1]);
  68. }
  69. t->tv_freq(c, freq);
  70. }
  71. static void set_radio_freq(struct i2c_client *c, unsigned int freq)
  72. {
  73. struct tuner *t = i2c_get_clientdata(c);
  74. if (t->type == UNSET) {
  75. tuner_warn ("tuner type not set\n");
  76. return;
  77. }
  78. if (NULL == t->radio_freq) {
  79. tuner_warn ("tuner has no way to set radio frequency\n");
  80. return;
  81. }
  82. if (freq <= radio_range[0] * 16000 || freq >= radio_range[1] * 16000) {
  83. tuner_dbg ("radio freq (%d.%02d) out of range (%d-%d)\n",
  84. freq / 16000, freq % 16000 * 100 / 16000,
  85. radio_range[0], radio_range[1]);
  86. }
  87. t->radio_freq(c, freq);
  88. return;
  89. }
  90. static void set_freq(struct i2c_client *c, unsigned long freq)
  91. {
  92. struct tuner *t = i2c_get_clientdata(c);
  93. switch (t->mode) {
  94. case V4L2_TUNER_RADIO:
  95. tuner_dbg("radio freq set to %lu.%02lu\n",
  96. freq / 16000, freq % 16000 * 100 / 16000);
  97. set_radio_freq(c, freq);
  98. break;
  99. case V4L2_TUNER_ANALOG_TV:
  100. case V4L2_TUNER_DIGITAL_TV:
  101. tuner_dbg("tv freq set to %lu.%02lu\n",
  102. freq / 16, freq % 16 * 100 / 16);
  103. set_tv_freq(c, freq);
  104. break;
  105. }
  106. t->freq = freq;
  107. }
  108. static void set_type(struct i2c_client *c, unsigned int type,
  109. unsigned int new_mode_mask)
  110. {
  111. struct tuner *t = i2c_get_clientdata(c);
  112. unsigned char buffer[4];
  113. if (type == UNSET || type == TUNER_ABSENT) {
  114. tuner_dbg ("tuner 0x%02x: Tuner type absent\n",c->addr);
  115. return;
  116. }
  117. if (type >= tuner_count) {
  118. tuner_warn ("tuner 0x%02x: Tuner count greater than %d\n",c->addr,tuner_count);
  119. return;
  120. }
  121. /* This code detects calls by card attach_inform */
  122. if (NULL == t->i2c.dev.driver) {
  123. tuner_dbg ("tuner 0x%02x: called during i2c_client register by adapter's attach_inform\n", c->addr);
  124. t->type=type;
  125. return;
  126. }
  127. t->type = type;
  128. switch (t->type) {
  129. case TUNER_MT2032:
  130. microtune_init(c);
  131. break;
  132. case TUNER_PHILIPS_TDA8290:
  133. tda8290_init(c);
  134. break;
  135. case TUNER_TEA5767:
  136. if (tea5767_tuner_init(c) == EINVAL) {
  137. t->type = TUNER_ABSENT;
  138. t->mode_mask = T_UNINITIALIZED;
  139. return;
  140. }
  141. t->mode_mask = T_RADIO;
  142. break;
  143. case TUNER_PHILIPS_FMD1216ME_MK3:
  144. buffer[0] = 0x0b;
  145. buffer[1] = 0xdc;
  146. buffer[2] = 0x9c;
  147. buffer[3] = 0x60;
  148. i2c_master_send(c, buffer, 4);
  149. mdelay(1);
  150. buffer[2] = 0x86;
  151. buffer[3] = 0x54;
  152. i2c_master_send(c, buffer, 4);
  153. default_tuner_init(c);
  154. break;
  155. case TUNER_LG_TDVS_H062F:
  156. /* Set the Auxiliary Byte. */
  157. buffer[2] &= ~0x20;
  158. buffer[2] |= 0x18;
  159. buffer[3] = 0x20;
  160. i2c_master_send(c, buffer, 4);
  161. default_tuner_init(c);
  162. break;
  163. default:
  164. default_tuner_init(c);
  165. break;
  166. }
  167. if (t->mode_mask == T_UNINITIALIZED)
  168. t->mode_mask = new_mode_mask;
  169. set_freq(c, t->freq);
  170. tuner_dbg("%s %s I2C addr 0x%02x with type %d used for 0x%02x\n",
  171. c->adapter->name, c->driver->name, c->addr << 1, type,
  172. t->mode_mask);
  173. }
  174. /*
  175. * This function apply tuner config to tuner specified
  176. * by tun_setup structure. I addr is unset, then admin status
  177. * and tun addr status is more precise then current status,
  178. * it's applied. Otherwise status and type are applied only to
  179. * tuner with exactly the same addr.
  180. */
  181. static void set_addr(struct i2c_client *c, struct tuner_setup *tun_setup)
  182. {
  183. struct tuner *t = i2c_get_clientdata(c);
  184. if ((tun_setup->addr == ADDR_UNSET &&
  185. (t->mode_mask & tun_setup->mode_mask)) ||
  186. tun_setup->addr == c->addr) {
  187. set_type(c, tun_setup->type, tun_setup->mode_mask);
  188. }
  189. }
  190. static inline int check_mode(struct tuner *t, char *cmd)
  191. {
  192. if ((1 << t->mode & t->mode_mask) == 0) {
  193. return EINVAL;
  194. }
  195. switch (t->mode) {
  196. case V4L2_TUNER_RADIO:
  197. tuner_dbg("Cmd %s accepted for radio\n", cmd);
  198. break;
  199. case V4L2_TUNER_ANALOG_TV:
  200. tuner_dbg("Cmd %s accepted for analog TV\n", cmd);
  201. break;
  202. case V4L2_TUNER_DIGITAL_TV:
  203. tuner_dbg("Cmd %s accepted for digital TV\n", cmd);
  204. break;
  205. }
  206. return 0;
  207. }
  208. static char pal[] = "-";
  209. module_param_string(pal, pal, sizeof(pal), 0644);
  210. static char secam[] = "-";
  211. module_param_string(secam, secam, sizeof(secam), 0644);
  212. /* get more precise norm info from insmod option */
  213. static int tuner_fixup_std(struct tuner *t)
  214. {
  215. if ((t->std & V4L2_STD_PAL) == V4L2_STD_PAL) {
  216. switch (pal[0]) {
  217. case 'b':
  218. case 'B':
  219. case 'g':
  220. case 'G':
  221. tuner_dbg ("insmod fixup: PAL => PAL-BG\n");
  222. t->std = V4L2_STD_PAL_BG;
  223. break;
  224. case 'i':
  225. case 'I':
  226. tuner_dbg ("insmod fixup: PAL => PAL-I\n");
  227. t->std = V4L2_STD_PAL_I;
  228. break;
  229. case 'd':
  230. case 'D':
  231. case 'k':
  232. case 'K':
  233. tuner_dbg ("insmod fixup: PAL => PAL-DK\n");
  234. t->std = V4L2_STD_PAL_DK;
  235. break;
  236. case 'M':
  237. case 'm':
  238. tuner_dbg ("insmod fixup: PAL => PAL-M\n");
  239. t->std = V4L2_STD_PAL_M;
  240. break;
  241. case 'N':
  242. case 'n':
  243. tuner_dbg ("insmod fixup: PAL => PAL-N\n");
  244. t->std = V4L2_STD_PAL_N;
  245. break;
  246. case '-':
  247. /* default parameter, do nothing */
  248. break;
  249. default:
  250. tuner_warn ("pal= argument not recognised\n");
  251. break;
  252. }
  253. }
  254. if ((t->std & V4L2_STD_SECAM) == V4L2_STD_SECAM) {
  255. switch (secam[0]) {
  256. case 'd':
  257. case 'D':
  258. case 'k':
  259. case 'K':
  260. tuner_dbg ("insmod fixup: SECAM => SECAM-DK\n");
  261. t->std = V4L2_STD_SECAM_DK;
  262. break;
  263. case 'l':
  264. case 'L':
  265. tuner_dbg ("insmod fixup: SECAM => SECAM-L\n");
  266. t->std = V4L2_STD_SECAM_L;
  267. break;
  268. case '-':
  269. /* default parameter, do nothing */
  270. break;
  271. default:
  272. tuner_warn ("secam= argument not recognised\n");
  273. break;
  274. }
  275. }
  276. return 0;
  277. }
  278. /* ---------------------------------------------------------------------- */
  279. /* static var Used only in tuner_attach and tuner_probe */
  280. static unsigned default_mode_mask;
  281. /* During client attach, set_type is called by adapter's attach_inform callback.
  282. set_type must then be completed by tuner_attach.
  283. */
  284. static int tuner_attach(struct i2c_adapter *adap, int addr, int kind)
  285. {
  286. struct tuner *t;
  287. client_template.adapter = adap;
  288. client_template.addr = addr;
  289. t = kmalloc(sizeof(struct tuner), GFP_KERNEL);
  290. if (NULL == t)
  291. return -ENOMEM;
  292. memset(t, 0, sizeof(struct tuner));
  293. memcpy(&t->i2c, &client_template, sizeof(struct i2c_client));
  294. i2c_set_clientdata(&t->i2c, t);
  295. t->type = UNSET;
  296. t->radio_if2 = 10700 * 1000; /* 10.7MHz - FM radio */
  297. t->audmode = V4L2_TUNER_MODE_STEREO;
  298. t->mode_mask = T_UNINITIALIZED;
  299. tuner_info("chip found @ 0x%x (%s)\n", addr << 1, adap->name);
  300. if (show_i2c) {
  301. unsigned char buffer[16];
  302. int i,rc;
  303. memset(buffer, 0, sizeof(buffer));
  304. rc = i2c_master_recv(&t->i2c, buffer, sizeof(buffer));
  305. printk("tuner-%04x I2C RECV = ",addr);
  306. for (i=0;i<rc;i++)
  307. printk("%02x ",buffer[i]);
  308. printk("\n");
  309. }
  310. /* TEA5767 autodetection code - only for addr = 0xc0 */
  311. if (!no_autodetect) {
  312. if (addr == 0x60) {
  313. if (tea5767_autodetection(&t->i2c) != EINVAL) {
  314. t->type = TUNER_TEA5767;
  315. t->mode_mask = T_RADIO;
  316. t->mode = T_STANDBY;
  317. t->freq = 87.5 * 16; /* Sets freq to FM range */
  318. default_mode_mask &= ~T_RADIO;
  319. i2c_attach_client (&t->i2c);
  320. set_type(&t->i2c,t->type, t->mode_mask);
  321. return 0;
  322. }
  323. }
  324. }
  325. /* Initializes only the first adapter found */
  326. if (default_mode_mask != T_UNINITIALIZED) {
  327. tuner_dbg ("Setting mode_mask to 0x%02x\n", default_mode_mask);
  328. t->mode_mask = default_mode_mask;
  329. t->freq = 400 * 16; /* Sets freq to VHF High */
  330. default_mode_mask = T_UNINITIALIZED;
  331. }
  332. /* Should be just before return */
  333. i2c_attach_client (&t->i2c);
  334. set_type (&t->i2c,t->type, t->mode_mask);
  335. return 0;
  336. }
  337. static int tuner_probe(struct i2c_adapter *adap)
  338. {
  339. if (0 != addr) {
  340. normal_i2c[0] = addr;
  341. normal_i2c[1] = I2C_CLIENT_END;
  342. }
  343. default_mode_mask = T_RADIO | T_ANALOG_TV | T_DIGITAL_TV;
  344. if (adap->class & I2C_CLASS_TV_ANALOG)
  345. return i2c_probe(adap, &addr_data, tuner_attach);
  346. return 0;
  347. }
  348. static int tuner_detach(struct i2c_client *client)
  349. {
  350. struct tuner *t = i2c_get_clientdata(client);
  351. int err;
  352. err = i2c_detach_client(&t->i2c);
  353. if (err) {
  354. tuner_warn
  355. ("Client deregistration failed, client not detached.\n");
  356. return err;
  357. }
  358. kfree(t);
  359. return 0;
  360. }
  361. /*
  362. * Switch tuner to other mode. If tuner support both tv and radio,
  363. * set another frequency to some value (This is needed for some pal
  364. * tuners to avoid locking). Otherwise, just put second tuner in
  365. * standby mode.
  366. */
  367. static inline int set_mode(struct i2c_client *client, struct tuner *t, int mode, char *cmd)
  368. {
  369. if (mode == t->mode)
  370. return 0;
  371. t->mode = mode;
  372. if (check_mode(t, cmd) == EINVAL) {
  373. t->mode = T_STANDBY;
  374. if (t->standby)
  375. t->standby (client);
  376. return EINVAL;
  377. }
  378. return 0;
  379. }
  380. #define switch_v4l2() if (!t->using_v4l2) \
  381. tuner_dbg("switching to v4l2\n"); \
  382. t->using_v4l2 = 1;
  383. static inline int check_v4l2(struct tuner *t)
  384. {
  385. if (t->using_v4l2) {
  386. tuner_dbg ("ignore v4l1 call\n");
  387. return EINVAL;
  388. }
  389. return 0;
  390. }
  391. static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
  392. {
  393. struct tuner *t = i2c_get_clientdata(client);
  394. unsigned int *iarg = (int *)arg;
  395. switch (cmd) {
  396. /* --- configuration --- */
  397. case TUNER_SET_TYPE_ADDR:
  398. tuner_dbg ("Calling set_type_addr for type=%d, addr=0x%02x, mode=0x%02x\n",
  399. ((struct tuner_setup *)arg)->type,
  400. ((struct tuner_setup *)arg)->addr,
  401. ((struct tuner_setup *)arg)->mode_mask);
  402. set_addr(client, (struct tuner_setup *)arg);
  403. break;
  404. case AUDC_SET_RADIO:
  405. set_mode(client,t,V4L2_TUNER_RADIO, "AUDC_SET_RADIO");
  406. break;
  407. case TUNER_SET_STANDBY:
  408. {
  409. if (check_mode(t, "TUNER_SET_STANDBY") == EINVAL)
  410. return 0;
  411. if (t->standby)
  412. t->standby (client);
  413. break;
  414. }
  415. case AUDC_CONFIG_PINNACLE:
  416. if (check_mode(t, "AUDC_CONFIG_PINNACLE") == EINVAL)
  417. return 0;
  418. switch (*iarg) {
  419. case 2:
  420. tuner_dbg("pinnacle pal\n");
  421. t->radio_if2 = 33300 * 1000;
  422. break;
  423. case 3:
  424. tuner_dbg("pinnacle ntsc\n");
  425. t->radio_if2 = 41300 * 1000;
  426. break;
  427. }
  428. break;
  429. case VIDIOCSAUDIO:
  430. if (check_mode(t, "VIDIOCSAUDIO") == EINVAL)
  431. return 0;
  432. if (check_v4l2(t) == EINVAL)
  433. return 0;
  434. /* Should be implemented, since bttv calls it */
  435. tuner_dbg("VIDIOCSAUDIO not implemented.\n");
  436. break;
  437. case MSP_SET_MATRIX:
  438. case TDA9887_SET_CONFIG:
  439. break;
  440. /* --- v4l ioctls --- */
  441. /* take care: bttv does userspace copying, we'll get a
  442. kernel pointer here... */
  443. case VIDIOCSCHAN:
  444. {
  445. static const v4l2_std_id map[] = {
  446. [VIDEO_MODE_PAL] = V4L2_STD_PAL,
  447. [VIDEO_MODE_NTSC] = V4L2_STD_NTSC_M,
  448. [VIDEO_MODE_SECAM] = V4L2_STD_SECAM,
  449. [4 /* bttv */ ] = V4L2_STD_PAL_M,
  450. [5 /* bttv */ ] = V4L2_STD_PAL_N,
  451. [6 /* bttv */ ] = V4L2_STD_NTSC_M_JP,
  452. };
  453. struct video_channel *vc = arg;
  454. if (check_v4l2(t) == EINVAL)
  455. return 0;
  456. if (set_mode(client,t,V4L2_TUNER_ANALOG_TV, "VIDIOCSCHAN")==EINVAL)
  457. return 0;
  458. if (vc->norm < ARRAY_SIZE(map))
  459. t->std = map[vc->norm];
  460. tuner_fixup_std(t);
  461. if (t->freq)
  462. set_tv_freq(client, t->freq);
  463. return 0;
  464. }
  465. case VIDIOCSFREQ:
  466. {
  467. unsigned long *v = arg;
  468. if (check_mode(t, "VIDIOCSFREQ") == EINVAL)
  469. return 0;
  470. if (check_v4l2(t) == EINVAL)
  471. return 0;
  472. set_freq(client, *v);
  473. return 0;
  474. }
  475. case VIDIOCGTUNER:
  476. {
  477. struct video_tuner *vt = arg;
  478. if (check_mode(t, "VIDIOCGTUNER") == EINVAL)
  479. return 0;
  480. if (check_v4l2(t) == EINVAL)
  481. return 0;
  482. if (V4L2_TUNER_RADIO == t->mode) {
  483. if (t->has_signal)
  484. vt->signal = t->has_signal(client);
  485. if (t->is_stereo) {
  486. if (t->is_stereo(client))
  487. vt->flags |=
  488. VIDEO_TUNER_STEREO_ON;
  489. else
  490. vt->flags &=
  491. ~VIDEO_TUNER_STEREO_ON;
  492. }
  493. vt->flags |= VIDEO_TUNER_LOW; /* Allow freqs at 62.5 Hz */
  494. vt->rangelow = radio_range[0] * 16000;
  495. vt->rangehigh = radio_range[1] * 16000;
  496. } else {
  497. vt->rangelow = tv_range[0] * 16;
  498. vt->rangehigh = tv_range[1] * 16;
  499. }
  500. return 0;
  501. }
  502. case VIDIOCGAUDIO:
  503. {
  504. struct video_audio *va = arg;
  505. if (check_mode(t, "VIDIOCGAUDIO") == EINVAL)
  506. return 0;
  507. if (check_v4l2(t) == EINVAL)
  508. return 0;
  509. if (V4L2_TUNER_RADIO == t->mode && t->is_stereo)
  510. va->mode = t->is_stereo(client)
  511. ? VIDEO_SOUND_STEREO : VIDEO_SOUND_MONO;
  512. return 0;
  513. }
  514. case VIDIOC_S_STD:
  515. {
  516. v4l2_std_id *id = arg;
  517. if (set_mode (client, t, V4L2_TUNER_ANALOG_TV, "VIDIOC_S_STD")
  518. == EINVAL)
  519. return 0;
  520. switch_v4l2();
  521. t->std = *id;
  522. tuner_fixup_std(t);
  523. if (t->freq)
  524. set_freq(client, t->freq);
  525. break;
  526. }
  527. case VIDIOC_S_FREQUENCY:
  528. {
  529. struct v4l2_frequency *f = arg;
  530. t->freq = f->frequency;
  531. switch_v4l2();
  532. if (V4L2_TUNER_RADIO == f->type &&
  533. V4L2_TUNER_RADIO != t->mode) {
  534. if (set_mode (client, t, f->type, "VIDIOC_S_FREQUENCY")
  535. == EINVAL)
  536. return 0;
  537. }
  538. set_freq(client,t->freq);
  539. break;
  540. }
  541. case VIDIOC_G_FREQUENCY:
  542. {
  543. struct v4l2_frequency *f = arg;
  544. if (check_mode(t, "VIDIOC_G_FREQUENCY") == EINVAL)
  545. return 0;
  546. switch_v4l2();
  547. f->type = t->mode;
  548. f->frequency = t->freq;
  549. break;
  550. }
  551. case VIDIOC_G_TUNER:
  552. {
  553. struct v4l2_tuner *tuner = arg;
  554. if (check_mode(t, "VIDIOC_G_TUNER") == EINVAL)
  555. return 0;
  556. switch_v4l2();
  557. if (V4L2_TUNER_RADIO == t->mode) {
  558. if (t->has_signal)
  559. tuner->signal = t->has_signal(client);
  560. if (t->is_stereo) {
  561. if (t->is_stereo(client)) {
  562. tuner->rxsubchans =
  563. V4L2_TUNER_SUB_STEREO |
  564. V4L2_TUNER_SUB_MONO;
  565. } else {
  566. tuner->rxsubchans =
  567. V4L2_TUNER_SUB_MONO;
  568. }
  569. }
  570. tuner->capability |=
  571. V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
  572. tuner->audmode = t->audmode;
  573. tuner->rangelow = radio_range[0] * 16000;
  574. tuner->rangehigh = radio_range[1] * 16000;
  575. } else {
  576. tuner->rangelow = tv_range[0] * 16;
  577. tuner->rangehigh = tv_range[1] * 16;
  578. }
  579. break;
  580. }
  581. case VIDIOC_S_TUNER:
  582. {
  583. struct v4l2_tuner *tuner = arg;
  584. if (check_mode(t, "VIDIOC_S_TUNER") == EINVAL)
  585. return 0;
  586. switch_v4l2();
  587. if (V4L2_TUNER_RADIO == t->mode) {
  588. t->audmode = tuner->audmode;
  589. set_radio_freq(client, t->freq);
  590. }
  591. break;
  592. }
  593. default:
  594. tuner_dbg("Unimplemented IOCTL 0x%08x(dir=%d,tp=0x%02x,nr=%d,sz=%d)\n",
  595. cmd, _IOC_DIR(cmd), _IOC_TYPE(cmd),
  596. _IOC_NR(cmd), _IOC_SIZE(cmd));
  597. break;
  598. }
  599. return 0;
  600. }
  601. static int tuner_suspend(struct device *dev, pm_message_t state, u32 level)
  602. {
  603. struct i2c_client *c = container_of (dev, struct i2c_client, dev);
  604. struct tuner *t = i2c_get_clientdata (c);
  605. tuner_dbg ("suspend\n");
  606. /* FIXME: power down ??? */
  607. return 0;
  608. }
  609. static int tuner_resume(struct device *dev, u32 level)
  610. {
  611. struct i2c_client *c = container_of (dev, struct i2c_client, dev);
  612. struct tuner *t = i2c_get_clientdata (c);
  613. tuner_dbg ("resume\n");
  614. if (t->freq)
  615. set_freq(c, t->freq);
  616. return 0;
  617. }
  618. /* ----------------------------------------------------------------------- */
  619. static struct i2c_driver driver = {
  620. .owner = THIS_MODULE,
  621. .name = "tuner",
  622. .id = I2C_DRIVERID_TUNER,
  623. .flags = I2C_DF_NOTIFY,
  624. .attach_adapter = tuner_probe,
  625. .detach_client = tuner_detach,
  626. .command = tuner_command,
  627. .driver = {
  628. .suspend = tuner_suspend,
  629. .resume = tuner_resume,
  630. },
  631. };
  632. static struct i2c_client client_template = {
  633. .name = "(tuner unset)",
  634. .flags = I2C_CLIENT_ALLOW_USE,
  635. .driver = &driver,
  636. };
  637. static int __init tuner_init_module(void)
  638. {
  639. return i2c_add_driver(&driver);
  640. }
  641. static void __exit tuner_cleanup_module(void)
  642. {
  643. i2c_del_driver(&driver);
  644. }
  645. module_init(tuner_init_module);
  646. module_exit(tuner_cleanup_module);
  647. /*
  648. * Overrides for Emacs so that we follow Linus's tabbing style.
  649. * ---------------------------------------------------------------------------
  650. * Local variables:
  651. * c-basic-offset: 8
  652. * End:
  653. */