radio-cadet.c 17 KB

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