radio-aimslab.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. #include "lm7000.h"
  40. MODULE_AUTHOR("M. Kirkwood");
  41. MODULE_DESCRIPTION("A driver for the RadioTrack/RadioReveal radio card.");
  42. MODULE_LICENSE("GPL");
  43. MODULE_VERSION("1.0.0");
  44. #ifndef CONFIG_RADIO_RTRACK_PORT
  45. #define CONFIG_RADIO_RTRACK_PORT -1
  46. #endif
  47. #define RTRACK_MAX 2
  48. static int io[RTRACK_MAX] = { [0] = CONFIG_RADIO_RTRACK_PORT,
  49. [1 ... (RTRACK_MAX - 1)] = -1 };
  50. static int radio_nr[RTRACK_MAX] = { [0 ... (RTRACK_MAX - 1)] = -1 };
  51. module_param_array(io, int, NULL, 0444);
  52. MODULE_PARM_DESC(io, "I/O addresses of the RadioTrack card (0x20f or 0x30f)");
  53. module_param_array(radio_nr, int, NULL, 0444);
  54. MODULE_PARM_DESC(radio_nr, "Radio device numbers");
  55. struct rtrack {
  56. struct radio_isa_card isa;
  57. int curvol;
  58. };
  59. static struct radio_isa_card *rtrack_alloc(void)
  60. {
  61. struct rtrack *rt = kzalloc(sizeof(struct rtrack), GFP_KERNEL);
  62. if (rt)
  63. rt->curvol = 0xff;
  64. return rt ? &rt->isa : NULL;
  65. }
  66. #define AIMS_BIT_TUN_CE (1 << 0)
  67. #define AIMS_BIT_TUN_CLK (1 << 1)
  68. #define AIMS_BIT_TUN_DATA (1 << 2)
  69. #define AIMS_BIT_VOL_CE (1 << 3)
  70. #define AIMS_BIT_TUN_STRQ (1 << 4)
  71. /* bit 5 is not connected */
  72. #define AIMS_BIT_VOL_UP (1 << 6) /* active low */
  73. #define AIMS_BIT_VOL_DN (1 << 7) /* active low */
  74. static void rtrack_set_pins(void *handle, u8 pins)
  75. {
  76. struct radio_isa_card *isa = handle;
  77. struct rtrack *rt = container_of(isa, struct rtrack, isa);
  78. u8 bits = AIMS_BIT_VOL_DN | AIMS_BIT_VOL_UP | AIMS_BIT_TUN_STRQ;
  79. if (!v4l2_ctrl_g_ctrl(rt->isa.mute))
  80. bits |= AIMS_BIT_VOL_CE;
  81. if (pins & LM7000_DATA)
  82. bits |= AIMS_BIT_TUN_DATA;
  83. if (pins & LM7000_CLK)
  84. bits |= AIMS_BIT_TUN_CLK;
  85. if (pins & LM7000_CE)
  86. bits |= AIMS_BIT_TUN_CE;
  87. outb_p(bits, rt->isa.io);
  88. }
  89. static int rtrack_s_frequency(struct radio_isa_card *isa, u32 freq)
  90. {
  91. lm7000_set_freq(freq, isa, rtrack_set_pins);
  92. return 0;
  93. }
  94. static u32 rtrack_g_signal(struct radio_isa_card *isa)
  95. {
  96. /* bit set = no signal present */
  97. return 0xffff * !(inb(isa->io) & 2);
  98. }
  99. static int rtrack_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
  100. {
  101. struct rtrack *rt = container_of(isa, struct rtrack, isa);
  102. int curvol = rt->curvol;
  103. if (mute) {
  104. outb(0xd0, isa->io); /* volume steady + sigstr + off */
  105. return 0;
  106. }
  107. if (vol == 0) { /* volume = 0 means mute the card */
  108. outb(0x48, isa->io); /* volume down but still "on" */
  109. msleep(curvol * 3); /* make sure it's totally down */
  110. } else if (curvol < vol) {
  111. outb(0x98, isa->io); /* volume up + sigstr + on */
  112. for (; curvol < vol; curvol++)
  113. mdelay(3);
  114. } else if (curvol > vol) {
  115. outb(0x58, isa->io); /* volume down + sigstr + on */
  116. for (; curvol > vol; curvol--)
  117. mdelay(3);
  118. }
  119. outb(0xd8, isa->io); /* volume steady + sigstr + on */
  120. rt->curvol = vol;
  121. return 0;
  122. }
  123. /* Mute card - prevents noisy bootups */
  124. static int rtrack_initialize(struct radio_isa_card *isa)
  125. {
  126. /* this ensures that the volume is all the way up */
  127. outb(0x90, isa->io); /* volume up but still "on" */
  128. msleep(3000); /* make sure it's totally up */
  129. outb(0xc0, isa->io); /* steady volume, mute card */
  130. return 0;
  131. }
  132. static const struct radio_isa_ops rtrack_ops = {
  133. .alloc = rtrack_alloc,
  134. .init = rtrack_initialize,
  135. .s_mute_volume = rtrack_s_mute_volume,
  136. .s_frequency = rtrack_s_frequency,
  137. .g_signal = rtrack_g_signal,
  138. };
  139. static const int rtrack_ioports[] = { 0x20f, 0x30f };
  140. static struct radio_isa_driver rtrack_driver = {
  141. .driver = {
  142. .match = radio_isa_match,
  143. .probe = radio_isa_probe,
  144. .remove = radio_isa_remove,
  145. .driver = {
  146. .name = "radio-aimslab",
  147. },
  148. },
  149. .io_params = io,
  150. .radio_nr_params = radio_nr,
  151. .io_ports = rtrack_ioports,
  152. .num_of_io_ports = ARRAY_SIZE(rtrack_ioports),
  153. .region_size = 2,
  154. .card = "AIMSlab RadioTrack/RadioReveal",
  155. .ops = &rtrack_ops,
  156. .has_stereo = true,
  157. .max_volume = 0xff,
  158. };
  159. static int __init rtrack_init(void)
  160. {
  161. return isa_register_driver(&rtrack_driver.driver, RTRACK_MAX);
  162. }
  163. static void __exit rtrack_exit(void)
  164. {
  165. isa_unregister_driver(&rtrack_driver.driver);
  166. }
  167. module_init(rtrack_init);
  168. module_exit(rtrack_exit);