radio-cadet.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* radio-cadet.c - A video4linux driver for the ADS Cadet AM/FM Radio Card
  3. *
  4. * by Fred Gleason <[email protected]>
  5. * Version 0.3.3
  6. *
  7. * (Loosely) based on code for the Aztech radio card by
  8. *
  9. * Russell Kroll ([email protected])
  10. * Quay Ly
  11. * Donald Song
  12. * Jason Lewis ([email protected])
  13. * Scott McGrath ([email protected])
  14. * William McGrath ([email protected])
  15. *
  16. * History:
  17. * 2000-04-29 Russell Kroll <[email protected]>
  18. * Added ISAPnP detection for Linux 2.3/2.4
  19. *
  20. * 2001-01-10 Russell Kroll <[email protected]>
  21. * Removed dead CONFIG_RADIO_CADET_PORT code
  22. * PnP detection on load is now default (no args necessary)
  23. *
  24. * 2002-01-17 Adam Belay <[email protected]>
  25. * Updated to latest pnp code
  26. *
  27. * 2003-01-31 Alan Cox <[email protected]>
  28. * Cleaned up locking, delay code, general odds and ends
  29. *
  30. * 2006-07-30 Hans J. Koch <[email protected]>
  31. * Changed API to V4L2
  32. */
  33. #include <linux/module.h> /* Modules */
  34. #include <linux/init.h> /* Initdata */
  35. #include <linux/ioport.h> /* request_region */
  36. #include <linux/delay.h> /* udelay */
  37. #include <linux/videodev2.h> /* V4L2 API defs */
  38. #include <linux/param.h>
  39. #include <linux/pnp.h>
  40. #include <linux/sched.h>
  41. #include <linux/io.h> /* outb, outb_p */
  42. #include <media/v4l2-device.h>
  43. #include <media/v4l2-ioctl.h>
  44. #include <media/v4l2-ctrls.h>
  45. #include <media/v4l2-fh.h>
  46. #include <media/v4l2-event.h>
  47. MODULE_AUTHOR("Fred Gleason, Russell Kroll, Quay Lu, Donald Song, Jason Lewis, Scott McGrath, William McGrath");
  48. MODULE_DESCRIPTION("A driver for the ADS Cadet AM/FM/RDS radio card.");
  49. MODULE_LICENSE("GPL");
  50. MODULE_VERSION("0.3.4");
  51. static int io = -1; /* default to isapnp activation */
  52. static int radio_nr = -1;
  53. module_param(io, int, 0);
  54. MODULE_PARM_DESC(io, "I/O address of Cadet card (0x330,0x332,0x334,0x336,0x338,0x33a,0x33c,0x33e)");
  55. module_param(radio_nr, int, 0);
  56. #define RDS_BUFFER 256
  57. #define RDS_RX_FLAG 1
  58. #define MBS_RX_FLAG 2
  59. struct cadet {
  60. struct v4l2_device v4l2_dev;
  61. struct video_device vdev;
  62. struct v4l2_ctrl_handler ctrl_handler;
  63. int io;
  64. bool is_fm_band;
  65. u32 curfreq;
  66. int tunestat;
  67. int sigstrength;
  68. wait_queue_head_t read_queue;
  69. struct timer_list readtimer;
  70. u8 rdsin, rdsout, rdsstat;
  71. unsigned char rdsbuf[RDS_BUFFER];
  72. struct mutex lock;
  73. int reading;
  74. };
  75. static struct cadet cadet_card;
  76. /*
  77. * Signal Strength Threshold Values
  78. * The V4L API spec does not define any particular unit for the signal
  79. * strength value. These values are in microvolts of RF at the tuner's input.
  80. */
  81. static u16 sigtable[2][4] = {
  82. { 1835, 2621, 4128, 65535 },
  83. { 2185, 4369, 13107, 65535 },
  84. };
  85. static const struct v4l2_frequency_band bands[] = {
  86. {
  87. .index = 0,
  88. .type = V4L2_TUNER_RADIO,
  89. .capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_FREQ_BANDS,
  90. .rangelow = 8320, /* 520 kHz */
  91. .rangehigh = 26400, /* 1650 kHz */
  92. .modulation = V4L2_BAND_MODULATION_AM,
  93. }, {
  94. .index = 1,
  95. .type = V4L2_TUNER_RADIO,
  96. .capability = V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_RDS |
  97. V4L2_TUNER_CAP_RDS_BLOCK_IO | V4L2_TUNER_CAP_LOW |
  98. V4L2_TUNER_CAP_FREQ_BANDS,
  99. .rangelow = 1400000, /* 87.5 MHz */
  100. .rangehigh = 1728000, /* 108.0 MHz */
  101. .modulation = V4L2_BAND_MODULATION_FM,
  102. },
  103. };
  104. static int cadet_getstereo(struct cadet *dev)
  105. {
  106. int ret = V4L2_TUNER_SUB_MONO;
  107. if (!dev->is_fm_band) /* Only FM has stereo capability! */
  108. return V4L2_TUNER_SUB_MONO;
  109. outb(7, dev->io); /* Select tuner control */
  110. if ((inb(dev->io + 1) & 0x40) == 0)
  111. ret = V4L2_TUNER_SUB_STEREO;
  112. return ret;
  113. }
  114. static unsigned cadet_gettune(struct cadet *dev)
  115. {
  116. int curvol, i;
  117. unsigned fifo = 0;
  118. /*
  119. * Prepare for read
  120. */
  121. outb(7, dev->io); /* Select tuner control */
  122. curvol = inb(dev->io + 1); /* Save current volume/mute setting */
  123. outb(0x00, dev->io + 1); /* Ensure WRITE-ENABLE is LOW */
  124. dev->tunestat = 0xffff;
  125. /*
  126. * Read the shift register
  127. */
  128. for (i = 0; i < 25; i++) {
  129. fifo = (fifo << 1) | ((inb(dev->io + 1) >> 7) & 0x01);
  130. if (i < 24) {
  131. outb(0x01, dev->io + 1);
  132. dev->tunestat &= inb(dev->io + 1);
  133. outb(0x00, dev->io + 1);
  134. }
  135. }
  136. /*
  137. * Restore volume/mute setting
  138. */
  139. outb(curvol, dev->io + 1);
  140. return fifo;
  141. }
  142. static unsigned cadet_getfreq(struct cadet *dev)
  143. {
  144. int i;
  145. unsigned freq = 0, test, fifo = 0;
  146. /*
  147. * Read current tuning
  148. */
  149. fifo = cadet_gettune(dev);
  150. /*
  151. * Convert to actual frequency
  152. */
  153. if (!dev->is_fm_band) /* AM */
  154. return ((fifo & 0x7fff) - 450) * 16;
  155. test = 12500;
  156. for (i = 0; i < 14; i++) {
  157. if ((fifo & 0x01) != 0)
  158. freq += test;
  159. test = test << 1;
  160. fifo = fifo >> 1;
  161. }
  162. freq -= 10700000; /* IF frequency is 10.7 MHz */
  163. freq = (freq * 16) / 1000; /* Make it 1/16 kHz */
  164. return freq;
  165. }
  166. static void cadet_settune(struct cadet *dev, unsigned fifo)
  167. {
  168. int i;
  169. unsigned test;
  170. outb(7, dev->io); /* Select tuner control */
  171. /*
  172. * Write the shift register
  173. */
  174. test = 0;
  175. test = (fifo >> 23) & 0x02; /* Align data for SDO */
  176. test |= 0x1c; /* SDM=1, SWE=1, SEN=1, SCK=0 */
  177. outb(7, dev->io); /* Select tuner control */
  178. outb(test, dev->io + 1); /* Initialize for write */
  179. for (i = 0; i < 25; i++) {
  180. test |= 0x01; /* Toggle SCK High */
  181. outb(test, dev->io + 1);
  182. test &= 0xfe; /* Toggle SCK Low */
  183. outb(test, dev->io + 1);
  184. fifo = fifo << 1; /* Prepare the next bit */
  185. test = 0x1c | ((fifo >> 23) & 0x02);
  186. outb(test, dev->io + 1);
  187. }
  188. }
  189. static void cadet_setfreq(struct cadet *dev, unsigned freq)
  190. {
  191. unsigned fifo;
  192. int i, j, test;
  193. int curvol;
  194. freq = clamp(freq, bands[dev->is_fm_band].rangelow,
  195. bands[dev->is_fm_band].rangehigh);
  196. dev->curfreq = freq;
  197. /*
  198. * Formulate a fifo command
  199. */
  200. fifo = 0;
  201. if (dev->is_fm_band) { /* FM */
  202. test = 102400;
  203. freq = freq / 16; /* Make it kHz */
  204. freq += 10700; /* IF is 10700 kHz */
  205. for (i = 0; i < 14; i++) {
  206. fifo = fifo << 1;
  207. if (freq >= test) {
  208. fifo |= 0x01;
  209. freq -= test;
  210. }
  211. test = test >> 1;
  212. }
  213. } else { /* AM */
  214. fifo = (freq / 16) + 450; /* Make it kHz */
  215. fifo |= 0x100000; /* Select AM Band */
  216. }
  217. /*
  218. * Save current volume/mute setting
  219. */
  220. outb(7, dev->io); /* Select tuner control */
  221. curvol = inb(dev->io + 1);
  222. /*
  223. * Tune the card
  224. */
  225. for (j = 3; j > -1; j--) {
  226. cadet_settune(dev, fifo | (j << 16));
  227. outb(7, dev->io); /* Select tuner control */
  228. outb(curvol, dev->io + 1);
  229. msleep(100);
  230. cadet_gettune(dev);
  231. if ((dev->tunestat & 0x40) == 0) { /* Tuned */
  232. dev->sigstrength = sigtable[dev->is_fm_band][j];
  233. goto reset_rds;
  234. }
  235. }
  236. dev->sigstrength = 0;
  237. reset_rds:
  238. outb(3, dev->io);
  239. outb(inb(dev->io + 1) & 0x7f, dev->io + 1);
  240. }
  241. static bool cadet_has_rds_data(struct cadet *dev)
  242. {
  243. bool result;
  244. mutex_lock(&dev->lock);
  245. result = dev->rdsin != dev->rdsout;
  246. mutex_unlock(&dev->lock);
  247. return result;
  248. }
  249. static void cadet_handler(struct timer_list *t)
  250. {
  251. struct cadet *dev = from_timer(dev, t, readtimer);
  252. /* Service the RDS fifo */
  253. if (mutex_trylock(&dev->lock)) {
  254. outb(0x3, dev->io); /* Select RDS Decoder Control */
  255. if ((inb(dev->io + 1) & 0x20) != 0)
  256. pr_err("cadet: RDS fifo overflow\n");
  257. outb(0x80, dev->io); /* Select RDS fifo */
  258. while ((inb(dev->io) & 0x80) != 0) {
  259. dev->rdsbuf[dev->rdsin] = inb(dev->io + 1);
  260. if (dev->rdsin + 1 != dev->rdsout)
  261. dev->rdsin++;
  262. }
  263. mutex_unlock(&dev->lock);
  264. }
  265. /*
  266. * Service pending read
  267. */
  268. if (cadet_has_rds_data(dev))
  269. wake_up_interruptible(&dev->read_queue);
  270. /*
  271. * Clean up and exit
  272. */
  273. dev->readtimer.expires = jiffies + msecs_to_jiffies(50);
  274. add_timer(&dev->readtimer);
  275. }
  276. static void cadet_start_rds(struct cadet *dev)
  277. {
  278. dev->rdsstat = 1;
  279. outb(0x80, dev->io); /* Select RDS fifo */
  280. timer_setup(&dev->readtimer, cadet_handler, 0);
  281. dev->readtimer.expires = jiffies + msecs_to_jiffies(50);
  282. add_timer(&dev->readtimer);
  283. }
  284. static ssize_t cadet_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
  285. {
  286. struct cadet *dev = video_drvdata(file);
  287. unsigned char readbuf[RDS_BUFFER];
  288. int i = 0;
  289. mutex_lock(&dev->lock);
  290. if (dev->rdsstat == 0)
  291. cadet_start_rds(dev);
  292. mutex_unlock(&dev->lock);
  293. if (!cadet_has_rds_data(dev) && (file->f_flags & O_NONBLOCK))
  294. return -EWOULDBLOCK;
  295. i = wait_event_interruptible(dev->read_queue, cadet_has_rds_data(dev));
  296. if (i)
  297. return i;
  298. mutex_lock(&dev->lock);
  299. while (i < count && dev->rdsin != dev->rdsout)
  300. readbuf[i++] = dev->rdsbuf[dev->rdsout++];
  301. mutex_unlock(&dev->lock);
  302. if (i && copy_to_user(data, readbuf, i))
  303. return -EFAULT;
  304. return i;
  305. }
  306. static int vidioc_querycap(struct file *file, void *priv,
  307. struct v4l2_capability *v)
  308. {
  309. strscpy(v->driver, "ADS Cadet", sizeof(v->driver));
  310. strscpy(v->card, "ADS Cadet", sizeof(v->card));
  311. strscpy(v->bus_info, "ISA:radio-cadet", sizeof(v->bus_info));
  312. return 0;
  313. }
  314. static int vidioc_g_tuner(struct file *file, void *priv,
  315. struct v4l2_tuner *v)
  316. {
  317. struct cadet *dev = video_drvdata(file);
  318. if (v->index)
  319. return -EINVAL;
  320. v->type = V4L2_TUNER_RADIO;
  321. strscpy(v->name, "Radio", sizeof(v->name));
  322. v->capability = bands[0].capability | bands[1].capability;
  323. v->rangelow = bands[0].rangelow; /* 520 kHz (start of AM band) */
  324. v->rangehigh = bands[1].rangehigh; /* 108.0 MHz (end of FM band) */
  325. if (dev->is_fm_band) {
  326. v->rxsubchans = cadet_getstereo(dev);
  327. outb(3, dev->io);
  328. outb(inb(dev->io + 1) & 0x7f, dev->io + 1);
  329. mdelay(100);
  330. outb(3, dev->io);
  331. if (inb(dev->io + 1) & 0x80)
  332. v->rxsubchans |= V4L2_TUNER_SUB_RDS;
  333. } else {
  334. v->rangelow = 8320; /* 520 kHz */
  335. v->rangehigh = 26400; /* 1650 kHz */
  336. v->rxsubchans = V4L2_TUNER_SUB_MONO;
  337. }
  338. v->audmode = V4L2_TUNER_MODE_STEREO;
  339. v->signal = dev->sigstrength; /* We might need to modify scaling of this */
  340. return 0;
  341. }
  342. static int vidioc_s_tuner(struct file *file, void *priv,
  343. const struct v4l2_tuner *v)
  344. {
  345. return v->index ? -EINVAL : 0;
  346. }
  347. static int vidioc_enum_freq_bands(struct file *file, void *priv,
  348. struct v4l2_frequency_band *band)
  349. {
  350. if (band->tuner)
  351. return -EINVAL;
  352. if (band->index >= ARRAY_SIZE(bands))
  353. return -EINVAL;
  354. *band = bands[band->index];
  355. return 0;
  356. }
  357. static int vidioc_g_frequency(struct file *file, void *priv,
  358. struct v4l2_frequency *f)
  359. {
  360. struct cadet *dev = video_drvdata(file);
  361. if (f->tuner)
  362. return -EINVAL;
  363. f->type = V4L2_TUNER_RADIO;
  364. f->frequency = dev->curfreq;
  365. return 0;
  366. }
  367. static int vidioc_s_frequency(struct file *file, void *priv,
  368. const struct v4l2_frequency *f)
  369. {
  370. struct cadet *dev = video_drvdata(file);
  371. if (f->tuner)
  372. return -EINVAL;
  373. dev->is_fm_band =
  374. f->frequency >= (bands[0].rangehigh + bands[1].rangelow) / 2;
  375. cadet_setfreq(dev, f->frequency);
  376. return 0;
  377. }
  378. static int cadet_s_ctrl(struct v4l2_ctrl *ctrl)
  379. {
  380. struct cadet *dev = container_of(ctrl->handler, struct cadet, ctrl_handler);
  381. switch (ctrl->id) {
  382. case V4L2_CID_AUDIO_MUTE:
  383. outb(7, dev->io); /* Select tuner control */
  384. if (ctrl->val)
  385. outb(0x00, dev->io + 1);
  386. else
  387. outb(0x20, dev->io + 1);
  388. return 0;
  389. }
  390. return -EINVAL;
  391. }
  392. static int cadet_open(struct file *file)
  393. {
  394. struct cadet *dev = video_drvdata(file);
  395. int err;
  396. mutex_lock(&dev->lock);
  397. err = v4l2_fh_open(file);
  398. if (err)
  399. goto fail;
  400. if (v4l2_fh_is_singular_file(file))
  401. init_waitqueue_head(&dev->read_queue);
  402. fail:
  403. mutex_unlock(&dev->lock);
  404. return err;
  405. }
  406. static int cadet_release(struct file *file)
  407. {
  408. struct cadet *dev = video_drvdata(file);
  409. mutex_lock(&dev->lock);
  410. if (v4l2_fh_is_singular_file(file) && dev->rdsstat) {
  411. del_timer_sync(&dev->readtimer);
  412. dev->rdsstat = 0;
  413. }
  414. v4l2_fh_release(file);
  415. mutex_unlock(&dev->lock);
  416. return 0;
  417. }
  418. static __poll_t cadet_poll(struct file *file, struct poll_table_struct *wait)
  419. {
  420. struct cadet *dev = video_drvdata(file);
  421. __poll_t req_events = poll_requested_events(wait);
  422. __poll_t res = v4l2_ctrl_poll(file, wait);
  423. poll_wait(file, &dev->read_queue, wait);
  424. if (dev->rdsstat == 0 && (req_events & (EPOLLIN | EPOLLRDNORM))) {
  425. mutex_lock(&dev->lock);
  426. if (dev->rdsstat == 0)
  427. cadet_start_rds(dev);
  428. mutex_unlock(&dev->lock);
  429. }
  430. if (cadet_has_rds_data(dev))
  431. res |= EPOLLIN | EPOLLRDNORM;
  432. return res;
  433. }
  434. static const struct v4l2_file_operations cadet_fops = {
  435. .owner = THIS_MODULE,
  436. .open = cadet_open,
  437. .release = cadet_release,
  438. .read = cadet_read,
  439. .unlocked_ioctl = video_ioctl2,
  440. .poll = cadet_poll,
  441. };
  442. static const struct v4l2_ioctl_ops cadet_ioctl_ops = {
  443. .vidioc_querycap = vidioc_querycap,
  444. .vidioc_g_tuner = vidioc_g_tuner,
  445. .vidioc_s_tuner = vidioc_s_tuner,
  446. .vidioc_g_frequency = vidioc_g_frequency,
  447. .vidioc_s_frequency = vidioc_s_frequency,
  448. .vidioc_enum_freq_bands = vidioc_enum_freq_bands,
  449. .vidioc_log_status = v4l2_ctrl_log_status,
  450. .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
  451. .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
  452. };
  453. static const struct v4l2_ctrl_ops cadet_ctrl_ops = {
  454. .s_ctrl = cadet_s_ctrl,
  455. };
  456. #ifdef CONFIG_PNP
  457. static const struct pnp_device_id cadet_pnp_devices[] = {
  458. /* ADS Cadet AM/FM Radio Card */
  459. {.id = "MSM0c24", .driver_data = 0},
  460. {.id = ""}
  461. };
  462. MODULE_DEVICE_TABLE(pnp, cadet_pnp_devices);
  463. static int cadet_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
  464. {
  465. if (!dev)
  466. return -ENODEV;
  467. /* only support one device */
  468. if (io > 0)
  469. return -EBUSY;
  470. if (!pnp_port_valid(dev, 0))
  471. return -ENODEV;
  472. io = pnp_port_start(dev, 0);
  473. printk(KERN_INFO "radio-cadet: PnP reports device at %#x\n", io);
  474. return io;
  475. }
  476. static struct pnp_driver cadet_pnp_driver = {
  477. .name = "radio-cadet",
  478. .id_table = cadet_pnp_devices,
  479. .probe = cadet_pnp_probe,
  480. .remove = NULL,
  481. };
  482. #else
  483. static struct pnp_driver cadet_pnp_driver;
  484. #endif
  485. static void cadet_probe(struct cadet *dev)
  486. {
  487. static int iovals[8] = { 0x330, 0x332, 0x334, 0x336, 0x338, 0x33a, 0x33c, 0x33e };
  488. int i;
  489. for (i = 0; i < 8; i++) {
  490. dev->io = iovals[i];
  491. if (request_region(dev->io, 2, "cadet-probe")) {
  492. cadet_setfreq(dev, bands[1].rangelow);
  493. if (cadet_getfreq(dev) == bands[1].rangelow) {
  494. release_region(dev->io, 2);
  495. return;
  496. }
  497. release_region(dev->io, 2);
  498. }
  499. }
  500. dev->io = -1;
  501. }
  502. /*
  503. * io should only be set if the user has used something like
  504. * isapnp (the userspace program) to initialize this card for us
  505. */
  506. static int __init cadet_init(void)
  507. {
  508. struct cadet *dev = &cadet_card;
  509. struct v4l2_device *v4l2_dev = &dev->v4l2_dev;
  510. struct v4l2_ctrl_handler *hdl;
  511. int res = -ENODEV;
  512. strscpy(v4l2_dev->name, "cadet", sizeof(v4l2_dev->name));
  513. mutex_init(&dev->lock);
  514. /* If a probe was requested then probe ISAPnP first (safest) */
  515. if (io < 0)
  516. pnp_register_driver(&cadet_pnp_driver);
  517. dev->io = io;
  518. /* If that fails then probe unsafely if probe is requested */
  519. if (dev->io < 0)
  520. cadet_probe(dev);
  521. /* Else we bail out */
  522. if (dev->io < 0) {
  523. #ifdef MODULE
  524. v4l2_err(v4l2_dev, "you must set an I/O address with io=0x330, 0x332, 0x334,\n");
  525. v4l2_err(v4l2_dev, "0x336, 0x338, 0x33a, 0x33c or 0x33e\n");
  526. #endif
  527. goto fail;
  528. }
  529. if (!request_region(dev->io, 2, "cadet"))
  530. goto fail;
  531. res = v4l2_device_register(NULL, v4l2_dev);
  532. if (res < 0) {
  533. release_region(dev->io, 2);
  534. v4l2_err(v4l2_dev, "could not register v4l2_device\n");
  535. goto fail;
  536. }
  537. hdl = &dev->ctrl_handler;
  538. v4l2_ctrl_handler_init(hdl, 2);
  539. v4l2_ctrl_new_std(hdl, &cadet_ctrl_ops,
  540. V4L2_CID_AUDIO_MUTE, 0, 1, 1, 1);
  541. v4l2_dev->ctrl_handler = hdl;
  542. if (hdl->error) {
  543. res = hdl->error;
  544. v4l2_err(v4l2_dev, "Could not register controls\n");
  545. goto err_hdl;
  546. }
  547. dev->is_fm_band = true;
  548. dev->curfreq = bands[dev->is_fm_band].rangelow;
  549. cadet_setfreq(dev, dev->curfreq);
  550. strscpy(dev->vdev.name, v4l2_dev->name, sizeof(dev->vdev.name));
  551. dev->vdev.v4l2_dev = v4l2_dev;
  552. dev->vdev.fops = &cadet_fops;
  553. dev->vdev.ioctl_ops = &cadet_ioctl_ops;
  554. dev->vdev.release = video_device_release_empty;
  555. dev->vdev.lock = &dev->lock;
  556. dev->vdev.device_caps = V4L2_CAP_TUNER | V4L2_CAP_RADIO |
  557. V4L2_CAP_READWRITE | V4L2_CAP_RDS_CAPTURE;
  558. video_set_drvdata(&dev->vdev, dev);
  559. res = video_register_device(&dev->vdev, VFL_TYPE_RADIO, radio_nr);
  560. if (res < 0)
  561. goto err_hdl;
  562. v4l2_info(v4l2_dev, "ADS Cadet Radio Card at 0x%x\n", dev->io);
  563. return 0;
  564. err_hdl:
  565. v4l2_ctrl_handler_free(hdl);
  566. v4l2_device_unregister(v4l2_dev);
  567. release_region(dev->io, 2);
  568. fail:
  569. pnp_unregister_driver(&cadet_pnp_driver);
  570. return res;
  571. }
  572. static void __exit cadet_exit(void)
  573. {
  574. struct cadet *dev = &cadet_card;
  575. video_unregister_device(&dev->vdev);
  576. v4l2_ctrl_handler_free(&dev->ctrl_handler);
  577. v4l2_device_unregister(&dev->v4l2_dev);
  578. outb(7, dev->io); /* Mute */
  579. outb(0x00, dev->io + 1);
  580. release_region(dev->io, 2);
  581. pnp_unregister_driver(&cadet_pnp_driver);
  582. }
  583. module_init(cadet_init);
  584. module_exit(cadet_exit);