radio-gemtek.c 16 KB

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