radio-gemtek.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. /* GemTek radio card driver for Linux (C) 1998 Jonas Munsin <jmunsin@iki.fi>
  2. *
  3. * GemTek hasn't released any specs on the card, so the protocol had to
  4. * be reverse engineered with dosemu.
  5. *
  6. * Besides the protocol changes, this is mostly a copy of:
  7. *
  8. * RadioTrack II driver for Linux radio support (C) 1998 Ben Pfaff
  9. *
  10. * Based on RadioTrack I/RadioReveal (C) 1997 M. Kirkwood
  11. * Converted to new API by Alan Cox <Alan.Cox@linux.org>
  12. * Various bugfixes and enhancements by Russell Kroll <rkroll@exploits.org>
  13. *
  14. * TODO: Allow for more than one of these foolish entities :-)
  15. *
  16. * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
  17. */
  18. #include <linux/module.h> /* Modules */
  19. #include <linux/init.h> /* Initdata */
  20. #include <linux/ioport.h> /* request_region */
  21. #include <linux/delay.h> /* udelay */
  22. #include <asm/io.h> /* outb, outb_p */
  23. #include <asm/uaccess.h> /* copy to/from user */
  24. #include <linux/videodev2.h> /* kernel radio structs */
  25. #include <media/v4l2-ioctl.h>
  26. #include <media/v4l2-common.h>
  27. #include <linux/spinlock.h>
  28. #include <linux/version.h> /* for KERNEL_VERSION MACRO */
  29. #define RADIO_VERSION KERNEL_VERSION(0,0,3)
  30. #define RADIO_BANNER "GemTek Radio card driver: v0.0.3"
  31. /*
  32. * Module info.
  33. */
  34. MODULE_AUTHOR("Jonas Munsin, Pekka Seppänen <pexu@kapsi.fi>");
  35. MODULE_DESCRIPTION("A driver for the GemTek Radio card.");
  36. MODULE_LICENSE("GPL");
  37. /*
  38. * Module params.
  39. */
  40. #ifndef CONFIG_RADIO_GEMTEK_PORT
  41. #define CONFIG_RADIO_GEMTEK_PORT -1
  42. #endif
  43. #ifndef CONFIG_RADIO_GEMTEK_PROBE
  44. #define CONFIG_RADIO_GEMTEK_PROBE 1
  45. #endif
  46. static int io = CONFIG_RADIO_GEMTEK_PORT;
  47. static int probe = CONFIG_RADIO_GEMTEK_PROBE;
  48. static int hardmute;
  49. static int shutdown = 1;
  50. static int keepmuted = 1;
  51. static int initmute = 1;
  52. static int radio_nr = -1;
  53. module_param(io, int, 0444);
  54. MODULE_PARM_DESC(io, "Force I/O port for the GemTek Radio card if automatic "
  55. "probing is disabled or fails. The most common I/O ports are: 0x20c "
  56. "0x30c, 0x24c or 0x34c (0x20c, 0x248 and 0x28c have been reported to "
  57. "work for the combined sound/radiocard).");
  58. module_param(probe, bool, 0444);
  59. MODULE_PARM_DESC(probe, "Enable automatic device probing. Note: only the most "
  60. "common I/O ports used by the card are probed.");
  61. module_param(hardmute, bool, 0644);
  62. MODULE_PARM_DESC(hardmute, "Enable `hard muting' by shutting down PLL, may "
  63. "reduce static noise.");
  64. module_param(shutdown, bool, 0644);
  65. MODULE_PARM_DESC(shutdown, "Enable shutting down PLL and muting line when "
  66. "module is unloaded.");
  67. module_param(keepmuted, bool, 0644);
  68. MODULE_PARM_DESC(keepmuted, "Keep card muted even when frequency is changed.");
  69. module_param(initmute, bool, 0444);
  70. MODULE_PARM_DESC(initmute, "Mute card when module is loaded.");
  71. module_param(radio_nr, int, 0444);
  72. /*
  73. * Functions for controlling the card.
  74. */
  75. #define GEMTEK_LOWFREQ (87*16000)
  76. #define GEMTEK_HIGHFREQ (108*16000)
  77. /*
  78. * Frequency calculation constants. Intermediate frequency 10.52 MHz (nominal
  79. * value 10.7 MHz), reference divisor 6.39 kHz (nominal 6.25 kHz).
  80. */
  81. #define FSCALE 8
  82. #define IF_OFFSET ((unsigned int)(10.52 * 16000 * (1<<FSCALE)))
  83. #define REF_FREQ ((unsigned int)(6.39 * 16 * (1<<FSCALE)))
  84. #define GEMTEK_CK 0x01 /* Clock signal */
  85. #define GEMTEK_DA 0x02 /* Serial data */
  86. #define GEMTEK_CE 0x04 /* Chip enable */
  87. #define GEMTEK_NS 0x08 /* No signal */
  88. #define GEMTEK_MT 0x10 /* Line mute */
  89. #define GEMTEK_STDF_3_125_KHZ 0x01 /* Standard frequency 3.125 kHz */
  90. #define GEMTEK_PLL_OFF 0x07 /* PLL off */
  91. #define BU2614_BUS_SIZE 32 /* BU2614 / BU2614FS bus size */
  92. #define SHORT_DELAY 5 /* usec */
  93. #define LONG_DELAY 75 /* usec */
  94. struct gemtek_device {
  95. unsigned long lastfreq;
  96. int muted;
  97. u32 bu2614data;
  98. };
  99. #define BU2614_FREQ_BITS 16 /* D0..D15, Frequency data */
  100. #define BU2614_PORT_BITS 3 /* P0..P2, Output port control data */
  101. #define BU2614_VOID_BITS 4 /* unused */
  102. #define BU2614_FMES_BITS 1 /* CT, Frequency measurement beginning data */
  103. #define BU2614_STDF_BITS 3 /* R0..R2, Standard frequency data */
  104. #define BU2614_SWIN_BITS 1 /* S, Switch between FMIN / AMIN */
  105. #define BU2614_SWAL_BITS 1 /* PS, Swallow counter division (AMIN only)*/
  106. #define BU2614_VOID2_BITS 1 /* unused */
  107. #define BU2614_FMUN_BITS 1 /* GT, Frequency measurement time & unlock */
  108. #define BU2614_TEST_BITS 1 /* TS, Test data is input */
  109. #define BU2614_FREQ_SHIFT 0
  110. #define BU2614_PORT_SHIFT (BU2614_FREQ_BITS + BU2614_FREQ_SHIFT)
  111. #define BU2614_VOID_SHIFT (BU2614_PORT_BITS + BU2614_PORT_SHIFT)
  112. #define BU2614_FMES_SHIFT (BU2614_VOID_BITS + BU2614_VOID_SHIFT)
  113. #define BU2614_STDF_SHIFT (BU2614_FMES_BITS + BU2614_FMES_SHIFT)
  114. #define BU2614_SWIN_SHIFT (BU2614_STDF_BITS + BU2614_STDF_SHIFT)
  115. #define BU2614_SWAL_SHIFT (BU2614_SWIN_BITS + BU2614_SWIN_SHIFT)
  116. #define BU2614_VOID2_SHIFT (BU2614_SWAL_BITS + BU2614_SWAL_SHIFT)
  117. #define BU2614_FMUN_SHIFT (BU2614_VOID2_BITS + BU2614_VOID2_SHIFT)
  118. #define BU2614_TEST_SHIFT (BU2614_FMUN_BITS + BU2614_FMUN_SHIFT)
  119. #define MKMASK(field) (((1<<BU2614_##field##_BITS) - 1) << \
  120. BU2614_##field##_SHIFT)
  121. #define BU2614_PORT_MASK MKMASK(PORT)
  122. #define BU2614_FREQ_MASK MKMASK(FREQ)
  123. #define BU2614_VOID_MASK MKMASK(VOID)
  124. #define BU2614_FMES_MASK MKMASK(FMES)
  125. #define BU2614_STDF_MASK MKMASK(STDF)
  126. #define BU2614_SWIN_MASK MKMASK(SWIN)
  127. #define BU2614_SWAL_MASK MKMASK(SWAL)
  128. #define BU2614_VOID2_MASK MKMASK(VOID2)
  129. #define BU2614_FMUN_MASK MKMASK(FMUN)
  130. #define BU2614_TEST_MASK MKMASK(TEST)
  131. static struct gemtek_device gemtek_unit;
  132. static spinlock_t lock;
  133. /*
  134. * Set data which will be sent to BU2614FS.
  135. */
  136. #define gemtek_bu2614_set(dev, field, data) ((dev)->bu2614data = \
  137. ((dev)->bu2614data & ~field##_MASK) | ((data) << field##_SHIFT))
  138. /*
  139. * Transmit settings to BU2614FS over GemTek IC.
  140. */
  141. static void gemtek_bu2614_transmit(struct gemtek_device *dev)
  142. {
  143. int i, bit, q, mute;
  144. spin_lock(&lock);
  145. mute = dev->muted ? GEMTEK_MT : 0x00;
  146. outb_p(mute | GEMTEK_DA | GEMTEK_CK, io);
  147. udelay(SHORT_DELAY);
  148. outb_p(mute | GEMTEK_CE | GEMTEK_DA | GEMTEK_CK, io);
  149. udelay(LONG_DELAY);
  150. for (i = 0, q = dev->bu2614data; i < 32; i++, q >>= 1) {
  151. bit = (q & 1) ? GEMTEK_DA : 0;
  152. outb_p(mute | GEMTEK_CE | bit, io);
  153. udelay(SHORT_DELAY);
  154. outb_p(mute | GEMTEK_CE | bit | GEMTEK_CK, io);
  155. udelay(SHORT_DELAY);
  156. }
  157. outb_p(mute | GEMTEK_DA | GEMTEK_CK, io);
  158. udelay(SHORT_DELAY);
  159. outb_p(mute | GEMTEK_CE | GEMTEK_DA | GEMTEK_CK, io);
  160. udelay(LONG_DELAY);
  161. spin_unlock(&lock);
  162. }
  163. /*
  164. * Calculate divisor from FM-frequency for BU2614FS (3.125 KHz STDF expected).
  165. */
  166. static unsigned long gemtek_convfreq(unsigned long freq)
  167. {
  168. return ((freq<<FSCALE) + IF_OFFSET + REF_FREQ/2) / REF_FREQ;
  169. }
  170. /*
  171. * Set FM-frequency.
  172. */
  173. static void gemtek_setfreq(struct gemtek_device *dev, unsigned long freq)
  174. {
  175. if (keepmuted && hardmute && dev->muted)
  176. return;
  177. if (freq < GEMTEK_LOWFREQ)
  178. freq = GEMTEK_LOWFREQ;
  179. else if (freq > GEMTEK_HIGHFREQ)
  180. freq = GEMTEK_HIGHFREQ;
  181. dev->lastfreq = freq;
  182. dev->muted = 0;
  183. gemtek_bu2614_set(dev, BU2614_PORT, 0);
  184. gemtek_bu2614_set(dev, BU2614_FMES, 0);
  185. gemtek_bu2614_set(dev, BU2614_SWIN, 0); /* FM-mode */
  186. gemtek_bu2614_set(dev, BU2614_SWAL, 0);
  187. gemtek_bu2614_set(dev, BU2614_FMUN, 1); /* GT bit set */
  188. gemtek_bu2614_set(dev, BU2614_TEST, 0);
  189. gemtek_bu2614_set(dev, BU2614_STDF, GEMTEK_STDF_3_125_KHZ);
  190. gemtek_bu2614_set(dev, BU2614_FREQ, gemtek_convfreq(freq));
  191. gemtek_bu2614_transmit(dev);
  192. }
  193. /*
  194. * Set mute flag.
  195. */
  196. static void gemtek_mute(struct gemtek_device *dev)
  197. {
  198. int i;
  199. dev->muted = 1;
  200. if (hardmute) {
  201. /* Turn off PLL, disable data output */
  202. gemtek_bu2614_set(dev, BU2614_PORT, 0);
  203. gemtek_bu2614_set(dev, BU2614_FMES, 0); /* CT bit off */
  204. gemtek_bu2614_set(dev, BU2614_SWIN, 0); /* FM-mode */
  205. gemtek_bu2614_set(dev, BU2614_SWAL, 0);
  206. gemtek_bu2614_set(dev, BU2614_FMUN, 0); /* GT bit off */
  207. gemtek_bu2614_set(dev, BU2614_TEST, 0);
  208. gemtek_bu2614_set(dev, BU2614_STDF, GEMTEK_PLL_OFF);
  209. gemtek_bu2614_set(dev, BU2614_FREQ, 0);
  210. gemtek_bu2614_transmit(dev);
  211. } else {
  212. spin_lock(&lock);
  213. /* Read bus contents (CE, CK and DA). */
  214. i = inb_p(io);
  215. /* Write it back with mute flag set. */
  216. outb_p((i >> 5) | GEMTEK_MT, io);
  217. udelay(SHORT_DELAY);
  218. spin_unlock(&lock);
  219. }
  220. }
  221. /*
  222. * Unset mute flag.
  223. */
  224. static void gemtek_unmute(struct gemtek_device *dev)
  225. {
  226. int i;
  227. dev->muted = 0;
  228. if (hardmute) {
  229. /* Turn PLL back on. */
  230. gemtek_setfreq(dev, dev->lastfreq);
  231. } else {
  232. spin_lock(&lock);
  233. i = inb_p(io);
  234. outb_p(i >> 5, io);
  235. udelay(SHORT_DELAY);
  236. spin_unlock(&lock);
  237. }
  238. }
  239. /*
  240. * Get signal strength (= stereo status).
  241. */
  242. static inline int gemtek_getsigstr(void)
  243. {
  244. return inb_p(io) & GEMTEK_NS ? 0 : 1;
  245. }
  246. /*
  247. * Check if requested card acts like GemTek Radio card.
  248. */
  249. static int gemtek_verify(int port)
  250. {
  251. static int verified = -1;
  252. int i, q;
  253. if (verified == port)
  254. return 1;
  255. spin_lock(&lock);
  256. q = inb_p(port); /* Read bus contents before probing. */
  257. /* Try to turn on CE, CK and DA respectively and check if card responds
  258. properly. */
  259. for (i = 0; i < 3; ++i) {
  260. outb_p(1 << i, port);
  261. udelay(SHORT_DELAY);
  262. if ((inb_p(port) & (~GEMTEK_NS)) != (0x17 | (1 << (i + 5)))) {
  263. spin_unlock(&lock);
  264. return 0;
  265. }
  266. }
  267. outb_p(q >> 5, port); /* Write bus contents back. */
  268. udelay(SHORT_DELAY);
  269. spin_unlock(&lock);
  270. verified = port;
  271. return 1;
  272. }
  273. /*
  274. * Automatic probing for card.
  275. */
  276. static int gemtek_probe(void)
  277. {
  278. int ioports[] = { 0x20c, 0x30c, 0x24c, 0x34c, 0x248, 0x28c };
  279. int i;
  280. if (!probe) {
  281. printk(KERN_INFO "Automatic device probing disabled.\n");
  282. return -1;
  283. }
  284. printk(KERN_INFO "Automatic device probing enabled.\n");
  285. for (i = 0; i < ARRAY_SIZE(ioports); ++i) {
  286. printk(KERN_INFO "Trying I/O port 0x%x...\n", ioports[i]);
  287. if (!request_region(ioports[i], 1, "gemtek-probe")) {
  288. printk(KERN_WARNING "I/O port 0x%x busy!\n",
  289. ioports[i]);
  290. continue;
  291. }
  292. if (gemtek_verify(ioports[i])) {
  293. printk(KERN_INFO "Card found from I/O port "
  294. "0x%x!\n", ioports[i]);
  295. release_region(ioports[i], 1);
  296. io = ioports[i];
  297. return io;
  298. }
  299. release_region(ioports[i], 1);
  300. }
  301. printk(KERN_ERR "Automatic probing failed!\n");
  302. return -1;
  303. }
  304. /*
  305. * Video 4 Linux stuff.
  306. */
  307. static struct v4l2_queryctrl radio_qctrl[] = {
  308. {
  309. .id = V4L2_CID_AUDIO_MUTE,
  310. .name = "Mute",
  311. .minimum = 0,
  312. .maximum = 1,
  313. .default_value = 1,
  314. .type = V4L2_CTRL_TYPE_BOOLEAN,
  315. }, {
  316. .id = V4L2_CID_AUDIO_VOLUME,
  317. .name = "Volume",
  318. .minimum = 0,
  319. .maximum = 65535,
  320. .step = 65535,
  321. .default_value = 0xff,
  322. .type = V4L2_CTRL_TYPE_INTEGER,
  323. }
  324. };
  325. static const struct file_operations gemtek_fops = {
  326. .owner = THIS_MODULE,
  327. .open = video_exclusive_open,
  328. .release = video_exclusive_release,
  329. .ioctl = video_ioctl2,
  330. #ifdef CONFIG_COMPAT
  331. .compat_ioctl = v4l_compat_ioctl32,
  332. #endif
  333. .llseek = no_llseek
  334. };
  335. static int vidioc_querycap(struct file *file, void *priv,
  336. struct v4l2_capability *v)
  337. {
  338. strlcpy(v->driver, "radio-gemtek", sizeof(v->driver));
  339. strlcpy(v->card, "GemTek", sizeof(v->card));
  340. sprintf(v->bus_info, "ISA");
  341. v->version = RADIO_VERSION;
  342. v->capabilities = V4L2_CAP_TUNER;
  343. return 0;
  344. }
  345. static int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *v)
  346. {
  347. if (v->index > 0)
  348. return -EINVAL;
  349. strcpy(v->name, "FM");
  350. v->type = V4L2_TUNER_RADIO;
  351. v->rangelow = GEMTEK_LOWFREQ;
  352. v->rangehigh = GEMTEK_HIGHFREQ;
  353. v->capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
  354. v->signal = 0xffff * gemtek_getsigstr();
  355. if (v->signal) {
  356. v->audmode = V4L2_TUNER_MODE_STEREO;
  357. v->rxsubchans = V4L2_TUNER_SUB_STEREO;
  358. } else {
  359. v->audmode = V4L2_TUNER_MODE_MONO;
  360. v->rxsubchans = V4L2_TUNER_SUB_MONO;
  361. }
  362. return 0;
  363. }
  364. static int vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *v)
  365. {
  366. if (v->index > 0)
  367. return -EINVAL;
  368. return 0;
  369. }
  370. static int vidioc_s_frequency(struct file *file, void *priv,
  371. struct v4l2_frequency *f)
  372. {
  373. struct video_device *dev = video_devdata(file);
  374. struct gemtek_device *rt = dev->priv;
  375. gemtek_setfreq(rt, f->frequency);
  376. return 0;
  377. }
  378. static int vidioc_g_frequency(struct file *file, void *priv,
  379. struct v4l2_frequency *f)
  380. {
  381. struct video_device *dev = video_devdata(file);
  382. struct gemtek_device *rt = dev->priv;
  383. f->type = V4L2_TUNER_RADIO;
  384. f->frequency = rt->lastfreq;
  385. return 0;
  386. }
  387. static int vidioc_queryctrl(struct file *file, void *priv,
  388. struct v4l2_queryctrl *qc)
  389. {
  390. int i;
  391. for (i = 0; i < ARRAY_SIZE(radio_qctrl); ++i) {
  392. if (qc->id && qc->id == radio_qctrl[i].id) {
  393. memcpy(qc, &(radio_qctrl[i]), sizeof(*qc));
  394. return 0;
  395. }
  396. }
  397. return -EINVAL;
  398. }
  399. static int vidioc_g_ctrl(struct file *file, void *priv,
  400. struct v4l2_control *ctrl)
  401. {
  402. struct video_device *dev = video_devdata(file);
  403. struct gemtek_device *rt = dev->priv;
  404. switch (ctrl->id) {
  405. case V4L2_CID_AUDIO_MUTE:
  406. ctrl->value = rt->muted;
  407. return 0;
  408. case V4L2_CID_AUDIO_VOLUME:
  409. if (rt->muted)
  410. ctrl->value = 0;
  411. else
  412. ctrl->value = 65535;
  413. return 0;
  414. }
  415. return -EINVAL;
  416. }
  417. static int vidioc_s_ctrl(struct file *file, void *priv,
  418. struct v4l2_control *ctrl)
  419. {
  420. struct video_device *dev = video_devdata(file);
  421. struct gemtek_device *rt = dev->priv;
  422. switch (ctrl->id) {
  423. case V4L2_CID_AUDIO_MUTE:
  424. if (ctrl->value)
  425. gemtek_mute(rt);
  426. else
  427. gemtek_unmute(rt);
  428. return 0;
  429. case V4L2_CID_AUDIO_VOLUME:
  430. if (ctrl->value)
  431. gemtek_unmute(rt);
  432. else
  433. gemtek_mute(rt);
  434. return 0;
  435. }
  436. return -EINVAL;
  437. }
  438. static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
  439. {
  440. if (a->index > 1)
  441. return -EINVAL;
  442. strcpy(a->name, "Radio");
  443. a->capability = V4L2_AUDCAP_STEREO;
  444. return 0;
  445. }
  446. static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
  447. {
  448. *i = 0;
  449. return 0;
  450. }
  451. static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
  452. {
  453. if (i != 0)
  454. return -EINVAL;
  455. return 0;
  456. }
  457. static int vidioc_s_audio(struct file *file, void *priv, struct v4l2_audio *a)
  458. {
  459. if (a->index != 0)
  460. return -EINVAL;
  461. return 0;
  462. }
  463. static const struct v4l2_ioctl_ops gemtek_ioctl_ops = {
  464. .vidioc_querycap = vidioc_querycap,
  465. .vidioc_g_tuner = vidioc_g_tuner,
  466. .vidioc_s_tuner = vidioc_s_tuner,
  467. .vidioc_g_audio = vidioc_g_audio,
  468. .vidioc_s_audio = vidioc_s_audio,
  469. .vidioc_g_input = vidioc_g_input,
  470. .vidioc_s_input = vidioc_s_input,
  471. .vidioc_g_frequency = vidioc_g_frequency,
  472. .vidioc_s_frequency = vidioc_s_frequency,
  473. .vidioc_queryctrl = vidioc_queryctrl,
  474. .vidioc_g_ctrl = vidioc_g_ctrl,
  475. .vidioc_s_ctrl = vidioc_s_ctrl
  476. };
  477. static struct video_device gemtek_radio = {
  478. .name = "GemTek Radio card",
  479. .fops = &gemtek_fops,
  480. .ioctl_ops = &gemtek_ioctl_ops,
  481. };
  482. /*
  483. * Initialization / cleanup related stuff.
  484. */
  485. /*
  486. * Initilize card.
  487. */
  488. static int __init gemtek_init(void)
  489. {
  490. printk(KERN_INFO RADIO_BANNER "\n");
  491. spin_lock_init(&lock);
  492. gemtek_probe();
  493. if (io) {
  494. if (!request_region(io, 1, "gemtek")) {
  495. printk(KERN_ERR "I/O port 0x%x already in use.\n", io);
  496. return -EBUSY;
  497. }
  498. if (!gemtek_verify(io))
  499. printk(KERN_WARNING "Card at I/O port 0x%x does not "
  500. "respond properly, check your "
  501. "configuration.\n", io);
  502. else
  503. printk(KERN_INFO "Using I/O port 0x%x.\n", io);
  504. } else if (probe) {
  505. printk(KERN_ERR "Automatic probing failed and no "
  506. "fixed I/O port defined.\n");
  507. return -ENODEV;
  508. } else {
  509. printk(KERN_ERR "Automatic probing disabled but no fixed "
  510. "I/O port defined.");
  511. return -EINVAL;
  512. }
  513. gemtek_radio.priv = &gemtek_unit;
  514. if (video_register_device(&gemtek_radio, VFL_TYPE_RADIO,
  515. radio_nr) == -1) {
  516. release_region(io, 1);
  517. return -EBUSY;
  518. }
  519. /* Set defaults */
  520. gemtek_unit.lastfreq = GEMTEK_LOWFREQ;
  521. gemtek_unit.bu2614data = 0;
  522. if (initmute)
  523. gemtek_mute(&gemtek_unit);
  524. return 0;
  525. }
  526. /*
  527. * Module cleanup
  528. */
  529. static void __exit gemtek_exit(void)
  530. {
  531. if (shutdown) {
  532. hardmute = 1; /* Turn off PLL */
  533. gemtek_mute(&gemtek_unit);
  534. } else {
  535. printk(KERN_INFO "Module unloaded but card not muted!\n");
  536. }
  537. video_unregister_device(&gemtek_radio);
  538. release_region(io, 1);
  539. }
  540. module_init(gemtek_init);
  541. module_exit(gemtek_exit);