radio-gemtek.c 15 KB

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