tuner-core.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306
  1. /*
  2. * i2c tv tuner chip device driver
  3. * core core, i.e. kernel interfaces, registering and so on
  4. *
  5. * Copyright(c) by Ralph Metzler, Gerd Knorr, Gunther Mayer
  6. *
  7. * Copyright(c) 2005-2011 by Mauro Carvalho Chehab
  8. * - Added support for a separate Radio tuner
  9. * - Major rework and cleanups at the code
  10. *
  11. * This driver supports many devices and the idea is to let the driver
  12. * detect which device is present. So rather than listing all supported
  13. * devices here, we pretend to support a single, fake device type that will
  14. * handle both radio and analog TV tuning.
  15. */
  16. #include <linux/module.h>
  17. #include <linux/kernel.h>
  18. #include <linux/string.h>
  19. #include <linux/timer.h>
  20. #include <linux/delay.h>
  21. #include <linux/errno.h>
  22. #include <linux/slab.h>
  23. #include <linux/poll.h>
  24. #include <linux/i2c.h>
  25. #include <linux/types.h>
  26. #include <linux/init.h>
  27. #include <linux/videodev2.h>
  28. #include <media/tuner.h>
  29. #include <media/tuner-types.h>
  30. #include <media/v4l2-device.h>
  31. #include <media/v4l2-ioctl.h>
  32. #include "mt20xx.h"
  33. #include "tda8290.h"
  34. #include "tea5761.h"
  35. #include "tea5767.h"
  36. #include "tuner-xc2028.h"
  37. #include "tuner-simple.h"
  38. #include "tda9887.h"
  39. #include "xc5000.h"
  40. #include "tda18271.h"
  41. #define UNSET (-1U)
  42. #define PREFIX (t->i2c->driver->driver.name)
  43. /*
  44. * Driver modprobe parameters
  45. */
  46. /* insmod options used at init time => read/only */
  47. static unsigned int addr;
  48. static unsigned int no_autodetect;
  49. static unsigned int show_i2c;
  50. module_param(addr, int, 0444);
  51. module_param(no_autodetect, int, 0444);
  52. module_param(show_i2c, int, 0444);
  53. /* insmod options used at runtime => read/write */
  54. static int tuner_debug;
  55. static unsigned int tv_range[2] = { 44, 958 };
  56. static unsigned int radio_range[2] = { 65, 108 };
  57. static char pal[] = "--";
  58. static char secam[] = "--";
  59. static char ntsc[] = "-";
  60. module_param_named(debug, tuner_debug, int, 0644);
  61. module_param_array(tv_range, int, NULL, 0644);
  62. module_param_array(radio_range, int, NULL, 0644);
  63. module_param_string(pal, pal, sizeof(pal), 0644);
  64. module_param_string(secam, secam, sizeof(secam), 0644);
  65. module_param_string(ntsc, ntsc, sizeof(ntsc), 0644);
  66. /*
  67. * Static vars
  68. */
  69. static LIST_HEAD(tuner_list);
  70. static const struct v4l2_subdev_ops tuner_ops;
  71. /*
  72. * Debug macros
  73. */
  74. #define tuner_warn(fmt, arg...) do { \
  75. printk(KERN_WARNING "%s %d-%04x: " fmt, PREFIX, \
  76. i2c_adapter_id(t->i2c->adapter), \
  77. t->i2c->addr, ##arg); \
  78. } while (0)
  79. #define tuner_info(fmt, arg...) do { \
  80. printk(KERN_INFO "%s %d-%04x: " fmt, PREFIX, \
  81. i2c_adapter_id(t->i2c->adapter), \
  82. t->i2c->addr, ##arg); \
  83. } while (0)
  84. #define tuner_err(fmt, arg...) do { \
  85. printk(KERN_ERR "%s %d-%04x: " fmt, PREFIX, \
  86. i2c_adapter_id(t->i2c->adapter), \
  87. t->i2c->addr, ##arg); \
  88. } while (0)
  89. #define tuner_dbg(fmt, arg...) do { \
  90. if (tuner_debug) \
  91. printk(KERN_DEBUG "%s %d-%04x: " fmt, PREFIX, \
  92. i2c_adapter_id(t->i2c->adapter), \
  93. t->i2c->addr, ##arg); \
  94. } while (0)
  95. /*
  96. * Internal struct used inside the driver
  97. */
  98. struct tuner {
  99. /* device */
  100. struct dvb_frontend fe;
  101. struct i2c_client *i2c;
  102. struct v4l2_subdev sd;
  103. struct list_head list;
  104. /* keep track of the current settings */
  105. v4l2_std_id std;
  106. unsigned int tv_freq;
  107. unsigned int radio_freq;
  108. unsigned int audmode;
  109. enum v4l2_tuner_type mode;
  110. unsigned int mode_mask; /* Combination of allowable modes */
  111. bool standby; /* Standby mode */
  112. unsigned int type; /* chip type id */
  113. unsigned int config;
  114. const char *name;
  115. };
  116. /*
  117. * Function prototypes
  118. */
  119. static void set_tv_freq(struct i2c_client *c, unsigned int freq);
  120. static void set_radio_freq(struct i2c_client *c, unsigned int freq);
  121. /*
  122. * tuner attach/detach logic
  123. */
  124. /* This macro allows us to probe dynamically, avoiding static links */
  125. #ifdef CONFIG_MEDIA_ATTACH
  126. #define tuner_symbol_probe(FUNCTION, ARGS...) ({ \
  127. int __r = -EINVAL; \
  128. typeof(&FUNCTION) __a = symbol_request(FUNCTION); \
  129. if (__a) { \
  130. __r = (int) __a(ARGS); \
  131. symbol_put(FUNCTION); \
  132. } else { \
  133. printk(KERN_ERR "TUNER: Unable to find " \
  134. "symbol "#FUNCTION"()\n"); \
  135. } \
  136. __r; \
  137. })
  138. static void tuner_detach(struct dvb_frontend *fe)
  139. {
  140. if (fe->ops.tuner_ops.release) {
  141. fe->ops.tuner_ops.release(fe);
  142. symbol_put_addr(fe->ops.tuner_ops.release);
  143. }
  144. if (fe->ops.analog_ops.release) {
  145. fe->ops.analog_ops.release(fe);
  146. symbol_put_addr(fe->ops.analog_ops.release);
  147. }
  148. }
  149. #else
  150. #define tuner_symbol_probe(FUNCTION, ARGS...) ({ \
  151. FUNCTION(ARGS); \
  152. })
  153. static void tuner_detach(struct dvb_frontend *fe)
  154. {
  155. if (fe->ops.tuner_ops.release)
  156. fe->ops.tuner_ops.release(fe);
  157. if (fe->ops.analog_ops.release)
  158. fe->ops.analog_ops.release(fe);
  159. }
  160. #endif
  161. static inline struct tuner *to_tuner(struct v4l2_subdev *sd)
  162. {
  163. return container_of(sd, struct tuner, sd);
  164. }
  165. /*
  166. * struct analog_demod_ops callbacks
  167. */
  168. static void fe_set_params(struct dvb_frontend *fe,
  169. struct analog_parameters *params)
  170. {
  171. struct dvb_tuner_ops *fe_tuner_ops = &fe->ops.tuner_ops;
  172. struct tuner *t = fe->analog_demod_priv;
  173. if (NULL == fe_tuner_ops->set_analog_params) {
  174. tuner_warn("Tuner frontend module has no way to set freq\n");
  175. return;
  176. }
  177. fe_tuner_ops->set_analog_params(fe, params);
  178. }
  179. static void fe_standby(struct dvb_frontend *fe)
  180. {
  181. struct dvb_tuner_ops *fe_tuner_ops = &fe->ops.tuner_ops;
  182. if (fe_tuner_ops->sleep)
  183. fe_tuner_ops->sleep(fe);
  184. }
  185. static int fe_has_signal(struct dvb_frontend *fe)
  186. {
  187. u16 strength = 0;
  188. if (fe->ops.tuner_ops.get_rf_strength)
  189. fe->ops.tuner_ops.get_rf_strength(fe, &strength);
  190. return strength;
  191. }
  192. static int fe_set_config(struct dvb_frontend *fe, void *priv_cfg)
  193. {
  194. struct dvb_tuner_ops *fe_tuner_ops = &fe->ops.tuner_ops;
  195. struct tuner *t = fe->analog_demod_priv;
  196. if (fe_tuner_ops->set_config)
  197. return fe_tuner_ops->set_config(fe, priv_cfg);
  198. tuner_warn("Tuner frontend module has no way to set config\n");
  199. return 0;
  200. }
  201. static void tuner_status(struct dvb_frontend *fe);
  202. static struct analog_demod_ops tuner_analog_ops = {
  203. .set_params = fe_set_params,
  204. .standby = fe_standby,
  205. .has_signal = fe_has_signal,
  206. .set_config = fe_set_config,
  207. .tuner_status = tuner_status
  208. };
  209. /*
  210. * Functions to select between radio and TV and tuner probe/remove functions
  211. */
  212. /**
  213. * set_type - Sets the tuner type for a given device
  214. *
  215. * @c: i2c_client descriptoy
  216. * @type: type of the tuner (e. g. tuner number)
  217. * @new_mode_mask: Indicates if tuner supports TV and/or Radio
  218. * @new_config: an optional parameter ranging from 0-255 used by
  219. a few tuners to adjust an internal parameter,
  220. like LNA mode
  221. * @tuner_callback: an optional function to be called when switching
  222. * to analog mode
  223. *
  224. * This function applys the tuner config to tuner specified
  225. * by tun_setup structure. It contains several per-tuner initialization "magic"
  226. */
  227. static void set_type(struct i2c_client *c, unsigned int type,
  228. unsigned int new_mode_mask, unsigned int new_config,
  229. int (*tuner_callback) (void *dev, int component, int cmd, int arg))
  230. {
  231. struct tuner *t = to_tuner(i2c_get_clientdata(c));
  232. struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
  233. struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
  234. unsigned char buffer[4];
  235. int tune_now = 1;
  236. if (type == UNSET || type == TUNER_ABSENT) {
  237. tuner_dbg("tuner 0x%02x: Tuner type absent\n", c->addr);
  238. return;
  239. }
  240. t->type = type;
  241. /* prevent invalid config values */
  242. t->config = new_config < 256 ? new_config : 0;
  243. if (tuner_callback != NULL) {
  244. tuner_dbg("defining GPIO callback\n");
  245. t->fe.callback = tuner_callback;
  246. }
  247. /* discard private data, in case set_type() was previously called */
  248. tuner_detach(&t->fe);
  249. t->fe.analog_demod_priv = NULL;
  250. switch (t->type) {
  251. case TUNER_MT2032:
  252. if (!dvb_attach(microtune_attach,
  253. &t->fe, t->i2c->adapter, t->i2c->addr))
  254. goto attach_failed;
  255. break;
  256. case TUNER_PHILIPS_TDA8290:
  257. {
  258. struct tda829x_config cfg = {
  259. .lna_cfg = t->config,
  260. };
  261. if (!dvb_attach(tda829x_attach, &t->fe, t->i2c->adapter,
  262. t->i2c->addr, &cfg))
  263. goto attach_failed;
  264. break;
  265. }
  266. case TUNER_TEA5767:
  267. if (!dvb_attach(tea5767_attach, &t->fe,
  268. t->i2c->adapter, t->i2c->addr))
  269. goto attach_failed;
  270. t->mode_mask = T_RADIO;
  271. break;
  272. case TUNER_TEA5761:
  273. if (!dvb_attach(tea5761_attach, &t->fe,
  274. t->i2c->adapter, t->i2c->addr))
  275. goto attach_failed;
  276. t->mode_mask = T_RADIO;
  277. break;
  278. case TUNER_PHILIPS_FMD1216ME_MK3:
  279. buffer[0] = 0x0b;
  280. buffer[1] = 0xdc;
  281. buffer[2] = 0x9c;
  282. buffer[3] = 0x60;
  283. i2c_master_send(c, buffer, 4);
  284. mdelay(1);
  285. buffer[2] = 0x86;
  286. buffer[3] = 0x54;
  287. i2c_master_send(c, buffer, 4);
  288. if (!dvb_attach(simple_tuner_attach, &t->fe,
  289. t->i2c->adapter, t->i2c->addr, t->type))
  290. goto attach_failed;
  291. break;
  292. case TUNER_PHILIPS_TD1316:
  293. buffer[0] = 0x0b;
  294. buffer[1] = 0xdc;
  295. buffer[2] = 0x86;
  296. buffer[3] = 0xa4;
  297. i2c_master_send(c, buffer, 4);
  298. if (!dvb_attach(simple_tuner_attach, &t->fe,
  299. t->i2c->adapter, t->i2c->addr, t->type))
  300. goto attach_failed;
  301. break;
  302. case TUNER_XC2028:
  303. {
  304. struct xc2028_config cfg = {
  305. .i2c_adap = t->i2c->adapter,
  306. .i2c_addr = t->i2c->addr,
  307. };
  308. if (!dvb_attach(xc2028_attach, &t->fe, &cfg))
  309. goto attach_failed;
  310. tune_now = 0;
  311. break;
  312. }
  313. case TUNER_TDA9887:
  314. if (!dvb_attach(tda9887_attach,
  315. &t->fe, t->i2c->adapter, t->i2c->addr))
  316. goto attach_failed;
  317. break;
  318. case TUNER_XC5000:
  319. {
  320. struct xc5000_config xc5000_cfg = {
  321. .i2c_address = t->i2c->addr,
  322. /* if_khz will be set at dvb_attach() */
  323. .if_khz = 0,
  324. };
  325. if (!dvb_attach(xc5000_attach,
  326. &t->fe, t->i2c->adapter, &xc5000_cfg))
  327. goto attach_failed;
  328. tune_now = 0;
  329. break;
  330. }
  331. case TUNER_NXP_TDA18271:
  332. {
  333. struct tda18271_config cfg = {
  334. .config = t->config,
  335. .small_i2c = TDA18271_03_BYTE_CHUNK_INIT,
  336. };
  337. if (!dvb_attach(tda18271_attach, &t->fe, t->i2c->addr,
  338. t->i2c->adapter, &cfg))
  339. goto attach_failed;
  340. tune_now = 0;
  341. break;
  342. }
  343. default:
  344. if (!dvb_attach(simple_tuner_attach, &t->fe,
  345. t->i2c->adapter, t->i2c->addr, t->type))
  346. goto attach_failed;
  347. break;
  348. }
  349. if ((NULL == analog_ops->set_params) &&
  350. (fe_tuner_ops->set_analog_params)) {
  351. t->name = fe_tuner_ops->info.name;
  352. t->fe.analog_demod_priv = t;
  353. memcpy(analog_ops, &tuner_analog_ops,
  354. sizeof(struct analog_demod_ops));
  355. } else {
  356. t->name = analog_ops->info.name;
  357. }
  358. tuner_dbg("type set to %s\n", t->name);
  359. t->mode_mask = new_mode_mask;
  360. /* Some tuners require more initialization setup before use,
  361. such as firmware download or device calibration.
  362. trying to set a frequency here will just fail
  363. FIXME: better to move set_freq to the tuner code. This is needed
  364. on analog tuners for PLL to properly work
  365. */
  366. if (tune_now) {
  367. if (V4L2_TUNER_RADIO == t->mode)
  368. set_radio_freq(c, t->radio_freq);
  369. else
  370. set_tv_freq(c, t->tv_freq);
  371. }
  372. tuner_dbg("%s %s I2C addr 0x%02x with type %d used for 0x%02x\n",
  373. c->adapter->name, c->driver->driver.name, c->addr << 1, type,
  374. t->mode_mask);
  375. return;
  376. attach_failed:
  377. tuner_dbg("Tuner attach for type = %d failed.\n", t->type);
  378. t->type = TUNER_ABSENT;
  379. return;
  380. }
  381. /**
  382. * tuner_s_type_addr - Sets the tuner type for a device
  383. *
  384. * @sd: subdev descriptor
  385. * @tun_setup: type to be associated to a given tuner i2c address
  386. *
  387. * This function applys the tuner config to tuner specified
  388. * by tun_setup structure.
  389. * If tuner I2C address is UNSET, then it will only set the device
  390. * if the tuner supports the mode specified in the call.
  391. * If the address is specified, the change will be applied only if
  392. * tuner I2C address matches.
  393. * The call can change the tuner number and the tuner mode.
  394. */
  395. static int tuner_s_type_addr(struct v4l2_subdev *sd,
  396. struct tuner_setup *tun_setup)
  397. {
  398. struct tuner *t = to_tuner(sd);
  399. struct i2c_client *c = v4l2_get_subdevdata(sd);
  400. tuner_dbg("Calling set_type_addr for type=%d, addr=0x%02x, mode=0x%02x, config=0x%02x\n",
  401. tun_setup->type,
  402. tun_setup->addr,
  403. tun_setup->mode_mask,
  404. tun_setup->config);
  405. if ((t->type == UNSET && ((tun_setup->addr == ADDR_UNSET) &&
  406. (t->mode_mask & tun_setup->mode_mask))) ||
  407. (tun_setup->addr == c->addr)) {
  408. set_type(c, tun_setup->type, tun_setup->mode_mask,
  409. tun_setup->config, tun_setup->tuner_callback);
  410. } else
  411. tuner_dbg("set addr discarded for type %i, mask %x. "
  412. "Asked to change tuner at addr 0x%02x, with mask %x\n",
  413. t->type, t->mode_mask,
  414. tun_setup->addr, tun_setup->mode_mask);
  415. return 0;
  416. }
  417. /**
  418. * tuner_s_config - Sets tuner configuration
  419. *
  420. * @sd: subdev descriptor
  421. * @cfg: tuner configuration
  422. *
  423. * Calls tuner set_config() private function to set some tuner-internal
  424. * parameters
  425. */
  426. static int tuner_s_config(struct v4l2_subdev *sd,
  427. const struct v4l2_priv_tun_config *cfg)
  428. {
  429. struct tuner *t = to_tuner(sd);
  430. struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
  431. if (t->type != cfg->tuner)
  432. return 0;
  433. if (analog_ops->set_config) {
  434. analog_ops->set_config(&t->fe, cfg->priv);
  435. return 0;
  436. }
  437. tuner_dbg("Tuner frontend module has no way to set config\n");
  438. return 0;
  439. }
  440. /**
  441. * tuner_lookup - Seek for tuner adapters
  442. *
  443. * @adap: i2c_adapter struct
  444. * @radio: pointer to be filled if the adapter is radio
  445. * @tv: pointer to be filled if the adapter is TV
  446. *
  447. * Search for existing radio and/or TV tuners on the given I2C adapter,
  448. * discarding demod-only adapters (tda9887).
  449. *
  450. * Note that when this function is called from tuner_probe you can be
  451. * certain no other devices will be added/deleted at the same time, I2C
  452. * core protects against that.
  453. */
  454. static void tuner_lookup(struct i2c_adapter *adap,
  455. struct tuner **radio, struct tuner **tv)
  456. {
  457. struct tuner *pos;
  458. *radio = NULL;
  459. *tv = NULL;
  460. list_for_each_entry(pos, &tuner_list, list) {
  461. int mode_mask;
  462. if (pos->i2c->adapter != adap ||
  463. strcmp(pos->i2c->driver->driver.name, "tuner"))
  464. continue;
  465. mode_mask = pos->mode_mask;
  466. if (*radio == NULL && mode_mask == T_RADIO)
  467. *radio = pos;
  468. /* Note: currently TDA9887 is the only demod-only
  469. device. If other devices appear then we need to
  470. make this test more general. */
  471. else if (*tv == NULL && pos->type != TUNER_TDA9887 &&
  472. (pos->mode_mask & T_ANALOG_TV))
  473. *tv = pos;
  474. }
  475. }
  476. /**
  477. *tuner_probe - Probes the existing tuners on an I2C bus
  478. *
  479. * @client: i2c_client descriptor
  480. * @id: not used
  481. *
  482. * This routine probes for tuners at the expected I2C addresses. On most
  483. * cases, if a device answers to a given I2C address, it assumes that the
  484. * device is a tuner. On a few cases, however, an additional logic is needed
  485. * to double check if the device is really a tuner, or to identify the tuner
  486. * type, like on tea5767/5761 devices.
  487. *
  488. * During client attach, set_type is called by adapter's attach_inform callback.
  489. * set_type must then be completed by tuner_probe.
  490. */
  491. static int tuner_probe(struct i2c_client *client,
  492. const struct i2c_device_id *id)
  493. {
  494. struct tuner *t;
  495. struct tuner *radio;
  496. struct tuner *tv;
  497. t = kzalloc(sizeof(struct tuner), GFP_KERNEL);
  498. if (NULL == t)
  499. return -ENOMEM;
  500. v4l2_i2c_subdev_init(&t->sd, client, &tuner_ops);
  501. t->i2c = client;
  502. t->name = "(tuner unset)";
  503. t->type = UNSET;
  504. t->audmode = V4L2_TUNER_MODE_STEREO;
  505. t->standby = 1;
  506. t->radio_freq = 87.5 * 16000; /* Initial freq range */
  507. t->tv_freq = 400 * 16; /* Sets freq to VHF High - needed for some PLL's to properly start */
  508. if (show_i2c) {
  509. unsigned char buffer[16];
  510. int i, rc;
  511. memset(buffer, 0, sizeof(buffer));
  512. rc = i2c_master_recv(client, buffer, sizeof(buffer));
  513. tuner_info("I2C RECV = ");
  514. for (i = 0; i < rc; i++)
  515. printk(KERN_CONT "%02x ", buffer[i]);
  516. printk("\n");
  517. }
  518. /* autodetection code based on the i2c addr */
  519. if (!no_autodetect) {
  520. switch (client->addr) {
  521. case 0x10:
  522. if (tuner_symbol_probe(tea5761_autodetection,
  523. t->i2c->adapter,
  524. t->i2c->addr) >= 0) {
  525. t->type = TUNER_TEA5761;
  526. t->mode_mask = T_RADIO;
  527. tuner_lookup(t->i2c->adapter, &radio, &tv);
  528. if (tv)
  529. tv->mode_mask &= ~T_RADIO;
  530. goto register_client;
  531. }
  532. kfree(t);
  533. return -ENODEV;
  534. case 0x42:
  535. case 0x43:
  536. case 0x4a:
  537. case 0x4b:
  538. /* If chip is not tda8290, don't register.
  539. since it can be tda9887*/
  540. if (tuner_symbol_probe(tda829x_probe, t->i2c->adapter,
  541. t->i2c->addr) >= 0) {
  542. tuner_dbg("tda829x detected\n");
  543. } else {
  544. /* Default is being tda9887 */
  545. t->type = TUNER_TDA9887;
  546. t->mode_mask = T_RADIO | T_ANALOG_TV;
  547. goto register_client;
  548. }
  549. break;
  550. case 0x60:
  551. if (tuner_symbol_probe(tea5767_autodetection,
  552. t->i2c->adapter, t->i2c->addr)
  553. >= 0) {
  554. t->type = TUNER_TEA5767;
  555. t->mode_mask = T_RADIO;
  556. /* Sets freq to FM range */
  557. tuner_lookup(t->i2c->adapter, &radio, &tv);
  558. if (tv)
  559. tv->mode_mask &= ~T_RADIO;
  560. goto register_client;
  561. }
  562. break;
  563. }
  564. }
  565. /* Initializes only the first TV tuner on this adapter. Why only the
  566. first? Because there are some devices (notably the ones with TI
  567. tuners) that have more than one i2c address for the *same* device.
  568. Experience shows that, except for just one case, the first
  569. address is the right one. The exception is a Russian tuner
  570. (ACORP_Y878F). So, the desired behavior is just to enable the
  571. first found TV tuner. */
  572. tuner_lookup(t->i2c->adapter, &radio, &tv);
  573. if (tv == NULL) {
  574. t->mode_mask = T_ANALOG_TV;
  575. if (radio == NULL)
  576. t->mode_mask |= T_RADIO;
  577. tuner_dbg("Setting mode_mask to 0x%02x\n", t->mode_mask);
  578. }
  579. /* Should be just before return */
  580. register_client:
  581. /* Sets a default mode */
  582. if (t->mode_mask & T_ANALOG_TV)
  583. t->mode = V4L2_TUNER_ANALOG_TV;
  584. else
  585. t->mode = V4L2_TUNER_RADIO;
  586. set_type(client, t->type, t->mode_mask, t->config, t->fe.callback);
  587. list_add_tail(&t->list, &tuner_list);
  588. tuner_info("Tuner %d found with type(s)%s%s.\n",
  589. t->type,
  590. t->mode_mask & T_RADIO ? " Radio" : "",
  591. t->mode_mask & T_ANALOG_TV ? " TV" : "");
  592. return 0;
  593. }
  594. /**
  595. * tuner_remove - detaches a tuner
  596. *
  597. * @client: i2c_client descriptor
  598. */
  599. static int tuner_remove(struct i2c_client *client)
  600. {
  601. struct tuner *t = to_tuner(i2c_get_clientdata(client));
  602. v4l2_device_unregister_subdev(&t->sd);
  603. tuner_detach(&t->fe);
  604. t->fe.analog_demod_priv = NULL;
  605. list_del(&t->list);
  606. kfree(t);
  607. return 0;
  608. }
  609. /*
  610. * Functions to switch between Radio and TV
  611. *
  612. * A few cards have a separate I2C tuner for radio. Those routines
  613. * take care of switching between TV/Radio mode, filtering only the
  614. * commands that apply to the Radio or TV tuner.
  615. */
  616. /**
  617. * check_mode - Verify if tuner supports the requested mode
  618. * @t: a pointer to the module's internal struct_tuner
  619. *
  620. * This function checks if the tuner is capable of tuning analog TV,
  621. * digital TV or radio, depending on what the caller wants. If the
  622. * tuner can't support that mode, it returns -EINVAL. Otherwise, it
  623. * returns 0.
  624. * This function is needed for boards that have a separate tuner for
  625. * radio (like devices with tea5767).
  626. */
  627. static inline int check_mode(struct tuner *t, enum v4l2_tuner_type mode)
  628. {
  629. if ((1 << mode & t->mode_mask) == 0)
  630. return -EINVAL;
  631. return 0;
  632. }
  633. /**
  634. * set_mode_freq - Switch tuner to other mode.
  635. * @client: struct i2c_client pointer
  636. * @t: a pointer to the module's internal struct_tuner
  637. * @mode: enum v4l2_type (radio or TV)
  638. * @freq: frequency to set (0 means to use the previous one)
  639. *
  640. * If tuner doesn't support the needed mode (radio or TV), prints a
  641. * debug message and returns -EINVAL, changing its state to standby.
  642. * Otherwise, changes the state and sets frequency to the last value, if
  643. * the tuner can sleep or if it supports both Radio and TV.
  644. */
  645. static int set_mode_freq(struct i2c_client *client, struct tuner *t,
  646. enum v4l2_tuner_type mode, unsigned int freq)
  647. {
  648. struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
  649. if (mode != t->mode) {
  650. if (check_mode(t, mode) == -EINVAL) {
  651. tuner_dbg("Tuner doesn't support mode %d. "
  652. "Putting tuner to sleep\n", mode);
  653. t->standby = true;
  654. if (analog_ops->standby)
  655. analog_ops->standby(&t->fe);
  656. return -EINVAL;
  657. }
  658. t->mode = mode;
  659. tuner_dbg("Changing to mode %d\n", mode);
  660. }
  661. if (t->mode == V4L2_TUNER_RADIO) {
  662. if (freq)
  663. t->radio_freq = freq;
  664. set_radio_freq(client, t->radio_freq);
  665. } else {
  666. if (freq)
  667. t->tv_freq = freq;
  668. set_tv_freq(client, t->tv_freq);
  669. }
  670. return 0;
  671. }
  672. /*
  673. * Functions that are specific for TV mode
  674. */
  675. /**
  676. * set_tv_freq - Set tuner frequency, freq in Units of 62.5 kHz = 1/16MHz
  677. *
  678. * @c: i2c_client descriptor
  679. * @freq: frequency
  680. */
  681. static void set_tv_freq(struct i2c_client *c, unsigned int freq)
  682. {
  683. struct tuner *t = to_tuner(i2c_get_clientdata(c));
  684. struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
  685. struct analog_parameters params = {
  686. .mode = t->mode,
  687. .audmode = t->audmode,
  688. .std = t->std
  689. };
  690. if (t->type == UNSET) {
  691. tuner_warn("tuner type not set\n");
  692. return;
  693. }
  694. if (NULL == analog_ops->set_params) {
  695. tuner_warn("Tuner has no way to set tv freq\n");
  696. return;
  697. }
  698. if (freq < tv_range[0] * 16 || freq > tv_range[1] * 16) {
  699. tuner_dbg("TV freq (%d.%02d) out of range (%d-%d)\n",
  700. freq / 16, freq % 16 * 100 / 16, tv_range[0],
  701. tv_range[1]);
  702. /* V4L2 spec: if the freq is not possible then the closest
  703. possible value should be selected */
  704. if (freq < tv_range[0] * 16)
  705. freq = tv_range[0] * 16;
  706. else
  707. freq = tv_range[1] * 16;
  708. }
  709. params.frequency = freq;
  710. tuner_dbg("tv freq set to %d.%02d\n",
  711. freq / 16, freq % 16 * 100 / 16);
  712. t->tv_freq = freq;
  713. t->standby = false;
  714. analog_ops->set_params(&t->fe, &params);
  715. }
  716. /**
  717. * tuner_fixup_std - force a given video standard variant
  718. *
  719. * @t: tuner internal struct
  720. *
  721. * A few devices or drivers have problem to detect some standard variations.
  722. * On other operational systems, the drivers generally have a per-country
  723. * code, and some logic to apply per-country hacks. V4L2 API doesn't provide
  724. * such hacks. Instead, it relies on a proper video standard selection from
  725. * the userspace application. However, as some apps are buggy, not allowing
  726. * to distinguish all video standard variations, a modprobe parameter can
  727. * be used to force a video standard match.
  728. */
  729. static int tuner_fixup_std(struct tuner *t)
  730. {
  731. if ((t->std & V4L2_STD_PAL) == V4L2_STD_PAL) {
  732. switch (pal[0]) {
  733. case '6':
  734. tuner_dbg("insmod fixup: PAL => PAL-60\n");
  735. t->std = V4L2_STD_PAL_60;
  736. break;
  737. case 'b':
  738. case 'B':
  739. case 'g':
  740. case 'G':
  741. tuner_dbg("insmod fixup: PAL => PAL-BG\n");
  742. t->std = V4L2_STD_PAL_BG;
  743. break;
  744. case 'i':
  745. case 'I':
  746. tuner_dbg("insmod fixup: PAL => PAL-I\n");
  747. t->std = V4L2_STD_PAL_I;
  748. break;
  749. case 'd':
  750. case 'D':
  751. case 'k':
  752. case 'K':
  753. tuner_dbg("insmod fixup: PAL => PAL-DK\n");
  754. t->std = V4L2_STD_PAL_DK;
  755. break;
  756. case 'M':
  757. case 'm':
  758. tuner_dbg("insmod fixup: PAL => PAL-M\n");
  759. t->std = V4L2_STD_PAL_M;
  760. break;
  761. case 'N':
  762. case 'n':
  763. if (pal[1] == 'c' || pal[1] == 'C') {
  764. tuner_dbg("insmod fixup: PAL => PAL-Nc\n");
  765. t->std = V4L2_STD_PAL_Nc;
  766. } else {
  767. tuner_dbg("insmod fixup: PAL => PAL-N\n");
  768. t->std = V4L2_STD_PAL_N;
  769. }
  770. break;
  771. case '-':
  772. /* default parameter, do nothing */
  773. break;
  774. default:
  775. tuner_warn("pal= argument not recognised\n");
  776. break;
  777. }
  778. }
  779. if ((t->std & V4L2_STD_SECAM) == V4L2_STD_SECAM) {
  780. switch (secam[0]) {
  781. case 'b':
  782. case 'B':
  783. case 'g':
  784. case 'G':
  785. case 'h':
  786. case 'H':
  787. tuner_dbg("insmod fixup: SECAM => SECAM-BGH\n");
  788. t->std = V4L2_STD_SECAM_B |
  789. V4L2_STD_SECAM_G |
  790. V4L2_STD_SECAM_H;
  791. break;
  792. case 'd':
  793. case 'D':
  794. case 'k':
  795. case 'K':
  796. tuner_dbg("insmod fixup: SECAM => SECAM-DK\n");
  797. t->std = V4L2_STD_SECAM_DK;
  798. break;
  799. case 'l':
  800. case 'L':
  801. if ((secam[1] == 'C') || (secam[1] == 'c')) {
  802. tuner_dbg("insmod fixup: SECAM => SECAM-L'\n");
  803. t->std = V4L2_STD_SECAM_LC;
  804. } else {
  805. tuner_dbg("insmod fixup: SECAM => SECAM-L\n");
  806. t->std = V4L2_STD_SECAM_L;
  807. }
  808. break;
  809. case '-':
  810. /* default parameter, do nothing */
  811. break;
  812. default:
  813. tuner_warn("secam= argument not recognised\n");
  814. break;
  815. }
  816. }
  817. if ((t->std & V4L2_STD_NTSC) == V4L2_STD_NTSC) {
  818. switch (ntsc[0]) {
  819. case 'm':
  820. case 'M':
  821. tuner_dbg("insmod fixup: NTSC => NTSC-M\n");
  822. t->std = V4L2_STD_NTSC_M;
  823. break;
  824. case 'j':
  825. case 'J':
  826. tuner_dbg("insmod fixup: NTSC => NTSC_M_JP\n");
  827. t->std = V4L2_STD_NTSC_M_JP;
  828. break;
  829. case 'k':
  830. case 'K':
  831. tuner_dbg("insmod fixup: NTSC => NTSC_M_KR\n");
  832. t->std = V4L2_STD_NTSC_M_KR;
  833. break;
  834. case '-':
  835. /* default parameter, do nothing */
  836. break;
  837. default:
  838. tuner_info("ntsc= argument not recognised\n");
  839. break;
  840. }
  841. }
  842. return 0;
  843. }
  844. /*
  845. * Functions that are specific for Radio mode
  846. */
  847. /**
  848. * set_radio_freq - Set tuner frequency, freq in Units of 62.5 Hz = 1/16kHz
  849. *
  850. * @c: i2c_client descriptor
  851. * @freq: frequency
  852. */
  853. static void set_radio_freq(struct i2c_client *c, unsigned int freq)
  854. {
  855. struct tuner *t = to_tuner(i2c_get_clientdata(c));
  856. struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
  857. struct analog_parameters params = {
  858. .mode = t->mode,
  859. .audmode = t->audmode,
  860. .std = t->std
  861. };
  862. if (t->type == UNSET) {
  863. tuner_warn("tuner type not set\n");
  864. return;
  865. }
  866. if (NULL == analog_ops->set_params) {
  867. tuner_warn("tuner has no way to set radio frequency\n");
  868. return;
  869. }
  870. if (freq < radio_range[0] * 16000 || freq > radio_range[1] * 16000) {
  871. tuner_dbg("radio freq (%d.%02d) out of range (%d-%d)\n",
  872. freq / 16000, freq % 16000 * 100 / 16000,
  873. radio_range[0], radio_range[1]);
  874. /* V4L2 spec: if the freq is not possible then the closest
  875. possible value should be selected */
  876. if (freq < radio_range[0] * 16000)
  877. freq = radio_range[0] * 16000;
  878. else
  879. freq = radio_range[1] * 16000;
  880. }
  881. params.frequency = freq;
  882. tuner_dbg("radio freq set to %d.%02d\n",
  883. freq / 16000, freq % 16000 * 100 / 16000);
  884. t->radio_freq = freq;
  885. t->standby = false;
  886. analog_ops->set_params(&t->fe, &params);
  887. }
  888. /*
  889. * Debug function for reporting tuner status to userspace
  890. */
  891. /**
  892. * tuner_status - Dumps the current tuner status at dmesg
  893. * @fe: pointer to struct dvb_frontend
  894. *
  895. * This callback is used only for driver debug purposes, answering to
  896. * VIDIOC_LOG_STATUS. No changes should happen on this call.
  897. */
  898. static void tuner_status(struct dvb_frontend *fe)
  899. {
  900. struct tuner *t = fe->analog_demod_priv;
  901. unsigned long freq, freq_fraction;
  902. struct dvb_tuner_ops *fe_tuner_ops = &fe->ops.tuner_ops;
  903. struct analog_demod_ops *analog_ops = &fe->ops.analog_ops;
  904. const char *p;
  905. switch (t->mode) {
  906. case V4L2_TUNER_RADIO:
  907. p = "radio";
  908. break;
  909. case V4L2_TUNER_DIGITAL_TV:
  910. p = "digital TV";
  911. break;
  912. case V4L2_TUNER_ANALOG_TV:
  913. default:
  914. p = "analog TV";
  915. break;
  916. }
  917. if (t->mode == V4L2_TUNER_RADIO) {
  918. freq = t->radio_freq / 16000;
  919. freq_fraction = (t->radio_freq % 16000) * 100 / 16000;
  920. } else {
  921. freq = t->tv_freq / 16;
  922. freq_fraction = (t->tv_freq % 16) * 100 / 16;
  923. }
  924. tuner_info("Tuner mode: %s%s\n", p,
  925. t->standby ? " on standby mode" : "");
  926. tuner_info("Frequency: %lu.%02lu MHz\n", freq, freq_fraction);
  927. tuner_info("Standard: 0x%08lx\n", (unsigned long)t->std);
  928. if (t->mode != V4L2_TUNER_RADIO)
  929. return;
  930. if (fe_tuner_ops->get_status) {
  931. u32 tuner_status;
  932. fe_tuner_ops->get_status(&t->fe, &tuner_status);
  933. if (tuner_status & TUNER_STATUS_LOCKED)
  934. tuner_info("Tuner is locked.\n");
  935. if (tuner_status & TUNER_STATUS_STEREO)
  936. tuner_info("Stereo: yes\n");
  937. }
  938. if (analog_ops->has_signal)
  939. tuner_info("Signal strength: %d\n",
  940. analog_ops->has_signal(fe));
  941. }
  942. /*
  943. * Function to splicitly change mode to radio. Probably not needed anymore
  944. */
  945. static int tuner_s_radio(struct v4l2_subdev *sd)
  946. {
  947. struct tuner *t = to_tuner(sd);
  948. struct i2c_client *client = v4l2_get_subdevdata(sd);
  949. if (set_mode_freq(client, t, V4L2_TUNER_RADIO, 0) == -EINVAL)
  950. return 0;
  951. return 0;
  952. }
  953. /*
  954. * Tuner callbacks to handle userspace ioctl's
  955. */
  956. /**
  957. * tuner_s_power - controls the power state of the tuner
  958. * @sd: pointer to struct v4l2_subdev
  959. * @on: a zero value puts the tuner to sleep
  960. */
  961. static int tuner_s_power(struct v4l2_subdev *sd, int on)
  962. {
  963. struct tuner *t = to_tuner(sd);
  964. struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
  965. /* FIXME: Why this function don't wake the tuner if on != 0 ? */
  966. if (on)
  967. return 0;
  968. tuner_dbg("Putting tuner to sleep\n");
  969. t->standby = true;
  970. if (analog_ops->standby)
  971. analog_ops->standby(&t->fe);
  972. return 0;
  973. }
  974. static int tuner_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
  975. {
  976. struct tuner *t = to_tuner(sd);
  977. struct i2c_client *client = v4l2_get_subdevdata(sd);
  978. if (set_mode_freq(client, t, V4L2_TUNER_ANALOG_TV, 0) == -EINVAL)
  979. return 0;
  980. t->std = std;
  981. tuner_fixup_std(t);
  982. return 0;
  983. }
  984. static int tuner_s_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f)
  985. {
  986. struct tuner *t = to_tuner(sd);
  987. struct i2c_client *client = v4l2_get_subdevdata(sd);
  988. if (set_mode_freq(client, t, f->type, f->frequency) == -EINVAL)
  989. return 0;
  990. return 0;
  991. }
  992. static int tuner_g_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f)
  993. {
  994. struct tuner *t = to_tuner(sd);
  995. struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
  996. if (check_mode(t, f->type) == -EINVAL)
  997. return 0;
  998. f->type = t->mode;
  999. if (fe_tuner_ops->get_frequency && !t->standby) {
  1000. u32 abs_freq;
  1001. fe_tuner_ops->get_frequency(&t->fe, &abs_freq);
  1002. f->frequency = (V4L2_TUNER_RADIO == t->mode) ?
  1003. DIV_ROUND_CLOSEST(abs_freq * 2, 125) :
  1004. DIV_ROUND_CLOSEST(abs_freq, 62500);
  1005. } else {
  1006. f->frequency = (V4L2_TUNER_RADIO == t->mode) ?
  1007. t->radio_freq : t->tv_freq;
  1008. }
  1009. return 0;
  1010. }
  1011. static int tuner_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
  1012. {
  1013. struct tuner *t = to_tuner(sd);
  1014. struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
  1015. struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
  1016. if (check_mode(t, vt->type) == -EINVAL)
  1017. return 0;
  1018. vt->type = t->mode;
  1019. if (analog_ops->get_afc)
  1020. vt->afc = analog_ops->get_afc(&t->fe);
  1021. if (t->mode == V4L2_TUNER_ANALOG_TV)
  1022. vt->capability |= V4L2_TUNER_CAP_NORM;
  1023. if (t->mode != V4L2_TUNER_RADIO) {
  1024. vt->rangelow = tv_range[0] * 16;
  1025. vt->rangehigh = tv_range[1] * 16;
  1026. return 0;
  1027. }
  1028. /* radio mode */
  1029. vt->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
  1030. if (fe_tuner_ops->get_status) {
  1031. u32 tuner_status;
  1032. fe_tuner_ops->get_status(&t->fe, &tuner_status);
  1033. vt->rxsubchans =
  1034. (tuner_status & TUNER_STATUS_STEREO) ?
  1035. V4L2_TUNER_SUB_STEREO :
  1036. V4L2_TUNER_SUB_MONO;
  1037. }
  1038. if (analog_ops->has_signal)
  1039. vt->signal = analog_ops->has_signal(&t->fe);
  1040. vt->capability |= V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
  1041. vt->audmode = t->audmode;
  1042. vt->rangelow = radio_range[0] * 16000;
  1043. vt->rangehigh = radio_range[1] * 16000;
  1044. return 0;
  1045. }
  1046. static int tuner_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
  1047. {
  1048. struct tuner *t = to_tuner(sd);
  1049. struct i2c_client *client = v4l2_get_subdevdata(sd);
  1050. if (set_mode_freq(client, t, vt->type, 0) == -EINVAL)
  1051. return 0;
  1052. if (t->mode == V4L2_TUNER_RADIO)
  1053. t->audmode = vt->audmode;
  1054. return 0;
  1055. }
  1056. static int tuner_log_status(struct v4l2_subdev *sd)
  1057. {
  1058. struct tuner *t = to_tuner(sd);
  1059. struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
  1060. if (analog_ops->tuner_status)
  1061. analog_ops->tuner_status(&t->fe);
  1062. return 0;
  1063. }
  1064. static int tuner_suspend(struct i2c_client *c, pm_message_t state)
  1065. {
  1066. struct tuner *t = to_tuner(i2c_get_clientdata(c));
  1067. struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
  1068. tuner_dbg("suspend\n");
  1069. if (!t->standby && analog_ops->standby)
  1070. analog_ops->standby(&t->fe);
  1071. return 0;
  1072. }
  1073. static int tuner_resume(struct i2c_client *c)
  1074. {
  1075. struct tuner *t = to_tuner(i2c_get_clientdata(c));
  1076. tuner_dbg("resume\n");
  1077. if (!t->standby)
  1078. set_mode_freq(c, t, t->type, 0);
  1079. return 0;
  1080. }
  1081. static int tuner_command(struct i2c_client *client, unsigned cmd, void *arg)
  1082. {
  1083. struct v4l2_subdev *sd = i2c_get_clientdata(client);
  1084. /* TUNER_SET_CONFIG is still called by tuner-simple.c, so we have
  1085. to handle it here.
  1086. There must be a better way of doing this... */
  1087. switch (cmd) {
  1088. case TUNER_SET_CONFIG:
  1089. return tuner_s_config(sd, arg);
  1090. }
  1091. return -ENOIOCTLCMD;
  1092. }
  1093. /*
  1094. * Callback structs
  1095. */
  1096. static const struct v4l2_subdev_core_ops tuner_core_ops = {
  1097. .log_status = tuner_log_status,
  1098. .s_std = tuner_s_std,
  1099. .s_power = tuner_s_power,
  1100. };
  1101. static const struct v4l2_subdev_tuner_ops tuner_tuner_ops = {
  1102. .s_radio = tuner_s_radio,
  1103. .g_tuner = tuner_g_tuner,
  1104. .s_tuner = tuner_s_tuner,
  1105. .s_frequency = tuner_s_frequency,
  1106. .g_frequency = tuner_g_frequency,
  1107. .s_type_addr = tuner_s_type_addr,
  1108. .s_config = tuner_s_config,
  1109. };
  1110. static const struct v4l2_subdev_ops tuner_ops = {
  1111. .core = &tuner_core_ops,
  1112. .tuner = &tuner_tuner_ops,
  1113. };
  1114. /*
  1115. * I2C structs and module init functions
  1116. */
  1117. static const struct i2c_device_id tuner_id[] = {
  1118. { "tuner", }, /* autodetect */
  1119. { }
  1120. };
  1121. MODULE_DEVICE_TABLE(i2c, tuner_id);
  1122. static struct i2c_driver tuner_driver = {
  1123. .driver = {
  1124. .owner = THIS_MODULE,
  1125. .name = "tuner",
  1126. },
  1127. .probe = tuner_probe,
  1128. .remove = tuner_remove,
  1129. .command = tuner_command,
  1130. .suspend = tuner_suspend,
  1131. .resume = tuner_resume,
  1132. .id_table = tuner_id,
  1133. };
  1134. static __init int init_tuner(void)
  1135. {
  1136. return i2c_add_driver(&tuner_driver);
  1137. }
  1138. static __exit void exit_tuner(void)
  1139. {
  1140. i2c_del_driver(&tuner_driver);
  1141. }
  1142. module_init(init_tuner);
  1143. module_exit(exit_tuner);
  1144. MODULE_DESCRIPTION("device driver for various TV and TV+FM radio tuners");
  1145. MODULE_AUTHOR("Ralph Metzler, Gerd Knorr, Gunther Mayer");
  1146. MODULE_LICENSE("GPL");