radio-aimslab.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * AimsLab RadioTrack (aka RadioVeveal) driver
  3. *
  4. * Copyright 1997 M. Kirkwood
  5. *
  6. * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@cisco.com>
  7. * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
  8. * Converted to new API by Alan Cox <alan@lxorguk.ukuu.org.uk>
  9. * Various bugfixes and enhancements by Russell Kroll <rkroll@exploits.org>
  10. *
  11. * Notes on the hardware (reverse engineered from other peoples'
  12. * reverse engineering of AIMS' code :-)
  13. *
  14. * Frequency control is done digitally -- ie out(port,encodefreq(95.8));
  15. *
  16. * The signal strength query is unsurprisingly inaccurate. And it seems
  17. * to indicate that (on my card, at least) the frequency setting isn't
  18. * too great. (I have to tune up .025MHz from what the freq should be
  19. * to get a report that the thing is tuned.)
  20. *
  21. * Volume control is (ugh) analogue:
  22. * out(port, start_increasing_volume);
  23. * wait(a_wee_while);
  24. * out(port, stop_changing_the_volume);
  25. *
  26. * Fully tested with the Keene USB FM Transmitter and the v4l2-compliance tool.
  27. */
  28. #include <linux/module.h> /* Modules */
  29. #include <linux/init.h> /* Initdata */
  30. #include <linux/ioport.h> /* request_region */
  31. #include <linux/delay.h> /* msleep */
  32. #include <linux/videodev2.h> /* kernel radio structs */
  33. #include <linux/io.h> /* outb, outb_p */
  34. #include <linux/slab.h>
  35. #include <media/v4l2-device.h>
  36. #include <media/v4l2-ioctl.h>
  37. #include <media/v4l2-ctrls.h>
  38. #include "radio-isa.h"
  39. MODULE_AUTHOR("M. Kirkwood");
  40. MODULE_DESCRIPTION("A driver for the RadioTrack/RadioReveal radio card.");
  41. MODULE_LICENSE("GPL");
  42. MODULE_VERSION("1.0.0");
  43. #ifndef CONFIG_RADIO_RTRACK_PORT
  44. #define CONFIG_RADIO_RTRACK_PORT -1
  45. #endif
  46. #define RTRACK_MAX 2
  47. static int io[RTRACK_MAX] = { [0] = CONFIG_RADIO_RTRACK_PORT,
  48. [1 ... (RTRACK_MAX - 1)] = -1 };
  49. static int radio_nr[RTRACK_MAX] = { [0 ... (RTRACK_MAX - 1)] = -1 };
  50. module_param_array(io, int, NULL, 0444);
  51. MODULE_PARM_DESC(io, "I/O addresses of the RadioTrack card (0x20f or 0x30f)");
  52. module_param_array(radio_nr, int, NULL, 0444);
  53. MODULE_PARM_DESC(radio_nr, "Radio device numbers");
  54. struct rtrack {
  55. struct radio_isa_card isa;
  56. int curvol;
  57. };
  58. static struct radio_isa_card *rtrack_alloc(void)
  59. {
  60. struct rtrack *rt = kzalloc(sizeof(struct rtrack), GFP_KERNEL);
  61. if (rt)
  62. rt->curvol = 0xff;
  63. return rt ? &rt->isa : NULL;
  64. }
  65. /* The 128+64 on these outb's is to keep the volume stable while tuning.
  66. * Without them, the volume _will_ creep up with each frequency change
  67. * and bit 4 (+16) is to keep the signal strength meter enabled.
  68. */
  69. static void send_0_byte(struct radio_isa_card *isa, int on)
  70. {
  71. outb_p(128+64+16+on+1, isa->io); /* wr-enable + data low */
  72. outb_p(128+64+16+on+2+1, isa->io); /* clock */
  73. msleep(1);
  74. }
  75. static void send_1_byte(struct radio_isa_card *isa, int on)
  76. {
  77. outb_p(128+64+16+on+4+1, isa->io); /* wr-enable+data high */
  78. outb_p(128+64+16+on+4+2+1, isa->io); /* clock */
  79. msleep(1);
  80. }
  81. static int rtrack_s_frequency(struct radio_isa_card *isa, u32 freq)
  82. {
  83. int on = v4l2_ctrl_g_ctrl(isa->mute) ? 0 : 8;
  84. int i;
  85. freq += 171200; /* Add 10.7 MHz IF */
  86. freq /= 800; /* Convert to 50 kHz units */
  87. send_0_byte(isa, on); /* 0: LSB of frequency */
  88. for (i = 0; i < 13; i++) /* : frequency bits (1-13) */
  89. if (freq & (1 << i))
  90. send_1_byte(isa, on);
  91. else
  92. send_0_byte(isa, on);
  93. send_0_byte(isa, on); /* 14: test bit - always 0 */
  94. send_0_byte(isa, on); /* 15: test bit - always 0 */
  95. send_0_byte(isa, on); /* 16: band data 0 - always 0 */
  96. send_0_byte(isa, on); /* 17: band data 1 - always 0 */
  97. send_0_byte(isa, on); /* 18: band data 2 - always 0 */
  98. send_0_byte(isa, on); /* 19: time base - always 0 */
  99. send_0_byte(isa, on); /* 20: spacing (0 = 25 kHz) */
  100. send_1_byte(isa, on); /* 21: spacing (1 = 25 kHz) */
  101. send_0_byte(isa, on); /* 22: spacing (0 = 25 kHz) */
  102. send_1_byte(isa, on); /* 23: AM/FM (FM = 1, always) */
  103. outb(0xd0 + on, isa->io); /* volume steady + sigstr */
  104. return 0;
  105. }
  106. static u32 rtrack_g_signal(struct radio_isa_card *isa)
  107. {
  108. /* bit set = no signal present */
  109. return 0xffff * !(inb(isa->io) & 2);
  110. }
  111. static int rtrack_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
  112. {
  113. struct rtrack *rt = container_of(isa, struct rtrack, isa);
  114. int curvol = rt->curvol;
  115. if (mute) {
  116. outb(0xd0, isa->io); /* volume steady + sigstr + off */
  117. return 0;
  118. }
  119. if (vol == 0) { /* volume = 0 means mute the card */
  120. outb(0x48, isa->io); /* volume down but still "on" */
  121. msleep(curvol * 3); /* make sure it's totally down */
  122. } else if (curvol < vol) {
  123. outb(0x98, isa->io); /* volume up + sigstr + on */
  124. for (; curvol < vol; curvol++)
  125. udelay(3000);
  126. } else if (curvol > vol) {
  127. outb(0x58, isa->io); /* volume down + sigstr + on */
  128. for (; curvol > vol; curvol--)
  129. udelay(3000);
  130. }
  131. outb(0xd8, isa->io); /* volume steady + sigstr + on */
  132. rt->curvol = vol;
  133. return 0;
  134. }
  135. /* Mute card - prevents noisy bootups */
  136. static int rtrack_initialize(struct radio_isa_card *isa)
  137. {
  138. /* this ensures that the volume is all the way up */
  139. outb(0x90, isa->io); /* volume up but still "on" */
  140. msleep(3000); /* make sure it's totally up */
  141. outb(0xc0, isa->io); /* steady volume, mute card */
  142. return 0;
  143. }
  144. static const struct radio_isa_ops rtrack_ops = {
  145. .alloc = rtrack_alloc,
  146. .init = rtrack_initialize,
  147. .s_mute_volume = rtrack_s_mute_volume,
  148. .s_frequency = rtrack_s_frequency,
  149. .g_signal = rtrack_g_signal,
  150. };
  151. static const int rtrack_ioports[] = { 0x20f, 0x30f };
  152. static struct radio_isa_driver rtrack_driver = {
  153. .driver = {
  154. .match = radio_isa_match,
  155. .probe = radio_isa_probe,
  156. .remove = radio_isa_remove,
  157. .driver = {
  158. .name = "radio-aimslab",
  159. },
  160. },
  161. .io_params = io,
  162. .radio_nr_params = radio_nr,
  163. .io_ports = rtrack_ioports,
  164. .num_of_io_ports = ARRAY_SIZE(rtrack_ioports),
  165. .region_size = 2,
  166. .card = "AIMSlab RadioTrack/RadioReveal",
  167. .ops = &rtrack_ops,
  168. .has_stereo = true,
  169. .max_volume = 0xff,
  170. };
  171. static int __init rtrack_init(void)
  172. {
  173. return isa_register_driver(&rtrack_driver.driver, RTRACK_MAX);
  174. }
  175. static void __exit rtrack_exit(void)
  176. {
  177. isa_unregister_driver(&rtrack_driver.driver);
  178. }
  179. module_init(rtrack_init);
  180. module_exit(rtrack_exit);