tuner-core.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337
  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_XC5000C:
  334. {
  335. struct xc5000_config xc5000c_cfg = {
  336. .i2c_address = t->i2c->addr,
  337. /* if_khz will be set at dvb_attach() */
  338. .if_khz = 0,
  339. .chip_id = XC5000C,
  340. };
  341. if (!dvb_attach(xc5000_attach,
  342. &t->fe, t->i2c->adapter, &xc5000c_cfg))
  343. goto attach_failed;
  344. tune_now = 0;
  345. break;
  346. }
  347. case TUNER_NXP_TDA18271:
  348. {
  349. struct tda18271_config cfg = {
  350. .config = t->config,
  351. .small_i2c = TDA18271_03_BYTE_CHUNK_INIT,
  352. };
  353. if (!dvb_attach(tda18271_attach, &t->fe, t->i2c->addr,
  354. t->i2c->adapter, &cfg))
  355. goto attach_failed;
  356. tune_now = 0;
  357. break;
  358. }
  359. case TUNER_XC4000:
  360. {
  361. struct xc4000_config xc4000_cfg = {
  362. .i2c_address = t->i2c->addr,
  363. /* FIXME: the correct parameters will be set */
  364. /* only when the digital dvb_attach() occurs */
  365. .default_pm = 0,
  366. .dvb_amplitude = 0,
  367. .set_smoothedcvbs = 0,
  368. .if_khz = 0
  369. };
  370. if (!dvb_attach(xc4000_attach,
  371. &t->fe, t->i2c->adapter, &xc4000_cfg))
  372. goto attach_failed;
  373. tune_now = 0;
  374. break;
  375. }
  376. default:
  377. if (!dvb_attach(simple_tuner_attach, &t->fe,
  378. t->i2c->adapter, t->i2c->addr, t->type))
  379. goto attach_failed;
  380. break;
  381. }
  382. if ((NULL == analog_ops->set_params) &&
  383. (fe_tuner_ops->set_analog_params)) {
  384. t->name = fe_tuner_ops->info.name;
  385. t->fe.analog_demod_priv = t;
  386. memcpy(analog_ops, &tuner_analog_ops,
  387. sizeof(struct analog_demod_ops));
  388. } else {
  389. t->name = analog_ops->info.name;
  390. }
  391. tuner_dbg("type set to %s\n", t->name);
  392. t->mode_mask = new_mode_mask;
  393. /* Some tuners require more initialization setup before use,
  394. such as firmware download or device calibration.
  395. trying to set a frequency here will just fail
  396. FIXME: better to move set_freq to the tuner code. This is needed
  397. on analog tuners for PLL to properly work
  398. */
  399. if (tune_now) {
  400. if (V4L2_TUNER_RADIO == t->mode)
  401. set_radio_freq(c, t->radio_freq);
  402. else
  403. set_tv_freq(c, t->tv_freq);
  404. }
  405. tuner_dbg("%s %s I2C addr 0x%02x with type %d used for 0x%02x\n",
  406. c->adapter->name, c->driver->driver.name, c->addr << 1, type,
  407. t->mode_mask);
  408. return;
  409. attach_failed:
  410. tuner_dbg("Tuner attach for type = %d failed.\n", t->type);
  411. t->type = TUNER_ABSENT;
  412. return;
  413. }
  414. /**
  415. * tuner_s_type_addr - Sets the tuner type for a device
  416. *
  417. * @sd: subdev descriptor
  418. * @tun_setup: type to be associated to a given tuner i2c address
  419. *
  420. * This function applys the tuner config to tuner specified
  421. * by tun_setup structure.
  422. * If tuner I2C address is UNSET, then it will only set the device
  423. * if the tuner supports the mode specified in the call.
  424. * If the address is specified, the change will be applied only if
  425. * tuner I2C address matches.
  426. * The call can change the tuner number and the tuner mode.
  427. */
  428. static int tuner_s_type_addr(struct v4l2_subdev *sd,
  429. struct tuner_setup *tun_setup)
  430. {
  431. struct tuner *t = to_tuner(sd);
  432. struct i2c_client *c = v4l2_get_subdevdata(sd);
  433. tuner_dbg("Calling set_type_addr for type=%d, addr=0x%02x, mode=0x%02x, config=0x%02x\n",
  434. tun_setup->type,
  435. tun_setup->addr,
  436. tun_setup->mode_mask,
  437. tun_setup->config);
  438. if ((t->type == UNSET && ((tun_setup->addr == ADDR_UNSET) &&
  439. (t->mode_mask & tun_setup->mode_mask))) ||
  440. (tun_setup->addr == c->addr)) {
  441. set_type(c, tun_setup->type, tun_setup->mode_mask,
  442. tun_setup->config, tun_setup->tuner_callback);
  443. } else
  444. tuner_dbg("set addr discarded for type %i, mask %x. "
  445. "Asked to change tuner at addr 0x%02x, with mask %x\n",
  446. t->type, t->mode_mask,
  447. tun_setup->addr, tun_setup->mode_mask);
  448. return 0;
  449. }
  450. /**
  451. * tuner_s_config - Sets tuner configuration
  452. *
  453. * @sd: subdev descriptor
  454. * @cfg: tuner configuration
  455. *
  456. * Calls tuner set_config() private function to set some tuner-internal
  457. * parameters
  458. */
  459. static int tuner_s_config(struct v4l2_subdev *sd,
  460. const struct v4l2_priv_tun_config *cfg)
  461. {
  462. struct tuner *t = to_tuner(sd);
  463. struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
  464. if (t->type != cfg->tuner)
  465. return 0;
  466. if (analog_ops->set_config) {
  467. analog_ops->set_config(&t->fe, cfg->priv);
  468. return 0;
  469. }
  470. tuner_dbg("Tuner frontend module has no way to set config\n");
  471. return 0;
  472. }
  473. /**
  474. * tuner_lookup - Seek for tuner adapters
  475. *
  476. * @adap: i2c_adapter struct
  477. * @radio: pointer to be filled if the adapter is radio
  478. * @tv: pointer to be filled if the adapter is TV
  479. *
  480. * Search for existing radio and/or TV tuners on the given I2C adapter,
  481. * discarding demod-only adapters (tda9887).
  482. *
  483. * Note that when this function is called from tuner_probe you can be
  484. * certain no other devices will be added/deleted at the same time, I2C
  485. * core protects against that.
  486. */
  487. static void tuner_lookup(struct i2c_adapter *adap,
  488. struct tuner **radio, struct tuner **tv)
  489. {
  490. struct tuner *pos;
  491. *radio = NULL;
  492. *tv = NULL;
  493. list_for_each_entry(pos, &tuner_list, list) {
  494. int mode_mask;
  495. if (pos->i2c->adapter != adap ||
  496. strcmp(pos->i2c->driver->driver.name, "tuner"))
  497. continue;
  498. mode_mask = pos->mode_mask;
  499. if (*radio == NULL && mode_mask == T_RADIO)
  500. *radio = pos;
  501. /* Note: currently TDA9887 is the only demod-only
  502. device. If other devices appear then we need to
  503. make this test more general. */
  504. else if (*tv == NULL && pos->type != TUNER_TDA9887 &&
  505. (pos->mode_mask & T_ANALOG_TV))
  506. *tv = pos;
  507. }
  508. }
  509. /**
  510. *tuner_probe - Probes the existing tuners on an I2C bus
  511. *
  512. * @client: i2c_client descriptor
  513. * @id: not used
  514. *
  515. * This routine probes for tuners at the expected I2C addresses. On most
  516. * cases, if a device answers to a given I2C address, it assumes that the
  517. * device is a tuner. On a few cases, however, an additional logic is needed
  518. * to double check if the device is really a tuner, or to identify the tuner
  519. * type, like on tea5767/5761 devices.
  520. *
  521. * During client attach, set_type is called by adapter's attach_inform callback.
  522. * set_type must then be completed by tuner_probe.
  523. */
  524. static int tuner_probe(struct i2c_client *client,
  525. const struct i2c_device_id *id)
  526. {
  527. struct tuner *t;
  528. struct tuner *radio;
  529. struct tuner *tv;
  530. t = kzalloc(sizeof(struct tuner), GFP_KERNEL);
  531. if (NULL == t)
  532. return -ENOMEM;
  533. v4l2_i2c_subdev_init(&t->sd, client, &tuner_ops);
  534. t->i2c = client;
  535. t->name = "(tuner unset)";
  536. t->type = UNSET;
  537. t->audmode = V4L2_TUNER_MODE_STEREO;
  538. t->standby = 1;
  539. t->radio_freq = 87.5 * 16000; /* Initial freq range */
  540. t->tv_freq = 400 * 16; /* Sets freq to VHF High - needed for some PLL's to properly start */
  541. if (show_i2c) {
  542. unsigned char buffer[16];
  543. int i, rc;
  544. memset(buffer, 0, sizeof(buffer));
  545. rc = i2c_master_recv(client, buffer, sizeof(buffer));
  546. tuner_info("I2C RECV = ");
  547. for (i = 0; i < rc; i++)
  548. printk(KERN_CONT "%02x ", buffer[i]);
  549. printk("\n");
  550. }
  551. /* autodetection code based on the i2c addr */
  552. if (!no_autodetect) {
  553. switch (client->addr) {
  554. case 0x10:
  555. if (tuner_symbol_probe(tea5761_autodetection,
  556. t->i2c->adapter,
  557. t->i2c->addr) >= 0) {
  558. t->type = TUNER_TEA5761;
  559. t->mode_mask = T_RADIO;
  560. tuner_lookup(t->i2c->adapter, &radio, &tv);
  561. if (tv)
  562. tv->mode_mask &= ~T_RADIO;
  563. goto register_client;
  564. }
  565. kfree(t);
  566. return -ENODEV;
  567. case 0x42:
  568. case 0x43:
  569. case 0x4a:
  570. case 0x4b:
  571. /* If chip is not tda8290, don't register.
  572. since it can be tda9887*/
  573. if (tuner_symbol_probe(tda829x_probe, t->i2c->adapter,
  574. t->i2c->addr) >= 0) {
  575. tuner_dbg("tda829x detected\n");
  576. } else {
  577. /* Default is being tda9887 */
  578. t->type = TUNER_TDA9887;
  579. t->mode_mask = T_RADIO | T_ANALOG_TV;
  580. goto register_client;
  581. }
  582. break;
  583. case 0x60:
  584. if (tuner_symbol_probe(tea5767_autodetection,
  585. t->i2c->adapter, t->i2c->addr)
  586. >= 0) {
  587. t->type = TUNER_TEA5767;
  588. t->mode_mask = T_RADIO;
  589. /* Sets freq to FM range */
  590. tuner_lookup(t->i2c->adapter, &radio, &tv);
  591. if (tv)
  592. tv->mode_mask &= ~T_RADIO;
  593. goto register_client;
  594. }
  595. break;
  596. }
  597. }
  598. /* Initializes only the first TV tuner on this adapter. Why only the
  599. first? Because there are some devices (notably the ones with TI
  600. tuners) that have more than one i2c address for the *same* device.
  601. Experience shows that, except for just one case, the first
  602. address is the right one. The exception is a Russian tuner
  603. (ACORP_Y878F). So, the desired behavior is just to enable the
  604. first found TV tuner. */
  605. tuner_lookup(t->i2c->adapter, &radio, &tv);
  606. if (tv == NULL) {
  607. t->mode_mask = T_ANALOG_TV;
  608. if (radio == NULL)
  609. t->mode_mask |= T_RADIO;
  610. tuner_dbg("Setting mode_mask to 0x%02x\n", t->mode_mask);
  611. }
  612. /* Should be just before return */
  613. register_client:
  614. /* Sets a default mode */
  615. if (t->mode_mask & T_ANALOG_TV)
  616. t->mode = V4L2_TUNER_ANALOG_TV;
  617. else
  618. t->mode = V4L2_TUNER_RADIO;
  619. set_type(client, t->type, t->mode_mask, t->config, t->fe.callback);
  620. list_add_tail(&t->list, &tuner_list);
  621. tuner_info("Tuner %d found with type(s)%s%s.\n",
  622. t->type,
  623. t->mode_mask & T_RADIO ? " Radio" : "",
  624. t->mode_mask & T_ANALOG_TV ? " TV" : "");
  625. return 0;
  626. }
  627. /**
  628. * tuner_remove - detaches a tuner
  629. *
  630. * @client: i2c_client descriptor
  631. */
  632. static int tuner_remove(struct i2c_client *client)
  633. {
  634. struct tuner *t = to_tuner(i2c_get_clientdata(client));
  635. v4l2_device_unregister_subdev(&t->sd);
  636. tuner_detach(&t->fe);
  637. t->fe.analog_demod_priv = NULL;
  638. list_del(&t->list);
  639. kfree(t);
  640. return 0;
  641. }
  642. /*
  643. * Functions to switch between Radio and TV
  644. *
  645. * A few cards have a separate I2C tuner for radio. Those routines
  646. * take care of switching between TV/Radio mode, filtering only the
  647. * commands that apply to the Radio or TV tuner.
  648. */
  649. /**
  650. * check_mode - Verify if tuner supports the requested mode
  651. * @t: a pointer to the module's internal struct_tuner
  652. *
  653. * This function checks if the tuner is capable of tuning analog TV,
  654. * digital TV or radio, depending on what the caller wants. If the
  655. * tuner can't support that mode, it returns -EINVAL. Otherwise, it
  656. * returns 0.
  657. * This function is needed for boards that have a separate tuner for
  658. * radio (like devices with tea5767).
  659. * NOTE: mt20xx uses V4L2_TUNER_DIGITAL_TV and calls set_tv_freq to
  660. * select a TV frequency. So, t_mode = T_ANALOG_TV could actually
  661. * be used to represent a Digital TV too.
  662. */
  663. static inline int check_mode(struct tuner *t, enum v4l2_tuner_type mode)
  664. {
  665. int t_mode;
  666. if (mode == V4L2_TUNER_RADIO)
  667. t_mode = T_RADIO;
  668. else
  669. t_mode = T_ANALOG_TV;
  670. if ((t_mode & t->mode_mask) == 0)
  671. return -EINVAL;
  672. return 0;
  673. }
  674. /**
  675. * set_mode - Switch tuner to other mode.
  676. * @t: a pointer to the module's internal struct_tuner
  677. * @mode: enum v4l2_type (radio or TV)
  678. *
  679. * If tuner doesn't support the needed mode (radio or TV), prints a
  680. * debug message and returns -EINVAL, changing its state to standby.
  681. * Otherwise, changes the mode and returns 0.
  682. */
  683. static int set_mode(struct tuner *t, enum v4l2_tuner_type mode)
  684. {
  685. struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
  686. if (mode != t->mode) {
  687. if (check_mode(t, mode) == -EINVAL) {
  688. tuner_dbg("Tuner doesn't support mode %d. "
  689. "Putting tuner to sleep\n", mode);
  690. t->standby = true;
  691. if (analog_ops->standby)
  692. analog_ops->standby(&t->fe);
  693. return -EINVAL;
  694. }
  695. t->mode = mode;
  696. tuner_dbg("Changing to mode %d\n", mode);
  697. }
  698. return 0;
  699. }
  700. /**
  701. * set_freq - Set the tuner to the desired frequency.
  702. * @t: a pointer to the module's internal struct_tuner
  703. * @freq: frequency to set (0 means to use the current frequency)
  704. */
  705. static void set_freq(struct tuner *t, unsigned int freq)
  706. {
  707. struct i2c_client *client = v4l2_get_subdevdata(&t->sd);
  708. if (t->mode == V4L2_TUNER_RADIO) {
  709. if (!freq)
  710. freq = t->radio_freq;
  711. set_radio_freq(client, freq);
  712. } else {
  713. if (!freq)
  714. freq = t->tv_freq;
  715. set_tv_freq(client, freq);
  716. }
  717. }
  718. /*
  719. * Functions that are specific for TV mode
  720. */
  721. /**
  722. * set_tv_freq - Set tuner frequency, freq in Units of 62.5 kHz = 1/16MHz
  723. *
  724. * @c: i2c_client descriptor
  725. * @freq: frequency
  726. */
  727. static void set_tv_freq(struct i2c_client *c, unsigned int freq)
  728. {
  729. struct tuner *t = to_tuner(i2c_get_clientdata(c));
  730. struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
  731. struct analog_parameters params = {
  732. .mode = t->mode,
  733. .audmode = t->audmode,
  734. .std = t->std
  735. };
  736. if (t->type == UNSET) {
  737. tuner_warn("tuner type not set\n");
  738. return;
  739. }
  740. if (NULL == analog_ops->set_params) {
  741. tuner_warn("Tuner has no way to set tv freq\n");
  742. return;
  743. }
  744. if (freq < tv_range[0] * 16 || freq > tv_range[1] * 16) {
  745. tuner_dbg("TV freq (%d.%02d) out of range (%d-%d)\n",
  746. freq / 16, freq % 16 * 100 / 16, tv_range[0],
  747. tv_range[1]);
  748. /* V4L2 spec: if the freq is not possible then the closest
  749. possible value should be selected */
  750. if (freq < tv_range[0] * 16)
  751. freq = tv_range[0] * 16;
  752. else
  753. freq = tv_range[1] * 16;
  754. }
  755. params.frequency = freq;
  756. tuner_dbg("tv freq set to %d.%02d\n",
  757. freq / 16, freq % 16 * 100 / 16);
  758. t->tv_freq = freq;
  759. t->standby = false;
  760. analog_ops->set_params(&t->fe, &params);
  761. }
  762. /**
  763. * tuner_fixup_std - force a given video standard variant
  764. *
  765. * @t: tuner internal struct
  766. * @std: TV standard
  767. *
  768. * A few devices or drivers have problem to detect some standard variations.
  769. * On other operational systems, the drivers generally have a per-country
  770. * code, and some logic to apply per-country hacks. V4L2 API doesn't provide
  771. * such hacks. Instead, it relies on a proper video standard selection from
  772. * the userspace application. However, as some apps are buggy, not allowing
  773. * to distinguish all video standard variations, a modprobe parameter can
  774. * be used to force a video standard match.
  775. */
  776. static v4l2_std_id tuner_fixup_std(struct tuner *t, v4l2_std_id std)
  777. {
  778. if (pal[0] != '-' && (std & V4L2_STD_PAL) == V4L2_STD_PAL) {
  779. switch (pal[0]) {
  780. case '6':
  781. return V4L2_STD_PAL_60;
  782. case 'b':
  783. case 'B':
  784. case 'g':
  785. case 'G':
  786. return V4L2_STD_PAL_BG;
  787. case 'i':
  788. case 'I':
  789. return V4L2_STD_PAL_I;
  790. case 'd':
  791. case 'D':
  792. case 'k':
  793. case 'K':
  794. return V4L2_STD_PAL_DK;
  795. case 'M':
  796. case 'm':
  797. return V4L2_STD_PAL_M;
  798. case 'N':
  799. case 'n':
  800. if (pal[1] == 'c' || pal[1] == 'C')
  801. return V4L2_STD_PAL_Nc;
  802. return V4L2_STD_PAL_N;
  803. default:
  804. tuner_warn("pal= argument not recognised\n");
  805. break;
  806. }
  807. }
  808. if (secam[0] != '-' && (std & V4L2_STD_SECAM) == V4L2_STD_SECAM) {
  809. switch (secam[0]) {
  810. case 'b':
  811. case 'B':
  812. case 'g':
  813. case 'G':
  814. case 'h':
  815. case 'H':
  816. return V4L2_STD_SECAM_B |
  817. V4L2_STD_SECAM_G |
  818. V4L2_STD_SECAM_H;
  819. case 'd':
  820. case 'D':
  821. case 'k':
  822. case 'K':
  823. return V4L2_STD_SECAM_DK;
  824. case 'l':
  825. case 'L':
  826. if ((secam[1] == 'C') || (secam[1] == 'c'))
  827. return V4L2_STD_SECAM_LC;
  828. return V4L2_STD_SECAM_L;
  829. default:
  830. tuner_warn("secam= argument not recognised\n");
  831. break;
  832. }
  833. }
  834. if (ntsc[0] != '-' && (std & V4L2_STD_NTSC) == V4L2_STD_NTSC) {
  835. switch (ntsc[0]) {
  836. case 'm':
  837. case 'M':
  838. return V4L2_STD_NTSC_M;
  839. case 'j':
  840. case 'J':
  841. return V4L2_STD_NTSC_M_JP;
  842. case 'k':
  843. case 'K':
  844. return V4L2_STD_NTSC_M_KR;
  845. default:
  846. tuner_info("ntsc= argument not recognised\n");
  847. break;
  848. }
  849. }
  850. return std;
  851. }
  852. /*
  853. * Functions that are specific for Radio mode
  854. */
  855. /**
  856. * set_radio_freq - Set tuner frequency, freq in Units of 62.5 Hz = 1/16kHz
  857. *
  858. * @c: i2c_client descriptor
  859. * @freq: frequency
  860. */
  861. static void set_radio_freq(struct i2c_client *c, unsigned int freq)
  862. {
  863. struct tuner *t = to_tuner(i2c_get_clientdata(c));
  864. struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
  865. struct analog_parameters params = {
  866. .mode = t->mode,
  867. .audmode = t->audmode,
  868. .std = t->std
  869. };
  870. if (t->type == UNSET) {
  871. tuner_warn("tuner type not set\n");
  872. return;
  873. }
  874. if (NULL == analog_ops->set_params) {
  875. tuner_warn("tuner has no way to set radio frequency\n");
  876. return;
  877. }
  878. if (freq < radio_range[0] * 16000 || freq > radio_range[1] * 16000) {
  879. tuner_dbg("radio freq (%d.%02d) out of range (%d-%d)\n",
  880. freq / 16000, freq % 16000 * 100 / 16000,
  881. radio_range[0], radio_range[1]);
  882. /* V4L2 spec: if the freq is not possible then the closest
  883. possible value should be selected */
  884. if (freq < radio_range[0] * 16000)
  885. freq = radio_range[0] * 16000;
  886. else
  887. freq = radio_range[1] * 16000;
  888. }
  889. params.frequency = freq;
  890. tuner_dbg("radio freq set to %d.%02d\n",
  891. freq / 16000, freq % 16000 * 100 / 16000);
  892. t->radio_freq = freq;
  893. t->standby = false;
  894. analog_ops->set_params(&t->fe, &params);
  895. }
  896. /*
  897. * Debug function for reporting tuner status to userspace
  898. */
  899. /**
  900. * tuner_status - Dumps the current tuner status at dmesg
  901. * @fe: pointer to struct dvb_frontend
  902. *
  903. * This callback is used only for driver debug purposes, answering to
  904. * VIDIOC_LOG_STATUS. No changes should happen on this call.
  905. */
  906. static void tuner_status(struct dvb_frontend *fe)
  907. {
  908. struct tuner *t = fe->analog_demod_priv;
  909. unsigned long freq, freq_fraction;
  910. struct dvb_tuner_ops *fe_tuner_ops = &fe->ops.tuner_ops;
  911. struct analog_demod_ops *analog_ops = &fe->ops.analog_ops;
  912. const char *p;
  913. switch (t->mode) {
  914. case V4L2_TUNER_RADIO:
  915. p = "radio";
  916. break;
  917. case V4L2_TUNER_DIGITAL_TV: /* Used by mt20xx */
  918. p = "digital TV";
  919. break;
  920. case V4L2_TUNER_ANALOG_TV:
  921. default:
  922. p = "analog TV";
  923. break;
  924. }
  925. if (t->mode == V4L2_TUNER_RADIO) {
  926. freq = t->radio_freq / 16000;
  927. freq_fraction = (t->radio_freq % 16000) * 100 / 16000;
  928. } else {
  929. freq = t->tv_freq / 16;
  930. freq_fraction = (t->tv_freq % 16) * 100 / 16;
  931. }
  932. tuner_info("Tuner mode: %s%s\n", p,
  933. t->standby ? " on standby mode" : "");
  934. tuner_info("Frequency: %lu.%02lu MHz\n", freq, freq_fraction);
  935. tuner_info("Standard: 0x%08lx\n", (unsigned long)t->std);
  936. if (t->mode != V4L2_TUNER_RADIO)
  937. return;
  938. if (fe_tuner_ops->get_status) {
  939. u32 tuner_status;
  940. fe_tuner_ops->get_status(&t->fe, &tuner_status);
  941. if (tuner_status & TUNER_STATUS_LOCKED)
  942. tuner_info("Tuner is locked.\n");
  943. if (tuner_status & TUNER_STATUS_STEREO)
  944. tuner_info("Stereo: yes\n");
  945. }
  946. if (analog_ops->has_signal)
  947. tuner_info("Signal strength: %d\n",
  948. analog_ops->has_signal(fe));
  949. }
  950. /*
  951. * Function to splicitly change mode to radio. Probably not needed anymore
  952. */
  953. static int tuner_s_radio(struct v4l2_subdev *sd)
  954. {
  955. struct tuner *t = to_tuner(sd);
  956. if (set_mode(t, V4L2_TUNER_RADIO) == 0)
  957. set_freq(t, 0);
  958. return 0;
  959. }
  960. /*
  961. * Tuner callbacks to handle userspace ioctl's
  962. */
  963. /**
  964. * tuner_s_power - controls the power state of the tuner
  965. * @sd: pointer to struct v4l2_subdev
  966. * @on: a zero value puts the tuner to sleep, non-zero wakes it up
  967. */
  968. static int tuner_s_power(struct v4l2_subdev *sd, int on)
  969. {
  970. struct tuner *t = to_tuner(sd);
  971. struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
  972. if (on) {
  973. if (t->standby && set_mode(t, t->mode) == 0) {
  974. tuner_dbg("Waking up tuner\n");
  975. set_freq(t, 0);
  976. }
  977. return 0;
  978. }
  979. tuner_dbg("Putting tuner to sleep\n");
  980. t->standby = true;
  981. if (analog_ops->standby)
  982. analog_ops->standby(&t->fe);
  983. return 0;
  984. }
  985. static int tuner_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
  986. {
  987. struct tuner *t = to_tuner(sd);
  988. if (set_mode(t, V4L2_TUNER_ANALOG_TV))
  989. return 0;
  990. t->std = tuner_fixup_std(t, std);
  991. if (t->std != std)
  992. tuner_dbg("Fixup standard %llx to %llx\n", std, t->std);
  993. set_freq(t, 0);
  994. return 0;
  995. }
  996. static int tuner_s_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f)
  997. {
  998. struct tuner *t = to_tuner(sd);
  999. if (set_mode(t, f->type) == 0)
  1000. set_freq(t, f->frequency);
  1001. return 0;
  1002. }
  1003. /**
  1004. * tuner_g_frequency - Get the tuned frequency for the tuner
  1005. * @sd: pointer to struct v4l2_subdev
  1006. * @f: pointer to struct v4l2_frequency
  1007. *
  1008. * At return, the structure f will be filled with tuner frequency
  1009. * if the tuner matches the f->type.
  1010. * Note: f->type should be initialized before calling it.
  1011. * This is done by either video_ioctl2 or by the bridge driver.
  1012. */
  1013. static int tuner_g_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f)
  1014. {
  1015. struct tuner *t = to_tuner(sd);
  1016. struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
  1017. if (check_mode(t, f->type) == -EINVAL)
  1018. return 0;
  1019. if (f->type == t->mode && fe_tuner_ops->get_frequency && !t->standby) {
  1020. u32 abs_freq;
  1021. fe_tuner_ops->get_frequency(&t->fe, &abs_freq);
  1022. f->frequency = (V4L2_TUNER_RADIO == t->mode) ?
  1023. DIV_ROUND_CLOSEST(abs_freq * 2, 125) :
  1024. DIV_ROUND_CLOSEST(abs_freq, 62500);
  1025. } else {
  1026. f->frequency = (V4L2_TUNER_RADIO == f->type) ?
  1027. t->radio_freq : t->tv_freq;
  1028. }
  1029. return 0;
  1030. }
  1031. /**
  1032. * tuner_g_tuner - Fill in tuner information
  1033. * @sd: pointer to struct v4l2_subdev
  1034. * @vt: pointer to struct v4l2_tuner
  1035. *
  1036. * At return, the structure vt will be filled with tuner information
  1037. * if the tuner matches vt->type.
  1038. * Note: vt->type should be initialized before calling it.
  1039. * This is done by either video_ioctl2 or by the bridge driver.
  1040. */
  1041. static int tuner_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
  1042. {
  1043. struct tuner *t = to_tuner(sd);
  1044. struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
  1045. struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
  1046. if (check_mode(t, vt->type) == -EINVAL)
  1047. return 0;
  1048. if (vt->type == t->mode && analog_ops->get_afc)
  1049. vt->afc = analog_ops->get_afc(&t->fe);
  1050. if (t->mode != V4L2_TUNER_RADIO) {
  1051. vt->capability |= V4L2_TUNER_CAP_NORM;
  1052. vt->rangelow = tv_range[0] * 16;
  1053. vt->rangehigh = tv_range[1] * 16;
  1054. return 0;
  1055. }
  1056. /* radio mode */
  1057. if (vt->type == t->mode) {
  1058. vt->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
  1059. if (fe_tuner_ops->get_status) {
  1060. u32 tuner_status;
  1061. fe_tuner_ops->get_status(&t->fe, &tuner_status);
  1062. vt->rxsubchans =
  1063. (tuner_status & TUNER_STATUS_STEREO) ?
  1064. V4L2_TUNER_SUB_STEREO :
  1065. V4L2_TUNER_SUB_MONO;
  1066. }
  1067. if (analog_ops->has_signal)
  1068. vt->signal = analog_ops->has_signal(&t->fe);
  1069. vt->audmode = t->audmode;
  1070. }
  1071. vt->capability |= V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
  1072. vt->rangelow = radio_range[0] * 16000;
  1073. vt->rangehigh = radio_range[1] * 16000;
  1074. return 0;
  1075. }
  1076. /**
  1077. * tuner_s_tuner - Set the tuner's audio mode
  1078. * @sd: pointer to struct v4l2_subdev
  1079. * @vt: pointer to struct v4l2_tuner
  1080. *
  1081. * Sets the audio mode if the tuner matches vt->type.
  1082. * Note: vt->type should be initialized before calling it.
  1083. * This is done by either video_ioctl2 or by the bridge driver.
  1084. */
  1085. static int tuner_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
  1086. {
  1087. struct tuner *t = to_tuner(sd);
  1088. if (set_mode(t, vt->type))
  1089. return 0;
  1090. if (t->mode == V4L2_TUNER_RADIO)
  1091. t->audmode = vt->audmode;
  1092. set_freq(t, 0);
  1093. return 0;
  1094. }
  1095. static int tuner_log_status(struct v4l2_subdev *sd)
  1096. {
  1097. struct tuner *t = to_tuner(sd);
  1098. struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
  1099. if (analog_ops->tuner_status)
  1100. analog_ops->tuner_status(&t->fe);
  1101. return 0;
  1102. }
  1103. static int tuner_suspend(struct i2c_client *c, pm_message_t state)
  1104. {
  1105. struct tuner *t = to_tuner(i2c_get_clientdata(c));
  1106. struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
  1107. tuner_dbg("suspend\n");
  1108. if (!t->standby && analog_ops->standby)
  1109. analog_ops->standby(&t->fe);
  1110. return 0;
  1111. }
  1112. static int tuner_resume(struct i2c_client *c)
  1113. {
  1114. struct tuner *t = to_tuner(i2c_get_clientdata(c));
  1115. tuner_dbg("resume\n");
  1116. if (!t->standby)
  1117. if (set_mode(t, t->mode) == 0)
  1118. set_freq(t, 0);
  1119. return 0;
  1120. }
  1121. static int tuner_command(struct i2c_client *client, unsigned cmd, void *arg)
  1122. {
  1123. struct v4l2_subdev *sd = i2c_get_clientdata(client);
  1124. /* TUNER_SET_CONFIG is still called by tuner-simple.c, so we have
  1125. to handle it here.
  1126. There must be a better way of doing this... */
  1127. switch (cmd) {
  1128. case TUNER_SET_CONFIG:
  1129. return tuner_s_config(sd, arg);
  1130. }
  1131. return -ENOIOCTLCMD;
  1132. }
  1133. /*
  1134. * Callback structs
  1135. */
  1136. static const struct v4l2_subdev_core_ops tuner_core_ops = {
  1137. .log_status = tuner_log_status,
  1138. .s_std = tuner_s_std,
  1139. .s_power = tuner_s_power,
  1140. };
  1141. static const struct v4l2_subdev_tuner_ops tuner_tuner_ops = {
  1142. .s_radio = tuner_s_radio,
  1143. .g_tuner = tuner_g_tuner,
  1144. .s_tuner = tuner_s_tuner,
  1145. .s_frequency = tuner_s_frequency,
  1146. .g_frequency = tuner_g_frequency,
  1147. .s_type_addr = tuner_s_type_addr,
  1148. .s_config = tuner_s_config,
  1149. };
  1150. static const struct v4l2_subdev_ops tuner_ops = {
  1151. .core = &tuner_core_ops,
  1152. .tuner = &tuner_tuner_ops,
  1153. };
  1154. /*
  1155. * I2C structs and module init functions
  1156. */
  1157. static const struct i2c_device_id tuner_id[] = {
  1158. { "tuner", }, /* autodetect */
  1159. { }
  1160. };
  1161. MODULE_DEVICE_TABLE(i2c, tuner_id);
  1162. static struct i2c_driver tuner_driver = {
  1163. .driver = {
  1164. .owner = THIS_MODULE,
  1165. .name = "tuner",
  1166. },
  1167. .probe = tuner_probe,
  1168. .remove = tuner_remove,
  1169. .command = tuner_command,
  1170. .suspend = tuner_suspend,
  1171. .resume = tuner_resume,
  1172. .id_table = tuner_id,
  1173. };
  1174. module_i2c_driver(tuner_driver);
  1175. MODULE_DESCRIPTION("device driver for various TV and TV+FM radio tuners");
  1176. MODULE_AUTHOR("Ralph Metzler, Gerd Knorr, Gunther Mayer");
  1177. MODULE_LICENSE("GPL");