tuner-core.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  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. 0x42, 0x43, 0x4a, 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. case TUNER_PHILIPS_TD1316:
  164. buffer[0] = 0x0b;
  165. buffer[1] = 0xdc;
  166. buffer[2] = 0x86;
  167. buffer[3] = 0xa4;
  168. i2c_master_send(c,buffer,4);
  169. default_tuner_init(c);
  170. default:
  171. default_tuner_init(c);
  172. break;
  173. }
  174. if (t->mode_mask == T_UNINITIALIZED)
  175. t->mode_mask = new_mode_mask;
  176. set_freq(c, t->freq);
  177. tuner_dbg("%s %s I2C addr 0x%02x with type %d used for 0x%02x\n",
  178. c->adapter->name, c->driver->name, c->addr << 1, type,
  179. t->mode_mask);
  180. }
  181. /*
  182. * This function apply tuner config to tuner specified
  183. * by tun_setup structure. I addr is unset, then admin status
  184. * and tun addr status is more precise then current status,
  185. * it's applied. Otherwise status and type are applied only to
  186. * tuner with exactly the same addr.
  187. */
  188. static void set_addr(struct i2c_client *c, struct tuner_setup *tun_setup)
  189. {
  190. struct tuner *t = i2c_get_clientdata(c);
  191. if ((tun_setup->addr == ADDR_UNSET &&
  192. (t->mode_mask & tun_setup->mode_mask)) ||
  193. tun_setup->addr == c->addr) {
  194. set_type(c, tun_setup->type, tun_setup->mode_mask);
  195. }
  196. }
  197. static inline int check_mode(struct tuner *t, char *cmd)
  198. {
  199. if ((1 << t->mode & t->mode_mask) == 0) {
  200. return EINVAL;
  201. }
  202. switch (t->mode) {
  203. case V4L2_TUNER_RADIO:
  204. tuner_dbg("Cmd %s accepted for radio\n", cmd);
  205. break;
  206. case V4L2_TUNER_ANALOG_TV:
  207. tuner_dbg("Cmd %s accepted for analog TV\n", cmd);
  208. break;
  209. case V4L2_TUNER_DIGITAL_TV:
  210. tuner_dbg("Cmd %s accepted for digital TV\n", cmd);
  211. break;
  212. }
  213. return 0;
  214. }
  215. static char pal[] = "-";
  216. module_param_string(pal, pal, sizeof(pal), 0644);
  217. static char secam[] = "-";
  218. module_param_string(secam, secam, sizeof(secam), 0644);
  219. /* get more precise norm info from insmod option */
  220. static int tuner_fixup_std(struct tuner *t)
  221. {
  222. if ((t->std & V4L2_STD_PAL) == V4L2_STD_PAL) {
  223. switch (pal[0]) {
  224. case 'b':
  225. case 'B':
  226. case 'g':
  227. case 'G':
  228. tuner_dbg ("insmod fixup: PAL => PAL-BG\n");
  229. t->std = V4L2_STD_PAL_BG;
  230. break;
  231. case 'i':
  232. case 'I':
  233. tuner_dbg ("insmod fixup: PAL => PAL-I\n");
  234. t->std = V4L2_STD_PAL_I;
  235. break;
  236. case 'd':
  237. case 'D':
  238. case 'k':
  239. case 'K':
  240. tuner_dbg ("insmod fixup: PAL => PAL-DK\n");
  241. t->std = V4L2_STD_PAL_DK;
  242. break;
  243. case 'M':
  244. case 'm':
  245. tuner_dbg ("insmod fixup: PAL => PAL-M\n");
  246. t->std = V4L2_STD_PAL_M;
  247. break;
  248. case 'N':
  249. case 'n':
  250. tuner_dbg ("insmod fixup: PAL => PAL-N\n");
  251. t->std = V4L2_STD_PAL_N;
  252. break;
  253. case '-':
  254. /* default parameter, do nothing */
  255. break;
  256. default:
  257. tuner_warn ("pal= argument not recognised\n");
  258. break;
  259. }
  260. }
  261. if ((t->std & V4L2_STD_SECAM) == V4L2_STD_SECAM) {
  262. switch (secam[0]) {
  263. case 'd':
  264. case 'D':
  265. case 'k':
  266. case 'K':
  267. tuner_dbg ("insmod fixup: SECAM => SECAM-DK\n");
  268. t->std = V4L2_STD_SECAM_DK;
  269. break;
  270. case 'l':
  271. case 'L':
  272. tuner_dbg ("insmod fixup: SECAM => SECAM-L\n");
  273. t->std = V4L2_STD_SECAM_L;
  274. break;
  275. case '-':
  276. /* default parameter, do nothing */
  277. break;
  278. default:
  279. tuner_warn ("secam= argument not recognised\n");
  280. break;
  281. }
  282. }
  283. return 0;
  284. }
  285. /* ---------------------------------------------------------------------- */
  286. /* static var Used only in tuner_attach and tuner_probe */
  287. static unsigned default_mode_mask;
  288. /* During client attach, set_type is called by adapter's attach_inform callback.
  289. set_type must then be completed by tuner_attach.
  290. */
  291. static int tuner_attach(struct i2c_adapter *adap, int addr, int kind)
  292. {
  293. struct tuner *t;
  294. client_template.adapter = adap;
  295. client_template.addr = addr;
  296. t = kmalloc(sizeof(struct tuner), GFP_KERNEL);
  297. if (NULL == t)
  298. return -ENOMEM;
  299. memset(t, 0, sizeof(struct tuner));
  300. memcpy(&t->i2c, &client_template, sizeof(struct i2c_client));
  301. i2c_set_clientdata(&t->i2c, t);
  302. t->type = UNSET;
  303. t->radio_if2 = 10700 * 1000; /* 10.7MHz - FM radio */
  304. t->audmode = V4L2_TUNER_MODE_STEREO;
  305. t->mode_mask = T_UNINITIALIZED;
  306. if (show_i2c) {
  307. unsigned char buffer[16];
  308. int i,rc;
  309. memset(buffer, 0, sizeof(buffer));
  310. rc = i2c_master_recv(&t->i2c, buffer, sizeof(buffer));
  311. tuner_info("I2C RECV = ");
  312. for (i=0;i<rc;i++)
  313. printk("%02x ",buffer[i]);
  314. printk("\n");
  315. }
  316. /* TEA5767 autodetection code - only for addr = 0xc0 */
  317. if (!no_autodetect) {
  318. switch (addr) {
  319. case 0x60:
  320. if (tea5767_autodetection(&t->i2c) != EINVAL) {
  321. t->type = TUNER_TEA5767;
  322. t->mode_mask = T_RADIO;
  323. t->mode = T_STANDBY;
  324. t->freq = 87.5 * 16; /* Sets freq to FM range */
  325. default_mode_mask &= ~T_RADIO;
  326. goto register_client;
  327. }
  328. case 0x42:
  329. case 0x43:
  330. case 0x4a:
  331. case 0x4b:
  332. /* If chip is not tda8290, don't register.
  333. since it can be tda9887*/
  334. if (tda8290_probe(&t->i2c) != 0) {
  335. kfree(t);
  336. return 0;
  337. }
  338. }
  339. }
  340. /* Initializes only the first adapter found */
  341. if (default_mode_mask != T_UNINITIALIZED) {
  342. tuner_dbg ("Setting mode_mask to 0x%02x\n", default_mode_mask);
  343. t->mode_mask = default_mode_mask;
  344. t->freq = 400 * 16; /* Sets freq to VHF High */
  345. default_mode_mask = T_UNINITIALIZED;
  346. }
  347. /* Should be just before return */
  348. register_client:
  349. tuner_info("chip found @ 0x%x (%s)\n", addr << 1, adap->name);
  350. i2c_attach_client (&t->i2c);
  351. set_type (&t->i2c,t->type, t->mode_mask);
  352. return 0;
  353. }
  354. static int tuner_probe(struct i2c_adapter *adap)
  355. {
  356. if (0 != addr) {
  357. normal_i2c[0] = addr;
  358. normal_i2c[1] = I2C_CLIENT_END;
  359. }
  360. default_mode_mask = T_RADIO | T_ANALOG_TV | T_DIGITAL_TV;
  361. if (adap->class & I2C_CLASS_TV_ANALOG)
  362. return i2c_probe(adap, &addr_data, tuner_attach);
  363. return 0;
  364. }
  365. static int tuner_detach(struct i2c_client *client)
  366. {
  367. struct tuner *t = i2c_get_clientdata(client);
  368. int err;
  369. err = i2c_detach_client(&t->i2c);
  370. if (err) {
  371. tuner_warn
  372. ("Client deregistration failed, client not detached.\n");
  373. return err;
  374. }
  375. kfree(t);
  376. return 0;
  377. }
  378. /*
  379. * Switch tuner to other mode. If tuner support both tv and radio,
  380. * set another frequency to some value (This is needed for some pal
  381. * tuners to avoid locking). Otherwise, just put second tuner in
  382. * standby mode.
  383. */
  384. static inline int set_mode(struct i2c_client *client, struct tuner *t, int mode, char *cmd)
  385. {
  386. if (mode == t->mode)
  387. return 0;
  388. t->mode = mode;
  389. if (check_mode(t, cmd) == EINVAL) {
  390. t->mode = T_STANDBY;
  391. if (t->standby)
  392. t->standby (client);
  393. return EINVAL;
  394. }
  395. return 0;
  396. }
  397. #define switch_v4l2() if (!t->using_v4l2) \
  398. tuner_dbg("switching to v4l2\n"); \
  399. t->using_v4l2 = 1;
  400. static inline int check_v4l2(struct tuner *t)
  401. {
  402. if (t->using_v4l2) {
  403. tuner_dbg ("ignore v4l1 call\n");
  404. return EINVAL;
  405. }
  406. return 0;
  407. }
  408. static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
  409. {
  410. struct tuner *t = i2c_get_clientdata(client);
  411. unsigned int *iarg = (int *)arg;
  412. switch (cmd) {
  413. /* --- configuration --- */
  414. case TUNER_SET_TYPE_ADDR:
  415. tuner_dbg ("Calling set_type_addr for type=%d, addr=0x%02x, mode=0x%02x\n",
  416. ((struct tuner_setup *)arg)->type,
  417. ((struct tuner_setup *)arg)->addr,
  418. ((struct tuner_setup *)arg)->mode_mask);
  419. set_addr(client, (struct tuner_setup *)arg);
  420. break;
  421. case AUDC_SET_RADIO:
  422. set_mode(client,t,V4L2_TUNER_RADIO, "AUDC_SET_RADIO");
  423. break;
  424. case TUNER_SET_STANDBY:
  425. {
  426. if (check_mode(t, "TUNER_SET_STANDBY") == EINVAL)
  427. return 0;
  428. if (t->standby)
  429. t->standby (client);
  430. break;
  431. }
  432. case AUDC_CONFIG_PINNACLE:
  433. if (check_mode(t, "AUDC_CONFIG_PINNACLE") == EINVAL)
  434. return 0;
  435. switch (*iarg) {
  436. case 2:
  437. tuner_dbg("pinnacle pal\n");
  438. t->radio_if2 = 33300 * 1000;
  439. break;
  440. case 3:
  441. tuner_dbg("pinnacle ntsc\n");
  442. t->radio_if2 = 41300 * 1000;
  443. break;
  444. }
  445. break;
  446. case VIDIOCSAUDIO:
  447. if (check_mode(t, "VIDIOCSAUDIO") == EINVAL)
  448. return 0;
  449. if (check_v4l2(t) == EINVAL)
  450. return 0;
  451. /* Should be implemented, since bttv calls it */
  452. tuner_dbg("VIDIOCSAUDIO not implemented.\n");
  453. break;
  454. case MSP_SET_MATRIX:
  455. case TDA9887_SET_CONFIG:
  456. break;
  457. /* --- v4l ioctls --- */
  458. /* take care: bttv does userspace copying, we'll get a
  459. kernel pointer here... */
  460. case VIDIOCSCHAN:
  461. {
  462. static const v4l2_std_id map[] = {
  463. [VIDEO_MODE_PAL] = V4L2_STD_PAL,
  464. [VIDEO_MODE_NTSC] = V4L2_STD_NTSC_M,
  465. [VIDEO_MODE_SECAM] = V4L2_STD_SECAM,
  466. [4 /* bttv */ ] = V4L2_STD_PAL_M,
  467. [5 /* bttv */ ] = V4L2_STD_PAL_N,
  468. [6 /* bttv */ ] = V4L2_STD_NTSC_M_JP,
  469. };
  470. struct video_channel *vc = arg;
  471. if (check_v4l2(t) == EINVAL)
  472. return 0;
  473. if (set_mode(client,t,V4L2_TUNER_ANALOG_TV, "VIDIOCSCHAN")==EINVAL)
  474. return 0;
  475. if (vc->norm < ARRAY_SIZE(map))
  476. t->std = map[vc->norm];
  477. tuner_fixup_std(t);
  478. if (t->freq)
  479. set_tv_freq(client, t->freq);
  480. return 0;
  481. }
  482. case VIDIOCSFREQ:
  483. {
  484. unsigned long *v = arg;
  485. if (check_mode(t, "VIDIOCSFREQ") == EINVAL)
  486. return 0;
  487. if (check_v4l2(t) == EINVAL)
  488. return 0;
  489. set_freq(client, *v);
  490. return 0;
  491. }
  492. case VIDIOCGTUNER:
  493. {
  494. struct video_tuner *vt = arg;
  495. if (check_mode(t, "VIDIOCGTUNER") == EINVAL)
  496. return 0;
  497. if (check_v4l2(t) == EINVAL)
  498. return 0;
  499. if (V4L2_TUNER_RADIO == t->mode) {
  500. if (t->has_signal)
  501. vt->signal = t->has_signal(client);
  502. if (t->is_stereo) {
  503. if (t->is_stereo(client))
  504. vt->flags |=
  505. VIDEO_TUNER_STEREO_ON;
  506. else
  507. vt->flags &=
  508. ~VIDEO_TUNER_STEREO_ON;
  509. }
  510. vt->flags |= VIDEO_TUNER_LOW; /* Allow freqs at 62.5 Hz */
  511. vt->rangelow = radio_range[0] * 16000;
  512. vt->rangehigh = radio_range[1] * 16000;
  513. } else {
  514. vt->rangelow = tv_range[0] * 16;
  515. vt->rangehigh = tv_range[1] * 16;
  516. }
  517. return 0;
  518. }
  519. case VIDIOCGAUDIO:
  520. {
  521. struct video_audio *va = arg;
  522. if (check_mode(t, "VIDIOCGAUDIO") == EINVAL)
  523. return 0;
  524. if (check_v4l2(t) == EINVAL)
  525. return 0;
  526. if (V4L2_TUNER_RADIO == t->mode && t->is_stereo)
  527. va->mode = t->is_stereo(client)
  528. ? VIDEO_SOUND_STEREO : VIDEO_SOUND_MONO;
  529. return 0;
  530. }
  531. case VIDIOC_S_STD:
  532. {
  533. v4l2_std_id *id = arg;
  534. if (set_mode (client, t, V4L2_TUNER_ANALOG_TV, "VIDIOC_S_STD")
  535. == EINVAL)
  536. return 0;
  537. switch_v4l2();
  538. t->std = *id;
  539. tuner_fixup_std(t);
  540. if (t->freq)
  541. set_freq(client, t->freq);
  542. break;
  543. }
  544. case VIDIOC_S_FREQUENCY:
  545. {
  546. struct v4l2_frequency *f = arg;
  547. t->freq = f->frequency;
  548. switch_v4l2();
  549. if (V4L2_TUNER_RADIO == f->type &&
  550. V4L2_TUNER_RADIO != t->mode) {
  551. if (set_mode (client, t, f->type, "VIDIOC_S_FREQUENCY")
  552. == EINVAL)
  553. return 0;
  554. }
  555. set_freq(client,t->freq);
  556. break;
  557. }
  558. case VIDIOC_G_FREQUENCY:
  559. {
  560. struct v4l2_frequency *f = arg;
  561. if (check_mode(t, "VIDIOC_G_FREQUENCY") == EINVAL)
  562. return 0;
  563. switch_v4l2();
  564. f->type = t->mode;
  565. f->frequency = t->freq;
  566. break;
  567. }
  568. case VIDIOC_G_TUNER:
  569. {
  570. struct v4l2_tuner *tuner = arg;
  571. if (check_mode(t, "VIDIOC_G_TUNER") == EINVAL)
  572. return 0;
  573. switch_v4l2();
  574. if (V4L2_TUNER_RADIO == t->mode) {
  575. if (t->has_signal)
  576. tuner->signal = t->has_signal(client);
  577. if (t->is_stereo) {
  578. if (t->is_stereo(client)) {
  579. tuner->rxsubchans =
  580. V4L2_TUNER_SUB_STEREO |
  581. V4L2_TUNER_SUB_MONO;
  582. } else {
  583. tuner->rxsubchans =
  584. V4L2_TUNER_SUB_MONO;
  585. }
  586. }
  587. tuner->capability |=
  588. V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
  589. tuner->audmode = t->audmode;
  590. tuner->rangelow = radio_range[0] * 16000;
  591. tuner->rangehigh = radio_range[1] * 16000;
  592. } else {
  593. tuner->rangelow = tv_range[0] * 16;
  594. tuner->rangehigh = tv_range[1] * 16;
  595. }
  596. break;
  597. }
  598. case VIDIOC_S_TUNER:
  599. {
  600. struct v4l2_tuner *tuner = arg;
  601. if (check_mode(t, "VIDIOC_S_TUNER") == EINVAL)
  602. return 0;
  603. switch_v4l2();
  604. if (V4L2_TUNER_RADIO == t->mode) {
  605. t->audmode = tuner->audmode;
  606. set_radio_freq(client, t->freq);
  607. }
  608. break;
  609. }
  610. default:
  611. tuner_dbg("Unimplemented IOCTL 0x%08x(dir=%d,tp='%c',nr=%d,sz=%d)\n",
  612. cmd, _IOC_DIR(cmd), _IOC_TYPE(cmd),
  613. _IOC_NR(cmd), _IOC_SIZE(cmd));
  614. break;
  615. }
  616. return 0;
  617. }
  618. static int tuner_suspend(struct device *dev, pm_message_t state)
  619. {
  620. struct i2c_client *c = container_of (dev, struct i2c_client, dev);
  621. struct tuner *t = i2c_get_clientdata (c);
  622. tuner_dbg ("suspend\n");
  623. /* FIXME: power down ??? */
  624. return 0;
  625. }
  626. static int tuner_resume(struct device *dev)
  627. {
  628. struct i2c_client *c = container_of (dev, struct i2c_client, dev);
  629. struct tuner *t = i2c_get_clientdata (c);
  630. tuner_dbg ("resume\n");
  631. if (t->freq)
  632. set_freq(c, t->freq);
  633. return 0;
  634. }
  635. /* ----------------------------------------------------------------------- */
  636. static struct i2c_driver driver = {
  637. .owner = THIS_MODULE,
  638. .name = "tuner",
  639. .id = I2C_DRIVERID_TUNER,
  640. .flags = I2C_DF_NOTIFY,
  641. .attach_adapter = tuner_probe,
  642. .detach_client = tuner_detach,
  643. .command = tuner_command,
  644. .driver = {
  645. .suspend = tuner_suspend,
  646. .resume = tuner_resume,
  647. },
  648. };
  649. static struct i2c_client client_template = {
  650. .name = "(tuner unset)",
  651. .flags = I2C_CLIENT_ALLOW_USE,
  652. .driver = &driver,
  653. };
  654. static int __init tuner_init_module(void)
  655. {
  656. return i2c_add_driver(&driver);
  657. }
  658. static void __exit tuner_cleanup_module(void)
  659. {
  660. i2c_del_driver(&driver);
  661. }
  662. module_init(tuner_init_module);
  663. module_exit(tuner_cleanup_module);
  664. /*
  665. * Overrides for Emacs so that we follow Linus's tabbing style.
  666. * ---------------------------------------------------------------------------
  667. * Local variables:
  668. * c-basic-offset: 8
  669. * End:
  670. */