radio-gemtek.c 16 KB

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