radio-gemtek.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  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. #define GEMTEK_CK 0x01 /* Clock signal */
  77. #define GEMTEK_DA 0x02 /* Serial data */
  78. #define GEMTEK_CE 0x04 /* Chip enable */
  79. #define GEMTEK_NS 0x08 /* No signal */
  80. #define GEMTEK_MT 0x10 /* Line mute */
  81. #define GEMTEK_STDF_3_125_KHZ 0x01 /* Standard frequency 3.125 kHz */
  82. #define GEMTEK_PLL_OFF 0x07 /* PLL off */
  83. #define BU2614_BUS_SIZE 32 /* BU2614 / BU2614FS bus size */
  84. #define BU2614_NOPS 8 /* Number of supported operations */
  85. #define SHORT_DELAY 5 /* usec */
  86. #define LONG_DELAY 75 /* usec */
  87. struct gemtek_device {
  88. unsigned long lastfreq;
  89. int muted;
  90. unsigned long bu2614data[BU2614_NOPS];
  91. };
  92. enum {
  93. BU2614_VOID,
  94. BU2614_FREQ, /* D0..D15, Frequency data */
  95. BU2614_PORT, /* P0..P2, Output port control data */
  96. BU2614_FMES, /* CT, Frequency measurement beginning data */
  97. BU2614_STDF, /* R0..R2, Standard frequency data */
  98. BU2614_SWIN, /* S, Switch between FMIN / AMIN */
  99. BU2614_SWAL, /* PS, Swallow counter division (AMIN only) */
  100. BU2614_FMUN, /* GT, Frequency measurement time and unlock */
  101. BU2614_TEST /* TS, Test data is input */
  102. };
  103. struct bu2614_op {
  104. int op; /* Operation */
  105. int size; /* Data size */
  106. };
  107. static struct gemtek_device gemtek_unit;
  108. static struct bu2614_op bu2614ops[] = {
  109. {.op = BU2614_FREQ,
  110. .size = 0x10},
  111. {.op = BU2614_PORT,
  112. .size = 0x03},
  113. {.op = BU2614_VOID,
  114. .size = 0x04},
  115. {.op = BU2614_FMES,
  116. .size = 0x01},
  117. {.op = BU2614_STDF,
  118. .size = 0x03},
  119. {.op = BU2614_SWIN,
  120. .size = 0x01},
  121. {.op = BU2614_SWAL,
  122. .size = 0x01},
  123. {.op = BU2614_VOID,
  124. .size = 0x01},
  125. {.op = BU2614_FMUN,
  126. .size = 0x01},
  127. {.op = BU2614_TEST,
  128. .size = 0x01}
  129. };
  130. static spinlock_t lock;
  131. /*
  132. * Set data which will be sent to BU2614FS.
  133. */
  134. static void gemtek_bu2614_set(struct gemtek_device *dev, int op,
  135. unsigned long data)
  136. {
  137. int i, q;
  138. for (i = 0, q = 0; q < ARRAY_SIZE(dev->bu2614data); ++i) {
  139. if (bu2614ops[i].op == op) {
  140. dev->bu2614data[q] =
  141. data & ((1 << bu2614ops[i].size) - 1);
  142. return;
  143. }
  144. if (bu2614ops[i].op != BU2614_VOID)
  145. ++q;
  146. }
  147. }
  148. /*
  149. * Transmit settings to BU2614FS over GemTek IC.
  150. */
  151. static void gemtek_bu2614_transmit(struct gemtek_device *dev)
  152. {
  153. int i, bit, q, mute;
  154. spin_lock(&lock);
  155. mute = dev->muted ? GEMTEK_MT : 0x00;
  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. for (i = 0, q = 0; q < ARRAY_SIZE(dev->bu2614data); ++i) {
  161. for (bit = 0; bit < bu2614ops[i].size; ++bit) {
  162. if (bu2614ops[i].op != BU2614_VOID &&
  163. dev->bu2614data[q] & (1 << bit)) {
  164. outb_p(mute | GEMTEK_CE | GEMTEK_DA, io);
  165. udelay(SHORT_DELAY);
  166. outb_p(mute | GEMTEK_CE | GEMTEK_DA |
  167. GEMTEK_CK, io);
  168. udelay(SHORT_DELAY);
  169. } else {
  170. outb_p(mute | GEMTEK_CE, io);
  171. udelay(SHORT_DELAY);
  172. outb_p(mute | GEMTEK_CE | GEMTEK_CK, io);
  173. udelay(SHORT_DELAY);
  174. }
  175. }
  176. if (bu2614ops[i].op != BU2614_VOID)
  177. ++q;
  178. }
  179. outb_p(mute | GEMTEK_DA | GEMTEK_CK, io);
  180. udelay(SHORT_DELAY);
  181. outb_p(mute | GEMTEK_CE | GEMTEK_DA | GEMTEK_CK, io);
  182. udelay(LONG_DELAY);
  183. spin_unlock(&lock);
  184. }
  185. /*
  186. * Convert FM-frequency for BU2614FS (3.125 KHz STDF expected).
  187. */
  188. static inline void gemtek_convfreq(unsigned long *freq)
  189. {
  190. (*freq) /= 160;
  191. (*freq) += 1052; /* FMIN, 10.52 MHz */
  192. (*freq) *= 1565; /* STDF, 1 / 156.5 = 0.00639 */
  193. (*freq) /= 1000;
  194. }
  195. /*
  196. * Set FM-frequency.
  197. */
  198. static void gemtek_setfreq(struct gemtek_device *dev, unsigned long freq)
  199. {
  200. if (keepmuted && hardmute && dev->muted)
  201. return;
  202. if (freq < GEMTEK_LOWFREQ)
  203. freq = GEMTEK_LOWFREQ;
  204. else if (freq > GEMTEK_HIGHFREQ)
  205. freq = GEMTEK_HIGHFREQ;
  206. dev->lastfreq = freq;
  207. dev->muted = 0;
  208. gemtek_bu2614_set(dev, BU2614_PORT, 0);
  209. gemtek_bu2614_set(dev, BU2614_FMES, 0);
  210. gemtek_bu2614_set(dev, BU2614_SWIN, 0); /* FM-mode */
  211. gemtek_bu2614_set(dev, BU2614_SWAL, 0);
  212. gemtek_bu2614_set(dev, BU2614_FMUN, 1); /* GT bit set */
  213. gemtek_bu2614_set(dev, BU2614_TEST, 0);
  214. gemtek_convfreq(&freq);
  215. gemtek_bu2614_set(dev, BU2614_STDF, GEMTEK_STDF_3_125_KHZ);
  216. gemtek_bu2614_set(dev, BU2614_FREQ, freq);
  217. gemtek_bu2614_transmit(dev);
  218. }
  219. /*
  220. * Set mute flag.
  221. */
  222. static void gemtek_mute(struct gemtek_device *dev)
  223. {
  224. int i;
  225. dev->muted = 1;
  226. if (hardmute) {
  227. /* Turn off PLL, disable data output */
  228. gemtek_bu2614_set(dev, BU2614_PORT, 0);
  229. gemtek_bu2614_set(dev, BU2614_FMES, 0); /* CT bit off */
  230. gemtek_bu2614_set(dev, BU2614_SWIN, 0); /* FM-mode */
  231. gemtek_bu2614_set(dev, BU2614_SWAL, 0);
  232. gemtek_bu2614_set(dev, BU2614_FMUN, 0); /* GT bit off */
  233. gemtek_bu2614_set(dev, BU2614_TEST, 0);
  234. gemtek_bu2614_set(dev, BU2614_STDF, GEMTEK_PLL_OFF);
  235. gemtek_bu2614_set(dev, BU2614_FREQ, 0);
  236. gemtek_bu2614_transmit(dev);
  237. } else {
  238. spin_lock(&lock);
  239. /* Read bus contents (CE, CK and DA). */
  240. i = inb_p(io);
  241. /* Write it back with mute flag set. */
  242. outb_p((i >> 5) | GEMTEK_MT, io);
  243. udelay(SHORT_DELAY);
  244. spin_unlock(&lock);
  245. }
  246. }
  247. /*
  248. * Unset mute flag.
  249. */
  250. static void gemtek_unmute(struct gemtek_device *dev)
  251. {
  252. int i;
  253. dev->muted = 0;
  254. if (hardmute) {
  255. /* Turn PLL back on. */
  256. gemtek_setfreq(dev, dev->lastfreq);
  257. } else {
  258. spin_lock(&lock);
  259. i = inb_p(io);
  260. outb_p(i >> 5, io);
  261. udelay(SHORT_DELAY);
  262. spin_unlock(&lock);
  263. }
  264. }
  265. /*
  266. * Get signal strength (= stereo status).
  267. */
  268. static inline int gemtek_getsigstr(void)
  269. {
  270. return inb_p(io) & GEMTEK_NS ? 0 : 1;
  271. }
  272. /*
  273. * Check if requested card acts like GemTek Radio card.
  274. */
  275. static int gemtek_verify(int port)
  276. {
  277. static int verified = -1;
  278. int i, q;
  279. if (verified == port)
  280. return 1;
  281. spin_lock(&lock);
  282. q = inb_p(port); /* Read bus contents before probing. */
  283. /* Try to turn on CE, CK and DA respectively and check if card responds
  284. properly. */
  285. for (i = 0; i < 3; ++i) {
  286. outb_p(1 << i, port);
  287. udelay(SHORT_DELAY);
  288. if ((inb_p(port) & (~GEMTEK_NS)) != (0x17 | (1 << (i + 5)))) {
  289. spin_unlock(&lock);
  290. return 0;
  291. }
  292. }
  293. outb_p(q >> 5, port); /* Write bus contents back. */
  294. udelay(SHORT_DELAY);
  295. spin_unlock(&lock);
  296. verified = port;
  297. return 1;
  298. }
  299. /*
  300. * Automatic probing for card.
  301. */
  302. static int gemtek_probe(void)
  303. {
  304. int ioports[] = { 0x20c, 0x30c, 0x24c, 0x34c, 0x248, 0x28c };
  305. int i;
  306. if (!probe) {
  307. printk(KERN_INFO "Automatic device probing disabled.\n");
  308. return -1;
  309. }
  310. printk(KERN_INFO "Automatic device probing enabled.\n");
  311. for (i = 0; i < ARRAY_SIZE(ioports); ++i) {
  312. printk(KERN_INFO "Trying I/O port 0x%x...\n", ioports[i]);
  313. if (!request_region(ioports[i], 1, "gemtek-probe")) {
  314. printk(KERN_WARNING "I/O port 0x%x busy!\n",
  315. ioports[i]);
  316. continue;
  317. }
  318. if (gemtek_verify(ioports[i])) {
  319. printk(KERN_INFO "Card found from I/O port "
  320. "0x%x!\n", ioports[i]);
  321. release_region(ioports[i], 1);
  322. io = ioports[i];
  323. return io;
  324. }
  325. release_region(ioports[i], 1);
  326. }
  327. printk(KERN_ERR "Automatic probing failed!\n");
  328. return -1;
  329. }
  330. /*
  331. * Video 4 Linux stuff.
  332. */
  333. static struct v4l2_queryctrl radio_qctrl[] = {
  334. {
  335. .id = V4L2_CID_AUDIO_MUTE,
  336. .name = "Mute",
  337. .minimum = 0,
  338. .maximum = 1,
  339. .default_value = 1,
  340. .type = V4L2_CTRL_TYPE_BOOLEAN,
  341. }, {
  342. .id = V4L2_CID_AUDIO_VOLUME,
  343. .name = "Volume",
  344. .minimum = 0,
  345. .maximum = 65535,
  346. .step = 65535,
  347. .default_value = 0xff,
  348. .type = V4L2_CTRL_TYPE_INTEGER,
  349. }
  350. };
  351. static struct file_operations gemtek_fops = {
  352. .owner = THIS_MODULE,
  353. .open = video_exclusive_open,
  354. .release = video_exclusive_release,
  355. .ioctl = video_ioctl2,
  356. .compat_ioctl = v4l_compat_ioctl32,
  357. .llseek = no_llseek
  358. };
  359. static int vidioc_querycap(struct file *file, void *priv,
  360. struct v4l2_capability *v)
  361. {
  362. strlcpy(v->driver, "radio-gemtek", sizeof(v->driver));
  363. strlcpy(v->card, "GemTek", sizeof(v->card));
  364. sprintf(v->bus_info, "ISA");
  365. v->version = RADIO_VERSION;
  366. v->capabilities = V4L2_CAP_TUNER;
  367. return 0;
  368. }
  369. static int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *v)
  370. {
  371. if (v->index > 0)
  372. return -EINVAL;
  373. strcpy(v->name, "FM");
  374. v->type = V4L2_TUNER_RADIO;
  375. v->rangelow = GEMTEK_LOWFREQ;
  376. v->rangehigh = GEMTEK_HIGHFREQ;
  377. v->capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
  378. v->signal = 0xffff * gemtek_getsigstr();
  379. if (v->signal) {
  380. v->audmode = V4L2_TUNER_MODE_STEREO;
  381. v->rxsubchans = V4L2_TUNER_SUB_STEREO;
  382. } else {
  383. v->audmode = V4L2_TUNER_MODE_MONO;
  384. v->rxsubchans = V4L2_TUNER_SUB_MONO;
  385. }
  386. return 0;
  387. }
  388. static int vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *v)
  389. {
  390. if (v->index > 0)
  391. return -EINVAL;
  392. return 0;
  393. }
  394. static int vidioc_s_frequency(struct file *file, void *priv,
  395. struct v4l2_frequency *f)
  396. {
  397. struct video_device *dev = video_devdata(file);
  398. struct gemtek_device *rt = dev->priv;
  399. gemtek_setfreq(rt, f->frequency);
  400. return 0;
  401. }
  402. static int vidioc_g_frequency(struct file *file, void *priv,
  403. struct v4l2_frequency *f)
  404. {
  405. struct video_device *dev = video_devdata(file);
  406. struct gemtek_device *rt = dev->priv;
  407. f->type = V4L2_TUNER_RADIO;
  408. f->frequency = rt->lastfreq;
  409. return 0;
  410. }
  411. static int vidioc_queryctrl(struct file *file, void *priv,
  412. struct v4l2_queryctrl *qc)
  413. {
  414. int i;
  415. for (i = 0; i < ARRAY_SIZE(radio_qctrl); ++i) {
  416. if (qc->id && qc->id == radio_qctrl[i].id) {
  417. memcpy(qc, &(radio_qctrl[i]), sizeof(*qc));
  418. return 0;
  419. }
  420. }
  421. return -EINVAL;
  422. }
  423. static int vidioc_g_ctrl(struct file *file, void *priv,
  424. struct v4l2_control *ctrl)
  425. {
  426. struct video_device *dev = video_devdata(file);
  427. struct gemtek_device *rt = dev->priv;
  428. switch (ctrl->id) {
  429. case V4L2_CID_AUDIO_MUTE:
  430. ctrl->value = rt->muted;
  431. return 0;
  432. case V4L2_CID_AUDIO_VOLUME:
  433. if (rt->muted)
  434. ctrl->value = 0;
  435. else
  436. ctrl->value = 65535;
  437. return 0;
  438. }
  439. return -EINVAL;
  440. }
  441. static int vidioc_s_ctrl(struct file *file, void *priv,
  442. struct v4l2_control *ctrl)
  443. {
  444. struct video_device *dev = video_devdata(file);
  445. struct gemtek_device *rt = dev->priv;
  446. switch (ctrl->id) {
  447. case V4L2_CID_AUDIO_MUTE:
  448. if (ctrl->value)
  449. gemtek_mute(rt);
  450. else
  451. gemtek_unmute(rt);
  452. return 0;
  453. case V4L2_CID_AUDIO_VOLUME:
  454. if (ctrl->value)
  455. gemtek_unmute(rt);
  456. else
  457. gemtek_mute(rt);
  458. return 0;
  459. }
  460. return -EINVAL;
  461. }
  462. static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
  463. {
  464. if (a->index > 1)
  465. return -EINVAL;
  466. strcpy(a->name, "Radio");
  467. a->capability = V4L2_AUDCAP_STEREO;
  468. return 0;
  469. }
  470. static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
  471. {
  472. *i = 0;
  473. return 0;
  474. }
  475. static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
  476. {
  477. if (i != 0)
  478. return -EINVAL;
  479. return 0;
  480. }
  481. static int vidioc_s_audio(struct file *file, void *priv, struct v4l2_audio *a)
  482. {
  483. if (a->index != 0)
  484. return -EINVAL;
  485. return 0;
  486. }
  487. static struct video_device gemtek_radio = {
  488. .owner = THIS_MODULE,
  489. .name = "GemTek Radio card",
  490. .type = VID_TYPE_TUNER,
  491. .hardware = VID_HARDWARE_GEMTEK,
  492. .fops = &gemtek_fops,
  493. .vidioc_querycap = vidioc_querycap,
  494. .vidioc_g_tuner = vidioc_g_tuner,
  495. .vidioc_s_tuner = vidioc_s_tuner,
  496. .vidioc_g_audio = vidioc_g_audio,
  497. .vidioc_s_audio = vidioc_s_audio,
  498. .vidioc_g_input = vidioc_g_input,
  499. .vidioc_s_input = vidioc_s_input,
  500. .vidioc_g_frequency = vidioc_g_frequency,
  501. .vidioc_s_frequency = vidioc_s_frequency,
  502. .vidioc_queryctrl = vidioc_queryctrl,
  503. .vidioc_g_ctrl = vidioc_g_ctrl,
  504. .vidioc_s_ctrl = vidioc_s_ctrl
  505. };
  506. /*
  507. * Initialization / cleanup related stuff.
  508. */
  509. /*
  510. * Initilize card.
  511. */
  512. static int __init gemtek_init(void)
  513. {
  514. int i;
  515. printk(KERN_INFO RADIO_BANNER "\n");
  516. spin_lock_init(&lock);
  517. gemtek_probe();
  518. if (io) {
  519. if (!request_region(io, 1, "gemtek")) {
  520. printk(KERN_ERR "I/O port 0x%x already in use.\n", io);
  521. return -EBUSY;
  522. }
  523. if (!gemtek_verify(io))
  524. printk(KERN_WARNING "Card at I/O port 0x%x does not "
  525. "respond properly, check your "
  526. "configuration.\n", io);
  527. else
  528. printk(KERN_INFO "Using I/O port 0x%x.\n", io);
  529. } else if (probe) {
  530. printk(KERN_ERR "Automatic probing failed and no "
  531. "fixed I/O port defined.\n");
  532. return -ENODEV;
  533. } else {
  534. printk(KERN_ERR "Automatic probing disabled but no fixed "
  535. "I/O port defined.");
  536. return -EINVAL;
  537. }
  538. gemtek_radio.priv = &gemtek_unit;
  539. if (video_register_device(&gemtek_radio, VFL_TYPE_RADIO,
  540. radio_nr) == -1) {
  541. release_region(io, 1);
  542. return -EBUSY;
  543. }
  544. /* Set defaults */
  545. gemtek_unit.lastfreq = GEMTEK_LOWFREQ;
  546. for (i = 0; i < ARRAY_SIZE(gemtek_unit.bu2614data); ++i)
  547. gemtek_unit.bu2614data[i] = 0;
  548. if (initmute)
  549. gemtek_mute(&gemtek_unit);
  550. return 0;
  551. }
  552. /*
  553. * Module cleanup
  554. */
  555. static void __exit gemtek_exit(void)
  556. {
  557. if (shutdown) {
  558. hardmute = 1; /* Turn off PLL */
  559. gemtek_mute(&gemtek_unit);
  560. } else {
  561. printk(KERN_INFO "Module unloaded but card not muted!\n");
  562. }
  563. video_unregister_device(&gemtek_radio);
  564. release_region(io, 1);
  565. }
  566. module_init(gemtek_init);
  567. module_exit(gemtek_exit);