tuner-core.c 34 KB

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