tuner-core.c 16 KB

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