tuner-core.c 17 KB

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