radio-gemtek.c 16 KB

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