radio-gemtek.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  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. 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 inode *inode, struct file *file)
  327. {
  328. return test_and_set_bit(0, &in_use) ? -EBUSY : 0;
  329. }
  330. static int gemtek_exclusive_release(struct inode *inode, struct file *file)
  331. {
  332. clear_bit(0, &in_use);
  333. return 0;
  334. }
  335. static const struct file_operations gemtek_fops = {
  336. .owner = THIS_MODULE,
  337. .open = gemtek_exclusive_open,
  338. .release = gemtek_exclusive_release,
  339. .ioctl = video_ioctl2,
  340. #ifdef CONFIG_COMPAT
  341. .compat_ioctl = v4l_compat_ioctl32,
  342. #endif
  343. .llseek = no_llseek
  344. };
  345. static int vidioc_querycap(struct file *file, void *priv,
  346. struct v4l2_capability *v)
  347. {
  348. strlcpy(v->driver, "radio-gemtek", sizeof(v->driver));
  349. strlcpy(v->card, "GemTek", sizeof(v->card));
  350. sprintf(v->bus_info, "ISA");
  351. v->version = RADIO_VERSION;
  352. v->capabilities = V4L2_CAP_TUNER;
  353. return 0;
  354. }
  355. static int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *v)
  356. {
  357. if (v->index > 0)
  358. return -EINVAL;
  359. strcpy(v->name, "FM");
  360. v->type = V4L2_TUNER_RADIO;
  361. v->rangelow = GEMTEK_LOWFREQ;
  362. v->rangehigh = GEMTEK_HIGHFREQ;
  363. v->capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
  364. v->signal = 0xffff * gemtek_getsigstr();
  365. if (v->signal) {
  366. v->audmode = V4L2_TUNER_MODE_STEREO;
  367. v->rxsubchans = V4L2_TUNER_SUB_STEREO;
  368. } else {
  369. v->audmode = V4L2_TUNER_MODE_MONO;
  370. v->rxsubchans = V4L2_TUNER_SUB_MONO;
  371. }
  372. return 0;
  373. }
  374. static int vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *v)
  375. {
  376. if (v->index > 0)
  377. return -EINVAL;
  378. return 0;
  379. }
  380. static int vidioc_s_frequency(struct file *file, void *priv,
  381. struct v4l2_frequency *f)
  382. {
  383. struct gemtek_device *rt = video_drvdata(file);
  384. gemtek_setfreq(rt, f->frequency);
  385. return 0;
  386. }
  387. static int vidioc_g_frequency(struct file *file, void *priv,
  388. struct v4l2_frequency *f)
  389. {
  390. struct gemtek_device *rt = video_drvdata(file);
  391. f->type = V4L2_TUNER_RADIO;
  392. f->frequency = rt->lastfreq;
  393. return 0;
  394. }
  395. static int vidioc_queryctrl(struct file *file, void *priv,
  396. struct v4l2_queryctrl *qc)
  397. {
  398. int i;
  399. for (i = 0; i < ARRAY_SIZE(radio_qctrl); ++i) {
  400. if (qc->id && qc->id == radio_qctrl[i].id) {
  401. memcpy(qc, &(radio_qctrl[i]), sizeof(*qc));
  402. return 0;
  403. }
  404. }
  405. return -EINVAL;
  406. }
  407. static int vidioc_g_ctrl(struct file *file, void *priv,
  408. struct v4l2_control *ctrl)
  409. {
  410. struct gemtek_device *rt = video_drvdata(file);
  411. switch (ctrl->id) {
  412. case V4L2_CID_AUDIO_MUTE:
  413. ctrl->value = rt->muted;
  414. return 0;
  415. case V4L2_CID_AUDIO_VOLUME:
  416. if (rt->muted)
  417. ctrl->value = 0;
  418. else
  419. ctrl->value = 65535;
  420. return 0;
  421. }
  422. return -EINVAL;
  423. }
  424. static int vidioc_s_ctrl(struct file *file, void *priv,
  425. struct v4l2_control *ctrl)
  426. {
  427. struct gemtek_device *rt = video_drvdata(file);
  428. switch (ctrl->id) {
  429. case V4L2_CID_AUDIO_MUTE:
  430. if (ctrl->value)
  431. gemtek_mute(rt);
  432. else
  433. gemtek_unmute(rt);
  434. return 0;
  435. case V4L2_CID_AUDIO_VOLUME:
  436. if (ctrl->value)
  437. gemtek_unmute(rt);
  438. else
  439. gemtek_mute(rt);
  440. return 0;
  441. }
  442. return -EINVAL;
  443. }
  444. static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
  445. {
  446. if (a->index > 1)
  447. return -EINVAL;
  448. strcpy(a->name, "Radio");
  449. a->capability = V4L2_AUDCAP_STEREO;
  450. return 0;
  451. }
  452. static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
  453. {
  454. *i = 0;
  455. return 0;
  456. }
  457. static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
  458. {
  459. if (i != 0)
  460. return -EINVAL;
  461. return 0;
  462. }
  463. static int vidioc_s_audio(struct file *file, void *priv, struct v4l2_audio *a)
  464. {
  465. if (a->index != 0)
  466. return -EINVAL;
  467. return 0;
  468. }
  469. static const struct v4l2_ioctl_ops gemtek_ioctl_ops = {
  470. .vidioc_querycap = vidioc_querycap,
  471. .vidioc_g_tuner = vidioc_g_tuner,
  472. .vidioc_s_tuner = vidioc_s_tuner,
  473. .vidioc_g_audio = vidioc_g_audio,
  474. .vidioc_s_audio = vidioc_s_audio,
  475. .vidioc_g_input = vidioc_g_input,
  476. .vidioc_s_input = vidioc_s_input,
  477. .vidioc_g_frequency = vidioc_g_frequency,
  478. .vidioc_s_frequency = vidioc_s_frequency,
  479. .vidioc_queryctrl = vidioc_queryctrl,
  480. .vidioc_g_ctrl = vidioc_g_ctrl,
  481. .vidioc_s_ctrl = vidioc_s_ctrl
  482. };
  483. static struct video_device gemtek_radio = {
  484. .name = "GemTek Radio card",
  485. .fops = &gemtek_fops,
  486. .ioctl_ops = &gemtek_ioctl_ops,
  487. .release = video_device_release_empty,
  488. };
  489. /*
  490. * Initialization / cleanup related stuff.
  491. */
  492. /*
  493. * Initilize card.
  494. */
  495. static int __init gemtek_init(void)
  496. {
  497. printk(KERN_INFO RADIO_BANNER "\n");
  498. spin_lock_init(&lock);
  499. gemtek_probe();
  500. if (io) {
  501. if (!request_region(io, 1, "gemtek")) {
  502. printk(KERN_ERR "I/O port 0x%x already in use.\n", io);
  503. return -EBUSY;
  504. }
  505. if (!gemtek_verify(io))
  506. printk(KERN_WARNING "Card at I/O port 0x%x does not "
  507. "respond properly, check your "
  508. "configuration.\n", io);
  509. else
  510. printk(KERN_INFO "Using I/O port 0x%x.\n", io);
  511. } else if (probe) {
  512. printk(KERN_ERR "Automatic probing failed and no "
  513. "fixed I/O port defined.\n");
  514. return -ENODEV;
  515. } else {
  516. printk(KERN_ERR "Automatic probing disabled but no fixed "
  517. "I/O port defined.");
  518. return -EINVAL;
  519. }
  520. video_set_drvdata(&gemtek_radio, &gemtek_unit);
  521. if (video_register_device(&gemtek_radio, VFL_TYPE_RADIO, radio_nr) < 0) {
  522. release_region(io, 1);
  523. return -EBUSY;
  524. }
  525. /* Set defaults */
  526. gemtek_unit.lastfreq = GEMTEK_LOWFREQ;
  527. gemtek_unit.bu2614data = 0;
  528. if (initmute)
  529. gemtek_mute(&gemtek_unit);
  530. return 0;
  531. }
  532. /*
  533. * Module cleanup
  534. */
  535. static void __exit gemtek_exit(void)
  536. {
  537. if (shutdown) {
  538. hardmute = 1; /* Turn off PLL */
  539. gemtek_mute(&gemtek_unit);
  540. } else {
  541. printk(KERN_INFO "Module unloaded but card not muted!\n");
  542. }
  543. video_unregister_device(&gemtek_radio);
  544. release_region(io, 1);
  545. }
  546. module_init(gemtek_init);
  547. module_exit(gemtek_exit);