radio-aimslab.c 5.4 KB

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